]> Shamusworld >> Repos - architektonas/blob - src/base/rs_entity.h
Changed RS_Graphic to Drawing; this is less confusing as a drawing is
[architektonas] / src / base / rs_entity.h
1 #ifndef RS_ENTITY_H
2 #define RS_ENTITY_H
3
4 #include <QtCore>
5 #include "rs.h"
6 #include "rs_layer.h"
7 #include "rs_math.h"
8 #include "rs_pen.h"
9 #include "rs_undoable.h"
10 #include "vector.h"
11 #include "vectorsolutions.h"
12
13 class RS_Arc;
14 class RS_Block;
15 class RS_Circle;
16 class RS_Document;
17 class RS_EntityContainer;
18 class Drawing;
19 class RS_GraphicView;
20 class RS_Insert;
21 class RS_Line;
22 class RS_Point;
23 class RS_Polyline;
24 class RS_Text;
25 class PaintInterface;
26
27 /**
28  * Base class for an entity (line, arc, circle, ...)
29  *
30  * @author Andrew Mustun
31  */
32 class RS_Entity: public RS_Undoable
33 {
34         public:
35                 RS_Entity(RS_EntityContainer * parent = NULL);
36                 virtual ~RS_Entity();
37
38                 void init();
39                 virtual void initId();
40                 virtual RS_Entity * clone() = 0;
41                 virtual void reparent(RS_EntityContainer * parent);
42                 void resetBorders();
43                 virtual RS2::EntityType rtti() const;
44                 virtual RS2::UndoableType undoRtti();
45                 unsigned long int getId() const;
46
47                 /**
48                 * This method must be overwritten in subclasses and return the
49                 * number of <b>atomic</b> entities in this entity.
50                 */
51                 virtual unsigned long int count() = 0;
52
53                 /**
54                 * This method must be overwritten in subclasses and return the
55                 * number of <b>atomic</b> entities in this entity including sub containers.
56                 */
57                 virtual unsigned long int countDeep() = 0;
58
59                 virtual double getLength();
60                 RS_EntityContainer * getParent() const;
61                 void setParent(RS_EntityContainer * p);
62                 Drawing * getGraphic();
63                 RS_Block * getBlock();
64                 RS_Insert * getInsert();
65                 RS_Entity * getBlockOrInsert();
66                 RS_Document * getDocument();
67
68                 void setLayer(const QString & name);
69                 void setLayer(RS_Layer * l);
70                 void setLayerToActive();
71                 RS_Layer * getLayer(bool resolve = true) const;
72                 void setPen(const RS_Pen & pen);
73                 void setPenToActive();
74                 RS_Pen getPen(bool resolve = true) const;
75
76                 /**
77                 * Must be overwritten to return true if an entity type
78                 * is a container for other entities (e.g. polyline, group, ...).
79                 */
80                 virtual bool isContainer() const = 0;
81
82                 /**
83                 * Must be overwritten to return true if an entity type
84                 * is an atomic entity.
85                 */
86                 virtual bool isAtomic() const = 0;
87
88                 virtual bool isEdge() const;
89                 virtual bool isDocument() const;
90                 virtual bool setSelected(bool select);
91                 virtual bool toggleSelected();
92                 virtual bool isSelected() const;
93                 virtual bool isParentSelected();
94                 virtual bool isProcessed() const;
95                 virtual void setProcessed(bool on);
96                 virtual bool isInWindow(Vector v1, Vector v2);
97                 virtual bool hasEndpointsWithinWindow(Vector /*v1*/, Vector /*v2*/);
98                 virtual bool isVisible();
99                 virtual void setVisible(bool v);
100                 virtual void setHighlighted(bool on);
101                 virtual bool isHighlighted();
102
103                 virtual bool isLocked();
104
105                 virtual void undoStateChanged(bool undone);
106                 virtual bool isUndone() const;
107                 virtual void update();
108                 virtual void setUpdateEnabled(bool on);
109                 Vector getMin() const;
110                 Vector getMax() const;
111                 Vector getSize() const;
112                 void addGraphicVariable(const QString & key, double val, int code);
113                 void addGraphicVariable(const QString & key, int val, int code);
114                 void addGraphicVariable(const QString & key, const QString & val, int code);
115                 double getGraphicVariableDouble(const QString & key, double def);
116                 int getGraphicVariableInt(const QString & key, int def);
117                 QString getGraphicVariableString(const QString & key, const QString & def);
118                 RS2::Unit getGraphicUnit();
119                 virtual VectorSolutions getRefPoints();
120
121                 /**
122                 * Must be overwritten to get the closest endpoint to the
123                 * given coordinate for this entity.
124                 *
125                 * @param coord Coordinate (typically a mouse coordinate)
126                 * @param dist Pointer to a value which will contain the measured
127                 * distance between 'coord' and the closest endpoint. The passed
128                 * pointer can also be NULL in which case the distance will be
129                 * lost.
130                 *
131                 * @return The closest endpoint.
132                 */
133                 virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL) = 0;
134
135                 /**
136                 * Must be overwritten to get the closest coordinate to the
137                 * given coordinate which is on this entity.
138                 *
139                 * @param coord Coordinate (typically a mouse coordinate)
140                 * @param dist Pointer to a value which will contain the measured
141                 * distance between \p coord and the point. The passed pointer can
142                 * also be \p NULL in which case the distance will be lost.
143                 *
144                 * @return The closest coordinate.
145                 */
146                 virtual Vector getNearestPointOnEntity(const Vector& /*coord*/,
147                         bool onEntity = true, double * dist = NULL, RS_Entity ** entity = NULL) = 0;
148
149                 /**
150                 * Must be overwritten to get the (nearest) center point to the
151                 * given coordinate for this entity.
152                 *
153                 * @param coord Coordinate (typically a mouse coordinate)
154                 * @param dist Pointer to a value which will contain the measured
155                 * distance between 'coord' and the closest center point. The passed
156                 * pointer can also be NULL in which case the distance will be
157                 * lost.
158                 *
159                 * @return The closest center point.
160                 */
161                 virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL) = 0;
162
163                 /**
164                 * Must be overwritten to get the (nearest) middle point to the
165                 * given coordinate for this entity.
166                 *
167                 * @param coord Coordinate (typically a mouse coordinate)
168                 * @param dist Pointer to a value which will contain the measured
169                 * distance between 'coord' and the closest middle point. The passed
170                 * pointer can also be NULL in which case the distance will be
171                 * lost.
172                 *
173                 * @return The closest middle point.
174                 */
175                 virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL) = 0;
176
177                 /**
178                 * Must be overwritten to get the nearest point with a given
179                 * distance to the endpoint to the given coordinate for this entity.
180                 *
181                 * @param distance Distance to endpoint.
182                 * @param coord Coordinate (typically a mouse coordinate)
183                 * @param dist Pointer to a value which will contain the measured
184                 * distance between 'coord' and the closest point. The passed
185                 * pointer can also be NULL in which case the distance will be
186                 * lost.
187                 *
188                 * @return The closest point with the given distance to the endpoint.
189                 */
190                 virtual Vector getNearestDist(double distance, const Vector & coord, double * dist = NULL) = 0;
191
192                 virtual Vector getNearestDist(double /*distance*/, bool /*startp*/);
193                 virtual Vector getNearestRef(const Vector & coord, double * dist = NULL);
194                 virtual Vector getNearestSelectedRef(const Vector & coord, double * dist = NULL);
195
196                 /**
197                 * Must be overwritten to get the shortest distance between this
198                 * entity and a coordinate.
199                 *
200                 * @param coord Coordinate (typically a mouse coordinate)
201                 * @param entity Pointer which will contain the (sub-)entity which is
202                 *               closest to the given point or NULL if the caller is not
203                 *               interested in this information.
204                 * @param level The resolve level.
205                 *
206                 * @sa RS2::ResolveLevel
207                 *
208                 * @return The measured distance between \p coord and the entity.
209                 */
210                 virtual double getDistanceToPoint(const Vector & coord, RS_Entity ** entity = NULL,
211                          RS2::ResolveLevel level = RS2::ResolveNone, double solidDist = RS_MAXDOUBLE) = 0;
212
213                 virtual bool isPointOnEntity(const Vector & coord, double tolerance = RS_TOLERANCE);
214
215                 /**
216                 * Implementations must move the entity by the given vector.
217                 */
218                 virtual void move(Vector offset) = 0;
219
220                 /**
221                 * Implementations must rotate the entity by the given angle around
222                 * the given center.
223                 */
224                 virtual void rotate(Vector center, double angle) = 0;
225
226                 /**
227                 * Implementations must scale the entity by the given factors.
228                 */
229                 virtual void scale(Vector center, Vector factor) = 0;
230
231                 virtual void scale(Vector center, double factor);
232
233                 /**
234                 * Implementations must mirror the entity by the given axis.
235                 */
236                 virtual void mirror(Vector axisPoint1, Vector axisPoint2) = 0;
237
238                 virtual void stretch(Vector firstCorner, Vector secondCorner, Vector offset);
239                 virtual void moveRef(const Vector & /*ref*/, const Vector & /*offset*/);
240                 virtual void moveSelectedRef(const Vector & /*ref*/, const Vector & /*offset*/);
241
242                 /**
243                 * Implementations must draw the entity on the given device.
244                 */
245 //              virtual void draw(RS_Painter* painter, RS_GraphicView* view,
246                 virtual void draw(PaintInterface * painter, RS_GraphicView * view, double patternOffset = 0.0) = 0;
247
248                 double getStyleFactor(RS_GraphicView * view);
249
250                 QString * getUserDefVar(QString key);
251                 QStringList getAllKeys();
252                 void setUserDefVar(QString key, QString val);
253                 void delUserDefVar(QString key);
254
255                 friend std::ostream & operator<<(std::ostream & os, RS_Entity & e);
256
257                 /** Recalculates the borders of this entity. */
258                 virtual void calculateBorders() = 0;
259
260         protected:
261                 //! Entity's parent entity or NULL is this entity has no parent.
262                 RS_EntityContainer * parent;
263                 //! minimum coordinates
264                 Vector minV;
265                 //! maximum coordinates
266                 Vector maxV;
267
268                 //! Pointer to layer
269                 RS_Layer * layer;
270
271                 //! Entity id
272                 unsigned long int id;
273
274                 //! pen (attributes) for this entity
275                 RS_Pen pen;
276
277                 //! auto updating enabled?
278                 bool updateEnabled;
279
280         private:
281 //              Q3Dict<QString> varList;
282                 QMultiHash<QString, QString *> varList;
283 };
284
285 #endif