Added basic object moving with MLCAD-like controls.

Fri, 12 Apr 2013 02:54:25 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 12 Apr 2013 02:54:25 +0300
changeset 102
cacd4681ccb4
parent 101
69d1464801d7
child 103
b0a345196435

Added basic object moving with MLCAD-like controls.

gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
gui_editactions.cpp file | annotate | diff | comparison | revisions
history.cpp file | annotate | diff | comparison | revisions
history.h file | annotate | diff | comparison | revisions
icons/move-x-neg.png file | annotate | diff | comparison | revisions
icons/move-x-pos.png file | annotate | diff | comparison | revisions
icons/move-y-neg.png file | annotate | diff | comparison | revisions
icons/move-y-pos.png file | annotate | diff | comparison | revisions
icons/move-z-neg.png file | annotate | diff | comparison | revisions
icons/move-z-pos.png file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
ldtypes.h file | annotate | diff | comparison | revisions
types.h file | annotate | diff | comparison | revisions
--- a/gui.cpp	Fri Apr 12 01:03:08 2013 +0300
+++ b/gui.cpp	Fri Apr 12 02:54:25 2013 +0300
@@ -60,6 +60,13 @@
 EXTERN_ACTION (redo)
 EXTERN_ACTION (showHistory)
 
+EXTERN_ACTION (moveXNeg)
+EXTERN_ACTION (moveYNeg)
+EXTERN_ACTION (moveZNeg)
+EXTERN_ACTION (moveXPos)
+EXTERN_ACTION (moveYPos)
+EXTERN_ACTION (moveZPos)
+
 #ifndef RELEASE
 EXTERN_ACTION (addTestQuad)
 #endif // RELEASE
@@ -179,9 +186,6 @@
 	qEditMenu->addAction (ACTION_NAME (paste));				// Paste
 	qEditMenu->addAction (ACTION_NAME (del));				// Delete
 	qEditMenu->addSeparator ();								// -----
-	qEditMenu->addAction (ACTION_NAME (moveUp));			// Move Up
-	qEditMenu->addAction (ACTION_NAME (moveDown));			// Move Down
-	qEditMenu->addSeparator ();								// -----
 	qEditMenu->addAction (ACTION_NAME (setColor));			// Set Color
 	qEditMenu->addAction (ACTION_NAME (inlineContents));	// Inline
 	qEditMenu->addAction (ACTION_NAME (deepInline));		// Deep Inline
@@ -189,6 +193,18 @@
 	qEditMenu->addAction (ACTION_NAME (setContents));		// Set Contents
 	qEditMenu->addAction (ACTION_NAME (makeBorders));		// Make Borders
 	
+	// Move menu
+	qMoveMenu = menuBar ()->addMenu (tr ("&Move"));
+	qMoveMenu->addAction (ACTION_NAME (moveUp));			// Move Up
+	qMoveMenu->addAction (ACTION_NAME (moveDown));			// Move Down
+	qMoveMenu->addSeparator ();								// -----
+	qMoveMenu->addAction (ACTION_NAME (moveXPos));			// Move +X
+	qMoveMenu->addAction (ACTION_NAME (moveXNeg));			// Move -X
+	qMoveMenu->addAction (ACTION_NAME (moveYPos));			// Move +Y
+	qMoveMenu->addAction (ACTION_NAME (moveYNeg));			// Move -Y
+	qMoveMenu->addAction (ACTION_NAME (moveZPos));			// Move +Z
+	qMoveMenu->addAction (ACTION_NAME (moveZNeg));			// Move -Z
+	
 	// Control menu
 	qControlMenu = menuBar ()->addMenu (tr ("&Control"));
 	qControlMenu->addAction (ACTION_NAME (showHistory));	// Show History
@@ -270,6 +286,12 @@
 	initSingleToolBar ("Move");
 	ADD_TOOLBAR_ITEM (moveUp)
 	ADD_TOOLBAR_ITEM (moveDown)
+	ADD_TOOLBAR_ITEM (moveXPos)
+	ADD_TOOLBAR_ITEM (moveXNeg)
+	ADD_TOOLBAR_ITEM (moveYPos)
+	ADD_TOOLBAR_ITEM (moveYNeg)
+	ADD_TOOLBAR_ITEM (moveZPos)
+	ADD_TOOLBAR_ITEM (moveZNeg)
 	
 	// ==========================================
 	// Color toolbar
--- a/gui.h	Fri Apr 12 01:03:08 2013 +0300
+++ b/gui.h	Fri Apr 12 02:54:25 2013 +0300
@@ -107,7 +107,7 @@
 	// Object list view
 	QTreeWidget* qObjList;
 	QTextEdit* qMessageLog;
-	QMenu* qFileMenu, *qEditMenu, *qInsertMenu, *qHelpMenu, *qControlMenu;
+	QMenu* qFileMenu, *qEditMenu, *qInsertMenu, *qMoveMenu, *qHelpMenu, *qControlMenu;
 	QMenu* qRecentFilesMenu;
 	std::vector<QAction*> qaRecentFiles;
 	
--- a/gui_editactions.cpp	Fri Apr 12 01:03:08 2013 +0300
+++ b/gui_editactions.cpp	Fri Apr 12 02:54:25 2013 +0300
@@ -352,4 +352,43 @@
 ACTION (showHistory, "Show History", "history", "Show the history dialog.", (0)) {
 	HistoryDialog dlg;
 	dlg.exec ();
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+void doMoveObjects (const vertex vVector) {
+	vector<ulong> ulaIndices;
+	
+	for (LDObject* obj : g_ForgeWindow->getSelectedObjects ()) {
+		ulaIndices.push_back (obj->getIndex (g_CurrentFile));
+		obj->move (vVector);
+	}
+	
+	History::addEntry (new MoveHistory (ulaIndices, vVector));
+	g_ForgeWindow->refresh ();
+}
+
+ACTION (moveXNeg, "Move -X", "move-x-neg", "Move selected objects negative on the X axis.", KEY (Left)) {
+	doMoveObjects ({-1, 0, 0});
+}
+
+ACTION (moveYNeg, "Move -Y", "move-y-neg", "Move selected objects negative on the Y axis.", KEY (PageUp)) {
+	doMoveObjects ({0, -1, 0});
+}
+
+ACTION (moveZNeg, "Move -Z", "move-z-neg", "Move selected objects negative on the Z axis.", KEY (Down)) {
+	doMoveObjects ({0, 0, -1});
+}
+
+ACTION (moveXPos, "Move +X", "move-x-pos", "Move selected objects positive on the X axis.", KEY (Right)) {
+	doMoveObjects ({1, 0, 0});
+}
+
+ACTION (moveYPos, "Move +Y", "move-y-pos", "Move selected objects positive on the Y axis.", KEY (PageDown)) {
+	doMoveObjects ({0, 1, 0});
+}
+
+ACTION (moveZPos, "Move +Z", "move-z-pos", "Move selected objects positive on the Z axis.", KEY (Up)) {
+	doMoveObjects ({0, 0, 1});
 }
\ No newline at end of file
--- a/history.cpp	Fri Apr 12 01:03:08 2013 +0300
+++ b/history.cpp	Fri Apr 12 02:54:25 2013 +0300
@@ -297,4 +297,23 @@
 InlineHistory::~InlineHistory () {
 	for (LDSubfile* ref : paRefs)
 		delete ref;
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+MoveHistory::~MoveHistory () {}
+
+void MoveHistory::undo () {
+	const vertex vInverse = -vVector;
+	
+	for (ulong i : ulaIndices)
+		g_CurrentFile->object (i)->move (vInverse);
+	g_ForgeWindow->refresh ();
+}
+
+void MoveHistory::redo () {
+	for (ulong i : ulaIndices)
+		g_CurrentFile->object (i)->move (vVector);
+	g_ForgeWindow->refresh ();
 }
\ No newline at end of file
--- a/history.h	Fri Apr 12 01:03:08 2013 +0300
+++ b/history.h	Fri Apr 12 02:54:25 2013 +0300
@@ -37,6 +37,7 @@
 	HISTORY_Add,
 	HISTORY_QuadSplit,
 	HISTORY_Inline,
+	HISTORY_Move,
 };
 
 // =============================================================================
@@ -168,6 +169,20 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+class MoveHistory : public HistoryEntry {
+public:
+	IMPLEMENT_HISTORY_TYPE (Move)
+	
+	const std::vector<ulong> ulaIndices;
+	const vertex vVector;
+	
+	MoveHistory (const std::vector<ulong> ulaIndices, const vertex vVector) :
+		ulaIndices (ulaIndices), vVector (vVector) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 namespace History {
 	extern std::vector<HistoryEntry*> entries;
 	
Binary file icons/move-x-neg.png has changed
Binary file icons/move-x-pos.png has changed
Binary file icons/move-y-neg.png has changed
Binary file icons/move-y-pos.png has changed
Binary file icons/move-z-neg.png has changed
Binary file icons/move-z-pos.png has changed
--- a/ldtypes.cpp	Fri Apr 12 01:03:08 2013 +0300
+++ b/ldtypes.cpp	Fri Apr 12 02:54:25 2013 +0300
@@ -453,4 +453,41 @@
 	}
 	
 	return zText;
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+void LDObject::move (vertex vVector) { vVector = vVector; /* to shut up GCC */ }
+void LDEmpty::move (vertex vVector) { vVector = vVector; }
+void LDBFC::move (vertex vVector) { vVector = vVector; }
+void LDComment::move (vertex vVector) { vVector = vVector; }
+void LDGibberish::move (vertex vVector) { vVector = vVector; }
+
+void LDVertex::move (vertex vVector) {
+	vPosition += vVector;
+}
+
+void LDSubfile::move (vertex vVector) {
+	vPosition += vVector;
+}
+
+void LDLine::move (vertex vVector) {
+	for (short i = 0; i < 2; ++i)
+		vaCoords[i] += vVector;
+}
+
+void LDTriangle::move (vertex vVector) {
+	for (short i = 0; i < 3; ++i)
+		vaCoords[i] += vVector;
+}
+
+void LDQuad::move (vertex vVector) {
+	for (short i = 0; i < 4; ++i)
+		vaCoords[i] += vVector;
+}
+
+void LDCondLine::move (vertex vVector) {
+	for (short i = 0; i < 4; ++i)
+		vaCoords[i] += vVector;
 }
\ No newline at end of file
--- a/ldtypes.h	Fri Apr 12 01:03:08 2013 +0300
+++ b/ldtypes.h	Fri Apr 12 02:54:25 2013 +0300
@@ -31,7 +31,8 @@
 	virtual str getContents (); \
 	virtual LD##N* clone () { \
 		return new LD##N (*this); \
-	}
+	} \
+	virtual void move (vertex vVector);
 
 class QTreeWidgetItem;
 
@@ -99,6 +100,9 @@
 	// Swap this object with another.
 	void swap (LDObject* other);
 	
+	// Moves this object using the given vertex as a movement vector
+	virtual void move (vertex vVector);
+	
 	static void moveObjects (std::vector<LDObject*> objs, const bool bUp);
 	static str objectListContents (std::vector<LDObject*>& objs);
 	
--- a/types.h	Fri Apr 12 01:03:08 2013 +0300
+++ b/types.h	Fri Apr 12 02:54:25 2013 +0300
@@ -26,6 +26,19 @@
 	}
 	
 	// =========================================================================
+	vertex& operator+= (vertex& other) {
+		x += other.x;
+		y += other.y;
+		z += other.z;
+		return *this;
+	}
+	
+	// =========================================================================
+	vertex operator- () const {
+		return vertex (-x, -y, -z);
+	}
+	
+	// =========================================================================
 	// Midpoint between this vertex and another vertex.
 	vertex midpoint (vertex& other);
 	str getStringRep (const bool bMangled);

mercurial