Wed, 05 Nov 2014 03:49:29 +0200
- bfc stuff (at least it works now...)
src/basics.h | file | annotate | diff | comparison | revisions | |
src/glCompiler.cc | file | annotate | diff | comparison | revisions | |
src/ldDocument.cc | file | annotate | diff | comparison | revisions | |
src/ldObject.cc | file | annotate | diff | comparison | revisions | |
src/ldObject.h | file | annotate | diff | comparison | revisions |
--- a/src/basics.h Wed Nov 05 02:07:38 2014 +0200 +++ b/src/basics.h Wed Nov 05 03:49:29 2014 +0200 @@ -23,6 +23,7 @@ #include <QMetaType> #include <QVector3D> #include <QSharedPointer> +#include <functional> #include "macros.h" class LDObject; @@ -65,10 +66,8 @@ inline void invertWinding (Winding& winding) { - if (winding == Winding::CW) - winding = Winding::CCW; - elif (winding == Winding::CCW) - winding = Winding::CW; + if (winding != Winding::None) + winding = Winding (int (winding) ^ 1); } //
--- a/src/glCompiler.cc Wed Nov 05 02:07:38 2014 +0200 +++ b/src/glCompiler.cc Wed Nov 05 03:49:29 2014 +0200 @@ -136,7 +136,6 @@ static const QColor bfcDisabledColor (64, 64, 208); static QList<int> warnedcolors; QColor qcol; - print ("Winding of %1 is %2", poly.id, (int) poly.winding); switch (complement) {
--- a/src/ldDocument.cc Wed Nov 05 02:07:38 2014 +0200 +++ b/src/ldDocument.cc Wed Nov 05 03:49:29 2014 +0200 @@ -1152,7 +1152,7 @@ // int LDDocument::addObject (LDObjectPtr obj) { - history()->add (new AddHistory (objects().size(), obj)); + history()->add (new AddHistory (m_objects.size(), obj)); m_objects << obj; addKnownVertices (obj); obj->setDocument (self()); @@ -1388,9 +1388,18 @@ } LDObjectList objs, objcache; + bool invertnext = false; for (LDObjectPtr obj : objects()) { + // Handle invertnext + if (obj->type() == OBJ_BFC + and obj.staticCast<LDBFC>()->statement() == BFCStatement::InvertNext) + { + invertnext = true; + continue; + } + // Skip those without scemantic meaning if (not obj->isScemantic()) continue; @@ -1399,8 +1408,17 @@ // just add it into the objects normally. Yay, recursion! if (deep == true and obj->type() == OBJ_Subfile) { + // If the subfile is BFC-inverted the rest of the files need to follow. + // This cannot be done in LDSubfile::inlineContents. for (LDObjectPtr otherobj : obj.staticCast<LDSubfile>()->inlineContents (deep, renderinline)) + { + if (invertnext) + otherobj->setBlockWinding (Winding (int (otherobj->blockWinding()) ^ 1)); + objs << otherobj; + } + + invertnext = false; } else objs << obj->createCopy(); @@ -1576,16 +1594,16 @@ if (not m_needBFCSweep) return; - QTime t0 (QTime::currentTime()); Winding winding (Winding::None); Winding preclip (winding); - LDBFCPtr bfc; bool invertnext (false); for (LDObjectPtr obj : m_objects) { if (obj->type() == OBJ_BFC) { + invertnext = false; + switch (obj.staticCast<LDBFC>()->statement()) { case BFCStatement::CCW: @@ -1596,6 +1614,7 @@ case BFCStatement::CW: case BFCStatement::CertifyCW: winding = Winding::CW; + break; case BFCStatement::NoCertify: winding = Winding::None; @@ -1628,11 +1647,10 @@ invertnext = false; } - print ("%1: BFC sweep: set winding of %2 to %3", getDisplayName(), obj->id(), int (objwinding)); obj->setBlockWinding (objwinding); } } - print ("%1: BFC sweep done in %2ms", getDisplayName(), t0.msecsTo (QTime::currentTime())); m_needBFCSweep = false; + m_needsReCache = true; }
--- a/src/ldObject.cc Wed Nov 05 02:07:38 2014 +0200 +++ b/src/ldObject.cc Wed Nov 05 03:49:29 2014 +0200 @@ -392,7 +392,6 @@ // Transform the objects for (LDObjectPtr obj : objs) { - assert (obj->type() != OBJ_Subfile); // Set the parent now so we know what inlined the object. obj->setParent (self()); TransformObject (obj, transform(), position(), color()); @@ -440,8 +439,6 @@ isInverted = true; } - print ("inlining polygons of subfile-ref %1: inverted: %2", fileInfo()->name(), isInverted ? "true" : "false"); - QList<LDPolygon> data = fileInfo()->inlinePolygons(); for (LDPolygon& entry : data) @@ -449,11 +446,12 @@ for (int i = 0; i < entry.numVertices(); ++i) entry.vertices[i].transform (transform(), position()); - if (isInverted) + if (blockWinding() == Winding::None) + entry.winding = Winding::None; + elif (isInverted) invertWinding (entry.winding); } - print ("Using winding: %1\n", (data[0].winding == Winding::CCW) ? "CCW" : (data[0].winding == Winding::CW) ? "CW" : "None"); return data; } @@ -930,6 +928,7 @@ LDObjectPtr LDObject::createCopy() const { LDObjectPtr copy = ParseLine (asText()); + copy->setBlockWinding (blockWinding()); return copy; } @@ -965,3 +964,12 @@ { verts.append (pos); } + +void LDObject::setBlockWinding (Winding const& a) +{ + if (m_blockWinding != a) + g_win->R()->compileObject (self()); + + m_blockWinding = a; +} +
--- a/src/ldObject.h Wed Nov 05 02:07:38 2014 +0200 +++ b/src/ldObject.h Wed Nov 05 03:49:29 2014 +0200 @@ -104,7 +104,7 @@ // What winding the object is supposed to be wound in, depending on the BFC statements // This is CW if the part is CW-certified at this object, and vice versa. Can also be // Winding::None for NOCERTIFY parts. - PROPERTY (public, Winding, blockWinding, setBlockWinding, STOCK_WRITE) + PROPERTY (public, Winding, blockWinding, setBlockWinding, CUSTOM_WRITE) public: LDObject (LDObjectPtr* selfptr);