[GRASS-SVN] r51716 - in grass/trunk: gui/wxpython/nviz lib/nviz
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu May 24 13:01:16 EDT 2012
Author: annakrat
Date: 2012-05-24 10:01:15 -0700 (Thu, 24 May 2012)
New Revision: 51716
Modified:
grass/trunk/gui/wxpython/nviz/mapwindow.py
grass/trunk/gui/wxpython/nviz/tools.py
grass/trunk/lib/nviz/draw.c
grass/trunk/lib/nviz/nviz.c
Log:
wxNviz: removing of scale bars improved
Modified: grass/trunk/gui/wxpython/nviz/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/nviz/mapwindow.py 2012-05-24 17:00:22 UTC (rev 51715)
+++ grass/trunk/gui/wxpython/nviz/mapwindow.py 2012-05-24 17:01:15 UTC (rev 51716)
@@ -779,8 +779,15 @@
elif self.mouse["use"] in ('arrow', 'scalebar'):
self.lmgr.nviz.FindWindowById(
self.lmgr.nviz.win['decoration'][self.mouse["use"]]['place']).SetValue(False)
+ if self.mouse["use"] == 'scalebar':
+ scalebarNum = len(self.decoration['scalebar'])
+ self.lmgr.nviz.AddScalebar(scalebarNum - 1)
+ else:
+ self.lmgr.nviz.AddArrow()
self.mouse['use'] = 'pointer'
self.SetCursor(self.cursors['default'])
+
+
elif self.mouse['use'] == 'pointer':
if self.dragid > 0:
dx = self.mouse['end'][0] - self.mouse['begin'][0]
Modified: grass/trunk/gui/wxpython/nviz/tools.py
===================================================================
--- grass/trunk/gui/wxpython/nviz/tools.py 2012-05-24 17:00:22 UTC (rev 51715)
+++ grass/trunk/gui/wxpython/nviz/tools.py 2012-05-24 17:01:15 UTC (rev 51716)
@@ -1932,15 +1932,18 @@
toggle.SetName('placeArrow')
delete = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Delete"))
+ self.win['decoration']['arrow']['delete'] = delete.GetId()
gridSizer.Add(item = delete, pos = (2, 1))
delete.Bind(wx.EVT_BUTTON, self.OnArrowDelete)
+ shown = self.mapWindow.decoration['arrow']['show']
+ delete.Enable(shown)
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)
- # north arrow
+ # scale bars
self.win['decoration']['scalebar'] = {}
nabox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
label = " %s " % (_("Scale bar")))
@@ -1967,19 +1970,26 @@
color.Bind(csel.EVT_COLOURSELECT, self.OnDecorationProp)
# control
- toggle = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("Place scalebar"))
+ toggle = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("Place new scale bar"))
gridSizer.Add(item = toggle, pos = (2, 0))
toggle.Bind(wx.EVT_TOGGLEBUTTON, self.OnDecorationPlacement)
self.win['decoration']['scalebar']['place'] = toggle.GetId()
toggle.SetName('placeScalebar')
- delete = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Delete last"))
- gridSizer.Add(item = delete, pos = (2, 1))
+ scalebarChoice = wx.Choice(parent = panel, id = wx.ID_ANY, choices = [])
+ self.win['decoration']['scalebar']['choice'] = scalebarChoice.GetId()
+ gridSizer.Add(item = scalebarChoice, pos = (3, 0), flag = wx.EXPAND)
+ delete = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Delete"))
+ self.win['decoration']['scalebar']['delete'] = delete.GetId()
+ gridSizer.Add(item = delete, pos = (3, 1))
delete.Bind(wx.EVT_BUTTON, self.OnScalebarDelete)
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)
+
+ self.DisableScalebarControls()
+
panel.SetSizer(pageSizer)
panel.Layout()
panel.Fit()
@@ -4295,19 +4305,39 @@
"""!Delete arrow"""
self._display.DeleteArrow()
self.mapWindow.decoration['arrow']['show'] = False
+ self.FindWindowById( self.win['decoration']['arrow']['delete']).Disable()
self.mapWindow.Refresh(False)
def OnScalebarDelete(self, event):
"""!Delete scalebar"""
- try:
- id = self.mapWindow.decoration['scalebar'][-1]['id']
- except IndexError:
+ choice = self.FindWindowById(self.win['decoration']['scalebar']['choice'])
+ choiceIndex = choice.GetSelection()
+ index = choice.GetClientData(choiceIndex)
+ if index == wx.NOT_FOUND:
return
- self._display.DeleteScalebar(id = id)
- del self.mapWindow.decoration['scalebar'][-1]
+ self._display.DeleteScalebar(id = index)
- self.mapWindow.Refresh(False)
+ self.FindWindowById(self.win['decoration']['scalebar']['choice']).Delete(choiceIndex)
+ if not choice.IsEmpty():
+ choice.SetSelection(choice.GetCount() - 1)
+ self.DisableScalebarControls()
+
+ self.mapWindow.Refresh(False)
+ def AddScalebar(self, scalebarNum):
+ choice = self.FindWindowById(self.win['decoration']['scalebar']['choice'])
+ choice.Append(_("Scalebar %d") % (scalebarNum + 1), scalebarNum)
+ choice.SetSelection(choice.GetCount() - 1)
+ self.DisableScalebarControls()
+
+ def AddArrow(self):
+ self.FindWindowById( self.win['decoration']['arrow']['delete']).Enable()
+
+ def DisableScalebarControls(self):
+ choice = self.FindWindowById(self.win['decoration']['scalebar']['choice'])
+ self.FindWindowById(self.win['decoration']['scalebar']['delete']).Enable(not choice.IsEmpty())
+ self.FindWindowById(self.win['decoration']['scalebar']['choice']).Enable(not choice.IsEmpty())
+
def OnDecorationProp(self, event):
"""!Set arrow/scalebar properties"""
if event.GetId() in self.win['decoration']['arrow'].values():
@@ -4322,8 +4352,9 @@
self.mapWindow.decoration[type]['color'] = self._getColorString(color)
self.mapWindow.decoration[type]['size'] = size
elif type == 'scalebar'and self.mapWindow.decoration['scalebar']:
- self.mapWindow.decoration[type][-1]['color'] = self._getColorString(color)
- self.mapWindow.decoration[type][-1]['size'] = size
+ for scalebar in self.mapWindow.decoration[type]:
+ scalebar['color'] = self._getColorString(color)
+ scalebar['size'] = size
if type == 'arrow' and self.mapWindow.decoration['arrow']['show']:
self._display.SetArrow(self.mapWindow.decoration['arrow']['position']['x'],
@@ -4332,11 +4363,17 @@
self.mapWindow.decoration['arrow']['color'])
self._display.DrawArrow()
elif type == 'scalebar' and self.mapWindow.decoration['scalebar']:
- self._display.SetScalebar(self.mapWindow.decoration['scalebar'][-1]['id'],
- self.mapWindow.decoration['scalebar'][-1]['position']['x'],
- self.mapWindow.decoration['scalebar'][-1]['position']['y'],
- self.mapWindow.decoration['scalebar'][-1]['size'],
- self.mapWindow.decoration['scalebar'][-1]['color'])
+ ids = []
+ choice = self.FindWindowById(self.win['decoration']['scalebar']['choice'])
+ for index in range(choice.GetCount()):
+ ids.append(choice.GetClientData(index))
+ for scalebar in self.mapWindow.decoration[type]:
+ if scalebar['id'] in ids:
+ self._display.SetScalebar(scalebar['id'],
+ scalebar['position']['x'],
+ scalebar['position']['y'],
+ scalebar['size'],
+ scalebar['color'])
self._display.DrawScalebar()
self.mapWindow.Refresh(False)
Modified: grass/trunk/lib/nviz/draw.c
===================================================================
--- grass/trunk/lib/nviz/draw.c 2012-05-24 17:00:22 UTC (rev 51715)
+++ grass/trunk/lib/nviz/draw.c 2012-05-24 17:01:15 UTC (rev 51716)
@@ -251,10 +251,11 @@
/* scale bar */
for (i = 0; i < data->num_scalebars; i++) {
- struct scalebar_data *s = data->scalebar[i];
- gsd_scalebar_v2(s->where, s->size, 0, s->color, s->color);
+ if (data->scalebar[i]){
+ struct scalebar_data *s = data->scalebar[i];
+ gsd_scalebar_v2(s->where, s->size, 0, s->color, s->color);
+ }
}
-
GS_done_draw();
GS_set_draw(GSD_BACK);
Modified: grass/trunk/lib/nviz/nviz.c
===================================================================
--- grass/trunk/lib/nviz/nviz.c 2012-05-24 17:00:22 UTC (rev 51715)
+++ grass/trunk/lib/nviz/nviz.c 2012-05-24 17:01:15 UTC (rev 51716)
@@ -347,7 +347,7 @@
s->where[2] = coords[2];
data->scalebar = (struct scalebar_data **) G_realloc(data->scalebar,
- data->num_scalebars + 1 * sizeof(struct scalebar_data *));
+ (data->num_scalebars + 1) * sizeof(struct scalebar_data *));
data->scalebar[data->num_scalebars++] = s;
return s;
@@ -385,16 +385,18 @@
GS_set_Narrow(pt, id, coords); /* the same like arrow */
for (i = 0; i < data->num_scalebars; i++) {
- s = data->scalebar[i];
- if (s->id == bar_id) {
- s->color = color;
- s->size = size;
- s->where[0] = coords[0];
- s->where[1] = coords[1];
- s->where[2] = coords[2];
+ if (data->scalebar[i]) {
+ s = data->scalebar[i];
+ if (s->id == bar_id) {
+ s->color = color;
+ s->size = size;
+ s->where[0] = coords[0];
+ s->where[1] = coords[1];
+ s->where[2] = coords[2];
- return s;
- }
+ return s;
+ }
+ }
}
s = Nviz_new_scalebar(data, bar_id, coords, size, color);
@@ -415,22 +417,26 @@
GLuint FontBase = 0; /* don't know how to get fontbase*/
for (i = 0; i < data->num_scalebars; i++) {
- struct scalebar_data *s = data->scalebar[i];
+ if (data->scalebar[i]) {
+ struct scalebar_data *s = data->scalebar[i];
- gsd_scalebar_v2(s->where, s->size, FontBase, s->color, s->color);
+ gsd_scalebar_v2(s->where, s->size, FontBase, s->color, s->color);
+ }
}
}
/*!
\brief Deletes scale bar
+
+ When scalebar is freed, array then contains NULL,
+ which must be tested during drawing.
\param data nviz data
*/
void Nviz_delete_scalebar(nv_data *data, int bar_id)
{
- if (bar_id < data->num_scalebars) {
+ if (bar_id < data->num_scalebars && data->scalebar[bar_id] != NULL) {
G_free(data->scalebar[bar_id]);
data->scalebar[bar_id] = NULL;
- data->num_scalebars--;
}
}
More information about the grass-commit
mailing list