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