vtkSMPropertyHelper.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkSMPropertyHelper.h
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*
16  * Copyright (c) 2007, Sandia Corporation
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are met:
21  * * Redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer.
23  * * Redistributions in binary form must reproduce the above copyright
24  * notice, this list of conditions and the following disclaimer in the
25  * documentation and/or other materials provided with the distribution.
26  * * Neither the name of the Sandia Corporation nor the
27  * names of its contributors may be used to endorse or promote products
28  * derived from this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY Sandia Corporation ``AS IS'' AND ANY
31  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  * DISCLAIMED. IN NO EVENT SHALL Sandia Corporation BE LIABLE FOR ANY
34  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
60 #ifndef vtkSMPropertyHelper_h
61 #define vtkSMPropertyHelper_h
62 
63 #include "vtkRemotingServerManagerModule.h" //needed for exports
64 #include "vtkVariant.h" // for vtkVariant
65 
66 #include <vector> // for std::vector
67 
68 #ifdef INT
69 #undef INT
70 #endif
71 #ifdef DOUBLE
72 #undef DOUBLE
73 #endif
74 #ifdef NONE
75 #undef NONE
76 #endif
77 
80 class vtkSMInputProperty;
82 class vtkSMOutputPort;
83 class vtkSMProperty;
84 class vtkSMProxy;
85 class vtkSMProxyProperty;
88 
90 {
91 public:
93 
97  vtkSMPropertyHelper(vtkSMProxy* proxy, const char* name, bool quiet = false);
98  vtkSMPropertyHelper(vtkSMProperty* property, bool quiet = false);
101 
107  void UpdateValueFromServer();
108 
113  void SetNumberOfElements(unsigned int elems);
114 
119  unsigned int GetNumberOfElements() const;
120 
124  void RemoveAllValues() { this->SetNumberOfElements(0); }
125 
129  vtkVariant GetAsVariant(unsigned int index) const;
130 
135  template <class T>
136  std::vector<T> GetArray() const;
137 
142  template <class T>
143  T GetAs(unsigned int index = 0) const;
144 
146 
150  void Set(int value) { this->Set(0, value); }
151  void Set(unsigned int index, int value);
152  void Set(const int* values, unsigned int count);
153  void Append(const int* values, unsigned int count);
154  int GetAsInt(unsigned int index = 0) const;
155  unsigned int Get(int* values, unsigned int count = 1) const;
156  std::vector<int> GetIntArray() const;
158 
160 
164  void Set(double value) { this->Set(0, value); }
165  void Set(unsigned int index, double value);
166  void Set(const double* values, unsigned int count);
167  void Append(const double* values, unsigned int count);
168  double GetAsDouble(unsigned int index = 0) const;
169  unsigned int Get(double* values, unsigned int count = 1) const;
170  std::vector<double> GetDoubleArray() const;
172 
173 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
174 
179  void Set(vtkIdType value) { this->Set(0, value); }
180  void Set(unsigned int index, vtkIdType value);
181  void Set(const vtkIdType* values, unsigned int count);
182  void Append(const vtkIdType* values, unsigned int count);
183  unsigned int Get(vtkIdType* values, unsigned int count = 1) const;
184 #endif
185  vtkIdType GetAsIdType(unsigned int index = 0) const;
186  std::vector<vtkIdType> GetIdTypeArray() const;
188 
190 
197  void Set(const char* value) { this->Set(0, value); }
198  void Set(unsigned int index, const char* value);
199  const char* GetAsString(unsigned int index = 0) const;
201 
203 
208  void Set(vtkSMProxy* value, unsigned int outputport = 0) { this->Set(0, value, outputport); }
209  void Set(unsigned int index, vtkSMProxy* value, unsigned int outputport = 0);
210  void Set(vtkSMProxy** value, unsigned int count, unsigned int* outputports = nullptr);
211  void Add(vtkSMProxy* value, unsigned int outputport = 0);
212  void Remove(vtkSMProxy* value);
213  vtkSMProxy* GetAsProxy(unsigned int index = 0) const;
214  unsigned int GetOutputPort(unsigned int index = 0) const;
215  vtkSMOutputPort* GetAsOutputPort(unsigned int index = 0) const;
217 
219 
224  void SetStatus(const char* key, int value);
225  int GetStatus(const char* key, int default_value = 0) const;
227 
229 
234  void SetStatus(const char* key, double* values, int num_values);
235  bool GetStatus(const char* key, double* values, int num_values) const;
237 
239 
244  void SetStatus(int key, int* values, int num_values);
245  bool GetStatus(int key, int* values, int num_values) const;
247 
249 
254  void SetStatus(const char* key, const char* value);
255  const char* GetStatus(const char* key, const char* default_value) const;
257 
263  void RemoveStatus(const char* key);
264 
266 
271  void SetStatus(int key, int value);
272  int GetStatus(int key, int default_value = 0) const;
274 
276 
281  void SetInputArrayToProcess(int fieldAssociation, const char* arrayName);
282  int GetInputArrayAssociation() const;
283  const char* GetInputArrayNameToProcess() const;
285 
289  void SetUseUnchecked(bool val) { this->UseUnchecked = val; }
290  bool GetUseUnchecked() const { return this->UseUnchecked; }
291 
297  bool Copy(const vtkSMPropertyHelper& source);
298 
303  vtkSMPropertyHelper& Modified();
304 
305 protected:
306  void setUseUnchecked(bool useUnchecked) { this->UseUnchecked = useUnchecked; }
307 
308 private:
309  vtkSMPropertyHelper(const vtkSMPropertyHelper&) = delete;
310  void operator=(const vtkSMPropertyHelper&) = delete;
311  void Initialize(vtkSMProperty* property);
312 
313  template <typename T>
314  T GetProperty(unsigned int index) const;
315  template <typename T>
316  std::vector<T> GetPropertyArray() const;
317  template <typename T>
318  unsigned int GetPropertyArray(T* values, unsigned int count = 1) const;
319  template <typename T>
320  void SetProperty(unsigned int index, T value);
321  template <typename T>
322  void SetPropertyArray(const T* values, unsigned int count);
323  void SetPropertyArrayIdType(const vtkIdType* values, unsigned int count);
324  template <typename T>
325  void AppendPropertyArray(const T* values, unsigned int count);
326  template <typename T>
327  bool CopyInternal(const vtkSMPropertyHelper& source);
328 
329  enum PType
330  {
331  INT,
332  DOUBLE,
333  IDTYPE,
334  STRING,
335  PROXY,
336  INPUT,
337  NONE
338  };
339 
340  bool Quiet;
341  bool UseUnchecked;
342  vtkSMProxy* Proxy;
343  PType Type;
344 
345  union {
354  };
355 };
356 
357 template <>
358 inline std::vector<int> vtkSMPropertyHelper::GetArray() const
359 {
360  return this->GetIntArray();
361 }
362 
363 template <>
364 inline std::vector<double> vtkSMPropertyHelper::GetArray() const
365 {
366  return this->GetDoubleArray();
367 }
368 
369 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
370 template <>
371 inline std::vector<vtkIdType> vtkSMPropertyHelper::GetArray() const
372 {
373  return this->GetIdTypeArray();
374 }
375 #endif
376 
377 template <>
378 inline int vtkSMPropertyHelper::GetAs(unsigned int index) const
379 {
380  return this->GetAsInt(index);
381 }
382 
383 template <>
384 inline double vtkSMPropertyHelper::GetAs(unsigned int index) const
385 {
386  return this->GetAsDouble(index);
387 }
388 
389 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
390 template <>
391 inline vtkIdType vtkSMPropertyHelper::GetAs(unsigned int index) const
392 {
393  return this->GetAsIdType(index);
394 }
395 #endif
396 
397 #endif
398 
399 // 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:152
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.