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