1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Gen_i.hxx
24 // Author : Paul RASCLE, EDF
27 #ifndef _SMESH_GEN_I_HXX_
28 #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 // ==========================================================
61 class SMESH_I_EXPORT StudyContext
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 if ( mapIdToIOR.find( newId ) != mapIdToIOR.end() ) {
106 mapIdToIOR[ oldId ] = mapIdToIOR[ newId ];
107 mapIdToIOR.erase( newId );
109 mapIdToId[ oldId ] = oldId;
111 // get old id by a new one
112 int getOldId( const int newId ) {
113 map<int, int>::iterator imap;
114 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
115 if ( imap->second == newId )
122 // get next free object identifier
126 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
131 map<int, string> mapIdToIOR; // persistent-to-transient map
132 map<int, int> mapIdToId; // used to translate object from persistent to transient form
135 // ===========================================================
136 // SMESH module's engine
137 // ==========================================================
138 class SMESH_I_EXPORT SMESH_Gen_i:
139 public virtual POA_SMESH::SMESH_Gen,
140 public virtual Engines_Component_i
143 // Get last created instance of the class
144 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
146 static CORBA::ORB_var GetORB() { return myOrb;}
147 // Get SMESH module's POA object
148 static PortableServer::POA_var GetPOA() { return myPoa;}
149 // Get Naming Service object
150 static SALOME_NamingService* GetNS();
151 // Get SALOME_LifeCycleCORBA object
152 static SALOME_LifeCycleCORBA* GetLCC();
153 // Retrieve and get GEOM engine reference
154 static GEOM::GEOM_Gen_ptr GetGeomEngine();
155 // Get object of the CORBA reference
156 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
157 // Get CORBA object corresponding to the SALOMEDS::SObject
158 static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
159 // Get the SALOMEDS::SObject corresponding to a CORBA object
160 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
161 CORBA::Object_ptr theObject);
162 // Get GEOM Object correspoding to TopoDS_Shape
163 GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
164 // Get TopoDS_Shape correspoding to GEOM_Object
165 TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
167 // Default constructor
169 // Standard constructor
170 SMESH_Gen_i( CORBA::ORB_ptr orb,
171 PortableServer::POA_ptr poa,
172 PortableServer::ObjectId* contId,
173 const char* instanceName,
174 const char* interfaceName );
176 virtual ~SMESH_Gen_i();
178 // *****************************************
180 // *****************************************
181 // Set a new Mesh object name
182 void SetName(const char* theIOR,
183 const char* theName);
185 //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
186 void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
189 void SetEmbeddedMode( CORBA::Boolean theMode );
191 CORBA::Boolean IsEmbeddedMode();
194 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
196 SALOMEDS::Study_ptr GetCurrentStudy();
198 // Create hypothesis/algorothm of given type
199 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
200 const char* theLibName)
201 throw ( SALOME::SALOME_Exception );
203 // Return hypothesis of given type holding parameter values of the existing mesh
204 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
205 const char* theLibName,
206 SMESH::SMESH_Mesh_ptr theMesh,
207 GEOM::GEOM_Object_ptr theGeom,
208 CORBA::Boolean byMesh)
209 throw ( SALOME::SALOME_Exception );
212 * Sets number of segments per diagonal of boundary box of geometry by which
213 * default segment length of appropriate 1D hypotheses is defined
215 void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
217 * \brief Sets default number of segments per edge
219 void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
221 // Create empty mesh on a shape
222 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
223 throw ( SALOME::SALOME_Exception );
226 SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
227 throw ( SALOME::SALOME_Exception );
229 // Create mesh(es) and import data from UNV file
230 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
231 throw ( SALOME::SALOME_Exception );
233 // Create mesh(es) and import data from MED file
234 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
235 SMESH::DriverMED_ReadStatus& theStatus )
236 throw ( SALOME::SALOME_Exception );
238 // Create mesh(es) and import data from STL file
239 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
240 throw ( SALOME::SALOME_Exception );
242 // Compute mesh on a shape
243 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
244 GEOM::GEOM_Object_ptr theShapeObject )
245 throw ( SALOME::SALOME_Exception );
247 * \brief Return errors of mesh computation
249 SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
250 GEOM::GEOM_Object_ptr theShapeObject )
251 throw ( SALOME::SALOME_Exception );
254 * Evaluate mesh on a shape and
255 * returns statistic of mesh elements
256 * Result array of number enityties
258 SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
259 GEOM::GEOM_Object_ptr theShapeObject)
260 throw ( SALOME::SALOME_Exception );
262 // Returns true if mesh contains enough data to be computed
263 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
264 GEOM::GEOM_Object_ptr theShapeObject )
265 throw ( SALOME::SALOME_Exception );
268 * Calculate Mesh as preview till indicated dimension on shape
269 * First, verify list of hypothesis associated with the subShape.
270 * Return mesh preview structure
272 SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
273 GEOM::GEOM_Object_ptr theSubObject,
274 SMESH::Dimension theDimension,
275 SMESH::long_array& theShapesId )
276 throw ( SALOME::SALOME_Exception );
278 // Returns errors of hypotheses definintion
279 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
280 GEOM::GEOM_Object_ptr theSubObject )
281 throw ( SALOME::SALOME_Exception );
283 // Return mesh elements preventing computation of a subshape
284 SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
285 CORBA::Short theSubShapeID )
286 throw ( SALOME::SALOME_Exception );
288 // Get sub-shapes unique ID's list
289 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
290 const SMESH::object_array& theListOfSubShape )
291 throw ( SALOME::SALOME_Exception );
293 // Return geometrical object the given element is built on. Publish it in study.
294 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
295 CORBA::Long theElementID,
296 const char* theGeomName)
297 throw ( SALOME::SALOME_Exception );
299 // Return geometrical object the given element is built on. Don't publish it in study.
300 GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
301 CORBA::Long theElementID)
302 throw ( SALOME::SALOME_Exception );
304 // Concatenate the given meshes into one mesh
305 SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
306 CORBA::Boolean theUniteIdenticalGroups,
307 CORBA::Boolean theMergeNodesAndElements,
308 CORBA::Double theMergeTolerance,
309 CORBA::Boolean theCommonGroups)
310 throw ( SALOME::SALOME_Exception );
312 // Concatenate the given meshes into one mesh
313 SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray,
314 CORBA::Boolean theUniteIdenticalGroups,
315 CORBA::Boolean theMergeNodesAndElements,
316 CORBA::Double theMergeTolerance)
317 throw ( SALOME::SALOME_Exception );
319 // Concatenate the given meshes into one mesh
320 // Create the groups of all elements from initial meshes
321 SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
322 CORBA::Boolean theUniteIdenticalGroups,
323 CORBA::Boolean theMergeNodesAndElements,
324 CORBA::Double theMergeTolerance)
325 throw ( SALOME::SALOME_Exception );
327 // ****************************************************
328 // Interface inherited methods (from SALOMEDS::Driver)
329 // ****************************************************
332 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
336 bool Load( SALOMEDS::SComponent_ptr theComponent,
337 const SALOMEDS::TMPFile& theStream,
340 // Save SMESH data in ASCII format
341 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
344 // Load SMESH data in ASCII format
345 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
346 const SALOMEDS::TMPFile& theStream,
350 // Create filter manager
351 SMESH::FilterManager_ptr CreateFilterManager();
353 // Return a pattern mesher
354 SMESH::SMESH_Pattern_ptr GetPattern();
356 // Clears study-connected data when it is closed
357 void Close( SALOMEDS::SComponent_ptr theComponent );
359 // Get component data type
360 char* ComponentDataType();
362 // Transform data from transient form to persistent
363 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
364 const char* IORString,
365 CORBA::Boolean isMultiFile,
366 CORBA::Boolean isASCII );
367 // Transform data from persistent form to transient
368 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
369 const char* aLocalPersistentID,
370 CORBA::Boolean isMultiFile,
371 CORBA::Boolean isASCII );
373 // Returns true if object can be published in the study
374 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
375 // Publish object in the study
376 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
377 SALOMEDS::SObject_ptr theSObject,
378 CORBA::Object_ptr theObject,
379 const char* theName )
380 throw ( SALOME::SALOME_Exception );
382 // Copy-paste methods - returns true if object can be copied to the clipboard
383 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
384 // Copy-paste methods - copy object to the clipboard
385 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
386 // Copy-paste methods - returns true if object can be pasted from the clipboard
387 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
388 // Copy-paste methods - paste object from the clipboard
389 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
390 CORBA::Long theObjectID,
391 SALOMEDS::SObject_ptr theObject ) {
392 SALOMEDS::SObject_var aResultSO;
393 return aResultSO._retn();
400 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
401 CORBA::Boolean isPublished,
402 CORBA::Boolean& isValidScript);
404 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
406 void RemoveLastFromPythonScript (int theStudyID);
408 void SavePython (SALOMEDS::Study_ptr theStudy);
410 TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
411 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
412 Resource_DataMapOfAsciiStringAsciiString& theNames,
415 const TCollection_AsciiString& theSavedTrace);
417 TCollection_AsciiString GetNewPythonLines (int theStudyID);
419 void CleanPythonTrace (int theStudyID);
422 // *****************************************
424 // *****************************************
427 GEOM_Client* GetShapeReader();
430 static long GetHypothesisRootTag();
431 static long GetAlgorithmsRootTag();
432 static long GetRefOnShapeTag();
433 static long GetRefOnAppliedHypothesisTag();
434 static long GetRefOnAppliedAlgorithmsTag();
435 static long GetSubMeshOnVertexTag();
436 static long GetSubMeshOnEdgeTag();
437 static long GetSubMeshOnFaceTag();
438 static long GetSubMeshOnSolidTag();
439 static long GetSubMeshOnCompoundTag();
440 static long GetSubMeshOnWireTag();
441 static long GetSubMeshOnShellTag();
442 static long GetNodeGroupsTag();
443 static long GetEdgeGroupsTag();
444 static long GetFaceGroupsTag();
445 static long GetVolumeGroupsTag();
447 // publishing methods
448 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
449 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
450 SMESH::SMESH_Mesh_ptr theMesh,
451 const char* theName = 0);
452 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
453 SMESH::SMESH_Hypothesis_ptr theHyp,
454 const char* theName = 0);
455 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
456 SMESH::SMESH_Mesh_ptr theMesh,
457 SMESH::SMESH_subMesh_ptr theSubMesh,
458 GEOM::GEOM_Object_ptr theShapeObject,
459 const char* theName = 0);
460 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
461 SMESH::SMESH_Mesh_ptr theMesh,
462 SMESH::SMESH_GroupBase_ptr theGroup,
463 GEOM::GEOM_Object_ptr theShapeObject,
464 const char* theName = 0);
465 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
466 SMESH::SMESH_Mesh_ptr theMesh,
467 GEOM::GEOM_Object_ptr theShapeObject,
468 SMESH::SMESH_Hypothesis_ptr theHyp);
469 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
470 SMESH::SMESH_Mesh_ptr theMesh,
471 GEOM::GEOM_Object_ptr theShapeObject,
472 SMESH::SMESH_Hypothesis_ptr theHyp);
473 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
474 SMESH::SMESH_Mesh_ptr theMesh,
475 GEOM::GEOM_Object_ptr theShape);
476 static void SetName(SALOMEDS::SObject_ptr theSObject,
478 const char* theDefaultName = 0);
480 static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
481 const char* thePixMap);
484 StudyContext* GetStudyContext( int theStudyId );
486 // Get current study context
487 StudyContext* GetCurrentStudyContext();
489 // Register an object in a StudyContext; return object id
490 int RegisterObject(CORBA::Object_ptr theObject);
492 // Return id of registered object
493 CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
495 // Return an object that previously had an oldID
496 template<class TInterface>
497 typename TInterface::_var_type GetObjectByOldId( const int oldID )
499 if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
500 string ior = myStudyContext->getIORbyOldId( oldID );
502 return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
504 return TInterface::_nil();
507 // Get current study ID
508 int GetCurrentStudyID();
511 * \brief Find SObject for an algo
513 SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
515 SALOMEDS::Study_ptr GetStudy(CORBA::Long theStudyID);
516 SALOME::Notebook_ptr GetNotebook(CORBA::Long theStudyID);
518 virtual SALOME::GenericObj_ptr FindObjectByInternalEntry( CORBA::Long theStudyID, const char* theEntry );
521 // Create hypothesis of given type
522 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
523 const char* theLibName)
524 throw ( SALOME::SALOME_Exception );
526 // Create empty mesh on shape
527 SMESH::SMESH_Mesh_ptr createMesh()
528 throw ( SALOME::SALOME_Exception );
530 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
533 static GEOM::GEOM_Gen_var myGeomGen;
534 static CORBA::ORB_var myOrb; // ORB reference
535 static PortableServer::POA_var myPoa; // POA reference
536 static SALOME_NamingService* myNS; // Naming Service
537 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
538 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
539 ::SMESH_Gen myGen; // SMESH_Gen local implementation
541 // hypotheses managing
542 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
544 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
546 GEOM_Client* myShapeReader; // Shape reader
547 SALOMEDS::Study_var myCurrentStudy; // Current study
548 CORBA::Boolean myIsEmbeddedMode; // Current mode
550 // Dump Python: trace of API methods calls
551 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
559 DownCast(CORBA::Object_ptr theArg)
561 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());