Skip to content

Commit

Permalink
[TD]add arrow style - Pyramid
Browse files Browse the repository at this point in the history
- contributed by @lidiriel
  • Loading branch information
WandererFan committed Dec 31, 2019
1 parent dcc2790 commit ac680bf
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 21 deletions.
26 changes: 18 additions & 8 deletions src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui
Expand Up @@ -84,7 +84,7 @@
<property name="toolTip">
<string>Dimension text color</string>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>0</red>
<green>0</green>
Expand Down Expand Up @@ -225,6 +225,16 @@
<normaloff>:/icons/arrowfork.svg</normaloff>:/icons/arrowfork.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>6 - Pyramid</string>
</property>
<property name="icon">
<iconset>
<normalon>:/icons/arrowpyramid.svg</normalon>
</iconset>
</property>
</item>
</widget>
</item>
<item row="8" column="0">
Expand Down Expand Up @@ -254,11 +264,11 @@
</widget>
</item>
<item row="4" column="2">
<widget class="Gui::PrefUnitSpinBox" name="plsb_FontSize">
<widget class="Gui::PrefUnitSpinBox" name="plsb_FontSize" native="true">
<property name="toolTip">
<string>Dimension font size in units</string>
</property>
<property name="value">
<property name="value" stdset="0">
<double>5.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
Expand All @@ -270,11 +280,11 @@
</widget>
</item>
<item row="9" column="2">
<widget class="Gui::PrefUnitSpinBox" name="plsb_ArrowSize">
<widget class="Gui::PrefUnitSpinBox" name="plsb_ArrowSize" native="true">
<property name="toolTip">
<string>Dimension arrowhead size in units</string>
</property>
<property name="value">
<property name="value" stdset="0">
<double>3.500000000000000</double>
</property>
<property name="prefEntry" stdset="0">
Expand Down Expand Up @@ -395,7 +405,7 @@
<property name="toolTip">
<string>Color for centerlines</string>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>175</red>
<green>175</green>
Expand Down Expand Up @@ -585,7 +595,7 @@
<property name="toolTip">
<string>Line color for sectionlines</string>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>175</red>
<green>175</green>
Expand Down Expand Up @@ -648,7 +658,7 @@
<property name="toolTip">
<string>Vertex display color</string>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>150</red>
<green>147</green>
Expand Down
76 changes: 63 additions & 13 deletions src/Mod/TechDraw/Gui/QGIArrow.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
{
Expand All @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Mod/TechDraw/Gui/QGIArrow.h
Expand Up @@ -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:
Expand Down Expand Up @@ -75,6 +85,8 @@ class TechDrawGuiExport QGIArrow : public QGIPrimPath
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;
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/Resources/TechDraw.qrc
Expand Up @@ -42,6 +42,7 @@
<file>icons/arrowopen.svg</file>
<file>icons/arrowtick.svg</file>
<file>icons/arrowfork.svg</file>
<file>icons/arrowpyramid.svg</file>
<file>icons/actions/techdraw-PageDefault.svg</file>
<file>icons/actions/techdraw-PageTemplate.svg</file>
<file>icons/actions/techdraw-View.svg</file>
Expand Down
85 changes: 85 additions & 0 deletions src/Mod/TechDraw/Gui/Resources/icons/arrowpyramid.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ac680bf

Please sign in to comment.