Salome HOME
Fix a bug that NbShapes() and ShapeInfo() return 2 solids for a box
[modules/geom.git] / src / XAO / XAO_Xao.hxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
20
21 #ifndef __XAO_XAO_HXX__
22 #define __XAO_XAO_HXX__
23
24 #include <string>
25 #include <list>
26 #include "XAO_Exception.hxx"
27 #include "XAO_XaoUtils.hxx"
28 #include "XAO_Geometry.hxx"
29
30 namespace XAO
31 {
32     class Group;
33     class Field;
34     class IntegerField;
35     class DoubleField;
36     class BooleanField;
37     class StringField;
38
39     /**
40      * @class Xao
41      * The Xao class describes the XAO format.
42      */
43     class Xao
44     {
45     public:
46         /**
47          * Default constructor.
48          */
49         Xao();
50         /**
51          * Constructor with author and version.
52          * \param author the author of the file.
53          * \param version the version of the XAO format.
54          */
55         Xao(const std::string& author, const std::string& version);
56         /**
57          * Destructor.
58          */
59         virtual ~Xao();
60
61         /**
62          * Gets the author of the file.
63          * \return the author of the file.
64          */
65         const std::string getAuthor() const
66         {
67             return m_author;
68         }
69         /**
70          * Sets the author of the file.
71          * \param author the author to set.
72          */
73         void setAuthor(const std::string& author)
74         {
75             m_author = author;
76         }
77
78         /**
79          * Gets the version of the file.
80          * \return the version of the file.
81          */
82         const std::string getVersion() const
83         {
84             return m_version;
85         }
86         /**
87          * Sets the version of the file.
88          * \param version the version to set.
89          */
90         void setVersion(const std::string& version)
91         {
92             m_version = version;
93         }
94
95         //
96         // Geometry
97         //
98
99         /**
100          * Gets the geometry.
101          * \return the geometry.
102          */
103         Geometry* getGeometry() const
104         {
105             return m_geometry;
106         }
107         /**
108          * Sets the geometry.
109          * \param geometry the geometry to set.
110          */
111         void setGeometry(Geometry* geometry) throw (XAO_Exception)
112         {
113             if (m_geometry != NULL)
114                 throw XAO_Exception("Geometry already set.");
115             m_geometry = geometry;
116             m_geometry->setReadOnly();
117         }
118
119         //
120         // Groups
121         //
122
123         /**
124          * Gets the number of groups.
125          * \return the number of groups.
126          */
127         const int countGroups() const;
128         /**
129          * Gets a group.
130          * \param index the index of the wanted group.
131          * \return the group.
132          */
133         Group* getGroup(const int& index) throw (XAO_Exception);
134         /**
135          * Adds a group.
136          * \param dim the dimension of the group.
137          * \param name the name of the group.
138          * \return the created group.
139          */
140         Group* addGroup(const XAO::Dimension& dim, const std::string& name = std::string("")) throw (XAO_Exception);
141         /**
142          * Removes a group.
143          * \param group the group to remove.
144          * \return true if the group has been removed, false otherwise.
145          */
146         bool removeGroup(Group* group);
147
148         //
149         // Fields
150         //
151
152         /**
153          * Gets the number of fields.
154          * \return the number of fields.
155          */
156         const int countFields() const;
157
158         /**
159          * Gets the type of a field.
160          * \param index the index of the wanted field.
161          * \return the type of the field.
162          */
163         const XAO::Type getFieldType(const int& index) throw (XAO_Exception);
164
165         /**
166          * Gets a field.
167          * \param index the index of the wanted field.
168          * \return the field.
169          */
170         Field* getField(const int& index) throw (XAO_Exception);
171
172         BooleanField* getBooleanField(const int& index) throw (XAO_Exception);
173         DoubleField* getDoubleField(const int& index) throw (XAO_Exception);
174         IntegerField* getIntegerField(const int& index) throw (XAO_Exception);
175         StringField* getStringField(const int& index) throw (XAO_Exception);
176
177         /**
178          * Adds a field.
179          * \param type the type of the field.
180          * \param dim the dimension of the field.
181          * \param nbComponents the number of components in the field.
182          * \param name the name of the field.
183          * \return the created field.
184          */
185         Field* addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents,
186                 const std::string& name = std::string(""))
187         throw (XAO_Exception);
188
189         BooleanField* addBooleanField(const XAO::Dimension& dim, const int& nbComponents,
190                 const std::string& name = std::string("")) throw (XAO_Exception);
191         IntegerField* addIntegerField(const XAO::Dimension& dim, const int& nbComponents,
192                 const std::string& name = std::string("")) throw (XAO_Exception);
193         DoubleField* addDoubleField(const XAO::Dimension& dim, const int& nbComponents,
194                 const std::string& name = std::string("")) throw (XAO_Exception);
195         StringField* addStringField(const XAO::Dimension& dim, const int& nbComponents,
196                 const std::string& name = std::string("")) throw (XAO_Exception);
197
198         /**
199          * Removes a field.
200          * \param field the field to remove.
201          * \return true if the field has been removed, false otherwise.
202          */
203         bool removeField(Field* field);
204
205         //
206         // Import / Export
207         //
208         /**
209          * Exports this XAO object to a file.
210          * \param fileName the name of the file to create.
211          * \return true is the export is successful.
212          */
213         const bool exportXAO(const std::string& fileName);
214         /**
215          * Gets the XML corresponding to this XAO.
216          * \return the XML as a string.
217          */
218         const std::string getXML();
219
220         /**
221          * Imports an XAO file into this object.
222          * \param fileName the name of the file to import.
223          * \return true if the import is successful.
224          */
225         const bool importXAO(const std::string& fileName);
226         /**
227          * Sets an XML describing an XAO format to this object.
228          * \param xml the XML to set.
229          * \return true if the import is successful.
230          */
231         const bool setXML(const std::string& xml);
232
233     private:
234         void checkGeometry() const throw (XAO_Exception);
235         void checkGroupIndex(const int& index) const throw (XAO_Exception);
236         void checkFieldIndex(const int& index) const throw (XAO_Exception);
237         void checkGroupDimension(const XAO::Dimension& dim) const throw (XAO_Exception);
238
239     private:
240         /** The author of the file. */
241         std::string m_author;
242         /** The version of the file. */
243         std::string m_version;
244         /** The geometry. */
245         Geometry* m_geometry;
246         /** The list of groups. */
247         std::list<Group*> m_groups;
248         /** The list of fields. */
249         std::list<Field*> m_fields;
250     };
251
252 }
253
254 #endif