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