65 } |
65 } |
66 |
66 |
67 LDSubfileReference::LDSubfileReference (Model* model) : |
67 LDSubfileReference::LDSubfileReference (Model* model) : |
68 LDMatrixObject (model) {} |
68 LDMatrixObject (model) {} |
69 |
69 |
70 LDOBJ_DEFAULT_CTOR (LDEmpty, LDObject) |
|
71 LDOBJ_DEFAULT_CTOR (LDError, LDObject) |
70 LDOBJ_DEFAULT_CTOR (LDError, LDObject) |
72 LDOBJ_DEFAULT_CTOR (LDLine, LDObject) |
71 LDOBJ_DEFAULT_CTOR (LDLine, LDObject) |
73 LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject) |
72 LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject) |
74 LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine) |
73 LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine) |
75 LDOBJ_DEFAULT_CTOR (LDQuad, LDObject) |
74 LDOBJ_DEFAULT_CTOR (LDQuad, LDObject) |
76 LDOBJ_DEFAULT_CTOR (LDBfc, LDObject) |
75 LDOBJ_DEFAULT_CTOR (LDBfc, LDObject) |
77 LDOBJ_DEFAULT_CTOR (LDComment, LDObject) |
|
78 LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject) |
76 LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject) |
79 |
77 |
80 LDObject::~LDObject() |
78 LDObject::~LDObject() |
81 { |
79 { |
82 // Delete the GL lists |
80 // Delete the GL lists |
83 if (g_win) |
81 if (g_win) |
84 g_win->renderer()->forgetObject(this); |
82 g_win->renderer()->forgetObject(this); |
85 |
83 |
86 // Remove this object from the list of LDObjects |
84 // Remove this object from the list of LDObjects |
87 g_allObjects.erase(g_allObjects.find(id())); |
85 g_allObjects.erase(g_allObjects.find(id())); |
88 } |
|
89 |
|
90 // ============================================================================= |
|
91 // |
|
92 QString LDComment::asText() const |
|
93 { |
|
94 return format ("0 %1", text()); |
|
95 } |
86 } |
96 |
87 |
97 // ============================================================================= |
88 // ============================================================================= |
98 // |
89 // |
99 QString LDSubfileReference::asText() const |
90 QString LDSubfileReference::asText() const |
349 data->vertices[i] = vertex (i); |
338 data->vertices[i] = vertex (i); |
350 |
339 |
351 return data; |
340 return data; |
352 } |
341 } |
353 |
342 |
|
343 LDColor LDObject::defaultColor() const |
|
344 { |
|
345 return MainColor; |
|
346 } |
|
347 |
|
348 bool LDObject::isColored() const |
|
349 { |
|
350 return true; |
|
351 } |
|
352 |
|
353 bool LDObject::isScemantic() const |
|
354 { |
|
355 return true; |
|
356 } |
|
357 |
|
358 bool LDObject::hasMatrix() const |
|
359 { |
|
360 return false; |
|
361 } |
|
362 |
354 // ============================================================================= |
363 // ============================================================================= |
355 // |
364 // |
356 QList<LDPolygon> LDSubfileReference::inlinePolygons() |
365 QList<LDPolygon> LDSubfileReference::inlinePolygons() |
357 { |
366 { |
358 QList<LDPolygon> data = fileInfo()->inlinePolygons(); |
367 QList<LDPolygon> data = fileInfo()->inlinePolygons(); |
474 |
483 |
475 // ============================================================================= |
484 // ============================================================================= |
476 // |
485 // |
477 void LDObject::invert() {} |
486 void LDObject::invert() {} |
478 void LDBfc::invert() {} |
487 void LDBfc::invert() {} |
479 void LDEmpty::invert() {} |
|
480 void LDComment::invert() {} |
|
481 void LDError::invert() {} |
488 void LDError::invert() {} |
482 |
489 |
483 // ============================================================================= |
490 // ============================================================================= |
484 // |
491 // |
485 void LDTriangle::invert() |
492 void LDTriangle::invert() |
628 return g_allObjects.value(id); |
635 return g_allObjects.value(id); |
629 } |
636 } |
630 |
637 |
631 // ============================================================================= |
638 // ============================================================================= |
632 // |
639 // |
633 // Hook the set accessors of certain properties to this changeProperty function. |
|
634 // It takes care of history management so we can capture low-level changes, this |
|
635 // makes history stuff work out of the box. |
|
636 // |
|
637 template<typename T> |
|
638 static void changeProperty(LDObject* object, T* property, const T& value) |
|
639 { |
|
640 if (*property == value) |
|
641 return; |
|
642 |
|
643 int position = object->lineNumber(); |
|
644 |
|
645 if (position != -1) |
|
646 { |
|
647 QString before = object->asText(); |
|
648 *property = value; |
|
649 emit object->codeChanged(position, before, object->asText()); |
|
650 } |
|
651 else |
|
652 { |
|
653 *property = value; |
|
654 } |
|
655 } |
|
656 |
|
657 // ============================================================================= |
|
658 // |
|
659 void LDObject::setColor (LDColor color) |
640 void LDObject::setColor (LDColor color) |
660 { |
641 { |
661 changeProperty (this, &m_color, color); |
642 changeProperty(&m_color, color); |
662 } |
643 } |
663 |
644 |
664 // ============================================================================= |
645 // ============================================================================= |
665 // |
646 // |
666 // Get a vertex by index |
647 // Get a vertex by index |
674 // |
655 // |
675 // Set a vertex to the given value |
656 // Set a vertex to the given value |
676 // |
657 // |
677 void LDObject::setVertex (int i, const Vertex& vert) |
658 void LDObject::setVertex (int i, const Vertex& vert) |
678 { |
659 { |
679 changeProperty (this, &m_coords[i], vert); |
660 changeProperty(&m_coords[i], vert); |
680 } |
661 } |
681 |
662 |
682 LDMatrixObject::LDMatrixObject (Model* model) : |
663 LDMatrixObject::LDMatrixObject (Model* model) : |
683 LDObject (model), |
664 LDObject (model), |
684 m_position (Origin) {} |
665 m_position (Origin) {} |
709 |
690 |
710 // ============================================================================= |
691 // ============================================================================= |
711 // |
692 // |
712 void LDMatrixObject::setPosition (const Vertex& a) |
693 void LDMatrixObject::setPosition (const Vertex& a) |
713 { |
694 { |
714 changeProperty (this, &m_position, a); |
695 changeProperty(&m_position, a); |
715 } |
696 } |
716 |
697 |
717 // ============================================================================= |
698 // ============================================================================= |
718 // |
699 // |
719 const Matrix& LDMatrixObject::transformationMatrix() const |
700 const Matrix& LDMatrixObject::transformationMatrix() const |
721 return m_transformationMatrix; |
702 return m_transformationMatrix; |
722 } |
703 } |
723 |
704 |
724 void LDMatrixObject::setTransformationMatrix (const Matrix& val) |
705 void LDMatrixObject::setTransformationMatrix (const Matrix& val) |
725 { |
706 { |
726 changeProperty (this, &m_transformationMatrix, val); |
707 changeProperty(&m_transformationMatrix, val); |
727 } |
708 } |
728 |
709 |
729 LDError::LDError (QString contents, QString reason, Model* model) : |
710 LDError::LDError (QString contents, QString reason, Model* model) : |
730 LDObject (model), |
711 LDObject (model), |
731 m_contents (contents), |
712 m_contents (contents), |
747 } |
728 } |
748 |
729 |
749 void LDError::setFileReferenced (QString value) |
730 void LDError::setFileReferenced (QString value) |
750 { |
731 { |
751 m_fileReferenced = value; |
732 m_fileReferenced = value; |
752 } |
|
753 |
|
754 LDComment::LDComment (QString text, Model* model) : |
|
755 LDObject {model}, |
|
756 m_text {text} {} |
|
757 |
|
758 QString LDComment::text() const |
|
759 { |
|
760 return m_text; |
|
761 } |
|
762 |
|
763 void LDComment::setText (QString value) |
|
764 { |
|
765 changeProperty (this, &m_text, value); |
|
766 } |
733 } |
767 |
734 |
768 LDBfc::LDBfc (const BfcStatement type, Model* model) : |
735 LDBfc::LDBfc (const BfcStatement type, Model* model) : |
769 LDObject {model}, |
736 LDObject {model}, |
770 m_statement {type} {} |
737 m_statement {type} {} |
869 return m_fileInfo; |
836 return m_fileInfo; |
870 } |
837 } |
871 |
838 |
872 void LDSubfileReference::setFileInfo (LDDocument* newReferee) |
839 void LDSubfileReference::setFileInfo (LDDocument* newReferee) |
873 { |
840 { |
874 changeProperty (this, &m_fileInfo, newReferee); |
841 changeProperty(&m_fileInfo, newReferee); |
875 |
842 |
876 if (model()) |
843 if (model()) |
877 model()->recountTriangles(); |
844 model()->recountTriangles(); |
878 |
845 |
879 // If it's an immediate subfile reference (i.e. this subfile is in an opened document), we need to pre-compile the |
846 // If it's an immediate subfile reference (i.e. this subfile is in an opened document), we need to pre-compile the |