38 LDObject::LDObject() : |
38 LDObject::LDObject() : |
39 m_Hidden (false), |
39 m_Hidden (false), |
40 m_Selected (false), |
40 m_Selected (false), |
41 m_Parent (null), |
41 m_Parent (null), |
42 m_File (null), |
42 m_File (null), |
43 qObjListEntry (null), |
43 m_GLInit (false), |
44 m_glinit (false) |
44 qObjListEntry (null) |
45 { |
45 { memset (m_coords, 0, sizeof m_coords); |
46 memset (m_coords, 0, sizeof m_coords); |
46 chooseID(); |
47 |
47 g_LDObjects << this; |
48 // Determine ID |
48 } |
49 int32 id = 1; // 0 is invalid |
49 |
|
50 // ============================================================================= |
|
51 // ----------------------------------------------------------------------------- |
|
52 void LDObject::chooseID() |
|
53 { int32 id = 1; // 0 is invalid |
50 |
54 |
51 for (LDObject* obj : g_LDObjects) |
55 for (LDObject* obj : g_LDObjects) |
52 if (obj->getID() >= id) |
56 if (obj->getID() >= id) |
53 id = obj->getID() + 1; |
57 id = obj->getID() + 1; |
54 |
58 |
55 setID (id); |
59 setID (id); |
56 g_LDObjects << this; |
|
57 } |
60 } |
58 |
61 |
59 // ============================================================================= |
62 // ============================================================================= |
60 // Default implementations for LDObject's virtual methods. These should never be |
63 // Default implementations for LDObject's virtual methods. These should never be |
61 // actually called, for a subclass-less LDObject should never come into existance. |
64 // actually called, for a subclass-less LDObject should never come into existance. |
95 |
98 |
96 LDError::LDError() {} |
99 LDError::LDError() {} |
97 |
100 |
98 // ============================================================================= |
101 // ============================================================================= |
99 // ----------------------------------------------------------------------------- |
102 // ----------------------------------------------------------------------------- |
100 str LDComment::raw() |
103 str LDComment::raw() const |
101 { return fmt ("0 %1", text); |
104 { return fmt ("0 %1", text); |
102 } |
105 } |
103 |
106 |
104 // ============================================================================= |
107 // ============================================================================= |
105 // ----------------------------------------------------------------------------- |
108 // ----------------------------------------------------------------------------- |
106 str LDSubfile::raw() |
109 str LDSubfile::raw() const |
107 { str val = fmt ("1 %1 %2 ", getColor(), getPosition()); |
110 { str val = fmt ("1 %1 %2 ", getColor(), getPosition()); |
108 val += getTransform().stringRep(); |
111 val += getTransform().stringRep(); |
109 val += ' '; |
112 val += ' '; |
110 val += getFileInfo()->getName(); |
113 val += getFileInfo()->getName(); |
111 return val; |
114 return val; |
112 } |
115 } |
113 |
116 |
114 // ============================================================================= |
117 // ============================================================================= |
115 // ----------------------------------------------------------------------------- |
118 // ----------------------------------------------------------------------------- |
116 str LDLine::raw() |
119 str LDLine::raw() const |
117 { str val = fmt ("2 %1", getColor()); |
120 { str val = fmt ("2 %1", getColor()); |
118 |
121 |
119 for (int i = 0; i < 2; ++i) |
122 for (int i = 0; i < 2; ++i) |
120 val += fmt (" %1", getVertex (i)); |
123 val += fmt (" %1", getVertex (i)); |
121 |
124 |
122 return val; |
125 return val; |
123 } |
126 } |
124 |
127 |
125 // ============================================================================= |
128 // ============================================================================= |
126 // ----------------------------------------------------------------------------- |
129 // ----------------------------------------------------------------------------- |
127 str LDTriangle::raw() |
130 str LDTriangle::raw() const |
128 { str val = fmt ("3 %1", getColor()); |
131 { str val = fmt ("3 %1", getColor()); |
129 |
132 |
130 for (int i = 0; i < 3; ++i) |
133 for (int i = 0; i < 3; ++i) |
131 val += fmt (" %1", getVertex (i)); |
134 val += fmt (" %1", getVertex (i)); |
132 |
135 |
133 return val; |
136 return val; |
134 } |
137 } |
135 |
138 |
136 // ============================================================================= |
139 // ============================================================================= |
137 // ----------------------------------------------------------------------------- |
140 // ----------------------------------------------------------------------------- |
138 str LDQuad::raw() |
141 str LDQuad::raw() const |
139 { str val = fmt ("4 %1", getColor()); |
142 { str val = fmt ("4 %1", getColor()); |
140 |
143 |
141 for (int i = 0; i < 4; ++i) |
144 for (int i = 0; i < 4; ++i) |
142 val += fmt (" %1", getVertex (i)); |
145 val += fmt (" %1", getVertex (i)); |
143 |
146 |
144 return val; |
147 return val; |
145 } |
148 } |
146 |
149 |
147 // ============================================================================= |
150 // ============================================================================= |
148 // ----------------------------------------------------------------------------- |
151 // ----------------------------------------------------------------------------- |
149 str LDCondLine::raw() |
152 str LDCondLine::raw() const |
150 { str val = fmt ("5 %1", getColor()); |
153 { str val = fmt ("5 %1", getColor()); |
151 |
154 |
152 // Add the coordinates |
155 // Add the coordinates |
153 for (int i = 0; i < 4; ++i) |
156 for (int i = 0; i < 4; ++i) |
154 val += fmt (" %1", getVertex (i)); |
157 val += fmt (" %1", getVertex (i)); |
156 return val; |
159 return val; |
157 } |
160 } |
158 |
161 |
159 // ============================================================================= |
162 // ============================================================================= |
160 // ----------------------------------------------------------------------------- |
163 // ----------------------------------------------------------------------------- |
161 str LDError::raw() |
164 str LDError::raw() const |
162 { return contents; |
165 { return contents; |
163 } |
166 } |
164 |
167 |
165 // ============================================================================= |
168 // ============================================================================= |
166 // ----------------------------------------------------------------------------- |
169 // ----------------------------------------------------------------------------- |
167 str LDVertex::raw() |
170 str LDVertex::raw() const |
168 { return fmt ("0 !LDFORGE VERTEX %1 %2", getColor(), pos); |
171 { return fmt ("0 !LDFORGE VERTEX %1 %2", getColor(), pos); |
169 } |
172 } |
170 |
173 |
171 // ============================================================================= |
174 // ============================================================================= |
172 // ----------------------------------------------------------------------------- |
175 // ----------------------------------------------------------------------------- |
173 str LDEmpty::raw() |
176 str LDEmpty::raw() const |
174 { return ""; |
177 { return ""; |
175 } |
178 } |
176 |
179 |
177 // ============================================================================= |
180 // ============================================================================= |
178 // ----------------------------------------------------------------------------- |
181 // ----------------------------------------------------------------------------- |
261 setVertex (3, v3); |
264 setVertex (3, v3); |
262 } |
265 } |
263 |
266 |
264 // ============================================================================= |
267 // ============================================================================= |
265 // ----------------------------------------------------------------------------- |
268 // ----------------------------------------------------------------------------- |
266 LDObject::~LDObject() |
269 LDObject::~LDObject() {} |
267 { // If this object was selected, unselect it now |
270 |
|
271 // ============================================================================= |
|
272 // ----------------------------------------------------------------------------- |
|
273 void LDObject::deleteSelf() |
|
274 { dlog( "#%1: type: %2\n", getID(), getType()); |
|
275 |
|
276 // If this object was selected, unselect it now |
268 if (isSelected()) |
277 if (isSelected()) |
269 unselect(); |
278 unselect(); |
270 |
279 |
271 // If this object was associated to a file, remove it off it now |
280 // If this object was associated to a file, remove it off it now |
272 if (getFile()) |
281 if (getFile()) |
275 // Delete the GL lists |
284 // Delete the GL lists |
276 GL::deleteLists (this); |
285 GL::deleteLists (this); |
277 |
286 |
278 // Remove this object from the list of LDObjects |
287 // Remove this object from the list of LDObjects |
279 g_LDObjects.removeOne (this); |
288 g_LDObjects.removeOne (this); |
|
289 |
|
290 delete this; |
280 } |
291 } |
281 |
292 |
282 // ============================================================================= |
293 // ============================================================================= |
283 // ----------------------------------------------------------------------------- |
294 // ----------------------------------------------------------------------------- |
284 static void transformObject (LDObject* obj, matrix transform, vertex pos, int parentcolor) |
295 static void transformObject (LDObject* obj, matrix transform, vertex pos, int parentcolor) |
319 // ----------------------------------------------------------------------------- |
330 // ----------------------------------------------------------------------------- |
320 QList<LDObject*> LDSubfile::inlineContents (InlineFlags flags) |
331 QList<LDObject*> LDSubfile::inlineContents (InlineFlags flags) |
321 { QList<LDObject*> objs = getFileInfo()->inlineContents (flags); |
332 { QList<LDObject*> objs = getFileInfo()->inlineContents (flags); |
322 |
333 |
323 // Transform the objects |
334 // Transform the objects |
324 for (LDObject * obj : objs) |
335 for (LDObject* obj : objs) |
325 { // Set the parent now so we know what inlined this. |
336 { // Set the parent now so we know what inlined the object. |
326 obj->setParent (this); |
337 obj->setParent (this); |
327 transformObject (obj, getTransform(), getPosition(), getColor()); |
338 transformObject (obj, getTransform(), getPosition(), getColor()); |
328 } |
339 } |
329 |
340 |
330 return objs; |
341 return objs; |
331 } |
342 } |
332 |
343 |
333 // ============================================================================= |
344 // ============================================================================= |
334 // ----------------------------------------------------------------------------- |
345 // ----------------------------------------------------------------------------- |
335 long LDObject::getIndex() const |
346 long LDObject::getIndex() const |
336 { |
347 { assert (getFile() != null); |
337 #ifndef RELEASE |
|
338 assert (getFile() != null); |
|
339 #endif |
|
340 |
348 |
341 for (int i = 0; i < getFile()->getObjectCount(); ++i) |
349 for (int i = 0; i < getFile()->getObjectCount(); ++i) |
342 if (getFile()->getObject (i) == this) |
350 if (getFile()->getObject (i) == this) |
343 return i; |
351 return i; |
344 |
352 |
611 return null; |
618 return null; |
612 } |
619 } |
613 |
620 |
614 // ============================================================================= |
621 // ============================================================================= |
615 // ----------------------------------------------------------------------------- |
622 // ----------------------------------------------------------------------------- |
616 str LDOverlay::raw() |
623 str LDOverlay::raw() const |
617 { return fmt ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6", |
624 { return fmt ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6", |
618 getFileName(), getCamera(), getX(), getY(), getWidth(), getHeight()); |
625 getFileName(), getCamera(), getX(), getY(), getWidth(), getHeight()); |
619 } |
626 } |
620 |
627 |
621 void LDOverlay::invert() {} |
628 void LDOverlay::invert() {} |
742 } |
751 } |
743 |
752 |
744 assert (false); |
753 assert (false); |
745 return ""; |
754 return ""; |
746 } |
755 } |
|
756 |
|
757 // ============================================================================= |
|
758 // ----------------------------------------------------------------------------- |
|
759 LDObject* LDObject::createCopy() const |
|
760 { /* |
|
761 LDObject* copy = clone(); |
|
762 copy->setFile (null); |
|
763 copy->setGLInit (false); |
|
764 copy->chooseID(); |
|
765 copy->setSelected (false); |
|
766 */ |
|
767 |
|
768 /* |
|
769 LDObject* copy = getDefault (getType()); |
|
770 copy->setColor (getColor()); |
|
771 |
|
772 if (hasMatrix()) |
|
773 { LDMatrixObject* copyMo = static_cast<LDMatrixObject*> (copy); |
|
774 const LDMatrixObject* mo = static_cast<const LDMatrixObject*> (this); |
|
775 copyMo->setPosition (mo->getPosition()); |
|
776 copyMo->setTransform (mo->getTransform()); |
|
777 } |
|
778 else |
|
779 { for (int i = 0; i < vertices(); ++i) |
|
780 copy->setVertex (getVertex (i)); |
|
781 } |
|
782 |
|
783 switch (getType()) |
|
784 { case Subfile: |
|
785 { LDSubfile* copyRef = static_cast<LDSubfile*> (copy); |
|
786 const LDSubfile* ref = static_cast<const LDSubfile*> (this); |
|
787 |
|
788 copyRef->setFileInfo (ref->getFileInfo()); |
|
789 } |
|
790 } |
|
791 */ |
|
792 |
|
793 LDObject* copy = parseLine (raw()); |
|
794 return copy; |
|
795 } |