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_
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;
107 // get old id by a new one
108 int getOldId( const int newId ) {
109 map<int, int>::iterator imap;
110 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
111 if ( imap->second == newId )
118 // get next free object identifier
122 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
127 map<int, string> mapIdToIOR; // persistent-to-transient map
128 map<int, int> mapIdToId; // used to translate object from persistent to transient form
131 // ===========================================================
132 // SMESH module's engine
133 // ==========================================================
135 public virtual POA_SMESH::SMESH_Gen,
136 public virtual Engines_Component_i
139 // Get last created instance of the class
140 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
142 static CORBA::ORB_var GetORB() { return myOrb;}
143 // Get SMESH module's POA object
144 static PortableServer::POA_var GetPOA() { return myPoa;}
145 // Get Naming Service object
146 static SALOME_NamingService* GetNS();
147 // Get SALOME_LifeCycleCORBA object
148 static SALOME_LifeCycleCORBA* GetLCC();
149 // Retrieve and get GEOM engine reference
150 static GEOM::GEOM_Gen_ptr GetGeomEngine();
151 // Get object of the CORBA reference
152 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
153 // Get CORBA object corresponding to the SALOMEDS::SObject
154 static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
155 // Get the SALOMEDS::SObject corresponding to a CORBA object
156 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
157 CORBA::Object_ptr theObject);
158 // Get GEOM Object correspoding to TopoDS_Shape
159 GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
160 // Get TopoDS_Shape correspoding to GEOM_Object
161 TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
163 // Default constructor
165 // Standard constructor
166 SMESH_Gen_i( CORBA::ORB_ptr orb,
167 PortableServer::POA_ptr poa,
168 PortableServer::ObjectId* contId,
169 const char* instanceName,
170 const char* interfaceName );
172 virtual ~SMESH_Gen_i();
174 // *****************************************
176 // *****************************************
179 void SetEmbeddedMode( CORBA::Boolean theMode );
181 CORBA::Boolean IsEmbeddedMode();
184 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
186 SALOMEDS::Study_ptr GetCurrentStudy();
188 // Create hypothesis/algorothm of given type
189 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
190 const char* theLibName)
191 throw ( SALOME::SALOME_Exception );
193 // Return hypothesis of given type holding parameter values of the existing mesh
194 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
195 const char* theLibName,
196 SMESH::SMESH_Mesh_ptr theMesh,
197 GEOM::GEOM_Object_ptr theGeom)
198 throw ( SALOME::SALOME_Exception );
200 // Create empty mesh on a shape
201 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
202 throw ( SALOME::SALOME_Exception );
205 SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
206 throw ( SALOME::SALOME_Exception );
208 // Create mesh(es) and import data from UNV file
209 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
210 throw ( SALOME::SALOME_Exception );
212 // Create mesh(es) and import data from MED file
213 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
214 SMESH::DriverMED_ReadStatus& theStatus )
215 throw ( SALOME::SALOME_Exception );
217 // Create mesh(es) and import data from STL file
218 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
219 throw ( SALOME::SALOME_Exception );
221 // Compute mesh on a shape
222 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
223 GEOM::GEOM_Object_ptr theShapeObject )
224 throw ( SALOME::SALOME_Exception );
226 * \brief Return errors of mesh computation
228 SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
229 GEOM::GEOM_Object_ptr theShapeObject )
230 throw ( SALOME::SALOME_Exception );
232 // Returns true if mesh contains enough data to be computed
233 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
234 GEOM::GEOM_Object_ptr theShapeObject )
235 throw ( SALOME::SALOME_Exception );
237 // Returns errors of hypotheses definintion
238 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
239 GEOM::GEOM_Object_ptr theSubObject )
240 throw ( SALOME::SALOME_Exception );
242 // Get sub-shapes unique ID's list
243 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
244 const SMESH::object_array& theListOfSubShape )
245 throw ( SALOME::SALOME_Exception );
247 // Return geometrical object the given element is built on. Publish it in study.
248 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
249 CORBA::Long theElementID,
250 const char* theGeomName)
251 throw ( SALOME::SALOME_Exception );
253 // Return geometrical object the given element is built on. Don't publish it in study.
254 GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
255 CORBA::Long theElementID)
256 throw ( SALOME::SALOME_Exception );
258 // Concatenate the given meshes into one mesh
259 SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray,
260 CORBA::Boolean theUniteIdenticalGroups,
261 CORBA::Boolean theMergeNodesAndElements,
262 CORBA::Double theMergeTolerance)
263 throw ( SALOME::SALOME_Exception );
266 // ****************************************************
267 // Interface inherited methods (from SALOMEDS::Driver)
268 // ****************************************************
271 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
275 bool Load( SALOMEDS::SComponent_ptr theComponent,
276 const SALOMEDS::TMPFile& theStream,
279 // Save SMESH data in ASCII format
280 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
283 // Load SMESH data in ASCII format
284 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
285 const SALOMEDS::TMPFile& theStream,
289 // Create filter manager
290 SMESH::FilterManager_ptr CreateFilterManager();
292 // Return a pattern mesher
293 SMESH::SMESH_Pattern_ptr GetPattern();
295 // Clears study-connected data when it is closed
296 void Close( SALOMEDS::SComponent_ptr theComponent );
298 // Get component data type
299 char* ComponentDataType();
301 // Transform data from transient form to persistent
302 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
303 const char* IORString,
304 CORBA::Boolean isMultiFile,
305 CORBA::Boolean isASCII );
306 // Transform data from persistent form to transient
307 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
308 const char* aLocalPersistentID,
309 CORBA::Boolean isMultiFile,
310 CORBA::Boolean isASCII );
312 // Returns true if object can be published in the study
313 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
314 // Publish object in the study
315 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
316 SALOMEDS::SObject_ptr theSObject,
317 CORBA::Object_ptr theObject,
318 const char* theName )
319 throw ( SALOME::SALOME_Exception );
321 // Copy-paste methods - returns true if object can be copied to the clipboard
322 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
323 // Copy-paste methods - copy object to the clipboard
324 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
325 // Copy-paste methods - returns true if object can be pasted from the clipboard
326 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
327 // Copy-paste methods - paste object from the clipboard
328 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
329 CORBA::Long theObjectID,
330 SALOMEDS::SObject_ptr theObject ) {
331 SALOMEDS::SObject_var aResultSO;
332 return aResultSO._retn();
339 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
340 CORBA::Boolean isPublished,
341 CORBA::Boolean& isValidScript);
343 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
345 void RemoveLastFromPythonScript (int theStudyID);
347 void SavePython (SALOMEDS::Study_ptr theStudy);
349 TCollection_AsciiString DumpPython_impl (int theStudyID,
350 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
351 Resource_DataMapOfAsciiStringAsciiString& theNames,
354 const TCollection_AsciiString& theSavedTrace);
356 TCollection_AsciiString GetNewPythonLines (int theStudyID);
358 void CleanPythonTrace (int theStudyID);
361 // *****************************************
363 // *****************************************
366 GEOM_Client* GetShapeReader();
369 static long GetHypothesisRootTag();
370 static long GetAlgorithmsRootTag();
371 static long GetRefOnShapeTag();
372 static long GetRefOnAppliedHypothesisTag();
373 static long GetRefOnAppliedAlgorithmsTag();
374 static long GetSubMeshOnVertexTag();
375 static long GetSubMeshOnEdgeTag();
376 static long GetSubMeshOnFaceTag();
377 static long GetSubMeshOnSolidTag();
378 static long GetSubMeshOnCompoundTag();
379 static long GetSubMeshOnWireTag();
380 static long GetSubMeshOnShellTag();
381 static long GetNodeGroupsTag();
382 static long GetEdgeGroupsTag();
383 static long GetFaceGroupsTag();
384 static long GetVolumeGroupsTag();
386 // publishing methods
387 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
388 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
389 SMESH::SMESH_Mesh_ptr theMesh,
390 const char* theName = 0);
391 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
392 SMESH::SMESH_Hypothesis_ptr theHyp,
393 const char* theName = 0);
394 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
395 SMESH::SMESH_Mesh_ptr theMesh,
396 SMESH::SMESH_subMesh_ptr theSubMesh,
397 GEOM::GEOM_Object_ptr theShapeObject,
398 const char* theName = 0);
399 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
400 SMESH::SMESH_Mesh_ptr theMesh,
401 SMESH::SMESH_GroupBase_ptr theGroup,
402 GEOM::GEOM_Object_ptr theShapeObject,
403 const char* theName = 0);
404 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
405 SMESH::SMESH_Mesh_ptr theMesh,
406 GEOM::GEOM_Object_ptr theShapeObject,
407 SMESH::SMESH_Hypothesis_ptr theHyp);
408 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
409 SMESH::SMESH_Mesh_ptr theMesh,
410 GEOM::GEOM_Object_ptr theShapeObject,
411 SMESH::SMESH_Hypothesis_ptr theHyp);
412 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
413 SMESH::SMESH_Mesh_ptr theMesh,
414 GEOM::GEOM_Object_ptr theShape);
415 static void SetName(SALOMEDS::SObject_ptr theSObject,
417 const char* theDefaultName = 0);
420 StudyContext* GetCurrentStudyContext();
422 // Register an object in a StudyContext; return object id
423 int RegisterObject(CORBA::Object_ptr theObject);
425 // Return id of registered object
426 int GetObjectId(CORBA::Object_ptr theObject);
428 // Return an object that previously had an oldID
429 template<class TInterface>
430 typename TInterface::_var_type GetObjectByOldId( const int oldID )
432 if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
433 string ior = myStudyContext->getIORbyOldId( oldID );
435 return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
437 return TInterface::_nil();
440 // Get current study ID
441 int GetCurrentStudyID()
442 { return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId(); }
445 * \brief Find SObject for an algo
447 SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
450 // Create hypothesis of given type
451 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
452 const char* theLibName)
453 throw ( SALOME::SALOME_Exception );
455 // Create empty mesh on shape
456 SMESH::SMESH_Mesh_ptr createMesh()
457 throw ( SALOME::SALOME_Exception );
459 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
463 static CORBA::ORB_var myOrb; // ORB reference
464 static PortableServer::POA_var myPoa; // POA reference
465 static SALOME_NamingService* myNS; // Naming Service
466 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
467 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
468 ::SMESH_Gen myGen; // SMESH_Gen local implementation
470 // hypotheses managing
471 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
473 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
475 GEOM_Client* myShapeReader; // Shape reader
476 SALOMEDS::Study_var myCurrentStudy; // Current study
477 CORBA::Boolean myIsEmbeddedMode; // Current mode
479 // Dump Python: trace of API methods calls
480 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
488 DownCast(CORBA::Object_ptr theArg)
490 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());