From 911ab15224cf1ba49aeadbad6466c28e02121caf Mon Sep 17 00:00:00 2001 From: WandererFan Date: Sun, 29 Dec 2019 22:00:48 -0500 Subject: [PATCH] [TD]add arrow style - Pyramid - contributed by @lidiriel --- src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui | 26 ++++-- src/Mod/TechDraw/Gui/QGIArrow.cpp | 76 ++++++++++++++--- src/Mod/TechDraw/Gui/QGIArrow.h | 12 +++ src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 1 + .../Gui/Resources/icons/arrowpyramid.svg | 85 +++++++++++++++++++ 5 files changed, 179 insertions(+), 21 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/arrowpyramid.svg diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui index 665696eb5d..34cc979a24 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui @@ -84,7 +84,7 @@ Dimension text color - + 0 0 @@ -225,6 +225,16 @@ :/icons/arrowfork.svg:/icons/arrowfork.svg + + + 6 - Pyramid + + + + :/icons/arrowpyramid.svg + + + @@ -254,11 +264,11 @@ - + Dimension font size in units - + 5.000000000000000 @@ -270,11 +280,11 @@ - + Dimension arrowhead size in units - + 3.500000000000000 @@ -395,7 +405,7 @@ Color for centerlines - + 175 175 @@ -585,7 +595,7 @@ Line color for sectionlines - + 175 175 @@ -648,7 +658,7 @@ Vertex display color - + 150 147 diff --git a/src/Mod/TechDraw/Gui/QGIArrow.cpp b/src/Mod/TechDraw/Gui/QGIArrow.cpp index 5248e069cb..810068910d 100644 --- a/src/Mod/TechDraw/Gui/QGIArrow.cpp +++ b/src/Mod/TechDraw/Gui/QGIArrow.cpp @@ -62,40 +62,47 @@ QGIArrow::QGIArrow() : void QGIArrow::draw() { QPainterPath path; - if (m_style == 0) { + if (m_style == FILLED_TRIANGLE) { setFillStyle(Qt::SolidPattern); if (m_dirMode) { path = makeFilledTriangle(getDirection(), m_size,m_size/6.0); } else { path = makeFilledTriangle(m_size,m_size/6.0,isFlipped()); //"arrow l/w sb 3/1" ?? } - } else if (m_style == 1) { + } else if (m_style == OPEN_ARROW) { setFillStyle(Qt::NoBrush); if (m_dirMode) { path = makeOpenArrow(getDirection(), m_size,m_size/3.0); //broad arrow? } else { path = makeOpenArrow(m_size,m_size/3.0,isFlipped()); } - } else if (m_style == 2) { + } else if (m_style == HASH_MARK) { setFillStyle(Qt::NoBrush); if (m_dirMode) { path = makeHashMark(getDirection(), m_size/2.0,m_size/2.0); //big enough? } else { path = makeHashMark(m_size/2.0,m_size/2.0,isFlipped()); //big enough? } - } else if (m_style == 3) { + } else if (m_style == DOT) { setFillStyle(Qt::SolidPattern); path = makeDot(m_size/2.0,m_size/2.0,isFlipped()); - } else if (m_style == 4) { + } else if (m_style == OPEN_CIRCLE) { path = makeOpenDot(m_size/2.0,m_size/2.0,isFlipped()); - } else if (m_style == 5) { + } else if (m_style == FORK) { setFillStyle(Qt::NoBrush); if (m_dirMode) { path = makeForkArrow(getDirection(), m_size/2.0,m_size/2.0); //big enough? } else { path = makeForkArrow(m_size/2.0,m_size/2.0,isFlipped()); //big enough? } - } else { + } else if (m_style == PYRAMID){ + setFillStyle(Qt::SolidPattern); + if (m_dirMode) { + path = makePyramid(getDirection(), m_size); + } else { + path = makePyramid(m_size,isFlipped()); + } + }else { path = makeFilledTriangle(m_size,m_size/6.0,isFlipped()); //sb a question mark or ??? } setPath(path); @@ -262,7 +269,47 @@ QPainterPath QGIArrow::makeForkArrow(Base::Vector3d dir, double length, double w return path; } +QPainterPath QGIArrow::makePyramid(double length, bool flipped) +{ + double half_width = length/2.; + double top = -length; + double base = 0.; + // [(0,-width), (0, width)] is base of arrow + if (flipped) { + top = 0.; + base = -length; + } + top = Rez::guiX(top); + base = Rez::guiX(base); + QPainterPath path; + path.moveTo(QPointF(top, 0.)); + path.lineTo(QPointF(base,Rez::guiX(-half_width))); + path.lineTo(QPointF(base,Rez::guiX(half_width))); + path.closeSubpath(); + setFillStyle(Qt::SolidPattern); + return path; +} +QPainterPath QGIArrow::makePyramid(Base::Vector3d dir, double length) +{ + //(0,0) is tip of arrow + // dir is direction arrow points + Base::Vector3d negDir = -dir; + negDir.Normalize(); + double width = length / 2.; + Base::Vector3d perp(-negDir.y,negDir.x, 0.0); + Base::Vector3d barb1 = perp * width; + Base::Vector3d barb2 = perp * -width; + Base::Vector3d top = negDir * length; + + QPainterPath path; + path.moveTo(QPointF(Rez::guiX(top.x),Rez::guiX(top.y))); + path.lineTo(QPointF(Rez::guiX(barb1.x),Rez::guiX(barb1.y))); + path.lineTo(QPointF(Rez::guiX(barb2.x),Rez::guiX(barb2.y))); + path.closeSubpath(); + setFillStyle(Qt::SolidPattern); + return path; +} int QGIArrow::getPrefArrowStyle() { @@ -289,25 +336,28 @@ double QGIArrow::getOverlapAdjust(int style, double size) // Base::Console().Message("QGIA::getOverlapAdjust(%d, %.3f) \n",style, size); double result = 1.0; switch(style) { - case 0: //filled triangle + case FILLED_TRIANGLE: result = 0.50 * size; break; - case 1: //open arrow + case OPEN_ARROW: result = 0.10 * size; break; - case 2: //hash mark + case HASH_MARK: result = 0.0; break; - case 3: //dot + case DOT: result = 0.0; break; - case 4: //open circle + case OPEN_CIRCLE: //diameter is size/2 so radius is size/4 result = 0.25 * size; break; - case 5: //fork + case FORK: result = 0.0; break; + case PYRAMID: + result = 0.0; + break; default: //unknown result = 1.0; } diff --git a/src/Mod/TechDraw/Gui/QGIArrow.h b/src/Mod/TechDraw/Gui/QGIArrow.h index 9074a4b7ab..7c34e466f4 100644 --- a/src/Mod/TechDraw/Gui/QGIArrow.h +++ b/src/Mod/TechDraw/Gui/QGIArrow.h @@ -35,6 +35,16 @@ QT_END_NAMESPACE namespace TechDrawGui { +enum ArrowType { + FILLED_TRIANGLE = 0, + OPEN_ARROW, + HASH_MARK, + DOT, + OPEN_CIRCLE, + FORK, + PYRAMID +}; + class TechDrawGuiExport QGIArrow : public QGIPrimPath { public: @@ -75,6 +85,8 @@ protected: QPainterPath makeOpenDot(double length, double width, bool flipped); QPainterPath makeForkArrow(double length, double width, bool flipped); QPainterPath makeForkArrow(Base::Vector3d dir, double length, double width); + QPainterPath makePyramid(double length, bool flipped); + QPainterPath makePyramid(Base::Vector3d dir, double length); private: QBrush m_brush; diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 4dc118536f..3c1448c24f 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -42,6 +42,7 @@ icons/arrowopen.svg icons/arrowtick.svg icons/arrowfork.svg + icons/arrowpyramid.svg icons/actions/techdraw-PageDefault.svg icons/actions/techdraw-PageTemplate.svg icons/actions/techdraw-View.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/arrowpyramid.svg b/src/Mod/TechDraw/Gui/Resources/icons/arrowpyramid.svg new file mode 100644 index 0000000000..921e201185 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/arrowpyramid.svg @@ -0,0 +1,85 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + +