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
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_Gen_i.hxx
25 // Author : Paul RASCLE, EDF
28 #ifndef _SMESH_GEN_I_HXX_
29 #define _SMESH_GEN_I_HXX_
33 #include <SALOMEconfig.h>
34 #include CORBA_SERVER_HEADER(SMESH_Gen)
35 #include CORBA_SERVER_HEADER(SMESH_Mesh)
36 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
37 #include CORBA_CLIENT_HEADER(GEOM_Gen)
38 #include CORBA_CLIENT_HEADER(SALOMEDS)
39 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
41 #include "SMESH_Mesh_i.hxx"
42 #include "SMESH_Hypothesis_i.hxx"
43 #include "SALOME_Component_i.hxx"
44 #include "SALOME_NamingService.hxx"
46 #include "SMESH_Gen.hxx"
47 #include "GEOM_Client.hxx"
49 #include <TCollection_AsciiString.hxx>
50 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
51 #include <TColStd_HSequenceOfAsciiString.hxx>
57 class SALOME_LifeCycleCORBA;
59 // ===========================================================
60 // Study context - stores study-connected objects references
61 // ==========================================================
62 class SMESH_I_EXPORT StudyContext
73 // register object in the internal map and return its id
74 int addObject( string theIOR )
76 int nextId = getNextId();
77 mapIdToIOR[ nextId ] = theIOR;
80 // find the object id in the internal map by the IOR
81 int findId( string theIOR )
83 map<int, string>::iterator imap;
84 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
85 if ( imap->second == theIOR )
90 // get object's IOR by id
91 string getIORbyId( const int theId )
93 if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
94 return mapIdToIOR[ theId ];
97 // get object's IOR by old id
98 string getIORbyOldId( const int theOldId )
100 if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
101 return getIORbyId( mapIdToId[ theOldId ] );
104 // maps old object id to the new one (used when restoring data)
105 void mapOldToNew( const int oldId, const int newId ) {
106 mapIdToId[ oldId ] = newId;
108 // get old id by a new one
109 int getOldId( const int newId ) {
110 map<int, int>::iterator imap;
111 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
112 if ( imap->second == newId )
119 // get next free object identifier
123 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
128 map<int, string> mapIdToIOR; // persistent-to-transient map
129 map<int, int> mapIdToId; // used to translate object from persistent to transient form
132 // ===========================================================
133 // SMESH module's engine
134 // ==========================================================
135 class SMESH_I_EXPORT SMESH_Gen_i:
136 public virtual POA_SMESH::SMESH_Gen,
137 public virtual Engines_Component_i
140 // Get last created instance of the class
141 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
143 static CORBA::ORB_var GetORB() { return myOrb;}
144 // Get SMESH module's POA object
145 static PortableServer::POA_var GetPOA() { return myPoa;}
146 // Get Naming Service object
147 static SALOME_NamingService* GetNS();
148 // Get SALOME_LifeCycleCORBA object
149 static SALOME_LifeCycleCORBA* GetLCC();
150 // Retrieve and get GEOM engine reference
151 static GEOM::GEOM_Gen_ptr GetGeomEngine();
152 // Get object of the CORBA reference
153 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
154 // Get CORBA object corresponding to the SALOMEDS::SObject
155 static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
156 // Get the SALOMEDS::SObject corresponding to a CORBA object
157 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
158 CORBA::Object_ptr theObject);
159 // Get GEOM Object correspoding to TopoDS_Shape
160 GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
161 // Get TopoDS_Shape correspoding to GEOM_Object
162 TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
164 // Default constructor
166 // Standard constructor
167 SMESH_Gen_i( CORBA::ORB_ptr orb,
168 PortableServer::POA_ptr poa,
169 PortableServer::ObjectId* contId,
170 const char* instanceName,
171 const char* interfaceName );
173 virtual ~SMESH_Gen_i();
175 // *****************************************
177 // *****************************************
178 // Set a new Mesh object name
179 void SetName(const char* theIOR,
180 const char* theName);
182 //GEOM::GEOM_Gen_ptr SetGeomEngine( const char* containerLoc );
183 void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
186 void SetEmbeddedMode( CORBA::Boolean theMode );
188 CORBA::Boolean IsEmbeddedMode();
191 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
193 SALOMEDS::Study_ptr GetCurrentStudy();
195 // Create hypothesis/algorothm of given type
196 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
197 const char* theLibName)
198 throw ( SALOME::SALOME_Exception );
200 // Return hypothesis of given type holding parameter values of the existing mesh
201 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
202 const char* theLibName,
203 SMESH::SMESH_Mesh_ptr theMesh,
204 GEOM::GEOM_Object_ptr theGeom,
205 CORBA::Boolean byMesh)
206 throw ( SALOME::SALOME_Exception );
209 * Sets number of segments per diagonal of boundary box of geometry by which
210 * default segment length of appropriate 1D hypotheses is defined
212 void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
214 * \brief Sets default number of segments per edge
216 void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
218 // Create empty mesh on a shape
219 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
220 throw ( SALOME::SALOME_Exception );
223 SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
224 throw ( SALOME::SALOME_Exception );
226 // Create mesh(es) and import data from UNV file
227 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
228 throw ( SALOME::SALOME_Exception );
230 // Create mesh(es) and import data from MED file
231 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
232 SMESH::DriverMED_ReadStatus& theStatus )
233 throw ( SALOME::SALOME_Exception );
235 // Create mesh(es) and import data from STL file
236 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
237 throw ( SALOME::SALOME_Exception );
239 // Compute mesh on a shape
240 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
241 GEOM::GEOM_Object_ptr theShapeObject )
242 throw ( SALOME::SALOME_Exception );
244 * \brief Return errors of mesh computation
246 SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
247 GEOM::GEOM_Object_ptr theShapeObject )
248 throw ( SALOME::SALOME_Exception );
251 * Evaluate mesh on a shape and
252 * returns statistic of mesh elements
253 * Result array of number enityties
255 SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
256 GEOM::GEOM_Object_ptr theShapeObject)
257 throw ( SALOME::SALOME_Exception );
259 // Returns true if mesh contains enough data to be computed
260 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
261 GEOM::GEOM_Object_ptr theShapeObject )
262 throw ( SALOME::SALOME_Exception );
265 * Calculate Mesh as preview till indicated dimension on shape
266 * First, verify list of hypothesis associated with the subShape.
267 * Return mesh preview structure
269 SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
270 GEOM::GEOM_Object_ptr theSubObject,
271 SMESH::Dimension theDimension,
272 SMESH::long_array& theShapesId )
273 throw ( SALOME::SALOME_Exception );
275 // Returns errors of hypotheses definintion
276 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
277 GEOM::GEOM_Object_ptr theSubObject )
278 throw ( SALOME::SALOME_Exception );
280 // Return mesh elements preventing computation of a subshape
281 SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
282 CORBA::Short theSubShapeID )
283 throw ( SALOME::SALOME_Exception );
285 // Get sub-shapes unique ID's list
286 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
287 const SMESH::object_array& theListOfSubShape )
288 throw ( SALOME::SALOME_Exception );
290 // Return geometrical object the given element is built on. Publish it in study.
291 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
292 CORBA::Long theElementID,
293 const char* theGeomName)
294 throw ( SALOME::SALOME_Exception );
296 // Return geometrical object the given element is built on. Don't publish it in study.
297 GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
298 CORBA::Long theElementID)
299 throw ( SALOME::SALOME_Exception );
301 // Concatenate the given meshes into one mesh
302 SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
303 CORBA::Boolean theUniteIdenticalGroups,
304 CORBA::Boolean theMergeNodesAndElements,
305 CORBA::Double theMergeTolerance,
306 CORBA::Boolean theCommonGroups)
307 throw ( SALOME::SALOME_Exception );
309 // Concatenate the given meshes into one mesh
310 SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray,
311 CORBA::Boolean theUniteIdenticalGroups,
312 CORBA::Boolean theMergeNodesAndElements,
313 CORBA::Double theMergeTolerance)
314 throw ( SALOME::SALOME_Exception );
316 // Concatenate the given meshes into one mesh
317 // Create the groups of all elements from initial meshes
318 SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
319 CORBA::Boolean theUniteIdenticalGroups,
320 CORBA::Boolean theMergeNodesAndElements,
321 CORBA::Double theMergeTolerance)
322 throw ( SALOME::SALOME_Exception );
324 // Get MED version of the file by its name
325 CORBA::Boolean GetMEDVersion(const char* theFileName,
326 SMESH::MED_VERSION& theVersion);
328 // Get names of meshes defined in file with the specified name
329 SMESH::string_array* GetMeshNames(const char* theFileName);
331 // ****************************************************
332 // Interface inherited methods (from SALOMEDS::Driver)
333 // ****************************************************
336 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
340 bool Load( SALOMEDS::SComponent_ptr theComponent,
341 const SALOMEDS::TMPFile& theStream,
344 // Save SMESH data in ASCII format
345 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
348 // Load SMESH data in ASCII format
349 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
350 const SALOMEDS::TMPFile& theStream,
354 // Create filter manager
355 SMESH::FilterManager_ptr CreateFilterManager();
357 // Return a pattern mesher
358 SMESH::SMESH_Pattern_ptr GetPattern();
360 // Clears study-connected data when it is closed
361 void Close( SALOMEDS::SComponent_ptr theComponent );
363 // Get component data type
364 char* ComponentDataType();
366 // Transform data from transient form to persistent
367 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
368 const char* IORString,
369 CORBA::Boolean isMultiFile,
370 CORBA::Boolean isASCII );
371 // Transform data from persistent form to transient
372 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
373 const char* aLocalPersistentID,
374 CORBA::Boolean isMultiFile,
375 CORBA::Boolean isASCII );
377 // Returns true if object can be published in the study
378 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
379 // Publish object in the study
380 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
381 SALOMEDS::SObject_ptr theSObject,
382 CORBA::Object_ptr theObject,
383 const char* theName )
384 throw ( SALOME::SALOME_Exception );
386 // Copy-paste methods - returns true if object can be copied to the clipboard
387 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
388 // Copy-paste methods - copy object to the clipboard
389 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
390 // Copy-paste methods - returns true if object can be pasted from the clipboard
391 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
392 // Copy-paste methods - paste object from the clipboard
393 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
394 CORBA::Long theObjectID,
395 SALOMEDS::SObject_ptr theObject ) {
396 SALOMEDS::SObject_var aResultSO;
397 return aResultSO._retn();
404 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
405 CORBA::Boolean isPublished,
406 CORBA::Boolean& isValidScript);
408 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
410 void RemoveLastFromPythonScript (int theStudyID);
412 void SavePython (SALOMEDS::Study_ptr theStudy);
414 TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
415 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
416 Resource_DataMapOfAsciiStringAsciiString& theNames,
419 const TCollection_AsciiString& theSavedTrace);
421 TCollection_AsciiString GetNewPythonLines (int theStudyID);
423 void CleanPythonTrace (int theStudyID);
426 // *****************************************
428 // *****************************************
431 GEOM_Client* GetShapeReader();
434 static long GetHypothesisRootTag();
435 static long GetAlgorithmsRootTag();
436 static long GetRefOnShapeTag();
437 static long GetRefOnAppliedHypothesisTag();
438 static long GetRefOnAppliedAlgorithmsTag();
439 static long GetSubMeshOnVertexTag();
440 static long GetSubMeshOnEdgeTag();
441 static long GetSubMeshOnFaceTag();
442 static long GetSubMeshOnSolidTag();
443 static long GetSubMeshOnCompoundTag();
444 static long GetSubMeshOnWireTag();
445 static long GetSubMeshOnShellTag();
446 static long GetNodeGroupsTag();
447 static long GetEdgeGroupsTag();
448 static long GetFaceGroupsTag();
449 static long GetVolumeGroupsTag();
451 // publishing methods
452 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
453 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
454 SMESH::SMESH_Mesh_ptr theMesh,
455 const char* theName = 0);
456 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
457 SMESH::SMESH_Hypothesis_ptr theHyp,
458 const char* theName = 0);
459 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
460 SMESH::SMESH_Mesh_ptr theMesh,
461 SMESH::SMESH_subMesh_ptr theSubMesh,
462 GEOM::GEOM_Object_ptr theShapeObject,
463 const char* theName = 0);
464 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
465 SMESH::SMESH_Mesh_ptr theMesh,
466 SMESH::SMESH_GroupBase_ptr theGroup,
467 GEOM::GEOM_Object_ptr theShapeObject,
468 const char* theName = 0);
469 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
470 SMESH::SMESH_Mesh_ptr theMesh,
471 GEOM::GEOM_Object_ptr theShapeObject,
472 SMESH::SMESH_Hypothesis_ptr theHyp);
473 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
474 SMESH::SMESH_Mesh_ptr theMesh,
475 GEOM::GEOM_Object_ptr theShapeObject,
476 SMESH::SMESH_Hypothesis_ptr theHyp);
477 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
478 SMESH::SMESH_Mesh_ptr theMesh,
479 GEOM::GEOM_Object_ptr theShape);
480 static void SetName(SALOMEDS::SObject_ptr theSObject,
482 const char* theDefaultName = 0);
484 static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
485 const char* thePixMap);
488 StudyContext* GetCurrentStudyContext();
490 // Register an object in a StudyContext; return object id
491 int RegisterObject(CORBA::Object_ptr theObject);
493 // Return id of registered object
494 CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
496 // Return an object that previously had an oldID
497 template<class TInterface>
498 typename TInterface::_var_type GetObjectByOldId( const int oldID )
500 if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
501 string ior = myStudyContext->getIORbyOldId( oldID );
503 return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
505 return TInterface::_nil();
508 // Get current study ID
509 int GetCurrentStudyID();
512 * \brief Find SObject for an algo
514 SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
516 void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
517 char* GetParameters(CORBA::Object_ptr theObject);
518 char* ParseParameters(const char* theParameters);
522 // Create hypothesis of given type
523 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
524 const char* theLibName)
525 throw ( SALOME::SALOME_Exception );
527 // Create empty mesh on shape
528 SMESH::SMESH_Mesh_ptr createMesh()
529 throw ( SALOME::SALOME_Exception );
531 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
534 static GEOM::GEOM_Gen_var myGeomGen;
535 static CORBA::ORB_var myOrb; // ORB reference
536 static PortableServer::POA_var myPoa; // POA reference
537 static SALOME_NamingService* myNS; // Naming Service
538 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
539 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
540 ::SMESH_Gen myGen; // SMESH_Gen local implementation
542 // hypotheses managing
543 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
545 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
547 GEOM_Client* myShapeReader; // Shape reader
548 SALOMEDS::Study_var myCurrentStudy; // Current study
549 CORBA::Boolean myIsEmbeddedMode; // Current mode
551 // Dump Python: trace of API methods calls
552 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
560 DownCast(CORBA::Object_ptr theArg)
562 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());