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