Pad/Pocket: Allow extrude up to a datum plane

This commit is contained in:
jrheinlaender
2013-05-14 15:44:24 +04:30
committed by Stefan Tröger
parent b815656649
commit f954a51430
12 changed files with 161 additions and 153 deletions

View File

@@ -96,17 +96,23 @@ App::DocumentObjectExecReturn *Pad::execute(void)
return new App::DocumentObjectExecReturn(e.what());
}
TopoDS_Shape support;
// if the Base property has a valid shape, fuse the prism into it
TopoDS_Shape base;
try {
support = getSupportShape();
base = getBaseShape();
} catch (const Base::Exception&) {
// ignore, because support isn't mandatory
support = TopoDS_Shape();
try {
// fall back to support (for legacy features)
base = getSupportShape();
} catch (const Base::Exception&) {
// ignore, because support isn't mandatory
base = TopoDS_Shape();
}
}
/*
// Find Body feature which owns this Pad and get the shape of the feature preceding this one for fusing
// This method was rejected in favour of the Base property because it makes the feature atomic (independent of the
// This method was rejected in favour of the BaseFeature property because that makes the feature atomic (independent of the
// Body object). See
// https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=19&t=3831
// https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=19&t=3855
@@ -138,7 +144,7 @@ App::DocumentObjectExecReturn *Pad::execute(void)
TopLoc_Location invObjLoc = this->getLocation().Inverted();
try {
support.Move(invObjLoc);
base.Move(invObjLoc);
gp_Dir dir(SketchVector.x,SketchVector.y,SketchVector.z);
dir.Transform(invObjLoc.Transformation());
@@ -151,42 +157,36 @@ App::DocumentObjectExecReturn *Pad::execute(void)
TopoDS_Shape prism;
std::string method(Type.getValueAsString());
if (method == "UpToFirst" || method == "UpToLast" || method == "UpToFace") {
// Note: This will throw an exception if the sketch is located on a datum plane
TopoDS_Face supportface = getSupportFace();
supportface.Move(invObjLoc);
if (Reversed.getValue())
dir.Reverse();
// Find a valid face to extrude up to
// Find a valid face or datum plane to extrude up to
TopoDS_Face upToFace;
if (method == "UpToFace") {
getUpToFaceFromLinkSub(upToFace, UpToFace);
upToFace.Move(invObjLoc);
}
getUpToFace(upToFace, support, supportface, sketchshape, method, dir);
getUpToFace(upToFace, base, supportface, sketchshape, method, dir);
// A support object is always required and we need to use BRepFeat_MakePrism
// Problem: For Pocket/UpToFirst (or an equivalent Pocket/UpToFace) the resulting shape is invalid
// because the feature does not add any material. This only happens with the "2" option, though
// Note: It might be possible to pass a shell or a compound containing multiple faces
// as the Until parameter of Perform()
// Note: Multiple independent wires are not supported, that's why we have to iterate over them.
TopoDS_Compound comp;
BRep_Builder builder;
builder.MakeCompound(comp);
// Note: Multiple independent wires are not supported, we should check for that and
// warn the user
// FIXME: If the support shape is not the previous solid in the tree, then there will be unexpected results
for (TopExp_Explorer xp(sketchshape, TopAbs_FACE); xp.More(); xp.Next()) {
BRepFeat_MakePrism PrismMaker;
PrismMaker.Init(support, xp.Current(), supportface, dir, 2, 1);
PrismMaker.Perform(upToFace);
BRepFeat_MakePrism PrismMaker;
PrismMaker.Init(base, sketchshape, supportface, dir, 2, 1);
PrismMaker.Perform(upToFace);
if (!PrismMaker.IsDone())
return new App::DocumentObjectExecReturn("Pad: Up to face: Could not extrude the sketch!");
builder.Add(comp, PrismMaker.Shape());
}
prism = comp;
if (!PrismMaker.IsDone())
return new App::DocumentObjectExecReturn("Pad: Up to face: Could not extrude the sketch!");
prism = PrismMaker.Shape();
} else {
generatePrism(prism, sketchshape, method, dir, L, L2,
Midplane.getValue(), Reversed.getValue());
@@ -197,17 +197,7 @@ App::DocumentObjectExecReturn *Pad::execute(void)
// set the additive shape property for later usage in e.g. pattern
prism = refineShapeIfActive(prism);
this->AddShape.setValue(prism);
// if the Base property has a valid shape, fuse the prism into it
TopoDS_Shape base;
try {
base = getBaseShape();
base.Move(invObjLoc);
} catch (const Base::Exception&) {
// fall back to support (for legacy features)
base = support;
}
this->AddShape.setValue(prism);
if (!base.IsNull()) {
// Let's call algorithm computing a fuse operation: