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 
174 
177  void Set(vtkSMProxy* value, unsigned int outputport = 0) { this->Set(0, value, outputport); }
178 
180  void Set(unsigned int index, vtkSMProxy* value, unsigned int outputport = 0);
181 
183  void Set(vtkSMProxy** value, unsigned int count, unsigned int* outputports = nullptr);
184 
186  void Add(vtkSMProxy* value, unsigned int outputport = 0);
187 
189  void Remove(vtkSMProxy* value);
190 
192  bool Contains(const vtkSMProxy* value) const;
193 
195  vtkSMProxy* GetAsProxy(unsigned int index = 0) const;
196 
198  unsigned int GetOutputPort(unsigned int index = 0) const;
199 
201  vtkSMOutputPort* GetAsOutputPort(unsigned int index = 0) const;
203 
205 
210  void SetStatus(const char* key, int value);
211  int GetStatus(const char* key, int default_value = 0) const;
213 
215 
220  void SetStatus(const char* key, double* values, int num_values);
221  bool GetStatus(const char* key, double* values, int num_values) const;
223 
225 
230  void SetStatus(int key, int* values, int num_values);
231  bool GetStatus(int key, int* values, int num_values) const;
233 
235 
240  void SetStatus(const char* key, const char* value);
241  const char* GetStatus(const char* key, const char* default_value) const;
243 
249  void RemoveStatus(const char* key);
250 
252 
257  void SetStatus(int key, int value);
258  int GetStatus(int key, int default_value = 0) const;
260 
262 
267  void SetInputArrayToProcess(int fieldAssociation, const char* arrayName);
268  int GetInputArrayAssociation() const;
269  const char* GetInputArrayNameToProcess() const;
271 
275  void SetUseUnchecked(bool val) { this->UseUnchecked = val; }
276  bool GetUseUnchecked() const { return this->UseUnchecked; }
277 
283  bool Copy(const vtkSMPropertyHelper& source);
284 
289  vtkSMPropertyHelper& Modified();
290 
291 protected:
292  void setUseUnchecked(bool useUnchecked) { this->UseUnchecked = useUnchecked; }
293 
294 private:
295  vtkSMPropertyHelper(const vtkSMPropertyHelper&) = delete;
296  void operator=(const vtkSMPropertyHelper&) = delete;
297  void Initialize(vtkSMProperty* property);
298 
299  template <typename T>
300  T GetProperty(unsigned int index) const;
301  template <typename T>
302  std::vector<T> GetPropertyArray() const;
303  template <typename T>
304  unsigned int GetPropertyArray(T* values, unsigned int count = 1) const;
305  template <typename T>
306  void SetProperty(unsigned int index, T value);
307  template <typename T>
308  void SetPropertyArray(const T* values, unsigned int count);
309  void SetPropertyArrayIdType(const vtkIdType* values, unsigned int count);
310  template <typename T>
311  void AppendPropertyArray(const T* values, unsigned int count);
312  template <typename T>
313  bool CopyInternal(const vtkSMPropertyHelper& source);
314 
315  enum PType
316  {
317  INT,
318  DOUBLE,
319  IDTYPE,
320  STRING,
321  PROXY,
322  INPUT,
323  NONE
324  };
325 
326  bool Quiet;
327  bool UseUnchecked;
328  vtkSMProxy* Proxy;
329  PType Type;
330 
331  union
332  {
341  };
342 };
343 
344 template <>
345 inline std::vector<int> vtkSMPropertyHelper::GetArray() const
346 {
347  return this->GetIntArray();
348 }
349 
350 template <>
351 inline std::vector<double> vtkSMPropertyHelper::GetArray() const
352 {
353  return this->GetDoubleArray();
354 }
355 
356 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
357 template <>
358 inline std::vector<vtkIdType> vtkSMPropertyHelper::GetArray() const
359 {
360  return this->GetIdTypeArray();
361 }
362 #endif
363 
364 template <>
365 inline int vtkSMPropertyHelper::GetAs(unsigned int index) const
366 {
367  return this->GetAsInt(index);
368 }
369 
370 template <>
371 inline double vtkSMPropertyHelper::GetAs(unsigned int index) const
372 {
373  return this->GetAsDouble(index);
374 }
375 
376 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
377 template <>
378 inline vtkIdType vtkSMPropertyHelper::GetAs(unsigned int index) const
379 {
380  return this->GetAsIdType(index);
381 }
382 #endif
383 
384 #endif
385 
386 // 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)
Replace the proxy at index 0 with a new one (optionally specifying output port).
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.