src/ldtypes.h

changeset 539
72ad83a67165
parent 538
2f85d4d286e5
child 540
0334789cb4d7
equal deleted inserted replaced
538:2f85d4d286e5 539:72ad83a67165
61 // in the LDraw code file. The virtual method getType returns an enumerator 61 // in the LDraw code file. The virtual method getType returns an enumerator
62 // which is a token of the object's type. The object can be casted into 62 // which is a token of the object's type. The object can be casted into
63 // sub-classes based on this enumerator. 63 // sub-classes based on this enumerator.
64 // ============================================================================= 64 // =============================================================================
65 class LDObject 65 class LDObject
66 { PROPERTY (bool, hidden, setHidden) 66 { PROPERTY (public, bool, Hidden, BOOL_OPS, NO_CB)
67 PROPERTY (bool, selected, setSelected) 67 PROPERTY (public, bool, Selected, BOOL_OPS, NO_CB)
68 PROPERTY (LDObject*, parent, setParent) 68 PROPERTY (public, LDObject*, Parent, NO_OPS, NO_CB)
69 PROPERTY (LDFile*, file, setFile) 69 PROPERTY (public, LDFile*, File, NO_OPS, NO_CB)
70 READ_PROPERTY (int32, id, setID) 70 PROPERTY (private, int32, ID, NUM_OPS, NO_CB)
71 DECLARE_PROPERTY (int, color, setColor)
72 71
73 public: 72 public:
74 // Object type codes. Codes are sorted in order of significance. 73 // Object type codes. Codes are sorted in order of significance.
75 enum Type 74 enum Type
76 { Subfile, // Object represents a sub-file reference 75 { Subfile, // Object represents a sub-file reference
93 92
94 virtual LDObject* clone() 93 virtual LDObject* clone()
95 { return 0; // Creates a new LDObject identical to this one. 94 { return 0; // Creates a new LDObject identical to this one.
96 } 95 }
97 long getIndex() const; // Index (i.e. line number) of this object 96 long getIndex() const; // Index (i.e. line number) of this object
97 const int& getColor() const; // Color of this object
98 virtual LDObject::Type getType() const; // Type enumerator of this object 98 virtual LDObject::Type getType() const; // Type enumerator of this object
99 const vertex& getVertex (int i) const; // Get a vertex by index 99 const vertex& getVertex (int i) const; // Get a vertex by index
100 virtual str getTypeName() const; // Type name of this object 100 virtual str getTypeName() const; // Type name of this object
101 virtual bool hasMatrix() const; // Does this object have a matrix and position? (see LDMatrixObject) 101 virtual bool hasMatrix() const; // Does this object have a matrix and position? (see LDMatrixObject)
102 virtual void invert(); // Inverts this object (winding is reversed) 102 virtual void invert(); // Inverts this object (winding is reversed)
106 LDObject* next() const; // Object after this in the current file 106 LDObject* next() const; // Object after this in the current file
107 LDObject* prev() const; // Object prior to this in the current file 107 LDObject* prev() const; // Object prior to this in the current file
108 virtual str raw() { return ""; } // This object as LDraw code 108 virtual str raw() { return ""; } // This object as LDraw code
109 void replace (LDObject* other); // Replace this LDObject with another LDObject. Object is deleted in the process. 109 void replace (LDObject* other); // Replace this LDObject with another LDObject. Object is deleted in the process.
110 void select(); 110 void select();
111 void setColor (int val);
111 void setVertex (int i, const vertex& vert); // Set a vertex to the given value 112 void setVertex (int i, const vertex& vert); // Set a vertex to the given value
112 void setVertexCoord (int i, Axis ax, double value); // Set a single coordinate of a vertex 113 void setVertexCoord (int i, Axis ax, double value); // Set a single coordinate of a vertex
113 void swap (LDObject* other); // Swap this object with another. 114 void swap (LDObject* other); // Swap this object with another.
114 LDObject* topLevelParent(); // What object in the current file ultimately references this? 115 LDObject* topLevelParent(); // What object in the current file ultimately references this?
115 void unselect(); 116 void unselect();
131 protected: 132 protected:
132 bool m_glinit; 133 bool m_glinit;
133 friend class GLRenderer; 134 friend class GLRenderer;
134 135
135 private: 136 private:
136 LDSharedVertex* m_coords[4]; 137 LDSharedVertex* m_coords[4];
138 int m_Color;
137 }; 139 };
138 140
139 // ============================================================================= 141 // =============================================================================
140 // LDSharedVertex 142 // LDSharedVertex
141 // 143 //
178 // In 0.1-alpha, there was a separate 'radial' type which had a position and 180 // In 0.1-alpha, there was a separate 'radial' type which had a position and
179 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping 181 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping
180 // this class distinct in case I get new extension ideas. :) 182 // this class distinct in case I get new extension ideas. :)
181 // ============================================================================= 183 // =============================================================================
182 class LDMatrixObject 184 class LDMatrixObject
183 { DECLARE_PROPERTY (matrix, transform, setTransform) 185 { PROPERTY (public, LDObject*, LinkPointer, NO_OPS, NO_CB)
184 PROPERTY (LDObject*, linkPointer, setLinkPointer)
185 186
186 public: 187 public:
187 LDMatrixObject() {} 188 LDMatrixObject() {}
188 LDMatrixObject (const matrix& transform, const vertex& pos) : 189 LDMatrixObject (const matrix& transform, const vertex& pos) :
189 m_transform (transform), m_position (LDSharedVertex::getSharedVertex (pos)) {} 190 m_Transform (transform),
191 m_position (LDSharedVertex::getSharedVertex (pos)) {}
190 192
191 const vertex& position() const 193 const vertex& position() const
192 { return m_position->data(); 194 { return m_position->data();
193 } 195 }
194 196
195 void setPosition (const vertex& a); 197 void setPosition (const vertex& a);
198 void setTransform (const matrix& val);
196 199
197 const double& setCoordinate (const Axis ax, double value) 200 const double& setCoordinate (const Axis ax, double value)
198 { vertex v = position(); 201 { vertex v = position();
199 v[ax] = value; 202 v[ax] = value;
200 setPosition (v); 203 setPosition (v);
201 204
202 return position() [ax]; 205 return position() [ax];
203 } 206 }
204 207
208 inline const matrix& getTransform() const
209 { return m_Transform;
210 }
211
205 private: 212 private:
206 LDSharedVertex* m_position; 213 matrix m_Transform;
214 LDSharedVertex* m_position;
207 }; 215 };
208 216
209 // ============================================================================= 217 // =============================================================================
210 // LDError 218 // LDError
211 // 219 //
219 LDOBJ_NAME (error) 227 LDOBJ_NAME (error)
220 LDOBJ_VERTICES (0) 228 LDOBJ_VERTICES (0)
221 LDOBJ_UNCOLORED 229 LDOBJ_UNCOLORED
222 LDOBJ_SCEMANTIC 230 LDOBJ_SCEMANTIC
223 LDOBJ_NO_MATRIX 231 LDOBJ_NO_MATRIX
224 PROPERTY (str, fileRef, setFileRef) 232 PROPERTY (public, str, FileReferenced, STR_OPS, NO_CB)
225 233
226 public: 234 public:
227 LDError(); 235 LDError();
228 LDError (str contents, str reason) : contents (contents), reason (reason) {} 236 LDError (str contents, str reason) : contents (contents), reason (reason) {}
229 237
317 LDOBJ_NAME (subfile) 325 LDOBJ_NAME (subfile)
318 LDOBJ_VERTICES (0) 326 LDOBJ_VERTICES (0)
319 LDOBJ_COLORED 327 LDOBJ_COLORED
320 LDOBJ_SCEMANTIC 328 LDOBJ_SCEMANTIC
321 LDOBJ_HAS_MATRIX 329 LDOBJ_HAS_MATRIX
322 PROPERTY (LDFile*, fileInfo, setFileInfo) 330 PROPERTY (public, LDFile*, FileInfo, NO_OPS, NO_CB)
323 331
324 public: 332 public:
325 enum InlineFlag 333 enum InlineFlag
326 { DeepInline = (1 << 0), 334 { DeepInline = (1 << 0),
327 CacheInline = (1 << 1), 335 CacheInline = (1 << 1),
461 LDOBJ_NAME (overlay) 469 LDOBJ_NAME (overlay)
462 LDOBJ_VERTICES (0) 470 LDOBJ_VERTICES (0)
463 LDOBJ_UNCOLORED 471 LDOBJ_UNCOLORED
464 LDOBJ_NON_SCEMANTIC 472 LDOBJ_NON_SCEMANTIC
465 LDOBJ_NO_MATRIX 473 LDOBJ_NO_MATRIX
466 PROPERTY (int, camera, setCamera) 474 PROPERTY (public, int, Camera, NUM_OPS, NO_CB)
467 PROPERTY (int, x, setX) 475 PROPERTY (public, int, X, NUM_OPS, NO_CB)
468 PROPERTY (int, y, setY) 476 PROPERTY (public, int, Y, NUM_OPS, NO_CB)
469 PROPERTY (int, width, setWidth) 477 PROPERTY (public, int, Width, NUM_OPS, NO_CB)
470 PROPERTY (int, height, setHeight) 478 PROPERTY (public, int, Height, NUM_OPS, NO_CB)
471 PROPERTY (str, filename, setFilename) 479 PROPERTY (public, str, FileName, STR_OPS, NO_CB)
472 }; 480 };
473 481
474 // Other common LDraw stuff 482 // Other common LDraw stuff
475 static const str CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt", 483 static const str CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt",
476 NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt"; 484 NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt";

mercurial