2 @package modules.vclean
4 @brief Dialog for interactive construction of vector cleaning
8 - vclean::VectorCleaningFrame
10 (C) 2010-2011 by the GRASS Development Team
11 This program is free software under the GNU General Public License
12 (>=v2). Read the file COPYING that comes with GRASS for details.
20 import wx.lib.scrolledpanel
as scrolled
25 from core
import globalvar
31 def __init__(self, parent, id = wx.ID_ANY, title = _(
'Set up vector cleaning tools'),
32 style = wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER,
35 Dialog for interactively defining vector cleaning tools
37 wx.Frame.__init__(self, parent, id, title, style = style, **kwargs)
41 self.
log = self.parent.GetLogWindow()
49 self.CreateStatusBar()
52 self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR,
'grass.ico'), wx.BITMAP_TYPE_ICO))
54 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
68 _(
'break lines/boundaries'),
69 _(
'remove duplicates'),
71 _(
'change boundary dangles to lines'),
73 _(
'change bridges to lines'),
74 _(
'snap lines/boundaries'),
75 _(
'remove duplicate area centroids'),
77 _(
'prune lines/boundaries'),
78 _(
'remove small areas'),
79 _(
'remove lines/boundaries of zero length'),
80 _(
'remove small angles at nodes')
113 self.SetStatusText(_(
"Set up vector cleaning tools"))
115 self.
ctlabel = _(
'Choose cleaning tools and set thresholds')
119 label= _(
'Select input vector map:'))
121 size = globalvar.DIALOG_GSELECT_SIZE,
124 ftypeBox = wx.StaticBox(parent = self.
panel, id = wx.ID_ANY,
125 label = _(
' Feature type: '))
129 label = _(
'Select output vector map:'))
131 size = globalvar.DIALOG_GSELECT_SIZE,
135 label = _(
'Allow output files to overwrite existing files'))
136 self.overwrite.SetValue(UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled'))
156 self.
btn_run = wx.Button(parent = self.
panel, id = wx.ID_ANY, label = _(
"&Run"))
157 self.btn_run.SetDefault()
159 self.btn_clipboard.SetToolTipString(_(
"Copy the current command string to the clipboard (Ctrl+C)"))
163 self.btn_close.Bind(wx.EVT_BUTTON, self.
OnClose)
165 self.btn_clipboard.Bind(wx.EVT_BUTTON, self.
OnCopy)
166 self.btn_help.Bind(wx.EVT_BUTTON, self.
OnHelp)
168 self.btn_add.Bind(wx.EVT_BUTTON, self.
OnAddTool)
169 self.btn_remove.Bind(wx.EVT_BUTTON, self.
OnClearTool)
176 self.SetMinSize(self.GetBestSize())
178 self.CentreOnScreen()
181 sizer = wx.BoxSizer(wx.VERTICAL)
186 inSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
188 inSizer.Add(item = self.
inmaplabel, pos = (0, 0),
189 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.EXPAND, border = 1)
191 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.EXPAND, border = 1)
194 wx.CheckBox(parent = self.
panel, id = wx.ID_ANY, label = _(
'point')),
195 wx.CheckBox(parent = self.
panel, id = wx.ID_ANY, label = _(
'line')),
196 wx.CheckBox(parent = self.
panel, id = wx.ID_ANY, label = _(
'boundary')),
197 wx.CheckBox(parent = self.
panel, id = wx.ID_ANY, label = _(
'centroid')),
198 wx.CheckBox(parent = self.
panel, id = wx.ID_ANY, label = _(
'area')),
199 wx.CheckBox(parent = self.
panel, id = wx.ID_ANY, label = _(
'face'))
202 typeoptSizer = wx.BoxSizer(wx.HORIZONTAL)
205 typeoptSizer.Add(item = type_box, flag = wx.ALIGN_LEFT, border = 1)
207 self.ftypeSizer.Add(item = typeoptSizer,
208 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 2)
210 outSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
212 outSizer.Add(item = self.
outmaplabel, pos = (0, 0),
213 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.EXPAND, border = 1)
215 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.EXPAND, border = 1)
216 replaceSizer = wx.BoxSizer(wx.HORIZONTAL)
217 replaceSizer.Add(item = self.
overwrite, proportion = 1,
218 flag = wx.ALL | wx.EXPAND, border = 1)
220 outSizer.Add(item = replaceSizer, pos = (2, 0),
221 flag = wx.ALL | wx.EXPAND, border = 1)
226 bodySizer = wx.GridBagSizer(hgap = 5, vgap = 5)
228 bodySizer.Add(item = self.
ct_label, pos = (0, 0), span = (1, 2),
229 flag = wx.ALL, border = 5)
231 bodySizer.Add(item = self.
ct_panel, pos = (1, 0), span = (1, 2))
233 manageBoxSizer = wx.GridBagSizer(hgap = 10, vgap = 1)
235 manageBoxSizer.Add(item = self.
btn_add, pos = (1, 0), border = 2, flag = wx.ALL | wx.EXPAND)
236 manageBoxSizer.Add(item = self.
btn_remove, pos = (2, 0), border = 2, flag = wx.ALL | wx.EXPAND)
237 manageBoxSizer.Add(item = self.
btn_moveup, pos = (3, 0), border = 2, flag = wx.ALL | wx.EXPAND)
238 manageBoxSizer.Add(item = self.
btn_movedown, pos = (4, 0), border = 2, flag = wx.ALL | wx.EXPAND)
240 bodySizer.Add(item = manageBoxSizer, pos = (1, 2),
241 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
243 bodySizer.AddGrowableCol(2)
248 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
250 flag = wx.LEFT | wx.RIGHT, border = 5)
252 flag = wx.LEFT | wx.RIGHT, border = 5)
254 flag = wx.LEFT | wx.RIGHT, border = 5)
256 flag = wx.LEFT | wx.RIGHT, border = 5)
261 sizer.Add(item = inSizer, proportion = 0,
262 flag = wx.ALL | wx.EXPAND, border = 5)
264 sizer.Add(item = self.
ftypeSizer, proportion = 0,
265 flag = wx.ALL | wx.EXPAND, border = 5)
267 sizer.Add(item = outSizer, proportion = 0,
268 flag = wx.ALL | wx.EXPAND, border = 5)
270 sizer.Add(item = wx.StaticLine(parent = self, id = wx.ID_ANY,
271 style = wx.LI_HORIZONTAL), proportion = 0,
272 flag = wx.EXPAND | wx.ALL, border = 5)
274 sizer.Add(item = bodySizer, proportion = 1,
275 flag = wx.ALL | wx.EXPAND, border = 5)
277 sizer.Add(item = wx.StaticLine(parent = self, id = wx.ID_ANY,
278 style = wx.LI_HORIZONTAL), proportion = 0,
279 flag = wx.EXPAND | wx.ALL, border = 5)
281 sizer.Add(item = btnSizer, proportion = 0,
282 flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
284 self.panel.SetAutoLayout(
True)
285 self.panel.SetSizer(sizer)
286 sizer.Fit(self.
panel)
290 def _toolsPanel(self):
291 ct_panel = scrolled.ScrolledPanel(parent = self.
panel, id = wx.ID_ANY,
293 style = wx.SUNKEN_BORDER)
295 self.
ct_sizer = wx.GridBagSizer(vgap = 2, hgap = 4)
298 ct_panel.SetAutoLayout(
True)
303 """!Add tool button pressed"""
307 snum = len(self.toolslines.keys())
310 tool_no = wx.StaticText(parent = self.
ct_panel, id = 3000+num,
311 label = str(num)+
'.')
313 tool_cbox = wx.ComboBox(parent = self.
ct_panel, id = 1000+num,
315 style = wx.CB_DROPDOWN |
316 wx.CB_READONLY | wx.TE_PROCESS_ENTER)
317 self.Bind(wx.EVT_COMBOBOX, self.
OnSetTool, tool_cbox)
319 txt_ctrl = wx.TextCtrl(parent = self.
ct_panel, id = 2000+num, value =
'0.00',
321 style = wx.TE_NOHIDESEL)
325 select = wx.CheckBox(parent = self.
ct_panel, id = num)
326 select.SetValue(
False)
327 self.Bind(wx.EVT_CHECKBOX, self.
OnSelect, select)
330 self.ct_sizer.Add(item = tool_no, pos = (num, 1),
331 flag = wx.ALIGN_CENTER_VERTICAL, border = 5)
332 self.ct_sizer.Add(item = tool_cbox, pos = (num, 2),
333 flag = wx.ALIGN_CENTER | wx.RIGHT, border = 5)
334 self.ct_sizer.Add(item = txt_ctrl, pos = (num, 3),
335 flag = wx.ALIGN_CENTER | wx.RIGHT, border = 5)
336 self.ct_sizer.Add(item = select, pos = (num, 4),
337 flag = wx.ALIGN_CENTER | wx.RIGHT)
344 self.ct_panel.Layout()
345 self.ct_panel.SetupScrolling()
348 """!Remove tool button pressed"""
352 self.FindWindowById(id+1000).
SetValue(
'')
355 self.SetStatusText(_(
"%s. cleaning tool removed, will be ignored") % id)
357 self.SetStatusText(_(
"Please select a cleaning tool to remove"))
360 """!Move up tool button pressed"""
368 self.FindWindowById(id_up).
SetValue(
True)
369 self.FindWindowById(id_up+1000).
SetValue(this_toolline[
'tool_desc'])
370 self.FindWindowById(id_up+2000).
SetValue(this_toolline[
'thresh'])
373 self.FindWindowById(id).
SetValue(
False)
374 self.FindWindowById(id+1000).
SetValue(up_toolline[
'tool_desc'])
375 self.FindWindowById(id+2000).
SetValue(up_toolline[
'thresh'])
378 self.SetStatusText(_(
"%s. cleaning tool moved up") % id)
380 self.SetStatusText(_(
"1. cleaning tool can not be moved up "))
382 self.SetStatusText(_(
"Please select a cleaning tool to move up"))
386 """!Move down tool button pressed"""
388 snum = len(self.toolslines.keys())
390 if id > 0
and id < snum:
395 self.FindWindowById(id_down).
SetValue(
True)
396 self.FindWindowById(id_down+1000).
SetValue(this_toolline[
'tool_desc'])
397 self.FindWindowById(id_down+2000).
SetValue(this_toolline[
'thresh'])
400 self.FindWindowById(id).
SetValue(
False)
401 self.FindWindowById(id+1000).
SetValue(down_toolline[
'tool_desc'])
402 self.FindWindowById(id+2000).
SetValue(down_toolline[
'thresh'])
405 self.SetStatusText(_(
"%s. cleaning tool moved down") % id)
407 self.SetStatusText(_(
"Last cleaning tool can not be moved down "))
409 self.SetStatusText(_(
"Please select a cleaning tool to move down"))
412 """!Tool was defined"""
415 num = self.FindWindowById(id).GetCurrentSelection()
420 self.SetStatusText( str(tool_no) +
'. ' + _(
"cleaning tool: '%s'") % (self.
tool_list[num]))
423 """!Threshold value was entered"""
428 self.SetStatusText(_(
"Threshold for %(num)s. tool '%(tool)s': %(thresh)s") % \
434 """!Tool was selected"""
438 win = self.FindWindowById(self.
selected)
448 self.SetStatusText(
'')
451 """!Builds options and runs v.clean
456 for p, name
in ((self.
inmap, _(
'Name of input vector map')),
457 (self.
outmap, _(
'Name for output vector map')),
461 err.append(_(
"'%s' not defined") % name)
463 GError(_(
"Some parameters not defined. Operation "
464 "canceled.\n\n%s") %
'\n'.join(err),
468 self.SetStatusText(_(
"Executing selected cleaning operations..."))
469 snum = len(self.toolslines.keys())
473 'input=%s' % self.
inmap,
474 'output=%s' % self.
outmap,
479 if self.overwrite.IsChecked():
480 cmd.append(
'--overwrite')
482 self.log.RunCmd(cmd, onDone = self.
OnDone)
485 if self.overwrite.IsChecked():
496 overwrite = overwrite)
502 """!Show GRASS manual page"""
509 """!Copy the command"""
510 cmddata = wx.TextDataObject()
513 cmdstring =
'%s' % (self.
cmd)
515 cmdstring +=
' input=%s output=%s type=%s tool=%s thres=%s' % \
517 if self.overwrite.IsChecked():
518 cmdstring +=
' --overwrite'
520 cmddata.SetText(cmdstring)
521 if wx.TheClipboard.Open():
522 wx.TheClipboard.SetData(cmddata)
523 wx.TheClipboard.Close()
524 self.SetStatusText(_(
"Vector cleaning command copied to clipboard"))
543 snum = len(self.toolslines.keys())
544 for num
in range(1, snum + 1):
554 self.
inmap = self.selectionInput.GetValue()
555 self.
outmap = self.selectionOutput.GetValue()