Salome HOME
Fix to avoid dependence of mesh on itself (it leaded to cycle in 'SetRemovedFromStudy').
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESH_Gen_i.hxx
23 //  Author : Paul RASCLE, EDF
24 //  Module : SMESH
25
26 #ifndef _SMESH_GEN_I_HXX_
27 #define _SMESH_GEN_I_HXX_
28
29 #include "SMESH.hxx"
30
31 #include <SALOMEconfig.h>
32 #include CORBA_SERVER_HEADER(SMESH_Gen)
33 #include CORBA_SERVER_HEADER(SMESH_Mesh)
34 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
35 #include CORBA_CLIENT_HEADER(GEOM_Gen)
36 #include CORBA_CLIENT_HEADER(SALOMEDS)
37 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
38
39 #include "SMESH_Gen.hxx"
40 #include "SMESH_Mesh_i.hxx"
41 #include "SMESH_Hypothesis_i.hxx"
42
43 #include <SALOME_Component_i.hxx>
44 #include <SALOME_NamingService.hxx>
45 #include <Utils_CorbaException.hxx>
46
47 #include <GEOM_Client.hxx>
48
49 #include <TCollection_AsciiString.hxx>
50 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
51 #include <TColStd_HSequenceOfAsciiString.hxx>
52
53 #include <map>
54 #include <sstream>
55
56 class SMESH_Mesh_i;
57 class SALOME_LifeCycleCORBA;
58
59 // ===========================================================
60 // Study context - stores study-connected objects references
61 // ==========================================================
62 class SMESH_I_EXPORT StudyContext
63 {
64 public:
65   // constructor
66   StudyContext() {}
67   // destructor
68   ~StudyContext()
69   {
70     mapIdToIOR.clear();
71     mapIdToId.clear();
72   }
73   // register object in the internal map and return its id
74   int addObject( string theIOR )
75   {
76     int nextId = getNextId();
77     mapIdToIOR[ nextId ]  = theIOR;
78     return nextId;
79   }
80   // find the object id in the internal map by the IOR
81   int findId( string theIOR )
82   {
83     map<int, string>::iterator imap;
84     for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
85       if ( imap->second == theIOR )
86         return imap->first;
87     }
88     return 0;
89   }
90   // get object's IOR by id
91   string getIORbyId( const int theId )
92   {
93     if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
94       return mapIdToIOR[ theId ];
95     return string( "" );
96   }
97   // get object's IOR by old id
98   string getIORbyOldId( const int theOldId )
99   {
100     if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
101       return getIORbyId( mapIdToId[ theOldId ] );
102     return string( "" );
103   }
104   // maps old object id to the new one (used when restoring data)
105   void mapOldToNew( const int oldId, const int newId ) {
106     mapIdToId[ oldId ] = newId;
107   }
108   // get old id by a new one
109   int getOldId( const int newId ) {
110     map<int, int>::iterator imap;
111     for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
112       if ( imap->second == newId )
113         return imap->first;
114     }
115     return 0;
116   }
117
118 private:
119   // get next free object identifier
120   int getNextId()
121   {
122     int id = 1;
123     while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
124       id++;
125     return id;
126   }
127
128   map<int, string> mapIdToIOR;      // persistent-to-transient map
129   map<int, int>    mapIdToId;       // used to translate object from persistent to transient form
130 };
131
132 // ===========================================================
133 // SMESH module's engine
134 // ==========================================================
135 class SMESH_I_EXPORT SMESH_Gen_i:
136   public virtual POA_SMESH::SMESH_Gen,
137   public virtual Engines_Component_i
138 {
139 public:
140   // Get last created instance of the class
141   static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
142   // Get ORB object
143   static CORBA::ORB_var GetORB() { return myOrb;}
144   // Get SMESH module's POA object
145   static PortableServer::POA_var GetPOA() { return myPoa;}
146   // Get Naming Service object
147   static SALOME_NamingService* GetNS();
148   // Get SALOME_LifeCycleCORBA object
149   static SALOME_LifeCycleCORBA* GetLCC();
150   // Retrieve and get GEOM engine reference
151   static GEOM::GEOM_Gen_var GetGeomEngine();
152   // Get object of the CORBA reference
153   static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
154   // Get CORBA object corresponding to the SALOMEDS::SObject
155   static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
156   // Get the SALOMEDS::SObject corresponding to a CORBA object
157   static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
158                                                CORBA::Object_ptr   theObject);
159   // Get GEOM Object correspoding to TopoDS_Shape
160   GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
161   // Get TopoDS_Shape correspoding to GEOM_Object
162   TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
163
164   // Default constructor
165   SMESH_Gen_i();
166   // Standard constructor
167   SMESH_Gen_i( CORBA::ORB_ptr            orb,
168                PortableServer::POA_ptr   poa,
169                PortableServer::ObjectId* contId,
170                const char*               instanceName,
171                const char*               interfaceName );
172   // Destructor
173   virtual ~SMESH_Gen_i();
174
175   // *****************************************
176   // Interface methods
177   // *****************************************
178   // Set a new Mesh object name
179   void SetName(const char* theIOR,
180                const char* theName);
181
182   //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
183   void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
184
185   // Set current study
186   void SetEmbeddedMode( CORBA::Boolean theMode );
187   // Get current study
188   CORBA::Boolean IsEmbeddedMode();
189
190   // Set current study
191   void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
192   // Get current study
193   SALOMEDS::Study_ptr GetCurrentStudy();
194
195   // Create hypothesis/algorothm of given type
196   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
197                                                 const char* theLibName)
198     throw ( SALOME::SALOME_Exception );
199
200   // Return hypothesis of given type holding parameter values of the existing mesh
201   SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char*           theHypType,
202                                                             const char*           theLibName,
203                                                             SMESH::SMESH_Mesh_ptr theMesh,
204                                                             GEOM::GEOM_Object_ptr theGeom,
205                                                             CORBA::Boolean        byMesh)
206     throw ( SALOME::SALOME_Exception );
207
208   // Preferences
209   // ------------
210   /*!
211    * Sets number of segments per diagonal of boundary box of geometry by which
212    * default segment length of appropriate 1D hypotheses is defined
213    */
214   void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
215   /*!
216    * \brief Sets default number of segments per edge
217    */
218   void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
219
220   /*!
221     Set an option value
222   */
223   virtual void  SetOption(const char*, const char*);
224   /*!
225     Return an option value
226   */
227   virtual char* GetOption(const char*);
228
229   /*!
230    * To load full mesh data from study at hyp modification or not
231    */
232   bool ToForgetMeshDataOnHypModif() const { return myToForgetMeshDataOnHypModif; }
233
234
235   // Create empty mesh on a shape
236   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
237     throw ( SALOME::SALOME_Exception );
238
239   // Create empty mesh
240   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
241     throw ( SALOME::SALOME_Exception );
242
243   //  Create a mesh and import data from an UNV file
244   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
245     throw ( SALOME::SALOME_Exception );
246
247   //  Create mesh(es) and import data from MED file
248   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
249                                           SMESH::DriverMED_ReadStatus& theStatus )
250     throw ( SALOME::SALOME_Exception );
251
252   //  Create mesh(es) and import data from MED file
253   SMESH::mesh_array* CreateMeshesFromSAUV( const char* theFileName,
254                                            SMESH::DriverMED_ReadStatus& theStatus )
255     throw ( SALOME::SALOME_Exception );
256
257   //  Create a mesh and import data from a STL file
258   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
259     throw ( SALOME::SALOME_Exception );
260
261   //  Create mesh(es) and import data from CGNS file
262   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
263                                            SMESH::DriverMED_ReadStatus& theStatus )
264     throw ( SALOME::SALOME_Exception );
265
266   //  Create a mesh and import data from a GMF file
267   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
268                                              CORBA::Boolean          theMakeRequiredGroups,
269                                              SMESH::ComputeError_out theError)
270     throw ( SALOME::SALOME_Exception );
271
272   // Copy a part of mesh
273   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
274                                  const char*               meshName,
275                                  CORBA::Boolean            toCopyGroups,
276                                  CORBA::Boolean            toKeepIDs);
277
278   // Compute mesh on a shape
279   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
280                           GEOM::GEOM_Object_ptr theShapeObject )
281     throw ( SALOME::SALOME_Exception );
282
283   // Cancel Compute mesh on a shape
284   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
285                       GEOM::GEOM_Object_ptr theShapeObject );
286
287   /*!
288    * \brief Return errors of mesh computation
289    */
290   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
291                                                GEOM::GEOM_Object_ptr  theShapeObject )
292     throw ( SALOME::SALOME_Exception );
293
294   /*!
295    * Evaluate mesh on a shape and
296    *  returns statistic of mesh elements
297    * Result array of number enityties
298    */
299   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
300                               GEOM::GEOM_Object_ptr theShapeObject)
301     throw ( SALOME::SALOME_Exception );
302
303   // Returns true if mesh contains enough data to be computed
304   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
305                                    GEOM::GEOM_Object_ptr theShapeObject )
306     throw ( SALOME::SALOME_Exception );
307
308   /*!
309    * Calculate Mesh as preview till indicated dimension on shape
310    * First, verify list of hypothesis associated with the subShape.
311    * Return mesh preview structure
312    */
313   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
314                                         GEOM::GEOM_Object_ptr theSubObject,
315                                         SMESH::Dimension      theDimension,
316                                         SMESH::long_array&    theShapesId )
317     throw ( SALOME::SALOME_Exception );
318
319   // Returns errors of hypotheses definintion
320   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
321                                          GEOM::GEOM_Object_ptr theSubObject )
322       throw ( SALOME::SALOME_Exception );
323
324   // Return mesh elements preventing computation of a subshape
325   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
326                                                  CORBA::Short          theSubShapeID )
327     throw ( SALOME::SALOME_Exception );
328
329   // Get sub-shapes unique ID's list
330   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
331                                      const SMESH::object_array& theListOfSubShape )
332     throw ( SALOME::SALOME_Exception );
333
334   // Return geometrical object the given element is built on. Publish it in study.
335   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
336                                                   CORBA::Long            theElementID,
337                                                   const char*            theGeomName)
338     throw ( SALOME::SALOME_Exception );
339
340   // Return geometrical object the given element is built on. Don't publish it in study.
341   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
342                                                    CORBA::Long            theElementID)
343     throw ( SALOME::SALOME_Exception );
344
345   // Concatenate the given meshes into one mesh
346   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
347                                           CORBA::Boolean           theUniteIdenticalGroups,
348                                           CORBA::Boolean           theMergeNodesAndElements,
349                                           CORBA::Double            theMergeTolerance,
350                                           CORBA::Boolean           theCommonGroups)
351     throw ( SALOME::SALOME_Exception );
352
353   // Concatenate the given meshes into one mesh
354   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray,
355                                     CORBA::Boolean           theUniteIdenticalGroups,
356                                     CORBA::Boolean           theMergeNodesAndElements,
357                                     CORBA::Double            theMergeTolerance)
358     throw ( SALOME::SALOME_Exception );
359
360   // Concatenate the given meshes into one mesh
361   // Create the groups of all elements from initial meshes
362   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
363                                               CORBA::Boolean           theUniteIdenticalGroups,
364                                               CORBA::Boolean           theMergeNodesAndElements,
365                                               CORBA::Double            theMergeTolerance)
366     throw ( SALOME::SALOME_Exception );
367
368   // Get MED version of the file by its name
369   CORBA::Boolean GetMEDVersion(const char* theFileName,
370                                SMESH::MED_VERSION& theVersion);
371
372   // Get names of meshes defined in file with the specified name
373   SMESH::string_array* GetMeshNames(const char* theFileName);
374
375   // ****************************************************
376   // Interface inherited methods (from SALOMEDS::Driver)
377   // ****************************************************
378
379   // Save SMESH data
380   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
381                          const char*              theURL,
382                          bool                     isMultiFile );
383   // Load SMESH data
384   bool Load( SALOMEDS::SComponent_ptr theComponent,
385              const SALOMEDS::TMPFile& theStream,
386              const char*              theURL,
387              bool                     isMultiFile );
388   // Save SMESH data in ASCII format
389   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
390                                 const char*              theURL,
391                                 bool                     isMultiFile );
392   // Load SMESH data in ASCII format
393   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
394                   const SALOMEDS::TMPFile& theStream,
395                   const char*              theURL,
396                   bool                     isMultiFile );
397
398   // Create filter manager
399   SMESH::FilterManager_ptr CreateFilterManager();
400
401   // Return a pattern mesher
402   SMESH::SMESH_Pattern_ptr GetPattern();
403
404   // Create measurement instance
405   SMESH::Measurements_ptr  CreateMeasurements();
406
407   // Clears study-connected data when it is closed
408   void Close( SALOMEDS::SComponent_ptr theComponent );
409
410   // Get component data type
411   char* ComponentDataType();
412
413   // Transform data from transient form to persistent
414   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
415                                 const char*           IORString,
416                                 CORBA::Boolean        isMultiFile,
417                                 CORBA::Boolean        isASCII );
418   // Transform data from persistent form to transient
419   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
420                                 const char*           aLocalPersistentID,
421                                 CORBA::Boolean        isMultiFile,
422                                 CORBA::Boolean        isASCII );
423
424   // Returns true if object can be published in the study
425   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
426   // Publish object in the study
427   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr   theStudy,
428                                         SALOMEDS::SObject_ptr theSObject,
429                                         CORBA::Object_ptr     theObject,
430                                         const char*           theName )
431     throw ( SALOME::SALOME_Exception );
432
433   // Copy-paste methods - returns true if object can be copied to the clipboard
434   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
435   // Copy-paste methods - copy object to the clipboard
436   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
437   // Copy-paste methods - returns true if object can be pasted from the clipboard
438   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
439   // Copy-paste methods - paste object from the clipboard
440   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
441                                    CORBA::Long              theObjectID,
442                                    SALOMEDS::SObject_ptr    theObject ) {
443     SALOMEDS::SObject_var aResultSO;
444     return aResultSO._retn();
445   }
446
447   // ============
448   // Version information
449   // ============
450
451   virtual char* getVersion();
452
453   // ============
454   // Dump python
455   // ============
456
457   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
458                                        CORBA::Boolean isPublished,
459                                        CORBA::Boolean isMultiFile,
460                                        CORBA::Boolean& isValidScript);
461
462   void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
463
464   void RemoveLastFromPythonScript (int theStudyID);
465
466   void SavePython (SALOMEDS::Study_ptr theStudy);
467
468   TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
469                                            Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
470                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
471                                            bool isPublished,
472                                            bool isMultiFile,
473                                            bool isHistoricalDump,
474                                            bool& aValidScript,
475                                            const TCollection_AsciiString& theSavedTrace);
476
477   TCollection_AsciiString GetNewPythonLines (int theStudyID);
478
479   void CleanPythonTrace (int theStudyID);
480
481
482   // *****************************************
483   // Internal methods
484   // *****************************************
485 public:
486   // Get shape reader
487   GEOM_Client* GetShapeReader();
488
489   // Tags definition
490   static long GetHypothesisRootTag();
491   static long GetAlgorithmsRootTag();
492   static long GetRefOnShapeTag();
493   static long GetRefOnAppliedHypothesisTag();
494   static long GetRefOnAppliedAlgorithmsTag();
495   static long GetSubMeshOnVertexTag();
496   static long GetSubMeshOnEdgeTag();
497   static long GetSubMeshOnFaceTag();
498   static long GetSubMeshOnSolidTag();
499   static long GetSubMeshOnCompoundTag();
500   static long GetSubMeshOnWireTag();
501   static long GetSubMeshOnShellTag();
502   static long GetNodeGroupsTag();
503   static long GetEdgeGroupsTag();
504   static long GetFaceGroupsTag();
505   static long GetVolumeGroupsTag();
506   static long Get0DElementsGroupsTag();
507   static long GetBallElementsGroupsTag();
508
509   // publishing methods
510   SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
511   SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr   theStudy,
512                                      SMESH::SMESH_Mesh_ptr theMesh,
513                                      const char*           theName = 0);
514   SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr         theStudy,
515                                            SMESH::SMESH_Hypothesis_ptr theHyp,
516                                            const char*                 theName = 0);
517   SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr      theStudy,
518                                         SMESH::SMESH_Mesh_ptr    theMesh,
519                                         SMESH::SMESH_subMesh_ptr theSubMesh,
520                                         GEOM::GEOM_Object_ptr    theShapeObject,
521                                         const char*              theName = 0);
522   SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr    theStudy,
523                                       SMESH::SMESH_Mesh_ptr  theMesh,
524                                       SMESH::SMESH_GroupBase_ptr theGroup,
525                                       GEOM::GEOM_Object_ptr  theShapeObject,
526                                       const char*            theName = 0);
527   bool AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
528                             SMESH::SMESH_Mesh_ptr       theMesh,
529                             GEOM::GEOM_Object_ptr       theShapeObject,
530                             SMESH::SMESH_Hypothesis_ptr theHyp);
531   bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy,
532                                  SMESH::SMESH_Mesh_ptr       theMesh,
533                                  GEOM::GEOM_Object_ptr       theShapeObject,
534                                  SMESH::SMESH_Hypothesis_ptr theHyp);
535   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr   theStudy,
536                                                  SMESH::SMESH_Mesh_ptr theMesh,
537                                                  GEOM::GEOM_Object_ptr theShape);
538   static void SetName(SALOMEDS::SObject_ptr theSObject,
539                       const char*           theName,
540                       const char*           theDefaultName = 0);
541
542   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
543                         const char*           thePixMap);
544
545   //  Get study context
546   StudyContext* GetCurrentStudyContext();
547
548   // Register an object in a StudyContext; return object id
549   int RegisterObject(CORBA::Object_ptr theObject);
550
551   // Return id of registered object
552   CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
553
554   // Return an object that previously had an oldID
555   template<class TInterface>
556   typename TInterface::_var_type GetObjectByOldId( const int oldID )
557   {
558     if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
559       string ior = myStudyContext->getIORbyOldId( oldID );
560       if ( !ior.empty() )
561         return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
562     }
563     return TInterface::_nil();
564   }
565
566   // Get current study ID
567   int GetCurrentStudyID();
568
569   /*!
570    * \brief Find SObject for an algo
571    */
572   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
573
574   void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
575   char* GetParameters(CORBA::Object_ptr theObject);
576   //char* ParseParameters(const char* theParameters);
577   const std::vector< int >&         GetLastParamIndices() const { return myLastParamIndex; }
578   const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
579   const std::string &               GetLastObjEntry() const { return myLastObj; }
580   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
581
582 private:
583   // Create hypothesis of given type
584   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
585                                                 const char* theLibName)
586     throw ( SALOME::SALOME_Exception );
587
588   // Create empty mesh on shape
589   SMESH::SMESH_Mesh_ptr createMesh()
590     throw ( SALOME::SALOME_Exception );
591
592   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
593
594   SMESH::mesh_array* CreateMeshesFromMEDorSAUV( const char* theFileName,
595                                                 SMESH::DriverMED_ReadStatus& theStatus,
596                                                 const char* theCommandNameForPython,
597                                                 const char* theFileNameForPython);
598
599   void setCurrentStudy( SALOMEDS::Study_ptr theStudy,
600                         bool                theStudyIsBeingClosed=false);
601
602 private:
603   static GEOM::GEOM_Gen_var      myGeomGen;
604   static CORBA::ORB_var          myOrb;         // ORB reference
605   static PortableServer::POA_var myPoa;         // POA reference
606   static SALOME_NamingService*   myNS;          // Naming Service
607   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
608   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
609   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
610
611   // hypotheses managing
612   map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
613
614   map<int, StudyContext*>   myStudyContextMap;  // Map of study context objects
615
616   GEOM_Client*              myShapeReader;      // Shape reader
617   SALOMEDS::Study_var       myCurrentStudy;     // Current study
618   CORBA::Boolean            myIsEmbeddedMode;   // Current mode
619
620   // To load full mesh data from study at hyp modification or not
621   bool myToForgetMeshDataOnHypModif;
622
623   // Dump Python: trace of API methods calls
624   std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
625   bool                                                     myIsHistoricalPythonDump;
626   std::vector< int >                                       myLastParamIndex;
627   std::vector< std::string >                               myLastParameters;
628   std::string                                              myLastObj;
629 };
630
631
632 namespace SMESH
633 {
634   template<class T>
635   T
636   DownCast(CORBA::Object_ptr theArg)
637   {
638     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
639   }
640
641   /*!
642    * \brief Function used in SMESH_CATCH to convert a caught exception to
643    * SALOME::SALOME_Exception
644    */
645   inline void throwCorbaException(const char* excText)
646   {
647     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
648   }
649 }
650
651
652 #endif