src/gui_editactions.cc

changeset 603
47e7773c7841
parent 600
209e3f1f7b2c
child 604
01bdac75994a
equal deleted inserted replaced
602:ac1744536b33 603:47e7773c7841
39 extern_cfg (String, ld_defaultuser); 39 extern_cfg (String, ld_defaultuser);
40 40
41 // ============================================================================= 41 // =============================================================================
42 // ----------------------------------------------------------------------------- 42 // -----------------------------------------------------------------------------
43 static int copyToClipboard() 43 static int copyToClipboard()
44 { QList<LDObject*> objs = selection(); 44 {
45 QList<LDObject*> objs = selection();
45 int num = 0; 46 int num = 0;
46 47
47 // Clear the clipboard first. 48 // Clear the clipboard first.
48 qApp->clipboard()->clear(); 49 qApp->clipboard()->clear();
49 50
50 // Now, copy the contents into the clipboard. 51 // Now, copy the contents into the clipboard.
51 str data; 52 str data;
52 53
53 for (LDObject* obj : objs) 54 for (LDObject* obj : objs)
54 { if (data.length() > 0) 55 {
56 if (data.length() > 0)
55 data += "\n"; 57 data += "\n";
56 58
57 data += obj->raw(); 59 data += obj->raw();
58 ++num; 60 ++num;
59 } 61 }
63 } 65 }
64 66
65 // ============================================================================= 67 // =============================================================================
66 // ----------------------------------------------------------------------------- 68 // -----------------------------------------------------------------------------
67 DEFINE_ACTION (Cut, CTRL (X)) 69 DEFINE_ACTION (Cut, CTRL (X))
68 { int num = copyToClipboard(); 70 {
71 int num = copyToClipboard();
69 deleteSelection(); 72 deleteSelection();
70 log (tr ("%1 objects cut"), num); 73 log (tr ("%1 objects cut"), num);
71 } 74 }
72 75
73 // ============================================================================= 76 // =============================================================================
74 // ----------------------------------------------------------------------------- 77 // -----------------------------------------------------------------------------
75 DEFINE_ACTION (Copy, CTRL (C)) 78 DEFINE_ACTION (Copy, CTRL (C))
76 { int num = copyToClipboard(); 79 {
80 int num = copyToClipboard();
77 log (tr ("%1 objects copied"), num); 81 log (tr ("%1 objects copied"), num);
78 } 82 }
79 83
80 // ============================================================================= 84 // =============================================================================
81 // ----------------------------------------------------------------------------- 85 // -----------------------------------------------------------------------------
82 DEFINE_ACTION (Paste, CTRL (V)) 86 DEFINE_ACTION (Paste, CTRL (V))
83 { const str clipboardText = qApp->clipboard()->text(); 87 {
88 const str clipboardText = qApp->clipboard()->text();
84 int idx = getInsertionPoint(); 89 int idx = getInsertionPoint();
85 getCurrentDocument()->clearSelection(); 90 getCurrentDocument()->clearSelection();
86 int num = 0; 91 int num = 0;
87 92
88 for (str line : clipboardText.split ("\n")) 93 for (str line : clipboardText.split ("\n"))
89 { LDObject* pasted = parseLine (line); 94 {
95 LDObject* pasted = parseLine (line);
90 getCurrentDocument()->insertObj (idx++, pasted); 96 getCurrentDocument()->insertObj (idx++, pasted);
91 pasted->select(); 97 pasted->select();
92 R()->compileObject (pasted); 98 R()->compileObject (pasted);
93 ++num; 99 ++num;
94 } 100 }
99 } 105 }
100 106
101 // ============================================================================= 107 // =============================================================================
102 // ----------------------------------------------------------------------------- 108 // -----------------------------------------------------------------------------
103 DEFINE_ACTION (Delete, KEY (Delete)) 109 DEFINE_ACTION (Delete, KEY (Delete))
104 { int num = deleteSelection(); 110 {
111 int num = deleteSelection();
105 log (tr ("%1 objects deleted"), num); 112 log (tr ("%1 objects deleted"), num);
106 } 113 }
107 114
108 // ============================================================================= 115 // =============================================================================
109 // ----------------------------------------------------------------------------- 116 // -----------------------------------------------------------------------------
110 static void doInline (bool deep) 117 static void doInline (bool deep)
111 { QList<LDObject*> sel = selection(); 118 {
119 QList<LDObject*> sel = selection();
112 120
113 for (LDObject* obj : sel) 121 for (LDObject* obj : sel)
114 { // Get the index of the subfile so we know where to insert the 122 {
123 // Get the index of the subfile so we know where to insert the
115 // inlined contents. 124 // inlined contents.
116 long idx = obj->getIndex(); 125 long idx = obj->getIndex();
117 126
118 if (idx == -1) 127 if (idx == -1)
119 continue; 128 continue;
129 else 138 else
130 continue; 139 continue;
131 140
132 // Merge in the inlined objects 141 // Merge in the inlined objects
133 for (LDObject * inlineobj : objs) 142 for (LDObject * inlineobj : objs)
134 { str line = inlineobj->raw(); 143 {
144 str line = inlineobj->raw();
135 inlineobj->deleteSelf(); 145 inlineobj->deleteSelf();
136 LDObject* newobj = parseLine (line); 146 LDObject* newobj = parseLine (line);
137 getCurrentDocument()->insertObj (idx++, newobj); 147 getCurrentDocument()->insertObj (idx++, newobj);
138 newobj->select(); 148 newobj->select();
139 g_win->R()->compileObject (newobj); 149 g_win->R()->compileObject (newobj);
145 155
146 g_win->refresh(); 156 g_win->refresh();
147 } 157 }
148 158
149 DEFINE_ACTION (Inline, CTRL (I)) 159 DEFINE_ACTION (Inline, CTRL (I))
150 { doInline (false); 160 {
161 doInline (false);
151 } 162 }
152 163
153 DEFINE_ACTION (InlineDeep, CTRL_SHIFT (I)) 164 DEFINE_ACTION (InlineDeep, CTRL_SHIFT (I))
154 { doInline (true); 165 {
166 doInline (true);
155 } 167 }
156 168
157 // ============================================================================= 169 // =============================================================================
158 // ----------------------------------------------------------------------------- 170 // -----------------------------------------------------------------------------
159 DEFINE_ACTION (SplitQuads, 0) 171 DEFINE_ACTION (SplitQuads, 0)
160 { QList<LDObject*> objs = selection(); 172 {
173 QList<LDObject*> objs = selection();
161 int num = 0; 174 int num = 0;
162 175
163 for (LDObject* obj : objs) 176 for (LDObject* obj : objs)
164 { if (obj->getType() != LDObject::Quad) 177 {
178 if (obj->getType() != LDObject::Quad)
165 continue; 179 continue;
166 180
167 // Find the index of this quad 181 // Find the index of this quad
168 long index = obj->getIndex(); 182 long index = obj->getIndex();
169 183
191 } 205 }
192 206
193 // ============================================================================= 207 // =============================================================================
194 // ----------------------------------------------------------------------------- 208 // -----------------------------------------------------------------------------
195 DEFINE_ACTION (EditRaw, KEY (F9)) 209 DEFINE_ACTION (EditRaw, KEY (F9))
196 { if (selection().size() != 1) 210 {
211 if (selection().size() != 1)
197 return; 212 return;
198 213
199 LDObject* obj = selection()[0]; 214 LDObject* obj = selection()[0];
200 QDialog* dlg = new QDialog; 215 QDialog* dlg = new QDialog;
201 Ui::EditRawUI ui; 216 Ui::EditRawUI ui;
204 ui.code->setText (obj->raw()); 219 ui.code->setText (obj->raw());
205 220
206 if (obj->getType() == LDObject::Error) 221 if (obj->getType() == LDObject::Error)
207 ui.errorDescription->setText (static_cast<LDError*> (obj)->reason); 222 ui.errorDescription->setText (static_cast<LDError*> (obj)->reason);
208 else 223 else
209 { ui.errorDescription->hide(); 224 {
225 ui.errorDescription->hide();
210 ui.errorIcon->hide(); 226 ui.errorIcon->hide();
211 } 227 }
212 228
213 if (!dlg->exec()) 229 if (!dlg->exec())
214 return; 230 return;
225 } 241 }
226 242
227 // ============================================================================= 243 // =============================================================================
228 // ----------------------------------------------------------------------------- 244 // -----------------------------------------------------------------------------
229 DEFINE_ACTION (SetColor, KEY (C)) 245 DEFINE_ACTION (SetColor, KEY (C))
230 { if (selection().isEmpty()) 246 {
247 if (selection().isEmpty())
231 return; 248 return;
232 249
233 int colnum; 250 int colnum;
234 int defcol = -1; 251 int defcol = -1;
235 252
239 // value to the color selection dialog. 256 // value to the color selection dialog.
240 defcol = getSelectedColor(); 257 defcol = getSelectedColor();
241 258
242 // Show the dialog to the user now and ask for a color. 259 // Show the dialog to the user now and ask for a color.
243 if (ColorSelector::selectColor (colnum, defcol, g_win)) 260 if (ColorSelector::selectColor (colnum, defcol, g_win))
244 { for (LDObject* obj : objs) 261 {
245 { if (obj->isColored() == false) 262 for (LDObject* obj : objs)
263 {
264 if (obj->isColored() == false)
246 continue; 265 continue;
247 266
248 obj->setColor (colnum); 267 obj->setColor (colnum);
249 R()->compileObject (obj); 268 R()->compileObject (obj);
250 } 269 }
254 } 273 }
255 274
256 // ============================================================================= 275 // =============================================================================
257 // ----------------------------------------------------------------------------- 276 // -----------------------------------------------------------------------------
258 DEFINE_ACTION (Borders, CTRL_SHIFT (B)) 277 DEFINE_ACTION (Borders, CTRL_SHIFT (B))
259 { QList<LDObject*> objs = selection(); 278 {
279 QList<LDObject*> objs = selection();
260 int num = 0; 280 int num = 0;
261 281
262 for (LDObject* obj : objs) 282 for (LDObject* obj : objs)
263 { const LDObject::Type type = obj->getType(); 283 {
284 const LDObject::Type type = obj->getType();
264 if (type != LDObject::Quad && type != LDObject::Triangle) 285 if (type != LDObject::Quad && type != LDObject::Triangle)
265 continue; 286 continue;
266 287
267 int numLines; 288 int numLines;
268 LDLine* lines[4]; 289 LDLine* lines[4];
269 290
270 if (type == LDObject::Quad) 291 if (type == LDObject::Quad)
271 { numLines = 4; 292 {
293 numLines = 4;
272 294
273 LDQuad* quad = static_cast<LDQuad*> (obj); 295 LDQuad* quad = static_cast<LDQuad*> (obj);
274 lines[0] = new LDLine (quad->getVertex (0), quad->getVertex (1)); 296 lines[0] = new LDLine (quad->getVertex (0), quad->getVertex (1));
275 lines[1] = new LDLine (quad->getVertex (1), quad->getVertex (2)); 297 lines[1] = new LDLine (quad->getVertex (1), quad->getVertex (2));
276 lines[2] = new LDLine (quad->getVertex (2), quad->getVertex (3)); 298 lines[2] = new LDLine (quad->getVertex (2), quad->getVertex (3));
277 lines[3] = new LDLine (quad->getVertex (3), quad->getVertex (0)); 299 lines[3] = new LDLine (quad->getVertex (3), quad->getVertex (0));
278 } 300 }
279 else 301 else
280 { numLines = 3; 302 {
303 numLines = 3;
281 304
282 LDTriangle* tri = static_cast<LDTriangle*> (obj); 305 LDTriangle* tri = static_cast<LDTriangle*> (obj);
283 lines[0] = new LDLine (tri->getVertex (0), tri->getVertex (1)); 306 lines[0] = new LDLine (tri->getVertex (0), tri->getVertex (1));
284 lines[1] = new LDLine (tri->getVertex (1), tri->getVertex (2)); 307 lines[1] = new LDLine (tri->getVertex (1), tri->getVertex (2));
285 lines[2] = new LDLine (tri->getVertex (2), tri->getVertex (0)); 308 lines[2] = new LDLine (tri->getVertex (2), tri->getVertex (0));
286 } 309 }
287 310
288 for (int i = 0; i < numLines; ++i) 311 for (int i = 0; i < numLines; ++i)
289 { long idx = obj->getIndex() + i + 1; 312 {
313 long idx = obj->getIndex() + i + 1;
290 314
291 lines[i]->setColor (edgecolor); 315 lines[i]->setColor (edgecolor);
292 getCurrentDocument()->insertObj (idx, lines[i]); 316 getCurrentDocument()->insertObj (idx, lines[i]);
293 R()->compileObject (lines[i]); 317 R()->compileObject (lines[i]);
294 } 318 }
301 } 325 }
302 326
303 // ============================================================================= 327 // =============================================================================
304 // ----------------------------------------------------------------------------- 328 // -----------------------------------------------------------------------------
305 DEFINE_ACTION (CornerVerts, 0) 329 DEFINE_ACTION (CornerVerts, 0)
306 { int num = 0; 330 {
331 int num = 0;
307 332
308 for (LDObject* obj : selection()) 333 for (LDObject* obj : selection())
309 { if (obj->vertices() < 2) 334 {
335 if (obj->vertices() < 2)
310 continue; 336 continue;
311 337
312 int idx = obj->getIndex(); 338 int idx = obj->getIndex();
313 339
314 for (int i = 0; i < obj->vertices(); ++i) 340 for (int i = 0; i < obj->vertices(); ++i)
315 { LDVertex* vert = new LDVertex; 341 {
342 LDVertex* vert = new LDVertex;
316 vert->pos = obj->getVertex (i); 343 vert->pos = obj->getVertex (i);
317 vert->setColor (obj->getColor()); 344 vert->setColor (obj->getColor());
318 345
319 getCurrentDocument()->insertObj (++idx, vert); 346 getCurrentDocument()->insertObj (++idx, vert);
320 R()->compileObject (vert); 347 R()->compileObject (vert);
327 } 354 }
328 355
329 // ============================================================================= 356 // =============================================================================
330 // ----------------------------------------------------------------------------- 357 // -----------------------------------------------------------------------------
331 static void doMoveSelection (const bool up) 358 static void doMoveSelection (const bool up)
332 { QList<LDObject*> objs = selection(); 359 {
360 QList<LDObject*> objs = selection();
333 LDObject::moveObjects (objs, up); 361 LDObject::moveObjects (objs, up);
334 g_win->buildObjList(); 362 g_win->buildObjList();
335 } 363 }
336 364
337 // ============================================================================= 365 // =============================================================================
338 // ----------------------------------------------------------------------------- 366 // -----------------------------------------------------------------------------
339 DEFINE_ACTION (MoveUp, KEY (PageUp)) 367 DEFINE_ACTION (MoveUp, KEY (PageUp))
340 { doMoveSelection (true); 368 {
369 doMoveSelection (true);
341 } 370 }
342 371
343 DEFINE_ACTION (MoveDown, KEY (PageDown)) 372 DEFINE_ACTION (MoveDown, KEY (PageDown))
344 { doMoveSelection (false); 373 {
374 doMoveSelection (false);
345 } 375 }
346 376
347 // ============================================================================= 377 // =============================================================================
348 // ----------------------------------------------------------------------------- 378 // -----------------------------------------------------------------------------
349 DEFINE_ACTION (Undo, CTRL (Z)) 379 DEFINE_ACTION (Undo, CTRL (Z))
350 { getCurrentDocument()->undo(); 380 {
381 getCurrentDocument()->undo();
351 } 382 }
352 383
353 DEFINE_ACTION (Redo, CTRL_SHIFT (Z)) 384 DEFINE_ACTION (Redo, CTRL_SHIFT (Z))
354 { getCurrentDocument()->redo(); 385 {
386 getCurrentDocument()->redo();
355 } 387 }
356 388
357 // ============================================================================= 389 // =============================================================================
358 // ----------------------------------------------------------------------------- 390 // -----------------------------------------------------------------------------
359 void doMoveObjects (vertex vect) 391 void doMoveObjects (vertex vect)
360 { // Apply the grid values 392 {
393 // Apply the grid values
361 vect[X] *= *currentGrid().confs[Grid::X]; 394 vect[X] *= *currentGrid().confs[Grid::X];
362 vect[Y] *= *currentGrid().confs[Grid::Y]; 395 vect[Y] *= *currentGrid().confs[Grid::Y];
363 vect[Z] *= *currentGrid().confs[Grid::Z]; 396 vect[Z] *= *currentGrid().confs[Grid::Z];
364 397
365 for (LDObject* obj : selection()) 398 for (LDObject* obj : selection())
366 { obj->move (vect); 399 {
400 obj->move (vect);
367 g_win->R()->compileObject (obj); 401 g_win->R()->compileObject (obj);
368 } 402 }
369 403
370 g_win->refresh(); 404 g_win->refresh();
371 } 405 }
372 406
373 // ============================================================================= 407 // =============================================================================
374 // ----------------------------------------------------------------------------- 408 // -----------------------------------------------------------------------------
375 DEFINE_ACTION (MoveXNeg, KEY (Left)) 409 DEFINE_ACTION (MoveXNeg, KEY (Left))
376 { doMoveObjects ({ -1, 0, 0}); 410 {
411 doMoveObjects ({ -1, 0, 0});
377 } 412 }
378 413
379 DEFINE_ACTION (MoveYNeg, KEY (Home)) 414 DEFINE_ACTION (MoveYNeg, KEY (Home))
380 { doMoveObjects ({0, -1, 0}); 415 {
416 doMoveObjects ({0, -1, 0});
381 } 417 }
382 418
383 DEFINE_ACTION (MoveZNeg, KEY (Down)) 419 DEFINE_ACTION (MoveZNeg, KEY (Down))
384 { doMoveObjects ({0, 0, -1}); 420 {
421 doMoveObjects ({0, 0, -1});
385 } 422 }
386 423
387 DEFINE_ACTION (MoveXPos, KEY (Right)) 424 DEFINE_ACTION (MoveXPos, KEY (Right))
388 { doMoveObjects ({1, 0, 0}); 425 {
426 doMoveObjects ({1, 0, 0});
389 } 427 }
390 428
391 DEFINE_ACTION (MoveYPos, KEY (End)) 429 DEFINE_ACTION (MoveYPos, KEY (End))
392 { doMoveObjects ({0, 1, 0}); 430 {
431 doMoveObjects ({0, 1, 0});
393 } 432 }
394 433
395 DEFINE_ACTION (MoveZPos, KEY (Up)) 434 DEFINE_ACTION (MoveZPos, KEY (Up))
396 { doMoveObjects ({0, 0, 1}); 435 {
436 doMoveObjects ({0, 0, 1});
397 } 437 }
398 438
399 // ============================================================================= 439 // =============================================================================
400 // ----------------------------------------------------------------------------- 440 // -----------------------------------------------------------------------------
401 DEFINE_ACTION (Invert, CTRL_SHIFT (W)) 441 DEFINE_ACTION (Invert, CTRL_SHIFT (W))
402 { QList<LDObject*> sel = selection(); 442 {
443 QList<LDObject*> sel = selection();
403 444
404 for (LDObject* obj : sel) 445 for (LDObject* obj : sel)
405 { obj->invert(); 446 {
447 obj->invert();
406 R()->compileObject (obj); 448 R()->compileObject (obj);
407 } 449 }
408 450
409 refresh(); 451 refresh();
410 } 452 }
411 453
412 // ============================================================================= 454 // =============================================================================
413 // ----------------------------------------------------------------------------- 455 // -----------------------------------------------------------------------------
414 static void rotateVertex (vertex& v, const vertex& rotpoint, const matrix& transform) 456 static void rotateVertex (vertex& v, const vertex& rotpoint, const matrix& transform)
415 { v.move (-rotpoint); 457 {
458 v.move (-rotpoint);
416 v.transform (transform, g_origin); 459 v.transform (transform, g_origin);
417 v.move (rotpoint); 460 v.move (rotpoint);
418 } 461 }
419 462
420 // ============================================================================= 463 // =============================================================================
421 // ----------------------------------------------------------------------------- 464 // -----------------------------------------------------------------------------
422 static void doRotate (const int l, const int m, const int n) 465 static void doRotate (const int l, const int m, const int n)
423 { QList<LDObject*> sel = selection(); 466 {
467 QList<LDObject*> sel = selection();
424 QList<vertex*> queue; 468 QList<vertex*> queue;
425 const vertex rotpoint = rotPoint (sel); 469 const vertex rotpoint = rotPoint (sel);
426 const double angle = (pi * *currentGrid().confs[Grid::Angle]) / 180, 470 const double angle = (pi * *currentGrid().confs[Grid::Angle]) / 180,
427 cosangle = cos (angle), 471 cosangle = cos (angle),
428 sinangle = sin (angle); 472 sinangle = sin (angle);
429 473
430 // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2 474 // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2
431 matrix transform ( 475 matrix transform (
432 { (l* l * (1 - cosangle)) + cosangle, 476 {
477 (l* l * (1 - cosangle)) + cosangle,
433 (m* l * (1 - cosangle)) - (n* sinangle), 478 (m* l * (1 - cosangle)) - (n* sinangle),
434 (n* l * (1 - cosangle)) + (m* sinangle), 479 (n* l * (1 - cosangle)) + (m* sinangle),
435 480
436 (l* m * (1 - cosangle)) + (n* sinangle), 481 (l* m * (1 - cosangle)) + (n* sinangle),
437 (m* m * (1 - cosangle)) + cosangle, 482 (m* m * (1 - cosangle)) + cosangle,
442 (n* n * (1 - cosangle)) + cosangle 487 (n* n * (1 - cosangle)) + cosangle
443 }); 488 });
444 489
445 // Apply the above matrix to everything 490 // Apply the above matrix to everything
446 for (LDObject* obj : sel) 491 for (LDObject* obj : sel)
447 { if (obj->vertices()) 492 {
448 { for (int i = 0; i < obj->vertices(); ++i) 493 if (obj->vertices())
449 { vertex v = obj->getVertex (i); 494 {
495 for (int i = 0; i < obj->vertices(); ++i)
496 {
497 vertex v = obj->getVertex (i);
450 rotateVertex (v, rotpoint, transform); 498 rotateVertex (v, rotpoint, transform);
451 obj->setVertex (i, v); 499 obj->setVertex (i, v);
452 } 500 }
453 } elif (obj->hasMatrix()) 501 } elif (obj->hasMatrix())
454 { LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj); 502 {
503 LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj);
455 504
456 // Transform the position 505 // Transform the position
457 /* 506 /*
458 vertex v = mo->getPosition(); 507 vertex v = mo->getPosition();
459 rotateVertex (v, rotpoint, transform); 508 rotateVertex (v, rotpoint, transform);
461 */ 510 */
462 511
463 // Transform the matrix 512 // Transform the matrix
464 mo->setTransform (transform * mo->getTransform()); 513 mo->setTransform (transform * mo->getTransform());
465 } elif (obj->getType() == LDObject::Vertex) 514 } elif (obj->getType() == LDObject::Vertex)
466 { LDVertex* vert = static_cast<LDVertex*> (obj); 515 {
516 LDVertex* vert = static_cast<LDVertex*> (obj);
467 vertex v = vert->pos; 517 vertex v = vert->pos;
468 rotateVertex (v, rotpoint, transform); 518 rotateVertex (v, rotpoint, transform);
469 vert->pos = v; 519 vert->pos = v;
470 } 520 }
471 521
476 } 526 }
477 527
478 // ============================================================================= 528 // =============================================================================
479 // ----------------------------------------------------------------------------- 529 // -----------------------------------------------------------------------------
480 DEFINE_ACTION (RotateXPos, CTRL (Right)) 530 DEFINE_ACTION (RotateXPos, CTRL (Right))
481 { doRotate (1, 0, 0); 531 {
532 doRotate (1, 0, 0);
482 } 533 }
483 DEFINE_ACTION (RotateYPos, CTRL (End)) 534 DEFINE_ACTION (RotateYPos, CTRL (End))
484 { doRotate (0, 1, 0); 535 {
536 doRotate (0, 1, 0);
485 } 537 }
486 DEFINE_ACTION (RotateZPos, CTRL (Up)) 538 DEFINE_ACTION (RotateZPos, CTRL (Up))
487 { doRotate (0, 0, 1); 539 {
540 doRotate (0, 0, 1);
488 } 541 }
489 DEFINE_ACTION (RotateXNeg, CTRL (Left)) 542 DEFINE_ACTION (RotateXNeg, CTRL (Left))
490 { doRotate (-1, 0, 0); 543 {
544 doRotate (-1, 0, 0);
491 } 545 }
492 DEFINE_ACTION (RotateYNeg, CTRL (Home)) 546 DEFINE_ACTION (RotateYNeg, CTRL (Home))
493 { doRotate (0, -1, 0); 547 {
548 doRotate (0, -1, 0);
494 } 549 }
495 DEFINE_ACTION (RotateZNeg, CTRL (Down)) 550 DEFINE_ACTION (RotateZNeg, CTRL (Down))
496 { doRotate (0, 0, -1); 551 {
552 doRotate (0, 0, -1);
497 } 553 }
498 554
499 DEFINE_ACTION (RotationPoint, (0)) 555 DEFINE_ACTION (RotationPoint, (0))
500 { configRotationPoint(); 556 {
557 configRotationPoint();
501 } 558 }
502 559
503 // ============================================================================= 560 // =============================================================================
504 // ----------------------------------------------------------------------------- 561 // -----------------------------------------------------------------------------
505 DEFINE_ACTION (RoundCoordinates, 0) 562 DEFINE_ACTION (RoundCoordinates, 0)
506 { setlocale (LC_ALL, "C"); 563 {
564 setlocale (LC_ALL, "C");
507 int num = 0; 565 int num = 0;
508 566
509 for (LDObject* obj : selection()) 567 for (LDObject* obj : selection())
510 { LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj); 568 {
569 LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj);
511 570
512 if (mo != null) 571 if (mo != null)
513 { vertex v = mo->getPosition(); 572 {
573 vertex v = mo->getPosition();
514 matrix t = mo->getTransform(); 574 matrix t = mo->getTransform();
515 575
516 for_axes (ax) 576 for_axes (ax)
517 roundToDecimals (v[ax], 3); 577 roundToDecimals (v[ax], 3);
518 578
524 mo->setPosition (v); 584 mo->setPosition (v);
525 mo->setTransform (t); 585 mo->setTransform (t);
526 num += 10; 586 num += 10;
527 } 587 }
528 else 588 else
529 { for (int i = 0; i < obj->vertices(); ++i) 589 {
530 { vertex v = obj->getVertex (i); 590 for (int i = 0; i < obj->vertices(); ++i)
591 {
592 vertex v = obj->getVertex (i);
531 593
532 for_axes (ax) 594 for_axes (ax)
533 roundToDecimals (v[ax], 3); 595 roundToDecimals (v[ax], 3);
534 596
535 obj->setVertex (i, v); 597 obj->setVertex (i, v);
545 } 607 }
546 608
547 // ============================================================================= 609 // =============================================================================
548 // ----------------------------------------------------------------------------- 610 // -----------------------------------------------------------------------------
549 DEFINE_ACTION (Uncolorize, 0) 611 DEFINE_ACTION (Uncolorize, 0)
550 { int num = 0; 612 {
613 int num = 0;
551 614
552 for (LDObject* obj : selection()) 615 for (LDObject* obj : selection())
553 { if (obj->isColored() == false) 616 {
617 if (obj->isColored() == false)
554 continue; 618 continue;
555 619
556 int col = maincolor; 620 int col = maincolor;
557 621
558 if (obj->getType() == LDObject::Line || obj->getType() == LDObject::CondLine) 622 if (obj->getType() == LDObject::Line || obj->getType() == LDObject::CondLine)
568 } 632 }
569 633
570 // ============================================================================= 634 // =============================================================================
571 // ----------------------------------------------------------------------------- 635 // -----------------------------------------------------------------------------
572 DEFINE_ACTION (ReplaceCoords, CTRL (R)) 636 DEFINE_ACTION (ReplaceCoords, CTRL (R))
573 { QDialog* dlg = new QDialog (g_win); 637 {
638 QDialog* dlg = new QDialog (g_win);
574 Ui::ReplaceCoordsUI ui; 639 Ui::ReplaceCoordsUI ui;
575 ui.setupUi (dlg); 640 ui.setupUi (dlg);
576 641
577 if (!dlg->exec()) 642 if (!dlg->exec())
578 return; 643 return;
588 if (ui.x->isChecked()) sel << X; 653 if (ui.x->isChecked()) sel << X;
589 if (ui.y->isChecked()) sel << Y; 654 if (ui.y->isChecked()) sel << Y;
590 if (ui.z->isChecked()) sel << Z; 655 if (ui.z->isChecked()) sel << Z;
591 656
592 for (LDObject* obj : selection()) 657 for (LDObject* obj : selection())
593 { for (int i = 0; i < obj->vertices(); ++i) 658 {
594 { vertex v = obj->getVertex (i); 659 for (int i = 0; i < obj->vertices(); ++i)
660 {
661 vertex v = obj->getVertex (i);
595 662
596 for (Axis ax : sel) 663 for (Axis ax : sel)
597 { double& coord = v[ax]; 664 {
665 double& coord = v[ax];
598 666
599 if (any || coord == search) 667 if (any || coord == search)
600 { if (!rel) 668 {
669 if (!rel)
601 coord = 0; 670 coord = 0;
602 671
603 coord += replacement; 672 coord += replacement;
604 num++; 673 num++;
605 } 674 }
615 } 684 }
616 685
617 // ============================================================================= 686 // =============================================================================
618 // ----------------------------------------------------------------------------- 687 // -----------------------------------------------------------------------------
619 DEFINE_ACTION (Flip, CTRL_SHIFT (F)) 688 DEFINE_ACTION (Flip, CTRL_SHIFT (F))
620 { QDialog* dlg = new QDialog; 689 {
690 QDialog* dlg = new QDialog;
621 Ui::FlipUI ui; 691 Ui::FlipUI ui;
622 ui.setupUi (dlg); 692 ui.setupUi (dlg);
623 693
624 if (!dlg->exec()) 694 if (!dlg->exec())
625 return; 695 return;
629 if (ui.x->isChecked()) sel << X; 699 if (ui.x->isChecked()) sel << X;
630 if (ui.y->isChecked()) sel << Y; 700 if (ui.y->isChecked()) sel << Y;
631 if (ui.z->isChecked()) sel << Z; 701 if (ui.z->isChecked()) sel << Z;
632 702
633 for (LDObject* obj : selection()) 703 for (LDObject* obj : selection())
634 { for (int i = 0; i < obj->vertices(); ++i) 704 {
635 { vertex v = obj->getVertex (i); 705 for (int i = 0; i < obj->vertices(); ++i)
706 {
707 vertex v = obj->getVertex (i);
636 708
637 for (Axis ax : sel) 709 for (Axis ax : sel)
638 v[ax] *= -1; 710 v[ax] *= -1;
639 711
640 obj->setVertex (i, v); 712 obj->setVertex (i, v);
646 } 718 }
647 719
648 // ============================================================================= 720 // =============================================================================
649 // ----------------------------------------------------------------------------- 721 // -----------------------------------------------------------------------------
650 DEFINE_ACTION (Demote, 0) 722 DEFINE_ACTION (Demote, 0)
651 { QList<LDObject*> sel = selection(); 723 {
724 QList<LDObject*> sel = selection();
652 int num = 0; 725 int num = 0;
653 726
654 for (LDObject* obj : sel) 727 for (LDObject* obj : sel)
655 { if (obj->getType() != LDObject::CondLine) 728 {
729 if (obj->getType() != LDObject::CondLine)
656 continue; 730 continue;
657 731
658 LDLine* repl = static_cast<LDCondLine*> (obj)->demote(); 732 LDLine* repl = static_cast<LDCondLine*> (obj)->demote();
659 R()->compileObject (repl); 733 R()->compileObject (repl);
660 ++num; 734 ++num;
665 } 739 }
666 740
667 // ============================================================================= 741 // =============================================================================
668 // ----------------------------------------------------------------------------- 742 // -----------------------------------------------------------------------------
669 static bool isColorUsed (int colnum) 743 static bool isColorUsed (int colnum)
670 { for (LDObject* obj : getCurrentDocument()->getObjects()) 744 {
745 for (LDObject* obj : getCurrentDocument()->getObjects())
671 if (obj->isColored() && obj->getColor() == colnum) 746 if (obj->isColored() && obj->getColor() == colnum)
672 return true; 747 return true;
673 748
674 return false; 749 return false;
675 } 750 }
676 751
677 // ============================================================================= 752 // =============================================================================
678 // ----------------------------------------------------------------------------- 753 // -----------------------------------------------------------------------------
679 DEFINE_ACTION (Autocolor, 0) 754 DEFINE_ACTION (Autocolor, 0)
680 { int colnum = 0; 755 {
756 int colnum = 0;
681 757
682 while (colnum < MAX_COLORS && (getColor (colnum) == null || isColorUsed (colnum))) 758 while (colnum < MAX_COLORS && (getColor (colnum) == null || isColorUsed (colnum)))
683 colnum++; 759 colnum++;
684 760
685 if (colnum >= MAX_COLORS) 761 if (colnum >= MAX_COLORS)
686 { log (tr ("Cannot auto-color: all colors are in use!")); 762 {
763 log (tr ("Cannot auto-color: all colors are in use!"));
687 return; 764 return;
688 } 765 }
689 766
690 for (LDObject* obj : selection()) 767 for (LDObject* obj : selection())
691 { if (obj->isColored() == false) 768 {
769 if (obj->isColored() == false)
692 continue; 770 continue;
693 771
694 obj->setColor (colnum); 772 obj->setColor (colnum);
695 R()->compileObject (obj); 773 R()->compileObject (obj);
696 } 774 }
700 } 778 }
701 779
702 // ============================================================================= 780 // =============================================================================
703 // ----------------------------------------------------------------------------- 781 // -----------------------------------------------------------------------------
704 DEFINE_ACTION (AddHistoryLine, 0) 782 DEFINE_ACTION (AddHistoryLine, 0)
705 { LDObject* obj; 783 {
784 LDObject* obj;
706 bool ishistory = false, 785 bool ishistory = false,
707 prevIsHistory = false; 786 prevIsHistory = false;
708 787
709 QDialog* dlg = new QDialog; 788 QDialog* dlg = new QDialog;
710 Ui_AddHistoryLine* ui = new Ui_AddHistoryLine; 789 Ui_AddHistoryLine* ui = new Ui_AddHistoryLine;
728 for ( 807 for (
729 obj = getCurrentDocument()->getObject (0); 808 obj = getCurrentDocument()->getObject (0);
730 obj && obj->next() && !obj->next()->isScemantic(); 809 obj && obj->next() && !obj->next()->isScemantic();
731 obj = obj->next() 810 obj = obj->next()
732 ) 811 )
733 { LDComment* comm = dynamic_cast<LDComment*> (obj); 812 {
813 LDComment* comm = dynamic_cast<LDComment*> (obj);
734 814
735 if (comm && comm->text.startsWith ("!HISTORY ")) 815 if (comm && comm->text.startsWith ("!HISTORY "))
736 ishistory = true; 816 ishistory = true;
737 817
738 if (prevIsHistory && !ishistory) 818 if (prevIsHistory && !ishistory)
739 { // Last line was history, this isn't, thus insert the new history 819 {
820 // Last line was history, this isn't, thus insert the new history
740 // line here. 821 // line here.
741 break; 822 break;
742 } 823 }
743 824
744 prevIsHistory = ishistory; 825 prevIsHistory = ishistory;

mercurial