Salome HOME
Multi-study support removal: finalization
authorakl <alexander.kovalev@opencascade.com>
Tue, 23 Sep 2014 08:21:50 +0000 (12:21 +0400)
committervsr <vsr@opencascade.com>
Wed, 1 Oct 2014 13:23:23 +0000 (17:23 +0400)
bin/runSalome.py
idl/SALOMEDS.idl
src/KERNEL_PY/__init__.py
src/KERNEL_PY/salome_kernel.py
src/KERNEL_PY/salome_study.py
src/SALOMEDS/CMakeLists.txt
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx

index c819b857c8513c044d2a650d8e4e63e69cbf26d6..f66b12939db0978ef6d421c82984cd02abe28040 100755 (executable)
@@ -738,11 +738,15 @@ def useSalome(args, modules_list, modules_root_dir):
 
         # run python scripts, passed as command line arguments
         toimport = []
-        if args.has_key('pyscript'):
-            if args.has_key('gui') and args.has_key('session_gui'):
-                if not args['gui'] or not args['session_gui']:
+        if args.has_key('gui') and args.has_key('session_gui'):
+            if not args['gui'] or not args['session_gui']:
+                if args.has_key('study_hdf'):
+                    toopen = args['study_hdf']
+                    if toopen:
+                        import salome
+                        salome.salome_init(toopen)
+                if args.has_key('pyscript'):
                     toimport = args['pyscript']
-
         from salomeContextUtils import formatScriptsAndArgs
         command = formatScriptsAndArgs(toimport)
         if command:
index 2fcb127bc0dbc4a06cce2b75f69d7f7ba45409d2..9bf7b9ccfea6a843b909c438eae420f4582b38c3 100644 (file)
@@ -125,6 +125,8 @@ during each working session.
   interface Study
   {
 
+//! Invalid study reference
+    exception StudyInvalidReference {};
 //! Invalid study context
     exception StudyInvalidContext {};
 //! Invalid study component
@@ -153,15 +155,15 @@ during each working session.
 //! Sequence containing %SObjects
     typedef sequence<SObject> ListOfSObject;
 //!  Get the persistent reference to the %Study.
-    PersistentReference  GetPersistentReference();
+    PersistentReference  GetPersistentReference() raises(StudyInvalidReference);
 //! Get a transient reference to the %Study.
-    SalomeReference      GetTransientReference();
+    SalomeReference      GetTransientReference() raises(StudyInvalidReference);
 
 /*! \brief indicate whether the %Study is empty
 
     \return True if the %Study is empty
 */
-    boolean IsEmpty();
+    boolean IsEmpty() raises(StudyInvalidReference);
 /*! \brief  Find a %SComponent by its name.
 
    \param aComponentName    It's a string value in the Comment Attribute of the Component,
@@ -170,11 +172,11 @@ during each working session.
 <em>See \ref example1 for an example of this method usage in batchmode of %SALOME application.</em>
 
 */
-    SComponent FindComponent  (in string aComponentName);
+    SComponent FindComponent  (in string aComponentName) raises(StudyInvalidReference);
 
 /*! \brief  Find a %SComponent by ID of the according %SObject
 */
-    SComponent FindComponentID(in ID aComponentID);
+    SComponent FindComponentID(in ID aComponentID) raises(StudyInvalidReference);
 /*! \brief  Find a %SObject by the Name Attribute of this %SObject
 
     \param anObjectName String parameter defining the name of the object
@@ -182,40 +184,40 @@ during each working session.
 
 <em>See \ref example19 for an example of this method usage in batchmode of %SALOME application.</em>
 */
-    SObject       FindObject      (in string anObjectName);
+    SObject       FindObject      (in string anObjectName) raises(StudyInvalidReference);
 /*! \brief  Find a %SObject by its ID
 
     \param aObjectID This parameter defines the ID of the required object
     \return The obtained %SObject
 */
-    SObject       FindObjectID    (in ID aObjectID);
+    SObject       FindObjectID    (in ID aObjectID) raises(StudyInvalidReference);
 /*! \brief Create a %SObject by its ID
 
     \param aObjectID This parameter defines the ID of the required object
     \return The created %SObject
 */
-    SObject       CreateObjectID    (in ID aObjectID);
+    SObject       CreateObjectID    (in ID aObjectID) raises(StudyInvalidReference);
 /*!  \brief Find a %SObject by IOR of the object belonging to this %SObject.
 
     \param anObjectName This parameter defines the IOR of the object
     \return The obtained %SObject
 */
-    SObject       FindObjectIOR   (in ID aObjectIOR);
+    SObject       FindObjectIOR   (in ID aObjectIOR) raises(StudyInvalidReference);
 /*! \brief  Find in the study all %SObjects produced by a given %Component.
 
     \param anObjectName The Name Attribute of the searched %SObjects should correspond to <VAR>anObjectName</VAR>.
     \param aComponentName The name of the component, which objects are searched for.
 */
-    ListOfSObject FindObjectByName(in string anObjectName, in string aComponentName);
+    ListOfSObject FindObjectByName(in string anObjectName, in string aComponentName) raises(StudyInvalidReference);
 /*! \brief  Find a %SObject by the path to it.
 
     \param thePath The path to the required %SObject.
     \return The obtained %SObject.
 */
-    SObject FindObjectByPath(in string thePath);
+    SObject FindObjectByPath(in string thePath) raises(StudyInvalidReference);
 /*! \brief Get the path to the %SObject.
 */
-    string  GetObjectPath(in Object theObject);
+    string GetObjectPath(in Object theObject) raises(StudyInvalidReference);
 
 /*! \brief  Set the context of the %Study.
 
@@ -223,44 +225,44 @@ during each working session.
 
 <em>See \ref example23 for an example of this method usage in batchmode of %SALOME application.</em>
 */
-    void SetContext(in string thePath);
+    void SetContext(in string thePath) raises (StudyInvalidReference, StudyInvalidContext);
 /*!  \brief Get the context of the %Study.
     
 <em>See \ref example23 for an example of this method usage in batchmode of %SALOME application.</em>
 */
-    string GetContext();
+    string GetContext() raises (StudyInvalidReference, StudyInvalidContext);
 /*!  \brief Get a list of names of objects corresponding to the context.
 
    \note  If the parameter <VAR>theContext</VAR> is empty, then the current context will be used.
 */
-    ListOfStrings GetObjectNames(in string theContext);
+    ListOfStrings GetObjectNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext);
 /*! \brief Get a list of names of directories and subdirectories corresponding to the context.
 
    \note  If the parameter <VAR>theContext</VAR> is empty, then the current context will be used.
 */
-    ListOfStrings GetDirectoryNames(in string theContext);
+    ListOfStrings GetDirectoryNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext);
 /*! \brief  Get a list of names of Files corresponding to the context.
 
     \note  If the parameter <VAR>theContext</VAR> is empty, then the current context will be used.
 */
-    ListOfStrings GetFileNames(in string theContext);
+    ListOfStrings GetFileNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext);
 /*! \brief Get a list of names of Components corresponding to the context.
 
    \note  If the parameter <VAR>theContext</VAR> is empty, then the current context will be used.
 */
-    ListOfStrings GetComponentNames(in string theContext);
+    ListOfStrings GetComponentNames(in string theContext) raises(StudyInvalidReference);
 /*!  \brief Create a new iterator of child levels of the given %SObject.
 
     \param aSO The given %SObject
     \return A new iterator of child levels of the given %SObject.
 */
-    ChildIterator      NewChildIterator(in SObject aSO);
+    ChildIterator NewChildIterator(in SObject aSO) raises(StudyInvalidReference);
 
 /*!  \brief Create a new iterator of the %SComponents.
 
     \return A new iterator of the %SComponents.
 */
-    SComponentIterator NewComponentIterator();
+    SComponentIterator NewComponentIterator() raises(StudyInvalidReference);
 
 /*! \brief  Create a new %StudyBuilder to add or modify an object in the study.
 
@@ -268,12 +270,12 @@ during each working session.
 
 <em>See \ref example20 for an example of this method usage in batchmode of %SALOME application.</em>
 */
-    StudyBuilder NewBuilder() ;
+    StudyBuilder NewBuilder() raises(StudyInvalidReference);
 /*! \brief Labels dependency
 
     Updates the map with IOR attribute. It's an inner method used for optimization.
 */
-    void UpdateIORLabelMap(in string anIOR, in string anEntry);
+    void UpdateIORLabelMap(in string anIOR, in string anEntry) raises(StudyInvalidReference);
 
 /*! \brief Getting properties of the study
 
@@ -282,7 +284,7 @@ during each working session.
 <em>See \ref example20 for an example of this method usage in batchmode of %SALOME application.</em>
 
 */
-    AttributeStudyProperties GetProperties();
+    AttributeStudyProperties GetProperties() raises(StudyInvalidReference);
 /*! \brief  Indicate whether the %study has been saved
 */
     attribute boolean IsSaved;
@@ -290,33 +292,33 @@ during each working session.
 
   Returns True if the %study has been modified and not saved.
 */
-    boolean IsModified();
+    boolean IsModified() raises(StudyInvalidReference);
 
 /*! \brief  Mark the %study as being modified and not saved.
 */
-    void Modified();
+    void Modified() raises(StudyInvalidReference);
 
 /*! \brief  Indicate the file where the %study has been saved
 */
-    attribute string  URL;
+    attribute string URL;
 
 /*! \brief List of %SObjects
 
     Returns the list of %SObjects which refers to %anObject.
 */
-    ListOfSObject FindDependances(in SObject anObject);
+    ListOfSObject FindDependances(in SObject anObject) raises(StudyInvalidReference);
 
 /*! \brief The date of the last saving of the study
 
     Returns the date of the last saving of study with format: "DD/MM/YYYY HH:MM"
 */
-    string GetLastModificationDate();
+    string GetLastModificationDate() raises(StudyInvalidReference);
 /*! \brief The list of modification dates of the study
 
     Returns the list of modification dates (without creation date) with format "DD/MM/YYYY HH:MM".
       Note : the first modification begins the list.
 */
-    ListOfDates GetModificationsDate();
+    ListOfDates GetModificationsDate() raises(StudyInvalidReference);
 /*! \brief Object conversion.
 
     Converts an object into IOR.
@@ -332,38 +334,38 @@ during each working session.
 
 /*!  \brief Get a new %UseCaseBuilder.
 */
-    UseCaseBuilder  GetUseCaseBuilder();
+    UseCaseBuilder  GetUseCaseBuilder() raises(StudyInvalidReference);
 
 /*! \brief  Close the components in the study, remove itself from the %StudyManager.
 */
-    void Close();
+    void Close() raises(StudyInvalidReference);
 
 /*! \brief  Enable (if isEnabled = True)/disable automatic addition of new %SObjects to the use case.
 */
-    void EnableUseCaseAutoFilling(in boolean isEnabled);
+    void EnableUseCaseAutoFilling(in boolean isEnabled) raises(StudyInvalidReference);
 
 /*!
     Functions for internal usage only
 */
-    void AddPostponed(in string theIOR);
+    void AddPostponed(in string theIOR) raises(StudyInvalidReference);
 
-    void AddCreatedPostponed(in string theIOR);
+    void AddCreatedPostponed(in string theIOR) raises(StudyInvalidReference);
 
-    void RemovePostponed(in long theUndoLimit);
+    void RemovePostponed(in long theUndoLimit) raises(StudyInvalidReference);
 
-    void UndoPostponed(in long theWay);
+    void UndoPostponed(in long theWay) raises(StudyInvalidReference);
 
     boolean DumpStudy(in string thePath,
                       in string theBaseName,
                       in boolean isPublished,
-                      in boolean isMultiFile);
+                      in boolean isMultiFile) raises(StudyInvalidReference);
 
 /*! \brief  Get an AttributeParameter used to store common parameters for given %theSavePoint.
 
     \param theID identifies a common parameters set (Example: "Interface Applicative")
     \param theSavePoint is number of a set of parameters as there can be several sets
 */
-    AttributeParameter GetCommonParameters(in string theID, in long theSavePoint);
+    AttributeParameter GetCommonParameters(in string theID, in long theSavePoint) raises(StudyInvalidReference);
 
 /*! \brief  Get an AttributeParameter used to store parameters for given %theModuleName.
 
@@ -371,7 +373,7 @@ during each working session.
     \param theModuleName is a name of the module (Example: "Geometry")
     \param theSavePoint is number of a set of parameters as there can be several sets
 */
-    AttributeParameter GetModuleParameters(in string theID, in string theModuleName, in long theSavePoint);
+    AttributeParameter GetModuleParameters(in string theID, in string theModuleName, in long theSavePoint) raises(StudyInvalidReference);
 
 
 /*! \brief Get a default Python script to restore visual parameters for given %theModuleName.
@@ -379,7 +381,7 @@ during each working session.
     \param theModuleName is a name of the module (Example: "Geometry")
     \param indent is a string to use for script indentation
 */
-    string GetDefaultScript(in string theModuleName, in string indent);
+    string GetDefaultScript(in string theModuleName, in string indent) raises(StudyInvalidReference);
 
 /*!
     Private method, returns an implementation of this Study.
@@ -395,24 +397,24 @@ during each working session.
     The lock status can be checked by method IsStudyLocked
     \param theLockerID identifies a locker of the study can be for ex. IOR of the engine that locks the study.
 */
-    void SetStudyLock(in string theLockerID);
+    void SetStudyLock(in string theLockerID) raises(StudyInvalidReference);
 
 /*! \brief Indicate if the Study is locked
 
    Returns True if the Study was marked locked. 
 */
-    boolean IsStudyLocked();
+    boolean IsStudyLocked() raises(StudyInvalidReference);
 
 /*! \brief  Mark this Study as being unlocked by the given locker. 
 
      The lock status can be checked by method IsStudyLocked
     \param theLockerID identifies a locker of the study can be for ex. IOR of the engine that unlocks the study.
 */
-    void UnLockStudy(in string theLockerID);
+    void UnLockStudy(in string theLockerID) raises(StudyInvalidReference);
 
 /*! \brief  Get the list of IDs of the Study's lockers. 
 */
-    ListOfStrings GetLockerID();
+    ListOfStrings GetLockerID() raises(StudyInvalidReference);
 
 /*! \brief  Create real variable with Name theVarName and value theValue 
 
@@ -420,7 +422,7 @@ during each working session.
     \param theVarName is a name of the variable
     \param theVarName is a value of the variable.
 */
-    void SetReal( in string theVarName, in double theValue );
+    void SetReal( in string theVarName, in double theValue ) raises(StudyInvalidReference);
 
 /*! \brief  Create integer variable with Name theVarName and value theValue 
 
@@ -428,14 +430,14 @@ during each working session.
     \param theVarName is a name of the variable
     \param theVarName is a value of the variable.
 */
-    void SetInteger( in string theVarName, in long theValue );
+    void SetInteger( in string theVarName, in long theValue ) raises(StudyInvalidReference);
 /*! \brief  Create boolean 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 SetBoolean( in string theVarName, in boolean theValue );
+    void SetBoolean( in string theVarName, in boolean theValue ) raises(StudyInvalidReference);
 
 /*! \brief  Create string variable with Name theVarName and value theValue 
 
@@ -443,35 +445,35 @@ during each working session.
     \param theVarName is a name of the variable
     \param theVarName is a value of the variable.
 */
-    void SetString( in string theVarName, in string theValue );
+    void SetString( in string theVarName, in string theValue ) raises(StudyInvalidReference);
 
 /*! \brief  Set current value as double for string variable
 */
-    void SetStringAsDouble( in string theVarName, in double theValue );
+    void SetStringAsDouble( in string theVarName, in double theValue ) raises(StudyInvalidReference);
 
 /*! \brief Get value of a real variable
 
     \param theVarName is a name of the variable.
 */
-    double GetReal( in string theVarName );
+    double GetReal( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Get value of an integer variable
 
     \param theVarName is a name of the variable.
 */
-    long GetInteger( in string theVarName );
+    long GetInteger( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Get value of a boolean variable
 
     \param theVarName is a name of the variable.
 */
-    boolean GetBoolean( in string theVarName );
+    boolean GetBoolean( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Get value of a string variable
 
     \param theVarName is a name of the variable.
 */
-    string GetString( in string theVarName );
+    string GetString( in string theVarName ) raises(StudyInvalidReference);
     
 
 /*! \brief Indicate if a variable is real
@@ -479,28 +481,28 @@ during each working session.
     Return true if variable is real otherwise return false.
     \param theVarName is a name of the variable.
 */
-    boolean IsReal( in string theVarName );
+    boolean IsReal( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Indicate if a variable is integer
 
     Return true if variable is integer otherwise return false.
     \param theVarName is a name of the variable.
 */
-    boolean IsInteger( in string theVarName );
+    boolean IsInteger( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Indicate if a variable is boolean
 
     Return true if variable is boolean otherwise return false.
     \param theVarName is a name of the variable.
 */
-    boolean IsBoolean( in string theVarName );
+    boolean IsBoolean( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \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 );
+    boolean IsString( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Indicate if a variable exists in the study
 
@@ -508,11 +510,11 @@ during each working session.
     otherwise return false.
     \param theVarName is a name of the variable.
 */
-    boolean IsVariable( in string theVarName );
+    boolean IsVariable( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Get names of all variables from the study.
 */
-    ListOfStrings GetVariableNames();
+    ListOfStrings GetVariableNames() raises(StudyInvalidReference);
 
 /*! \brief Remove a variable
 
@@ -521,7 +523,7 @@ during each working session.
    \param theVarName Name of the variable.
    \return Status of operation.
 */
-    boolean RemoveVariable( in string theVarName );
+    boolean RemoveVariable( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Rename a variable
 
@@ -531,7 +533,7 @@ during each working session.
    \param theNewVarName New name for the variable.
    \return Status of operation.
 */
-    boolean RenameVariable( in string theVarName, in string theNewVarName );
+    boolean RenameVariable( in string theVarName, in string theNewVarName ) raises(StudyInvalidReference);
 
 /*! \brief Indicate whether variable is used
 
@@ -540,14 +542,14 @@ during each working session.
    \param theVarName Name of the variable.
    \return Variable usage.
 */
-    boolean IsVariableUsed( in string theVarName );
+    boolean IsVariableUsed( in string theVarName ) raises(StudyInvalidReference);
 
 /*! \brief Parse variables used for object creation
 
    \param string with variables, separated by special symbol. 
    \return Variables list.
 */
-    ListOfListOfStrings ParseVariables( in string theVars );
+    ListOfListOfStrings ParseVariables( in string theVars ) raises(StudyInvalidReference);
 
 /*!
      Attach an observer to the Study
index 6933a14f297e9170f1e0ecd6329e5a38ac2e69b0..7c779f2ff42143be0da077ec71311d6d8fe160c4 100755 (executable)
@@ -221,7 +221,7 @@ def salome_init(theStudyId=0,embedded=0):
             salome_initial=0
             sg = salome_iapp_init(embedded)
             orb, lcc, naming_service, cm = salome_kernel_init()
-            myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init(theStudyId)
+            myStudyManager, myStudyId, myStudy, myStudyName = salome_study_init(theStudyId)
             pass
         pass
     except RuntimeError, inst:
@@ -238,13 +238,18 @@ def salome_init(theStudyId=0,embedded=0):
         ============================================
         """
         raise
-
+    
 def salome_close():
-    global salome_initial
+    global salome_initial, myStudy, myStudyId, myStudyName
+    try:
+        # study can be closed either from GUI or directly with salome.myStudy.Close()
+        myStudy.Close()
+    except:
+        pass
     salome_initial=1
     salome_iapp_close()
-    salome_kernel_close()
     salome_study_close()
+    myStudyId, myStudy, myStudyName=None,None,None
     pass
 
 
index 9824f788be8220efcee3240e1536d5765e8b647c..0f6f62720c4220fb7bc42c7026b15201cecc390b 100755 (executable)
@@ -32,15 +32,15 @@ from SALOME_NamingServicePy import *
 from SALOME_utilities import *
 import Engines
 
-salome_kernel_initial=1
+orb = None
+lcc = None
+naming_service = None
+cm = None
 
 def salome_kernel_init():
-    global salome_kernel_initial
     global orb, lcc, naming_service, cm
     
-    if salome_kernel_initial:
-        salome_kernel_initial = 0
-        
+    if not orb:
         # initialise the ORB
         orb = CORBA.ORB_init([''], CORBA.ORB_ID)
 
@@ -55,8 +55,3 @@ def salome_kernel_init():
         cm = obj._narrow(Engines.ContainerManager)
 
     return orb, lcc, naming_service, cm
-
-def salome_kernel_close():
-    global salome_kernel_initial
-    salome_kernel_initial=1
-    pass
index 29ba67d032871cf78eba9da6cde40be6fcc56d25..ae3853675be40ab20a8ce79812f167ccc1c49a33 100755 (executable)
@@ -31,6 +31,11 @@ import SALOMEDS
 import salome_iapp
 from launchConfigureParser import verbose
 
+myStudyManager = None
+myStudyId = None
+myStudy = None
+myStudyName = None
+
 #--------------------------------------------------------------------------
 
 def DumpComponent(Study, SO, Builder,offset):
@@ -70,8 +75,9 @@ def DumpStudies():
   """
     Dump all studies in a StudyManager
   """
+  global myStudyManager
   for name in myStudyManager.GetOpenStudies():
-    s=myStudyManager.GetStudyByName(name)
+    s = myStudyManager.GetStudyByName(name)
     print "study:",name, s._get_StudyId()
     DumpStudy(s)
 
@@ -79,6 +85,7 @@ def DumpStudies():
 #--------------------------------------------------------------------------
 
 def IDToObject(id):
+    global myStudy
     myObj = None
     mySO = myStudy.FindObjectID(id);
     if mySO is not None:
@@ -104,6 +111,7 @@ def ObjectToID(obj):
     return ""
 
 def IDToSObject(id):
+    global myStudy
     mySO = myStudy.FindObjectID(id);
     return mySO
 
@@ -178,6 +186,7 @@ def PersistentPresentation(theStudy, theSO, theWithID):
 
 def GetTree(theSO):
     # returns the document list tree (as list)
+    global myStudy
     aResult = [theSO.GetID()]
     anIter = myStudy.NewChildIterator(theSO)
     while anIter.More():
@@ -188,6 +197,8 @@ def GetTree(theSO):
     #--------------------------------------------------------------------------
 
 def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
+    global myStudyManager, myStudy
+
     aRoot = theSO
     while aRoot.GetID() != "0:":
         aRoot = aRoot.GetFather()
@@ -229,6 +240,7 @@ def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
 
 def GetComponentVersion(theComponent, all_versions = False):
     # returns the document list tree (as list)
+    global myStudy
     props = myStudy.GetProperties()
     stored_components = props.GetStoredComponents()
     version = "no component data" # vsr: better raise an exception in this case?
@@ -269,31 +281,27 @@ def FindFileInDataDir(filename):
 
 salome_study_ID = -1
 
-def getActiveStudy(theStudyId=0):
+# *args are used here to support backward compatibility
+# previously it was possible to pass theStudyId parameter to this function
+# which is no more supported.
+def getActiveStudy(*args):
+    global myStudyManager
     global salome_study_ID
 
+    if not myStudyManager:
+        print "No active study"
+        return None
+        pass
+
     if verbose(): print "getActiveStudy"
     if salome_study_ID == -1:
-        if salome_iapp.hasDesktop():
-            if verbose(): print "---in gui"
-            salome_study_ID = salome_iapp.sg.getActiveStudyId()
+        listOpenStudies = myStudyManager.GetOpenStudies()
+        if len(listOpenStudies) == 0:
+            return None
         else:
-            if verbose(): print "---outside gui"
-            if theStudyId:
-                aStudy=myStudyManager.GetStudyByID(theStudyId)
-                if aStudy:
-                    if verbose(): print "connection to existing study ", theStudyId
-                    salome_study_ID = theStudyId
-            if salome_study_ID == -1:
-                listOpenStudies = myStudyManager.GetOpenStudies()
-                if len(listOpenStudies) == 0:
-                    salome_study_ID = createNewStudy()
-                else:
-                    s = myStudyManager.GetStudyByName(listOpenStudies[0])
-                    salome_study_ID = s._get_StudyId()
-            else:
-                pass
-            if verbose(): print"--- Study Id ", salome_study_ID
+            s = myStudyManager.GetStudyByName(listOpenStudies[0])
+            salome_study_ID = s._get_StudyId()
+    if verbose(): print"--- Study Id ", salome_study_ID
     return salome_study_ID
 
     #--------------------------------------------------------------------------
@@ -303,50 +311,51 @@ def setCurrentStudy(theStudy):
     Change current study : an existing one given by a study object.
 
     :param theStudy: the study CORBA object to set as current study
+
+    Obsolete: only one study can be opened at the moment.
+    This function works properly if specified theStudy parameter
+    corresponds to the currently opened study.
+    Kept for backward compatibility only.
     """
     global myStudyId, myStudy, myStudyName
     global salome_study_ID
-    myStudy=theStudy
-    myStudyId=theStudy._get_StudyId()
-    myStudyName=theStudy._get_Name()
+    myStudy = theStudy
+    myStudyId = theStudy._get_StudyId()
+    myStudyName = theStudy._get_Name()
     return myStudyId, myStudy, myStudyName
 
     #--------------------------------------------------------------------------
 
-def setCurrentStudyId(theStudyId=0):
+# *args are used here to support backward compatibility
+# previously it was possible to pass theStudyId parameter to this function
+# which is no more supported.
+def setCurrentStudyId(*args):
     """
     Change current study : an existing or new one.
-    optional argument : theStudyId
-        0      : create a new study (default).
-        n (>0) : try connection to study with Id = n, or create a new one
-                 if study not found.
+
+    This function connects to the single opened study if there is any; otherwise
+    new empty study is created.
+
+    Obsolete: only one study can be opened at the moment.
+    Kept for backward compatibility only.
     """
-    global myStudyId, myStudy, myStudyName
+    global myStudyManager, myStudyId, myStudy, myStudyName
     global salome_study_ID
     salome_study_ID = -1
-    myStudyId = getActiveStudy(theStudyId)
+    myStudyId = getActiveStudy()
+    if not myStudyId:
+      myStudyId = createNewStudy()
     if verbose(): print "myStudyId",myStudyId
     myStudy = myStudyManager.GetStudyByID(myStudyId)
     myStudyName = myStudy._get_Name()
-
     return myStudyId, myStudy, myStudyName
 
     #--------------------------------------------------------------------------
 
 def createNewStudy():
+    global myStudyManager
     print "createNewStudy"
-    i=1
-    aStudyName = "noName"
-    nameAlreadyInUse = 1
-    listOfOpenStudies = myStudyManager.GetOpenStudies()
-    print listOfOpenStudies
-    while nameAlreadyInUse:
-        aStudyName = "extStudy_%d"%i
-        if aStudyName not in listOfOpenStudies:
-            nameAlreadyInUse=0
-        else:
-            i = i+1
-
+    aStudyName = "extStudy"
     theStudy = myStudyManager.NewStudy(aStudyName)
     theStudyId = theStudy._get_StudyId()
     print aStudyName, theStudyId
@@ -354,26 +363,29 @@ def createNewStudy():
 
     #--------------------------------------------------------------------------
 
-salome_study_initial = 1
+def openStudy(theStudyPath):
+    global myStudyManager
+    print "openStudy"
+    theStudy = myStudyManager.Open(theStudyPath)
+    theStudyId = theStudy._get_StudyId()
+    print theStudyPath, theStudyId
+    return theStudyId
+
+    #--------------------------------------------------------------------------
 
-def salome_study_init(theStudyId=0):
+def salome_study_init(theStudyPath=None):
     """
     Performs only once study creation or connection.
-    optional argument : theStudyId
-      When in embedded interpreter inside IAPP, theStudyId is not used
-      When used without GUI (external interpreter)
-        0      : create a new study (default).
-        n (>0) : try connection to study with Id = n, or create a new one
-                 if study not found.
+    optional argument : theStudyPath
+        None        : attach to the currently active single study;
+                      create new empty study if there is active study
+        <URL> (str) : open study with the given file name
     """
-
-    global salome_study_initial
     global myStudyManager, myStudyId, myStudy, myStudyName
     global orb, lcc, naming_service, cm
 
-    if salome_study_initial:
-        salome_study_initial = 0
-
+    if verbose(): print "theStudyPath:", theStudyPath
+    if not myStudyManager:
         orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init()
 
         # get Study Manager reference
@@ -381,17 +393,28 @@ def salome_study_init(theStudyId=0):
         obj = naming_service.Resolve('myStudyManager')
         myStudyManager = obj._narrow(SALOMEDS.StudyManager)
         if verbose(): print "studyManager found"
+        pass
 
-        # get active study Id, ref and name
-        myStudyId = getActiveStudy(theStudyId)
-        if verbose(): print "myStudyId",myStudyId
+    # get active study Id, ref and name
+    myStudy = None
+    myStudyId = getActiveStudy()
+    if myStudyId == None :
+        import types
+        if theStudyPath and type(theStudyPath) == types.StringType:
+            myStudyId = openStudy(theStudyPath)
+        else:
+            myStudyId = createNewStudy()
+    if verbose(): print "myStudyId", myStudyId
+
+    if myStudy == None:
         myStudy = myStudyManager.GetStudyByID(myStudyId)
-        myStudyName = myStudy._get_Name()
+    myStudyName = myStudy._get_Name()
 
     return myStudyManager, myStudyId, myStudy, myStudyName
 
 def salome_study_close():
-    global salome_study_initial, salome_study_ID
-    salome_study_initial=1
-    salome_study_ID=-1
+    global salome_study_ID
+    global myStudyId, myStudy, myStudyName
+    salome_study_ID = -1
+    myStudyId, myStudy, myStudyName = None, None, None
     pass
index bd54f4c287b32f325c6f9d3678daa8e7f7210bce..aef592069dca85f3705f2ab17da6230e02437171 100755 (executable)
@@ -27,6 +27,7 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/../HDFPersist
   ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
   ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace
+  ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers
   ${CMAKE_CURRENT_SOURCE_DIR}/../Utils
   ${CMAKE_CURRENT_SOURCE_DIR}/../DF
   ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMEDSImpl
@@ -51,6 +52,7 @@ SET(COMMON_LIBS
   SALOMELocalTrace
   SALOMEBasics
   SalomeHDFPersist
+  SalomeKernelHelpers
   DF
   SalomeDSImpl
   SalomeGenericObj
index 5bbc01b31cb8a13b4c32a9fbdf347175fafc5064..b19a8fd2b6715589e2f10c496b1b2a8933df289e 100644 (file)
@@ -25,6 +25,7 @@
 //  Module : SALOME
 //
 #include "utilities.h"
+#include <sstream>
 #include "SALOMEDS_Study_i.hxx"
 #include "SALOMEDS_StudyManager_i.hxx"
 #include "SALOMEDS_UseCaseIterator_i.hxx"
@@ -48,6 +49,7 @@
 #include "DF_Attribute.hxx"
 
 #include "Basics_Utils.hxx"
+#include "SALOME_KernelServices.hxx"
 
 #ifdef WIN32
 #include <process.h>
@@ -232,9 +234,23 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
   _builder        = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);  
   _notifier       = new SALOMEDS::Notifier(_orb);
   _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
+  _closed         = false;
 
   theImpl->setNotifier(_notifier);
   theImpl->setGenObjRegister( _genObjRegister );
+
+  // Notify GUI that study was created
+  SALOME_NamingService *aNamingService = KERNEL::getNamingService();
+  CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
+  SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
+  if ( !CORBA::is_nil(aSession) ) {
+    std::stringstream ss;
+    ss << "studyCreated:" << theImpl->StudyId();
+    std::string str = ss.str();
+    SALOMEDS::unlock();
+    aSession->emitMessageOneWay(str.c_str());
+    SALOMEDS::lock();
+  }
 }
   
 //============================================================================
@@ -266,6 +282,8 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i()
 char* SALOMEDS_Study_i::GetPersistentReference()
 {
   SALOMEDS::Locker lock; 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
   return CORBA::string_dup(_impl->GetPersistentReference().c_str());
 }
 //============================================================================
@@ -276,7 +294,9 @@ char* SALOMEDS_Study_i::GetPersistentReference()
 char* SALOMEDS_Study_i::GetTransientReference()
 {
   SALOMEDS::Locker lock; 
-  return CORBA::string_dup(_impl->GetTransientReference().c_str()); 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+  return CORBA::string_dup(_impl->GetTransientReference().c_str());
 }
 
 //============================================================================
@@ -287,6 +307,8 @@ char* SALOMEDS_Study_i::GetTransientReference()
 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
 {
   SALOMEDS::Locker lock; 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
   return _impl->IsEmpty();
 }
 
@@ -299,10 +321,15 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponent
 {
   SALOMEDS::Locker lock; 
   
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SComponent_var sco;
+
   SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
-  if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
+  if (!aCompImpl.IsNull())
+    sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
 
-  SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
   return sco._retn();
 }
 
@@ -315,10 +342,15 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponen
 {
   SALOMEDS::Locker lock; 
   
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SComponent_var sco;
+
   SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
-  if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
+  if (!aCompImpl.IsNull())
+    sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
 
-  SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
   return sco._retn();
 }
 
@@ -331,18 +363,23 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
 {
   SALOMEDS::Locker lock; 
 
-  SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
-  if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SObject_var so;
 
-  if(aSO.IsComponent()) {
-    SALOMEDSImpl_SComponent aSCO = aSO;
-    SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
-    return sco._retn();
+  SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
+  if (!aSO.IsNull()) {
+    if (aSO.IsComponent()) {
+      SALOMEDSImpl_SComponent aSCO = aSO;
+      so = SALOMEDS_SComponent_i::New(aSCO, _orb);
+    }
+    else {
+      so = SALOMEDS_SObject_i::New(aSO, _orb);
+    }
   }
-   
-  SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
- return so._retn();
+
+  return so._retn();
 }
 
 //============================================================================
@@ -354,9 +391,15 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SObject_var so;
+
   SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
-  if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
-  SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
+  if (!aSO.IsNull())
+    so = SALOMEDS_SObject_i::New(aSO, _orb);
+
   return so._retn();
 }
 
@@ -369,12 +412,17 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
 {
   SALOMEDS::Locker lock; 
 
-  if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
-  if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
+  SALOMEDS::SObject_var so;
+
+  if (anObjectID && strlen(anObjectID) > 0) {
+    SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
+    if (!aSO.IsNull())
+      so = SALOMEDS_SObject_i::New(aSO, _orb);
+  }
 
-  SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
   return so._retn();
 }
 
@@ -389,16 +437,21 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char*
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
-                                                               std::string((char*)aComponentName));
+                                                                  std::string((char*)aComponentName));
+
+  SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
   int aLength = aSeq.size();
-  SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
   listSO->length(aLength);
-  for(int i = 0; i<aLength; i++) {
-    SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSeq[i], _orb);
-    listSO[i] = so ;
+  for (int i = 0; i < aLength; i++) {
+    SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
+    listSO[i] = so;
   }
-  return listSO._retn() ;
+  
+  return listSO._retn();
 }
 
 //============================================================================
@@ -410,10 +463,15 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SObject_var so;
+
   SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
-  if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
+  if (!aSO.IsNull())
+    so = SALOMEDS_SObject_i::New(aSO, _orb);
 
-  SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
   return so._retn();
 }
 
@@ -426,10 +484,15 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::SObject_var so;
+
   SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
-  if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
+  if (!aSO.IsNull())
+    so = SALOMEDS_SObject_i::New (aSO, _orb);
 
-  SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
   return so._retn();
 }
 
@@ -442,22 +505,28 @@ char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
 {
   SALOMEDS::Locker lock; 
 
-  std::string aPath("");
-  if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str());
-  SALOMEDSImpl_SObject aSO;
-  SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
-  if(!CORBA::is_nil(aSObj)) {
-    aSO = _impl->FindObjectID(aSObj->GetID());
-  }
-  else {
-    aSO  = _impl->FindObjectIOR(_orb->object_to_string(theObject));
+  std::string aPath = "";
+
+  if (!CORBA::is_nil(theObject)) {
+    SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
+    SALOMEDSImpl_SObject aSO;
+
+    if (!CORBA::is_nil(aSObj)) {
+      aSO = _impl->FindObjectID(aSObj->GetID());
+    }
+    else {
+      aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
+    }
+    
+    if (!aSO.IsNull()) {    
+      aPath = _impl->GetObjectPath(aSO);
+    }
   }
-   
-  if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str());
-  
-  aPath = _impl->GetObjectPath(aSO);
-  return  CORBA::string_dup(aPath.c_str());
+
+  return CORBA::string_dup(aPath.c_str());
 }
 
 
@@ -470,8 +539,11 @@ void SALOMEDS_Study_i::SetContext(const char* thePath)
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->SetContext(std::string((char*)thePath));
-  if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") 
+  if (_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") 
     throw SALOMEDS::Study::StudyInvalidContext();  
 }
 
@@ -484,7 +556,11 @@ char* SALOMEDS_Study_i::GetContext()
 {
   SALOMEDS::Locker lock; 
   
-  if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  if (!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
+
   return CORBA::string_dup(_impl->GetContext().c_str());
 }
 
@@ -497,11 +573,14 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
 
   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
     throw SALOMEDS::Study::StudyInvalidContext();
-
+  
   std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
   if (_impl->GetErrorCode() == "InvalidContext")
     throw SALOMEDS::Study::StudyInvalidContext();
@@ -524,11 +603,14 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theCont
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
 
   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
     throw SALOMEDS::Study::StudyInvalidContext();
-
+  
   std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
   if (_impl->GetErrorCode() == "InvalidContext")
     throw SALOMEDS::Study::StudyInvalidContext();
@@ -538,7 +620,7 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theCont
   for (int anIndex = 0; anIndex < aLength; anIndex++) {
     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
-
+  
   return aResult._retn();
 }
 
@@ -551,11 +633,14 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
 
   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
     throw SALOMEDS::Study::StudyInvalidContext();
-
+  
   std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
   if (_impl->GetErrorCode() == "InvalidContext")
     throw SALOMEDS::Study::StudyInvalidContext();
@@ -579,6 +664,9 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theCont
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
 
   std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
@@ -601,14 +689,16 @@ SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject
 {
   SALOMEDS::Locker lock; 
 
-  CORBA::String_var anID=theSO->GetID();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  CORBA::String_var anID = theSO->GetID();
   SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
   SALOMEDSImpl_ChildIterator anItr(aSO);
-
-  //Create iterator
   SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
+  SALOMEDS::ChildIterator_var it = it_servant->_this();
 
-  return it_servant->_this();
+  return it._retn();
 }
 
 
@@ -620,9 +710,15 @@ SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject
 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
 {
   SALOMEDS::Locker lock; 
-  SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
-  _it->Init();
-  return _it->_this();
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
+  it_servant->Init();
+  SALOMEDS::SComponentIterator_var it = it_servant->_this();
+
+  return it._retn();
 }
 
 
@@ -634,7 +730,13 @@ SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
 {
   SALOMEDS::Locker lock; 
-  return _builder->_this();
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
+
+  return sb._retn();
 }
  
 //============================================================================
@@ -645,6 +747,7 @@ SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
 char* SALOMEDS_Study_i::Name()
 {
   SALOMEDS::Locker lock; 
+  // Name is specified as IDL attribute: user exception cannot be raised
   return CORBA::string_dup(_impl->Name().c_str());
 }
 
@@ -656,6 +759,7 @@ char* SALOMEDS_Study_i::Name()
 void SALOMEDS_Study_i::Name(const char* name)
 {
   SALOMEDS::Locker lock;  
+  // Name is specified as IDL attribute: user exception cannot be raised
   _impl->Name(std::string(name));
 }
 
@@ -664,10 +768,11 @@ void SALOMEDS_Study_i::Name(const char* name)
  *  Purpose  : get if study has been saved
  */
 //============================================================================
-CORBA::Boolean  SALOMEDS_Study_i::IsSaved()
+CORBA::Boolean SALOMEDS_Study_i::IsSaved()
 {
   SALOMEDS::Locker lock; 
-  return _impl->IsSaved();
+  // IsSaved is specified as IDL attribute: user exception cannot be raised
+  return (!_closed) ? _impl->IsSaved() : false;
 }
 
 //============================================================================
@@ -678,7 +783,9 @@ CORBA::Boolean  SALOMEDS_Study_i::IsSaved()
 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
 {
   SALOMEDS::Locker lock; 
-  _impl->IsSaved(save);
+  // IsSaved is specified as IDL attribute: user exception cannot be raised
+  if (!_closed)
+    _impl->IsSaved(save);
 }
 
 //============================================================================
@@ -686,9 +793,13 @@ void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
  *  Purpose  : Detect if a Study has been modified since it has been saved
  */
 //============================================================================
-CORBA::Boolean  SALOMEDS_Study_i::IsModified()
+CORBA::Boolean SALOMEDS_Study_i::IsModified()
 {
   SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->IsModified();
 }
 
@@ -697,12 +808,15 @@ CORBA::Boolean  SALOMEDS_Study_i::IsModified()
  *  Purpose  : Sets a Modified flag of a Study to True
  */
 //============================================================================
-void  SALOMEDS_Study_i::Modified()
+void SALOMEDS_Study_i::Modified()
 {
   SALOMEDS::Locker lock; 
-  return _impl->Modify();
-}
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  _impl->Modify();
+}
 
 //============================================================================
 /*! Function : URL
@@ -712,6 +826,7 @@ void  SALOMEDS_Study_i::Modified()
 char* SALOMEDS_Study_i::URL()
 {
   SALOMEDS::Locker lock; 
+  // URL is specified as IDL attribute: user exception cannot be raised
   return CORBA::string_dup(_impl->URL().c_str());
 }
 
@@ -723,25 +838,31 @@ char* SALOMEDS_Study_i::URL()
 void SALOMEDS_Study_i::URL(const char* url)
 {
   SALOMEDS::Locker lock; 
+  // URL is specified as IDL attribute: user exception cannot be raised
   _impl->URL(std::string((char*)url));
 }
 
-
 CORBA::Short SALOMEDS_Study_i::StudyId()
 {
   SALOMEDS::Locker lock; 
+  // StudyId is specified as IDL attribute: user exception cannot be raised
   return _impl->StudyId();
 }
 
 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
 { 
   SALOMEDS::Locker lock; 
+  // StudyId is specified as IDL attribute: user exception cannot be raised
   _impl->StudyId(id);
 }
 
-void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) 
+void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry) 
 {
   SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
 }
 
@@ -767,11 +888,11 @@ SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyIm
   if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end()) 
     return _mapOfStudies[aStudyImpl];
   else
-    {
-      SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
-      _mapOfStudies[aStudyImpl]=Study_servant;
-      return Study_servant;
-    }
+  {
+    SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
+    _mapOfStudies[aStudyImpl]=Study_servant;
+    return Study_servant;
+  }
 }
 
 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) 
@@ -784,6 +905,9 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObj
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS::GenericAttribute_ptr aTarget;
   if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
     return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
@@ -798,14 +922,22 @@ SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
 {
   SALOMEDS::Locker lock; 
   
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
   SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
-  return SP->AttributeStudyProperties::_this();
+  SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
+  return aProp._retn();
 }
 
 char* SALOMEDS_Study_i::GetLastModificationDate() 
 {
   SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
 }
 
@@ -813,19 +945,22 @@ SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
 {
   SALOMEDS::Locker lock; 
   
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
+
   std::vector<std::string> aSeq = _impl->GetModificationsDate();
+
   int aLength = aSeq.size();
-  SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
   aDates->length(aLength);
-
-  for(int anIndex = 0; anIndex < aLength; anIndex++) {
+  for (int anIndex = 0; anIndex < aLength; anIndex++) {
     aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
+
   return aDates._retn();
 }
 
-
-
 //============================================================================
 /*! Function : GetUseCaseBuilder
  *  Purpose  : Returns a UseCase builder
@@ -834,8 +969,13 @@ SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() 
 {
   SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
-  return UCBuilder->_this();
+  SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
+  return uc._retn();
 }
 
 
@@ -848,8 +988,11 @@ void SALOMEDS_Study_i::Close()
 {
   SALOMEDS::Locker lock; 
 
-  RemovePostponed(-1);
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
+  RemovePostponed(-1);
+  
   SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
   for (; itcomponent->More(); itcomponent->Next()) {
     SALOMEDS::SComponent_var sco = itcomponent->Value();
@@ -861,31 +1004,41 @@ void SALOMEDS_Study_i::Close()
       // we have found the associated engine to write the data 
       MESSAGE ( "We have found an engine for data type :"<< compodatatype);
       //_narrow can throw a corba exception
-      try
-        {
-          CORBA::Object_var obj = _orb->string_to_object(IOREngine);
-          if (!CORBA::is_nil(obj)) 
-            {
-              SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
-              if (!anEngine->_is_nil()) 
-                { 
-                  SALOMEDS::unlock();
-                  anEngine->Close(sco);
-                  SALOMEDS::lock();
-                }
-            }
-        } 
-      catch (CORBA::Exception&) 
-        {/*pass*/ }
+      try {
+       CORBA::Object_var obj = _orb->string_to_object(IOREngine);
+       if (!CORBA::is_nil(obj)) {
+         SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
+         if (!anEngine->_is_nil())  { 
+           SALOMEDS::unlock();
+           anEngine->Close(sco);
+           SALOMEDS::lock();
+         }
+       }
+      } 
+      catch (CORBA::Exception&) {
+      }
     }
     sco->UnRegister();
   }
-
+  
   //Does not need any more this iterator
   itcomponent->UnRegister();
-
-
+  
+  // Notify GUI that study is closed
+  SALOME_NamingService *aNamingService = KERNEL::getNamingService();
+  CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
+  SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
+  if ( !CORBA::is_nil(aSession) ) {
+    std::stringstream ss;
+    ss << "studyClosed:" << _impl->StudyId();
+    std::string str = ss.str();
+    SALOMEDS::unlock();
+    aSession->emitMessageOneWay(str.c_str());
+    SALOMEDS::lock();
+  }
+  
   _impl->Close();
+  _closed = true;
 }
 
 //============================================================================
@@ -910,24 +1063,23 @@ void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
  *  Purpose  : 
  */
 //============================================================================
-#ifndef WIN32
-void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/) 
-#else
 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/) 
-#endif
 {  
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   std::vector<std::string> anIORs = _impl->GetIORs();
   int i, aSize = (int)anIORs.size();
-
-  for(i = 0; i < aSize; i++) {
+  
+  for (i = 0; i < aSize; i++) {
     try {
       CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
-          //rnv: To avoid double deletion of the Salome Generic Objects:
-          //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
-          //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
+      //rnv: To avoid double deletion of the Salome Generic Objects:
+      //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
+      //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
       //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
     } catch (...) {}
   }
@@ -940,11 +1092,7 @@ void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
  *  Purpose  : 
  */
 //============================================================================
-#ifndef WIN32
-void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay) 
-#else
 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) 
-#endif
 {
   SALOMEDS::Locker lock; 
   //Not implemented
@@ -963,10 +1111,14 @@ CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
   SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
-  CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
+  bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
   delete factory;
+
   return ret;
 }
 
@@ -979,9 +1131,14 @@ SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const cha
 {
   SALOMEDS::Locker lock; 
   
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
-  return SP->AttributeParameter::_this();
+  SALOMEDS::AttributeParameter_var aParam = SP->_this();
+
+  return aParam._retn();
 }
  
 //============================================================================
@@ -995,9 +1152,14 @@ SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const cha
 {
   SALOMEDS::Locker lock; 
   
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
-  return SP->AttributeParameter::_this();
+  SALOMEDS::AttributeParameter_var aParam = SP->_this();
+
+  return aParam._retn();
 }
 
 //============================================================================
@@ -1008,6 +1170,10 @@ SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const cha
 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
 {
   SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->SetStudyLock(theLockerID);
 }
 
@@ -1019,6 +1185,10 @@ void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
 bool SALOMEDS_Study_i::IsStudyLocked()
 {
   SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->IsStudyLocked();
 }
 
@@ -1030,6 +1200,10 @@ bool SALOMEDS_Study_i::IsStudyLocked()
 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
 {
   SALOMEDS::Locker lock; 
+
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->UnLockStudy(theLockerID);
 }
 
@@ -1042,6 +1216,9 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
 
   std::vector<std::string> aSeq = _impl->GetLockerID();
@@ -1051,6 +1228,7 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
   for(int anIndex = 0; anIndex < aLength; anIndex++) {
     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
+
   return aResult._retn();
 }
 //============================================================================
@@ -1060,10 +1238,14 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
 //============================================================================
 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+
   _impl->SetVariable(std::string(theVarName), 
-                     theValue,
-                     SALOMEDSImpl_GenericVariable::REAL_VAR);
-  if(_notifier)
+                    theValue,
+                    SALOMEDSImpl_GenericVariable::REAL_VAR);
+  if (_notifier)
     _notifier->modifyNB_Notification(theVarName);
 }
 
@@ -1074,10 +1256,13 @@ void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
 //============================================================================
 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->SetVariable(std::string(theVarName), 
-                     theValue,
-                     SALOMEDSImpl_GenericVariable::INTEGER_VAR);
-  if(_notifier)
+                    theValue,
+                    SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+  if (_notifier)
     _notifier->modifyNB_Notification(theVarName);
 }
 
@@ -1088,10 +1273,13 @@ void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
 //============================================================================
 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->SetVariable(std::string(theVarName), 
-                     theValue,
-                     SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
-  if(_notifier)
+                    theValue,
+                    SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+  if (_notifier)
     _notifier->modifyNB_Notification(theVarName);
 }
 
@@ -1102,10 +1290,13 @@ void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValu
 //============================================================================
 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->SetStringVariable(std::string(theVarName), 
-                           theValue,
-                           SALOMEDSImpl_GenericVariable::STRING_VAR);
-  if(_notifier)
+                          theValue,
+                          SALOMEDSImpl_GenericVariable::STRING_VAR);
+  if (_notifier)
     _notifier->modifyNB_Notification(theVarName);
 }
 
@@ -1116,9 +1307,12 @@ void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
 //============================================================================
 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->SetStringVariableAsDouble(std::string(theVarName), 
-                                   theValue,
-                                   SALOMEDSImpl_GenericVariable::STRING_VAR);
+                                  theValue,
+                                  SALOMEDSImpl_GenericVariable::STRING_VAR);
 }
 
 //============================================================================
@@ -1128,6 +1322,9 @@ void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double t
 //============================================================================
 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->GetVariableValue(std::string(theVarName));
 }
 
@@ -1138,7 +1335,10 @@ CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
 //============================================================================
 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
 {
-  return (int)_impl->GetVariableValue(std::string(theVarName));
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  return (long)_impl->GetVariableValue(std::string(theVarName));
 }
 
 //============================================================================
@@ -1148,6 +1348,9 @@ CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return (bool)_impl->GetVariableValue(std::string(theVarName));
 }
 
@@ -1158,6 +1361,9 @@ CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
 //============================================================================
 char* SALOMEDS_Study_i::GetString(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
 }
 
@@ -1168,8 +1374,11 @@ char* SALOMEDS_Study_i::GetString(const char* theVarName)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->IsTypeOf(std::string(theVarName),
-                         SALOMEDSImpl_GenericVariable::REAL_VAR);
+                        SALOMEDSImpl_GenericVariable::REAL_VAR);
 }
 
 //============================================================================
@@ -1179,8 +1388,11 @@ CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->IsTypeOf(std::string(theVarName),
-                         SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+                        SALOMEDSImpl_GenericVariable::INTEGER_VAR);
 }
 
 //============================================================================
@@ -1190,8 +1402,11 @@ CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->IsTypeOf(std::string(theVarName),
-                         SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+                        SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
 }
 
 //============================================================================
@@ -1201,8 +1416,11 @@ CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->IsTypeOf(std::string(theVarName),
-                         SALOMEDSImpl_GenericVariable::STRING_VAR);
+                        SALOMEDSImpl_GenericVariable::STRING_VAR);
 }
 
 //============================================================================
@@ -1212,6 +1430,9 @@ CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->IsVariable(std::string(theVarName));
 }
 
@@ -1222,12 +1443,15 @@ CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
 //============================================================================
 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
 {
-  std::vector<std::string> aVarNames = _impl->GetVariableNames();
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  
+
+  std::vector<std::string> aVarNames = _impl->GetVariableNames();
+
   int aLen = aVarNames.size();
   aResult->length(aLen);
-  
   for (int anInd = 0; anInd < aLen; anInd++)
     aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
   
@@ -1241,9 +1465,13 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
 {
-  CORBA::Boolean res = _impl->RemoveVariable(std::string(theVarName));
-  if(res && _notifier)
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  bool res = _impl->RemoveVariable(std::string(theVarName));
+  if (res && _notifier)
     _notifier->modifyNB_Notification(theVarName);
+
   return res;
 }
 
@@ -1254,9 +1482,13 @@ CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
 {
-  CORBA::Boolean res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
-  if(res && _notifier)
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
+  bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
+  if (res && _notifier)
     _notifier->modifyNB_Notification(theVarName);
+
   return res;
 }
 
@@ -1267,6 +1499,9 @@ CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const ch
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
 {
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   return _impl->IsVariableUsed(std::string(theVarName));
 }
 
@@ -1278,10 +1513,13 @@ CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
 //============================================================================
 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
 {
-  std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
 
   SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
 
+  std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
+
   int aSectionsLen = aSections.size();
   aResult->length(aSectionsLen);
 
@@ -1311,6 +1549,9 @@ char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char*
 {
   SALOMEDS::Locker lock; 
 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
   return CORBA::string_dup(script.c_str());
 }
@@ -1322,10 +1563,13 @@ char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char*
 //============================================================================
 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) 
 { 
+  if (_closed)
+    throw SALOMEDS::Study::StudyInvalidReference();  
+
   _impl->EnableUseCaseAutoFilling(isEnabled); 
   SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
-  if(builder) {
-    if(isEnabled) {
+  if (builder) {
+    if (isEnabled) {
       builder->SetOnAddSObject(_impl->GetCallback());
       builder->SetOnRemoveSObject(_impl->GetCallback());
     }
@@ -1341,10 +1585,10 @@ void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
  *  Purpose  : This function attach an observer to the study
  */
 //============================================================================
-void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs,CORBA::Boolean modify)
+void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
 {
-  if(_notifier)
-    static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs,modify);
+  if (_notifier)
+    static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
 }
 
 
@@ -1355,7 +1599,7 @@ void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs,CORBA::Boolean modif
 //============================================================================
 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
 {
-  if(_notifier)
+  if (_notifier)
     static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
 }
 
index d988daa48980d470f9422a733010db99cb807ab7..b334ff9094b551b95374f49cc503391527a50a68 100644 (file)
@@ -55,6 +55,7 @@ private:
   static std::map<SALOMEDSImpl_Study*, SALOMEDS_Study_i*> _mapOfStudies;
   SALOMEDSImpl_AbstractCallback* _notifier;
   SALOMEDSImpl_AbstractCallback* _genObjRegister;
+  bool                           _closed;
 
 public:
 
@@ -276,17 +277,10 @@ public:
 
   virtual void AddCreatedPostponed(const char* theIOR);
 
-#ifndef WIN32
-  virtual void RemovePostponed(const CORBA::Long theUndoLimit); // removes postponed IORs of old transaction
-                                                        // if theUndoLimit==0, removes all
-  virtual void UndoPostponed(const CORBA::Long theWay); // theWay = 1: resurrect objects,
-                                                // theWay = -1: get back to the list of postponed
-#else
   virtual void RemovePostponed(CORBA::Long theUndoLimit); // removes postponed IORs of old transaction
                                                         // if theUndoLimit==0, removes all
   virtual void UndoPostponed(CORBA::Long theWay); // theWay = 1: resurrect objects,
                                                 // theWay = -1: get back to the list of postponed
-#endif
 
   virtual SALOMEDS::AttributeParameter_ptr GetCommonParameters(const char* theID, CORBA::Long theSavePoint);
   virtual SALOMEDS::AttributeParameter_ptr GetModuleParameters(const char* theID,