Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ support of merging projects on App level
- Loading branch information
Showing
8 changed files
with
266 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> * | ||
* * | ||
* This file is part of the FreeCAD CAx development system. * | ||
* * | ||
* This library is free software; you can redistribute it and/or * | ||
* modify it under the terms of the GNU Library General Public * | ||
* License as published by the Free Software Foundation; either * | ||
* version 2 of the License, or (at your option) any later version. * | ||
* * | ||
* This library is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU Library General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Library General Public * | ||
* License along with this library; see the file COPYING.LIB. If not, * | ||
* write to the Free Software Foundation, Inc., 59 Temple Place, * | ||
* Suite 330, Boston, MA 02111-1307, USA * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "PreCompiled.h" | ||
#ifndef _PreComp_ | ||
# include <stack> | ||
# include <boost/bind.hpp> | ||
#endif | ||
#include "MergeDocuments.h" | ||
#include <Base/Console.h> | ||
#include <Base/Reader.h> | ||
#include <Base/Writer.h> | ||
#include <App/Document.h> | ||
#include <App/DocumentObject.h> | ||
|
||
using namespace App; | ||
|
||
namespace App { | ||
|
||
class XMLMergeReader : public Base::XMLReader | ||
{ | ||
public: | ||
XMLMergeReader(std::map<std::string, std::string>& name, const char* FileName, std::istream& str) | ||
: Base::XMLReader(FileName, str), nameMap(name) | ||
{} | ||
|
||
void addName(const char* s1, const char* s2) | ||
{ | ||
nameMap[s1] = s2; | ||
} | ||
const char* getName(const char* name) const | ||
{ | ||
std::map<std::string, std::string>::const_iterator it = nameMap.find(name); | ||
if (it != nameMap.end()) | ||
return it->second.c_str(); | ||
else | ||
return name; | ||
} | ||
bool doNameMapping() const | ||
{ | ||
return true; | ||
} | ||
protected: | ||
void startElement(const XMLCh* const uri, const XMLCh* const localname, | ||
const XMLCh* const qname, | ||
const XERCES_CPP_NAMESPACE_QUALIFIER Attributes& attrs) | ||
{ | ||
Base::XMLReader::startElement(uri, localname, qname, attrs); | ||
if (LocalName == "Property") | ||
propertyStack.push(std::make_pair(AttrMap["name"],AttrMap["type"])); | ||
|
||
if (!propertyStack.empty()) { | ||
// replace the stored object name with the real one | ||
if (LocalName == "Link" || LocalName == "LinkSub" || (LocalName == "String" && propertyStack.top().first == "Label")) { | ||
for (std::map<std::string, std::string>::iterator it = AttrMap.begin(); it != AttrMap.end(); ++it) { | ||
std::map<std::string, std::string>::const_iterator jt = nameMap.find(it->second); | ||
if (jt != nameMap.end()) | ||
it->second = jt->second; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void endElement(const XMLCh* const uri, const XMLCh *const localname, const XMLCh *const qname) | ||
{ | ||
Base::XMLReader::endElement(uri, localname, qname); | ||
if (LocalName == "Property") | ||
propertyStack.pop(); | ||
} | ||
|
||
private: | ||
std::map<std::string, std::string>& nameMap; | ||
typedef std::pair<std::string, std::string> PropertyTag; | ||
std::stack<PropertyTag> propertyStack; | ||
}; | ||
} | ||
|
||
MergeDocuments::MergeDocuments(App::Document* doc) : appdoc(doc) | ||
{ | ||
connectExport = doc->signalExportObjects.connect | ||
(boost::bind(&MergeDocuments::exportObject, this, _1, _2)); | ||
connectImport = doc->signalImportObjects.connect | ||
(boost::bind(&MergeDocuments::importObject, this, _1, _2)); | ||
} | ||
|
||
MergeDocuments::~MergeDocuments() | ||
{ | ||
connectExport.disconnect(); | ||
connectImport.disconnect(); | ||
} | ||
|
||
unsigned int MergeDocuments::getMemSize (void) const | ||
{ | ||
return 0; | ||
} | ||
|
||
std::vector<App::DocumentObject*> | ||
MergeDocuments::importObjects(std::istream& input) | ||
{ | ||
this->nameMap.clear(); | ||
this->stream = new zipios::ZipInputStream(input); | ||
XMLMergeReader reader(this->nameMap,"<memory>", *stream); | ||
std::vector<App::DocumentObject*> objs = appdoc->importObjects(reader); | ||
|
||
delete this->stream; | ||
this->stream = 0; | ||
|
||
return objs; | ||
} | ||
|
||
void MergeDocuments::importObject(const std::vector<App::DocumentObject*>& o, Base::XMLReader & r) | ||
{ | ||
objects = o; | ||
Restore(r); | ||
r.readFiles(*this->stream); | ||
} | ||
|
||
void MergeDocuments::exportObject(const std::vector<App::DocumentObject*>& o, Base::Writer & w) | ||
{ | ||
objects = o; | ||
Save(w); | ||
} | ||
|
||
void MergeDocuments::Save (Base::Writer & w) const | ||
{ | ||
// Save view provider stuff | ||
} | ||
|
||
void MergeDocuments::Restore(Base::XMLReader &r) | ||
{ | ||
// Restore view provider stuff | ||
} | ||
|
||
void MergeDocuments::SaveDocFile (Base::Writer & w) const | ||
{ | ||
// Save view provider stuff | ||
} | ||
|
||
void MergeDocuments::RestoreDocFile(Base::Reader & r) | ||
{ | ||
// Restore view provider stuff | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> * | ||
* * | ||
* This file is part of the FreeCAD CAx development system. * | ||
* * | ||
* This library is free software; you can redistribute it and/or * | ||
* modify it under the terms of the GNU Library General Public * | ||
* License as published by the Free Software Foundation; either * | ||
* version 2 of the License, or (at your option) any later version. * | ||
* * | ||
* This library is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU Library General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Library General Public * | ||
* License along with this library; see the file COPYING.LIB. If not, * | ||
* write to the Free Software Foundation, Inc., 59 Temple Place, * | ||
* Suite 330, Boston, MA 02111-1307, USA * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#ifndef APP_MERGEDOCUMENTS_H | ||
#define APP_MERGEDOCUMENTS_H | ||
|
||
#include <boost/signals.hpp> | ||
#include <Base/Persistence.h> | ||
|
||
namespace zipios { | ||
class ZipInputStream; | ||
} | ||
|
||
namespace App { | ||
class Document; | ||
class DocumentObject; | ||
class AppExport MergeDocuments : public Base::Persistence | ||
{ | ||
public: | ||
MergeDocuments(App::Document* doc); | ||
~MergeDocuments(); | ||
unsigned int getMemSize (void) const; | ||
std::vector<App::DocumentObject*> importObjects(std::istream&); | ||
void importObject(const std::vector<App::DocumentObject*>& o, Base::XMLReader & r); | ||
void exportObject(const std::vector<App::DocumentObject*>& o, Base::Writer & w); | ||
void Save (Base::Writer & w) const; | ||
void Restore(Base::XMLReader &r); | ||
void SaveDocFile (Base::Writer & w) const; | ||
void RestoreDocFile(Base::Reader & r); | ||
|
||
private: | ||
zipios::ZipInputStream* stream; | ||
App::Document* appdoc; | ||
std::vector<App::DocumentObject*> objects; | ||
std::map<std::string, std::string> nameMap; | ||
typedef boost::signals::connection Connection; | ||
Connection connectExport; | ||
Connection connectImport; | ||
}; | ||
|
||
} // namespace App | ||
|
||
#endif // APP_MERGEDOCUMENTS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters