Skip to content

Commit

Permalink
Toggle RUN_PAUSE button
Browse files Browse the repository at this point in the history
  • Loading branch information
ufechner7 committed Mar 23, 2024
1 parent 8222f6a commit c6e8431
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions mwes/mwe_03.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using KiteViewers
Viewer3D()

# KiteViewers.running[]=true
nothing
6 changes: 3 additions & 3 deletions src/KiteViewers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions src/viewer3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c6e8431

Please sign in to comment.