9 #ifndef vtkSMVectorPropertyTemplate_h 10 #define vtkSMVectorPropertyTemplate_h 14 #include "vtkStringFormatter.h" 27 std::string AsString(
const T& var)
29 return vtk::to_string(var);
33 [[maybe_unused]]
inline std::string AsString(
const std::string& var)
39 T vtkSMVPConvertFromString(
const std::string& string_representation)
42 std::istringstream buffer(string_representation);
48 [[maybe_unused]]
inline std::string vtkSMVPConvertFromString<std::string>(
49 const std::string& string_representation)
51 return string_representation;
70 this->Property = property;
71 this->DefaultsValid =
false;
72 this->Initialized =
false;
78 this->DefaultValues.clear();
79 this->DefaultValues.insert(this->DefaultValues.end(), this->Values.begin(), this->Values.end());
80 this->DefaultsValid =
true;
86 this->UncheckedValues.resize(num);
87 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
93 return static_cast<unsigned int>(this->UncheckedValues.size());
102 if (num == this->Values.size())
106 this->Values.resize(num);
107 this->UncheckedValues.resize(num);
111 this->Initialized =
true;
115 this->Initialized =
false;
123 assert(idx < this->Values.size());
124 return this->Values[idx];
131 if (idx >= 0 && idx < static_cast<int>(this->DefaultValues.size()))
133 return this->DefaultValues[idx];
136 static T empty_value = T();
141 T*
GetElements() {
return !this->Values.empty() ? this->Values.data() :
nullptr; }
146 return (!this->UncheckedValues.empty()) ? this->UncheckedValues.data() :
nullptr;
151 assert(idx < this->UncheckedValues.size());
152 return this->UncheckedValues[idx];
160 this->UncheckedValues.resize(idx + 1);
163 if (this->UncheckedValues[idx] != value)
165 this->UncheckedValues[idx] = value;
166 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
179 bool modified =
false;
181 if (numArgs != numValues)
183 this->UncheckedValues.resize(numValues);
189 modified = !std::equal(this->UncheckedValues.begin(), this->UncheckedValues.end(), values);
197 std::copy(values, values + numArgs, this->UncheckedValues.begin());
199 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
208 if (this->Initialized && idx < numElems && value == this->
GetElement(idx))
217 this->Values[idx] = value;
221 this->Initialized =
true;
236 bool modified =
false;
238 if (numArgs != numValues)
240 this->Values.resize(numValues);
241 this->UncheckedValues.resize(numValues);
247 modified = !std::equal(this->Values.begin(), this->Values.end(), values);
249 if (!modified && this->Initialized)
254 std::copy(values, values + numArgs, this->Values.begin());
255 this->Initialized =
true;
256 if (!modified && numValues == 0)
275 this->UncheckedValues.insert(std::end(this->UncheckedValues), values, values + numValues);
276 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
284 this->Values.insert(std::end(this->Values), values, values + numValues);
285 this->Initialized =
true;
297 bool modified =
false;
299 if (this->Values != dsrc->
Values)
301 this->Values = dsrc->
Values;
307 this->Initialized =
true;
315 if (this->UncheckedValues != dsrc->
Values)
317 this->UncheckedValues = dsrc->
Values;
322 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
330 if (this->DefaultsValid)
332 if (this->DefaultValues != this->Values || this->DefaultValues != this->UncheckedValues)
337 this->Initialized =
true;
344 this->Values.clear();
345 this->Initialized =
true;
359 std::vector<T> new_values;
361 for (
unsigned int i = 0; i < numElems; i++)
364 if (current->
GetName() && strcmp(current->
GetName(),
"Element") == 0)
370 if (index <= static_cast<int>(new_values.size()))
372 new_values.resize(index + 1);
375 new_values[index] = vtkSMVPConvertFromString<T>(str_value);
379 if (!new_values.empty())
381 this->
SetElements(new_values.data(),
static_cast<unsigned int>(new_values.size()));
397 propertyElement->
AddAttribute(
"number_of_elements", size);
401 for (
unsigned int i = 0; i < size; i++)
404 elementElement->
SetName(
"Element");
416 this->UncheckedValues = this->
Values;
417 this->Property->
InvokeEvent(vtkCommand::UncheckedPropertyModifiedEvent);
423 if (this->Values.size() != this->DefaultValues.size())
428 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()