From 1a9637a384fde657d86d28ea040ed09134f5d812 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Thu, 10 Nov 2022 16:22:23 -0500 Subject: [PATCH] [TD]fix XDirection rotation of simple sections --- src/Mod/TechDraw/App/DrawViewPart.cpp | 27 ++++++++++++------------ src/Mod/TechDraw/App/DrawViewSection.cpp | 10 ++++----- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 73996ded23..c60dd6b08f 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -79,6 +79,7 @@ using namespace TechDraw; +using DU = DrawUtil; //=========================================================================== // DrawViewPart @@ -342,7 +343,7 @@ GeometryObject* DrawViewPart::makeGeometryForShape(TopoDS_Shape& shape) viewAxis, Rotation.getValue()); //conventional rotation } -// BRepTools::Write(scaledShape, "DVPScaled.brep"); //debug + BRepTools::Write(scaledShape, "DVPScaled.brep"); //debug GeometryObject* go = buildGeometryObject(scaledShape, viewAxis); return go; } @@ -1011,23 +1012,23 @@ bool DrawViewPart::hasGeometry(void) const //in the derived view. gp_Ax2 DrawViewPart::localVectorToCS(const Base::Vector3d localUnit) const { - gp_Pnt stdOrigin(0.0, 0.0, 0.0); - gp_Ax2 dvpCS = getProjectionCS(DrawUtil::toVector3d(stdOrigin)); - gp_Vec gLocalUnit = DrawUtil::togp_Dir(localUnit); - gp_Vec gLocalX(-gLocalUnit.Y(), gLocalUnit.X(), 0.0); //clockwise perp for 2d + double angle = atan2(localUnit.y, localUnit.x); //radians + gp_Ax1 rotateAxisDir(gp_Pnt(0.0, 0.0, 0.0), getProjectionCS().Direction()); + gp_Vec gNewDirection = getProjectionCS().XDirection().Rotated(rotateAxisDir, angle); - gp_Ax3 OXYZ; - gp_Trsf xLocalOXYZ; - xLocalOXYZ.SetTransformation(OXYZ, gp_Ax3(dvpCS)); - gp_Vec gLocalUnitOXYZ = gLocalUnit.Transformed(xLocalOXYZ); - gp_Vec gLocalXOXYZ = gLocalX.Transformed(xLocalOXYZ); - - return { stdOrigin, gp_Dir(gLocalUnitOXYZ), gp_Dir(gLocalXOXYZ) }; + gp_Vec crossDirs = getProjectionCS().Direction().Crossed(gNewDirection); + gp_Vec gNewX = getProjectionCS().XDirection(); + gp_Vec triple = crossDirs.Crossed(getProjectionCS().XDirection()); + if (!DU::fpCompare(triple.Magnitude(), 0.0, EWTOLERANCE)) { + gNewX = triple; + } + return { gp_Pnt(0.0, 0.0, 0.0), gp_Dir(gNewDirection), gp_Dir(gNewX) }; } + Base::Vector3d DrawViewPart::localVectorToDirection(const Base::Vector3d localUnit) const { - Base::Console().Message("DVP::localVectorToDirection() - localUnit: %s\n", DrawUtil::formatVector(localUnit).c_str()); +// Base::Console().Message("DVP::localVectorToDirection() - localUnit: %s\n", DrawUtil::formatVector(localUnit).c_str()); gp_Ax2 cs = localVectorToCS(localUnit); return DrawUtil::toVector3d(cs.Direction()); } diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index dc587b1e03..afa86bd7c6 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -492,7 +492,7 @@ void DrawViewSection::onSectionCutFinished() postSectionCutTasks(); //display geometry for cut shape is in geometryObject as in DVP - m_tempGeometryObject = buildGeometryObject(m_preparedShape, getSectionCS()); + m_tempGeometryObject = buildGeometryObject(m_preparedShape, getProjectionCS()); } //activities that depend on updated geometry object @@ -651,7 +651,7 @@ TopoDS_Compound DrawViewSection::mapToPage(TopoDS_Shape& shapeToAlign) TopExp_Explorer expWires(face, TopAbs_WIRE); for ( ; expWires.More(); expWires.Next()) { const TopoDS_Wire& wire = TopoDS::Wire(expWires.Current()); - TopoDS_Shape projectedShape = GeometryObject::projectSimpleShape(wire, getSectionCS()); + TopoDS_Shape projectedShape = GeometryObject::projectSimpleShape(wire, getProjectionCS()); std::vector wireEdges; //projectedShape is just a bunch of edges. we have to rebuild the wire. TopExp_Explorer expEdges(projectedShape, TopAbs_EDGE); @@ -814,7 +814,7 @@ void DrawViewSection::setCSFromBase(const Base::Vector3d localUnit) Base::Vector3d vXDir(newSectionCS.XDirection().X(), newSectionCS.XDirection().Y(), newSectionCS.XDirection().Z()); - XDirection.setValue(vXDir); + XDirection.setValue(vXDir); //XDir is for projection } //reset the section CS based on an XY vector in current section CS @@ -858,8 +858,8 @@ gp_Ax2 DrawViewSection::getCSFromBase(const std::string sectionName) const dvsDir = dvpUp; dvsXDir = dvpRight; } else if (sectionName == "Left") { - dvsDir = dvpRight; - dvsXDir = dvpDir.Reversed(); + dvsDir = dvpRight; //dvpX + dvsXDir = dvpDir.Reversed(); //-dvpZ } else if (sectionName == "Right") { dvsDir = dvpRight.Reversed(); dvsXDir = dvpDir;