# HG changeset patch # User Teemu Piippo # Date 1443953985 -10800 # Node ID a88cf5a322466573de5f04ac235b12405cf02c70 # Parent ba420043717978ece1155596d7e7c448dc3c4897 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. diff -r ba4200437179 -r a88cf5a32246 CMakeLists.txt --- 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 diff -r ba4200437179 -r a88cf5a32246 src/dialogs/configdialog.ui --- 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 @@ 0 0 - 668 + 792 408 @@ -743,6 +743,19 @@ + + + + LDU + + + 5 + + + 10000.000000000000000 + + + @@ -800,6 +813,13 @@ + + + + Medium + + + @@ -823,13 +843,6 @@ - - - - Medium - - - @@ -856,6 +869,13 @@ + + + + Fine + + + @@ -866,26 +886,6 @@ - - - - Fine - - - - - - - LDU - - - 5 - - - 10000.000000000000000 - - - @@ -899,7 +899,7 @@ - + Qt::Horizontal @@ -912,6 +912,43 @@ + + + + Bézier curve segments + + + + + + + 1 + + + 1000 + + + + + + + 1 + + + 1000 + + + + + + + 1 + + + 10000 + + + diff -r ba4200437179 -r a88cf5a32246 src/glCompiler.cpp --- 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 (obj); - for (LDPolygon& poly : curve->rasterizePolygons (24)) + for (LDPolygon& poly : curve->rasterizePolygons (gridBezierCurveSegments())) { poly.id = obj->id(); compilePolygon (poly, obj, &info); diff -r ba4200437179 -r a88cf5a32246 src/ldobjectiterator.h --- 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 (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 +QVector filterByType (const R& stuff) +{ + QVector result; + + for (LDObjectIterator it (stuff); it.isValid(); ++it) + result << it; + + return result; +} diff -r ba4200437179 -r a88cf5a32246 src/mainwindow.cpp --- 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 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); } // --------------------------------------------------------------------------------------------------------------------- diff -r ba4200437179 -r a88cf5a32246 src/mainwindow.ui --- 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 @@ + + true + :/icons/beziercurve.png:/icons/beziercurve.png diff -r ba4200437179 -r a88cf5a32246 src/miscallenous.cpp --- 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. diff -r ba4200437179 -r a88cf5a32246 src/miscallenous.h --- 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 diff -r ba4200437179 -r a88cf5a32246 src/toolsets/algorithmtoolset.cpp --- 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 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) diff -r ba4200437179 -r a88cf5a32246 src/toolsets/basictoolset.cpp --- 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 it (selectedObjects()); it.isValid(); ++it) + for (LDSubfile* ref : filterByType (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 (selectedObjects())) + curve->replace (curve->rasterize (gridBezierCurveSegments())); } void BasicToolset::inlineShallow()