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