From: srn Date: Tue, 14 Feb 2006 13:08:54 +0000 (+0000) Subject: Changed method DumpStudy, added IParameters X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6acf5f6fabf24b1d132660c3fda92819fb2aa313;p=modules%2Fkernel.git Changed method DumpStudy, added IParameters --- diff --git a/src/SALOMEDSImpl/Makefile.in b/src/SALOMEDSImpl/Makefile.in index b64478a7e..6df78bef6 100644 --- a/src/SALOMEDSImpl/Makefile.in +++ b/src/SALOMEDSImpl/Makefile.in @@ -56,6 +56,7 @@ EXPORT_HEADERS= \ SALOMEDSImpl_StudyManager.hxx \ SALOMEDSImpl_OCAFApplication.hxx \ SALOMEDSImpl_ChildNodeIterator.hxx \ + SALOMEDSImpl_IParameters.hxx LIB_CLIENT_IDL = LIB_SERVER_IDL = @@ -113,7 +114,8 @@ LIB_SRC = SALOMEDSImpl_Tool.cxx \ SALOMEDSImpl_SComponentIterator.cxx \ SALOMEDSImpl_StudyBuilder.cxx \ SALOMEDSImpl_Study.cxx \ - SALOMEDSImpl_StudyManager.cxx + SALOMEDSImpl_StudyManager.cxx \ + SALOMEDSImpl_IParameters.cxx diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.cxx new file mode 100644 index 000000000..71254c62f --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.cxx @@ -0,0 +1,272 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// +#include "SALOMEDSImpl_IParameters.hxx" +#include + +#include + +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_ChildIterator.hxx" + +using namespace std; + +#define _AP_LISTS_LIST_ "AP_LISTS_LIST" +#define _AP_ENTRIES_LIST_ "AP_ENTRIES_LIST" +#define _AP_PROPERTIES_LIST_ "AP_PROPERTIES_LIST" +#define _AP_DUMP_PYTHON_ "AP_DUMP_PYTHON" + +/*! + Constructor +*/ +SALOMEDSImpl_IParameters::SALOMEDSImpl_IParameters(const Handle(SALOMEDSImpl_AttributeParameter)& ap) +{ + if(ap.IsNull()) return; + _ap = ap; +} + +SALOMEDSImpl_IParameters::~SALOMEDSImpl_IParameters() +{} + +int SALOMEDSImpl_IParameters::append(const string& listName, const string& value) +{ + if(_ap.IsNull()) return -1; + vector v; + if(!_ap->IsSet(listName, PT_STRARRAY)) { + if(!_ap->IsSet(_AP_LISTS_LIST_, PT_STRARRAY)) _ap->SetStrArray(_AP_LISTS_LIST_, v); + if(listName != _AP_ENTRIES_LIST_ && + listName != _AP_PROPERTIES_LIST_) { + append(_AP_LISTS_LIST_, listName); + } + _ap->SetStrArray(listName, v); + } + v = _ap->GetStrArray(listName); + v.push_back(value); + _ap->SetStrArray(listName, v); + return (v.size()-1); +} + +int SALOMEDSImpl_IParameters::nbValues(const string& listName) +{ + if(_ap.IsNull()) return -1; + if(!_ap->IsSet(listName, PT_STRARRAY)) return 0; + vector v = _ap->GetStrArray(listName); + return v.size(); +} + +vector SALOMEDSImpl_IParameters::getValues(const string& listName) +{ + vector v; + if(_ap.IsNull()) return v; + if(!_ap->IsSet(listName, PT_STRARRAY)) return v; + return _ap->GetStrArray(listName); +} + + +string SALOMEDSImpl_IParameters::getValue(const string& listName, int index) +{ + if(_ap.IsNull()) return ""; + if(!_ap->IsSet(listName, PT_STRARRAY)) return ""; + vector v = _ap->GetStrArray(listName); + if(index >= v.size()) return ""; + return v[index]; +} + +vector SALOMEDSImpl_IParameters::getLists() +{ + vector v; + if(!_ap->IsSet(_AP_LISTS_LIST_, PT_STRARRAY)) return v; + return _ap->GetStrArray(_AP_LISTS_LIST_); +} + +void SALOMEDSImpl_IParameters::setParameter(const string& entry, const string& parameterName, const string& value) +{ + if(_ap.IsNull()) return; + vector v; + if(!_ap->IsSet(entry, PT_STRARRAY)) { + append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries + _ap->SetStrArray(entry, v); + } + v = _ap->GetStrArray(entry); + v.push_back(parameterName); + v.push_back(value); + _ap->SetStrArray(entry, v); +} + + +string SALOMEDSImpl_IParameters::getParameter(const string& entry, const string& parameterName) +{ + if(_ap.IsNull()) return ""; + if(!_ap->IsSet(entry, PT_STRARRAY)) return ""; + vector v = _ap->GetStrArray(entry); + int length = v.size(); + for(int i = 0; i SALOMEDSImpl_IParameters::getAllParameterNames(const string& entry) +{ + vector v, names; + if(_ap.IsNull()) return v; + if(!_ap->IsSet(entry, PT_STRARRAY)) return v; + v = _ap->GetStrArray(entry); + int length = v.size(); + for(int i = 0; i SALOMEDSImpl_IParameters::getAllParameterValues(const string& entry) +{ + vector v, values; + if(_ap.IsNull()) return v; + if(!_ap->IsSet(entry, PT_STRARRAY)) return v; + v = _ap->GetStrArray(entry); + int length = v.size(); + for(int i = 1; iIsSet(entry, PT_STRARRAY)) return -1; + return _ap->GetStrArray(entry).size()/2; +} + +vector SALOMEDSImpl_IParameters::getEntries() +{ + vector v; + if(_ap.IsNull()) return v; + if(!_ap->IsSet(_AP_ENTRIES_LIST_, PT_STRARRAY)) return v; + return _ap->GetStrArray(_AP_ENTRIES_LIST_); +} + +void SALOMEDSImpl_IParameters::setProperty(const string& name, const std::string& value) +{ + if(_ap.IsNull()) return; + if(!_ap->IsSet(name, PT_STRING)) { + append(_AP_PROPERTIES_LIST_, name); //Add the property to the internal list of properties + } + _ap->SetString(name, value); +} + +string SALOMEDSImpl_IParameters::getProperty(const string& name) +{ + if(_ap.IsNull()) return ""; + if(!_ap->IsSet(name, PT_STRING)) return ""; + return _ap->GetString(name); +} + +vector SALOMEDSImpl_IParameters::getProperties() +{ + vector v; + if(_ap.IsNull()) return v; + if(!_ap->IsSet(_AP_PROPERTIES_LIST_, PT_STRARRAY)) return v; + return _ap->GetStrArray(_AP_PROPERTIES_LIST_); +} + + +bool SALOMEDSImpl_IParameters::isDumpPython(const Handle(SALOMEDSImpl_Study)& study, const string& theID) +{ + string anID; + if(theID == "") anID = getDefaultVisualComponent(); + else anID = theID; + + Handle(SALOMEDSImpl_AttributeParameter) ap = study->GetCommonParameters((char*)anID.c_str(), 0); + if(ap.IsNull()) return false; + if(!ap->IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN)) return false; + return (bool)ap->GetBool(_AP_DUMP_PYTHON_); +} + + +int SALOMEDSImpl_IParameters::getLastSavePoint(const Handle(SALOMEDSImpl_Study)& study, const string& theID) +{ + string anID; + if(theID == "") anID = getDefaultVisualComponent(); + else anID = theID; + + + Handle(SALOMEDSImpl_SObject) so = study->FindComponent((char*)anID.c_str()); + if(so.IsNull()) return -1; + + Handle(SALOMEDSImpl_StudyBuilder) builder = study->NewBuilder(); + Handle(SALOMEDSImpl_ChildIterator) anIter ( study->NewChildIterator( so ) ); + int tag = -1; + for(; anIter->More(); anIter->Next()) + { + Handle(SALOMEDSImpl_SObject) val( anIter->Value() ); + Handle(SALOMEDSImpl_GenericAttribute) genAttr; + if(builder->FindAttribute(val, genAttr, "AttributeParameter")) tag = val->Tag(); + } + + return tag; +} + + + +string SALOMEDSImpl_IParameters::getStudyScript(const Handle(SALOMEDSImpl_Study)& study, int savePoint, const std::string& theID) +{ + string anID; + if(theID == "") anID = getDefaultVisualComponent(); + else anID = theID; + + Handle(SALOMEDSImpl_AttributeParameter) ap = study->GetCommonParameters((char*)anID.c_str(), savePoint); + SALOMEDSImpl_IParameters ip(ap); + + string dump(""); + + dump += "import iparameters\n"; + dump += "ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters(\""+anID+"\", 1))\n\n"; + + + vector v = ip.getProperties(); + if(v.size() > 0) { + dump += "#Set up visual properties:\n"; + for(int i = 0; i 0) { + dump += "#Set up lists:\n"; + for(int i = 0; i lst = ip.getValues(v[i]); + dump += "# fill list "+v[i]+"\n"; + for(int j = 0; j < lst.size(); j++) + dump += "ipar.append(\""+v[i]+"\", \""+lst[j]+"\")\n"; + } + } + + return dump; +} + +string SALOMEDSImpl_IParameters::getDefaultVisualComponent() +{ + return "Interface Applicative"; +} + + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.hxx new file mode 100644 index 000000000..d41f21ef3 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.hxx @@ -0,0 +1,136 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// +#ifndef SALOMEDSImpl_IParameters_H +#define SALOMEDSImpl_IParameters_H + +#include +#include + +#include "SALOMEDSImpl_AttributeParameter.hxx" +#include "SALOMEDSImpl_Study.hxx" + +/*! + Class which an interface to store the parameters of the objects +*/ +class SALOMEDSImpl_IParameters +{ +public: + SALOMEDSImpl_IParameters(const Handle(SALOMEDSImpl_AttributeParameter)& ap); + + virtual ~SALOMEDSImpl_IParameters(); + + /*! + Appends a string value to a named list. + Returns a number of the added value. + Note: the name of the list MUST be unique + */ + virtual int append(const std::string& listName, const std::string& value); + + /*! + Returns a number elements in the list + */ + virtual int nbValues(const std::string& listName); + + /*! + Returns a list of values in the list + */ + virtual std::vector getValues(const std::string& listName); + + /*! + Returns a value with given %index, where %index is in range [0:nbValues-1] + */ + virtual std::string getValue(const std::string& listName, int index); + + /*! + Returns a list all entries lists + */ + virtual std::vector getLists(); + + /*! + Sets a new named parameter value for the given entry + */ + virtual void setParameter(const std::string& entry, const std::string& parameterName, const std::string& value); + + /*! + Gets a named parameter value for the given entry + */ + virtual std::string getParameter(const std::string& entry, const std::string& parameterName); + + /*! + Returns all parameter names of the given entry + */ + virtual std::vector SALOMEDSImpl_IParameters::getAllParameterNames(const std::string& entry); + + /*! + Returns all parameter values of the given entry + */ + virtual std::vector SALOMEDSImpl_IParameters::getAllParameterValues(const std::string& entry); + + /*! + Returns a number of parameters of the given entry + */ + virtual int getNbParameters(const std::string& entry); + + /*! + Returns a list all entries + */ + virtual std::vector getEntries(); + + /*! + Sets a global named property value + */ + virtual void setProperty(const std::string& name, const std::string& value); + + /*! + Gets a value of global named property + */ + virtual std::string getProperty(const std::string& name); + + /*! + Returns a list all properties + */ + virtual std::vector getProperties(); + + + /*! + Returns whether there is the dumping visual parameters + */ + static bool isDumpPython(const Handle(SALOMEDSImpl_Study)& study, const string& theID = ""); + + /*! + Returns an ID of the last save point + */ + static int getLastSavePoint(const Handle(SALOMEDSImpl_Study)& study, const std::string& theID = ""); + + /*! + Returns a Python script for the study, which sets up visual parameters + */ + static std::string getStudyScript(const Handle(SALOMEDSImpl_Study)& study, int savePoint, const std::string& theID = ""); + + /*! + Returns a default name of the component where the visula parameters are stored. + */ + static std::string getDefaultVisualComponent(); + +private: + Handle(SALOMEDSImpl_AttributeParameter) _ap; +}; + + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 507a9a547..b38df3443 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -46,6 +46,7 @@ using namespace std; #include "SALOMEDSImpl_AttributeReference.hxx" #include "SALOMEDSImpl_StudyHandle.hxx" #include "SALOMEDSImpl_Tool.hxx" +#include "SALOMEDSImpl_IParameters.hxx" IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_Study, MMgt_TShared ) IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_Study, MMgt_TShared ) @@ -1246,8 +1247,7 @@ Handle(TDF_Attribute) SALOMEDSImpl_Study::GetAttribute(const TCollection_AsciiSt bool SALOMEDSImpl_Study::DumpStudy(const TCollection_AsciiString& thePath, const TCollection_AsciiString& theBaseName, bool isPublished, - SALOMEDSImpl_DriverFactory* theFactory, - const TCollection_AsciiString& thePrefix) + SALOMEDSImpl_DriverFactory* theFactory) { _errorCode = ""; @@ -1299,11 +1299,18 @@ bool SALOMEDSImpl_Study::DumpStudy(const TCollection_AsciiString& thePath, fp << "import " << aBatchModeScript << "\n" << endl; fp << "sys.path.insert( 0, \'" << thePath << "\')\n" << endl; - //Output the prefix if there is any - if(thePrefix.Length() > 0) { - fp << thePrefix; - fp << "\n" << endl; + + //Check if it's necessary to dump visual parameters + bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this); + int lastSavePoint = -1; + if(isDumpVisuals) { + lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this); + if(lastSavePoint > 0) { + fp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint); + fp << "\n" << endl; + } } + Handle(TColStd_HSequenceOfAsciiString) aSeqOfFileNames = new TColStd_HSequenceOfAsciiString; @@ -1389,7 +1396,7 @@ bool SALOMEDSImpl_Study::DumpStudy(const TCollection_AsciiString& thePath, fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << endl; } - if(thePrefix.Length() > 0) { //Output the call to Session's method restoreVisualState + if(isDumpVisuals) { //Output the call to Session's method restoreVisualState fp << "iparameters.getSession().restoreVisualState(1)" << endl; } @@ -1512,11 +1519,15 @@ void SALOMEDSImpl_Study::Modify() //============================================================================ Handle(SALOMEDSImpl_AttributeParameter) SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint) { - if(theSavePoint <= 0) return NULL; + if(theSavePoint < 0) return NULL; Handle(SALOMEDSImpl_StudyBuilder) builder = NewBuilder(); Handle(SALOMEDSImpl_SObject) so = FindComponent((char*)theID); if(so.IsNull()) so = builder->NewComponent((char*)theID); - Handle(SALOMEDSImpl_SObject) newSO = builder->NewObjectToTag(so, theSavePoint); + Handle(SALOMEDSImpl_SObject) newSO; + if(theSavePoint == 0) //Get an attribute that is placed on the component itself. + newSO = so; + else + newSO = builder->NewObjectToTag(so, theSavePoint); return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(builder->FindOrCreateAttribute(newSO, "AttributeParameter")); } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index b2f497213..c22b2cd77 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -257,8 +257,7 @@ public: Standard_EXPORT virtual bool DumpStudy(const TCollection_AsciiString& thePath, const TCollection_AsciiString& theBaseName, bool isPublished, - SALOMEDSImpl_DriverFactory* theFactory, - const TCollection_AsciiString& thePrefix = ""); + SALOMEDSImpl_DriverFactory* theFactory); Standard_EXPORT static TCollection_AsciiString GetDumpStudyComment(const char* theComponentName = 0);