4 @brief Open/save workspace definition file
12 (C) 2007-2010 by the GRASS Development Team
13 This program is free software under the GNU General Public
14 License (>=v2). Read the file COPYING that comes with GRASS
17 @author Martin Landa <landa.martin gmail.com>
31 import xml.etree.ElementTree
as etree
33 import elementtree.ElementTree
as etree
37 from preferences
import globalSettings
as UserSettings
41 except (ImportError, NameError):
46 """!A ElementTree handler for the GXW XML file, as defined in
50 self.
root = self.tree.getroot()
74 def __filterValue(self, value):
79 value = value.replace(
'<',
'<')
80 value = value.replace(
'>',
'>')
84 def __getNodeText(self, node, tag, default = ''):
88 return utils.normalize_whitespace(p.text)
92 def __processFile(self):
93 """!Process workspace file"""
97 node_lm = self.root.find(
'layer_manager')
98 if node_lm
is not None:
99 posAttr = node_lm.get(
'dim',
'')
101 posVal =
map(int, posAttr.split(
','))
111 for display
in self.root.findall(
'display'):
115 posAttr = display.get(
'dim',
'')
117 posVal =
map(int, posAttr.split(
','))
119 pos = (posVal[0], posVal[1])
120 size = (posVal[2], posVal[3])
128 extentAttr = display.get(
'extent',
'')
131 extent =
map(float, extentAttr.split(
','))
136 node_projection = display.find(
'projection')
137 if node_projection
is not None:
138 projection = {
'enabled' :
True,
139 'epsg' : node_projection.get(
'epsg',
''),
142 projection = {
'enabled' :
False }
144 self.displays.append( {
145 "render" : bool(int(display.get(
'render',
"0"))),
146 "mode" : int(display.get(
'mode', 0)),
147 "showCompExtent" : bool(int(display.get(
'showCompExtent',
"0"))),
151 "constrainRes" : bool(int(display.get(
'constrainRes',
"0"))),
152 "projection" : projection, } )
157 def __processLayers(self, node, inGroup = -1):
158 """!Process layers/groups of selected display
160 @param node display tree node
161 @param inGroup in group -> index of group item otherwise -1
163 for item
in node.getchildren():
164 if item.tag ==
'group':
166 self.layers.append( {
168 "name" : item.get(
'name',
''),
169 "checked" : bool(int(item.get(
'checked',
"0"))),
179 elif item.tag ==
'layer':
182 self.layers.append( {
183 "type" : item.get(
'type',
None),
184 "name" : item.get(
'name',
None),
185 "checked" : bool(int(item.get(
'checked',
"0"))),
186 "opacity" : float(item.get(
'opacity',
'1.0')),
190 "selected" : selected,
194 def __processLayer(self, layer):
195 """!Process layer item
197 @param layer tree node
204 node_task = layer.find(
'task')
205 cmd.append(node_task.get(
'name',
"unknown"))
208 for p
in node_task.findall(
'flag'):
209 flag = p.get(
'name',
'')
211 cmd.append(
'--' + flag)
213 cmd.append(
'-' + flag)
216 for p
in node_task.findall(
'parameter'):
217 cmd.append(
'%s=%s' % (p.get(
'name',
''),
220 if layer.find(
'selected')
is not None:
228 node_vdigit = layer.find(
'vdigit')
229 if node_vdigit
is not None:
237 node_nviz = layer.find(
'nviz')
238 if node_nviz
is not None:
243 return (cmd, selected, vdigit, nviz)
245 def __processLayerVdigit(self, node_vdigit):
246 """!Process vector digitizer layer settings
248 @param node_vdigit vdigit node
252 for node
in node_vdigit.findall(
'geometryAttribute'):
253 if 'geomAttr' not in vdigit:
254 vdigit[
'geomAttr'] = dict()
255 type = node.get(
'type')
256 vdigit[
'geomAttr'][type] = dict()
257 vdigit[
'geomAttr'][type][
'column'] = node.get(
'column')
259 vdigit[
'geomAttr'][type][
'units'] = node.get(
'units',
'mu')
263 def __processLayerNviz(self, node_nviz):
264 """!Process 3D layer settings
266 @param node_nviz nviz node
270 if node_nviz.find(
'surface')
is not None:
272 for sec
in (
'attribute',
'draw',
'mask',
'position'):
273 nviz[
'surface'][sec] = {}
274 elif node_nviz.find(
'vlines')
is not None or \
275 node_nviz.find(
'vpoints')
is not None:
277 for sec
in (
'lines',
'points'):
278 nviz[
'vector'][sec] = {}
280 if 'surface' in nviz:
281 node_surface = node_nviz.find(
'surface')
283 for attrb
in node_surface.findall(
'attribute'):
284 tagName = str(attrb.tag)
285 attrbName = attrb.get(
'name',
'')
286 dc = nviz[
'surface'][tagName][attrbName] = {}
287 if attrb.get(
'map',
'0') ==
'0':
293 dc[
'value'] = int(value)
296 dc[
'value'] = float(value)
298 dc[
'value'] = str(value)
301 node_draw = node_surface.find(
'draw')
302 if node_draw
is not None:
303 tagName = str(node_draw.tag)
304 nviz[
'surface'][tagName][
'all'] =
False
305 nviz[
'surface'][tagName][
'mode'] = {}
306 nviz[
'surface'][tagName][
'mode'][
'value'] = -1
307 nviz[
'surface'][tagName][
'mode'][
'desc'] = {}
308 nviz[
'surface'][tagName][
'mode'][
'desc'][
'shading'] = \
309 str(node_draw.get(
'shading',
''))
310 nviz[
'surface'][tagName][
'mode'][
'desc'][
'style'] = \
311 str(node_draw.get(
'style',
''))
312 nviz[
'surface'][tagName][
'mode'][
'desc'][
'mode'] = \
313 str(node_draw.get(
'mode',
''))
316 for node_res
in node_draw.findall(
'resolution'):
317 resType = str(node_res.get(
'type',
''))
318 if 'resolution' not in nviz[
'surface'][
'draw']:
319 nviz[
'surface'][
'draw'][
'resolution'] = {}
321 nviz[
'surface'][
'draw'][
'resolution'][resType] = value
324 node_wire_color = node_draw.find(
'wire_color')
325 if node_wire_color
is not None:
326 nviz[
'surface'][
'draw'][
'wire-color'] = {}
328 nviz[
'surface'][
'draw'][
'wire-color'][
'value'] = value
331 node_pos = node_surface.find(
'position')
332 if node_pos
is not None:
333 dc = self.nviz[
'surface'][
'position'] = {}
334 for coor
in [
'x',
'y',
'z']:
335 node = node_pos.find(coor)
341 elif 'vector' in nviz:
343 node_vpoints = node_nviz.find(
'vpoints')
344 if node_vpoints
is not None:
345 marker = str(node_vpoints.get(
'marker',
''))
346 markerId = list(UserSettings.Get(group=
'nviz', key=
'vector',
347 subkey=[
'points',
'marker'], internal=
True)).index(marker)
348 nviz[
'vector'][
'points'][
'marker'] = {
'value' : markerId }
350 node_mode = node_vpoints.find(
'mode')
351 if node_mode
is not None:
352 nviz[
'vector'][
'points'][
'mode'] = {}
353 nviz[
'vector'][
'points'][
'mode'][
'type'] = str(node_mode.get(
'type',
''))
354 nviz[
'vector'][
'points'][
'mode'][
'surface'] = \
359 nviz[
'vector'][
'points'])
363 nviz[
'vector'][
'points'])
367 nviz[
'vector'][
'points'])
371 nviz[
'vector'][
'points'])
374 node_vlines = node_nviz.find(
'vlines')
375 if node_vlines
is not None:
376 node_mode = node_vlines.find(
'mode')
377 if node_mode
is not None:
378 nviz[
'vector'][
'lines'][
'mode'] = {}
379 nviz[
'vector'][
'lines'][
'mode'][
'type'] = str(node_mode.get(
'type',
''))
380 nviz[
'vector'][
'lines'][
'mode'][
'surface'] =
''
383 nviz[
'vector'][
'lines'][
'mode'][
'surface'] = \
388 nviz[
'vector'][
'lines'])
392 nviz[
'vector'][
'lines'])
396 nviz[
'vector'][
'lines'])
400 def __processLayerNvizNode(self, node, tag, cast, dc = None):
401 """!Process given tag nviz/vector"""
402 node_tag = node.find(tag)
403 if node_tag
is not None:
404 if node_tag.find(
'value')
is not None:
408 value = cast(node_tag.text)
416 dc[tag][
'value'] = value
422 """Default 3D settings"""
426 """Set default surface data properties"""
428 for sec
in (
'attribute',
'draw',
'mask',
'position'):
434 for attrb
in (
'shine', ):
435 data[
'attribute'][attrb] = {}
436 for key, value
in UserSettings.Get(group=
'nviz', key=
'volume',
437 subkey=attrb).iteritems():
438 data[
'attribute'][attrb][key] = value
439 data[
'attribute'][attrb][
'update'] =
None
444 data[
'draw'][
'all'] =
False
445 for control, value
in UserSettings.Get(group=
'nviz', key=
'surface', subkey=
'draw').iteritems():
446 if control[:3] ==
'res':
447 if 'resolution' not in data[
'draw']:
448 data[
'draw'][
'resolution'] = {}
449 if 'update' not in data[
'draw'][
'resolution']:
450 data[
'draw'][
'resolution'][
'update'] =
None
451 data[
'draw'][
'resolution'][control[4:]] = value
454 if control ==
'wire-color':
455 value = str(value[0]) +
':' + str(value[1]) +
':' + str(value[2])
456 elif control
in (
'mode',
'style',
'shading'):
457 if 'mode' not in data[
'draw']:
458 data[
'draw'][
'mode'] = {}
461 data[
'draw'][control] = {
'value' : value }
462 data[
'draw'][control][
'update'] =
None
464 value, desc = self.GetDrawMode(UserSettings.Get(group=
'nviz', key=
'surface', subkey=[
'draw',
'mode']),
465 UserSettings.Get(group=
'nviz', key=
'surface', subkey=[
'draw',
'style']),
466 UserSettings.Get(group=
'nviz', key=
'surface', subkey=[
'draw',
'shading']))
468 data[
'draw'][
'mode'] = {
'value' : value,
475 """Set default volume data properties"""
477 for sec
in (
'attribute',
'draw',
'position'):
479 for sec
in (
'isosurface',
'slice'):
485 for control, value
in UserSettings.Get(group=
'nviz', key=
'volume', subkey=
'draw').iteritems():
486 if control ==
'mode':
488 if control ==
'shading':
489 sel = UserSettings.Get(group=
'nviz', key=
'surface', subkey=[
'draw',
'shading'])
490 value, desc = self.
GetDrawMode(shade=sel, string=
False)
492 data[
'draw'][
'shading'] = {
'value' : value,
493 'desc' : desc[
'shading'] }
494 elif control ==
'mode':
495 sel = UserSettings.Get(group=
'nviz', key=
'volume', subkey=[
'draw',
'mode'])
500 data[
'draw'][
'mode'] = {
'value' : sel,
503 data[
'draw'][control] = {
'value' : value }
505 if 'update' not in data[
'draw'][control]:
506 data[
'draw'][control][
'update'] =
None
511 for attrb
in (
'shine', ):
512 data[
'attribute'][attrb] = {}
513 for key, value
in UserSettings.Get(group=
'nviz', key=
'volume',
514 subkey=attrb).iteritems():
515 data[
'attribute'][attrb][key] = value
520 """Set default vector data properties"""
522 for sec
in (
'lines',
'points'):
531 """Set default vector properties -- lines"""
533 data[
'width'] = {
'value' : UserSettings.Get(group=
'nviz', key=
'vector',
534 subkey=[
'lines',
'width']) }
537 value = UserSettings.Get(group=
'nviz', key=
'vector',
538 subkey=[
'lines',
'color'])
539 color = str(value[0]) +
':' + str(value[1]) +
':' + str(value[2])
540 data[
'color'] = {
'value' : color }
543 if UserSettings.Get(group=
'nviz', key=
'vector',
544 subkey=[
'lines',
'flat']):
552 data[
'mode'][
'type'] = type
553 data[
'mode'][
'update'] =
None
555 data[
'mode'][
'surface'] = map
558 data[
'height'] = {
'value' : UserSettings.Get(group=
'nviz', key=
'vector',
559 subkey=[
'lines',
'height']) }
562 for attrb
in (
'color',
'width',
'mode',
'height'):
563 data[attrb][
'update'] =
None
566 """Set default vector properties -- points"""
568 data[
'size'] = {
'value' : UserSettings.Get(group=
'nviz', key=
'vector',
569 subkey=[
'points',
'size']) }
572 data[
'width'] = {
'value' : UserSettings.Get(group=
'nviz', key=
'vector',
573 subkey=[
'points',
'width']) }
576 data[
'marker'] = {
'value' : UserSettings.Get(group=
'nviz', key=
'vector',
577 subkey=[
'points',
'marker']) }
580 value = UserSettings.Get(group=
'nviz', key=
'vector',
581 subkey=[
'points',
'color'])
582 color = str(value[0]) +
':' + str(value[1]) +
':' + str(value[2])
583 data[
'color'] = {
'value' : color }
586 data[
'mode'] = {
'type' :
'surface',
590 data[
'height'] = {
'value' : UserSettings.Get(group=
'nviz', key=
'vector',
591 subkey=[
'points',
'height']) }
594 for attrb
in (
'size',
'width',
'marker',
595 'color',
'surface',
'height'):
596 data[attrb][
'update'] =
None
598 def GetDrawMode(self, mode=None, style=None, shade=None, string=False):
599 """Get surface draw mode (value) from description/selection
601 @param mode,style,shade modes
602 @param string if True input parameters are strings otherwise
614 value |= wxnviz.DM_WIRE
616 value |= wxnviz.DM_POLY
618 value |= wxnviz.DM_WIRE_POLY
620 if style
is not None:
622 value |= wxnviz.DM_GRID_WIRE
624 value |= wxnviz.DM_GRID_SURF
626 if shade
is not None:
628 value |= wxnviz.DM_FLAT
630 value |= wxnviz.DM_GOURAUD
637 value |= wxnviz.DM_WIRE
638 desc[
'mode'] =
'coarse'
640 value |= wxnviz.DM_POLY
641 desc[
'mode'] =
'fine'
643 value |= wxnviz.DM_WIRE_POLY
644 desc[
'mode'] =
'both'
646 if style
is not None:
648 value |= wxnviz.DM_GRID_WIRE
649 desc[
'style'] =
'wire'
651 value |= wxnviz.DM_GRID_SURF
652 desc[
'style'] =
'surface'
654 if shade
is not None:
656 value |= wxnviz.DM_FLAT
657 desc[
'shading'] =
'flat'
659 value |= wxnviz.DM_GOURAUD
660 desc[
'shading'] =
'gouraud'
665 """!Generic class for writing workspace file"""
672 self.file.write(
'<?xml version="1.0" encoding="UTF-8"?>\n')
673 self.file.write(
'<!DOCTYPE gxw SYSTEM "grass-gxw.dtd">\n')
674 self.file.write(
'%s<gxw>\n' % (
' ' * self.
indent))
679 windowPos = self.lmgr.GetPosition()
680 windowSize = self.lmgr.GetSize()
681 file.write(
'%s<layer_manager dim="%d,%d,%d,%d">\n' % (
' ' * self.
indent,
688 file.write(
'%s</layer_manager>\n' % (
' ' * self.
indent))
691 for page
in range(0, self.lmgr.gm_cb.GetPageCount()):
692 mapTree = self.lmgr.gm_cb.GetPage(page).maptree
693 region = mapTree.Map.region
695 displayPos = mapTree.mapdisplay.GetPosition()
696 displaySize = mapTree.mapdisplay.GetSize()
698 file.write(
'%s<display render="%d" '
699 'mode="%d" showCompExtent="%d" '
702 'extent="%f,%f,%f,%f">\n' % (
' ' * self.
indent,
703 int(mapTree.mapdisplay.statusbarWin[
'render'].IsChecked()),
704 mapTree.mapdisplay.statusbarWin[
'toggle'].GetSelection(),
705 int(mapTree.mapdisplay.statusbarWin[
'region'].IsChecked()),
706 int(mapTree.mapdisplay.statusbarWin[
'resolution'].IsChecked()),
717 if mapTree.mapdisplay.statusbarWin[
'projection'].IsChecked()
and \
718 UserSettings.Get(group=
'display', key=
'projection', subkey=
'proj4'):
720 file.write(
'%s<projection' % (
' ' * self.
indent))
721 epsg = UserSettings.Get(group=
'display', key=
'projection', subkey=
'epsg')
723 file.write(
' epsg="%s"' % epsg)
725 proj = UserSettings.Get(group=
'display', key=
'projection', subkey=
'proj4')
727 file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, proj))
729 file.write(
'%s</projection>\n' % (
' ' * self.
indent))
733 item = mapTree.GetFirstChild(mapTree.root)[0]
735 file.write(
'%s</display>\n' % (
' ' * self.
indent))
738 file.write(
'%s</gxw>\n' % (
' ' * self.
indent))
740 def __filterValue(self, value):
741 """!Make value XML-valid"""
742 value = value.replace(
'<',
'<')
743 value = value.replace(
'>',
'>')
747 def __writeLayer(self, mapTree, item):
748 """!Write bunch of layers to GRASS Workspace XML file"""
750 itemSelected = mapTree.GetSelections()
751 while item
and item.IsOk():
752 type = mapTree.GetPyData(item)[0][
'type']
754 maplayer = mapTree.GetPyData(item)[0][
'maplayer']
758 checked = int(item.IsChecked())
759 if type ==
'command':
760 cmd = mapTree.GetPyData(item)[0][
'maplayer'].GetCmd(string=
True)
761 self.file.write(
'%s<layer type="%s" name="%s" checked="%d">\n' % \
762 (
' ' * self.
indent, type, cmd, checked));
763 self.file.write(
'%s</layer>\n' % (
' ' * self.
indent));
764 elif type ==
'group':
765 name = mapTree.GetItemText(item)
766 self.file.write(
'%s<group name="%s" checked="%d">\n' % \
767 (
' ' * self.
indent, name.encode(
'utf8'), checked));
769 subItem = mapTree.GetFirstChild(item)[0]
772 self.file.write(
'%s</group>\n' % (
' ' * self.
indent));
774 cmd = mapTree.GetPyData(item)[0][
'maplayer'].GetCmd(string=
False)
775 name = mapTree.GetItemText(item)
776 opacity = maplayer.GetOpacity(float =
True)
779 name = name.split(
'(', -1)[0].strip()
780 self.file.write(
'%s<layer type="%s" name="%s" checked="%d" opacity="%f">\n' % \
781 (
' ' * self.
indent, type, name.encode(
'utf8'), checked, opacity));
785 if item
in itemSelected:
786 self.file.write(
'%s<selected />\n' % (
' ' * self.
indent))
788 self.file.write(
'%s<task name="%s">\n' % (
' ' * self.
indent, cmd[0]))
790 for key, val
in cmd[1].iteritems():
793 self.file.write(
'%s<flag name="%s" />\n' %
795 elif val
in (
True,
False):
796 self.file.write(
'%s<flag name="%s" />\n' %
799 self.file.write(
'%s<parameter name="%s">\n' %
802 self.file.write(
'%s<value>%s</value>\n' %
805 self.file.write(
'%s</parameter>\n' % (
' ' * self.
indent));
807 self.file.write(
'%s</task>\n' % (
' ' * self.
indent));
809 vdigit = mapTree.GetPyData(item)[0][
'vdigit']
811 self.file.write(
'%s<vdigit>\n' % (
' ' * self.
indent))
812 if 'geomAttr' in vdigit:
814 for type, val
in vdigit[
'geomAttr'].iteritems():
816 if val[
'units'] !=
'mu':
817 units =
' units="%s"' % val[
'units']
818 self.file.write(
'%s<geometryAttribute type="%s" column="%s"%s />\n' % \
819 (
' ' * self.
indent, type, val[
'column'], units))
821 self.file.write(
'%s</vdigit>\n' % (
' ' * self.
indent))
823 nviz = mapTree.GetPyData(item)[0][
'nviz']
825 self.file.write(
'%s<nviz>\n' % (
' ' * self.
indent))
826 if maplayer.type ==
'raster':
828 elif maplayer.type ==
'vector':
830 self.file.write(
'%s</nviz>\n' % (
' ' * self.
indent))
832 self.file.write(
'%s</layer>\n' % (
' ' * self.
indent))
833 item = mapTree.GetNextSibling(item)
836 def __writeNvizSurface(self, data):
837 """!Save Nviz raster layer properties to workspace
839 @param data Nviz layer properties
841 if 'object' not in data:
845 self.file.write(
'%s<surface>\n' % (
' ' * self.
indent))
847 for attrb
in data.iterkeys():
848 if len(data[attrb]) < 1:
850 if attrb ==
'object':
853 for name
in data[attrb].iterkeys():
855 if attrb ==
'attribute':
856 self.file.write(
'%s<%s name="%s" map="%d">\n' % \
857 (
' ' * self.
indent, attrb, name, data[attrb][name][
'map']))
859 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, data[attrb][name][
'value']))
862 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, attrb))
866 self.file.write(
'%s<%s' %(
' ' * self.
indent, attrb))
867 if 'mode' in data[attrb]:
868 for tag, value
in data[attrb][
'mode'][
'desc'].iteritems():
869 self.file.write(
' %s="%s"' % (tag, value))
870 self.file.write(
'>\n')
872 if 'resolution' in data[attrb]:
874 for type
in (
'coarse',
'fine'):
875 self.file.write(
'%s<resolution type="%s">\n' % (
' ' * self.
indent, type))
877 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent,
878 data[attrb][
'resolution'][type]))
880 self.file.write(
'%s</resolution>\n' % (
' ' * self.
indent))
882 if 'wire-color' in data[attrb]:
883 self.file.write(
'%s<wire_color>\n' % (
' ' * self.
indent))
885 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent,
886 data[attrb][
'wire-color'][
'value']))
888 self.file.write(
'%s</wire_color>\n' % (
' ' * self.
indent))
892 elif attrb ==
'position':
893 self.file.write(
'%s<%s>\n' %(
' ' * self.
indent, attrb))
895 for tag
in (
'x',
'y',
'z'):
897 self.file.write(
'%s<%s>%d</%s>\n' % (
' ' * self.
indent, tag,
898 data[attrb][tag], tag))
902 if attrb !=
'attribute':
904 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, attrb))
907 self.file.write(
'%s</surface>\n' % (
' ' * self.
indent))
910 def __writeNvizVector(self, data):
911 """!Save Nviz vector layer properties (lines/points) to workspace
913 @param data Nviz layer properties
916 for attrb
in data.iterkeys():
917 if len(data[attrb]) < 1:
920 if 'object' not in data[attrb]:
923 self.file.write(
'%s<v%s>\n' % (
' ' * self.
indent, attrb))
924 elif attrb ==
'points':
925 markerId = data[attrb][
'marker'][
'value']
926 marker = UserSettings.Get(group =
'nviz', key =
'vector',
927 subkey = [
'points',
'marker'], internal =
True)[markerId]
928 self.file.write(
'%s<v%s marker="%s">\n' % (
' ' * self.
indent,
932 for name
in data[attrb].iterkeys():
933 if name
in (
'object',
'marker'):
936 self.file.write(
'%s<%s type="%s">\n' % (
' ' * self.
indent, name,
937 data[attrb][name][
'type']))
938 if data[attrb][name][
'type'] ==
'surface':
940 self.file.write(
'%s<map>%s</map>\n' % (
' ' * self.
indent,
941 data[attrb][name][
'surface']))
943 self.file.write(
'%s</%s>\n' % ((
' ' * self.
indent, name)))
945 self.file.write(
'%s<%s>\n' % (
' ' * self.
indent, name))
947 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, data[attrb][name][
'value']))
949 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, name))
951 self.file.write(
'%s</v%s>\n' % (
' ' * self.
indent, attrb))
957 """!Process GRC file"""
975 @param parent parent window
977 @return list of map layers
982 wx.MessageBox(parent=parent,
983 message=_(
"Unable to open file <%s> for reading.") % self.
filename,
984 caption=_(
"Error"), style=wx.OK | wx.ICON_ERROR)
988 for line
in file.readlines():
995 wx.MessageBox(parent=parent,
996 message=_(
"Some lines were skipped when reading settings "
997 "from file <%(file)s>.\nSee 'Command output' window for details.\n\n"
998 "Number of skipped lines: %(line)d") % \
1000 caption=_(
"Warning"), style=wx.OK | wx.ICON_EXCLAMATION)
1001 parent.goutput.WriteLog(
'Map layers loaded from GRC file <%s>' % self.
filename)
1002 parent.goutput.WriteLog(
'Skipped lines:\n%s' % self.
error)
1007 """!Process line definition"""
1009 if element ==
'Group':
1011 self.layers.append({
1021 elif element ==
'_check':
1023 self.
layers[-1][
'checked'] =
True
1025 self.
layers[-1][
'checked'] =
False
1027 elif element ==
'End':
1037 elif element ==
'opacity':
1041 elif element ==
'Raster':
1043 self.layers.append({
1052 elif element ==
'map' and self.
inRaster:
1055 elif element ==
'overlay' and self.
inRaster:
1057 self.
layers[-1][
'cmd'].append(
'-o')
1059 elif element ==
'rastquery' and self.
inRaster:
1062 self.
layers[-1][
'cmd'].append(
'catlist=%s' % value)
1064 elif element ==
'bkcolor' and self.
inRaster:
1067 self.
layers[-1][
'cmd'].append(
'bg=%s' % value)
1070 elif element ==
'Vector':
1072 self.layers.append({
1081 elif element ==
'vect' and self.
inVector:
1084 elif element
in (
'display_shape',
1097 name = element.split(
'_')[0]
1098 type = element.split(
'_')[1]
1101 self.
layers[-1][
'cmd'].append(
'%s=%s' % (name, type))
1103 self.
layers[-1][
'cmd'][paramId] +=
',%s' % type
1105 elif element
in (
'color',
1110 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element,
1113 elif element ==
'rdmcolor' and self.
inVector:
1115 self.
layers[-1][
'cmd'].append(
'-c')
1117 elif element ==
'sqlcolor' and self.
inVector:
1119 self.
layers[-1][
'cmd'].append(
'-a')
1121 elif element
in (
'icon',
1132 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element,
1135 elif element ==
'lwidth':
1138 self.
layers[-1][
'cmd'].append(
'width=%s' % value)
1140 elif element ==
'lfield':
1143 self.
layers[-1][
'cmd'].append(
'llayer=%s' % value)
1145 elif element ==
'attribute':
1148 self.
layers[-1][
'cmd'].append(
'attrcol=%s' % value)
1150 elif element ==
'cat':
1153 self.
layers[-1][
'cmd'].append(
'cats=%s' % value)
1156 elif element ==
'gridline':
1158 self.layers.append({
1167 elif element ==
'gridcolor':
1172 elif element ==
'gridborder':
1177 elif element ==
'textcolor':
1182 elif element
in (
'gridsize',
1186 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element[4:], value))
1188 elif element
in 'fontsize':
1191 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element, value))
1193 elif element ==
'griddraw':
1196 self.
layers[-1][
'cmd'].append(
'-n')
1198 elif element ==
'gridgeo':
1201 self.
layers[-1][
'cmd'].append(
'-g')
1203 elif element ==
'borderdraw':
1206 self.
layers[-1][
'cmd'].append(
'-b')
1208 elif element ==
'textdraw':
1211 self.
layers[-1][
'cmd'].append(
'-t')
1214 self.
error += _(
' row %d:') % line_id + line + os.linesep
1217 def _get_value(self, line):
1218 """!Get value of element"""
1220 return line.strip(
' ').
split(
' ')[1].strip(
' ')
1224 def _get_element(self, line):
1225 """!Get element tag"""
1226 return line.strip(
' ').
split(
' ')[0].strip(
' ')
1228 def _get_cmd_param_index(self, cmd, name):
1229 """!Get index of parameter in cmd list
1232 @param name parameter name
1235 @return -1 if not found
1239 if '=' not in param:
1242 if param.split(
'=')[0] == name:
1249 def _color_name_to_rgb(self, value):
1250 """!Convert color name (#) to rgb values"""
1251 col = wx.NamedColour(value)
1252 return str(col.Red()) +
':' + \
1253 str(col.Green()) +
':' + \