Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias Command #1895

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
708924e
added alias mapping, new alias command, modified triggerCommand to ch…
void-inject Dec 20, 2024
58fd3bd
fixed declare error
void-inject Dec 20, 2024
5e914d1
reworked alias command
void-inject Jan 8, 2025
93eb9e1
test cver for alias
void-inject Jan 8, 2025
76f8666
resolve alias
void-inject Jan 8, 2025
829e014
here we go
void-inject Jan 8, 2025
854b1cc
refactored
void-inject Jan 8, 2025
e606595
added using addCommand
void-inject Jan 8, 2025
949913d
Refactored, deleted
void-inject Jan 8, 2025
c0bc7f7
aliasMap changed to AliasMap
void-inject Jan 8, 2025
2a3b0f8
redecleared AliasMap
void-inject Jan 8, 2025
44e0776
little test
void-inject Jan 9, 2025
d3589d5
action fixed
void-inject Jan 9, 2025
1fdad26
aliasCommand modified
void-inject Jan 9, 2025
bec0cc1
format fix
void-inject Jan 9, 2025
cacbe78
prevent recursion
void-inject Jan 9, 2025
ffd66ef
";" fixed
void-inject Jan 9, 2025
885195c
testcov for different situations
void-inject Jan 9, 2025
f145f69
first time taking error for white-space : )
void-inject Jan 9, 2025
f1bdd7c
white-space formated
void-inject Jan 9, 2025
ca3c54a
fixed declaration error
void-inject Jan 9, 2025
a6f8211
........................ ;)
void-inject Jan 9, 2025
98cb859
refactor
void-inject Jan 11, 2025
ceda6b3
Refactored according to suggestions
void-inject Jan 11, 2025
542b735
std::accumulate library import
void-inject Jan 11, 2025
a60c07a
Fix: format error && compile error
void-inject Jan 11, 2025
e382472
removed test for recursive_alias
void-inject Jan 11, 2025
06f791d
refactor
void-inject Jan 11, 2025
221aed9
Update library/src/interactor_impl.cxx
void-inject Jan 11, 2025
3f28d6e
Update library/src/interactor_impl.cxx
void-inject Jan 11, 2025
b672b08
Update library/src/interactor_impl.cxx
void-inject Jan 11, 2025
ebeea32
refactor
void-inject Jan 11, 2025
04ae5ef
Fix: stylecheck && log::info
void-inject Jan 11, 2025
cd46840
white-space
void-inject Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/private/interactor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class interactor_impl : public interactor
private:
class internals;
std::unique_ptr<internals> Internals;
std::unordered_map<std::string, std::string> AliasMap;
void-inject marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
Expand Down
50 changes: 49 additions & 1 deletion library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ class interactor_impl::internals
std::multimap<std::string, interaction_bind_t> GroupedBinds;
std::vector<std::string> OrderedBindGroups;

std::map<std::string, std::string> AliasMap;

vtkNew<vtkCellPicker> CellPicker;
vtkNew<vtkPointPicker> PointPicker;

Expand Down Expand Up @@ -762,6 +764,41 @@ interactor& interactor_impl::initCommands()
this->Internals->AnimationManager->StopAnimation();
this->Internals->Scene.add(files);
});

this->addCommand("alias",
[&](const std::vector<std::string>& args)
{
if (args.size() < 2)
{
throw interactor_impl::invalid_args_exception(
"alias command requires at least 2 arguments");
}
mwestphal marked this conversation as resolved.
Show resolved Hide resolved

// Validate the alias arguments
const std::string& aliasName = args[0];
// Combine all remaining arguments into the alias command
std::string aliasCommand;

for (size_t i = 1; i < args.size(); ++i)
{
if (i > 1)
{
aliasCommand += " ";
}
aliasCommand += args[i];
}
void-inject marked this conversation as resolved.
Show resolved Hide resolved

// Prevent recursion
if (aliasName == aliasCommand)
{
throw interactor_impl::invalid_args_exception(
"Alias cannot reference itself: " + aliasName);
}
void-inject marked this conversation as resolved.
Show resolved Hide resolved

// Add alias to the map
AliasMap[aliasName] = aliasCommand;
void-inject marked this conversation as resolved.
Show resolved Hide resolved
log::info("Alias added: ", aliasName, " → ", aliasCommand);
});
return *this;
}

Expand Down Expand Up @@ -817,7 +854,18 @@ bool interactor_impl::triggerCommand(std::string_view command)
return true;
}

const std::string& action = tokens[0];
std::string action = tokens[0];
void-inject marked this conversation as resolved.
Show resolved Hide resolved

// Resolve Alias
auto aliasIt = AliasMap.find(action);
if (aliasIt != AliasMap.end())
{
std::vector<std::string> aliasTokens = utils::tokenize(aliasIt->second);
tokens.erase(tokens.begin());
tokens.insert(tokens.begin(), aliasTokens.begin(), aliasTokens.end());
action = tokens[0];
}
void-inject marked this conversation as resolved.
Show resolved Hide resolved

try
{
// Find the right command to call
Expand Down
11 changes: 11 additions & 0 deletions library/testing/TestSDKInteractorCommand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ int TestSDKInteractorCommand(int argc, char* argv[])
inter.triggerCommand("toggle model.scivis.cells");
test("triggerCommand toggle", options.model.scivis.cells == true);

// Test alias command
inter.triggerCommand("alias axis_off set ui.axis off");
inter.triggerCommand("axis_off");
test("triggerCommand alias resolve", options.ui.axis == false);
bool alias_result;
alias_result = inter.triggerCommand("alias axis_off");
test("triggerCommand alias invalid args", alias_result == false);
inter.triggerCommand("alias recursive_alias recursive_alias");
alias_result = inter.triggerCommand("recursive_alias");
test("triggerCommand alias recursion handling", alias_result == false);

// triggerCommand error codepaths
test("triggerCommand toggle incompatible",
inter.triggerCommand("toggle scene.animation.index") == false);
Expand Down
Loading