From ebe3541632797c5fad97573b46655718ddd61444 Mon Sep 17 00:00:00 2001 From: mpa Date: Wed, 21 Sep 2016 14:52:50 +0300 Subject: [PATCH] 0023299: [CEA] Finalize multi-study removal - remove study manager - remove study id component - move methods from study manager classes to study --- idl/SALOMEDS.idl | 1152 ++++++------ idl/SALOME_Component.idl | 28 +- idl/SALOME_PACOExtension.idl | 3 +- idl/SALOME_Session.idl | 2 - src/Basics/Basics_DirUtils.cxx | 23 +- src/Basics/Basics_DirUtils.hxx | 6 +- src/Container/Component_i.cxx | 43 +- src/Container/Container_i.cxx | 700 ++++---- src/Container/SALOME_Component_i.hxx | 5 +- src/Container/SALOME_Container.py | 2 +- src/Container/SALOME_Container_i.hxx | 13 +- src/KERNEL_PY/salome_ComponentGUI.py | 2 +- src/KernelHelpers/SALOME_KernelServices.cxx | 38 +- src/KernelHelpers/SALOME_KernelServices.hxx | 4 +- src/KernelHelpers/SALOME_StudyEditor.cxx | 12 - src/KernelHelpers/SALOME_StudyEditor.hxx | 3 - src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 46 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx | 16 +- src/MPIContainer/MPIContainer_i.cxx | 37 +- src/MPIContainer/MPIContainer_i.hxx | 8 +- .../SALOME_ParallelComponent_i.cxx | 44 +- .../SALOME_ParallelComponent_i.hxx | 7 +- .../SALOME_ParallelContainerProxy_i.cxx | 12 +- .../SALOME_ParallelContainerProxy_i.hxx | 4 +- .../SALOME_ParallelContainer_i.cxx | 74 +- .../SALOME_ParallelContainer_i.hxx | 22 +- src/SALOMEDS/CMakeLists.txt | 4 - src/SALOMEDS/SALOMEDS.cxx | 118 +- src/SALOMEDS/SALOMEDS_Driver_i.cxx | 9 +- src/SALOMEDS/SALOMEDS_Driver_i.hxx | 3 +- src/SALOMEDS/SALOMEDS_SObject_i.cxx | 2 - src/SALOMEDS/SALOMEDS_Server.cxx | 20 +- src/SALOMEDS/SALOMEDS_Study.cxx | 207 ++- src/SALOMEDS/SALOMEDS_Study.hxx | 22 +- src/SALOMEDS/SALOMEDS_StudyBuilder.cxx | 1 - src/SALOMEDS/SALOMEDS_StudyManager.cxx | 326 ---- src/SALOMEDS/SALOMEDS_StudyManager.hxx | 74 - src/SALOMEDS/SALOMEDS_StudyManager_i.cxx | 535 ------ src/SALOMEDS/SALOMEDS_StudyManager_i.hxx | 156 -- src/SALOMEDS/SALOMEDS_Study_i.cxx | 394 +++-- src/SALOMEDS/SALOMEDS_Study_i.hxx | 59 +- src/SALOMEDSClient/SALOMEDSClient.hxx | 1 - .../SALOMEDSClient_ClientFactory.cxx | 38 - .../SALOMEDSClient_ClientFactory.hxx | 11 - src/SALOMEDSClient/SALOMEDSClient_Study.hxx | 20 +- .../SALOMEDSClient_StudyManager.hxx | 57 - src/SALOMEDSImpl/CMakeLists.txt | 1 - src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx | 3 +- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 1390 ++++++++++++++- src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx | 64 +- .../SALOMEDSImpl_StudyManager.cxx | 1568 ----------------- .../SALOMEDSImpl_StudyManager.hxx | 144 -- 52 files changed, 2921 insertions(+), 4612 deletions(-) delete mode 100644 src/SALOMEDS/SALOMEDS_StudyManager.cxx delete mode 100644 src/SALOMEDS/SALOMEDS_StudyManager.hxx delete mode 100644 src/SALOMEDS/SALOMEDS_StudyManager_i.cxx delete mode 100644 src/SALOMEDS/SALOMEDS_StudyManager_i.hxx delete mode 100644 src/SALOMEDSClient/SALOMEDSClient_StudyManager.hxx delete mode 100644 src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx delete mode 100644 src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index 3303ac682..4f8ca7ef3 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -41,7 +41,7 @@ module SALOMEDS { /*! \brief Name of the file in which the %Study is saved. */ - typedef string URL; + typedef string URLPath; /*! \brief Main identifier of an object in %SALOME application */ @@ -55,12 +55,6 @@ module SALOMEDS */ typedef string SalomeReference; -/*! \brief List of the names of studies which are currently open in this %SALOME session. - -Since %SALOME is a multi-study application, it allows to open a lot of studies -during each working session. -*/ - typedef sequence ListOfOpenStudies; //! List of file names typedef sequence ListOfFileNames; //! List of modification dates of a study @@ -81,7 +75,6 @@ during each working session. interface GenericAttribute; interface Study; - interface StudyManager; interface StudyBuilder; interface SObject; interface SComponent; @@ -105,899 +98,804 @@ during each working session. //! Exception indicating that this feature hasn't been implemented in %SALOME application. exception NotImplemented {}; + //========================================================================== +/*! \brief %Study Builder Interface - //=========================================================================== - /*! \brief %Study Interface - - The purpose of the %Study is to manage the data produced by various components of %SALOME platform. - Most of the %Study operations are handled by the StudyManager and the StudyBuilder. - What is left in the %Study interface are elementary inquiries. - (Incidentally, we recall that a CORBA attribute is implemented as a pair of get - and set methods.) A %Study is explored by a set of tools, mainly iterators - , which are described further. Nevertheless, the %Study - interface allows the search of an object by name or by ID. - \note -
The Path of an object in %SALOME application is much alike a standard path of a file. - In general it's a string of names of directories divided by a slash '/'. -
The Context is the current directory of an object.

+ The purpose of the Builder is to add and/or remove objects and attributes. + A %StudyBuilder is linked to a %Study. A + command management is provided for the undo/redo functionalities. + \note +
The Tag of an item in %SALOME application is a symbolic description of + item's position in the tree-type structure of the browser. In general it has the following + form: 0:2:1:1 */ + //========================================================================== - interface Study + interface StudyBuilder { +/*! \brief %LockProtection Exception -//! Invalid study reference - exception StudyInvalidReference {}; -//! Invalid study context - exception StudyInvalidContext {}; -//! Invalid study component - exception StudyInvalidComponent {}; -//! Invalid directory of the %study exception - exception StudyInvalidDirectory {}; -//! Exception pointing that this name of the study has already been used. - exception StudyNameAlreadyUsed {}; -//! study object already exists - exception StudyObjectAlreadyExists {}; -//! Invalid name of the %study exception - exception StudyNameError {}; -//! Invalid study comment - exception StudyCommentError {}; + This exception is raised while attempting to modify a locked %study. +*/ + exception LockProtection {}; +/*! \brief Creation of a new %SComponent. -/*! \brief The name of the %Study + Creates a new %SComponent + \param ComponentDataType Data type of the %SComponent which will be created. + +See \ref example17 for an example of this method usage in batchmode of %SALOME application. - This is equivalent to the methods setName() & getName() */ - attribute string Name; // equivalent to setName() & getName() -/*! \brief The ID of the %Study + SComponent NewComponent(in string ComponentDataType) raises(LockProtection); +/*! \brief Definition of the instance to the %SComponent - This is equivalent to the methods setID() & getID() + Defines the instance to the %SComponent. */ - attribute short StudyId; -//! Sequence containing %SObjects - typedef sequence ListOfSObject; -//! Get the persistent reference to the %Study. - PersistentReference GetPersistentReference() raises(StudyInvalidReference); -//! Get a transient reference to the %Study. - SalomeReference GetTransientReference() raises(StudyInvalidReference); + void DefineComponentInstance (in SComponent aComponent,in Object ComponentIOR) raises(LockProtection); -/*! \brief indicate whether the %Study is empty +/*! \brief Deletion of a %SComponent - \return True if the %Study is empty + Removes a %SComponent. */ - boolean IsEmpty() raises(StudyInvalidReference); -/*! \brief Find a %SComponent by its name. + void RemoveComponent(in SComponent aComponent) raises(LockProtection); - \param aComponentName It's a string value in the Comment Attribute of the Component, - which is looked for, defining the data type of this Component. +/*! \brief Creation of a new %SObject -See \ref example1 for an example of this method usage in batchmode of %SALOME application. + Creates a new %SObject under a definite father %SObject. -*/ - SComponent FindComponent (in string aComponentName) raises(StudyInvalidReference); + \param theFatherObject The father %SObject under which this one should be created. + \return New %SObject + +See \ref example18 for an example of this method usage in batchmode of %SALOME application. -/*! \brief Find a %SComponent by ID of the according %SObject */ - 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 - \return The obtained %SObject + SObject NewObject (in SObject theFatherObject) raises(LockProtection); -See \ref example19 for an example of this method usage in batchmode of %SALOME application. -*/ - SObject FindObject (in string anObjectName) raises(StudyInvalidReference); -/*! \brief Find a %SObject by its ID +/*! \brief Creation of a new %SObject with a definite %tag - \param aObjectID This parameter defines the ID of the required object - \return The obtained %SObject -*/ - SObject FindObjectID (in ID aObjectID) raises(StudyInvalidReference); -/*! \brief Create a %SObject by its ID + Creates a new %SObject with a definite %tag. - \param aObjectID This parameter defines the ID of the required object - \return The created %SObject -*/ - SObject CreateObjectID (in ID aObjectID) raises(StudyInvalidReference); -/*! \brief Find a %SObject by IOR of the object belonging to this %SObject. + \param atag Long value corresponding to the tag of the new %SObject. + \return New %SObject - \param anObjectName This parameter defines the IOR of the object - \return The obtained %SObject */ - SObject FindObjectIOR (in ID aObjectIOR) raises(StudyInvalidReference); -/*! \brief Find in the study all %SObjects produced by a given %Component. + SObject NewObjectToTag (in SObject theFatherObject, in long atag) raises(LockProtection); +/*! \brief Deletion of the %SObject - \param anObjectName The Name Attribute of the searched %SObjects should correspond to anObjectName. - \param aComponentName The name of the component, which objects are searched for. -*/ - ListOfSObject FindObjectByName(in string anObjectName, in string aComponentName) raises(StudyInvalidReference); -/*! \brief Find a %SObject by the path to it. + Removes a %SObject from the %StudyBuilder. - \param thePath The path to the required %SObject. - \return The obtained %SObject. -*/ - SObject FindObjectByPath(in string thePath) raises(StudyInvalidReference); -/*! \brief Get the path to the %SObject. + \param anObject The %SObject to be deleted. */ - string GetObjectPath(in Object theObject) raises(StudyInvalidReference); - -/*! \brief Set the context of the %Study. + void RemoveObject (in SObject anObject) raises(LockProtection); +/*! \brief Deletion of the %SObject with all his child objects. - \param thePath String parameter defining the context of the study. + Removes the %SObject with all his child objects. -See \ref example23 for an example of this method usage in batchmode of %SALOME application. + \param anObject The %SObject to be deleted with all child objects. */ - void SetContext(in string thePath) raises (StudyInvalidReference, StudyInvalidContext); -/*! \brief Get the context of the %Study. + void RemoveObjectWithChildren(in SObject anObject) raises(LockProtection); -See \ref example23 for an example of this method usage in batchmode of %SALOME application. -*/ - string GetContext() raises (StudyInvalidReference, StudyInvalidContext); -/*! \brief Get a list of names of objects corresponding to the context. +/*! + Loads a %SComponent. - \note If the parameter theContext is empty, then the current context will be used. -*/ - ListOfStrings GetObjectNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext); -/*! \brief Get a list of names of directories and subdirectories corresponding to the context. +See \ref example19 for an example of this method usage in batchmode of %SALOME application. - \note If the parameter theContext is empty, then the current context will be used. */ - ListOfStrings GetDirectoryNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext); -/*! \brief Get a list of names of Files corresponding to the context. + void LoadWith (in SComponent sco, in Driver Engine) raises (SALOME::SALOME_Exception); +/*! + Loads a %SObject. - \note If the parameter theContext is empty, then the current context will be used. + \param sco %SObject to be loaded. */ - ListOfStrings GetFileNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext); -/*! \brief Get a list of names of Components corresponding to the context. + void Load (in SObject sco); - \note If the parameter theContext is empty, then the current context will be used. -*/ - ListOfStrings GetComponentNames(in string theContext) raises(StudyInvalidReference); -/*! \brief Create a new iterator of child levels of the given %SObject. +/*! \brief Looking for or creating an attribute assigned to the %SObject - \param aSO The given %SObject - \return A new iterator of child levels of the given %SObject. + Allows to find or create an attribute of a specific type which is assigned to the object. + \param anObject The %SObject corresponding to the attribute which is looked for. + \param aTypeOfAttribute Type of the attribute. + +See \ref example1 for an example of this method usage in batchmode of %SALOME application. */ - ChildIterator NewChildIterator(in SObject aSO) raises(StudyInvalidReference); -/*! \brief Create a new iterator of the %SComponents. + GenericAttribute FindOrCreateAttribute(in SObject anObject, + in string aTypeOfAttribute) raises(LockProtection); - \return A new iterator of the %SComponents. -*/ - SComponentIterator NewComponentIterator() raises(StudyInvalidReference); +/*! \brief Looking for an attribute assigned to a %SObject -/*! \brief Create a new %StudyBuilder to add or modify an object in the study. + Allows to find an attribute of a specific type which is assigned to the object. + \param anObject The %SObject corresponding to the attribute which is looked for. + \param aTypeOfAttribute Type of the attribute. + \param anAttribute Where the attribute is placed if it's found. + \return True if it finds an attribute. + */ - \return A new %StudyBuilder. + boolean FindAttribute(in SObject anObject, + out GenericAttribute anAttribute, + in string aTypeOfAttribute); +/*! \brief Deleting the attribute assigned to the %SObject -See \ref example20 for an example of this method usage in batchmode of %SALOME application. + Removes the attribute of a specific type which is assigned to the object. + \param anObject The %SObject corresponding to the attribute. + \param aTypeOfAttribute Type of the attribute. + +See \ref example17 for an example of this method usage in batchmode of %SALOME application. +*/ + void RemoveAttribute(in SObject anObject, + in string aTypeOfAttribute) raises(LockProtection); +/*! + Adds a reference between %anObject and %theReferencedObject. + \param anObject The %SObject which will get a reference + \param theReferencedObject The %SObject having a reference */ - StudyBuilder NewBuilder() raises(StudyInvalidReference); -/*! \brief Labels dependency - Updates the map with IOR attribute. It's an inner method used for optimization. + void Addreference(in SObject anObject, + in SObject theReferencedObject) ; + +/*! + Removes a reference from %anObject to another object. + \param anObject The %SObject which contains a reference */ - void UpdateIORLabelMap(in string anIOR, in string anEntry) raises(StudyInvalidReference); -/*! \brief Getting properties of the study + void RemoveReference(in SObject anObject) ; - Returns the attribute, which contains the properties of this study. +/*! + Adds a directory in the %Study. + \param theName String parameter defining the name of the directory. -See \ref example20 for an example of this method usage in batchmode of %SALOME application. +See \ref example23 for an example of this method usage in batchmode of %SALOME application. */ - AttributeStudyProperties GetProperties() raises(StudyInvalidReference); -/*! \brief Indicate whether the %study has been saved -*/ - attribute boolean IsSaved; -/*! \brief Indicate whether the %study has been modified and not saved. + void AddDirectory(in string theName) raises(LockProtection); - Returns True if the %study has been modified and not saved. -*/ - boolean IsModified() raises(StudyInvalidReference); +/*! \brief Identification of the %SObject's substructure. -/*! \brief Mark the %study as being modified and not saved. -*/ - void Modified() raises(StudyInvalidReference); + Identification of the %SObject's substructure by GUID. -/*! \brief Indicate the file where the %study has been saved + + \param anObject The %SObject which will be identified + \param theGUID GUID has the following format "00000000-0000-0000-0000-000000000000" */ - attribute string URL; -/*! \brief List of %SObjects + void SetGUID(in SObject anObject, in string theGUID) raises(LockProtection); +/*! +Searches for a definite %SObject with a definite GUID and returns True if it finds it. - Returns the list of %SObjects which refers to %anObject. +\param anObject A definite %SObject which will be identified +\param theGUID GUID has the following format "00000000-0000-0000-0000-000000000000" */ - ListOfSObject FindDependances(in SObject anObject) raises(StudyInvalidReference); + boolean IsGUID(in SObject anObject, in string theGUID); -/*! \brief The date of the last saving of the study +/*! \brief Creation of a new command - Returns the date of the last saving of study with format: "DD/MM/YYYY HH:MM" -*/ - string GetLastModificationDate() raises(StudyInvalidReference); -/*! \brief The list of modification dates of the study + Creates a new command which can contain several different actions. - 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() raises(StudyInvalidReference); -/*! \brief Object conversion. +See \ref example3 for an example of this method usage in batchmode of %SALOME application. - Converts an object into IOR. - \return IOR */ - string ConvertObjectToIOR(in Object theObject); -/*! \brief Object conversion. + void NewCommand(); // command management +/*! \brief Execution of the command - Converts IOR into an object. - \return An object -*/ - Object ConvertIORToObject(in string theIOR); + Commits all actions declared within this command. -/*! \brief Get a new %UseCaseBuilder. -*/ - UseCaseBuilder GetUseCaseBuilder() raises(StudyInvalidReference); + \exception LockProtection This exception is raised, when trying to perform this command a study, which is protected for modifications. -/*! \brief Close the components in the study, remove itself from the %StudyManager. -*/ - void Close() raises(StudyInvalidReference); +See \ref example16 for an example of this method usage in batchmode of %SALOME application. -/*! \brief Enable (if isEnabled = True)/disable automatic addition of new %SObjects to the use case. */ - void EnableUseCaseAutoFilling(in boolean isEnabled) raises(StudyInvalidReference); - + void CommitCommand() raises(LockProtection); // command management /*! - Functions for internal usage only + Returns True if at this moment there is a command under execution. */ - void AddPostponed(in string theIOR) raises(StudyInvalidReference); - - void AddCreatedPostponed(in string theIOR) raises(StudyInvalidReference); - - void RemovePostponed(in long theUndoLimit) raises(StudyInvalidReference); - - void UndoPostponed(in long theWay) raises(StudyInvalidReference); - - boolean DumpStudy(in string thePath, - in string theBaseName, - in boolean isPublished, - in boolean isMultiFile) raises(StudyInvalidReference); + boolean HasOpenCommand(); +/*! \brief Cancelation of the command -/*! \brief Get an AttributeParameter used to store common parameters for given %theSavePoint. + Cancels all actions declared within the command. - \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 +See \ref example17 for an example of this method usage in batchmode of %SALOME application. */ - AttributeParameter GetCommonParameters(in string theID, in long theSavePoint) raises(StudyInvalidReference); - -/*! \brief Get an AttributeParameter used to store parameters for given %theModuleName. + void AbortCommand(); // command management +/*! \brief Undolimit - \param theID identifies a common parameters set (Example: "Interface Applicative") - \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 + The number of actions which can be undone */ - AttributeParameter GetModuleParameters(in string theID, in string theModuleName, in long theSavePoint) raises(StudyInvalidReference); + attribute long UndoLimit; +/*! \brief Undo method + Cancels all actions of the last command. -/*! \brief Get a default Python script to restore visual parameters for given %theModuleName. + \exception LockProtection This exception is raised, when trying to perform this command a study, which is protected for modifications. - \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) raises(StudyInvalidReference); +See \ref example16 for an example of this method usage in batchmode of %SALOME application. -/*! - Private method, returns an implementation of this Study. - \param theHostname is a hostname of the caller - \param thePID is a process ID of the caller - \param isLocal is set True if the Study is launched locally with the caller */ - long long GetLocalImpl(in string theHostname, in long thePID, out boolean isLocal); + void Undo() raises (LockProtection); +/*! \brief Redo method + Redoes all actions of the last command. -/*! \brief Mark this Study as being locked by the given locker. +\exception LockProtection This exception is raised, when trying to perform this command a study, which is protected for modifications. + +See \ref example16 for an example of this method usage in batchmode of %SALOME application. - 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) raises(StudyInvalidReference); + void Redo() raises (LockProtection); +/*! + Returns True if at this moment there are any actions which can be canceled. -/*! \brief Indicate if the Study is locked +See \ref example16 for an example of this method usage in batchmode of %SALOME application. - Returns True if the Study was marked locked. */ - boolean IsStudyLocked() raises(StudyInvalidReference); + boolean GetAvailableUndos(); +/*! + Returns True if at this moment there are any actions which can be redone. -/*! \brief Mark this Study as being unlocked by the given locker. +See \ref example3 for an example of this method usage in batchmode of %SALOME application. - 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) raises(StudyInvalidReference); + boolean GetAvailableRedos(); +/*! + Puts name attribute with the given string value to the given %SObject -/*! \brief Get the list of IDs of the Study's lockers. + \param theSO Existing SObject to set name attribute. + \param theValue The value to be set to the name attribute. */ - ListOfStrings GetLockerID() raises(StudyInvalidReference); + void SetName(in SObject theSO, in string theValue) raises (LockProtection); -/*! \brief Create real variable with Name theVarName and value theValue +/*! + Puts comment attribute with the given string value to the given %SObject - (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. + \param theSO Existing SObject to set comment attribute. + \param theValue The value to be set to the comment attribute. */ - void SetReal( in string theVarName, in double theValue ) raises(StudyInvalidReference); + void SetComment(in SObject theSO, in string theValue) raises (LockProtection); -/*! \brief Create integer variable with Name theVarName and value theValue +/*! + Puts IOR attribute with the given string value to the given %SObject - (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. + \param theSO Existing SObject to set IOR attribute. + \param theValue The value to be set to the IOR attribute. */ - void SetInteger( in string theVarName, in long theValue ) raises(StudyInvalidReference); -/*! \brief Create boolean variable with Name theVarName and value theValue + void SetIOR(in SObject theSO, in string theValue) raises (LockProtection); + }; - (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. + //=========================================================================== + /*! \brief %Study Interface + + The purpose of the %Study is to manage the data produced by various components of %SALOME platform. + Most of the %Study operations are handled by the StudyBuilder. + What is left in the %Study interface are elementary inquiries. + (Incidentally, we recall that a CORBA attribute is implemented as a pair of get + and set methods.) A %Study is explored by a set of tools, mainly iterators + , which are described further. Nevertheless, the %Study + interface allows the search of an object by name or by ID. + \note +
The Path of an object in %SALOME application is much alike a standard path of a file. + In general it's a string of names of directories divided by a slash '/'. +
The Context is the current directory of an object.

*/ - void SetBoolean( in string theVarName, in boolean theValue ) raises(StudyInvalidReference); -/*! \brief Create string variable with Name theVarName and value theValue + interface Study + { - (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. +//! Invalid study reference + exception StudyInvalidReference {}; +//! Invalid study context + exception StudyInvalidContext {}; +//! Invalid study component + exception StudyInvalidComponent {}; +//! Invalid directory of the %study exception + exception StudyInvalidDirectory {}; +//! Exception pointing that this name of the study has already been used. + exception StudyNameAlreadyUsed {}; +//! study object already exists + exception StudyObjectAlreadyExists {}; +//! Invalid name of the %study exception + exception StudyNameError {}; +//! Invalid study comment + exception StudyCommentError {}; + +/*! + Determines whether the server has already been loaded or not. */ - void SetString( in string theVarName, in string theValue ) raises(StudyInvalidReference); - -/*! \brief Set current value as double for string variable + void ping(); + void Shutdown(); +/*! + Returns the PID of the server */ - void SetStringAsDouble( in string theVarName, in double theValue ) raises(StudyInvalidReference); - -/*! \brief Get value of a real variable + long getPID(); - \param theVarName is a name of the variable. +/*! + Shutdown the Study process. */ - double GetReal( in string theVarName ) raises(StudyInvalidReference); + oneway void ShutdownWithExit(); -/*! \brief Get value of an integer variable +/*! \brief The name of the %Study - \param theVarName is a name of the variable. + This is equivalent to the methods setName() & getName() */ - long GetInteger( in string theVarName ) raises(StudyInvalidReference); - -/*! \brief Get value of a boolean variable + readonly attribute string Name; // equivalent to getName() - \param theVarName is a name of the variable. -*/ - boolean GetBoolean( in string theVarName ) raises(StudyInvalidReference); +//! Sequence containing %SObjects + typedef sequence ListOfSObject; +//! Get the persistent reference to the %Study. + PersistentReference GetPersistentReference() raises(StudyInvalidReference); +//! Get a transient reference to the %Study. + SalomeReference GetTransientReference() raises(StudyInvalidReference); -/*! \brief Get value of a string variable +/*! \brief indicate whether the %Study is empty - \param theVarName is a name of the variable. + \return True if the %Study is empty */ - string GetString( in string theVarName ) raises(StudyInvalidReference); + 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, + which is looked for, defining the data type of this Component. -/*! \brief Indicate if a variable is real +See \ref example1 for an example of this method usage in batchmode of %SALOME application. - Return true if variable is real otherwise return false. - \param theVarName is a name of the variable. */ - boolean IsReal( in string theVarName ) raises(StudyInvalidReference); - -/*! \brief Indicate if a variable is integer + SComponent FindComponent (in string aComponentName) raises(StudyInvalidReference); - Return true if variable is integer otherwise return false. - \param theVarName is a name of the variable. +/*! \brief Find a %SComponent by ID of the according %SObject */ - boolean IsInteger( in string theVarName ) raises(StudyInvalidReference); + SComponent FindComponentID(in ID aComponentID) raises(StudyInvalidReference); +/*! \brief Find a %SObject by the Name Attribute of this %SObject -/*! \brief Indicate if a variable is boolean + \param anObjectName String parameter defining the name of the object + \return The obtained %SObject - Return true if variable is boolean otherwise return false. - \param theVarName is a name of the variable. +See \ref example19 for an example of this method usage in batchmode of %SALOME application. */ - boolean IsBoolean( in string theVarName ) raises(StudyInvalidReference); - -/*! \brief Indicate if a variable is string + SObject FindObject (in string anObjectName) raises(StudyInvalidReference); +/*! \brief Find a %SObject by its ID - Return true if variable is string otherwise return false. - \param theVarName is a name of the variable. + \param aObjectID This parameter defines the ID of the required object + \return The obtained %SObject */ - boolean IsString( in string theVarName ) raises(StudyInvalidReference); - -/*! \brief Indicate if a variable exists in the study + SObject FindObjectID (in ID aObjectID) raises(StudyInvalidReference); +/*! \brief Create a %SObject by its ID - Return true if variable exists in the study, - otherwise return false. - \param theVarName is a name of the variable. + \param aObjectID This parameter defines the ID of the required object + \return The created %SObject */ - boolean IsVariable( in string theVarName ) raises(StudyInvalidReference); + SObject CreateObjectID (in ID aObjectID) raises(StudyInvalidReference); +/*! \brief Find a %SObject by IOR of the object belonging to this %SObject. -/*! \brief Get names of all variables from the study. + \param anObjectName This parameter defines the IOR of the object + \return The obtained %SObject */ - ListOfStrings GetVariableNames() raises(StudyInvalidReference); - -/*! \brief Remove a variable - - Remove variable with the specified name from the study with substitution of its value. + SObject FindObjectIOR (in ID aObjectIOR) raises(StudyInvalidReference); +/*! \brief Find in the study all %SObjects produced by a given %Component. - \param theVarName Name of the variable. - \return Status of operation. + \param anObjectName The Name Attribute of the searched %SObjects should correspond to anObjectName. + \param aComponentName The name of the component, which objects are searched for. */ - boolean RemoveVariable( in string theVarName ) raises(StudyInvalidReference); - -/*! \brief Rename a variable - - Rename variable with the specified name within the study. + ListOfSObject FindObjectByName(in string anObjectName, in string aComponentName) raises(StudyInvalidReference); +/*! \brief Find a %SObject by the path to it. - \param theVarName Name of the variable. - \param theNewVarName New name for the variable. - \return Status of operation. + \param thePath The path to the required %SObject. + \return The obtained %SObject. */ - boolean RenameVariable( in string theVarName, in string theNewVarName ) raises(StudyInvalidReference); - -/*! \brief Indicate whether variable is used - - Check that variable is used in the study. - - \param theVarName Name of the variable. - \return Variable usage. + SObject FindObjectByPath(in string thePath) raises(StudyInvalidReference); +/*! \brief Get the path to the %SObject. */ - boolean IsVariableUsed( in string theVarName ) raises(StudyInvalidReference); - -/*! \brief Parse variables used for object creation + string GetObjectPath(in Object theObject) raises(StudyInvalidReference); - \param string with variables, separated by special symbol. - \return Variables list. -*/ - ListOfListOfStrings ParseVariables( in string theVars ) raises(StudyInvalidReference); +/*! \brief Set the context of the %Study. -/*! - Attach an observer to the Study + \param thePath String parameter defining the context of the study. - \param theObserver observer being attached - \param modify when \c true, observer receives any object's modification events; - otherwise observer receives object's creation events only +See \ref example23 for an example of this method usage in batchmode of %SALOME application. */ - void attach(in SALOMEDS::Observer theObserver, in boolean modify); -/*! - Detach an observer from the Study + void SetContext(in string thePath) raises (StudyInvalidReference, StudyInvalidContext); +/*! \brief Get the context of the %Study. - \param theObserver observer to be detached +See \ref example23 for an example of this method usage in batchmode of %SALOME application. */ - void detach(in SALOMEDS::Observer theObserver); - }; - - //========================================================================== -/*! \brief %Study Builder Interface + string GetContext() raises (StudyInvalidReference, StudyInvalidContext); +/*! \brief Get a list of names of objects corresponding to the context. - The purpose of the Builder is to add and/or remove objects and attributes. - A %StudyBuilder is linked to a %Study. A - command management is provided for the undo/redo functionalities. - \note -
The Tag of an item in %SALOME application is a symbolic description of - item's position in the tree-type structure of the browser. In general it has the following - form: 0:2:1:1 + \note If the parameter theContext is empty, then the current context will be used. */ - //========================================================================== - - interface StudyBuilder - { -/*! \brief %LockProtection Exception + ListOfStrings GetObjectNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext); +/*! \brief Get a list of names of directories and subdirectories corresponding to the context. - This exception is raised while attempting to modify a locked %study. + \note If the parameter theContext is empty, then the current context will be used. */ - exception LockProtection {}; -/*! \brief Creation of a new %SComponent. - - Creates a new %SComponent - \param ComponentDataType Data type of the %SComponent which will be created. - -See \ref example17 for an example of this method usage in batchmode of %SALOME application. + ListOfStrings GetDirectoryNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext); +/*! \brief Get a list of names of Files corresponding to the context. + \note If the parameter theContext is empty, then the current context will be used. */ - SComponent NewComponent(in string ComponentDataType) raises(LockProtection); -/*! \brief Definition of the instance to the %SComponent + ListOfStrings GetFileNames(in string theContext) raises (StudyInvalidReference, StudyInvalidContext); +/*! \brief Get a list of names of Components corresponding to the context. - Defines the instance to the %SComponent. + \note If the parameter theContext is empty, then the current context will be used. */ - void DefineComponentInstance (in SComponent aComponent,in Object ComponentIOR) raises(LockProtection); - -/*! \brief Deletion of a %SComponent + ListOfStrings GetComponentNames(in string theContext) raises(StudyInvalidReference); +/*! \brief Create a new iterator of child levels of the given %SObject. - Removes a %SComponent. + \param aSO The given %SObject + \return A new iterator of child levels of the given %SObject. */ - void RemoveComponent(in SComponent aComponent) raises(LockProtection); + ChildIterator NewChildIterator(in SObject aSO) raises(StudyInvalidReference); -/*! \brief Creation of a new %SObject +/*! \brief Create a new iterator of the %SComponents. - Creates a new %SObject under a definite father %SObject. + \return A new iterator of the %SComponents. +*/ + SComponentIterator NewComponentIterator() raises(StudyInvalidReference); - \param theFatherObject The father %SObject under which this one should be created. - \return New %SObject +/*! \brief Create a new %StudyBuilder to add or modify an object in the study. -See \ref example18 for an example of this method usage in batchmode of %SALOME application. + \return A new %StudyBuilder. +See \ref example20 for an example of this method usage in batchmode of %SALOME application. */ + StudyBuilder NewBuilder() raises(StudyInvalidReference); +/*! \brief Labels dependency - SObject NewObject (in SObject theFatherObject) raises(LockProtection); + Updates the map with IOR attribute. It's an inner method used for optimization. +*/ + void UpdateIORLabelMap(in string anIOR, in string anEntry) raises(StudyInvalidReference); -/*! \brief Creation of a new %SObject with a definite %tag +/*! \brief Getting properties of the study - Creates a new %SObject with a definite %tag. + Returns the attribute, which contains the properties of this study. - \param atag Long value corresponding to the tag of the new %SObject. - \return New %SObject +See \ref example20 for an example of this method usage in batchmode of %SALOME application. */ - SObject NewObjectToTag (in SObject theFatherObject, in long atag) raises(LockProtection); -/*! \brief Deletion of the %SObject - - Removes a %SObject from the %StudyBuilder. - - \param anObject The %SObject to be deleted. + AttributeStudyProperties GetProperties() raises(StudyInvalidReference); +/*! \brief Indicate whether the %study has been saved */ - void RemoveObject (in SObject anObject) raises(LockProtection); -/*! \brief Deletion of the %SObject with all his child objects. - - Removes the %SObject with all his child objects. + attribute boolean IsSaved; +/*! \brief Indicate whether the %study has been modified and not saved. - \param anObject The %SObject to be deleted with all child objects. + Returns True if the %study has been modified and not saved. */ - void RemoveObjectWithChildren(in SObject anObject) raises(LockProtection); - -/*! - Loads a %SComponent. - -See \ref example19 for an example of this method usage in batchmode of %SALOME application. + boolean IsModified() raises(StudyInvalidReference); +/*! \brief Mark the %study as being modified and not saved. */ - void LoadWith (in SComponent sco, in Driver Engine) raises (SALOME::SALOME_Exception); -/*! - Loads a %SObject. + void Modified() raises(StudyInvalidReference); - \param sco %SObject to be loaded. +/*! \brief Indicate the file where the %study has been saved */ - void Load (in SObject sco); - -/*! \brief Looking for or creating an attribute assigned to the %SObject + attribute string URL; - Allows to find or create an attribute of a specific type which is assigned to the object. - \param anObject The %SObject corresponding to the attribute which is looked for. - \param aTypeOfAttribute Type of the attribute. +/*! \brief List of %SObjects -See \ref example1 for an example of this method usage in batchmode of %SALOME application. + Returns the list of %SObjects which refers to %anObject. */ + ListOfSObject FindDependances(in SObject anObject) raises(StudyInvalidReference); - GenericAttribute FindOrCreateAttribute(in SObject anObject, - in string aTypeOfAttribute) raises(LockProtection); +/*! \brief The date of the last saving of the study -/*! \brief Looking for an attribute assigned to a %SObject + Returns the date of the last saving of study with format: "DD/MM/YYYY HH:MM" +*/ + string GetLastModificationDate() raises(StudyInvalidReference); +/*! \brief The list of modification dates of the study - Allows to find an attribute of a specific type which is assigned to the object. - \param anObject The %SObject corresponding to the attribute which is looked for. - \param aTypeOfAttribute Type of the attribute. - \param anAttribute Where the attribute is placed if it's found. - \return True if it finds an attribute. - */ + 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() raises(StudyInvalidReference); +/*! \brief Object conversion. - boolean FindAttribute(in SObject anObject, - out GenericAttribute anAttribute, - in string aTypeOfAttribute); -/*! \brief Deleting the attribute assigned to the %SObject + Converts an object into IOR. + \return IOR +*/ + string ConvertObjectToIOR(in Object theObject); +/*! \brief Object conversion. - Removes the attribute of a specific type which is assigned to the object. - \param anObject The %SObject corresponding to the attribute. - \param aTypeOfAttribute Type of the attribute. + Converts IOR into an object. + \return An object +*/ + Object ConvertIORToObject(in string theIOR); -See \ref example17 for an example of this method usage in batchmode of %SALOME application. +/*! \brief Get a new %UseCaseBuilder. */ - void RemoveAttribute(in SObject anObject, - in string aTypeOfAttribute) raises(LockProtection); -/*! - Adds a reference between %anObject and %theReferencedObject. - \param anObject The %SObject which will get a reference - \param theReferencedObject The %SObject having a reference + UseCaseBuilder GetUseCaseBuilder() raises(StudyInvalidReference); + +/*! \brief Clear a study object */ + void Clear(); + +/*! \brief Open a study by url - void Addreference(in SObject anObject, - in SObject theReferencedObject) ; - -/*! - Removes a reference from %anObject to another object. - \param anObject The %SObject which contains a reference + Reads and activates the structure of the study %Objects. + \param aStudyUrl The path to the study */ + boolean Open (in URLPath aStudyUrl) raises (SALOME::SALOME_Exception); + +/*! \brief Saving the study in a HDF file (or files). - void RemoveReference(in SObject anObject) ; - -/*! - Adds a directory in the %Study. - \param theName String parameter defining the name of the directory. - -See \ref example23 for an example of this method usage in batchmode of %SALOME application. - + Saves a study. + \param theMultiFile If this parameter is True the study will be saved in several files. */ - void AddDirectory(in string theName) raises(LockProtection); - -/*! \brief Identification of the %SObject's substructure. - - Identification of the %SObject's substructure by GUID. - + boolean Save(in boolean theMultiFile); + +/*! \brief Saving a study in a ASCII file (or files). - \param anObject The %SObject which will be identified - \param theGUID GUID has the following format "00000000-0000-0000-0000-000000000000" + Saves a study in an ASCII format file (or files). + \param theMultiFile If this parameter is True the study will be saved in several files. */ + boolean SaveASCII(in boolean theMultiFile); +/*! \brief Saving the study in a specified HDF file (or files). - void SetGUID(in SObject anObject, in string theGUID) raises(LockProtection); -/*! -Searches for a definite %SObject with a definite GUID and returns True if it finds it. + Saves the study in a specified file (or files). + \param aUrl The path to the definite file in whcih the study will be saved + \param aStudy The study which will be saved + \param theMultiFile If this parameter is True the study will be saved in several files. -\param anObject A definite %SObject which will be identified -\param theGUID GUID has the following format "00000000-0000-0000-0000-000000000000" +See \ref example1 for an example of this method usage in batchmode of %SALOME application. */ - boolean IsGUID(in SObject anObject, in string theGUID); - -/*! \brief Creation of a new command - - Creates a new command which can contain several different actions. + boolean SaveAs(in URLPath aUrl, // if the file already exists + in boolean theMultiFile); // overwrite (as option) +/*! \brief Saving the study in a specified ASCII file (or files). -See \ref example3 for an example of this method usage in batchmode of %SALOME application. + Saves the study in a specified ASCII file (or files). + \param aUrl The path to the definite file in whcih the study will be saved + \param aStudy The study which will be saved + \param theMultiFile If this parameter is True the study will be saved in several files. */ - void NewCommand(); // command management -/*! \brief Execution of the command - - Commits all actions declared within this command. - - \exception LockProtection This exception is raised, when trying to perform this command a study, which is protected for modifications. - -See \ref example16 for an example of this method usage in batchmode of %SALOME application. + boolean SaveAsASCII(in URLPath aUrl, // if the file already exists + in boolean theMultiFile); // overwrite (as option) +/*! + Returns True, if the given %SObject can be copied to the clipboard. */ - void CommitCommand() raises(LockProtection); // command management + boolean CanCopy(in SObject theObject); /*! - Returns True if at this moment there is a command under execution. + Returns True, if the given %SObject is copied to the clipboard. + \param theObject The %SObject which will be copied */ - boolean HasOpenCommand(); -/*! \brief Cancelation of the command - - Cancels all actions declared within the command. + boolean Copy(in SObject theObject); +/*! + Returns True, if the object from the clipboard can be pasted to the given %SObject. + \param theObject The %SObject stored in the clipboard. +*/ + boolean CanPaste(in SObject theObject); +/*! + Returns the %SObject in which the object from the clipboard was pasted to. + \param theObject The %SObject which will be pasted + \exception SALOMEDS::StudyBuilder::LockProtection This exception is raised, when trying to paste + an object into a study, which is protected for modifications. +*/ + SObject Paste(in SObject theObject) raises (SALOMEDS::StudyBuilder::LockProtection); -See \ref example17 for an example of this method usage in batchmode of %SALOME application. +/*! \brief Enable (if isEnabled = True)/disable automatic addition of new %SObjects to the use case. */ - void AbortCommand(); // command management -/*! \brief Undolimit + void EnableUseCaseAutoFilling(in boolean isEnabled) raises(StudyInvalidReference); - The number of actions which can be undone +/*! + Functions for internal usage only */ - attribute long UndoLimit; -/*! \brief Undo method + void AddPostponed(in string theIOR) raises(StudyInvalidReference); - Cancels all actions of the last command. + void AddCreatedPostponed(in string theIOR) raises(StudyInvalidReference); - \exception LockProtection This exception is raised, when trying to perform this command a study, which is protected for modifications. + void RemovePostponed(in long theUndoLimit) raises(StudyInvalidReference); -See \ref example16 for an example of this method usage in batchmode of %SALOME application. + void UndoPostponed(in long theWay) raises(StudyInvalidReference); -*/ - void Undo() raises (LockProtection); -/*! \brief Redo method + boolean DumpStudy(in string thePath, + in string theBaseName, + in boolean isPublished, + in boolean isMultiFile) raises(StudyInvalidReference); - Redoes all actions of the last command. +/*! \brief Get an AttributeParameter used to store common parameters for given %theSavePoint. -\exception LockProtection This exception is raised, when trying to perform this command a study, which is protected for modifications. + \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) raises(StudyInvalidReference); -See \ref example16 for an example of this method usage in batchmode of %SALOME application. +/*! \brief Get an AttributeParameter used to store parameters for given %theModuleName. + \param theID identifies a common parameters set (Example: "Interface Applicative") + \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 */ - void Redo() raises (LockProtection); -/*! - Returns True if at this moment there are any actions which can be canceled. + AttributeParameter GetModuleParameters(in string theID, in string theModuleName, in long theSavePoint) raises(StudyInvalidReference); -See \ref example16 for an example of this method usage in batchmode of %SALOME application. +/*! \brief Get a default Python script to restore visual parameters for given %theModuleName. + + \param theModuleName is a name of the module (Example: "Geometry") + \param indent is a string to use for script indentation */ - boolean GetAvailableUndos(); + string GetDefaultScript(in string theModuleName, in string indent) raises(StudyInvalidReference); + /*! - Returns True if at this moment there are any actions which can be redone. + Private method, returns an implementation of this Study. + \param theHostname is a hostname of the caller + \param thePID is a process ID of the caller + \param isLocal is set True if the Study is launched locally with the caller +*/ + long long GetLocalImpl(in string theHostname, in long thePID, out boolean isLocal); -See \ref example3 for an example of this method usage in batchmode of %SALOME application. -*/ - boolean GetAvailableRedos(); -/*! - Puts name attribute with the given string value to the given %SObject +/*! \brief Mark this Study as being locked by the given locker. - \param theSO Existing SObject to set name attribute. - \param theValue The value to be set to the name attribute. + 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 SetName(in SObject theSO, in string theValue) raises (LockProtection); + void SetStudyLock(in string theLockerID) raises(StudyInvalidReference); -/*! - Puts comment attribute with the given string value to the given %SObject +/*! \brief Indicate if the Study is locked - \param theSO Existing SObject to set comment attribute. - \param theValue The value to be set to the comment attribute. + Returns True if the Study was marked locked. */ - void SetComment(in SObject theSO, in string theValue) raises (LockProtection); + boolean IsStudyLocked() raises(StudyInvalidReference); -/*! - Puts IOR attribute with the given string value to the given %SObject +/*! \brief Mark this Study as being unlocked by the given locker. - \param theSO Existing SObject to set IOR attribute. - \param theValue The value to be set to the IOR attribute. + 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 SetIOR(in SObject theSO, in string theValue) raises (LockProtection); - }; - - //========================================================================== -/*! \brief %Study Manager interface + void UnLockStudy(in string theLockerID) raises(StudyInvalidReference); - The purpose of the Manager is to manipulate the %Studies. You will find in this - interface the methods to create, open, - close, and save a %Study. Since a %SALOME session is multi-document, you will - also find the methods allowing to navigate - through the collection of studies present in a session. +/*! \brief Get the list of IDs of the Study's lockers. */ - //========================================================================== + ListOfStrings GetLockerID() raises(StudyInvalidReference); - interface StudyManager - { -/*! - Determines whether the server has already been loaded or not. +/*! \brief Create real 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 ping(); + void SetReal( in string theVarName, in double theValue ) raises(StudyInvalidReference); - void Shutdown(); +/*! \brief Create integer variable with Name theVarName and value theValue -/*! - Returns the PID of the server + (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. */ - long getPID(); + void SetInteger( in string theVarName, in long theValue ) raises(StudyInvalidReference); +/*! \brief Create boolean variable with Name theVarName and value theValue -/*! - Shutdown the StudyManager process. + (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. */ - oneway void ShutdownWithExit(); + void SetBoolean( in string theVarName, in boolean theValue ) raises(StudyInvalidReference); -/*! \brief Creation of a new study +/*! \brief Create string variable with Name theVarName and value theValue - Creates a new study with a definite name. + (or set if variable value into theValue already exists) + \param theVarName is a name of the variable + \param theVarName is a value of the variable. +*/ + void SetString( in string theVarName, in string theValue ) raises(StudyInvalidReference); - \param study_name String parameter defining the name of the study +/*! \brief Set current value as double for string variable +*/ + void SetStringAsDouble( in string theVarName, in double theValue ) raises(StudyInvalidReference); -See \ref example17 for an example of this method usage in batchmode of %SALOME application. +/*! \brief Get value of a real variable + \param theVarName is a name of the variable. */ - Study NewStudy(in string study_name) raises (SALOME::SALOME_Exception); - -/*! \brief Open a study + double GetReal( in string theVarName ) raises(StudyInvalidReference); - Reads and activates the structure of the study %Objects. - \param aStudyUrl The path to the study - \warning This method doesn't activate the corba objects. Only a component can do it. +/*! \brief Get value of an integer variable -See \ref example1 for an example of this method usage in batchmode of %SALOME application. + \param theVarName is a name of the variable. */ - Study Open (in URL aStudyUrl) raises (SALOME::SALOME_Exception); + long GetInteger( in string theVarName ) raises(StudyInvalidReference); -/*! \brief Closing the study +/*! \brief Get value of a boolean variable - Closes a study. + \param theVarName is a name of the variable. */ - void Close(in Study aStudy); -/*! \brief Saving the study in a HDF file (or files). + boolean GetBoolean( in string theVarName ) raises(StudyInvalidReference); - Saves a study. +/*! \brief Get value of a string variable - \param theMultiFile If this parameter is True the study will be saved in several files. + \param theVarName is a name of the variable. +*/ + string GetString( in string theVarName ) raises(StudyInvalidReference); -See \ref example19 for an example of this method usage in batchmode of %SALOME application. -*/ - boolean Save(in Study aStudy, in boolean theMultiFile); -/*! \brief Saving a study in a ASCII file (or files). +/*! \brief Indicate if a variable is real - Saves a study in an ASCII format file (or files). - \param theMultiFile If this parameter is True the study will be saved in several files. + Return true if variable is real otherwise return false. + \param theVarName is a name of the variable. */ - boolean SaveASCII(in Study aStudy, in boolean theMultiFile); -/*! \brief Saving the study in a specified HDF file (or files). + boolean IsReal( in string theVarName ) raises(StudyInvalidReference); - Saves the study in a specified file (or files). - \param aUrl The path to the definite file in whcih the study will be saved - \param aStudy The study which will be saved - \param theMultiFile If this parameter is True the study will be saved in several files. +/*! \brief Indicate if a variable is integer -See \ref example1 for an example of this method usage in batchmode of %SALOME application. + Return true if variable is integer otherwise return false. + \param theVarName is a name of the variable. */ - boolean SaveAs(in URL aUrl, // if the file already exists - in Study aStudy, - in boolean theMultiFile); // overwrite (as option) -/*! \brief Saving the study in a specified ASCII file (or files). + boolean IsInteger( in string theVarName ) raises(StudyInvalidReference); - Saves the study in a specified ASCII file (or files). +/*! \brief Indicate if a variable is boolean - \param aUrl The path to the definite file in whcih the study will be saved - \param aStudy The study which will be saved - \param theMultiFile If this parameter is True the study will be saved in several files. + Return true if variable is boolean otherwise return false. + \param theVarName is a name of the variable. */ - boolean SaveAsASCII(in URL aUrl, // if the file already exists - in Study aStudy, - in boolean theMultiFile); // overwrite (as option) + boolean IsBoolean( in string theVarName ) raises(StudyInvalidReference); +/*! \brief Indicate if a variable is string -/*! \brief List of open studies. + Return true if variable is string otherwise return false. + \param theVarName is a name of the variable. +*/ + boolean IsString( in string theVarName ) raises(StudyInvalidReference); -Gets the list of open studies +/*! \brief Indicate if a variable exists in the study - \return A list of open studies in the current session. + Return true if variable exists in the study, + otherwise return false. + \param theVarName is a name of the variable. */ - ListOfOpenStudies GetOpenStudies(); - -/*! \brief Getting a particular %Study picked by name + boolean IsVariable( in string theVarName ) raises(StudyInvalidReference); - Activates a particular %Study - among the session collection picking it by name. - \param aStudyName The name of the study +/*! \brief Get names of all variables from the study. */ - Study GetStudyByName (in string aStudyName); + ListOfStrings GetVariableNames() raises(StudyInvalidReference); -/*! \brief Getting a particular %Study picked by ID +/*! \brief Remove a variable + + Remove variable with the specified name from the study with substitution of its value. - Activates a particular %Study - among the session collection picking it by ID. - \param aStudyID The ID of the study + \param theVarName Name of the variable. + \return Status of operation. */ - Study GetStudyByID (in short aStudyID); + boolean RemoveVariable( in string theVarName ) raises(StudyInvalidReference); - // copy/paste methods +/*! \brief Rename a variable -/*! - Returns True, if the given %SObject can be copied to the clipboard. -*/ - boolean CanCopy(in SObject theObject); -/*! - Returns True, if the given %SObject is copied to the clipboard. - \param theObject The %SObject which will be copied -*/ - boolean Copy(in SObject theObject); -/*! - Returns True, if the object from the clipboard can be pasted to the given %SObject. - \param theObject The %SObject stored in the clipboard. -*/ - boolean CanPaste(in SObject theObject); -/*! - Returns the %SObject in which the object from the clipboard was pasted to. - \param theObject The %SObject which will be pasted - \exception SALOMEDS::StudyBuilder::LockProtection This exception is raised, when trying to paste - an object into a study, which is protected for modifications. + Rename variable with the specified name within the study. + + \param theVarName Name of the variable. + \param theNewVarName New name for the variable. + \return Status of operation. */ - SObject Paste(in SObject theObject) raises (SALOMEDS::StudyBuilder::LockProtection); + boolean RenameVariable( in string theVarName, in string theNewVarName ) raises(StudyInvalidReference); -/*! \brief Object conversion. +/*! \brief Indicate whether variable is used - Converts an object into IOR. - \return IOR + Check that variable is used in the study. + + \param theVarName Name of the variable. + \return Variable usage. */ - string ConvertObjectToIOR(in Object theObject); -/*! \brief Object conversion. + boolean IsVariableUsed( in string theVarName ) raises(StudyInvalidReference); - Converts IOR into an object. - \return An object +/*! \brief Parse variables used for object creation + + \param string with variables, separated by special symbol. + \return Variables list. */ - Object ConvertIORToObject(in string theIOR); + ListOfListOfStrings ParseVariables( in string theVars ) raises(StudyInvalidReference); /*! - Private method, returns an implementation of this StudyManager. - \param theHostname is a hostname of the caller - \param thePID is a process ID of the caller - \param isLocal is set True if the StudyManager is launched locally with the caller + Attach an observer to the Study + + \param theObserver observer being attached + \param modify when \c true, observer receives any object's modification events; + otherwise observer receives object's creation events only */ - long long GetLocalImpl(in string theHostname, in long thePID, out boolean isLocal); + void attach(in SALOMEDS::Observer theObserver, in boolean modify); +/*! + Detach an observer from the Study + \param theObserver observer to be detached +*/ + void detach(in SALOMEDS::Observer theObserver); }; - //========================================================================== /*! \brief %SObject interface @@ -1374,7 +1272,7 @@ This class represents a common tool for all components integrated into SALOME ap can be called by any component and which provide the following functionality:
  • publishing in the study of the objects created by a definite component -
  • saving/loading of the data created by a definite component. These methods are called by the StudyManager when loading/saving a study containing the data created by a definite component. +
  • saving/loading of the data created by a definite component. These methods are called when loading/saving a study containing the data created by a definite component.
  • transforming of the transient references into persistant references (or vice versa) of the SObjects when saving (or loading) a study
  • copy/paste common functionality. These methods can be called by any component in order to copy/paste its object created in the study
@@ -1386,7 +1284,7 @@ can be called by any component and which provide the following functionality: /*! \brief Saving the data produced by a definite component. - This method is called by the StudyManager when saving a study. + This method is called when saving a study. \param theComponent %SComponent corresponding to this Component \param theURL The path to the file in which the data will be saved. \param isMultiFile If the value of this boolean parameter is True, the data will be saved in several files. @@ -1401,7 +1299,7 @@ can be called by any component and which provide the following functionality: /*! \brief Saving the data in ASCII format produced by a definite component. - This method is called by the StudyManager when saving a study in ASCII format. + This method is called when saving a study in ASCII format. \param theComponent %SComponent corresponding to this Component \param theURL The path to the file in which the data will be saved. \param isMultiFile If the value of this boolean parameter is True, the data will be saved in several files. @@ -1414,7 +1312,7 @@ can be called by any component and which provide the following functionality: /*! \brief Loading the data. - This method is called by the StudyManager when opening a study. + This method is called when opening a study. \param theComponent %SComponent corresponding to this Component \param theStream The file which contains all data saved by the component on Save method \param isMultiFile If the value of this boolean parameter is True, the data will be loaded from several files @@ -1425,7 +1323,7 @@ can be called by any component and which provide the following functionality: /*! \brief Loading the data from files in ASCII format. - This method is called by the StudyManager when opening a study. + This method is called when opening a study. \param theComponent %SComponent corresponding to this Component \param theStream The file which contains all data saved by the component on Save method \param isMultiFile If the value of this boolean parameter is True, the data will be loaded from several files @@ -1436,7 +1334,7 @@ can be called by any component and which provide the following functionality: /*! \brief Closing of the study - This method Close is called by the StudyManager when closing a study. + This method Close is called when closing a study. \param aSComponent The according %SComponent */ diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 1e6df7625..012cfc644 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -90,12 +90,9 @@ module Engines \param componentName Name of the component which will be registered in Registry and Name Service, (instance number suffix added to the registered name) - \param studyId 0 if instance is not associated to a study, - >0 otherwise (== study id) \return a loaded component */ - Engines::EngineComponent create_component_instance(in string componentName, - in long studyId); + Engines::EngineComponent create_component_instance(in string componentName); //! Create a new Python servant instance of a generic service. /*! @@ -118,25 +115,20 @@ module Engines \param componentName Name of the component which will be registered in Registry and Name Service, (instance number suffix added to the registered name) - \param studyId 0 if instance is not associated to a study, - >0 otherwise (== study id) \param env a dict of env variables \param reason in case of error (return nil) a string explaining the error \return a loaded component */ Engines::EngineComponent create_component_instance_env(in string componentName, - in long studyId, in FieldsDict env, + in FieldsDict env, out string reason); //! Find a servant instance of a component /*! \param registeredName Name of the component in Registry or Name Service, without instance suffix number - \param studyId 0 if instance is not associated to a study, - >0 otherwise (== study id) - \return the first instance found with same studyId + \return the first instance found */ - EngineComponent find_component_instance(in string registeredName, - in long studyId); + EngineComponent find_component_instance(in string registeredName); //! Find a servant instance of a component, or create a new one. /*! @@ -261,15 +253,6 @@ module Engines //! Determines whether the server has already been loaded or not. void ping(); - //! Get study associated to component instance - /*! - get study associated to component instance - \return -1: not initialised (Internal Error) - 0: multistudy component instance - >0: study id associated to this instance - */ - long getStudyId(); - //! Remove component instance from container /*! Deactivates the %Component. @@ -469,11 +452,10 @@ module Engines It is worth using this method only if hasObjectInfo() method returns true. \param entry object's entry. - \param studyId study id \return an information about the given object. */ - string getObjectInfo(in long studyId, in string entry); + string getObjectInfo(in string entry); //! Get version of the component /*! diff --git a/idl/SALOME_PACOExtension.idl b/idl/SALOME_PACOExtension.idl index 855f6f73c..ecedde31a 100644 --- a/idl/SALOME_PACOExtension.idl +++ b/idl/SALOME_PACOExtension.idl @@ -39,8 +39,7 @@ module Engines // Replicated Method used by the proxy to create // a PACO Component void create_paco_component_node_instance(in string registeredName, - in string proxy_containerName, - in long studyId) raises(SALOME::SALOME_Exception); + in string proxy_containerName) raises(SALOME::SALOME_Exception); void updateInstanceNumber(); }; diff --git a/idl/SALOME_Session.idl b/idl/SALOME_Session.idl index 90509c0bb..8f1957446 100644 --- a/idl/SALOME_Session.idl +++ b/idl/SALOME_Session.idl @@ -94,8 +94,6 @@ module SALOME long getPID(); //! Returns host name string getHostname(); -//! Get Active study ID - long GetActiveStudyId(); //! Restores a state of the study at theSavePoint boolean restoreVisualState(in long theSavePoint); diff --git a/src/Basics/Basics_DirUtils.cxx b/src/Basics/Basics_DirUtils.cxx index 549ebafc2..38020be9a 100644 --- a/src/Basics/Basics_DirUtils.cxx +++ b/src/Basics/Basics_DirUtils.cxx @@ -44,14 +44,22 @@ # define _separator_ '/' #endif +#define _extension_ ".hdf" + namespace Kernel_Utils { - std::string GetBaseName( const std::string& file_path ) + std::string GetBaseName( const std::string& file_path, const bool with_extension ) { + std::string tmp_str = file_path; int pos = file_path.rfind( _separator_ ); if ( pos >= 0 ) - return pos < (int)file_path.size()-1 ? file_path.substr( pos+1 ) : ""; - return file_path; + tmp_str = pos < (int)file_path.size()-1 ? file_path.substr( pos+1 ) : ""; + + pos = tmp_str.rfind( _extension_ ); + if( !with_extension && pos >= 0 ) + tmp_str = pos < (int)file_path.size()-1 ? file_path.substr( 0, pos ) : ""; + + return tmp_str; } std::string GetDirName( const std::string& file_path ) @@ -157,6 +165,15 @@ namespace Kernel_Utils return aFilePath; } + std::string AddExtension( const std::string& name ) + { + std::string tmp_str = name; + int pos = tmp_str.rfind( _extension_ ); + if( pos < 0 ) + return tmp_str.append( _extension_ ); + return tmp_str; + } + //============================================================================ // function : IsExists // purpose : Returns True(False) if the path (not)exists diff --git a/src/Basics/Basics_DirUtils.hxx b/src/Basics/Basics_DirUtils.hxx index edc100ebe..787277ad6 100644 --- a/src/Basics/Basics_DirUtils.hxx +++ b/src/Basics/Basics_DirUtils.hxx @@ -32,7 +32,7 @@ namespace Kernel_Utils { // Extracts and returns the base name of the specified file name. - BASICS_EXPORT std::string GetBaseName( const std::string& file_path ); + BASICS_EXPORT std::string GetBaseName( const std::string& file_path, bool with_extension = true ); // Extracts and returns the dir name of the specified file name. BASICS_EXPORT std::string GetDirName( const std::string& file_path ); @@ -49,11 +49,13 @@ namespace Kernel_Utils // /tmp/something/ for Unix or c:\something\ for WIN32 BASICS_EXPORT std::string GetTmpDir(); - // Returns the unique temporary file name without any extension // /tmp/something/file for Unix or c:\something\file for WIN32 BASICS_EXPORT std::string GetTmpFileName(); + // Adds extension in the end of the specified file name. + BASICS_EXPORT std::string AddExtension( const std::string& name ); + // Returns True(False) if the path (not)exists BASICS_EXPORT bool IsExists( const std::string& path ); diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 8a84c67d1..7857a5d10 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -51,7 +51,7 @@ int SIGUSR11 = 1000; extern bool _Sleeping ; static Engines_Component_i * theEngines_Component ; -bool Engines_Component_i::_isMultiStudy = true; +bool Engines_Component_i::_isMultiStudy = false; bool Engines_Component_i::_isMultiInstance = false; /*! \class Engines_Component_i @@ -101,7 +101,6 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _Executed(false) , _graphName("") , _nodeName(""), - _studyId(-1), _id(0), _contId(0), _CanceledThread(false) @@ -155,7 +154,6 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _Executed(false) , _graphName("") , _nodeName(""), - _studyId(-1), _id(0), _contId(0), _CanceledThread(false) @@ -227,20 +225,6 @@ char* Engines_Component_i::interfaceName() return CORBA::string_dup(_interfaceName.c_str()) ; } -//============================================================================= -/*! - * CORBA method: Get study Id - * \return -1: not initialised (Internal Error) - * 0: multistudy component instance - * >0: study id associated to this instance - */ -//============================================================================= - -CORBA::Long Engines_Component_i::getStudyId() -{ - return _studyId; -} - //============================================================================= /*! * CORBA method: Test if instance is alive and responds @@ -606,31 +590,6 @@ Engines_Container_i *Engines_Component_i::GetContainerPtr() return dynamic_cast(_poa->id_to_servant(contId)) ; } -//============================================================================= -/*! - * C++ method: set study Id - * \param studyId 0 if instance is not associated to a study, - * >0 otherwise (== study id) - * \return true if the set of study Id is OK - * must be set once by Container, at instance creation, - * and cannot be changed after. - */ -//============================================================================= - -CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId) -{ - ASSERT( studyId >= 0); - CORBA::Boolean ret = false; - if (_studyId < 0) // --- not yet initialized - { - _studyId = studyId; - ret = true; - } - else - if ( _studyId == studyId) ret = true; - return ret; -} - //============================================================================= /*! * C++ method: return CORBA instance id, the id is set in derived class diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 68373b289..085651006 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -255,17 +255,17 @@ Engines_Container_i::~Engines_Container_i() if(_NS) delete _NS; for(std::map::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++) - { - Engines::PyNode_var tmpVar((*it).second); - if(!CORBA::is_nil(tmpVar)) - tmpVar->UnRegister(); - } + { + Engines::PyNode_var tmpVar((*it).second); + if(!CORBA::is_nil(tmpVar)) + tmpVar->UnRegister(); + } for(std::map::iterator it=_dftPyScriptNode.begin();it!=_dftPyScriptNode.end();it++) - { - Engines::PyScriptNode_var tmpVar((*it).second); - if(!CORBA::is_nil(tmpVar)) - tmpVar->UnRegister(); - } + { + Engines::PyScriptNode_var tmpVar((*it).second); + if(!CORBA::is_nil(tmpVar)) + tmpVar->UnRegister(); + } } //============================================================================= @@ -370,20 +370,20 @@ void Engines_Container_i::Shutdown() */ std::map::iterator itm; for (itm = _listInstances_map.begin(); itm != _listInstances_map.end(); itm++) + { + try + { + itm->second->destroy(); + } + catch(const CORBA::Exception& e) + { + // ignore this entry and continue + } + catch(...) { - try - { - itm->second->destroy(); - } - catch(const CORBA::Exception& e) - { - // ignore this entry and continue - } - catch(...) - { - // ignore this entry and continue - } + // ignore this entry and continue } + } _listInstances_map.clear(); _NS->Destroy_FullDirectory(_containerName.c_str()); @@ -414,15 +414,15 @@ Engines_Container_i::load_component_Library(const char* componentName, CORBA::St //================================================================= std::string retso; if(load_component_CppImplementation(componentName,retso)) - { - reason=CORBA::string_dup(""); - return true; - } + { + reason=CORBA::string_dup(""); + return true; + } else if(retso != "ImplementationNotFound") - { - reason=CORBA::string_dup(retso.c_str()); - return false; - } + { + reason=CORBA::string_dup(retso.c_str()); + return false; + } retso="Component "; retso+=componentName; @@ -434,15 +434,15 @@ Engines_Container_i::load_component_Library(const char* componentName, CORBA::St //================================================================= std::string retpy; if(load_component_PythonImplementation(componentName,retpy)) - { - reason=CORBA::string_dup(""); - return true; - } + { + reason=CORBA::string_dup(""); + return true; + } else if(retpy != "ImplementationNotFound") - { - reason=CORBA::string_dup(retpy.c_str()); - return false; - } + { + reason=CORBA::string_dup(retpy.c_str()); + return false; + } retpy="Component "; retpy+=componentName; @@ -455,15 +455,15 @@ Engines_Container_i::load_component_Library(const char* componentName, CORBA::St //================================================================= std::string retex; if(load_component_ExecutableImplementation(componentName,retex)) - { - reason=CORBA::string_dup(""); - return true; - } + { + reason=CORBA::string_dup(""); + return true; + } else if(retex != "ImplementationNotFound") - { - reason=CORBA::string_dup(retex.c_str()); - return false; - } + { + reason=CORBA::string_dup(retex.c_str()); + return false; + } retex="Component "; retex+=componentName; @@ -504,63 +504,63 @@ Engines_Container_i::load_component_CppImplementation(const char* componentName, // (see decInstanceCnt, finalize_removal)) if (_toRemove_map.count(impl_name) != 0) _toRemove_map.erase(impl_name); if (_library_map.count(impl_name) != 0) - { - MESSAGE("Library " << impl_name << " already loaded"); - _numInstanceMutex.unlock(); - reason=""; - return true; - } + { + MESSAGE("Library " << impl_name << " already loaded"); + _numInstanceMutex.unlock(); + reason=""; + return true; + } _numInstanceMutex.unlock(); #ifndef WIN32 void* handle; handle = dlopen( impl_name.c_str() , RTLD_NOW ) ; if ( !handle ) + { + //not loadable. Try to find the lib file in LD_LIBRARY_PATH + std::string path; + char* p=getenv("LD_LIBRARY_PATH"); + if(p)path=p; + path=path+SEP+"/usr/lib"+SEP+"/lib"; + + std::string pth; + if(findpathof(path, pth, impl_name)) { - //not loadable. Try to find the lib file in LD_LIBRARY_PATH - std::string path; - char* p=getenv("LD_LIBRARY_PATH"); - if(p)path=p; - path=path+SEP+"/usr/lib"+SEP+"/lib"; - - std::string pth; - if(findpathof(path, pth, impl_name)) - { - //found but not loadable - reason="Component "; - reason+=aCompName; - reason+=": C++ implementation found "; - reason+=pth; - reason+=" but it is not loadable. Error:\n"; - reason+=dlerror(); - std::cerr << reason << std::endl; - return false; - } - else - { - //not found - //continue with other implementation - reason="ImplementationNotFound"; - return false; - } + //found but not loadable + reason="Component "; + reason+=aCompName; + reason+=": C++ implementation found "; + reason+=pth; + reason+=" but it is not loadable. Error:\n"; + reason+=dlerror(); + std::cerr << reason << std::endl; + return false; + } + else + { + //not found + //continue with other implementation + reason="ImplementationNotFound"; + return false; } + } #else HINSTANCE handle; handle = LoadLibrary( impl_name.c_str() ); if ( !handle ) - { - reason="ImplementationNotFound"; - } + { + reason="ImplementationNotFound"; + } #endif if ( handle ) - { - _numInstanceMutex.lock(); - _library_map[impl_name] = handle; - _numInstanceMutex.unlock(); - reason=""; - return true; - } + { + _numInstanceMutex.lock(); + _library_map[impl_name] = handle; + _numInstanceMutex.unlock(); + reason=""; + return true; + } return false; @@ -581,11 +581,11 @@ Engines_Container_i::load_component_PythonImplementation(const char* componentNa _numInstanceMutex.lock() ; // lock to be alone (stl container write) if (_library_map.count(aCompName) != 0) - { - _numInstanceMutex.unlock() ; - reason=""; - return true; // Python Component, already imported - } + { + _numInstanceMutex.unlock() ; + reason=""; + return true; // Python Component, already imported + } _numInstanceMutex.unlock() ; PyGILState_STATE gstate = PyGILState_Ensure(); @@ -599,24 +599,24 @@ Engines_Container_i::load_component_PythonImplementation(const char* componentNa PyGILState_Release(gstate); if (reason=="") - { - //Python component has been loaded (import componentName) - _numInstanceMutex.lock() ; // lock to be alone (stl container write) - _library_map[aCompName] = (void *)_pyCont; // any non O value OK - _numInstanceMutex.unlock() ; - MESSAGE("import Python: "<< aCompName <<" OK"); - return true; - } + { + //Python component has been loaded (import componentName) + _numInstanceMutex.lock() ; // lock to be alone (stl container write) + _library_map[aCompName] = (void *)_pyCont; // any non O value OK + _numInstanceMutex.unlock() ; + MESSAGE("import Python: "<< aCompName <<" OK"); + return true; + } else if(reason=="ImplementationNotFound") - { - //Python implementation has not been found. Continue with other implementation - reason="ImplementationNotFound"; - } + { + //Python implementation has not been found. Continue with other implementation + reason="ImplementationNotFound"; + } else - { - //Python implementation has been found but loading has failed - std::cerr << reason << std::endl; - } + { + //Python implementation has been found but loading has failed + std::cerr << reason << std::endl; + } return false; } @@ -642,27 +642,27 @@ Engines_Container_i::load_component_ExecutableImplementation(const char* compone if(p)path=p; if (findpathof(path, pth, executable)) + { + if(checkifexecutable(pth)) { - if(checkifexecutable(pth)) - { - _numInstanceMutex.lock() ; // lock to be alone (stl container write) - _library_map[executable] = (void *)1; // any non O value OK - _numInstanceMutex.unlock() ; - MESSAGE("import executable: "<< pth <<" OK"); - reason=""; - return true; - } - reason="Component "; - reason+=aCompName; - reason+=": implementation found "; - reason+=pth; - reason+=" but it is not executable"; - std::cerr << reason << std::endl; + _numInstanceMutex.lock() ; // lock to be alone (stl container write) + _library_map[executable] = (void *)1; // any non O value OK + _numInstanceMutex.unlock() ; + MESSAGE("import executable: "<< pth <<" OK"); + reason=""; + return true; } + reason="Component "; + reason+=aCompName; + reason+=": implementation found "; + reason+=pth; + reason+=" but it is not executable"; + std::cerr << reason << std::endl; + } else - { - reason="ImplementationNotFound"; - } + { + reason="ImplementationNotFound"; + } return false; } @@ -673,19 +673,16 @@ Engines_Container_i::load_component_ExecutableImplementation(const char* compone * The servant registers itself to naming service and Registry. * \param genericRegisterName Name of the component instance to register * in Registry & Name Service (without _inst_n suffix) -* \param studyId 0 for multiStudy instance, -* study Id (>0) otherwise * \return a loaded component */ //============================================================================= Engines::EngineComponent_ptr -Engines_Container_i::create_component_instance(const char*genericRegisterName, - CORBA::Long studyId) +Engines_Container_i::create_component_instance(const char*genericRegisterName) { Engines::FieldsDict_var env = new Engines::FieldsDict; char* reason; Engines::EngineComponent_ptr compo = - create_component_instance_env(genericRegisterName, studyId, env, reason); + create_component_instance_env(genericRegisterName, env, reason); CORBA::string_free(reason); return compo; } @@ -697,8 +694,6 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName, * The servant registers itself to naming service and Registry. * \param genericRegisterName Name of the component instance to register * in Registry & Name Service (without _inst_n suffix) -* \param studyId 0 for multiStudy instance, -* study Id (>0) otherwise * \param env dict of env variables * \param reason explains error when create_component_instance_env fails * \return a loaded component @@ -706,44 +701,36 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName, //============================================================================= Engines::EngineComponent_ptr Engines_Container_i::create_component_instance_env(const char*genericRegisterName, - CORBA::Long studyId, const Engines::FieldsDict& env, CORBA::String_out reason) { - if (studyId < 0) - { - INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy"); - reason=CORBA::string_dup("studyId must be > 0 for mono study instance, =0 for multiStudy"); - return Engines::EngineComponent::_nil() ; - } - std::string error; if (_library_map.count(genericRegisterName) != 0) - { - // It's a Python component - Engines::EngineComponent_ptr compo = createPythonInstance(genericRegisterName, studyId, error); - reason=CORBA::string_dup(error.c_str()); - return compo; - } + { + // It's a Python component + Engines::EngineComponent_ptr compo = createPythonInstance(genericRegisterName, error); + reason=CORBA::string_dup(error.c_str()); + return compo; + } std::string impl_name = std::string(LIB) + genericRegisterName + ENGINESO; if (_library_map.count(impl_name) != 0) - { - // It's a C++ component - void* handle = _library_map[impl_name]; - Engines::EngineComponent_ptr compo = createInstance(genericRegisterName, handle, studyId, error); - reason=CORBA::string_dup(error.c_str()); - return compo; - } + { + // It's a C++ component + void* handle = _library_map[impl_name]; + Engines::EngineComponent_ptr compo = createInstance(genericRegisterName, handle, error); + reason=CORBA::string_dup(error.c_str()); + return compo; + } impl_name = std::string(genericRegisterName) + ".exe"; if (_library_map.count(impl_name) != 0) - { - //It's an executable component - Engines::EngineComponent_ptr compo = createExecutableInstance(genericRegisterName, studyId, env, error); - reason=CORBA::string_dup(error.c_str()); - return compo; - } + { + //It's an executable component + Engines::EngineComponent_ptr compo = createExecutableInstance(genericRegisterName, env, error); + reason=CORBA::string_dup(error.c_str()); + return compo; + } error="load_component_Library has probably not been called for component: "; error += genericRegisterName; @@ -756,8 +743,6 @@ Engines_Container_i::create_component_instance_env(const char*genericRegisterNam //! Create a new component instance (Executable implementation) /*! * \param CompName Name of the component instance -* \param studyId 0 for multiStudy instance, -* study Id (>0) otherwise * \param env dict of env variables * \param reason explains error when creation fails * \return a loaded component @@ -768,7 +753,7 @@ Engines_Container_i::create_component_instance_env(const char*genericRegisterNam */ //============================================================================= Engines::EngineComponent_ptr -Engines_Container_i::createExecutableInstance(std::string CompName, int studyId, +Engines_Container_i::createExecutableInstance(std::string CompName, const Engines::FieldsDict& env, std::string& reason) { @@ -822,35 +807,35 @@ Engines_Container_i::createExecutableInstance(std::string CompName, int studyId, int status; pid_t pid = fork(); if(pid == 0) // child + { + for (CORBA::ULong i=0; i < env.length(); i++) { - for (CORBA::ULong i=0; i < env.length(); i++) - { - if (env[i].value.type()->kind() == CORBA::tk_string) - { - const char* value; - env[i].value >>= value; - std::string s(env[i].key); - s+='='; - s+=value; - putenv(strdup(s.c_str())); - } - } - - execl("/bin/sh", "sh", "-c", command.c_str() , (char *)0); - status=-1; + if (env[i].value.type()->kind() == CORBA::tk_string) + { + const char* value; + env[i].value >>= value; + std::string s(env[i].key); + s+='='; + s+=value; + putenv(strdup(s.c_str())); + } } + + execl("/bin/sh", "sh", "-c", command.c_str() , (char *)0); + status=-1; + } else if(pid < 0) // failed to fork - { - status=-1; - } + { + status=-1; + } else //parent + { + pid_t tpid; + do { - pid_t tpid; - do - { - tpid = wait(&status); - } while (tpid != pid); - } + tpid = wait(&status); + } while (tpid != pid); + } #else // launch component with a system call int status=system(command.c_str()); @@ -920,14 +905,12 @@ Engines_Container_i::createExecutableInstance(std::string CompName, int studyId, //! Create a new component instance (Python implementation) /*! * \param CompName Name of the component instance -* \param studyId 0 for multiStudy instance, -* study Id (>0) otherwise * \param reason explains error when creation fails * \return a loaded component */ //============================================================================= Engines::EngineComponent_ptr -Engines_Container_i::createPythonInstance(std::string CompName, int studyId, +Engines_Container_i::createPythonInstance(std::string CompName, std::string& reason) { Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil() ; @@ -947,8 +930,7 @@ Engines_Container_i::createPythonInstance(std::string CompName, int studyId, (char*)"create_component_instance", (char*)"ssl", CompName.c_str(), - instanceName.c_str(), - studyId); + instanceName.c_str()); const char *ior; const char *error; PyArg_ParseTuple(result,"ss", &ior, &error); @@ -958,11 +940,11 @@ Engines_Container_i::createPythonInstance(std::string CompName, int studyId, PyGILState_Release(gstate); if( iors!="" ) - { - CORBA::Object_var obj = _orb->string_to_object(iors.c_str()); - iobject = Engines::EngineComponent::_narrow( obj ) ; - _listInstances_map[instanceName] = iobject; - } + { + CORBA::Object_var obj = _orb->string_to_object(iors.c_str()); + iobject = Engines::EngineComponent::_narrow( obj ) ; + _listInstances_map[instanceName] = iobject; + } return iobject._retn(); } @@ -1009,8 +991,6 @@ Engines_Container_i::create_python_service_instance(const char * CompName, * in Registry & Name Service, * (without _inst_n suffix, like "COMPONENT") * \param handle loaded library handle -* \param studyId 0 for multiStudy instance, -* study Id (>0) otherwise * \param reason explains error when creation fails * \return a loaded component * @@ -1026,7 +1006,6 @@ Engines_Container_i::create_python_service_instance(const char * CompName, Engines::EngineComponent_ptr Engines_Container_i::createInstance(std::string genericRegisterName, void *handle, - int studyId, std::string& reason) { // --- find the factory @@ -1080,30 +1059,23 @@ Engines_Container_i::createInstance(std::string genericRegisterName, id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str(), aGenRegisterName.c_str() ) ; if (id == NULL) - { - reason="Can't get ObjectId from factory"; - INFOS(reason); - return iobject._retn(); - } + { + reason="Can't get ObjectId from factory"; + INFOS(reason); + return iobject._retn(); + } - // --- get reference & servant from id + // --- get reference from id CORBA::Object_var obj = _poa->id_to_reference(*id); iobject = Engines::EngineComponent::_narrow( obj ) ; - Engines_Component_i *servant = - dynamic_cast(_poa->reference_to_servant(iobject)); - ASSERT(servant); - //SCRUTE(servant->_refcount_value()); _numInstanceMutex.lock() ; // lock to be alone (stl container write) _listInstances_map[instanceName] = iobject; _cntInstances_map[aGenRegisterName] += 1; _numInstanceMutex.unlock() ; SCRUTE(aGenRegisterName); SCRUTE(_cntInstances_map[aGenRegisterName]); - servant->setStudyId(studyId); - servant->_remove_ref(); // do not need servant any more (remove ref from reference_to_servant) - //SCRUTE(servant->_refcount_value()); // --- register the engine under the name // containerName(.dir)/instanceName(.object) @@ -1125,14 +1097,11 @@ Engines_Container_i::createInstance(std::string genericRegisterName, * CORBA method: Finds a servant instance of a component * \param registeredName Name of the component in Registry or Name Service, * without instance suffix number -* \param studyId 0 if instance is not associated to a study, -* >0 otherwise (== study id) -* \return the first instance found with same studyId +* \return the first found instance */ //============================================================================= Engines::EngineComponent_ptr -Engines_Container_i::find_component_instance( const char* registeredName, - CORBA::Long studyId) +Engines_Container_i::find_component_instance( const char* registeredName) { Engines::EngineComponent_var anEngine = Engines::EngineComponent::_nil(); std::map::iterator itm =_listInstances_map.begin(); @@ -1143,10 +1112,7 @@ Engines_Container_i::find_component_instance( const char* registeredName, if (instance.find(registeredName) == 0) { anEngine = (*itm).second; - if (studyId == anEngine->getStudyId()) - { - return anEngine._retn(); - } + return anEngine._retn(); } itm++; } @@ -1312,29 +1278,11 @@ Engines_Container_i::find_or_create_instance(std::string genericRegisterName, { iobject = createInstance(genericRegisterName, handle, - 0, - reason); // force multiStudy instance here ! + reason); } else { iobject = Engines::EngineComponent::_narrow( obj ) ; - Engines_Component_i *servant = - dynamic_cast - (_poa->reference_to_servant(iobject)); - ASSERT(servant) - int studyId = servant->getStudyId(); - ASSERT (studyId >= 0); - if (studyId == 0) // multiStudy instance, OK - { - // No ReBind ! - MESSAGE(component_registerBase.c_str()<<" already bound"); - } - else // monoStudy instance: NOK - { - iobject = Engines::EngineComponent::_nil(); - INFOS("load_impl & find_component_instance methods " - << "NOT SUITABLE for mono study components"); - } } } catch (...) @@ -1624,36 +1572,36 @@ void Engines_Container_i::copyFile(Engines::Container_ptr container, const char* FILE* fp; if ((fp = fopen(localFile,"wb")) == NULL) - { - INFOS("file " << localFile << " cannot be open for writing"); - return; - } + { + INFOS("file " << localFile << " cannot be open for writing"); + return; + } CORBA::Long fileId = fileTransfer->open(remoteFile); if (fileId > 0) + { + Engines::fileBlock* aBlock; + int toFollow = 1; + int ctr=0; + while (toFollow) { - Engines::fileBlock* aBlock; - int toFollow = 1; - int ctr=0; - while (toFollow) - { - ctr++; - //SCRUTE(ctr); - aBlock = fileTransfer->getBlock(fileId); - toFollow = aBlock->length(); - //SCRUTE(toFollow); - CORBA::Octet *buf = aBlock->get_buffer(); - fwrite(buf, sizeof(CORBA::Octet), toFollow, fp); - delete aBlock; - } - fclose(fp); - MESSAGE("end of transfer"); - fileTransfer->close(fileId); + ctr++; + //SCRUTE(ctr); + aBlock = fileTransfer->getBlock(fileId); + toFollow = aBlock->length(); + //SCRUTE(toFollow); + CORBA::Octet *buf = aBlock->get_buffer(); + fwrite(buf, sizeof(CORBA::Octet), toFollow, fp); + delete aBlock; } + fclose(fp); + MESSAGE("end of transfer"); + fileTransfer->close(fileId); + } else - { - INFOS("open reference file for copy impossible"); - } + { + INFOS("open reference file for copy impossible"); + } } //============================================================================= @@ -1665,57 +1613,57 @@ void Engines_Container_i::copyFile(Engines::Container_ptr container, const char* //============================================================================= Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, const char* code) { - Engines::PyNode_var node= Engines::PyNode::_nil(); + Engines::PyNode_var node= Engines::PyNode::_nil(); - PyGILState_STATE gstate = PyGILState_Ensure(); - PyObject *res = PyObject_CallMethod(_pyCont, - (char*)"create_pynode", - (char*)"ss", - nodeName, - code); - if(res==NULL) - { - //internal error - PyErr_Print(); - PyGILState_Release(gstate); - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = "can not create a python node"; - throw SALOME::SALOME_Exception(es); - } - long ierr=PyInt_AsLong(PyTuple_GetItem(res,0)); - PyObject* result=PyTuple_GetItem(res,1); - std::string astr=PyString_AsString(result); - Py_DECREF(res); + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject *res = PyObject_CallMethod(_pyCont, + (char*)"create_pynode", + (char*)"ss", + nodeName, + code); + if(res==NULL) + { + //internal error + PyErr_Print(); PyGILState_Release(gstate); - if(ierr==0) - { - Utils_Locker lck(&_mutexForDftPy); - CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); - node=Engines::PyNode::_narrow(obj); - std::map::iterator it(_dftPyNode.find(nodeName)); - if(it==_dftPyNode.end()) - { - _dftPyNode[nodeName]=node; - } - else - { - Engines::PyNode_var oldNode((*it).second); - if(!CORBA::is_nil(oldNode)) - oldNode->UnRegister(); - (*it).second=node; - } - if(!CORBA::is_nil(node)) - node->Register(); - return node._retn(); - } + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "can not create a python node"; + throw SALOME::SALOME_Exception(es); + } + long ierr=PyInt_AsLong(PyTuple_GetItem(res,0)); + PyObject* result=PyTuple_GetItem(res,1); + std::string astr=PyString_AsString(result); + Py_DECREF(res); + PyGILState_Release(gstate); + if(ierr==0) + { + Utils_Locker lck(&_mutexForDftPy); + CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); + node=Engines::PyNode::_narrow(obj); + std::map::iterator it(_dftPyNode.find(nodeName)); + if(it==_dftPyNode.end()) + { + _dftPyNode[nodeName]=node; + } else - { - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = astr.c_str(); - throw SALOME::SALOME_Exception(es); - } + { + Engines::PyNode_var oldNode((*it).second); + if(!CORBA::is_nil(oldNode)) + oldNode->UnRegister(); + (*it).second=node; + } + if(!CORBA::is_nil(node)) + node->Register(); + return node._retn(); + } + else + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = astr.c_str(); + throw SALOME::SALOME_Exception(es); + } } //============================================================================= @@ -1730,13 +1678,13 @@ Engines::PyNode_ptr Engines_Container_i::getDefaultPyNode(const char *nodeName) if(it==_dftPyNode.end()) return Engines::PyNode::_nil(); else - { - Engines::PyNode_var tmpVar((*it).second); - if(!CORBA::is_nil(tmpVar)) - return Engines::PyNode::_duplicate(tmpVar); - else - return Engines::PyNode::_nil(); - } + { + Engines::PyNode_var tmpVar((*it).second); + if(!CORBA::is_nil(tmpVar)) + return Engines::PyNode::_duplicate(tmpVar); + else + return Engines::PyNode::_nil(); + } } //============================================================================= @@ -1748,58 +1696,58 @@ Engines::PyNode_ptr Engines_Container_i::getDefaultPyNode(const char *nodeName) //============================================================================= Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* nodeName, const char* code) { - Engines::PyScriptNode_var node= Engines::PyScriptNode::_nil(); + Engines::PyScriptNode_var node= Engines::PyScriptNode::_nil(); - PyGILState_STATE gstate = PyGILState_Ensure(); - PyObject *res = PyObject_CallMethod(_pyCont, - (char*)"create_pyscriptnode", - (char*)"ss", - nodeName, - code); - if(res==NULL) - { - //internal error - PyErr_Print(); - PyGILState_Release(gstate); - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = "can not create a python node"; - throw SALOME::SALOME_Exception(es); - } - long ierr=PyInt_AsLong(PyTuple_GetItem(res,0)); - PyObject* result=PyTuple_GetItem(res,1); - std::string astr=PyString_AsString(result); - Py_DECREF(res); + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject *res = PyObject_CallMethod(_pyCont, + (char*)"create_pyscriptnode", + (char*)"ss", + nodeName, + code); + if(res==NULL) + { + //internal error + PyErr_Print(); PyGILState_Release(gstate); + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "can not create a python node"; + throw SALOME::SALOME_Exception(es); + } + long ierr=PyInt_AsLong(PyTuple_GetItem(res,0)); + PyObject* result=PyTuple_GetItem(res,1); + std::string astr=PyString_AsString(result); + Py_DECREF(res); + PyGILState_Release(gstate); - if(ierr==0) - { - Utils_Locker lck(&_mutexForDftPy); - CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); - node=Engines::PyScriptNode::_narrow(obj); - std::map::iterator it(_dftPyScriptNode.find(nodeName)); - if(it==_dftPyScriptNode.end()) - { - _dftPyScriptNode[nodeName]=node; - } - else - { - Engines::PyScriptNode_var oldNode((*it).second); - if(!CORBA::is_nil(oldNode)) - oldNode->UnRegister(); - (*it).second=node; - } - if(!CORBA::is_nil(node)) - node->Register(); - return node._retn(); - } + if(ierr==0) + { + Utils_Locker lck(&_mutexForDftPy); + CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); + node=Engines::PyScriptNode::_narrow(obj); + std::map::iterator it(_dftPyScriptNode.find(nodeName)); + if(it==_dftPyScriptNode.end()) + { + _dftPyScriptNode[nodeName]=node; + } else - { - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = astr.c_str(); - throw SALOME::SALOME_Exception(es); - } + { + Engines::PyScriptNode_var oldNode((*it).second); + if(!CORBA::is_nil(oldNode)) + oldNode->UnRegister(); + (*it).second=node; + } + if(!CORBA::is_nil(node)) + node->Register(); + return node._retn(); + } + else + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = astr.c_str(); + throw SALOME::SALOME_Exception(es); + } } //============================================================================= @@ -1814,13 +1762,13 @@ Engines::PyScriptNode_ptr Engines_Container_i::getDefaultPyScriptNode(const char if(it==_dftPyScriptNode.end()) return Engines::PyScriptNode::_nil(); else - { - Engines::PyScriptNode_var tmpVar((*it).second); - if(!CORBA::is_nil(tmpVar)) - return Engines::PyScriptNode::_duplicate(tmpVar); - else - return Engines::PyScriptNode::_nil(); - } + { + Engines::PyScriptNode_var tmpVar((*it).second); + if(!CORBA::is_nil(tmpVar)) + return Engines::PyScriptNode::_duplicate(tmpVar); + else + return Engines::PyScriptNode::_nil(); + } } //============================================================================= diff --git a/src/Container/SALOME_Component_i.hxx b/src/Container/SALOME_Component_i.hxx index 4315da8b3..a69339168 100644 --- a/src/Container/SALOME_Component_i.hxx +++ b/src/Container/SALOME_Component_i.hxx @@ -81,7 +81,6 @@ public: void ping(); void destroy(); - CORBA::Long getStudyId(); Engines::Container_ptr GetContainerRef(); void setProperties(const Engines::FieldsDict& dico); @@ -118,7 +117,7 @@ public: // Object information virtual bool hasObjectInfo() { return false; } - virtual char* getObjectInfo(CORBA::Long studyId, const char* entry) { return CORBA::string_dup(""); } + virtual char* getObjectInfo(const char* entry) { return CORBA::string_dup(""); } // Version information virtual char* getVersion(); @@ -130,7 +129,6 @@ public: std::string getContainerName(); void setContainerName(); - virtual bool setStudyId(CORBA::Long studyId); static bool isMultiStudy(); static bool isMultiInstance(); static std::string GetDynLibraryName(const char *componentName); @@ -150,7 +148,6 @@ public: Salome_file_i * file); protected: - int _studyId; // -1: not initialised; 0: multiStudy; >0: study static bool _isMultiStudy; static bool _isMultiInstance; diff --git a/src/Container/SALOME_Container.py b/src/Container/SALOME_Container.py index 2d6ee3b75..298e23d17 100644 --- a/src/Container/SALOME_Container.py +++ b/src/Container/SALOME_Container.py @@ -102,7 +102,7 @@ class SALOME_Container_i: #------------------------------------------------------------------------- - def create_component_instance(self, componentName, instanceName, studyId): + def create_component_instance(self, componentName, instanceName): MESSAGE( "SALOME_Container_i::create_component_instance" ) comp_iors="" ret="" diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 197d0def9..1193ec379 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -69,12 +69,10 @@ public: virtual bool load_component_Library(const char* componentName, CORBA::String_out reason); virtual Engines::EngineComponent_ptr - create_component_instance( const char* componentName, - CORBA::Long studyId); // 0 for multiStudy + create_component_instance( const char* componentName); virtual Engines::EngineComponent_ptr create_component_instance_env( const char* componentName, - CORBA::Long studyId, // 0 for multiStudy const Engines::FieldsDict& env, CORBA::String_out reason); @@ -83,8 +81,7 @@ public: CORBA::String_out reason); Engines::EngineComponent_ptr - find_component_instance( const char* registeredName, - CORBA::Long studyId); // 0 for multiStudy + find_component_instance( const char* registeredName); Engines::EngineComponent_ptr load_impl(const char* nameToRegister, @@ -125,9 +122,9 @@ public: bool load_component_PythonImplementation(const char* componentName,std::string& reason); bool load_component_ExecutableImplementation(const char* componentName,std::string& reason); - Engines::EngineComponent_ptr createPythonInstance(std::string CompName, int studyId, std::string& error); - Engines::EngineComponent_ptr createExecutableInstance(std::string CompName, int studyId, const Engines::FieldsDict& env, std::string& error); - Engines::EngineComponent_ptr createInstance(std::string genericRegisterName, void *handle, int studyId, std::string& error); + Engines::EngineComponent_ptr createPythonInstance(std::string CompName, std::string& error); + Engines::EngineComponent_ptr createExecutableInstance(std::string CompName, const Engines::FieldsDict& env, std::string& error); + Engines::EngineComponent_ptr createInstance(std::string genericRegisterName, void *handle, std::string& error); static bool isPythonContainer(const char* ContainerName); static void decInstanceCnt(std::string genericRegisterName); diff --git a/src/KERNEL_PY/salome_ComponentGUI.py b/src/KERNEL_PY/salome_ComponentGUI.py index 9baeb7d5d..1ec8d1098 100644 --- a/src/KERNEL_PY/salome_ComponentGUI.py +++ b/src/KERNEL_PY/salome_ComponentGUI.py @@ -83,7 +83,7 @@ def setNameMode(objId, mode): #-------------------------------------------------------------------------- -def Init(studyId): +def Init(): return #-------------------------------------------------------------------------- diff --git a/src/KernelHelpers/SALOME_KernelServices.cxx b/src/KernelHelpers/SALOME_KernelServices.cxx index 481c1ac13..4b3a07d70 100644 --- a/src/KernelHelpers/SALOME_KernelServices.cxx +++ b/src/KernelHelpers/SALOME_KernelServices.cxx @@ -61,18 +61,17 @@ namespace KERNEL { /** - * This returns a static reference to the SALOME study manager. The - * study manager can be used to retrieve a study or to get - * informations about a study. + * This returns a static reference to the SALOME study. The + * study can be used to get informations about it. */ - SALOMEDS::StudyManager_ptr getStudyManager() { - static SALOMEDS::StudyManager_ptr aStudyManager; - if(CORBA::is_nil(aStudyManager)){ + SALOMEDS::Study_ptr getStudy() { + static SALOMEDS::Study_ptr aStudy; + if(CORBA::is_nil(aStudy)){ SALOME_NamingService *aNamingService = getNamingService(); - CORBA::Object_ptr anObject = aNamingService->Resolve("/myStudyManager"); - aStudyManager = SALOMEDS::StudyManager::_narrow(anObject); + CORBA::Object_ptr anObject = aNamingService->Resolve("/Study"); + aStudy = SALOMEDS::Study::_narrow(anObject); } - return aStudyManager; + return aStudy; } /** @@ -117,27 +116,6 @@ namespace KERNEL { return resourcesManager; } - /** - * This returns the study with the specified id if it's defined in - * the SALOME study manager. Returns null otherwise. - * Please not that it is just a shortcut, and you may prefer use - * directly the study manager: - * KERNEL::getStudyManager()->GetStudyByID(aStudyId) - */ - SALOMEDS::Study_ptr getStudyById(int aStudyId) { - if ( aStudyId < 0 ) { - INFOS("ERR: trying to get a study with ID<0"); - return SALOMEDS::Study::_nil(); - } - return getStudyManager()->GetStudyByID(aStudyId); - } - - int getStudyId(SALOMEDS::Study_ptr study) { - if( CORBA::is_nil(study) ) return -1; - return study->StudyId(); - } - - /** * This function retrieve the CORBA object reference from the study * object wrapping it. diff --git a/src/KernelHelpers/SALOME_KernelServices.hxx b/src/KernelHelpers/SALOME_KernelServices.hxx index 5c0f39edc..9496986b1 100644 --- a/src/KernelHelpers/SALOME_KernelServices.hxx +++ b/src/KernelHelpers/SALOME_KernelServices.hxx @@ -41,7 +41,7 @@ namespace KERNEL { KERNELHELPERS_EXPORT SALOME_NamingService * getNamingService(); KERNELHELPERS_EXPORT SALOME_LifeCycleCORBA * getLifeCycleCORBA(); KERNELHELPERS_EXPORT SALOME::Session_ptr getSalomeSession(); - KERNELHELPERS_EXPORT SALOMEDS::StudyManager_ptr getStudyManager(); + KERNELHELPERS_EXPORT SALOMEDS::Study_ptr getStudy(); KERNELHELPERS_EXPORT Engines::SalomeLauncher_ptr getSalomeLauncher(); KERNELHELPERS_EXPORT Engines::ResourcesManager_ptr getResourcesManager(); @@ -49,8 +49,6 @@ namespace KERNEL { // SALOME KERNEL services to deal with a SALOME study, SObject and // SComponent. // - KERNELHELPERS_EXPORT SALOMEDS::Study_ptr getStudyById(int aStudyId); - KERNELHELPERS_EXPORT int getStudyId(SALOMEDS::Study_ptr study); KERNELHELPERS_EXPORT CORBA::Object_ptr IORToObject(char * IOR); KERNELHELPERS_EXPORT CORBA::Object_ptr SObjectToObject(SALOMEDS::SObject_ptr); diff --git a/src/KernelHelpers/SALOME_StudyEditor.cxx b/src/KernelHelpers/SALOME_StudyEditor.cxx index 4a0bb4396..fe79af59d 100644 --- a/src/KernelHelpers/SALOME_StudyEditor.cxx +++ b/src/KernelHelpers/SALOME_StudyEditor.cxx @@ -30,18 +30,6 @@ void SALOME_StudyEditor::setStudy(SALOMEDS::Study_ptr study) { _sbuilder = _study->NewBuilder(); } -void SALOME_StudyEditor::setStudyById(int studyId) { - this->setStudy(KERNEL::getStudyManager()->GetStudyByID(studyId)); -} - -int SALOME_StudyEditor::getStudyId() { - if ( _study->_is_nil() ) return UNDEFINED; - return _study->StudyId(); -} - -SALOME_StudyEditor::SALOME_StudyEditor(int studyId) { - this->setStudyById(studyId); -} SALOME_StudyEditor::SALOME_StudyEditor(SALOMEDS::Study_ptr study) { this->setStudy(study); } diff --git a/src/KernelHelpers/SALOME_StudyEditor.hxx b/src/KernelHelpers/SALOME_StudyEditor.hxx index 23329461d..52b98fc5a 100644 --- a/src/KernelHelpers/SALOME_StudyEditor.hxx +++ b/src/KernelHelpers/SALOME_StudyEditor.hxx @@ -32,7 +32,6 @@ class KERNELHELPERS_EXPORT SALOME_StudyEditor { public: - SALOME_StudyEditor(int studyId); SALOME_StudyEditor(SALOMEDS::Study_ptr study); typedef std::vector SObjectList; @@ -58,8 +57,6 @@ public: protected: SALOME_StudyEditor(); void setStudy(SALOMEDS::Study_ptr study); - void setStudyById(int studyId); - int getStudyId(); SALOMEDS::Study_var _study; diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 75bf0dd5e..ecc25b84e 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -132,14 +132,12 @@ SALOME_LifeCycleCORBA::~SALOME_LifeCycleCORBA() * * \param params container parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the component instance, or _nil if not found */ //============================================================================= Engines::EngineComponent_ptr SALOME_LifeCycleCORBA::FindComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { if (! isKnownComponentClass(componentName)) return Engines::EngineComponent::_nil(); @@ -160,7 +158,6 @@ SALOME_LifeCycleCORBA::FindComponent(const Engines::ContainerParameters& params, Engines::EngineComponent_var compo = _FindComponent(new_params, componentName, - studyId, listOfResources); return compo._retn(); @@ -171,15 +168,13 @@ SALOME_LifeCycleCORBA::FindComponent(const Engines::ContainerParameters& params, * * \param params container parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the component instance, or _nil if problem */ //============================================================================= Engines::EngineComponent_ptr SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { // --- Check if Component Name is known in ModuleCatalog @@ -203,8 +198,7 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params, new_params.resource_params.resList = listOfResources; Engines::EngineComponent_var compo = _LoadComponent(new_params, - componentName, - studyId); + componentName); return compo._retn(); } @@ -215,7 +209,6 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params, * * \param params container parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the component instance, or _nil if problem */ //============================================================================= @@ -223,8 +216,7 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params, Engines::EngineComponent_ptr SALOME_LifeCycleCORBA:: FindOrLoad_Component(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { // --- Check if Component Name is known in ModuleCatalog @@ -247,16 +239,14 @@ FindOrLoad_Component(const Engines::ContainerParameters& params, } Engines::EngineComponent_var compo = _FindComponent(new_params, - componentName, - studyId, - listOfResources); + componentName, + listOfResources); if(CORBA::is_nil(compo)) { new_params.resource_params.resList = listOfResources; compo = _LoadComponent(new_params, - componentName, - studyId); + componentName); } return compo._retn(); @@ -475,10 +465,10 @@ void SALOME_LifeCycleCORBA::shutdownServers() // 2) SALOMEDS try { - CORBA::Object_var objSDS = _NS->Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ; - if ( !CORBA::is_nil(studyManager) && ( pid != studyManager->getPID() ) ) - studyManager->Shutdown(); + CORBA::Object_var objSDS = _NS->Resolve("/Study"); + SALOMEDS::Study_var study = SALOMEDS::Study::_narrow(objSDS) ; + if ( !CORBA::is_nil(study) && ( pid != study->getPID() ) ) + study->Shutdown(); } catch(const CORBA::Exception& e) { @@ -639,7 +629,6 @@ void SALOME_LifeCycleCORBA::killOmniNames() * * \param params machine parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \param listOfMachines list of machine address * \return a CORBA reference of the component instance, or _nil if not found */ @@ -649,7 +638,6 @@ Engines::EngineComponent_ptr SALOME_LifeCycleCORBA:: _FindComponent(const Engines::ContainerParameters& params, const char *componentName, - int studyId, const Engines::ResourceList& listOfResources) { // --- build the list of machines on which the component is already running @@ -700,7 +688,6 @@ _FindComponent(const Engines::ContainerParameters& params, * * \param params machine parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the component instance, or _nil if problem */ //============================================================================= @@ -708,8 +695,7 @@ _FindComponent(const Engines::ContainerParameters& params, Engines::EngineComponent_ptr SALOME_LifeCycleCORBA:: _LoadComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { MESSAGE("_LoadComponent, required " << params.container_name << " " << componentName << " " << NbProc(params)); @@ -730,7 +716,7 @@ _LoadComponent(const Engines::ContainerParameters& params, CORBA::string_free(reason); Engines::EngineComponent_var myInstance = - cont->create_component_instance(componentName, studyId); + cont->create_component_instance(componentName); return myInstance._retn(); } @@ -739,14 +725,12 @@ _LoadComponent(const Engines::ContainerParameters& params, * * \param params machine parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the parallel component instance, or _nil if problem */ //============================================================================= Engines::EngineComponent_ptr SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { MESSAGE("Entering LoadParallelComponent"); @@ -782,7 +766,7 @@ SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::ContainerParameters // @PARALLEL@ permits to identify that the component requested // is a parallel component. std::string name = std::string(componentName); - Engines::EngineComponent_var myInstance = cont->create_component_instance(name.c_str(), studyId); + Engines::EngineComponent_var myInstance = cont->create_component_instance(name.c_str()); if (CORBA::is_nil(myInstance)) INFOS("create_component_instance returns a NULL component !"); return myInstance._retn(); diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index 8713d5705..4da31b0d9 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -66,18 +66,15 @@ public: Engines::EngineComponent_ptr FindComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId=0); + const char *componentName); Engines::EngineComponent_ptr LoadComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId=0); + const char *componentName); Engines::EngineComponent_ptr FindOrLoad_Component(const Engines::ContainerParameters& params, - const char *componentName, - int studyId =0); + const char *componentName); Engines::EngineComponent_ptr FindOrLoad_Component(const char *containerName, @@ -86,8 +83,7 @@ public: // Parallel extension Engines::EngineComponent_ptr Load_ParallelComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId); + const char *componentName); bool isKnownComponentClass(const char *componentName); @@ -115,13 +111,11 @@ protected: Engines::EngineComponent_ptr _FindComponent(const Engines::ContainerParameters& params, const char *componentName, - int studyId, const Engines::ResourceList& listOfResources); Engines::EngineComponent_ptr _LoadComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId); + const char *componentName); SALOME_NamingService *_NS; SALOME_NamingService *_NSnew; diff --git a/src/MPIContainer/MPIContainer_i.cxx b/src/MPIContainer/MPIContainer_i.cxx index 2c9d5efc3..19f6f8fe0 100644 --- a/src/MPIContainer/MPIContainer_i.cxx +++ b/src/MPIContainer/MPIContainer_i.cxx @@ -215,7 +215,6 @@ bool Engines_MPIContainer_i::Lload_component_Library(const char* componentName) // Create an instance of component Engines::EngineComponent_ptr Engines_MPIContainer_i::create_component_instance_env( const char* componentName, - CORBA::Long studyId, const Engines::FieldsDict& env, CORBA::String_out reason) { @@ -229,12 +228,11 @@ Engines_MPIContainer_i::create_component_instance_env( const char* componentName st->ip = ip; st->tior = _tior; st->compoName = componentName; - st->studyId = studyId; pthread_create(&(th[ip]),NULL,th_createcomponentinstance,(void*)st); } } - Engines::EngineComponent_ptr cptr = Lcreate_component_instance(componentName,studyId); + Engines::EngineComponent_ptr cptr = Lcreate_component_instance(componentName); if(_numproc == 0){ for(int ip=1;ip<_nbproc;ip++) @@ -246,13 +244,8 @@ Engines_MPIContainer_i::create_component_instance_env( const char* componentName } Engines::EngineComponent_ptr -Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterName, CORBA::Long studyId) +Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterName ) { - if (studyId < 0) { - INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy"); - return Engines::EngineComponent::_nil() ; - } - Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil() ; Engines::MPIObject_var pobj; @@ -281,8 +274,7 @@ Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterN (char*)"create_component_instance", (char*)"ssl", aCompName.c_str(), - instanceName.c_str(), - studyId); + instanceName.c_str()); const char *ior; const char *error; PyArg_ParseTuple(result,"ss", &ior, &error); @@ -308,8 +300,7 @@ Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterN { void* handle = _library_map[impl_name]; iobject = createMPIInstance(genericRegisterName, - handle, - studyId); + handle); return iobject._retn(); } @@ -318,8 +309,7 @@ Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterN Engines::EngineComponent_ptr Engines_MPIContainer_i::createMPIInstance(std::string genericRegisterName, - void *handle, - int studyId) + void *handle) { Engines::EngineComponent_var iobject; Engines::MPIObject_var pobj; @@ -369,27 +359,14 @@ Engines_MPIContainer_i::createMPIInstance(std::string genericRegisterName, PortableServer::ObjectId *id ; //not owner, do not delete (nore use var) id = (MPIComponent_factory) ( _orb, _poa, _id, instanceName.c_str(), aGenRegisterName.c_str() ) ; - // --- get reference & servant from id + // --- get reference from id CORBA::Object_var obj = _poa->id_to_reference(*id); iobject = Engines::EngineComponent::_narrow( obj ) ; pobj = Engines::MPIObject::_narrow(obj) ; - Engines_Component_i *servant = - dynamic_cast(_poa->reference_to_servant(iobject)); - ASSERT(servant); - //SCRUTE(servant->pd_refCount); - servant->_remove_ref(); // compensate previous id_to_reference - //SCRUTE(servant->pd_refCount); _listInstances_map[instanceName] = iobject; _cntInstances_map[aGenRegisterName] += 1; - //SCRUTE(servant->pd_refCount); -#ifndef _DEBUG_ - servant->setStudyId(studyId); -#else - bool ret_studyId = servant->setStudyId(studyId); - ASSERT(ret_studyId); -#endif // --- register the engine under the name // containerName(.dir)/instanceName(.object) @@ -608,7 +585,7 @@ void *th_loadcomponentlibrary(void *s) void *th_createcomponentinstance(void *s) { thread_st *st = (thread_st*)s; - (Engines::MPIContainer::_narrow((*(st->tior))[st->ip]))->create_component_instance(st->compoName.c_str(),st->studyId); + (Engines::MPIContainer::_narrow((*(st->tior))[st->ip]))->create_component_instance(st->compoName.c_str()); return NULL; } diff --git a/src/MPIContainer/MPIContainer_i.hxx b/src/MPIContainer/MPIContainer_i.hxx index c53cdefd5..3a8ed1deb 100644 --- a/src/MPIContainer/MPIContainer_i.hxx +++ b/src/MPIContainer/MPIContainer_i.hxx @@ -41,7 +41,6 @@ typedef struct { Engines::IORTab* tior; std::string compoName; std::string nameToRegister; - long studyId; Engines::EngineComponent_ptr cptr; } thread_st; @@ -71,7 +70,6 @@ class Engines_MPIContainer_i : public POA_Engines::MPIContainer, // synchronous version for process 0 virtual Engines::EngineComponent_ptr create_component_instance_env( const char* componentName, - CORBA::Long studyId, // 0 for multiStudy const Engines::FieldsDict& env, CORBA::String_out reason); @@ -90,15 +88,13 @@ class Engines_MPIContainer_i : public POA_Engines::MPIContainer, private: bool Lload_component_Library(const char* componentName); Engines::EngineComponent_ptr - Lcreate_component_instance( const char* componentName, - CORBA::Long studyId); // 0 for multiStudy + Lcreate_component_instance(const char* componentName); Engines::EngineComponent_ptr Lload_impl(const char* nameToRegister, const char* componentName); Engines::EngineComponent_ptr createMPIInstance(std::string genericRegisterName, - void *handle, - int studyId); + void *handle); }; #endif diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx index fd75687f9..112132bab 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx @@ -22,7 +22,7 @@ // SALOME_ParallelComponent : implementation of container and engine for Parallel Kernel // File : SALOME_ParallelComponent_i.cxx -// Author : André RIBES, EDF +// Author : Andr� RIBES, EDF // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA // #include "SALOME_ParallelComponent_i.hxx" @@ -53,7 +53,7 @@ int SIGUSR11 = 1000; extern bool _Sleeping ; static Engines_Parallel_Component_i * theEngines_Component ; -bool Engines_Parallel_Component_i::_isMultiStudy = true; +bool Engines_Parallel_Component_i::_isMultiStudy = false; bool Engines_Parallel_Component_i::_isMultiInstance = false; //============================================================================= @@ -90,7 +90,6 @@ Engines_Parallel_Component_i::Engines_Parallel_Component_i(CORBA::ORB_ptr orb, c _Executed(false) , _graphName("") , _nodeName(""), - _studyId(-1), _destroyed(false), _CanceledThread(false) { @@ -160,20 +159,6 @@ char* Engines_Parallel_Component_i::interfaceName() return CORBA::string_dup(_interfaceName.c_str()) ; } -//============================================================================= -/*! - * CORBA method: Get study Id - * \return -1: not initialised (Internal Error) - * 0: multistudy component instance - * >0: study id associated to this instance - */ -//============================================================================= - -CORBA::Long Engines_Parallel_Component_i::getStudyId() -{ - return _studyId; -} - //============================================================================= /*! * CORBA method: Test if instance is alive and responds @@ -517,31 +502,6 @@ Engines_Parallel_Container_i *Engines_Parallel_Component_i::GetContainerPtr() return dynamic_cast(_poa->id_to_servant(*_contId)) ; } -//============================================================================= -/*! - * C++ method: set study Id - * \param studyId 0 if instance is not associated to a study, - * >0 otherwise (== study id) - * \return true if the set of study Id is OK - * must be set once by Container, at instance creation, - * and cannot be changed after. - */ -//============================================================================= - -CORBA::Boolean Engines_Parallel_Component_i::setStudyId(CORBA::Long studyId) -{ - ASSERT( studyId >= 0); - CORBA::Boolean ret = false; - if (_studyId < 0) // --- not yet initialized - { - _studyId = studyId; - ret = true; - } - else - if ( _studyId == studyId) ret = true; - return ret; -} - //============================================================================= /*! * C++ method: return CORBA instance id, the id is set in derived class diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx index a5d41f270..d7bcbf38d 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx @@ -22,7 +22,7 @@ // SALOME_ParallelComponent : implementation of container and engine for Parallel Kernel // File : SALOME_ParallelComponent_i.hxx -// Author : André RIBES, EDF +// Author : Andr� RIBES, EDF // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA // #ifndef _SALOME_PARALLEL_COMPONENT_I_HXX_ @@ -80,7 +80,6 @@ public: void ping(); void destroy(); - CORBA::Long getStudyId(); Engines::Container_ptr GetContainerRef(); void setProperties(const Engines::FieldsDict& dico); @@ -116,14 +115,13 @@ public: // Object information virtual bool hasObjectInfo() { return false; } - virtual char* getObjectInfo(CORBA::Long studyId, const char* entry) { return ""; } + virtual char* getObjectInfo(const char* entry) { return ""; } // --- local C++ methods PortableServer::ObjectId * getId(); Engines_Parallel_Container_i *GetContainerPtr(); - bool setStudyId(CORBA::Long studyId); static bool isMultiStudy(); static bool isMultiInstance(); static std::string GetDynLibraryName(const char *componentName); @@ -146,7 +144,6 @@ public: Engines::Parallel_Salome_file_proxy_impl * file); protected: - int _studyId; // -1: not initialised; 0: multiStudy; >0: study static bool _isMultiStudy; static bool _isMultiInstance; diff --git a/src/ParallelContainer/SALOME_ParallelContainerProxy_i.cxx b/src/ParallelContainer/SALOME_ParallelContainerProxy_i.cxx index 53a9ff747..19e5ab33d 100644 --- a/src/ParallelContainer/SALOME_ParallelContainerProxy_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainerProxy_i.cxx @@ -271,11 +271,11 @@ Container_proxy_impl_final::load_component_Library(const char* componentName, CO } Engines::EngineComponent_ptr -Container_proxy_impl_final::create_component_instance(const char* componentName, ::CORBA::Long studyId) +Container_proxy_impl_final::create_component_instance(const char* componentName) { Engines::FieldsDict_var env = new Engines::FieldsDict; char* reason; - Engines::EngineComponent_ptr compo = create_component_instance_env(componentName, studyId, env, reason); + Engines::EngineComponent_ptr compo = create_component_instance_env(componentName, env, reason); CORBA::string_free(reason); return compo; } @@ -285,7 +285,7 @@ Container_proxy_impl_final::create_component_instance(const char* componentName, // Composant parallèle -> création du proxy ici puis appel de la création de chaque objet participant // au composant parallèle Engines::EngineComponent_ptr -Container_proxy_impl_final::create_component_instance_env(const char* componentName, ::CORBA::Long studyId, +Container_proxy_impl_final::create_component_instance_env(const char* componentName, const Engines::FieldsDict& env, CORBA::String_out reason) { reason=CORBA::string_dup(""); @@ -305,7 +305,7 @@ Container_proxy_impl_final::create_component_instance_env(const char* componentN _numInstance++; _numInstanceMutex.unlock(); Engines::PACO_Container_proxy_impl::updateInstanceNumber(); - return Engines::Container_proxy_impl::create_component_instance(componentName, studyId); + return Engines::Container_proxy_impl::create_component_instance(componentName); } // Parallel Component ! @@ -353,7 +353,7 @@ Container_proxy_impl_final::create_component_instance_env(const char* componentN instanceName.c_str(), _parallel_object_topology.total); - // --- get reference & servant from id + // --- get reference from id CORBA::Object_var obj = _poa->id_to_reference(*(proxy->proxy_id)); component_proxy = Engines::EngineComponent::_narrow(obj); proxy->proxy_corba_ref = component_proxy; @@ -392,7 +392,7 @@ Container_proxy_impl_final::create_component_instance_env(const char* componentN { try { - node->create_paco_component_node_instance(componentName, _containerName.c_str(), studyId); + node->create_paco_component_node_instance(componentName, _containerName.c_str()); MESSAGE("Call create_paco_component_node_instance done on node : " << i); } catch (SALOME::SALOME_Exception & ex) diff --git a/src/ParallelContainer/SALOME_ParallelContainerProxy_i.hxx b/src/ParallelContainer/SALOME_ParallelContainerProxy_i.hxx index 3949f0f82..d825dec45 100644 --- a/src/ParallelContainer/SALOME_ParallelContainerProxy_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelContainerProxy_i.hxx @@ -54,10 +54,8 @@ class Container_proxy_impl_final : virtual void Shutdown(); virtual ::CORBA::Boolean load_component_Library(const char* componentName,CORBA::String_out reason); - virtual Engines::EngineComponent_ptr create_component_instance (const char* componentName, - ::CORBA::Long studyId); + virtual Engines::EngineComponent_ptr create_component_instance (const char* componentName); virtual Engines::EngineComponent_ptr create_component_instance_env (const char* componentName, - CORBA::Long studyId, // 0 for multiStudy const Engines::FieldsDict& env, CORBA::String_out reason); diff --git a/src/ParallelContainer/SALOME_ParallelContainer_i.cxx b/src/ParallelContainer/SALOME_ParallelContainer_i.cxx index 6e75e1a2c..e4852f4f4 100644 --- a/src/ParallelContainer/SALOME_ParallelContainer_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainer_i.cxx @@ -376,18 +376,15 @@ Engines_Parallel_Container_i::load_component_Library(const char* componentName, * The servant registers itself to naming service and Registry. * \param genericRegisterName Name of the component instance to register * in Registry & Name Service (without _inst_n suffix) - * \param studyId 0 for multiStudy instance, - * study Id (>0) otherwise * \return a loaded component */ //============================================================================= Engines::EngineComponent_ptr -Engines_Parallel_Container_i::create_component_instance(const char*genericRegisterName, - CORBA::Long studyId) +Engines_Parallel_Container_i::create_component_instance(const char*genericRegisterName) { Engines::FieldsDict_var env = new Engines::FieldsDict; char* reason; - Engines::EngineComponent_ptr compo = create_component_instance_env(genericRegisterName,studyId,env, reason); + Engines::EngineComponent_ptr compo = create_component_instance_env(genericRegisterName,env, reason); CORBA::string_free(reason); return compo; } @@ -399,8 +396,6 @@ Engines_Parallel_Container_i::create_component_instance(const char*genericRegist * The servant registers itself to naming service and Registry. * \param genericRegisterName Name of the component instance to register * in Registry & Name Service (without _inst_n suffix) - * \param studyId 0 for multiStudy instance, - * study Id (>0) otherwise * \param env dict of environment variables * \return a loaded component */ @@ -408,19 +403,12 @@ Engines_Parallel_Container_i::create_component_instance(const char*genericRegist Engines::EngineComponent_ptr Engines_Parallel_Container_i::create_component_instance_env(const char*genericRegisterName, - CORBA::Long studyId, const Engines::FieldsDict& env, CORBA::String_out reason) { MESSAGE("Begin of create_component_instance in node : " << getMyRank()); reason=CORBA::string_dup(""); - if (studyId < 0) - { - INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy"); - return Engines::EngineComponent::_nil() ; - } - std::string aCompName = genericRegisterName; #ifndef WIN32 std::string impl_name = string ("lib") + aCompName +string("Engine.so"); @@ -448,9 +436,9 @@ Engines_Parallel_Container_i::create_component_instance_env(const char*genericRe Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil(); if (type_of_lib == "cpp") - iobject = createCPPInstance(aCompName, handle, studyId); + iobject = createCPPInstance(aCompName, handle); else - iobject = createPythonInstance(aCompName, studyId); + iobject = createPythonInstance(aCompName); _numInstanceMutex.unlock(); return iobject._retn(); @@ -462,14 +450,11 @@ Engines_Parallel_Container_i::create_component_instance_env(const char*genericRe * CORBA method: Finds a servant instance of a component * \param registeredName Name of the component in Registry or Name Service, * without instance suffix number - * \param studyId 0 if instance is not associated to a study, - * >0 otherwise (== study id) - * \return the first instance found with same studyId + * \return the first found instance */ //============================================================================= -Engines::EngineComponent_ptr Engines_Parallel_Container_i::find_component_instance( const char* registeredName, - CORBA::Long studyId) +Engines::EngineComponent_ptr Engines_Parallel_Container_i::find_component_instance(const char* registeredName) { Engines::EngineComponent_var anEngine = Engines::EngineComponent::_nil(); std::map::iterator itm =_listInstances_map.begin(); @@ -480,10 +465,7 @@ Engines::EngineComponent_ptr Engines_Parallel_Container_i::find_component_instan if (instance.find(registeredName) == 0) { anEngine = (*itm).second; - if (studyId == anEngine->getStudyId()) - { - return anEngine._retn(); - } + return anEngine._retn(); } itm++; } @@ -729,22 +711,11 @@ Engines_Parallel_Container_i::find_or_create_instance(std::string genericRegiste CORBA::Object_var obj = _NS->ResolveFirst(component_registerBase.c_str()); if (CORBA::is_nil( obj )) { - iobject = create_component_instance(genericRegisterName.c_str(), - 0); // force multiStudy instance here ! + iobject = create_component_instance(genericRegisterName.c_str()); } else { iobject = Engines::EngineComponent::_narrow(obj) ; - Engines_Component_i *servant = dynamic_cast(_poa->reference_to_servant(iobject)); - ASSERT(servant) - int studyId = servant->getStudyId(); - ASSERT (studyId >= 0); - if (studyId != 0) // monoStudy instance: NOK - { - iobject = Engines::EngineComponent::_nil(); - INFOS("load_impl & find_component_instance methods " - << "NOT SUITABLE for mono study components"); - } } } catch (...) @@ -762,8 +733,6 @@ Engines_Parallel_Container_i::find_or_create_instance(std::string genericRegiste * in Registry & Name Service, * (without _inst_n suffix, like "COMPONENT") * \param handle loaded library handle - * \param studyId 0 for multiStudy instance, - * study Id (>0) otherwise * \return a loaded component * * example with names: @@ -776,7 +745,7 @@ Engines_Parallel_Container_i::find_or_create_instance(std::string genericRegiste */ //============================================================================= Engines::EngineComponent_ptr -Engines_Parallel_Container_i::createPythonInstance(std::string genericRegisterName, int studyId) +Engines_Parallel_Container_i::createPythonInstance(std::string genericRegisterName) { Engines::EngineComponent_var iobject = Engines::EngineComponent::_nil(); @@ -795,8 +764,7 @@ Engines_Parallel_Container_i::createPythonInstance(std::string genericRegisterNa (char*)"create_component_instance", (char*)"ssl", genericRegisterName.c_str(), - instanceName.c_str(), - studyId); + instanceName.c_str()); const char *ior; const char *error; PyArg_ParseTuple(result,"ss", &ior, &error); @@ -824,8 +792,6 @@ Engines_Parallel_Container_i::createPythonInstance(std::string genericRegisterNa * in Registry & Name Service, * (without _inst_n suffix, like "COMPONENT") * \param handle loaded library handle - * \param studyId 0 for multiStudy instance, - * study Id (>0) otherwise * \return a loaded component * * example with names: @@ -839,8 +805,7 @@ Engines_Parallel_Container_i::createPythonInstance(std::string genericRegisterNa //============================================================================= Engines::EngineComponent_ptr Engines_Parallel_Container_i::createCPPInstance(std::string genericRegisterName, - void *handle, - int studyId) + void *handle) { MESSAGE("Entering Engines_Parallel_Container_i::createCPPInstance"); @@ -894,22 +859,12 @@ Engines_Parallel_Container_i::createCPPInstance(std::string genericRegisterName, return iobject._retn(); } - // --- get reference & servant from id + // --- get reference from id CORBA::Object_var obj = _poa->id_to_reference(*id); iobject = Engines::EngineComponent::_narrow(obj); - Engines_Component_i *servant = - dynamic_cast(_poa->reference_to_servant(iobject)); - ASSERT(servant); - servant->_remove_ref(); // compensate previous id_to_reference _listInstances_map[instanceName] = iobject; _cntInstances_map[aGenRegisterName] += 1; -#if defined(_DEBUG_) || defined(_DEBUG) - bool ret_studyId = servant->setStudyId(studyId); - ASSERT(ret_studyId); -#else - servant->setStudyId(studyId); -#endif // --- register the engine under the name // containerName(.dir)/instanceName(.object) @@ -925,8 +880,7 @@ Engines_Parallel_Container_i::createCPPInstance(std::string genericRegisterName, void Engines_Parallel_Container_i::create_paco_component_node_instance(const char* componentName, - const char* proxy_containerName, - CORBA::Long studyId) + const char* proxy_containerName) { // Init de la méthode char * proxy_ior; @@ -991,7 +945,7 @@ Engines_Parallel_Container_i::create_paco_component_node_instance(const char* co id = (Component_factory) (_orb, proxy_ior, getMyRank(), _poa, _id, instanceName.c_str(), componentName); CORBA::string_free(proxy_ior); - // --- get reference & servant from id + // --- get reference from id CORBA::Object_var obj = _poa->id_to_reference(*id); work_node = Engines::EngineComponent_PaCO::_narrow(obj) ; if (CORBA::is_nil(work_node)) diff --git a/src/ParallelContainer/SALOME_ParallelContainer_i.hxx b/src/ParallelContainer/SALOME_ParallelContainer_i.hxx index b99f8f782..52d232dce 100644 --- a/src/ParallelContainer/SALOME_ParallelContainer_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelContainer_i.hxx @@ -20,7 +20,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : SALOME_ParallelContainer_i.hxx -// Author : André RIBES, EDF +// Author : Andr� RIBES, EDF #ifndef _SALOME_PARALLEL_CONTAINER_I_HXX_ #define _SALOME_PARALLEL_CONTAINER_I_HXX_ @@ -73,12 +73,10 @@ public: virtual bool load_component_Library(const char* componentName, CORBA::String_out reason); virtual Engines::EngineComponent_ptr - create_component_instance( const char* componentName, - CORBA::Long studyId); // 0 for multiStudy + create_component_instance( const char* componentName); virtual Engines::EngineComponent_ptr create_component_instance_env( const char* componentName, - CORBA::Long studyId, // 0 for multiStudy const Engines::FieldsDict& env, CORBA::String_out reason); @@ -87,8 +85,7 @@ public: CORBA::String_out reason); Engines::EngineComponent_ptr - find_component_instance( const char* registeredName, - CORBA::Long studyId); // 0 for multiStudy + find_component_instance( const char* registeredName); Engines::EngineComponent_ptr load_impl(const char* nameToRegister, @@ -96,8 +93,7 @@ public: void create_paco_component_node_instance(const char* componentName, - const char* proxy_containerName, - CORBA::Long studyId); // 0 for multiStudy + const char* proxy_containerName); void updateInstanceNumber(); @@ -123,12 +119,10 @@ public: Engines::EngineComponent_ptr createCPPInstance(std::string genericRegisterName, - void *handle, - int studyId); + void *handle); Engines::EngineComponent_ptr - createPythonInstance(std::string genericRegisterName, - int studyId); + createPythonInstance(std::string genericRegisterName); static bool isPythonContainer(const char* ContainerName); static void decInstanceCnt(std::string genericRegisterName); @@ -167,8 +161,8 @@ protected: _fileRef_map_t _fileRef_map; _Salome_file_map_t _Salome_file_map; - // Cette map contient les references vers les différentes - // instances d'objets parallèles. + // Cette map contient les references vers les diff�rentes + // instances d'objets parall�les. std::map _par_obj_inst_map; typedef PortableServer::ObjectId * (*FACTORY_FUNCTION) (CORBA::ORB_ptr, char *, int, diff --git a/src/SALOMEDS/CMakeLists.txt b/src/SALOMEDS/CMakeLists.txt index 894e6f744..68c5a4b8b 100755 --- a/src/SALOMEDS/CMakeLists.txt +++ b/src/SALOMEDS/CMakeLists.txt @@ -63,7 +63,6 @@ SET(COMMON_LIBS SET(SalomeDS_SOURCES SALOMEDS.cxx SALOMEDS_Driver_i.cxx - SALOMEDS_StudyManager_i.cxx SALOMEDS_UseCaseBuilder_i.cxx SALOMEDS_UseCaseIterator_i.cxx SALOMEDS_ChildIterator_i.cxx @@ -112,7 +111,6 @@ SET(SalomeDS_SOURCES SALOMEDS_UseCaseBuilder.cxx SALOMEDS_StudyBuilder.cxx SALOMEDS_Study.cxx - SALOMEDS_StudyManager.cxx SALOMEDS_AttributeStudyProperties.cxx SALOMEDS_AttributeComment.cxx SALOMEDS_AttributeDrawable.cxx @@ -166,9 +164,7 @@ INSTALL(TARGETS SALOMEDS_Server SALOMEDS_Client SALOME_INSTALL_SCRIPTS(SALOME_DriverPy.py ${SALOME_INSTALL_SCRIPT_PYTHON}) SET(COMMON_HEADERS_HXX - SALOMEDS_StudyManager_i.hxx SALOMEDS_Driver_i.hxx - SALOMEDS_StudyManager.hxx SALOMEDS_Study_i.hxx SALOMEDS_Study.hxx SALOMEDS_SObject_i.hxx diff --git a/src/SALOMEDS/SALOMEDS.cxx b/src/SALOMEDS/SALOMEDS.cxx index 81a3ce56e..42ba79c59 100644 --- a/src/SALOMEDS/SALOMEDS.cxx +++ b/src/SALOMEDS/SALOMEDS.cxx @@ -27,7 +27,6 @@ // $Header$ // #include "SALOMEDS.hxx" -#include "SALOMEDS_StudyManager.hxx" #include "SALOMEDS_Study.hxx" #include "SALOMEDS_StudyBuilder.hxx" #include "SALOMEDS_SObject.hxx" @@ -35,7 +34,6 @@ #include "SALOMEDSClient.hxx" #include "SALOMEDSClient_IParameters.hxx" #include "SALOMEDS_IParameters.hxx" -#include "SALOMEDS_StudyManager_i.hxx" #include "SALOMEDS_Defines.hxx" @@ -62,12 +60,10 @@ void SALOMEDS::lock() void SALOMEDS::unlock() { - SALOMEDS::Locker::MutexDS.unlock(); + SALOMEDS::Locker::MutexDS.unlock(); } - - -// srn: Added new library methods that create basic SALOMEDS objects (StudyManager, Study, SComponent, SObject) +// srn: Added new library methods that create basic SALOMEDS objects (Study, SComponent, SObject) //============================================================================= /*! @@ -78,86 +74,64 @@ void SALOMEDS::unlock() extern "C" { -SALOMEDS_EXPORT - SALOMEDSClient_StudyManager* StudyManagerFactory() -{ - return new SALOMEDS_StudyManager(); -} -SALOMEDS_EXPORT + SALOMEDS_EXPORT SALOMEDSClient_Study* StudyFactory(SALOMEDS::Study_ptr theStudy) -{ - if(CORBA::is_nil(theStudy)) return NULL; - return new SALOMEDS_Study(theStudy); -} + { + if(CORBA::is_nil(theStudy)) return NULL; + return new SALOMEDS_Study(theStudy); + } -SALOMEDS_EXPORT + SALOMEDS_EXPORT SALOMEDSClient_SObject* SObjectFactory(SALOMEDS::SObject_ptr theSObject) -{ - if(CORBA::is_nil(theSObject)) return NULL; - return new SALOMEDS_SObject(theSObject); -} + { + if(CORBA::is_nil(theSObject)) return NULL; + return new SALOMEDS_SObject(theSObject); + } -SALOMEDS_EXPORT + SALOMEDS_EXPORT SALOMEDSClient_SComponent* SComponentFactory(SALOMEDS::SComponent_ptr theSComponent) -{ - if(CORBA::is_nil(theSComponent)) return NULL; - return new SALOMEDS_SComponent(theSComponent); -} + { + if(CORBA::is_nil(theSComponent)) return NULL; + return new SALOMEDS_SComponent(theSComponent); + } -SALOMEDS_EXPORT + SALOMEDS_EXPORT SALOMEDSClient_StudyBuilder* BuilderFactory(SALOMEDS::StudyBuilder_ptr theBuilder) -{ - if(CORBA::is_nil(theBuilder)) return NULL; - return new SALOMEDS_StudyBuilder(theBuilder); -} - -SALOMEDS_EXPORT - SALOMEDSClient_StudyManager* CreateStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa) -{ - SALOME_NamingService namingService(orb); - CORBA::Object_var obj = namingService.Resolve( "/myStudyManager" ); - SALOMEDS::StudyManager_var theManager = SALOMEDS::StudyManager::_narrow( obj ); - if( CORBA::is_nil(theManager) ) { - SALOMEDS_StudyManager_i * aStudyManager_i = new SALOMEDS_StudyManager_i(orb, root_poa); - // Activate the objects. This tells the POA that the objects are ready to accept requests. - PortableServer::ObjectId_var aStudyManager_iid = root_poa->activate_object(aStudyManager_i); - //give ownership to the poa : the object will be deleted by the poa - aStudyManager_i->_remove_ref(); - aStudyManager_i->register_name((char*)"/myStudyManager"); + { + if(CORBA::is_nil(theBuilder)) return NULL; + return new SALOMEDS_StudyBuilder(theBuilder); } - return new SALOMEDS_StudyManager(); -} -SALOMEDS_EXPORT + SALOMEDS_EXPORT SALOMEDSClient_IParameters* GetIParameters(const _PTR(AttributeParameter)& ap) -{ - return new SALOMEDS_IParameters(ap); -} + { + return new SALOMEDS_IParameters(ap); + } -SALOMEDS_EXPORT + SALOMEDS_EXPORT SALOMEDS::SObject_ptr ConvertSObject(const _PTR(SObject)& theSObject) -{ - - SALOMEDS_SObject* so = _CAST(SObject, theSObject); - if(!theSObject || !so) return SALOMEDS::SObject::_nil(); - return so->GetSObject(); -} + { + SALOMEDS_SObject* so = _CAST(SObject, theSObject); + if ( !theSObject || !so ) + return SALOMEDS::SObject::_nil(); + return so->GetSObject(); + } -SALOMEDS_EXPORT + SALOMEDS_EXPORT SALOMEDS::Study_ptr ConvertStudy(const _PTR(Study)& theStudy) -{ - SALOMEDS_Study* study = _CAST(Study, theStudy); - if(!theStudy || !study) return SALOMEDS::Study::_nil(); - return study->GetStudy(); -} + { + SALOMEDS_Study* study = _CAST(Study, theStudy); + if ( !theStudy || !study ) + return SALOMEDS::Study::_nil(); + return study->GetStudy(); + } -SALOMEDS_EXPORT + SALOMEDS_EXPORT SALOMEDS::StudyBuilder_ptr ConvertBuilder(const _PTR(StudyBuilder)& theBuilder) -{ - SALOMEDS_StudyBuilder* builder = _CAST(StudyBuilder, theBuilder); - if(!theBuilder || !builder) return SALOMEDS::StudyBuilder::_nil(); - return builder->GetBuilder(); -} - - + { + SALOMEDS_StudyBuilder* builder = _CAST(StudyBuilder, theBuilder); + if ( !theBuilder || !builder ) + return SALOMEDS::StudyBuilder::_nil(); + return builder->GetBuilder(); + } } diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.cxx b/src/SALOMEDS/SALOMEDS_Driver_i.cxx index 8c704beef..488b07f74 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.cxx @@ -28,6 +28,7 @@ #include "SALOMEDS_Study_i.hxx" #include "SALOMEDS.hxx" #include +#include #include #include CORBA_CLIENT_HEADER(SALOME_Session) @@ -316,14 +317,14 @@ std::string SALOMEDS_Driver_i::PasteInto(const unsigned char* theStream, return entry; } -SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy, - bool isPublished, +SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(bool isPublished, bool isMultiFile, bool& isValidScript, long& theStreamLength) { - SALOMEDS_Study_i * st_servant = SALOMEDS_Study_i::GetStudyServant(theStudy, _orb);//new SALOMEDS_Study_i (theStudy, _orb); - SALOMEDS::Study_var st = SALOMEDS::Study::_narrow(st_servant->_this()); + SALOME_NamingService* namingService = KERNEL::getNamingService(); + CORBA::Object_var obj = namingService->Resolve("/Study"); + SALOMEDS::Study_var st = SALOMEDS::Study::_narrow(obj); SALOMEDS::unlock(); diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.hxx b/src/SALOMEDS/SALOMEDS_Driver_i.hxx index c07c30eb4..1b1809b30 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.hxx @@ -98,8 +98,7 @@ public: int theObjectID, const SALOMEDSImpl_SObject& theObject); - virtual SALOMEDSImpl_TMPFile* DumpPython(SALOMEDSImpl_Study* theStudy, - bool isPublished, + virtual SALOMEDSImpl_TMPFile* DumpPython(bool isPublished, bool isMultiFile, bool& isValidScript, long& theStreamLength); diff --git a/src/SALOMEDS/SALOMEDS_SObject_i.cxx b/src/SALOMEDS/SALOMEDS_SObject_i.cxx index 210e0fa68..0378e3003 100644 --- a/src/SALOMEDS/SALOMEDS_SObject_i.cxx +++ b/src/SALOMEDS/SALOMEDS_SObject_i.cxx @@ -28,7 +28,6 @@ #include "SALOMEDS_SObject_i.hxx" #include "SALOMEDS_SComponent_i.hxx" #include "SALOMEDS_GenericAttribute_i.hxx" -#include "SALOMEDS_StudyManager_i.hxx" #include "SALOMEDS.hxx" #include "SALOMEDSImpl_GenericAttribute.hxx" #include "SALOMEDSImpl_SComponent.hxx" @@ -71,7 +70,6 @@ SALOMEDS_SObject_i::SALOMEDS_SObject_i(const SALOMEDSImpl_SObject& impl, CORBA:: } } _orb = CORBA::ORB::_duplicate(orb); - //SALOME::GenericObj_i::myPOA = SALOMEDS_StudyManager_i::GetPOA(GetStudy()); } diff --git a/src/SALOMEDS/SALOMEDS_Server.cxx b/src/SALOMEDS/SALOMEDS_Server.cxx index 17a6583b0..2903a8217 100644 --- a/src/SALOMEDS/SALOMEDS_Server.cxx +++ b/src/SALOMEDS/SALOMEDS_Server.cxx @@ -30,7 +30,7 @@ #include "Utils_SINGLETON.hxx" #include "SALOME_NamingService.hxx" -#include "SALOMEDS_StudyManager_i.hxx" +#include "SALOMEDS_Study_i.hxx" #include #include CORBA_SERVER_HEADER(SALOMEDS) @@ -58,7 +58,8 @@ int main(int argc, char** argv) CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ; #else CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" ); -#endif +#endif + SALOME_NamingService NS; // Obtain a reference to the root POA. long TIMESleep = 500000000; int NumberOfTries = 40; @@ -108,7 +109,7 @@ int main(int argc, char** argv) if(EnvL==1) { CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ; - SALOME_NamingService &NS = *SINGLETON_::Instance() ; + NS = *SINGLETON_::Instance() ; NS.init_orb( orb1 ) ; for(int j=1; j<=NumberOfTries; j++) { @@ -154,13 +155,18 @@ int main(int argc, char** argv) // We allocate the objects on the heap. Since these are reference // counted objects, they will be deleted by the POA when they are no // longer needed. - SALOMEDS_StudyManager_i * myStudyManager_i = new SALOMEDS_StudyManager_i(orb,poa); + SALOMEDS_Study_i * myStudy_i = new SALOMEDS_Study_i(orb); // Activate the objects. This tells the POA that the objects are // ready to accept requests. - PortableServer::ObjectId_var myStudyManager_iid = poa->activate_object(myStudyManager_i); - myStudyManager_i->register_name("/myStudyManager"); - myStudyManager_i->_remove_ref(); + PortableServer::ObjectId_var myStudy_iid = poa->activate_object(myStudy_i); + SALOMEDS::Study_var Study = myStudy_i->_this(); + NS.Register(Study.in(), "/Study"); + myStudy_i->_remove_ref(); + + // Assign the value of the IOR in the study->root + CORBA::String_var IORStudy = orb->object_to_string(Study); + myStudy_i->GetImpl()->SetTransientReference((char*)IORStudy.in()); // Obtain a POAManager, and tell the POA to start accepting // requests on its objects. diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 63d44b5ac..40894df09 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -48,6 +48,8 @@ #include "SALOMEDSImpl_GenericVariable.hxx" #include "SALOMEDSImpl_UseCaseBuilder.hxx" +#include + #include "SALOMEDS_Driver_i.hxx" #include "SALOMEDS_Study_i.hxx" @@ -68,7 +70,7 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDSImpl_Study* theStudy) _isLocal = true; _local_impl = theStudy; _corba_impl = SALOMEDS::Study::_nil(); - init_orb(); + Init(); } SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy) @@ -89,13 +91,164 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy) _corba_impl = SALOMEDS::Study::_duplicate(theStudy); } - init_orb(); + Init(); } SALOMEDS_Study::~SALOMEDS_Study() { } +void SALOMEDS_Study::Init() +{ + ORB_INIT &init = *SINGLETON_::Instance() ; + ASSERT(SINGLETON_::IsAlreadyExisting()); + _orb = init(0 , 0 ) ; +} + +void SALOMEDS_Study::Clear() +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->Clear(); + } + else + _corba_impl->Clear(); +} + +bool SALOMEDS_Study::Open(const std::string& theStudyUrl) +{ + if(CORBA::is_nil(_corba_impl)) + return false; + + if (!_corba_impl->Open(theStudyUrl.c_str())) + return false; + + return true; +} + +bool SALOMEDS_Study::Save(bool theMultiFile) +{ + //SRN: Pure CORBA save as the save operation require CORBA in any case + return _corba_impl->Save(theMultiFile); +} + +bool SALOMEDS_Study::SaveASCII(bool theMultiFile) +{ + //SRN: Pure CORBA save as the save operation require CORBA in any case + return _corba_impl->SaveASCII(theMultiFile); +} + +bool SALOMEDS_Study::SaveAs(const std::string& theUrl, bool theMultiFile) +{ + //SRN: Pure CORBA save as the save operation require CORBA in any case + return _corba_impl->SaveAs((char*)theUrl.c_str(), theMultiFile); +} + +bool SALOMEDS_Study::SaveAsASCII(const std::string& theUrl, bool theMultiFile) +{ + //SRN: Pure CORBA save as the save operation require CORBA in any case + return _corba_impl->SaveAsASCII((char*)theUrl.c_str(), theMultiFile); +} + +SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb) +{ + SALOMEDS_Driver_i* driver = NULL; + + SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent(); + if(!aSCO.IsNull()) { + std::string IOREngine = aSCO.GetIOR(); + if(!IOREngine.empty()) { + CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str()); + Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ; + driver = new SALOMEDS_Driver_i(Engine, orb); + } + } + + return driver; +} + +bool SALOMEDS_Study::CanCopy(const _PTR(SObject)& theSO) +{ + SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); + bool ret; + + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl()); + SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb); + ret = _local_impl->CanCopy(aSO_impl, aDriver); + delete aDriver; + } + else { + ret = _corba_impl->CanCopy(aSO->GetCORBAImpl()); + } + + return ret; +} + +bool SALOMEDS_Study::Copy(const _PTR(SObject)& theSO) +{ + SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); + bool ret; + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl()); + SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb); + ret = _local_impl->Copy(aSO_impl, aDriver); + delete aDriver; + } + else { + ret = _corba_impl->Copy(aSO->GetCORBAImpl()); + } + return ret; +} + +bool SALOMEDS_Study::CanPaste(const _PTR(SObject)& theSO) +{ + SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); + bool ret; + + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl()); + SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb); + ret = _local_impl->CanPaste(aSO_impl, aDriver); + delete aDriver; + } + else { + ret = _corba_impl->CanPaste(aSO->GetCORBAImpl()); + } + + return ret; +} + +_PTR(SObject) SALOMEDS_Study::Paste(const _PTR(SObject)& theSO) +{ + SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); + SALOMEDSClient_SObject* aResult = NULL; + + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl()); + SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb); + SALOMEDSImpl_SObject aNewSO = _local_impl->Paste(aSO_impl, aDriver); + delete aDriver; + if(aNewSO.IsNull()) return _PTR(SObject)(aResult); + aResult = new SALOMEDS_SObject(aNewSO); + } + else { + SALOMEDS::SObject_ptr aNewSO = _corba_impl->Paste(aSO->GetCORBAImpl()); + if(CORBA::is_nil(aNewSO)) return _PTR(SObject)(aResult); + aResult = new SALOMEDS_SObject(aNewSO); + } + + return _PTR(SObject)(aResult); +} + std::string SALOMEDS_Study::GetPersistentReference() { std::string aRef; @@ -446,15 +599,6 @@ std::string SALOMEDS_Study::Name() return aName; } -void SALOMEDS_Study::Name(const std::string& theName) -{ - if (_isLocal) { - SALOMEDS::Locker lock; - _local_impl->Name(theName); - } - else _corba_impl->Name((char*)theName.c_str()); -} - bool SALOMEDS_Study::IsSaved() { bool isSaved; @@ -516,26 +660,6 @@ void SALOMEDS_Study::URL(const std::string& url) else _corba_impl->URL((char*)url.c_str()); } -int SALOMEDS_Study::StudyId() -{ - int anID; - if (_isLocal) { - SALOMEDS::Locker lock; - anID = _local_impl->StudyId(); - } - else anID = _corba_impl->StudyId(); - return anID; -} - -void SALOMEDS_Study::StudyId(int id) -{ - if (_isLocal) { - SALOMEDS::Locker lock; - _local_impl->StudyId(id); - } - else _corba_impl->StudyId(id); -} - std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO) { std::vector<_PTR(SObject)> aVector; @@ -614,15 +738,6 @@ _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder() return _PTR(UseCaseBuilder)(aUB); } -void SALOMEDS_Study::Close() -{ - if (_isLocal) { - SALOMEDS::Locker lock; - _local_impl->Close(); - } - else _corba_impl->Close(); -} - void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled) { if(_isLocal) _local_impl->EnableUseCaseAutoFilling(isEnabled); @@ -938,13 +1053,6 @@ CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR) return _orb->string_to_object(theIOR.c_str()); } -void SALOMEDS_Study::init_orb() -{ - ORB_INIT &init = *SINGLETON_::Instance() ; - ASSERT(SINGLETON_::IsAlreadyExisting()); - _orb = init(0 , 0 ) ; -} - SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy() { if (_isLocal) { @@ -957,8 +1065,9 @@ SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy() aStudy = SALOMEDS::Study::_narrow(_orb->string_to_object(anIOR.c_str())); } else { - SALOMEDS_Study_i *aStudy_servant = new SALOMEDS_Study_i(_local_impl, _orb); - aStudy = aStudy_servant->_this(); + SALOME_NamingService* namingService = KERNEL::getNamingService(); + CORBA::Object_var obj = namingService->Resolve("/Study"); + aStudy = SALOMEDS::Study::_narrow(obj); _local_impl->SetTransientReference(_orb->object_to_string(aStudy)); } _corba_impl = SALOMEDS::Study::_duplicate(aStudy); diff --git a/src/SALOMEDS/SALOMEDS_Study.hxx b/src/SALOMEDS/SALOMEDS_Study.hxx index af663d633..585487928 100644 --- a/src/SALOMEDS/SALOMEDS_Study.hxx +++ b/src/SALOMEDS/SALOMEDS_Study.hxx @@ -52,6 +52,20 @@ public: SALOMEDS_Study(SALOMEDS::Study_ptr theStudy); ~SALOMEDS_Study(); + virtual void Clear(); + + virtual bool Open(const std::string& theStudyUrl); + + virtual bool Save(bool theMultiFile); + virtual bool SaveASCII(bool theMultiFile); + virtual bool SaveAs(const std::string& theUrl, bool theMultiFile); + virtual bool SaveAsASCII(const std::string& theUrl, bool theMultiFile); + + virtual bool CanCopy(const _PTR(SObject)& theSO); + virtual bool Copy(const _PTR(SObject)& theSO); + virtual bool CanPaste(const _PTR(SObject)& theSO); + virtual _PTR(SObject) Paste(const _PTR(SObject)& theSO); + virtual std::string GetPersistentReference(); virtual std::string GetTransientReference(); virtual bool IsEmpty(); @@ -74,21 +88,17 @@ public: virtual _PTR(SComponentIterator) NewComponentIterator(); virtual _PTR(StudyBuilder) NewBuilder(); virtual std::string Name(); - virtual void Name(const std::string& name); virtual bool IsSaved(); virtual void IsSaved(bool save); virtual bool IsModified(); virtual void Modified(); virtual std::string URL(); virtual void URL(const std::string& url); - virtual int StudyId(); - virtual void StudyId(int id); virtual std::vector<_PTR(SObject)> FindDependances(const _PTR(SObject)& theSO); virtual _PTR(AttributeStudyProperties) GetProperties(); virtual std::string GetLastModificationDate(); virtual std::vector GetModificationsDate(); virtual _PTR(UseCaseBuilder) GetUseCaseBuilder(); - virtual void Close(); virtual void EnableUseCaseAutoFilling(bool isEnabled); virtual bool DumpStudy(const std::string& thePath,const std::string& theBaseName,bool isPublished,bool isMultiFile); virtual _PTR(AttributeParameter) GetCommonParameters(const std::string& theID, int theSavePoint); @@ -131,9 +141,9 @@ public: SALOMEDS::Study_ptr GetStudy(); SALOMEDSImpl_Study* GetLocalImpl() { return _local_impl; } - + private: - void init_orb(); + void Init(); }; #endif diff --git a/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx b/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx index 11de3ed7f..c43220b29 100644 --- a/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx @@ -32,7 +32,6 @@ #include "SALOMEDS_SObject.hxx" #include "SALOMEDS_SComponent.hxx" #include "SALOMEDS_GenericAttribute.hxx" -#include "SALOMEDS_StudyManager.hxx" #include "SALOMEDS_StudyBuilder_i.hxx" #include "SALOMEDS_Driver_i.hxx" diff --git a/src/SALOMEDS/SALOMEDS_StudyManager.cxx b/src/SALOMEDS/SALOMEDS_StudyManager.cxx deleted file mode 100644 index ba0a8f206..000000000 --- a/src/SALOMEDS/SALOMEDS_StudyManager.cxx +++ /dev/null @@ -1,326 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : SALOMEDSClient_StudyManager.cxx -// Author : Sergey RUIN -// Module : SALOME -// -#include "SALOMEDS_StudyManager.hxx" - -#include "SALOMEDS.hxx" -#include "SALOMEDS_Study.hxx" -#include "SALOMEDS_SObject.hxx" -#include "SALOMEDS_Driver_i.hxx" - -#include "SALOMEDSImpl_Study.hxx" - -#include "Utils_ORB_INIT.hxx" -#include "Utils_SINGLETON.hxx" -#include "utilities.h" - -#include "Basics_Utils.hxx" - -#ifdef WIN32 -#include -#else -#include -#include -#endif - -SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb); - -SALOMEDS_StudyManager::SALOMEDS_StudyManager(SALOMEDS::StudyManager_ptr theManager) -{ - -#ifdef WIN32 - long pid = (long)_getpid(); -#else - long pid = (long)getpid(); -#endif - - CORBA::LongLong addr = theManager->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal); - if(_isLocal) { - _local_impl = reinterpret_cast(addr); - _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager); - } - else { - _local_impl = NULL; - _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager); - } - - init_orb(); -} - -SALOMEDS_StudyManager::SALOMEDS_StudyManager() -{ - init_orb(); - - SALOME_NamingService namingService(_orb); - CORBA::Object_var obj = namingService.Resolve( "/myStudyManager" ); - SALOMEDS::StudyManager_var theManager = SALOMEDS::StudyManager::_narrow( obj ); - ASSERT( !CORBA::is_nil(theManager) ); - -#ifdef WIN32 - long pid = (long)_getpid(); -#else - long pid = (long)getpid(); -#endif - - CORBA::LongLong addr = theManager->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal); - if(_isLocal) { - _local_impl = reinterpret_cast(addr); - _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager); - } - else { - _local_impl = NULL; - _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager); - } -} - -SALOMEDS_StudyManager::~SALOMEDS_StudyManager() -{ -} - -_PTR(Study) SALOMEDS_StudyManager::NewStudy(const std::string& study_name) -{ - //SRN: Pure CORBA NewStudy as it does more initialization than the local one - SALOMEDSClient_Study* aStudy = NULL; - - SALOMEDS::Study_var aStudy_impl = _corba_impl->NewStudy((char*)study_name.c_str()); - if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy); - aStudy = new SALOMEDS_Study(aStudy_impl); - - return _PTR(Study)(aStudy); -} - -_PTR(Study) SALOMEDS_StudyManager::Open(const std::string& theStudyUrl) -{ - //SRN: Pure CORBA Open as it does more initialization than the local one - SALOMEDSClient_Study* aStudy = NULL; - - SALOMEDS::Study_var aStudy_impl = _corba_impl->Open((char*)theStudyUrl.c_str()); - if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy); - - aStudy = new SALOMEDS_Study(aStudy_impl.in()); - - return _PTR(Study)(aStudy); -} - -void SALOMEDS_StudyManager::Close(const _PTR(Study)& theStudy) -{ - //SRN: Pure CORBA close as it does more cleaning than the local one - SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId()); - _corba_impl->Close(aStudy); -} - -bool SALOMEDS_StudyManager::Save(const _PTR(Study)& theStudy, bool theMultiFile) -{ - //SRN: Pure CORBA save as the save operation require CORBA in any case - SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId()); - return _corba_impl->Save(aStudy, theMultiFile); -} - -bool SALOMEDS_StudyManager::SaveASCII(const _PTR(Study)& theStudy, bool theMultiFile) -{ - //SRN: Pure CORBA save as the save operation require CORBA in any case - SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId()); - return _corba_impl->SaveASCII(aStudy, theMultiFile); -} - -bool SALOMEDS_StudyManager::SaveAs(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile) -{ - //SRN: Pure CORBA save as the save operation require CORBA in any case - SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId()); - return _corba_impl->SaveAs((char*)theUrl.c_str(), aStudy, theMultiFile); -} - -bool SALOMEDS_StudyManager::SaveAsASCII(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile) -{ - //SRN: Pure CORBA save as the save operation require CORBA in any case - SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId()); - return _corba_impl->SaveAsASCII((char*)theUrl.c_str(), aStudy, theMultiFile); -} - -std::vector SALOMEDS_StudyManager::GetOpenStudies() -{ - std::vector aVector; - int aLength, i; - - if (_isLocal) { - SALOMEDS::Locker lock; - - std::vector aSeq = _local_impl->GetOpenStudies(); - aLength = aSeq.size(); - for(i = 0; i < aLength; i++) - aVector.push_back(aSeq[i]->Name()); - } - else { - SALOMEDS::ListOfOpenStudies_var aSeq = _corba_impl->GetOpenStudies(); - aLength = aSeq->length(); - for(i = 0; i < aLength; i++) - aVector.push_back(aSeq[i].in()); - } - return aVector; -} - -_PTR(Study) SALOMEDS_StudyManager::GetStudyByName(const std::string& theStudyName) -{ - SALOMEDSClient_Study* aStudy = NULL; - if (_isLocal) { - SALOMEDS::Locker lock; - - SALOMEDSImpl_Study* aStudy_impl = _local_impl->GetStudyByName(theStudyName); - if(!aStudy_impl) return _PTR(Study)(aStudy); - aStudy = new SALOMEDS_Study(aStudy_impl); - } - else { - SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByName((char*)theStudyName.c_str()); - if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy); - aStudy = new SALOMEDS_Study(aStudy_impl); - } - return _PTR(Study)(aStudy); -} - -_PTR(Study) SALOMEDS_StudyManager::GetStudyByID(int theStudyID) -{ - SALOMEDSClient_Study* aStudy = NULL; - if (_isLocal) { - SALOMEDS::Locker lock; - - SALOMEDSImpl_Study* aStudy_impl = _local_impl->GetStudyByID(theStudyID); - if(!aStudy_impl) return _PTR(Study)(aStudy); - aStudy = new SALOMEDS_Study(aStudy_impl); - } - else { - SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByID(theStudyID); - if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy); - aStudy = new SALOMEDS_Study(aStudy_impl); - } - return _PTR(Study)(aStudy); -} - -bool SALOMEDS_StudyManager::CanCopy(const _PTR(SObject)& theSO) -{ - SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); - bool ret; - - if (_isLocal) { - SALOMEDS::Locker lock; - - SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl()); - SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb); - ret = _local_impl->CanCopy(aSO_impl, aDriver); - delete aDriver; - } - else { - ret = _corba_impl->CanCopy(aSO->GetCORBAImpl()); - } - - return ret; -} - -bool SALOMEDS_StudyManager::Copy(const _PTR(SObject)& theSO) -{ - SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); - bool ret; - if (_isLocal) { - SALOMEDS::Locker lock; - - SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl()); - SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb); - ret = _local_impl->Copy(aSO_impl, aDriver); - delete aDriver; - } - else { - ret = _corba_impl->Copy(aSO->GetCORBAImpl()); - } - return ret; -} - -bool SALOMEDS_StudyManager::CanPaste(const _PTR(SObject)& theSO) -{ - SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); - bool ret; - - if (_isLocal) { - SALOMEDS::Locker lock; - - SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl()); - SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb); - ret = _local_impl->CanPaste(aSO_impl, aDriver); - delete aDriver; - } - else { - ret = _corba_impl->CanPaste(aSO->GetCORBAImpl()); - } - - return ret; -} - -_PTR(SObject) SALOMEDS_StudyManager::Paste(const _PTR(SObject)& theSO) -{ - SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); - SALOMEDSClient_SObject* aResult = NULL; - - if (_isLocal) { - SALOMEDS::Locker lock; - - SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl()); - SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb); - SALOMEDSImpl_SObject aNewSO = _local_impl->Paste(aSO_impl, aDriver); - delete aDriver; - if(aNewSO.IsNull()) return _PTR(SObject)(aResult); - aResult = new SALOMEDS_SObject(aNewSO); - } - else { - SALOMEDS::SObject_ptr aNewSO = _corba_impl->Paste(aSO->GetCORBAImpl()); - if(CORBA::is_nil(aNewSO)) return _PTR(SObject)(aResult); - aResult = new SALOMEDS_SObject(aNewSO); - } - - return _PTR(SObject)(aResult); -} - - -void SALOMEDS_StudyManager::init_orb() -{ - ORB_INIT &init = *SINGLETON_::Instance(); - ASSERT(SINGLETON_::IsAlreadyExisting()); - _orb = init(0 , 0 ); -} - -SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb) -{ - SALOMEDS_Driver_i* driver = NULL; - - SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent(); - if(!aSCO.IsNull()) { - std::string IOREngine = aSCO.GetIOR(); - if(!IOREngine.empty()) { - CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str()); - Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ; - driver = new SALOMEDS_Driver_i(Engine, orb); - } - } - - return driver; -} diff --git a/src/SALOMEDS/SALOMEDS_StudyManager.hxx b/src/SALOMEDS/SALOMEDS_StudyManager.hxx deleted file mode 100644 index 600676199..000000000 --- a/src/SALOMEDS/SALOMEDS_StudyManager.hxx +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : SALOMEDS_StudyManager.hxx -// Author : Sergey RUIN -// Module : SALOME -// -#ifndef __SALOMEDS_STUDYMANAGER_H__ -#define __SALOMEDS_STUDYMANAGER_H__ - -#include -#include - -#include "SALOMEDSClient.hxx" -#include "SALOMEDSImpl_StudyManager.hxx" - -// IDL headers - -#include -#include CORBA_SERVER_HEADER(SALOMEDS) - -class Standard_EXPORT SALOMEDS_StudyManager: public SALOMEDSClient_StudyManager -{ -private: - bool _isLocal; - SALOMEDSImpl_StudyManager* _local_impl; - SALOMEDS::StudyManager_var _corba_impl; - CORBA::ORB_var _orb; - -public: - - SALOMEDS_StudyManager(SALOMEDS::StudyManager_ptr theManager); - SALOMEDS_StudyManager(); - ~SALOMEDS_StudyManager(); - - virtual _PTR(Study) NewStudy(const std::string& study_name); - virtual _PTR(Study) Open(const std::string& theStudyUrl); - virtual void Close(const _PTR(Study)& theStudy); - virtual bool Save(const _PTR(Study)& theStudy, bool theMultiFile); - virtual bool SaveASCII(const _PTR(Study)& theStudy, bool theMultiFile); - virtual bool SaveAs(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile); - virtual bool SaveAsASCII(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile); - virtual std::vector GetOpenStudies(); - virtual _PTR(Study) GetStudyByName(const std::string& theStudyName) ; - virtual _PTR(Study) GetStudyByID(int theStudyID) ; - virtual bool CanCopy(const _PTR(SObject)& theSO); - virtual bool Copy(const _PTR(SObject)& theSO); - virtual bool CanPaste(const _PTR(SObject)& theSO); - virtual _PTR(SObject) Paste(const _PTR(SObject)& theSO); - -private: - void init_orb(); -}; - -#endif diff --git a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx deleted file mode 100644 index 6113ccc98..000000000 --- a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx +++ /dev/null @@ -1,535 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : SALOMEDS_StudyManager_i.cxx -// Author : Sergey RUIN -// Module : SALOME -// -#include "utilities.h" -#include "SALOME_LifeCycleCORBA.hxx" -#include "SALOMEDS_StudyManager_i.hxx" -#include "SALOMEDS_Study_i.hxx" -#include "SALOMEDS_SComponent_i.hxx" -#include "SALOMEDS_Driver_i.hxx" -#include "SALOMEDS.hxx" - -#include "SALOMEDSImpl_Study.hxx" -#include "SALOMEDSImpl_SObject.hxx" -#include "SALOMEDSImpl_SComponent.hxx" -#include "SALOMEDSImpl_AttributeIOR.hxx" - -#include "Utils_CorbaException.hxx" -#include "Utils_ExceptHandlers.hxx" -#include "Basics_Utils.hxx" -#include "SALOME_GenericObj_i.hh" - -#include -#include -#include - -#ifdef WIN32 -#include -#else -#include -#include -#endif - -UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception); -UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection); - -static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb); - -static std::map _mapOfPOA; - -//============================================================================ -/*! Function : SALOMEDS_StudyManager_i - * Purpose : SALOMEDS_StudyManager_i constructor - */ -//============================================================================ -SALOMEDS_StudyManager_i::SALOMEDS_StudyManager_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr thePOA) -{ - _orb = CORBA::ORB::_duplicate(orb); - _poa = PortableServer::POA::_duplicate(thePOA); - _name_service = new SALOME_NamingService(_orb); - // Study directory creation in the naming service : to register all - // open studies in the session - _name_service->Create_Directory("/Study"); - _impl = new SALOMEDSImpl_StudyManager; - _factory = new SALOMEDS_DriverFactory_i(_orb); -} - -//============================================================================ -/*! Function : ~SALOMEDS_StudyManager_i - * Purpose : SALOMEDS_StudyManager_i destructor - */ -//============================================================================ -SALOMEDS_StudyManager_i::~SALOMEDS_StudyManager_i() -{ - // Destroy directory to register open studies - _name_service->Destroy_Directory("/Study"); - delete _name_service; - delete _factory; - delete _impl; -} - -//============================================================================ -/*! Function : register_name - * Purpose : Register the study Manager in the naming service under the - * context name - */ -//============================================================================ -void SALOMEDS_StudyManager_i::register_name(const char * name) -{ - SALOMEDS::StudyManager_var aManager(_this()); - _name_service->Register(aManager.in(), name); -} - - -//============================================================================ -/*! Function : NewStudy - * Purpose : Create a New Study of name study_name - */ -//============================================================================ -SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::NewStudy(const char* study_name) - throw(SALOME::SALOME_Exception) -{ - SALOMEDS::Locker lock; - -#ifndef ALLOW_MULTI_STUDIES - std::vector anOpened = _impl->GetOpenStudies(); - int aLength = anOpened.size(); - - if(aLength) - { - MESSAGE("There is already an active study in this session. Launch a new session, or close the study"); - THROW_SALOME_CORBA_EXCEPTION("Problem on New Study.\nThere is already an active study in this session.\nLaunch a new session, or close the study", SALOME::BAD_PARAM) - } -#endif // !ALLOW_MULTI_STUDIES - - SALOMEDSImpl_Study* aStudyImpl = _impl->NewStudy(study_name); - if(!aStudyImpl) { - MESSAGE("NewStudy : Error : " << _impl->GetErrorCode()); - return SALOMEDS::Study::_nil(); - } - - MESSAGE("NewStudy : Creating the CORBA servant holding it... "); - - SALOMEDS_Study_i *Study_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb); - PortableServer::ObjectId_var servantid = _poa->activate_object(Study_servant); // to use poa registered in _mapOfPOA - SALOMEDS::Study_var Study = Study_servant->_this(); - - // Register study in the naming service - // Path to acces the study - if(!_name_service->Change_Directory("/Study")) - MESSAGE( "Unable to access the study directory" ) - else - _name_service->Register(Study, study_name); - - // Assign the value of the IOR in the study->root - CORBA::String_var IORStudy = _orb->object_to_string(Study); - - aStudyImpl->SetTransientReference((char*)IORStudy.in()); - - _mapOfPOA[Study->StudyId()] = _poa; - - return Study._retn(); -} - -//============================================================================ -/*! Function : Open - * Purpose : Open a Study from it's persistent reference - */ -//============================================================================ -SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::Open(const char* aUrl) - throw(SALOME::SALOME_Exception) -{ - SALOMEDS::Locker lock; - - Unexpect aCatch(SalomeException); - MESSAGE("Begin of SALOMEDS_StudyManager_i::Open"); - - #ifndef ALLOW_MULTI_STUDIES - std::vector anOpened = _impl->GetOpenStudies(); - int aLength = anOpened.size(); - - if(aLength) - { - MESSAGE("There is already an active study in this session. Launch a new session, or close the study."); - THROW_SALOME_CORBA_EXCEPTION("Problem on Open Study.\nThere is already an active study in this session.\nLaunch a new session, or close the study.", SALOME::BAD_PARAM) - } -#endif // ;ALLOW_MULTI_STUDIES - - SALOMEDSImpl_Study* aStudyImpl = _impl->Open(std::string(aUrl)); - - if ( !aStudyImpl ) - THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM) - - MESSAGE("Open : Creating the CORBA servant holding it... "); - - // Temporary aStudyUrl in place of study name - SALOMEDS_Study_i * Study_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb); - PortableServer::ObjectId_var servantid = _poa->activate_object(Study_servant); // to use poa register in _mapOfPOA - SALOMEDS::Study_var Study = Study_servant->_this(); - - // Assign the value of the IOR in the study->root - CORBA::String_var IORStudy = _orb->object_to_string(Study); - aStudyImpl->SetTransientReference((char*)IORStudy.in()); - - _mapOfPOA[Study->StudyId()] = _poa; - - // Register study in the naming service - // Path to acces the study - if(!_name_service->Change_Directory("/Study")) MESSAGE( "Unable to access the study directory" ) - else _name_service->Register(Study, aStudyImpl->Name().c_str()); - - return Study._retn(); -} - - - -//============================================================================ -/*! Function : Close - * Purpose : Close a study. - * If the study hasn't been saved, ask the user to confirm the - * close action without saving - */ -//============================================================================ -void SALOMEDS_StudyManager_i::Close(SALOMEDS::Study_ptr aStudy) -{ - SALOMEDS::Locker lock; - - if(aStudy->_is_nil()) return; - - // Destroy study name in the naming service - if(_name_service->Change_Directory("/Study")){ - CORBA::String_var aString(aStudy->Name()); - _name_service->Destroy_Name(aString.in()); - } - - SALOMEDS::unlock(); - aStudy->Close(); - SALOMEDS::lock(); - - //remove study servant - PortableServer::POA_ptr poa=GetPOA(aStudy); - PortableServer::ServantBase* aservant=poa->reference_to_servant(aStudy); - PortableServer::ObjectId_var anObjectId = poa->servant_to_id(aservant); - poa->deactivate_object(anObjectId.in()); - aservant->_remove_ref(); // decrement for the call to reference_to_servant - aservant->_remove_ref(); // to delete the object -} - -//============================================================================ -/*! Function : Save - * Purpose : Save a Study to it's persistent reference - */ -//============================================================================ -CORBA::Boolean SALOMEDS_StudyManager_i::Save(SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile) -{ - SALOMEDS::Locker lock; - - if(aStudy->_is_nil()) { - MESSAGE("Save error: Study is null"); - return false; - } - - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); - return _impl->Save(aStudyImpl, _factory, theMultiFile); -} - -CORBA::Boolean SALOMEDS_StudyManager_i::SaveASCII(SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile) -{ - SALOMEDS::Locker lock; - - if(aStudy->_is_nil()) { - MESSAGE("SaveASCII error: Study is null"); - return false; - } - - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); - return _impl->SaveASCII(aStudyImpl, _factory, theMultiFile); -} - -//============================================================================= -/*! Function : SaveAs - * Purpose : Save a study to the persistent reference aUrl - */ -//============================================================================ -CORBA::Boolean SALOMEDS_StudyManager_i::SaveAs(const char* aUrl, SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile) -{ - SALOMEDS::Locker lock; - - if(aStudy->_is_nil()) { - MESSAGE("SaveASCII error: Study is null"); - return false; - } - - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); - return _impl->SaveAs(std::string(aUrl), aStudyImpl, _factory, theMultiFile); -} - -CORBA::Boolean SALOMEDS_StudyManager_i::SaveAsASCII(const char* aUrl, SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile) -{ - SALOMEDS::Locker lock; - - if(aStudy->_is_nil()) { - MESSAGE("SaveASCII error: Study is null"); - return false; - } - - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); - return _impl->SaveAsASCII(std::string(aUrl), aStudyImpl, _factory, theMultiFile); -} - -//============================================================================ -/*! Function : GetOpenStudies - * Purpose : Get name list of open studies in the session - */ -//============================================================================ -SALOMEDS::ListOfOpenStudies* SALOMEDS_StudyManager_i::GetOpenStudies() -{ - SALOMEDS::Locker lock; - - std::vector anOpened = _impl->GetOpenStudies(); - int aLength = anOpened.size(); - - SALOMEDS::ListOfOpenStudies_var _list_open_studies = new SALOMEDS::ListOfOpenStudies; - _list_open_studies->length(aLength); - - if(!aLength) - { - MESSAGE("No active study in this session"); - } - else - { - for (unsigned int ind=0; ind < aLength; ind++) - { - _list_open_studies[ind] = CORBA::string_dup(anOpened[ind]->Name().c_str()); - SCRUTE(_list_open_studies[ind]) ; - } - } - return _list_open_studies._retn(); -} - -//============================================================================ -/*! Function : GetStudyByName - * Purpose : Get a study from its name - */ -//============================================================================ -SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::GetStudyByName(const char* aStudyName) -{ - SALOMEDS::Locker lock; - - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByName(std::string(aStudyName)); - - if (!aStudyImpl) - { - MESSAGE(_impl->GetErrorCode().c_str()); - return SALOMEDS::Study::_nil(); - } - - SALOMEDS_Study_i* aStudy_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb); - return aStudy_servant->_this(); -} - -//============================================================================ -/*! Function : GetStudyByID - * Purpose : Get a study from its ID - */ -//============================================================================ -SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::GetStudyByID(CORBA::Short aStudyID) -{ - SALOMEDS::Locker lock; - - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudyID); - - if (!aStudyImpl) - { - MESSAGE(_impl->GetErrorCode().c_str()); - return SALOMEDS::Study::_nil(); - } - - SALOMEDS_Study_i* aStudy_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb); - return aStudy_servant->_this(); -} - - -//============================================================================ -/*! Function : CanCopy - * Purpose : - */ -//============================================================================ -CORBA::Boolean SALOMEDS_StudyManager_i::CanCopy(SALOMEDS::SObject_ptr theObject) -{ - SALOMEDS::Locker lock; - - SALOMEDS::Study_var aStudy = theObject->GetStudy(); - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); - CORBA::String_var anID = theObject->GetID(); - SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in()); - - SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb); - bool ret = _impl->CanCopy(anObject, aDriver); - delete aDriver; - return ret; -} - -//============================================================================ -/*! Function : Copy - * Purpose : - */ -//============================================================================ -CORBA::Boolean SALOMEDS_StudyManager_i::Copy(SALOMEDS::SObject_ptr theObject) -{ - SALOMEDS::Locker lock; - - SALOMEDS::Study_var aStudy = theObject->GetStudy(); - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); - CORBA::String_var anID = theObject->GetID(); - SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in()); - - SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb); - bool ret = _impl->Copy(anObject, aDriver); - delete aDriver; - return ret; -} - -//============================================================================ -/*! Function : CanPaste - * Purpose : - */ -//============================================================================ -CORBA::Boolean SALOMEDS_StudyManager_i::CanPaste(SALOMEDS::SObject_ptr theObject) -{ - SALOMEDS::Locker lock; - - SALOMEDS::Study_var aStudy = theObject->GetStudy(); - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); - CORBA::String_var anID = theObject->GetID(); - SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in()); - - SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb); - bool ret = _impl->CanPaste(anObject, aDriver); - delete aDriver; - return ret; -} - -//============================================================================ -/*! Function : Paste - * Purpose : - */ -//============================================================================ -SALOMEDS::SObject_ptr SALOMEDS_StudyManager_i::Paste(SALOMEDS::SObject_ptr theObject) - throw(SALOMEDS::StudyBuilder::LockProtection) -{ - SALOMEDS::Locker lock; - - Unexpect aCatch(LockProtection); - SALOMEDS::Study_var aStudy = theObject->GetStudy(); - - SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); - CORBA::String_var anID = theObject->GetID(); - SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in()); - SALOMEDSImpl_SObject aNewSO; - - try { - SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb); - aNewSO = _impl->Paste(anObject, aDriver); - delete aDriver; - } - catch (...) { - throw SALOMEDS::StudyBuilder::LockProtection(); - } - - SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb); - return so._retn(); -} - - -SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb) -{ - SALOMEDS_Driver_i* driver = NULL; - - SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent(); - if(!aSCO.IsNull()) { - std::string IOREngine = aSCO.GetIOR(); - if(!IOREngine.empty()) { - CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str()); - Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ; - driver = new SALOMEDS_Driver_i(Engine, orb); - } - } - - return driver; -} - -PortableServer::POA_ptr SALOMEDS_StudyManager_i::GetPOA(const SALOMEDS::Study_ptr theStudy) { - if (_mapOfPOA.find(theStudy->StudyId()) != _mapOfPOA.end()) return _mapOfPOA[theStudy->StudyId()]; - return PortableServer::POA::_nil(); -} - -CORBA::Long SALOMEDS_StudyManager_i::getPID() -{ -#ifdef WIN32 - return (CORBA::Long)_getpid(); -#else - return (CORBA::Long)getpid(); -#endif -} - -void SALOMEDS_StudyManager_i::ShutdownWithExit() -{ - exit( EXIT_SUCCESS ); -} - -//=========================================================================== -// PRIVATE FUNCTIONS -//=========================================================================== -CORBA::LongLong SALOMEDS_StudyManager_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal) -{ -#ifdef WIN32 - long pid = (long)_getpid(); -#else - long pid = (long)getpid(); -#endif - isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0; - return reinterpret_cast(_impl); -} - -//=========================================================================== -namespace SALOMEDS -{ - PortableServer::ServantBase_var - GetServant(CORBA::Object_ptr theObject, PortableServer::POA_ptr thePOA) - { - if(CORBA::is_nil(theObject)) - return NULL; - try{ - return thePOA->reference_to_servant(theObject); - }catch(...){ - return NULL; - } - } - -} - -//=========================================================================== diff --git a/src/SALOMEDS/SALOMEDS_StudyManager_i.hxx b/src/SALOMEDS/SALOMEDS_StudyManager_i.hxx deleted file mode 100644 index ba1daf0eb..000000000 --- a/src/SALOMEDS/SALOMEDS_StudyManager_i.hxx +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : SALOMEDS_StudyManager_i.hxx -// Author : Sergey RUIN -// Module : SALOME -// -#ifndef __SALOMEDS_STUDYMANAGER_I_H__ -#define __SALOMEDS_STUDYMANAGER_I_H__ - -// std C++ headers -#include - -#ifndef WIN32 -#include -#endif - -// IDL headers -#include -#include CORBA_SERVER_HEADER(SALOMEDS) - -// Naming Service header -#include "SALOME_NamingService.hxx" - -#include - -#include "SALOMEDS_Driver_i.hxx" -#include "SALOMEDSImpl_StudyManager.hxx" - -namespace SALOMEDS{ - - // To convert CORBA::Object to PortableServer::ServantBase - PortableServer::ServantBase_var GetServant(CORBA::Object_ptr, PortableServer::POA_ptr); - -} - -class Standard_EXPORT SALOMEDS_StudyManager_i: public POA_SALOMEDS::StudyManager -{ -private: - - CORBA::ORB_var _orb; - PortableServer::POA_var _poa; - SALOMEDSImpl_StudyManager* _impl; - SALOME_NamingService* _name_service; - SALOMEDS_DriverFactory_i* _factory; - -public: - - //! standard constructor - SALOMEDS_StudyManager_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr thePOA); - - //! standard destructor - virtual ~SALOMEDS_StudyManager_i(); - - //! method to Register study Manager in the naming service - /*! - \param char* arguments, the context to register the study manager in the NS - */ - void register_name(const char * name); - - //! method to Create a New Study of name study_name - /*! - \param char* arguments, the new study name - \return Study_ptr arguments - */ - virtual SALOMEDS::Study_ptr NewStudy(const char* study_name) throw (SALOME::SALOME_Exception); - - //! method to Open a Study from it's persistent reference - /*! - \param char* arguments, the study URL - \return Study_ptr arguments - */ - virtual SALOMEDS::Study_ptr Open(const char* aStudyUrl) throw (SALOME::SALOME_Exception); - - - //! method to close a Study - /*! - \param Study_ptr arguments - */ - virtual void Close( SALOMEDS::Study_ptr aStudy); - - //! method to save a Study - /*! - \param Study_ptr arguments - */ - virtual CORBA::Boolean Save( SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile); - - virtual CORBA::Boolean SaveASCII( SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile); - - //! method to save a Study to the persistent reference aUrl - /*! - \param char* arguments, the new URL of the study - \param Study_ptr arguments - */ - virtual CORBA::Boolean SaveAs(const char* aUrl, SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile); - virtual CORBA::Boolean SaveAsASCII(const char* aUrl, SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile); - - //! method to Get name list of open studies in the session - /*! - \return ListOfOpenStudies* arguments - */ - virtual SALOMEDS::ListOfOpenStudies* GetOpenStudies(); - - //! method to get a Study from it's name - /*! - \param char* arguments, the study name - \return Study_ptr arguments - */ - virtual SALOMEDS::Study_ptr GetStudyByName(const char* aStudyName) ; - - //! method to get a Study from it's ID - /*! - \param char* arguments, the study ID - \return Study_ptr arguments - */ - virtual SALOMEDS::Study_ptr GetStudyByID(CORBA::Short aStudyID) ; - - virtual CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject); - virtual CORBA::Boolean Copy(SALOMEDS::SObject_ptr theObject); - virtual CORBA::Boolean CanPaste(SALOMEDS::SObject_ptr theObject); - virtual SALOMEDS::SObject_ptr Paste(SALOMEDS::SObject_ptr theObject) throw(SALOMEDS::StudyBuilder::LockProtection); - - virtual char* ConvertObjectToIOR(CORBA::Object_ptr theObject) {return _orb->object_to_string(theObject); } - virtual CORBA::Object_ptr ConvertIORToObject(const char* theIOR) { return _orb->string_to_object(theIOR); }; - - void ping(){}; - CORBA::Long getPID(); - void ShutdownWithExit(); - - virtual CORBA::LongLong GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal); - - static PortableServer::POA_ptr GetPOA(const SALOMEDS::Study_ptr theStudy); - - void Shutdown() { if(!CORBA::is_nil(_orb)) _orb->shutdown(0); } -}; - -#endif diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 921c9b34b..5c1337f18 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -27,7 +27,6 @@ #include "utilities.h" #include #include "SALOMEDS_Study_i.hxx" -#include "SALOMEDS_StudyManager_i.hxx" #include "SALOMEDS_UseCaseIterator_i.hxx" #include "SALOMEDS_GenericAttribute_i.hxx" #include "SALOMEDS_AttributeStudyProperties_i.hxx" @@ -48,6 +47,8 @@ #include "DF_Label.hxx" #include "DF_Attribute.hxx" +#include "Utils_ExceptHandlers.hxx" + #include "Basics_Utils.hxx" #include "SALOME_KernelServices.hxx" @@ -58,6 +59,11 @@ #include #endif +UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception); +UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection); + +static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb); + namespace SALOMEDS { class Notifier: public SALOMEDSImpl_AbstractCallback @@ -219,25 +225,46 @@ namespace SALOMEDS } // namespace SALOMEDS -std::map SALOMEDS_Study_i::_mapOfStudies; - //============================================================================ /*! Function : SALOMEDS_Study_i * Purpose : SALOMEDS_Study_i constructor */ //============================================================================ -SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl, - CORBA::ORB_ptr orb) +SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb) +{ + _orb = CORBA::ORB::_duplicate(orb); + _impl = new SALOMEDSImpl_Study(); + _factory = new SALOMEDS_DriverFactory_i(_orb); + + Init(); +} + +//============================================================================ +/*! Function : ~SALOMEDS_Study_i + * Purpose : SALOMEDS_Study_i destructor + */ +//============================================================================ +SALOMEDS_Study_i::~SALOMEDS_Study_i() +{ + Clear(); + delete _factory; + delete _impl; +} + +//============================================================================ +/*! Function : Init + * Purpose : Initialize study components + */ +//============================================================================ +void SALOMEDS_Study_i::Init() { - _orb = CORBA::ORB::_duplicate(orb); - _impl = 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 ); + _impl->setNotifier(_notifier); + _impl->setGenObjRegister( _genObjRegister ); // Notify GUI that study was created SALOME_NamingService *aNamingService = KERNEL::getNamingService(); @@ -245,20 +272,20 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl, SALOME::Session_var aSession = SALOME::Session::_narrow(obj); if ( !CORBA::is_nil(aSession) ) { std::stringstream ss; - ss << "studyCreated:" << theImpl->StudyId(); + ss << "studyCreated"; std::string str = ss.str(); SALOMEDS::unlock(); aSession->emitMessageOneWay(str.c_str()); SALOMEDS::lock(); } } - + //============================================================================ -/*! Function : ~SALOMEDS_Study_i - * Purpose : SALOMEDS_Study_i destructor +/*! Function : Clear + * Purpose : Clear study components */ //============================================================================ -SALOMEDS_Study_i::~SALOMEDS_Study_i() +void SALOMEDS_Study_i::Clear() { //delete the builder servant PortableServer::POA_var poa=_builder->_default_POA(); @@ -266,13 +293,218 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i() poa->deactivate_object(anObjectId.in()); _builder->_remove_ref(); + _impl->Clear(); _impl->setNotifier(0); delete _notifier; delete _genObjRegister; - //delete implementation - delete _impl; - _mapOfStudies.erase(_impl); -} + + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + RemovePostponed(-1); + + SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator(); + for (; itcomponent->More(); itcomponent->Next()) { + SALOMEDS::SComponent_var sco = itcomponent->Value(); + CORBA::String_var compodatatype=sco->ComponentDataType(); + MESSAGE ( "Look for an engine for data type :"<< compodatatype); + // if there is an associated Engine call its method for closing + CORBA::String_var IOREngine; + if (sco->ComponentIOR(IOREngine)) { + // 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&) { + } + } + sco->UnRegister(); + } + + //Does not need any more this iterator + itcomponent->UnRegister(); + + // Notify GUI that study is cleared + 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 << "studyCleared"; + std::string str = ss.str(); + SALOMEDS::unlock(); + aSession->emitMessageOneWay(str.c_str()); + SALOMEDS::lock(); + } + + _closed = true; +} + +//============================================================================ +/*! Function : Open + * Purpose : Open a Study from it's persistent reference + */ +//============================================================================ +bool SALOMEDS_Study_i::Open(const char* aUrl) + throw(SALOME::SALOME_Exception) +{ + SALOMEDS::Locker lock; + + Unexpect aCatch(SalomeException); + MESSAGE("Begin of SALOMEDS_Study_i::Open"); + + bool res = _impl->Open(std::string(aUrl)); + + if ( !res ) + THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM) + return res; +} + +//============================================================================ +/*! Function : Save + * Purpose : Save a Study to it's persistent reference + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile) +{ + SALOMEDS::Locker lock; + return _impl->Save(_factory, theMultiFile); +} + +CORBA::Boolean SALOMEDS_Study_i::SaveASCII(CORBA::Boolean theMultiFile) +{ + SALOMEDS::Locker lock; + return _impl->SaveASCII(_factory, theMultiFile); +} + +//============================================================================= +/*! Function : SaveAs + * Purpose : Save a study to the persistent reference aUrl + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile) +{ + SALOMEDS::Locker lock; + return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile); +} + +CORBA::Boolean SALOMEDS_Study_i::SaveAsASCII(const char* aUrl, CORBA::Boolean theMultiFile) +{ + SALOMEDS::Locker lock; + return _impl->SaveAsASCII(std::string(aUrl), _factory, theMultiFile); +} + +//============================================================================ +/*! Function : CanCopy + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject) +{ + SALOMEDS::Locker lock; + + CORBA::String_var anID = theObject->GetID(); + SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in()); + + SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb); + bool ret = _impl->CanCopy(anObject, aDriver); + delete aDriver; + return ret; +} + +//============================================================================ +/*! Function : Copy + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject) +{ + SALOMEDS::Locker lock; + + CORBA::String_var anID = theObject->GetID(); + SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in()); + + SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb); + bool ret = _impl->Copy(anObject, aDriver); + delete aDriver; + return ret; +} + +//============================================================================ +/*! Function : CanPaste + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject) +{ + SALOMEDS::Locker lock; + + CORBA::String_var anID = theObject->GetID(); + SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in()); + + SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb); + bool ret = _impl->CanPaste(anObject, aDriver); + delete aDriver; + return ret; +} + +//============================================================================ +/*! Function : Paste + * Purpose : + */ +//============================================================================ +SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject) + throw(SALOMEDS::StudyBuilder::LockProtection) +{ + SALOMEDS::Locker lock; + + Unexpect aCatch(LockProtection); + + CORBA::String_var anID = theObject->GetID(); + SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in()); + SALOMEDSImpl_SObject aNewSO; + + try { + SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb); + aNewSO = _impl->Paste(anObject, aDriver); + delete aDriver; + } + catch (...) { + throw SALOMEDS::StudyBuilder::LockProtection(); + } + + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb); + return so._retn(); +} + +SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb) +{ + SALOMEDS_Driver_i* driver = NULL; + + SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent(); + if(!aSCO.IsNull()) { + std::string IOREngine = aSCO.GetIOR(); + if(!IOREngine.empty()) { + CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str()); + Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ; + driver = new SALOMEDS_Driver_i(Engine, orb); + } + } + + return driver; +} //============================================================================ /*! Function : GetPersistentReference @@ -751,18 +983,6 @@ char* SALOMEDS_Study_i::Name() return CORBA::string_dup(_impl->Name().c_str()); } -//============================================================================ -/*! Function : Name - * Purpose : set study 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)); -} - //============================================================================ /*! Function : IsSaved * Purpose : get if study has been saved @@ -842,20 +1062,6 @@ void SALOMEDS_Study_i::URL(const char* url) _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) { SALOMEDS::Locker lock; @@ -866,9 +1072,9 @@ void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry) _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry)); } -SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb) +SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb) { - SALOMEDS::Locker lock; + SALOMEDS::Locker lock; SALOMEDSImpl_AttributeIOR* Att = NULL; if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){ @@ -883,18 +1089,6 @@ SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA:: return SALOMEDS::Study::_nil(); } -SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb) -{ - 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; - } -} - void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) { SALOMEDS::Locker lock; @@ -978,69 +1172,6 @@ SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() return uc._retn(); } - -//============================================================================ -/*! Function : Close - * Purpose : - */ -//============================================================================ -void SALOMEDS_Study_i::Close() -{ - SALOMEDS::Locker lock; - - if (_closed) - throw SALOMEDS::Study::StudyInvalidReference(); - - RemovePostponed(-1); - - SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator(); - for (; itcomponent->More(); itcomponent->Next()) { - SALOMEDS::SComponent_var sco = itcomponent->Value(); - CORBA::String_var compodatatype=sco->ComponentDataType(); - MESSAGE ( "Look for an engine for data type :"<< compodatatype); - // if there is an associated Engine call its method for closing - CORBA::String_var IOREngine; - if (sco->ComponentIOR(IOREngine)) { - // 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&) { - } - } - 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; -} - //============================================================================ /*! Function : AddPostponed * Purpose : @@ -1580,6 +1711,27 @@ void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) } } + +CORBA::Long SALOMEDS_Study_i::getPID() +{ +#ifdef WIN32 + return (CORBA::Long)_getpid(); +#else + return (CORBA::Long)getpid(); +#endif +} + +void SALOMEDS_Study_i::ShutdownWithExit() +{ + exit( EXIT_SUCCESS ); +} + +void SALOMEDS_Study_i::Shutdown() +{ + if(!CORBA::is_nil(_orb)) + _orb->shutdown(0); +} + //============================================================================ /*! Function : attach * Purpose : This function attach an observer to the study diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index a767e6414..20b3bd6d2 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -42,6 +42,7 @@ #include "SALOMEDS_StudyBuilder_i.hxx" #include "SALOMEDS_SObject_i.hxx" #include "SALOMEDS_UseCaseBuilder_i.hxx" +#include "SALOMEDS_Driver_i.hxx" #include "SALOMEDSImpl_Study.hxx" #include "SALOMEDSImpl_AttributeIOR.hxx" @@ -52,19 +53,53 @@ private: CORBA::ORB_var _orb; SALOMEDSImpl_Study* _impl; SALOMEDS_StudyBuilder_i* _builder; - static std::map _mapOfStudies; SALOMEDSImpl_AbstractCallback* _notifier; SALOMEDSImpl_AbstractCallback* _genObjRegister; + SALOMEDS_DriverFactory_i* _factory; bool _closed; public: //! standard constructor - SALOMEDS_Study_i(SALOMEDSImpl_Study*, CORBA::ORB_ptr); + SALOMEDS_Study_i(CORBA::ORB_ptr); //! standard destructor - virtual ~SALOMEDS_Study_i(); + virtual ~SALOMEDS_Study_i(); + virtual void Init(); + virtual void Clear(); + + //! method to Open a Study + /*! + \param char* arguments, the study URL + \return Study_ptr arguments + */ + virtual bool Open(const char* aStudyUrl) throw (SALOME::SALOME_Exception); + + //! method to save a Study + virtual CORBA::Boolean Save(CORBA::Boolean theMultiFile); + virtual CORBA::Boolean SaveASCII(CORBA::Boolean theMultiFile); + + //! method to save a Study to the persistent reference aUrl + /*! + \param char* arguments, the new URL of the study + */ + virtual CORBA::Boolean SaveAs(const char* aUrl, CORBA::Boolean theMultiFile); + virtual CORBA::Boolean SaveAsASCII(const char* aUrl, CORBA::Boolean theMultiFile); + + //! method to copy the object + /*! + \param theObject object to copy + */ + virtual CORBA::Boolean Copy(SALOMEDS::SObject_ptr theObject); + virtual CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject); + //! method to paste the object in study + /*! + \param theObject object to paste + */ + virtual SALOMEDS::SObject_ptr Paste(SALOMEDS::SObject_ptr theObject) throw(SALOMEDS::StudyBuilder::LockProtection); + virtual CORBA::Boolean CanPaste(SALOMEDS::SObject_ptr theObject); + //! method to Get persistent reference of study (idem URL()) /*! \sa URL() @@ -206,12 +241,6 @@ public: */ virtual char* Name(); - //! method to set study name - /*! - \param name char* arguments, the study name - */ - virtual void Name(const char* name); - //! method to get if study has been saved /*! \return bool arguments @@ -245,11 +274,7 @@ public: */ virtual void URL(const char* url); - virtual CORBA::Short StudyId(); - virtual void StudyId(CORBA::Short id); - static SALOMEDS::Study_ptr GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb); - static SALOMEDS_Study_i* GetStudyServant(SALOMEDSImpl_Study*, CORBA::ORB_ptr orb); static void IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute); @@ -268,8 +293,6 @@ public: virtual SALOMEDS::UseCaseBuilder_ptr GetUseCaseBuilder(); - virtual void Close(); - void EnableUseCaseAutoFilling(CORBA::Boolean isEnabled); // postponed destroying of CORBA object functionality @@ -344,6 +367,12 @@ public: virtual CORBA::LongLong GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal); + void ping(){}; + CORBA::Long getPID(); + void ShutdownWithExit(); + + void Shutdown(); + virtual void attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify); virtual void detach(SALOMEDS::Observer_ptr theObs); }; diff --git a/src/SALOMEDSClient/SALOMEDSClient.hxx b/src/SALOMEDSClient/SALOMEDSClient.hxx index 9a1598467..aeba1bbad 100644 --- a/src/SALOMEDSClient/SALOMEDSClient.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient.hxx @@ -61,7 +61,6 @@ #include "SALOMEDSClient_SObject.hxx" #include "SALOMEDSClient_Study.hxx" #include "SALOMEDSClient_StudyBuilder.hxx" -#include "SALOMEDSClient_StudyManager.hxx" #include "SALOMEDSClient_UseCaseBuilder.hxx" #include "SALOMEDSClient_UseCaseIterator.hxx" diff --git a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx index bfada6418..b42b4b12e 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx +++ b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx @@ -36,8 +36,6 @@ static void* _libHandle = NULL; #define SCOMPONENT_FACTORY "SComponentFactory" #define STUDY_FACTORY "StudyFactory" #define BUILDER_FACTORY "BuilderFactory" -#define STUDYMANAGER_FACTORY "StudyManagerFactory" -#define STUDYMANAGER_CREATE "CreateStudyManager" #define GET_PARAMETERS "GetIParameters" #define CONVERT_SOBJECT "ConvertSObject" #define CONVERT_STUDY "ConvertStudy" @@ -46,9 +44,7 @@ static void* _libHandle = NULL; typedef SALOMEDSClient_SObject* (*SOBJECT_FACTORY_FUNCTION) (SALOMEDS::SObject_ptr); typedef SALOMEDSClient_SComponent* (*SCOMPONENT_FACTORY_FUNCTION) (SALOMEDS::SComponent_ptr); typedef SALOMEDSClient_Study* (*STUDY_FACTORY_FUNCTION) (SALOMEDS::Study_ptr); -typedef SALOMEDSClient_StudyManager* (*STUDYMANAGER_FACTORY_FUNCTION) (); typedef SALOMEDSClient_StudyBuilder* (*BUILDER_FACTORY_FUNCTION) (SALOMEDS::StudyBuilder_ptr); -typedef SALOMEDSClient_StudyManager* (*STUDYMANAGER_CREATE_FUNCTION) (CORBA::ORB_ptr, PortableServer::POA_ptr); typedef SALOMEDSClient_IParameters* (*GET_PARAMETERS_FACTORY) (const _PTR(AttributeParameter)&); typedef SALOMEDS::SObject_ptr (*CONVERT_SOBJECT_FUNCTION) (const _PTR(SObject)&); typedef SALOMEDS::Study_ptr (*CONVERT_STUDY_FUNCTION) (const _PTR(Study)&); @@ -59,8 +55,6 @@ static SOBJECT_FACTORY_FUNCTION aSObjectFactory = NULL; static SCOMPONENT_FACTORY_FUNCTION aSComponentFactory = NULL; static STUDY_FACTORY_FUNCTION aStudyFactory = NULL; static BUILDER_FACTORY_FUNCTION aBuilderFactory = NULL; -static STUDYMANAGER_FACTORY_FUNCTION aManagerFactory = NULL; -static STUDYMANAGER_CREATE_FUNCTION aCreateFactory = NULL; static GET_PARAMETERS_FACTORY aGetIParameters = NULL; static CONVERT_SOBJECT_FUNCTION aConvertSObject = NULL; static CONVERT_STUDY_FUNCTION aConvertStudy = NULL; @@ -130,38 +124,6 @@ _PTR(StudyBuilder) ClientFactory::StudyBuilder(SALOMEDS::StudyBuilder_ptr theStu return _PTR(StudyBuilder)(studyBuilder); } -_PTR(StudyManager) ClientFactory::StudyManager() -{ - SALOMEDSClient_StudyManager* manager = NULL; - -#ifdef WIN32 - if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); - if(!aManagerFactory) aManagerFactory = (STUDYMANAGER_FACTORY_FUNCTION)::GetProcAddress(_libHandle, STUDYMANAGER_FACTORY); -#else - if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL); - if(!aManagerFactory) aManagerFactory = (STUDYMANAGER_FACTORY_FUNCTION) dlsym(_libHandle, STUDYMANAGER_FACTORY); -#endif - - if(aManagerFactory) manager = aManagerFactory(); - return _PTR(StudyManager)(manager); -} - -_PTR(StudyManager) ClientFactory::createStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) -{ - SALOMEDSClient_StudyManager* manager = NULL; - -#ifdef WIN32 - if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); - if(!aCreateFactory) aCreateFactory = (STUDYMANAGER_CREATE_FUNCTION)::GetProcAddress(_libHandle, STUDYMANAGER_CREATE); -#else - if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL); - if(!aCreateFactory) aCreateFactory = (STUDYMANAGER_CREATE_FUNCTION) dlsym(_libHandle, STUDYMANAGER_CREATE); -#endif - - if(aCreateFactory) manager = aCreateFactory(orb, poa); - return _PTR(StudyManager)(manager); -} - _PTR(IParameters) ClientFactory::getIParameters(const _PTR(AttributeParameter)& ap) { SALOMEDSClient_IParameters* interface = NULL; diff --git a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx index 59df14ea5..a3d5ca4fa 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx @@ -32,7 +32,6 @@ #include "SALOMEDSClient_SObject.hxx" #include "SALOMEDSClient_SComponent.hxx" #include "SALOMEDSClient_Study.hxx" -#include "SALOMEDSClient_StudyManager.hxx" #include "SALOMEDSClient_IParameters.hxx" #include @@ -64,16 +63,6 @@ public: */ static _PTR(StudyBuilder) StudyBuilder(SALOMEDS::StudyBuilder_ptr theBuilder); - /*! - * Returns a client StudyManager wrapper - */ - static _PTR(StudyManager) StudyManager(); - - /*! - * Creates and returns a client StudyManager wrapper - */ - static _PTR(StudyManager) createStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); - /*! * Returns an IParameters interface */ diff --git a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx index 7f7349f3b..46b598865 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx @@ -49,6 +49,11 @@ class SALOMEDSClient_Study public: virtual ~SALOMEDSClient_Study() {} + virtual void Init() = 0; + virtual void Clear() = 0; + + virtual bool Open(const std::string& theStudyUrl) = 0; + virtual std::string GetPersistentReference() = 0; virtual std::string GetTransientReference() = 0; virtual bool IsEmpty() = 0; @@ -71,21 +76,28 @@ public: virtual _PTR(SComponentIterator) NewComponentIterator() = 0; virtual _PTR(StudyBuilder) NewBuilder() = 0; virtual std::string Name() = 0; - virtual void Name(const std::string& name) = 0; virtual bool IsSaved() = 0; virtual void IsSaved(bool save) = 0; virtual bool IsModified() = 0; virtual void Modified() = 0; virtual std::string URL() = 0; virtual void URL(const std::string& url) = 0; - virtual int StudyId() = 0; - virtual void StudyId(int id) = 0; virtual std::vector<_PTR(SObject)> FindDependances(const _PTR(SObject)& theSO) = 0; virtual _PTR(AttributeStudyProperties) GetProperties() = 0; virtual std::string GetLastModificationDate() = 0; virtual std::vector GetModificationsDate() = 0; virtual _PTR(UseCaseBuilder) GetUseCaseBuilder() = 0; - virtual void Close() = 0; + + virtual bool Save(bool theMultiFile) = 0; + virtual bool SaveASCII(bool theMultiFile) = 0; + virtual bool SaveAs(const std::string& theUrl, bool theMultiFile) = 0; + virtual bool SaveAsASCII(const std::string& theUrl, bool theMultiFile) = 0; + + virtual bool CanCopy(const _PTR(SObject)& theSO) = 0; + virtual bool Copy(const _PTR(SObject)& theSO) = 0; + virtual bool CanPaste(const _PTR(SObject)& theSO) = 0; + virtual _PTR(SObject) Paste(const _PTR(SObject)& theSO) = 0; + virtual void EnableUseCaseAutoFilling(bool isEnabled) = 0; virtual bool DumpStudy(const std::string& thePath, const std::string& theBaseName, diff --git a/src/SALOMEDSClient/SALOMEDSClient_StudyManager.hxx b/src/SALOMEDSClient/SALOMEDSClient_StudyManager.hxx deleted file mode 100644 index d536bfe20..000000000 --- a/src/SALOMEDSClient/SALOMEDSClient_StudyManager.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : SALOMEDSClient_StudyManager.hxx -// Author : Sergey RUIN -// Module : SALOME -// -#ifndef __SALOMEDSClient_STUDYMANAGER_H__ -#define __SALOMEDSClient_STUDYMANAGER_H__ - -#include -#include - -#include "SALOMEDSClient_definitions.hxx" -#include "SALOMEDSClient_Study.hxx" - -class SALOMEDSClient_StudyManager -{ -public: - virtual ~SALOMEDSClient_StudyManager() {} - - virtual _PTR(Study) NewStudy(const std::string& study_name) = 0; - virtual _PTR(Study) Open(const std::string& theStudyUrl) = 0; - virtual void Close(const _PTR(Study)& theStudy) = 0; - virtual bool Save(const _PTR(Study)& theStudy, bool theMultiFile) = 0; - virtual bool SaveASCII(const _PTR(Study)& theStudy, bool theMultiFile) = 0; - virtual bool SaveAs(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile) = 0; - virtual bool SaveAsASCII(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile) = 0; - virtual std::vector GetOpenStudies() = 0; - virtual _PTR(Study) GetStudyByName(const std::string& theStudyName) = 0; - virtual _PTR(Study) GetStudyByID(int theStudyID) = 0; - virtual bool CanCopy(const _PTR(SObject)& theSO) = 0; - virtual bool Copy(const _PTR(SObject)& theSO) = 0; - virtual bool CanPaste(const _PTR(SObject)& theSO) = 0; - virtual _PTR(SObject) Paste(const _PTR(SObject)& theSO) = 0; -}; - -#endif diff --git a/src/SALOMEDSImpl/CMakeLists.txt b/src/SALOMEDSImpl/CMakeLists.txt index 5038a832a..f2feb6670 100755 --- a/src/SALOMEDSImpl/CMakeLists.txt +++ b/src/SALOMEDSImpl/CMakeLists.txt @@ -84,7 +84,6 @@ SET(SalomeDSImpl_SOURCES SALOMEDSImpl_SComponentIterator.cxx SALOMEDSImpl_StudyBuilder.cxx SALOMEDSImpl_Study.cxx - SALOMEDSImpl_StudyManager.cxx SALOMEDSImpl_IParameters.cxx SALOMEDSImpl_TMPFile.cxx SALOMEDSImpl_GenericVariable.cxx diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx index 93e7483b4..804218c12 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx @@ -87,8 +87,7 @@ public: int theObjectID, const SALOMEDSImpl_SObject& theObject) = 0; - virtual SALOMEDSImpl_TMPFile* DumpPython(SALOMEDSImpl_Study* theStudy, - bool isPublished, + virtual SALOMEDSImpl_TMPFile* DumpPython(bool isPublished, bool isMultiFile, bool& isValidScript, long& theStreamLength) = 0; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 5947c4030..4d26ae7a9 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -29,6 +29,9 @@ #include #include +#include + +#include "HDFexplorer.hxx" #include "DF_Application.hxx" #include "DF_ChildIterator.hxx" @@ -41,7 +44,9 @@ #include "SALOMEDSImpl_Tool.hxx" #include "SALOMEDSImpl_IParameters.hxx" #include "SALOMEDSImpl_ScalarVariable.hxx" +#include "SALOMEDSImpl_SComponent.hxx" +#include "HDFOI.hxx" #include #include #include @@ -54,20 +59,89 @@ #define FILEID "FILE: " #define VARIABLE_SEPARATOR ':' #define OPERATION_SEPARATOR '|' +#define USE_CASE_LABEL_ID "0:2" + +static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject); +static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* ); +static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*); +static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&, + SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII); +static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup); + +namespace { + class StudyUnlocker + { + public: + StudyUnlocker( SALOMEDSImpl_Study* study ): myStudy( study ), myLocked( false ) + { + myPrevLocked = myStudy->GetProperties()->IsLocked(); + resume(); + } + ~StudyUnlocker() + { + suspend(); + } + void suspend() + { + if (myLocked) { + myStudy->GetProperties()->SetLocked(true); + myPrevLocked = myLocked; + myLocked = false; + } + } + void resume() + { + if (myPrevLocked) { + myStudy->GetProperties()->SetLocked(false); + myLocked = myPrevLocked; + myPrevLocked = false; + } + } + private: + SALOMEDSImpl_Study* myStudy; + bool myLocked; + bool myPrevLocked; + }; +} //============================================================================ /*! Function : SALOMEDSImpl_Study * Purpose : SALOMEDSImpl_Study constructor */ //============================================================================ -SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc, - const std::string& study_name) +SALOMEDSImpl_Study::SALOMEDSImpl_Study() { - _name = study_name; - _doc = (DF_Document*)doc; + _appli = new DF_Application(); + _clipboard = _appli->NewDocument("SALOME_STUDY"); + + Init(); +} + +//============================================================================ +/*! Function : ~SALOMEDSImpl_Study + * Purpose : SALOMEDSImpl_Study destructor + */ +//============================================================================ +SALOMEDSImpl_Study::~SALOMEDSImpl_Study() +{ + Clear(); + _appli->Close(_clipboard); + // Destroy application + delete _appli; +} + +//============================================================================ +/*! Function : Init + * Purpose : Initialize study components + */ +//============================================================================ +void SALOMEDSImpl_Study::Init() +{ + static int _id = 0; + _name = "Study" + std::to_string(++_id); + _doc = _appli->NewDocument("SALOME_STUDY"); _Saved = false ; _URL = ""; - _StudyId = -1; _autoFill = false; _errorCode = ""; _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc); @@ -78,19 +152,1059 @@ SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc, //Put on the root label a StudyHandle attribute to store the address of this object //It will be used to retrieve the study object by DF_Label that belongs to the study SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this); -} + // set Study properties + SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties(); + + int month=0,day=0,year=0,hh=0,mn=0,ss=0; + SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss); + aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(), + mn, hh, day, month, year); + aProp->SetCreationMode(1); //"from scratch" +} //============================================================================ -/*! Function : ~SALOMEDSImpl_Study - * Purpose : SALOMEDSImpl_Study destructor +/*! Function : Clear + * Purpose : Clear study components */ //============================================================================ -SALOMEDSImpl_Study::~SALOMEDSImpl_Study() +void SALOMEDSImpl_Study::Clear() { delete _builder; delete _cb; delete _useCaseBuilder; + _appli->Close(_doc); + _doc = NULL; + _mapOfSO.clear(); + _mapOfSCO.clear(); +} + +//============================================================================ +/*! Function : Open + * Purpose : Open a Study from it's persistent reference + */ +//============================================================================ +bool SALOMEDSImpl_Study::Open(const std::string& aUrl) +{ + Clear(); + Init(); + // Set "C" locale temporarily to avoid possible localization problems + Kernel_Utils::Localizer loc; + + _errorCode = ""; + + // open the HDFFile + HDFfile *hdf_file =0; + HDFgroup *hdf_group_study_structure =0; + HDFgroup *hdf_notebook_vars = 0; + + char* aC_HDFUrl; + std::string aHDFUrl; + bool isASCII = false; + if (HDFascii::isASCII(aUrl.c_str())) { + isASCII = true; + char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.c_str()); + if ( !aResultPath ) + return NULL; + aC_HDFUrl = new char[strlen(aResultPath) + 19]; + sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath); + delete [] (aResultPath); + aHDFUrl = aC_HDFUrl; + delete [] aC_HDFUrl; + } + else { + aHDFUrl = aUrl; + } + + hdf_file = new HDFfile((char*)aHDFUrl.c_str()); + try { + hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too + } + catch (HDFexception) + { + char *eStr; + eStr = new char[strlen(aUrl.c_str())+17]; + sprintf(eStr,"Can't open file %s",aUrl.c_str()); + delete [] eStr; + _errorCode = std::string(eStr); + return NULL; + } + + // Assign the value of the URL in the study object + URL(aUrl); + + SALOMEDSImpl_AttributePersistentRef::Set(_doc->Main(), aUrl); + + if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) { + _errorCode = "Study is empty"; + return false; + } + + //Create the Structure of the Document + hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); + + try { + BuildTree (this, hdf_group_study_structure); + } + catch (HDFexception) + { + char *eStr = new char [strlen(aUrl.c_str())+17]; + sprintf(eStr,"Can't open file %s", aUrl.c_str()); + _errorCode = std::string(eStr); + return false; + } + + //Read and create notebook variables + if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) { + hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file); + ReadNoteBookVariables(this, hdf_notebook_vars); + hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor + } + + hdf_file->CloseOnDisk(); + hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); + + if (isASCII) { + std::vector aFilesToRemove; + aFilesToRemove.push_back("hdf_from_ascii.hdf"); + SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true); + } + + delete hdf_file; // all related hdf objects will be deleted + + // unlock study if it is locked, to set components versions + StudyUnlocker unlock(this); + + //For old studies we have to add "unknown" version tag for all stored components + SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator(); + for (; itcomponent.More(); itcomponent.Next()) + { + SALOMEDSImpl_SComponent sco = itcomponent.Value(); + std::string aCompType = sco.GetComment(); + if ( aCompType == SALOMEDSImpl_IParameters::getDefaultVisualComponent() ) continue; + if ( GetProperties()->GetComponentVersions( aCompType ).empty() ) + GetProperties()->SetComponentVersion( aCompType, "" ); // empty version means "unknown" + } + + return true; +} + +//============================================================================ +/*! Function : Save + * Purpose : Save a Study to it's persistent reference + */ +//============================================================================ +bool SALOMEDSImpl_Study::Save(SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile) +{ + _errorCode = ""; + + std::string url = URL(); + if (url.empty()) { + _errorCode = "No path specified to save the study. Nothing done"; + return false; + } + else { + return Impl_SaveAs(url, aFactory, theMultiFile, false); + } + + return false; +} + +bool SALOMEDSImpl_Study::SaveASCII(SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile) +{ + _errorCode = ""; + + std::string url = URL(); + if (url.empty()) { + _errorCode = "No path specified to save the study. Nothing done"; + return false; + } + else { + return Impl_SaveAs(url, aFactory, theMultiFile, true); + } + + return false; +} + +//============================================================================= +/*! Function : SaveAs + * Purpose : Save a study to the persistent reference aUrl + */ +//============================================================================ +bool SALOMEDSImpl_Study::SaveAs(const std::string& aUrl, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile) +{ + _errorCode = ""; + return Impl_SaveAs(aUrl, aFactory, theMultiFile, false); +} + +bool SALOMEDSImpl_Study::SaveAsASCII(const std::string& aUrl, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile) +{ + _errorCode = ""; + return Impl_SaveAs(aUrl, aFactory, theMultiFile, true); +} + +//============================================================================= +/*! Function : _SaveProperties + * Purpose : save the study properties in HDF file + */ +//============================================================================ +bool SALOMEDSImpl_Study::Impl_SaveProperties(HDFgroup *hdf_group) +{ + _errorCode = ""; + + HDFdataset *hdf_dataset = 0; + hdf_size size[1]; + hdf_int32 name_len; + + // add modifications list (user and date of save) + SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties(); + + // unlock study if it is locked, to set modification date + StudyUnlocker unlock(this); + + int month=0,day=0,year=0,hh=0,mn=0,ss=0; + SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss); + aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(), + mn, hh, day, month, year); + + // lock study back if it was locked initially, to write correct value of Locked flag + unlock.suspend(); + + std::vector aNames; + std::vector aMinutes, aHours, aDays, aMonths, aYears; + + aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears); + + std::string units = aProp->GetUnits(); + std::string comment = aProp->GetComment(); + + std::map< std::string, std::vector > allVersions = aProp->GetComponentsVersions(); + std::map versions; + + int aLength = 0, aLength1 = 0, anIndex, i, unitsSize = 0, commentSize = 0; + + for(i=1; i<=aNames.size(); i++) + aLength += aNames[i-1].size() + 1; + + std::map< std::string, std::vector >::const_iterator it; + for (it = allVersions.begin(); it != allVersions.end(); ++it ) { + std::string vlist = ""; + std::vector vl = it->second; + std::vector::const_iterator vlit; + for ( vlit = vl.begin(); vlit != vl.end(); ++vlit ) { + if ( vlist != "" ) vlist += ";"; + vlist += *vlit; + } + versions[ it->first ] = vlist; + aLength1 += it->first.size() + vlist.size() + 2; + } + + unitsSize = units.size(); + commentSize = comment.size(); + + //string format: + //locked flag, modified flag, + //minutes, hours, day, months, year, user name, char(1), + //minutes, hours, day, months, year, user name, char(1), + //....................................................., + //....................................................., + //....................................................., + //minutes, hours, day, months, year, user name, char(1), char(30) <- !!!! used to define end of section with modifications !!!! + //units, char(1), comment, char(30) <- !!!! used to define start of section with components' versions !!!! + //component=versions, char(1), + //component=versions, char(1), + //..........................., + //component=versions, char(1), char(0) + + //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, 1 byte (char(30) section delimeter) + // unit length + 1, comment length, "zero" byte + + char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize + 1 + aLength1 ]; + + sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u'); + + aLength = aNames.size(); + int a = 2; + for(anIndex = 0; anIndex 0) { + sprintf(&(aProperty[a]),"%s",units.c_str()); + a = strlen(aProperty); + } + + aProperty[a++] = 1; + + //Write comments if need + if(comment.size() > 0) { + sprintf(&(aProperty[a]),"%s",comment.c_str()); + a = strlen(aProperty); + } + + aProperty[a++] = 30; //delimeter of the component versions + + std::map::const_iterator versionsIt; + for ( versionsIt = versions.begin(); versionsIt != versions.end(); ++versionsIt ) { + sprintf(&(aProperty[a]),"%s=%s", + (char*)(versionsIt->first.c_str()), + (char*)(versionsIt->second.c_str())); + a = a + versionsIt->first.size() + versionsIt->second.size() + 1; + aProperty[a++] = 1; + } + + aProperty[a] = 0; + + name_len = (hdf_int32) a; + size[0] = name_len + 1 ; + hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk(aProperty); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + delete [] aProperty; + + aProp->SetModified(0); + return true; +} + +//============================================================================= +/*! Function : _SaveAs + * Purpose : save the study in HDF file + */ +//============================================================================ +bool SALOMEDSImpl_Study::Impl_SaveAs(const std::string& aStudyUrl, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile, + bool theASCII) +{ + // Set "C" locale temporarily to avoid possible localization problems + Kernel_Utils::Localizer loc; + + // HDF File will be composed of differents part : + // * For each ComponentDataType, all data created by the component + // Informations in data group hdf_group_datacomponent + // * Study Structure -> Exactly what is contained in Document + // Informations in data group hdf_group_study_structure + + _errorCode = ""; + + HDFfile *hdf_file=0; + HDFgroup *hdf_group_study_structure =0; + HDFgroup *hdf_sco_group =0; + HDFgroup *hdf_sco_group2 =0; + HDFgroup *hdf_notebook_vars =0; + HDFgroup *hdf_notebook_var = 0; + + HDFgroup *hdf_group_datacomponent =0; + HDFdataset *hdf_dataset =0; + hdf_size size[1]; + hdf_int32 name_len = 0; + std::string component_name; + + // Store previous URL + std::string anOldName = Name(); + + // Map to store components' versions + std::map componentVersions; + + //Create a temporary url to which the study is saved + std::string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl); + + // unlock study if it is locked, as some attributes need to be modified + StudyUnlocker unlock(this); + + SALOMEDSImpl_StudyBuilder* SB= NewBuilder(); + std::map aMapTypeDriver; + + try { + // mpv 15.12.2003: for saving components we have to load all data from all modules + SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator(); + for (; itcomponent.More(); itcomponent.Next()) { + SALOMEDSImpl_SComponent sco = itcomponent.Value(); + // if there is an associated Engine call its method for saving + std::string IOREngine; + try { + SALOMEDSImpl_Driver* aDriver = NULL; + std::string aCompType = sco.GetComment(); + if (!sco.ComponentIOR(IOREngine)) { + if (!aCompType.empty()) { + aDriver = aFactory->GetDriverByType(aCompType); + if (aDriver != NULL) { + if (!SB->LoadWith(sco, aDriver)) { + _errorCode = SB->GetErrorCode(); + return false; + } + } + } + } + else { + aDriver = aFactory->GetDriverByIOR(IOREngine); + } + aMapTypeDriver[aCompType] = aDriver; + } + catch(...) { + _errorCode = "Can not restore information to resave it"; + return false; + } + } + + // VSR: set URL to new file name + // VSR: remember to set previous name if save operation fails + URL(aStudyUrl); + + // To change for Save + // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything?? + hdf_file = new HDFfile((char*)aUrl.c_str()); + hdf_file->CreateOnDisk(); + + //----------------------------------------------------------------------- + // 1 - Create a groupe for each SComponent and Update the PersistanceRef + //----------------------------------------------------------------------- + hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file); + hdf_group_datacomponent->CreateOnDisk(); + + for (itcomponent.Init(); itcomponent.More(); itcomponent.Next()) { + SALOMEDSImpl_SComponent sco = itcomponent.Value(); + + std::string scoid = sco.GetID(); + hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent); + hdf_sco_group->CreateOnDisk(); + + std::string componentDataType = sco.ComponentDataType(); + std::string IOREngine; + if (sco.ComponentIOR(IOREngine)) { + // Engine should be already in the map as it was to added before + SALOMEDSImpl_Driver* Engine = aMapTypeDriver[componentDataType]; + if (Engine != NULL) { + SALOMEDSImpl_TMPFile* aStream = NULL; + long length = 0; + + componentVersions[ componentDataType ] = Engine->Version(); + + if (theASCII) aStream = Engine->SaveASCII(sco, + SALOMEDSImpl_Tool::GetDirFromPath(aUrl), + length, + theMultiFile); + else aStream = Engine->Save(sco, + SALOMEDSImpl_Tool::GetDirFromPath(aUrl), + length, + theMultiFile); + HDFdataset *hdf_dataset; + hdf_size aHDFSize[1]; + if (length > 0) { //The component saved some auxiliary files, then put them into HDF file + aHDFSize[0] = length; + + HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file + hdf_dataset->CloseOnDisk(); + } + + if (aStream) delete aStream; + + // store multifile state + aHDFSize[0] = 2; + hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor + // store ASCII state + aHDFSize[0] = 2; + hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor + // Creation of the persistance reference attribute + Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII); + } + } + hdf_sco_group->CloseOnDisk(); + hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor + } + hdf_group_datacomponent->CloseOnDisk(); + hdf_group_datacomponent =0; // will be deleted by hdf_file destructor + + //----------------------------------------------------------------------- + //3 - Write the Study Structure + //----------------------------------------------------------------------- + hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); + hdf_group_study_structure->CreateOnDisk(); + // save component attributes + for (itcomponent.Init(); itcomponent.More(); itcomponent.Next()) { + SALOMEDSImpl_SComponent SC = itcomponent.Value(); + std::string scid = SC.GetID(); + hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure); + hdf_sco_group2->CreateOnDisk(); + SaveAttributes(SC, hdf_sco_group2); + // ComponentDataType treatment + component_name = SC.ComponentDataType(); + name_len = (hdf_int32)component_name.length(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)component_name.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + Impl_SaveObject(SC, hdf_sco_group2); + hdf_sco_group2->CloseOnDisk(); + hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor + } + //----------------------------------------------------------------------- + //4 - Write the Study UseCases Structure + //----------------------------------------------------------------------- + SALOMEDSImpl_SObject aSO = FindObjectID(USE_CASE_LABEL_ID); + if (aSO) { + HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure); + hdf_soo_group->CreateOnDisk(); + SaveAttributes(aSO, hdf_soo_group); + Impl_SaveObject(aSO, hdf_soo_group); + hdf_soo_group->CloseOnDisk(); + hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor + } + //----------------------------------------------------------------------- + //5 - Write the NoteBook Variables + //----------------------------------------------------------------------- + + //5.1 Create group to store all note book variables + hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file); + hdf_notebook_vars->CreateOnDisk(); + + std::string varValue; + std::string varType; + std::string varIndex; + + for (int i=0 ;i < myNoteBookVars.size(); i++ ) { + // For each variable create HDF group + hdf_notebook_var = new HDFgroup((char*)myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars); + hdf_notebook_var->CreateOnDisk(); + + // Save Variable type + varType = myNoteBookVars[i]->SaveType(); + name_len = (hdf_int32) varType.length(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)varType.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + + char buffer[256]; + sprintf(buffer,"%d",i); + varIndex= std::string(buffer); + name_len = (hdf_int32) varIndex.length(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)varIndex.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + + // Save Variable value + varValue = myNoteBookVars[i]->Save(); + name_len = (hdf_int32) varValue.length(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)varValue.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + hdf_notebook_var->CloseOnDisk(); + hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor + } + hdf_notebook_vars->CloseOnDisk(); + hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor + + // record component versions + std::map::const_iterator itVersions; + for ( itVersions = componentVersions.begin(); itVersions != componentVersions.end(); ++itVersions ) + GetProperties()->SetComponentVersion( itVersions->first, itVersions->second ); + + // lock study back if it was locked initially, to write correct value of Locked flag + unlock.suspend(); + + //----------------------------------------------------------------------- + //6 - Write the Study Properties + //----------------------------------------------------------------------- + std::string study_name = Name(); + name_len = (hdf_int32) study_name.size(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)study_name.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor + + Impl_SaveProperties(hdf_group_study_structure); + hdf_group_study_structure->CloseOnDisk(); + hdf_file->CloseOnDisk(); + + hdf_group_study_structure =0; // will be deleted by hdf_file destructor + delete hdf_file; // recursively deletes all hdf objects... + } + catch (HDFexception) { + _errorCode = "HDFexception ! "; + URL( anOldName ); // VSR: restore previous url if operation is failed + return false; + } + catch (std::exception& exc) { + _errorCode = const_cast(exc.what()); + URL( anOldName ); // VSR: restore previous url if operation is failed + return false; + } + catch (...) { + _errorCode = "Unknown exception ! "; + URL( anOldName ); // VSR: restore previous url if operation is failed + return false; + } + if (theASCII) { // save file in ASCII format + HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true); + } + + // Now it's necessary to copy files from the temporary directory to the user defined directory. + // The easiest way to get a list of file in the temporary directory + + std::string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir(); + std::string aTmpFile = aTmpFileDir +"files"; + std::string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl); + +#ifdef WIN32 + aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile; +#else + aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile; +#endif + system(aCmd.c_str()); + + // Iterate and move files in the temporary directory + FILE* fp = fopen(aTmpFile.c_str(), "rb"); + if (!fp) { + URL( anOldName ); // VSR: restore previous url if operation is failed + return false; + } + char* buffer = new char[2047]; + int errors = 0; + while (!feof(fp) && !errors) { + if ((fgets(buffer, 2046, fp)) == NULL) break; + size_t aLen = strlen(buffer); + if (buffer[aLen-1] == '\n') buffer[aLen-1] = char(0); +#ifdef WIN32 + aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\""; +#else + aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\""; +#endif + errors = system(aCmd.c_str()); + } + + delete []buffer; + fclose(fp); + + // Perform cleanup +#ifdef WIN32 + DeleteFileA(aTmpFile.c_str()); +#else + unlink(aTmpFile.c_str()); +#endif + +#ifdef WIN32 + RemoveDirectoryA(aTmpFileDir.c_str()); + RemoveDirectoryA(aStudyTmpDir.c_str()); +#else + rmdir(aTmpFileDir.c_str()); + rmdir(aStudyTmpDir.c_str()); +#endif + + if ( !errors ) { + // VSR: finally, if all is done without errors, mark study as Saved + IsSaved(true); + } + + return !errors; +} + +//============================================================================ +/*! Function : Impl_SaveObject + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::Impl_SaveObject(const SALOMEDSImpl_SObject& SC, + HDFgroup *hdf_group_datatype) +{ + _errorCode = ""; + + // Write in group hdf_group_datatype all informations of SObject SC + // Iterative function to parse all SObjects under a SComponent + + HDFgroup *hdf_group_sobject = 0; + + DF_ChildIterator itchild(SC.GetLabel()); + for (; itchild.More(); itchild.Next()) { + // mpv: don't save empty labels + std::vector attr = itchild.Value().GetAttributes(); + if (attr.size() == 0) { //No attributes on the label + DF_ChildIterator subchild(itchild.Value()); + if (!subchild.More()) { + continue; + } + subchild.Init(itchild.Value(), true); + bool anEmpty = true; + for (; subchild.More() && anEmpty; subchild.Next()) { + std::vector attr2 = subchild.Value().GetAttributes(); + if (attr2.size()) { + anEmpty = false; //There are attributes on the child label + break; + } + } + if (anEmpty) continue; + } + + SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value()); + + std::string scoid = SO.GetID(); + hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype); + hdf_group_sobject->CreateOnDisk(); + SaveAttributes(SO, hdf_group_sobject); + Impl_SaveObject(SO, hdf_group_sobject); + hdf_group_sobject->CloseOnDisk(); + hdf_group_sobject =0; // will be deleted by father hdf object destructor + } + return true; +} + +//============================================================================ +/*! Function : CanCopy + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::CanCopy(const SALOMEDSImpl_SObject& theObject, + SALOMEDSImpl_Driver* theEngine) +{ + _errorCode = ""; + SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent(); + if (!aComponent) return false; + if (aComponent.GetLabel() == theObject.GetLabel()) return false; + std::string IOREngine; + if (!aComponent.ComponentIOR(IOREngine)) return false; + if (theEngine == NULL) return false; + return theEngine->CanCopy(theObject); +} + +//============================================================================ +/*! Function : CopyLabel + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::CopyLabel(SALOMEDSImpl_Driver* theEngine, + const int theSourceStartDepth, + const DF_Label& theSource, + const DF_Label& theDestinationMain) +{ + _errorCode = ""; + + int a; + DF_Label aTargetLabel = theDestinationMain; + DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2); + for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) { + DF_Label aSourceLabel = theSource; + for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father(); + aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag()); + aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag()); + } + // iterate attributes + std::vector attrList = theSource.GetAttributes(); + for(int i = 0, len = attrList.size(); i(anAttr)->Get(); + std::string anEntry = aReferenced.Entry(); + // store the value of name attribute of referenced label + SALOMEDSImpl_AttributeName* aNameAttribute; + if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) { + anEntry += " "; + anEntry += aNameAttribute->Value(); + } + SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry); + continue; + } + + if (type == std::string("AttributeIOR")) { // IOR => ID and TMPFile of Engine + std::string anEntry = theSource.Entry(); + SALOMEDSImpl_SObject aSO = FindObjectID(anEntry); + int anObjID; + long aLen; + SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen); + std::string aResStr(""); + for(a = 0; a < aLen; a++) { + aResStr += (char)(aStream->Get(a)); + } + + if(aStream) delete aStream; + + SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID); + SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr); + continue; + } + DF_Attribute* aNewAttribute = anAttr->NewEmpty(); + aTargetLabel.AddAttribute(aNewAttribute); + anAttr->Paste(aNewAttribute); + } + + return true; +} + +//============================================================================ +/*! Function : Copy + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::Copy(const SALOMEDSImpl_SObject& theObject, + SALOMEDSImpl_Driver* theEngine) +{ + _errorCode = ""; + + // adoptation for alliances datamodel copy: without IOR attributes !!! + bool aStructureOnly; // copy only SObjects and attributes without component help + aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID()); + + // get component-engine + SALOMEDSImpl_Study* aStudy = theObject.GetStudy(); + + if (!_doc) { + _errorCode = "Document is null"; + return false; + } + + //Clear the clipboard + _clipboard->Main().Root().ForgetAllAttributes(true); + _appli->Close(_clipboard); + _clipboard = _appli->NewDocument("SALOME_STUDY"); + + // set component data type to the name attribute of root label + if (!aStructureOnly) { + SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(), + theEngine->ComponentDataType()); + } + // iterate all theObject's label children + DF_Label aStartLabel = theObject.GetLabel(); + int aSourceStartDepth = aStartLabel.Depth(); + + // copy main source label + CopyLabel(theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main()); + + // copy all subchildren of the main source label (all levels) + DF_ChildIterator anIterator(aStartLabel, true); + for(; anIterator.More(); anIterator.Next()) { + CopyLabel(theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main()); + } + + return true; +} + +//============================================================================ +/*! Function : CanPaste + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::CanPaste(const SALOMEDSImpl_SObject& theObject, + SALOMEDSImpl_Driver* theEngine) +{ + _errorCode = ""; + + if (!_clipboard) { + _errorCode = "Clipboard is null"; + return false; + } + + SALOMEDSImpl_AttributeComment* aCompName = NULL; + if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) { + _errorCode = "Clipboard has no component type"; + return false; + } + SALOMEDSImpl_AttributeInteger* anObjID; + if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) { + _errorCode = "Clipboard has no object id"; + return false; + } + SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent(); + if (!aComponent) { + _errorCode = "Object doesn't belong to component"; + return false; + } + + std::string IOREngine; + if (!aComponent.ComponentIOR(IOREngine)) { + _errorCode = "component has no IOR"; + return false; + } + return theEngine->CanPaste(aCompName->Value(), anObjID->Value()); +} + +//============================================================================ +/*! Function : PasteLabel + * Purpose : + */ +//============================================================================ +DF_Label SALOMEDSImpl_Study::PasteLabel(SALOMEDSImpl_Driver* theEngine, + const DF_Label& theSource, + const DF_Label& theDestinationStart, + const bool isFirstElement) +{ + _errorCode = ""; + + // get corresponding source, target and auxiliary labels + DF_Label aTargetLabel = theDestinationStart; + + DF_Label aAuxSourceLabel = theSource.Root().FindChild(2); + int a; + if (!isFirstElement) { + for(a = theSource.Depth() - 1; a > 0 ; a--) { + DF_Label aSourceLabel = theSource; + for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father(); + aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag()); + aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag()); + } + SALOMEDSImpl_SObject so = GetSObject(aTargetLabel); + addSO_Notification(so); + } + + // check auxiliary label for TMPFile => IOR + SALOMEDSImpl_AttributeName* aNameAttribute = NULL; + if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) { + SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()); + SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()); + std::string aCompName = aComponentName->Value(); + + if (theEngine->CanPaste(aCompName, anObjID->Value())) { + std::string aTMPStr = aNameAttribute->Value(); + int aLen = aTMPStr.size(); + unsigned char* aStream = NULL; + if(aLen > 0) { + aStream = new unsigned char[aLen+10]; + for(a = 0; a < aLen; a++) { + aStream[a] = aTMPStr[a]; + } + } + + std::string anEntry = aTargetLabel.Entry(); + SALOMEDSImpl_SObject aPastedSO = FindObjectID(anEntry); + + if (isFirstElement) { + std::string aDestEntry = theEngine->PasteInto(aStream, + aLen, + anObjID->Value(), + aPastedSO.GetFatherComponent()); + aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry); + } else + theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO); + + if(aStream != NULL) delete []aStream; + } + } + + // iterate attributes + std::vector attrList = theSource.GetAttributes(); + for(int i = 0, len = attrList.size(); iID())) { + aTargetLabel.ForgetAttribute(anAttr->ID()); + } + DF_Attribute* aNewAttribute = anAttr->NewEmpty(); + aTargetLabel.AddAttribute(aNewAttribute); + anAttr->Paste(aNewAttribute); + } + + // check auxiliary label for Comment => reference or name attribute of the referenced object + SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL; + if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) { + char * anEntry = new char[aCommentAttribute->Value().size() + 1]; + strcpy(anEntry, std::string(aCommentAttribute->Value()).c_str()); + char* aNameStart = strchr(anEntry, ' '); + if (aNameStart) { + *aNameStart = '\0'; + aNameStart++; + } + // copy to the same study, reanimate reference + DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry); + SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel); + // target attributes structure support + SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel)); + + delete [] anEntry; + } + + return aTargetLabel; +} + +//============================================================================ +/*! Function : Paste + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SObject SALOMEDSImpl_Study::Paste(const SALOMEDSImpl_SObject& theObject, + SALOMEDSImpl_Driver* theEngine) +{ + _errorCode = ""; + + SALOMEDSImpl_SObject so; + + // if study is locked, then paste can't be done + if (GetProperties()->IsLocked()) { + _errorCode = "LockProtection"; + throw LockProtection("LockProtection"); + } + + // if there is no component name, then paste only SObjects and attributes: without component help + SALOMEDSImpl_AttributeComment* aComponentName = NULL; + bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID())); + + // CAF document of current study usage + if (!_doc) { + _errorCode = "Document is null"; + return so; + } + + SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent(); + + // fill root inserted SObject + DF_Label aStartLabel; + if (aStructureOnly) { + DF_Label anObjectLabel = DF_Label::Label(_doc->Main(), theObject.GetID()); + aStartLabel = PasteLabel(theEngine, _clipboard->Main(), anObjectLabel, false); + } else { + DF_Label aComponentLabel = DF_Label::Label(_doc->Main(), aComponent.GetID()); + aStartLabel = PasteLabel(theEngine, _clipboard->Main(), aComponentLabel, true); + } + + // paste all sublebels + DF_ChildIterator anIterator(_clipboard->Main(), true); + for(; anIterator.More(); anIterator.Next()) { + PasteLabel(theEngine, anIterator.Value(), aStartLabel, false); + } + + return SALOMEDSImpl_Study::SObject(aStartLabel); } //============================================================================ @@ -733,18 +1847,7 @@ SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder() std::string SALOMEDSImpl_Study::Name() { _errorCode = ""; - return _name; -} - -//============================================================================ -/*! Function : Name - * Purpose : set study name - */ -//============================================================================ -void SALOMEDSImpl_Study::Name(const std::string& name) -{ - _errorCode = ""; - _name = name; + return Kernel_Utils::GetBaseName( _name, false ); } //============================================================================ @@ -793,6 +1896,8 @@ bool SALOMEDSImpl_Study::IsModified() std::string SALOMEDSImpl_Study::URL() { _errorCode = ""; + if ( _URL.empty() ) + return Kernel_Utils::AddExtension( _name ); return _URL; } @@ -805,6 +1910,7 @@ void SALOMEDSImpl_Study::URL(const std::string& url) { _errorCode = ""; _URL = url; + _name = url; /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study std::string tmp(_URL); @@ -817,7 +1923,6 @@ void SALOMEDSImpl_Study::URL(const std::string& url) adr = strtok(NULL, "/"); } Name(aName);*/ - Name(url); } @@ -955,18 +2060,6 @@ bool SALOMEDSImpl_Study::IsLocked() return GetProperties()->IsLocked(); } -int SALOMEDSImpl_Study::StudyId() -{ - _errorCode = ""; - return _StudyId; -} - -void SALOMEDSImpl_Study::StudyId(int id) -{ - _errorCode = ""; - _StudyId = id; -} - void SALOMEDSImpl_Study::UpdateIORLabelMap(const std::string& anIOR,const std::string& anEntry) { _errorCode = ""; @@ -1085,23 +2178,6 @@ SALOMEDSImpl_UseCaseBuilder* SALOMEDSImpl_Study::GetUseCaseBuilder() return _useCaseBuilder; } - -//============================================================================ -/*! Function : Close - * Purpose : - */ -//============================================================================ -void SALOMEDSImpl_Study::Close() -{ - _errorCode = ""; - _notifier = 0; - _doc->GetApplication()->Close(_doc); - _doc = NULL; - _mapOfSO.clear(); - _mapOfSCO.clear(); -} - - //============================================================================ /*! Function : GetSComponent * Purpose : @@ -1356,7 +2432,7 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, bool isValidScript; long aStreamLength = 0; - SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isMultiFile, isValidScript, aStreamLength); + SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(isPublished, isMultiFile, isValidScript, aStreamLength); if ( !isValidScript ) isOk = false; @@ -2165,3 +3241,213 @@ void SALOMEDSImpl_Study::UnRegisterGenObj(const std::string& theIOR, DF_Label la if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() )) goRegister->UnRegisterGenObj( theIOR ); } + +//####################################################################################################### +//# STATIC PRIVATE FUNCTIONS +//####################################################################################################### + +//============================================================================ +/*! Function : SaveAttributes + * Purpose : Save attributes for object + */ +//============================================================================ +static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject) +{ + hdf_size size[1]; + std::vector attrList = aSO.GetLabel().GetAttributes(); + DF_Attribute* anAttr = NULL; + for(int i = 0, len = attrList.size(); iSave(); + //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl; + size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1; + HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + } +} + +//=========================================================================== +//Function : ReadAttributes +//=========================================================================== +static void ReadAttributes(SALOMEDSImpl_Study* theStudy, + const SALOMEDSImpl_SObject& aSO, + HDFdataset* hdf_dataset) +{ + hdf_dataset->OpenOnDisk(); + + DF_Attribute* anAttr = NULL; + char* current_string = new char[hdf_dataset->GetSize()+1]; + hdf_dataset->ReadFromDisk(current_string); + //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl; + if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) { + anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment"); + } + else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") || + !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance + theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string)); + delete [] (current_string); + hdf_dataset->CloseOnDisk(); + return; + } + else { + anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName()); + } + + if (anAttr) { + anAttr->Load(current_string); + } + + delete [] (current_string); + hdf_dataset->CloseOnDisk(); +} + +//============================================================================ +//Function : BuildlTree +//============================================================================ +static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group) +{ + hdf_current_group->OpenOnDisk(); + SALOMEDSImpl_SObject aSO; + char* Entry = hdf_current_group->GetName(); + if (strcmp(Entry,"STUDY_STRUCTURE") == 0) { + aSO = theStudy->CreateObjectID("0:1"); + } + else { + aSO = theStudy->CreateObjectID(Entry); + } + + char name[HDF_NAME_MAX_LEN+1]; + int nbsons = hdf_current_group->nInternalObjects(); + for (int i=0; iInternalObjectIndentify(i,name); + if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue; + hdf_object_type type = hdf_current_group->InternalObjectType(name); + + if (type == HDF_DATASET) { + HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group); + ReadAttributes(theStudy,aSO,new_dataset); + new_dataset = 0; // will be deleted by father destructor + } + else if (type == HDF_GROUP) { + HDFgroup* new_group = new HDFgroup(name,hdf_current_group); + BuildTree (theStudy, new_group); + new_group = 0; // will be deleted by father destructor + } + } + hdf_current_group->CloseOnDisk(); +} + + +//============================================================================ +//Function : Translate_IOR_to_persistentID +//============================================================================ +static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so, + SALOMEDSImpl_Driver* engine, + bool isMultiFile, + bool isASCII) +{ + DF_ChildIterator itchild(so.GetLabel()); + std::string ior_string, persistent_string, curid; + + for (; itchild.More(); itchild.Next()) { + SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value()); + SALOMEDSImpl_AttributeIOR* IOR = NULL; + if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) { + ior_string = IOR->Value(); + + persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII); + SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string); + } + Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII); + } +} + +void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup) +{ + if(!theGroup) + return; + + HDFgroup* new_group =0; + HDFdataset* new_dataset =0; + + char aVarName[HDF_NAME_MAX_LEN+1]; + char *currentVarType = 0; + char *currentVarValue = 0; + char *currentVarIndex = 0; + int order = 0; + //Open HDF group with notebook variables + theGroup->OpenOnDisk(); + + //Get Nb of variables + int aNbVars = theGroup->nInternalObjects(); + + std::map aVarsMap; + + for( int iVar=0;iVar < aNbVars;iVar++ ) { + theGroup->InternalObjectIndentify(iVar,aVarName); + hdf_object_type type = theGroup->InternalObjectType(aVarName); + if(type == HDF_GROUP) { + + //Read Variable + new_group = new HDFgroup(aVarName,theGroup); + new_group->OpenOnDisk(); + + //Read Type + new_dataset = new HDFdataset("VARIABLE_TYPE",new_group); + new_dataset->OpenOnDisk(); + currentVarType = new char[new_dataset->GetSize()+1]; + new_dataset->ReadFromDisk(currentVarType); + new_dataset->CloseOnDisk(); + new_dataset = 0; //will be deleted by hdf_sco_group destructor + + //Read Order + if(new_group->ExistInternalObject("VARIABLE_INDEX")) { + new_dataset = new HDFdataset("VARIABLE_INDEX",new_group); + new_dataset->OpenOnDisk(); + currentVarIndex = new char[new_dataset->GetSize()+1]; + new_dataset->ReadFromDisk(currentVarIndex); + new_dataset->CloseOnDisk(); + new_dataset = 0; //will be deleted by hdf_sco_group destructor + order = atoi(currentVarIndex); + delete [] currentVarIndex; + } + else + order = iVar; + + //Read Value + new_dataset = new HDFdataset("VARIABLE_VALUE",new_group); + new_dataset->OpenOnDisk(); + currentVarValue = new char[new_dataset->GetSize()+1]; + new_dataset->ReadFromDisk(currentVarValue); + new_dataset->CloseOnDisk(); + new_dataset = 0; //will be deleted by hdf_sco_group destructor + + new_group->CloseOnDisk(); + new_group = 0; //will be deleted by hdf_sco_group destructor + + SALOMEDSImpl_GenericVariable::VariableTypes aVarType = + SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType)); + delete [] currentVarType; + + //Create variable and add it in the study + SALOMEDSImpl_GenericVariable* aVariable = + new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName)); + aVariable->Load(std::string(currentVarValue)); + aVarsMap.insert(std::make_pair(order,aVariable)); + delete [] currentVarValue; + } + } + + std::map::const_iterator it= aVarsMap.begin(); + for(;it!=aVarsMap.end();it++) + theStudy->AddVariable((*it).second); + + theGroup->CloseOnDisk(); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index a4a07b905..bd8f55faf 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -51,7 +51,7 @@ #include "SALOMEDSImpl_ChildIterator.hxx" #include "SALOMEDSImpl_GenericVariable.hxx" -class SALOMEDSImpl_StudyManager; +class HDFgroup; class SALOMEDSImpl_GenericAttribute; @@ -59,10 +59,11 @@ class SALOMEDSIMPL_EXPORT SALOMEDSImpl_Study { private: std::string _name; + DF_Application* _appli; DF_Document* _doc; // Document + DF_Document* _clipboard; bool _Saved; // True if the Study is saved std::string _URL; //URL of the persistent reference of the study - int _StudyId; DF_Label _current; bool _autoFill; std::string _errorCode; @@ -98,11 +99,58 @@ public: static void IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute); //! standard constructor - SALOMEDSImpl_Study(const DF_Document*, const std::string& study_name); + SALOMEDSImpl_Study(); //! standard destructor virtual ~SALOMEDSImpl_Study(); + virtual void Init(); + virtual void Clear(); + + //! method to Open a Study from it's persistent reference + virtual bool Open(const std::string& aStudyUrl); + + //! method to save a Study + virtual bool Save(SALOMEDSImpl_DriverFactory* aFactory, bool theMultiFile); + + virtual bool SaveASCII(SALOMEDSImpl_DriverFactory* aFactory, bool theMultiFile); + + //! method to save a Study to the persistent reference aUrl + virtual bool SaveAs(const std::string& aUrl, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile); + + virtual bool SaveAsASCII(const std::string& aUrl, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile); + + bool CopyLabel(SALOMEDSImpl_Driver* theEngine, + const int theSourceStartDepth, + const DF_Label& theSource, + const DF_Label& theDestinationMain); + + DF_Label PasteLabel(SALOMEDSImpl_Driver* theEngine, + const DF_Label& theSource, + const DF_Label& theDestinationStart, + const bool isFirstElement); + + virtual bool CanCopy(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine); + virtual bool Copy(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine); + virtual bool CanPaste(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine); + virtual SALOMEDSImpl_SObject Paste(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine); + + // _SaveAs private function called by Save and SaveAs + virtual bool Impl_SaveAs(const std::string& aUrl, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile, + bool theASCII); + + // _SaveObject private function called by _SaveAs + virtual bool Impl_SaveObject(const SALOMEDSImpl_SObject& SC, HDFgroup *hdf_group_datatype); + + virtual bool Impl_SaveProperties(HDFgroup *hdf_group); + + //! method to Get persistent reference of study (idem URL()) virtual std::string GetPersistentReference(); @@ -174,9 +222,6 @@ public: //! method to get study name virtual std::string Name(); - - //! method to set study name - virtual void Name(const std::string& name); //! method to get if study has been saved virtual bool IsSaved(); @@ -195,10 +240,6 @@ public: virtual bool IsLocked(); - virtual int StudyId(); - - virtual void StudyId(int id); - virtual void DeleteIORLabelMapItem(const std::string& anIOR); virtual void UpdateIORLabelMap(const std::string& anIOR, const std::string& aLabel); @@ -212,8 +253,6 @@ public: virtual SALOMEDSImpl_UseCaseBuilder* GetUseCaseBuilder(); - virtual void Close(); - void EnableUseCaseAutoFilling(bool isEnabled); virtual std::string GetErrorCode() { return _errorCode; } @@ -326,7 +365,6 @@ public: static void UnRegisterGenObj(const std::string& theIOR, DF_Label label); void setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister); - friend class SALOMEDSImpl_StudyManager; friend class SALOMEDSImpl_GenericAttribute; friend class SALOMEDSImpl_GenericVariable; }; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx deleted file mode 100644 index d05604ea5..000000000 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx +++ /dev/null @@ -1,1568 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : SALOMEDSImpl_StudyManager.cxx -// Author : Sergey RUIN -// Module : SALOME -// -#include "SALOMEDSImpl_StudyManager.hxx" - -#include "DF_ChildIterator.hxx" -#include "HDFexplorer.hxx" -#include "Basics_Utils.hxx" - -//Warning undef of Ascii Winwows define -#ifdef WIN32 -# undef GetUserName -#endif - -#include "SALOMEDSImpl_Attributes.hxx" -#include "SALOMEDSImpl_Tool.hxx" -#include "SALOMEDSImpl_SComponent.hxx" -#include "SALOMEDSImpl_GenericAttribute.hxx" -#include "SALOMEDSImpl_ScalarVariable.hxx" -#include "SALOMEDSImpl_IParameters.hxx" -#include - -#include "HDFOI.hxx" -#include -#include -#include - -#define USE_CASE_LABEL_ID "0:2" - -static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject); -static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* ); -static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*); -static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&, - SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII); -static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup); - -namespace { - class StudyUnlocker - { - public: - StudyUnlocker( SALOMEDSImpl_Study* study ): myStudy( study ), myLocked( false ) - { - myPrevLocked = myStudy->GetProperties()->IsLocked(); - resume(); - } - ~StudyUnlocker() - { - suspend(); - } - void suspend() - { - if (myLocked) { - myStudy->GetProperties()->SetLocked(true); - myPrevLocked = myLocked; - myLocked = false; - } - } - void resume() - { - if (myPrevLocked) { - myStudy->GetProperties()->SetLocked(false); - myLocked = myPrevLocked; - myPrevLocked = false; - } - } - private: - SALOMEDSImpl_Study* myStudy; - bool myLocked; - bool myPrevLocked; - }; -} - -//============================================================================ -/*! Function : SALOMEDSImpl_StudyManager - * Purpose : SALOMEDSImpl_StudyManager constructor - */ -//============================================================================ -SALOMEDSImpl_StudyManager::SALOMEDSImpl_StudyManager() -{ - _errorCode = ""; - _appli = new DF_Application(); - _IDcounter = 0; - _clipboard = _appli->NewDocument("SALOME_STUDY"); -} - -//============================================================================ -/*! Function : ~SALOMEDSImpl_StudyManager - * Purpose : SALOMEDSImpl_StudyManager destructor - */ -//============================================================================ -SALOMEDSImpl_StudyManager::~SALOMEDSImpl_StudyManager() -{ - _appli->Close(_clipboard); - // Destroy application - delete _appli; -} - - -//============================================================================ -/*! Function : NewStudy - * Purpose : Create a New Study of name study_name - */ -//==================================================T========================== -SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::NewStudy(const std::string& study_name) -{ - _errorCode = ""; - - DF_Document* Doc = _appli->NewDocument("SALOME_STUDY"); - - SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, study_name); - - _IDcounter++; - Study->StudyId( _IDcounter ); - - // set Study properties - SALOMEDSImpl_AttributeStudyProperties* aProp = Study->GetProperties(); - - int month=0,day=0,year=0,hh=0,mn=0,ss=0; - SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss); - aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(), - mn, hh, day, month, year); - aProp->SetCreationMode(1); //"from scratch" - - return Study; -} - -//============================================================================ -/*! Function : Open - * Purpose : Open a Study from it's persistent reference - */ -//============================================================================ -SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const std::string& aUrl) -{ - // Set "C" locale temporarily to avoid possible localization problems - Kernel_Utils::Localizer loc; - - _errorCode = ""; - - // open the HDFFile - HDFfile *hdf_file =0; - HDFgroup *hdf_group_study_structure =0; - HDFgroup *hdf_notebook_vars = 0; - - char* aC_HDFUrl; - std::string aHDFUrl; - bool isASCII = false; - if (HDFascii::isASCII(aUrl.c_str())) { - isASCII = true; - char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.c_str()); - if ( !aResultPath ) - return NULL; - aC_HDFUrl = new char[strlen(aResultPath) + 19]; - sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath); - delete [] (aResultPath); - aHDFUrl = aC_HDFUrl; - delete [] aC_HDFUrl; - } else { - aHDFUrl = aUrl; - } - - - hdf_file = new HDFfile((char*)aHDFUrl.c_str()); - try { - hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too - } - catch (HDFexception) - { - char *eStr; - eStr = new char[strlen(aUrl.c_str())+17]; - sprintf(eStr,"Can't open file %s",aUrl.c_str()); - delete [] eStr; - _errorCode = std::string(eStr); - return NULL; - } - - // Temporary aStudyUrl in place of study name - DF_Document* Doc = _appli->NewDocument("SALOME_STUDY"); - - SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, aUrl); - - _IDcounter++; - Study->StudyId( _IDcounter ); - - // Assign the value of the URL in the study object - Study->URL (aUrl); - - SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl); - - if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) { - _errorCode = "Study is empty"; - return Study; - } - - //Create the Structure of the Document - hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); - - try { - BuildTree (Study, hdf_group_study_structure); - } - catch (HDFexception) - { - char *eStr = new char [strlen(aUrl.c_str())+17]; - sprintf(eStr,"Can't open file %s", aUrl.c_str()); - _errorCode = std::string(eStr); - return NULL; - } - - //Read and create notebook variables - if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) { - hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file); - ReadNoteBookVariables(Study,hdf_notebook_vars); - hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor - } - - hdf_file->CloseOnDisk(); - hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); - - if (isASCII) { - std::vector aFilesToRemove; - aFilesToRemove.push_back("hdf_from_ascii.hdf"); - SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true); - } - - delete hdf_file; // all related hdf objects will be deleted - - // unlock study if it is locked, to set components versions - StudyUnlocker unlock(Study); - - //For old studies we have to add "unknown" version tag for all stored components - SALOMEDSImpl_SComponentIterator itcomponent = Study->NewComponentIterator(); - for (; itcomponent.More(); itcomponent.Next()) - { - SALOMEDSImpl_SComponent sco = itcomponent.Value(); - std::string aCompType = sco.GetComment(); - if ( aCompType == SALOMEDSImpl_IParameters::getDefaultVisualComponent() ) continue; - if ( Study->GetProperties()->GetComponentVersions( aCompType ).empty() ) - Study->GetProperties()->SetComponentVersion( aCompType, "" ); // empty version means "unknown" - } - - return Study; -} - - - -//============================================================================ -/*! Function : Close - * Purpose : Close a study. - * If the study hasn't been saved, ask the user to confirm the - * close action without saving - */ - -//============================================================================ -void SALOMEDSImpl_StudyManager::Close(SALOMEDSImpl_Study* aStudy) -{ - _errorCode = ""; - - if(!aStudy) { - _errorCode = "Study is null"; - return; - } - - aStudy->Close(); - DF_Document* doc=aStudy->GetDocument(); - _appli->Close(doc); -} - -//============================================================================ -/*! Function : Save - * Purpose : Save a Study to it's persistent reference - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::Save(SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile) -{ - _errorCode = ""; - - std::string url = aStudy->URL(); - if (url.empty()) { - _errorCode = "No path specified to save the study. Nothing done"; - return false; - } - else { - return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false); - } - - return false; -} - -bool SALOMEDSImpl_StudyManager::SaveASCII(SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile) -{ - _errorCode = ""; - - std::string url = aStudy->URL(); - if (url.empty()) { - _errorCode = "No path specified to save the study. Nothing done"; - return false; - } - else { - return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true); - } - - return false; -} - -//============================================================================= -/*! Function : SaveAs - * Purpose : Save a study to the persistent reference aUrl - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::SaveAs(const std::string& aUrl, - SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile) -{ - _errorCode = ""; - return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false); -} - -bool SALOMEDSImpl_StudyManager::SaveAsASCII(const std::string& aUrl, - SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile) -{ - _errorCode = ""; - return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true); -} - -//============================================================================ -/*! Function : GetOpenStudies - * Purpose : Get name list of open studies in the session - */ -//============================================================================ -std::vector SALOMEDSImpl_StudyManager::GetOpenStudies() -{ - _errorCode = ""; - std::vector aList; - - int nbDocs = _appli->NbDocuments(); - - if(nbDocs == 0) { - _errorCode = "No active study in this session"; - return aList; - } - else { - SALOMEDSImpl_Study* aStudy; - std::vector ids = _appli->GetDocumentIDs(); - for (int i = 0, len = ids.size(); iGetDocument(ids[i]); - if(D == _clipboard) continue; - aStudy = SALOMEDSImpl_Study::GetStudy(D->Main()); - if(!aStudy) continue; - aList.push_back(aStudy); - } - } - - return aList; -} - -//============================================================================ -/*! Function : GetStudyByName - * Purpose : Get a study from its name - */ -//============================================================================ -SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByName - (const std::string& aStudyName) -{ - _errorCode = ""; - int nbDocs = _appli->NbDocuments(); - - if (nbDocs == 0) { - _errorCode = "No active study in this session"; - return NULL; - } - else { - std::vector studies = GetOpenStudies(); - for (int i = 0, len = studies.size(); iName() == aStudyName) return studies[i]; - } - } - - _errorCode = std::string("Found no study with the name ") + aStudyName; - return NULL; -} - -//============================================================================ -/*! Function : GetStudyByID - * Purpose : Get a study from its ID - */ -//============================================================================ -SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID) -{ - _errorCode = ""; - int nbDocs = _appli->NbDocuments(); - - if (nbDocs == 0) { - _errorCode = "No active study in this session"; - return NULL; - } - else { - std::vector studies = GetOpenStudies(); - for (int i = 0, len = studies.size(); iStudyId() == aStudyID) return studies[i]; - } - } - - _errorCode = "Found no study with the given ID"; - return NULL; -} - -//============================================================================= -/*! Function : _SaveProperties - * Purpose : save the study properties in HDF file - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy, - HDFgroup *hdf_group) -{ - _errorCode = ""; - - HDFdataset *hdf_dataset = 0; - hdf_size size[1]; - hdf_int32 name_len; - - // add modifications list (user and date of save) - SALOMEDSImpl_AttributeStudyProperties* aProp = aStudy->GetProperties(); - - // unlock study if it is locked, to set modification date - StudyUnlocker unlock(aStudy); - - int month=0,day=0,year=0,hh=0,mn=0,ss=0; - SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss); - aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(), - mn, hh, day, month, year); - - // lock study back if it was locked initially, to write correct value of Locked flag - unlock.suspend(); - - std::vector aNames; - std::vector aMinutes, aHours, aDays, aMonths, aYears; - - aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears); - - std::string units = aProp->GetUnits(); - std::string comment = aProp->GetComment(); - - std::map< std::string, std::vector > allVersions = aProp->GetComponentsVersions(); - std::map versions; - - int aLength = 0, aLength1 = 0, anIndex, i, unitsSize = 0, commentSize = 0; - - for(i=1; i<=aNames.size(); i++) - aLength += aNames[i-1].size() + 1; - - std::map< std::string, std::vector >::const_iterator it; - for (it = allVersions.begin(); it != allVersions.end(); ++it ) { - std::string vlist = ""; - std::vector vl = it->second; - std::vector::const_iterator vlit; - for ( vlit = vl.begin(); vlit != vl.end(); ++vlit ) { - if ( vlist != "" ) vlist += ";"; - vlist += *vlit; - } - versions[ it->first ] = vlist; - aLength1 += it->first.size() + vlist.size() + 2; - } - - unitsSize = units.size(); - commentSize = comment.size(); - - //string format: - //locked flag, modified flag, - //minutes, hours, day, months, year, user name, char(1), - //minutes, hours, day, months, year, user name, char(1), - //....................................................., - //....................................................., - //....................................................., - //minutes, hours, day, months, year, user name, char(1), char(30) <- !!!! used to define end of section with modifications !!!! - //units, char(1), comment, char(30) <- !!!! used to define start of section with components' versions !!!! - //component=versions, char(1), - //component=versions, char(1), - //..........................., - //component=versions, char(1), char(0) - - //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, 1 byte (char(30) section delimeter) - // unit length + 1, comment length, "zero" byte - - char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize + 1 + aLength1 ]; - - sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u'); - - aLength = aNames.size(); - int a = 2; - for(anIndex = 0; anIndex 0) { - sprintf(&(aProperty[a]),"%s",units.c_str()); - a = strlen(aProperty); - } - - aProperty[a++] = 1; - - //Write comments if need - if(comment.size() > 0) { - sprintf(&(aProperty[a]),"%s",comment.c_str()); - a = strlen(aProperty); - } - - aProperty[a++] = 30; //delimeter of the component versions - - std::map::const_iterator versionsIt; - for ( versionsIt = versions.begin(); versionsIt != versions.end(); ++versionsIt ) { - sprintf(&(aProperty[a]),"%s=%s", - (char*)(versionsIt->first.c_str()), - (char*)(versionsIt->second.c_str())); - a = a + versionsIt->first.size() + versionsIt->second.size() + 1; - aProperty[a++] = 1; - } - - aProperty[a] = 0; - - name_len = (hdf_int32) a; - size[0] = name_len + 1 ; - hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk(aProperty); - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_group destructor - delete [] aProperty; - - aProp->SetModified(0); - return true; -} - -//============================================================================= -/*! Function : _SaveAs - * Purpose : save the study in HDF file - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const std::string& aStudyUrl, - SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile, - bool theASCII) -{ - // Set "C" locale temporarily to avoid possible localization problems - Kernel_Utils::Localizer loc; - - // HDF File will be composed of differents part : - // * For each ComponentDataType, all data created by the component - // Informations in data group hdf_group_datacomponent - // * Study Structure -> Exactly what is contained in Document - // Informations in data group hdf_group_study_structure - - _errorCode = ""; - - HDFfile *hdf_file=0; - HDFgroup *hdf_group_study_structure =0; - HDFgroup *hdf_sco_group =0; - HDFgroup *hdf_sco_group2 =0; - HDFgroup *hdf_notebook_vars =0; - HDFgroup *hdf_notebook_var = 0; - - HDFgroup *hdf_group_datacomponent =0; - HDFdataset *hdf_dataset =0; - hdf_size size[1]; - hdf_int32 name_len = 0; - std::string component_name; - - if(!aStudy) { - _errorCode = "Study is null"; - return false; - } - - // Store previous URL - std::string anOldName = aStudy->Name(); - - // Map to store components' versions - std::map componentVersions; - - //Create a temporary url to which the study is saved - std::string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl); - - // unlock study if it is locked, as some attributes need to be modified - StudyUnlocker unlock(aStudy); - - SALOMEDSImpl_StudyBuilder* SB= aStudy->NewBuilder(); - std::map aMapTypeDriver; - - try - { - // mpv 15.12.2003: for saving components we have to load all data from all modules - SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator(); - for (; itcomponent.More(); itcomponent.Next()) - { - SALOMEDSImpl_SComponent sco = itcomponent.Value(); - // if there is an associated Engine call its method for saving - std::string IOREngine; - try { - SALOMEDSImpl_Driver* aDriver = NULL; - std::string aCompType = sco.GetComment(); - if (!sco.ComponentIOR(IOREngine)) { - if (!aCompType.empty()) { - - aDriver = aFactory->GetDriverByType(aCompType); - - if (aDriver != NULL) { - if(!SB->LoadWith(sco, aDriver)) { - _errorCode = SB->GetErrorCode(); - return false; - } - } - } - } - else { - aDriver = aFactory->GetDriverByIOR(IOREngine); - } - aMapTypeDriver[aCompType] = aDriver; - } catch(...) { - _errorCode = "Can not restore information to resave it"; - return false; - } - } - - // VSR: set URL to new file name - // VSR: remember to set previous name if save operation fails - aStudy->URL(aStudyUrl); - - // To change for Save - // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything?? - hdf_file = new HDFfile((char*)aUrl.c_str()); - hdf_file->CreateOnDisk(); - - //----------------------------------------------------------------------- - // 1 - Create a groupe for each SComponent and Update the PersistanceRef - //----------------------------------------------------------------------- - hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file); - hdf_group_datacomponent->CreateOnDisk(); - - for (itcomponent.Init(); itcomponent.More(); itcomponent.Next()) - { - SALOMEDSImpl_SComponent sco = itcomponent.Value(); - - std::string scoid = sco.GetID(); - hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent); - hdf_sco_group->CreateOnDisk(); - - std::string componentDataType = sco.ComponentDataType(); - std::string IOREngine; - if (sco.ComponentIOR(IOREngine)) - { - // Engine should be already in the map as it was to added before - SALOMEDSImpl_Driver* Engine = aMapTypeDriver[componentDataType]; - if (Engine != NULL) - { - SALOMEDSImpl_TMPFile* aStream = NULL; - long length = 0; - - componentVersions[ componentDataType ] = Engine->Version(); - - if (theASCII) aStream = Engine->SaveASCII(sco, - SALOMEDSImpl_Tool::GetDirFromPath(aUrl), - length, - theMultiFile); - else aStream = Engine->Save(sco, - SALOMEDSImpl_Tool::GetDirFromPath(aUrl), - length, - theMultiFile); - HDFdataset *hdf_dataset; - hdf_size aHDFSize[1]; - if(length > 0) { //The component saved some auxiliary files, then put them into HDF file - - aHDFSize[0] = length; - - HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file - hdf_dataset->CloseOnDisk(); - } - - if(aStream) delete aStream; - - // store multifile state - aHDFSize[0] = 2; - hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor - // store ASCII state - aHDFSize[0] = 2; - hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor - // Creation of the persistance reference attribute - Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII); - } - } - hdf_sco_group->CloseOnDisk(); - hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor - } - hdf_group_datacomponent->CloseOnDisk(); - hdf_group_datacomponent =0; // will be deleted by hdf_file destructor - - //----------------------------------------------------------------------- - //3 - Write the Study Structure - //----------------------------------------------------------------------- - hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); - hdf_group_study_structure->CreateOnDisk(); - // save component attributes - for (itcomponent.Init(); itcomponent.More(); itcomponent.Next()) - { - SALOMEDSImpl_SComponent SC = itcomponent.Value(); - std::string scid = SC.GetID(); - hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure); - hdf_sco_group2->CreateOnDisk(); - SaveAttributes(SC, hdf_sco_group2); - // ComponentDataType treatment - component_name = SC.ComponentDataType(); - name_len = (hdf_int32)component_name.length(); - size[0] = name_len +1 ; - hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((char*)component_name.c_str()); - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_group destructor - Impl_SaveObject(SC, hdf_sco_group2); - hdf_sco_group2->CloseOnDisk(); - hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor - } - //----------------------------------------------------------------------- - //4 - Write the Study UseCases Structure - //----------------------------------------------------------------------- - SALOMEDSImpl_SObject aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID); - if (aSO) { - HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure); - hdf_soo_group->CreateOnDisk(); - SaveAttributes(aSO, hdf_soo_group); - Impl_SaveObject(aSO, hdf_soo_group); - hdf_soo_group->CloseOnDisk(); - hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor - } - //----------------------------------------------------------------------- - //5 - Write the NoteBook Variables - //----------------------------------------------------------------------- - - //5.1 Create group to store all note book variables - hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file); - hdf_notebook_vars->CreateOnDisk(); - - std::string varValue; - std::string varType; - std::string varIndex; - - for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){ - // For each variable create HDF group - hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars); - hdf_notebook_var->CreateOnDisk(); - - // Save Variable type - varType = aStudy->myNoteBookVars[i]->SaveType(); - name_len = (hdf_int32) varType.length(); - size[0] = name_len +1 ; - hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((char*)varType.c_str()); - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_group destructor - - char buffer[256]; - sprintf(buffer,"%d",i); - varIndex= std::string(buffer); - name_len = (hdf_int32) varIndex.length(); - size[0] = name_len +1 ; - hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((char*)varIndex.c_str()); - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_group destructor - - - // Save Variable value - varValue = aStudy->myNoteBookVars[i]->Save(); - name_len = (hdf_int32) varValue.length(); - size[0] = name_len +1 ; - hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((char*)varValue.c_str()); - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_group destructor - hdf_notebook_var->CloseOnDisk(); - hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor - } - hdf_notebook_vars->CloseOnDisk(); - hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor - - // record component versions - std::map::const_iterator itVersions; - for ( itVersions = componentVersions.begin(); itVersions != componentVersions.end(); ++itVersions ) - aStudy->GetProperties()->SetComponentVersion( itVersions->first, itVersions->second ); - - // lock study back if it was locked initially, to write correct value of Locked flag - unlock.suspend(); - - //----------------------------------------------------------------------- - //6 - Write the Study Properties - //----------------------------------------------------------------------- - std::string study_name = aStudy->Name(); - name_len = (hdf_int32) study_name.size(); - size[0] = name_len +1 ; - hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((char*)study_name.c_str()); - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor - - Impl_SaveProperties(aStudy, hdf_group_study_structure); - hdf_group_study_structure->CloseOnDisk(); - hdf_file->CloseOnDisk(); - - hdf_group_study_structure =0; // will be deleted by hdf_file destructor - delete hdf_file; // recursively deletes all hdf objects... - } - catch (HDFexception) - { - _errorCode = "HDFexception ! "; - aStudy->URL( anOldName ); // VSR: restore previous url if operation is failed - return false; - } - catch(std::exception& exc) - { - _errorCode = const_cast(exc.what()); - aStudy->URL( anOldName ); // VSR: restore previous url if operation is failed - return false; - } - catch(...) - { - _errorCode = "Unknown exception ! "; - aStudy->URL( anOldName ); // VSR: restore previous url if operation is failed - return false; - } - if (theASCII) { // save file in ASCII format - HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true); - } - - //Now it's necessary to copy files from the temporary directory to the user defined directory. - - // The easiest way to get a list of file in the temporary directory - - std::string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir(); - std::string aTmpFile = aTmpFileDir +"files"; - std::string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl); - -#ifdef WIN32 - aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile; -#else - aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile; -#endif - system(aCmd.c_str()); - - // Iterate and move files in the temporary directory - FILE* fp = fopen(aTmpFile.c_str(), "rb"); - if(!fp) { - aStudy->URL( anOldName ); // VSR: restore previous url if operation is failed - return false; - } - char* buffer = new char[2047]; - int errors = 0; - while(!feof(fp) && !errors) { - if((fgets(buffer, 2046, fp)) == NULL) break; - size_t aLen = strlen(buffer); - if(buffer[aLen-1] == '\n') buffer[aLen-1] = char(0); -#ifdef WIN32 - aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\""; -#else - aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\""; -#endif - errors = system(aCmd.c_str()); - } - - delete []buffer; - fclose(fp); - - // Perform cleanup -#ifdef WIN32 - DeleteFileA(aTmpFile.c_str()); -#else - unlink(aTmpFile.c_str()); -#endif - -#ifdef WIN32 - RemoveDirectoryA(aTmpFileDir.c_str()); - RemoveDirectoryA(aStudyTmpDir.c_str()); -#else - rmdir(aTmpFileDir.c_str()); - rmdir(aStudyTmpDir.c_str()); -#endif - - if ( !errors ) { - // VSR: finally, if all is done without errors, mark study as Saved - aStudy->IsSaved(true); - } - - return !errors; -} - -//============================================================================ -/*! Function : Impl_SaveObject - * Purpose : - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC, - HDFgroup *hdf_group_datatype) -{ - _errorCode = ""; - - // Write in group hdf_group_datatype all informations of SObject SC - // Iterative function to parse all SObjects under a SComponent - - HDFgroup *hdf_group_sobject = 0; - - DF_ChildIterator itchild(SC.GetLabel()); - for (; itchild.More(); itchild.Next()) - { - - // mpv: don't save empty labels - std::vector attr = itchild.Value().GetAttributes(); - if (attr.size() == 0) { //No attributes on the label - DF_ChildIterator subchild(itchild.Value()); - if (!subchild.More()) { - continue; - } - subchild.Init(itchild.Value(), true); - bool anEmpty = true; - for (; subchild.More() && anEmpty; subchild.Next()) { - std::vector attr2 = subchild.Value().GetAttributes(); - if (attr2.size()) { - anEmpty = false; //There are attributes on the child label - break; - } - } - if (anEmpty) continue; - } - - SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value()); - - std::string scoid = SO.GetID(); - hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype); - hdf_group_sobject->CreateOnDisk(); - SaveAttributes(SO, hdf_group_sobject); - Impl_SaveObject(SO, hdf_group_sobject); - hdf_group_sobject->CloseOnDisk(); - hdf_group_sobject =0; // will be deleted by father hdf object destructor - } - - return true; -} - -//============================================================================ -/*! Function : Impl_SubstituteSlash - * Purpose : - */ -//============================================================================ -std::string SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const std::string& aUrl) -{ - _errorCode = ""; - - std::string theUrl(aUrl); - for(int i = 0; i_doc; -} - -//============================================================================ -/*! Function : CanCopy - * Purpose : - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::CanCopy(const SALOMEDSImpl_SObject& theObject, - SALOMEDSImpl_Driver* theEngine) -{ - _errorCode = ""; - SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent(); - if (!aComponent) return false; - if (aComponent.GetLabel() == theObject.GetLabel()) return false; - std::string IOREngine; - if (!aComponent.ComponentIOR(IOREngine)) return false; - if (theEngine == NULL) return false; - return theEngine->CanCopy(theObject); -} - -//============================================================================ -/*! Function : CopyLabel - * Purpose : - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::CopyLabel(SALOMEDSImpl_Study* theSourceStudy, - SALOMEDSImpl_Driver* theEngine, - const int theSourceStartDepth, - const DF_Label& theSource, - const DF_Label& theDestinationMain) -{ - _errorCode = ""; - - int a; - DF_Label aTargetLabel = theDestinationMain; - DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2); - for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) { - DF_Label aSourceLabel = theSource; - for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father(); - aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag()); - aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag()); - } - // iterate attributes - std::vector attrList = theSource.GetAttributes(); - for(int i = 0, len = attrList.size(); i(anAttr)->Get(); - std::string anEntry = aReferenced.Entry(); - // store the value of name attribute of referenced label - SALOMEDSImpl_AttributeName* aNameAttribute; - if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) { - anEntry += " "; - anEntry += aNameAttribute->Value(); - } - SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry); - continue; - } - - if (type == std::string("AttributeIOR")) { // IOR => ID and TMPFile of Engine - std::string anEntry = theSource.Entry(); - SALOMEDSImpl_SObject aSO = theSourceStudy->FindObjectID(anEntry); - int anObjID; - long aLen; - SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen); - std::string aResStr(""); - for(a = 0; a < aLen; a++) { - aResStr += (char)(aStream->Get(a)); - } - - if(aStream) delete aStream; - - SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID); - SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr); - continue; - } - DF_Attribute* aNewAttribute = anAttr->NewEmpty(); - aTargetLabel.AddAttribute(aNewAttribute); - anAttr->Paste(aNewAttribute); - } - - return true; -} - -//============================================================================ -/*! Function : Copy - * Purpose : - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::Copy(const SALOMEDSImpl_SObject& theObject, - SALOMEDSImpl_Driver* theEngine) -{ - _errorCode = ""; - - // adoptation for alliances datamodel copy: without IOR attributes !!! - bool aStructureOnly; // copy only SObjects and attributes without component help - aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID()); - - // get component-engine - SALOMEDSImpl_Study* aStudy = theObject.GetStudy(); - - // CAF document of current study usage - DF_Document* aDocument = GetDocumentOfStudy(aStudy); - if (!aDocument) { - _errorCode = "Document is null"; - return false; - } - - //Clear the clipboard - _clipboard->Main().Root().ForgetAllAttributes(true); - _appli->Close(_clipboard); - _clipboard = _appli->NewDocument("SALOME_STUDY"); - - // set component data type to the name attribute of root label - if (!aStructureOnly) { - SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(), - theEngine->ComponentDataType()); - } - // set to the Root label integer attribute: study id - SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId()); - // iterate all theObject's label children - DF_Label aStartLabel = theObject.GetLabel(); - int aSourceStartDepth = aStartLabel.Depth(); - - // copy main source label - CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main()); - - // copy all subchildren of the main source label (all levels) - DF_ChildIterator anIterator(aStartLabel, true); - for(; anIterator.More(); anIterator.Next()) { - CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main()); - } - - return true; -} -//============================================================================ -/*! Function : CanPaste - * Purpose : - */ -//============================================================================ -bool SALOMEDSImpl_StudyManager::CanPaste(const SALOMEDSImpl_SObject& theObject, - SALOMEDSImpl_Driver* theEngine) -{ - _errorCode = ""; - - if (!_clipboard) { - _errorCode = "Clipboard is null"; - return false; - } - - SALOMEDSImpl_AttributeComment* aCompName = NULL; - if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) { - _errorCode = "Clipboard has no component type"; - return false; - } - SALOMEDSImpl_AttributeInteger* anObjID; - if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) { - _errorCode = "Clipboard has no object id"; - return false; - } - SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent(); - if (!aComponent) { - _errorCode = "Object doesn't belong to component"; - return false; - } - - std::string IOREngine; - if (!aComponent.ComponentIOR(IOREngine)) { - _errorCode = "component has no IOR"; - return false; - } - return theEngine->CanPaste(aCompName->Value(), anObjID->Value()); -} - -//============================================================================ -/*! Function : PasteLabel - * Purpose : - */ -//============================================================================ -DF_Label SALOMEDSImpl_StudyManager::PasteLabel(SALOMEDSImpl_Study* theDestinationStudy, - SALOMEDSImpl_Driver* theEngine, - const DF_Label& theSource, - const DF_Label& theDestinationStart, - const int theCopiedStudyID, - const bool isFirstElement) -{ - _errorCode = ""; - - // get corresponding source, target and auxiliary labels - DF_Label aTargetLabel = theDestinationStart; - - DF_Label aAuxSourceLabel = theSource.Root().FindChild(2); - int a; - if (!isFirstElement) { - for(a = theSource.Depth() - 1; a > 0 ; a--) { - DF_Label aSourceLabel = theSource; - for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father(); - aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag()); - aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag()); - } - SALOMEDSImpl_SObject so = theDestinationStudy->GetSObject(aTargetLabel); - theDestinationStudy->addSO_Notification(so); - } - - // check auxiliary label for TMPFile => IOR - SALOMEDSImpl_AttributeName* aNameAttribute = NULL; - if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) { - SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()); - SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()); - std::string aCompName = aComponentName->Value(); - - if (theEngine->CanPaste(aCompName, anObjID->Value())) { - std::string aTMPStr = aNameAttribute->Value(); - int aLen = aTMPStr.size(); - unsigned char* aStream = NULL; - if(aLen > 0) { - aStream = new unsigned char[aLen+10]; - for(a = 0; a < aLen; a++) { - aStream[a] = aTMPStr[a]; - } - } - - std::string anEntry = aTargetLabel.Entry(); - SALOMEDSImpl_SObject aPastedSO = theDestinationStudy->FindObjectID(anEntry); - - if (isFirstElement) { - std::string aDestEntry = theEngine->PasteInto(aStream, - aLen, - anObjID->Value(), - aPastedSO.GetFatherComponent()); - aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry); - } else - theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO); - - if(aStream != NULL) delete []aStream; - } - } - - // iterate attributes - std::vector attrList = theSource.GetAttributes(); - for(int i = 0, len = attrList.size(); iID())) { - aTargetLabel.ForgetAttribute(anAttr->ID()); - } - DF_Attribute* aNewAttribute = anAttr->NewEmpty(); - aTargetLabel.AddAttribute(aNewAttribute); - anAttr->Paste(aNewAttribute); - } - - // check auxiliary label for Comment => reference or name attribute of the referenced object - SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL; - if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) { - char * anEntry = new char[aCommentAttribute->Value().size() + 1]; - strcpy(anEntry, std::string(aCommentAttribute->Value()).c_str()); - char* aNameStart = strchr(anEntry, ' '); - if (aNameStart) { - *aNameStart = '\0'; - aNameStart++; - } - if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference - DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry); - SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel); - // target attributes structure support - SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel)); - } else { - if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart); - else SALOMEDSImpl_AttributeName::Set(aTargetLabel, std::string("Reference to:")+anEntry); - } - delete [] anEntry; - } - - return aTargetLabel; -} - -//============================================================================ -/*! Function : Paste - * Purpose : - */ -//============================================================================ -SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject& theObject, - SALOMEDSImpl_Driver* theEngine) -{ - _errorCode = ""; - - SALOMEDSImpl_SObject so; - SALOMEDSImpl_Study* aStudy = theObject.GetStudy(); - - // if study is locked, then paste can't be done - if (aStudy->GetProperties()->IsLocked()) { - _errorCode = "LockProtection"; - throw LockProtection("LockProtection"); - } - - // if there is no component name, then paste only SObjects and attributes: without component help - SALOMEDSImpl_AttributeComment* aComponentName = NULL; - bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID())); - - // get copied study ID - SALOMEDSImpl_AttributeInteger* aStudyIDAttribute = NULL; - if (!(aStudyIDAttribute=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) { - _errorCode = "No study ID was found"; - return so; - } - int aCStudyID = aStudyIDAttribute->Value(); - - // CAF document of current study usage - DF_Document* aDocument = GetDocumentOfStudy(aStudy); - if (!aDocument) { - _errorCode = "Document is null"; - return so; - } - - SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent(); - - // fill root inserted SObject - DF_Label aStartLabel; - if (aStructureOnly) { - DF_Label anObjectLabel = DF_Label::Label(aDocument->Main(), theObject.GetID()); - aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false); - } else { - DF_Label aComponentLabel = DF_Label::Label(aDocument->Main(), aComponent.GetID()); - aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true); - } - - // paste all sublebels - DF_ChildIterator anIterator(_clipboard->Main(), true); - for(; anIterator.More(); anIterator.Next()) { - PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false); - } - - return SALOMEDSImpl_Study::SObject(aStartLabel); -} - -//####################################################################################################### -//# STATIC PRIVATE FUNCTIONS -//####################################################################################################### - -//============================================================================ -/*! Function : SaveAttributes - * Purpose : Save attributes for object - */ -//============================================================================ -static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject) -{ - hdf_size size[1]; - std::vector attrList = aSO.GetLabel().GetAttributes(); - DF_Attribute* anAttr = NULL; - for(int i = 0, len = attrList.size(); iSave(); - //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl; - size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1; - HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str()); - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_group destructor - } -} - -//=========================================================================== -//Function : ReadAttributes -//=========================================================================== -static void ReadAttributes(SALOMEDSImpl_Study* theStudy, - const SALOMEDSImpl_SObject& aSO, - HDFdataset* hdf_dataset) -{ - hdf_dataset->OpenOnDisk(); - - DF_Attribute* anAttr = NULL; - char* current_string = new char[hdf_dataset->GetSize()+1]; - hdf_dataset->ReadFromDisk(current_string); - //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl; - if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) { - anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment"); - } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") || - !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance - theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string)); - delete [] (current_string); - hdf_dataset->CloseOnDisk(); - return; - } else { - anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName()); - } - - if (anAttr) { - anAttr->Load(current_string); - } - - delete [] (current_string); - hdf_dataset->CloseOnDisk(); -} - -//============================================================================ -//Function : BuildlTree -//============================================================================ -static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group) -{ - hdf_current_group->OpenOnDisk(); - SALOMEDSImpl_SObject aSO; - char* Entry = hdf_current_group->GetName(); - if (strcmp(Entry,"STUDY_STRUCTURE") == 0) { - aSO = theStudy->CreateObjectID("0:1"); - } - else { - aSO = theStudy->CreateObjectID(Entry); - } - - char name[HDF_NAME_MAX_LEN+1]; - int nbsons = hdf_current_group->nInternalObjects(); - for (int i=0; iInternalObjectIndentify(i,name); - if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue; - hdf_object_type type = hdf_current_group->InternalObjectType(name); - - if (type == HDF_DATASET) { - HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group); - ReadAttributes(theStudy,aSO,new_dataset); - new_dataset = 0; // will be deleted by father destructor - - } - else if (type == HDF_GROUP) { - HDFgroup* new_group = new HDFgroup(name,hdf_current_group); - BuildTree (theStudy, new_group); - new_group = 0; // will be deleted by father destructor - } - } - hdf_current_group->CloseOnDisk(); -} - - -//============================================================================ -//Function : Translate_IOR_to_persistentID -//============================================================================ -static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so, - SALOMEDSImpl_Driver* engine, - bool isMultiFile, - bool isASCII) -{ - DF_ChildIterator itchild(so.GetLabel()); - std::string ior_string, persistent_string, curid; - - for (; itchild.More(); itchild.Next()) { - SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value()); - SALOMEDSImpl_AttributeIOR* IOR = NULL; - if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) { - ior_string = IOR->Value(); - - persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII); - SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string); - } - Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII); - } -} - -void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup) -{ - if(!theGroup) - return; - - HDFgroup* new_group =0; - HDFdataset* new_dataset =0; - - char aVarName[HDF_NAME_MAX_LEN+1]; - char *currentVarType = 0; - char *currentVarValue = 0; - char *currentVarIndex = 0; - int order = 0; - //Open HDF group with notebook variables - theGroup->OpenOnDisk(); - - //Get Nb of variables - int aNbVars = theGroup->nInternalObjects(); - - std::map aVarsMap; - - for( int iVar=0;iVar < aNbVars;iVar++ ) { - theGroup->InternalObjectIndentify(iVar,aVarName); - hdf_object_type type = theGroup->InternalObjectType(aVarName); - if(type == HDF_GROUP) { - - //Read Variable - new_group = new HDFgroup(aVarName,theGroup); - new_group->OpenOnDisk(); - - //Read Type - new_dataset = new HDFdataset("VARIABLE_TYPE",new_group); - new_dataset->OpenOnDisk(); - currentVarType = new char[new_dataset->GetSize()+1]; - new_dataset->ReadFromDisk(currentVarType); - new_dataset->CloseOnDisk(); - new_dataset = 0; //will be deleted by hdf_sco_group destructor - - //Read Order - if(new_group->ExistInternalObject("VARIABLE_INDEX")) { - new_dataset = new HDFdataset("VARIABLE_INDEX",new_group); - new_dataset->OpenOnDisk(); - currentVarIndex = new char[new_dataset->GetSize()+1]; - new_dataset->ReadFromDisk(currentVarIndex); - new_dataset->CloseOnDisk(); - new_dataset = 0; //will be deleted by hdf_sco_group destructor - order = atoi(currentVarIndex); - delete [] currentVarIndex; - } - else - order = iVar; - - //Read Value - new_dataset = new HDFdataset("VARIABLE_VALUE",new_group); - new_dataset->OpenOnDisk(); - currentVarValue = new char[new_dataset->GetSize()+1]; - new_dataset->ReadFromDisk(currentVarValue); - new_dataset->CloseOnDisk(); - new_dataset = 0; //will be deleted by hdf_sco_group destructor - - new_group->CloseOnDisk(); - new_group = 0; //will be deleted by hdf_sco_group destructor - - SALOMEDSImpl_GenericVariable::VariableTypes aVarType = - SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType)); - delete [] currentVarType; - - //Create variable and add it in the study - SALOMEDSImpl_GenericVariable* aVariable = - new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName)); - aVariable->Load(std::string(currentVarValue)); - aVarsMap.insert(std::make_pair(order,aVariable)); - delete [] currentVarValue; - } - } - - std::map::const_iterator it= aVarsMap.begin(); - for(;it!=aVarsMap.end();it++) - theStudy->AddVariable((*it).second); - - theGroup->CloseOnDisk(); -} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx deleted file mode 100644 index c111e0b76..000000000 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : SALOMEDSImpl_StudyManager.hxx -// Author : Sergey RUIN -// Module : SALOME -// -#ifndef __SALOMEDSImpl_STUDYMANAGER_I_H__ -#define __SALOMEDSImpl_STUDYMANAGER_I_H__ - -#include "SALOMEDSImpl_Defines.hxx" - -// std C++ headers -#include -#include -#include - -#include "DF_Application.hxx" -#include "SALOMEDSImpl_Study.hxx" -#include "SALOMEDSImpl_SObject.hxx" -#include "SALOMEDSImpl_Driver.hxx" -#include "DF_Attribute.hxx" -#include "DF_Label.hxx" -#include "DF_Document.hxx" - -class HDFgroup; - -class SALOMEDSIMPL_EXPORT SALOMEDSImpl_StudyManager -{ - -private: - - DF_Application* _appli; - int _IDcounter; - DF_Document* _clipboard; - std::string _errorCode; - -public: - - //! standard constructor - SALOMEDSImpl_StudyManager(); - - //! standard destructor - virtual ~SALOMEDSImpl_StudyManager(); - - //! method to Create a New Study of name study_name - virtual SALOMEDSImpl_Study* NewStudy(const std::string& study_name); - - //! method to Open a Study from it's persistent reference - virtual SALOMEDSImpl_Study* Open(const std::string& aStudyUrl); - - //! method to close a Study - virtual void Close(SALOMEDSImpl_Study* aStudy); - - //! method to save a Study - virtual bool Save(SALOMEDSImpl_Study* aStudy, SALOMEDSImpl_DriverFactory* aFactory, bool theMultiFile); - - virtual bool SaveASCII(SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile); - - //! method to save a Study to the persistent reference aUrl - virtual bool SaveAs(const std::string& aUrl, - SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile); - - virtual bool SaveAsASCII(const std::string& aUrl, - SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile); - - //! method to Get name list of open studies in the session - virtual std::vector GetOpenStudies(); - - //! method to get a Study from it's name - virtual SALOMEDSImpl_Study* GetStudyByName(const std::string& aStudyName) ; - - //! method to get a Study from it's ID - virtual SALOMEDSImpl_Study* GetStudyByID(int aStudyID) ; - - - DF_Document* GetDocumentOfStudy(SALOMEDSImpl_Study* theStudy); - - DF_Document* GetClipboard() { return _clipboard; } - - bool CopyLabel(SALOMEDSImpl_Study* theSourceStudy, - SALOMEDSImpl_Driver* theEngine, - const int theSourceStartDepth, - const DF_Label& theSource, - const DF_Label& theDestinationMain); - - DF_Label PasteLabel(SALOMEDSImpl_Study* theDestinationStudy, - SALOMEDSImpl_Driver* theEngine, - const DF_Label& theSource, - const DF_Label& theDestinationStart, - const int theCopiedStudyID, - const bool isFirstElement); - - virtual bool CanCopy(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine); - virtual bool Copy(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine); - virtual bool CanPaste(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine); - virtual SALOMEDSImpl_SObject Paste(const SALOMEDSImpl_SObject& theObject, SALOMEDSImpl_Driver* Engine); - - // _SaveAs private function called by Save and SaveAs - virtual bool Impl_SaveAs(const std::string& aUrl, - SALOMEDSImpl_Study* aStudy, - SALOMEDSImpl_DriverFactory* aFactory, - bool theMultiFile, - bool theASCII); - - // _SaveObject private function called by _SaveAs - virtual bool Impl_SaveObject(const SALOMEDSImpl_SObject& SC, HDFgroup *hdf_group_datatype); - - // _SubstituteSlash function called by Open and GetStudyByName - virtual std::string Impl_SubstituteSlash(const std::string& aUrl); - - virtual bool Impl_SaveProperties(SALOMEDSImpl_Study* aStudy, HDFgroup *hdf_group); - - std::string GetErrorCode() { return _errorCode; } - virtual bool IsError() { return _errorCode != ""; } - -}; - -#endif -- 2.30.2