1
/***************************************************************************
2
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
26
# include <QPainterPath>
29
#include <Mod/TechDraw/App/ArrowPropEnum.h>
32
#include "PreferencesGui.h"
36
using namespace TechDrawGui;
37
using namespace TechDraw;
40
m_fill(Qt::SolidPattern),
41
m_size(getPrefArrowSize()),
44
m_dir(Base::Vector3d(1.0, 0.0, 0.0))
47
setFillStyle(Qt::SolidPattern);
48
m_brush.setStyle(m_fill);
49
m_colDefFill = getNormalColor();
50
m_colNormalFill = m_colDefFill;
52
setCacheMode(QGraphicsItem::NoCache);
53
setAcceptHoverEvents(false);
54
setFlag(QGraphicsItem::ItemIsSelectable, false);
55
setFlag(QGraphicsItem::ItemIsMovable, false);
58
void QGIArrow::draw() {
60
if (m_style == ArrowType::FILLED_ARROW) {
62
path = makeFilledTriangle(getDirection(), m_size, m_size/6.0);
64
path = makeFilledTriangle(m_size, m_size/6.0, isFlipped()); //"arrow l/w sb 3/1" ??
66
} else if (m_style == ArrowType::OPEN_ARROW) {
68
path = makeOpenArrow(getDirection(), m_size, m_size/3.0); //broad arrow?
70
path = makeOpenArrow(m_size, m_size/3.0, isFlipped());
72
} else if (m_style == ArrowType::TICK) {
74
path = makeHashMark(getDirection(), m_size/2.0, m_size/2.0); //big enough?
76
path = makeHashMark(m_size/2.0, m_size/2.0, isFlipped()); //big enough?
78
} else if (m_style == ArrowType::DOT) {
79
path = makeDot(m_size/2.0, m_size/2.0, isFlipped());
80
} else if (m_style == ArrowType::OPEN_CIRCLE) {
81
path = makeOpenDot(m_size/2.0, m_size/2.0, isFlipped());
82
} else if (m_style == ArrowType::FORK) {
84
path = makeForkArrow(getDirection(), m_size/2.0, m_size/2.0); //big enough?
86
path = makeForkArrow(m_size/2.0, m_size/2.0, isFlipped()); //big enough?
88
} else if (m_style == ArrowType::FILLED_TRIANGLE){
90
path = makePyramid(getDirection(), m_size);
92
path = makePyramid(m_size, isFlipped());
95
path = makeFilledTriangle(m_size, m_size/6.0, isFlipped()); //sb a question mark or ???
100
void QGIArrow::setSize(double s)
106
QPainterPath QGIArrow::makeFilledTriangle(double length, double width, bool flipped)
108
//(0, 0) is tip of arrow
114
path.moveTo(QPointF(0., 0.));
115
path.lineTo(QPointF(Rez::guiX(length), Rez::guiX(-width)));
116
path.lineTo(QPointF(Rez::guiX(length), Rez::guiX(width)));
118
setFillStyle(Qt::SolidPattern);
122
QPainterPath QGIArrow::makeFilledTriangle(Base::Vector3d dir, double length, double width)
124
//(0, 0) is tip of arrow
125
// dir is direction arrow points
126
Base::Vector3d negDir = -dir;
128
Base::Vector3d perp(-negDir.y, negDir.x, 0.0);
129
Base::Vector3d barb1 = negDir * length + perp * width;
130
Base::Vector3d barb2 = negDir * length - perp * width;
133
path.moveTo(QPointF(0., 0.));
134
path.lineTo(QPointF(Rez::guiX(barb1.x), Rez::guiX(barb1.y)));
135
path.lineTo(QPointF(Rez::guiX(barb2.x), Rez::guiX(barb2.y)));
137
setFillStyle(Qt::SolidPattern);
141
QPainterPath QGIArrow::makeOpenArrow(double length, double width, bool flipped)
143
//(0, 0) is tip of arrow
149
path.moveTo(QPointF(Rez::guiX(length), Rez::guiX(-width)));
150
path.lineTo(QPointF(0., 0.));
151
path.lineTo(QPointF(Rez::guiX(length), Rez::guiX(width)));
152
setFillStyle(Qt::NoBrush);
156
QPainterPath QGIArrow::makeOpenArrow(Base::Vector3d dir, double length, double width)
158
//(0, 0) is tip of arrow
159
Base::Vector3d negDir = -dir;
161
Base::Vector3d perp(-negDir.y, negDir.x, 0.0);
162
Base::Vector3d barb1 = negDir * length + perp * width;
163
Base::Vector3d barb2 = negDir * length - perp * width;
166
path.moveTo(QPointF(Rez::guiX(barb1.x), Rez::guiX(barb1.y)));
167
path.lineTo(QPointF(0., 0.));
168
path.lineTo(QPointF(Rez::guiX(barb2.x), Rez::guiX(barb2.y)));
169
setFillStyle(Qt::NoBrush);
174
QPainterPath QGIArrow::makeHashMark(double length, double width, bool flipped) //Arch tick
176
double adjWidth = 1.0;
177
//(0, 0) is tip of arrow
183
path.moveTo(QPointF(Rez::guiX(length), Rez::guiX(adjWidth * (-width))));
184
path.lineTo(QPointF(Rez::guiX(-length), Rez::guiX(adjWidth * width)));
185
setFillStyle(Qt::NoBrush);
189
QPainterPath QGIArrow::makeHashMark(Base::Vector3d dir, double length, double width) //Arch tick
191
double adjWidth = 1.0;
192
Base::Vector3d negDir = -dir;
193
Base::Vector3d normDir = dir;
196
Base::Vector3d perp(-negDir.y, negDir.x, 0.0);
197
Base::Vector3d barb1 = negDir * length - perp * (adjWidth * width);
198
Base::Vector3d barb2 = normDir * length + perp * (adjWidth * width);
201
path.moveTo(QPointF(Rez::guiX(barb1.x), Rez::guiX(barb1.y)));
202
path.lineTo(QPointF(Rez::guiX(barb2.x), Rez::guiX(barb2.y)));
203
setFillStyle(Qt::NoBrush);
207
QPainterPath QGIArrow::makeDot(double length, double width, bool flipped) //closed dot
211
path.moveTo(0.0, 0.0); ////(0, 0) is Center of dot
212
path.addEllipse(Rez::guiX(-length/2.0), Rez::guiX(-width/2.0), Rez::guiX(length), Rez::guiX(width));
213
setFillStyle(Qt::SolidPattern);
217
QPainterPath QGIArrow::makeOpenDot(double length, double width, bool flipped)
221
path.moveTo(0.0, 0.0); ////(0, 0) is Center of dot
222
path.addEllipse(Rez::guiX(-length/2.0), Rez::guiX(-width/2.0), Rez::guiX(length), Rez::guiX(width));
223
setFillStyle(Qt::NoBrush);
227
QPainterPath QGIArrow::makeForkArrow(double length, double width, bool flipped)
229
//(0, 0) is tip of arrow
235
path.moveTo(QPointF(Rez::guiX(length), Rez::guiX(-width)));
236
path.lineTo(QPointF(0., 0.));
237
path.lineTo(QPointF(Rez::guiX(length), Rez::guiX(width)));
238
setFillStyle(Qt::NoBrush);
242
QPainterPath QGIArrow::makeForkArrow(Base::Vector3d dir, double length, double width)
244
//(0, 0) is tip of arrow
245
Base::Vector3d negDir = -dir;
246
Base::Vector3d normDir = dir;
249
Base::Vector3d perp(-normDir.y, normDir.x, 0.0);
250
Base::Vector3d barb1 = normDir * length + perp * width;
251
Base::Vector3d barb2 = normDir * length - perp * width;
254
path.moveTo(QPointF(Rez::guiX(barb1.x), Rez::guiX(barb1.y)));
255
path.lineTo(QPointF(0., 0.));
256
path.lineTo(QPointF(Rez::guiX(barb2.x), Rez::guiX(barb2.y)));
257
setFillStyle(Qt::NoBrush);
261
QPainterPath QGIArrow::makePyramid(double length, bool flipped)
263
double half_width = length/2.;
264
double top = -length;
266
// [(0, -width), (0, width)] is base of arrow
271
top = Rez::guiX(top);
272
base = Rez::guiX(base);
274
path.moveTo(QPointF(top, 0.));
275
path.lineTo(QPointF(base, Rez::guiX(-half_width)));
276
path.lineTo(QPointF(base, Rez::guiX(half_width)));
278
setFillStyle(Qt::SolidPattern);
282
QPainterPath QGIArrow::makePyramid(Base::Vector3d dir, double length)
284
//(0, 0) is tip of arrow
285
// dir is direction arrow points
286
Base::Vector3d negDir = -dir;
288
double width = length / 2.;
289
Base::Vector3d perp(-negDir.y, negDir.x, 0.0);
290
Base::Vector3d barb1 = perp * width;
291
Base::Vector3d barb2 = perp * -width;
292
Base::Vector3d top = negDir * length;
295
path.moveTo(QPointF(Rez::guiX(top.x), Rez::guiX(top.y)));
296
path.lineTo(QPointF(Rez::guiX(barb1.x), Rez::guiX(barb1.y)));
297
path.lineTo(QPointF(Rez::guiX(barb2.x), Rez::guiX(barb2.y)));
299
setFillStyle(Qt::SolidPattern);
303
int QGIArrow::getPrefArrowStyle()
305
return PreferencesGui::dimArrowStyle();
308
double QGIArrow::getPrefArrowSize()
310
return PreferencesGui::dimArrowSize();
313
double QGIArrow::getOverlapAdjust(int style, double size)
315
// adjustment required depends on arrow size and type! :(
316
// ex for fork and tick, adjustment sb zero. 0.25 is good for filled triangle, 0.1 for open arrow.
317
// open circle sb = radius
318
// NOTE: this may need to be adjusted to account for line thickness too.
319
// Base::Console().Message("QGIA::getOverlapAdjust(%d, %.3f) \n", style, size);
330
//diameter is size/2 so radius is size/4
334
case FILLED_TRIANGLE:
339
return 1.0; // Unknown