Skip to content

Commit

Permalink
wxGUI: Use r.mask.status to get info about mask
Browse files Browse the repository at this point in the history
This replaces low level checks of MASK raster in the current mapset with calls of r.mask.status.

GConsole and SbMask require r.mask.status to output a potential name of the mask regerdless of mask being set or not, so this functionality still needs to be implemented first before moving this PR forward. History changes seem to be complete.
  • Loading branch information
wenzeslaus committed Oct 14, 2024
1 parent b5289ee commit 197732c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
9 changes: 7 additions & 2 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,13 +856,18 @@ def OnCmdDone(self, event):
for p in task.get_options()["flags"]:
if p.get("name") == "r" and p.get("value"):
action = "delete"
# TODO: Use giface here.
mask_full_name = gs.parse_command(
"r.mask.status", format="json", env=env_run
)["configured_name"]
mask_name, mask_mapset = mask_full_name.split("@", maxsplit=1)
gisenv = gs.gisenv()
self._giface.grassdbChanged.emit(
grassdb=gisenv["GISDBASE"],
location=gisenv["LOCATION_NAME"],
mapset=gisenv["MAPSET"],
mapset=mapset,
action=action,
map="MASK",
map=name,
element="raster",
)

Expand Down
28 changes: 17 additions & 11 deletions gui/wxpython/lmgr/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ class SbMask:

def __init__(self, parent, giface):
self.name = "mask"
self.mask_layer = "MASK"
self.parent = parent
self.giface = giface
self.widget = Button(
parent=parent, id=wx.ID_ANY, label=_(self.mask_layer), style=wx.NO_BORDER
parent=parent, id=wx.ID_ANY, label=_("Mask"), style=wx.NO_BORDER
)
self.widget.Bind(wx.EVT_BUTTON, self.OnRemoveMask)
self.widget.SetForegroundColour(wx.Colour(255, 0, 0))
self.widget.SetToolTip(tip=_("Left mouse click to remove the MASK"))
self.widget.SetToolTip(tip=_("Left mouse click to remove the raster mask"))
self.giface.currentMapsetChanged.connect(self.Refresh)
if not watchdog_used:
self.giface.grassdbChanged.connect(self.dbChanged)
Expand All @@ -94,7 +93,11 @@ def dbChanged(self, map=None, newname=None):
:param str map: map that is changed
:param str newname: new map
"""
if self.mask_layer in {map, newname}:
# TODO: Use giface here.
mask_layer = gs.parse_command("r.mask.status", format="json", env=env_run)[
"configured_name"
].split("@", maxsplit=1)[0]
if mask_layer in {map, newname}:
self.Refresh()
self.giface.updateMap.emit()

Expand Down Expand Up @@ -124,30 +127,33 @@ def GetWidget(self):

def Refresh(self):
"""Show mask in the statusbar if mask file found"""
if gs.find_file(
name=self.mask_layer, element="cell", mapset=gs.gisenv()["MAPSET"]
)["name"]:
if gs.parse_command("r.mask.status", format="json", env=env_run)["present"]:
self.Show()
else:
self.Hide()

def OnRemoveMask(self, event):
dlg = wx.MessageDialog(
self.parent,
message=_("Are you sure that you want to remove the MASK?"),
caption=_("Remove MASK"),
message=_("Are you sure that you want to remove the current raster mask?"),
caption=_("Remove raster mask"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if dlg.ShowModal() != wx.ID_YES:
dlg.Destroy()
return
RunCommand("r.mask", flags="r")
# TODO: Use giface here.
mask_full_name = gs.parse_command("r.mask.status", format="json", env=env_run)[
"configured_name"
]
mask_name, mask_mapset = mask_full_name.split("@", maxsplit=1)
gisenv = gs.gisenv()
self.giface.grassdbChanged.emit(
grassdb=gisenv["GISDBASE"],
location=gisenv["LOCATION_NAME"],
mapset=gisenv["MAPSET"],
map=self.mask_layer,
mapset=mask_mapset,
map=mask_name,
action="delete",
element="raster",
)
8 changes: 5 additions & 3 deletions python/grass/grassdb/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ def get_initial_command_info(env_run):
exec_time = datetime.now().isoformat()

# 2D raster MASK presence
env = gs.gisenv(env_run)
mapset_path = Path(env["GISDBASE"]) / env["LOCATION_NAME"] / env["MAPSET"]
mask2d_present = (mapset_path / "cell" / "MASK").exists()
mask2d_present = gs.parse_command("r.mask.status", format="json", env=env_run)[
"present"
]

# 3D raster MASK presence
env = gs.gisenv(env_run)
mapset_path = Path(env["GISDBASE"]) / env["LOCATION_NAME"] / env["MAPSET"]
mask3d_present = (mapset_path / "grid3" / "RASTER3D_MASK").exists()

# Computational region settings
Expand Down

0 comments on commit 197732c

Please sign in to comment.