]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESH_I/SMESH_Gen_i.hxx
Salome HOME
Mesh module improvement related to selection of geometrical objects in mesh group...
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.hxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  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. 
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 //
23 //
24 //  File   : SMESH_Gen_i.hxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef _SMESH_GEN_I_HXX_
30 #define _SMESH_GEN_I_HXX_
31
32 #include <SALOMEconfig.h>
33 #include CORBA_SERVER_HEADER(SMESH_Gen)
34 #include CORBA_SERVER_HEADER(SMESH_Mesh)
35 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
36 #include CORBA_CLIENT_HEADER(GEOM_Gen)
37 #include CORBA_CLIENT_HEADER(SALOMEDS)
38 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
39
40 #include "SMESH_Mesh_i.hxx"
41 #include "SMESH_Hypothesis_i.hxx"
42 #include "SALOME_Component_i.hxx"
43 #include "SALOME_NamingService.hxx"
44
45 #include "SMESH_Gen.hxx"
46 #include "GEOM_Client.hxx"
47
48 #include <TCollection_AsciiString.hxx>
49 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
50 #include <TColStd_HSequenceOfAsciiString.hxx>
51
52 #include <map>
53 #include <sstream>
54
55 class SMESH_Mesh_i;
56 class SALOME_LifeCycleCORBA;
57
58 // ===========================================================
59 // Study context - stores study-connected objects references
60 // ==========================================================
61 class StudyContext
62 {
63 public:
64   // constructor
65   StudyContext() {}
66   // destructor
67   ~StudyContext() 
68   { 
69     mapIdToIOR.clear();
70     mapIdToId.clear();
71   }
72   // register object in the internal map and return its id
73   int addObject( string theIOR )
74   {
75     int nextId = getNextId();
76     mapIdToIOR[ nextId ]  = theIOR;
77     return nextId;
78   }
79   // find the object id in the internal map by the IOR
80   int findId( string theIOR )
81   {
82     map<int, string>::iterator imap;
83     for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
84       if ( imap->second == theIOR )
85         return imap->first;
86     }
87     return 0;
88   }
89   // get object's IOR by id
90   string getIORbyId( const int theId )
91   {
92     if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
93       return mapIdToIOR[ theId ];
94     return string( "" );
95   }
96   // get object's IOR by old id
97   string getIORbyOldId( const int theOldId )
98   {
99     if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
100       return getIORbyId( mapIdToId[ theOldId ] );
101     return string( "" );
102   }
103   // maps old object id to the new one (used when restoring data)
104   void mapOldToNew( const int oldId, const int newId ) {
105     mapIdToId[ oldId ] = newId;
106   }
107     
108 private:
109   // get next free object identifier
110   int getNextId()
111   {
112     int id = 1;
113     while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
114       id++;
115     return id;
116   }
117
118   map<int, string> mapIdToIOR;      // persistent-to-transient map
119   map<int, int>    mapIdToId;       // used to translate object from persistent to transient form
120 };
121
122 // ===========================================================
123 // SMESH module's engine
124 // ==========================================================
125 class SMESH_Gen_i:
126   public virtual POA_SMESH::SMESH_Gen,
127   public virtual Engines_Component_i 
128 {
129 public:
130   // Get last created instance of the class
131   static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
132   // Get ORB object
133   static CORBA::ORB_var GetORB() { return myOrb;}
134   // Get SMESH module's POA object
135   static PortableServer::POA_var GetPOA() { return myPoa;}
136   // Get Naming Service object
137   static SALOME_NamingService* GetNS();
138   // Get SALOME_LifeCycleCORBA object
139   static SALOME_LifeCycleCORBA* GetLCC();
140   // Retrieve and get GEOM engine reference
141   static GEOM::GEOM_Gen_ptr GetGeomEngine();
142   // Get object of the CORBA reference
143   static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
144   // Get CORBA object corresponding to the SALOMEDS::SObject
145   static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
146   // Get the SALOMEDS::SObject corresponding to a CORBA object
147   static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
148                                                CORBA::Object_ptr   theObject);
149   // Get GEOM Object correspoding to TopoDS_Shape
150   GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
151   // Get TopoDS_Shape correspoding to GEOM_Object
152   TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
153   
154   // Default constructor
155   SMESH_Gen_i();
156   // Standard constructor
157   SMESH_Gen_i( CORBA::ORB_ptr            orb,
158                PortableServer::POA_ptr   poa,
159                PortableServer::ObjectId* contId, 
160                const char*               instanceName, 
161                const char*               interfaceName );
162   // Destructor
163   virtual ~SMESH_Gen_i();
164   
165   // *****************************************
166   // Interface methods
167   // *****************************************
168
169   // Set current study
170   void SetEmbeddedMode( CORBA::Boolean theMode );
171   // Get current study
172   CORBA::Boolean IsEmbeddedMode();
173
174   // Set current study
175   void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
176   // Get current study
177   SALOMEDS::Study_ptr GetCurrentStudy();
178
179   // Create hypothesis/algorothm of given type
180   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
181                                                 const char* theLibName)
182     throw ( SALOME::SALOME_Exception );
183   
184   // Return hypothesis of given type holding parameter values of the existing mesh
185   SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char*           theHypType,
186                                                             const char*           theLibName,
187                                                             SMESH::SMESH_Mesh_ptr theMesh,
188                                                             GEOM::GEOM_Object_ptr theGeom)
189     throw ( SALOME::SALOME_Exception );
190   
191   // Create empty mesh on a shape
192   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
193     throw ( SALOME::SALOME_Exception );
194
195   // Create empty mesh
196   SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
197     throw ( SALOME::SALOME_Exception );
198
199   //  Create mesh(es) and import data from UNV file
200   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
201     throw ( SALOME::SALOME_Exception );
202
203   //  Create mesh(es) and import data from MED file
204   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
205                                           SMESH::DriverMED_ReadStatus& theStatus )
206     throw ( SALOME::SALOME_Exception );
207
208   //  Create mesh(es) and import data from STL file
209   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
210     throw ( SALOME::SALOME_Exception );
211
212   // Compute mesh on a shape
213   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
214                           GEOM::GEOM_Object_ptr  theShapeObject )
215     throw ( SALOME::SALOME_Exception );
216
217   // Returns true if mesh contains enough data to be computed
218   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
219                                    GEOM::GEOM_Object_ptr theShapeObject )
220     throw ( SALOME::SALOME_Exception );
221
222   // Returns errors of hypotheses definintion
223   SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh, 
224                                          GEOM::GEOM_Object_ptr theSubObject )
225       throw ( SALOME::SALOME_Exception );
226
227   // Get sub-shapes unique ID's list
228   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
229                                      const SMESH::object_array& theListOfSubShape )
230     throw ( SALOME::SALOME_Exception );
231
232   // Return geometrical object the given element is built on. Publish it in study.
233   GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
234                                                   CORBA::Long            theElementID,
235                                                   const char*            theGeomName)
236     throw ( SALOME::SALOME_Exception );
237
238   // Return geometrical object the given element is built on. Don't publish it in study.
239   GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr  theMesh,
240                                                    CORBA::Long            theElementID)
241     throw ( SALOME::SALOME_Exception );
242
243   // ****************************************************
244   // Interface inherited methods (from SALOMEDS::Driver)
245   // ****************************************************
246
247   // Save SMESH data
248   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
249                          const char*              theURL,
250                          bool                     isMultiFile );
251   // Load SMESH data
252   bool Load( SALOMEDS::SComponent_ptr theComponent,
253              const SALOMEDS::TMPFile& theStream,
254              const char*              theURL,
255              bool                     isMultiFile );
256   // Save SMESH data in ASCII format
257   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
258                                 const char*              theURL,
259                                 bool                     isMultiFile );
260   // Load SMESH data in ASCII format
261   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
262                   const SALOMEDS::TMPFile& theStream,
263                   const char*              theURL,
264                   bool                     isMultiFile );
265
266   // Create filter manager
267   SMESH::FilterManager_ptr CreateFilterManager();
268
269   // Return a pattern mesher
270   SMESH::SMESH_Pattern_ptr GetPattern();
271
272   // Clears study-connected data when it is closed
273   void Close( SALOMEDS::SComponent_ptr theComponent );
274   
275   // Get component data type
276   char* ComponentDataType();
277     
278   // Transform data from transient form to persistent
279   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
280                                 const char*           IORString,
281                                 CORBA::Boolean        isMultiFile,
282                                 CORBA::Boolean        isASCII );
283   // Transform data from persistent form to transient
284   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
285                                 const char*           aLocalPersistentID,
286                                 CORBA::Boolean        isMultiFile,
287                                 CORBA::Boolean        isASCII );
288
289   // Returns true if object can be published in the study
290   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
291   // Publish object in the study
292   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr   theStudy,
293                                         SALOMEDS::SObject_ptr theSObject,
294                                         CORBA::Object_ptr     theObject,
295                                         const char*           theName ) 
296     throw ( SALOME::SALOME_Exception );
297
298   // Copy-paste methods - returns true if object can be copied to the clipboard
299   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
300   // Copy-paste methods - copy object to the clipboard
301   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
302   // Copy-paste methods - returns true if object can be pasted from the clipboard
303   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
304   // Copy-paste methods - paste object from the clipboard
305   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
306                                    CORBA::Long              theObjectID,
307                                    SALOMEDS::SObject_ptr    theObject ) {
308     SALOMEDS::SObject_var aResultSO;
309     return aResultSO._retn();
310   }
311
312   // ============
313   // Dump python
314   // ============
315
316   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, 
317                                        CORBA::Boolean isPublished, 
318                                        CORBA::Boolean& isValidScript);
319
320   void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
321
322   void RemoveLastFromPythonScript (int theStudyID);
323
324   void SavePython (SALOMEDS::Study_ptr theStudy);
325
326   TCollection_AsciiString DumpPython_impl (int theStudyID, 
327                                            Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
328                                            Resource_DataMapOfAsciiStringAsciiString& theNames,
329                                            bool isPublished, 
330                                            bool& aValidScript,
331                                            const TCollection_AsciiString& theSavedTrace);
332
333   TCollection_AsciiString GetNewPythonLines (int theStudyID);
334
335   void CleanPythonTrace (int theStudyID);
336
337
338   // *****************************************
339   // Internal methods
340   // *****************************************
341 public:
342   // Get shape reader
343   GEOM_Client* GetShapeReader();
344
345   // Tags definition 
346   static long GetHypothesisRootTag();
347   static long GetAlgorithmsRootTag();
348   static long GetRefOnShapeTag();
349   static long GetRefOnAppliedHypothesisTag();
350   static long GetRefOnAppliedAlgorithmsTag();
351   static long GetSubMeshOnVertexTag();
352   static long GetSubMeshOnEdgeTag();
353   static long GetSubMeshOnFaceTag();
354   static long GetSubMeshOnSolidTag();
355   static long GetSubMeshOnCompoundTag();
356   static long GetSubMeshOnWireTag();
357   static long GetSubMeshOnShellTag();
358   static long GetNodeGroupsTag();
359   static long GetEdgeGroupsTag();
360   static long GetFaceGroupsTag();
361   static long GetVolumeGroupsTag();
362
363   // publishing methods
364   SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
365   SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr   theStudy,
366                                      SMESH::SMESH_Mesh_ptr theMesh,
367                                      const char*           theName = 0);
368   SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr         theStudy,
369                                            SMESH::SMESH_Hypothesis_ptr theHyp,
370                                            const char*                 theName = 0);
371   SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr      theStudy,
372                                         SMESH::SMESH_Mesh_ptr    theMesh,
373                                         SMESH::SMESH_subMesh_ptr theSubMesh,
374                                         GEOM::GEOM_Object_ptr    theShapeObject,
375                                         const char*              theName = 0);
376   SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr    theStudy,
377                                       SMESH::SMESH_Mesh_ptr  theMesh,
378                                       SMESH::SMESH_GroupBase_ptr theGroup,
379                                       GEOM::GEOM_Object_ptr  theShapeObject,
380                                       const char*            theName = 0);
381   bool AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
382                             SMESH::SMESH_Mesh_ptr       theMesh,
383                             GEOM::GEOM_Object_ptr       theShapeObject,
384                             SMESH::SMESH_Hypothesis_ptr theHyp);
385   bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy,
386                                  SMESH::SMESH_Mesh_ptr       theMesh,
387                                  GEOM::GEOM_Object_ptr       theShapeObject,
388                                  SMESH::SMESH_Hypothesis_ptr theHyp);
389   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr   theStudy,
390                                                  SMESH::SMESH_Mesh_ptr theMesh,
391                                                  GEOM::GEOM_Object_ptr theShape);
392   static void SetName(SALOMEDS::SObject_ptr theSObject,
393                       const char*           theName,
394                       const char*           theDefaultName = 0);
395
396   //  Get study context
397   StudyContext* GetCurrentStudyContext();
398
399   // Register an object in a StudyContext; return object id
400   int RegisterObject(CORBA::Object_ptr theObject);
401
402   // Get current study ID
403   int GetCurrentStudyID()
404   { return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId(); }
405  
406 private:
407   // Create hypothesis of given type
408   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
409                                                 const char* theLibName)
410     throw ( SALOME::SALOME_Exception );
411   
412   // Create empty mesh on shape
413   SMESH::SMESH_Mesh_ptr createMesh()
414     throw ( SALOME::SALOME_Exception );
415
416   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
417   
418 private:
419
420   static CORBA::ORB_var          myOrb;         // ORB reference
421   static PortableServer::POA_var myPoa;         // POA reference
422   static SALOME_NamingService*   myNS;          // Naming Service
423   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
424   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
425   ::SMESH_Gen               myGen;              // SMESH_Gen local implementation
426
427   // hypotheses managing
428   map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
429
430   map<int, StudyContext*>   myStudyContextMap;  // Map of study context objects
431
432   GEOM_Client*              myShapeReader;      // Shape reader
433   SALOMEDS::Study_var       myCurrentStudy;     // Current study
434   CORBA::Boolean            myIsEmbeddedMode;   // Current mode
435
436   // Dump Python: trace of API methods calls
437   std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
438 };
439
440
441 namespace SMESH
442 {
443   template<class T>
444   T
445   DownCast(CORBA::Object_ptr theArg)
446   {
447     return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
448   }
449 }
450
451
452 #endif