Tue, 19 Jun 2018 21:49:21 +0300
fixed bugs regarding primitives, added chord substitution
--- 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 };
--- 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 @@ </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Edit circular primitive</string> </property> <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,1,0"> <item> @@ -116,6 +116,13 @@ </property> </widget> </item> + <item row="2" column="0"> + <widget class="QRadioButton" name="chord"> + <property name="text"> + <string>Chord</string> + </property> + </widget> + </item> </layout> </widget> </item>
--- 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 "";
--- 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<LDCircularPrimitive>( position,
--- 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<QLineF> circle = makeCircle(segments, divisions, 1); + + for (int i = 1; i < segments; ++i) + { + LDTriangle* segment = model.emplace<LDTriangle>(); + 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) : "";
--- 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)
--- 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; }