Seamly2D
Code documentation
vtoolcut.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 vtoolcut.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 25 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 "vtoolcut.h"
53 
54 #include <QDomElement>
55 #include <QSharedPointer>
56 #include <new>
57 
58 #include "../ifc/xml/vdomdocument.h"
59 #include "../ifc/ifcdef.h"
60 #include "../vgeometry/vgobject.h"
61 #include "../vgeometry/vpointf.h"
62 #include "../vmisc/vabstractapplication.h"
63 #include "../vpatterndb/vcontainer.h"
64 #include "../vpatterndb/vformula.h"
65 #include "../../../../vabstracttool.h"
66 #include "../../../vdrawtool.h"
67 #include "../vtoolsinglepoint.h"
68 
69 //---------------------------------------------------------------------------------------------------------------------
70 VToolCut::VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
71  const quint32 &curveCutId, QGraphicsItem *parent)
72  : VToolSinglePoint(doc, data, id, QColor(qApp->Settings()->getPointNameColor()), parent)
73  , formula(formula)
74  , curveCutId(curveCutId)
75  , m_piecesMode(false)
76 {
77  Q_ASSERT_X(curveCutId != 0, Q_FUNC_INFO, "curveCutId == 0"); //-V654 //-V712
78 }
79 
80 //---------------------------------------------------------------------------------------------------------------------
81 void VToolCut::Disable(bool disable, const QString &draftBlockName)
82 {
83  VToolSinglePoint::Disable(disable, draftBlockName);
84 }
85 
86 //---------------------------------------------------------------------------------------------------------------------
87 void VToolCut::piecesMode(bool mode)
88 {
89  m_piecesMode = mode;
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
93 /**
94  * @brief FullUpdateFromFile update tool data form file.
95  */
97 {
101 }
102 
103 //---------------------------------------------------------------------------------------------------------------------
104 // cppcheck-suppress unusedFunction
105 quint32 VToolCut::getCurveCutId() const
106 {
107  return curveCutId;
108 }
109 
110 //---------------------------------------------------------------------------------------------------------------------
111 // cppcheck-suppress unusedFunction
112 void VToolCut::setCurveCutId(const quint32 &value)
113 {
114  if (value != NULL_ID)
115  {
116  curveCutId = value;
118  SaveOption(obj);
119  }
120 }
121 
122 //---------------------------------------------------------------------------------------------------------------------
124 {
125  VFormula val(formula, getData());
126  val.setCheckZero(true);
127  val.setToolId(m_id);
128  val.setPostfix(UnitsToStr(qApp->patternUnit()));
129  return val;
130 }
131 
132 //---------------------------------------------------------------------------------------------------------------------
133 void VToolCut::SetFormula(const VFormula &value)
134 {
135  if (value.error() == false)
136  {
138 
140  SaveOption(obj);
141  }
142 }
143 
144 //---------------------------------------------------------------------------------------------------------------------
145 QString VToolCut::CurveName() const
146 {
147  return VAbstractTool::data.GetGObject(curveCutId)->name();
148 }
149 
150 //---------------------------------------------------------------------------------------------------------------------
151 /**
152  * @brief RefreshGeometry refresh item on scene.
153  */
155 {
156  VToolSinglePoint::refreshPointGeometry(*VDrawTool::data.GeometricObject<VPointF>(m_id));
157 }
158 
159 //---------------------------------------------------------------------------------------------------------------------
160 /**
161  * @brief RemoveReferens decrement referens value for used objects.
162  */
164 {
165  const auto curve = VAbstractTool::data.GetGObject(curveCutId);
166 
167  doc->DecrementReferens(curve->getIdTool());
168 }
virtual void DecrementReferens(quint32 id) const =0
VAbstractPattern * doc
doc dom document container
const VContainer * getData() const
getData return pointer to data container.
const quint32 m_id
id object id.
virtual void SetVisualization()=0
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
VContainer data
data container with data
Definition: vdatatool.h:84
void SaveOption(QSharedPointer< VGObject > &obj)
Definition: vdrawtool.cpp:142
void ReadAttributes()
Definition: vdrawtool.cpp:190
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
virtual void refreshPointGeometry(const VPointF &point)
QString formula
formula keep formula of length
Definition: vtoolcut.h:96
virtual void RemoveReferens() Q_DECL_OVERRIDE
RemoveReferens decrement referens value for used objects.
Definition: vtoolcut.cpp:163
quint32 getCurveCutId() const
Definition: vtoolcut.cpp:105
void SetFormula(const VFormula &value)
Definition: vtoolcut.cpp:133
void setCurveCutId(const quint32 &value)
Definition: vtoolcut.cpp:112
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE
FullUpdateFromFile update tool data form file.
Definition: vtoolcut.cpp:96
void RefreshGeometry()
RefreshGeometry refresh item on scene.
Definition: vtoolcut.cpp:154
virtual void Disable(bool disable, const QString &draftBlockName) Q_DECL_OVERRIDE
Definition: vtoolcut.cpp:81
virtual void piecesMode(bool mode) Q_DECL_OVERRIDE
Definition: vtoolcut.cpp:87
VFormula GetFormula() const
Definition: vtoolcut.cpp:123
bool m_piecesMode
Definition: vtoolcut.h:99
VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, const quint32 &curveCutId, QGraphicsItem *parent=nullptr)
Definition: vtoolcut.cpp:70
QString CurveName() const
Definition: vtoolcut.cpp:145
quint32 curveCutId
Definition: vtoolcut.h:98
The VToolSinglePoint class parent for all tools what create points.
virtual void Disable(bool disable, const QString &draftBlockName) Q_DECL_OVERRIDE
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
#define NULL_ID
Definition: ifcdef.h:76
#define qApp
Definition: vapplication.h:67