PartDesign: avoid duplicate code in getting the support shape

This commit is contained in:
jrheinlaender
2012-10-29 16:09:54 +01:00
committed by logari81
parent 48df619e5e
commit b2a59199f8
6 changed files with 87 additions and 91 deletions

View File

@@ -81,27 +81,29 @@ App::DocumentObjectExecReturn *Pad::execute(void)
if ((std::string(Type.getValueAsString()) == "TwoLengths") && (L < Precision::Confusion()))
return new App::DocumentObjectExecReturn("Second length of pad too small");
Part::Part2DObject* pcSketch = 0;
Part::Part2DObject* sketch = 0;
std::vector<TopoDS_Wire> wires;
try {
pcSketch = getVerifiedSketch();
sketch = getVerifiedSketch();
wires = getSketchWires();
} catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
TopoDS_Shape support;
try {
support = getSupportShape();
} catch (const Base::Exception&) {
// ignore, because support isn't mandatory
support = TopoDS_Shape();
}
// get the Sketch plane
Base::Placement SketchPos = pcSketch->Placement.getValue();
Base::Placement SketchPos = sketch->Placement.getValue();
Base::Rotation SketchOrientation = SketchPos.getRotation();
Base::Vector3d SketchVector(0,0,1);
SketchOrientation.multVec(SketchVector,SketchVector);
// get the support of the Sketch if any
App::DocumentObject* SupportLink = pcSketch->Support.getValue();
Part::Feature *SupportObject = 0;
if (SupportLink && SupportLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
SupportObject = static_cast<Part::Feature*>(SupportLink);
TopoDS_Shape aFace = makeFace(wires);
if (aFace.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
@@ -126,12 +128,8 @@ App::DocumentObjectExecReturn *Pad::execute(void)
(std::string(Type.getValueAsString()) == "UpToFirst"))
{
// Check for valid support object
if (!SupportObject)
return new App::DocumentObjectExecReturn("Cannot extrude up to face: No support in Sketch!");
const TopoDS_Shape& support = SupportObject->Shape.getValue();
if (support.IsNull())
return new App::DocumentObjectExecReturn("Cannot extrude up to face: Support shape is invalid");
return new App::DocumentObjectExecReturn("Cannot extrude up to face: No valid support in Sketch");
TopExp_Explorer xp (support, TopAbs_SOLID);
if (!xp.More())
return new App::DocumentObjectExecReturn("Cannot extrude up to face: Support shape is not a solid");
@@ -251,12 +249,11 @@ App::DocumentObjectExecReturn *Pad::execute(void)
return new App::DocumentObjectExecReturn("Internal error: Unknown type for Pad feature");
}
// set the additive shape property for later usage in e.g. pattern
this->AddShape.setValue(prism);
// if the sketch has a support fuse them to get one result object (PAD!)
if (SupportObject) {
// set the additive shape property for later usage in e.g. pattern
this->AddShape.setValue(prism);
const TopoDS_Shape& support = SupportObject->Shape.getValue();
if (!support.IsNull()) {
if (!isSolidChecked) { // we haven't checked for solid, yet
if (!support.IsNull()) {