54 #include <QDomElement>
57 #include <QGraphicsScene>
58 #include <QGraphicsSceneMouseEvent>
59 #include <QGraphicsView>
64 #include <QSharedPointer>
65 #include <QStaticStringData>
66 #include <QStringData>
67 #include <QStringDataPtr>
73 #include "../../../dialogs/tools/dialogspline.h"
74 #include "../../../dialogs/tools/dialogtool.h"
75 #include "../../../undocommands/movespline.h"
76 #include "../../../visualization/visualization.h"
77 #include "../../../visualization/path/vistoolspline.h"
78 #include "../ifc/exception/vexception.h"
79 #include "../ifc/ifcdef.h"
80 #include "../qmuparser/qmutokenparser.h"
81 #include "../vgeometry/vabstractcurve.h"
82 #include "../vgeometry/vgobject.h"
83 #include "../vgeometry/vpointf.h"
84 #include "../vgeometry/vspline.h"
85 #include "../vmisc/vabstractapplication.h"
86 #include "../vmisc/vmath.h"
87 #include "../vpatterndb/vcontainer.h"
88 #include "../vwidgets/vcontrolpointspline.h"
89 #include "../vwidgets/vmaingraphicsscene.h"
90 #include "../../vabstracttool.h"
91 #include "../vdrawtool.h"
107 QGraphicsItem *parent)
112 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
113 this->setFlag(QGraphicsItem::ItemIsFocusable,
true);
121 static_cast<QPointF
>(spl->GetP2()),
122 static_cast<QPointF
>(spl->GetP1()),
123 freeAngle1, freeLength1,
this);
134 static_cast<QPointF
>(spl->GetP3()),
135 static_cast<QPointF
>(spl->GetP4()),
136 freeAngle2, freeLength2,
this);
158 dialogTool->SetSpline(*spl);
161 dialogTool->setPenStyle(spl->GetPenStyle());
181 spline->setLineColor(dialogTool->getLineColor());
182 spline->SetPenStyle(dialogTool->getPenStyle());
183 spline->setLineWeight(dialogTool->getLineWeight());
189 spl->m_dialog = dialogTool;
230 scene->addItem(_spl);
242 QString &l1, QString &l2, quint32 duplicate,
const QString &color,
245 const Source &typeCreation)
256 auto spline =
new VSpline(*p1, *p4, calcAngle1, a1, calcAngle2, a2, calcLength1, l1, calcLength2, l2);
259 spline->SetDuplicate(duplicate);
262 spline->setLineColor(color);
263 spline->SetPenStyle(penStyle);
264 spline->setLineWeight(lineWeight);
273 return *spline.data();
281 *spline.data() = spl;
288 ShowToolVisualization<VisToolSpline>(show);
301 Q_UNUSED(indexSpline)
307 qApp->getUndoStack()->push(moveSpl);
313 this->setFlag(QGraphicsItem::ItemIsMovable, move);
327 ContextMenu<DialogSpline>(event);
354 auto dialogTool = qobject_cast<DialogSpline*>(
m_dialog);
357 const VSpline spl = dialogTool->GetSpline();
379 auto spl = qSharedPointerDynamicCast<VSpline>(obj);
387 if (flags() & QGraphicsItem::ItemIsMovable)
389 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
405 if (flags() & QGraphicsItem::ItemIsMovable)
407 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
446 weight = (pow((6 * t - 1) / 2.0, 3)) / 2;
448 else if (t <= 5.0 / 6.0)
450 weight = (1 - pow((6 * (1-t) - 1) / 2.0, 3)) / 2 + 0.5;
457 const QPointF delta =
event->scenePos() -
oldPosition;
458 const QPointF offset0 = ((1-weight)/(3*t*(1-t)*(1-t))) * delta;
459 const QPointF offset1 = (weight/(3*t*t*(1-t))) * delta;
461 const QPointF p2 =
static_cast<QPointF
>(spline->GetP2()) + offset0;
462 const QPointF p3 =
static_cast<QPointF
>(spline->GetP3()) + offset1;
470 qApp->getUndoStack()->push(moveSpl);
474 static bool changeFinished =
true;
477 changeFinished =
false;
480 if (not viewList.isEmpty())
482 if (QGraphicsView *view = viewList.at(0))
486 const QPointF cursorPosition = currentScene->
getScenePos();
487 view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
490 changeFinished =
true;
498 if (flags() & QGraphicsItem::ItemIsMovable)
512 if (flags() & QGraphicsItem::ItemIsMovable)
516 setCursor(QCursor());
526 if (not
vis.isNull())
562 point->setFlag(QGraphicsItem::ItemSendsGeometryChanges,
false);
574 const QPointF splinePoint =
577 static_cast<QPointF
>(splinePoint), freeAngle1, freeLength1);
584 const QPointF splinePoint =
587 static_cast<QPointF
>(splinePoint), freeAngle2, freeLength2);
595 point->setFlag(QGraphicsItem::ItemSendsGeometryChanges,
true);
The DialogSpline class dialog for ToolSpline. Help create spline and edit option.
QString getLineWeight() const
getLineWeight return weight of the lines
QString getLineColor() const
quint32 GetDuplicate() const
virtual void LiteParseTree(const Document &parse)=0
virtual void UpdateToolData(const quint32 &id, VContainer *data)=0
virtual void IncrementReferens(quint32 id) const =0
static void AddTool(quint32 id, VDataTool *tool)
AddTool add tool to list tools.
virtual void DecrementReferens(quint32 id) const =0
virtual void SaveOptions(QDomElement &tag, QSharedPointer< VGObject > &obj) Q_DECL_OVERRIDE
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
mouseReleaseEvent handle mouse release events.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE
void setEnabledPoint(bool enable)
setEnabledPoint disable control points.
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
hoverEnterEvent handle hover enter events.
static void InitSplineToolConnections(VMainGraphicsScene *scene, T *tool)
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
hoverLeaveEvent handle hover leave events.
QVector< VControlPointSpline * > controlPoints
controlPoints list pointers of control points.
void ShowHandles(bool show)
VSpline CorrectedSpline(const VSpline &spline, const SplinePointPosition &position, const QPointF &pos) const
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
void AddSpline(const QSharedPointer< VAbstractBezier > &curve, quint32 id, quint32 parentId=null_id)
quint32 AddGObject(VGObject *obj)
AddGObject add new GObject to container.
void UpdateGObject(quint32 id, T *obj)
UpdateGObject update GObject by id.
The VControlPointSpline class control spline point.
void showContextMenu(QGraphicsSceneContextMenuEvent *event)
showContextMenu emit when need show tool's context menu.
void ControlPointChangePosition(const qint32 &indexSpline, SplinePointPosition position, const QPointF &pos)
ControlPointChangePosition emit when control point change position.
void setEnabledPoint(bool enable)
setEnabledPoint disable or enable control point.
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
quint32 id() const
id return id object.
quint32 getIdTool() const
The VMainGraphicsScene class main scene.
QPointF getScenePos() const
The VPointF class keep data of point.
VSpline class that implements the spline.
virtual VPointF GetP4() const Q_DECL_OVERRIDE
GetP4 return last spline point.
QString GetC1LengthFormula() const
qreal ParamT(const QPointF &pBt) const
VSpline::ParamT calculate t coeffient that reprezent point on curve.
virtual VPointF GetP1() const Q_DECL_OVERRIDE
GetP1 return first spline point.
virtual VPointF GetP2() const Q_DECL_OVERRIDE
GetP2 return first control point.
QString GetStartAngleFormula() const
QString GetEndAngleFormula() const
virtual VPointF GetP3() const Q_DECL_OVERRIDE
GetP3 return second control point.
QString GetC2LengthFormula() const
void NeedLiteParsing(const Document &parse)
void SetMode(const Mode &value)
void setObject1Id(const quint32 &value)
void setLineStyle(const Qt::PenStyle &value)
static bool IsSingle(const QString &formula)
IsSingle test formula and return true if it contain only one number.
const QString cursorArrowOpenHand
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
const QString cursorArrowCloseHand
const QString AttrDuplicate
const QString AttrLineWeight
const QString AttrPenStyle
const QString AttrLength2
const QString AttrLength1
Qt::PenStyle lineTypeToPenStyle(const QString &lineType)
LineStyle return pen style for current line style.