X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYBRIDPlugin%2FHYBRIDPlugin_HYBRID.cxx;h=f9362f059c87232d2edcc8ae04909f29cfe1799f;hb=7972d6e3ce34777547876d3f4d52fc7c09d39334;hp=80d5993f0e7aa46536f76142fdaf1a2fd145fe36;hpb=28410a8526f5e958f0fd5f38c5529217c9d001f6;p=plugins%2Fhybridplugin.git diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx index 80d5993..f9362f0 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -70,6 +70,10 @@ #include #include +#include +namespace boofs = boost::filesystem; + +#include #include #define castToNode(n) static_cast( n ); @@ -95,6 +99,13 @@ static void removeFile( const std::string& fileName ) } } +// change results files permissions to user only (using boost to be used without C++17) +static void chmodUserOnly(const char* filename) +{ + if (boofs::exists(filename)) + boofs::permissions(filename, boofs::remove_perms | boofs::group_all | boofs::others_all ); +} + //============================================================================= /*! * @@ -167,11 +178,11 @@ bool HYBRIDPlugin_HYBRID::CheckHypothesis ( SMESH_Mesh& aMesh, TopoDS_Shape HYBRIDPlugin_HYBRID::entryToShape(std::string entry) { - if ( SMESH_Gen_i::getStudyServant()->_is_nil() ) + if ( SMESH_Gen_i::GetSMESHGen()->getStudyServant()->_is_nil() ) throw SALOME_Exception("MG-HYBRID plugin can't work w/o publishing in the study"); GEOM::GEOM_Object_var aGeomObj; TopoDS_Shape S = TopoDS_Shape(); - SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.c_str() ); + SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( entry.c_str() ); if (!aSObj->_is_nil() ) { CORBA::Object_var obj = aSObj->GetObject(); aGeomObj = GEOM::GEOM_Object::_narrow(obj); @@ -190,7 +201,7 @@ TopoDS_Shape HYBRIDPlugin_HYBRID::entryToShape(std::string entry) static void addElemInMeshGroup(SMESH_Mesh* theMesh, const SMDS_MeshElement* anElem, std::string& groupName, - std::set& groupsToRemove) + std::set& /*groupsToRemove*/) { if ( !anElem ) return; // issue 0021776 @@ -329,13 +340,13 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, SMESH_MesherHelper* theHelper, std::vector & theNodeByHybridId, std::vector & theFaceByHybridId, - std::map & theNodeToHybridIdMap, + std::map & /*theNodeToHybridIdMap*/, std::vector & aNodeGroupByHybridId, std::vector & anEdgeGroupByHybridId, std::vector & aFaceGroupByHybridId, std::set & groupsToRemove, bool toMakeGroupsOfDomains=false, - bool toMeshHoles=true) + bool /*toMeshHoles*/=true) { std::string tmpStr; SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS(); @@ -378,15 +389,15 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, theFaceByHybridId.clear(); } - int nbMeshNodes = theMeshDS->NbNodes(); int nbInitialNodes = theNodeByHybridId.size(); +#ifdef _DEBUG_ + int nbMeshNodes = theMeshDS->NbNodes(); const bool isQuadMesh = theHelper->GetMesh()->NbEdges( ORDER_QUADRATIC ) || theHelper->GetMesh()->NbFaces( ORDER_QUADRATIC ) || theHelper->GetMesh()->NbVolumes( ORDER_QUADRATIC ); -#ifdef _DEBUG_ std::cout << "theNodeByHybridId.size(): " << nbInitialNodes << std::endl; std::cout << "theHelper->GetMesh()->NbNodes(): " << nbMeshNodes << std::endl; std::cout << "isQuadMesh: " << isQuadMesh << std::endl; @@ -815,7 +826,7 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, std::map >::const_iterator subdomainIt = subdomainId2tetraId.begin(); std::string aSubdomainFileName = theFile; aSubdomainFileName = aSubdomainFileName + ".subdomain"; - ofstream aSubdomainFile ( aSubdomainFileName , ios::out); + std::ofstream aSubdomainFile ( aSubdomainFileName , ios::out); aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl; for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) { @@ -1382,11 +1393,17 @@ static bool writeGMFFile(MG_HYBRID_API* MGInput } MGInput->GmfCloseMesh(idx); + chmodUserOnly(theMeshFileName); if (idxRequired) - MGInput->GmfCloseMesh(idxRequired); + { + MGInput->GmfCloseMesh(idxRequired); + chmodUserOnly(theRequiredFileName); + } if (idxSol) - MGInput->GmfCloseMesh(idxSol); - + { + MGInput->GmfCloseMesh(idxSol); + chmodUserOnly(theSolFileName); + } return true; } @@ -1489,7 +1506,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // Write aSmdsToHybridIdMap to temp file std::string aSmdsToHybridIdMapFileName; aSmdsToHybridIdMapFileName = aGenericName + ".ids"; // ids relation - ofstream aIdsFile ( aSmdsToHybridIdMapFileName , ios::out); + std::ofstream aIdsFile ( aSmdsToHybridIdMapFileName , ios::out); Ok = aIdsFile.rdbuf()->is_open(); if (!Ok) { INFOS( "Can't write into " << aSmdsToHybridIdMapFileName); @@ -1503,6 +1520,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, } aIdsFile.close(); + chmodUserOnly(aSmdsToHybridIdMapFileName.c_str()); if ( ! Ok ) { if ( !_keepFiles ) { @@ -1519,7 +1537,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // run hybrid mesher // ----------------- - std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, theMesh ); + std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp ); if ( mgHybrid.IsExecutable() ) { @@ -1545,9 +1563,17 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, if ( _logInStandardOutput && mgHybrid.IsLibrary() ) std::cout << std::endl << mgHybrid.GetLog() << std::endl; + else + chmodUserOnly(aLogFileName.c_str()); if ( Ok ) std::cout << "End of Hybrid execution !" << std::endl; + if ( mgHybrid.IsExecutable() ) + { + chmodUserOnly(aResultFileName.c_str()); + chmodUserOnly(aResSolFileName.c_str()); + } + // -------------- // read a result // -------------- @@ -1721,7 +1747,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // run hybrid mesher // ----------------- - std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, theMesh ); + std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp ); if ( mgHybrid.IsExecutable() ) { @@ -1744,9 +1770,17 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, if ( _logInStandardOutput && mgHybrid.IsLibrary() ) std::cout << std::endl << mgHybrid.GetLog() << std::endl; + else + chmodUserOnly(aLogFileName.c_str()); if ( Ok ) std::cout << "End of Hybrid execution !" << std::endl; + if (mgHybrid.IsExecutable()) + { + chmodUserOnly(aResultFileName.c_str()); + chmodUserOnly(aResSolFileName.c_str()); + } + // -------------- // read a result // -------------- @@ -2095,9 +2129,12 @@ bool HYBRIDPlugin_HYBRID::storeErrorDescription(const char* logFi if ( errDescription.empty() ) { // no errors found char msgLic1[] = "connection to server failed"; char msgLic2[] = " Dlim "; + char msgLic3[] = "license is not valid"; if ( std::search( &buf[0], bufEnd, msgLic1, msgLic1 + strlen(msgLic1)) != bufEnd || std::search( &buf[0], bufEnd, msgLic2, msgLic2 + strlen(msgLic2)) != bufEnd ) - errDescription << "Licence problems."; + errDescription << "Network license problem."; + else if ( std::search( &buf[0], bufEnd, msgLic3, msgLic3 + strlen(msgLic3)) != bufEnd ) + errDescription << "License is not valid."; else { char msg2[] = "SEGMENTATION FAULT"; @@ -2205,9 +2242,9 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh, "Submesh can not be evaluated",this)); return false; } - std::vector aVec = (*anIt).second; - nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]); - nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]); + std::vector aVec = (*anIt).second; + nbtri += std::max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]); + nbqua += std::max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]); GProp_GProps G; BRepGProp::SurfaceProperties(F,G); double anArea = G.Mass(); @@ -2226,9 +2263,9 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh, tmpMap.Add(E); SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current()); MapShapeNbElemsItr anIt = aResMap.find(aSubMesh); - std::vector aVec = (*anIt).second; + std::vector aVec = (*anIt).second; nb0d_e += aVec[SMDSEntity_Node]; - nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]); + nb1d_e += std::max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]); if(IsFirst) { IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]); IsFirst = false; @@ -2246,7 +2283,7 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh, int nbVols = int(aVolume/tetrVol/CoeffQuality); int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2; int nb1d_in = (int) ( nbVols*6 - nb1d_e - nb1d_f ) / 5; - std::vector aVec(SMDSEntity_Last); + std::vector aVec(SMDSEntity_Last); for(int i=SMDSEntity_Node; iGetAlgo() )