62 |
62 |
63 LDSubfileReference::LDSubfileReference (Model* model) : |
63 LDSubfileReference::LDSubfileReference (Model* model) : |
64 LDMatrixObject (model) {} |
64 LDMatrixObject (model) {} |
65 |
65 |
66 LDOBJ_DEFAULT_CTOR (LDError, LDObject) |
66 LDOBJ_DEFAULT_CTOR (LDError, LDObject) |
67 LDOBJ_DEFAULT_CTOR (LDLine, LDObject) |
67 LDOBJ_DEFAULT_CTOR (LDEdgeLine, LDObject) |
68 LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject) |
68 LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject) |
69 LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine) |
69 LDOBJ_DEFAULT_CTOR (LDConditionalEdge, LDEdgeLine) |
70 LDOBJ_DEFAULT_CTOR (LDQuad, LDObject) |
70 LDOBJ_DEFAULT_CTOR (LDQuadrilateral, LDObject) |
71 LDOBJ_DEFAULT_CTOR (LDBfc, LDObject) |
71 LDOBJ_DEFAULT_CTOR (LDBfc, LDObject) |
72 LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject) |
72 LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject) |
73 |
73 |
74 LDObject::~LDObject() |
74 LDObject::~LDObject() |
75 { |
75 { |
92 return val; |
92 return val; |
93 } |
93 } |
94 |
94 |
95 // ============================================================================= |
95 // ============================================================================= |
96 // |
96 // |
97 QString LDLine::asText() const |
97 QString LDEdgeLine::asText() const |
98 { |
98 { |
99 QString val = format ("2 %1", color()); |
99 QString val = format ("2 %1", color()); |
100 |
100 |
101 for (int i = 0; i < 2; ++i) |
101 for (int i = 0; i < 2; ++i) |
102 val += format (" %1", vertex (i)); |
102 val += format (" %1", vertex (i)); |
116 return val; |
116 return val; |
117 } |
117 } |
118 |
118 |
119 // ============================================================================= |
119 // ============================================================================= |
120 // |
120 // |
121 QString LDQuad::asText() const |
121 QString LDQuadrilateral::asText() const |
122 { |
122 { |
123 QString val = format ("4 %1", color()); |
123 QString val = format ("4 %1", color()); |
124 |
124 |
125 for (int i = 0; i < 4; ++i) |
125 for (int i = 0; i < 4; ++i) |
126 val += format (" %1", vertex (i)); |
126 val += format (" %1", vertex (i)); |
128 return val; |
128 return val; |
129 } |
129 } |
130 |
130 |
131 // ============================================================================= |
131 // ============================================================================= |
132 // |
132 // |
133 QString LDCondLine::asText() const |
133 QString LDConditionalEdge::asText() const |
134 { |
134 { |
135 QString val = format ("5 %1", color()); |
135 QString val = format ("5 %1", color()); |
136 |
136 |
137 // Add the coordinates |
137 // Add the coordinates |
138 for (int i = 0; i < 4; ++i) |
138 for (int i = 0; i < 4; ++i) |
220 setVertex (2, v3); |
220 setVertex (2, v3); |
221 } |
221 } |
222 |
222 |
223 // ============================================================================= |
223 // ============================================================================= |
224 // |
224 // |
225 LDQuad::LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model) : |
225 LDQuadrilateral::LDQuadrilateral (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model) : |
226 LDObject {model} |
226 LDObject {model} |
227 { |
227 { |
228 setVertex (0, v1); |
228 setVertex (0, v1); |
229 setVertex (1, v2); |
229 setVertex (1, v2); |
230 setVertex (2, v3); |
230 setVertex (2, v3); |
231 setVertex (3, v4); |
231 setVertex (3, v4); |
232 } |
232 } |
233 |
233 |
234 // ============================================================================= |
234 // ============================================================================= |
235 // |
235 // |
236 LDCondLine::LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : |
236 LDConditionalEdge::LDConditionalEdge (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : |
237 LDLine {model} |
237 LDEdgeLine {model} |
238 { |
238 { |
239 setVertex (0, v0); |
239 setVertex (0, v0); |
240 setVertex (1, v1); |
240 setVertex (1, v1); |
241 setVertex (2, v2); |
241 setVertex (2, v2); |
242 setVertex (3, v3); |
242 setVertex (3, v3); |
264 // |
264 // |
265 static void TransformObject (LDObject* obj, Matrix transform, Vertex pos, LDColor parentcolor) |
265 static void TransformObject (LDObject* obj, Matrix transform, Vertex pos, LDColor parentcolor) |
266 { |
266 { |
267 switch (obj->type()) |
267 switch (obj->type()) |
268 { |
268 { |
269 case LDObjectType::Line: |
269 case LDObjectType::EdgeLine: |
270 case LDObjectType::CondLine: |
270 case LDObjectType::ConditionalEdge: |
271 case LDObjectType::Triangle: |
271 case LDObjectType::Triangle: |
272 case LDObjectType::Quad: |
272 case LDObjectType::Quadrilateral: |
273 for (int i = 0; i < obj->numVertices(); ++i) |
273 for (int i = 0; i < obj->numVertices(); ++i) |
274 { |
274 { |
275 Vertex v = obj->vertex (i); |
275 Vertex v = obj->vertex (i); |
276 v.transform (transform, pos); |
276 v.transform (transform, pos); |
277 obj->setVertex (i, v); |
277 obj->setVertex (i, v); |
314 // ============================================================================= |
314 // ============================================================================= |
315 // |
315 // |
316 LDPolygon* LDObject::getPolygon() |
316 LDPolygon* LDObject::getPolygon() |
317 { |
317 { |
318 LDObjectType ot = type(); |
318 LDObjectType ot = type(); |
319 int num = (ot == LDObjectType::Line) ? 2 |
319 int num = (ot == LDObjectType::EdgeLine) ? 2 |
320 : (ot == LDObjectType::Triangle) ? 3 |
320 : (ot == LDObjectType::Triangle) ? 3 |
321 : (ot == LDObjectType::Quad) ? 4 |
321 : (ot == LDObjectType::Quadrilateral) ? 4 |
322 : (ot == LDObjectType::CondLine) ? 5 |
322 : (ot == LDObjectType::ConditionalEdge) ? 5 |
323 : 0; |
323 : 0; |
324 |
324 |
325 if (num == 0) |
325 if (num == 0) |
326 return nullptr; |
326 return nullptr; |
327 |
327 |
496 return; |
496 return; |
497 } |
497 } |
498 |
498 |
499 // ============================================================================= |
499 // ============================================================================= |
500 // |
500 // |
501 void LDQuad::invert() |
501 void LDQuadrilateral::invert() |
502 { |
502 { |
503 // Quad: 0 -> 1 -> 2 -> 3 |
503 // Quad: 0 -> 1 -> 2 -> 3 |
504 // reversed: 0 -> 3 -> 2 -> 1 |
504 // reversed: 0 -> 3 -> 2 -> 1 |
505 // Thus, we swap 1 and 3. |
505 // Thus, we swap 1 and 3. |
506 Vertex tmp = vertex (1); |
506 Vertex tmp = vertex (1); |
578 this->model()->emplaceAt<LDBfc>(idx, BfcStatement::InvertNext); |
578 this->model()->emplaceAt<LDBfc>(idx, BfcStatement::InvertNext); |
579 } |
579 } |
580 |
580 |
581 // ============================================================================= |
581 // ============================================================================= |
582 // |
582 // |
583 void LDLine::invert() |
583 void LDEdgeLine::invert() |
584 { |
584 { |
585 // For lines, we swap the vertices. |
585 // For lines, we swap the vertices. |
586 Vertex tmp = vertex (0); |
586 Vertex tmp = vertex (0); |
587 setVertex (0, vertex (1)); |
587 setVertex (0, vertex (1)); |
588 setVertex (1, tmp); |
588 setVertex (1, tmp); |
589 } |
589 } |
590 |
590 |
591 // ============================================================================= |
591 // ============================================================================= |
592 // |
592 // |
593 void LDCondLine::invert() |
593 void LDConditionalEdge::invert() |
594 { |
594 { |
595 // I don't think that a conditional line's control points need to be swapped, do they? |
595 // I don't think that a conditional line's control points need to be swapped, do they? |
596 Vertex tmp = vertex (0); |
596 Vertex tmp = vertex (0); |
597 setVertex (0, vertex (1)); |
597 setVertex (0, vertex (1)); |
598 setVertex (1, tmp); |
598 setVertex (1, tmp); |
611 setVertex (2, tmp); |
611 setVertex (2, tmp); |
612 } |
612 } |
613 |
613 |
614 // ============================================================================= |
614 // ============================================================================= |
615 // |
615 // |
616 LDLine* LDCondLine::becomeEdgeLine() |
616 LDEdgeLine* LDConditionalEdge::becomeEdgeLine() |
617 { |
617 { |
618 LDLine* replacement = model()->emplaceReplacement<LDLine>(this); |
618 LDEdgeLine* replacement = model()->emplaceReplacement<LDEdgeLine>(this); |
619 |
619 |
620 for (int i = 0; i < replacement->numVertices(); ++i) |
620 for (int i = 0; i < replacement->numVertices(); ++i) |
621 replacement->setVertex (i, vertex (i)); |
621 replacement->setVertex (i, vertex (i)); |
622 |
622 |
623 replacement->setColor (color()); |
623 replacement->setColor (color()); |
788 { |
788 { |
789 QVector<LDPolygon> polygons = rasterizePolygons(segments); |
789 QVector<LDPolygon> polygons = rasterizePolygons(segments); |
790 |
790 |
791 for (LDPolygon& poly : polygons) |
791 for (LDPolygon& poly : polygons) |
792 { |
792 { |
793 LDLine* line = model.emplace<LDLine>(poly.vertices[0], poly.vertices[1]); |
793 LDEdgeLine* line = model.emplace<LDEdgeLine>(poly.vertices[0], poly.vertices[1]); |
794 line->setColor (poly.color); |
794 line->setColor (poly.color); |
795 } |
795 } |
796 } |
796 } |
797 |
797 |
798 QVector<LDPolygon> LDBezierCurve::rasterizePolygons(int segments) |
798 QVector<LDPolygon> LDBezierCurve::rasterizePolygons(int segments) |