Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModelAPI / ModelAPI_AttributeTables.h
1 // Copyright (C) 2014-2017  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, 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModelAPI_AttributeTables_H_
22 #define ModelAPI_AttributeTables_H_
23
24 #include <ModelAPI.h>
25 #include <ModelAPI_Attribute.h>
26
27 #include <string>
28
29 /// \class ModelAPI_AttributeTables
30 /// \ingroup DataModel
31 /// \brief API for the attribute that contains tables of some values type.
32 ///
33 /// The type of values can be changed. But all the values in the tables must have the same one
34 /// type. The currently allowed types now are: Boolean, Integer, Double, String.
35 /// By default there is only one table, but it may be increased/decreased by adding/removing
36 /// tables one by one.
37 /// The number of rows and columns are equal in all tables. If table, row or column is added,
38 /// the previous values are kept unchanged. New cells are filled by zero, false or empty strings.
39 class ModelAPI_AttributeTables: public ModelAPI_Attribute
40 {
41 public:
42   /// Type of the value in the table
43   enum ValueType {
44     BOOLEAN,
45     INTEGER,
46     DOUBLE,
47     STRING
48   };
49
50   struct Value {
51     bool myBool;
52     int myInt;
53     double myDouble;
54     std::string myStr;
55   };
56
57   /// Returns the number of rows in the table
58   MODELAPI_EXPORT virtual int rows() = 0;
59   /// Returns the number of columns in the table
60   MODELAPI_EXPORT virtual int columns() = 0;
61   /// Returns the number of tables
62   MODELAPI_EXPORT virtual int tables() = 0;
63
64   /// Sets the new size of the tables set. This method tries to keep old values if number of
65   /// rows, columns or tables is increased.
66   MODELAPI_EXPORT virtual void setSize(
67     const int theRows, const int theColumns, const int theTables = 1) = 0;
68
69   /// Defines the tyoe of values in the table. If it differs from the current, erases the content.
70   MODELAPI_EXPORT virtual void setType(ValueType theType) = 0;
71   /// Defines the tyoe of values in the table. If it differs from the current, erases the content.
72   MODELAPI_EXPORT virtual const ValueType& type() const = 0;
73   /// Defines the value by the index in the tables set (indexes are zero-based).
74   MODELAPI_EXPORT virtual void setValue(
75     const Value theValue, const int theRow, const int theColumn, const int theTable = 0) = 0;
76   /// Returns the value by the index (indexes are zero-based).
77   MODELAPI_EXPORT virtual Value value(
78     const int theRow, const int theColumn, const int theTable = 0) = 0;
79
80   /// Returns the value in the format of string (usefull for the python connection)
81   MODELAPI_EXPORT virtual std::string valueStr(
82     const int theRow, const int theColumn, const int theTable = 0) = 0;
83
84   /// Returns the type of this class of attributes
85   MODELAPI_EXPORT static std::string typeId()
86   {
87     return "Tables";
88   }
89   /// Returns the type of this class of attributes, not static method
90   MODELAPI_EXPORT virtual std::string attributeType();
91   /// To virtually destroy the fields of successors
92   MODELAPI_EXPORT virtual ~ModelAPI_AttributeTables();
93
94 protected:
95   /// Objects are created for features automatically
96   MODELAPI_EXPORT ModelAPI_AttributeTables();
97 };
98
99 /// Pointer on double attribute
100 typedef std::shared_ptr<ModelAPI_AttributeTables> AttributeTablesPtr;
101
102 #endif