21 #ifndef vtkSMVectorPropertyTemplate_h 22 #define vtkSMVectorPropertyTemplate_h 31 #include VTK_DOUBLECONVERSION_HEADER(double-conversion.h) 46 std::string AsString(
const T& var)
48 std::ostringstream str;
54 vtkMaybeUnused(
"not used in non-double specializations")
std::
string AsString(
const double& var)
57 const double_conversion::DoubleToStringConverter& converter =
58 double_conversion::DoubleToStringConverter::EcmaScriptConverter();
59 double_conversion::StringBuilder builder(buf,
sizeof(buf));
61 converter.ToShortest(var, &builder);
62 return builder.Finalize();
66 B vtkSMVPConvertFromString(
const std::string& string_representation)
69 std::istringstream buffer(string_representation);
75 vtkMaybeUnused(
"not used in non-string specializations")
std::
string 76 vtkSMVPConvertFromString<
std::
string>(
const std::
string& string_representation)
78 return string_representation;
97 this->Property = property;
98 this->DefaultsValid =
false;
99 this->Initialized =
false;
105 this->DefaultValues.clear();
106 this->DefaultValues.insert(this->DefaultValues.end(), this->Values.begin(), this->Values.end());
107 this->DefaultsValid =
true;
113 this->UncheckedValues.resize(num);
114 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
120 return static_cast<unsigned int>(this->UncheckedValues.size());
129 if (num == this->Values.size())
133 this->Values.resize(num);
134 this->UncheckedValues.resize(num);
138 this->Initialized =
true;
142 this->Initialized =
false;
150 assert(idx < this->Values.size());
151 return this->Values[idx];
158 if (idx >= 0 && idx < static_cast<int>(this->DefaultValues.size()))
160 return this->DefaultValues[idx];
163 static T empty_value = T();
168 T*
GetElements() {
return (this->Values.size() > 0) ? &this->Values[0] : NULL; }
173 return (this->UncheckedValues.size() > 0) ? &this->UncheckedValues[0] : NULL;
178 assert(idx < this->UncheckedValues.size());
179 return this->UncheckedValues[idx];
187 this->UncheckedValues.resize(idx + 1);
190 if (this->UncheckedValues[idx] != value)
192 this->UncheckedValues[idx] = value;
193 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
206 bool modified =
false;
208 if (numArgs != numValues)
210 this->UncheckedValues.resize(numValues);
216 modified = !std::equal(this->UncheckedValues.begin(), this->UncheckedValues.end(), values);
224 std::copy(values, values + numArgs, this->UncheckedValues.begin());
226 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
235 if (this->Initialized && idx < numElems && value == this->
GetElement(idx))
244 this->Values[idx] = value;
248 this->Initialized =
true;
263 bool modified =
false;
265 if (numArgs != numValues)
267 this->Values.resize(numValues);
268 this->UncheckedValues.resize(numValues);
274 modified = !std::equal(this->Values.begin(), this->Values.end(), values);
276 if (!modified && this->Initialized)
281 std::copy(values, values + numArgs, this->Values.begin());
282 this->Initialized =
true;
283 if (!modified && numValues == 0)
302 this->UncheckedValues.insert(std::end(this->UncheckedValues), values, values + numValues);
303 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
311 this->Values.insert(std::end(this->Values), values, values + numValues);
312 this->Initialized =
true;
324 bool modified =
false;
326 if (this->Values != dsrc->
Values)
328 this->Values = dsrc->
Values;
334 this->Initialized =
true;
342 if (this->UncheckedValues != dsrc->
Values)
344 this->UncheckedValues = dsrc->
Values;
349 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
357 if (this->DefaultsValid && this->DefaultValues != this->Values)
362 this->Initialized =
true;
368 this->Values.clear();
369 this->Initialized =
true;
383 std::vector<T> new_values;
385 for (
unsigned int i = 0; i < numElems; i++)
388 if (current->
GetName() && strcmp(current->
GetName(),
"Element") == 0)
394 if (index <= static_cast<int>(new_values.size()))
396 new_values.resize(index + 1);
399 new_values[index] = vtkSMVPConvertFromString<T>(str_value);
403 if (new_values.size() > 0)
405 this->
SetElements(&new_values[0], static_cast<unsigned int>(new_values.size()));
421 propertyElement->
AddAttribute(
"number_of_elements", size);
425 for (
unsigned int i = 0; i < size; i++)
428 elementElement->
SetName(
"Element");
440 this->UncheckedValues = this->
Values;
441 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
447 if (this->Values.size() != this->DefaultValues.size())
452 return std::equal(this->Values.begin(), this->Values.end(), this->DefaultValues.begin());
unsigned int GetNumberOfNestedElements()
Get the number of elements nested in this one.
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 InvokeEvent(unsigned long event)
int SetElement(unsigned int idx, T value)
void SetUncheckedElement(unsigned int idx, T value)
superclass for all SM properties
void SetNumberOfUncheckedElements(unsigned int num)
void Modified() override
Overridden to support blocking of modified events.
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()
int AppendElements(const T *values, unsigned int numValues)
unsigned int GetNumberOfUncheckedElements()
T & GetUncheckedElement(unsigned int idx)
int AppendUncheckedElements(const T *values, unsigned int numValues)
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.
T * GetUncheckedElements()
void ClearUncheckedElements()