54 #include <QDomElement>
57 #include <QGraphicsScene>
58 #include <QGraphicsSceneHoverEvent>
59 #include <QGraphicsSceneMouseEvent>
60 #include <QGraphicsView>
65 #include <QSharedPointer>
66 #include <QStaticStringData>
67 #include <QStringData>
68 #include <QStringDataPtr>
73 #include "../../../dialogs/tools/dialogtool.h"
74 #include "../../../dialogs/tools/dialogsplinepath.h"
75 #include "../../../undocommands/movesplinepath.h"
76 #include "../../../undocommands/vundocommand.h"
77 #include "../../../visualization/visualization.h"
78 #include "../../../visualization/path/vistoolsplinepath.h"
79 #include "../ifc/exception/vexception.h"
80 #include "../ifc/xml/vdomdocument.h"
81 #include "../ifc/ifcdef.h"
82 #include "../qmuparser/qmutokenparser.h"
83 #include "../vgeometry/vabstractcubicbezierpath.h"
84 #include "../vgeometry/vabstractcurve.h"
85 #include "../vgeometry/vgobject.h"
86 #include "../vgeometry/vpointf.h"
87 #include "../vgeometry/vspline.h"
88 #include "../vgeometry/vsplinepoint.h"
89 #include "../vmisc/vabstractapplication.h"
90 #include "../vmisc/vmath.h"
91 #include "../vpatterndb/vcontainer.h"
92 #include "../vwidgets/../vgeometry/vsplinepath.h"
93 #include "../vwidgets/vcontrolpointspline.h"
94 #include "../vwidgets/vmaingraphicsscene.h"
95 #include "../../vabstracttool.h"
96 #include "../vdrawtool.h"
112 QGraphicsItem *parent)
119 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
120 this->setFlag(QGraphicsItem::ItemIsFocusable,
true);
123 for (qint32 i = 1; i<=
splPath->CountSubSpl(); ++i)
131 static_cast<QPointF
>(spl.
GetP2()),
132 static_cast<QPointF
>(spl.
GetP1()),
133 freeAngle1, freeLength1,
this);
144 static_cast<QPointF
>(spl.
GetP4()), freeAngle2, freeLength2,
this);
168 dialogTool->setLineColor(
splPath->getLineColor());
169 dialogTool->setLineWeight(
splPath->getLineWeight());
170 dialogTool->setPenStyle(
splPath->GetPenStyle());
188 for (qint32 i = 0; i < path->CountPoints(); ++i)
193 path->setLineColor(dialogTool->getLineColor());
194 path->SetPenStyle(dialogTool->getPenStyle());
195 path->setLineWeight(dialogTool->getLineWeight());
218 const Source &typeCreation)
252 const QString &color,
const QString &penStyle,
const QString &lineWeight,
260 path->SetDuplicate(duplicate);
263 for (
int i = 0; i < points.size(); ++i)
273 path->append(
VSplinePoint(p, calcAngle1, a1.at(i), calcAngle2, a2.at(i), calcLength1, l1.at(i), calcLength2,
277 path->setLineColor(color);
278 path->SetPenStyle(penStyle);
279 path->setLineWeight(lineWeight);
301 qApp->getUndoStack()->push(moveSplPath);
307 this->setFlag(QGraphicsItem::ItemIsMovable, move);
390 ShowToolVisualization<VisToolSplinePath>(show);
404 ContextMenu<DialogSplinePath>(event);
445 domElement.appendChild(pathPoint);
455 for (qint32 i = 0; i <
splPath->CountSubSpl(); ++i)
472 for (qint32 i = 1; i <=
splPath.CountSubSpl(); ++i)
507 if (flags() & QGraphicsItem::ItemIsMovable)
509 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
527 if (flags() & QGraphicsItem::ItemIsMovable)
529 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
569 weight = (pow((6 * t - 1) / 2.0, 3)) / 2;
571 else if (t <= 5.0 / 6.0)
573 weight = (1 - pow((6 * (1-t) - 1) / 2.0, 3)) / 2 + 0.5;
580 const QPointF delta =
event->scenePos() -
oldPosition;
581 const QPointF offset0 = ((1-weight)/(3*t*(1-t)*(1-t))) * delta;
582 const QPointF offset1 = (weight/(3*t*t*(1-t))) * delta;
584 const QPointF p2 =
static_cast<QPointF
>(spline.
GetP2()) + offset0;
585 const QPointF p3 =
static_cast<QPointF
>(spline.
GetP3()) + offset1;
595 qApp->getUndoStack()->push(moveSplPath);
599 static bool changeFinished =
true;
602 changeFinished =
false;
605 if (not viewList.isEmpty())
607 if (QGraphicsView *view = viewList.at(0))
611 const QPointF cursorPosition = currentScene->
getScenePos();
612 view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
615 changeFinished =
true;
623 if (flags() & QGraphicsItem::ItemIsMovable)
640 if (flags() & QGraphicsItem::ItemIsMovable)
643 setCursor(QCursor());
652 if (not
vis.isNull())
672 if (index == -1 || index < 1 || index >
splPath->CountSubSpl())
689 point->setFlag(QGraphicsItem::ItemSendsGeometryChanges,
false);
694 for (qint32 i = 1; i<=
splPath->CountSubSpl(); ++i)
696 const qint32 j = i*2;
701 const auto spl =
splPath->GetSpline(i);
707 const auto splinePoint = spl.GetP1();
709 static_cast<QPointF
>(splinePoint), freeAngle1, freeLength1);
716 const auto splinePoint = spl.GetP4();
718 static_cast<QPointF
>(splinePoint), freeAngle2, freeLength2);
727 point->setFlag(QGraphicsItem::ItemSendsGeometryChanges,
true);
The DialogSplinePath class dialog for ToolSplinePath. Help create spline path and edit option.
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.
static void InitSplinePathToolConnections(VMainGraphicsScene *scene, T *tool)
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.
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 AddCurveWithSegments(const QSharedPointer< VAbstractCubicBezierPath > &curve, const 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 ".".
static void RemoveAllChildren(QDomElement &domElement)
RemoveAllChildren remove all children from file.
quint32 id() const
id return id object.
The VMainGraphicsScene class main scene.
QPointF getScenePos() const
The VPointF class keep data of point.
The VSplinePath class keep information about splinePath.
const VSplinePoint & at(int indx) const
at return spline point by index.
virtual qint32 CountPoints() const Q_DECL_OVERRIDE
CountPoints return count of points.
The VSplinePoint class keep information about point in spline path. Each point have two angles and tw...
QString Length1Formula() const
void SetAngle1(const qreal &value, const QString &angle1F)
QString Angle2Formula() const
void SetLength1(const qreal &value, const QString &length1F)
QString Length2Formula() const
QString Angle1Formula() const
void SetLength2(const qreal &value, const QString &length2F)
void SetAngle2(const qreal &value, const QString &angle2F)
VSpline class that implements the spline.
virtual qreal GetC2Length() const Q_DECL_OVERRIDE
virtual VPointF GetP4() const Q_DECL_OVERRIDE
GetP4 return last spline point.
QString GetC1LengthFormula() const
virtual qreal GetStartAngle() const Q_DECL_OVERRIDE
GetAngle1 return first angle control line.
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 qreal GetC1Length() const Q_DECL_OVERRIDE
virtual VPointF GetP3() const Q_DECL_OVERRIDE
GetP3 return second control point.
QString GetC2LengthFormula() const
virtual qreal GetEndAngle() const Q_DECL_OVERRIDE
GetAngle2 return second angle control line.
void NeedLiteParsing(const Document &parse)
void setLineWeight(const QString &value)
void SetMode(const Mode &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 AttrPSpline
const QString AttrPenStyle
const QString AttrLength2
const QString AttrLength1
const QString AttrPathPoint
Qt::PenStyle lineTypeToPenStyle(const QString &lineType)
LineStyle return pen style for current line style.