1
/***************************************************************************
2
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
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
131
// Save view provider stuff
133
w.addFile("GuiDocument.xml", this);
137
void MergeDocuments::Restore(Base::XMLReader &r)
139
// Restore view provider stuff
141
r.addFile("GuiDocument.xml", this);
145
void MergeDocuments::SaveDocFile (Base::Writer & w) const
147
// Save view provider stuff
148
appdoc->signalExportViewObjects(this->objects, w);
151
void MergeDocuments::RestoreDocFile(Base::Reader & r)
153
// Restore view provider stuff
154
appdoc->signalImportViewObjects(this->objects, r, this->nameMap);