this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.

Sat, 16 Mar 2013 03:11:19 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 16 Mar 2013 03:11:19 +0200
changeset 14
6d9d8efae2f8
parent 13
3955ff2a7d72
child 15
a78ccb3976b6

this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.

gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
io.cpp file | annotate | diff | comparison | revisions
ldforge.pro file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
ldtypes.h file | annotate | diff | comparison | revisions
--- a/gui.cpp	Sat Mar 16 01:32:47 2013 +0200
+++ b/gui.cpp	Sat Mar 16 03:11:19 2013 +0200
@@ -6,12 +6,15 @@
 #include "model.h"
 #include "io.h"
 
+#include "zz_setContentsDialog.h"
+
 LDForgeWindow::LDForgeWindow () {
 	R = new renderer;
 	
 	qObjList = new QTreeWidget;
 	qObjList->setHeaderHidden (true);
 	qObjList->setMaximumWidth (256);
+	qObjList->setSelectionMode (QTreeWidget::MultiSelection);
 	
 	qMessageLog = new QTextEdit;
 	qMessageLog->setReadOnly (true);
@@ -59,6 +62,8 @@
 	MAKE_ACTION (about,			sAboutText,		"about",		"Shows information about " APPNAME_DISPLAY ".")
 	MAKE_ACTION (aboutQt,		"About Qt",		"aboutQt",		"Shows information about Qt.")
 	
+	MAKE_ACTION (setContents,	"Set Contents",	"set-contents",	"Set the raw code of this object.")
+	
 	MAKE_ACTION (newSubfile,	"New Subfile",	"add-subfile",	"Creates a new subfile reference.")
 	MAKE_ACTION (newLine,		"New Line", 	"add-line",		"Creates a new line.")
 	MAKE_ACTION (newTriangle,	"New Triangle", "add-triangle",	"Creates a new triangle.")
@@ -125,6 +130,8 @@
 	qEditMenu->addAction (qAct_cut);			// Cut
 	qEditMenu->addAction (qAct_copy);			// Copy
 	qEditMenu->addAction (qAct_paste);			// Paste
+	qEditMenu->addSeparator ();					// -----
+	qEditMenu->addAction (qAct_setContents);	// Set Contents
 	
 	// Help menu
 	qHelpMenu = menuBar ()->addMenu (tr ("&Help"));
@@ -155,6 +162,7 @@
 	qEditToolBar->addAction (qAct_cut);
 	qEditToolBar->addAction (qAct_copy);
 	qEditToolBar->addAction (qAct_paste);
+	qEditToolBar->addAction (qAct_setContents);
 	addToolBar (qEditToolBar);
 }
 
@@ -259,6 +267,26 @@
 	
 }
 
+void LDForgeWindow::slot_setContents () {
+	if (qObjList->selectedItems().size() != 1)
+		return;
+	
+	ulong ulIndex;
+	LDObject* obj = nullptr;
+	
+	QTreeWidgetItem* item = qObjList->selectedItems()[0];
+	for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex) {
+		obj = g_CurrentFile->objects[ulIndex];
+		
+		if (obj->qObjListEntry == item)
+			break;
+	}
+	
+	if (ulIndex >= g_CurrentFile->objects.size())
+		return;
+	
+	Dialog_SetContents::staticDialog (obj, this);
+}
 
 static QIcon IconForObjectType (LDObject* obj) {
 	switch (obj->getType ()) {
@@ -311,7 +339,7 @@
 		str zText;
 		switch (obj->getType ()) {
 		case OBJ_Comment:
-			zText = static_cast<LDComment*> (obj)->zText;
+			zText = static_cast<LDComment*> (obj)->zText.chars();
 			
 			// Remove leading whitespace
 			while (~zText && zText[0] == ' ')
@@ -354,7 +382,7 @@
 		
 		case OBJ_Gibberish:
 			zText.format ("ERROR: %s",
-				static_cast<LDGibberish*> (obj)->zContent.chars());
+				static_cast<LDGibberish*> (obj)->zContents.chars());
 			break;
 		
 		case OBJ_Vector:
@@ -370,7 +398,7 @@
 			break;
 		}
 		
-		QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*)nullptr,
+		QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*) (nullptr),
 			QStringList (zText.chars()), 0);
 		item->setIcon (0, IconForObjectType (obj));
 		
@@ -380,8 +408,14 @@
 			item->setForeground (0, QColor ("#FFAA00"));
 		}
 		
+		obj->qObjListEntry = item;
+		
 		qaItems.append (item);
 	}
 	
 	qObjList->insertTopLevelItems (0, qaItems);
+}
+
+void LDForgeWindow::slot_selectionChanged () {
+	
 }
\ No newline at end of file
--- a/gui.h	Sat Mar 16 01:32:47 2013 +0200
+++ b/gui.h	Sat Mar 16 03:11:19 2013 +0200
@@ -34,6 +34,7 @@
 	QAction* qAct_cut, *qAct_copy, *qAct_paste;
 	QAction* qAct_newSubfile, *qAct_newLine, *qAct_newTriangle, *qAct_newQuad;
 	QAction* qAct_newCondLine, *qAct_newComment, *qAct_newVector, *qAct_newVertex;
+	QAction* qAct_setContents;
 	QAction* qAct_about, *qAct_aboutQt;
 	
 	LDForgeWindow ();
@@ -46,6 +47,8 @@
     void createToolbars ();
 
 private slots:
+	void slot_selectionChanged ();
+	
 	void slot_new ();
 	void slot_open ();
 	void slot_save ();
@@ -61,6 +64,8 @@
 	void slot_newVector ();
 	void slot_newVertex ();
 	
+	void slot_setContents ();
+	
 	void slot_cut ();
 	void slot_copy ();
 	void slot_paste ();
--- a/io.cpp	Sat Mar 16 01:32:47 2013 +0200
+++ b/io.cpp	Sat Mar 16 03:11:19 2013 +0200
@@ -83,8 +83,8 @@
 	g_qWindow->buildObjList ();
 	g_qWindow->setTitle ();
 	
-	logf (LOG_Success, "File %s parsed successfully (%lu warnings).\n",
-		path.chars(), numWarnings);
+	logf (LOG_Success, "File %s parsed successfully (%lu warning%s).\n",
+		path.chars(), numWarnings, PLURAL (numWarnings));
 	
 	return g_CurrentFile;
 }
--- a/ldforge.pro	Sat Mar 16 01:32:47 2013 +0200
+++ b/ldforge.pro	Sat Mar 16 03:11:19 2013 +0200
@@ -9,28 +9,31 @@
 
 # Input
 HEADERS += bbox.h \
-           common.h \
-           draw.h \
-           gui.h \
-           io.h \
-           ldtypes.h \
-           misc.h \
-           model.h \
-           scanner.h \
-           str.h \
-           config.h \
-           cfgdef.h
+	common.h \
+	draw.h \
+	gui.h \
+	io.h \
+	ldtypes.h \
+	misc.h \
+	model.h \
+	scanner.h \
+	str.h \
+	config.h \
+	cfgdef.h \
+	zz_setContentsDialog.h
+
 SOURCES += bbox.cpp \
-           draw.cpp \
-           gui.cpp \
-           io.cpp \
-           ldtypes.cpp \
-           main.cpp \
-           misc.cpp \
-           model.cpp \
-           scanner.cpp \
-           str.cpp \ 
-           config.cpp
+	draw.cpp \
+	gui.cpp \
+	io.cpp \
+	ldtypes.cpp \
+	main.cpp \
+	misc.cpp \
+	model.cpp \
+	scanner.cpp \
+	str.cpp \ 
+	config.cpp \
+	zz_setContentsDialog.cpp
 
 QMAKE_CXXFLAGS += -std=c++0x
 QT += opengl
\ No newline at end of file
--- a/ldtypes.cpp	Sat Mar 16 01:32:47 2013 +0200
+++ b/ldtypes.cpp	Sat Mar 16 03:11:19 2013 +0200
@@ -19,52 +19,58 @@
 // =============================================================================
 // LDObject constructors
 LDObject::LDObject () {
-	
+	commonInit ();
+}
+
+void LDObject::commonInit () {
+	qObjListEntry = nullptr;
 }
 
 LDGibberish::LDGibberish () {
-	
+	commonInit ();
 }
 
 LDGibberish::LDGibberish (str _zContent, str _zReason) {
-	zContent = _zContent;
+	zContents = _zContent;
 	zReason = _zReason;
+	
+	commonInit ();
 }
 
 LDEmpty::LDEmpty () {
-	
+	commonInit ();
 }
 
 LDComment::LDComment () {
-	
+	commonInit ();
 }
 
 LDSubfile::LDSubfile () {
-	
+	commonInit ();
 }
 
 LDLine::LDLine () {
-	
+	commonInit ();
 }
 
 LDTriangle::LDTriangle () {
-	
+	commonInit ();
 }
 
 LDQuad::LDQuad () {
-	
+	commonInit ();
 }
 
 LDCondLine::LDCondLine () {
-	
+	commonInit ();
 }
 
 LDVector::LDVector () {
-	
+	commonInit ();
 }
 
 LDVertex::LDVertex () {
-	
+	commonInit ();
 }
 
 ulong LDObject::getIndex () {
@@ -78,4 +84,64 @@
 	}
 	
 	return -1u;
+}
+
+// =============================================================================
+str LDComment::getContents () {
+	return str::mkfmt ("0%s", zText.chars ());
+}
+
+str LDLine::getContents () {
+	return str::mkfmt ("2 %d %f %f %f %f %f %f", dColor,
+		vaCoords[0].x, vaCoords[0].y, vaCoords[0].z,
+		vaCoords[1].x, vaCoords[1].y, vaCoords[1].z);
+}
+
+str LDTriangle::getContents () {
+	return str::mkfmt ("3 %d %f %f %f %f %f %f %f %f %f", dColor,
+		vaCoords[0].x, vaCoords[0].y, vaCoords[0].z,
+		vaCoords[1].x, vaCoords[1].y, vaCoords[1].z,
+		vaCoords[2].x, vaCoords[2].y, vaCoords[2].z);
+}
+
+str LDQuad::getContents () {
+	// Oh, Jesus.
+	return str::mkfmt ("3 %d %f %f %f %f %f %f %f %f %f %f %f %f", dColor,
+		vaCoords[0].x, vaCoords[0].y, vaCoords[0].z,
+		vaCoords[1].x, vaCoords[1].y, vaCoords[1].z,
+		vaCoords[2].x, vaCoords[2].y, vaCoords[2].z,
+		vaCoords[3].x, vaCoords[3].y, vaCoords[3].z);
+}
+
+str LDCondLine::getContents () {
+	return str::mkfmt ("3 %d %f %f %f %f %f %f %f %f %f %f %f %f", dColor,
+		vaCoords[0].x, vaCoords[0].y, vaCoords[0].z,
+		vaCoords[1].x, vaCoords[1].y, vaCoords[1].z,
+		vaControl[0].x, vaControl[0].y, vaControl[0].z,
+		vaControl[1].x, vaControl[1].y, vaControl[1].z);
+}
+
+str LDGibberish::getContents () {
+	return zContents;
+}
+
+str LDSubfile::getContents () {
+	return str::mkfmt ("1 %d %f %f %f %f %f %f %f %f %f %f %f %f %s", dColor,
+		vPosition.x, vPosition.y, vPosition.y,
+		faMatrix[0], faMatrix[1], faMatrix[2],
+		faMatrix[3], faMatrix[4], faMatrix[5],
+		faMatrix[6], faMatrix[7], faMatrix[8],
+		zFileName.chars());
+}
+
+str LDVector::getContents () {
+	return str::mkfmt ("0 !LDFORGE VECTOR"); // TODO
+}
+
+str LDVertex::getContents () {
+	return "!LDFORGE VERTEX"; // TODO
+}
+
+str LDEmpty::getContents () {
+	return str ();
 }
\ No newline at end of file
--- a/ldtypes.h	Sat Mar 16 01:32:47 2013 +0200
+++ b/ldtypes.h	Sat Mar 16 03:11:19 2013 +0200
@@ -8,7 +8,10 @@
 	LD##N (); \
 	virtual LDObjectType_e getType () const { \
 		return OBJ_##N; \
-	}
+	} \
+	virtual str getContents ();
+
+class QTreeWidgetItem;
 
 // =============================================================================
 // LDObjectType_e
@@ -48,6 +51,15 @@
 	virtual LDObjectType_e getType () const {
 		return OBJ_Unidentified;
 	};
+	
+	// A string that represents this line
+	virtual str getContents () {
+		return "";
+	}
+	
+	void commonInit ();
+	
+	QTreeWidgetItem* qObjListEntry;
 };
 
 // =============================================================================
@@ -65,7 +77,7 @@
 	LDGibberish (str _zContent, str _zReason);
 	
 	// Content of this unknown line
-	str zContent;
+	str zContents;
 	
 	// Why is this gibberish?
 	str zReason;

mercurial