[TD]fix centering of shape

- centering of shape was not affecting the OCC TShape, so
  we now make a deep copy of the original
This commit is contained in:
wandererfan
2023-03-12 10:33:53 -04:00
committed by WandererFan
parent 37d7f7d570
commit fb9b3a9e9e
2 changed files with 50 additions and 11 deletions

View File

@@ -318,11 +318,21 @@ void DrawViewPart::partExec(TopoDS_Shape& shape)
//prepare the shape for HLR processing by centering, scaling and rotating it
GeometryObjectPtr DrawViewPart::makeGeometryForShape(TopoDS_Shape& shape)
{
// Base::Console().Message("DVP::makeGeometryForShape() - %s\n", getNameInDocument());
gp_Pnt inputCenter = TechDraw::findCentroid(shape, getProjectionCS());
m_saveCentroid = DU::toVector3d(inputCenter);
m_saveShape = centerScaleRotate(this, shape, m_saveCentroid);
GeometryObjectPtr go = buildGeometryObject(shape, getProjectionCS());
// Base::Console().Message("DVP::makeGeometryForShape() - %s\n", getNameInDocument());
// if we use the passed reference directly, the centering doesn't work. Maybe the underlying OCC TShape
// isn't modified? using a copy works and the referenced shape (from getSourceShape in execute())
// isn't used for anything anyway.
bool copyGeometry = true;
bool copyMesh = false;
BRepBuilderAPI_Copy copier(shape, copyGeometry, copyMesh);
TopoDS_Shape localShape = copier.Shape();
gp_Pnt gCentroid = TechDraw::findCentroid(localShape, getProjectionCS());
m_saveCentroid = DU::toVector3d(gCentroid);
m_saveShape = centerScaleRotate(this, localShape, m_saveCentroid);
GeometryObjectPtr go = buildGeometryObject(localShape, getProjectionCS());
return go;
}
@@ -330,7 +340,7 @@ GeometryObjectPtr DrawViewPart::makeGeometryForShape(TopoDS_Shape& shape)
TopoDS_Shape DrawViewPart::centerScaleRotate(DrawViewPart* dvp, TopoDS_Shape& inOutShape,
Base::Vector3d centroid)
{
// Base::Console().Message("DVP::centerScaleRotate() - %s\n", dvp->getNameInDocument());
// Base::Console().Message("DVP::centerScaleRotate() - %s\n", dvp->getNameInDocument());
gp_Ax2 viewAxis = dvp->getProjectionCS();
//center shape on origin
@@ -345,12 +355,11 @@ TopoDS_Shape DrawViewPart::centerScaleRotate(DrawViewPart* dvp, TopoDS_Shape& in
return centeredShape;
}
//create a geometry object and trigger the HLR process in another thread
TechDraw::GeometryObjectPtr DrawViewPart::buildGeometryObject(TopoDS_Shape& shape,
const gp_Ax2& viewAxis)
{
// Base::Console().Message("DVP::buildGeometryObject() - %s\n", getNameInDocument());
// Base::Console().Message("DVP::buildGeometryObject() - %s\n", getNameInDocument());
showProgressMessage(getNameInDocument(), "is finding hidden lines");
TechDraw::GeometryObjectPtr go(
@@ -366,6 +375,15 @@ TechDraw::GeometryObjectPtr DrawViewPart::buildGeometryObject(TopoDS_Shape& shap
go->projectShapeWithPolygonAlgo(shape, viewAxis);
}
else {
// TODO: we should give the thread its own copy of the shape because the passed one will be
// destroyed when the call stack we followed to get here unwinds and the thread could still be
// running.
// Should we pass a smart pointer instead of const& ??
// bool copyGeometry = true;
// bool copyMesh = false;
// BRepBuilderAPI_Copy copier(shape, copyGeometry, copyMesh);
// copier.Shape();
//projectShape (the HLR process) runs in a separate thread since it can take a long time
//note that &m_hlrWatcher in the third parameter is not strictly required, but using the
//4 parameter signature instead of the 3 parameter signature prevents clazy warning:
@@ -1144,11 +1162,28 @@ Base::Vector3d DrawViewPart::getOriginalCentroid() const { return m_saveCentroid
Base::Vector3d DrawViewPart::getCurrentCentroid() const
{
TopoDS_Shape shape = getSourceShape();
gp_Ax2 cs = getProjectionCS(Base::Vector3d(0.0, 0.0, 0.0));
Base::Vector3d center = TechDraw::findCentroidVec(shape, cs);
return center;
if (shape.IsNull()) {
return Base::Vector3d(0.0, 0.0, 0.0);
}
gp_Ax2 cs = getProjectionCS();
gp_Pnt gCenter = TechDraw::findCentroid(shape, cs);
return DU::toVector3d(gCenter);
}
Base::Vector3d DrawViewPart::getLocalOrigin3d() const
{
return getCurrentCentroid();
}
Base::Vector3d DrawViewPart::getLocalOrigin2d() const
{
Base::Vector3d centroid = getCurrentCentroid();
Base::Vector3d localOrigin = projectPoint(centroid, false);
return localOrigin;
}
std::vector<DrawViewSection*> DrawViewPart::getSectionRefs() const
{
std::vector<DrawViewSection*> result;