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