Salome HOME
PAL8267: two new API methods added: ExtrusionSweepObject1(2)D()
[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   // Get the SALOMEDS::SObject corresponding to a CORBA object
142   static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
143                                                CORBA::Object_ptr   theObject);
144   // Get GEOM Object correspoding to TopoDS_Shape
145   GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
146   // Get TopoDS_Shape correspoding to GEOM_Object
147   TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
148   
149   // Default constructor
150   SMESH_Gen_i();
151   // Standard constructor
152   SMESH_Gen_i( CORBA::ORB_ptr            orb,
153                PortableServer::POA_ptr   poa,
154                PortableServer::ObjectId* contId, 
155                const char*               instanceName, 
156                const char*               interfaceName );
157   // Destructor
158   virtual ~SMESH_Gen_i();
159   
160   // *****************************************
161   // Interface methods
162   // *****************************************
163
164   // Set current study
165   void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
166   // Get current study
167   SALOMEDS::Study_ptr GetCurrentStudy();
168
169   // Create hypothesis/algorothm of given type
170   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
171                                                 const char* theLibName)
172     throw ( SALOME::SALOME_Exception );
173   
174   // Create empty mesh on a shape
175   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
176     throw ( SALOME::SALOME_Exception );
177
178   //  Create mesh(es) and import data from UNV file
179   SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
180     throw ( SALOME::SALOME_Exception );
181
182   //  Create mesh(es) and import data from MED file
183   SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
184                                           SMESH::DriverMED_ReadStatus& theStatus )
185     throw ( SALOME::SALOME_Exception );
186
187   //  Create mesh(es) and import data from STL file
188   SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
189     throw ( SALOME::SALOME_Exception );
190
191   // Compute mesh on a shape
192   CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
193                           GEOM::GEOM_Object_ptr  theShapeObject )
194     throw ( SALOME::SALOME_Exception );
195
196   // Returns true if mesh contains enough data to be computed
197   CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
198                                    GEOM::GEOM_Object_ptr theShapeObject )
199     throw ( SALOME::SALOME_Exception );
200
201   // Get sub-shapes unique ID's list
202   SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr      theMainShapeObject,
203                                      const SMESH::object_array& theListOfSubShape )
204     throw ( SALOME::SALOME_Exception );
205
206
207   // ****************************************************
208   // Interface inherited methods (from SALOMEDS::Driver)
209   // ****************************************************
210
211   // Save SMESH data
212   SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
213                          const char*              theURL,
214                          bool                     isMultiFile );
215   // Load SMESH data
216   bool Load( SALOMEDS::SComponent_ptr theComponent,
217              const SALOMEDS::TMPFile& theStream,
218              const char*              theURL,
219              bool                     isMultiFile );
220   // Save SMESH data in ASCII format
221   SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
222                                 const char*              theURL,
223                                 bool                     isMultiFile );
224   // Load SMESH data in ASCII format
225   bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
226                   const SALOMEDS::TMPFile& theStream,
227                   const char*              theURL,
228                   bool                     isMultiFile );
229
230   // Create filter manager
231   SMESH::FilterManager_ptr CreateFilterManager();
232
233   // Return a pattern mesher
234   SMESH::SMESH_Pattern_ptr GetPattern();
235
236   // Clears study-connected data when it is closed
237   void Close( SALOMEDS::SComponent_ptr theComponent );
238   
239   // Get component data type
240   char* ComponentDataType();
241     
242   // Transform data from transient form to persistent
243   char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
244                                 const char*           IORString,
245                                 CORBA::Boolean        isMultiFile,
246                                 CORBA::Boolean        isASCII );
247   // Transform data from persistent form to transient
248   char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
249                                 const char*           aLocalPersistentID,
250                                 CORBA::Boolean        isMultiFile,
251                                 CORBA::Boolean        isASCII );
252
253   // Returns true if object can be published in the study
254   bool CanPublishInStudy( CORBA::Object_ptr theIOR );
255   // Publish object in the study
256   SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr   theStudy,
257                                         SALOMEDS::SObject_ptr theSObject,
258                                         CORBA::Object_ptr     theObject,
259                                         const char*           theName ) 
260     throw ( SALOME::SALOME_Exception );
261
262   // Copy-paste methods - returns true if object can be copied to the clipboard
263   CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
264   // Copy-paste methods - copy object to the clipboard
265   SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
266   // Copy-paste methods - returns true if object can be pasted from the clipboard
267   CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
268   // Copy-paste methods - paste object from the clipboard
269   SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
270                                    CORBA::Long              theObjectID,
271                                    SALOMEDS::SObject_ptr    theObject ) {
272     SALOMEDS::SObject_var aResultSO;
273     return aResultSO._retn();
274   }
275
276   // *****************************************
277   // Internal methods
278   // *****************************************
279 public:
280   // Get shape reader
281   GEOM_Client* GetShapeReader();
282
283   // Tags definition 
284   static long GetHypothesisRootTag();
285   static long GetAlgorithmsRootTag();
286   static long GetRefOnShapeTag();
287   static long GetRefOnAppliedHypothesisTag();
288   static long GetRefOnAppliedAlgorithmsTag();
289   static long GetSubMeshOnVertexTag();
290   static long GetSubMeshOnEdgeTag();
291   static long GetSubMeshOnFaceTag();
292   static long GetSubMeshOnSolidTag();
293   static long GetSubMeshOnCompoundTag();
294   static long GetSubMeshOnWireTag();
295   static long GetSubMeshOnShellTag();
296   static long GetNodeGroupsTag();
297   static long GetEdgeGroupsTag();
298   static long GetFaceGroupsTag();
299   static long GetVolumeGroupsTag();
300
301   // publishing methods
302   SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
303   SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr   theStudy,
304                                      SMESH::SMESH_Mesh_ptr theMesh,
305                                      const char*           theName = 0);
306   SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr         theStudy,
307                                            SMESH::SMESH_Hypothesis_ptr theHyp,
308                                            const char*                 theName = 0);
309   SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr      theStudy,
310                                         SMESH::SMESH_Mesh_ptr    theMesh,
311                                         SMESH::SMESH_subMesh_ptr theSubMesh,
312                                         GEOM::GEOM_Object_ptr    theShapeObject,
313                                         const char*              theName = 0);
314   SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr    theStudy,
315                                       SMESH::SMESH_Mesh_ptr  theMesh,
316                                       SMESH::SMESH_GroupBase_ptr theGroup,
317                                       GEOM::GEOM_Object_ptr  theShapeObject,
318                                       const char*            theName = 0);
319   bool AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
320                             SMESH::SMESH_Mesh_ptr       theMesh,
321                             GEOM::GEOM_Object_ptr       theShapeObject,
322                             SMESH::SMESH_Hypothesis_ptr theHyp);
323   bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy,
324                                  SMESH::SMESH_Mesh_ptr       theMesh,
325                                  GEOM::GEOM_Object_ptr       theShapeObject,
326                                  SMESH::SMESH_Hypothesis_ptr theHyp);
327   SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr   theStudy,
328                                                  SMESH::SMESH_Mesh_ptr theMesh,
329                                                  GEOM::GEOM_Object_ptr theShape);
330   static void SetName(SALOMEDS::SObject_ptr theSObject,
331                       const char*           theName,
332                       const char*           theDefaultName = 0);
333
334   //  Get study context
335   StudyContext* GetCurrentStudyContext();
336
337   // Register an object in a StudyContext; return object id
338   int RegisterObject(CORBA::Object_ptr theObject);
339
340   // Get current study ID
341   int GetCurrentStudyID()
342   { return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId(); }
343  
344 private:
345   // Create hypothesis of given type
346   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
347                                                 const char* theLibName)
348     throw ( SALOME::SALOME_Exception );
349   
350   // Create empty mesh on shape
351   SMESH::SMESH_Mesh_ptr createMesh()
352     throw ( SALOME::SALOME_Exception );
353
354   static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
355   
356 private:
357
358   static CORBA::ORB_var          myOrb;         // ORB reference
359   static PortableServer::POA_var myPoa;         // POA reference
360   static SALOME_NamingService*   myNS;          // Naming Service
361   static SALOME_LifeCycleCORBA*  myLCC;         // Life Cycle CORBA
362   static SMESH_Gen_i*            mySMESHGen;    // Point to last created instance of the class
363   ::SMESH_Gen               myGen;              // SMESH_Gen local implementation
364
365   // hypotheses managing
366   map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
367
368   map<int, StudyContext*>   myStudyContextMap;  // Map of study context objects
369
370   GEOM_Client*              myShapeReader;      // Shape reader
371   SALOMEDS::Study_var       myCurrentStudy;     // Current study
372 };
373
374 #endif