+/*static*/ bool FileIO::WriteObjectToFile(FILE * file, Object * obj)
+{
+ // Sanity check
+ if (obj == NULL)
+ return false;
+
+ 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);
+ break;
+ case OTCircle:
+ fprintf(file, "CIRCLE %i (%lf,%lf) %lf", 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]);
+ break;
+ case OTPolygon:
+ break;
+ case OTDimension:
+ 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);
+ break;
+ case OTSpline:
+ break;
+ case OTText:
+ fprintf(file, "TEXT %i (%lf,%lf) \"%s\"", obj->layer, obj->p[0].x, obj->p[0].y, ((Text *)obj)->s.c_str());
+ break;
+ case OTContainer:
+ {
+ Container * c = (Container *)obj;
+
+ if (c->topLevel == false)
+ fprintf(file, "CONTAINER %i\n", obj->layer);
+
+ std::vector<void *>::iterator i;
+
+ for(i=c->objects.begin(); i!=c->objects.end(); i++)
+ WriteObjectToFile(file, (Object *)*i);
+
+ if (c->topLevel == false)
+ fprintf(file, "ENDCONTAINER\n");
+
+ break;
+ }
+ default:
+ break;
+ }
+
+ if (obj->type != OTContainer)
+ fprintf(file, " (%i, %f, %i)\n", obj->color, obj->thickness, obj->style);
+
+ return true;
+}