332 return false; |
332 return false; |
333 |
333 |
334 // Clear the clipboard. However, its contents are dynamically allocated |
334 // Clear the clipboard. However, its contents are dynamically allocated |
335 // clones of LDObjects (cannot use pointers to real objects because the |
335 // clones of LDObjects (cannot use pointers to real objects because the |
336 // cut operation deletes them!), so we have to delete said objects first. |
336 // cut operation deletes them!), so we have to delete said objects first. |
337 for (std::size_t i = 0; i < g_Clipboard.size(); ++i) |
337 FOREACH (LDObject, *, obj, g_Clipboard) |
338 delete g_Clipboard[i]; |
338 delete obj; |
339 |
339 |
340 g_Clipboard.clear (); |
340 g_Clipboard.clear (); |
341 |
341 |
342 for (std::size_t i = 0; i < objs.size(); ++i) |
342 for (std::size_t i = 0; i < objs.size(); ++i) |
343 g_Clipboard.push_back (objs[i]->makeClone ()); |
343 g_Clipboard.push_back (objs[i]->makeClone ()); |
344 |
344 |
345 return true; |
345 return true; |
346 } |
|
347 |
|
348 // ============================================================================= |
|
349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
350 // ============================================================================= |
|
351 void ForgeWindow::deleteSelection () { |
|
352 vector<LDObject*> objs = getSelectedObjects (); |
|
353 |
|
354 // Delete the objects that were being selected |
|
355 for (ulong i = 0; i < (ulong)objs.size(); ++i) { |
|
356 LDObject* obj = objs[i]; |
|
357 |
|
358 g_CurrentFile->forgetObject (obj); |
|
359 delete obj; |
|
360 } |
|
361 } |
346 } |
362 |
347 |
363 // ============================================================================= |
348 // ============================================================================= |
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
365 // ============================================================================= |
350 // ============================================================================= |
383 |
368 |
384 // ============================================================================= |
369 // ============================================================================= |
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
370 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
386 // ============================================================================= |
371 // ============================================================================= |
387 void ForgeWindow::slot_paste () { |
372 void ForgeWindow::slot_paste () { |
388 for (std::size_t i = 0; i < g_Clipboard.size(); ++i) { |
373 FOREACH (LDObject, *, obj, g_Clipboard) |
389 LDObject* copy = g_Clipboard[i]->makeClone (); |
374 g_CurrentFile->addObject (obj->makeClone ()); |
390 g_CurrentFile->addObject (copy); |
|
391 } |
|
392 |
375 |
393 refresh (); |
376 refresh (); |
394 } |
377 } |
395 |
378 |
396 // ============================================================================= |
379 // ============================================================================= |
426 continue; |
409 continue; |
427 |
410 |
428 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
411 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
429 |
412 |
430 // Get the inlined objects. These are clones of the subfile's contents. |
413 // Get the inlined objects. These are clones of the subfile's contents. |
431 vector<LDObject*> objs = ref->inlineContents (bDeep, ref->faMatrix, |
414 vector<LDObject*> objs = ref->inlineContents (bDeep, ref->mMatrix, |
432 ref->vPosition, true); |
415 ref->vPosition, true); |
433 |
416 |
434 // Merge in the inlined objects |
417 // Merge in the inlined objects |
435 FOREACH (LDObject, *, inlineobj, objs) |
418 FOREACH (LDObject, *, inlineobj, objs) |
436 g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx++, inlineobj); |
419 g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx++, inlineobj); |
455 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
438 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
456 // ============================================================================= |
439 // ============================================================================= |
457 void ForgeWindow::slot_splitQuads () { |
440 void ForgeWindow::slot_splitQuads () { |
458 vector<LDObject*> objs = getSelectedObjects (); |
441 vector<LDObject*> objs = getSelectedObjects (); |
459 |
442 |
460 // Delete the objects that were being selected |
443 FOREACH (LDObject, *, obj, objs) { |
461 for (ulong i = 0; i < (ulong)objs.size(); ++i) { |
|
462 LDObject* obj = objs[i]; |
|
463 |
|
464 // Don't even consider non-quads |
|
465 if (obj->getType() != OBJ_Quad) |
444 if (obj->getType() != OBJ_Quad) |
466 continue; |
445 continue; |
467 |
446 |
468 static_cast<LDQuad*> (obj)->splitToTriangles (); |
447 static_cast<LDQuad*> (obj)->splitToTriangles (); |
469 } |
448 } |
492 short dColor; |
471 short dColor; |
493 short dDefault = -1; |
472 short dDefault = -1; |
494 |
473 |
495 std::vector<LDObject*> objs = getSelectedObjects (); |
474 std::vector<LDObject*> objs = getSelectedObjects (); |
496 |
475 |
497 // Try to get a consensus on the color used for use as a default. |
476 // If all selected objects have the same color, said color is our default |
498 for (ulong i = 0; i < objs.size(); ++i) { |
477 // value to the color selection dialog. |
499 LDObject* obj = objs[i]; |
478 FOREACH (LDObject, *, obj, objs) { |
500 |
|
501 if (obj->dColor == -1) |
479 if (obj->dColor == -1) |
502 continue; // doesn't use colors |
480 continue; // doesn't use color |
503 |
481 |
504 if (dDefault != -1 && obj->dColor != dDefault) { |
482 if (dDefault != -1 && obj->dColor != dDefault) { |
505 // No unanimosity in object color, therefore we don't have a |
483 // No consensus in object color, therefore we don't have a |
506 // proper default value to use. |
484 // proper default value to use. |
507 dDefault = -1; |
485 dDefault = -1; |
508 break; |
486 break; |
509 } |
487 } |
510 |
488 |
511 if (dDefault == -1) |
489 if (dDefault == -1) |
512 dDefault = obj->dColor; |
490 dDefault = obj->dColor; |
513 } |
491 } |
514 |
492 |
515 // Show the dialog to the user now and ask him for a color. |
493 // Show the dialog to the user now and ask for a color. |
516 if (ColorSelectDialog::staticDialog (dColor, dDefault, this)) { |
494 if (ColorSelectDialog::staticDialog (dColor, dDefault, this)) { |
517 for (ulong i = 0; i < objs.size(); ++i) { |
495 FOREACH (LDObject, *, obj, objs) |
518 LDObject* obj = objs[i]; |
|
519 if (obj->dColor != -1) |
496 if (obj->dColor != -1) |
520 obj->dColor = dColor; |
497 obj->dColor = dColor; |
521 } |
|
522 |
498 |
523 refresh (); |
499 refresh (); |
524 } |
500 } |
525 } |
501 } |
526 |
502 |
529 // ============================================================================= |
505 // ============================================================================= |
530 void ForgeWindow::slot_makeBorders () { |
506 void ForgeWindow::slot_makeBorders () { |
531 vector<LDObject*> objs = getSelectedObjects (); |
507 vector<LDObject*> objs = getSelectedObjects (); |
532 |
508 |
533 // Delete the objects that were being selected |
509 // Delete the objects that were being selected |
534 for (std::size_t i = 0; i < objs.size(); ++i) { |
510 FOREACH (LDObject, *, obj, objs) { |
535 LDObject* obj = objs[i]; |
|
536 |
|
537 if (obj->getType() != OBJ_Quad && obj->getType() != OBJ_Triangle) |
511 if (obj->getType() != OBJ_Quad && obj->getType() != OBJ_Triangle) |
538 continue; |
512 continue; |
539 |
513 |
540 short dNumLines; |
514 short dNumLines; |
541 LDLine* lines[4]; |
515 LDLine* lines[4]; |
567 } |
541 } |
568 |
542 |
569 // ============================================================================= |
543 // ============================================================================= |
570 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
544 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
571 // ============================================================================= |
545 // ============================================================================= |
|
546 void ForgeWindow::deleteSelection () { |
|
547 vector<LDObject*> objs = getSelectedObjects (); |
|
548 |
|
549 // Delete the objects that were being selected |
|
550 FOREACH (LDObject, *, obj, objs) { |
|
551 g_CurrentFile->forgetObject (obj); |
|
552 delete obj; |
|
553 } |
|
554 } |
|
555 |
|
556 // ============================================================================= |
|
557 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
558 // ============================================================================= |
572 void ForgeWindow::buildObjList () { |
559 void ForgeWindow::buildObjList () { |
573 if (!g_CurrentFile) |
560 if (!g_CurrentFile) |
574 return; |
561 return; |
575 |
562 |
576 QList<QTreeWidgetItem*> qaItems; |
563 QList<QTreeWidgetItem*> qaItems; |
650 zText.format ("%s %s, (", |
637 zText.format ("%s %s, (", |
651 ref->zFileName.chars(), ref->vPosition.getStringRep (true).chars()); |
638 ref->zFileName.chars(), ref->vPosition.getStringRep (true).chars()); |
652 |
639 |
653 for (short i = 0; i < 9; ++i) |
640 for (short i = 0; i < 9; ++i) |
654 zText.appendformat ("%s%s", |
641 zText.appendformat ("%s%s", |
655 ftoa (ref->faMatrix[i]).chars(), |
642 ftoa (ref->mMatrix[i]).chars(), |
656 (i != 8) ? " " : ""); |
643 (i != 8) ? " " : ""); |
657 |
644 |
658 zText += ')'; |
645 zText += ')'; |
659 } |
646 } |
660 break; |
647 break; |