[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10555 - gnuradio/branches/developers/jblum/gui_guts/g
From: |
jblum |
Subject: |
[Commit-gnuradio] r10555 - gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter |
Date: |
Tue, 3 Mar 2009 00:34:05 -0700 (MST) |
Author: jblum
Date: 2009-03-03 00:34:04 -0700 (Tue, 03 Mar 2009)
New Revision: 10555
Added:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/grid_plotter_base.py
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/Makefile.am
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/bar_plotter.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/common.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/waterfall_plotter.py
Log:
WIP! Separated grid plotter.
Poke cache object on resize.
Better cache (compiled list) interface.
Padding is auto-calculated.
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/Makefile.am
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/Makefile.am
2009-03-03 02:27:36 UTC (rev 10554)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/Makefile.am
2009-03-03 07:34:04 UTC (rev 10555)
@@ -34,6 +34,7 @@
channel_plotter.py \
common.py \
gltext.py \
+ grid_plotter_base.py \
plotter_base.py \
waterfall_plotter.py
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/bar_plotter.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/bar_plotter.py
2009-03-03 02:27:36 UTC (rev 10554)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/bar_plotter.py
2009-03-03 07:34:04 UTC (rev 10555)
@@ -20,14 +20,14 @@
#
import wx
-from plotter_base import grid_plotter_base
+from grid_plotter_base import grid_plotter_base
from OpenGL import GL
import common
import numpy
LEGEND_TEXT_FONT_SIZE = 8
LEGEND_BOX_PADDING = 3
-PADDING = 35, 15, 40, 60 #top, right, bottom, left
+MIN_PADDING = 0, 0, 0, 80 #top, right, bottom, left
#constants for the waveform storage
SAMPLES_KEY = 'samples'
COLOR_SPEC_KEY = 'color_spec'
@@ -44,13 +44,14 @@
Create a new bar plotter.
"""
#init
- grid_plotter_base.__init__(self, parent, PADDING)
+ grid_plotter_base.__init__(self, parent, MIN_PADDING)
self._bars = list()
self._bar_width = .5
self._color_spec = (0, 0, 0)
- #setup channel plotter
+ #setup bar cache
+ self._bar_cache = self.new_gl_cache(self._draw_bars)
+ #setup bar plotter
self.register_init(self._init_bar_plotter)
- self.register_draw(self._draw_bars)
def _init_bar_plotter(self):
"""
@@ -132,6 +133,7 @@
self._bars = bars
self._bar_width = bar_width
self._color_spec = color_spec
+ self._bar_cache.changed(True)
self.unlock()
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
2009-03-03 02:27:36 UTC (rev 10554)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
2009-03-03 07:34:04 UTC (rev 10555)
@@ -20,7 +20,7 @@
#
import wx
-from plotter_base import grid_plotter_base
+from grid_plotter_base import grid_plotter_base
from OpenGL import GL
import common
import numpy
@@ -29,7 +29,7 @@
LEGEND_TEXT_FONT_SIZE = 8
LEGEND_BOX_PADDING = 3
-PADDING = 35, 15, 40, 60 #top, right, bottom, left
+MIN_PADDING = 35, 10, 0, 0 #top, right, bottom, left
#constants for the waveform storage
SAMPLES_KEY = 'samples'
COLOR_SPEC_KEY = 'color_spec'
@@ -46,16 +46,15 @@
Create a new channel plotter.
"""
#init
- grid_plotter_base.__init__(self, parent, PADDING)
+ grid_plotter_base.__init__(self, parent, MIN_PADDING)
#setup legend cache
- self._legend_cache = common.gl_cache(self._draw_legend)
- self.register_init(self._legend_cache.init)
- self.register_draw(self._legend_cache.draw)
- #setup channel plotter
+ self._legend_cache = self.new_gl_cache(self._draw_legend, 50)
+ self.enable_legend(False)
+ #setup waveform cache
+ self._waveform_cache = self.new_gl_cache(self._draw_waveforms,
50)
self._channels = dict()
- self.enable_legend(False)
+ #init channel plotter
self.register_init(self._init_channel_plotter)
- self.register_draw(self._draw_waveforms)
def _init_channel_plotter(self):
"""
@@ -184,6 +183,7 @@
if channel in self._channels.keys():
self._channels.pop(channel)
self._legend_cache.changed(True)
+ self._waveform_cache.changed(True)
self.unlock()
def set_waveform(self, channel, samples=[], color_spec=(0, 0, 0),
marker=None, trig_off=0):
@@ -203,6 +203,7 @@
MARKERY_KEY: marker,
TRIG_OFF_KEY: trig_off,
}
+ self._waveform_cache.changed(True)
self.unlock()
if __name__ == '__main__':
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/common.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/common.py
2009-03-03 02:27:36 UTC (rev 10554)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/common.py
2009-03-03 07:34:04 UTC (rev 10555)
@@ -23,7 +23,6 @@
import time
import math
import wx
-from OpenGL import GL
##################################################
# Number formatting
@@ -129,47 +128,3 @@
last_coor = coor
last_ts = time.time()
except wx.PyDeadObjectError: pass
-
-##################################################
-# GL caching interface
-##################################################
-class gl_cache(object):
- """
- Cache a set of gl drawing routines in a compiled list.
- """
-
- def __init__(self, draw):
- """
- Create a new cache.
- @param draw a function to draw gl stuff
- """
- self.changed(True)
- self._draw = draw
-
- def init(self):
- """
- To be called when gl initializes.
- Create a new compiled list.
- """
- self._grid_compiled_list_id = GL.glGenLists(1)
-
- def draw(self):
- """
- Draw the gl stuff using a compiled list.
- If changed, reload the compiled list.
- """
- if self.changed():
- GL.glNewList(self._grid_compiled_list_id, GL.GL_COMPILE)
- self._draw()
- GL.glEndList()
- self.changed(False)
- #draw the grid
- GL.glCallList(self._grid_compiled_list_id)
-
- def changed(self, state=None):
- """
- Set the changed flag if state is not None.
- Otherwise return the changed flag.
- """
- if state is None: return self._changed
- self._changed = state
Copied:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/grid_plotter_base.py
(from rev 10547,
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py)
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/grid_plotter_base.py
(rev 0)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/grid_plotter_base.py
2009-03-03 07:34:04 UTC (rev 10555)
@@ -0,0 +1,357 @@
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+import wx
+import wx.glcanvas
+from OpenGL import GL
+import common
+from plotter_base import plotter_base
+import gltext
+import math
+
+GRID_LINE_COLOR_SPEC = (.7, .7, .7) #gray
+GRID_BORDER_COLOR_SPEC = (0, 0, 0) #black
+TICK_TEXT_FONT_SIZE = 9
+TITLE_TEXT_FONT_SIZE = 13
+UNITS_TEXT_FONT_SIZE = 9
+AXIS_LABEL_PADDING = 5
+TICK_LABEL_PADDING = 5
+TITLE_LABEL_PADDING = 7
+POINT_LABEL_FONT_SIZE = 8
+POINT_LABEL_COLOR_SPEC = (1, 1, .5)
+POINT_LABEL_PADDING = 3
+
+##################################################
+# Grid Plotter Base Class
+##################################################
+class grid_plotter_base(plotter_base):
+
+ def __init__(self, parent, min_padding=(0, 0, 0, 0)):
+ plotter_base.__init__(self, parent)
+ #setup grid cache
+ self._grid_cache = self.new_gl_cache(self._draw_grid, 25)
+ self.enable_grid_lines(True)
+ #setup padding
+ self.padding_top_min, self.padding_right_min,
self.padding_bottom_min, self.padding_left_min = min_padding
+ #store title and unit strings
+ self.set_title('Title')
+ self.set_x_label('X Label')
+ self.set_y_label('Y Label')
+ #init the grid to some value
+ self.set_x_grid(-1, 1, 1)
+ self.set_y_grid(-1, 1, 1)
+ #setup point label cache
+ self._point_label_cache =
self.new_gl_cache(self._draw_point_label, 75)
+ self.enable_point_label(False)
+ self.set_point_label_coordinate(None)
+ common.point_label_thread(self)
+
+ def set_point_label_coordinate(self, coor):
+ """
+ Set the point label coordinate.
+ @param coor the coordinate x, y tuple or None
+ """
+ self.lock()
+ self._point_label_coordinate = coor
+ self._point_label_cache.changed(True)
+ self.update()
+ self.unlock()
+
+ def enable_point_label(self, enable=None):
+ """
+ Enable/disable the point label.
+ @param enable true to enable
+ @return the enable state when None
+ """
+ if enable is None: return self._enable_point_label
+ self.lock()
+ self._enable_point_label = enable
+ self._point_label_cache.changed(True)
+ self.unlock()
+
+ def set_title(self, title):
+ """
+ Set the title.
+ @param title the title string
+ """
+ self.lock()
+ self.title = title
+ self._grid_cache.changed(True)
+ self.unlock()
+
+ def set_x_label(self, x_label, x_units=''):
+ """
+ Set the x label and units.
+ @param x_label the x label string
+ @param x_units the x units string
+ """
+ self.lock()
+ self.x_label = x_label
+ self.x_units = x_units
+ self._grid_cache.changed(True)
+ self.unlock()
+
+ def set_y_label(self, y_label, y_units=''):
+ """
+ Set the y label and units.
+ @param y_label the y label string
+ @param y_units the y units string
+ """
+ self.lock()
+ self.y_label = y_label
+ self.y_units = y_units
+ self._grid_cache.changed(True)
+ self.unlock()
+
+ def set_x_grid(self, minimum, maximum, step, scale=False):
+ """
+ Set the x grid parameters.
+ @param minimum the left-most value
+ @param maximum the right-most value
+ @param step the grid spacing
+ @param scale true to scale the x grid
+ """
+ self.lock()
+ self.x_min = float(minimum)
+ self.x_max = float(maximum)
+ self.x_step = float(step)
+ if scale:
+ coeff, exp, prefix =
common.get_si_components(max(abs(self.x_min), abs(self.x_max)))
+ self.x_scalar = 10**(-exp)
+ self.x_prefix = prefix
+ else:
+ self.x_scalar = 1.0
+ self.x_prefix = ''
+ self._grid_cache.changed(True)
+ self.unlock()
+
+ def set_y_grid(self, minimum, maximum, step, scale=False):
+ """
+ Set the y grid parameters.
+ @param minimum the bottom-most value
+ @param maximum the top-most value
+ @param step the grid spacing
+ @param scale true to scale the y grid
+ """
+ self.lock()
+ self.y_min = float(minimum)
+ self.y_max = float(maximum)
+ self.y_step = float(step)
+ if scale:
+ coeff, exp, prefix =
common.get_si_components(max(abs(self.y_min), abs(self.y_max)))
+ self.y_scalar = 10**(-exp)
+ self.y_prefix = prefix
+ else:
+ self.y_scalar = 1.0
+ self.y_prefix = ''
+ self._grid_cache.changed(True)
+ self.unlock()
+
+ def _draw_grid(self):
+ """
+ Create the x, y, tick, and title labels.
+ Resize the padding for the labels.
+ Draw the border, grid, title, and labels.
+ """
+ ##################################################
+ # Create GL text labels
+ ##################################################
+ #create x tick labels
+ x_tick_labels = [(tick, self._get_tick_label(tick,
self.x_units))
+ for tick in self._get_ticks(self.x_min, self.x_max,
self.x_step, self.x_scalar)]
+ #create x tick labels
+ y_tick_labels = [(tick, self._get_tick_label(tick,
self.y_units))
+ for tick in self._get_ticks(self.y_min, self.y_max,
self.y_step, self.y_scalar)]
+ #create x label
+ x_label_str = self.x_units and "%s (%s%s)"%(self.x_label,
self.x_prefix, self.x_units) or self.x_label
+ x_label = gltext.Text(x_label_str, bold=True,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
+ #create y label
+ y_label_str = self.y_units and "%s (%s%s)"%(self.y_label,
self.y_prefix, self.y_units) or self.y_label
+ y_label = gltext.Text(y_label_str, bold=True,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
+ #create title
+ title_label = gltext.Text(self.title, bold=True,
font_size=TITLE_TEXT_FONT_SIZE, centered=True)
+ ##################################################
+ # Resize the padding
+ ##################################################
+ self.padding_top = max(2*TITLE_LABEL_PADDING +
title_label.get_size()[1], self.padding_top_min)
+ self.padding_right = max(0, self.padding_right_min)
+ self.padding_bottom = max(2*AXIS_LABEL_PADDING +
TICK_LABEL_PADDING + x_label.get_size()[1] + max([label.get_size()[1] for tick,
label in x_tick_labels]), self.padding_bottom_min)
+ self.padding_left = max(2*AXIS_LABEL_PADDING +
TICK_LABEL_PADDING + y_label.get_size()[1] + max([label.get_size()[0] for tick,
label in y_tick_labels]), self.padding_left_min)
+ ##################################################
+ # Draw Grid X
+ ##################################################
+ GL.glColor3f(*GRID_LINE_COLOR_SPEC)
+ for tick, label in x_tick_labels:
+ scaled_tick =
(self.width-self.padding_left-self.padding_right)*\
+
(tick/self.x_scalar-self.x_min)/(self.x_max-self.x_min) + self.padding_left-1
+ self._draw_grid_line(
+ (scaled_tick, self.padding_top),
+ (scaled_tick, self.height-self.padding_bottom),
+ )
+ w, h = label.get_size()
+ label.draw_text(wx.Point(scaled_tick-w/2,
self.height-self.padding_bottom+TICK_LABEL_PADDING))
+ ##################################################
+ # Draw Grid Y
+ ##################################################
+ GL.glColor3f(*GRID_LINE_COLOR_SPEC)
+ for tick, label in y_tick_labels:
+ scaled_tick =
(self.height-self.padding_top-self.padding_bottom)*\
+ (1 -
(tick/self.y_scalar-self.y_min)/(self.y_max-self.y_min)) + self.padding_top
+ self._draw_grid_line(
+ (self.padding_left, scaled_tick),
+ (self.width-self.padding_right, scaled_tick),
+ )
+ w, h = label.get_size()
+
label.draw_text(wx.Point(self.padding_left-w-TICK_LABEL_PADDING,
scaled_tick-h/2))
+ ##################################################
+ # Draw Border
+ ##################################################
+ GL.glColor3f(*GRID_BORDER_COLOR_SPEC)
+ self._draw_rect(
+ self.padding_left,
+ self.padding_top,
+ self.width - self.padding_right - self.padding_left,
+ self.height - self.padding_top - self.padding_bottom,
+ fill=False,
+ )
+ ##################################################
+ # Draw Labels
+ ##################################################
+ #draw title label
+ title_label.draw_text(wx.Point(self.width/2.0,
TITLE_LABEL_PADDING + title_label.get_size()[1]/2))
+ #draw x labels
+ x_label.draw_text(wx.Point(
+
(self.width-self.padding_left-self.padding_right)/2.0 + self.padding_left,
+ self.height-(AXIS_LABEL_PADDING +
x_label.get_size()[1]/2),
+ )
+ )
+ #draw y labels
+ y_label.draw_text(wx.Point(
+ AXIS_LABEL_PADDING + y_label.get_size()[1]/2,
+
(self.height-self.padding_top-self.padding_bottom)/2.0 + self.padding_top,
+ ), rotation=90,
+ )
+
+ def _get_tick_label(self, tick, unit):
+ """
+ Format the tick value and create a gl text.
+ @param tick the floating point tick value
+ @param unit the axis unit
+ @return the tick label text
+ """
+ if unit: tick_str = common.sci_format(tick)
+ else: tick_str = common.eng_format(tick)
+ return gltext.Text(tick_str, font_size=TICK_TEXT_FONT_SIZE)
+
+ def _get_ticks(self, min, max, step, scalar):
+ """
+ Determine the positions for the ticks.
+ @param min the lower bound
+ @param max the upper bound
+ @param step the grid spacing
+ @param scalar the grid scaling
+ @return a list of tick positions between min and max
+ """
+ #cast to float
+ min = float(min)
+ max = float(max)
+ step = float(step)
+ #check for valid numbers
+ assert step > 0
+ assert max > min
+ assert max - min > step
+ #determine the start and stop value
+ start = int(math.ceil(min/step))
+ stop = int(math.floor(max/step))
+ return [i*step*scalar for i in range(start, stop+1)]
+
+ def enable_grid_lines(self, enable=None):
+ """
+ Enable/disable the grid lines.
+ @param enable true to enable
+ @return the enable state when None
+ """
+ if enable is None: return self._enable_grid_lines
+ self.lock()
+ self._enable_grid_lines = enable
+ self._grid_cache.changed(True)
+ self.unlock()
+
+ def _draw_grid_line(self, coor1, coor2):
+ """
+ Draw a dashed line from coor1 to coor2.
+ @param corr1 a tuple of x, y
+ @param corr2 a tuple of x, y
+ """
+ if not self.enable_grid_lines(): return
+ GL.glEnable(GL.GL_LINE_STIPPLE)
+ GL.glLineStipple(1, int("1110" + "0000" + "1110" + "0000", 2))
+ GL.glBegin(GL.GL_LINES)
+ GL.glVertex2f(*coor1)
+ GL.glVertex2f(*coor2)
+ GL.glEnd()
+ GL.glDisable(GL.GL_LINE_STIPPLE)
+
+ def _draw_rect(self, x, y, width, height, fill=True):
+ """
+ Draw a rectangle on the x, y plane.
+ X and Y are the top-left corner.
+ @param x the left position of the rectangle
+ @param y the top position of the rectangle
+ @param width the width of the rectangle
+ @param height the height of the rectangle
+ @param fill true to color inside of rectangle
+ """
+ GL.glBegin(fill and GL.GL_QUADS or GL.GL_LINE_LOOP)
+ GL.glVertex2f(x, y)
+ GL.glVertex2f(x+width, y)
+ GL.glVertex2f(x+width, y+height)
+ GL.glVertex2f(x, y+height)
+ GL.glEnd()
+
+ def _draw_point_label(self):
+ """
+ Draw the point label for the last mouse motion coordinate.
+ The mouse coordinate must be an X, Y tuple.
+ The label will be drawn at the X, Y coordinate.
+ The values of the X, Y coordinate will be scaled to the current
X, Y bounds.
+ """
+ if not self.enable_point_label(): return
+ if not self._point_label_coordinate: return
+ x, y = self._point_label_coordinate
+ if x < self.padding_left or x > self.width-self.padding_right:
return
+ if y < self.padding_top or y > self.height-self.padding_bottom:
return
+ #scale to window bounds
+ x_win_scalar = float(x -
self.padding_left)/(self.width-self.padding_left-self.padding_right)
+ y_win_scalar = float((self.height - y) -
self.padding_bottom)/(self.height-self.padding_top-self.padding_bottom)
+ #scale to grid bounds
+ x_val = x_win_scalar*(self.x_max-self.x_min) + self.x_min
+ y_val = y_win_scalar*(self.y_max-self.y_min) + self.y_min
+ #create text
+ label_str = self._populate_point_label(x_val, y_val)
+ if not label_str: return
+ txt = gltext.Text(label_str, font_size=POINT_LABEL_FONT_SIZE)
+ w, h = txt.get_size()
+ #draw rect + text
+ GL.glColor3f(*POINT_LABEL_COLOR_SPEC)
+ if x > self.width/2: x -= w+2*POINT_LABEL_PADDING
+ self._draw_rect(x, y-h-2*POINT_LABEL_PADDING,
w+2*POINT_LABEL_PADDING, h+2*POINT_LABEL_PADDING)
+ txt.draw_text(wx.Point(x+POINT_LABEL_PADDING,
y-h-POINT_LABEL_PADDING))
Property changes on:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/grid_plotter_base.py
___________________________________________________________________
Added: svn:mergeinfo
+
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
2009-03-03 02:27:36 UTC (rev 10554)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
2009-03-03 07:34:04 UTC (rev 10555)
@@ -23,26 +23,57 @@
import wx.glcanvas
from OpenGL import GL
import common
-import threading
-import gltext
-import math
-import time
BACKGROUND_COLOR_SPEC = (1, 0.976, 1, 1) #creamy white
-GRID_LINE_COLOR_SPEC = (.7, .7, .7) #gray
-GRID_BORDER_COLOR_SPEC = (0, 0, 0) #black
-TICK_TEXT_FONT_SIZE = 9
-TITLE_TEXT_FONT_SIZE = 13
-UNITS_TEXT_FONT_SIZE = 9
-TICK_LABEL_PADDING = 5
-POINT_LABEL_FONT_SIZE = 8
-POINT_LABEL_COLOR_SPEC = (1, 1, .5)
-POINT_LABEL_PADDING = 3
##################################################
+# GL caching interface
+##################################################
+class gl_cache(object):
+ """
+ Cache a set of gl drawing routines in a compiled list.
+ """
+
+ def __init__(self, draw):
+ """
+ Create a new cache.
+ @param draw a function to draw gl stuff
+ """
+ self.changed(True)
+ self._draw = draw
+
+ def init(self):
+ """
+ To be called when gl initializes.
+ Create a new compiled list.
+ """
+ self._grid_compiled_list_id = GL.glGenLists(1)
+
+ def draw(self):
+ """
+ Draw the gl stuff using a compiled list.
+ If changed, reload the compiled list.
+ """
+ if self.changed():
+ GL.glNewList(self._grid_compiled_list_id, GL.GL_COMPILE)
+ self._draw()
+ GL.glEndList()
+ self.changed(False)
+ #draw the grid
+ GL.glCallList(self._grid_compiled_list_id)
+
+ def changed(self, state=None):
+ """
+ Set the changed flag if state is not None.
+ Otherwise return the changed flag.
+ """
+ if state is None: return self._changed
+ self._changed = state
+
+##################################################
# OpenGL WX Plotter Canvas
##################################################
-class _plotter_base(wx.glcanvas.GLCanvas, common.mutex):
+class plotter_base(wx.glcanvas.GLCanvas, common.mutex):
"""
Plotter base class for all plot types.
"""
@@ -61,34 +92,55 @@
self._resized_flag = True
self._init_fcns = list()
self._draw_fcns = list()
+ self._gl_caches = list()
self.Bind(wx.EVT_PAINT, self._on_paint)
self.Bind(wx.EVT_SIZE, self._on_size)
+ self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None)
- def register_init(self, fcn): self._init_fcns.append(fcn)
- def register_draw(self, fcn, z=50):
+ def new_gl_cache(self, draw_fcn, draw_pri=50):
"""
+ Create a new gl cache.
+ Register its draw and init function.
+ @return the new cache object
+ """
+ cache = gl_cache(draw_fcn)
+ self.register_init(cache.init)
+ self.register_draw(cache.draw, draw_pri)
+ self._gl_caches.append(cache)
+ return cache
+
+ def register_init(self, init_fcn):
+ self._init_fcns.append(init_fcn)
+
+ def register_draw(self, draw_fcn, draw_pri=50):
+ """
Register a draw function with a layer priority.
- Large z values are drawn last.
- Small z values are drawn first.
+ Large pri values are drawn last.
+ Small pri values are drawn first.
"""
for i in range(len(self._draw_fcns)):
- if z < self._draw_fcns[i][0]:
- self._draw_fcns.insert(i, (z, fcn))
+ if draw_pri < self._draw_fcns[i][0]:
+ self._draw_fcns.insert(i, (draw_pri, draw_fcn))
return
- self._draw_fcns.append((z, fcn))
+ self._draw_fcns.append((draw_pri, draw_fcn))
def _on_size(self, event):
"""
Flag the resize event.
The paint event will handle the actual resizing.
"""
+ self.lock()
self._resized_flag = True
+ self.unlock()
def _on_paint(self, event):
"""
- Respond to paint events, call update.
+ Respond to paint events.
Initialize GL if this is the first paint event.
+ Resize the view port if the width or height changed.
+ Redraw the screen, calling the draw functions.
"""
+ self.lock()
self.SetCurrent()
#check if gl was initialized
if not self._gl_init_flag:
@@ -97,7 +149,6 @@
self._gl_init_flag = True
#check for a change in window size
if self._resized_flag:
- self.lock()
self.width, self.height = self.GetSize()
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glLoadIdentity()
@@ -105,325 +156,16 @@
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glViewport(0, 0, self.width, self.height)
+ for cache in self._gl_caches: cache.changed(True)
self._resized_flag = False
- self.unlock()
#clear, draw functions, swap
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
- self.lock()
for fcn in self._draw_fcns: fcn[1]()
- self.unlock()
self.SwapBuffers()
+ self.unlock()
def update(self):
"""
Force a paint event.
- Record the timestamp.
"""
wx.PostEvent(self, wx.PaintEvent())
- self._update_ts = time.time()
-
-##################################################
-# Grid Plotter Base Class
-##################################################
-class grid_plotter_base(_plotter_base):
-
- def __init__(self, parent, padding):
- _plotter_base.__init__(self, parent)
- #setup grid cache
- self._grid_cache = common.gl_cache(self._draw_grid)
- self.register_init(self._grid_cache.init)
- self.register_draw(self._grid_cache.draw)
- self.enable_grid_lines(True)
- #setup padding
- self.padding_top, self.padding_right, self.padding_bottom,
self.padding_left = padding
- #store title and unit strings
- self.set_title('Title')
- self.set_x_label('X Label')
- self.set_y_label('Y Label')
- #init the grid to some value
- self.set_x_grid(-1, 1, 1)
- self.set_y_grid(-1, 1, 1)
- #setup point label cache
- self._point_label_cache =
common.gl_cache(self._draw_point_label)
- self.register_init(self._point_label_cache.init)
- self.register_draw(self._point_label_cache.draw, 75)
- #setup point label
- self.enable_point_label(False)
- self.set_point_label_coordinate(None)
- common.point_label_thread(self)
-
- def set_point_label_coordinate(self, coor):
- """
- Set the point label coordinate.
- @param coor the coordinate x, y tuple or None
- """
- self.lock()
- self._point_label_coordinate = coor
- self._point_label_cache.changed(True)
- self.update()
- self.unlock()
-
- def enable_point_label(self, enable=None):
- """
- Enable/disable the point label.
- @param enable true to enable
- @return the enable state when None
- """
- if enable is None: return self._enable_point_label
- self.lock()
- self._enable_point_label = enable
- self._point_label_cache.changed(True)
- self.unlock()
-
- def set_title(self, title):
- """
- Set the title.
- @param title the title string
- """
- self.lock()
- self.title = title
- self._grid_cache.changed(True)
- self.unlock()
-
- def set_x_label(self, x_label, x_units=''):
- """
- Set the x label and units.
- @param x_label the x label string
- @param x_units the x units string
- """
- self.lock()
- self.x_label = x_label
- self.x_units = x_units
- self._grid_cache.changed(True)
- self.unlock()
-
- def set_y_label(self, y_label, y_units=''):
- """
- Set the y label and units.
- @param y_label the y label string
- @param y_units the y units string
- """
- self.lock()
- self.y_label = y_label
- self.y_units = y_units
- self._grid_cache.changed(True)
- self.unlock()
-
- def set_x_grid(self, minimum, maximum, step, scale=False):
- """
- Set the x grid parameters.
- @param minimum the left-most value
- @param maximum the right-most value
- @param step the grid spacing
- @param scale true to scale the x grid
- """
- self.lock()
- self.x_min = float(minimum)
- self.x_max = float(maximum)
- self.x_step = float(step)
- if scale:
- coeff, exp, prefix =
common.get_si_components(max(abs(self.x_min), abs(self.x_max)))
- self.x_scalar = 10**(-exp)
- self.x_prefix = prefix
- else:
- self.x_scalar = 1.0
- self.x_prefix = ''
- self._grid_cache.changed(True)
- self.unlock()
-
- def set_y_grid(self, minimum, maximum, step, scale=False):
- """
- Set the y grid parameters.
- @param minimum the bottom-most value
- @param maximum the top-most value
- @param step the grid spacing
- @param scale true to scale the y grid
- """
- self.lock()
- self.y_min = float(minimum)
- self.y_max = float(maximum)
- self.y_step = float(step)
- if scale:
- coeff, exp, prefix =
common.get_si_components(max(abs(self.y_min), abs(self.y_max)))
- self.y_scalar = 10**(-exp)
- self.y_prefix = prefix
- else:
- self.y_scalar = 1.0
- self.y_prefix = ''
- self._grid_cache.changed(True)
- self.unlock()
-
- def _draw_grid(self):
- """
- Draw the border, grid, title, and units.
- """
- ##################################################
- # Draw Grid X
- ##################################################
- GL.glColor3f(*GRID_LINE_COLOR_SPEC)
- for tick in self._get_ticks(self.x_min, self.x_max,
self.x_step, self.x_scalar):
- scaled_tick =
(self.width-self.padding_left-self.padding_right)*\
-
(tick/self.x_scalar-self.x_min)/(self.x_max-self.x_min) + self.padding_left-1
- self._draw_grid_line(
- (scaled_tick, self.padding_top),
- (scaled_tick, self.height-self.padding_bottom),
- )
- txt = self._get_tick_label(tick, self.x_units)
- w, h = txt.get_size()
- txt.draw_text(wx.Point(scaled_tick-w/2,
self.height-self.padding_bottom+TICK_LABEL_PADDING))
- ##################################################
- # Draw Grid Y
- ##################################################
- GL.glColor3f(*GRID_LINE_COLOR_SPEC)
- for tick in self._get_ticks(self.y_min, self.y_max,
self.y_step, self.y_scalar):
- scaled_tick =
(self.height-self.padding_top-self.padding_bottom)*\
- (1 -
(tick/self.y_scalar-self.y_min)/(self.y_max-self.y_min)) + self.padding_top
- self._draw_grid_line(
- (self.padding_left, scaled_tick),
- (self.width-self.padding_right, scaled_tick),
- )
- txt = self._get_tick_label(tick, self.y_units)
- w, h = txt.get_size()
-
txt.draw_text(wx.Point(self.padding_left-w-TICK_LABEL_PADDING, scaled_tick-h/2))
- ##################################################
- # Draw Border
- ##################################################
- GL.glColor3f(*GRID_BORDER_COLOR_SPEC)
- self._draw_rect(
- self.padding_left,
- self.padding_top,
- self.width - self.padding_right - self.padding_left,
- self.height - self.padding_top - self.padding_bottom,
- fill=False,
- )
- ##################################################
- # Draw Title
- ##################################################
- #draw x units
- txt = gltext.Text(self.title, bold=True,
font_size=TITLE_TEXT_FONT_SIZE, centered=True)
- txt.draw_text(wx.Point(self.width/2.0, .5*self.padding_top))
- ##################################################
- # Draw Labels
- ##################################################
- #draw x labels
- x_label_str = self.x_units and "%s (%s%s)"%(self.x_label,
self.x_prefix, self.x_units) or self.x_label
- txt = gltext.Text(x_label_str, bold=True,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
- txt.draw_text(wx.Point(
-
(self.width-self.padding_left-self.padding_right)/2.0 + self.padding_left,
- self.height-.25*self.padding_bottom,
- )
- )
- #draw y labels
- y_label_str = self.y_units and "%s (%s%s)"%(self.y_label,
self.y_prefix, self.y_units) or self.y_label
- txt = gltext.Text(y_label_str, bold=True,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
- txt.draw_text(wx.Point(
- .25*self.padding_left,
-
(self.height-self.padding_top-self.padding_bottom)/2.0 + self.padding_top,
- ), rotation=90,
- )
-
- def _get_tick_label(self, tick, unit):
- """
- Format the tick value and create a gl text.
- @param tick the floating point tick value
- @param unit the axis unit
- @return the tick label text
- """
- if unit: tick_str = common.sci_format(tick)
- else: tick_str = common.eng_format(tick)
- return gltext.Text(tick_str, font_size=TICK_TEXT_FONT_SIZE)
-
- def _get_ticks(self, min, max, step, scalar):
- """
- Determine the positions for the ticks.
- @param min the lower bound
- @param max the upper bound
- @param step the grid spacing
- @param scalar the grid scaling
- @return a list of tick positions between min and max
- """
- #cast to float
- min = float(min)
- max = float(max)
- step = float(step)
- #check for valid numbers
- assert step > 0
- assert max > min
- assert max - min > step
- #determine the start and stop value
- start = int(math.ceil(min/step))
- stop = int(math.floor(max/step))
- return [i*step*scalar for i in range(start, stop+1)]
-
- def enable_grid_lines(self, enable=None):
- """
- Enable/disable the grid lines.
- @param enable true to enable
- @return the enable state when None
- """
- if enable is None: return self._enable_grid_lines
- self.lock()
- self._enable_grid_lines = enable
- self._grid_cache.changed(True)
- self.unlock()
-
- def _draw_grid_line(self, coor1, coor2):
- """
- Draw a dashed line from coor1 to coor2.
- @param corr1 a tuple of x, y
- @param corr2 a tuple of x, y
- """
- if not self.enable_grid_lines(): return
- GL.glEnable(GL.GL_LINE_STIPPLE)
- GL.glLineStipple(1, int("1110" + "0000" + "1110" + "0000", 2))
- GL.glBegin(GL.GL_LINES)
- GL.glVertex2f(*coor1)
- GL.glVertex2f(*coor2)
- GL.glEnd()
- GL.glDisable(GL.GL_LINE_STIPPLE)
-
- def _draw_rect(self, x, y, width, height, fill=True):
- """
- Draw a rectangle on the x, y plane.
- X and Y are the top-left corner.
- @param x the left position of the rectangle
- @param y the top position of the rectangle
- @param width the width of the rectangle
- @param height the height of the rectangle
- @param fill true to color inside of rectangle
- """
- GL.glBegin(fill and GL.GL_QUADS or GL.GL_LINE_LOOP)
- GL.glVertex2f(x, y)
- GL.glVertex2f(x+width, y)
- GL.glVertex2f(x+width, y+height)
- GL.glVertex2f(x, y+height)
- GL.glEnd()
-
- def _draw_point_label(self):
- """
- Draw the point label for the last mouse motion coordinate.
- The mouse coordinate must be an X, Y tuple.
- The label will be drawn at the X, Y coordinate.
- The values of the X, Y coordinate will be scaled to the current
X, Y bounds.
- """
- if not self.enable_point_label(): return
- if not self._point_label_coordinate: return
- x, y = self._point_label_coordinate
- if x < self.padding_left or x > self.width-self.padding_right:
return
- if y < self.padding_top or y > self.height-self.padding_bottom:
return
- #scale to window bounds
- x_win_scalar = float(x -
self.padding_left)/(self.width-self.padding_left-self.padding_right)
- y_win_scalar = float((self.height - y) -
self.padding_bottom)/(self.height-self.padding_top-self.padding_bottom)
- #scale to grid bounds
- x_val = x_win_scalar*(self.x_max-self.x_min) + self.x_min
- y_val = y_win_scalar*(self.y_max-self.y_min) + self.y_min
- #create text
- label_str = self._populate_point_label(x_val, y_val)
- if not label_str: return
- txt = gltext.Text(label_str, font_size=POINT_LABEL_FONT_SIZE)
- w, h = txt.get_size()
- #draw rect + text
- GL.glColor3f(*POINT_LABEL_COLOR_SPEC)
- if x > self.width/2: x -= w+2*POINT_LABEL_PADDING
- self._draw_rect(x, y-h-2*POINT_LABEL_PADDING,
w+2*POINT_LABEL_PADDING, h+2*POINT_LABEL_PADDING)
- txt.draw_text(wx.Point(x+POINT_LABEL_PADDING,
y-h-POINT_LABEL_PADDING))
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/waterfall_plotter.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/waterfall_plotter.py
2009-03-03 02:27:36 UTC (rev 10554)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/waterfall_plotter.py
2009-03-03 07:34:04 UTC (rev 10555)
@@ -20,7 +20,7 @@
#
import wx
-from plotter_base import grid_plotter_base
+from grid_plotter_base import grid_plotter_base
from OpenGL import GL
import common
import numpy
@@ -33,7 +33,7 @@
LEGEND_WIDTH = 8
LEGEND_FONT_SIZE = 8
LEGEND_BORDER_COLOR_SPEC = (0, 0, 0) #black
-PADDING = 35, 60, 40, 60 #top, right, bottom, left
+MIN_PADDING = 0, 60, 0, 0 #top, right, bottom, left
ceil_log2 = lambda x: 2**int(math.ceil(math.log(x)/math.log(2)))
@@ -91,14 +91,13 @@
Create a new channel plotter.
"""
#init
- grid_plotter_base.__init__(self, parent, PADDING)
+ grid_plotter_base.__init__(self, parent, MIN_PADDING)
#setup legend cache
- self._legend_cache = common.gl_cache(self._draw_legend)
- self.register_init(self._legend_cache.init)
- self.register_draw(self._legend_cache.draw)
+ self._legend_cache = self.new_gl_cache(self._draw_legend)
+ #setup waterfall cache
+ self._waterfall_cache = self.new_gl_cache(self._draw_waterfall,
50)
#setup waterfall plotter
self.register_init(self._init_waterfall)
- self.register_draw(self._draw_waterfall)
self._resize_texture(False)
self._minimum = 0
self._maximum = 0
@@ -264,4 +263,5 @@
#convert the samples to RGBA data
data = numpy.choose(samples,
COLORS[self._color_mode]).tostring()
self._buffer.append(data)
+ self._waterfall_cache.changed(True)
self.unlock()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10555 - gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter,
jblum <=