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