Toponaming: Remove all FC_USE_TNP_FIX protected old code
This commit is contained in:
@@ -71,200 +71,17 @@ Pocket::Pocket()
|
||||
|
||||
App::DocumentObjectExecReturn *Pocket::execute()
|
||||
{
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
// MakeFace|MakeFuse: because we want a solid.
|
||||
// InverseDirection: to inverse the auto detected extrusion direction for
|
||||
// backward compatibility to upstream
|
||||
ExtrudeOptions options(ExtrudeOption::MakeFace | ExtrudeOption::MakeFuse
|
||||
| ExtrudeOption::InverseDirection);
|
||||
return buildExtrusion(options);
|
||||
#else
|
||||
// Handle legacy features, these typically have Type set to 3 (previously NULL, now UpToFace),
|
||||
// empty FaceName (because it didn't exist) and a value for Length
|
||||
if (std::string(Type.getValueAsString()) == "UpToFace" &&
|
||||
(!UpToFace.getValue() && Length.getValue() > Precision::Confusion()))
|
||||
Type.setValue("Length");
|
||||
|
||||
double L = Length.getValue();
|
||||
double L2 = Length2.getValue();
|
||||
|
||||
TopoDS_Shape profileshape;
|
||||
try {
|
||||
profileshape = getVerifiedFace();
|
||||
} catch (const Base::Exception& e) {
|
||||
return new App::DocumentObjectExecReturn(e.what());
|
||||
}
|
||||
|
||||
// if the Base property has a valid shape, fuse the prism into it
|
||||
TopoShape base;
|
||||
try {
|
||||
base = getBaseTopoShape();
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
std::string text(QT_TRANSLATE_NOOP("Exception", ("The requested feature cannot be created. The reason may be that:\n"
|
||||
" - the active Body does not contain a base shape, so there is no\n"
|
||||
" material to be removed;\n"
|
||||
" - the selected sketch does not belong to the active Body.")));
|
||||
return new App::DocumentObjectExecReturn(text);
|
||||
}
|
||||
|
||||
// get the normal vector of the sketch
|
||||
Base::Vector3d SketchVector = getProfileNormal();
|
||||
|
||||
// turn around for pockets
|
||||
SketchVector *= -1;
|
||||
|
||||
try {
|
||||
this->positionByPrevious();
|
||||
TopLoc_Location invObjLoc = this->getLocation().Inverted();
|
||||
|
||||
base.move(invObjLoc);
|
||||
|
||||
Base::Vector3d pocketDirection = computeDirection(SketchVector, false);
|
||||
|
||||
// create vector in pocketing direction with length 1
|
||||
gp_Dir dir(pocketDirection.x, pocketDirection.y, pocketDirection.z);
|
||||
|
||||
// The length of a gp_Dir is 1 so the resulting pocket would have
|
||||
// the length L in the direction of dir. But we want to have its height in the
|
||||
// direction of the normal vector.
|
||||
// Therefore we must multiply L by the factor that is necessary
|
||||
// to make dir as long that its projection to the SketchVector
|
||||
// equals the SketchVector.
|
||||
// This is the scalar product of both vectors.
|
||||
// Since the pocket length cannot be negative, the factor must not be negative.
|
||||
|
||||
double factor = fabs(dir * gp_Dir(SketchVector.x, SketchVector.y, SketchVector.z));
|
||||
|
||||
// factor would be zero if vectors are orthogonal
|
||||
if (factor < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Pocket: Creation failed because direction is orthogonal to sketch's normal vector"));
|
||||
|
||||
// perform the length correction if not along custom vector
|
||||
if (AlongSketchNormal.getValue()) {
|
||||
L = L / factor;
|
||||
L2 = L2 / factor;
|
||||
}
|
||||
|
||||
dir.Transform(invObjLoc.Transformation());
|
||||
|
||||
if (profileshape.IsNull())
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Pocket: Creating a face from sketch failed"));
|
||||
profileshape.Move(invObjLoc);
|
||||
|
||||
std::string method(Type.getValueAsString());
|
||||
if (method == "UpToFirst" || method == "UpToFace") {
|
||||
if (base.isNull())
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Pocket: Extruding up to a face is only possible if the sketch is located on a face"));
|
||||
|
||||
// Note: This will return an unlimited planar face if support is a datum plane
|
||||
TopoDS_Face supportface = getSupportFace();
|
||||
supportface.Move(invObjLoc);
|
||||
|
||||
if (Reversed.getValue())
|
||||
dir.Reverse();
|
||||
|
||||
// Find a valid face or datum plane to extrude up to
|
||||
TopoDS_Face upToFace;
|
||||
if (method == "UpToFace") {
|
||||
getFaceFromLinkSub(upToFace, UpToFace);
|
||||
upToFace.Move(invObjLoc);
|
||||
}
|
||||
getUpToFace(upToFace, base.getShape(), profileshape, method, dir);
|
||||
addOffsetToFace(upToFace, dir, Offset.getValue());
|
||||
|
||||
// BRepFeat_MakePrism(..., 2, 1) in combination with PerForm(upToFace) is buggy when the
|
||||
// prism that is being created is contained completely inside the base solid
|
||||
// In this case the resulting shape is empty. This is not a problem for the Pad or Pocket itself
|
||||
// but it leads to an invalid SubShape
|
||||
// The bug only occurs when the upToFace is limited (by a wire), not for unlimited upToFace. But
|
||||
// other problems occur with unlimited concave upToFace so it is not an option to always unlimit upToFace
|
||||
// Check supportface for limits, otherwise Perform() throws an exception
|
||||
TopExp_Explorer Ex(supportface,TopAbs_WIRE);
|
||||
if (!Ex.More())
|
||||
supportface = TopoDS_Face();
|
||||
TopoDS_Shape prism;
|
||||
PrismMode mode = PrismMode::CutFromBase;
|
||||
generatePrism(prism, method, base.getShape(), profileshape, supportface, upToFace, dir, mode, Standard_True);
|
||||
|
||||
// And the really expensive way to get the SubShape...
|
||||
BRepAlgoAPI_Cut mkCut(base.getShape(), prism);
|
||||
if (!mkCut.IsDone())
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Pocket: Up to face: Could not get SubShape!"));
|
||||
// FIXME: In some cases this affects the Shape property: It is set to the same shape as the SubShape!!!!
|
||||
TopoDS_Shape result = refineShapeIfActive(mkCut.Shape());
|
||||
this->AddSubShape.setValue(result);
|
||||
|
||||
if (!isSingleSolidRuleSatisfied(result)) {
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported."));
|
||||
}
|
||||
|
||||
this->Shape.setValue(getSolid(prism));
|
||||
}
|
||||
else {
|
||||
TopoDS_Shape prism;
|
||||
if (hasTaperedAngle()) {
|
||||
if (Reversed.getValue())
|
||||
dir.Reverse();
|
||||
generateTaperedPrism(prism, profileshape, method, dir, L, L2, TaperAngle.getValue(), TaperAngle2.getValue(), Midplane.getValue());
|
||||
}
|
||||
else {
|
||||
generatePrism(prism, profileshape, method, dir, L, L2, Midplane.getValue(), Reversed.getValue());
|
||||
}
|
||||
|
||||
if (prism.IsNull())
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Pocket: Resulting shape is empty"));
|
||||
|
||||
// set the subtractive shape property for later usage in e.g. pattern
|
||||
prism = refineShapeIfActive(prism);
|
||||
this->AddSubShape.setValue(prism);
|
||||
|
||||
// Cut the SubShape out of the base feature
|
||||
BRepAlgoAPI_Cut mkCut(base.getShape(), prism);
|
||||
if (!mkCut.IsDone())
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Pocket: Cut out of base feature failed"));
|
||||
TopoDS_Shape result = mkCut.Shape();
|
||||
// we have to get the solids (fuse sometimes creates compounds)
|
||||
TopoDS_Shape solRes = this->getSolid(result);
|
||||
if (solRes.IsNull())
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid"));
|
||||
|
||||
if (!isSingleSolidRuleSatisfied(result)) {
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported."));
|
||||
|
||||
}
|
||||
solRes = refineShapeIfActive(solRes);
|
||||
remapSupportShape(solRes);
|
||||
this->Shape.setValue(getSolid(solRes));
|
||||
}
|
||||
|
||||
// eventually disable some settings that are not valid for the current method
|
||||
updateProperties(method);
|
||||
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
if (std::string(e.GetMessageString()) == "TopoDS::Face" &&
|
||||
(std::string(Type.getValueAsString()) == "UpToFirst" || std::string(Type.getValueAsString()) == "UpToFace"))
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Could not create face from sketch.\n"
|
||||
"Intersecting sketch entities or multiple faces in a sketch are not allowed "
|
||||
"for making a pocket up to a face."));
|
||||
else
|
||||
return new App::DocumentObjectExecReturn(e.GetMessageString());
|
||||
}
|
||||
catch (Base::Exception& e) {
|
||||
return new App::DocumentObjectExecReturn(e.what());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Base::Vector3d Pocket::getProfileNormal() const
|
||||
{
|
||||
auto res = FeatureExtrude::getProfileNormal();
|
||||
// turn around for pockets
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return res * -1;
|
||||
#else
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user