214 // ============================================================================= |
214 // ============================================================================= |
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
216 // ============================================================================= |
216 // ============================================================================= |
217 static void transformObject (LDObject* obj, matrix<3> transform, vertex pos, short parentcolor) { |
217 static void transformObject (LDObject* obj, matrix<3> transform, vertex pos, short parentcolor) { |
218 switch (obj->getType()) { |
218 switch (obj->getType()) { |
219 case OBJ_Line: |
219 case LDObject::Line: |
220 case OBJ_CondLine: |
220 case LDObject::CondLine: |
221 case OBJ_Triangle: |
221 case LDObject::Triangle: |
222 case OBJ_Quad: |
222 case LDObject::Quad: |
223 for (short i = 0; i < obj->vertices (); ++i) |
223 for (short i = 0; i < obj->vertices (); ++i) |
224 obj->vaCoords[i].transform (transform, pos); |
224 obj->vaCoords[i].transform (transform, pos); |
225 break; |
225 break; |
226 |
226 |
227 case OBJ_Subfile: |
227 case LDObject::Subfile: |
228 { |
228 { |
229 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
229 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
230 |
230 |
231 matrix<3> newMatrix = transform * ref->mMatrix; |
231 matrix<3> newMatrix = transform * ref->mMatrix; |
232 ref->vPosition.transform (transform, pos); |
232 ref->vPosition.transform (transform, pos); |
277 } |
277 } |
278 |
278 |
279 // Got another sub-file reference, inline it if we're deep-inlining. If not, |
279 // Got another sub-file reference, inline it if we're deep-inlining. If not, |
280 // just add it into the objects normally. Also, we only cache immediate |
280 // just add it into the objects normally. Also, we only cache immediate |
281 // subfiles and this is not one. Yay, recursion! |
281 // subfiles and this is not one. Yay, recursion! |
282 if (bDeepInline && obj->getType() == OBJ_Subfile) { |
282 if (bDeepInline && obj->getType() == LDObject::Subfile) { |
283 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
283 LDSubfile* ref = static_cast<LDSubfile*> (obj); |
284 |
284 |
285 vector<LDObject*> otherobjs = ref->inlineContents (true, false); |
285 vector<LDObject*> otherobjs = ref->inlineContents (true, false); |
286 |
286 |
287 for (LDObject* otherobj : otherobjs) { |
287 for (LDObject* otherobj : otherobjs) { |
621 |
621 |
622 // ============================================================================= |
622 // ============================================================================= |
623 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
623 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
624 // ============================================================================= |
624 // ============================================================================= |
625 str LDRadial::makeFileName () { |
625 str LDRadial::makeFileName () { |
626 short dNumerator = dSegments, |
626 short numer = dSegments, |
627 dDenominator = dDivisions; |
627 denom = dDivisions; |
628 |
628 |
629 // Simplify the fractional part, but the denominator must be at least 4. |
629 // Simplify the fractional part, but the denominator must be at least 4. |
630 simplify (dNumerator, dDenominator); |
630 simplify (numer, denom); |
631 |
631 |
632 if (dDenominator < 4) { |
632 if (denom < 4) { |
633 const short dFactor = (4 / dDenominator); |
633 const short factor = (4 / denom); |
634 |
634 |
635 dNumerator *= dFactor; |
635 numer *= factor; |
636 dDenominator *= dFactor; |
636 denom *= factor; |
637 } |
637 } |
638 |
638 |
639 // Compose some general information: prefix, fraction, root, ring number |
639 // Compose some general information: prefix, fraction, root, ring number |
640 str zPrefix = (dDivisions == 16) ? "" : fmt ("%d/", dDivisions); |
640 str prefix = (dDivisions == 16) ? "" : fmt ("%d/", dDivisions); |
641 str zFrac = fmt ("%d-%d", dNumerator, dDenominator); |
641 str frac = fmt ("%d-%d", numer, denom); |
642 str zRoot = g_saRadialNameRoots[eRadialType]; |
642 str root = g_saRadialNameRoots[eRadialType]; |
643 str zRingNum = (eRadialType == Ring || eRadialType == Cone) ? fmt ("%d", dRingNum) : ""; |
643 str ringNum = (eRadialType == Ring || eRadialType == Cone) ? fmt ("%d", dRingNum) : ""; |
644 |
644 |
645 // Truncate the root if necessary (7-16rin4.dat for instance). |
645 // Truncate the root if necessary (7-16rin4.dat for instance). |
646 // However, always keep the root at least 2 characters. |
646 // However, always keep the root at least 2 characters. |
647 short dExtra = (~zFrac + ~zRingNum + ~zRoot) - 8; |
647 short extra = (~frac + ~ringNum + ~root) - 8; |
648 zRoot -= min<short> (max<short> (dExtra, 0), 2); |
648 root -= min<short> (max<short> (extra, 0), 2); |
649 |
649 |
650 // Stick them all together and return the result. |
650 // Stick them all together and return the result. |
651 return fmt ("%s%s%s%s", zPrefix.chars(), zFrac.chars (), zRoot.chars (), zRingNum.chars ()); |
651 return fmt ("%s%s%s%s", prefix.chars(), frac.chars (), root.chars (), ringNum.chars ()); |
652 } |
652 } |
653 |
653 |
654 // ============================================================================= |
654 // ============================================================================= |
655 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
655 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
656 // ============================================================================= |
656 // ============================================================================= |
657 #define CHECK_FOR_OBJ(N) \ |
657 #define CHECK_FOR_OBJ(N) \ |
658 if (type == OBJ_##N) \ |
658 if (type == LDObject::##N) \ |
659 return new LD##N; |
659 return new LD##N; |
660 LDObject* LDObject::getDefault (const LDObjectType_e type) { |
660 LDObject* LDObject::getDefault (const LDObject::Type type) { |
661 CHECK_FOR_OBJ (Comment) |
661 CHECK_FOR_OBJ (Comment) |
662 CHECK_FOR_OBJ (BFC) |
662 CHECK_FOR_OBJ (BFC) |
663 CHECK_FOR_OBJ (Line) |
663 CHECK_FOR_OBJ (Line) |
664 CHECK_FOR_OBJ (CondLine) |
664 CHECK_FOR_OBJ (CondLine) |
665 CHECK_FOR_OBJ (Radial) |
665 CHECK_FOR_OBJ (Radial) |