Skip to content

Commit

Permalink
Unfinished command
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Nov 25, 2023
1 parent 610b202 commit 7a4621b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/private/interactor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class interactor_impl : public interactor
interactor& setKeyPressCallBack(std::function<bool(int, std::string)> callBack) override;
interactor& setDropFilesCallBack(std::function<bool(std::vector<std::string>)> callBack) override;

interactor& command(const std::string& command) override;

unsigned long createTimerCallBack(double time, std::function<void()> callBack) override;
void removeTimerCallBack(unsigned long id) override;

Expand Down
1 change: 1 addition & 0 deletions library/public/interactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class F3D_EXPORT interactor
*/
virtual interactor& addKeyPressToggle(const std::string& keySym, ModifierKeys modifiers, const std::string& option) = 0;

virtual interactor& command(const std::string& command) = 0;
virtual interactor& addDefaultKeyPressInteractions();

/**
Expand Down
62 changes: 62 additions & 0 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
#include <vtkVersion.h>
#include <vtksys/SystemTools.hxx>

#include <algorithm>
#include <chrono>
#include <cmath>
#include <map>
#include <vector>

#include "camera.h"

Expand Down Expand Up @@ -805,4 +807,64 @@ void interactor_impl::UpdateRendererAfterInteraction()
{
this->Internals->Style->UpdateRendererAfterInteraction();
}

//----------------------------------------------------------------------------
interactor& command(const std::string& commandString)
{
// Split command with space
std::string temp;
std::stringstream stringstream { commandString };
std::vector<std::string> result;
while (std::getline(stringstream, temp, ' '))
{
result.push_back(temp);
}

size_t nTokens = result.size();
if (nTokens > 3 || nTokens == 0)
{
log::error("Command: \"", commandString, "\" contains incorrect number of tokens, ignoring");
return this;
}

std::string command = results[0];
std::string option = nTokens >= 1 ? results[1] : "";
std::string value = nTokens >= 2 ? results[2] : "";

// Identify command
if (command == "set")
{
// TODO add alias support

// TODO do we want a map ?
std::vector<std::string> optionNames = this->Internals->Options->getNames();
if(std::find(optionNames.begin(), optionNames.end(), option) == vec.end())
{
log::error("Option: \"", option, "\" is not valid, ignoring");
return this;
}

}
else if (command == "inc")
{
}
else if (command == "dec")
{
}
else if (command == "toggle")
{
}
else if (command == "print")
{
}
else if (command == "alias")
{
}
else
{
log::error("Command: \"", command, "\" is not recognized, ignoring");
return this;
}

}
}

0 comments on commit 7a4621b

Please sign in to comment.