src/gui_editactions.cpp

changeset 460
b230ae09c8e5
parent 458
cb360f4d8979
child 461
fbcc91ae1dd2
equal deleted inserted replaced
459:51cca3ce540d 460:b230ae09c8e5
118 continue; 118 continue;
119 119
120 List<LDObject*> objs; 120 List<LDObject*> objs;
121 121
122 if (obj->getType() == LDObject::Subfile) 122 if (obj->getType() == LDObject::Subfile)
123 objs = static_cast<LDSubfileObject*> (obj)->inlineContents ( 123 objs = static_cast<LDSubfile*> (obj)->inlineContents (
124 (LDSubfileObject::InlineFlags) 124 (LDSubfile::InlineFlags)
125 ((deep) ? LDSubfileObject::DeepInline : 0) | 125 ((deep) ? LDSubfile::DeepInline : 0) |
126 LDSubfileObject::CacheInline 126 LDSubfile::CacheInline
127 ); 127 );
128 else 128 else
129 continue; 129 continue;
130 130
131 // Merge in the inlined objects 131 // Merge in the inlined objects
169 long index = obj->getIndex(); 169 long index = obj->getIndex();
170 170
171 if (index == -1) 171 if (index == -1)
172 return; 172 return;
173 173
174 List<LDTriangleObject*> triangles = static_cast<LDQuadObject*> (obj)->splitToTriangles(); 174 List<LDTriangle*> triangles = static_cast<LDQuad*> (obj)->splitToTriangles();
175 175
176 // Replace the quad with the first triangle and add the second triangle 176 // Replace the quad with the first triangle and add the second triangle
177 // after the first one. 177 // after the first one.
178 LDFile::current()->setObject (index, triangles[0]); 178 LDFile::current()->setObject (index, triangles[0]);
179 LDFile::current()->insertObj (index + 1, triangles[1]); 179 LDFile::current()->insertObj (index + 1, triangles[1]);
180 180
181 for (LDTriangleObject * t : triangles) 181 for (LDTriangle * t : triangles)
182 g_win->R()->compileObject (t); 182 g_win->R()->compileObject (t);
183 183
184 // Delete this quad now, it has been split. 184 // Delete this quad now, it has been split.
185 delete obj; 185 delete obj;
186 186
203 203
204 ui.setupUi (dlg); 204 ui.setupUi (dlg);
205 ui.code->setText (obj->raw()); 205 ui.code->setText (obj->raw());
206 206
207 if (obj->getType() == LDObject::Error) 207 if (obj->getType() == LDObject::Error)
208 ui.errorDescription->setText (static_cast<LDErrorObject*> (obj)->reason); 208 ui.errorDescription->setText (static_cast<LDError*> (obj)->reason);
209 else { 209 else {
210 ui.errorDescription->hide(); 210 ui.errorDescription->hide();
211 ui.errorIcon->hide(); 211 ui.errorIcon->hide();
212 } 212 }
213 213
263 for (LDObject* obj : objs) { 263 for (LDObject* obj : objs) {
264 if (obj->getType() != LDObject::Quad && obj->getType() != LDObject::Triangle) 264 if (obj->getType() != LDObject::Quad && obj->getType() != LDObject::Triangle)
265 continue; 265 continue;
266 266
267 short numLines; 267 short numLines;
268 LDLineObject* lines[4]; 268 LDLine* lines[4];
269 269
270 if (obj->getType() == LDObject::Quad) { 270 if (obj->getType() == LDObject::Quad) {
271 numLines = 4; 271 numLines = 4;
272 272
273 LDQuadObject* quad = static_cast<LDQuadObject*> (obj); 273 LDQuad* quad = static_cast<LDQuad*> (obj);
274 lines[0] = new LDLineObject (quad->getVertex (0), quad->getVertex (1)); 274 lines[0] = new LDLine (quad->getVertex (0), quad->getVertex (1));
275 lines[1] = new LDLineObject (quad->getVertex (1), quad->getVertex (2)); 275 lines[1] = new LDLine (quad->getVertex (1), quad->getVertex (2));
276 lines[2] = new LDLineObject (quad->getVertex (2), quad->getVertex (3)); 276 lines[2] = new LDLine (quad->getVertex (2), quad->getVertex (3));
277 lines[3] = new LDLineObject (quad->getVertex (3), quad->getVertex (0)); 277 lines[3] = new LDLine (quad->getVertex (3), quad->getVertex (0));
278 } else { 278 } else {
279 numLines = 3; 279 numLines = 3;
280 280
281 LDTriangleObject* tri = static_cast<LDTriangleObject*> (obj); 281 LDTriangle* tri = static_cast<LDTriangle*> (obj);
282 lines[0] = new LDLineObject (tri->getVertex (0), tri->getVertex (1)); 282 lines[0] = new LDLine (tri->getVertex (0), tri->getVertex (1));
283 lines[1] = new LDLineObject (tri->getVertex (1), tri->getVertex (2)); 283 lines[1] = new LDLine (tri->getVertex (1), tri->getVertex (2));
284 lines[2] = new LDLineObject (tri->getVertex (2), tri->getVertex (0)); 284 lines[2] = new LDLine (tri->getVertex (2), tri->getVertex (0));
285 } 285 }
286 286
287 for (short i = 0; i < numLines; ++i) { 287 for (short i = 0; i < numLines; ++i) {
288 ulong idx = obj->getIndex() + i + 1; 288 ulong idx = obj->getIndex() + i + 1;
289 289
309 continue; 309 continue;
310 310
311 ulong idx = obj->getIndex(); 311 ulong idx = obj->getIndex();
312 312
313 for (short i = 0; i < obj->vertices(); ++i) { 313 for (short i = 0; i < obj->vertices(); ++i) {
314 LDVertexObject* vert = new LDVertexObject; 314 LDVertex* vert = new LDVertex;
315 vert->pos = obj->getVertex (i); 315 vert->pos = obj->getVertex (i);
316 vert->setColor (obj->color()); 316 vert->setColor (obj->color());
317 317
318 LDFile::current()->insertObj (++idx, vert); 318 LDFile::current()->insertObj (++idx, vert);
319 g_win->R()->compileObject (vert); 319 g_win->R()->compileObject (vert);
458 mo->setPosition (v); 458 mo->setPosition (v);
459 459
460 // Transform the matrix 460 // Transform the matrix
461 mo->setTransform (mo->transform() * transform); 461 mo->setTransform (mo->transform() * transform);
462 } elif (obj->getType() == LDObject::Vertex) { 462 } elif (obj->getType() == LDObject::Vertex) {
463 LDVertexObject* vert = static_cast<LDVertexObject*> (obj); 463 LDVertex* vert = static_cast<LDVertex*> (obj);
464 vertex v = vert->pos; 464 vertex v = vert->pos;
465 rotateVertex (v, rotpoint, transform); 465 rotateVertex (v, rotpoint, transform);
466 vert->pos = v; 466 vert->pos = v;
467 } 467 }
468 468
520 if (obj->isColored() == false) 520 if (obj->isColored() == false)
521 continue; 521 continue;
522 522
523 int col = maincolor; 523 int col = maincolor;
524 524
525 if (obj->getType() == LDObject::Line || obj->getType() == LDObject::CondLine) 525 if (obj->getType() == LDObject::Line || obj->getType() == LDObject::CndLine)
526 col = edgecolor; 526 col = edgecolor;
527 527
528 obj->setColor (col); 528 obj->setColor (col);
529 g_win->R()->compileObject (obj); 529 g_win->R()->compileObject (obj);
530 num++; 530 num++;
614 DEFINE_ACTION (Demote, 0) { 614 DEFINE_ACTION (Demote, 0) {
615 List<LDObject*> sel = g_win->sel(); 615 List<LDObject*> sel = g_win->sel();
616 int num = 0; 616 int num = 0;
617 617
618 for (LDObject* obj : sel) { 618 for (LDObject* obj : sel) {
619 if (obj->getType() != LDObject::CondLine) 619 if (obj->getType() != LDObject::CndLine)
620 continue; 620 continue;
621 621
622 LDLineObject* repl = static_cast<LDCondLineObject*> (obj)->demote(); 622 LDLine* repl = static_cast<LDCndLine*> (obj)->demote();
623 g_win->R()->compileObject (repl); 623 g_win->R()->compileObject (repl);
624 ++num; 624 ++num;
625 } 625 }
626 626
627 log (ForgeWindow::tr ("Demoted %1 conditional lines"), num); 627 log (ForgeWindow::tr ("Demoted %1 conditional lines"), num);
684 str commentText = fmt ("!HISTORY %1 [%2] %3", 684 str commentText = fmt ("!HISTORY %1 [%2] %3",
685 ui->m_date->date().toString("yyyy-MM-dd"), 685 ui->m_date->date().toString("yyyy-MM-dd"),
686 ui->m_username->text(), 686 ui->m_username->text(),
687 ui->m_comment->text()); 687 ui->m_comment->text());
688 688
689 LDCommentObject* comm = new LDCommentObject (commentText); 689 LDComment* comm = new LDComment (commentText);
690 690
691 // Find a spot to place the new comment 691 // Find a spot to place the new comment
692 for ( 692 for (
693 obj = LDFile::current()->object (0); 693 obj = LDFile::current()->object (0);
694 obj && obj->next() && !obj->next()->isScemantic(); 694 obj && obj->next() && !obj->next()->isScemantic();
695 obj = obj->next() 695 obj = obj->next()
696 ) { 696 ) {
697 LDCommentObject* comm = dynamic_cast<LDCommentObject*> (obj); 697 LDComment* comm = dynamic_cast<LDComment*> (obj);
698 if (comm && comm->text.startsWith ("!HISTORY ")) 698 if (comm && comm->text.startsWith ("!HISTORY "))
699 ishistory = true; 699 ishistory = true;
700 700
701 if (prevIsHistory && !ishistory) { 701 if (prevIsHistory && !ishistory) {
702 // Last line was history, this isn't, thus insert the new history 702 // Last line was history, this isn't, thus insert the new history
711 LDFile::current()->insertObj (idx++, comm); 711 LDFile::current()->insertObj (idx++, comm);
712 712
713 // If we're adding a history line right before a scemantic object, pad it 713 // If we're adding a history line right before a scemantic object, pad it
714 // an empty line 714 // an empty line
715 if (obj && obj->next() && obj->next()->isScemantic()) 715 if (obj && obj->next() && obj->next()->isScemantic())
716 LDFile::current()->insertObj (idx, new LDEmptyObject); 716 LDFile::current()->insertObj (idx, new LDEmpty);
717 717
718 g_win->buildObjList(); 718 g_win->buildObjList();
719 delete ui; 719 delete ui;
720 } 720 }

mercurial