126 // History stuff |
126 // History stuff |
127 vector<LDSubfile*> paRefs; |
127 vector<LDSubfile*> paRefs; |
128 vector<ulong> ulaRefIndices, ulaBitIndices; |
128 vector<ulong> ulaRefIndices, ulaBitIndices; |
129 |
129 |
130 for (LDObject* obj : sel) { |
130 for (LDObject* obj : sel) { |
131 if (obj->getType() != OBJ_Subfile) |
131 if (obj->getType() != LDObject::Subfile) |
132 continue; |
132 continue; |
133 |
133 |
134 ulaRefIndices.push_back (obj->getIndex (g_curfile)); |
134 ulaRefIndices.push_back (obj->getIndex (g_curfile)); |
135 paRefs.push_back (static_cast<LDSubfile*> (obj)->clone ()); |
135 paRefs.push_back (static_cast<LDSubfile*> (obj)->clone ()); |
136 } |
136 } |
142 if (idx == -1) |
142 if (idx == -1) |
143 continue; |
143 continue; |
144 |
144 |
145 vector<LDObject*> objs; |
145 vector<LDObject*> objs; |
146 |
146 |
147 if (obj->getType() == OBJ_Subfile) |
147 if (obj->getType() == LDObject::Subfile) |
148 objs = static_cast<LDSubfile*> (obj)->inlineContents (bDeep, true); |
148 objs = static_cast<LDSubfile*> (obj)->inlineContents (bDeep, true); |
149 else if (obj->getType() == OBJ_Radial) |
149 else if (obj->getType() == LDObject::Radial) |
150 objs = static_cast<LDRadial*> (obj)->decompose (true); |
150 objs = static_cast<LDRadial*> (obj)->decompose (true); |
151 else |
151 else |
152 continue; |
152 continue; |
153 |
153 |
154 // Merge in the inlined objects |
154 // Merge in the inlined objects |
189 vector<ulong> ulaIndices; |
189 vector<ulong> ulaIndices; |
190 vector<LDQuad*> paCopies; |
190 vector<LDQuad*> paCopies; |
191 |
191 |
192 // Store stuff first for history archival |
192 // Store stuff first for history archival |
193 for (LDObject* obj : objs) { |
193 for (LDObject* obj : objs) { |
194 if (obj->getType() != OBJ_Quad) |
194 if (obj->getType() != LDObject::Quad) |
195 continue; |
195 continue; |
196 |
196 |
197 ulaIndices.push_back (obj->getIndex (g_curfile)); |
197 ulaIndices.push_back (obj->getIndex (g_curfile)); |
198 paCopies.push_back (static_cast<LDQuad*> (obj)->clone ()); |
198 paCopies.push_back (static_cast<LDQuad*> (obj)->clone ()); |
199 } |
199 } |
200 |
200 |
201 for (LDObject* obj : objs) { |
201 for (LDObject* obj : objs) { |
202 if (obj->getType() != OBJ_Quad) |
202 if (obj->getType() != LDObject::Quad) |
203 continue; |
203 continue; |
204 |
204 |
205 // Find the index of this quad |
205 // Find the index of this quad |
206 long lIndex = obj->getIndex (g_curfile); |
206 long lIndex = obj->getIndex (g_curfile); |
207 |
207 |
279 |
279 |
280 vector<ulong> ulaIndices; |
280 vector<ulong> ulaIndices; |
281 vector<LDObject*> paObjs; |
281 vector<LDObject*> paObjs; |
282 |
282 |
283 for (LDObject* obj : objs) { |
283 for (LDObject* obj : objs) { |
284 if (obj->getType() != OBJ_Quad && obj->getType() != OBJ_Triangle) |
284 if (obj->getType() != LDObject::Quad && obj->getType() != LDObject::Triangle) |
285 continue; |
285 continue; |
286 |
286 |
287 short dNumLines; |
287 short dNumLines; |
288 LDLine* lines[4]; |
288 LDLine* lines[4]; |
289 |
289 |
290 if (obj->getType() == OBJ_Quad) { |
290 if (obj->getType() == LDObject::Quad) { |
291 dNumLines = 4; |
291 dNumLines = 4; |
292 |
292 |
293 LDQuad* quad = static_cast<LDQuad*> (obj); |
293 LDQuad* quad = static_cast<LDQuad*> (obj); |
294 lines[0] = new LDLine (quad->vaCoords[0], quad->vaCoords[1]); |
294 lines[0] = new LDLine (quad->vaCoords[0], quad->vaCoords[1]); |
295 lines[1] = new LDLine (quad->vaCoords[1], quad->vaCoords[2]); |
295 lines[1] = new LDLine (quad->vaCoords[1], quad->vaCoords[2]); |
458 ulong ulHistoryIndex = obj->getIndex (g_curfile); |
458 ulong ulHistoryIndex = obj->getIndex (g_curfile); |
459 LDObject* pOldCopy, *pNewCopy; |
459 LDObject* pOldCopy, *pNewCopy; |
460 bool bEdited = false; |
460 bool bEdited = false; |
461 |
461 |
462 switch (obj->getType ()) { |
462 switch (obj->getType ()) { |
463 case OBJ_Line: |
463 case LDObject::Line: |
464 case OBJ_CondLine: |
464 case LDObject::CondLine: |
465 { |
465 { |
466 // For lines, we swap the vertices. I don't think that a |
466 // For lines, we swap the vertices. I don't think that a |
467 // cond-line's control points need to be swapped, do they? |
467 // cond-line's control points need to be swapped, do they? |
468 LDLine* pLine = static_cast<LDLine*> (obj); |
468 LDLine* pLine = static_cast<LDLine*> (obj); |
469 vertex vTemp = pLine->vaCoords[0]; |
469 vertex vTemp = pLine->vaCoords[0]; |
474 pNewCopy = pLine->clone (); |
474 pNewCopy = pLine->clone (); |
475 bEdited = true; |
475 bEdited = true; |
476 } |
476 } |
477 break; |
477 break; |
478 |
478 |
479 case OBJ_Triangle: |
479 case LDObject::Triangle: |
480 { |
480 { |
481 // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1. |
481 // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1. |
482 // Thus, we swap 1 and 2. |
482 // Thus, we swap 1 and 2. |
483 LDTriangle* pTri = static_cast<LDTriangle*> (obj); |
483 LDTriangle* pTri = static_cast<LDTriangle*> (obj); |
484 vertex vTemp = pTri->vaCoords[1]; |
484 vertex vTemp = pTri->vaCoords[1]; |
489 pNewCopy = pTri->clone (); |
489 pNewCopy = pTri->clone (); |
490 bEdited = true; |
490 bEdited = true; |
491 } |
491 } |
492 break; |
492 break; |
493 |
493 |
494 case OBJ_Quad: |
494 case LDObject::Quad: |
495 { |
495 { |
496 // Quad: 0 -> 1 -> 2 -> 3 |
496 // Quad: 0 -> 1 -> 2 -> 3 |
497 // rev: 0 -> 3 -> 2 -> 1 |
497 // rev: 0 -> 3 -> 2 -> 1 |
498 // Thus, we swap 1 and 3. |
498 // Thus, we swap 1 and 3. |
499 LDQuad* pQuad = static_cast<LDQuad*> (obj); |
499 LDQuad* pQuad = static_cast<LDQuad*> (obj); |
505 pNewCopy = pQuad->clone (); |
505 pNewCopy = pQuad->clone (); |
506 bEdited = true; |
506 bEdited = true; |
507 } |
507 } |
508 break; |
508 break; |
509 |
509 |
510 case OBJ_Subfile: |
510 case LDObject::Subfile: |
511 case OBJ_Radial: |
511 case LDObject::Radial: |
512 { |
512 { |
513 // Subfiles and radials are inverted when they're prefixed with |
513 // Subfiles and radials are inverted when they're prefixed with |
514 // a BFC INVERTNEXT statement. Thus we need to toggle this status. |
514 // a BFC INVERTNEXT statement. Thus we need to toggle this status. |
515 // For flat primitives it's sufficient that the determinant is |
515 // For flat primitives it's sufficient that the determinant is |
516 // flipped but I don't have a method for checking flatness yet. |
516 // flipped but I don't have a method for checking flatness yet. |
584 (n * n * (1 - cos (angle))) + cos (angle) |
584 (n * n * (1 - cos (angle))) + cos (angle) |
585 }); |
585 }); |
586 |
586 |
587 // Calculate center vertex |
587 // Calculate center vertex |
588 for (LDObject* obj : sel) { |
588 for (LDObject* obj : sel) { |
589 if (obj->getType () == OBJ_Subfile) |
589 if (obj->getType () == LDObject::Subfile) |
590 box << static_cast<LDSubfile*> (obj)->vPosition; |
590 box << static_cast<LDSubfile*> (obj)->vPosition; |
591 else if (obj->getType () == OBJ_Radial) |
591 else if (obj->getType () == LDObject::Radial) |
592 box << static_cast<LDRadial*> (obj)->vPosition; |
592 box << static_cast<LDRadial*> (obj)->vPosition; |
593 else |
593 else |
594 box << obj; |
594 box << obj; |
595 } |
595 } |
596 |
596 |
599 // Apply the above matrix to everything |
599 // Apply the above matrix to everything |
600 for (LDObject* obj : sel) { |
600 for (LDObject* obj : sel) { |
601 if (obj->vertices ()) |
601 if (obj->vertices ()) |
602 for (short i = 0; i < obj->vertices (); ++i) |
602 for (short i = 0; i < obj->vertices (); ++i) |
603 queue.push_back (&obj->vaCoords[i]); |
603 queue.push_back (&obj->vaCoords[i]); |
604 else if (obj->getType () == OBJ_Subfile) { |
604 else if (obj->getType () == LDObject::Subfile) { |
605 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
605 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
606 |
606 |
607 queue.push_back (&ref->vPosition); |
607 queue.push_back (&ref->vPosition); |
608 ref->mMatrix = ref->mMatrix * transform; |
608 ref->mMatrix = ref->mMatrix * transform; |
609 } else if (obj->getType () == OBJ_Radial) { |
609 } else if (obj->getType () == LDObject::Radial) { |
610 LDRadial* rad = static_cast<LDRadial*> (obj); |
610 LDRadial* rad = static_cast<LDRadial*> (obj); |
611 |
611 |
612 queue.push_back (&rad->vPosition); |
612 queue.push_back (&rad->vPosition); |
613 rad->mMatrix = rad->mMatrix * transform; |
613 rad->mMatrix = rad->mMatrix * transform; |
614 } else if (obj->getType () == OBJ_Vertex) |
614 } else if (obj->getType () == LDObject::Vertex) |
615 queue.push_back (&static_cast<LDVertex*> (obj)->vPosition); |
615 queue.push_back (&static_cast<LDVertex*> (obj)->vPosition); |
616 } |
616 } |
617 |
617 |
618 for (vertex* v : queue) { |
618 for (vertex* v : queue) { |
619 v->move (-origin); |
619 v->move (-origin); |
674 continue; |
674 continue; |
675 |
675 |
676 indices.push_back (obj->getIndex (g_curfile)); |
676 indices.push_back (obj->getIndex (g_curfile)); |
677 oldCopies.push_back (obj->clone ()); |
677 oldCopies.push_back (obj->clone ()); |
678 |
678 |
679 obj->dColor = (obj->getType () == OBJ_Line || obj->getType () == OBJ_CondLine) ? edgecolor : maincolor; |
679 obj->dColor = (obj->getType () == LDObject::Line || obj->getType () == LDObject::CondLine) ? edgecolor : maincolor; |
680 newCopies.push_back (obj->clone ()); |
680 newCopies.push_back (obj->clone ()); |
681 } |
681 } |
682 |
682 |
683 if (indices.size () > 0) { |
683 if (indices.size () > 0) { |
684 History::addEntry (new EditHistory (indices, oldCopies, newCopies)); |
684 History::addEntry (new EditHistory (indices, oldCopies, newCopies)); |
685 g_win->refresh (); |
685 g_win->refresh (); |
686 } |
686 } |
687 } |
687 } |
688 |
|
689 // ============================================================================= |
|
690 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
691 // ============================================================================= |
|
692 MAKE_ACTION (ytruder, "Ytruder", "ytruder", "Extrude selected lines to a given plane", KEY (F8)) { |
|
693 runYtruder (); |
|
694 } |
|