Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MULTIPR / MULTIPR_Family.hxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_Family.hxx
6  *
7  * \brief   Class Family, Group and Attributs used to wrap MED file structures.
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 #ifndef MULTIPR_FAMILY_HXX
15 #define MULTIPR_FAMILY_HXX
16
17 //*****************************************************************************
18 // Includes section
19 //*****************************************************************************
20
21 extern "C"
22 {
23     #include "med.h"
24 }
25
26
27 #include <iostream>
28 #include <vector>
29 #include <set>
30 #include <map>
31
32 #include "MULTIPR_Mesh.hxx"
33
34 namespace multipr
35 {
36
37 //*****************************************************************************
38 // Predeclaration
39 //*****************************************************************************
40
41 class Group;
42
43
44 //*****************************************************************************
45 // Class Attributs
46 //*****************************************************************************
47
48 class Attributs
49 {
50 public:
51     
52     /** 
53      * Builds an empty Attributs (default constructor).
54      */
55     Attributs();
56     
57     /**
58      * Destructor. Removes everything.
59      */
60     ~Attributs();
61     
62     /**
63      * Assignment operator (deep copy).
64      * \param  pAttr any Atttibuts to be copied.
65      * \return a reference towards the copy.
66      */
67     Attributs& operator=(const Attributs& pAttr);
68     
69     /**
70      * Resets this object in its state by default (empty). Cleans memory.
71      */
72     void reset();
73     
74     //---------------------------------------------------------------------
75     // I/O
76     //---------------------------------------------------------------------
77     
78     /**
79      * Dumps any Attributs to the given output stream.
80      * \param  pOs any output stream.
81      * \param  pA  any Attributs.
82      * \return the output stream pOs.
83      */
84     friend std::ostream& operator<<(std::ostream& pOs, Attributs& pA);
85     
86 public:
87
88     med_int   mNum;     /**< Number of attributes. */
89     med_int*  mId;      /**< Table of identifiers: for each attribute, its identifier. */
90     med_int*  mVal;     /**< Table of values; for each attribute, its value. */
91     char*     mDesc;    /**< Table of description; for each attribute, its description. */
92     
93 private:
94
95     // do not allow copy constructor
96     Attributs(const Attributs&);
97     
98     // do not allow operator ==
99     bool operator==(const Attributs&); 
100     
101 }; // class Attribut
102
103
104 //*****************************************************************************
105 // Class Family
106 //*****************************************************************************
107
108 class Family
109 {
110 public:
111
112     /** 
113      * Builds an empty Family (default constructor).
114      */
115     Family();
116     
117     /**
118      * Copy constructor.
119      */
120     Family(const Family& pFamily);
121     
122     /**
123      * Destructor. Removes everything.
124      */
125     ~Family();    
126     
127     /**
128      * Resets this object in its state by default (empty). Cleans memory.
129      */
130     void reset();
131     
132     //---------------------------------------------------------------------
133     // Basic accessors/mutators
134     //---------------------------------------------------------------------
135     
136     /**
137      * Returns the identifier (= number) of this Family.
138      * \return the identifier of this Family.
139      */
140     med_int getId() const { return mId; }
141     
142     /**
143      * Set the identifier of this family.
144      * \param pId The identifier.
145      */
146     void    setId(med_int pId) { mId = pId; };
147      
148     /**
149      * Returns the name of this Family.
150      * \return the name of this Family.
151      */
152     const char* getName() const { return mName; }
153     
154     /**
155      * Returns true if this Family if a family of nodes, false if is a family of elements (=cells)).
156      * \return true iff this Family if a family of nodes.
157      */
158     bool isFamilyOfNodes() const { return mIsFamilyOfNodes; }
159     
160     /**
161      * Sets whether this Family is a family of nodes or family of elements (= cells).
162      * \param  pIsFamilyOfNodes flag.
163      */
164     void setIsFamilyOfNodes(bool pIsFamilyOfNodes) { mIsFamilyOfNodes = pIsFamilyOfNodes; }
165     
166     /**
167      * Inserts a new element (by its index) into this Family.
168      * \param  pIndexElt index of the element to be added; must be >= 1.
169          * \param  pMeshIndex Index of the mesh (eMED_TETRA4 etc...). Default value when its a family of nodes.
170      * \throw  IllegalArgumentException if pIndexElt <= 0.
171      */
172     void insertElt(med_int pIndexElt, eMeshType pMeshIndex = eMED_POINT1); 
173     
174     /**
175      * Returns the number of elements in this Family.
176      * \return the number of elements in this Family.
177      */
178     int getSize(eMeshType pMeshIndex = eMED_POINT1) const { return mElt[pMeshIndex].size(); }
179     
180     //---------------------------------------------------------------------
181     // Algorithms
182     //---------------------------------------------------------------------
183
184     /**
185      * Adds all the groups of this Family into the set of groups described by (pGroups, pGroupNameToGroup).
186      * \param  pGroups            current list of groups.
187      * \param  pGroupNameToGroup  table (map) to retrieve a Group* from its name.
188      */
189     void buildGroups(
190         std::vector<Group*>&            pGroups, 
191         std::map<std::string, Group*>&  pGroupNameToGroup) const;
192     
193     /**
194      * Constructor. Returns a copy of this family restricted to the given group if pGroupName != NULL.
195      * Examples: 
196      * 1. If current family have 3 groups "A", "B" and "C" and pGroupName="B", then the new family will only reference the group "B"
197      * 2. If current family have 3 groups "A", "B" and "C" and pGroupName="D", then the new family will reference groups "A", "B" and "C".
198      * WARNING: elements are not copied
199      * \param   pGroupName name of the group to keep.
200      * \return  a copy of this family.
201      */
202     Family* extractGroup(const char* pGroupName);
203     
204         /**
205      * Returns the set of all the elements referenced in this Family.
206      * \return the set of all the elements referenced in this Family.
207      */
208     const std::set<med_int>& getSetOfElt(eMeshType pMeshIndex) const { return mElt[pMeshIndex]; }
209         
210     //---------------------------------------------------------------------
211     // I/O
212     //---------------------------------------------------------------------
213
214     /**
215      * Reads a Family from a MED file.
216      * \param  pMEDfile  any valid MED file opened for reading.
217      * \param  pMeshName name of the mesh. 
218      * \param  pIndex    index of the family to be read (must be >= 1).
219      * \throw  IOException if any i/o error occurs.
220      */
221     void readMED(med_idt pMEDfile, char* pMeshName, med_int pIndex);
222     
223     /**
224      * Writes this Family to a MED file.
225      * WARNING: mesh must have been created and added to the MED file before.
226      * \param  pMEDfile  any valid MED file opened for writing.
227      * \param  pPeshName name of the mesh.
228      * \throw  IOException if any i/o error occurs.
229      */
230     void writeMED(med_idt pMEDfile, char* pMeshName);
231     
232     /**
233      * Sets the flag which control the stream operator <<.
234      * \param  pFlag new flag value.
235      */
236     void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } 
237     
238     /**
239      * Dumps any Family to the given output stream.
240      * \param  pOs any output stream.
241      * \param  pF  any Family.
242      * \return the output stream pOs.
243      */
244     friend std::ostream& operator<<(std::ostream& pOs, Family& pF);
245     
246 private:
247     
248     char                     mName[MED_TAILLE_NOM + 1];   /** Name of the Family */
249     med_int                  mId;               /**< Id: > 0 if family of nodes; < 0 if family of elements. */
250     std::set<med_int>        mElt[eMaxMedMesh]; /**< Set of all the elements (by their index in 1..*). */
251     std::string              mStrNameGroups;    /**< A string with name of all groups which contain the Family. */
252     std::vector<std::string> mNameGroups;       /**< List of groups (by name) which contain the Family. */
253     Attributs                mAttributs;        /**< All the attributed related to the Family. */
254     bool                     mIsFamilyOfNodes;  /**< Is it a family of nodes or a family of elements? */
255     
256     bool                     mFlagPrintAll;     /** Flag to control the behaviour of the stream operator <<. */
257     
258 private:
259
260     // do not allow copy constructor
261     //Family(const Family&);
262     
263     // do not allow copy
264     Family& operator=(const Family&);
265     
266     // do not allow operator ==
267     bool operator==(const Family&); 
268     
269 }; // class Family
270
271
272 //*****************************************************************************
273 // Class Group
274 //*****************************************************************************
275
276 class Group
277 {
278 public:
279
280     /** 
281      * Builds an empty group (default constructor).
282      */
283     Group();
284     
285     /**
286      * Destructor. Removes everything.
287      */
288     ~Group();
289     
290     /**
291      * Resets this object in its state by default (empty). Cleans memory.
292      */
293     void reset();
294     
295     //---------------------------------------------------------------------
296     // Basic accessors/mutators
297     //---------------------------------------------------------------------
298     
299     /**
300      * Returns true if it is a group of nodes, false if it is a group of elements.
301      * \return true if it is a group of nodes, false if it is a group of elements.
302      */
303     bool isGroupOfNodes() const { return mIsGroupOfNodes; }
304     
305     /**
306      * Sets whether it is a group of nodes or a group of elements. 
307      * \param  pIsGroupOfNodes true for a group of nodes, false for a group of elements.
308      */
309     void setIsGroupOfNodes(bool pIsGroupOfNodes) { mIsGroupOfNodes = pIsGroupOfNodes; }
310     
311     /**
312      * Returns the name of this Group.
313      * \return the name of this Group.
314      */
315     const std::string& getName() const { return mName; }
316      
317     /**
318      * Sets the name of this Group.
319      * \param  pName new name of this Group (length of name must not exceed MED_TAILLE_LNOM).
320      */
321     void setName(const std::string& pName);
322     
323     /**
324      * Adds the index of a new element to this Group.
325      * \param  pIndexElt must be >= 1.
326      * \param pMeshIndex The index of the mesh type.
327      */
328     void insertElt(med_int pIndexElt, eMeshType pMeshIndex);
329     
330     /**
331      * Set a complete set of elements.
332      * \param pMeshIndex The index of the mesh type.
333      * \param pSetOfElt The set of elements.
334      */
335     void setSetOfElt(eMeshType pMeshIndex, const std::set<med_int>& pSetOfElt) { mElt[pMeshIndex] = pSetOfElt; };
336     
337     /**
338      * Returns the set of all the elements referenced in this Group.
339      * \return the set of all the elements referenced in this Group.
340      */
341     const std::set<med_int>& getSetOfElt(eMeshType pMeshIndex) const { return mElt[pMeshIndex]; }
342     
343     /**
344      * Returns the number of elements referenced in this Group.
345      * \return the number of elements referenced in this Group.
346      */
347     int getSize(eMeshType pMeshIndex) const { return mElt[pMeshIndex].size(); }
348         
349     //---------------------------------------------------------------------
350     // I/O
351     //---------------------------------------------------------------------
352     
353     /**
354      * Sets the flag which control the stream operator <<.
355      * \param  pFlag new flag value.
356      */
357     void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } 
358     
359     /**
360      * Dumps any Group to the given output stream.
361      * \param  pOs any output stream.
362      * \param  pG  any Group.
363      * \return the output stream pOs.
364      */
365     friend std::ostream& operator<<(std::ostream& pOs, Group& pG);
366     
367 private:
368     
369     std::string        mName;            /**< Name of the group. */
370     std::set<med_int>  mElt[eMaxMedMesh];             /**< All elements of this group; each element is referenced by its index >= 1; each element is unique. */
371     bool               mIsGroupOfNodes;  /**< Is it a group of nodes or a group of elements? */
372     
373     bool               mFlagPrintAll;    /** Flag to control the behaviour of the stream operator <<. */
374         
375 private:
376
377     // do not allow copy constructor
378     Group(const Group&);
379     
380     // do not allow copy
381     Group& operator=(const Group&);
382     
383     // do not allow operator ==
384     bool operator==(const Group&); 
385     
386 }; // class Group
387
388
389 } // namespace MULTIPR
390
391
392 #endif // MULTIPR_FAMILY_HXX
393
394 // EOF