Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI: Use r.mask.status to get info about mask #4519

Merged
merged 7 commits into from
Jan 29, 2025
Merged
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 gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,13 +856,15 @@ def OnCmdDone(self, event):
for p in task.get_options()["flags"]:
if p.get("name") == "r" and p.get("value"):
action = "delete"
mask_full_name = gs.parse_command("r.mask.status", format="json")["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=mask_mapset,
action=action,
map="MASK",
map=mask_name,
element="raster",
)

Expand Down
26 changes: 15 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,12 @@ 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}:
mask_layer = gs.parse_command("r.mask.status", format="json")["name"].split(
"@", maxsplit=1
)[0]
# This assumes mask is always in the current mapset (or the event is triggered
# only for the current mapset).
if mask_layer in {map, newname}:
self.Refresh()
self.giface.updateMap.emit()

Expand Down Expand Up @@ -124,30 +128,30 @@ 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")["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")
mask_full_name = gs.parse_command("r.mask.status", format="json")["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",
)
11 changes: 7 additions & 4 deletions python/grass/grassdb/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,24 @@ 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_status = gs.parse_command("r.mask.status", format="json", env=env_run)

# 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()
mask3d_name = f"RASTER3D_MASK@{env['MAPSET']}"

# Computational region settings
region_settings = gs.region(env=env_run)

# Finalize the command info dictionary
return {
"timestamp": exec_time,
"mask2d": mask2d_present,
"mask2d": mask2d_status["present"],
"mask2d_name": mask2d_status["name"],
"mask3d": mask3d_present,
"mask3d_name": mask3d_name,
"region": region_settings,
"status": Status.RUNNING.value,
}
Expand Down
Loading