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.gm_cb.GetPageCount()):
559 dispName = self.lmgr.gm_cb.GetPageText(page)
560 mapTree = self.lmgr.gm_cb.GetPage(page).maptree
561 region = mapTree.Map.region
563 displayPos = mapTree.mapdisplay.GetPosition()
564 displaySize = mapTree.mapdisplay.GetSize()
565 if mapTree.mapdisplay.toolbars[
'map'].combo.GetSelection() == 1:
570 file.write(
'%s<display '
571 'name="%s" render="%d" '
572 'mode="%d" showCompExtent="%d" '
576 'extent="%f,%f,%f,%f" '
577 'viewMode="%s" >\n' % (
' ' * self.
indent,
578 dispName.encode(
'utf8'),
579 int(mapTree.mapdisplay.GetProperty(
'render')),
580 mapTree.mapdisplay.statusbarManager.GetMode(),
581 int(mapTree.mapdisplay.GetProperty(
'region')),
582 int(mapTree.mapdisplay.GetProperty(
'alignExtent')),
583 int(mapTree.mapdisplay.GetProperty(
'resolution')),
595 if mapTree.mapdisplay.GetProperty(
'projection')
and \
596 UserSettings.Get(group=
'display', key=
'projection', subkey=
'proj4'):
598 file.write(
'%s<projection' % (
' ' * self.
indent))
599 epsg = UserSettings.Get(group=
'display', key=
'projection', subkey=
'epsg')
601 file.write(
' epsg="%s"' % epsg)
603 proj = UserSettings.Get(group=
'display', key=
'projection', subkey=
'proj4')
605 file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, proj))
607 file.write(
'%s</projection>\n' % (
' ' * self.
indent))
611 item = mapTree.GetFirstChild(mapTree.root)[0]
614 if mapTree.mapdisplay.MapWindow3D
is not None:
615 nvizDisp = mapTree.mapdisplay.MapWindow3D
617 light = nvizDisp.light, constants = nvizDisp.constants)
619 file.write(
'%s</display>\n' % (
' ' * self.
indent))
622 file.write(
'%s</gxw>\n' % (
' ' * self.
indent))
624 def __filterValue(self, value):
625 """!Make value XML-valid"""
626 value = value.replace(
'<',
'<')
627 value = value.replace(
'>',
'>')
631 def __writeLayer(self, mapTree, item):
632 """!Write bunch of layers to GRASS Workspace XML file"""
634 itemSelected = mapTree.GetSelections()
635 while item
and item.IsOk():
636 type = mapTree.GetPyData(item)[0][
'type']
638 maplayer = mapTree.GetPyData(item)[0][
'maplayer']
642 checked =
int(item.IsChecked())
643 if type ==
'command':
644 cmd = mapTree.GetPyData(item)[0][
'maplayer'].GetCmd(string=
True)
645 self.file.write(
'%s<layer type="%s" name="%s" checked="%d">\n' % \
647 self.file.write(
'%s</layer>\n' % (
' ' * self.
indent));
648 elif type ==
'group':
649 name = mapTree.GetItemText(item)
650 self.file.write(
'%s<group name="%s" checked="%d">\n' % \
653 subItem = mapTree.GetFirstChild(item)[0]
656 self.file.write(
'%s</group>\n' % (
' ' * self.
indent));
658 cmd = mapTree.GetPyData(item)[0][
'maplayer'].GetCmd(string =
False)
659 name = mapTree.GetItemText(item).replace(os.linesep,
'\\n')
660 opacity = maplayer.GetOpacity(float =
True)
663 name = name.split(
'(', -1)[0].strip()
664 self.file.write(
'%s<layer type="%s" name="%s" checked="%d" opacity="%f">\n' % \
669 if item
in itemSelected:
670 self.file.write(
'%s<selected />\n' % (
' ' * self.
indent))
672 self.file.write(
'%s<task name="%s">\n' % (
' ' * self.
indent, cmd[0]))
674 for key, val
in cmd[1].iteritems():
677 self.file.write(
'%s<flag name="%s" />\n' %
679 elif val
in (
True,
False):
680 self.file.write(
'%s<flag name="%s" />\n' %
683 self.file.write(
'%s<parameter name="%s">\n' %
686 self.file.write(
'%s<value>%s</value>\n' %
689 self.file.write(
'%s</parameter>\n' % (
' ' * self.
indent));
691 self.file.write(
'%s</task>\n' % (
' ' * self.
indent));
693 vdigit = mapTree.GetPyData(item)[0][
'vdigit']
695 self.file.write(
'%s<vdigit>\n' % (
' ' * self.
indent))
696 if 'geomAttr' in vdigit:
698 for type, val
in vdigit[
'geomAttr'].iteritems():
700 if val[
'units'] !=
'mu':
701 units =
' units="%s"' % val[
'units']
702 self.file.write(
'%s<geometryAttribute type="%s" column="%s"%s />\n' % \
703 (
' ' * self.
indent, type, val[
'column'], units))
705 self.file.write(
'%s</vdigit>\n' % (
' ' * self.
indent))
707 nviz = mapTree.GetPyData(item)[0][
'nviz']
709 self.file.write(
'%s<nviz>\n' % (
' ' * self.
indent))
710 if maplayer.type ==
'raster':
712 elif maplayer.type ==
'vector':
714 self.file.write(
'%s</nviz>\n' % (
' ' * self.
indent))
716 self.file.write(
'%s</layer>\n' % (
' ' * self.
indent))
717 item = mapTree.GetNextSibling(item)
720 def __writeNvizSurface(self, data):
721 """!Save Nviz raster layer properties to workspace
723 @param data Nviz layer properties
725 if 'object' not in data:
728 self.file.write(
'%s<surface>\n' % (
' ' * self.
indent))
730 for attrb
in data.iterkeys():
731 if len(data[attrb]) < 1:
733 if attrb ==
'object':
736 for name
in data[attrb].iterkeys():
738 if attrb ==
'attribute':
739 if data[attrb][name][
'map']
is None:
741 self.file.write(
'%s<%s name="%s" map="%d">\n' % \
742 (
' ' * self.
indent, attrb, name, data[attrb][name][
'map']))
744 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, data[attrb][name][
'value']))
747 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, attrb))
751 self.file.write(
'%s<%s' %(
' ' * self.
indent, attrb))
752 if 'mode' in data[attrb]:
753 for tag, value
in data[attrb][
'mode'][
'desc'].iteritems():
754 self.file.write(
' %s="%s"' % (tag, value))
755 self.file.write(
'>\n')
757 if 'resolution' in data[attrb]:
759 for type
in (
'coarse',
'fine'):
760 self.file.write(
'%s<resolution type="%s">\n' % (
' ' * self.
indent, type))
762 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent,
763 data[attrb][
'resolution'][type]))
765 self.file.write(
'%s</resolution>\n' % (
' ' * self.
indent))
767 if 'wire-color' in data[attrb]:
768 self.file.write(
'%s<wire_color>\n' % (
' ' * self.
indent))
770 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent,
771 data[attrb][
'wire-color'][
'value']))
773 self.file.write(
'%s</wire_color>\n' % (
' ' * self.
indent))
777 elif attrb ==
'position':
778 self.file.write(
'%s<%s>\n' %(
' ' * self.
indent, attrb))
780 for tag
in (
'x',
'y',
'z'):
782 self.file.write(
'%s<%s>%d</%s>\n' % (
' ' * self.
indent, tag,
783 data[attrb][tag], tag))
787 if attrb !=
'attribute':
789 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, attrb))
792 self.file.write(
'%s</surface>\n' % (
' ' * self.
indent))
795 def __writeNvizVector(self, data):
796 """!Save Nviz vector layer properties (lines/points) to workspace
798 @param data Nviz layer properties
801 for attrb
in data.iterkeys():
802 if len(data[attrb]) < 1:
805 if 'object' not in data[attrb]:
808 self.file.write(
'%s<v%s>\n' % (
' ' * self.
indent, attrb))
809 elif attrb ==
'points':
810 markerId = data[attrb][
'marker'][
'value']
811 marker = UserSettings.Get(group =
'nviz', key =
'vector',
812 subkey = [
'points',
'marker'], internal =
True)[markerId]
813 self.file.write(
'%s<v%s marker="%s">\n' % (
' ' * self.
indent,
817 for name
in data[attrb].iterkeys():
818 if name
in (
'object',
'marker'):
821 self.file.write(
'%s<%s type="%s">\n' % (
' ' * self.
indent, name,
822 data[attrb][name][
'type']))
823 if data[attrb][name][
'type'] ==
'surface':
825 for idx, surface
in enumerate(data[attrb][name][
'surface'][
'value']):
826 checked = data[attrb][name][
'surface'][
'show'][idx]
827 self.file.write(
'%s<map>\n' % (
' ' * self.
indent))
829 self.file.write(
'%s<name>%s</name>\n' % (
' ' * self.
indent, surface))
830 self.file.write(
'%s<checked>%s</checked>\n' % (
' ' * self.
indent,
int(checked)))
832 self.file.write(
'%s</map>\n' % (
' ' * self.
indent))
834 self.file.write(
'%s</%s>\n' % ((
' ' * self.
indent, name)))
836 self.file.write(
'%s<%s>\n' % (
' ' * self.
indent, name))
838 self.file.write(
'%s<value>%s</value>\n' % (
' ' * self.
indent, data[attrb][name][
'value']))
840 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, name))
842 self.file.write(
'%s</v%s>\n' % (
' ' * self.
indent, attrb))
846 def __writeNvizState(self, view, iview, light, constants):
847 """"!Save Nviz properties (view, light) to workspace
849 @param view Nviz view properties
850 @param iview Nviz internal view properties
851 @param light Nviz light properties
854 self.file.write(
'%s<nviz_state>\n' % (
' ' * self.
indent))
859 self.file.write(
'%s<view>\n' % (
' ' * self.
indent))
862 self.file.write(
'%s<v_position>\n' % (
' ' * self.
indent))
864 self.file.write(
'%s<x>%.2f</x>\n' % (
' ' * self.
indent, view[
'position'][
'x']))
865 self.file.write(
'%s<y>%.2f</y>\n' % (
' ' * self.
indent, view[
'position'][
'y']))
867 self.file.write(
'%s</v_position>\n' % (
' ' * self.
indent))
869 self.file.write(
'%s<persp>\n' % (
' ' * self.
indent))
871 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent, view[
'persp'][
'value']))
872 self.file.write(
'%s<step>%d</step>\n' % (
' ' * self.
indent, view[
'persp'][
'step']))
873 self.file.write(
'%s<min>%d</min>\n' % (
' ' * self.
indent, iview[
'persp'][
'min']))
874 self.file.write(
'%s<max>%d</max>\n' % (
' ' * self.
indent, iview[
'persp'][
'max']))
876 self.file.write(
'%s</persp>\n' % (
' ' * self.
indent))
878 self.file.write(
'%s<v_height>\n' % (
' ' * self.
indent))
880 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent, iview[
'height'][
'value']))
881 self.file.write(
'%s<min>%d</min>\n' % (
' ' * self.
indent, iview[
'height'][
'min']))
882 self.file.write(
'%s<max>%d</max>\n' % (
' ' * self.
indent, iview[
'height'][
'max']))
884 self.file.write(
'%s</v_height>\n' % (
' ' * self.
indent))
886 self.file.write(
'%s<twist>\n' % (
' ' * self.
indent))
888 self.file.write(
'%s<value>%d</value>\n' % (
' ' * self.
indent, view[
'twist'][
'value']))
889 self.file.write(
'%s<min>%d</min>\n' % (
' ' * self.
indent, iview[
'twist'][
'min']))
890 self.file.write(
'%s<max>%d</max>\n' % (
' ' * self.
indent, iview[
'twist'][
'max']))
892 self.file.write(
'%s</twist>\n' % (
' ' * self.
indent))
894 self.file.write(
'%s<z-exag>\n' % (
' ' * self.
indent))
896 self.file.write(
'%s<value>%.2f</value>\n' % (
' ' * self.
indent, view[
'z-exag'][
'value']))
897 self.file.write(
'%s<min>%d</min>\n' % (
' ' * self.
indent, view[
'z-exag'][
'min']))
898 self.file.write(
'%s<max>%d</max>\n' % (
' ' * self.
indent, view[
'z-exag'][
'max']))
899 self.file.write(
'%s<llRatio>%.2f</llRatio>\n' % (
' ' * self.
indent, iview[
'z-exag'][
'llRatio']))
901 self.file.write(
'%s</z-exag>\n' % (
' ' * self.
indent))
903 self.file.write(
'%s<focus>\n' % (
' ' * self.
indent))
905 self.file.write(
'%s<x>%d</x>\n' % (
' ' * self.
indent, iview[
'focus'][
'x']))
906 self.file.write(
'%s<y>%d</y>\n' % (
' ' * self.
indent, iview[
'focus'][
'y']))
907 self.file.write(
'%s<z>%d</z>\n' % (
' ' * self.
indent, iview[
'focus'][
'z']))
909 self.file.write(
'%s</focus>\n' % (
' ' * self.
indent))
911 self.
__writeTagWithValue(
'background_color', view[
'background'][
'color'][:3], format =
'd:%d:%d')
914 self.file.write(
'%s</view>\n' % (
' ' * self.
indent))
918 self.file.write(
'%s<light>\n' % (
' ' * self.
indent))
921 self.file.write(
'%s<l_position>\n' % (
' ' * self.
indent))
923 self.file.write(
'%s<x>%.2f</x>\n' % (
' ' * self.
indent, light[
'position'][
'x']))
924 self.file.write(
'%s<y>%.2f</y>\n' % (
' ' * self.
indent, light[
'position'][
'y']))
925 self.file.write(
'%s<z>%d</z>\n' % (
' ' * self.
indent, light[
'position'][
'z']))
927 self.file.write(
'%s</l_position>\n' % (
' ' * self.
indent))
936 self.file.write(
'%s</light>\n' % (
' ' * self.
indent))
941 self.file.write(
'%s<constant_planes>\n' % (
' ' * self.
indent))
943 for idx, plane
in enumerate(constants):
944 self.file.write(
'%s<plane>\n' % (
' ' * self.
indent))
950 self.file.write(
'%s</plane>\n' % (
' ' * self.
indent))
952 self.file.write(
'%s</constant_planes>\n' % (
' ' * self.
indent))
955 self.file.write(
'%s</nviz_state>\n' % (
' ' * self.
indent))
958 def __writeTagWithValue(self, tag, data, format = 'd'):
959 """!Helper function for writing pair tag
961 @param tag written tag
962 @param data written data
963 @param format conversion type
965 self.file.write(
'%s<%s>\n' % (
' ' * self.
indent, tag))
967 self.file.write(
'%s' % (
' ' * self.
indent))
968 self.file.write((
'<value>%' + format +
'</value>\n') % data)
970 self.file.write(
'%s</%s>\n' % (
' ' * self.
indent, tag))
974 """!Process GRC file"""
992 @param parent parent window
994 @return list of map layers
999 wx.MessageBox(parent=parent,
1000 message=_(
"Unable to open file <%s> for reading.") % self.
filename,
1001 caption=_(
"Error"), style=wx.OK | wx.ICON_ERROR)
1005 for line
in file.readlines():
1012 wx.MessageBox(parent=parent,
1013 message=_(
"Some lines were skipped when reading settings "
1014 "from file <%(file)s>.\nSee 'Command output' window for details.\n\n"
1015 "Number of skipped lines: %(line)d") % \
1017 caption=_(
"Warning"), style=wx.OK | wx.ICON_EXCLAMATION)
1018 parent.goutput.WriteLog(
'Map layers loaded from GRC file <%s>' % self.
filename)
1019 parent.goutput.WriteLog(
'Skipped lines:\n%s' % self.
error)
1024 """!Process line definition"""
1026 if element ==
'Group':
1028 self.layers.append({
1038 elif element ==
'_check':
1040 self.
layers[-1][
'checked'] =
True
1042 self.
layers[-1][
'checked'] =
False
1044 elif element ==
'End':
1054 elif element ==
'opacity':
1058 elif element ==
'Raster':
1060 self.layers.append({
1069 elif element ==
'map' and self.
inRaster:
1072 elif element ==
'overlay' and self.
inRaster:
1074 self.
layers[-1][
'cmd'].append(
'-o')
1076 elif element ==
'rastquery' and self.
inRaster:
1079 self.
layers[-1][
'cmd'].append(
'catlist=%s' % value)
1081 elif element ==
'bkcolor' and self.
inRaster:
1084 self.
layers[-1][
'cmd'].append(
'bg=%s' % value)
1087 elif element ==
'Vector':
1089 self.layers.append({
1098 elif element ==
'vect' and self.
inVector:
1101 elif element
in (
'display_shape',
1114 name = element.split(
'_')[0]
1115 type = element.split(
'_')[1]
1118 self.
layers[-1][
'cmd'].append(
'%s=%s' % (name, type))
1120 self.
layers[-1][
'cmd'][paramId] +=
',%s' % type
1122 elif element
in (
'color',
1127 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element,
1130 elif element ==
'rdmcolor' and self.
inVector:
1132 self.
layers[-1][
'cmd'].append(
'-c')
1134 elif element ==
'sqlcolor' and self.
inVector:
1136 self.
layers[-1][
'cmd'].append(
'-a')
1138 elif element
in (
'icon',
1149 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element,
1152 elif element ==
'lwidth':
1155 self.
layers[-1][
'cmd'].append(
'width=%s' % value)
1157 elif element ==
'lfield':
1160 self.
layers[-1][
'cmd'].append(
'llayer=%s' % value)
1162 elif element ==
'attribute':
1165 self.
layers[-1][
'cmd'].append(
'attrcol=%s' % value)
1167 elif element ==
'cat':
1170 self.
layers[-1][
'cmd'].append(
'cats=%s' % value)
1173 elif element ==
'gridline':
1175 self.layers.append({
1184 elif element ==
'gridcolor':
1189 elif element ==
'gridborder':
1194 elif element ==
'textcolor':
1199 elif element
in (
'gridsize',
1203 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element[4:], value))
1205 elif element
in 'fontsize':
1208 self.
layers[-1][
'cmd'].append(
'%s=%s' % (element, value))
1210 elif element ==
'griddraw':
1213 self.
layers[-1][
'cmd'].append(
'-n')
1215 elif element ==
'gridgeo':
1218 self.
layers[-1][
'cmd'].append(
'-g')
1220 elif element ==
'borderdraw':
1223 self.
layers[-1][
'cmd'].append(
'-b')
1225 elif element ==
'textdraw':
1228 self.
layers[-1][
'cmd'].append(
'-t')
1231 self.
error += _(
' row %d:') % line_id + line + os.linesep
1234 def _get_value(self, line):
1235 """!Get value of element"""
1237 return line.strip(
' ').
split(
' ')[1].strip(
' ')
1241 def _get_element(self, line):
1242 """!Get element tag"""
1243 return line.strip(
' ').
split(
' ')[0].strip(
' ')
1245 def _get_cmd_param_index(self, cmd, name):
1246 """!Get index of parameter in cmd list
1249 @param name parameter name
1252 @return -1 if not found
1256 if '=' not in param:
1259 if param.split(
'=')[0] == name:
1266 def _color_name_to_rgb(self, value):
1267 """!Convert color name (#) to rgb values"""
1268 col = wx.NamedColour(value)
1269 return str(col.Red()) +
':' + \
1270 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.