Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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(GEOM_Shape)
38 #include CORBA_CLIENT_HEADER(SALOMEDS)
39 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
40
41 #include "SMESH_Mesh_i.hxx"
42 #include "SMESH_Hypothesis_i.hxx"
43 #include "SALOME_Component_i.hxx"
44 #include "SALOME_NamingService.hxx"
45
46 #include "SMESH_Gen.hxx"
47 #include "SMESH_topo.hxx"
48 #include "GEOM_Client.hxx"
49
50 #include <map>
51
52 class SMESH_Mesh_i;
53 class SALOME_LifeCycleCORBA;
54
55 // ===========================================================
56 // Study context - stores study-connected objects references
57 // ==========================================================
58 class StudyContext
59 {
60 public:
61   // constructor
62   StudyContext() {}
63   // destructor
64   ~StudyContext() 
65   { 
66     mapIdToIOR.clear();
67     mapIdToId.clear();
68   }
69   // register object in the internal map and return its id
70   int addObject( string theIOR )
71   {
72     int nextId = getNextId();
73     mapIdToIOR[ nextId ]  = theIOR;
74     return nextId;
75   }
76   // find the object id in the internal map by the IOR
77   int findId( string theIOR )
78   {
79     map<int, string>::iterator imap;
80     for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
81       if ( imap->second == theIOR )
82         return imap->first;
83     }
84     return 0;
85   }
86   // get object's IOR by id
87   string getIORbyId( const int theId )
88   {
89     if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
90       return mapIdToIOR[ theId ];
91     return string( "" );
92   }
93   // get object's IOR by old id
94   string getIORbyOldId( const int theOldId )
95   {
96     if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
97       return getIORbyId( mapIdToId[ theOldId ] );
98     return string( "" );
99   }
100   // maps old object id to the new one (used when restoring data)
101   void mapOldToNew( const int oldId, const int newId ) {
102     mapIdToId[ oldId ] = newId;
103   }
104     
105 private:
106   // get next free object identifier
107   int getNextId()
108   {
109     int id = 1;
110     while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
111       id++;
112     return id;
113   }
114
115   map<int, string> mapIdToIOR;      // persistent-to-transient map
116   map<int, int>    mapIdToId;       // used to translate object from persistent to transient form
117 };
118
119 // ===========================================================
120 // SMESH module's engine
121 // ==========================================================
122 class SMESH_Gen_i:
123   public virtual POA_SMESH::SMESH_Gen,
124   public virtual Engines_Component_i 
125 {
126 public:
127   // Get ORB object
128   static CORBA::ORB_var GetORB() { return myOrb;}
129   // Get SMESH module's POA object
130   static PortableServer::POA_var GetPOA() { return myPoa;}
131   // Get Naming Service object
132   static SALOME_NamingService* GetNS();
133   // Get SALOME_LifeCycleCORBA object
134   static SALOME_LifeCycleCORBA* GetLCC();
135   // Retrieve and get GEOM engine reference
136   static GEOM::GEOM_Gen_ptr GetGeomEngine();
137   // Get object of the CORBA reference
138   static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
139   // Get CORBA object corresponding to the SALOMEDS::SObject
140   static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
141
142   // Default constructor
143   SMESH_Gen_i();
144   // Standard constructor
145   SMESH_Gen_i( CORBA::ORB_ptr            orb,
146                PortableServer::POA_ptr   poa,
147                PortableServer::ObjectId* contId, 
148                const char*               instanceName, 
149                const char*               interfaceName );
150   // Destructor
151   virtual ~SMESH_Gen_i();
152   
153   // *****************************************
154   // Interface methods
155   // *****************************************
156
157   // Set current study
158   void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
159   // Get current study
160   SALOMEDS::Study_ptr GetCurrentStudy();
161
162   // Create hypothesis/algorothm of given type
163   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
164                                                 const char* theLibName)
165     throw ( SALOME::SALOME_Exception );
166   
167   // Create empty mesh on a shape
168   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Shape_ptr theShape )
169     throw ( SALOME::SALOME_Exception );
170
171   //  Create mesh(es) and import data from MED file
172   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
173                                           SMESH::DriverMED_ReadStatus& theStatus )
174     throw ( SALOME::SALOME_Exception );
175
176   // Compute mesh on a shape
177   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
178                           GEOM::GEOM_Shape_ptr  theShape )
179     throw ( SALOME::SALOME_Exception );
180
181   // Returns true if mesh contains enough data to be computed
182   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
183                                    GEOM::GEOM_Shape_ptr  theShape )
184     throw ( SALOME::SALOME_Exception );
185
186   // Get sub-shapes unique ID's list
187   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Shape_ptr      theMainShape,
188                                      const SMESH::shape_array& theListOfSubShape )
189     throw ( SALOME::SALOME_Exception );
190
191
192   // ****************************************************
193   // Interface inherited methods (from SALOMEDS::Driver)
194   // ****************************************************
195
196   // Save SMESH data
197   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
198                            const char*              theURL,
199                            bool                     isMultiFile );
200   // Load SMESH data
201   bool Load( SALOMEDS::SComponent_ptr theComponent,
202              const SALOMEDS::TMPFile& theStream,
203              const char*              theURL,
204              bool                     isMultiFile );
205   // Save SMESH data in ASCII format
206   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
207                                 const char*              theURL,
208                                 bool                     isMultiFile );
209   // Load SMESH data in ASCII format
210   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
211                   const SALOMEDS::TMPFile& theStream,
212                   const char*              theURL,
213                   bool                     isMultiFile );
214
215   // Create filter manager
216   SMESH::FilterManager_ptr CreateFilterManager();
217
218   // Clears study-connected data when it is closed
219   void Close( SALOMEDS::SComponent_ptr theComponent );
220   
221   // Get component data type
222   char* ComponentDataType();
223     
224   // Transform data from transient form to persistent
225   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
226                                 const char*           IORString,
227                                 CORBA::Boolean        isMultiFile,
228                                 CORBA::Boolean        isASCII );
229   // Transform data from persistent form to transient
230   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
231                                 const char*           aLocalPersistentID,
232                                 CORBA::Boolean        isMultiFile,
233                                 CORBA::Boolean        isASCII );
234
235   // Returns true if object can be published in the study
236   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
237   // Publish object in the study
238   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr   theStudy,
239                                         SALOMEDS::SObject_ptr theSObject,
240                                         CORBA::Object_ptr     theObject,
241                                         const char*           theName ) 
242     throw ( SALOME::SALOME_Exception );
243
244   // Copy-paste methods - returns true if object can be copied to the clipboard
245   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
246   // Copy-paste methods - copy object to the clipboard
247   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
248   // Copy-paste methods - returns true if object can be pasted from the clipboard
249   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
250   // Copy-paste methods - paste object from the clipboard
251   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
252                                    CORBA::Long              theObjectID,
253                                    SALOMEDS::SObject_ptr    theObject ) {
254     SALOMEDS::SObject_var aResultSO;
255     return aResultSO._retn();
256   }
257
258   // *****************************************
259   // Internal methods
260   // *****************************************
261 public:
262   // Get shape reader
263   GEOM_Client* GetShapeReader();
264
265   // Tags definition 
266   static long GetHypothesisRootTag();
267   static long GetAlgorithmsRootTag();
268   static long GetRefOnShapeTag();
269   static long GetRefOnAppliedHypothesisTag();
270   static long GetRefOnAppliedAlgorithmsTag();
271   static long GetSubMeshOnVertexTag();
272   static long GetSubMeshOnEdgeTag();
273   static long GetSubMeshOnFaceTag();
274   static long GetSubMeshOnSolidTag();
275   static long GetSubMeshOnCompoundTag();
276   static long GetNodeGroupsTag();
277   static long GetEdgeGroupsTag();
278   static long GetFaceGroupsTag();
279   static long GetVolumeGroupsTag();
280
281   //  Get study context
282   StudyContext* GetCurrentStudyContext();
283   
284 private:
285   // Create hypothesis of given type
286   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
287                                                 const char* theLibName)
288     throw ( SALOME::SALOME_Exception );
289   
290   // Create empty mesh on shape
291   SMESH::SMESH_Mesh_ptr createMesh()
292     throw ( SALOME::SALOME_Exception );
293
294   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
295   
296 private:
297
298   static CORBA::ORB_var          myOrb;         // ORB reference
299   static PortableServer::POA_var myPoa;         // POA reference
300   static SALOME_NamingService*   myNS;          // Naming Service
301   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
302
303   ::SMESH_Gen               myGen;              // SMESH_Gen local implementation
304
305   // hypotheses managing
306   map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
307
308   map<int, StudyContext*>   myStudyContextMap;  // Map of study context objects
309
310   GEOM_Client*              myShapeReader;      // Shape reader
311   SALOMEDS::Study_var       myCurrentStudy;     // Current study
312 };
313
314 #endif