42 // LDObject constructors |
42 // LDObject constructors |
43 // |
43 // |
44 LDObject::LDObject() : |
44 LDObject::LDObject() : |
45 m_isHidden {false} |
45 m_isHidden {false} |
46 { |
46 { |
47 // Let's hope that nobody goes to create 17 million objects anytime soon... |
|
48 static qint32 nextId = 1; // 0 shalt be null |
|
49 if (nextId < MAX_LDOBJECT_IDS) |
|
50 m_id = nextId++; |
|
51 else |
|
52 m_id = 0; |
|
53 |
|
54 if (m_id != 0) |
|
55 g_allObjects[m_id] = this; |
|
56 |
|
57 m_randomColor = QColor::fromHsv (rand() % 360, rand() % 256, rand() % 96 + 128); |
47 m_randomColor = QColor::fromHsv (rand() % 360, rand() % 256, rand() % 96 + 128); |
58 } |
|
59 |
|
60 LDObject::~LDObject() |
|
61 { |
|
62 // Remove this object from the list of LDObjects |
|
63 g_allObjects.erase(g_allObjects.find(id())); |
|
64 } |
48 } |
65 |
49 |
66 // ============================================================================= |
50 // ============================================================================= |
67 // |
51 // |
68 QString LDSubfileReference::asText() const |
52 QString LDSubfileReference::asText() const |
266 void LDObject::setHidden (bool value) |
249 void LDObject::setHidden (bool value) |
267 { |
250 { |
268 m_isHidden = value; |
251 m_isHidden = value; |
269 } |
252 } |
270 |
253 |
271 qint32 LDObject::id() const |
|
272 { |
|
273 return m_id; |
|
274 } |
|
275 |
|
276 LDColor LDObject::color() const |
254 LDColor LDObject::color() const |
277 { |
255 { |
278 return m_color; |
256 return m_color; |
279 } |
257 } |
280 |
258 |
281 QColor LDObject::randomColor() const |
259 QColor LDObject::randomColor() const |
282 { |
260 { |
283 return m_randomColor; |
261 return m_randomColor; |
284 } |
|
285 |
|
286 // ============================================================================= |
|
287 // |
|
288 LDObject* LDObject::fromID(qint32 id) |
|
289 { |
|
290 return g_allObjects.value(id); |
|
291 } |
262 } |
292 |
263 |
293 LDObject* LDObject::newFromType(LDObjectType type) |
264 LDObject* LDObject::newFromType(LDObjectType type) |
294 { |
265 { |
295 switch (type) |
266 switch (type) |
488 parms.append (pointAt (double (i) / segments)); |
459 parms.append (pointAt (double (i) / segments)); |
489 |
460 |
490 parms.append (pointAt (1.0)); |
461 parms.append (pointAt (1.0)); |
491 LDPolygon poly; |
462 LDPolygon poly; |
492 poly.color = color().index(); |
463 poly.color = color().index(); |
493 poly.id = id(); |
|
494 poly.num = 2; |
464 poly.num = 2; |
495 |
465 |
496 for (int i = 0; i < segments; ++i) |
466 for (int i = 0; i < segments; ++i) |
497 { |
467 { |
498 poly.vertices[0] = parms[i]; |
468 poly.vertices[0] = parms[i]; |
589 |
559 |
590 void LDObject::serialize(Serializer& serializer) |
560 void LDObject::serialize(Serializer& serializer) |
591 { |
561 { |
592 serializer << m_hasInvertNext; |
562 serializer << m_hasInvertNext; |
593 serializer << m_isHidden; |
563 serializer << m_isHidden; |
594 serializer << m_id; |
|
595 serializer << m_color; |
564 serializer << m_color; |
596 serializer << m_randomColor; |
565 serializer << m_randomColor; |
597 serializer << m_coords[0]; |
566 serializer << m_coords[0]; |
598 serializer << m_coords[1]; |
567 serializer << m_coords[1]; |
599 serializer << m_coords[2]; |
568 serializer << m_coords[2]; |