Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / Model / Model_AttributeTables.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_AttributeTables.h
4 // Created:     14 Nov 2016
5 // Author:      Mikhail Ponikarov
6
7 #ifndef Model_AttributeTables_H_
8 #define Model_AttributeTables_H_
9
10 #include "Model.h"
11
12 #include <ModelAPI_AttributeTables.h>
13
14 #include <TDF_Label.hxx>
15 #include <TDataStd_IntegerList.hxx>
16
17 #include <string>
18
19 /// \class Model_AttributeTables
20 /// \ingroup DataModel
21 /// \brief API for the attribute that contains tables of some values type.
22 ///
23 /// The type of values can be changed. But all the values in the tables must have the same one
24 /// type. The currently allowed types now are: Boolean, Integer, Double, String.
25 /// By default there is only one table, but it may be increased/decreased by adding/removing 
26 /// tables one by one.
27 /// The number of rows and columns are equal in all tables. If table, row or column is added,
28 /// the previous values are kept unchanged. New cells are filled by zero, false or empty strings.
29 class Model_AttributeTables: public ModelAPI_AttributeTables
30 {
31 public:
32   /// Returns the number of rows in the table
33   MODEL_EXPORT virtual int rows();
34   /// Returns the number of columns in the table
35   MODEL_EXPORT virtual int columns();
36   /// Returns the number of tables
37   MODEL_EXPORT virtual int tables();
38
39   /// Sets the new size of the tables set. This method tries to keep old values if number of
40   /// rows, columns or tables is increased.
41   MODEL_EXPORT virtual void setSize(
42     const int theRows, const int theColumns, const int theTables = 1);
43
44   /// Defines the tyoe of values in the table. If it differs from the current, erases the content.
45   MODEL_EXPORT virtual void setType(ValueType theType);
46   /// Defines the tyoe of values in the table. If it differs from the current, erases the content.
47   MODEL_EXPORT virtual const ValueType& type() const;
48   /// Defines the value by the index in the tables set (indexes are zero-based).
49   MODEL_EXPORT virtual void setValue(
50     const Value theValue, const int theRow, const int theColumn, const int theTable = 0);
51   /// Returns the value by the index (indexes are zero-based).
52   MODEL_EXPORT virtual Value value(
53     const int theRow, const int theColumn, const int theTable = 0);
54
55 protected:
56   /// Objects are created for features automatically
57   MODEL_EXPORT Model_AttributeTables(TDF_Label& theLabel);
58   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
59   virtual void reinit();
60
61 private:
62   /// The OCCT array that keeps all values. Indexes are computed as:
63   /// TableNum * NbRows * NbColumns + RowNum * NbColumns + ColNum
64   //Handle_TDF_Attribute myArray;
65
66   /// Container that stores properties of the tables set: type, nbtables, nbrows, nbcolumns
67   /// If sizes are zero, myArray IsNull and vice-versa
68   Handle_TDataStd_IntegerList myProp;
69
70   /// cashed main properties
71   int myTables, myRows, myCols;
72   /// cashed main properties
73   ModelAPI_AttributeTables::ValueType myType;
74
75   /// Stores the label as a field
76   TDF_Label myLab;
77
78   friend class Model_Data;
79 };
80
81 #endif