# HG changeset patch # User Teemu Piippo # Date 1455645583 -7200 # Node ID 9450ac3cd930a25af1789ae5928a8c9dabda1f4b # Parent a7f8ce5aa8584c12243c18a66f96b39802b0b242 Split grid stuff into a new class Grid in grid.cpp/grid.h diff -r a7f8ce5aa858 -r 9450ac3cd930 CMakeLists.txt --- a/CMakeLists.txt Tue Feb 16 16:28:44 2016 +0200 +++ b/CMakeLists.txt Tue Feb 16 19:59:43 2016 +0200 @@ -43,6 +43,7 @@ src/editHistory.cpp src/glRenderer.cpp src/glCompiler.cpp + src/grid.cpp src/guiutilities.cpp src/hierarchyelement.cpp src/ldDocument.cpp @@ -96,6 +97,7 @@ src/format.h src/glCompiler.h src/glRenderer.h + src/grid.h src/guiutilities.h src/hierarchyelement.h src/ldDocument.h diff -r a7f8ce5aa858 -r 9450ac3cd930 src/dialogs/configdialog.cpp --- a/src/dialogs/configdialog.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/dialogs/configdialog.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -79,20 +79,19 @@ ui.setupUi (this); // Set defaults - applyToWidgetOptions ( - [&](QWidget* widget, QString confname) + applyToWidgetOptions([&](QWidget* widget, QString confname) { QVariant value = m_settings->value (confname, m_config->defaultValueByName (confname)); - QLineEdit* le; + QLineEdit* lineedit; QSpinBox* spinbox; QDoubleSpinBox* doublespinbox; QSlider* slider; QCheckBox* checkbox; QPushButton* button; - if ((le = qobject_cast (widget))) + if ((lineedit = qobject_cast (widget))) { - le->setText (value.toString()); + lineedit->setText (value.toString()); } else if ((spinbox = qobject_cast (widget))) { diff -r a7f8ce5aa858 -r 9450ac3cd930 src/documentloader.cpp --- a/src/documentloader.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/documentloader.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -79,7 +79,7 @@ { // Show a progress dialog if we're loading the main ldDocument.here so we can show progress updates and keep the // WM posted that we're still here. - m_progressDialog = new OpenProgressDialog (g_win); + m_progressDialog = new OpenProgressDialog(qobject_cast(parent())); m_progressDialog->setNumLines (m_lines.size()); m_progressDialog->setModal (true); m_progressDialog->show(); diff -r a7f8ce5aa858 -r 9450ac3cd930 src/editmodes/abstractEditMode.cpp --- a/src/editmodes/abstractEditMode.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/editmodes/abstractEditMode.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -29,6 +29,7 @@ #include "../mainwindow.h" #include "../glRenderer.h" #include "../miscallenous.h" +#include "../grid.h" ConfigOption (bool DrawLineLengths = true) ConfigOption (bool DrawAngles = false) @@ -291,8 +292,8 @@ renderer()->getRelativeAxes (relX, relY); QLineF ln (v0[relX], v0[relY], v1[relX], v1[relY]); ln.setAngle (intervalClamp (ln.angle(), 45)); - result.setCoordinate (relX, snapToGrid (ln.x2(), Grid::Coordinate)); - result.setCoordinate (relY, snapToGrid (ln.y2(), Grid::Coordinate)); + result.setCoordinate (relX, grid()->snap(ln.x2(), Grid::Coordinate)); + result.setCoordinate (relY, grid()->snap(ln.y2(), Grid::Coordinate)); } return result; diff -r a7f8ce5aa858 -r 9450ac3cd930 src/editmodes/circleMode.cpp --- a/src/editmodes/circleMode.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/editmodes/circleMode.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -26,6 +26,7 @@ #include "../glRenderer.h" #include "../mainwindow.h" #include "../ldObjectMath.h" +#include "../grid.h" CircleMode::CircleMode (GLRenderer* renderer) : Super (renderer) {} @@ -39,13 +40,18 @@ { if (m_drawedVerts.size() >= pos + 1) { - Vertex v1 = (m_drawedVerts.size() >= pos + 2) ? m_drawedVerts[pos + 1] : - renderer()->convert2dTo3d (renderer()->mousePosition(), false); + Vertex v1; + + if (m_drawedVerts.size() >= pos + 2) + v1 = m_drawedVerts[pos + 1]; + else + v1 = renderer()->convert2dTo3d (renderer()->mousePosition(), false); + Axis localx, localy; renderer()->getRelativeAxes (localx, localy); double dx = m_drawedVerts[0][localx] - v1[localx]; double dy = m_drawedVerts[0][localy] - v1[localy]; - return snapToGrid (sqrt ((dx * dx) + (dy * dy)), Grid::Coordinate); + return grid()->snap(hypot(dx, dy), Grid::Coordinate); } return 0.0; diff -r a7f8ce5aa858 -r 9450ac3cd930 src/glCompiler.cpp --- a/src/glCompiler.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/glCompiler.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -28,6 +28,7 @@ #include "dialogs.h" #include "guiutilities.h" #include "documentmanager.h" +#include "grid.h" struct GLErrorInfo { @@ -324,10 +325,10 @@ case OBJ_BezierCurve: { LDBezierCurve* curve = static_cast (obj); - for (LDPolygon& poly : curve->rasterizePolygons()) + for (LDPolygon& polygon : curve->rasterizePolygons(grid()->bezierCurveSegments())) { - poly.id = obj->id(); - compilePolygon (poly, obj, &info); + polygon.id = obj->id(); + compilePolygon (polygon, obj, &info); } } break; diff -r a7f8ce5aa858 -r 9450ac3cd930 src/glRenderer.cpp --- a/src/glRenderer.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/glRenderer.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -41,6 +41,7 @@ #include "glCompiler.h" #include "primitives.h" #include "documentmanager.h" +#include "grid.h" const LDFixedCamera g_FixedCameras[6] = { @@ -119,12 +120,6 @@ // GLRenderer::~GLRenderer() { - for (int i = 0; i < countof (currentDocumentData().overlays); ++i) - delete currentDocumentData().overlays[i].img; - - for (CameraIcon& info : m_cameraIcons) - delete info.image; - if (messageLog()) messageLog()->setRenderer (nullptr); @@ -552,8 +547,8 @@ if (snap) { - cx = snapToGrid (cx, Grid::Coordinate); - cy = snapToGrid (cy, Grid::Coordinate); + cx = grid()->snap(cx, Grid::Coordinate); + cy = grid()->snap(cy, Grid::Coordinate); } cx *= signX; @@ -896,9 +891,8 @@ // ============================================================================= // -void GLRenderer::leaveEvent (QEvent* ev) +void GLRenderer::leaveEvent (QEvent*) { - (void) ev; m_drawToolTip = false; m_toolTipTimer->stop(); update(); @@ -913,15 +907,15 @@ // ============================================================================= // -void GLRenderer::setCamera (const ECamera cam) +void GLRenderer::setCamera (const ECamera camera) { // The edit mode may forbid the free camera. - if (cam == EFreeCamera and not m_currentEditMode->allowFreeCamera()) - return; - - m_camera = cam; - m_config->setCamera ((int) cam); - m_window->updateEditModeActions(); + if (m_currentEditMode->allowFreeCamera() or camera != EFreeCamera) + { + m_camera = camera; + m_config->setCamera((int) camera); + m_window->updateEditModeActions(); + } } // ============================================================================= @@ -1678,3 +1672,30 @@ { return currentDocumentData().zoom[camera()]; } + + +// +// --------------------------------------------------------------------------------------------------------------------- +// + + +LDGLOverlay::LDGLOverlay() : + img(nullptr) {} + +LDGLOverlay::~LDGLOverlay() +{ + delete img; +} + + +// +// --------------------------------------------------------------------------------------------------------------------- +// + +CameraIcon::CameraIcon() : + image(nullptr) {} + +CameraIcon::~CameraIcon() +{ + delete image; +} diff -r a7f8ce5aa858 -r 9450ac3cd930 src/glRenderer.h --- a/src/glRenderer.h Tue Feb 16 16:28:44 2016 +0200 +++ b/src/glRenderer.h Tue Feb 16 19:59:43 2016 +0200 @@ -50,6 +50,9 @@ // struct LDGLOverlay { + LDGLOverlay(); + ~LDGLOverlay(); + Vertex v0, v1; int ox, @@ -116,13 +119,17 @@ MAKE_ITERABLE_ENUM (ECamera) -// + // CameraIcon::image is a heap-allocated QPixmap because otherwise it gets // initialized before program gets to main() and constructs a QApplication // and Qt doesn't like that. // +// TODO: maybe this then shouldn't get allocated before the program gets to main(). struct CameraIcon { + CameraIcon(); + ~CameraIcon(); + QPixmap* image; QRect sourceRect; QRect targetRect; diff -r a7f8ce5aa858 -r 9450ac3cd930 src/glShared.h --- a/src/glShared.h Tue Feb 16 16:28:44 2016 +0200 +++ b/src/glShared.h Tue Feb 16 19:59:43 2016 +0200 @@ -18,12 +18,11 @@ #pragma once +#include "basics.h" #ifdef USE_QT5 # include #endif -#include "basics.h" - class LDObject; struct LDPolygon diff -r a7f8ce5aa858 -r 9450ac3cd930 src/grid.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/grid.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -0,0 +1,96 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2016 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "grid.h" +#include "configuration.h" + + +ConfigOption (int Grid = 1) +ConfigOption (qreal GridCoarseCoordinateSnap = 5.0) +ConfigOption (qreal GridCoarseAngleSnap = 45.0) +ConfigOption (int GridCoarseBezierCurveSegments = 8) +ConfigOption (qreal GridMediumCoordinateSnap = 1.0) +ConfigOption (qreal GridMediumAngleSnap = 22.5) +ConfigOption (qreal GridMediumBezierCurveSegments = 16) +ConfigOption (qreal GridFineCoordinateSnap = 0.1) +ConfigOption (qreal GridFineAngleSnap = 7.5) +ConfigOption (qreal GridFineBezierCurveSegments = 32) +ConfigOption (int RotationPointType = 0) +ConfigOption (Vertex CustomRotationPoint = Origin) + + +Grid::Grid(QObject* parent) : + HierarchyElement(parent) {} + + +qreal Grid::coordinateSnap() const +{ + switch (m_config->grid()) + { + default: + case Grid::Coarse: return m_config->gridCoarseCoordinateSnap(); + case Grid::Medium: return m_config->gridMediumCoordinateSnap(); + case Grid::Fine: return m_config->gridFineCoordinateSnap(); + } +} + + +qreal Grid::angleSnap() const +{ + switch (m_config->grid()) + { + default: + case Grid::Coarse: return m_config->gridCoarseAngleSnap(); + case Grid::Medium: return m_config->gridMediumAngleSnap(); + case Grid::Fine: return m_config->gridFineAngleSnap(); + } +} + + +qreal Grid::angleAsRadians() const +{ + return (Pi * angleSnap()) / 180; +} + + +int Grid::bezierCurveSegments() const +{ + switch (m_config->grid()) + { + default: + case Grid::Coarse: return m_config->gridCoarseBezierCurveSegments(); + case Grid::Medium: return m_config->gridMediumBezierCurveSegments(); + case Grid::Fine: return m_config->gridFineBezierCurveSegments(); + } +} + + +qreal Grid::snap(qreal value, const Grid::Config type) const +{ + double snapvalue = (type == Grid::Coordinate) ? coordinateSnap() : angleSnap(); + double multiplier = floor (qAbs(value / snapvalue)); + double out = multiplier * snapvalue; + + if (qAbs (value) - (multiplier * snapvalue) > snapvalue / 2) + out += snapvalue; + + if (value < 0) + out = -out; + + return out; +} diff -r a7f8ce5aa858 -r 9450ac3cd930 src/grid.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/grid.h Tue Feb 16 19:59:43 2016 +0200 @@ -0,0 +1,46 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2016 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include "hierarchyelement.h" + +class Grid : public HierarchyElement +{ +public: + Grid(QObject* parent); + + enum Type + { + Coarse, + Medium, + Fine + }; + + enum Config + { + Coordinate, + Angle + }; + + qreal angleSnap() const; + qreal angleAsRadians() const; + int bezierCurveSegments() const; + qreal coordinateSnap() const; + qreal snap(qreal value, const Grid::Config type) const; +}; + diff -r a7f8ce5aa858 -r 9450ac3cd930 src/hierarchyelement.cpp --- a/src/hierarchyelement.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/hierarchyelement.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -23,7 +23,6 @@ #include "guiutilities.h" - HierarchyElement::HierarchyElement (QObject* parent) : m_window (nullptr) { @@ -37,9 +36,10 @@ if (m_window == nullptr) { + // Drat! It doesn't seem to have the MainWindow as a parent! We'll need to force it to be in one. + // This shouldn't have any side effects but also shouldn't happen regardless. m_window = g_win; - print ("WARNING: Hierarchy element instance %1 should be in the hierarchy of a " - "MainWindow but isn't.\n", this); + print("Hierarchy element instance %1 should be in the hierarchy of a MainWindow, but isn't.\n", this); } m_documents = m_window->documents(); @@ -47,29 +47,31 @@ } - GuiUtilities* HierarchyElement::guiUtilities() const { return m_window->guiUtilities(); } - LDDocument* HierarchyElement::currentDocument() { return m_window->currentDocument(); } - const LDObjectList& HierarchyElement::selectedObjects() { return m_window->selectedObjects(); } - PrimitiveManager* HierarchyElement::primitives() { return m_window->primitives(); } + + +Grid* HierarchyElement::grid() const +{ + return m_window->grid(); +} diff -r a7f8ce5aa858 -r 9450ac3cd930 src/hierarchyelement.h --- a/src/hierarchyelement.h Tue Feb 16 16:28:44 2016 +0200 +++ b/src/hierarchyelement.h Tue Feb 16 19:59:43 2016 +0200 @@ -26,10 +26,11 @@ class LDDocument; class DocumentManager; class PrimitiveManager; +class Grid; // -// Objects that are to take part in the MainWindow's hierarchy multiple-inherit from this class to get a few useful -// pointer members. +// Objects that are to take part in the MainWindow's hierarchy multiple-inherit from this class to get a pointer back +// to the MainWindow class along with a few useful pointers and methods. // class HierarchyElement { @@ -40,6 +41,7 @@ LDDocument* currentDocument(); GuiUtilities* guiUtilities() const; PrimitiveManager* primitives(); + Grid* grid() const; protected: MainWindow* m_window; diff -r a7f8ce5aa858 -r 9450ac3cd930 src/ldObject.cpp --- a/src/ldObject.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/ldObject.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -1107,10 +1107,7 @@ LDObjectList LDBezierCurve::rasterize (int segments) { - if (segments == 0) - segments = gridBezierCurveSegments(); - - QVector polygons = rasterizePolygons (segments); + QVector polygons = rasterizePolygons(segments); LDObjectList result; for (LDPolygon& poly : polygons) @@ -1123,11 +1120,8 @@ return result; } -QVector LDBezierCurve::rasterizePolygons (int segments) +QVector LDBezierCurve::rasterizePolygons(int segments) { - if (segments == 0) - segments = gridBezierCurveSegments(); - QVector result; QVector parms; parms.append (pointAt (0.0)); diff -r a7f8ce5aa858 -r 9450ac3cd930 src/ldObject.h --- a/src/ldObject.h Tue Feb 16 16:28:44 2016 +0200 +++ b/src/ldObject.h Tue Feb 16 19:59:43 2016 +0200 @@ -465,8 +465,8 @@ LDBezierCurve (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); Vertex pointAt (qreal t) const; - LDObjectList rasterize (int segments = 0); - QVector rasterizePolygons (int segments = 0); + LDObjectList rasterize (int segments); + QVector rasterizePolygons (int segments); }; // Other common LDraw stuff diff -r a7f8ce5aa858 -r 9450ac3cd930 src/mainwindow.cpp --- a/src/mainwindow.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/mainwindow.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -56,6 +56,7 @@ #include "glCompiler.h" #include "documentmanager.h" #include "ldobjectiterator.h" +#include "grid.h" ConfigOption (bool ColorizeObjectsList = true) ConfigOption (QString QuickColorToolbar = "4:25:14:27:2:3:11:1:22:|:0:72:71:15") @@ -69,6 +70,7 @@ m_config(config), m_guiUtilities (new GuiUtilities (this)), m_primitives(new PrimitiveManager(this)), + m_grid(new Grid(this)), ui (*new Ui_MainWindow), m_externalPrograms (nullptr), m_settings (makeSettings (this)), @@ -881,7 +883,10 @@ // ============================================================================ void ObjectList::contextMenuEvent (QContextMenuEvent* ev) { - g_win->spawnContextMenu (ev->globalPos()); + MainWindow* mainWindow = qobject_cast(parent()); + + if (mainWindow) + mainWindow->spawnContextMenu (ev->globalPos()); } // --------------------------------------------------------------------------------------------------------------------- @@ -1329,6 +1334,11 @@ return &m_config; } +Grid* MainWindow::grid() +{ + return m_grid; +} + // --------------------------------------------------------------------------------------------------------------------- // ColorToolbarItem::ColorToolbarItem (LDColor color, QToolButton* toolButton) : diff -r a7f8ce5aa858 -r 9450ac3cd930 src/mainwindow.h --- a/src/mainwindow.h Tue Feb 16 16:28:44 2016 +0200 +++ b/src/mainwindow.h Tue Feb 16 19:59:43 2016 +0200 @@ -38,6 +38,7 @@ class Toolset; class Configuration; class PrimitiveManager; +class Grid; class ColorToolbarItem { @@ -94,6 +95,7 @@ QTreeWidget* getPrimitivesTree() const; class QSettings* getSettings() { return m_settings; } LDColor getUniformSelectedColor(); + Grid* grid(); class GuiUtilities* guiUtilities(); void loadShortcuts(); LDDocument* newDocument (bool cache = false); @@ -140,6 +142,7 @@ class GuiUtilities* m_guiUtilities; GLRenderer* m_renderer; PrimitiveManager* m_primitives; + Grid* m_grid; LDObjectList m_sel; QList m_quickColors; QList m_colorButtons; diff -r a7f8ce5aa858 -r 9450ac3cd930 src/miscallenous.cpp --- a/src/miscallenous.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/miscallenous.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -24,72 +24,6 @@ #include "mainwindow.h" #include "dialogs.h" #include "ldDocument.h" -#include "ui_rotpoint.h" - -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) - - -float gridCoordinateSnap() -{ - switch (Config->grid()) - { - default: - case Grid::Coarse: return Config->gridCoarseCoordinateSnap(); - case Grid::Medium: return Config->gridMediumCoordinateSnap(); - case Grid::Fine: return Config->gridFineCoordinateSnap(); - } -} - - -float gridAngleSnap() -{ - switch (Config->grid()) - { - default: - case Grid::Coarse: return Config->gridCoarseAngleSnap(); - case Grid::Medium: return Config->gridMediumAngleSnap(); - case Grid::Fine: return Config->gridFineAngleSnap(); - } -} - - -float gridBezierCurveSegments() -{ - switch (Config->grid()) - { - default: - case Grid::Coarse: return Config->gridCoarseBezierCurveSegments(); - case Grid::Medium: return Config->gridMediumBezierCurveSegments(); - case Grid::Fine: return Config->gridFineBezierCurveSegments(); - } -} - -// Snaps the given coordinate value on the current grid's given axis. -double snapToGrid (double value, const Grid::Config type) -{ - double snapvalue = (type == Grid::Coordinate) ? gridCoordinateSnap() : gridAngleSnap(); - double mult = floor (qAbs (value / snapvalue)); - double out = mult * snapvalue; - - if (qAbs (value) - (mult * snapvalue) > snapvalue / 2) - out += snapvalue; - - if (value < 0) - out = -out; - - return out; -} int gcd (int a, int b) @@ -147,50 +81,6 @@ } -void configureRotationPoint() -{ - QDialog* dlg = new QDialog; - Ui::RotPointUI ui; - ui.setupUi (dlg); - - switch (RotationPoint (Config->rotationPointType())) - { - case RotationPoint::ObjectOrigin: - ui.objectPoint->setChecked (true); - break; - - case RotationPoint::WorldOrigin: - ui.worldPoint->setChecked (true); - break; - - case RotationPoint::CustomPoint: - ui.customPoint->setChecked (true); - break; - - case RotationPoint::NumValues: - break; - } - - Vertex custompoint = Config->customRotationPoint(); - ui.customX->setValue (custompoint.x()); - ui.customY->setValue (custompoint.y()); - ui.customZ->setValue (custompoint.z()); - - if (not dlg->exec()) - return; - - Config->setRotationPointType (int ( - (ui.objectPoint->isChecked()) ? RotationPoint::ObjectOrigin : - (ui.worldPoint->isChecked()) ? RotationPoint::WorldOrigin : - RotationPoint::CustomPoint)); - - custompoint.setX (ui.customX->value()); - custompoint.setY (ui.customY->value()); - custompoint.setZ (ui.customZ->value()); - Config->setCustomRotationPoint (custompoint); -} - - QString joinStrings (QList vals, QString delim) { QStringList list; diff -r a7f8ce5aa858 -r 9450ac3cd930 src/miscallenous.h --- a/src/miscallenous.h Tue Feb 16 16:28:44 2016 +0200 +++ b/src/miscallenous.h Tue Feb 16 19:59:43 2016 +0200 @@ -37,32 +37,12 @@ NumValues }; -namespace Grid -{ - enum Type - { - Coarse, - Medium, - Fine - }; - - enum Config - { - Coordinate, - Angle - }; -} - void applyToMatrix (Matrix& a, ApplyToMatrixFunction func); void applyToMatrix (const Matrix& a, ApplyToMatrixConstFunction func); void configureRotationPoint(); QString formatFileSize (qint64 size); int gcd (int a, int b); Vertex getRotationPoint (const LDObjectList& objs); -float gridAngleSnap(); -float gridBezierCurveSegments(); -float gridCoordinateSnap(); QString joinStrings (QList vals, QString delim = " "); void roundToDecimals (double& a, int decimals); void simplify (int& numer, int& denom); -double snapToGrid (double value, const Grid::Config type); diff -r a7f8ce5aa858 -r 9450ac3cd930 src/toolsets/basictoolset.cpp --- a/src/toolsets/basictoolset.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/toolsets/basictoolset.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -29,6 +29,7 @@ #include "../ldobjectiterator.h" #include "../mainwindow.h" #include "../dialogs/colorselector.h" +#include "../grid.h" #include "basictoolset.h" BasicToolset::BasicToolset (MainWindow *parent) : @@ -121,7 +122,7 @@ } for (LDBezierCurve* curve : filterByType (selectedObjects())) - curve->replace (curve->rasterize()); + curve->replace (curve->rasterize(grid()->bezierCurveSegments())); } void BasicToolset::inlineShallow() diff -r a7f8ce5aa858 -r 9450ac3cd930 src/toolsets/extprogramtoolset.cpp --- a/src/toolsets/extprogramtoolset.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/toolsets/extprogramtoolset.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -35,6 +35,7 @@ #include "../editHistory.h" #include "../dialogs.h" #include "../documentmanager.h" +#include "../grid.h" #include "extprogramtoolset.h" #include "ui_ytruder.h" #include "ui_intersector.h" @@ -178,7 +179,7 @@ else if (obj->type() == OBJ_BezierCurve) { LDBezierCurve* curve = static_cast (obj); - LDObjectList objs = curve->rasterize(); + LDObjectList objs = curve->rasterize(grid()->bezierCurveSegments()); writeObjects (objs, f); for (LDObject* obj : objs) diff -r a7f8ce5aa858 -r 9450ac3cd930 src/toolsets/movetoolset.cpp --- a/src/toolsets/movetoolset.cpp Tue Feb 16 16:28:44 2016 +0200 +++ b/src/toolsets/movetoolset.cpp Tue Feb 16 19:59:43 2016 +0200 @@ -21,6 +21,8 @@ #include "../miscallenous.h" #include "../mainwindow.h" #include "movetoolset.h" +#include "ui_rotpoint.h" +#include "../grid.h" MoveToolset::MoveToolset (MainWindow* parent) : Toolset (parent) {} @@ -63,7 +65,7 @@ void MoveToolset::moveObjects (Vertex vect) { // Apply the grid values - vect *= gridCoordinateSnap(); + vect *= grid()->coordinateSnap(); for (LDObject* obj : selectedObjects()) obj->move (vect); @@ -101,7 +103,7 @@ double MoveToolset::getRotateActionAngle() { - return (Pi * gridAngleSnap()) / 180; + return (Pi * grid()->angleSnap()) / 180; } void MoveToolset::rotateXPos() @@ -136,5 +138,48 @@ void MoveToolset::configureRotationPoint() { - configureRotationPoint(); + QDialog* dialog = new QDialog; + Ui_RotPointUI ui; + ui.setupUi(dialog); + + switch (RotationPoint(m_config->rotationPointType())) + { + case RotationPoint::ObjectOrigin: + ui.objectPoint->setChecked (true); + break; + + case RotationPoint::WorldOrigin: + ui.worldPoint->setChecked (true); + break; + + case RotationPoint::CustomPoint: + ui.customPoint->setChecked (true); + break; + + case RotationPoint::NumValues: + break; + } + + Vertex custompoint = m_config->customRotationPoint(); + ui.customX->setValue(custompoint.x()); + ui.customY->setValue(custompoint.y()); + ui.customZ->setValue(custompoint.z()); + + if (dialog->exec() == QDialog::Accepted) + { + RotationPoint pointType; + + if (ui.objectPoint->isChecked()) + pointType = RotationPoint::ObjectOrigin; + else if (ui.objectPoint->isChecked()) + pointType = RotationPoint::WorldOrigin; + else + pointType = RotationPoint::CustomPoint; + + custompoint.setX (ui.customX->value()); + custompoint.setY (ui.customY->value()); + custompoint.setZ (ui.customZ->value()); + m_config->setRotationPointType((int) pointType); + m_config->setCustomRotationPoint (custompoint); + } } \ No newline at end of file