X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Gen_i.cxx;h=f6abcbdceb5767cac2dcc9937152b2f81a7deaf3;hb=b131becc0872f2050b117ce5bfc0fda84e34faa6;hp=e89466cfbdc42868373a38f9e039a2d55e9b2525;hpb=9851a42aa94c3c0b3c0ef9a9f9c7a4e039298040;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index e89466cfb..f6abcbdce 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -49,6 +49,10 @@ #include #include +// Have to be included before std headers +#include +#include + #ifdef WIN32 #include #include @@ -102,6 +106,7 @@ #include "SMESH_PreMeshInfo.hxx" #include "SMESH_PythonDump.hxx" #include "SMESH_ControlsDef.hxx" +#include // to pass CORBA exception through SMESH_TRY #define SMY_OWN_CATCH catch( SALOME::SALOME_Exception& se ) { throw se; } @@ -144,9 +149,11 @@ #include #include -#include #include #include +#include + +namespace fs = boost::filesystem; using namespace std; using SMESH::TPythonDump; @@ -189,22 +196,22 @@ PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theOb } catch (PortableServer::POA::ObjectNotActive &ex) { - INFOS("GetServant: ObjectNotActive"); + MESSAGE("GetServant: ObjectNotActive"); return NULL; } catch (PortableServer::POA::WrongAdapter &ex) { - INFOS("GetServant: WrongAdapter: OK when several servants used to build several mesh in parallel..."); + MESSAGE("GetServant: WrongAdapter: OK when several servants used to build several mesh in parallel..."); return NULL; } catch (PortableServer::POA::WrongPolicy &ex) { - INFOS("GetServant: WrongPolicy"); + MESSAGE("GetServant: WrongPolicy"); return NULL; } catch (...) { - INFOS( "GetServant - Unknown exception was caught!!!" ); + MESSAGE( "GetServant - Unknown exception was caught!!!" ); return NULL; } } @@ -237,6 +244,14 @@ CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject return anObj; } +// Set Naming Service object +void SMESH_Gen_i::SetNS(SALOME_NamingService_Abstract *ns) +{ + if(myNS) + delete myNS; + myNS = ns; +} + //============================================================================= /*! * GetNS [ static ] @@ -247,7 +262,7 @@ CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject SALOME_NamingService_Abstract* SMESH_Gen_i::GetNS() { - if ( myNS == NULL ) { + if ( !myNS ) { myNS = SINGLETON_::Instance(); ASSERT(SINGLETON_::IsAlreadyExisting()); myNS->init_orb( GetORB() ); @@ -452,18 +467,17 @@ GenericHypothesisCreator_i* SMESH_Gen_i::getHypothesisCreator(const char* theHyp // load plugin library if(MYDEBUG) MESSAGE("Loading server meshers plugin library ..."); #ifdef WIN32 -#ifdef UNICODE +# ifdef UNICODE const wchar_t* path = Kernel_Utils::decode_s(aPlatformLibName); -#else + SMESHUtils::ArrayDeleter deleter( path ); +# else const char* path = aPlatformLibName.c_str(); -#endif +# endif #else const char* path = aPlatformLibName.c_str(); #endif LibHandle libHandle = LoadLib( path ); -#if defined(WIN32) && defined(UNICODE) - delete path; -#endif + if (!libHandle) { // report any error, if occurred @@ -1309,17 +1323,17 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName */ //============================================================================= -SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileName, - SMESH::DriverMED_ReadStatus& theStatus, - const char* theCommandNameForPython, - const char* theFileNameForPython) +SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName, + SMESH::DriverMED_ReadStatus& theStatus ) { + checkFileReadable( theFileName ); + #ifdef WIN32 char bname[ _MAX_FNAME ]; - _splitpath( theFileNameForPython, NULL, NULL, bname, NULL ); + _splitpath( theFileName, NULL, NULL, bname, NULL ); string aFileName = bname; #else - string aFileName = basename( const_cast(theFileNameForPython) ); + string aFileName = basename( const_cast( theFileName )); #endif // Retrieve mesh names from the file DriverMED_R_SMESHDS_Mesh myReader; @@ -1332,59 +1346,57 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileNa { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups() - // Python Dump - TPythonDump aPythonDump(this); - aPythonDump << "(["; + // Python Dump + TPythonDump aPythonDump(this); + aPythonDump << "(["; - if (theStatus == SMESH::DRS_OK) { - SALOMEDS::StudyBuilder_var aStudyBuilder; - aStudyBuilder = getStudyServant()->NewBuilder(); - aStudyBuilder->NewCommand(); // There is a transaction + if (theStatus == SMESH::DRS_OK) + { + SALOMEDS::StudyBuilder_var aStudyBuilder; + aStudyBuilder = getStudyServant()->NewBuilder(); + aStudyBuilder->NewCommand(); // There is a transaction - aResult->length( aNames.size() ); - int i = 0; + aResult->length( aNames.size() ); + int i = 0; - // Iterate through all meshes and create mesh objects - for ( list::iterator it = aNames.begin(); it != aNames.end(); it++ ) - { - // Python Dump - if (i > 0) aPythonDump << ", "; - - // create mesh - SMESH::SMESH_Mesh_var mesh = createMesh(); - - // publish mesh in the study - SALOMEDS::SObject_wrap aSO; - if ( CanPublishInStudy( mesh ) ) - // little trick: for MED file theFileName and theFileNameForPython are the same, but they are different for SAUV - // - as names of meshes are stored in MED file, we use them for data publishing - // - as mesh name is not stored in UNV file, we use file name as name of mesh when publishing data - aSO = PublishMesh( mesh.in(), ( theFileName == theFileNameForPython ) ? (*it).c_str() : aFileName.c_str() ); - - // Python Dump - if ( !aSO->_is_nil() ) { - aPythonDump << aSO; - } else { - aPythonDump << "mesh_" << i; - } + // Iterate through all meshes and create mesh objects + for ( const std::string & meshName : aNames ) + { + // Python Dump + if (i > 0) aPythonDump << ", "; + + // create mesh + SMESH::SMESH_Mesh_var mesh = createMesh(); - // Read mesh data (groups are published automatically by ImportMEDFile()) - SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( mesh ).in() ); - ASSERT( meshServant ); - SMESH::DriverMED_ReadStatus status1 = - meshServant->ImportMEDFile( theFileName, (*it).c_str() ); - if (status1 > theStatus) - theStatus = status1; + // publish mesh in the study + SALOMEDS::SObject_wrap aSO; + if ( CanPublishInStudy( mesh ) ) + aSO = PublishMesh( mesh.in(), meshName.c_str() ); - aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh ); - meshServant->GetImpl().GetMeshDS()->Modified(); + // Python Dump + if ( !aSO->_is_nil() ) { + aPythonDump << aSO; + } else { + aPythonDump << "mesh_" << i; + } + + // Read mesh data (groups are published automatically by ImportMEDFile()) + SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( mesh ).in() ); + ASSERT( meshServant ); + SMESH::DriverMED_ReadStatus status1 = + meshServant->ImportMEDFile( theFileName, meshName.c_str() ); + if (status1 > theStatus) + theStatus = status1; + + aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh ); + meshServant->GetImpl().GetMeshDS()->Modified(); + } + if ( !aStudyBuilder->_is_nil() ) + aStudyBuilder->CommitCommand(); } - if ( !aStudyBuilder->_is_nil() ) - aStudyBuilder->CommitCommand(); - } - // Update Python script - aPythonDump << "], status) = " << this << "." << theCommandNameForPython << "(r'" << theFileNameForPython << "')"; + // Update Python script + aPythonDump << "], status) = " << this << ".CreateMeshesFromMED( r'" << theFileName << "' )"; } // Dump creation of groups for ( CORBA::ULong i = 0; i < aResult->length(); ++i ) @@ -1393,66 +1405,6 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileNa return aResult._retn(); } -//================================================================================ -/*! - * \brief Create meshes by reading a MED file - */ -//================================================================================ - -SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName, - SMESH::DriverMED_ReadStatus& theStatus) -{ - Unexpect aCatch(SALOME_SalomeException); - checkFileReadable( theFileName ); - - SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(theFileName, theStatus, - "CreateMeshesFromMED", theFileName); - return result; -} - -//============================================================================= -/*! - * SMESH_Gen_i::CreateMeshFromSAUV - * - * Create mesh and import data from SAUV file - */ -//============================================================================= - -SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromSAUV( const char* theFileName, - SMESH::DriverMED_ReadStatus& theStatus) -{ - Unexpect aCatch(SALOME_SalomeException); - checkFileReadable( theFileName ); - - std::string sauvfilename(theFileName); - std::string medfilename(theFileName); - medfilename += ".med"; - std::string cmd; -#ifdef WIN32 - cmd = "%PYTHONBIN% "; -#else - cmd = "python3 "; -#endif - cmd += "-c \""; - cmd += "from medutilities import convert ; convert(r'" + sauvfilename + "', 'GIBI', 'MED', 1, r'" + medfilename + "')"; - cmd += "\""; - system(cmd.c_str()); - SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(medfilename.c_str(), - theStatus, - "CreateMeshesFromSAUV", - sauvfilename.c_str()); -#ifdef WIN32 - cmd = "%PYTHONBIN% "; -#else - cmd = "python3 "; -#endif - cmd += "-c \""; - cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')"; - cmd += "\""; - system(cmd.c_str()); - return result; -} - //============================================================================= /*! * SMESH_Gen_i::CreateMeshFromSTL @@ -2315,9 +2267,8 @@ SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh */ //============================================================================= -SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh, - GEOM::GEOM_Object_ptr theShapeObject) -// SMESH::long_array& theNbElems) +SMESH::smIdType_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh, + GEOM::GEOM_Object_ptr theShapeObject) { Unexpect aCatch(SALOME_SalomeException); if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" ); @@ -2328,7 +2279,7 @@ SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh, if ( CORBA::is_nil( theMesh ) ) THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM ); - SMESH::long_array_var nbels = new SMESH::long_array; + SMESH::smIdType_array_var nbels = new SMESH::smIdType_array; nbels->length(SMESH::Entity_Last); int i = SMESH::Entity_Node; for (; i < SMESH::Entity_Last; i++) @@ -2358,9 +2309,9 @@ SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh, /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap); MapShapeNbElemsItr anIt = aResMap.begin(); for(; anIt!=aResMap.end(); anIt++) { - const vector& aVec = (*anIt).second; + const vector& aVec = (*anIt).second; for ( i = SMESH::Entity_Node; i < (int)aVec.size(); i++ ) { - int nbElem = aVec[i]; + smIdType nbElem = aVec[i]; if ( nbElem < 0 ) // algo failed, check that it has reported a message { SMESH_subMesh* sm = anIt->first; @@ -2403,7 +2354,7 @@ SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh, GEOM::GEOM_Object_ptr SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh, - CORBA::Long theElementID, + SMESH::smIdType theElementID, const char* theGeomName) { Unexpect aCatch(SALOME_SalomeException); @@ -2467,7 +2418,7 @@ SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh, GEOM::GEOM_Object_ptr SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh, - CORBA::Long theElementID) + SMESH::smIdType theElementID) { Unexpect aCatch(SALOME_SalomeException); if ( CORBA::is_nil( theMesh ) ) @@ -2655,7 +2606,7 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray, } // remember nb of elements before filling in - SMESH::long_array_var prevState = newMesh->GetNbElementsByType(); + SMESH::smIdType_array_var prevState = newMesh->GetNbElementsByType(); // copy nodes @@ -2669,28 +2620,31 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray, // copy elements - SMESH::array_of_ElementType_var srcElemTypes = theMeshesArray[i]->GetTypes(); - if ( srcElemTypes->length() == 1 && srcElemTypes[0] == SMESH::NODE ) // group of nodes - continue; std::vector< const SMDS_MeshElement* > newElems( initMeshDS->NbElements() + 1, 0 ); - elemIt = initImpl->GetElements( theMeshesArray[i], SMESH::ALL ); - while ( elemIt->more() ) + SMESH::array_of_ElementType_var srcElemTypes = theMeshesArray[i]->GetTypes(); + bool hasElems = (( srcElemTypes->length() > 1 ) || + ( srcElemTypes->length() == 1 && srcElemTypes[0] != SMESH::NODE )); + if ( hasElems ) { - const SMDS_MeshElement* elem = elemIt->next(); - elemType.myNodes.resize( elem->NbNodes() ); - - SMDS_NodeIteratorPtr itNodes = elem->nodeIterator(); - for ( int k = 0; itNodes->more(); k++) + elemIt = initImpl->GetElements( theMeshesArray[i], SMESH::ALL ); + while ( elemIt->more() ) { - const SMDS_MeshNode* node = itNodes->next(); - elemType.myNodes[ k ] = static_cast< const SMDS_MeshNode*> ( newNodes[ node->GetID() ]); - } + const SMDS_MeshElement* elem = elemIt->next(); + elemType.myNodes.resize( elem->NbNodes() ); - // creates a corresponding element on existent nodes in new mesh - newElems[ elem->GetID() ] = - newEditor.AddElement( elemType.myNodes, elemType.Init( elem, /*basicOnly=*/false )); + SMDS_NodeIteratorPtr itNodes = elem->nodeIterator(); + for ( int k = 0; itNodes->more(); k++) + { + const SMDS_MeshNode* node = itNodes->next(); + elemType.myNodes[ k ] = static_cast< const SMDS_MeshNode*> ( newNodes[ node->GetID() ]); + } + + // creates a corresponding element on existent nodes in new mesh + newElems[ elem->GetID() ] = + newEditor.AddElement( elemType.myNodes, elemType.Init( elem, /*basicOnly=*/false )); + } + newEditor.ClearLastCreated(); // forget the history } - newEditor.ClearLastCreated(); // forget the history // create groups of just added elements @@ -2700,12 +2654,12 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray, { // type names const char* typeNames[] = { "All","Nodes","Edges","Faces","Volumes","0DElems","Balls" }; - { // check of typeNames: compilation failure mains that NB_ELEMENT_TYPES changed: - const int nbNames = sizeof(typeNames) / sizeof(const char*); - int _assert[( nbNames == SMESH::NB_ELEMENT_TYPES ) ? 2 : -1 ]; _assert[0]=_assert[1]=0; - } - SMESH::long_array_var curState = newMesh->GetNbElementsByType(); + // check of typeNames: compilation failure mains that NB_ELEMENT_TYPES changed: + static_assert( sizeof(typeNames) / sizeof(const char*) ==SMESH::NB_ELEMENT_TYPES, + "Update names of ElementType's!!!" ); + + SMESH::smIdType_array_var curState = newMesh->GetNbElementsByType(); for( groupType = SMESH::NODE; groupType < SMESH::NB_ELEMENT_TYPES; @@ -2752,7 +2706,7 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray, SMESH::SMESH_GroupBase_ptr group; CORBA::String_var groupName; - SMESH::long_array_var newIDs = new SMESH::long_array(); + SMESH::smIdType_array_var newIDs = new SMESH::smIdType_array(); // loop on groups of a source mesh SMESH::ListOfGroups_var listOfGroups = initImpl->GetGroups(); @@ -2855,6 +2809,100 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray, return newMesh._retn(); } + +//================================================================================ +/*! + * \brief Create a mesh by copying a part of another mesh + * \param mesh - TetraHedron mesh + * \param meshName Name of the created mesh + * \retval SMESH::SMESH_Mesh_ptr - the new mesh + */ +//================================================================================ + +SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateDualMesh(SMESH::SMESH_IDSource_ptr mesh, + const char* meshName, + CORBA::Boolean adapt_to_shape) +{ + Unexpect aCatch(SALOME_SalomeException); + + TPythonDump* pyDump = new TPythonDump(this); // prevent dump from CreateMesh() + std::unique_ptr pyDumpDeleter( pyDump ); + + // 1. Get source mesh + + if ( CORBA::is_nil( mesh )) + THROW_SALOME_CORBA_EXCEPTION( "bad IDSource", SALOME::BAD_PARAM ); + + std::cout << mesh << std::endl; + SMESH::SMESH_Mesh_var srcMesh = mesh->GetMesh(); + SMESH_Mesh_i* srcMesh_i = SMESH::DownCast( srcMesh ); + if ( !srcMesh_i ) + THROW_SALOME_CORBA_EXCEPTION( "bad mesh of IDSource", SALOME::BAD_PARAM ); + + CORBA::String_var mesh_var=GetORB()->object_to_string(mesh); + std::string mesh_ior = mesh_var.in(); + + //temporary folder for the generation of the med file + fs::path tmp_folder = fs::temp_directory_path() / fs::unique_path(fs::path("dual_mesh-%%%%")); + fs::create_directories(tmp_folder); + fs::path dual_mesh_file = tmp_folder / fs::path("tmp_dual_mesh.med"); + std::string mesh_name = meshName; + MESSAGE("Working in folder" + tmp_folder.string()); + + // Running Python script + assert(Py_IsInitialized()); + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + std::string cmd="import salome.smesh.smesh_tools as smt"; + PyRun_SimpleString(cmd.c_str()); + std::string ats; + if(adapt_to_shape) + ats = "True"; + else + ats = "False"; + + cmd = "smt.smesh_create_dual_mesh(\"" + mesh_ior + "\", \"" + + dual_mesh_file.string() + "\", mesh_name=\"" + mesh_name + "\", adapt_to_shape=" + ats + ")"; + MESSAGE(cmd); + PyRun_SimpleString(cmd.c_str()); + + PyGILState_Release(gstate); + MESSAGE("Executed python script"); + MESSAGE("Mesh created in " + dual_mesh_file.string()); + + // Import created MED + SMESH::SMESH_Mesh_var newMesh = CreateMesh(GEOM::GEOM_Object::_nil()); + SMESH_Mesh_i* newMesh_i = SMESH::DownCast( newMesh ); + if ( !newMesh_i ) + THROW_SALOME_CORBA_EXCEPTION( "can't create a mesh", SALOME::INTERNAL_ERROR ); + SALOMEDS::SObject_wrap meshSO = ObjectToSObject( newMesh ); + if ( !meshSO->_is_nil() ) + { + SetName( meshSO, meshName, meshName ); + SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED"); + } + + SMESH_Mesh& newMesh2 = newMesh_i->GetImpl(); + + MESSAGE("Loading file: " << dual_mesh_file.string() << " with mesh " << mesh_name); + newMesh2.MEDToMesh(dual_mesh_file.c_str(), meshName); + + MESSAGE("Imported created MED") + + SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS(); + + newMeshDS->Modified(); + + *pyDump << newMesh << " = " << this + << ".CreateDualMesh(" + << mesh << ", " + << "'" << meshName << "', " + << ats << ") "; + + return newMesh._retn(); +} + //================================================================================ /*! * \brief Create a mesh by copying a part of another mesh @@ -2917,7 +2965,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart, } else { - SMESH::long_array_var ids = meshPart->GetIDs(); + SMESH::smIdType_array_var ids = meshPart->GetIDs(); if ( srcElemTypes->length() == 1 && srcElemTypes[0] == SMESH::NODE ) // group of nodes { for ( CORBA::ULong i=0; i < ids->length(); i++ ) @@ -3040,8 +3088,8 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart, { TE2EMap & e2eMap = e2eMapByType[ groupDS->GetType() ]; if ( e2eMap.empty() ) continue; - int minID = e2eMap.begin()->first->GetID(); - int maxID = e2eMap.rbegin()->first->GetID(); + smIdType minID = e2eMap.begin()->first->GetID(); + smIdType maxID = e2eMap.rbegin()->first->GetID(); TE2EMap::iterator e2e; while ( eIt->more() && groupElems.size() < e2eMap.size()) { @@ -3872,7 +3920,7 @@ CORBA::Boolean SMESH_Gen_i::CopyMeshWithGeom( SMESH::SMESH_Mesh_ptr theSou { if ( newMeshDS->GetMeshInfo().NbElements( SMDSAbs_ElementType( elemType )) > 0 ) { - SMESH::long_array_var elemIDs = stdlGroup->GetIDs(); + SMESH::smIdType_array_var elemIDs = stdlGroup->GetIDs(); const bool isElem = ( elemType != SMESH::NODE ); CORBA::ULong iE = 0; for ( ; iE < elemIDs->length(); ++iE ) // check if any element has been copied @@ -4199,8 +4247,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, system(cmd.ToCString()); // MED writer to be used by storage process - DriverMED_W_SMESHDS_Mesh myWriter; - myWriter.SetFile( meshfile.ToCString() ); + DriverMED_W_SMESHDS_Mesh writer; + writer.SetFile( meshfile.ToCString() ); + //writer.SetSaveNumbers( false ); // bos #24400 -- it leads to change of element IDs // IMP issue 20918 // SetStoreName() to groups before storing hypotheses to let them refer to @@ -4407,8 +4456,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // check if the mesh is not empty if ( mySMESHDSMesh->NbNodes() > 0 ) { // write mesh data to med file - myWriter.SetMesh( mySMESHDSMesh ); - myWriter.SetMeshId( id ); + writer.SetMesh( mySMESHDSMesh ); + writer.SetMeshId( id ); strHasData = "1"; } aSize[ 0 ] = strHasData.length() + 1; @@ -4456,7 +4505,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // write reference on a shape if exists SALOMEDS::SObject_wrap myRef; bool shapeRefFound = false; - bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef.inout() ); + bool found = gotBranch->FindSubObject( (CORBA::Long)GetRefOnShapeTag(), myRef.inout() ); if ( found ) { SALOMEDS::SObject_wrap myShape; bool ok = myRef->ReferencedObject( myShape.inout() ); @@ -4487,7 +4536,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // write applied hypotheses if exist SALOMEDS::SObject_wrap myHypBranch; - found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() ); + found = gotBranch->FindSubObject( (CORBA::Long)GetRefOnAppliedHypothesisTag(), myHypBranch.inout() ); if ( found && !shapeRefFound && hasShape ) { // remove applied hyps aStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch ); } @@ -4882,7 +4931,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // Pass SMESHDS_Group to MED writer SMESHDS_Group* aGrpDS = dynamic_cast( aGrpBaseDS ); if ( aGrpDS ) - myWriter.AddGroup( aGrpDS ); + writer.AddGroup( aGrpDS ); // write reference on a shape if exists SMESHDS_GroupOnGeom* aGeomGrp = @@ -4907,7 +4956,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, else // shape ref is invalid: { // save a group on geometry as ordinary group - myWriter.AddGroup( aGeomGrp ); + writer.AddGroup( aGeomGrp ); } } else if ( SMESH_GroupOnFilter_i* aFilterGrp_i = @@ -4930,7 +4979,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( strcmp( strHasData.c_str(), "1" ) == 0 ) { // Flush current mesh information into MED file - myWriter.Perform(); + writer.Perform(); // save info on nb of elements SMESH_PreMeshInfo::SaveToFile( myImpl, id, aFile ); @@ -4957,7 +5006,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, { SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator( isNode ? SMDSAbs_Node : SMDSAbs_All ); - int nbElems = isNode ? mySMESHDSMesh->NbNodes() : mySMESHDSMesh->GetMeshInfo().NbElements(); + smIdType nbElems = isNode ? mySMESHDSMesh->NbNodes() : mySMESHDSMesh->GetMeshInfo().NbElements(); if ( nbElems < 1 ) continue; std::vector smIDs; smIDs.reserve( nbElems ); @@ -4998,7 +5047,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, SMESHDS_SubMesh* aSubMesh = const_cast< SMESHDS_SubMesh* >( smIt->next() ); if ( aSubMesh->IsComplexSubmesh() ) continue; // submesh containing other submeshs - int nbNodes = aSubMesh->NbNodes(); + smIdType nbNodes = aSubMesh->NbNodes(); if ( nbNodes == 0 ) continue; int aShapeID = aSubMesh->GetID(); @@ -5186,7 +5235,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, TCollection_AsciiString aStudyName( "" ); if ( isMultiFile ) { CORBA::WString_var url = aStudy->URL(); - aStudyName = (char*)SALOMEDS_Tool::GetNameFromPath( Kernel_Utils::encode(url.in()) ).c_str(); + SMESHUtils::ArrayDeleter urlMulibyte( Kernel_Utils::encode( url.in()) ); + aStudyName = (char*)SALOMEDS_Tool::GetNameFromPath( urlMulibyte.get() ).c_str(); } // Set names of temporary files TCollection_AsciiString filename = tmpDir + aStudyName + "_SMESH.hdf"; @@ -5540,7 +5590,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, } } // reading MESHes - // As all object that can be referred by hypothesis are created, + // As all objects that can be referred by hypothesis are created, // we can restore hypothesis data list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data; @@ -5716,7 +5766,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, if ( aSubMesh->_is_nil() ) continue; string iorSubString = GetORB()->object_to_string( aSubMesh ); - int newSubId = myStudyContext->findId( iorSubString ); + int newSubId = myStudyContext->findId( iorSubString ); myStudyContext->mapOldToNew( subid, newSubId ); } } @@ -5908,7 +5958,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, if ( aNewGroup->_is_nil() ) continue; - string iorSubString = GetORB()->object_to_string( aNewGroup ); + CORBA::String_var iorSubStringVar = GetORB()->object_to_string( aNewGroup ); + string iorSubString(iorSubStringVar.in()); int newSubId = myStudyContext->findId( iorSubString ); myStudyContext->mapOldToNew( subid, newSubId ); @@ -5987,13 +6038,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, aDataset->ReadFromDisk((char*) dataString.data() ); aDataset->CloseOnDisk(); - std::istringstream istream( dataString.data() ); - boost::archive::text_iarchive archive( istream ); std::list< std::list< std::string > > orderEntryLists; - try { - archive >> orderEntryLists; - } - catch (...) {} + SMESHUtils::BoostTxtArchive( dataString ) >> orderEntryLists; TListOfListOfInt anOrderIds; for ( const std::list< std::string >& entryList : orderEntryLists ) @@ -6233,11 +6279,12 @@ int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject) */ //================================================================================ -CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject) +CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject) { if ( myStudyContext && !CORBA::is_nil( theObject )) { - string iorString = GetORB()->object_to_string( theObject ); - return myStudyContext->findId( iorString ); + CORBA::String_var iorString = GetORB()->object_to_string( theObject ); + string iorStringCpp(iorString.in()); + return myStudyContext->findId( iorStringCpp ); } return 0; } @@ -6311,46 +6358,6 @@ void SMESH_Gen_i::Move( const SMESH::sobject_list& what, useCaseBuilder->AppendTo( where, sobj ); // append to the end of list } } -//================================================================================ -/*! - * \brief Returns true if algorithm can be used to mesh a given geometry - * \param [in] theAlgoType - the algorithm type - * \param [in] theLibName - a name of the Plug-in library implementing the algorithm - * \param [in] theGeomObject - the geometry to mesh - * \param [in] toCheckAll - if \c True, returns \c True if all shapes are meshable, - * else, returns \c True if at least one shape is meshable - * \return CORBA::Boolean - can or can't - */ -//================================================================================ - -CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char* theAlgoType, - const char* theLibName, - GEOM::GEOM_Object_ptr theGeomObject, - CORBA::Boolean toCheckAll) -{ - SMESH_TRY; - - std::string aPlatformLibName; - GenericHypothesisCreator_i* aCreator = - getHypothesisCreator(theAlgoType, theLibName, aPlatformLibName); - if (aCreator) - { - TopoDS_Shape shape = GeomObjectToShape( theGeomObject ); - const SMESH_Algo::Features& feat = SMESH_Algo::GetFeatures( theAlgoType ); - return shape.IsNull() || aCreator->IsApplicable( shape, toCheckAll, feat._dim ); - } - else - { - return false; - } - - SMESH_CATCH( SMESH::doNothing ); - -#ifdef _DEBUG_ - cout << "SMESH_Gen_i::IsApplicable(): exception in " << ( theAlgoType ? theAlgoType : "") << endl; -#endif - return true; -} //================================================================================ /*! @@ -6533,7 +6540,7 @@ std::vector SMESH_Gen_i::_GetInside( SMESH::SMESH_IDSource_ptr meshPart, SMESH::SMESH_Group_var gsource = SMESH::SMESH_Group::_narrow(meshPart); if ( !gsource->_is_nil() ) { if(theElemType == SMESH::NODE) { - SMESH::long_array_var nodes = gsource->GetNodeIDs(); + SMESH::smIdType_array_var nodes = gsource->GetNodeIDs(); for ( CORBA::ULong i = 0; i < nodes->length(); ++i ) { if ( const SMDS_MeshNode* node = meshDS->FindNode( nodes[i] )) { long anId = node->GetID(); @@ -6542,7 +6549,7 @@ std::vector SMESH_Gen_i::_GetInside( SMESH::SMESH_IDSource_ptr meshPart, } } } else if (gsource->GetType() == theElemType || theElemType == SMESH::ALL ) { - SMESH::long_array_var elems = gsource->GetListOfID(); + SMESH::smIdType_array_var elems = gsource->GetListOfID(); for ( CORBA::ULong i = 0; i < elems->length(); ++i ) { if ( const SMDS_MeshElement* elem = meshDS->FindElement( elems[i] )) { long anId = elem->GetID(); @@ -6554,7 +6561,7 @@ std::vector SMESH_Gen_i::_GetInside( SMESH::SMESH_IDSource_ptr meshPart, } SMESH::SMESH_subMesh_var smsource = SMESH::SMESH_subMesh::_narrow(meshPart); if ( !smsource->_is_nil() ) { - SMESH::long_array_var elems = smsource->GetElementsByType( theElemType ); + SMESH::smIdType_array_var elems = smsource->GetElementsByType( theElemType ); for ( CORBA::ULong i = 0; i < elems->length(); ++i ) { const SMDS_MeshElement* elem = ( theElemType == SMESH::NODE ) ? meshDS->FindNode( elems[i] ) : meshDS->FindElement( elems[i] ); if (elem) { @@ -6566,3 +6573,47 @@ std::vector SMESH_Gen_i::_GetInside( SMESH::SMESH_IDSource_ptr meshPart, } return res; } + +//================================================================================ +/*! + * \brief Returns true if algorithm can be used to mesh a given geometry + * \param [in] theAlgoType - the algorithm type + * \param [in] theLibName - a name of the Plug-in library implementing the algorithm + * \param [in] theGeomObject - the geometry to mesh + * \param [in] toCheckAll - if \c True, returns \c True if all shapes are meshable, + * else, returns \c True if at least one shape is meshable + * \return CORBA::Boolean - can or can't + */ +//================================================================================ + +#undef SMY_OWN_CATCH +#define SMY_OWN_CATCH // prevent re-throwing SALOME::SALOME_Exception in IsApplicable() + +CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char* theAlgoType, + const char* theLibName, + GEOM::GEOM_Object_ptr theGeomObject, + CORBA::Boolean toCheckAll) +{ + SMESH_TRY; + + std::string aPlatformLibName; + GenericHypothesisCreator_i* aCreator = + getHypothesisCreator(theAlgoType, theLibName, aPlatformLibName); + if (aCreator) + { + TopoDS_Shape shape = GeomObjectToShape( theGeomObject ); + const SMESH_Algo::Features& feat = SMESH_Algo::GetFeatures( theAlgoType ); + return shape.IsNull() || aCreator->IsApplicable( shape, toCheckAll, feat._dim ); + } + else + { + return false; + } + + SMESH_CATCH( SMESH::doNothing ); + +#ifdef _DEBUG_ + cout << "SMESH_Gen_i::IsApplicable(): exception in " << ( theAlgoType ? theAlgoType : "") << endl; +#endif + return true; +}