# HG changeset patch # User Santeri Piippo # Date 1398709884 -10800 # Node ID c37564d59ce10d6ef291f7b742d2dfd27e821835 # Parent 0379f6fca732b1bf6e33f333ea74770d3fa80cfa - grids now have a single coordinate snap value instead of individual X, Y and Z values diff -r 0379f6fca732 -r c37564d59ce1 src/actionsEdit.cc --- a/src/actionsEdit.cc Mon Apr 28 18:27:02 2014 +0300 +++ b/src/actionsEdit.cc Mon Apr 28 21:31:24 2014 +0300 @@ -364,9 +364,7 @@ void doMoveObjects (Vertex vect) { // Apply the grid values - vect.setX (vect.x() * *currentGrid().confs[Grid::X]); - vect.setY (vect.y() * *currentGrid().confs[Grid::Y]); - vect.setZ (vect.z() * *currentGrid().confs[Grid::Z]); + vect *= *currentGrid().coordsnap; for (LDObject* obj : selection()) obj->move (vect); @@ -378,7 +376,7 @@ // DEFINE_ACTION (MoveXNeg, KEY (Left)) { - doMoveObjects ({ -1, 0, 0}); + doMoveObjects ({-1, 0, 0}); } DEFINE_ACTION (MoveYNeg, KEY (Home)) @@ -434,7 +432,7 @@ LDObjectList sel = selection(); QList queue; const Vertex rotpoint = rotPoint (sel); - const double angle = (pi * *currentGrid().confs[Grid::Angle]) / 180, + const double angle = (pi * *currentGrid().anglesnap) / 180, cosangle = cos (angle), sinangle = sin (angle); diff -r 0379f6fca732 -r c37564d59ce1 src/configDialog.cc --- a/src/configDialog.cc Mon Apr 28 18:27:02 2014 +0300 +++ b/src/configDialog.cc Mon Apr 28 21:31:24 2014 +0300 @@ -202,26 +202,28 @@ void ConfigDialog::initGrids() { QGridLayout* gridlayout = new QGridLayout; - QLabel* xlabel = new QLabel ("X"), - *ylabel = new QLabel ("Y"), - *zlabel = new QLabel ("Z"), - *anglabel = new QLabel ("Angle"); + QLabel* coordlabel = new QLabel ("Coordinate"); + QLabel* anglelabel = new QLabel ("Angle"); int i = 1; - for (QLabel* label : QList ({xlabel, ylabel, zlabel, anglabel})) + for (QLabel* label : QList ({coordlabel, anglelabel})) { label->setAlignment (Qt::AlignCenter); gridlayout->addWidget (label, 0, i++); } - for (int i = 0; i < g_NumGrids; ++i) + gridlayout->setColumnStretch (0, 0); + gridlayout->setColumnStretch (1, 1); + gridlayout->setColumnStretch (2, 1); + + for (int i = 0; i < g_numGrids; ++i) { // Icon lb_gridIcons[i] = new QLabel; - lb_gridIcons[i]->setPixmap (getIcon (format ("grid-%1", String (g_GridInfo[i].name).toLower()))); + lb_gridIcons[i]->setPixmap (getIcon (format ("grid-%1", String (g_gridInfo[i].name).toLower()))); // Text label - lb_gridLabels[i] = new QLabel (format ("%1:", g_GridInfo[i].name)); + lb_gridLabels[i] = new QLabel (format ("%1:", g_gridInfo[i].name)); QHBoxLayout* labellayout = new QHBoxLayout; labellayout->addWidget (lb_gridIcons[i]); @@ -229,17 +231,17 @@ gridlayout->addLayout (labellayout, i + 1, 0); // Add the widgets - for (int j = 0; j < 4; ++j) + for (int j = 0; j < 2; ++j) { dsb_gridData[i][j] = new QDoubleSpinBox; - - // Set the maximum angle - if (j == 3) - dsb_gridData[i][j]->setMaximum (360); - - dsb_gridData[i][j]->setValue (*g_GridInfo[i].confs[j]); gridlayout->addWidget (dsb_gridData[i][j], i + 1, j + 1); } + + // Fill in defaults and stuff + dsb_gridData[i][0]->setValue (*g_gridInfo[i].coordsnap); + dsb_gridData[i][1]->setValue (*g_gridInfo[i].anglesnap); + dsb_gridData[i][1]->setMaximum (360); + dsb_gridData[i][1]->setSuffix (UTF16 (u"\u00B0")); // degree symbol } ui->grids->setLayout (gridlayout); @@ -342,9 +344,11 @@ gui_colortoolbar = quickColorString(); // Set the grid settings - for (int i = 0; i < g_NumGrids; ++i) - for (int j = 0; j < 4; ++j) - *g_GridInfo[i].confs[j] = dsb_gridData[i][j]->value(); + for (int i = 0; i < g_numGrids; ++i) + { + *g_gridInfo[i].coordsnap = dsb_gridData[i][0]->value(); + *g_gridInfo[i].anglesnap = dsb_gridData[i][1]->value(); + } // Apply key shortcuts g_win->updateActionShortcuts(); diff -r 0379f6fca732 -r c37564d59ce1 src/configDialog.h --- a/src/configDialog.h Mon Apr 28 18:27:02 2014 +0300 +++ b/src/configDialog.h Mon Apr 28 21:31:24 2014 +0300 @@ -57,7 +57,7 @@ float getGridValue (int i, int j) const; QList quickColors; - QDoubleSpinBox* dsb_gridData[3][4]; + QDoubleSpinBox* dsb_gridData[3][2]; private: Ui_ConfigUI* ui; diff -r 0379f6fca732 -r c37564d59ce1 src/glRenderer.cc --- a/src/glRenderer.cc Mon Apr 28 18:27:02 2014 +0300 +++ b/src/glRenderer.cc Mon Apr 28 21:31:24 2014 +0300 @@ -528,8 +528,8 @@ if (snap) { - cx = Grid::snap (cx, (Grid::Config) axisX); - cy = Grid::snap (cy, (Grid::Config) axisY); + cx = Grid::snap (cx, Grid::Coordinate); + cy = Grid::snap (cy, Grid::Coordinate); } cx *= negXFac; diff -r 0379f6fca732 -r c37564d59ce1 src/macros.h --- a/src/macros.h Mon Apr 28 18:27:02 2014 +0300 +++ b/src/macros.h Mon Apr 28 21:31:24 2014 +0300 @@ -64,6 +64,8 @@ // #define elif(A) else if (A) +#define UTF16(A) (QString::fromUtf16 (reinterpret_cast (A))) + // ============================================================================= // #ifdef WIN32 @@ -99,6 +101,10 @@ # define assert(N) {} #endif // DEBUG +#ifdef foreach +# undef foreach +#endif + #define for_axes(AX) for (const Axis AX : std::initializer_list ({X, Y, Z})) // ============================================================================= diff -r 0379f6fca732 -r c37564d59ce1 src/miscallenous.cc --- a/src/miscallenous.cc Mon Apr 28 18:27:02 2014 +0300 +++ b/src/miscallenous.cc Mon Apr 28 21:31:24 2014 +0300 @@ -103,44 +103,37 @@ // Grid stuff // cfg (Int, grid, Grid::Medium); -cfg (Float, grid_coarse_x, 5.0f); -cfg (Float, grid_coarse_y, 5.0f); -cfg (Float, grid_coarse_z, 5.0f); +cfg (Float, grid_coarse_snap, 5.0f); cfg (Float, grid_coarse_angle, 45.0f); -cfg (Float, grid_medium_x, 1.0f); -cfg (Float, grid_medium_y, 1.0f); -cfg (Float, grid_medium_z, 1.0f); +cfg (Float, grid_medium_snap, 1.0f); cfg (Float, grid_medium_angle, 22.5f); -cfg (Float, grid_fine_x, 0.1f); -cfg (Float, grid_fine_y, 0.1f); -cfg (Float, grid_fine_z, 0.1f); +cfg (Float, grid_fine_snap, 0.1f); cfg (Float, grid_fine_angle, 7.5f); cfg (Int, edit_rotpoint, 0); cfg (Vertex, edit_customrotpoint, g_origin); -const gridinfo g_GridInfo[3] = +const gridinfo g_gridInfo[3] = { - { "Coarse", { &grid_coarse_x, &grid_coarse_y, &grid_coarse_z, &grid_coarse_angle }}, - { "Medium", { &grid_medium_x, &grid_medium_y, &grid_medium_z, &grid_medium_angle }}, - { "Fine", { &grid_fine_x, &grid_fine_y, &grid_fine_z, &grid_fine_angle }} + { "Coarse", &grid_coarse_snap, &grid_coarse_angle }, + { "Medium", &grid_medium_snap, &grid_medium_angle }, + { "Fine", &grid_fine_snap, &grid_fine_angle }, }; // ============================================================================= // // Snap the given coordinate value on the current grid's given axis. // -double Grid::snap (double in, const Grid::Config axis) +double Grid::snap (double value, const Grid::Config type) { - const double gridval = *currentGrid().confs[axis]; - const long mult = abs (in / gridval); - const bool neg = (in < 0); - double out = mult * gridval; + double snapvalue = (type == Coordinate) ? *currentGrid().coordsnap : *currentGrid().anglesnap; + double mult = floor (abs (value / snapvalue)); + double out = mult * snapvalue; - if (abs (in) - (mult * gridval) > gridval / 2) - out += gridval; + if (abs (value) - (mult * snapvalue) > snapvalue / 2) + out += snapvalue; - if (neg && out != 0) - out *= -1; + if (value < 0 && out != 0) + out = -out; return out; } diff -r 0379f6fca732 -r c37564d59ce1 src/miscallenous.h --- a/src/miscallenous.h Mon Apr 28 18:27:02 2014 +0300 +++ b/src/miscallenous.h Mon Apr 28 21:31:24 2014 +0300 @@ -51,17 +51,18 @@ // Grid stuff struct gridinfo { - const char* const name; - float* const confs[4]; + const char* const name; + Config::FloatType* const coordsnap; + Config::FloatType* const anglesnap; }; extern_cfg (Int, grid); -static const int g_NumGrids = 3; -extern const gridinfo g_GridInfo[3]; +static const int g_numGrids = 3; +extern const gridinfo g_gridInfo[3]; inline const gridinfo& currentGrid() { - return g_GridInfo[grid]; + return g_gridInfo[grid]; } // ============================================================================= @@ -87,13 +88,11 @@ enum Config { - X, - Y, - Z, + Coordinate, Angle }; - double snap (double value, const Grid::Config axis); + double snap (double value, const Grid::Config type); } // =============================================================================