]> Shamusworld >> Repos - architektonas/blob - src/base/rs_modification.h
Refactoring: Moved RS_GraphicView to GraphicView.
[architektonas] / src / base / rs_modification.h
1 #ifndef RS_MODIFICATION_H
2 #define RS_MODIFICATION_H
3
4 #include "rs_entitycontainer.h"
5 #include "graphicview.h"
6 #include "rs_line.h"
7
8 /**
9  * Holds the data needed for move modifications.
10  */
11 class RS_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 RS_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 RS_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 RS_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 RS_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 RS_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 RS_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 RS_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 RS_MoveRefData
113 {
114         public:
115                 Vector ref;
116                 Vector offset;
117 };
118
119 /**
120  * Holds the data needed for changing attributes.
121  */
122 class RS_AttributesData
123 {
124         public:
125                 QString layer;
126                 RS_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 RS_PasteData
137 {
138         public:
139                 RS_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 RS_Modification
174 {
175         public:
176                 RS_Modification(RS_EntityContainer & entityContainer,
177                         GraphicView * graphicView = NULL, bool handleUndo = true);
178
179                 void remove();
180                 bool changeAttributes(RS_AttributesData& data);
181
182                 void copy(const Vector & ref, const bool cut);
183         private:
184                 void copyEntity(RS_Entity * e, const Vector & ref, const bool cut);
185         public:
186                 void copyLayers(RS_Entity * e);
187                 void copyBlocks(RS_Entity * e);
188                 void paste(const RS_PasteData & data, Drawing * source = NULL);
189
190                 bool move(RS_MoveData & data);
191                 bool rotate(RS_RotateData & data);
192                 bool scale(RS_ScaleData & data);
193                 bool mirror(RS_MirrorData & data);
194                 bool moveRotate(RS_MoveRotateData & data);
195                 bool rotate2(RS_Rotate2Data & data);
196
197                 bool trim(const Vector & trimCoord, RS_AtomicEntity * trimEntity,
198                         const Vector & limitCoord, RS_Entity * limitEntity,
199                         bool both);
200                 bool trimAmount(const Vector & trimCoord, RS_AtomicEntity * trimEntity,
201                         double dist);
202
203                 bool cut(const Vector& cutCoord, RS_AtomicEntity* cutEntity);
204                 bool stretch(const Vector & firstCorner, const Vector & secondCorner,
205                         const Vector & offset);
206
207                 bool bevel(const Vector & coord1, RS_AtomicEntity * entity1,
208                         const Vector & coord2, RS_AtomicEntity * entity2,
209                         RS_BevelData & data);
210                 bool round(const Vector & coord, const Vector & coord1, RS_AtomicEntity * entity1,
211                         const Vector & coord2, RS_AtomicEntity * entity2, RS_RoundData & data);
212
213                 bool explode();
214                 bool explodeTextIntoLetters();
215 //              bool explodeTextIntoLetters(RS_Text* text, Q3PtrList<RS_Entity>& addList);
216                 bool explodeTextIntoLetters(RS_Text * text, QList<RS_Entity *> & addList);
217                 bool moveRef(RS_MoveRefData & data);
218
219                 bool splitPolyline(RS_Polyline & polyline, RS_Entity & e1, Vector v1,
220                         RS_Entity & e2, Vector v2, RS_Polyline ** polyline1, RS_Polyline ** polyline2) const;
221                 RS_Polyline * addPolylineNode(RS_Polyline& polyline,
222                         const RS_AtomicEntity& segment, const Vector& node);
223                 RS_Polyline * deletePolylineNode(RS_Polyline& polyline, const Vector& node);
224                 RS_Polyline * deletePolylineNodesBetween(RS_Polyline & polyline, RS_AtomicEntity & segment,
225                         const Vector& node1, const Vector & node2);
226                 RS_Polyline * polylineTrim(RS_Polyline & polyline,
227                         RS_AtomicEntity & segment1, RS_AtomicEntity & segment2);
228
229         private:
230                 void deselectOriginals(bool remove);
231 //              void addNewEntities(Q3PtrList<RS_Entity>& addList);
232                 void addNewEntities(QList<RS_Entity *> & addList);
233
234         protected:
235                 RS_EntityContainer * container;
236                 Drawing * graphic;
237                 RS_Document * document;
238                 GraphicView * graphicView;
239                 bool handleUndo;
240 };
241
242 #endif