Fix Error when OCC projection returns nothing

This commit is contained in:
wandererfan
2019-04-24 16:40:31 -04:00
committed by WandererFan
parent 40c0347b25
commit 57d35a392c
2 changed files with 28 additions and 10 deletions

View File

@@ -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<App::DocumentObject*>& links = Source.getValues();
if (links.empty()) {
@@ -203,6 +205,7 @@ TopoDS_Shape DrawViewPart::getSourceShape(void) const
std::vector<TopoDS_Shape> DrawViewPart::getShapesFromObject(App::DocumentObject* docObj) const
{
// Base::Console().Message("DVP::getShapesFromObject() - %s\n", getNameInDocument());
std::vector<TopoDS_Shape> result;
App::GroupExtension* gex = dynamic_cast<App::GroupExtension*>(docObj);
App::Property* gProp = docObj->getPropertyByName("Group");
@@ -250,6 +253,7 @@ std::vector<TopoDS_Shape> 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 <double, milli> (diff).count();
Base::Console().Log("TIMING - %s DVP spent: %.3f millisecs in GO::extractGeometry\n",getNameInDocument(),diffOut);
const std::vector<TechDrawGeometry::BaseGeom *> & edges = go->getEdgeGeometry();
if (edges.empty()) {
Base::Console().Log("DVP::buildGO - NO extracted edges!\n");
}
bbox = go->calcBoundingBox();
return go;
}

View File

@@ -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<BaseGeom *>::const_iterator it( edgeGeom.begin() );
it != edgeGeom.end(); ++it) {
BRepBndLib::Add((*it)->occEdge, testBox);
if (!edgeGeom.empty()) {
for (std::vector<BaseGeom *>::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;
}