Sat, 16 Mar 2013 15:45:20 +0200
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