9 #include "rs_undoable.h"
11 #include "vectorsolutions.h"
17 class RS_EntityContainer;
28 * Base class for an entity (line, arc, circle, ...)
30 * @author Andrew Mustun
32 class RS_Entity: public RS_Undoable
35 RS_Entity(RS_EntityContainer * parent = NULL);
39 virtual void initId();
40 virtual RS_Entity * clone() = 0;
41 virtual void reparent(RS_EntityContainer * parent);
43 virtual RS2::EntityType rtti() const;
44 virtual RS2::UndoableType undoRtti();
45 unsigned long int getId() const;
48 * This method must be overwritten in subclasses and return the
49 * number of <b>atomic</b> entities in this entity.
51 virtual unsigned long int count() = 0;
54 * This method must be overwritten in subclasses and return the
55 * number of <b>atomic</b> entities in this entity including sub containers.
57 virtual unsigned long int countDeep() = 0;
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();
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;
77 * Must be overwritten to return true if an entity type
78 * is a container for other entities (e.g. polyline, group, ...).
80 virtual bool isContainer() const = 0;
83 * Must be overwritten to return true if an entity type
84 * is an atomic entity.
86 virtual bool isAtomic() const = 0;
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();
103 virtual bool isLocked();
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();
122 * Must be overwritten to get the closest endpoint to the
123 * given coordinate for this entity.
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
131 * @return The closest endpoint.
133 virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL) = 0;
136 * Must be overwritten to get the closest coordinate to the
137 * given coordinate which is on this entity.
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.
144 * @return The closest coordinate.
146 virtual Vector getNearestPointOnEntity(const Vector& /*coord*/,
147 bool onEntity = true, double * dist = NULL, RS_Entity ** entity = NULL) = 0;
150 * Must be overwritten to get the (nearest) center point to the
151 * given coordinate for this entity.
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
159 * @return The closest center point.
161 virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL) = 0;
164 * Must be overwritten to get the (nearest) middle point to the
165 * given coordinate for this entity.
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
173 * @return The closest middle point.
175 virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL) = 0;
178 * Must be overwritten to get the nearest point with a given
179 * distance to the endpoint to the given coordinate for this entity.
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
188 * @return The closest point with the given distance to the endpoint.
190 virtual Vector getNearestDist(double distance, const Vector & coord, double * dist = NULL) = 0;
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);
197 * Must be overwritten to get the shortest distance between this
198 * entity and a coordinate.
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.
206 * @sa RS2::ResolveLevel
208 * @return The measured distance between \p coord and the entity.
210 virtual double getDistanceToPoint(const Vector & coord, RS_Entity ** entity = NULL,
211 RS2::ResolveLevel level = RS2::ResolveNone, double solidDist = RS_MAXDOUBLE) = 0;
213 virtual bool isPointOnEntity(const Vector & coord, double tolerance = RS_TOLERANCE);
216 * Implementations must move the entity by the given vector.
218 virtual void move(Vector offset) = 0;
221 * Implementations must rotate the entity by the given angle around
224 virtual void rotate(Vector center, double angle) = 0;
227 * Implementations must scale the entity by the given factors.
229 virtual void scale(Vector center, Vector factor) = 0;
231 virtual void scale(Vector center, double factor);
234 * Implementations must mirror the entity by the given axis.
236 virtual void mirror(Vector axisPoint1, Vector axisPoint2) = 0;
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*/);
243 * Implementations must draw the entity on the given device.
245 virtual void draw(PaintInterface * painter, GraphicView * view, double patternOffset = 0.0) = 0;
247 double getStyleFactor(GraphicView * view);
249 QString * getUserDefVar(QString key);
250 QStringList getAllKeys();
251 void setUserDefVar(QString key, QString val);
252 void delUserDefVar(QString key);
254 friend std::ostream & operator<<(std::ostream & os, RS_Entity & e);
256 /** Recalculates the borders of this entity. */
257 virtual void calculateBorders() = 0;
260 //! Entity's parent entity or NULL is this entity has no parent.
261 RS_EntityContainer * parent;
262 //! minimum coordinates
264 //! maximum coordinates
271 unsigned long int id;
273 //! pen (attributes) for this entity
276 //! auto updating enabled?
280 // Q3Dict<QString> varList;
281 QMultiHash<QString, QString *> varList;