20 #define __LDTYPES_H__ |
20 #define __LDTYPES_H__ |
21 |
21 |
22 #include "common.h" |
22 #include "common.h" |
23 #include "types.h" |
23 #include "types.h" |
24 |
24 |
25 #define IMPLEMENT_LDTYPE(N) \ |
25 #define IMPLEMENT_LDTYPE(T, NUMVERTS) \ |
26 LD##N (); \ |
26 LD##T (); \ |
27 virtual ~LD##N (); \ |
27 virtual ~LD##T (); \ |
28 virtual LDObjectType_e getType () const { \ |
28 virtual LDObjectType_e getType () const { \ |
29 return OBJ_##N; \ |
29 return OBJ_##T; \ |
30 } \ |
30 } \ |
31 virtual str getContents (); \ |
31 virtual str getContents (); \ |
32 virtual LD##N* clone () { \ |
32 virtual LD##T* clone () { \ |
33 return new LD##N (*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 |
37 |
37 class QTreeWidgetItem; |
38 class QTreeWidgetItem; |
38 class LDSubfile; |
39 class LDSubfile; |
39 |
40 |
40 // ============================================================================= |
41 // ============================================================================= |
79 short dColor; |
80 short dColor; |
80 |
81 |
81 // OpenGL list for this object |
82 // OpenGL list for this object |
82 uint uGLList, uGLPickList; |
83 uint uGLList, uGLPickList; |
83 |
84 |
|
85 // Vertices of this object |
|
86 vertex vaCoords[4]; |
|
87 |
84 // Object this object was referenced from, if any |
88 // Object this object was referenced from, if any |
85 LDObject* parent; |
89 LDObject* parent; |
86 |
90 |
87 // Type enumerator of this object |
91 // Type enumerator of this object |
88 virtual LDObjectType_e getType () const { |
92 virtual LDObjectType_e getType () const { |
110 virtual void move (vertex vVector); |
114 virtual void move (vertex vVector); |
111 |
115 |
112 // What object in the current file ultimately references this? |
116 // What object in the current file ultimately references this? |
113 LDObject* topLevelParent (); |
117 LDObject* topLevelParent (); |
114 |
118 |
|
119 // Number of vertices this object has |
|
120 virtual short vertices () const { return 0; } |
|
121 |
115 static void moveObjects (std::vector<LDObject*> objs, const bool bUp); |
122 static void moveObjects (std::vector<LDObject*> objs, const bool bUp); |
116 static str objectListContents (const std::vector<LDObject*>& objs); |
123 static str objectListContents (const std::vector<LDObject*>& objs); |
117 |
124 |
118 QTreeWidgetItem* qObjListEntry; |
125 QTreeWidgetItem* qObjListEntry; |
119 }; |
126 }; |
126 // allowing garbage lines be debugged and corrected within LDForge. The member |
133 // allowing garbage lines be debugged and corrected within LDForge. The member |
127 // zContent contains the contents of the unparsable line. |
134 // zContent contains the contents of the unparsable line. |
128 // ============================================================================= |
135 // ============================================================================= |
129 class LDGibberish : public LDObject { |
136 class LDGibberish : public LDObject { |
130 public: |
137 public: |
131 IMPLEMENT_LDTYPE (Gibberish) |
138 IMPLEMENT_LDTYPE (Gibberish, 0) |
132 |
139 |
133 LDGibberish (str _zContent, str _zReason); |
140 LDGibberish (str _zContent, str _zReason); |
134 |
141 |
135 // Content of this unknown line |
142 // Content of this unknown line |
136 str zContents; |
143 str zContents; |
144 // |
151 // |
145 // Represents an empty line in the LDraw code file. |
152 // Represents an empty line in the LDraw code file. |
146 // ============================================================================= |
153 // ============================================================================= |
147 class LDEmpty : public LDObject { |
154 class LDEmpty : public LDObject { |
148 public: |
155 public: |
149 IMPLEMENT_LDTYPE (Empty) |
156 IMPLEMENT_LDTYPE (Empty, 0) |
150 }; |
157 }; |
151 |
158 |
152 // ============================================================================= |
159 // ============================================================================= |
153 // LDComment |
160 // LDComment |
154 // |
161 // |
155 // Represents a code-0 comment in the LDraw code file. Member zText contains |
162 // Represents a code-0 comment in the LDraw code file. Member zText contains |
156 // the text of the comment. |
163 // the text of the comment. |
157 // ============================================================================= |
164 // ============================================================================= |
158 class LDComment : public LDObject { |
165 class LDComment : public LDObject { |
159 public: |
166 public: |
160 IMPLEMENT_LDTYPE (Comment) |
167 IMPLEMENT_LDTYPE (Comment, 0) |
161 LDComment (str zText) : zText (zText) {} |
168 LDComment (str zText) : zText (zText) {} |
162 |
169 |
163 str zText; // The text of this comment |
170 str zText; // The text of this comment |
164 }; |
171 }; |
165 |
172 |
179 NoCertify, // Winding becomes disabled (0 BFC NOCERTIFY) |
186 NoCertify, // Winding becomes disabled (0 BFC NOCERTIFY) |
180 InvertNext, // Winding is inverted for next object (0 BFC INVERTNEXT) |
187 InvertNext, // Winding is inverted for next object (0 BFC INVERTNEXT) |
181 NumStatements |
188 NumStatements |
182 }; |
189 }; |
183 |
190 |
184 IMPLEMENT_LDTYPE (BFC) |
191 IMPLEMENT_LDTYPE (BFC, 0) |
185 LDBFC (const LDBFC::Type eType) : eStatement (eType) {} |
192 LDBFC (const LDBFC::Type eType) : eStatement (eType) {} |
186 |
193 |
187 // Statement strings |
194 // Statement strings |
188 static const char* saStatements[]; |
195 static const char* saStatements[]; |
189 |
196 |
195 // |
202 // |
196 // Represents a single code-1 subfile reference. |
203 // Represents a single code-1 subfile reference. |
197 // ============================================================================= |
204 // ============================================================================= |
198 class LDSubfile : public LDObject { |
205 class LDSubfile : public LDObject { |
199 public: |
206 public: |
200 IMPLEMENT_LDTYPE (Subfile) |
207 IMPLEMENT_LDTYPE (Subfile, 0) |
201 |
208 |
202 vertex vPosition; // Position of the subpart |
209 vertex vPosition; // Position of the subpart |
203 matrix mMatrix; // Transformation matrix for the subpart |
210 matrix mMatrix; // Transformation matrix for the subpart |
204 str zFileName; // Filename of the subpart |
211 str zFileName; // Filename of the subpart |
205 OpenFile* pFile; // Pointer to opened file for this subfile. null if unopened. |
212 OpenFile* pFile; // Pointer to opened file for this subfile. null if unopened. |
215 // points of the line. The line is colored with dColor unless uncolored mode is |
222 // points of the line. The line is colored with dColor unless uncolored mode is |
216 // set. |
223 // set. |
217 // ============================================================================= |
224 // ============================================================================= |
218 class LDLine : public LDObject { |
225 class LDLine : public LDObject { |
219 public: |
226 public: |
220 IMPLEMENT_LDTYPE (Line) |
227 IMPLEMENT_LDTYPE (Line, 2) |
221 LDLine (vertex v1, vertex v2); |
228 LDLine (vertex v1, vertex v2); |
222 |
|
223 vertex vaCoords[2]; // End points of this line |
|
224 }; |
229 }; |
225 |
230 |
226 // ============================================================================= |
231 // ============================================================================= |
227 // LDCondLine |
232 // LDCondLine |
228 // |
233 // |
229 // Represents a single code-5 conditional line. The end-points v0 and v1 are |
234 // Represents a single code-5 conditional line. The end-points v0 and v1 are |
230 // inherited from LDLine, c0 and c1 are the control points of this line. |
235 // inherited from LDLine, c0 and c1 are the control points of this line. |
231 // ============================================================================= |
236 // ============================================================================= |
232 class LDCondLine : public LDLine { |
237 class LDCondLine : public LDLine { |
233 public: |
238 public: |
234 IMPLEMENT_LDTYPE (CondLine) |
239 IMPLEMENT_LDTYPE (CondLine, 4) |
235 |
|
236 vertex vaCoords[4]; // End points + control points of this line |
|
237 }; |
240 }; |
238 |
241 |
239 // ============================================================================= |
242 // ============================================================================= |
240 // LDTriangle |
243 // LDTriangle |
241 // |
244 // |
243 // and v2 contain the end-points of this triangle. dColor is the color the |
246 // and v2 contain the end-points of this triangle. dColor is the color the |
244 // triangle is colored with. |
247 // triangle is colored with. |
245 // ============================================================================= |
248 // ============================================================================= |
246 class LDTriangle : public LDObject { |
249 class LDTriangle : public LDObject { |
247 public: |
250 public: |
248 IMPLEMENT_LDTYPE (Triangle) |
251 IMPLEMENT_LDTYPE (Triangle, 3) |
249 |
|
250 vertex vaCoords[3]; |
|
251 |
252 |
252 LDTriangle (vertex _v0, vertex _v1, vertex _v2) { |
253 LDTriangle (vertex _v0, vertex _v1, vertex _v2) { |
253 vaCoords[0] = _v0; |
254 vaCoords[0] = _v0; |
254 vaCoords[1] = _v1; |
255 vaCoords[1] = _v1; |
255 vaCoords[2] = _v2; |
256 vaCoords[2] = _v2; |
262 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
263 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
263 // of the quad, dColor is the color used for the quad. |
264 // of the quad, dColor is the color used for the quad. |
264 // ============================================================================= |
265 // ============================================================================= |
265 class LDQuad : public LDObject { |
266 class LDQuad : public LDObject { |
266 public: |
267 public: |
267 IMPLEMENT_LDTYPE (Quad) |
268 IMPLEMENT_LDTYPE (Quad, 4) |
268 |
|
269 vertex vaCoords[4]; |
|
270 |
269 |
271 // Split this quad into two triangles |
270 // Split this quad into two triangles |
272 vector<LDTriangle*> splitToTriangles (); |
271 vector<LDTriangle*> splitToTriangles (); |
273 }; |
272 }; |
274 |
273 |
280 // with. Vertices are a part authoring tool and they should not appear in |
279 // with. Vertices are a part authoring tool and they should not appear in |
281 // finished parts. |
280 // finished parts. |
282 // ============================================================================= |
281 // ============================================================================= |
283 class LDVertex : public LDObject { |
282 class LDVertex : public LDObject { |
284 public: |
283 public: |
285 IMPLEMENT_LDTYPE (Vertex) |
284 IMPLEMENT_LDTYPE (Vertex, 0) // TODO: move vPosition to vaCoords[0] |
286 |
285 |
287 vertex vPosition; |
286 vertex vPosition; |
288 }; |
287 }; |
289 |
288 |
290 // ============================================================================= |
289 // ============================================================================= |