src/toolsets/algorithmtoolset.cpp

changeset 1186
eae8b3bce545
parent 1166
d2e78bb77763
child 1187
46dc716238fd
equal deleted inserted replaced
1185:c2e0db52ea07 1186:eae8b3bce545
57 57
58 Vertex v0 = object->vertex(0); 58 Vertex v0 = object->vertex(0);
59 Vertex v1 = object->vertex(1); 59 Vertex v1 = object->vertex(1);
60 Vertex v2 = object->vertex(2); 60 Vertex v2 = object->vertex(2);
61 Vertex v3 = object->vertex(3); 61 Vertex v3 = object->vertex(3);
62 LDColor color = object->color();
63 62
64 // Find the index of this quad 63 // Find the index of this quad
65 int index = object->lineNumber(); 64 int index = object->lineNumber();
66 if (index == -1) 65 if (index == -1)
67 continue; 66 continue;
70 // 0───3 0───3 3 69 // 0───3 0───3 3
71 // │ │ --→ │ ╱ ╱│ 70 // │ │ --→ │ ╱ ╱│
72 // │ │ --→ │ ╱ ╱ │ 71 // │ │ --→ │ ╱ ╱ │
73 // │ │ --→ │╱ ╱ │ 72 // │ │ --→ │╱ ╱ │
74 // 1───2 1 1───2 73 // 1───2 1 1───2
75 LDTriangle* triangle1 = currentDocument()->emplaceReplacementAt<LDTriangle>(index, v0, v1, v3); 74 Model replacement {m_documents};
76 LDTriangle* triangle2 = currentDocument()->emplaceAt<LDTriangle>(index + 1, v1, v2, v3); 75 LDTriangle* triangle1 = replacement.emplace<LDTriangle>(v0, v1, v3);
76 LDTriangle* triangle2 = replacement.emplace<LDTriangle>(v1, v2, v3);
77 77
78 // The triangles also inherit the quad's color 78 // The triangles also inherit the quad's color
79 triangle1->setColor(color); 79 triangle1->setColor(object->color());
80 triangle2->setColor(color); 80 triangle2->setColor(object->color());
81 currentDocument()->replace(object, replacement);
81 count += 1; 82 count += 1;
82 } 83 }
83 84
84 print ("%1 quadrilaterals split", count); 85 print ("%1 quadrilaterals split", count);
85 } 86 }
276 } 277 }
277 } 278 }
278 279
279 void AlgorithmToolset::demote() 280 void AlgorithmToolset::demote()
280 { 281 {
281 int num = 0; 282 int count = 0;
282 283
283 for (LDConditionalEdge* line : filterByType<LDConditionalEdge>(selectedObjects())) 284 for (LDConditionalEdge* line : filterByType<LDConditionalEdge>(selectedObjects()))
284 { 285 {
285 line->becomeEdgeLine(); 286 line->becomeEdgeLine();
286 ++num; 287 count += 1;
287 } 288 }
288 289
289 print (tr ("Converted %1 conditional lines"), num); 290 print (tr ("Converted %1 conditional lines"), count);
290 } 291 }
291 292
292 bool AlgorithmToolset::isColorUsed (LDColor color) 293 bool AlgorithmToolset::isColorUsed (LDColor color)
293 { 294 {
294 for (LDObject* obj : currentDocument()->objects()) 295 for (LDObject* obj : currentDocument()->objects())

mercurial