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