Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[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(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 <map>
49
50 class SMESH_Mesh_i;
51 class SALOME_LifeCycleCORBA;
52
53 // ===========================================================
54 // Study context - stores study-connected objects references
55 // ==========================================================
56 class StudyContext
57 {
58 public:
59   // constructor
60   StudyContext() {}
61   // destructor
62   ~StudyContext() 
63   { 
64     mapIdToIOR.clear();
65     mapIdToId.clear();
66   }
67   // register object in the internal map and return its id
68   int addObject( string theIOR )
69   {
70     int nextId = getNextId();
71     mapIdToIOR[ nextId ]  = theIOR;
72     return nextId;
73   }
74   // find the object id in the internal map by the IOR
75   int findId( string theIOR )
76   {
77     map<int, string>::iterator imap;
78     for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
79       if ( imap->second == theIOR )
80         return imap->first;
81     }
82     return 0;
83   }
84   // get object's IOR by id
85   string getIORbyId( const int theId )
86   {
87     if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
88       return mapIdToIOR[ theId ];
89     return string( "" );
90   }
91   // get object's IOR by old id
92   string getIORbyOldId( const int theOldId )
93   {
94     if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
95       return getIORbyId( mapIdToId[ theOldId ] );
96     return string( "" );
97   }
98   // maps old object id to the new one (used when restoring data)
99   void mapOldToNew( const int oldId, const int newId ) {
100     mapIdToId[ oldId ] = newId;
101   }
102     
103 private:
104   // get next free object identifier
105   int getNextId()
106   {
107     int id = 1;
108     while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
109       id++;
110     return id;
111   }
112
113   map<int, string> mapIdToIOR;      // persistent-to-transient map
114   map<int, int>    mapIdToId;       // used to translate object from persistent to transient form
115 };
116
117 // ===========================================================
118 // SMESH module's engine
119 // ==========================================================
120 class SMESH_Gen_i:
121   public virtual POA_SMESH::SMESH_Gen,
122   public virtual Engines_Component_i 
123 {
124 public:
125   // Get last created instance of the class
126   static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
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_Object_ptr theShapeObject )
169     throw ( SALOME::SALOME_Exception );
170
171   //  Create mesh(es) and import data from UNV file
172   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
173     throw ( SALOME::SALOME_Exception );
174
175   //  Create mesh(es) and import data from MED file
176   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
177                                           SMESH::DriverMED_ReadStatus& theStatus )
178     throw ( SALOME::SALOME_Exception );
179
180   //  Create mesh(es) and import data from STL file
181   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
182     throw ( SALOME::SALOME_Exception );
183
184   // Compute mesh on a shape
185   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
186                           GEOM::GEOM_Object_ptr  theShapeObject )
187     throw ( SALOME::SALOME_Exception );
188
189   // Returns true if mesh contains enough data to be computed
190   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
191                                    GEOM::GEOM_Object_ptr theShapeObject )
192     throw ( SALOME::SALOME_Exception );
193
194   // Get sub-shapes unique ID's list
195   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
196                                      const SMESH::object_array& theListOfSubShape )
197     throw ( SALOME::SALOME_Exception );
198
199
200   // ****************************************************
201   // Interface inherited methods (from SALOMEDS::Driver)
202   // ****************************************************
203
204   // Save SMESH data
205   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
206                          const char*              theURL,
207                          bool                     isMultiFile );
208   // Load SMESH data
209   bool Load( SALOMEDS::SComponent_ptr theComponent,
210              const SALOMEDS::TMPFile& theStream,
211              const char*              theURL,
212              bool                     isMultiFile );
213   // Save SMESH data in ASCII format
214   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
215                                 const char*              theURL,
216                                 bool                     isMultiFile );
217   // Load SMESH data in ASCII format
218   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
219                   const SALOMEDS::TMPFile& theStream,
220                   const char*              theURL,
221                   bool                     isMultiFile );
222
223   // Create filter manager
224   SMESH::FilterManager_ptr CreateFilterManager();
225
226   // Return a pattern mesher
227   SMESH::SMESH_Pattern_ptr GetPattern();
228
229   // Clears study-connected data when it is closed
230   void Close( SALOMEDS::SComponent_ptr theComponent );
231   
232   // Get component data type
233   char* ComponentDataType();
234     
235   // Transform data from transient form to persistent
236   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
237                                 const char*           IORString,
238                                 CORBA::Boolean        isMultiFile,
239                                 CORBA::Boolean        isASCII );
240   // Transform data from persistent form to transient
241   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
242                                 const char*           aLocalPersistentID,
243                                 CORBA::Boolean        isMultiFile,
244                                 CORBA::Boolean        isASCII );
245
246   // Returns true if object can be published in the study
247   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
248   // Publish object in the study
249   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr   theStudy,
250                                         SALOMEDS::SObject_ptr theSObject,
251                                         CORBA::Object_ptr     theObject,
252                                         const char*           theName ) 
253     throw ( SALOME::SALOME_Exception );
254
255   // Copy-paste methods - returns true if object can be copied to the clipboard
256   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
257   // Copy-paste methods - copy object to the clipboard
258   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
259   // Copy-paste methods - returns true if object can be pasted from the clipboard
260   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
261   // Copy-paste methods - paste object from the clipboard
262   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
263                                    CORBA::Long              theObjectID,
264                                    SALOMEDS::SObject_ptr    theObject ) {
265     SALOMEDS::SObject_var aResultSO;
266     return aResultSO._retn();
267   }
268
269   // *****************************************
270   // Internal methods
271   // *****************************************
272 public:
273   // Get shape reader
274   GEOM_Client* GetShapeReader();
275
276   // Tags definition 
277   static long GetHypothesisRootTag();
278   static long GetAlgorithmsRootTag();
279   static long GetRefOnShapeTag();
280   static long GetRefOnAppliedHypothesisTag();
281   static long GetRefOnAppliedAlgorithmsTag();
282   static long GetSubMeshOnVertexTag();
283   static long GetSubMeshOnEdgeTag();
284   static long GetSubMeshOnFaceTag();
285   static long GetSubMeshOnSolidTag();
286   static long GetSubMeshOnCompoundTag();
287   static long GetSubMeshOnWireTag();
288   static long GetSubMeshOnShellTag();
289   static long GetNodeGroupsTag();
290   static long GetEdgeGroupsTag();
291   static long GetFaceGroupsTag();
292   static long GetVolumeGroupsTag();
293
294   //  Get study context
295   StudyContext* GetCurrentStudyContext();
296   
297 private:
298   // Create hypothesis of given type
299   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
300                                                 const char* theLibName)
301     throw ( SALOME::SALOME_Exception );
302   
303   // Create empty mesh on shape
304   SMESH::SMESH_Mesh_ptr createMesh()
305     throw ( SALOME::SALOME_Exception );
306
307   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
308   
309 private:
310
311   static CORBA::ORB_var          myOrb;         // ORB reference
312   static PortableServer::POA_var myPoa;         // POA reference
313   static SALOME_NamingService*   myNS;          // Naming Service
314   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
315   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
316   ::SMESH_Gen               myGen;              // SMESH_Gen local implementation
317
318   // hypotheses managing
319   map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
320
321   map<int, StudyContext*>   myStudyContextMap;  // Map of study context objects
322
323   GEOM_Client*              myShapeReader;      // Shape reader
324   SALOMEDS::Study_var       myCurrentStudy;     // Current study
325 };
326
327 #endif