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