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