diff --git a/src/Mod/TechDraw/App/DrawComplexSection.cpp b/src/Mod/TechDraw/App/DrawComplexSection.cpp index 167b8f442dc4..4c2765b4a5a6 100644 --- a/src/Mod/TechDraw/App/DrawComplexSection.cpp +++ b/src/Mod/TechDraw/App/DrawComplexSection.cpp @@ -123,31 +123,6 @@ using namespace TechDraw; using namespace std; using DU = DrawUtil; -//class to store geometry of points where the section line changes direction -ChangePoint::ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection) -{ - m_location = location; - m_preDirection = preDirection; - m_postDirection = postDirection; -} - -ChangePoint::ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection) -{ - m_location.setX(location.X()); - m_location.setY(location.Y()); - m_preDirection.setX(preDirection.X()); - m_preDirection.setY(preDirection.Y()); - m_postDirection.setX(postDirection.X()); - m_postDirection.setY(postDirection.Y()); -} - -void ChangePoint::scale(double scaleFactor) -{ - m_location = m_location * scaleFactor; - m_preDirection = m_preDirection * scaleFactor; - m_postDirection = m_postDirection * scaleFactor; -} - //=========================================================================== // DrawComplexSection //=========================================================================== diff --git a/src/Mod/TechDraw/App/DrawComplexSection.h b/src/Mod/TechDraw/App/DrawComplexSection.h index e6bac6f0ebf4..769ef31e0e27 100644 --- a/src/Mod/TechDraw/App/DrawComplexSection.h +++ b/src/Mod/TechDraw/App/DrawComplexSection.h @@ -35,27 +35,6 @@ namespace TechDraw { -//changes in direction of complex section line -class ChangePoint -{ -public: - ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection); - ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection); - ~ChangePoint() = default; - - QPointF getLocation() const { return m_location; } - QPointF getPreDirection() const { return m_preDirection; } - QPointF getPostDirection() const { return m_postDirection; } - void scale(double scaleFactor); - -private: - QPointF m_location; - QPointF m_preDirection; - QPointF m_postDirection; -}; - -using ChangePointVector = std::vector; - class TechDrawExport DrawComplexSection: public DrawViewSection { PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawComplexSection); @@ -94,7 +73,7 @@ class TechDrawExport DrawComplexSection: public DrawViewSection std::pair sectionArrowDirs(); TopoDS_Wire makeSectionLineWire(); - ChangePointVector getChangePointsFromSectionLine(); + ChangePointVector getChangePointsFromSectionLine() override; bool validateProfilePosition(TopoDS_Wire profileWire, gp_Ax2 sectionCS, gp_Dir &gClosestBasis) const; diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 5fdae12e370e..f11a153981a3 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -145,11 +145,17 @@ class TechDrawExport DrawUtil { Base::Vector3d p2, Base::Vector3d d2); static Base::Vector2d Intersect2d(Base::Vector2d p1, Base::Vector2d d1, Base::Vector2d p2, Base::Vector2d d2); + static Base::Vector3d toVector3d(const gp_Pnt gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); } static Base::Vector3d toVector3d(const gp_Dir gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); } + static Base::Vector3d toVector3d(const gp_Vec gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); } + static Base::Vector3d toVector3d(const QPointF gp) { return Base::Vector3d(gp.x(), gp.y(), 0.0); } + static gp_Pnt togp_Pnt(const Base::Vector3d v) { return gp_Pnt(v.x, v.y, v.z); } static gp_Dir togp_Dir(const Base::Vector3d v) { return gp_Dir(v.x, v.y, v.z); } static gp_Vec togp_Vec(const Base::Vector3d v) { return gp_Vec(v.x, v.y, v.z); } + static QPointF toQPointF(const Base::Vector3d v) { return QPointF(v.x, v.y); } + static std::string shapeToString(TopoDS_Shape s); static TopoDS_Shape shapeFromString(std::string s); static Base::Vector3d invertY(Base::Vector3d v); diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index ccd7a2f87293..d2224bfd1910 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -95,6 +95,29 @@ using namespace TechDraw; using DU = DrawUtil; +//class to store geometry of points where the section line changes direction +ChangePoint::ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection) +{ + m_location = location; + m_preDirection = preDirection; + m_postDirection = postDirection; +} + +ChangePoint::ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection) +{ + m_location.setX(location.X()); + m_location.setY(location.Y()); + m_preDirection.setX(preDirection.X()); + m_preDirection.setY(preDirection.Y()); + m_postDirection.setX(postDirection.X()); + m_postDirection.setY(postDirection.Y()); +} + +void ChangePoint::scale(double scaleFactor) +{ + m_location = m_location * scaleFactor; +} + const char* DrawViewSection::SectionDirEnums[]= {"Right", "Left", "Up", @@ -726,6 +749,30 @@ std::pair DrawViewSection::sectionLineEnds() return result; } +//find the points and directions to make the change point marks. +ChangePointVector DrawViewSection::getChangePointsFromSectionLine() +{ + // Base::Console().Message("Dvs::getChangePointsFromSectionLine()\n"); + ChangePointVector result; + std::vector allPoints; + DrawViewPart *baseDvp = dynamic_cast(BaseView.getValue()); + if (baseDvp) { + std::pair lineEnds = sectionLineEnds(); + //make start and end marks + gp_Pnt location0 = DU::togp_Pnt(lineEnds.first); + gp_Pnt location1 = DU::togp_Pnt(lineEnds.second); + gp_Dir postDir = gp_Dir(location1.XYZ() - location0.XYZ()); + gp_Dir preDir = postDir.Reversed(); + ChangePoint startPoint(location0, preDir, postDir); + result.push_back(startPoint); + preDir = gp_Dir(location0.XYZ() - location1.XYZ()); + postDir = preDir.Reversed(); + ChangePoint endPoint(location1, preDir, postDir); + result.push_back(endPoint); + } + return result; +} + //this should really be in BoundBox.h //!check if point is in box or on boundary of box //!compare to isInBox which doesn't allow on boundary diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index e2ba17bbbca7..93877ef8eb70 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -58,6 +58,28 @@ class PATLineSpec; class LineSet; class DashSet; +//changes in direction of complex section line. also marks at arrow positions. +class ChangePoint +{ +public: + ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection); + ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection); + ~ChangePoint() = default; + + QPointF getLocation() const { return m_location; } + void setLocation(QPointF newLocation) { m_location = newLocation; } + QPointF getPreDirection() const { return m_preDirection; } + QPointF getPostDirection() const { return m_postDirection; } + void scale(double scaleFactor); + +private: + QPointF m_location; + QPointF m_preDirection; + QPointF m_postDirection; +}; + +using ChangePointVector = std::vector; + class TechDrawExport DrawViewSection : public DrawViewPart { PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawViewSection); @@ -141,6 +163,7 @@ class TechDrawExport DrawViewSection : public DrawViewPart static const char* CutSurfaceEnums[]; virtual std::pair sectionLineEnds(); + virtual ChangePointVector getChangePointsFromSectionLine(); bool showSectionEdges(void); diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 9aa0c66d2b18..7691e158f2d1 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -86,6 +86,7 @@ using namespace TechDraw; using namespace TechDrawGui; using namespace std; +using DU = DrawUtil; #define GEOMETRYEDGE 0 #define COSMETICEDGE 1 @@ -844,17 +845,32 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b Base::Vector3d l1 = Rez::guiX(sLineEnds.first) * scale; Base::Vector3d l2 = Rez::guiX(sLineEnds.second) * scale; //make the section line a little longer - double fudge = Rez::guiX(2.0 * Preferences::dimFontSizeMM()); + double fudge = 2.0 * Preferences::dimFontSizeMM(); Base::Vector3d lineDir = l2 - l1; lineDir.Normalize(); - sectionLine->setEnds(l1 - lineDir * fudge, - l2 + lineDir * fudge); + sectionLine->setEnds(l1 - lineDir * Rez::guiX(fudge), + l2 + lineDir * Rez::guiX(fudge)); //which way do the arrows point? Base::Vector3d arrowDir = viewSection->SectionNormal.getValue(); arrowDir = - viewPart->projectPoint(arrowDir); //arrows point reverse of sectionNormal sectionLine->setDirection(arrowDir.x, - arrowDir.y); //3d direction needs Y inversion + if (vp->SectionLineMarks.getValue()) { + ChangePointVector points = viewSection->getChangePointsFromSectionLine(); + //extend the changePoint locations to match the fudged section line ends + QPointF location0 = points.front().getLocation() * scale; + location0 = location0 - DU::toQPointF(lineDir) * fudge; + QPointF location1 = points.back().getLocation() * scale; + location1 = location1 + DU::toQPointF(lineDir) * fudge; + //change points have Rez::guiX applied in sectionLine + points.front().setLocation(location0); + points.back().setLocation(location1); + sectionLine->setChangePoints(points); + } else { + sectionLine->clearChangePoints(); + } + //set the general parameters sectionLine->setPos(0.0, 0.0); sectionLine->setWidth(lineWidthThin);