Seamly2D
Code documentation
vtoolmove.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
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 1 10, 2016
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) 2016 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 "vtoolmove.h"
53 
54 #include <limits.h>
55 #include <qiterator.h>
56 #include <QColor>
57 #include <QDomNode>
58 #include <QDomNodeList>
59 #include <QMapIterator>
60 #include <QPoint>
61 #include <QSharedPointer>
62 #include <QStaticStringData>
63 #include <QStringData>
64 #include <QStringDataPtr>
65 #include <QUndoStack>
66 #include <new>
67 
68 #include "../../../dialogs/tools/dialogtool.h"
69 #include "../../../dialogs/tools/dialogmove.h"
70 #include "../../../visualization/line/operation/vistoolmove.h"
71 #include "../../../visualization/visualization.h"
72 #include "../vgeometry/vabstractcurve.h"
73 #include "../vgeometry/varc.h"
74 #include "../vgeometry/vellipticalarc.h"
75 #include "../vgeometry/vcubicbezier.h"
76 #include "../vgeometry/vcubicbezierpath.h"
77 #include "../vgeometry/vgobject.h"
78 #include "../vgeometry/vpointf.h"
79 #include "../vgeometry/vspline.h"
80 #include "../vgeometry/vsplinepath.h"
81 #include "../vpatterndb/vtranslatevars.h"
82 #include "../vmisc/vabstractapplication.h"
83 #include "../vmisc/vcommonsettings.h"
84 #include "../vmisc/diagnostic.h"
85 #include "../vmisc/logging.h"
86 #include "../vpatterndb/vcontainer.h"
87 #include "../vpatterndb/vformula.h"
88 #include "../ifc/ifcdef.h"
89 #include "../ifc/exception/vexception.h"
90 #include "../ifc/xml/vabstractpattern.h"
91 #include "../vwidgets/vabstractsimple.h"
92 #include "../vwidgets/vmaingraphicsscene.h"
93 #include "../../vabstracttool.h"
94 #include "../../vdatatool.h"
95 #include "../vdrawtool.h"
96 #include "../vmisc/logging.h"
97 
98 template <class T> class QSharedPointer;
99 
100 const QString VToolMove::ToolType = QStringLiteral("moving");
101 
102 namespace
103 {
104 QT_WARNING_PUSH
105 QT_WARNING_DISABLE_GCC("-Wswitch-default")
106 QPointF findRotationOrigin(const QVector<SourceItem> objects, const VContainer *data, qreal calcLength, qreal calcAngle)
107 {
108  QPolygonF originObjects;
109  qCDebug(vTool, "Find center of objects: ");
110  for (auto item : objects)
111  {
112  qCDebug(vTool, "Object: %d", item.id);
113  const QSharedPointer<VGObject> object = data->GetGObject(item.id);
114 
115  Q_STATIC_ASSERT_X(static_cast<int>(GOType::AllCurves) == 10, "Not all objects were handled.");
116 
117  switch(static_cast<GOType>(object->getType()))
118  {
119  case GOType::Point:
120  originObjects.append(data->GeometricObject<VPointF>(item.id)->toQPointF());
121  break;
122  case GOType::Arc:
124  case GOType::Spline:
125  case GOType::SplinePath:
126  case GOType::CubicBezier:
128  originObjects.append(data->GeometricObject<VAbstractCurve>(item.id)->getPoints());
129  break;
130  case GOType::Unknown:
131  case GOType::Curve:
132  case GOType::Path:
133  case GOType::AllCurves:
134  default:
135  Q_UNREACHABLE();
136  break;
137  }
138  }
139 
140  QPointF rotationOrigin = originObjects.boundingRect().center();
141  QLineF move(rotationOrigin, QPointF(rotationOrigin.x() + calcLength, rotationOrigin.y()));
142  move.setAngle(calcAngle);
143  return move.p2();}
145 }
146 
147 //---------------------------------------------------------------------------------------------------------------------
149  const QString &formulaAngle, const QString &formulaLength, const QString &formulaRotation,
150  const quint32 &originPointId, const QString &suffix, const QVector<SourceItem> &source,
151  const QVector<DestinationItem> &destination,
152  const Source &typeCreation, QGraphicsItem *parent)
153  : VAbstractOperation(doc, data, id, suffix, source, destination, parent)
154  , formulaAngle(formulaAngle)
155  , formulaLength(formulaLength)
156  , formulaRotation(formulaRotation)
157  , m_originPointId(originPointId)
158 {
160  ToolCreation(typeCreation);
161 }
162 
163 //---------------------------------------------------------------------------------------------------------------------
165 {
166  SCASSERT(!m_dialog.isNull())
167  QSharedPointer<DialogMove> dialogTool = m_dialog.objectCast<DialogMove>();
168  SCASSERT(!dialogTool.isNull())
169  dialogTool->SetAngle(formulaAngle);
170  dialogTool->SetLength(formulaLength);
171  dialogTool->setRotation(formulaRotation);
172  dialogTool->setSuffix(suffix);
173  dialogTool->setOriginPointId(m_originPointId);
174  dialogTool->setSourceObjects(source);
175 }
176 
177 //---------------------------------------------------------------------------------------------------------------------
179  VContainer *data)
180 {
181  SCASSERT(!dialog.isNull())
182 
183  QSharedPointer<DialogMove> dialogTool = dialog.objectCast<DialogMove>();
184  SCASSERT(!dialogTool.isNull())
185  QString angle = dialogTool->GetAngle();
186  QString length = dialogTool->GetLength();
187  QString rotation = dialogTool->getRotation();
188  quint32 originPointId = dialogTool->getOriginPointId();
189  const QString suffix = dialogTool->getSuffix();
190  const QVector<SourceItem> source = dialogTool->getSourceObjects();
191 
192  VToolMove* operation = Create(0, angle, length, rotation, originPointId, suffix, source,
194 
195  if (operation != nullptr)
196  {
197  operation->m_dialog = dialogTool;
198  }
199  return operation;
200 }
201 
202 //---------------------------------------------------------------------------------------------------------------------
203 VToolMove *VToolMove::Create(quint32 _id, QString &formulaAngle, QString &formulaLength, QString &formulaRotation,
204  quint32 &originPointId, const QString &suffix, const QVector<SourceItem> &source,
205  const QVector<DestinationItem> &destination, VMainGraphicsScene *scene,
206  VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation)
207 {
208  qreal calcAngle = 0;
209  qreal calcLength = 0;
210  qreal calcRotation = 0;
211 
212  calcAngle = CheckFormula(_id, formulaAngle, data);
213  calcLength = qApp->toPixel(CheckFormula(_id, formulaLength, data));
214  calcRotation = CheckFormula(_id, formulaRotation, data);
215 
216  QPointF rotationOrigin;
217  QSharedPointer<VPointF> originPoint;
218 
219  if (originPointId == NULL_ID)
220  {
221  rotationOrigin = findRotationOrigin(source, data, calcLength, calcAngle);
222  }
223  else
224  {
225  originPoint = data->GeometricObject<VPointF>(originPointId);
226  rotationOrigin = static_cast<QPointF>(*originPoint);
227  QLineF moveLine(rotationOrigin, QPointF(rotationOrigin.x() + calcLength, rotationOrigin.y()));
228  moveLine.setAngle(calcAngle);
229  rotationOrigin = moveLine.p2();
230  }
231 
233 
234  quint32 id = _id;
235  if (typeCreation == Source::FromGui)
236  {
237  dest.clear();// Try to avoid mistake, value must be empty
238 
239  id = VContainer::getNextId();//Just reserve id for tool
240 
241  qCDebug(vTool, "Create SourceItem GUI");
242  for (int i = 0; i < source.size(); ++i)
243  {
244  const SourceItem item = source.at(i);
245  qCDebug(vTool, "Add Object: %d", item.id);
246  const QSharedPointer<VGObject> object = data->GetGObject(item.id);
247 
248  // This check helps to find missed objects in the switch
249  Q_STATIC_ASSERT_X(static_cast<int>(GOType::AllCurves) == 10, "Not all objects were handled.");
250 
251 QT_WARNING_PUSH
252 QT_WARNING_DISABLE_GCC("-Wswitch-default")
253  qCDebug(vTool, "VToolMove - Rotation Origin");
254  qCDebug(vTool, "X: %f", rotationOrigin.x());
255  qCDebug(vTool, "Y: %f", rotationOrigin.y());
256  switch(static_cast<GOType>(object->getType()))
257  {
258  case GOType::Point:
259  qCDebug(vTool, "VToolMove - Point");
260  qCDebug(vTool, "length: %f", calcLength);
261  qCDebug(vTool, "angle: %f", calcAngle);
262  qCDebug(vTool, "rotation: %f\n", calcRotation);
263  dest.append(createPoint(id, item.id, calcAngle, calcLength, calcRotation,
264  rotationOrigin, suffix, data));
265  break;
266  case GOType::Arc:
267  dest.append(createArc<VArc>(id, item.id, calcAngle, calcLength, calcRotation,
268  rotationOrigin, suffix, data));
269  break;
271  dest.append(createArc<VEllipticalArc>(id, item.id, calcAngle, calcLength, calcRotation,
272  rotationOrigin, suffix, data));
273  break;
274  case GOType::Spline:
275  qCDebug(vTool, "VToolMove - Spline");
276  qCDebug(vTool, "length: %f", calcLength);
277  qCDebug(vTool, "angle: %f", calcAngle);
278  qCDebug(vTool, "rotation: %f\n", calcRotation);
279  dest.append(createCurve<VSpline>(id, item.id, calcAngle, calcLength, calcRotation,
280  rotationOrigin, suffix, data));
281  break;
282  case GOType::SplinePath:
283  dest.append(createCurveWithSegments<VSplinePath>(id, item.id, calcAngle, calcLength,
284  calcRotation, rotationOrigin, suffix,
285  data));
286  break;
287  case GOType::CubicBezier:
288  dest.append(createCurve<VCubicBezier>(id, item.id, calcAngle, calcLength, calcRotation,
289  rotationOrigin, suffix, data));
290  break;
292  qCDebug(vTool, "VToolMove - VCubicBezier");
293  qCDebug(vTool, "length: %f", calcLength);
294  qCDebug(vTool, "angle: %f", calcAngle);
295  qCDebug(vTool, "rotation: %f\n", calcRotation);
296  dest.append(createCurveWithSegments<VCubicBezierPath>(id, item.id, calcAngle, calcLength,
297  calcRotation, rotationOrigin, suffix,
298  data));
299  break;
300  case GOType::Unknown:
301  case GOType::Curve:
302  case GOType::Path:
303  case GOType::AllCurves:
304  default:
305  break;
306  }
308  }
309  }
310  else
311  {
312 
313  qCDebug(vTool, "Create sourceItem\n");
314  for (int i = 0; i < source.size(); ++i)
315  {
316  const SourceItem item = source.at(i);
317  qCDebug(vTool, "Add Object: %d\n", item.id);
318  const QSharedPointer<VGObject> object = data->GetGObject(item.id);
319 
320  // This check helps to find missed objects in the switch
321  Q_STATIC_ASSERT_X(static_cast<int>(GOType::AllCurves) == 10, "Not all objects were handled.");
322 
323 QT_WARNING_PUSH
324 QT_WARNING_DISABLE_GCC("-Wswitch-default")
325  switch(static_cast<GOType>(object->getType()))
326  {
327  case GOType::Point:
328  {
329  updatePoint(id, item.id, calcAngle, calcLength, calcRotation, rotationOrigin,
330  suffix, data, dest.at(i));
331  break;
332  }
333  case GOType::Arc:
334  updateArc<VArc>(id, item.id, calcAngle, calcLength, calcRotation, rotationOrigin,
335  suffix, data, dest.at(i).id);
336  break;
338  updateArc<VEllipticalArc>(id, item.id, calcAngle, calcLength, calcRotation, rotationOrigin,
339  suffix, data, dest.at(i).id);
340  break;
341  case GOType::Spline:
342  updateCurve<VSpline>(id, item.id, calcAngle, calcLength, calcRotation, rotationOrigin,
343  suffix, data, dest.at(i).id);
344  break;
345  case GOType::SplinePath:
346  updateCurveWithSegments<VSplinePath>(id, item.id, calcAngle, calcLength, calcRotation,
347  rotationOrigin, suffix, data, dest.at(i).id);
348  break;
349  case GOType::CubicBezier:
350  updateCurve<VCubicBezier>(id, item.id, calcAngle, calcLength, calcRotation, rotationOrigin,
351  suffix, data, dest.at(i).id);
352  break;
354  updateCurveWithSegments<VCubicBezierPath>(id, item.id, calcAngle, calcLength, calcRotation,
355  rotationOrigin, suffix, data, dest.at(i).id);
356  break;
357  case GOType::Unknown:
358  case GOType::Curve:
359  case GOType::Path:
360  case GOType::AllCurves:
361  default:
362  break;
363  }
365  }
366  if (parse != Document::FullParse)
367  {
368  doc->UpdateToolData(id, data);
369  }
370  }
371 
372  if (parse == Document::FullParse)
373  {
375  VToolMove *tool = new VToolMove(doc, data, id, formulaAngle, formulaLength, formulaRotation, originPointId,
376  suffix, source, dest, typeCreation);
377  scene->addItem(tool);
378  initOperationToolConnections(scene, tool);
379  VAbstractPattern::AddTool(id, tool);
380 
381  if (!originPoint.isNull())
382  {
383  doc->IncrementReferens(originPoint->getIdTool());
384  }
385  qCDebug(vTool, "Increment references");
386  for (int i = 0; i < source.size(); ++i)
387  {
388  const SourceItem item = source.at(i);
389  qCDebug(vTool, "Object: %d", item.id);
390  doc->IncrementReferens(data->GetGObject(item.id)->getIdTool());
391  }
392  return tool;
393  }
394  return nullptr;
395 }
396 
397 //---------------------------------------------------------------------------------------------------------------------
399 {
400  VFormula fAngle(formulaAngle, getData());
401  fAngle.setCheckZero(false);
402  fAngle.setToolId(m_id);
403  fAngle.setPostfix(degreeSymbol);
404  fAngle.Eval();
405  return fAngle;
406 }
407 
408 //---------------------------------------------------------------------------------------------------------------------
410 {
411  if (value.error() == false)
412  {
414 
416  SaveOption(obj);
417  }
418 }
419 
420 //---------------------------------------------------------------------------------------------------------------------
422 {
423  VFormula fLength(formulaLength, getData());
424  fLength.setCheckZero(true);
425  fLength.setToolId(m_id);
426  fLength.setPostfix(UnitsToStr(qApp->patternUnit()));
427  fLength.Eval();
428  return fLength;
429 }
430 
431 //---------------------------------------------------------------------------------------------------------------------
433 {
434  if (value.error() == false)
435  {
437 
439  SaveOption(obj);
440  }
441 }
442 
443 //---------------------------------------------------------------------------------------------------------------------
445 {
446  VFormula fRotation(formulaRotation, getData());
447  fRotation.setCheckZero(false);
448  fRotation.setToolId(m_id);
449  fRotation.setPostfix(degreeSymbol);
450  fRotation.Eval();
451  return fRotation;
452 }
453 
454 //---------------------------------------------------------------------------------------------------------------------
456 {
457  if (value.error() == false)
458  {
460 
462  SaveOption(obj);
463  }
464 }
465 
466 //---------------------------------------------------------------------------------------------------------------------
468 {
469  try
470  {
472  }
473  catch (const VExceptionBadId &)
474  {
475  return tr("Center point");
476  }
477 }
478 
479 //---------------------------------------------------------------------------------------------------------------------
481 {
482  return m_originPointId;
483 }
484 
485 //---------------------------------------------------------------------------------------------------------------------
486 void VToolMove::setOriginPointId(const quint32 &value)
487 {
488  m_originPointId = value;
489 
491  SaveOption(obj);
492 }
493 
494 //---------------------------------------------------------------------------------------------------------------------
496 {
497  ShowToolVisualization<VisToolMove>(show);
498 }
499 
500 //---------------------------------------------------------------------------------------------------------------------
502 {
503  if (!vis.isNull())
504  {
505  VisToolMove *visual = qobject_cast<VisToolMove *>(vis);
506  SCASSERT(visual != nullptr)
507 
509  visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator()));
510  visual->SetLength(qApp->TrVars()->FormulaToUser(formulaLength, qApp->Settings()->GetOsSeparator()));
511  visual->setRotation(qApp->TrVars()->FormulaToUser(formulaRotation, qApp->Settings()->GetOsSeparator()));
513  visual->RefreshGeometry();
514  }
515 }
516 
517 //---------------------------------------------------------------------------------------------------------------------
518 void VToolMove::SaveDialog(QDomElement &domElement)
519 {
520  SCASSERT(!m_dialog.isNull())
521  QSharedPointer<DialogMove> dialogTool = m_dialog.objectCast<DialogMove>();
522  SCASSERT(!dialogTool.isNull())
523 
524  doc->SetAttribute(domElement, AttrAngle, dialogTool->GetAngle());
525  QString length = dialogTool->GetLength();
526  doc->SetAttribute(domElement, AttrLength, length);
527  doc->SetAttribute(domElement, AttrSuffix, dialogTool->getSuffix());
528  doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->getOriginPointId()));
529  doc->SetAttribute(domElement, AttrRotationAngle, dialogTool->getRotation());
530 
531  source = dialogTool->getSourceObjects();
532  SaveSourceDestination(domElement);
533 }
534 
535 //---------------------------------------------------------------------------------------------------------------------
536 void VToolMove::ReadToolAttributes(const QDomElement &domElement)
537 {
539 
540  formulaAngle = doc->GetParametrString(domElement, AttrAngle, "0");
541  formulaLength = doc->GetParametrString(domElement, AttrLength, "0");
543  suffix = doc->GetParametrString(domElement, AttrSuffix);
545 
546 }
547 
548 //---------------------------------------------------------------------------------------------------------------------
550 {
552 
558  doc->SetAttribute(tag, AttrCenter, QString().setNum(m_originPointId));
559 }
560 
561 //---------------------------------------------------------------------------------------------------------------------
562 QString VToolMove::makeToolTip() const
563 {
564  const QString toolTipStr = QString("<tr> <td><b>%1:</b> %2°</td> </tr>"
565  "<tr> <td><b>%3:</b> %4 %5</td> </tr>"
566  "<tr> <td><b>%6:</b> %7</td> </tr>"
567  "<tr> <td><b>%8:</b> %9°</td> </tr>")
568  .arg(tr("Angle")) //1
569  .arg(GetFormulaAngle().getDoubleValue()) //2
570  .arg(tr("Length")) //3
571  .arg(GetFormulaLength().getDoubleValue()) //4
572  .arg(UnitsToStr(qApp->patternUnit(), true)) //5
573  .arg(tr("Rotation point")) //6
574  .arg(getOriginPointName()) //7
575  .arg(tr("Rotation angle")) //8
576  .arg(getFormulaRotation().getDoubleValue()); //9
577 
578  return toolTipStr;
579 }
580 
581 //---------------------------------------------------------------------------------------------------------------------
582 void VToolMove::showContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id)
583 {
584  try
585  {
586  ContextMenu<DialogMove>(event, id);
587  }
588  catch(const VExceptionToolWasDeleted &e)
589  {
590  Q_UNUSED(e)
591  return;//Leave this method immediately!!!
592  }
593 }
594 
595 //---------------------------------------------------------------------------------------------------------------------
596 DestinationItem VToolMove::createPoint(quint32 idTool, quint32 idItem, qreal angle,
597  qreal length, qreal rotation, const QPointF &rotationOrigin,
598  const QString &suffix, VContainer *data)
599 {
600  const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
601  VPointF moved = point->Move(length, angle, suffix).Rotate(rotationOrigin, rotation);
602  moved.setIdObject(idTool);
603 
604  DestinationItem item;
605  item.mx = moved.mx();
606  item.my = moved.my();
607  item.showPointName = moved.isShowPointName();
608  item.id = data->AddGObject(new VPointF(moved));
609  return item;
610 }
611 
612 //---------------------------------------------------------------------------------------------------------------------
613 template <class Item>
614 DestinationItem VToolMove::createItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation,
615  const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
616 {
617  const QSharedPointer<Item> i = data->GeometricObject<Item>(idItem);
618  Item moved = i->Move(length, angle, suffix).Rotate(rotationOrigin, rotation);
619  moved.setIdObject(idTool);
620 
621  DestinationItem item;
622  item.mx = INT_MAX;
623  item.my = INT_MAX;
624  item.id = data->AddGObject(new Item(moved));
625  return item;
626 }
627 
628 //---------------------------------------------------------------------------------------------------------------------
629 template <class Item>
630 DestinationItem VToolMove::createArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation,
631  const QPointF &rotationOrigin, const QString &suffix,
632  VContainer *data)
633 {
634  const DestinationItem item = createItem<Item>(idTool, idItem, angle, length, rotation, rotationOrigin,
635  suffix, data);
636  data->AddArc(data->GeometricObject<Item>(item.id), item.id);
637  return item;
638 }
639 
640 //---------------------------------------------------------------------------------------------------------------------
641 template <class Item>
642 DestinationItem VToolMove::createCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation,
643  const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
644 {
645  const DestinationItem item = createItem<Item>(idTool, idItem, angle, length, rotation, rotationOrigin,
646  suffix, data);
647  data->AddSpline(data->GeometricObject<Item>(item.id), item.id);
648  return item;
649 }
650 
651 //---------------------------------------------------------------------------------------------------------------------
652 template <class Item>
653 DestinationItem VToolMove::createCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle,
654  qreal length, qreal rotation, const QPointF &rotationOrigin,
655  const QString &suffix, VContainer *data)
656 {
657  const DestinationItem item = createItem<Item>(idTool, idItem, angle, length, rotation, rotationOrigin,
658  suffix, data);
660  return item;
661 }
662 
663 //---------------------------------------------------------------------------------------------------------------------
664 void VToolMove::updatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation,
665  const QPointF &rotationOrigin, const QString &suffix, VContainer *data, const DestinationItem &item)
666 {
667  const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
668  VPointF moved = point->Move(length, angle, suffix).Rotate(rotationOrigin, rotation);
669  moved.setIdObject(idTool);
670  moved.setMx(item.mx);
671  moved.setMy(item.my);
672  moved.setShowPointName(item.showPointName);
673  data->UpdateGObject(item.id, new VPointF(moved));
674 }
675 
676 //---------------------------------------------------------------------------------------------------------------------
677 template <class Item>
678 void VToolMove::updateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation,
679  const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
680 {
681  const QSharedPointer<Item> i = data->GeometricObject<Item>(idItem);
682  Item moved = i->Move(length, angle, suffix).Rotate(rotationOrigin, rotation);
683  moved.setIdObject(idTool);
684  data->UpdateGObject(id, new Item(moved));
685 }
686 
687 //---------------------------------------------------------------------------------------------------------------------
688 template <class Item>
689 void VToolMove::updateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation,
690  const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
691 {
692  updateItem<Item>(idTool, idItem, angle, length, rotation, rotationOrigin, suffix, data, id);
693  data->AddArc(data->GeometricObject<Item>(id), id);
694 }
695 
696 //---------------------------------------------------------------------------------------------------------------------
697 template <class Item>
698 void VToolMove::updateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation,
699  const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
700 {
701  updateItem<Item>(idTool, idItem, angle, length, rotation, rotationOrigin, suffix, data, id);
702  data->AddSpline(data->GeometricObject<Item>(id), id);
703 }
704 
705 //---------------------------------------------------------------------------------------------------------------------
706 template <class Item>
707 void VToolMove::updateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length,
708  qreal rotation, const QPointF &rotationOrigin,
709  const QString &suffix, VContainer *data, quint32 id)
710 {
711  updateItem<Item>(idTool, idItem, angle, length, rotation, rotationOrigin, suffix, data, id);
713 }
virtual QVector< QPointF > getPoints() const =0
virtual void SaveOptions(QDomElement &tag, QSharedPointer< VGObject > &obj) Q_DECL_OVERRIDE
QVector< SourceItem > source
static void initOperationToolConnections(VMainGraphicsScene *scene, T *tool)
void SaveSourceDestination(QDomElement &tag)
virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE
QVector< DestinationItem > destination
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.
VAbstractPattern * doc
doc dom document container
QPointer< Visualization > vis
const VContainer * getData() const
getData return pointer to data container.
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
void AddArc(const QSharedPointer< VAbstractCurve > &arc, const quint32 &id, const quint32 &parentId=null_id)
Definition: vcontainer.cpp:395
static quint32 getNextId()
getNextId generate next unique id
Definition: vcontainer.cpp:251
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
void AddCurveWithSegments(const QSharedPointer< VAbstractCubicBezierPath > &curve, const quint32 &id, quint32 parentId=null_id)
Definition: vcontainer.cpp:452
quint32 AddGObject(VGObject *obj)
AddGObject add new GObject to container.
Definition: vcontainer.cpp:216
static const QSharedPointer< VGObject > GetFakeGObject(quint32 id)
Definition: vcontainer.cpp:156
void UpdateGObject(quint32 id, T *obj)
UpdateGObject update GObject by id.
Definition: vcontainer.h:374
VContainer data
data container with data
Definition: vdatatool.h:84
static QString GetParametrString(const QDomElement &domElement, const QString &name, const QString &defValue=QString())
Returns the string value of the given attribute. RENAME: see above.
static quint32 GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue)
Returns the long long value of the given attribute. RENAME: GetParameterLongLong?
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
The VExceptionBadId class for exception bad id.
void Eval()
Definition: vformula.cpp:250
bool error() const
Definition: vformula.cpp:238
QString GetFormula(FormulaType type=FormulaType::ToUser) const
Definition: vformula.cpp:135
void setToolId(const quint32 &value)
Definition: vformula.cpp:216
void setCheckZero(bool value)
Definition: vformula.cpp:184
void setPostfix(const QString &value)
Definition: vformula.cpp:228
QSharedPointer< DialogTool > m_dialog
m_dialog tool's dialog options.
The VMainGraphicsScene class main scene.
The VPointF class keep data of point.
Definition: vpointf.h:75
QPointF toQPointF() const
Definition: vpointf.cpp:213
qreal y() const
y return y coordinate
Definition: vpointf.cpp:243
qreal x() const
x return x coordinate
Definition: vpointf.cpp:223
static void updateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
Definition: vtoolmove.cpp:689
static void updatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, const DestinationItem &item)
Definition: vtoolmove.cpp:664
static void updateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
Definition: vtoolmove.cpp:698
static VToolMove * Create(QSharedPointer< DialogTool > dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
Definition: vtoolmove.cpp:178
virtual void SetVisualization() Q_DECL_OVERRIDE
Definition: vtoolmove.cpp:501
void setFormulaRotation(const VFormula &value)
Definition: vtoolmove.cpp:455
virtual void showContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id=NULL_ID) Q_DECL_OVERRIDE
Definition: vtoolmove.cpp:582
static DestinationItem createArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
Definition: vtoolmove.cpp:630
static DestinationItem createItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
Definition: vtoolmove.cpp:614
QString formulaAngle
Definition: vtoolmove.h:118
virtual void setDialog() Q_DECL_OVERRIDE
setDialog set dialog when user want change tool option.
Definition: vtoolmove.cpp:164
QString getOriginPointName() const
Definition: vtoolmove.cpp:467
quint32 getOriginPointId() const
Definition: vtoolmove.cpp:480
VFormula getFormulaRotation() const
Definition: vtoolmove.cpp:444
QString formulaLength
Definition: vtoolmove.h:119
static void updateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
Definition: vtoolmove.cpp:707
VToolMove(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formulaAngle, const QString &formulaLength, const QString &formulaRotation, const quint32 &originPointId, const QString &suffix, const QVector< SourceItem > &source, const QVector< DestinationItem > &destination, const Source &typeCreation, QGraphicsItem *parent=nullptr)
Definition: vtoolmove.cpp:148
QString formulaRotation
Definition: vtoolmove.h:120
static DestinationItem createPoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
Definition: vtoolmove.cpp:596
static DestinationItem createCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
Definition: vtoolmove.cpp:653
static DestinationItem createCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data)
Definition: vtoolmove.cpp:642
void SetFormulaLength(const VFormula &value)
Definition: vtoolmove.cpp:432
VFormula GetFormulaLength() const
Definition: vtoolmove.cpp:421
static const QString ToolType
Definition: vtoolmove.h:86
void SetFormulaAngle(const VFormula &value)
Definition: vtoolmove.cpp:409
virtual QString makeToolTip() const Q_DECL_OVERRIDE
Definition: vtoolmove.cpp:562
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE
Definition: vtoolmove.cpp:495
virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE
Definition: vtoolmove.cpp:536
quint32 m_originPointId
Definition: vtoolmove.h:121
void setOriginPointId(const quint32 &value)
Definition: vtoolmove.cpp:486
static void updateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotation, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id)
Definition: vtoolmove.cpp:678
virtual void SaveOptions(QDomElement &tag, QSharedPointer< VGObject > &obj) Q_DECL_OVERRIDE
Definition: vtoolmove.cpp:549
virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE
SaveDialog save options into file after change in dialog.
Definition: vtoolmove.cpp:518
VFormula GetFormulaAngle() const
Definition: vtoolmove.cpp:398
void setObjects(QVector< quint32 > objects)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void SetAngle(const QString &expression)
void setOriginPointId(quint32 value)
void setRotation(const QString &expression)
void SetLength(const QString &expression)
const QString degreeSymbol
Definition: def.cpp:196
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
#define SCASSERT(cond)
Definition: def.h:317
Source
Definition: def.h:106
const QString AttrLength
Definition: ifcdef.cpp:94
const QString AttrAngle
Definition: ifcdef.cpp:103
const QString AttrRotationAngle
Definition: ifcdef.cpp:151
const QString AttrType
Definition: ifcdef.cpp:73
const QString AttrSuffix
Definition: ifcdef.cpp:147
const QString AttrCenter
Definition: ifcdef.cpp:99
#define NULL_ID
Definition: ifcdef.h:76
#define NULL_ID_STR
Definition: ifcdef.h:77
QT_WARNING_PUSH QPointF findRotationOrigin(const QVector< SourceItem > objects, const VContainer *data, qreal calcLength, qreal calcAngle)
Definition: vtoolmove.cpp:106
QVector< quint32 > sourceToObjects(const QVector< SourceItem > &source)
Document
#define qApp
Definition: vapplication.h:67
GOType
Definition: vgeometrydef.h:56
@ CubicBezierPath
@ SplinePath
@ EllipticalArc
@ CubicBezier