src/ldtypes.h

changeset 560
39085791128f
parent 558
5f6e30e0450c
child 564
79b23e02dcf1
equal deleted inserted replaced
559:5a31f6c14451 560:39085791128f
21 21
22 #include "main.h" 22 #include "main.h"
23 #include "types.h" 23 #include "types.h"
24 24
25 #define LDOBJ(T) \ 25 #define LDOBJ(T) \
26 protected: \
27 virtual ~LD##T() {} \
28 virtual LD##T* clone() override { \
29 return new LD##T (*this); \
30 } \
26 public: \ 31 public: \
27 virtual ~LD##T() {} \
28 virtual LDObject::Type getType() const override { \ 32 virtual LDObject::Type getType() const override { \
29 return LDObject::T; \ 33 return LDObject::T; \
30 } \ 34 } \
31 virtual str raw(); \ 35 virtual str raw() const override; \
32 virtual LD##T* clone() { \ 36 virtual void invert() override;
33 return new LD##T (*this); \
34 } \
35 virtual void invert();
36 37
37 #define LDOBJ_NAME(N) virtual str getTypeName() const override { return #N; } 38 #define LDOBJ_NAME(N) virtual str getTypeName() const override { return #N; }
38 #define LDOBJ_VERTICES(V) virtual int vertices() const override { return V; } 39 #define LDOBJ_VERTICES(V) virtual int vertices() const override { return V; }
39 #define LDOBJ_SETCOLORED(V) virtual bool isColored() const override { return V; } 40 #define LDOBJ_SETCOLORED(V) virtual bool isColored() const override { return V; }
40 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) 41 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true)
60 // 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
61 // 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
62 // sub-classes based on this enumerator. 63 // sub-classes based on this enumerator.
63 // ============================================================================= 64 // =============================================================================
64 class LDObject 65 class LDObject
65 { PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE) 66 { PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE)
66 PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE) 67 PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE)
67 PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE) 68 PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE)
68 PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) 69 PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) // TODO: rename~
69 PROPERTY (private, int32, ID, NUM_OPS, STOCK_WRITE) 70 PROPERTY (private, int32, ID, NUM_OPS, STOCK_WRITE)
70 PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE) 71 PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE)
72 PROPERTY (public, bool, GLInit, BOOL_OPS, STOCK_WRITE)
71 73
72 public: 74 public:
73 // Object type codes. Codes are sorted in order of significance. 75 // Object type codes. Codes are sorted in order of significance.
74 enum Type 76 enum Type
75 { Subfile, // Object represents a sub-file reference 77 { Subfile, // Object represents a sub-file reference
76 Quad, // Object represents a quadrilateral 78 Quad, // Object represents a quadrilateral
77 Triangle, // Object represents a triangle 79 Triangle, // Object represents a triangle
78 Line, // Object represents a line 80 Line, // Object represents a line
79 CondLine, // Object represents a conditional line 81 CondLine, // Object represents a conditional line
80 Vertex, // Object is a vertex, LDForge extension object 82 Vertex, // Object is a vertex, LDForge extension object
81 BFC, // Object represents a BFC statement 83 BFC, // Object represents a BFC statement
82 Overlay, // Object contains meta-info about an overlay image. 84 Overlay, // Object contains meta-info about an overlay image.
83 Comment, // Object represents a comment 85 Comment, // Object represents a comment
84 Error, // Object is the result of failed parsing 86 Error, // Object is the result of failed parsing
86 Unidentified, // Object is an uninitialized (SHOULD NEVER HAPPEN) 88 Unidentified, // Object is an uninitialized (SHOULD NEVER HAPPEN)
87 NumTypes // Amount of object types 89 NumTypes // Amount of object types
88 }; 90 };
89 91
90 LDObject(); 92 LDObject();
91 virtual ~LDObject(); 93
92 94 // Makes a copy of this object
93 virtual LDObject* clone() 95 LDObject* createCopy() const;
94 { return 0; // Creates a new LDObject identical to this one. 96
95 } 97 // Deletes this object
96 long getIndex() const; // Index (i.e. line number) of this object 98 void deleteSelf();
97 virtual LDObject::Type getType() const; // Type enumerator of this object 99
98 const vertex& getVertex (int i) const; // Get a vertex by index 100 // Index (i.e. line number) of this object
99 virtual str getTypeName() const; // Type name of this object 101 long getIndex() const;
100 virtual bool hasMatrix() const; // Does this object have a matrix and position? (see LDMatrixObject) 102
101 virtual void invert(); // Inverts this object (winding is reversed) 103 // Type enumerator of this object
102 virtual bool isColored() const; // Is this object colored? 104 virtual LDObject::Type getType() const;
103 virtual bool isScemantic() const; // Does this object have meaning in the part model? 105
104 void move (vertex vect); // Moves this object using the given vertex as a movement List 106 // Get a vertex by index
105 LDObject* next() const; // Object after this in the current file 107 const vertex& getVertex (int i) const;
106 LDObject* prev() const; // Object prior to this in the current file 108
107 virtual str raw() { return ""; } // This object as LDraw code 109 // Type name of this object
108 void replace (LDObject* other); // Replace this LDObject with another LDObject. Object is deleted in the process. 110 virtual str getTypeName() const;
109 void select(); 111
110 void setVertex (int i, const vertex& vert); // Set a vertex to the given value 112 // Does this object have a matrix and position? (see LDMatrixObject)
111 void setVertexCoord (int i, Axis ax, double value); // Set a single coordinate of a vertex 113 virtual bool hasMatrix() const;
112 void swap (LDObject* other); // Swap this object with another. 114
113 LDObject* topLevelParent(); // What object in the current file ultimately references this? 115 // Inverts this object (winding is reversed)
114 void unselect(); 116 virtual void invert();
115 virtual int vertices() const; // Number of vertices this object has 117
116 118 // Is this object colored?
117 static str typeName (LDObject::Type type); // Get type name by enumerator 119 virtual bool isColored() const;
118 static LDObject* getDefault (const LDObject::Type type); // Returns a sample object by the given enumerator 120
119 static void moveObjects (QList<LDObject*> objs, const bool up); // TODO: move this to LDDocument? 121 // Does this object have meaning in the part model?
120 static str describeObjects (const QList<LDObject*>& objs); // Get a description of a list of LDObjects 122 virtual bool isScemantic() const;
123
124 // Moves this object using the given vertex as a movement List
125 void move (vertex vect);
126
127 // Object after this in the current file
128 LDObject* next() const;
129
130 // Object prior to this in the current file
131 LDObject* prev() const;
132
133 // This object as LDraw code
134 virtual str raw() const = 0;
135
136 // Replace this LDObject with another LDObject. Object is deleted in the process.
137 void replace (LDObject* other);
138
139 // Selects this object.
140 void select();
141
142 // Set a vertex to the given value
143 void setVertex (int i, const vertex& vert);
144
145 // Set a single coordinate of a vertex
146 void setVertexCoord (int i, Axis ax, double value);
147
148 // Swap this object with another.
149 void swap (LDObject* other);
150
151 // What object in the current file ultimately references this?
152 LDObject* topLevelParent();
153
154 // Removes this object from selection // TODO: rename to deselect?
155 void unselect();
156
157 // Number of vertices this object has // TODO: rename to getNumVertices
158 virtual int vertices() const;
159
160 // Get type name by enumerator
161 static str typeName (LDObject::Type type);
162
163 // Returns a sample object by the given enumerator
164 // TODO: Use of this function only really results in hacks, get rid of it!
165 static LDObject* getDefault (const LDObject::Type type);
166
167 // TODO: move this to LDDocument?
168 static void moveObjects (QList<LDObject*> objs, const bool up);
169
170 // Get a description of a list of LDObjects
171 static str describeObjects (const QList<LDObject*>& objs);
121 static LDObject* fromID (int id); 172 static LDObject* fromID (int id);
122 173
123 // TODO: make these private! 174 // TODO: make these private!
124 // OpenGL list for this object 175 // OpenGL list for this object
125 uint glLists[4]; 176 uint glLists[4];
126 177
127 // Object list entry for this object 178 // Object list entry for this object
128 QListWidgetItem* qObjListEntry; 179 QListWidgetItem* qObjListEntry;
129 180
130 protected: 181 protected:
131 bool m_glinit; 182 // LDObjects are to be deleted with the deleteSelf() method, not with
132 friend class GLRenderer; 183 // operator delete. This is because it seems virtual functions cannot
184 // be properly called from the destructor, thus a normal method must
185 // be used instead. The destructor also doesn't seem to be able to
186 // be private without causing a truckload of problems so it's protected
187 // instead.
188 virtual ~LDObject();
189 void chooseID();
133 190
134 private: 191 private:
192 virtual LDObject* clone() = 0;
135 LDSharedVertex* m_coords[4]; 193 LDSharedVertex* m_coords[4];
136 }; 194 };
137 195
138 // ============================================================================= 196 // =============================================================================
139 // LDSharedVertex 197 // LDSharedVertex
336 LDSubfile() 394 LDSubfile()
337 { setLinkPointer (this); 395 { setLinkPointer (this);
338 } 396 }
339 397
340 // Inlines this subfile. Note that return type is an array of heap-allocated 398 // Inlines this subfile. Note that return type is an array of heap-allocated
341 // LDObject-clones, they must be deleted one way or another. 399 // LDObject copies, they must be deleted manually.
342 QList<LDObject*> inlineContents (InlineFlags flags); 400 QList<LDObject*> inlineContents (InlineFlags flags);
343 }; 401 };
344 402
345 Q_DECLARE_OPERATORS_FOR_FLAGS (LDSubfile::InlineFlags) 403 Q_DECLARE_OPERATORS_FOR_FLAGS (LDSubfile::InlineFlags)
346 404

mercurial