23
#include "PreCompiled.h"
28
#include <QCoreApplication>
29
#include <App/Document.h>
30
#include <Base/Reader.h>
31
#include <Base/Writer.h>
33
#include "MergeDocuments.h"
37
namespace sp = std::placeholders;
41
class XMLMergeReader : public Base::XMLReader
44
XMLMergeReader(std::map<std::string, std::string>& name, const char* FileName, std::istream& str)
45
: Base::XMLReader(FileName, str), nameMap(name)
48
void addName(const char* s1, const char* s2) override
52
const char* getName(const char* name) const override
54
std::map<std::string, std::string>::const_iterator it = nameMap.find(name);
55
if (it != nameMap.end())
56
return it->second.c_str();
60
bool doNameMapping() const override
68
std::map<std::string, std::string>& nameMap;
69
using PropertyTag = std::pair<std::string, std::string>;
70
std::stack<PropertyTag> propertyStack;
74
MergeDocuments::MergeDocuments(App::Document* doc)
78
connectExport = doc->signalExportObjects.connect
79
(std::bind(&MergeDocuments::exportObject, this, sp::_1, sp::_2));
80
connectImport = doc->signalImportObjects.connect
81
(std::bind(&MergeDocuments::importObject, this, sp::_1, sp::_2));
84
QCoreApplication* app = QCoreApplication::instance();
85
if (app && app->inherits("QApplication")) {
90
MergeDocuments::~MergeDocuments()
92
connectExport.disconnect();
93
connectImport.disconnect();
96
unsigned int MergeDocuments::getMemSize () const
101
std::vector<App::DocumentObject*>
102
MergeDocuments::importObjects(std::istream& input)
104
this->nameMap.clear();
105
this->stream = new zipios::ZipInputStream(input);
106
XMLMergeReader reader(this->nameMap,"<memory>", *stream);
107
reader.setVerbose(isVerbose());
108
std::vector<App::DocumentObject*> objs = appdoc->importObjects(reader);
111
this->stream = nullptr;
116
void MergeDocuments::importObject(const std::vector<App::DocumentObject*>& o, Base::XMLReader & r)
120
r.readFiles(*this->stream);
123
void MergeDocuments::exportObject(const std::vector<App::DocumentObject*>& o, Base::Writer & w)
129
void MergeDocuments::Save (Base::Writer & w) const
133
w.addFile("GuiDocument.xml", this);
137
void MergeDocuments::Restore(Base::XMLReader &r)
141
r.addFile("GuiDocument.xml", this);
145
void MergeDocuments::SaveDocFile (Base::Writer & w) const
148
appdoc->signalExportViewObjects(this->objects, w);
151
void MergeDocuments::RestoreDocFile(Base::Reader & r)
154
appdoc->signalImportViewObjects(this->objects, r, this->nameMap);