Skip to content

Commit

Permalink
PartDesign: Fix hardcoded through all distance in ProfileBased
Browse files Browse the repository at this point in the history
Before the throughall distance was 10 m, which is not enough for
many applications. The fix is to use the bounding box of the base shape
together with the sketch profile to calculate dynamically a large enough
length.
  • Loading branch information
davidosterberg authored and wwmayer committed Feb 12, 2021
1 parent 158acd1 commit f0d3e19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
19 changes: 16 additions & 3 deletions src/Mod/PartDesign/App/FeatureSketchBased.cpp
Expand Up @@ -543,6 +543,21 @@ void ProfileBased::getUpToFace(TopoDS_Face& upToFace,
}
}

double ProfileBased::getThroughAllLength() const
{
TopoDS_Shape profileshape;
TopoDS_Shape base;
profileshape = getVerifiedFace();
base = getBaseShape();
Bnd_Box box;
BRepBndLib::Add(base, box);
BRepBndLib::Add(profileshape, box);
box.SetGap(0.0);
// The diagonal of the bounding box, plus 1% extra to eliminate risk of
// co-planar issues, gives a length that is guaranteed to go through all.
return 1.01 * sqrt(box.SquareExtent());
}

void ProfileBased::generatePrism(TopoDS_Shape& prism,
const TopoDS_Shape& sketchshape,
const std::string& method,
Expand All @@ -556,9 +571,7 @@ void ProfileBased::generatePrism(TopoDS_Shape& prism,
double Ltotal = L;
double Loffset = 0.;
if (method == "ThroughAll")
// "ThroughAll" is modelled as a very long, but finite prism to avoid problems with pockets
// Note: 1E6 created problems once...
Ltotal = 1E4;
Ltotal = getThroughAllLength();


if (method == "TwoLengths") {
Expand Down
19 changes: 11 additions & 8 deletions src/Mod/PartDesign/App/FeatureSketchBased.h
Expand Up @@ -113,6 +113,9 @@ class PartDesignExport ProfileBased : public PartDesign::FeatureAddSub
//backwards compatibility: profile property was renamed and has different type now
virtual void Restore(Base::XMLReader& reader);

// calculate the through all length
double getThroughAllLength() const;

protected:
void remapSupportShape(const TopoDS_Shape&);

Expand All @@ -132,14 +135,14 @@ class PartDesignExport ProfileBased : public PartDesign::FeatureAddSub
* Generate a linear prism
* It will be a stand-alone solid created with BRepPrimAPI_MakePrism
*/
static void generatePrism(TopoDS_Shape& prism,
const TopoDS_Shape& sketchshape,
const std::string& method,
const gp_Dir& direction,
const double L,
const double L2,
const bool midplane,
const bool reversed);
void generatePrism(TopoDS_Shape& prism,
const TopoDS_Shape& sketchshape,
const std::string& method,
const gp_Dir& direction,
const double L,
const double L2,
const bool midplane,
const bool reversed);
/**
* Generate a linear prism
* It will be a stand-alone solid created with BRepFeat_MakePrism
Expand Down

0 comments on commit f0d3e19

Please sign in to comment.