Skip to content

Commit

Permalink
Console: Run console provided command in eventLoop using a buffer (#1899
Browse files Browse the repository at this point in the history
)

 - Add an internal API to setCommandBuffer
 - Use the API when trigger a command from console
 - actuall call triggerCommand in the event loop
  - Extensive testing
     - reload_current_file_groups
     - toggle_volume_rendering
     - set_camera top
  • Loading branch information
mwestphal authored Jan 11, 2025
1 parent b019130 commit 456f0f2
Show file tree
Hide file tree
Showing 17 changed files with 563 additions and 1 deletion.
4 changes: 4 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,10 @@ f3d_test(NAME TestInteractionConsoleInvalidCommand DATA f3d.glb INTERACTION UI)
f3d_test(NAME TestInteractionConsoleInvalidOption DATA f3d.glb INTERACTION UI) #Escape;toggle foo;Return
f3d_test(NAME TestInteractionConsoleClear DATA dragon.vtu INTERACTION UI) #Escape;e;Escape;printt;BackSpace;_scee;Left;n;Right;_info;Return;clear;Return
f3d_test(NAME TestInteractionConsoleTypingSceneInfo DATA f3d.glb INTERACTION UI) #Escape;e;Escape;printt;BackSpace;_scee;Left;Right;_info;Return
f3d_test(NAME TestInteractionConsoleReload DATA f3d.glb INTERACTION UI) #Escape;reload_current_file_group;Return
f3d_test(NAME TestInteractionConsoleLoadNext DATA f3d.glb cow.vtp INTERACTION UI) #Escape;load_next_file_group;Return
f3d_test(NAME TestInteractionConsoleRender ARGS --coloring-by-cells DATA waveletMaterial.vti INTERACTION UI) #Escape;toggle_volume_rendering;Return
f3d_test(NAME TestInteractionConsoleCamera DATA f3d.glb INTERACTION UI) #Escape;set_camera top;Return

if (F3D_MODULE_TINYFILEDIALOGS)
f3d_test(NAME TestInteractionFileOpen INTERACTION NO_BASELINE ENV CTEST_OPEN_DIALOG_FILE=${F3D_SOURCE_DIR}/testing/data/cow.vtp)
Expand Down
5 changes: 5 additions & 0 deletions library/private/interactor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class interactor_impl : public interactor
*/
void EventLoop();

/**
* Set a command to be run on the next event loop
*/
void SetCommandBuffer(const char* command);

/**
* An exception that can be thrown by certain command callbacks
* when the arguments of the callback are incorrect and expected
Expand Down
16 changes: 15 additions & 1 deletion library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class interactor_impl::internals
if (event == vtkF3DConsoleOutputWindow::TriggerEvent)
{
const char* commandWithArgs = static_cast<const char*>(data);
self->Interactor.triggerCommand(commandWithArgs);
self->Interactor.SetCommandBuffer(commandWithArgs);
}
else if (event == vtkF3DConsoleOutputWindow::ShowEvent ||
event == vtkF3DConsoleOutputWindow::HideEvent)
Expand Down Expand Up @@ -516,6 +516,12 @@ class interactor_impl::internals
this->EventLoopUserCallBack();
}

if (this->CommandBuffer.has_value())
{
this->Interactor.triggerCommand(this->CommandBuffer.value());
this->CommandBuffer.reset();
}

this->AnimationManager->Tick();

if (this->RenderRequested)
Expand Down Expand Up @@ -543,6 +549,7 @@ class interactor_impl::internals
std::map<unsigned long, std::pair<int, std::function<void()>>> TimerCallBacks;

std::map<std::string, std::function<void(const std::vector<std::string>&)>> Commands;
std::optional<std::string> CommandBuffer;

std::map<interaction_bind_t, BindingCommands> Bindings;
std::multimap<std::string, interaction_bind_t> GroupedBinds;
Expand Down Expand Up @@ -1254,6 +1261,13 @@ void interactor_impl::UpdateRendererAfterInteraction()
this->Internals->Style->UpdateRendererAfterInteraction();
}

//----------------------------------------------------------------------------
void interactor_impl::SetCommandBuffer(const char* command)
{
// XXX This replace previous command buffer, it should be improved
this->Internals->CommandBuffer = command;
}

//----------------------------------------------------------------------------
interactor_impl::invalid_args_exception::invalid_args_exception(const std::string& what)
: exception(what)
Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestInteractionConsoleCamera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestInteractionConsoleLoadNext.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestInteractionConsoleReload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestInteractionConsoleRender.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions testing/recordings/TestInteractionConsoleCamera.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# StreamVersion 1.2
ConfigureEvent 1249 1374 0 0 0 0 0
ExposeEvent 0 1406 0 0 0 0 0
RenderEvent 0 1406 0 0 0 0 0

KeyPressEvent -763 401 0 27 1 Escape 0
CharEvent -763 401 0 27 1 Escape 0
KeyReleaseEvent -763 401 0 27 1 Escape 0

KeyPressEvent -763 401 0 115 1 s 0
CharEvent -763 401 0 115 1 s 0
KeyReleaseEvent -763 401 0 115 1 s 0

KeyPressEvent -763 401 0 101 1 e 0
CharEvent -763 401 0 101 1 e 0
KeyReleaseEvent -763 401 0 101 1 e 0

KeyPressEvent -763 401 0 116 1 t 0
CharEvent -763 401 0 116 1 t 0
KeyReleaseEvent -763 401 0 116 1 t 0

KeyPressEvent -763 401 1 95 1 underscore 0
CharEvent -763 401 1 95 1 underscore 0
KeyReleaseEvent -763 401 1 95 1 underscore 0

KeyPressEvent -763 401 0 99 1 c 0
CharEvent -763 401 0 99 1 c 0
KeyReleaseEvent -763 401 0 99 1 c 0

KeyPressEvent -763 401 0 97 1 a 0
CharEvent -763 401 0 97 1 a 0
KeyReleaseEvent -763 401 0 97 1 a 0

KeyPressEvent -763 401 0 109 1 m 0
CharEvent -763 401 0 109 1 m 0
KeyReleaseEvent -763 401 0 109 1 m 0

KeyPressEvent -763 401 0 101 1 e 0
CharEvent -763 401 0 101 1 e 0
KeyReleaseEvent -763 401 0 101 1 e 0

KeyPressEvent -763 401 0 114 1 r 0
CharEvent -763 401 0 114 1 r 0
KeyReleaseEvent -763 401 0 114 1 r 0

KeyPressEvent -763 401 0 97 1 a 0
CharEvent -763 401 0 97 1 a 0
KeyReleaseEvent -763 401 0 97 1 a 0

KeyPressEvent -763 401 0 32 1 space 0
CharEvent -763 401 0 32 1 space 0
KeyReleaseEvent -763 401 0 32 1 space 0

KeyPressEvent -763 401 0 116 1 t 0
CharEvent -763 401 0 116 1 t 0
KeyReleaseEvent -763 401 0 116 1 t 0

KeyPressEvent -763 401 0 111 1 o 0
CharEvent -763 401 0 111 1 o 0
KeyReleaseEvent -763 401 0 111 1 o 0

KeyPressEvent -763 401 0 112 1 p 0
CharEvent -763 401 0 112 1 p 0
KeyReleaseEvent -763 401 0 112 1 p 0

KeyPressEvent -763 401 0 13 1 Return 0
CharEvent -763 401 0 13 1 Return 0
KeyReleaseEvent -763 401 0 13 1 Return 0

KeyPressEvent -763 401 0 27 1 Escape 0
CharEvent -763 401 0 27 1 Escape 0
KeyReleaseEvent -763 401 0 27 1 Escape 0

TimerEvent 212 76 0 27 1 Escape 0
1 change: 1 addition & 0 deletions testing/recordings/TestInteractionConsoleClear.log
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ KeyPressEvent 0 0 0 13 1 Return 0
CharEvent 0 0 0 13 1 Return 0
KeyReleaseEvent 0 0 0 13 1 Return 0

TimerEvent 351 169 0 0 0 0 0
2 changes: 2 additions & 0 deletions testing/recordings/TestInteractionConsoleInvalidCommand.log
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ KeyReleaseEvent 0 0 0 111 1 o 0
KeyPressEvent 0 0 0 13 1 Return 0
CharEvent 0 0 0 13 1 Return 0
KeyReleaseEvent 0 0 0 13 1 Return 0

TimerEvent 351 169 0 0 0 0 0
2 changes: 2 additions & 0 deletions testing/recordings/TestInteractionConsoleInvalidOption.log
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ KeyReleaseEvent 0 0 0 111 1 o 0
KeyPressEvent 0 0 0 13 1 Return 0
CharEvent 0 0 0 13 1 Return 0
KeyReleaseEvent 0 0 0 13 1 Return 0

TimerEvent 351 169 0 0 0 0 0
98 changes: 98 additions & 0 deletions testing/recordings/TestInteractionConsoleLoadNext.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# StreamVersion 1.2
ConfigureEvent 1249 1374 0 0 0 0 0
ExposeEvent 0 1406 0 0 0 0 0
RenderEvent 0 1406 0 0 0 0 0

KeyPressEvent -179 393 0 27 1 Escape 0
CharEvent -179 393 0 27 1 Escape 0
KeyReleaseEvent -179 393 0 27 1 Escape 0

KeyPressEvent -179 393 0 108 1 l 0
CharEvent -179 393 0 108 1 l 0
KeyReleaseEvent -179 393 0 108 1 l 0

KeyPressEvent -179 393 0 111 1 o 0
CharEvent -179 393 0 111 1 o 0
KeyReleaseEvent -179 393 0 111 1 o 0

KeyPressEvent -179 393 0 97 1 a 0
CharEvent -179 393 0 97 1 a 0
KeyReleaseEvent -179 393 0 97 1 a 0

KeyPressEvent -179 393 0 100 1 d 0
CharEvent -179 393 0 100 1 d 0
KeyReleaseEvent -179 393 0 100 1 d 0

KeyPressEvent -179 393 1 95 1 underscore 0
CharEvent -179 393 1 95 1 underscore 0
KeyReleaseEvent -179 393 1 95 1 underscore 0

KeyPressEvent -179 393 0 110 1 n 0
CharEvent -179 393 0 110 1 n 0
KeyReleaseEvent -179 393 0 110 1 n 0

KeyPressEvent -179 393 0 101 1 e 0
CharEvent -179 393 0 101 1 e 0
KeyReleaseEvent -179 393 0 101 1 e 0

KeyPressEvent -179 393 0 120 1 x 0
CharEvent -179 393 0 120 1 x 0
KeyReleaseEvent -179 393 0 120 1 x 0

KeyPressEvent -179 393 0 116 1 t 0
CharEvent -179 393 0 116 1 t 0
KeyReleaseEvent -179 393 0 116 1 t 0

KeyPressEvent -179 393 1 95 1 underscore 0
CharEvent -179 393 1 95 1 underscore 0
KeyReleaseEvent -179 393 1 95 1 underscore 0

KeyPressEvent -179 393 0 102 1 f 0
CharEvent -179 393 0 102 1 f 0
KeyReleaseEvent -179 393 0 102 1 f 0

KeyPressEvent -179 393 0 105 1 i 0
CharEvent -179 393 0 105 1 i 0
KeyReleaseEvent -179 393 0 105 1 i 0

KeyPressEvent -179 393 0 108 1 l 0
CharEvent -179 393 0 108 1 l 0
KeyReleaseEvent -179 393 0 108 1 l 0

KeyPressEvent -179 393 0 101 1 e 0
CharEvent -179 393 0 101 1 e 0
KeyReleaseEvent -179 393 0 101 1 e 0

KeyPressEvent -179 393 1 95 1 underscore 0
CharEvent -179 393 1 95 1 underscore 0
KeyReleaseEvent -179 393 1 95 1 underscore 0

KeyPressEvent -179 393 0 103 1 g 0
CharEvent -179 393 0 103 1 g 0
KeyReleaseEvent -179 393 0 103 1 g 0

KeyPressEvent -179 393 0 114 1 r 0
CharEvent -179 393 0 114 1 r 0
KeyReleaseEvent -179 393 0 114 1 r 0

KeyPressEvent -179 393 0 111 1 o 0
CharEvent -179 393 0 111 1 o 0
KeyReleaseEvent -179 393 0 111 1 o 0

KeyPressEvent -179 393 0 117 1 u 0
CharEvent -179 393 0 117 1 u 0
KeyReleaseEvent -179 393 0 117 1 u 0

KeyPressEvent -179 393 0 112 1 p 0
CharEvent -179 393 0 112 1 p 0
KeyReleaseEvent -179 393 0 112 1 p 0

KeyPressEvent -179 393 0 13 1 Return 0
CharEvent -179 393 0 13 1 Return 0
KeyReleaseEvent -179 393 0 13 1 Return 0

KeyPressEvent -179 393 0 27 1 Escape 0
CharEvent -179 393 0 27 1 Escape 0
KeyReleaseEvent -179 393 0 27 1 Escape 0

TimerEvent 212 76 0 27 1 Escape 0
2 changes: 2 additions & 0 deletions testing/recordings/TestInteractionConsoleOpenExit.log
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ KeyReleaseEvent 199 142 0 116 1 t 0
KeyPressEvent 199 142 0 13 1 Return 0
CharEvent 199 142 0 13 1 Return 0
KeyReleaseEvent 199 142 0 13 1 Return 0

TimerEvent 351 169 0 0 0 0 0
118 changes: 118 additions & 0 deletions testing/recordings/TestInteractionConsoleReload.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# StreamVersion 1.2
ConfigureEvent 1249 1374 0 0 0 0 0
ExposeEvent 0 1406 0 0 0 0 0
RenderEvent 0 1406 0 0 0 0 0

KeyPressEvent -740 995 0 27 1 Escape 0
CharEvent -740 995 0 27 1 Escape 0
KeyReleaseEvent -740 995 0 27 1 Escape 0

KeyPressEvent -740 995 0 114 1 r 0
CharEvent -740 995 0 114 1 r 0
KeyReleaseEvent -740 995 0 114 1 r 0

KeyPressEvent -740 995 0 101 1 e 0
CharEvent -740 995 0 101 1 e 0
KeyReleaseEvent -740 995 0 101 1 e 0

KeyPressEvent -740 995 0 108 1 l 0
CharEvent -740 995 0 108 1 l 0
KeyReleaseEvent -740 995 0 108 1 l 0

KeyPressEvent -740 995 0 111 1 o 0
CharEvent -740 995 0 111 1 o 0
KeyReleaseEvent -740 995 0 111 1 o 0

KeyPressEvent -740 995 0 97 1 a 0
CharEvent -740 995 0 97 1 a 0
KeyReleaseEvent -740 995 0 97 1 a 0

KeyPressEvent -740 995 0 100 1 d 0
CharEvent -740 995 0 100 1 d 0
KeyReleaseEvent -740 995 0 100 1 d 0

KeyPressEvent -740 995 1 95 1 underscore 0
CharEvent -740 995 1 95 1 underscore 0
KeyReleaseEvent -740 995 1 95 1 underscore 0

KeyPressEvent -740 995 0 99 1 c 0
CharEvent -740 995 0 99 1 c 0
KeyReleaseEvent -740 995 0 99 1 c 0

KeyPressEvent -740 995 0 117 1 u 0
CharEvent -740 995 0 117 1 u 0
KeyReleaseEvent -740 995 0 117 1 u 0

KeyPressEvent -740 995 0 114 1 r 0
CharEvent -740 995 0 114 1 r 0
KeyReleaseEvent -740 995 0 114 1 r 0

KeyPressEvent -740 995 0 114 1 r 0
CharEvent -740 995 0 114 1 r 0
KeyReleaseEvent -740 995 0 114 1 r 0

KeyPressEvent -740 995 0 101 1 e 0
CharEvent -740 995 0 101 1 e 0
KeyReleaseEvent -740 995 0 101 1 e 0

KeyPressEvent -740 995 0 110 1 n 0
CharEvent -740 995 0 110 1 n 0
KeyReleaseEvent -740 995 0 110 1 n 0

KeyPressEvent -740 995 0 116 1 t 0
CharEvent -740 995 0 116 1 t 0
KeyReleaseEvent -740 995 0 116 1 t 0

KeyPressEvent -740 995 1 95 1 underscore 0
CharEvent -740 995 1 95 1 underscore 0
KeyReleaseEvent -740 995 1 95 1 underscore 0

KeyPressEvent -740 995 0 102 1 f 0
CharEvent -740 995 0 102 1 f 0
KeyReleaseEvent -740 995 0 102 1 f 0

KeyPressEvent -740 995 0 105 1 i 0
CharEvent -740 995 0 105 1 i 0
KeyReleaseEvent -740 995 0 105 1 i 0

KeyPressEvent -740 995 0 108 1 l 0
CharEvent -740 995 0 108 1 l 0
KeyReleaseEvent -740 995 0 108 1 l 0

KeyPressEvent -740 995 0 101 1 e 0
CharEvent -740 995 0 101 1 e 0
KeyReleaseEvent -740 995 0 101 1 e 0

KeyPressEvent -740 995 1 95 1 underscore 0
CharEvent -740 995 1 95 1 underscore 0
KeyReleaseEvent -740 995 1 95 1 underscore 0

KeyPressEvent -740 995 0 103 1 g 0
CharEvent -740 995 0 103 1 g 0
KeyReleaseEvent -740 995 0 103 1 g 0

KeyPressEvent -740 995 0 114 1 r 0
CharEvent -740 995 0 114 1 r 0
KeyReleaseEvent -740 995 0 114 1 r 0

KeyPressEvent -740 995 0 111 1 o 0
CharEvent -740 995 0 111 1 o 0
KeyReleaseEvent -740 995 0 111 1 o 0

KeyPressEvent -740 995 0 117 1 u 0
CharEvent -740 995 0 117 1 u 0
KeyReleaseEvent -740 995 0 117 1 u 0

KeyPressEvent -740 995 0 112 1 p 0
CharEvent -740 995 0 112 1 p 0
KeyReleaseEvent -740 995 0 112 1 p 0

KeyPressEvent -740 995 0 13 1 Return 0
CharEvent -740 995 0 13 1 Return 0
KeyReleaseEvent -740 995 0 13 1 Return 0

KeyPressEvent -740 995 0 27 1 Escape 0
CharEvent -740 995 0 27 1 Escape 0
KeyReleaseEvent -740 995 0 27 1 Escape 0

TimerEvent 212 76 0 27 1 Escape 0
Loading

0 comments on commit 456f0f2

Please sign in to comment.