src/ldtypes.h

changeset 211
8d35e631bef3
parent 192
c414924a647c
child 214
28e0b37156be
equal deleted inserted replaced
210:58a3cbb49374 211:8d35e631bef3
22 #include "common.h" 22 #include "common.h"
23 #include "types.h" 23 #include "types.h"
24 24
25 class HistoryEntry; 25 class HistoryEntry;
26 26
27 #define IMPLEMENT_LDTYPE(T, NUMVERTS) \ 27 #define LDOBJ(T) \
28 LD##T () {} \ 28 LD##T () {} \
29 virtual ~LD##T () {} \ 29 virtual ~LD##T () {} \
30 virtual LDObject::Type getType () const { \ 30 virtual LDObject::Type getType () const { \
31 return LDObject::T; \ 31 return LDObject::T; \
32 } \ 32 } \
33 virtual str getContents (); \ 33 virtual str getContents (); \
34 virtual LD##T* clone () { \ 34 virtual LD##T* clone () { \
35 return new LD##T (*this); \ 35 return new LD##T (*this); \
36 } \ 36 } \
37 virtual void move (vertex vVector); \ 37 virtual void move (vertex vVector); \
38 virtual short vertices () const { return NUMVERTS; } \
39 virtual HistoryEntry* invert (); 38 virtual HistoryEntry* invert ();
40 39
40 #define LDOBJ_VERTICES(V) virtual short vertices () const { return V; }
41 #define LDOBJ_SETCOLORED(V) virtual bool isColored () const { return V; } 41 #define LDOBJ_SETCOLORED(V) virtual bool isColored () const { return V; }
42 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) 42 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true)
43 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) 43 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false)
44 44
45 #define LDOBJ_CUSTOM_SCHEMANTIC virtual bool isSchemantic () const 45 #define LDOBJ_CUSTOM_SCHEMANTIC virtual bool isSchemantic () const
46 #define LDOBJ_SCHEMANTIC LDOBJ_CUSTOM_SCHEMANTIC { return true; } 46 #define LDOBJ_SCHEMANTIC LDOBJ_CUSTOM_SCHEMANTIC { return true; }
47 #define LDOBJ_NON_SCHEMANTIC LDOBJ_CUSTOM_SCHEMANTIC { return false; } 47 #define LDOBJ_NON_SCHEMANTIC LDOBJ_CUSTOM_SCHEMANTIC { return false; }
48 48
49 #define LDOBJ_SETMATRIX(V) virtual bool hasMatrix () const { return V; }
50 #define LDOBJ_HAS_MATRIX LDOBJ_SETMATRIX (true)
51 #define LDOBJ_NO_MATRIX LDOBJ_SETMATRIX (false)
52
49 class QListWidgetItem; 53 class QListWidgetItem;
50 class LDSubfile; 54 class LDSubfile;
55
56 // =============================================================================
57 // LDMatrixObject
58 //
59 // Common code for objects with matrices
60 // =============================================================================
61 class LDMatrixObject {
62 public:
63 LDMatrixObject () {}
64 LDMatrixObject (const matrix& transform, const vertex& pos) :
65 transform (transform), pos (pos) {}
66
67 matrix transform;
68 vertex pos;
69 };
51 70
52 // ============================================================================= 71 // =============================================================================
53 // LDObject 72 // LDObject
54 // 73 //
55 // Base class object for all LD* types. Each LDObject represents a single line 74 // Base class object for all LD* types. Each LDObject represents a single line
140 159
141 // Object list entry for this object 160 // Object list entry for this object
142 QListWidgetItem* qObjListEntry; 161 QListWidgetItem* qObjListEntry;
143 162
144 bool hidden () const { return m_hidden; } 163 bool hidden () const { return m_hidden; }
164 virtual bool hasMatrix () const { return false; }
145 virtual HistoryEntry* invert (); 165 virtual HistoryEntry* invert ();
146 LDObject* next () const; 166 LDObject* next () const;
147 LDObject* prev () const; 167 LDObject* prev () const;
148 void setHidden (const bool hidden) { m_hidden = hidden; } 168 void setHidden (const bool hidden) { m_hidden = hidden; }
149 bool selected () const { return m_selected; } 169 bool selected () const { return m_selected; }
162 // allowing garbage lines be debugged and corrected within LDForge. The member 182 // allowing garbage lines be debugged and corrected within LDForge. The member
163 // zContent contains the contents of the unparsable line. 183 // zContent contains the contents of the unparsable line.
164 // ============================================================================= 184 // =============================================================================
165 class LDGibberish : public LDObject { 185 class LDGibberish : public LDObject {
166 public: 186 public:
167 IMPLEMENT_LDTYPE (Gibberish, 0) 187 LDOBJ (Gibberish)
188 LDOBJ_VERTICES (0)
168 LDOBJ_UNCOLORED 189 LDOBJ_UNCOLORED
169 LDOBJ_SCHEMANTIC 190 LDOBJ_SCHEMANTIC
191 LDOBJ_NO_MATRIX
170 192
171 LDGibberish (str _zContent, str _zReason); 193 LDGibberish (str _zContent, str _zReason);
172 194
173 // Content of this unknown line 195 // Content of this unknown line
174 str contents; 196 str contents;
182 // 204 //
183 // Represents an empty line in the LDraw code file. 205 // Represents an empty line in the LDraw code file.
184 // ============================================================================= 206 // =============================================================================
185 class LDEmpty : public LDObject { 207 class LDEmpty : public LDObject {
186 public: 208 public:
187 IMPLEMENT_LDTYPE (Empty, 0) 209 LDOBJ (Empty)
210 LDOBJ_VERTICES (0)
188 LDOBJ_UNCOLORED 211 LDOBJ_UNCOLORED
189 LDOBJ_NON_SCHEMANTIC 212 LDOBJ_NON_SCHEMANTIC
213 LDOBJ_NO_MATRIX
190 }; 214 };
191 215
192 // ============================================================================= 216 // =============================================================================
193 // LDComment 217 // LDComment
194 // 218 //
195 // Represents a code-0 comment in the LDraw code file. Member zText contains 219 // Represents a code-0 comment in the LDraw code file. Member zText contains
196 // the text of the comment. 220 // the text of the comment.
197 // ============================================================================= 221 // =============================================================================
198 class LDComment : public LDObject { 222 class LDComment : public LDObject {
199 public: 223 public:
200 IMPLEMENT_LDTYPE (Comment, 0) 224 LDOBJ (Comment)
225 LDOBJ_VERTICES (0)
201 LDOBJ_UNCOLORED 226 LDOBJ_UNCOLORED
202 LDOBJ_NON_SCHEMANTIC 227 LDOBJ_NON_SCHEMANTIC
228 LDOBJ_NO_MATRIX
203 229
204 LDComment (str text) : text (text) {} 230 LDComment (str text) : text (text) {}
205 231
206 str text; // The text of this comment 232 str text; // The text of this comment
207 }; 233 };
212 // Represents a 0 BFC statement in the LDraw code. eStatement contains the type 238 // Represents a 0 BFC statement in the LDraw code. eStatement contains the type
213 // of this statement. 239 // of this statement.
214 // ============================================================================= 240 // =============================================================================
215 class LDBFC : public LDComment { 241 class LDBFC : public LDComment {
216 public: 242 public:
217 enum Type { 243 enum Type { CertifyCCW, CCW, CertifyCW, CW, NoCertify, InvertNext, NumStatements };
218 CertifyCCW, 244
219 CCW, 245 LDOBJ (BFC)
220 CertifyCW, 246 LDOBJ_VERTICES (0)
221 CW,
222 NoCertify, // Winding becomes disabled (0 BFC NOCERTIFY)
223 InvertNext, // Winding is inverted for next object (0 BFC INVERTNEXT)
224 NumStatements
225 };
226
227 IMPLEMENT_LDTYPE (BFC, 0)
228 LDOBJ_UNCOLORED 247 LDOBJ_UNCOLORED
229 LDOBJ_CUSTOM_SCHEMANTIC { return (type == InvertNext); } 248 LDOBJ_CUSTOM_SCHEMANTIC { return (type == InvertNext); }
249 LDOBJ_NO_MATRIX
230 250
231 LDBFC (const LDBFC::Type type) : type (type) {} 251 LDBFC (const LDBFC::Type type) : type (type) {}
232 252
233 // Statement strings 253 // Statement strings
234 static const char* statements[]; 254 static const char* statements[];
239 // ============================================================================= 259 // =============================================================================
240 // LDSubfile 260 // LDSubfile
241 // 261 //
242 // Represents a single code-1 subfile reference. 262 // Represents a single code-1 subfile reference.
243 // ============================================================================= 263 // =============================================================================
244 class LDSubfile : public LDObject { 264 class LDSubfile : public LDObject, public LDMatrixObject {
245 public: 265 public:
246 IMPLEMENT_LDTYPE (Subfile, 0) 266 LDOBJ (Subfile)
247 LDOBJ_COLORED 267 LDOBJ_VERTICES (0)
248 LDOBJ_SCHEMANTIC 268 LDOBJ_COLORED
249 269 LDOBJ_SCHEMANTIC
250 vertex pos; // Position of the subpart (TODO: should get rid of this) 270 LDOBJ_HAS_MATRIX
251 matrix transform; // Transformation matrix for the subpart 271
252 str fileName; // Filename of the subpart (TODO: rid this too - use fileInfo->fileName instead) 272 str fileName; // Filename of the subpart (TODO: rid this too - use fileInfo->fileName instead)
253 OpenFile* fileInfo; // Pointer to opened file for this subfile. null if unopened. 273 OpenFile* fileInfo; // Pointer to opened file for this subfile. null if unopened.
254 274
255 // Inlines this subfile. Note that return type is an array of heap-allocated 275 // Inlines this subfile. Note that return type is an array of heap-allocated
256 // LDObject-clones, they must be deleted one way or another. 276 // LDObject-clones, they must be deleted one way or another.
264 // points of the line. The line is colored with dColor unless uncolored mode is 284 // points of the line. The line is colored with dColor unless uncolored mode is
265 // set. 285 // set.
266 // ============================================================================= 286 // =============================================================================
267 class LDLine : public LDObject { 287 class LDLine : public LDObject {
268 public: 288 public:
269 IMPLEMENT_LDTYPE (Line, 2) 289 LDOBJ (Line)
270 LDOBJ_COLORED 290 LDOBJ_VERTICES (2)
271 LDOBJ_SCHEMANTIC 291 LDOBJ_COLORED
292 LDOBJ_SCHEMANTIC
293 LDOBJ_NO_MATRIX
272 294
273 LDLine (vertex v1, vertex v2); 295 LDLine (vertex v1, vertex v2);
274 }; 296 };
275 297
276 // ============================================================================= 298 // =============================================================================
279 // Represents a single code-5 conditional line. The end-points v0 and v1 are 301 // Represents a single code-5 conditional line. The end-points v0 and v1 are
280 // inherited from LDLine, c0 and c1 are the control points of this line. 302 // inherited from LDLine, c0 and c1 are the control points of this line.
281 // ============================================================================= 303 // =============================================================================
282 class LDCondLine : public LDLine { 304 class LDCondLine : public LDLine {
283 public: 305 public:
284 IMPLEMENT_LDTYPE (CondLine, 4) 306 LDOBJ (CondLine)
285 LDOBJ_COLORED 307 LDOBJ_VERTICES (4)
286 LDOBJ_SCHEMANTIC 308 LDOBJ_COLORED
309 LDOBJ_SCHEMANTIC
310 LDOBJ_NO_MATRIX
287 }; 311 };
288 312
289 // ============================================================================= 313 // =============================================================================
290 // LDTriangle 314 // LDTriangle
291 // 315 //
293 // and v2 contain the end-points of this triangle. dColor is the color the 317 // and v2 contain the end-points of this triangle. dColor is the color the
294 // triangle is colored with. 318 // triangle is colored with.
295 // ============================================================================= 319 // =============================================================================
296 class LDTriangle : public LDObject { 320 class LDTriangle : public LDObject {
297 public: 321 public:
298 IMPLEMENT_LDTYPE (Triangle, 3) 322 LDOBJ (Triangle)
299 LDOBJ_COLORED 323 LDOBJ_VERTICES (3)
300 LDOBJ_SCHEMANTIC 324 LDOBJ_COLORED
325 LDOBJ_SCHEMANTIC
326 LDOBJ_NO_MATRIX
301 327
302 LDTriangle (vertex _v0, vertex _v1, vertex _v2) { 328 LDTriangle (vertex _v0, vertex _v1, vertex _v2) {
303 coords[0] = _v0; 329 coords[0] = _v0;
304 coords[1] = _v1; 330 coords[1] = _v1;
305 coords[2] = _v2; 331 coords[2] = _v2;
312 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points 338 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points
313 // of the quad, dColor is the color used for the quad. 339 // of the quad, dColor is the color used for the quad.
314 // ============================================================================= 340 // =============================================================================
315 class LDQuad : public LDObject { 341 class LDQuad : public LDObject {
316 public: 342 public:
317 IMPLEMENT_LDTYPE (Quad, 4) 343 LDOBJ (Quad)
318 LDOBJ_COLORED 344 LDOBJ_VERTICES (4)
319 LDOBJ_SCHEMANTIC 345 LDOBJ_COLORED
346 LDOBJ_SCHEMANTIC
347 LDOBJ_NO_MATRIX
320 348
321 // Split this quad into two triangles (note: heap-allocated) 349 // Split this quad into two triangles (note: heap-allocated)
322 vector<LDTriangle*> splitToTriangles (); 350 vector<LDTriangle*> splitToTriangles ();
323 }; 351 };
324 352
330 // with. Vertices are a part authoring tool and they should not appear in 358 // with. Vertices are a part authoring tool and they should not appear in
331 // finished parts. 359 // finished parts.
332 // ============================================================================= 360 // =============================================================================
333 class LDVertex : public LDObject { 361 class LDVertex : public LDObject {
334 public: 362 public:
335 IMPLEMENT_LDTYPE (Vertex, 0) // TODO: move pos to vaCoords[0] 363 LDOBJ (Vertex)
364 LDOBJ_VERTICES (0) // TODO: move pos to vaCoords[0]
336 LDOBJ_COLORED 365 LDOBJ_COLORED
337 LDOBJ_NON_SCHEMANTIC 366 LDOBJ_NON_SCHEMANTIC
367 LDOBJ_NO_MATRIX
338 368
339 vertex pos; 369 vertex pos;
340 }; 370 };
341 371
342 // ============================================================================= 372 // =============================================================================
346 // extension which represents an arbitrary circular primitive. Radials can appear 376 // extension which represents an arbitrary circular primitive. Radials can appear
347 // as circles, cylinders, rings, cones, discs and disc negatives; the point is to 377 // as circles, cylinders, rings, cones, discs and disc negatives; the point is to
348 // allow part authors to add radial primitives to parts without much hassle about 378 // allow part authors to add radial primitives to parts without much hassle about
349 // non-existant primitive parts. 379 // non-existant primitive parts.
350 // ============================================================================= 380 // =============================================================================
351 class LDRadial : public LDObject { 381 class LDRadial : public LDObject, public LDMatrixObject {
352 public: 382 public:
353 enum Type { 383 enum Type {
354 Circle, 384 Circle,
355 Cylinder, 385 Cylinder,
356 Disc, 386 Disc,
358 Ring, 388 Ring,
359 Cone, 389 Cone,
360 NumTypes 390 NumTypes
361 }; 391 };
362 392
363 IMPLEMENT_LDTYPE (Radial, 0) 393 LDOBJ (Radial)
364 LDOBJ_COLORED 394 LDOBJ_VERTICES (0)
365 LDOBJ_SCHEMANTIC 395 LDOBJ_COLORED
396 LDOBJ_SCHEMANTIC
397 LDOBJ_HAS_MATRIX
366 398
367 LDRadial::Type radType; 399 LDRadial::Type radType;
368 vertex pos;
369 matrix transform;
370 short divs, segs, ringNum; 400 short divs, segs, ringNum;
371 401
372 LDRadial (LDRadial::Type radType, vertex pos, matrix transform, short divs, short segs, short ringNum) : 402 LDRadial (LDRadial::Type radType, vertex pos, matrix transform, short divs, short segs, short ringNum) :
373 radType (radType), pos (pos), transform (transform), divs (divs), segs (segs), ringNum (ringNum) {} 403 LDMatrixObject (transform, pos), radType (radType), divs (divs), segs (segs), ringNum (ringNum) {}
374 404
375 // Returns a set of objects that provide the equivalent of this radial. 405 // Returns a set of objects that provide the equivalent of this radial.
376 // Note: objects are heap-allocated. 406 // Note: objects are heap-allocated.
377 std::vector<LDObject*> decompose (bool applyTransform); 407 std::vector<LDObject*> decompose (bool applyTransform);
378 408

mercurial