]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
23413: [CEA 2025] bug SMESH orientation
authoreap <eap@opencascade.com>
Wed, 15 Feb 2017 16:34:55 +0000 (19:34 +0300)
committereap <eap@opencascade.com>
Wed, 15 Feb 2017 16:34:55 +0000 (19:34 +0300)
Add a flag to MED driver to make all element belong to some group

src/DriverMED/DriverMED_Family.cxx
src/DriverMED/DriverMED_Family.h
src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx
src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx
src/DriverMED/DriverMED_W_SMESHDS_Mesh.h
src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_Mesh.hxx
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_Gen_i.cxx

index 577879462120528b10274b8e62efa3e0c9e57275..f6d67ea597d72ee76eb19488b0b9f874c7c4bc52 100644 (file)
@@ -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);
index 0f77a01ed27536f4ae988a5207e8d0a04fe9680a..1325617f13203d0b34b2e28223f5c52d59d0d6eb 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <boost/shared_ptr.hpp>
 #include <set>
+#include <limits>
 
 #define REST_NODES_FAMILY 1
 #define FIRST_NODE_FAMILY 2
 #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_FamilyPtr               > DriverMED_FamilyPtrList;
 typedef std::map<int,SMESHDS_SubMesh*               > SMESHDS_SubMeshPtrMap;
 typedef std::list<SMESHDS_GroupBase*                > 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 
index 3164ae065ebda3f53366536501a55335e10927e6..16c555eaf4723c41a7dfb138aea43e0d6f266f54 100644 (file)
@@ -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;
index f31f262c03438b16bd4bcd561a227484f13ab973..64d6b6a3b687b3ac68c3030c1cb28744e93107b0 100644 (file)
@@ -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 : "<<aMeshName<<"; "<<aMeshInfo->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<DriverMED_FamilyPtr> 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<DriverMED_FamilyPtr>::iterator aFamsIter;
     for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
index 873adf45028478205f94bb9fa0086296ea5f3ddd..a9539b9e8741fe509dc95803d76eab4d74c5e345 100644 (file)
@@ -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
index 04d04761111be66bec2792c13c7a7b964fd76a05..eac04a4d1604fda010e7e467e0897f81f132a8b7 100644 (file)
@@ -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<string> 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
index 6a6953074e85bdbfbd509106740cae528ecbe56f..4e8da8e920019de28896a7853d76df427757a957 100644 (file)
@@ -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,
index 17ee75746e49b91d4e0f02b86d1e43d47f08f01d..e8bc862a90dd119667e2afc63ddeaf5a8254f506 100644 (file)
@@ -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 ));
     }
index d4d65b56c95b9b4a6cec955dfd5b10c018a6bb7d..9c8a983040e33fb4af1ab5cc62d98e55a1bb0a4e 100644 (file)
@@ -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;
       }