# HG changeset patch # User Teemu Piippo # Date 1529434161 -10800 # Node ID 0d6162662040c2ec1f29053666e05293ca394c13 # Parent 22bc5862cb56c09ad36909525ab86efb9996cd3b fixed bugs regarding primitives, added chord substitution diff -r 22bc5862cb56 -r 0d6162662040 src/dialogs/circularprimitiveeditor.cpp --- a/src/dialogs/circularprimitiveeditor.cpp Sun Jun 17 17:07:29 2018 +0300 +++ b/src/dialogs/circularprimitiveeditor.cpp Tue Jun 19 21:49:21 2018 +0300 @@ -42,6 +42,7 @@ MAP_RADIO_BUTTON(discNegative, DiscNegative), MAP_RADIO_BUTTON(cylinderClosed, CylinderClosed), MAP_RADIO_BUTTON(cylinderOpen, CylinderOpen), + MAP_RADIO_BUTTON(chord, Chord), #undef MAP_RADIO_BUTTON }; diff -r 22bc5862cb56 -r 0d6162662040 src/dialogs/circularprimitiveeditor.ui --- a/src/dialogs/circularprimitiveeditor.ui Sun Jun 17 17:07:29 2018 +0300 +++ b/src/dialogs/circularprimitiveeditor.ui Tue Jun 19 21:49:21 2018 +0300 @@ -11,7 +11,7 @@ - Dialog + Edit circular primitive @@ -116,6 +116,13 @@ + + + + Chord + + + diff -r 22bc5862cb56 -r 0d6162662040 src/linetypes/circularprimitive.cpp --- a/src/linetypes/circularprimitive.cpp Sun Jun 17 17:07:29 2018 +0300 +++ b/src/linetypes/circularprimitive.cpp Tue Jun 19 21:49:21 2018 +0300 @@ -153,9 +153,15 @@ case PrimitiveModel::CylinderOpen: return "cylo"; - default: - throw std::logic_error("Bad primitive type to LDCircularPrimitive"); + case PrimitiveModel::Chord: + return "chrd"; + + case PrimitiveModel::Ring: + case PrimitiveModel::Cone: + break; } + + throw std::logic_error("Bad primitive type to LDCircularPrimitive"); } QString LDCircularPrimitive::objectListText() const @@ -234,6 +240,9 @@ case PrimitiveModel::Circle: return 0; + + case PrimitiveModel::Chord: + return m_segments - 1; } return 0; @@ -264,6 +273,9 @@ case PrimitiveModel::CylinderOpen: return "cylinder-open"; + + case PrimitiveModel::Chord: + return "chord"; } return ""; diff -r 22bc5862cb56 -r 0d6162662040 src/parser.cpp --- a/src/parser.cpp Sun Jun 17 17:07:29 2018 +0300 +++ b/src/parser.cpp Tue Jun 19 21:49:21 2018 +0300 @@ -268,7 +268,7 @@ } */ - if (invertNext and object->type() == LDObjectType::SubfileReference) + if (invertNext and object->isRasterizable()) object->setInverted(true); invertNext = false; @@ -392,7 +392,7 @@ matrix.optimize(); static const QRegExp circularPrimitiveRegexp { - R"((?:(\d+)\\)?(\d+)-(\d+)(cyli|edge|disc|ndis|cylc|cylo)\.dat)" + R"((?:(\d+)\\)?(\d+)-(\d+)(cyli|edge|disc|ndis|cylc|cylo|chrd)\.dat)" }; LDObject* obj; @@ -419,6 +419,8 @@ type = PrimitiveModel::CylinderClosed; else if (stem == "cylo") type = PrimitiveModel::CylinderOpen; + else if (stem == "chrd") + type = PrimitiveModel::Chord; obj = model.emplaceAt( position, diff -r 22bc5862cb56 -r 0d6162662040 src/primitives.cpp --- a/src/primitives.cpp Sun Jun 17 17:07:29 2018 +0300 +++ b/src/primitives.cpp Tue Jun 19 21:49:21 2018 +0300 @@ -374,6 +374,20 @@ } } +void PrimitiveModel::generateChord(Model& model) const +{ + QVector circle = makeCircle(segments, divisions, 1); + + for (int i = 1; i < segments; ++i) + { + LDTriangle* segment = model.emplace(); + segment->setColor(MainColor); + segment->setVertex(0, {circle[0].x1(), 0.0, circle[0].y1()}); + segment->setVertex(1, {circle[i].x1(), 0.0, circle[i].y1()}); + segment->setVertex(2, {circle[i].x2(), 0.0, circle[i].y2()}); + } +} + void PrimitiveModel::generateBody(Model& model, bool deep) const { switch (type) @@ -419,6 +433,10 @@ } return; + case Chord: + generateChord(model); + return; + default: break; } @@ -473,6 +491,7 @@ } break; + case Chord: case Disc: case DiscNegative: case Circle: @@ -529,7 +548,8 @@ "Ring", "Cone", "Cylinder Closed", - "Cylinder Open" + "Cylinder Open", + "Chord" }; if (type >= 0 and type < countof(names)) @@ -557,7 +577,7 @@ // Compose some general information: prefix, fraction, root, ring number QString prefix = (divisions == MediumResolution) ? "" : format ("%1\\", divisions); QString frac = format ("%1-%2", numerator, denominator); - static const char* roots[] = {"edge", "cyli", "disc", "ndis", "ring", "con"}; + static const char* roots[] = {"edge", "cyli", "disc", "ndis", "ring", "con", "chrd"}; QString root = roots[type]; QString numberString = (type == Ring or type == Cone) ? format ("%1", ringNumber) : ""; diff -r 22bc5862cb56 -r 0d6162662040 src/primitives.h --- a/src/primitives.h Sun Jun 17 17:07:29 2018 +0300 +++ b/src/primitives.h Tue Jun 19 21:49:21 2018 +0300 @@ -52,6 +52,7 @@ Cone, CylinderClosed, CylinderOpen, + Chord, } type; int segments; int divisions; @@ -67,6 +68,7 @@ private: void generateDiscNegative(Model& model) const; + void generateChord(Model& model) const; }; Q_DECLARE_METATYPE(PrimitiveModel::Type) diff -r 22bc5862cb56 -r 0d6162662040 src/widgets/matrixeditor.cpp --- a/src/widgets/matrixeditor.cpp Sun Jun 17 17:07:29 2018 +0300 +++ b/src/widgets/matrixeditor.cpp Tue Jun 19 21:49:21 2018 +0300 @@ -176,9 +176,10 @@ (float) ui.positionX->value(), (float) ui.positionY->value(), (float) ui.positionZ->value(), - 0.0f + 1.0f }; transformationMatrix.setColumn(3, translation); + transformationMatrix.optimize(); return transformationMatrix; }