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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
174 SALOMEDS::Study_ptr GetCurrentStudy();
176 // Create hypothesis/algorothm of given type
177 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
178 const char* theLibName)
179 throw ( SALOME::SALOME_Exception );
181 // Return hypothesis of given type holding parameter values of the existing mesh
182 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
183 const char* theLibName,
184 SMESH::SMESH_Mesh_ptr theMesh,
185 GEOM::GEOM_Object_ptr theGeom)
186 throw ( SALOME::SALOME_Exception );
188 // Create empty mesh on a shape
189 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
190 throw ( SALOME::SALOME_Exception );
192 // Create mesh(es) and import data from UNV file
193 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
194 throw ( SALOME::SALOME_Exception );
196 // Create mesh(es) and import data from MED file
197 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
198 SMESH::DriverMED_ReadStatus& theStatus )
199 throw ( SALOME::SALOME_Exception );
201 // Create mesh(es) and import data from STL file
202 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
203 throw ( SALOME::SALOME_Exception );
205 // Compute mesh on a shape
206 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
207 GEOM::GEOM_Object_ptr theShapeObject )
208 throw ( SALOME::SALOME_Exception );
210 // Returns true if mesh contains enough data to be computed
211 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
212 GEOM::GEOM_Object_ptr theShapeObject )
213 throw ( SALOME::SALOME_Exception );
215 // Returns errors of hypotheses definintion
216 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
217 GEOM::GEOM_Object_ptr theSubObject )
218 throw ( SALOME::SALOME_Exception );
220 // Get sub-shapes unique ID's list
221 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
222 const SMESH::object_array& theListOfSubShape )
223 throw ( SALOME::SALOME_Exception );
225 // Return geometrical object the given element is built on
226 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
227 CORBA::Long theElementID,
228 const char* theGeomName)
229 throw ( SALOME::SALOME_Exception );
231 // ****************************************************
232 // Interface inherited methods (from SALOMEDS::Driver)
233 // ****************************************************
236 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
240 bool Load( SALOMEDS::SComponent_ptr theComponent,
241 const SALOMEDS::TMPFile& theStream,
244 // Save SMESH data in ASCII format
245 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
248 // Load SMESH data in ASCII format
249 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
250 const SALOMEDS::TMPFile& theStream,
254 // Create filter manager
255 SMESH::FilterManager_ptr CreateFilterManager();
257 // Return a pattern mesher
258 SMESH::SMESH_Pattern_ptr GetPattern();
260 // Clears study-connected data when it is closed
261 void Close( SALOMEDS::SComponent_ptr theComponent );
263 // Get component data type
264 char* ComponentDataType();
266 // Transform data from transient form to persistent
267 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
268 const char* IORString,
269 CORBA::Boolean isMultiFile,
270 CORBA::Boolean isASCII );
271 // Transform data from persistent form to transient
272 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
273 const char* aLocalPersistentID,
274 CORBA::Boolean isMultiFile,
275 CORBA::Boolean isASCII );
277 // Returns true if object can be published in the study
278 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
279 // Publish object in the study
280 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
281 SALOMEDS::SObject_ptr theSObject,
282 CORBA::Object_ptr theObject,
283 const char* theName )
284 throw ( SALOME::SALOME_Exception );
286 // Copy-paste methods - returns true if object can be copied to the clipboard
287 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
288 // Copy-paste methods - copy object to the clipboard
289 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
290 // Copy-paste methods - returns true if object can be pasted from the clipboard
291 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
292 // Copy-paste methods - paste object from the clipboard
293 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
294 CORBA::Long theObjectID,
295 SALOMEDS::SObject_ptr theObject ) {
296 SALOMEDS::SObject_var aResultSO;
297 return aResultSO._retn();
304 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
305 CORBA::Boolean isPublished,
306 CORBA::Boolean& isValidScript);
308 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
310 void RemoveLastFromPythonScript (int theStudyID);
312 void SavePython (SALOMEDS::Study_ptr theStudy);
314 TCollection_AsciiString DumpPython_impl (int theStudyID,
315 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
316 Resource_DataMapOfAsciiStringAsciiString& theNames,
319 const TCollection_AsciiString& theSavedTrace);
321 TCollection_AsciiString GetNewPythonLines (int theStudyID);
323 void CleanPythonTrace (int theStudyID);
326 // *****************************************
328 // *****************************************
331 GEOM_Client* GetShapeReader();
334 static long GetHypothesisRootTag();
335 static long GetAlgorithmsRootTag();
336 static long GetRefOnShapeTag();
337 static long GetRefOnAppliedHypothesisTag();
338 static long GetRefOnAppliedAlgorithmsTag();
339 static long GetSubMeshOnVertexTag();
340 static long GetSubMeshOnEdgeTag();
341 static long GetSubMeshOnFaceTag();
342 static long GetSubMeshOnSolidTag();
343 static long GetSubMeshOnCompoundTag();
344 static long GetSubMeshOnWireTag();
345 static long GetSubMeshOnShellTag();
346 static long GetNodeGroupsTag();
347 static long GetEdgeGroupsTag();
348 static long GetFaceGroupsTag();
349 static long GetVolumeGroupsTag();
351 // publishing methods
352 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
353 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
354 SMESH::SMESH_Mesh_ptr theMesh,
355 const char* theName = 0);
356 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
357 SMESH::SMESH_Hypothesis_ptr theHyp,
358 const char* theName = 0);
359 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
360 SMESH::SMESH_Mesh_ptr theMesh,
361 SMESH::SMESH_subMesh_ptr theSubMesh,
362 GEOM::GEOM_Object_ptr theShapeObject,
363 const char* theName = 0);
364 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
365 SMESH::SMESH_Mesh_ptr theMesh,
366 SMESH::SMESH_GroupBase_ptr theGroup,
367 GEOM::GEOM_Object_ptr theShapeObject,
368 const char* theName = 0);
369 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
370 SMESH::SMESH_Mesh_ptr theMesh,
371 GEOM::GEOM_Object_ptr theShapeObject,
372 SMESH::SMESH_Hypothesis_ptr theHyp);
373 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
374 SMESH::SMESH_Mesh_ptr theMesh,
375 GEOM::GEOM_Object_ptr theShapeObject,
376 SMESH::SMESH_Hypothesis_ptr theHyp);
377 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
378 SMESH::SMESH_Mesh_ptr theMesh,
379 GEOM::GEOM_Object_ptr theShape);
380 static void SetName(SALOMEDS::SObject_ptr theSObject,
382 const char* theDefaultName = 0);
385 StudyContext* GetCurrentStudyContext();
387 // Register an object in a StudyContext; return object id
388 int RegisterObject(CORBA::Object_ptr theObject);
390 // Get current study ID
391 int GetCurrentStudyID()
392 { return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId(); }
395 // Create hypothesis of given type
396 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
397 const char* theLibName)
398 throw ( SALOME::SALOME_Exception );
400 // Create empty mesh on shape
401 SMESH::SMESH_Mesh_ptr createMesh()
402 throw ( SALOME::SALOME_Exception );
404 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
408 static CORBA::ORB_var myOrb; // ORB reference
409 static PortableServer::POA_var myPoa; // POA reference
410 static SALOME_NamingService* myNS; // Naming Service
411 static SALOME_LifeCycleCORBA* myLCC; // Life Cycle CORBA
412 static SMESH_Gen_i* mySMESHGen; // Point to last created instance of the class
413 ::SMESH_Gen myGen; // SMESH_Gen local implementation
415 // hypotheses managing
416 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
418 map<int, StudyContext*> myStudyContextMap; // Map of study context objects
420 GEOM_Client* myShapeReader; // Shape reader
421 SALOMEDS::Study_var myCurrentStudy; // Current study
423 // Dump Python: trace of API methods calls
424 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
432 DownCast(CORBA::Object_ptr theArg)
434 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());