[GRASS-SVN] r47320 - in grass/trunk: gui/wxpython/gui_modules
include lib/nviz
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jul 30 13:19:35 EDT 2011
Author: annakrat
Date: 2011-07-30 10:19:35 -0700 (Sat, 30 Jul 2011)
New Revision: 47320
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
Log:
wxNviz: draw simple scale bar (sofar without text label)
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-30 14:40:56 UTC (rev 47319)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-30 17:19:35 UTC (rev 47320)
@@ -144,12 +144,9 @@
self.nvizDefault = NvizDefault()
self.light = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'light')) # copy
- self.decoration = self.nvizDefault.SetDecorDefaultProp()
- arwSize = self._display.GetLongDim() / 8.
- coef = 0.01
- if arwSize < 1:
- coef = 100.
- self.decoration['arrow']['size'] = int(arwSize * coef)/coef
+ self.decoration = self.nvizDefault.SetDecorDefaultProp(type = 'arrow')
+ self.decoration['scalebar'] = []
+ self.decoration['arrow']['size'] = self._getDecorationSize()
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE, self.OnSize)
@@ -412,6 +409,11 @@
size = self.GetClientSize()
self.SetDrawArrow((pos[0], size[1] - pos[1]))
+ if self.mouse['use'] == 'scalebar':
+ pos = event.GetPosition()
+ size = self.GetClientSize()
+ self.SetDrawScalebar((pos[0], size[1] - pos[1]))
+
if self.mouse['use'] == 'pointer':
# get decoration or text id
self.dragid = None
@@ -473,8 +475,9 @@
self.lmgr.nviz.FindWindowByName('cplaneHere').SetValue(False)
self.mouse['use'] = 'pointer'
self.SetCursor(self.cursors['default'])
- elif self.mouse["use"] == 'arrow':
- self.lmgr.nviz.FindWindowByName('placeArrow').SetValue(False)
+ elif self.mouse["use"] in ('arrow', 'scalebar'):
+ self.lmgr.nviz.FindWindowById(
+ self.lmgr.nviz.win['decoration'][self.mouse["use"]]['place']).SetValue(False)
self.mouse['use'] = 'pointer'
self.SetCursor(self.cursors['default'])
elif self.mouse['use'] == 'pointer':
@@ -641,6 +644,8 @@
self._display.DrawFringe()
if self.decoration['arrow']['show']:
self._display.DrawArrow()
+ if self.decoration['scalebar']:
+ self._display.DrawScalebar()
stop = time.clock()
@@ -658,6 +663,14 @@
self._display.EraseMap()
self.SwapBuffers()
+ def _getDecorationSize(self):
+ """!Get initial size of north arrow/scalebar"""
+ size = self._display.GetLongDim() / 8.
+ coef = 0.01
+ if size < 1:
+ coef = 100.
+ return int(size * coef)/coef
+
def SetDrawArrow(self, pos):
if self._display.SetArrow(pos[0], pos[1],
@@ -669,7 +682,27 @@
self.decoration['arrow']['position']['x'] = pos[0]
self.decoration['arrow']['position']['y'] = pos[1]
self.Refresh(False)
-
+
+ def SetDrawScalebar(self, pos):
+ """!Add scale bar, sets properties and draw"""
+ if len(self.decoration['scalebar']) == 0:
+ self.decoration['scalebar'].append(
+ self.nvizDefault.SetDecorDefaultProp(type = 'scalebar')['scalebar'])
+ self.decoration['scalebar'][0]['size'] = self._getDecorationSize()
+ else:
+ self.decoration['scalebar'].append(copy.deepcopy(self.decoration['scalebar'][-1]))
+ self.decoration['scalebar'][-1]['id'] += 1
+
+ ret = self._display.SetScalebar(self.decoration['scalebar'][-1]['id'], pos[0], pos[1],
+ self.decoration['scalebar'][-1]['size'],
+ self.decoration['scalebar'][-1]['color'])
+ if ret:
+ self._display.DrawScalebar()
+ # update
+ self.decoration['scalebar'][-1]['position']['x'] = pos[0]
+ self.decoration['scalebar'][-1]['position']['y'] = pos[1]
+ self.Refresh(False)
+
def IsLoaded(self, item):
"""!Check if layer (item) is already loaded
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py 2011-07-30 14:40:56 UTC (rev 47319)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py 2011-07-30 17:19:35 UTC (rev 47320)
@@ -479,8 +479,19 @@
"""!Create data (surface, vector, volume) settings page"""
self.mainPanelAppear = ScrolledPanel(parent = self)
self.mainPanelAppear.SetupScrolling(scroll_x = False)
- self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
- style = fpb.FPB_SINGLE_FOLD)
+
+ try:# wxpython <= 2.8.10
+ self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
+ style = fpb.FPB_DEFAULT_STYLE,
+ extraStyle = fpb.FPB_SINGLE_FOLD)
+ except:
+ try:# wxpython >= 2.8.11
+ self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
+ agwStyle = fpb.FPB_SINGLE_FOLD)
+ except: # to be sure
+ self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
+ style = fpb.FPB_SINGLE_FOLD)
+
self.foldpanelAppear.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
# light page
lightPanel = self.foldpanelAppear.AddFoldPanel(_("Lighting"), collapsed = False)
@@ -1311,6 +1322,7 @@
maps = list()
for layer in self.mapWindow.Map.GetListOfLayers(l_type = ltype, l_active = True):
maps.append(layer.GetName())
+ maps.append('aaaaaaaa')
return maps, exclude
def _createVolumePage(self, parent):
@@ -1735,13 +1747,13 @@
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):")),
+ label = _("Arrow length (in map units):")),
pos = (0,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
sizeCtrl = NumTextCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), style = wx.TE_PROCESS_ENTER)
gridSizer.Add(sizeCtrl, pos = (0, 2))
self.win['decoration']['arrow']['size'] = sizeCtrl.GetId()
- sizeCtrl.Bind(wx.EVT_TEXT_ENTER, self.OnArrowProp)
- sizeCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnArrowProp)
+ sizeCtrl.Bind(wx.EVT_TEXT_ENTER, self.OnDecorationProp)
+ sizeCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnDecorationProp)
# color
gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
@@ -1751,12 +1763,13 @@
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)
+ color.Bind(csel.EVT_COLOURSELECT, self.OnDecorationProp)
# 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.Bind(wx.EVT_TOGGLEBUTTON, self.OnDecorationPlacement)
+ self.win['decoration']['arrow']['place'] = toggle.GetId()
toggle.SetName('placeArrow')
delete = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Delete"))
@@ -1766,7 +1779,48 @@
pageSizer.Add(item = naboxSizer, proportion = 0,
flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
border = 3)
-
+
+
+ # north arrow
+ self.win['decoration']['scalebar'] = {}
+ nabox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
+ label = " %s " % (_("Scale bar")))
+ 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 = _("Scale bar length (in map units):")),
+ pos = (0,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
+ sizeCtrl = NumTextCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), style = wx.TE_PROCESS_ENTER)
+ gridSizer.Add(sizeCtrl, pos = (0, 2))
+ self.win['decoration']['scalebar']['size'] = sizeCtrl.GetId()
+ sizeCtrl.Bind(wx.EVT_TEXT_ENTER, self.OnDecorationProp)
+ sizeCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnDecorationProp)
+
+ # color
+ gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+ label = _("Scale bar 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']['scalebar']['color'] = color.GetId()
+ color.Bind(csel.EVT_COLOURSELECT, self.OnDecorationProp)
+
+ # control
+ toggle = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("Place scalebar"))
+ 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))
+ 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)
panel.SetSizer(pageSizer)
panel.Layout()
panel.Fit()
@@ -3793,10 +3847,16 @@
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"""
+ def OnDecorationPlacement(self, event):
+ """!Place an arrow/scalebar by clicking on display"""
+ if event.GetId() == self.win['decoration']['arrow']['place']:
+ type = 'arrow'
+ elif event.GetId() == self.win['decoration']['scalebar']['place']:
+ type = 'scalebar'
+ else: return
+
if event.GetInt():
- self.mapWindow.mouse['use'] = 'arrow'
+ self.mapWindow.mouse['use'] = type
self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
else:
self.mapWindow.mouse['use'] = 'default'
@@ -3807,21 +3867,48 @@
self._display.DeleteArrow()
self.mapWindow.decoration['arrow']['show'] = False
self.mapWindow.Refresh(False)
+
+ def OnScalebarDelete(self, event):
+ """!Delete scalebar"""
+ try:
+ id = self.mapWindow.decoration['scalebar'][-1]['id']
+ except IndexError:
+ return
+ self._display.DeleteScalebar(id = id)
+ del self.mapWindow.decoration['scalebar'][-1]
- def OnArrowProp(self, event):
- """!Set arrow properties"""
- color = self.FindWindowById(self.win['decoration']['arrow']['color']).GetValue()
- self.mapWindow.decoration['arrow']['color'] = self._getColorString(color)
+ self.mapWindow.Refresh(False)
+
+ def OnDecorationProp(self, event):
+ """!Set arrow/scalebar properties"""
+ if event.GetId() in self.win['decoration']['arrow'].values():
+ type = 'arrow'
+ elif event.GetId() in self.win['decoration']['scalebar'].values():
+ type = 'scalebar'
+ else: return
- size = self.FindWindowById(self.win['decoration']['arrow']['size']).GetValue()
- self.mapWindow.decoration['arrow']['size'] = size
+ color = self.FindWindowById(self.win['decoration'][type]['color']).GetValue()
+ size = self.FindWindowById(self.win['decoration'][type]['size']).GetValue()
+ if type == 'arrow':
+ 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
- if self.mapWindow.decoration['arrow']['show']:
+ if type == 'arrow' and 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()
+ 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'])
+ self._display.DrawScalebar()
self.mapWindow.Refresh(False)
def UpdatePage(self, pageId):
@@ -3887,6 +3974,8 @@
elif pageId == 'decoration':
win = self.FindWindowById(self.win['decoration']['arrow']['size'])
win.SetValue(self.mapWindow.decoration['arrow']['size'])
+ win = self.FindWindowById(self.win['decoration']['scalebar']['size'])
+ win.SetValue(self.mapWindow._getDecorationSize())
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-30 14:40:56 UTC (rev 47319)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2011-07-30 17:19:35 UTC (rev 47320)
@@ -603,6 +603,9 @@
},
'arrow': {
'color': (0, 0, 0),
+ },
+ 'scalebar': {
+ 'color': (0, 0, 0),
}
},
'modeler' : {
@@ -710,11 +713,12 @@
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
+ for decor in ('arrow', 'scalebar'):
+ self.internalSettings['nviz'][decor] = {}
+ self.internalSettings['nviz'][decor]['position'] = {}
+ self.internalSettings['nviz'][decor]['position']['x'] = 0
+ self.internalSettings['nviz'][decor]['position']['y'] = 0
+ self.internalSettings['nviz'][decor]['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-30 14:40:56 UTC (rev 47319)
+++ grass/trunk/gui/wxpython/gui_modules/workspace.py 2011-07-30 17:19:35 UTC (rev 47320)
@@ -807,18 +807,26 @@
return (value, desc)
- def SetDecorDefaultProp(self):
+ def SetDecorDefaultProp(self, type):
"""!Set default arrow properties
"""
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
+ if type == '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
+ # arrow
+ if type == 'scalebar':
+ data['scalebar'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar'))
+ data['scalebar']['color'] = "%d:%d:%d" % (
+ UserSettings.Get(group = 'nviz', key = 'scalebar', subkey = 'color')[:3])
+ data['scalebar'].update(copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar', internal = True)))
+ data['scalebar']['id'] = 0
return data
class WriteWorkspaceFile(object):
Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-07-30 14:40:56 UTC (rev 47319)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-07-30 17:19:35 UTC (rev 47320)
@@ -1637,10 +1637,30 @@
return Nviz_set_arrow(self.data, sx, sy, size, Nviz_color_from_str(color))
def DeleteArrow(self):
- """!Delete draw north arrow
+ """!Delete north arrow
"""
Nviz_delete_arrow(self.data)
+
+ def SetScalebar(self, id, sx, sy, size, color):
+ """!Set scale bar from canvas coordinates
+ @param sx,sy canvas coordinates
+ @param id scale bar id
+ @param size scale bar length
+ @param color scale bar color
+ """
+ return Nviz_set_scalebar(self.data, id, sx, sy, size, Nviz_color_from_str(color))
+
+## def DrawScalebar(self):
+## """!Draw scale bar
+## """
+## return Nviz_draw_scalebar(self.data)
+
+ def DeleteScalebar(self, id):
+ """!Delete scalebar
+ """
+ Nviz_delete_scalebar(self.data, id)
+
def GetPointOnSurface(self, sx, sy):
"""!Get point on surface
@@ -1686,4 +1706,3 @@
byref(d), int(useExag))
return d.value
-
Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h 2011-07-30 14:40:56 UTC (rev 47319)
+++ grass/trunk/include/nviz.h 2011-07-30 17:19:35 UTC (rev 47320)
@@ -87,6 +87,14 @@
float where[3];
};
+struct scalebar_data
+{
+ int id;
+ unsigned long color;
+ float size;
+ float where[3];
+};
+
typedef struct
{
/* ranges */
@@ -109,6 +117,10 @@
int draw_arrow;
struct arrow_data *arrow;
+ /* scalebar */
+ int num_scalebars;
+ struct scalebar_data **scalebar;
+
/* background color */
int bgcolor;
@@ -200,6 +212,10 @@
int Nviz_draw_arrow(nv_data *);
int Nviz_set_arrow(nv_data *, int, int, float, unsigned int);
void Nviz_delete_arrow(nv_data *);
+struct scalebar_data * Nviz_new_scalebar(nv_data *, int, float *, float, unsigned int);
+struct scalebar_data * Nviz_set_scalebar(nv_data *, int , int, int, float, unsigned int);
+void Nviz_draw_scalebar(nv_data *);
+void Nviz_delete_scalebar(nv_data *, int);
/* position.c */
void Nviz_init_view(nv_data *);
Modified: grass/trunk/lib/nviz/draw.c
===================================================================
--- grass/trunk/lib/nviz/draw.c 2011-07-30 14:40:56 UTC (rev 47319)
+++ grass/trunk/lib/nviz/draw.c 2011-07-30 17:19:35 UTC (rev 47320)
@@ -243,6 +243,12 @@
gsd_north_arrow(data->arrow->where, data->arrow->size,
(GLuint)NULL, data->arrow->color, data->arrow->color);
}
+
+ /* scale bar */
+ for (i = 0; i < data->num_scalebars; i++) {
+ struct scalebar_data *s = data->scalebar[i];
+ gsd_scalebar(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 2011-07-30 14:40:56 UTC (rev 47319)
+++ grass/trunk/lib/nviz/nviz.c 2011-07-30 17:19:35 UTC (rev 47320)
@@ -50,7 +50,11 @@
/* north arrow */
data->draw_arrow = 0;
data->arrow = NULL;
-
+
+ /* scale bar*/
+ data->num_scalebars = 0;
+ data->scalebar = NULL;
+
return;
}
@@ -73,7 +77,13 @@
data->arrow = NULL;
data->draw_arrow = 0;
}
-
+
+ for (i = 0; data->num_scalebars; i++) {
+ G_free(data->scalebar[i]);
+ data->scalebar[i] = NULL;
+ }
+ data->num_scalebars = 0;
+ data->scalebar = NULL;
}
/*!
@@ -306,3 +316,119 @@
return;
}
+
+/*! Add new scalebar
+
+ \param data nviz data
+ \param bar_id scale bar id
+ \param coords real(?) coordinates
+ \param size scale bar length
+ \param color scalebar/text color
+
+ \return pointer to allocated scalebar_data structure
+ \return NULL on error
+*/
+
+struct scalebar_data *Nviz_new_scalebar(nv_data *data,
+ int bar_id, float *coords, float size,
+ unsigned int color)
+{
+ struct scalebar_data *s;
+
+
+ s = (struct scalebar_data *) G_malloc(sizeof(struct scalebar_data));
+ 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];
+
+ data->scalebar = (struct scalebar_data **) G_realloc(data->scalebar,
+ data->num_scalebars + 1 * sizeof(struct scalebar_data *));
+ data->scalebar[data->num_scalebars++] = s;
+
+ return s;
+
+}
+/*!
+ \brief Sets the scale bar position and return world coords
+
+ \param data nviz data
+ \param bar_id scale bar id
+ \param sx,sy screen coordinates
+ \param size scale bar length
+ \param color scalebar/text color
+
+ \return pointer to allocated scalebar_data structure
+ \return NULL when there's no surface
+ */
+struct scalebar_data *Nviz_set_scalebar(nv_data *data, int bar_id,
+ int sx, int sy, float size,
+ unsigned int color)
+{
+ int i, id, pt[2];
+ int *surf_list, num_surfs;
+ float coords[3];
+ struct scalebar_data *s;
+
+ 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); /* 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];
+
+ return s;
+ }
+ }
+
+ s = Nviz_new_scalebar(data, bar_id, coords, size, color);
+
+ return s;
+ }
+ return NULL;
+}
+/*!
+ \brief Draws the Scale bar
+
+ \param data nviz data
+ */
+void Nviz_draw_scalebar(nv_data *data)
+{
+ int i;
+
+ 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];
+
+ gsd_scalebar(s->where, s->size, FontBase, s->color, s->color);
+ }
+}
+
+/*!
+ \brief Deletes scale bar
+
+ \param data nviz data
+ */
+void Nviz_delete_scalebar(nv_data *data, int bar_id)
+{
+ if (bar_id < data->num_scalebars) {
+ G_free(data->scalebar[bar_id]);
+ data->scalebar[bar_id] = NULL;
+ data->num_scalebars--;
+ }
+}
More information about the grass-commit
mailing list