diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index df0b090b2f..063cf64296 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -61,7 +61,7 @@ using namespace std; // Base::XMLReader: Constructors and Destructor // --------------------------------------------------------------------------- -Base::XMLReader::XMLReader(const char* FileName, std::istream& str) +Base::XMLReader::XMLReader(const char* FileName, std::istream& str) : DocumentSchema(0), ProgramVersion(""), FileVersion(0), Level(0), CharacterCount(0), ReadType(None), _File(FileName), _valid(false), _verbose(true) @@ -169,13 +169,15 @@ const char* Base::XMLReader::getAttribute (const char* AttrName) const { AttrMapType::const_iterator pos = AttrMap.find(AttrName); - if (pos != AttrMap.end()) + if (pos != AttrMap.end()) { return pos->second.c_str(); - else + } + else { // wrong name, use hasAttribute if not sure! - assert(0); - - return ""; + std::ostringstream msg; + msg << "Attribute: \"" << AttrName << "\" not found"; + THROWM(Base::AttributeError, msg.str()); + } } bool Base::XMLReader::hasAttribute (const char* AttrName) const @@ -293,7 +295,7 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const { // It's possible that not all objects inside the document could be created, e.g. if a module // is missing that would know these object types. So, there may be data files inside the zip - // file that cannot be read. We simply ignore these files. + // file that cannot be read. We simply ignore these files. // On the other hand, however, it could happen that a file should be read that is not part of // the zip file. This happens e.g. if a document is written without GUI up but is read with GUI // up. In this case the associated GUI document asks for its file which is not part of the ZIP @@ -311,7 +313,7 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const std::vector::const_iterator it = FileList.begin(); Base::SequencerLauncher seq("Importing project files...", FileList.size()); while (entry->isValid() && it != FileList.end()) { - std::vector::const_iterator jt = it; + std::vector::const_iterator jt = it; // Check if the current entry is registered, otherwise check the next registered files as soon as // both file names match while (jt != FileList.end() && entry->getName() != jt->FileName) @@ -505,6 +507,42 @@ void Base::XMLReader::resetErrors() { } +bool Base::XMLReader::testStatus(ReaderStatus pos) const +{ + return StatusBits.test((size_t)pos); +} + +void Base::XMLReader::setStatus(ReaderStatus pos, bool on) +{ + StatusBits.set((size_t)pos, on); +} + +void Base::XMLReader::setPartialRestore(bool on) +{ + setStatus(PartialRestore, on); + setStatus(PartialRestoreInDocumentObject, on); + setStatus(PartialRestoreInProperty, on); + setStatus(PartialRestoreInObject, on); +} + +void Base::XMLReader::clearPartialRestoreDocumentObject(void) +{ + setStatus(PartialRestoreInDocumentObject, false); + setStatus(PartialRestoreInProperty, false); + setStatus(PartialRestoreInObject, false); +} + +void Base::XMLReader::clearPartialRestoreProperty(void) +{ + setStatus(PartialRestoreInProperty, false); + setStatus(PartialRestoreInObject, false); +} + +void Base::XMLReader::clearPartialRestoreObject(void) +{ + setStatus(PartialRestoreInObject, false); +} + // ---------------------------------------------------------- Base::Reader::Reader(std::istream& str, const std::string& name, int version) diff --git a/src/Base/Reader.h b/src/Base/Reader.h index 2195ab42f2..d25304b0f8 100644 --- a/src/Base/Reader.h +++ b/src/Base/Reader.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -47,14 +48,14 @@ namespace Base { -/** The XML reader class +/** The XML reader class * This is an important helper class for the store and retrieval system - * of objects in FreeCAD. These classes mainly inherit the App::Persitance + * of objects in FreeCAD. These classes mainly inherit the App::Persitance * base class and implement the Restore() method. * \par - * The reader gets mainly initialized by the App::Document on retrieving a + * The reader gets mainly initialized by the App::Document on retrieving a * document out of a file. From there subsequently the Restore() method will - * by called on all object stored. + * by called on all object stored. * \par * A simple example is the Restore of App::PropertyString: * \code @@ -84,9 +85,9 @@ void PropertyContainer::Save (short indent,std::ostream &str) std::map::iterator it; for(it = Map.begin(); it != Map.end(); ++it) { - str << ind(indent+1) << "first << "\" type=\"" << it->second->getTypeId().getName() << "\">" ; + str << ind(indent+1) << "first << "\" type=\"" << it->second->getTypeId().getName() << "\">" ; it->second->Save(indent+2,str); - str << "" << endl; + str << "" << endl; } str << ind(indent) << "" << endl; } @@ -115,6 +116,12 @@ void PropertyContainer::Restore(Base::Reader &reader) class BaseExport XMLReader : public XERCES_CPP_NAMESPACE_QUALIFIER DefaultHandler { public: + enum ReaderStatus { + PartialRestore = 0, // This bit indicates that a partial restore took place somewhere in this Document + PartialRestoreInDocumentObject = 1, // This bit is local to the DocumentObject being read indicating a partial restore therein + PartialRestoreInProperty = 2, // Local to the Property + PartialRestoreInObject = 3 // Local to the object partially restored itself + }; /// open the file and read the first element XMLReader(const char* FileName, std::istream&); ~XMLReader(); @@ -173,6 +180,18 @@ public: /// Version of the file format int FileVersion; + /// sets simultaneously the global and local PartialRestore bits + void setPartialRestore(bool on); + + void clearPartialRestoreDocumentObject(void); + void clearPartialRestoreProperty(void); + void clearPartialRestoreObject(void); + + /// return the status bits + bool testStatus(ReaderStatus pos) const; + /// set the status bits + void setStatus(ReaderStatus pos, bool on); + protected: /// read the next element bool read(void); @@ -252,6 +271,8 @@ protected: }; std::vector FileList; std::vector FileNames; + + std::bitset<32> StatusBits; }; class BaseExport Reader : public std::istream