Salome HOME
Merge 'master' branch into 'V9_dev' branch.
[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     int id = 1;
121     while( mapIdToIOR.IsBound( id ) )
122       id++;
123     return id;
124   }
125
126   TInt2StringMap mapIdToIOR; // persistent-to-transient map
127   TInt2IntMap    mapIdToId;  // to translate object from persistent to transient form
128 };
129
130 // ===========================================================
131 // SMESH module's engine
132 // ==========================================================
133 class SMESH_I_EXPORT SMESH_Gen_i:
134   public virtual POA_SMESH::SMESH_Gen,
135   public virtual Engines_Component_i
136 {
137 public:
138   // Get last created instance of the class
139   static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
140   // Get ORB object
141   static CORBA::ORB_var GetORB() { return myOrb;}
142   // Get SMESH module's POA object
143   static PortableServer::POA_var GetPOA() { return myPoa;}
144   // Get Naming Service object
145   static SALOME_NamingService* GetNS();
146   // Get SALOME_LifeCycleCORBA object
147   static SALOME_LifeCycleCORBA* GetLCC();
148   // Retrieve and get GEOM engine reference
149   static GEOM::GEOM_Gen_var GetGeomEngine();
150   // Get object of the CORBA reference
151   static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
152   // Get CORBA object corresponding to the SALOMEDS::SObject
153   static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
154   // Get the SALOMEDS::SObject corresponding to a CORBA object
155   static SALOMEDS::SObject_ptr ObjectToSObject(CORBA::Object_ptr theObject);
156   // Get the SALOMEDS::Study from naming service
157   static SALOMEDS::Study_ptr getStudyServant();
158   // Get GEOM Object corresponding to TopoDS_Shape
159   GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
160   // Get TopoDS_Shape corresponding to GEOM_Object
161   TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
162
163   // Default constructor
164   SMESH_Gen_i();
165   // Standard constructor
166   SMESH_Gen_i( CORBA::ORB_ptr            orb,
167                PortableServer::POA_ptr   poa,
168                PortableServer::ObjectId* contId,
169                const char*               instanceName,
170                const char*               interfaceName );
171   // Destructor
172   virtual ~SMESH_Gen_i();
173
174   // *****************************************
175   // Interface methods
176   // *****************************************
177   // Set a new Mesh object name
178   void SetName(const char* theIOR,
179                const char* theName);
180
181   //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
182   void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
183
184   // Set embedded mode
185   void SetEmbeddedMode( CORBA::Boolean theMode );
186   // Check embedded mode
187   CORBA::Boolean IsEmbeddedMode();
188
189   // Set enable publishing in the study
190   void SetEnablePublish( CORBA::Boolean theIsEnablePublish );
191
192   // Check enable publishing
193   CORBA::Boolean IsEnablePublish();
194
195   // Update study
196   void UpdateStudy();
197
198   // Create hypothesis/algorothm of given type
199   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
200                                                 const char* theLibName)
201     throw ( SALOME::SALOME_Exception );
202
203   // Return hypothesis of given type holding parameter values of the existing mesh
204   SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char*           theHypType,
205                                                             const char*           theLibName,
206                                                             SMESH::SMESH_Mesh_ptr theMesh,
207                                                             GEOM::GEOM_Object_ptr theGeom,
208                                                             CORBA::Boolean        byMesh)
209     throw ( SALOME::SALOME_Exception );
210
211   /*
212    * Returns True if a hypothesis is assigned to a sole sub-mesh in a current Study
213    */
214   CORBA::Boolean GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp,
215                                          SMESH::SMESH_Mesh_out       theMesh,
216                                          GEOM::GEOM_Object_out       theShape);
217
218   // Preferences
219   // ------------
220   /*!
221    * Sets number of segments per diagonal of boundary box of geometry by which
222    * default segment length of appropriate 1D hypotheses is defined
223    */
224   void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
225   /*!
226    * \brief Sets default number of segments per edge
227    */
228   void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
229
230   /*!
231     Set an option value
232   */
233   virtual void  SetOption(const char*, const char*);
234   /*!
235     Return an option value
236   */
237   virtual char* GetOption(const char*);
238
239   /*!
240    * To load full mesh data from study at hyp modification or not
241    */
242   bool ToForgetMeshDataOnHypModif() const { return myToForgetMeshDataOnHypModif; }
243
244
245   // Create empty mesh on a shape
246   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
247     throw ( SALOME::SALOME_Exception );
248
249   // Create empty mesh
250   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
251     throw ( SALOME::SALOME_Exception );
252
253   //  Create a mesh and import data from an UNV file
254   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
255     throw ( SALOME::SALOME_Exception );
256
257   //  Create mesh(es) and import data from MED file
258   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
259                                           SMESH::DriverMED_ReadStatus& theStatus )
260     throw ( SALOME::SALOME_Exception );
261
262   //  Create mesh(es) and import data from MED file
263   SMESH::mesh_array* CreateMeshesFromSAUV( const char* theFileName,
264                                            SMESH::DriverMED_ReadStatus& theStatus )
265     throw ( SALOME::SALOME_Exception );
266
267   //  Create a mesh and import data from a STL file
268   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
269     throw ( SALOME::SALOME_Exception );
270
271   //  Create mesh(es) and import data from CGNS file
272   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
273                                            SMESH::DriverMED_ReadStatus& theStatus )
274     throw ( SALOME::SALOME_Exception );
275
276   //  Create a mesh and import data from a GMF file
277   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
278                                              CORBA::Boolean          theMakeRequiredGroups,
279                                              SMESH::ComputeError_out theError)
280     throw ( SALOME::SALOME_Exception );
281
282   // Copy a part of mesh
283   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
284                                  const char*               meshName,
285                                  CORBA::Boolean            toCopyGroups,
286                                  CORBA::Boolean            toKeepIDs);
287
288   // Compute mesh on a shape
289   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
290                           GEOM::GEOM_Object_ptr theShapeObject )
291     throw ( SALOME::SALOME_Exception );
292
293   // Cancel Compute mesh on a shape
294   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
295                       GEOM::GEOM_Object_ptr theShapeObject );
296
297   /*!
298    * \brief Return errors of mesh computation
299    */
300   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
301                                                GEOM::GEOM_Object_ptr  theShapeObject )
302     throw ( SALOME::SALOME_Exception );
303
304   /*!
305    * Evaluate mesh on a shape and
306    *  returns statistic of mesh elements
307    * Result array of number enityties
308    */
309   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
310                               GEOM::GEOM_Object_ptr theShapeObject)
311     throw ( SALOME::SALOME_Exception );
312
313   // Returns true if mesh contains enough data to be computed
314   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
315                                    GEOM::GEOM_Object_ptr theShapeObject )
316     throw ( SALOME::SALOME_Exception );
317
318   /*!
319    * Calculate Mesh as preview till indicated dimension on shape
320    * First, verify list of hypothesis associated with the subShape.
321    * Return mesh preview structure
322    */
323   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
324                                         GEOM::GEOM_Object_ptr theSubObject,
325                                         SMESH::Dimension      theDimension,
326                                         SMESH::long_array&    theShapesId )
327     throw ( SALOME::SALOME_Exception );
328
329   // Returns errors of hypotheses definition
330   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
331                                          GEOM::GEOM_Object_ptr theSubObject )
332       throw ( SALOME::SALOME_Exception );
333
334   // Return mesh elements preventing computation of a subshape
335   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
336                                                  CORBA::Short          theSubShapeID )
337     throw ( SALOME::SALOME_Exception );
338
339   // Create groups of elements preventing computation of a sub-shape
340   SMESH::ListOfGroups* MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
341                                                      CORBA::Short          theSubShapeID,
342                                                      const char*           theGroupName)
343     throw ( SALOME::SALOME_Exception );
344
345   // Get sub-shapes unique ID's list
346   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
347                                      const SMESH::object_array& theListOfSubShape )
348     throw ( SALOME::SALOME_Exception );
349
350   // Return geometrical object the given element is built on. Publish it in study.
351   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
352                                                   CORBA::Long            theElementID,
353                                                   const char*            theGeomName)
354     throw ( SALOME::SALOME_Exception );
355
356   // Return geometrical object the given element is built on. Don't publish it in study.
357   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
358                                                    CORBA::Long            theElementID)
359     throw ( SALOME::SALOME_Exception );
360
361   // Concatenate the given meshes into one mesh
362   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
363                                           CORBA::Boolean                uniteIdenticalGroups,
364                                           CORBA::Boolean                mergeNodesAndElements,
365                                           CORBA::Double                 mergeTolerance,
366                                           CORBA::Boolean                commonGroups)
367     throw ( SALOME::SALOME_Exception );
368
369   // Concatenate the given meshes into one mesh
370   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
371                                     CORBA::Boolean                uniteIdenticalGroups,
372                                     CORBA::Boolean                mergeNodesAndElements,
373                                     CORBA::Double                 mergeTolerance)
374     throw ( SALOME::SALOME_Exception );
375
376   // Concatenate the given meshes into one mesh
377   // Create the groups of all elements from initial meshes
378   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
379                                               CORBA::Boolean                uniteIdenticalGroups,
380                                               CORBA::Boolean                mergeNodesAndElements,
381                                               CORBA::Double                 mergeTolerance)
382     throw ( SALOME::SALOME_Exception );
383
384   // Get version of MED format being used.
385   char* GetMEDFileVersion();
386
387   // Get MED version of the file by its name
388   char* GetMEDVersion(const char* theFileName);
389
390   // Check compatibility of file with MED format being used.
391   CORBA::Boolean CheckCompatibility(const char* theFileName);
392
393   // Get names of meshes defined in file with the specified name
394   SMESH::string_array* GetMeshNames(const char* theFileName);
395
396   // ****************************************************
397   // Interface inherited methods (from SALOMEDS::Driver)
398   // ****************************************************
399
400   // Save SMESH data
401   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
402                          const char*              theURL,
403                          bool                     isMultiFile );
404   // Load SMESH data
405   bool Load( SALOMEDS::SComponent_ptr theComponent,
406              const SALOMEDS::TMPFile& theStream,
407              const char*              theURL,
408              bool                     isMultiFile );
409   // Save SMESH data in ASCII format
410   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
411                                 const char*              theURL,
412                                 bool                     isMultiFile );
413   // Load SMESH data in ASCII format
414   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
415                   const SALOMEDS::TMPFile& theStream,
416                   const char*              theURL,
417                   bool                     isMultiFile );
418
419   // Create filter manager
420   SMESH::FilterManager_ptr CreateFilterManager();
421
422   // Return a pattern mesher
423   SMESH::SMESH_Pattern_ptr GetPattern();
424
425   // Create measurement instance
426   SMESH::Measurements_ptr  CreateMeasurements();
427
428   // Clears study-connected data when it is closed
429   void Close( SALOMEDS::SComponent_ptr theComponent );
430
431   // Get component data type
432   char* ComponentDataType();
433
434   // Transform data from transient form to persistent
435   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
436                                 const char*           IORString,
437                                 CORBA::Boolean        isMultiFile,
438                                 CORBA::Boolean        isASCII );
439   // Transform data from persistent form to transient
440   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
441                                 const char*           aLocalPersistentID,
442                                 CORBA::Boolean        isMultiFile,
443                                 CORBA::Boolean        isASCII );
444
445   // Returns true if object can be published in the study
446   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
447   // Publish object in the study
448   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::SObject_ptr theSObject,
449                                         CORBA::Object_ptr     theObject,
450                                         const char*           theName )
451     throw ( SALOME::SALOME_Exception );
452
453   // Copy-paste methods - returns true if object can be copied to the clipboard
454   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
455   // Copy-paste methods - copy object to the clipboard
456   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return NULL; }
457   // Copy-paste methods - returns true if object can be pasted from the clipboard
458   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
459   // Copy-paste methods - paste object from the clipboard
460   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
461                                    CORBA::Long              theObjectID,
462                                    SALOMEDS::SObject_ptr    theObject ) {
463     SALOMEDS::SObject_var aResultSO;
464     return aResultSO._retn();
465   }
466
467   // ============
468   // Version information
469   // ============
470
471   virtual char* getVersion();
472
473   // ============
474   // Dump python
475   // ============
476
477   virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished,
478                                        CORBA::Boolean isMultiFile,
479                                        CORBA::Boolean& isValidScript);
480
481   void AddToPythonScript (const TCollection_AsciiString& theString);
482
483   void RemoveLastFromPythonScript();
484
485   void SavePython();
486
487   TCollection_AsciiString DumpPython_impl (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
488                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
489                                            bool isPublished,
490                                            bool isMultiFile,
491                                            bool isHistoricalDump,
492                                            bool& aValidScript,
493                                            TCollection_AsciiString& theSavedTrace);
494
495   TCollection_AsciiString GetNewPythonLines();
496
497   void CleanPythonTrace();
498
499   // *****************************************
500   // Internal methods
501   // *****************************************
502 public:
503   // Get shape reader
504   GEOM_Client* GetShapeReader();
505
506   // Tags definition
507   static long GetHypothesisRootTag();
508   static long GetAlgorithmsRootTag();
509   static long GetRefOnShapeTag();
510   static long GetRefOnAppliedHypothesisTag();
511   static long GetRefOnAppliedAlgorithmsTag();
512   static long GetSubMeshOnVertexTag();
513   static long GetSubMeshOnEdgeTag();
514   static long GetSubMeshOnFaceTag();
515   static long GetSubMeshOnSolidTag();
516   static long GetSubMeshOnCompoundTag();
517   static long GetSubMeshOnWireTag();
518   static long GetSubMeshOnShellTag();
519   static long GetNodeGroupsTag();
520   static long GetEdgeGroupsTag();
521   static long GetFaceGroupsTag();
522   static long GetVolumeGroupsTag();
523   static long Get0DElementsGroupsTag();
524   static long GetBallElementsGroupsTag();
525
526   // publishing methods
527   SALOMEDS::SComponent_ptr PublishComponent();
528   SALOMEDS::SObject_ptr PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
529                                      const char*           theName = 0);
530   SALOMEDS::SObject_ptr PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
531                                            const char*                 theName = 0);
532   SALOMEDS::SObject_ptr PublishSubMesh (SMESH::SMESH_Mesh_ptr    theMesh,
533                                         SMESH::SMESH_subMesh_ptr theSubMesh,
534                                         GEOM::GEOM_Object_ptr    theShapeObject,
535                                         const char*              theName = 0);
536   SALOMEDS::SObject_ptr PublishGroup (SMESH::SMESH_Mesh_ptr  theMesh,
537                                       SMESH::SMESH_GroupBase_ptr theGroup,
538                                       GEOM::GEOM_Object_ptr  theShapeObject,
539                                       const char*            theName = 0);
540   bool AddHypothesisToShape(SMESH::SMESH_Mesh_ptr       theMesh,
541                             GEOM::GEOM_Object_ptr       theShapeObject,
542                             SMESH::SMESH_Hypothesis_ptr theHyp);
543   bool RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr       theMesh,
544                                  GEOM::GEOM_Object_ptr       theShapeObject,
545                                  SMESH::SMESH_Hypothesis_ptr theHyp);
546   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
547                                                  GEOM::GEOM_Object_ptr theShape);
548   static void SetName(SALOMEDS::SObject_ptr theSObject,
549                       const char*           theName,
550                       const char*           theDefaultName = 0);
551
552   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
553                         const char*           thePixMap);
554
555   //  Get study context
556   StudyContext* GetStudyContext();
557
558   // Register an object in a StudyContext; return object id
559   int RegisterObject(CORBA::Object_ptr theObject);
560
561   // Return id of registered object
562   CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
563
564   // Return an object that previously had an oldID
565   template<class TInterface>
566     typename TInterface::_var_type GetObjectByOldId( const int oldID )
567   {
568     if ( myStudyContext ) {
569       std::string ior = myStudyContext->getIORbyOldId( oldID );
570       if ( !ior.empty() )
571         return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
572     }
573     return TInterface::_nil();
574   }
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   std::vector<long> _GetInside(SMESH::SMESH_IDSource_ptr meshPart,
652                                SMESH::ElementType     theElemType,
653                                TopoDS_Shape& aShape,
654                                double* theTolerance = NULL);
655
656 private:
657   static GEOM::GEOM_Gen_var      myGeomGen;
658   static CORBA::ORB_var          myOrb;         // ORB reference
659   static PortableServer::POA_var myPoa;         // POA reference
660   static SALOME_NamingService*   myNS;          // Naming Service
661   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
662   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
663   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
664
665   // hypotheses managing
666   std::map<std::string, GenericHypothesisCreator_i*> myHypCreatorMap;
667
668   StudyContext*                  myStudyContext;  // study context
669
670   GEOM_Client*                   myShapeReader;      // Shape reader
671   CORBA::Boolean                 myIsEmbeddedMode;   // Current mode
672   CORBA::Boolean                 myIsEnablePublish;  // Enable publishing
673
674   // Default color of groups
675   std::string myDefaultGroupColor;
676
677   // To load full mesh data from study at hyp modification or not
678   bool myToForgetMeshDataOnHypModif;
679
680   // Dump Python: trace of API methods calls
681   Handle(TColStd_HSequenceOfAsciiString) myPythonScript;
682   bool                                   myIsHistoricalPythonDump;
683   std::vector< int >                     myLastParamIndex;
684   std::vector< std::string >             myLastParameters;
685   std::string                            myLastObj;
686 };
687
688
689 namespace SMESH
690 {
691   template<class T>
692   T
693   DownCast(CORBA::Object_ptr theArg)
694   {
695     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
696   }
697
698   /*!
699    * \brief Function used in SMESH_CATCH to convert a caught exception to
700    * SALOME::SALOME_Exception
701    */
702   inline void throwCorbaException(const char* excText)
703   {
704     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
705   }
706 }
707
708
709 #endif