Added action from inserting raw LDraw data into the part.

Fri, 26 Apr 2013 22:53:21 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 26 Apr 2013 22:53:21 +0300
changeset 142
6e8aee653dab
parent 141
184d117e1b12
child 143
e3c37b950a68

Added action from inserting raw LDraw data into the part.

gui.cpp file | annotate | diff | comparison | revisions
gui_actions.cpp file | annotate | diff | comparison | revisions
--- a/gui.cpp	Fri Apr 26 18:28:07 2013 +0300
+++ b/gui.cpp	Fri Apr 26 22:53:21 2013 +0300
@@ -85,6 +85,7 @@
 EXTERN_ACTION (gridFine)
 EXTERN_ACTION (resetView)
 EXTERN_ACTION (insertFrom)
+EXTERN_ACTION (insertRaw)
 
 #ifndef RELEASE
 EXTERN_ACTION (addTestQuad)
@@ -190,8 +191,6 @@
 	qFileMenu->addAction (ACTION (save));					// Save
 	qFileMenu->addAction (ACTION (saveAs));				// Save As
 	qFileMenu->addSeparator ();							// -------
-	qFileMenu->addAction (ACTION (insertFrom));			// Insert from File
-	qFileMenu->addSeparator ();							// -------
 	qFileMenu->addAction (ACTION (settings));				// Settings
 	qFileMenu->addSeparator ();							// -------
 	qFileMenu->addAction (ACTION (exit));					// Exit
@@ -202,6 +201,9 @@
 	
 	// Insert menu
 	qInsertMenu = menuBar ()->addMenu (tr ("&Insert"));
+	qInsertMenu->addAction (ACTION (insertFrom));			// Insert from File
+	qInsertMenu->addAction (ACTION (insertRaw));			// Insert Raw
+	qInsertMenu->addSeparator ();							// -------
 	qInsertMenu->addAction (ACTION (newSubfile));		// New Subfile
 	qInsertMenu->addAction (ACTION (newLine));			// New Line
 	qInsertMenu->addAction (ACTION (newTriangle));		// New Triangle
--- a/gui_actions.cpp	Fri Apr 26 18:28:07 2013 +0300
+++ b/gui_actions.cpp	Fri Apr 26 22:53:21 2013 +0300
@@ -243,12 +243,16 @@
 }
 
 // =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 MAKE_ACTION (resetView, "Reset View", "reset-view", "Reset view angles, pan and zoom", CTRL (0)) {
 	g_ForgeWindow->R->resetAngles ();
 	g_ForgeWindow->R->updateGL ();
 }
 
 // =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 MAKE_ACTION (insertFrom, "Insert from File", "insert-from", "Insert LDraw data from a file.", (0)) {
 	str fname = QFileDialog::getOpenFileName ();
 	ulong idx = g_ForgeWindow->getInsertionPoint ();
@@ -287,6 +291,47 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+MAKE_ACTION (insertRaw, "Insert Raw", "insert-raw", "Type in LDraw code to insert.", (0)) {
+	ulong idx = g_ForgeWindow->getInsertionPoint ();
+	
+	QDialog* const dlg = new QDialog;
+	QVBoxLayout* const layout = new QVBoxLayout;
+	QTextEdit* const te_edit = new QTextEdit;
+	QDialogButtonBox* const bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+	std::vector<LDObject*> historyCopies;
+	std::vector<ulong> historyIndices;
+	
+	layout->addWidget (te_edit);
+	layout->addWidget (bbx_buttons);
+	dlg->setLayout (layout);
+	dlg->connect (bbx_buttons, SIGNAL (accepted ()), dlg, SLOT (accept ()));
+	dlg->connect (bbx_buttons, SIGNAL (rejected ()), dlg, SLOT (reject ()));
+	
+	if (dlg->exec () == false)
+		return;
+	
+	g_ForgeWindow->sel.clear ();
+	
+	for (str line : str (te_edit->toPlainText ()).split ("\n")) {
+		LDObject* obj = parseLine (line);
+		
+		g_CurrentFile->objects.insert (g_CurrentFile->objects.begin () + idx, obj);
+		historyIndices.push_back (idx);
+		historyCopies.push_back (obj->clone ());
+		g_ForgeWindow->sel.push_back (obj);
+		idx++;
+	}
+	
+	if (historyCopies.size () > 0) {
+		History::addEntry (new AddHistory (historyIndices, historyCopies));
+		g_ForgeWindow->refresh ();
+		g_ForgeWindow->scrollToSelection ();
+	}
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 // Debug things
 #ifndef RELEASE
 MAKE_ACTION (addTestQuad, "Add Test Quad", "add-quad", "Adds a test quad.", (0)) {

mercurial