Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/MG2D/grav/grav_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/MG2D/joint/joint_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/MG2D/mag/mag_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/tracepolygons/drawpolygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
150 changes: 83 additions & 67 deletions src/tracepolygons/editpolygon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ 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)
limits!(ax1,-10,10,-10,10)

# 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)
Expand Down Expand Up @@ -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)
Expand All @@ -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!!! ##
Expand All @@ -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"
Expand All @@ -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!!! ##
Expand All @@ -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

=#



Expand All @@ -304,6 +319,7 @@ end
# end



#########################################################

# function add_move!(scene, points, pplot)
Expand Down
52 changes: 0 additions & 52 deletions src/tracepolygons/editpolygon.jl~

This file was deleted.