X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ffileio.cpp;h=ace5bfa247713a3adc4aabee61f0dc3871a4c0aa;hb=790c1a6d97f73f7457c7fad7e82fa29e5b6accd5;hp=02ab2f577dc60af0a95f392a60e069b32b57b631;hpb=a6e76b6a748a350bda067a99672f9dcca626d872;p=architektonas diff --git a/src/fileio.cpp b/src/fileio.cpp index 02ab2f5..ace5bfa 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -19,6 +19,9 @@ #include #include #include +#include "applicationwindow.h" +#include "drawingview.h" +#include "global.h" #include "structs.h" /* @@ -125,7 +128,13 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile }; virtual Object function that reports the object by itself if it's a non- Container, otherwise it enumerates all objects within itself. */ - fprintf(file, "ARCHITEKTONAS DRAWING V1.1\n"); + fprintf(file, "ARCHITEKTONAS DRAWING V1.2\n"); + fprintf(file, "LAYERS %i\n", Global::numLayers); + + for(int i=0; i containerStack; Container * currentTopContainer = drawing; + ResetLayerVectors(); while (!feof(file)) { @@ -197,6 +225,76 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile }; /*static*/ bool FileIO::LoadVersion1_1(FILE * file, Container * drawing) { + // Approach: read each object in the file, one by one. If the object is a + // Container, add objects to it until an "endContainer" marker is found. + // This will require a stack to maintain the current Container. + std::vector containerStack; + Container * currentTopContainer = drawing; + ResetLayerVectors(); + + while (!feof(file)) + { + // Reconstruct the object (extended format!) + Object * obj = GetObjectFromFile(file, true); + + // objectFileType is set in GetObjectFromFile()... + if (objectFileType == OTFObject) + { + if (obj == NULL) + return false; + + currentTopContainer->objects.push_back(obj); +//printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.size(), currentTopContainer->objects.size()); + + // If the object is a container, push current TLC on the stack and + // set it as the new TLC + if (obj->type == OTContainer) + { + containerStack.push_back(currentTopContainer); + currentTopContainer = (Container *)obj; + } + } + else if (objectFileType == OTFContainerEnd) + { + // Add the extents of the current container + Rect r = ApplicationWindow::drawing->GetObjectExtents((Object *)currentTopContainer); + currentTopContainer->p[0] = r.TopLeft(); + currentTopContainer->p[1] = r.BottomRight(); +//printf("Container extents: <%lf, %lf>, <%lf, %lf>\n", r.l, r.t, r.r, r.b); + + // Container is done, so pop the stack to get back the previous TLC + currentTopContainer = containerStack.back(); + containerStack.pop_back(); + } + else if (objectFileType == OTFEndOfFile) + { +//printf("Load: container size = %li\n", drawing->objects.size()); + return true; + } + } + + return false; +} + + +/*static*/ bool FileIO::LoadVersion1_2(FILE * file, Container * drawing) +{ + int hidden, locked; + char textBuffer[65536]; + + // Load layer information first + fscanf(file, "LAYERS %i\n", &Global::numLayers); + + for(int i=0; iGetObjectExtents((Object *)currentTopContainer); + currentTopContainer->p[0] = r.TopLeft(); + currentTopContainer->p[1] = r.BottomRight(); +//printf("Container extents: <%lf, %lf>, <%lf, %lf>\n", r.l, r.t, r.r, r.b); + // Container is done, so pop the stack to get back the previous TLC currentTopContainer = containerStack.back(); containerStack.pop_back(); @@ -280,6 +384,7 @@ if (errno) } // Need to add pen attributes as well... do that for v1.1 :-P + // And fill attributes... do that for v1.3 (1.2 added layers) if (strcmp(buffer, "LINE") == 0) { Point p1, p2;