Yay! This thing can save now.

Sat, 16 Mar 2013 15:45:20 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 16 Mar 2013 15:45:20 +0200
changeset 20
2ca638886082
parent 19
6c5977e43e73
child 21
9aebaaafa5da

Yay! This thing can save now.

gui.cpp file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
model.cpp file | annotate | diff | comparison | revisions
model.h file | annotate | diff | comparison | revisions
--- a/gui.cpp	Sat Mar 16 14:21:31 2013 +0200
+++ b/gui.cpp	Sat Mar 16 15:45:20 2013 +0200
@@ -86,7 +86,6 @@
 	
 	// things not implemented yet
 	QAction* qaDisabledActions[] = {
-		qAct_save,
 		qAct_saveAs,
 		qAct_newSubfile,
 		qAct_newTriangle,
@@ -203,7 +202,7 @@
 }
 
 void LDForgeWindow::slot_save () {
-	printf ("save file\n");
+	saveModel ();
 }
 
 void LDForgeWindow::slot_saveAs () {
--- a/ldtypes.cpp	Sat Mar 16 14:21:31 2013 +0200
+++ b/ldtypes.cpp	Sat Mar 16 15:45:20 2013 +0200
@@ -93,15 +93,11 @@
 }
 
 str LDSubfile::getContents () {
-	str val = str::mkfmt ("1 %d", dColor);
-	val += vPosition;
+	str val = str::mkfmt ("1 %d %s ", dColor, vPosition.getStringRep (false).chars ());
 	
-	for (short i = 0; i < 9; ++i) {
-		val += ' ';
-		val += ftoa (faMatrix[i]);
-	}
+	for (short i = 0; i < 9; ++i)
+		val.appendformat ("%s ", ftoa (faMatrix[i]).chars());
 	
-	val += ' ';
 	val += zFileName;
 	return val;
 }
--- a/model.cpp	Sat Mar 16 14:21:31 2013 +0200
+++ b/model.cpp	Sat Mar 16 15:45:20 2013 +0200
@@ -37,4 +37,25 @@
 	g_CurrentFile = f;
 	
 	g_qWindow->R->hardRefresh();
+}
+
+void saveModel () {
+	if (!g_CurrentFile)
+		return;
+	
+	FILE* fp = fopen (g_CurrentFile->zFileName, "w");
+	if (!fp)
+		return;
+	
+	// Write all entries now
+	for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) {
+		LDObject* obj = g_CurrentFile->objects[i];
+		
+		// LDraw requires lines to have DOS line endings
+		str zLine = str::mkfmt ("%s\r\n",obj->getContents ().chars ());
+		
+		fwrite (zLine.chars(), 1, ~zLine, fp);
+	}
+	
+	fclose (fp);
 }
\ No newline at end of file
--- a/model.h	Sat Mar 16 14:21:31 2013 +0200
+++ b/model.h	Sat Mar 16 15:45:20 2013 +0200
@@ -1,2 +1,3 @@
 void closeModel ();
-void newModel ();
\ No newline at end of file
+void newModel ();
+void saveModel ();
\ No newline at end of file

mercurial