From c6e8431d6498820928c1559abd92939de2fdcdb9 Mon Sep 17 00:00:00 2001 From: Uwe Fechner Date: Sat, 23 Mar 2024 12:11:32 +0100 Subject: [PATCH] Toggle RUN_PAUSE button --- mwes/mwe_03.jl | 5 +++++ src/KiteViewers.jl | 6 +++--- src/viewer3D.jl | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 mwes/mwe_03.jl diff --git a/mwes/mwe_03.jl b/mwes/mwe_03.jl new file mode 100644 index 0000000..1c1fe72 --- /dev/null +++ b/mwes/mwe_03.jl @@ -0,0 +1,5 @@ +using KiteViewers +Viewer3D() + +# KiteViewers.running[]=true +nothing \ No newline at end of file diff --git a/src/KiteViewers.jl b/src/KiteViewers.jl index 87729df..b74c558 100644 --- a/src/KiteViewers.jl +++ b/src/KiteViewers.jl @@ -5,8 +5,8 @@ using GeometryBasics, Rotations, GLMakie, FileIO, LinearAlgebra, Printf, Paramet import GeometryBasics:Point3f, GeometryBasics.Point2f using KiteUtils -export Viewer3D, AbstractKiteViewer, AKV # types -export clear_viewer, update_system, save_png, stop, set_status # functions +export Viewer3D, AbstractKiteViewer, AKV # types +export clear_viewer, update_system, save_png, stop, pause, set_status # functions @reexport using GLMakie: on const KITE_SPRINGS = 8 @@ -32,7 +32,7 @@ end @compile_workload begin # all calls in this block will be precompiled, regardless of whether # they belong to your package or not (on Julia 1.8 and higher) - viewer=Viewer3D(true) + viewer=Viewer3D(true; precompile=true) segments=6 state=demo_state_4p(segments+1) update_system(viewer, state, kite_scale=0.25) diff --git a/src/viewer3D.jl b/src/viewer3D.jl index bc9cfb1..48b3a35 100644 --- a/src/viewer3D.jl +++ b/src/viewer3D.jl @@ -98,11 +98,16 @@ function stop(kv::AKV) status[]="Stopped" end +function pause(kv::AKV) + kv.stop = true + status[]="Paused" +end + function set_status(kv::AKV, status_text) status[] = status_text end -function Viewer3D(show_kite=true, autolabel="Autopilot") +function Viewer3D(show_kite=true, autolabel="Autopilot"; precompile=false) fig = Figure(size=(840, 900), backgroundcolor=RGBf(0.7, 0.8, 1)) sub_fig = fig[1,1] scene2D = LScene(fig[3,1], show_axis=false, height=16) @@ -135,7 +140,11 @@ function Viewer3D(show_kite=true, autolabel="Autopilot") btn_RESET = Button(sub_fig, label = "RESET") btn_ZOOM_in = Button(sub_fig, label = "Zoom +") btn_ZOOM_out = Button(sub_fig, label = "Zoom -") - btn_PLAY_PAUSE = Button(sub_fig, label = @lift($running ? "PAUSE" : " RUN ")) + if precompile + btn_PLAY_PAUSE = Button(sub_fig, label = " RUN ") + else + btn_PLAY_PAUSE = Button(sub_fig, label = @lift($running ? "PAUSE" : " RUN ")) + end btn_AUTO = Button(sub_fig, label = autolabel) btn_PARKING = Button(sub_fig, label = "Parking") btn_STOP = Button(sub_fig, label = "STOP") @@ -174,6 +183,9 @@ function Viewer3D(show_kite=true, autolabel="Autopilot") on(s.btn_STOP.clicks) do c stop(s) end + on(s.btn_PLAY.clicks) do c + running[] = ! running[] + end status[] = "Stopped" s end