# HG changeset patch # User Teemu Piippo # Date 1415274669 -7200 # Node ID a6c180bffa123de4324718cc41fbca6a92be137e # Parent 3b0b2b1738e9aefd3e937867878c30a8444381ad - argh diff -r 3b0b2b1738e9 -r a6c180bffa12 src/ldDocument.cc --- a/src/ldDocument.cc Wed Nov 05 17:48:11 2014 +0200 +++ b/src/ldDocument.cc Thu Nov 06 13:51:09 2014 +0200 @@ -1373,6 +1373,8 @@ // ----------------------------------------------------------------------------- LDObjectList LDDocument::inlineContents (bool deep, bool renderinline) { + sweepBFC(); + // Possibly substitute with logoed studs: // stud.dat -> stud-logo.dat // stud2.dat -> stud-logo2.dat @@ -1387,41 +1389,42 @@ return g_logoedStud2->inlineContents (deep, renderinline); } - LDObjectList objs, objcache; - bool invertnext = false; + LDObjectList objs; + QList subfiles; for (LDObjectPtr obj : objects()) { - // Handle invertnext - if (obj->type() == OBJ_BFC - and obj.staticCast()->statement() == BFCStatement::InvertNext) - { - invertnext = true; - continue; - } - // Skip those without scemantic meaning if (not obj->isScemantic()) continue; - + // Got another sub-file reference, inline it if we're deep-inlining. If not, // just add it into the objects normally. Yay, recursion! if (deep == true and obj->type() == OBJ_Subfile) - { - for (LDObjectPtr otherobj : obj.staticCast()->inlineContents (deep, renderinline)) - { - if (invertnext) - otherobj->setBlockWinding (Winding (int (otherobj->blockWinding()) ^ 1)); - - objs << otherobj; - } - - invertnext = false; - } + subfiles << obj.staticCast(); else objs << obj->createCopy(); } + // Perform deep inlining + while (not subfiles.isEmpty()) + { + QList subfiles2; + + for (LDSubfilePtr& ref : subfiles) + { + for (LDObjectPtr obj : ref->inlineContents (false, renderinline)) + { + if (obj->type() == OBJ_Subfile) + subfiles2 << obj.staticCast(); + else + objs << obj; + } + } + + subfiles = subfiles2; + } + return objs; } @@ -1641,10 +1644,12 @@ if (invertnext) { + print ("sweepBFC: applying invertnext on %1\n", obj->id()); invertWinding (objwinding); invertnext = false; } + print ("sweepBFC: winding of %1 -> %2\n", obj->id(), int (objwinding)); obj->setBlockWinding (objwinding); } } diff -r 3b0b2b1738e9 -r a6c180bffa12 src/ldObject.cc --- a/src/ldObject.cc Wed Nov 05 17:48:11 2014 +0200 +++ b/src/ldObject.cc Thu Nov 06 13:51:09 2014 +0200 @@ -387,6 +387,9 @@ // ----------------------------------------------------------------------------- LDObjectList LDSubfile::inlineContents (bool deep, bool render) { + fileInfo()->sweepBFC(); + bool isInverted = ((blockWinding() == Winding::CW) + or (transform().getDeterminant() < 0)); LDObjectList objs = fileInfo()->inlineContents (deep, render); // Transform the objects @@ -395,6 +398,12 @@ // Set the parent now so we know what inlined the object. obj->setParent (self()); TransformObject (obj, transform(), position(), color()); + + // Adjust winding + if (blockWinding() == Winding::None) + obj->setBlockWinding (Winding::None); + elif (isInverted) + obj->setBlockWinding (Winding (int (obj->blockWinding()) ^ 1)); } return objs; @@ -426,19 +435,18 @@ return data; } +/* +0 BFC CERTIFY CCW +1 16 0 0 0 1 0 0 0 1 0 0 0 1 stud2a.dat +*/ + // ============================================================================= // QList LDSubfile::inlinePolygons() { - bool isInverted (false); - LDBFCPtr bfc (previous().dynamicCast()); - - if ((bfc != null and bfc->statement() == BFCStatement::InvertNext) - or transform().getDeterminant() < 0) - { - isInverted = true; - } - + fileInfo()->sweepBFC(); + bool isInverted = ((blockWinding() == Winding::CW) + or (transform().getDeterminant() < 0)); QList data = fileInfo()->inlinePolygons(); for (LDPolygon& entry : data) @@ -446,12 +454,15 @@ for (int i = 0; i < entry.numVertices(); ++i) entry.vertices[i].transform (transform(), position()); - if (blockWinding() == Winding::None) + // Adjust winding + if (entry.winding == Winding::None) entry.winding = Winding::None; + //obj->setBlockWinding (Winding::None); elif (isInverted) invertWinding (entry.winding); + //obj->setBlockWinding (Winding (int (obj->blockWinding()) ^ 1)); } - + return data; } diff -r 3b0b2b1738e9 -r a6c180bffa12 src/mainWindow.cc --- a/src/mainWindow.cc Wed Nov 05 17:48:11 2014 +0200 +++ b/src/mainWindow.cc Thu Nov 06 13:51:09 2014 +0200 @@ -403,6 +403,10 @@ } } +#ifdef DEBUG + descr.prepend (format ("[%1] ", obj->id())); +#endif + QListWidgetItem* item = new QListWidgetItem (descr); item->setIcon (GetIcon (obj->typeName()));