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