Seamly2D
Code documentation
vabstractmirror.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 16 9, 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 "vabstractmirror.h"
53 #include "../vgeometry/vabstractcurve.h"
54 #include "../vgeometry/varc.h"
55 #include "../vgeometry/vellipticalarc.h"
56 #include "../vgeometry/vcubicbezier.h"
57 #include "../vgeometry/vcubicbezierpath.h"
58 #include "../vgeometry/vgobject.h"
59 #include "../vgeometry/vpointf.h"
60 #include "../vgeometry/vspline.h"
61 #include "../vgeometry/vsplinepath.h"
62 
63 //---------------------------------------------------------------------------------------------------------------------
64 VAbstractMirror::VAbstractMirror(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix,
65  const QVector<SourceItem> &source, const QVector<DestinationItem> &destination,
66  QGraphicsItem *parent)
67  : VAbstractOperation(doc, data, id, suffix, source, destination, parent)
68 {
69 }
70 
71 //---------------------------------------------------------------------------------------------------------------------
73  const QVector<SourceItem> &source, const QPointF &fPoint, const QPointF &sPoint,
74  const QString &suffix, VAbstractPattern *doc, VContainer *data,
75  const Document &parse)
76 {
77  if (typeCreation == Source::FromGui)
78  {
79  dest.clear();// Try to avoid mistake, value must be empty
80 
81  id = VContainer::getNextId();//Just reserve id for tool
82 
83  for (int i = 0; i < source.size(); ++i)
84  {
85  const SourceItem item = source.at(i);
86  const quint32 objectId = item.id;
87  const QSharedPointer<VGObject> obj = data->GetGObject(objectId);
88 
89  // This check helps to find missed objects in the switch
90  Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
91 
92 QT_WARNING_PUSH
93 QT_WARNING_DISABLE_GCC("-Wswitch-default")
94  switch(static_cast<GOType>(obj->getType()))
95  {
96  case GOType::Point:
97  dest.append(createPoint(id, objectId, fPoint, sPoint, suffix, data));
98  break;
99  case GOType::Arc:
100  dest.append(createArc<VArc>(id, objectId, fPoint, sPoint, suffix, data));
101  break;
103  dest.append(createArc<VEllipticalArc>(id, objectId, fPoint, sPoint, suffix, data));
104  break;
105  case GOType::Spline:
106  dest.append(createCurve<VSpline>(id, objectId, fPoint, sPoint, suffix, data));
107  break;
108  case GOType::SplinePath:
109  dest.append(createCurveWithSegments<VSplinePath>(id, objectId, fPoint, sPoint, suffix, data));
110  break;
111  case GOType::CubicBezier:
112  dest.append(createCurve<VCubicBezier>(id, objectId, fPoint, sPoint, suffix, data));
113  break;
115  dest.append(createCurveWithSegments<VCubicBezierPath>(id, objectId, fPoint, sPoint, suffix, data));
116  break;
117  case GOType::Curve:
118  case GOType::Path:
119  case GOType::AllCurves:
120  case GOType::Unknown:
121  default:
122  break;
123  }
125  }
126  }
127  else
128  {
129  for (int i = 0; i < source.size(); ++i)
130  {
131  const SourceItem item = source.at(i);
132  const quint32 objectId = item.id;
133  const QSharedPointer<VGObject> obj = data->GetGObject(objectId);
134 
135  // This check helps to find missed objects in the switch
136  Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
137 
138 QT_WARNING_PUSH
139 QT_WARNING_DISABLE_GCC("-Wswitch-default")
140  switch(static_cast<GOType>(obj->getType()))
141  {
142  case GOType::Point:
143  {
144  const DestinationItem &item = dest.at(i);
145  updatePoint(id, objectId, fPoint, sPoint, suffix, data, item);
146  //dest.at(i).id, dest.at(i).mx, dest.at(i).my);
147  break;
148  }
149  case GOType::Arc:
150  updateArc<VArc>(id, objectId, fPoint, sPoint, suffix, data, dest.at(i).id);
151  break;
153  updateArc<VEllipticalArc>(id, objectId, fPoint, sPoint, suffix, data, dest.at(i).id);
154  break;
155  case GOType::Spline:
156  updateCurve<VSpline>(id, objectId, fPoint, sPoint, suffix, data, dest.at(i).id);
157  break;
158  case GOType::SplinePath:
159  updateCurveWithSegments<VSplinePath>(id, objectId, fPoint, sPoint, suffix, data, dest.at(i).id);
160  break;
161  case GOType::CubicBezier:
162  updateCurve<VCubicBezier>(id, objectId, fPoint, sPoint, suffix, data, dest.at(i).id);
163  break;
165  updateCurveWithSegments<VCubicBezierPath>(id, objectId, fPoint, sPoint, suffix, data,
166  dest.at(i).id);
167  break;
168  case GOType::Unknown:
169  case GOType::Curve:
170  case GOType::Path:
171  case GOType::AllCurves:
172  break;
173  }
175  }
176  if (parse != Document::FullParse)
177  {
178  doc->UpdateToolData(id, data);
179  }
180  }
181 }
182 
183 //---------------------------------------------------------------------------------------------------------------------
184 DestinationItem VAbstractMirror::createPoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
185  const QPointF &secondPoint, const QString &suffix, VContainer *data)
186 {
187  const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
188  VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix);
189  rotated.setIdObject(idTool);
190 
191  DestinationItem item;
192  item.mx = rotated.mx();
193  item.my = rotated.my();
194  item.showPointName = rotated.isShowPointName();
195  item.id = data->AddGObject(new VPointF(rotated));
196  return item;
197 }
198 
199 //---------------------------------------------------------------------------------------------------------------------
200 template <class Item>
201 DestinationItem VAbstractMirror::createArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
202  const QPointF &secondPoint, const QString &suffix, VContainer *data)
203 {
204  const DestinationItem item = createItem<Item>(idTool, idItem, firstPoint, secondPoint, suffix, data);
205  data->AddArc(data->GeometricObject<Item>(item.id), item.id);
206  return item;
207 }
208 
209 //---------------------------------------------------------------------------------------------------------------------
210 void VAbstractMirror::updatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
211  const QPointF &secondPoint, const QString &suffix, VContainer *data,
212  const DestinationItem &item)
213 {
214  const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(idItem);
215  VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix);
216  rotated.setIdObject(idTool);
217  rotated.setMx(item.mx);
218  rotated.setMy(item.my);
219  rotated.setShowPointName(item.showPointName);
220  data->UpdateGObject(item.id, new VPointF(rotated));
221 }
222 
223 //---------------------------------------------------------------------------------------------------------------------
224 template <class Item>
225 void VAbstractMirror::updateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint,
226  const QString &suffix, VContainer *data, quint32 id)
227 {
228  updateItem<Item>(idTool, idItem, firstPoint, secondPoint, suffix, data, id);
229  data->AddArc(data->GeometricObject<Item>(id), id);
230 }
static void createDestination(Source typeCreation, quint32 &id, QVector< DestinationItem > &dest, const QVector< SourceItem > &source, const QPointF &fPoint, const QPointF &sPoint, const QString &suffix, VAbstractPattern *doc, VContainer *data, const Document &parse)
static DestinationItem createArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data)
static void updatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, const DestinationItem &item)
static DestinationItem createPoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data)
static void updateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id)
VAbstractMirror(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, const QVector< SourceItem > &source, const QVector< DestinationItem > &destination, QGraphicsItem *parent=nullptr)
QVector< SourceItem > source
virtual void UpdateToolData(const quint32 &id, VContainer *data)=0
VAbstractPattern * doc
doc dom document container
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
quint32 AddGObject(VGObject *obj)
AddGObject add new GObject to container.
Definition: vcontainer.cpp:216
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
The VPointF class keep data of point.
Definition: vpointf.h:75
Source
Definition: def.h:106
Document
GOType
Definition: vgeometrydef.h:56
@ CubicBezierPath
@ SplinePath
@ EllipticalArc
@ CubicBezier