From 5d0b75d9d1a9935ec419e820e6dde45a665dd978 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 15 Feb 2017 19:34:55 +0300 Subject: [PATCH] 23413: [CEA 2025] bug SMESH orientation Add a flag to MED driver to make all element belong to some group --- src/DriverMED/DriverMED_Family.cxx | 40 ++++++++++++--- src/DriverMED/DriverMED_Family.h | 12 ++++- src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx | 3 +- src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx | 57 ++++++++++++++++++---- src/DriverMED/DriverMED_W_SMESHDS_Mesh.h | 2 + src/SMESH/SMESH_Mesh.cxx | 11 ++++- src/SMESH/SMESH_Mesh.hxx | 3 +- src/SMESH_I/SMESH_2smeshpy.cxx | 2 + src/SMESH_I/SMESH_Gen_i.cxx | 4 +- 9 files changed, 111 insertions(+), 23 deletions(-) diff --git a/src/DriverMED/DriverMED_Family.cxx b/src/DriverMED/DriverMED_Family.cxx index 577879462..f6d67ea59 100644 --- a/src/DriverMED/DriverMED_Family.cxx +++ b/src/DriverMED/DriverMED_Family.cxx @@ -152,7 +152,8 @@ DriverMED_Family const bool doGroupOfFaces, const bool doGroupOfVolumes, const bool doGroupOf0DElems, - const bool doGroupOfBalls) + const bool doGroupOfBalls, + const bool doAllInGroups) { DriverMED_FamilyPtrList aFamilies; @@ -330,10 +331,38 @@ DriverMED_Family } DriverMED_FamilyPtr aNullFam (new DriverMED_Family); - aNullFam->SetId(0); + aNullFam->SetId( 0 ); aNullFam->myType = SMDSAbs_All; aFamilies.push_back(aNullFam); + if ( doAllInGroups ) + { + if ( !doGroupOfEdges ) + { + DriverMED_FamilyPtr aNigEdgeFam (new DriverMED_Family); + aNigEdgeFam->SetId( NIG_EDGES_FAMILY ); + aNigEdgeFam->myType = SMDSAbs_Edge; + aNigEdgeFam->myGroupNames.insert( NIG_GROUP_PREFIX "_EDGES" ); + aFamilies.push_back(aNigEdgeFam); + } + if ( !doGroupOfFaces ) + { + DriverMED_FamilyPtr aNigFaceFam (new DriverMED_Family); + aNigFaceFam->SetId( NIG_FACES_FAMILY ); + aNigFaceFam->myType = SMDSAbs_Face; + aNigFaceFam->myGroupNames.insert( NIG_GROUP_PREFIX "_FACES" ); + aFamilies.push_back(aNigFaceFam); + } + if ( !doGroupOfVolumes ) + { + DriverMED_FamilyPtr aNigVolFam (new DriverMED_Family); + aNigVolFam->SetId( NIG_VOLS_FAMILY ); + aNigVolFam->myType = SMDSAbs_Volume; + aNigVolFam->myGroupNames.insert( NIG_GROUP_PREFIX "_VOLS" ); + aFamilies.push_back(aNigVolFam); + } + } + return aFamilies; } @@ -342,7 +371,7 @@ DriverMED_Family * Create TFamilyInfo for this family */ //============================================================================= -MED::PFamilyInfo +MED::PFamilyInfo DriverMED_Family::GetFamilyInfo(const MED::PWrapper& theWrapper, const MED::PMeshInfo& theMeshInfo) const { @@ -445,9 +474,8 @@ void DriverMED_Family::Init (SMESHDS_GroupBase* theGroup) */ //============================================================================= DriverMED_FamilyPtrList -DriverMED_Family -::SplitByType (SMESHDS_SubMesh* theSubMesh, - const int theId) +DriverMED_Family::SplitByType (SMESHDS_SubMesh* theSubMesh, + const int theId) { DriverMED_FamilyPtrList aFamilies; DriverMED_FamilyPtr aNodesFamily (new DriverMED_Family); diff --git a/src/DriverMED/DriverMED_Family.h b/src/DriverMED/DriverMED_Family.h index 0f77a01ed..1325617f1 100644 --- a/src/DriverMED/DriverMED_Family.h +++ b/src/DriverMED/DriverMED_Family.h @@ -38,6 +38,7 @@ #include #include +#include #define REST_NODES_FAMILY 1 #define FIRST_NODE_FAMILY 2 @@ -49,6 +50,14 @@ #define REST_BALL_FAMILY -5 #define FIRST_ELEM_FAMILY -6 +// Not In Group families +#define NIG_EDGES_FAMILY INT_MAX-1 +#define NIG_FACES_FAMILY INT_MAX-2 +#define NIG_VOLS_FAMILY INT_MAX-3 +#define NIG_0DELEM_FAMILY INT_MAX-4 +#define NIG_BALL_FAMILY INT_MAX-5 +#define NIG_GROUP_PREFIX "NOT_IN_GRP" + typedef std::list DriverMED_FamilyPtrList; typedef std::map SMESHDS_SubMeshPtrMap; typedef std::list SMESHDS_GroupBasePtrList; @@ -76,7 +85,8 @@ class MESHDRIVERMED_EXPORT DriverMED_Family const bool doGroupOfFaces, const bool doGroupOfVolumes, const bool doGroupOf0DElems, - const bool doGroupOfBalls); + const bool doGroupOfBalls, + const bool doAllInGroups); //! Create TFamilyInfo for this family MED::PFamilyInfo diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index 3164ae065..16c555eaf 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -155,7 +155,8 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() aFamily->SetGroupAttributVal(anAttrVal); } if(MYDEBUG) MESSAGE(aGroupName); - aFamily->AddGroupName(aGroupName); + if ( strncmp( aGroupName.c_str(), NIG_GROUP_PREFIX, strlen(NIG_GROUP_PREFIX) ) != 0 ) + aFamily->AddGroupName(aGroupName); } aFamily->SetId( aFamId ); myFamilies[aFamId] = aFamily; diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index f31f262c0..64d6b6a3b 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -61,7 +61,8 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh(): myDoGroupOf0DElems(false), myDoGroupOfBalls(false), myAutoDimension(false), - myAddODOnVertices(false) + myAddODOnVertices(false), + myDoAllInGroups(false) {} void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, @@ -129,6 +130,32 @@ void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes() myDoGroupOfVolumes = true; } +void DriverMED_W_SMESHDS_Mesh::AddGroupOf0DElems() +{ + myDoGroupOf0DElems = true; +} + +void DriverMED_W_SMESHDS_Mesh::AddGroupOfBalls() +{ + myDoGroupOfBalls = true; +} + +//================================================================================ +/*! + * \brief Set up a flag to add all elements not belonging to any group to + * some auxiliary group. This is needed for SMESH -> SAUVE -> SMESH conversion, + * which since PAL0023285 reads only SAUVE elements belonging to any group, + * and hence can lose some elements. That auxiliary group is ignored while + * reading a MED file. + */ +//================================================================================ + +void DriverMED_W_SMESHDS_Mesh::AddAllToGroup() +{ + myDoAllInGroups = true; +} + + namespace { typedef double (SMDS_MeshNode::* TGetCoord)() const; @@ -429,7 +456,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() break; } } - + MED::PWrapper myMed = CrWrapper(myFile,myMedVersion); PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName); //MESSAGE("Add - aMeshName : "<GetName()); @@ -449,12 +476,20 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() int nbEdges = myMesh->NbEdges(); int nbFaces = myMesh->NbFaces(); int nbVolumes = myMesh->NbVolumes(); - if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY; - if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY; - if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY; - if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY; - if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY; - if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY; + if (myDoGroupOfNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY; + if (myDoGroupOfEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY; + if (myDoGroupOfFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY; + if (myDoGroupOfVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY; + if (myDoGroupOf0DElems) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY; + if (myDoGroupOfBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY; + if (myDoAllInGroups ) + { + if (!myDoGroupOfEdges) myEdgesDefaultFamilyId = NIG_EDGES_FAMILY ; + if (!myDoGroupOfFaces) myFacesDefaultFamilyId = NIG_FACES_FAMILY ; + if (!myDoGroupOfVolumes) myVolumesDefaultFamilyId = NIG_VOLS_FAMILY ; + if (!myDoGroupOf0DElems) my0DElementsDefaultFamilyId = NIG_0DELEM_FAMILY ; + if (!myDoGroupOfBalls) myBallsDefaultFamilyId = NIG_BALL_FAMILY ; + } //MESSAGE("Perform - aFamilyInfo"); list aFamilies; @@ -466,7 +501,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() myDoGroupOfFaces && nbFaces, myDoGroupOfVolumes && nbVolumes, myDoGroupOf0DElems && nb0DElements, - myDoGroupOfBalls && nbBalls); + myDoGroupOfBalls && nbBalls, + myDoAllInGroups); } else { aFamilies = DriverMED_Family::MakeFamilies @@ -476,7 +512,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() myDoGroupOfFaces && nbFaces, myDoGroupOfVolumes && nbVolumes, myDoGroupOf0DElems && nb0DElements, - myDoGroupOfBalls && nbBalls); + myDoGroupOfBalls && nbBalls, + myDoAllInGroups); } list::iterator aFamsIter; for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++) diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h index 873adf450..a9539b9e8 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h @@ -59,6 +59,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh void AddGroupOfVolumes(); void AddGroupOf0DElems(); void AddGroupOfBalls(); + void AddAllToGroup(); /*! functions to prepare adding one mesh */ @@ -88,6 +89,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh bool myDoGroupOfBalls; bool myAutoDimension; bool myAddODOnVertices; + bool myDoAllInGroups; }; #endif diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 04d047611..eac04a4d1 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1386,6 +1386,8 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED() * - 2D if all mesh nodes lie on XOY coordinate plane, or * - 3D in the rest cases. * If \a theAutoDimension is \c false, the space dimension is always 3. + * \param [in] theAddODOnVertices - to create 0D elements on all vertices + * \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413) * \return int - mesh index in the file */ //================================================================================ @@ -1396,7 +1398,8 @@ void SMESH_Mesh::ExportMED(const char * file, int theVersion, const SMESHDS_Mesh* meshPart, bool theAutoDimension, - bool theAddODOnVertices) + bool theAddODOnVertices, + bool theAllElemsToGroup) throw(SALOME_Exception) { SMESH_TRY; @@ -1419,6 +1422,8 @@ void SMESH_Mesh::ExportMED(const char * file, myWriter.AddGroupOfFaces(); myWriter.AddGroupOfVolumes(); } + if ( theAllElemsToGroup ) + myWriter.AddAllToGroup(); // Pass groups to writer. Provide unique group names. //set aGroupNames; // Corrected for Mantis issue 0020028 @@ -1474,7 +1479,9 @@ void SMESH_Mesh::ExportSAUV(const char *file, cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')"; cmd += "\""; system(cmd.c_str()); - ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, 1); + ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*theVersion=*/1, + /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false, + /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413 #ifdef WIN32 cmd = "%PYTHONBIN% "; #else diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index 6a6953074..4e8da8e92 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -253,7 +253,8 @@ class SMESH_EXPORT SMESH_Mesh int theVersion = 0, const SMESHDS_Mesh* theMeshPart = 0, bool theAutoDimension = false, - bool theAddODOnVertices = false) + bool theAddODOnVertices = false, + bool theAllElemsToGroup = false) throw(SALOME_Exception); void ExportDAT(const char * file, diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index 17ee75746..e8bc862a9 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -686,6 +686,7 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand _AString indent = aCommand->GetIndentation(); _AString tryStr = indent + "try:"; _AString newCmd = indent + tab + ( aCommand->GetString().ToCString() + indent.Length() ); + _AString pasCmd = indent + tab + "pass"; // to keep valid if newCmd is erased _AString excStr = indent + "except:"; _AString msgStr = indent + "\tprint '"; msgStr += method + "() failed. Invalid file name?'"; @@ -693,6 +694,7 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand aCommand->Clear(); aCommand->GetString() = newCmd; aCommand->SetOrderNb( ++myNbCommands ); + myCommands.push_back( new _pyCommand( pasCmd, ++myNbCommands )); myCommands.push_back( new _pyCommand( excStr, ++myNbCommands )); myCommands.push_back( new _pyCommand( msgStr, ++myNbCommands )); } diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index d4d65b56c..9c8a98304 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -1217,11 +1217,11 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileNa // - 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( myCurrentStudy, mesh.in(), ( theFileName == theFileNameForPython ) ? (*it).c_str() : aFileName.c_str() ); + + // Python Dump if ( !aSO->_is_nil() ) { - // Python Dump aPythonDump << aSO; } else { - // Python Dump aPythonDump << "mesh_" << i; } -- 2.39.2