]> Shamusworld >> Repos - architektonas/blob - src/base/rs_modification.h
Initial import
[architektonas] / src / base / rs_modification.h
1 /****************************************************************************
2 ** $Id: rs_modification.h 1946 2004-12-24 19:27:43Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #ifndef RS_MODIFICATION_H
28 #define RS_MODIFICATION_H
29
30 #include "rs_entitycontainer.h"
31 #include "rs_graphicview.h"
32 #include "rs_line.h"
33
34 /**
35  * Holds the data needed for move modifications.
36  */
37 class RS_MoveData
38 {
39         public:
40                 int number;
41                 bool useCurrentAttributes;
42                 bool useCurrentLayer;
43                 Vector offset;
44 };
45
46 /**
47  * Holds the data needed for rotation modifications.
48  */
49 class RS_RotateData
50 {
51         public:
52                 int number;
53                 bool useCurrentAttributes;
54                 bool useCurrentLayer;
55                 Vector center;
56                 double angle;
57 };
58
59 /**
60  * Holds the data needed for scale modifications.
61  */
62 class RS_ScaleData
63 {
64         public:
65                 int number;
66                 bool useCurrentAttributes;
67                 bool useCurrentLayer;
68                 Vector referencePoint;
69                 double factor;
70 };
71
72 /**
73  * Holds the data needed for mirror modifications.
74  */
75 class RS_MirrorData
76 {
77         public:
78                 bool copy;
79                 bool useCurrentAttributes;
80                 bool useCurrentLayer;
81                 Vector axisPoint1;
82                 Vector axisPoint2;
83 };
84
85 /**
86  * Holds the data needed for move/rotate modifications.
87  */
88 class RS_MoveRotateData
89 {
90         public:
91                 int number;
92                 bool useCurrentAttributes;
93                 bool useCurrentLayer;
94                 Vector referencePoint;
95                 Vector offset;
96                 double angle;
97 };
98
99 /**
100  * Holds the data needed for rotation around two centers modifications.
101  */
102 class RS_Rotate2Data
103 {
104         public:
105                 int number;
106                 bool useCurrentAttributes;
107                 bool useCurrentLayer;
108                 Vector center1;
109                 Vector center2;
110                 double angle1;
111                 double angle2;
112 };
113
114 /**
115  * Holds the data needed for beveling modifications.
116  */
117 class RS_BevelData
118 {
119         public:
120                 double length1;
121                 double length2;
122                 bool trim;
123 };
124
125 /**
126  * Holds the data needed for rounding modifications.
127  */
128 class RS_RoundData
129 {
130         public:
131                 double radius;
132                 bool trim;
133 };
134
135 /**
136  * Holds the data needed for moving reference points.
137  */
138 class RS_MoveRefData
139 {
140         public:
141                 Vector ref;
142                 Vector offset;
143 };
144
145 /**
146  * Holds the data needed for changing attributes.
147  */
148 class RS_AttributesData
149 {
150         public:
151                 QString layer;
152                 RS_Pen pen;
153                 bool changeLayer;
154                 bool changeColor;
155                 bool changeLineType;
156                 bool changeWidth;
157 };
158
159 /**
160  * Holds the data needed for pasting.
161  */
162 class RS_PasteData
163 {
164         public:
165                 RS_PasteData(Vector insertionPoint, double factor, double angle,
166                         bool asInsert, const QString & blockName)
167                 {
168                         this->insertionPoint = insertionPoint;
169                         this->factor = factor;
170                         this->angle = angle;
171                         this->asInsert = asInsert;
172                         this->blockName = blockName;
173                 }
174
175                 //! Insertion point.
176                 Vector insertionPoint;
177                 //! Scale factor.
178                 double factor;
179                 //! Rotation angle.
180                 double angle;
181                 //! Paste as an insert rather than individual entities.
182                 bool asInsert;
183                 //! Name of the block to create or an empty string to assign a new auto name.
184                 QString blockName;
185 };
186
187 /**
188  * API Class for manipulating entities.
189  * There's no interaction handled in this class.
190  *
191  * All modifications can be undone / redone if the container
192  * is a RS_Graphic.
193  *
194  * This class is connected to an entity container and
195  * can be connected to a graphic view.
196  *
197  * @author Andrew Mustun
198  */
199 class RS_Modification
200 {
201         public:
202                 RS_Modification(RS_EntityContainer & entityContainer,
203                         RS_GraphicView * graphicView = NULL, bool handleUndo = true);
204
205                 void remove();
206                 bool changeAttributes(RS_AttributesData& data);
207
208                 void copy(const Vector & ref, const bool cut);
209         private:
210                 void copyEntity(RS_Entity * e, const Vector & ref, const bool cut);
211         public:
212                 void copyLayers(RS_Entity * e);
213                 void copyBlocks(RS_Entity * e);
214                 void paste(const RS_PasteData & data, RS_Graphic * source = NULL);
215
216                 bool move(RS_MoveData & data);
217                 bool rotate(RS_RotateData & data);
218                 bool scale(RS_ScaleData & data);
219                 bool mirror(RS_MirrorData & data);
220                 bool moveRotate(RS_MoveRotateData & data);
221                 bool rotate2(RS_Rotate2Data & data);
222
223                 bool trim(const Vector & trimCoord, RS_AtomicEntity * trimEntity,
224                         const Vector & limitCoord, RS_Entity * limitEntity,
225                         bool both);
226                 bool trimAmount(const Vector & trimCoord, RS_AtomicEntity * trimEntity,
227                         double dist);
228
229                 bool cut(const Vector& cutCoord, RS_AtomicEntity* cutEntity);
230                 bool stretch(const Vector & firstCorner, const Vector & secondCorner,
231                         const Vector & offset);
232
233                 bool bevel(const Vector & coord1, RS_AtomicEntity * entity1,
234                         const Vector & coord2, RS_AtomicEntity * entity2,
235                         RS_BevelData & data);
236                 bool round(const Vector & coord, const Vector & coord1, RS_AtomicEntity * entity1,
237                         const Vector & coord2, RS_AtomicEntity * entity2, RS_RoundData & data);
238
239                 bool explode();
240                 bool explodeTextIntoLetters();
241 //              bool explodeTextIntoLetters(RS_Text* text, Q3PtrList<RS_Entity>& addList);
242                 bool explodeTextIntoLetters(RS_Text * text, QList<RS_Entity *> & addList);
243                 bool moveRef(RS_MoveRefData & data);
244
245                 bool splitPolyline(RS_Polyline & polyline, RS_Entity & e1, Vector v1,
246                         RS_Entity & e2, Vector v2, RS_Polyline ** polyline1, RS_Polyline ** polyline2) const;
247                 RS_Polyline * addPolylineNode(RS_Polyline& polyline,
248                         const RS_AtomicEntity& segment, const Vector& node);
249                 RS_Polyline * deletePolylineNode(RS_Polyline& polyline, const Vector& node);
250                 RS_Polyline * deletePolylineNodesBetween(RS_Polyline & polyline, RS_AtomicEntity & segment,
251                         const Vector& node1, const Vector & node2);
252                 RS_Polyline * polylineTrim(RS_Polyline & polyline,
253                         RS_AtomicEntity & segment1, RS_AtomicEntity & segment2);
254
255         private:
256                 void deselectOriginals(bool remove);
257 //              void addNewEntities(Q3PtrList<RS_Entity>& addList);
258                 void addNewEntities(QList<RS_Entity *> & addList);
259
260         protected:
261                 RS_EntityContainer * container;
262                 RS_Graphic * graphic;
263                 RS_Document * document;
264                 RS_GraphicView * graphicView;
265                 bool handleUndo;
266 };
267
268 #endif