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