src/gui_editactions.cpp

changeset 538
2f85d4d286e5
parent 522
afa691788bdb
child 539
72ad83a67165
equal deleted inserted replaced
537:1add0ee96fb3 538:2f85d4d286e5
230 // ----------------------------------------------------------------------------- 230 // -----------------------------------------------------------------------------
231 DEFINE_ACTION (SetColor, KEY (C)) 231 DEFINE_ACTION (SetColor, KEY (C))
232 { if (selection().isEmpty()) 232 { if (selection().isEmpty())
233 return; 233 return;
234 234
235 short colnum; 235 int colnum;
236 short defcol = -1; 236 int defcol = -1;
237 237
238 QList<LDObject*> objs = selection(); 238 QList<LDObject*> objs = selection();
239 239
240 // If all selected objects have the same color, said color is our default 240 // If all selected objects have the same color, said color is our default
241 // value to the color selection dialog. 241 // value to the color selection dialog.
242 defcol = g_win->getSelectedColor(); 242 defcol = g_win->getSelectedColor();
243 243
244 // Show the dialog to the user now and ask for a color. 244 // Show the dialog to the user now and ask for a color.
245 if (ColorSelector::getColor (colnum, defcol, g_win)) 245 if (ColorSelector::selectColor (colnum, defcol, g_win))
246 { for (LDObject* obj : objs) 246 { for (LDObject* obj : objs)
247 { if (obj->isColored() == false) 247 { if (obj->isColored() == false)
248 continue; 248 continue;
249 249
250 obj->setColor (colnum); 250 obj->setColor (colnum);
264 for (LDObject* obj : objs) 264 for (LDObject* obj : objs)
265 { const LDObject::Type type = obj->getType(); 265 { const LDObject::Type type = obj->getType();
266 if (type != LDObject::Quad && type != LDObject::Triangle) 266 if (type != LDObject::Quad && type != LDObject::Triangle)
267 continue; 267 continue;
268 268
269 short numLines; 269 int numLines;
270 LDLine* lines[4]; 270 LDLine* lines[4];
271 271
272 if (type == LDObject::Quad) 272 if (type == LDObject::Quad)
273 { numLines = 4; 273 { numLines = 4;
274 274
285 lines[0] = new LDLine (tri->getVertex (0), tri->getVertex (1)); 285 lines[0] = new LDLine (tri->getVertex (0), tri->getVertex (1));
286 lines[1] = new LDLine (tri->getVertex (1), tri->getVertex (2)); 286 lines[1] = new LDLine (tri->getVertex (1), tri->getVertex (2));
287 lines[2] = new LDLine (tri->getVertex (2), tri->getVertex (0)); 287 lines[2] = new LDLine (tri->getVertex (2), tri->getVertex (0));
288 } 288 }
289 289
290 for (short i = 0; i < numLines; ++i) 290 for (int i = 0; i < numLines; ++i)
291 { long idx = obj->getIndex() + i + 1; 291 { long idx = obj->getIndex() + i + 1;
292 292
293 lines[i]->setColor (edgecolor); 293 lines[i]->setColor (edgecolor);
294 LDFile::current()->insertObj (idx, lines[i]); 294 LDFile::current()->insertObj (idx, lines[i]);
295 g_win->R()->compileObject (lines[i]); 295 g_win->R()->compileObject (lines[i]);
419 v.move (rotpoint); 419 v.move (rotpoint);
420 } 420 }
421 421
422 // ============================================================================= 422 // =============================================================================
423 // ----------------------------------------------------------------------------- 423 // -----------------------------------------------------------------------------
424 static void doRotate (const short l, const short m, const short n) 424 static void doRotate (const int l, const int m, const int n)
425 { QList<LDObject*> sel = selection(); 425 { QList<LDObject*> sel = selection();
426 QList<vertex*> queue; 426 QList<vertex*> queue;
427 const vertex rotpoint = rotPoint (sel); 427 const vertex rotpoint = rotPoint (sel);
428 const double angle = (pi * currentGrid().confs[Grid::Angle]->value) / 180, 428 const double angle = (pi * currentGrid().confs[Grid::Angle]->value) / 180,
429 cosangle = cos (angle), 429 cosangle = cos (angle),
445 }); 445 });
446 446
447 // Apply the above matrix to everything 447 // Apply the above matrix to everything
448 for (LDObject* obj : sel) 448 for (LDObject* obj : sel)
449 { if (obj->vertices()) 449 { if (obj->vertices())
450 { for (short i = 0; i < obj->vertices(); ++i) 450 { for (int i = 0; i < obj->vertices(); ++i)
451 { vertex v = obj->getVertex (i); 451 { vertex v = obj->getVertex (i);
452 rotateVertex (v, rotpoint, transform); 452 rotateVertex (v, rotpoint, transform);
453 obj->setVertex (i, v); 453 obj->setVertex (i, v);
454 } 454 }
455 } elif (obj->hasMatrix()) 455 } elif (obj->hasMatrix())
506 DEFINE_ACTION (RoundCoordinates, 0) 506 DEFINE_ACTION (RoundCoordinates, 0)
507 { setlocale (LC_ALL, "C"); 507 { setlocale (LC_ALL, "C");
508 int num = 0; 508 int num = 0;
509 509
510 for (LDObject* obj : selection()) 510 for (LDObject* obj : selection())
511 { for (short i = 0; i < obj->vertices(); ++i) 511 { for (int i = 0; i < obj->vertices(); ++i)
512 { vertex v = obj->getVertex (i); 512 { vertex v = obj->getVertex (i);
513 513
514 for (const Axis ax : g_Axes) 514 for (const Axis ax : g_Axes)
515 { // HACK: .. should find a better way to do this 515 { // HACK: .. should find a better way to do this
516 str valstr; 516 str valstr;
572 if (ui.x->isChecked()) sel << X; 572 if (ui.x->isChecked()) sel << X;
573 if (ui.y->isChecked()) sel << Y; 573 if (ui.y->isChecked()) sel << Y;
574 if (ui.z->isChecked()) sel << Z; 574 if (ui.z->isChecked()) sel << Z;
575 575
576 for (LDObject* obj : selection()) 576 for (LDObject* obj : selection())
577 { for (short i = 0; i < obj->vertices(); ++i) 577 { for (int i = 0; i < obj->vertices(); ++i)
578 { vertex v = obj->getVertex (i); 578 { vertex v = obj->getVertex (i);
579 579
580 for (Axis ax : sel) 580 for (Axis ax : sel)
581 { double& coord = v[ax]; 581 { double& coord = v[ax];
582 582
613 if (ui.x->isChecked()) sel << X; 613 if (ui.x->isChecked()) sel << X;
614 if (ui.y->isChecked()) sel << Y; 614 if (ui.y->isChecked()) sel << Y;
615 if (ui.z->isChecked()) sel << Z; 615 if (ui.z->isChecked()) sel << Z;
616 616
617 for (LDObject* obj : selection()) 617 for (LDObject* obj : selection())
618 { for (short i = 0; i < obj->vertices(); ++i) 618 { for (int i = 0; i < obj->vertices(); ++i)
619 { vertex v = obj->getVertex (i); 619 { vertex v = obj->getVertex (i);
620 620
621 for (Axis ax : sel) 621 for (Axis ax : sel)
622 v[ax] *= -1; 622 v[ax] *= -1;
623 623
648 g_win->refresh(); 648 g_win->refresh();
649 } 649 }
650 650
651 // ============================================================================= 651 // =============================================================================
652 // ----------------------------------------------------------------------------- 652 // -----------------------------------------------------------------------------
653 static bool isColorUsed (short colnum) 653 static bool isColorUsed (int colnum)
654 { for (LDObject* obj : LDFile::current()->objects()) 654 { for (LDObject* obj : LDFile::current()->objects())
655 if (obj->isColored() && obj->color() == colnum) 655 if (obj->isColored() && obj->color() == colnum)
656 return true; 656 return true;
657 657
658 return false; 658 return false;
659 } 659 }
660 660
661 // ============================================================================= 661 // =============================================================================
662 // ----------------------------------------------------------------------------- 662 // -----------------------------------------------------------------------------
663 DEFINE_ACTION (Autocolor, 0) 663 DEFINE_ACTION (Autocolor, 0)
664 { short colnum = 0; 664 { int colnum = 0;
665 665
666 while (colnum < MAX_COLORS && (getColor (colnum) == null || isColorUsed (colnum))) 666 while (colnum < MAX_COLORS && (getColor (colnum) == null || isColorUsed (colnum)))
667 colnum++; 667 colnum++;
668 668
669 if (colnum >= MAX_COLORS) 669 if (colnum >= MAX_COLORS)
708 708
709 LDComment* comm = new LDComment (commentText); 709 LDComment* comm = new LDComment (commentText);
710 710
711 // Find a spot to place the new comment 711 // Find a spot to place the new comment
712 for ( 712 for (
713 obj = LDFile::current()->object (0); 713 obj = LDFile::current()->getObject (0);
714 obj && obj->next() && !obj->next()->isScemantic(); 714 obj && obj->next() && !obj->next()->isScemantic();
715 obj = obj->next() 715 obj = obj->next()
716 ) 716 )
717 { LDComment* comm = dynamic_cast<LDComment*> (obj); 717 { LDComment* comm = dynamic_cast<LDComment*> (obj);
718 718

mercurial