1 // Copyright (C) 2007-2011 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 // File : SMESH_Gen_i.hxx
23 // Author : Paul RASCLE, EDF
26 #ifndef _SMESH_GEN_I_HXX_
27 #define _SMESH_GEN_I_HXX_
31 #include <SALOMEconfig.h>
32 #include CORBA_SERVER_HEADER(SMESH_Gen)
33 #include CORBA_SERVER_HEADER(SMESH_Mesh)
34 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
35 #include CORBA_CLIENT_HEADER(GEOM_Gen)
36 #include CORBA_CLIENT_HEADER(SALOMEDS)
37 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
39 #include "SMESH_Mesh_i.hxx"
40 #include "SMESH_Hypothesis_i.hxx"
41 #include "SALOME_Component_i.hxx"
42 #include "SALOME_NamingService.hxx"
44 #include "SMESH_Gen.hxx"
45 #include "GEOM_Client.hxx"
47 #include <TCollection_AsciiString.hxx>
48 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
49 #include <TColStd_HSequenceOfAsciiString.hxx>
55 class SALOME_LifeCycleCORBA;
57 // ===========================================================
58 // Study context - stores study-connected objects references
59 // ==========================================================
60 class SMESH_I_EXPORT StudyContext
71 // register object in the internal map and return its id
72 int addObject( string theIOR )
74 int nextId = getNextId();
75 mapIdToIOR[ nextId ] = theIOR;
78 // find the object id in the internal map by the IOR
79 int findId( string theIOR )
81 map<int, string>::iterator imap;
82 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
83 if ( imap->second == theIOR )
88 // get object's IOR by id
89 string getIORbyId( const int theId )
91 if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
92 return mapIdToIOR[ theId ];
95 // get object's IOR by old id
96 string getIORbyOldId( const int theOldId )
98 if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
99 return getIORbyId( mapIdToId[ theOldId ] );
102 // maps old object id to the new one (used when restoring data)
103 void mapOldToNew( const int oldId, const int newId ) {
104 mapIdToId[ oldId ] = newId;
106 // get old id by a new one
107 int getOldId( const int newId ) {
108 map<int, int>::iterator imap;
109 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
110 if ( imap->second == newId )
117 // get next free object identifier
121 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
126 map<int, string> mapIdToIOR; // persistent-to-transient map
127 map<int, int> mapIdToId; // used to translate object from persistent to transient form
130 // ===========================================================
131 // SMESH module's engine
132 // ==========================================================
133 class SMESH_I_EXPORT SMESH_Gen_i:
134 public virtual POA_SMESH::SMESH_Gen,
135 public virtual Engines_Component_i
138 // Get last created instance of the class
139 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
141 static CORBA::ORB_var GetORB() { return myOrb;}
142 // Get SMESH module's POA object
143 static PortableServer::POA_var GetPOA() { return myPoa;}
144 // Get Naming Service object
145 static SALOME_NamingService* GetNS();
146 // Get SALOME_LifeCycleCORBA object
147 static SALOME_LifeCycleCORBA* GetLCC();
148 // Retrieve and get GEOM engine reference
149 static GEOM::GEOM_Gen_ptr GetGeomEngine();
150 // Get object of the CORBA reference
151 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
152 // Get CORBA object corresponding to the SALOMEDS::SObject
153 static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
154 // Get the SALOMEDS::SObject corresponding to a CORBA object
155 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
156 CORBA::Object_ptr theObject);
157 // Get GEOM Object correspoding to TopoDS_Shape
158 GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
159 // Get TopoDS_Shape correspoding to GEOM_Object
160 TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
162 // Default constructor
164 // Standard constructor
165 SMESH_Gen_i( CORBA::ORB_ptr orb,
166 PortableServer::POA_ptr poa,
167 PortableServer::ObjectId* contId,
168 const char* instanceName,
169 const char* interfaceName );
171 virtual ~SMESH_Gen_i();
173 // *****************************************
175 // *****************************************
176 // Set a new Mesh object name
177 void SetName(const char* theIOR,
178 const char* theName);
180 //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
181 void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
184 void SetEmbeddedMode( CORBA::Boolean theMode );
186 CORBA::Boolean IsEmbeddedMode();
189 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
191 SALOMEDS::Study_ptr GetCurrentStudy();
193 // Create hypothesis/algorothm of given type
194 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
195 const char* theLibName)
196 throw ( SALOME::SALOME_Exception );
198 // Return hypothesis of given type holding parameter values of the existing mesh
199 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
200 const char* theLibName,
201 SMESH::SMESH_Mesh_ptr theMesh,
202 GEOM::GEOM_Object_ptr theGeom,
203 CORBA::Boolean byMesh)
204 throw ( SALOME::SALOME_Exception );
207 * Sets number of segments per diagonal of boundary box of geometry by which
208 * default segment length of appropriate 1D hypotheses is defined
210 void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
212 * \brief Sets default number of segments per edge
214 void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
216 // Create empty mesh on a shape
217 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
218 throw ( SALOME::SALOME_Exception );
221 SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
222 throw ( SALOME::SALOME_Exception );
224 // Create mesh(es) and import data from UNV fileter
225 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
226 throw ( SALOME::SALOME_Exception );
228 // Create mesh(es) and import data from MED file
229 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
230 SMESH::DriverMED_ReadStatus& theStatus )
231 throw ( SALOME::SALOME_Exception );
233 // Create mesh(es) and import data from STL file
234 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
235 throw ( SALOME::SALOME_Exception );
237 // Copy a part of mesh
238 SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
239 const char* meshName,
240 CORBA::Boolean toCopyGroups,
241 CORBA::Boolean toKeepIDs);
243 // Compute mesh on a shape
244 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
245 GEOM::GEOM_Object_ptr theShapeObject )
246 throw ( SALOME::SALOME_Exception );
248 // Cancel Compute mesh on a shape
249 void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
250 GEOM::GEOM_Object_ptr theShapeObject );
253 * \brief Return errors of mesh computation
255 SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
256 GEOM::GEOM_Object_ptr theShapeObject )
257 throw ( SALOME::SALOME_Exception );
260 * Evaluate mesh on a shape and
261 * returns statistic of mesh elements
262 * Result array of number enityties
264 SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
265 GEOM::GEOM_Object_ptr theShapeObject)
266 throw ( SALOME::SALOME_Exception );
268 // Returns true if mesh contains enough data to be computed
269 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
270 GEOM::GEOM_Object_ptr theShapeObject )
271 throw ( SALOME::SALOME_Exception );
274 * Calculate Mesh as preview till indicated dimension on shape
275 * First, verify list of hypothesis associated with the subShape.
276 * Return mesh preview structure
278 SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
279 GEOM::GEOM_Object_ptr theSubObject,
280 SMESH::Dimension theDimension,
281 SMESH::long_array& theShapesId )
282 throw ( SALOME::SALOME_Exception );
284 // Returns errors of hypotheses definintion
285 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
286 GEOM::GEOM_Object_ptr theSubObject )
287 throw ( SALOME::SALOME_Exception );
289 // Return mesh elements preventing computation of a subshape
290 SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
291 CORBA::Short theSubShapeID )
292 throw ( SALOME::SALOME_Exception );
294 // Get sub-shapes unique ID's list
295 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
296 const SMESH::object_array& theListOfSubShape )
297 throw ( SALOME::SALOME_Exception );
299 // Return geometrical object the given element is built on. Publish it in study.
300 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
301 CORBA::Long theElementID,
302 const char* theGeomName)
303 throw ( SALOME::SALOME_Exception );
305 // Return geometrical object the given element is built on. Don't publish it in study.
306 GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
307 CORBA::Long theElementID)
308 throw ( SALOME::SALOME_Exception );
310 // Concatenate the given meshes into one mesh
311 SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
312 CORBA::Boolean theUniteIdenticalGroups,
313 CORBA::Boolean theMergeNodesAndElements,
314 CORBA::Double theMergeTolerance,
315 CORBA::Boolean theCommonGroups)
316 throw ( SALOME::SALOME_Exception );
318 // Concatenate the given meshes into one mesh
319 SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray,
320 CORBA::Boolean theUniteIdenticalGroups,
321 CORBA::Boolean theMergeNodesAndElements,
322 CORBA::Double theMergeTolerance)
323 throw ( SALOME::SALOME_Exception );
325 // Concatenate the given meshes into one mesh
326 // Create the groups of all elements from initial meshes
327 SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
328 CORBA::Boolean theUniteIdenticalGroups,
329 CORBA::Boolean theMergeNodesAndElements,
330 CORBA::Double theMergeTolerance)
331 throw ( SALOME::SALOME_Exception );
333 // Get MED version of the file by its name
334 CORBA::Boolean GetMEDVersion(const char* theFileName,
335 SMESH::MED_VERSION& theVersion);
337 // Get names of meshes defined in file with the specified name
338 SMESH::string_array* GetMeshNames(const char* theFileName);
340 // ****************************************************
341 // Interface inherited methods (from SALOMEDS::Driver)
342 // ****************************************************
345 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
349 bool Load( SALOMEDS::SComponent_ptr theComponent,
350 const SALOMEDS::TMPFile& theStream,
353 // Save SMESH data in ASCII format
354 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
357 // Load SMESH data in ASCII format
358 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
359 const SALOMEDS::TMPFile& theStream,
363 // Create filter manager
364 SMESH::FilterManager_ptr CreateFilterManager();
366 // Return a pattern mesher
367 SMESH::SMESH_Pattern_ptr GetPattern();
369 // Create measurement instance
370 SMESH::Measurements_ptr CreateMeasurements();
372 // Clears study-connected data when it is closed
373 void Close( SALOMEDS::SComponent_ptr theComponent );
375 // Get component data type
376 char* ComponentDataType();
378 // Transform data from transient form to persistent
379 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
380 const char* IORString,
381 CORBA::Boolean isMultiFile,
382 CORBA::Boolean isASCII );
383 // Transform data from persistent form to transient
384 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
385 const char* aLocalPersistentID,
386 CORBA::Boolean isMultiFile,
387 CORBA::Boolean isASCII );
389 // Returns true if object can be published in the study
390 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
391 // Publish object in the study
392 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
393 SALOMEDS::SObject_ptr theSObject,
394 CORBA::Object_ptr theObject,
395 const char* theName )
396 throw ( SALOME::SALOME_Exception );
398 // Copy-paste methods - returns true if object can be copied to the clipboard
399 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
400 // Copy-paste methods - copy object to the clipboard
401 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
402 // Copy-paste methods - returns true if object can be pasted from the clipboard
403 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
404 // Copy-paste methods - paste object from the clipboard
405 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
406 CORBA::Long theObjectID,
407 SALOMEDS::SObject_ptr theObject ) {
408 SALOMEDS::SObject_var aResultSO;
409 return aResultSO._retn();
416 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
417 CORBA::Boolean isPublished,
418 CORBA::Boolean isMultiFile,
419 CORBA::Boolean& isValidScript);
421 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
423 void RemoveLastFromPythonScript (int theStudyID);
425 void SavePython (SALOMEDS::Study_ptr theStudy);
427 TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
428 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
429 Resource_DataMapOfAsciiStringAsciiString& theNames,
433 const TCollection_AsciiString& theSavedTrace);
435 TCollection_AsciiString GetNewPythonLines (int theStudyID);
437 void CleanPythonTrace (int theStudyID);
440 // *****************************************
442 // *****************************************
445 GEOM_Client* GetShapeReader();
448 static long GetHypothesisRootTag();
449 static long GetAlgorithmsRootTag();
450 static long GetRefOnShapeTag();
451 static long GetRefOnAppliedHypothesisTag();
452 static long GetRefOnAppliedAlgorithmsTag();
453 static long GetSubMeshOnVertexTag();
454 static long GetSubMeshOnEdgeTag();
455 static long GetSubMeshOnFaceTag();
456 static long GetSubMeshOnSolidTag();
457 static long GetSubMeshOnCompoundTag();
458 static long GetSubMeshOnWireTag();
459 static long GetSubMeshOnShellTag();
460 static long GetNodeGroupsTag();
461 static long GetEdgeGroupsTag();
462 static long GetFaceGroupsTag();
463 static long GetVolumeGroupsTag();
464 static long Get0DElementsGroupsTag();
466 // publishing methods
467 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
468 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
469 SMESH::SMESH_Mesh_ptr theMesh,
470 const char* theName = 0);
471 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
472 SMESH::SMESH_Hypothesis_ptr theHyp,
473 const char* theName = 0);
474 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
475 SMESH::SMESH_Mesh_ptr theMesh,
476 SMESH::SMESH_subMesh_ptr theSubMesh,
477 GEOM::GEOM_Object_ptr theShapeObject,
478 const char* theName = 0);
479 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
480 SMESH::SMESH_Mesh_ptr theMesh,
481 SMESH::SMESH_GroupBase_ptr theGroup,
482 GEOM::GEOM_Object_ptr theShapeObject,
483 const char* theName = 0);
484 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
485 SMESH::SMESH_Mesh_ptr theMesh,
486 GEOM::GEOM_Object_ptr theShapeObject,
487 SMESH::SMESH_Hypothesis_ptr theHyp);
488 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
489 SMESH::SMESH_Mesh_ptr theMesh,
490 GEOM::GEOM_Object_ptr theShapeObject,
491 SMESH::SMESH_Hypothesis_ptr theHyp);
492 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
493 SMESH::SMESH_Mesh_ptr theMesh,
494 GEOM::GEOM_Object_ptr theShape);
495 static void SetName(SALOMEDS::SObject_ptr theSObject,
497 const char* theDefaultName = 0);
499 static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
500 const char* thePixMap);
503 StudyContext* GetCurrentStudyContext();
505 // Register an object in a StudyContext; return object id
506 int RegisterObject(CORBA::Object_ptr theObject);
508 // Return id of registered object
509 CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
511 // Return an object that previously had an oldID
512 template<class TInterface>
513 typename TInterface::_var_type GetObjectByOldId( const int oldID )
515 if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
516 string ior = myStudyContext->getIORbyOldId( oldID );
518 return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
520 return TInterface::_nil();
523 // Get current study ID
524 int GetCurrentStudyID();
527 * \brief Find SObject for an algo
529 SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
531 void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
532 char* GetParameters(CORBA::Object_ptr theObject);
533 char* ParseParameters(const char* theParameters);
537 // Create hypothesis of given type
538 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
539 const char* theLibName)
540 throw ( SALOME::SALOME_Exception );
542 // Create empty mesh on shape
543 SMESH::SMESH_Mesh_ptr createMesh()
544 throw ( SALOME::SALOME_Exception );
546 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
549 static GEOM::GEOM_Gen_var myGeomGen;
550 static CORBA::ORB_var myOrb; // ORB reference
551 static PortableServer::POA_var myPoa; // POA reference
552 static SALOME_NamingService* myNS; // Naming Service
553 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
554 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
555 ::SMESH_Gen myGen; // SMESH_Gen local implementation
557 // hypotheses managing
558 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
560 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
562 GEOM_Client* myShapeReader; // Shape reader
563 SALOMEDS::Study_var myCurrentStudy; // Current study
564 CORBA::Boolean myIsEmbeddedMode; // Current mode
566 // Dump Python: trace of API methods calls
567 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
575 DownCast(CORBA::Object_ptr theArg)
577 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());