From: Shamus Hammons Date: Tue, 7 Feb 2017 03:09:05 +0000 (-0600) Subject: Fix loading/saving of V1.1 documents. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=86ad64f2288cf50ae9832116ef37c433556355c4 Fix loading/saving of V1.1 documents. --- diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index a4c39b7..5093fb6 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -142,7 +142,7 @@ void ApplicationWindow::FileOpen(void) return; } - Container container; + Container container(true); // Make sure it's a top level container... bool successful = FileIO::LoadAtnsFile(file, &container); fclose(file); diff --git a/src/drawingview.cpp b/src/drawingview.cpp index a86e857..a88be25 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -56,7 +56,6 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); Global::gridSpacing = 12.0; // In base units (inch is default) - #if 0 Line * line = new Line(Vector(5, 5), Vector(50, 40), &document); document.Add(line); @@ -94,6 +93,7 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), document.objects.push_back(new Text(Vector(10, 83), "Here is some awesome text!")); #endif +printf("Document topLevel = %s\n", (document.topLevel ? "true" : "false")); /* Here we set the grid size in pixels--12 in this case. Initially, we have our zoom set to make this represent 12 inches at a zoom factor of 25%. (This is diff --git a/src/fileio.cpp b/src/fileio.cpp index 1002dca..7f1a90a 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -126,11 +126,7 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile }; Container, otherwise it enumerates all objects within itself. */ fprintf(file, "ARCHITEKTONAS DRAWING V1.1\n"); -#if 0 - object->Enumerate(file); -#else WriteObjectToFile(file, (Object *)c); -#endif fprintf(file, "END\n"); return true; } @@ -142,66 +138,13 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile }; fscanf(file, "ARCHITEKTONAS DRAWING V%f", &version); -//printf("Load: version = %f\n", version); -// if (version != 1.0) -// return false; - - if (version == 1.0) + if (version == 1.0f) return LoadVersion1_0(file, drawing); - else if (version == 1.1) + else if (version == 1.1f) return LoadVersion1_1(file, drawing); +//printf("LoadAtnsFile: Could not locate version! (version=%f)\n", version); return false; - /* 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. */ - -#if 0 - std::vector containerStack; - Container * currentTopContainer = drawing;//new Container(Vector(0, 0)); - Object * object; -// ObjectType objectType; - int objectType; - - while (!feof(file)) - { - if (FileIO::GetObjectFromFile(file, currentTopContainer, &object, &objectType) == false) - return false; - - // object->type down below can be replaced with objType. - // Above could be: bool FileIO::GetObjectFromFile(FILE *, Object *, - // ObjectType *); where the return value tells if it's a valid object, - // Object * returns the reconstructed object and ObjectType * returns - // the object type. - - if (objectType == OTFEndOfFile) - { -//printf("Load: container size = %li\n", drawing->objects.size()); - return true; - } - else if (objectType == OTFContainer) - { - containerStack.push_back(currentTopContainer); - currentTopContainer = new Container(Vector(0, 0), currentTopContainer); - } - else if (objectType == OTFContainerEnd) - { - Container * containerToAdd = currentTopContainer; - currentTopContainer = containerStack.back(); - containerStack.pop_back(); - currentTopContainer->Add(containerToAdd); - } - else - { - currentTopContainer->Add(object); -//printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.size(), currentTopContainer->objects.size()); - } - } - - return false; -#else - return false; -#endif }