src/gui_actions.cc

changeset 587
507e5d5c348c
parent 578
a86ae85a277c
child 590
7aec744ce97b
equal deleted inserted replaced
586:89d1161197d3 587:507e5d5c348c
99 new LDEmpty, 99 new LDEmpty,
100 new LDBFC (BFCType), 100 new LDBFC (BFCType),
101 new LDEmpty, 101 new LDEmpty,
102 }); 102 });
103 103
104 g_win->doFullRefresh(); 104 doFullRefresh();
105 } 105 }
106 106
107 // ============================================================================= 107 // =============================================================================
108 // ----------------------------------------------------------------------------- 108 // -----------------------------------------------------------------------------
109 DEFINE_ACTION (NewFile, CTRL (N)) 109 DEFINE_ACTION (NewFile, CTRL (N))
122 } 122 }
123 123
124 // ============================================================================= 124 // =============================================================================
125 // ----------------------------------------------------------------------------- 125 // -----------------------------------------------------------------------------
126 DEFINE_ACTION (Save, CTRL (S)) 126 DEFINE_ACTION (Save, CTRL (S))
127 { g_win->save (getCurrentDocument(), false); 127 { save (getCurrentDocument(), false);
128 } 128 }
129 129
130 // ============================================================================= 130 // =============================================================================
131 // ----------------------------------------------------------------------------- 131 // -----------------------------------------------------------------------------
132 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) 132 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S))
133 { g_win->save (getCurrentDocument(), true); 133 { save (getCurrentDocument(), true);
134 } 134 }
135 135
136 // ============================================================================= 136 // =============================================================================
137 // ----------------------------------------------------------------------------- 137 // -----------------------------------------------------------------------------
138 DEFINE_ACTION (SaveAll, CTRL (L)) 138 DEFINE_ACTION (SaveAll, CTRL (L))
139 { for (LDDocument* file : g_loadedFiles) 139 { for (LDDocument* file : g_loadedFiles)
140 { if (file->isImplicit()) 140 { if (file->isImplicit())
141 continue; 141 continue;
142 142
143 g_win->save (file, false); 143 save (file, false);
144 } 144 }
145 } 145 }
146 146
147 // ============================================================================= 147 // =============================================================================
148 // ----------------------------------------------------------------------------- 148 // -----------------------------------------------------------------------------
260 // ----------------------------------------------------------------------------- 260 // -----------------------------------------------------------------------------
261 DEFINE_ACTION (SelectAll, CTRL (A)) 261 DEFINE_ACTION (SelectAll, CTRL (A))
262 { for (LDObject* obj : getCurrentDocument()->getObjects()) 262 { for (LDObject* obj : getCurrentDocument()->getObjects())
263 obj->select(); 263 obj->select();
264 264
265 g_win->updateSelection(); 265 updateSelection();
266 } 266 }
267 267
268 // ============================================================================= 268 // =============================================================================
269 // ----------------------------------------------------------------------------- 269 // -----------------------------------------------------------------------------
270 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) 270 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A))
271 { int colnum = g_win->getSelectedColor(); 271 { int colnum = getSelectedColor();
272 272
273 if (colnum == -1) 273 if (colnum == -1)
274 return; // no consensus on color 274 return; // no consensus on color
275 275
276 getCurrentDocument()->clearSelection(); 276 getCurrentDocument()->clearSelection();
277 277
278 for (LDObject* obj : getCurrentDocument()->getObjects()) 278 for (LDObject* obj : getCurrentDocument()->getObjects())
279 if (obj->getColor() == colnum) 279 if (obj->getColor() == colnum)
280 obj->select(); 280 obj->select();
281 281
282 g_win->updateSelection(); 282 updateSelection();
283 } 283 }
284 284
285 // ============================================================================= 285 // =============================================================================
286 // ----------------------------------------------------------------------------- 286 // -----------------------------------------------------------------------------
287 DEFINE_ACTION (SelectByType, 0) 287 DEFINE_ACTION (SelectByType, 0)
288 { if (selection().isEmpty()) 288 { if (selection().isEmpty())
289 return; 289 return;
290 290
291 LDObject::Type type = g_win->getUniformSelectedType(); 291 LDObject::Type type = getUniformSelectedType();
292 292
293 if (type == LDObject::Unidentified) 293 if (type == LDObject::Unidentified)
294 return; 294 return;
295 295
296 // If we're selecting subfile references, the reference filename must also 296 // If we're selecting subfile references, the reference filename must also
315 continue; 315 continue;
316 316
317 obj->select(); 317 obj->select();
318 } 318 }
319 319
320 g_win->updateSelection(); 320 updateSelection();
321 } 321 }
322 322
323 // ============================================================================= 323 // =============================================================================
324 // ----------------------------------------------------------------------------- 324 // -----------------------------------------------------------------------------
325 DEFINE_ACTION (GridCoarse, 0) 325 DEFINE_ACTION (GridCoarse, 0)
326 { grid = Grid::Coarse; 326 { grid = Grid::Coarse;
327 g_win->updateGridToolBar(); 327 updateGridToolBar();
328 } 328 }
329 329
330 DEFINE_ACTION (GridMedium, 0) 330 DEFINE_ACTION (GridMedium, 0)
331 { grid = Grid::Medium; 331 { grid = Grid::Medium;
332 g_win->updateGridToolBar(); 332 updateGridToolBar();
333 } 333 }
334 334
335 DEFINE_ACTION (GridFine, 0) 335 DEFINE_ACTION (GridFine, 0)
336 { grid = Grid::Fine; 336 { grid = Grid::Fine;
337 g_win->updateGridToolBar(); 337 updateGridToolBar();
338 } 338 }
339 339
340 // ============================================================================= 340 // =============================================================================
341 // ----------------------------------------------------------------------------- 341 // -----------------------------------------------------------------------------
342 DEFINE_ACTION (ResetView, CTRL (0)) 342 DEFINE_ACTION (ResetView, CTRL (0))
343 { g_win->R()->resetAngles(); 343 { R()->resetAngles();
344 g_win->R()->update(); 344 R()->update();
345 } 345 }
346 346
347 // ============================================================================= 347 // =============================================================================
348 // ----------------------------------------------------------------------------- 348 // -----------------------------------------------------------------------------
349 DEFINE_ACTION (InsertFrom, 0) 349 DEFINE_ACTION (InsertFrom, 0)
350 { str fname = QFileDialog::getOpenFileName(); 350 { str fname = QFileDialog::getOpenFileName();
351 int idx = g_win->getInsertionPoint(); 351 int idx = getInsertionPoint();
352 352
353 if (!fname.length()) 353 if (!fname.length())
354 return; 354 return;
355 355
356 File f (fname, File::Read); 356 File f (fname, File::Read);
365 getCurrentDocument()->clearSelection(); 365 getCurrentDocument()->clearSelection();
366 366
367 for (LDObject* obj : objs) 367 for (LDObject* obj : objs)
368 { getCurrentDocument()->insertObj (idx, obj); 368 { getCurrentDocument()->insertObj (idx, obj);
369 obj->select(); 369 obj->select();
370 g_win->R()->compileObject (obj); 370 R()->compileObject (obj);
371 371
372 idx++; 372 idx++;
373 } 373 }
374 374
375 g_win->refresh(); 375 refresh();
376 g_win->scrollToSelection(); 376 scrollToSelection();
377 } 377 }
378 378
379 // ============================================================================= 379 // =============================================================================
380 // ----------------------------------------------------------------------------- 380 // -----------------------------------------------------------------------------
381 DEFINE_ACTION (ExportTo, 0) 381 DEFINE_ACTION (ExportTo, 0)
403 } 403 }
404 404
405 // ============================================================================= 405 // =============================================================================
406 // ----------------------------------------------------------------------------- 406 // -----------------------------------------------------------------------------
407 DEFINE_ACTION (InsertRaw, 0) 407 DEFINE_ACTION (InsertRaw, 0)
408 { int idx = g_win->getInsertionPoint(); 408 { int idx = getInsertionPoint();
409 409
410 QDialog* const dlg = new QDialog; 410 QDialog* const dlg = new QDialog;
411 QVBoxLayout* const layout = new QVBoxLayout; 411 QVBoxLayout* const layout = new QVBoxLayout;
412 QTextEdit* const te_edit = new QTextEdit; 412 QTextEdit* const te_edit = new QTextEdit;
413 QDialogButtonBox* const bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 413 QDialogButtonBox* const bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
427 for (str line : str (te_edit->toPlainText()).split ("\n")) 427 for (str line : str (te_edit->toPlainText()).split ("\n"))
428 { LDObject* obj = parseLine (line); 428 { LDObject* obj = parseLine (line);
429 429
430 getCurrentDocument()->insertObj (idx, obj); 430 getCurrentDocument()->insertObj (idx, obj);
431 obj->select(); 431 obj->select();
432 g_win->R()->compileObject (obj); 432 R()->compileObject (obj);
433 idx++; 433 idx++;
434 } 434 }
435 435
436 g_win->refresh(); 436 refresh();
437 g_win->scrollToSelection(); 437 scrollToSelection();
438 } 438 }
439 439
440 // ============================================================================= 440 // =============================================================================
441 // ----------------------------------------------------------------------------- 441 // -----------------------------------------------------------------------------
442 DEFINE_ACTION (Screenshot, 0) 442 DEFINE_ACTION (Screenshot, 0)
443 { setlocale (LC_ALL, "C"); 443 { setlocale (LC_ALL, "C");
444 444
445 int w, h; 445 int w, h;
446 uchar* imgdata = g_win->R()->getScreencap (w, h); 446 uchar* imgdata = R()->getScreencap (w, h);
447 QImage img = imageFromScreencap (imgdata, w, h); 447 QImage img = imageFromScreencap (imgdata, w, h);
448 448
449 str root = basename (getCurrentDocument()->getName()); 449 str root = basename (getCurrentDocument()->getName());
450 450
451 if (root.right (4) == ".dat") 451 if (root.right (4) == ".dat")
464 // ============================================================================= 464 // =============================================================================
465 // ----------------------------------------------------------------------------- 465 // -----------------------------------------------------------------------------
466 extern_cfg (Bool, gl_axes); 466 extern_cfg (Bool, gl_axes);
467 DEFINE_ACTION (Axes, 0) 467 DEFINE_ACTION (Axes, 0)
468 { gl_axes = !gl_axes; 468 { gl_axes = !gl_axes;
469 g_win->updateActions(); 469 updateActions();
470 g_win->R()->update(); 470 R()->update();
471 } 471 }
472 472
473 // ============================================================================= 473 // =============================================================================
474 // ----------------------------------------------------------------------------- 474 // -----------------------------------------------------------------------------
475 DEFINE_ACTION (VisibilityToggle, 0) 475 DEFINE_ACTION (VisibilityToggle, 0)
476 { for (LDObject* obj : selection()) 476 { for (LDObject* obj : selection())
477 obj->toggleHidden(); 477 obj->toggleHidden();
478 478
479 g_win->refresh(); 479 refresh();
480 } 480 }
481 481
482 // ============================================================================= 482 // =============================================================================
483 // ----------------------------------------------------------------------------- 483 // -----------------------------------------------------------------------------
484 DEFINE_ACTION (VisibilityHide, 0) 484 DEFINE_ACTION (VisibilityHide, 0)
485 { for (LDObject* obj : selection()) 485 { for (LDObject* obj : selection())
486 obj->setHidden (true); 486 obj->setHidden (true);
487 487
488 g_win->refresh(); 488 refresh();
489 } 489 }
490 490
491 // ============================================================================= 491 // =============================================================================
492 // ----------------------------------------------------------------------------- 492 // -----------------------------------------------------------------------------
493 DEFINE_ACTION (VisibilityReveal, 0) 493 DEFINE_ACTION (VisibilityReveal, 0)
494 { for (LDObject* obj : selection()) 494 { for (LDObject* obj : selection())
495 obj->setHidden (false); 495 obj->setHidden (false);
496 g_win->refresh(); 496 refresh();
497 } 497 }
498 498
499 // ============================================================================= 499 // =============================================================================
500 // ----------------------------------------------------------------------------- 500 // -----------------------------------------------------------------------------
501 DEFINE_ACTION (Wireframe, 0) 501 DEFINE_ACTION (Wireframe, 0)
502 { gl_wireframe = !gl_wireframe; 502 { gl_wireframe = !gl_wireframe;
503 g_win->R()->refresh(); 503 R()->refresh();
504 } 504 }
505 505
506 // ============================================================================= 506 // =============================================================================
507 // ----------------------------------------------------------------------------- 507 // -----------------------------------------------------------------------------
508 DEFINE_ACTION (SetOverlay, 0) 508 DEFINE_ACTION (SetOverlay, 0)
509 { OverlayDialog dlg; 509 { OverlayDialog dlg;
510 510
511 if (!dlg.exec()) 511 if (!dlg.exec())
512 return; 512 return;
513 513
514 g_win->R()->setupOverlay ((GL::EFixedCamera) dlg.camera(), dlg.fpath(), dlg.ofsx(), 514 R()->setupOverlay ((GL::EFixedCamera) dlg.camera(), dlg.fpath(), dlg.ofsx(),
515 dlg.ofsy(), dlg.lwidth(), dlg.lheight()); 515 dlg.ofsy(), dlg.lwidth(), dlg.lheight());
516 } 516 }
517 517
518 // ============================================================================= 518 // =============================================================================
519 // ----------------------------------------------------------------------------- 519 // -----------------------------------------------------------------------------
520 DEFINE_ACTION (ClearOverlay, 0) 520 DEFINE_ACTION (ClearOverlay, 0)
521 { g_win->R()->clearOverlay(); 521 { R()->clearOverlay();
522 } 522 }
523 523
524 // ============================================================================= 524 // =============================================================================
525 // ----------------------------------------------------------------------------- 525 // -----------------------------------------------------------------------------
526 DEFINE_ACTION (ModeSelect, CTRL (1)) 526 DEFINE_ACTION (ModeSelect, CTRL (1))
527 { g_win->R()->setEditMode (ESelectMode); 527 { R()->setEditMode (ESelectMode);
528 } 528 }
529 529
530 // ============================================================================= 530 // =============================================================================
531 // ----------------------------------------------------------------------------- 531 // -----------------------------------------------------------------------------
532 DEFINE_ACTION (ModeDraw, CTRL (2)) 532 DEFINE_ACTION (ModeDraw, CTRL (2))
533 { g_win->R()->setEditMode (EDrawMode); 533 { R()->setEditMode (EDrawMode);
534 } 534 }
535 535
536 // ============================================================================= 536 // =============================================================================
537 // ----------------------------------------------------------------------------- 537 // -----------------------------------------------------------------------------
538 DEFINE_ACTION (ModeCircle, CTRL (3)) 538 DEFINE_ACTION (ModeCircle, CTRL (3))
539 { g_win->R()->setEditMode (ECircleMode); 539 { R()->setEditMode (ECircleMode);
540 } 540 }
541 541
542 // ============================================================================= 542 // =============================================================================
543 // ----------------------------------------------------------------------------- 543 // -----------------------------------------------------------------------------
544 DEFINE_ACTION (DrawAngles, 0) 544 DEFINE_ACTION (DrawAngles, 0)
545 { gl_drawangles = !gl_drawangles; 545 { gl_drawangles = !gl_drawangles;
546 g_win->R()->refresh(); 546 R()->refresh();
547 } 547 }
548 548
549 // ============================================================================= 549 // =============================================================================
550 // ----------------------------------------------------------------------------- 550 // -----------------------------------------------------------------------------
551 DEFINE_ACTION (SetDrawDepth, 0) 551 DEFINE_ACTION (SetDrawDepth, 0)
552 { if (g_win->R()->camera() == GL::EFreeCamera) 552 { if (R()->camera() == GL::EFreeCamera)
553 return; 553 return;
554 554
555 bool ok; 555 bool ok;
556 double depth = QInputDialog::getDouble (g_win, "Set Draw Depth", 556 double depth = QInputDialog::getDouble (g_win, "Set Draw Depth",
557 fmt ("Depth value for %1 Camera:", g_win->R()->getCameraName()), 557 fmt ("Depth value for %1 Camera:", R()->getCameraName()),
558 g_win->R()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); 558 R()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok);
559 559
560 if (ok) 560 if (ok)
561 g_win->R()->setDepthValue (depth); 561 R()->setDepthValue (depth);
562 } 562 }
563 563
564 #if 0 564 #if 0
565 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery, 565 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery,
566 // but I can't figure how to generate these pictures properly. Multi-threading 566 // but I can't figure how to generate these pictures properly. Multi-threading
614 614
615 // ============================================================================= 615 // =============================================================================
616 // ----------------------------------------------------------------------------- 616 // -----------------------------------------------------------------------------
617 DEFINE_ACTION (BFCView, SHIFT (B)) 617 DEFINE_ACTION (BFCView, SHIFT (B))
618 { gl_colorbfc = !gl_colorbfc; 618 { gl_colorbfc = !gl_colorbfc;
619 g_win->updateActions(); 619 updateActions();
620 g_win->R()->refresh(); 620 R()->refresh();
621 } 621 }
622 622
623 // ============================================================================= 623 // =============================================================================
624 // ----------------------------------------------------------------------------- 624 // -----------------------------------------------------------------------------
625 DEFINE_ACTION (JumpTo, CTRL (G)) 625 DEFINE_ACTION (JumpTo, CTRL (G))
636 if (!ok || (obj = getCurrentDocument()->getObject (idx - 1)) == null) 636 if (!ok || (obj = getCurrentDocument()->getObject (idx - 1)) == null)
637 return; 637 return;
638 638
639 getCurrentDocument()->clearSelection(); 639 getCurrentDocument()->clearSelection();
640 obj->select(); 640 obj->select();
641 g_win->updateSelection(); 641 updateSelection();
642 } 642 }
643 643
644 // ============================================================================= 644 // =============================================================================
645 // ----------------------------------------------------------------------------- 645 // -----------------------------------------------------------------------------
646 DEFINE_ACTION (SubfileSelection, 0) 646 DEFINE_ACTION (SubfileSelection, 0)
687 // a subdirectory named s/. Ensure it exists! 687 // a subdirectory named s/. Ensure it exists!
688 str topdirname = basename (dirname (getCurrentDocument()->getFullPath())); 688 str topdirname = basename (dirname (getCurrentDocument()->getFullPath()));
689 689
690 if (topdirname != "s") 690 if (topdirname != "s")
691 { str desiredPath = subdirname + "/s"; 691 { str desiredPath = subdirname + "/s";
692 str title = ForgeWindow::tr ("Create subfile directory?"); 692 str title = tr ("Create subfile directory?");
693 str text = fmt (ForgeWindow::tr ("The directory <b>%1</b> is suggested for " 693 str text = fmt (tr ("The directory <b>%1</b> is suggested for "
694 "subfiles. This directory does not exist, create it?"), desiredPath); 694 "subfiles. This directory does not exist, create it?"), desiredPath);
695 695
696 if (QDir (desiredPath).exists() || confirm (title, text)) 696 if (QDir (desiredPath).exists() || confirm (title, text))
697 { subdirname = desiredPath; 697 { subdirname = desiredPath;
698 QDir().mkpath (subdirname); 698 QDir().mkpath (subdirname);
767 { LDObject* obj = parseLine (line); 767 { LDObject* obj = parseLine (line);
768 doc->addObject (obj); 768 doc->addObject (obj);
769 } 769 }
770 770
771 // Try save it 771 // Try save it
772 if (g_win->save (doc, true)) 772 if (save (doc, true))
773 { // Remove the selection now 773 { // Remove the selection now
774 for (LDObject* obj : selection()) 774 for (LDObject* obj : selection())
775 obj->deleteSelf(); 775 obj->deleteSelf();
776 776
777 // Compile all objects in the new subfile 777 // Compile all objects in the new subfile
778 for (LDObject* obj : doc->getObjects()) 778 for (LDObject* obj : doc->getObjects())
779 g_win->R()->compileObject (obj); 779 R()->compileObject (obj);
780 780
781 g_loadedFiles << doc; 781 g_loadedFiles << doc;
782 782
783 // Add a reference to the new subfile to where the selection was 783 // Add a reference to the new subfile to where the selection was
784 LDSubfile* ref = new LDSubfile(); 784 LDSubfile* ref = new LDSubfile();
785 ref->setColor (maincolor); 785 ref->setColor (maincolor);
786 ref->setFileInfo (doc); 786 ref->setFileInfo (doc);
787 ref->setPosition (g_origin); 787 ref->setPosition (g_origin);
788 ref->setTransform (g_identity); 788 ref->setTransform (g_identity);
789 getCurrentDocument()->insertObj (refidx, ref); 789 getCurrentDocument()->insertObj (refidx, ref);
790 g_win->R()->compileObject (ref); 790 R()->compileObject (ref);
791 791
792 // Refresh stuff 792 // Refresh stuff
793 g_win->updateDocumentList(); 793 updateDocumentList();
794 g_win->doFullRefresh(); 794 doFullRefresh();
795 } 795 }
796 else 796 else
797 { // Failed to save. 797 { // Failed to save.
798 delete doc; 798 delete doc;
799 } 799 }

mercurial