src/ldtypes.cpp

changeset 312
97620579d86c
parent 311
c6e38e5e4f33
child 316
b4fefda58f43
equal deleted inserted replaced
311:c6e38e5e4f33 312:97620579d86c
24 #include "history.h" 24 #include "history.h"
25 #include "gldraw.h" 25 #include "gldraw.h"
26 26
27 char const* g_saObjTypeNames[] = { 27 char const* g_saObjTypeNames[] = {
28 "subfile", 28 "subfile",
29 "radial",
30 "quadrilateral", 29 "quadrilateral",
31 "triangle", 30 "triangle",
32 "line", 31 "line",
33 "condline", 32 "condline",
34 "vertex", 33 "vertex",
40 }; 39 };
41 40
42 // Should probably get rid of this array sometime 41 // Should probably get rid of this array sometime
43 char const* g_saObjTypeIcons[] = { 42 char const* g_saObjTypeIcons[] = {
44 "subfile", 43 "subfile",
45 "radial",
46 "quad", 44 "quad",
47 "triangle", 45 "triangle",
48 "line", 46 "line",
49 "condline", 47 "condline",
50 "vertex", 48 "vertex",
475 473
476 void LDSubfile::move (vertex vect) { 474 void LDSubfile::move (vertex vect) {
477 setPosition (position () + vect); 475 setPosition (position () + vect);
478 } 476 }
479 477
480 void LDRadial::move (vertex vect) {
481 setPosition (position () + vect);
482 }
483
484 void LDLine::move (vertex vect) { 478 void LDLine::move (vertex vect) {
485 for (short i = 0; i < 2; ++i) 479 for (short i = 0; i < 2; ++i)
486 setVertex (i, getVertex (i) + vect); 480 setVertex (i, getVertex (i) + vect);
487 } 481 }
488 482
497 } 491 }
498 492
499 void LDCondLine::move (vertex vect) { 493 void LDCondLine::move (vertex vect) {
500 for (short i = 0; i < 4; ++i) 494 for (short i = 0; i < 4; ++i)
501 setVertex (i, getVertex (i) + vect); 495 setVertex (i, getVertex (i) + vect);
502 }
503
504 // =============================================================================
505 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
506 // =============================================================================
507 static char const* g_saRadialTypeNames[] = {
508 "Circle",
509 "Cylinder",
510 "Disc",
511 "Disc Negative",
512 "Ring",
513 "Cone",
514 null
515 };
516
517 char const* LDRadial::radialTypeName () {
518 return g_saRadialTypeNames[type ()];
519 }
520
521 char const* LDRadial::radialTypeName (const LDRadial::Type typeval) {
522 return g_saRadialTypeNames[typeval];
523 }
524
525 vector<LDObject*> LDRadial::decompose( bool applyTransform )
526 {
527 return vector<LDObject*>();
528 }
529
530 // =============================================================================
531 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
532 // =============================================================================
533 str LDRadial::raw () {
534 return fmt ("0 !LDFORGE RADIAL %1 %2 %3 %4 %5 %6 %7",
535 str (radialTypeName ()).toUpper ().remove (' '),
536 color (), segments (), divisions (), number (),
537 position ().stringRep (false), transform ().stringRep());
538 }
539
540 char const* g_radialNameRoots[] = {
541 "edge",
542 "cyli",
543 "disc",
544 "ndis",
545 "ring",
546 "con",
547 null
548 };
549
550 // =============================================================================
551 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
552 // =============================================================================
553 str LDRadial::makeFileName () {
554 return "";
555 } 496 }
556 497
557 // ============================================================================= 498 // =============================================================================
558 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 499 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
559 // ============================================================================= 500 // =============================================================================
563 LDObject* LDObject::getDefault (const LDObject::Type type) { 504 LDObject* LDObject::getDefault (const LDObject::Type type) {
564 CHECK_FOR_OBJ (Comment) 505 CHECK_FOR_OBJ (Comment)
565 CHECK_FOR_OBJ (BFC) 506 CHECK_FOR_OBJ (BFC)
566 CHECK_FOR_OBJ (Line) 507 CHECK_FOR_OBJ (Line)
567 CHECK_FOR_OBJ (CondLine) 508 CHECK_FOR_OBJ (CondLine)
568 CHECK_FOR_OBJ (Radial)
569 CHECK_FOR_OBJ (Subfile) 509 CHECK_FOR_OBJ (Subfile)
570 CHECK_FOR_OBJ (Triangle) 510 CHECK_FOR_OBJ (Triangle)
571 CHECK_FOR_OBJ (Quad) 511 CHECK_FOR_OBJ (Quad)
572 CHECK_FOR_OBJ (Empty) 512 CHECK_FOR_OBJ (Empty)
573 CHECK_FOR_OBJ (BFC) 513 CHECK_FOR_OBJ (BFC)
602 vertex tmp = getVertex (1); 542 vertex tmp = getVertex (1);
603 setVertex (1, getVertex (3)); 543 setVertex (1, getVertex (3));
604 setVertex (3, tmp); 544 setVertex (3, tmp);
605 } 545 }
606 546
607 static void invertSubfile (LDObject* obj) { 547 void LDSubfile::invert () {
608 // Subfiles and radials are inverted when they're prefixed with 548 // Subfiles are inverted when they're prefixed with
609 // a BFC INVERTNEXT statement. Thus we need to toggle this status. 549 // a BFC INVERTNEXT statement. Thus we need to toggle this status.
610 // For flat primitives it's sufficient that the determinant is 550 // For flat primitives it's sufficient that the determinant is
611 // flipped but I don't have a method for checking flatness yet. 551 // flipped but I don't have a method for checking flatness yet.
612 // Food for thought... 552 // Food for thought...
613 553
614 ulong idx = obj->getIndex (g_curfile); 554 ulong idx = getIndex( g_curfile );
615 555
616 if (idx > 0) { 556 if (idx > 0) {
617 LDBFC* bfc = dynamic_cast<LDBFC*> (obj->prev ()); 557 LDBFC* bfc = dynamic_cast<LDBFC*>( prev() );
618 558
619 if (bfc && bfc->type == LDBFC::InvertNext) { 559 if( bfc && bfc->type == LDBFC::InvertNext )
620 // Object is prefixed with an invertnext, thus remove it. 560 {
621 g_curfile->forgetObject (bfc); 561 // This is prefixed with an invertnext, thus remove it.
562 g_curfile->forgetObject( bfc );
622 delete bfc; 563 delete bfc;
623 return; 564 return;
624 } 565 }
625 } 566 }
626 567
627 // Not inverted, thus prefix it with a new invertnext. 568 // Not inverted, thus prefix it with a new invertnext.
628 LDBFC* bfc = new LDBFC (LDBFC::InvertNext); 569 LDBFC* bfc = new LDBFC( LDBFC::InvertNext );
629 g_curfile->insertObj (idx, bfc); 570 g_curfile->insertObj( idx, bfc );
630 }
631
632 void LDSubfile::invert () {
633 invertSubfile (this);
634 }
635
636 void LDRadial::invert () {
637 invertSubfile (this);
638 } 571 }
639 572
640 static void invertLine (LDObject* line) { 573 static void invertLine (LDObject* line) {
641 // For lines, we swap the vertices. I don't think that a 574 // For lines, we swap the vertices. I don't think that a
642 // cond-line's control points need to be swapped, do they? 575 // cond-line's control points need to be swapped, do they?

mercurial