From ae787bc534411d468aa7d692cdb0cc89067c550a Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Thu, 19 Oct 2023 17:20:56 -0400 Subject: [PATCH] ENH: Convert AttributeArray DataType allows user to delete input array. (#746) Signed-off-by: Michael Jackson --- .../ComplexCore/docs/ConvertDataFilter.md | 2 +- .../ComplexCore/Filters/ConvertDataFilter.cpp | 21 ++++++++++++++----- .../ComplexCore/Filters/ConvertDataFilter.hpp | 1 + .../Filters/SplitAttributeArrayFilter.cpp | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Plugins/ComplexCore/docs/ConvertDataFilter.md b/src/Plugins/ComplexCore/docs/ConvertDataFilter.md index a6251c6db8..6833c61485 100644 --- a/src/Plugins/ComplexCore/docs/ConvertDataFilter.md +++ b/src/Plugins/ComplexCore/docs/ConvertDataFilter.md @@ -1,4 +1,4 @@ -# Convert Attribute Data Type +# Convert AttributeArray DataType ## Group (Subgroup) diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/ConvertDataFilter.cpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/ConvertDataFilter.cpp index d72a3adf2b..7f63e820b6 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/ConvertDataFilter.cpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/ConvertDataFilter.cpp @@ -6,7 +6,9 @@ #include "complex/DataStructure/DataPath.hpp" #include "complex/DataStructure/IDataArray.hpp" #include "complex/Filter/Actions/CreateArrayAction.hpp" +#include "complex/Filter/Actions/DeleteDataAction.hpp" #include "complex/Parameters/ArraySelectionParameter.hpp" +#include "complex/Parameters/BoolParameter.hpp" #include "complex/Parameters/ChoicesParameter.hpp" #include "complex/Parameters/DataObjectNameParameter.hpp" @@ -52,6 +54,8 @@ Parameters ConvertDataFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameters"}); params.insert(std::make_unique(k_ScalarType_Key, "Scalar Type", "Convert to this data type", 0, GetAllDataTypesAsStrings())); params.insert(std::make_unique(k_ArrayToConvert_Key, "Data Array to Convert", "The complete path to the Data Array to Convert", DataPath{}, GetAllDataTypes())); + params.insert(std::make_unique(k_DeleteOriginal_Key, "Remove Original Array", "Whether or not to remove the original array after conversion", false)); + params.insertSeparator(Parameters::Separator{"Created Data Objects"}); params.insert(std::make_unique(k_ConvertedArray_Key, "Converted Data Array", "The name of the converted Data Array", "Converted_")); @@ -71,24 +75,31 @@ IFilter::PreflightResult ConvertDataFilter::preflightImpl(const DataStructure& d auto pScalarTypeIndex = filterArgs.value(k_ScalarType_Key); auto pInputArrayPath = filterArgs.value(k_ArrayToConvert_Key); auto pConvertedArrayName = filterArgs.value(k_ConvertedArray_Key); - DataPath convertedArrayPath = pInputArrayPath.getParent().createChildPath(pConvertedArrayName); + auto pRemoveOriginal = filterArgs.value(k_DeleteOriginal_Key); + + DataPath const convertedArrayPath = pInputArrayPath.getParent().createChildPath(pConvertedArrayName); - DataType pScalarType = StringToDataType(GetAllDataTypesAsStrings()[pScalarTypeIndex]); + DataType const pScalarType = StringToDataType(GetAllDataTypesAsStrings()[pScalarTypeIndex]); PreflightResult preflightResult; complex::Result resultOutputActions; - auto* inputArray = dataStructure.getDataAs(pInputArrayPath); - if(inputArray == nullptr) + auto* inputArrayPtr = dataStructure.getDataAs(pInputArrayPath); + if(inputArrayPtr == nullptr) { return {nonstd::make_unexpected(std::vector{Error{-15201, fmt::format("Cannot find input data array at path '{}'", pInputArrayPath.toString())}})}; } resultOutputActions.value().appendAction( - std::make_unique(pScalarType, inputArray->getIDataStoreRef().getTupleShape(), inputArray->getIDataStoreRef().getComponentShape(), convertedArrayPath)); + std::make_unique(pScalarType, inputArrayPtr->getIDataStoreRef().getTupleShape(), inputArrayPtr->getIDataStoreRef().getComponentShape(), convertedArrayPath)); std::vector preflightUpdatedValues; + if(pRemoveOriginal) + { + resultOutputActions.value().appendDeferredAction(std::make_unique(pInputArrayPath, DeleteDataAction::DeleteType::JustObject)); + } + // Return both the resultOutputActions and the preflightUpdatedValues via std::move() return {std::move(resultOutputActions), std::move(preflightUpdatedValues)}; } diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/ConvertDataFilter.hpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/ConvertDataFilter.hpp index e2cb7c00e3..b0d5ee4ab8 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/ConvertDataFilter.hpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/ConvertDataFilter.hpp @@ -27,6 +27,7 @@ class COMPLEXCORE_EXPORT ConvertDataFilter : public IFilter static inline constexpr StringLiteral k_ScalarType_Key = "scalar_type"; static inline constexpr StringLiteral k_ArrayToConvert_Key = "array_to_convert"; static inline constexpr StringLiteral k_ConvertedArray_Key = "converted_array"; + static inline constexpr StringLiteral k_DeleteOriginal_Key = "delete_original_array"; /** * @brief Returns the name of the filter. diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/SplitAttributeArrayFilter.cpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/SplitAttributeArrayFilter.cpp index c279306e63..1b1caedd56 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/SplitAttributeArrayFilter.cpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/SplitAttributeArrayFilter.cpp @@ -43,7 +43,7 @@ std::string SplitAttributeArrayFilter::humanName() const //------------------------------------------------------------------------------ std::vector SplitAttributeArrayFilter::defaultTags() const { - return {className(), "Core", "Split"}; + return {className(), "Core", "Split", "Data", "Multi-Component"}; } //------------------------------------------------------------------------------