commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8963 - in gnuradio/branches/features/experimental-gui


From: jblum
Subject: [Commit-gnuradio] r8963 - in gnuradio/branches/features/experimental-gui: . plotter
Date: Mon, 21 Jul 2008 15:42:29 -0600 (MDT)

Author: jblum
Date: 2008-07-21 15:42:29 -0600 (Mon, 21 Jul 2008)
New Revision: 8963

Added:
   gnuradio/branches/features/experimental-gui/plotter/
   gnuradio/branches/features/experimental-gui/plotter/__init__.py
   gnuradio/branches/features/experimental-gui/plotter/channel_plotter.py
   gnuradio/branches/features/experimental-gui/plotter/gltext.py
   gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
   gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
Removed:
   gnuradio/branches/features/experimental-gui/gltext.py
   gnuradio/branches/features/experimental-gui/plotter.py
Modified:
   gnuradio/branches/features/experimental-gui/const_window.py
   gnuradio/branches/features/experimental-gui/fft_window.py
   gnuradio/branches/features/experimental-gui/scope_window.py
Log:
split up plotter into module

Modified: gnuradio/branches/features/experimental-gui/const_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/const_window.py 2008-07-21 
20:23:01 UTC (rev 8962)
+++ gnuradio/branches/features/experimental-gui/const_window.py 2008-07-21 
21:42:29 UTC (rev 8963)
@@ -120,7 +120,7 @@
                self.gain_omega_key = gain_omega_key
                #init panel and plot
                wx.Panel.__init__(self, parent, -1, style=wx.SIMPLE_BORDER)
-               self.plotter = plotter.grid_plotter(self)
+               self.plotter = plotter.channel_plotter(self)
                self.plotter.SetSize(wx.Size(*size))
                self.plotter.set_title(title)
                self.plotter.set_x_units('Inphase')

Modified: gnuradio/branches/features/experimental-gui/fft_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/fft_window.py   2008-07-21 
20:23:01 UTC (rev 8962)
+++ gnuradio/branches/features/experimental-gui/fft_window.py   2008-07-21 
21:42:29 UTC (rev 8963)
@@ -158,7 +158,7 @@
                self.peak_vals = NO_PEAK_VALS
                #init panel and plot
                wx.Panel.__init__(self, parent, -1, style=wx.SIMPLE_BORDER)
-               self.plotter = plotter.grid_plotter(self)
+               self.plotter = plotter.channel_plotter(self)
                self.plotter.SetSize(wx.Size(*size))
                self.plotter.set_title(title)
                #setup the box with plot and controls

Deleted: gnuradio/branches/features/experimental-gui/gltext.py

Added: gnuradio/branches/features/experimental-gui/plotter/__init__.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/__init__.py             
                (rev 0)
+++ gnuradio/branches/features/experimental-gui/plotter/__init__.py     
2008-07-21 21:42:29 UTC (rev 8963)
@@ -0,0 +1,23 @@
+#
+# Copyright 2008 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.
+#
+
+from channel_plotter import channel_plotter
+from waterfall_plotter import waterfall_plotter

Added: gnuradio/branches/features/experimental-gui/plotter/channel_plotter.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/channel_plotter.py      
                        (rev 0)
+++ gnuradio/branches/features/experimental-gui/plotter/channel_plotter.py      
2008-07-21 21:42:29 UTC (rev 8963)
@@ -0,0 +1,185 @@
+#
+# Copyright 2008 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
+from plotter_base import grid_plotter_base
+from OpenGL.GL import *
+import numpy
+import gltext
+
+LEGEND_TEXT_FONT_SIZE = 8
+LEGEND_BOX_WIDTH, LEGEND_BOX_HEIGHT = 26, 20
+PADDING = 35, 15, 40, 60 #top, right, bottom, left
+
+##################################################
+# Channel Plotter for X Y Waveforms
+##################################################
+class channel_plotter(grid_plotter_base):
+
+       def __init__(self, parent):
+               """!
+               Create a new channel plotter.
+               """
+               #init
+               grid_plotter_base.__init__(self, parent, PADDING)
+               self.channels = dict()
+               self.set_legend(False)
+
+       def _gl_init(self):
+               """!
+               Run gl initialization tasks.
+               """
+               glEnableClientState(GL_VERTEX_ARRAY)
+               self.grid_compiled_list_id = glGenLists(1)
+
+       def set_legend(self, legend):
+               """!
+               Set the legend on/off.
+               @param legend true to turn on
+               """
+               self.semaphore.acquire(True)
+               self.legend = legend
+               self.changed(True)
+               self.semaphore.release()
+
+       def draw(self):
+               """!
+               Draw the grid and waveforms.
+               """
+               self.semaphore.acquire(True)
+               self.clear()
+               #store the grid drawing operations
+               if self.changed():
+                       glNewList(self.grid_compiled_list_id, GL_COMPILE)
+                       self._draw_grid()
+                       self._draw_legend()
+                       glEndList()
+                       self.changed(False)
+               #draw the grid
+               glCallList(self.grid_compiled_list_id)
+               #use scissor to prevent drawing outside grid
+               glEnable(GL_SCISSOR_TEST)
+               glScissor(
+                       self.padding_left+1,
+                       self.padding_bottom+1,
+                       self.width-self.padding_left-self.padding_right-1,
+                       self.height-self.padding_top-self.padding_bottom-1,
+               )
+               #draw the waveforms
+               self._draw_waveforms()
+               glDisable(GL_SCISSOR_TEST)
+               #swap buffer into display
+               self.SwapBuffers()
+               self.semaphore.release()
+
+       def _draw_waveforms(self):
+               """!
+               Draw the waveforms for each channel.
+               Scale the waveform data to the grid using numpy (saves CPU).
+               """
+               ##################################################
+               # Draw Waveforms
+               ##################################################
+               for channel in reversed(sorted(self.channels.keys())):
+                       samples, color_spec, marker = self.channels[channel]
+                       num_samps = len(samples)
+                       #use opengl to scale the waveform
+                       glPushMatrix()
+                       glTranslatef(self.padding_left, self.padding_top, 0)
+                       glScalef(
+                               
(self.width-self.padding_left-self.padding_right),
+                               
(self.height-self.padding_top-self.padding_bottom),
+                               1,
+                       )
+                       glTranslatef(0, 1, 0)
+                       if isinstance(samples, tuple):
+                               x_scale, x_trans = 1.0/(self.x_max-self.x_min), 
-self.x_min
+                               points = zip(*samples)
+                       else:
+                               x_scale, x_trans = 1.0/(num_samps-1), 0
+                               points = zip(numpy.arange(0, num_samps), 
samples)
+                       glScalef(x_scale, -1.0/(self.y_max-self.y_min), 1)
+                       glTranslatef(x_trans, -self.y_min, 0)
+                       #draw the points/lines
+                       glColor3f(*color_spec)
+                       if marker == '+': #TODO slow, slow, slow
+                               points_4 = numpy.array(zip(points, points, 
points, points))
+                               points_4 = points_4 + .01*numpy.array([
+                                               (self.x_max-self.x_min, 0),
+                                               (self.x_min-self.x_max, 0),
+                                               (0, self.y_max-self.y_min),
+                                               (0, self.y_min-self.y_max),
+                                       ]
+                               )
+                               points = points_4.reshape(len(points)*4, 2)
+                       glVertexPointer(2, GL_FLOAT, 0, points)
+                       glDrawArrays({None: GL_LINE_STRIP, '.': GL_POINTS, '+': 
GL_LINES}[marker], 0, len(points))
+                       glPopMatrix()
+
+       def _draw_legend(self):
+               ##################################################
+               # Draw Legend
+               ##################################################
+               if self.legend:
+                       for i, channel in 
enumerate(sorted(self.channels.keys())):
+                               x_off = 
1.1*LEGEND_BOX_WIDTH*(len(self.channels) - i - 1) + LEGEND_BOX_WIDTH/2
+                               color_spec = self.channels[channel][1]
+                               #draw colored rectangle
+                               glColor3f(*color_spec)
+                               self._draw_rect(
+                                       self.width - self.padding_right - x_off 
- LEGEND_BOX_WIDTH/2,
+                                       
(self.padding_top-LEGEND_BOX_HEIGHT)/2.0,
+                                       LEGEND_BOX_WIDTH,
+                                       LEGEND_BOX_HEIGHT,
+                               )
+                               #draw label text
+                               txt = gltext.Text('Ch%s'%channel, 
font_size=LEGEND_TEXT_FONT_SIZE, centered=True)
+                               txt.draw_text(wx.Point(self.width - 
self.padding_right - x_off, self.padding_top/2.0))
+
+       def set_waveform(self, channel, samples, color_spec, marker=None):
+               """!
+               Set the waveform for a given channel.
+               @param channel the channel number
+               @param samples the waveform samples
+               @param color_spec the 3-tuple for line color
+               @param marker None for line
+               """
+               self.channels[channel] = samples, color_spec, marker
+
+if __name__ == '__main__':
+       app = wx.PySimpleApp()
+       frame = wx.Frame(None, -1, 'Demo', wx.DefaultPosition)
+       vbox = wx.BoxSizer(wx.VERTICAL)
+
+       plotter = channel_plotter(frame)
+       plotter.set_x_grid(-1, 1, .2)
+       plotter.set_y_grid(-1, 1, .4)
+       vbox.Add(plotter, 1, wx.EXPAND)
+
+       plotter = channel_plotter(frame)
+       plotter.set_x_grid(-1, 1, .2)
+       plotter.set_y_grid(-1, 1, .4)
+       vbox.Add(plotter, 1, wx.EXPAND)
+
+       frame.SetSizerAndFit(vbox)
+       frame.SetSize(wx.Size(800, 600))
+       frame.Show()
+       app.MainLoop()

Copied: gnuradio/branches/features/experimental-gui/plotter/gltext.py (from rev 
8962, gnuradio/branches/features/experimental-gui/gltext.py)
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/gltext.py               
                (rev 0)
+++ gnuradio/branches/features/experimental-gui/plotter/gltext.py       
2008-07-21 21:42:29 UTC (rev 8963)
@@ -0,0 +1,494 @@
+#!/usr/bin/env python
+# -*- coding: utf-8
+#
+#    Provides some text display functions for wx + ogl
+#    Copyright (C) 2007 Christian Brugger, Stefan Hacker
+#
+#    This program 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 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import wx
+from OpenGL.GL import *
+
+"""
+Optimize with psyco if possible, this gains us about 50% speed when
+creating our textures in trade for about 4MBytes of additional memory usage for
+psyco. If you don't like loosing the memory you have to turn the lines 
following
+"enable psyco" into a comment while uncommenting the line after "Disable 
psyco".
+"""
+#Try to enable psyco
+try:
+    import psyco
+    psyco_optimized = False
+except ImportError:
+    psyco = None
+    
+#Disable psyco
+#psyco = None
+          
+class TextElement(object):
+    """
+    A simple class for using system Fonts to display
+    text in an OpenGL scene
+    """
+    def __init__(self,
+                 text = '',
+                 font = None,
+                 foreground = wx.BLACK,
+                 centered = False):
+        """
+        text (String)         - Text
+        font (wx.Font)        - Font to draw with (None = System default)
+        foreground (wx.Color) - Color of the text
+                or (wx.Bitmap)- Bitmap to overlay the text with
+        centered (bool)       - Center the text
+        
+        Initializes the TextElement
+        """
+        # save given variables
+        self._text        = text
+        self._lines       = text.split('\n')
+        self._font        = font
+        self._foreground  = foreground
+        self._centered    = centered
+        
+        # init own variables
+        self._owner_cnt   = 0        #refcounter
+        self._texture     = None     #OpenGL texture ID
+        self._text_size   = None     #x/y size tuple of the text
+        self._texture_size= None     #x/y Texture size tuple
+        
+        # create Texture
+        self.createTexture()
+        
+
+    #---Internal helpers
+    
+    def _getUpper2Base(self, value):
+        """
+        Returns the lowest value with the power of
+        2 greater than 'value' (2^n>value)
+        """
+        base2 = 1
+        while base2 < value:
+            base2 *= 2
+        return base2
+        
+    #---Functions
+    
+    def draw_text(self, position = wx.Point(0,0), scale = 1.0, rotation = 0):
+        """
+        position (wx.Point)    - x/y Position to draw in scene
+        scale    (float)       - Scale
+        rotation (int)         - Rotation in degree
+        
+        Draws the text to the scene
+        """
+        #Enable necessary functions
+        glColor(1,1,1,1)
+        glEnable(GL_TEXTURE_2D)     
+        glEnable(GL_ALPHA_TEST)       #Enable alpha test
+        glAlphaFunc(GL_GREATER, 0)
+        glEnable(GL_BLEND)            #Enable blending
+        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+        #Bind texture
+        glBindTexture(GL_TEXTURE_2D, self._texture)
+        
+        ow, oh = self._text_size
+        w , h  = self._texture_size
+        #Perform transformations
+        glPushMatrix()
+        glTranslated(position.x, position.y, 0)
+        glRotate(-rotation, 0, 0, 1)
+        glScaled(scale, scale, scale)
+        if self._centered:
+            glTranslate(-w/2, -oh/2, 0)
+        #Draw vertices
+        glBegin(GL_QUADS)
+        glTexCoord2f(0,0); glVertex2f(0,0)
+        glTexCoord2f(0,1); glVertex2f(0,h)
+        glTexCoord2f(1,1); glVertex2f(w,h)
+        glTexCoord2f(1,0); glVertex2f(w,0)
+        glEnd()
+        glPopMatrix()
+        
+        #Disable features
+        glDisable(GL_BLEND)
+        glDisable(GL_ALPHA_TEST)
+        glDisable(GL_TEXTURE_2D)
+        
+    def createTexture(self):
+        """
+        Creates a texture from the settings saved in TextElement, to be able 
to use normal
+        system fonts conviently a wx.MemoryDC is used to draw on a wx.Bitmap. 
As wxwidgets 
+        device contexts don't support alpha at all it is necessary to apply a 
little hack
+        to preserve antialiasing without sticking to a fixed background color:
+        
+        We draw the bmp in b/w mode so we can use its data as a alpha channel 
for a solid
+        color bitmap which after GL_ALPHA_TEST and GL_BLEND will show a nicely 
antialiased
+        text on any surface.
+        
+        To access the raw pixel data the bmp gets converted to a wx.Image. Now 
we just have
+        to merge our foreground color with the alpha data we just created and 
push it all
+        into a OpenGL texture and we are DONE *inhalesdelpy*
+        
+        DRAWBACK of the whole conversion thing is a really long time for 
creating the
+        texture. If you see any optimizations that could save time PLEASE 
CREATE A PATCH!!!
+        """
+        # get a memory dc
+        dc = wx.MemoryDC()
+        
+        # set our font
+        dc.SetFont(self._font)
+        
+        # Approximate extend to next power of 2 and create our bitmap
+        # REMARK: You wouldn't believe how much fucking speed this little
+        #         sucker gains compared to sizes not of the power of 2. It's 
like
+        #         500ms --> 0.5ms (on my ATI-GPU powered Notebook). On Sams 
nvidia
+        #         machine there don't seem to occur any losses...bad drivers?
+        ow, oh = dc.GetMultiLineTextExtent(self._text)[:2]
+        w, h = self._getUpper2Base(ow), self._getUpper2Base(oh)
+        
+        self._text_size = wx.Size(ow,oh)
+        self._texture_size = wx.Size(w,h)
+        bmp = wx.EmptyBitmap(w,h)
+        
+        
+        #Draw in b/w mode to bmp so we can use it as alpha channel
+        dc.SelectObject(bmp)
+        dc.SetBackground(wx.BLACK_BRUSH)
+        dc.Clear()
+        dc.SetTextForeground(wx.WHITE)
+        x,y = 0,0
+        centered = self.centered
+        for line in self._lines:
+            if not line: line = ' '
+            tw, th = dc.GetTextExtent(line)
+            if centered:
+                x = int(round((w-tw)/2))
+            dc.DrawText(line, x, y)
+            x = 0
+            y += th
+        #Release the dc
+        dc.SelectObject(wx.NullBitmap)
+        del dc
+
+        #Generate a correct RGBA data string from our bmp 
+        """
+        NOTE: You could also use wx.AlphaPixelData to access the pixel data
+        in 'bmp' directly, but the iterator given by it is much slower than
+        first converting to an image and using wx.Image.GetData().
+        """
+        img   = wx.ImageFromBitmap(bmp)
+        alpha = img.GetData()
+        
+        if isinstance(self._foreground, wx.Color):  
+            """
+            If we have a static color...  
+            """    
+            r,g,b = self._foreground.Get()
+            color = "%c%c%c" % (chr(r), chr(g), chr(b))
+            
+            data = ''
+            for i in xrange(0, len(alpha)-1, 3):
+                data += color + alpha[i]
+        
+        elif isinstance(self._foreground, wx.Bitmap):
+            """
+            If we have a bitmap...
+            """
+            bg_img    = wx.ImageFromBitmap(self._foreground)
+            bg        = bg_img.GetData()
+            bg_width  = self._foreground.GetWidth()
+            bg_height = self._foreground.GetHeight()
+            
+            data = ''
+
+            for y in xrange(0, h):
+                for x in xrange(0, w):
+                    if (y > (bg_height-1)) or (x > (bg_width-1)):              
         
+                        color = "%c%c%c" % (chr(0),chr(0),chr(0))
+                    else:
+                        pos = (x+y*bg_width) * 3
+                        color = bg[pos:pos+3]
+                    data += color + alpha[(x+y*w)*3]
+
+
+        # now convert it to ogl texture
+        self._texture = glGenTextures(1)
+        glBindTexture(GL_TEXTURE_2D, self._texture)
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
+        
+        glPixelStorei(GL_UNPACK_ROW_LENGTH, 0)
+        glPixelStorei(GL_UNPACK_ALIGNMENT, 2)
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, 
GL_UNSIGNED_BYTE, data)
+    
+    def deleteTexture(self):
+        """
+        Deletes the OpenGL texture object
+        """
+        if self._texture:
+            if glIsTexture(self._texture):
+                glDeleteTextures(self._texture)
+            else:
+                self._texture = None
+
+    def bind(self):
+        """
+        Increase refcount
+        """
+        self._owner_cnt += 1
+    
+    def release(self):
+        """
+        Decrease refcount
+        """
+        self._owner_cnt -= 1
+        
+    def isBound(self):
+        """
+        Return refcount
+        """
+        return self._owner_cnt
+        
+    def __del__(self):
+        """
+        Destructor
+        """
+        self.deleteTexture()
+
+    #---Getters/Setters
+    
+    def getText(self): return self._text
+    def getFont(self): return self._font
+    def getForeground(self): return self._foreground
+    def getCentered(self): return self._centered
+    def getTexture(self): return self._texture
+    def getTexture_size(self): return self._texture_size
+
+    def getOwner_cnt(self): return self._owner_cnt
+    def setOwner_cnt(self, value):
+        self._owner_cnt = value
+        
+    #---Properties
+    
+    text         = property(getText, None, None, "Text of the object")
+    font         = property(getFont, None, None, "Font of the object")
+    foreground   = property(getForeground, None, None, "Color of the text")
+    centered     = property(getCentered, None, None, "Is text centered")
+    owner_cnt    = property(getOwner_cnt, setOwner_cnt, None, "Owner count")
+    texture      = property(getTexture, None, None, "Used texture")
+    texture_size = property(getTexture_size, None, None, "Size of the used 
texture")       
+               
+
+class Text(object):
+    """
+    A simple class for using System Fonts to display text in
+    an OpenGL scene. The Text adds a global Cache of already
+    created text elements to TextElement's base functionality
+    so you can save some memory and increase speed
+    """
+    _texts         = []    #Global cache for TextElements
+    
+    def __init__(self,
+                 text = 'Text',
+                 font = None,
+                 font_size = 8,
+                 foreground = wx.BLACK,
+                 centered = False):
+        """
+            text (string)           - displayed text
+            font (wx.Font)          - if None, system default font will be 
used with font_size
+            font_size (int)         - font size in points
+            foreground (wx.Color)   - Color of the text
+                    or (wx.Bitmap)  - Bitmap to overlay the text with
+            centered (bool)         - should the text drawn centered towards 
position?
+            
+            Initializes the text object
+        """
+        #Init/save variables
+        self._aloc_text = None
+        self._text      = text
+        self._font_size = font_size
+        self._foreground= foreground
+        self._centered  = centered
+        
+        #Check if we are offered a font
+        if not font:
+            #if not use the system default
+            self._font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
+        else: 
+            #save it
+            self._font = font
+            
+        #Bind us to our texture
+        self._initText()
+
+    #---Internal helpers
+
+    def _initText(self):
+        """
+        Initializes/Reinitializes the Text object by binding it
+        to a TextElement suitable for its current settings
+        """
+        #Check if we already bound to a texture
+        if self._aloc_text:
+            #if so release it
+            self._aloc_text.release()
+            if not self._aloc_text.isBound():
+                self._texts.remove(self._aloc_text)
+            self._aloc_text = None
+            
+        #Adjust our font
+        self._font.SetPointSize(self._font_size)
+        
+        #Search for existing element in our global buffer
+        for element in self._texts:
+            if element.text == self._text and\
+              element.font == self._font and\
+              element.foreground == self._foreground and\
+              element.centered == self._centered:
+                # We already exist in global buffer ;-)
+                element.bind()
+                self._aloc_text = element
+                break
+        
+        if not self._aloc_text:
+            # We are not in the global buffer, let's create ourselves
+            aloc_text = self._aloc_text = TextElement(self._text,
+                                                       self._font,
+                                                       self._foreground,
+                                                       self._centered)
+            aloc_text.bind()
+            self._texts.append(aloc_text)
+    
+    def __del__(self):
+        """
+        Destructor
+        """
+        aloc_text = self._aloc_text
+        aloc_text.release()
+        if not aloc_text.isBound():
+            self._texts.remove(aloc_text)
+    
+    #---Functions
+        
+    def draw_text(self, position = wx.Point(0,0), scale = 1.0, rotation = 0):
+        """
+        position (wx.Point)    - x/y Position to draw in scene
+        scale    (float)       - Scale
+        rotation (int)         - Rotation in degree
+        
+        Draws the text to the scene
+        """
+        
+        self._aloc_text.draw_text(position, scale, rotation)
+
+    #---Setter/Getter
+    
+    def getText(self): return self._text
+    def setText(self, value, reinit = True):
+        """
+        value (bool)    - New Text
+        reinit (bool)   - Create a new texture
+        
+        Sets a new text
+        """
+        self._text = value
+        if reinit:
+            self._initText()
+
+    def getFont(self): return self._font
+    def setFont(self, value, reinit = True):
+        """
+        value (bool)    - New Font
+        reinit (bool)   - Create a new texture
+        
+        Sets a new font
+        """
+        self._font = value
+        if reinit:
+            self._initText()
+
+    def getFont_size(self): return self._font_size
+    def setFont_size(self, value, reinit = True):
+        """
+        value (bool)    - New font size
+        reinit (bool)   - Create a new texture
+        
+        Sets a new font size
+        """
+        self._font_size = value
+        if reinit:
+            self._initText()
+
+    def getForeground(self): return self._foreground
+    def setForeground(self, value, reinit = True):
+        """
+        value (bool)    - New centered value
+        reinit (bool)   - Create a new texture
+        
+        Sets a new value for 'centered'
+        """
+        self._foreground = value
+        if reinit:
+            self._initText()
+
+    def getCentered(self): return self._centered
+    def setCentered(self, value, reinit = True):
+        """
+        value (bool)    - New centered value
+        reinit (bool)   - Create a new texture
+        
+        Sets a new value for 'centered'
+        """
+        self._centered = value
+        if reinit:
+            self._initText()
+    
+    def getTexture_size(self):
+        """
+        Returns a texture size tuple
+        """
+        return self._aloc_text.texture_size
+    
+    def getTextElement(self):
+        """
+        Returns the text element bound to the Text class
+        """
+        return self._aloc_text
+    
+    def getTexture(self):
+        """
+        Returns the texture of the bound TextElement
+        """
+        return self._aloc_text.texture
+
+    
+    #---Properties
+    
+    text         = property(getText, setText, None, "Text of the object")
+    font         = property(getFont, setFont, None, "Font of the object")
+    font_size    = property(getFont_size, setFont_size, None, "Font size")
+    foreground   = property(getForeground, setForeground, None, "Color/Overlay 
bitmap of the text")
+    centered     = property(getCentered, setCentered, None, "Display the text 
centered")
+    texture_size = property(getTexture_size, None, None, "Size of the used 
texture")
+    texture      = property(getTexture, None, None, "Texture of bound 
TextElement")
+    text_element = property(getTextElement,None , None, "TextElement bound to 
this class")
+
+#Optimize critical functions
+if psyco and not psyco_optimized:
+    psyco.bind(TextElement.createTexture)
+    psyco_optimized = True

Added: gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/plotter_base.py         
                (rev 0)
+++ gnuradio/branches/features/experimental-gui/plotter/plotter_base.py 
2008-07-21 21:42:29 UTC (rev 8963)
@@ -0,0 +1,301 @@
+#
+# Copyright 2008 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.GL import *
+import threading
+import gltext
+import math
+
+BACKGROUND_COLOR_SPEC = (1, 0.976, 1, 1) #creamy white
+GRID_LINE_COLOR_SPEC = (0, 0, 0) #black
+TICK_TEXT_FONT_SIZE = 9
+TITLE_TEXT_FONT_SIZE = 13
+UNITS_TEXT_FONT_SIZE = 9
+
+##################################################
+# OpenGL WX Plotter Canvas
+##################################################
+class _plotter_base(wx.glcanvas.GLCanvas):
+       """!
+       Plotter base class for all plot types.
+       """
+
+       def __init__(self, parent):
+               """!
+               Create a new plotter base.
+               Initialize GL and register events.
+               @param parent the parent widgit
+               """
+               wx.glcanvas.GLCanvas.__init__(self, parent, -1)
+               self.changed(False)
+               self._gl_init_flag = False
+               self._resized_flag = True
+               wx.EVT_PAINT(self, self._on_paint)
+               wx.EVT_SIZE(self, self._on_size)
+
+       def _on_size(self, event):
+               """!
+               Flag the resize event.
+               The paint event will handle the actual resizing.
+               """
+               self._resized_flag = True
+
+       def _on_paint(self, event):
+               """!
+               Respond to paint events, call update.
+               Initialize GL if this is the first paint event.
+               """
+               self.SetCurrent()
+               #check if gl was initialized
+               if not self._gl_init_flag:
+                       glClearColor(*BACKGROUND_COLOR_SPEC)
+                       self._gl_init()
+                       self._gl_init_flag = True
+               #check for a change in window size
+               if self._resized_flag:
+                       self.width, self.height = self.GetSize()
+                       glViewport(0, 0, self.width, self.height)
+                       glMatrixMode(GL_PROJECTION)
+                       glLoadIdentity()
+                       glOrtho(0, self.width, self.height, 0, 1, 0)
+                       self._resized_flag = False
+                       self.changed(True)
+               self.draw()
+
+       def update(self): wx.PostEvent(self, wx.PaintEvent())
+
+       def clear(self): glClear(GL_COLOR_BUFFER_BIT)
+
+       def changed(self, state=None):
+               """!
+               Set the changed flag if state is not None.
+               Otherwise return the changed flag.
+               """
+               if state is not None: self._changed = state
+               else: return self._changed
+
+##################################################
+# Grid Plotter Base Class
+##################################################
+class grid_plotter_base(_plotter_base):
+
+       def __init__(self, parent, padding):
+               self.semaphore = threading.Semaphore(1)
+               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_units('X Units (xx)')
+               self.set_y_units('Y Units (yy)')
+               #init the grid to some value
+               self.set_x_grid(-1, 1, 1)
+               self.set_y_grid(-1, 1, 1)
+               _plotter_base.__init__(self, parent)
+
+       def set_title(self, title):
+               """!
+               Set the title.
+               @param title the title string
+               """
+               self.semaphore.acquire(True)
+               self.title = title
+               self.changed(True)
+               self.semaphore.release()
+
+       def set_x_units(self, x_units):
+               """!
+               Set the x_units.
+               @param x_units the x_units string
+               """
+               self.semaphore.acquire(True)
+               self.x_units = x_units
+               self.changed(True)
+               self.semaphore.release()
+
+       def set_y_units(self, y_units):
+               """!
+               Set the y_units.
+               @param y_units the y_units string
+               """
+               self.semaphore.acquire(True)
+               self.y_units = y_units
+               self.changed(True)
+               self.semaphore.release()
+
+       def set_x_grid(self, x_min, x_max, x_step):
+               """!
+               Set the x grid parameters.
+               @param x_min the left-most value
+               @param x_max the right-most value
+               @param x_step the grid spacing
+               """
+               self.semaphore.acquire(True)
+               self.x_min = float(x_min)
+               self.x_max = float(x_max)
+               self.x_step = float(x_step)
+               self.changed(True)
+               self.semaphore.release()
+
+       def set_y_grid(self, y_min, y_max, y_step):
+               """!
+               Set the y grid parameters.
+               @param y_min the bottom-most value
+               @param y_max the top-most value
+               @param y_step the grid spacing
+               """
+               self.semaphore.acquire(True)
+               self.y_min = float(y_min)
+               self.y_max = float(y_max)
+               self.y_step = float(y_step)
+               self.changed(True)
+               self.semaphore.release()
+
+       def _draw_grid(self):
+               """!
+               Draw the border, grid, title, and units.
+               """
+               ##################################################
+               # Draw Border
+               ##################################################
+               glColor3f(*GRID_LINE_COLOR_SPEC)
+               glBegin(GL_LINE_LOOP)
+               glVertex3f(self.padding_left, self.padding_top, 0)
+               glVertex3f(self.width - self.padding_right, self.padding_top, 0)
+               glVertex3f(self.width - self.padding_right, self.height - 
self.padding_bottom, 0)
+               glVertex3f(self.padding_left, self.height - 
self.padding_bottom, 0)
+               glEnd()
+               ##################################################
+               # Draw Grid X
+               ##################################################
+               for tick in self._get_ticks(self.x_min, self.x_max, 
self.x_step):
+                       scaled_tick = 
(self.width-self.padding_left-self.padding_right)*\
+                               (tick-self.x_min)/(self.x_max-self.x_min) + 
self.padding_left
+                       glColor3f(*GRID_LINE_COLOR_SPEC)
+                       self._draw_line(
+                               (scaled_tick, self.padding_top, 0),
+                               (scaled_tick, self.height-self.padding_bottom, 
0),
+                       )
+                       self._draw_tick_label(tick, (scaled_tick, 
self.height-.75*self.padding_bottom))
+               ##################################################
+               # Draw Grid Y
+               ##################################################
+               for tick in self._get_ticks(self.y_min, self.y_max, 
self.y_step):
+                       scaled_tick = 
(self.height-self.padding_top-self.padding_bottom)*\
+                               (1 - (tick-self.y_min)/(self.y_max-self.y_min)) 
+ self.padding_top
+                       glColor3f(*GRID_LINE_COLOR_SPEC)
+                       self._draw_line(
+                               (self.padding_left, scaled_tick, 0),
+                               (self.width-self.padding_right, scaled_tick, 0),
+                       )
+                       self._draw_tick_label(tick, (.75*self.padding_left, 
scaled_tick))
+               ##################################################
+               # Draw Title
+               ##################################################
+               font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
+               font.SetWeight(wx.FONTWEIGHT_BOLD)
+               #draw x units
+               txt = gltext.Text(self.title, font=font, 
font_size=TITLE_TEXT_FONT_SIZE, centered=True)
+               txt.draw_text(wx.Point(self.width/2.0, .5*self.padding_top))
+               ##################################################
+               # Draw Units
+               ##################################################
+               font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
+               font.SetWeight(wx.FONTWEIGHT_BOLD)
+               #draw x units
+               txt = gltext.Text(self.x_units, font=font, 
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 units
+               txt = gltext.Text(self.y_units, font=font, 
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 _draw_tick_label(self, tick, coor):
+               """!
+               Format the tick value and draw it at the coordinate.
+               Intelligently switch between decimal representations.
+               @param tick the floating point tick value
+               @param coor the x, y coordinate
+               """
+               #format
+               if tick == 0: exp = 0
+               else: exp = int(math.floor(math.log10(abs(tick))))
+               base = int(tick/10**exp)
+               if abs(exp) >= 3: tick_str = '%de%d'%(base, exp)
+               else: tick_str = '%g'%tick
+               #draw
+               txt = gltext.Text(tick_str, font_size=TICK_TEXT_FONT_SIZE, 
centered=True)
+               txt.draw_text(wx.Point(*coor))
+
+       def _get_ticks(self, min, max, step):
+               """!
+               Determine the positions for the ticks.
+               @param min the lower bound
+               @param max the upper bound
+               @param step the grid spacing
+               @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 for i in range(start, stop+1)]
+
+       def _draw_line(self, coor1, coor2):
+               """!
+               Draw a line from coor1 to coor2.
+               @param corr1 a tuple of x, y, z
+               @param corr2 a tuple of x, y, z
+               """
+               glBegin(GL_LINES)
+               glVertex3f(*coor1)
+               glVertex3f(*coor2)
+               glEnd()
+
+       def _draw_rect(self, x, y, width, height):
+               """!
+               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
+               """
+               glBegin(GL_QUADS)
+               glVertex3f(x, y, 0)
+               glVertex3f(x+width, y, 0)
+               glVertex3f(x+width, y+height, 0)
+               glVertex3f(x, y+height, 0)
+               glEnd()

Added: gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py    
                        (rev 0)
+++ gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py    
2008-07-21 21:42:29 UTC (rev 8963)
@@ -0,0 +1,65 @@
+#
+# Copyright 2008 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
+from plotter_base import grid_plotter_base
+from OpenGL.GL import *
+import numpy
+import gltext
+
+PADDING = 35, 35, 40, 60 #top, right, bottom, left
+
+##################################################
+# Waterfall Plotter
+##################################################
+class waterfall_plotter(grid_plotter_base):
+       def __init__(self, parent):
+               """!
+               Create a new channel plotter.
+               """
+               #init
+               grid_plotter_base.__init__(self, parent, PADDING)
+
+       def _gl_init(self):
+               """!
+               Run gl initialization tasks.
+               """
+               self.grid_compiled_list_id = glGenLists(1)
+               
+       def draw(self):
+               """!
+               Draw the grid and waveforms.
+               """
+               self.semaphore.acquire(True)
+               self.clear()
+               #store the grid drawing operations
+               if self._changed:
+                       glNewList(self.grid_compiled_list_id, GL_COMPILE)
+                       self._draw_grid()
+                       glEndList()
+                       self._changed = False
+               #draw the grid
+               glCallList(self.grid_compiled_list_id)
+               #draw the waterfall
+               #TODO
+               #swap buffer into display
+               self.SwapBuffers()
+               self.semaphore.release()

Deleted: gnuradio/branches/features/experimental-gui/plotter.py

Modified: gnuradio/branches/features/experimental-gui/scope_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/scope_window.py 2008-07-21 
20:23:01 UTC (rev 8962)
+++ gnuradio/branches/features/experimental-gui/scope_window.py 2008-07-21 
21:42:29 UTC (rev 8963)
@@ -208,7 +208,7 @@
                self.scope_num_samples_key = scope_num_samples_key
                #init panel and plot
                wx.Panel.__init__(self, parent, -1, style=wx.SIMPLE_BORDER)
-               self.plotter = plotter.grid_plotter(self)
+               self.plotter = plotter.channel_plotter(self)
                self.plotter.SetSize(wx.Size(*size))
                self.plotter.set_title(title)
                self.plotter.set_legend(self.num_inputs > 1)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]