# HG changeset patch # User Santeri Piippo # Date 1363441520 -7200 # Node ID 2ca6388860827711bc8e0bbd6e0244bf45c6afa3 # Parent 6c5977e43e7341b2d02787d459d1109c207d26ec Yay! This thing can save now. diff -r 6c5977e43e73 -r 2ca638886082 gui.cpp --- 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 () { diff -r 6c5977e43e73 -r 2ca638886082 ldtypes.cpp --- 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; } diff -r 6c5977e43e73 -r 2ca638886082 model.cpp --- 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 diff -r 6c5977e43e73 -r 2ca638886082 model.h --- 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