PartDesign: Adopt pattern to face based features
This commit is contained in:
parent
f712f5e4ac
commit
4ec7fe6303
|
@ -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<TopoDS_Wire> ProfileBased::getProfileWires() const {
|
||||
std::vector<TopoDS_Wire> 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<Part::Part2DObject*>()->Shape.getValue();
|
||||
else {
|
||||
if(Profile.getSubValues().empty())
|
||||
throw Base::Exception("No valid subelement linked in Part::Feature");
|
||||
|
||||
shape = Profile.getValue<Part::Feature*>()->Shape.getShape().getSubShape(Profile.getSubValues().front().c_str());
|
||||
}
|
||||
|
||||
if (shape.IsNull())
|
||||
throw Base::Exception("Linked shape object is empty");
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ App::DocumentObject* Transformed::getSketchObject() const
|
|||
{
|
||||
std::vector<DocumentObject*> originals = Originals.getValues();
|
||||
if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
|
||||
return (static_cast<PartDesign::ProfileBased*>(originals.front()))->getVerifiedSketch();
|
||||
return (static_cast<PartDesign::ProfileBased*>(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();
|
||||
|
|
|
@ -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<PartDesign::ProfileBased*>(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<PartDesign::Body*>(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<PartDesign::ProfileBased*>(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<PartDesign::Body*>(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<PartDesign::ProfileBased*>(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<PartDesign::Body*>(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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user