Mod: catch exception raised by Rotation::setValue

This commit is contained in:
wmayer
2023-03-01 17:43:04 +01:00
committed by wwmayer
parent f195c3a0ca
commit c770e1b677
5 changed files with 59 additions and 34 deletions

View File

@@ -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<App::DocumentObject*> 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<Part::Feature*>(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);

View File

@@ -67,6 +67,8 @@ private:
void createShape(const TopoDS_Shape& label, const TopLoc_Location&, const std::string&, std::vector<App::DocumentObject*> &);
void loadColors(Part::Feature* part, const TopoDS_Shape& aShape);
virtual void applyColors(Part::Feature*, const std::vector<App::Color>&){}
static void tryPlacementFromLoc(App::GeoFeature*, const TopLoc_Location&);
static void tryPlacementFromMatrix(App::GeoFeature*, const Base::Matrix4D&);
private:
Handle(TDocStd_Document) pDoc;

View File

@@ -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'

View File

@@ -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&) {
}
}
}
}

View File

@@ -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);