Seamly2D
Code documentation
vtoolspline.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vtoolspline.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "vtoolspline.h"
53 
54 #include <QDomElement>
55 #include <QEvent>
56 #include <QFlags>
57 #include <QGraphicsScene>
58 #include <QGraphicsSceneMouseEvent>
59 #include <QGraphicsView>
60 #include <QList>
61 #include <QPen>
62 #include <QPoint>
63 #include <QRectF>
64 #include <QSharedPointer>
65 #include <QStaticStringData>
66 #include <QStringData>
67 #include <QStringDataPtr>
68 #include <QUndoStack>
69 #include <QVector>
70 #include <Qt>
71 #include <new>
72 
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"
92 #include "vabstractspline.h"
93 
94 const QString VToolSpline::ToolType = QStringLiteral("simpleInteractive");
95 const QString VToolSpline::OldToolType = QStringLiteral("simple");
96 
97 //---------------------------------------------------------------------------------------------------------------------
98 /**
99  * @brief VToolSpline constructor.
100  * @param doc dom document container.
101  * @param data container with variables.
102  * @param id object id in container.
103  * @param typeCreation way we create this tool.
104  * @param parent parent object.
105  */
106 VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
107  QGraphicsItem *parent)
108  :VAbstractSpline(doc, data, id, parent), oldPosition()
109 {
111 
112  this->setFlag(QGraphicsItem::ItemIsMovable, true);
113  this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
114 
115  const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
116 
117  const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl->GetStartAngleFormula());
118  const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula());
119 
120  auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint,
121  static_cast<QPointF>(spl->GetP2()),
122  static_cast<QPointF>(spl->GetP1()),
123  freeAngle1, freeLength1, this);
124  connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
128  controlPoints.append(controlPoint1);
129 
130  const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl->GetEndAngleFormula());
131  const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl->GetC2LengthFormula());
132 
133  auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint,
134  static_cast<QPointF>(spl->GetP3()),
135  static_cast<QPointF>(spl->GetP4()),
136  freeAngle2, freeLength2, this);
137  connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
141  controlPoints.append(controlPoint2);
142 
144 
145  ToolCreation(typeCreation);
146 }
147 
148 //---------------------------------------------------------------------------------------------------------------------
149 /**
150  * @brief setDialog set dialog when user want change tool option.
151  */
153 {
154  SCASSERT(not m_dialog.isNull())
155  QSharedPointer<DialogSpline> dialogTool = m_dialog.objectCast<DialogSpline>();
156  SCASSERT(not dialogTool.isNull())
157  const auto spl = VAbstractTool::data.GeometricObject<VSpline>(m_id);
158  dialogTool->SetSpline(*spl);
159  dialogTool->setLineColor(spl->getLineColor());
160  dialogTool->setLineWeight(spl->getLineWeight());
161  dialogTool->setPenStyle(spl->GetPenStyle());
162 }
163 
164 //---------------------------------------------------------------------------------------------------------------------
165 /**
166  * @brief Create help create tool from GUI.
167  * @param dialog dialog.
168  * @param scene pointer to scene.
169  * @param doc dom document container.
170  * @param data container with variables.
171  * @return the created tool
172  */
174  VContainer *data)
175 {
176  SCASSERT(not dialog.isNull())
177  QSharedPointer<DialogSpline> dialogTool = dialog.objectCast<DialogSpline>();
178  SCASSERT(not dialogTool.isNull())
179 
180  VSpline *spline = new VSpline(dialogTool->GetSpline());
181  spline->setLineColor(dialogTool->getLineColor());
182  spline->SetPenStyle(dialogTool->getPenStyle());
183  spline->setLineWeight(dialogTool->getLineWeight());
184 
185  auto spl = Create(0, spline, scene, doc, data, Document::FullParse, Source::FromGui);
186 
187  if (spl != nullptr)
188  {
189  spl->m_dialog = dialogTool;
190  }
191  return spl;
192 }
193 
194 //---------------------------------------------------------------------------------------------------------------------
195 /**
196  * @brief Create help create tool.
197  * @param _id tool id, 0 if tool doesn't exist yet.
198  * @param spline spline.
199  * @param scene pointer to scene.
200  * @param doc dom document container.
201  * @param data container with variables.
202  * @param parse parser file mode.
203  * @param typeCreation way we create this tool.
204  * @return the created tool
205  */
207  VContainer *data, const Document &parse, const Source &typeCreation)
208 {
209  quint32 id = _id;
210 
211  if (typeCreation == Source::FromGui)
212  {
213  id = data->AddGObject(spline);
215  }
216  else
217  {
218  data->UpdateGObject(id, spline);
220  if (parse != Document::FullParse)
221  {
222  doc->UpdateToolData(id, data);
223  }
224  }
225 
226  if (parse == Document::FullParse)
227  {
229  auto _spl = new VToolSpline(doc, data, id, typeCreation);
230  scene->addItem(_spl);
231  InitSplineToolConnections(scene, _spl);
232  VAbstractPattern::AddTool(id, _spl);
233  doc->IncrementReferens(spline->GetP1().getIdTool());
234  doc->IncrementReferens(spline->GetP4().getIdTool());
235  return _spl;
236  }
237  return nullptr;
238 }
239 
240 //---------------------------------------------------------------------------------------------------------------------
241 VToolSpline *VToolSpline::Create(const quint32 _id, quint32 point1, quint32 point4, QString &a1, QString &a2,
242  QString &l1, QString &l2, quint32 duplicate, const QString &color,
243  const QString &penStyle, const QString &lineWeight, VMainGraphicsScene *scene,
244  VAbstractPattern *doc, VContainer *data, const Document &parse,
245  const Source &typeCreation)
246 {
247  const qreal calcAngle1 = CheckFormula(_id, a1, data);
248  const qreal calcAngle2 = CheckFormula(_id, a2, data);
249 
250  const qreal calcLength1 = qApp->toPixel(CheckFormula(_id, l1, data));
251  const qreal calcLength2 = qApp->toPixel(CheckFormula(_id, l2, data));
252 
253  auto p1 = data->GeometricObject<VPointF>(point1);
254  auto p4 = data->GeometricObject<VPointF>(point4);
255 
256  auto spline = new VSpline(*p1, *p4, calcAngle1, a1, calcAngle2, a2, calcLength1, l1, calcLength2, l2);
257  if (duplicate > 0)
258  {
259  spline->SetDuplicate(duplicate);
260  }
261 
262  spline->setLineColor(color);
263  spline->SetPenStyle(penStyle);
264  spline->setLineWeight(lineWeight);
265 
266  return VToolSpline::Create(_id, spline, scene, doc, data, parse, typeCreation);
267 }
268 
269 //---------------------------------------------------------------------------------------------------------------------
271 {
273  return *spline.data();
274 }
275 
276 //---------------------------------------------------------------------------------------------------------------------
278 {
280  QSharedPointer<VSpline> spline = qSharedPointerDynamicCast<VSpline>(obj);
281  *spline.data() = spl;
282  SaveOption(obj);
283 }
284 
285 //---------------------------------------------------------------------------------------------------------------------
287 {
288  ShowToolVisualization<VisToolSpline>(show);
289 }
290 
291 //---------------------------------------------------------------------------------------------------------------------
292 /**
293  * @brief ControlPointChangePosition handle change position control point.
294  * @param indexSpline position spline in spline list.
295  * @param position position point in spline.
296  * @param pos new position.
297  */
298 void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const SplinePointPosition &position,
299  const QPointF &pos)
300 {
301  Q_UNUSED(indexSpline)
303  const VSpline spl = CorrectedSpline(*spline, position, pos);
304 
305  MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, m_id);
307  qApp->getUndoStack()->push(moveSpl);
308 }
309 
310 //---------------------------------------------------------------------------------------------------------------------
312 {
313  this->setFlag(QGraphicsItem::ItemIsMovable, move);
314 }
315 
316 //---------------------------------------------------------------------------------------------------------------------
317 /**
318  * @brief contextMenuEvent handle context menu events.
319  * @param event context menu event.
320  */
321 void VToolSpline::showContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id)
322 {
323  Q_UNUSED(id)
324 
325  try
326  {
327  ContextMenu<DialogSpline>(event);
328  }
329  catch(const VExceptionToolWasDeleted &e)
330  {
331  Q_UNUSED(e)
332  return;//Leave this method immediately!!!
333  }
334 }
335 
336 //---------------------------------------------------------------------------------------------------------------------
337 /**
338  * @brief RemoveReferens decrement value of reference.
339  */
341 {
342  const auto spl = VAbstractTool::data.GeometricObject<VSpline>(m_id);
343  doc->DecrementReferens(spl->GetP1().getIdTool());
344  doc->DecrementReferens(spl->GetP4().getIdTool());
345 }
346 
347 //---------------------------------------------------------------------------------------------------------------------
348 /**
349  * @brief SaveDialog save options into file after change in dialog.
350  */
351 void VToolSpline::SaveDialog(QDomElement &domElement)
352 {
353  SCASSERT(not m_dialog.isNull())
354  auto dialogTool = qobject_cast<DialogSpline*>(m_dialog);
355  SCASSERT(dialogTool != nullptr)
356 
357  const VSpline spl = dialogTool->GetSpline();
358 
359  controlPoints[0]->blockSignals(true);
360  controlPoints[1]->blockSignals(true);
361 
362  controlPoints[0]->setPos(static_cast<QPointF>(spl.GetP2()));
363  controlPoints[1]->setPos(static_cast<QPointF>(spl.GetP3()));
364 
365  controlPoints[0]->blockSignals(false);
366  controlPoints[1]->blockSignals(false);
367 
368  SetSplineAttributes(domElement, spl);
369  doc->SetAttribute(domElement, AttrColor, dialogTool->getLineColor());
370  doc->SetAttribute(domElement, AttrPenStyle, dialogTool->getPenStyle());
371  doc->SetAttribute(domElement, AttrLineWeight, dialogTool->getLineWeight());
372 }
373 
374 //---------------------------------------------------------------------------------------------------------------------
376 {
378 
379  auto spl = qSharedPointerDynamicCast<VSpline>(obj);
380  SCASSERT(spl.isNull() == false)
381  SetSplineAttributes(tag, *spl);
382 }
383 
384 //---------------------------------------------------------------------------------------------------------------------
385 void VToolSpline::mousePressEvent(QGraphicsSceneMouseEvent *event)
386 {
387  if (flags() & QGraphicsItem::ItemIsMovable)
388  {
389  if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
390  {
391  if (IsMovable())
392  {
394  oldPosition = event->scenePos();
395  event->accept();
396  }
397  }
398  }
400 }
401 
402 //---------------------------------------------------------------------------------------------------------------------
403 void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
404 {
405  if (flags() & QGraphicsItem::ItemIsMovable)
406  {
407  if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
408  {
409  if (IsMovable())
410  {
412  }
413  }
414  }
416 }
417 
418 //---------------------------------------------------------------------------------------------------------------------
419 void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
420 {
421  if (IsMovable())
422  {
423  // Don't need check if left mouse button was pressed. According to the Qt documentation "If you do receive this
424  // event, you can be certain that this item also received a mouse press event, and that this item is the current
425  // mouse grabber.".
426 
427  // Magic Bezier Drag Equations follow!
428  // "weight" describes how the influence of the drag should be distributed
429  // among the handles; 0 = front handle only, 1 = back handle only.
430 
431  const auto spline = VAbstractTool::data.GeometricObject<VSpline>(m_id);
432  const qreal t = spline->ParamT(oldPosition);
433 
434  if (qFloor(t) == -1)
435  {
436  return;
437  }
438 
439  double weight;
440  if (t <= 1.0 / 6.0)
441  {
442  weight = 0;
443  }
444  else if (t <= 0.5)
445  {
446  weight = (pow((6 * t - 1) / 2.0, 3)) / 2;
447  }
448  else if (t <= 5.0 / 6.0)
449  {
450  weight = (1 - pow((6 * (1-t) - 1) / 2.0, 3)) / 2 + 0.5;
451  }
452  else
453  {
454  weight = 1;
455  }
456 
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;
460 
461  const QPointF p2 = static_cast<QPointF>(spline->GetP2()) + offset0;
462  const QPointF p3 = static_cast<QPointF>(spline->GetP3()) + offset1;
463 
464  oldPosition = event->scenePos(); // Now mouse here
465 
466  VSpline spl = VSpline(spline->GetP1(), p2, p3, spline->GetP4());
467 
468  MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, m_id);
470  qApp->getUndoStack()->push(moveSpl);
471 
472  // Each time we move something we call recalculation scene rect. In some cases this can cause moving
473  // objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move.
474  static bool changeFinished = true;
475  if (changeFinished)
476  {
477  changeFinished = false;
478 
479  const QList<QGraphicsView *> viewList = scene()->views();
480  if (not viewList.isEmpty())
481  {
482  if (QGraphicsView *view = viewList.at(0))
483  {
484  VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
485  SCASSERT(currentScene)
486  const QPointF cursorPosition = currentScene->getScenePos();
487  view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
488  }
489  }
490  changeFinished = true;
491  }
492  }
493 }
494 
495 //---------------------------------------------------------------------------------------------------------------------
496 void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
497 {
498  if (flags() & QGraphicsItem::ItemIsMovable)
499  {
500  if (IsMovable())
501  {
503  }
504  }
505 
507 }
508 
509 //---------------------------------------------------------------------------------------------------------------------
510 void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
511 {
512  if (flags() & QGraphicsItem::ItemIsMovable)
513  {
514  if (IsMovable())
515  {
516  setCursor(QCursor());
517  }
518  }
519 
521 }
522 
523 //---------------------------------------------------------------------------------------------------------------------
525 {
526  if (not vis.isNull())
527  {
528  VisToolSpline *visual = qobject_cast<VisToolSpline *>(vis);
529  SCASSERT(visual != nullptr)
530 
532  visual->setObject1Id(spl->GetP1().id());
533  visual->setObject4Id(spl->GetP4().id());
534  visual->SetAngle1(spl->GetStartAngle());
535  visual->SetAngle2(spl->GetEndAngle());
536  visual->SetKAsm1(spl->GetKasm1());
537  visual->SetKAsm2(spl->GetKasm2());
538  visual->SetKCurve(spl->GetKcurve());
539  visual->setLineStyle(lineTypeToPenStyle(spl->GetPenStyle()));
540  visual->SetMode(Mode::Show);
541  visual->RefreshGeometry();
542  }
543 }
544 
545 //---------------------------------------------------------------------------------------------------------------------
547 {
548  const auto spline = VAbstractTool::data.GeometricObject<VSpline>(m_id);
549 
550  return qmu::QmuTokenParser::IsSingle(spline->GetStartAngleFormula()) &&
551  qmu::QmuTokenParser::IsSingle(spline->GetEndAngleFormula()) &&
552  qmu::QmuTokenParser::IsSingle(spline->GetC1LengthFormula()) &&
553  qmu::QmuTokenParser::IsSingle(spline->GetC2LengthFormula());
554 }
555 
556 //---------------------------------------------------------------------------------------------------------------------
558 {
559  // Very important to disable control points. Without it the pogram can't move the curve.
560  foreach (auto *point, controlPoints)
561  {
562  point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
563  }
564 
565  const auto spl = VAbstractTool::data.GeometricObject<VSpline>(m_id);
566 
567  controlPoints[0]->blockSignals(true);
568  controlPoints[1]->blockSignals(true);
569 
570  {
571  const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl->GetStartAngleFormula());
572  const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula());
573 
574  const QPointF splinePoint =
575  static_cast<QPointF>(*VAbstractTool::data.GeometricObject<VPointF>(spl->GetP1().id()));
576  controlPoints[0]->refreshCtrlPoint(1, SplinePointPosition::FirstPoint, static_cast<QPointF>(spl->GetP2()),
577  static_cast<QPointF>(splinePoint), freeAngle1, freeLength1);
578  }
579 
580  {
581  const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl->GetEndAngleFormula());
582  const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl->GetC2LengthFormula());
583 
584  const QPointF splinePoint =
585  static_cast<QPointF>(*VAbstractTool::data.GeometricObject<VPointF>(spl->GetP4().id()));
586  controlPoints[1]->refreshCtrlPoint(1, SplinePointPosition::LastPoint, static_cast<QPointF>(spl->GetP3()),
587  static_cast<QPointF>(splinePoint), freeAngle2, freeLength2);
588  }
589 
590  controlPoints[0]->blockSignals(false);
591  controlPoints[1]->blockSignals(false);
592 
593  foreach (auto *point, controlPoints)
594  {
595  point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
596  }
597 }
598 
599 //---------------------------------------------------------------------------------------------------------------------
600 void VToolSpline::SetSplineAttributes(QDomElement &domElement, const VSpline &spl)
601 {
602  SCASSERT(doc != nullptr)
603 
604  doc->SetAttribute(domElement, AttrType, ToolType);
605  doc->SetAttribute(domElement, AttrPoint1, spl.GetP1().id());
606  doc->SetAttribute(domElement, AttrPoint4, spl.GetP4().id());
607  doc->SetAttribute(domElement, AttrAngle1, spl.GetStartAngleFormula());
608  doc->SetAttribute(domElement, AttrAngle2, spl.GetEndAngleFormula());
609  doc->SetAttribute(domElement, AttrLength1, spl.GetC1LengthFormula());
610  doc->SetAttribute(domElement, AttrLength2, spl.GetC2LengthFormula());
611 
612  if (spl.GetDuplicate() > 0)
613  {
614  doc->SetAttribute(domElement, AttrDuplicate, spl.GetDuplicate());
615  }
616  else
617  {
618  if (domElement.hasAttribute(AttrDuplicate))
619  {
620  domElement.removeAttribute(AttrDuplicate);
621  }
622  }
623 
624  if (domElement.hasAttribute(AttrKCurve))
625  {
626  domElement.removeAttribute(AttrKCurve);
627  }
628 
629  if (domElement.hasAttribute(AttrKAsm1))
630  {
631  domElement.removeAttribute(AttrKAsm1);
632  }
633 
634  if (domElement.hasAttribute(AttrKAsm2))
635  {
636  domElement.removeAttribute(AttrKAsm2);
637  }
638 }
The DialogSpline class dialog for ToolSpline. Help create spline and edit option.
Definition: dialogspline.h:77
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.
SceneObject sceneType
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
VAbstractPattern * doc
doc dom document container
QPointer< Visualization > vis
virtual void ToolCreation(const Source &typeCreation)
static void AddRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc)
AddRecord add record about tool in history.
static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data)
CheckFormula check formula.
const quint32 m_id
id object id.
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< VGObject > GetGObject(quint32 id) const
GetGObject returns a point by id.
Definition: vcontainer.cpp:150
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
void AddSpline(const QSharedPointer< VAbstractBezier > &curve, quint32 id, quint32 parentId=null_id)
Definition: vcontainer.cpp:440
quint32 AddGObject(VGObject *obj)
AddGObject add new GObject to container.
Definition: vcontainer.cpp:216
void UpdateGObject(quint32 id, T *obj)
UpdateGObject update GObject by id.
Definition: vcontainer.h:374
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.
VContainer data
data container with data
Definition: vdatatool.h:84
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
Definition: vdomdocument.h:185
void SaveOption(QSharedPointer< VGObject > &obj)
Definition: vdrawtool.cpp:142
quint32 id() const
id return id object.
Definition: vgobject.cpp:205
quint32 getIdTool() const
Definition: vgobject.cpp:221
QSharedPointer< DialogTool > m_dialog
m_dialog tool's dialog options.
The VMainGraphicsScene class main scene.
QPointF getScenePos() const
The VPointF class keep data of point.
Definition: vpointf.h:75
VSpline class that implements the spline.
Definition: vspline.h:75
virtual VPointF GetP4() const Q_DECL_OVERRIDE
GetP4 return last spline point.
Definition: vspline.cpp:321
QString GetC1LengthFormula() const
Definition: vspline.cpp:391
qreal ParamT(const QPointF &pBt) const
VSpline::ParamT calculate t coeffient that reprezent point on curve.
Definition: vspline.cpp:540
virtual VPointF GetP1() const Q_DECL_OVERRIDE
GetP1 return first spline point.
Definition: vspline.cpp:281
virtual VPointF GetP2() const Q_DECL_OVERRIDE
GetP2 return first control point.
Definition: vspline.cpp:297
QString GetStartAngleFormula() const
Definition: vspline.cpp:353
QString GetEndAngleFormula() const
Definition: vspline.cpp:359
virtual VPointF GetP3() const Q_DECL_OVERRIDE
GetP3 return second control point.
Definition: vspline.cpp:309
QString GetC2LengthFormula() const
Definition: vspline.cpp:397
The VToolSpline class tool for creation spline. I mean bezier curve.
Definition: vtoolspline.h:74
VSpline getSpline() const
static const QString OldToolType
Definition: vtoolspline.h:89
virtual void RemoveReferens() Q_DECL_OVERRIDE
RemoveReferens decrement value of reference.
virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE
virtual void SaveOptions(QDomElement &tag, QSharedPointer< VGObject > &obj) Q_DECL_OVERRIDE
QPointF oldPosition
Definition: vtoolspline.h:120
void setSpline(const VSpline &spl)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
static VToolSpline * Create(QSharedPointer< DialogTool > dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
Create help create tool from GUI.
bool IsMovable() const
void ControlPointChangePosition(const qint32 &indexSpline, const SplinePointPosition &position, const QPointF &pos)
ControlPointChangePosition handle change position control point.
virtual void refreshCtrlPoints() Q_DECL_OVERRIDE
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE
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.
VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem *parent=nullptr)
VToolSpline constructor.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
mouseReleaseEvent handle mouse release events.
void SetSplineAttributes(QDomElement &domElement, const VSpline &spl)
virtual void setDialog() Q_DECL_OVERRIDE
setDialog set dialog when user want change tool option.
virtual void showContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id=NULL_ID) Q_DECL_OVERRIDE
contextMenuEvent handle context menu events.
virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE
SaveDialog save options into file after change in dialog.
virtual void SetVisualization() Q_DECL_OVERRIDE
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
static const QString ToolType
Definition: vtoolspline.h:88
void NeedLiteParsing(const Document &parse)
void SetKCurve(const qreal &value)
void SetAngle2(const qreal &value)
void SetKAsm1(const qreal &value)
void setObject4Id(const quint32 &value)
void SetAngle1(const qreal &value)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void SetKAsm2(const qreal &value)
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
Definition: def.cpp:191
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
Definition: def.cpp:206
const QString cursorArrowCloseHand
Definition: def.cpp:192
#define SCASSERT(cond)
Definition: def.h:317
@ Spline
Source
Definition: def.h:106
const QString AttrKAsm2
Definition: ifcdef.cpp:120
const QString AttrDuplicate
Definition: ifcdef.cpp:122
const QString AttrLineWeight
Definition: ifcdef.cpp:91
const QString AttrPenStyle
Definition: ifcdef.cpp:132
const QString AttrLength2
Definition: ifcdef.cpp:107
const QString AttrPoint1
Definition: ifcdef.cpp:115
const QString AttrLength1
Definition: ifcdef.cpp:106
const QString AttrKCurve
Definition: ifcdef.cpp:121
const QString AttrType
Definition: ifcdef.cpp:73
const QString AttrAngle2
Definition: ifcdef.cpp:105
const QString AttrPoint4
Definition: ifcdef.cpp:118
const QString AttrColor
Definition: ifcdef.cpp:131
Qt::PenStyle lineTypeToPenStyle(const QString &lineType)
LineStyle return pen style for current line style.
Definition: ifcdef.cpp:183
const QString AttrAngle1
Definition: ifcdef.cpp:104
const QString AttrKAsm1
Definition: ifcdef.cpp:119
Document
#define qApp
Definition: vapplication.h:67
SplinePointPosition
Definition: vgeometrydef.h:58