Salome HOME
9f9b4ac4de85c03ce767a277cf4cfac41bd362ff
[modules/shaper.git] / src / Model / Model_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 Model_AttributeTables_H_
21 #define Model_AttributeTables_H_
22
23 #include "Model.h"
24
25 #include <ModelAPI_AttributeTables.h>
26
27 #include <TDF_Label.hxx>
28 #include <TDataStd_IntegerList.hxx>
29
30 #include <string>
31
32 /// \class Model_AttributeTables
33 /// \ingroup DataModel
34 /// \brief API for the attribute that contains tables of some values type.
35 ///
36 /// The type of values can be changed. But all the values in the tables must have the same one
37 /// type. The currently allowed types now are: Boolean, Integer, Double, String.
38 /// By default there is only one table, but it may be increased/decreased by adding/removing
39 /// tables one by one.
40 /// The number of rows and columns are equal in all tables. If table, row or column is added,
41 /// the previous values are kept unchanged. New cells are filled by zero, false or empty strings.
42 class Model_AttributeTables: public ModelAPI_AttributeTables
43 {
44 public:
45   /// Returns the number of rows in the table
46   MODEL_EXPORT virtual int rows();
47   /// Returns the number of columns in the table
48   MODEL_EXPORT virtual int columns();
49   /// Returns the number of tables
50   MODEL_EXPORT virtual int tables();
51
52   /// Sets the new size of the tables set. This method tries to keep old values if number of
53   /// rows, columns or tables is increased.
54   MODEL_EXPORT virtual void setSize(
55     const int theRows, const int theColumns, const int theTables = 1);
56
57   /// Defines the tyoe of values in the table. If it differs from the current, erases the content.
58   MODEL_EXPORT virtual void setType(ValueType theType);
59   /// Defines the tyoe of values in the table. If it differs from the current, erases the content.
60   MODEL_EXPORT virtual const ValueType& type() const;
61   /// Defines the value by the index in the tables set (indexes are zero-based).
62   MODEL_EXPORT virtual void setValue(
63     const Value theValue, const int theRow, const int theColumn, const int theTable = 0);
64   /// Returns the value by the index (indexes are zero-based).
65   MODEL_EXPORT virtual Value value(
66     const int theRow, const int theColumn, const int theTable = 0);
67
68   /// Returns the value in the format of string (usefull for the python connection)
69   MODEL_EXPORT virtual std::string valueStr(
70     const int theRow, const int theColumn, const int theTable = 0);
71
72 protected:
73   /// Objects are created for features automatically
74   MODEL_EXPORT Model_AttributeTables(TDF_Label& theLabel);
75   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
76   virtual void reinit();
77
78 private:
79   /// The OCCT array that keeps all values. Indexes are computed as:
80   /// TableNum * NbRows * NbColumns + RowNum * NbColumns + ColNum
81   //Handle_TDF_Attribute myArray;
82
83   /// Container that stores properties of the tables set: type, nbtables, nbrows, nbcolumns
84   /// If sizes are zero, myArray IsNull and vice-versa
85   Handle_TDataStd_IntegerList myProp;
86
87   /// cashed main properties
88   int myTables, myRows, myCols;
89   /// cashed main properties
90   ModelAPI_AttributeTables::ValueType myType;
91
92   /// Stores the label as a field
93   TDF_Label myLab;
94
95   friend class Model_Data;
96 };
97
98 #endif