--- /dev/null
+// 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 <utilities.h>
+
+#include <TCollection_AsciiString.hxx>
+
+#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<string> 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<string> v = _ap->GetStrArray(listName);
+ return v.size();
+}
+
+vector<string> SALOMEDSImpl_IParameters::getValues(const string& listName)
+{
+ vector<string> 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<string> v = _ap->GetStrArray(listName);
+ if(index >= v.size()) return "";
+ return v[index];
+}
+
+vector<string> SALOMEDSImpl_IParameters::getLists()
+{
+ vector<string> 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<string> 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<string> v = _ap->GetStrArray(entry);
+ int length = v.size();
+ for(int i = 0; i<length; i+=1) {
+ if(v[i] == parameterName) return v[i+1];
+ }
+ return "";
+}
+
+
+vector<string> SALOMEDSImpl_IParameters::getAllParameterNames(const string& entry)
+{
+ vector<string> 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<length; i+=2) {
+ names.push_back(v[i]);
+ }
+ return names;
+}
+
+vector<string> SALOMEDSImpl_IParameters::getAllParameterValues(const string& entry)
+{
+ vector<string> 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; i<length; i+=2) {
+ values.push_back(v[i]);
+ }
+ return values;
+}
+
+int SALOMEDSImpl_IParameters::getNbParameters(const string& entry)
+{
+ if(_ap.IsNull()) return -1;
+ if(!_ap->IsSet(entry, PT_STRARRAY)) return -1;
+ return _ap->GetStrArray(entry).size()/2;
+}
+
+vector<string> SALOMEDSImpl_IParameters::getEntries()
+{
+ vector<string> 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<string> SALOMEDSImpl_IParameters::getProperties()
+{
+ vector<string> 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<string> v = ip.getProperties();
+ if(v.size() > 0) {
+ dump += "#Set up visual properties:\n";
+ for(int i = 0; i<v.size(); i++) {
+ string prp = ip.getProperty(v[i]);
+ dump += "ipar.setProperty(\""+v[i]+"\", \""+prp+"\")\n";
+ }
+ }
+
+ v = ip.getLists();
+ if(v.size() > 0) {
+ dump += "#Set up lists:\n";
+ for(int i = 0; i<v.size(); i++) {
+ vector<string> 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";
+}
+
+
--- /dev/null
+// 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 <string>
+#include <vector>
+
+#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<std::string> 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<std::string> 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<std::string> SALOMEDSImpl_IParameters::getAllParameterNames(const std::string& entry);
+
+ /*!
+ Returns all parameter values of the given entry
+ */
+ virtual std::vector<std::string> 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<std::string> 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<std::string> 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
#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 )
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 = "";
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;
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;
}
//============================================================================
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"));
}