Salome HOME
Adding parallel meshing (NETGEN only, Linux Only)
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.hxx
1 // Copyright (C) 2007-2022  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   // 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 mesh
235   SMESH::SMESH_Mesh_ptr CreateEmptyMesh();
236
237   //  Create a mesh and import data from an UNV file
238   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName );
239
240   //  Create mesh(es) and import data from MED file
241   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
242                                           SMESH::DriverMED_ReadStatus& theStatus );
243
244   //  Create a mesh and import data from a STL file
245   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName );
246
247   //  Create mesh(es) and import data from CGNS file
248   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
249                                            SMESH::DriverMED_ReadStatus& theStatus );
250
251   //  Create a mesh and import data from a GMF file
252   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
253                                              CORBA::Boolean          theMakeRequiredGroups,
254                                              SMESH::ComputeError_out theError);
255
256   // Create dual mesh of a tetrahedron mesh
257   SMESH::SMESH_Mesh_ptr CreateDualMesh(SMESH::SMESH_IDSource_ptr meshPart,
258                                        const char*               meshName,
259                                        CORBA::Boolean            adapt_to_shape);
260
261   // Copy a part of mesh
262   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
263                                  const char*               meshName,
264                                  CORBA::Boolean            toCopyGroups,
265                                  CORBA::Boolean            toKeepIDs);
266
267   // Create a mesh by copying definitions of another mesh to a given geometry
268   CORBA::Boolean CopyMeshWithGeom( SMESH::SMESH_Mesh_ptr       sourceMesh,
269                                    GEOM::GEOM_Object_ptr       newGeometry,
270                                    const char*                 meshName,
271                                    CORBA::Boolean              toCopyGroups,
272                                    CORBA::Boolean              toReuseHypotheses,
273                                    CORBA::Boolean              toCopyElements,
274                                    SMESH::SMESH_Mesh_out       newMesh,
275                                    SMESH::ListOfGroups_out     newGroups,
276                                    SMESH::submesh_array_out    newSubmeshes,
277                                    SMESH::ListOfHypothesis_out newHypotheses,
278                                    SMESH::string_array_out     invalidEntries);
279
280     // Compute mesh on a shape
281   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
282                           GEOM::GEOM_Object_ptr theShapeObject );
283
284   // Cancel Compute mesh on a shape
285   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
286                       GEOM::GEOM_Object_ptr theShapeObject );
287
288   /*!
289    * \brief Return errors of mesh computation
290    */
291   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
292                                                GEOM::GEOM_Object_ptr  theShapeObject );
293
294   /*!
295    * Evaluate mesh on a shape and
296    *  returns statistic of mesh elements
297    * Result array of number enityties
298    */
299   SMESH::smIdType_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
300                               GEOM::GEOM_Object_ptr theShapeObject);
301
302   // Returns true if mesh contains enough data to be computed
303   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
304                                    GEOM::GEOM_Object_ptr theShapeObject );
305
306   /*!
307    * Calculate Mesh as preview till indicated dimension on shape
308    * First, verify list of hypothesis associated with the subShape.
309    * Return mesh preview structure
310    */
311   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
312                                         GEOM::GEOM_Object_ptr theSubObject,
313                                         SMESH::Dimension      theDimension,
314                                         SMESH::long_array&    theShapesId );
315
316   // Returns errors of hypotheses definition
317   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
318                                          GEOM::GEOM_Object_ptr theSubObject );
319
320   // Return mesh elements preventing computation of a subshape
321   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
322                                                  CORBA::Short          theSubShapeID );
323
324   // Create groups of elements preventing computation of a sub-shape
325   SMESH::ListOfGroups* MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
326                                                      CORBA::Short          theSubShapeID,
327                                                      const char*           theGroupName);
328
329   // Get sub-shapes unique ID's list
330   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
331                                      const SMESH::object_array& theListOfSubShape );
332
333   // Return geometrical object the given element is built on. Publish it in study.
334   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
335                                                   SMESH::smIdType        theElementID,
336                                                   const char*            theGeomName);
337
338   // Return geometrical object the given element is built on. Don't publish it in study.
339   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
340                                                    SMESH::smIdType        theElementID);
341
342   // Concatenate the given meshes into one mesh
343   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
344                                           CORBA::Boolean                uniteIdenticalGroups,
345                                           CORBA::Boolean                mergeNodesAndElements,
346                                           CORBA::Double                 mergeTolerance,
347                                           CORBA::Boolean                commonGroups,
348                                           SMESH::SMESH_Mesh_ptr         meshToAppendTo);
349
350   // Concatenate the given meshes into one mesh
351   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
352                                     CORBA::Boolean                uniteIdenticalGroups,
353                                     CORBA::Boolean                mergeNodesAndElements,
354                                     CORBA::Double                 mergeTolerance,
355                                     SMESH::SMESH_Mesh_ptr         meshToAppendTo);
356
357   // Concatenate the given meshes into one mesh
358   // Create the groups of all elements from initial meshes
359   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
360                                               CORBA::Boolean                uniteIdenticalGroups,
361                                               CORBA::Boolean                mergeNodesAndElements,
362                                               CORBA::Double                 mergeTolerance,
363                                               SMESH::SMESH_Mesh_ptr         meshToAppendTo);
364
365   // Get version of MED format being used.
366   char* GetMEDFileVersion();
367
368   // Get MED version of the file by its name
369   char* GetMEDVersion(const char* theFileName);
370
371   // Check compatibility of file with MED format being used, read only.
372   CORBA::Boolean CheckCompatibility(const char* theFileName);
373
374   // Check compatibility of file with MED format being used, for append on write.
375   CORBA::Boolean CheckWriteCompatibility(const char* theFileName);
376
377   // Get names of meshes defined in file with the specified name
378   SMESH::string_array* GetMeshNames(const char* theFileName);
379
380   // ****************************************************
381   // Interface inherited methods (from SALOMEDS::Driver)
382   // ****************************************************
383
384   // Save SMESH data
385   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
386                          const char*              theURL,
387                          bool                     isMultiFile );
388   // Load SMESH data
389   bool Load( SALOMEDS::SComponent_ptr theComponent,
390              const SALOMEDS::TMPFile& theStream,
391              const char*              theURL,
392              bool                     isMultiFile );
393   // Save SMESH data in ASCII format
394   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
395                                 const char*              theURL,
396                                 bool                     isMultiFile );
397   // Load SMESH data in ASCII format
398   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
399                   const SALOMEDS::TMPFile& theStream,
400                   const char*              theURL,
401                   bool                     isMultiFile );
402
403   // Create filter manager
404   SMESH::FilterManager_ptr CreateFilterManager();
405
406   // Return a pattern mesher
407   SMESH::SMESH_Pattern_ptr GetPattern();
408
409   // Create measurement instance
410   SMESH::Measurements_ptr  CreateMeasurements();
411
412   // Clears study-connected data when it is closed
413   void Close( SALOMEDS::SComponent_ptr theComponent );
414
415   // Get component data type
416   char* ComponentDataType();
417
418   // Transform data from transient form to persistent
419   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
420                                 const char*           IORString,
421                                 CORBA::Boolean        isMultiFile,
422                                 CORBA::Boolean        isASCII );
423   // Transform data from persistent form to transient
424   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
425                                 const char*           aLocalPersistentID,
426                                 CORBA::Boolean        isMultiFile,
427                                 CORBA::Boolean        isASCII );
428
429   // Returns true if object can be published in the study
430   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
431   // Publish object in the study
432   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::SObject_ptr theSObject,
433                                         CORBA::Object_ptr     theObject,
434                                         const char*           theName );
435
436   // Copy-paste methods - returns true if object can be copied to the clipboard
437   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr /*theObject*/ ) { return false; }
438   // Copy-paste methods - copy object to the clipboard
439   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr /*theObject*/, CORBA::Long& /*theObjectID*/ ) { return NULL; }
440   // Copy-paste methods - returns true if object can be pasted from the clipboard
441   CORBA::Boolean CanPaste( const char* /*theComponentName*/, CORBA::Long /*theObjectID*/ ) { return false; }
442   // Copy-paste methods - paste object from the clipboard
443   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& /*theStream*/,
444                                    CORBA::Long              /*theObjectID*/,
445                                    SALOMEDS::SObject_ptr    /*theObject*/ ) {
446     SALOMEDS::SObject_var aResultSO;
447     return aResultSO._retn();
448   }
449
450   // ============
451   // Version information
452   // ============
453
454   virtual char* getVersion();
455
456   // ============
457   // Dump python
458   // ============
459
460   virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished,
461                                        CORBA::Boolean isMultiFile,
462                                        CORBA::Boolean& isValidScript);
463
464   void AddToPythonScript (const TCollection_AsciiString& theString);
465
466   void RemoveLastFromPythonScript();
467
468   void SavePython();
469
470   TCollection_AsciiString DumpPython_impl (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
471                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
472                                            bool isPublished,
473                                            bool isMultiFile,
474                                            bool isHistoricalDump,
475                                            bool& aValidScript,
476                                            TCollection_AsciiString& theSavedTrace);
477
478   TCollection_AsciiString GetNewPythonLines();
479
480   void CleanPythonTrace();
481
482   int CountInPyDump(const TCollection_AsciiString& text);
483
484   SMESH::MG_ADAPT_ptr CreateMG_ADAPT();
485   SMESHHOMARD::HOMARD_Gen_ptr CreateHOMARD_ADAPT();
486   SMESH::MG_ADAPT_ptr CreateAdaptationHypothesis();
487   //SMESH::MG_ADAPT_OBJECT_ptr Adaptation( const char* adaptationType);
488   SALOME::GenericObj_ptr Adaptation( const char* adaptationType);
489
490   // *****************************************
491   // Internal methods
492   // *****************************************
493 public:
494   // Get shape reader
495   GEOM_Client* GetShapeReader();
496
497   // Tags definition
498   static long GetHypothesisRootTag();
499   static long GetAlgorithmsRootTag();
500   static long GetRefOnShapeTag();
501   static long GetRefOnAppliedHypothesisTag();
502   static long GetRefOnAppliedAlgorithmsTag();
503   static long GetSubMeshOnVertexTag();
504   static long GetSubMeshOnEdgeTag();
505   static long GetSubMeshOnFaceTag();
506   static long GetSubMeshOnSolidTag();
507   static long GetSubMeshOnCompoundTag();
508   static long GetSubMeshOnWireTag();
509   static long GetSubMeshOnShellTag();
510   static long GetNodeGroupsTag();
511   static long GetEdgeGroupsTag();
512   static long GetFaceGroupsTag();
513   static long GetVolumeGroupsTag();
514   static long Get0DElementsGroupsTag();
515   static long GetBallElementsGroupsTag();
516
517   // publishing methods
518   SALOMEDS::SComponent_ptr PublishComponent();
519   SALOMEDS::SObject_ptr PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
520                                      const char*           theName = 0);
521   SALOMEDS::SObject_ptr PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
522                                            const char*                 theName = 0);
523   SALOMEDS::SObject_ptr PublishSubMesh (SMESH::SMESH_Mesh_ptr    theMesh,
524                                         SMESH::SMESH_subMesh_ptr theSubMesh,
525                                         GEOM::GEOM_Object_ptr    theShapeObject,
526                                         const char*              theName = 0);
527   SALOMEDS::SObject_ptr PublishGroup (SMESH::SMESH_Mesh_ptr  theMesh,
528                                       SMESH::SMESH_GroupBase_ptr theGroup,
529                                       GEOM::GEOM_Object_ptr  theShapeObject,
530                                       const char*            theName = 0);
531   void UpdateIcons(SMESH::SMESH_Mesh_ptr theMesh);
532   void HighLightInvalid(CORBA::Object_ptr theObject, bool isInvalid);
533   bool IsInvalid(SALOMEDS::SObject_ptr theObject);
534   bool AddHypothesisToShape(SMESH::SMESH_Mesh_ptr       theMesh,
535                             GEOM::GEOM_Object_ptr       theShapeObject,
536                             SMESH::SMESH_Hypothesis_ptr theHyp);
537   bool RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr       theMesh,
538                                  GEOM::GEOM_Object_ptr       theShapeObject,
539                                  SMESH::SMESH_Hypothesis_ptr theHyp);
540   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
541                                                  GEOM::GEOM_Object_ptr theShape);
542   void SetName(SALOMEDS::SObject_ptr theSObject,
543               const char*           theName,
544               const char*           theDefaultName = 0);
545
546   void SetPixMap(SALOMEDS::SObject_ptr theSObject, const char *thePixMap);
547   void addReference (SALOMEDS::SObject_ptr theSObject, CORBA::Object_ptr theToObject, int theTag = 0);
548
549   //  Get study context
550   StudyContext* GetStudyContext();
551
552   // Register an object in a StudyContext; return object id
553   int RegisterObject(CORBA::Object_ptr theObject);
554
555   // Return id of registered object
556   CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
557
558   // Return an object that previously had an oldID
559   template<class TInterface>
560     typename TInterface::_var_type GetObjectByOldId( const int oldID )
561   {
562     if ( myStudyContext ) {
563       std::string ior = myStudyContext->getIORbyOldId( oldID );
564       if ( !ior.empty() )
565         return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
566     }
567     return TInterface::_nil();
568   }
569
570   /*!
571    * \brief Find SObject for an algo
572    */
573   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
574
575   void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
576   char* GetParameters(CORBA::Object_ptr theObject);
577   //char* ParseParameters(const char* theParameters);
578   const std::vector< int >&         GetLastParamIndices() const { return myLastParamIndex; }
579   const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
580   const std::string &               GetLastObjEntry() const { return myLastObj; }
581   std::vector< std::string >        GetAllParameters(const std::string& theObjectEntry) const;
582
583   // Move objects to the specified position
584   void Move( const SMESH::sobject_list& what,
585              SALOMEDS::SObject_ptr where,
586              CORBA::Long row );
587
588   CORBA::Boolean IsApplicable ( const char*           theAlgoType,
589                                 const char*           theLibName,
590                                 GEOM::GEOM_Object_ptr theShapeObject,
591                                 CORBA::Boolean        toCheckAll);
592
593   SMESH::long_array* GetInsideSphere( SMESH::SMESH_IDSource_ptr meshPart,
594                                       SMESH::ElementType        theElemType,
595                                       CORBA::Double             theX,
596                                       CORBA::Double             theY,
597                                       CORBA::Double             theZ,
598                                       CORBA::Double             theR);
599
600   SMESH::long_array* GetInsideBox( SMESH::SMESH_IDSource_ptr meshPart,
601                                    SMESH::ElementType        theElemType,
602                                    CORBA::Double             theX1,
603                                    CORBA::Double             theY1,
604                                    CORBA::Double             theZ1,
605                                    CORBA::Double             theX2,
606                                    CORBA::Double             theY2,
607                                    CORBA::Double             theZ2);
608
609   SMESH::long_array* GetInsideCylinder( SMESH::SMESH_IDSource_ptr meshPart,
610                                         SMESH::ElementType        theElemType,
611                                         CORBA::Double             theX,
612                                         CORBA::Double             theY,
613                                         CORBA::Double             theZ,
614                                         CORBA::Double             theDX,
615                                         CORBA::Double             theDY,
616                                         CORBA::Double             theDZ,
617                                         CORBA::Double             theH,
618                                         CORBA::Double             theR );
619
620   SMESH::long_array* GetInside( SMESH::SMESH_IDSource_ptr meshPart,
621                                 SMESH::ElementType        theElemType,
622                                 GEOM::GEOM_Object_ptr     theGeom,
623                                 CORBA::Double             theTolerance );
624
625 private:
626   // Get hypothesis creator
627   GenericHypothesisCreator_i* getHypothesisCreator( const char*  theHypName,
628                                                     const char*  theLibName,
629                                                     std::string& thePlatformLibName);
630   // Create hypothesis of given type
631   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
632                                                 const char* theLibName);
633   // Create empty mesh on shape
634   SMESH::SMESH_Mesh_ptr createMesh();
635
636   // Check mesh icon
637   bool isGeomModifIcon( SMESH::SMESH_Mesh_ptr mesh );
638
639   // Create a sub-mesh on a geometry that is not a sub-shape of the main shape
640   // for the case where a valid sub-shape not found by CopyMeshWithGeom()
641   SMESH::SMESH_subMesh_ptr createInvalidSubMesh( SMESH::SMESH_Mesh_ptr mesh,
642                                                  GEOM::GEOM_Object_ptr strangerGeom,
643                                                  const char*           name );
644
645   void highLightInvalid( SALOMEDS::SObject_ptr theSObject, bool isInvalid );
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