*/
void SetBoolean( in string theVarName, in boolean theValue );
+/*! \brief Create string variable with Name theVarName and value theValue
+
+ (or set if variable value into theValue already exists)
+ \param theVarName is a name of the variable
+ \param theVarName is a value of the variable.
+*/
+ void SetString( in string theVarName, in string theValue );
+
+/*! \brief Set current value as double for string variable
+*/
+ void SetStringAsDouble( in string theVarName, in double theValue );
+
/*! \brief Get value of a real variable
\param theVarName is a name of the variable.
\param theVarName is a name of the variable.
*/
boolean GetBoolean( in string theVarName );
+
+/*! \brief Get value of a string variable
+
+ \param theVarName is a name of the variable.
+*/
+ string GetString( in string theVarName );
/*! \brief Indicate if a variable is real
*/
boolean IsBoolean( in string theVarName );
+/*! \brief Indicate if a variable is string
+
+ Return true if variable is string otherwise return false.
+ \param theVarName is a name of the variable.
+*/
+ boolean IsString( in string theVarName );
+
/*! \brief Indicate if a variable exists in the study
Return true if variable exists in the study,
import salome
+class PseudoStudyForNoteBook(object):
+
+ def __init__(self, **kwargs):
+ self.kwargs = kwargs
+ pass
+
+ def GetVariableNames(self):
+ return self.kwargs.keys()
+
+ def IsVariable(self, variableName):
+ return variableName in self.kwargs
+
+ def IsReal(self, variableName):
+ val = self.kwargs[variableName]
+ try:
+ float(val)
+ return True
+ except:
+ pass
+ return False
+
+ IsInteger = IsReal
+ IsBoolean = IsReal
+
+ def IsString(self, variableName):
+ return not self.IsReal(variableName)
+
+ def GetString(self, variableName):
+ return self.kwargs[variableName]
+
+ def GetReal(self, variableName):
+ return float(self.kwargs[variableName])
+
+ GetInteger = GetReal
+ GetBoolean = GetReal
+
+ pass
+
class NoteBook:
def __init__(self, Study):
elif type(variable) == bool:
self.myStudy.SetBoolean(variableName, variable)
+ elif type(variable) == str:
+ self.myStudy.SetString(variableName, variable)
+
def get(self, variableName):
"""
Return value of the variable with name "variableName".
elif self.myStudy.IsBoolean(variableName):
aResult = self.myStudy.GetBoolean(variableName)
+
+ elif self.myStudy.IsString(variableName):
+ aResult = self.myStudy.GetString(variableName)
+ aResult_orig = aResult
+ l = self.myStudy.GetVariableNames()
+ l.remove(variableName)
+ for name in l:
+ val = self.get(name)
+ import re
+ while 1:
+ m = re.search(r"\b(%s)\b"%name, aResult)
+ if not m: break
+ aResult = aResult[:m.start()] + "%s"%(val) + aResult[m.end():]
+ pass
+ pass
+ try:
+ aResult = eval(aResult)
+ except Exception, e:
+ msg = str(e)
+ msg += "\n"
+ msg += "A problem occurs while parsing "
+ msg += "the variable %s "%(variableName.__repr__())
+ msg += "with value %s ..."%(aResult_orig.__repr__())
+ msg += "\n"
+ msg += "Please, check your notebook !"
+ raise Exception(msg)
+ pass
return aResult
exists in the study, otherwise return false.
"""
return self.myStudy.IsVariable(variableName)
-
-notebook = NoteBook(salome.myStudy)
\ No newline at end of file
+
+ def setAs(self, variableName, typ):
+ value = self.get(variableName)
+ value = float(typ(value))
+ self.myStudy.SetStringAsDouble(variableName, value)
+ return
+
+ def setAsReal(self, variableName):
+ self.setAs(variableName, float)
+ return
+
+ def setAsInteger(self, variableName):
+ self.setAs(variableName, int)
+ return
+
+ def setAsBool(self, variableName):
+ self.setAs(variableName, bool)
+ return
+
+ def check(self):
+ for variableName in self.myStudy.GetVariableNames():
+ self.get(variableName)
+ pass
+ return
+
+ pass
+
+def checkThisNoteBook(**kwargs):
+ study = PseudoStudyForNoteBook(**kwargs)
+ note_book = NoteBook(study)
+ note_book.check()
+ return
+
+notebook = NoteBook(salome.myStudy)
_corba_impl->SetBoolean((char*)theVarName.c_str(),theValue);
}
+void SALOMEDS_Study::SetString(const string& theVarName, const string& theValue)
+{
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ _local_impl->SetStringVariable(theVarName,
+ theValue,
+ SALOMEDSImpl_GenericVariable::STRING_VAR);
+ }
+ else
+ _corba_impl->SetString((char*)theVarName.c_str(),(char*)theValue.c_str());
+}
+
+void SALOMEDS_Study::SetStringAsDouble(const string& theVarName, const double theValue)
+{
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ _local_impl->SetStringVariableAsDouble(theVarName,
+ theValue,
+ SALOMEDSImpl_GenericVariable::STRING_VAR);
+ }
+ else
+ _corba_impl->SetStringAsDouble((char*)theVarName.c_str(),theValue);
+}
+
double SALOMEDS_Study::GetReal(const string& theVarName)
{
double aResult;
return aResult;
}
+std::string SALOMEDS_Study::GetString(const string& theVarName)
+{
+ std::string aResult;
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ aResult = _local_impl->GetStringVariableValue(theVarName);
+ }
+ else
+ aResult = _corba_impl->GetString((char*)theVarName.c_str());
+ return aResult;
+}
+
bool SALOMEDS_Study::IsReal(const string& theVarName)
{
bool aResult;
return aResult;
}
+bool SALOMEDS_Study::IsString(const string& theVarName)
+{
+ bool aResult;
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ aResult = _local_impl->IsTypeOf(theVarName,
+ SALOMEDSImpl_GenericVariable::STRING_VAR);
+ }
+ else
+ aResult = _corba_impl->IsString((char*)theVarName.c_str());
+ return aResult;
+}
+
bool SALOMEDS_Study::IsVariable(const string& theVarName)
{
bool aResult;
virtual void SetReal(const std::string& theVarName, const double theValue);
virtual void SetInteger(const std::string& theVarName, const int theValue);
virtual void SetBoolean(const std::string& theVarName, const bool theValue);
+ virtual void SetString(const std::string& theVarName, const std::string& theValue);
+ virtual void SetStringAsDouble(const std::string& theVarName, const double theValue);
virtual double GetReal(const std::string& theVarName);
virtual int GetInteger(const std::string& theVarName);
virtual bool GetBoolean(const std::string& theVarName);
+ virtual std::string GetString(const std::string& theVarName);
virtual bool IsReal(const std::string& theVarName);
virtual bool IsInteger(const std::string& theVarName);
virtual bool IsBoolean(const std::string& theVarName);
+ virtual bool IsString(const std::string& theVarName);
virtual bool IsVariable(const std::string& theVarName);
virtual std::vector<std::string> GetVariableNames();
SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
}
+//============================================================================
+/*! Function : SetString
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
+{
+ _impl->SetStringVariable(string(theVarName),
+ theValue,
+ SALOMEDSImpl_GenericVariable::STRING_VAR);
+}
+
+//============================================================================
+/*! Function : SetStringAsDouble
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
+{
+ _impl->SetStringVariableAsDouble(string(theVarName),
+ theValue,
+ SALOMEDSImpl_GenericVariable::STRING_VAR);
+}
+
//============================================================================
/*! Function : GetReal
* Purpose :
return (bool)_impl->GetVariableValue(string(theVarName));
}
+//============================================================================
+/*! Function : GetString
+ * Purpose :
+ */
+//============================================================================
+char* SALOMEDS_Study_i::GetString(const char* theVarName)
+{
+ return CORBA::string_dup(_impl->GetStringVariableValue(string(theVarName)).c_str());
+}
+
//============================================================================
/*! Function : IsReal
* Purpose :
SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
}
+//============================================================================
+/*! Function : IsString
+ * Purpose :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
+{
+ return _impl->IsTypeOf(string(theVarName),
+ SALOMEDSImpl_GenericVariable::STRING_VAR);
+}
+
//============================================================================
/*! Function : IsVariable
* Purpose :
virtual void SetBoolean(const char* theVarName, CORBA::Boolean theValue);
+ virtual void SetString(const char* theVarName, const char* theValue);
+
+ virtual void SetStringAsDouble(const char* theVarName, CORBA::Double theValue);
+
virtual CORBA::Double GetReal(const char* theVarName);
virtual CORBA::Long GetInteger(const char* theVarName);
virtual CORBA::Boolean GetBoolean(const char* theVarName);
+ virtual char* GetString(const char* theVarName);
+
virtual CORBA::Boolean IsReal(const char* theVarName);
virtual CORBA::Boolean IsInteger(const char* theVarName);
virtual CORBA::Boolean IsBoolean(const char* theVarName);
+ virtual CORBA::Boolean IsString(const char* theVarName);
+
virtual CORBA::Boolean IsVariable(const char* theVarName);
virtual SALOMEDS::ListOfStrings* GetVariableNames();
virtual void SetReal(const std::string& theVarName, const double theValue) = 0;
virtual void SetInteger(const std::string& theVarName, const int theValue) = 0;
virtual void SetBoolean(const std::string& theVarName, const bool theValue) = 0;
+ virtual void SetString(const std::string& theVarName, const std::string& theValue) = 0;
+ virtual void SetStringAsDouble(const std::string& theVarName, const double theValue) = 0;
virtual double GetReal(const std::string& theVarName) = 0;
virtual int GetInteger(const std::string& theVarName) = 0;
virtual bool GetBoolean(const std::string& theVarName) = 0;
+ virtual std::string GetString(const std::string& theVarName) = 0;
virtual bool IsReal(const std::string& theVarName) = 0;
virtual bool IsInteger(const std::string& theVarName) = 0;
virtual bool IsBoolean(const std::string& theVarName) = 0;
+ virtual bool IsString(const std::string& theVarName) = 0;
virtual bool IsVariable(const std::string& theVarName) = 0;
virtual std::vector<std::string> GetVariableNames() = 0;
public:
//Supported types of the nootebook variables
- enum VariableTypes{REAL_VAR, INTEGER_VAR, BOOLEAN_VAR};
+ enum VariableTypes{REAL_VAR, INTEGER_VAR, BOOLEAN_VAR, STRING_VAR};
SALOMEDSImpl_GenericVariable(VariableTypes theType, const std::string& theName);
~SALOMEDSImpl_GenericVariable();
return true;
}
+//============================================================================
+/*! Function :
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_ScalarVariable::setStringValue(const string& theValue)
+{
+
+ if(myStrValue == theValue)
+ return false;
+
+ myStrValue = theValue;
+ return true;
+}
+
//============================================================================
/*! Function : getValue()
* Purpose :
return myValue;
}
+//============================================================================
+/*! Function : getStringValue()
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_ScalarVariable::getStringValue() const
+{
+ return myStrValue;
+}
+
//============================================================================
/*! Function : Save()
* Purpose :
sprintf(buffer, "%d", (int)myValue);
break;
}
+ case SALOMEDSImpl_GenericVariable::STRING_VAR:
+ {
+ sprintf(buffer, "\"%s\"", myStrValue.c_str());
+ break;
+ }
default:break;
}
return string(buffer);
sprintf(buffer, "%s", "False");
break;
}
+ case SALOMEDSImpl_GenericVariable::STRING_VAR:
+ {
+ sprintf(buffer, "\"%s\"", myStrValue.c_str());
+ break;
+ }
default:break;
}
return string(buffer);
bool setValue(const double theValue);
double getValue() const;
+ bool setStringValue(const std::string& theValue);
+ std::string getStringValue() const;
+
virtual std::string Save() const;
virtual std::string SaveToScript() const;
virtual std::string SaveType() const;
private:
double myValue;
+ std::string myStrValue;
};
Modify();
}
+//============================================================================
+/*! Function : SetStringVariable
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::SetStringVariable(const string& theVarName,
+ const string& theValue,
+ const SALOMEDSImpl_GenericVariable::VariableTypes theType)
+{
+ bool modified = false;
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+
+ if( aGVar == NULL ) {
+
+ SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
+
+ aSVar->setStringValue(theValue);
+ myNoteBookVars.push_back(aSVar);
+ modified = true;
+ }
+ else {
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
+ modified = aSVar->setStringValue(theValue) || modified;
+ modified = aSVar->setType(theType) || modified;
+ }
+ }
+ if(modified)
+ Modify();
+}
+
+//============================================================================
+/*! Function : SetStringVariableAsDouble
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::SetStringVariableAsDouble(const string& theVarName,
+ const double theValue,
+ const SALOMEDSImpl_GenericVariable::VariableTypes theType)
+{
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
+ aSVar->setValue(theValue);
+}
+
//============================================================================
/*! Function : GetReal
* Purpose :
return 0;
}
+//============================================================================
+/*! Function : GetString
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_Study::GetStringVariableValue(const string& theVarName)
+{
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+
+ if(aGVar != NULL )
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
+ return aSVar->getStringValue();
+
+ return 0;
+}
+
//============================================================================
/*! Function : IsTypeOf
* Purpose :
const double theValue,
const SALOMEDSImpl_GenericVariable::VariableTypes);
+ void SetStringVariable(const std::string& theVarName,
+ const std::string& theValue,
+ const SALOMEDSImpl_GenericVariable::VariableTypes);
+
+ void SetStringVariableAsDouble(const std::string& theVarName,
+ const double theValue,
+ const SALOMEDSImpl_GenericVariable::VariableTypes);
+
double GetVariableValue(const std::string& theVarName);
+ std::string GetStringVariableValue(const std::string& theVarName);
+
bool IsTypeOf(const std::string& theVarName,
SALOMEDSImpl_GenericVariable::VariableTypes theType) const;