Salome HOME
23586: [EDF] HYDRO: Copy mesh to new geometry
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.hxx
1 // Copyright (C) 2007-2016  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 #include <NCollection_DataMap.hxx>
53
54 #include <map>
55 #include <sstream>
56
57 class SMESH_Mesh_i;
58 class SALOME_LifeCycleCORBA;
59
60 // ===========================================================
61 // Study context - stores study-connected objects references
62 // ==========================================================
63 class SMESH_I_EXPORT StudyContext
64 {
65   typedef NCollection_DataMap< int, std::string > TInt2StringMap;
66   typedef NCollection_DataMap< int, int >         TInt2IntMap;
67 public:
68   // constructor
69   StudyContext() {}
70
71   // register object in the internal map and return its id
72   int addObject( std::string theIOR )
73   {
74     int nextId = getNextId();
75     mapIdToIOR.Bind( nextId, theIOR );
76     return nextId;
77   }
78   // find the object id in the internal map by the IOR
79   int findId( std::string theIOR )
80   {
81     TInt2StringMap::iterator imap;
82     for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
83       if ( *imap == theIOR )
84         return imap.Iterator().Key();
85     }
86     return 0;
87   }
88   // get object's IOR by id
89   std::string getIORbyId( const int theId )
90   {
91     if ( mapIdToIOR.IsBound( theId ) )
92       return mapIdToIOR( theId );
93     return std::string();
94   }
95   // get object's IOR by old id
96   std::string getIORbyOldId( const int theOldId )
97   {
98     if ( mapIdToId.IsBound( theOldId ) )
99       return getIORbyId( mapIdToId( theOldId ));
100     return std::string();
101   }
102   // maps old object id to the new one (used when restoring data)
103   void mapOldToNew( const int oldId, const int newId ) {
104     mapIdToId.Bind( oldId, newId );
105   }
106   // get old id by a new one
107   int getOldId( const int newId ) {
108     TInt2IntMap::iterator imap;
109     for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
110       if ( *imap == newId )
111         return imap.Iterator().Key();
112     }
113     return 0;
114   }
115
116 private:
117   // get next free object identifier
118   int getNextId()
119   {
120     return mapIdToIOR.Extent() + 1;
121   }
122
123   TInt2StringMap mapIdToIOR; // persistent-to-transient map
124   TInt2IntMap    mapIdToId;  // to translate object from persistent to transient form
125 };
126
127 // ===========================================================
128 // SMESH module's engine
129 // ==========================================================
130 class SMESH_I_EXPORT SMESH_Gen_i:
131   public virtual POA_SMESH::SMESH_Gen,
132   public virtual Engines_Component_i
133 {
134 public:
135   // Get last created instance of the class
136   static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
137   // Get ORB object
138   static CORBA::ORB_var GetORB() { return myOrb;}
139   // Get SMESH module's POA object
140   static PortableServer::POA_var GetPOA() { return myPoa;}
141   // Get Naming Service object
142   static SALOME_NamingService* GetNS();
143   // Get SALOME_LifeCycleCORBA object
144   static SALOME_LifeCycleCORBA* GetLCC();
145   // Retrieve and get GEOM engine reference
146   static GEOM::GEOM_Gen_var GetGeomEngine();
147   // Get object of the CORBA reference
148   static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
149   // Get CORBA object corresponding to the SALOMEDS::SObject
150   static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
151   // Get the SALOMEDS::SObject corresponding to a CORBA object
152   static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
153                                                CORBA::Object_ptr   theObject);
154   // Get GEOM Object corresponding to TopoDS_Shape
155   GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
156   // Get TopoDS_Shape corresponding to GEOM_Object
157   TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
158
159   // Default constructor
160   SMESH_Gen_i();
161   // Standard constructor
162   SMESH_Gen_i( CORBA::ORB_ptr            orb,
163                PortableServer::POA_ptr   poa,
164                PortableServer::ObjectId* contId,
165                const char*               instanceName,
166                const char*               interfaceName );
167   // Destructor
168   virtual ~SMESH_Gen_i();
169
170   // *****************************************
171   // Interface methods
172   // *****************************************
173   // Set a new Mesh object name
174   void SetName(const char* theIOR,
175                const char* theName);
176
177   //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
178   void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
179
180   // Set current study
181   void SetEmbeddedMode( CORBA::Boolean theMode );
182   // Get current study
183   CORBA::Boolean IsEmbeddedMode();
184
185   // Set current study
186   void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
187   // Get current study
188   SALOMEDS::Study_ptr GetCurrentStudy();
189
190   // Create hypothesis/algorothm of given type
191   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
192                                                 const char* theLibName)
193     throw ( SALOME::SALOME_Exception );
194
195   // Return hypothesis of given type holding parameter values of the existing mesh
196   SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char*           theHypType,
197                                                             const char*           theLibName,
198                                                             SMESH::SMESH_Mesh_ptr theMesh,
199                                                             GEOM::GEOM_Object_ptr theGeom,
200                                                             CORBA::Boolean        byMesh)
201     throw ( SALOME::SALOME_Exception );
202
203   /*
204    * Returns True if a hypothesis is assigned to a sole sub-mesh in a current Study
205    */
206   CORBA::Boolean GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp,
207                                          SMESH::SMESH_Mesh_out       theMesh,
208                                          GEOM::GEOM_Object_out       theShape);
209
210   // Preferences
211   // ------------
212   /*!
213    * Sets number of segments per diagonal of boundary box of geometry by which
214    * default segment length of appropriate 1D hypotheses is defined
215    */
216   void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
217   /*!
218    * \brief Sets default number of segments per edge
219    */
220   void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
221
222   /*!
223     Set an option value
224   */
225   virtual void  SetOption(const char*, const char*);
226   /*!
227     Return an option value
228   */
229   virtual char* GetOption(const char*);
230
231   /*!
232    * To load full mesh data from study at hyp modification or not
233    */
234   bool ToForgetMeshDataOnHypModif() const { return myToForgetMeshDataOnHypModif; }
235
236
237   // Create empty mesh on a shape
238   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
239     throw ( SALOME::SALOME_Exception );
240
241   // Create empty mesh
242   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
243     throw ( SALOME::SALOME_Exception );
244
245   //  Create a mesh and import data from an UNV file
246   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
247     throw ( SALOME::SALOME_Exception );
248
249   //  Create mesh(es) and import data from MED file
250   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
251                                           SMESH::DriverMED_ReadStatus& theStatus )
252     throw ( SALOME::SALOME_Exception );
253
254   //  Create mesh(es) and import data from MED file
255   SMESH::mesh_array* CreateMeshesFromSAUV( const char* theFileName,
256                                            SMESH::DriverMED_ReadStatus& theStatus )
257     throw ( SALOME::SALOME_Exception );
258
259   //  Create a mesh and import data from a STL file
260   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
261     throw ( SALOME::SALOME_Exception );
262
263   //  Create mesh(es) and import data from CGNS file
264   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
265                                            SMESH::DriverMED_ReadStatus& theStatus )
266     throw ( SALOME::SALOME_Exception );
267
268   //  Create a mesh and import data from a GMF file
269   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
270                                              CORBA::Boolean          theMakeRequiredGroups,
271                                              SMESH::ComputeError_out theError)
272     throw ( SALOME::SALOME_Exception );
273
274   // Copy a part of mesh
275   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
276                                  const char*               meshName,
277                                  CORBA::Boolean            toCopyGroups,
278                                  CORBA::Boolean            toKeepIDs)
279     throw ( SALOME::SALOME_Exception );
280
281   // Create a mesh by copying definitions of another mesh to a given geometry
282   CORBA::Boolean CopyMeshWithGeom( SMESH::SMESH_Mesh_ptr       sourceMesh,
283                                    GEOM::GEOM_Object_ptr       newGeometry,
284                                    const char*                 meshName,
285                                    CORBA::Boolean              toCopyGroups,
286                                    CORBA::Boolean              toReuseHypotheses,
287                                    CORBA::Boolean              toCopyElements,
288                                    SMESH::SMESH_Mesh_out       newMesh,
289                                    SMESH::ListOfGroups_out     newGroups,
290                                    SMESH::submesh_array_out    newSubmeshes,
291                                    SMESH::ListOfHypothesis_out newHypotheses,
292                                    SMESH::string_array_out     invalidEntries)
293     throw ( SALOME::SALOME_Exception );
294
295     // Compute mesh on a shape
296   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
297                           GEOM::GEOM_Object_ptr theShapeObject )
298     throw ( SALOME::SALOME_Exception );
299
300   // Cancel Compute mesh on a shape
301   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
302                       GEOM::GEOM_Object_ptr theShapeObject );
303
304   /*!
305    * \brief Return errors of mesh computation
306    */
307   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
308                                                GEOM::GEOM_Object_ptr  theShapeObject )
309     throw ( SALOME::SALOME_Exception );
310
311   /*!
312    * Evaluate mesh on a shape and
313    *  returns statistic of mesh elements
314    * Result array of number enityties
315    */
316   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
317                               GEOM::GEOM_Object_ptr theShapeObject)
318     throw ( SALOME::SALOME_Exception );
319
320   // Returns true if mesh contains enough data to be computed
321   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
322                                    GEOM::GEOM_Object_ptr theShapeObject )
323     throw ( SALOME::SALOME_Exception );
324
325   /*!
326    * Calculate Mesh as preview till indicated dimension on shape
327    * First, verify list of hypothesis associated with the subShape.
328    * Return mesh preview structure
329    */
330   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
331                                         GEOM::GEOM_Object_ptr theSubObject,
332                                         SMESH::Dimension      theDimension,
333                                         SMESH::long_array&    theShapesId )
334     throw ( SALOME::SALOME_Exception );
335
336   // Returns errors of hypotheses definition
337   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
338                                          GEOM::GEOM_Object_ptr theSubObject )
339       throw ( SALOME::SALOME_Exception );
340
341   // Return mesh elements preventing computation of a subshape
342   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
343                                                  CORBA::Short          theSubShapeID )
344     throw ( SALOME::SALOME_Exception );
345
346   // Create groups of elements preventing computation of a sub-shape
347   SMESH::ListOfGroups* MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
348                                                      CORBA::Short          theSubShapeID,
349                                                      const char*           theGroupName)
350     throw ( SALOME::SALOME_Exception );
351
352   // Get sub-shapes unique ID's list
353   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
354                                      const SMESH::object_array& theListOfSubShape )
355     throw ( SALOME::SALOME_Exception );
356
357   // Return geometrical object the given element is built on. Publish it in study.
358   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
359                                                   CORBA::Long            theElementID,
360                                                   const char*            theGeomName)
361     throw ( SALOME::SALOME_Exception );
362
363   // Return geometrical object the given element is built on. Don't publish it in study.
364   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
365                                                    CORBA::Long            theElementID)
366     throw ( SALOME::SALOME_Exception );
367
368   // Concatenate the given meshes into one mesh
369   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
370                                           CORBA::Boolean                uniteIdenticalGroups,
371                                           CORBA::Boolean                mergeNodesAndElements,
372                                           CORBA::Double                 mergeTolerance,
373                                           CORBA::Boolean                commonGroups)
374     throw ( SALOME::SALOME_Exception );
375
376   // Concatenate the given meshes into one mesh
377   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
378                                     CORBA::Boolean                uniteIdenticalGroups,
379                                     CORBA::Boolean                mergeNodesAndElements,
380                                     CORBA::Double                 mergeTolerance)
381     throw ( SALOME::SALOME_Exception );
382
383   // Concatenate the given meshes into one mesh
384   // Create the groups of all elements from initial meshes
385   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
386                                               CORBA::Boolean                uniteIdenticalGroups,
387                                               CORBA::Boolean                mergeNodesAndElements,
388                                               CORBA::Double                 mergeTolerance)
389     throw ( SALOME::SALOME_Exception );
390
391   // Get MED version of the file by its name
392   CORBA::Boolean GetMEDVersion(const char* theFileName,
393                                SMESH::MED_VERSION& theVersion);
394
395   // Get names of meshes defined in file with the specified name
396   SMESH::string_array* GetMeshNames(const char* theFileName);
397
398   // ****************************************************
399   // Interface inherited methods (from SALOMEDS::Driver)
400   // ****************************************************
401
402   // Save SMESH data
403   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
404                          const char*              theURL,
405                          bool                     isMultiFile );
406   // Load SMESH data
407   bool Load( SALOMEDS::SComponent_ptr theComponent,
408              const SALOMEDS::TMPFile& theStream,
409              const char*              theURL,
410              bool                     isMultiFile );
411   // Save SMESH data in ASCII format
412   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
413                                 const char*              theURL,
414                                 bool                     isMultiFile );
415   // Load SMESH data in ASCII format
416   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
417                   const SALOMEDS::TMPFile& theStream,
418                   const char*              theURL,
419                   bool                     isMultiFile );
420
421   // Create filter manager
422   SMESH::FilterManager_ptr CreateFilterManager();
423
424   // Return a pattern mesher
425   SMESH::SMESH_Pattern_ptr GetPattern();
426
427   // Create measurement instance
428   SMESH::Measurements_ptr  CreateMeasurements();
429
430   // Clears study-connected data when it is closed
431   void Close( SALOMEDS::SComponent_ptr theComponent );
432
433   // Get component data type
434   char* ComponentDataType();
435
436   // Transform data from transient form to persistent
437   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
438                                 const char*           IORString,
439                                 CORBA::Boolean        isMultiFile,
440                                 CORBA::Boolean        isASCII );
441   // Transform data from persistent form to transient
442   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
443                                 const char*           aLocalPersistentID,
444                                 CORBA::Boolean        isMultiFile,
445                                 CORBA::Boolean        isASCII );
446
447   // Returns true if object can be published in the study
448   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
449   // Publish object in the study
450   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr   theStudy,
451                                         SALOMEDS::SObject_ptr theSObject,
452                                         CORBA::Object_ptr     theObject,
453                                         const char*           theName )
454     throw ( SALOME::SALOME_Exception );
455
456   // Copy-paste methods - returns true if object can be copied to the clipboard
457   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
458   // Copy-paste methods - copy object to the clipboard
459   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return NULL; }
460   // Copy-paste methods - returns true if object can be pasted from the clipboard
461   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
462   // Copy-paste methods - paste object from the clipboard
463   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
464                                    CORBA::Long              theObjectID,
465                                    SALOMEDS::SObject_ptr    theObject ) {
466     SALOMEDS::SObject_var aResultSO;
467     return aResultSO._retn();
468   }
469
470   // ============
471   // Version information
472   // ============
473
474   virtual char* getVersion();
475
476   // ============
477   // Dump python
478   // ============
479
480   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
481                                        CORBA::Boolean isPublished,
482                                        CORBA::Boolean isMultiFile,
483                                        CORBA::Boolean& isValidScript);
484
485   void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
486
487   void RemoveLastFromPythonScript (int theStudyID);
488
489   void SavePython (SALOMEDS::Study_ptr theStudy);
490
491   TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
492                                            Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
493                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
494                                            bool isPublished,
495                                            bool isMultiFile,
496                                            bool isHistoricalDump,
497                                            bool& aValidScript,
498                                            TCollection_AsciiString& theSavedTrace);
499
500   TCollection_AsciiString GetNewPythonLines (int theStudyID);
501
502   void CleanPythonTrace (int theStudyID);
503
504   // *****************************************
505   // Internal methods
506   // *****************************************
507 public:
508   // Get shape reader
509   GEOM_Client* GetShapeReader();
510
511   // Tags definition
512   static long GetHypothesisRootTag();
513   static long GetAlgorithmsRootTag();
514   static long GetRefOnShapeTag();
515   static long GetRefOnAppliedHypothesisTag();
516   static long GetRefOnAppliedAlgorithmsTag();
517   static long GetSubMeshOnVertexTag();
518   static long GetSubMeshOnEdgeTag();
519   static long GetSubMeshOnFaceTag();
520   static long GetSubMeshOnSolidTag();
521   static long GetSubMeshOnCompoundTag();
522   static long GetSubMeshOnWireTag();
523   static long GetSubMeshOnShellTag();
524   static long GetNodeGroupsTag();
525   static long GetEdgeGroupsTag();
526   static long GetFaceGroupsTag();
527   static long GetVolumeGroupsTag();
528   static long Get0DElementsGroupsTag();
529   static long GetBallElementsGroupsTag();
530
531   // publishing methods
532   SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
533   SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr   theStudy,
534                                      SMESH::SMESH_Mesh_ptr theMesh,
535                                      const char*           theName = 0);
536   SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr         theStudy,
537                                            SMESH::SMESH_Hypothesis_ptr theHyp,
538                                            const char*                 theName = 0);
539   SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr      theStudy,
540                                         SMESH::SMESH_Mesh_ptr    theMesh,
541                                         SMESH::SMESH_subMesh_ptr theSubMesh,
542                                         GEOM::GEOM_Object_ptr    theShapeObject,
543                                         const char*              theName = 0);
544   SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr    theStudy,
545                                       SMESH::SMESH_Mesh_ptr  theMesh,
546                                       SMESH::SMESH_GroupBase_ptr theGroup,
547                                       GEOM::GEOM_Object_ptr  theShapeObject,
548                                       const char*            theName = 0);
549   void HighLightInvalid(CORBA::Object_ptr theObject, bool isInvalid);
550   bool AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
551                             SMESH::SMESH_Mesh_ptr       theMesh,
552                             GEOM::GEOM_Object_ptr       theShapeObject,
553                             SMESH::SMESH_Hypothesis_ptr theHyp);
554   bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy,
555                                  SMESH::SMESH_Mesh_ptr       theMesh,
556                                  GEOM::GEOM_Object_ptr       theShapeObject,
557                                  SMESH::SMESH_Hypothesis_ptr theHyp);
558   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr   theStudy,
559                                                  SMESH::SMESH_Mesh_ptr theMesh,
560                                                  GEOM::GEOM_Object_ptr theShape);
561   static void SetName(SALOMEDS::SObject_ptr theSObject,
562                       const char*           theName,
563                       const char*           theDefaultName = 0);
564
565   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
566                         const char*           thePixMap);
567
568   //  Get study context
569   StudyContext* GetCurrentStudyContext();
570
571   // Register an object in a StudyContext; return object id
572   int RegisterObject(CORBA::Object_ptr theObject);
573
574   // Return id of registered object
575   CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
576
577   // Return an object that previously had an oldID
578   template<class TInterface>
579     typename TInterface::_var_type GetObjectByOldId( const int oldID )
580   {
581     if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
582       std::string ior = myStudyContext->getIORbyOldId( oldID );
583       if ( !ior.empty() )
584         return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
585     }
586     return TInterface::_nil();
587   }
588
589   // Get current study ID
590   int GetCurrentStudyID();
591
592   /*!
593    * \brief Find SObject for an algo
594    */
595   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
596
597   void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
598   char* GetParameters(CORBA::Object_ptr theObject);
599   //char* ParseParameters(const char* theParameters);
600   const std::vector< int >&         GetLastParamIndices() const { return myLastParamIndex; }
601   const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
602   const std::string &               GetLastObjEntry() const { return myLastObj; }
603   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
604
605   // Move objects to the specified position
606   void Move( const SMESH::sobject_list& what,
607              SALOMEDS::SObject_ptr where,
608              CORBA::Long row );
609
610   CORBA::Boolean IsApplicable ( const char*           theAlgoType,
611                                 const char*           theLibName,
612                                 GEOM::GEOM_Object_ptr theShapeObject,
613                                 CORBA::Boolean        toCheckAll);
614
615   SMESH::long_array* GetInsideSphere( SMESH::SMESH_IDSource_ptr meshPart,
616                                       SMESH::ElementType        theElemType,
617                                       CORBA::Double             theX,
618                                       CORBA::Double             theY,
619                                       CORBA::Double             theZ,
620                                       CORBA::Double             theR);
621
622   SMESH::long_array* GetInsideBox( SMESH::SMESH_IDSource_ptr meshPart,
623                                    SMESH::ElementType        theElemType,
624                                    CORBA::Double             theX1,
625                                    CORBA::Double             theY1,
626                                    CORBA::Double             theZ1,
627                                    CORBA::Double             theX2,
628                                    CORBA::Double             theY2,
629                                    CORBA::Double             theZ2);
630
631   SMESH::long_array* GetInsideCylinder( SMESH::SMESH_IDSource_ptr meshPart,
632                                         SMESH::ElementType        theElemType,
633                                         CORBA::Double             theX,
634                                         CORBA::Double             theY,
635                                         CORBA::Double             theZ,
636                                         CORBA::Double             theDX,
637                                         CORBA::Double             theDY,
638                                         CORBA::Double             theDZ,
639                                         CORBA::Double             theH,
640                                         CORBA::Double             theR );
641
642   SMESH::long_array* GetInside( SMESH::SMESH_IDSource_ptr meshPart,
643                                 SMESH::ElementType        theElemType,
644                                 GEOM::GEOM_Object_ptr     theGeom,
645                                 CORBA::Double             theTolerance );
646
647 private:
648   // Get hypothesis creator
649   GenericHypothesisCreator_i* getHypothesisCreator( const char*  theHypName,
650                                                     const char*  theLibName,
651                                                     std::string& thePlatformLibName)
652   throw ( SALOME::SALOME_Exception );
653   // Create hypothesis of given type
654   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
655                                                 const char* theLibName);
656   // Create empty mesh on shape
657   SMESH::SMESH_Mesh_ptr createMesh()
658     throw ( SALOME::SALOME_Exception );
659
660   // Create a sub-mesh on a geometry that is not a sub-shape of the main shape
661   // for the case where a valid sub-shape not found by CopyMeshWithGeom()
662   SMESH::SMESH_subMesh_ptr createInvalidSubMesh( SMESH::SMESH_Mesh_ptr mesh,
663                                                  GEOM::GEOM_Object_ptr strangerGeom,
664                                                  const char*           name );
665
666   void highLightInvalid( SALOMEDS::SObject_ptr theSObject, bool isInvalid );
667
668   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
669
670   SMESH::mesh_array* CreateMeshesFromMEDorSAUV( const char* theFileName,
671                                                 SMESH::DriverMED_ReadStatus& theStatus,
672                                                 const char* theCommandNameForPython,
673                                                 const char* theFileNameForPython);
674
675   void setCurrentStudy( SALOMEDS::Study_ptr theStudy,
676                         bool                theStudyIsBeingClosed=false);
677
678   std::vector<long> _GetInside(SMESH::SMESH_IDSource_ptr meshPart,
679                                SMESH::ElementType     theElemType,
680                                TopoDS_Shape& aShape,
681                                double* theTolerance = NULL);
682
683 private:
684   static GEOM::GEOM_Gen_var      myGeomGen;
685   static CORBA::ORB_var          myOrb;         // ORB reference
686   static PortableServer::POA_var myPoa;         // POA reference
687   static SALOME_NamingService*   myNS;          // Naming Service
688   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
689   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
690   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
691
692   // hypotheses managing
693   std::map<std::string, GenericHypothesisCreator_i*> myHypCreatorMap;
694
695   std::map<int, StudyContext*>   myStudyContextMap;  // Map of study context objects
696
697   GEOM_Client*                   myShapeReader;      // Shape reader
698   SALOMEDS::Study_var            myCurrentStudy;     // Current study
699   CORBA::Boolean                 myIsEmbeddedMode;   // Current mode
700
701   // Default color of groups
702   std::string myDefaultGroupColor;
703
704   // To load full mesh data from study at hyp modification or not
705   bool myToForgetMeshDataOnHypModif;
706
707   // Dump Python: trace of API methods calls
708   std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
709   bool                                                     myIsHistoricalPythonDump;
710   std::vector< int >                                       myLastParamIndex;
711   std::vector< std::string >                               myLastParameters;
712   std::string                                              myLastObj;
713 };
714
715
716 namespace SMESH
717 {
718   template<class T>
719   T
720   DownCast(CORBA::Object_ptr theArg)
721   {
722     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
723   }
724
725   /*!
726    * \brief Function used in SMESH_CATCH to convert a caught exception to
727    * SALOME::SALOME_Exception
728    */
729   inline void throwCorbaException(const char* excText)
730   {
731     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
732   }
733 }
734
735
736 #endif