]> Shamusworld >> Repos - architektonas/commitdiff
Fix loading/saving of V1.1 documents.
authorShamus Hammons <jlhamm@acm.org>
Tue, 7 Feb 2017 03:09:05 +0000 (21:09 -0600)
committerShamus Hammons <jlhamm@acm.org>
Tue, 7 Feb 2017 03:09:05 +0000 (21:09 -0600)
src/applicationwindow.cpp
src/drawingview.cpp
src/fileio.cpp

index a4c39b74fe96eace7ee7376055641138c6c49d1e..5093fb6c3b5334e475064af01dd8584a1fbbb7d4 100644 (file)
@@ -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);
 
index a86e857880402542b3bdf4d53c16d4bb8133f4e7..a88be252f9df4b9e3fb011bb700f4316a544a302 100644 (file)
@@ -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
index 1002dca87fecf22b79cbb2883253e9660fe6c34b..7f1a90a8d08b7e7c634545c0fb78b34dbc1b94c8 100644 (file)
@@ -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<Container *> 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
 }