From 299ac94c9f5403e873eba04940888e961da24982 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Sun, 22 Jan 2017 08:41:04 -0500 Subject: [PATCH] Geometric hatch for Section face --- src/Mod/TechDraw/App/DrawCrosshatch.cpp | 158 ++++++++---------- src/Mod/TechDraw/App/DrawCrosshatch.h | 30 ++-- src/Mod/TechDraw/App/DrawViewPart.cpp | 7 +- src/Mod/TechDraw/App/DrawViewPart.h | 10 +- src/Mod/TechDraw/App/DrawViewSection.cpp | 68 ++++++-- src/Mod/TechDraw/App/DrawViewSection.h | 32 ++-- src/Mod/TechDraw/App/GeometryObject.h | 5 + src/Mod/TechDraw/App/HatchLine.cpp | 5 + src/Mod/TechDraw/App/HatchLine.h | 13 +- src/Mod/TechDraw/Gui/QGIFace.cpp | 35 ++-- src/Mod/TechDraw/Gui/QGIFace.h | 11 +- src/Mod/TechDraw/Gui/QGIViewPart.cpp | 49 +++--- src/Mod/TechDraw/Gui/QGIViewSection.cpp | 59 +++++-- .../TechDraw/Gui/ViewProviderCrosshatch.cpp | 84 +++++++--- src/Mod/TechDraw/Gui/ViewProviderCrosshatch.h | 3 + .../TechDraw/Gui/ViewProviderDrawingView.cpp | 21 ++- .../TechDraw/Gui/ViewProviderViewSection.cpp | 62 ++++++- .../TechDraw/Gui/ViewProviderViewSection.h | 11 ++ 18 files changed, 427 insertions(+), 236 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawCrosshatch.cpp b/src/Mod/TechDraw/App/DrawCrosshatch.cpp index d216b3106..9d0e64ede 100644 --- a/src/Mod/TechDraw/App/DrawCrosshatch.cpp +++ b/src/Mod/TechDraw/App/DrawCrosshatch.cpp @@ -64,6 +64,7 @@ #include "DrawUtil.h" #include "Geometry.h" #include "DrawViewPart.h" +#include "DrawViewSection.h" #include "DrawCrosshatch.h" #include // generated from DrawCrosshatchPy.xml @@ -78,41 +79,13 @@ PROPERTY_SOURCE(TechDraw::DrawCrosshatch, App::DocumentObject) DrawCrosshatch::DrawCrosshatch(void) { static const char *vgroup = "Crosshatch"; - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); - App::Color fcColor; - fcColor.setPackedValue(hGrp->GetUnsigned("Crosshatch", 0x00000000)); - ADD_PROPERTY_TYPE(DirProjection ,(0,0,1.0) ,vgroup,App::Prop_None,"Projection direction when Crosshatch was defined"); //sb RO? ADD_PROPERTY_TYPE(Source,(0),vgroup,(App::PropertyType)(App::Prop_None),"The View + Face to be crosshatched"); ADD_PROPERTY_TYPE(FilePattern ,(""),vgroup,App::Prop_None,"The crosshatch pattern file for this area"); ADD_PROPERTY_TYPE(NamePattern,(""),vgroup,App::Prop_None,"The name of the pattern"); ADD_PROPERTY_TYPE(ScalePattern,(1.0),vgroup,App::Prop_None,"Crosshatch pattern size adjustment"); -// ADD_PROPERTY_TYPE(ColorPattern,(fcColor),vgroup,App::Prop_None,"The color of the pattern"); //to vp? -// ADD_PROPERTY_TYPE(WeightPattern,(0.0),vgroup,App::Prop_None,"Crosshatch pattern line thickness"); -// ADD_PROPERTY_TYPE(LineSpecs,(""),vgroup,App::Prop_None,"Pattern line specifications"); //this sb RO or removed? - DirProjection.setStatus(App::Property::ReadOnly,true); - -//this is probably "/build/data/Mod/TechDraw/PAT" - hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); - - std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/PAT/"; - std::string defaultFileName = defaultDir + "FCStd.pat"; - QString patternFileName = QString::fromStdString(hGrp->GetASCII("FilePattern",defaultFileName.c_str())); - if (patternFileName.isEmpty()) { - patternFileName = QString::fromStdString(defaultFileName); - } - QFileInfo tfi(patternFileName); - if (tfi.isReadable()) { - FilePattern.setValue(patternFileName.toUtf8().constData()); - } - hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); - - std::string defaultNamePattern = "Diamond"; - NamePattern.setValue(hGrp->GetASCII("NamePattern",defaultNamePattern.c_str())); + getParameters(); } @@ -144,12 +117,6 @@ void DrawCrosshatch::onChanged(const App::Property* prop) } } - if (prop == &ScalePattern) { - if (!isRestoring()) { - adviseParent(); //just need to have the parent redraw on Gui side. handle through VPDC::updateData - } - } - App::DocumentObject::onChanged(prop); } @@ -171,37 +138,10 @@ short DrawCrosshatch::mustExecute() const App::DocumentObjectExecReturn *DrawCrosshatch::execute(void) { - DrawViewPart* source = getSourceView(); - if (!source) { - return App::DocumentObject::StdReturn; - } - - if (!source->hasGeometry()) { - return App::DocumentObject::StdReturn; - } - - Base::Vector3d sourceDir = source->Direction.getValue(); - Base::Vector3d ourDir = DirProjection.getValue(); - if (sourceDir != ourDir) { - Base::Console().Warning("Pattern %s may be incorrect due to source %d Direction change.\n", - getNameInDocument(),source->getNameInDocument()); - } - - adviseParent(); return App::DocumentObject::StdReturn; } -void DrawCrosshatch::adviseParent(void) const -{ - //if the hatch changes, the source has to change too. actually only the source's QGVI has to change. - DrawViewPart* parent = getSourceView(); - if (parent) { - parent->touch(); - parent->recomputeFeature(); - } -} - DrawViewPart* DrawCrosshatch::getSourceView(void) const { App::DocumentObject* obj = Source.getValue(); @@ -209,12 +149,19 @@ DrawViewPart* DrawCrosshatch::getSourceView(void) const return result; } -//!get all the specification lines and decode them into HatchLine structures std::vector DrawCrosshatch::getDecodedSpecsFromFile() { - std::vector result; std::string fileSpec = FilePattern.getValue(); std::string myPattern = NamePattern.getValue(); + return getDecodedSpecsFromFile(fileSpec,myPattern); +} + + +//!get all the specification lines and decode them into HatchLine structures +/*static*/ +std::vector DrawCrosshatch::getDecodedSpecsFromFile(std::string fileSpec, std::string myPattern) +{ + std::vector result; Base::FileInfo fi(fileSpec); if (!fi.isReadable()) { Base::Console().Error("DrawCrosshatch::getDecodedSpecsFromFile not able to open %s!\n",fileSpec.c_str()); @@ -225,29 +172,46 @@ std::vector DrawCrosshatch::getDecodedSpecsFromFile() return result; } -std::vector DrawCrosshatch::getDrawableLines() +std::vector DrawCrosshatch::getDrawableLines(int i) //get the drawable lines for face i { std::vector result; - DrawViewPart* source = getSourceView(); if (!source || !source->hasGeometry()) { Base::Console().Message("TRACE - DC::getDrawableLines - no source geometry\n"); return result; } + return getDrawableLines(source, m_lineSets,i, ScalePattern.getValue()); +} + +/* static */ +std::vector DrawCrosshatch::getDrawableLines(DrawViewPart* source, std::vector lineSets, int iface, double scale ) +{ + std::vector result; + + //is source is a section? + DrawViewSection* section = dynamic_cast(source); + bool usingSection = false; + if (section != nullptr) { + usingSection = true; + } - if (m_lineSets.empty()) { - Base::Console().Message("TRACE - DC::getDrawableLines - no LineSets!\n"); + if (lineSets.empty()) { + Base::Console().Log("INFO - DC::getDrawableLines - no LineSets!\n"); return result; } - //get geometry for linked Face - const std::vector &subElements = Source.getSubValues(); - int idx = DrawUtil::getIndexFromName(subElements[0]); + std::vector faceWires; + if (usingSection) { + faceWires = section->getWireForFace(iface); + } else { + faceWires = source->getWireForFace(iface); + } - //build wire(s) from geometry - std::vector faceWires = source->getWireForFace(idx); - gp_Pln plane = source->getProjPlane(); + //build face(s) from geometry + gp_Pnt gOrg(0.0,0.0,0.0); + gp_Dir gDir(0.0,0.0,1.0); + gp_Pln plane(gOrg,gDir); BRepBuilderAPI_MakeFace mkFace(plane, faceWires.front(), true); std::vector::iterator itWire = ++faceWires.begin(); //starting with second wire @@ -255,7 +219,7 @@ std::vector DrawCrosshatch::getDrawableLines() mkFace.Add(*itWire); } if (!mkFace.IsDone()) { - Base::Console().Message("TRACE - DC::getDrawableLines - face creation failed\n"); + Base::Console().Log("INFO - DC::getDrawableLines - face creation failed\n"); return result; } TopoDS_Face face = mkFace.Face(); @@ -263,11 +227,10 @@ std::vector DrawCrosshatch::getDrawableLines() Bnd_Box bBox; BRepBndLib::Add(face, bBox); bBox.SetGap(0.0); -// face & box are done! - - for (auto& ls: m_lineSets) { + + for (auto& ls: lineSets) { HatchLine hl = ls.getHatchLine(); - std::vector candidates = DrawCrosshatch::makeEdgeOverlay(hl, bBox); + std::vector candidates = DrawCrosshatch::makeEdgeOverlay(hl, bBox, scale); //make Compound for this linespec BRep_Builder builder; @@ -281,7 +244,7 @@ std::vector DrawCrosshatch::getDrawableLines() BRepAlgoAPI_Common mkCommon(face, Comp); if ((!mkCommon.IsDone()) || (mkCommon.Shape().IsNull()) ) { - Base::Console().Message("TRACE - DC::getDrawableLines - Common creation failed\n"); + Base::Console().Log("INFO - DC::getDrawableLines - Common creation failed\n"); return result; } TopoDS_Shape common = mkCommon.Shape(); @@ -294,12 +257,12 @@ std::vector DrawCrosshatch::getDrawableLines() for ( int i = 1 ; i <= mapOfEdges.Extent() ; i++ ) { const TopoDS_Edge& edge = TopoDS::Edge(mapOfEdges(i)); if (edge.IsNull()) { - Base::Console().Message("TRACE - DC::getDrawableLines - edge: %d is NULL\n",i); + Base::Console().Log("INFO - DC::getDrawableLines - edge: %d is NULL\n",i); continue; } TechDrawGeometry::BaseGeom* base = BaseGeom::baseFactory(edge); if (base == nullptr) { - Base::Console().Message("TRACE - DC::getDrawableLines - baseFactory failed for edge: %d\n",i); + Base::Console().Log("FAIL - DC::getDrawableLines - baseFactory failed for edge: %d\n",i); throw Base::Exception("GeometryObject::addGeomFromCompound - baseFactory failed"); } resultGeoms.push_back(base); @@ -311,8 +274,8 @@ std::vector DrawCrosshatch::getDrawableLines() } return result; } - -std::vector DrawCrosshatch::makeEdgeOverlay(HatchLine hl, Bnd_Box b) +/* static */ +std::vector DrawCrosshatch::makeEdgeOverlay(HatchLine hl, Bnd_Box b, double scale) { std::vector result; @@ -322,7 +285,8 @@ std::vector DrawCrosshatch::makeEdgeOverlay(HatchLine hl, Bnd_Box b Base::Vector3d start; Base::Vector3d end; Base::Vector3d origin = hl.getOrigin(); - double interval = hl.getInterval() * ScalePattern.getValue(); +// double interval = hl.getInterval() * ScalePattern.getValue(); + double interval = hl.getInterval() * scale; double angle = hl.getAngle(); //only dealing with angles -180:180 for now @@ -422,6 +386,30 @@ TopoDS_Edge DrawCrosshatch::makeLine(Base::Vector3d s, Base::Vector3d e) return result; } +void DrawCrosshatch::getParameters(void) +{ +//this is probably "/build/data/Mod/TechDraw/PAT" + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); + + std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/PAT/"; + std::string defaultFileName = defaultDir + "FCStd.pat"; + QString patternFileName = QString::fromStdString(hGrp->GetASCII("FilePattern",defaultFileName.c_str())); + if (patternFileName.isEmpty()) { + patternFileName = QString::fromStdString(defaultFileName); + } + QFileInfo tfi(patternFileName); + if (tfi.isReadable()) { + FilePattern.setValue(patternFileName.toUtf8().constData()); + } + hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); + std::string defaultNamePattern = "Diamond"; + NamePattern.setValue(hGrp->GetASCII("NamePattern",defaultNamePattern.c_str())); + +} + + PyObject *DrawCrosshatch::getPyObject(void) { if (PythonObject.is(Py::_None())) { diff --git a/src/Mod/TechDraw/App/DrawCrosshatch.h b/src/Mod/TechDraw/App/DrawCrosshatch.h index baa2adfbf..751104b52 100644 --- a/src/Mod/TechDraw/App/DrawCrosshatch.h +++ b/src/Mod/TechDraw/App/DrawCrosshatch.h @@ -28,15 +28,20 @@ # include #include -#include "HatchLine.h" -#include "Geometry.h" - class TopoDS_Edge; class Bnd_Box; +namespace TechDrawGeometry +{ +class BaseGeom; +} + namespace TechDraw { class DrawViewPart; +class HatchLine; +class LineSet; +class DashSet; class TechDrawExport DrawCrosshatch : public App::DocumentObject { @@ -46,14 +51,10 @@ public: DrawCrosshatch(); virtual ~DrawCrosshatch(); - App::PropertyVector DirProjection; //Source is only valid for original projection? - App::PropertyLinkSub Source; //the dvp & face this crosshatch belongs to + App::PropertyLinkSub Source; //the dvX & face(s) this crosshatch belongs to App::PropertyFile FilePattern; App::PropertyString NamePattern; App::PropertyFloat ScalePattern; -// App::PropertyFloat WeightPattern; -// App::PropertyColor ColorPattern; -// App::PropertyStringList LineSpecs; virtual short mustExecute() const; virtual App::DocumentObjectExecReturn *execute(void); @@ -63,15 +64,18 @@ public: } virtual PyObject *getPyObject(void); - std::vector getDrawableLines(); DrawViewPart* getSourceView(void) const; - void adviseParent(void) const; //don't like this! - + + std::vector getDrawableLines(int i = 0); + static std::vector getDrawableLines(DrawViewPart* dvp, std::vector lineSets, int iface, double scale); + + static std::vector makeEdgeOverlay(HatchLine hl, Bnd_Box bBox, double scale); + static TopoDS_Edge makeLine(Base::Vector3d s, Base::Vector3d e); + static std::vector getDecodedSpecsFromFile(std::string fileSpec, std::string myPattern); protected: - TopoDS_Edge makeLine(Base::Vector3d s, Base::Vector3d e); + void getParameters(void); std::vector getDecodedSpecsFromFile(); - std::vector makeEdgeOverlay(HatchLine hl, Bnd_Box bBox); std::vector m_lineSets; private: diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 7b7a19336..64a9a3425 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -58,16 +58,20 @@ #include #include #include +#include +#include +#include + #include #include #include +#include #endif #include #include #include -#include #include #include @@ -80,6 +84,7 @@ #include "DrawUtil.h" #include "DrawViewSection.h" +#include "DrawProjectSplit.h" #include "Geometry.h" #include "GeometryObject.h" #include "DrawViewPart.h" diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 8c8860189..e15a363fb 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -37,10 +37,14 @@ #include #include "DrawView.h" -#include "DrawProjectSplit.h" class gp_Pnt; class gp_Pln; +class gp_Ax2; +//class TopoDS_Edge; +//class TopoDS_Vertex; +//class TopoDS_Wire; +//class TopoDS_Shape; namespace TechDrawGeometry { @@ -53,6 +57,8 @@ class Face; namespace TechDraw { class DrawHatch; class DrawCrosshatch; +class DrawProjectSplit; +class DrawViewSection; } namespace TechDraw @@ -141,7 +147,7 @@ public: bool isDeleting(void) { return nowDeleting; } gp_Pln getProjPlane(void) const; - std::vector getWireForFace(int idx) const; + virtual std::vector getWireForFace(int idx) const; protected: diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 0b6d07b9e..a807834f1 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -63,20 +64,24 @@ # include #include +#include #include #include #include #include +#include #include #include #include "Geometry.h" #include "GeometryObject.h" +#include "HatchLine.h" #include "EdgeWalker.h" #include "DrawUtil.h" #include "DrawProjGroupItem.h" #include "DrawProjectSplit.h" +#include "DrawCrosshatch.h" #include "DrawViewSection.h" using namespace TechDraw; @@ -110,13 +115,18 @@ DrawViewSection::DrawViewSection() SectionDirection.setEnums(SectionDirEnums); ADD_PROPERTY_TYPE(SectionDirection,((long)0),sgroup, App::Prop_None, "Direction in Base View for this Section"); - ADD_PROPERTY_TYPE(ShowCutSurface ,(true),fgroup,App::Prop_None,"Shade the cut surface"); - ADD_PROPERTY_TYPE(CutSurfaceColor,(0.0,0.0,0.0),fgroup,App::Prop_None,"The color to shade the cut surface"); - ADD_PROPERTY_TYPE(HatchCutSurface ,(false),fgroup,App::Prop_None,"Hatch the cut surface"); - ADD_PROPERTY_TYPE(HatchPattern ,(""),fgroup,App::Prop_None,"The hatch pattern file for the cut surface"); - ADD_PROPERTY_TYPE(HatchColor,(0.0,0.0,0.0),fgroup,App::Prop_None,"The color of the hatch pattern"); + ADD_PROPERTY_TYPE(FileHatchPattern ,(""),fgroup,App::Prop_None,"The hatch pattern file for the cut surface"); + ADD_PROPERTY_TYPE(NameGeomPattern ,(""),fgroup,App::Prop_None,"The pattern name for geometric hatching"); ADD_PROPERTY_TYPE(HatchScale,(1.0),fgroup,App::Prop_None,"Hatch pattern size adjustment"); +// ADD_PROPERTY_TYPE(ShowCutSurface ,(true),fgroup,App::Prop_None,"Show/hide the cut surface"); +// ADD_PROPERTY_TYPE(CutSurfaceColor,(0.0,0.0,0.0),fgroup,App::Prop_None,"The color to shade the cut surface"); +// ADD_PROPERTY_TYPE(HatchCutSurface ,(false),fgroup,App::Prop_None,"Hatch the cut surface"); +// ADD_PROPERTY_TYPE(FileHatchPattern ,(""),fgroup,App::Prop_None,"The hatch pattern file for the cut surface"); +// ADD_PROPERTY_TYPE(NameGeomPattern ,(""),fgroup,App::Prop_None,"The pattern name for geometric hatching"); +// ADD_PROPERTY_TYPE(HatchColor,(0.0,0.0,0.0),fgroup,App::Prop_None,"The color of the hatch pattern"); + + getParameters(); } @@ -159,6 +169,23 @@ void DrawViewSection::onChanged(const App::Property* prop) } } } + if (prop == &FileHatchPattern || + prop == &NameGeomPattern ) { + if ((!FileHatchPattern.isEmpty()) && + (!NameGeomPattern.isEmpty())) { + std::vector specs = + DrawCrosshatch::getDecodedSpecsFromFile(FileHatchPattern.getValue(),NameGeomPattern.getValue()); + m_lineSets.clear(); + for (auto& hl: specs) { + //hl.dump("hl from section"); + LineSet ls; + ls.setHatchLine(hl); + m_lineSets.push_back(ls); + } + + } + } + DrawView::onChanged(prop); } @@ -249,10 +276,12 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) inputCenter, Scale.getValue()); + sectionFaceWires.clear(); TopoDS_Compound newFaces; BRep_Builder builder; builder.MakeCompound(newFaces); TopExp_Explorer expl(mirroredSection, TopAbs_FACE); + int idb = 0; for (; expl.More(); expl.Next()) { const TopoDS_Face& face = TopoDS::Face(expl.Current()); TopoDS_Face pFace = projectFace(face, @@ -260,8 +289,9 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) Direction.getValue()); if (!pFace.IsNull()) { builder.Add(newFaces,pFace); + sectionFaceWires.push_back(ShapeAnalysis::OuterWire(pFace)); } - + idb++; } sectionFaces = newFaces; } @@ -506,6 +536,20 @@ Base::Vector3d DrawViewSection::getSectionVector (const std::string sectionName) return adjResult; } +std::vector DrawViewSection::getDrawableLines(int i) +{ + std::vector result; + result = DrawCrosshatch::getDrawableLines(this,m_lineSets,i,HatchScale.getValue()); + return result; +} + +std::vector DrawViewSection::getWireForFace(int idx) const +{ + std::vector result; + result.push_back(sectionFaceWires.at(idx)); + return result; +} + void DrawViewSection::unsetupObject() { getBaseDVP()->touch(); @@ -534,13 +578,6 @@ TechDraw::DrawProjGroupItem* DrawViewSection::getBaseDPGI() void DrawViewSection::getParameters() { Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); - App::Color cutColor = App::Color((uint32_t) hGrp->GetUnsigned("CutSurfaceColor", 0xC8C8C800)); - CutSurfaceColor.setValue(cutColor); - App::Color hatchColor = App::Color((uint32_t) hGrp->GetUnsigned("SectionHatchColor", 0x00000000)); - HatchColor.setValue(hatchColor); - - hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw"); std::string defaultDir = App::Application::getResourceDir() + "Mod/Drawing/patterns/"; @@ -551,9 +588,10 @@ void DrawViewSection::getParameters() } QFileInfo tfi(patternFileName); if (tfi.isReadable()) { - HatchPattern.setValue(patternFileName.toUtf8().constData()); + FileHatchPattern.setValue(patternFileName.toUtf8().constData()); } - + std::string patternName = hGrp->GetASCII("PatternName","Diamond"); + NameGeomPattern.setValue(patternName); } // Python Drawing feature --------------------------------------------------------- diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index 7ff5a2855..606a8fbd7 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -45,16 +45,16 @@ class Face; namespace TechDraw { class DrawProjGroupItem; +class DrawCrosshatch; +class HatchLine; +class LineSet; +class DashSet; - -/** Base class of all View Features in the drawing module - */ class TechDrawExport DrawViewSection : public DrawViewPart { PROPERTY_HEADER(Part::DrawViewSection); public: - /// Constructor DrawViewSection(void); virtual ~DrawViewSection(); @@ -62,24 +62,16 @@ public: App::PropertyVector SectionNormal; App::PropertyVector SectionOrigin; App::PropertyEnumeration SectionDirection; - App::PropertyBool ShowCutSurface; - App::PropertyColor CutSurfaceColor; - App::PropertyBool HatchCutSurface; - App::PropertyFile HatchPattern; - App::PropertyColor HatchColor; + App::PropertyFile FileHatchPattern; + App::PropertyString NameGeomPattern; App::PropertyFloat HatchScale; App::PropertyString SectionSymbol; virtual short mustExecute() const; bool isReallyInBox (const Base::Vector3d v, const Base::BoundBox3d bb) const; - /** @name methods overide Feature */ - //@{ - /// recalculate the Feature + virtual App::DocumentObjectExecReturn *execute(void); virtual void onChanged(const App::Property* prop); - //@} - - /// returns the type name of the ViewProvider virtual const char* getViewProviderName(void) const { return "TechDrawGui::ViewProviderViewSection"; } @@ -91,10 +83,20 @@ public: TechDraw::DrawProjGroupItem* getBaseDPGI(); virtual void unsetupObject(); + virtual std::vector getWireForFace(int idx) const; + TopoDS_Compound getSectionFaces() { return sectionFaces;}; + std::vector getSectionFaceWires(void) { return sectionFaceWires; } + + std::vector getDrawableLines(int i = 0); + std::vector getDecodedSpecsFromFile(std::string fileSpec, std::string myPattern); + static const char* SectionDirEnums[]; protected: TopoDS_Compound sectionFaces; + std::vector sectionFaceWires; + std::vector m_lineSets; + gp_Pln getSectionPlane() const; TopoDS_Compound findSectionPlaneIntersections(const TopoDS_Shape& shape); diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index b2f98a02b..5461a4de1 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -34,6 +34,7 @@ #include "Geometry.h" + namespace TechDraw { class DrawViewPart; @@ -43,6 +44,10 @@ class DrawView; namespace TechDrawGeometry { +class BaseGeom; +class Vector; +class Face; +class Vertex; //! scales & mirrors a shape about a center TopoDS_Shape TechDrawExport mirrorShape(const TopoDS_Shape &input, diff --git a/src/Mod/TechDraw/App/HatchLine.cpp b/src/Mod/TechDraw/App/HatchLine.cpp index e469c00c0..3f36c9b2a 100644 --- a/src/Mod/TechDraw/App/HatchLine.cpp +++ b/src/Mod/TechDraw/App/HatchLine.cpp @@ -30,7 +30,12 @@ #include #endif +#include + #include +#include + +#include "Geometry.h" #include "DrawUtil.h" #include "HatchLine.h" diff --git a/src/Mod/TechDraw/App/HatchLine.h b/src/Mod/TechDraw/App/HatchLine.h index 8ed3142a0..6a686605f 100644 --- a/src/Mod/TechDraw/App/HatchLine.h +++ b/src/Mod/TechDraw/App/HatchLine.h @@ -31,7 +31,12 @@ #include -#include "Geometry.h" +class TopoDS_Edge; + +namespace TechDrawGeometry +{ +class BaseGeom; +} namespace TechDraw { @@ -40,6 +45,7 @@ class DrawUtil; // HatchLine is the result of parsing a line from PAT file into accessible parameters +// e /HatchLine/PATSpecLine/ class HatchLine { public: @@ -65,7 +71,7 @@ public: private: void init(void); std::vector split(std::string line); - + //PAT line extracted tokens double m_angle; Base::Vector3d m_origin; double m_interval; @@ -73,7 +79,7 @@ private: std::vector m_dashParms; //why isn't this a DashSpec object? }; -// a LineSet is all the generated edges for a HatchLine +// a LineSet is all the generated edges for 1 HatchLine for 1 Face class LineSet { public: @@ -88,6 +94,7 @@ public: std::vector getDashSpec(void) { return m_hatchLine.getDashParms();} std::vector getEdges(void) { return m_edges; } std::vector getGeoms(void) { return m_geoms; } + //void clearGeom(void); private: std::vector m_edges; diff --git a/src/Mod/TechDraw/Gui/QGIFace.cpp b/src/Mod/TechDraw/Gui/QGIFace.cpp index b35afbaa5..8d2960f3c 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.cpp +++ b/src/Mod/TechDraw/Gui/QGIFace.cpp @@ -74,8 +74,8 @@ QGIFace::QGIFace(int index) : m_styleNormal = m_styleDef; m_fillStyle = m_styleDef; m_colNormalFill = m_colDefFill; - setCrosshatchColor(QColor(Qt::black)); - setCrosshatchWeight(0.5); //0 = cosmetic + m_crossColor = QColor(Qt::black); + setLineWeight(0.5); //0 = cosmetic setPrettyNormal(); m_texture = nullptr; //empty texture @@ -247,31 +247,27 @@ void QGIFace::clearFillItems(void) } } -void QGIFace::setCrosshatchColor(const QColor& c) -{ - m_crossColor = c; -} - //convert from PAT style "-1,0,-1,+1" to Qt style "mark,space,mark,space" QVector QGIFace::decodeDashSpec(DashSpec patDash) { //Rez::guiX(something)? - double dotLength = 3.0; //guess work! + double dotLength = 3.0; double unitLength = 6.0; - //double penWidth = m_crossWeight; +// double penWidth = m_crossWeight; //mark, space and dot lengths are to be in terms of penWidth(Qt) or mm(PAT)?? +// //if we want it in terms of mm, we need to divide by penWidth? +// double minPen = 0.01; //avoid trouble with cosmetic pen (zero width) std::vector result; + std::string prim; for (auto& d: patDash.get()) { double strokeLength; if (DrawUtil::fpCompare(d,0.0)) { //pat dot strokeLength = dotLength; - result.push_back(strokeLength); } else if (Rez::guiX(d) < 0) { //pat space strokeLength = fabs(Rez::guiX(d)) * unitLength; - result.push_back(strokeLength); } else { //pat dash strokeLength = Rez::guiX(d) * unitLength; - result.push_back(strokeLength); } + result.push_back(strokeLength); } return QVector::fromStdVector( result ); } @@ -284,8 +280,8 @@ QPen QGIFace::setCrossPen(int i) //ourSpec.dump("our spec"); QPen result; -// result.setWidthF(m_crossWeight); - result.setWidthF(Rez::guiX(0.09)); + result.setWidthF(Rez::guiX(m_crossWeight)); //Rez::guiX() ?? line weights are in mm? +// result.setWidthF(Rez::guiX(0.09)); result.setColor(m_crossColor); if (ourSpec.empty()) { result.setStyle(Qt::SolidLine); @@ -349,11 +345,10 @@ QPixmap QGIFace::textureFromSvg(std::string fileSpec) return result; } -//c is a CSS color ie "#000000" -//set hatch color before building hatch -void QGIFace::setHatchColor(std::string c) +void QGIFace::setHatchColor(App::Color c) { - m_svgCol = c; + m_svgCol = c.asCSSString(); + m_crossColor = c.asValue(); } void QGIFace::setHatchScale(double s) @@ -400,6 +395,10 @@ void QGIFace::resetFill() { m_styleNormal = m_styleDef; } +void QGIFace::setLineWeight(double w) { + m_crossWeight = w; +} + QRectF QGIFace::boundingRect() const { diff --git a/src/Mod/TechDraw/Gui/QGIFace.h b/src/Mod/TechDraw/Gui/QGIFace.h index 561086efb..5d405bd93 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.h +++ b/src/Mod/TechDraw/Gui/QGIFace.h @@ -87,25 +87,25 @@ public: void setFill(QColor c, Qt::BrushStyle s); void setFill(QBrush b); void resetFill(); + + //general hatch parms & methods + void setHatchColor(App::Color c); + void setHatchScale(double s); //svg fill parms & methods void setHatchFile(std::string fileSpec); - void setHatchColor(std::string c); - void setHatchScale(double s); void loadSvgHatch(std::string fileSpec); void buildSvgHatch(void); void toggleSvg(bool b); void clearSvg(void); //PAT fill parms & methods -// void setCrosshatch(const QPainterPath& p); - void setCrosshatchColor(const QColor& c); void setCrosshatchWeight(double w) { m_crossWeight = w; } - //void setLineSets(std::vector ls); void clearLineSets(void); void addLineSet(QPainterPath pp, std::vector dp); QGraphicsPathItem* addFillItem(); void clearFillItems(void); + void setLineWeight(double w); //bitmap texture fill parms method QPixmap textureFromBitmap(std::string fileSpec); @@ -126,7 +126,6 @@ protected: QPen setCrossPen(int i); QVector decodeDashSpec(DashSpec d); -// QGraphicsPathItem* m_fillItem; std::vector m_fillItems; std::vector m_crossHatchPaths; // 0/1 dashspec per crosshatchpath std::vector m_dashSpecs; diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 39bb34b3b..f22e116fb 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -388,36 +388,39 @@ void QGIViewPart::drawViewPart() TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs); TechDraw::DrawCrosshatch* fCross = faceIsCrosshatched(i,crossObjs); if (fCross) { - std::vector lineSets = fCross->getDrawableLines(); - if (!lineSets.empty()) { - newFace->clearLineSets(); - for (auto& ls: lineSets) { - QPainterPath bigPath; - for (auto& g: ls.getGeoms()) { - QPainterPath smallPath = drawPainterPath(g); - bigPath.addPath(smallPath); + const std::vector &sourceNames = fCross->Source.getSubValues(); + if (!sourceNames.empty()) { + int fdx = TechDraw::DrawUtil::getIndexFromName(sourceNames.at(0)); + std::vector lineSets = fCross->getDrawableLines(fdx); + if (!lineSets.empty()) { + newFace->clearLineSets(); + for (auto& ls: lineSets) { + QPainterPath bigPath; + for (auto& g: ls.getGeoms()) { + QPainterPath smallPath = drawPainterPath(g); + bigPath.addPath(smallPath); + } + newFace->addLineSet(bigPath,ls.getDashSpec()); + } + newFace->isHatched(true); + newFace->setFillMode(QGIFace::CrosshatchFill); + newFace->setHatchScale(fCross->ScalePattern.getValue()); + newFace->setHatchFile(fCross->FilePattern.getValue()); + Gui::ViewProvider* gvp = QGIView::getViewProvider(fCross); + ViewProviderCrosshatch* crossVp = dynamic_cast(gvp); + if (crossVp != nullptr) { + newFace->setHatchColor(crossVp->ColorPattern.getValue()); + newFace->setLineWeight(crossVp->WeightPattern.getValue()); } - newFace->addLineSet(bigPath,ls.getDashSpec()); - } - newFace->isHatched(true); - newFace->setFillMode(QGIFace::CrosshatchFill); - newFace->setHatchScale(fCross->ScalePattern.getValue()); - Gui::ViewProvider* gvp = QGIView::getViewProvider(fCross); - ViewProviderCrosshatch* crossVp = dynamic_cast(gvp); - if (crossVp != nullptr) { - App::Color hColor = crossVp->ColorPattern.getValue(); - newFace->setCrosshatchColor(hColor.asValue()); -// newFace->setLineWeight(crossVp->WeightPattern.getValue()); } } } else if (fHatch) { if (!fHatch->HatchPattern.isEmpty()) { - newFace->setHatchFile(fHatch->HatchPattern.getValue()); - App::Color hColor = fHatch->HatchColor.getValue(); - newFace->setHatchColor(hColor.asCSSString()); - newFace->setHatchScale(fHatch->HatchScale.getValue()); newFace->isHatched(true); newFace->setFillMode(QGIFace::FromFile); + newFace->setHatchFile(fHatch->HatchPattern.getValue()); + newFace->setHatchScale(fHatch->HatchScale.getValue()); + newFace->setHatchColor(fHatch->HatchColor.getValue()); } } newFace->setDrawEdges(true); diff --git a/src/Mod/TechDraw/Gui/QGIViewSection.cpp b/src/Mod/TechDraw/Gui/QGIViewSection.cpp index dcb52620b..cecbd4df1 100644 --- a/src/Mod/TechDraw/Gui/QGIViewSection.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewSection.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -38,10 +40,14 @@ #include #include +#include +#include #include + #include "ZVALUE.h" +#include "ViewProviderViewSection.h" #include "QGIFace.h" #include "QGIViewSection.h" @@ -64,7 +70,13 @@ void QGIViewSection::drawSectionFace() return; } - if ( !section->hasGeometry() || !section->ShowCutSurface.getValue() ) { + if ( !section->hasGeometry()) { + return; + } + Gui::ViewProvider* gvp = QGIView::getViewProvider(section); + ViewProviderViewSection* sectionVp = dynamic_cast(gvp); + if ((sectionVp == nullptr) || + (!sectionVp->ShowCutSurface.getValue())) { return; } @@ -73,9 +85,11 @@ void QGIViewSection::drawSectionFace() //Base::Console().Log("INFO - QGIViewSection::drawSectionFace - No sectionFaces available. Check Section plane.\n"); return; } + std::vector::iterator fit = sectionFaces.begin(); - QColor faceColor = section->CutSurfaceColor.getValue().asValue(); - for(; fit != sectionFaces.end(); fit++) { + QColor faceColor = (sectionVp->CutSurfaceColor.getValue()).asValue(); + int i = 0; + for(; fit != sectionFaces.end(); fit++, i++) { QGIFace* newFace = drawFace(*fit,-1); newFace->setZValue(ZVALUE::SECTIONFACE); if (section->showSectionEdges()) { @@ -83,14 +97,39 @@ void QGIViewSection::drawSectionFace() } else { newFace->setDrawEdges(false); } - if (section->HatchCutSurface.getValue()) { - App::Color hColor = section->HatchColor.getValue(); - newFace->setHatchColor(hColor.asCSSString()); - newFace->setHatchFile(section->HatchPattern.getValue()); - newFace->setHatchScale(section->HatchScale.getValue()); - newFace->isHatched(true); - } newFace->setFill(faceColor, Qt::SolidPattern); + + if (sectionVp->HatchCutSurface.getValue()) { + newFace->isHatched(true); + newFace->setFillMode(QGIFace::FromFile); + newFace->setHatchColor(sectionVp->HatchColor.getValue()); + newFace->setHatchScale(section->HatchScale.getValue()); + + std::string hatchFile = section->FileHatchPattern.getValue(); + newFace->setHatchFile(hatchFile); + std::string patternName = section->NameGeomPattern.getValue(); + QFileInfo hfi(QString::fromUtf8(hatchFile.data(),hatchFile.size())); + if (hfi.isReadable()) { + QString ext = hfi.suffix(); + if ((ext.toUpper() == QString::fromUtf8("PAT")) && + !patternName.empty() ) { + newFace->setFillMode(QGIFace::CrosshatchFill); + newFace->setLineWeight(sectionVp->WeightPattern.getValue()); + std::vector lineSets = section->getDrawableLines(i); + if (!lineSets.empty()) { + newFace->clearLineSets(); + for (auto& ls: lineSets) { + QPainterPath bigPath; + for (auto& g: ls.getGeoms()) { + QPainterPath smallPath = drawPainterPath(g); + bigPath.addPath(smallPath); + } + newFace->addLineSet(bigPath,ls.getDashSpec()); + } + } + } + } + } newFace->draw(); newFace->setPrettyNormal(); newFace->setAcceptHoverEvents(false); diff --git a/src/Mod/TechDraw/Gui/ViewProviderCrosshatch.cpp b/src/Mod/TechDraw/Gui/ViewProviderCrosshatch.cpp index abc342a85..5ef17124b 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderCrosshatch.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderCrosshatch.cpp @@ -36,11 +36,23 @@ #include #include -//#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include + #include +#include #include +#include "ViewProviderDrawingView.h" #include "ViewProviderCrosshatch.h" using namespace TechDrawGui; @@ -55,11 +67,11 @@ ViewProviderCrosshatch::ViewProviderCrosshatch() static const char *vgroup = "Format"; sPixmap = "actions/techdraw-crosshatch"; - App::Color fcColor; - fcColor.setPackedValue(0x00000000); - ADD_PROPERTY_TYPE(ColorPattern,(fcColor),vgroup,App::Prop_None,"The color of the pattern"); - ADD_PROPERTY_TYPE(WeightPattern,(0.0),vgroup,App::Prop_None,"Crosshatch pattern line thickness"); + ADD_PROPERTY_TYPE(ColorPattern,(0),vgroup,App::Prop_None,"The color of the pattern"); + ADD_PROPERTY_TYPE(WeightPattern,(0.1),vgroup,App::Prop_None,"Crosshatch pattern line thickness"); + + getParameters(); } @@ -89,7 +101,10 @@ std::vector ViewProviderCrosshatch::getDisplayModes(void) const //for VP properties void ViewProviderCrosshatch::onChanged(const App::Property* prop) { -// Base::Console().Message("TRACE - VPC::onChanged(%s)\n",prop->getName()); + if (prop == &WeightPattern || + prop == &ColorPattern ) { + updateGraphic(); + } Gui::ViewProviderDocumentObject::onChanged(prop); } @@ -97,29 +112,46 @@ void ViewProviderCrosshatch::onChanged(const App::Property* prop) //for feature properties void ViewProviderCrosshatch::updateData(const App::Property* prop) { -// Base::Console().Message("TRACE - VPC::updateData(%s)\n",prop->getName()); - if (prop == &WeightPattern || - prop == &ColorPattern || - prop == &(getViewObject()->ScalePattern)) { - //Base::Console().Message("TRACE - VPC::updateData - should update parent now\n"); - //how does QGIVP find this VP to get properties? -// Gui::ViewProvider* view = Application::Instance->getDocument(it->pDoc)->getViewProvider(it->pObject); -// TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); -// Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); -// TechDrawGui::ViewProviderPage* dvp = dynamic_cast(vp); -// if (dvp) { -// dvp->show(); - - // redraw QGIVP - //QGIView* qgiv = getQView(); this will be different have to find source's QView -// if (qgiv) { -// qgiv->updateView(true); -// } - } - + if (prop == &(getViewObject()->ScalePattern)) { + updateGraphic(); + } Gui::ViewProviderDocumentObject::updateData(prop); } +void ViewProviderCrosshatch::updateGraphic(void) +{ + TechDraw::DrawCrosshatch* dc = getViewObject(); + if (dc) { + TechDraw::DrawViewPart* dvp = dc->getSourceView(); + if (dvp) { + Gui::ViewProvider* view = Gui::Application::Instance->getDocument(dvp->getDocument())->getViewProvider(dvp); + TechDrawGui::ViewProviderDrawingView* vpDV = dynamic_cast(view); + if (vpDV) { + vpDV->show(); + QGIView* qgiv = vpDV->getQView(); + if (qgiv) { + qgiv->updateView(true); + } + } + } + } +} + + +void ViewProviderCrosshatch::getParameters(void) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("Crosshatch", 0x00000000)); + ColorPattern.setValue(fcColor); + + hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); + double lineWeight = hGrp->GetFloat("GeomWeight",0.1); + WeightPattern.setValue(lineWeight); +} + TechDraw::DrawCrosshatch* ViewProviderCrosshatch::getViewObject() const { return dynamic_cast(pcObject); diff --git a/src/Mod/TechDraw/Gui/ViewProviderCrosshatch.h b/src/Mod/TechDraw/Gui/ViewProviderCrosshatch.h index 15c52c682..2c8bd0f69 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderCrosshatch.h +++ b/src/Mod/TechDraw/Gui/ViewProviderCrosshatch.h @@ -31,6 +31,7 @@ #include + namespace TechDraw{ class DrawCrosshatch; } @@ -59,6 +60,8 @@ public: virtual bool useNewSelectionModel(void) const {return false;} virtual void setDisplayMode(const char* ModeName); virtual std::vector getDisplayModes(void) const; + void updateGraphic(void); + void getParameters(void); TechDraw::DrawCrosshatch* getViewObject() const; }; diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index 0a118fc9b..62e00560d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -37,13 +37,9 @@ #include #include -#include #include #include -#include -#include #include -#include #include #include @@ -143,13 +139,16 @@ QGIView* ViewProviderDrawingView::getQView(void) { QGIView *qView = nullptr; if (m_docReady){ - Gui::Document* guiDoc = Gui::Application::Instance->getDocument(getViewObject()->getDocument()); - Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage()); - ViewProviderPage* dvp = dynamic_cast(vp); - if (dvp) { - if (dvp->getMDIViewPage()) { - if (dvp->getMDIViewPage()->getQGVPage()) { - qView = dynamic_cast(dvp->getMDIViewPage()->getQGVPage()->findView(getViewObject())); + TechDraw::DrawView* dv = getViewObject(); + if (dv) { + Gui::Document* guiDoc = Gui::Application::Instance->getDocument(getViewObject()->getDocument()); + Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage()); + ViewProviderPage* dvp = dynamic_cast(vp); + if (dvp) { + if (dvp->getMDIViewPage()) { + if (dvp->getMDIViewPage()->getQGVPage()) { + qView = dynamic_cast(dvp->getMDIViewPage()->getQGVPage()->findView(getViewObject())); + } } } } diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp index 6b73f0ab7..d2f70d1ad 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp @@ -48,7 +48,17 @@ PROPERTY_SOURCE(TechDrawGui::ViewProviderViewSection, TechDrawGui::ViewProviderV ViewProviderViewSection::ViewProviderViewSection() { + static const char *sgroup = "Surface"; + static const char *hgroup = "Hatch"; sPixmap = "TechDraw_Tree_Section"; + ADD_PROPERTY_TYPE(ShowCutSurface ,(true),sgroup,App::Prop_None,"Show/hide the cut surface"); + ADD_PROPERTY_TYPE(CutSurfaceColor,(0.0,0.0,0.0),sgroup,App::Prop_None,"The color to shade the cut surface"); + ADD_PROPERTY_TYPE(HatchCutSurface ,(false),hgroup,App::Prop_None,"Hatch the cut surface"); + ADD_PROPERTY_TYPE(HatchColor,(0.0,0.0,0.0),hgroup,App::Prop_None,"The color of the hatch pattern"); + ADD_PROPERTY_TYPE(WeightPattern,(0.1),hgroup,App::Prop_None,"Crosshatch pattern line thickness"); + + getParameters(); + } ViewProviderViewSection::~ViewProviderViewSection() @@ -74,16 +84,28 @@ std::vector ViewProviderViewSection::getDisplayModes(void) const return StrList; } +//for VP properties +void ViewProviderViewSection::onChanged(const App::Property* prop) +{ + if (prop == &WeightPattern || + prop == &HatchCutSurface || + prop == &HatchColor || + prop == &ShowCutSurface || + prop == &CutSurfaceColor ) { + updateGraphic(); + } + + ViewProviderViewPart::onChanged(prop); +} + +//for Feature properties void ViewProviderViewSection::updateData(const App::Property* prop) { - if (prop == &(getViewObject()->ShowCutSurface) || - prop == &(getViewObject()->CutSurfaceColor) ) { - // redraw QGIVP - QGIView* qgiv = getQView(); - if (qgiv) { - qgiv->updateView(true); - } - } + if (prop == &(getViewObject()->FileHatchPattern) || + prop == &(getViewObject()->NameGeomPattern) || + prop == &(getViewObject()->HatchScale) ) { + updateGraphic(); + } ViewProviderViewPart::updateData(prop); } @@ -93,6 +115,30 @@ std::vector ViewProviderViewSection::claimChildren(void) c return ViewProviderViewPart::claimChildren(); } +void ViewProviderViewSection::updateGraphic(void) +{ + // redraw QGIVP + QGIView* qgiv = getQView(); + if (qgiv) { + qgiv->updateView(true); + } +} + +void ViewProviderViewSection::getParameters(void) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color cutColor = App::Color((uint32_t) hGrp->GetUnsigned("CutSurfaceColor", 0xC8C8C800)); + CutSurfaceColor.setValue(cutColor); + App::Color hatchColor = App::Color((uint32_t) hGrp->GetUnsigned("SectionHatchColor", 0x00000000)); + HatchColor.setValue(hatchColor); + + hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); + double lineWeight = hGrp->GetFloat("GeomWeight",0.1); + WeightPattern.setValue(lineWeight); +} + TechDraw::DrawViewSection* ViewProviderViewSection::getViewObject() const { return dynamic_cast(pcObject); diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewSection.h b/src/Mod/TechDraw/Gui/ViewProviderViewSection.h index 5395ec8e9..a9047be9c 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewSection.h +++ b/src/Mod/TechDraw/Gui/ViewProviderViewSection.h @@ -44,14 +44,25 @@ public: /// destructor virtual ~ViewProviderViewSection(); + App::PropertyBool ShowCutSurface; + App::PropertyColor CutSurfaceColor; + App::PropertyBool HatchCutSurface; + App::PropertyColor HatchColor; + App::PropertyFloat WeightPattern; + virtual void attach(App::DocumentObject *); virtual void setDisplayMode(const char* ModeName); /// returns a list of all possible modes virtual std::vector getDisplayModes(void) const; virtual void updateData(const App::Property*); + virtual void onChanged(const App::Property *prop); + virtual std::vector claimChildren(void) const; + void updateGraphic(void); + void getParameters(void); + virtual TechDraw::DrawViewSection* getViewObject() const; };