X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ffileio.cpp;h=27ed4f3c3ccec27eacee2403c6bc0b891863c5f3;hb=4bc000ba003a53fb11428a2eb71e3b4471a15c7a;hp=4a1c25f1de1c47bffd33280697acb425789eafe7;hpb=676007c81e292079daaa7188f4fbf2757ae77ef8;p=architektonas diff --git a/src/fileio.cpp b/src/fileio.cpp index 4a1c25f..27ed4f3 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -15,14 +15,16 @@ #include "fileio.h" //#include +#include #include #include #include -#include "arc.h" -#include "circle.h" -#include "container.h" -#include "dimension.h" -#include "line.h" +//#include "arc.h" +//#include "circle.h" +//#include "container.h" +//#include "dimension.h" +//#include "line.h" +#include "structs.h" /* How to handle connected objects @@ -101,10 +103,18 @@ 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 ObjectType { OTContainer, OTContainerEnd, OTLine, OTCircle, OTArc, OTDimension, - OTPolygon, OTText, OTImage, OTBlock, OTEndOfFile }; +enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc, OTFDimension, + OTFPolygon, OTFText, OTFImage, OTFBlock, OTFEndOfFile }; /*static*/ bool FileIO::SaveAtnsFile(FILE * file, Container * object) @@ -116,7 +126,7 @@ enum ObjectType { OTContainer, OTContainerEnd, OTLine, OTCircle, OTArc, OTDimens enumerates all objects within itself. */ fprintf(file, "ARCHITEKTONAS DRAWING V1.0\n"); -#if 1 +#if 0 object->Enumerate(file); fprintf(file, "END\n"); return true; @@ -140,7 +150,7 @@ enum ObjectType { OTContainer, OTContainerEnd, OTLine, OTCircle, OTArc, OTDimens add objects to it until an "endContainer" marker is found. This will require a stack to maintain the current Container. */ -#if 1 +#if 0 std::vector containerStack; Container * currentTopContainer = drawing;//new Container(Vector(0, 0)); Object * object; @@ -157,17 +167,17 @@ enum ObjectType { OTContainer, OTContainerEnd, OTLine, OTCircle, OTArc, OTDimens // where the return value tells if it's a valid object, Object * returns the // reconstructed object and ObjectType * returns the object type. - if (objectType == OTEndOfFile) + 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 == OTContainer) + else if (objectType == OTFContainer) { containerStack.push_back(currentTopContainer); currentTopContainer = new Container(Vector(0, 0), currentTopContainer); } - else if (objectType == OTContainerEnd) + else if (objectType == OTFContainerEnd) { Container * containerToAdd = currentTopContainer; currentTopContainer = containerStack.back(); @@ -177,7 +187,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()); } } @@ -190,10 +200,40 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz /*static*/ bool FileIO::GetObjectFromFile(FILE * file, Object * parent, Object ** object, int * objectType) { +#if 0 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) { @@ -203,7 +243,7 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz fscanf(file, "(%lf,%lf) (%lf,%lf)", &v1.x, &v1.y, &v2.x, &v2.y); //printf(" Number of params recognized: %i\n", n); *object = new Line(v1, v2, parent); - *objectType = OTLine; + *objectType = OTFLine; } else if (strcmp(buffer, "CIRCLE") == 0) { @@ -212,7 +252,7 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz double r; fscanf(file, "(%lf,%lf) %lf", &v.x, &v.y, &r); *object = new Circle(v, r, parent); - *objectType = OTCircle; + *objectType = OTFCircle; } else if (strcmp(buffer, "ARC") == 0) { @@ -221,7 +261,7 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz double r, a1, a2; fscanf(file, "(%lf,%lf) %lf, %lf, %lf", &v.x, &v.y, &r, &a1, &a2); *object = new Arc(v, r, a1, a2, parent); - *objectType = OTArc; + *objectType = OTFArc; } else if (strcmp(buffer, "DIMENSION") == 0) { @@ -230,24 +270,30 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz DimensionType type; fscanf(file, "(%lf,%lf) (%lf,%lf) %i", &v1.x, &v1.y, &v2.x, &v2.y, &type); *object = new Dimension(v1, v2, type, parent); - *objectType = OTDimension; + *objectType = OTFDimension; } else if (strcmp(buffer, "CONTAINER") == 0) { recognized = true; - *objectType = OTContainer; + *objectType = OTFContainer; } else if (strcmp(buffer, "ENDCONTAINER") == 0) { recognized = true; - *objectType = OTContainerEnd; + *objectType = OTFContainerEnd; } else if (strcmp(buffer, "END") == 0) { recognized = true; - *objectType = OTEndOfFile; + *objectType = OTFEndOfFile; } + if (*object) + (*object)->layer = foundLayer; + return recognized; +#else + return false; +#endif }