src/ldtypes.cpp

changeset 266
12e7302f14e9
parent 265
955c0aabfebf
child 267
95fde37e1f00
equal deleted inserted replaced
265:955c0aabfebf 266:12e7302f14e9
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
60 // ============================================================================= 60 // =============================================================================
61 // LDObject constructors 61 // LDObject constructors
62 LDObject::LDObject () { 62 LDObject::LDObject () {
63 qObjListEntry = null; 63 qObjListEntry = null;
64 parent = null; 64 setParent (null);
65 m_hidden = false; 65 m_hidden = false;
66 m_selected = false; 66 m_selected = false;
67 m_glinit = false; 67 m_glinit = false;
68 } 68 }
69 69
76 str LDComment::getContents () { 76 str LDComment::getContents () {
77 return fmt ("0 %s", text.chars ()); 77 return fmt ("0 %s", text.chars ());
78 } 78 }
79 79
80 str LDSubfile::getContents () { 80 str LDSubfile::getContents () {
81 str val = fmt ("1 %d %s ", color, pos.stringRep (false).chars ()); 81 str val = fmt ("1 %d %s ", color (), pos.stringRep (false).chars ());
82 val += transform.stringRep (); 82 val += transform.stringRep ();
83 val += ' '; 83 val += ' ';
84 val += fileName; 84 val += fileName;
85 return val; 85 return val;
86 } 86 }
87 87
88 str LDLine::getContents () { 88 str LDLine::getContents () {
89 str val = fmt ("2 %d", color); 89 str val = fmt ("2 %d", color ());
90 90
91 for (ushort i = 0; i < 2; ++i) 91 for (ushort i = 0; i < 2; ++i)
92 val += fmt (" %s", coords[i].stringRep (false).chars ()); 92 val += fmt (" %s", coords[i].stringRep (false).chars ());
93 93
94 return val; 94 return val;
95 } 95 }
96 96
97 str LDTriangle::getContents () { 97 str LDTriangle::getContents () {
98 str val = fmt ("3 %d", color); 98 str val = fmt ("3 %d", color ());
99 99
100 for (ushort i = 0; i < 3; ++i) 100 for (ushort i = 0; i < 3; ++i)
101 val += fmt (" %s", coords[i].stringRep (false).chars ()); 101 val += fmt (" %s", coords[i].stringRep (false).chars ());
102 102
103 return val; 103 return val;
104 } 104 }
105 105
106 str LDQuad::getContents () { 106 str LDQuad::getContents () {
107 str val = fmt ("4 %d", color); 107 str val = fmt ("4 %d", color ());
108 108
109 for (ushort i = 0; i < 4; ++i) 109 for (ushort i = 0; i < 4; ++i)
110 val += fmt (" %s", coords[i].stringRep (false).chars ()); 110 val += fmt (" %s", coords[i].stringRep (false).chars ());
111 111
112 return val; 112 return val;
113 } 113 }
114 114
115 str LDCondLine::getContents () { 115 str LDCondLine::getContents () {
116 str val = fmt ("5 %d", color); 116 str val = fmt ("5 %d", color ());
117 117
118 // Add the coordinates 118 // Add the coordinates
119 for (ushort i = 0; i < 4; ++i) 119 for (ushort i = 0; i < 4; ++i)
120 val += fmt (" %s", coords[i].stringRep (false).chars ()); 120 val += fmt (" %s", coords[i].stringRep (false).chars ());
121 121
125 str LDGibberish::getContents () { 125 str LDGibberish::getContents () {
126 return contents; 126 return contents;
127 } 127 }
128 128
129 str LDVertex::getContents () { 129 str LDVertex::getContents () {
130 return fmt ("0 !LDFORGE VERTEX %d %s", color, pos.stringRep (false).chars()); 130 return fmt ("0 !LDFORGE VERTEX %d %s", color (), pos.stringRep (false).chars());
131 } 131 }
132 132
133 str LDEmpty::getContents () { 133 str LDEmpty::getContents () {
134 return str (); 134 return str ();
135 } 135 }
169 tri2->coords[0] = coords[1]; 169 tri2->coords[0] = coords[1];
170 tri2->coords[1] = coords[2]; 170 tri2->coords[1] = coords[2];
171 tri2->coords[2] = coords[3]; 171 tri2->coords[2] = coords[3];
172 172
173 // The triangles also inherit the quad's color 173 // The triangles also inherit the quad's color
174 tri1->color = tri2->color = color; 174 tri1->setColor (tri2->setColor (color ()));
175 175
176 vector<LDTriangle*> triangles; 176 vector<LDTriangle*> triangles;
177 triangles << tri1; 177 triangles << tri1;
178 triangles << tri2; 178 triangles << tri2;
179 return triangles; 179 return triangles;
247 247
248 default: 248 default:
249 break; 249 break;
250 } 250 }
251 251
252 if (obj->color == maincolor) 252 if (obj->color () == maincolor)
253 obj->color = parentcolor; 253 obj->setColor (parentcolor);
254 } 254 }
255 255
256 // ============================================================================= 256 // =============================================================================
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
258 // ============================================================================= 258 // =============================================================================
315 } 315 }
316 316
317 // Transform the objects 317 // Transform the objects
318 for (LDObject* obj : objs) { 318 for (LDObject* obj : objs) {
319 // Set the parent now so we know what inlined this. 319 // Set the parent now so we know what inlined this.
320 obj->parent = this; 320 obj->setParent (this);
321 321
322 transformObject (obj, transform, pos, color); 322 transformObject (obj, transform, pos, color ());
323 } 323 }
324 324
325 return objs; 325 return objs;
326 } 326 }
327 327
412 return text; 412 return text;
413 } 413 }
414 414
415 // ============================================================================= 415 // =============================================================================
416 LDObject* LDObject::topLevelParent () { 416 LDObject* LDObject::topLevelParent () {
417 if (!parent) 417 if (!parent ())
418 return this; 418 return this;
419 419
420 LDObject* it = this; 420 LDObject* it = this;
421 421
422 while (it->parent) 422 while (it->parent ())
423 it = it->parent; 423 it = it->parent ();
424 424
425 return it; 425 return it;
426 } 426 }
427 427
428 // ============================================================================= 428 // =============================================================================
511 511
512 // ============================================================================= 512 // =============================================================================
513 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 513 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
514 // ============================================================================= 514 // =============================================================================
515 vector<LDObject*> LDRadial::decompose (bool applyTransform) { 515 vector<LDObject*> LDRadial::decompose (bool applyTransform) {
516 vector<LDObject*> paObjects; 516 vector<LDObject*> objs;
517 517
518 for (short i = 0; i < segs; ++i) { 518 for (short i = 0; i < segs; ++i) {
519 double x0 = cos ((i * 2 * pi) / divs), 519 double x0 = cos ((i * 2 * pi) / divs),
520 x1 = cos (((i + 1) * 2 * pi) / divs), 520 x1 = cos (((i + 1) * 2 * pi) / divs),
521 z0 = sin ((i * 2 * pi) / divs), 521 z0 = sin ((i * 2 * pi) / divs),
530 if (applyTransform) { 530 if (applyTransform) {
531 v0.transform (transform, pos); 531 v0.transform (transform, pos);
532 v1.transform (transform, pos); 532 v1.transform (transform, pos);
533 } 533 }
534 534
535 LDLine* pLine = new LDLine; 535 LDLine* line = new LDLine;
536 pLine->coords[0] = v0; 536 line->coords[0] = v0;
537 pLine->coords[1] = v1; 537 line->coords[1] = v1;
538 pLine->color = edgecolor; 538 line->setColor (edgecolor);
539 pLine->parent = this; 539 line->setParent (this);
540 540
541 paObjects << pLine; 541 objs << line;
542 } 542 }
543 break; 543 break;
544 544
545 case LDRadial::Cylinder: 545 case LDRadial::Cylinder:
546 case LDRadial::Ring: 546 case LDRadial::Ring:
586 v1.transform (transform, pos); 586 v1.transform (transform, pos);
587 v2.transform (transform, pos); 587 v2.transform (transform, pos);
588 v3.transform (transform, pos); 588 v3.transform (transform, pos);
589 } 589 }
590 590
591 LDQuad* pQuad = new LDQuad; 591 LDQuad* quad = new LDQuad;
592 pQuad->coords[0] = v0; 592 quad->coords[0] = v0;
593 pQuad->coords[1] = v1; 593 quad->coords[1] = v1;
594 pQuad->coords[2] = v2; 594 quad->coords[2] = v2;
595 pQuad->coords[3] = v3; 595 quad->coords[3] = v3;
596 pQuad->color = color; 596 quad->setColor (color ());
597 pQuad->parent = this; 597 quad->setParent (this);
598 598
599 paObjects << pQuad; 599 objs << quad;
600 } 600 }
601 break; 601 break;
602 602
603 case LDRadial::Disc: 603 case LDRadial::Disc:
604 case LDRadial::DiscNeg: 604 case LDRadial::DiscNeg:
620 v0.transform (transform, pos); 620 v0.transform (transform, pos);
621 v1.transform (transform, pos); 621 v1.transform (transform, pos);
622 v2.transform (transform, pos); 622 v2.transform (transform, pos);
623 } 623 }
624 624
625 LDTriangle* pSeg = new LDTriangle; 625 LDTriangle* seg = new LDTriangle;
626 pSeg->coords[0] = v0; 626 seg->coords[0] = v0;
627 pSeg->coords[1] = v1; 627 seg->coords[1] = v1;
628 pSeg->coords[2] = v2; 628 seg->coords[2] = v2;
629 pSeg->color = color; 629 seg->setColor (color ());
630 pSeg->parent = this; 630 seg->setParent (this);
631 631
632 paObjects << pSeg; 632 objs << seg;
633 } 633 }
634 break; 634 break;
635 635
636 default: 636 default:
637 break; 637 break;
638 } 638 }
639 } 639 }
640 640
641 return paObjects; 641 return objs;
642 } 642 }
643 643
644 // ============================================================================= 644 // =============================================================================
645 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 645 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
646 // ============================================================================= 646 // =============================================================================
647 str LDRadial::getContents () { 647 str LDRadial::getContents () {
648 return fmt ("0 !LDFORGE RADIAL %s %d %d %d %d %s %s", 648 return fmt ("0 !LDFORGE RADIAL %s %d %d %d %d %s %s",
649 str (radialTypeName()).upper ().strip (' ').c (), 649 str (radialTypeName()).upper ().strip (' ').c (),
650 color, segs, divs, ringNum, 650 color (), segs, divs, ringNum,
651 pos.stringRep (false).chars(), transform.stringRep().chars()); 651 pos.stringRep (false).chars(), transform.stringRep().chars());
652 } 652 }
653 653
654 char const* g_radialNameRoots[] = { 654 char const* g_radialNameRoots[] = {
655 "edge", 655 "edge",
796 796
797 // ============================================================================= 797 // =============================================================================
798 LDLine* LDCondLine::demote () { 798 LDLine* LDCondLine::demote () {
799 LDLine* repl = new LDLine; 799 LDLine* repl = new LDLine;
800 memcpy (repl->coords, coords, sizeof coords); 800 memcpy (repl->coords, coords, sizeof coords);
801 repl->color = color; 801 repl->setColor (color ());
802 802
803 replace (repl); 803 replace (repl);
804 return repl; 804 return repl;
805 } 805 }

mercurial