src/ldObject.cpp

changeset 1000
c064cc048f14
parent 998
5be0ce31ce60
child 1002
a3ee23db8393
equal deleted inserted replaced
999:213a7c7a3ce4 1000:c064cc048f14
77 LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine) 77 LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine)
78 LDOBJ_DEFAULT_CTOR (LDQuad, LDObject) 78 LDOBJ_DEFAULT_CTOR (LDQuad, LDObject)
79 LDOBJ_DEFAULT_CTOR (LDOverlay, LDObject) 79 LDOBJ_DEFAULT_CTOR (LDOverlay, LDObject)
80 LDOBJ_DEFAULT_CTOR (LDBfc, LDObject) 80 LDOBJ_DEFAULT_CTOR (LDBfc, LDObject)
81 LDOBJ_DEFAULT_CTOR (LDComment, LDObject) 81 LDOBJ_DEFAULT_CTOR (LDComment, LDObject)
82 LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject)
82 83
83 LDObject::~LDObject() 84 LDObject::~LDObject()
84 { 85 {
85 if (not m_isDestroyed) 86 if (not m_isDestroyed)
86 print ("Warning: Object #%1 (%2) was not destroyed before being deleted\n", id(), this); 87 print ("Warning: Object #%1 (%2) was not destroyed before being deleted\n", id(), this);
143 // ============================================================================= 144 // =============================================================================
144 // 145 //
145 QString LDCondLine::asText() const 146 QString LDCondLine::asText() const
146 { 147 {
147 QString val = format ("5 %1", color()); 148 QString val = format ("5 %1", color());
148 149
149 // Add the coordinates 150 // Add the coordinates
150 for (int i = 0; i < 4; ++i) 151 for (int i = 0; i < 4; ++i)
151 val += format (" %1", vertex (i)); 152 val += format (" %1", vertex (i));
152 153
153 return val; 154 return val;
155 }
156
157 QString LDBezierCurve::asText() const
158 {
159 QString result = format ("0 !LDFORGE BEZIER_CURVE %1", color());
160
161 // Add the coordinates
162 for (int i = 0; i < 4; ++i)
163 result += format (" %1", vertex (i));
164
165 return result;
154 } 166 }
155 167
156 // ============================================================================= 168 // =============================================================================
157 // 169 //
158 QString LDError::asText() const 170 QString LDError::asText() const
254 266
255 // ============================================================================= 267 // =============================================================================
256 // 268 //
257 LDCondLine::LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document) : 269 LDCondLine::LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document) :
258 LDLine (document) 270 LDLine (document)
271 {
272 setVertex (0, v0);
273 setVertex (1, v1);
274 setVertex (2, v2);
275 setVertex (3, v3);
276 }
277
278 // =============================================================================
279 //
280 LDBezierCurve::LDBezierCurve(const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3,
281 LDDocument* document) :
282 LDObject (document)
259 { 283 {
260 setVertex (0, v0); 284 setVertex (0, v0);
261 setVertex (1, v1); 285 setVertex (1, v1);
262 setVertex (2, v2); 286 setVertex (2, v2);
263 setVertex (3, v3); 287 setVertex (3, v3);
598 // 622 //
599 LDObject* LDObject::getDefault (const LDObjectType type) 623 LDObject* LDObject::getDefault (const LDObjectType type)
600 { 624 {
601 switch (type) 625 switch (type)
602 { 626 {
603 case OBJ_Comment: return LDSpawn<LDComment>(); 627 case OBJ_Comment: return LDSpawn<LDComment>();
604 case OBJ_Bfc: return LDSpawn<LDBfc>(); 628 case OBJ_Bfc: return LDSpawn<LDBfc>();
605 case OBJ_Line: return LDSpawn<LDLine>(); 629 case OBJ_Line: return LDSpawn<LDLine>();
606 case OBJ_CondLine: return LDSpawn<LDCondLine>(); 630 case OBJ_CondLine: return LDSpawn<LDCondLine>();
607 case OBJ_Subfile: return LDSpawn<LDSubfile>(); 631 case OBJ_Subfile: return LDSpawn<LDSubfile>();
608 case OBJ_Triangle: return LDSpawn<LDTriangle>(); 632 case OBJ_Triangle: return LDSpawn<LDTriangle>();
609 case OBJ_Quad: return LDSpawn<LDQuad>(); 633 case OBJ_Quad: return LDSpawn<LDQuad>();
610 case OBJ_Empty: return LDSpawn<LDEmpty>(); 634 case OBJ_Empty: return LDSpawn<LDEmpty>();
611 case OBJ_Error: return LDSpawn<LDError>(); 635 case OBJ_Error: return LDSpawn<LDError>();
612 case OBJ_Overlay: return LDSpawn<LDOverlay>(); 636 case OBJ_Overlay: return LDSpawn<LDOverlay>();
613 case OBJ_NumTypes: break; 637 case OBJ_BezierCurve: return LDSpawn<LDBezierCurve>();
638 case OBJ_NumTypes: break;
614 } 639 }
615 return nullptr; 640 return nullptr;
616 } 641 }
617 642
618 // ============================================================================= 643 // =============================================================================
733 { 758 {
734 // I don't think that a conditional line's control points need to be swapped, do they? 759 // I don't think that a conditional line's control points need to be swapped, do they?
735 Vertex tmp = vertex (0); 760 Vertex tmp = vertex (0);
736 setVertex (0, vertex (1)); 761 setVertex (0, vertex (1));
737 setVertex (1, tmp); 762 setVertex (1, tmp);
763 }
764
765 // =============================================================================
766 //
767 void LDBezierCurve::invert()
768 {
769 // A Bézier curve's control points probably need to be, though.
770 Vertex tmp = vertex (1);
771 setVertex (1, vertex (0));
772 setVertex (0, tmp);
773 tmp = vertex (3);
774 setVertex (3, vertex (2));
775 setVertex (2, tmp);
738 } 776 }
739 777
740 // ============================================================================= 778 // =============================================================================
741 // 779 //
742 LDLine* LDCondLine::toEdgeLine() 780 LDLine* LDCondLine::toEdgeLine()

mercurial