1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Gen_i.hxx
25 // Author : Paul RASCLE, EDF
29 #ifndef _SMESH_GEN_I_HXX_
30 #define _SMESH_GEN_I_HXX_
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)
40 #include "SMESH_Mesh_i.hxx"
41 #include "SMESH_Hypothesis_i.hxx"
42 #include "SALOME_Component_i.hxx"
43 #include "SALOME_NamingService.hxx"
45 #include "SMESH_Gen.hxx"
46 #include "GEOM_Client.hxx"
47 #include "SMESH_Factory.hxx"
52 class SALOME_LifeCycleCORBA;
54 // ===========================================================
55 // Study context - stores study-connected objects references
56 // ==========================================================
68 // register object in the internal map and return its id
69 int addObject( string theIOR )
71 int nextId = getNextId();
72 mapIdToIOR[ nextId ] = theIOR;
75 // find the object id in the internal map by the IOR
76 int findId( string theIOR )
78 map<int, string>::iterator imap;
79 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
80 if ( imap->second == theIOR )
85 // get object's IOR by id
86 string getIORbyId( const int theId )
88 if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
89 return mapIdToIOR[ theId ];
92 // get object's IOR by old id
93 string getIORbyOldId( const int theOldId )
95 if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
96 return getIORbyId( mapIdToId[ theOldId ] );
99 // maps old object id to the new one (used when restoring data)
100 void mapOldToNew( const int oldId, const int newId ) {
101 mapIdToId[ oldId ] = newId;
105 // get next free object identifier
109 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
114 map<int, string> mapIdToIOR; // persistent-to-transient map
115 map<int, int> mapIdToId; // used to translate object from persistent to transient form
118 // ===========================================================
119 // SMESH module's engine
120 // ==========================================================
122 public virtual POA_SMESH::SMESH_Gen,
123 public virtual Engines_Component_i,
124 public virtual SMESH::Factory
127 // Get last created instance of the class
128 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
130 static CORBA::ORB_var GetORB() { return myOrb;}
131 // Get SMESH module's POA object
132 static PortableServer::POA_var GetPOA() { return myPoa;}
133 // Get Naming Service object
134 static SALOME_NamingService* GetNS();
135 // Get SALOME_LifeCycleCORBA object
136 static SALOME_LifeCycleCORBA* GetLCC();
137 // Retrieve and get GEOM engine reference
138 static GEOM::GEOM_Gen_ptr GetGeomEngine();
139 // Get object of the CORBA reference
140 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
141 // Get CORBA object corresponding to the SALOMEDS::SObject
142 static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
143 // Get the SALOMEDS::SObject corresponding to a CORBA object
144 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
145 CORBA::Object_ptr theObject);
146 // Get GEOM Object correspoding to TopoDS_Shape
147 GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
148 // Get TopoDS_Shape correspoding to GEOM_Object
149 TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
151 // Default constructor
153 // Standard constructor
154 SMESH_Gen_i( CORBA::ORB_ptr orb,
155 PortableServer::POA_ptr poa,
156 PortableServer::ObjectId* contId,
157 const char* instanceName,
158 const char* interfaceName );
160 virtual ~SMESH_Gen_i();
162 // *****************************************
164 // *****************************************
167 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
169 SALOMEDS::Study_ptr GetCurrentStudy();
171 // Create hypothesis/algorothm of given type
172 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
173 const char* theLibName)
174 throw ( SALOME::SALOME_Exception );
176 // Create empty mesh on a shape
177 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
178 throw ( SALOME::SALOME_Exception );
180 // Create mesh(es) and import data from UNV file
181 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
182 throw ( SALOME::SALOME_Exception );
184 // Create mesh(es) and import data from MED file
185 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
186 SMESH::DriverMED_ReadStatus& theStatus )
187 throw ( SALOME::SALOME_Exception );
189 // Create mesh(es) and import data from STL file
190 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
191 throw ( SALOME::SALOME_Exception );
193 // Compute mesh on a shape
194 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
195 GEOM::GEOM_Object_ptr theShapeObject )
196 throw ( SALOME::SALOME_Exception );
198 // Returns true if mesh contains enough data to be computed
199 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
200 GEOM::GEOM_Object_ptr theShapeObject )
201 throw ( SALOME::SALOME_Exception );
203 // Get sub-shapes unique ID's list
204 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
205 const SMESH::object_array& theListOfSubShape )
206 throw ( SALOME::SALOME_Exception );
209 // ****************************************************
210 // Interface inherited methods (from SALOMEDS::Driver)
211 // ****************************************************
214 DumpPython(CORBA::Object_ptr theStudy,
215 CORBA::Boolean theIsPublished,
216 CORBA::Boolean& theIsValidScript);
219 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
223 bool Load( SALOMEDS::SComponent_ptr theComponent,
224 const SALOMEDS::TMPFile& theStream,
227 // Save SMESH data in ASCII format
228 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
231 // Load SMESH data in ASCII format
232 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
233 const SALOMEDS::TMPFile& theStream,
237 // Create filter manager
238 SMESH::FilterManager_ptr CreateFilterManager();
240 // Return a pattern mesher
241 SMESH::SMESH_Pattern_ptr GetPattern();
243 // Clears study-connected data when it is closed
244 void Close( SALOMEDS::SComponent_ptr theComponent );
246 // Get component data type
247 char* ComponentDataType();
249 // Transform data from transient form to persistent
250 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
251 const char* IORString,
252 CORBA::Boolean isMultiFile,
253 CORBA::Boolean isASCII );
254 // Transform data from persistent form to transient
255 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
256 const char* aLocalPersistentID,
257 CORBA::Boolean isMultiFile,
258 CORBA::Boolean isASCII );
260 // Returns true if object can be published in the study
261 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
262 // Publish object in the study
263 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
264 SALOMEDS::SObject_ptr theSObject,
265 CORBA::Object_ptr theObject,
266 const char* theName )
267 throw ( SALOME::SALOME_Exception );
269 // Copy-paste methods - returns true if object can be copied to the clipboard
270 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
271 // Copy-paste methods - copy object to the clipboard
272 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
273 // Copy-paste methods - returns true if object can be pasted from the clipboard
274 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
275 // Copy-paste methods - paste object from the clipboard
276 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
277 CORBA::Long theObjectID,
278 SALOMEDS::SObject_ptr theObject ) {
279 SALOMEDS::SObject_var aResultSO;
280 return aResultSO._retn();
283 // *****************************************
285 // *****************************************
288 GEOM_Client* GetShapeReader();
291 static long GetHypothesisRootTag();
292 static long GetAlgorithmsRootTag();
293 static long GetRefOnShapeTag();
294 static long GetRefOnAppliedHypothesisTag();
295 static long GetRefOnAppliedAlgorithmsTag();
296 static long GetSubMeshOnVertexTag();
297 static long GetSubMeshOnEdgeTag();
298 static long GetSubMeshOnFaceTag();
299 static long GetSubMeshOnSolidTag();
300 static long GetSubMeshOnCompoundTag();
301 static long GetSubMeshOnWireTag();
302 static long GetSubMeshOnShellTag();
303 static long GetNodeGroupsTag();
304 static long GetEdgeGroupsTag();
305 static long GetFaceGroupsTag();
306 static long GetVolumeGroupsTag();
308 // publishing methods
309 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
310 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
311 SMESH::SMESH_Mesh_ptr theMesh,
312 const char* theName = 0);
313 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
314 SMESH::SMESH_Hypothesis_ptr theHyp,
315 const char* theName = 0);
316 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
317 SMESH::SMESH_Mesh_ptr theMesh,
318 SMESH::SMESH_subMesh_ptr theSubMesh,
319 GEOM::GEOM_Object_ptr theShapeObject,
320 const char* theName = 0);
321 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
322 SMESH::SMESH_Mesh_ptr theMesh,
323 SMESH::SMESH_GroupBase_ptr theGroup,
324 GEOM::GEOM_Object_ptr theShapeObject,
325 const char* theName = 0);
326 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
327 SMESH::SMESH_Mesh_ptr theMesh,
328 GEOM::GEOM_Object_ptr theShapeObject,
329 SMESH::SMESH_Hypothesis_ptr theHyp);
330 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
331 SMESH::SMESH_Mesh_ptr theMesh,
332 GEOM::GEOM_Object_ptr theShapeObject,
333 SMESH::SMESH_Hypothesis_ptr theHyp);
334 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
335 SMESH::SMESH_Mesh_ptr theMesh,
336 GEOM::GEOM_Object_ptr theShape);
337 static void SetName(SALOMEDS::SObject_ptr theSObject,
339 const char* theDefaultName = 0);
342 StudyContext* GetCurrentStudyContext();
344 // Register an object in a StudyContext; return object id
345 int RegisterObject(CORBA::Object_ptr theObject);
347 // Get current study ID
348 int GetCurrentStudyID()
349 { return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId(); }
352 // Create hypothesis of given type
353 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
354 const char* theLibName)
355 throw ( SALOME::SALOME_Exception );
357 // Create empty mesh on shape
358 SMESH::SMESH_Mesh_ptr createMesh()
359 throw ( SALOME::SALOME_Exception );
361 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
365 static CORBA::ORB_var myOrb; // ORB reference
366 static PortableServer::POA_var myPoa; // POA reference
367 static SALOME_NamingService* myNS; // Naming Service
368 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
369 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
370 ::SMESH_Gen myGen; // SMESH_Gen local implementation
372 // hypotheses managing
373 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
375 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
377 GEOM_Client* myShapeReader; // Shape reader
378 SALOMEDS::Study_var myCurrentStudy; // Current study