]> Shamusworld >> Repos - architektonas/blobdiff - src/fileio.cpp
Added miscellaneous features.
[architektonas] / src / fileio.cpp
index 1002dca87fecf22b79cbb2883253e9660fe6c34b..02ab2f577dc60af0a95f392a60e069b32b57b631 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
 }
 
 
@@ -302,6 +245,7 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile };
 /*static*/ Object * FileIO::GetObjectFromFile(FILE * file, bool extended/*= false*/)
 {
        char buffer[256];
+       char textBuffer[65536];
        int foundLayer = 0;
        /*int num =*/ fscanf(file, "%s", buffer);
        Object * obj = NULL;
@@ -356,6 +300,12 @@ if (errno)
                fscanf(file, "(%lf,%lf) %lf, %lf, %lf", &p.x, &p.y, &r, &a1, &a2);
                obj = (Object *)new Arc(p, r, a1, a2);
        }
+       else if (strcmp(buffer, "TEXT") == 0)
+       {
+               Point p;
+               fscanf(file, "(%lf,%lf) \"%[^\"]\"", &p.x, &p.y, textBuffer);
+               obj = (Object *)new Text(p, textBuffer);
+       }
        else if (strcmp(buffer, "DIMENSION") == 0)
        {
                Point p1, p2;
@@ -376,6 +326,8 @@ if (errno)
        {
                objectFileType = OTFEndOfFile;
        }
+       else
+               printf("Unknown object type '%s'...\n", buffer);
 
        if (obj != NULL)
        {