Seamly2D
Code documentation
vabstractmirror.h
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 #ifndef VABSTRACTMIRROR_H
53 #define VABSTRACTMIRROR_H
54 
55 #include <QtGlobal>
56 
57 #include "../vabstractoperation.h"
58 
60 {
61  Q_OBJECT
62 
63 public:
64  virtual ~VAbstractMirror() Q_DECL_EQ_DEFAULT;
65 
66 protected:
67  VAbstractMirror(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix,
69  QGraphicsItem *parent = nullptr);
70 
71  static void createDestination(Source typeCreation, quint32 &id, QVector<DestinationItem> &dest,
72  const QVector<SourceItem> &source, const QPointF &fPoint,
73  const QPointF &sPoint, const QString &suffix, VAbstractPattern *doc,
74  VContainer *data, const Document &parse);
75 
76  static DestinationItem createPoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
77  const QPointF &secondPoint, const QString &suffix, VContainer *data);
78 
79  template <class Item>
80  static DestinationItem createItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
81  const QPointF &secondPoint, const QString &suffix, VContainer *data);
82  template <class Item>
83  static DestinationItem createArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
84  const QPointF &secondPoint, const QString &suffix, VContainer *data);
85  template <class Item>
86  static DestinationItem createCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
87  const QPointF &secondPoint, const QString &suffix, VContainer *data);
88  template <class Item>
89  static DestinationItem createCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
90  const QPointF &secondPoint, const QString &suffix, VContainer *data);
91 
92  static void updatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint,
93  const QString &suffix, VContainer *data, const DestinationItem &item);
94  template <class Item>
95  static void updateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint,
96  const QString &suffix, VContainer *data, quint32 id);
97  template <class Item>
98  static void updateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint,
99  const QString &suffix, VContainer *data, quint32 id);
100  template <class Item>
101  static void updateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint,
102  const QString &suffix, VContainer *data, quint32 id);
103  template <class Item>
104  static void updateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
105  const QPointF &secondPoint, const QString &suffix, VContainer *data,
106  quint32 id);
107 
108 private:
109  Q_DISABLE_COPY(VAbstractMirror)
110 };
111 
112 //---------------------------------------------------------------------------------------------------------------------
113 template <class Item>
114 DestinationItem VAbstractMirror::createItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
115  const QPointF &secondPoint, const QString &suffix, VContainer *data)
116 {
117  const QSharedPointer<Item> i = data->GeometricObject<Item>(idItem);
118  Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix);
119  rotated.setIdObject(idTool);
120 
121  DestinationItem item;
122  item.mx = INT_MAX;
123  item.my = INT_MAX;
124  item.id = data->AddGObject(new Item(rotated));
125  return item;
126 }
127 
128 //---------------------------------------------------------------------------------------------------------------------
129 template <class Item>
130 DestinationItem VAbstractMirror::createCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
131  const QPointF &secondPoint, const QString &suffix, VContainer *data)
132 {
133  const DestinationItem item = createItem<Item>(idTool, idItem, firstPoint, secondPoint, suffix, data);
134  data->AddSpline(data->GeometricObject<Item>(item.id), item.id);
135  return item;
136 }
137 
138 //---------------------------------------------------------------------------------------------------------------------
139 template <class Item>
140 DestinationItem VAbstractMirror::createCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
141  const QPointF &secondPoint, const QString &suffix,
142  VContainer *data)
143 {
144  const DestinationItem item = createItem<Item>(idTool, idItem, firstPoint, secondPoint, suffix, data);
146  return item;
147 }
148 
149 //---------------------------------------------------------------------------------------------------------------------
150 template <class Item>
151 void VAbstractMirror::updateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
152  const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id)
153 {
154  const QSharedPointer<Item> i = data->GeometricObject<Item>(idItem);
155  Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix);
156  rotated.setIdObject(idTool);
157  data->UpdateGObject(id, new Item(rotated));
158 }
159 
160 //---------------------------------------------------------------------------------------------------------------------
161 template <class Item>
162 void VAbstractMirror::updateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
163  const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id)
164 {
165  updateItem<Item>(idTool, idItem, firstPoint, secondPoint, suffix, data, id);
166  data->AddSpline(data->GeometricObject<Item>(id), id);
167 }
168 
169 //---------------------------------------------------------------------------------------------------------------------
170 template <class Item>
171 void VAbstractMirror::updateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
172  const QPointF &secondPoint, const QString &suffix, VContainer *data,
173  quint32 id)
174 {
175  updateItem<Item>(idTool, idItem, firstPoint, secondPoint, suffix, data, id);
177 }
178 
179 #endif // VABSTRACTMIRROR_H
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 updateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id)
static void updatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, const DestinationItem &item)
static void updateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id)
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)
static void updateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id)
virtual ~VAbstractMirror() Q_DECL_EQ_DEFAULT
static DestinationItem createCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data)
static DestinationItem createItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data)
static DestinationItem createCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data)
QVector< SourceItem > source
QVector< DestinationItem > destination
VAbstractPattern * doc
doc dom document container
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
void AddSpline(const QSharedPointer< VAbstractBezier > &curve, quint32 id, quint32 parentId=null_id)
Definition: vcontainer.cpp:440
void AddCurveWithSegments(const QSharedPointer< VAbstractCubicBezierPath > &curve, const quint32 &id, quint32 parentId=null_id)
Definition: vcontainer.cpp:452
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
Source
Definition: def.h:106
Document