Mon, 18 Mar 2013 18:29:02 +0200
Added LDraw path setting dialog
0 | 1 | #ifndef __LDTYPES_H__ |
2 | #define __LDTYPES_H__ | |
3 | ||
4 | #include "common.h" | |
5 | ||
6 | #define IMPLEMENT_LDTYPE(N) \ | |
7 | LD##N (); \ | |
24
d2d4d0154338
added dummy action for future inlining command. Also GCC says that deleting instances of classes with virtual members but no virtual destructors is bad.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
8 | virtual ~LD##N (); \ |
0 | 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 { | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
22 | OBJ_Unidentified, // Object is an uninitialized (LDObject) (SHOULD NEVER HAPPEN) |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
23 | OBJ_Gibberish, // Object is the result of failed parsing (LDGibberish) |
0 | 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 (); | |
24
d2d4d0154338
added dummy action for future inlining command. Also GCC says that deleting instances of classes with virtual members but no virtual destructors is bad.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
46 | virtual ~LDObject (); |
0 | 47 | |
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 | // 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
|
49 | 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
|
50 | |
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
|
51 | // Type enumerator of this object |
0 | 52 | virtual LDObjectType_e getType () const { |
53 | return OBJ_Unidentified; | |
54 | }; | |
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
|
55 | |
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 | // 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
|
57 | 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
|
58 | 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
|
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 | |
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 | 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
|
62 | |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
63 | // Replace this LDObject with another LDObject. This method deletes the |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
64 | // object and any pointers to it become invalid. |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
65 | void replace (LDObject* replacement); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
66 | |
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
|
67 | QTreeWidgetItem* qObjListEntry; |
0 | 68 | }; |
69 | ||
70 | // ============================================================================= | |
71 | // LDGibberish | |
72 | // | |
73 | // Represents a line in the LDraw file that could not be properly parsed. It is | |
74 | // represented by a (!) ERROR in the code view. It exists for the purpose of | |
75 | // allowing garbage lines be debugged and corrected within LDForge. The member | |
76 | // zContent contains the contents of the unparsable line. | |
77 | // ============================================================================= | |
78 | class LDGibberish : public LDObject { | |
79 | public: | |
80 | IMPLEMENT_LDTYPE (Gibberish) | |
81 | ||
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
|
82 | 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
|
83 | |
0 | 84 | // 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
|
85 | 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
|
86 | |
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
|
87 | // 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
|
88 | str zReason; |
0 | 89 | }; |
90 | ||
91 | // ============================================================================= | |
92 | // LDEmptyLine | |
93 | // | |
94 | // Represents an empty line in the LDraw code file. | |
95 | // ============================================================================= | |
96 | class LDEmpty : public LDObject { | |
97 | public: | |
98 | IMPLEMENT_LDTYPE (Empty) | |
99 | }; | |
100 | ||
101 | // ============================================================================= | |
102 | // LDComment | |
103 | // | |
104 | // Represents a code-0 comment in the LDraw code file. Member zText contains | |
105 | // the text of the comment. | |
106 | // ============================================================================= | |
107 | class LDComment : public LDObject { | |
108 | public: | |
109 | IMPLEMENT_LDTYPE (Comment) | |
110 | ||
111 | str zText; // The text of this comment | |
112 | }; | |
113 | ||
114 | // ============================================================================= | |
115 | // LDSubfile | |
116 | // | |
117 | // Represents a single code-1 subfile reference. | |
118 | // ============================================================================= | |
119 | class LDSubfile : public LDObject { | |
120 | public: | |
121 | IMPLEMENT_LDTYPE (Subfile) | |
122 | ||
123 | short dColor; // Color used by the reference | |
124 | vertex vPosition; // Position of the subpart | |
125 | double faMatrix[9]; // Transformation matrix for the subpart | |
126 | str zFileName; // Filename of the subpart | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
21
diff
changeset
|
127 | OpenFile* pFile; // Pointer to opened file for this subfile. nullptr if unopened. |
0 | 128 | }; |
129 | ||
130 | // ============================================================================= | |
131 | // LDLine | |
132 | // | |
133 | // Represents a single code-2 line in the LDraw code file. v0 and v1 are the end | |
134 | // points of the line. The line is colored with dColor unless uncolored mode is | |
135 | // set. | |
136 | // ============================================================================= | |
137 | class LDLine : public LDObject { | |
138 | public: | |
139 | IMPLEMENT_LDTYPE (Line) | |
140 | ||
141 | short dColor; // Color of this line | |
142 | vertex vaCoords[2]; // End points of this line | |
143 | }; | |
144 | ||
145 | // ============================================================================= | |
146 | // LDCondLine | |
147 | // | |
148 | // Represents a single code-5 conditional line. The end-points v0 and v1 are | |
149 | // inherited from LDLine, c0 and c1 are the control points of this line. | |
150 | // ============================================================================= | |
151 | class LDCondLine : public LDLine { | |
152 | public: | |
153 | IMPLEMENT_LDTYPE (CondLine) | |
154 | ||
155 | vertex vaControl[2]; // Control points | |
156 | }; | |
157 | ||
158 | // ============================================================================= | |
159 | // LDTriangle | |
160 | // | |
161 | // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 | |
162 | // and v2 contain the end-points of this triangle. dColor is the color the | |
163 | // triangle is colored with. | |
164 | // ============================================================================= | |
165 | class LDTriangle : public LDObject { | |
166 | public: | |
167 | IMPLEMENT_LDTYPE (Triangle) | |
168 | ||
169 | short dColor; | |
170 | vertex vaCoords[3]; | |
171 | ||
172 | LDTriangle (vertex _v0, vertex _v1, vertex _v2) { | |
173 | vaCoords[0] = _v0; | |
174 | vaCoords[1] = _v1; | |
175 | vaCoords[2] = _v2; | |
176 | } | |
177 | }; | |
178 | ||
179 | // ============================================================================= | |
180 | // LDQuad | |
181 | // | |
182 | // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points | |
183 | // of the quad, dColor is the color used for the quad. | |
184 | // ============================================================================= | |
185 | class LDQuad : public LDObject { | |
186 | public: | |
187 | IMPLEMENT_LDTYPE (Quad) | |
188 | ||
189 | short dColor; | |
190 | vertex vaCoords[4]; | |
21
9aebaaafa5da
Added split-quads-to-triangles function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
191 | |
9aebaaafa5da
Added split-quads-to-triangles function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
192 | // Split this quad into two triangles |
9aebaaafa5da
Added split-quads-to-triangles function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
193 | void splitToTriangles (); |
0 | 194 | }; |
195 | ||
196 | // ============================================================================= | |
197 | // LDVector | |
198 | // | |
199 | // The vector is a LDForge-specific extension. It is essentially a line with an | |
200 | // alternative definition. Instead of being defined with two vertices, the vector | |
201 | // is defined with a single vertex, a length and a bearing. This makes it useful | |
202 | // for dealing with lines positioned on arbitrary angles without fear of precision | |
203 | // loss of vertex coordinates. A vector can be transformed into a line and vice | |
204 | // versa. Vectors are not a part of official LDraw standard and should be | |
205 | // converted to lines for finished parts. | |
206 | // | |
207 | // TODO: should a conditional vector be considered? | |
208 | // ============================================================================= | |
209 | class LDVector : public LDObject { | |
210 | public: | |
211 | IMPLEMENT_LDTYPE (Vector) | |
212 | ||
213 | vertex vPos; | |
214 | 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
|
215 | unsigned long ulLength; |
0 | 216 | }; |
217 | ||
218 | // ============================================================================= | |
219 | // LDVertex | |
220 | // | |
221 | // The vertex is another LDForce-specific extension. It represents a single | |
222 | // vertex which can be used as a parameter to tools or to store coordinates | |
223 | // with. Vertices are a part authoring tool and they should not appear in | |
224 | // finished parts. | |
225 | // ============================================================================= | |
226 | class LDVertex : public LDObject { | |
227 | public: | |
228 | IMPLEMENT_LDTYPE (Vertex) | |
229 | ||
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
230 | short dColor; |
0 | 231 | vertex vPosition; |
232 | }; | |
233 | ||
234 | // ============================================================================= | |
235 | // Object type names. Pass the return value of getType as the index to get a | |
236 | // string representation of the object's type. | |
237 | extern const char* g_saObjTypeNames[]; | |
238 | ||
239 | #endif |