Salome HOME
Copyright update 2022
[modules/smesh.git] / src / DriverMED / DriverMED_Family.h
index c83534cf9b01e60bde87c3e02df50c738f25e524..2c490a36f44331385526a33a084f17365df3d86a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  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
 #include "SMESHDS_SubMesh.hxx"
 #include "MED_Common.hxx"
 
+#include <boost/container/flat_set.hpp>
 #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
 
-typedef std::list<DriverMED_FamilyPtr     > DriverMED_FamilyPtrList;
-typedef std::map<int,SMESHDS_SubMesh*     > SMESHDS_SubMeshPtrMap;
-typedef std::list<SMESHDS_GroupBase*      > SMESHDS_GroupBasePtrList;
-typedef std::set<const SMDS_MeshElement*  > ElementsSet;
+// 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;
+typedef std::set<const SMDS_MeshElement*,TIDCompare     > ElementsSet;
+typedef boost::container::flat_set< SMDSAbs_ElementType > ElemTypeSet;
 
 class MESHDRIVERMED_EXPORT DriverMED_Family
 {
@@ -76,12 +87,14 @@ 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
+  template<class LowLevelWriter>
   MED::PFamilyInfo 
-  GetFamilyInfo (const MED::PWrapper& theWrapper, 
-                 const MED::PMeshInfo& theMeshInfo) const;
+  GetFamilyInfo(const LowLevelWriter& theWrapper, 
+                const MED::PMeshInfo& theMeshInfo) const;
 
   //! Returns elements of this family
   const ElementsSet& GetElements () const;
@@ -103,22 +116,23 @@ class MESHDRIVERMED_EXPORT DriverMED_Family
 
   void SetType(const SMDSAbs_ElementType theType);
   SMDSAbs_ElementType GetType();
-  const std::set< SMDSAbs_ElementType >& GetTypes() const;
+  const ElemTypeSet&  GetTypes() const;
 
   bool MemberOf(std::string theGroupName) const;
 
-  int GetGroupAttributVal() const;
+  int  GetGroupAttributVal() const;
   void SetGroupAttributVal( int theValue);
 
+  size_t NbElements( SMDSAbs_ElementType ) const;
+
  private:
   //! Initialize the tool by SMESHDS_GroupBase
   void Init (SMESHDS_GroupBase* group);
 
   //! Split <theSubMesh> on some parts (families) on the basis of the elements type.
   static
-  DriverMED_FamilyPtrList 
-  SplitByType(SMESHDS_SubMesh* theSubMesh,
-              const int        theId);
+  DriverMED_FamilyPtrList SplitByType(SMESHDS_SubMesh* theSubMesh,
+                                      const int        theId);
 
 
   /*! Remove from <Elements> elements, common with <by>,
@@ -133,12 +147,78 @@ class MESHDRIVERMED_EXPORT DriverMED_Family
 
 
  private:
-  int                           myId;
-  SMDSAbs_ElementType           myType;
-  ElementsSet                   myElements;
-  MED::TStringSet               myGroupNames;
-  int                           myGroupAttributVal;
-  std::set<SMDSAbs_ElementType> myTypes; // Issue 0020576
+  int                 myId;
+  SMDSAbs_ElementType myType;
+  ElementsSet         myElements;
+  MED::TStringSet     myGroupNames;
+  int                 myGroupAttributVal;
+  ElemTypeSet         myTypes; // Issue 0020576
 };
 
+#include "MED_Factory.hxx"
+
+#include <set>
+#include <string>
+//=============================================================================
+/*!
+ *  Create TFamilyInfo for this family
+ */
+//=============================================================================
+template<class LowLevelWriter>
+MED::PFamilyInfo
+DriverMED_Family::GetFamilyInfo(const LowLevelWriter& theWrapper, 
+                                const MED::PMeshInfo& theMeshInfo) const
+{
+  std::ostringstream aStr;
+  aStr << "FAM_" << myId;
+  std::set<std::string>::const_iterator aGrIter = myGroupNames.begin();
+  for(; aGrIter != myGroupNames.end(); aGrIter++){
+    aStr << "_" << *aGrIter;
+  }
+  std::string aValue = aStr.str();
+  // PAL19785,0019867 - med forbids whitespace to be the last char in the name
+  int maxSize = MED::GetNOMLength();
+  int lastCharPos = std::min( maxSize, (int) aValue.size() ) - 1;
+  while ( isspace( aValue[ lastCharPos ] ))
+    aValue.resize( lastCharPos-- );
+
+  MED::PFamilyInfo anInfo;
+  if(myId == 0 || myGroupAttributVal == 0){
+    anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
+                                      aValue,
+                                      myId,
+                                      myGroupNames);
+  }else{
+    MED::TStringVector anAttrDescs (1, "");  // 1 attribute with empty description,
+    MED::TIntVector anAttrIds (1, myId);        // Id=0,
+    MED::TIntVector anAttrVals (1, myGroupAttributVal);
+    anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
+                                      aValue,
+                                      myId,
+                                      myGroupNames,
+                                      anAttrDescs,
+                                      anAttrIds,
+                                      anAttrVals);
+  }
+
+//  cout << endl;
+//  cout << "Groups: ";
+//  set<string>::iterator aGrIter = myGroupNames.begin();
+//  for (; aGrIter != myGroupNames.end(); aGrIter++)
+//  {
+//    cout << " " << *aGrIter;
+//  }
+//  cout << endl;
+//
+//  cout << "Elements: ";
+//  set<const SMDS_MeshElement *>::iterator anIter = myElements.begin();
+//  for (; anIter != myElements.end(); anIter++)
+//  {
+//    cout << " " << (*anIter)->GetID();
+//  }
+//  cout << endl;
+
+  return anInfo;
+}
+
 #endif