1 // Copyright (C) 2007-2010 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 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 // ==========================================================
134 class SMESH_I_EXPORT SMESH_Gen_i:
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 // *****************************************
177 // Set a new Mesh object name
178 void SetName(const char* theIOR,
179 const char* theName);
181 //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
182 void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
185 void SetEmbeddedMode( CORBA::Boolean theMode );
187 CORBA::Boolean IsEmbeddedMode();
190 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
192 SALOMEDS::Study_ptr GetCurrentStudy();
194 // Create hypothesis/algorothm of given type
195 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
196 const char* theLibName)
197 throw ( SALOME::SALOME_Exception );
199 // Return hypothesis of given type holding parameter values of the existing mesh
200 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
201 const char* theLibName,
202 SMESH::SMESH_Mesh_ptr theMesh,
203 GEOM::GEOM_Object_ptr theGeom,
204 CORBA::Boolean byMesh)
205 throw ( SALOME::SALOME_Exception );
208 * Sets number of segments per diagonal of boundary box of geometry by which
209 * default segment length of appropriate 1D hypotheses is defined
211 void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
213 * \brief Sets default number of segments per edge
215 void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
217 // Create empty mesh on a shape
218 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
219 throw ( SALOME::SALOME_Exception );
222 SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
223 throw ( SALOME::SALOME_Exception );
225 // Create mesh(es) and import data from UNV fileter
226 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
227 throw ( SALOME::SALOME_Exception );
229 // Create mesh(es) and import data from MED file
230 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
231 SMESH::DriverMED_ReadStatus& theStatus )
232 throw ( SALOME::SALOME_Exception );
234 // Create mesh(es) and import data from STL file
235 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
236 throw ( SALOME::SALOME_Exception );
238 // Copy a part of mesh
239 SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
240 const char* meshName,
241 CORBA::Boolean toCopyGroups,
242 CORBA::Boolean toKeepIDs);
244 // Compute mesh on a shape
245 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
246 GEOM::GEOM_Object_ptr theShapeObject )
247 throw ( SALOME::SALOME_Exception );
249 * \brief Return errors of mesh computation
251 SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
252 GEOM::GEOM_Object_ptr theShapeObject )
253 throw ( SALOME::SALOME_Exception );
256 * Evaluate mesh on a shape and
257 * returns statistic of mesh elements
258 * Result array of number enityties
260 SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
261 GEOM::GEOM_Object_ptr theShapeObject)
262 throw ( SALOME::SALOME_Exception );
264 // Returns true if mesh contains enough data to be computed
265 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
266 GEOM::GEOM_Object_ptr theShapeObject )
267 throw ( SALOME::SALOME_Exception );
270 * Calculate Mesh as preview till indicated dimension on shape
271 * First, verify list of hypothesis associated with the subShape.
272 * Return mesh preview structure
274 SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
275 GEOM::GEOM_Object_ptr theSubObject,
276 SMESH::Dimension theDimension,
277 SMESH::long_array& theShapesId )
278 throw ( SALOME::SALOME_Exception );
280 // Returns errors of hypotheses definintion
281 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
282 GEOM::GEOM_Object_ptr theSubObject )
283 throw ( SALOME::SALOME_Exception );
285 // Return mesh elements preventing computation of a subshape
286 SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
287 CORBA::Short theSubShapeID )
288 throw ( SALOME::SALOME_Exception );
290 // Get sub-shapes unique ID's list
291 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
292 const SMESH::object_array& theListOfSubShape )
293 throw ( SALOME::SALOME_Exception );
295 // Return geometrical object the given element is built on. Publish it in study.
296 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
297 CORBA::Long theElementID,
298 const char* theGeomName)
299 throw ( SALOME::SALOME_Exception );
301 // Return geometrical object the given element is built on. Don't publish it in study.
302 GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
303 CORBA::Long theElementID)
304 throw ( SALOME::SALOME_Exception );
306 // Concatenate the given meshes into one mesh
307 SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
308 CORBA::Boolean theUniteIdenticalGroups,
309 CORBA::Boolean theMergeNodesAndElements,
310 CORBA::Double theMergeTolerance,
311 CORBA::Boolean theCommonGroups)
312 throw ( SALOME::SALOME_Exception );
314 // Concatenate the given meshes into one mesh
315 SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray,
316 CORBA::Boolean theUniteIdenticalGroups,
317 CORBA::Boolean theMergeNodesAndElements,
318 CORBA::Double theMergeTolerance)
319 throw ( SALOME::SALOME_Exception );
321 // Concatenate the given meshes into one mesh
322 // Create the groups of all elements from initial meshes
323 SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
324 CORBA::Boolean theUniteIdenticalGroups,
325 CORBA::Boolean theMergeNodesAndElements,
326 CORBA::Double theMergeTolerance)
327 throw ( SALOME::SALOME_Exception );
329 // Get MED version of the file by its name
330 CORBA::Boolean GetMEDVersion(const char* theFileName,
331 SMESH::MED_VERSION& theVersion);
333 // Get names of meshes defined in file with the specified name
334 SMESH::string_array* GetMeshNames(const char* theFileName);
336 // ****************************************************
337 // Interface inherited methods (from SALOMEDS::Driver)
338 // ****************************************************
341 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
345 bool Load( SALOMEDS::SComponent_ptr theComponent,
346 const SALOMEDS::TMPFile& theStream,
349 // Save SMESH data in ASCII format
350 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
353 // Load SMESH data in ASCII format
354 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
355 const SALOMEDS::TMPFile& theStream,
359 // Create filter manager
360 SMESH::FilterManager_ptr CreateFilterManager();
362 // Return a pattern mesher
363 SMESH::SMESH_Pattern_ptr GetPattern();
365 // Create measurement instance
366 SMESH::Measurements_ptr CreateMeasurements();
368 // Clears study-connected data when it is closed
369 void Close( SALOMEDS::SComponent_ptr theComponent );
371 // Get component data type
372 char* ComponentDataType();
374 // Transform data from transient form to persistent
375 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
376 const char* IORString,
377 CORBA::Boolean isMultiFile,
378 CORBA::Boolean isASCII );
379 // Transform data from persistent form to transient
380 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
381 const char* aLocalPersistentID,
382 CORBA::Boolean isMultiFile,
383 CORBA::Boolean isASCII );
385 // Returns true if object can be published in the study
386 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
387 // Publish object in the study
388 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
389 SALOMEDS::SObject_ptr theSObject,
390 CORBA::Object_ptr theObject,
391 const char* theName )
392 throw ( SALOME::SALOME_Exception );
394 // Copy-paste methods - returns true if object can be copied to the clipboard
395 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
396 // Copy-paste methods - copy object to the clipboard
397 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
398 // Copy-paste methods - returns true if object can be pasted from the clipboard
399 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
400 // Copy-paste methods - paste object from the clipboard
401 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
402 CORBA::Long theObjectID,
403 SALOMEDS::SObject_ptr theObject ) {
404 SALOMEDS::SObject_var aResultSO;
405 return aResultSO._retn();
412 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
413 CORBA::Boolean isPublished,
414 CORBA::Boolean& isValidScript);
416 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
418 void RemoveLastFromPythonScript (int theStudyID);
420 void SavePython (SALOMEDS::Study_ptr theStudy);
422 TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
423 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
424 Resource_DataMapOfAsciiStringAsciiString& theNames,
427 const TCollection_AsciiString& theSavedTrace);
429 TCollection_AsciiString GetNewPythonLines (int theStudyID);
431 void CleanPythonTrace (int theStudyID);
434 // *****************************************
436 // *****************************************
439 GEOM_Client* GetShapeReader();
442 static long GetHypothesisRootTag();
443 static long GetAlgorithmsRootTag();
444 static long GetRefOnShapeTag();
445 static long GetRefOnAppliedHypothesisTag();
446 static long GetRefOnAppliedAlgorithmsTag();
447 static long GetSubMeshOnVertexTag();
448 static long GetSubMeshOnEdgeTag();
449 static long GetSubMeshOnFaceTag();
450 static long GetSubMeshOnSolidTag();
451 static long GetSubMeshOnCompoundTag();
452 static long GetSubMeshOnWireTag();
453 static long GetSubMeshOnShellTag();
454 static long GetNodeGroupsTag();
455 static long GetEdgeGroupsTag();
456 static long GetFaceGroupsTag();
457 static long GetVolumeGroupsTag();
459 // publishing methods
460 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
461 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
462 SMESH::SMESH_Mesh_ptr theMesh,
463 const char* theName = 0);
464 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
465 SMESH::SMESH_Hypothesis_ptr theHyp,
466 const char* theName = 0);
467 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
468 SMESH::SMESH_Mesh_ptr theMesh,
469 SMESH::SMESH_subMesh_ptr theSubMesh,
470 GEOM::GEOM_Object_ptr theShapeObject,
471 const char* theName = 0);
472 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
473 SMESH::SMESH_Mesh_ptr theMesh,
474 SMESH::SMESH_GroupBase_ptr theGroup,
475 GEOM::GEOM_Object_ptr theShapeObject,
476 const char* theName = 0);
477 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
478 SMESH::SMESH_Mesh_ptr theMesh,
479 GEOM::GEOM_Object_ptr theShapeObject,
480 SMESH::SMESH_Hypothesis_ptr theHyp);
481 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
482 SMESH::SMESH_Mesh_ptr theMesh,
483 GEOM::GEOM_Object_ptr theShapeObject,
484 SMESH::SMESH_Hypothesis_ptr theHyp);
485 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
486 SMESH::SMESH_Mesh_ptr theMesh,
487 GEOM::GEOM_Object_ptr theShape);
488 static void SetName(SALOMEDS::SObject_ptr theSObject,
490 const char* theDefaultName = 0);
492 static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
493 const char* thePixMap);
496 StudyContext* GetCurrentStudyContext();
498 // Register an object in a StudyContext; return object id
499 int RegisterObject(CORBA::Object_ptr theObject);
501 // Return id of registered object
502 CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
504 // Return an object that previously had an oldID
505 template<class TInterface>
506 typename TInterface::_var_type GetObjectByOldId( const int oldID )
508 if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
509 string ior = myStudyContext->getIORbyOldId( oldID );
511 return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
513 return TInterface::_nil();
516 // Get current study ID
517 int GetCurrentStudyID();
520 * \brief Find SObject for an algo
522 SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
524 void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
525 char* GetParameters(CORBA::Object_ptr theObject);
526 char* ParseParameters(const char* theParameters);
530 // Create hypothesis of given type
531 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
532 const char* theLibName)
533 throw ( SALOME::SALOME_Exception );
535 // Create empty mesh on shape
536 SMESH::SMESH_Mesh_ptr createMesh()
537 throw ( SALOME::SALOME_Exception );
539 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
542 static GEOM::GEOM_Gen_var myGeomGen;
543 static CORBA::ORB_var myOrb; // ORB reference
544 static PortableServer::POA_var myPoa; // POA reference
545 static SALOME_NamingService* myNS; // Naming Service
546 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
547 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
548 ::SMESH_Gen myGen; // SMESH_Gen local implementation
550 // hypotheses managing
551 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
553 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
555 GEOM_Client* myShapeReader; // Shape reader
556 SALOMEDS::Study_var myCurrentStudy; // Current study
557 CORBA::Boolean myIsEmbeddedMode; // Current mode
559 // Dump Python: trace of API methods calls
560 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
568 DownCast(CORBA::Object_ptr theArg)
570 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());