Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / DriverMED / DriverMED_Family.h
1 // Copyright (C) 2007-2012  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
23 //  SMESH DriverMED : tool to split groups on families
24 //  File   : DriverMED_Family.hxx
25 //  Author : Julia DOROVSKIKH
26 //  Module : SMESH
27 //  $Header$
28 //
29 #ifndef _INCLUDE_DRIVERMED_FAMILY
30 #define _INCLUDE_DRIVERMED_FAMILY
31
32 #include "SMESH_DriverMED.hxx"
33
34 #include "SMDS_Mesh.hxx"
35 #include "SMESHDS_GroupBase.hxx"
36 #include "SMESHDS_SubMesh.hxx"
37 #include "MED_Common.hxx"
38
39 #include <boost/shared_ptr.hpp>
40 #include <set>
41
42 #define REST_NODES_FAMILY 1
43 #define REST_EDGES_FAMILY -1
44 #define REST_FACES_FAMILY -2
45 #define REST_VOLUMES_FAMILY -3
46 #define FIRST_NODE_FAMILY 2
47 #define FIRST_ELEM_FAMILY -4
48
49 class DriverMED_Family;
50 typedef boost::shared_ptr<DriverMED_Family> DriverMED_FamilyPtr;
51 typedef std::list<DriverMED_FamilyPtr> DriverMED_FamilyPtrList;
52 typedef std::map<int,SMESHDS_SubMesh*> SMESHDS_SubMeshPtrMap;
53 typedef std::list<SMESHDS_GroupBase*> SMESHDS_GroupBasePtrList;
54 typedef std::set<const SMDS_MeshElement*> ElementsSet;
55
56 class MESHDRIVERMED_EXPORT DriverMED_Family
57 {
58  public:
59
60   DriverMED_Family();
61
62   //! Methods for groups storing to MED
63   /*!
64     Split each group from list <theGroups> and each sub-mesh from list <theSubMeshes>
65     on some parts (families) on the basis of the elements membership in other groups
66     from <theGroups> and other sub-meshes from <theSubMeshes>.
67     Resulting families have no common elements.
68   */
69   static 
70   DriverMED_FamilyPtrList
71   MakeFamilies (const SMESHDS_SubMeshPtrMap& theSubMeshes,
72                 const SMESHDS_GroupBasePtrList& theGroups,
73                 const bool doGroupOfNodes,
74                 const bool doGroupOfEdges,
75                 const bool doGroupOfFaces,
76                 const bool doGroupOfVolumes);
77
78   //! Create TFamilyInfo for this family
79   MED::PFamilyInfo 
80   GetFamilyInfo (const MED::PWrapper& theWrapper, 
81                  const MED::PMeshInfo& theMeshInfo) const;
82
83   //! Returns elements of this family
84   const ElementsSet& GetElements () const;
85
86   //! Returns a family ID
87   int GetId () const;
88
89   //! Sets a family ID
90   void SetId (const int theId);
91
92  public:
93
94   // Methods for groups reading from MED
95
96   void AddElement(const SMDS_MeshElement* theElement);
97
98   const MED::TStringSet& GetGroupNames() const;
99   void AddGroupName(std::string theGroupName);
100
101   void SetType(const SMDSAbs_ElementType theType);
102   SMDSAbs_ElementType GetType();
103   const std::set< SMDSAbs_ElementType >& GetTypes() const;
104
105   bool MemberOf(std::string theGroupName) const;
106
107   int GetGroupAttributVal() const;
108   void SetGroupAttributVal( int theValue);
109
110  private:
111   //! Initialize the tool by SMESHDS_GroupBase
112   void Init (SMESHDS_GroupBase* group);
113
114   //! Split <theSubMesh> on some parts (families) on the basis of the elements type.
115   static
116   DriverMED_FamilyPtrList 
117   SplitByType(SMESHDS_SubMesh* theSubMesh,
118               const int        theId);
119
120
121   /*! Remove from <Elements> elements, common with <by>,
122     Remove from <by> elements, common with <Elements>,
123     Create family <common> from common elements, with combined groups list.
124   */
125   void Split (DriverMED_FamilyPtr by,
126               DriverMED_FamilyPtr common);
127
128   //! Check, if this family has empty list of elements
129   bool IsEmpty () const;
130
131
132  private:
133   int                           myId;
134   SMDSAbs_ElementType           myType;
135   ElementsSet                   myElements;
136   MED::TStringSet               myGroupNames;
137   int                           myGroupAttributVal;
138   std::set<SMDSAbs_ElementType> myTypes; // Issue 0020576
139 };
140
141 #endif