]> Shamusworld >> Repos - architektonas/blob - src/base/modification.h
Bugfixes related to removing Snapper class.
[architektonas] / src / base / modification.h
1 #ifndef __MODIFICATION_H__
2 #define __MODIFICATION_H__
3
4 #include "entitycontainer.h"
5 #include "graphicview.h"
6 #include "line.h"
7
8 /**
9  * Holds the data needed for move modifications.
10  */
11 class MoveData
12 {
13         public:
14                 int number;
15                 bool useCurrentAttributes;
16                 bool useCurrentLayer;
17                 Vector offset;
18 };
19
20 /**
21  * Holds the data needed for rotation modifications.
22  */
23 class RotateData
24 {
25         public:
26                 int number;
27                 bool useCurrentAttributes;
28                 bool useCurrentLayer;
29                 Vector center;
30                 double angle;
31 };
32
33 /**
34  * Holds the data needed for scale modifications.
35  */
36 class ScaleData
37 {
38         public:
39                 int number;
40                 bool useCurrentAttributes;
41                 bool useCurrentLayer;
42                 Vector referencePoint;
43                 double factor;
44 };
45
46 /**
47  * Holds the data needed for mirror modifications.
48  */
49 class MirrorData
50 {
51         public:
52                 bool copy;
53                 bool useCurrentAttributes;
54                 bool useCurrentLayer;
55                 Vector axisPoint1;
56                 Vector axisPoint2;
57 };
58
59 /**
60  * Holds the data needed for move/rotate modifications.
61  */
62 class MoveRotateData
63 {
64         public:
65                 int number;
66                 bool useCurrentAttributes;
67                 bool useCurrentLayer;
68                 Vector referencePoint;
69                 Vector offset;
70                 double angle;
71 };
72
73 /**
74  * Holds the data needed for rotation around two centers modifications.
75  */
76 class Rotate2Data
77 {
78         public:
79                 int number;
80                 bool useCurrentAttributes;
81                 bool useCurrentLayer;
82                 Vector center1;
83                 Vector center2;
84                 double angle1;
85                 double angle2;
86 };
87
88 /**
89  * Holds the data needed for beveling modifications.
90  */
91 class BevelData
92 {
93         public:
94                 double length1;
95                 double length2;
96                 bool trim;
97 };
98
99 /**
100  * Holds the data needed for rounding modifications.
101  */
102 class RoundData
103 {
104         public:
105                 double radius;
106                 bool trim;
107 };
108
109 /**
110  * Holds the data needed for moving reference points.
111  */
112 class MoveRefData
113 {
114         public:
115                 Vector ref;
116                 Vector offset;
117 };
118
119 /**
120  * Holds the data needed for changing attributes.
121  */
122 class AttributesData
123 {
124         public:
125                 QString layer;
126                 Pen pen;
127                 bool changeLayer;
128                 bool changeColor;
129                 bool changeLineType;
130                 bool changeWidth;
131 };
132
133 /**
134  * Holds the data needed for pasting.
135  */
136 class PasteData
137 {
138         public:
139                 PasteData(Vector insertionPoint, double factor, double angle,
140                         bool asInsert, const QString & blockName)
141                 {
142                         this->insertionPoint = insertionPoint;
143                         this->factor = factor;
144                         this->angle = angle;
145                         this->asInsert = asInsert;
146                         this->blockName = blockName;
147                 }
148
149                 //! Insertion point.
150                 Vector insertionPoint;
151                 //! Scale factor.
152                 double factor;
153                 //! Rotation angle.
154                 double angle;
155                 //! Paste as an insert rather than individual entities.
156                 bool asInsert;
157                 //! Name of the block to create or an empty string to assign a new auto name.
158                 QString blockName;
159 };
160
161 /**
162  * API Class for manipulating entities.
163  * There's no interaction handled in this class.
164  *
165  * All modifications can be undone / redone if the container
166  * is a Drawing.
167  *
168  * This class is connected to an entity container and
169  * can be connected to a graphic view.
170  *
171  * @author Andrew Mustun
172  */
173 class Modification
174 {
175         public:
176                 Modification(EntityContainer & entityContainer,
177                         GraphicView * graphicView = NULL, bool handleUndo = true);
178
179                 void remove();
180                 bool changeAttributes(AttributesData& data);
181
182                 void copy(const Vector & ref, const bool cut);
183         private:
184                 void copyEntity(Entity * e, const Vector & ref, const bool cut);
185         public:
186                 void copyLayers(Entity * e);
187                 void copyBlocks(Entity * e);
188                 void paste(const PasteData & data, Drawing * source = NULL);
189
190                 bool move(MoveData & data);
191                 bool rotate(RotateData & data);
192                 bool scale(ScaleData & data);
193                 bool mirror(MirrorData & data);
194                 bool moveRotate(MoveRotateData & data);
195                 bool rotate2(Rotate2Data & data);
196
197                 bool trim(const Vector & trimCoord, AtomicEntity * trimEntity,
198                         const Vector & limitCoord, Entity * limitEntity,
199                         bool both);
200                 bool trimAmount(const Vector & trimCoord, AtomicEntity * trimEntity,
201                         double dist);
202
203                 bool cut(const Vector& cutCoord, AtomicEntity* cutEntity);
204                 bool stretch(const Vector & firstCorner, const Vector & secondCorner,
205                         const Vector & offset);
206
207                 bool bevel(const Vector & coord1, AtomicEntity * entity1,
208                         const Vector & coord2, AtomicEntity * entity2,
209                         BevelData & data);
210                 bool round(const Vector & coord, const Vector & coord1, AtomicEntity * entity1,
211                         const Vector & coord2, AtomicEntity * entity2, RoundData & data);
212
213                 bool explode();
214                 bool explodeTextIntoLetters();
215                 bool explodeTextIntoLetters(Text * text, QList<Entity *> & addList);
216                 bool moveRef(MoveRefData & data);
217
218                 bool splitPolyline(Polyline & polyline, Entity & e1, Vector v1,
219                         Entity & e2, Vector v2, Polyline ** polyline1, Polyline ** polyline2) const;
220                 Polyline * addPolylineNode(Polyline& polyline,
221                         const AtomicEntity& segment, const Vector& node);
222                 Polyline * deletePolylineNode(Polyline& polyline, const Vector& node);
223                 Polyline * deletePolylineNodesBetween(Polyline & polyline, AtomicEntity & segment,
224                         const Vector& node1, const Vector & node2);
225                 Polyline * polylineTrim(Polyline & polyline,
226                         AtomicEntity & segment1, AtomicEntity & segment2);
227
228         private:
229                 void deselectOriginals(bool remove);
230                 void addNewEntities(QList<Entity *> & addList);
231
232         protected:
233                 EntityContainer * container;
234                 Drawing * graphic;
235                 Document * document;
236                 GraphicView * graphicView;
237                 bool handleUndo;
238 };
239
240 #endif