]> Shamusworld >> Repos - architektonas/blobdiff - src/fileio.cpp
Further progress on Polylines: Polylines can be selected and moved.
[architektonas] / src / fileio.cpp
index 1b11902e37b672f1f6a72bd6dc443894acce5efd..8058a41d490aba1d0e7b79847e8067326fb61a3c 100644 (file)
@@ -108,11 +108,8 @@ 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, OTFPolygon, OTFText, OTFImage, OTFBlock, OTFEndOfFile };
 enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile };
 
 // Instantiate class variables
@@ -127,6 +124,12 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile };
           Container, otherwise it enumerates all objects within itself. */
 
        fprintf(file, "ARCHITEKTONAS DRAWING V1.2\n");
+       fprintf(file, "PROPERTIES 4\n");
+       fprintf(file, "BASE_UNIT %i\n", c->baseUnit);
+       fprintf(file, "UNIT_STYLE %i\n", c->unitStyle);
+       fprintf(file, "DEC_PREC %i\n", c->decimalPrecision);
+       fprintf(file, "FRAC_PREC %i\n", c->fractionalPrecision);
+
        fprintf(file, "LAYERS %i\n", Global::numLayers);
 
        for(int i=0; i<Global::numLayers; i++)
@@ -156,7 +159,6 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile };
        else if (version == 1.2f)
                return LoadVersion1_2(file, drawing);
 
-//printf("LoadAtnsFile: Could not locate version! (version=%f)\n", version);
        return false;
 }
 
@@ -272,10 +274,21 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile };
 
 /*static*/ bool FileIO::LoadVersion1_2(FILE * file, Container * drawing)
 {
-       int hidden, locked;
+       int hidden, locked, props = 0;
        char textBuffer[65536];
 
-       // Load layer information first
+       // Load drawing properties, if any, first
+       fscanf(file, "PROPERTIES %i\n", &props);
+
+       if (props == 4)
+       {
+               fscanf(file, "BASE_UNIT %i\n", &(drawing->baseUnit));
+               fscanf(file, "UNIT_STYLE %i\n", &(drawing->unitStyle));
+               fscanf(file, "DEC_PREC %i\n", &(drawing->decimalPrecision));
+               fscanf(file, "FRAC_PREC %i\n", &(drawing->fractionalPrecision));
+       }
+
+       // Load layer information next
        fscanf(file, "LAYERS %i\n", &Global::numLayers);
 
        for(int i=0; i<Global::numLayers; i++)
@@ -397,6 +410,26 @@ 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, "POLYLINE") == 0)
+       {
+               long int size;
+               std::vector<Point> pts;
+               uint32_t color;
+               float thickness;
+               int style;
+
+               fscanf(file, "(%li)", &size);
+               fscanf(file, " (%i, %f, %i)\n", &color, &thickness, &style);
+
+               for(int i=0; i<size; i++)
+               {
+                       Point p;
+                       fscanf(file, "(%lf,%lf,%lf)\n", &p.x, &p.y, &p.b);
+                       pts.push_back(p);
+               }
+
+               obj = (Object *)new Polyline(pts, thickness, color, style);
+       }
        else if (strcmp(buffer, "TEXT") == 0)
        {
                Point p;
@@ -435,7 +468,7 @@ if (errno)
        {
                obj->layer = foundLayer;
 
-               if (extended && (obj->type != OTContainer))
+               if (extended && (obj->type != OTContainer) && (obj->type != OTPolyline))
                {
                        fscanf(file, " (%i, %f, %i)\n", &obj->color, &obj->thickness, &obj->style);
                }
@@ -453,21 +486,30 @@ if (errno)
        switch (obj->type)
        {
        case OTLine:
-               fprintf(file, "LINE %i (%lf,%lf) (%lf,%lf)", obj->layer, obj->p[0].x, obj->p[0].y, obj->p[1].x, obj->p[1].y);
+               fprintf(file, "LINE %i (%.16lf,%.16lf) (%.16lf,%.16lf)", obj->layer, obj->p[0].x, obj->p[0].y, obj->p[1].x, obj->p[1].y);
                break;
        case OTCircle:
-               fprintf(file, "CIRCLE %i (%lf,%lf) %lf", obj->layer, obj->p[0].x, obj->p[0].y, obj->radius[0]);
+               fprintf(file, "CIRCLE %i (%.16lf,%.16lf) %.16lf", obj->layer, obj->p[0].x, obj->p[0].y, obj->radius[0]);
                break;
        case OTEllipse:
                break;
        case OTArc:
-               fprintf(file, "ARC %i (%lf,%lf) %lf, %lf, %lf", obj->layer, obj->p[0].x, obj->p[0].y, obj->radius[0], obj->angle[0], obj->angle[1]);
+               fprintf(file, "ARC %i (%.16lf,%.16lf) %.16lf, %.16lf, %.16lf", obj->layer, obj->p[0].x, obj->p[0].y, obj->radius[0], obj->angle[0], obj->angle[1]);
                break;
-       case OTPolygon:
+       case OTPolyline:
+       {
+               Polyline * p = (Polyline *)obj;
+               fprintf(file, "POLYLINE %i (%li)", p->layer, p->points.size());
+               fprintf(file, " (%i, %f, %i)\n", obj->color, obj->thickness, obj->style);
+
+               for(long unsigned int i=0; i<p->points.size(); i++)
+               {
+                       fprintf(file, "(%.16lf,%.16lf,%.16lf)\n", p->points[i].x, p->points[i].y, p->points[i].b);
+               }
+       }
                break;
        case OTDimension:
-//             fprintf(file, "DIMENSION %i (%lf,%lf) (%lf,%lf) %i\n", layer, position.x, position.y, endpoint.x, endpoint.y, dimensionType);
-               fprintf(file, "DIMENSION %i (%lf,%lf) (%lf,%lf) %i %lf", obj->layer, obj->p[0].x, obj->p[0].y, obj->p[1].x, obj->p[1].y, ((Dimension *)obj)->subtype, ((Dimension *)obj)->offset);
+               fprintf(file, "DIMENSION %i (%.16lf,%.16lf) (%.16lf,%.16lf) %i %lf", obj->layer, obj->p[0].x, obj->p[0].y, obj->p[1].x, obj->p[1].y, ((Dimension *)obj)->subtype, ((Dimension *)obj)->offset);
                break;
        case OTSpline:
                break;
@@ -495,7 +537,7 @@ if (errno)
                break;
        }
 
-       if (obj->type != OTContainer)
+       if ((obj->type != OTContainer) && (obj->type != OTPolyline))
                fprintf(file, " (%i, %f, %i)\n", obj->color, obj->thickness, obj->style);
 
        return true;