[GRASS-SVN] r47004 - in grass/trunk: gui/wxpython/gui_modules
include lib/nviz
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 5 10:21:00 EDT 2011
Author: annakrat
Date: 2011-07-05 07:21:00 -0700 (Tue, 05 Jul 2011)
New Revision: 47004
Modified:
grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
grass/trunk/gui/wxpython/gui_modules/preferences.py
grass/trunk/gui/wxpython/gui_modules/workspace.py
grass/trunk/gui/wxpython/gui_modules/wxnviz.py
grass/trunk/include/nviz.h
grass/trunk/lib/nviz/draw.c
grass/trunk/lib/nviz/nviz.c
grass/trunk/lib/nviz/position.c
Log:
wxNviz: draw north arrow
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-05 14:21:00 UTC (rev 47004)
@@ -140,6 +140,8 @@
self.nvizDefault = NvizDefault()
self.light = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'light')) # copy
+ self.decoration = self.nvizDefault.SetDecorDefaultProp()
+ self.decoration['arrow']['size'] = round(self._display.GetLongDim() / 8., -2)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE, self.OnSize)
@@ -208,6 +210,7 @@
self.lmgr.nviz.UpdatePage('view')
self.lmgr.nviz.UpdatePage('light')
self.lmgr.nviz.UpdatePage('cplane')
+ self.lmgr.nviz.UpdatePage('decoration')
layer = self.GetSelectedLayer()
if layer:
if layer.type == 'raster':
@@ -302,7 +305,19 @@
self.cplanes[idx]['position']['x'] = x
self.cplanes[idx]['position']['y'] = y
self.render['quick'] = True
-
+
+ if self.mouse['use'] == 'arrow':
+ pos = event.GetPosition()
+ size = self.GetClientSize()
+ if self._display.SetArrow(pos[0], size[1] - pos[1],
+ self.decoration['arrow']['size'],
+ self.decoration['arrow']['color']):
+ self._display.DrawArrow()
+ # update
+ self.decoration['arrow']['show'] = True
+ self.decoration['arrow']['position']['x'] = pos[0]
+ self.decoration['arrow']['position']['y'] = size[1] - pos[1]
+ self.DoPaint()
event.Skip()
def OnDragging(self, event):
@@ -347,6 +362,10 @@
self.lmgr.nviz.FindWindowByName('cplaneHere').SetValue(False)
self.mouse['use'] = 'default'
self.SetCursor(self.cursors['default'])
+ elif self.mouse["use"] == 'arrow':
+ self.lmgr.nviz.FindWindowByName('placeArrow').SetValue(False)
+ self.mouse['use'] = 'default'
+ self.SetCursor(self.cursors['default'])
def OnQuerySurface(self, event):
"""!Query surface on given position"""
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py 2011-07-05 14:21:00 UTC (rev 47004)
@@ -442,8 +442,13 @@
window = self._createFringePage(parent = fringePanel), flags = fpb.FPB_ALIGN_WIDTH)
self.EnablePage('fringe', False)
-
-
+
+ # decoration page
+ decorationPanel = self.foldpanelAppear.AddFoldPanel(_("Decorations"), collapsed = True)
+ self.foldpanelAppear.AddFoldPanelWindow(decorationPanel,
+ window = self._createDecorationPage(parent = decorationPanel), flags = fpb.FPB_ALIGN_WIDTH)
+
+
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.foldpanelAppear, proportion = 1, flag = wx.EXPAND)
self.mainPanelAppear.SetSizer(sizer)
@@ -1692,7 +1697,64 @@
panel.Fit()
return panel
+
+ def _createDecorationPage(self, parent):
+ """!Create decoration (north arrow, scalebar, legend) page"""
+ panel = wx.Panel(parent = parent, id = wx.ID_ANY)
+
+ self.page['decoration'] = { 'id' : 2,
+ 'notebook' : self.foldpanelAppear.GetId()}
+ self.win['decoration'] = {}
+ pageSizer = wx.BoxSizer(wx.VERTICAL)
+ #
+ # north arrow
+ #
+ self.win['decoration']['arrow'] = {}
+ nabox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
+ label = " %s " % (_("North Arrow")))
+ naboxSizer = wx.StaticBoxSizer(nabox, wx.VERTICAL)
+ gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
+ # size
+ gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+ label = _("Arrow size (in map units):")),
+ pos = (0,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
+ sizeSpin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
+ min = 0, max = 1e6, initial = 1000)
+ gridSizer.Add(sizeSpin, pos = (0, 2))
+ self.win['decoration']['arrow']['size'] = sizeSpin.GetId()
+ sizeSpin.Bind(wx.EVT_SPINCTRL, self.OnArrowProp)
+
+ # color
+ gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+ label = _("Arrow color:")),
+ pos = (1,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
+ color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
+ size = globalvar.DIALOG_COLOR_SIZE)
+ gridSizer.Add(color, pos = (1, 2))
+ self.win['decoration']['arrow']['color'] = color.GetId()
+ color.Bind(csel.EVT_COLOURSELECT, self.OnArrowProp)
+
+ # control
+ toggle = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("Place arrow"))
+ gridSizer.Add(item = toggle, pos = (2, 0))
+ toggle.Bind(wx.EVT_TOGGLEBUTTON, self.OnArrowPlacement)
+ toggle.SetName('placeArrow')
+
+ delete = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Delete"))
+ gridSizer.Add(item = delete, pos = (2, 1))
+ delete.Bind(wx.EVT_BUTTON, self.OnArrowDelete)
+ naboxSizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND, border = 3)
+ pageSizer.Add(item = naboxSizer, proportion = 0,
+ flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
+ border = 3)
+
+ panel.SetSizer(pageSizer)
+ panel.Layout()
+ panel.Fit()
+
+ return panel
+
def GetLayerData(self, nvizType):
"""!Get nviz data"""
name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
@@ -3099,16 +3161,43 @@
self.UpdateCPlanePage(planeIndex)
def OnCPlanePos(self, event):
- plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
- try:
- planeIndex = int(plane.split()[1])
- except:#TODO disabled page
- planeIndex = -1
+ """!Place cutting plane rotation center interactively"""
self.mapWindow.mouse['use'] = 'cplane'
self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
self.parent.curr_page.maptree.mapdisplay.SetFocus()
self.parent.curr_page.maptree.mapdisplay.Raise()
+
+ def OnArrowPlacement(self, event):
+ """!Place an arrow by clicking on display"""
+ if event.GetInt():
+ self.mapWindow.mouse['use'] = 'arrow'
+ self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
+ else:
+ self.mapWindow.mouse['use'] = 'default'
+ self.mapWindow.SetCursor(self.mapWindow.cursors["default"])
+
+ def OnArrowDelete(self, event):
+ """!Delete arrow"""
+ self._display.DeleteArrow()
+ self.mapWindow.decoration['arrow']['show'] = False
+ self.mapWindow.Refresh(False)
+ def OnArrowProp(self, event):
+ """!Set arrow properties"""
+ color = self.FindWindowById(self.win['decoration']['arrow']['color']).GetValue()
+ self.mapWindow.decoration['arrow']['color'] = self._getColorString(color)
+
+ size = self.FindWindowById(self.win['decoration']['arrow']['size']).GetValue()
+ self.mapWindow.decoration['arrow']['size'] = size
+
+ if self.mapWindow.decoration['arrow']['show']:
+ self._display.SetArrow(self.mapWindow.decoration['arrow']['position']['x'],
+ self.mapWindow.decoration['arrow']['position']['y'],
+ self.mapWindow.decoration['arrow']['size'],
+ self.mapWindow.decoration['arrow']['color'])
+ self._display.DrawArrow()
+ self.mapWindow.Refresh(False)
+
def UpdatePage(self, pageId):
"""!Update dialog (selected page)"""
self.pageChanging = True
@@ -3169,6 +3258,9 @@
elif pageId == 'fringe':
win = self.FindWindowById(self.win['fringe']['map'])
win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
+ elif pageId == 'decoration':
+ win = self.FindWindowById(self.win['decoration']['arrow']['size'])
+ win.SetValue(self.mapWindow.decoration['arrow']['size'])
elif pageId == 'constant':
if self.mapWindow.constants:
surface = self.FindWindowById(self.win['constant']['surface'])
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2011-07-05 14:21:00 UTC (rev 47004)
@@ -577,6 +577,9 @@
'elev' : 55,
'color' : (128, 128, 128, 255), # grey
},
+ 'arrow': {
+ 'color': (0, 0, 0)
+ }
},
'modeler' : {
'action' : {
@@ -683,6 +686,11 @@
self.internalSettings['nviz']['view']['focus']['x'] = -1
self.internalSettings['nviz']['view']['focus']['y'] = -1
self.internalSettings['nviz']['view']['focus']['z'] = -1
+ self.internalSettings['nviz']['arrow'] = {}
+ self.internalSettings['nviz']['arrow']['position'] = {}
+ self.internalSettings['nviz']['arrow']['position']['x'] = 0
+ self.internalSettings['nviz']['arrow']['position']['y'] = 0
+ self.internalSettings['nviz']['arrow']['size'] = 100
self.internalSettings['nviz']['vector'] = {}
self.internalSettings['nviz']['vector']['points'] = {}
self.internalSettings['nviz']['vector']['points']['marker'] = ("x",
Modified: grass/trunk/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/workspace.py 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/gui/wxpython/gui_modules/workspace.py 2011-07-05 14:21:00 UTC (rev 47004)
@@ -780,6 +780,19 @@
return (value, desc)
+ def SetDecorDefaultProp(self):
+ data = {}
+
+ # arrow
+ data['arrow'] = UserSettings.Get(group = 'nviz', key = 'arrow')
+ data['arrow']['color'] = "%d:%d:%d" % (
+ UserSettings.Get(group = 'nviz', key = 'arrow', subkey = 'color')[:3])
+ data['arrow'].update(UserSettings.Get(group = 'nviz', key = 'arrow', internal = True))
+ data['arrow']['show'] = False
+ return data
+
+
+
class WriteWorkspaceFile(object):
"""!Generic class for writing workspace file"""
def __init__(self, lmgr, file):
Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-07-05 14:21:00 UTC (rev 47004)
@@ -104,6 +104,10 @@
width, height)
return Nviz_resize_window(width, height)
+ def GetLongDim(self):
+ """!Get longest dimension, used for initial size of north arrow"""
+ return Nviz_get_longdim(self.data)
+
def SetViewDefault(self):
"""!Set default view (based on loaded data)
@@ -1368,7 +1372,26 @@
Nviz_set_fringe(self.data,
sid, Nviz_color_from_str(scolor),
elev, int(nw), int(ne), int(sw), int(se))
+
+ def DrawArrow(self):
+ """!Draw north arrow
+ """
+ return Nviz_draw_arrow(self.data)
+ def SetArrow(self, sx, sy, size, color):
+ """!Set north arrow from canvas coordinates
+
+ @param sx,sy canvas coordinates
+ @param size arrow length
+ @param color arrow color
+ """
+ return Nviz_set_arrow(self.data, sx, sy, size, Nviz_color_from_str(color))
+
+ def DeleteArrow(self):
+ """!Delete draw north arrow
+ """
+ Nviz_delete_arrow(self.data)
+
def GetPointOnSurface(self, sx, sy):
"""!Get point on surface
Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/include/nviz.h 2011-07-05 14:21:00 UTC (rev 47004)
@@ -80,6 +80,13 @@
int where[4];
};
+struct arrow_data
+{
+ unsigned long color;
+ float size;
+ float where[3];
+};
+
typedef struct
{
/* ranges */
@@ -97,6 +104,10 @@
/* fringe */
int num_fringes;
struct fringe_data **fringe;
+
+ /* north arrow */
+ int draw_arrow;
+ struct arrow_data *arrow;
/* background color */
int bgcolor;
@@ -186,6 +197,9 @@
struct fringe_data *Nviz_set_fringe(nv_data *, int, unsigned long,
double, int, int, int, int);
void Nviz_draw_fringe(nv_data *data);
+int Nviz_draw_arrow(nv_data *);
+int Nviz_set_arrow(nv_data *, int, int, float, unsigned int);
+void Nviz_delete_arrow(nv_data *);
/* position.c */
void Nviz_init_view(nv_data *);
@@ -196,6 +210,7 @@
int Nviz_get_focus(nv_data *, float *, float *, float *);
float Nviz_get_xyrange(nv_data *);
int Nviz_get_zrange(nv_data *, float *, float *);
+float Nviz_get_longdim(nv_data *);
/* render.c */
struct render_window *Nviz_new_render_window();
Modified: grass/trunk/lib/nviz/draw.c
===================================================================
--- grass/trunk/lib/nviz/draw.c 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/lib/nviz/draw.c 2011-07-05 14:21:00 UTC (rev 47004)
@@ -237,6 +237,12 @@
struct fringe_data * f = data->fringe[i];
GS_draw_fringe(f->id, f->color, f->elev, f->where);
}
+
+ /* North Arrow */
+ if (data->draw_arrow) {
+ gsd_north_arrow(data->arrow->where, data->arrow->size,
+ (GLuint)NULL, data->arrow->color, data->arrow->color);
+ }
GS_done_draw();
GS_set_draw(GSD_BACK);
Modified: grass/trunk/lib/nviz/nviz.c
===================================================================
--- grass/trunk/lib/nviz/nviz.c 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/lib/nviz/nviz.c 2011-07-05 14:21:00 UTC (rev 47004)
@@ -46,6 +46,10 @@
/* fringe */
data->num_fringes = 0;
data->fringe = NULL;
+
+ /* north arrow */
+ data->draw_arrow = 0;
+ data->arrow = NULL;
return;
}
@@ -63,6 +67,13 @@
}
data->num_fringes = 0;
data->fringe = NULL;
+
+ if (data->arrow) {
+ G_free(data->arrow);
+ data->arrow = NULL;
+ data->draw_arrow = 0;
+ }
+
}
/*!
@@ -136,6 +147,7 @@
if (num < 1)
return NULL;
id = surf[0];
+ G_free(surf);
}
@@ -179,6 +191,7 @@
if (num < 1)
return NULL;
id = surf[0];
+ G_free(surf);
}
for (i = 0; i < data->num_fringes; i++) {
@@ -215,3 +228,81 @@
GS_draw_fringe(f->id, f->color, f->elev, f->where);
}
}
+/*!
+ \brief Sets the North Arrow position and return world coords
+
+ \param data nviz data
+ \param sx,sy screen coordinates
+ \param size arrow length
+ \param color arrow/text color
+ */
+int Nviz_set_arrow(nv_data *data,
+ int sx, int sy, float size,
+ unsigned int color)
+{
+ int id, pt[2];
+ int *surf_list, num_surfs;
+ float coords[3];
+ struct arrow_data *arw;
+
+ if (GS_num_surfs() > 0) {
+ surf_list = GS_get_surf_list(&num_surfs);
+ id = surf_list[0];
+ G_free(surf_list);
+
+ pt[0] = sx;
+ pt[1] = sy;
+
+ GS_set_Narrow(pt, id, coords);
+
+ if (data->arrow) {
+ data->arrow->color = color;
+ data->arrow->size = size;
+ data->arrow->where[0] = coords[0];
+ data->arrow->where[1] = coords[1];
+ data->arrow->where[2] = coords[2];
+ }
+ else {
+ arw = (struct arrow_data *) G_malloc(sizeof(struct arrow_data));
+ arw->color = color;
+ arw->size = size;
+ arw->where[0] = coords[0];
+ arw->where[1] = coords[1];
+ arw->where[2] = coords[2];
+
+ data->arrow = arw;
+ }
+ return 1;
+ }
+ return 0;
+}
+
+
+/*!
+ \brief Draws the North Arrow
+
+ \param data nviz data
+ */
+int Nviz_draw_arrow(nv_data *data)
+{
+
+ struct arrow_data *arw = data->arrow;
+ GLuint FontBase = 0; /* don't know how to get fontbase*/
+
+ data->draw_arrow = 1;
+ gsd_north_arrow(arw->where, arw->size, FontBase, arw->color, arw->color);
+
+ return 1;
+}
+
+/*!
+ \brief Deletes the North Arrow
+
+ \param data nviz data
+ */
+void Nviz_delete_arrow(nv_data *data)
+{
+ data->draw_arrow = 0;
+
+ return;
+}
Modified: grass/trunk/lib/nviz/position.c
===================================================================
--- grass/trunk/lib/nviz/position.c 2011-07-05 14:20:49 UTC (rev 47003)
+++ grass/trunk/lib/nviz/position.c 2011-07-05 14:21:00 UTC (rev 47004)
@@ -189,3 +189,17 @@
GS_get_zrange_nz(min, max);
return 1;
}
+
+/*!
+ \brief Get largest dimension
+
+ \param data nviz data
+ */
+float Nviz_get_longdim(nv_data * data)
+{
+ float dim;
+
+ GS_get_longdim(&dim);
+
+ return dim;
+}
More information about the grass-commit
mailing list