Skip to content

Commit

Permalink
nvizlib: fringe implemented (including nviz_cmd and wxNviz)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42635 15284696-431f-4ddb-bdfa-cd5b030d7da7
  • Loading branch information
landam committed Jun 22, 2010
1 parent 3f13a50 commit 8b4483b
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 88 deletions.
6 changes: 6 additions & 0 deletions gui/wxpython/gui_modules/globalvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def CheckForWx():
FN.FNB_BACKGROUND_GRADIENT | \
FN.FNB_NODRAG | \
FN.FNB_TABS_BORDER_SIMPLE

FNPageDStyle = FN.FNB_FANCY_TABS | \
FN.FNB_BOTTOM | \
FN.FNB_NO_NAV_BUTTONS | \
FN.FNB_NO_X_BUTTON

FNPageColor = wx.Colour(125,200,175)

"""!Dialog widget dimension"""
Expand Down
1 change: 1 addition & 0 deletions gui/wxpython/gui_modules/nviz_mapdisp.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def OnPaint(self, event):
if layer:
if layer.type == 'raster':
self.lmgr.nviz.UpdatePage('surface')
self.lmgr.nviz.UpdatePage('fringe')
elif layer.type == 'vector':
self.lmgr.nviz.UpdatePage('vector')

Expand Down
153 changes: 139 additions & 14 deletions gui/wxpython/gui_modules/nviz_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from preferences import globalSettings as UserSettings
from preferences import PreferencesBaseDialog
from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties
from debug import Debug

import wxnviz
# sys.path.append(os.path.join(globalvar.ETCWXDIR, "nviz"))
Expand All @@ -62,22 +63,18 @@ def __init__(self, parent, display, id = wx.ID_ANY,

self.win = {} # window ids
self.page = {} # page ids

# view page
self.AddPage(page = self._createViewPage(),
text = " %s " % _("View"))
# surface page
self.AddPage(page = self._createSurfacePage(),
text = " %s " % _("Surface"))
# vector page
self.AddPage(page = self._createVectorPage(),
text = " %s " % _("Vector"))
# volume page
self.AddPage(page = self._createVolumePage(),
text = " %s " % _("Volume"))
# light page
self.AddPage(page = self._createLightPage(),
text = " %s " % _("Light"))

# data page
self.AddPage(page = self._createDataPage(),
text = " %s " % _("Data"))

# appearance page
self.AddPage(page = self._createAppearancePage(),
text = " %s " % _("Appearance"))

self.UpdateSettings()
self.pageChanging = False
Expand Down Expand Up @@ -257,6 +254,36 @@ def _createViewPage(self):

return panel

def _createDataPage(self):
"""!Create data (surface, vector, volume) settings page"""
self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
style = globalvar.FNPageDStyle)
# surface page
self.notebookData.AddPage(page = self._createSurfacePage(),
text = " %s " % _("Surface"))
# vector page
self.notebookData.AddPage(page = self._createVectorPage(),
text = " %s " % _("Vector"))
# volume page
self.notebookData.AddPage(page = self._createVolumePage(),
text = " %s " % _("Volume"))

return self.notebookData

def _createAppearancePage(self):
"""!Create data (surface, vector, volume) settings page"""
self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
style = globalvar.FNPageDStyle)
# light page
self.notebookAppearance.AddPage(page = self._createLightPage(),
text = " %s " % _("Lighting"))

# fringe page
self.notebookAppearance.AddPage(page = self._createFringePage(),
text = " %s " % _("Fringe"))

return self.notebookAppearance

def _createSurfacePage(self):
"""!Create view settings page"""
panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
Expand Down Expand Up @@ -1192,7 +1219,100 @@ def _createLightPage(self):
panel.SetSizer(pageSizer)

return panel

def _createFringePage(self):
"""!Create fringe page"""
panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
panel.SetupScrolling(scroll_x = False)

self.page['fringe'] = { 'id' : 2 }
self.win['fringe'] = {}

pageSizer = wx.BoxSizer(wx.VERTICAL)

# selection
rbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
label = " %s " % (_("Surface")))
rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
rmaps = gselect.Select(parent = panel, type = 'raster',
onPopup = self.GselectOnPopup)
self.win['fringe']['surface'] = rmaps.GetId()
rboxSizer.Add(item = rmaps, proportion = 0,
flag = wx.ALL,
border = 3)
pageSizer.Add(item = rboxSizer, proportion = 0,
flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
border = 3)

ebox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
label = " %s " % (_("Edges with fringe")))
eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
for edge in [(_("N && W"), "nw"),
(_("N && E"), "ne"),
(_("S && W"), "sw"),
(_("S && E"), "se")]:
chkbox = wx.CheckBox(parent = panel,
label = edge[0],
name = edge[1])
eboxSizer.Add(item = chkbox, proportion = 0,
flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT, border = 5)
chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)

pageSizer.Add(item = eboxSizer, proportion = 0,
flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
border = 3)

sbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
label = " %s " % (_("Settings")))
sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)

# elevation
gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
label = _("Elevation of fringe from bottom:")),
pos = (0, 0),
flag = wx.ALIGN_CENTER_VERTICAL)
spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
size = (65, -1), min = -1e6, max = 1e6)
spin.SetValue(UserSettings.Get(group = 'nviz', key = 'fringe', subkey = 'elev'))
self.win['fringe']['elev'] = spin.GetId()
gridSizer.Add(item = spin, pos = (0, 1))

# color
gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
label = _("Color:")),
pos = (1, 0),
flag = wx.ALIGN_CENTER_VERTICAL)
color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
size = globalvar.DIALOG_COLOR_SIZE)
color.SetColour(UserSettings.Get(group = 'nviz', key = 'fringe',
subkey = 'color'))
self.win['fringe']['color'] = color.GetId()
gridSizer.Add(item = color, pos = (1, 1))

sboxSizer.Add(item = gridSizer, proportion = 1,
flag = wx.ALL | wx.EXPAND, border = 3)
pageSizer.Add(item = sboxSizer, proportion = 0,
flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
border = 3)

panel.SetSizer(pageSizer)

return panel

def OnFringe(self, event):
"""!Show/hide fringe"""
enabled = event.IsChecked()
win = self.FindWindowById(event.GetId())
print win.GetName()
data = self.mapWindow.GetSelectedLayer(type = 'nviz')['surface']
sid = data['object']['id']
elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
color = self.FindWindowById(self.win['fringe']['color']).GetValue()

self._display.SetFringe(sid, color, elev, True, True, True, True)
self.mapWindow.Refresh(False)

def OnScroll(self, event, win, data):
"""!Generic scrolling handler"""
winName = self.__GetWindowName(win, event.GetId())
Expand Down Expand Up @@ -2262,6 +2382,7 @@ def UpdatePage(self, pageId):
self.pageChanging = True
layer = self.mapWindow.GetSelectedLayer()
data = self.mapWindow.GetSelectedLayer(type = 'nviz')
Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)

if pageId == 'view':
self.SetPage('view')
Expand Down Expand Up @@ -2299,7 +2420,11 @@ def UpdatePage(self, pageId):
self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)

elif pageId == 'fringe':
mapLayer = self.mapWindow.GetSelectedLayer()
win = self.FindWindowById(self.win['fringe']['surface'])
win.SetValue(mapLayer.GetName())

self.Update()
self.pageChanging = False

Expand Down
4 changes: 4 additions & 0 deletions gui/wxpython/gui_modules/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ def __init__(self):
'bright' : 80,
'ambient' : 20,
},
'fringe' : {
'elev' : 55,
'color' : (128, 128, 128, 255), # grey
},
},
'modeler' : {
'action' : {
Expand Down
16 changes: 15 additions & 1 deletion gui/wxpython/gui_modules/wxnviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def GetSurfacePosition(self, id):
GS_get_trans(id, byref(x), byref(y), byref(z))

Debug.msg(3, "Nviz::GetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
id, x, y, z)
id, x.value, y.value, z.value)

return [x.value, y.value, z.value]

Expand Down Expand Up @@ -1119,3 +1119,17 @@ def DrawLightingModel(self):
"""!Draw lighting model"""
if self.showLight:
GS_draw_lighting_model()

def SetFringe(self, sid, color, elev, nw = False, ne = False, sw = False, se = False):
"""!Set fringe
@param sid surface id
@param color color
@param elev elevation (height)
@param nw,ne,sw,se fringe edges (turn on/off)
"""
scolor = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
Nviz_new_fringe(self.data,
sid, Nviz_color_from_str(scolor),
elev, int(nw), int(ne), int(sw), int(se))

9 changes: 2 additions & 7 deletions gui/wxpython/wxgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,10 @@ def __init__(self, parent, id=wx.ID_ANY, title=_("GRASS GIS Layer Manager"),

def __createNoteBook(self):
"""!Creates notebook widgets"""
nbStyle = FN.FNB_FANCY_TABS | \
FN.FNB_BOTTOM | \
FN.FNB_NO_NAV_BUTTONS | \
FN.FNB_NO_X_BUTTON

if globalvar.hasAgw:
self.notebook = FN.FlatNotebook(parent=self, id=wx.ID_ANY, agwStyle = nbStyle)
self.notebook = FN.FlatNotebook(parent=self, id=wx.ID_ANY, agwStyle = globalvar.FNPageDStyle)
else:
self.notebook = FN.FlatNotebook(parent=self, id=wx.ID_ANY, style = nbStyle)
self.notebook = FN.FlatNotebook(parent=self, id=wx.ID_ANY, style = globalvar.FNPageDStyle)

# create displays notebook widget and add it to main notebook page
cbStyle = globalvar.FNPageStyle
Expand Down
42 changes: 16 additions & 26 deletions include/nviz.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ typedef struct
float x, y, z, w; /* position */
} light_data;

struct fringe_data
{
int id;
unsigned long color;
float elev;
int where[4];
};

typedef struct
{
/* ranges */
Expand All @@ -89,37 +97,16 @@ typedef struct

/* light */
light_data light[MAX_LIGHTS];


/* fringe */
int num_fringes;
struct fringe_data **fringe;

/* background color */
int bgcolor;

} nv_data;

/* The following structure is used to associate client data with surfaces.
* We do this so that we don't have to rely on the surface ID (which is libal to change
* between subsequent executions of nviz) when saving set-up info to files.
*/

typedef struct
{
/* We use logical names to assign textual names to map objects.
When Nviz needs to refer to a map object it uses the logical name
rather than the map ID. By setting appropriate logical names, we
can reuse names inbetween executions of Nviz. The Nviz library
also provides a mechanism for aliasing between logical names.
Thus several logical names may refer to the same map object.
Aliases are meant to support the case in which two logical names
happen to be the same. The Nviz library automatically assigns
logical names uniquely if they are not specified in the creation
of a map object. When loading a saved file containing several map
objects, it is expected that the map 0bjects will be aliased to
their previous names. This ensures that old scripts will work.
*/

char *logical_name;

} nv_clientdata;

struct render_window
{
#if defined(OPENGL_X11)
Expand Down Expand Up @@ -182,8 +169,11 @@ int Nviz_unset_attr(int, int, int);

/* nviz.c */
void Nviz_init_data(nv_data *);
void Nviz_destroy_data(nv_data *);
void Nviz_set_bgcolor(nv_data *, int);
int Nviz_color_from_str(const char *);
struct fringe_data *Nviz_new_fringe(nv_data *, int, unsigned long,
double, int, int, int, int);

/* position.c */
void Nviz_init_view(nv_data *);
Expand Down
8 changes: 7 additions & 1 deletion lib/nviz/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ int Nviz_draw_all_vol()
*/
int Nviz_draw_all(nv_data * data)
{
int i;
int draw_surf, draw_vect, draw_site, draw_vol;

draw_surf = 1;
draw_vect = 1;
draw_site = 1;
Expand Down Expand Up @@ -232,6 +233,11 @@ int Nviz_draw_all(nv_data * data)
if (draw_vol)
Nviz_draw_all_vol(data);

for(i = 0; i < data->num_fringes; i++) {
struct fringe_data * f = data->fringe[i];
GS_draw_fringe(f->id, f->color, f->elev, f->where);
}

GS_done_draw();
GS_set_draw(GSD_BACK);

Expand Down
Loading

0 comments on commit 8b4483b

Please sign in to comment.