Seamly2D
Code documentation
movesplinepath.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 movesplinepath.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 11 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 "movesplinepath.h"
53 
54 #include <QDomElement>
55 
56 #include "../ifc/xml/vabstractpattern.h"
57 #include "../tools/drawTools/toolcurve/vtoolsplinepath.h"
58 #include "../vmisc/logging.h"
59 #include "../vmisc/vabstractapplication.h"
60 #include "../vmisc/def.h"
61 #include "../vwidgets/vmaingraphicsview.h"
62 #include "../vgeometry/vsplinepath.h"
63 #include "vundocommand.h"
64 
65 //---------------------------------------------------------------------------------------------------------------------
66 MoveSplinePath::MoveSplinePath(VAbstractPattern *doc, const VSplinePath &oldSplPath, const VSplinePath &newSplPath,
67  const quint32 &id, QUndoCommand *parent)
68  : VUndoCommand(QDomElement(), doc, parent),
69  oldSplinePath(oldSplPath),
70  newSplinePath(newSplPath),
71  scene(qApp->getCurrentScene())
72 {
73  setText(tr("move spline path"));
74  nodeId = id;
75 
76  SCASSERT(scene != nullptr)
77 }
78 
79 //---------------------------------------------------------------------------------------------------------------------
81 {}
82 
83 //---------------------------------------------------------------------------------------------------------------------
85 {
86  qCDebug(vUndo, "Undo.");
87 
89  VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
94 {
95  qCDebug(vUndo, "Redo.");
96 
98  VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
99 }
100 
101 //---------------------------------------------------------------------------------------------------------------------
102 bool MoveSplinePath::mergeWith(const QUndoCommand *command)
103 {
104  const MoveSplinePath *moveCommand = static_cast<const MoveSplinePath *>(command);
105  SCASSERT(moveCommand != nullptr)
106  const quint32 id = moveCommand->getSplinePathId();
107 
108  if (id != nodeId)
109  {
110  return false;
111  }
112 
113  newSplinePath = moveCommand->getNewSplinePath();
114  return true;
115 }
116 
117 //---------------------------------------------------------------------------------------------------------------------
119 {
120  return static_cast<int>(UndoCommand::MoveSplinePath);
121 }
122 
123 //---------------------------------------------------------------------------------------------------------------------
125 {
126  QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagSpline);
127  if (domElement.isElement())
128  {
130 
132  }
133  else
134  {
135  qCDebug(vUndo, "Can't find spline path with id = %u.", nodeId);
136  return;
137  }
138 }
QGraphicsScene * scene
virtual ~MoveSplinePath() Q_DECL_OVERRIDE
MoveSplinePath(VAbstractPattern *doc, const VSplinePath &oldSplPath, const VSplinePath &newSplPath, const quint32 &id, QUndoCommand *parent=nullptr)
virtual void redo() Q_DECL_OVERRIDE
virtual void undo() Q_DECL_OVERRIDE
void Do(const VSplinePath &splPath)
VSplinePath newSplinePath
quint32 getSplinePathId() const
VSplinePath oldSplinePath
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE
VSplinePath getNewSplinePath() const
virtual int id() const Q_DECL_OVERRIDE
static const QString TagSpline
QDomElement elementById(quint32 id, const QString &tagName=QString())
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.
The VSplinePath class keep information about splinePath.
Definition: vsplinepath.h:72
static void UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VSplinePath &path)
UpdatePathPoints update spline path in pattern file.
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 splPath
Definition: ifcdef.cpp:419
#define qApp
Definition: vapplication.h:67