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