+
+//============================================================================
+/*! Function : SetStudyLock
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
+{
+ _lockers.push_back(theLockerID);
+}
+
+//============================================================================
+/*! Function : IsStudyLocked
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::IsStudyLocked()
+{
+ return (_lockers.size() > 0);
+}
+
+//============================================================================
+/*! Function : UnLockStudy
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
+{
+ std::vector<std::string>::iterator vsI = _lockers.begin();
+ int length = _lockers.size();
+ bool isFound = false;
+ std::string id(theLockerID);
+ for(int i = 0; i<length; i++, vsI++) {
+ if(id == _lockers[i]) {
+ isFound = true;;
+ break;
+ }
+ }
+ if(isFound) _lockers.erase(vsI);
+}
+
+//============================================================================
+/*! Function : GetLockerID
+ * Purpose :
+ */
+//============================================================================
+std::vector<std::string> SALOMEDSImpl_Study::GetLockerID()
+{
+ return _lockers;
+}
+
+//============================================================================
+/*! Function : SetVariable
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::SetVariable(const std::string& theVarName,
+ const double 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->setValue(theValue);
+ myNoteBookVars.push_back(aSVar);
+ modified = true;
+ }
+ else {
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
+ modified = aSVar->setValue(theValue) || modified;
+ modified = aSVar->setType(theType) || modified;
+ }
+ }
+ if(modified)
+ Modify();
+}
+
+//============================================================================
+/*! Function : SetStringVariable
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::SetStringVariable(const std::string& theVarName,
+ const std::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 std::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 :
+ */
+//============================================================================
+double SALOMEDSImpl_Study::GetVariableValue(const std::string& theVarName)
+{
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+
+ if(aGVar != NULL )
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
+ return aSVar->getValue();
+
+ return 0;
+}
+
+//============================================================================
+/*! Function : GetString
+ * Purpose :
+ */
+//============================================================================
+std::string SALOMEDSImpl_Study::GetStringVariableValue(const std::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 :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::IsTypeOf(const std::string& theVarName,
+ SALOMEDSImpl_GenericVariable::
+ VariableTypes theType) const
+{
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+
+ if(aGVar != NULL )
+ return aGVar->Type() == theType;
+
+ return false;
+}
+
+//============================================================================
+/*! Function : IsVariable
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::IsVariable(const std::string& theVarName) const
+{
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+ return (aGVar != NULL);
+}
+
+//============================================================================
+/*! Function : GetVariableNames
+ * Purpose :
+ */
+//============================================================================
+std::vector<std::string> SALOMEDSImpl_Study::GetVariableNames() const
+{
+ std::vector<std::string> aResult;
+
+ for(int i = 0; i < myNoteBookVars.size(); i++)
+ aResult.push_back(myNoteBookVars[i]->Name());
+
+ return aResult;
+}
+
+//============================================================================
+/*! Function : AddVariable
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* 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;
+}
+
+//============================================================================
+/*! Function : RemoveVariable
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::RemoveVariable(const std::string& theVarName)
+{
+ SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
+ if( !aVariable )
+ return false;
+
+ std::string aValue = aVariable->SaveToScript();
+ ReplaceVariableAttribute( theVarName, aValue );
+
+ std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
+ for( ; it != itEnd; it++ )
+ {
+ SALOMEDSImpl_GenericVariable* aVariableRef = *it;
+ if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
+ {
+ myNoteBookVars.erase( it );
+ Modify();
+ break;
+ }
+ }
+
+ return true;
+}
+
+//============================================================================
+/*! Function : RenameVariable
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
+{
+ SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
+ if( !aVariable )
+ return false;
+
+ ReplaceVariableAttribute( theVarName, theNewVarName );
+
+ std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
+ for( ; it != itEnd; it++ )
+ {
+ SALOMEDSImpl_GenericVariable* aVariableRef = *it;
+ if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
+ {
+ aVariableRef->setName( theNewVarName );
+ Modify();
+ break;
+ }
+ }
+
+ return true;
+}
+
+//============================================================================
+/*! Function : IsVariableUsed
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::IsVariableUsed(const std::string& theVarName)
+{
+ return FindVariableAttribute( theVarName );
+}
+
+//============================================================================
+/*! Function : FindVariableAttribute
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
+ SALOMEDSImpl_SObject theSObject,
+ const std::string& theName)
+{
+ SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
+ for( ; anIter.More(); anIter.Next() )
+ if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
+ return true;
+
+ DF_Attribute* anAttr;
+ if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
+ {
+ if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
+ {
+ std::string aString = aStringAttr->Value();
+
+ std::vector< std::vector<std::string> > aSections = ParseVariables( aString );
+ for( int i = 0, n = aSections.size(); i < n; i++ )
+ {
+ std::vector<std::string> aVector = aSections[i];
+ for( int j = 0, m = aVector.size(); j < m; j++ )
+ {
+ std::string aStr = aVector[j];
+ if( aStr.compare( theName ) == 0 )
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+//============================================================================
+/*! Function : FindVariableAttribute
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
+{
+ SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
+ SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
+ for( ; aCompIter.More(); aCompIter.Next() )
+ {
+ SALOMEDSImpl_SObject aComp = aCompIter.Value();
+ if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
+ return true;
+ }
+ return false;
+}
+
+//============================================================================
+/*! Function : ReplaceVariableAttribute
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
+ SALOMEDSImpl_SObject theSObject,
+ const std::string& theSource,
+ const std::string& theDest)
+{
+ SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
+ for( ; anIter.More(); anIter.Next() )
+ ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
+
+ DF_Attribute* anAttr;
+ if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
+ {
+ if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
+ {
+ bool isChanged = false;
+ std::string aNewString, aCurrentString = aStringAttr->Value();
+
+ std::vector< std::vector<std::string> > aSections = ParseVariables( aCurrentString );
+ for( int i = 0, n = aSections.size(); i < n; i++ )
+ {
+ std::vector<std::string> aVector = aSections[i];
+ for( int j = 0, m = aVector.size(); j < m; j++ )
+ {
+ std::string aStr = aVector[j];
+ if( aStr.compare( theSource ) == 0 )
+ {
+ isChanged = true;
+ aStr = theDest;
+ }
+
+ aNewString.append( aStr );
+ if( j != m - 1 )
+ aNewString.append( ":" );
+ }
+ if( i != n - 1 )
+ aNewString.append( "|" );
+ }
+
+ if( isChanged )
+ aStringAttr->SetValue( aNewString );
+ }
+ }
+}
+
+//============================================================================
+/*! Function : ReplaceVariableAttribute
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
+{
+ SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
+ SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
+ for( ; aCompIter.More(); aCompIter.Next() )
+ {
+ SALOMEDSImpl_SObject aComp = aCompIter.Value();
+ ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
+ }
+}
+
+//============================================================================
+/*! Function : ParseVariables
+ * Purpose :
+ */
+//============================================================================
+std::vector< std::vector< std::string > > SALOMEDSImpl_Study::ParseVariables(const std::string& theVariables) const
+{
+ return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
+}
+
+//============================================================================
+/*! Function : EnableUseCaseAutoFilling
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
+{
+ _errorCode = ""; _autoFill = isEnabled;
+ if(isEnabled) {
+ _builder->SetOnAddSObject(_cb);
+ _builder->SetOnRemoveSObject(_cb);
+ }
+ else {
+ _builder->SetOnAddSObject(NULL);
+ _builder->SetOnRemoveSObject(NULL);
+ }
+}
+
+//============================================================================
+/*! Function : GetIORs
+ * Purpose :
+ */
+//============================================================================
+std::vector<std::string> SALOMEDSImpl_Study::GetIORs()
+{
+ std::vector<std::string> anIORs;
+ std::map<std::string, DF_Label>::const_iterator MI;
+ for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
+ anIORs.push_back(MI->first);
+
+ return anIORs;
+}
+
+//============================================================================
+/*! Function : addSO_Notification
+ * Purpose : This function tells all the observers that a SO has been added
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject)
+{
+ if(_notifier)
+ return _notifier->addSO_Notification(theSObject);
+ else
+ return false;
+}
+
+//============================================================================
+/*! Function : removeSO_Notification
+ * Purpose : This function tells all the observers that a SO has been removed
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject)
+{
+ if(_notifier)
+ return _notifier->removeSO_Notification(theSObject);
+ else
+ return false;
+}
+
+//============================================================================
+/*! Function : modifySO_Notification
+ * Purpose : This function tells all the observers that a SO has been modified and
+ pass the mofification reason
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject, int reason)
+{
+ if(_notifier)
+ return _notifier->modifySO_Notification(theSObject, reason);
+ else
+ return false;
+}
+
+//============================================================================
+/*! Function : setNotifier
+ * Purpose : register a notifier
+ */
+//============================================================================
+void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier)
+{
+ _notifier=notifier;
+}
+
+static SALOMEDSImpl_AbstractCallback* & getGenObjRegister( DF_Document* doc )
+{
+ static std::vector< SALOMEDSImpl_AbstractCallback* > _genObjRegVec;
+ if ( doc->GetDocumentID() >= (int)_genObjRegVec.size() )
+ _genObjRegVec.resize( doc->GetDocumentID() + 1, 0 );
+ return _genObjRegVec[ doc->GetDocumentID() ];
+}
+
+//================================================================================
+/*!
+ * \brief Stores theRegister
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister)
+{
+ getGenObjRegister( _doc ) = theRegister;
+}
+
+//================================================================================
+/*!
+ * \brief Indirectly invokes GenericObj_i::Register()
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::RegisterGenObj (const std::string& theIOR, DF_Label label)
+{
+ if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
+ goRegister->RegisterGenObj( theIOR );
+}
+
+//================================================================================
+/*!
+ * \brief Indirectly invokes GenericObj_i::UnRegister()
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::UnRegisterGenObj(const std::string& theIOR, DF_Label label)
+{
+ if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
+ goRegister->UnRegisterGenObj( theIOR );
+}