Seamly2D
Code documentation
savepieceoptions.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file savepieceoptions.cpp
3  ** @author Douglas S Caskey
4  ** @date Dec 11, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 /************************************************************************
26  **
27  ** @file
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 9 11, 2016
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentine project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2016 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #include "savepieceoptions.h"
54 
55 #include <QDomElement>
56 #include <QPointF>
57 #include <QUndoCommand>
58 #include <QDebug>
59 
60 #include "../ifc/xml/vabstractpattern.h"
61 #include "../ifc/ifcdef.h"
62 #include "../vmisc/logging.h"
63 #include "../vmisc/def.h"
64 #include "../vpatterndb/vpiecenode.h"
65 #include "../vpatterndb/floatItemData/vpatternlabeldata.h"
66 #include "../vpatterndb/floatItemData/vpiecelabeldata.h"
67 #include "../vpatterndb/floatItemData/vgrainlinedata.h"
68 #include "../tools/pattern_piece_tool.h"
69 #include "vundocommand.h"
70 
71 //---------------------------------------------------------------------------------------------------------------------
72 SavePieceOptions::SavePieceOptions(const VPiece &oldPiece, const VPiece &newPiece, VAbstractPattern *doc, quint32 id,
73  QUndoCommand *parent)
74  : VUndoCommand(QDomElement(), doc, parent)
75  , m_oldPiece(oldPiece)
76  , m_newPiece(newPiece)
77 {
78  setText(tr("save detail option"));
79  nodeId = id;
80 }
81 
82 //---------------------------------------------------------------------------------------------------------------------
84 {}
85 
86 //---------------------------------------------------------------------------------------------------------------------
88 {
89  qCDebug(vUndo, "Undo.");
90 
91  QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPiece);
92  if (domElement.isElement())
93  {
95  doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
103 
109  }
110  else
111  {
112  qCDebug(vUndo, "Can't find piece with id = %u.", nodeId);
113  return;
114  }
115 }
116 
117 //---------------------------------------------------------------------------------------------------------------------
119 {
120  qCDebug(vUndo, "Redo.");
121 
122  QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPiece);
123  if (domElement.isElement())
124  {
126  doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
134 
139 
141  }
142  else
143  {
144  qCDebug(vUndo, "Can't find piece with id = %u.", nodeId);
145  return;
146  }
147 }
148 
149 //---------------------------------------------------------------------------------------------------------------------
150 bool SavePieceOptions::mergeWith(const QUndoCommand *command)
151 {
152  const SavePieceOptions *saveCommand = static_cast<const SavePieceOptions *>(command);
153  SCASSERT(saveCommand != nullptr);
154  const quint32 id = saveCommand->pieceId();
155 
156  if (id != nodeId)
157  {
158  return false;
159  }
160 
161  m_newPiece = saveCommand->getNewPiece();
162  return true;
163 }
164 
165 //---------------------------------------------------------------------------------------------------------------------
167 {
168  return static_cast<int>(UndoCommand::SavePieceOptions);
169 }
static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece)
static void AddCSARecords(VAbstractPattern *doc, QDomElement &domElement, const QVector< CustomSARecord > &records)
static void AddInternalPaths(VAbstractPattern *doc, QDomElement &domElement, const QVector< quint32 > &paths)
static void AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
static void addAnchors(VAbstractPattern *doc, QDomElement &domElement, const QVector< quint32 > &anchors)
SavePieceOptions(const VPiece &oldPiece, const VPiece &newPiece, VAbstractPattern *doc, quint32 id, QUndoCommand *parent=nullptr)
virtual ~SavePieceOptions()
virtual void undo() Q_DECL_OVERRIDE
virtual void redo() Q_DECL_OVERRIDE
quint32 pieceId() const
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE
const VPiece m_oldPiece
virtual int id() const Q_DECL_OVERRIDE
VPiece getNewPiece() const
static const QString TagPiece
static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path)
QDomElement elementById(quint32 id, const QString &tagName=QString())
static void RemoveAllChildren(QDomElement &domElement)
RemoveAllChildren remove all children from file.
Definition: vpiece.h:88
QVector< CustomSARecord > GetCustomSARecords() const
Definition: vpiece.cpp:444
QVector< quint32 > GetInternalPaths() const
Definition: vpiece.cpp:426
QVector< quint32 > missingAnchors(const VPiece &piece) const
Definition: vpiece.cpp:516
QVector< quint32 > getAnchors() const
Definition: vpiece.cpp:462
QVector< quint32 > MissingInternalPaths(const VPiece &piece) const
Definition: vpiece.cpp:510
QVector< quint32 > MissingNodes(const VPiece &piece) const
MissingNodes find missing nodes in piece. When we deleted object in piece and return this piece need ...
Definition: vpiece.cpp:486
QVector< quint32 > MissingCSAPath(const VPiece &piece) const
Definition: vpiece.cpp:492
void DecrementReferences(const QVector< quint32 > &nodes) const
VAbstractPattern * doc
Definition: vundocommand.h:106
void NeedLiteParsing(const Document &parse)
void IncrementReferences(const QVector< quint32 > &nodes) const
quint32 nodeId
Definition: vundocommand.h:107
#define SCASSERT(cond)
Definition: def.h:317