00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _SMESH_GEN_I_HXX_
00027 #define _SMESH_GEN_I_HXX_
00028
00029 #include "SMESH.hxx"
00030
00031 #include <SALOMEconfig.h>
00032 #include CORBA_SERVER_HEADER(SMESH_Gen)
00033 #include CORBA_SERVER_HEADER(SMESH_Mesh)
00034 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
00035 #include CORBA_CLIENT_HEADER(GEOM_Gen)
00036 #include CORBA_CLIENT_HEADER(SALOMEDS)
00037 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
00038
00039 #include "SMESH_Mesh_i.hxx"
00040 #include "SMESH_Hypothesis_i.hxx"
00041 #include "SALOME_Component_i.hxx"
00042 #include "SALOME_NamingService.hxx"
00043
00044 #include "SMESH_Gen.hxx"
00045 #include "GEOM_Client.hxx"
00046
00047 #include <TCollection_AsciiString.hxx>
00048 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
00049 #include <TColStd_HSequenceOfAsciiString.hxx>
00050
00051 #include <map>
00052 #include <sstream>
00053
00054 class SMESH_Mesh_i;
00055 class SALOME_LifeCycleCORBA;
00056
00057
00058
00059
00060 class SMESH_I_EXPORT StudyContext
00061 {
00062 public:
00063
00064 StudyContext() {}
00065
00066 ~StudyContext()
00067 {
00068 mapIdToIOR.clear();
00069 mapIdToId.clear();
00070 }
00071
00072 int addObject( string theIOR )
00073 {
00074 int nextId = getNextId();
00075 mapIdToIOR[ nextId ] = theIOR;
00076 return nextId;
00077 }
00078
00079 int findId( string theIOR )
00080 {
00081 map<int, string>::iterator imap;
00082 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
00083 if ( imap->second == theIOR )
00084 return imap->first;
00085 }
00086 return 0;
00087 }
00088
00089 string getIORbyId( const int theId )
00090 {
00091 if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() )
00092 return mapIdToIOR[ theId ];
00093 return string( "" );
00094 }
00095
00096 string getIORbyOldId( const int theOldId )
00097 {
00098 if ( mapIdToId.find( theOldId ) != mapIdToId.end() )
00099 return getIORbyId( mapIdToId[ theOldId ] );
00100 return string( "" );
00101 }
00102
00103 void mapOldToNew( const int oldId, const int newId ) {
00104 mapIdToId[ oldId ] = newId;
00105 }
00106
00107 int getOldId( const int newId ) {
00108 map<int, int>::iterator imap;
00109 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
00110 if ( imap->second == newId )
00111 return imap->first;
00112 }
00113 return 0;
00114 }
00115
00116 private:
00117
00118 int getNextId()
00119 {
00120 int id = 1;
00121 while( mapIdToIOR.find( id ) != mapIdToIOR.end() )
00122 id++;
00123 return id;
00124 }
00125
00126 map<int, string> mapIdToIOR;
00127 map<int, int> mapIdToId;
00128 };
00129
00130
00131
00132
00133 class SMESH_I_EXPORT SMESH_Gen_i:
00134 public virtual POA_SMESH::SMESH_Gen,
00135 public virtual Engines_Component_i
00136 {
00137 public:
00138
00139 static SMESH_Gen_i* GetSMESHGen() { return mySMESHGen;}
00140
00141 static CORBA::ORB_var GetORB() { return myOrb;}
00142
00143 static PortableServer::POA_var GetPOA() { return myPoa;}
00144
00145 static SALOME_NamingService* GetNS();
00146
00147 static SALOME_LifeCycleCORBA* GetLCC();
00148
00149 static GEOM::GEOM_Gen_ptr GetGeomEngine();
00150
00151 static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject );
00152
00153 static CORBA::Object_var SObjectToObject( SALOMEDS::SObject_ptr theSObject );
00154
00155 static SALOMEDS::SObject_ptr ObjectToSObject(SALOMEDS::Study_ptr theStudy,
00156 CORBA::Object_ptr theObject);
00157
00158 GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape );
00159
00160 TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject);
00161
00162
00163 SMESH_Gen_i();
00164
00165 SMESH_Gen_i( CORBA::ORB_ptr orb,
00166 PortableServer::POA_ptr poa,
00167 PortableServer::ObjectId* contId,
00168 const char* instanceName,
00169 const char* interfaceName );
00170
00171 virtual ~SMESH_Gen_i();
00172
00173
00174
00175
00176
00177 void SetName(const char* theIOR,
00178 const char* theName);
00179
00180
00181 void SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo );
00182
00183
00184 void SetEmbeddedMode( CORBA::Boolean theMode );
00185
00186 CORBA::Boolean IsEmbeddedMode();
00187
00188
00189 void SetCurrentStudy( SALOMEDS::Study_ptr theStudy );
00190
00191 SALOMEDS::Study_ptr GetCurrentStudy();
00192
00193
00194 SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const char* theHypType,
00195 const char* theLibName)
00196 throw ( SALOME::SALOME_Exception );
00197
00198
00199 SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType,
00200 const char* theLibName,
00201 SMESH::SMESH_Mesh_ptr theMesh,
00202 GEOM::GEOM_Object_ptr theGeom,
00203 CORBA::Boolean byMesh)
00204 throw ( SALOME::SALOME_Exception );
00205
00210 void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
00214 void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
00215
00216
00217 SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
00218 throw ( SALOME::SALOME_Exception );
00219
00220
00221 SMESH::SMESH_Mesh_ptr CreateEmptyMesh()
00222 throw ( SALOME::SALOME_Exception );
00223
00224
00225 SMESH::SMESH_Mesh_ptr CreateMeshesFromUNV( const char* theFileName )
00226 throw ( SALOME::SALOME_Exception );
00227
00228
00229 SMESH::mesh_array* CreateMeshesFromMED( const char* theFileName,
00230 SMESH::DriverMED_ReadStatus& theStatus )
00231 throw ( SALOME::SALOME_Exception );
00232
00233
00234 SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName )
00235 throw ( SALOME::SALOME_Exception );
00236
00237
00238 SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
00239 const char* meshName,
00240 CORBA::Boolean toCopyGroups,
00241 CORBA::Boolean toKeepIDs);
00242
00243
00244 CORBA::Boolean Compute( SMESH::SMESH_Mesh_ptr theMesh,
00245 GEOM::GEOM_Object_ptr theShapeObject )
00246 throw ( SALOME::SALOME_Exception );
00247
00248
00249 void CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
00250 GEOM::GEOM_Object_ptr theShapeObject );
00251
00255 SMESH::compute_error_array* GetComputeErrors(SMESH::SMESH_Mesh_ptr theMesh,
00256 GEOM::GEOM_Object_ptr theShapeObject )
00257 throw ( SALOME::SALOME_Exception );
00258
00264 SMESH::long_array* Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
00265 GEOM::GEOM_Object_ptr theShapeObject)
00266 throw ( SALOME::SALOME_Exception );
00267
00268
00269 CORBA::Boolean IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
00270 GEOM::GEOM_Object_ptr theShapeObject )
00271 throw ( SALOME::SALOME_Exception );
00272
00278 SMESH::MeshPreviewStruct* Precompute( SMESH::SMESH_Mesh_ptr theMesh,
00279 GEOM::GEOM_Object_ptr theSubObject,
00280 SMESH::Dimension theDimension,
00281 SMESH::long_array& theShapesId )
00282 throw ( SALOME::SALOME_Exception );
00283
00284
00285 SMESH::algo_error_array* GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
00286 GEOM::GEOM_Object_ptr theSubObject )
00287 throw ( SALOME::SALOME_Exception );
00288
00289
00290 SMESH::MeshPreviewStruct* GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
00291 CORBA::Short theSubShapeID )
00292 throw ( SALOME::SALOME_Exception );
00293
00294
00295 SMESH::long_array* GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
00296 const SMESH::object_array& theListOfSubShape )
00297 throw ( SALOME::SALOME_Exception );
00298
00299
00300 GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
00301 CORBA::Long theElementID,
00302 const char* theGeomName)
00303 throw ( SALOME::SALOME_Exception );
00304
00305
00306 GEOM::GEOM_Object_ptr FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
00307 CORBA::Long theElementID)
00308 throw ( SALOME::SALOME_Exception );
00309
00310
00311 SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
00312 CORBA::Boolean theUniteIdenticalGroups,
00313 CORBA::Boolean theMergeNodesAndElements,
00314 CORBA::Double theMergeTolerance,
00315 CORBA::Boolean theCommonGroups)
00316 throw ( SALOME::SALOME_Exception );
00317
00318
00319 SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray,
00320 CORBA::Boolean theUniteIdenticalGroups,
00321 CORBA::Boolean theMergeNodesAndElements,
00322 CORBA::Double theMergeTolerance)
00323 throw ( SALOME::SALOME_Exception );
00324
00325
00326
00327 SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
00328 CORBA::Boolean theUniteIdenticalGroups,
00329 CORBA::Boolean theMergeNodesAndElements,
00330 CORBA::Double theMergeTolerance)
00331 throw ( SALOME::SALOME_Exception );
00332
00333
00334 CORBA::Boolean GetMEDVersion(const char* theFileName,
00335 SMESH::MED_VERSION& theVersion);
00336
00337
00338 SMESH::string_array* GetMeshNames(const char* theFileName);
00339
00340
00341
00342
00343
00344
00345 SALOMEDS::TMPFile* Save( SALOMEDS::SComponent_ptr theComponent,
00346 const char* theURL,
00347 bool isMultiFile );
00348
00349 bool Load( SALOMEDS::SComponent_ptr theComponent,
00350 const SALOMEDS::TMPFile& theStream,
00351 const char* theURL,
00352 bool isMultiFile );
00353
00354 SALOMEDS::TMPFile* SaveASCII( SALOMEDS::SComponent_ptr theComponent,
00355 const char* theURL,
00356 bool isMultiFile );
00357
00358 bool LoadASCII( SALOMEDS::SComponent_ptr theComponent,
00359 const SALOMEDS::TMPFile& theStream,
00360 const char* theURL,
00361 bool isMultiFile );
00362
00363
00364 SMESH::FilterManager_ptr CreateFilterManager();
00365
00366
00367 SMESH::SMESH_Pattern_ptr GetPattern();
00368
00369
00370 SMESH::Measurements_ptr CreateMeasurements();
00371
00372
00373 void Close( SALOMEDS::SComponent_ptr theComponent );
00374
00375
00376 char* ComponentDataType();
00377
00378
00379 char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
00380 const char* IORString,
00381 CORBA::Boolean isMultiFile,
00382 CORBA::Boolean isASCII );
00383
00384 char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
00385 const char* aLocalPersistentID,
00386 CORBA::Boolean isMultiFile,
00387 CORBA::Boolean isASCII );
00388
00389
00390 bool CanPublishInStudy( CORBA::Object_ptr theIOR );
00391
00392 SALOMEDS::SObject_ptr PublishInStudy( SALOMEDS::Study_ptr theStudy,
00393 SALOMEDS::SObject_ptr theSObject,
00394 CORBA::Object_ptr theObject,
00395 const char* theName )
00396 throw ( SALOME::SALOME_Exception );
00397
00398
00399 CORBA::Boolean CanCopy( SALOMEDS::SObject_ptr theObject ) { return false; }
00400
00401 SALOMEDS::TMPFile* CopyFrom( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID ) { return false; }
00402
00403 CORBA::Boolean CanPaste( const char* theComponentName, CORBA::Long theObjectID ) { return false; }
00404
00405 SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream,
00406 CORBA::Long theObjectID,
00407 SALOMEDS::SObject_ptr theObject ) {
00408 SALOMEDS::SObject_var aResultSO;
00409 return aResultSO._retn();
00410 }
00411
00412
00413
00414
00415
00416 virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
00417 CORBA::Boolean isPublished,
00418 CORBA::Boolean isMultiFile,
00419 CORBA::Boolean& isValidScript);
00420
00421 void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
00422
00423 void RemoveLastFromPythonScript (int theStudyID);
00424
00425 void SavePython (SALOMEDS::Study_ptr theStudy);
00426
00427 TCollection_AsciiString DumpPython_impl (SALOMEDS::Study_ptr theStudy,
00428 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
00429 Resource_DataMapOfAsciiStringAsciiString& theNames,
00430 bool isPublished,
00431 bool isMultiFile,
00432 bool& aValidScript,
00433 const TCollection_AsciiString& theSavedTrace);
00434
00435 TCollection_AsciiString GetNewPythonLines (int theStudyID);
00436
00437 void CleanPythonTrace (int theStudyID);
00438
00439
00440
00441
00442
00443 public:
00444
00445 GEOM_Client* GetShapeReader();
00446
00447
00448 static long GetHypothesisRootTag();
00449 static long GetAlgorithmsRootTag();
00450 static long GetRefOnShapeTag();
00451 static long GetRefOnAppliedHypothesisTag();
00452 static long GetRefOnAppliedAlgorithmsTag();
00453 static long GetSubMeshOnVertexTag();
00454 static long GetSubMeshOnEdgeTag();
00455 static long GetSubMeshOnFaceTag();
00456 static long GetSubMeshOnSolidTag();
00457 static long GetSubMeshOnCompoundTag();
00458 static long GetSubMeshOnWireTag();
00459 static long GetSubMeshOnShellTag();
00460 static long GetNodeGroupsTag();
00461 static long GetEdgeGroupsTag();
00462 static long GetFaceGroupsTag();
00463 static long GetVolumeGroupsTag();
00464 static long Get0DElementsGroupsTag();
00465
00466
00467 SALOMEDS::SComponent_ptr PublishComponent(SALOMEDS::Study_ptr theStudy);
00468 SALOMEDS::SObject_ptr PublishMesh (SALOMEDS::Study_ptr theStudy,
00469 SMESH::SMESH_Mesh_ptr theMesh,
00470 const char* theName = 0);
00471 SALOMEDS::SObject_ptr PublishHypothesis (SALOMEDS::Study_ptr theStudy,
00472 SMESH::SMESH_Hypothesis_ptr theHyp,
00473 const char* theName = 0);
00474 SALOMEDS::SObject_ptr PublishSubMesh (SALOMEDS::Study_ptr theStudy,
00475 SMESH::SMESH_Mesh_ptr theMesh,
00476 SMESH::SMESH_subMesh_ptr theSubMesh,
00477 GEOM::GEOM_Object_ptr theShapeObject,
00478 const char* theName = 0);
00479 SALOMEDS::SObject_ptr PublishGroup (SALOMEDS::Study_ptr theStudy,
00480 SMESH::SMESH_Mesh_ptr theMesh,
00481 SMESH::SMESH_GroupBase_ptr theGroup,
00482 GEOM::GEOM_Object_ptr theShapeObject,
00483 const char* theName = 0);
00484 bool AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
00485 SMESH::SMESH_Mesh_ptr theMesh,
00486 GEOM::GEOM_Object_ptr theShapeObject,
00487 SMESH::SMESH_Hypothesis_ptr theHyp);
00488 bool RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
00489 SMESH::SMESH_Mesh_ptr theMesh,
00490 GEOM::GEOM_Object_ptr theShapeObject,
00491 SMESH::SMESH_Hypothesis_ptr theHyp);
00492 SALOMEDS::SObject_ptr GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
00493 SMESH::SMESH_Mesh_ptr theMesh,
00494 GEOM::GEOM_Object_ptr theShape);
00495 static void SetName(SALOMEDS::SObject_ptr theSObject,
00496 const char* theName,
00497 const char* theDefaultName = 0);
00498
00499 static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
00500 const char* thePixMap);
00501
00502
00503 StudyContext* GetCurrentStudyContext();
00504
00505
00506 int RegisterObject(CORBA::Object_ptr theObject);
00507
00508
00509 CORBA::Long GetObjectId(CORBA::Object_ptr theObject);
00510
00511
00512 template<class TInterface>
00513 typename TInterface::_var_type GetObjectByOldId( const int oldID )
00514 {
00515 if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) {
00516 string ior = myStudyContext->getIORbyOldId( oldID );
00517 if ( !ior.empty() )
00518 return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() ));
00519 }
00520 return TInterface::_nil();
00521 }
00522
00523
00524 int GetCurrentStudyID();
00525
00529 SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
00530
00531 void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
00532 char* GetParameters(CORBA::Object_ptr theObject);
00533 char* ParseParameters(const char* theParameters);
00534
00535
00536 private:
00537
00538 SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
00539 const char* theLibName)
00540 throw ( SALOME::SALOME_Exception );
00541
00542
00543 SMESH::SMESH_Mesh_ptr createMesh()
00544 throw ( SALOME::SALOME_Exception );
00545
00546 static void loadGeomData( SALOMEDS::SComponent_ptr theCompRoot );
00547
00548 private:
00549 static GEOM::GEOM_Gen_var myGeomGen;
00550 static CORBA::ORB_var myOrb;
00551 static PortableServer::POA_var myPoa;
00552 static SALOME_NamingService* myNS;
00553 static SALOME_LifeCycleCORBA* myLCC;
00554 static SMESH_Gen_i* mySMESHGen;
00555 ::SMESH_Gen myGen;
00556
00557
00558 map<string, GenericHypothesisCreator_i*> myHypCreatorMap;
00559
00560 map<int, StudyContext*> myStudyContextMap;
00561
00562 GEOM_Client* myShapeReader;
00563 SALOMEDS::Study_var myCurrentStudy;
00564 CORBA::Boolean myIsEmbeddedMode;
00565
00566
00567 std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
00568 };
00569
00570
00571 namespace SMESH
00572 {
00573 template<class T>
00574 T
00575 DownCast(CORBA::Object_ptr theArg)
00576 {
00577 return dynamic_cast<T>(SMESH_Gen_i::GetServant(theArg).in());
00578 }
00579 }
00580
00581
00582 #endif