PD: Mirror feature should be more permissive

If you have a mirror feature and set the mirror plane with the normal feature editing the recompute works. But if the mirror plane is set with the property editor then the recompute fails with the message that no mirror plane reference is set.

This is related to a an empty sub-name list of the link property instead of a single and empty sub-name element.

This PR allows to specify a sketch, plane or datum plane without a sub-name.

For more details see: https://forum.freecad.org/viewtopic.php?t=86568

This fixes #13238
This commit is contained in:
wmayer
2024-03-31 08:37:39 +02:00
committed by wwmayer
parent 5adb384e20
commit b908e46b26
2 changed files with 15 additions and 9 deletions

View File

@@ -69,15 +69,15 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
if (auto refSketch = dynamic_cast<Part::Part2DObject*>(refObject)) {
Base::Axis axis;
if (subStrings[0] == "H_Axis") {
if (subStrings.empty() || subStrings[0].empty()) {
axis = refSketch->getAxis(Part::Part2DObject::N_Axis);
}
else if (subStrings[0] == "H_Axis") {
axis = refSketch->getAxis(Part::Part2DObject::V_Axis);
}
else if (subStrings[0] == "V_Axis") {
axis = refSketch->getAxis(Part::Part2DObject::H_Axis);
}
else if (subStrings[0].empty()) {
axis = refSketch->getAxis(Part::Part2DObject::N_Axis);
}
else if (subStrings[0].compare(0, 4, "Axis") == 0) {
int AxId = std::atoi(subStrings[0].substr(4,4000).c_str());
if (AxId >= 0 && AxId < refSketch->getAxisCount()) {
@@ -85,6 +85,9 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
axis.setBase(axis.getBase() + 0.5 * axis.getDirection());
axis.setDirection(Base::Vector3d(-axis.getDirection().y, axis.getDirection().x, axis.getDirection().z));
}
else {
throw Base::ValueError("No valid axis specified");
}
}
axis *= refSketch->Placement.getValue();
axbase = gp_Pnt(axis.getBase().x, axis.getBase().y, axis.getBase().z);
@@ -131,6 +134,9 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
std::vector<std::string> subStrings = MirrorPlane.getSubValues();
if (auto feature = dynamic_cast<Part::Feature*>(refObject)) {
if (subStrings.empty()) {
throw Base::ValueError("No mirror plane reference specified");
}
if (subStrings[0].empty()) {
throw Base::ValueError("No direction reference specified");
}
@@ -162,10 +168,6 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
if (!refObject) {
throw Base::ValueError("No mirror plane reference specified");
}
std::vector<std::string> subStrings = MirrorPlane.getSubValues();
if (subStrings.empty()) {
throw Base::ValueError("No mirror plane reference specified");
}
gp_Pnt axbase;
gp_Dir axdir;

View File

@@ -183,9 +183,13 @@ App::DocumentObjectExecReturn *Transformed::execute()
try {
std::list<gp_Trsf> t_list = getTransformations(originals);
transformations.insert(transformations.end(), t_list.begin(), t_list.end());
} catch (Base::Exception& e) {
}
catch (Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
catch (const Standard_Failure& e) {
return new App::DocumentObjectExecReturn(e.GetMessageString());
}
if (transformations.empty())
return App::DocumentObject::StdReturn; // No transformations defined, exit silently