Tue, 19 Mar 2013 21:52:38 +0200
Begin work on dialogs for adding objects. Comments functional!
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1 | /* |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
3 | * Copyright (C) 2013 Santeri `arezey` Piippo |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
4 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
8 | * (at your option) any later version. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
9 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
13 | * GNU General Public License for more details. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
14 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
17 | */ |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
18 | |
0 | 19 | #ifndef __LDTYPES_H__ |
20 | #define __LDTYPES_H__ | |
21 | ||
22 | #include "common.h" | |
23 | ||
24 | #define IMPLEMENT_LDTYPE(N) \ | |
25 | 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
|
26 | virtual ~LD##N (); \ |
0 | 27 | virtual LDObjectType_e getType () const { \ |
28 | 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
|
29 | } \ |
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
|
30 | 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
|
31 | |
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
|
32 | class QTreeWidgetItem; |
0 | 33 | |
34 | // ============================================================================= | |
35 | // LDObjectType_e | |
36 | // | |
37 | // Object type codes | |
38 | // ============================================================================= | |
39 | 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
|
40 | 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
|
41 | OBJ_Gibberish, // Object is the result of failed parsing (LDGibberish) |
0 | 42 | OBJ_Empty, // Object represents an empty line (LDEmpty) |
43 | OBJ_Comment, // Object represents a comment (LDComment, code: 0) | |
44 | OBJ_Subfile, // Object represents a sub-file reference (LDSubfile, code: 1) | |
45 | OBJ_Line, // Object represents a line (LDLine, code: 2) | |
46 | OBJ_Triangle, // Object represents a triangle (LDTriangle, code: 3) | |
47 | OBJ_Quad, // Object represents a quadrilateral (LDQuad, code: 4) | |
48 | OBJ_CondLine, // Object represents a conditional line (LDCondLine, code: 5) | |
49 | OBJ_Vector, // Object is a vector, LDForge extension object (LDVector) | |
50 | OBJ_Vertex // Object is a vertex, LDForge extension object (LDVertex) | |
51 | }; | |
52 | ||
53 | // ============================================================================= | |
54 | // LDObject | |
55 | // | |
56 | // Base class object for all LD* types. Each LDObject represents a single line | |
57 | // in the LDraw code file. The virtual method getType returns an enumerator | |
58 | // which is a token of the object's type. The object can be casted into | |
59 | // sub-classes based on this enumerator. | |
60 | // ============================================================================= | |
61 | class LDObject { | |
62 | public: | |
63 | 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
|
64 | virtual ~LDObject (); |
0 | 65 | |
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
|
66 | // 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
|
67 | 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
|
68 | |
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
|
69 | // Type enumerator of this object |
0 | 70 | virtual LDObjectType_e getType () const { |
71 | return OBJ_Unidentified; | |
72 | }; | |
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
|
73 | |
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
|
74 | // 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
|
75 | 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
|
76 | 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
|
77 | } |
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
|
78 | |
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
|
79 | 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
|
80 | |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
81 | // 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
|
82 | // object and any pointers to it become invalid. |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
83 | void replace (LDObject* replacement); |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
84 | |
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 | QTreeWidgetItem* qObjListEntry; |
0 | 86 | }; |
87 | ||
88 | // ============================================================================= | |
89 | // LDGibberish | |
90 | // | |
91 | // Represents a line in the LDraw file that could not be properly parsed. It is | |
92 | // represented by a (!) ERROR in the code view. It exists for the purpose of | |
93 | // allowing garbage lines be debugged and corrected within LDForge. The member | |
94 | // zContent contains the contents of the unparsable line. | |
95 | // ============================================================================= | |
96 | class LDGibberish : public LDObject { | |
97 | public: | |
98 | IMPLEMENT_LDTYPE (Gibberish) | |
99 | ||
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
|
100 | 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
|
101 | |
0 | 102 | // 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
|
103 | 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
|
104 | |
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
|
105 | // 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
|
106 | str zReason; |
0 | 107 | }; |
108 | ||
109 | // ============================================================================= | |
110 | // LDEmptyLine | |
111 | // | |
112 | // Represents an empty line in the LDraw code file. | |
113 | // ============================================================================= | |
114 | class LDEmpty : public LDObject { | |
115 | public: | |
116 | IMPLEMENT_LDTYPE (Empty) | |
117 | }; | |
118 | ||
119 | // ============================================================================= | |
120 | // LDComment | |
121 | // | |
122 | // Represents a code-0 comment in the LDraw code file. Member zText contains | |
123 | // the text of the comment. | |
124 | // ============================================================================= | |
125 | class LDComment : public LDObject { | |
126 | public: | |
127 | IMPLEMENT_LDTYPE (Comment) | |
128 | ||
129 | str zText; // The text of this comment | |
130 | }; | |
131 | ||
132 | // ============================================================================= | |
133 | // LDSubfile | |
134 | // | |
135 | // Represents a single code-1 subfile reference. | |
136 | // ============================================================================= | |
137 | class LDSubfile : public LDObject { | |
138 | public: | |
139 | IMPLEMENT_LDTYPE (Subfile) | |
140 | ||
141 | short dColor; // Color used by the reference | |
142 | vertex vPosition; // Position of the subpart | |
143 | double faMatrix[9]; // Transformation matrix for the subpart | |
144 | str zFileName; // Filename of the subpart | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
21
diff
changeset
|
145 | OpenFile* pFile; // Pointer to opened file for this subfile. nullptr if unopened. |
0 | 146 | }; |
147 | ||
148 | // ============================================================================= | |
149 | // LDLine | |
150 | // | |
151 | // Represents a single code-2 line in the LDraw code file. v0 and v1 are the end | |
152 | // points of the line. The line is colored with dColor unless uncolored mode is | |
153 | // set. | |
154 | // ============================================================================= | |
155 | class LDLine : public LDObject { | |
156 | public: | |
157 | IMPLEMENT_LDTYPE (Line) | |
158 | ||
159 | short dColor; // Color of this line | |
160 | vertex vaCoords[2]; // End points of this line | |
161 | }; | |
162 | ||
163 | // ============================================================================= | |
164 | // LDCondLine | |
165 | // | |
166 | // Represents a single code-5 conditional line. The end-points v0 and v1 are | |
167 | // inherited from LDLine, c0 and c1 are the control points of this line. | |
168 | // ============================================================================= | |
169 | class LDCondLine : public LDLine { | |
170 | public: | |
171 | IMPLEMENT_LDTYPE (CondLine) | |
172 | ||
173 | vertex vaControl[2]; // Control points | |
174 | }; | |
175 | ||
176 | // ============================================================================= | |
177 | // LDTriangle | |
178 | // | |
179 | // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 | |
180 | // and v2 contain the end-points of this triangle. dColor is the color the | |
181 | // triangle is colored with. | |
182 | // ============================================================================= | |
183 | class LDTriangle : public LDObject { | |
184 | public: | |
185 | IMPLEMENT_LDTYPE (Triangle) | |
186 | ||
187 | short dColor; | |
188 | vertex vaCoords[3]; | |
189 | ||
190 | LDTriangle (vertex _v0, vertex _v1, vertex _v2) { | |
191 | vaCoords[0] = _v0; | |
192 | vaCoords[1] = _v1; | |
193 | vaCoords[2] = _v2; | |
194 | } | |
195 | }; | |
196 | ||
197 | // ============================================================================= | |
198 | // LDQuad | |
199 | // | |
200 | // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points | |
201 | // of the quad, dColor is the color used for the quad. | |
202 | // ============================================================================= | |
203 | class LDQuad : public LDObject { | |
204 | public: | |
205 | IMPLEMENT_LDTYPE (Quad) | |
206 | ||
207 | short dColor; | |
208 | vertex vaCoords[4]; | |
21
9aebaaafa5da
Added split-quads-to-triangles function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
209 | |
9aebaaafa5da
Added split-quads-to-triangles function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
210 | // Split this quad into two triangles |
9aebaaafa5da
Added split-quads-to-triangles function
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
211 | void splitToTriangles (); |
0 | 212 | }; |
213 | ||
214 | // ============================================================================= | |
215 | // LDVector | |
216 | // | |
217 | // The vector is a LDForge-specific extension. It is essentially a line with an | |
218 | // alternative definition. Instead of being defined with two vertices, the vector | |
219 | // is defined with a single vertex, a length and a bearing. This makes it useful | |
220 | // for dealing with lines positioned on arbitrary angles without fear of precision | |
221 | // loss of vertex coordinates. A vector can be transformed into a line and vice | |
222 | // versa. Vectors are not a part of official LDraw standard and should be | |
223 | // converted to lines for finished parts. | |
224 | // | |
225 | // TODO: should a conditional vector be considered? | |
226 | // ============================================================================= | |
227 | class LDVector : public LDObject { | |
228 | public: | |
229 | IMPLEMENT_LDTYPE (Vector) | |
230 | ||
231 | vertex vPos; | |
232 | 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
|
233 | unsigned long ulLength; |
0 | 234 | }; |
235 | ||
236 | // ============================================================================= | |
237 | // LDVertex | |
238 | // | |
239 | // The vertex is another LDForce-specific extension. It represents a single | |
240 | // vertex which can be used as a parameter to tools or to store coordinates | |
241 | // with. Vertices are a part authoring tool and they should not appear in | |
242 | // finished parts. | |
243 | // ============================================================================= | |
244 | class LDVertex : public LDObject { | |
245 | public: | |
246 | IMPLEMENT_LDTYPE (Vertex) | |
247 | ||
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
248 | short dColor; |
0 | 249 | vertex vPosition; |
250 | }; | |
251 | ||
252 | // ============================================================================= | |
253 | // Object type names. Pass the return value of getType as the index to get a | |
254 | // string representation of the object's type. | |
255 | extern const char* g_saObjTypeNames[]; | |
256 | ||
39
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
257 | // Icons for these types |
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
258 | extern const char* g_saObjTypeIcons[]; |
110669124caf
Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
259 | |
0 | 260 | #endif |