Skip to content

Commit

Permalink
wxGUI/gcp: adding the option/show overwrite confirm dialog to overwri…
Browse files Browse the repository at this point in the history
…te the result map (#912)
  • Loading branch information
tmszi authored and neteler committed Aug 23, 2020
1 parent f203dc4 commit 80ce804
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
3 changes: 3 additions & 0 deletions gui/wxpython/core/settings.py
Expand Up @@ -624,6 +624,9 @@ def _defaultSettings(self):
'size': 8,
'width': 2,
},
'map': {
'overwrite': False,
},
},
'nviz': {
'view': {
Expand Down
110 changes: 108 additions & 2 deletions gui/wxpython/gcp/manager.py
Expand Up @@ -1043,6 +1043,8 @@ def __init__(self, parent, giface, grwiz=None, id=wx.ID_ANY,
self.gr_method = 'nearest'
# region clipping for georectified map
self.clip_to_region = False
# overwrite result map
self.overwrite = False
# number of GCPs selected to be used for georectification (checked)
self.GCPcount = 0
# forward RMS error
Expand Down Expand Up @@ -1297,6 +1299,10 @@ def SetSettings(self):
self.pointsToDrawSrc.SetPropertyVal("text", textProp)
self.pointsToDrawTgt.SetPropertyVal("text", copy(textProp))

# overwrite result map
self.overwrite = UserSettings.Get(group='gcpman', key='map',
subkey='overwrite')

def SetGCPSatus(self, item, itemIndex):
"""Before GCP is drawn, decides it's colour and whether it
will be drawed.
Expand Down Expand Up @@ -1589,6 +1595,60 @@ def CheckGCPcount(self, msg=False):
else:
return True

def _getOverWriteDialog(self, maptype, overwrite):
"""Get overwrite confirm dialog
:param str maptype: map type
:param bool overwrite: overwrite
:return
object: overwrite dialog
None: it isn't necessary to display the overwrite dialog
"""
if maptype == 'raster':
self.grwiz.SwitchEnv('source')
maps = grass.read_command(
'i.group', flags='gl', group=self.xygroup, quiet=True,
).split('\n')
self.grwiz.SwitchEnv('target')
found_maps = []
if maps:
for map in maps:
if map:
map_name = map.split('@')[0] + self.extension
found = grass.find_file(
name=map_name, element='cell',
mapset=self.currentmapset,
)
if found['name']:
found_maps.append("<{}>".format(found['name']))
map_name = ', '.join(found_maps)
else:
self.grwiz.SwitchEnv('target')
found = grass.find_file(
name=self.outname, element='vector',
mapset=self.currentmapset,
)
self.grwiz.SwitchEnv('source')
map_name = "<{}>".format(found['name'])

if found['name'] and not overwrite:
overwrite_dlg = wx.MessageDialog(
self.GetParent(),
message=_(
"The {map_type} map {map_name} exists. "
"Do you want to overwrite?".format(
map_type=maptype,
map_name=map_name,
),
),
caption=_('Overwrite?'),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
return overwrite_dlg

def OnGeorect(self, event):
"""
Georectifies map(s) in group using i.rectify or v.transform
Expand All @@ -1600,6 +1660,18 @@ def OnGeorect(self, event):
return

if maptype == 'raster':
overwrite_dlg = self._getOverWriteDialog(
maptype=maptype, overwrite=self.overwrite,
)
if overwrite_dlg:
if not overwrite_dlg.ShowModal() == wx.ID_YES:
overwrite_dlg.Destroy()
return
overwrite_dlg.Destroy()
overwrite = True
else:
overwrite = self.overwrite

self.grwiz.SwitchEnv('source')

if self.clip_to_region:
Expand All @@ -1619,7 +1691,8 @@ def OnGeorect(self, event):
extension=self.extension,
order=self.gr_order,
method=self.gr_method,
flags=flags)
flags=flags,
overwrite=overwrite)

del busy

Expand All @@ -1628,6 +1701,7 @@ def OnGeorect(self, event):
print(msg, file=sys.stderr)

elif maptype == 'vector':

# loop through all vectors in VREF

self.grwiz.SwitchEnv('source')
Expand All @@ -1647,6 +1721,17 @@ def OnGeorect(self, event):
# georectify each vector in VREF using v.rectify
for vect in vectlist:
self.outname = str(vect.split('@')[0]) + self.extension
overwrite_dlg = self._getOverWriteDialog(
maptype=maptype, overwrite=self.overwrite,
)
if overwrite_dlg:
if not overwrite_dlg.ShowModal() == wx.ID_YES:
overwrite_dlg.Destroy()
return
overwrite_dlg.Destroy()
overwrite = True
else:
overwrite = self.overwrite
self._giface.WriteLog(text=_('Transforming <%s>...') % vect,
notification=Notification.MAKE_VISIBLE)
ret = msg = ''
Expand All @@ -1663,7 +1748,8 @@ def OnGeorect(self, event):
input=vect,
output=self.outname,
group=self.xygroup,
order=self.gr_order)
order=self.gr_order,
overwrite=overwrite)

del busy

Expand Down Expand Up @@ -2992,6 +3078,17 @@ def __CreateRectificationPage(self, notebook):
flag=wx.EXPAND | wx.ALL, border=5)
self.check.SetValue(self.parent.clip_to_region)

# overwrite result map
overwrite = UserSettings.Get(group='gcpman', key='map',
subkey='overwrite')
self.overwrite = wx.CheckBox(parent=panel, id=wx.ID_ANY,
label=_('overwrite result map'))
self.Bind(wx.EVT_CHECKBOX, self.OnOverwrite, self.overwrite)
sizer.Add(self.overwrite, proportion=0,
flag=wx.EXPAND | wx.ALL, border=5)
self.overwrite.SetValue(overwrite)
self.parent.overwrite = overwrite

# extension
sizer.Add(
StaticText(
Expand Down Expand Up @@ -3071,6 +3168,9 @@ def OnMethod(self, event):
def OnClipRegion(self, event):
self.parent.clip_to_region = event.IsChecked()

def OnOverwrite(self, event):
self.parent.overwrite = event.IsChecked()

def OnExtension(self, event):
self.parent.extension = self.ext_txt.GetValue()

Expand Down Expand Up @@ -3134,6 +3234,12 @@ def UpdateSettings(self):
subkey='width',
value=wx.FindWindowById(
self.symbol['width']).GetValue())
UserSettings.Set(
group='gcpman',
key='map',
subkey='overwrite',
value=self.parent.overwrite,
)

srcrender = False
srcrenderVector = False
Expand Down

0 comments on commit 80ce804

Please sign in to comment.