Mon, 27 May 2013 22:05:10 +0300
Fixed behavior of mid-button vertex selector, add ability to all-replace and relative moving to replace coords
changelog.txt | file | annotate | diff | comparison | revisions | |
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs.h | file | annotate | diff | comparison | revisions | |
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/gldraw.h | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions |
--- a/changelog.txt Mon May 27 18:17:21 2013 +0300 +++ b/changelog.txt Mon May 27 22:05:10 2013 +0300 @@ -9,4 +9,5 @@ button from the LDraw path config dialog, it's no longer needed. - Fixed: Coordinates weren't drawn properly on a bright background (was always drawn in bright colors..). - Parts are now zoomed to fit properly -- Added ability to snap to pre-existing vertices while drawing. \ No newline at end of file +- Added ability to snap to pre-existing vertices while drawing. +- Replace coords: allow replacing all coords regardless of original value, plus relative moving (offset) \ No newline at end of file
--- a/src/dialogs.cpp Mon May 27 18:17:21 2013 +0300 +++ b/src/dialogs.cpp Mon May 27 22:05:10 2013 +0300 @@ -26,6 +26,7 @@ #include <QBoxLayout> #include <QGridLayout> #include <qprogressbar.h> +#include <QCheckBox> #include "dialogs.h" #include "widgets.h" @@ -164,12 +165,19 @@ dsb_replacement = new QDoubleSpinBox; dsb_replacement->setRange (-10000.0f, 10000.0f); + cb_any = new QCheckBox ("Any"); + cb_rel = new QCheckBox ("Relative"); + + connect (cb_any, SIGNAL (stateChanged (int)), this, SLOT (anyChanged (int))); + QGridLayout* valueLayout = new QGridLayout; valueLayout->setColumnStretch (1, 1); valueLayout->addWidget (lb_search, 0, 0); valueLayout->addWidget (dsb_search, 0, 1); + valueLayout->addWidget (cb_any, 0, 2); valueLayout->addWidget (lb_replacement, 1, 0); valueLayout->addWidget (dsb_replacement, 1, 1); + valueLayout->addWidget (cb_rel, 1, 2); QVBoxLayout* layout = new QVBoxLayout; layout->addWidget (cbg_axes); @@ -190,6 +198,18 @@ return cbg_axes->checkedValues (); } +void ReplaceCoordsDialog::anyChanged (int state) { + dsb_search->setEnabled (state != Qt::Checked); +} + +bool ReplaceCoordsDialog::any () const { + return cb_any->isChecked (); +} + +bool ReplaceCoordsDialog::rel () const { + return cb_rel->isChecked (); +} + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // =============================================================================
--- a/src/dialogs.h Mon May 27 18:17:21 2013 +0300 +++ b/src/dialogs.h Mon May 27 22:05:10 2013 +0300 @@ -21,7 +21,9 @@ #include <QDialog> #include "common.h" +#include "types.h" +class QCheckBox; class QProgressBar; class QGroupBox; class QDialogButtonBox; @@ -63,17 +65,25 @@ }; class ReplaceCoordsDialog : public QDialog { + Q_OBJECT + public: explicit ReplaceCoordsDialog (QWidget* parent = null, Qt::WindowFlags f = 0); - vector< int > axes () const; + vector<int> axes () const; double searchValue () const; double replacementValue () const; + bool any () const; + bool rel () const; private: CheckBoxGroup* cbg_axes; QLabel* lb_search, *lb_replacement; QDoubleSpinBox* dsb_search, *dsb_replacement; + QCheckBox* cb_any, *cb_rel; + +private slots: + void anyChanged (int state); }; // =============================================================================
--- a/src/gldraw.cpp Mon May 27 18:17:21 2013 +0300 +++ b/src/gldraw.cpp Mon May 27 22:05:10 2013 +0300 @@ -839,6 +839,18 @@ angle -= 360.0; } +void GLRenderer::addDrawnVertex (vertex pos) { + // If we picked an already-existing vertex, stop drawing + for (vertex& vert : m_drawedVerts) { + if (vert == pos) { + endDraw (true); + return; + } + } + + m_drawedVerts << pos; +} + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= @@ -846,6 +858,7 @@ const bool wasLeft = (m_lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton); const bool wasRight = (m_lastButtons & Qt::RightButton) && !(ev->buttons() & Qt::RightButton); const bool wasMid = (m_lastButtons & Qt::MidButton) && !(ev->buttons() & Qt::MidButton); + printf ("totalmove: %lu\n", m_totalmove); if (wasLeft) { // Check if we selected a camera icon @@ -875,17 +888,9 @@ if (m_drawedVerts.size () == 0 && ev->modifiers () & Qt::ShiftModifier) m_rectdraw = true; - - // If we picked an already-existing vertex, stop drawing - for (vertex& vert : m_drawedVerts) { - if (vert == m_hoverpos) { - endDraw (true); - return; - } - } } - m_drawedVerts << m_hoverpos; + addDrawnVertex (m_hoverpos); update (); break; @@ -901,11 +906,9 @@ } m_rangepick = false; - m_totalmove = 0; - return; } - if (wasMid && editMode () == Draw && m_drawedVerts.size () < 4) { + if (wasMid && editMode () == Draw && m_drawedVerts.size () < 4 && m_totalmove < 10) { // Find the closest vertex to our cursor double mindist = 1024.0f; vertex closest; @@ -931,12 +934,8 @@ } } - if (valid) { - m_drawedVerts << closest; - update (); - } - - return; + if (valid) + addDrawnVertex (closest); } if (wasRight && m_drawedVerts.size () > 0) { @@ -948,14 +947,15 @@ update (); } + + m_totalmove = 0; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::mousePressEvent (QMouseEvent* ev) { - if (ev->buttons () & Qt::LeftButton) - m_totalmove = 0; + m_totalmove = 0; if (ev->modifiers () & Qt::ShiftModifier) { m_rangepick = true;
--- a/src/gldraw.h Mon May 27 18:17:21 2013 +0300 +++ b/src/gldraw.h Mon May 27 22:05:10 2013 +0300 @@ -126,6 +126,7 @@ overlayMeta m_overlays[6]; vector<vertex> m_knownVerts; + void addDrawnVertex (vertex m_hoverpos); void calcCameraIcons (); // Compute geometry for camera icons void clampAngle (double& angle) const; // Clamps an angle to [0, 360] void compileList (LDObject* obj, const ListType list); // Compile one of the lists of an object
--- a/src/gui_editactions.cpp Mon May 27 18:17:21 2013 +0300 +++ b/src/gui_editactions.cpp Mon May 27 22:05:10 2013 +0300 @@ -681,7 +681,7 @@ runIsecalc (); } -// ========================================================================================================================================= +// ============================================================================= MAKE_ACTION (replaceCoords, "Replace Coordinates", "replace-coords", "Find and replace coordinate values", CTRL (R)) { ReplaceCoordsDialog dlg; @@ -690,8 +690,10 @@ const double search = dlg.searchValue (), replacement = dlg.replacementValue (); + const bool any = dlg.any (), + rel = dlg.rel (); + vector<int> sel = dlg.axes (); - EditHistory* history = new EditHistory; for (LDObject* obj : g_win->sel ()) { @@ -701,8 +703,12 @@ for (int ax : sel) { double& coord = obj->coords[i][(Axis) ax]; - if (coord == search) - coord = replacement; + if (any || coord == search) { + if (!rel) + coord = 0; + + coord += replacement; + } } history->addEntry (copy, obj, obj->getIndex (g_curfile));