ldtypes.cpp

changeset 168
96691a009dff
parent 164
8c93d8e38494
child 169
f562323760a2
equal deleted inserted replaced
167:df78c894ae24 168:96691a009dff
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);
257 bCache = false; 257 bCache = false;
258 258
259 for (LDObject* obj : pFile->m_objs) { 259 for (LDObject* obj : pFile->m_objs) {
260 // Skip those without schemantic meaning 260 // Skip those without schemantic meaning
261 switch (obj->getType ()) { 261 switch (obj->getType ()) {
262 case OBJ_Comment: 262 case LDObject::Comment:
263 case OBJ_Empty: 263 case LDObject::Empty:
264 case OBJ_Gibberish: 264 case LDObject::Gibberish:
265 case OBJ_Unidentified: 265 case LDObject::Unidentified:
266 case OBJ_Vertex: 266 case LDObject::Vertex:
267 continue; 267 continue;
268 268
269 case OBJ_BFC: 269 case LDObject::BFC:
270 // Filter non-INVERTNEXT statements 270 // Filter non-INVERTNEXT statements
271 if (static_cast<LDBFC*> (obj)->type != LDBFC::InvertNext) 271 if (static_cast<LDBFC*> (obj)->type != LDBFC::InvertNext)
272 continue; 272 continue;
273 break; 273 break;
274 274
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) {
362 str text = ""; 362 str text = "";
363 363
364 if (objs.size() == 0) 364 if (objs.size() == 0)
365 return "nothing"; // :) 365 return "nothing"; // :)
366 366
367 for (long i = 0; i < NUM_ObjectTypes; ++i) { 367 for (long i = 0; i < LDObject::NumTypes; ++i) {
368 LDObjectType_e objType = (LDObjectType_e) i; 368 LDObject::Type objType = (LDObject::Type) i;
369 ulong objCount = 0; 369 ulong objCount = 0;
370 370
371 for (LDObject* obj : objs) 371 for (LDObject* obj : objs)
372 if (obj->getType() == objType) 372 if (obj->getType() == objType)
373 objCount++; 373 objCount++;
379 text += ", "; 379 text += ", ";
380 380
381 str noun = fmt ("%s%s", g_saObjTypeNames[objType], PLURAL (objCount)); 381 str noun = fmt ("%s%s", g_saObjTypeNames[objType], PLURAL (objCount));
382 382
383 // Plural of "vertex" is "vertices". Stupid English. 383 // Plural of "vertex" is "vertices". Stupid English.
384 if (objType == OBJ_Vertex && objCount != 1) 384 if (objType == LDObject::Vertex && objCount != 1)
385 noun = "vertices"; 385 noun = "vertices";
386 386
387 text.appendformat ("%lu %s", objCount, noun.chars ()); 387 text.appendformat ("%lu %s", objCount, noun.chars ());
388 firstDetails = false; 388 firstDetails = false;
389 } 389 }
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)

mercurial