2 @package core.workspace
4 @brief Open/save workspace definition file
7 - workspace::ProcessWorkspaceFile
8 - workspace::WriteWorkspaceFile
9 - workspace::ProcessGrcFile
11 (C) 2007-2011 by the GRASS Development Team
13 This program is free software under the GNU General Public License
14 (>=v2). Read the file COPYING that comes with GRASS for details.
16 @author Martin Landa <landa.martin gmail.com>
25 from core.gcmd import EncodeString, GetDefaultEncoding
30 """!A ElementTree handler for the GXW XML file, as defined in
34 self.
root = self.tree.getroot()
65 def __filterValue(self, value):
70 value = value.replace(
'<',
'<')
71 value = value.replace(
'>',
'>')
75 def __getNodeText(self, node, tag, default = ''):
83 def __processFile(self):
84 """!Process workspace file"""
88 node_lm = self.root.find(
'layer_manager')
89 if node_lm
is not None:
90 posAttr = node_lm.get(
'dim',
'')
92 posVal = map(int, posAttr.split(
','))
102 for display
in self.root.findall(
'display'):
106 posAttr = display.get(
'dim',
'')
108 posVal = map(int, posAttr.split(
','))
110 pos = (posVal[0], posVal[1])
111 size = (posVal[2], posVal[3])
119 extentAttr = display.get(
'extent',
'')
122 extent = map(float, extentAttr.split(
','))
127 node_projection = display.find(
'projection')
128 if node_projection
is not None:
129 projection = {
'enabled' :
True,
130 'epsg' : node_projection.get(
'epsg',
''),
133 projection = {
'enabled' :
False }
135 self.displays.append( {
136 "name" : display.get(
'name'),
137 "render" : bool(int(display.get(
'render',
"0"))),
138 "mode" : int(display.get(
'mode', 0)),
139 "showCompExtent" : bool(int(display.get(
'showCompExtent',
"0"))),
143 "alignExtent" : bool(int(display.get(
'alignExtent',
"0"))),
144 "constrainRes" : bool(int(display.get(
'constrainRes',
"0"))),
145 "projection" : projection,
146 "viewMode" : display.get(
'viewMode',
'2d')} )
153 def __processLayers(self, node, inGroup = -1):
154 """!Process layers/groups of selected display
156 @param node display tree node
157 @param inGroup in group -> index of group item otherwise -1
159 for item
in node.getchildren():
160 if item.tag ==
'group':
162 self.layers.append( {
164 "name" : item.get(
'name',
''),
165 "checked" : bool(int(item.get(
'checked',
"0"))),
175 elif item.tag ==
'layer':
177 lname = item.get(
'name',
None)
178 if lname
and '\\n' in lname:
179 lname = lname.replace(
'\\n', os.linesep)
181 self.layers.append( {
182 "type" : item.get(
'type',
None),
184 "checked" : bool(int(item.get(
'checked',
"0"))),
185 "opacity" : float(item.get(
'opacity',
'1.0')),
189 "selected" : selected,
193 def __processLayer(self, layer):
194 """!Process layer item
196 @param layer tree node
203 node_task = layer.find(
'task')
204 cmd.append(node_task.get(
'name',
"unknown"))
207 for p
in node_task.findall(
'flag'):
208 flag = p.get(
'name',
'')
210 cmd.append(
'--' + flag)
212 cmd.append(
'-' + flag)
215 for p
in node_task.findall(
'parameter'):
216 cmd.append(
'%s=%s' % (p.get(
'name',
''),
219 if layer.find(
'selected')
is not None:
227 node_vdigit = layer.find(
'vdigit')
228 if node_vdigit
is not None:
236 node_nviz = layer.find(
'nviz')
237 if node_nviz
is not None:
242 return (cmd, selected, vdigit, nviz)
244 def __processLayerVdigit(self, node_vdigit):
245 """!Process vector digitizer layer settings
247 @param node_vdigit vdigit node
251 for node
in node_vdigit.findall(
'geometryAttribute'):
252 if 'geomAttr' not in vdigit:
253 vdigit[
'geomAttr'] = dict()
254 type = node.get(
'type')
255 vdigit[
'geomAttr'][type] = dict()
256 vdigit[
'geomAttr'][type][
'column'] = node.get(
'column')
258 vdigit[
'geomAttr'][type][
'units'] = node.get(
'units',
'mu')
262 def __processLayerNviz(self, node_nviz):
263 """!Process 3D layer settings
265 @param node_nviz nviz node
269 if node_nviz.find(
'surface')
is not None:
271 for sec
in (
'attribute',
'draw',
'position'):
272 nviz[
'surface'][sec] = {}
273 elif node_nviz.find(
'vlines')
is not None or \
274 node_nviz.find(
'vpoints')
is not None:
276 for sec
in (
'lines',
'points'):
277 nviz[
'vector'][sec] = {}
279 if 'surface' in nviz:
280 node_surface = node_nviz.find(
'surface')
282 for attrb
in node_surface.findall(
'attribute'):
283 tagName = str(attrb.tag)
284 attrbName = attrb.get(
'name',
'')
285 dc = nviz[
'surface'][tagName][attrbName] = {}
286 if attrb.get(
'map',
'0') ==
'0':
292 dc[
'value'] = int(value)
295 dc[
'value'] = float(value)
297 dc[
'value'] = str(value)
300 node_draw = node_surface.find(
'draw')
301 if node_draw
is not None:
302 tagName = str(node_draw.tag)
303 nviz[
'surface'][tagName][
'all'] =
False
304 nviz[
'surface'][tagName][
'mode'] = {}
305 nviz[
'surface'][tagName][
'mode'][
'value'] = -1
306 nviz[
'surface'][tagName][
'mode'][
'desc'] = {}
307 nviz[
'surface'][tagName][
'mode'][
'desc'][
'shading'] = \
308 str(node_draw.get(
'shading',
''))
309 nviz[
'surface'][tagName][
'mode'][
'desc'][
'style'] = \
310 str(node_draw.get(
'style',
''))
311 nviz[
'surface'][tagName][
'mode'][
'desc'][
'mode'] = \
312 str(node_draw.get(
'mode',
''))
315 for node_res
in node_draw.findall(
'resolution'):
316 resType = str(node_res.get(
'type',
''))
317 if 'resolution' not in nviz[
'surface'][
'draw']:
318 nviz[
'surface'][
'draw'][
'resolution'] = {}
320 nviz[
'surface'][
'draw'][
'resolution'][resType] = value
323 node_wire_color = node_draw.find(
'wire_color')
324 if node_wire_color
is not None:
325 nviz[
'surface'][
'draw'][
'wire-color'] = {}
327 nviz[
'surface'][
'draw'][
'wire-color'][
'value'] = value
330 node_pos = node_surface.find(
'position')
331 if node_pos
is not None:
332 dc = nviz[
'surface'][
'position'] = {}
333 for coor
in [
'x',
'y',
'z']:
334 node = node_pos.find(coor)
340 elif 'vector' in nviz:
342 node_vpoints = node_nviz.find(
'vpoints')
343 if node_vpoints
is not None:
344 marker = str(node_vpoints.get(
'marker',
''))
345 markerId = list(UserSettings.Get(group=
'nviz', key=
'vector',
346 subkey=[
'points',
'marker'], internal=
True)).index(marker)
347 nviz[
'vector'][
'points'][
'marker'] = {
'value' : markerId }
349 node_mode = node_vpoints.find(
'mode')
350 if node_mode
is not None:
351 nviz[
'vector'][
'points'][
'mode'] = {}
352 nviz[
'vector'][
'points'][
'mode'][
'type'] = str(node_mode.get(
'type',
'surface'))
353 nviz[
'vector'][
'points'][
'mode'][
'surface'] = {}
354 nviz[
'vector'][
'points'][
'mode'][
'surface'][
'value'] = []
355 nviz[
'vector'][
'points'][
'mode'][
'surface'][
'show'] = []
358 for node_map
in node_mode.findall(
'map'):
359 nviz[
'vector'][
'points'][
'mode'][
'surface'][
'value'].append(
361 nviz[
'vector'][
'points'][
'mode'][
'surface'][
'show'].append(bool(
366 nviz[
'vector'][
'points'])
370 nviz[
'vector'][
'points'])
374 nviz[
'vector'][
'points'])
378 nviz[
'vector'][
'points'])
381 node_vlines = node_nviz.find(
'vlines')
382 if node_vlines
is not None:
383 node_mode = node_vlines.find(
'mode')
384 if node_mode
is not None:
385 nviz[
'vector'][
'lines'][
'mode'] = {}
386 nviz[
'vector'][
'lines'][
'mode'][
'type'] = str(node_mode.get(
'type',
''))
387 nviz[
'vector'][
'lines'][
'mode'][
'surface'] = {}
388 nviz[
'vector'][
'lines'][
'mode'][
'surface'][
'value'] = []
389 nviz[
'vector'][
'lines'][
'mode'][
'surface'][
'show'] = []
392 for node_map
in node_mode.findall(
'map'):
393 nviz[
'vector'][
'lines'][
'mode'][
'surface'][
'value'].append(
395 nviz[
'vector'][
'lines'][
'mode'][
'surface'][
'show'].append(bool(
400 nviz[
'vector'][
'lines'])
404 nviz[
'vector'][
'lines'])
408 nviz[
'vector'][
'lines'])
412 def __processLayerNvizNode(self, node, tag, cast, dc = None):
413 """!Process given tag nviz/vector"""
414 node_tag = node.find(tag)
415 if node_tag
is not None:
416 if node_tag.find(
'value')
is not None:
420 value = cast(node_tag.text)
428 dc[tag][
'value'] = value
432 def __processNvizState(self, node):
433 """!Process tag nviz_state"""
434 node_state = node.find(
'nviz_state')
435 if node_state
is None:
441 node_view = node_state.find(
'view')
445 node_position = node_view.find(
'v_position')
446 view[
'position'] = {}
449 node_persp = node_view.find(
'persp')
456 node_height = node_view.find(
'v_height')
461 node_twist = node_view.find(
'twist')
467 node_zexag = node_view.find(
'z-exag')
474 node_focus = node_view.find(
'focus')
479 node_dir = node_view.find(
'dir')
485 iview[
'dir'][
'use'] =
True
488 iview[
'dir'][
'x'] = -1
489 iview[
'dir'][
'y'] = -1
490 iview[
'dir'][
'z'] = -1
491 iview[
'dir'][
'use'] =
False
493 view[
'background'] = {}
495 view[
'background'][
'color'] = tuple(map(int, color.split(
':')))
502 node_light = node_state.find(
'light')
505 node_position = node_light.find(
'l_position')
506 light[
'position'] = {}
514 light[
'color'] = tuple(map(int, color.split(
':')))
518 node_constants = node_state.find(
'constant_planes')
521 for i, node_plane
in enumerate(node_constants.findall(
'plane')):
527 constants.append({
'constant': plane})
531 """!Generic class for writing workspace file"""
539 self.file.write(
'<?xml version="1.0" encoding="%s"?>\n' %
GetDefaultEncoding(forceUTF8 =
True))
540 self.file.write(
'<!DOCTYPE gxw SYSTEM "grass-gxw.dtd">\n')
541 self.file.write(
'%s<gxw>\n' % (
' ' * self.
indent))
546 windowPos = self.lmgr.GetPosition()
547 windowSize = self.lmgr.GetSize()
548 file.write(
'%s<layer_manager dim="%d,%d,%d,%d">\n' % (
' ' * self.
indent,
555 file.write(
'%s</layer_manager>\n' % (
' ' * self.
indent))
558 for page
in range(0, self.lmgr.GetLayerNotebook().GetPageCount()):
559 dispName = self.lmgr.GetLayerNotebook().GetPageText(page)
560 mapTree = self.lmgr.GetLayerNotebook().GetPage(page).maptree
561 region = mapTree.GetMap().GetCurrentRegion()
562 mapdisp = mapTree.GetMapDisplay()
564 displayPos = mapTree.mapdisplay.GetPosition()
565 displaySize = mapTree.mapdisplay.GetSize()
566 if mapTree.mapdisplay.toolbars[
'map'].combo.GetSelection() == 1:
571 file.write(
'%s<display '
572 'name="%s" render="%d" '
573 'mode="%d" showCompExtent="%d" '
577 'extent="%f,%f,%f,%f" '
578 'viewMode="%s" >\n' % (
' ' * self.
indent,
579 dispName.encode(
'utf8'),
580 int(mapTree.mapdisplay.GetProperty(
'render')),
581 mapTree.mapdisplay.statusbarManager.GetMode(),
582 int(mapTree.mapdisplay.GetProperty(
'region')),
583 int(mapTree.mapdisplay.GetProperty(
'alignExtent')),
584 int(mapTree.mapdisplay.GetProperty(
'resolution')),
596 if mapTree.mapdisplay.GetProperty(
'projection')
and \
597 UserSettings.Get(group=
'display', key=
'projection', subkey=
'proj4'):
599 file.write(
'%s<projection' % (
' ' * self.
indent))
600 epsg = UserSettings.Get(group=
'display', key=
'projection', subkey=
'epsg')
602 file.write(
' epsg="%s"' % epsg)
604 proj = UserSettings.Get(group=
'display', key=
'projection', subkey=
'proj4')
606 file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, proj))
608 file.write(
'%s</projection>\n' % (
' ' * self.
indent))
612 item = mapTree.GetFirstChild(mapTree.root)[0]
615 if mapTree.mapdisplay.MapWindow3D
is not None:
616 nvizDisp = mapTree.mapdisplay.MapWindow3D
618 light = nvizDisp.light, constants = nvizDisp.constants)
620 file.write(
'%s</display>\n' % (
' ' * self.
indent))
623 file.write(
'%s</gxw>\n' % (
' ' * self.
indent))
625 def __filterValue(self, value):
626 """!Make value XML-valid"""
627 value = value.replace(
'<',
'<')
628 value = value.replace(
'>',
'>')
632 def __writeLayer(self, mapTree, item):
633 """!Write bunch of layers to GRASS Workspace XML file"""
635 itemSelected = mapTree.GetSelections()
636 while item
and item.IsOk():
637 type = mapTree.GetPyData(item)[0][
'type']
639 maplayer = mapTree.GetPyData(item)[0][
'maplayer']
643 checked = int(item.IsChecked())
644 if type ==
'command':
645 cmd = mapTree.GetPyData(item)[0][
'maplayer'].GetCmd(string=
True)
646 self.file.write(
'%s<layer type="%s" name="%s" checked="%d">\n' % \
648 self.file.write(
'%s</layer>\n' % (
' ' * self.
indent));
649 elif type ==
'group':
650 name = mapTree.GetItemText(item)
651 self.file.write(
'%s<group name="%s" checked="%d">\n' % \
654 subItem = mapTree.GetFirstChild(item)[0]
657 self.file.write(
'%s</group>\n' % (
' ' * self.
indent));
659 cmd = mapTree.GetPyData(item)[0][
'maplayer'].GetCmd(string =
False)
660 name = mapTree.GetItemText(item).replace(os.linesep,
'\\n')
661 opacity = maplayer.GetOpacity(float =
True)
664 name = name.split(
'(', -1)[0].strip()
665 self.file.write(
'%s<layer type="%s" name="%s" checked="%d" opacity="%f">\n' % \
670 if item
in itemSelected:
671 self.file.write(
'%s<selected />\n' % (
' ' * self.
indent))
673 self.file.write(
'%s<task name="%s">\n' % (
' ' * self.
indent, cmd[0]))
675 for key, val
in cmd[1].iteritems():
678 self.file.write(
'%s<flag name="%s" />\n' %
680 elif val
in (
True,
False):
681 self.file.write(
'%s<flag name="%s" />\n' %
684 self.file.write(
'%s<parameter name="%s">\n' %
687 self.file.write(
'%s<value>%s</value>\n' %
690 self.file.write(
'%s</parameter>\n' % (
' ' * self.
indent));
692 self.file.write(
'%s</task>\n' % (
' ' * self.
indent));
694 vdigit = mapTree.GetPyData(item)[0][
'vdigit']
696 self.file.write(
'%s<vdigit>\n' % (
' ' * self.
indent))
697 if 'geomAttr' in vdigit:
699 for type, val
in vdigit[
'geomAttr'].iteritems():
701 if val[
'units'] !=
'mu':
702 units =
' units="%s"' % val[
'units']
703 self.file.write(
'%s<geometryAttribute type="%s" column="%s"%s />\n' % \
704 (
' ' * self.
indent, type, val[
'column'], units))
706 self.file.write(
'%s</vdigit>\n' % (
' ' * self.
indent))
708 nviz = mapTree.GetPyData(item)[0][
'nviz']
710 self.file.write(
'%s<nviz>\n' % (
' ' * self.
indent))
711 if maplayer.type ==
'raster':
713 elif maplayer.type ==
'vector':
715 self.file.write(
'%s</nviz>\n' % (
' ' * self.
indent))
717 self.file.write(
'%s</layer>\n' % (
' ' * self.
indent))
718 item = mapTree.GetNextSibling(item)
721 def __writeNvizSurface(self, data):
722 """!Save Nviz raster layer properties to workspace
724 @param data Nviz layer properties
726 if 'object' not in data:
729 self.file.write(
'%s<surface>\n' % (
' ' * self.
indent))
731 for attrb
in data.iterkeys():
732 if len(data[attrb]) < 1:
734 if attrb ==
'object':
737 for name
in data[attrb].iterkeys():
739 if attrb ==
'attribute':
740 if data[attrb][name][
'map']
is None:
742 self.file.write(
'%s<%s name="%s" map="%d">\n' % \
743 (
' ' * self.
indent, attrb, name, data[attrb][name][
'map']))
745 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, data[attrb][name][
'value']))
748 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, attrb))
752 self.file.write(
'%s<%s' %(
' ' * self.
indent, attrb))
753 if 'mode' in data[attrb]:
754 for tag, value
in data[attrb][
'mode'][
'desc'].iteritems():
755 self.file.write(
' %s="%s"' % (tag, value))
756 self.file.write(
'>\n')
758 if 'resolution' in data[attrb]:
760 for type
in (
'coarse',
'fine'):
761 self.file.write(
'%s<resolution type="%s">\n' % (
' ' * self.
indent, type))
763 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent,
764 data[attrb][
'resolution'][type]))
766 self.file.write(
'%s</resolution>\n' % (
' ' * self.
indent))
768 if 'wire-color' in data[attrb]:
769 self.file.write(
'%s<wire_color>\n' % (
' ' * self.
indent))
771 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent,
772 data[attrb][
'wire-color'][
'value']))
774 self.file.write(
'%s</wire_color>\n' % (
' ' * self.
indent))
778 elif attrb ==
'position':
779 self.file.write(
'%s<%s>\n' %(
' ' * self.
indent, attrb))
781 for tag
in (
'x',
'y',
'z'):
783 self.file.write(
'%s<%s>%d</%s>\n' % (
' ' * self.
indent, tag,
784 data[attrb][tag], tag))
788 if attrb !=
'attribute':
790 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, attrb))
793 self.file.write(
'%s</surface>\n' % (
' ' * self.
indent))
796 def __writeNvizVector(self, data):
797 """!Save Nviz vector layer properties (lines/points) to workspace
799 @param data Nviz layer properties
802 for attrb
in data.iterkeys():
803 if len(data[attrb]) < 1:
806 if 'object' not in data[attrb]:
809 self.file.write(
'%s<v%s>\n' % (
' ' * self.
indent, attrb))
810 elif attrb ==
'points':
811 markerId = data[attrb][
'marker'][
'value']
812 marker = UserSettings.Get(group =
'nviz', key =
'vector',
813 subkey = [
'points',
'marker'], internal =
True)[markerId]
814 self.file.write(
'%s<v%s marker="%s">\n' % (
' ' * self.
indent,
818 for name
in data[attrb].iterkeys():
819 if name
in (
'object',
'marker'):
822 self.file.write(
'%s<%s type="%s">\n' % (
' ' * self.
indent, name,
823 data[attrb][name][
'type']))
824 if data[attrb][name][
'type'] ==
'surface':
826 for idx, surface
in enumerate(data[attrb][name][
'surface'][
'value']):
827 checked = data[attrb][name][
'surface'][
'show'][idx]
828 self.file.write(
'%s<map>\n' % (
' ' * self.
indent))
830 self.file.write(
'%s<name>%s</name>\n' % (
' ' * self.
indent, surface))
831 self.file.write(
'%s<checked>%s</checked>\n' % (
' ' * self.
indent, int(checked)))
833 self.file.write(
'%s</map>\n' % (
' ' * self.
indent))
835 self.file.write(
'%s</%s>\n' % ((
' ' * self.
indent, name)))
837 self.file.write(
'%s<%s>\n' % (
' ' * self.
indent, name))
839 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, data[attrb][name][
'value']))
841 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, name))
843 self.file.write(
'%s</v%s>\n' % (
' ' * self.
indent, attrb))
847 def __writeNvizState(self, view, iview, light, constants):
848 """"!Save Nviz properties (view, light) to workspace
850 @param view Nviz view properties
851 @param iview Nviz internal view properties
852 @param light Nviz light properties
855 self.file.write(
'%s<nviz_state>\n' % (
' ' * self.
indent))
860 self.file.write(
'%s<view>\n' % (
' ' * self.
indent))
863 self.file.write(
'%s<v_position>\n' % (
' ' * self.
indent))
865 self.file.write(
'%s<x>%.2f</x>\n' % (
' ' * self.
indent, view[
'position'][
'x']))
866 self.file.write(
'%s<y>%.2f</y>\n' % (
' ' * self.
indent, view[
'position'][
'y']))
868 self.file.write(
'%s</v_position>\n' % (
' ' * self.
indent))
870 self.file.write(
'%s<persp>\n' % (
' ' * self.
indent))
872 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent, view[
'persp'][
'value']))
873 self.file.write(
'%s<step>%d</step>\n' % (
' ' * self.
indent, view[
'persp'][
'step']))
874 self.file.write(
'%s<min>%d</min>\n' % (
' ' * self.
indent, iview[
'persp'][
'min']))
875 self.file.write(
'%s<max>%d</max>\n' % (
' ' * self.
indent, iview[
'persp'][
'max']))
877 self.file.write(
'%s</persp>\n' % (
' ' * self.
indent))
879 self.file.write(
'%s<v_height>\n' % (
' ' * self.
indent))
881 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent, iview[
'height'][
'value']))
882 self.file.write(
'%s<min>%d</min>\n' % (
' ' * self.
indent, iview[
'height'][
'min']))
883 self.file.write(
'%s<max>%d</max>\n' % (
' ' * self.
indent, iview[
'height'][
'max']))
885 self.file.write(
'%s</v_height>\n' % (
' ' * self.
indent))
887 self.file.write(
'%s<twist>\n' % (
' ' * self.
indent))
889 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent, view[
'twist'][
'value']))
890 self.file.write(
'%s<min>%d</min>\n' % (
' ' * self.
indent, iview[
'twist'][
'min']))
891 self.file.write(
'%s<max>%d</max>\n' % (
' ' * self.
indent, iview[
'twist'][
'max']))
893 self.file.write(
'%s</twist>\n' % (
' ' * self.
indent))
895 self.file.write(
'%s<z-exag>\n' % (
' ' * self.
indent))
897 self.file.write(
'%s<value>%.2f</value>\n' % (
' ' * self.
indent, view[
'z-exag'][
'value']))
898 self.file.write(
'%s<min>%d</min>\n' % (
' ' * self.
indent, view[
'z-exag'][
'min']))
899 self.file.write(
'%s<max>%d</max>\n' % (
' ' * self.
indent, view[
'z-exag'][
'max']))
900 self.file.write(
'%s<llRatio>%.2f</llRatio>\n' % (
' ' * self.
indent, iview[
'z-exag'][
'llRatio']))
902 self.file.write(
'%s</z-exag>\n' % (
' ' * self.
indent))
904 self.file.write(
'%s<focus>\n' % (
' ' * self.
indent))
906 self.file.write(
'%s<x>%d</x>\n' % (
' ' * self.
indent, iview[
'focus'][
'x']))
907 self.file.write(
'%s<y>%d</y>\n' % (
' ' * self.
indent, iview[
'focus'][
'y']))
908 self.file.write(
'%s<z>%d</z>\n' % (
' ' * self.
indent, iview[
'focus'][
'z']))
910 self.file.write(
'%s</focus>\n' % (
' ' * self.
indent))
912 self.
__writeTagWithValue(
'background_color', view[
'background'][
'color'][:3], format =
'd:%d:%d')
915 self.file.write(
'%s</view>\n' % (
' ' * self.
indent))
919 self.file.write(
'%s<light>\n' % (
' ' * self.
indent))
922 self.file.write(
'%s<l_position>\n' % (
' ' * self.
indent))
924 self.file.write(
'%s<x>%.2f</x>\n' % (
' ' * self.
indent, light[
'position'][
'x']))
925 self.file.write(
'%s<y>%.2f</y>\n' % (
' ' * self.
indent, light[
'position'][
'y']))
926 self.file.write(
'%s<z>%d</z>\n' % (
' ' * self.
indent, light[
'position'][
'z']))
928 self.file.write(
'%s</l_position>\n' % (
' ' * self.
indent))
937 self.file.write(
'%s</light>\n' % (
' ' * self.
indent))
942 self.file.write(
'%s<constant_planes>\n' % (
' ' * self.
indent))
944 for idx, plane
in enumerate(constants):
945 self.file.write(
'%s<plane>\n' % (
' ' * self.
indent))
951 self.file.write(
'%s</plane>\n' % (
' ' * self.
indent))
953 self.file.write(
'%s</constant_planes>\n' % (
' ' * self.
indent))
956 self.file.write(
'%s</nviz_state>\n' % (
' ' * self.
indent))
959 def __writeTagWithValue(self, tag, data, format = 'd'):
960 """!Helper function for writing pair tag
962 @param tag written tag
963 @param data written data
964 @param format conversion type
966 self.file.write(
'%s<%s>\n' % (
' ' * self.
indent, tag))
968 self.file.write(
'%s' % (
' ' * self.
indent))
969 self.file.write((
'<value>%' + format +
'</value>\n') % data)
971 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, tag))
975 """!Process GRC file"""
993 @param parent parent window
995 @return list of map layers
1000 wx.MessageBox(parent=parent,
1001 message=_(
"Unable to open file <%s> for reading.") % self.
filename,
1002 caption=_(
"Error"), style=wx.OK | wx.ICON_ERROR)
1006 for line
in file.readlines():
1013 wx.MessageBox(parent=parent,
1014 message=_(
"Some lines were skipped when reading settings "
1015 "from file <%(file)s>.\nSee 'Command output' window for details.\n\n"
1016 "Number of skipped lines: %(line)d") % \
1018 caption=_(
"Warning"), style=wx.OK | wx.ICON_EXCLAMATION)
1019 parent.goutput.WriteLog(
'Map layers loaded from GRC file <%s>' % self.
filename)
1020 parent.goutput.WriteLog(
'Skipped lines:\n%s' % self.
error)
1025 """!Process line definition"""
1027 if element ==
'Group':
1029 self.layers.append({
1039 elif element ==
'_check':
1041 self.
layers[-1][
'checked'] =
True
1043 self.
layers[-1][
'checked'] =
False
1045 elif element ==
'End':
1055 elif element ==
'opacity':
1059 elif element ==
'Raster':
1061 self.layers.append({
1070 elif element ==
'map' and self.
inRaster:
1073 elif element ==
'overlay' and self.
inRaster:
1075 self.
layers[-1][
'cmd'].append(
'-o')
1077 elif element ==
'rastquery' and self.
inRaster:
1080 self.
layers[-1][
'cmd'].append(
'catlist=%s' % value)
1082 elif element ==
'bkcolor' and self.
inRaster:
1085 self.
layers[-1][
'cmd'].append(
'bg=%s' % value)
1088 elif element ==
'Vector':
1090 self.layers.append({
1099 elif element ==
'vect' and self.
inVector:
1102 elif element
in (
'display_shape',
1115 name = element.split(
'_')[0]
1116 type = element.split(
'_')[1]
1119 self.
layers[-1][
'cmd'].append(
'%s=%s' % (name, type))
1121 self.
layers[-1][
'cmd'][paramId] +=
',%s' % type
1123 elif element
in (
'color',
1128 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element,
1131 elif element ==
'rdmcolor' and self.
inVector:
1133 self.
layers[-1][
'cmd'].append(
'-c')
1135 elif element ==
'sqlcolor' and self.
inVector:
1137 self.
layers[-1][
'cmd'].append(
'-a')
1139 elif element
in (
'icon',
1150 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element,
1153 elif element ==
'lwidth':
1156 self.
layers[-1][
'cmd'].append(
'width=%s' % value)
1158 elif element ==
'lfield':
1161 self.
layers[-1][
'cmd'].append(
'llayer=%s' % value)
1163 elif element ==
'attribute':
1166 self.
layers[-1][
'cmd'].append(
'attrcol=%s' % value)
1168 elif element ==
'cat':
1171 self.
layers[-1][
'cmd'].append(
'cats=%s' % value)
1174 elif element ==
'gridline':
1176 self.layers.append({
1185 elif element ==
'gridcolor':
1190 elif element ==
'gridborder':
1195 elif element ==
'textcolor':
1200 elif element
in (
'gridsize',
1204 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element[4:], value))
1206 elif element
in 'fontsize':
1209 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element, value))
1211 elif element ==
'griddraw':
1214 self.
layers[-1][
'cmd'].append(
'-n')
1216 elif element ==
'gridgeo':
1219 self.
layers[-1][
'cmd'].append(
'-g')
1221 elif element ==
'borderdraw':
1224 self.
layers[-1][
'cmd'].append(
'-b')
1226 elif element ==
'textdraw':
1229 self.
layers[-1][
'cmd'].append(
'-t')
1232 self.
error += _(
' row %d:') % line_id + line + os.linesep
1235 def _get_value(self, line):
1236 """!Get value of element"""
1238 return line.strip(
' ').
split(
' ')[1].strip(
' ')
1242 def _get_element(self, line):
1243 """!Get element tag"""
1244 return line.strip(
' ').
split(
' ')[0].strip(
' ')
1246 def _get_cmd_param_index(self, cmd, name):
1247 """!Get index of parameter in cmd list
1250 @param name parameter name
1253 @return -1 if not found
1257 if '=' not in param:
1260 if param.split(
'=')[0] == name:
1267 def _color_name_to_rgb(self, value):
1268 """!Convert color name (#) to rgb values"""
1269 col = wx.NamedColour(value)
1270 return str(col.Red()) +
':' + \
1271 str(col.Green()) +
':' + \
def normalize_whitespace
Remove redundant whitespace from a string.
def EncodeString
Return encoded string using system locales.
def __processLayerNvizNode
Process given tag nviz/vector.
def __processFile
Process workspace file.
def __writeTagWithValue
Helper function for writing pair tag.
def __init__
Process GRC file.
def __filterValue
Filter value.
def __processLayer
Process layer item.
def __processLayerNviz
Process 3D layer settings.
def split
Platform spefic shlex.split.
def __writeNvizSurface
Save Nviz raster layer properties to workspace.
def __init__
A ElementTree handler for the GXW XML file, as defined in grass-gxw.dtd.
def _get_element
Get element tag.
def __processNvizState
Process tag nviz_state.
def GetDefaultEncoding
Get default system encoding.
def __writeLayer
Write bunch of layers to GRASS Workspace XML file.
Misc utilities for wxGUI.
def process_line
Process line definition.
def _get_cmd_param_index
Get index of parameter in cmd list.
def _get_value
Get value of element.
def __filterValue
Make value XML-valid.
def __processLayers
Process layers/groups of selected display.
def __writeNvizVector
Save Nviz vector layer properties (lines/points) to workspace.
Generic class for writing workspace file.
def __getNodeText
Get node text.
def __processLayerVdigit
Process vector digitizer layer settings.
def _color_name_to_rgb
Convert color name (#) to rgb values.