From 57d35a392ca77ea12ee5999eb8d2d549c7600a45 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 24 Apr 2019 16:40:31 -0400 Subject: [PATCH] Fix Error when OCC projection returns nothing --- src/Mod/TechDraw/App/DrawViewPart.cpp | 12 +++++++++++- src/Mod/TechDraw/App/GeometryObject.cpp | 26 ++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 620df235e6..c99f250907 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -159,6 +159,8 @@ DrawViewPart::~DrawViewPart() TopoDS_Shape DrawViewPart::getSourceShape(void) const { +// Base::Console().Message("DVP::getSourceShape() - %s\n", getNameInDocument()); + TopoDS_Shape result; const std::vector& links = Source.getValues(); if (links.empty()) { @@ -203,6 +205,7 @@ TopoDS_Shape DrawViewPart::getSourceShape(void) const std::vector DrawViewPart::getShapesFromObject(App::DocumentObject* docObj) const { +// Base::Console().Message("DVP::getShapesFromObject() - %s\n", getNameInDocument()); std::vector result; App::GroupExtension* gex = dynamic_cast(docObj); App::Property* gProp = docObj->getPropertyByName("Group"); @@ -250,6 +253,7 @@ std::vector DrawViewPart::getShapesFromObject(App::DocumentObject* TopoDS_Shape DrawViewPart::getSourceShapeFused(void) const { +// Base::Console().Message("DVP::getSourceShapeFused() - %s\n", getNameInDocument()); TopoDS_Shape baseShape = getSourceShape(); if (!baseShape.IsNull()) { TopoDS_Iterator it(baseShape); @@ -272,6 +276,7 @@ TopoDS_Shape DrawViewPart::getSourceShapeFused(void) const App::DocumentObjectExecReturn *DrawViewPart::execute(void) { +// Base::Console().Message("DVP::execute() - %s\n", getNameInDocument()); if (!keepUpdated()) { return App::DocumentObject::StdReturn; } @@ -382,6 +387,7 @@ void DrawViewPart::onChanged(const App::Property* prop) //note: slightly different than routine with same name in DrawProjectSplit TechDrawGeometry::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape, gp_Ax2 viewAxis) { +// Base::Console().Message("DVP::buildGO() - %s\n", getNameInDocument()); TechDrawGeometry::GeometryObject* go = new TechDrawGeometry::GeometryObject(getNameInDocument(), this); go->setIsoCount(IsoCount.getValue()); go->isPerspective(Perspective.getValue()); @@ -436,11 +442,15 @@ TechDrawGeometry::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape go->extractGeometry(TechDrawGeometry::ecUVISO, false); } + auto end = chrono::high_resolution_clock::now(); auto diff = end - start; double diffOut = chrono::duration (diff).count(); Base::Console().Log("TIMING - %s DVP spent: %.3f millisecs in GO::extractGeometry\n",getNameInDocument(),diffOut); - + const std::vector & edges = go->getEdgeGeometry(); + if (edges.empty()) { + Base::Console().Log("DVP::buildGO - NO extracted edges!\n"); + } bbox = go->calcBoundingBox(); return go; } diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 30c79364be..1bf2b8e454 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -162,7 +162,8 @@ void GeometryObject::clear() void GeometryObject::projectShape(const TopoDS_Shape& input, const gp_Ax2 viewAxis) { - // Clear previous Geometry +// Base::Console().Message("GO::projectShape()\n"); + // Clear previous Geometry clear(); auto start = chrono::high_resolution_clock::now(); @@ -183,6 +184,7 @@ void GeometryObject::projectShape(const TopoDS_Shape& input, } brep_hlr->Update(); brep_hlr->Hide(); + } catch (Standard_Failure e) { Base::Console().Error("GO::projectShape - OCC error - %s - while projecting shape\n", @@ -386,6 +388,7 @@ void GeometryObject::extractGeometry(edgeClass category, bool visible) //! update edgeGeom and vertexGeom from Compound of edges void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass category, bool visible) { +// Base::Console().Message("GO::addGeomFromCompound()\n"); if(edgeCompound.IsNull()) { Base::Console().Log("TechDraw::GeometryObject::addGeomFromCompound edgeCompound is NULL\n"); return; // There is no OpenCascade Geometry to be calculated @@ -393,7 +396,8 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca BaseGeom* base; TopExp_Explorer edges(edgeCompound, TopAbs_EDGE); - for (int i = 1 ; edges.More(); edges.Next(),i++) { + int i = 1; + for ( ; edges.More(); edges.Next(),i++) { const TopoDS_Edge& edge = TopoDS::Edge(edges.Current()); if (edge.IsNull()) { //Base::Console().Log("INFO - GO::addGeomFromCompound - edge: %d is NULL\n",i); @@ -406,7 +410,7 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca base = BaseGeom::baseFactory(edge); if (base == nullptr) { - Base::Console().Message("Error - GO::addGeomFromCompound - baseFactory failed for edge: %d\n",i); + Base::Console().Log("Error - GO::addGeomFromCompound - baseFactory failed for edge: %d\n",i); throw Base::ValueError("GeometryObject::addGeomFromCompound - baseFactory failed"); } base->classOfEdge = category; @@ -533,18 +537,22 @@ bool GeometryObject::isWithinArc(double theta, double first, Base::BoundBox3d GeometryObject::calcBoundingBox() const { +// Base::Console().Message("GO::calcBoundingBox() - edges: %d\n", edgeGeom.size()); Bnd_Box testBox; testBox.SetGap(0.0); - for (std::vector::const_iterator it( edgeGeom.begin() ); - it != edgeGeom.end(); ++it) { - BRepBndLib::Add((*it)->occEdge, testBox); + if (!edgeGeom.empty()) { + for (std::vector::const_iterator it( edgeGeom.begin() ); + it != edgeGeom.end(); ++it) { + BRepBndLib::Add((*it)->occEdge, testBox); + } } + + double xMin = 0,xMax = 0,yMin = 0,yMax = 0, zMin = 0, zMax = 0; if (testBox.IsVoid()) { Base::Console().Log("INFO - GO::calcBoundingBox - testBox is void\n"); + } else { + testBox.Get(xMin,yMin,zMin,xMax,yMax,zMax); } - double xMin,xMax,yMin,yMax,zMin,zMax; - testBox.Get(xMin,yMin,zMin,xMax,yMax,zMax); - Base::BoundBox3d bbox(xMin,yMin,zMin,xMax,yMax,zMax); return bbox; }