diff --git a/src/Mod/TechDraw/App/DrawProjectSplit.cpp b/src/Mod/TechDraw/App/DrawProjectSplit.cpp index 1cc183af39..0e69b6176d 100644 --- a/src/Mod/TechDraw/App/DrawProjectSplit.cpp +++ b/src/Mod/TechDraw/App/DrawProjectSplit.cpp @@ -129,8 +129,15 @@ TechDrawGeometry::GeometryObject* DrawProjectSplit::buildGeometryObject(TopoDS_S { TechDrawGeometry::GeometryObject* geometryObject = new TechDrawGeometry::GeometryObject("DrawProjectSplit",nullptr); - geometryObject->projectShape(shape, - viewAxis); + if (geometryObject->usePolygonHLR()){ + geometryObject->projectShapeWithPolygonAlgo(shape, + viewAxis); + } + else{ + geometryObject->projectShape(shape, + viewAxis); + } + geometryObject->extractGeometry(TechDrawGeometry::ecHARD, //always show the hard&outline visible lines true); geometryObject->extractGeometry(TechDrawGeometry::ecOUTLINE, diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index fab07e9056..8fa99a850a 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -125,7 +125,7 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0) Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); double defDist = hGrp->GetFloat("FocusDistance",100.0); - + bool coarseView = hGrp->GetBool("CoarseView", false); //properties that affect Geometry ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"3D Shape to view"); @@ -135,6 +135,7 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0) ADD_PROPERTY_TYPE(Focus,(defDist),group,App::Prop_None,"Perspective view focus distance"); //properties that affect Appearance + ADD_PROPERTY_TYPE(CoarseView, (coarseView), sgroup, App::Prop_None, "Coarse View on/off"); //visible outline ADD_PROPERTY_TYPE(SmoothVisible ,(false),sgroup,App::Prop_None,"Visible Smooth lines on/off"); ADD_PROPERTY_TYPE(SeamVisible ,(false),sgroup,App::Prop_None,"Visible Seam lines on/off"); @@ -278,7 +279,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) geometryObject = buildGeometryObject(mirroredShape,viewAxis); #if MOD_TECHDRAW_HANDLE_FACES - if (handleFaces()) { + if (handleFaces() && !geometryObject->usePolygonHLR()) { try { extractFaces(); } @@ -323,12 +324,19 @@ TechDrawGeometry::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape go->setIsoCount(IsoCount.getValue()); go->isPerspective(Perspective.getValue()); go->setFocus(Focus.getValue()); + go->usePolygonHLR(CoarseView.getValue()); Base::Vector3d baseProjDir = Direction.getValue(); saveParamSpace(baseProjDir); - go->projectShape(shape, - viewAxis); + if (go->usePolygonHLR()){ + go->projectShapeWithPolygonAlgo(shape, + viewAxis); + } + else{ + go->projectShape(shape, + viewAxis); + } go->extractGeometry(TechDrawGeometry::ecHARD, //always show the hard&outline visible lines true); go->extractGeometry(TechDrawGeometry::ecOUTLINE, diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 10ca8daebf..3addf317ab 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -87,6 +87,7 @@ public: App::PropertyBool Perspective; App::PropertyDistance Focus; + App::PropertyBool CoarseView; App::PropertyBool SeamVisible; App::PropertyBool SmoothVisible; //App::PropertyBool OutlinesVisible; diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 283e76d6a4..5cb36e492e 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -43,6 +43,14 @@ #include #include #include + + +#include +#include +#include +#include +#include + #include #include #include @@ -83,7 +91,9 @@ GeometryObject::GeometryObject(const string& parent, TechDraw::DrawView* parentO m_parent(parentObj), m_isoCount(0), m_isPersp(false), - m_focus(100.0) + m_focus(100.0), + m_usePolygonHLR(false) + { } @@ -209,9 +219,77 @@ void GeometryObject::projectShape(const TopoDS_Shape& input, catch (...) { Standard_Failure::Raise("GeometryObject::projectShape - error occurred while extracting edges"); } - } +//!set up a hidden line remover and project a shape with it +void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input, + const gp_Ax2 viewAxis) +{ + // Clear previous Geometry + clear(); + + auto start = chrono::high_resolution_clock::now(); + + Handle(HLRBRep_PolyAlgo) brep_hlrPoly = NULL; + + try { + TopExp_Explorer faces(input, TopAbs_FACE); + for (int i = 1; faces.More(); faces.Next(), i++) { + const TopoDS_Face& f = TopoDS::Face(faces.Current()); + if (!f.IsNull()) { + BRepMesh_IncrementalMesh(f, 0.10); //Poly Algo requires a mesh! + } + } + brep_hlrPoly = new HLRBRep_PolyAlgo(); + brep_hlrPoly->Load(input); + if (m_isPersp) { + double fLength = std::max(Precision::Confusion(), m_focus); + HLRAlgo_Projector projector(viewAxis, fLength); + brep_hlrPoly->Projector(projector); + } + else { // non perspective + HLRAlgo_Projector projector(viewAxis); + brep_hlrPoly->Projector(projector); + } + brep_hlrPoly->Update(); + } + catch (...) { + Standard_Failure::Raise("GeometryObject::projectShapeWithPolygonAlgo - error occurred while projecting shape"); + } + auto end = chrono::high_resolution_clock::now(); + auto diff = end - start; + double diffOut = chrono::duration (diff).count(); + Base::Console().Log("TIMING - %s GO spent: %.3f millisecs in HLRBRep_PolyAlgo & co\n", m_parentName.c_str(), diffOut); + + try { + HLRBRep_PolyHLRToShape polyhlrToShape; + polyhlrToShape.Update(brep_hlrPoly); + + visHard = polyhlrToShape.VCompound(); + visSmooth = polyhlrToShape.Rg1LineVCompound(); + visSeam = polyhlrToShape.RgNLineVCompound(); + visOutline = polyhlrToShape.OutLineVCompound(); + hidHard = polyhlrToShape.HCompound(); + hidSmooth = polyhlrToShape.Rg1LineHCompound(); + hidSeam = polyhlrToShape.RgNLineHCompound(); + hidOutline = polyhlrToShape.OutLineHCompound(); + + //need these 3d curves to prevent "zero edges" later + BRepLib::BuildCurves3d(visHard); + BRepLib::BuildCurves3d(visSmooth); + BRepLib::BuildCurves3d(visSeam); + BRepLib::BuildCurves3d(visOutline); + BRepLib::BuildCurves3d(hidHard); + BRepLib::BuildCurves3d(hidSmooth); + BRepLib::BuildCurves3d(hidSeam); + BRepLib::BuildCurves3d(hidOutline); + } + catch (...) { + Standard_Failure::Raise("GeometryObject::projectShapeWithPolygonAlgo - error occurred while extracting edges"); + } +} + + //!add edges meeting filter criteria for category, visibility void GeometryObject::extractGeometry(edgeClass category, bool visible) { diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index a9084ea677..39e756849d 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -85,14 +85,16 @@ public: //! Returns 2D bounding box Base::BoundBox3d calcBoundingBox() const; - const std::vector & getVertexGeometry() const { return vertexGeom; }; - const std::vector & getEdgeGeometry() const { return edgeGeom; }; + const std::vector & getVertexGeometry() const { return vertexGeom; } + const std::vector & getEdgeGeometry() const { return edgeGeom; } const std::vector getVisibleFaceEdges(bool smooth, bool seam) const; - const std::vector & getFaceGeometry() const { return faceGeom; }; + const std::vector & getFaceGeometry() const { return faceGeom; } void projectShape(const TopoDS_Shape &input, const gp_Ax2 viewAxis); - + void projectShapeWithPolygonAlgo(const TopoDS_Shape &input, + const gp_Ax2 viewAxis); + void extractGeometry(edgeClass category, bool visible); void addFaceGeom(Face * f); void clearFaceGeom(); @@ -100,6 +102,8 @@ public: void setParentName(std::string n); //for debug messages void isPerspective(bool b) { m_isPersp = b; } bool isPerspective(void) { return m_isPersp; } + void usePolygonHLR(bool b) { m_usePolygonHLR = b; } + bool usePolygonHLR(void) const { return m_usePolygonHLR; } void setFocus(double f) { m_focus = f; } double getFocus(void) { return m_focus; } void pruneVertexGeom(Base::Vector3d center, double radius); @@ -150,6 +154,7 @@ protected: int m_isoCount; bool m_isPersp; double m_focus; + bool m_usePolygonHLR; }; } //namespace TechDrawGeometry diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 40aba7e481..98cf8e5e58 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -477,6 +477,7 @@ void QGIViewPart::drawViewPart() GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); double vertexScaleFactor = hGrp->GetFloat("VertexScale", 3.0); + bool usePolygonHLR = viewPart->CoarseView.getValue(); const std::vector &verts = viewPart->getVertexGeometry(); std::vector::const_iterator vert = verts.begin(); bool showCenters = viewPart->ArcCenterMarks.getValue(); @@ -491,7 +492,7 @@ void QGIViewPart::drawViewPart() cmItem->setSize( cAdjust * lineWidth * vertexScaleFactor); cmItem->setZValue(ZVALUE::VERTEX); } - } else { + } else if(!usePolygonHLR){ //Disable dots WHEN usePolygonHLR QGIVertex *item = new QGIVertex(i); addToGroup(item); item->setPos(Rez::guiX((*vert)->pnt.x), Rez::guiX((*vert)->pnt.y));