Skip to content

Commit

Permalink
[TD]fix fail to load CS for some profiles and directions
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Dec 9, 2022
1 parent 8b511b9 commit c5e3c54
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/Mod/TechDraw/App/DrawComplexSection.cpp
Expand Up @@ -175,7 +175,7 @@ TopoDS_Shape DrawComplexSection::getShapeToCut()

TopoDS_Shape DrawComplexSection::makeCuttingTool(double dMax)
{
// Base::Console().Message("DCS::makeCuttingTool()\n");
// Base::Console().Message("DCS::makeCuttingTool()\n");
TopoDS_Wire profileWire = makeProfileWire();
if (profileWire.IsNull()) {
throw Base::RuntimeError("Can not make wire from cutting tool (1)");
Expand Down Expand Up @@ -282,8 +282,8 @@ TopoDS_Shape DrawComplexSection::prepareShape(const TopoDS_Shape& cutShape, doub

void DrawComplexSection::makeSectionCut(TopoDS_Shape& baseShape)
{
// Base::Console().Message("DCS::makeSectionCut() - %s - baseShape.IsNull: %d\n",
// getNameInDocument(), baseShape.IsNull());
// Base::Console().Message("DCS::makeSectionCut() - %s - baseShape.IsNull: %d\n",
// getNameInDocument(), baseShape.IsNull());
if (ProjectionStrategy.getValue() == 0) {
//Offset. Use regular section behaviour
return DrawViewSection::makeSectionCut(baseShape);
Expand Down Expand Up @@ -325,7 +325,12 @@ void DrawComplexSection::onSectionCutFinished()
//TODO: this process should replace the "makeSectionCut" from DVS
void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape)
{
// Base::Console().Message("DCS::makeAlignedPieces() - rawShape.isNull: %d\n", rawShape.IsNull());
// Base::Console().Message("DCS::makeAlignedPieces() - rawShape.isNull: %d\n", rawShape.IsNull());

if (!canBuild(getSectionCS(), CuttingToolWireObject.getValue())) {
throw Base::RuntimeError("Profile is parallel to Section Normal");
}

std::vector<TopoDS_Shape> pieces;
std::vector<double> pieceXSizeAll;//size in sectionCS.XDirection (width)
std::vector<double> pieceYSizeAll;//size in sectionCS.Direction (depth)
Expand All @@ -346,13 +351,13 @@ void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape)
throw Base::RuntimeError("Can not make wire from cutting tool (2)");
}
gp_Vec gProfileVec = makeProfileVector(profileWire);
gp_Vec rotateAxis = (getSectionCS().Direction()).Crossed(gProfileVec);

//now we want to know what the profileVector looks like on the page (only X,Y coords)
//so we know if we are going to stack views vertically or horizontally and if the segments
//will occur (left to right or right to left) or (top to bottom or bottom to top)
gProfileVec = projectVector(gProfileVec).Normalized();

if (!canBuild(getSectionCS(), CuttingToolWireObject.getValue())) {
throw Base::RuntimeError("Profile is parallel to Section Normal");
}

bool isProfileVertical = true;
if (fabs(gProfileVec.Dot(gp::OY().Direction().XYZ())) != 1.0) {
//profile is not parallel with stdY (paper space Up).
Expand All @@ -371,11 +376,8 @@ void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape)
verticalReverser = -1.0;
}

gp_Vec rotateAxis = getSectionCS().Direction().Crossed(gProfileVec);

//make a tool for each segment of the toolFaceShape and intersect it with the
//raw shape
// TopExp_Explorer expFaces(toolFaceShape, TopAbs_FACE);
TopExp_Explorer expFaces(m_toolFaceShape, TopAbs_FACE);
for (int iPiece = 0; expFaces.More(); expFaces.Next(), iPiece++) {
TopoDS_Face face = TopoDS::Face(expFaces.Current());
Expand All @@ -385,7 +387,7 @@ void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape)
continue;
}
//we only want to reverse the segment normal if it is not perpendicular to section normal
if (segmentNormal.Dot(-gProjectionUnit) != 0.0
if (segmentNormal.Dot(gProjectionUnit) != 0.0
&& segmentNormal.Angle(gProjectionUnit) <= M_PI_2) {
segmentNormal.Reverse();
}
Expand Down

0 comments on commit c5e3c54

Please sign in to comment.