Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions c/interactor_c_api.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void f3d_interactor_init_bindings(f3d_interactor_t* interactor)
//----------------------------------------------------------------------------
void f3d_interactor_add_binding(f3d_interactor_t* interactor, const f3d_interaction_bind_t* bind,
const char** commands, int command_count, const char* group, f3d_interactor_binding_type_t type,
int notify)
int notify, int repeat)
{
if (!interactor || !bind || !commands || command_count <= 0)
{
Expand All @@ -520,7 +520,7 @@ void f3d_interactor_add_binding(f3d_interactor_t* interactor, const f3d_interact
try
{
cpp_interactor->addBinding(cpp_bind, cpp_commands, cpp_group, nullptr,
static_cast<f3d::interactor::BindingType>(type), notify != 0);
static_cast<f3d::interactor::BindingType>(type), notify != 0, repeat != 0);
}
catch (const f3d::interactor::already_exists_exception& ex)
{
Expand Down
3 changes: 2 additions & 1 deletion c/interactor_c_api.h
Comment thread
Meakk marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ extern "C"
* @param group Optional group name (can be NULL).
* @param type Optional binding type.
* @param notify Notify when the binding is triggered.
* @param repeat Binding is repeatedly applied when holding down the key.
*/
F3D_EXPORT void f3d_interactor_add_binding(f3d_interactor_t* interactor,
const f3d_interaction_bind_t* bind, const char** commands, int command_count, const char* group,
f3d_interactor_binding_type_t type, int notify);
f3d_interactor_binding_type_t type, int notify, int repeat);

/**
* @brief Remove a binding for the provided bind.
Expand Down
18 changes: 17 additions & 1 deletion c/testing/test_interactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ int test_interactor()
snprintf(ctrl_bind.inter, sizeof(ctrl_bind.inter), "A");
f3d_interaction_bind_format(&ctrl_bind, formatted, sizeof(formatted));

f3d_interaction_bind_t repeat_bind;
repeat_bind.mod = F3D_INTERACTION_BIND_NONE;
snprintf(repeat_bind.inter, sizeof(repeat_bind.inter), "r");
f3d_interaction_bind_format(&repeat_bind, formatted, sizeof(formatted));

f3d_interaction_bind_t parsed_bind;
f3d_interaction_bind_parse("Shift+B", &parsed_bind);

Expand All @@ -106,7 +111,10 @@ int test_interactor()
(void)less1;

const char* test_commands[] = { "test_action" };
f3d_interactor_add_binding(interactor, &bind, test_commands, 1, "test_group", F3D_INTERACTOR_BINDING_CYCLIC, 1);
f3d_interactor_add_binding(interactor, &bind, test_commands, 1, "test_group", F3D_INTERACTOR_BINDING_CYCLIC, 1, 0);

const char* test_commands_repeat[] = { "test_action_repeat" };
f3d_interactor_add_binding(interactor, &repeat_bind, test_commands_repeat, 1, "test_group", F3D_INTERACTOR_BINDING_NUMERICAL, 1, 1);

int group_count = 0;
char** groups = f3d_interactor_get_bind_groups(interactor, &group_count);
Expand Down Expand Up @@ -138,6 +146,14 @@ int test_interactor()

f3d_interactor_remove_binding(interactor, &bind);

f3d_binding_documentation_t doc_repeat;
f3d_interactor_get_binding_documentation(interactor, &repeat_bind, &doc_repeat);

f3d_interactor_binding_type_t binding_type_repeat = f3d_interactor_get_binding_type(interactor, &repeat_bind);
(void)binding_type_repeat;

f3d_interactor_remove_binding(interactor, &repeat_bind);

f3d_interactor_set_event_loop_user_callback(interactor, stop_callback, interactor);
f3d_interactor_start(interactor, 0.01);

Expand Down
8 changes: 4 additions & 4 deletions java/F3DInteractorBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ extern "C"
}

JNIEXPORT jobject JAVA_BIND(Interactor, addBindingCommands)(JNIEnv* env, jobject self,
jobject bind, jobject commands, jstring group, jobject type, jboolean notify)
jobject bind, jobject commands, jstring group, jobject type, jboolean notify, jboolean repeat)
{
f3d::interaction_bind_t nativeBind = JavaBindToNative(env, bind);

Expand Down Expand Up @@ -276,7 +276,7 @@ extern "C"
try
{
GetInteractor(env, self).addBinding(
nativeBind, commandsVec, groupCpp, nullptr, nativeType, notify);
nativeBind, commandsVec, groupCpp, nullptr, nativeType, notify, repeat);
}
catch (const f3d::interactor::already_exists_exception& e)
{
Expand All @@ -286,7 +286,7 @@ extern "C"
}

JNIEXPORT jobject JAVA_BIND(Interactor, addBindingCommand)(JNIEnv* env, jobject self,
jobject bind, jstring command, jstring group, jobject type, jboolean notify)
jobject bind, jstring command, jstring group, jobject type, jboolean notify, jboolean repeat)
{
f3d::interaction_bind_t nativeBind = JavaBindToNative(env, bind);

Expand Down Expand Up @@ -323,7 +323,7 @@ extern "C"
try
{
GetInteractor(env, self).addBinding(
nativeBind, commandCpp, groupCpp, nullptr, nativeType, notify);
nativeBind, commandCpp, groupCpp, nullptr, nativeType, notify, repeat);
}
catch (const f3d::interactor::already_exists_exception& e)
{
Expand Down
20 changes: 12 additions & 8 deletions java/Interactor.java
Comment thread
mwestphal marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ public boolean triggerCommand(String command) {
* @param group optional group name for organization
* @param type optional binding type
* @param notify notify when the binding is triggered
* @param repeat repeatedly apply binding when holding down key
* @return this interactor for method chaining
*/
private native Interactor addBindingCommands(InteractionBind bind, List<String> commands, String group, BindingType type, boolean notify);
private native Interactor addBindingCommands(InteractionBind bind, List<String> commands, String group, BindingType type, boolean notify, boolean repeat);

/**
* Add binding to trigger commands for a specific bind.
Expand All @@ -271,10 +272,11 @@ public boolean triggerCommand(String command) {
* @param group optional group name for organization
* @param type optional binding type
* @param notify notify when the binding is triggered
* @param repeat repeatedly apply binding when holding down key
* @return this interactor for method chaining
*/
public Interactor addBinding(InteractionBind bind, List<String> commands, String group, BindingType type, boolean notify) {
return addBindingCommands(bind, commands, group, type, notify);
public Interactor addBinding(InteractionBind bind, List<String> commands, String group, BindingType type, boolean notify, boolean repeat) {
return addBindingCommands(bind, commands, group, type, notify, repeat);
}

/**
Expand All @@ -285,7 +287,7 @@ public Interactor addBinding(InteractionBind bind, List<String> commands, String
* @return this interactor for method chaining
*/
public Interactor addBinding(InteractionBind bind, List<String> commands) {
return addBindingCommands(bind, commands, "", BindingType.OTHER, true);
return addBindingCommands(bind, commands, "", BindingType.OTHER, true, false);
}

/**
Expand All @@ -296,9 +298,10 @@ public Interactor addBinding(InteractionBind bind, List<String> commands) {
* @param group optional group name for organization
* @param type optional binding type
* @param notify notify when the binding is triggered
* @param repeat repeatedly apply binding when holding down key
* @return this interactor for method chaining
*/
private native Interactor addBindingCommand(InteractionBind bind, String command, String group, BindingType type, boolean notify);
private native Interactor addBindingCommand(InteractionBind bind, String command, String group, BindingType type, boolean notify, boolean repeat);

/**
* Add binding to trigger a single command for a specific bind.
Expand All @@ -308,10 +311,11 @@ public Interactor addBinding(InteractionBind bind, List<String> commands) {
* @param group optional group name for organization
* @param type optional binding type
* @param notify notify when the binding is triggered
* @param repeat repeatedly apply binding when holding down key
* @return this interactor for method chaining
*/
public Interactor addBinding(InteractionBind bind, String command, String group, BindingType type, boolean notify) {
return addBindingCommand(bind, command, group, type, notify);
public Interactor addBinding(InteractionBind bind, String command, String group, BindingType type, boolean notify, boolean repeat) {
return addBindingCommand(bind, command, group, type, notify, repeat);
}

/**
Expand All @@ -322,7 +326,7 @@ public Interactor addBinding(InteractionBind bind, String command, String group,
* @return this interactor for method chaining
*/
public Interactor addBinding(InteractionBind bind, String command) {
return addBindingCommand(bind, command, "", BindingType.OTHER, true);
return addBindingCommand(bind, command, "", BindingType.OTHER, true, false);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions java/testing/TestInteractor.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import app.f3d.F3D.*;
import java.util.List;

public class TestInteractor {

Expand Down Expand Up @@ -41,6 +42,17 @@ public static void main(String[] args) {
parsed.compareTo(parsed2);
parsed2.hashCode();

Interactor.InteractionBind repeatBind = new Interactor.InteractionBind();
repeatBind.mod = Interactor.ModifierKeys.NONE;
repeatBind.inter = "R";

interactor.addBinding(repeatBind, "test_command", "test_group", Interactor.BindingType.NUMERICAL, false, true);

List<Interactor.InteractionBind> testBindings = interactor.getBindsForGroup("test_group");
testBindings.stream().allMatch((binding) -> binding.equals(repeatBind));

interactor.removeBinding(repeatBind);

interactor.toggleAnimation();
interactor.toggleAnimation(Interactor.AnimationDirection.FORWARD);
interactor.toggleAnimation(Interactor.AnimationDirection.BACKWARD);
Expand Down
4 changes: 2 additions & 2 deletions library/private/interactor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class interactor_impl : public interactor
interactor& initBindings() override;
interactor& addBinding(const interaction_bind_t& bind, std::vector<std::string> commands,
std::string group = std::string(), documentation_callback_t documentationCallback = nullptr,
BindingType type = BindingType::OTHER, bool notify = true) override;
BindingType type = BindingType::OTHER, bool notify = true, bool repeat = false) override;
interactor& addBinding(const interaction_bind_t& bind, std::string command,
std::string group = std::string(), documentation_callback_t documentationCallback = nullptr,
BindingType type = BindingType::OTHER, bool notify = true) override;
BindingType type = BindingType::OTHER, bool notify = true, bool repeat = false) override;
interactor& removeBinding(const interaction_bind_t& bind) override;
std::vector<std::string> getBindGroups() const override;
std::vector<interaction_bind_t> getBindsForGroup(std::string group) const override;
Expand Down
10 changes: 6 additions & 4 deletions library/public/interactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ class F3D_EXPORT interactor
*
* If notify is true, a notification is triggered when pressing the binding
*
* If repeat is true, the binding is applied repeatedly when holding down the key
*
* Adding commands for an existing bind will throw a interactor::already_exists_exception.
*/
virtual interactor& addBinding(const interaction_bind_t& bind, std::vector<std::string> commands,
std::string group = {}, documentation_callback_t documentationCallback = nullptr,
BindingType type = BindingType::OTHER, bool notify = true) = 0;
BindingType type = BindingType::OTHER, bool notify = true, bool repeat = false) = 0;

/**
* See addBinding
Expand All @@ -202,17 +204,17 @@ class F3D_EXPORT interactor
*/
virtual interactor& addBinding(const interaction_bind_t& bind, std::string command,
std::string group = {}, documentation_callback_t documentationCallback = nullptr,
BindingType type = BindingType::OTHER, bool notify = true) = 0;
BindingType type = BindingType::OTHER, bool notify = true, bool repeat = false) = 0;

/**
* Convenience initializer list signature for add binding method
*/
interactor& addBinding(const interaction_bind_t& bind, std::initializer_list<std::string> list,
std::string group = {}, documentation_callback_t documentationCallback = nullptr,
BindingType type = BindingType::OTHER, bool notify = true)
BindingType type = BindingType::OTHER, bool notify = true, bool repeat = false)
{
return this->addBinding(bind, std::vector<std::string>(list), std::move(group),
std::move(documentationCallback), type, notify);
std::move(documentationCallback), type, notify, repeat);
}

/**
Expand Down
55 changes: 30 additions & 25 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class interactor_impl::internals
documentation_callback_t DocumentationCallback;
BindingType Type;
bool Notify;
bool Repeat;
};

struct CommandCallbacks
Expand Down Expand Up @@ -496,33 +497,36 @@ class interactor_impl::internals
// invalidating any references/iterators into it.
const BindingCommands binding = commandsIt->second;

for (const std::string& command : binding.CommandVector)
if (binding.Repeat || rwi->GetRepeatCount() <= 1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with <= here in case VTK can support starting the repeat count at 0. Can switch the logic if we'd like.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need updated once VTK changes indeed.

{
std::string commandWithArgs = command;
if (!argsString.empty())
for (const std::string& command : binding.CommandVector)
{
commandWithArgs.push_back(' ');
commandWithArgs.append(argsString);
};
try
{
// XXX: Ignore the boolean return of triggerCommand,
// error is already logged by triggerCommand
this->Interactor.triggerCommand(commandWithArgs);
std::string commandWithArgs = command;
if (!argsString.empty())
{
commandWithArgs.push_back(' ');
commandWithArgs.append(argsString);
};
try
{
// XXX: Ignore the boolean return of triggerCommand,
// error is already logged by triggerCommand
this->Interactor.triggerCommand(commandWithArgs);
}
catch (const f3d::interactor::command_runtime_exception& ex)
{
log::error(
"Interaction: error running command: \"" + commandWithArgs + "\": " + ex.what());
}
}
catch (const f3d::interactor::command_runtime_exception& ex)

if (binding.Notify && binding.DocumentationCallback)
{
log::error(
"Interaction: error running command: \"" + commandWithArgs + "\": " + ex.what());
// trigger notification
auto [desc, value] = binding.DocumentationCallback();
this->AddNotification(desc, value, bind.format(), 3.0);
}
}

if (binding.Notify && binding.DocumentationCallback)
{
// trigger notification
auto [desc, value] = binding.DocumentationCallback();
this->AddNotification(desc, value, bind.format(), 3.0);
}
}

// Update the dynamic options of the animation manager so check if the cheatsheet needs an
Expand Down Expand Up @@ -1707,10 +1711,10 @@ interactor& interactor_impl::initBindings()
//----------------------------------------------------------------------------
interactor& interactor_impl::addBinding(const interaction_bind_t& bind,
std::vector<std::string> commands, std::string group,
documentation_callback_t documentationCallback, BindingType type, bool notify)
documentation_callback_t documentationCallback, BindingType type, bool notify, bool repeat)
{
const auto [it, success] = this->Internals->Bindings.insert(
{ bind, { std::move(commands), std::move(documentationCallback), type, notify } });
{ bind, { std::move(commands), std::move(documentationCallback), type, notify, repeat } });
if (!success)
{
throw interactor::already_exists_exception(
Expand All @@ -1732,10 +1736,11 @@ interactor& interactor_impl::addBinding(const interaction_bind_t& bind,

//----------------------------------------------------------------------------
interactor& interactor_impl::addBinding(const interaction_bind_t& bind, std::string command,
std::string group, documentation_callback_t documentationCallback, BindingType type, bool notify)
std::string group, documentation_callback_t documentationCallback, BindingType type, bool notify,
bool repeat)
{
return this->addBinding(bind, std::vector<std::string>{ std::move(command) }, std::move(group),
std::move(documentationCallback), type, notify);
std::move(documentationCallback), type, notify, repeat);
}

//----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions library/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
list(APPEND libf3dSDKTests_list
TestPseudoUnitTest.cxx
TestSDKAnimation.cxx
TestSDKBindingRepeat.cxx
TestSDKCamera.cxx
TestSDKCompareWithFile.cxx
TestSDKDynamicLightIntensity.cxx
Expand Down
Loading