Skip to content

Commit

Permalink
Clear command (#1836)
Browse files Browse the repository at this point in the history
Added clear command and test as suggested in issue #1810
  • Loading branch information
0xfedcafe authored Dec 30, 2024
1 parent 2be0ac5 commit 7770587
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 0 deletions.
1 change: 1 addition & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ f3d_test(NAME TestInteractionConsoleOpenWarningClick DATA f3d.glb ARGS --positio
f3d_test(NAME TestInteractionConsoleToggleGrid DATA f3d.glb INTERACTION UI) #Escape;toggle render.grid.enable;Return;Escape
f3d_test(NAME TestInteractionConsoleInvalidCommand DATA f3d.glb INTERACTION UI) #Escape;foo;Return
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

if (F3D_MODULE_TINYFILEDIALOGS)
Expand Down
2 changes: 2 additions & 0 deletions doc/user/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The libf3d provides a few commands, many related to manipulating libf3d (options

`reset option.name`: A command to reset a libf3d option to its default values, eg: `reset render.background.blur.coc`.

`clear`: A command to clear ImGui console. No argument.

`print option.name`: A command to print the value of an libf3d option, eg: `print scene.up.direction`.

`cycle_animation`: A specific command to cycle `scene.animation.index` option using model information, No argument.
Expand Down
16 changes: 16 additions & 0 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include "window_impl.h"

#include "vtkF3DConsoleOutputWindow.h"

#if F3D_MODULE_UI
#include "vtkF3DImguiConsole.h"
#endif

#include "vtkF3DInteractorEventRecorder.h"
#include "vtkF3DInteractorStyle.h"
#include "vtkF3DRenderer.h"
Expand Down Expand Up @@ -603,6 +608,17 @@ interactor& interactor_impl::initCommands()
check_args(args, 1, "reset");
this->Internals->Options.reset(args[0]);
});
this->addCommand("clear",
[&](const std::vector<std::string>& args)
{
check_args(args, 0, "clear");
#if F3D_MODULE_UI
vtkF3DImguiConsole* console =
vtkF3DImguiConsole::SafeDownCast(vtkOutputWindow::GetInstance());
assert(console != nullptr);
console->Clear();
#endif
});
this->addCommand("print",
[&](const std::vector<std::string>& args)
{
Expand Down
6 changes: 6 additions & 0 deletions library/testing/TestSDKInteractorCommand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ int TestSDKInteractorCommand(int argc, char* argv[])
inter.triggerCommand("reset render.hdri.file");
test("triggerCommand reset optional", options.render.hdri.file.has_value() == false);

// Test clear
#if F3D_MODULE_UI
inter.triggerCommand("print_scene_info");
test("triggerCommand clear", (inter.triggerCommand("clear") == true));
#endif

// Test toggle
inter.triggerCommand("toggle model.scivis.cells");
test("triggerCommand toggle", options.model.scivis.cells == true);
Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestInteractionConsoleClear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 125 additions & 0 deletions testing/recordings/TestInteractionConsoleClear.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# StreamVersion 1.2
RenderEvent 0 0 0 0 0 0 0

KeyPressEvent 0 0 0 27 1 Escape 0
CharEvent 0 0 0 27 1 Escape 0
KeyReleaseEvent 0 0 0 27 1 Escape 0

KeyPressEvent 0 0 0 101 1 e 0
CharEvent 0 0 0 101 1 e 0
KeyReleaseEvent 0 0 0 101 1 e 0

KeyPressEvent 0 0 0 27 1 Escape 0
CharEvent 0 0 0 27 1 Escape 0
KeyReleaseEvent 0 0 0 27 1 Escape 0

KeyPressEvent 0 0 0 112 1 p 0
CharEvent 0 0 0 112 1 p 0
KeyReleaseEvent 0 0 0 112 1 p 0

KeyPressEvent 0 0 0 114 1 r 0
CharEvent 0 0 0 114 1 r 0
KeyReleaseEvent 0 0 0 114 1 r 0

KeyPressEvent 0 0 0 105 1 i 0
CharEvent 0 0 0 105 1 i 0
KeyReleaseEvent 0 0 0 105 1 i 0

KeyPressEvent 0 0 0 110 1 n 0
CharEvent 0 0 0 110 1 n 0
KeyReleaseEvent 0 0 0 110 1 n 0

KeyPressEvent 0 0 0 116 1 t 0
CharEvent 0 0 0 116 1 t 0
KeyReleaseEvent 0 0 0 116 1 t 0

KeyPressEvent 0 0 0 116 1 t 0
CharEvent 0 0 0 116 1 t 0
KeyReleaseEvent 0 0 0 116 1 t 0

KeyPressEvent 0 0 0 8 1 BackSpace 0
CharEvent 0 0 0 8 1 BackSpace 0
KeyReleaseEvent 0 0 0 8 1 BackSpace 0

KeyPressEvent 0 0 1 0 1 Shift_L 0
KeyPressEvent 0 0 1 95 1 underscore 0
CharEvent 0 0 1 95 1 underscore 0
KeyReleaseEvent 0 0 1 95 1 underscore 0
KeyReleaseEvent 0 0 0 0 1 Shift_L 0

KeyPressEvent 0 0 0 115 1 s 0
CharEvent 0 0 0 115 1 s 0
KeyReleaseEvent 0 0 0 115 1 s 0

KeyPressEvent 0 0 0 99 1 c 0
CharEvent 0 0 0 99 1 c 0
KeyReleaseEvent 0 0 0 99 1 c 0

KeyPressEvent 0 0 0 101 1 e 0
CharEvent 0 0 0 101 1 e 0
KeyReleaseEvent 0 0 0 101 1 e 0

KeyPressEvent 0 0 0 101 1 e 0
CharEvent 0 0 0 101 1 e 0
KeyReleaseEvent 0 0 0 101 1 e 0

KeyPressEvent 0 0 0 0 1 Left 0
KeyReleaseEvent 0 0 0 0 1 Left 0

KeyPressEvent 0 0 0 110 1 n 0
CharEvent 0 0 0 110 1 n 0
KeyReleaseEvent 0 0 0 110 1 n 0

KeyPressEvent 0 0 0 0 1 Right 0
KeyReleaseEvent 0 0 0 0 1 Right 0

KeyPressEvent 0 0 1 0 1 Shift_L 0
KeyPressEvent 0 0 1 95 1 underscore 0
CharEvent 0 0 1 95 1 underscore 0
KeyReleaseEvent 0 0 1 95 1 underscore 0
KeyReleaseEvent 0 0 0 0 1 Shift_L 0

KeyPressEvent 0 0 0 105 1 i 0
CharEvent 0 0 0 105 1 i 0
KeyReleaseEvent 0 0 0 105 1 i 0

KeyPressEvent 0 0 0 110 1 n 0
CharEvent 0 0 0 110 1 n 0
KeyReleaseEvent 0 0 0 110 1 n 0

KeyPressEvent 0 0 0 102 1 f 0
CharEvent 0 0 0 102 1 f 0
KeyReleaseEvent 0 0 0 102 1 f 0

KeyPressEvent 0 0 0 111 1 o 0
CharEvent 0 0 0 111 1 o 0
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

KeyPressEvent 0 0 0 99 1 c 0
CharEvent 0 0 0 99 1 c 0
KeyReleaseEvent 0 0 0 99 1 c 0

KeyPressEvent 0 0 0 108 1 l 0
CharEvent 0 0 0 108 1 l 0
KeyReleaseEvent 0 0 0 108 1 l 0

KeyPressEvent 0 0 0 101 1 e 0
CharEvent 0 0 0 101 1 e 0
KeyReleaseEvent 0 0 0 101 1 e 0

KeyPressEvent 0 0 0 97 1 a 0
CharEvent 0 0 0 97 1 a 0
KeyReleaseEvent 0 0 0 97 1 a 0

KeyPressEvent 0 0 0 114 1 r 0
CharEvent 0 0 0 114 1 r 0
KeyReleaseEvent 0 0 0 114 1 r 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

8 changes: 8 additions & 0 deletions vtkext/private/module/vtkF3DImguiConsole.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,11 @@ void vtkF3DImguiConsole::ShowBadge()
ImGui::End();
}
}

//----------------------------------------------------------------------------
void vtkF3DImguiConsole::Clear()
{
this->Pimpl->Logs.clear();
this->Pimpl->NewError = false;
this->Pimpl->NewWarning = false;
}
5 changes: 5 additions & 0 deletions vtkext/private/module/vtkF3DImguiConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class vtkF3DImguiConsole : public vtkF3DConsoleOutputWindow
*/
void ShowBadge();

/**
* Clear console
*/
void Clear();

protected:
vtkF3DImguiConsole();
~vtkF3DImguiConsole() override;
Expand Down

0 comments on commit 7770587

Please sign in to comment.