2. Use a std::vector for storage notebook vasiables instead of a std::map.
double aResult;
if (_isLocal) {
SALOMEDS::Locker lock;
- aResult = _local_impl->GetVariable(theVarName);
+ aResult = _local_impl->GetVariableValue(theVarName);
}
else
aResult = _corba_impl->GetReal((char*)theVarName.c_str());
int aResult;
if (_isLocal) {
SALOMEDS::Locker lock;
- aResult = (int) _local_impl->GetVariable(theVarName);
+ aResult = (int) _local_impl->GetVariableValue(theVarName);
}
else
aResult = _corba_impl->GetInteger((char*)theVarName.c_str());
bool aResult;
if (_isLocal) {
SALOMEDS::Locker lock;
- aResult = (bool) _local_impl->GetVariable(theVarName);
+ aResult = (bool) _local_impl->GetVariableValue(theVarName);
}
else
aResult = _corba_impl->GetBoolean((char*)theVarName.c_str());
//============================================================================
CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
{
- return _impl->GetVariable(string(theVarName));
+ return _impl->GetVariableValue(string(theVarName));
}
//============================================================================
//============================================================================
CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
{
- return (int)_impl->GetVariable(string(theVarName));
+ return (int)_impl->GetVariableValue(string(theVarName));
}
//============================================================================
//============================================================================
CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
{
- return (bool)_impl->GetVariable(string(theVarName));
+ return (bool)_impl->GetVariableValue(string(theVarName));
}
//============================================================================
*/
//============================================================================
SALOMEDSImpl_GenericVariable::
-SALOMEDSImpl_GenericVariable(SALOMEDSImpl_GenericVariable::VariableTypes theType):
- _type(theType)
+SALOMEDSImpl_GenericVariable(SALOMEDSImpl_GenericVariable::VariableTypes theType,
+ const string& theName):
+ _type(theType),
+ _name(theName)
{}
//============================================================================
return _type;
}
+//============================================================================
+/*! Function : Name
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_GenericVariable::Name() const
+{
+ return _name;
+}
+
//============================================================================
/*! Function : setType
* Purpose :
return string();
}
+
+//============================================================================
+/*! Function : SaveToScript
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_GenericVariable::SaveToScript() const
+{
+ return string();
+}
//============================================================================
/*! Function : SaveType
* Purpose :
//Supported types of the nootebook variables
enum VariableTypes{REAL_VAR, INTEGER_VAR, BOOLEAN_VAR};
- SALOMEDSImpl_GenericVariable(VariableTypes theType);
+ SALOMEDSImpl_GenericVariable(VariableTypes theType, const std::string& theName);
~SALOMEDSImpl_GenericVariable();
VariableTypes Type() const;
+ std::string Name() const;
+
static VariableTypes String2VariableType(const std::string& theStrType);
void setType(const VariableTypes theType);
virtual void SetModifyFlag();
virtual std::string Save() const;
+ virtual std::string SaveToScript() const;
virtual std::string SaveType() const;
virtual void Load(const std::string& theStrValue);
private:
VariableTypes _type;
+ std::string _name;
};
#endif //_GENERICIMPL_VARIABLE_HXX_
*/
//============================================================================
SALOMEDSImpl_ScalarVariable::
-SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes type):
- SALOMEDSImpl_GenericVariable(type)
+SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes type,
+ const string& theName):
+ SALOMEDSImpl_GenericVariable(type,theName)
{}
//============================================================================
case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
{
sprintf(buffer, "%d", (int)myValue);
+ break;
}
default:break;
}
return string(buffer);
}
+//============================================================================
+/*! Function : SaveToScript()
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_ScalarVariable::SaveToScript() const
+{
+ char buffer[255];
+ switch(Type())
+ {
+ case SALOMEDSImpl_GenericVariable::REAL_VAR:
+ {
+ sprintf(buffer, "%f", myValue);
+ break;
+ }
+ case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
+ {
+ sprintf(buffer, "%d", (int)myValue);
+ break;
+ }
+ case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
+ {
+ if((bool)myValue)
+ sprintf(buffer, "%s", "True");
+ else
+ sprintf(buffer, "%s", "False");
+ break;
+ }
+ default:break;
+ }
+ return string(buffer);
+}
//============================================================================
/*! Function : SaveType()
public SALOMEDSImpl_GenericVariable
{
public:
- SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes theType);
+ SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes theType,
+ const std::string& theName);
~SALOMEDSImpl_ScalarVariable();
void setValue(const double theValue);
double getValue() const;
virtual std::string Save() const;
+ virtual std::string SaveToScript() const;
virtual std::string SaveType() const;
virtual void Load(const std::string& theStrValue);
return RefSO;
}
+//============================================================================
+/*! Function : _GetNoteBookAccessor
+ * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
+ */
+//============================================================================
+string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
+ return string("notebook");
+}
+
+//============================================================================
+/*! Function : _GetStudyVariablesScript
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_Study::_GetStudyVariablesScript()
+{
+ string dump("");
+
+ if(myNoteBookVars.empty())
+ return dump;
+
+ dump += "####################################################\n";
+ dump += "## Begin of NoteBook variables section ##\n";
+ dump += "####################################################\n";
+
+ string set_method = _GetNoteBookAccessor()+".set(";
+ string varName;
+ string varValue;
+ for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
+ varName = myNoteBookVars[i]->Name();
+ varValue = myNoteBookVars[i]->SaveToScript();
+ dump+=set_method+"\""+varName+"\", "+varValue+")\n";
+ }
+
+ dump += "####################################################\n";
+ dump += "## End of NoteBook variables section ##\n";
+ dump += "####################################################\n";
+
+ return dump;
+}
+
+//============================================================================
+/*! Function : _GetNoteBookAccess
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_Study::_GetNoteBookAccess()
+{
+ string accessor = _GetNoteBookAccessor();
+ string notebook = "import salome_notebook\n";
+ notebook += accessor+" = salome_notebook."+accessor + "\n";
+ return notebook;
+}
+
bool SALOMEDSImpl_Study::IsLocked()
{
_errorCode = "";
fp << aBatchModeScript << ".salome_init()" << endl << endl;
+ fp << _GetNoteBookAccess();
+
fp << "sys.path.insert( 0, \'" << thePath << "\')" << endl << endl;
+ //Dump NoteBook Variables
+ fp << _GetStudyVariablesScript();
//Check if it's necessary to dump visual parameters
bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
const double theValue,
const SALOMEDSImpl_GenericVariable::VariableTypes theType)
{
- std::map<std::string, SALOMEDSImpl_GenericVariable*>::iterator it
- = myNoteBookVars.find(theVarName);
+
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
- SALOMEDSImpl_ScalarVariable* aVar = NULL;
- if( it == myNoteBookVars.end() ) {
+ if( aGVar == NULL ) {
- aVar = new SALOMEDSImpl_ScalarVariable(theType);
+ SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
- aVar->setValue(theValue);
- myNoteBookVars[theVarName] = aVar;
+ aSVar->setValue(theValue);
+ myNoteBookVars.push_back(aSVar);
}
else {
- if(aVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>((*it).second)) {
- aVar->setValue(theValue);
- if(aVar->Type() != theType)
- aVar->setType(theType);
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
+ aSVar->setValue(theValue);
+ if(aSVar->Type() != theType)
+ aSVar->setType(theType);
}
}
}
* Purpose :
*/
//============================================================================
-double SALOMEDSImpl_Study::GetVariable(const string& theVarName)
+double SALOMEDSImpl_Study::GetVariableValue(const string& theVarName)
{
- std::map<std::string, SALOMEDSImpl_GenericVariable*>::const_iterator it =
- myNoteBookVars.find(theVarName);
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
- if(it != myNoteBookVars.end())
- if(SALOMEDSImpl_ScalarVariable* aVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>((*it).second))
- return aVar->getValue();
+ if(aGVar != NULL )
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
+ return aSVar->getValue();
}
//============================================================================
SALOMEDSImpl_GenericVariable::
VariableTypes theType) const
{
- std::map<std::string, SALOMEDSImpl_GenericVariable*>::const_iterator it =
- myNoteBookVars.find(theVarName);
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
- if(it != myNoteBookVars.end())
- return (*it).second->Type() == theType;
+ if(aGVar != NULL )
+ return aGVar->Type() == theType;
return false;
}
//============================================================================
bool SALOMEDSImpl_Study::IsVariable(const string& theVarName) const
{
- return myNoteBookVars.find(theVarName) != myNoteBookVars.end();
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+ return (aGVar != NULL);
}
//============================================================================
vector<string> SALOMEDSImpl_Study::GetVariableNames() const
{
vector<string> aResult;
- std::map<std::string, SALOMEDSImpl_GenericVariable*>::const_iterator it =
- myNoteBookVars.begin();
-
- for(; it != myNoteBookVars.end(); it++)
- aResult.push_back((*it).first);
+ for(int i = 0; i < myNoteBookVars.size(); i++)
+ aResult.push_back(myNoteBookVars[i]->Name());
+
return aResult;
}
* Purpose :
*/
//============================================================================
-void SALOMEDSImpl_Study::AddVariable(const string& theVarName,
- SALOMEDSImpl_GenericVariable* theVariable)
+void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
{
- myNoteBookVars[theVarName] = theVariable;
+ myNoteBookVars.push_back(theVariable);
+}
+
+//============================================================================
+/*! Function : AddVariable
+ * Purpose :
+ */
+//============================================================================
+SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
+{
+ SALOMEDSImpl_GenericVariable* aResult = NULL;
+ for(int i = 0; i < myNoteBookVars.size();i++) {
+ if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
+ aResult = myNoteBookVars[i];
+ break;
+ }
+ }
+ return aResult;
}
//============================================================================
std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
std::map<std::string, DF_Label> myIORLabels;
- std::map<std::string, SALOMEDSImpl_GenericVariable*> myNoteBookVars;
+ std::vector<SALOMEDSImpl_GenericVariable*> myNoteBookVars;
SALOMEDSImpl_SObject _FindObject(const SALOMEDSImpl_SObject& SO,
const std::string& anObjectName,
const std::string& anObjectIOR,
bool& _find);
+ std::string _GetStudyVariablesScript();
+ std::string _GetNoteBookAccessor();
+ std::string _GetNoteBookAccess();
+
public:
static SALOMEDSImpl_Study* GetStudy(const DF_Label& theLabel);
const double theValue,
const SALOMEDSImpl_GenericVariable::VariableTypes);
- double GetVariable(const std::string& theVarName);
+ double GetVariableValue(const std::string& theVarName);
bool IsTypeOf(const std::string& theVarName,
SALOMEDSImpl_GenericVariable::VariableTypes theType) const;
bool IsVariable(const std::string& theVarName) const;
+
std::vector<std::string> GetVariableNames() const;
- void AddVariable(const std::string& theVarName,
- SALOMEDSImpl_GenericVariable* theVariable);
-
+ void AddVariable(SALOMEDSImpl_GenericVariable* theVariable);
+
+ SALOMEDSImpl_GenericVariable* GetVariable(const std::string& theName) const;
//Returns a callback
SALOMEDSImpl_Callback* GetCallback() { return _cb; }
hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
hdf_notebook_vars->CreateOnDisk();
- map <std::string, SALOMEDSImpl_GenericVariable*>::const_iterator it =
- aStudy->myNoteBookVars.begin();
string varValue;
string varType;
- for( ;it != aStudy->myNoteBookVars.end(); it++ ){
+ for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){
// For each variable create HDF group
- hdf_notebook_var = new HDFgroup((char*)(*it).first.c_str(),hdf_notebook_vars);
+ hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
hdf_notebook_var->CreateOnDisk();
// Save Variable type
- varType = (*it).second->SaveType();
+ varType = aStudy->myNoteBookVars[i]->SaveType();
name_len = (hdf_int32) varType.length();
size[0] = name_len +1 ;
hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1);
hdf_dataset=0; //will be deleted by hdf_sco_group destructor
// Save Variable value
- varValue = (*it).second->Save();
+ varValue = aStudy->myNoteBookVars[i]->Save();
name_len = (hdf_int32) varValue.length();
size[0] = name_len +1 ;
hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1);
//Create variable and add it in the study
SALOMEDSImpl_GenericVariable* aVariable =
- new SALOMEDSImpl_ScalarVariable(aVarType);
+ new SALOMEDSImpl_ScalarVariable(aVarType,string(aVarName));
aVariable->Load(string(currentVarValue));
delete currentVarValue;
- theStudy->AddVariable(string(aVarName),aVariable);
+ theStudy->AddVariable(aVariable);
}
}
theGroup->CloseOnDisk();