55 #include <QGraphicsLineItem>
56 #include <QGraphicsPathItem>
57 #include <QGuiApplication>
59 #include <QPainterPath>
60 #include <QSharedPointer>
62 #include <QtAlgorithms>
66 #include "../ifc/xml/vdomdocument.h"
67 #include "../vmisc/diagnostic.h"
68 #include "../vgeometry/vabstractcurve.h"
69 #include "../vgeometry/varc.h"
70 #include "../vgeometry/vcubicbezier.h"
71 #include "../vgeometry/vcubicbezierpath.h"
72 #include "../vgeometry/vellipticalarc.h"
73 #include "../vgeometry/vgeometrydef.h"
74 #include "../vgeometry/vgobject.h"
75 #include "../vgeometry/vpointf.h"
76 #include "../vgeometry/vspline.h"
77 #include "../vgeometry/vsplinepath.h"
78 #include "../vgeometry/varc.h"
79 #include "../vmisc/vabstractapplication.h"
80 #include "../vpatterndb/vcontainer.h"
81 #include "../vwidgets/vmaingraphicsscene.h"
83 #include "../vmisc/logging.h"
85 Q_LOGGING_CATEGORY(visTool,
"vistool")
92 , rotationAngle(INT_MIN)
93 , originPointItem(
nullptr)
94 , rotationOriginPointItem(
nullptr)
95 , rotationFinishPointItem(
nullptr)
96 , moveLineItem(
nullptr)
97 , rotationLineItem(
nullptr)
99 , m_rotationPoint(QPointF())
101 originPointItem = InitPoint(supportColor2,
this, 110);
102 originPointItem->setBrush(QBrush(supportColor2, Qt::SolidPattern));
104 rotationOriginPointItem = InitPoint(supportColor2,
this, 120);
105 rotationOriginPointItem->setBrush(QBrush(supportColor2, Qt::SolidPattern));
107 rotationFinishPointItem = InitPoint(supportColor3,
this, 130);
108 rotationFinishPointItem->setBrush(QBrush(supportColor3, Qt::SolidPattern));
110 moveLineItem = InitItem<ArrowedLineItem>(supportColor2,
this);
111 rotationLineItem = InitItem<VScaledLine>(supportColor3,
this);
133 qreal tempLength = 0;
134 qreal tempRotation = 0;
139 if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
149 tempAngle = line.angle();
150 tempLength = line.length();
178 if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
180 rotationLine.setAngle(
CorrectAngle(rotationLine.angle()));
183 qreal cursorLength = rotationLine.length();
188 if (cursorLength > minL)
190 tempRotation = rotationLine.angle();
194 rotationLine.setAngle(0);
209 static const QString prefix =
UnitsToStr(
qApp->patternUnit(),
true);
213 "<b>Mouse click</b> - finish selecting a position")
214 .arg(
qApp->TrVars()->FormulaToUser(QString::number(
qApp->fromPixel(tempLength)),
215 qApp->Settings()->GetOsSeparator()))
221 Visualization::toolTip = tr(
"Length = %1%2, angle = %3°, rotation angle = %4° Hold <b>SHIFT</b> to constrain angle,"
222 "<b>CTRL</b> - change rotation origin point, <b>Mouse click</b> - finish creating")
223 .arg(
qApp->TrVars()->FormulaToUser(QString::number(
qApp->fromPixel(tempLength)),
224 qApp->Settings()->GetOsSeparator()))
282 template <
class Item>
296 template <
class Item>
298 const QPointF &rotationOrigin)
313 QT_WARNING_DISABLE_GCC(
"-Wswitch-default")
317 QPolygonF sourceObjects;
319 for (
int i = 0; i < objects.size(); ++i)
321 const quint32
id = objects.at(i);
325 Q_STATIC_ASSERT_X(
static_cast<int>(
GOType::Unknown) == 7,
"Not all objects were handled.");
327 switch(
static_cast<GOType>(obj->getType()))
334 VScaledEllipse *point = GetPoint(
static_cast<quint32
>(iPoint), supportColor2);
335 DrawPoint(point,
static_cast<QPointF
>(*p), supportColor2);
336 sourceObjects.append(p->toQPointF());
340 AddOriginCurve<VArc>(
id, iCurve);
341 sourceObjects.append(
Visualization::data->GeometricObject<VAbstractCurve>(
id)->getPoints());
344 AddOriginCurve<VEllipticalArc>(
id, iCurve);
345 sourceObjects.append(
Visualization::data->GeometricObject<VAbstractCurve>(
id)->getPoints());
348 AddOriginCurve<VSpline>(
id, iCurve);
349 sourceObjects.append(
Visualization::data->GeometricObject<VAbstractCurve>(
id)->getPoints());
352 AddOriginCurve<VSplinePath>(
id, iCurve);
353 sourceObjects.append(
Visualization::data->GeometricObject<VAbstractCurve>(
id)->getPoints());
356 AddOriginCurve<VCubicBezier>(
id, iCurve);
357 sourceObjects.append(
Visualization::data->GeometricObject<VAbstractCurve>(
id)->getPoints());
360 AddOriginCurve<VCubicBezierPath>(
id, iCurve);
361 sourceObjects.append(
Visualization::data->GeometricObject<VAbstractCurve>(
id)->getPoints());
372 m_origin = sourceObjects.boundingRect().center();
379 QT_WARNING_DISABLE_GCC(
"-Wswitch-default")
381 void
VisToolMove::createRotatedObjects(
int &iPoint,
int &iCurve, qreal length, qreal angle, qreal rotationAngle,
382 const QPointF &rotationOrigin)
384 for (
int i = 0; i < objects.size(); ++i)
386 const quint32
id = objects.at(i);
390 Q_STATIC_ASSERT_X(
static_cast<int>(
GOType::Unknown) == 7,
"Not all objects was handled.");
392 switch(
static_cast<GOType>(obj->getType()))
399 VScaledEllipse *point = GetPoint(
static_cast<quint32
>(iPoint), supportColor);
400 DrawPoint(point,
static_cast<QPointF
>(p->Move(length, angle).Rotate(rotationOrigin, rotationAngle)),
405 iCurve = AddDestinationCurve<VArc>(angle, length,
id, iCurve, rotationAngle, rotationOrigin);
408 iCurve = AddDestinationCurve<VEllipticalArc>(angle, length,
id, iCurve, rotationAngle, rotationOrigin);
411 iCurve = AddDestinationCurve<VSpline>(angle, length,
id, iCurve, rotationAngle, rotationOrigin);
414 iCurve = AddDestinationCurve<VSplinePath>(angle, length,
id, iCurve, rotationAngle, rotationOrigin);
417 iCurve = AddDestinationCurve<VCubicBezier>(angle, length,
id, iCurve, rotationAngle, rotationOrigin);
420 iCurve = AddDestinationCurve<VCubicBezierPath>(angle, length,
id, iCurve, rotationAngle, rotationOrigin);
The VContainer class container of all variables.
const QSharedPointer< VGObject > GetGObject(quint32 id) const
GetGObject returns a point by id.
const QSharedPointer< T > GeometricObject(const quint32 &id) const
static QLineF BuildLine(const QPointF &p1, const qreal &length, const qreal &angle)
The VPointF class keep data of point.
static qreal CorrectAngle(const qreal &angle)
QPointF Ray(const QPointF &firstPoint, const qreal &angle) const
VCurvePathItem * GetCurve(quint32 i, const QColor &color)
QVector< quint32 > objects
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style=Qt::SolidLine)
static qreal FindLength(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style=Qt::SolidLine, const qreal &weight=0.35, Qt::PenCapStyle cap=Qt::SquareCap)
void drawArrowedLine(ArrowedLineItem *item, const QLineF &line, const QColor &color, Qt::PenStyle style=Qt::SolidLine)
virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color, const qreal &lineWeight, Qt::PenStyle style=Qt::SolidLine)
static qreal FindVal(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)
qreal sceneScale(QGraphicsScene *scene)
qreal scaledRadius(qreal scale)