diff --git a/src/MG2D/grav/grav_utils.jl b/src/MG2D/grav/grav_utils.jl index 9bb122b..607a6e1 100644 --- a/src/MG2D/grav/grav_utils.jl +++ b/src/MG2D/grav/grav_utils.jl @@ -74,10 +74,12 @@ function printgravmodparinfo(mstart,bodyindices,grav_whichpar,mlow,mup) println(" ---------------------------------------------------") printstyled(" Lower constraints for model parameters:\n",bold=true,color=:light_cyan) - pretty_table(vecparl, noheader = true, crop = :horizontal, formatters = ft_round(3)) + pretty_table(vecparl, formatters = [fmt__round(3)]) + #pretty_table(vecparl, noheader = true, crop = :horizontal, formatters = ft_round(3)) printstyled(" Upper constraints for model parameters:\n",bold=true,color=:light_cyan) - pretty_table(vecparu, noheader = true, crop = :horizontal, formatters = ft_round(3)) + pretty_table(vecparu, formatters = [fmt__round(3)]) + #pretty_table(vecparu, noheader = true, crop = :horizontal, formatters = ft_round(3)) return nothing end diff --git a/src/MG2D/joint/joint_utils.jl b/src/MG2D/joint/joint_utils.jl index 9914ab5..8dc8850 100644 --- a/src/MG2D/joint/joint_utils.jl +++ b/src/MG2D/joint/joint_utils.jl @@ -69,10 +69,12 @@ function printjointmodparinfo(mstart,bodyindices,mag_whichpar,grav_whichpar,mlow println(" ---------------------------------------------------") printstyled(" Lower constraints for model parameters:\n",bold=true,color=:light_cyan) - pretty_table(vecparl, noheader = true, crop = :horizontal, formatters = ft_round(3)) + pretty_table(vecparl, formatters = [fmt__round(3)]) + #pretty_table(vecparl, noheader = true, crop = :horizontal, formatters = ft_round(3)) printstyled(" Upper constraints for model parameters:\n",bold=true,color=:light_cyan) - pretty_table(vecparu, noheader = true, crop = :horizontal, formatters = ft_round(3)) + pretty_table(vecparu, formatters = [fmt__round(3)]) + #pretty_table(vecparu, noheader = true, crop = :horizontal, formatters = ft_round(3)) return nothing end diff --git a/src/MG2D/mag/mag_utils.jl b/src/MG2D/mag/mag_utils.jl index a3901fc..76d9f5f 100644 --- a/src/MG2D/mag/mag_utils.jl +++ b/src/MG2D/mag/mag_utils.jl @@ -151,10 +151,12 @@ function printmagmodparinfo(mstart,bodyindices,mag_whichpar,mlow,mup) println(" ---------------------------------------------------") printstyled(" Lower constraints for model parameters:\n",bold=true,color=:light_cyan) - pretty_table(vecparl, noheader = true, crop = :horizontal, formatters = ft_round(3)) + pretty_table(vecparl, formatters = [fmt__round(3)]) + #pretty_table(vecparl, noheader = true, crop = :horizontal, formatters = ft_round(3)) printstyled(" Upper constraints for model parameters:\n",bold=true,color=:light_cyan) - pretty_table(vecparu, noheader = true, crop = :horizontal, formatters = ft_round(3)) + pretty_table(vecparu, formatters = [fmt__round(3)]) + #pretty_table(vecparu, noheader = true, crop = :horizontal, formatters = ft_round(3)) return nothing end diff --git a/src/tracepolygons/drawpolygons.jl b/src/tracepolygons/drawpolygons.jl index 5a6cbc5..46d4808 100755 --- a/src/tracepolygons/drawpolygons.jl +++ b/src/tracepolygons/drawpolygons.jl @@ -148,7 +148,7 @@ end ######################################################### -function MakieLayout.process_interaction(state::InteractionState, event::Union{MouseEvent,KeysEvent}, ax1) +function process_interaction(state::InteractionState, event::Union{MouseEvent,KeysEvent}, ax1) markersize = 30 @@ -262,7 +262,7 @@ function drawpolygons() ################### ## Init - fig = Figure(resolution = (1000, 700)) + fig = Figure(size = (1000, 700)) ax1 = Axis(fig[1,1]) xlims!(1,100); ylims!(1,100) @@ -271,7 +271,7 @@ function drawpolygons() ######################################## ## Interactions - clicks = Node(Array{Float64,2}(undef,0,2)) + clicks = Observable(Array{Float64,2}(undef,0,2)) ## LIFT function splitobs! points1 = lift(splitobs1!,clicks) diff --git a/src/tracepolygons/editpolygon.jl b/src/tracepolygons/editpolygon.jl index 56d45ea..8876d84 100755 --- a/src/tracepolygons/editpolygon.jl +++ b/src/tracepolygons/editpolygon.jl @@ -11,22 +11,22 @@ end function drawpoly( ; markersize=20.0) - points = Node(Point2f[(-2,-2), (2,-2), (2,2),]) + points = Observable(Point2f[(-2,-2), (2,-2), (2,2),]) #Node # initialize struct to hold variable states state = InteractionState(points) # create the figure - fig = Figure(resolution = (1000, 900)) + fig = Figure(size = (1000, 900)) ax1 = Axis(fig[1,1]) # plot the initial polygon - poly!(ax1,state.points, strokewidth=2, strokecolor=:black, color=:skyblue2) + poly!(ax1,state.points, strokewidth=2, strokecolor=:black, color=:skyblue2) #scale_plot = false) # plot vertices as a scatter plot scatplt = scatter!(ax1,state.points, color=:white, strokewidth=3, markersize=markersize, - strokecolor=:black, raw=true) + strokecolor=:black) #, raw=true) # resize figure to polygon #autolimits!(ax1) @@ -34,12 +34,12 @@ function drawpoly( ; markersize=20.0) # remove the click and drag zoom action deregister_interaction!(ax1, :rectanglezoom) - + # # add_move!(scene, points, pplot) add_remove_move_points!(ax1, points) - mouseevents = addmouseevents!(ax1.scene,scatplt) - move_points!(ax1,points,scatplt,mouseevents) + #mouseevents = addmouseevents!(ax1.scene,scatplt) + #move_points!(ax1,points,scatplt,mouseevents) #move_points!(ax1,points) # center!(fig.scene) @@ -142,7 +142,7 @@ function addpoint2nearestedge!(ax,points) println("Point has the same distance to two (or more) edges, cannot determine \n to which edge should add it. Please select another point.") #@show dist elseif counter==0 - error("addpoint2nearestedge(): Something went wrong, no shortest distance found.") + error("addpoint2nearesteadge(): Something went wrong, no shortest distance found.") else # index of the closest edge points[] = insert!(points[],idx+1,pos) @@ -155,7 +155,7 @@ end function removepoint!(ax,points) # get which plot and id the mouse is over - plot, idx = mouse_selection(ax.scene) + plot, idx = pick(ax.scene) ########################################## ## Check the following!!! ## @@ -178,85 +178,100 @@ function removepoint!(ax,points) return end -####################################################### -# function movepoint!(ax,points) +####################################################### +#= + function movepoint!(ax,points) -# # get which plot and id the mouse is over -# plot, idx = mouse_selection(ax.scene) + # get which plot and id the mouse is over + plot, idx = pick(ax.scene) -# ########################################## -# ## Check the following!!! ## -# ########################################## -# # take action only if the plot is of type Scatter -# targetplot = Scatter{Tuple{Vector{Point{2, Float32}}}} #<<<<<--------<<<<<< + ########################################## + ## Check the following!!! ## + ########################################## + # take action only if the plot is of type Scatter + targetplot = Scatter{Tuple{Vector{Point{2, Float32}}}} #<<<<<--------<<<<<< -# if typeof(plot) == targetplot && checkbounds(Bool, points[], idx) -# pos = mouseposition(ax.scene) -# points[][idx] = Point2f(pos) -# end -# points[] = points[] + if typeof(plot) == targetplot && checkbounds(Bool, points[], idx) + pos = mouseposition(ax.scene) + points[][idx] = Point2f(pos) + end + points[] = points[] -# return -# end + return + end +=# ########################################################## """ +Add, remove or move points in a polygon interactively. -Add or remove points from the polygon. +Controls: +- [A] + Left Click: Add point near closest edge +- [D] + Left Click: Remove point +- [S] + Left Click and Drag: Move point """ function add_remove_move_points!(ax, points) - on(events(ax.scene).mousebutton) do moueve - - # println() - # @show moueve - # @show moueve.button - # @show moueve.action - # @show ax.scene.events.mouseposition[] - # @show to_world(ax.scene, Point2f(ax.scene.events.mouseposition[])) - # @show mouseposition(ax.scene) - - # keystate is a Set - # keystate = events(ax.scene).keyboardstate - - # if Keyboard.a in keystate - # println("key a pressed") - # @show ispressed(fig.scene,Keyboard.a) - # end - - if moueve.button==Mouse.left - - if ispressed(ax.scene,Keyboard.a) - # add a new vertex to polygon - addpoint2nearestedge!(ax,points) - - elseif ispressed(ax.scene,Keyboard.d) - # remove points from polygon - removepoint!(ax,points) - - elseif ispressed(ax.scene,Keyboard.s) - - println("move point is pressed s") - - ## relocate already existing vertices - #movepoint!(ax,points) - + global idx + idx = 0 # initialize selected index for dragging + scene = ax.scene + + # Mouse press handler + on(events(scene).mousebutton) do mouse_event + if mouse_event.button == Mouse.left + pos = mouseposition(scene) + + if mouse_event.action == Mouse.press + if ispressed(scene, Keyboard.a) + # Add a new vertex to polygon + addpoint2nearestedge!(ax, points) + + elseif ispressed(scene, Keyboard.d) + # Remove points from polygon + removepoint!(ax, points) + + elseif ispressed(scene, Keyboard.s) + # Select point for dragging + plot, i = pick(scene) + if plot isa Scatter && checkbounds(Bool, points[], i) + idx = i + else + idx = 0 # No point selected + end + end + + elseif mouse_event.action == Mouse.release + # Release point after dragging + idx = 0 + notify(points) end end - - # do not consume the event return Consume(false) end + + # Mouse motion handler (for dragging) + on(events(scene).mouseposition) do _ + if idx > 0 && ispressed(scene, Keyboard.s) + pos = mouseposition(scene) + points[][idx] = Point2f(pos) + notify(points) + end + end + + return nothing end -####################################################### + +####################################################### +#= """ Move vertices of polygon. """ + function move_points!(ax, points, scatplt, mouseevents) # idx must be passed somewhat from "onmouseleftdragstart" to "onmouseleftdrag" @@ -265,7 +280,7 @@ function move_points!(ax, points, scatplt, mouseevents) # left drag starts onmouseleftdragstart(mouseevents) do event # get which plot and id the mouse is over - plot, idx = mouse_selection(ax.scene) + plot, idx = pick(ax.scene) #mouse_selection ########################################## ## Check the following!!! ## @@ -283,13 +298,13 @@ function move_points!(ax, points, scatplt, mouseevents) # left drag continues onmouseleftdrag(mouseevents) do event pos = mouseposition(ax.scene) - points[][idx] = Point2f(pos) + points[][idx] = Point2f(pos) points[] = points[] end return end - +=# @@ -304,6 +319,7 @@ end # end + ######################################################### # function add_move!(scene, points, pplot) diff --git a/src/tracepolygons/editpolygon.jl~ b/src/tracepolygons/editpolygon.jl~ deleted file mode 100644 index 73a0532..0000000 --- a/src/tracepolygons/editpolygon.jl~ +++ /dev/null @@ -1,52 +0,0 @@ - -using GLMakie - - -points = Node(Point2f0[(0, 0), (0.5, 0.5), (1.0, 0.0)]) -scene = Scene(resolution = (500, 500)) -poly!(scene, points, strokewidth = 2, strokecolor = :black, color = :skyblue2, show_axis = false, scale_plot = false) -scatter!(points, color = :white, strokewidth = 10, markersize = 0.05, strokecolor = :black, raw = true) -pplot = scene[end] -push!(points[], Point2f0(0.6, -0.3)) -points[] = points[] -function add_move!(scene, points, pplot) - idx = Ref(0); dragstart = Ref(false); startpos = Base.RefValue(Point2f0(0)) - on(events(scene).mousedrag) do drag - if ispressed(scene, Mouse.left) - if drag == Mouse.down - plot, _idx = mouse_selection(scene) - if plot == pplot - idx[] = _idx; dragstart[] = true - startpos[] = to_world(scene, Point2f0(scene.events.mouseposition[])) - end - elseif drag == Mouse.pressed && dragstart[] && checkbounds(Bool, points[], idx[]) - pos = to_world(scene, Point2f0(scene.events.mouseposition[])) - points[][idx[]] = pos - points[] = points[] - end - else - dragstart[] = false - end - return - end -end - -function add_remove_add!(scene, points, pplot) - on(events(scene).mousebuttons) do but - if ispressed(but, Mouse.left) && ispressed(scene, Keyboard.left_control) - pos = to_world(scene, Point2f0(events(scene).mouseposition[])) - push!(points[], pos) - points[] = points[] - elseif ispressed(but, Mouse.right) - plot, idx = mouse_selection(scene) - if plot == pplot && checkbounds(Bool, points[], idx) - deleteat!(points[], idx) - points[] = points[] - end - end - return - end -end -add_move!(scene, points, pplot) -add_remove_add!(scene, points, pplot) -center!(scene)