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