Salome HOME
3380d2f3ff4246a6cbcaf37d628964b711329264
[modules/geom.git] / src / GEOM / GEOM_Field.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef _GEOM_Field_HeaderFile
24 #define _GEOM_Field_HeaderFile
25
26 #include "GEOM_Object.hxx"
27
28 #include <list>
29
30
31 const int GEOM_FIELD_OBJTYPE      = 52; // same value #defined in GEOMImpl_Types.hxx
32 const int GEOM_FIELD_STEP_OBJTYPE = 53;
33
34 class GEOM_Field;
35 class GEOM_FieldStep;
36 DEFINE_STANDARD_HANDLE( GEOM_Field, GEOM_BaseObject );
37 DEFINE_STANDARD_HANDLE( GEOM_FieldStep, GEOM_BaseObject );
38
39
40
41 class GEOM_Field : public GEOM_BaseObject
42 {
43   GEOM_Field(const TDF_Label& theLabel);
44   friend class GEOM_Engine;
45
46  public:
47
48   // Function types
49   enum { FUN_ADD_FIELD = 1,
50          FUN_ADD_STEP,
51          FUN_CHANGE_COMP_NAMES,
52          //FUN_REMOVE_STEP,
53          FUN_CHANGE_STEP_STAMP,
54          FUN_CHANGE_VALUE
55   };
56
57   // Creates a GEOM_Field on an empty Label
58   Standard_EXPORT GEOM_Field(const TDF_Label& theLabel, int );
59   Standard_EXPORT ~GEOM_Field();
60
61   // Finds a GEOM_Field on theLabel
62   Standard_EXPORT static Handle(GEOM_Field) GetField(const TDF_Label& theLabel);
63
64   // Returns a GUID associated with a field object (GEOM_Field or GEOM_FieldStep)
65   // This GUID corresponds to GEOMImpl_FieldDriver::GetID() and
66   // it also marks TDataStd_TreeNode on a label of GEOM_FieldStep
67   Standard_EXPORT static const Standard_GUID& GetFieldID();
68
69   // Sets the basic data that do not change (except compNames?)
70   Standard_EXPORT void Init(const Handle(GEOM_Object)&                     theShape,
71                             const char*                                    theName,
72                             const int                                      theDataType,
73                             const int                                      theDimension,
74                             const Handle(TColStd_HArray1OfExtendedString)& theCompNames);
75
76   // Returns a shape this GEOM_Field lies on
77   Standard_EXPORT Handle(GEOM_Object) GetShape();
78
79   // Returns a data type of this GEOM_Field
80   // 0 - bool, 1 - int, 2 - double, 3 - string
81   Standard_EXPORT int GetDataType();
82
83   // Returns one of "Bool","Int","Double","String"
84   Standard_EXPORT static TCollection_AsciiString GetDataTypeString(int type);
85
86   // Returns dimension of the shape the field lies on:
87   // 0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
88   Standard_EXPORT int GetDimension();
89
90   // Sets names of components
91   Standard_EXPORT void SetComponents( const Handle(TColStd_HArray1OfExtendedString)& compNames );
92
93   // Returns names of components
94   Standard_EXPORT Handle(TColStd_HArray1OfExtendedString) GetComponents();
95
96   // Returns names of components in a python syntax
97   Standard_EXPORT TCollection_AsciiString GetComponentsForPython();
98
99   // Returns number of components
100   Standard_EXPORT int GetNbComponents();
101
102   // Returns number of sub-shapes.
103   // Size of data arrays == GetNbSubShapes() * GetComponents()->Extent()
104   Standard_EXPORT int GetNbSubShapes();
105
106   // Returns number of sub-shapes of given dimension
107   Standard_EXPORT static int GetNbSubShapes(const Handle(GEOM_Object)& shape,
108                                             const int                  dim);
109
110   // Returns size of data array == GetNbSubShapes() * GetComponents()->Extent()
111   Standard_EXPORT int GetArrayLength();
112
113   // Removes a component. Number counts from one.
114   //Standard_EXPORT void RemoveComponent(const int number);
115
116   // Adds a step
117   Standard_EXPORT Handle(GEOM_FieldStep) AddStep(const int stepID, const int stamp);
118
119   // Removes a step
120   Standard_EXPORT void RemoveStep(const int stepID);
121
122   // Returns a step
123   Standard_EXPORT Handle(GEOM_FieldStep) GetStep(const int stepID);
124  
125   // Returns all steps
126   Standard_EXPORT std::list< Handle(GEOM_FieldStep)> GetSteps();
127
128   DEFINE_STANDARD_RTTI( GEOM_Field );
129
130 private:
131
132   int nbSubShapes; // not to explode the shape each time nbSubShapes is needed
133 };
134
135
136 class GEOM_FieldStep : public GEOM_BaseObject
137 {
138   GEOM_FieldStep(const TDF_Label& theLabel);
139   friend class GEOM_Engine;
140
141 public:
142   // Creates a GEOM_FieldStep on an empty Label
143   Standard_EXPORT GEOM_FieldStep(const TDF_Label& theLabel, int );
144   Standard_EXPORT ~GEOM_FieldStep();
145
146   // Sets the basic data
147   Standard_EXPORT void Init(const Handle(GEOM_Field)& theField,
148                             const int                 theID,
149                             const int                 theStamp);
150
151   // Finds a GEOM_FieldStep on the label theLabel
152   Standard_EXPORT static Handle(GEOM_FieldStep) GetFieldStep(const TDF_Label& theLabel);
153
154   // Returns the Field this GEOM_FieldStep belongs to
155   Standard_EXPORT Handle(GEOM_Field) GetField();
156
157   // Returns the stamp step id
158   Standard_EXPORT int GetID();
159
160   // Removes a component. Number counts from one.
161   //Standard_EXPORT void RemoveComponent(const int number);
162
163   // Sets the stamp of the step
164   Standard_EXPORT void SetStamp(const int stamp);
165
166   // Returns the stamp of the step
167   Standard_EXPORT int GetStamp();
168
169   // Sets int or bool values. Returns false if number of values is wrong
170   Standard_EXPORT bool SetValues( const Handle(TColStd_HArray1OfInteger)& values );
171
172   // Sets double values. Returns false if number of values is wrong
173   Standard_EXPORT bool SetValues( const Handle(TColStd_HArray1OfReal)& values );
174
175   // Sets string values. Returns false if number of values is wrong
176   Standard_EXPORT bool SetValues( const Handle(TColStd_HArray1OfExtendedString)& values );
177
178   // Returns int or bool values
179   Standard_EXPORT Handle(TColStd_HArray1OfInteger) GetIntValues();
180
181   // Returns double values
182   Standard_EXPORT Handle(TColStd_HArray1OfReal) GetDoubleValues();
183
184   // Returns string values
185   Standard_EXPORT Handle(TColStd_HArray1OfExtendedString) GetStringValues();
186
187   // Returns GUID of CAF data array
188   const Standard_GUID& GetDataID();
189
190
191
192   DEFINE_STANDARD_RTTI( GEOM_FieldStep );
193
194 private:
195
196   Handle(GEOM_Function) getFunctionToSetValuesAndDump(const TCollection_AsciiString& valueStr);
197
198 };
199
200
201 #endif