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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Gen_i.hxx
25 // Author : Paul RASCLE, EDF
29 #ifndef _SMESH_GEN_I_HXX_
30 #define _SMESH_GEN_I_HXX_
34 #include <SALOMEconfig.h>
35 #include CORBA_SERVER_HEADER(SMESH_Gen)
36 #include CORBA_SERVER_HEADER(SMESH_Mesh)
37 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
38 #include CORBA_CLIENT_HEADER(GEOM_Gen)
39 #include CORBA_CLIENT_HEADER(SALOMEDS)
40 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
42 #include "SMESH_Mesh_i.hxx"
43 #include "SMESH_Hypothesis_i.hxx"
44 #include "SALOME_Component_i.hxx"
45 #include "SALOME_NamingService.hxx"
47 #include "SMESH_Gen.hxx"
48 #include "GEOM_Client.hxx"
50 #include <TCollection_AsciiString.hxx>
51 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
52 #include <TColStd_HSequenceOfAsciiString.hxx>
58 class SALOME_LifeCycleCORBA;
60 // ===========================================================
61 // Study context - stores study-connected objects references
62 // ==========================================================
63 class SMESH_I_EXPORT StudyContext
74 // register object in the internal map and return its id
75 int addObject( string theIOR )
77 int nextId = getNextId();
78 mapIdToIOR[ nextId ] = theIOR;
81 // find the object id in the internal map by the IOR
82 int findId( string theIOR )
84 map<int, string>::iterator imap;
85 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
86 if ( imap->second == theIOR )
91 // get object's IOR by id
92 string getIORbyId( const int theId )
94 if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
95 return mapIdToIOR[ theId ];
98 // get object's IOR by old id
99 string getIORbyOldId( const int theOldId )
101 if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
102 return getIORbyId( mapIdToId[ theOldId ] );
105 // maps old object id to the new one (used when restoring data)
106 void mapOldToNew( const int oldId, const int newId ) {
107 mapIdToId[ oldId ] = newId;
109 // get old id by a new one
110 int getOldId( const int newId ) {
111 map<int, int>::iterator imap;
112 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
113 if ( imap->second == newId )
120 // get next free object identifier
124 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
129 map<int, string> mapIdToIOR; // persistent-to-transient map
130 map<int, int> mapIdToId; // used to translate object from persistent to transient form
133 // ===========================================================
134 // SMESH module's engine
135 // ==========================================================
136 class SMESH_I_EXPORT SMESH_Gen_i:
137 public virtual POA_SMESH::SMESH_Gen,
138 public virtual Engines_Component_i
141 // Get last created instance of the class
142 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
144 static CORBA::ORB_var GetORB() { return myOrb;}
145 // Get SMESH module's POA object
146 static PortableServer::POA_var GetPOA() { return myPoa;}
147 // Get Naming Service object
148 static SALOME_NamingService* GetNS();
149 // Get SALOME_LifeCycleCORBA object
150 static SALOME_LifeCycleCORBA* GetLCC();
151 // Retrieve and get GEOM engine reference
152 static GEOM::GEOM_Gen_ptr GetGeomEngine();
153 // Get object of the CORBA reference
154 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
155 // Get CORBA object corresponding to the SALOMEDS::SObject
156 static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
157 // Get the SALOMEDS::SObject corresponding to a CORBA object
158 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
159 CORBA::Object_ptr theObject);
160 // Get GEOM Object correspoding to TopoDS_Shape
161 GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
162 // Get TopoDS_Shape correspoding to GEOM_Object
163 TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
165 // Default constructor
167 // Standard constructor
168 SMESH_Gen_i( CORBA::ORB_ptr orb,
169 PortableServer::POA_ptr poa,
170 PortableServer::ObjectId* contId,
171 const char* instanceName,
172 const char* interfaceName );
174 virtual ~SMESH_Gen_i();
176 // *****************************************
178 // *****************************************
181 void SetEmbeddedMode( CORBA::Boolean theMode );
183 CORBA::Boolean IsEmbeddedMode();
186 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
188 SALOMEDS::Study_ptr GetCurrentStudy();
190 // Create hypothesis/algorothm of given type
191 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
192 const char* theLibName)
193 throw ( SALOME::SALOME_Exception );
195 // Return hypothesis of given type holding parameter values of the existing mesh
196 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
197 const char* theLibName,
198 SMESH::SMESH_Mesh_ptr theMesh,
199 GEOM::GEOM_Object_ptr theGeom)
200 throw ( SALOME::SALOME_Exception );
202 // Create empty mesh on a shape
203 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
204 throw ( SALOME::SALOME_Exception );
207 SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
208 throw ( SALOME::SALOME_Exception );
210 // Create mesh(es) and import data from UNV file
211 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
212 throw ( SALOME::SALOME_Exception );
214 // Create mesh(es) and import data from MED file
215 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
216 SMESH::DriverMED_ReadStatus& theStatus )
217 throw ( SALOME::SALOME_Exception );
219 // Create mesh(es) and import data from STL file
220 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
221 throw ( SALOME::SALOME_Exception );
223 // Compute mesh on a shape
224 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
225 GEOM::GEOM_Object_ptr theShapeObject )
226 throw ( SALOME::SALOME_Exception );
228 * \brief Return errors of mesh computation
230 SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
231 GEOM::GEOM_Object_ptr theShapeObject )
232 throw ( SALOME::SALOME_Exception );
234 // Returns true if mesh contains enough data to be computed
235 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
236 GEOM::GEOM_Object_ptr theShapeObject )
237 throw ( SALOME::SALOME_Exception );
239 // Returns errors of hypotheses definintion
240 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
241 GEOM::GEOM_Object_ptr theSubObject )
242 throw ( SALOME::SALOME_Exception );
244 // Get sub-shapes unique ID's list
245 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
246 const SMESH::object_array& theListOfSubShape )
247 throw ( SALOME::SALOME_Exception );
249 // Return geometrical object the given element is built on. Publish it in study.
250 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
251 CORBA::Long theElementID,
252 const char* theGeomName)
253 throw ( SALOME::SALOME_Exception );
255 // Return geometrical object the given element is built on. Don't publish it in study.
256 GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
257 CORBA::Long theElementID)
258 throw ( SALOME::SALOME_Exception );
260 // Concatenate the given meshes into one mesh
261 SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray,
262 CORBA::Boolean theUniteIdenticalGroups,
263 CORBA::Boolean theMergeNodesAndElements,
264 CORBA::Double theMergeTolerance)
265 throw ( SALOME::SALOME_Exception );
268 // ****************************************************
269 // Interface inherited methods (from SALOMEDS::Driver)
270 // ****************************************************
273 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
277 bool Load( SALOMEDS::SComponent_ptr theComponent,
278 const SALOMEDS::TMPFile& theStream,
281 // Save SMESH data in ASCII format
282 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
285 // Load SMESH data in ASCII format
286 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
287 const SALOMEDS::TMPFile& theStream,
291 // Create filter manager
292 SMESH::FilterManager_ptr CreateFilterManager();
294 // Return a pattern mesher
295 SMESH::SMESH_Pattern_ptr GetPattern();
297 // Clears study-connected data when it is closed
298 void Close( SALOMEDS::SComponent_ptr theComponent );
300 // Get component data type
301 char* ComponentDataType();
303 // Transform data from transient form to persistent
304 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
305 const char* IORString,
306 CORBA::Boolean isMultiFile,
307 CORBA::Boolean isASCII );
308 // Transform data from persistent form to transient
309 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
310 const char* aLocalPersistentID,
311 CORBA::Boolean isMultiFile,
312 CORBA::Boolean isASCII );
314 // Returns true if object can be published in the study
315 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
316 // Publish object in the study
317 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
318 SALOMEDS::SObject_ptr theSObject,
319 CORBA::Object_ptr theObject,
320 const char* theName )
321 throw ( SALOME::SALOME_Exception );
323 // Copy-paste methods - returns true if object can be copied to the clipboard
324 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
325 // Copy-paste methods - copy object to the clipboard
326 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
327 // Copy-paste methods - returns true if object can be pasted from the clipboard
328 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
329 // Copy-paste methods - paste object from the clipboard
330 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
331 CORBA::Long theObjectID,
332 SALOMEDS::SObject_ptr theObject ) {
333 SALOMEDS::SObject_var aResultSO;
334 return aResultSO._retn();
341 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
342 CORBA::Boolean isPublished,
343 CORBA::Boolean& isValidScript);
345 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
347 void RemoveLastFromPythonScript (int theStudyID);
349 void SavePython (SALOMEDS::Study_ptr theStudy);
351 TCollection_AsciiString DumpPython_impl (int theStudyID,
352 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
353 Resource_DataMapOfAsciiStringAsciiString& theNames,
356 const TCollection_AsciiString& theSavedTrace);
358 TCollection_AsciiString GetNewPythonLines (int theStudyID);
360 void CleanPythonTrace (int theStudyID);
363 // *****************************************
365 // *****************************************
368 GEOM_Client* GetShapeReader();
371 static long GetHypothesisRootTag();
372 static long GetAlgorithmsRootTag();
373 static long GetRefOnShapeTag();
374 static long GetRefOnAppliedHypothesisTag();
375 static long GetRefOnAppliedAlgorithmsTag();
376 static long GetSubMeshOnVertexTag();
377 static long GetSubMeshOnEdgeTag();
378 static long GetSubMeshOnFaceTag();
379 static long GetSubMeshOnSolidTag();
380 static long GetSubMeshOnCompoundTag();
381 static long GetSubMeshOnWireTag();
382 static long GetSubMeshOnShellTag();
383 static long GetNodeGroupsTag();
384 static long GetEdgeGroupsTag();
385 static long GetFaceGroupsTag();
386 static long GetVolumeGroupsTag();
388 // publishing methods
389 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
390 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
391 SMESH::SMESH_Mesh_ptr theMesh,
392 const char* theName = 0);
393 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
394 SMESH::SMESH_Hypothesis_ptr theHyp,
395 const char* theName = 0);
396 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
397 SMESH::SMESH_Mesh_ptr theMesh,
398 SMESH::SMESH_subMesh_ptr theSubMesh,
399 GEOM::GEOM_Object_ptr theShapeObject,
400 const char* theName = 0);
401 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
402 SMESH::SMESH_Mesh_ptr theMesh,
403 SMESH::SMESH_GroupBase_ptr theGroup,
404 GEOM::GEOM_Object_ptr theShapeObject,
405 const char* theName = 0);
406 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
407 SMESH::SMESH_Mesh_ptr theMesh,
408 GEOM::GEOM_Object_ptr theShapeObject,
409 SMESH::SMESH_Hypothesis_ptr theHyp);
410 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
411 SMESH::SMESH_Mesh_ptr theMesh,
412 GEOM::GEOM_Object_ptr theShapeObject,
413 SMESH::SMESH_Hypothesis_ptr theHyp);
414 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
415 SMESH::SMESH_Mesh_ptr theMesh,
416 GEOM::GEOM_Object_ptr theShape);
417 static void SetName(SALOMEDS::SObject_ptr theSObject,
419 const char* theDefaultName = 0);
422 StudyContext* GetCurrentStudyContext();
424 // Register an object in a StudyContext; return object id
425 int RegisterObject(CORBA::Object_ptr theObject);
427 // Return id of registered object
428 int GetObjectId(CORBA::Object_ptr theObject);
430 // Return an object that previously had an oldID
431 template<class TInterface>
432 typename TInterface::_var_type GetObjectByOldId( const int oldID )
434 if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
435 string ior = myStudyContext->getIORbyOldId( oldID );
437 return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
439 return TInterface::_nil();
442 // Get current study ID
443 int GetCurrentStudyID()
444 { return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId(); }
447 * \brief Find SObject for an algo
449 SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
452 // Create hypothesis of given type
453 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
454 const char* theLibName)
455 throw ( SALOME::SALOME_Exception );
457 // Create empty mesh on shape
458 SMESH::SMESH_Mesh_ptr createMesh()
459 throw ( SALOME::SALOME_Exception );
461 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
465 static CORBA::ORB_var myOrb; // ORB reference
466 static PortableServer::POA_var myPoa; // POA reference
467 static SALOME_NamingService* myNS; // Naming Service
468 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
469 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
470 ::SMESH_Gen myGen; // SMESH_Gen local implementation
472 // hypotheses managing
473 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
475 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
477 GEOM_Client* myShapeReader; // Shape reader
478 SALOMEDS::Study_var myCurrentStudy; // Current study
479 CORBA::Boolean myIsEmbeddedMode; // Current mode
481 // Dump Python: trace of API methods calls
482 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
490 DownCast(CORBA::Object_ptr theArg)
492 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());