Sat, 16 Mar 2013 14:21:31 +0200
Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
0 | 1 | #ifndef __LDTYPES_H__ |
2 | #define __LDTYPES_H__ | |
3 | ||
4 | #include "common.h" | |
5 | ||
6 | #define IMPLEMENT_LDTYPE(N) \ | |
7 | LD##N (); \ | |
8 | virtual LDObjectType_e getType () const { \ | |
9 | return OBJ_##N; \ | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
10 | } \ |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
11 | virtual str getContents (); |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
12 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
13 | class QTreeWidgetItem; |
0 | 14 | |
15 | // ============================================================================= | |
16 | // LDObjectType_e | |
17 | // | |
18 | // Object type codes | |
19 | // ============================================================================= | |
20 | enum LDObjectType_e { | |
21 | OBJ_Unidentified, // Object is uninitialized (LDObject) | |
22 | OBJ_Gibberish, // Object is unknown (LDUnknown; bad code number) | |
23 | OBJ_Empty, // Object represents an empty line (LDEmpty) | |
24 | OBJ_Comment, // Object represents a comment (LDComment, code: 0) | |
25 | OBJ_Subfile, // Object represents a sub-file reference (LDSubfile, code: 1) | |
26 | OBJ_Line, // Object represents a line (LDLine, code: 2) | |
27 | OBJ_Triangle, // Object represents a triangle (LDTriangle, code: 3) | |
28 | OBJ_Quad, // Object represents a quadrilateral (LDQuad, code: 4) | |
29 | OBJ_CondLine, // Object represents a conditional line (LDCondLine, code: 5) | |
30 | OBJ_Vector, // Object is a vector, LDForge extension object (LDVector) | |
31 | OBJ_Vertex // Object is a vertex, LDForge extension object (LDVertex) | |
32 | }; | |
33 | ||
34 | // ============================================================================= | |
35 | // LDObject | |
36 | // | |
37 | // Base class object for all LD* types. Each LDObject represents a single line | |
38 | // in the LDraw code file. The virtual method getType returns an enumerator | |
39 | // which is a token of the object's type. The object can be casted into | |
40 | // sub-classes based on this enumerator. | |
41 | // ============================================================================= | |
42 | class LDObject { | |
43 | public: | |
44 | LDObject (); | |
45 | ||
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
46 | // Index (i.e. line number) of this object |
19
6c5977e43e73
Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
47 | unsigned long getIndex (); |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
48 | |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
49 | // Type enumerator of this object |
0 | 50 | virtual LDObjectType_e getType () const { |
51 | return OBJ_Unidentified; | |
52 | }; | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
53 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
54 | // A string that represents this line |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
55 | virtual str getContents () { |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
56 | return ""; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
57 | } |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
58 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
59 | void commonInit (); |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
60 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
61 | QTreeWidgetItem* qObjListEntry; |
0 | 62 | }; |
63 | ||
64 | // ============================================================================= | |
65 | // LDGibberish | |
66 | // | |
67 | // Represents a line in the LDraw file that could not be properly parsed. It is | |
68 | // represented by a (!) ERROR in the code view. It exists for the purpose of | |
69 | // allowing garbage lines be debugged and corrected within LDForge. The member | |
70 | // zContent contains the contents of the unparsable line. | |
71 | // ============================================================================= | |
72 | class LDGibberish : public LDObject { | |
73 | public: | |
74 | IMPLEMENT_LDTYPE (Gibberish) | |
75 | ||
11
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
76 | LDGibberish (str _zContent, str _zReason); |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
77 | |
0 | 78 | // Content of this unknown line |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
79 | str zContents; |
11
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
80 | |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
81 | // Why is this gibberish? |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
82 | str zReason; |
0 | 83 | }; |
84 | ||
85 | // ============================================================================= | |
86 | // LDEmptyLine | |
87 | // | |
88 | // Represents an empty line in the LDraw code file. | |
89 | // ============================================================================= | |
90 | class LDEmpty : public LDObject { | |
91 | public: | |
92 | IMPLEMENT_LDTYPE (Empty) | |
93 | }; | |
94 | ||
95 | // ============================================================================= | |
96 | // LDComment | |
97 | // | |
98 | // Represents a code-0 comment in the LDraw code file. Member zText contains | |
99 | // the text of the comment. | |
100 | // ============================================================================= | |
101 | class LDComment : public LDObject { | |
102 | public: | |
103 | IMPLEMENT_LDTYPE (Comment) | |
104 | ||
105 | str zText; // The text of this comment | |
106 | }; | |
107 | ||
108 | // ============================================================================= | |
109 | // LDSubfile | |
110 | // | |
111 | // Represents a single code-1 subfile reference. | |
112 | // ============================================================================= | |
113 | class LDSubfile : public LDObject { | |
114 | public: | |
115 | IMPLEMENT_LDTYPE (Subfile) | |
116 | ||
117 | short dColor; // Color used by the reference | |
118 | vertex vPosition; // Position of the subpart | |
119 | double faMatrix[9]; // Transformation matrix for the subpart | |
120 | str zFileName; // Filename of the subpart | |
121 | }; | |
122 | ||
123 | // ============================================================================= | |
124 | // LDLine | |
125 | // | |
126 | // Represents a single code-2 line in the LDraw code file. v0 and v1 are the end | |
127 | // points of the line. The line is colored with dColor unless uncolored mode is | |
128 | // set. | |
129 | // ============================================================================= | |
130 | class LDLine : public LDObject { | |
131 | public: | |
132 | IMPLEMENT_LDTYPE (Line) | |
133 | ||
134 | short dColor; // Color of this line | |
135 | vertex vaCoords[2]; // End points of this line | |
136 | }; | |
137 | ||
138 | // ============================================================================= | |
139 | // LDCondLine | |
140 | // | |
141 | // Represents a single code-5 conditional line. The end-points v0 and v1 are | |
142 | // inherited from LDLine, c0 and c1 are the control points of this line. | |
143 | // ============================================================================= | |
144 | class LDCondLine : public LDLine { | |
145 | public: | |
146 | IMPLEMENT_LDTYPE (CondLine) | |
147 | ||
148 | vertex vaControl[2]; // Control points | |
149 | }; | |
150 | ||
151 | // ============================================================================= | |
152 | // LDTriangle | |
153 | // | |
154 | // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 | |
155 | // and v2 contain the end-points of this triangle. dColor is the color the | |
156 | // triangle is colored with. | |
157 | // ============================================================================= | |
158 | class LDTriangle : public LDObject { | |
159 | public: | |
160 | IMPLEMENT_LDTYPE (Triangle) | |
161 | ||
162 | short dColor; | |
163 | vertex vaCoords[3]; | |
164 | ||
165 | LDTriangle (vertex _v0, vertex _v1, vertex _v2) { | |
166 | vaCoords[0] = _v0; | |
167 | vaCoords[1] = _v1; | |
168 | vaCoords[2] = _v2; | |
169 | } | |
170 | }; | |
171 | ||
172 | // ============================================================================= | |
173 | // LDQuad | |
174 | // | |
175 | // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points | |
176 | // of the quad, dColor is the color used for the quad. | |
177 | // ============================================================================= | |
178 | class LDQuad : public LDObject { | |
179 | public: | |
180 | IMPLEMENT_LDTYPE (Quad) | |
181 | ||
182 | short dColor; | |
183 | vertex vaCoords[4]; | |
184 | }; | |
185 | ||
186 | // ============================================================================= | |
187 | // LDVector | |
188 | // | |
189 | // The vector is a LDForge-specific extension. It is essentially a line with an | |
190 | // alternative definition. Instead of being defined with two vertices, the vector | |
191 | // is defined with a single vertex, a length and a bearing. This makes it useful | |
192 | // for dealing with lines positioned on arbitrary angles without fear of precision | |
193 | // loss of vertex coordinates. A vector can be transformed into a line and vice | |
194 | // versa. Vectors are not a part of official LDraw standard and should be | |
195 | // converted to lines for finished parts. | |
196 | // | |
197 | // TODO: should a conditional vector be considered? | |
198 | // ============================================================================= | |
199 | class LDVector : public LDObject { | |
200 | public: | |
201 | IMPLEMENT_LDTYPE (Vector) | |
202 | ||
203 | vertex vPos; | |
204 | bearing gAngle3D; | |
19
6c5977e43e73
Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
205 | unsigned long ulLength; |
0 | 206 | }; |
207 | ||
208 | // ============================================================================= | |
209 | // LDVertex | |
210 | // | |
211 | // The vertex is another LDForce-specific extension. It represents a single | |
212 | // vertex which can be used as a parameter to tools or to store coordinates | |
213 | // with. Vertices are a part authoring tool and they should not appear in | |
214 | // finished parts. | |
215 | // ============================================================================= | |
216 | class LDVertex : public LDObject { | |
217 | public: | |
218 | IMPLEMENT_LDTYPE (Vertex) | |
219 | ||
220 | vertex vPosition; | |
221 | }; | |
222 | ||
223 | // ============================================================================= | |
224 | // Object type names. Pass the return value of getType as the index to get a | |
225 | // string representation of the object's type. | |
226 | extern const char* g_saObjTypeNames[]; | |
227 | ||
228 | #endif |