0000827: Sketch copy deletes all constraints
This commit is contained in:
parent
94b0102dc7
commit
cf499792e6
|
@ -771,32 +771,28 @@ void Document::exportObjects(const std::vector<App::DocumentObject*>& obj,
|
|||
}
|
||||
|
||||
std::vector<App::DocumentObject*>
|
||||
Document::importObjects(std::istream& input)
|
||||
Document::readObjects(Base::XMLReader& reader)
|
||||
{
|
||||
std::vector<App::DocumentObject*> objs;
|
||||
zipios::ZipInputStream zipstream(input);
|
||||
Base::XMLReader reader("<memory>", zipstream);
|
||||
|
||||
int i,Cnt;
|
||||
reader.readElement("Document");
|
||||
long scheme = reader.getAttributeAsInteger("SchemaVersion");
|
||||
reader.DocumentSchema = scheme;
|
||||
|
||||
// read the object types
|
||||
std::map<std::string, std::string> nameMap;
|
||||
reader.readElement("Objects");
|
||||
Cnt = reader.getAttributeAsInteger("Count");
|
||||
for (i=0 ;i<Cnt ;i++) {
|
||||
int Cnt = reader.getAttributeAsInteger("Count");
|
||||
for (int i=0 ;i<Cnt ;i++) {
|
||||
reader.readElement("Object");
|
||||
string type = reader.getAttribute("type");
|
||||
string name = reader.getAttribute("name");
|
||||
std::string type = reader.getAttribute("type");
|
||||
std::string name = reader.getAttribute("name");
|
||||
|
||||
try {
|
||||
// Use name from XML as is and do NOT remove trailing digits because
|
||||
// otherwise we may cause a dependency to itself
|
||||
// Example: Object 'Cut001' references object 'Cut' and removing the
|
||||
// digits we make an object 'Cut' referencing itself.
|
||||
App::DocumentObject* o = addObject(type.c_str(),name.c_str());
|
||||
objs.push_back(o);
|
||||
// use this name for the later access because an object with
|
||||
// the given name may already exist
|
||||
nameMap[name] = o->getNameInDocument();
|
||||
reader.addName(name.c_str(), o->getNameInDocument());
|
||||
}
|
||||
catch (Base::Exception&) {
|
||||
Base::Console().Message("Cannot create object '%s'\n", name.c_str());
|
||||
|
@ -807,9 +803,9 @@ Document::importObjects(std::istream& input)
|
|||
// read the features itself
|
||||
reader.readElement("ObjectData");
|
||||
Cnt = reader.getAttributeAsInteger("Count");
|
||||
for (i=0 ;i<Cnt ;i++) {
|
||||
for (int i=0 ;i<Cnt ;i++) {
|
||||
reader.readElement("Object");
|
||||
std::string name = nameMap[reader.getAttribute("name")];
|
||||
std::string name = reader.getName(reader.getAttribute("name"));
|
||||
DocumentObject* pObj = getObject(name.c_str());
|
||||
if (pObj) { // check if this feature has been registered
|
||||
pObj->StatusBits.set(4);
|
||||
|
@ -820,12 +816,26 @@ Document::importObjects(std::istream& input)
|
|||
}
|
||||
reader.readEndElement("ObjectData");
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*>
|
||||
Document::importObjects(Base::XMLReader& reader)
|
||||
{
|
||||
reader.readElement("Document");
|
||||
long scheme = reader.getAttributeAsInteger("SchemaVersion");
|
||||
reader.DocumentSchema = scheme;
|
||||
|
||||
std::vector<App::DocumentObject*> objs = readObjects(reader);
|
||||
|
||||
reader.readEndElement("Document");
|
||||
signalImportObjects(objs, reader);
|
||||
reader.readFiles(zipstream);
|
||||
|
||||
// reset all touched
|
||||
for (std::vector<DocumentObject*>::iterator it= objs.begin();it!=objs.end();++it)
|
||||
for (std::vector<DocumentObject*>::iterator it= objs.begin();it!=objs.end();++it) {
|
||||
(*it)->onDocumentRestored();
|
||||
(*it)->purgeTouched();
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ public:
|
|||
void restore (void);
|
||||
void exportObjects(const std::vector<App::DocumentObject*>&, std::ostream&);
|
||||
void exportGraphviz(std::ostream&);
|
||||
std::vector<App::DocumentObject*> importObjects(std::istream&);
|
||||
std::vector<App::DocumentObject*> importObjects(Base::XMLReader& reader);
|
||||
/// Opens the document from its file name
|
||||
//void open (void);
|
||||
/// Is the document already saved to a file
|
||||
|
@ -266,6 +266,7 @@ protected:
|
|||
/// checks if a valid transaction is open
|
||||
void _checkTransaction(void);
|
||||
void breakDependency(DocumentObject* pcObject, bool clear);
|
||||
std::vector<App::DocumentObject*> readObjects(Base::XMLReader& reader);
|
||||
|
||||
void onChanged(const Property* prop);
|
||||
/// callback from the Document objects before property will be changed
|
||||
|
|
|
@ -360,6 +360,15 @@ bool Base::XMLReader::isRegistered(Base::Persistence *Object) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void Base::XMLReader::addName(const char*, const char*)
|
||||
{
|
||||
}
|
||||
|
||||
const char* Base::XMLReader::getName(const char* name) const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Base::XMLReader: Implementation of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -159,6 +159,8 @@ public:
|
|||
/// get all registered file names
|
||||
const std::vector<std::string>& getFilenames() const;
|
||||
bool isRegistered(Base::Persistence *Object) const;
|
||||
virtual void addName(const char*, const char*);
|
||||
virtual const char* getName(const char*) const;
|
||||
//@}
|
||||
|
||||
/// Schema Version of the document
|
||||
|
|
|
@ -42,10 +42,22 @@ namespace Gui {
|
|||
class XMLMergeReader : public Base::XMLReader
|
||||
{
|
||||
public:
|
||||
XMLMergeReader(const std::map<std::string, std::string>& name, const char* FileName, std::istream& str)
|
||||
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;
|
||||
}
|
||||
protected:
|
||||
void startElement(const XMLCh* const uri, const XMLCh* const localname,
|
||||
const XMLCh* const qname,
|
||||
|
@ -75,7 +87,7 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
const std::map<std::string, std::string>& nameMap;
|
||||
std::map<std::string, std::string>& nameMap;
|
||||
typedef std::pair<std::string, std::string> PropertyTag;
|
||||
std::stack<PropertyTag> propertyStack;
|
||||
};
|
||||
|
@ -104,64 +116,14 @@ unsigned int MergeDocuments::getMemSize (void) const
|
|||
std::vector<App::DocumentObject*>
|
||||
MergeDocuments::importObjects(std::istream& input)
|
||||
{
|
||||
//std::map<std::string, std::string> nameMap;
|
||||
std::vector<App::DocumentObject*> objs;
|
||||
zipios::ZipInputStream zipstream(input);
|
||||
XMLMergeReader reader(nameMap,"<memory>", zipstream);
|
||||
this->nameMap.clear();
|
||||
this->stream = new zipios::ZipInputStream(input);
|
||||
XMLMergeReader reader(this->nameMap,"<memory>", *stream);
|
||||
std::vector<App::DocumentObject*> objs = appdoc->importObjects(reader);
|
||||
|
||||
int i,Cnt;
|
||||
reader.readElement("Document");
|
||||
long scheme = reader.getAttributeAsInteger("SchemaVersion");
|
||||
reader.DocumentSchema = scheme;
|
||||
delete this->stream;
|
||||
this->stream = 0;
|
||||
|
||||
// read the object types
|
||||
nameMap.clear();
|
||||
reader.readElement("Objects");
|
||||
Cnt = reader.getAttributeAsInteger("Count");
|
||||
for (i=0 ;i<Cnt ;i++) {
|
||||
reader.readElement("Object");
|
||||
std::string type = reader.getAttribute("type");
|
||||
std::string name = reader.getAttribute("name");
|
||||
|
||||
try {
|
||||
// Use name from XML as is and do NOT remove trailing digits because
|
||||
// otherwise we may cause a dependency to itself
|
||||
// Example: Object 'Cut001' references object 'Cut' and removing the
|
||||
// digits we make an object 'Cut' referencing itself.
|
||||
App::DocumentObject* o = appdoc->addObject(type.c_str(),name.c_str());
|
||||
objs.push_back(o);
|
||||
// use this name for the later access because an object with
|
||||
// the given name may already exist
|
||||
nameMap[name] = o->getNameInDocument();
|
||||
}
|
||||
catch (Base::Exception&) {
|
||||
Base::Console().Message("Cannot create object '%s'\n", name.c_str());
|
||||
}
|
||||
}
|
||||
reader.readEndElement("Objects");
|
||||
|
||||
// read the features itself
|
||||
reader.readElement("ObjectData");
|
||||
Cnt = reader.getAttributeAsInteger("Count");
|
||||
for (i=0 ;i<Cnt ;i++) {
|
||||
reader.readElement("Object");
|
||||
std::string name = nameMap[reader.getAttribute("name")];
|
||||
App::DocumentObject* pObj = appdoc->getObject(name.c_str());
|
||||
if (pObj) { // check if this feature has been registered
|
||||
// pObj->StatusBits.set(4);
|
||||
pObj->Restore(reader);
|
||||
// pObj->StatusBits.reset(4);
|
||||
}
|
||||
reader.readEndElement("Object");
|
||||
}
|
||||
reader.readEndElement("ObjectData");
|
||||
|
||||
reader.readEndElement("Document");
|
||||
appdoc->signalImportObjects(objs, reader);
|
||||
reader.readFiles(zipstream);
|
||||
// reset all touched
|
||||
for (std::vector<App::DocumentObject*>::iterator it= objs.begin();it!=objs.end();++it)
|
||||
(*it)->purgeTouched();
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
@ -173,6 +135,8 @@ void MergeDocuments::importObject(const std::vector<App::DocumentObject*>& o, Ba
|
|||
if (vp) vp->hide();
|
||||
}
|
||||
Restore(r);
|
||||
|
||||
r.readFiles(*this->stream);
|
||||
}
|
||||
|
||||
void MergeDocuments::exportObject(const std::vector<App::DocumentObject*>& o, Base::Writer & w)
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include <boost/signals.hpp>
|
||||
#include <Base/Persistence.h>
|
||||
|
||||
namespace zipios {
|
||||
class ZipInputStream;
|
||||
}
|
||||
namespace App {
|
||||
class Document;
|
||||
class DocumentObject;
|
||||
|
@ -49,6 +52,7 @@ public:
|
|||
void RestoreDocFile(Base::Reader & r);
|
||||
|
||||
private:
|
||||
zipios::ZipInputStream* stream;
|
||||
App::Document* appdoc;
|
||||
Gui::Document* document;
|
||||
std::vector<App::DocumentObject*> objects;
|
||||
|
|
Loading…
Reference in New Issue
Block a user