diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObject.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObject.cpp deleted file mode 100644 index 38800f75c2..0000000000 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObject.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "RenameDataObject.hpp" - -#include "simplnx/DataStructure/DataGroup.hpp" -#include "simplnx/Filter/Actions/RenameDataAction.hpp" -#include "simplnx/Parameters/DataPathSelectionParameter.hpp" -#include "simplnx/Parameters/StringParameter.hpp" -#include "simplnx/Utilities/DataArrayUtilities.hpp" - -#include "simplnx/Utilities/SIMPLConversion.hpp" - -#include - -using namespace nx::core; - -namespace -{ -constexpr int32 k_EmptyParameterError = -520; -} // namespace - -namespace nx::core -{ - -//------------------------------------------------------------------------------ -std::string RenameDataObject::name() const -{ - return FilterTraits::name; -} - -//------------------------------------------------------------------------------ -std::string RenameDataObject::className() const -{ - return FilterTraits::className; -} - -//------------------------------------------------------------------------------ -Uuid RenameDataObject::uuid() const -{ - return FilterTraits::uuid; -} - -//------------------------------------------------------------------------------ -std::string RenameDataObject::humanName() const -{ - return "Rename DataObject"; -} - -//------------------------------------------------------------------------------ -std::vector RenameDataObject::defaultTags() const -{ - return {className(), "Data Management", "Rename", "Data Structure", "Data Object"}; -} - -//------------------------------------------------------------------------------ -Parameters RenameDataObject::parameters() const -{ - Parameters params; - - params.insertSeparator(Parameters::Separator{"Input Parameters"}); - params.insert(std::make_unique(k_AllowOverwrite_Key, "Allow Overwrite", - "If true existing object with `New Name` and all of its nested objects will be removed to free up the name for the target DataObject", false)); - params.insert(std::make_unique(k_SourceDataObjectPath_Key, "DataObject to Rename", "DataPath pointing to the target DataObject", DataPath())); - params.insert(std::make_unique(k_NewName_Key, "New Name", "Target DataObject name", "")); - return params; -} - -//------------------------------------------------------------------------------ -IFilter::UniquePointer RenameDataObject::clone() const -{ - return std::make_unique(); -} - -//------------------------------------------------------------------------------ -IFilter::PreflightResult RenameDataObject::preflightImpl(const DataStructure& dataStructure, const Arguments& filterArgs, const MessageHandler& messageHandler, - const std::atomic_bool& shouldCancel) const -{ - auto allowOverwrite = filterArgs.value(k_AllowOverwrite_Key); - auto dataGroupPath = filterArgs.value(k_SourceDataObjectPath_Key); - auto newName = filterArgs.value(k_NewName_Key); - - auto action = std::make_unique(dataGroupPath, newName, allowOverwrite); - - OutputActions actions; - actions.appendAction(std::move(action)); - return {std::move(actions)}; -} - -//------------------------------------------------------------------------------ -Result<> RenameDataObject::executeImpl(DataStructure& data, const Arguments& args, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) const -{ - return {}; -} - -namespace -{ -namespace SIMPL -{ -constexpr StringLiteral k_SelectedAttributeMatrixPathKey = "SelectedAttributeMatrixPath"; -constexpr StringLiteral k_NewAttributeMatrixKey = "NewAttributeMatrix"; -constexpr StringLiteral k_SelectedDataContainerNameKey = "SelectedDataContainerName"; -constexpr StringLiteral k_NewDataContainerNameKey = "NewDataContainerName"; -constexpr StringLiteral k_SelectedArrayPathKey = "SelectedArrayPath"; -constexpr StringLiteral k_NewArrayNameKey = "NewArrayName"; -} // namespace SIMPL -} // namespace - -Result RenameDataObject::FromSIMPLJson(const nlohmann::json& json) -{ - Arguments args = RenameDataObject().getDefaultArguments(); - - std::vector> results; - - if(json.contains(SIMPL::k_SelectedArrayPathKey.str())) - { - results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_SelectedArrayPathKey, k_SourceDataObjectPath_Key)); - results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_NewArrayNameKey, k_NewName_Key)); - } - else if(json.contains(SIMPL::k_SelectedAttributeMatrixPathKey)) - { - results.push_back( - SIMPLConversion::ConvertParameter(args, json, SIMPL::k_SelectedAttributeMatrixPathKey, k_SourceDataObjectPath_Key)); - results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_NewAttributeMatrixKey, k_NewName_Key)); - } - else - { - results.push_back( - SIMPLConversion::ConvertParameter(args, json, SIMPL::k_SelectedDataContainerNameKey, k_SourceDataObjectPath_Key)); - results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_NewDataContainerNameKey, k_NewName_Key)); - } - - Result<> conversionResult = MergeResults(std::move(results)); - - return ConvertResultTo(std::move(conversionResult), std::move(args)); -} -} // namespace nx::core diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObject.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObject.hpp deleted file mode 100644 index 5958e8c46f..0000000000 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObject.hpp +++ /dev/null @@ -1,106 +0,0 @@ -#pragma once - -#include "SimplnxCore/SimplnxCore_export.hpp" - -#include "simplnx/Common/StringLiteral.hpp" -#include "simplnx/Filter/FilterTraits.hpp" -#include "simplnx/Filter/IFilter.hpp" - -namespace nx::core -{ -/** - * @class RenameDataObject - * @brief RenameDataObject class is used to rename any DataObject. - */ -class SIMPLNXCORE_EXPORT RenameDataObject : public IFilter -{ -public: - RenameDataObject() = default; - ~RenameDataObject() noexcept override = default; - - RenameDataObject(const RenameDataObject&) = delete; - RenameDataObject(RenameDataObject&&) noexcept = delete; - - RenameDataObject& operator=(const RenameDataObject&) = delete; - RenameDataObject& operator=(RenameDataObject&&) noexcept = delete; - - // Parameter Keys - static inline constexpr StringLiteral k_AllowOverwrite_Key = "allow_overwrite"; - static inline constexpr StringLiteral k_SourceDataObjectPath_Key = "source_data_object_path"; - static inline constexpr StringLiteral k_NewName_Key = "new_name"; - - /** - * @brief Reads SIMPL json and converts it simplnx Arguments. - * @param json - * @return Result - */ - static Result FromSIMPLJson(const nlohmann::json& json); - - /** - * @brief - * @return std::string - */ - std::string name() const override; - - /** - * @brief Returns the C++ classname of this filter. - * @return std::string - */ - std::string className() const override; - - /** - * @brief - * @return Uuid - */ - Uuid uuid() const override; - - /** - * @brief - * @return std::string - */ - std::string humanName() const override; - - /** - * @brief Returns the default tags for this filter. - * @return - */ - std::vector defaultTags() const override; - - /** - * @brief - * @return Parameters - */ - Parameters parameters() const override; - - /** - * @brief - * @return UniquePointer - */ - UniquePointer clone() const override; - -protected: - /** - * @brief - * @param data - * @param filterArgs - * @param messageHandler - * @param shouldCancel - * @return Result - */ - PreflightResult preflightImpl(const DataStructure& data, const Arguments& filterArgs, const MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) const override; - - /** - * @brief - * @param dataStructure - * @param args - * @param pipelineNode - * @param messageHandler - * @param shouldCancel - * @return Result<> - */ - Result<> executeImpl(DataStructure& dataStructure, const Arguments& args, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler, - const std::atomic_bool& shouldCancel) const override; -}; -} // namespace nx::core - -SIMPLNX_DEF_FILTER_TRAITS(nx::core, RenameDataObject, "911a3aa9-d3c2-4f66-9451-8861c4b726d5"); diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObjectFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObjectFilter.cpp index 85d7eddd09..c48d47edec 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObjectFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObjectFilter.cpp @@ -56,6 +56,8 @@ Parameters RenameDataObjectFilter::parameters() const Parameters params; params.insertSeparator(Parameters::Separator{"Input Parameters"}); + params.insert(std::make_unique(k_AllowOverwrite_Key, "Allow Overwrite", + "If true existing object with `New Name` and all of its nested objects will be removed to free up the name for the target DataObject", false)); params.insert(std::make_unique(k_SourceDataObjectPath_Key, "DataObject to Rename", "DataPath pointing to the target DataObject", DataPath())); params.insert(std::make_unique(k_NewName_Key, "New Name", "Target DataObject name", "")); return params; @@ -71,10 +73,11 @@ IFilter::UniquePointer RenameDataObjectFilter::clone() const IFilter::PreflightResult RenameDataObjectFilter::preflightImpl(const DataStructure& dataStructure, const Arguments& filterArgs, const MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) const { + auto allowOverwrite = filterArgs.value(k_AllowOverwrite_Key); auto dataGroupPath = filterArgs.value(k_SourceDataObjectPath_Key); auto newName = filterArgs.value(k_NewName_Key); - auto action = std::make_unique(dataGroupPath, newName); + auto action = std::make_unique(dataGroupPath, newName, allowOverwrite); OutputActions actions; actions.appendAction(std::move(action)); diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObjectFilter.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObjectFilter.hpp index 17b8067544..5dae8d2d44 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObjectFilter.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RenameDataObjectFilter.hpp @@ -25,6 +25,7 @@ class SIMPLNXCORE_EXPORT RenameDataObjectFilter : public IFilter RenameDataObjectFilter& operator=(RenameDataObjectFilter&&) noexcept = delete; // Parameter Keys + static inline constexpr StringLiteral k_AllowOverwrite_Key = "allow_overwrite"; static inline constexpr StringLiteral k_SourceDataObjectPath_Key = "source_data_object_path"; static inline constexpr StringLiteral k_NewName_Key = "new_name"; diff --git a/src/Plugins/SimplnxCore/test/RenameDataObjectTest.cpp b/src/Plugins/SimplnxCore/test/RenameDataObjectTest.cpp index a0283519b5..9ae87f46d9 100644 --- a/src/Plugins/SimplnxCore/test/RenameDataObjectTest.cpp +++ b/src/Plugins/SimplnxCore/test/RenameDataObjectTest.cpp @@ -72,13 +72,13 @@ TEST_CASE("SimplnxCore::RenameDataAction(Valid Overwrite)", "[SimplnxCore][Renam static constexpr StringLiteral k_NewName = Constants::k_GroupHName; static const DataPath k_DataPath({Constants::k_GroupAName, Constants::k_GroupCName, Constants::k_GroupDName, Constants::k_ArrayIName}); - RenameDataObject filter; + RenameDataObjectFilter filter; DataStructure dataStructure = UnitTest::CreateComplexMultiLevelDataGraph(); Arguments args; - args.insert(RenameDataObject::k_AllowOverwrite_Key, std::make_any(true)); - args.insert(RenameDataObject::k_NewName_Key, std::make_any(k_NewName)); - args.insert(RenameDataObject::k_SourceDataObjectPath_Key, std::make_any(k_DataPath)); + args.insert(RenameDataObjectFilter::k_AllowOverwrite_Key, std::make_any(true)); + args.insert(RenameDataObjectFilter::k_NewName_Key, std::make_any(k_NewName)); + args.insert(RenameDataObjectFilter::k_SourceDataObjectPath_Key, std::make_any(k_DataPath)); auto preflightResult = filter.preflight(dataStructure, args); SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); @@ -126,14 +126,14 @@ TEST_CASE("SimplnxCore::RenameDataAction(InValid Overwrite)", "[SimplnxCore][Ren static constexpr StringLiteral k_NewName = Constants::k_GroupDName; static const DataPath k_DataPath({Constants::k_GroupAName, Constants::k_GroupCName, Constants::k_GroupDName, Constants::k_ArrayIName}); - RenameDataObject filter; + RenameDataObjectFilter filter; DataStructure dataStructure = UnitTest::CreateComplexMultiLevelDataGraph(); Arguments args; - args.insert(RenameDataObject::k_AllowOverwrite_Key, std::make_any(true)); - args.insert(RenameDataObject::k_NewName_Key, std::make_any(k_NewName)); - args.insert(RenameDataObject::k_SourceDataObjectPath_Key, std::make_any(k_DataPath)); + args.insert(RenameDataObjectFilter::k_AllowOverwrite_Key, std::make_any(true)); + args.insert(RenameDataObjectFilter::k_NewName_Key, std::make_any(k_NewName)); + args.insert(RenameDataObjectFilter::k_SourceDataObjectPath_Key, std::make_any(k_DataPath)); auto preflightResult = filter.preflight(dataStructure, args); SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions);