Salome HOME
Issue #2027 Modification of data strtucture outside of transaction when create circle...
[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   /// Returns the value in the format of string (usefull for the python connection)
56   MODEL_EXPORT virtual std::string valueStr(
57     const int theRow, const int theColumn, const int theTable = 0);
58
59 protected:
60   /// Objects are created for features automatically
61   MODEL_EXPORT Model_AttributeTables(TDF_Label& theLabel);
62   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
63   virtual void reinit();
64
65 private:
66   /// The OCCT array that keeps all values. Indexes are computed as:
67   /// TableNum * NbRows * NbColumns + RowNum * NbColumns + ColNum
68   //Handle_TDF_Attribute myArray;
69
70   /// Container that stores properties of the tables set: type, nbtables, nbrows, nbcolumns
71   /// If sizes are zero, myArray IsNull and vice-versa
72   Handle_TDataStd_IntegerList myProp;
73
74   /// cashed main properties
75   int myTables, myRows, myCols;
76   /// cashed main properties
77   ModelAPI_AttributeTables::ValueType myType;
78
79   /// Stores the label as a field
80   TDF_Label myLab;
81
82   friend class Model_Data;
83 };
84
85 #endif