src/actions/MainActions.cc

changeset 690
9e9c52ca955e
parent 644
93dcd1a0e4bd
child 697
2766f7b037ad
equal deleted inserted replaced
689:397870c6ed38 690:9e9c52ca955e
43 extern_cfg (String, ld_defaultuser); 43 extern_cfg (String, ld_defaultuser);
44 extern_cfg (Int, ld_defaultlicense); 44 extern_cfg (Int, ld_defaultlicense);
45 extern_cfg (Bool, gl_drawangles); 45 extern_cfg (Bool, gl_drawangles);
46 46
47 // ============================================================================= 47 // =============================================================================
48 // ----------------------------------------------------------------------------- 48 //
49 DEFINE_ACTION (New, CTRL_SHIFT (N)) 49 DEFINE_ACTION (New, CTRL_SHIFT (N))
50 { 50 {
51 QDialog* dlg = new QDialog (g_win); 51 QDialog* dlg = new QDialog (g_win);
52 Ui::NewPartUI ui; 52 Ui::NewPartUI ui;
53 ui.setupUi (dlg); 53 ui.setupUi (dlg);
54 54
55 QString authortext = ld_defaultname; 55 QString authortext = ld_defaultname;
56 56
57 if (!ld_defaultuser.isEmpty()) 57 if (!ld_defaultuser.isEmpty())
58 authortext.append (fmt (" [%1]", ld_defaultuser)); 58 authortext.append (format (" [%1]", ld_defaultuser));
59 59
60 ui.le_author->setText (authortext); 60 ui.le_author->setText (authortext);
61 61
62 switch (ld_defaultlicense) 62 switch (ld_defaultlicense)
63 { 63 {
73 ui.rb_license_none->setChecked (true); 73 ui.rb_license_none->setChecked (true);
74 break; 74 break;
75 75
76 default: 76 default:
77 QMessageBox::warning (null, "Warning", 77 QMessageBox::warning (null, "Warning",
78 fmt ("Unknown ld_defaultlicense value %1!", ld_defaultlicense)); 78 format ("Unknown ld_defaultlicense value %1!", ld_defaultlicense));
79 break; 79 break;
80 } 80 }
81 81
82 if (dlg->exec() == false) 82 if (dlg->exec() == false)
83 return; 83 return;
84 84
85 newFile(); 85 newFile();
86 86
87 const LDBFC::Type BFCType = 87 const LDBFC::Statement BFCType =
88 ui.rb_bfc_ccw->isChecked() ? LDBFC::CertifyCCW : 88 ui.rb_bfc_ccw->isChecked() ? LDBFC::CertifyCCW :
89 ui.rb_bfc_cw->isChecked() ? LDBFC::CertifyCW : LDBFC::NoCertify; 89 ui.rb_bfc_cw->isChecked() ? LDBFC::CertifyCW : LDBFC::NoCertify;
90 90
91 const QString license = 91 const QString license =
92 ui.rb_license_ca->isChecked() ? CALicense : 92 ui.rb_license_ca->isChecked() ? g_CALicense :
93 ui.rb_license_nonca->isChecked() ? NonCALicense : ""; 93 ui.rb_license_nonca->isChecked() ? g_nonCALicense : "";
94 94
95 getCurrentDocument()->addObjects ( 95 getCurrentDocument()->addObjects (
96 { 96 {
97 new LDComment (ui.le_title->text()), 97 new LDComment (ui.le_title->text()),
98 new LDComment ("Name: <untitled>.dat"), 98 new LDComment ("Name: <untitled>.dat"),
99 new LDComment (fmt ("Author: %1", ui.le_author->text())), 99 new LDComment (format ("Author: %1", ui.le_author->text())),
100 new LDComment (fmt ("!LDRAW_ORG Unofficial_Part")), 100 new LDComment (format ("!LDRAW_ORG Unofficial_Part")),
101 (license != "" ? new LDComment (license) : null), 101 (license != "" ? new LDComment (license) : null),
102 new LDEmpty, 102 new LDEmpty,
103 new LDBFC (BFCType), 103 new LDBFC (BFCType),
104 new LDEmpty, 104 new LDEmpty,
105 }); 105 });
106 106
107 doFullRefresh(); 107 doFullRefresh();
108 } 108 }
109 109
110 // ============================================================================= 110 // =============================================================================
111 // ----------------------------------------------------------------------------- 111 //
112 DEFINE_ACTION (NewFile, CTRL (N)) 112 DEFINE_ACTION (NewFile, CTRL (N))
113 { 113 {
114 newFile(); 114 newFile();
115 } 115 }
116 116
117 // ============================================================================= 117 // =============================================================================
118 // ----------------------------------------------------------------------------- 118 //
119 DEFINE_ACTION (Open, CTRL (O)) 119 DEFINE_ACTION (Open, CTRL (O))
120 { 120 {
121 QString name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)"); 121 QString name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)");
122 122
123 if (name.length() == 0) 123 if (name.length() == 0)
125 125
126 openMainFile (name); 126 openMainFile (name);
127 } 127 }
128 128
129 // ============================================================================= 129 // =============================================================================
130 // ----------------------------------------------------------------------------- 130 //
131 DEFINE_ACTION (Save, CTRL (S)) 131 DEFINE_ACTION (Save, CTRL (S))
132 { 132 {
133 save (getCurrentDocument(), false); 133 save (getCurrentDocument(), false);
134 } 134 }
135 135
136 // ============================================================================= 136 // =============================================================================
137 // ----------------------------------------------------------------------------- 137 //
138 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) 138 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S))
139 { 139 {
140 save (getCurrentDocument(), true); 140 save (getCurrentDocument(), true);
141 } 141 }
142 142
143 // ============================================================================= 143 // =============================================================================
144 // ----------------------------------------------------------------------------- 144 //
145 DEFINE_ACTION (SaveAll, CTRL (L)) 145 DEFINE_ACTION (SaveAll, CTRL (L))
146 { 146 {
147 for (LDDocument* file : g_loadedFiles) 147 for (LDDocument* file : g_loadedFiles)
148 { 148 {
149 if (file->isImplicit()) 149 if (file->isImplicit())
152 save (file, false); 152 save (file, false);
153 } 153 }
154 } 154 }
155 155
156 // ============================================================================= 156 // =============================================================================
157 // ----------------------------------------------------------------------------- 157 //
158 DEFINE_ACTION (Close, CTRL (W)) 158 DEFINE_ACTION (Close, CTRL (W))
159 { 159 {
160 if (!getCurrentDocument()->isSafeToClose()) 160 if (!getCurrentDocument()->isSafeToClose())
161 return; 161 return;
162 162
163 delete getCurrentDocument(); 163 delete getCurrentDocument();
164 } 164 }
165 165
166 // ============================================================================= 166 // =============================================================================
167 // ----------------------------------------------------------------------------- 167 //
168 DEFINE_ACTION (CloseAll, 0) 168 DEFINE_ACTION (CloseAll, 0)
169 { 169 {
170 if (!safeToCloseAll()) 170 if (!safeToCloseAll())
171 return; 171 return;
172 172
173 closeAll(); 173 closeAll();
174 } 174 }
175 175
176 // ============================================================================= 176 // =============================================================================
177 // ----------------------------------------------------------------------------- 177 //
178 DEFINE_ACTION (Settings, 0) 178 DEFINE_ACTION (Settings, 0)
179 { 179 {
180 (new ConfigDialog)->exec(); 180 (new ConfigDialog)->exec();
181 } 181 }
182 182
183 // ============================================================================= 183 // =============================================================================
184 // ----------------------------------------------------------------------------- 184 //
185 DEFINE_ACTION (SetLDrawPath, 0) 185 DEFINE_ACTION (SetLDrawPath, 0)
186 { 186 {
187 (new LDrawPathDialog (true))->exec(); 187 (new LDrawPathDialog (true))->exec();
188 } 188 }
189 189
190 // ============================================================================= 190 // =============================================================================
191 // ----------------------------------------------------------------------------- 191 //
192 DEFINE_ACTION (Exit, CTRL (Q)) 192 DEFINE_ACTION (Exit, CTRL (Q))
193 { 193 {
194 exit (0); 194 exit (0);
195 } 195 }
196 196
197 // ============================================================================= 197 // =============================================================================
198 // ----------------------------------------------------------------------------- 198 //
199 DEFINE_ACTION (NewSubfile, 0) 199 DEFINE_ACTION (NewSubfile, 0)
200 { 200 {
201 AddObjectDialog::staticDialog (LDObject::ESubfile, null); 201 AddObjectDialog::staticDialog (LDObject::ESubfile, null);
202 } 202 }
203 203
204 // ============================================================================= 204 // =============================================================================
205 // ----------------------------------------------------------------------------- 205 //
206 DEFINE_ACTION (NewLine, 0) 206 DEFINE_ACTION (NewLine, 0)
207 { 207 {
208 AddObjectDialog::staticDialog (LDObject::ELine, null); 208 AddObjectDialog::staticDialog (LDObject::ELine, null);
209 } 209 }
210 210
211 // ============================================================================= 211 // =============================================================================
212 // ----------------------------------------------------------------------------- 212 //
213 DEFINE_ACTION (NewTriangle, 0) 213 DEFINE_ACTION (NewTriangle, 0)
214 { 214 {
215 AddObjectDialog::staticDialog (LDObject::ETriangle, null); 215 AddObjectDialog::staticDialog (LDObject::ETriangle, null);
216 } 216 }
217 217
218 // ============================================================================= 218 // =============================================================================
219 // ----------------------------------------------------------------------------- 219 //
220 DEFINE_ACTION (NewQuad, 0) 220 DEFINE_ACTION (NewQuad, 0)
221 { 221 {
222 AddObjectDialog::staticDialog (LDObject::EQuad, null); 222 AddObjectDialog::staticDialog (LDObject::EQuad, null);
223 } 223 }
224 224
225 // ============================================================================= 225 // =============================================================================
226 // ----------------------------------------------------------------------------- 226 //
227 DEFINE_ACTION (NewCLine, 0) 227 DEFINE_ACTION (NewCLine, 0)
228 { 228 {
229 AddObjectDialog::staticDialog (LDObject::ECondLine, null); 229 AddObjectDialog::staticDialog (LDObject::ECondLine, null);
230 } 230 }
231 231
232 // ============================================================================= 232 // =============================================================================
233 // ----------------------------------------------------------------------------- 233 //
234 DEFINE_ACTION (NewComment, 0) 234 DEFINE_ACTION (NewComment, 0)
235 { 235 {
236 AddObjectDialog::staticDialog (LDObject::EComment, null); 236 AddObjectDialog::staticDialog (LDObject::EComment, null);
237 } 237 }
238 238
239 // ============================================================================= 239 // =============================================================================
240 // ----------------------------------------------------------------------------- 240 //
241 DEFINE_ACTION (NewBFC, 0) 241 DEFINE_ACTION (NewBFC, 0)
242 { 242 {
243 AddObjectDialog::staticDialog (LDObject::EBFC, null); 243 AddObjectDialog::staticDialog (LDObject::EBFC, null);
244 } 244 }
245 245
246 // ============================================================================= 246 // =============================================================================
247 // ----------------------------------------------------------------------------- 247 //
248 DEFINE_ACTION (NewVertex, 0) 248 DEFINE_ACTION (NewVertex, 0)
249 { 249 {
250 AddObjectDialog::staticDialog (LDObject::EVertex, null); 250 AddObjectDialog::staticDialog (LDObject::EVertex, null);
251 } 251 }
252 252
253 // ============================================================================= 253 // =============================================================================
254 // ----------------------------------------------------------------------------- 254 //
255 DEFINE_ACTION (Edit, 0) 255 DEFINE_ACTION (Edit, 0)
256 { 256 {
257 if (selection().size() != 1) 257 if (selection().size() != 1)
258 return; 258 return;
259 259
260 LDObject* obj = selection() [0]; 260 LDObject* obj = selection() [0];
261 AddObjectDialog::staticDialog (obj->getType(), obj); 261 AddObjectDialog::staticDialog (obj->type(), obj);
262 } 262 }
263 263
264 // ============================================================================= 264 // =============================================================================
265 // ----------------------------------------------------------------------------- 265 //
266 DEFINE_ACTION (Help, KEY (F1)) 266 DEFINE_ACTION (Help, KEY (F1))
267 { 267 {
268 } 268 }
269 269
270 // ============================================================================= 270 // =============================================================================
271 // ----------------------------------------------------------------------------- 271 //
272 DEFINE_ACTION (About, 0) 272 DEFINE_ACTION (About, 0)
273 { 273 {
274 AboutDialog().exec(); 274 AboutDialog().exec();
275 } 275 }
276 276
277 // ============================================================================= 277 // =============================================================================
278 // ----------------------------------------------------------------------------- 278 //
279 DEFINE_ACTION (AboutQt, 0) 279 DEFINE_ACTION (AboutQt, 0)
280 { 280 {
281 QMessageBox::aboutQt (g_win); 281 QMessageBox::aboutQt (g_win);
282 } 282 }
283 283
284 // ============================================================================= 284 // =============================================================================
285 // ----------------------------------------------------------------------------- 285 //
286 DEFINE_ACTION (SelectAll, CTRL (A)) 286 DEFINE_ACTION (SelectAll, CTRL (A))
287 { 287 {
288 for (LDObject* obj : getCurrentDocument()->getObjects()) 288 for (LDObject* obj : getCurrentDocument()->objects())
289 obj->select(); 289 obj->select();
290 290
291 updateSelection(); 291 updateSelection();
292 } 292 }
293 293
294 // ============================================================================= 294 // =============================================================================
295 // ----------------------------------------------------------------------------- 295 //
296 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) 296 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A))
297 { 297 {
298 int colnum = getSelectedColor(); 298 int colnum = getSelectedColor();
299 299
300 if (colnum == -1) 300 if (colnum == -1)
301 return; // no consensus on color 301 return; // no consensus on color
302 302
303 getCurrentDocument()->clearSelection(); 303 getCurrentDocument()->clearSelection();
304 304
305 for (LDObject* obj : getCurrentDocument()->getObjects()) 305 for (LDObject* obj : getCurrentDocument()->objects())
306 if (obj->getColor() == colnum) 306 if (obj->color() == colnum)
307 obj->select(); 307 obj->select();
308 308
309 updateSelection(); 309 updateSelection();
310 } 310 }
311 311
312 // ============================================================================= 312 // =============================================================================
313 // ----------------------------------------------------------------------------- 313 //
314 DEFINE_ACTION (SelectByType, 0) 314 DEFINE_ACTION (SelectByType, 0)
315 { 315 {
316 if (selection().isEmpty()) 316 if (selection().isEmpty())
317 return; 317 return;
318 318
325 // be uniform. 325 // be uniform.
326 QString refName; 326 QString refName;
327 327
328 if (type == LDObject::ESubfile) 328 if (type == LDObject::ESubfile)
329 { 329 {
330 refName = static_cast<LDSubfile*> (selection()[0])->getFileInfo()->getName(); 330 refName = static_cast<LDSubfile*> (selection()[0])->fileInfo()->name();
331 331
332 for (LDObject* obj : selection()) 332 for (LDObject* obj : selection())
333 if (static_cast<LDSubfile*> (obj)->getFileInfo()->getName() != refName) 333 if (static_cast<LDSubfile*> (obj)->fileInfo()->name() != refName)
334 return; 334 return;
335 } 335 }
336 336
337 getCurrentDocument()->clearSelection(); 337 getCurrentDocument()->clearSelection();
338 338
339 for (LDObject* obj : getCurrentDocument()->getObjects()) 339 for (LDObject* obj : getCurrentDocument()->objects())
340 { 340 {
341 if (obj->getType() != type) 341 if (obj->type() != type)
342 continue; 342 continue;
343 343
344 if (type == LDObject::ESubfile && static_cast<LDSubfile*> (obj)->getFileInfo()->getName() != refName) 344 if (type == LDObject::ESubfile && static_cast<LDSubfile*> (obj)->fileInfo()->name() != refName)
345 continue; 345 continue;
346 346
347 obj->select(); 347 obj->select();
348 } 348 }
349 349
350 updateSelection(); 350 updateSelection();
351 } 351 }
352 352
353 // ============================================================================= 353 // =============================================================================
354 // ----------------------------------------------------------------------------- 354 //
355 DEFINE_ACTION (GridCoarse, 0) 355 DEFINE_ACTION (GridCoarse, 0)
356 { 356 {
357 grid = Grid::Coarse; 357 grid = Grid::Coarse;
358 updateGridToolBar(); 358 updateGridToolBar();
359 } 359 }
369 grid = Grid::Fine; 369 grid = Grid::Fine;
370 updateGridToolBar(); 370 updateGridToolBar();
371 } 371 }
372 372
373 // ============================================================================= 373 // =============================================================================
374 // ----------------------------------------------------------------------------- 374 //
375 DEFINE_ACTION (ResetView, CTRL (0)) 375 DEFINE_ACTION (ResetView, CTRL (0))
376 { 376 {
377 R()->resetAngles(); 377 R()->resetAngles();
378 R()->update(); 378 R()->update();
379 } 379 }
380 380
381 // ============================================================================= 381 // =============================================================================
382 // ----------------------------------------------------------------------------- 382 //
383 DEFINE_ACTION (InsertFrom, 0) 383 DEFINE_ACTION (InsertFrom, 0)
384 { 384 {
385 QString fname = QFileDialog::getOpenFileName(); 385 QString fname = QFileDialog::getOpenFileName();
386 int idx = getInsertionPoint(); 386 int idx = getInsertionPoint();
387 387
390 390
391 QFile f (fname); 391 QFile f (fname);
392 392
393 if (!f.open (QIODevice::ReadOnly)) 393 if (!f.open (QIODevice::ReadOnly))
394 { 394 {
395 critical (fmt ("Couldn't open %1 (%2)", fname, f.errorString())); 395 critical (format ("Couldn't open %1 (%2)", fname, f.errorString()));
396 return; 396 return;
397 } 397 }
398 398
399 LDObjectList objs = loadFileContents (&f, null); 399 LDObjectList objs = loadFileContents (&f, null);
400 400
412 refresh(); 412 refresh();
413 scrollToSelection(); 413 scrollToSelection();
414 } 414 }
415 415
416 // ============================================================================= 416 // =============================================================================
417 // ----------------------------------------------------------------------------- 417 //
418 DEFINE_ACTION (ExportTo, 0) 418 DEFINE_ACTION (ExportTo, 0)
419 { 419 {
420 if (selection().isEmpty()) 420 if (selection().isEmpty())
421 return; 421 return;
422 422
427 427
428 QFile file (fname); 428 QFile file (fname);
429 429
430 if (!file.open (QIODevice::WriteOnly | QIODevice::Text)) 430 if (!file.open (QIODevice::WriteOnly | QIODevice::Text))
431 { 431 {
432 critical (fmt ("Unable to open %1 for writing (%2)", fname, file.errorString())); 432 critical (format ("Unable to open %1 for writing (%2)", fname, file.errorString()));
433 return; 433 return;
434 } 434 }
435 435
436 for (LDObject* obj : selection()) 436 for (LDObject* obj : selection())
437 { 437 {
438 QString contents = obj->raw(); 438 QString contents = obj->asText();
439 QByteArray data = contents.toUtf8(); 439 QByteArray data = contents.toUtf8();
440 file.write (data, data.size()); 440 file.write (data, data.size());
441 file.write ("\r\n", 2); 441 file.write ("\r\n", 2);
442 } 442 }
443 } 443 }
444 444
445 // ============================================================================= 445 // =============================================================================
446 // ----------------------------------------------------------------------------- 446 //
447 DEFINE_ACTION (InsertRaw, 0) 447 DEFINE_ACTION (InsertRaw, 0)
448 { 448 {
449 int idx = getInsertionPoint(); 449 int idx = getInsertionPoint();
450 450
451 QDialog* const dlg = new QDialog; 451 QDialog* const dlg = new QDialog;
478 refresh(); 478 refresh();
479 scrollToSelection(); 479 scrollToSelection();
480 } 480 }
481 481
482 // ============================================================================= 482 // =============================================================================
483 // ----------------------------------------------------------------------------- 483 //
484 DEFINE_ACTION (Screenshot, 0) 484 DEFINE_ACTION (Screenshot, 0)
485 { 485 {
486 setlocale (LC_ALL, "C"); 486 setlocale (LC_ALL, "C");
487 487
488 int w, h; 488 int w, h;
489 uchar* imgdata = R()->getScreencap (w, h); 489 uchar* imgdata = R()->getScreencap (w, h);
490 QImage img = imageFromScreencap (imgdata, w, h); 490 QImage img = imageFromScreencap (imgdata, w, h);
491 491
492 QString root = basename (getCurrentDocument()->getName()); 492 QString root = basename (getCurrentDocument()->name());
493 493
494 if (root.right (4) == ".dat") 494 if (root.right (4) == ".dat")
495 root.chop (4); 495 root.chop (4);
496 496
497 QString defaultname = (root.length() > 0) ? fmt ("%1.png", root) : ""; 497 QString defaultname = (root.length() > 0) ? format ("%1.png", root) : "";
498 QString fname = QFileDialog::getSaveFileName (g_win, "Save Screencap", defaultname, 498 QString fname = QFileDialog::getSaveFileName (g_win, "Save Screencap", defaultname,
499 "PNG images (*.png);;JPG images (*.jpg);;BMP images (*.bmp);;All Files (*.*)"); 499 "PNG images (*.png);;JPG images (*.jpg);;BMP images (*.bmp);;All Files (*.*)");
500 500
501 if (fname.length() > 0 && !img.save (fname)) 501 if (fname.length() > 0 && !img.save (fname))
502 critical (fmt ("Couldn't open %1 for writing to save screencap: %2", fname, strerror (errno))); 502 critical (format ("Couldn't open %1 for writing to save screencap: %2", fname, strerror (errno)));
503 503
504 delete[] imgdata; 504 delete[] imgdata;
505 } 505 }
506 506
507 // ============================================================================= 507 // =============================================================================
508 // ----------------------------------------------------------------------------- 508 //
509 extern_cfg (Bool, gl_axes); 509 extern_cfg (Bool, gl_axes);
510 DEFINE_ACTION (Axes, 0) 510 DEFINE_ACTION (Axes, 0)
511 { 511 {
512 gl_axes = !gl_axes; 512 gl_axes = !gl_axes;
513 updateActions(); 513 updateActions();
514 R()->update(); 514 R()->update();
515 } 515 }
516 516
517 // ============================================================================= 517 // =============================================================================
518 // ----------------------------------------------------------------------------- 518 //
519 DEFINE_ACTION (VisibilityToggle, 0) 519 DEFINE_ACTION (VisibilityToggle, 0)
520 { 520 {
521 for (LDObject* obj : selection()) 521 for (LDObject* obj : selection())
522 obj->toggleHidden(); 522 obj->setHidden (!obj->isHidden());
523 523
524 refresh(); 524 refresh();
525 } 525 }
526 526
527 // ============================================================================= 527 // =============================================================================
528 // ----------------------------------------------------------------------------- 528 //
529 DEFINE_ACTION (VisibilityHide, 0) 529 DEFINE_ACTION (VisibilityHide, 0)
530 { 530 {
531 for (LDObject* obj : selection()) 531 for (LDObject* obj : selection())
532 obj->setHidden (true); 532 obj->setHidden (true);
533 533
534 refresh(); 534 refresh();
535 } 535 }
536 536
537 // ============================================================================= 537 // =============================================================================
538 // ----------------------------------------------------------------------------- 538 //
539 DEFINE_ACTION (VisibilityReveal, 0) 539 DEFINE_ACTION (VisibilityReveal, 0)
540 { 540 {
541 for (LDObject* obj : selection()) 541 for (LDObject* obj : selection())
542 obj->setHidden (false); 542 obj->setHidden (false);
543 refresh(); 543 refresh();
544 } 544 }
545 545
546 // ============================================================================= 546 // =============================================================================
547 // ----------------------------------------------------------------------------- 547 //
548 DEFINE_ACTION (Wireframe, 0) 548 DEFINE_ACTION (Wireframe, 0)
549 { 549 {
550 gl_wireframe = !gl_wireframe; 550 gl_wireframe = !gl_wireframe;
551 R()->refresh(); 551 R()->refresh();
552 } 552 }
553 553
554 // ============================================================================= 554 // =============================================================================
555 // ----------------------------------------------------------------------------- 555 //
556 DEFINE_ACTION (SetOverlay, 0) 556 DEFINE_ACTION (SetOverlay, 0)
557 { 557 {
558 OverlayDialog dlg; 558 OverlayDialog dlg;
559 559
560 if (!dlg.exec()) 560 if (!dlg.exec())
563 R()->setupOverlay ((GL::EFixedCamera) dlg.camera(), dlg.fpath(), dlg.ofsx(), 563 R()->setupOverlay ((GL::EFixedCamera) dlg.camera(), dlg.fpath(), dlg.ofsx(),
564 dlg.ofsy(), dlg.lwidth(), dlg.lheight()); 564 dlg.ofsy(), dlg.lwidth(), dlg.lheight());
565 } 565 }
566 566
567 // ============================================================================= 567 // =============================================================================
568 // ----------------------------------------------------------------------------- 568 //
569 DEFINE_ACTION (ClearOverlay, 0) 569 DEFINE_ACTION (ClearOverlay, 0)
570 { 570 {
571 R()->clearOverlay(); 571 R()->clearOverlay();
572 } 572 }
573 573
574 // ============================================================================= 574 // =============================================================================
575 // ----------------------------------------------------------------------------- 575 //
576 DEFINE_ACTION (ModeSelect, CTRL (1)) 576 DEFINE_ACTION (ModeSelect, CTRL (1))
577 { 577 {
578 R()->setEditMode (ESelectMode); 578 R()->setEditMode (ESelectMode);
579 } 579 }
580 580
581 // ============================================================================= 581 // =============================================================================
582 // ----------------------------------------------------------------------------- 582 //
583 DEFINE_ACTION (ModeDraw, CTRL (2)) 583 DEFINE_ACTION (ModeDraw, CTRL (2))
584 { 584 {
585 R()->setEditMode (EDrawMode); 585 R()->setEditMode (EDrawMode);
586 } 586 }
587 587
588 // ============================================================================= 588 // =============================================================================
589 // ----------------------------------------------------------------------------- 589 //
590 DEFINE_ACTION (ModeCircle, CTRL (3)) 590 DEFINE_ACTION (ModeCircle, CTRL (3))
591 { 591 {
592 R()->setEditMode (ECircleMode); 592 R()->setEditMode (ECircleMode);
593 } 593 }
594 594
595 // ============================================================================= 595 // =============================================================================
596 // ----------------------------------------------------------------------------- 596 //
597 DEFINE_ACTION (DrawAngles, 0) 597 DEFINE_ACTION (DrawAngles, 0)
598 { 598 {
599 gl_drawangles = !gl_drawangles; 599 gl_drawangles = !gl_drawangles;
600 R()->refresh(); 600 R()->refresh();
601 } 601 }
602 602
603 // ============================================================================= 603 // =============================================================================
604 // ----------------------------------------------------------------------------- 604 //
605 DEFINE_ACTION (SetDrawDepth, 0) 605 DEFINE_ACTION (SetDrawDepth, 0)
606 { 606 {
607 if (R()->camera() == GL::EFreeCamera) 607 if (R()->camera() == GL::EFreeCamera)
608 return; 608 return;
609 609
610 bool ok; 610 bool ok;
611 double depth = QInputDialog::getDouble (g_win, "Set Draw Depth", 611 double depth = QInputDialog::getDouble (g_win, "Set Draw Depth",
612 fmt ("Depth value for %1 Camera:", R()->getCameraName()), 612 format ("Depth value for %1 Camera:", R()->getCameraName()),
613 R()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); 613 R()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok);
614 614
615 if (ok) 615 if (ok)
616 R()->setDepthValue (depth); 616 R()->setDepthValue (depth);
617 } 617 }
664 rend->deleteLater(); 664 rend->deleteLater();
665 } 665 }
666 #endif 666 #endif
667 667
668 // ============================================================================= 668 // =============================================================================
669 // ----------------------------------------------------------------------------- 669 //
670 DEFINE_ACTION (ScanPrimitives, 0) 670 DEFINE_ACTION (ScanPrimitives, 0)
671 { 671 {
672 PrimitiveScanner::start(); 672 PrimitiveScanner::start();
673 } 673 }
674 674
675 // ============================================================================= 675 // =============================================================================
676 // ----------------------------------------------------------------------------- 676 //
677 DEFINE_ACTION (BFCView, SHIFT (B)) 677 DEFINE_ACTION (BFCView, SHIFT (B))
678 { 678 {
679 gl_colorbfc = !gl_colorbfc; 679 gl_colorbfc = !gl_colorbfc;
680 updateActions(); 680 updateActions();
681 R()->refresh(); 681 R()->refresh();
682 } 682 }
683 683
684 // ============================================================================= 684 // =============================================================================
685 // ----------------------------------------------------------------------------- 685 //
686 DEFINE_ACTION (JumpTo, CTRL (G)) 686 DEFINE_ACTION (JumpTo, CTRL (G))
687 { 687 {
688 bool ok; 688 bool ok;
689 int defval = 0; 689 int defval = 0;
690 LDObject* obj; 690 LDObject* obj;
691 691
692 if (selection().size() == 1) 692 if (selection().size() == 1)
693 defval = selection()[0]->getIndex(); 693 defval = selection()[0]->lineNumber();
694 694
695 int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval, 695 int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval,
696 1, getCurrentDocument()->getObjectCount(), 1, &ok); 696 1, getCurrentDocument()->getObjectCount(), 1, &ok);
697 697
698 if (!ok || (obj = getCurrentDocument()->getObject (idx - 1)) == null) 698 if (!ok || (obj = getCurrentDocument()->getObject (idx - 1)) == null)
702 obj->select(); 702 obj->select();
703 updateSelection(); 703 updateSelection();
704 } 704 }
705 705
706 // ============================================================================= 706 // =============================================================================
707 // ----------------------------------------------------------------------------- 707 //
708 DEFINE_ACTION (SubfileSelection, 0) 708 DEFINE_ACTION (SubfileSelection, 0)
709 { 709 {
710 if (selection().size() == 0) 710 if (selection().size() == 0)
711 return; 711 return;
712 712
713 QString parentpath = getCurrentDocument()->getFullPath(); 713 QString parentpath = getCurrentDocument()->fullPath();
714 714
715 // BFC type of the new subfile - it shall inherit the BFC type of the parent document 715 // BFC type of the new subfile - it shall inherit the BFC type of the parent document
716 LDBFC::Type bfctype = LDBFC::NoCertify; 716 LDBFC::Statement bfctype = LDBFC::NoCertify;
717 717
718 // Dirname of the new subfile 718 // Dirname of the new subfile
719 QString subdirname = dirname (parentpath); 719 QString subdirname = dirname (parentpath);
720 720
721 // Title of the new subfile 721 // Title of the new subfile
732 732
733 // Full path of the subfile to be 733 // Full path of the subfile to be
734 QString fullsubname; 734 QString fullsubname;
735 735
736 // Where to insert the subfile reference? 736 // Where to insert the subfile reference?
737 int refidx = selection()[0]->getIndex(); 737 int refidx = selection()[0]->lineNumber();
738 738
739 // Determine title of subfile 739 // Determine title of subfile
740 if (titleobj != null) 740 if (titleobj != null)
741 subtitle = "~" + titleobj->text; 741 subtitle = "~" + titleobj->text();
742 else 742 else
743 subtitle = "~subfile"; 743 subtitle = "~subfile";
744 744
745 // Remove duplicate tildes 745 // Remove duplicate tildes
746 while (subtitle[0] == '~' && subtitle[1] == '~') 746 while (subtitle[0] == '~' && subtitle[1] == '~')
747 subtitle.remove (0, 1); 747 subtitle.remove (0, 1);
748 748
749 // If this the parent document isn't already in s/, we need to stuff it into 749 // If this the parent document isn't already in s/, we need to stuff it into
750 // a subdirectory named s/. Ensure it exists! 750 // a subdirectory named s/. Ensure it exists!
751 QString topdirname = basename (dirname (getCurrentDocument()->getFullPath())); 751 QString topdirname = basename (dirname (getCurrentDocument()->fullPath()));
752 752
753 if (topdirname != "s") 753 if (topdirname != "s")
754 { 754 {
755 QString desiredPath = subdirname + "/s"; 755 QString desiredPath = subdirname + "/s";
756 QString title = tr ("Create subfile directory?"); 756 QString title = tr ("Create subfile directory?");
757 QString text = fmt (tr ("The directory <b>%1</b> is suggested for " 757 QString text = format (tr ("The directory <b>%1</b> is suggested for "
758 "subfiles. This directory does not exist, create it?"), desiredPath); 758 "subfiles. This directory does not exist, create it?"), desiredPath);
759 759
760 if (QDir (desiredPath).exists() || confirm (title, text)) 760 if (QDir (desiredPath).exists() || confirm (title, text))
761 { 761 {
762 subdirname = desiredPath; 762 subdirname = desiredPath;
793 } while (findDocument ("s\\" + basename (fullsubname)) != null || QFile (fullsubname).exists()); 793 } while (findDocument ("s\\" + basename (fullsubname)) != null || QFile (fullsubname).exists());
794 } 794 }
795 795
796 // Determine the BFC winding type used in the main document - it is to 796 // Determine the BFC winding type used in the main document - it is to
797 // be carried over to the subfile. 797 // be carried over to the subfile.
798 for (LDObject* obj : getCurrentDocument()->getObjects()) 798 for (LDObject* obj : getCurrentDocument()->objects())
799 { 799 {
800 LDBFC* bfc = dynamic_cast<LDBFC*> (obj); 800 LDBFC* bfc = dynamic_cast<LDBFC*> (obj);
801 801
802 if (!bfc) 802 if (!bfc)
803 continue; 803 continue;
804 804
805 LDBFC::Type a = bfc->type; 805 LDBFC::Statement a = bfc->statement();
806 806
807 if (a == LDBFC::CertifyCCW || a == LDBFC::CertifyCW || a == LDBFC::NoCertify) 807 if (a == LDBFC::CertifyCCW || a == LDBFC::CertifyCW || a == LDBFC::NoCertify)
808 { 808 {
809 bfctype = a; 809 bfctype = a;
810 break; 810 break;
811 } 811 }
812 } 812 }
813 813
814 // Get the body of the document in LDraw code 814 // Get the body of the document in LDraw code
815 for (LDObject* obj : selection()) 815 for (LDObject* obj : selection())
816 code << obj->raw(); 816 code << obj->asText();
817 817
818 // Create the new subfile document 818 // Create the new subfile document
819 LDDocument* doc = new LDDocument; 819 LDDocument* doc = new LDDocument;
820 doc->setImplicit (false); 820 doc->setImplicit (false);
821 doc->setFullPath (fullsubname); 821 doc->setFullPath (fullsubname);
822 doc->setName (LDDocument::shortenName (fullsubname)); 822 doc->setName (LDDocument::shortenName (fullsubname));
823 doc->addObjects ( 823 doc->addObjects (
824 { 824 {
825 new LDComment (subtitle), 825 new LDComment (subtitle),
826 new LDComment ("Name: "), 826 new LDComment ("Name: "),
827 new LDComment (fmt ("Author: %1 [%2]", ld_defaultname, ld_defaultuser)), 827 new LDComment (format ("Author: %1 [%2]", ld_defaultname, ld_defaultuser)),
828 new LDComment (fmt ("!LDRAW_ORG Unofficial_Subpart")), 828 new LDComment (format ("!LDRAW_ORG Unofficial_Subpart")),
829 (license != "" ? new LDComment (license) : null), 829 (license != "" ? new LDComment (license) : null),
830 new LDEmpty, 830 new LDEmpty,
831 new LDBFC (bfctype), 831 new LDBFC (bfctype),
832 new LDEmpty, 832 new LDEmpty,
833 }); 833 });
842 // Try save it 842 // Try save it
843 if (save (doc, true)) 843 if (save (doc, true))
844 { 844 {
845 // Remove the selection now 845 // Remove the selection now
846 for (LDObject* obj : selection()) 846 for (LDObject* obj : selection())
847 obj->deleteSelf(); 847 obj->destroy();
848 848
849 // Compile all objects in the new subfile 849 // Compile all objects in the new subfile
850 for (LDObject* obj : doc->getObjects()) 850 for (LDObject* obj : doc->objects())
851 R()->compileObject (obj); 851 R()->compileObject (obj);
852 852
853 g_loadedFiles << doc; 853 g_loadedFiles << doc;
854 854
855 // Add a reference to the new subfile to where the selection was 855 // Add a reference to the new subfile to where the selection was

mercurial