Salome HOME
Cherry-pick 254c2216: Python3 porting: fix the pb with creation of StdMeshersBuilder_...
[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
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( std::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( std::string theIOR )
82   {
83     std::map<int, std::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   std::string getIORbyId( const int theId )
92   {
93     if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
94       return mapIdToIOR[ theId ];
95     return std::string( "" );
96   }
97   // get object's IOR by old id
98   std::string getIORbyOldId( const int theOldId )
99   {
100     if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
101       return getIORbyId( mapIdToId[ theOldId ] );
102     return std::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     std::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   std::map<int, std::string> mapIdToIOR; // persistent-to-transient map
129   std::map<int, int>         mapIdToId;  // 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(CORBA::Object_ptr theObject);
158   // Get the SALOMEDS::Study from naming service
159   static SALOMEDS::Study_ptr getStudyServant();
160   // Get GEOM Object correspoding to TopoDS_Shape
161   GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
162   // Get TopoDS_Shape correspoding to GEOM_Object
163   TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
164
165   // Default constructor
166   SMESH_Gen_i();
167   // Standard constructor
168   SMESH_Gen_i( CORBA::ORB_ptr            orb,
169                PortableServer::POA_ptr   poa,
170                PortableServer::ObjectId* contId,
171                const char*               instanceName,
172                const char*               interfaceName );
173   // Destructor
174   virtual ~SMESH_Gen_i();
175
176   // *****************************************
177   // Interface methods
178   // *****************************************
179   // Set a new Mesh object name
180   void SetName(const char* theIOR,
181                const char* theName);
182
183   //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
184   void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
185
186   // Set embedded mode
187   void SetEmbeddedMode( CORBA::Boolean theMode );
188   // Check embedded mode
189   CORBA::Boolean IsEmbeddedMode();
190
191   // Set enable publishing in the study
192   void SetEnablePublish( CORBA::Boolean theIsEnablePublish );
193
194   // Check enable publishing
195   CORBA::Boolean IsEnablePublish();
196
197   // Update study
198   void UpdateStudy();
199
200   // Create hypothesis/algorothm of given type
201   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
202                                                 const char* theLibName)
203     throw ( SALOME::SALOME_Exception );
204
205   // Return hypothesis of given type holding parameter values of the existing mesh
206   SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char*           theHypType,
207                                                             const char*           theLibName,
208                                                             SMESH::SMESH_Mesh_ptr theMesh,
209                                                             GEOM::GEOM_Object_ptr theGeom,
210                                                             CORBA::Boolean        byMesh)
211     throw ( SALOME::SALOME_Exception );
212
213   /*
214    * Returns True if a hypothesis is assigned to a sole sub-mesh in a current Study
215    */
216   CORBA::Boolean GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp,
217                                          SMESH::SMESH_Mesh_out       theMesh,
218                                          GEOM::GEOM_Object_out       theShape);
219
220   // Preferences
221   // ------------
222   /*!
223    * Sets number of segments per diagonal of boundary box of geometry by which
224    * default segment length of appropriate 1D hypotheses is defined
225    */
226   void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
227   /*!
228    * \brief Sets default number of segments per edge
229    */
230   void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
231
232   /*!
233     Set an option value
234   */
235   virtual void  SetOption(const char*, const char*);
236   /*!
237     Return an option value
238   */
239   virtual char* GetOption(const char*);
240
241   /*!
242    * To load full mesh data from study at hyp modification or not
243    */
244   bool ToForgetMeshDataOnHypModif() const { return myToForgetMeshDataOnHypModif; }
245
246
247   // Create empty mesh on a shape
248   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
249     throw ( SALOME::SALOME_Exception );
250
251   // Create empty mesh
252   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
253     throw ( SALOME::SALOME_Exception );
254
255   //  Create a mesh and import data from an UNV file
256   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
257     throw ( SALOME::SALOME_Exception );
258
259   //  Create mesh(es) and import data from MED file
260   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
261                                           SMESH::DriverMED_ReadStatus& theStatus )
262     throw ( SALOME::SALOME_Exception );
263
264   //  Create mesh(es) and import data from MED file
265   SMESH::mesh_array* CreateMeshesFromSAUV( const char* theFileName,
266                                            SMESH::DriverMED_ReadStatus& theStatus )
267     throw ( SALOME::SALOME_Exception );
268
269   //  Create a mesh and import data from a STL file
270   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
271     throw ( SALOME::SALOME_Exception );
272
273   //  Create mesh(es) and import data from CGNS file
274   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
275                                            SMESH::DriverMED_ReadStatus& theStatus )
276     throw ( SALOME::SALOME_Exception );
277
278   //  Create a mesh and import data from a GMF file
279   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
280                                              CORBA::Boolean          theMakeRequiredGroups,
281                                              SMESH::ComputeError_out theError)
282     throw ( SALOME::SALOME_Exception );
283
284   // Copy a part of mesh
285   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
286                                  const char*               meshName,
287                                  CORBA::Boolean            toCopyGroups,
288                                  CORBA::Boolean            toKeepIDs);
289
290   // Compute mesh on a shape
291   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
292                           GEOM::GEOM_Object_ptr theShapeObject )
293     throw ( SALOME::SALOME_Exception );
294
295   // Cancel Compute mesh on a shape
296   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
297                       GEOM::GEOM_Object_ptr theShapeObject );
298
299   /*!
300    * \brief Return errors of mesh computation
301    */
302   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
303                                                GEOM::GEOM_Object_ptr  theShapeObject )
304     throw ( SALOME::SALOME_Exception );
305
306   /*!
307    * Evaluate mesh on a shape and
308    *  returns statistic of mesh elements
309    * Result array of number enityties
310    */
311   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
312                               GEOM::GEOM_Object_ptr theShapeObject)
313     throw ( SALOME::SALOME_Exception );
314
315   // Returns true if mesh contains enough data to be computed
316   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
317                                    GEOM::GEOM_Object_ptr theShapeObject )
318     throw ( SALOME::SALOME_Exception );
319
320   /*!
321    * Calculate Mesh as preview till indicated dimension on shape
322    * First, verify list of hypothesis associated with the subShape.
323    * Return mesh preview structure
324    */
325   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
326                                         GEOM::GEOM_Object_ptr theSubObject,
327                                         SMESH::Dimension      theDimension,
328                                         SMESH::long_array&    theShapesId )
329     throw ( SALOME::SALOME_Exception );
330
331   // Returns errors of hypotheses definintion
332   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
333                                          GEOM::GEOM_Object_ptr theSubObject )
334       throw ( SALOME::SALOME_Exception );
335
336   // Return mesh elements preventing computation of a subshape
337   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
338                                                  CORBA::Short          theSubShapeID )
339     throw ( SALOME::SALOME_Exception );
340
341   // Create groups of elements preventing computation of a sub-shape
342   SMESH::ListOfGroups* MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
343                                                      CORBA::Short          theSubShapeID,
344                                                      const char*           theGroupName)
345     throw ( SALOME::SALOME_Exception );
346
347   // Get sub-shapes unique ID's list
348   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
349                                      const SMESH::object_array& theListOfSubShape )
350     throw ( SALOME::SALOME_Exception );
351
352   // Return geometrical object the given element is built on. Publish it in study.
353   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
354                                                   CORBA::Long            theElementID,
355                                                   const char*            theGeomName)
356     throw ( SALOME::SALOME_Exception );
357
358   // Return geometrical object the given element is built on. Don't publish it in study.
359   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
360                                                    CORBA::Long            theElementID)
361     throw ( SALOME::SALOME_Exception );
362
363   // Concatenate the given meshes into one mesh
364   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
365                                           CORBA::Boolean                uniteIdenticalGroups,
366                                           CORBA::Boolean                mergeNodesAndElements,
367                                           CORBA::Double                 mergeTolerance,
368                                           CORBA::Boolean                commonGroups)
369     throw ( SALOME::SALOME_Exception );
370
371   // Concatenate the given meshes into one mesh
372   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
373                                     CORBA::Boolean                uniteIdenticalGroups,
374                                     CORBA::Boolean                mergeNodesAndElements,
375                                     CORBA::Double                 mergeTolerance)
376     throw ( SALOME::SALOME_Exception );
377
378   // Concatenate the given meshes into one mesh
379   // Create the groups of all elements from initial meshes
380   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
381                                               CORBA::Boolean                uniteIdenticalGroups,
382                                               CORBA::Boolean                mergeNodesAndElements,
383                                               CORBA::Double                 mergeTolerance)
384     throw ( SALOME::SALOME_Exception );
385
386   // Get version of MED format being used.
387   char* GetMEDFileVersion();
388
389   // Get MED version of the file by its name
390   char* GetMEDVersion(const char* theFileName);
391
392   // Check compatibility of file with MED format being used.
393   CORBA::Boolean CheckCompatibility(const char* theFileName);
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::SObject_ptr theSObject,
451                                         CORBA::Object_ptr     theObject,
452                                         const char*           theName )
453     throw ( SALOME::SALOME_Exception );
454
455   // Copy-paste methods - returns true if object can be copied to the clipboard
456   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
457   // Copy-paste methods - copy object to the clipboard
458   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return NULL; }
459   // Copy-paste methods - returns true if object can be pasted from the clipboard
460   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
461   // Copy-paste methods - paste object from the clipboard
462   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
463                                    CORBA::Long              theObjectID,
464                                    SALOMEDS::SObject_ptr    theObject ) {
465     SALOMEDS::SObject_var aResultSO;
466     return aResultSO._retn();
467   }
468
469   // ============
470   // Version information
471   // ============
472
473   virtual char* getVersion();
474
475   // ============
476   // Dump python
477   // ============
478
479   virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished,
480                                        CORBA::Boolean isMultiFile,
481                                        CORBA::Boolean& isValidScript);
482
483   void AddToPythonScript (const TCollection_AsciiString& theString);
484
485   void RemoveLastFromPythonScript();
486
487   void SavePython();
488
489   TCollection_AsciiString DumpPython_impl (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
490                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
491                                            bool isPublished,
492                                            bool isMultiFile,
493                                            bool isHistoricalDump,
494                                            bool& aValidScript,
495                                            TCollection_AsciiString& theSavedTrace);
496
497   TCollection_AsciiString GetNewPythonLines();
498
499   void CleanPythonTrace();
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();
530   SALOMEDS::SObject_ptr PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
531                                      const char*           theName = 0);
532   SALOMEDS::SObject_ptr PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
533                                            const char*                 theName = 0);
534   SALOMEDS::SObject_ptr PublishSubMesh (SMESH::SMESH_Mesh_ptr    theMesh,
535                                         SMESH::SMESH_subMesh_ptr theSubMesh,
536                                         GEOM::GEOM_Object_ptr    theShapeObject,
537                                         const char*              theName = 0);
538   SALOMEDS::SObject_ptr PublishGroup (SMESH::SMESH_Mesh_ptr  theMesh,
539                                       SMESH::SMESH_GroupBase_ptr theGroup,
540                                       GEOM::GEOM_Object_ptr  theShapeObject,
541                                       const char*            theName = 0);
542   bool AddHypothesisToShape(SMESH::SMESH_Mesh_ptr       theMesh,
543                             GEOM::GEOM_Object_ptr       theShapeObject,
544                             SMESH::SMESH_Hypothesis_ptr theHyp);
545   bool RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr       theMesh,
546                                  GEOM::GEOM_Object_ptr       theShapeObject,
547                                  SMESH::SMESH_Hypothesis_ptr theHyp);
548   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
549                                                  GEOM::GEOM_Object_ptr theShape);
550   static void SetName(SALOMEDS::SObject_ptr theSObject,
551                       const char*           theName,
552                       const char*           theDefaultName = 0);
553
554   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
555                         const char*           thePixMap);
556
557   //  Get study context
558   StudyContext* GetStudyContext();
559
560   // Register an object in a StudyContext; return object id
561   int RegisterObject(CORBA::Object_ptr theObject);
562
563   // Return id of registered object
564   CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
565
566   // Return an object that previously had an oldID
567   template<class TInterface>
568   typename TInterface::_var_type GetObjectByOldId( const int oldID )
569   {
570     if ( myStudyContext ) {
571       std::string ior = myStudyContext->getIORbyOldId( oldID );
572       if ( !ior.empty() )
573         return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
574     }
575     return TInterface::_nil();
576   }
577
578   /*!
579    * \brief Find SObject for an algo
580    */
581   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
582
583   void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
584   char* GetParameters(CORBA::Object_ptr theObject);
585   //char* ParseParameters(const char* theParameters);
586   const std::vector< int >&         GetLastParamIndices() const { return myLastParamIndex; }
587   const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
588   const std::string &               GetLastObjEntry() const { return myLastObj; }
589   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
590
591   // Move objects to the specified position
592   void Move( const SMESH::sobject_list& what,
593              SALOMEDS::SObject_ptr where,
594              CORBA::Long row );
595
596   CORBA::Boolean IsApplicable ( const char*           theAlgoType,
597                                 const char*           theLibName,
598                                 GEOM::GEOM_Object_ptr theShapeObject,
599                                 CORBA::Boolean        toCheckAll);
600
601   SMESH::long_array* GetInsideSphere( SMESH::SMESH_IDSource_ptr meshPart,
602                                       SMESH::ElementType        theElemType,
603                                       CORBA::Double             theX,
604                                       CORBA::Double             theY,
605                                       CORBA::Double             theZ,
606                                       CORBA::Double             theR);
607
608   SMESH::long_array* GetInsideBox( SMESH::SMESH_IDSource_ptr meshPart,
609                                    SMESH::ElementType        theElemType,
610                                    CORBA::Double             theX1,
611                                    CORBA::Double             theY1,
612                                    CORBA::Double             theZ1,
613                                    CORBA::Double             theX2,
614                                    CORBA::Double             theY2,
615                                    CORBA::Double             theZ2);
616
617   SMESH::long_array* GetInsideCylinder( SMESH::SMESH_IDSource_ptr meshPart,
618                                         SMESH::ElementType        theElemType,
619                                         CORBA::Double             theX,
620                                         CORBA::Double             theY,
621                                         CORBA::Double             theZ,
622                                         CORBA::Double             theDX,
623                                         CORBA::Double             theDY,
624                                         CORBA::Double             theDZ,
625                                         CORBA::Double             theH,
626                                         CORBA::Double             theR );
627
628   SMESH::long_array* GetInside( SMESH::SMESH_IDSource_ptr meshPart,
629                                 SMESH::ElementType        theElemType,
630                                 GEOM::GEOM_Object_ptr     theGeom,
631                                 CORBA::Double             theTolerance );
632
633 private:
634   // Get hypothesis creator
635   GenericHypothesisCreator_i* getHypothesisCreator( const char*  theHypName,
636                                                     const char*  theLibName,
637                                                     std::string& thePlatformLibName)
638   throw ( SALOME::SALOME_Exception );
639   // Create hypothesis of given type
640   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
641                                                 const char* theLibName);
642   // Create empty mesh on shape
643   SMESH::SMESH_Mesh_ptr createMesh()
644     throw ( SALOME::SALOME_Exception );
645
646   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
647
648   SMESH::mesh_array* CreateMeshesFromMEDorSAUV( const char* theFileName,
649                                                 SMESH::DriverMED_ReadStatus& theStatus,
650                                                 const char* theCommandNameForPython,
651                                                 const char* theFileNameForPython);
652
653   std::vector<long> _GetInside(SMESH::SMESH_IDSource_ptr meshPart,
654                                SMESH::ElementType     theElemType,
655                                TopoDS_Shape& aShape,
656                                double* theTolerance = NULL);
657
658 private:
659   static GEOM::GEOM_Gen_var      myGeomGen;
660   static CORBA::ORB_var          myOrb;         // ORB reference
661   static PortableServer::POA_var myPoa;         // POA reference
662   static SALOME_NamingService*   myNS;          // Naming Service
663   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
664   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
665   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
666
667   // hypotheses managing
668   std::map<std::string, GenericHypothesisCreator_i*> myHypCreatorMap;
669
670   StudyContext*                  myStudyContext;  // study context
671
672   GEOM_Client*                   myShapeReader;      // Shape reader
673   CORBA::Boolean                 myIsEmbeddedMode;   // Current mode
674   CORBA::Boolean                 myIsEnablePublish;  // Enable publishing
675
676   // Default color of groups
677   std::string myDefaultGroupColor;
678
679   // To load full mesh data from study at hyp modification or not
680   bool myToForgetMeshDataOnHypModif;
681
682   // Dump Python: trace of API methods calls
683   Handle(TColStd_HSequenceOfAsciiString) myPythonScript;
684   bool                                   myIsHistoricalPythonDump;
685   std::vector< int >                     myLastParamIndex;
686   std::vector< std::string >             myLastParameters;
687   std::string                            myLastObj;
688 };
689
690
691 namespace SMESH
692 {
693   template<class T>
694   T
695   DownCast(CORBA::Object_ptr theArg)
696   {
697     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
698   }
699
700   /*!
701    * \brief Function used in SMESH_CATCH to convert a caught exception to
702    * SALOME::SALOME_Exception
703    */
704   inline void throwCorbaException(const char* excText)
705   {
706     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
707   }
708 }
709
710
711 #endif