From 7e701969afedb7929b7acf45d9303a44786b2873 Mon Sep 17 00:00:00 2001 From: Wanderer Fan Date: Mon, 18 Jul 2022 19:25:51 -0400 Subject: [PATCH] [TD]run hlr and extractFaces in threads --- src/Mod/TechDraw/App/DrawView.h | 6 +- src/Mod/TechDraw/App/DrawViewDetail.cpp | 32 +-- src/Mod/TechDraw/App/DrawViewDetail.h | 2 + src/Mod/TechDraw/App/DrawViewPart.cpp | 240 +++++++++++++---------- src/Mod/TechDraw/App/DrawViewPart.h | 26 +++ src/Mod/TechDraw/App/DrawViewSection.cpp | 146 +++++++------- src/Mod/TechDraw/App/DrawViewSection.h | 6 +- src/Mod/TechDraw/App/GeometryObject.cpp | 163 +++++++++------ src/Mod/TechDraw/App/GeometryObject.h | 2 +- 9 files changed, 357 insertions(+), 266 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index 3e3a7f5f06..8c56069a6f 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -23,15 +23,17 @@ #ifndef _DrawView_h_ #define _DrawView_h_ +#include + #include #include +#include #include #include #include #include -#include namespace TechDraw @@ -44,7 +46,7 @@ class DrawLeaderLine; /** Base class of all View Features in the drawing module */ -class TechDrawExport DrawView : public App::DocumentObject +class TechDrawExport DrawView : public App::DocumentObject, public QObject { Q_DECLARE_TR_FUNCTIONS(TechDraw::DrawView) PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawView); diff --git a/src/Mod/TechDraw/App/DrawViewDetail.cpp b/src/Mod/TechDraw/App/DrawViewDetail.cpp index 961249b84d..ed88fc043c 100644 --- a/src/Mod/TechDraw/App/DrawViewDetail.cpp +++ b/src/Mod/TechDraw/App/DrawViewDetail.cpp @@ -283,11 +283,15 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape, DrawViewPart* dvp, DrawViewSection* dvs) { + if (waitingForResult()) { + Base::Console().Message("DVD::detailExec - waiting for result\n"); + return; + } + Base::Vector3d anchor = AnchorPoint.getValue(); //this is a 2D point (in unrotated coords) Base::Vector3d dirDetail = dvp->Direction.getValue(); double radius = getFudgeRadius(); - double scale = getScale(); int solidCount = DrawUtil::countSubShapes(shape, TopAbs_SOLID); int shellCount = DrawUtil::countSubShapes(shape, TopAbs_SHELL); @@ -469,33 +473,17 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape, } geometryObject = buildGeometryObject(scaledShape,viewAxis); - geometryObject->pruneVertexGeom(Base::Vector3d(0.0,0.0,0.0), - Radius.getValue() * scale); //remove vertices beyond clipradius - -#if MOD_TECHDRAW_HANDLE_FACES - if (handleFaces()) { - try { - extractFaces(); - } - catch (Standard_Failure& e4) { - Base::Console().Log("LOG - DVD::execute - extractFaces failed for %s - %s **\n",getNameInDocument(),e4.GetMessageString()); - return; - } - } - -#endif //#if MOD_TECHDRAW_HANDLE_FACES } catch (Standard_Failure& e1) { Base::Console().Message("LOG - DVD::execute - failed to create detail %s - %s **\n",getNameInDocument(),e1.GetMessageString()); return; } +} - addCosmeticVertexesToGeom(); - addCosmeticEdgesToGeom(); - addCenterLinesToGeom(); - - addReferencesToGeom(); //what if landmarks are outside detail area?? - +void DrawViewDetail::postHlrTasks(void) +{ + geometryObject->pruneVertexGeom(Base::Vector3d(0.0,0.0,0.0), + Radius.getValue() * getScale()); //remove vertices beyond clipradius } TopoDS_Shape DrawViewDetail::projectEdgesOntoFace(TopoDS_Shape edgeShape, TopoDS_Face projFace, gp_Dir projDir) diff --git a/src/Mod/TechDraw/App/DrawViewDetail.h b/src/Mod/TechDraw/App/DrawViewDetail.h index dca5cc9acc..650f569a58 100644 --- a/src/Mod/TechDraw/App/DrawViewDetail.h +++ b/src/Mod/TechDraw/App/DrawViewDetail.h @@ -75,6 +75,8 @@ public: std::vector getDetailRefs() const override; + void postHlrTasks(void) override; + protected: Base::Vector3d toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint); void getParameters(); diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index c57a6368de..1333a06d0e 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -28,6 +28,8 @@ #ifndef _PreComp_ # include +#include "QtConcurrent/qtconcurrentrun.h" + #include #include #include @@ -126,8 +128,10 @@ using namespace std; PROPERTY_SOURCE_WITH_EXTENSIONS(TechDraw::DrawViewPart, TechDraw::DrawView) -DrawViewPart::DrawViewPart() : - geometryObject(nullptr) +DrawViewPart::DrawViewPart(void) : + geometryObject(nullptr), + m_waitingForFaces(false), + m_waitingForHlr(false) { static const char *group = "Projection"; static const char *sgroup = "HLR Parameters"; @@ -246,7 +250,37 @@ std::vector DrawViewPart::getAllSources() const return result; } -App::DocumentObjectExecReturn *DrawViewPart::execute() +void DrawViewPart::addShapes2d(void) +{ + std::vector shapes = getSourceShape2d(); + for (auto& s: shapes) { + //just vertices for now + if (s.ShapeType() == TopAbs_VERTEX) { + gp_Pnt gp = BRep_Tool::Pnt(TopoDS::Vertex(s)); + Base::Vector3d vp(gp.X(), gp.Y(), gp.Z()); + vp = vp - m_saveCentroid; + //need to offset the point to match the big projection + Base::Vector3d projected = projectPoint(vp * getScale()); + TechDraw::VertexPtr v1(std::make_shared(projected)); + geometryObject->addVertex(v1); + } else if (s.ShapeType() == TopAbs_EDGE) { + //not supporting edges yet. +// Base::Console().Message("DVP::add2dShapes - found loose edge - isNull: %d\n", s.IsNull()); +// TopoDS_Shape sTrans = TechDraw::moveShape(s, +// m_saveCentroid * -1.0); +// TopoDS_Shape sScale = TechDraw::scaleShape(sTrans, +// getScale()); +// TopoDS_Shape sMirror = TechDraw::mirrorShape(sScale); +// TopoDS_Edge edge = TopoDS::Edge(sMirror); +// BaseGeomPtr bg = projectEdge(edge); + +// geometryObject->addEdge(bg); + //save connection between source feat and this edge + } + } +} + +App::DocumentObjectExecReturn *DrawViewPart::execute(void) { if (!keepUpdated()) { return App::DocumentObject::StdReturn; @@ -302,7 +336,6 @@ App::DocumentObjectExecReturn *DrawViewPart::execute() } } -//#endif //#if MOD_TECHDRAW_HANDLE_FACES return DrawView::execute(); } @@ -353,60 +386,16 @@ void DrawViewPart::onChanged(const App::Property* prop) void DrawViewPart::partExec(TopoDS_Shape shape) { // Base::Console().Message("DVP::partExec()\n"); + if (waitingForResult()) { +// Base::Console().Message("DVP::partExec - %s - GO is waiting for result\n", getNameInDocument()); + return; + } + if (geometryObject) { delete geometryObject; geometryObject = nullptr; } geometryObject = makeGeometryForShape(shape); - if (!geometryObject) - return; - -#if MOD_TECHDRAW_HANDLE_FACES - if (handleFaces() && !geometryObject->usePolygonHLR()) { - try { - extractFaces(); - } - catch (Standard_Failure& e4) { - Base::Console().Log("LOG - DVP::partExec - extractFaces failed for %s - %s **\n",getNameInDocument(),e4.GetMessageString()); - } - } -#endif //#if MOD_TECHDRAW_HANDLE_FACES -// std::vector verts = getVertexGeometry(); - addCosmeticVertexesToGeom(); - addCosmeticEdgesToGeom(); - addCenterLinesToGeom(); - - addReferencesToGeom(); -} - -void DrawViewPart::addShapes2d() -{ - std::vector shapes = getSourceShape2d(); - for (auto& s: shapes) { - //just vertices for now - if (s.ShapeType() == TopAbs_VERTEX) { - gp_Pnt gp = BRep_Tool::Pnt(TopoDS::Vertex(s)); - Base::Vector3d vp(gp.X(), gp.Y(), gp.Z()); - vp = vp - m_saveCentroid; - //need to offset the point to match the big projection - Base::Vector3d projected = projectPoint(vp * getScale()); - TechDraw::VertexPtr v1(std::make_shared(projected)); - geometryObject->addVertex(v1); - } else if (s.ShapeType() == TopAbs_EDGE) { - //not supporting edges yet. -// Base::Console().Message("DVP::add2dShapes - found loose edge - isNull: %d\n", s.IsNull()); -// TopoDS_Shape sTrans = TechDraw::moveShape(s, -// m_saveCentroid * -1.0); -// TopoDS_Shape sScale = TechDraw::scaleShape(sTrans, -// getScale()); -// TopoDS_Shape sMirror = TechDraw::mirrorShape(sScale); -// TopoDS_Edge edge = TopoDS::Edge(sMirror); -// BaseGeomPtr bg = projectEdge(edge); - -// geometryObject->addEdge(bg); - //save connection between source feat and this edge - } - } } GeometryObject* DrawViewPart::makeGeometryForShape(TopoDS_Shape shape) @@ -452,62 +441,67 @@ TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape, go->setFocus(Focus.getValue()); go->usePolygonHLR(CoarseView.getValue()); - if (go->usePolygonHLR()){ + if (CoarseView.getValue()){ go->projectShapeWithPolygonAlgo(shape, - viewAxis); - } - else{ - go->projectShape(shape, - viewAxis); + viewAxis); + onHlrFinished(); //poly algo does not run in separate thread, so we need to invoke + //the post hlr processing manually + } else { + waitingForHlr(true); + QObject::connect(&m_hlrWatcher, SIGNAL(finished()), this, SLOT(onHlrFinished())); + m_hlrFuture = QtConcurrent::run(go, &GeometryObject::projectShape, shape, viewAxis); + m_hlrWatcher.setFuture(m_hlrFuture); } - go->extractGeometry(TechDraw::ecHARD, //always show the hard&outline visible lines - true); - go->extractGeometry(TechDraw::ecOUTLINE, - true); - if (SmoothVisible.getValue()) { - go->extractGeometry(TechDraw::ecSMOOTH, - true); - } - if (SeamVisible.getValue()) { - go->extractGeometry(TechDraw::ecSEAM, - true); - } - if ((IsoVisible.getValue()) && (IsoCount.getValue() > 0)) { - go->extractGeometry(TechDraw::ecUVISO, - true); - } - if (HardHidden.getValue()) { - go->extractGeometry(TechDraw::ecHARD, - false); - go->extractGeometry(TechDraw::ecOUTLINE, - false); - } - if (SmoothHidden.getValue()) { - go->extractGeometry(TechDraw::ecSMOOTH, - false); - } - if (SeamHidden.getValue()) { - go->extractGeometry(TechDraw::ecSEAM, - false); - } - if (IsoHidden.getValue() && (IsoCount.getValue() > 0)) { - go->extractGeometry(TechDraw::ecUVISO, - false); - } - - const BaseGeomPtrVector& edges = go->getEdgeGeometry(); - if (edges.empty()) - Base::Console().Log("DVP::buildGO - NO extracted edges!\n"); - bbox = go->calcBoundingBox(); return go; } +//continue processing after hlr thread completes +void DrawViewPart::onHlrFinished(void) +{ + waitingForHlr(false); + + bbox = geometryObject->calcBoundingBox(); + + if (handleFaces() && !CoarseView.getValue()) { + try { + QObject::connect(&m_faceWatcher, SIGNAL(finished()), this, SLOT(onFacesFinished())); + m_faceFuture = QtConcurrent::run(this, &DrawViewPart::extractFaces); + m_faceWatcher.setFuture(m_faceFuture); + } + catch (Standard_Failure& e4) { + Base::Console().Message("DVP::partExec - extractFaces failed for %s - %s **\n",getNameInDocument(),e4.GetMessageString()); + } + } + + addCosmeticVertexesToGeom(); + addCosmeticEdgesToGeom(); + addCenterLinesToGeom(); + + addReferencesToGeom(); + + postHlrTasks(); + + requestPaint(); +} + +void DrawViewPart::postHlrTasks(void) +{ + //nothing to do here. DVDetail and DVSection have special needs. +} + //! make faces from the existing edge geometry void DrawViewPart::extractFaces() { - if (!geometryObject) + if (!geometryObject) { return; + } + + if (waitingForFaces()) { + return; + } + + waitingForFaces(true); geometryObject->clearFaceGeom(); const std::vector& goEdges = geometryObject->getVisibleFaceEdges(SmoothVisible.getValue(),SeamVisible.getValue()); @@ -598,10 +592,11 @@ void DrawViewPart::extractFaces() if (newEdges.empty()) { Base::Console().Log("DVP::extractFaces - no newEdges\n"); + waitingForFaces(false); return; } - newEdges = DrawProjectSplit::removeDuplicateEdges(newEdges); //<<< here + newEdges = DrawProjectSplit::removeDuplicateEdges(newEdges); //find all the wires in the pile of faceEdges EdgeWalker ew; @@ -609,6 +604,7 @@ void DrawViewPart::extractFaces() bool success = ew.perform(); if (!success) { Base::Console().Warning("DVP::extractFaces - %s -Can't make faces from projected edges\n", getNameInDocument()); + waitingForFaces(false); return; } std::vector fw = ew.getResultNoDups(); @@ -631,6 +627,15 @@ void DrawViewPart::extractFaces() f->wires.push_back(w); geometryObject->addFaceGeom(f); } + waitingForFaces(false); +} + +//continue processing after extractFaces thread completes +void DrawViewPart::onFacesFinished(void) +{ +// Base::Console().Message("DVP::onFacesFinished()\n"); + waitingForFaces(false); + requestPaint(); } std::vector DrawViewPart::getHatches() const @@ -704,7 +709,10 @@ const std::vector DrawViewPart::getVertexGeometry() const const std::vector DrawViewPart::getFaceGeometry() const { std::vector result; - if (geometryObject) { + if (waitingForFaces()) { + return result; + } + if (geometryObject != nullptr) { result = geometryObject->getFaceGeometry(); } return result; @@ -724,11 +732,11 @@ TechDraw::BaseGeomPtr DrawViewPart::getGeomByIndex(int idx) const { const std::vector &geoms = getEdgeGeometry(); if (geoms.empty()) { - Base::Console().Log("INFO - getGeomByIndex(%d) - no Edge Geometry. Probably restoring?\n",idx); + Base::Console().Log("DVP::getGeomByIndex(%d) - no Edge Geometry. Probably restoring?\n",idx); return nullptr; } if ((unsigned)idx >= geoms.size()) { - Base::Console().Log("INFO - getGeomByIndex(%d) - invalid index\n",idx); + Base::Console().Error("DVP::getGeomByIndex(%d) - invalid index - size: %d\n", idx, geoms.size()); return nullptr; } return geoms.at(idx); @@ -739,11 +747,11 @@ TechDraw::VertexPtr DrawViewPart::getProjVertexByIndex(int idx) const { const std::vector &geoms = getVertexGeometry(); if (geoms.empty()) { - Base::Console().Log("INFO - getProjVertexByIndex(%d) - no Vertex Geometry. Probably restoring?\n",idx); + Base::Console().Log("DVP::getProjVertexByIndex(%d) - no Vertex Geometry. Probably restoring?\n",idx); return nullptr; } if ((unsigned)idx >= geoms.size()) { - Base::Console().Log("INFO - getProjVertexByIndex(%d) - invalid index\n",idx); + Base::Console().Error("DVP::getProjVertexByIndex(%d) - invalid index\n",idx); return nullptr; } return geoms.at(idx); @@ -871,11 +879,28 @@ BaseGeomPtr DrawViewPart::projectEdge(const TopoDS_Edge& e) const return result; } -bool DrawViewPart::hasGeometry() const +bool DrawViewPart::waitingForResult() const +{ + bool result(false); + if (waitingForHlr()) { + result = true; + } +// if (waitingForFaces()) { +// result = true; +// } + return result; +} + +bool DrawViewPart::hasGeometry(void) const { bool result = false; - if (!geometryObject) + if (!geometryObject) { return result; + } + + if (waitingForResult()) { + return result; + } const std::vector &verts = getVertexGeometry(); const std::vector &edges = getEdgeGeometry(); if (verts.empty() && @@ -1516,6 +1541,7 @@ int DrawViewPart::prefIsoCount() return result; } +#include // Python Drawing feature --------------------------------------------------------- diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 82944facba..8f4c543a87 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -25,6 +25,12 @@ #ifndef _DrawViewPart_h_ #define _DrawViewPart_h_ +#include + +#include +#include +#include + #include #include @@ -78,6 +84,7 @@ class DrawViewSection; class TechDrawExport DrawViewPart : public DrawView, public CosmeticExtension { PROPERTY_HEADER_WITH_EXTENSIONS(TechDraw::DrawViewPart); + Q_OBJECT public: DrawViewPart(); @@ -163,6 +170,7 @@ public: virtual TopoDS_Shape getSourceShapeFused() const; virtual std::vector getSourceShape2d() const; + virtual void postHlrTasks(void); bool isIso() const; @@ -197,6 +205,17 @@ public: std::vector getAllSources() const; + bool waitingForFaces() const { return m_waitingForFaces; } + void waitingForFaces(bool s) { m_waitingForFaces = s;} + bool waitingForHlr() const { return m_waitingForHlr; } + void waitingForHlr(bool s) { m_waitingForHlr = s; } + bool waitingForResult() const; + + void progressValueChanged(int v); + +public Q_SLOTS: + void onHlrFinished(void); + void onFacesFinished(void); protected: bool checkXDirection() const; @@ -238,6 +257,13 @@ protected: private: bool nowUnsetting; + bool m_waitingForFaces; + bool m_waitingForHlr; + + QFutureWatcher m_hlrWatcher; + QFuture m_hlrFuture; + QFutureWatcher m_faceWatcher; + QFuture m_faceFuture; }; diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 9f127f075f..1f5fc1d84e 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -299,7 +299,7 @@ App::DocumentObjectExecReturn *DrawViewSection::execute() } else { dvp = static_cast(base); } - + TopoDS_Shape baseShape; if (FuseBeforeCut.getValue()) { baseShape = dvp->getSourceShapeFused(); @@ -346,12 +346,17 @@ App::DocumentObjectExecReturn *DrawViewSection::execute() } } - dvp->requestPaint(); //to refresh section line return DrawView::execute(); } void DrawViewSection::sectionExec(TopoDS_Shape baseShape) { +// Base::Console().Message("DVS::sectionExec() - %s\n", getNameInDocument()); + if (waitingForResult()) { +// Base::Console().Message("DVS::sectionExec - waiting for result\n"); + return; + } + // cut base shape with tool //is SectionOrigin valid? Bnd_Box centerBox; @@ -452,11 +457,10 @@ void DrawViewSection::sectionExec(TopoDS_Shape baseShape) // DrawUtil::dumpCS("DVS::execute - CS to GO", viewAxis); } - geometryObject = buildGeometryObject(scaledShape,viewAxis); + m_rawShape = rawShape; //save for postHlrTasks + m_viewAxis= viewAxis; //save for postHlrTasks -#if MOD_TECHDRAW_HANDLE_FACES - extractFaces(); -#endif //#if MOD_TECHDRAW_HANDLE_FACES + geometryObject = buildGeometryObject(scaledShape,viewAxis); } catch (Standard_Failure& e1) { Base::Console().Warning("DVS::execute - failed to build base shape %s - %s **\n", @@ -464,78 +468,84 @@ void DrawViewSection::sectionExec(TopoDS_Shape baseShape) return; } //display geometry for cut shape is in geometryObject as in DVP +} -// build section face geometry - TopoDS_Compound faceIntersections = findSectionPlaneIntersections(rawShape); - TopoDS_Shape centeredShapeF = TechDraw::moveShape(faceIntersections, - m_saveCentroid * -1.0); +void DrawViewSection::postHlrTasks(void) +{ +// Base::Console().Message("DVS::postHlrTasks() - %s\n", getNameInDocument()); + // build section face geometry + TopoDS_Compound faceIntersections = findSectionPlaneIntersections(m_rawShape); + TopoDS_Shape centeredShapeF = TechDraw::moveShape(faceIntersections, + m_saveCentroid * -1.0); - TopoDS_Shape scaledSection = TechDraw::scaleShape(centeredShapeF, - getScale()); - if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { - scaledSection = TechDraw::rotateShape(scaledSection, - viewAxis, - Rotation.getValue()); - } - if (debugSection()) { - BRepTools::Write(scaledSection, "DVSScaledFaces.brep"); //debug - } -// scaledSection is compound of TopoDS_Face intersections, but aligned to pln(origin, sectionNormal) -// needs to be aligned to pln (origin, stdZ); - gp_Ax3 R3; - gp_Ax2 projCS = getSectionCS(); - gp_Ax3 proj3 = gp_Ax3(gp_Pnt(0.0, 0.0, 0.0), - projCS.Direction(), - projCS.XDirection()); - gp_Trsf fromR3; - fromR3.SetTransformation(R3, proj3); - BRepBuilderAPI_Transform xformer(fromR3); - xformer.Perform(scaledSection, true); - if (xformer.IsDone()) { - sectionFaces = TopoDS::Compound(xformer.Shape()); + TopoDS_Shape scaledSection = TechDraw::scaleShape(centeredShapeF, + getScale()); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { + scaledSection = TechDraw::rotateShape(scaledSection, + m_viewAxis, + Rotation.getValue()); + } + if (debugSection()) { + BRepTools::Write(scaledSection, "DVSScaledFaces.brep"); //debug + } + + // scaledSection is compound of TopoDS_Face intersections, but aligned to pln(origin, sectionNormal) + // needs to be aligned to pln (origin, stdZ); + gp_Ax3 R3; + gp_Ax2 projCS = getSectionCS(); + gp_Ax3 proj3 = gp_Ax3(gp_Pnt(0.0, 0.0, 0.0), + projCS.Direction(), + projCS.XDirection()); + gp_Trsf fromR3; + fromR3.SetTransformation(R3, proj3); + BRepBuilderAPI_Transform xformer(fromR3); + xformer.Perform(scaledSection, true); + if (xformer.IsDone()) { + sectionFaces = TopoDS::Compound(xformer.Shape()); // BRepTools::Write(sectionFaces, "DVSXFaces.brep"); //debug - } else { - Base::Console().Message("DVS::sectionExec - face xform failed\n"); - } + } else { + Base::Console().Message("DVS::sectionExec - face xform failed\n"); + } - sectionFaces = TopoDS::Compound(GeometryObject::invertGeometry(sectionFaces)); //handle Qt -y + sectionFaces = TopoDS::Compound(GeometryObject::invertGeometry(sectionFaces)); //handle Qt -y //turn section faces into something we can draw - tdSectionFaces.clear(); - TopExp_Explorer sectionExpl(sectionFaces, TopAbs_FACE); - int iface = 0; - for (; sectionExpl.More(); sectionExpl.Next()) { - iface++; - const TopoDS_Face& face = TopoDS::Face(sectionExpl.Current()); - TechDraw::FacePtr sectionFace(std::make_shared()); - TopExp_Explorer expFace(face, TopAbs_WIRE); - int iwire = 0; - for ( ; expFace.More(); expFace.Next()) { - iwire++; - TechDraw::Wire* w = new TechDraw::Wire(); - const TopoDS_Wire& wire = TopoDS::Wire(expFace.Current()); - int iedge = 0; - TopExp_Explorer expWire(wire, TopAbs_EDGE); - for ( ; expWire.More(); expWire.Next()) { - iedge++; - const TopoDS_Edge& edge = TopoDS::Edge(expWire.Current()); - TechDraw::BaseGeomPtr e = BaseGeom::baseFactory(edge); - if (e) { - w->geoms.push_back(e); - } + tdSectionFaces.clear(); + TopExp_Explorer sectionExpl(sectionFaces, TopAbs_FACE); + int iface = 0; + for (; sectionExpl.More(); sectionExpl.Next()) { + iface++; + const TopoDS_Face& face = TopoDS::Face(sectionExpl.Current()); + TechDraw::FacePtr sectionFace(std::make_shared()); + TopExp_Explorer expFace(face, TopAbs_WIRE); + int iwire = 0; + for ( ; expFace.More(); expFace.Next()) { + iwire++; + TechDraw::Wire* w = new TechDraw::Wire(); + const TopoDS_Wire& wire = TopoDS::Wire(expFace.Current()); + int iedge = 0; + TopExp_Explorer expWire(wire, TopAbs_EDGE); + for ( ; expWire.More(); expWire.Next()) { + iedge++; + const TopoDS_Edge& edge = TopoDS::Edge(expWire.Current()); + TechDraw::BaseGeomPtr e = BaseGeom::baseFactory(edge); + if (e) { + w->geoms.push_back(e); } - sectionFace->wires.push_back(w); } - tdSectionFaces.push_back(sectionFace); + sectionFace->wires.push_back(w); } + tdSectionFaces.push_back(sectionFace); + } -// add cosmetic entities to view - addCosmeticVertexesToGeom(); - addCosmeticEdgesToGeom(); - addCenterLinesToGeom(); - -// add landmark dim reference points to view - addReferencesToGeom(); + App::DocumentObject* base = BaseView.getValue(); + if (base != nullptr) { + if (base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + TechDraw::DrawViewPart* dvp = static_cast(base); + dvp->requestPaint(); //to refresh section line + } + } + requestPaint(); } gp_Pln DrawViewSection::getSectionPlane() const diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index 729d3e5677..96676a2ebb 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -32,6 +32,7 @@ #include #include +#include #include "DrawViewPart.h" @@ -121,7 +122,8 @@ public: std::pair sectionLineEnds(); - bool showSectionEdges(); + bool showSectionEdges(void); + void postHlrTasks(void) override; protected: TopoDS_Compound sectionFaces; //tSectionFaces @@ -145,6 +147,8 @@ protected: void replaceSvgIncluded(std::string newSvgFile); void replacePatIncluded(std::string newPatFile); + TopoDS_Shape m_rawShape; + gp_Ax2 m_viewAxis; }; diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index c016e558bc..f71af6c339 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -158,29 +158,19 @@ void GeometryObject::clear() edgeGeom.clear(); } -//!set up a hidden line remover and project a shape with it -void GeometryObject::projectShape(const TopoDS_Shape& input, +void GeometryObject::projectShape(const TopoDS_Shape& inShape, const gp_Ax2& viewAxis) { -// Base::Console().Message("GO::projectShape() - %s\n", m_parentName.c_str()); - // Clear previous Geometry clear(); -// DrawUtil::dumpCS("GO::projectShape - VA in", viewAxis); //debug - auto start = chrono::high_resolution_clock::now(); Handle(HLRBRep_Algo) brep_hlr; try { brep_hlr = new HLRBRep_Algo(); - brep_hlr->Add(input, m_isoCount); - if (m_isPersp) { - double fLength = std::max(Precision::Confusion(),m_focus); - HLRAlgo_Projector projector( viewAxis, fLength ); - brep_hlr->Projector(projector); - } else { - HLRAlgo_Projector projector( viewAxis ); - brep_hlr->Projector(projector); - } +// brep_hlr->Debug(true); + brep_hlr->Add(inShape); + HLRAlgo_Projector projector( viewAxis ); + brep_hlr->Projector(projector); brep_hlr->Update(); brep_hlr->Hide(); @@ -188,77 +178,120 @@ void GeometryObject::projectShape(const TopoDS_Shape& input, catch (const Standard_Failure& e) { Base::Console().Error("GO::projectShape - OCC error - %s - while projecting shape\n", e.GetMessageString()); + throw Base::RuntimeError("GeometryObject::hlrExecute - OCC error"); } catch (...) { - Base::Console().Error("GeometryObject::projectShape - unknown error occurred while projecting shape\n"); -// throw Base::RuntimeError("GeometryObject::projectShape - unknown error occurred while projecting shape"); + throw Base::RuntimeError("GeometryObject::hlrExecute - unknown error"); } - 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_Algo & co\n",m_parentName.c_str(),diffOut); - - start = chrono::high_resolution_clock::now(); - try { HLRBRep_HLRToShape hlrToShape(brep_hlr); - visHard = hlrToShape.VCompound(); - BRepLib::BuildCurves3d(visHard); - visHard = invertGeometry(visHard); -// BRepTools::Write(visHard, "GOvisHardi.brep"); //debug + if (!hlrToShape.VCompound().IsNull()) { + visHard = hlrToShape.VCompound(); + BRepLib::BuildCurves3d(visHard); + visHard = invertGeometry(visHard); + } - visSmooth = hlrToShape.Rg1LineVCompound(); - BRepLib::BuildCurves3d(visSmooth); - visSmooth = invertGeometry(visSmooth); + if (!hlrToShape.Rg1LineVCompound().IsNull()) { + visSmooth = hlrToShape.Rg1LineVCompound(); + BRepLib::BuildCurves3d(visSmooth); + visSmooth = invertGeometry(visSmooth); + } - visSeam = hlrToShape.RgNLineVCompound(); - BRepLib::BuildCurves3d(visSeam); - visSeam = invertGeometry(visSeam); + if (!hlrToShape.RgNLineVCompound().IsNull()) { + visSeam = hlrToShape.RgNLineVCompound(); + BRepLib::BuildCurves3d(visSeam); + visSeam = invertGeometry(visSeam); + } - visOutline = hlrToShape.OutLineVCompound(); - BRepLib::BuildCurves3d(visOutline); - visOutline = invertGeometry(visOutline); + if (!hlrToShape.OutLineVCompound().IsNull()) { +// BRepTools::Write(hlrToShape.OutLineVCompound(), "GOOutLineVCompound.brep"); //debug + visOutline = hlrToShape.OutLineVCompound(); + BRepLib::BuildCurves3d(visOutline); + visOutline = invertGeometry(visOutline); + } - visIso = hlrToShape.IsoLineVCompound(); - BRepLib::BuildCurves3d(visIso); - visIso = invertGeometry(visIso); + if (!hlrToShape.IsoLineVCompound().IsNull()) { + visIso = hlrToShape.IsoLineVCompound(); + BRepLib::BuildCurves3d(visIso); + visIso = invertGeometry(visIso); + } - hidHard = hlrToShape.HCompound(); - BRepLib::BuildCurves3d(hidHard); - hidHard = invertGeometry(hidHard); -// BRepTools::Write(hidHard, "GOhidHardi.brep"); //debug + if (!hlrToShape.HCompound().IsNull()) { + hidHard = hlrToShape.HCompound(); + BRepLib::BuildCurves3d(hidHard); + hidHard = invertGeometry(hidHard); + } - hidSmooth = hlrToShape.Rg1LineHCompound(); - BRepLib::BuildCurves3d(hidSmooth); - hidSmooth = invertGeometry(hidSmooth); + if (!hlrToShape.Rg1LineHCompound().IsNull()) { + hidSmooth = hlrToShape.Rg1LineHCompound(); + BRepLib::BuildCurves3d(hidSmooth); + hidSmooth = invertGeometry(hidSmooth); + } - hidSeam = hlrToShape.RgNLineHCompound(); - BRepLib::BuildCurves3d(hidSeam); - hidSeam = invertGeometry(hidSeam); + if (!hlrToShape.RgNLineHCompound().IsNull()) { + hidSeam = hlrToShape.RgNLineHCompound(); + BRepLib::BuildCurves3d(hidSeam); + hidSeam = invertGeometry(hidSeam); + } - hidOutline = hlrToShape.OutLineHCompound(); - BRepLib::BuildCurves3d(hidOutline); - hidOutline = invertGeometry(hidOutline); - - hidIso = hlrToShape.IsoLineHCompound(); - BRepLib::BuildCurves3d(hidIso); - hidIso = invertGeometry(hidIso); + if (!hlrToShape.OutLineHCompound().IsNull()) { + hidOutline = hlrToShape.OutLineHCompound(); + BRepLib::BuildCurves3d(hidOutline); + hidOutline = invertGeometry(hidOutline); + } + if (!hlrToShape.IsoLineHCompound().IsNull()) { + hidIso = hlrToShape.IsoLineHCompound(); + BRepLib::BuildCurves3d(hidIso); + hidIso = invertGeometry(hidIso); + } } catch (const Standard_Failure& e) { - Base::Console().Error("GO::projectShape - OCC error - %s - while extracting edges\n", - e.GetMessageString()); + throw Base::RuntimeError("GeometryObject::hlrExecute - OCC error occurred while extracting edges"); } catch (...) { - Base::Console().Error("GO::projectShape - unknown error while extracting edges\n"); -// throw Base::RuntimeError("GeometryObject::projectShape - error occurred while extracting edges"); + throw Base::RuntimeError("GeometryObject::hlrExecute - unknown error occurred while extracting edges"); } - end = chrono::high_resolution_clock::now(); - diff = end - start; - diffOut = chrono::duration (diff).count(); - Base::Console().Log("TIMING - %s GO spent: %.3f millisecs in hlrToShape and BuildCurves\n",m_parentName.c_str(),diffOut); + + //convert the hlr output into TD Geometry + const DrawViewPart* dvp = static_cast(m_parent); + extractGeometry(TechDraw::ecHARD, //always show the hard&outline visible lines + true); + extractGeometry(TechDraw::ecOUTLINE, + true); + if (dvp->SmoothVisible.getValue()) { + extractGeometry(TechDraw::ecSMOOTH, + true); + } + if (dvp->SeamVisible.getValue()) { + extractGeometry(TechDraw::ecSEAM, + true); + } + if ((dvp->IsoVisible.getValue()) && (dvp->IsoCount.getValue() > 0)) { + extractGeometry(TechDraw::ecUVISO, + true); + } + if (dvp->HardHidden.getValue()) { + extractGeometry(TechDraw::ecHARD, + false); + extractGeometry(TechDraw::ecOUTLINE, + false); + } + if (dvp->SmoothHidden.getValue()) { + extractGeometry(TechDraw::ecSMOOTH, + false); + } + if (dvp->SeamHidden.getValue()) { + extractGeometry(TechDraw::ecSEAM, + false); + } + if (dvp->IsoHidden.getValue() && (dvp->IsoCount.getValue() > 0)) { + extractGeometry(TechDraw::ecUVISO, + false); + } + } //mirror a shape thru XZ plane for Qt's inverted Y coordinate diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index b3826c32ab..d090e3ea05 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -168,7 +169,6 @@ public: int addCenterLine(TechDraw::BaseGeomPtr bg, std::string tag); -/* int s = 0, int si = -1);*/ protected: //HLR output