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_
34 #include <SALOMEconfig.h>
35 #include CORBA_SERVER_HEADER(SMESH_Gen)
36 #include CORBA_SERVER_HEADER(SMESH_Mesh)
37 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
38 #include CORBA_CLIENT_HEADER(GEOM_Gen)
39 #include CORBA_CLIENT_HEADER(SALOMEDS)
40 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
42 #include "SMESH_Mesh_i.hxx"
43 #include "SMESH_Hypothesis_i.hxx"
44 #include "SALOME_Component_i.hxx"
45 #include "SALOME_NamingService.hxx"
47 #include "SMESH_Gen.hxx"
48 #include "GEOM_Client.hxx"
50 #include <TCollection_AsciiString.hxx>
51 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
52 #include <TColStd_HSequenceOfAsciiString.hxx>
58 class SALOME_LifeCycleCORBA;
60 // ===========================================================
61 // Study context - stores study-connected objects references
62 // ==========================================================
63 class SMESH_I_EXPORT StudyContext
74 // register object in the internal map and return its id
75 int addObject( string theIOR )
77 int nextId = getNextId();
78 mapIdToIOR[ nextId ] = theIOR;
81 // find the object id in the internal map by the IOR
82 int findId( string theIOR )
84 map<int, string>::iterator imap;
85 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
86 if ( imap->second == theIOR )
91 // get object's IOR by id
92 string getIORbyId( const int theId )
94 if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
95 return mapIdToIOR[ theId ];
98 // get object's IOR by old id
99 string getIORbyOldId( const int theOldId )
101 if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
102 return getIORbyId( mapIdToId[ theOldId ] );
105 // maps old object id to the new one (used when restoring data)
106 void mapOldToNew( const int oldId, const int newId ) {
107 mapIdToId[ oldId ] = newId;
111 // get next free object identifier
115 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
120 map<int, string> mapIdToIOR; // persistent-to-transient map
121 map<int, int> mapIdToId; // used to translate object from persistent to transient form
124 // ===========================================================
125 // SMESH module's engine
126 // ==========================================================
127 class SMESH_I_EXPORT SMESH_Gen_i:
128 public virtual POA_SMESH::SMESH_Gen,
129 public virtual Engines_Component_i
132 // Get last created instance of the class
133 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
135 static CORBA::ORB_var GetORB() { return myOrb;}
136 // Get SMESH module's POA object
137 static PortableServer::POA_var GetPOA() { return myPoa;}
138 // Get Naming Service object
139 static SALOME_NamingService* GetNS();
140 // Get SALOME_LifeCycleCORBA object
141 static SALOME_LifeCycleCORBA* GetLCC();
142 // Retrieve and get GEOM engine reference
143 static GEOM::GEOM_Gen_ptr GetGeomEngine();
144 // Get object of the CORBA reference
145 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
146 // Get CORBA object corresponding to the SALOMEDS::SObject
147 static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
148 // Get the SALOMEDS::SObject corresponding to a CORBA object
149 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
150 CORBA::Object_ptr theObject);
151 // Get GEOM Object correspoding to TopoDS_Shape
152 GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
153 // Get TopoDS_Shape correspoding to GEOM_Object
154 TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
156 // Default constructor
158 // Standard constructor
159 SMESH_Gen_i( CORBA::ORB_ptr orb,
160 PortableServer::POA_ptr poa,
161 PortableServer::ObjectId* contId,
162 const char* instanceName,
163 const char* interfaceName );
165 virtual ~SMESH_Gen_i();
167 // *****************************************
169 // *****************************************
172 void SetEmbeddedMode( CORBA::Boolean theMode );
174 CORBA::Boolean IsEmbeddedMode();
177 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
179 SALOMEDS::Study_ptr GetCurrentStudy();
181 // Create hypothesis/algorothm of given type
182 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
183 const char* theLibName)
184 throw ( SALOME::SALOME_Exception );
186 // Return hypothesis of given type holding parameter values of the existing mesh
187 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
188 const char* theLibName,
189 SMESH::SMESH_Mesh_ptr theMesh,
190 GEOM::GEOM_Object_ptr theGeom)
191 throw ( SALOME::SALOME_Exception );
193 // Create empty mesh on a shape
194 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
195 throw ( SALOME::SALOME_Exception );
198 SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
199 throw ( SALOME::SALOME_Exception );
201 // Create mesh(es) and import data from UNV file
202 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
203 throw ( SALOME::SALOME_Exception );
205 // Create mesh(es) and import data from MED file
206 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
207 SMESH::DriverMED_ReadStatus& theStatus )
208 throw ( SALOME::SALOME_Exception );
210 // Create mesh(es) and import data from STL file
211 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
212 throw ( SALOME::SALOME_Exception );
214 // Compute mesh on a shape
215 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
216 GEOM::GEOM_Object_ptr theShapeObject )
217 throw ( SALOME::SALOME_Exception );
219 // Returns true if mesh contains enough data to be computed
220 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
221 GEOM::GEOM_Object_ptr theShapeObject )
222 throw ( SALOME::SALOME_Exception );
224 // Returns errors of hypotheses definintion
225 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
226 GEOM::GEOM_Object_ptr theSubObject )
227 throw ( SALOME::SALOME_Exception );
229 // Get sub-shapes unique ID's list
230 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
231 const SMESH::object_array& theListOfSubShape )
232 throw ( SALOME::SALOME_Exception );
234 // Return geometrical object the given element is built on
235 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
236 CORBA::Long theElementID,
237 const char* theGeomName)
238 throw ( SALOME::SALOME_Exception );
240 // ****************************************************
241 // Interface inherited methods (from SALOMEDS::Driver)
242 // ****************************************************
245 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
249 bool Load( SALOMEDS::SComponent_ptr theComponent,
250 const SALOMEDS::TMPFile& theStream,
253 // Save SMESH data in ASCII format
254 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
257 // Load SMESH data in ASCII format
258 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
259 const SALOMEDS::TMPFile& theStream,
263 // Create filter manager
264 SMESH::FilterManager_ptr CreateFilterManager();
266 // Return a pattern mesher
267 SMESH::SMESH_Pattern_ptr GetPattern();
269 // Clears study-connected data when it is closed
270 void Close( SALOMEDS::SComponent_ptr theComponent );
272 // Get component data type
273 char* ComponentDataType();
275 // Transform data from transient form to persistent
276 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
277 const char* IORString,
278 CORBA::Boolean isMultiFile,
279 CORBA::Boolean isASCII );
280 // Transform data from persistent form to transient
281 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
282 const char* aLocalPersistentID,
283 CORBA::Boolean isMultiFile,
284 CORBA::Boolean isASCII );
286 // Returns true if object can be published in the study
287 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
288 // Publish object in the study
289 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
290 SALOMEDS::SObject_ptr theSObject,
291 CORBA::Object_ptr theObject,
292 const char* theName )
293 throw ( SALOME::SALOME_Exception );
295 // Copy-paste methods - returns true if object can be copied to the clipboard
296 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
297 // Copy-paste methods - copy object to the clipboard
298 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
299 // Copy-paste methods - returns true if object can be pasted from the clipboard
300 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
301 // Copy-paste methods - paste object from the clipboard
302 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
303 CORBA::Long theObjectID,
304 SALOMEDS::SObject_ptr theObject ) {
305 SALOMEDS::SObject_var aResultSO;
306 return aResultSO._retn();
313 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
314 CORBA::Boolean isPublished,
315 CORBA::Boolean& isValidScript);
317 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
319 void RemoveLastFromPythonScript (int theStudyID);
321 void SavePython (SALOMEDS::Study_ptr theStudy);
323 TCollection_AsciiString DumpPython_impl (int theStudyID,
324 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
325 Resource_DataMapOfAsciiStringAsciiString& theNames,
328 const TCollection_AsciiString& theSavedTrace);
330 TCollection_AsciiString GetNewPythonLines (int theStudyID);
332 void CleanPythonTrace (int theStudyID);
335 // *****************************************
337 // *****************************************
340 GEOM_Client* GetShapeReader();
343 static long GetHypothesisRootTag();
344 static long GetAlgorithmsRootTag();
345 static long GetRefOnShapeTag();
346 static long GetRefOnAppliedHypothesisTag();
347 static long GetRefOnAppliedAlgorithmsTag();
348 static long GetSubMeshOnVertexTag();
349 static long GetSubMeshOnEdgeTag();
350 static long GetSubMeshOnFaceTag();
351 static long GetSubMeshOnSolidTag();
352 static long GetSubMeshOnCompoundTag();
353 static long GetSubMeshOnWireTag();
354 static long GetSubMeshOnShellTag();
355 static long GetNodeGroupsTag();
356 static long GetEdgeGroupsTag();
357 static long GetFaceGroupsTag();
358 static long GetVolumeGroupsTag();
360 // publishing methods
361 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
362 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
363 SMESH::SMESH_Mesh_ptr theMesh,
364 const char* theName = 0);
365 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
366 SMESH::SMESH_Hypothesis_ptr theHyp,
367 const char* theName = 0);
368 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
369 SMESH::SMESH_Mesh_ptr theMesh,
370 SMESH::SMESH_subMesh_ptr theSubMesh,
371 GEOM::GEOM_Object_ptr theShapeObject,
372 const char* theName = 0);
373 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
374 SMESH::SMESH_Mesh_ptr theMesh,
375 SMESH::SMESH_GroupBase_ptr theGroup,
376 GEOM::GEOM_Object_ptr theShapeObject,
377 const char* theName = 0);
378 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
379 SMESH::SMESH_Mesh_ptr theMesh,
380 GEOM::GEOM_Object_ptr theShapeObject,
381 SMESH::SMESH_Hypothesis_ptr theHyp);
382 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
383 SMESH::SMESH_Mesh_ptr theMesh,
384 GEOM::GEOM_Object_ptr theShapeObject,
385 SMESH::SMESH_Hypothesis_ptr theHyp);
386 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
387 SMESH::SMESH_Mesh_ptr theMesh,
388 GEOM::GEOM_Object_ptr theShape);
389 static void SetName(SALOMEDS::SObject_ptr theSObject,
391 const char* theDefaultName = 0);
394 StudyContext* GetCurrentStudyContext();
396 // Register an object in a StudyContext; return object id
397 int RegisterObject(CORBA::Object_ptr theObject);
399 // Get current study ID
400 int GetCurrentStudyID()
401 { return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId(); }
404 // Create hypothesis of given type
405 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
406 const char* theLibName)
407 throw ( SALOME::SALOME_Exception );
409 // Create empty mesh on shape
410 SMESH::SMESH_Mesh_ptr createMesh()
411 throw ( SALOME::SALOME_Exception );
413 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
417 static CORBA::ORB_var myOrb; // ORB reference
418 static PortableServer::POA_var myPoa; // POA reference
419 static SALOME_NamingService* myNS; // Naming Service
420 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
421 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
422 ::SMESH_Gen myGen; // SMESH_Gen local implementation
424 // hypotheses managing
425 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
427 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
429 GEOM_Client* myShapeReader; // Shape reader
430 SALOMEDS::Study_var myCurrentStudy; // Current study
431 CORBA::Boolean myIsEmbeddedMode; // Current mode
433 // Dump Python: trace of API methods calls
434 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
442 DownCast(CORBA::Object_ptr theArg)
444 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());