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