From c770e1b677445595b9082cbba079ff863d8a7fad Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 1 Mar 2023 17:43:04 +0100 Subject: [PATCH] Mod: catch exception raised by Rotation::setValue --- src/Mod/Import/App/ImportOCAF.cpp | 57 +++++++++++++++++----------- src/Mod/Import/App/ImportOCAF.h | 2 + src/Mod/Mesh/App/MeshFeature.cpp | 12 ++++-- src/Mod/Part/App/PartFeature.cpp | 10 +++-- src/Mod/Points/App/PointsFeature.cpp | 12 ++++-- 5 files changed, 59 insertions(+), 34 deletions(-) diff --git a/src/Mod/Import/App/ImportOCAF.cpp b/src/Mod/Import/App/ImportOCAF.cpp index b904d9c815..2397b62c37 100644 --- a/src/Mod/Import/App/ImportOCAF.cpp +++ b/src/Mod/Import/App/ImportOCAF.cpp @@ -94,6 +94,33 @@ ImportOCAF::~ImportOCAF() { } +void ImportOCAF::tryPlacementFromLoc(App::GeoFeature* part, const TopLoc_Location& part_loc) +{ + gp_Trsf trf; + Base::Matrix4D mtrx; + if (part_loc.IsIdentity()) { + trf = part_loc.Transformation(); + } + else { + trf = TopLoc_Location(part_loc.FirstDatum()).Transformation(); + } + + Part::TopoShape::convertToMatrix(trf, mtrx); + tryPlacementFromMatrix(part, mtrx); +} + +void ImportOCAF::tryPlacementFromMatrix(App::GeoFeature* part, const Base::Matrix4D& mat) +{ + try { + Base::Placement pl; + pl.fromMatrix(mat); + part->Placement.setValue(pl); + } + catch (const Base::ValueError& e) { + e.ReportException(); + } +} + void ImportOCAF::loadShapes() { std::vector lValue; @@ -235,17 +262,7 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc, // there local placement updated and relative to the STEP file content // standard FreeCAD placement was absolute we are now moving to relative - gp_Trsf trf; - Base::Matrix4D mtrx; - if (part_loc.IsIdentity()) - trf = part_loc.Transformation(); - else - trf = TopLoc_Location(part_loc.FirstDatum()).Transformation(); - Part::TopoShape::convertToMatrix(trf, mtrx); - Base::Placement pl; - pl.fromMatrix(mtrx); - pcPart->Placement.setValue(pl); - + tryPlacementFromLoc(pcPart, part_loc); lValue.push_back(pcPart); } } @@ -332,20 +349,14 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc, if (!comp.IsNull() && (ctSolids||ctShells||ctEdges||ctVertices)) { Part::Feature* part = static_cast(doc->addObject("Part::Feature")); // Let's allocate the relative placement of the Compound from the STEP file - gp_Trsf trf; - Base::Matrix4D mtrx; - if ( loc.IsIdentity() ) - trf = loc.Transformation(); - else - trf = TopLoc_Location(loc.FirstDatum()).Transformation(); - Part::TopoShape::convertToMatrix(trf, mtrx); - Base::Placement pl; - pl.fromMatrix(mtrx); - part->Placement.setValue(pl); - if (!loc.IsIdentity()) + tryPlacementFromLoc(part, loc); + if (!loc.IsIdentity()) { part->Shape.setValue(comp.Moved(loc)); - else + } + else { part->Shape.setValue(comp); + } + part->Label.setValue(name); lValue.push_back(part); diff --git a/src/Mod/Import/App/ImportOCAF.h b/src/Mod/Import/App/ImportOCAF.h index 62e68be9c0..da0c21a081 100644 --- a/src/Mod/Import/App/ImportOCAF.h +++ b/src/Mod/Import/App/ImportOCAF.h @@ -67,6 +67,8 @@ private: void createShape(const TopoDS_Shape& label, const TopLoc_Location&, const std::string&, std::vector &); void loadColors(Part::Feature* part, const TopoDS_Shape& aShape); virtual void applyColors(Part::Feature*, const std::vector&){} + static void tryPlacementFromLoc(App::GeoFeature*, const TopLoc_Location&); + static void tryPlacementFromMatrix(App::GeoFeature*, const Base::Matrix4D&); private: Handle(TDocStd_Document) pDoc; diff --git a/src/Mod/Mesh/App/MeshFeature.cpp b/src/Mod/Mesh/App/MeshFeature.cpp index a6a5f1f80e..db279de4ab 100644 --- a/src/Mod/Mesh/App/MeshFeature.cpp +++ b/src/Mod/Mesh/App/MeshFeature.cpp @@ -69,10 +69,14 @@ void Feature::onChanged(const App::Property* prop) } // if the mesh data has changed check and adjust the transformation as well else if (prop == &this->Mesh) { - Base::Placement p; - p.fromMatrix(this->Mesh.getTransform()); - if (p != this->Placement.getValue()) - this->Placement.setValue(p); + try { + Base::Placement p; + p.fromMatrix(this->Mesh.getTransform()); + if (p != this->Placement.getValue()) + this->Placement.setValue(p); + } + catch (const Base::ValueError&) { + } } // Note: If the Mesh property has changed the property and this object are marked as 'touched' diff --git a/src/Mod/Part/App/PartFeature.cpp b/src/Mod/Part/App/PartFeature.cpp index 3773e5bb67..18cbad6044 100644 --- a/src/Mod/Part/App/PartFeature.cpp +++ b/src/Mod/Part/App/PartFeature.cpp @@ -544,9 +544,13 @@ void Feature::onChanged(const App::Property* prop) Base::Placement p; // shape must not be null to override the placement if (!this->Shape.getValue().IsNull()) { - p.fromMatrix(this->Shape.getShape().getTransform()); - if (p != this->Placement.getValue()) - this->Placement.setValue(p); + try { + p.fromMatrix(this->Shape.getShape().getTransform()); + if (p != this->Placement.getValue()) + this->Placement.setValue(p); + } + catch (const Base::ValueError&) { + } } } } diff --git a/src/Mod/Points/App/PointsFeature.cpp b/src/Mod/Points/App/PointsFeature.cpp index 1740226cf7..cb513e2220 100644 --- a/src/Mod/Points/App/PointsFeature.cpp +++ b/src/Mod/Points/App/PointsFeature.cpp @@ -76,10 +76,14 @@ void Feature::onChanged(const App::Property* prop) } // if the point data has changed check and adjust the transformation as well else if (prop == &this->Points) { - Base::Placement p; - p.fromMatrix(this->Points.getTransform()); - if (p != this->Placement.getValue()) - this->Placement.setValue(p); + try { + Base::Placement p; + p.fromMatrix(this->Points.getTransform()); + if (p != this->Placement.getValue()) + this->Placement.setValue(p); + } + catch (const Base::ValueError&) { + } } GeoFeature::onChanged(prop);