ParaView
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 "vtkPVServerManagerCoreModule.h" //needed for exports
64 #include "vtkSMObject.h"
65 #include "vtkVariant.h"
66 
67 #include <vector>
68 
69 #ifdef INT
70 #undef INT
71 #endif
72 #ifdef DOUBLE
73 #undef DOUBLE
74 #endif
75 #ifdef NONE
76 #undef NONE
77 #endif
78 
79 class vtkSMProperty;
80 class vtkSMProxy;
86 class vtkSMProxyProperty;
87 class vtkSMInputProperty;
88 
89 class VTKPVSERVERMANAGERCORE_EXPORT vtkSMPropertyHelper
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);
130 
135  template <class T>
136  std::vector<T> GetArray();
137 
142  template <class T>
143  T GetAs(unsigned int index = 0);
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  int GetAsInt(unsigned int index = 0);
154  unsigned int Get(int* values, unsigned int count = 1);
155  std::vector<int> GetIntArray();
157 
159 
163  void Set(double value) { this->Set(0, value); }
164  void Set(unsigned int index, double value);
165  void Set(const double* values, unsigned int count);
166  double GetAsDouble(unsigned int index = 0);
167  unsigned int Get(double* values, unsigned int count = 1);
168  std::vector<double> GetDoubleArray();
170 
171 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
172 
173 
177  void Set(vtkIdType value) { this->Set(0, value); }
178  void Set(unsigned int index, vtkIdType value);
179  void Set(const vtkIdType* values, unsigned int count);
180  unsigned int Get(vtkIdType* values, unsigned int count = 1);
181 #endif
182  vtkIdType GetAsIdType(unsigned int index = 0);
183  std::vector<vtkIdType> GetIdTypeArray();
185 
187 
194  void Set(const char* value) { this->Set(0, value); }
195  void Set(unsigned int index, const char* value);
196  const char* GetAsString(unsigned int index = 0);
198 
200 
205  void Set(vtkSMProxy* value, unsigned int outputport = 0) { this->Set(0, value, outputport); }
206  void Set(unsigned int index, vtkSMProxy* value, unsigned int outputport = 0);
207  void Set(vtkSMProxy** value, unsigned int count, unsigned int* outputports = NULL);
208  void Add(vtkSMProxy* value, unsigned int outputport = 0);
209  void Remove(vtkSMProxy* value);
210  vtkSMProxy* GetAsProxy(unsigned int index = 0);
211  unsigned int GetOutputPort(unsigned int index = 0);
213 
215 
220  void SetStatus(const char* key, int value);
221  int GetStatus(const char* key, int default_value = 0);
223 
225 
230  void SetStatus(const char* key, double* values, int num_values);
231  bool GetStatus(const char* key, double* values, int num_values);
233 
235 
240  void SetStatus(const char* key, const char* value);
241  const char* GetStatus(const char* key, const char* default_value);
243 
245 
250  void SetInputArrayToProcess(int fieldAssociation, const char* arrayName);
251  int GetInputArrayAssociation();
252  const char* GetInputArrayNameToProcess();
254 
258  void SetUseUnchecked(bool val) { this->UseUnchecked = val; }
259  bool GetUseUnchecked() { return this->UseUnchecked; }
260 
266  bool Copy(vtkSMPropertyHelper& source);
267 
268 protected:
269  void setUseUnchecked(bool useUnchecked) { this->UseUnchecked = useUnchecked; }
270 
271 private:
272  vtkSMPropertyHelper(const vtkSMPropertyHelper&) VTK_DELETE_FUNCTION;
273  void operator=(const vtkSMPropertyHelper&) VTK_DELETE_FUNCTION;
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);
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  bool CopyInternal(vtkSMPropertyHelper& source);
289 
290  enum PType
291  {
292  INT,
293  DOUBLE,
294  IDTYPE,
295  STRING,
296  PROXY,
297  INPUT,
298  NONE
299  };
300 
301  bool Quiet;
302  bool UseUnchecked;
303  vtkSMProxy* Proxy;
304  PType Type;
305 
306  union {
315  };
316 };
317 
318 template <>
319 inline std::vector<int> vtkSMPropertyHelper::GetArray()
320 {
321  return this->GetIntArray();
322 }
323 
324 template <>
325 inline std::vector<double> vtkSMPropertyHelper::GetArray()
326 {
327  return this->GetDoubleArray();
328 }
329 
330 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
331 template <>
332 inline std::vector<vtkIdType> vtkSMPropertyHelper::GetArray()
333 {
334  return this->GetIdTypeArray();
335 }
336 #endif
337 
338 template <>
339 inline int vtkSMPropertyHelper::GetAs(unsigned int index)
340 {
341  return this->GetAsInt(index);
342 }
343 
344 template <>
345 inline double vtkSMPropertyHelper::GetAs(unsigned int index)
346 {
347  return this->GetAsDouble(index);
348 }
349 
350 #if VTK_SIZEOF_ID_TYPE != VTK_SIZEOF_INT
351 template <>
352 inline vtkIdType vtkSMPropertyHelper::GetAs(unsigned int index)
353 {
354  return this->GetAsIdType(index);
355 }
356 #endif
357 
358 #endif
359 
360 // VTK-HeaderTest-Exclude: vtkSMPropertyHelper.h
void Set(const char *value)
Set/Get methods for vtkSMStringVectorProperty.
vtkSMInputProperty * InputProperty
T GetAs(unsigned int index=0)
Templated method to call GetAsInt(), GetAsDouble(), GetAsIdType() Note, we only provide implementatio...
vtkSMDoubleVectorProperty * DoubleVectorProperty
property representing pointer(s) to vtkObject(s)
vtkSMProxyProperty * ProxyProperty
void setUseUnchecked(bool useUnchecked)
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.
vtkSMVectorProperty * VectorProperty
void Set(double value)
Set/Get methods with double API.
property representing a vector of integers
abstract superclass for all vector properties
void RemoveAllValues()
Equivalent to SetNumberOfElements(0).
property representing a vector of integers
vtkSMProperty * Property
std::vector< T > GetArray()
Templated method to call GetIntArray(), GetDoubleArray(), GetIdTypeArray().
property representing a vector of doubles
void SetUseUnchecked(bool val)
Get/Set whether to use unchecked properties.
proxy for a VTK object(s) on a server
Definition: vtkSMProxy.h:152
void Set(int value)
Set/Get methods with int API.
vtkSMIntVectorProperty * IntVectorProperty
proxy representing inputs to a filter
helper class to get/set property values.