Salome HOME
GPUSPHGUI: add Offset transformation
[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
280   // Compute mesh on a shape
281   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
282                           GEOM::GEOM_Object_ptr theShapeObject )
283     throw ( SALOME::SALOME_Exception );
284
285   // Cancel Compute mesh on a shape
286   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
287                       GEOM::GEOM_Object_ptr theShapeObject );
288
289   /*!
290    * \brief Return errors of mesh computation
291    */
292   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
293                                                GEOM::GEOM_Object_ptr  theShapeObject )
294     throw ( SALOME::SALOME_Exception );
295
296   /*!
297    * Evaluate mesh on a shape and
298    *  returns statistic of mesh elements
299    * Result array of number enityties
300    */
301   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
302                               GEOM::GEOM_Object_ptr theShapeObject)
303     throw ( SALOME::SALOME_Exception );
304
305   // Returns true if mesh contains enough data to be computed
306   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
307                                    GEOM::GEOM_Object_ptr theShapeObject )
308     throw ( SALOME::SALOME_Exception );
309
310   /*!
311    * Calculate Mesh as preview till indicated dimension on shape
312    * First, verify list of hypothesis associated with the subShape.
313    * Return mesh preview structure
314    */
315   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
316                                         GEOM::GEOM_Object_ptr theSubObject,
317                                         SMESH::Dimension      theDimension,
318                                         SMESH::long_array&    theShapesId )
319     throw ( SALOME::SALOME_Exception );
320
321   // Returns errors of hypotheses definition
322   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
323                                          GEOM::GEOM_Object_ptr theSubObject )
324       throw ( SALOME::SALOME_Exception );
325
326   // Return mesh elements preventing computation of a subshape
327   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
328                                                  CORBA::Short          theSubShapeID )
329     throw ( SALOME::SALOME_Exception );
330
331   // Create groups of elements preventing computation of a sub-shape
332   SMESH::ListOfGroups* MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
333                                                      CORBA::Short          theSubShapeID,
334                                                      const char*           theGroupName)
335     throw ( SALOME::SALOME_Exception );
336
337   // Get sub-shapes unique ID's list
338   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
339                                      const SMESH::object_array& theListOfSubShape )
340     throw ( SALOME::SALOME_Exception );
341
342   // Return geometrical object the given element is built on. Publish it in study.
343   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
344                                                   CORBA::Long            theElementID,
345                                                   const char*            theGeomName)
346     throw ( SALOME::SALOME_Exception );
347
348   // Return geometrical object the given element is built on. Don't publish it in study.
349   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
350                                                    CORBA::Long            theElementID)
351     throw ( SALOME::SALOME_Exception );
352
353   // Concatenate the given meshes into one mesh
354   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
355                                           CORBA::Boolean                uniteIdenticalGroups,
356                                           CORBA::Boolean                mergeNodesAndElements,
357                                           CORBA::Double                 mergeTolerance,
358                                           CORBA::Boolean                commonGroups)
359     throw ( SALOME::SALOME_Exception );
360
361   // Concatenate the given meshes into one mesh
362   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
363                                     CORBA::Boolean                uniteIdenticalGroups,
364                                     CORBA::Boolean                mergeNodesAndElements,
365                                     CORBA::Double                 mergeTolerance)
366     throw ( SALOME::SALOME_Exception );
367
368   // Concatenate the given meshes into one mesh
369   // Create the groups of all elements from initial meshes
370   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
371                                               CORBA::Boolean                uniteIdenticalGroups,
372                                               CORBA::Boolean                mergeNodesAndElements,
373                                               CORBA::Double                 mergeTolerance)
374     throw ( SALOME::SALOME_Exception );
375
376   // Get MED version of the file by its name
377   CORBA::Boolean GetMEDVersion(const char* theFileName,
378                                SMESH::MED_VERSION& theVersion);
379
380   // Get names of meshes defined in file with the specified name
381   SMESH::string_array* GetMeshNames(const char* theFileName);
382
383   // ****************************************************
384   // Interface inherited methods (from SALOMEDS::Driver)
385   // ****************************************************
386
387   // Save SMESH data
388   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
389                          const char*              theURL,
390                          bool                     isMultiFile );
391   // Load SMESH data
392   bool Load( SALOMEDS::SComponent_ptr theComponent,
393              const SALOMEDS::TMPFile& theStream,
394              const char*              theURL,
395              bool                     isMultiFile );
396   // Save SMESH data in ASCII format
397   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
398                                 const char*              theURL,
399                                 bool                     isMultiFile );
400   // Load SMESH data in ASCII format
401   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
402                   const SALOMEDS::TMPFile& theStream,
403                   const char*              theURL,
404                   bool                     isMultiFile );
405
406   // Create filter manager
407   SMESH::FilterManager_ptr CreateFilterManager();
408
409   // Return a pattern mesher
410   SMESH::SMESH_Pattern_ptr GetPattern();
411
412   // Create measurement instance
413   SMESH::Measurements_ptr  CreateMeasurements();
414
415   // Clears study-connected data when it is closed
416   void Close( SALOMEDS::SComponent_ptr theComponent );
417
418   // Get component data type
419   char* ComponentDataType();
420
421   // Transform data from transient form to persistent
422   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
423                                 const char*           IORString,
424                                 CORBA::Boolean        isMultiFile,
425                                 CORBA::Boolean        isASCII );
426   // Transform data from persistent form to transient
427   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
428                                 const char*           aLocalPersistentID,
429                                 CORBA::Boolean        isMultiFile,
430                                 CORBA::Boolean        isASCII );
431
432   // Returns true if object can be published in the study
433   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
434   // Publish object in the study
435   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr   theStudy,
436                                         SALOMEDS::SObject_ptr theSObject,
437                                         CORBA::Object_ptr     theObject,
438                                         const char*           theName )
439     throw ( SALOME::SALOME_Exception );
440
441   // Copy-paste methods - returns true if object can be copied to the clipboard
442   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
443   // Copy-paste methods - copy object to the clipboard
444   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return NULL; }
445   // Copy-paste methods - returns true if object can be pasted from the clipboard
446   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
447   // Copy-paste methods - paste object from the clipboard
448   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
449                                    CORBA::Long              theObjectID,
450                                    SALOMEDS::SObject_ptr    theObject ) {
451     SALOMEDS::SObject_var aResultSO;
452     return aResultSO._retn();
453   }
454
455   // ============
456   // Version information
457   // ============
458
459   virtual char* getVersion();
460
461   // ============
462   // Dump python
463   // ============
464
465   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
466                                        CORBA::Boolean isPublished,
467                                        CORBA::Boolean isMultiFile,
468                                        CORBA::Boolean& isValidScript);
469
470   void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
471
472   void RemoveLastFromPythonScript (int theStudyID);
473
474   void SavePython (SALOMEDS::Study_ptr theStudy);
475
476   TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
477                                            Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
478                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
479                                            bool isPublished,
480                                            bool isMultiFile,
481                                            bool isHistoricalDump,
482                                            bool& aValidScript,
483                                            TCollection_AsciiString& theSavedTrace);
484
485   TCollection_AsciiString GetNewPythonLines (int theStudyID);
486
487   void CleanPythonTrace (int theStudyID);
488
489   // *****************************************
490   // Internal methods
491   // *****************************************
492 public:
493   // Get shape reader
494   GEOM_Client* GetShapeReader();
495
496   // Tags definition
497   static long GetHypothesisRootTag();
498   static long GetAlgorithmsRootTag();
499   static long GetRefOnShapeTag();
500   static long GetRefOnAppliedHypothesisTag();
501   static long GetRefOnAppliedAlgorithmsTag();
502   static long GetSubMeshOnVertexTag();
503   static long GetSubMeshOnEdgeTag();
504   static long GetSubMeshOnFaceTag();
505   static long GetSubMeshOnSolidTag();
506   static long GetSubMeshOnCompoundTag();
507   static long GetSubMeshOnWireTag();
508   static long GetSubMeshOnShellTag();
509   static long GetNodeGroupsTag();
510   static long GetEdgeGroupsTag();
511   static long GetFaceGroupsTag();
512   static long GetVolumeGroupsTag();
513   static long Get0DElementsGroupsTag();
514   static long GetBallElementsGroupsTag();
515
516   // publishing methods
517   SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
518   SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr   theStudy,
519                                      SMESH::SMESH_Mesh_ptr theMesh,
520                                      const char*           theName = 0);
521   SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr         theStudy,
522                                            SMESH::SMESH_Hypothesis_ptr theHyp,
523                                            const char*                 theName = 0);
524   SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr      theStudy,
525                                         SMESH::SMESH_Mesh_ptr    theMesh,
526                                         SMESH::SMESH_subMesh_ptr theSubMesh,
527                                         GEOM::GEOM_Object_ptr    theShapeObject,
528                                         const char*              theName = 0);
529   SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr    theStudy,
530                                       SMESH::SMESH_Mesh_ptr  theMesh,
531                                       SMESH::SMESH_GroupBase_ptr theGroup,
532                                       GEOM::GEOM_Object_ptr  theShapeObject,
533                                       const char*            theName = 0);
534   bool AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
535                             SMESH::SMESH_Mesh_ptr       theMesh,
536                             GEOM::GEOM_Object_ptr       theShapeObject,
537                             SMESH::SMESH_Hypothesis_ptr theHyp);
538   bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy,
539                                  SMESH::SMESH_Mesh_ptr       theMesh,
540                                  GEOM::GEOM_Object_ptr       theShapeObject,
541                                  SMESH::SMESH_Hypothesis_ptr theHyp);
542   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr   theStudy,
543                                                  SMESH::SMESH_Mesh_ptr theMesh,
544                                                  GEOM::GEOM_Object_ptr theShape);
545   static void SetName(SALOMEDS::SObject_ptr theSObject,
546                       const char*           theName,
547                       const char*           theDefaultName = 0);
548
549   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
550                         const char*           thePixMap);
551
552   //  Get study context
553   StudyContext* GetCurrentStudyContext();
554
555   // Register an object in a StudyContext; return object id
556   int RegisterObject(CORBA::Object_ptr theObject);
557
558   // Return id of registered object
559   CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
560
561   // Return an object that previously had an oldID
562   template<class TInterface>
563     typename TInterface::_var_type GetObjectByOldId( const int oldID )
564   {
565     if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
566       std::string ior = myStudyContext->getIORbyOldId( oldID );
567       if ( !ior.empty() )
568         return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
569     }
570     return TInterface::_nil();
571   }
572
573   // Get current study ID
574   int GetCurrentStudyID();
575
576   /*!
577    * \brief Find SObject for an algo
578    */
579   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
580
581   void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
582   char* GetParameters(CORBA::Object_ptr theObject);
583   //char* ParseParameters(const char* theParameters);
584   const std::vector< int >&         GetLastParamIndices() const { return myLastParamIndex; }
585   const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
586   const std::string &               GetLastObjEntry() const { return myLastObj; }
587   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
588
589   // Move objects to the specified position
590   void Move( const SMESH::sobject_list& what,
591              SALOMEDS::SObject_ptr where,
592              CORBA::Long row );
593
594   CORBA::Boolean IsApplicable ( const char*           theAlgoType,
595                                 const char*           theLibName,
596                                 GEOM::GEOM_Object_ptr theShapeObject,
597                                 CORBA::Boolean        toCheckAll);
598
599   SMESH::long_array* GetInsideSphere( SMESH::SMESH_IDSource_ptr meshPart,
600                                       SMESH::ElementType        theElemType,
601                                       CORBA::Double             theX,
602                                       CORBA::Double             theY,
603                                       CORBA::Double             theZ,
604                                       CORBA::Double             theR);
605
606   SMESH::long_array* GetInsideBox( SMESH::SMESH_IDSource_ptr meshPart,
607                                    SMESH::ElementType        theElemType,
608                                    CORBA::Double             theX1,
609                                    CORBA::Double             theY1,
610                                    CORBA::Double             theZ1,
611                                    CORBA::Double             theX2,
612                                    CORBA::Double             theY2,
613                                    CORBA::Double             theZ2);
614
615   SMESH::long_array* GetInsideCylinder( SMESH::SMESH_IDSource_ptr meshPart,
616                                         SMESH::ElementType        theElemType,
617                                         CORBA::Double             theX,
618                                         CORBA::Double             theY,
619                                         CORBA::Double             theZ,
620                                         CORBA::Double             theDX,
621                                         CORBA::Double             theDY,
622                                         CORBA::Double             theDZ,
623                                         CORBA::Double             theH,
624                                         CORBA::Double             theR );
625
626   SMESH::long_array* GetInside( SMESH::SMESH_IDSource_ptr meshPart,
627                                 SMESH::ElementType        theElemType,
628                                 GEOM::GEOM_Object_ptr     theGeom,
629                                 CORBA::Double             theTolerance );
630
631 private:
632   // Get hypothesis creator
633   GenericHypothesisCreator_i* getHypothesisCreator( const char*  theHypName,
634                                                     const char*  theLibName,
635                                                     std::string& thePlatformLibName)
636   throw ( SALOME::SALOME_Exception );
637   // Create hypothesis of given type
638   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
639                                                 const char* theLibName);
640   // Create empty mesh on shape
641   SMESH::SMESH_Mesh_ptr createMesh()
642     throw ( SALOME::SALOME_Exception );
643
644   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
645
646   SMESH::mesh_array* CreateMeshesFromMEDorSAUV( const char* theFileName,
647                                                 SMESH::DriverMED_ReadStatus& theStatus,
648                                                 const char* theCommandNameForPython,
649                                                 const char* theFileNameForPython);
650
651   void setCurrentStudy( SALOMEDS::Study_ptr theStudy,
652                         bool                theStudyIsBeingClosed=false);
653
654   std::vector<long> _GetInside(SMESH::SMESH_IDSource_ptr meshPart,
655                                SMESH::ElementType     theElemType,
656                                TopoDS_Shape& aShape,
657                                double* theTolerance = NULL);
658
659 private:
660   static GEOM::GEOM_Gen_var      myGeomGen;
661   static CORBA::ORB_var          myOrb;         // ORB reference
662   static PortableServer::POA_var myPoa;         // POA reference
663   static SALOME_NamingService*   myNS;          // Naming Service
664   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
665   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
666   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
667
668   // hypotheses managing
669   std::map<std::string, GenericHypothesisCreator_i*> myHypCreatorMap;
670
671   std::map<int, StudyContext*>   myStudyContextMap;  // Map of study context objects
672
673   GEOM_Client*                   myShapeReader;      // Shape reader
674   SALOMEDS::Study_var            myCurrentStudy;     // Current study
675   CORBA::Boolean                 myIsEmbeddedMode;   // Current mode
676
677   // Default color of groups
678   std::string myDefaultGroupColor;
679
680   // To load full mesh data from study at hyp modification or not
681   bool myToForgetMeshDataOnHypModif;
682
683   // Dump Python: trace of API methods calls
684   std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
685   bool                                                     myIsHistoricalPythonDump;
686   std::vector< int >                                       myLastParamIndex;
687   std::vector< std::string >                               myLastParameters;
688   std::string                                              myLastObj;
689 };
690
691
692 namespace SMESH
693 {
694   template<class T>
695   T
696   DownCast(CORBA::Object_ptr theArg)
697   {
698     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
699   }
700
701   /*!
702    * \brief Function used in SMESH_CATCH to convert a caught exception to
703    * SALOME::SALOME_Exception
704    */
705   inline void throwCorbaException(const char* excText)
706   {
707     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
708   }
709 }
710
711
712 #endif