Salome HOME
First executable version
[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.org
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 "SMESH_DriverMED.hxx"
32
33 #include "SMDS_Mesh.hxx"
34 #include "SMESHDS_GroupBase.hxx"
35 #include "SMESHDS_SubMesh.hxx"
36 #include "MED_Common.hxx"
37
38 #include <boost/shared_ptr.hpp>
39 #include <set>
40
41 #define REST_NODES_FAMILY 1
42 #define REST_EDGES_FAMILY -1
43 #define REST_FACES_FAMILY -2
44 #define REST_VOLUMES_FAMILY -3
45 #define FIRST_NODE_FAMILY 2
46 #define FIRST_ELEM_FAMILY -4
47
48 class DriverMED_Family;
49 typedef boost::shared_ptr<DriverMED_Family> DriverMED_FamilyPtr;
50
51 class MESHDRIVERMED_EXPORT DriverMED_Family
52 {
53  public:
54
55   // Methods for groups storing to MED
56
57   static std::list<DriverMED_FamilyPtr> MakeFamilies (const std::map <int, SMESHDS_SubMesh*>& theSubMeshes,
58                                                       const std::list<SMESHDS_GroupBase*>& theGroups,
59                                                       const bool doGroupOfNodes,
60                                                       const bool doGroupOfEdges,
61                                                       const bool doGroupOfFaces,
62                                                       const bool doGroupOfVolumes);
63   // Split each group from list <theGroups> and each sub-mesh from list <theSubMeshes>
64   // on some parts (families) on the basis of the elements membership in other groups
65   // from <theGroups> and other sub-meshes from <theSubMeshes>.
66   // Resulting families have no common elements.
67
68   MED::PFamilyInfo GetFamilyInfo (const MED::PWrapper& theWrapper, 
69                                   const MED::PMeshInfo& theMeshInfo) const;
70   // Create TFamilyInfo for this family
71
72   const std::set<const SMDS_MeshElement *>& GetElements () const { return myElements; }
73   // Returns elements of this family
74
75   int GetId () const { return myId; }
76   // Returns a family ID
77
78  public:
79
80   // Methods for groups reading from MED
81
82   void AddElement (const SMDS_MeshElement* theElement) { myElements.insert(theElement); }
83
84   void AddGroupName (std::string theGroupName) { myGroupNames.insert(theGroupName); }
85
86   void SetType (const SMDSAbs_ElementType theType) { myType = theType; }
87   SMDSAbs_ElementType GetType () { return myType; }
88
89   bool MemberOf (std::string theGroupName) const
90     { return (myGroupNames.find(theGroupName) != myGroupNames.end()); }
91
92   const MED::TStringSet& GetGroupNames () const { return myGroupNames; }
93
94   void SetId (const int theId) { myId = theId; }
95   // Sets a family ID
96
97  private:
98   void Init (SMESHDS_GroupBase* group);
99   // Initialize the tool by SMESHDS_GroupBase
100
101   static std::list<DriverMED_FamilyPtr> SplitByType (SMESHDS_SubMesh* theSubMesh,
102                                                      const int        theId);
103   // Split <theSubMesh> on some parts (families)
104   // on the basis of the elements type.
105
106   void Split (DriverMED_FamilyPtr by,
107               DriverMED_FamilyPtr common);
108   // Remove from <Elements> elements, common with <by>,
109   // Remove from <by> elements, common with <Elements>,
110   // Create family <common> from common elements, with combined groups list.
111
112   bool IsEmpty () const { return myElements.empty(); }
113   // Check, if this family has empty list of elements
114
115  private:
116   int                           myId;
117   SMDSAbs_ElementType           myType;
118   std::set<const SMDS_MeshElement *> myElements;
119   MED::TStringSet               myGroupNames;
120 };
121
122 #endif