21 |
21 |
22 #include "common.h" |
22 #include "common.h" |
23 #include "types.h" |
23 #include "types.h" |
24 |
24 |
25 #define IMPLEMENT_LDTYPE(T, NUMVERTS) \ |
25 #define IMPLEMENT_LDTYPE(T, NUMVERTS) \ |
26 LD##T (); \ |
26 LD##T () {} \ |
27 virtual ~LD##T (); \ |
27 virtual ~LD##T () {} \ |
28 virtual LDObjectType_e getType () const { \ |
28 virtual LDObjectType_e getType () const { \ |
29 return OBJ_##T; \ |
29 return OBJ_##T; \ |
30 } \ |
30 } \ |
31 virtual str getContents (); \ |
31 virtual str getContents (); \ |
32 virtual LD##T* clone () { \ |
32 virtual LD##T* clone () { \ |
33 return new LD##T (*this); \ |
33 return new LD##T (*this); \ |
34 } \ |
34 } \ |
35 virtual void move (vertex vVector); \ |
35 virtual void move (vertex vVector); \ |
36 virtual short vertices () const { return NUMVERTS; } \ |
36 virtual short vertices () const { return NUMVERTS; } \ |
37 |
37 |
38 #define LDOBJ_COLORED(V) virtual bool isColored () const { return V; } |
38 #define LDOBJ_SETCOLORED(V) virtual bool isColored () const { return V; } |
|
39 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
|
40 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) |
39 |
41 |
40 class QListWidgetItem; |
42 class QListWidgetItem; |
41 class LDSubfile; |
43 class LDSubfile; |
42 |
44 |
43 // ============================================================================= |
45 // ============================================================================= |
147 // zContent contains the contents of the unparsable line. |
149 // zContent contains the contents of the unparsable line. |
148 // ============================================================================= |
150 // ============================================================================= |
149 class LDGibberish : public LDObject { |
151 class LDGibberish : public LDObject { |
150 public: |
152 public: |
151 IMPLEMENT_LDTYPE (Gibberish, 0) |
153 IMPLEMENT_LDTYPE (Gibberish, 0) |
152 LDOBJ_COLORED (false) |
154 LDOBJ_UNCOLORED |
153 |
155 |
154 LDGibberish (str _zContent, str _zReason); |
156 LDGibberish (str _zContent, str _zReason); |
155 |
157 |
156 // Content of this unknown line |
158 // Content of this unknown line |
157 str zContents; |
159 str zContents; |
166 // Represents an empty line in the LDraw code file. |
168 // Represents an empty line in the LDraw code file. |
167 // ============================================================================= |
169 // ============================================================================= |
168 class LDEmpty : public LDObject { |
170 class LDEmpty : public LDObject { |
169 public: |
171 public: |
170 IMPLEMENT_LDTYPE (Empty, 0) |
172 IMPLEMENT_LDTYPE (Empty, 0) |
171 LDOBJ_COLORED (false) |
173 LDOBJ_UNCOLORED |
172 }; |
174 }; |
173 |
175 |
174 // ============================================================================= |
176 // ============================================================================= |
175 // LDComment |
177 // LDComment |
176 // |
178 // |
178 // the text of the comment. |
180 // the text of the comment. |
179 // ============================================================================= |
181 // ============================================================================= |
180 class LDComment : public LDObject { |
182 class LDComment : public LDObject { |
181 public: |
183 public: |
182 IMPLEMENT_LDTYPE (Comment, 0) |
184 IMPLEMENT_LDTYPE (Comment, 0) |
183 LDOBJ_COLORED (false) |
185 LDOBJ_UNCOLORED |
184 |
186 |
185 LDComment (str zText) : zText (zText) {} |
187 LDComment (str zText) : text (zText) {} |
186 |
188 |
187 str zText; // The text of this comment |
189 str text; // The text of this comment |
188 }; |
190 }; |
189 |
191 |
190 // ============================================================================= |
192 // ============================================================================= |
191 // LDBFC |
193 // LDBFC |
192 // |
194 // |
204 InvertNext, // Winding is inverted for next object (0 BFC INVERTNEXT) |
206 InvertNext, // Winding is inverted for next object (0 BFC INVERTNEXT) |
205 NumStatements |
207 NumStatements |
206 }; |
208 }; |
207 |
209 |
208 IMPLEMENT_LDTYPE (BFC, 0) |
210 IMPLEMENT_LDTYPE (BFC, 0) |
209 LDOBJ_COLORED (false) |
211 LDOBJ_UNCOLORED |
210 |
212 |
211 LDBFC (const LDBFC::Type eType) : eStatement (eType) {} |
213 LDBFC (const LDBFC::Type eType) : type (eType) {} |
212 |
214 |
213 // Statement strings |
215 // Statement strings |
214 static const char* saStatements[]; |
216 static const char* statements[]; |
215 |
217 |
216 Type eStatement; |
218 Type type; |
217 }; |
219 }; |
218 |
220 |
219 // ============================================================================= |
221 // ============================================================================= |
220 // LDSubfile |
222 // LDSubfile |
221 // |
223 // |
222 // Represents a single code-1 subfile reference. |
224 // Represents a single code-1 subfile reference. |
223 // ============================================================================= |
225 // ============================================================================= |
224 class LDSubfile : public LDObject { |
226 class LDSubfile : public LDObject { |
225 public: |
227 public: |
226 IMPLEMENT_LDTYPE (Subfile, 0) |
228 IMPLEMENT_LDTYPE (Subfile, 0) |
227 LDOBJ_COLORED (true) |
229 LDOBJ_COLORED |
228 |
230 |
229 vertex vPosition; // Position of the subpart |
231 vertex vPosition; // Position of the subpart (FIXME: should get rid of this) |
230 matrix<3> mMatrix; // Transformation matrix for the subpart |
232 matrix<3> mMatrix; // Transformation matrix for the subpart |
231 str zFileName; // Filename of the subpart |
233 str zFileName; // Filename of the subpart |
232 OpenFile* pFile; // Pointer to opened file for this subfile. null if unopened. |
234 OpenFile* pFile; // Pointer to opened file for this subfile. null if unopened. |
233 |
235 |
234 // Gets the inlined contents of this subfile. |
236 // Inlines this subfile. Note that return type is an array of heap-allocated |
|
237 // LDObject-clones, they must be deleted one way or another. |
235 std::vector<LDObject*> inlineContents (bool bDeepInline, bool bCache); |
238 std::vector<LDObject*> inlineContents (bool bDeepInline, bool bCache); |
236 }; |
239 }; |
237 |
240 |
238 // ============================================================================= |
241 // ============================================================================= |
239 // LDLine |
242 // LDLine |
243 // set. |
246 // set. |
244 // ============================================================================= |
247 // ============================================================================= |
245 class LDLine : public LDObject { |
248 class LDLine : public LDObject { |
246 public: |
249 public: |
247 IMPLEMENT_LDTYPE (Line, 2) |
250 IMPLEMENT_LDTYPE (Line, 2) |
248 LDOBJ_COLORED (true) |
251 LDOBJ_COLORED |
249 |
252 |
250 LDLine (vertex v1, vertex v2); |
253 LDLine (vertex v1, vertex v2); |
251 }; |
254 }; |
252 |
255 |
253 // ============================================================================= |
256 // ============================================================================= |
257 // inherited from LDLine, c0 and c1 are the control points of this line. |
260 // inherited from LDLine, c0 and c1 are the control points of this line. |
258 // ============================================================================= |
261 // ============================================================================= |
259 class LDCondLine : public LDLine { |
262 class LDCondLine : public LDLine { |
260 public: |
263 public: |
261 IMPLEMENT_LDTYPE (CondLine, 4) |
264 IMPLEMENT_LDTYPE (CondLine, 4) |
262 LDOBJ_COLORED (true) |
265 LDOBJ_COLORED |
263 }; |
266 }; |
264 |
267 |
265 // ============================================================================= |
268 // ============================================================================= |
266 // LDTriangle |
269 // LDTriangle |
267 // |
270 // |
270 // triangle is colored with. |
273 // triangle is colored with. |
271 // ============================================================================= |
274 // ============================================================================= |
272 class LDTriangle : public LDObject { |
275 class LDTriangle : public LDObject { |
273 public: |
276 public: |
274 IMPLEMENT_LDTYPE (Triangle, 3) |
277 IMPLEMENT_LDTYPE (Triangle, 3) |
275 LDOBJ_COLORED (true) |
278 LDOBJ_COLORED |
276 |
279 |
277 LDTriangle (vertex _v0, vertex _v1, vertex _v2) { |
280 LDTriangle (vertex _v0, vertex _v1, vertex _v2) { |
278 vaCoords[0] = _v0; |
281 vaCoords[0] = _v0; |
279 vaCoords[1] = _v1; |
282 vaCoords[1] = _v1; |
280 vaCoords[2] = _v2; |
283 vaCoords[2] = _v2; |
288 // of the quad, dColor is the color used for the quad. |
291 // of the quad, dColor is the color used for the quad. |
289 // ============================================================================= |
292 // ============================================================================= |
290 class LDQuad : public LDObject { |
293 class LDQuad : public LDObject { |
291 public: |
294 public: |
292 IMPLEMENT_LDTYPE (Quad, 4) |
295 IMPLEMENT_LDTYPE (Quad, 4) |
293 LDOBJ_COLORED (true) |
296 LDOBJ_COLORED |
294 |
297 |
295 // Split this quad into two triangles |
298 // Split this quad into two triangles (note: heap-allocated) |
296 vector<LDTriangle*> splitToTriangles (); |
299 vector<LDTriangle*> splitToTriangles (); |
297 }; |
300 }; |
298 |
301 |
299 // ============================================================================= |
302 // ============================================================================= |
300 // LDVertex |
303 // LDVertex |
305 // finished parts. |
308 // finished parts. |
306 // ============================================================================= |
309 // ============================================================================= |
307 class LDVertex : public LDObject { |
310 class LDVertex : public LDObject { |
308 public: |
311 public: |
309 IMPLEMENT_LDTYPE (Vertex, 0) // TODO: move vPosition to vaCoords[0] |
312 IMPLEMENT_LDTYPE (Vertex, 0) // TODO: move vPosition to vaCoords[0] |
310 LDOBJ_COLORED (true) |
313 LDOBJ_COLORED |
311 |
314 |
312 vertex vPosition; |
315 vertex vPosition; |
313 }; |
316 }; |
314 |
317 |
315 // ============================================================================= |
318 // ============================================================================= |
344 LDRadial (LDRadial::Type eRadialType, vertex vPosition, matrix<3> mMatrix, |
347 LDRadial (LDRadial::Type eRadialType, vertex vPosition, matrix<3> mMatrix, |
345 short dDivisions, short dSegments, short dRingNum) : |
348 short dDivisions, short dSegments, short dRingNum) : |
346 eRadialType (eRadialType), vPosition (vPosition), mMatrix (mMatrix), |
349 eRadialType (eRadialType), vPosition (vPosition), mMatrix (mMatrix), |
347 dDivisions (dDivisions), dSegments (dSegments), dRingNum (dRingNum) {} |
350 dDivisions (dDivisions), dSegments (dSegments), dRingNum (dRingNum) {} |
348 |
351 |
|
352 // Returns a set of objects that provide the equivalent of this radial. |
|
353 // Note: objects are heap-allocated. |
|
354 std::vector<LDObject*> decompose (bool bTransform); |
|
355 |
|
356 // Compose a file name for this radial. |
|
357 str makeFileName (); |
|
358 |
349 char const* radialTypeName (); |
359 char const* radialTypeName (); |
350 std::vector<LDObject*> decompose (bool bTransform); |
|
351 str makeFileName (); |
|
352 |
|
353 static char const* radialTypeName (const LDRadial::Type eType); |
360 static char const* radialTypeName (const LDRadial::Type eType); |
354 }; |
361 }; |
355 |
362 |
356 // ============================================================================= |
363 // ============================================================================= |
357 // Object type names. Pass the return value of getType as the index to get a |
364 // Object type names. Pass the return value of getType as the index to get a |