Salome HOME
1cc0ae4aa44d5172994d06c617c222c5d1064b1a
[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(CORBA::Object_ptr theObject);
153   // Get the SALOMEDS::Study from naming service
154   static SALOMEDS::Study_ptr getStudyServant();
155   // Get GEOM Object corresponding to TopoDS_Shape
156   GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
157   // Get TopoDS_Shape corresponding to GEOM_Object
158   TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
159
160   // Default constructor
161   SMESH_Gen_i();
162   // Standard constructor
163   SMESH_Gen_i( CORBA::ORB_ptr            orb,
164                PortableServer::POA_ptr   poa,
165                PortableServer::ObjectId* contId,
166                const char*               instanceName,
167                const char*               interfaceName );
168   // Destructor
169   virtual ~SMESH_Gen_i();
170
171   // *****************************************
172   // Interface methods
173   // *****************************************
174   // Set a new Mesh object name
175   void SetName(const char* theIOR,
176                const char* theName);
177
178   //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
179   void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
180
181   // Set embedded mode
182   void SetEmbeddedMode( CORBA::Boolean theMode );
183   // Check embedded mode
184   CORBA::Boolean IsEmbeddedMode();
185
186   // Set enable publishing in the study
187   void SetEnablePublish( CORBA::Boolean theIsEnablePublish );
188
189   // Check enable publishing
190   CORBA::Boolean IsEnablePublish();
191
192   // Update study
193   void UpdateStudy();
194
195   // Create hypothesis/algorothm of given type
196   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
197                                                 const char* theLibName)
198     throw ( SALOME::SALOME_Exception );
199
200   // Return hypothesis of given type holding parameter values of the existing mesh
201   SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char*           theHypType,
202                                                             const char*           theLibName,
203                                                             SMESH::SMESH_Mesh_ptr theMesh,
204                                                             GEOM::GEOM_Object_ptr theGeom,
205                                                             CORBA::Boolean        byMesh)
206     throw ( SALOME::SALOME_Exception );
207
208   /*
209    * Returns True if a hypothesis is assigned to a sole sub-mesh in a current Study
210    */
211   CORBA::Boolean GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp,
212                                          SMESH::SMESH_Mesh_out       theMesh,
213                                          GEOM::GEOM_Object_out       theShape);
214
215   // Preferences
216   // ------------
217   /*!
218    * Sets number of segments per diagonal of boundary box of geometry by which
219    * default segment length of appropriate 1D hypotheses is defined
220    */
221   void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
222   /*!
223    * \brief Sets default number of segments per edge
224    */
225   void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
226
227   /*!
228     Set an option value
229   */
230   virtual void  SetOption(const char*, const char*);
231   /*!
232     Return an option value
233   */
234   virtual char* GetOption(const char*);
235
236   /*!
237    * To load full mesh data from study at hyp modification or not
238    */
239   bool ToForgetMeshDataOnHypModif() const { return myToForgetMeshDataOnHypModif; }
240
241
242   // Create empty mesh on a shape
243   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
244     throw ( SALOME::SALOME_Exception );
245
246   // Create empty mesh
247   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
248     throw ( SALOME::SALOME_Exception );
249
250   //  Create a mesh and import data from an UNV file
251   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
252     throw ( SALOME::SALOME_Exception );
253
254   //  Create mesh(es) and import data from MED file
255   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
256                                           SMESH::DriverMED_ReadStatus& theStatus )
257     throw ( SALOME::SALOME_Exception );
258
259   //  Create mesh(es) and import data from MED file
260   SMESH::mesh_array* CreateMeshesFromSAUV( const char* theFileName,
261                                            SMESH::DriverMED_ReadStatus& theStatus )
262     throw ( SALOME::SALOME_Exception );
263
264   //  Create a mesh and import data from a STL file
265   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
266     throw ( SALOME::SALOME_Exception );
267
268   //  Create mesh(es) and import data from CGNS file
269   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
270                                            SMESH::DriverMED_ReadStatus& theStatus )
271     throw ( SALOME::SALOME_Exception );
272
273   //  Create a mesh and import data from a GMF file
274   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
275                                              CORBA::Boolean          theMakeRequiredGroups,
276                                              SMESH::ComputeError_out theError)
277     throw ( SALOME::SALOME_Exception );
278
279   // Copy a part of mesh
280   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
281                                  const char*               meshName,
282                                  CORBA::Boolean            toCopyGroups,
283                                  CORBA::Boolean            toKeepIDs);
284
285   // Compute mesh on a shape
286   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
287                           GEOM::GEOM_Object_ptr theShapeObject )
288     throw ( SALOME::SALOME_Exception );
289
290   // Cancel Compute mesh on a shape
291   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
292                       GEOM::GEOM_Object_ptr theShapeObject );
293
294   /*!
295    * \brief Return errors of mesh computation
296    */
297   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
298                                                GEOM::GEOM_Object_ptr  theShapeObject )
299     throw ( SALOME::SALOME_Exception );
300
301   /*!
302    * Evaluate mesh on a shape and
303    *  returns statistic of mesh elements
304    * Result array of number enityties
305    */
306   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
307                               GEOM::GEOM_Object_ptr theShapeObject)
308     throw ( SALOME::SALOME_Exception );
309
310   // Returns true if mesh contains enough data to be computed
311   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
312                                    GEOM::GEOM_Object_ptr theShapeObject )
313     throw ( SALOME::SALOME_Exception );
314
315   /*!
316    * Calculate Mesh as preview till indicated dimension on shape
317    * First, verify list of hypothesis associated with the subShape.
318    * Return mesh preview structure
319    */
320   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
321                                         GEOM::GEOM_Object_ptr theSubObject,
322                                         SMESH::Dimension      theDimension,
323                                         SMESH::long_array&    theShapesId )
324     throw ( SALOME::SALOME_Exception );
325
326   // Returns errors of hypotheses definition
327   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
328                                          GEOM::GEOM_Object_ptr theSubObject )
329       throw ( SALOME::SALOME_Exception );
330
331   // Return mesh elements preventing computation of a subshape
332   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
333                                                  CORBA::Short          theSubShapeID )
334     throw ( SALOME::SALOME_Exception );
335
336   // Create groups of elements preventing computation of a sub-shape
337   SMESH::ListOfGroups* MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
338                                                      CORBA::Short          theSubShapeID,
339                                                      const char*           theGroupName)
340     throw ( SALOME::SALOME_Exception );
341
342   // Get sub-shapes unique ID's list
343   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
344                                      const SMESH::object_array& theListOfSubShape )
345     throw ( SALOME::SALOME_Exception );
346
347   // Return geometrical object the given element is built on. Publish it in study.
348   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
349                                                   CORBA::Long            theElementID,
350                                                   const char*            theGeomName)
351     throw ( SALOME::SALOME_Exception );
352
353   // Return geometrical object the given element is built on. Don't publish it in study.
354   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
355                                                    CORBA::Long            theElementID)
356     throw ( SALOME::SALOME_Exception );
357
358   // Concatenate the given meshes into one mesh
359   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
360                                           CORBA::Boolean                uniteIdenticalGroups,
361                                           CORBA::Boolean                mergeNodesAndElements,
362                                           CORBA::Double                 mergeTolerance,
363                                           CORBA::Boolean                commonGroups)
364     throw ( SALOME::SALOME_Exception );
365
366   // Concatenate the given meshes into one mesh
367   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
368                                     CORBA::Boolean                uniteIdenticalGroups,
369                                     CORBA::Boolean                mergeNodesAndElements,
370                                     CORBA::Double                 mergeTolerance)
371     throw ( SALOME::SALOME_Exception );
372
373   // Concatenate the given meshes into one mesh
374   // Create the groups of all elements from initial meshes
375   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
376                                               CORBA::Boolean                uniteIdenticalGroups,
377                                               CORBA::Boolean                mergeNodesAndElements,
378                                               CORBA::Double                 mergeTolerance)
379     throw ( SALOME::SALOME_Exception );
380
381   // Get version of MED format being used.
382   char* GetMEDFileVersion();
383
384   // Get MED version of the file by its name
385   char* GetMEDVersion(const char* theFileName);
386
387   // Check compatibility of file with MED format being used.
388   CORBA::Boolean CheckCompatibility(const char* theFileName);
389
390   // Get names of meshes defined in file with the specified name
391   SMESH::string_array* GetMeshNames(const char* theFileName);
392
393   // ****************************************************
394   // Interface inherited methods (from SALOMEDS::Driver)
395   // ****************************************************
396
397   // Save SMESH data
398   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
399                          const char*              theURL,
400                          bool                     isMultiFile );
401   // Load SMESH data
402   bool Load( SALOMEDS::SComponent_ptr theComponent,
403              const SALOMEDS::TMPFile& theStream,
404              const char*              theURL,
405              bool                     isMultiFile );
406   // Save SMESH data in ASCII format
407   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
408                                 const char*              theURL,
409                                 bool                     isMultiFile );
410   // Load SMESH data in ASCII format
411   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
412                   const SALOMEDS::TMPFile& theStream,
413                   const char*              theURL,
414                   bool                     isMultiFile );
415
416   // Create filter manager
417   SMESH::FilterManager_ptr CreateFilterManager();
418
419   // Return a pattern mesher
420   SMESH::SMESH_Pattern_ptr GetPattern();
421
422   // Create measurement instance
423   SMESH::Measurements_ptr  CreateMeasurements();
424
425   // Clears study-connected data when it is closed
426   void Close( SALOMEDS::SComponent_ptr theComponent );
427
428   // Get component data type
429   char* ComponentDataType();
430
431   // Transform data from transient form to persistent
432   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
433                                 const char*           IORString,
434                                 CORBA::Boolean        isMultiFile,
435                                 CORBA::Boolean        isASCII );
436   // Transform data from persistent form to transient
437   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
438                                 const char*           aLocalPersistentID,
439                                 CORBA::Boolean        isMultiFile,
440                                 CORBA::Boolean        isASCII );
441
442   // Returns true if object can be published in the study
443   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
444   // Publish object in the study
445   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::SObject_ptr theSObject,
446                                         CORBA::Object_ptr     theObject,
447                                         const char*           theName )
448     throw ( SALOME::SALOME_Exception );
449
450   // Copy-paste methods - returns true if object can be copied to the clipboard
451   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
452   // Copy-paste methods - copy object to the clipboard
453   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return NULL; }
454   // Copy-paste methods - returns true if object can be pasted from the clipboard
455   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
456   // Copy-paste methods - paste object from the clipboard
457   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
458                                    CORBA::Long              theObjectID,
459                                    SALOMEDS::SObject_ptr    theObject ) {
460     SALOMEDS::SObject_var aResultSO;
461     return aResultSO._retn();
462   }
463
464   // ============
465   // Version information
466   // ============
467
468   virtual char* getVersion();
469
470   // ============
471   // Dump python
472   // ============
473
474   virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished,
475                                        CORBA::Boolean isMultiFile,
476                                        CORBA::Boolean& isValidScript);
477
478   void AddToPythonScript (const TCollection_AsciiString& theString);
479
480   void RemoveLastFromPythonScript();
481
482   void SavePython();
483
484   TCollection_AsciiString DumpPython_impl (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
485                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
486                                            bool isPublished,
487                                            bool isMultiFile,
488                                            bool isHistoricalDump,
489                                            bool& aValidScript,
490                                            TCollection_AsciiString& theSavedTrace);
491
492   TCollection_AsciiString GetNewPythonLines();
493
494   void CleanPythonTrace();
495
496   // *****************************************
497   // Internal methods
498   // *****************************************
499 public:
500   // Get shape reader
501   GEOM_Client* GetShapeReader();
502
503   // Tags definition
504   static long GetHypothesisRootTag();
505   static long GetAlgorithmsRootTag();
506   static long GetRefOnShapeTag();
507   static long GetRefOnAppliedHypothesisTag();
508   static long GetRefOnAppliedAlgorithmsTag();
509   static long GetSubMeshOnVertexTag();
510   static long GetSubMeshOnEdgeTag();
511   static long GetSubMeshOnFaceTag();
512   static long GetSubMeshOnSolidTag();
513   static long GetSubMeshOnCompoundTag();
514   static long GetSubMeshOnWireTag();
515   static long GetSubMeshOnShellTag();
516   static long GetNodeGroupsTag();
517   static long GetEdgeGroupsTag();
518   static long GetFaceGroupsTag();
519   static long GetVolumeGroupsTag();
520   static long Get0DElementsGroupsTag();
521   static long GetBallElementsGroupsTag();
522
523   // publishing methods
524   SALOMEDS::SComponent_ptr PublishComponent();
525   SALOMEDS::SObject_ptr PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
526                                      const char*           theName = 0);
527   SALOMEDS::SObject_ptr PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
528                                            const char*                 theName = 0);
529   SALOMEDS::SObject_ptr PublishSubMesh (SMESH::SMESH_Mesh_ptr    theMesh,
530                                         SMESH::SMESH_subMesh_ptr theSubMesh,
531                                         GEOM::GEOM_Object_ptr    theShapeObject,
532                                         const char*              theName = 0);
533   SALOMEDS::SObject_ptr PublishGroup (SMESH::SMESH_Mesh_ptr  theMesh,
534                                       SMESH::SMESH_GroupBase_ptr theGroup,
535                                       GEOM::GEOM_Object_ptr  theShapeObject,
536                                       const char*            theName = 0);
537   bool AddHypothesisToShape(SMESH::SMESH_Mesh_ptr       theMesh,
538                             GEOM::GEOM_Object_ptr       theShapeObject,
539                             SMESH::SMESH_Hypothesis_ptr theHyp);
540   bool RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr       theMesh,
541                                  GEOM::GEOM_Object_ptr       theShapeObject,
542                                  SMESH::SMESH_Hypothesis_ptr theHyp);
543   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (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* GetStudyContext();
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 ( myStudyContext ) {
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   /*!
574    * \brief Find SObject for an algo
575    */
576   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
577
578   void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
579   char* GetParameters(CORBA::Object_ptr theObject);
580   //char* ParseParameters(const char* theParameters);
581   const std::vector< int >&         GetLastParamIndices() const { return myLastParamIndex; }
582   const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
583   const std::string &               GetLastObjEntry() const { return myLastObj; }
584   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
585
586   // Move objects to the specified position
587   void Move( const SMESH::sobject_list& what,
588              SALOMEDS::SObject_ptr where,
589              CORBA::Long row );
590
591   CORBA::Boolean IsApplicable ( const char*           theAlgoType,
592                                 const char*           theLibName,
593                                 GEOM::GEOM_Object_ptr theShapeObject,
594                                 CORBA::Boolean        toCheckAll);
595
596   SMESH::long_array* GetInsideSphere( SMESH::SMESH_IDSource_ptr meshPart,
597                                       SMESH::ElementType        theElemType,
598                                       CORBA::Double             theX,
599                                       CORBA::Double             theY,
600                                       CORBA::Double             theZ,
601                                       CORBA::Double             theR);
602
603   SMESH::long_array* GetInsideBox( SMESH::SMESH_IDSource_ptr meshPart,
604                                    SMESH::ElementType        theElemType,
605                                    CORBA::Double             theX1,
606                                    CORBA::Double             theY1,
607                                    CORBA::Double             theZ1,
608                                    CORBA::Double             theX2,
609                                    CORBA::Double             theY2,
610                                    CORBA::Double             theZ2);
611
612   SMESH::long_array* GetInsideCylinder( SMESH::SMESH_IDSource_ptr meshPart,
613                                         SMESH::ElementType        theElemType,
614                                         CORBA::Double             theX,
615                                         CORBA::Double             theY,
616                                         CORBA::Double             theZ,
617                                         CORBA::Double             theDX,
618                                         CORBA::Double             theDY,
619                                         CORBA::Double             theDZ,
620                                         CORBA::Double             theH,
621                                         CORBA::Double             theR );
622
623   SMESH::long_array* GetInside( SMESH::SMESH_IDSource_ptr meshPart,
624                                 SMESH::ElementType        theElemType,
625                                 GEOM::GEOM_Object_ptr     theGeom,
626                                 CORBA::Double             theTolerance );
627
628 private:
629   // Get hypothesis creator
630   GenericHypothesisCreator_i* getHypothesisCreator( const char*  theHypName,
631                                                     const char*  theLibName,
632                                                     std::string& thePlatformLibName)
633   throw ( SALOME::SALOME_Exception );
634   // Create hypothesis of given type
635   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
636                                                 const char* theLibName);
637   // Create empty mesh on shape
638   SMESH::SMESH_Mesh_ptr createMesh()
639     throw ( SALOME::SALOME_Exception );
640
641   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
642
643   SMESH::mesh_array* CreateMeshesFromMEDorSAUV( const char* theFileName,
644                                                 SMESH::DriverMED_ReadStatus& theStatus,
645                                                 const char* theCommandNameForPython,
646                                                 const char* theFileNameForPython);
647
648   std::vector<long> _GetInside(SMESH::SMESH_IDSource_ptr meshPart,
649                                SMESH::ElementType     theElemType,
650                                TopoDS_Shape& aShape,
651                                double* theTolerance = NULL);
652
653 private:
654   static GEOM::GEOM_Gen_var      myGeomGen;
655   static CORBA::ORB_var          myOrb;         // ORB reference
656   static PortableServer::POA_var myPoa;         // POA reference
657   static SALOME_NamingService*   myNS;          // Naming Service
658   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
659   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
660   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
661
662   // hypotheses managing
663   std::map<std::string, GenericHypothesisCreator_i*> myHypCreatorMap;
664
665   StudyContext*                  myStudyContext;  // study context
666
667   GEOM_Client*                   myShapeReader;      // Shape reader
668   CORBA::Boolean                 myIsEmbeddedMode;   // Current mode
669   CORBA::Boolean                 myIsEnablePublish;  // Enable publishing
670
671   // Default color of groups
672   std::string myDefaultGroupColor;
673
674   // To load full mesh data from study at hyp modification or not
675   bool myToForgetMeshDataOnHypModif;
676
677   // Dump Python: trace of API methods calls
678   Handle(TColStd_HSequenceOfAsciiString) myPythonScript;
679   bool                                   myIsHistoricalPythonDump;
680   std::vector< int >                     myLastParamIndex;
681   std::vector< std::string >             myLastParameters;
682   std::string                            myLastObj;
683 };
684
685
686 namespace SMESH
687 {
688   template<class T>
689   T
690   DownCast(CORBA::Object_ptr theArg)
691   {
692     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
693   }
694
695   /*!
696    * \brief Function used in SMESH_CATCH to convert a caught exception to
697    * SALOME::SALOME_Exception
698    */
699   inline void throwCorbaException(const char* excText)
700   {
701     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
702   }
703 }
704
705
706 #endif