src/toolsets/algorithmtoolset.cpp

changeset 1079
67c6e5d32e68
parent 1078
c72e3115a297
child 1081
47cde4087cc5
equal deleted inserted replaced
1078:c72e3115a297 1079:67c6e5d32e68
108 108
109 if (dlg->exec() == QDialog::Rejected) 109 if (dlg->exec() == QDialog::Rejected)
110 return; 110 return;
111 111
112 // Reinterpret it from the text of the input field 112 // Reinterpret it from the text of the input field
113 LDObject* newobj = ParseLine (ui.code->text()); 113 currentDocument()->replaceWithFromString(obj, ui.code->text());
114 obj->replace (newobj);
115 } 114 }
116 115
117 void AlgorithmToolset::makeBorders() 116 void AlgorithmToolset::makeBorders()
118 { 117 {
119 int count = 0; 118 int count = 0;
123 const LDObjectType type = object->type(); 122 const LDObjectType type = object->type();
124 123
125 if (type != OBJ_Quad and type != OBJ_Triangle) 124 if (type != OBJ_Quad and type != OBJ_Triangle)
126 continue; 125 continue;
127 126
128 Model lines; 127 Model lines {m_documents};
129 128
130 if (type == OBJ_Quad) 129 if (type == OBJ_Quad)
131 { 130 {
132 LDQuad* quad = static_cast<LDQuad*>(object); 131 LDQuad* quad = static_cast<LDQuad*>(object);
133 lines.emplace<LDLine>(quad->vertex (0), quad->vertex (1)); 132 lines.emplace<LDLine>(quad->vertex (0), quad->vertex (1));
393 for (LDObject* obj : selectedObjects()) 392 for (LDObject* obj : selectedObjects())
394 { 393 {
395 if (not isOneOf (obj->type(), OBJ_Line, OBJ_CondLine)) 394 if (not isOneOf (obj->type(), OBJ_Line, OBJ_CondLine))
396 continue; 395 continue;
397 396
398 Model segments; 397 Model segments {m_documents};
399 398
400 for (int i = 0; i < numSegments; ++i) 399 for (int i = 0; i < numSegments; ++i)
401 { 400 {
402 Vertex v0; 401 Vertex v0;
403 Vertex v1; 402 Vertex v1;
534 LDDocument* subfile = m_window->newDocument(); 533 LDDocument* subfile = m_window->newDocument();
535 subfile->openForEditing(); 534 subfile->openForEditing();
536 subfile->setFullPath(fullsubname); 535 subfile->setFullPath(fullsubname);
537 subfile->setName(LDDocument::shortenName(fullsubname)); 536 subfile->setName(LDDocument::shortenName(fullsubname));
538 537
539 Model header; 538 Model header {m_documents};
540 header.emplace<LDComment>(subtitle); 539 header.emplace<LDComment>(subtitle);
541 header.emplace<LDComment>("Name: "); // This gets filled in when the subfile is saved 540 header.emplace<LDComment>("Name: "); // This gets filled in when the subfile is saved
542 header.emplace<LDComment>(format("Author: %1 [%2]", m_config->defaultName(), m_config->defaultUser())); 541 header.emplace<LDComment>(format("Author: %1 [%2]", m_config->defaultName(), m_config->defaultUser()));
543 header.emplace<LDComment>("!LDRAW_ORG Unofficial_Subpart"); 542 header.emplace<LDComment>("!LDRAW_ORG Unofficial_Subpart");
544 543
550 header.emplace<LDEmpty>(); 549 header.emplace<LDEmpty>();
551 subfile->merge(header); 550 subfile->merge(header);
552 551
553 // Copy the body over to the new document 552 // Copy the body over to the new document
554 for (LDObject* object : selectedObjects()) 553 for (LDObject* object : selectedObjects())
555 subfile->addObject(object->createCopy()); 554 subfile->addFromString(object->asText());
556 555
557 // Try save it 556 // Try save it
558 if (m_window->save(subfile, true)) 557 if (m_window->save(subfile, true))
559 { 558 {
560 // Save was successful. Delete the original selection now from the 559 // Save was successful. Delete the original selection now from the

mercurial