Salome HOME
0023505: Sigsegv with fuse on cylinder and cone
[modules/smesh.git] / src / DriverMED / DriverMED_Family.h
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 //
28 #ifndef _INCLUDE_DRIVERMED_FAMILY
29 #define _INCLUDE_DRIVERMED_FAMILY
30
31 #include "SMESH_DriverMED.hxx"
32 #include "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 #include <limits>
42
43 #define REST_NODES_FAMILY 1
44 #define FIRST_NODE_FAMILY 2
45
46 #define REST_EDGES_FAMILY   -1
47 #define REST_FACES_FAMILY   -2
48 #define REST_VOLUMES_FAMILY -3
49 #define REST_0DELEM_FAMILY  -4
50 #define REST_BALL_FAMILY    -5
51 #define FIRST_ELEM_FAMILY   -6
52
53 // Not In Group families
54 #define NIG_EDGES_FAMILY   INT_MAX-1
55 #define NIG_FACES_FAMILY   INT_MAX-2
56 #define NIG_VOLS_FAMILY    INT_MAX-3
57 #define NIG_0DELEM_FAMILY  INT_MAX-4
58 #define NIG_BALL_FAMILY    INT_MAX-5
59 #define NIG_GROUP_PREFIX "NOT_IN_GRP"
60
61 typedef std::list<DriverMED_FamilyPtr               > DriverMED_FamilyPtrList;
62 typedef std::map<int,SMESHDS_SubMesh*               > SMESHDS_SubMeshPtrMap;
63 typedef std::list<SMESHDS_GroupBase*                > SMESHDS_GroupBasePtrList;
64 typedef std::set<const SMDS_MeshElement*,TIDCompare > ElementsSet;
65
66 class MESHDRIVERMED_EXPORT DriverMED_Family
67 {
68  public:
69
70   DriverMED_Family();
71
72   //! Methods for groups storing to MED
73   /*!
74     Split each group from list <theGroups> and each sub-mesh from list <theSubMeshes>
75     on some parts (families) on the basis of the elements membership in other groups
76     from <theGroups> and other sub-meshes from <theSubMeshes>.
77     Resulting families have no common elements.
78   */
79   static 
80   DriverMED_FamilyPtrList
81   MakeFamilies (SMESHDS_SubMeshIteratorPtr      theSubMeshes,
82                 const SMESHDS_GroupBasePtrList& theGroups,
83                 const bool doGroupOfNodes,
84                 const bool doGroupOfEdges,
85                 const bool doGroupOfFaces,
86                 const bool doGroupOfVolumes,
87                 const bool doGroupOf0DElems,
88                 const bool doGroupOfBalls,
89                 const bool doAllInGroups);
90
91   //! Create TFamilyInfo for this family
92   MED::PFamilyInfo 
93   GetFamilyInfo (const MED::PWrapper& theWrapper, 
94                  const MED::PMeshInfo& theMeshInfo) const;
95
96   //! Returns elements of this family
97   const ElementsSet& GetElements () const;
98
99   //! Returns a family ID
100   int GetId () const;
101
102   //! Sets a family ID
103   void SetId (const int theId);
104
105  public:
106
107   // Methods for groups reading from MED
108
109   void AddElement(const SMDS_MeshElement* theElement);
110
111   const MED::TStringSet& GetGroupNames() const;
112   void AddGroupName(std::string theGroupName);
113
114   void SetType(const SMDSAbs_ElementType theType);
115   SMDSAbs_ElementType GetType();
116   const std::set< SMDSAbs_ElementType >& GetTypes() const;
117
118   bool MemberOf(std::string theGroupName) const;
119
120   int GetGroupAttributVal() const;
121   void SetGroupAttributVal( int theValue);
122
123  private:
124   //! Initialize the tool by SMESHDS_GroupBase
125   void Init (SMESHDS_GroupBase* group);
126
127   //! Split <theSubMesh> on some parts (families) on the basis of the elements type.
128   static
129   DriverMED_FamilyPtrList 
130   SplitByType(SMESHDS_SubMesh* theSubMesh,
131               const int        theId);
132
133
134   /*! Remove from <Elements> elements, common with <by>,
135     Remove from <by> elements, common with <Elements>,
136     Create family <common> from common elements, with combined groups list.
137   */
138   void Split (DriverMED_FamilyPtr by,
139               DriverMED_FamilyPtr common);
140
141   //! Check, if this family has empty list of elements
142   bool IsEmpty () const;
143
144
145  private:
146   int                           myId;
147   SMDSAbs_ElementType           myType;
148   ElementsSet                   myElements;
149   MED::TStringSet               myGroupNames;
150   int                           myGroupAttributVal;
151   std::set<SMDSAbs_ElementType> myTypes; // Issue 0020576
152 };
153
154 #endif