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 5778794..f6d67ea 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 0f77a01..1325617 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 3164ae0..16c555e 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 f31f262..64d6b6a 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 873adf4..a9539b9 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 04d0476..eac04a4 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 6a69530..4e8da8e 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 17ee757..e8bc862 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 d4d65b5..9c8a983 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;
       }