src/actionsEdit.cc

changeset 944
1a6f1997fcbe
parent 869
7184f3bae695
child 945
c310073e4f22
equal deleted inserted replaced
943:af81220741d9 944:1a6f1997fcbe
54 qApp->clipboard()->clear(); 54 qApp->clipboard()->clear();
55 55
56 // Now, copy the contents into the clipboard. 56 // Now, copy the contents into the clipboard.
57 QString data; 57 QString data;
58 58
59 for (LDObjectPtr obj : objs) 59 for (LDObject* obj : objs)
60 { 60 {
61 if (not data.isEmpty()) 61 if (not data.isEmpty())
62 data += "\n"; 62 data += "\n";
63 63
64 data += obj->asText(); 64 data += obj->asText();
95 CurrentDocument()->clearSelection(); 95 CurrentDocument()->clearSelection();
96 int num = 0; 96 int num = 0;
97 97
98 for (QString line : clipboardText.split ("\n")) 98 for (QString line : clipboardText.split ("\n"))
99 { 99 {
100 LDObjectPtr pasted = ParseLine (line); 100 LDObject* pasted = ParseLine (line);
101 CurrentDocument()->insertObj (idx++, pasted); 101 CurrentDocument()->insertObj (idx++, pasted);
102 pasted->select(); 102 pasted->select();
103 ++num; 103 ++num;
104 } 104 }
105 105
130 130
131 assert (idx != -1); 131 assert (idx != -1);
132 LDObjectList objs = ref->inlineContents (deep, false); 132 LDObjectList objs = ref->inlineContents (deep, false);
133 133
134 // Merge in the inlined objects 134 // Merge in the inlined objects
135 for (LDObjectPtr inlineobj : objs) 135 for (LDObject* inlineobj : objs)
136 { 136 {
137 QString line = inlineobj->asText(); 137 QString line = inlineobj->asText();
138 inlineobj->destroy(); 138 inlineobj->destroy();
139 LDObjectPtr newobj = ParseLine (line); 139 LDObject* newobj = ParseLine (line);
140 CurrentDocument()->insertObj (idx++, newobj); 140 CurrentDocument()->insertObj (idx++, newobj);
141 newobj->select(); 141 newobj->select();
142 } 142 }
143 143
144 // Delete the subfile now as it's been inlined. 144 // Delete the subfile now as it's been inlined.
190 void MainWindow::slot_actionEditRaw() 190 void MainWindow::slot_actionEditRaw()
191 { 191 {
192 if (Selection().size() != 1) 192 if (Selection().size() != 1)
193 return; 193 return;
194 194
195 LDObjectPtr obj = Selection()[0]; 195 LDObject* obj = Selection()[0];
196 QDialog* dlg = new QDialog; 196 QDialog* dlg = new QDialog;
197 Ui::EditRawUI ui; 197 Ui::EditRawUI ui;
198 198
199 ui.setupUi (dlg); 199 ui.setupUi (dlg);
200 ui.code->setText (obj->asText()); 200 ui.code->setText (obj->asText());
201 201
202 if (obj->type() == OBJ_Error) 202 if (obj->type() == OBJ_Error)
203 ui.errorDescription->setText (obj.staticCast<LDError>()->reason()); 203 ui.errorDescription->setText (static_cast<LDError*> (obj)->reason());
204 else 204 else
205 { 205 {
206 ui.errorDescription->hide(); 206 ui.errorDescription->hide();
207 ui.errorIcon->hide(); 207 ui.errorIcon->hide();
208 } 208 }
209 209
210 if (dlg->exec() == QDialog::Rejected) 210 if (dlg->exec() == QDialog::Rejected)
211 return; 211 return;
212 212
213 // Reinterpret it from the text of the input field 213 // Reinterpret it from the text of the input field
214 LDObjectPtr newobj = ParseLine (ui.code->text()); 214 LDObject* newobj = ParseLine (ui.code->text());
215 obj->replace (newobj); 215 obj->replace (newobj);
216 refresh(); 216 refresh();
217 } 217 }
218 218
219 // ============================================================================= 219 // =============================================================================
231 LDColor defaultcol = getSelectedColor(); 231 LDColor defaultcol = getSelectedColor();
232 232
233 // Show the dialog to the user now and ask for a color. 233 // Show the dialog to the user now and ask for a color.
234 if (ColorSelector::selectColor (color, defaultcol, g_win)) 234 if (ColorSelector::selectColor (color, defaultcol, g_win))
235 { 235 {
236 for (LDObjectPtr obj : objs) 236 for (LDObject* obj : objs)
237 { 237 {
238 if (obj->isColored()) 238 if (obj->isColored())
239 obj->setColor (color); 239 obj->setColor (color);
240 } 240 }
241 241
248 void MainWindow::slot_actionBorders() 248 void MainWindow::slot_actionBorders()
249 { 249 {
250 LDObjectList objs = Selection(); 250 LDObjectList objs = Selection();
251 int num = 0; 251 int num = 0;
252 252
253 for (LDObjectPtr obj : objs) 253 for (LDObject* obj : objs)
254 { 254 {
255 const LDObjectType type = obj->type(); 255 const LDObjectType type = obj->type();
256 256
257 if (type != OBJ_Quad and type != OBJ_Triangle) 257 if (type != OBJ_Quad and type != OBJ_Triangle)
258 continue; 258 continue;
259 259
260 LDLinePtr lines[4]; 260 LDLinePtr lines[4];
261 261
262 if (type == OBJ_Quad) 262 if (type == OBJ_Quad)
263 { 263 {
264 LDQuadPtr quad = obj.staticCast<LDQuad>(); 264 LDQuadPtr quad = static_cast<LDQuad*> (obj);
265 lines[0] = LDSpawn<LDLine> (quad->vertex (0), quad->vertex (1)); 265 lines[0] = LDSpawn<LDLine> (quad->vertex (0), quad->vertex (1));
266 lines[1] = LDSpawn<LDLine> (quad->vertex (1), quad->vertex (2)); 266 lines[1] = LDSpawn<LDLine> (quad->vertex (1), quad->vertex (2));
267 lines[2] = LDSpawn<LDLine> (quad->vertex (2), quad->vertex (3)); 267 lines[2] = LDSpawn<LDLine> (quad->vertex (2), quad->vertex (3));
268 lines[3] = LDSpawn<LDLine> (quad->vertex (3), quad->vertex (0)); 268 lines[3] = LDSpawn<LDLine> (quad->vertex (3), quad->vertex (0));
269 } 269 }
270 else 270 else
271 { 271 {
272 LDTrianglePtr tri = obj.staticCast<LDTriangle>(); 272 LDTrianglePtr tri = static_cast<LDTriangle*> (obj);
273 lines[0] = LDSpawn<LDLine> (tri->vertex (0), tri->vertex (1)); 273 lines[0] = LDSpawn<LDLine> (tri->vertex (0), tri->vertex (1));
274 lines[1] = LDSpawn<LDLine> (tri->vertex (1), tri->vertex (2)); 274 lines[1] = LDSpawn<LDLine> (tri->vertex (1), tri->vertex (2));
275 lines[2] = LDSpawn<LDLine> (tri->vertex (2), tri->vertex (0)); 275 lines[2] = LDSpawn<LDLine> (tri->vertex (2), tri->vertex (0));
276 } 276 }
277 277
295 // 295 //
296 void MainWindow::slot_actionCornerVerts() 296 void MainWindow::slot_actionCornerVerts()
297 { 297 {
298 int num = 0; 298 int num = 0;
299 299
300 for (LDObjectPtr obj : Selection()) 300 for (LDObject* obj : Selection())
301 { 301 {
302 if (obj->numVertices() < 2) 302 if (obj->numVertices() < 2)
303 continue; 303 continue;
304 304
305 int ln = obj->lineNumber(); 305 int ln = obj->lineNumber();
356 static void MoveObjects (Vertex vect) 356 static void MoveObjects (Vertex vect)
357 { 357 {
358 // Apply the grid values 358 // Apply the grid values
359 vect *= *CurrentGrid().coordinateSnap; 359 vect *= *CurrentGrid().coordinateSnap;
360 360
361 for (LDObjectPtr obj : Selection()) 361 for (LDObject* obj : Selection())
362 obj->move (vect); 362 obj->move (vect);
363 363
364 g_win->refresh(); 364 g_win->refresh();
365 } 365 }
366 366
398 398
399 // ============================================================================= 399 // =============================================================================
400 // 400 //
401 void MainWindow::slot_actionInvert() 401 void MainWindow::slot_actionInvert()
402 { 402 {
403 for (LDObjectPtr obj : Selection()) 403 for (LDObject* obj : Selection())
404 obj->invert(); 404 obj->invert();
405 405
406 refresh(); 406 refresh();
407 } 407 }
408 408
448 void MainWindow::slot_actionRoundCoordinates() 448 void MainWindow::slot_actionRoundCoordinates()
449 { 449 {
450 setlocale (LC_ALL, "C"); 450 setlocale (LC_ALL, "C");
451 int num = 0; 451 int num = 0;
452 452
453 for (LDObjectPtr obj : Selection()) 453 for (LDObject* obj : Selection())
454 { 454 {
455 LDMatrixObjectPtr mo = obj.dynamicCast<LDMatrixObject>(); 455 LDMatrixObjectPtr mo = dynamic_cast<LDMatrixObject*> (obj);
456 456
457 if (mo != null) 457 if (mo != null)
458 { 458 {
459 Vertex v = mo->position(); 459 Vertex v = mo->position();
460 Matrix t = mo->transform(); 460 Matrix t = mo->transform();
488 // 488 //
489 void MainWindow::slot_actionUncolor() 489 void MainWindow::slot_actionUncolor()
490 { 490 {
491 int num = 0; 491 int num = 0;
492 492
493 for (LDObjectPtr obj : Selection()) 493 for (LDObject* obj : Selection())
494 { 494 {
495 if (not obj->isColored()) 495 if (not obj->isColored())
496 continue; 496 continue;
497 497
498 obj->setColor (obj->defaultColor()); 498 obj->setColor (obj->defaultColor());
524 524
525 if (ui.x->isChecked()) sel << X; 525 if (ui.x->isChecked()) sel << X;
526 if (ui.y->isChecked()) sel << Y; 526 if (ui.y->isChecked()) sel << Y;
527 if (ui.z->isChecked()) sel << Z; 527 if (ui.z->isChecked()) sel << Z;
528 528
529 for (LDObjectPtr obj : Selection()) 529 for (LDObject* obj : Selection())
530 { 530 {
531 for (int i = 0; i < obj->numVertices(); ++i) 531 for (int i = 0; i < obj->numVertices(); ++i)
532 { 532 {
533 Vertex v = obj->vertex (i); 533 Vertex v = obj->vertex (i);
534 534
570 570
571 if (ui.x->isChecked()) sel << X; 571 if (ui.x->isChecked()) sel << X;
572 if (ui.y->isChecked()) sel << Y; 572 if (ui.y->isChecked()) sel << Y;
573 if (ui.z->isChecked()) sel << Z; 573 if (ui.z->isChecked()) sel << Z;
574 574
575 for (LDObjectPtr obj : Selection()) 575 for (LDObject* obj : Selection())
576 { 576 {
577 for (int i = 0; i < obj->numVertices(); ++i) 577 for (int i = 0; i < obj->numVertices(); ++i)
578 { 578 {
579 Vertex v = obj->vertex (i); 579 Vertex v = obj->vertex (i);
580 580
609 609
610 // ============================================================================= 610 // =============================================================================
611 // 611 //
612 static bool IsColorUsed (LDColor color) 612 static bool IsColorUsed (LDColor color)
613 { 613 {
614 for (LDObjectPtr obj : CurrentDocument()->objects()) 614 for (LDObject* obj : CurrentDocument()->objects())
615 { 615 {
616 if (obj->isColored() and obj->color() == color) 616 if (obj->isColored() and obj->color() == color)
617 return true; 617 return true;
618 } 618 }
619 619
637 { 637 {
638 print (tr ("Cannot auto-color: all colors are in use!")); 638 print (tr ("Cannot auto-color: all colors are in use!"));
639 return; 639 return;
640 } 640 }
641 641
642 for (LDObjectPtr obj : Selection()) 642 for (LDObject* obj : Selection())
643 { 643 {
644 if (not obj->isColored()) 644 if (not obj->isColored())
645 continue; 645 continue;
646 646
647 obj->setColor (color); 647 obj->setColor (color);
653 653
654 // ============================================================================= 654 // =============================================================================
655 // 655 //
656 void MainWindow::slot_actionAddHistoryLine() 656 void MainWindow::slot_actionAddHistoryLine()
657 { 657 {
658 LDObjectPtr obj; 658 LDObject* obj;
659 bool ishistory = false, 659 bool ishistory = false,
660 prevIsHistory = false; 660 prevIsHistory = false;
661 661
662 QDialog* dlg = new QDialog; 662 QDialog* dlg = new QDialog;
663 Ui_AddHistoryLine* ui = new Ui_AddHistoryLine; 663 Ui_AddHistoryLine* ui = new Ui_AddHistoryLine;
680 // Find a spot to place the new comment 680 // Find a spot to place the new comment
681 for (obj = CurrentDocument()->getObject (0); 681 for (obj = CurrentDocument()->getObject (0);
682 obj != null and obj->next() != null and not obj->next()->isScemantic(); 682 obj != null and obj->next() != null and not obj->next()->isScemantic();
683 obj = obj->next()) 683 obj = obj->next())
684 { 684 {
685 LDCommentPtr comm = obj.dynamicCast<LDComment>(); 685 LDCommentPtr comm = dynamic_cast<LDComment*> (obj);
686 686
687 if (comm != null and comm->text().startsWith ("!HISTORY ")) 687 if (comm != null and comm->text().startsWith ("!HISTORY "))
688 ishistory = true; 688 ishistory = true;
689 689
690 if (prevIsHistory and not ishistory) 690 if (prevIsHistory and not ishistory)
718 if (not ok) 718 if (not ok)
719 return; 719 return;
720 720
721 cfg::SplitLinesSegments = segments; 721 cfg::SplitLinesSegments = segments;
722 722
723 for (LDObjectPtr obj : Selection()) 723 for (LDObject* obj : Selection())
724 { 724 {
725 if (not Eq (obj->type(), OBJ_Line, OBJ_CondLine)) 725 if (not Eq (obj->type(), OBJ_Line, OBJ_CondLine))
726 continue; 726 continue;
727 727
728 QVector<LDObjectPtr> newsegs; 728 QVector<LDObject*> newsegs;
729 729
730 for (int i = 0; i < segments; ++i) 730 for (int i = 0; i < segments; ++i)
731 { 731 {
732 LDObjectPtr segment; 732 LDObject* segment;
733 Vertex v0, v1; 733 Vertex v0, v1;
734 734
735 v0.apply ([&](Axis ax, double& a) 735 v0.apply ([&](Axis ax, double& a)
736 { 736 {
737 double len = obj->vertex (1)[ax] - obj->vertex (0)[ax]; 737 double len = obj->vertex (1)[ax] - obj->vertex (0)[ax];
752 newsegs << segment; 752 newsegs << segment;
753 } 753 }
754 754
755 int ln = obj->lineNumber(); 755 int ln = obj->lineNumber();
756 756
757 for (LDObjectPtr seg : newsegs) 757 for (LDObject* seg : newsegs)
758 CurrentDocument()->insertObj (ln++, seg); 758 CurrentDocument()->insertObj (ln++, seg);
759 759
760 obj->destroy(); 760 obj->destroy();
761 } 761 }
762 762

mercurial