31 } \ |
31 } \ |
32 \ |
32 \ |
33 public: \ |
33 public: \ |
34 virtual LDObject::Type getType() const override \ |
34 virtual LDObject::Type getType() const override \ |
35 { \ |
35 { \ |
36 return LDObject::T; \ |
36 return LDObject::E##T; \ |
37 } \ |
37 } \ |
38 virtual str raw() const override; \ |
38 virtual str raw() const override; \ |
39 virtual void invert() override; |
39 virtual void invert() override; |
40 |
40 |
41 #define LDOBJ_NAME(N) virtual str getTypeName() const override { return #N; } |
41 #define LDOBJ_NAME(N) virtual str getTypeName() const override { return #N; } |
77 |
77 |
78 public: |
78 public: |
79 // Object type codes. Codes are sorted in order of significance. |
79 // Object type codes. Codes are sorted in order of significance. |
80 enum Type |
80 enum Type |
81 { |
81 { |
82 Subfile, // Object represents a sub-file reference |
82 ESubfile, // Object represents a sub-file reference |
83 Quad, // Object represents a quadrilateral |
83 EQuad, // Object represents a quadrilateral |
84 Triangle, // Object represents a triangle |
84 ETriangle, // Object represents a triangle |
85 Line, // Object represents a line |
85 ELine, // Object represents a line |
86 CondLine, // Object represents a conditional line |
86 ECondLine, // Object represents a conditional line |
87 Vertex, // Object is a vertex, LDForge extension object |
87 EVertex, // Object is a vertex, LDForge extension object |
88 BFC, // Object represents a BFC statement |
88 EBFC, // Object represents a BFC statement |
89 Overlay, // Object contains meta-info about an overlay image. |
89 EOverlay, // Object contains meta-info about an overlay image. |
90 Comment, // Object represents a comment |
90 EComment, // Object represents a comment |
91 Error, // Object is the result of failed parsing |
91 EError, // Object is the result of failed parsing |
92 Empty, // Object represents an empty line |
92 EEmpty, // Object represents an empty line |
93 Unidentified, // Object is an uninitialized (SHOULD NEVER HAPPEN) |
93 EUnidentified, // Object is an uninitialized (SHOULD NEVER HAPPEN) |
94 NumTypes // Amount of object types |
94 ENumTypes // Amount of object types |
95 }; |
95 }; |
96 |
96 |
97 LDObject(); |
97 LDObject(); |
98 |
98 |
99 // Makes a copy of this object |
99 // Makes a copy of this object |
107 |
107 |
108 // Type enumerator of this object |
108 // Type enumerator of this object |
109 virtual LDObject::Type getType() const; |
109 virtual LDObject::Type getType() const; |
110 |
110 |
111 // Get a vertex by index |
111 // Get a vertex by index |
112 const vertex& getVertex (int i) const; |
112 const Vertex& getVertex (int i) const; |
113 |
113 |
114 // Type name of this object |
114 // Type name of this object |
115 virtual str getTypeName() const; |
115 virtual str getTypeName() const; |
116 |
116 |
117 // Does this object have a matrix and position? (see LDMatrixObject) |
117 // Does this object have a matrix and position? (see LDMatrixObject) |
125 |
125 |
126 // Does this object have meaning in the part model? |
126 // Does this object have meaning in the part model? |
127 virtual bool isScemantic() const; |
127 virtual bool isScemantic() const; |
128 |
128 |
129 // Moves this object using the given vertex as a movement List |
129 // Moves this object using the given vertex as a movement List |
130 void move (vertex vect); |
130 void move (Vertex vect); |
131 |
131 |
132 // Object after this in the current file |
132 // Object after this in the current file |
133 LDObject* next() const; |
133 LDObject* next() const; |
134 |
134 |
135 // Object prior to this in the current file |
135 // Object prior to this in the current file |
143 |
143 |
144 // Selects this object. |
144 // Selects this object. |
145 void select(); |
145 void select(); |
146 |
146 |
147 // Set a vertex to the given value |
147 // Set a vertex to the given value |
148 void setVertex (int i, const vertex& vert); |
148 void setVertex (int i, const Vertex& vert); |
149 |
149 |
150 // Set a single coordinate of a vertex |
150 // Set a single coordinate of a vertex |
151 void setVertexCoord (int i, Axis ax, double value); |
151 void setVertexCoord (int i, Axis ax, double value); |
152 |
152 |
153 // Swap this object with another. |
153 // Swap this object with another. |
163 virtual int vertices() const; |
163 virtual int vertices() const; |
164 |
164 |
165 // Get type name by enumerator |
165 // Get type name by enumerator |
166 static str typeName (LDObject::Type type); |
166 static str typeName (LDObject::Type type); |
167 |
167 |
168 // Returns a sample object by the given enumerator |
168 // Returns a default-constructed LDObject by the given type |
169 // TODO: Use of this function only really results in hacks, get rid of it! |
|
170 static LDObject* getDefault (const LDObject::Type type); |
169 static LDObject* getDefault (const LDObject::Type type); |
171 |
170 |
172 // TODO: move this to LDDocument? |
171 // TODO: move this to LDDocument? |
173 static void moveObjects (QList<LDObject*> objs, const bool up); |
172 static void moveObjects (QList<LDObject*> objs, const bool up); |
174 |
173 |
204 // For use as coordinates of LDObjects. Keeps count of references. |
203 // For use as coordinates of LDObjects. Keeps count of references. |
205 // ----------------------------------------------------------------------------- |
204 // ----------------------------------------------------------------------------- |
206 class LDSharedVertex |
205 class LDSharedVertex |
207 { |
206 { |
208 public: |
207 public: |
209 inline const vertex& data() const |
208 inline const Vertex& data() const |
210 { |
209 { |
211 return m_data; |
210 return m_data; |
212 } |
211 } |
213 |
212 |
214 inline operator const vertex&() const |
213 inline operator const Vertex&() const |
215 { |
214 { |
216 return m_data; |
215 return m_data; |
217 } |
216 } |
218 |
217 |
219 void addRef (LDObject* a); |
218 void addRef (LDObject* a); |
220 void delRef (LDObject* a); |
219 void delRef (LDObject* a); |
221 |
220 |
222 static LDSharedVertex* getSharedVertex (const vertex& a); |
221 static LDSharedVertex* getSharedVertex (const Vertex& a); |
223 |
222 |
224 protected: |
223 protected: |
225 LDSharedVertex (const vertex& a) : m_data (a) {} |
224 LDSharedVertex (const Vertex& a) : m_data (a) {} |
226 |
225 |
227 private: |
226 private: |
228 QList<LDObject*> m_refs; |
227 QList<LDObject*> m_refs; |
229 vertex m_data; |
228 Vertex m_data; |
230 }; |
229 }; |
231 |
230 |
232 // ============================================================================= |
231 // ============================================================================= |
233 // LDMatrixObject |
232 // LDMatrixObject |
234 // ============================================================================= |
233 // ============================================================================= |
245 // this class distinct in case I get new extension ideas. :) |
244 // this class distinct in case I get new extension ideas. :) |
246 // ============================================================================= |
245 // ============================================================================= |
247 class LDMatrixObject |
246 class LDMatrixObject |
248 { |
247 { |
249 PROPERTY (public, LDObject*, LinkPointer, NO_OPS, STOCK_WRITE) |
248 PROPERTY (public, LDObject*, LinkPointer, NO_OPS, STOCK_WRITE) |
250 PROPERTY (public, matrix, Transform, NO_OPS, CUSTOM_WRITE) |
249 PROPERTY (public, Matrix, Transform, NO_OPS, CUSTOM_WRITE) |
251 |
250 |
252 public: |
251 public: |
253 LDMatrixObject() : |
252 LDMatrixObject() : |
254 m_Position (LDSharedVertex::getSharedVertex (g_origin)) {} |
253 m_Position (LDSharedVertex::getSharedVertex (g_origin)) {} |
255 |
254 |
256 LDMatrixObject (const matrix& transform, const vertex& pos) : |
255 LDMatrixObject (const Matrix& transform, const Vertex& pos) : |
257 m_Transform (transform), |
256 m_Transform (transform), |
258 m_Position (LDSharedVertex::getSharedVertex (pos)) {} |
257 m_Position (LDSharedVertex::getSharedVertex (pos)) {} |
259 |
258 |
260 inline const vertex& getPosition() const |
259 inline const Vertex& getPosition() const |
261 { |
260 { |
262 return m_Position->data(); |
261 return m_Position->data(); |
263 } |
262 } |
264 |
263 |
265 void setCoordinate (const Axis ax, double value) |
264 void setCoordinate (const Axis ax, double value) |
266 { |
265 { |
267 vertex v = getPosition(); |
266 Vertex v = getPosition(); |
268 v[ax] = value; |
267 v[ax] = value; |
269 setPosition (v); |
268 setPosition (v); |
270 } |
269 } |
271 |
270 |
272 void setPosition (const vertex& a); |
271 void setPosition (const Vertex& a); |
273 |
272 |
274 private: |
273 private: |
275 LDSharedVertex* m_Position; |
274 LDSharedVertex* m_Position; |
276 }; |
275 }; |
277 |
276 |