Seamly2D
Code documentation
movespline.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 movespline.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 9 6, 2014
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 "movespline.h"
53 
54 #include <QDomElement>
55 
56 #include "../ifc/ifcdef.h"
57 #include "../ifc/xml/vabstractpattern.h"
58 #include "../vmisc/logging.h"
59 #include "../vmisc/vabstractapplication.h"
60 #include "../vmisc/def.h"
61 #include "../vwidgets/vmaingraphicsview.h"
62 #include "../vgeometry/vpointf.h"
63 #include "../vgeometry/vspline.h"
64 #include "vundocommand.h"
65 
66 //---------------------------------------------------------------------------------------------------------------------
67 MoveSpline::MoveSpline(VAbstractPattern *doc, const VSpline *oldSpl, const VSpline &newSpl, const quint32 &id,
68  QUndoCommand *parent)
69  : VUndoCommand(QDomElement(), doc, parent),
70  oldSpline(*oldSpl),
71  newSpline(newSpl),
72  scene(qApp->getCurrentScene())
73 {
74  setText(tr("move spline"));
75  nodeId = id;
76 
77  SCASSERT(scene != nullptr)
78 }
79 
80 //---------------------------------------------------------------------------------------------------------------------
82 {}
83 
84 //---------------------------------------------------------------------------------------------------------------------
86 {
87  qCDebug(vUndo, "Undo.");
88 
89  Do(oldSpline);
90  VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
91 }
92 
93 //---------------------------------------------------------------------------------------------------------------------
95 {
96  qCDebug(vUndo, "Redo.");
97 
98  Do(newSpline);
99  VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
103 bool MoveSpline::mergeWith(const QUndoCommand *command)
104 {
105  const MoveSpline *moveCommand = static_cast<const MoveSpline *>(command);
106  SCASSERT(moveCommand != nullptr)
107  const quint32 id = moveCommand->getSplineId();
108 
109  if (id != nodeId)
110  {
111  return false;
112  }
113 
114  newSpline = moveCommand->getNewSpline();
115  return true;
116 }
117 
118 //---------------------------------------------------------------------------------------------------------------------
119 int MoveSpline::id() const
120 {
121  return static_cast<int>(UndoCommand::MoveSpline);
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
125 void MoveSpline::Do(const VSpline &spl)
126 {
127  QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagSpline);
128  if (domElement.isElement())
129  {
130  doc->SetAttribute(domElement, AttrPoint1, spl.GetP1().id());
131  doc->SetAttribute(domElement, AttrPoint4, spl.GetP4().id());
132  doc->SetAttribute(domElement, AttrAngle1, spl.GetStartAngleFormula());
133  doc->SetAttribute(domElement, AttrAngle2, spl.GetEndAngleFormula());
134  doc->SetAttribute(domElement, AttrLength1, spl.GetC1LengthFormula());
135  doc->SetAttribute(domElement, AttrLength2, spl.GetC2LengthFormula());
136 
138  }
139  else
140  {
141  qCDebug(vUndo, "Can't find spline with id = %u.", nodeId);
142  return;
143  }
144 }
virtual void redo() Q_DECL_OVERRIDE
Definition: movespline.cpp:94
quint32 getSplineId() const
Definition: movespline.h:88
void Do(const VSpline &spl)
Definition: movespline.cpp:125
virtual ~MoveSpline() Q_DECL_OVERRIDE
Definition: movespline.cpp:81
VSpline newSpline
Definition: movespline.h:82
MoveSpline(VAbstractPattern *doc, const VSpline *oldSpl, const VSpline &newSpl, const quint32 &id, QUndoCommand *parent=nullptr)
Definition: movespline.cpp:67
virtual int id() const Q_DECL_OVERRIDE
Definition: movespline.cpp:119
VSpline oldSpline
Definition: movespline.h:81
QGraphicsScene * scene
Definition: movespline.h:83
virtual void undo() Q_DECL_OVERRIDE
Definition: movespline.cpp:85
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE
Definition: movespline.cpp:103
VSpline getNewSpline() const
Definition: movespline.h:94
static const QString TagSpline
QDomElement elementById(quint32 id, const QString &tagName=QString())
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
Definition: vdomdocument.h:185
quint32 id() const
id return id object.
Definition: vgobject.cpp:205
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QGraphicsItem *item=nullptr)
NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view.
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
virtual VPointF GetP1() const Q_DECL_OVERRIDE
GetP1 return first spline point.
Definition: vspline.cpp:281
QString GetStartAngleFormula() const
Definition: vspline.cpp:353
QString GetEndAngleFormula() const
Definition: vspline.cpp:359
QString GetC2LengthFormula() const
Definition: vspline.cpp:397
VAbstractPattern * doc
Definition: vundocommand.h:106
void NeedLiteParsing(const Document &parse)
quint32 nodeId
Definition: vundocommand.h:107
#define SCASSERT(cond)
Definition: def.h:317
const QString AttrLength2
Definition: ifcdef.cpp:107
const QString AttrPoint1
Definition: ifcdef.cpp:115
const QString AttrLength1
Definition: ifcdef.cpp:106
const QString AttrAngle2
Definition: ifcdef.cpp:105
const QString AttrPoint4
Definition: ifcdef.cpp:118
const QString AttrAngle1
Definition: ifcdef.cpp:104
#define qApp
Definition: vapplication.h:67