Added tool for replacing coordinate values

Fri, 10 May 2013 21:45:36 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 10 May 2013 21:45:36 +0300
changeset 190
82f784cf2ce5
parent 189
ac2d3e8dd110
child 191
9bb6a17305ad

Added tool for replacing coordinate values

src/extprogs.cpp file | annotate | diff | comparison | revisions
src/gui.cpp file | annotate | diff | comparison | revisions
src/gui.h file | annotate | diff | comparison | revisions
src/gui_editactions.cpp file | annotate | diff | comparison | revisions
src/history.cpp file | annotate | diff | comparison | revisions
src/history.h file | annotate | diff | comparison | revisions
src/radiobox.cpp file | annotate | diff | comparison | revisions
--- a/src/extprogs.cpp	Fri May 10 17:39:56 2013 +0300
+++ b/src/extprogs.cpp	Fri May 10 21:45:36 2013 +0300
@@ -236,13 +236,6 @@
 	g_win->refresh ();
 }
 
-QDialogButtonBox* makeButtonBox (QDialog& dlg) {
-	QDialogButtonBox* bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
-	QWidget::connect (bbx_buttons, SIGNAL (accepted ()), &dlg, SLOT (accept ()));
-	QWidget::connect (bbx_buttons, SIGNAL (rejected ()), &dlg, SLOT (reject ()));
-	return bbx_buttons;
-}
-
 // =============================================================================
 // Interface for Ytruder
 void runYtruder () {
--- a/src/gui.cpp	Fri May 10 17:39:56 2013 +0300
+++ b/src/gui.cpp	Fri May 10 21:45:36 2013 +0300
@@ -25,6 +25,7 @@
 #include <qlistwidget.h>
 #include <qtoolbutton.h>
 #include <qcombobox.h>
+#include <qdialogbuttonbox.h>
 #include <qcoreapplication.h>
 #include "common.h"
 #include "gldraw.h"
@@ -375,6 +376,7 @@
 	addToolBarAction ("screencap");
 	addToolBarAction ("uncolorize");
 	addToolBarAction ("visibility");
+	addToolBarAction ("replaceCoords");
 	
 	initSingleToolBar ("External Programs");
 	addToolBarAction ("ytruder");
@@ -1045,4 +1047,12 @@
 		
 		++row;
 	}
+}
+
+// ========================================================================================================================================
+QDialogButtonBox* makeButtonBox (QDialog& dlg) {
+	QDialogButtonBox* bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+	QWidget::connect (bbx_buttons, SIGNAL (accepted ()), &dlg, SLOT (accept ()));
+	QWidget::connect (bbx_buttons, SIGNAL (rejected ()), &dlg, SLOT (reject ()));
+	return bbx_buttons;
 }
\ No newline at end of file
--- a/src/gui.h	Fri May 10 17:39:56 2013 +0300
+++ b/src/gui.h	Fri May 10 21:45:36 2013 +0300
@@ -38,6 +38,7 @@
 class QSplitter;
 class DelHistory;
 class QToolButton;
+class QDialogButtonBox;
 
 // Stuff for dialogs
 #define IMPLEMENT_DIALOG_BUTTONS \
@@ -242,6 +243,7 @@
 QAction* findAction (str name);
 QIcon makeColorIcon (color* colinfo, const ushort size);
 void makeColorSelector (QComboBox* box);
+QDialogButtonBox* makeButtonBox (QDialog& dlg);
 
 // -----------------------------------------------------------------------------
 // Pointer to the instance of ForgeWindow.
--- a/src/gui_editactions.cpp	Fri May 10 17:39:56 2013 +0300
+++ b/src/gui_editactions.cpp	Fri May 10 21:45:36 2013 +0300
@@ -27,6 +27,7 @@
 #include "bbox.h"
 #include "radiobox.h"
 #include "extprogs.h"
+#include "checkboxgroup.h"
 #include <qspinbox.h>
 #include <qcheckbox.h>
 
@@ -754,6 +755,81 @@
 // =========================================================================================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =========================================================================================================================================
+class ReplaceCoordsDialog : public QDialog {
+public:
+	explicit ReplaceCoordsDialog (QWidget* parent = null, Qt::WindowFlags f = 0) : QDialog (parent, f) {
+		cbg_axes = new CheckBoxGroup<Axis> ("Axes", Qt::Horizontal);
+		cbg_axes->addCheckBox ("X", X);
+		cbg_axes->addCheckBox ("Y", Y);
+		cbg_axes->addCheckBox ("Z", Z);
+		
+		lb_search = new QLabel ("Search:");
+		lb_replacement = new QLabel ("Replacement:");
+		
+		dsb_search = new QDoubleSpinBox;
+		dsb_search->setRange (-10000.0f, 10000.0f);
+		
+		dsb_replacement = new QDoubleSpinBox;
+		dsb_replacement->setRange (-10000.0f, 10000.0f);
+		
+		QGridLayout* valueLayout = new QGridLayout;
+		valueLayout->setColumnStretch (1, 1);
+		valueLayout->addWidget (lb_search, 0, 0);
+		valueLayout->addWidget (dsb_search, 0, 1);
+		valueLayout->addWidget (lb_replacement, 1, 0);
+		valueLayout->addWidget (dsb_replacement, 1, 1);
+		
+		QVBoxLayout* layout = new QVBoxLayout;
+		layout->addWidget (cbg_axes);
+		layout->addLayout (valueLayout);
+		layout->addWidget (makeButtonBox (*this));
+		setLayout (layout);
+	}
+	
+	std::vector<Axis> axes () const {
+		return cbg_axes->checkedValues ();
+	}
+	
+	double searchValue () { return dsb_search->value (); }
+	double replacementValue () { return dsb_replacement->value (); }
+	
+private:
+	CheckBoxGroup<Axis>* cbg_axes;
+	QLabel* lb_search, *lb_replacement;
+	QDoubleSpinBox* dsb_search, *dsb_replacement;
+};
+
+// =========================================================================================================================================
 MAKE_ACTION (replaceCoords, "Replace Coordinates", "replace-coords", "Find and replace coordinate values", CTRL (R)) {
-	QDialog dlg;
+	ReplaceCoordsDialog dlg;
+	
+	if (!dlg.exec ())
+		return;
+	
+	const double search = dlg.searchValue (),
+		replacement = dlg.replacementValue ();
+	vector<Axis> sel = dlg.axes ();
+	
+	EditHistory* history = new EditHistory;
+	
+	for (LDObject* obj : g_win->sel ()) {
+		bool altered = false;
+		LDObject* copy = obj->clone ();
+		
+		for (short i = 0; i < obj->vertices (); ++i)
+		for (Axis ax : sel) {
+			if (obj->coords[i][ax] == search) {
+				obj->coords[i][ax] = replacement;
+				altered = true;
+			}
+		}
+		
+		if (altered)
+			history->addEntry (copy, obj, obj->getIndex (g_curfile));
+		
+		delete copy;
+	}
+	
+	History::addEntry (history);
+	g_win->refresh ();
 }
\ No newline at end of file
--- a/src/history.cpp	Fri May 10 17:39:56 2013 +0300
+++ b/src/history.cpp	Fri May 10 21:45:36 2013 +0300
@@ -165,12 +165,11 @@
 }
 
 void EditHistory::addEntry (LDObject* const oldObj, LDObject* const newObj) {
-	printf ("%s at %lu, replaced by a %s\n",
-		g_saObjTypeNames[oldObj->getType()],
-		oldObj->getIndex (g_curfile),
-		g_saObjTypeNames[newObj->getType()]);
-	
-	ulaIndices.push_back (oldObj->getIndex (g_curfile));
+	addEntry (oldObj, newObj, oldObj->getIndex (g_curfile));
+}
+
+void EditHistory::addEntry (LDObject* const oldObj, LDObject* const newObj, const ulong idx) {
+	ulaIndices.push_back (idx);
 	paOldObjs.push_back (oldObj->clone ());
 	paNewObjs.push_back (newObj->clone ());
 }
--- a/src/history.h	Fri May 10 17:39:56 2013 +0300
+++ b/src/history.h	Fri May 10 21:45:36 2013 +0300
@@ -103,6 +103,7 @@
 		ulaIndices (ulaIndices), paOldObjs (paOldObjs), paNewObjs (paNewObjs) {}
 	
 	void addEntry (LDObject* const oldObj, LDObject* const newObj);
+	void addEntry (LDObject* const oldObj, LDObject* const newObj, const ulong idx);
 };
 
 // =============================================================================
--- a/src/radiobox.cpp	Fri May 10 17:39:56 2013 +0300
+++ b/src/radiobox.cpp	Fri May 10 21:45:36 2013 +0300
@@ -20,7 +20,7 @@
 #include <qradiobutton.h>
 #include "radiobox.h"
 
-static QBoxLayout::Direction makeDirection (Qt::Orientation orient, bool invert = false) {
+QBoxLayout::Direction makeDirection (Qt::Orientation orient, bool invert = false) {
 	return (orient == (invert ? Qt::Vertical : Qt::Horizontal)) ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom;
 }
 

mercurial