Salome HOME
INT PAL 0052683: Parameter "Color group" in the "Create Group" dialog box is empty
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.hxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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   /*
209    * Returns True if a hypothesis is assigned to a sole sub-mesh in a current Study
210    */
211   CORBA::Boolean GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp,
212                                          SMESH::SMESH_Mesh_out       theMesh,
213                                          GEOM::GEOM_Object_out       theShape);
214
215   // Preferences
216   // ------------
217   /*!
218    * Sets number of segments per diagonal of boundary box of geometry by which
219    * default segment length of appropriate 1D hypotheses is defined
220    */
221   void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
222   /*!
223    * \brief Sets default number of segments per edge
224    */
225   void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
226
227   /*!
228     Set an option value
229   */
230   virtual void  SetOption(const char*, const char*);
231   /*!
232     Return an option value
233   */
234   virtual char* GetOption(const char*);
235
236   /*!
237    * To load full mesh data from study at hyp modification or not
238    */
239   bool ToForgetMeshDataOnHypModif() const { return myToForgetMeshDataOnHypModif; }
240
241
242   // Create empty mesh on a shape
243   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
244     throw ( SALOME::SALOME_Exception );
245
246   // Create empty mesh
247   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
248     throw ( SALOME::SALOME_Exception );
249
250   //  Create a mesh and import data from an UNV file
251   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
252     throw ( SALOME::SALOME_Exception );
253
254   //  Create mesh(es) and import data from MED file
255   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
256                                           SMESH::DriverMED_ReadStatus& theStatus )
257     throw ( SALOME::SALOME_Exception );
258
259   //  Create mesh(es) and import data from MED file
260   SMESH::mesh_array* CreateMeshesFromSAUV( const char* theFileName,
261                                            SMESH::DriverMED_ReadStatus& theStatus )
262     throw ( SALOME::SALOME_Exception );
263
264   //  Create a mesh and import data from a STL file
265   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
266     throw ( SALOME::SALOME_Exception );
267
268   //  Create mesh(es) and import data from CGNS file
269   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
270                                            SMESH::DriverMED_ReadStatus& theStatus )
271     throw ( SALOME::SALOME_Exception );
272
273   //  Create a mesh and import data from a GMF file
274   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
275                                              CORBA::Boolean          theMakeRequiredGroups,
276                                              SMESH::ComputeError_out theError)
277     throw ( SALOME::SALOME_Exception );
278
279   // Copy a part of mesh
280   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
281                                  const char*               meshName,
282                                  CORBA::Boolean            toCopyGroups,
283                                  CORBA::Boolean            toKeepIDs);
284
285   // Compute mesh on a shape
286   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
287                           GEOM::GEOM_Object_ptr theShapeObject )
288     throw ( SALOME::SALOME_Exception );
289
290   // Cancel Compute mesh on a shape
291   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
292                       GEOM::GEOM_Object_ptr theShapeObject );
293
294   /*!
295    * \brief Return errors of mesh computation
296    */
297   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
298                                                GEOM::GEOM_Object_ptr  theShapeObject )
299     throw ( SALOME::SALOME_Exception );
300
301   /*!
302    * Evaluate mesh on a shape and
303    *  returns statistic of mesh elements
304    * Result array of number enityties
305    */
306   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
307                               GEOM::GEOM_Object_ptr theShapeObject)
308     throw ( SALOME::SALOME_Exception );
309
310   // Returns true if mesh contains enough data to be computed
311   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
312                                    GEOM::GEOM_Object_ptr theShapeObject )
313     throw ( SALOME::SALOME_Exception );
314
315   /*!
316    * Calculate Mesh as preview till indicated dimension on shape
317    * First, verify list of hypothesis associated with the subShape.
318    * Return mesh preview structure
319    */
320   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
321                                         GEOM::GEOM_Object_ptr theSubObject,
322                                         SMESH::Dimension      theDimension,
323                                         SMESH::long_array&    theShapesId )
324     throw ( SALOME::SALOME_Exception );
325
326   // Returns errors of hypotheses definintion
327   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
328                                          GEOM::GEOM_Object_ptr theSubObject )
329       throw ( SALOME::SALOME_Exception );
330
331   // Return mesh elements preventing computation of a subshape
332   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
333                                                  CORBA::Short          theSubShapeID )
334     throw ( SALOME::SALOME_Exception );
335
336   // Create groups of elements preventing computation of a sub-shape
337   SMESH::ListOfGroups* MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
338                                                      CORBA::Short          theSubShapeID,
339                                                      const char*           theGroupName)
340     throw ( SALOME::SALOME_Exception );
341
342   // Get sub-shapes unique ID's list
343   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
344                                      const SMESH::object_array& theListOfSubShape )
345     throw ( SALOME::SALOME_Exception );
346
347   // Return geometrical object the given element is built on. Publish it in study.
348   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
349                                                   CORBA::Long            theElementID,
350                                                   const char*            theGeomName)
351     throw ( SALOME::SALOME_Exception );
352
353   // Return geometrical object the given element is built on. Don't publish it in study.
354   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
355                                                    CORBA::Long            theElementID)
356     throw ( SALOME::SALOME_Exception );
357
358   // Concatenate the given meshes into one mesh
359   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
360                                           CORBA::Boolean                uniteIdenticalGroups,
361                                           CORBA::Boolean                mergeNodesAndElements,
362                                           CORBA::Double                 mergeTolerance,
363                                           CORBA::Boolean                commonGroups)
364     throw ( SALOME::SALOME_Exception );
365
366   // Concatenate the given meshes into one mesh
367   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
368                                     CORBA::Boolean                uniteIdenticalGroups,
369                                     CORBA::Boolean                mergeNodesAndElements,
370                                     CORBA::Double                 mergeTolerance)
371     throw ( SALOME::SALOME_Exception );
372
373   // Concatenate the given meshes into one mesh
374   // Create the groups of all elements from initial meshes
375   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
376                                               CORBA::Boolean                uniteIdenticalGroups,
377                                               CORBA::Boolean                mergeNodesAndElements,
378                                               CORBA::Double                 mergeTolerance)
379     throw ( SALOME::SALOME_Exception );
380
381   // Get MED version of the file by its name
382   CORBA::Boolean GetMEDVersion(const char* theFileName,
383                                SMESH::MED_VERSION& theVersion);
384
385   // Get names of meshes defined in file with the specified name
386   SMESH::string_array* GetMeshNames(const char* theFileName);
387
388   // ****************************************************
389   // Interface inherited methods (from SALOMEDS::Driver)
390   // ****************************************************
391
392   // Save SMESH data
393   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
394                          const char*              theURL,
395                          bool                     isMultiFile );
396   // Load SMESH data
397   bool Load( SALOMEDS::SComponent_ptr theComponent,
398              const SALOMEDS::TMPFile& theStream,
399              const char*              theURL,
400              bool                     isMultiFile );
401   // Save SMESH data in ASCII format
402   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
403                                 const char*              theURL,
404                                 bool                     isMultiFile );
405   // Load SMESH data in ASCII format
406   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
407                   const SALOMEDS::TMPFile& theStream,
408                   const char*              theURL,
409                   bool                     isMultiFile );
410
411   // Create filter manager
412   SMESH::FilterManager_ptr CreateFilterManager();
413
414   // Return a pattern mesher
415   SMESH::SMESH_Pattern_ptr GetPattern();
416
417   // Create measurement instance
418   SMESH::Measurements_ptr  CreateMeasurements();
419
420   // Clears study-connected data when it is closed
421   void Close( SALOMEDS::SComponent_ptr theComponent );
422
423   // Get component data type
424   char* ComponentDataType();
425
426   // Transform data from transient form to persistent
427   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
428                                 const char*           IORString,
429                                 CORBA::Boolean        isMultiFile,
430                                 CORBA::Boolean        isASCII );
431   // Transform data from persistent form to transient
432   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
433                                 const char*           aLocalPersistentID,
434                                 CORBA::Boolean        isMultiFile,
435                                 CORBA::Boolean        isASCII );
436
437   // Returns true if object can be published in the study
438   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
439   // Publish object in the study
440   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr   theStudy,
441                                         SALOMEDS::SObject_ptr theSObject,
442                                         CORBA::Object_ptr     theObject,
443                                         const char*           theName )
444     throw ( SALOME::SALOME_Exception );
445
446   // Copy-paste methods - returns true if object can be copied to the clipboard
447   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
448   // Copy-paste methods - copy object to the clipboard
449   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return NULL; }
450   // Copy-paste methods - returns true if object can be pasted from the clipboard
451   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
452   // Copy-paste methods - paste object from the clipboard
453   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
454                                    CORBA::Long              theObjectID,
455                                    SALOMEDS::SObject_ptr    theObject ) {
456     SALOMEDS::SObject_var aResultSO;
457     return aResultSO._retn();
458   }
459
460   // ============
461   // Version information
462   // ============
463
464   virtual char* getVersion();
465
466   // ============
467   // Dump python
468   // ============
469
470   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
471                                        CORBA::Boolean isPublished,
472                                        CORBA::Boolean isMultiFile,
473                                        CORBA::Boolean& isValidScript);
474
475   void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
476
477   void RemoveLastFromPythonScript (int theStudyID);
478
479   void SavePython (SALOMEDS::Study_ptr theStudy);
480
481   TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
482                                            Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
483                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
484                                            bool isPublished,
485                                            bool isMultiFile,
486                                            bool isHistoricalDump,
487                                            bool& aValidScript,
488                                            TCollection_AsciiString& theSavedTrace);
489
490   TCollection_AsciiString GetNewPythonLines (int theStudyID);
491
492   void CleanPythonTrace (int theStudyID);
493
494   // SIMAN-related functions (check out/check in) : import data to study
495   virtual Engines::ListOfIdentifiers* importData(CORBA::Long studyId,
496                                                  Engines::DataContainer_ptr data,
497                                                  const Engines::ListOfOptions& options);
498   // SIMAN-related functions (check out/check in) : get modified data
499   virtual Engines::ListOfData* getModifiedData(CORBA::Long studyId);
500
501   // *****************************************
502   // Internal methods
503   // *****************************************
504 public:
505   // Get shape reader
506   GEOM_Client* GetShapeReader();
507
508   // Tags definition
509   static long GetHypothesisRootTag();
510   static long GetAlgorithmsRootTag();
511   static long GetRefOnShapeTag();
512   static long GetRefOnAppliedHypothesisTag();
513   static long GetRefOnAppliedAlgorithmsTag();
514   static long GetSubMeshOnVertexTag();
515   static long GetSubMeshOnEdgeTag();
516   static long GetSubMeshOnFaceTag();
517   static long GetSubMeshOnSolidTag();
518   static long GetSubMeshOnCompoundTag();
519   static long GetSubMeshOnWireTag();
520   static long GetSubMeshOnShellTag();
521   static long GetNodeGroupsTag();
522   static long GetEdgeGroupsTag();
523   static long GetFaceGroupsTag();
524   static long GetVolumeGroupsTag();
525   static long Get0DElementsGroupsTag();
526   static long GetBallElementsGroupsTag();
527
528   // publishing methods
529   SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
530   SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr   theStudy,
531                                      SMESH::SMESH_Mesh_ptr theMesh,
532                                      const char*           theName = 0);
533   SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr         theStudy,
534                                            SMESH::SMESH_Hypothesis_ptr theHyp,
535                                            const char*                 theName = 0);
536   SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr      theStudy,
537                                         SMESH::SMESH_Mesh_ptr    theMesh,
538                                         SMESH::SMESH_subMesh_ptr theSubMesh,
539                                         GEOM::GEOM_Object_ptr    theShapeObject,
540                                         const char*              theName = 0);
541   SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr    theStudy,
542                                       SMESH::SMESH_Mesh_ptr  theMesh,
543                                       SMESH::SMESH_GroupBase_ptr theGroup,
544                                       GEOM::GEOM_Object_ptr  theShapeObject,
545                                       const char*            theName = 0);
546   bool AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
547                             SMESH::SMESH_Mesh_ptr       theMesh,
548                             GEOM::GEOM_Object_ptr       theShapeObject,
549                             SMESH::SMESH_Hypothesis_ptr theHyp);
550   bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy,
551                                  SMESH::SMESH_Mesh_ptr       theMesh,
552                                  GEOM::GEOM_Object_ptr       theShapeObject,
553                                  SMESH::SMESH_Hypothesis_ptr theHyp);
554   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr   theStudy,
555                                                  SMESH::SMESH_Mesh_ptr theMesh,
556                                                  GEOM::GEOM_Object_ptr theShape);
557   static void SetName(SALOMEDS::SObject_ptr theSObject,
558                       const char*           theName,
559                       const char*           theDefaultName = 0);
560
561   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
562                         const char*           thePixMap);
563
564   //  Get study context
565   StudyContext* GetCurrentStudyContext();
566
567   // Register an object in a StudyContext; return object id
568   int RegisterObject(CORBA::Object_ptr theObject);
569
570   // Return id of registered object
571   CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
572
573   // Return an object that previously had an oldID
574   template<class TInterface>
575   typename TInterface::_var_type GetObjectByOldId( const int oldID )
576   {
577     if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
578       string ior = myStudyContext->getIORbyOldId( oldID );
579       if ( !ior.empty() )
580         return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
581     }
582     return TInterface::_nil();
583   }
584
585   // Get current study ID
586   int GetCurrentStudyID();
587
588   /*!
589    * \brief Find SObject for an algo
590    */
591   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
592
593   void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
594   char* GetParameters(CORBA::Object_ptr theObject);
595   //char* ParseParameters(const char* theParameters);
596   const std::vector< int >&         GetLastParamIndices() const { return myLastParamIndex; }
597   const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
598   const std::string &               GetLastObjEntry() const { return myLastObj; }
599   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
600
601   // Move objects to the specified position
602   void Move( const SMESH::sobject_list& what,
603              SALOMEDS::SObject_ptr where,
604              CORBA::Long row );
605   CORBA::Boolean IsApplicable ( const char*           theAlgoType,
606                                 const char*           theLibName,
607                                 GEOM::GEOM_Object_ptr theShapeObject,
608                                 CORBA::Boolean        toCheckAll);
609
610 private:
611   // Get hypothesis creator
612   GenericHypothesisCreator_i* getHypothesisCreator( const char*  theHypName,
613                                                     const char*  theLibName,
614                                                     std::string& thePlatformLibName)
615   throw ( SALOME::SALOME_Exception );
616   // Create hypothesis of given type
617   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
618                                                 const char* theLibName);
619   // Create empty mesh on shape
620   SMESH::SMESH_Mesh_ptr createMesh()
621     throw ( SALOME::SALOME_Exception );
622
623   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
624
625   SMESH::mesh_array* CreateMeshesFromMEDorSAUV( const char* theFileName,
626                                                 SMESH::DriverMED_ReadStatus& theStatus,
627                                                 const char* theCommandNameForPython,
628                                                 const char* theFileNameForPython);
629
630   void setCurrentStudy( SALOMEDS::Study_ptr theStudy,
631                         bool                theStudyIsBeingClosed=false);
632
633 private:
634   static GEOM::GEOM_Gen_var      myGeomGen;
635   static CORBA::ORB_var          myOrb;         // ORB reference
636   static PortableServer::POA_var myPoa;         // POA reference
637   static SALOME_NamingService*   myNS;          // Naming Service
638   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
639   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
640   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
641
642   // hypotheses managing
643   map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
644
645   map<int, StudyContext*>   myStudyContextMap;  // Map of study context objects
646
647   GEOM_Client*              myShapeReader;      // Shape reader
648   SALOMEDS::Study_var       myCurrentStudy;     // Current study
649   CORBA::Boolean            myIsEmbeddedMode;   // Current mode
650
651   // To load full mesh data from study at hyp modification or not
652   bool myToForgetMeshDataOnHypModif;
653
654   // Dump Python: trace of API methods calls
655   std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
656   bool                                                     myIsHistoricalPythonDump;
657   std::vector< int >                                       myLastParamIndex;
658   std::vector< std::string >                               myLastParameters;
659   std::string                                              myLastObj;
660   int                                                      myImportedStudyId;      // SIMAN: identifier of the imported in importData study to keep no-modifiection flag for getModifiedData method
661   int                                                      myImportedStudyChanged; // SIMAN: flag that indicates that the imported study has been changed (by creation of the additional mesh)
662 };
663
664
665 namespace SMESH
666 {
667   template<class T>
668   T
669   DownCast(CORBA::Object_ptr theArg)
670   {
671     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
672   }
673
674   /*!
675    * \brief Function used in SMESH_CATCH to convert a caught exception to
676    * SALOME::SALOME_Exception
677    */
678   inline void throwCorbaException(const char* excText)
679   {
680     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
681   }
682 }
683
684
685 #endif