[GRASS-SVN] r68931 - in grass/branches/releasebranch_7_2/gui/wxpython: core lmgr
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jul 10 07:05:34 PDT 2016
Author: annakrat
Date: 2016-07-10 07:05:34 -0700 (Sun, 10 Jul 2016)
New Revision: 68931
Modified:
grass/branches/releasebranch_7_2/gui/wxpython/core/workspace.py
grass/branches/releasebranch_7_2/gui/wxpython/lmgr/frame.py
Log:
wxGUI: write overlays (legend, barscale, arrow) into workspace, see #2369, author Adam Laza (merged from trunk, r68645 and others)
Modified: grass/branches/releasebranch_7_2/gui/wxpython/core/workspace.py
===================================================================
--- grass/branches/releasebranch_7_2/gui/wxpython/core/workspace.py 2016-07-10 01:35:04 UTC (rev 68930)
+++ grass/branches/releasebranch_7_2/gui/wxpython/core/workspace.py 2016-07-10 14:05:34 UTC (rev 68931)
@@ -53,6 +53,9 @@
#
self.layers = []
#
+ # list of overlays
+ self.overlays = []
+ #
# nviz state
#
self.nviz_state = {}
@@ -213,6 +216,13 @@
"vdigit": vdigit,
"nviz": nviz})
+ elif item.tag == 'overlay':
+ cmd = self.__processOverlay(item)
+
+ self.overlays.append({
+ "display": self.displayIndex,
+ "cmd": cmd})
+
def __processLayer(self, layer):
"""Process layer item
@@ -271,6 +281,31 @@
return (cmd, selected, vdigit, nviz)
+ def __processOverlay(self, node_overlay):
+ """
+ Process overlay item
+ :param overlay: tree node
+ """
+ cmd = list()
+
+ cmd.append(node_overlay.get('name', "unknown"))
+
+ # flags
+ for f in node_overlay.findall('flag'):
+ flag = f.get('name', '')
+ if len(flag) > 1:
+ cmd.append('--' + flag)
+ else:
+ cmd.append('-' + flag)
+
+ # parameters
+ for p in node_overlay.findall('parameter'):
+ cmd.append('%s=%s' % (p.get('name', ''),
+ self.__filterValue(
+ self.__getNodeText(p, 'value'))))
+
+ return cmd
+
def __processLayerVdigit(self, node_vdigit):
"""Process vector digitizer layer settings
@@ -866,6 +901,10 @@
light=nvizDisp.light,
constants=nvizDisp.constants)
+ # list of map elements
+ item = mapTree.GetFirstChild(mapTree.root)[0]
+ self.__writeOverlay(mapdisp)
+
file.write('%s</display>\n' % (' ' * self.indent))
self.indent = - 4
@@ -1474,7 +1513,74 @@
self.indent -= 4
self.file.write('%s</%s>\n' % (' ' * self.indent, tag))
+ def __writeOverlay(self, mapdisp):
+ """Function for writing map elements (barscale, northarrow etc.)
+ """
+ disp_size = mapdisp.GetMapWindow().GetClientSize()
+ if mapdisp.arrow.IsShown():
+ cmd = mapdisp.arrow.cmd
+ coord_px = mapdisp.arrow.coords
+ self.__writeOverlayParams(disp_size, cmd, coord_px)
+
+ if (mapdisp.legend) and mapdisp.legend.IsShown():
+ cmd = mapdisp.legend.cmd
+ coord_px = mapdisp.legend.coords
+ self.__writeOverlayParams(disp_size, cmd, coord_px)
+
+ if mapdisp.barscale and mapdisp.barscale.IsShown():
+ cmd = mapdisp.barscale.cmd
+ coord_px = mapdisp.barscale.coords
+ self.__writeOverlayParams(disp_size, cmd, coord_px)
+
+ def __writeOverlayParams(self, disp_size, cmd, coord_px):
+ """
+ :param mapdisp: mapdisplay
+ :param cmd: d.* command with flags and parameters
+ """
+ # Canvas width = display width minus 1 px on both sides
+ cnvs_w = float(disp_size[0])
+ # Canvas height = display height minus 1 px on bottom and height of toolbar
+ cnvs_h = float(disp_size[1])
+
+ x_prcn = round(coord_px[0] / cnvs_w * 100, 1)
+ y_prcn = 100 - round(coord_px[1] / cnvs_h * 100, 1)
+ self.indent += 4
+ self.file.write('%s<overlay name="%s">\n' % (' ' * self.indent, cmd[0]))
+ self.indent += 4
+ for prm in cmd[1:]:
+ if prm[0] == "-":
+ for i in range(1, len(prm)):
+ self.file.write('%s<flag name="%s" />\n' % (' ' * self.indent, prm[i]))
+ elif prm.startswith("at="):
+ # legend "at" argument takes 4 numbers not 2
+ if cmd[0] == "d.legend":
+ leg_coord_prcn = prm.split("=", 1)[1].split(",")
+ leg_w = float(leg_coord_prcn[3]) - float(leg_coord_prcn[2])
+ leg_h = float(leg_coord_prcn[1]) - float(leg_coord_prcn[0])
+ self.file.write('%s<parameter name="at">\n' % (' ' * self.indent))
+ self.indent += 4
+ self.file.write('%s<value>%.1f,%.1f,%.1f,%.1f</value>\n' % (' ' * self.indent,
+ y_prcn - leg_h, y_prcn, x_prcn, x_prcn + leg_w))
+ self.indent -= 4
+ self.file.write('%s</parameter>\n' % (' ' * self.indent))
+ else:
+ self.file.write('%s<parameter name="at">\n' % (' ' * self.indent))
+ self.indent += 4
+ self.file.write('%s<value>%.1f,%.1f</value>\n' % (' ' * self.indent, x_prcn, y_prcn))
+ self.indent -= 4
+ self.file.write('%s</parameter>\n' % (' ' * self.indent))
+ else:
+ self.file.write('%s<parameter name="%s">\n' % (' ' * self.indent, prm.split("=", 1)[0]))
+ self.indent += 4
+ self.file.write('%s<value>%s</value>\n' % (' ' * self.indent, prm.split("=", 1)[1]))
+ self.indent -= 4
+ self.file.write('%s</parameter>\n' % (' ' * self.indent))
+ self.indent -= 4
+ self.file.write('%s</overlay>\n' % (' ' * self.indent))
+ self.indent -= 4
+
+
class ProcessGrcFile(object):
def __init__(self, filename):
Modified: grass/branches/releasebranch_7_2/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/branches/releasebranch_7_2/gui/wxpython/lmgr/frame.py 2016-07-10 01:35:04 UTC (rev 68930)
+++ grass/branches/releasebranch_7_2/gui/wxpython/lmgr/frame.py 2016-07-10 14:05:34 UTC (rev 68931)
@@ -1474,22 +1474,34 @@
for i, display in enumerate(gxwXml.displays):
mapdisplay[i].mapWindowProperties.autoRender = display['render']
- for idx, mdisp in enumerate(mapdisplay):
+ for overlay in gxwXml.overlays:
+ # overlay["cmd"][0] name of command e.g. d.barscale, d.legend
+ # overlay["cmd"][1:] parameters and flags
+ if overlay['display'] == i:
+ if overlay['cmd'][0] == "d.legend":
+ mapdisplay[i].AddLegend(overlay['cmd'])
+ if overlay['cmd'][0] == "d.barscale":
+ mapdisplay[i].AddBarscale(overlay['cmd'])
+ if overlay['cmd'][0] == "d.northarrow":
+ mapdisplay[i].AddArrow(overlay['cmd'])
+ if overlay['cmd'][0] == "d.text":
+ mapdisplay[i].AddDtext(overlay['cmd'])
+
# avoid double-rendering when loading workspace
# mdisp.MapWindow2D.UpdateMap()
# nviz
- if gxwXml.displays[idx]['viewMode'] == '3d':
- mdisp.AddNviz()
+ if gxwXml.displays[i]['viewMode'] == '3d':
+ mapdisplay[i].AddNviz()
self.nviz.UpdateState(view=gxwXml.nviz_state['view'],
iview=gxwXml.nviz_state['iview'],
light=gxwXml.nviz_state['light'])
- mdisp.MapWindow3D.constants = gxwXml.nviz_state['constants']
- for idx, constant in enumerate(mdisp.MapWindow3D.constants):
- mdisp.MapWindow3D.AddConstant(constant, idx + 1)
+ mapdisplay[i].MapWindow3D.constants = gxwXml.nviz_state['constants']
+ for idx, constant in enumerate(mapdisplay[i].MapWindow3D.constants):
+ mapdisplay[i].MapWindow3D.AddConstant(constant, i + 1)
for page in ('view', 'light', 'fringe', 'constant', 'cplane'):
self.nviz.UpdatePage(page)
self.nviz.UpdateSettings()
- mdisp.toolbars['map'].combo.SetSelection(1)
+ mapdisplay[i].toolbars['map'].combo.SetSelection(1)
return True
@@ -2410,10 +2422,10 @@
self.Destroy()
return
- # save changes in the workspace
- maptree = self.GetLayerTree()
- if self.workspaceChanged and UserSettings.Get(
- group='manager', key='askOnQuit', subkey='enabled'):
+ if UserSettings.Get(group='manager', key='askOnQuit',
+ subkey='enabled') and self.workspaceChanged:
+ maptree = self.GetLayerTree()
+
if self.workspaceFile:
message = _("Do you want to save changes in the workspace?")
else:
More information about the grass-commit
mailing list