Skip to content

Commit

Permalink
ENH: Updates array names to have padding digits for SplitAtributeArray.
Browse files Browse the repository at this point in the history
Allows the names to show in correct order when viewed in a user interface.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
  • Loading branch information
imikejackson committed Feb 18, 2025
1 parent 1278b47 commit 5cf5dc9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Uuid SplitAttributeArrayFilter::uuid() const
//------------------------------------------------------------------------------
std::string SplitAttributeArrayFilter::humanName() const
{
return "Split Multicomponent Attribute Array";
return "Split Multi component Attribute Array";
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -119,7 +119,7 @@ IFilter::PreflightResult SplitAttributeArrayFilter::preflightImpl(const DataStru
-65402, fmt::format("Selected component '{}' is not a valid component. Input array at path '{}' only has {} components, please choose a component number between 0 and {} to extract.",
comp, pInputArrayPath.toString(), numComponents, numComponents - 1)}})};
}
std::string arrayName = pInputArrayPath.getTargetName() + pPostfix + StringUtilities::number(compIndex);
std::string arrayName = pInputArrayPath.getTargetName() + pPostfix + StringUtilities::GenerateIndexString(compIndex, numComponents - 1);
DataPath newArrayPath = pInputArrayPath.replaceName(arrayName);
resultOutputActions.value().appendAction(std::make_unique<CreateArrayAction>(inputArray->getDataType(), tdims, cdims, newArrayPath));
}
Expand All @@ -128,7 +128,7 @@ IFilter::PreflightResult SplitAttributeArrayFilter::preflightImpl(const DataStru
{
for(usize i = 0; i < numComponents; i++)
{
std::string arrayName = pInputArrayPath.getTargetName() + pPostfix + StringUtilities::number(i);
std::string arrayName = pInputArrayPath.getTargetName() + pPostfix + StringUtilities::GenerateIndexString(i, numComponents - 1);
DataPath newArrayPath = pInputArrayPath.replaceName(arrayName);
resultOutputActions.value().appendAction(std::make_unique<CreateArrayAction>(inputArray->getDataType(), tdims, cdims, newArrayPath));
}
Expand Down
29 changes: 29 additions & 0 deletions src/simplnx/Utilities/StringUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <algorithm>
#include <array>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -509,4 +511,31 @@ inline std::vector<BestMatchType> FindBestMatches(const std::vector<std::string>
// return bestPairs;
return bestMatches;
}

/**
* @brief Creates a '0' padded string from a number based on maxIndex which dictates how many zeros there will be.
* @param index The index in the string
* @param maxIndex The max Index which determines the number of padding digits.
* @return String
*/
inline std::string GenerateIndexString(int32 index, int32 maxIndex)
{
std::string numStr = fmt::format("{}", index);

if(maxIndex >= 10)
{
int mag = 0;
int max = maxIndex;
while(max > 0)
{
mag++;
max = max / 10;
}
std::stringstream ss; // Create a QTextStream to set up the padding
ss << std::setw(mag) << std::setfill('0') << index;
numStr = ss.str();
}
return numStr;
}

} // namespace nx::core::StringUtilities

0 comments on commit 5cf5dc9

Please sign in to comment.