HatchColor & HatchScale prop to Gui side

This commit is contained in:
WandererFan
2018-02-13 19:26:21 -05:00
parent 6fa92cb188
commit cbca02f7f3
5 changed files with 53 additions and 29 deletions

View File

@@ -50,30 +50,20 @@
using namespace TechDraw;
using namespace std;
App::PropertyFloatConstraint::Constraints DrawHatch::scaleRange = {Precision::Confusion(),
std::numeric_limits<double>::max(),
pow(10,- Base::UnitsApi::getDecimals())};
PROPERTY_SOURCE(TechDraw::DrawHatch, App::DocumentObject)
DrawHatch::DrawHatch(void)
{
static const char *vgroup = "Hatch";
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("Hatch", 0x00FF0000));
ADD_PROPERTY_TYPE(DirProjection ,(0,0,1.0) ,vgroup,App::Prop_None,"Projection direction when Hatch was defined"); //sb RO?
ADD_PROPERTY_TYPE(Source,(0),vgroup,(App::PropertyType)(App::Prop_None),"The View + Face to be hatched");
ADD_PROPERTY_TYPE(HatchPattern ,(""),vgroup,App::Prop_None,"The hatch pattern file for this area");
ADD_PROPERTY_TYPE(HatchColor,(fcColor),vgroup,App::Prop_None,"The color of the hatch pattern");
ADD_PROPERTY_TYPE(HatchScale,(1.0),vgroup,App::Prop_None,"Hatch pattern size adjustment");
HatchScale.setConstraints(&scaleRange);
DirProjection.setStatus(App::Property::ReadOnly,true);
hGrp = App::GetApplication().GetUserParameter()
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files");
std::string defaultDir = App::Application::getResourceDir() + "Mod/Drawing/patterns/";
@@ -94,10 +84,8 @@ DrawHatch::~DrawHatch()
void DrawHatch::onChanged(const App::Property* prop)
{
if (prop == &Source ||
prop == &HatchPattern || //sb VP property?
prop == &HatchScale ||
prop == &HatchColor) {
if ((prop == &Source) ||
(prop == &HatchPattern)) {
if (!isRestoring()) {
DrawHatch::execute();
}

View File

@@ -43,10 +43,6 @@ public:
App::PropertyVector DirProjection; //Source is only valid for original projection?
App::PropertyLinkSub Source; //the dvp & face this hatch belongs to
App::PropertyFile HatchPattern;
App::PropertyColor HatchColor;
App::PropertyFloatConstraint HatchScale;
//short mustExecute() const;
virtual App::DocumentObjectExecReturn *execute(void);
@@ -62,7 +58,6 @@ protected:
void onChanged(const App::Property* prop);
private:
static App::PropertyFloatConstraint::Constraints scaleRange;
};

View File

@@ -70,6 +70,7 @@
#include "QGIMatting.h"
#include "QGIViewPart.h"
#include "ViewProviderGeomHatch.h"
#include "ViewProviderHatch.h"
using namespace TechDrawGui;
using namespace TechDrawGeometry;
@@ -412,8 +413,12 @@ void QGIViewPart::drawViewPart()
newFace->isHatched(true);
newFace->setFillMode(QGIFace::FromFile);
newFace->setHatchFile(fHatch->HatchPattern.getValue());
newFace->setHatchScale(fHatch->HatchScale.getValue());
newFace->setHatchColor(fHatch->HatchColor.getValue());
Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch);
ViewProviderHatch* hatchVp = dynamic_cast<ViewProviderHatch*>(gvp);
if (hatchVp != nullptr) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
newFace->setHatchColor(hatchVp->HatchColor.getValue());
}
}
}
bool drawEdges = getFaceEdgesPref();

View File

@@ -25,24 +25,33 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <Precision.hxx>
#endif
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Base/Exception.h>
#include <Base/Sequencer.h>
//#include <Base/Exception.h>
//#include <Base/Sequencer.h>
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Gui/SoFCSelection.h>
#include <Gui/Selection.h>
//#include <Gui/SoFCSelection.h>
//#include <Gui/Selection.h>
#include <Mod/TechDraw/App/DrawHatch.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include "ViewProviderHatch.h"
using namespace TechDrawGui;
App::PropertyFloatConstraint::Constraints ViewProviderHatch::scaleRange = {Precision::Confusion(),
std::numeric_limits<double>::max(),
pow(10,- Base::UnitsApi::getDecimals())};
PROPERTY_SOURCE(TechDrawGui::ViewProviderHatch, Gui::ViewProviderDocumentObject)
//**************************************************************************
@@ -51,6 +60,16 @@ PROPERTY_SOURCE(TechDrawGui::ViewProviderHatch, Gui::ViewProviderDocumentObject)
ViewProviderHatch::ViewProviderHatch()
{
sPixmap = "TechDraw_Tree_Hatch";
static const char *vgroup = "Hatch";
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("Hatch", 0x00FF0000));
ADD_PROPERTY_TYPE(HatchColor,(fcColor),vgroup,App::Prop_None,"The color of the hatch pattern");
ADD_PROPERTY_TYPE(HatchScale,(1.0),vgroup,App::Prop_None,"Hatch pattern size adjustment");
HatchScale.setConstraints(&scaleRange);
}
ViewProviderHatch::~ViewProviderHatch()
@@ -76,9 +95,19 @@ std::vector<std::string> ViewProviderHatch::getDisplayModes(void) const
return StrList;
}
void ViewProviderHatch::onChanged(const App::Property* prop)
{
if ((prop == &HatchScale) ||
(prop == &HatchColor)) {
TechDraw::DrawViewPart* parent = getViewObject()->getSourceView();
if (parent) {
parent->requestPaint();
}
}
}
void ViewProviderHatch::updateData(const App::Property* prop)
{
Gui::ViewProviderDocumentObject::updateData(prop);
Gui::ViewProviderDocumentObject::updateData(prop);
}
TechDraw::DrawHatch* ViewProviderHatch::getViewObject() const

View File

@@ -25,7 +25,7 @@
#ifndef DRAWINGGUI_VIEWPROVIDERHATCH_H
#define DRAWINGGUI_VIEWPROVIDERHATCH_H
#include <Gui/ViewProviderFeature.h>
#include <Gui/ViewProviderDocumentObject.h>
namespace TechDraw{
class DrawHatch;
@@ -44,15 +44,22 @@ public:
/// destructor
virtual ~ViewProviderHatch();
App::PropertyColor HatchColor;
App::PropertyFloatConstraint HatchScale;
virtual void attach(App::DocumentObject *);
virtual void setDisplayMode(const char* ModeName);
virtual bool useNewSelectionModel(void) const {return false;}
/// returns a list of all possible modes
virtual std::vector<std::string> getDisplayModes(void) const;
virtual void onChanged(const App::Property* prop);
virtual void updateData(const App::Property*);
TechDraw::DrawHatch* getViewObject() const;
private:
static App::PropertyFloatConstraint::Constraints scaleRange;
};
} // namespace TechDrawGui