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