From f987bc8051ee119398f1b030656a2b007f96dd36 Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit Date: Wed, 24 May 2017 11:41:22 -0400 Subject: [PATCH 1/3] Add `std::vector` API to properties. Properties now sport std::vector API. Also cleaned up vtkSMStringVectorProperty's internal storage to use std::string instead of vtkStdString. --- .../Core/vtkSMDoubleVectorProperty.cxx | 27 ++++++++++ .../Core/vtkSMDoubleVectorProperty.h | 20 ++++++++ .../Core/vtkSMIdTypeVectorProperty.cxx | 28 +++++++++++ .../Core/vtkSMIdTypeVectorProperty.h | 20 ++++++++ .../Core/vtkSMIntVectorProperty.cxx | 26 ++++++++++ .../Core/vtkSMIntVectorProperty.h | 19 +++++++ .../Core/vtkSMStringVectorProperty.cxx | 49 +++++++++++-------- .../Core/vtkSMStringVectorProperty.h | 16 ++++++ 8 files changed, 185 insertions(+), 20 deletions(-) diff --git a/ParaViewCore/ServerManager/Core/vtkSMDoubleVectorProperty.cxx b/ParaViewCore/ServerManager/Core/vtkSMDoubleVectorProperty.cxx index a94c5ee064..3641eba325 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMDoubleVectorProperty.cxx +++ b/ParaViewCore/ServerManager/Core/vtkSMDoubleVectorProperty.cxx @@ -193,6 +193,33 @@ int vtkSMDoubleVectorProperty::SetUncheckedElements(const double* values, unsign return this->Internals->SetUncheckedElements(values, numValues); } +//--------------------------------------------------------------------------- +int vtkSMDoubleVectorProperty::SetElements(const std::vector& values) +{ + return this->Internals->SetElements( + values.size() > 0 ? &values[0] : nullptr, static_cast(values.size())); +} + +//--------------------------------------------------------------------------- +int vtkSMDoubleVectorProperty::SetUncheckedElements(const std::vector& values) +{ + return this->Internals->SetUncheckedElements( + values.size() > 0 ? &values[0] : nullptr, static_cast(values.size())); +} + +//--------------------------------------------------------------------------- +const std::vector& vtkSMDoubleVectorProperty::GetElements(const std::vector&) const +{ + return this->Internals->Values; +} + +//--------------------------------------------------------------------------- +const std::vector& vtkSMDoubleVectorProperty::GetUnCheckedElements( + const std::vector&) const +{ + return this->Internals->UncheckedValues; +} + //--------------------------------------------------------------------------- int vtkSMDoubleVectorProperty::ReadXMLAttributes(vtkSMProxy* proxy, vtkPVXMLElement* element) { diff --git a/ParaViewCore/ServerManager/Core/vtkSMDoubleVectorProperty.h b/ParaViewCore/ServerManager/Core/vtkSMDoubleVectorProperty.h index 73bc4b42c7..ad215ce440 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMDoubleVectorProperty.h +++ b/ParaViewCore/ServerManager/Core/vtkSMDoubleVectorProperty.h @@ -28,6 +28,8 @@ #include "vtkPVServerManagerCoreModule.h" //needed for exports #include "vtkSMVectorProperty.h" +#include // for std::vector + class vtkSMStateLocator; class VTKPVSERVERMANAGERCORE_EXPORT vtkSMDoubleVectorProperty : public vtkSMVectorProperty @@ -68,6 +70,24 @@ public: double* GetElements(); //@} + // typedef to circumvent wrapping issues. + typedef std::vector VectorOfDoubles; + + //@{ + /** + * Get/Set elements (and unchecked elements) API using std::vector. + * The `Set` methods return 1 if the property was modified, otherwise 0. + * + * The `Get` methods take in an optional unused argument to disambiguate from + * variants that return `double*`. + */ + int SetElements(const std::vector& values); + int SetUncheckedElements(const std::vector& values); + const VectorOfDoubles& GetElements(const VectorOfDoubles& notused = VectorOfDoubles()) const; + const VectorOfDoubles& GetUnCheckedElements( + const VectorOfDoubles& notused = VectorOfDoubles()) const; + //@} + //@{ /** * Sets the values of all the unchecked elements. diff --git a/ParaViewCore/ServerManager/Core/vtkSMIdTypeVectorProperty.cxx b/ParaViewCore/ServerManager/Core/vtkSMIdTypeVectorProperty.cxx index 86b1a967f6..e9d3b23e3e 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMIdTypeVectorProperty.cxx +++ b/ParaViewCore/ServerManager/Core/vtkSMIdTypeVectorProperty.cxx @@ -174,6 +174,34 @@ int vtkSMIdTypeVectorProperty::SetUncheckedElements(const vtkIdType* values, uns return this->Internals->SetUncheckedElements(values, numValues); } +//--------------------------------------------------------------------------- +int vtkSMIdTypeVectorProperty::SetElements(const std::vector& values) +{ + return this->Internals->SetElements( + values.size() > 0 ? &values[0] : nullptr, static_cast(values.size())); +} + +//--------------------------------------------------------------------------- +int vtkSMIdTypeVectorProperty::SetUncheckedElements(const std::vector& values) +{ + return this->Internals->SetUncheckedElements( + values.size() > 0 ? &values[0] : nullptr, static_cast(values.size())); +} + +//--------------------------------------------------------------------------- +const std::vector& vtkSMIdTypeVectorProperty::GetElements( + const std::vector&) const +{ + return this->Internals->Values; +} + +//--------------------------------------------------------------------------- +const std::vector& vtkSMIdTypeVectorProperty::GetUnCheckedElements( + const std::vector&) const +{ + return this->Internals->UncheckedValues; +} + //--------------------------------------------------------------------------- int vtkSMIdTypeVectorProperty::ReadXMLAttributes(vtkSMProxy* parent, vtkPVXMLElement* element) { diff --git a/ParaViewCore/ServerManager/Core/vtkSMIdTypeVectorProperty.h b/ParaViewCore/ServerManager/Core/vtkSMIdTypeVectorProperty.h index 691dcf5235..da050698e3 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMIdTypeVectorProperty.h +++ b/ParaViewCore/ServerManager/Core/vtkSMIdTypeVectorProperty.h @@ -28,6 +28,8 @@ #include "vtkPVServerManagerCoreModule.h" //needed for exports #include "vtkSMVectorProperty.h" +#include // for std::vector + class vtkSMStateLocator; class VTKPVSERVERMANAGERCORE_EXPORT vtkSMIdTypeVectorProperty : public vtkSMVectorProperty @@ -75,6 +77,24 @@ public: int SetUncheckedElements(const vtkIdType* values, unsigned int numValues); //@} + // typedef to circumvent wrapping issues. + typedef std::vector VectorOfIdTypes; + + //@{ + /** + * Get/Set elements (and unchecked elements) API using std::vector. + * The `Set` methods return 1 if the property was modified, otherwise 0. + * + * The `Get` methods take in an optional unused argument to disambiguate from + * variants that return `vtkIdType*`. + */ + int SetElements(const std::vector& values); + int SetUncheckedElements(const std::vector& values); + const VectorOfIdTypes& GetElements(const VectorOfIdTypes& notused = VectorOfIdTypes()) const; + const VectorOfIdTypes& GetUnCheckedElements( + const VectorOfIdTypes& notused = VectorOfIdTypes()) const; + //@} + /** * Set the value of 1st element. The vector is resized as necessary. * Returns 0 if Set fails either because the property is read only diff --git a/ParaViewCore/ServerManager/Core/vtkSMIntVectorProperty.cxx b/ParaViewCore/ServerManager/Core/vtkSMIntVectorProperty.cxx index 57d712c822..a59a31b6c0 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMIntVectorProperty.cxx +++ b/ParaViewCore/ServerManager/Core/vtkSMIntVectorProperty.cxx @@ -202,6 +202,32 @@ int vtkSMIntVectorProperty::SetUncheckedElements(const int* values, unsigned int return this->Internals->SetUncheckedElements(values, numValues); } +//--------------------------------------------------------------------------- +int vtkSMIntVectorProperty::SetElements(const std::vector& values) +{ + return this->Internals->SetElements( + values.size() > 0 ? &values[0] : nullptr, static_cast(values.size())); +} + +//--------------------------------------------------------------------------- +int vtkSMIntVectorProperty::SetUncheckedElements(const std::vector& values) +{ + return this->Internals->SetUncheckedElements( + values.size() > 0 ? &values[0] : nullptr, static_cast(values.size())); +} + +//--------------------------------------------------------------------------- +const std::vector& vtkSMIntVectorProperty::GetElements(const std::vector&) const +{ + return this->Internals->Values; +} + +//--------------------------------------------------------------------------- +const std::vector& vtkSMIntVectorProperty::GetUnCheckedElements(const std::vector&) const +{ + return this->Internals->UncheckedValues; +} + //--------------------------------------------------------------------------- int vtkSMIntVectorProperty::ReadXMLAttributes(vtkSMProxy* parent, vtkPVXMLElement* element) { diff --git a/ParaViewCore/ServerManager/Core/vtkSMIntVectorProperty.h b/ParaViewCore/ServerManager/Core/vtkSMIntVectorProperty.h index c3e541866c..ffe68325de 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMIntVectorProperty.h +++ b/ParaViewCore/ServerManager/Core/vtkSMIntVectorProperty.h @@ -28,6 +28,8 @@ #include "vtkPVServerManagerCoreModule.h" //needed for exports #include "vtkSMVectorProperty.h" +#include // needed for std::vector + class vtkSMStateLocator; class VTKPVSERVERMANAGERCORE_EXPORT vtkSMIntVectorProperty : public vtkSMVectorProperty @@ -77,6 +79,23 @@ public: int* GetUnCheckedElements(); //@} + // typedef to circumvent wrapping issues. + typedef std::vector VectorOfInt; + + //@{ + /** + * Get/Set elements (and unchecked elements) API using std::vector. + * The `Set` methods return 1 if the property was modified, otherwise 0. + * + * The `Get` methods take in an optional unused argument to disambiguate from + * variants that return `int*`. + */ + int SetElements(const std::vector& values); + int SetUncheckedElements(const std::vector& values); + const VectorOfInt& GetElements(const VectorOfInt& notused = VectorOfInt()) const; + const VectorOfInt& GetUnCheckedElements(const VectorOfInt& notused = VectorOfInt()) const; + //@} + /** * Set the value of 1st element. The vector is resized as necessary. * Returns 0 if Set fails either because the property is read only diff --git a/ParaViewCore/ServerManager/Core/vtkSMStringVectorProperty.cxx b/ParaViewCore/ServerManager/Core/vtkSMStringVectorProperty.cxx index a447e95681..8053d5a2c4 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMStringVectorProperty.cxx +++ b/ParaViewCore/ServerManager/Core/vtkSMStringVectorProperty.cxx @@ -20,7 +20,6 @@ #include "vtkSMMessage.h" #include "vtkSMStateLocator.h" #include "vtkSMVectorPropertyTemplate.h" -#include "vtkStdString.h" #include "vtkStringList.h" #include @@ -28,13 +27,13 @@ vtkStandardNewMacro(vtkSMStringVectorProperty); -class vtkSMStringVectorProperty::vtkInternals : public vtkSMVectorPropertyTemplate +class vtkSMStringVectorProperty::vtkInternals : public vtkSMVectorPropertyTemplate { public: std::vector ElementTypes; - vtkInternals(vtkSMStringVectorProperty* ivp) - : vtkSMVectorPropertyTemplate(ivp) + vtkInternals(vtkSMStringVectorProperty* svp) + : vtkSMVectorPropertyTemplate(svp) { } }; @@ -163,6 +162,19 @@ void vtkSMStringVectorProperty::GetUncheckedElements(vtkStringList* list) } } +//--------------------------------------------------------------------------- +const std::vector& vtkSMStringVectorProperty::GetElements( + const std::vector&) const +{ + return this->Internals->Values; +} + +//--------------------------------------------------------------------------- +const std::vector& vtkSMStringVectorProperty::GetUncheckedElements() const +{ + return this->Internals->UncheckedValues; +} + //--------------------------------------------------------------------------- const char* vtkSMStringVectorProperty::GetUncheckedElement(unsigned int idx) { @@ -183,7 +195,7 @@ void vtkSMStringVectorProperty::SetUncheckedElement(unsigned int idx, const char int vtkSMStringVectorProperty::SetElements(vtkStringList* list) { unsigned int count = static_cast(list->GetLength()); - vtkStdString* values = new vtkStdString[count + 1]; + std::string* values = new std::string[count + 1]; for (unsigned int cc = 0; cc < count; cc++) { values[cc] = list->GetString(cc) ? list->GetString(cc) : ""; @@ -197,7 +209,7 @@ int vtkSMStringVectorProperty::SetElements(vtkStringList* list) int vtkSMStringVectorProperty::SetUncheckedElements(vtkStringList* list) { unsigned int count = static_cast(list->GetLength()); - vtkStdString* values = new vtkStdString[count + 1]; + std::string* values = new std::string[count + 1]; for (unsigned int cc = 0; cc < count; cc++) { values[cc] = list->GetString(cc) ? list->GetString(cc) : ""; @@ -210,7 +222,7 @@ int vtkSMStringVectorProperty::SetUncheckedElements(vtkStringList* list) //--------------------------------------------------------------------------- int vtkSMStringVectorProperty::SetElements(const char* values[], unsigned int count) { - vtkStdString* std_values = new vtkStdString[count + 1]; + std::string* std_values = new std::string[count + 1]; for (unsigned int cc = 0; cc < count; cc++) { std_values[cc] = values[cc] ? values[cc] : ""; @@ -223,15 +235,14 @@ int vtkSMStringVectorProperty::SetElements(const char* values[], unsigned int co //--------------------------------------------------------------------------- int vtkSMStringVectorProperty::SetElements(const std::vector& values) { - std::vector svalues(values.size() + 1); - std::copy(values.begin(), values.end(), svalues.begin()); - return this->Internals->SetElements(&svalues[0], static_cast(values.size())); + return this->Internals->SetElements( + values.size() > 0 ? &values[0] : nullptr, static_cast(values.size())); } //--------------------------------------------------------------------------- int vtkSMStringVectorProperty::SetUncheckedElements(const char* values[], unsigned int count) { - vtkStdString* std_values = new vtkStdString[count + 1]; + std::string* std_values = new std::string[count + 1]; for (unsigned int cc = 0; cc < count; cc++) { std_values[cc] = values[cc] ? values[cc] : ""; @@ -244,10 +255,8 @@ int vtkSMStringVectorProperty::SetUncheckedElements(const char* values[], unsign //--------------------------------------------------------------------------- int vtkSMStringVectorProperty::SetUncheckedElements(const std::vector& values) { - std::vector svalues(values.size() + 1); - std::copy(values.begin(), values.end(), svalues.begin()); return this->Internals->SetUncheckedElements( - &svalues[0], static_cast(values.size())); + values.size() > 0 ? &values[0] : nullptr, static_cast(values.size())); } //--------------------------------------------------------------------------- @@ -316,18 +325,18 @@ int vtkSMStringVectorProperty::ReadXMLAttributes(vtkSMProxy* proxy, vtkPVXMLElem const char* delimiter = element->GetAttribute("default_values_delimiter"); if (tmp && delimiter) { - vtkStdString initVal = tmp; - vtkStdString delim = delimiter; - vtkStdString::size_type pos1 = 0; - vtkStdString::size_type pos2 = 0; - for (int i = 0; i < numEls && pos2 != vtkStdString::npos; i++) + std::string initVal = tmp; + std::string delim = delimiter; + std::string::size_type pos1 = 0; + std::string::size_type pos2 = 0; + for (int i = 0; i < numEls && pos2 != std::string::npos; i++) { if (i != 0) { pos1 += delim.size(); } pos2 = initVal.find(delimiter, pos1); - vtkStdString v = pos1 == pos2 ? "" : initVal.substr(pos1, pos2 - pos1); + std::string v = pos1 == pos2 ? "" : initVal.substr(pos1, pos2 - pos1); this->Internals->DefaultValues.push_back(v); this->Internals->DefaultsValid = true; this->SetElement(i, v.c_str()); diff --git a/ParaViewCore/ServerManager/Core/vtkSMStringVectorProperty.h b/ParaViewCore/ServerManager/Core/vtkSMStringVectorProperty.h index 7d45d24b99..0a53831e10 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMStringVectorProperty.h +++ b/ParaViewCore/ServerManager/Core/vtkSMStringVectorProperty.h @@ -100,6 +100,22 @@ public: */ unsigned int GetElementIndex(const char* value, int& exists); + // typedef to circumvent wrapping issues. + typedef std::vector VectorOfStrings; + + /** + * Returns values as a std::vector. + * + * The optional argument is only for consistency with other + * vtkSMVectorProperty subclasses. + */ + const VectorOfStrings& GetElements(const VectorOfStrings& notused = VectorOfStrings()) const; + + /** + * Returns unchecked values as a std::vector. + */ + const std::vector& GetUncheckedElements() const; + //@{ /** * Set the cast type used when passing a value to the stream. -- GitLab From 668edd6bad00f46965eb8b708f96eda32476c52c Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit Date: Wed, 24 May 2017 12:17:06 -0400 Subject: [PATCH 2/3] Fix indentation and add missing `;` after macros. --- .../ServerManager/Core/vtkSMProperty.h | 118 +++++++++--------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/ParaViewCore/ServerManager/Core/vtkSMProperty.h b/ParaViewCore/ServerManager/Core/vtkSMProperty.h index f264136728..2338418296 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMProperty.h +++ b/ParaViewCore/ServerManager/Core/vtkSMProperty.h @@ -335,65 +335,65 @@ public: * By default, all properties have "default" visibility. */ - vtkSetStringMacro(PanelVisibility) - //@} - - //@{ - /** - * Returns the panel visibility for the property. - */ - vtkGetStringMacro(PanelVisibility) - //@} - - //@{ - /** - * Sets the panel visibility to default if the current - * representation type matches \p representation. - */ - vtkSetStringMacro(PanelVisibilityDefaultForRepresentation) - //@} - - //@{ - /** - * Returns which representation type the property will be shown by - * default for. - */ - vtkGetStringMacro(PanelVisibilityDefaultForRepresentation) - //@} - - //@{ - /** - * Sets the name of the custom panel widget to use for the property. - */ - vtkSetStringMacro(PanelWidget) - //@} - - //@{ - /** - * Returns name of the panel widget for the property. - */ - vtkGetStringMacro(PanelWidget) - //@} - - //@{ - /** - * Sets the tracing of sub property of this property - */ - vtkSetStringMacro(DisableSubTrace) - //@} - - //@{ - /** - * Returns the tracing state of the properties of this property - */ - vtkGetStringMacro(DisableSubTrace) - //@} - - /** - * Copy all property values. This will copy both checked and unchecked values, - * if applicable. - */ - virtual void Copy(vtkSMProperty* src); + vtkSetStringMacro(PanelVisibility); + //@} + + //@{ + /** + * Returns the panel visibility for the property. + */ + vtkGetStringMacro(PanelVisibility); + //@} + + //@{ + /** + * Sets the panel visibility to default if the current + * representation type matches \p representation. + */ + vtkSetStringMacro(PanelVisibilityDefaultForRepresentation); + //@} + + //@{ + /** + * Returns which representation type the property will be shown by + * default for. + */ + vtkGetStringMacro(PanelVisibilityDefaultForRepresentation); + //@} + + //@{ + /** + * Sets the name of the custom panel widget to use for the property. + */ + vtkSetStringMacro(PanelWidget); + //@} + + //@{ + /** + * Returns name of the panel widget for the property. + */ + vtkGetStringMacro(PanelWidget); + //@} + + //@{ + /** + * Sets the tracing of sub property of this property + */ + vtkSetStringMacro(DisableSubTrace); + //@} + + //@{ + /** + * Returns the tracing state of the properties of this property + */ + vtkGetStringMacro(DisableSubTrace); + //@} + + /** + * Copy all property values. This will copy both checked and unchecked values, + * if applicable. + */ + virtual void Copy(vtkSMProperty* src); //@{ /** -- GitLab From 1c40d28f8ef96b20c8eef1bf0e6593540d688913 Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit Date: Wed, 24 May 2017 12:19:42 -0400 Subject: [PATCH 3/3] Fix comment blocks. --- ParaViewCore/ServerManager/Core/vtkSMProperty.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ParaViewCore/ServerManager/Core/vtkSMProperty.h b/ParaViewCore/ServerManager/Core/vtkSMProperty.h index 2338418296..f516e7c715 100644 --- a/ParaViewCore/ServerManager/Core/vtkSMProperty.h +++ b/ParaViewCore/ServerManager/Core/vtkSMProperty.h @@ -491,8 +491,10 @@ public: */ vtkSMProxy* GetParent(); - // Flag used to ignore property when building Proxy state for Undo/Redo state. - // The default value is false. + /** + * Flag used to ignore property when building Proxy state for Undo/Redo state. + * The default value is false. + */ virtual bool IsStateIgnored() { return this->StateIgnored; } /** @@ -693,8 +695,10 @@ private: vtkSMProperty(const vtkSMProperty&) = delete; void operator=(const vtkSMProperty&) = delete; - // Callback to fire vtkCommand::DomainModifiedEvent every time any of the - // domains change. + /** + * Callback to fire vtkCommand::DomainModifiedEvent every time any of the + * domains change. + */ void InvokeDomainModifiedEvent(); /** -- GitLab