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"
48 #include <TCollection_AsciiString.hxx>
49 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
50 #include <TColStd_HSequenceOfAsciiString.hxx>
56 class SALOME_LifeCycleCORBA;
58 // ===========================================================
59 // Study context - stores study-connected objects references
60 // ==========================================================
72 // register object in the internal map and return its id
73 int addObject( string theIOR )
75 int nextId = getNextId();
76 mapIdToIOR[ nextId ] = theIOR;
79 // find the object id in the internal map by the IOR
80 int findId( string theIOR )
82 map<int, string>::iterator imap;
83 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
84 if ( imap->second == theIOR )
89 // get object's IOR by id
90 string getIORbyId( const int theId )
92 if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
93 return mapIdToIOR[ theId ];
96 // get object's IOR by old id
97 string getIORbyOldId( const int theOldId )
99 if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
100 return getIORbyId( mapIdToId[ theOldId ] );
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;
109 // get next free object identifier
113 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
118 map<int, string> mapIdToIOR; // persistent-to-transient map
119 map<int, int> mapIdToId; // used to translate object from persistent to transient form
122 // ===========================================================
123 // SMESH module's engine
124 // ==========================================================
126 public virtual POA_SMESH::SMESH_Gen,
127 public virtual Engines_Component_i
130 // Get last created instance of the class
131 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
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);
154 // Default constructor
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 );
163 virtual ~SMESH_Gen_i();
165 // *****************************************
167 // *****************************************
170 void SetEmbeddedMode( CORBA::Boolean theMode );
172 CORBA::Boolean IsEmbeddedMode();
175 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
177 SALOMEDS::Study_ptr GetCurrentStudy();
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 );
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 );
191 // Create empty mesh on a shape
192 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
193 throw ( SALOME::SALOME_Exception );
195 // Create mesh(es) and import data from UNV file
196 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
197 throw ( SALOME::SALOME_Exception );
199 // Create mesh(es) and import data from MED file
200 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
201 SMESH::DriverMED_ReadStatus& theStatus )
202 throw ( SALOME::SALOME_Exception );
204 // Create mesh(es) and import data from STL file
205 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
206 throw ( SALOME::SALOME_Exception );
208 // Compute mesh on a shape
209 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
210 GEOM::GEOM_Object_ptr theShapeObject )
211 throw ( SALOME::SALOME_Exception );
213 // Returns true if mesh contains enough data to be computed
214 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
215 GEOM::GEOM_Object_ptr theShapeObject )
216 throw ( SALOME::SALOME_Exception );
218 // Returns errors of hypotheses definintion
219 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
220 GEOM::GEOM_Object_ptr theSubObject )
221 throw ( SALOME::SALOME_Exception );
223 // Get sub-shapes unique ID's list
224 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
225 const SMESH::object_array& theListOfSubShape )
226 throw ( SALOME::SALOME_Exception );
228 // Return geometrical object the given element is built on
229 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
230 CORBA::Long theElementID,
231 const char* theGeomName)
232 throw ( SALOME::SALOME_Exception );
234 // ****************************************************
235 // Interface inherited methods (from SALOMEDS::Driver)
236 // ****************************************************
239 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
243 bool Load( SALOMEDS::SComponent_ptr theComponent,
244 const SALOMEDS::TMPFile& theStream,
247 // Save SMESH data in ASCII format
248 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
251 // Load SMESH data in ASCII format
252 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
253 const SALOMEDS::TMPFile& theStream,
257 // Create filter manager
258 SMESH::FilterManager_ptr CreateFilterManager();
260 // Return a pattern mesher
261 SMESH::SMESH_Pattern_ptr GetPattern();
263 // Clears study-connected data when it is closed
264 void Close( SALOMEDS::SComponent_ptr theComponent );
266 // Get component data type
267 char* ComponentDataType();
269 // Transform data from transient form to persistent
270 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
271 const char* IORString,
272 CORBA::Boolean isMultiFile,
273 CORBA::Boolean isASCII );
274 // Transform data from persistent form to transient
275 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
276 const char* aLocalPersistentID,
277 CORBA::Boolean isMultiFile,
278 CORBA::Boolean isASCII );
280 // Returns true if object can be published in the study
281 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
282 // Publish object in the study
283 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
284 SALOMEDS::SObject_ptr theSObject,
285 CORBA::Object_ptr theObject,
286 const char* theName )
287 throw ( SALOME::SALOME_Exception );
289 // Copy-paste methods - returns true if object can be copied to the clipboard
290 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
291 // Copy-paste methods - copy object to the clipboard
292 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
293 // Copy-paste methods - returns true if object can be pasted from the clipboard
294 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
295 // Copy-paste methods - paste object from the clipboard
296 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
297 CORBA::Long theObjectID,
298 SALOMEDS::SObject_ptr theObject ) {
299 SALOMEDS::SObject_var aResultSO;
300 return aResultSO._retn();
307 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
308 CORBA::Boolean isPublished,
309 CORBA::Boolean& isValidScript);
311 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
313 void RemoveLastFromPythonScript (int theStudyID);
315 void SavePython (SALOMEDS::Study_ptr theStudy);
317 TCollection_AsciiString DumpPython_impl (int theStudyID,
318 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
319 Resource_DataMapOfAsciiStringAsciiString& theNames,
322 const TCollection_AsciiString& theSavedTrace);
324 TCollection_AsciiString GetNewPythonLines (int theStudyID);
326 void CleanPythonTrace (int theStudyID);
329 // *****************************************
331 // *****************************************
334 GEOM_Client* GetShapeReader();
337 static long GetHypothesisRootTag();
338 static long GetAlgorithmsRootTag();
339 static long GetRefOnShapeTag();
340 static long GetRefOnAppliedHypothesisTag();
341 static long GetRefOnAppliedAlgorithmsTag();
342 static long GetSubMeshOnVertexTag();
343 static long GetSubMeshOnEdgeTag();
344 static long GetSubMeshOnFaceTag();
345 static long GetSubMeshOnSolidTag();
346 static long GetSubMeshOnCompoundTag();
347 static long GetSubMeshOnWireTag();
348 static long GetSubMeshOnShellTag();
349 static long GetNodeGroupsTag();
350 static long GetEdgeGroupsTag();
351 static long GetFaceGroupsTag();
352 static long GetVolumeGroupsTag();
354 // publishing methods
355 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
356 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
357 SMESH::SMESH_Mesh_ptr theMesh,
358 const char* theName = 0);
359 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
360 SMESH::SMESH_Hypothesis_ptr theHyp,
361 const char* theName = 0);
362 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
363 SMESH::SMESH_Mesh_ptr theMesh,
364 SMESH::SMESH_subMesh_ptr theSubMesh,
365 GEOM::GEOM_Object_ptr theShapeObject,
366 const char* theName = 0);
367 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
368 SMESH::SMESH_Mesh_ptr theMesh,
369 SMESH::SMESH_GroupBase_ptr theGroup,
370 GEOM::GEOM_Object_ptr theShapeObject,
371 const char* theName = 0);
372 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
373 SMESH::SMESH_Mesh_ptr theMesh,
374 GEOM::GEOM_Object_ptr theShapeObject,
375 SMESH::SMESH_Hypothesis_ptr theHyp);
376 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
377 SMESH::SMESH_Mesh_ptr theMesh,
378 GEOM::GEOM_Object_ptr theShapeObject,
379 SMESH::SMESH_Hypothesis_ptr theHyp);
380 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
381 SMESH::SMESH_Mesh_ptr theMesh,
382 GEOM::GEOM_Object_ptr theShape);
383 static void SetName(SALOMEDS::SObject_ptr theSObject,
385 const char* theDefaultName = 0);
388 StudyContext* GetCurrentStudyContext();
390 // Register an object in a StudyContext; return object id
391 int RegisterObject(CORBA::Object_ptr theObject);
393 // Get current study ID
394 int GetCurrentStudyID()
395 { return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId(); }
398 // Create hypothesis of given type
399 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
400 const char* theLibName)
401 throw ( SALOME::SALOME_Exception );
403 // Create empty mesh on shape
404 SMESH::SMESH_Mesh_ptr createMesh()
405 throw ( SALOME::SALOME_Exception );
407 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
411 static CORBA::ORB_var myOrb; // ORB reference
412 static PortableServer::POA_var myPoa; // POA reference
413 static SALOME_NamingService* myNS; // Naming Service
414 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
415 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
416 ::SMESH_Gen myGen; // SMESH_Gen local implementation
418 // hypotheses managing
419 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
421 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
423 GEOM_Client* myShapeReader; // Shape reader
424 SALOMEDS::Study_var myCurrentStudy; // Current study
425 CORBA::Boolean myIsEmbeddedMode; // Current mode
427 // Dump Python: trace of API methods calls
428 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
436 DownCast(CORBA::Object_ptr theArg)
438 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());