]> Shamusworld >> Repos - architektonas/blobdiff - src/fileio.cpp
Added layer attribute to load/save code.
[architektonas] / src / fileio.cpp
index b64e5bd200fa05ac1223dd337133abe522c19896..931c5131653b64b89069ec995d67e6305fc25345 100644 (file)
@@ -15,6 +15,7 @@
 #include "fileio.h"
 
 //#include <stdio.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 #include <vector>
@@ -101,6 +102,14 @@ perpendicular, or an arbitrary angle. How to encode that information? It's not
 intrinsic to either the Line or the Circle, but is a function of the
 relationship between them by virtue of their connection.
 
+
+OTHER CONSIDERATIONS:
+---------------------
+
+  - Need to figure out how to store the Layer list (should layer list be optional?)
+  - Need to figure out how to store the Block list and blocks
+
+
 */
 
 enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc, OTFDimension,
@@ -159,7 +168,7 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc,
 
                if (objectType == OTFEndOfFile)
                {
-printf("Load: container size = %li\n", drawing->objects.size());
+//printf("Load: container size = %li\n", drawing->objects.size());
                        return true;
                }
                else if (objectType == OTFContainer)
@@ -177,7 +186,7 @@ printf("Load: container size = %li\n", drawing->objects.size());
                else
                {
                        currentTopContainer->Add(object);
-printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.size(), currentTopContainer->objects.size());
+//printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.size(), currentTopContainer->objects.size());
                }
        }
 
@@ -191,9 +200,38 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz
 /*static*/ bool FileIO::GetObjectFromFile(FILE * file, Object * parent, Object ** object, int * objectType)
 {
        char buffer[256];
-       fscanf(file, "%s ", buffer);
+       int foundLayer = 0;
+       int num = fscanf(file, "%s", buffer);
        bool recognized = false;
-//printf("Load: buffer = \"%s\"\n", buffer);
+       *object = NULL;
+//printf("FileIO: fscanf returned %i, buffer = \"%s\"\n", num, buffer);
+
+// The following fugliness is for troubleshooting. Can remove later.
+       if ((strcmp(buffer, "END") != 0) && (strcmp(buffer, "ENDCONTAINER") != 0))
+{
+errno = 0;
+               num = fscanf(file, " %i ", &foundLayer);
+//printf("FileIO: fscanf returned %i, foundLayer = %i\n", num, foundLayer);
+if (errno)
+{
+       if (errno == EAGAIN)
+               printf("EAGAIN\n");
+       else if (errno == EBADF)
+               printf("EBADF\n");
+       else if (errno == EILSEQ)
+               printf("EILSEQ\n");
+       else if (errno == EINTR)
+               printf("EINTR\n");
+       else if (errno == EINVAL)
+               printf("EINVAL\n");
+       else if (errno == ENOMEM)
+               printf("ENOMEM\n");
+       else if (errno == ERANGE)
+               printf("ERANGE\n");
+       else
+               printf("errno = %i\n", errno);
+}
+}
 
        if (strcmp(buffer, "LINE") == 0)
        {
@@ -248,6 +286,9 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz
                *objectType = OTFEndOfFile;
        }
 
+       if (*object)
+               (*object)->layer = foundLayer;
+
        return recognized;
 }