[TD]fix misplaced section line

- BRepBndLib::Add results in wrong bbox center.
- replaced with BRepBndLib::AddOptimal
This commit is contained in:
Wanderer Fan
2022-03-02 10:08:59 -05:00
committed by WandererFan
parent 7ebc4c44c9
commit 855941d5bb
10 changed files with 34 additions and 20 deletions

View File

@@ -899,7 +899,7 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints(DrawViewPart
if (!faceEdges.empty()) {
for (auto& fe: faceEdges) {
if (!fe->cosmetic) {
BRepBndLib::Add(fe->occEdge, faceBox);
BRepBndLib::AddOptimal(fe->occEdge, faceBox);
}
}
}

View File

@@ -194,7 +194,7 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawDimHelper::minMax(DrawViewPart* dv
std::vector<hTrimCurve> hTCurve2dList;
for (auto& bg: selEdges) {
TopoDS_Edge e = bg->occEdge;
BRepBndLib::Add(e, edgeBbx);
BRepBndLib::AddOptimal(e, edgeBbx);
double first = 0.0;
double last = 0.0;
Handle(Geom_Curve) hCurve = BRep_Tool::Curve(e, first, last);

View File

@@ -285,7 +285,7 @@ std::vector<LineSet> DrawGeomHatch::getTrimmedLines(DrawViewPart* source,
TopoDS_Face face = f;
Bnd_Box bBox;
BRepBndLib::Add(face, bBox);
BRepBndLib::AddOptimal(face, bBox);
bBox.SetGap(0.0);
for (auto& ls: lineSets) {
@@ -312,7 +312,7 @@ std::vector<LineSet> DrawGeomHatch::getTrimmedLines(DrawViewPart* source,
//save the boundingBox of hatch pattern
Bnd_Box overlayBox;
overlayBox.SetGap(0.0);
BRepBndLib::Add(common, overlayBox);
BRepBndLib::AddOptimal(common, overlayBox);
ls.setBBox(overlayBox);
//get resulting edges
@@ -471,7 +471,7 @@ std::vector<LineSet> DrawGeomHatch::getFaceOverlay(int fdx)
TopoDS_Face face = extractFace(source,fdx);
Bnd_Box bBox;
BRepBndLib::Add(face, bBox);
BRepBndLib::AddOptimal(face, bBox);
bBox.SetGap(0.0);
for (auto& ls: m_lineSets) {

View File

@@ -177,7 +177,7 @@ std::vector<TopoDS_Edge> DrawProjectSplit::getEdges(TechDraw::GeometryObject* ge
TopoDS_Vertex v1 = TopExp::FirstVertex((*itOuter));
TopoDS_Vertex v2 = TopExp::LastVertex((*itOuter));
Bnd_Box sOuter;
BRepBndLib::Add(*itOuter, sOuter);
BRepBndLib::AddOptimal(*itOuter, sOuter);
sOuter.SetGap(0.1);
if (sOuter.IsVoid()) {
Base::Console().Message("DPS::Extract Faces - outer Bnd_Box is void\n");
@@ -198,7 +198,7 @@ std::vector<TopoDS_Edge> DrawProjectSplit::getEdges(TechDraw::GeometryObject* ge
}
Bnd_Box sInner;
BRepBndLib::Add(*itInner, sInner);
BRepBndLib::AddOptimal(*itInner, sInner);
sInner.SetGap(0.1);
if (sInner.IsVoid()) {
Base::Console().Log("INFO - DPS::Extract Faces - inner Bnd_Box is void\n");
@@ -251,7 +251,7 @@ bool DrawProjectSplit::isOnEdge(TopoDS_Edge e, TopoDS_Vertex v, double& param, b
//eliminate obvious cases
Bnd_Box sBox;
BRepBndLib::Add(e, sBox);
BRepBndLib::AddOptimal(e, sBox);
sBox.SetGap(0.1);
if (sBox.IsVoid()) {
Base::Console().Message("DPS::isOnEdge - Bnd_Box is void\n");

View File

@@ -297,15 +297,15 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawUtil::boxIntersect2d(Base::Vector3
// y = mx + b
// m = (y1 - y0) / (x1 - x0)
if (DrawUtil::fpCompare(dir.x, 0.0) ) { //vertical case
p1 = Base::Vector3d(point.x, - yRange / 2.0, 0.0);
p2 = Base::Vector3d(point.x, yRange / 2.0, 0.0);
p1 = Base::Vector3d(point.x, point.y - (yRange / 2.0), 0.0);
p2 = Base::Vector3d(point.x, point.y + (yRange / 2.0), 0.0);
} else {
double slope = dir.y / dir.x;
double left = -xRange / 2.0;
double right = xRange / 2.0;
if (DrawUtil::fpCompare(slope, 0.0)) { //horizontal case
p1 = Base::Vector3d(left, point.y);
p2 = Base::Vector3d(right, point.y);
p1 = Base::Vector3d(point.x - (xRange / 2.0), point.y);
p2 = Base::Vector3d(point.x + (xRange / 2.0), point.y);
} else { //normal case
double top = yRange / 2.0;
double bottom = -yRange / 2.0;

View File

@@ -318,7 +318,7 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape,
Bnd_Box bbxSource;
bbxSource.SetGap(0.0);
BRepBndLib::Add(myShape, bbxSource);
BRepBndLib::AddOptimal(myShape, bbxSource);
double diag = sqrt(bbxSource.SquareExtent());
Base::Vector3d toolPlaneOrigin = anchorOffset3d + dirDetail * diag * -1.0; //center tool about anchor

View File

@@ -417,8 +417,11 @@ GeometryObject* DrawViewPart::makeGeometryForShape(TopoDS_Shape shape)
gp_Ax2 viewAxis = getProjectionCS(stdOrg);
// BRepTools::Write(shape, "DVPShape.brep"); //debug
inputCenter = TechDraw::findCentroid(shape,
viewAxis);
Base::Vector3d centroid(inputCenter.X(),
inputCenter.Y(),
inputCenter.Z());
@@ -536,7 +539,7 @@ void DrawViewPart::extractFaces()
TopoDS_Vertex v1 = TopExp::FirstVertex((*itOuter));
TopoDS_Vertex v2 = TopExp::LastVertex((*itOuter));
Bnd_Box sOuter;
BRepBndLib::Add(*itOuter, sOuter);
BRepBndLib::AddOptimal(*itOuter, sOuter);
sOuter.SetGap(0.1);
if (sOuter.IsVoid()) {
Base::Console().Log("DVP::Extract Faces - outer Bnd_Box is void for %s\n",getNameInDocument());
@@ -557,7 +560,7 @@ void DrawViewPart::extractFaces()
}
Bnd_Box sInner;
BRepBndLib::Add(*itInner, sInner);
BRepBndLib::AddOptimal(*itInner, sInner);
sInner.SetGap(0.1);
if (sInner.IsVoid()) {
Base::Console().Log("INFO - DVP::Extract Faces - inner Bnd_Box is void for %s\n",getNameInDocument());
@@ -928,6 +931,16 @@ Base::Vector3d DrawViewPart::getOriginalCentroid(void) const
return m_saveCentroid;
}
Base::Vector3d DrawViewPart::getCurrentCentroid(void) const
{
TopoDS_Shape shape = getSourceShape();
gp_Ax2 cs = getProjectionCS(Base::Vector3d(0.0, 0.0, 0.0));
Base::Vector3d center = TechDraw::findCentroidVec(shape, cs);
Base::Console().Message("DVP::getCurrentCentroid - center: %s\n",
DrawUtil::formatVector(center).c_str());
return center;
}
std::vector<DrawViewSection*> DrawViewPart::getSectionRefs(void) const
{
std::vector<DrawViewSection*> result;

View File

@@ -156,6 +156,7 @@ public:
virtual gp_Ax2 getProjectionCS(Base::Vector3d pt) const;
virtual Base::Vector3d getXDirection(void) const; //don't use XDirection.getValue()
virtual Base::Vector3d getOriginalCentroid(void) const;
virtual Base::Vector3d getCurrentCentroid(void) const;
virtual Base::Vector3d getLegacyX(const Base::Vector3d& pt,
const Base::Vector3d& axis,
const bool flip = true) const;

View File

@@ -357,7 +357,7 @@ void DrawViewSection::sectionExec(TopoDS_Shape baseShape)
// cut base shape with tool
//is SectionOrigin valid?
Bnd_Box centerBox;
BRepBndLib::Add(baseShape, centerBox);
BRepBndLib::AddOptimal(baseShape, centerBox);
centerBox.SetGap(0.0);
// make tool
@@ -414,7 +414,7 @@ void DrawViewSection::sectionExec(TopoDS_Shape baseShape)
// check for error in cut
Bnd_Box testBox;
BRepBndLib::Add(rawShape, testBox);
BRepBndLib::AddOptimal(rawShape, testBox);
testBox.SetGap(0.0);
if (testBox.IsVoid()) { //prism & input don't intersect. rawShape is garbage, don't bother.
Base::Console().Warning("DVS::execute - prism & input don't intersect - %s\n", Label.getValue());

View File

@@ -772,7 +772,7 @@ Base::BoundBox3d GeometryObject::calcBoundingBox() const
if (!edgeGeom.empty()) {
for (BaseGeomPtrVector::const_iterator it( edgeGeom.begin() );
it != edgeGeom.end(); ++it) {
BRepBndLib::Add((*it)->occEdge, testBox);
BRepBndLib::AddOptimal((*it)->occEdge, testBox);
}
}
@@ -937,9 +937,9 @@ gp_Pnt TechDraw::findCentroid(const TopoDS_Shape &shape,
BRepBuilderAPI_Transform builder(shape, tempTransform);
Bnd_Box tBounds;
BRepBndLib::Add(builder.Shape(), tBounds);
tBounds.SetGap(0.0);
BRepBndLib::AddOptimal(builder.Shape(), tBounds, true, false);
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
tBounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);