9 #ifndef vtkSMVectorPropertyTemplate_h 10 #define vtkSMVectorPropertyTemplate_h 17 #include VTK_DOUBLECONVERSION_HEADER(double-conversion.h) 32 std::string AsString(
const T& var)
34 std::ostringstream str;
40 vtkMaybeUnused(
"not used in non-double specializations") inline
std::
string 41 AsString(
const double& var)
44 const double_conversion::DoubleToStringConverter& converter =
45 double_conversion::DoubleToStringConverter::EcmaScriptConverter();
46 double_conversion::StringBuilder builder(buf,
sizeof(buf));
48 converter.ToShortest(var, &builder);
49 return builder.Finalize();
53 B vtkSMVPConvertFromString(
const std::string& string_representation)
56 std::istringstream buffer(string_representation);
62 vtkMaybeUnused(
"not used in non-string specializations") inline
std::
string 63 vtkSMVPConvertFromString<
std::
string>(
const std::
string& string_representation)
65 return string_representation;
84 this->Property = property;
85 this->DefaultsValid =
false;
86 this->Initialized =
false;
92 this->DefaultValues.clear();
93 this->DefaultValues.insert(this->DefaultValues.end(), this->Values.begin(), this->Values.end());
94 this->DefaultsValid =
true;
100 this->UncheckedValues.resize(num);
101 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
107 return static_cast<unsigned int>(this->UncheckedValues.size());
116 if (num == this->Values.size())
120 this->Values.resize(num);
121 this->UncheckedValues.resize(num);
125 this->Initialized =
true;
129 this->Initialized =
false;
137 assert(idx < this->Values.size());
138 return this->Values[idx];
145 if (idx >= 0 && idx < static_cast<int>(this->DefaultValues.size()))
147 return this->DefaultValues[idx];
150 static T empty_value = T();
155 T*
GetElements() {
return !this->Values.empty() ? &this->Values[0] :
nullptr; }
160 return (!this->UncheckedValues.empty()) ? &this->UncheckedValues[0] :
nullptr;
165 assert(idx < this->UncheckedValues.size());
166 return this->UncheckedValues[idx];
174 this->UncheckedValues.resize(idx + 1);
177 if (this->UncheckedValues[idx] != value)
179 this->UncheckedValues[idx] = value;
180 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
193 bool modified =
false;
195 if (numArgs != numValues)
197 this->UncheckedValues.resize(numValues);
203 modified = !std::equal(this->UncheckedValues.begin(), this->UncheckedValues.end(), values);
211 std::copy(values, values + numArgs, this->UncheckedValues.begin());
213 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
222 if (this->Initialized && idx < numElems && value == this->
GetElement(idx))
231 this->Values[idx] = value;
235 this->Initialized =
true;
250 bool modified =
false;
252 if (numArgs != numValues)
254 this->Values.resize(numValues);
255 this->UncheckedValues.resize(numValues);
261 modified = !std::equal(this->Values.begin(), this->Values.end(), values);
263 if (!modified && this->Initialized)
268 std::copy(values, values + numArgs, this->Values.begin());
269 this->Initialized =
true;
270 if (!modified && numValues == 0)
289 this->UncheckedValues.insert(std::end(this->UncheckedValues), values, values + numValues);
290 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
298 this->Values.insert(std::end(this->Values), values, values + numValues);
299 this->Initialized =
true;
311 bool modified =
false;
313 if (this->Values != dsrc->
Values)
315 this->Values = dsrc->
Values;
321 this->Initialized =
true;
329 if (this->UncheckedValues != dsrc->
Values)
331 this->UncheckedValues = dsrc->
Values;
336 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
344 if (this->DefaultsValid)
346 if (this->DefaultValues != this->Values || this->DefaultValues != this->UncheckedValues)
351 this->Initialized =
true;
358 this->Values.clear();
359 this->Initialized =
true;
373 std::vector<T> new_values;
375 for (
unsigned int i = 0; i < numElems; i++)
378 if (current->
GetName() && strcmp(current->
GetName(),
"Element") == 0)
384 if (index <= static_cast<int>(new_values.size()))
386 new_values.resize(index + 1);
389 new_values[index] = vtkSMVPConvertFromString<T>(str_value);
393 if (!new_values.empty())
395 this->
SetElements(&new_values[0], static_cast<unsigned int>(new_values.size()));
411 propertyElement->
AddAttribute(
"number_of_elements", size);
415 for (
unsigned int i = 0; i < size; i++)
418 elementElement->
SetName(
"Element");
430 this->UncheckedValues = this->
Values;
431 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
437 if (this->Values.size() != this->DefaultValues.size())
442 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()