Skip to content

Commit

Permalink
ENH: Convert AttributeArray DataType allows user to delete input arra…
Browse files Browse the repository at this point in the history
…y. (#746)

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Oct 19, 2023
1 parent 1807f62 commit ae787bc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Plugins/ComplexCore/docs/ConvertDataFilter.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Convert Attribute Data Type
# Convert AttributeArray DataType

## Group (Subgroup)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -52,6 +54,8 @@ Parameters ConvertDataFilter::parameters() const
params.insertSeparator(Parameters::Separator{"Input Parameters"});
params.insert(std::make_unique<ChoicesParameter>(k_ScalarType_Key, "Scalar Type", "Convert to this data type", 0, GetAllDataTypesAsStrings()));
params.insert(std::make_unique<ArraySelectionParameter>(k_ArrayToConvert_Key, "Data Array to Convert", "The complete path to the Data Array to Convert", DataPath{}, GetAllDataTypes()));
params.insert(std::make_unique<BoolParameter>(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<DataObjectNameParameter>(k_ConvertedArray_Key, "Converted Data Array", "The name of the converted Data Array", "Converted_"));

Expand All @@ -71,24 +75,31 @@ IFilter::PreflightResult ConvertDataFilter::preflightImpl(const DataStructure& d
auto pScalarTypeIndex = filterArgs.value<ChoicesParameter::ValueType>(k_ScalarType_Key);
auto pInputArrayPath = filterArgs.value<ArraySelectionParameter::ValueType>(k_ArrayToConvert_Key);
auto pConvertedArrayName = filterArgs.value<DataObjectNameParameter::ValueType>(k_ConvertedArray_Key);
DataPath convertedArrayPath = pInputArrayPath.getParent().createChildPath(pConvertedArrayName);
auto pRemoveOriginal = filterArgs.value<bool>(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<OutputActions> resultOutputActions;

auto* inputArray = dataStructure.getDataAs<IDataArray>(pInputArrayPath);
if(inputArray == nullptr)
auto* inputArrayPtr = dataStructure.getDataAs<IDataArray>(pInputArrayPath);
if(inputArrayPtr == nullptr)
{
return {nonstd::make_unexpected(std::vector<Error>{Error{-15201, fmt::format("Cannot find input data array at path '{}'", pInputArrayPath.toString())}})};
}

resultOutputActions.value().appendAction(
std::make_unique<CreateArrayAction>(pScalarType, inputArray->getIDataStoreRef().getTupleShape(), inputArray->getIDataStoreRef().getComponentShape(), convertedArrayPath));
std::make_unique<CreateArrayAction>(pScalarType, inputArrayPtr->getIDataStoreRef().getTupleShape(), inputArrayPtr->getIDataStoreRef().getComponentShape(), convertedArrayPath));

std::vector<PreflightValue> preflightUpdatedValues;

if(pRemoveOriginal)
{
resultOutputActions.value().appendDeferredAction(std::make_unique<DeleteDataAction>(pInputArrayPath, DeleteDataAction::DeleteType::JustObject));
}

// Return both the resultOutputActions and the preflightUpdatedValues via std::move()
return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::string SplitAttributeArrayFilter::humanName() const
//------------------------------------------------------------------------------
std::vector<std::string> SplitAttributeArrayFilter::defaultTags() const
{
return {className(), "Core", "Split"};
return {className(), "Core", "Split", "Data", "Multi-Component"};
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit ae787bc

Please sign in to comment.