Salome HOME
f91693a88ac99ce379be10fb5c146558643bdd6c
[modules/smesh.git] / src / DriverMED / DriverMED_Family.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH DriverMED : tool to split groups on families
23 //  File   : DriverMED_Family.hxx
24 //  Author : Julia DOROVSKIKH
25 //  Module : SMESH
26 //
27 #ifndef _INCLUDE_DRIVERMED_FAMILY
28 #define _INCLUDE_DRIVERMED_FAMILY
29
30 #include "SMESH_DriverMED.hxx"
31
32 #include "SMDS_Mesh.hxx"
33 #include "SMESHDS_GroupBase.hxx"
34 #include "SMESHDS_SubMesh.hxx"
35 #include "MED_Common.hxx"
36
37 #include <boost/shared_ptr.hpp>
38 #include <set>
39
40 #define REST_NODES_FAMILY 1
41 #define REST_EDGES_FAMILY -1
42 #define REST_FACES_FAMILY -2
43 #define REST_VOLUMES_FAMILY -3
44 #define FIRST_NODE_FAMILY 2
45 #define FIRST_ELEM_FAMILY -4
46
47 class DriverMED_Family;
48 typedef boost::shared_ptr<DriverMED_Family> DriverMED_FamilyPtr;
49 typedef std::list<DriverMED_FamilyPtr> DriverMED_FamilyPtrList;
50 typedef std::map<int,SMESHDS_SubMesh*> SMESHDS_SubMeshPtrMap;
51 typedef std::list<SMESHDS_GroupBase*> SMESHDS_GroupBasePtrList;
52 typedef std::set<const SMDS_MeshElement*> ElementsSet;
53
54 class MESHDRIVERMED_EXPORT DriverMED_Family
55 {
56  public:
57
58   DriverMED_Family();
59
60   //! Methods for groups storing to MED
61   /*!
62     Split each group from list <theGroups> and each sub-mesh from list <theSubMeshes>
63     on some parts (families) on the basis of the elements membership in other groups
64     from <theGroups> and other sub-meshes from <theSubMeshes>.
65     Resulting families have no common elements.
66   */
67   static 
68   DriverMED_FamilyPtrList
69   MakeFamilies (const SMESHDS_SubMeshPtrMap& theSubMeshes,
70                 const SMESHDS_GroupBasePtrList& theGroups,
71                 const bool doGroupOfNodes,
72                 const bool doGroupOfEdges,
73                 const bool doGroupOfFaces,
74                 const bool doGroupOfVolumes);
75
76   //! Create TFamilyInfo for this family
77   MED::PFamilyInfo 
78   GetFamilyInfo (const MED::PWrapper& theWrapper, 
79                  const MED::PMeshInfo& theMeshInfo) const;
80
81   //! Returns elements of this family
82   const ElementsSet& GetElements () const;
83
84   //! Returns a family ID
85   int GetId () const;
86
87   //! Sets a family ID
88   void SetId (const int theId);
89
90  public:
91
92   // Methods for groups reading from MED
93
94   void AddElement(const SMDS_MeshElement* theElement);
95
96   const MED::TStringSet& GetGroupNames() const;
97   void AddGroupName(std::string theGroupName);
98
99   void SetType(const SMDSAbs_ElementType theType);
100   SMDSAbs_ElementType GetType();
101   const std::set< SMDSAbs_ElementType >& GetTypes() const;
102
103   bool MemberOf(std::string theGroupName) const;
104
105   int GetGroupAttributVal() const;
106   void SetGroupAttributVal( int theValue);
107
108  private:
109   //! Initialize the tool by SMESHDS_GroupBase
110   void Init (SMESHDS_GroupBase* group);
111
112   //! Split <theSubMesh> on some parts (families) on the basis of the elements type.
113   static
114   DriverMED_FamilyPtrList 
115   SplitByType(SMESHDS_SubMesh* theSubMesh,
116               const int        theId);
117
118
119   /*! Remove from <Elements> elements, common with <by>,
120     Remove from <by> elements, common with <Elements>,
121     Create family <common> from common elements, with combined groups list.
122   */
123   void Split (DriverMED_FamilyPtr by,
124               DriverMED_FamilyPtr common);
125
126   //! Check, if this family has empty list of elements
127   bool IsEmpty () const;
128
129
130  private:
131   int                           myId;
132   SMDSAbs_ElementType           myType;
133   ElementsSet                   myElements;
134   MED::TStringSet               myGroupNames;
135   int                           myGroupAttributVal;
136   std::set<SMDSAbs_ElementType> myTypes; // Issue 0020576
137 };
138
139 #endif