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