+/*static*/ bool FileIO::LoadVersion1_2(FILE * file, Container * drawing)
+{
+ int hidden, locked, props = 0;
+ char textBuffer[65536];
+
+ // 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++)
+ {
+ fscanf(file, "%i %i \"%[^\"]\"\n", &hidden, &locked, textBuffer);
+ Global::layerHidden.push_back(hidden ? true : false);
+ Global::layerLocked.push_back(locked ? true : false);
+ Global::layerName.push_back(textBuffer);
+ }
+
+ fscanf(file, "ACTIVE %i\n", &Global::activeLayer);
+
+ // 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.
+ std::vector<Container *> containerStack;
+ Container * currentTopContainer = drawing;
+
+ while (!feof(file))
+ {
+ // Reconstruct the object (extended format!)
+ Object * obj = GetObjectFromFile(file, true, true);
+
+ // objectFileType is set in GetObjectFromFile()...
+ if (objectFileType == OTFObject)
+ {
+ if (obj == NULL)
+ return false;
+
+ currentTopContainer->objects.push_back(obj);
+//printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.size(), currentTopContainer->objects.size());
+
+ // If the object is a container, push current TLC on the stack and
+ // set it as the new TLC
+ if (obj->type == OTContainer)
+ {
+ containerStack.push_back(currentTopContainer);
+ currentTopContainer = (Container *)obj;
+ }
+ }
+ else if (objectFileType == OTFContainerEnd)
+ {
+ // Add the extents of the current container
+ Rect r = ApplicationWindow::drawing->GetObjectExtents((Object *)currentTopContainer);
+ currentTopContainer->p[0] = r.TopLeft();
+ currentTopContainer->p[1] = r.BottomRight();
+//printf("Container extents: <%lf, %lf>, <%lf, %lf>\n", r.l, r.t, r.r, r.b);