Removing Options

Moderator: GiD Team

Post Reply
barnacle
Posts: 12
Joined: Sat Feb 28, 2015 1:51 pm

Removing Options

Post by barnacle »

Hi there,

I would like to remove the "Calculate remote" option from the "Calculate" menu. However the command:
'GiDMenu::RemoveOption "Calculate" "Calculate remote" PRE' does not work. How can I remove this option?

Thanks and greetings,

barnacle
User avatar
escolano
Posts: 1918
Joined: Sun Sep 05, 1982 10:51 pm

Re: Removing Options

Post by escolano »

the second argument of the procedure GiDMenu::RemoveOption must be a list of items that fully identify the desired item path in the tree of submenus.
instead of

Code: Select all

GiDMenu::RemoveOption "Calculate" "Calculate remote" PRE
must use:

Code: Select all

GiDMenu::RemoveOption "Calculate" [list "Calculate remote"] PRE
GiDMenu::UpdateMenus
the bug of your syntax is that it is like you were finding
Calculate->Calculate->remote
Instead of
Calculate->Calculate remote
barnacle
Posts: 12
Joined: Sat Feb 28, 2015 1:51 pm

Re: Removing Options

Post by barnacle »

That worked thank you (especially for the fast reply)!

Threefollowup questions:

1. How to change the position of the line between "Calculate remote" and "Cancel Process"? Or better, how to create, erase and move such a line?
2. How to enable and disable the availability of an option (like with "Calculate" before and after a mesh is generated)?
and 3. If I create a new menu, why are there a minimum of two field, even if I just add one option?

Thanks,

barnacle
User avatar
escolano
Posts: 1918
Joined: Sun Sep 05, 1982 10:51 pm

Re: Removing Options

Post by escolano »

1) a separator menu must be specified as --- ,
e.g. to remove the separator line of the Calculate menu:
GiDMenu::RemoveOption "Calculate"
  • PRE

    in case of multiple separators the name is ambiguour, then it is possible to specify an extra index number, starting from 0,
    e.g.
    GiDMenu::RemoveOption "Calculate"
    • PRE

      2) menus are not really disabled, they are only set in 'ligth gray' to suggest that are disabled, but really will invoke its command (the command could then do nothing if it wants).

      This is an example of our code that set at runtime the state of the calculate menu.

      Code: Select all

      proc SetCalculateMenuState { } {
          set menu_name "Calculate#C#menu"
          set i [ GiDMenu::_FindIndex $menu_name PRE]
          if { $i == -1 } return
          set menuname [ GetMenuName $i]
          if { ![info exists ::RunProcInfo] || $::RunProcInfo == "" } {
              set color $::GidPriv(Color,DisabledForegroundMenu)
          } else {
              set color black
          }
          set option_name [list "Cancel process#C#menu"]
          set position [lindex [split [ GiDMenu::_FindOptionIndex $i $option_name PRE] ,] end]
          if { $position != -1 } {
              ChangeMenuForegroundColor $menuname $position $color
          }
          if { [PWFIndOutputFilenameCurrent] == "" } {
              set color $::GidPriv(Color,DisabledForegroundMenu)
          } else {
              set color black
          }
          set option_name [list "View process info#C#menu"]
          set position [lindex [split [ GiDMenu::_FindOptionIndex $i $option_name PRE] ,] end]
          if { $position != -1 } {
              ChangeMenuForegroundColor $menuname $position $color
          }
          if { [ GiD_Info Project ProblemType] == "UNKNOWN" } {
              set color $::GidPriv(Color,DisabledForegroundMenu)
          } else {
              set color black
          }
          set option_name [list "Calculate window#C#menu"]
          set position [lindex [split [ GiDMenu::_FindOptionIndex $i $option_name PRE] ,] end]
          if { $position != -1 } {
              ChangeMenuForegroundColor $menuname $position $color
          }
          if { [lindex [ GiD_Info Mesh] 0] == 0 || [lindex [ GiD_Info Mesh] 0] == 0 } {
              set color $::GidPriv(Color,DisabledForegroundMenu)
          } else {
              set color black
          }
          set option_name [list "Calculate#C#menu"]
          set position [lindex [split [ GiDMenu::_FindOptionIndex $i $option_name PRE] ,] end]
          if { $position != -1 } {
              ChangeMenuForegroundColor $menuname $position $color
          }
          set option_name [list "Calculate remote#C#menu"]
          set position [lindex [split [ GiDMenu::_FindOptionIndex $i $option_name PRE] ,] end]
          if { $position != -1 } {
              ChangeMenuForegroundColor $menuname $position $color
          }
      }
      3) I am not sure, Is seems that initially it is created like an empty submenu, or that 'end' points to the entry after the last.
      unfortunatelly we must not change this behaviour to avoid to break scripts of third parts.
      In any case the drawback could be avoided for example using GiDMenu::InsertOption with the index number (0, 1, ...) instead of 'end'

      Code: Select all

      GiDMenu::Create [= "Kratos#C#menu"] PRE -1
      GiDMenu::InsertOption [= "Kratos#C#menu"] [list [= "Model properties#C#menu"]] 0 PRE KMProps::StartBaseWindow "" "" replace
      GiDMenu::InsertOption [= "Kratos#C#menu"] [list [= "Material database#C#menu"]] 1 PRE {KMProps::StartBaseWindow Materials} "" "" replace
      GiDMenu::UpdateMenus
      ('replace' is the default mode, it is possible to use others like 'insert')
Post Reply