Sun, 04 Oct 2015 13:19:45 +0300
Subject Bézier curve fineness to the grid. By default, the coarse grid uses 8 segments, medium 16 and fine 32. Moved rasterization from demoting to inlining, it feels more sensible for it to be there.
--- a/CMakeLists.txt Sun Oct 04 06:59:09 2015 +0300 +++ b/CMakeLists.txt Sun Oct 04 13:19:45 2015 +0300 @@ -100,6 +100,7 @@ src/ldDocument.h src/ldObject.h src/ldObjectMath.h + src/ldobjectiterator.h src/ldpaths.h src/macros.h src/main.h
--- a/src/dialogs/configdialog.ui Sun Oct 04 06:59:09 2015 +0300 +++ b/src/dialogs/configdialog.ui Sun Oct 04 13:19:45 2015 +0300 @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>668</width> + <width>792</width> <height>408</height> </rect> </property> @@ -743,6 +743,19 @@ <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <layout class="QGridLayout" name="gridLayout"> + <item row="3" column="3"> + <widget class="QDoubleSpinBox" name="configGridFineCoordinateSnap"> + <property name="suffix"> + <string> LDU</string> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="maximum"> + <double>10000.000000000000000</double> + </property> + </widget> + </item> <item row="3" column="4"> <widget class="QDoubleSpinBox" name="configGridFineAngleSnap"> <property name="suffix"> @@ -800,6 +813,13 @@ </property> </widget> </item> + <item row="2" column="2"> + <widget class="QLabel" name="label_13"> + <property name="text"> + <string>Medium</string> + </property> + </widget> + </item> <item row="1" column="4"> <widget class="QDoubleSpinBox" name="configGridCoarseAngleSnap"> <property name="suffix"> @@ -823,13 +843,6 @@ </property> </widget> </item> - <item row="2" column="2"> - <widget class="QLabel" name="label_13"> - <property name="text"> - <string>Medium</string> - </property> - </widget> - </item> <item row="2" column="3"> <widget class="QDoubleSpinBox" name="configGridMediumCoordinateSnap"> <property name="suffix"> @@ -856,6 +869,13 @@ </property> </widget> </item> + <item row="3" column="2"> + <widget class="QLabel" name="label_14"> + <property name="text"> + <string>Fine</string> + </property> + </widget> + </item> <item row="3" column="1"> <widget class="QLabel" name="label_11"> <property name="text"> @@ -866,26 +886,6 @@ </property> </widget> </item> - <item row="3" column="2"> - <widget class="QLabel" name="label_14"> - <property name="text"> - <string>Fine</string> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="QDoubleSpinBox" name="configGridFineCoordinateSnap"> - <property name="suffix"> - <string> LDU</string> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="maximum"> - <double>10000.000000000000000</double> - </property> - </widget> - </item> <item row="1" column="0"> <spacer name="horizontalSpacer_9"> <property name="orientation"> @@ -899,7 +899,7 @@ </property> </spacer> </item> - <item row="1" column="5"> + <item row="1" column="6"> <spacer name="horizontalSpacer_10"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -912,6 +912,43 @@ </property> </spacer> </item> + <item row="0" column="5"> + <widget class="QLabel" name="label_9"> + <property name="text"> + <string>Bézier curve segments</string> + </property> + </widget> + </item> + <item row="1" column="5"> + <widget class="QSpinBox" name="configGridCoarseBezierCurveSegments"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>1000</number> + </property> + </widget> + </item> + <item row="2" column="5"> + <widget class="QSpinBox" name="configGridMediumBezierCurveSegments"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>1000</number> + </property> + </widget> + </item> + <item row="3" column="5"> + <widget class="QSpinBox" name="configGridFineBezierCurveSegments"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>10000</number> + </property> + </widget> + </item> </layout> </item> <item>
--- a/src/glCompiler.cpp Sun Oct 04 06:59:09 2015 +0300 +++ b/src/glCompiler.cpp Sun Oct 04 13:19:45 2015 +0300 @@ -340,7 +340,7 @@ case OBJ_BezierCurve: { LDBezierCurve* curve = static_cast<LDBezierCurve*> (obj); - for (LDPolygon& poly : curve->rasterizePolygons (24)) + for (LDPolygon& poly : curve->rasterizePolygons (gridBezierCurveSegments())) { poly.id = obj->id(); compilePolygon (poly, obj, &info);
--- a/src/ldobjectiterator.h Sun Oct 04 06:59:09 2015 +0300 +++ b/src/ldobjectiterator.h Sun Oct 04 13:19:45 2015 +0300 @@ -27,7 +27,7 @@ T* get() const { - return (T*) m_list[m_i]; + return static_cast<T*> (m_list[m_i]); } bool isValid() const @@ -87,7 +87,23 @@ rewindTillValid(); } + operator T*() + { + return get(); + } + private: const LDObjectList& m_list; int m_i; }; + +template<typename T, typename R> +QVector<T*> filterByType (const R& stuff) +{ + QVector<T*> result; + + for (LDObjectIterator<T> it (stuff); it.isValid(); ++it) + result << it; + + return result; +}
--- a/src/mainwindow.cpp Sun Oct 04 06:59:09 2015 +0300 +++ b/src/mainwindow.cpp Sun Oct 04 13:19:45 2015 +0300 @@ -55,6 +55,7 @@ #include "guiutilities.h" #include "glCompiler.h" #include "documentmanager.h" +#include "ldobjectiterator.h" ConfigOption (bool ColorizeObjectsList = true) ConfigOption (QString QuickColorToolbar = "4:25:14:27:2:3:11:1:22:|:0:72:71:15") @@ -82,6 +83,9 @@ m_tabs->setTabsClosable (true); ui.verticalLayout->insertWidget (0, m_tabs); + createBlankDocument(); + m_renderer->setDocument (m_currentDocument); + // Stuff the renderer into its frame QVBoxLayout* rendererLayout = new QVBoxLayout (ui.rendererFrame); rendererLayout->addWidget (renderer()); @@ -165,9 +169,6 @@ toolbar->hide(); } - createBlankDocument(); - m_renderer->setDocument (m_currentDocument); - // If this is the first start, get the user to configuration. Especially point // them to the profile tab, it's the most important form to fill in. if (m_configOptions.firstStart()) @@ -310,6 +311,10 @@ ui.actionGridCoarse->setChecked (grid == Grid::Coarse); ui.actionGridMedium->setChecked (grid == Grid::Medium); ui.actionGridFine->setChecked (grid == Grid::Fine); + + // Recompile all Bézier curves, the changing grid affects their precision. + for (LDObjectIterator<LDBezierCurve> it (m_currentDocument); it.isValid(); ++it) + renderer()->compileObject (it); } // --------------------------------------------------------------------------------------------------------------------- @@ -810,6 +815,7 @@ ui.actionModeCircle->setChecked (mode == EditModeType::Circle); ui.actionModeMagicWand->setChecked (mode == EditModeType::MagicWand); ui.actionModeLinePath->setChecked (mode == EditModeType::LinePath); + ui.actionModeCurve->setChecked (mode == EditModeType::Curve); } // ---------------------------------------------------------------------------------------------------------------------
--- a/src/mainwindow.ui Sun Oct 04 06:59:09 2015 +0300 +++ b/src/mainwindow.ui Sun Oct 04 13:19:45 2015 +0300 @@ -1696,6 +1696,9 @@ </property> </action> <action name="actionModeCurve"> + <property name="checkable"> + <bool>true</bool> + </property> <property name="icon"> <iconset resource="../ldforge.qrc"> <normaloff>:/icons/beziercurve.png</normaloff>:/icons/beziercurve.png</iconset>
--- a/src/miscallenous.cpp Sun Oct 04 06:59:09 2015 +0300 +++ b/src/miscallenous.cpp Sun Oct 04 13:19:45 2015 +0300 @@ -88,10 +88,13 @@ ConfigOption (int Grid = 1) ConfigOption (float GridCoarseCoordinateSnap = 5.0f) ConfigOption (float GridCoarseAngleSnap = 45.0f) +ConfigOption (float GridCoarseBezierCurveSegments = 8) ConfigOption (float GridMediumCoordinateSnap = 1.0f) ConfigOption (float GridMediumAngleSnap = 22.5f) +ConfigOption (float GridMediumBezierCurveSegments = 16) ConfigOption (float GridFineCoordinateSnap = 0.1f) ConfigOption (float GridFineAngleSnap = 7.5f) +ConfigOption (float GridFineBezierCurveSegments = 32) ConfigOption (int RotationPointType = 0) ConfigOption (Vertex CustomRotationPoint = Origin) @@ -123,6 +126,19 @@ return 45.0f; } +float gridBezierCurveSegments() +{ + ConfigurationValueBag* config = g_win->configBag(); + + switch (config->grid()) + { + default: + case Grid::Coarse: return config->gridCoarseBezierCurveSegments(); + case Grid::Medium: return config->gridMediumBezierCurveSegments(); + case Grid::Fine: return config->gridFineBezierCurveSegments(); + } +} + // ============================================================================= // // Snap the given coordinate value on the current grid's given axis.
--- a/src/miscallenous.h Sun Oct 04 06:59:09 2015 +0300 +++ b/src/miscallenous.h Sun Oct 04 13:19:45 2015 +0300 @@ -45,6 +45,7 @@ // Grid stuff float gridCoordinateSnap(); float gridAngleSnap(); +float gridBezierCurveSegments(); // ============================================================================= enum class RotationPoint
--- a/src/toolsets/algorithmtoolset.cpp Sun Oct 04 06:59:09 2015 +0300 +++ b/src/toolsets/algorithmtoolset.cpp Sun Oct 04 13:19:45 2015 +0300 @@ -283,13 +283,7 @@ ++num; } - for (LDObjectIterator<LDBezierCurve> it (selectedObjects()); it.isValid(); ++it) - { - it->replace (it->rasterize (10)); - ++num; - } - - print (tr ("Converted %1 conditional lines and Bézier curves"), num); + print (tr ("Converted %1 conditional lines"), num); } bool AlgorithmToolset::isColorUsed (LDColor color)
--- a/src/toolsets/basictoolset.cpp Sun Oct 04 06:59:09 2015 +0300 +++ b/src/toolsets/basictoolset.cpp Sun Oct 04 13:19:45 2015 +0300 @@ -29,6 +29,7 @@ #include "../ldobjectiterator.h" #include "../mainwindow.h" #include "../dialogs/colorselector.h" +#include "../miscallenous.h" #include "basictoolset.h" BasicToolset::BasicToolset (MainWindow *parent) : @@ -95,15 +96,15 @@ void BasicToolset::doInline (bool deep) { - for (LDObjectIterator<LDSubfile> it (selectedObjects()); it.isValid(); ++it) + for (LDSubfile* ref : filterByType<LDSubfile> (selectedObjects())) { // Get the index of the subfile so we know where to insert the // inlined contents. - int idx = it->lineNumber(); + int idx = ref->lineNumber(); if (idx != -1) { - LDObjectList objs = it->inlineContents (deep, false); + LDObjectList objs = ref->inlineContents (deep, false); // Merge in the inlined objects for (LDObject* inlineobj : objs) @@ -116,9 +117,12 @@ } // Delete the subfile now as it's been inlined. - it->destroy(); + ref->destroy(); } } + + for (LDBezierCurve* curve : filterByType<LDBezierCurve> (selectedObjects())) + curve->replace (curve->rasterize (gridBezierCurveSegments())); } void BasicToolset::inlineShallow()