4 @brief Dialog for interactive construction of vector cleaning
10 (C) 2010-2011 by the GRASS Development Team
12 This program is free software under the GNU General Public License
13 (>=v2). Read the file COPYING that comes with GRASS for details.
23 import wx.lib.scrolledpanel
as scrolled
33 from debug
import Debug
as Debug
34 from preferences
import globalSettings
as UserSettings
37 def __init__(self, parent, id=wx.ID_ANY, title=_(
'set up vector cleaning tools'),
38 pos=wx.DefaultPosition, size=(-1, -1),
39 style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER,
42 Dialog for interactively defining vector cleaning tools
44 wx.Frame.__init__(self, parent, id, title, pos, size, style)
48 self.
log = self.parent.GetLogWindow()
56 self.CreateStatusBar()
59 self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR,
'grass.ico'), wx.BITMAP_TYPE_ICO))
76 _(
'break lines/boundaries'),
77 _(
'remove duplicates'),
79 _(
'change boundary dangles to lines'),
81 _(
'change bridges to lines'),
82 _(
'snap lines/boundaries'),
83 _(
'remove duplicate area centroids'),
85 _(
'prune lines/boundaries'),
86 _(
'remove small areas'),
87 _(
'remove lines/boundaries of zero length'),
88 _(
'remove small angles at nodes')
121 self.SetTitle(_(
'Set up vector cleaning tools'))
122 self.SetStatusText(_(
"Set up vector cleaning tools"))
124 self.
ctlabel = _(
'Choose cleaning tools and set thresholds')
127 self.
inmaplabel = wx.StaticText(parent = self, id = wx.ID_ANY,
128 label= _(
'Select input vector map:'))
130 size=globalvar.DIALOG_GSELECT_SIZE,
133 ftypeBox = wx.StaticBox(parent=self, id=wx.ID_ANY,
134 label=_(
' Feature type: '))
138 label= _(
'Select output vector map:'))
140 size=globalvar.DIALOG_GSELECT_SIZE,
144 label=_(
'Allow output files to overwrite existing files'))
145 self.overwrite.SetValue(UserSettings.Get(group=
'cmd', key=
'overwrite', subkey=
'enabled'))
148 self.
ct_label = wx.StaticText(parent=self, id=wx.ID_ANY,
154 self.
btn_add = wx.Button(parent=self, id=wx.ID_ADD)
164 self.
btn_close = wx.Button(parent = self, id = wx.ID_CLOSE)
165 self.
btn_run = wx.Button(parent = self, id = wx.ID_ANY, label = _(
"&Run"))
166 self.btn_run.SetDefault()
168 self.btn_clipboard.SetToolTipString(_(
"Copy the current command string to the clipboard (Ctrl+C)"))
169 self.
btn_help = wx.Button(parent = self, id = wx.ID_HELP)
172 self.btn_close.Bind(wx.EVT_BUTTON, self.
OnClose)
174 self.btn_clipboard.Bind(wx.EVT_BUTTON, self.
OnCopy)
175 self.btn_help.Bind(wx.EVT_BUTTON, self.
OnHelp)
177 self.btn_add.Bind(wx.EVT_BUTTON, self.
OnAddTool)
178 self.btn_remove.Bind(wx.EVT_BUTTON, self.
OnClearTool)
182 self.SetMinSize(self.GetBestSize())
187 self.CentreOnScreen()
191 sizer = wx.BoxSizer(wx.VERTICAL)
196 inSizer = wx.GridBagSizer(hgap=5, vgap=5)
199 flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.EXPAND, border=1)
201 flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.EXPAND, border=1)
204 wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
'point')),
205 wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
'line')),
206 wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
'boundary')),
207 wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
'centroid')),
208 wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
'area')),
209 wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
'face'))
212 typeoptSizer = wx.BoxSizer(wx.HORIZONTAL)
215 typeoptSizer.Add(item=type_box, flag=wx.ALIGN_LEFT, border=1)
217 self.ftypeSizer.Add(item = typeoptSizer,
218 flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=2)
220 outSizer = wx.GridBagSizer(hgap=5, vgap=5)
223 flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.EXPAND, border=1)
225 flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.EXPAND, border=1)
226 replaceSizer = wx.BoxSizer(wx.HORIZONTAL)
227 replaceSizer.Add(item=self.
overwrite, proportion=1,
228 flag=wx.ALL | wx.EXPAND, border=1)
230 outSizer.Add(item=replaceSizer, pos=(2, 0),
231 flag=wx.ALL | wx.EXPAND, border=1)
236 bodySizer = wx.GridBagSizer(hgap=5, vgap=5)
238 bodySizer.Add(item=self.
ct_label, pos=(0, 0), span=(1, 2),
239 flag=wx.ALL, border=5)
241 bodySizer.Add(item=self.
ct_panel, pos=(1, 0), span=(1, 2))
243 manageBoxSizer = wx.GridBagSizer(hgap=10, vgap=1)
245 manageBoxSizer.Add(item=self.
btn_add, pos=(1, 0), border=2, flag=wx.ALL | wx.EXPAND)
246 manageBoxSizer.Add(item=self.
btn_remove, pos=(2, 0), border=2, flag=wx.ALL | wx.EXPAND)
247 manageBoxSizer.Add(item=self.
btn_moveup, pos=(3, 0), border=2, flag=wx.ALL | wx.EXPAND)
248 manageBoxSizer.Add(item=self.
btn_movedown, pos=(4, 0), border=2, flag=wx.ALL | wx.EXPAND)
250 bodySizer.Add(item=manageBoxSizer, pos=(1, 2),
251 flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
253 bodySizer.AddGrowableCol(2)
258 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
260 flag=wx.LEFT | wx.RIGHT, border=5)
262 flag=wx.LEFT | wx.RIGHT, border=5)
264 flag=wx.LEFT | wx.RIGHT, border=5)
266 flag=wx.LEFT | wx.RIGHT, border=5)
271 sizer.Add(item=inSizer, proportion=0,
272 flag=wx.ALL | wx.EXPAND, border=5)
275 flag=wx.ALL | wx.EXPAND, border=5)
277 sizer.Add(item=outSizer, proportion=0,
278 flag=wx.ALL | wx.EXPAND, border=5)
280 sizer.Add(item=wx.StaticLine(parent=self, id=wx.ID_ANY,
281 style=wx.LI_HORIZONTAL), proportion=0,
282 flag=wx.EXPAND | wx.ALL, border=5)
284 sizer.Add(item=bodySizer, proportion=1,
285 flag=wx.ALL | wx.EXPAND, border=5)
287 sizer.Add(item=wx.StaticLine(parent=self, id=wx.ID_ANY,
288 style=wx.LI_HORIZONTAL), proportion=0,
289 flag=wx.EXPAND | wx.ALL, border=5)
291 sizer.Add(item=btnSizer, proportion=0,
292 flag=wx.ALL | wx.ALIGN_RIGHT, border=5)
298 def __toolsPanel(self):
299 ct_panel = scrolled.ScrolledPanel(parent=self, id=wx.ID_ANY,
301 style=wx.SUNKEN_BORDER)
306 ct_panel.SetAutoLayout(
True)
311 """!Add tool button pressed"""
315 snum = len(self.toolslines.keys())
318 tool_no = wx.StaticText(parent = self.
ct_panel, id = 3000+num,
321 tool_cbox = wx.ComboBox(parent = self.
ct_panel, id=1000+num,
323 style = wx.CB_DROPDOWN |
324 wx.CB_READONLY | wx.TE_PROCESS_ENTER)
325 self.Bind(wx.EVT_COMBOBOX, self.
OnSetTool, tool_cbox)
327 txt_ctrl = wx.TextCtrl(parent=self.
ct_panel, id=2000+num, value=
'0.00',
329 style=wx.TE_NOHIDESEL)
333 select = wx.CheckBox(parent=self.
ct_panel, id=num)
334 select.SetValue(
False)
335 self.Bind(wx.EVT_CHECKBOX, self.
OnSelect, select)
338 self.ct_sizer.Add(item=tool_no, pos=(num, 1),
339 flag=wx.ALIGN_CENTER_VERTICAL, border=5)
340 self.ct_sizer.Add(item=tool_cbox, pos=(num, 2),
341 flag=wx.ALIGN_CENTER | wx.RIGHT, border=5)
342 self.ct_sizer.Add(item=txt_ctrl, pos=(num, 3),
343 flag=wx.ALIGN_CENTER | wx.RIGHT, border=5)
344 self.ct_sizer.Add(item=select, pos=(num, 4),
345 flag=wx.ALIGN_CENTER | wx.RIGHT)
352 self.ct_panel.Layout()
353 self.ct_panel.SetupScrolling()
356 """!Remove tool button pressed"""
360 self.FindWindowById(id+1000).SetValue(
'')
363 self.SetStatusText(_(
"%s. cleaning tool removed, will be ignored") % id)
365 self.SetStatusText(_(
"Please select a cleaning tool to remove"))
368 """!Move up tool button pressed"""
376 self.FindWindowById(id_up).SetValue(
True)
377 self.FindWindowById(id_up+1000).SetValue(this_toolline[
'tool_desc'])
378 self.FindWindowById(id_up+2000).SetValue(this_toolline[
'thresh'])
381 self.FindWindowById(id).SetValue(
False)
382 self.FindWindowById(id+1000).SetValue(up_toolline[
'tool_desc'])
383 self.FindWindowById(id+2000).SetValue(up_toolline[
'thresh'])
386 self.SetStatusText(_(
"%s. cleaning tool moved up") % id)
388 self.SetStatusText(_(
"1. cleaning tool can not be moved up "))
390 self.SetStatusText(_(
"Please select a cleaning tool to move up"))
394 """!Move down tool button pressed"""
396 snum = len(self.toolslines.keys())
398 if id > 0
and id < snum:
403 self.FindWindowById(id_down).SetValue(
True)
404 self.FindWindowById(id_down+1000).SetValue(this_toolline[
'tool_desc'])
405 self.FindWindowById(id_down+2000).SetValue(this_toolline[
'thresh'])
408 self.FindWindowById(id).SetValue(
False)
409 self.FindWindowById(id+1000).SetValue(down_toolline[
'tool_desc'])
410 self.FindWindowById(id+2000).SetValue(down_toolline[
'thresh'])
413 self.SetStatusText(_(
"%s. cleaning tool moved down") % id)
415 self.SetStatusText(_(
"Last cleaning tool can not be moved down "))
417 self.SetStatusText(_(
"Please select a cleaning tool to move down"))
420 """!Tool was defined"""
423 num = self.FindWindowById(id).GetCurrentSelection()
428 self.SetStatusText( str(tool_no) +
'. ' + _(
"cleaning tool: '%s'") % (self.
tool_list[num]))
431 """!Threshold value was entered"""
434 self.
toolslines[num][
'thresh'] = self.FindWindowById(id).GetValue()
436 self.SetStatusText(_(
"Threshold for %(num)s. tool '%(tool)s': %(thresh)s") % \
442 """!Tool was selected"""
446 win = self.FindWindowById(self.
selected)
455 """!Builds options and runs v.clean
457 self.SetStatusText(_(
"Executing selected cleaning operations..."))
458 snum = len(self.toolslines.keys())
463 'input=%s' % self.inmap,
464 'output=%s' % self.outmap,
465 'tool=%s' % self.tools_string,
466 'thres=%s' % self.thresh_string ]
467 if self.ftype_string:
468 cmd.append(
'type=%s' % self.ftype_string)
469 if self.overwrite.IsChecked():
470 cmd.append(
'--overwrite')
475 if self.overwrite.IsChecked():
480 gcmd.RunCommand(self.cmd,
482 output = self.outmap,
483 type = self.ftype_string,
484 tool = self.tools_string,
485 thresh = self.thresh_string,
486 overwrite = overwrite)
492 """!Show GRASS manual page"""
493 gcmd.RunCommand(
'g.manual',
499 """!Copy the command"""
500 cmddata = wx.TextDataObject()
503 cmdstring =
'%s' % (self.
cmd)
505 cmdstring +=
' input=%s output=%s type=%s tool=%s thres=%s' % \
507 if self.overwrite.IsChecked():
508 cmdstring +=
' --overwrite'
510 cmddata.SetText(cmdstring)
511 if wx.TheClipboard.Open():
512 wx.TheClipboard.SetData(cmddata)
513 wx.TheClipboard.Close()
514 self.SetStatusText(_(
"Vector cleaning command copied to clipboard"))
522 for num
in range(0, self.
n_ftypes - 1):
533 snum = len(self.toolslines.keys())
534 for num
in range(1, snum + 1):
544 self.
inmap = self.selectionInput.GetValue()
545 self.
outmap = self.selectionOutput.GetValue()