Skip to content

Commit

Permalink
finish populating the menus
Browse files Browse the repository at this point in the history
  • Loading branch information
aoterodelaroza committed Nov 25, 2024
1 parent 6f53207 commit 1617a67
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 37 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.347
1.2.348
36 changes: 31 additions & 5 deletions src/gui/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ subroutine show_main_menu()
use windows, only: win, iwin_tree, iwin_view, iwin_console_input,&
iwin_console_output, iwin_about, stack_create_window, wintype_dialog,&
wpurp_dialog_openfiles, wintype_new_struct, wintype_new_struct_library,&
wintype_preferences, wintype_view, wpurp_view_alternate,&
wintype_about, wintype_geometry
wintype_preferences, wintype_view, wpurp_view_alternate, wintype_load_field,&
wintype_about, wintype_geometry, wintype_rebond, wintype_vibrations
use utils, only: igIsItemHovered_delayed, iw_tooltip, iw_text, iw_calcwidth, iw_menuitem
use keybindings, only: BIND_QUIT, BIND_OPEN, BIND_NEW, BIND_GEOMETRY, get_bind_keyname,&
is_bind_event
Expand All @@ -837,7 +837,7 @@ subroutine show_main_menu()

character(kind=c_char,len=:), allocatable, target :: str1, str2
integer(c_int) :: idum
logical :: launchquit, launch(5)
logical :: launchquit, launch(5), isysok, ifieldok
integer :: isys

logical, save :: ttshown = .false. ! tooltip flag
Expand Down Expand Up @@ -872,6 +872,23 @@ subroutine show_main_menu()
! File -> Separator
call igSeparator()

! File -> Load Field
isys = win(iwin_tree)%tree_selected
isysok = ok_system(isys,sys_init)
if (iw_menuitem("Load Field...",enabled=isysok)) &
idum = stack_create_window(wintype_load_field,.true.,isys=isys,orraise=-1)
call iw_tooltip("Load a scalar field for the current system",ttshown)

! File -> Remove Field
ifieldok = isysok
if (ifieldok) ifieldok = (sys(isys)%iref /= 0)
if (iw_menuitem("Remove Field",enabled=ifieldok)) &
call sys(isys)%unload_field(sys(isys)%iref)
call iw_tooltip("Remove the reference field from the current system",ttshown)

! File -> Separator
call igSeparator()

! File -> Quit
launchquit = launchquit .or. iw_menuitem("Quit",BIND_QUIT)
call iw_tooltip("Quit critic2",ttshown)
Expand Down Expand Up @@ -933,11 +950,20 @@ subroutine show_main_menu()
! Windows
str1 = "Tools" // c_null_char
if (igBeginMenu(c_loc(str1),.true._c_bool)) then
isys = win(iwin_tree)%table_selected
isys = win(iwin_view)%view_selected
isysok = ok_system(isys,sys_init)
launch(d_geometry) = launch(d_geometry) .or. &
iw_menuitem("View/Edit Geometry...",BIND_GEOMETRY,enabled=ok_system(isys,sys_init))
iw_menuitem("View/Edit Geometry...",BIND_GEOMETRY,enabled=isysok)
call iw_tooltip("View and edit the atomic positions, bonds, etc.",ttshown)

if (iw_menuitem("Recalculate Bonds...",enabled=isysok.and..not.are_threads_running())) &
idum = stack_create_window(wintype_rebond,.true.,isys=isys,orraise=-1)
call iw_tooltip("Recalculate the bonds in the current system",ttshown)

if (iw_menuitem("Vibrations...",enabled=isysok)) &
idum = stack_create_window(wintype_vibrations,.true.,idparent=iwin_view,orraise=-1)
call iw_tooltip("Display an animation showing the atomic vibrations for this system",ttshown)

call igEndMenu()
else
ttshown = .false.
Expand Down
6 changes: 3 additions & 3 deletions src/gui/windows.f90
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ module windows
logical :: isdocked = .false. ! whether the window is docked
real*8 :: timelastupdate ! time the window data was last updated
! tree table parameters
integer :: table_selected = 1 ! the system selected in a table (input to iord)
integer :: tree_selected = 1 ! the system selected in a table (input to iord)
integer, allocatable :: iord(:) ! table order
integer(c_int) :: table_sortcid = 0 ! sort table by this column id
integer(c_int) :: table_sortdir = 1 ! sort table with this direction
integer(c_int) :: tree_sortcid = 0 ! sort table by this column id
integer(c_int) :: tree_sortdir = 1 ! sort table with this direction
logical :: forceresize = .false. ! make true to force resize of columns
logical :: forcesort = .false. ! make true to force a sort of the tree
logical :: forceupdate = .false. ! make true to force an update of the tree
Expand Down
6 changes: 3 additions & 3 deletions src/gui/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ module subroutine window_init(w,type,isopen,id,purpose,isys,irep,idparent,itoken
w%id = -id
w%name = "" // c_null_char
w%errmsg = ""
w%table_selected = 1
w%table_sortcid = 0
w%table_sortdir = 1
w%tree_selected = 1
w%tree_sortcid = 0
w%tree_sortdir = 1
w%forceresize = .false.
w%forcesort = .false.
w%forceupdate = .false.
Expand Down
55 changes: 30 additions & 25 deletions src/gui/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module subroutine draw_tree(w)
type(ImVec2) :: szero, sz
type(ImVec4) :: col4
integer(c_int) :: flags, color, idir
integer :: i, j, k, nshown, newsel, jsel, ll, id, iref, inext, iprev, isys, iaux
integer :: i, j, k, nshown, newsel, jsel, ll, id, iref, inext, iprev, isys, iaux, nfreal
logical(c_bool) :: ldum, isel
type(c_ptr) :: ptrc
type(ImGuiTableSortSpecs), pointer :: sortspecs
Expand Down Expand Up @@ -111,9 +111,9 @@ module subroutine draw_tree(w)
szero%x = 0
szero%y = 0
if (.not.allocated(w%iord)) then
w%table_sortcid = ic_id
w%table_sortdir = 1
w%table_selected = 1
w%tree_sortcid = ic_id
w%tree_sortdir = 1
w%tree_selected = 1
w%forceupdate = .true.
timelastupdate = 0d0
timelastresize = 0d0
Expand Down Expand Up @@ -230,10 +230,10 @@ module subroutine draw_tree(w)
do k = 1, size(w%forceremove,1)
call remove_system(w%forceremove(k))
! if we removed the selected system, go to the next; either, go to the previous
if (w%forceremove(k) == w%table_selected) then
if (w%forceremove(k) == w%tree_selected) then
jsel = 0
do j = 1, size(w%iord,1)
if (w%iord(j) == w%table_selected) then
if (w%iord(j) == w%tree_selected) then
jsel = j
exit
end if
Expand Down Expand Up @@ -270,9 +270,9 @@ module subroutine draw_tree(w)
end if
! if we removed the system for the input console or the view, update
if (w%forceremove(k) == win(iwin_console_input)%inpcon_selected) &
win(iwin_console_input)%inpcon_selected = w%table_selected
win(iwin_console_input)%inpcon_selected = w%tree_selected
if (w%forceremove(k) == win(iwin_view)%view_selected) &
call win(iwin_view)%select_view(w%table_selected)
call win(iwin_view)%select_view(w%tree_selected)
end do
deallocate(w%forceremove)
w%timelastupdate = time
Expand All @@ -284,7 +284,7 @@ module subroutine draw_tree(w)
timelastupdate = time
end if
if (w%forcesort) then
call w%sort_tree(w%table_sortcid,w%table_sortdir)
call w%sort_tree(w%tree_sortcid,w%tree_sortdir)
timelastsort = time
end if
if (w%forceinit) then
Expand Down Expand Up @@ -425,15 +425,15 @@ module subroutine draw_tree(w)
call c_f_pointer(ptrc,sortspecs)
if (c_associated(sortspecs%Specs)) then
call c_f_pointer(sortspecs%Specs,colspecs)
w%table_sortcid = colspecs%ColumnUserID
w%table_sortdir = colspecs%SortDirection
w%tree_sortcid = colspecs%ColumnUserID
w%tree_sortdir = colspecs%SortDirection
if (sortspecs%SpecsDirty .and. nshown > 1) then
w%forcesort = .true.
sortspecs%SpecsDirty = .false.
end if
else
w%table_sortcid = ic_id
w%table_sortdir = 1
w%tree_sortcid = ic_id
w%tree_sortdir = 1
end if
end if

Expand Down Expand Up @@ -533,7 +533,12 @@ module subroutine draw_tree(w)
end if
pos = igGetCursorPosX()
call igSetCursorPosX(pos + g%Style%FramePadding%x)
if (sys(i)%nf > 0) then

nfreal = 0
do k = 1, sys(i)%nf
if (sys(i)%f(k)%isinit) nfreal = nfreal + 1
end do
if (nfreal > 0) then
call iw_text(ch,rgba=rgba_fields)
else
call iw_text(ch)
Expand Down Expand Up @@ -576,7 +581,7 @@ module subroutine draw_tree(w)
str = "└─►(" // string(k) // "): " // trim(sys(i)%f(k)%name) // "##field" // &
string(i) // "," // string(k) // c_null_char
end if
isel = (w%table_selected==i) .and. (sys(i)%iref == k)
isel = (w%tree_selected==i) .and. (sys(i)%iref == k)
call igPushStyleColor_Vec4(ImGuiCol_Header,ColorFieldSelected)
flags = ImGuiSelectableFlags_SpanAllColumns
if (igSelectable_Bool(c_loc(str),isel,flags,szero)) then
Expand Down Expand Up @@ -714,7 +719,7 @@ module subroutine draw_tree(w)
"<generated>, potential of $" // string(k),sys(i)%f(k)%grid,ifformat_as_ft_pot)
end if
call iw_tooltip("Load a new grid field using FFT as the potential that generates&
this field (via Poisson's equation)",ttshown)
&this field (via Poisson's equation)",ttshown)
call igEndMenu()
end if

Expand Down Expand Up @@ -910,7 +915,7 @@ module subroutine draw_tree(w)
ok = is_bind_event(BIND_TREE_REMOVE_SYSTEM_FIELD)
ok = ok .and. igIsWindowFocused(ImGuiFocusedFlags_None)
if (ok) then
jsel = w%table_selected
jsel = w%tree_selected
iref = sys(jsel)%iref
ok = ok_system(jsel,sys_init)
if (ok) ok = sysc(jsel)%showfields
Expand Down Expand Up @@ -989,7 +994,7 @@ subroutine write_maybe_selectable(isys,tooltipstr)
flags = ior(flags,ImGuiSelectableFlags_AllowItemOverlap)
flags = ior(flags,ImGuiSelectableFlags_AllowDoubleClick)
flags = ior(flags,ImGuiSelectableFlags_SelectOnNav)
selected = (w%table_selected==isys)
selected = (w%tree_selected==isys)
strl = "##selectable" // string(isys) // c_null_char
ok = igSelectable_Bool(c_loc(strl),selected,flags,szero)
ok = ok .or. (w%forceselect == isys)
Expand All @@ -1007,7 +1012,7 @@ subroutine write_maybe_selectable(isys,tooltipstr)

! update the iprev and inext
if (inext==0.and.didtableselected) inext = isys
if (isys == w%table_selected) didtableselected = .true.
if (isys == w%tree_selected) didtableselected = .true.
if (.not.didtableselected) iprev = isys

enabled = (sysc(isys)%status == sys_init)
Expand Down Expand Up @@ -1057,7 +1062,7 @@ subroutine write_maybe_selectable(isys,tooltipstr)
! rebond
if (iw_menuitem("Recalculate Bonds...",enabled=enabled_no_threads)) &
idrebond = stack_create_window(wintype_rebond,.true.,isys=isys,orraise=-1)
call iw_tooltip("Recalculate the covalent bonds in this system and the molecular structures",ttshown)
call iw_tooltip("Recalculate the bonds in this system",ttshown)

call igEndMenu()
end if
Expand Down Expand Up @@ -1195,8 +1200,8 @@ subroutine collapse_system(i)
end do
sysc(i)%collapse = -1
! selected goes to master
if (w%table_selected >= 1 .and. w%table_selected <= nsys) then
if (sysc(w%table_selected)%collapse == i) call select_system(i,.true.)
if (w%tree_selected >= 1 .and. w%tree_selected <= nsys) then
if (sysc(w%tree_selected)%collapse == i) call select_system(i,.true.)
end if
w%forceupdate = .true.

Expand All @@ -1208,7 +1213,7 @@ subroutine select_system(i,force)
integer, intent(in) :: i
logical, intent(in) :: force

w%table_selected = i
w%tree_selected = i
if (tree_select_updates_inpcon .or. force) &
win(iwin_console_input)%inpcon_selected = i
if (tree_select_updates_view .or. force) &
Expand Down Expand Up @@ -1880,7 +1885,7 @@ module subroutine draw_load_field(w)
oksys = ok_system(isys,sys_init)
if (.not.oksys) then
! reset to the table selected
isys = win(iwin_tree)%table_selected
isys = win(iwin_tree)%tree_selected
oksys = ok_system(isys,sys_init)
end if
if (.not.oksys) then
Expand Down Expand Up @@ -2390,7 +2395,7 @@ module subroutine draw_rebond(w)
oksys = ok_system(isys,sys_init)
if (.not.oksys) then
! reset to the table selected
isys = win(iwin_tree)%table_selected
isys = win(iwin_tree)%tree_selected
oksys = ok_system(isys,sys_init)
end if
if (.not.oksys) then
Expand Down

0 comments on commit 1617a67

Please sign in to comment.