diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index eba5e465b..96e9b4a1e 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -158,10 +158,12 @@ Part::Part2DObject* ProfileBased::getVerifiedSketch(bool silent) const { const char* err = nullptr; if (!result) { - err = "No sketch linked"; + err = "No profile linked at all"; } else { - if (!result->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) + if (!result->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) { err = "Linked object is not a Sketch or Part2DObject"; + result = nullptr; + } } if (!silent && err) { @@ -242,7 +244,19 @@ TopoDS_Face ProfileBased::getVerifiedFace(bool silent) const { std::vector ProfileBased::getProfileWires() const { std::vector result; - TopoDS_Shape shape = getVerifiedFace(); + if(!Profile.getValue() || !Profile.getValue()->isDerivedFrom(Part::Feature::getClassTypeId())) + throw Base::Exception("No valid profile linked"); + + TopoDS_Shape shape; + if(Profile.getValue()->isDerivedFrom(Part::Part2DObject::getClassTypeId())) + shape = Profile.getValue()->Shape.getValue(); + else { + if(Profile.getSubValues().empty()) + throw Base::Exception("No valid subelement linked in Part::Feature"); + + shape = Profile.getValue()->Shape.getShape().getSubShape(Profile.getSubValues().front().c_str()); + } + if (shape.IsNull()) throw Base::Exception("Linked shape object is empty"); diff --git a/src/Mod/PartDesign/App/FeatureTransformed.cpp b/src/Mod/PartDesign/App/FeatureTransformed.cpp index f8ae76559..a3387631b 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.cpp +++ b/src/Mod/PartDesign/App/FeatureTransformed.cpp @@ -104,7 +104,7 @@ App::DocumentObject* Transformed::getSketchObject() const { std::vector originals = Originals.getValues(); if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { - return (static_cast(originals.front()))->getVerifiedSketch(); + return (static_cast(originals.front()))->getVerifiedSketch(true); } else if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) { return NULL; @@ -211,7 +211,7 @@ App::DocumentObjectExecReturn *Transformed::execute(void) return App::DocumentObject::StdReturn; // No transformations defined, exit silently // Get the support - Part::Feature* supportFeature = getBaseObject(); + Part::Feature* supportFeature; try { supportFeature = getBaseObject(); diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index fc14d05df..1bd32cc6b 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -1545,17 +1545,22 @@ void CmdPartDesignMirrored::activated(int iMsg) if (features.empty()) return; + bool direction = false; if(features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { Part::Part2DObject *sketch = (static_cast(features.front()))->getVerifiedSketch(/* silent =*/ true); - if (sketch) - Gui::Command::doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])", + if (sketch) { + doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])", FeatName.c_str(), sketch->getNameInDocument()); + direction = true; + } + } + if(!direction) { + auto body = static_cast(Part::BodyBase::findBodyOf(features.front())); + if(body) { + doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), + body->getOrigin()->getXY()->getNameInDocument()); + } } - // TODO Check if default mirrored plane correctly set (2015-09-01, Fat-Zer) - // else { - // doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), - // App::Part::BaseplaneTypes[0]); - // } finishTransformed(cmd, FeatName); }; @@ -1593,17 +1598,22 @@ void CmdPartDesignLinearPattern::activated(int iMsg) if (features.empty()) return; + bool direction = false; if(features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { Part::Part2DObject *sketch = (static_cast(features.front()))->getVerifiedSketch(/* silent =*/ true); - if (sketch) + if (sketch) { doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])", FeatName.c_str(), sketch->getNameInDocument()); + direction = true; + } + } + if(!direction) { + auto body = static_cast(Part::BodyBase::findBodyOf(features.front())); + if(body) { + doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), + body->getOrigin()->getX()->getNameInDocument()); + } } - // TODO Check if default direction correctly set (2015-09-01, Fat-Zer) - // else { - // doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), - // App::Part::BaselineTypes[0]); - // } doCommand(Doc,"App.activeDocument().%s.Length = 100", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str()); @@ -1643,17 +1653,22 @@ void CmdPartDesignPolarPattern::activated(int iMsg) if (features.empty()) return; + bool direction = false; if(features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { Part::Part2DObject *sketch = (static_cast(features.front()))->getVerifiedSketch(/* silent =*/ true); - if (sketch) + if (sketch) { doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])", FeatName.c_str(), sketch->getNameInDocument()); + direction = true; + } + } + if(!direction) { + auto body = static_cast(Part::BodyBase::findBodyOf(features.front())); + if(body) { + doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), + body->getOrigin()->getZ()->getNameInDocument()); + } } - // TODO Check if default axis correctly set (2015-09-01, Fat-Zer) - // else { - // doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), - // App::Part::BaselineTypes[0]); - // } doCommand(Doc,"App.activeDocument().%s.Angle = 360", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str());