Salome HOME
Bug NPAL12872 - EDF189 GEOM, SMESH : Visualization of groups with many colors
[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 "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 typedef std::list<DriverMED_FamilyPtr> DriverMED_FamilyPtrList;
51 typedef std::map<int,SMESHDS_SubMesh*> SMESHDS_SubMeshPtrMap;
52 typedef std::list<SMESHDS_GroupBase*> SMESHDS_GroupBasePtrList;
53 typedef std::set<const SMDS_MeshElement*> ElementsSet;
54 typedef std::map<int,SALOMEDS::Color> ColorMap;
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
104   bool MemberOf(std::string theGroupName) const;
105
106   int GetGroupAttributVal() const;
107   void SetGroupAttributVal( int theValue);
108
109  private:
110   //! Initialize the tool by SMESHDS_GroupBase
111   void Init (SMESHDS_GroupBase* theGroup, const ColorMap& theColorMap);
112
113   //! Split <theSubMesh> on some parts (families) on the basis of the elements type.
114   static
115   DriverMED_FamilyPtrList 
116   SplitByType(SMESHDS_SubMesh* theSubMesh,
117               const int        theId);
118
119
120   /*! Remove from <Elements> elements, common with <by>,
121     Remove from <by> elements, common with <Elements>,
122     Create family <common> from common elements, with combined groups list.
123   */
124   void Split (DriverMED_FamilyPtr by,
125               DriverMED_FamilyPtr common);
126
127   //! Check, if this family has empty list of elements
128   bool IsEmpty () const;
129
130
131  private:
132   int                           myId;
133   SMDSAbs_ElementType           myType;
134   ElementsSet                   myElements;
135   MED::TStringSet               myGroupNames;
136   int                           myGroupAttributVal;
137 };
138
139 #endif