From c752d0cdf9a8a7574bd1895eecb06cd76455bdbb Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Tue, 9 May 2023 19:28:17 -0300 Subject: [PATCH 01/25] Added per project Unit System feature --- src/Gui/Application.cpp | 15 +++++++++++ src/Gui/DlgGeneral.ui | 36 +++++++++++++++++++++++--- src/Gui/DlgGeneralImp.cpp | 53 ++++++++++++++++++++++++++++++++++++++- src/Gui/DlgGeneralImp.h | 1 + src/Gui/Document.cpp | 45 +++++++++++++++++++++++++++++++++ src/Gui/Document.h | 6 +++++ 6 files changed, 151 insertions(+), 5 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 4ba6c4b2d3..c7621de622 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -54,6 +54,8 @@ #include #include +#include + #include #include @@ -927,6 +929,19 @@ void Application::slotActiveDocument(const App::Document& Doc) Py::Module("FreeCADGui").setAttr(std::string("ActiveDocument"),Py::None()); } } + + //Set Unit System. + int projectUnitSystemIndex = doc->second->getProjectUnitSystem(); + int ignore = doc->second->getProjectUnitSystemIgnore(); + if( projectUnitSystemIndex >= 0 && !ignore ){//is valid + Base::UnitsApi::setSchema(static_cast(projectUnitSystemIndex)); + }else{// set up Unit system default + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Units"); + Base::UnitsApi::setSchema((Base::UnitSystem)hGrp->GetInt("UserSchema",0)); + Base::UnitsApi::setDecimals(hGrp->GetInt("Decimals", Base::UnitsApi::getDecimals())); + } + signalActiveDocument(*doc->second); updateActions(); } diff --git a/src/Gui/DlgGeneral.ui b/src/Gui/DlgGeneral.ui index 70a13f7c8d..ef0816048b 100644 --- a/src/Gui/DlgGeneral.ui +++ b/src/Gui/DlgGeneral.ui @@ -87,14 +87,42 @@ + + + + Project Unit system: + + + + + + + + Unit system used for display metrics stored in project + + + + + + + + If enabled, Unit System stored in project will be ignored. + + + Ignore + + + + + Minimum fractional inch: - + Minimum fractional inch to be displayed @@ -136,14 +164,14 @@ - + Number format: - + UseLocaleFormatting @@ -168,7 +196,7 @@ - + If enabled, numerical keypad decimal separator diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index 9edb20b4e1..65feac3df1 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -38,6 +38,8 @@ #include #include +#include + #include "DlgGeneralImp.h" #include "ui_DlgGeneral.h" #include "Action.h" @@ -50,6 +52,7 @@ #include "PreferencePackManager.h" #include "Language/Translator.h" + using namespace Gui::Dialog; namespace fs = boost::filesystem; using namespace Base; @@ -90,6 +93,7 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent ) for (int i = 0; i < num; i++) { QString item = qApp->translate("Gui::Dialog::DlgGeneralImp", Base::UnitsApi::getDescription(static_cast(i))); ui->comboBox_UnitSystem->addItem(item, i); + ui->comboBox_projectUnitSystem->addItem(item, i); } // Enable/disable the fractional inch option depending on system @@ -202,7 +206,21 @@ void DlgGeneralImp::saveSettings() // Set and save the Unit System viewSystemIndex = ui->comboBox_UnitSystem->currentIndex(); - UnitsApi::setSchema(static_cast(viewSystemIndex)); + auto activeDoc = Gui::Application::Instance->activeDocument(); + bool projectUnitSystemIgnore = ui->checkBox_projectUnitSystemIgnore->isChecked(); + if(activeDoc){ + activeDoc->setProjectUnitSystemIgnore( projectUnitSystemIgnore ); + if(!projectUnitSystemIgnore){ + int projectUnitSystemIndex = ui->comboBox_projectUnitSystem->currentIndex(); + activeDoc->setProjectUnitSystem( projectUnitSystemIndex ); + UnitsApi::setSchema(static_cast(projectUnitSystemIndex)); + }else{ + UnitsApi::setSchema(static_cast(viewSystemIndex)); + } + }else{ + UnitsApi::setSchema(static_cast(viewSystemIndex)); + } + // ui->SubstituteDecimal->onSave(); ui->UseLocaleFormatting->onSave(); @@ -268,6 +286,24 @@ void DlgGeneralImp::loadSettings() // handy little equation. cbIndex = std::log2(FracInch) - 1; ui->comboBox_FracInch->setCurrentIndex(cbIndex); + + + auto activeDoc = Gui::Application::Instance->activeDocument(); + if(activeDoc){ + int us = activeDoc->getProjectUnitSystem(); + if(us >= 0){//Valid unit system: + ui->comboBox_projectUnitSystem->setCurrentIndex( us ); + int pusIgnore = activeDoc->getProjectUnitSystemIgnore(); + ui->checkBox_projectUnitSystemIgnore->setChecked( pusIgnore ); + }else{ + ui->comboBox_projectUnitSystem->setCurrentIndex( 0 ); + ui->checkBox_projectUnitSystemIgnore->setChecked( false ); + } + }else{ + ui->checkBox_projectUnitSystemIgnore->setEnabled(false); + ui->comboBox_projectUnitSystem->setEnabled(false); + } + ui->SubstituteDecimal->onRestore(); @@ -403,9 +439,11 @@ void DlgGeneralImp::changeEvent(QEvent *event) if (event->type() == QEvent::LanguageChange) { int index = ui->UseLocaleFormatting->currentIndex(); int index2 = ui->comboBox_UnitSystem->currentIndex(); + int pusIndex = ui->comboBox_projectUnitSystem->currentIndex(); ui->retranslateUi(this); ui->UseLocaleFormatting->setCurrentIndex(index); ui->comboBox_UnitSystem->setCurrentIndex(index2); + ui->comboBox_projectUnitSystem->setCurrentIndex(pusIndex); } else { QWidget::changeEvent(event); @@ -561,4 +599,17 @@ void DlgGeneralImp::onUnitSystemIndexChanged(int index) } } +void DlgGeneralImp::on_checkBox_projectUnitSystemIgnore_stateChanged(int state) +{ + if (state < 0) + return; // happens when clearing the combo box in retranslateUi() + + // Enable/disable the projectUnitSystem if being ignored: + if(state == 2){//ignore + ui->comboBox_projectUnitSystem->setEnabled(false); + }else if(state == 0){ + ui->comboBox_projectUnitSystem->setEnabled(true); + } +} + #include "moc_DlgGeneralImp.cpp" diff --git a/src/Gui/DlgGeneralImp.h b/src/Gui/DlgGeneralImp.h index 4039012aeb..1d40b8f370 100644 --- a/src/Gui/DlgGeneralImp.h +++ b/src/Gui/DlgGeneralImp.h @@ -66,6 +66,7 @@ protected Q_SLOTS: public Q_SLOTS: void onUnitSystemIndexChanged(int index); + void on_checkBox_projectUnitSystemIgnore_stateChanged(int state); private: void setRecentFileSize(); diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index ed84eb045b..3bbfc42b70 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -105,6 +105,9 @@ struct DocumentP std::map _CoinMap; std::map _ViewProviderMapAnnotation; std::list _redoViewProviders; + + int projectUnitSystem=-1; + bool projectUnitSystemIgnore; using Connection = boost::signals2::connection; Connection connectNewObject; @@ -646,6 +649,30 @@ void Document::setPos(const char* name, const Base::Matrix4D& rclMtrx) } +void Document::setProjectUnitSystem(int pUS) +{ + if(pUS != d->projectUnitSystem && pUS >= 0){ + d->projectUnitSystem = pUS; + setModified(true); + } +} + +int Document::getProjectUnitSystem() const +{ + return d->projectUnitSystem; +} + +void Document::setProjectUnitSystemIgnore(bool ignore) +{ + d->projectUnitSystemIgnore = ignore; + setModified(true); +} + +bool Document::getProjectUnitSystemIgnore() const +{ + return d->projectUnitSystemIgnore; +} + //***************************************************************************************************** // Document //***************************************************************************************************** @@ -1453,6 +1480,15 @@ void Document::RestoreDocFile(Base::Reader &reader) Base::Console().Error("%s\n", e.what()); } } + try{ + localreader->readElement("ProjectUnitSystem"); + int US = localreader->getAttributeAsInteger("US"); + int ignore = localreader->getAttributeAsInteger("ignore"); + d->projectUnitSystem = US; + d->projectUnitSystemIgnore = ignore; + }catch (const Base::XMLParseException& e) { + Base::Console().Error("ProjectUnitSystem not found\n"); + } } localreader->readEndElement("Document"); @@ -1575,6 +1611,15 @@ void Document::SaveDocFile (Base::Writer &writer) const writer.Stream() << writer.ind() << "\n"; writer.decInd(); // indentation for camera settings + + if( d->projectUnitSystem >= 0 ){ + writer.incInd(); // indentation for ProjectUnitSystem + writer.Stream() << writer.ind() << "projectUnitSystem << "\" ignore=\"" + << d->projectUnitSystemIgnore << "\"/>\n"; + writer.decInd(); // indentation for ProjectUnitSystem + } + writer.Stream() << "" << std::endl; } diff --git a/src/Gui/Document.h b/src/Gui/Document.h index 73df51510d..f7fdad5ebd 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -297,6 +297,12 @@ public: const char *getCameraSettings() const; bool saveCameraSettings(const char *) const; + + void setProjectUnitSystem(int); + int getProjectUnitSystem() const; + + void setProjectUnitSystemIgnore(bool); + bool getProjectUnitSystemIgnore() const; protected: // pointer to the python class From d7e5b9dc5ad289ee11d46bd1ed01dec0d8a632d6 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Sun, 21 May 2023 01:39:39 -0300 Subject: [PATCH 02/25] Handling errors --- src/Base/Reader.cpp | 25 +++++++++++++++++++------ src/Gui/Document.cpp | 17 +++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index 507186db52..5580d0897a 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -330,12 +330,25 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const // no file name for the current entry in the zip was registered. if (jt != FileList.end()) { try { - Base::Reader reader(zipstream, jt->FileName, FileVersion); - jt->Object->RestoreDocFile(reader); - if (reader.getLocalReader()) - reader.getLocalReader()->readFiles(zipstream); - } - catch(...) { + Base::Reader reader(zipstream, jt->FileName, FileVersion); + + try{ + jt->Object->RestoreDocFile(reader); + }catch (const Base::XMLParseException& e) { + //For some reason catching this error in RestoreDocFile(reader) its working but + //still need to catch it here again. Im not sure how its that possible since its from a constructor. + + //It comes from trying to read "ProjectUnitSystem" from GuiDocument.xml and reaching EndDocument + //because was not found. + //I dont think EndDocument should throw error anyway. + if(e.getMessage() != "End of document reached"){ + throw; + } + } + + if (reader.getLocalReader()) + reader.getLocalReader()->readFiles(zipstream); + }catch(...) { // For any exception we just continue with the next file. // It doesn't matter if the last reader has read more or // less data than the file size would allow. diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 3bbfc42b70..703856a99c 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1480,14 +1480,15 @@ void Document::RestoreDocFile(Base::Reader &reader) Base::Console().Error("%s\n", e.what()); } } - try{ - localreader->readElement("ProjectUnitSystem"); - int US = localreader->getAttributeAsInteger("US"); - int ignore = localreader->getAttributeAsInteger("ignore"); - d->projectUnitSystem = US; - d->projectUnitSystemIgnore = ignore; - }catch (const Base::XMLParseException& e) { - Base::Console().Error("ProjectUnitSystem not found\n"); + + try{ + localreader->readElement("ProjectUnitSystem"); + int US = localreader->getAttributeAsInteger("US"); + int ignore = localreader->getAttributeAsInteger("ignore"); + d->projectUnitSystem = US; + d->projectUnitSystemIgnore = ignore; + }catch (const Base::XMLParseException& e) { + Base::Console().Warning("ProjectUnitSystem not found: %s\n", e.getMessage().c_str()); } } From 20da8341c666e9f54949d718515cb8345519ca19 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Fri, 16 Jun 2023 15:36:17 -0300 Subject: [PATCH 03/25] Implementing agnostic version of ParameterGrp for reading XML, replacing XMLReader from src/Base/reader.cpp with new class DocumentReader --- src/App/Extension.h | 1 + src/App/ExtensionContainer.cpp | 77 ++++++++ src/App/ExtensionContainer.h | 10 ++ src/App/PropertyContainer.cpp | 98 ++++++++++ src/App/PropertyContainer.h | 1 + src/Base/CMakeLists.txt | 1 + src/Base/DocumentReader.cpp | 314 +++++++++++++++++++++++++++++++++ src/Base/DocumentReader.h | 98 ++++++++++ src/Base/Parameter.cpp | 109 ++++-------- src/Base/Parameter.h | 57 ++++-- src/Base/Persistence.cpp | 6 + src/Base/Persistence.h | 2 + src/Base/Reader.cpp | 26 +-- src/Gui/Document.cpp | 187 ++++++++++++-------- src/Gui/Tree.cpp | 37 ++++ src/Gui/Tree.h | 1 + src/Gui/ViewProvider.cpp | 12 ++ src/Gui/ViewProvider.h | 1 + 18 files changed, 862 insertions(+), 176 deletions(-) create mode 100644 src/Base/DocumentReader.cpp create mode 100644 src/Base/DocumentReader.h diff --git a/src/App/Extension.h b/src/App/Extension.h index 79171b2071..84bb442a10 100644 --- a/src/App/Extension.h +++ b/src/App/Extension.h @@ -273,6 +273,7 @@ public: //@{ virtual void extensionSave(Base::Writer&) const {} virtual void extensionRestore(Base::XMLReader&) {} + virtual void extensionRestore(Base::DocumentReader&) {} //@} /** @name TypeHandling */ diff --git a/src/App/ExtensionContainer.cpp b/src/App/ExtensionContainer.cpp index 30022e809b..372967dbae 100644 --- a/src/App/ExtensionContainer.cpp +++ b/src/App/ExtensionContainer.cpp @@ -30,6 +30,7 @@ #include "Extension.h" #include "ExtensionContainer.h" +#include using namespace App; @@ -307,6 +308,18 @@ void ExtensionContainer::Restore(Base::XMLReader& reader) { App::PropertyContainer::Restore(reader); } +void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl) { + //restore dynamic extensions. + //Note 1: The extension element must be read first, before all other object elements. That is + // needed as the element works together with an object element attribute, which would be + // cleared if another attribute is read first + //Note 2: This must happen before the py object of this container is used, as only in the + // pyobject constructor the extension methods are added to the container. + restoreExtensions(reader,viewProviderEl); + //TODO NOW: + //App::PropertyContainer::Restore(reader); +} + void ExtensionContainer::saveExtensions(Base::Writer& writer) const { //we don't save anything if there are no dynamic extensions @@ -352,6 +365,70 @@ void ExtensionContainer::saveExtensions(Base::Writer& writer) const { writer.decInd(); } +void ExtensionContainer::restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl) { + //Dynamic extensions are optional (also because they are introduced late into the document format) + //and hence it is possible that the element does not exist. As we cannot check for the existence of + //an element a object attribute is set if extensions are available. Here we check that + //attribute, and only if it exists the extensions element will be available. + const char* expanded_cstr = reader.GetAttribute(viewProviderEl,"expanded"); + if(!expanded_cstr) + return; + auto ExtensionsDOM = reader.FindElement(viewProviderEl,"Extensions"); + if(ExtensionsDOM){ + const char* cnt_cstr = reader.GetAttribute(ExtensionsDOM,"Count"); + if(cnt_cstr){ + long Cnt = reader.ContentToInt( cnt_cstr ); + for (int i=0 ;i(extension.createInstance()); + //check if this really is a python extension! + if (!ext->isPythonExtension()) { + delete ext; + std::stringstream str; + str << "Extension is not a python addable version: '" << type_cstr << "'" << std::ends; + throw Base::TypeError(str.str()); + } + ext->initExtension(this); + if( strcmp(ext->getExtensionTypeId().getName(), type_cstr) == 0 ) + ext->extensionRestore(reader); + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } + #ifndef FC_DEBUG + catch (...) { + Base::Console().Error("ExtensionContainer::Restore: Unknown C++ exception thrown\n"); + } + #endif + } + } + } +} + void ExtensionContainer::restoreExtensions(Base::XMLReader& reader) { //Dynamic extensions are optional (also because they are introduced late into the document format) diff --git a/src/App/ExtensionContainer.h b/src/App/ExtensionContainer.h index d3661c1dcf..9c90b95fbf 100644 --- a/src/App/ExtensionContainer.h +++ b/src/App/ExtensionContainer.h @@ -25,6 +25,14 @@ #define APP_EXTENSIONCONTAINER_H #include "PropertyContainer.h" +#include + +XERCES_CPP_NAMESPACE_BEGIN + class DOMNode; + class DOMElement; +// class DefaultHandler; +// class SAX2XMLReader; +XERCES_CPP_NAMESPACE_END namespace App { @@ -177,11 +185,13 @@ public: void Save(Base::Writer& writer) const override; void Restore(Base::XMLReader& reader) override; + void Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); //those methods save/restore the dynamic extensions without handling properties, which is something //done by the default Save/Restore methods. void saveExtensions(Base::Writer& writer) const; void restoreExtensions(Base::XMLReader& reader); + void restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); /** Extends the rules for handling property name changed, so that extensions are given an opportunity to handle it. * If an extension handles a change, neither the rest of the extensions, nor the container itself get to handle it. diff --git a/src/App/PropertyContainer.cpp b/src/App/PropertyContainer.cpp index 09e9120c69..837162fc4b 100644 --- a/src/App/PropertyContainer.cpp +++ b/src/App/PropertyContainer.cpp @@ -30,6 +30,7 @@ #include "Property.h" #include "PropertyContainer.h" +#include FC_LOG_LEVEL_INIT("App",true,true) @@ -402,6 +403,103 @@ void PropertyContainer::Restore(Base::XMLReader &reader) reader.readEndElement("Properties"); } +void PropertyContainer::Restore(Base::DocumentReader &reader) +{ + //TODO NOW + Base::Console().Error("PropertyContainer::Restore: DocumentReader\n"); + reader.clearPartialRestoreProperty(); + /* + reader.clearPartialRestoreProperty(); + reader.readElement("Properties"); + int Cnt = reader.getAttributeAsInteger("Count"); + + int transientCount = 0; + if(reader.hasAttribute("TransientCount")) + transientCount = reader.getAttributeAsUnsigned("TransientCount"); + + for (int i=0;igetName() << "'"); + if(prop && reader.hasAttribute("status")) + prop->setStatusValue(reader.getAttributeAsUnsigned("status")); + } + + for (int i=0 ;igetContainer() != this) + prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); + + decltype(Property::StatusBits) status; + if(reader.hasAttribute("status")) { + status = decltype(status)(reader.getAttributeAsUnsigned("status")); + if(prop) + prop->setStatusValue(status.to_ulong()); + } + // name and type match + if (prop && strcmp(prop->getTypeId().getName(), TypeName.c_str()) == 0) { + if (!prop->testStatus(Property::Transient) + && !status.test(Property::Transient) + && !status.test(Property::PropTransient) + && !prop->testStatus(Property::PropTransient)) + { + FC_TRACE("restore property '" << prop->getName() << "'"); + prop->Restore(reader); + }else + FC_TRACE("skip transient '" << prop->getName() << "'"); + } + // name matches but not the type + else if (prop) { + handleChangedPropertyType(reader, TypeName.c_str(), prop); + } + // name doesn't match, the sub-class then has to know + // if the property has been renamed or removed + else { + handleChangedPropertyName(reader, TypeName.c_str(), PropName.c_str()); + } + + if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInProperty)) { + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str()); + reader.clearPartialRestoreProperty(); + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::RestoreError &) { + reader.setPartialRestore(true); + reader.clearPartialRestoreProperty(); + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str()); + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } +#ifndef FC_DEBUG + catch (...) { + Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n"); + } +#endif + reader.readEndElement("Property"); + } + reader.readEndElement("Properties"); + */ +} + void PropertyContainer::onPropertyStatusChanged(const Property &prop, unsigned long oldStatus) { (void)prop; diff --git a/src/App/PropertyContainer.h b/src/App/PropertyContainer.h index c86b03e9a4..4a165d51ee 100644 --- a/src/App/PropertyContainer.h +++ b/src/App/PropertyContainer.h @@ -220,6 +220,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader) override; virtual void editProperty(const char * /*propName*/) {} diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index 3b5c9e159a..1c8ad149b6 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -267,6 +267,7 @@ SET(FreeCADBase_CPP_SRCS Writer.cpp XMLTools.cpp ZipHeader.cpp + DocumentReader.cpp ) SET(SWIG_HEADERS diff --git a/src/Base/DocumentReader.cpp b/src/Base/DocumentReader.cpp new file mode 100644 index 0000000000..01b97285f0 --- /dev/null +++ b/src/Base/DocumentReader.cpp @@ -0,0 +1,314 @@ +/*************************************************************************** + * Copyright (c) 2011 Jürgen Riegel * + * * + * 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" + +//#include + +#include "DocumentReader.h" + +//#include "Reader.h" +//#include "Base64.h" +//#include "Console.h" +#include "InputSource.h" +//#include "Persistence.h" +//#include "Sequencer.h" +//#include "Stream.h" +#include "XMLTools.h" +//#ifdef _MSC_VER +//#include +//#endif +//#include + +#include +#include +#ifndef _PreComp_ +//# include +//# include +# include +//# include +//# include +//# include +//# include +# include +//# include +//# include +//# include +//# include +//# include +#endif + +XERCES_CPP_NAMESPACE_USE + +//using namespace std; +using namespace Base; + +// --------------------------------------------------------------------------- +// DocumentReader: Constructors and Destructor +// --------------------------------------------------------------------------- +static XercesDOMParser::ValSchemes gValScheme = XercesDOMParser::Val_Auto; +DocumentReader::DocumentReader() +{ + + gDoNamespaces = false; + gDoSchema = false; + gSchemaFullChecking = false; + gDoCreate = true; + + /* + gOutputEncoding = nullptr; + gMyEOLSequence = nullptr; + + gSplitCdataSections = true; + gDiscardDefaultContent = true; + gUseFilter = true; + gFormatPrettyPrint = true; + */ + +} + +//DocumentReader::~DocumentReader() +//{ + //delete parser; +//} +//int DocumentReader::LoadDocument(const XERCES_CPP_NAMESPACE_QUALIFIER InputSource& inputSource) +//int DocumentReader::LoadDocument(std::istream& Stream,std::string filename) +int DocumentReader::LoadDocument(Base::Reader& reader) +{ + FileInfo _File( reader.getFileName() ); + StdInputSource inputSource(reader, _File.filePath().c_str()); + + // + // Create our parser, then attach an error handler to the parser. + // The parser will call back to methods of the ErrorHandler if it + // discovers errors during the course of parsing the XML document. + // + XercesDOMParser *parser = new XercesDOMParser; + parser->setValidationScheme(gValScheme); + parser->setDoNamespaces(gDoNamespaces); + parser->setDoSchema(gDoSchema); + parser->setValidationSchemaFullChecking(gSchemaFullChecking); + parser->setCreateEntityReferenceNodes(gDoCreate); + + DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter(); + parser->setErrorHandler(errReporter); + // + // Parse the XML file, catching any XML exceptions that might propagate + // out of it. + // + bool errorsOccured = false; + try { + parser->parse(inputSource); + } + catch (const XMLException& e) { + std::cerr << "An error occurred during parsing\n Message: " + << StrX(e.getMessage()) << std::endl; + errorsOccured = true; + } + catch (const DOMException& e) { + std::cerr << "A DOM error occurred during parsing\n DOMException code: " + << e.code << std::endl; + errorsOccured = true; + } + catch (...) { + std::cerr << "An error occurred during parsing\n " << std::endl; + errorsOccured = true; + } + + if (errorsOccured) { + delete parser; + delete errReporter; + return 0; + } + + XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* _pDocument = parser->adoptDocument(); + delete parser; + delete errReporter; + + if (!_pDocument) + throw XMLBaseException("Malformed Parameter document: Invalid document"); + + DOMElement* rootElem = _pDocument->getDocumentElement(); + if (!rootElem) + throw XMLBaseException("Malformed Parameter document: Root group not found"); + + _pGroupNode = rootElem; + + if (!_pGroupNode){ + throw XMLBaseException("Malformed document."); + } + + return 1; +} + +XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::GetRootElement() const +{ + //if (!_pGroupNode) + //return nullptr; + return _pGroupNode; +} + +XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(const char* Type) const +{ + if(!Type) + return nullptr; + + for (DOMNode *clChild = _pGroupNode->getFirstChild(); clChild != nullptr; clChild = clChild->getNextSibling()) { + if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { + if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { + if (clChild->getAttributes()->getLength() > 0) { + return static_cast(clChild); + } + } + } + } + return nullptr; +} + +XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* Start, const char* Type) const +{ + if(!Start || !Type) + return nullptr; + for (DOMNode *clChild = Start->getFirstChild(); clChild != nullptr; clChild = clChild->getNextSibling()) { + if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { + if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { + return static_cast(clChild); + //if (clChild->getAttributes()->getLength() > 0) { + //return static_cast(clChild); + //} + } + } + } + return nullptr; +} + +XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const +{ + if (!Prev || !Type) + return nullptr; + DOMNode *clChild = Prev; + while ((clChild = clChild->getNextSibling()) != nullptr) { + if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { + // the right node Type + if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { + return static_cast(clChild); + } + } + } + return nullptr; +} + +/* +//CONTENT: +const char * DocumentReader::GetContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl) const +{ + if (!DOMEl) + return nullptr; + return StrX(DOMEl->getAttribute(XStr("Value").unicodeForm())).c_str(); +} + +std::string DocumentReader::GetContentASCII(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl) const +{ + //return std::string(StrXUTF8(pcElem->getNodeValue()).c_str() ); + //maybe its better to use getNodeValue() + if (!DOMEl) + return nullptr; + return std::string( StrXUTF8(DOMEl->getAttribute(XStr("Value").unicodeForm())).c_str() ); +} +*/ + +long DocumentReader::ContentToInt( const char* content ) const +{ + return atol( content ); +} + +unsigned long DocumentReader::ContentToUnsigned(const char* content) const +{ + return strtoul(content,nullptr,10); +} + +double DocumentReader::ContentToFloat(const char* content) const +{ + return atof(content); +} + +bool DocumentReader::ContentToBool(const char* content) const +{ + if (strcmp(content,"1")) + return false; + else + return true; +} + +//ATTRIBUTE: +const char * DocumentReader::GetAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl, const char* Attr) const +{ + if(!Attr) + return nullptr; + XStr xstr( Attr ); + bool hasAttr = DOMEl->hasAttribute(xstr.unicodeForm()); + if (!hasAttr){ + return nullptr; + } + const XMLCh * attr = DOMEl->getAttribute( xstr.unicodeForm() ); + return strdup( StrX( attr ).c_str() ); +} + +const char * DocumentReader::GetAttribute(const char* Attr) const +{ + if(!Attr) + return nullptr; + XStr xstr( Attr ); + bool hasAttr = _pGroupNode->hasAttribute(xstr.unicodeForm()); + if (!hasAttr){ + return nullptr; + } + const XMLCh * attr = _pGroupNode->getAttribute( xstr.unicodeForm() ); + //stringLen + return strdup( StrX( attr ).c_str() );//strdup is needed since pointer from strx only exists in context where StrX() is created. +} + +/* +unsigned int Base::XMLReader::getAttributeCount() const +{ + return static_cast(AttrMap.size()); +} +*/ + +//Status + +void Base::DocumentReader::clearPartialRestoreProperty() +{ + setStatus(PartialRestoreInProperty, false); + setStatus(PartialRestoreInObject, false); +} + +bool Base::DocumentReader::testStatus(ReaderStatus pos) const +{ + return StatusBits.test(static_cast(pos)); +} + +void Base::DocumentReader::setStatus(ReaderStatus pos, bool on) +{ + StatusBits.set(static_cast(pos), on); +} + + diff --git a/src/Base/DocumentReader.h b/src/Base/DocumentReader.h new file mode 100644 index 0000000000..e414046f37 --- /dev/null +++ b/src/Base/DocumentReader.h @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (c) 2011 Jürgen Riegel * + * * + * 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 BASE_DOCUMENTREADER_H +#define BASE_DOCUMENTREADER_H + +#include +#include +//#include +//#include +#include +#include + +//#include +//#include +//#include +#include +//#include "FileInfo.h"//reemplazado por: +#include +//#include + +XERCES_CPP_NAMESPACE_BEGIN + class DOMNode; + class DOMElement; +// class DefaultHandler; +// class SAX2XMLReader; +XERCES_CPP_NAMESPACE_END +namespace Base +{ +class Reader; +class Persistence; + +class BaseExport DocumentReader //: public ParameterManager +{ +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 + }; + DocumentReader(); + int LoadDocument(Base::Reader& reader); + + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *GetRootElement() const; + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* Start, const char* Type) const; + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElement(const char* Type) const; + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const; + + long ContentToASCII(const char* Content) const; + + long ContentToInt(const char* Content) const; + unsigned long ContentToUnsigned(const char* Content) const; + double ContentToFloat(const char* Content) const; + bool ContentToBool(const char* Content) const; + + const char* GetAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* DOMEl, const char* Attr) const; + const char* GetAttribute(const char* Attr) const; + + /// return the status bits + bool testStatus(ReaderStatus pos) const; + /// set the status bits + void setStatus(ReaderStatus pos, bool on); + + void clearPartialRestoreProperty(); + +protected: + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *_pGroupNode; + bool gDoNamespaces ; + bool gDoSchema ; + bool gSchemaFullChecking ; + bool gDoCreate ; + std::bitset<32> StatusBits; + +}; + +} + +#endif diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 93d45a9ca9..6753142d14 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -75,43 +75,44 @@ using namespace Base; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -class DOMTreeErrorReporter : public ErrorHandler +DOMTreeErrorReporter::DOMTreeErrorReporter(): + fSawErrors(false) { +} + +void DOMTreeErrorReporter::warning(const SAXParseException&) { -public: - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - DOMTreeErrorReporter() : - fSawErrors(false) { - } + // + // Ignore all warnings. + // +} - ~DOMTreeErrorReporter() override = default; +void DOMTreeErrorReporter::error(const SAXParseException& toCatch) +{ + fSawErrors = true; + std::cerr << "Error at file \"" << StrX(toCatch.getSystemId()) + << "\", line " << toCatch.getLineNumber() + << ", column " << toCatch.getColumnNumber() + << "\n Message: " << StrX(toCatch.getMessage()) << std::endl; +} +void DOMTreeErrorReporter::fatalError(const SAXParseException& toCatch) +{ + fSawErrors = true; + std::cerr << "Fatal Error at file \"" << StrX(toCatch.getSystemId()) + << "\", line " << toCatch.getLineNumber() + << ", column " << toCatch.getColumnNumber() + << "\n Message: " << StrX(toCatch.getMessage()) << std::endl; +} - // ----------------------------------------------------------------------- - // Implementation of the error handler interface - // ----------------------------------------------------------------------- - void warning(const SAXParseException& toCatch) override; - void error(const SAXParseException& toCatch) override; - void fatalError(const SAXParseException& toCatch) override; - void resetErrors() override; - - // ----------------------------------------------------------------------- - // Getter methods - // ----------------------------------------------------------------------- - bool getSawErrors() const; - - // ----------------------------------------------------------------------- - // Private data members - // - // fSawErrors - // This is set if we get any errors, and is queryable via a getter - // method. Its used by the main code to suppress output if there are - // errors. - // ----------------------------------------------------------------------- - bool fSawErrors; -}; +void DOMTreeErrorReporter::resetErrors() +{ + // No-op in this case +} +inline bool DOMTreeErrorReporter::getSawErrors() const +{ + return fSawErrors; +} class DOMPrintFilter : public DOMLSSerializerFilter { @@ -157,14 +158,6 @@ private : void operator=(const DOMErrorHandler&); }; - - -inline bool DOMTreeErrorReporter::getSawErrors() const -{ - return fSawErrors; -} - - //************************************************************************** //************************************************************************** // ParameterManager @@ -1865,42 +1858,6 @@ void ParameterManager::CheckDocument() const } -//************************************************************************** -//************************************************************************** -// DOMTreeErrorReporter -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -void DOMTreeErrorReporter::warning(const SAXParseException&) -{ - // - // Ignore all warnings. - // -} - -void DOMTreeErrorReporter::error(const SAXParseException& toCatch) -{ - fSawErrors = true; - std::cerr << "Error at file \"" << StrX(toCatch.getSystemId()) - << "\", line " << toCatch.getLineNumber() - << ", column " << toCatch.getColumnNumber() - << "\n Message: " << StrX(toCatch.getMessage()) << std::endl; -} - -void DOMTreeErrorReporter::fatalError(const SAXParseException& toCatch) -{ - fSawErrors = true; - std::cerr << "Fatal Error at file \"" << StrX(toCatch.getSystemId()) - << "\", line " << toCatch.getLineNumber() - << ", column " << toCatch.getColumnNumber() - << "\n Message: " << StrX(toCatch.getMessage()) << std::endl; -} - -void DOMTreeErrorReporter::resetErrors() -{ - // No-op in this case -} - - //************************************************************************** //************************************************************************** // DOMPrintFilter diff --git a/src/Base/Parameter.h b/src/Base/Parameter.h index 72a2391d4f..eece3510b6 100644 --- a/src/Base/Parameter.h +++ b/src/Base/Parameter.h @@ -65,6 +65,10 @@ using PyObject = struct _object; # pragma warning( disable : 4275 ) #endif +#ifndef _PreComp_ +# include +#endif + XERCES_CPP_NAMESPACE_BEGIN class DOMNode; @@ -279,6 +283,7 @@ protected: ~ParameterGrp() override; /// helper function for GetGroup Base::Reference _GetGroup(const char* Name); + bool ShouldRemove() const; void _Reset(); @@ -411,16 +416,17 @@ public: /// Saves an XML document by calling the serializer's save method. void SaveDocument() const; //@} - -private: - - XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *_pDocument; - ParameterSerializer * paramSerializer; - - bool gDoNamespaces ; + +protected: + bool gDoNamespaces ; bool gDoSchema ; bool gSchemaFullChecking ; bool gDoCreate ; + XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *_pDocument; +private: + ParameterManager(); + ~ParameterManager() override; + ParameterSerializer * paramSerializer; const XMLCh* gOutputEncoding ; @@ -431,11 +437,42 @@ private: bool gUseFilter ; bool gFormatPrettyPrint ; -private: - ParameterManager(); - ~ParameterManager() override; }; +XERCES_CPP_NAMESPACE_USE + +class DOMTreeErrorReporter : public ErrorHandler +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + DOMTreeErrorReporter(); + ~DOMTreeErrorReporter() override = default; + // ----------------------------------------------------------------------- + // Implementation of the error handler interface + // ----------------------------------------------------------------------- + void warning(const SAXParseException& toCatch) override; + void error(const SAXParseException& toCatch) override; + void fatalError(const SAXParseException& toCatch) override; + void resetErrors() override; + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool getSawErrors() const; +private: + // ----------------------------------------------------------------------- + // Private data members + // + // fSawErrors + // This is set if we get any errors, and is queryable via a getter + // method. Its used by the main code to suppress output if there are + // errors. + // ----------------------------------------------------------------------- + bool fSawErrors; +}; + + /** python wrapper function */ BaseExport PyObject* GetPyObject( const Base::Reference &hcParamGrp); diff --git a/src/Base/Persistence.cpp b/src/Base/Persistence.cpp index 892fc4df36..742a06cf35 100644 --- a/src/Base/Persistence.cpp +++ b/src/Base/Persistence.cpp @@ -61,6 +61,12 @@ void Persistence::Save (Writer &/*writer*/) const assert(0); } +void Persistence::Restore(DocumentReader &/*reader*/) +{ + // you have to implement this method in all descending classes! + assert(0); +} + void Persistence::Restore(XMLReader &/*reader*/) { // you have to implement this method in all descending classes! diff --git a/src/Base/Persistence.h b/src/Base/Persistence.h index 75deac6212..7941f7c748 100644 --- a/src/Base/Persistence.h +++ b/src/Base/Persistence.h @@ -31,6 +31,7 @@ namespace Base class Reader; class Writer; class XMLReader; +class DocumentReader; /// Persistence class and root of the type system class BaseExport Persistence : public BaseClass @@ -77,6 +78,7 @@ public: * \endcode */ virtual void Restore(XMLReader &/*reader*/) = 0; + virtual void Restore(DocumentReader &/*reader*/); /** This method is used to save large amounts of data to a binary file. * Sometimes it makes no sense to write property data as XML. In case the * amount of data is too big or the data type has a more effective way to diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index 5580d0897a..92e207953b 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ # include +# include #endif #include @@ -42,7 +43,7 @@ #include #endif #include - +#include XERCES_CPP_NAMESPACE_USE @@ -330,24 +331,11 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const // no file name for the current entry in the zip was registered. if (jt != FileList.end()) { try { - Base::Reader reader(zipstream, jt->FileName, FileVersion); - - try{ - jt->Object->RestoreDocFile(reader); - }catch (const Base::XMLParseException& e) { - //For some reason catching this error in RestoreDocFile(reader) its working but - //still need to catch it here again. Im not sure how its that possible since its from a constructor. - - //It comes from trying to read "ProjectUnitSystem" from GuiDocument.xml and reaching EndDocument - //because was not found. - //I dont think EndDocument should throw error anyway. - if(e.getMessage() != "End of document reached"){ - throw; - } - } - - if (reader.getLocalReader()) - reader.getLocalReader()->readFiles(zipstream); + Base::Reader reader(zipstream, jt->FileName, FileVersion); + jt->Object->RestoreDocFile(reader); + + if (reader.getLocalReader()) + reader.getLocalReader()->readFiles(zipstream); }catch(...) { // For any exception we just continue with the next file. // It doesn't matter if the last reader has read more or diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 703856a99c..f4c31f7b8a 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -33,6 +33,7 @@ # include # include # include +# include #endif #include @@ -45,6 +46,7 @@ #include #include #include +#include #include #include @@ -66,7 +68,6 @@ #include "ViewProviderDocumentObjectGroup.h" #include "WaitCursor.h" - FC_LOG_LEVEL_INIT("Gui", true, true) using namespace Gui; @@ -680,7 +681,6 @@ void Document::slotNewObject(const App::DocumentObject& Obj) { auto pcProvider = static_cast(getViewProvider(&Obj)); if (!pcProvider) { - //Base::Console().Log("Document::slotNewObject() called\n"); std::string cName = Obj.getViewProviderNameStored(); for(;;) { if (cName.empty()) { @@ -762,7 +762,6 @@ void Document::slotDeletedObject(const App::DocumentObject& Obj) { std::list::iterator vIt; setModified(true); - //Base::Console().Log("Document::slotDeleteObject() called\n"); // cycling to all views of the document ViewProvider* viewProvider = getViewProvider(&Obj); @@ -1415,88 +1414,134 @@ void Document::Restore(Base::XMLReader &reader) */ void Document::RestoreDocFile(Base::Reader &reader) { - // We must create an XML parser to read from the input stream - std::shared_ptr localreader = std::make_shared("GuiDocument.xml", reader); - localreader->FileVersion = reader.getFileVersion(); - - localreader->readElement("Document"); - long scheme = localreader->getAttributeAsInteger("SchemaVersion"); - localreader->DocumentSchema = scheme; - - bool hasExpansion = localreader->hasAttribute("HasExpansion"); - if(hasExpansion) { - auto tree = TreeWidget::instance(); + Base::DocumentReader docReader; + docReader.LoadDocument(reader); + //docReader.GetRootElement()//can be used to get Document XMLElement, but not needed. + const char* SchemaVersion_cstr = docReader.GetAttribute("SchemaVersion"); + long SchemaVersion = docReader.ContentToInt( SchemaVersion_cstr ); + + const char* HasExpansion_cstr = docReader.GetAttribute("HasExpansion"); + if(HasExpansion_cstr){ + auto tree = TreeWidget::instance(); if(tree) { auto docItem = tree->getDocumentItem(this); if(docItem) - docItem->Restore(*localreader); + docItem->Restore(docReader); } } - + // At this stage all the document objects and their associated view providers exist. // Now we must restore the properties of the view providers only. - // - // SchemeVersion "1" - if (scheme == 1) { - // read the viewproviders itself - localreader->readElement("ViewProviderData"); - int Cnt = localreader->getAttributeAsInteger("Count"); - for (int i=0; ireadElement("ViewProvider"); - std::string name = localreader->getAttribute("name"); - bool expanded = false; - if (!hasExpansion && localreader->hasAttribute("expanded")) { - const char* attr = localreader->getAttribute("expanded"); - if (strcmp(attr,"1") == 0) { - expanded = true; - } - } - ViewProvider* pObj = getViewProviderByName(name.c_str()); - if (pObj) // check if this feature has been registered - pObj->Restore(*localreader); - if (pObj && expanded) { - auto vp = static_cast(pObj); - this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); - } - localreader->readEndElement("ViewProvider"); - } - localreader->readEndElement("ViewProviderData"); + if (SchemaVersion == 1) { + auto VProviderDataDOM = docReader.FindElement("ViewProviderData"); + if(VProviderDataDOM){ + const char* vpd_count_cstr = docReader.GetAttribute(VProviderDataDOM,"Count"); + if(vpd_count_cstr){ + long Cnt = docReader.ContentToInt( vpd_count_cstr ); + auto prev_ViewProviderDOM = docReader.FindElement(VProviderDataDOM,"ViewProvider"); + if(prev_ViewProviderDOM){ + const char* name_cstr = docReader.GetAttribute(prev_ViewProviderDOM,"name"); + const char* expanded_cstr = docReader.GetAttribute(prev_ViewProviderDOM,"expanded"); + bool expanded = false; + if (!HasExpansion_cstr && expanded_cstr) { + if (strcmp(expanded_cstr,"1") == 0) { + expanded = true; + } + } + + ViewProvider* pObj = getViewProviderByName(name_cstr); + if (pObj) + pObj->Restore(docReader,prev_ViewProviderDOM); + + if (pObj && expanded) { + auto vp = static_cast(pObj); + this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); + } + } + for (int i=1; ireadElement("Camera"); - const char* ppReturn = localreader->getAttribute("settings"); - cameraSettings.clear(); - if(ppReturn && ppReturn[0]) { - saveCameraSettings(ppReturn); - try { - const char** pReturnIgnore=nullptr; - std::list mdi = getMDIViews(); - for (const auto & it : mdi) { - if (it->onHasMsg("SetCamera")) - it->onMsg(cameraSettings.c_str(), pReturnIgnore); - } - } - catch (const Base::Exception& e) { - Base::Console().Error("%s\n", e.what()); - } - } + bool expanded = false; + if (!HasExpansion_cstr && expanded_cstr_i) { + if (strcmp(expanded_cstr_i,"1") == 0) { + expanded = true; + } + } + ViewProvider* pObj = getViewProviderByName(name_cstr_i); + if (pObj) + pObj->Restore(docReader,ViewProviderDOM_i);//Im still implementing this, which calls ExtensionContainer::Restore. + + if (pObj && expanded) { + auto vp = static_cast(pObj); + this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); + } + prev_ViewProviderDOM = ViewProviderDOM_i; + } + } + } + } + // read camera settings + auto CameraDOM = docReader.FindElement("Camera"); + if(CameraDOM){ + const char* ppReturn = docReader.GetAttribute(CameraDOM,"settings"); + cameraSettings.clear(); + if(ppReturn && ppReturn[0]) { + saveCameraSettings(ppReturn); + try { + const char** pReturnIgnore=nullptr; + std::list mdi = getMDIViews(); + for (const auto & it : mdi) { + if (it->onHasMsg("SetCamera")) + it->onMsg(cameraSettings.c_str(), pReturnIgnore); + } + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + } + } - try{ - localreader->readElement("ProjectUnitSystem"); - int US = localreader->getAttributeAsInteger("US"); - int ignore = localreader->getAttributeAsInteger("ignore"); + /* + try{//if this fails then all other reading attemps will fail, since XERCES doesnt allow to get back to previous point, reading the file should restarted each time an element its not present, since it looks for it untill the end of the document. + //Since ProjectUnitSystem its the only optional field, and its being read at the end of this function, it does not cause any issue, but if other optional its added the way of reading XML used in Reader.cpp will be obsolete + + localreader->readElement("ProjectUnitSystem"); + Base::Console().Error("readElement(ProjectUnitSystem)\n"); + int US = localreader->getAttributeAsInteger("US"); + int ignore = localreader->getAttributeAsInteger("ignore"); d->projectUnitSystem = US; d->projectUnitSystemIgnore = ignore; + }catch (const Base::XMLParseException& e) { Base::Console().Warning("ProjectUnitSystem not found: %s\n", e.getMessage().c_str()); - } + }catch(const Base::XMLBaseException& e){ + Base::Console().Warning("ProjectUnitSystem XMLBaseException: %s\n", e.getMessage().c_str()); + }catch(...) { + Base::Console().Error("ProjectUnitSystem catch(...)\n"); + } + */ + } - - localreader->readEndElement("Document"); - - // reset modified flag - reader.initLocalReader(localreader); - setModified(false); + /* + + try{ + localreader->readEndElement("Document"); + }catch(const Base::XMLParseException& e){ + Base::Console().Warning("readEndElement(Document) XMLParseException: %s\n", e.getMessage().c_str()); + }catch(const Base::XMLBaseException& e){ + Base::Console().Warning("readEndElement(Document) XMLBaseException: %s\n", e.getMessage().c_str()); + }catch(...) { + Base::Console().Error("readEndElement(Document) unkown error.\n"); + } + */ + + // reset modified flag + //dont see what this does: + //reader.initLocalReader(localreader); + setModified(false); } void Document::slotStartRestoreDocument(const App::Document& doc) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 41bdcdebc0..54b7d5b2f6 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -66,6 +66,10 @@ #include "Widgets.h" #include "Workbench.h" +#include +#include +#include + FC_LOG_LEVEL_INIT("Tree", false, true, true) @@ -348,6 +352,21 @@ public: } reader.readEndElement("Expand", level - 1); } + + void restore(Base::DocumentReader& reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *expandEl) { + Base::Console().Error("ExpandInfo restore\n"); + const char* count_cstr = reader.GetAttribute(expandEl,"count"); + if(count_cstr){ + long count = reader.ContentToInt( count_cstr ); + Base::Console().Error("ExpandInfo count: %d\n",count); + auto _expandEl = reader.FindElement(expandEl,"Expand"); + const char* name_cstr = reader.GetAttribute(_expandEl,"name"); + Base::Console().Error("ExpandInfo name_cstr: %s\n",name_cstr); + auto& entry = (*this)[name_cstr]; + entry.reset(new ExpandInfo); + entry->restore(reader,_expandEl); + } + } }; // --------------------------------------------------------------------------- @@ -3927,6 +3946,24 @@ void DocumentItem::Restore(Base::XMLReader& reader) { } } +void DocumentItem::Restore(Base::DocumentReader& reader) { + Base::Console().Error("DocumentItem::Restore() DocumentReader\n"); + auto expandEl = reader.FindElement("Expand"); + if( !reader.GetAttribute(expandEl,"count") ) + return; + _ExpandInfo.reset(new ExpandInfo); + _ExpandInfo->restore(reader,expandEl); + //TODO NOW + for (auto inst : TreeWidget::Instances) { + if (inst != getTree()) { + auto docItem = inst->getDocumentItem(document()); + if (docItem) + docItem->_ExpandInfo = _ExpandInfo; + + } + } +} + void DocumentItem::restoreItemExpansion(const ExpandInfoPtr& info, DocumentObjectItem* item) { item->setExpanded(true); if (!info) diff --git a/src/Gui/Tree.h b/src/Gui/Tree.h index b41fc0c27a..377b564376 100644 --- a/src/Gui/Tree.h +++ b/src/Gui/Tree.h @@ -297,6 +297,7 @@ public: unsigned int getMemSize () const override; void Save (Base::Writer &) const override; void Restore(Base::XMLReader &) override; + void Restore(Base::DocumentReader& reader) override; class ExpandInfo; using ExpandInfoPtr = std::shared_ptr; diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index eb8d64f456..f985cca235 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -839,6 +839,18 @@ void ViewProvider::Restore(Base::XMLReader& reader) { // setStatus(Gui::isRestoring, false); } +void ViewProvider::Restore(Base::DocumentReader& reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl) { + // Because some PropertyLists type properties are stored in a separate file, + // and is thus restored outside this function. So we rely on Gui::Document + // to set the isRestoring flags for us. + // + // setStatus(Gui::isRestoring, true); + + TransactionalObject::Restore(reader,viewProviderEl); + + // setStatus(Gui::isRestoring, false); +} + void ViewProvider::updateData(const App::Property* prop) { auto vector = getExtensionsDerivedFromType(); diff --git a/src/Gui/ViewProvider.h b/src/Gui/ViewProvider.h index 1ec43105e8..101375776b 100644 --- a/src/Gui/ViewProvider.h +++ b/src/Gui/ViewProvider.h @@ -498,6 +498,7 @@ public: //restoring the object from document: //this may be of interest to extensions, hence call them void Restore(Base::XMLReader& reader) override; + void Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); bool isRestoring() {return testStatus(Gui::isRestoring);} From 69b324e42253cff08d6ddc5a4cc60657f62c1af0 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Fri, 16 Jun 2023 15:36:17 -0300 Subject: [PATCH 04/25] DocumentReader implemented for GuiDocument.xml reading. --- src/App/Document.cpp | 6 +- src/App/DynamicProperty.cpp | 30 +++ src/App/DynamicProperty.h | 11 + src/App/Extension.cpp | 20 +- src/App/Extension.h | 4 + src/App/ExtensionContainer.cpp | 110 +++++++++- src/App/ExtensionContainer.h | 8 +- src/App/PropertyContainer.cpp | 219 +++++++++++--------- src/App/PropertyContainer.h | 15 +- src/App/PropertyStandard.cpp | 357 +++++++++++++++++++++++++++++++++ src/App/PropertyStandard.h | 24 +++ src/Base/DocumentReader.cpp | 177 ++++++++-------- src/Base/DocumentReader.h | 49 +++-- src/Base/Persistence.cpp | 12 ++ src/Base/Persistence.h | 13 ++ src/Base/Reader.cpp | 19 +- src/Base/Reader.h | 4 + src/Gui/Document.cpp | 248 ++++++++++++++--------- src/Gui/Document.h | 2 + src/Gui/Tree.cpp | 29 ++- 20 files changed, 1053 insertions(+), 304 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index a72cc89188..30a65d4579 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -87,6 +87,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees. #include #include #include +#include #include #include #include @@ -1227,7 +1228,6 @@ Document::readObjects(Base::XMLReader& reader) // read the object types reader.readElement("Objects"); int Cnt = reader.getAttributeAsInteger("Count"); - if(!reader.hasAttribute(FC_ATTR_DEPENDENCIES)) d->partialLoadObjects.clear(); else if(!d->partialLoadObjects.empty()) { @@ -2023,12 +2023,12 @@ void Document::restore (const char *filename, // without GUI. But if available then follow after all data files of the App document. signalRestoreDocument(reader); reader.readFiles(zipstream); - + if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestore)) { setStatus(Document::PartialRestore, true); Base::Console().Error("There were errors while loading the file. Some data might have been modified or not recovered at all. Look above for more specific information about the objects involved.\n"); } - + if(!delaySignal) afterRestore(true); } diff --git a/src/App/DynamicProperty.cpp b/src/App/DynamicProperty.cpp index 7ad6419b33..c105483f42 100644 --- a/src/App/DynamicProperty.cpp +++ b/src/App/DynamicProperty.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "DynamicProperty.h" #include "Application.h" @@ -322,6 +323,35 @@ Property *DynamicProperty::restore(PropertyContainer &pc, return addDynamicProperty(pc,TypeName, PropName, group, doc, attribute, readonly, hidden); } +Property *DynamicProperty::restore(PropertyContainer &pc, + const char *PropName, const char *TypeName, Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM) +{ + const char* group_cstr = reader.GetAttribute(PropertyDOM,"group"); + if(!group_cstr) + return nullptr; + + short attribute = 0; + bool readonly = false, hidden = false; + + const char* doc_cstr = reader.GetAttribute(PropertyDOM,"doc"); + const char* attr_cstr = reader.GetAttribute(PropertyDOM,"attr"); + + if(attr_cstr){ + std::istringstream str(attr_cstr); + str >> attribute; + } + + const char* ro_cstr = reader.GetAttribute(PropertyDOM,"ro"); + if(ro_cstr) + readonly = (ro_cstr[0]-48) != 0; + + const char* hide_cstr = reader.GetAttribute(PropertyDOM,"hide"); + if(hide_cstr) + hidden = (hide_cstr[0]-48) != 0; + + return addDynamicProperty(pc,TypeName, PropName, group_cstr, doc_cstr, attribute, readonly, hidden); +} + DynamicProperty::PropData DynamicProperty::getDynamicPropertyData(const Property *prop) const { auto &index = props.get<1>(); diff --git a/src/App/DynamicProperty.h b/src/App/DynamicProperty.h index a292f74c8e..e02a2e9659 100644 --- a/src/App/DynamicProperty.h +++ b/src/App/DynamicProperty.h @@ -33,6 +33,15 @@ #include #include #include +#include + + +XERCES_CPP_NAMESPACE_BEGIN + class DOMNode; + class DOMElement; +// class DefaultHandler; +// class SAX2XMLReader; +XERCES_CPP_NAMESPACE_END namespace Base { @@ -145,6 +154,8 @@ public: Property *restore(PropertyContainer &pc, const char *PropName, const char *TypeName, Base::XMLReader &reader); + Property *restore(PropertyContainer &pc, + const char *PropName, const char *TypeName, Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM); struct PropData { Property* property; diff --git a/src/App/Extension.cpp b/src/App/Extension.cpp index c3dea0f5e7..ce0991f042 100644 --- a/src/App/Extension.cpp +++ b/src/App/Extension.cpp @@ -34,7 +34,6 @@ #include "ExtensionPython.h" #include - /* We do not use a standard property macro for type initiation. The reason is that we have the first * PropertyData in the extension chain, there is no parent property data. */ @@ -79,7 +78,6 @@ void Extension::initExtensionType(Base::Type type) { } void Extension::initExtension(ExtensionContainer* obj) { - if (m_extensionType.isBad()) throw Base::RuntimeError("Extension: Extension type not set"); @@ -205,6 +203,24 @@ bool Extension::extensionHandleChangedPropertyType(Base::XMLReader &reader, cons return false; }; +bool Extension::extensionHandleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) +{ + (void) reader; + (void) TypeName; + (void) PropName; + + return false; +}; + +bool Extension::extensionHandleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) +{ + (void) reader; + (void) TypeName; + (void) prop; + + return false; +}; + namespace App { EXTENSION_PROPERTY_SOURCE_TEMPLATE(App::ExtensionPython, App::ExtensionPython::Inherited) diff --git a/src/App/Extension.h b/src/App/Extension.h index 84bb442a10..d667d35900 100644 --- a/src/App/Extension.h +++ b/src/App/Extension.h @@ -290,6 +290,10 @@ protected: virtual bool extensionHandleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName); /// returns true if the property type change was handled by the extension. virtual bool extensionHandleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop); + /// returns true if the property name change was handled by the extension. + virtual bool extensionHandleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName); + /// returns true if the property type change was handled by the extension. + virtual bool extensionHandleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop); friend class App::ExtensionContainer; diff --git a/src/App/ExtensionContainer.cpp b/src/App/ExtensionContainer.cpp index 372967dbae..742b322998 100644 --- a/src/App/ExtensionContainer.cpp +++ b/src/App/ExtensionContainer.cpp @@ -32,6 +32,11 @@ #include "ExtensionContainer.h" #include +#ifndef _PreComp_ +# include +//# include +#endif + using namespace App; @@ -308,7 +313,7 @@ void ExtensionContainer::Restore(Base::XMLReader& reader) { App::PropertyContainer::Restore(reader); } -void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl) { +void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) { //restore dynamic extensions. //Note 1: The extension element must be read first, before all other object elements. That is // needed as the element works together with an object element attribute, which would be @@ -316,7 +321,6 @@ void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPA //Note 2: This must happen before the py object of this container is used, as only in the // pyobject constructor the extension methods are added to the container. restoreExtensions(reader,viewProviderEl); - //TODO NOW: //App::PropertyContainer::Restore(reader); } @@ -429,6 +433,80 @@ void ExtensionContainer::restoreExtensions(Base::DocumentReader& reader,XERCES_C } } +void ExtensionContainer::restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) { + //Dynamic extensions are optional (also because they are introduced late into the document format) + //and hence it is possible that the element does not exist. As we cannot check for the existence of + //an element a object attribute is set if extensions are available. Here we check that + //attribute, and only if it exists the extensions element will be available. + const char* expanded_cstr = reader.GetAttribute(containerEl,"expanded"); + if(!expanded_cstr) + return; + auto ExtensionsDOM = reader.FindElement(containerEl,"Extensions"); + if(ExtensionsDOM){ + const char* cnt_cstr = reader.GetAttribute(ExtensionsDOM,"Count"); + if(cnt_cstr){ + long Cnt = reader.ContentToInt( cnt_cstr ); + auto prev_ExtensionDOM = reader.FindElement(ExtensionsDOM,"Extension"); + readExtension(reader,prev_ExtensionDOM); + for (int i=1 ;i(extension.createInstance()); + //check if this really is a python extension! + if (!ext->isPythonExtension()) { + delete ext; + std::stringstream str; + str << "Extension is not a python addable version: '" << type_cstr << "'" << std::ends; + throw Base::TypeError(str.str()); + } + ext->initExtension(this); + if( strcmp(ext->getExtensionTypeId().getName(), type_cstr) == 0 ) + ext->extensionRestore(reader); + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } +#ifndef FC_DEBUG + catch (...) { + Base::Console().Error("ExtensionContainer::Restore: Unknown C++ exception thrown\n"); + } +#endif + +} + void ExtensionContainer::restoreExtensions(Base::XMLReader& reader) { //Dynamic extensions are optional (also because they are introduced late into the document format) @@ -508,6 +586,20 @@ void ExtensionContainer::handleChangedPropertyName(Base::XMLReader &reader, cons PropertyContainer::handleChangedPropertyName(reader, TypeName, PropName); } +void ExtensionContainer::handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) +{ + //inform all extensions about changed property name. This includes all properties from the + //extended object (this) as well as all extension properties + for(const auto& entry : _extensions) { + bool handled = entry.second->extensionHandleChangedPropertyName(reader, TypeName, PropName); + + if(handled) + return; // one property change needs only be handled once + } + + PropertyContainer::handleChangedPropertyName(reader, TypeName, PropName); +} + void ExtensionContainer::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop) { //inform all extensions about changed property type. This includes all properties from the @@ -521,3 +613,17 @@ void ExtensionContainer::handleChangedPropertyType(Base::XMLReader &reader, cons PropertyContainer::handleChangedPropertyType(reader, TypeName, prop); } + +void ExtensionContainer::handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) +{ + //inform all extensions about changed property type. This includes all properties from the + //extended object (this) as well as all extension properties + for(const auto& entry : _extensions) { + bool handled = entry.second->extensionHandleChangedPropertyType(reader, TypeName, prop); + + if(handled) + return; // one property change needs only be handled once + } + + PropertyContainer::handleChangedPropertyType(reader, TypeName, prop); +} diff --git a/src/App/ExtensionContainer.h b/src/App/ExtensionContainer.h index 9c90b95fbf..d71908ba7a 100644 --- a/src/App/ExtensionContainer.h +++ b/src/App/ExtensionContainer.h @@ -185,13 +185,13 @@ public: void Save(Base::Writer& writer) const override; void Restore(Base::XMLReader& reader) override; - void Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); + void Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl); //those methods save/restore the dynamic extensions without handling properties, which is something //done by the default Save/Restore methods. void saveExtensions(Base::Writer& writer) const; void restoreExtensions(Base::XMLReader& reader); - void restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); + void restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl); /** Extends the rules for handling property name changed, so that extensions are given an opportunity to handle it. * If an extension handles a change, neither the rest of the extensions, nor the container itself get to handle it. @@ -201,6 +201,7 @@ public: * If no extension handles the request, then the containers handleChangedPropertyName() is called. */ virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) override; + virtual void handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) override; /** Extends the rules for handling property type changed, so that extensions are given an opportunity to handle it. * If an extension handles a change, neither the rest of the extensions, nor the container itself get to handle it. * @@ -209,6 +210,9 @@ public: * If no extension handles the request, then the containers handleChangedPropertyType() is called. */ virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop) override; + virtual void handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) override; + + void readExtension(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ExtensionDOM); private: //stored extensions diff --git a/src/App/PropertyContainer.cpp b/src/App/PropertyContainer.cpp index 837162fc4b..5d5ee8dd2e 100644 --- a/src/App/PropertyContainer.cpp +++ b/src/App/PropertyContainer.cpp @@ -32,6 +32,10 @@ #include "PropertyContainer.h" #include +#ifndef _PreComp_ +# include +#endif + FC_LOG_LEVEL_INIT("App",true,true) @@ -75,8 +79,9 @@ App::Property* PropertyContainer::addDynamicProperty( Property *PropertyContainer::getPropertyByName(const char* name) const { auto prop = dynamicProps.getDynamicPropertyByName(name); - if(prop) + if(prop){ return prop; + } return getPropertyData().getPropertyByName(this,name); } @@ -199,6 +204,13 @@ void PropertyContainer::handleChangedPropertyName(Base::XMLReader &reader, const (void)PropName; } +void PropertyContainer::handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) +{ + (void)reader; + (void)TypeName; + (void)PropName; +} + /** * @brief PropertyContainer::handleChangedPropertyType is called during restore to possibly * fix reading of older versions of the property container. This method is typically called @@ -218,6 +230,13 @@ void PropertyContainer::handleChangedPropertyType(XMLReader &reader, const char (void)prop; } +void PropertyContainer::handleChangedPropertyType(DocumentReader &reader, const char *TypeName, Property *prop) +{ + (void)reader; + (void)TypeName; + (void)prop; +} + PropertyData PropertyContainer::propertyData; void PropertyContainer::Save (Base::Writer &writer) const @@ -321,6 +340,7 @@ void PropertyContainer::Restore(Base::XMLReader &reader) if(reader.hasAttribute("TransientCount")) transientCount = reader.getAttributeAsUnsigned("TransientCount"); + for (int i=0;igetContainer() != this) + if(!prop || prop->getContainer() != this){ prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); + } decltype(Property::StatusBits) status; if(reader.hasAttribute("status")) { @@ -403,101 +424,115 @@ void PropertyContainer::Restore(Base::XMLReader &reader) reader.readEndElement("Properties"); } -void PropertyContainer::Restore(Base::DocumentReader &reader) +void PropertyContainer::Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) { - //TODO NOW - Base::Console().Error("PropertyContainer::Restore: DocumentReader\n"); reader.clearPartialRestoreProperty(); - /* - reader.clearPartialRestoreProperty(); - reader.readElement("Properties"); - int Cnt = reader.getAttributeAsInteger("Count"); + + auto PropertiesDOM = reader.FindElement(containerEl,"Properties"); + const char* count_cstr = reader.GetAttribute(PropertiesDOM,"Count"); + if(count_cstr){ + long Cnt = reader.ContentToInt( count_cstr ); + const char* TransientCount_cstr = reader.GetAttribute(PropertiesDOM,"TransientCount"); + int transientCount = 0; + if(TransientCount_cstr) + transientCount = reader.ContentToUnsigned( TransientCount_cstr ); + + for (int i=0;igetName() << "'"); + if(prop && status_cstr){ + int u_status = reader.ContentToUnsigned( status_cstr ); + prop->setStatusValue(u_status); + } + } + if(Cnt){ + auto prev_PropertyDOM = reader.FindElement(PropertiesDOM,"Property"); + readProperty(reader,prev_PropertyDOM); + for (int i=1 ;igetName() << "'"); - if(prop && reader.hasAttribute("status")) - prop->setStatusValue(reader.getAttributeAsUnsigned("status")); - } - - for (int i=0 ;igetContainer() != this) - prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); - - decltype(Property::StatusBits) status; - if(reader.hasAttribute("status")) { - status = decltype(status)(reader.getAttributeAsUnsigned("status")); - if(prop) - prop->setStatusValue(status.to_ulong()); - } - // name and type match - if (prop && strcmp(prop->getTypeId().getName(), TypeName.c_str()) == 0) { - if (!prop->testStatus(Property::Transient) - && !status.test(Property::Transient) - && !status.test(Property::PropTransient) - && !prop->testStatus(Property::PropTransient)) - { - FC_TRACE("restore property '" << prop->getName() << "'"); - prop->Restore(reader); - }else - FC_TRACE("skip transient '" << prop->getName() << "'"); - } - // name matches but not the type - else if (prop) { - handleChangedPropertyType(reader, TypeName.c_str(), prop); - } - // name doesn't match, the sub-class then has to know - // if the property has been renamed or removed - else { - handleChangedPropertyName(reader, TypeName.c_str(), PropName.c_str()); - } - - if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInProperty)) { - Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str()); - reader.clearPartialRestoreProperty(); - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::RestoreError &) { - reader.setPartialRestore(true); - reader.clearPartialRestoreProperty(); - Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str()); - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } +// NOTE: We must also check the type of the current property because a +// subclass of PropertyContainer might change the type of a property but +// not its name. In this case we would force to read-in a wrong property +// type and the behaviour would be undefined. +void PropertyContainer::readProperty(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM){ + const char* name_cstr = reader.GetAttribute(PropertyDOM,"name"); + const char* type_cstr = reader.GetAttribute(PropertyDOM,"type"); + try { + + auto prop = getPropertyByName(name_cstr); + if(!prop || prop->getContainer() != this){ + prop = dynamicProps.restore(*this,name_cstr,type_cstr,reader,PropertyDOM); + } + + decltype(Property::StatusBits) status; + const char* status_cstr = reader.GetAttribute(PropertyDOM,"status"); + if(status_cstr){ + int u_status = reader.ContentToUnsigned( status_cstr ); + status = decltype(status)(u_status); + if(prop) + prop->setStatusValue(status.to_ulong()); + } + // name and type match + if (prop && strcmp(prop->getTypeId().getName(), type_cstr) == 0) { + if (!prop->testStatus(Property::Transient) + && !status.test(Property::Transient) + && !status.test(Property::PropTransient) + && !prop->testStatus(Property::PropTransient)) + { + FC_TRACE("restore property '" << prop->getName() << "'"); + prop->Restore(reader,PropertyDOM); + }else + FC_TRACE("skip transient '" << prop->getName() << "'"); + } + // name matches but not the type + else if (prop) { + handleChangedPropertyType(reader, type_cstr, prop); + } + // name doesn't match, the sub-class then has to know + // if the property has been renamed or removed + else { + handleChangedPropertyName(reader, type_cstr, name_cstr); + } + + if (reader.testStatus(Base::DocumentReader::ReaderStatus::PartialRestoreInProperty)) { + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",name_cstr,type_cstr); + reader.clearPartialRestoreProperty(); + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::RestoreError &) { + reader.setPartialRestore(true); + reader.clearPartialRestoreProperty(); + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",name_cstr,type_cstr); + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } #ifndef FC_DEBUG - catch (...) { - Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n"); - } + catch (...) { + Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n"); + } #endif - reader.readEndElement("Property"); - } - reader.readEndElement("Properties"); - */ } void PropertyContainer::onPropertyStatusChanged(const Property &prop, unsigned long oldStatus) diff --git a/src/App/PropertyContainer.h b/src/App/PropertyContainer.h index 4a165d51ee..d49b8a8e76 100644 --- a/src/App/PropertyContainer.h +++ b/src/App/PropertyContainer.h @@ -30,6 +30,16 @@ #include "DynamicProperty.h" +#include + +XERCES_CPP_NAMESPACE_BEGIN + class DOMNode; + class DOMElement; +// class DefaultHandler; +// class SAX2XMLReader; +XERCES_CPP_NAMESPACE_END + + namespace Base { class Writer; } @@ -220,7 +230,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader) override; + void Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) override; virtual void editProperty(const char * /*propName*/) {} @@ -248,11 +258,14 @@ protected: virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName); virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop); + virtual void handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName); + virtual void handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop); private: // forbidden PropertyContainer(const PropertyContainer&); PropertyContainer& operator = (const PropertyContainer&); + void readProperty(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM); protected: DynamicProperty dynamicProps; diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 96b69440b0..030d2b3463 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -23,6 +23,10 @@ #include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + #include #include @@ -30,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +122,20 @@ void PropertyInteger::Restore(Base::XMLReader &reader) setValue(reader.getAttributeAsInteger("value")); } +void PropertyInteger::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto IntegerDOM = reader.FindElement(ContainerDOM,"Integer"); + if(IntegerDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(IntegerDOM,"value"); + if(value_cstr){ + long value = reader.ContentToInt( value_cstr ); + setValue(value); + } + } +} + Property *PropertyInteger::Copy() const { PropertyInteger *p= new PropertyInteger(); @@ -242,6 +261,18 @@ void PropertyPath::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } +void PropertyPath::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto PathDOM = reader.FindElement(ContainerDOM,"Path"); + if(PathDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(PathDOM,"value"); + if(value_cstr){ + setValue(value_cstr); + } + } +} + Property *PropertyPath::Copy() const { PropertyPath *p= new PropertyPath(); @@ -432,6 +463,54 @@ void PropertyEnumeration::Restore(Base::XMLReader &reader) hasSetValue(); } +void PropertyEnumeration::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto IntegerDOM = reader.FindElement(ContainerDOM,"Integer"); + if(IntegerDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(IntegerDOM,"value"); + if(value_cstr){ + long val = reader.ContentToInt( value_cstr ); + aboutToSetValue(); + + const char* CustomEnum_cstr = reader.GetAttribute(IntegerDOM,"CustomEnum"); + if(CustomEnum_cstr){ + auto CustomEnumListDOM = reader.FindElement(IntegerDOM,"CustomEnumList"); + if(CustomEnumListDOM){ + const char* count_cstr = reader.GetAttribute(IntegerDOM,"count"); + if(count_cstr){ + long count = reader.ContentToInt( count_cstr ); + std::vector values(count); + + if(count >= 1){ + auto prev_EnumDOM = reader.FindElement(CustomEnumListDOM,"Enum"); + const char* enum_value_cstr = reader.GetAttribute(prev_EnumDOM,"value"); + values[0] = enum_value_cstr; + for(int i = 1; i < count; i++) { + auto EnumDOM_i = reader.FindNextElement(prev_EnumDOM,"Enum"); + const char* _enum_value_cstr = reader.GetAttribute(EnumDOM_i,"value"); + values[i] = _enum_value_cstr; + + prev_EnumDOM = EnumDOM_i; + } + } + _enum.setEnums(values); + } + } + } + if (val < 0) { + // If the enum is empty at this stage do not print a warning + if (_enum.hasEnums()) + Base::Console().Warning("Enumeration index %d is out of range, ignore it\n", val); + val = getValue(); + } + + _enum.setValue(val); + hasSetValue(); + } + } +} + PyObject * PropertyEnumeration::getPyObject() { if (!_enum.isValid()) { @@ -782,6 +861,35 @@ void PropertyIntegerList::Restore(Base::XMLReader &reader) setValues(values); } +void PropertyIntegerList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto IntegerListDOM = reader.FindElement(ContainerDOM,"IntegerList"); + if(IntegerListDOM){ + // get the value of my Attribute + const char* count_cstr = reader.GetAttribute(IntegerListDOM,"count"); + long count = reader.ContentToInt( count_cstr ); + std::vector values(count); + if(count >= 1){ + auto prev_I_DOM = reader.FindElement(IntegerListDOM,"I"); + const char* v_cstr = reader.GetAttribute(prev_I_DOM,"v"); + long v = reader.ContentToInt( v_cstr ); + values[0] = v; + + for(int i = 1; i < count; i++) { + auto I_DOM_i = reader.FindNextElement(prev_I_DOM,"I"); + const char* _v_cstr = reader.GetAttribute(I_DOM_i,"v"); + long v = reader.ContentToInt( _v_cstr ); + values[i] = v; + + prev_I_DOM = I_DOM_i; + } + } + //assignment + setValues(values); + } +} + + Property *PropertyIntegerList::Copy() const { PropertyIntegerList *p= new PropertyIntegerList(); @@ -902,6 +1010,35 @@ void PropertyIntegerSet::Restore(Base::XMLReader &reader) setValues(values); } +void PropertyIntegerSet::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto IntegerSetDOM = reader.FindElement(ContainerDOM,"IntegerSet"); + if(IntegerSetDOM){ + // get the value of my Attribute + const char* count_cstr = reader.GetAttribute(IntegerSetDOM,"count"); + long count = reader.ContentToInt( count_cstr ); + std::set values; + + if(count >= 1){ + auto prev_I_DOM = reader.FindElement(IntegerSetDOM,"I"); + const char* v_cstr = reader.GetAttribute(prev_I_DOM,"v"); + long v = reader.ContentToInt( v_cstr ); + values.insert( v ); + + for(int i = 1; i < count; i++) { + auto I_DOM_i = reader.FindNextElement(prev_I_DOM,"I"); + const char* _v_cstr = reader.GetAttribute(I_DOM_i,"v"); + long v = reader.ContentToInt( _v_cstr ); + values.insert( v ); + + prev_I_DOM = I_DOM_i; + } + } + //assignment + setValues(values); + } +} + Property *PropertyIntegerSet::Copy() const { PropertyIntegerSet *p= new PropertyIntegerSet(); @@ -993,6 +1130,21 @@ void PropertyFloat::Restore(Base::XMLReader &reader) setValue(reader.getAttributeAsFloat("value")); } +void PropertyFloat::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto FloatDOM = reader.FindElement(ContainerDOM,"Float"); + if(FloatDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(FloatDOM,"value"); + if(value_cstr){ + double value = reader.ContentToFloat( value_cstr ); + setValue(value); + } + } +} + + + Property *PropertyFloat::Copy() const { PropertyFloat *p= new PropertyFloat(); @@ -1242,6 +1394,24 @@ void PropertyFloatList::Restore(Base::XMLReader &reader) } } +void PropertyFloatList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + //TODO for this its needed to implement addFile() into Reader.cpp, and ReadFiles() since its not possible to have an XMLReader object at this point, because it gives error to use both methods(XMLReader progressive reading and DocumentReader reading) probably because there is something wrong with the zipios implementation, it looks like its locking file or in some way makes the file structure invalid to be readed by xerces by both methods. + //worked around reimplementing ReadFiles in DocumentReader.cpp: + auto FloatListDOM = reader.FindElement(ContainerDOM,"FloatList"); + if(FloatListDOM){ + // get the value of my Attribute + const char* file_cstr = reader.GetAttribute(FloatListDOM,"file"); + if(file_cstr){ + string file ( file_cstr ); + if (!file.empty()) { + // initiate a file read + reader.addFile(file.c_str(),this); + } + } + } +} + void PropertyFloatList::SaveDocFile (Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -1502,6 +1672,31 @@ void PropertyString::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } +void PropertyString::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto StringDOM = reader.FindElement(ContainerDOM,"String"); + const char* value_cstr = reader.GetAttribute(StringDOM,"value"); + + auto obj = dynamic_cast(getContainer()); + if(obj && &obj->Label==this) { + const char* restore_cstr = reader.GetAttribute(StringDOM,"restore"); + + if(restore_cstr) { + int restore = reader.ContentToInt( restore_cstr ); + if(restore == 1) { + aboutToSetValue(); + _cValue = value_cstr; + hasSetValue(); + return; + } + return; + } + } + setValue(value_cstr); + + +} + Property *PropertyString::Copy() const { PropertyString *p= new PropertyString(); @@ -1634,6 +1829,18 @@ void PropertyUUID::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } +void PropertyUUID::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto UuidDOM = reader.FindElement(ContainerDOM,"Uuid"); + if(UuidDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(UuidDOM,"value"); + if(value_cstr){ + setValue(value_cstr); + } + } +} + Property *PropertyUUID::Copy() const { PropertyUUID *p= new PropertyUUID(); @@ -1755,6 +1962,32 @@ void PropertyStringList::Restore(Base::XMLReader &reader) setValues(values); } +void PropertyStringList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto StringListDOM = reader.FindElement(ContainerDOM,"StringList"); + if(StringListDOM){ + // get the value of my Attribute + const char* count_cstr = reader.GetAttribute(StringListDOM,"count"); + long count = reader.ContentToInt( count_cstr ); + std::vector values(count); + if(count >= 1){ + auto prev_StringDOM = reader.FindElement(StringListDOM,"String"); + const char* value_cstr = reader.GetAttribute(prev_StringDOM,"value"); + values[0] = value_cstr; + for(int i = 1; i < count; i++) { + auto StringDOM_i = reader.FindNextElement(prev_StringDOM,"String"); + const char* _value_cstr = reader.GetAttribute(StringDOM_i,"value"); + values[i] = _value_cstr; + + prev_StringDOM = StringDOM_i; + } + + } + // assignment + setValues(values); + } +} + Property *PropertyStringList::Copy() const { PropertyStringList *p= new PropertyStringList(); @@ -1919,6 +2152,32 @@ void PropertyMap::Restore(Base::XMLReader &reader) setValues(values); } +void PropertyMap::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto MapDOM = reader.FindElement(ContainerDOM,"Map"); + if(MapDOM){ + // get the value of my Attribute + const char* count_cstr = reader.GetAttribute(MapDOM,"count"); + int count = reader.ContentToInt( count_cstr ); + std::map values; + auto prev_ItemDOM = reader.FindElement(MapDOM,"Item"); + const char* key_cstr = reader.GetAttribute(prev_ItemDOM,"key"); + const char* value_cstr = reader.GetAttribute(prev_ItemDOM,"value"); + values[key_cstr] = value_cstr; + + for(int i = 1; i < count; i++) { + auto ItemDOM_i = reader.FindNextElement(prev_ItemDOM,"Item"); + const char* key_cstr = reader.GetAttribute(ItemDOM_i,"key"); + const char* value_cstr = reader.GetAttribute(ItemDOM_i,"value"); + values[key_cstr] = value_cstr; + + prev_ItemDOM = ItemDOM_i; + } + // assignment + setValues(values); + } +} + Property *PropertyMap::Copy() const { PropertyMap *p= new PropertyMap(); @@ -2004,6 +2263,15 @@ void PropertyBool::Restore(Base::XMLReader &reader) (b == "true") ? setValue(true) : setValue(false); } +void PropertyBool::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto BoolDOM = reader.FindElement(ContainerDOM,"Bool"); + if(BoolDOM){ + // get the value of my Attribute + string b = reader.GetAttribute(BoolDOM,"value"); + (b == "true") ? setValue(true) : setValue(false); + } +} Property *PropertyBool::Copy() const { @@ -2122,6 +2390,18 @@ void PropertyBoolList::Restore(Base::XMLReader &reader) setValues(bitset); } +void PropertyBoolList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto BoolListDOM = reader.FindElement(ContainerDOM,"BoolList"); + if(BoolListDOM){ + // get the value of my Attribute + string str = reader.GetAttribute(BoolListDOM,"value"); + boost::dynamic_bitset<> bitset(str); + setValues(bitset); + } +} + Property *PropertyBoolList::Copy() const { PropertyBoolList *p= new PropertyBoolList(); @@ -2275,6 +2555,17 @@ void PropertyColor::Restore(Base::XMLReader &reader) setValue(rgba); } +void PropertyColor::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto PropertyColorDOM = reader.FindElement(ContainerDOM,"PropertyColor"); + if(PropertyColorDOM){ + const char* val_cstr = reader.GetAttribute(PropertyColorDOM,"value"); + unsigned long rgba = reader.ContentToUnsigned(val_cstr); + setValue(rgba); + } +} + Property *PropertyColor::Copy() const { PropertyColor *p= new PropertyColor(); @@ -2354,6 +2645,22 @@ void PropertyColorList::Restore(Base::XMLReader &reader) } } +void PropertyColorList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto ColorListDOM = reader.FindElement(ContainerDOM,"ColorList"); + if(ColorListDOM){ + // get the value of my Attribute + const char* file_cstr = reader.GetAttribute(ColorListDOM,"file"); + if(file_cstr){ + std::string file (file_cstr); + if (!file.empty()) { + // initiate a file read + reader.addFile(file.c_str(),this); + } + } + } +} + void PropertyColorList::SaveDocFile (Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -2504,6 +2811,32 @@ void PropertyMaterial::Restore(Base::XMLReader &reader) hasSetValue(); } +void PropertyMaterial::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto PropertyMaterialDOM = reader.FindElement(ContainerDOM,"PropertyMaterial"); + if(PropertyMaterialDOM){ + // get the value of my Attribute + aboutToSetValue(); + + const char* ambientColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"ambientColor"); + const char* diffuseColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"diffuseColor"); + const char* specularColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"specularColor"); + const char* emissiveColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"emissiveColor"); + const char* shininess_cstr = reader.GetAttribute(PropertyMaterialDOM,"shininess"); + const char* transparency_cstr = reader.GetAttribute(PropertyMaterialDOM,"transparency"); + + _cMat.ambientColor.setPackedValue(reader.ContentToUnsigned(ambientColor_cstr)); + _cMat.diffuseColor.setPackedValue(reader.ContentToUnsigned(diffuseColor_cstr)); + _cMat.specularColor.setPackedValue(reader.ContentToUnsigned(specularColor_cstr)); + _cMat.emissiveColor.setPackedValue(reader.ContentToUnsigned(emissiveColor_cstr)); + _cMat.shininess = (float)reader.ContentToFloat(shininess_cstr); + _cMat.transparency = (float)reader.ContentToFloat(transparency_cstr); + hasSetValue(); + } +} + + const char* PropertyMaterial::getEditorName() const { if(testStatus(MaterialEdit)) @@ -2583,6 +2916,22 @@ void PropertyMaterialList::Restore(Base::XMLReader &reader) } } +void PropertyMaterialList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto MaterialListDOM = reader.FindElement(ContainerDOM,"MaterialList"); + if(MaterialListDOM){ + // get the value of my Attribute + const char* file_cstr = reader.GetAttribute(MaterialListDOM,"file"); + if(file_cstr){ + std::string file (file_cstr); + if (!file.empty()) { + // initiate a file read + reader.addFile(file.c_str(),this); + } + } + } +} + void PropertyMaterialList::SaveDocFile(Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -2679,6 +3028,14 @@ void PropertyPersistentObject::Restore(Base::XMLReader &reader){ reader.readEndElement(ELEMENT_PERSISTENT_OBJ); } +void PropertyPersistentObject::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + inherited::Restore(reader,ContainerDOM); + auto element_persistent_obj_DOM = reader.FindElement(ELEMENT_PERSISTENT_OBJ); + if(_pObject) + _pObject->Restore(reader,element_persistent_obj_DOM); +} + Property *PropertyPersistentObject::Copy() const{ auto *p= new PropertyPersistentObject(); p->_cValue = _cValue; diff --git a/src/App/PropertyStandard.h b/src/App/PropertyStandard.h index cd5d8755f3..e1d1cd0d43 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -36,6 +36,12 @@ #include "Enumeration.h" #include "Material.h" +#include + +XERCES_CPP_NAMESPACE_BEGIN + class DOMElement; +XERCES_CPP_NAMESPACE_END + namespace Base { class Writer; @@ -70,6 +76,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -121,6 +128,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -220,6 +228,7 @@ public: void Save(Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property * Copy() const override; void Paste(const Property &from) override; @@ -358,6 +367,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -403,6 +413,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -462,6 +473,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -515,6 +527,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -658,6 +671,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile (Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -705,6 +719,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -758,6 +773,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -824,6 +840,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -865,6 +882,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -902,6 +920,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -949,6 +968,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -988,6 +1008,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile (Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -1040,6 +1061,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; const char* getEditorName() const override; @@ -1083,6 +1105,7 @@ public: void Save(Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile(Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -1112,6 +1135,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; diff --git a/src/Base/DocumentReader.cpp b/src/Base/DocumentReader.cpp index 01b97285f0..5102632604 100644 --- a/src/Base/DocumentReader.cpp +++ b/src/Base/DocumentReader.cpp @@ -19,41 +19,24 @@ * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ -//#include "PreCompiled.h" - -//#include - #include "DocumentReader.h" - -//#include "Reader.h" -//#include "Base64.h" -//#include "Console.h" #include "InputSource.h" -//#include "Persistence.h" -//#include "Sequencer.h" -//#include "Stream.h" #include "XMLTools.h" -//#ifdef _MSC_VER -//#include -//#endif -//#include #include #include +#include "Persistence.h" +#include "Sequencer.h" + + +#ifdef _MSC_VER +#include +#endif +#include + #ifndef _PreComp_ -//# include -//# include # include -//# include -//# include -//# include -//# include # include -//# include -//# include -//# include -//# include -//# include #endif XERCES_CPP_NAMESPACE_USE @@ -72,25 +55,8 @@ DocumentReader::DocumentReader() gDoSchema = false; gSchemaFullChecking = false; gDoCreate = true; - - /* - gOutputEncoding = nullptr; - gMyEOLSequence = nullptr; - - gSplitCdataSections = true; - gDiscardDefaultContent = true; - gUseFilter = true; - gFormatPrettyPrint = true; - */ - } -//DocumentReader::~DocumentReader() -//{ - //delete parser; -//} -//int DocumentReader::LoadDocument(const XERCES_CPP_NAMESPACE_QUALIFIER InputSource& inputSource) -//int DocumentReader::LoadDocument(std::istream& Stream,std::string filename) int DocumentReader::LoadDocument(Base::Reader& reader) { FileInfo _File( reader.getFileName() ); @@ -139,7 +105,7 @@ int DocumentReader::LoadDocument(Base::Reader& reader) return 0; } - XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* _pDocument = parser->adoptDocument(); + XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* _pDocument = parser->adoptDocument(); delete parser; delete errReporter; @@ -174,9 +140,7 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(const cha for (DOMNode *clChild = _pGroupNode->getFirstChild(); clChild != nullptr; clChild = clChild->getNextSibling()) { if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { - if (clChild->getAttributes()->getLength() > 0) { - return static_cast(clChild); - } + return static_cast(clChild); } } } @@ -191,9 +155,6 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(XERCES_CP if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { return static_cast(clChild); - //if (clChild->getAttributes()->getLength() > 0) { - //return static_cast(clChild); - //} } } } @@ -216,41 +177,22 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindNextElement(XERCE return nullptr; } -/* -//CONTENT: -const char * DocumentReader::GetContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl) const -{ - if (!DOMEl) - return nullptr; - return StrX(DOMEl->getAttribute(XStr("Value").unicodeForm())).c_str(); -} - -std::string DocumentReader::GetContentASCII(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl) const -{ - //return std::string(StrXUTF8(pcElem->getNodeValue()).c_str() ); - //maybe its better to use getNodeValue() - if (!DOMEl) - return nullptr; - return std::string( StrXUTF8(DOMEl->getAttribute(XStr("Value").unicodeForm())).c_str() ); -} -*/ - -long DocumentReader::ContentToInt( const char* content ) const +long DocumentReader::ContentToInt( const char* content ) { return atol( content ); } -unsigned long DocumentReader::ContentToUnsigned(const char* content) const +unsigned long DocumentReader::ContentToUnsigned(const char* content) { return strtoul(content,nullptr,10); } -double DocumentReader::ContentToFloat(const char* content) const +double DocumentReader::ContentToFloat(const char* content) { return atof(content); } -bool DocumentReader::ContentToBool(const char* content) const +bool DocumentReader::ContentToBool(const char* content) { if (strcmp(content,"1")) return false; @@ -282,18 +224,16 @@ const char * DocumentReader::GetAttribute(const char* Attr) const return nullptr; } const XMLCh * attr = _pGroupNode->getAttribute( xstr.unicodeForm() ); - //stringLen return strdup( StrX( attr ).c_str() );//strdup is needed since pointer from strx only exists in context where StrX() is created. } - -/* -unsigned int Base::XMLReader::getAttributeCount() const -{ - return static_cast(AttrMap.size()); -} -*/ - //Status +void Base::DocumentReader::setPartialRestore(bool on) +{ + setStatus(PartialRestore, on); + setStatus(PartialRestoreInDocumentObject, on); + setStatus(PartialRestoreInProperty, on); + setStatus(PartialRestoreInObject, on); +} void Base::DocumentReader::clearPartialRestoreProperty() { @@ -311,4 +251,77 @@ void Base::DocumentReader::setStatus(ReaderStatus pos, bool on) StatusBits.set(static_cast(pos), on); } +const char *Base::DocumentReader::addFile(const char* Name, Base::Persistence *Object) +{ + FileEntry temp; + temp.FileName = Name; + temp.Object = Object; + FileList.push_back(temp); + FileNames.push_back( temp.FileName ); + + return Name; +} + +void Base::DocumentReader::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. + // 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 + // file, then. + // In either case it's guaranteed that the order of the files is kept. + zipios::ConstEntryPointer entry; + try { + entry = zipstream.getNextEntry(); + } + catch (const std::exception&) { + // There is no further file at all. This can happen if the + // project file was created without GUI + return; + } + 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; + // 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) + ++jt; + // If this condition is true both file names match and we can read-in the data, otherwise + // no file name for the current entry in the zip was registered. + if (jt != FileList.end()) { + try { + Base::Reader reader(zipstream, jt->FileName, FileVersion); + jt->Object->RestoreDocFile(reader); + if (reader.getLocalReader()) + reader.getLocalReader()->readFiles(zipstream); + if (reader.getLocalDocReader()) + reader.getLocalDocReader()->readFiles(zipstream); + + }catch(...) { + // For any exception we just continue with the next file. + // It doesn't matter if the last reader has read more or + // less data than the file size would allow. + // All what we need to do is to notify the user about the + // failure. + Base::Console().Error("Reading failed from embedded file(DocumentReader): %s\n", entry->toString().c_str()); + } + // Go to the next registered file name + it = jt + 1; + } + + seq.next(); + + // In either case we must go to the next entry + try { + entry = zipstream.getNextEntry(); + } + catch (const std::exception&) { + // there is no further entry + break; + } + } +} diff --git a/src/Base/DocumentReader.h b/src/Base/DocumentReader.h index e414046f37..863fa521de 100644 --- a/src/Base/DocumentReader.h +++ b/src/Base/DocumentReader.h @@ -25,18 +25,16 @@ #include #include -//#include -//#include +#include #include #include - -//#include -//#include -//#include #include -//#include "FileInfo.h"//reemplazado por: +//#include "FileInfo.h"//remplaced: #include -//#include + +namespace zipios { +class ZipInputStream; +} XERCES_CPP_NAMESPACE_BEGIN class DOMNode; @@ -49,7 +47,7 @@ namespace Base class Reader; class Persistence; -class BaseExport DocumentReader //: public ParameterManager +class BaseExport DocumentReader { public: enum ReaderStatus { @@ -66,12 +64,12 @@ public: XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElement(const char* Type) const; XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const; - long ContentToASCII(const char* Content) const; + static long ContentToASCII(const char* Content); - long ContentToInt(const char* Content) const; - unsigned long ContentToUnsigned(const char* Content) const; - double ContentToFloat(const char* Content) const; - bool ContentToBool(const char* Content) const; + static long ContentToInt(const char* Content); + static unsigned long ContentToUnsigned(const char* Content); + static double ContentToFloat(const char* Content); + static bool ContentToBool(const char* Content); const char* GetAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* DOMEl, const char* Attr) const; const char* GetAttribute(const char* Attr) const; @@ -80,15 +78,38 @@ public: bool testStatus(ReaderStatus pos) const; /// set the status bits void setStatus(ReaderStatus pos, bool on); + /// sets simultaneously the global and local PartialRestore bits + void setPartialRestore(bool on); void clearPartialRestoreProperty(); + /// add a read request of a persistent object + const char *addFile(const char* Name, Base::Persistence *Object); + + void readFiles(zipios::ZipInputStream &zipstream) const; + + std::shared_ptr getLocalReader() const; + + struct FileEntry { + std::string FileName; + Base::Persistence *Object; + }; + std::vector FileList; + + /// Version of the file format + int FileVersion; + + + protected: XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *_pGroupNode; bool gDoNamespaces ; bool gDoSchema ; bool gSchemaFullChecking ; bool gDoCreate ; + + std::vector FileNames; + std::bitset<32> StatusBits; }; diff --git a/src/Base/Persistence.cpp b/src/Base/Persistence.cpp index 742a06cf35..0d69101985 100644 --- a/src/Base/Persistence.cpp +++ b/src/Base/Persistence.cpp @@ -34,6 +34,10 @@ /// Here the FreeCAD includes sorted by Base,App,Gui...... #include "Persistence.h" +#ifndef _PreComp_ +# include +#endif + using namespace Base; @@ -61,6 +65,14 @@ void Persistence::Save (Writer &/*writer*/) const assert(0); } +void Persistence::Restore(DocumentReader &/*reader*/) +{ +} + +void Persistence::Restore(DocumentReader &/*reader*/,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement */*containerEl*/) +{ +} + void Persistence::Restore(DocumentReader &/*reader*/) { // you have to implement this method in all descending classes! diff --git a/src/Base/Persistence.h b/src/Base/Persistence.h index 7941f7c748..cf4634c66d 100644 --- a/src/Base/Persistence.h +++ b/src/Base/Persistence.h @@ -26,6 +26,15 @@ #include "BaseClass.h" +#include + +XERCES_CPP_NAMESPACE_BEGIN + class DOMNode; + class DOMElement; +// class DefaultHandler; +// class SAX2XMLReader; +XERCES_CPP_NAMESPACE_END + namespace Base { class Reader; @@ -79,6 +88,8 @@ public: */ virtual void Restore(XMLReader &/*reader*/) = 0; virtual void Restore(DocumentReader &/*reader*/); + virtual void Restore(DocumentReader &/*reader*/,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement */*containerEl*/); + /** This method is used to save large amounts of data to a binary file. * Sometimes it makes no sense to write property data as XML. In case the * amount of data is too big or the data type has a more effective way to @@ -143,6 +154,8 @@ public: * @see Base::Reader,Base::XMLReader */ virtual void RestoreDocFile(Reader &/*reader*/); + + /// Encodes an attribute upon saving. static std::string encodeAttribute(const std::string&); diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index 92e207953b..8ff610621d 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -31,6 +31,7 @@ #include #include "Reader.h" +#include "DocumentReader.h" #include "Base64.h" #include "Console.h" #include "InputSource.h" @@ -333,9 +334,11 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const try { Base::Reader reader(zipstream, jt->FileName, FileVersion); jt->Object->RestoreDocFile(reader); - - if (reader.getLocalReader()) - reader.getLocalReader()->readFiles(zipstream); + if (reader.getLocalReader()) + reader.getLocalReader()->readFiles(zipstream); + if (reader.getLocalDocReader()) + reader.getLocalDocReader()->readFiles(zipstream); + }catch(...) { // For any exception we just continue with the next file. // It doesn't matter if the last reader has read more or @@ -577,3 +580,13 @@ std::shared_ptr Base::Reader::getLocalReader() const { return(this->localreader); } + +void Base::Reader::initLocalDocReader(std::shared_ptr reader) +{ + this->localdocreader = reader; +} + +std::shared_ptr Base::Reader::getLocalDocReader() const +{ + return(this->localdocreader); +} diff --git a/src/Base/Reader.h b/src/Base/Reader.h index d06617a95f..6673a3a43b 100644 --- a/src/Base/Reader.h +++ b/src/Base/Reader.h @@ -48,6 +48,7 @@ XERCES_CPP_NAMESPACE_END namespace Base { class Persistence; +class DocumentReader; /** The XML reader class * This is an important helper class for the store and retrieval system @@ -295,13 +296,16 @@ public: std::string getFileName() const; int getFileVersion() const; void initLocalReader(std::shared_ptr); + void initLocalDocReader(std::shared_ptr); std::shared_ptr getLocalReader() const; + std::shared_ptr getLocalDocReader() const; private: std::istream& _str; std::string _name; int fileVersion; std::shared_ptr localreader; + std::shared_ptr localdocreader; }; } diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index f4c31f7b8a..ef64d500cc 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1400,6 +1400,7 @@ void Document::Save (Base::Writer &writer) const void Document::Restore(Base::XMLReader &reader) { reader.addFile("GuiDocument.xml",this); + // hide all elements to avoid to update the 3d view when loading data files // RestoreDocFile then restores the visibility status again std::map::iterator it; @@ -1414,134 +1415,195 @@ void Document::Restore(Base::XMLReader &reader) */ void Document::RestoreDocFile(Base::Reader &reader) { - Base::DocumentReader docReader; - docReader.LoadDocument(reader); - //docReader.GetRootElement()//can be used to get Document XMLElement, but not needed. - const char* SchemaVersion_cstr = docReader.GetAttribute("SchemaVersion"); - long SchemaVersion = docReader.ContentToInt( SchemaVersion_cstr ); - const char* HasExpansion_cstr = docReader.GetAttribute("HasExpansion"); - if(HasExpansion_cstr){ - auto tree = TreeWidget::instance(); + readUsing_DocumentReader(reader); + //readUsing_XMLReader(reader); + setModified(false); +} + +void Document::readUsing_XMLReader(Base::Reader &reader){ + // We must create an XML parser to read from the input stream + std::shared_ptr localreader = std::make_shared("GuiDocument.xml", reader); + //localreader->FileVersion = reader.getFileVersion(); + + localreader->readElement("Document"); + long scheme = localreader->getAttributeAsInteger("SchemaVersion"); + //localreader->DocumentSchema = scheme; + + bool hasExpansion = localreader->hasAttribute("HasExpansion"); + if(hasExpansion) { + auto tree = TreeWidget::instance(); if(tree) { auto docItem = tree->getDocumentItem(this); if(docItem) - docItem->Restore(docReader); + docItem->Restore(*localreader); } } - + // At this stage all the document objects and their associated view providers exist. // Now we must restore the properties of the view providers only. - if (SchemaVersion == 1) { - auto VProviderDataDOM = docReader.FindElement("ViewProviderData"); + // + // SchemeVersion "1" + if (scheme == 1) { + + // read the viewproviders itself + + localreader->readElement("ViewProviderData"); + int Cnt = localreader->getAttributeAsInteger("Count"); + + for (int i=0; ireadElement("ViewProvider"); + std::string name = localreader->getAttribute("name"); + bool expanded = false; + if (!hasExpansion && localreader->hasAttribute("expanded")) { + + const char* attr = localreader->getAttribute("expanded"); + if (strcmp(attr,"1") == 0) { + expanded = true; + } + } + ViewProvider* pObj = getViewProviderByName(name.c_str()); + if (pObj){// check if this feature has been registered + pObj->Restore(*localreader); + } + + if (pObj && expanded) { + auto vp = static_cast(pObj); + this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); + } + localreader->readEndElement("ViewProvider"); + } + + localreader->readEndElement("ViewProviderData"); + + + // read camera settings + localreader->readElement("Camera"); + const char* ppReturn = localreader->getAttribute("settings"); + cameraSettings.clear(); + if(ppReturn && ppReturn[0]) { + saveCameraSettings(ppReturn); + try { + const char** pReturnIgnore=nullptr; + std::list mdi = getMDIViews(); + for (const auto & it : mdi) { + if (it->onHasMsg("SetCamera")) + it->onMsg(cameraSettings.c_str(), pReturnIgnore); + } + } + + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + } + } + localreader->readEndElement("Document"); + reader.initLocalReader(localreader); +} + +void Document::readUsing_DocumentReader(Base::Reader &reader){ + std::shared_ptr docReader = std::make_shared(); + docReader->LoadDocument(reader); + //docReader->GetRootElement()//can be used to get Document XMLElement, but not needed. + const char* SchemaVersion_cstr = docReader->GetAttribute("SchemaVersion"); + long SchemaVersion = docReader->ContentToInt( SchemaVersion_cstr ); + const char* HasExpansion_cstr = docReader->GetAttribute("HasExpansion"); + if(HasExpansion_cstr){ + auto tree = TreeWidget::instance(); + if(tree) { + auto docItem = tree->getDocumentItem(this); + if(docItem) + docItem->Restore(*docReader); + } + } + + // At this stage all the document objects and their associated view providers exist. + // Now we must restore the properties of the view providers only. + if (SchemaVersion == 1) { + auto VProviderDataDOM = docReader->FindElement("ViewProviderData"); if(VProviderDataDOM){ - const char* vpd_count_cstr = docReader.GetAttribute(VProviderDataDOM,"Count"); + const char* vpd_count_cstr = docReader->GetAttribute(VProviderDataDOM,"Count"); if(vpd_count_cstr){ - long Cnt = docReader.ContentToInt( vpd_count_cstr ); - auto prev_ViewProviderDOM = docReader.FindElement(VProviderDataDOM,"ViewProvider"); + long Cnt = docReader->ContentToInt( vpd_count_cstr ); + auto prev_ViewProviderDOM = docReader->FindElement(VProviderDataDOM,"ViewProvider"); if(prev_ViewProviderDOM){ - const char* name_cstr = docReader.GetAttribute(prev_ViewProviderDOM,"name"); - const char* expanded_cstr = docReader.GetAttribute(prev_ViewProviderDOM,"expanded"); + const char* name_cstr = docReader->GetAttribute(prev_ViewProviderDOM,"name"); + const char* expanded_cstr = docReader->GetAttribute(prev_ViewProviderDOM,"expanded"); bool expanded = false; if (!HasExpansion_cstr && expanded_cstr) { if (strcmp(expanded_cstr,"1") == 0) { expanded = true; } } - ViewProvider* pObj = getViewProviderByName(name_cstr); - if (pObj) - pObj->Restore(docReader,prev_ViewProviderDOM); - + if (pObj){ + pObj->Restore(*docReader,prev_ViewProviderDOM); + } if (pObj && expanded) { auto vp = static_cast(pObj); this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); } - } - for (int i=1; iFindNextElement(prev_ViewProviderDOM,"ViewProvider"); + if(ViewProviderDOM_i){ + const char* name_cstr_i = docReader->GetAttribute(ViewProviderDOM_i,"name"); + const char* expanded_cstr_i = docReader->GetAttribute(ViewProviderDOM_i,"expanded"); + bool expanded = false; + if (!HasExpansion_cstr && expanded_cstr_i) { + if (strcmp(expanded_cstr_i,"1") == 0) { + expanded = true; + } } + ViewProvider* pObj = getViewProviderByName(name_cstr_i); + if (pObj){ + pObj->Restore(*docReader,ViewProviderDOM_i); + } + + if (pObj && expanded) { + auto vp = static_cast(pObj); + this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); + } + prev_ViewProviderDOM = ViewProviderDOM_i; } - ViewProvider* pObj = getViewProviderByName(name_cstr_i); - if (pObj) - pObj->Restore(docReader,ViewProviderDOM_i);//Im still implementing this, which calls ExtensionContainer::Restore. - - if (pObj && expanded) { - auto vp = static_cast(pObj); - this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); - } - prev_ViewProviderDOM = ViewProviderDOM_i; } + } + + } } // read camera settings - auto CameraDOM = docReader.FindElement("Camera"); + auto CameraDOM = docReader->FindElement("Camera"); if(CameraDOM){ - const char* ppReturn = docReader.GetAttribute(CameraDOM,"settings"); + const char* ppReturn = docReader->GetAttribute(CameraDOM,"settings"); cameraSettings.clear(); if(ppReturn && ppReturn[0]) { - saveCameraSettings(ppReturn); - try { - const char** pReturnIgnore=nullptr; - std::list mdi = getMDIViews(); - for (const auto & it : mdi) { - if (it->onHasMsg("SetCamera")) - it->onMsg(cameraSettings.c_str(), pReturnIgnore); - } - } - catch (const Base::Exception& e) { - Base::Console().Error("%s\n", e.what()); - } - } + saveCameraSettings(ppReturn); + try { + const char** pReturnIgnore=nullptr; + std::list mdi = getMDIViews(); + for (const auto & it : mdi) { + if (it->onHasMsg("SetCamera")) + it->onMsg(cameraSettings.c_str(), pReturnIgnore); + } + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + } + } + + auto ProjectUnitSysDOM = docReader->FindElement("ProjectUnitSystem"); + if(ProjectUnitSysDOM){ + const char* US_cstr = docReader->GetAttribute(ProjectUnitSysDOM,"US"); + const char* ignore_cstr = docReader->GetAttribute(ProjectUnitSysDOM,"ignore"); + + d->projectUnitSystem = docReader->ContentToInt( US_cstr ); + d->projectUnitSystemIgnore = docReader->ContentToInt( ignore_cstr ); } - - /* - try{//if this fails then all other reading attemps will fail, since XERCES doesnt allow to get back to previous point, reading the file should restarted each time an element its not present, since it looks for it untill the end of the document. - //Since ProjectUnitSystem its the only optional field, and its being read at the end of this function, it does not cause any issue, but if other optional its added the way of reading XML used in Reader.cpp will be obsolete - - localreader->readElement("ProjectUnitSystem"); - Base::Console().Error("readElement(ProjectUnitSystem)\n"); - int US = localreader->getAttributeAsInteger("US"); - int ignore = localreader->getAttributeAsInteger("ignore"); - d->projectUnitSystem = US; - d->projectUnitSystemIgnore = ignore; - - }catch (const Base::XMLParseException& e) { - Base::Console().Warning("ProjectUnitSystem not found: %s\n", e.getMessage().c_str()); - }catch(const Base::XMLBaseException& e){ - Base::Console().Warning("ProjectUnitSystem XMLBaseException: %s\n", e.getMessage().c_str()); - }catch(...) { - Base::Console().Error("ProjectUnitSystem catch(...)\n"); - } - */ - } - /* - - try{ - localreader->readEndElement("Document"); - }catch(const Base::XMLParseException& e){ - Base::Console().Warning("readEndElement(Document) XMLParseException: %s\n", e.getMessage().c_str()); - }catch(const Base::XMLBaseException& e){ - Base::Console().Warning("readEndElement(Document) XMLBaseException: %s\n", e.getMessage().c_str()); - }catch(...) { - Base::Console().Error("readEndElement(Document) unkown error.\n"); } - */ - - // reset modified flag - //dont see what this does: - //reader.initLocalReader(localreader); - setModified(false); + reader.initLocalDocReader(docReader); } void Document::slotStartRestoreDocument(const App::Document& doc) diff --git a/src/Gui/Document.h b/src/Gui/Document.h index f7fdad5ebd..5eff465959 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -158,6 +158,8 @@ public: void SaveDocFile (Base::Writer &writer) const override; /// This method is used to restore large amounts of data from a binary file. void RestoreDocFile(Base::Reader &reader) override; + void readUsing_XMLReader(Base::Reader &reader); + void readUsing_DocumentReader(Base::Reader &reader); void exportObjects(const std::vector&, Base::Writer&); void importObjects(const std::vector&, Base::Reader&, const std::map& nameMapping); diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 54b7d5b2f6..0e255c1a19 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -354,17 +354,29 @@ public: } void restore(Base::DocumentReader& reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *expandEl) { - Base::Console().Error("ExpandInfo restore\n"); const char* count_cstr = reader.GetAttribute(expandEl,"count"); if(count_cstr){ long count = reader.ContentToInt( count_cstr ); - Base::Console().Error("ExpandInfo count: %d\n",count); - auto _expandEl = reader.FindElement(expandEl,"Expand"); - const char* name_cstr = reader.GetAttribute(_expandEl,"name"); - Base::Console().Error("ExpandInfo name_cstr: %s\n",name_cstr); + auto prev_ExpandDOM = reader.FindElement(expandEl,"Expand"); + const char* name_cstr = reader.GetAttribute(prev_ExpandDOM,"name"); + const char* _count_cstr = reader.GetAttribute(prev_ExpandDOM,"count"); auto& entry = (*this)[name_cstr]; - entry.reset(new ExpandInfo); - entry->restore(reader,_expandEl); + if(_count_cstr){ + entry.reset(new ExpandInfo); + entry->restore(reader,prev_ExpandDOM); + } + + for (int i = 1; i < count; ++i) { + auto ExpandDOM_i = reader.FindNextElement(prev_ExpandDOM,"Expand"); + const char* name_cstr = reader.GetAttribute(ExpandDOM_i,"name"); + const char* _count_cstr = reader.GetAttribute(ExpandDOM_i,"count"); + auto& entry = (*this)[name_cstr]; + if(_count_cstr){ + entry.reset(new ExpandInfo); + entry->restore(reader,ExpandDOM_i); + } + prev_ExpandDOM = ExpandDOM_i; + } } } }; @@ -3947,19 +3959,16 @@ void DocumentItem::Restore(Base::XMLReader& reader) { } void DocumentItem::Restore(Base::DocumentReader& reader) { - Base::Console().Error("DocumentItem::Restore() DocumentReader\n"); auto expandEl = reader.FindElement("Expand"); if( !reader.GetAttribute(expandEl,"count") ) return; _ExpandInfo.reset(new ExpandInfo); _ExpandInfo->restore(reader,expandEl); - //TODO NOW for (auto inst : TreeWidget::Instances) { if (inst != getTree()) { auto docItem = inst->getDocumentItem(document()); if (docItem) docItem->_ExpandInfo = _ExpandInfo; - } } } From 1db4bcf3741e058496c5f8ca1b03cf6a6025d1f9 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Fri, 30 Jun 2023 20:27:12 -0300 Subject: [PATCH 05/25] Revert "DocumentReader implemented for GuiDocument.xml reading." This reverts commit 2eb5fd7f132035e24880bd88076d49ed368e23e0. --- src/App/Document.cpp | 6 +- src/App/DynamicProperty.cpp | 30 --- src/App/DynamicProperty.h | 11 - src/App/Extension.cpp | 20 +- src/App/Extension.h | 4 - src/App/ExtensionContainer.cpp | 110 +--------- src/App/ExtensionContainer.h | 8 +- src/App/PropertyContainer.cpp | 219 +++++++++----------- src/App/PropertyContainer.h | 15 +- src/App/PropertyStandard.cpp | 357 --------------------------------- src/App/PropertyStandard.h | 24 --- src/Base/DocumentReader.cpp | 175 ++++++++-------- src/Base/DocumentReader.h | 51 ++--- src/Base/Persistence.cpp | 12 -- src/Base/Persistence.h | 13 -- src/Base/Reader.cpp | 19 +- src/Base/Reader.h | 4 - src/Gui/Document.cpp | 250 +++++++++-------------- src/Gui/Document.h | 2 - src/Gui/Tree.cpp | 29 +-- 20 files changed, 305 insertions(+), 1054 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 30a65d4579..a72cc89188 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -87,7 +87,6 @@ recompute path. Also, it enables more complicated dependencies beyond trees. #include #include #include -#include #include #include #include @@ -1228,6 +1227,7 @@ Document::readObjects(Base::XMLReader& reader) // read the object types reader.readElement("Objects"); int Cnt = reader.getAttributeAsInteger("Count"); + if(!reader.hasAttribute(FC_ATTR_DEPENDENCIES)) d->partialLoadObjects.clear(); else if(!d->partialLoadObjects.empty()) { @@ -2023,12 +2023,12 @@ void Document::restore (const char *filename, // without GUI. But if available then follow after all data files of the App document. signalRestoreDocument(reader); reader.readFiles(zipstream); - + if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestore)) { setStatus(Document::PartialRestore, true); Base::Console().Error("There were errors while loading the file. Some data might have been modified or not recovered at all. Look above for more specific information about the objects involved.\n"); } - + if(!delaySignal) afterRestore(true); } diff --git a/src/App/DynamicProperty.cpp b/src/App/DynamicProperty.cpp index c105483f42..7ad6419b33 100644 --- a/src/App/DynamicProperty.cpp +++ b/src/App/DynamicProperty.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include "DynamicProperty.h" #include "Application.h" @@ -323,35 +322,6 @@ Property *DynamicProperty::restore(PropertyContainer &pc, return addDynamicProperty(pc,TypeName, PropName, group, doc, attribute, readonly, hidden); } -Property *DynamicProperty::restore(PropertyContainer &pc, - const char *PropName, const char *TypeName, Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM) -{ - const char* group_cstr = reader.GetAttribute(PropertyDOM,"group"); - if(!group_cstr) - return nullptr; - - short attribute = 0; - bool readonly = false, hidden = false; - - const char* doc_cstr = reader.GetAttribute(PropertyDOM,"doc"); - const char* attr_cstr = reader.GetAttribute(PropertyDOM,"attr"); - - if(attr_cstr){ - std::istringstream str(attr_cstr); - str >> attribute; - } - - const char* ro_cstr = reader.GetAttribute(PropertyDOM,"ro"); - if(ro_cstr) - readonly = (ro_cstr[0]-48) != 0; - - const char* hide_cstr = reader.GetAttribute(PropertyDOM,"hide"); - if(hide_cstr) - hidden = (hide_cstr[0]-48) != 0; - - return addDynamicProperty(pc,TypeName, PropName, group_cstr, doc_cstr, attribute, readonly, hidden); -} - DynamicProperty::PropData DynamicProperty::getDynamicPropertyData(const Property *prop) const { auto &index = props.get<1>(); diff --git a/src/App/DynamicProperty.h b/src/App/DynamicProperty.h index e02a2e9659..a292f74c8e 100644 --- a/src/App/DynamicProperty.h +++ b/src/App/DynamicProperty.h @@ -33,15 +33,6 @@ #include #include #include -#include - - -XERCES_CPP_NAMESPACE_BEGIN - class DOMNode; - class DOMElement; -// class DefaultHandler; -// class SAX2XMLReader; -XERCES_CPP_NAMESPACE_END namespace Base { @@ -154,8 +145,6 @@ public: Property *restore(PropertyContainer &pc, const char *PropName, const char *TypeName, Base::XMLReader &reader); - Property *restore(PropertyContainer &pc, - const char *PropName, const char *TypeName, Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM); struct PropData { Property* property; diff --git a/src/App/Extension.cpp b/src/App/Extension.cpp index ce0991f042..c3dea0f5e7 100644 --- a/src/App/Extension.cpp +++ b/src/App/Extension.cpp @@ -34,6 +34,7 @@ #include "ExtensionPython.h" #include + /* We do not use a standard property macro for type initiation. The reason is that we have the first * PropertyData in the extension chain, there is no parent property data. */ @@ -78,6 +79,7 @@ void Extension::initExtensionType(Base::Type type) { } void Extension::initExtension(ExtensionContainer* obj) { + if (m_extensionType.isBad()) throw Base::RuntimeError("Extension: Extension type not set"); @@ -203,24 +205,6 @@ bool Extension::extensionHandleChangedPropertyType(Base::XMLReader &reader, cons return false; }; -bool Extension::extensionHandleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) -{ - (void) reader; - (void) TypeName; - (void) PropName; - - return false; -}; - -bool Extension::extensionHandleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) -{ - (void) reader; - (void) TypeName; - (void) prop; - - return false; -}; - namespace App { EXTENSION_PROPERTY_SOURCE_TEMPLATE(App::ExtensionPython, App::ExtensionPython::Inherited) diff --git a/src/App/Extension.h b/src/App/Extension.h index d667d35900..84bb442a10 100644 --- a/src/App/Extension.h +++ b/src/App/Extension.h @@ -290,10 +290,6 @@ protected: virtual bool extensionHandleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName); /// returns true if the property type change was handled by the extension. virtual bool extensionHandleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop); - /// returns true if the property name change was handled by the extension. - virtual bool extensionHandleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName); - /// returns true if the property type change was handled by the extension. - virtual bool extensionHandleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop); friend class App::ExtensionContainer; diff --git a/src/App/ExtensionContainer.cpp b/src/App/ExtensionContainer.cpp index 742b322998..372967dbae 100644 --- a/src/App/ExtensionContainer.cpp +++ b/src/App/ExtensionContainer.cpp @@ -32,11 +32,6 @@ #include "ExtensionContainer.h" #include -#ifndef _PreComp_ -# include -//# include -#endif - using namespace App; @@ -313,7 +308,7 @@ void ExtensionContainer::Restore(Base::XMLReader& reader) { App::PropertyContainer::Restore(reader); } -void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) { +void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl) { //restore dynamic extensions. //Note 1: The extension element must be read first, before all other object elements. That is // needed as the element works together with an object element attribute, which would be @@ -321,6 +316,7 @@ void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPA //Note 2: This must happen before the py object of this container is used, as only in the // pyobject constructor the extension methods are added to the container. restoreExtensions(reader,viewProviderEl); + //TODO NOW: //App::PropertyContainer::Restore(reader); } @@ -433,80 +429,6 @@ void ExtensionContainer::restoreExtensions(Base::DocumentReader& reader,XERCES_C } } -void ExtensionContainer::restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) { - //Dynamic extensions are optional (also because they are introduced late into the document format) - //and hence it is possible that the element does not exist. As we cannot check for the existence of - //an element a object attribute is set if extensions are available. Here we check that - //attribute, and only if it exists the extensions element will be available. - const char* expanded_cstr = reader.GetAttribute(containerEl,"expanded"); - if(!expanded_cstr) - return; - auto ExtensionsDOM = reader.FindElement(containerEl,"Extensions"); - if(ExtensionsDOM){ - const char* cnt_cstr = reader.GetAttribute(ExtensionsDOM,"Count"); - if(cnt_cstr){ - long Cnt = reader.ContentToInt( cnt_cstr ); - auto prev_ExtensionDOM = reader.FindElement(ExtensionsDOM,"Extension"); - readExtension(reader,prev_ExtensionDOM); - for (int i=1 ;i(extension.createInstance()); - //check if this really is a python extension! - if (!ext->isPythonExtension()) { - delete ext; - std::stringstream str; - str << "Extension is not a python addable version: '" << type_cstr << "'" << std::ends; - throw Base::TypeError(str.str()); - } - ext->initExtension(this); - if( strcmp(ext->getExtensionTypeId().getName(), type_cstr) == 0 ) - ext->extensionRestore(reader); - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } -#ifndef FC_DEBUG - catch (...) { - Base::Console().Error("ExtensionContainer::Restore: Unknown C++ exception thrown\n"); - } -#endif - -} - void ExtensionContainer::restoreExtensions(Base::XMLReader& reader) { //Dynamic extensions are optional (also because they are introduced late into the document format) @@ -586,20 +508,6 @@ void ExtensionContainer::handleChangedPropertyName(Base::XMLReader &reader, cons PropertyContainer::handleChangedPropertyName(reader, TypeName, PropName); } -void ExtensionContainer::handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) -{ - //inform all extensions about changed property name. This includes all properties from the - //extended object (this) as well as all extension properties - for(const auto& entry : _extensions) { - bool handled = entry.second->extensionHandleChangedPropertyName(reader, TypeName, PropName); - - if(handled) - return; // one property change needs only be handled once - } - - PropertyContainer::handleChangedPropertyName(reader, TypeName, PropName); -} - void ExtensionContainer::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop) { //inform all extensions about changed property type. This includes all properties from the @@ -613,17 +521,3 @@ void ExtensionContainer::handleChangedPropertyType(Base::XMLReader &reader, cons PropertyContainer::handleChangedPropertyType(reader, TypeName, prop); } - -void ExtensionContainer::handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) -{ - //inform all extensions about changed property type. This includes all properties from the - //extended object (this) as well as all extension properties - for(const auto& entry : _extensions) { - bool handled = entry.second->extensionHandleChangedPropertyType(reader, TypeName, prop); - - if(handled) - return; // one property change needs only be handled once - } - - PropertyContainer::handleChangedPropertyType(reader, TypeName, prop); -} diff --git a/src/App/ExtensionContainer.h b/src/App/ExtensionContainer.h index d71908ba7a..9c90b95fbf 100644 --- a/src/App/ExtensionContainer.h +++ b/src/App/ExtensionContainer.h @@ -185,13 +185,13 @@ public: void Save(Base::Writer& writer) const override; void Restore(Base::XMLReader& reader) override; - void Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl); + void Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); //those methods save/restore the dynamic extensions without handling properties, which is something //done by the default Save/Restore methods. void saveExtensions(Base::Writer& writer) const; void restoreExtensions(Base::XMLReader& reader); - void restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl); + void restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); /** Extends the rules for handling property name changed, so that extensions are given an opportunity to handle it. * If an extension handles a change, neither the rest of the extensions, nor the container itself get to handle it. @@ -201,7 +201,6 @@ public: * If no extension handles the request, then the containers handleChangedPropertyName() is called. */ virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) override; - virtual void handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) override; /** Extends the rules for handling property type changed, so that extensions are given an opportunity to handle it. * If an extension handles a change, neither the rest of the extensions, nor the container itself get to handle it. * @@ -210,9 +209,6 @@ public: * If no extension handles the request, then the containers handleChangedPropertyType() is called. */ virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop) override; - virtual void handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) override; - - void readExtension(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ExtensionDOM); private: //stored extensions diff --git a/src/App/PropertyContainer.cpp b/src/App/PropertyContainer.cpp index 5d5ee8dd2e..837162fc4b 100644 --- a/src/App/PropertyContainer.cpp +++ b/src/App/PropertyContainer.cpp @@ -32,10 +32,6 @@ #include "PropertyContainer.h" #include -#ifndef _PreComp_ -# include -#endif - FC_LOG_LEVEL_INIT("App",true,true) @@ -79,9 +75,8 @@ App::Property* PropertyContainer::addDynamicProperty( Property *PropertyContainer::getPropertyByName(const char* name) const { auto prop = dynamicProps.getDynamicPropertyByName(name); - if(prop){ + if(prop) return prop; - } return getPropertyData().getPropertyByName(this,name); } @@ -204,13 +199,6 @@ void PropertyContainer::handleChangedPropertyName(Base::XMLReader &reader, const (void)PropName; } -void PropertyContainer::handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) -{ - (void)reader; - (void)TypeName; - (void)PropName; -} - /** * @brief PropertyContainer::handleChangedPropertyType is called during restore to possibly * fix reading of older versions of the property container. This method is typically called @@ -230,13 +218,6 @@ void PropertyContainer::handleChangedPropertyType(XMLReader &reader, const char (void)prop; } -void PropertyContainer::handleChangedPropertyType(DocumentReader &reader, const char *TypeName, Property *prop) -{ - (void)reader; - (void)TypeName; - (void)prop; -} - PropertyData PropertyContainer::propertyData; void PropertyContainer::Save (Base::Writer &writer) const @@ -340,7 +321,6 @@ void PropertyContainer::Restore(Base::XMLReader &reader) if(reader.hasAttribute("TransientCount")) transientCount = reader.getAttributeAsUnsigned("TransientCount"); - for (int i=0;igetContainer() != this){ + if(!prop || prop->getContainer() != this) prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); - } decltype(Property::StatusBits) status; if(reader.hasAttribute("status")) { @@ -424,115 +403,101 @@ void PropertyContainer::Restore(Base::XMLReader &reader) reader.readEndElement("Properties"); } -void PropertyContainer::Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) +void PropertyContainer::Restore(Base::DocumentReader &reader) { + //TODO NOW + Base::Console().Error("PropertyContainer::Restore: DocumentReader\n"); reader.clearPartialRestoreProperty(); - - auto PropertiesDOM = reader.FindElement(containerEl,"Properties"); - const char* count_cstr = reader.GetAttribute(PropertiesDOM,"Count"); - if(count_cstr){ - long Cnt = reader.ContentToInt( count_cstr ); - const char* TransientCount_cstr = reader.GetAttribute(PropertiesDOM,"TransientCount"); - int transientCount = 0; - if(TransientCount_cstr) - transientCount = reader.ContentToUnsigned( TransientCount_cstr ); - - for (int i=0;igetName() << "'"); - if(prop && status_cstr){ - int u_status = reader.ContentToUnsigned( status_cstr ); - prop->setStatusValue(u_status); - } - } - if(Cnt){ - auto prev_PropertyDOM = reader.FindElement(PropertiesDOM,"Property"); - readProperty(reader,prev_PropertyDOM); - for (int i=1 ;igetContainer() != this){ - prop = dynamicProps.restore(*this,name_cstr,type_cstr,reader,PropertyDOM); - } - - decltype(Property::StatusBits) status; - const char* status_cstr = reader.GetAttribute(PropertyDOM,"status"); - if(status_cstr){ - int u_status = reader.ContentToUnsigned( status_cstr ); - status = decltype(status)(u_status); - if(prop) - prop->setStatusValue(status.to_ulong()); - } - // name and type match - if (prop && strcmp(prop->getTypeId().getName(), type_cstr) == 0) { - if (!prop->testStatus(Property::Transient) - && !status.test(Property::Transient) - && !status.test(Property::PropTransient) - && !prop->testStatus(Property::PropTransient)) - { - FC_TRACE("restore property '" << prop->getName() << "'"); - prop->Restore(reader,PropertyDOM); - }else - FC_TRACE("skip transient '" << prop->getName() << "'"); - } - // name matches but not the type - else if (prop) { - handleChangedPropertyType(reader, type_cstr, prop); - } - // name doesn't match, the sub-class then has to know - // if the property has been renamed or removed - else { - handleChangedPropertyName(reader, type_cstr, name_cstr); - } - - if (reader.testStatus(Base::DocumentReader::ReaderStatus::PartialRestoreInProperty)) { - Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",name_cstr,type_cstr); - reader.clearPartialRestoreProperty(); - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::RestoreError &) { - reader.setPartialRestore(true); - reader.clearPartialRestoreProperty(); - Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",name_cstr,type_cstr); - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } + int transientCount = 0; + if(reader.hasAttribute("TransientCount")) + transientCount = reader.getAttributeAsUnsigned("TransientCount"); + + for (int i=0;igetName() << "'"); + if(prop && reader.hasAttribute("status")) + prop->setStatusValue(reader.getAttributeAsUnsigned("status")); + } + + for (int i=0 ;igetContainer() != this) + prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); + + decltype(Property::StatusBits) status; + if(reader.hasAttribute("status")) { + status = decltype(status)(reader.getAttributeAsUnsigned("status")); + if(prop) + prop->setStatusValue(status.to_ulong()); + } + // name and type match + if (prop && strcmp(prop->getTypeId().getName(), TypeName.c_str()) == 0) { + if (!prop->testStatus(Property::Transient) + && !status.test(Property::Transient) + && !status.test(Property::PropTransient) + && !prop->testStatus(Property::PropTransient)) + { + FC_TRACE("restore property '" << prop->getName() << "'"); + prop->Restore(reader); + }else + FC_TRACE("skip transient '" << prop->getName() << "'"); + } + // name matches but not the type + else if (prop) { + handleChangedPropertyType(reader, TypeName.c_str(), prop); + } + // name doesn't match, the sub-class then has to know + // if the property has been renamed or removed + else { + handleChangedPropertyName(reader, TypeName.c_str(), PropName.c_str()); + } + + if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInProperty)) { + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str()); + reader.clearPartialRestoreProperty(); + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::RestoreError &) { + reader.setPartialRestore(true); + reader.clearPartialRestoreProperty(); + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str()); + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } #ifndef FC_DEBUG - catch (...) { - Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n"); - } + catch (...) { + Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n"); + } #endif + reader.readEndElement("Property"); + } + reader.readEndElement("Properties"); + */ } void PropertyContainer::onPropertyStatusChanged(const Property &prop, unsigned long oldStatus) diff --git a/src/App/PropertyContainer.h b/src/App/PropertyContainer.h index d49b8a8e76..4a165d51ee 100644 --- a/src/App/PropertyContainer.h +++ b/src/App/PropertyContainer.h @@ -30,16 +30,6 @@ #include "DynamicProperty.h" -#include - -XERCES_CPP_NAMESPACE_BEGIN - class DOMNode; - class DOMElement; -// class DefaultHandler; -// class SAX2XMLReader; -XERCES_CPP_NAMESPACE_END - - namespace Base { class Writer; } @@ -230,7 +220,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) override; + void Restore(Base::DocumentReader &reader) override; virtual void editProperty(const char * /*propName*/) {} @@ -258,14 +248,11 @@ protected: virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName); virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop); - virtual void handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName); - virtual void handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop); private: // forbidden PropertyContainer(const PropertyContainer&); PropertyContainer& operator = (const PropertyContainer&); - void readProperty(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM); protected: DynamicProperty dynamicProps; diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 030d2b3463..96b69440b0 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -23,10 +23,6 @@ #include "PreCompiled.h" -#ifndef _PreComp_ -# include -#endif - #include #include @@ -34,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -122,20 +117,6 @@ void PropertyInteger::Restore(Base::XMLReader &reader) setValue(reader.getAttributeAsInteger("value")); } -void PropertyInteger::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - // read my Element - auto IntegerDOM = reader.FindElement(ContainerDOM,"Integer"); - if(IntegerDOM){ - // get the value of my Attribute - const char* value_cstr = reader.GetAttribute(IntegerDOM,"value"); - if(value_cstr){ - long value = reader.ContentToInt( value_cstr ); - setValue(value); - } - } -} - Property *PropertyInteger::Copy() const { PropertyInteger *p= new PropertyInteger(); @@ -261,18 +242,6 @@ void PropertyPath::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } -void PropertyPath::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto PathDOM = reader.FindElement(ContainerDOM,"Path"); - if(PathDOM){ - // get the value of my Attribute - const char* value_cstr = reader.GetAttribute(PathDOM,"value"); - if(value_cstr){ - setValue(value_cstr); - } - } -} - Property *PropertyPath::Copy() const { PropertyPath *p= new PropertyPath(); @@ -463,54 +432,6 @@ void PropertyEnumeration::Restore(Base::XMLReader &reader) hasSetValue(); } -void PropertyEnumeration::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto IntegerDOM = reader.FindElement(ContainerDOM,"Integer"); - if(IntegerDOM){ - // get the value of my Attribute - const char* value_cstr = reader.GetAttribute(IntegerDOM,"value"); - if(value_cstr){ - long val = reader.ContentToInt( value_cstr ); - aboutToSetValue(); - - const char* CustomEnum_cstr = reader.GetAttribute(IntegerDOM,"CustomEnum"); - if(CustomEnum_cstr){ - auto CustomEnumListDOM = reader.FindElement(IntegerDOM,"CustomEnumList"); - if(CustomEnumListDOM){ - const char* count_cstr = reader.GetAttribute(IntegerDOM,"count"); - if(count_cstr){ - long count = reader.ContentToInt( count_cstr ); - std::vector values(count); - - if(count >= 1){ - auto prev_EnumDOM = reader.FindElement(CustomEnumListDOM,"Enum"); - const char* enum_value_cstr = reader.GetAttribute(prev_EnumDOM,"value"); - values[0] = enum_value_cstr; - for(int i = 1; i < count; i++) { - auto EnumDOM_i = reader.FindNextElement(prev_EnumDOM,"Enum"); - const char* _enum_value_cstr = reader.GetAttribute(EnumDOM_i,"value"); - values[i] = _enum_value_cstr; - - prev_EnumDOM = EnumDOM_i; - } - } - _enum.setEnums(values); - } - } - } - if (val < 0) { - // If the enum is empty at this stage do not print a warning - if (_enum.hasEnums()) - Base::Console().Warning("Enumeration index %d is out of range, ignore it\n", val); - val = getValue(); - } - - _enum.setValue(val); - hasSetValue(); - } - } -} - PyObject * PropertyEnumeration::getPyObject() { if (!_enum.isValid()) { @@ -861,35 +782,6 @@ void PropertyIntegerList::Restore(Base::XMLReader &reader) setValues(values); } -void PropertyIntegerList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto IntegerListDOM = reader.FindElement(ContainerDOM,"IntegerList"); - if(IntegerListDOM){ - // get the value of my Attribute - const char* count_cstr = reader.GetAttribute(IntegerListDOM,"count"); - long count = reader.ContentToInt( count_cstr ); - std::vector values(count); - if(count >= 1){ - auto prev_I_DOM = reader.FindElement(IntegerListDOM,"I"); - const char* v_cstr = reader.GetAttribute(prev_I_DOM,"v"); - long v = reader.ContentToInt( v_cstr ); - values[0] = v; - - for(int i = 1; i < count; i++) { - auto I_DOM_i = reader.FindNextElement(prev_I_DOM,"I"); - const char* _v_cstr = reader.GetAttribute(I_DOM_i,"v"); - long v = reader.ContentToInt( _v_cstr ); - values[i] = v; - - prev_I_DOM = I_DOM_i; - } - } - //assignment - setValues(values); - } -} - - Property *PropertyIntegerList::Copy() const { PropertyIntegerList *p= new PropertyIntegerList(); @@ -1010,35 +902,6 @@ void PropertyIntegerSet::Restore(Base::XMLReader &reader) setValues(values); } -void PropertyIntegerSet::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto IntegerSetDOM = reader.FindElement(ContainerDOM,"IntegerSet"); - if(IntegerSetDOM){ - // get the value of my Attribute - const char* count_cstr = reader.GetAttribute(IntegerSetDOM,"count"); - long count = reader.ContentToInt( count_cstr ); - std::set values; - - if(count >= 1){ - auto prev_I_DOM = reader.FindElement(IntegerSetDOM,"I"); - const char* v_cstr = reader.GetAttribute(prev_I_DOM,"v"); - long v = reader.ContentToInt( v_cstr ); - values.insert( v ); - - for(int i = 1; i < count; i++) { - auto I_DOM_i = reader.FindNextElement(prev_I_DOM,"I"); - const char* _v_cstr = reader.GetAttribute(I_DOM_i,"v"); - long v = reader.ContentToInt( _v_cstr ); - values.insert( v ); - - prev_I_DOM = I_DOM_i; - } - } - //assignment - setValues(values); - } -} - Property *PropertyIntegerSet::Copy() const { PropertyIntegerSet *p= new PropertyIntegerSet(); @@ -1130,21 +993,6 @@ void PropertyFloat::Restore(Base::XMLReader &reader) setValue(reader.getAttributeAsFloat("value")); } -void PropertyFloat::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto FloatDOM = reader.FindElement(ContainerDOM,"Float"); - if(FloatDOM){ - // get the value of my Attribute - const char* value_cstr = reader.GetAttribute(FloatDOM,"value"); - if(value_cstr){ - double value = reader.ContentToFloat( value_cstr ); - setValue(value); - } - } -} - - - Property *PropertyFloat::Copy() const { PropertyFloat *p= new PropertyFloat(); @@ -1394,24 +1242,6 @@ void PropertyFloatList::Restore(Base::XMLReader &reader) } } -void PropertyFloatList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - //TODO for this its needed to implement addFile() into Reader.cpp, and ReadFiles() since its not possible to have an XMLReader object at this point, because it gives error to use both methods(XMLReader progressive reading and DocumentReader reading) probably because there is something wrong with the zipios implementation, it looks like its locking file or in some way makes the file structure invalid to be readed by xerces by both methods. - //worked around reimplementing ReadFiles in DocumentReader.cpp: - auto FloatListDOM = reader.FindElement(ContainerDOM,"FloatList"); - if(FloatListDOM){ - // get the value of my Attribute - const char* file_cstr = reader.GetAttribute(FloatListDOM,"file"); - if(file_cstr){ - string file ( file_cstr ); - if (!file.empty()) { - // initiate a file read - reader.addFile(file.c_str(),this); - } - } - } -} - void PropertyFloatList::SaveDocFile (Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -1672,31 +1502,6 @@ void PropertyString::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } -void PropertyString::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto StringDOM = reader.FindElement(ContainerDOM,"String"); - const char* value_cstr = reader.GetAttribute(StringDOM,"value"); - - auto obj = dynamic_cast(getContainer()); - if(obj && &obj->Label==this) { - const char* restore_cstr = reader.GetAttribute(StringDOM,"restore"); - - if(restore_cstr) { - int restore = reader.ContentToInt( restore_cstr ); - if(restore == 1) { - aboutToSetValue(); - _cValue = value_cstr; - hasSetValue(); - return; - } - return; - } - } - setValue(value_cstr); - - -} - Property *PropertyString::Copy() const { PropertyString *p= new PropertyString(); @@ -1829,18 +1634,6 @@ void PropertyUUID::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } -void PropertyUUID::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto UuidDOM = reader.FindElement(ContainerDOM,"Uuid"); - if(UuidDOM){ - // get the value of my Attribute - const char* value_cstr = reader.GetAttribute(UuidDOM,"value"); - if(value_cstr){ - setValue(value_cstr); - } - } -} - Property *PropertyUUID::Copy() const { PropertyUUID *p= new PropertyUUID(); @@ -1962,32 +1755,6 @@ void PropertyStringList::Restore(Base::XMLReader &reader) setValues(values); } -void PropertyStringList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto StringListDOM = reader.FindElement(ContainerDOM,"StringList"); - if(StringListDOM){ - // get the value of my Attribute - const char* count_cstr = reader.GetAttribute(StringListDOM,"count"); - long count = reader.ContentToInt( count_cstr ); - std::vector values(count); - if(count >= 1){ - auto prev_StringDOM = reader.FindElement(StringListDOM,"String"); - const char* value_cstr = reader.GetAttribute(prev_StringDOM,"value"); - values[0] = value_cstr; - for(int i = 1; i < count; i++) { - auto StringDOM_i = reader.FindNextElement(prev_StringDOM,"String"); - const char* _value_cstr = reader.GetAttribute(StringDOM_i,"value"); - values[i] = _value_cstr; - - prev_StringDOM = StringDOM_i; - } - - } - // assignment - setValues(values); - } -} - Property *PropertyStringList::Copy() const { PropertyStringList *p= new PropertyStringList(); @@ -2152,32 +1919,6 @@ void PropertyMap::Restore(Base::XMLReader &reader) setValues(values); } -void PropertyMap::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto MapDOM = reader.FindElement(ContainerDOM,"Map"); - if(MapDOM){ - // get the value of my Attribute - const char* count_cstr = reader.GetAttribute(MapDOM,"count"); - int count = reader.ContentToInt( count_cstr ); - std::map values; - auto prev_ItemDOM = reader.FindElement(MapDOM,"Item"); - const char* key_cstr = reader.GetAttribute(prev_ItemDOM,"key"); - const char* value_cstr = reader.GetAttribute(prev_ItemDOM,"value"); - values[key_cstr] = value_cstr; - - for(int i = 1; i < count; i++) { - auto ItemDOM_i = reader.FindNextElement(prev_ItemDOM,"Item"); - const char* key_cstr = reader.GetAttribute(ItemDOM_i,"key"); - const char* value_cstr = reader.GetAttribute(ItemDOM_i,"value"); - values[key_cstr] = value_cstr; - - prev_ItemDOM = ItemDOM_i; - } - // assignment - setValues(values); - } -} - Property *PropertyMap::Copy() const { PropertyMap *p= new PropertyMap(); @@ -2263,15 +2004,6 @@ void PropertyBool::Restore(Base::XMLReader &reader) (b == "true") ? setValue(true) : setValue(false); } -void PropertyBool::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto BoolDOM = reader.FindElement(ContainerDOM,"Bool"); - if(BoolDOM){ - // get the value of my Attribute - string b = reader.GetAttribute(BoolDOM,"value"); - (b == "true") ? setValue(true) : setValue(false); - } -} Property *PropertyBool::Copy() const { @@ -2390,18 +2122,6 @@ void PropertyBoolList::Restore(Base::XMLReader &reader) setValues(bitset); } -void PropertyBoolList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - // read my Element - auto BoolListDOM = reader.FindElement(ContainerDOM,"BoolList"); - if(BoolListDOM){ - // get the value of my Attribute - string str = reader.GetAttribute(BoolListDOM,"value"); - boost::dynamic_bitset<> bitset(str); - setValues(bitset); - } -} - Property *PropertyBoolList::Copy() const { PropertyBoolList *p= new PropertyBoolList(); @@ -2555,17 +2275,6 @@ void PropertyColor::Restore(Base::XMLReader &reader) setValue(rgba); } -void PropertyColor::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - // read my Element - auto PropertyColorDOM = reader.FindElement(ContainerDOM,"PropertyColor"); - if(PropertyColorDOM){ - const char* val_cstr = reader.GetAttribute(PropertyColorDOM,"value"); - unsigned long rgba = reader.ContentToUnsigned(val_cstr); - setValue(rgba); - } -} - Property *PropertyColor::Copy() const { PropertyColor *p= new PropertyColor(); @@ -2645,22 +2354,6 @@ void PropertyColorList::Restore(Base::XMLReader &reader) } } -void PropertyColorList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto ColorListDOM = reader.FindElement(ContainerDOM,"ColorList"); - if(ColorListDOM){ - // get the value of my Attribute - const char* file_cstr = reader.GetAttribute(ColorListDOM,"file"); - if(file_cstr){ - std::string file (file_cstr); - if (!file.empty()) { - // initiate a file read - reader.addFile(file.c_str(),this); - } - } - } -} - void PropertyColorList::SaveDocFile (Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -2811,32 +2504,6 @@ void PropertyMaterial::Restore(Base::XMLReader &reader) hasSetValue(); } -void PropertyMaterial::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - // read my Element - auto PropertyMaterialDOM = reader.FindElement(ContainerDOM,"PropertyMaterial"); - if(PropertyMaterialDOM){ - // get the value of my Attribute - aboutToSetValue(); - - const char* ambientColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"ambientColor"); - const char* diffuseColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"diffuseColor"); - const char* specularColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"specularColor"); - const char* emissiveColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"emissiveColor"); - const char* shininess_cstr = reader.GetAttribute(PropertyMaterialDOM,"shininess"); - const char* transparency_cstr = reader.GetAttribute(PropertyMaterialDOM,"transparency"); - - _cMat.ambientColor.setPackedValue(reader.ContentToUnsigned(ambientColor_cstr)); - _cMat.diffuseColor.setPackedValue(reader.ContentToUnsigned(diffuseColor_cstr)); - _cMat.specularColor.setPackedValue(reader.ContentToUnsigned(specularColor_cstr)); - _cMat.emissiveColor.setPackedValue(reader.ContentToUnsigned(emissiveColor_cstr)); - _cMat.shininess = (float)reader.ContentToFloat(shininess_cstr); - _cMat.transparency = (float)reader.ContentToFloat(transparency_cstr); - hasSetValue(); - } -} - - const char* PropertyMaterial::getEditorName() const { if(testStatus(MaterialEdit)) @@ -2916,22 +2583,6 @@ void PropertyMaterialList::Restore(Base::XMLReader &reader) } } -void PropertyMaterialList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - auto MaterialListDOM = reader.FindElement(ContainerDOM,"MaterialList"); - if(MaterialListDOM){ - // get the value of my Attribute - const char* file_cstr = reader.GetAttribute(MaterialListDOM,"file"); - if(file_cstr){ - std::string file (file_cstr); - if (!file.empty()) { - // initiate a file read - reader.addFile(file.c_str(),this); - } - } - } -} - void PropertyMaterialList::SaveDocFile(Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -3028,14 +2679,6 @@ void PropertyPersistentObject::Restore(Base::XMLReader &reader){ reader.readEndElement(ELEMENT_PERSISTENT_OBJ); } -void PropertyPersistentObject::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) -{ - inherited::Restore(reader,ContainerDOM); - auto element_persistent_obj_DOM = reader.FindElement(ELEMENT_PERSISTENT_OBJ); - if(_pObject) - _pObject->Restore(reader,element_persistent_obj_DOM); -} - Property *PropertyPersistentObject::Copy() const{ auto *p= new PropertyPersistentObject(); p->_cValue = _cValue; diff --git a/src/App/PropertyStandard.h b/src/App/PropertyStandard.h index e1d1cd0d43..cd5d8755f3 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -36,12 +36,6 @@ #include "Enumeration.h" #include "Material.h" -#include - -XERCES_CPP_NAMESPACE_BEGIN - class DOMElement; -XERCES_CPP_NAMESPACE_END - namespace Base { class Writer; @@ -76,7 +70,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -128,7 +121,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -228,7 +220,6 @@ public: void Save(Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property * Copy() const override; void Paste(const Property &from) override; @@ -367,7 +358,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -413,7 +403,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -473,7 +462,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -527,7 +515,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -671,7 +658,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile (Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -719,7 +705,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -773,7 +758,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -840,7 +824,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -882,7 +865,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -920,7 +902,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -968,7 +949,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -1008,7 +988,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile (Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -1061,7 +1040,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; const char* getEditorName() const override; @@ -1105,7 +1083,6 @@ public: void Save(Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile(Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -1135,7 +1112,6 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; diff --git a/src/Base/DocumentReader.cpp b/src/Base/DocumentReader.cpp index 5102632604..01b97285f0 100644 --- a/src/Base/DocumentReader.cpp +++ b/src/Base/DocumentReader.cpp @@ -19,24 +19,41 @@ * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ +//#include "PreCompiled.h" + +//#include + #include "DocumentReader.h" + +//#include "Reader.h" +//#include "Base64.h" +//#include "Console.h" #include "InputSource.h" +//#include "Persistence.h" +//#include "Sequencer.h" +//#include "Stream.h" #include "XMLTools.h" +//#ifdef _MSC_VER +//#include +//#endif +//#include #include #include -#include "Persistence.h" -#include "Sequencer.h" - - -#ifdef _MSC_VER -#include -#endif -#include - #ifndef _PreComp_ +//# include +//# include # include +//# include +//# include +//# include +//# include # include +//# include +//# include +//# include +//# include +//# include #endif XERCES_CPP_NAMESPACE_USE @@ -55,8 +72,25 @@ DocumentReader::DocumentReader() gDoSchema = false; gSchemaFullChecking = false; gDoCreate = true; + + /* + gOutputEncoding = nullptr; + gMyEOLSequence = nullptr; + + gSplitCdataSections = true; + gDiscardDefaultContent = true; + gUseFilter = true; + gFormatPrettyPrint = true; + */ + } +//DocumentReader::~DocumentReader() +//{ + //delete parser; +//} +//int DocumentReader::LoadDocument(const XERCES_CPP_NAMESPACE_QUALIFIER InputSource& inputSource) +//int DocumentReader::LoadDocument(std::istream& Stream,std::string filename) int DocumentReader::LoadDocument(Base::Reader& reader) { FileInfo _File( reader.getFileName() ); @@ -105,7 +139,7 @@ int DocumentReader::LoadDocument(Base::Reader& reader) return 0; } - XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* _pDocument = parser->adoptDocument(); + XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* _pDocument = parser->adoptDocument(); delete parser; delete errReporter; @@ -140,7 +174,9 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(const cha for (DOMNode *clChild = _pGroupNode->getFirstChild(); clChild != nullptr; clChild = clChild->getNextSibling()) { if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { - return static_cast(clChild); + if (clChild->getAttributes()->getLength() > 0) { + return static_cast(clChild); + } } } } @@ -155,6 +191,9 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(XERCES_CP if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { return static_cast(clChild); + //if (clChild->getAttributes()->getLength() > 0) { + //return static_cast(clChild); + //} } } } @@ -177,22 +216,41 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindNextElement(XERCE return nullptr; } -long DocumentReader::ContentToInt( const char* content ) +/* +//CONTENT: +const char * DocumentReader::GetContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl) const +{ + if (!DOMEl) + return nullptr; + return StrX(DOMEl->getAttribute(XStr("Value").unicodeForm())).c_str(); +} + +std::string DocumentReader::GetContentASCII(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl) const +{ + //return std::string(StrXUTF8(pcElem->getNodeValue()).c_str() ); + //maybe its better to use getNodeValue() + if (!DOMEl) + return nullptr; + return std::string( StrXUTF8(DOMEl->getAttribute(XStr("Value").unicodeForm())).c_str() ); +} +*/ + +long DocumentReader::ContentToInt( const char* content ) const { return atol( content ); } -unsigned long DocumentReader::ContentToUnsigned(const char* content) +unsigned long DocumentReader::ContentToUnsigned(const char* content) const { return strtoul(content,nullptr,10); } -double DocumentReader::ContentToFloat(const char* content) +double DocumentReader::ContentToFloat(const char* content) const { return atof(content); } -bool DocumentReader::ContentToBool(const char* content) +bool DocumentReader::ContentToBool(const char* content) const { if (strcmp(content,"1")) return false; @@ -224,16 +282,18 @@ const char * DocumentReader::GetAttribute(const char* Attr) const return nullptr; } const XMLCh * attr = _pGroupNode->getAttribute( xstr.unicodeForm() ); + //stringLen return strdup( StrX( attr ).c_str() );//strdup is needed since pointer from strx only exists in context where StrX() is created. } -//Status -void Base::DocumentReader::setPartialRestore(bool on) + +/* +unsigned int Base::XMLReader::getAttributeCount() const { - setStatus(PartialRestore, on); - setStatus(PartialRestoreInDocumentObject, on); - setStatus(PartialRestoreInProperty, on); - setStatus(PartialRestoreInObject, on); + return static_cast(AttrMap.size()); } +*/ + +//Status void Base::DocumentReader::clearPartialRestoreProperty() { @@ -251,77 +311,4 @@ void Base::DocumentReader::setStatus(ReaderStatus pos, bool on) StatusBits.set(static_cast(pos), on); } -const char *Base::DocumentReader::addFile(const char* Name, Base::Persistence *Object) -{ - FileEntry temp; - temp.FileName = Name; - temp.Object = Object; - FileList.push_back(temp); - FileNames.push_back( temp.FileName ); - - return Name; -} - -void Base::DocumentReader::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. - // 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 - // file, then. - // In either case it's guaranteed that the order of the files is kept. - zipios::ConstEntryPointer entry; - try { - entry = zipstream.getNextEntry(); - } - catch (const std::exception&) { - // There is no further file at all. This can happen if the - // project file was created without GUI - return; - } - 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; - // 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) - ++jt; - // If this condition is true both file names match and we can read-in the data, otherwise - // no file name for the current entry in the zip was registered. - if (jt != FileList.end()) { - try { - Base::Reader reader(zipstream, jt->FileName, FileVersion); - jt->Object->RestoreDocFile(reader); - if (reader.getLocalReader()) - reader.getLocalReader()->readFiles(zipstream); - if (reader.getLocalDocReader()) - reader.getLocalDocReader()->readFiles(zipstream); - - }catch(...) { - // For any exception we just continue with the next file. - // It doesn't matter if the last reader has read more or - // less data than the file size would allow. - // All what we need to do is to notify the user about the - // failure. - Base::Console().Error("Reading failed from embedded file(DocumentReader): %s\n", entry->toString().c_str()); - } - // Go to the next registered file name - it = jt + 1; - } - - seq.next(); - - // In either case we must go to the next entry - try { - entry = zipstream.getNextEntry(); - } - catch (const std::exception&) { - // there is no further entry - break; - } - } -} diff --git a/src/Base/DocumentReader.h b/src/Base/DocumentReader.h index 863fa521de..e414046f37 100644 --- a/src/Base/DocumentReader.h +++ b/src/Base/DocumentReader.h @@ -25,16 +25,18 @@ #include #include -#include +//#include +//#include #include #include -#include -//#include "FileInfo.h"//remplaced: -#include -namespace zipios { -class ZipInputStream; -} +//#include +//#include +//#include +#include +//#include "FileInfo.h"//reemplazado por: +#include +//#include XERCES_CPP_NAMESPACE_BEGIN class DOMNode; @@ -47,7 +49,7 @@ namespace Base class Reader; class Persistence; -class BaseExport DocumentReader +class BaseExport DocumentReader //: public ParameterManager { public: enum ReaderStatus { @@ -64,12 +66,12 @@ public: XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElement(const char* Type) const; XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const; - static long ContentToASCII(const char* Content); + long ContentToASCII(const char* Content) const; - static long ContentToInt(const char* Content); - static unsigned long ContentToUnsigned(const char* Content); - static double ContentToFloat(const char* Content); - static bool ContentToBool(const char* Content); + long ContentToInt(const char* Content) const; + unsigned long ContentToUnsigned(const char* Content) const; + double ContentToFloat(const char* Content) const; + bool ContentToBool(const char* Content) const; const char* GetAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* DOMEl, const char* Attr) const; const char* GetAttribute(const char* Attr) const; @@ -78,38 +80,15 @@ public: bool testStatus(ReaderStatus pos) const; /// set the status bits void setStatus(ReaderStatus pos, bool on); - /// sets simultaneously the global and local PartialRestore bits - void setPartialRestore(bool on); void clearPartialRestoreProperty(); - /// add a read request of a persistent object - const char *addFile(const char* Name, Base::Persistence *Object); - - void readFiles(zipios::ZipInputStream &zipstream) const; - - std::shared_ptr getLocalReader() const; - - struct FileEntry { - std::string FileName; - Base::Persistence *Object; - }; - std::vector FileList; - - /// Version of the file format - int FileVersion; - - - protected: XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *_pGroupNode; bool gDoNamespaces ; bool gDoSchema ; bool gSchemaFullChecking ; bool gDoCreate ; - - std::vector FileNames; - std::bitset<32> StatusBits; }; diff --git a/src/Base/Persistence.cpp b/src/Base/Persistence.cpp index 0d69101985..742a06cf35 100644 --- a/src/Base/Persistence.cpp +++ b/src/Base/Persistence.cpp @@ -34,10 +34,6 @@ /// Here the FreeCAD includes sorted by Base,App,Gui...... #include "Persistence.h" -#ifndef _PreComp_ -# include -#endif - using namespace Base; @@ -65,14 +61,6 @@ void Persistence::Save (Writer &/*writer*/) const assert(0); } -void Persistence::Restore(DocumentReader &/*reader*/) -{ -} - -void Persistence::Restore(DocumentReader &/*reader*/,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement */*containerEl*/) -{ -} - void Persistence::Restore(DocumentReader &/*reader*/) { // you have to implement this method in all descending classes! diff --git a/src/Base/Persistence.h b/src/Base/Persistence.h index cf4634c66d..7941f7c748 100644 --- a/src/Base/Persistence.h +++ b/src/Base/Persistence.h @@ -26,15 +26,6 @@ #include "BaseClass.h" -#include - -XERCES_CPP_NAMESPACE_BEGIN - class DOMNode; - class DOMElement; -// class DefaultHandler; -// class SAX2XMLReader; -XERCES_CPP_NAMESPACE_END - namespace Base { class Reader; @@ -88,8 +79,6 @@ public: */ virtual void Restore(XMLReader &/*reader*/) = 0; virtual void Restore(DocumentReader &/*reader*/); - virtual void Restore(DocumentReader &/*reader*/,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement */*containerEl*/); - /** This method is used to save large amounts of data to a binary file. * Sometimes it makes no sense to write property data as XML. In case the * amount of data is too big or the data type has a more effective way to @@ -154,8 +143,6 @@ public: * @see Base::Reader,Base::XMLReader */ virtual void RestoreDocFile(Reader &/*reader*/); - - /// Encodes an attribute upon saving. static std::string encodeAttribute(const std::string&); diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index 8ff610621d..92e207953b 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -31,7 +31,6 @@ #include #include "Reader.h" -#include "DocumentReader.h" #include "Base64.h" #include "Console.h" #include "InputSource.h" @@ -334,11 +333,9 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const try { Base::Reader reader(zipstream, jt->FileName, FileVersion); jt->Object->RestoreDocFile(reader); - if (reader.getLocalReader()) - reader.getLocalReader()->readFiles(zipstream); - if (reader.getLocalDocReader()) - reader.getLocalDocReader()->readFiles(zipstream); - + + if (reader.getLocalReader()) + reader.getLocalReader()->readFiles(zipstream); }catch(...) { // For any exception we just continue with the next file. // It doesn't matter if the last reader has read more or @@ -580,13 +577,3 @@ std::shared_ptr Base::Reader::getLocalReader() const { return(this->localreader); } - -void Base::Reader::initLocalDocReader(std::shared_ptr reader) -{ - this->localdocreader = reader; -} - -std::shared_ptr Base::Reader::getLocalDocReader() const -{ - return(this->localdocreader); -} diff --git a/src/Base/Reader.h b/src/Base/Reader.h index 6673a3a43b..d06617a95f 100644 --- a/src/Base/Reader.h +++ b/src/Base/Reader.h @@ -48,7 +48,6 @@ XERCES_CPP_NAMESPACE_END namespace Base { class Persistence; -class DocumentReader; /** The XML reader class * This is an important helper class for the store and retrieval system @@ -296,16 +295,13 @@ public: std::string getFileName() const; int getFileVersion() const; void initLocalReader(std::shared_ptr); - void initLocalDocReader(std::shared_ptr); std::shared_ptr getLocalReader() const; - std::shared_ptr getLocalDocReader() const; private: std::istream& _str; std::string _name; int fileVersion; std::shared_ptr localreader; - std::shared_ptr localdocreader; }; } diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index ef64d500cc..f4c31f7b8a 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1400,7 +1400,6 @@ void Document::Save (Base::Writer &writer) const void Document::Restore(Base::XMLReader &reader) { reader.addFile("GuiDocument.xml",this); - // hide all elements to avoid to update the 3d view when loading data files // RestoreDocFile then restores the visibility status again std::map::iterator it; @@ -1415,195 +1414,134 @@ void Document::Restore(Base::XMLReader &reader) */ void Document::RestoreDocFile(Base::Reader &reader) { + Base::DocumentReader docReader; + docReader.LoadDocument(reader); + //docReader.GetRootElement()//can be used to get Document XMLElement, but not needed. + const char* SchemaVersion_cstr = docReader.GetAttribute("SchemaVersion"); + long SchemaVersion = docReader.ContentToInt( SchemaVersion_cstr ); - readUsing_DocumentReader(reader); - //readUsing_XMLReader(reader); - setModified(false); -} - -void Document::readUsing_XMLReader(Base::Reader &reader){ - // We must create an XML parser to read from the input stream - std::shared_ptr localreader = std::make_shared("GuiDocument.xml", reader); - //localreader->FileVersion = reader.getFileVersion(); - - localreader->readElement("Document"); - long scheme = localreader->getAttributeAsInteger("SchemaVersion"); - //localreader->DocumentSchema = scheme; - - bool hasExpansion = localreader->hasAttribute("HasExpansion"); - if(hasExpansion) { - auto tree = TreeWidget::instance(); + const char* HasExpansion_cstr = docReader.GetAttribute("HasExpansion"); + if(HasExpansion_cstr){ + auto tree = TreeWidget::instance(); if(tree) { auto docItem = tree->getDocumentItem(this); if(docItem) - docItem->Restore(*localreader); + docItem->Restore(docReader); } } - + // At this stage all the document objects and their associated view providers exist. // Now we must restore the properties of the view providers only. - // - // SchemeVersion "1" - if (scheme == 1) { - - // read the viewproviders itself - - localreader->readElement("ViewProviderData"); - int Cnt = localreader->getAttributeAsInteger("Count"); - - for (int i=0; ireadElement("ViewProvider"); - std::string name = localreader->getAttribute("name"); - bool expanded = false; - if (!hasExpansion && localreader->hasAttribute("expanded")) { - - const char* attr = localreader->getAttribute("expanded"); - if (strcmp(attr,"1") == 0) { - expanded = true; - } - } - ViewProvider* pObj = getViewProviderByName(name.c_str()); - if (pObj){// check if this feature has been registered - pObj->Restore(*localreader); - } - - if (pObj && expanded) { - auto vp = static_cast(pObj); - this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); - } - localreader->readEndElement("ViewProvider"); - } - - localreader->readEndElement("ViewProviderData"); - - - // read camera settings - localreader->readElement("Camera"); - const char* ppReturn = localreader->getAttribute("settings"); - cameraSettings.clear(); - if(ppReturn && ppReturn[0]) { - saveCameraSettings(ppReturn); - try { - const char** pReturnIgnore=nullptr; - std::list mdi = getMDIViews(); - for (const auto & it : mdi) { - if (it->onHasMsg("SetCamera")) - it->onMsg(cameraSettings.c_str(), pReturnIgnore); - } - } - - catch (const Base::Exception& e) { - Base::Console().Error("%s\n", e.what()); - } - } - } - localreader->readEndElement("Document"); - reader.initLocalReader(localreader); -} - -void Document::readUsing_DocumentReader(Base::Reader &reader){ - std::shared_ptr docReader = std::make_shared(); - docReader->LoadDocument(reader); - //docReader->GetRootElement()//can be used to get Document XMLElement, but not needed. - const char* SchemaVersion_cstr = docReader->GetAttribute("SchemaVersion"); - long SchemaVersion = docReader->ContentToInt( SchemaVersion_cstr ); - const char* HasExpansion_cstr = docReader->GetAttribute("HasExpansion"); - if(HasExpansion_cstr){ - auto tree = TreeWidget::instance(); - if(tree) { - auto docItem = tree->getDocumentItem(this); - if(docItem) - docItem->Restore(*docReader); - } - } - - // At this stage all the document objects and their associated view providers exist. - // Now we must restore the properties of the view providers only. - if (SchemaVersion == 1) { - auto VProviderDataDOM = docReader->FindElement("ViewProviderData"); + if (SchemaVersion == 1) { + auto VProviderDataDOM = docReader.FindElement("ViewProviderData"); if(VProviderDataDOM){ - const char* vpd_count_cstr = docReader->GetAttribute(VProviderDataDOM,"Count"); + const char* vpd_count_cstr = docReader.GetAttribute(VProviderDataDOM,"Count"); if(vpd_count_cstr){ - long Cnt = docReader->ContentToInt( vpd_count_cstr ); - auto prev_ViewProviderDOM = docReader->FindElement(VProviderDataDOM,"ViewProvider"); + long Cnt = docReader.ContentToInt( vpd_count_cstr ); + auto prev_ViewProviderDOM = docReader.FindElement(VProviderDataDOM,"ViewProvider"); if(prev_ViewProviderDOM){ - const char* name_cstr = docReader->GetAttribute(prev_ViewProviderDOM,"name"); - const char* expanded_cstr = docReader->GetAttribute(prev_ViewProviderDOM,"expanded"); + const char* name_cstr = docReader.GetAttribute(prev_ViewProviderDOM,"name"); + const char* expanded_cstr = docReader.GetAttribute(prev_ViewProviderDOM,"expanded"); bool expanded = false; if (!HasExpansion_cstr && expanded_cstr) { if (strcmp(expanded_cstr,"1") == 0) { expanded = true; } } + ViewProvider* pObj = getViewProviderByName(name_cstr); - if (pObj){ - pObj->Restore(*docReader,prev_ViewProviderDOM); - } + if (pObj) + pObj->Restore(docReader,prev_ViewProviderDOM); + if (pObj && expanded) { auto vp = static_cast(pObj); this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); } - for (int i=1; iFindNextElement(prev_ViewProviderDOM,"ViewProvider"); - if(ViewProviderDOM_i){ - const char* name_cstr_i = docReader->GetAttribute(ViewProviderDOM_i,"name"); - const char* expanded_cstr_i = docReader->GetAttribute(ViewProviderDOM_i,"expanded"); - bool expanded = false; - if (!HasExpansion_cstr && expanded_cstr_i) { - if (strcmp(expanded_cstr_i,"1") == 0) { - expanded = true; - } - } - ViewProvider* pObj = getViewProviderByName(name_cstr_i); - if (pObj){ - pObj->Restore(*docReader,ViewProviderDOM_i); - } - - if (pObj && expanded) { - auto vp = static_cast(pObj); - this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); - } - prev_ViewProviderDOM = ViewProviderDOM_i; - } - } - } - - + for (int i=1; iRestore(docReader,ViewProviderDOM_i);//Im still implementing this, which calls ExtensionContainer::Restore. + + if (pObj && expanded) { + auto vp = static_cast(pObj); + this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); + } + prev_ViewProviderDOM = ViewProviderDOM_i; + } + } } } // read camera settings - auto CameraDOM = docReader->FindElement("Camera"); + auto CameraDOM = docReader.FindElement("Camera"); if(CameraDOM){ - const char* ppReturn = docReader->GetAttribute(CameraDOM,"settings"); + const char* ppReturn = docReader.GetAttribute(CameraDOM,"settings"); cameraSettings.clear(); if(ppReturn && ppReturn[0]) { - saveCameraSettings(ppReturn); - try { - const char** pReturnIgnore=nullptr; - std::list mdi = getMDIViews(); - for (const auto & it : mdi) { - if (it->onHasMsg("SetCamera")) - it->onMsg(cameraSettings.c_str(), pReturnIgnore); - } - } - catch (const Base::Exception& e) { - Base::Console().Error("%s\n", e.what()); - } - } + saveCameraSettings(ppReturn); + try { + const char** pReturnIgnore=nullptr; + std::list mdi = getMDIViews(); + for (const auto & it : mdi) { + if (it->onHasMsg("SetCamera")) + it->onMsg(cameraSettings.c_str(), pReturnIgnore); + } + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + } } - - auto ProjectUnitSysDOM = docReader->FindElement("ProjectUnitSystem"); - if(ProjectUnitSysDOM){ - const char* US_cstr = docReader->GetAttribute(ProjectUnitSysDOM,"US"); - const char* ignore_cstr = docReader->GetAttribute(ProjectUnitSysDOM,"ignore"); + + /* + try{//if this fails then all other reading attemps will fail, since XERCES doesnt allow to get back to previous point, reading the file should restarted each time an element its not present, since it looks for it untill the end of the document. + //Since ProjectUnitSystem its the only optional field, and its being read at the end of this function, it does not cause any issue, but if other optional its added the way of reading XML used in Reader.cpp will be obsolete + + localreader->readElement("ProjectUnitSystem"); + Base::Console().Error("readElement(ProjectUnitSystem)\n"); + int US = localreader->getAttributeAsInteger("US"); + int ignore = localreader->getAttributeAsInteger("ignore"); + d->projectUnitSystem = US; + d->projectUnitSystemIgnore = ignore; - d->projectUnitSystem = docReader->ContentToInt( US_cstr ); - d->projectUnitSystemIgnore = docReader->ContentToInt( ignore_cstr ); + }catch (const Base::XMLParseException& e) { + Base::Console().Warning("ProjectUnitSystem not found: %s\n", e.getMessage().c_str()); + }catch(const Base::XMLBaseException& e){ + Base::Console().Warning("ProjectUnitSystem XMLBaseException: %s\n", e.getMessage().c_str()); + }catch(...) { + Base::Console().Error("ProjectUnitSystem catch(...)\n"); } + */ + } + /* + + try{ + localreader->readEndElement("Document"); + }catch(const Base::XMLParseException& e){ + Base::Console().Warning("readEndElement(Document) XMLParseException: %s\n", e.getMessage().c_str()); + }catch(const Base::XMLBaseException& e){ + Base::Console().Warning("readEndElement(Document) XMLBaseException: %s\n", e.getMessage().c_str()); + }catch(...) { + Base::Console().Error("readEndElement(Document) unkown error.\n"); } - reader.initLocalDocReader(docReader); + */ + + // reset modified flag + //dont see what this does: + //reader.initLocalReader(localreader); + setModified(false); } void Document::slotStartRestoreDocument(const App::Document& doc) diff --git a/src/Gui/Document.h b/src/Gui/Document.h index 5eff465959..f7fdad5ebd 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -158,8 +158,6 @@ public: void SaveDocFile (Base::Writer &writer) const override; /// This method is used to restore large amounts of data from a binary file. void RestoreDocFile(Base::Reader &reader) override; - void readUsing_XMLReader(Base::Reader &reader); - void readUsing_DocumentReader(Base::Reader &reader); void exportObjects(const std::vector&, Base::Writer&); void importObjects(const std::vector&, Base::Reader&, const std::map& nameMapping); diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 0e255c1a19..54b7d5b2f6 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -354,29 +354,17 @@ public: } void restore(Base::DocumentReader& reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *expandEl) { + Base::Console().Error("ExpandInfo restore\n"); const char* count_cstr = reader.GetAttribute(expandEl,"count"); if(count_cstr){ long count = reader.ContentToInt( count_cstr ); - auto prev_ExpandDOM = reader.FindElement(expandEl,"Expand"); - const char* name_cstr = reader.GetAttribute(prev_ExpandDOM,"name"); - const char* _count_cstr = reader.GetAttribute(prev_ExpandDOM,"count"); + Base::Console().Error("ExpandInfo count: %d\n",count); + auto _expandEl = reader.FindElement(expandEl,"Expand"); + const char* name_cstr = reader.GetAttribute(_expandEl,"name"); + Base::Console().Error("ExpandInfo name_cstr: %s\n",name_cstr); auto& entry = (*this)[name_cstr]; - if(_count_cstr){ - entry.reset(new ExpandInfo); - entry->restore(reader,prev_ExpandDOM); - } - - for (int i = 1; i < count; ++i) { - auto ExpandDOM_i = reader.FindNextElement(prev_ExpandDOM,"Expand"); - const char* name_cstr = reader.GetAttribute(ExpandDOM_i,"name"); - const char* _count_cstr = reader.GetAttribute(ExpandDOM_i,"count"); - auto& entry = (*this)[name_cstr]; - if(_count_cstr){ - entry.reset(new ExpandInfo); - entry->restore(reader,ExpandDOM_i); - } - prev_ExpandDOM = ExpandDOM_i; - } + entry.reset(new ExpandInfo); + entry->restore(reader,_expandEl); } } }; @@ -3959,16 +3947,19 @@ void DocumentItem::Restore(Base::XMLReader& reader) { } void DocumentItem::Restore(Base::DocumentReader& reader) { + Base::Console().Error("DocumentItem::Restore() DocumentReader\n"); auto expandEl = reader.FindElement("Expand"); if( !reader.GetAttribute(expandEl,"count") ) return; _ExpandInfo.reset(new ExpandInfo); _ExpandInfo->restore(reader,expandEl); + //TODO NOW for (auto inst : TreeWidget::Instances) { if (inst != getTree()) { auto docItem = inst->getDocumentItem(document()); if (docItem) docItem->_ExpandInfo = _ExpandInfo; + } } } From 9cf1cdadbc07b9499b15a1c005f53ad988d69f49 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Fri, 30 Jun 2023 20:50:36 -0300 Subject: [PATCH 06/25] Implemented DocumentReader for GuiDocument.xml reading. Final --- src/App/Document.cpp | 6 +- src/App/DynamicProperty.cpp | 30 +++ src/App/DynamicProperty.h | 11 + src/App/Extension.cpp | 20 +- src/App/Extension.h | 4 + src/App/ExtensionContainer.cpp | 149 +++++++++----- src/App/ExtensionContainer.h | 8 +- src/App/PropertyContainer.cpp | 219 +++++++++++--------- src/App/PropertyContainer.h | 15 +- src/App/PropertyStandard.cpp | 357 +++++++++++++++++++++++++++++++++ src/App/PropertyStandard.h | 24 +++ src/Base/DocumentReader.cpp | 178 ++++++++-------- src/Base/DocumentReader.h | 49 +++-- src/Base/Persistence.cpp | 10 +- src/Base/Persistence.h | 13 ++ src/Base/Reader.cpp | 19 +- src/Base/Reader.h | 4 + src/Gui/Document.cpp | 248 ++++++++++++++--------- src/Gui/Document.h | 2 + src/Gui/Tree.cpp | 29 ++- 20 files changed, 1036 insertions(+), 359 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index a72cc89188..30a65d4579 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -87,6 +87,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees. #include #include #include +#include #include #include #include @@ -1227,7 +1228,6 @@ Document::readObjects(Base::XMLReader& reader) // read the object types reader.readElement("Objects"); int Cnt = reader.getAttributeAsInteger("Count"); - if(!reader.hasAttribute(FC_ATTR_DEPENDENCIES)) d->partialLoadObjects.clear(); else if(!d->partialLoadObjects.empty()) { @@ -2023,12 +2023,12 @@ void Document::restore (const char *filename, // without GUI. But if available then follow after all data files of the App document. signalRestoreDocument(reader); reader.readFiles(zipstream); - + if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestore)) { setStatus(Document::PartialRestore, true); Base::Console().Error("There were errors while loading the file. Some data might have been modified or not recovered at all. Look above for more specific information about the objects involved.\n"); } - + if(!delaySignal) afterRestore(true); } diff --git a/src/App/DynamicProperty.cpp b/src/App/DynamicProperty.cpp index 7ad6419b33..c105483f42 100644 --- a/src/App/DynamicProperty.cpp +++ b/src/App/DynamicProperty.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "DynamicProperty.h" #include "Application.h" @@ -322,6 +323,35 @@ Property *DynamicProperty::restore(PropertyContainer &pc, return addDynamicProperty(pc,TypeName, PropName, group, doc, attribute, readonly, hidden); } +Property *DynamicProperty::restore(PropertyContainer &pc, + const char *PropName, const char *TypeName, Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM) +{ + const char* group_cstr = reader.GetAttribute(PropertyDOM,"group"); + if(!group_cstr) + return nullptr; + + short attribute = 0; + bool readonly = false, hidden = false; + + const char* doc_cstr = reader.GetAttribute(PropertyDOM,"doc"); + const char* attr_cstr = reader.GetAttribute(PropertyDOM,"attr"); + + if(attr_cstr){ + std::istringstream str(attr_cstr); + str >> attribute; + } + + const char* ro_cstr = reader.GetAttribute(PropertyDOM,"ro"); + if(ro_cstr) + readonly = (ro_cstr[0]-48) != 0; + + const char* hide_cstr = reader.GetAttribute(PropertyDOM,"hide"); + if(hide_cstr) + hidden = (hide_cstr[0]-48) != 0; + + return addDynamicProperty(pc,TypeName, PropName, group_cstr, doc_cstr, attribute, readonly, hidden); +} + DynamicProperty::PropData DynamicProperty::getDynamicPropertyData(const Property *prop) const { auto &index = props.get<1>(); diff --git a/src/App/DynamicProperty.h b/src/App/DynamicProperty.h index a292f74c8e..e02a2e9659 100644 --- a/src/App/DynamicProperty.h +++ b/src/App/DynamicProperty.h @@ -33,6 +33,15 @@ #include #include #include +#include + + +XERCES_CPP_NAMESPACE_BEGIN + class DOMNode; + class DOMElement; +// class DefaultHandler; +// class SAX2XMLReader; +XERCES_CPP_NAMESPACE_END namespace Base { @@ -145,6 +154,8 @@ public: Property *restore(PropertyContainer &pc, const char *PropName, const char *TypeName, Base::XMLReader &reader); + Property *restore(PropertyContainer &pc, + const char *PropName, const char *TypeName, Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM); struct PropData { Property* property; diff --git a/src/App/Extension.cpp b/src/App/Extension.cpp index c3dea0f5e7..ce0991f042 100644 --- a/src/App/Extension.cpp +++ b/src/App/Extension.cpp @@ -34,7 +34,6 @@ #include "ExtensionPython.h" #include - /* We do not use a standard property macro for type initiation. The reason is that we have the first * PropertyData in the extension chain, there is no parent property data. */ @@ -79,7 +78,6 @@ void Extension::initExtensionType(Base::Type type) { } void Extension::initExtension(ExtensionContainer* obj) { - if (m_extensionType.isBad()) throw Base::RuntimeError("Extension: Extension type not set"); @@ -205,6 +203,24 @@ bool Extension::extensionHandleChangedPropertyType(Base::XMLReader &reader, cons return false; }; +bool Extension::extensionHandleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) +{ + (void) reader; + (void) TypeName; + (void) PropName; + + return false; +}; + +bool Extension::extensionHandleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) +{ + (void) reader; + (void) TypeName; + (void) prop; + + return false; +}; + namespace App { EXTENSION_PROPERTY_SOURCE_TEMPLATE(App::ExtensionPython, App::ExtensionPython::Inherited) diff --git a/src/App/Extension.h b/src/App/Extension.h index 84bb442a10..d667d35900 100644 --- a/src/App/Extension.h +++ b/src/App/Extension.h @@ -290,6 +290,10 @@ protected: virtual bool extensionHandleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName); /// returns true if the property type change was handled by the extension. virtual bool extensionHandleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop); + /// returns true if the property name change was handled by the extension. + virtual bool extensionHandleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName); + /// returns true if the property type change was handled by the extension. + virtual bool extensionHandleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop); friend class App::ExtensionContainer; diff --git a/src/App/ExtensionContainer.cpp b/src/App/ExtensionContainer.cpp index 372967dbae..fdcd5a14b8 100644 --- a/src/App/ExtensionContainer.cpp +++ b/src/App/ExtensionContainer.cpp @@ -32,6 +32,11 @@ #include "ExtensionContainer.h" #include +#ifndef _PreComp_ +# include +//# include +#endif + using namespace App; @@ -49,7 +54,6 @@ ExtensionContainer::~ExtensionContainer() { } void ExtensionContainer::registerExtension(Base::Type extension, Extension* ext) { - if(ext->getExtendedContainer() != this) throw Base::ValueError("ExtensionContainer::registerExtension: Extension has not this as base object"); @@ -308,16 +312,15 @@ void ExtensionContainer::Restore(Base::XMLReader& reader) { App::PropertyContainer::Restore(reader); } -void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl) { +void ExtensionContainer::Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) { //restore dynamic extensions. //Note 1: The extension element must be read first, before all other object elements. That is // needed as the element works together with an object element attribute, which would be // cleared if another attribute is read first //Note 2: This must happen before the py object of this container is used, as only in the // pyobject constructor the extension methods are added to the container. - restoreExtensions(reader,viewProviderEl); - //TODO NOW: - //App::PropertyContainer::Restore(reader); + restoreExtensions(reader,containerEl); + App::PropertyContainer::Restore(reader,containerEl); } void ExtensionContainer::saveExtensions(Base::Writer& writer) const { @@ -365,70 +368,80 @@ void ExtensionContainer::saveExtensions(Base::Writer& writer) const { writer.decInd(); } -void ExtensionContainer::restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl) { +void ExtensionContainer::restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) { //Dynamic extensions are optional (also because they are introduced late into the document format) //and hence it is possible that the element does not exist. As we cannot check for the existence of //an element a object attribute is set if extensions are available. Here we check that //attribute, and only if it exists the extensions element will be available. - const char* expanded_cstr = reader.GetAttribute(viewProviderEl,"expanded"); + const char* expanded_cstr = reader.GetAttribute(containerEl,"expanded"); if(!expanded_cstr) return; - auto ExtensionsDOM = reader.FindElement(viewProviderEl,"Extensions"); + auto ExtensionsDOM = reader.FindElement(containerEl,"Extensions"); if(ExtensionsDOM){ const char* cnt_cstr = reader.GetAttribute(ExtensionsDOM,"Count"); if(cnt_cstr){ long Cnt = reader.ContentToInt( cnt_cstr ); - for (int i=0 ;i(extension.createInstance()); - //check if this really is a python extension! - if (!ext->isPythonExtension()) { - delete ext; - std::stringstream str; - str << "Extension is not a python addable version: '" << type_cstr << "'" << std::ends; - throw Base::TypeError(str.str()); - } - ext->initExtension(this); - if( strcmp(ext->getExtensionTypeId().getName(), type_cstr) == 0 ) - ext->extensionRestore(reader); - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } - #ifndef FC_DEBUG - catch (...) { - Base::Console().Error("ExtensionContainer::Restore: Unknown C++ exception thrown\n"); - } - #endif + auto prev_ExtensionDOM = reader.FindElement(ExtensionsDOM,"Extension"); + readExtension(reader,prev_ExtensionDOM); + for (int i=1 ;i(extension.createInstance()); + //check if this really is a python extension! + if (!ext->isPythonExtension()) { + delete ext; + std::stringstream str; + str << "Extension is not a python addable version: '" << type_cstr << "'" << std::ends; + throw Base::TypeError(str.str()); + } + ext->initExtension(this); + if( strcmp(ext->getExtensionTypeId().getName(), type_cstr) == 0 ) + ext->extensionRestore(reader); + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } +#ifndef FC_DEBUG + catch (...) { + Base::Console().Error("ExtensionContainer::Restore: Unknown C++ exception thrown\n"); + } +#endif + +} + void ExtensionContainer::restoreExtensions(Base::XMLReader& reader) { //Dynamic extensions are optional (also because they are introduced late into the document format) @@ -508,6 +521,20 @@ void ExtensionContainer::handleChangedPropertyName(Base::XMLReader &reader, cons PropertyContainer::handleChangedPropertyName(reader, TypeName, PropName); } +void ExtensionContainer::handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) +{ + //inform all extensions about changed property name. This includes all properties from the + //extended object (this) as well as all extension properties + for(const auto& entry : _extensions) { + bool handled = entry.second->extensionHandleChangedPropertyName(reader, TypeName, PropName); + + if(handled) + return; // one property change needs only be handled once + } + + PropertyContainer::handleChangedPropertyName(reader, TypeName, PropName); +} + void ExtensionContainer::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop) { //inform all extensions about changed property type. This includes all properties from the @@ -521,3 +548,17 @@ void ExtensionContainer::handleChangedPropertyType(Base::XMLReader &reader, cons PropertyContainer::handleChangedPropertyType(reader, TypeName, prop); } + +void ExtensionContainer::handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) +{ + //inform all extensions about changed property type. This includes all properties from the + //extended object (this) as well as all extension properties + for(const auto& entry : _extensions) { + bool handled = entry.second->extensionHandleChangedPropertyType(reader, TypeName, prop); + + if(handled) + return; // one property change needs only be handled once + } + + PropertyContainer::handleChangedPropertyType(reader, TypeName, prop); +} diff --git a/src/App/ExtensionContainer.h b/src/App/ExtensionContainer.h index 9c90b95fbf..d71908ba7a 100644 --- a/src/App/ExtensionContainer.h +++ b/src/App/ExtensionContainer.h @@ -185,13 +185,13 @@ public: void Save(Base::Writer& writer) const override; void Restore(Base::XMLReader& reader) override; - void Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); + void Restore(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl); //those methods save/restore the dynamic extensions without handling properties, which is something //done by the default Save/Restore methods. void saveExtensions(Base::Writer& writer) const; void restoreExtensions(Base::XMLReader& reader); - void restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *viewProviderEl); + void restoreExtensions(Base::DocumentReader& reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl); /** Extends the rules for handling property name changed, so that extensions are given an opportunity to handle it. * If an extension handles a change, neither the rest of the extensions, nor the container itself get to handle it. @@ -201,6 +201,7 @@ public: * If no extension handles the request, then the containers handleChangedPropertyName() is called. */ virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) override; + virtual void handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) override; /** Extends the rules for handling property type changed, so that extensions are given an opportunity to handle it. * If an extension handles a change, neither the rest of the extensions, nor the container itself get to handle it. * @@ -209,6 +210,9 @@ public: * If no extension handles the request, then the containers handleChangedPropertyType() is called. */ virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop) override; + virtual void handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop) override; + + void readExtension(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ExtensionDOM); private: //stored extensions diff --git a/src/App/PropertyContainer.cpp b/src/App/PropertyContainer.cpp index 837162fc4b..5d5ee8dd2e 100644 --- a/src/App/PropertyContainer.cpp +++ b/src/App/PropertyContainer.cpp @@ -32,6 +32,10 @@ #include "PropertyContainer.h" #include +#ifndef _PreComp_ +# include +#endif + FC_LOG_LEVEL_INIT("App",true,true) @@ -75,8 +79,9 @@ App::Property* PropertyContainer::addDynamicProperty( Property *PropertyContainer::getPropertyByName(const char* name) const { auto prop = dynamicProps.getDynamicPropertyByName(name); - if(prop) + if(prop){ return prop; + } return getPropertyData().getPropertyByName(this,name); } @@ -199,6 +204,13 @@ void PropertyContainer::handleChangedPropertyName(Base::XMLReader &reader, const (void)PropName; } +void PropertyContainer::handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName) +{ + (void)reader; + (void)TypeName; + (void)PropName; +} + /** * @brief PropertyContainer::handleChangedPropertyType is called during restore to possibly * fix reading of older versions of the property container. This method is typically called @@ -218,6 +230,13 @@ void PropertyContainer::handleChangedPropertyType(XMLReader &reader, const char (void)prop; } +void PropertyContainer::handleChangedPropertyType(DocumentReader &reader, const char *TypeName, Property *prop) +{ + (void)reader; + (void)TypeName; + (void)prop; +} + PropertyData PropertyContainer::propertyData; void PropertyContainer::Save (Base::Writer &writer) const @@ -321,6 +340,7 @@ void PropertyContainer::Restore(Base::XMLReader &reader) if(reader.hasAttribute("TransientCount")) transientCount = reader.getAttributeAsUnsigned("TransientCount"); + for (int i=0;igetContainer() != this) + if(!prop || prop->getContainer() != this){ prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); + } decltype(Property::StatusBits) status; if(reader.hasAttribute("status")) { @@ -403,101 +424,115 @@ void PropertyContainer::Restore(Base::XMLReader &reader) reader.readEndElement("Properties"); } -void PropertyContainer::Restore(Base::DocumentReader &reader) +void PropertyContainer::Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) { - //TODO NOW - Base::Console().Error("PropertyContainer::Restore: DocumentReader\n"); reader.clearPartialRestoreProperty(); - /* - reader.clearPartialRestoreProperty(); - reader.readElement("Properties"); - int Cnt = reader.getAttributeAsInteger("Count"); + + auto PropertiesDOM = reader.FindElement(containerEl,"Properties"); + const char* count_cstr = reader.GetAttribute(PropertiesDOM,"Count"); + if(count_cstr){ + long Cnt = reader.ContentToInt( count_cstr ); + const char* TransientCount_cstr = reader.GetAttribute(PropertiesDOM,"TransientCount"); + int transientCount = 0; + if(TransientCount_cstr) + transientCount = reader.ContentToUnsigned( TransientCount_cstr ); + + for (int i=0;igetName() << "'"); + if(prop && status_cstr){ + int u_status = reader.ContentToUnsigned( status_cstr ); + prop->setStatusValue(u_status); + } + } + if(Cnt){ + auto prev_PropertyDOM = reader.FindElement(PropertiesDOM,"Property"); + readProperty(reader,prev_PropertyDOM); + for (int i=1 ;igetName() << "'"); - if(prop && reader.hasAttribute("status")) - prop->setStatusValue(reader.getAttributeAsUnsigned("status")); - } - - for (int i=0 ;igetContainer() != this) - prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); - - decltype(Property::StatusBits) status; - if(reader.hasAttribute("status")) { - status = decltype(status)(reader.getAttributeAsUnsigned("status")); - if(prop) - prop->setStatusValue(status.to_ulong()); - } - // name and type match - if (prop && strcmp(prop->getTypeId().getName(), TypeName.c_str()) == 0) { - if (!prop->testStatus(Property::Transient) - && !status.test(Property::Transient) - && !status.test(Property::PropTransient) - && !prop->testStatus(Property::PropTransient)) - { - FC_TRACE("restore property '" << prop->getName() << "'"); - prop->Restore(reader); - }else - FC_TRACE("skip transient '" << prop->getName() << "'"); - } - // name matches but not the type - else if (prop) { - handleChangedPropertyType(reader, TypeName.c_str(), prop); - } - // name doesn't match, the sub-class then has to know - // if the property has been renamed or removed - else { - handleChangedPropertyName(reader, TypeName.c_str(), PropName.c_str()); - } - - if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInProperty)) { - Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str()); - reader.clearPartialRestoreProperty(); - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::RestoreError &) { - reader.setPartialRestore(true); - reader.clearPartialRestoreProperty(); - Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str()); - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } +// NOTE: We must also check the type of the current property because a +// subclass of PropertyContainer might change the type of a property but +// not its name. In this case we would force to read-in a wrong property +// type and the behaviour would be undefined. +void PropertyContainer::readProperty(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM){ + const char* name_cstr = reader.GetAttribute(PropertyDOM,"name"); + const char* type_cstr = reader.GetAttribute(PropertyDOM,"type"); + try { + + auto prop = getPropertyByName(name_cstr); + if(!prop || prop->getContainer() != this){ + prop = dynamicProps.restore(*this,name_cstr,type_cstr,reader,PropertyDOM); + } + + decltype(Property::StatusBits) status; + const char* status_cstr = reader.GetAttribute(PropertyDOM,"status"); + if(status_cstr){ + int u_status = reader.ContentToUnsigned( status_cstr ); + status = decltype(status)(u_status); + if(prop) + prop->setStatusValue(status.to_ulong()); + } + // name and type match + if (prop && strcmp(prop->getTypeId().getName(), type_cstr) == 0) { + if (!prop->testStatus(Property::Transient) + && !status.test(Property::Transient) + && !status.test(Property::PropTransient) + && !prop->testStatus(Property::PropTransient)) + { + FC_TRACE("restore property '" << prop->getName() << "'"); + prop->Restore(reader,PropertyDOM); + }else + FC_TRACE("skip transient '" << prop->getName() << "'"); + } + // name matches but not the type + else if (prop) { + handleChangedPropertyType(reader, type_cstr, prop); + } + // name doesn't match, the sub-class then has to know + // if the property has been renamed or removed + else { + handleChangedPropertyName(reader, type_cstr, name_cstr); + } + + if (reader.testStatus(Base::DocumentReader::ReaderStatus::PartialRestoreInProperty)) { + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",name_cstr,type_cstr); + reader.clearPartialRestoreProperty(); + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::RestoreError &) { + reader.setPartialRestore(true); + reader.clearPartialRestoreProperty(); + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",name_cstr,type_cstr); + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } #ifndef FC_DEBUG - catch (...) { - Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n"); - } + catch (...) { + Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n"); + } #endif - reader.readEndElement("Property"); - } - reader.readEndElement("Properties"); - */ } void PropertyContainer::onPropertyStatusChanged(const Property &prop, unsigned long oldStatus) diff --git a/src/App/PropertyContainer.h b/src/App/PropertyContainer.h index 4a165d51ee..d49b8a8e76 100644 --- a/src/App/PropertyContainer.h +++ b/src/App/PropertyContainer.h @@ -30,6 +30,16 @@ #include "DynamicProperty.h" +#include + +XERCES_CPP_NAMESPACE_BEGIN + class DOMNode; + class DOMElement; +// class DefaultHandler; +// class SAX2XMLReader; +XERCES_CPP_NAMESPACE_END + + namespace Base { class Writer; } @@ -220,7 +230,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; - void Restore(Base::DocumentReader &reader) override; + void Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) override; virtual void editProperty(const char * /*propName*/) {} @@ -248,11 +258,14 @@ protected: virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName); virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop); + virtual void handleChangedPropertyName(Base::DocumentReader &reader, const char * TypeName, const char *PropName); + virtual void handleChangedPropertyType(Base::DocumentReader &reader, const char * TypeName, Property * prop); private: // forbidden PropertyContainer(const PropertyContainer&); PropertyContainer& operator = (const PropertyContainer&); + void readProperty(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *PropertyDOM); protected: DynamicProperty dynamicProps; diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 96b69440b0..030d2b3463 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -23,6 +23,10 @@ #include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + #include #include @@ -30,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +122,20 @@ void PropertyInteger::Restore(Base::XMLReader &reader) setValue(reader.getAttributeAsInteger("value")); } +void PropertyInteger::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto IntegerDOM = reader.FindElement(ContainerDOM,"Integer"); + if(IntegerDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(IntegerDOM,"value"); + if(value_cstr){ + long value = reader.ContentToInt( value_cstr ); + setValue(value); + } + } +} + Property *PropertyInteger::Copy() const { PropertyInteger *p= new PropertyInteger(); @@ -242,6 +261,18 @@ void PropertyPath::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } +void PropertyPath::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto PathDOM = reader.FindElement(ContainerDOM,"Path"); + if(PathDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(PathDOM,"value"); + if(value_cstr){ + setValue(value_cstr); + } + } +} + Property *PropertyPath::Copy() const { PropertyPath *p= new PropertyPath(); @@ -432,6 +463,54 @@ void PropertyEnumeration::Restore(Base::XMLReader &reader) hasSetValue(); } +void PropertyEnumeration::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto IntegerDOM = reader.FindElement(ContainerDOM,"Integer"); + if(IntegerDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(IntegerDOM,"value"); + if(value_cstr){ + long val = reader.ContentToInt( value_cstr ); + aboutToSetValue(); + + const char* CustomEnum_cstr = reader.GetAttribute(IntegerDOM,"CustomEnum"); + if(CustomEnum_cstr){ + auto CustomEnumListDOM = reader.FindElement(IntegerDOM,"CustomEnumList"); + if(CustomEnumListDOM){ + const char* count_cstr = reader.GetAttribute(IntegerDOM,"count"); + if(count_cstr){ + long count = reader.ContentToInt( count_cstr ); + std::vector values(count); + + if(count >= 1){ + auto prev_EnumDOM = reader.FindElement(CustomEnumListDOM,"Enum"); + const char* enum_value_cstr = reader.GetAttribute(prev_EnumDOM,"value"); + values[0] = enum_value_cstr; + for(int i = 1; i < count; i++) { + auto EnumDOM_i = reader.FindNextElement(prev_EnumDOM,"Enum"); + const char* _enum_value_cstr = reader.GetAttribute(EnumDOM_i,"value"); + values[i] = _enum_value_cstr; + + prev_EnumDOM = EnumDOM_i; + } + } + _enum.setEnums(values); + } + } + } + if (val < 0) { + // If the enum is empty at this stage do not print a warning + if (_enum.hasEnums()) + Base::Console().Warning("Enumeration index %d is out of range, ignore it\n", val); + val = getValue(); + } + + _enum.setValue(val); + hasSetValue(); + } + } +} + PyObject * PropertyEnumeration::getPyObject() { if (!_enum.isValid()) { @@ -782,6 +861,35 @@ void PropertyIntegerList::Restore(Base::XMLReader &reader) setValues(values); } +void PropertyIntegerList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto IntegerListDOM = reader.FindElement(ContainerDOM,"IntegerList"); + if(IntegerListDOM){ + // get the value of my Attribute + const char* count_cstr = reader.GetAttribute(IntegerListDOM,"count"); + long count = reader.ContentToInt( count_cstr ); + std::vector values(count); + if(count >= 1){ + auto prev_I_DOM = reader.FindElement(IntegerListDOM,"I"); + const char* v_cstr = reader.GetAttribute(prev_I_DOM,"v"); + long v = reader.ContentToInt( v_cstr ); + values[0] = v; + + for(int i = 1; i < count; i++) { + auto I_DOM_i = reader.FindNextElement(prev_I_DOM,"I"); + const char* _v_cstr = reader.GetAttribute(I_DOM_i,"v"); + long v = reader.ContentToInt( _v_cstr ); + values[i] = v; + + prev_I_DOM = I_DOM_i; + } + } + //assignment + setValues(values); + } +} + + Property *PropertyIntegerList::Copy() const { PropertyIntegerList *p= new PropertyIntegerList(); @@ -902,6 +1010,35 @@ void PropertyIntegerSet::Restore(Base::XMLReader &reader) setValues(values); } +void PropertyIntegerSet::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto IntegerSetDOM = reader.FindElement(ContainerDOM,"IntegerSet"); + if(IntegerSetDOM){ + // get the value of my Attribute + const char* count_cstr = reader.GetAttribute(IntegerSetDOM,"count"); + long count = reader.ContentToInt( count_cstr ); + std::set values; + + if(count >= 1){ + auto prev_I_DOM = reader.FindElement(IntegerSetDOM,"I"); + const char* v_cstr = reader.GetAttribute(prev_I_DOM,"v"); + long v = reader.ContentToInt( v_cstr ); + values.insert( v ); + + for(int i = 1; i < count; i++) { + auto I_DOM_i = reader.FindNextElement(prev_I_DOM,"I"); + const char* _v_cstr = reader.GetAttribute(I_DOM_i,"v"); + long v = reader.ContentToInt( _v_cstr ); + values.insert( v ); + + prev_I_DOM = I_DOM_i; + } + } + //assignment + setValues(values); + } +} + Property *PropertyIntegerSet::Copy() const { PropertyIntegerSet *p= new PropertyIntegerSet(); @@ -993,6 +1130,21 @@ void PropertyFloat::Restore(Base::XMLReader &reader) setValue(reader.getAttributeAsFloat("value")); } +void PropertyFloat::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto FloatDOM = reader.FindElement(ContainerDOM,"Float"); + if(FloatDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(FloatDOM,"value"); + if(value_cstr){ + double value = reader.ContentToFloat( value_cstr ); + setValue(value); + } + } +} + + + Property *PropertyFloat::Copy() const { PropertyFloat *p= new PropertyFloat(); @@ -1242,6 +1394,24 @@ void PropertyFloatList::Restore(Base::XMLReader &reader) } } +void PropertyFloatList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + //TODO for this its needed to implement addFile() into Reader.cpp, and ReadFiles() since its not possible to have an XMLReader object at this point, because it gives error to use both methods(XMLReader progressive reading and DocumentReader reading) probably because there is something wrong with the zipios implementation, it looks like its locking file or in some way makes the file structure invalid to be readed by xerces by both methods. + //worked around reimplementing ReadFiles in DocumentReader.cpp: + auto FloatListDOM = reader.FindElement(ContainerDOM,"FloatList"); + if(FloatListDOM){ + // get the value of my Attribute + const char* file_cstr = reader.GetAttribute(FloatListDOM,"file"); + if(file_cstr){ + string file ( file_cstr ); + if (!file.empty()) { + // initiate a file read + reader.addFile(file.c_str(),this); + } + } + } +} + void PropertyFloatList::SaveDocFile (Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -1502,6 +1672,31 @@ void PropertyString::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } +void PropertyString::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto StringDOM = reader.FindElement(ContainerDOM,"String"); + const char* value_cstr = reader.GetAttribute(StringDOM,"value"); + + auto obj = dynamic_cast(getContainer()); + if(obj && &obj->Label==this) { + const char* restore_cstr = reader.GetAttribute(StringDOM,"restore"); + + if(restore_cstr) { + int restore = reader.ContentToInt( restore_cstr ); + if(restore == 1) { + aboutToSetValue(); + _cValue = value_cstr; + hasSetValue(); + return; + } + return; + } + } + setValue(value_cstr); + + +} + Property *PropertyString::Copy() const { PropertyString *p= new PropertyString(); @@ -1634,6 +1829,18 @@ void PropertyUUID::Restore(Base::XMLReader &reader) setValue(reader.getAttribute("value")); } +void PropertyUUID::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto UuidDOM = reader.FindElement(ContainerDOM,"Uuid"); + if(UuidDOM){ + // get the value of my Attribute + const char* value_cstr = reader.GetAttribute(UuidDOM,"value"); + if(value_cstr){ + setValue(value_cstr); + } + } +} + Property *PropertyUUID::Copy() const { PropertyUUID *p= new PropertyUUID(); @@ -1755,6 +1962,32 @@ void PropertyStringList::Restore(Base::XMLReader &reader) setValues(values); } +void PropertyStringList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto StringListDOM = reader.FindElement(ContainerDOM,"StringList"); + if(StringListDOM){ + // get the value of my Attribute + const char* count_cstr = reader.GetAttribute(StringListDOM,"count"); + long count = reader.ContentToInt( count_cstr ); + std::vector values(count); + if(count >= 1){ + auto prev_StringDOM = reader.FindElement(StringListDOM,"String"); + const char* value_cstr = reader.GetAttribute(prev_StringDOM,"value"); + values[0] = value_cstr; + for(int i = 1; i < count; i++) { + auto StringDOM_i = reader.FindNextElement(prev_StringDOM,"String"); + const char* _value_cstr = reader.GetAttribute(StringDOM_i,"value"); + values[i] = _value_cstr; + + prev_StringDOM = StringDOM_i; + } + + } + // assignment + setValues(values); + } +} + Property *PropertyStringList::Copy() const { PropertyStringList *p= new PropertyStringList(); @@ -1919,6 +2152,32 @@ void PropertyMap::Restore(Base::XMLReader &reader) setValues(values); } +void PropertyMap::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto MapDOM = reader.FindElement(ContainerDOM,"Map"); + if(MapDOM){ + // get the value of my Attribute + const char* count_cstr = reader.GetAttribute(MapDOM,"count"); + int count = reader.ContentToInt( count_cstr ); + std::map values; + auto prev_ItemDOM = reader.FindElement(MapDOM,"Item"); + const char* key_cstr = reader.GetAttribute(prev_ItemDOM,"key"); + const char* value_cstr = reader.GetAttribute(prev_ItemDOM,"value"); + values[key_cstr] = value_cstr; + + for(int i = 1; i < count; i++) { + auto ItemDOM_i = reader.FindNextElement(prev_ItemDOM,"Item"); + const char* key_cstr = reader.GetAttribute(ItemDOM_i,"key"); + const char* value_cstr = reader.GetAttribute(ItemDOM_i,"value"); + values[key_cstr] = value_cstr; + + prev_ItemDOM = ItemDOM_i; + } + // assignment + setValues(values); + } +} + Property *PropertyMap::Copy() const { PropertyMap *p= new PropertyMap(); @@ -2004,6 +2263,15 @@ void PropertyBool::Restore(Base::XMLReader &reader) (b == "true") ? setValue(true) : setValue(false); } +void PropertyBool::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto BoolDOM = reader.FindElement(ContainerDOM,"Bool"); + if(BoolDOM){ + // get the value of my Attribute + string b = reader.GetAttribute(BoolDOM,"value"); + (b == "true") ? setValue(true) : setValue(false); + } +} Property *PropertyBool::Copy() const { @@ -2122,6 +2390,18 @@ void PropertyBoolList::Restore(Base::XMLReader &reader) setValues(bitset); } +void PropertyBoolList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto BoolListDOM = reader.FindElement(ContainerDOM,"BoolList"); + if(BoolListDOM){ + // get the value of my Attribute + string str = reader.GetAttribute(BoolListDOM,"value"); + boost::dynamic_bitset<> bitset(str); + setValues(bitset); + } +} + Property *PropertyBoolList::Copy() const { PropertyBoolList *p= new PropertyBoolList(); @@ -2275,6 +2555,17 @@ void PropertyColor::Restore(Base::XMLReader &reader) setValue(rgba); } +void PropertyColor::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto PropertyColorDOM = reader.FindElement(ContainerDOM,"PropertyColor"); + if(PropertyColorDOM){ + const char* val_cstr = reader.GetAttribute(PropertyColorDOM,"value"); + unsigned long rgba = reader.ContentToUnsigned(val_cstr); + setValue(rgba); + } +} + Property *PropertyColor::Copy() const { PropertyColor *p= new PropertyColor(); @@ -2354,6 +2645,22 @@ void PropertyColorList::Restore(Base::XMLReader &reader) } } +void PropertyColorList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto ColorListDOM = reader.FindElement(ContainerDOM,"ColorList"); + if(ColorListDOM){ + // get the value of my Attribute + const char* file_cstr = reader.GetAttribute(ColorListDOM,"file"); + if(file_cstr){ + std::string file (file_cstr); + if (!file.empty()) { + // initiate a file read + reader.addFile(file.c_str(),this); + } + } + } +} + void PropertyColorList::SaveDocFile (Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -2504,6 +2811,32 @@ void PropertyMaterial::Restore(Base::XMLReader &reader) hasSetValue(); } +void PropertyMaterial::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto PropertyMaterialDOM = reader.FindElement(ContainerDOM,"PropertyMaterial"); + if(PropertyMaterialDOM){ + // get the value of my Attribute + aboutToSetValue(); + + const char* ambientColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"ambientColor"); + const char* diffuseColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"diffuseColor"); + const char* specularColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"specularColor"); + const char* emissiveColor_cstr = reader.GetAttribute(PropertyMaterialDOM,"emissiveColor"); + const char* shininess_cstr = reader.GetAttribute(PropertyMaterialDOM,"shininess"); + const char* transparency_cstr = reader.GetAttribute(PropertyMaterialDOM,"transparency"); + + _cMat.ambientColor.setPackedValue(reader.ContentToUnsigned(ambientColor_cstr)); + _cMat.diffuseColor.setPackedValue(reader.ContentToUnsigned(diffuseColor_cstr)); + _cMat.specularColor.setPackedValue(reader.ContentToUnsigned(specularColor_cstr)); + _cMat.emissiveColor.setPackedValue(reader.ContentToUnsigned(emissiveColor_cstr)); + _cMat.shininess = (float)reader.ContentToFloat(shininess_cstr); + _cMat.transparency = (float)reader.ContentToFloat(transparency_cstr); + hasSetValue(); + } +} + + const char* PropertyMaterial::getEditorName() const { if(testStatus(MaterialEdit)) @@ -2583,6 +2916,22 @@ void PropertyMaterialList::Restore(Base::XMLReader &reader) } } +void PropertyMaterialList::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto MaterialListDOM = reader.FindElement(ContainerDOM,"MaterialList"); + if(MaterialListDOM){ + // get the value of my Attribute + const char* file_cstr = reader.GetAttribute(MaterialListDOM,"file"); + if(file_cstr){ + std::string file (file_cstr); + if (!file.empty()) { + // initiate a file read + reader.addFile(file.c_str(),this); + } + } + } +} + void PropertyMaterialList::SaveDocFile(Base::Writer &writer) const { Base::OutputStream str(writer.Stream()); @@ -2679,6 +3028,14 @@ void PropertyPersistentObject::Restore(Base::XMLReader &reader){ reader.readEndElement(ELEMENT_PERSISTENT_OBJ); } +void PropertyPersistentObject::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + inherited::Restore(reader,ContainerDOM); + auto element_persistent_obj_DOM = reader.FindElement(ELEMENT_PERSISTENT_OBJ); + if(_pObject) + _pObject->Restore(reader,element_persistent_obj_DOM); +} + Property *PropertyPersistentObject::Copy() const{ auto *p= new PropertyPersistentObject(); p->_cValue = _cValue; diff --git a/src/App/PropertyStandard.h b/src/App/PropertyStandard.h index cd5d8755f3..e1d1cd0d43 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -36,6 +36,12 @@ #include "Enumeration.h" #include "Material.h" +#include + +XERCES_CPP_NAMESPACE_BEGIN + class DOMElement; +XERCES_CPP_NAMESPACE_END + namespace Base { class Writer; @@ -70,6 +76,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -121,6 +128,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -220,6 +228,7 @@ public: void Save(Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property * Copy() const override; void Paste(const Property &from) override; @@ -358,6 +367,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -403,6 +413,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -462,6 +473,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -515,6 +527,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -658,6 +671,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile (Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -705,6 +719,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -758,6 +773,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -824,6 +840,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -865,6 +882,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -902,6 +920,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -949,6 +968,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -988,6 +1008,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile (Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -1040,6 +1061,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; const char* getEditorName() const override; @@ -1083,6 +1105,7 @@ public: void Save(Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile(Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -1112,6 +1135,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; Property *Copy() const override; void Paste(const Property &from) override; diff --git a/src/Base/DocumentReader.cpp b/src/Base/DocumentReader.cpp index 01b97285f0..4160b2e6a0 100644 --- a/src/Base/DocumentReader.cpp +++ b/src/Base/DocumentReader.cpp @@ -19,41 +19,24 @@ * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ -//#include "PreCompiled.h" - -//#include - #include "DocumentReader.h" - -//#include "Reader.h" -//#include "Base64.h" -//#include "Console.h" #include "InputSource.h" -//#include "Persistence.h" -//#include "Sequencer.h" -//#include "Stream.h" #include "XMLTools.h" -//#ifdef _MSC_VER -//#include -//#endif -//#include #include #include +#include "Persistence.h" +#include "Sequencer.h" + + +#ifdef _MSC_VER +#include +#endif +#include + #ifndef _PreComp_ -//# include -//# include # include -//# include -//# include -//# include -//# include # include -//# include -//# include -//# include -//# include -//# include #endif XERCES_CPP_NAMESPACE_USE @@ -67,30 +50,12 @@ using namespace Base; static XercesDOMParser::ValSchemes gValScheme = XercesDOMParser::Val_Auto; DocumentReader::DocumentReader() { - gDoNamespaces = false; gDoSchema = false; gSchemaFullChecking = false; gDoCreate = true; - - /* - gOutputEncoding = nullptr; - gMyEOLSequence = nullptr; - - gSplitCdataSections = true; - gDiscardDefaultContent = true; - gUseFilter = true; - gFormatPrettyPrint = true; - */ - } -//DocumentReader::~DocumentReader() -//{ - //delete parser; -//} -//int DocumentReader::LoadDocument(const XERCES_CPP_NAMESPACE_QUALIFIER InputSource& inputSource) -//int DocumentReader::LoadDocument(std::istream& Stream,std::string filename) int DocumentReader::LoadDocument(Base::Reader& reader) { FileInfo _File( reader.getFileName() ); @@ -139,7 +104,7 @@ int DocumentReader::LoadDocument(Base::Reader& reader) return 0; } - XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* _pDocument = parser->adoptDocument(); + XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* _pDocument = parser->adoptDocument(); delete parser; delete errReporter; @@ -174,9 +139,7 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(const cha for (DOMNode *clChild = _pGroupNode->getFirstChild(); clChild != nullptr; clChild = clChild->getNextSibling()) { if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { - if (clChild->getAttributes()->getLength() > 0) { - return static_cast(clChild); - } + return static_cast(clChild); } } } @@ -191,9 +154,6 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(XERCES_CP if (clChild->getNodeType() == DOMNode::ELEMENT_NODE) { if (!strcmp(Type,StrX(clChild->getNodeName()).c_str())) { return static_cast(clChild); - //if (clChild->getAttributes()->getLength() > 0) { - //return static_cast(clChild); - //} } } } @@ -216,41 +176,22 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindNextElement(XERCE return nullptr; } -/* -//CONTENT: -const char * DocumentReader::GetContent(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl) const -{ - if (!DOMEl) - return nullptr; - return StrX(DOMEl->getAttribute(XStr("Value").unicodeForm())).c_str(); -} - -std::string DocumentReader::GetContentASCII(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DOMEl) const -{ - //return std::string(StrXUTF8(pcElem->getNodeValue()).c_str() ); - //maybe its better to use getNodeValue() - if (!DOMEl) - return nullptr; - return std::string( StrXUTF8(DOMEl->getAttribute(XStr("Value").unicodeForm())).c_str() ); -} -*/ - -long DocumentReader::ContentToInt( const char* content ) const +long DocumentReader::ContentToInt( const char* content ) { return atol( content ); } -unsigned long DocumentReader::ContentToUnsigned(const char* content) const +unsigned long DocumentReader::ContentToUnsigned(const char* content) { return strtoul(content,nullptr,10); } -double DocumentReader::ContentToFloat(const char* content) const +double DocumentReader::ContentToFloat(const char* content) { return atof(content); } -bool DocumentReader::ContentToBool(const char* content) const +bool DocumentReader::ContentToBool(const char* content) { if (strcmp(content,"1")) return false; @@ -282,18 +223,16 @@ const char * DocumentReader::GetAttribute(const char* Attr) const return nullptr; } const XMLCh * attr = _pGroupNode->getAttribute( xstr.unicodeForm() ); - //stringLen return strdup( StrX( attr ).c_str() );//strdup is needed since pointer from strx only exists in context where StrX() is created. } - -/* -unsigned int Base::XMLReader::getAttributeCount() const -{ - return static_cast(AttrMap.size()); -} -*/ - //Status +void Base::DocumentReader::setPartialRestore(bool on) +{ + setStatus(PartialRestore, on); + setStatus(PartialRestoreInDocumentObject, on); + setStatus(PartialRestoreInProperty, on); + setStatus(PartialRestoreInObject, on); +} void Base::DocumentReader::clearPartialRestoreProperty() { @@ -311,4 +250,77 @@ void Base::DocumentReader::setStatus(ReaderStatus pos, bool on) StatusBits.set(static_cast(pos), on); } +const char *Base::DocumentReader::addFile(const char* Name, Base::Persistence *Object) +{ + FileEntry temp; + temp.FileName = Name; + temp.Object = Object; + FileList.push_back(temp); + FileNames.push_back( temp.FileName ); + + return Name; +} + +void Base::DocumentReader::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. + // 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 + // file, then. + // In either case it's guaranteed that the order of the files is kept. + zipios::ConstEntryPointer entry; + try { + entry = zipstream.getNextEntry(); + } + catch (const std::exception&) { + // There is no further file at all. This can happen if the + // project file was created without GUI + return; + } + 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; + // 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) + ++jt; + // If this condition is true both file names match and we can read-in the data, otherwise + // no file name for the current entry in the zip was registered. + if (jt != FileList.end()) { + try { + Base::Reader reader(zipstream, jt->FileName, FileVersion); + jt->Object->RestoreDocFile(reader); + if (reader.getLocalReader()) + reader.getLocalReader()->readFiles(zipstream); + if (reader.getLocalDocReader()) + reader.getLocalDocReader()->readFiles(zipstream); + + }catch(...) { + // For any exception we just continue with the next file. + // It doesn't matter if the last reader has read more or + // less data than the file size would allow. + // All what we need to do is to notify the user about the + // failure. + Base::Console().Error("Reading failed from embedded file(DocumentReader): %s\n", entry->toString().c_str()); + } + // Go to the next registered file name + it = jt + 1; + } + + seq.next(); + + // In either case we must go to the next entry + try { + entry = zipstream.getNextEntry(); + } + catch (const std::exception&) { + // there is no further entry + break; + } + } +} diff --git a/src/Base/DocumentReader.h b/src/Base/DocumentReader.h index e414046f37..863fa521de 100644 --- a/src/Base/DocumentReader.h +++ b/src/Base/DocumentReader.h @@ -25,18 +25,16 @@ #include #include -//#include -//#include +#include #include #include - -//#include -//#include -//#include #include -//#include "FileInfo.h"//reemplazado por: +//#include "FileInfo.h"//remplaced: #include -//#include + +namespace zipios { +class ZipInputStream; +} XERCES_CPP_NAMESPACE_BEGIN class DOMNode; @@ -49,7 +47,7 @@ namespace Base class Reader; class Persistence; -class BaseExport DocumentReader //: public ParameterManager +class BaseExport DocumentReader { public: enum ReaderStatus { @@ -66,12 +64,12 @@ public: XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElement(const char* Type) const; XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const; - long ContentToASCII(const char* Content) const; + static long ContentToASCII(const char* Content); - long ContentToInt(const char* Content) const; - unsigned long ContentToUnsigned(const char* Content) const; - double ContentToFloat(const char* Content) const; - bool ContentToBool(const char* Content) const; + static long ContentToInt(const char* Content); + static unsigned long ContentToUnsigned(const char* Content); + static double ContentToFloat(const char* Content); + static bool ContentToBool(const char* Content); const char* GetAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* DOMEl, const char* Attr) const; const char* GetAttribute(const char* Attr) const; @@ -80,15 +78,38 @@ public: bool testStatus(ReaderStatus pos) const; /// set the status bits void setStatus(ReaderStatus pos, bool on); + /// sets simultaneously the global and local PartialRestore bits + void setPartialRestore(bool on); void clearPartialRestoreProperty(); + /// add a read request of a persistent object + const char *addFile(const char* Name, Base::Persistence *Object); + + void readFiles(zipios::ZipInputStream &zipstream) const; + + std::shared_ptr getLocalReader() const; + + struct FileEntry { + std::string FileName; + Base::Persistence *Object; + }; + std::vector FileList; + + /// Version of the file format + int FileVersion; + + + protected: XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *_pGroupNode; bool gDoNamespaces ; bool gDoSchema ; bool gSchemaFullChecking ; bool gDoCreate ; + + std::vector FileNames; + std::bitset<32> StatusBits; }; diff --git a/src/Base/Persistence.cpp b/src/Base/Persistence.cpp index 742a06cf35..73e6c2a9f2 100644 --- a/src/Base/Persistence.cpp +++ b/src/Base/Persistence.cpp @@ -34,6 +34,10 @@ /// Here the FreeCAD includes sorted by Base,App,Gui...... #include "Persistence.h" +#ifndef _PreComp_ +# include +#endif + using namespace Base; @@ -63,8 +67,10 @@ void Persistence::Save (Writer &/*writer*/) const void Persistence::Restore(DocumentReader &/*reader*/) { - // you have to implement this method in all descending classes! - assert(0); +} + +void Persistence::Restore(DocumentReader &/*reader*/,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement */*containerEl*/) +{ } void Persistence::Restore(XMLReader &/*reader*/) diff --git a/src/Base/Persistence.h b/src/Base/Persistence.h index 7941f7c748..cf4634c66d 100644 --- a/src/Base/Persistence.h +++ b/src/Base/Persistence.h @@ -26,6 +26,15 @@ #include "BaseClass.h" +#include + +XERCES_CPP_NAMESPACE_BEGIN + class DOMNode; + class DOMElement; +// class DefaultHandler; +// class SAX2XMLReader; +XERCES_CPP_NAMESPACE_END + namespace Base { class Reader; @@ -79,6 +88,8 @@ public: */ virtual void Restore(XMLReader &/*reader*/) = 0; virtual void Restore(DocumentReader &/*reader*/); + virtual void Restore(DocumentReader &/*reader*/,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement */*containerEl*/); + /** This method is used to save large amounts of data to a binary file. * Sometimes it makes no sense to write property data as XML. In case the * amount of data is too big or the data type has a more effective way to @@ -143,6 +154,8 @@ public: * @see Base::Reader,Base::XMLReader */ virtual void RestoreDocFile(Reader &/*reader*/); + + /// Encodes an attribute upon saving. static std::string encodeAttribute(const std::string&); diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index 92e207953b..8ff610621d 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -31,6 +31,7 @@ #include #include "Reader.h" +#include "DocumentReader.h" #include "Base64.h" #include "Console.h" #include "InputSource.h" @@ -333,9 +334,11 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const try { Base::Reader reader(zipstream, jt->FileName, FileVersion); jt->Object->RestoreDocFile(reader); - - if (reader.getLocalReader()) - reader.getLocalReader()->readFiles(zipstream); + if (reader.getLocalReader()) + reader.getLocalReader()->readFiles(zipstream); + if (reader.getLocalDocReader()) + reader.getLocalDocReader()->readFiles(zipstream); + }catch(...) { // For any exception we just continue with the next file. // It doesn't matter if the last reader has read more or @@ -577,3 +580,13 @@ std::shared_ptr Base::Reader::getLocalReader() const { return(this->localreader); } + +void Base::Reader::initLocalDocReader(std::shared_ptr reader) +{ + this->localdocreader = reader; +} + +std::shared_ptr Base::Reader::getLocalDocReader() const +{ + return(this->localdocreader); +} diff --git a/src/Base/Reader.h b/src/Base/Reader.h index d06617a95f..6673a3a43b 100644 --- a/src/Base/Reader.h +++ b/src/Base/Reader.h @@ -48,6 +48,7 @@ XERCES_CPP_NAMESPACE_END namespace Base { class Persistence; +class DocumentReader; /** The XML reader class * This is an important helper class for the store and retrieval system @@ -295,13 +296,16 @@ public: std::string getFileName() const; int getFileVersion() const; void initLocalReader(std::shared_ptr); + void initLocalDocReader(std::shared_ptr); std::shared_ptr getLocalReader() const; + std::shared_ptr getLocalDocReader() const; private: std::istream& _str; std::string _name; int fileVersion; std::shared_ptr localreader; + std::shared_ptr localdocreader; }; } diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index f4c31f7b8a..ef64d500cc 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1400,6 +1400,7 @@ void Document::Save (Base::Writer &writer) const void Document::Restore(Base::XMLReader &reader) { reader.addFile("GuiDocument.xml",this); + // hide all elements to avoid to update the 3d view when loading data files // RestoreDocFile then restores the visibility status again std::map::iterator it; @@ -1414,134 +1415,195 @@ void Document::Restore(Base::XMLReader &reader) */ void Document::RestoreDocFile(Base::Reader &reader) { - Base::DocumentReader docReader; - docReader.LoadDocument(reader); - //docReader.GetRootElement()//can be used to get Document XMLElement, but not needed. - const char* SchemaVersion_cstr = docReader.GetAttribute("SchemaVersion"); - long SchemaVersion = docReader.ContentToInt( SchemaVersion_cstr ); - const char* HasExpansion_cstr = docReader.GetAttribute("HasExpansion"); - if(HasExpansion_cstr){ - auto tree = TreeWidget::instance(); + readUsing_DocumentReader(reader); + //readUsing_XMLReader(reader); + setModified(false); +} + +void Document::readUsing_XMLReader(Base::Reader &reader){ + // We must create an XML parser to read from the input stream + std::shared_ptr localreader = std::make_shared("GuiDocument.xml", reader); + //localreader->FileVersion = reader.getFileVersion(); + + localreader->readElement("Document"); + long scheme = localreader->getAttributeAsInteger("SchemaVersion"); + //localreader->DocumentSchema = scheme; + + bool hasExpansion = localreader->hasAttribute("HasExpansion"); + if(hasExpansion) { + auto tree = TreeWidget::instance(); if(tree) { auto docItem = tree->getDocumentItem(this); if(docItem) - docItem->Restore(docReader); + docItem->Restore(*localreader); } } - + // At this stage all the document objects and their associated view providers exist. // Now we must restore the properties of the view providers only. - if (SchemaVersion == 1) { - auto VProviderDataDOM = docReader.FindElement("ViewProviderData"); + // + // SchemeVersion "1" + if (scheme == 1) { + + // read the viewproviders itself + + localreader->readElement("ViewProviderData"); + int Cnt = localreader->getAttributeAsInteger("Count"); + + for (int i=0; ireadElement("ViewProvider"); + std::string name = localreader->getAttribute("name"); + bool expanded = false; + if (!hasExpansion && localreader->hasAttribute("expanded")) { + + const char* attr = localreader->getAttribute("expanded"); + if (strcmp(attr,"1") == 0) { + expanded = true; + } + } + ViewProvider* pObj = getViewProviderByName(name.c_str()); + if (pObj){// check if this feature has been registered + pObj->Restore(*localreader); + } + + if (pObj && expanded) { + auto vp = static_cast(pObj); + this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); + } + localreader->readEndElement("ViewProvider"); + } + + localreader->readEndElement("ViewProviderData"); + + + // read camera settings + localreader->readElement("Camera"); + const char* ppReturn = localreader->getAttribute("settings"); + cameraSettings.clear(); + if(ppReturn && ppReturn[0]) { + saveCameraSettings(ppReturn); + try { + const char** pReturnIgnore=nullptr; + std::list mdi = getMDIViews(); + for (const auto & it : mdi) { + if (it->onHasMsg("SetCamera")) + it->onMsg(cameraSettings.c_str(), pReturnIgnore); + } + } + + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + } + } + localreader->readEndElement("Document"); + reader.initLocalReader(localreader); +} + +void Document::readUsing_DocumentReader(Base::Reader &reader){ + std::shared_ptr docReader = std::make_shared(); + docReader->LoadDocument(reader); + //docReader->GetRootElement()//can be used to get Document XMLElement, but not needed. + const char* SchemaVersion_cstr = docReader->GetAttribute("SchemaVersion"); + long SchemaVersion = docReader->ContentToInt( SchemaVersion_cstr ); + const char* HasExpansion_cstr = docReader->GetAttribute("HasExpansion"); + if(HasExpansion_cstr){ + auto tree = TreeWidget::instance(); + if(tree) { + auto docItem = tree->getDocumentItem(this); + if(docItem) + docItem->Restore(*docReader); + } + } + + // At this stage all the document objects and their associated view providers exist. + // Now we must restore the properties of the view providers only. + if (SchemaVersion == 1) { + auto VProviderDataDOM = docReader->FindElement("ViewProviderData"); if(VProviderDataDOM){ - const char* vpd_count_cstr = docReader.GetAttribute(VProviderDataDOM,"Count"); + const char* vpd_count_cstr = docReader->GetAttribute(VProviderDataDOM,"Count"); if(vpd_count_cstr){ - long Cnt = docReader.ContentToInt( vpd_count_cstr ); - auto prev_ViewProviderDOM = docReader.FindElement(VProviderDataDOM,"ViewProvider"); + long Cnt = docReader->ContentToInt( vpd_count_cstr ); + auto prev_ViewProviderDOM = docReader->FindElement(VProviderDataDOM,"ViewProvider"); if(prev_ViewProviderDOM){ - const char* name_cstr = docReader.GetAttribute(prev_ViewProviderDOM,"name"); - const char* expanded_cstr = docReader.GetAttribute(prev_ViewProviderDOM,"expanded"); + const char* name_cstr = docReader->GetAttribute(prev_ViewProviderDOM,"name"); + const char* expanded_cstr = docReader->GetAttribute(prev_ViewProviderDOM,"expanded"); bool expanded = false; if (!HasExpansion_cstr && expanded_cstr) { if (strcmp(expanded_cstr,"1") == 0) { expanded = true; } } - ViewProvider* pObj = getViewProviderByName(name_cstr); - if (pObj) - pObj->Restore(docReader,prev_ViewProviderDOM); - + if (pObj){ + pObj->Restore(*docReader,prev_ViewProviderDOM); + } if (pObj && expanded) { auto vp = static_cast(pObj); this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); } - } - for (int i=1; iFindNextElement(prev_ViewProviderDOM,"ViewProvider"); + if(ViewProviderDOM_i){ + const char* name_cstr_i = docReader->GetAttribute(ViewProviderDOM_i,"name"); + const char* expanded_cstr_i = docReader->GetAttribute(ViewProviderDOM_i,"expanded"); + bool expanded = false; + if (!HasExpansion_cstr && expanded_cstr_i) { + if (strcmp(expanded_cstr_i,"1") == 0) { + expanded = true; + } } + ViewProvider* pObj = getViewProviderByName(name_cstr_i); + if (pObj){ + pObj->Restore(*docReader,ViewProviderDOM_i); + } + + if (pObj && expanded) { + auto vp = static_cast(pObj); + this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); + } + prev_ViewProviderDOM = ViewProviderDOM_i; } - ViewProvider* pObj = getViewProviderByName(name_cstr_i); - if (pObj) - pObj->Restore(docReader,ViewProviderDOM_i);//Im still implementing this, which calls ExtensionContainer::Restore. - - if (pObj && expanded) { - auto vp = static_cast(pObj); - this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0); - } - prev_ViewProviderDOM = ViewProviderDOM_i; } + } + + } } // read camera settings - auto CameraDOM = docReader.FindElement("Camera"); + auto CameraDOM = docReader->FindElement("Camera"); if(CameraDOM){ - const char* ppReturn = docReader.GetAttribute(CameraDOM,"settings"); + const char* ppReturn = docReader->GetAttribute(CameraDOM,"settings"); cameraSettings.clear(); if(ppReturn && ppReturn[0]) { - saveCameraSettings(ppReturn); - try { - const char** pReturnIgnore=nullptr; - std::list mdi = getMDIViews(); - for (const auto & it : mdi) { - if (it->onHasMsg("SetCamera")) - it->onMsg(cameraSettings.c_str(), pReturnIgnore); - } - } - catch (const Base::Exception& e) { - Base::Console().Error("%s\n", e.what()); - } - } + saveCameraSettings(ppReturn); + try { + const char** pReturnIgnore=nullptr; + std::list mdi = getMDIViews(); + for (const auto & it : mdi) { + if (it->onHasMsg("SetCamera")) + it->onMsg(cameraSettings.c_str(), pReturnIgnore); + } + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + } + } + + auto ProjectUnitSysDOM = docReader->FindElement("ProjectUnitSystem"); + if(ProjectUnitSysDOM){ + const char* US_cstr = docReader->GetAttribute(ProjectUnitSysDOM,"US"); + const char* ignore_cstr = docReader->GetAttribute(ProjectUnitSysDOM,"ignore"); + + d->projectUnitSystem = docReader->ContentToInt( US_cstr ); + d->projectUnitSystemIgnore = docReader->ContentToInt( ignore_cstr ); } - - /* - try{//if this fails then all other reading attemps will fail, since XERCES doesnt allow to get back to previous point, reading the file should restarted each time an element its not present, since it looks for it untill the end of the document. - //Since ProjectUnitSystem its the only optional field, and its being read at the end of this function, it does not cause any issue, but if other optional its added the way of reading XML used in Reader.cpp will be obsolete - - localreader->readElement("ProjectUnitSystem"); - Base::Console().Error("readElement(ProjectUnitSystem)\n"); - int US = localreader->getAttributeAsInteger("US"); - int ignore = localreader->getAttributeAsInteger("ignore"); - d->projectUnitSystem = US; - d->projectUnitSystemIgnore = ignore; - - }catch (const Base::XMLParseException& e) { - Base::Console().Warning("ProjectUnitSystem not found: %s\n", e.getMessage().c_str()); - }catch(const Base::XMLBaseException& e){ - Base::Console().Warning("ProjectUnitSystem XMLBaseException: %s\n", e.getMessage().c_str()); - }catch(...) { - Base::Console().Error("ProjectUnitSystem catch(...)\n"); - } - */ - } - /* - - try{ - localreader->readEndElement("Document"); - }catch(const Base::XMLParseException& e){ - Base::Console().Warning("readEndElement(Document) XMLParseException: %s\n", e.getMessage().c_str()); - }catch(const Base::XMLBaseException& e){ - Base::Console().Warning("readEndElement(Document) XMLBaseException: %s\n", e.getMessage().c_str()); - }catch(...) { - Base::Console().Error("readEndElement(Document) unkown error.\n"); } - */ - - // reset modified flag - //dont see what this does: - //reader.initLocalReader(localreader); - setModified(false); + reader.initLocalDocReader(docReader); } void Document::slotStartRestoreDocument(const App::Document& doc) diff --git a/src/Gui/Document.h b/src/Gui/Document.h index f7fdad5ebd..5eff465959 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -158,6 +158,8 @@ public: void SaveDocFile (Base::Writer &writer) const override; /// This method is used to restore large amounts of data from a binary file. void RestoreDocFile(Base::Reader &reader) override; + void readUsing_XMLReader(Base::Reader &reader); + void readUsing_DocumentReader(Base::Reader &reader); void exportObjects(const std::vector&, Base::Writer&); void importObjects(const std::vector&, Base::Reader&, const std::map& nameMapping); diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 54b7d5b2f6..0e255c1a19 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -354,17 +354,29 @@ public: } void restore(Base::DocumentReader& reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *expandEl) { - Base::Console().Error("ExpandInfo restore\n"); const char* count_cstr = reader.GetAttribute(expandEl,"count"); if(count_cstr){ long count = reader.ContentToInt( count_cstr ); - Base::Console().Error("ExpandInfo count: %d\n",count); - auto _expandEl = reader.FindElement(expandEl,"Expand"); - const char* name_cstr = reader.GetAttribute(_expandEl,"name"); - Base::Console().Error("ExpandInfo name_cstr: %s\n",name_cstr); + auto prev_ExpandDOM = reader.FindElement(expandEl,"Expand"); + const char* name_cstr = reader.GetAttribute(prev_ExpandDOM,"name"); + const char* _count_cstr = reader.GetAttribute(prev_ExpandDOM,"count"); auto& entry = (*this)[name_cstr]; - entry.reset(new ExpandInfo); - entry->restore(reader,_expandEl); + if(_count_cstr){ + entry.reset(new ExpandInfo); + entry->restore(reader,prev_ExpandDOM); + } + + for (int i = 1; i < count; ++i) { + auto ExpandDOM_i = reader.FindNextElement(prev_ExpandDOM,"Expand"); + const char* name_cstr = reader.GetAttribute(ExpandDOM_i,"name"); + const char* _count_cstr = reader.GetAttribute(ExpandDOM_i,"count"); + auto& entry = (*this)[name_cstr]; + if(_count_cstr){ + entry.reset(new ExpandInfo); + entry->restore(reader,ExpandDOM_i); + } + prev_ExpandDOM = ExpandDOM_i; + } } } }; @@ -3947,19 +3959,16 @@ void DocumentItem::Restore(Base::XMLReader& reader) { } void DocumentItem::Restore(Base::DocumentReader& reader) { - Base::Console().Error("DocumentItem::Restore() DocumentReader\n"); auto expandEl = reader.FindElement("Expand"); if( !reader.GetAttribute(expandEl,"count") ) return; _ExpandInfo.reset(new ExpandInfo); _ExpandInfo->restore(reader,expandEl); - //TODO NOW for (auto inst : TreeWidget::Instances) { if (inst != getTree()) { auto docItem = inst->getDocumentItem(document()); if (docItem) docItem->_ExpandInfo = _ExpandInfo; - } } } From f8bd862d48bdccb34a1269728817691191e53249 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Mon, 3 Jul 2023 02:22:14 -0300 Subject: [PATCH 07/25] added define _strdup for Windows --- src/Base/DocumentReader.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Base/DocumentReader.cpp b/src/Base/DocumentReader.cpp index 4160b2e6a0..42b1ed7a03 100644 --- a/src/Base/DocumentReader.cpp +++ b/src/Base/DocumentReader.cpp @@ -39,6 +39,10 @@ # include #endif +#ifdef _MSC_VER +# define strdup _strdup +#endif + XERCES_CPP_NAMESPACE_USE //using namespace std; From dae3d4f6902f697a2a1b4bf78c74dd1fb40bbede Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Wed, 9 Aug 2023 02:19:26 -0300 Subject: [PATCH 08/25] fixed class name --- src/Gui/PreferencePages/DlgSettingsGeneral.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp index 44e530e6ce..fbf509c3b1 100644 --- a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp +++ b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp @@ -612,7 +612,7 @@ void DlgSettingsGeneral::onUnitSystemIndexChanged(int index) } } -void DlgGeneralImp::on_checkBox_projectUnitSystemIgnore_stateChanged(int state) +void DlgSettingsGeneral::on_checkBox_projectUnitSystemIgnore_stateChanged(int state) { if (state < 0) return; // happens when clearing the combo box in retranslateUi() From 704a5bd10a154f20a50a8480ec698d60224cfcfd Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Tue, 29 Aug 2023 14:41:58 -0300 Subject: [PATCH 09/25] Fixed working with tests --- src/App/ExtensionContainer.cpp | 4 +- src/App/PropertyGeo.cpp | 21 ++++ src/App/PropertyGeo.h | 3 +- src/App/PropertyPythonObject.cpp | 118 ++++++++++++++++++ src/App/PropertyPythonObject.h | 2 + src/Base/DocumentReader.cpp | 26 +++- src/Base/DocumentReader.h | 9 ++ src/Base/Persistence.cpp | 6 + .../Sketcher/Gui/PropertyVisualLayerList.cpp | 30 +++++ .../Sketcher/Gui/PropertyVisualLayerList.h | 1 + src/Mod/Sketcher/Gui/VisualLayer.cpp | 20 +++ src/Mod/Sketcher/Gui/VisualLayer.h | 1 + 12 files changed, 234 insertions(+), 7 deletions(-) diff --git a/src/App/ExtensionContainer.cpp b/src/App/ExtensionContainer.cpp index fdcd5a14b8..88aaca16f3 100644 --- a/src/App/ExtensionContainer.cpp +++ b/src/App/ExtensionContainer.cpp @@ -418,9 +418,9 @@ void ExtensionContainer::readExtension(Base::DocumentReader &reader,XERCES_CPP_N throw Base::TypeError(str.str()); } ext->initExtension(this); - if( strcmp(ext->getExtensionTypeId().getName(), type_cstr) == 0 ) - ext->extensionRestore(reader); } + if (ext && strcmp(ext->getExtensionTypeId().getName(), type_cstr) == 0) + ext->extensionRestore(reader); } catch (const Base::XMLParseException&) { throw; // re-throw diff --git a/src/App/PropertyGeo.cpp b/src/App/PropertyGeo.cpp index 7fb82d88c8..9bccd9847e 100644 --- a/src/App/PropertyGeo.cpp +++ b/src/App/PropertyGeo.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ #include "Placement.h" #include "ObjectIdentifier.h" +#include using namespace App; using namespace Base; @@ -152,6 +154,25 @@ void PropertyVector::Restore(Base::XMLReader &reader) hasSetValue(); } +void PropertyVector::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + // read my Element + auto PropertyVectorDOM = reader.FindElement(ContainerDOM,"PropertyVector"); + if(PropertyVectorDOM){ + // get the value of my Attribute + const char* valueX_cstr = reader.GetAttribute(PropertyVectorDOM,"valueX"); + const char* valueY_cstr = reader.GetAttribute(PropertyVectorDOM,"valueY"); + const char* valueZ_cstr = reader.GetAttribute(PropertyVectorDOM,"valueZ"); + if(valueX_cstr || valueY_cstr || valueZ_cstr){ + aboutToSetValue(); + _cVec.x = reader.ContentToFloat(valueX_cstr); + _cVec.y = reader.ContentToFloat(valueY_cstr); + _cVec.z = reader.ContentToFloat(valueZ_cstr); + hasSetValue(); + } + } +} + Property *PropertyVector::Copy() const { diff --git a/src/App/PropertyGeo.h b/src/App/PropertyGeo.h index 62d1f1299c..9e17db026e 100644 --- a/src/App/PropertyGeo.h +++ b/src/App/PropertyGeo.h @@ -89,6 +89,7 @@ public: void Save (Base::Writer &writer) const override; void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) override; Property *Copy() const override; void Paste(const Property &from) override; @@ -273,7 +274,7 @@ public: void setPyObject(PyObject *) override; void Save (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; + void Restore(Base::XMLReader &reader) override; Property *Copy() const override; void Paste(const Property &from) override; diff --git a/src/App/PropertyPythonObject.cpp b/src/App/PropertyPythonObject.cpp index 4fa12a9ba9..00618b8c12 100644 --- a/src/App/PropertyPythonObject.cpp +++ b/src/App/PropertyPythonObject.cpp @@ -30,8 +30,13 @@ #include #include #include +#include #include +//#ifndef _PreComp_ +//# include +//#endif + #include "PropertyPythonObject.h" #include "DocumentObject.h" @@ -264,6 +269,37 @@ void PropertyPythonObject::restoreObject(Base::XMLReader &reader) } } +void PropertyPythonObject::restoreObject(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + Base::PyGILStateLocker lock; + try { + PropertyContainer* parent = this->getContainer(); + const char* object_cstr = reader.GetAttribute(ContainerDOM,"object"); + if (object_cstr) { + if (strcmp(object_cstr,"yes") == 0) { + Py::Object obj = Py::asObject(parent->getPyObject()); + this->object.setAttr("__object__", obj); + } + } + const char* vobject_cstr = reader.GetAttribute(ContainerDOM,"vobject"); + if (vobject_cstr) { + if (strcmp(vobject_cstr,"yes") == 0) { + Py::Object obj = Py::asObject(parent->getPyObject()); + this->object.setAttr("__vobject__", obj); + } + } + } + catch (Py::Exception& e) { + e.clear(); + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n",e.what()); + } + catch (...) { + Base::Console().Error("Critical error in PropertyPythonObject::restoreObject\n"); + } +} + void PropertyPythonObject::Save (Base::Writer &writer) const { //if (writer.isForceXML()) { @@ -381,6 +417,88 @@ void PropertyPythonObject::Restore(Base::XMLReader &reader) } } +void PropertyPythonObject::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + auto PythonDOM = reader.FindElement(ContainerDOM,"Python"); + if(PythonDOM){ + const char* file_cstr = reader.GetAttribute(PythonDOM,"file"); + if (file_cstr){ + reader.addFile(file_cstr,this); + }else{ + bool load_json=false; + bool load_pickle=false; + bool load_failed=false; + const char* value_cstr = reader.GetAttribute(PythonDOM,"value"); + const char* encoded_cstr = reader.GetAttribute(PythonDOM,"encoded"); + std::string buffer = value_cstr; + if (encoded_cstr && strcmp(encoded_cstr,"yes") == 0) { + buffer = Base::base64_decode(buffer); + }else { + buffer = decodeValue(buffer); + } + Base::PyGILStateLocker lock; + try { + boost::regex pickle(R"(^\(i(\w+)\n(\w+)\n)"); + boost::match_results what; + std::string::const_iterator start, end; + start = buffer.begin(); + end = buffer.end(); + + const char* module_cstr = reader.GetAttribute(PythonDOM,"module"); + const char* class_cstr = reader.GetAttribute(PythonDOM,"class"); + const char* json_cstr = reader.GetAttribute(PythonDOM,"json"); + if (module_cstr && class_cstr) { + Py::Module mod(PyImport_ImportModule(module_cstr),true); + if (mod.isNull()) + throw Py::Exception(); + PyObject* cls = mod.getAttr(class_cstr).ptr(); + if (!cls) { + std::stringstream s; + s << "Module " << module_cstr + << " has no class " << class_cstr; + throw Py::AttributeError(s.str()); + } + if (PyType_Check(cls)) { + this->object = PyType_GenericAlloc((PyTypeObject*)cls, 0); + } + else { + throw Py::TypeError("neither class nor type object"); + } + load_json = true; + } + else if (boost::regex_search(start, end, what, pickle)) { + std::string name = std::string(what[1].first, what[1].second); + std::string type = std::string(what[2].first, what[2].second); + Py::Module mod(PyImport_ImportModule(name.c_str()),true); + if (mod.isNull()) + throw Py::Exception(); + this->object = PyObject_CallObject(mod.getAttr(type).ptr(), nullptr); + load_pickle = true; + buffer = std::string(what[2].second, end); + } + else if (json_cstr) { + load_json = true; + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + this->object = Py::None(); + load_failed = true; + } + aboutToSetValue(); + if (load_json) + this->fromString(buffer); + else if (load_pickle) + this->loadPickle(buffer); + else if (!load_failed) + Base::Console().Warning("PropertyPythonObject::Restore: unsupported serialisation: %s\n", buffer.c_str()); + restoreObject(reader,PythonDOM); + hasSetValue(); + } + } +} + void PropertyPythonObject::SaveDocFile (Base::Writer &writer) const { std::string buffer = this->toString(); diff --git a/src/App/PropertyPythonObject.h b/src/App/PropertyPythonObject.h index cf1357a234..febdbb255b 100644 --- a/src/App/PropertyPythonObject.h +++ b/src/App/PropertyPythonObject.h @@ -60,6 +60,7 @@ public: void Save (Base::Writer &writer) const override; /** Use Python's pickle module to restore the object */ void Restore(Base::XMLReader &reader) override; + void Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) override; void SaveDocFile (Base::Writer &writer) const override; void RestoreDocFile(Base::Reader &reader) override; @@ -73,6 +74,7 @@ public: private: void saveObject(Base::Writer &writer) const; void restoreObject(Base::XMLReader &reader); + void restoreObject(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM); std::string encodeValue(const std::string& str) const; std::string decodeValue(const std::string& str) const; void loadPickle(const std::string& str); diff --git a/src/Base/DocumentReader.cpp b/src/Base/DocumentReader.cpp index 42b1ed7a03..01d18e5275 100644 --- a/src/Base/DocumentReader.cpp +++ b/src/Base/DocumentReader.cpp @@ -34,10 +34,10 @@ #endif #include -#ifndef _PreComp_ -# include -# include -#endif +//#ifndef _PreComp_ +//# include +//# include +//#endif #ifdef _MSC_VER # define strdup _strdup @@ -150,6 +150,24 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(const cha return nullptr; } +XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElementByField( + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* Start, + const char* TypeEl,const char* field_name,const char* field_value) const +{ + if(!TypeEl || !field_name ||!field_value) + return nullptr; + for (DOMNode *clChild = Start; clChild != nullptr; clChild = clChild->getNextSibling()) { + //auto cast = static_cast(clChild); + const char* attr = GetAttribute( static_cast(clChild), field_name ); + if(attr){ + if( !strcmp( attr, field_value ) ){ + return static_cast(clChild);; + } + } + } + return nullptr; +} + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* Start, const char* Type) const { if(!Start || !Type) diff --git a/src/Base/DocumentReader.h b/src/Base/DocumentReader.h index 863fa521de..97afbcf906 100644 --- a/src/Base/DocumentReader.h +++ b/src/Base/DocumentReader.h @@ -32,6 +32,11 @@ //#include "FileInfo.h"//remplaced: #include +#ifndef _PreComp_ +# include +# include +#endif + namespace zipios { class ZipInputStream; } @@ -62,6 +67,10 @@ public: XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *GetRootElement() const; XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* Start, const char* Type) const; XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElement(const char* Type) const; + + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElementByField(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* Start, + const char* TypeEl,const char* field_name, const char* field_value) const; + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const; static long ContentToASCII(const char* Content); diff --git a/src/Base/Persistence.cpp b/src/Base/Persistence.cpp index 73e6c2a9f2..de0a1cb240 100644 --- a/src/Base/Persistence.cpp +++ b/src/Base/Persistence.cpp @@ -65,12 +65,18 @@ void Persistence::Save (Writer &/*writer*/) const assert(0); } + void Persistence::Restore(DocumentReader &/*reader*/) { + // you have to implement this method in all descending classes! + assert(0); } + void Persistence::Restore(DocumentReader &/*reader*/,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement */*containerEl*/) { + // you have to implement this method in all descending classes! + assert(0); } void Persistence::Restore(XMLReader &/*reader*/) diff --git a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp index 2f35d2b9f2..16536a9b4e 100644 --- a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp +++ b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "PropertyVisualLayerList.h" @@ -91,6 +92,35 @@ void PropertyVisualLayerList::Restore(Base::XMLReader& reader) setValues(std::move(layers)); } +void PropertyVisualLayerList::Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) +{ + auto Prop_VisualLayerListDOM = reader.FindElementByField(containerEl,"Property","name","VisualLayerList"); + if(Prop_VisualLayerListDOM){ + auto VisualLayerListDOM = reader.FindElement(Prop_VisualLayerListDOM,"VisualLayerList"); + const char* count_cstr = reader.GetAttribute(VisualLayerListDOM,"count"); + if(count_cstr){ + int count = reader.ContentToInt( count_cstr ); + std::vector layers; + layers.reserve(count); + + auto prev_VisualLayerDOM = reader.FindElement(VisualLayerListDOM,"VisualLayer"); + VisualLayer visualLayer; + visualLayer.Restore(reader,prev_VisualLayerDOM); + layers.push_back(std::move(visualLayer)); + for (int i = 1; i < count; i++) { + auto VisualLayerDOM_i = reader.FindNextElement(prev_VisualLayerDOM,"VisualLayer"); + VisualLayer visualLayer; + visualLayer.Restore(reader,VisualLayerDOM_i); + layers.push_back(std::move(visualLayer)); + prev_VisualLayerDOM = VisualLayerDOM_i; + } + + setValues(std::move(layers)); + } + + } +} + Property* PropertyVisualLayerList::Copy() const { PropertyVisualLayerList* p = new PropertyVisualLayerList(); diff --git a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h index dcbb05c2c8..f03112a8fb 100644 --- a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h +++ b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h @@ -61,6 +61,7 @@ public: void Save(Base::Writer& writer) const override; void Restore(Base::XMLReader& reader) override; + void Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) override; Property* Copy() const override; void Paste(const Property& from) override; diff --git a/src/Mod/Sketcher/Gui/VisualLayer.cpp b/src/Mod/Sketcher/Gui/VisualLayer.cpp index f44acb4719..b3e58bff59 100644 --- a/src/Mod/Sketcher/Gui/VisualLayer.cpp +++ b/src/Mod/Sketcher/Gui/VisualLayer.cpp @@ -22,8 +22,10 @@ #include "PreCompiled.h" +#include #include #include +#include #include "VisualLayer.h" @@ -86,3 +88,21 @@ void VisualLayer::Restore(Base::XMLReader& reader) linePattern = reader.getAttributeAsUnsigned("linePattern"); lineWidth = reader.getAttributeAsFloat("lineWidth"); } + +void VisualLayer::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +{ + const char* visible_cstr = reader.GetAttribute(ContainerDOM,"visible"); + if(visible_cstr){ + std::string str = visible_cstr; + visible = (str == "true"); + + const char* linePattern_cstr = reader.GetAttribute(ContainerDOM,"linePattern"); + const char* lineWidth_cstr = reader.GetAttribute(ContainerDOM,"lineWidth"); + if(linePattern_cstr && lineWidth_cstr){ + linePattern = reader.ContentToUnsigned( linePattern_cstr ); + lineWidth = reader.ContentToUnsigned( lineWidth_cstr ); + } + + + } +} diff --git a/src/Mod/Sketcher/Gui/VisualLayer.h b/src/Mod/Sketcher/Gui/VisualLayer.h index 587a835ddd..71dc2ce006 100644 --- a/src/Mod/Sketcher/Gui/VisualLayer.h +++ b/src/Mod/Sketcher/Gui/VisualLayer.h @@ -51,6 +51,7 @@ public: void Save(Base::Writer& /*writer*/) const; void Restore(Base::XMLReader& /*reader*/); + void Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl); private: unsigned int linePattern; From eebf7517517318b4cde72213be386f239bf72499 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Wed, 30 Aug 2023 17:59:41 -0300 Subject: [PATCH 10/25] fix merge --- src/Base/Parameter.cpp | 15 +++------------ src/Base/Parameter.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index b35be01f32..284dbedc5f 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -64,23 +64,14 @@ using namespace Base; //************************************************************************** //************************************************************************** // private classes declaration: -// - DOMTreeErrorReporter // - StrX // - DOMPrintFilter // - DOMPrintErrorHandler // - XStr //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - -class DOMTreeErrorReporter : public ErrorHandler -{ -public: - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - DOMTreeErrorReporter() : - fSawErrors(false) { - } +DOMTreeErrorReporter::DOMTreeErrorReporter(): + fSawErrors(false) { +} void DOMTreeErrorReporter::warning(const SAXParseException&) { diff --git a/src/Base/Parameter.h b/src/Base/Parameter.h index c9adbce0cd..2c9ba62f86 100644 --- a/src/Base/Parameter.h +++ b/src/Base/Parameter.h @@ -430,6 +430,39 @@ private: ~ParameterManager() override; }; +XERCES_CPP_NAMESPACE_USE + +class DOMTreeErrorReporter : public ErrorHandler +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + DOMTreeErrorReporter(); + ~DOMTreeErrorReporter() override = default; + // ----------------------------------------------------------------------- + // Implementation of the error handler interface + // ----------------------------------------------------------------------- + void warning(const SAXParseException& toCatch) override; + void error(const SAXParseException& toCatch) override; + void fatalError(const SAXParseException& toCatch) override; + void resetErrors() override; + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool getSawErrors() const; +private: + // ----------------------------------------------------------------------- + // Private data members + // + // fSawErrors + // This is set if we get any errors, and is queryable via a getter + // method. Its used by the main code to suppress output if there are + // errors. + // ----------------------------------------------------------------------- + bool fSawErrors; +}; + /** python wrapper function */ From 9f9b3a5af148abb5b269114ceb8e784a7a9e47f2 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Thu, 31 Aug 2023 01:03:51 -0300 Subject: [PATCH 11/25] fix parameter --- src/Base/DocumentReader.h | 2 +- src/Base/Parameter.cpp | 1 - src/Base/Parameter.h | 14 ++++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Base/DocumentReader.h b/src/Base/DocumentReader.h index 97afbcf906..4fdcc59193 100644 --- a/src/Base/DocumentReader.h +++ b/src/Base/DocumentReader.h @@ -28,7 +28,7 @@ #include #include #include -#include +//#include //#include "FileInfo.h"//remplaced: #include diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 284dbedc5f..b650f63f21 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -33,7 +33,6 @@ # include # include # include -# include # include # include # include diff --git a/src/Base/Parameter.h b/src/Base/Parameter.h index 2c9ba62f86..e3c2342ec5 100644 --- a/src/Base/Parameter.h +++ b/src/Base/Parameter.h @@ -57,6 +57,14 @@ using PyObject = struct _object; #include "Handle.h" #include "Observer.h" + + +#ifndef _PreComp_ +//# include +# include +#endif + + #ifdef _MSC_VER # pragma warning( disable : 4251 ) # pragma warning( disable : 4503 ) @@ -65,11 +73,6 @@ using PyObject = struct _object; # pragma warning( disable : 4275 ) #endif -#ifndef _PreComp_ -# include -#endif - - XERCES_CPP_NAMESPACE_BEGIN class DOMNode; class DOMElement; @@ -439,7 +442,6 @@ public: // Constructors and Destructor // ----------------------------------------------------------------------- DOMTreeErrorReporter(); - ~DOMTreeErrorReporter() override = default; // ----------------------------------------------------------------------- // Implementation of the error handler interface // ----------------------------------------------------------------------- From ccc4d6033b920848decc65451843f1f82bae4e9e Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Thu, 31 Aug 2023 12:38:31 -0300 Subject: [PATCH 12/25] Trying to solve header issues in windows. --- src/Base/DocumentReader.cpp | 10 ++++++---- src/Base/DocumentReader.h | 15 ++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Base/DocumentReader.cpp b/src/Base/DocumentReader.cpp index 01d18e5275..b4245d58eb 100644 --- a/src/Base/DocumentReader.cpp +++ b/src/Base/DocumentReader.cpp @@ -34,10 +34,12 @@ #endif #include -//#ifndef _PreComp_ +#ifndef _PreComp_ //# include -//# include -//#endif +# include +# include +# include +#endif #ifdef _MSC_VER # define strdup _strdup @@ -182,7 +184,7 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindElement(XERCES_CP return nullptr; } -XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const +XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *DocumentReader::FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *Prev, const char* Type) const { if (!Prev || !Type) return nullptr; diff --git a/src/Base/DocumentReader.h b/src/Base/DocumentReader.h index 4fdcc59193..ff7d6b14ce 100644 --- a/src/Base/DocumentReader.h +++ b/src/Base/DocumentReader.h @@ -28,14 +28,15 @@ #include #include #include -//#include -//#include "FileInfo.h"//remplaced: #include -#ifndef _PreComp_ -# include -# include -#endif +//#ifndef _PreComp_ +//# include +//# include +//#endif + + +#include namespace zipios { class ZipInputStream; @@ -71,7 +72,7 @@ public: XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElementByField(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* Start, const char* TypeEl,const char* field_name, const char* field_value) const; - XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const; + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *Prev, const char* Type) const; static long ContentToASCII(const char* Content); From 93679b272942eb14e7ed19a48785acc1d55506c8 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Fri, 8 Sep 2023 09:12:52 -0300 Subject: [PATCH 13/25] Fix DOMDocument redefinition error --- src/Base/DocumentReader.cpp | 1 + src/Base/DocumentReader.h | 8 -------- src/Base/Parameter.h | 9 +-------- src/Base/XMLTools.cpp | 10 ++++------ src/Base/XMLTools.h | 20 +++++++------------ src/Main/MainGui.cpp | 8 ++++++-- src/Main/MainPy.cpp | 6 ++++-- src/Mod/Inspection/Gui/Command.cpp | 4 ++-- .../Inspection/Gui/ViewProviderInspection.cpp | 4 +++- src/Mod/Points/Gui/Command.cpp | 5 +++-- src/Mod/Points/Gui/ViewProvider.cpp | 3 ++- src/Mod/Sandbox/Gui/PreCompiled.h | 8 ++++---- .../Gui/ViewProviderSpreadsheet.cpp | 3 ++- src/Tools/_TEMPLATE_/Gui/PreCompiled.h | 8 +++++--- 14 files changed, 44 insertions(+), 53 deletions(-) diff --git a/src/Base/DocumentReader.cpp b/src/Base/DocumentReader.cpp index b4245d58eb..b91c0e5b1f 100644 --- a/src/Base/DocumentReader.cpp +++ b/src/Base/DocumentReader.cpp @@ -19,6 +19,7 @@ * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ +#include "PreCompiled.h" #include "DocumentReader.h" #include "InputSource.h" #include "XMLTools.h" diff --git a/src/Base/DocumentReader.h b/src/Base/DocumentReader.h index ff7d6b14ce..cf9bf4e71e 100644 --- a/src/Base/DocumentReader.h +++ b/src/Base/DocumentReader.h @@ -30,12 +30,6 @@ #include #include -//#ifndef _PreComp_ -//# include -//# include -//#endif - - #include namespace zipios { @@ -45,8 +39,6 @@ class ZipInputStream; XERCES_CPP_NAMESPACE_BEGIN class DOMNode; class DOMElement; -// class DefaultHandler; -// class SAX2XMLReader; XERCES_CPP_NAMESPACE_END namespace Base { diff --git a/src/Base/Parameter.h b/src/Base/Parameter.h index e3c2342ec5..f27c3b02cb 100644 --- a/src/Base/Parameter.h +++ b/src/Base/Parameter.h @@ -53,18 +53,11 @@ using PyObject = struct _object; #include #include #include +#include #include "Handle.h" #include "Observer.h" - - -#ifndef _PreComp_ -//# include -# include -#endif - - #ifdef _MSC_VER # pragma warning( disable : 4251 ) # pragma warning( disable : 4503 ) diff --git a/src/Base/XMLTools.cpp b/src/Base/XMLTools.cpp index fb0fda11e7..fb492c062d 100644 --- a/src/Base/XMLTools.cpp +++ b/src/Base/XMLTools.cpp @@ -26,15 +26,15 @@ #include "XMLTools.h" using namespace Base; +XERCES_CPP_NAMESPACE_USE -std::unique_ptr XMLTools::transcoder; +std::unique_ptr XMLTools::transcoder; void XMLTools::initialize() { - XERCES_CPP_NAMESPACE_USE; if (!transcoder.get()) { XMLTransService::Codes res{}; - transcoder.reset(XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgTransService->makeNewTranscoderFor(XERCES_CPP_NAMESPACE_QUALIFIER XMLRecognizer::UTF_8, res, 4096, XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager)); + transcoder.reset(XMLPlatformUtils::fgTransService->makeNewTranscoderFor(XMLRecognizer::UTF_8, res, 4096, XMLPlatformUtils::fgMemoryManager)); if (res != XMLTransService::Ok) throw Base::UnicodeError("Can\'t create transcoder"); } @@ -44,7 +44,6 @@ std::string XMLTools::toStdString(const XMLCh* const toTranscode) { std::string str; - XERCES_CPP_NAMESPACE_USE; initialize(); //char outBuff[128]; @@ -74,8 +73,7 @@ std::basic_string XMLTools::toXMLString(const char* const fromTranscode) std::basic_string str; if (!fromTranscode) return str; - - XERCES_CPP_NAMESPACE_USE; + initialize(); static XMLCh outBuff[128]; diff --git a/src/Base/XMLTools.h b/src/Base/XMLTools.h index d0dc66c876..e5f537b2f2 100644 --- a/src/Base/XMLTools.h +++ b/src/Base/XMLTools.h @@ -28,16 +28,10 @@ #include #include #include +#include #include - - -XERCES_CPP_NAMESPACE_BEGIN - class DOMNode; - class DOMElement; - class DOMDocument; -XERCES_CPP_NAMESPACE_END - +XERCES_CPP_NAMESPACE_USE // Helper class class BaseExport XMLTools { @@ -48,7 +42,7 @@ public: static void terminate(); private: - static std::unique_ptr transcoder; + static std::unique_ptr transcoder; }; //************************************************************************** @@ -79,12 +73,12 @@ inline std::ostream& operator<<(std::ostream& target, const StrX& toDump) inline StrX::StrX(const XMLCh* const toTranscode) { // Call the private transcoding method - fLocalForm = XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(toTranscode); + fLocalForm = XMLString::transcode(toTranscode); } inline StrX::~StrX() { - XERCES_CPP_NAMESPACE_QUALIFIER XMLString::release(&fLocalForm); + XMLString::release(&fLocalForm); } @@ -158,12 +152,12 @@ private : inline XStr::XStr(const char* const toTranscode) { - fUnicodeForm = XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(toTranscode); + fUnicodeForm = XMLString::transcode(toTranscode); } inline XStr::~XStr() { - XERCES_CPP_NAMESPACE_QUALIFIER XMLString::release(&fUnicodeForm); + XMLString::release(&fUnicodeForm); } diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp index b405a07832..48ae847ef4 100644 --- a/src/Main/MainGui.cpp +++ b/src/Main/MainGui.cpp @@ -23,6 +23,12 @@ #include +#if defined(_MSC_VER) +#include +#include +#endif + + #ifdef _PreComp_ # undef _PreComp_ #endif @@ -305,8 +311,6 @@ int main( int argc, char ** argv ) } #if defined(_MSC_VER) -#include -#include typedef BOOL (__stdcall *tMDWD)( IN HANDLE hProcess, diff --git a/src/Main/MainPy.cpp b/src/Main/MainPy.cpp index e202653592..83ccf0fe36 100644 --- a/src/Main/MainPy.cpp +++ b/src/Main/MainPy.cpp @@ -27,6 +27,10 @@ # undef _PreComp_ #endif +#if defined(FC_OS_WIN32) +# include +#endif + #if defined(FC_OS_LINUX) || defined(FC_OS_BSD) # include #endif @@ -52,9 +56,7 @@ #include #include - #if defined(FC_OS_WIN32) -# include /** DllMain is called when DLL is loaded */ diff --git a/src/Mod/Inspection/Gui/Command.cpp b/src/Mod/Inspection/Gui/Command.cpp index 659d8a63cf..e7d0f0c255 100644 --- a/src/Mod/Inspection/Gui/Command.cpp +++ b/src/Mod/Inspection/Gui/Command.cpp @@ -24,6 +24,8 @@ #ifndef _PreComp_ # include #endif +#include +#include #include #include @@ -31,8 +33,6 @@ #include #include #include -#include -#include #include #include "VisualInspection.h" diff --git a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp index e62b62bc6d..ebe105c7df 100644 --- a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp +++ b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp @@ -46,13 +46,15 @@ # include #endif +#include + #include #include #include #include #include #include -#include + #include #include #include diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index 98b3bb5800..4525f2ddfd 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -26,6 +26,8 @@ # include # include #endif +#include +#include #include #include @@ -39,8 +41,7 @@ #include #include #include -#include -#include + #include #include diff --git a/src/Mod/Points/Gui/ViewProvider.cpp b/src/Mod/Points/Gui/ViewProvider.cpp index e9fa723855..eec2a03c5f 100644 --- a/src/Mod/Points/Gui/ViewProvider.cpp +++ b/src/Mod/Points/Gui/ViewProvider.cpp @@ -36,13 +36,14 @@ # include # include #endif +#include #include #include #include #include #include -#include + #include #include diff --git a/src/Mod/Sandbox/Gui/PreCompiled.h b/src/Mod/Sandbox/Gui/PreCompiled.h index f8a4715690..7f913bc123 100644 --- a/src/Mod/Sandbox/Gui/PreCompiled.h +++ b/src/Mod/Sandbox/Gui/PreCompiled.h @@ -26,6 +26,10 @@ #include +#ifdef FC_OS_WIN32 +# include +#endif + // Importing of App classes #ifdef FC_OS_WIN32 # define SandboxAppExport __declspec(dllimport) @@ -62,10 +66,6 @@ // Xerces #include -#ifdef FC_OS_WIN32 -# include -#endif - // Qt Toolkit #include #include diff --git a/src/Mod/Spreadsheet/Gui/ViewProviderSpreadsheet.cpp b/src/Mod/Spreadsheet/Gui/ViewProviderSpreadsheet.cpp index 4d9d70378f..b8dfebee15 100644 --- a/src/Mod/Spreadsheet/Gui/ViewProviderSpreadsheet.cpp +++ b/src/Mod/Spreadsheet/Gui/ViewProviderSpreadsheet.cpp @@ -29,11 +29,12 @@ # include #endif +#include + #include #include #include #include -#include #include #include "ViewProviderSpreadsheet.h" diff --git a/src/Tools/_TEMPLATE_/Gui/PreCompiled.h b/src/Tools/_TEMPLATE_/Gui/PreCompiled.h index af3161df95..44a5c54fc8 100644 --- a/src/Tools/_TEMPLATE_/Gui/PreCompiled.h +++ b/src/Tools/_TEMPLATE_/Gui/PreCompiled.h @@ -26,6 +26,10 @@ #include +#ifdef FC_OS_WIN32 +#include +#endif + // Importing of App classes #ifdef FC_OS_WIN32 #define _TEMPLATE_AppExport __declspec(dllimport) @@ -56,9 +60,7 @@ // Xerces #include -#ifdef FC_OS_WIN32 -#include -#endif + // Qt Toolkit #ifndef __QtAll__ From e64c5ee399e7e325ebcfa6e1c0225f36528d94c1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 8 Sep 2023 12:13:32 +0000 Subject: [PATCH 14/25] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../Sketcher/Gui/PropertyVisualLayerList.cpp | 55 ++++++++++--------- .../Sketcher/Gui/PropertyVisualLayerList.h | 3 +- src/Mod/Sketcher/Gui/VisualLayer.cpp | 31 +++++------ src/Mod/Sketcher/Gui/VisualLayer.h | 3 +- src/Tools/_TEMPLATE_/Gui/PreCompiled.h | 1 - 5 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp index 16536a9b4e..162e5d56e8 100644 --- a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp +++ b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.cpp @@ -23,10 +23,10 @@ #include "PreCompiled.h" #include +#include #include #include #include -#include #include "PropertyVisualLayerList.h" @@ -92,33 +92,34 @@ void PropertyVisualLayerList::Restore(Base::XMLReader& reader) setValues(std::move(layers)); } -void PropertyVisualLayerList::Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) +void PropertyVisualLayerList::Restore(Base::DocumentReader& reader, + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* containerEl) { - auto Prop_VisualLayerListDOM = reader.FindElementByField(containerEl,"Property","name","VisualLayerList"); - if(Prop_VisualLayerListDOM){ - auto VisualLayerListDOM = reader.FindElement(Prop_VisualLayerListDOM,"VisualLayerList"); - const char* count_cstr = reader.GetAttribute(VisualLayerListDOM,"count"); - if(count_cstr){ - int count = reader.ContentToInt( count_cstr ); - std::vector layers; - layers.reserve(count); - - auto prev_VisualLayerDOM = reader.FindElement(VisualLayerListDOM,"VisualLayer"); - VisualLayer visualLayer; - visualLayer.Restore(reader,prev_VisualLayerDOM); - layers.push_back(std::move(visualLayer)); - for (int i = 1; i < count; i++) { - auto VisualLayerDOM_i = reader.FindNextElement(prev_VisualLayerDOM,"VisualLayer"); - VisualLayer visualLayer; - visualLayer.Restore(reader,VisualLayerDOM_i); - layers.push_back(std::move(visualLayer)); - prev_VisualLayerDOM = VisualLayerDOM_i; - } - - setValues(std::move(layers)); - } - - } + auto Prop_VisualLayerListDOM = + reader.FindElementByField(containerEl, "Property", "name", "VisualLayerList"); + if (Prop_VisualLayerListDOM) { + auto VisualLayerListDOM = reader.FindElement(Prop_VisualLayerListDOM, "VisualLayerList"); + const char* count_cstr = reader.GetAttribute(VisualLayerListDOM, "count"); + if (count_cstr) { + int count = reader.ContentToInt(count_cstr); + std::vector layers; + layers.reserve(count); + + auto prev_VisualLayerDOM = reader.FindElement(VisualLayerListDOM, "VisualLayer"); + VisualLayer visualLayer; + visualLayer.Restore(reader, prev_VisualLayerDOM); + layers.push_back(std::move(visualLayer)); + for (int i = 1; i < count; i++) { + auto VisualLayerDOM_i = reader.FindNextElement(prev_VisualLayerDOM, "VisualLayer"); + VisualLayer visualLayer; + visualLayer.Restore(reader, VisualLayerDOM_i); + layers.push_back(std::move(visualLayer)); + prev_VisualLayerDOM = VisualLayerDOM_i; + } + + setValues(std::move(layers)); + } + } } Property* PropertyVisualLayerList::Copy() const diff --git a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h index f03112a8fb..0fe2091525 100644 --- a/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h +++ b/src/Mod/Sketcher/Gui/PropertyVisualLayerList.h @@ -61,7 +61,8 @@ public: void Save(Base::Writer& writer) const override; void Restore(Base::XMLReader& reader) override; - void Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl) override; + void Restore(Base::DocumentReader& reader, + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* containerEl) override; Property* Copy() const override; void Paste(const Property& from) override; diff --git a/src/Mod/Sketcher/Gui/VisualLayer.cpp b/src/Mod/Sketcher/Gui/VisualLayer.cpp index b3e58bff59..f2f3a3cd9b 100644 --- a/src/Mod/Sketcher/Gui/VisualLayer.cpp +++ b/src/Mod/Sketcher/Gui/VisualLayer.cpp @@ -23,9 +23,9 @@ #include "PreCompiled.h" #include +#include #include #include -#include #include "VisualLayer.h" @@ -89,20 +89,19 @@ void VisualLayer::Restore(Base::XMLReader& reader) lineWidth = reader.getAttributeAsFloat("lineWidth"); } -void VisualLayer::Restore(Base::DocumentReader &reader,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *ContainerDOM) +void VisualLayer::Restore(Base::DocumentReader& reader, + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* ContainerDOM) { - const char* visible_cstr = reader.GetAttribute(ContainerDOM,"visible"); - if(visible_cstr){ - std::string str = visible_cstr; - visible = (str == "true"); - - const char* linePattern_cstr = reader.GetAttribute(ContainerDOM,"linePattern"); - const char* lineWidth_cstr = reader.GetAttribute(ContainerDOM,"lineWidth"); - if(linePattern_cstr && lineWidth_cstr){ - linePattern = reader.ContentToUnsigned( linePattern_cstr ); - lineWidth = reader.ContentToUnsigned( lineWidth_cstr ); - } - - - } + const char* visible_cstr = reader.GetAttribute(ContainerDOM, "visible"); + if (visible_cstr) { + std::string str = visible_cstr; + visible = (str == "true"); + + const char* linePattern_cstr = reader.GetAttribute(ContainerDOM, "linePattern"); + const char* lineWidth_cstr = reader.GetAttribute(ContainerDOM, "lineWidth"); + if (linePattern_cstr && lineWidth_cstr) { + linePattern = reader.ContentToUnsigned(linePattern_cstr); + lineWidth = reader.ContentToUnsigned(lineWidth_cstr); + } + } } diff --git a/src/Mod/Sketcher/Gui/VisualLayer.h b/src/Mod/Sketcher/Gui/VisualLayer.h index 71dc2ce006..2ab6374647 100644 --- a/src/Mod/Sketcher/Gui/VisualLayer.h +++ b/src/Mod/Sketcher/Gui/VisualLayer.h @@ -51,7 +51,8 @@ public: void Save(Base::Writer& /*writer*/) const; void Restore(Base::XMLReader& /*reader*/); - void Restore(Base::DocumentReader &reader, XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *containerEl); + void Restore(Base::DocumentReader& reader, + XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* containerEl); private: unsigned int linePattern; diff --git a/src/Tools/_TEMPLATE_/Gui/PreCompiled.h b/src/Tools/_TEMPLATE_/Gui/PreCompiled.h index 44a5c54fc8..25852981af 100644 --- a/src/Tools/_TEMPLATE_/Gui/PreCompiled.h +++ b/src/Tools/_TEMPLATE_/Gui/PreCompiled.h @@ -61,7 +61,6 @@ #include - // Qt Toolkit #ifndef __QtAll__ #include From b3a2aa41f295f4258206cbcb69904f2b123a3fa6 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Fri, 8 Sep 2023 21:10:48 -0300 Subject: [PATCH 15/25] Adding temporary compiler option for printing included headers while compiling --- cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake b/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake index 63c471ab33..c67ecce528 100644 --- a/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake +++ b/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake @@ -3,6 +3,7 @@ # https://cmake.org/cmake/help/v3.8/manual/cmake-compile-features.7.html macro(CompilerChecksAndSetups) + set(CMAKE_CXX_FLAGS "/showIncludes ${CMAKE_CXX_FLAGS}") if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") set(CMAKE_COMPILER_IS_CLANGXX TRUE) endif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") From 5fc6726feb17c409381b3bad77ff75079d757d53 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Sat, 9 Sep 2023 04:58:38 -0300 Subject: [PATCH 16/25] fixing DOMDocument redefinition on windows --- src/Mod/Fem/Gui/TaskFemConstraint.cpp | 4 +++- src/Mod/Fem/Gui/TaskPostBoxes.cpp | 6 ++++-- src/Mod/Part/Gui/ViewProviderGridExtension.cpp | 6 ++++-- src/Mod/Path/Gui/AppPathGui.cpp | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Mod/Fem/Gui/TaskFemConstraint.cpp b/src/Mod/Fem/Gui/TaskFemConstraint.cpp index 00d103a0c3..4b07bac81d 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraint.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraint.cpp @@ -32,10 +32,12 @@ # include // OvG conversion between string and int etc. #endif +#include + #include #include #include -#include + #include #include #include diff --git a/src/Mod/Fem/Gui/TaskPostBoxes.cpp b/src/Mod/Fem/Gui/TaskPostBoxes.cpp index e1851748a5..26b7d36f40 100644 --- a/src/Mod/Fem/Gui/TaskPostBoxes.cpp +++ b/src/Mod/Fem/Gui/TaskPostBoxes.cpp @@ -36,6 +36,9 @@ # include #endif +#include +#include + #include #include #include @@ -45,8 +48,7 @@ #include #include #include -#include -#include + #include #include diff --git a/src/Mod/Part/Gui/ViewProviderGridExtension.cpp b/src/Mod/Part/Gui/ViewProviderGridExtension.cpp index ed298adff3..fed8af47ae 100644 --- a/src/Mod/Part/Gui/ViewProviderGridExtension.cpp +++ b/src/Mod/Part/Gui/ViewProviderGridExtension.cpp @@ -38,6 +38,9 @@ # include #endif +#include +#include + #include #include #include @@ -45,8 +48,7 @@ #include #include #include -#include -#include + #include #include diff --git a/src/Mod/Path/Gui/AppPathGui.cpp b/src/Mod/Path/Gui/AppPathGui.cpp index 8b3c0641c2..2f5699c46f 100644 --- a/src/Mod/Path/Gui/AppPathGui.cpp +++ b/src/Mod/Path/Gui/AppPathGui.cpp @@ -25,7 +25,7 @@ #include #include #include -#include + #include #include @@ -34,6 +34,7 @@ #include "ViewProviderPath.h" #include "ViewProviderPathCompound.h" #include "ViewProviderPathShape.h" +#include // use a different name to CreateCommand() From 375df38e7844c7d3231f59e58071224c8a9d74df Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Thu, 14 Sep 2023 03:50:53 -0300 Subject: [PATCH 17/25] fixing DOMDocument redefinition error 2 --- src/Mod/Fem/Gui/Command.cpp | 5 +++-- src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp | 6 ++++-- src/Mod/Sketcher/Gui/AppSketcherGui.cpp | 3 ++- src/Mod/TechDraw/Gui/TaskActiveView.cpp | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index 6e91e2c7d8..2b4ba0d6c2 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -31,6 +31,8 @@ # include # include #endif +#include +#include #include #include @@ -44,8 +46,7 @@ #include #include #include -#include -#include + #include #include diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index a5e324d3e7..eddd8ccd2e 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -46,6 +46,9 @@ # include #endif +#include +#include + #include #include #include @@ -56,8 +59,7 @@ #include #include #include -#include -#include + #include #include "ViewProviderFemPostObject.h" diff --git a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp index f1f35539d8..5a319390d0 100644 --- a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp +++ b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp @@ -22,6 +22,7 @@ #include "PreCompiled.h" +#include "ViewProviderSketch.h" #include #include #include @@ -34,7 +35,7 @@ #include "SketcherSettings.h" #include "SoZoomTranslation.h" #include "ViewProviderPython.h" -#include "ViewProviderSketch.h" + #include "ViewProviderSketchGeometryExtension.h" #include "ViewProviderSketchGeometryExtensionPy.h" #include "Workbench.h" diff --git a/src/Mod/TechDraw/Gui/TaskActiveView.cpp b/src/Mod/TechDraw/Gui/TaskActiveView.cpp index bcd2c7b657..c97ad31027 100644 --- a/src/Mod/TechDraw/Gui/TaskActiveView.cpp +++ b/src/Mod/TechDraw/Gui/TaskActiveView.cpp @@ -27,6 +27,8 @@ # include # include #endif // #ifndef _PreComp_ +#include +#include #include #include @@ -36,8 +38,7 @@ #include #include #include -#include -#include + #include #include From b360b43ebef91d641f4688995094ae58025909b2 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Sat, 16 Sep 2023 00:38:41 -0300 Subject: [PATCH 18/25] Fixing DOMDocument redefinition --- src/Gui/PreferencePages/DlgSettingsNavigation.cpp | 5 +++-- src/Gui/TaskView/TaskImage.cpp | 5 +++-- src/Mod/Fem/Gui/TaskCreateNodeSet.cpp | 4 ++-- src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp | 5 +++-- src/Mod/Mesh/Gui/Command.cpp | 4 ++-- src/Mod/Mesh/Gui/MeshEditor.cpp | 5 +++-- src/Mod/Mesh/Gui/MeshSelection.cpp | 5 ++--- src/Mod/MeshPart/Gui/Command.cpp | 5 ++--- src/Mod/MeshPart/Gui/CrossSections.cpp | 5 ++--- src/Mod/MeshPart/Gui/CurveOnMesh.cpp | 5 ++--- src/Mod/Part/Gui/BoxSelection.cpp | 5 ++--- src/Mod/Part/Gui/Command.cpp | 5 ++--- src/Mod/Part/Gui/CrossSections.cpp | 5 ++--- src/Mod/Part/Gui/DlgPrimitives.cpp | 5 ++--- src/Mod/Part/Gui/DlgProjectionOnSurface.cpp | 5 ++--- src/Mod/Part/Gui/SectionCutting.cpp | 5 ++--- src/Mod/Part/Gui/TaskDimension.cpp | 5 ++--- src/Mod/Part/Gui/TaskFaceColors.cpp | 5 ++--- src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 5 ++--- src/Mod/PartDesign/Gui/ViewProviderDatum.cpp | 5 ++--- src/Mod/Sandbox/Gui/AppSandboxGui.cpp | 5 ++--- src/Mod/Sandbox/Gui/Command.cpp | 5 ++--- src/Mod/Sandbox/Gui/Overlay.cpp | 9 +++------ src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 5 ++--- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 5 ++--- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 5 ++--- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 5 ++--- src/Mod/TechDraw/Gui/DrawGuiUtil.cpp | 5 ++--- src/Mod/TechDraw/Gui/Grabber3d.cpp | 5 ++--- src/Mod/TechDraw/Gui/QGVPage.cpp | 5 ++--- src/Mod/TechDraw/Gui/TaskProjection.cpp | 5 ++--- 31 files changed, 67 insertions(+), 90 deletions(-) diff --git a/src/Gui/PreferencePages/DlgSettingsNavigation.cpp b/src/Gui/PreferencePages/DlgSettingsNavigation.cpp index ee65c0d091..7312137176 100644 --- a/src/Gui/PreferencePages/DlgSettingsNavigation.cpp +++ b/src/Gui/PreferencePages/DlgSettingsNavigation.cpp @@ -28,6 +28,8 @@ # include # include #endif +#include +#include #include #include @@ -35,8 +37,7 @@ #include #include #include -#include -#include + #include "DlgSettingsNavigation.h" #include "ui_DlgSettingsNavigation.h" diff --git a/src/Gui/TaskView/TaskImage.cpp b/src/Gui/TaskView/TaskImage.cpp index a93aaf9440..48038c9f26 100644 --- a/src/Gui/TaskView/TaskImage.cpp +++ b/src/Gui/TaskView/TaskImage.cpp @@ -41,6 +41,8 @@ # include # include #endif +#include +#include #include #include @@ -52,8 +54,7 @@ #include #include #include -#include -#include + #include #include diff --git a/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp b/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp index 650d7aaeba..56459bbeaf 100644 --- a/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp +++ b/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp @@ -30,14 +30,14 @@ # include # include #endif +#include +#include #include #include #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp index bd195196f9..05f7634b80 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp @@ -42,6 +42,8 @@ # include # include #endif +#include +#include #include #include @@ -49,8 +51,7 @@ #include #include #include -#include -#include + #include #include "ViewProviderFemPostFunction.h" diff --git a/src/Mod/Mesh/Gui/Command.cpp b/src/Mod/Mesh/Gui/Command.cpp index 47ce40302e..2efee094db 100644 --- a/src/Mod/Mesh/Gui/Command.cpp +++ b/src/Mod/Mesh/Gui/Command.cpp @@ -38,6 +38,8 @@ #ifndef __InventorAll__ # include #endif +#include +#include #include #include @@ -53,8 +55,6 @@ #include #include #include -#include -#include #include #include diff --git a/src/Mod/Mesh/Gui/MeshEditor.cpp b/src/Mod/Mesh/Gui/MeshEditor.cpp index e15df12cc4..0d87575b21 100644 --- a/src/Mod/Mesh/Gui/MeshEditor.cpp +++ b/src/Mod/Mesh/Gui/MeshEditor.cpp @@ -45,11 +45,12 @@ # include # include #endif +#include +#include #include #include -#include -#include + #include #include #include diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index eb464ffe2b..18be15611c 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -32,7 +32,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -42,8 +43,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/MeshPart/Gui/Command.cpp b/src/Mod/MeshPart/Gui/Command.cpp index 4da4af0e89..4dfb6994fc 100644 --- a/src/Mod/MeshPart/Gui/Command.cpp +++ b/src/Mod/MeshPart/Gui/Command.cpp @@ -26,7 +26,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -35,8 +36,6 @@ #include #include #include -#include -#include #include #include "CrossSections.h" diff --git a/src/Mod/MeshPart/Gui/CrossSections.cpp b/src/Mod/MeshPart/Gui/CrossSections.cpp index 6e4cf1015a..f76099a050 100644 --- a/src/Mod/MeshPart/Gui/CrossSections.cpp +++ b/src/Mod/MeshPart/Gui/CrossSections.cpp @@ -41,15 +41,14 @@ # include # include #endif - +#include +#include #include #include #include #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp index be26d5474e..00e62a10cc 100644 --- a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp +++ b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp @@ -50,14 +50,13 @@ # include # include #endif - +#include +#include #include #include #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Part/Gui/BoxSelection.cpp b/src/Mod/Part/Gui/BoxSelection.cpp index 9a18d68d31..cc9215ed97 100644 --- a/src/Mod/Part/Gui/BoxSelection.cpp +++ b/src/Mod/Part/Gui/BoxSelection.cpp @@ -33,7 +33,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -41,8 +42,6 @@ #include #include #include -#include -#include #include "BoxSelection.h" #include "ViewProviderExt.h" diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index 983045064f..128215678e 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -31,7 +31,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -48,8 +49,6 @@ #include #include #include -#include -#include #include #include "BoxSelection.h" diff --git a/src/Mod/Part/Gui/CrossSections.cpp b/src/Mod/Part/Gui/CrossSections.cpp index 76069d3282..f1144e9115 100644 --- a/src/Mod/Part/Gui/CrossSections.cpp +++ b/src/Mod/Part/Gui/CrossSections.cpp @@ -38,7 +38,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -46,8 +47,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 0d6d1c525a..9ac0dc2d86 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -33,7 +33,8 @@ #include #include #endif - +#include +#include #include #include #include @@ -43,8 +44,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp index 4d0704f981..48dbec94ce 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp @@ -42,12 +42,11 @@ # include # include #endif - +#include +#include #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Part/Gui/SectionCutting.cpp b/src/Mod/Part/Gui/SectionCutting.cpp index ddf2c15b7d..8fa4a41534 100644 --- a/src/Mod/Part/Gui/SectionCutting.cpp +++ b/src/Mod/Part/Gui/SectionCutting.cpp @@ -38,7 +38,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -50,8 +51,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Part/Gui/TaskDimension.cpp b/src/Mod/Part/Gui/TaskDimension.cpp index a733465e24..b916f05168 100644 --- a/src/Mod/Part/Gui/TaskDimension.cpp +++ b/src/Mod/Part/Gui/TaskDimension.cpp @@ -62,7 +62,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -72,8 +73,6 @@ #include #include #include -#include -#include #include #include "TaskDimension.h" diff --git a/src/Mod/Part/Gui/TaskFaceColors.cpp b/src/Mod/Part/Gui/TaskFaceColors.cpp index 0b088f898a..84a71e1740 100644 --- a/src/Mod/Part/Gui/TaskFaceColors.cpp +++ b/src/Mod/Part/Gui/TaskFaceColors.cpp @@ -42,7 +42,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -51,8 +52,6 @@ #include #include #include -#include -#include #include "TaskFaceColors.h" #include "ui_TaskFaceColors.h" diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index 19313c0003..ed06ec5b4d 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -29,7 +29,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -39,8 +40,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp index 7c84e38206..2d0e2fda58 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp @@ -40,14 +40,13 @@ # include # include #endif - +#include +#include #include #include #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp index 14664b6ae9..b2ce5434fa 100644 --- a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp +++ b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp @@ -30,7 +30,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -42,8 +43,6 @@ #include #include #include -#include -#include #include #ifdef HAVE_PART #include diff --git a/src/Mod/Sandbox/Gui/Command.cpp b/src/Mod/Sandbox/Gui/Command.cpp index 0f034ec871..b7a0ad6f9d 100644 --- a/src/Mod/Sandbox/Gui/Command.cpp +++ b/src/Mod/Sandbox/Gui/Command.cpp @@ -58,7 +58,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -68,8 +69,6 @@ #include #include #include -#include -#include #include #include diff --git a/src/Mod/Sandbox/Gui/Overlay.cpp b/src/Mod/Sandbox/Gui/Overlay.cpp index e7fa9e8f7c..aa8674dfc6 100644 --- a/src/Mod/Sandbox/Gui/Overlay.cpp +++ b/src/Mod/Sandbox/Gui/Overlay.cpp @@ -29,6 +29,8 @@ # include # include #endif +#include +#include #include @@ -36,9 +38,7 @@ #include #include #include -#include -#include - +#include #include "Overlay.h" @@ -444,9 +444,6 @@ void paintSelection() } // --------------------------------------- -#include -#include -#include #if 0 void MeshSelection::prepareFreehandSelection(bool add) { diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index c1e1bc7744..43cb566d4f 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -28,7 +28,8 @@ #include #include #endif - +#include +#include #include #include #include @@ -37,8 +38,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index f3eccc92fc..50142dbbe5 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -27,15 +27,14 @@ #include #include #endif// #ifndef _PreComp_ - +#include +#include #include #include #include #include #include #include -#include -#include #include #include "CommandConstraints.h" diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 2bced92a6d..e7bd088750 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -29,15 +29,14 @@ #include #include #endif - +#include +#include #include #include #include #include #include #include -#include -#include #include #include diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index b8dcae8dff..047f1085c9 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -38,7 +38,8 @@ #include #include #endif - +#include +#include #include #include #include @@ -52,8 +53,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index 83d6e0c79b..404a42629f 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp @@ -35,7 +35,8 @@ # include # include #endif - +#include +#include #include #include #include @@ -50,8 +51,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/TechDraw/Gui/Grabber3d.cpp b/src/Mod/TechDraw/Gui/Grabber3d.cpp index 85c8139352..07a8463e8a 100644 --- a/src/Mod/TechDraw/Gui/Grabber3d.cpp +++ b/src/Mod/TechDraw/Gui/Grabber3d.cpp @@ -21,12 +21,11 @@ ***************************************************************************/ #include "PreCompiled.h" - +#include +#include #include #include #include -#include -#include #include "Grabber3d.h" diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 18bb6e419a..7242a04f01 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -34,7 +34,8 @@ #include #include #endif - +#include +#include #include #include #include @@ -42,8 +43,6 @@ #include #include #include -#include -#include #include #include diff --git a/src/Mod/TechDraw/Gui/TaskProjection.cpp b/src/Mod/TechDraw/Gui/TaskProjection.cpp index 9c2e2aa227..87a011d80c 100644 --- a/src/Mod/TechDraw/Gui/TaskProjection.cpp +++ b/src/Mod/TechDraw/Gui/TaskProjection.cpp @@ -26,15 +26,14 @@ #ifndef _PreComp_ # include #endif - +#include +#include #include #include #include #include #include #include -#include -#include #include #include "TaskProjection.h" From 19887876d2227af68005dc5e04cad1e7cc9e6243 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 16 Sep 2023 05:13:49 +0000 Subject: [PATCH 19/25] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/Mod/MeshPart/Gui/Command.cpp | 4 ++-- src/Mod/MeshPart/Gui/CrossSections.cpp | 10 +++++----- src/Mod/MeshPart/Gui/CurveOnMesh.cpp | 4 ++-- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 4 ++-- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 4 ++-- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 4 ++-- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Mod/MeshPart/Gui/Command.cpp b/src/Mod/MeshPart/Gui/Command.cpp index 2445d564b0..75c21e4574 100644 --- a/src/Mod/MeshPart/Gui/Command.cpp +++ b/src/Mod/MeshPart/Gui/Command.cpp @@ -26,8 +26,6 @@ #include #include #endif -#include -#include #include #include #include @@ -36,6 +34,8 @@ #include #include #include +#include +#include #include #include "CrossSections.h" diff --git a/src/Mod/MeshPart/Gui/CrossSections.cpp b/src/Mod/MeshPart/Gui/CrossSections.cpp index 47c07446b5..28a6fbf5ad 100644 --- a/src/Mod/MeshPart/Gui/CrossSections.cpp +++ b/src/Mod/MeshPart/Gui/CrossSections.cpp @@ -41,16 +41,16 @@ #include #include #endif -#include -#include -#include -#include -#include #include #include #include #include #include +#include +#include +#include +#include +#include #include #include #include diff --git a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp index ff294c1564..4041fcac89 100644 --- a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp +++ b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp @@ -50,13 +50,13 @@ #include #include #endif -#include -#include #include #include #include #include #include +#include +#include #include #include #include diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 7807d45d02..2852bfb808 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -28,8 +28,6 @@ #include #include #endif -#include -#include #include #include #include @@ -38,6 +36,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 1d6e000aee..517349ef1f 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -27,14 +27,14 @@ #include #include #endif // #ifndef _PreComp_ -#include -#include #include #include #include #include #include #include +#include +#include #include #include "CommandConstraints.h" diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index fce007a561..395fc3e3e4 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -29,14 +29,14 @@ #include #include #endif -#include -#include #include #include #include #include #include #include +#include +#include #include #include diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 047f1085c9..2b7b057819 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -38,8 +38,6 @@ #include #include #endif -#include -#include #include #include #include @@ -53,6 +51,8 @@ #include #include #include +#include +#include #include #include #include From f206e91e1c351e63cd8000156446f100f6aae92a Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Sat, 16 Sep 2023 07:27:11 -0300 Subject: [PATCH 20/25] fixing DOMDocument redefinition3 --- src/Mod/MeshPart/Gui/Command.cpp | 4 ++-- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Mod/MeshPart/Gui/Command.cpp b/src/Mod/MeshPart/Gui/Command.cpp index 75c21e4574..2445d564b0 100644 --- a/src/Mod/MeshPart/Gui/Command.cpp +++ b/src/Mod/MeshPart/Gui/Command.cpp @@ -26,6 +26,8 @@ #include #include #endif +#include +#include #include #include #include @@ -34,8 +36,6 @@ #include #include #include -#include -#include #include #include "CrossSections.h" diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 911e51b99c..b5ce402cb8 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -29,10 +29,12 @@ #include #include +#include + #include #include #include -#include + #include #include #include From 4aea1468870fa9b8caba8104acc6e4fae4c36125 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 16 Sep 2023 07:27:49 +0000 Subject: [PATCH 21/25] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/Mod/MeshPart/Gui/Command.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/MeshPart/Gui/Command.cpp b/src/Mod/MeshPart/Gui/Command.cpp index 2445d564b0..75c21e4574 100644 --- a/src/Mod/MeshPart/Gui/Command.cpp +++ b/src/Mod/MeshPart/Gui/Command.cpp @@ -26,8 +26,6 @@ #include #include #endif -#include -#include #include #include #include @@ -36,6 +34,8 @@ #include #include #include +#include +#include #include #include "CrossSections.h" From ae9bb6ed4399ade1cd31aab7536e447c1e5a9a8d Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Mon, 18 Sep 2023 13:40:13 -0300 Subject: [PATCH 22/25] using clang-format tags to avoid get headers reordered(fix DOMDocument redefinition error) --- src/Mod/MeshPart/Gui/Command.cpp | 6 ++++-- src/Mod/MeshPart/Gui/CrossSections.cpp | 7 +++++-- src/Mod/MeshPart/Gui/CurveOnMesh.cpp | 8 ++++++-- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 8 ++++++-- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 8 ++++++-- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 8 ++++++-- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 8 ++++++-- 7 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/Mod/MeshPart/Gui/Command.cpp b/src/Mod/MeshPart/Gui/Command.cpp index 75c21e4574..59ad55ca5b 100644 --- a/src/Mod/MeshPart/Gui/Command.cpp +++ b/src/Mod/MeshPart/Gui/Command.cpp @@ -26,6 +26,10 @@ #include #include #endif +// clang-format off +#include +#include +// clang-format on #include #include #include @@ -34,8 +38,6 @@ #include #include #include -#include -#include #include #include "CrossSections.h" diff --git a/src/Mod/MeshPart/Gui/CrossSections.cpp b/src/Mod/MeshPart/Gui/CrossSections.cpp index 28a6fbf5ad..7f748988d5 100644 --- a/src/Mod/MeshPart/Gui/CrossSections.cpp +++ b/src/Mod/MeshPart/Gui/CrossSections.cpp @@ -41,13 +41,16 @@ #include #include #endif + +// clang-format off +#include +#include +// clang-format on #include #include #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp index 4041fcac89..6490fe6b63 100644 --- a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp +++ b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp @@ -50,13 +50,17 @@ #include #include #endif + +// clang-format off +#include +#include +// clang-format on + #include #include #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 2852bfb808..b362b14dab 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -28,6 +28,12 @@ #include #include #endif + +// clang-format off +#include +#include +// clang-format on + #include #include #include @@ -36,8 +42,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 517349ef1f..12adc95424 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -27,14 +27,18 @@ #include #include #endif // #ifndef _PreComp_ + +// clang-format off +#include +#include +// clang-format on + #include #include #include #include #include #include -#include -#include #include #include "CommandConstraints.h" diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 395fc3e3e4..7f7be469ef 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -29,14 +29,18 @@ #include #include #endif + +// clang-format off +#include +#include +// clang-format on + #include #include #include #include #include #include -#include -#include #include #include diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 2b7b057819..7352cd8407 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -38,6 +38,12 @@ #include #include #endif + +// clang-format off +#include +#include +// clang-format on + #include #include #include @@ -51,8 +57,6 @@ #include #include #include -#include -#include #include #include #include From 40c05f67142e3e26b0458a5dfcd74384108bda22 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Mon, 18 Sep 2023 18:58:05 -0300 Subject: [PATCH 23/25] continue fix DOMDocument redefinition --- src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp b/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp index 9a7627b88f..1aab1cb96f 100644 --- a/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp +++ b/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp @@ -21,13 +21,11 @@ ***************************************************************************/ #include "PreCompiled.h" - -#include - -#include "TaskDlgEditSketch.h" +// clang-format off #include "ViewProviderSketch.h" - - +#include +#include "TaskDlgEditSketch.h" +// clang-format on using namespace SketcherGui; //************************************************************************** From 6ae6126243e62d1c75f92a625d9d7d4c94068ccc Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Tue, 19 Sep 2023 07:06:13 -0300 Subject: [PATCH 24/25] Removing /showIncludes option for windows compiler --- cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake b/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake index c67ecce528..63c471ab33 100644 --- a/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake +++ b/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake @@ -3,7 +3,6 @@ # https://cmake.org/cmake/help/v3.8/manual/cmake-compile-features.7.html macro(CompilerChecksAndSetups) - set(CMAKE_CXX_FLAGS "/showIncludes ${CMAKE_CXX_FLAGS}") if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") set(CMAKE_COMPILER_IS_CLANGXX TRUE) endif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") From f431a025342c5ff5ce8b76d09d4e969770ac5cf5 Mon Sep 17 00:00:00 2001 From: AgCaliva Date: Wed, 4 Oct 2023 13:18:20 -0300 Subject: [PATCH 25/25] solving new error related to cmake --- src/Mod/Mesh/Gui/MeshSelection.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index 9776805e9b..cbc56352ec 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -46,10 +46,10 @@ #include #include -#include -#include -#include #include +#include +#include +#include #include "MeshSelection.h" #include "ViewProvider.h"