Salome HOME
Unify function headers
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.hxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESH_Gen_i.hxx
23 //  Author : Paul RASCLE, EDF
24 //  Module : SMESH
25
26 #ifndef _SMESH_GEN_I_HXX_
27 #define _SMESH_GEN_I_HXX_
28
29 #include "SMESH.hxx"
30
31 #include <SALOMEconfig.h>
32 #include CORBA_SERVER_HEADER(SMESH_Gen)
33 #include CORBA_SERVER_HEADER(SMESH_Mesh)
34 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
35 #include CORBA_CLIENT_HEADER(GEOM_Gen)
36 #include CORBA_CLIENT_HEADER(SALOMEDS)
37 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
38
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   // Do provide info on objects
163   bool hasObjectInfo();
164
165   // Return an information for a given object
166   char* getObjectInfo(const char* entry);
167
168   // Create hypothesis/algorithm of given type
169   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
170                                                 const char* theLibName)
171     throw ( SALOME::SALOME_Exception );
172
173   SMESH::SMESH_Hypothesis_ptr CreateHypothesisByAverageLength( const char*    theHypType,
174                                                                const char*    theLibName,
175                                                                CORBA::Double  theAverageLength,
176                                                                CORBA::Boolean theQuadDominated)
177     throw ( SALOME::SALOME_Exception );
178
179   // Return hypothesis of given type holding parameter values of the existing mesh
180   SMESH::SMESH_Hypothesis_ptr
181     GetHypothesisParameterValues (const char*                 theHypType,
182                                   const char*                 theLibName,
183                                   SMESH::SMESH_Mesh_ptr       theMesh,
184                                   GEOM::GEOM_Object_ptr       theGeom,
185                                   const SMESH::HypInitParams& theWay)
186     throw ( SALOME::SALOME_Exception );
187
188   /*
189    * Returns True if a hypothesis is assigned to a sole sub-mesh in a current Study
190    */
191   CORBA::Boolean GetSoleSubMeshUsingHyp( SMESH::SMESH_Hypothesis_ptr theHyp,
192                                          SMESH::SMESH_Mesh_out       theMesh,
193                                          GEOM::GEOM_Object_out       theShape);
194
195   // Preferences
196   // ------------
197   /*!
198    * Sets number of segments per diagonal of boundary box of geometry by which
199    * default segment length of appropriate 1D hypotheses is defined
200    */
201   void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
202   /*!
203    * \brief Sets default number of segments per edge
204    */
205   void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
206
207   /*!
208     Set an option value
209   */
210   virtual void  SetOption(const char*, const char*);
211   /*!
212     Return an option value
213   */
214   virtual char* GetOption(const char*);
215
216   /*!
217    * To load full mesh data from study at hyp modification or not
218    */
219   bool ToForgetMeshDataOnHypModif() const { return myToForgetMeshDataOnHypModif; }
220
221
222   // Create empty mesh on a shape
223   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
224     throw ( SALOME::SALOME_Exception );
225
226   // Create empty mesh
227   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
228     throw ( SALOME::SALOME_Exception );
229
230   //  Create a mesh and import data from an UNV file
231   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
232     throw ( SALOME::SALOME_Exception );
233
234   //  Create mesh(es) and import data from MED file
235   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
236                                           SMESH::DriverMED_ReadStatus& theStatus )
237     throw ( SALOME::SALOME_Exception );
238
239   //  Create mesh(es) and import data from MED file
240   SMESH::mesh_array* CreateMeshesFromSAUV( const char* theFileName,
241                                            SMESH::DriverMED_ReadStatus& theStatus )
242     throw ( SALOME::SALOME_Exception );
243
244   //  Create a mesh and import data from a STL file
245   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
246     throw ( SALOME::SALOME_Exception );
247
248   //  Create mesh(es) and import data from CGNS file
249   SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName,
250                                            SMESH::DriverMED_ReadStatus& theStatus )
251     throw ( SALOME::SALOME_Exception );
252
253   //  Create a mesh and import data from a GMF file
254   SMESH::SMESH_Mesh_ptr CreateMeshesFromGMF( const char*             theFileName,
255                                              CORBA::Boolean          theMakeRequiredGroups,
256                                              SMESH::ComputeError_out theError)
257     throw ( SALOME::SALOME_Exception );
258
259   // Copy a part of mesh
260   SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
261                                  const char*               meshName,
262                                  CORBA::Boolean            toCopyGroups,
263                                  CORBA::Boolean            toKeepIDs)
264     throw ( SALOME::SALOME_Exception );
265
266   // Create a mesh by copying definitions of another mesh to a given geometry
267   CORBA::Boolean CopyMeshWithGeom( SMESH::SMESH_Mesh_ptr       sourceMesh,
268                                    GEOM::GEOM_Object_ptr       newGeometry,
269                                    const char*                 meshName,
270                                    CORBA::Boolean              toCopyGroups,
271                                    CORBA::Boolean              toReuseHypotheses,
272                                    CORBA::Boolean              toCopyElements,
273                                    SMESH::SMESH_Mesh_out       newMesh,
274                                    SMESH::ListOfGroups_out     newGroups,
275                                    SMESH::submesh_array_out    newSubmeshes,
276                                    SMESH::ListOfHypothesis_out newHypotheses,
277                                    SMESH::string_array_out     invalidEntries)
278     throw ( SALOME::SALOME_Exception );
279
280     // Compute mesh on a shape
281   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
282                           GEOM::GEOM_Object_ptr theShapeObject )
283     throw ( SALOME::SALOME_Exception );
284
285   // Cancel Compute mesh on a shape
286   void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
287                       GEOM::GEOM_Object_ptr theShapeObject );
288
289   /*!
290    * \brief Return errors of mesh computation
291    */
292   SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
293                                                GEOM::GEOM_Object_ptr  theShapeObject )
294     throw ( SALOME::SALOME_Exception );
295
296   /*!
297    * Evaluate mesh on a shape and
298    *  returns statistic of mesh elements
299    * Result array of number enityties
300    */
301   SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
302                               GEOM::GEOM_Object_ptr theShapeObject)
303     throw ( SALOME::SALOME_Exception );
304
305   // Returns true if mesh contains enough data to be computed
306   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
307                                    GEOM::GEOM_Object_ptr theShapeObject )
308     throw ( SALOME::SALOME_Exception );
309
310   /*!
311    * Calculate Mesh as preview till indicated dimension on shape
312    * First, verify list of hypothesis associated with the subShape.
313    * Return mesh preview structure
314    */
315   SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
316                                         GEOM::GEOM_Object_ptr theSubObject,
317                                         SMESH::Dimension      theDimension,
318                                         SMESH::long_array&    theShapesId )
319     throw ( SALOME::SALOME_Exception );
320
321   // Returns errors of hypotheses definition
322   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
323                                          GEOM::GEOM_Object_ptr theSubObject )
324     throw ( SALOME::SALOME_Exception );
325
326   // Return mesh elements preventing computation of a subshape
327   SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
328                                                  CORBA::Short          theSubShapeID )
329     throw ( SALOME::SALOME_Exception );
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     throw ( SALOME::SALOME_Exception );
336
337   // Get sub-shapes unique ID's list
338   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
339                                      const SMESH::object_array& theListOfSubShape )
340     throw ( SALOME::SALOME_Exception );
341
342   // Return geometrical object the given element is built on. Publish it in study.
343   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
344                                                   CORBA::Long            theElementID,
345                                                   const char*            theGeomName)
346     throw ( SALOME::SALOME_Exception );
347
348   // Return geometrical object the given element is built on. Don't publish it in study.
349   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
350                                                    CORBA::Long            theElementID)
351     throw ( SALOME::SALOME_Exception );
352
353   // Concatenate the given meshes into one mesh
354   SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::ListOfIDSources& meshesArray,
355                                           CORBA::Boolean                uniteIdenticalGroups,
356                                           CORBA::Boolean                mergeNodesAndElements,
357                                           CORBA::Double                 mergeTolerance,
358                                           CORBA::Boolean                commonGroups,
359                                           SMESH::SMESH_Mesh_ptr         meshToAppendTo)
360     throw ( SALOME::SALOME_Exception );
361
362   // Concatenate the given meshes into one mesh
363   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::ListOfIDSources& meshesArray,
364                                     CORBA::Boolean                uniteIdenticalGroups,
365                                     CORBA::Boolean                mergeNodesAndElements,
366                                     CORBA::Double                 mergeTolerance,
367                                     SMESH::SMESH_Mesh_ptr         meshToAppendTo)
368     throw ( SALOME::SALOME_Exception );
369
370   // Concatenate the given meshes into one mesh
371   // Create the groups of all elements from initial meshes
372   SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::ListOfIDSources& meshesArray,
373                                               CORBA::Boolean                uniteIdenticalGroups,
374                                               CORBA::Boolean                mergeNodesAndElements,
375                                               CORBA::Double                 mergeTolerance,
376                                               SMESH::SMESH_Mesh_ptr         meshToAppendTo)
377     throw ( SALOME::SALOME_Exception );
378
379   // Get version of MED format being used.
380   char* GetMEDFileVersion();
381
382   // Get MED version of the file by its name
383   char* GetMEDVersion(const char* theFileName);
384
385   // Check compatibility of file with MED format being used, read only.
386   CORBA::Boolean CheckCompatibility(const char* theFileName);
387
388   // Check compatibility of file with MED format being used, for append on write.
389   CORBA::Boolean CheckWriteCompatibility(const char* theFileName);
390
391   // Get names of meshes defined in file with the specified name
392   SMESH::string_array* GetMeshNames(const char* theFileName);
393
394   // ****************************************************
395   // Interface inherited methods (from SALOMEDS::Driver)
396   // ****************************************************
397
398   // Save SMESH data
399   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
400                          const char*              theURL,
401                          bool                     isMultiFile );
402   // Load SMESH data
403   bool Load( SALOMEDS::SComponent_ptr theComponent,
404              const SALOMEDS::TMPFile& theStream,
405              const char*              theURL,
406              bool                     isMultiFile );
407   // Save SMESH data in ASCII format
408   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
409                                 const char*              theURL,
410                                 bool                     isMultiFile );
411   // Load SMESH data in ASCII format
412   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
413                   const SALOMEDS::TMPFile& theStream,
414                   const char*              theURL,
415                   bool                     isMultiFile );
416
417   // Create filter manager
418   SMESH::FilterManager_ptr CreateFilterManager();
419
420   // Return a pattern mesher
421   SMESH::SMESH_Pattern_ptr GetPattern();
422
423   // Create measurement instance
424   SMESH::Measurements_ptr  CreateMeasurements();
425
426   // Clears study-connected data when it is closed
427   void Close( SALOMEDS::SComponent_ptr theComponent );
428
429   // Get component data type
430   char* ComponentDataType();
431
432   // Transform data from transient form to persistent
433   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
434                                 const char*           IORString,
435                                 CORBA::Boolean        isMultiFile,
436                                 CORBA::Boolean        isASCII );
437   // Transform data from persistent form to transient
438   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
439                                 const char*           aLocalPersistentID,
440                                 CORBA::Boolean        isMultiFile,
441                                 CORBA::Boolean        isASCII );
442
443   // Returns true if object can be published in the study
444   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
445   // Publish object in the study
446   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::SObject_ptr theSObject,
447                                         CORBA::Object_ptr     theObject,
448                                         const char*           theName )
449     throw ( SALOME::SALOME_Exception );
450
451   // Copy-paste methods - returns true if object can be copied to the clipboard
452   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
453   // Copy-paste methods - copy object to the clipboard
454   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return NULL; }
455   // Copy-paste methods - returns true if object can be pasted from the clipboard
456   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
457   // Copy-paste methods - paste object from the clipboard
458   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
459                                    CORBA::Long              theObjectID,
460                                    SALOMEDS::SObject_ptr    theObject ) {
461     SALOMEDS::SObject_var aResultSO;
462     return aResultSO._retn();
463   }
464
465   // ============
466   // Version information
467   // ============
468
469   virtual char* getVersion();
470
471   // ============
472   // Dump python
473   // ============
474
475   virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished,
476                                        CORBA::Boolean isMultiFile,
477                                        CORBA::Boolean& isValidScript);
478
479   void AddToPythonScript (const TCollection_AsciiString& theString);
480
481   void RemoveLastFromPythonScript();
482
483   void SavePython();
484
485   TCollection_AsciiString DumpPython_impl (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
486                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
487                                            bool isPublished,
488                                            bool isMultiFile,
489                                            bool isHistoricalDump,
490                                            bool& aValidScript,
491                                            TCollection_AsciiString& theSavedTrace);
492
493   TCollection_AsciiString GetNewPythonLines();
494
495   void CleanPythonTrace();
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   static void SetName(SALOMEDS::SObject_ptr theSObject,
550                       const char*           theName,
551                       const char*           theDefaultName = 0);
552
553   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
554                         const char*           thePixMap);
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   throw ( SALOME::SALOME_Exception );
638   // Create hypothesis of given type
639   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
640                                                 const char* theLibName);
641   // Create empty mesh on shape
642   SMESH::SMESH_Mesh_ptr createMesh()
643     throw ( SALOME::SALOME_Exception );
644
645   // Check mesh icon
646   bool isGeomModifIcon( SMESH::SMESH_Mesh_ptr mesh );
647
648   // Create a sub-mesh on a geometry that is not a sub-shape of the main shape
649   // for the case where a valid sub-shape not found by CopyMeshWithGeom()
650   SMESH::SMESH_subMesh_ptr createInvalidSubMesh( SMESH::SMESH_Mesh_ptr mesh,
651                                                  GEOM::GEOM_Object_ptr strangerGeom,
652                                                  const char*           name );
653
654   void highLightInvalid( SALOMEDS::SObject_ptr theSObject, bool isInvalid );
655
656   SMESH::mesh_array* CreateMeshesFromMEDorSAUV( const char* theFileName,
657                                                 SMESH::DriverMED_ReadStatus& theStatus,
658                                                 const char* theCommandNameForPython,
659                                                 const char* theFileNameForPython);
660
661   std::vector<long> _GetInside(SMESH::SMESH_IDSource_ptr meshPart,
662                                SMESH::ElementType        ElemType,
663                                const TopoDS_Shape&       Shape,
664                                double*                   Tolerance = NULL);
665
666 private:
667   static GEOM::GEOM_Gen_var      myGeomGen;
668   static CORBA::ORB_var          myOrb;         // ORB reference
669   static PortableServer::POA_var myPoa;         // POA reference
670   static SALOME_NamingService*   myNS;          // Naming Service
671   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
672   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
673   ::SMESH_Gen                    myGen;         // SMESH_Gen local implementation
674
675   // hypotheses managing
676   std::map<std::string, GenericHypothesisCreator_i*> myHypCreatorMap;
677
678   StudyContext*                  myStudyContext;  // study context
679
680   GEOM_Client*                   myShapeReader;      // Shape reader
681   CORBA::Boolean                 myIsEmbeddedMode;   // Current mode
682   CORBA::Boolean                 myIsEnablePublish;  // Enable publishing
683
684   // Default color of groups
685   std::string myDefaultGroupColor;
686
687   // To load full mesh data from study at hyp modification or not
688   bool myToForgetMeshDataOnHypModif;
689
690   // Dump Python: trace of API methods calls
691   Handle(TColStd_HSequenceOfAsciiString) myPythonScript;
692   bool                                   myIsHistoricalPythonDump;
693   std::vector< int >                     myLastParamIndex;
694   std::vector< std::string >             myLastParameters;
695   std::string                            myLastObj;
696 };
697
698
699 namespace SMESH
700 {
701   template<class T>
702   T
703   DownCast(CORBA::Object_ptr theArg)
704   {
705     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
706   }
707
708   /*!
709    * \brief Function used in SMESH_CATCH to convert a caught exception to
710    * SALOME::SALOME_Exception
711    */
712   inline void throwCorbaException(const char* excText)
713   {
714     THROW_SALOME_CORBA_EXCEPTION( excText, SALOME::INTERNAL_ERROR );
715   }
716 }
717
718
719 #endif