[GRASS-SVN] r31919 - in grass-addons/visualization/nviz2: lib
wxpython wxpython/nviz
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 1 06:13:16 EDT 2008
Author: martinl
Date: 2008-07-01 06:13:16 -0400 (Tue, 01 Jul 2008)
New Revision: 31919
Modified:
grass-addons/visualization/nviz2/lib/draw.c
grass-addons/visualization/nviz2/lib/nviz.h
grass-addons/visualization/nviz2/wxpython/nviz.py
grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i
grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp
grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp
Log:
nviz2/wxGUI: draw mode fixed
Modified: grass-addons/visualization/nviz2/lib/draw.c
===================================================================
--- grass-addons/visualization/nviz2/lib/draw.c 2008-07-01 08:18:17 UTC (rev 31918)
+++ grass-addons/visualization/nviz2/lib/draw.c 2008-07-01 10:13:16 UTC (rev 31919)
@@ -50,7 +50,7 @@
G_free (surf_list);
-/* re-initialize lights */
+ /* re-initialize lights */
GS_setlight_position(num, x, y, z, w);
num = 2;
GS_setlight_position(num, 0., 0., 1., 0);
@@ -123,7 +123,7 @@
blanking maps during specific frames.
\param map_id map object id
-
+
\return 0 not blank
\return 1 blank
*/
@@ -132,7 +132,13 @@
return 0;
}
-int Nviz_draw_all(nv_data *data)
+/*!
+ \brief Draw all
+
+ \param data nviz data
+ \param clear clear screen before drawing
+*/
+int Nviz_draw_all(nv_data *data, int clear)
{
int draw_surf, draw_vect, draw_site, draw_vol;
int draw_north_arrow, arrow_x, draw_label, draw_legend;
@@ -160,7 +166,8 @@
// Tcl_SetVar(interp, "is_drawing", "1", TCL_GLOBAL_ONLY);
GS_set_draw(GSD_BACK); /* needs to be BACK to avoid flickering */
- GS_clear(data->bgcolor);
+ if (clear)
+ GS_clear(data->bgcolor);
GS_ready_draw();
/*
@@ -292,14 +299,28 @@
return 1;
}
-int Nviz_draw_quick(nv_data *dc)
+/*!
+ \brief Draw in coarse mode
+
+ \param dc nviz data
+ \param clear clear screen before drawing
+ \return 1
+*/
+int Nviz_draw_quick(nv_data *dc, int clear)
{
int i, max;
int *surf_list, *vol_list;
GS_set_draw(GSD_BACK);
- GS_clear(dc->bgcolor);
+
+ if (clear)
+ GS_clear(dc->bgcolor);
+
GS_ready_draw();
+
+ GS_alldraw_wire();
+
+ /*
surf_list = GS_get_surf_list(&max);
max = GS_num_surfs();
@@ -310,7 +331,8 @@
}
G_free (surf_list);
-
+ */
+
/*
vol_list = GVL_get_vol_list(&max);
max = GVL_num_vols();
@@ -372,14 +394,12 @@
- DRAW_FINE
- DRAW_BOTH
+ \param data nviz data
\param mode draw mode
*/
void Nviz_set_draw_mode(nv_data *data, int mode)
{
- if (mode == DRAW_COARSE) {
- data->draw_coarse = 1;
- }
- else {
- data->draw_coarse = 0;
- }
+ data->draw_mode = mode;
+
+ return;
}
Modified: grass-addons/visualization/nviz2/lib/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/lib/nviz.h 2008-07-01 08:18:17 UTC (rev 31918)
+++ grass-addons/visualization/nviz2/lib/nviz.h 2008-07-01 10:13:16 UTC (rev 31919)
@@ -83,7 +83,7 @@
int bgcolor;
/* draw */
- int draw_coarse;
+ int draw_mode;
} nv_data;
/* The following structure is used to associate client data with surfaces.
@@ -135,8 +135,8 @@
/* draw.c */
int Nviz_draw_all_surf(nv_data *);
-int Nviz_draw_all(nv_data *);
-int Nviz_draw_quick(nv_data *);
+int Nviz_draw_all(nv_data *, int);
+int Nviz_draw_quick(nv_data *, int);
int Nviz_draw_all_vect(nv_data *);
void Nviz_set_draw_mode(nv_data *, int);
Modified: grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i 2008-07-01 08:18:17 UTC (rev 31918)
+++ grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i 2008-07-01 10:13:16 UTC (rev 31919)
@@ -25,3 +25,19 @@
#define DRAW_COARSE 0
#define DRAW_FINE 1
#define DRAW_BOTH 2
+
+/* extracted from include/gsurf.h */
+#define DM_GOURAUD 0x00000100
+#define DM_FLAT 0x00000200
+
+#define DM_FRINGE 0x00000010
+
+#define DM_WIRE 0x00000001
+#define DM_COL_WIRE 0x00000002
+#define DM_POLY 0x00000004
+#define DM_WIRE_POLY 0x00000008
+
+#define DM_GRID_WIRE 0x00000400
+#define DM_GRID_SURF 0x00000800
+
+#define WC_COLOR_ATT 0xFF000000
Modified: grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp 2008-07-01 08:18:17 UTC (rev 31918)
+++ grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp 2008-07-01 10:13:16 UTC (rev 31919)
@@ -22,31 +22,31 @@
/*!
\brief Draw map
- \param quick true for quick rendering
+ \param quick true for forcing coarse draw mode
*/
void Nviz::Draw(bool quick)
{
- GS_clear(data->bgcolor);
-
- Nviz_draw_cplane(data, -1, -1);
- if (data->draw_coarse) { /* coarse */
- GS_set_draw(GSD_BACK);
- GS_ready_draw();
- GS_alldraw_wire();
- GS_done_draw();
+ Nviz_draw_cplane(data, -1, -1); // ?
- G_debug(1, "Nviz::Draw(): mode=coarse");
+ if (data->draw_mode == DRAW_COARSE ||
+ data->draw_mode == DRAW_BOTH || quick) {
+ Nviz_draw_quick(data, 1); // clear screen
}
- else { /* fine / both */
- if (!quick)
- Nviz_draw_all (data);
- else
- Nviz_draw_quick(data); // ?
- G_debug(1, "Nviz::Draw(): mode=fine, quick=%d", quick);
+ if (data->draw_mode == DRAW_FINE ||
+ data->draw_mode == DRAW_BOTH) {
+ if (data->draw_mode == DRAW_FINE) {
+ Nviz_draw_all (data, 1); // clear screen
+ }
+ else {
+ Nviz_draw_all (data, 0);
+ }
}
+ G_debug(1, "Nviz::Draw(): mode=%d, quick=%d",
+ data->draw_mode, quick);
+
return;
}
Modified: grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/nviz.h 2008-07-01 08:18:17 UTC (rev 31918)
+++ grass-addons/visualization/nviz2/wxpython/nviz/nviz.h 2008-07-01 10:13:16 UTC (rev 31919)
@@ -80,6 +80,8 @@
int UnsetSurfaceTransp(int);
int UnsetSurfaceEmit(int);
int SetSurfaceRes(int, int, int);
+ int SetSurfaceStyle(int, int);
+ int SetWireColor(int, const char *);
};
#endif /* __NVIZ_H__ */
Modified: grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp 2008-07-01 08:18:17 UTC (rev 31918)
+++ grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp 2008-07-01 10:13:16 UTC (rev 31919)
@@ -221,3 +221,49 @@
{
return GS_set_drawres(id, fine, fine, coarse, coarse);
}
+
+/*!
+ \brief Set draw style
+
+ Draw styles:
+ - DM_GOURAUD
+ - DM_FLAT
+ - DM_FRINGE
+ - DM_WIRE
+ - DM_COL_WIRE
+ - DM_POLY
+ - DM_WIRE_POLY
+ - DM_GRID_WIRE
+ - DM_GRID_SURF
+
+ \param id surface id (<= 0 for all)
+ \param style draw style
+
+ \return 0 on success
+ \return -1 on error
+*/
+int Nviz::SetSurfaceStyle(int id, int style)
+{
+ if (id > 0) {
+ return GS_set_drawmode(id, style);
+ }
+
+ return GS_setall_drawmode(style);
+}
+
+/*!
+ \brief Set color of wire
+
+ \todo all
+
+ \param surface id
+ \param color color string (R:G:B)
+
+ \return 1
+*/
+int Nviz::SetWireColor(int id, const char* color)
+{
+ GS_set_wire_color(id, Nviz_color_from_str(color));
+
+ return 1;
+}
Modified: grass-addons/visualization/nviz2/wxpython/nviz.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz.py 2008-07-01 08:18:17 UTC (rev 31918)
+++ grass-addons/visualization/nviz2/wxpython/nviz.py 2008-07-01 10:13:16 UTC (rev 31919)
@@ -243,10 +243,11 @@
self.nvizClass.SetZExag(self.view['z-exag']['value'])
del self.update['z-exag']
- if render is True:
- self.nvizClass.Draw(False)
- elif render is False:
- self.nvizClass.Draw(True) # quick
+ # if render is True:
+ # self.nvizClass.Draw(False)
+ # elif render is False:
+ # self.nvizClass.Draw(True) # quick
+ self.nvizClass.Draw(False)
self.SwapBuffers()
@@ -268,8 +269,6 @@
Debug.msg(3, "GLWindow.UpdateMap(): render=%s, -> time=%g" % \
(render, (stop-start)))
- print '# %.6f' % (stop-start)
-
def EraseMap(self):
"""
Erase the canvas
@@ -689,7 +688,7 @@
_("surface")])
style.SetName("selection")
self.win['surface']['draw']['style'] = style.GetId()
- style.Bind(wx.EVT_CHOICE, self.OnSurfaceStyle)
+ style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
gridSizer.Add(item=style, flag=wx.ALIGN_CENTER_VERTICAL,
pos=(1, 1))
@@ -702,7 +701,7 @@
_("gouraud")])
shade.SetName("selection")
self.win['surface']['draw']['shading'] = shade.GetId()
- shade.Bind(wx.EVT_CHOICE, self.OnSurfaceShade)
+ shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
gridSizer.Add(item=shade, flag=wx.ALIGN_CENTER_VERTICAL,
pos=(1, 3))
@@ -710,9 +709,9 @@
gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
label=_("Wire color:")),
pos=(2, 0), flag=wx.ALIGN_CENTER_VERTICAL)
- color = csel.ColourSelect(panel, id=wx.ID_ANY,
- colour="white")
+ color = csel.ColourSelect(panel, id=wx.ID_ANY)
color.SetName("colour")
+ color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
self.win['surface']['draw']['color'] = color.GetId()
gridSizer.Add(item=color, flag=wx.ALIGN_CENTER_VERTICAL,
pos=(2, 1))
@@ -1030,11 +1029,11 @@
del self.mapWindow.update[attrb]
- # drawing mode
+ # draw mode
if self.mapWindow.update.has_key('draw-mode'):
self.mapWindow.nvizClass.SetDrawMode(self.mapWindow.update['draw-mode'])
- # drawing res
+ # draw res
if self.mapWindow.update.has_key('draw-res'):
mode, res = self.mapWindow.update['draw-res']
if mode == 0: # coarse
@@ -1048,6 +1047,16 @@
self.mapWindow.nvizClass.SetSurfaceRes(id, fine, coarse)
+ # draw style
+ if self.mapWindow.update.has_key('draw-style'):
+ self.mapWindow.nvizClass.SetSurfaceStyle(id, self.mapWindow.update['draw-style'])
+
+ # wire color
+ if self.mapWindow.update.has_key('draw-color'):
+ print self.mapWindow.update['draw-color']
+ self.mapWindow.nvizClass.SetWireColor(id, str(self.mapWindow.update['draw-color']))
+
+
self.mapWindow.Refresh(False)
def OnClose(self, event):
@@ -1141,42 +1150,71 @@
if self.parent.autoRender.IsChecked():
self.OnApply(None)
- def OnSurfaceMode(self, event):
- """Drawing mode changed"""
- self.SetSurfaceMode(event.GetSelection())
- event.Skip()
+ def OnSurfaceResolution(self, event):
+ """Draw resolution changed"""
+ value = event.GetInt()
+ mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
+
+ self.mapWindow.update['draw-res'] = (mode, value)
- def SetSurfaceMode(self, selection):
- """Set drawing mode and resolution"""
- if selection == 0: # coarse
+ if self.parent.autoRender.IsChecked():
+ self.OnApply(None)
+
+ def SetSurfaceMode(self):
+ """Set draw mode"""
+ value = 0
+
+ mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
+ if mode == 0: # coarse
+ value |= wxnviz.DM_WIRE
self.mapWindow.update['draw-mode'] = wxnviz.DRAW_COARSE
self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(False)
- elif selection == 1: # fine
+ elif mode == 1: # fine
+ value |= wxnviz.DM_POLY
self.mapWindow.update['draw-mode'] = wxnviz.DRAW_FINE
self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(False)
self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
- elif selection == 2: # both
+ else: # both
+ value |= wxnviz.DM_WIRE_POLY
self.mapWindow.update['draw-mode'] = wxnviz.DRAW_BOTH
self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
- def OnSurfaceResolution(self, event):
- """Draw resolution changed"""
- value = event.GetInt()
- mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
-
- self.mapWindow.update['draw-res'] = (mode, value)
+ style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
+ if style == 0: # wire
+ value |= wxnviz.DM_GRID_WIRE
+ else: # surface
+ value |= wxnviz.DM_GRID_SURF
+ shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
+ if shade == 0:
+ value |= wxnviz.DM_FLAT
+ else: # surface
+ value |= wxnviz.DM_GOURAUD
+
+ self.mapWindow.update['draw-style'] = value
+
if self.parent.autoRender.IsChecked():
self.OnApply(None)
- def OnSurfaceStyle(self, event):
- pass
+ def OnSurfaceMode(self, event):
+ """Set draw mode"""
+ self.SetSurfaceMode()
- def OnSurfaceShade(self, event):
- pass
+ def SetSurfaceWireColor(self, color):
+ """Set wire color"""
+ value = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
+ self.mapWindow.update['draw-color'] = value
+
+ if self.parent.autoRender.IsChecked():
+ self.OnApply(None)
+
+ def OnSurfaceWireColor(self, event):
+ """Set wire color"""
+ self.SetSurfaceWireColor(event.GetValue())
+
def UpdatePage(self, pageId):
"""Update dialog (selected page)"""
layer = self.mapWindow.GetSelectedLayer()
@@ -1213,9 +1251,10 @@
win.SetColour(value)
else:
win.SetValue(value)
- # enable/disable res widget
- mode = self.FindWindowById(self.win['surface']['draw']['mode'])
- self.SetSurfaceMode(mode.GetSelection())
+ # enable/disable res widget + set draw mode
+ self.SetSurfaceMode()
+ color = self.FindWindowById(self.win['surface']['draw']['color'])
+ self.SetSurfaceWireColor(color.GetColour())
elif layer.type == 'raster':
# surface attributes
More information about the grass-commit
mailing list