1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
5 * \file MULTIPR_Family.hxx
7 * \brief Class Family, Group and Attributs used to wrap MED file structures.
9 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
14 #ifndef MULTIPR_FAMILY_HXX
15 #define MULTIPR_FAMILY_HXX
17 //*****************************************************************************
19 //*****************************************************************************
32 #include "MULTIPR_Mesh.hxx"
37 //*****************************************************************************
39 //*****************************************************************************
44 //*****************************************************************************
46 //*****************************************************************************
53 * Builds an empty Attributs (default constructor).
58 * Destructor. Removes everything.
63 * Assignment operator (deep copy).
64 * \param pAttr any Atttibuts to be copied.
65 * \return a reference towards the copy.
67 Attributs& operator=(const Attributs& pAttr);
70 * Resets this object in its state by default (empty). Cleans memory.
74 //---------------------------------------------------------------------
76 //---------------------------------------------------------------------
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.
84 friend std::ostream& operator<<(std::ostream& pOs, Attributs& pA);
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. */
95 // do not allow copy constructor
96 Attributs(const Attributs&);
98 // do not allow operator ==
99 bool operator==(const Attributs&);
104 //*****************************************************************************
106 //*****************************************************************************
113 * Builds an empty Family (default constructor).
120 Family(const Family& pFamily);
123 * Destructor. Removes everything.
128 * Resets this object in its state by default (empty). Cleans memory.
132 //---------------------------------------------------------------------
133 // Basic accessors/mutators
134 //---------------------------------------------------------------------
137 * Returns the identifier (= number) of this Family.
138 * \return the identifier of this Family.
140 med_int getId() const { return mId; }
143 * Set the identifier of this family.
144 * \param pId The identifier.
146 void setId(med_int pId) { mId = pId; };
149 * Returns the name of this Family.
150 * \return the name of this Family.
152 const char* getName() const { return mName; }
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.
158 bool isFamilyOfNodes() const { return mIsFamilyOfNodes; }
161 * Sets whether this Family is a family of nodes or family of elements (= cells).
162 * \param pIsFamilyOfNodes flag.
164 void setIsFamilyOfNodes(bool pIsFamilyOfNodes) { mIsFamilyOfNodes = pIsFamilyOfNodes; }
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.
172 void insertElt(med_int pIndexElt, eMeshType pMeshIndex = eMED_POINT1);
175 * Returns the number of elements in this Family.
176 * \return the number of elements in this Family.
178 int getSize(eMeshType pMeshIndex = eMED_POINT1) const { return mElt[pMeshIndex].size(); }
180 //---------------------------------------------------------------------
182 //---------------------------------------------------------------------
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.
190 std::vector<Group*>& pGroups,
191 std::map<std::string, Group*>& pGroupNameToGroup) const;
194 * Constructor. Returns a copy of this family restricted to the given group if pGroupName != NULL.
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.
202 Family* extractGroup(const char* pGroupName);
205 * Returns the set of all the elements referenced in this Family.
206 * \return the set of all the elements referenced in this Family.
208 const std::set<med_int>& getSetOfElt(eMeshType pMeshIndex) const { return mElt[pMeshIndex]; }
210 //---------------------------------------------------------------------
212 //---------------------------------------------------------------------
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.
221 void readMED(med_idt pMEDfile, char* pMeshName, med_int pIndex);
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.
230 void writeMED(med_idt pMEDfile, char* pMeshName);
233 * Sets the flag which control the stream operator <<.
234 * \param pFlag new flag value.
236 void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; }
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.
244 friend std::ostream& operator<<(std::ostream& pOs, Family& pF);
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? */
256 bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */
260 // do not allow copy constructor
261 //Family(const Family&);
264 Family& operator=(const Family&);
266 // do not allow operator ==
267 bool operator==(const Family&);
272 //*****************************************************************************
274 //*****************************************************************************
281 * Builds an empty group (default constructor).
286 * Destructor. Removes everything.
291 * Resets this object in its state by default (empty). Cleans memory.
295 //---------------------------------------------------------------------
296 // Basic accessors/mutators
297 //---------------------------------------------------------------------
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.
303 bool isGroupOfNodes() const { return mIsGroupOfNodes; }
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.
309 void setIsGroupOfNodes(bool pIsGroupOfNodes) { mIsGroupOfNodes = pIsGroupOfNodes; }
312 * Returns the name of this Group.
313 * \return the name of this Group.
315 const std::string& getName() const { return mName; }
318 * Sets the name of this Group.
319 * \param pName new name of this Group (length of name must not exceed MED_TAILLE_LNOM).
321 void setName(const std::string& pName);
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.
328 void insertElt(med_int pIndexElt, eMeshType pMeshIndex);
331 * Set a complete set of elements.
332 * \param pMeshIndex The index of the mesh type.
333 * \param pSetOfElt The set of elements.
335 void setSetOfElt(eMeshType pMeshIndex, const std::set<med_int>& pSetOfElt) { mElt[pMeshIndex] = pSetOfElt; };
338 * Returns the set of all the elements referenced in this Group.
339 * \return the set of all the elements referenced in this Group.
341 const std::set<med_int>& getSetOfElt(eMeshType pMeshIndex) const { return mElt[pMeshIndex]; }
344 * Returns the number of elements referenced in this Group.
345 * \return the number of elements referenced in this Group.
347 int getSize(eMeshType pMeshIndex) const { return mElt[pMeshIndex].size(); }
349 //---------------------------------------------------------------------
351 //---------------------------------------------------------------------
354 * Sets the flag which control the stream operator <<.
355 * \param pFlag new flag value.
357 void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; }
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.
365 friend std::ostream& operator<<(std::ostream& pOs, Group& pG);
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? */
373 bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */
377 // do not allow copy constructor
381 Group& operator=(const Group&);
383 // do not allow operator ==
384 bool operator==(const Group&);
389 } // namespace MULTIPR
392 #endif // MULTIPR_FAMILY_HXX