36 #include "ui_addhistoryline.h" |
36 #include "ui_addhistoryline.h" |
37 |
37 |
38 cfg (bool, edit_schemanticinline, false); |
38 cfg (bool, edit_schemanticinline, false); |
39 |
39 |
40 // ============================================================================= |
40 // ============================================================================= |
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
41 // ----------------------------------------------------------------------------- |
42 // ============================================================================= |
|
43 static int copyToClipboard() { |
42 static int copyToClipboard() { |
44 List<LDObject*> objs = g_win->sel(); |
43 List<LDObject*> objs = g_win->sel(); |
45 int num = 0; |
44 int num = 0; |
46 |
45 |
47 // Clear the clipboard first. |
46 // Clear the clipboard first. |
61 qApp->clipboard()->setText (data); |
60 qApp->clipboard()->setText (data); |
62 return num; |
61 return num; |
63 } |
62 } |
64 |
63 |
65 // ============================================================================= |
64 // ============================================================================= |
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
65 // ----------------------------------------------------------------------------- |
67 // ============================================================================= |
|
68 DEFINE_ACTION (Cut, CTRL (X)) { |
66 DEFINE_ACTION (Cut, CTRL (X)) { |
69 int num = copyToClipboard(); |
67 int num = copyToClipboard(); |
70 g_win->deleteSelection(); |
68 g_win->deleteSelection(); |
71 log (ForgeWindow::tr ("%1 objects cut"), num); |
69 log (ForgeWindow::tr ("%1 objects cut"), num); |
72 } |
70 } |
73 |
71 |
74 // ============================================================================= |
72 // ============================================================================= |
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
73 // ----------------------------------------------------------------------------- |
76 // ============================================================================= |
|
77 DEFINE_ACTION (Copy, CTRL (C)) { |
74 DEFINE_ACTION (Copy, CTRL (C)) { |
78 int num = copyToClipboard(); |
75 int num = copyToClipboard(); |
79 log (ForgeWindow::tr ("%1 objects copied"), num); |
76 log (ForgeWindow::tr ("%1 objects copied"), num); |
80 } |
77 } |
81 |
78 |
82 // ============================================================================= |
79 // ============================================================================= |
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
80 // ----------------------------------------------------------------------------- |
84 // ============================================================================= |
|
85 DEFINE_ACTION (Paste, CTRL (V)) { |
81 DEFINE_ACTION (Paste, CTRL (V)) { |
86 const str clipboardText = qApp->clipboard()->text(); |
82 const str clipboardText = qApp->clipboard()->text(); |
87 ulong idx = g_win->getInsertionPoint(); |
83 ulong idx = g_win->getInsertionPoint(); |
88 g_win->sel().clear(); |
84 g_win->sel().clear(); |
89 int num = 0; |
85 int num = 0; |
100 g_win->refresh(); |
96 g_win->refresh(); |
101 g_win->scrollToSelection(); |
97 g_win->scrollToSelection(); |
102 } |
98 } |
103 |
99 |
104 // ============================================================================= |
100 // ============================================================================= |
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
101 // ----------------------------------------------------------------------------- |
106 // ============================================================================= |
|
107 DEFINE_ACTION (Delete, KEY (Delete)) { |
102 DEFINE_ACTION (Delete, KEY (Delete)) { |
108 int num = g_win->deleteSelection(); |
103 int num = g_win->deleteSelection(); |
109 log (ForgeWindow::tr ("%1 objects deleted"), num); |
104 log (ForgeWindow::tr ("%1 objects deleted"), num); |
110 } |
105 } |
111 |
106 |
112 // ============================================================================= |
107 // ============================================================================= |
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
108 // ----------------------------------------------------------------------------- |
114 // ============================================================================= |
|
115 static void doInline (bool deep) { |
109 static void doInline (bool deep) { |
116 List<LDObject*> sel = g_win->sel(); |
110 List<LDObject*> sel = g_win->sel(); |
117 |
111 |
118 for (LDObject* obj : sel) { |
112 for (LDObject* obj : sel) { |
119 // Get the index of the subfile so we know where to insert the |
113 // Get the index of the subfile so we know where to insert the |
155 |
149 |
156 DEFINE_ACTION (InlineDeep, CTRL_SHIFT (I)) { |
150 DEFINE_ACTION (InlineDeep, CTRL_SHIFT (I)) { |
157 doInline (true); |
151 doInline (true); |
158 } |
152 } |
159 |
153 |
160 // =============================================================================================== |
154 // ============================================================================= |
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
155 // ----------------------------------------------------------------------------- |
162 // =============================================================================================== |
|
163 DEFINE_ACTION (SplitQuads, 0) { |
156 DEFINE_ACTION (SplitQuads, 0) { |
164 List<LDObject*> objs = g_win->sel(); |
157 List<LDObject*> objs = g_win->sel(); |
165 int num = 0; |
158 int num = 0; |
166 |
159 |
167 for (LDObject* obj : objs) { |
160 for (LDObject* obj : objs) { |
193 log ("%1 quadrilaterals split", num); |
186 log ("%1 quadrilaterals split", num); |
194 g_win->refresh(); |
187 g_win->refresh(); |
195 } |
188 } |
196 |
189 |
197 // ============================================================================= |
190 // ============================================================================= |
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
191 // ----------------------------------------------------------------------------- |
199 // ============================================================================= |
|
200 DEFINE_ACTION (EditRaw, KEY (F9)) { |
192 DEFINE_ACTION (EditRaw, KEY (F9)) { |
201 if (g_win->sel().size() != 1) |
193 if (g_win->sel().size() != 1) |
202 return; |
194 return; |
203 |
195 |
204 LDObject* obj = g_win->sel() [0]; |
196 LDObject* obj = g_win->sel() [0]; |
228 g_win->R()->compileObject (obj); |
220 g_win->R()->compileObject (obj); |
229 g_win->refresh(); |
221 g_win->refresh(); |
230 } |
222 } |
231 |
223 |
232 // ============================================================================= |
224 // ============================================================================= |
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
225 // ----------------------------------------------------------------------------- |
234 // ============================================================================= |
|
235 DEFINE_ACTION (SetColor, KEY (C)) { |
226 DEFINE_ACTION (SetColor, KEY (C)) { |
236 if (g_win->sel().size() <= 0) |
227 if (g_win->sel().size() <= 0) |
237 return; |
228 return; |
238 |
229 |
239 short colnum; |
230 short colnum; |
258 g_win->refresh(); |
249 g_win->refresh(); |
259 } |
250 } |
260 } |
251 } |
261 |
252 |
262 // ============================================================================= |
253 // ============================================================================= |
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
254 // ----------------------------------------------------------------------------- |
264 // ============================================================================= |
|
265 DEFINE_ACTION (Borders, CTRL_SHIFT (B)) { |
255 DEFINE_ACTION (Borders, CTRL_SHIFT (B)) { |
266 List<LDObject*> objs = g_win->sel(); |
256 List<LDObject*> objs = g_win->sel(); |
267 int num = 0; |
257 int num = 0; |
268 |
258 |
269 for (LDObject* obj : objs) { |
259 for (LDObject* obj : objs) { |
304 log (ForgeWindow::tr ("Added %1 border lines"), num); |
294 log (ForgeWindow::tr ("Added %1 border lines"), num); |
305 g_win->refresh(); |
295 g_win->refresh(); |
306 } |
296 } |
307 |
297 |
308 // ============================================================================= |
298 // ============================================================================= |
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
299 // ----------------------------------------------------------------------------- |
310 // ============================================================================= |
|
311 DEFINE_ACTION (CornerVerts, 0) { |
300 DEFINE_ACTION (CornerVerts, 0) { |
312 int num = 0; |
301 int num = 0; |
313 |
302 |
314 for (LDObject* obj : g_win->sel()) { |
303 for (LDObject* obj : g_win->sel()) { |
315 if (obj->vertices() < 2) |
304 if (obj->vertices() < 2) |
331 log (ForgeWindow::tr ("Added %1 vertices"), num); |
320 log (ForgeWindow::tr ("Added %1 vertices"), num); |
332 g_win->refresh(); |
321 g_win->refresh(); |
333 } |
322 } |
334 |
323 |
335 // ============================================================================= |
324 // ============================================================================= |
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
325 // ----------------------------------------------------------------------------- |
337 // ============================================================================= |
|
338 static void doMoveSelection (const bool up) { |
326 static void doMoveSelection (const bool up) { |
339 List<LDObject*> objs = g_win->sel(); |
327 List<LDObject*> objs = g_win->sel(); |
340 LDObject::moveObjects (objs, up); |
328 LDObject::moveObjects (objs, up); |
341 g_win->buildObjList(); |
329 g_win->buildObjList(); |
342 } |
330 } |
343 |
331 |
|
332 // ============================================================================= |
|
333 // ----------------------------------------------------------------------------- |
344 DEFINE_ACTION (MoveUp, KEY (PageUp)) { |
334 DEFINE_ACTION (MoveUp, KEY (PageUp)) { |
345 doMoveSelection (true); |
335 doMoveSelection (true); |
346 } |
336 } |
347 |
337 |
348 DEFINE_ACTION (MoveDown, KEY (PageDown)) { |
338 DEFINE_ACTION (MoveDown, KEY (PageDown)) { |
349 doMoveSelection (false); |
339 doMoveSelection (false); |
350 } |
340 } |
351 |
341 |
352 // ============================================================================= |
342 // ============================================================================= |
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
343 // ----------------------------------------------------------------------------- |
354 // ============================================================================= |
|
355 DEFINE_ACTION (Undo, CTRL (Z)) { |
344 DEFINE_ACTION (Undo, CTRL (Z)) { |
356 LDFile::current()->undo(); |
345 LDFile::current()->undo(); |
357 } |
346 } |
358 |
347 |
359 DEFINE_ACTION (Redo, CTRL_SHIFT (Z)) { |
348 DEFINE_ACTION (Redo, CTRL_SHIFT (Z)) { |
360 LDFile::current()->redo(); |
349 LDFile::current()->redo(); |
361 } |
350 } |
362 |
351 |
363 // ============================================================================= |
352 // ============================================================================= |
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
353 // ----------------------------------------------------------------------------- |
365 // ============================================================================= |
|
366 void doMoveObjects (vertex vect) { |
354 void doMoveObjects (vertex vect) { |
367 // Apply the grid values |
355 // Apply the grid values |
368 vect[X] *= currentGrid().confs[Grid::X]->value; |
356 vect[X] *= currentGrid().confs[Grid::X]->value; |
369 vect[Y] *= currentGrid().confs[Grid::Y]->value; |
357 vect[Y] *= currentGrid().confs[Grid::Y]->value; |
370 vect[Z] *= currentGrid().confs[Grid::Z]->value; |
358 vect[Z] *= currentGrid().confs[Grid::Z]->value; |
375 } |
363 } |
376 |
364 |
377 g_win->refresh(); |
365 g_win->refresh(); |
378 } |
366 } |
379 |
367 |
|
368 // ============================================================================= |
|
369 // ----------------------------------------------------------------------------- |
380 DEFINE_ACTION (MoveXNeg, KEY (Left)) { |
370 DEFINE_ACTION (MoveXNeg, KEY (Left)) { |
381 doMoveObjects ({ -1, 0, 0}); |
371 doMoveObjects ({-1, 0, 0}); |
382 } |
372 } |
383 |
373 |
384 DEFINE_ACTION (MoveYNeg, KEY (Home)) { |
374 DEFINE_ACTION (MoveYNeg, KEY (Home)) { |
385 doMoveObjects ({0, -1, 0}); |
375 doMoveObjects ({0, -1, 0}); |
386 } |
376 } |
400 DEFINE_ACTION (MoveZPos, KEY (Up)) { |
390 DEFINE_ACTION (MoveZPos, KEY (Up)) { |
401 doMoveObjects ({0, 0, 1}); |
391 doMoveObjects ({0, 0, 1}); |
402 } |
392 } |
403 |
393 |
404 // ============================================================================= |
394 // ============================================================================= |
|
395 // ----------------------------------------------------------------------------- |
405 DEFINE_ACTION (Invert, CTRL_SHIFT (W)) { |
396 DEFINE_ACTION (Invert, CTRL_SHIFT (W)) { |
406 List<LDObject*> sel = g_win->sel(); |
397 List<LDObject*> sel = g_win->sel(); |
407 |
398 |
408 for (LDObject* obj : sel) { |
399 for (LDObject* obj : sel) { |
409 obj->invert(); |
400 obj->invert(); |
412 |
403 |
413 g_win->refresh(); |
404 g_win->refresh(); |
414 } |
405 } |
415 |
406 |
416 // ============================================================================= |
407 // ============================================================================= |
|
408 // ----------------------------------------------------------------------------- |
417 static void rotateVertex (vertex& v, const vertex& rotpoint, const matrix& transform) { |
409 static void rotateVertex (vertex& v, const vertex& rotpoint, const matrix& transform) { |
418 v.move (-rotpoint); |
410 v.move (-rotpoint); |
419 v.transform (transform, g_origin); |
411 v.transform (transform, g_origin); |
420 v.move (rotpoint); |
412 v.move (rotpoint); |
421 } |
413 } |
422 |
414 |
|
415 // ============================================================================= |
|
416 // ----------------------------------------------------------------------------- |
423 static void doRotate (const short l, const short m, const short n) { |
417 static void doRotate (const short l, const short m, const short n) { |
424 List<LDObject*> sel = g_win->sel(); |
418 List<LDObject*> sel = g_win->sel(); |
425 List<vertex*> queue; |
419 List<vertex*> queue; |
426 const vertex rotpoint = rotPoint (sel); |
420 const vertex rotpoint = rotPoint (sel); |
427 const double angle = (pi * currentGrid().confs[Grid::Angle]->value) / 180; |
421 const double angle = (pi * currentGrid().confs[Grid::Angle]->value) / 180; |
469 } |
463 } |
470 |
464 |
471 g_win->refresh(); |
465 g_win->refresh(); |
472 } |
466 } |
473 |
467 |
|
468 // ============================================================================= |
|
469 // ----------------------------------------------------------------------------- |
474 DEFINE_ACTION (RotateXPos, CTRL (Right)) { doRotate (1, 0, 0); } |
470 DEFINE_ACTION (RotateXPos, CTRL (Right)) { doRotate (1, 0, 0); } |
475 DEFINE_ACTION (RotateYPos, CTRL (End)) { doRotate (0, 1, 0); } |
471 DEFINE_ACTION (RotateYPos, CTRL (End)) { doRotate (0, 1, 0); } |
476 DEFINE_ACTION (RotateZPos, CTRL (Up)) { doRotate (0, 0, 1); } |
472 DEFINE_ACTION (RotateZPos, CTRL (Up)) { doRotate (0, 0, 1); } |
477 DEFINE_ACTION (RotateXNeg, CTRL (Left)) { doRotate (-1, 0, 0); } |
473 DEFINE_ACTION (RotateXNeg, CTRL (Left)) { doRotate (-1, 0, 0); } |
478 DEFINE_ACTION (RotateYNeg, CTRL (Home)) { doRotate (0, -1, 0); } |
474 DEFINE_ACTION (RotateYNeg, CTRL (Home)) { doRotate (0, -1, 0); } |
481 DEFINE_ACTION (RotationPoint, (0)) { |
477 DEFINE_ACTION (RotationPoint, (0)) { |
482 configRotationPoint(); |
478 configRotationPoint(); |
483 } |
479 } |
484 |
480 |
485 // ============================================================================= |
481 // ============================================================================= |
486 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
482 // ----------------------------------------------------------------------------- |
487 // ============================================================================= |
|
488 DEFINE_ACTION (RoundCoordinates, 0) { |
483 DEFINE_ACTION (RoundCoordinates, 0) { |
489 setlocale (LC_ALL, "C"); |
484 setlocale (LC_ALL, "C"); |
490 int num = 0; |
485 int num = 0; |
491 |
486 |
492 for (LDObject* obj : g_win->sel()) |
487 for (LDObject* obj : g_win->sel()) |
508 log (ForgeWindow::tr ("Rounded %1 coordinates"), num); |
503 log (ForgeWindow::tr ("Rounded %1 coordinates"), num); |
509 g_win->refresh(); |
504 g_win->refresh(); |
510 } |
505 } |
511 |
506 |
512 // ============================================================================= |
507 // ============================================================================= |
513 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
508 // ----------------------------------------------------------------------------- |
514 // ============================================================================= |
|
515 DEFINE_ACTION (Uncolorize, 0) { |
509 DEFINE_ACTION (Uncolorize, 0) { |
516 int num = 0; |
510 int num = 0; |
517 |
511 |
518 for (LDObject* obj : g_win->sel()) { |
512 for (LDObject* obj : g_win->sel()) { |
519 if (obj->isColored() == false) |
513 if (obj->isColored() == false) |
532 log (ForgeWindow::tr ("%1 objects uncolored"), num); |
526 log (ForgeWindow::tr ("%1 objects uncolored"), num); |
533 g_win->refresh(); |
527 g_win->refresh(); |
534 } |
528 } |
535 |
529 |
536 // ============================================================================= |
530 // ============================================================================= |
|
531 // ----------------------------------------------------------------------------- |
537 DEFINE_ACTION (ReplaceCoords, CTRL (R)) { |
532 DEFINE_ACTION (ReplaceCoords, CTRL (R)) { |
538 QDialog* dlg = new QDialog (g_win); |
533 QDialog* dlg = new QDialog (g_win); |
539 Ui::ReplaceCoordsUI ui; |
534 Ui::ReplaceCoordsUI ui; |
540 ui.setupUi (dlg); |
535 ui.setupUi (dlg); |
541 |
536 |
622 |
619 |
623 log (ForgeWindow::tr ("Demoted %1 conditional lines"), num); |
620 log (ForgeWindow::tr ("Demoted %1 conditional lines"), num); |
624 g_win->refresh(); |
621 g_win->refresh(); |
625 } |
622 } |
626 |
623 |
627 // ================================================================================================= |
624 // ============================================================================= |
|
625 // ----------------------------------------------------------------------------- |
628 static bool isColorUsed (short colnum) { |
626 static bool isColorUsed (short colnum) { |
629 for (LDObject* obj : LDFile::current()->objs()) |
627 for (LDObject* obj : LDFile::current()->objs()) |
630 if (obj->isColored() && obj->color() == colnum) |
628 if (obj->isColored() && obj->color() == colnum) |
631 return true; |
629 return true; |
632 |
630 |
633 return false; |
631 return false; |
634 } |
632 } |
635 |
633 |
|
634 // ============================================================================= |
|
635 // ----------------------------------------------------------------------------- |
636 DEFINE_ACTION (Autocolor, 0) { |
636 DEFINE_ACTION (Autocolor, 0) { |
637 short colnum = 0; |
637 short colnum = 0; |
638 |
638 |
639 while (colnum < MAX_COLORS && (getColor (colnum) == null || isColorUsed (colnum))) |
639 while (colnum < MAX_COLORS && (getColor (colnum) == null || isColorUsed (colnum))) |
640 colnum++; |
640 colnum++; |