21 #ifndef vtkSMVectorPropertyTemplate_h 22 #define vtkSMVectorPropertyTemplate_h 24 #include "vtkCommand.h" 41 B vtkSMVPConvertFromString(
const std::string& string_representation)
44 std::istringstream buffer(string_representation);
50 vtkMaybeUnused(
"not used in non-string specializations")
51 vtkStdString vtkSMVPConvertFromString<vtkStdString>(const std::
string& string_representation)
53 return string_representation;
72 this->Property = property;
73 this->DefaultsValid =
false;
74 this->Initialized =
false;
80 this->DefaultValues.clear();
81 this->DefaultValues.insert(this->DefaultValues.end(), this->Values.begin(), this->Values.end());
82 this->DefaultsValid =
true;
88 this->UncheckedValues.resize(num);
89 this->Property->InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
95 return static_cast<unsigned int>(this->UncheckedValues.size());
104 if (num == this->Values.size())
108 this->Values.resize(num);
109 this->UncheckedValues.resize(num);
113 this->Initialized =
true;
117 this->Initialized =
false;
125 assert(idx < this->Values.size());
126 return this->Values[idx];
133 if (idx >= 0 && idx < static_cast<int>(this->DefaultValues.size()))
135 return this->DefaultValues[idx];
138 static T empty_value = T();
143 T*
GetElements() {
return (this->Values.size() > 0) ? &this->Values[0] : NULL; }
148 assert(idx < this->UncheckedValues.size());
149 return this->UncheckedValues[idx];
157 this->UncheckedValues.resize(idx + 1);
160 if (this->UncheckedValues[idx] != value)
162 this->UncheckedValues[idx] = value;
163 this->Property->InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
176 bool modified =
false;
178 if (numArgs != numValues)
180 this->UncheckedValues.resize(numValues);
186 modified = !std::equal(this->UncheckedValues.begin(), this->UncheckedValues.end(), values);
194 std::copy(values, values + numArgs, this->UncheckedValues.begin());
196 this->Property->InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
205 if (this->Initialized && idx < numElems && value == this->
GetElement(idx))
214 this->Values[idx] = value;
218 this->Initialized =
true;
233 bool modified =
false;
235 if (numArgs != numValues)
237 this->Values.resize(numValues);
238 this->UncheckedValues.resize(numValues);
244 modified = !std::equal(this->Values.begin(), this->Values.end(), values);
246 if (!modified && this->Initialized)
251 std::copy(values, values + numArgs, this->Values.begin());
252 this->Initialized =
true;
253 if (!modified && numValues == 0)
274 bool modified =
false;
276 if (this->Values != dsrc->
Values)
278 this->Values = dsrc->
Values;
284 this->Initialized =
true;
292 if (this->UncheckedValues != dsrc->
Values)
294 this->UncheckedValues = dsrc->
Values;
299 this->Property->InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
307 if (this->DefaultsValid && this->DefaultValues != this->Values)
312 this->Initialized =
true;
318 this->Values.clear();
319 this->Initialized =
true;
333 std::vector<T> new_values;
335 for (
unsigned int i = 0; i < numElems; i++)
338 if (current->
GetName() && strcmp(current->
GetName(),
"Element") == 0)
344 if (index <= static_cast<int>(new_values.size()))
346 new_values.resize(index + 1);
349 new_values[index] = vtkSMVPConvertFromString<T>(str_value);
353 if (new_values.size() > 0)
355 this->
SetElements(&new_values[0], static_cast<unsigned int>(new_values.size()));
371 propertyElement->
AddAttribute(
"number_of_elements", size);
373 for (
unsigned int i = 0; i < size; i++)
375 std::ostringstream valueAsString;
378 valueAsString.precision(std::numeric_limits<T>::digits10);
383 elementElement->
SetName(
"Element");
385 elementElement->
AddAttribute(
"value", valueAsString.str().c_str());
387 elementElement->Delete();
395 this->UncheckedValues = this->
Values;
396 this->Property->InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
402 if (this->Values.size() != this->DefaultValues.size())
407 return std::equal(this->Values.begin(), this->Values.end(), this->DefaultValues.begin());
unsigned int GetNumberOfNestedElements()
Get the number of elements nested in this one.
virtual void Modified()
Overridden to support blocking of modified events.
T & GetElement(unsigned int idx)
void AddAttribute(const char *attrName, const char *attrValue)
Given it's name and value, add an attribute.
void Copy(vtkSMVectorPropertyTemplate< T > *dsrc)
int SetUncheckedElements(const T *values)
void SetNumberOfElements(unsigned int num)
int GetScalarAttribute(const char *name, int *value)
Get the attribute with the given name converted to a scalar value.
int SetUncheckedElements(const T *values, unsigned int numValues)
static vtkPVXMLElement * New()
int SetElements(const T *values)
int SetElement(unsigned int idx, T value)
void SetUncheckedElement(unsigned int idx, T value)
superclass for all SM properties
void SetNumberOfUncheckedElements(unsigned int num)
virtual int GetRepeatable()
If repeatable, a property can have 1 or more values of the same kind.
const char * GetAttribute(const char *name)
Get the attribute with the given name.
vtkPVXMLElement * GetNestedElement(unsigned int index)
Get the element nested in this one at the given index.
void SaveStateValues(vtkPVXMLElement *propertyElement)
std::vector< T > UncheckedValues
int SetElements(const T *values, unsigned int numValues)
vtkSMVectorPropertyTemplate(vtkSMProperty *property)
void UpdateDefaultValues()
unsigned int GetNumberOfUncheckedElements()
T & GetUncheckedElement(unsigned int idx)
unsigned int GetNumberOfElements()
bool LoadStateValues(vtkPVXMLElement *element)
void ResetToXMLDefaults()
std::vector< T > DefaultValues
virtual char * GetName()
Set/Get the name of the element.
void AddNestedElement(vtkPVXMLElement *element, int setPrent)
Add a sub-element.
T & GetDefaultValue(int idx)
This is used by vtkPVXMLParser to represent an XML document starting at the root element.
virtual void SetName(const char *)
Set/Get the name of the element.
void ClearUncheckedElements()