Salome HOME
New mesh icon if geometry changes
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.hxx
1 // Copyright (C) 2007-2019  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 - store 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   // register object in the internal map and return its id
71   int         addObject( const std::string& theIOR );
72   // find the object id in the internal map by the IOR
73   int         findId( const std::string& theIOR );
74   // get object's IOR by id
75   std::string getIORbyId( const int theId );
76   // get object's IOR by old id
77   std::string getIORbyOldId( const int theOldId );
78   // maps old object id to the new one (used when restoring data)
79   void        mapOldToNew( const int oldId, const int newId );
80   // get old id by a new one
81   int         getOldId( const int newId );
82   // clear data
83   void        Clear();
84
85 private:
86   // get next free object identifier
87   int         getNextId() { return mapIdToIOR.Extent() + 1; }
88
89   TInt2StringMap mapIdToIOR; // persistent-to-transient map
90   TInt2IntMap    mapIdToId;  // to translate object from persistent to transient form
91 };
92
93 // ===========================================================
94 // SMESH module's engine
95 // ==========================================================
96 class SMESH_I_EXPORT SMESH_Gen_i:
97   public virtual POA_SMESH::SMESH_Gen,
98   public virtual Engines_Component_i
99 {
100 public:
101   // Get last created instance of the class
102   static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
103   // Get ORB object
104   static CORBA::ORB_var GetORB() { return myOrb;}
105   // Get SMESH module's POA object
106   static PortableServer::POA_var GetPOA() { return myPoa;}
107   // Get Naming Service object
108   static SALOME_NamingService* GetNS();
109   // Get SALOME_LifeCycleCORBA object
110   static SALOME_LifeCycleCORBA* GetLCC();
111   // Retrieve and get GEOM engine reference
112   static GEOM::GEOM_Gen_var GetGeomEngine( bool isShaper );
113   static GEOM::GEOM_Gen_var GetGeomEngine( GEOM::GEOM_Object_ptr );
114   // Get object of the CORBA reference
115   static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
116   // Get CORBA object corresponding to the SALOMEDS::SObject
117   static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
118   // Get the SALOMEDS::SObject corresponding to a CORBA object
119   static SALOMEDS::SObject_ptr ObjectToSObject(CORBA::Object_ptr theObject);
120   // Get the SALOMEDS::Study from naming service
121   static SALOMEDS::Study_var getStudyServant();
122   // Get GEOM Object corresponding to TopoDS_Shape
123   GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
124   // Get TopoDS_Shape corresponding to GEOM_Object
125   TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
126
127   // Default constructor
128   SMESH_Gen_i();
129   // Standard constructor
130   SMESH_Gen_i( CORBA::ORB_ptr            orb,
131                PortableServer::POA_ptr   poa,
132                PortableServer::ObjectId* contId,
133                const char*               instanceName,
134                const char*               interfaceName );
135   // Destructor
136   virtual ~SMESH_Gen_i();
137
138   // *****************************************
139   // Interface methods
140   // *****************************************
141   // Set a new Mesh object name
142   void SetName(const char* theIOR,
143                const char* theName);
144
145   //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
146   void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
147
148   // Set embedded mode
149   void SetEmbeddedMode( CORBA::Boolean theMode );
150   // Check embedded mode
151   CORBA::Boolean IsEmbeddedMode();
152
153   // Set enable publishing in the study
154   void SetEnablePublish( CORBA::Boolean theIsEnablePublish );
155
156   // Check enable publishing
157   CORBA::Boolean IsEnablePublish();
158
159   // Update study
160   void UpdateStudy();
161
162   // Do provide info on objects
163   bool hasObjectInfo();
164
165   // Return an information for a given object
166   char* getObjectInfo(const char* entry);
167
168   // Create hypothesis/algorithm of given type
169   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
170                                                 const char* theLibName)
171     throw ( SALOME::SALOME_Exception );
172
173   // Return hypothesis of given type holding parameter values of the existing mesh
174   SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char*           theHypType,
175                                                             const char*           theLibName,
176                                                             SMESH::SMESH_Mesh_ptr theMesh,
177                                                             GEOM::GEOM_Object_ptr theGeom,
178                                                             CORBA::Boolean        byMesh)
179     throw ( SALOME::SALOME_Exception );
180
181   /*
182    * Returns True if a hypothesis is assigned to a sole sub-mesh in a current Study
183    */
184   CORBA::Boolean GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp,
185                                          SMESH::SMESH_Mesh_out       theMesh,
186                                          GEOM::GEOM_Object_out       theShape);
187
188   // Preferences
189   // ------------
190   /*!
191    * Sets number of segments per diagonal of boundary box of geometry by which
192    * default segment length of appropriate 1D hypotheses is defined
193    */
194   void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
195   /*!
196    * \brief Sets default number of segments per edge
197    */
198   void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
199
200   /*!
201     Set an option value
202   */
203   virtual void  SetOption(const char*, const char*);
204   /*!
205     Return an option value
206   */
207   virtual char* GetOption(const char*);
208
209   /*!
210    * To load full mesh data from study at hyp modification or not
211    */
212   bool ToForgetMeshDataOnHypModif() const { return myToForgetMeshDataOnHypModif; }
213
214
215   // Create empty mesh on a shape
216   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
217     throw ( SALOME::SALOME_Exception );
218
219   // Create empty mesh
220   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
221     throw ( SALOME::SALOME_Exception );
222
223   //  Create a mesh and import data from an UNV file
224   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
225     throw ( SALOME::SALOME_Exception );
226
227   //  Create mesh(es) and import data from MED file
228   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
229                                           SMESH::DriverMED_ReadStatus& theStatus )
230     throw ( SALOME::SALOME_Exception );
231
232   //  Create mesh(es) and import data from MED file
233   SMESH::mesh_array* CreateMeshesFromSAUV( const char* theFileName,
234                                            SMESH::DriverMED_ReadStatus& theStatus )
235     throw ( SALOME::SALOME_Exception );
236
237   //  Create a mesh and import data from a STL file
238   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
239     throw ( SALOME::SALOME_Exception );
240
241   //  Create mesh(es) and import data from CGNS file
242   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
243                                            SMESH::DriverMED_ReadStatus& theStatus )
244     throw ( SALOME::SALOME_Exception );
245
246   //  Create a mesh and import data from a GMF file
247   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
248                                              CORBA::Boolean          theMakeRequiredGroups,
249                                              SMESH::ComputeError_out theError)
250     throw ( SALOME::SALOME_Exception );
251
252   // Copy a part of mesh
253   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
254                                  const char*               meshName,
255                                  CORBA::Boolean            toCopyGroups,
256                                  CORBA::Boolean            toKeepIDs)
257     throw ( SALOME::SALOME_Exception );
258
259   // Create a mesh by copying definitions of another mesh to a given geometry
260   CORBA::Boolean CopyMeshWithGeom( SMESH::SMESH_Mesh_ptr       sourceMesh,
261                                    GEOM::GEOM_Object_ptr       newGeometry,
262                                    const char*                 meshName,
263                                    CORBA::Boolean              toCopyGroups,
264                                    CORBA::Boolean              toReuseHypotheses,
265                                    CORBA::Boolean              toCopyElements,
266                                    SMESH::SMESH_Mesh_out       newMesh,
267                                    SMESH::ListOfGroups_out     newGroups,
268                                    SMESH::submesh_array_out    newSubmeshes,
269                                    SMESH::ListOfHypothesis_out newHypotheses,
270                                    SMESH::string_array_out     invalidEntries)
271     throw ( SALOME::SALOME_Exception );
272
273     // Compute mesh on a shape
274   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
275                           GEOM::GEOM_Object_ptr theShapeObject )
276     throw ( SALOME::SALOME_Exception );
277
278   // Cancel Compute mesh on a shape
279   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
280                       GEOM::GEOM_Object_ptr theShapeObject );
281
282   /*!
283    * \brief Return errors of mesh computation
284    */
285   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
286                                                GEOM::GEOM_Object_ptr  theShapeObject )
287     throw ( SALOME::SALOME_Exception );
288
289   /*!
290    * Evaluate mesh on a shape and
291    *  returns statistic of mesh elements
292    * Result array of number enityties
293    */
294   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
295                               GEOM::GEOM_Object_ptr theShapeObject)
296     throw ( SALOME::SALOME_Exception );
297
298   // Returns true if mesh contains enough data to be computed
299   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
300                                    GEOM::GEOM_Object_ptr theShapeObject )
301     throw ( SALOME::SALOME_Exception );
302
303   /*!
304    * Calculate Mesh as preview till indicated dimension on shape
305    * First, verify list of hypothesis associated with the subShape.
306    * Return mesh preview structure
307    */
308   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
309                                         GEOM::GEOM_Object_ptr theSubObject,
310                                         SMESH::Dimension      theDimension,
311                                         SMESH::long_array&    theShapesId )
312     throw ( SALOME::SALOME_Exception );
313
314   // Returns errors of hypotheses definition
315   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
316                                          GEOM::GEOM_Object_ptr theSubObject )
317     throw ( SALOME::SALOME_Exception );
318
319   // Return mesh elements preventing computation of a subshape
320   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
321                                                  CORBA::Short          theSubShapeID )
322     throw ( SALOME::SALOME_Exception );
323
324   // Create groups of elements preventing computation of a sub-shape
325   SMESH::ListOfGroups* MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
326                                                      CORBA::Short          theSubShapeID,
327                                                      const char*           theGroupName)
328     throw ( SALOME::SALOME_Exception );
329
330   // Get sub-shapes unique ID's list
331   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
332                                      const SMESH::object_array& theListOfSubShape )
333     throw ( SALOME::SALOME_Exception );
334
335   // Return geometrical object the given element is built on. Publish it in study.
336   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
337                                                   CORBA::Long            theElementID,
338                                                   const char*            theGeomName)
339     throw ( SALOME::SALOME_Exception );
340
341   // Return geometrical object the given element is built on. Don't publish it in study.
342   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
343                                                    CORBA::Long            theElementID)
344     throw ( SALOME::SALOME_Exception );
345
346   // Concatenate the given meshes into one mesh
347   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
348                                           CORBA::Boolean                uniteIdenticalGroups,
349                                           CORBA::Boolean                mergeNodesAndElements,
350                                           CORBA::Double                 mergeTolerance,
351                                           CORBA::Boolean                commonGroups,
352                                           SMESH::SMESH_Mesh_ptr         meshToAppendTo)
353     throw ( SALOME::SALOME_Exception );
354
355   // Concatenate the given meshes into one mesh
356   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
357                                     CORBA::Boolean                uniteIdenticalGroups,
358                                     CORBA::Boolean                mergeNodesAndElements,
359                                     CORBA::Double                 mergeTolerance,
360                                     SMESH::SMESH_Mesh_ptr         meshToAppendTo)
361     throw ( SALOME::SALOME_Exception );
362
363   // Concatenate the given meshes into one mesh
364   // Create the groups of all elements from initial meshes
365   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
366                                               CORBA::Boolean                uniteIdenticalGroups,
367                                               CORBA::Boolean                mergeNodesAndElements,
368                                               CORBA::Double                 mergeTolerance,
369                                               SMESH::SMESH_Mesh_ptr         meshToAppendTo)
370     throw ( SALOME::SALOME_Exception );
371
372   // Get version of MED format being used.
373   char* GetMEDFileVersion();
374
375   // Get MED version of the file by its name
376   char* GetMEDVersion(const char* theFileName);
377
378   // Check compatibility of file with MED format being used, read only.
379   CORBA::Boolean CheckCompatibility(const char* theFileName);
380
381   // Check compatibility of file with MED format being used, for append on write.
382   CORBA::Boolean CheckWriteCompatibility(const char* theFileName);
383
384   // Get names of meshes defined in file with the specified name
385   SMESH::string_array* GetMeshNames(const char* theFileName);
386
387   // ****************************************************
388   // Interface inherited methods (from SALOMEDS::Driver)
389   // ****************************************************
390
391   // Save SMESH data
392   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
393                          const char*              theURL,
394                          bool                     isMultiFile );
395   // Load SMESH data
396   bool Load( SALOMEDS::SComponent_ptr theComponent,
397              const SALOMEDS::TMPFile& theStream,
398              const char*              theURL,
399              bool                     isMultiFile );
400   // Save SMESH data in ASCII format
401   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
402                                 const char*              theURL,
403                                 bool                     isMultiFile );
404   // Load SMESH data in ASCII format
405   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
406                   const SALOMEDS::TMPFile& theStream,
407                   const char*              theURL,
408                   bool                     isMultiFile );
409
410   // Create filter manager
411   SMESH::FilterManager_ptr CreateFilterManager();
412
413   // Return a pattern mesher
414   SMESH::SMESH_Pattern_ptr GetPattern();
415
416   // Create measurement instance
417   SMESH::Measurements_ptr  CreateMeasurements();
418
419   // Clears study-connected data when it is closed
420   void Close( SALOMEDS::SComponent_ptr theComponent );
421
422   // Get component data type
423   char* ComponentDataType();
424
425   // Transform data from transient form to persistent
426   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
427                                 const char*           IORString,
428                                 CORBA::Boolean        isMultiFile,
429                                 CORBA::Boolean        isASCII );
430   // Transform data from persistent form to transient
431   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
432                                 const char*           aLocalPersistentID,
433                                 CORBA::Boolean        isMultiFile,
434                                 CORBA::Boolean        isASCII );
435
436   // Returns true if object can be published in the study
437   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
438   // Publish object in the study
439   SALOMEDS::SObject_ptr PublishInStudy( 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::Boolean isPublished,
469                                        CORBA::Boolean isMultiFile,
470                                        CORBA::Boolean& isValidScript);
471
472   void AddToPythonScript (const TCollection_AsciiString& theString);
473
474   void RemoveLastFromPythonScript();
475
476   void SavePython();
477
478   TCollection_AsciiString DumpPython_impl (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
479                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
480                                            bool isPublished,
481                                            bool isMultiFile,
482                                            bool isHistoricalDump,
483                                            bool& aValidScript,
484                                            TCollection_AsciiString& theSavedTrace);
485
486   TCollection_AsciiString GetNewPythonLines();
487
488   void CleanPythonTrace();
489
490   // *****************************************
491   // Internal methods
492   // *****************************************
493 public:
494   // Get shape reader
495   GEOM_Client* GetShapeReader();
496
497   // Tags definition
498   static long GetHypothesisRootTag();
499   static long GetAlgorithmsRootTag();
500   static long GetRefOnShapeTag();
501   static long GetRefOnAppliedHypothesisTag();
502   static long GetRefOnAppliedAlgorithmsTag();
503   static long GetSubMeshOnVertexTag();
504   static long GetSubMeshOnEdgeTag();
505   static long GetSubMeshOnFaceTag();
506   static long GetSubMeshOnSolidTag();
507   static long GetSubMeshOnCompoundTag();
508   static long GetSubMeshOnWireTag();
509   static long GetSubMeshOnShellTag();
510   static long GetNodeGroupsTag();
511   static long GetEdgeGroupsTag();
512   static long GetFaceGroupsTag();
513   static long GetVolumeGroupsTag();
514   static long Get0DElementsGroupsTag();
515   static long GetBallElementsGroupsTag();
516
517   // publishing methods
518   SALOMEDS::SComponent_ptr PublishComponent();
519   SALOMEDS::SObject_ptr PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
520                                      const char*           theName = 0);
521   SALOMEDS::SObject_ptr PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
522                                            const char*                 theName = 0);
523   SALOMEDS::SObject_ptr PublishSubMesh (SMESH::SMESH_Mesh_ptr    theMesh,
524                                         SMESH::SMESH_subMesh_ptr theSubMesh,
525                                         GEOM::GEOM_Object_ptr    theShapeObject,
526                                         const char*              theName = 0);
527   SALOMEDS::SObject_ptr PublishGroup (SMESH::SMESH_Mesh_ptr  theMesh,
528                                       SMESH::SMESH_GroupBase_ptr theGroup,
529                                       GEOM::GEOM_Object_ptr  theShapeObject,
530                                       const char*            theName = 0);
531   void UpdateIcons(SMESH::SMESH_Mesh_ptr theMesh);
532   void HighLightInvalid(CORBA::Object_ptr theObject, bool isInvalid);
533   bool AddHypothesisToShape(SMESH::SMESH_Mesh_ptr       theMesh,
534                             GEOM::GEOM_Object_ptr       theShapeObject,
535                             SMESH::SMESH_Hypothesis_ptr theHyp);
536   bool RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr       theMesh,
537                                  GEOM::GEOM_Object_ptr       theShapeObject,
538                                  SMESH::SMESH_Hypothesis_ptr theHyp);
539   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
540                                                  GEOM::GEOM_Object_ptr theShape);
541   static void SetName(SALOMEDS::SObject_ptr theSObject,
542                       const char*           theName,
543                       const char*           theDefaultName = 0);
544
545   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
546                         const char*           thePixMap);
547
548   //  Get study context
549   StudyContext* GetStudyContext();
550
551   // Register an object in a StudyContext; return object id
552   int RegisterObject(CORBA::Object_ptr theObject);
553
554   // Return id of registered object
555   CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
556
557   // Return an object that previously had an oldID
558   template<class TInterface>
559     typename TInterface::_var_type GetObjectByOldId( const int oldID )
560   {
561     if ( myStudyContext ) {
562       std::string ior = myStudyContext->getIORbyOldId( oldID );
563       if ( !ior.empty() )
564         return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
565     }
566     return TInterface::_nil();
567   }
568
569   /*!
570    * \brief Find SObject for an algo
571    */
572   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
573
574   void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
575   char* GetParameters(CORBA::Object_ptr theObject);
576   //char* ParseParameters(const char* theParameters);
577   const std::vector< int >&         GetLastParamIndices() const { return myLastParamIndex; }
578   const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
579   const std::string &               GetLastObjEntry() const { return myLastObj; }
580   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
581
582   // Move objects to the specified position
583   void Move( const SMESH::sobject_list& what,
584              SALOMEDS::SObject_ptr where,
585              CORBA::Long row );
586
587   CORBA::Boolean IsApplicable ( const char*           theAlgoType,
588                                 const char*           theLibName,
589                                 GEOM::GEOM_Object_ptr theShapeObject,
590                                 CORBA::Boolean        toCheckAll);
591
592   SMESH::long_array* GetInsideSphere( SMESH::SMESH_IDSource_ptr meshPart,
593                                       SMESH::ElementType        theElemType,
594                                       CORBA::Double             theX,
595                                       CORBA::Double             theY,
596                                       CORBA::Double             theZ,
597                                       CORBA::Double             theR);
598
599   SMESH::long_array* GetInsideBox( SMESH::SMESH_IDSource_ptr meshPart,
600                                    SMESH::ElementType        theElemType,
601                                    CORBA::Double             theX1,
602                                    CORBA::Double             theY1,
603                                    CORBA::Double             theZ1,
604                                    CORBA::Double             theX2,
605                                    CORBA::Double             theY2,
606                                    CORBA::Double             theZ2);
607
608   SMESH::long_array* GetInsideCylinder( SMESH::SMESH_IDSource_ptr meshPart,
609                                         SMESH::ElementType        theElemType,
610                                         CORBA::Double             theX,
611                                         CORBA::Double             theY,
612                                         CORBA::Double             theZ,
613                                         CORBA::Double             theDX,
614                                         CORBA::Double             theDY,
615                                         CORBA::Double             theDZ,
616                                         CORBA::Double             theH,
617                                         CORBA::Double             theR );
618
619   SMESH::long_array* GetInside( SMESH::SMESH_IDSource_ptr meshPart,
620                                 SMESH::ElementType        theElemType,
621                                 GEOM::GEOM_Object_ptr     theGeom,
622                                 CORBA::Double             theTolerance );
623
624 private:
625   // Get hypothesis creator
626   GenericHypothesisCreator_i* getHypothesisCreator( const char*  theHypName,
627                                                     const char*  theLibName,
628                                                     std::string& thePlatformLibName)
629   throw ( SALOME::SALOME_Exception );
630   // Create hypothesis of given type
631   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
632                                                 const char* theLibName);
633   // Create empty mesh on shape
634   SMESH::SMESH_Mesh_ptr createMesh()
635     throw ( SALOME::SALOME_Exception );
636
637   // Create a sub-mesh on a geometry that is not a sub-shape of the main shape
638   // for the case where a valid sub-shape not found by CopyMeshWithGeom()
639   SMESH::SMESH_subMesh_ptr createInvalidSubMesh( SMESH::SMESH_Mesh_ptr mesh,
640                                                  GEOM::GEOM_Object_ptr strangerGeom,
641                                                  const char*           name );
642
643   void highLightInvalid( SALOMEDS::SObject_ptr theSObject, bool isInvalid );
644
645   SMESH::mesh_array* CreateMeshesFromMEDorSAUV( const char* theFileName,
646                                                 SMESH::DriverMED_ReadStatus& theStatus,
647                                                 const char* theCommandNameForPython,
648                                                 const char* theFileNameForPython);
649
650   std::vector<long> _GetInside(SMESH::SMESH_IDSource_ptr meshPart,
651                                SMESH::ElementType     theElemType,
652                                TopoDS_Shape& aShape,
653                                double* theTolerance = NULL);
654
655 private:
656   static GEOM::GEOM_Gen_var      myGeomGen;
657   static CORBA::ORB_var          myOrb;         // ORB reference
658   static PortableServer::POA_var myPoa;         // POA reference
659   static SALOME_NamingService*   myNS;          // Naming Service
660   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
661   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
662   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
663
664   // hypotheses managing
665   std::map<std::string, GenericHypothesisCreator_i*> myHypCreatorMap;
666
667   StudyContext*                  myStudyContext;  // study context
668
669   GEOM_Client*                   myShapeReader;      // Shape reader
670   CORBA::Boolean                 myIsEmbeddedMode;   // Current mode
671   CORBA::Boolean                 myIsEnablePublish;  // Enable publishing
672
673   // Default color of groups
674   std::string myDefaultGroupColor;
675
676   // To load full mesh data from study at hyp modification or not
677   bool myToForgetMeshDataOnHypModif;
678
679   // Dump Python: trace of API methods calls
680   Handle(TColStd_HSequenceOfAsciiString) myPythonScript;
681   bool                                   myIsHistoricalPythonDump;
682   std::vector< int >                     myLastParamIndex;
683   std::vector< std::string >             myLastParameters;
684   std::string                            myLastObj;
685 };
686
687
688 namespace SMESH
689 {
690   template<class T>
691   T
692   DownCast(CORBA::Object_ptr theArg)
693   {
694     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
695   }
696
697   /*!
698    * \brief Function used in SMESH_CATCH to convert a caught exception to
699    * SALOME::SALOME_Exception
700    */
701   inline void throwCorbaException(const char* excText)
702   {
703     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
704   }
705 }
706
707
708 #endif