vtkSMPropertyHelper.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) 2007, Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
23 #ifndef vtkSMPropertyHelper_h
24 #define vtkSMPropertyHelper_h
25 
26 #include "vtkRemotingServerManagerModule.h" //needed for exports
27 #include "vtkVariant.h" // for vtkVariant
28 
29 #include <vector> // for std::vector
30 
31 #ifdef INT
32 #undef INT
33 #endif
34 #ifdef DOUBLE
35 #undef DOUBLE
36 #endif
37 #ifdef NONE
38 #undef NONE
39 #endif
40 
43 class vtkSMInputProperty;
45 class vtkSMOutputPort;
46 class vtkSMProperty;
47 class vtkSMProxy;
48 class vtkSMProxyProperty;
51 
53 {
54 public:
56 
60  vtkSMPropertyHelper(vtkSMProxy* proxy, const char* name, bool quiet = false);
61  vtkSMPropertyHelper(vtkSMProperty* property, bool quiet = false);
64 
70  void UpdateValueFromServer();
71 
76  void SetNumberOfElements(unsigned int elems);
77 
82  unsigned int GetNumberOfElements() const;
83 
87  void RemoveAllValues() { this->SetNumberOfElements(0); }
88 
92  vtkVariant GetAsVariant(unsigned int index) const;
93 
98  template <class T>
99  std::vector<T> GetArray() const;
100 
105  template <class T>
106  T GetAs(unsigned int index = 0) const;
107 
109 
113  void Set(int value) { this->Set(0, value); }
114  void Set(unsigned int index, int value);
115  void Set(const int* values, unsigned int count);
116  void Append(const int* values, unsigned int count);
117  int GetAsInt(unsigned int index = 0) const;
118  unsigned int Get(int* values, unsigned int count = 1) const;
119  std::vector<int> GetIntArray() const;
121 
123 
127  void Set(double value) { this->Set(0, value); }
128  void Set(unsigned int index, double value);
129  void Set(const double* values, unsigned int count);
130  void Append(const double* values, unsigned int count);
131  double GetAsDouble(unsigned int index = 0) const;
132  unsigned int Get(double* values, unsigned int count = 1) const;
133  std::vector<double> GetDoubleArray() const;
135 
136 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
137 
142  void Set(vtkIdType value) { this->Set(0, value); }
143  void Set(unsigned int index, vtkIdType value);
144  void Set(const vtkIdType* values, unsigned int count);
145  void Append(const vtkIdType* values, unsigned int count);
146  unsigned int Get(vtkIdType* values, unsigned int count = 1) const;
147 #endif
148  vtkIdType GetAsIdType(unsigned int index = 0) const;
149  std::vector<vtkIdType> GetIdTypeArray() const;
151 
153 
160  void Set(const char* value) { this->Set(0, value); }
161  void Set(unsigned int index, const char* value);
162  const char* GetAsString(unsigned int index = 0) const;
164 
166 
171  void Set(vtkSMProxy* value, unsigned int outputport = 0) { this->Set(0, value, outputport); }
172  void Set(unsigned int index, vtkSMProxy* value, unsigned int outputport = 0);
173  void Set(vtkSMProxy** value, unsigned int count, unsigned int* outputports = nullptr);
174  void Add(vtkSMProxy* value, unsigned int outputport = 0);
175  void Remove(vtkSMProxy* value);
176  vtkSMProxy* GetAsProxy(unsigned int index = 0) const;
177  unsigned int GetOutputPort(unsigned int index = 0) const;
178  vtkSMOutputPort* GetAsOutputPort(unsigned int index = 0) const;
180 
182 
187  void SetStatus(const char* key, int value);
188  int GetStatus(const char* key, int default_value = 0) const;
190 
192 
197  void SetStatus(const char* key, double* values, int num_values);
198  bool GetStatus(const char* key, double* values, int num_values) const;
200 
202 
207  void SetStatus(int key, int* values, int num_values);
208  bool GetStatus(int key, int* values, int num_values) const;
210 
212 
217  void SetStatus(const char* key, const char* value);
218  const char* GetStatus(const char* key, const char* default_value) const;
220 
226  void RemoveStatus(const char* key);
227 
229 
234  void SetStatus(int key, int value);
235  int GetStatus(int key, int default_value = 0) const;
237 
239 
244  void SetInputArrayToProcess(int fieldAssociation, const char* arrayName);
245  int GetInputArrayAssociation() const;
246  const char* GetInputArrayNameToProcess() const;
248 
252  void SetUseUnchecked(bool val) { this->UseUnchecked = val; }
253  bool GetUseUnchecked() const { return this->UseUnchecked; }
254 
260  bool Copy(const vtkSMPropertyHelper& source);
261 
266  vtkSMPropertyHelper& Modified();
267 
268 protected:
269  void setUseUnchecked(bool useUnchecked) { this->UseUnchecked = useUnchecked; }
270 
271 private:
272  vtkSMPropertyHelper(const vtkSMPropertyHelper&) = delete;
273  void operator=(const vtkSMPropertyHelper&) = delete;
274  void Initialize(vtkSMProperty* property);
275 
276  template <typename T>
277  T GetProperty(unsigned int index) const;
278  template <typename T>
279  std::vector<T> GetPropertyArray() const;
280  template <typename T>
281  unsigned int GetPropertyArray(T* values, unsigned int count = 1) const;
282  template <typename T>
283  void SetProperty(unsigned int index, T value);
284  template <typename T>
285  void SetPropertyArray(const T* values, unsigned int count);
286  void SetPropertyArrayIdType(const vtkIdType* values, unsigned int count);
287  template <typename T>
288  void AppendPropertyArray(const T* values, unsigned int count);
289  template <typename T>
290  bool CopyInternal(const vtkSMPropertyHelper& source);
291 
292  enum PType
293  {
294  INT,
295  DOUBLE,
296  IDTYPE,
297  STRING,
298  PROXY,
299  INPUT,
300  NONE
301  };
302 
303  bool Quiet;
304  bool UseUnchecked;
305  vtkSMProxy* Proxy;
306  PType Type;
307 
308  union {
317  };
318 };
319 
320 template <>
321 inline std::vector<int> vtkSMPropertyHelper::GetArray() const
322 {
323  return this->GetIntArray();
324 }
325 
326 template <>
327 inline std::vector<double> vtkSMPropertyHelper::GetArray() const
328 {
329  return this->GetDoubleArray();
330 }
331 
332 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
333 template <>
334 inline std::vector<vtkIdType> vtkSMPropertyHelper::GetArray() const
335 {
336  return this->GetIdTypeArray();
337 }
338 #endif
339 
340 template <>
341 inline int vtkSMPropertyHelper::GetAs(unsigned int index) const
342 {
343  return this->GetAsInt(index);
344 }
345 
346 template <>
347 inline double vtkSMPropertyHelper::GetAs(unsigned int index) const
348 {
349  return this->GetAsDouble(index);
350 }
351 
352 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
353 template <>
354 inline vtkIdType vtkSMPropertyHelper::GetAs(unsigned int index) const
355 {
356  return this->GetAsIdType(index);
357 }
358 #endif
359 
360 #endif
361 
362 // VTK-HeaderTest-Exclude: vtkSMPropertyHelper.h
void Set(const char *value)
Set/Get methods for vtkSMStringVectorProperty.
vtkSMInputProperty * InputProperty
vtkSMDoubleVectorProperty * DoubleVectorProperty
property representing pointer(s) to vtkObject(s)
vtkSMProxyProperty * ProxyProperty
void setUseUnchecked(bool useUnchecked)
#define VTKREMOTINGSERVERMANAGER_EXPORT
property representing a vector of strings
vtkSMIdTypeVectorProperty * IdTypeVectorProperty
vtkSMStringVectorProperty * StringVectorProperty
superclass for all SM properties
void Set(vtkSMProxy *value, unsigned int outputport=0)
Set/Get methods for vtkSMProxyProperty or vtkSMInputProperty.
int vtkIdType
vtkSMVectorProperty * VectorProperty
void Set(double value)
Set/Get methods with double API.
property representing a vector of integers
abstract superclass for all vector properties
name
void RemoveAllValues()
Equivalent to SetNumberOfElements(0).
property representing a vector of integers
const int NONE
std::vector< T > GetArray() const
Templated method to call GetIntArray(), GetDoubleArray(), GetIdTypeArray().
vtkSMProperty * Property
T GetAs(unsigned int index=0) const
Templated method to call GetAsInt(), GetAsDouble(), GetAsIdType() Note, we only provide implementatio...
property representing a vector of doubles
source
void SetUseUnchecked(bool val)
Get/Set whether to use unchecked properties.
proxy for a VTK object(s) on a server
Definition: vtkSMProxy.h:140
reference for an output port of a vtkAlgorithm.
value
void Set(int value)
Set/Get methods with int API.
index
vtkSMIntVectorProperty * IntVectorProperty
proxy representing inputs to a filter
key
helper class to get/set property values.