+ // 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);
+
+ // Container is done, so pop the stack to get back the previous TLC
+ currentTopContainer = containerStack.back();
+ containerStack.pop_back();
+ }
+ else if (objectFileType == OTFEndOfFile)
+ {
+//printf("Load: container size = %li\n", drawing->objects.size());
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/*static*/ Object * FileIO::GetObjectFromFile(FILE * file, bool extended/*= false*/, bool ext2/*= false*/)