src/toolsets/algorithmtoolset.cpp

changeset 1258
f5921a474d57
parent 1242
725cb1084044
child 1259
0384b1d49786
equal deleted inserted replaced
1257:0d42a1ebd954 1258:f5921a474d57
48 48
49 void AlgorithmToolset::splitQuads() 49 void AlgorithmToolset::splitQuads()
50 { 50 {
51 int count = 0; 51 int count = 0;
52 52
53 for (LDObject* object : selectedObjects().toList()) 53 for (LDObject* object : selectedObjects())
54 { 54 {
55 QModelIndex index = currentDocument()->indexOf(object);
56
55 if (object->numVertices() != 4) 57 if (object->numVertices() != 4)
56 continue; 58 continue;
57 59
58 Vertex v0 = object->vertex(0); 60 Vertex v0 = object->vertex(0);
59 Vertex v1 = object->vertex(1); 61 Vertex v1 = object->vertex(1);
60 Vertex v2 = object->vertex(2); 62 Vertex v2 = object->vertex(2);
61 Vertex v3 = object->vertex(3); 63 Vertex v3 = object->vertex(3);
62 LDColor color = object->color(); 64 LDColor color = object->color();
63
64 // Find the index of this quad
65 int index = object->lineNumber();
66 if (index == -1)
67 continue;
68 65
69 // Create the two triangles based on this quadrilateral: 66 // Create the two triangles based on this quadrilateral:
70 // 0───3 0───3 3 67 // 0───3 0───3 3
71 // │ │ --→ │ ╱ ╱│ 68 // │ │ --→ │ ╱ ╱│
72 // │ │ --→ │ ╱ ╱ │ 69 // │ │ --→ │ ╱ ╱ │
73 // │ │ --→ │╱ ╱ │ 70 // │ │ --→ │╱ ╱ │
74 // 1───2 1 1───2 71 // 1───2 1 1───2
75 LDTriangle* triangle1 = currentDocument()->emplaceReplacementAt<LDTriangle>(index, v0, v1, v3); 72 LDTriangle* triangle1 = currentDocument()->emplaceReplacementAt<LDTriangle>(index.row(), v0, v1, v3);
76 LDTriangle* triangle2 = currentDocument()->emplaceAt<LDTriangle>(index + 1, v1, v2, v3); 73 LDTriangle* triangle2 = currentDocument()->emplaceAt<LDTriangle>(index.row() + 1, v1, v2, v3);
77 74
78 // The triangles also inherit the quad's color 75 // The triangles also inherit the quad's color
79 triangle1->setColor(color); 76 triangle1->setColor(color);
80 triangle2->setColor(color); 77 triangle2->setColor(color);
81 count += 1; 78 count += 1;
140 lines.emplace<LDEdgeLine>(triangle->vertex (1), triangle->vertex (2)); 137 lines.emplace<LDEdgeLine>(triangle->vertex (1), triangle->vertex (2));
141 lines.emplace<LDEdgeLine>(triangle->vertex (2), triangle->vertex (0)); 138 lines.emplace<LDEdgeLine>(triangle->vertex (2), triangle->vertex (0));
142 } 139 }
143 140
144 count += countof(lines.objects()); 141 count += countof(lines.objects());
145 currentDocument()->merge(lines, object->lineNumber() + 1); 142 currentDocument()->merge(lines, currentDocument()->indexOf(object).row() + 1);
146 } 143 }
147 144
148 print(tr("Added %1 border lines"), count); 145 print(tr("Added %1 border lines"), count);
149 } 146 }
150 147
366 break; // Last line was history, this isn't, thus insert the new history line here. 363 break; // Last line was history, this isn't, thus insert the new history line here.
367 364
368 prevIsHistory = ishistory; 365 prevIsHistory = ishistory;
369 } 366 }
370 367
371 int idx = obj ? obj->lineNumber() : 0; 368 int idx = obj ? currentDocument()->indexOf(obj).row() : 0;
372 369
373 // Create the comment object based on input 370 // Create the comment object based on input
374 currentDocument()->emplaceAt<LDComment>(idx++, format("!HISTORY %1 [%2] %3", 371 currentDocument()->emplaceAt<LDComment>(idx++, format("!HISTORY %1 [%2] %3",
375 ui.m_date->date().toString ("yyyy-MM-dd"), 372 ui.m_date->date().toString ("yyyy-MM-dd"),
376 ui.m_username->text(), 373 ui.m_username->text(),
539 // Try save it 536 // Try save it
540 if (m_window->save(subfile, true)) 537 if (m_window->save(subfile, true))
541 { 538 {
542 // Where to insert the subfile reference? 539 // Where to insert the subfile reference?
543 // TODO: the selection really should be sorted by position... 540 // TODO: the selection really should be sorted by position...
544 int referencePosition = (*selectedObjects().begin())->lineNumber(); 541 int referencePosition = m_window->selectedIndexes().begin()->row();
545 542
546 // Save was successful. Delete the original selection now from the 543 // Save was successful. Delete the original selection now from the
547 // main document. 544 // main document.
548 for (LDObject* object : selectedObjects().toList()) 545 for (LDObject* object : selectedObjects().toList())
549 currentDocument()->remove(object); 546 currentDocument()->remove(object);

mercurial