Mon, 06 Mar 2017 00:55:45 +0200
Grid is now a namespace.
--- a/src/canvas.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/canvas.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -98,11 +98,11 @@ // Find the top left corner of the grid Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0})); Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()})); - qreal gridSize = grid()->coordinateSnap(); + qreal gridSize = Grid::coordinateSnap(); glEnable(GL_LINE_STIPPLE); glBegin(GL_LINES); - switch (grid()->type()) + switch (Grid::type()) { case Grid::Cartesian: { @@ -148,8 +148,8 @@ case Grid::Polar: { - const QPointF pole = grid()->pole(); - const qreal size = grid()->coordinateSnap(); + const QPointF pole = Grid::pole(); + const qreal size = Grid::coordinateSnap(); Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0})); Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()})); QPointF topLeft2d {topLeft.x(), topLeft.y()}; @@ -171,9 +171,9 @@ glColor4f(0, 0, 0, 0.25); // Render the axes - for (int i = 0; i < grid()->polarDivisions() / 2; ++i) + for (int i = 0; i < Grid::polarDivisions() / 2; ++i) { - qreal azimuth = (2.0 * pi) * i / grid()->polarDivisions(); + qreal azimuth = (2.0 * pi) * i / Grid::polarDivisions(); if (not poleIsOrigin or not isZero(fmod(azimuth, pi / 2))) { @@ -191,17 +191,17 @@ { Vertex points[48]; - for (int i = 0; i < grid()->polarDivisions(); ++i) + for (int i = 0; i < Grid::polarDivisions(); ++i) { - qreal azimuth = (2.0 * pi) * i / grid()->polarDivisions(); + qreal azimuth = (2.0 * pi) * i / Grid::polarDivisions(); QPointF point = pole + QPointF {radius * cos(azimuth), radius * sin(azimuth)}; points[i] = currentCamera().realize({point.x(), point.y(), 999}); } - for (int i = 0; i < grid()->polarDivisions(); ++i) + for (int i = 0; i < Grid::polarDivisions(); ++i) { glVertex(points[i]); - glVertex(ring(points, grid()->polarDivisions())[i + 1]); + glVertex(ring(points, Grid::polarDivisions())[i + 1]); } } } @@ -274,7 +274,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) { // Calculate 3d position of the cursor - m_position3D = currentCamera().convert2dTo3d(mousePosition(), grid()); + m_position3D = currentCamera().convert2dTo3d(mousePosition(), true); if (not m_currentEditMode->mouseMoved(event)) GLRenderer::mouseMoveEvent(event);
--- a/src/editmodes/abstractEditMode.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/editmodes/abstractEditMode.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -311,7 +311,7 @@ renderer()->getRelativeAxes(relativeX, relativeY); QLineF line = {vertex0[relativeX], vertex0[relativeY], vertex1[relativeX], vertex1[relativeY]}; line.setAngle(roundToInterval<int>(line.angle(), 45)); - QPointF point = grid()->snap(line.p2()); + QPointF point = Grid::snap(line.p2()); result.setCoordinate(relativeX, point.x()); result.setCoordinate(relativeY, point.y()); }
--- a/src/editmodes/circleMode.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/editmodes/circleMode.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -50,13 +50,13 @@ if (countof(m_drawedVerts) >= position + 2) v1 = m_drawedVerts[position + 1]; else - v1 = renderer()->currentCamera().convert2dTo3d(renderer()->mousePosition(), grid()); + v1 = renderer()->currentCamera().convert2dTo3d(renderer()->mousePosition(), true); Axis localx, localy; renderer()->getRelativeAxes(localx, localy); double dx = m_drawedVerts[0][localx] - v1[localx]; double dy = m_drawedVerts[0][localy] - v1[localy]; - return grid()->snap({hypot(dx, dy), 0}).x(); + return Grid::snap({hypot(dx, dy), 0}).x(); } return 0.0;
--- a/src/glcamera.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/glcamera.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -88,7 +88,7 @@ /* * This converts a 2D point on the screen to a 3D point in the model. If 'snap' is true, the 3D point will snap to the current grid. */ -Vertex GLCamera::convert2dTo3d(const QPoint& position2d, Grid* grid) const +Vertex GLCamera::convert2dTo3d(const QPoint& position2d, bool snapToGrid) const { if (m_isFree) { @@ -105,9 +105,9 @@ double cy = m_virtualSize.height() - (2 * position2d.y() * m_virtualSize.height() / m_size.height()) - m_panningY; // If a grid was passed, snap coordinates to it. - if (grid) + if (snapToGrid) { - QPointF snapped = grid->snap({cx, cy}); + QPointF snapped = Grid::snap({cx, cy}); cx = snapped.x(); cy = snapped.y(); }
--- a/src/glcamera.h Mon Mar 06 00:43:43 2017 +0200 +++ b/src/glcamera.h Mon Mar 06 00:55:45 2017 +0200 @@ -48,7 +48,7 @@ Axis axisX() const; Axis axisY() const; Axis axisZ() const; - Vertex convert2dTo3d(const QPoint& pos2d, class Grid* grid = nullptr) const; + Vertex convert2dTo3d(const QPoint& pos2d, bool snapToGrid = false) const; QPoint convert3dTo2d(const Vertex& pos3d) const; Vertex realize(const Vertex& idealCoordinates) const; Vertex idealize(const Vertex& realCoordinates) const;
--- a/src/glcompiler.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/glcompiler.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -355,7 +355,7 @@ case LDObjectType::BezierCurve: { LDBezierCurve* curve = static_cast<LDBezierCurve*>(object); - for (LDPolygon& polygon : curve->rasterizePolygons(grid()->bezierCurveSegments())) + for (LDPolygon& polygon : curve->rasterizePolygons(Grid::bezierCurveSegments())) { polygon.id = object->id(); compilePolygon (polygon, object, info);
--- a/src/grid.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/grid.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -19,7 +19,7 @@ #include "grid.h" #include "linetypes/modelobject.h" -qreal Grid::coordinateSnap() const +qreal Grid::coordinateSnap() { switch (configuration().grid()) { @@ -31,7 +31,7 @@ } -qreal Grid::angleSnap() const +qreal Grid::angleSnap() { switch (configuration().grid()) { @@ -43,13 +43,13 @@ } -qreal Grid::angleAsRadians() const +qreal Grid::angleAsRadians() { return (pi * angleSnap()) / 180; } -int Grid::bezierCurveSegments() const +int Grid::bezierCurveSegments() { switch (configuration().grid()) { @@ -61,7 +61,7 @@ } -QPointF Grid::snap(QPointF point) const +QPointF Grid::snap(QPointF point) { switch (type()) { @@ -90,7 +90,7 @@ /* * Returns the pole of the grid, in ideal X/Y co-ordinates. Z is left up for the caller to decide. */ -QPointF Grid::pole() const +QPointF Grid::pole() { return {0, 0}; } @@ -98,7 +98,7 @@ /* * Returns the amount of divisions (slices) to be used in the polar grid. */ -int Grid::polarDivisions() const +int Grid::polarDivisions() { switch (configuration().grid()) { @@ -115,7 +115,7 @@ /* * Returns whether to use a cartesian or polar grid. */ -Grid::Type Grid::type() const +Grid::Type Grid::type() { return configuration().polarGrid() ? Polar : Cartesian; }
--- a/src/grid.h Mon Mar 06 00:43:43 2017 +0200 +++ b/src/grid.h Mon Mar 06 00:55:45 2017 +0200 @@ -19,9 +19,8 @@ #pragma once #include "main.h" -class Grid +namespace Grid { -public: enum Size { Coarse, @@ -41,13 +40,12 @@ Polar }; - qreal angleSnap() const; - qreal angleAsRadians() const; - int bezierCurveSegments() const; - qreal coordinateSnap() const; - QPointF pole() const; - int polarDivisions() const; - QPointF snap(QPointF point) const; - Type type() const; -}; - + qreal angleSnap(); + qreal angleAsRadians(); + int bezierCurveSegments(); + qreal coordinateSnap(); + QPointF pole(); + int polarDivisions(); + QPointF snap(QPointF point); + Type type(); +}
--- a/src/hierarchyelement.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/hierarchyelement.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -61,9 +61,3 @@ { return m_window->primitives(); } - - -Grid* HierarchyElement::grid() const -{ - return m_window->grid(); -}
--- a/src/hierarchyelement.h Mon Mar 06 00:43:43 2017 +0200 +++ b/src/hierarchyelement.h Mon Mar 06 00:55:45 2017 +0200 @@ -26,7 +26,6 @@ class LDDocument; class DocumentManager; class PrimitiveManager; -class Grid; class MainWindow; // @@ -41,7 +40,6 @@ const QSet<LDObject*>& selectedObjects(); LDDocument* currentDocument(); PrimitiveManager* primitives(); - Grid* grid() const; // Format and print the given args to the message log. template<typename... Args>
--- a/src/mainwindow.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/mainwindow.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -51,8 +51,7 @@ // MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) : QMainWindow (parent, flags), - m_primitives(new PrimitiveManager(this)), - m_grid(new Grid), + m_primitives(new PrimitiveManager(this)), ui (*new Ui_MainWindow), m_externalPrograms (nullptr), m_settings (makeSettings (this)), @@ -167,7 +166,6 @@ MainWindow::~MainWindow() { delete m_primitives; - delete m_grid; delete &ui; delete m_settings; @@ -266,7 +264,7 @@ ui.actionGridCoarse->setChecked (grid == Grid::Coarse); ui.actionGridMedium->setChecked (grid == Grid::Medium); ui.actionGridFine->setChecked (grid == Grid::Fine); - ui.actionPolarGrid->setChecked(m_grid->type() == Grid::Polar); + ui.actionPolarGrid->setChecked(Grid::type() == Grid::Polar); emit gridChanged(); } @@ -1217,11 +1215,6 @@ return m_externalPrograms; } -Grid* MainWindow::grid() -{ - return m_grid; -} - // --------------------------------------------------------------------------------------------------------------------- // ColorToolbarItem::ColorToolbarItem (LDColor color, QToolButton* toolButton) :
--- a/src/mainwindow.h Mon Mar 06 00:43:43 2017 +0200 +++ b/src/mainwindow.h Mon Mar 06 00:55:45 2017 +0200 @@ -35,7 +35,6 @@ class Toolset; class Configuration; class PrimitiveManager; -class Grid; class DocumentManager; class LDDocument; @@ -85,7 +84,6 @@ class QSettings* getSettings() { return m_settings; } LDColor getUniformSelectedColor(); Canvas* getRendererForDocument(LDDocument* document); - Grid* grid(); void loadShortcuts(); MessageManager* messageLog() const; LDDocument* newDocument (bool cache = false); @@ -146,7 +144,6 @@ MessageManager* m_messageLog = nullptr; QMap<LDDocument*, Canvas*> m_renderers; PrimitiveManager* m_primitives; - Grid* m_grid; QVector<LDObject*> m_sel; QVector<ColorToolbarItem> m_quickColors; QList<QToolButton*> m_colorButtons;
--- a/src/toolsets/basictoolset.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/toolsets/basictoolset.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -117,7 +117,7 @@ for (LDBezierCurve* curve : filterByType<LDBezierCurve> (selectedObjects())) { Model curveModel {m_documents}; - curve->rasterize(curveModel, grid()->bezierCurveSegments()); + curve->rasterize(curveModel, Grid::bezierCurveSegments()); currentDocument()->replace(curve, curveModel); } }
--- a/src/toolsets/extprogramtoolset.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/toolsets/extprogramtoolset.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -163,7 +163,7 @@ { LDBezierCurve* curve = static_cast<LDBezierCurve*> (obj); Model model {m_documents}; - curve->rasterize(model, grid()->bezierCurveSegments()); + curve->rasterize(model, Grid::bezierCurveSegments()); writeObjects(model.objects().toQVector(), f); } else
--- a/src/toolsets/movetoolset.cpp Mon Mar 06 00:43:43 2017 +0200 +++ b/src/toolsets/movetoolset.cpp Mon Mar 06 00:55:45 2017 +0200 @@ -103,7 +103,7 @@ void MoveToolset::moveObjects (Vertex vect) { // Apply the grid values - vect *= grid()->coordinateSnap(); + vect *= Grid::coordinateSnap(); for (LDObject* obj : selectedObjects()) obj->move (vect); @@ -141,7 +141,7 @@ double MoveToolset::getRotateActionAngle() { - return (pi * grid()->angleSnap()) / 180; + return (pi * Grid::angleSnap()) / 180; } void MoveToolset::rotateXPos()