Salome HOME
8399ff900d520f0c48c07b59f639501c81e6b9a0
[modules/geom.git] / src / XAO / XAO_Xao.hxx
1 // Copyright (C) 2013-2023  CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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
27 #include "XAO.hxx"
28 #include "XAO_Exception.hxx"
29 #include "XAO_XaoUtils.hxx"
30 #include "XAO_Geometry.hxx"
31
32 #ifdef WIN32
33 #pragma warning(disable:4290) // Warning Exception ...
34 #pragma warning(disable:4251) // Warning dll-interface ...
35 #endif
36
37 namespace XAO
38 {
39     class Group;
40     class Field;
41     class IntegerField;
42     class DoubleField;
43     class BooleanField;
44     class StringField;
45
46     /**
47      * @class Xao
48      * The Xao class describes the XAO format.
49      */
50     class XAO_EXPORT Xao
51     {
52     public:
53         /**
54          * Default constructor.
55          */
56         Xao();
57         /**
58          * Constructor with author and version.
59          * \param author the author of the file.
60          * \param version the version of the XAO format.
61          */
62         Xao(const std::string& author, const std::string& version);
63         /**
64          * Destructor.
65          */
66         virtual ~Xao();
67
68         /**
69          * Gets the author of the file.
70          * \return the author of the file.
71          */
72         const std::string getAuthor() const
73         {
74             return m_author;
75         }
76         /**
77          * Sets the author of the file.
78          * \param author the author to set.
79          */
80         void setAuthor(const std::string& author)
81         {
82             m_author = author;
83         }
84
85         /**
86          * Gets the version of the file.
87          * \return the version of the file.
88          */
89         const std::string getVersion() const
90         {
91             return m_version;
92         }
93         /**
94          * Sets the version of the file.
95          * \param version the version to set.
96          */
97         void setVersion(const std::string& version)
98         {
99             m_version = version;
100         }
101
102         //
103         // Geometry
104         //
105
106         /**
107          * Gets the geometry.
108          * \return the geometry.
109          */
110         Geometry* getGeometry() const
111         {
112             return m_geometry;
113         }
114         /**
115          * Sets the geometry.
116          * \param geometry the geometry to set.
117          */
118         void setGeometry(Geometry* geometry) 
119         {
120             if (m_geometry != NULL)
121                 throw XAO_Exception("Geometry already set.");
122             m_geometry = geometry;
123             m_geometry->setReadOnly();
124         }
125
126         //
127         // Groups
128         //
129
130         /**
131          * Gets the number of groups.
132          * \return the number of groups.
133          */
134         int countGroups() const;
135         /**
136          * Gets a group.
137          * \param index the index of the wanted group.
138          * \return the group.
139          */
140         Group* getGroup(int index) ;
141         /**
142          * Adds a group.
143          * \param dim the dimension of the group.
144          * \param name the name of the group.
145          * \return the created group.
146          */
147         Group* addGroup(XAO::Dimension dim, const std::string& name = std::string("")) ;
148         /**
149          * Removes a group.
150          * \param group the group to remove.
151          * \return true if the group has been removed, false otherwise.
152          */
153         bool removeGroup(Group* group);
154
155         //
156         // Fields
157         //
158
159         /**
160          * Gets the number of fields.
161          * \return the number of fields.
162          */
163         int countFields() const;
164
165         /**
166          * Gets the type of a field.
167          * \param index the index of the wanted field.
168          * \return the type of the field.
169          */
170         XAO::Type getFieldType(int index) ;
171
172         /**
173          * Gets a field.
174          * \param index the index of the wanted field.
175          * \return the field.
176          */
177         Field* getField(int index) ;
178
179         BooleanField* getBooleanField(int index) ;
180         DoubleField* getDoubleField(int index) ;
181         IntegerField* getIntegerField(int index) ;
182         StringField* getStringField(int index) ;
183
184         /**
185          * Adds a field.
186          * \param type the type of the field.
187          * \param dim the dimension of the field.
188          * \param nbComponents the number of components in the field.
189          * \param name the name of the field.
190          * \return the created field.
191          */
192         Field* addField(XAO::Type type, XAO::Dimension dim, int nbComponents,
193                 const std::string& name = std::string(""))
194         ;
195
196         BooleanField* addBooleanField(XAO::Dimension dim, int nbComponents,
197                 const std::string& name = std::string("")) ;
198         IntegerField* addIntegerField(XAO::Dimension dim, int nbComponents,
199                 const std::string& name = std::string("")) ;
200         DoubleField* addDoubleField(XAO::Dimension dim, int nbComponents,
201                 const std::string& name = std::string("")) ;
202         StringField* addStringField(XAO::Dimension dim, int nbComponents,
203                 const std::string& name = std::string("")) ;
204
205         /**
206          * Removes a field.
207          * \param field the field to remove.
208          * \return true if the field has been removed, false otherwise.
209          */
210         bool removeField(Field* field);
211
212         //
213         // Import / Export
214         //
215         /**
216          * Exports this XAO object to a file.
217          * \param fileName the name of the file to create.
218          * \param shapeFileName if not empty, export the shape to this external file.
219          * \return true is the export is successful.
220          */
221         bool exportXAO(const std::string& fileName, const std::string& shapeFileName);
222         /**
223          * Gets the XML corresponding to this XAO.
224          * \return the XML as a string.
225          */
226         const std::string getXML();
227
228         /**
229          * Imports an XAO file into this object.
230          * \param fileName the name of the file to import.
231          * \return true if the import is successful.
232          */
233         bool importXAO(const std::string& fileName);
234         /**
235          * Sets an XML describing an XAO format to this object.
236          * \param xml the XML to set.
237          * \return true if the import is successful.
238          */
239         bool setXML(const std::string& xml);
240
241     private:
242         void checkGeometry() const ;
243         void checkGroupIndex(int index) const ;
244         void checkFieldIndex(int index) const ;
245         void checkGroupDimension(XAO::Dimension dim) const ;
246
247     private:
248         /** The author of the file. */
249         std::string m_author;
250         /** The version of the file. */
251         std::string m_version;
252         /** The geometry. */
253         Geometry* m_geometry;
254         /** The list of groups. */
255         std::list<Group*> m_groups;
256         /** The list of fields. */
257         std::list<Field*> m_fields;
258     };
259
260 }
261
262 #endif