src/ldtypes.h

changeset 540
0334789cb4d7
parent 539
72ad83a67165
child 541
0e38beeb050a
equal deleted inserted replaced
539:72ad83a67165 540:0334789cb4d7
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 (public, bool, Hidden, BOOL_OPS, NO_CB) 66 { PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE)
67 PROPERTY (public, bool, Selected, BOOL_OPS, NO_CB) 67 PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE)
68 PROPERTY (public, LDObject*, Parent, NO_OPS, NO_CB) 68 PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE)
69 PROPERTY (public, LDFile*, File, NO_OPS, NO_CB) 69 PROPERTY (public, LDFile*, File, NO_OPS, STOCK_WRITE)
70 PROPERTY (private, int32, ID, NUM_OPS, NO_CB) 70 PROPERTY (private, int32, ID, NUM_OPS, STOCK_WRITE)
71 PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE)
71 72
72 public: 73 public:
73 // Object type codes. Codes are sorted in order of significance. 74 // Object type codes. Codes are sorted in order of significance.
74 enum Type 75 enum Type
75 { Subfile, // Object represents a sub-file reference 76 { Subfile, // Object represents a sub-file reference
92 93
93 virtual LDObject* clone() 94 virtual LDObject* clone()
94 { return 0; // Creates a new LDObject identical to this one. 95 { return 0; // Creates a new LDObject identical to this one.
95 } 96 }
96 long getIndex() const; // Index (i.e. line number) of this object 97 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);
112 void setVertex (int i, const vertex& vert); // Set a vertex to the given value 111 void setVertex (int i, const vertex& vert); // Set a vertex to the given value
113 void setVertexCoord (int i, Axis ax, double value); // Set a single coordinate of a vertex 112 void setVertexCoord (int i, Axis ax, double value); // Set a single coordinate of a vertex
114 void swap (LDObject* other); // Swap this object with another. 113 void swap (LDObject* other); // Swap this object with another.
115 LDObject* topLevelParent(); // What object in the current file ultimately references this? 114 LDObject* topLevelParent(); // What object in the current file ultimately references this?
116 void unselect(); 115 void unselect();
133 bool m_glinit; 132 bool m_glinit;
134 friend class GLRenderer; 133 friend class GLRenderer;
135 134
136 private: 135 private:
137 LDSharedVertex* m_coords[4]; 136 LDSharedVertex* m_coords[4];
138 int m_Color;
139 }; 137 };
140 138
141 // ============================================================================= 139 // =============================================================================
142 // LDSharedVertex 140 // LDSharedVertex
143 // 141 //
180 // In 0.1-alpha, there was a separate 'radial' type which had a position and 178 // In 0.1-alpha, there was a separate 'radial' type which had a position and
181 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping 179 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping
182 // this class distinct in case I get new extension ideas. :) 180 // this class distinct in case I get new extension ideas. :)
183 // ============================================================================= 181 // =============================================================================
184 class LDMatrixObject 182 class LDMatrixObject
185 { PROPERTY (public, LDObject*, LinkPointer, NO_OPS, NO_CB) 183 { PROPERTY (public, LDObject*, LinkPointer, NO_OPS, STOCK_WRITE)
184 PROPERTY (public, vertex, Position, NO_OPS, CUSTOM_WRITE)
185 PROPERTY (public, matrix, Transform, NO_OPS, CUSTOM_WRITE)
186 186
187 public: 187 public:
188 LDMatrixObject() {} 188 LDMatrixObject() {}
189 LDMatrixObject (const matrix& transform, const vertex& pos) : 189 LDMatrixObject (const matrix& transform, const vertex& pos) :
190 m_Transform (transform), 190 m_Transform (transform),
191 m_position (LDSharedVertex::getSharedVertex (pos)) {} 191 m_position (LDSharedVertex::getSharedVertex (pos)) {}
192 192
193 const vertex& position() const
194 { return m_position->data();
195 }
196
197 void setPosition (const vertex& a);
198 void setTransform (const matrix& val);
199
200 const double& setCoordinate (const Axis ax, double value) 193 const double& setCoordinate (const Axis ax, double value)
201 { vertex v = position(); 194 { vertex v = getPosition();
202 v[ax] = value; 195 v[ax] = value;
203 setPosition (v); 196 setPosition (v);
204 197
205 return position() [ax]; 198 return getPosition()[ax];
206 }
207
208 inline const matrix& getTransform() const
209 { return m_Transform;
210 } 199 }
211 200
212 private: 201 private:
213 matrix m_Transform;
214 LDSharedVertex* m_position; 202 LDSharedVertex* m_position;
215 }; 203 };
216 204
217 // ============================================================================= 205 // =============================================================================
218 // LDError 206 // LDError
227 LDOBJ_NAME (error) 215 LDOBJ_NAME (error)
228 LDOBJ_VERTICES (0) 216 LDOBJ_VERTICES (0)
229 LDOBJ_UNCOLORED 217 LDOBJ_UNCOLORED
230 LDOBJ_SCEMANTIC 218 LDOBJ_SCEMANTIC
231 LDOBJ_NO_MATRIX 219 LDOBJ_NO_MATRIX
232 PROPERTY (public, str, FileReferenced, STR_OPS, NO_CB) 220 PROPERTY (public, str, FileReferenced, STR_OPS, STOCK_WRITE)
233 221
234 public: 222 public:
235 LDError(); 223 LDError();
236 LDError (str contents, str reason) : contents (contents), reason (reason) {} 224 LDError (str contents, str reason) : contents (contents), reason (reason) {}
237 225
325 LDOBJ_NAME (subfile) 313 LDOBJ_NAME (subfile)
326 LDOBJ_VERTICES (0) 314 LDOBJ_VERTICES (0)
327 LDOBJ_COLORED 315 LDOBJ_COLORED
328 LDOBJ_SCEMANTIC 316 LDOBJ_SCEMANTIC
329 LDOBJ_HAS_MATRIX 317 LDOBJ_HAS_MATRIX
330 PROPERTY (public, LDFile*, FileInfo, NO_OPS, NO_CB) 318 PROPERTY (public, LDFile*, FileInfo, NO_OPS, STOCK_WRITE)
331 319
332 public: 320 public:
333 enum InlineFlag 321 enum InlineFlag
334 { DeepInline = (1 << 0), 322 { DeepInline = (1 << 0),
335 CacheInline = (1 << 1), 323 CacheInline = (1 << 1),
469 LDOBJ_NAME (overlay) 457 LDOBJ_NAME (overlay)
470 LDOBJ_VERTICES (0) 458 LDOBJ_VERTICES (0)
471 LDOBJ_UNCOLORED 459 LDOBJ_UNCOLORED
472 LDOBJ_NON_SCEMANTIC 460 LDOBJ_NON_SCEMANTIC
473 LDOBJ_NO_MATRIX 461 LDOBJ_NO_MATRIX
474 PROPERTY (public, int, Camera, NUM_OPS, NO_CB) 462 PROPERTY (public, int, Camera, NUM_OPS, STOCK_WRITE)
475 PROPERTY (public, int, X, NUM_OPS, NO_CB) 463 PROPERTY (public, int, X, NUM_OPS, STOCK_WRITE)
476 PROPERTY (public, int, Y, NUM_OPS, NO_CB) 464 PROPERTY (public, int, Y, NUM_OPS, STOCK_WRITE)
477 PROPERTY (public, int, Width, NUM_OPS, NO_CB) 465 PROPERTY (public, int, Width, NUM_OPS, STOCK_WRITE)
478 PROPERTY (public, int, Height, NUM_OPS, NO_CB) 466 PROPERTY (public, int, Height, NUM_OPS, STOCK_WRITE)
479 PROPERTY (public, str, FileName, STR_OPS, NO_CB) 467 PROPERTY (public, str, FileName, STR_OPS, STOCK_WRITE)
480 }; 468 };
481 469
482 // Other common LDraw stuff 470 // Other common LDraw stuff
483 static const str CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt", 471 static const str CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt",
484 NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt"; 472 NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt";

mercurial