[GRASS-SVN] r35554 - in grass/branches/develbranch_6/gui/wxpython: gui_modules vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 23 13:53:22 EST 2009


Author: martinl
Date: 2009-01-23 13:53:22 -0500 (Fri, 23 Jan 2009)
New Revision: 35554

Added:
   grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.h
   grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.i
Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
   grass/branches/develbranch_6/gui/wxpython/vdigit/Makefile
   grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
   grass/branches/develbranch_6/gui/wxpython/vdigit/driver_draw.cpp
Log:
glynn: Use local version of wxPseudoDC (for real) 
       (merge from trunk, r35537)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2009-01-23 17:00:07 UTC (rev 35553)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2009-01-23 18:53:22 UTC (rev 35554)
@@ -1106,7 +1106,7 @@
             self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
         
         # create pseudoDC for drawing the map
-        self.parent.MapWindow.pdcVector = wx.PseudoDC()
+        self.parent.MapWindow.pdcVector = vdigit.PseudoDC()
         self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
 
         if not self.parent.MapWindow.resize:

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2009-01-23 17:00:07 UTC (rev 35553)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2009-01-23 18:53:22 UTC (rev 35554)
@@ -57,10 +57,12 @@
 except ImportError, err:
     GV_LINES = None
     digitErr = err
-    #    print >> sys.stderr, "%sWARNING: Digitization tool is disabled (%s). " \
-    #          "Detailed information in README file." % \
-    #          (os.linesep, err)
+    print >> sys.stderr, "%sWARNING: Digitization tool is disabled (%s). " \
+          "Detailed information in README file." % \
+          (os.linesep, err)
 
+PseudoDC = wxvdigit.PseudoDC
+
 class AbstractDigit:
     """
     Abstract digitization class

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/Makefile
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/Makefile	2009-01-23 17:00:07 UTC (rev 35553)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/Makefile	2009-01-23 18:53:22 UTC (rev 35554)
@@ -11,10 +11,10 @@
 ifeq ($(findstring darwin,$(ARCH)),darwin)
 EXTRA_LIBS := -bundle -undefined dynamic_lookup $(EXTRA_LIBS)
 else
-EXTRA_LIBS := $(PYTHONLDFLAGS) $(EXTRA_LIBS) -lgdi
+EXTRA_LIBS := $(PYTHONLDFLAGS) $(EXTRA_LIBS)
 endif
 
-LOCAL_HEADERS = digit.h driver.h
+LOCAL_HEADERS = digit.h driver.h pseudodc.h
 
 ETCDIR = $(ETC)/wxpython
 
@@ -32,8 +32,8 @@
 endif
 endif
 
-$(LIB_NAME).i: digit.i dig_types.i driver.h digit.h
-	cat digit.i dig_types.i > $(LIB_NAME).i
+$(LIB_NAME).i: digit.i dig_types.i pseudodc.i driver.h digit.h
+	cat digit.i pseudodc.i dig_types.i > $(LIB_NAME).i
 	echo "/* auto-generated swig typedef file */" >> $(LIB_NAME).i
 	cat driver.h digit.h >> $(LIB_NAME).i
 

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp	2009-01-23 17:00:07 UTC (rev 35553)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp	2009-01-23 18:53:22 UTC (rev 35554)
@@ -36,8 +36,8 @@
 
     mapInfo = NULL;
 
-    dc = (wxPseudoDC *) device;
-    dcTmp = (wxPseudoDC *) deviceTmp;
+    dc = (gwxPseudoDC *) device;
+    dcTmp = (gwxPseudoDC *) deviceTmp;
 
     points = Vect_new_line_struct();
     pointsScreen = new wxList();
@@ -88,7 +88,7 @@
 */
 void DisplayDriver::SetDevice(void *device)
 {
-    dc = (wxPseudoDC *) device;
+    dc = (gwxPseudoDC *) device;
 
     return;
 }

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h	2009-01-23 17:00:07 UTC (rev 35553)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h	2009-01-23 18:53:22 UTC (rev 35554)
@@ -23,7 +23,7 @@
 #include <wx/string.h>
 
 #include <Python.h>
-#include <wx/wxPython/pseudodc.h>
+#include "pseudodc.h"
 
 extern "C" {
 #include <grass/gis.h>
@@ -34,7 +34,7 @@
 {
 private:
     friend class Digit;
-    wxPseudoDC *dc, *dcTmp;  // device content
+    gwxPseudoDC *dc, *dcTmp;  // device content
     wxWindow *parentWin;
     
     /* disabled due to expensive calling dc->SetId()
@@ -135,7 +135,7 @@
 		     double *, double *, double *);
     double DistanceInPixels(double);
 
-    int DrawCross(wxPseudoDC *, int, const wxPoint *, int size=5);
+    int DrawCross(gwxPseudoDC *, int, const wxPoint *, int size=5);
     int DrawArrow(double, double, double, double, double,
 		   int);
 

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver_draw.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver_draw.cpp	2009-01-23 17:00:07 UTC (rev 35553)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver_draw.cpp	2009-01-23 18:53:22 UTC (rev 35554)
@@ -223,7 +223,7 @@
     double x, y, z; // screen coordinates
     bool draw;      // draw object ?
     wxPen *pen;
-    wxPseudoDC *pdc;
+    gwxPseudoDC *pdc;
 
     pen = NULL;
     draw = false;
@@ -395,7 +395,7 @@
     int dcId;
     wxPoint *point;
     wxPen *pen;
-    wxPseudoDC *pdc;
+    gwxPseudoDC *pdc;
 
     if (!IsSelected(line) && !settings.vertex.enabled)
 	return -1;
@@ -471,7 +471,7 @@
     bool draw;
 
     wxPen *pen;
-    wxPseudoDC *pdc;
+    gwxPseudoDC *pdc;
 
     pdc = NULL;
 
@@ -563,7 +563,7 @@
    \return 1 on success
    \return -1 on failure
 */
-int DisplayDriver::DrawCross(wxPseudoDC *pdc, int line, const wxPoint* point, int size)
+int DisplayDriver::DrawCross(gwxPseudoDC *pdc, int line, const wxPoint* point, int size)
 {
     if (!pdc || !point)
 	return -1;

Copied: grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.cpp (from rev 35537, grass/trunk/gui/wxpython/vdigit/pseudodc.cpp)
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.cpp	                        (rev 0)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.cpp	2009-01-23 18:53:22 UTC (rev 35554)
@@ -0,0 +1,633 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        pseudodc.cpp
+// Purpose:     Implementation of the gwxPseudoDC Class
+// Author:      Paul Lanier
+// Modified by: Glynn Clements 2009-01-14
+// Created:     05/25/06
+// RCS-ID:      $Id: pseudodc.cpp 51090 2008-01-08 04:36:23Z RD $
+// Copyright:   (c) wxWidgets team
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+// For compilers that support precompilation, includes "wx.h".
+//include "wx/wxprec.h"
+
+#undef DEBUG
+#include <Python.h>
+#include <wx/wxPython/wxPython.h>
+#include "pseudodc.h"
+
+// wxList based class definitions
+#include <wx/listimpl.cpp>
+WX_DEFINE_LIST(gpdcOpList);
+WX_DEFINE_LIST(gpdcObjectList);
+
+//----------------------------------------------------------------------------
+// Helper functions used for drawing greyed out versions of objects
+//----------------------------------------------------------------------------
+wxColour &gwxMakeColourGrey(const wxColour &c)
+{
+    static wxColour rval;
+    rval.Set(byte((230-c.Red())*0.7+c.Red()),
+             byte((230-c.Green())*0.7+c.Green()),
+             byte((230-c.Blue())*0.7+c.Blue()));
+    return rval;
+}
+wxBrush &gwxGetGreyBrush(wxBrush &brush)
+{
+	static wxBrush b;
+	wxColour c;
+	b = brush;
+	c = gwxMakeColourGrey(brush.GetColour());
+	b.SetColour(c);
+	return b;
+}
+
+wxPen &gwxGetGreyPen(wxPen &pen)
+{
+	static wxPen p;
+	wxColour c;
+	p = pen;
+	c = gwxMakeColourGrey(pen.GetColour());
+	p.SetColour(c);
+	return p;
+}
+
+void gwxGreyOutImage(wxImage &img)
+{
+    unsigned char *data = img.GetData();
+    unsigned char r,g,b;
+    unsigned char mr,mg,mb;
+    int i, tst;
+    int len = img.GetHeight()*img.GetWidth()*3;
+    if (img.HasMask())
+    {
+        mr = img.GetMaskRed();
+        mg = img.GetMaskGreen();
+        mb = img.GetMaskBlue();
+    }
+    tst=0;
+    for (i=0;i<len;i+=3)
+    {
+        r=data[i]; g=data[i+1]; b=data[i+2];
+        if (!img.HasMask() || 
+            r!=mr || g!=mg || b!=mb)
+        {
+            if (!tst)
+            {
+                tst=1;
+            }
+            r = (unsigned char)((230.0-r)*0.7+r);
+            g = (unsigned char)((230.0-g)*0.7+g);
+            b = (unsigned char)((230.0-b)*0.7+b);
+            data[i]=r; data[i+1]=g; data[i+2]=b;
+        }
+    }
+}
+
+wxIcon &gwxGetGreyIcon(wxIcon &icon)
+{
+    wxBitmap bmp;
+    bmp.CopyFromIcon(icon);
+    wxImage img = bmp.ConvertToImage();
+    gwxGreyOutImage(img);
+    wxBitmap bmp2(img,32);
+    static wxIcon rval;
+    rval.CopyFromBitmap(bmp2);
+    return rval;
+}
+
+wxBitmap &gwxGetGreyBitmap(wxBitmap &bmp)
+{
+    wxImage img = bmp.ConvertToImage();
+    gwxGreyOutImage(img);
+    static wxBitmap rval(img,32);
+    return rval;
+}
+
+// ============================================================================
+// various gpdcOp class implementation methods
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// gpdcDrawPolyPolygonOp constructor
+// ----------------------------------------------------------------------------
+gpdcDrawPolyPolygonOp::gpdcDrawPolyPolygonOp(int n, int count[], wxPoint points[],
+                 wxCoord xoffset, wxCoord yoffset, int fillStyle) 
+{
+    m_n=n; m_xoffset=xoffset; m_yoffset=yoffset; m_fillStyle=fillStyle;
+    int total_n=0;
+    if (n)
+    {
+        m_count = new int[n];
+        for(int i=0; i<n; i++) 
+        {
+            total_n+=count[i];
+            m_count[i]=count[i];
+        }
+        if (total_n)
+        {
+            m_points = new wxPoint[total_n];
+            for(int j=0; j<total_n; j++)
+                m_points[j] = points[j];
+        }
+        else m_points=NULL;
+    }
+    else
+    {
+        m_points=NULL;
+        m_count=NULL;
+    }
+    m_totaln = total_n;
+}
+
+// ----------------------------------------------------------------------------
+// gpdcDrawPolyPolygonOp destructor
+// ----------------------------------------------------------------------------
+gpdcDrawPolyPolygonOp::~gpdcDrawPolyPolygonOp()
+{
+    if (m_points) delete m_points;
+    if (m_count) delete m_count;
+    m_points=NULL;
+    m_count=NULL;
+}
+        
+// ----------------------------------------------------------------------------
+// gpdcDrawLinesOp constructor
+// ----------------------------------------------------------------------------
+gpdcDrawLinesOp::gpdcDrawLinesOp(int n, wxPoint points[],
+             wxCoord xoffset, wxCoord yoffset)
+{
+    m_n=n; m_xoffset=xoffset; m_yoffset=yoffset;
+    if (n)
+    {
+        m_points = new wxPoint[n];
+        for (int i=0; i<n; i++)
+            m_points[i] = points[i];
+    }
+    else m_points=NULL;
+}
+
+// ----------------------------------------------------------------------------
+// gpdcDrawLinesOp destructor
+// ----------------------------------------------------------------------------
+gpdcDrawLinesOp::~gpdcDrawLinesOp()
+{
+    if (m_points) delete m_points;
+    m_points=NULL;
+}
+        
+// ----------------------------------------------------------------------------
+// gpdcDrawPolygonOp constructor
+// ----------------------------------------------------------------------------
+gpdcDrawPolygonOp::gpdcDrawPolygonOp(int n, wxPoint points[],
+             wxCoord xoffset, wxCoord yoffset, int fillStyle)
+{
+    m_n=n; m_xoffset=xoffset; m_yoffset=yoffset; m_fillStyle=fillStyle;
+    if (n)
+    {
+        m_points = new wxPoint[n];
+        for (int i=0; i<n; i++)
+            m_points[i] = points[i];
+    }
+    else m_points=NULL;
+}
+
+// ----------------------------------------------------------------------------
+// gpdcDrawPolygonOp destructor
+// ----------------------------------------------------------------------------
+gpdcDrawPolygonOp::~gpdcDrawPolygonOp()
+{
+    if (m_points) delete m_points;
+    m_points=NULL;
+}
+
+#if wxUSE_SPLINES
+// ----------------------------------------------------------------------------
+// gpdcDrawSplineOp constructor
+// ----------------------------------------------------------------------------
+gpdcDrawSplineOp::gpdcDrawSplineOp(int n, wxPoint points[])
+{
+    m_n=n;
+    if (n)
+    {
+        m_points = new wxPoint[n];
+        for(int i=0; i<n; i++)
+            m_points[i] = points[i];
+    }
+    else m_points=NULL;
+}
+
+// ----------------------------------------------------------------------------
+// gpdcDrawSplineOp destructor
+// ----------------------------------------------------------------------------
+gpdcDrawSplineOp::~gpdcDrawSplineOp()
+{
+    if (m_points) delete m_points;
+    m_points=NULL;
+}
+#endif // wxUSE_SPLINES
+
+// ============================================================================
+// gpdcObject implementation
+// ============================================================================
+// ----------------------------------------------------------------------------
+// DrawToDC - play back the op list to the DC 
+// ----------------------------------------------------------------------------
+void gpdcObject::DrawToDC(wxDC *dc)
+{
+    gpdcOpList::compatibility_iterator node = m_oplist.GetFirst(); 
+    while(node)
+    {
+        node->GetData()->DrawToDC(dc, m_greyedout);
+        node = node->GetNext();
+    }
+}
+
+// ----------------------------------------------------------------------------
+// Translate - translate all the operations by some dx,dy
+// ----------------------------------------------------------------------------
+void gpdcObject::Translate(wxCoord dx, wxCoord dy)
+{
+    gpdcOpList::compatibility_iterator node = m_oplist.GetFirst(); 
+    while(node)
+    {
+        node->GetData()->Translate(dx,dy);
+        node = node->GetNext();
+    }
+    if (m_bounded) 
+    {
+        m_bounds.x += dx;
+        m_bounds.y += dy;
+    }
+}
+
+// ----------------------------------------------------------------------------
+// SetGreyedOut - set the greyout member and cache grey versions of everything
+// if greyout is true
+// ----------------------------------------------------------------------------
+void gpdcObject::SetGreyedOut(bool greyout) 
+{
+    m_greyedout=greyout;
+    if (greyout)
+    {
+        gpdcOpList::compatibility_iterator node = m_oplist.GetFirst(); 
+        gpdcOp *obj;
+        while(node)
+        {
+            obj = node->GetData();
+            obj->CacheGrey();
+            node = node->GetNext();
+        }
+    }
+}
+
+// ============================================================================
+// gwxPseudoDC implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// Destructor
+// ----------------------------------------------------------------------------
+gwxPseudoDC::~gwxPseudoDC()
+{
+    // delete all the nodes in the list
+	RemoveAll();
+	
+}
+
+// ----------------------------------------------------------------------------
+// ClearAll - remove all nodes from list
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::RemoveAll(void)
+{
+    m_objectlist.Clear();
+    m_objectIndex.clear();
+    m_currId = -1;
+	m_lastObject = NULL;
+    
+}
+
+// ----------------------------------------------------------------------------
+// GetLen - return the number of operations in the current op list
+// ----------------------------------------------------------------------------
+int gwxPseudoDC::GetLen(void)
+{
+    gpdcObjectList::compatibility_iterator pt = m_objectlist.GetFirst();
+    int len=0;
+    while (pt) 
+    {
+        len += pt->GetData()->GetLen();
+        pt = pt->GetNext();
+    }
+    return len;
+}
+
+// ----------------------------------------------------------------------------
+// FindObject - find and return an object node by id.  If node doesn't exist
+//               and create is true then create one and return it.  Otherwise
+//               return NULL.
+// ----------------------------------------------------------------------------
+gpdcObject *gwxPseudoDC::FindObject(int id, bool create)
+{
+    // see if last operation was for same id
+    //~ if (m_lastObject && m_lastObject->GetId() == id)
+        //~ return m_lastObject;
+    // if not then search for it    
+    gpdcObjectHash::iterator lookup = m_objectIndex.find(id);
+    if (lookup == m_objectIndex.end()) {//not found
+        if (create) {
+            m_lastObject = new gpdcObject(id);
+            m_objectlist.Append(m_lastObject);
+			gpdcObjectHash::value_type insert(id, m_lastObject);
+            m_objectIndex.insert(insert);
+            return m_lastObject;
+        } else {
+            return NULL;
+        }
+    } else { //found
+        return lookup->second;
+    }
+}
+
+// ----------------------------------------------------------------------------
+// AddToList - Add a node to the list at the end (preserve draw order)
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::AddToList(gpdcOp *newOp)
+{
+    gpdcObject *obj = FindObject(m_currId, true);
+    obj->AddOp(newOp);
+}
+
+// ----------------------------------------------------------------------------
+// ClearID - remove all the operations associated with a single ID
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::ClearId(int id)
+{
+    gpdcObject *obj = FindObject(id);
+    if (obj) obj->Clear();
+}
+
+// ----------------------------------------------------------------------------
+// RemoveID - Remove the object node (and all operations) associated with an id
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::RemoveId(int id)
+{
+    gpdcObject *obj = FindObject(id);
+    if (obj) 
+    {
+        if (m_lastObject == obj)
+            m_lastObject = obj;
+        m_objectlist.DeleteObject(obj);
+    }
+    m_objectIndex.erase(id);
+}
+
+// ----------------------------------------------------------------------------
+// SetIdBounds - Set the bounding rect for a given id
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::SetIdBounds(int id, wxRect& rect)
+{
+    gpdcObject *obj = FindObject(id, true);
+    obj->SetBounds(rect);
+}
+
+// ----------------------------------------------------------------------------
+// GetIdBounds - Get the bounding rect for a given id
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::GetIdBounds(int id, wxRect& rect)
+{
+    gpdcObject *obj = FindObject(id);
+	if (obj && obj->IsBounded())
+		rect = obj->GetBounds();
+	else
+		rect.x = rect.y = rect.width = rect.height = 0;
+}
+
+// ----------------------------------------------------------------------------
+// TranslateId - Translate all the operations of a single id
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::TranslateId(int id, wxCoord dx, wxCoord dy)
+{
+    gpdcObject *obj = FindObject(id);
+    if (obj) obj->Translate(dx,dy);
+}
+
+// ----------------------------------------------------------------------------
+// DrawIdToDC - Draw a specific id to the dc passed in
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::DrawIdToDC(int id, wxDC *dc)
+{
+    gpdcObject *obj = FindObject(id);
+    if (obj) obj->DrawToDC(dc);
+}
+
+// ----------------------------------------------------------------------------
+// SetIdGreyedOut - Set the greyedout member of id
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::SetIdGreyedOut(int id, bool greyout)
+{
+    gpdcObject *obj = FindObject(id);
+    if (obj) obj->SetGreyedOut(greyout);
+}
+
+// ----------------------------------------------------------------------------
+// GetIdGreyedOut - Get the greyedout member of id
+// ----------------------------------------------------------------------------
+bool gwxPseudoDC::GetIdGreyedOut(int id)
+{
+    gpdcObject *obj = FindObject(id);
+    if (obj) return obj->GetGreyedOut();
+	else return false;
+}
+
+// ----------------------------------------------------------------------------
+// FindObjectsByBBox - Return a list of all the ids whose bounding boxes
+//                     contain (x,y)
+// ----------------------------------------------------------------------------
+PyObject *gwxPseudoDC::FindObjectsByBBox(wxCoord x, wxCoord y)
+{
+    //wxPyBlock_t blocked = wxPyBeginBlockThreads();
+    gpdcObjectList::compatibility_iterator pt = m_objectlist.GetFirst();
+    gpdcObject *obj;
+    PyObject* pyList = NULL;
+    pyList = PyList_New(0);
+    wxRect r;
+    while (pt) 
+    {
+        obj = pt->GetData();
+        r = obj->GetBounds();
+        if (obj->IsBounded() && r.Contains(x,y))
+        {
+            PyObject* pyObj = PyInt_FromLong((long)obj->GetId());
+            PyList_Insert(pyList, 0, pyObj);
+            Py_DECREF(pyObj);
+        }
+        pt = pt->GetNext();
+    }
+    //wxPyEndBlockThreads(blocked);
+    return pyList;
+}
+
+// ----------------------------------------------------------------------------
+// FindObjects - Return a list of all the ids that draw to (x,y)
+// ----------------------------------------------------------------------------
+PyObject *gwxPseudoDC::FindObjects(wxCoord x, wxCoord y, 
+                                  wxCoord radius, const wxColor& bg)
+{
+    //wxPyBlock_t blocked = wxPyBeginBlockThreads();
+    gpdcObjectList::compatibility_iterator pt = m_objectlist.GetFirst();
+    gpdcObject *obj;
+    PyObject* pyList = NULL;
+    pyList = PyList_New(0);
+    wxBrush bgbrush(bg);
+    wxPen bgpen(bg);
+    // special case radius = 0
+    if (radius == 0)
+    {
+        wxBitmap bmp(4,4,24);
+        wxMemoryDC memdc;
+        wxColor pix;
+        wxRect viewrect(x-2,y-2,4,4);
+        // setup the memdc for rendering
+        memdc.SelectObject(bmp);
+        memdc.SetBackground(bgbrush);
+        memdc.Clear();
+        memdc.SetDeviceOrigin(2-x,2-y);
+        while (pt) 
+        {
+            obj = pt->GetData();
+            if (obj->IsBounded() && obj->GetBounds().Contains(x,y))
+            {
+                // start clean
+                memdc.SetBrush(bgbrush);
+                memdc.SetPen(bgpen);
+                memdc.DrawRectangle(viewrect);
+                // draw the object
+                obj->DrawToDC(&memdc);
+                memdc.GetPixel(x,y,&pix);
+                // clear and update rgn2
+                if (pix != bg)
+                {
+                    PyObject* pyObj = PyInt_FromLong((long)obj->GetId());
+                    PyList_Insert(pyList, 0, pyObj);
+                    Py_DECREF(pyObj);
+                }
+            }
+            pt = pt->GetNext();
+        }
+        memdc.SelectObject(wxNullBitmap);
+    }
+    else
+    {
+        wxRect viewrect(x-radius,y-radius,2*radius,2*radius);
+        wxBitmap maskbmp(2*radius,2*radius,24);
+        wxMemoryDC maskdc;
+        // create bitmap with circle for masking
+        maskdc.SelectObject(maskbmp);
+        maskdc.SetBackground(*wxBLACK_BRUSH);
+        maskdc.Clear();
+        maskdc.SetBrush(*wxWHITE_BRUSH);
+        maskdc.SetPen(*wxWHITE_PEN);
+        maskdc.DrawCircle(radius,radius,radius);
+        // now setup a memdc for rendering our object
+        wxBitmap bmp(2*radius,2*radius,24);
+        wxMemoryDC memdc;
+        memdc.SelectObject(bmp);
+        // set the origin so (x,y) is in the bmp center
+        memdc.SetDeviceOrigin(radius-x,radius-y);
+        // a region will be used to see if the result is empty
+        wxRegion rgn2;
+        while (pt) 
+        {
+            obj = pt->GetData();
+            if (obj->IsBounded() && viewrect.Intersects(obj->GetBounds()))
+            {
+                // start clean
+                //memdc.Clear();
+                memdc.SetBrush(bgbrush);
+                memdc.SetPen(bgpen);
+                memdc.DrawRectangle(viewrect);
+                // draw the object
+                obj->DrawToDC(&memdc);
+                // remove background color
+                memdc.SetLogicalFunction(wxXOR);
+                memdc.SetBrush(bgbrush);
+                memdc.SetPen(bgpen);
+                memdc.DrawRectangle(viewrect);
+                memdc.SetLogicalFunction(wxCOPY);
+#ifdef __WXMAC__
+                // wxAND is not supported on wxMac, but it doesn't seem to
+                // hurt anything to use wxCOPY instead...
+                memdc.Blit(x-radius,y-radius,2*radius,2*radius,&maskdc,0,0,wxCOPY);
+#else
+                // AND with circle bitmap
+                memdc.Blit(x-radius,y-radius,2*radius,2*radius,&maskdc,0,0,wxAND);
+#endif
+                // clear and update rgn2
+                memdc.SelectObject(wxNullBitmap);
+                rgn2.Clear();
+                rgn2.Union(bmp, *wxBLACK);
+                //rgn2.Intersect(rgn);
+                memdc.SelectObject(bmp);
+                if (!rgn2.IsEmpty())
+                {
+                    PyObject* pyObj = PyInt_FromLong((long)obj->GetId());
+                    PyList_Insert(pyList, 0, pyObj);
+                    Py_DECREF(pyObj);
+                }
+            }
+            pt = pt->GetNext();
+        }
+        maskdc.SelectObject(wxNullBitmap);
+        memdc.SelectObject(wxNullBitmap);
+    }
+    //wxPyEndBlockThreads(blocked);
+    return pyList;
+}
+
+// ----------------------------------------------------------------------------
+// DrawToDCClipped - play back the op list to the DC but clip any objects
+//                   known to be not in rect.  This is a coarse level of 
+//                   clipping to speed things up when lots of objects are off 
+//                   screen and doesn't affect the dc level clipping
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::DrawToDCClipped(wxDC *dc, const wxRect& rect)
+{
+    gpdcObjectList::compatibility_iterator pt = m_objectlist.GetFirst();
+    gpdcObject *obj;
+    while (pt) 
+    {
+        obj = pt->GetData();
+        if (!obj->IsBounded() || rect.Intersects(obj->GetBounds()))
+            obj->DrawToDC(dc);
+        pt = pt->GetNext();
+    }
+}
+void gwxPseudoDC::DrawToDCClippedRgn(wxDC *dc, const wxRegion& region)
+{
+    gpdcObjectList::compatibility_iterator pt = m_objectlist.GetFirst();
+    gpdcObject *obj;
+    while (pt) 
+    {
+        obj = pt->GetData();
+        if (!obj->IsBounded() || 
+		    (region.Contains(obj->GetBounds()) != wxOutRegion))
+            obj->DrawToDC(dc);
+        pt = pt->GetNext();
+    }
+}
+
+// ----------------------------------------------------------------------------
+// DrawToDC - play back the op list to the DC 
+// ----------------------------------------------------------------------------
+void gwxPseudoDC::DrawToDC(wxDC *dc)
+{
+    gpdcObjectList::compatibility_iterator pt = m_objectlist.GetFirst();
+    while (pt) 
+    {
+        pt->GetData()->DrawToDC(dc);
+        pt = pt->GetNext();
+    }
+}
+        

Copied: grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.h (from rev 35537, grass/trunk/gui/wxpython/vdigit/pseudodc.h)
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.h	                        (rev 0)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.h	2009-01-23 18:53:22 UTC (rev 35554)
@@ -0,0 +1,826 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        pseudodc.h
+// Purpose:     gwxPseudoDC class
+// Author:      Paul Lanier
+// Modified by: Glynn Clements 2009-01-14
+// Created:     05/25/06
+// RCS-ID:      $Id: pseudodc.h 49047 2007-10-05 18:08:39Z RD $
+// Copyright:   (c) wxWidgets team
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+#ifndef _GWX_PSUEDO_DC_H_BASE_
+#define _GWX_PSUEDO_DC_H_BASE_
+
+//----------------------------------------------------------------------------
+// Base class for all gpdcOp classes
+//----------------------------------------------------------------------------
+class gpdcOp
+{
+    public:
+        // Constructor and Destructor
+        gpdcOp() {}
+        virtual ~gpdcOp() {}
+
+        // Virtual Drawing Methods
+        virtual void DrawToDC(wxDC *dc, bool grey=false)=0;
+        virtual void Translate(wxCoord dx, wxCoord dy) {}
+        virtual void CacheGrey() {}
+};
+
+//----------------------------------------------------------------------------
+// declare a list class for list of gpdcOps
+//----------------------------------------------------------------------------
+WX_DECLARE_LIST(gpdcOp, gpdcOpList);
+
+
+//----------------------------------------------------------------------------
+// Helper functions used for drawing greyed out versions of objects
+//----------------------------------------------------------------------------
+wxColour &gwxMakeColourGrey(const wxColour &c);
+wxBrush &gwxGetGreyBrush(wxBrush &brush);
+wxPen &gwxGetGreyPen(wxPen &pen);
+wxIcon &gwxGetGreyIcon(wxIcon &icon);
+wxBitmap &gwxGetGreyBitmap(wxBitmap &bmp);
+void gwxGreyOutImage(wxImage &img);
+
+//----------------------------------------------------------------------------
+// Classes derived from gpdcOp
+// There is one class for each method mirrored from wxDC to gwxPseudoDC
+//----------------------------------------------------------------------------
+class gpdcSetFontOp : public gpdcOp
+{
+    public:
+        gpdcSetFontOp(const wxFont& font) 
+            {m_font=font;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->SetFont(m_font);}
+    protected:
+        wxFont m_font;
+};
+
+class gpdcSetBrushOp : public gpdcOp
+{
+    public:
+        gpdcSetBrushOp(const wxBrush& brush) 
+            {m_greybrush=m_brush=brush;} 
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+        {
+            if (!grey) dc->SetBrush(m_brush);
+            else dc->SetBrush(m_greybrush);
+        }
+        virtual void CacheGrey() {m_greybrush=gwxGetGreyBrush(m_brush);}
+    protected:
+        wxBrush m_brush;
+        wxBrush m_greybrush;
+};
+
+class gpdcSetBackgroundOp : public gpdcOp
+{
+    public:
+        gpdcSetBackgroundOp(const wxBrush& brush) 
+            {m_greybrush=m_brush=brush;} 
+        virtual void DrawToDC(wxDC *dc, bool grey=false)
+        {
+            if (!grey) dc->SetBackground(m_brush);
+            else dc->SetBackground(m_greybrush);
+        }
+        virtual void CacheGrey() {m_greybrush=gwxGetGreyBrush(m_brush);}
+    protected:
+        wxBrush m_brush;
+        wxBrush m_greybrush;
+};
+
+class gpdcSetPenOp : public gpdcOp
+{
+    public:
+        gpdcSetPenOp(const wxPen& pen) 
+            {m_greypen=m_pen=pen;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false)
+        {
+            if (!grey) dc->SetPen(m_pen);
+            else dc->SetPen(m_greypen);
+        }
+        virtual void CacheGrey() {m_greypen=gwxGetGreyPen(m_pen);}
+    protected:
+        wxPen m_pen;
+        wxPen m_greypen;
+};
+
+class gpdcSetTextBackgroundOp : public gpdcOp
+{
+    public:
+        gpdcSetTextBackgroundOp(const wxColour& colour) 
+            {m_colour=colour;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+        {
+            if (!grey) dc->SetTextBackground(m_colour);
+            else dc->SetTextBackground(gwxMakeColourGrey(m_colour));
+        }
+    protected:
+        wxColour m_colour;
+};
+
+class gpdcSetTextForegroundOp : public gpdcOp
+{
+    public:
+        gpdcSetTextForegroundOp(const wxColour& colour) 
+            {m_colour=colour;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false)
+        {
+            if (!grey) dc->SetTextForeground(m_colour);
+            else dc->SetTextForeground(gwxMakeColourGrey(m_colour));
+        }
+    protected:
+        wxColour m_colour;
+};
+
+class gpdcDrawRectangleOp : public gpdcOp
+{
+    public:
+        gpdcDrawRectangleOp(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
+            {m_x=x; m_y=y; m_w=w; m_h=h;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawRectangle(m_x,m_y,m_w,m_h);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx;m_y+=dy;}
+    protected:
+        wxCoord m_x,m_y,m_w,m_h;
+};
+
+class gpdcDrawLineOp : public gpdcOp
+{
+    public:
+        gpdcDrawLineOp(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
+            {m_x1=x1; m_y1=y1; m_x2=x2; m_y2=y2;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawLine(m_x1,m_y1,m_x2,m_y2);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x1+=dx; m_y1+=dy; m_x2+=dx; m_y2+=dy;}
+    protected:
+        wxCoord m_x1,m_y1,m_x2,m_y2;
+};
+
+class gpdcSetBackgroundModeOp : public gpdcOp
+{
+    public:
+        gpdcSetBackgroundModeOp(int mode) {m_mode=mode;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->SetBackgroundMode(m_mode);}
+    protected:
+        int m_mode;
+};
+
+class gpdcDrawTextOp : public gpdcOp
+{
+    public:
+        gpdcDrawTextOp(const wxString& text, wxCoord x, wxCoord y)
+            {m_text=text; m_x=x; m_y=y;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawText(m_text, m_x, m_y);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxString m_text;
+        wxCoord m_x, m_y;
+};
+
+class gpdcClearOp : public gpdcOp
+{
+    public:
+        gpdcClearOp() {}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->Clear();}
+};
+
+class gpdcBeginDrawingOp : public gpdcOp
+{
+    public:
+        gpdcBeginDrawingOp() {}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {}
+};
+
+class gpdcEndDrawingOp : public gpdcOp
+{
+    public:
+        gpdcEndDrawingOp() {}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {}
+};
+
+class gpdcFloodFillOp : public gpdcOp
+{
+    public:
+        gpdcFloodFillOp(wxCoord x, wxCoord y, const wxColour& col,
+                   int style) {m_x=x; m_y=y; m_col=col; m_style=style;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+        {
+            if (!grey) dc->FloodFill(m_x,m_y,m_col,m_style);
+            else dc->FloodFill(m_x,m_y,gwxMakeColourGrey(m_col),m_style);
+        }
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxCoord m_x,m_y;
+        wxColour m_col;
+        int m_style;
+};
+
+class gpdcCrossHairOp : public gpdcOp
+{
+    public:
+        gpdcCrossHairOp(wxCoord x, wxCoord y) {m_x=x; m_y=y;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->CrossHair(m_x,m_y);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxCoord m_x,m_y;
+};
+
+class gpdcDrawArcOp : public gpdcOp
+{
+    public:
+        gpdcDrawArcOp(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
+                         wxCoord xc, wxCoord yc) 
+            {m_x1=x1; m_y1=y1; m_x2=x2; m_y2=y2; m_xc=xc; m_yc=yc;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawArc(m_x1,m_y1,m_x2,m_y2,m_xc,m_yc);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x1+=dx; m_x2+=dx; m_y1+=dy; m_y2+=dy;}
+    protected:
+        wxCoord m_x1,m_x2,m_xc;
+        wxCoord m_y1,m_y2,m_yc;
+};
+
+class gpdcDrawCheckMarkOp : public gpdcOp
+{
+    public:
+        gpdcDrawCheckMarkOp(wxCoord x, wxCoord y,
+                       wxCoord width, wxCoord height) 
+            {m_x=x; m_y=y; m_w=width; m_h=height;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawCheckMark(m_x,m_y,m_w,m_h);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxCoord m_x,m_y,m_w,m_h;
+};
+
+class gpdcDrawEllipticArcOp : public gpdcOp
+{
+    public:
+        gpdcDrawEllipticArcOp(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
+                         double sa, double ea) 
+            {m_x=x; m_y=y; m_w=w; m_h=h; m_sa=sa; m_ea=ea;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawEllipticArc(m_x,m_y,m_w,m_h,m_sa,m_ea);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxCoord m_x,m_y,m_w,m_h;
+        double m_sa,m_ea;
+};
+
+class gpdcDrawPointOp : public gpdcOp
+{
+    public:
+        gpdcDrawPointOp(wxCoord x, wxCoord y) 
+            {m_x=x; m_y=y;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawPoint(m_x,m_y);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxCoord m_x,m_y;
+};
+
+class gpdcDrawRoundedRectangleOp : public gpdcOp
+{
+    public:
+        gpdcDrawRoundedRectangleOp(wxCoord x, wxCoord y, wxCoord width, 
+                                  wxCoord height, double radius) 
+            {m_x=x; m_y=y; m_w=width; m_h=height; m_r=radius;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawRoundedRectangle(m_x,m_y,m_w,m_h,m_r);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxCoord m_x,m_y,m_w,m_h;
+        double m_r;
+};
+
+class gpdcDrawEllipseOp : public gpdcOp
+{
+    public:
+        gpdcDrawEllipseOp(wxCoord x, wxCoord y, wxCoord width, wxCoord height) 
+            {m_x=x; m_y=y; m_w=width; m_h=height;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawEllipse(m_x,m_y,m_w,m_h);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxCoord m_x,m_y,m_w,m_h;
+};
+
+class gpdcDrawIconOp : public gpdcOp
+{
+    public:
+        gpdcDrawIconOp(const wxIcon& icon, wxCoord x, wxCoord y) 
+            {m_icon=icon; m_x=x; m_y=y;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+        {
+            if (grey) dc->DrawIcon(m_greyicon,m_x,m_y);
+            else dc->DrawIcon(m_icon,m_x,m_y);
+        }
+        virtual void CacheGrey() {m_greyicon=gwxGetGreyIcon(m_icon);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxIcon m_icon;
+        wxIcon m_greyicon;
+        wxCoord m_x,m_y;
+};
+
+class gpdcDrawLinesOp : public gpdcOp
+{
+    public:
+        gpdcDrawLinesOp(int n, wxPoint points[],
+               wxCoord xoffset = 0, wxCoord yoffset = 0);
+        virtual ~gpdcDrawLinesOp();
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawLines(m_n,m_points,m_xoffset,m_yoffset);}
+        virtual void Translate(wxCoord dx, wxCoord dy)
+        { 
+            for(int i=0; i<m_n; i++)
+            {
+                m_points[i].x+=dx; 
+                m_points[i].y+=dy;
+            }
+        }
+    protected:
+        int m_n;
+        wxPoint *m_points;
+        wxCoord m_xoffset,m_yoffset;
+};
+
+class gpdcDrawPolygonOp : public gpdcOp
+{
+    public:
+        gpdcDrawPolygonOp(int n, wxPoint points[],
+                     wxCoord xoffset = 0, wxCoord yoffset = 0,
+                     int fillStyle = wxODDEVEN_RULE);
+        virtual ~gpdcDrawPolygonOp();
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawPolygon(m_n,m_points,m_xoffset,m_yoffset,m_fillStyle);}
+        
+        virtual void Translate(wxCoord dx, wxCoord dy)
+        { 
+            for(int i=0; i<m_n; i++)
+            {
+                m_points[i].x+=dx; 
+                m_points[i].y+=dy;
+            }
+        }
+    protected:
+        int m_n;
+        wxPoint *m_points;
+        wxCoord m_xoffset,m_yoffset;
+        int m_fillStyle;
+};
+
+class gpdcDrawPolyPolygonOp : public gpdcOp
+{
+    public:
+        gpdcDrawPolyPolygonOp(int n, int count[], wxPoint points[],
+                         wxCoord xoffset = 0, wxCoord yoffset = 0,
+                         int fillStyle = wxODDEVEN_RULE);
+        virtual ~gpdcDrawPolyPolygonOp();
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawPolyPolygon(m_n,m_count,m_points,
+                    m_xoffset,m_yoffset,m_fillStyle);}
+        virtual void Translate(wxCoord dx, wxCoord dy)
+        { 
+            for(int i=0; i<m_totaln; i++)
+            {
+                m_points[i].x += dx; 
+                m_points[i].y += dy;
+            }
+        }
+    protected:
+        int m_n;
+        int m_totaln;
+        int *m_count;
+        wxPoint *m_points;
+        wxCoord m_xoffset, m_yoffset;
+        int m_fillStyle;
+};
+
+class gpdcDrawRotatedTextOp : public gpdcOp
+{
+    public:
+        gpdcDrawRotatedTextOp(const wxString& text, wxCoord x, wxCoord y, double angle) 
+            {m_text=text; m_x=x; m_y=y; m_angle=angle;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawRotatedText(m_text,m_x,m_y,m_angle);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxString m_text;
+        wxCoord m_x,m_y;
+        double m_angle;
+};
+
+class gpdcDrawBitmapOp : public gpdcOp
+{
+    public:
+        gpdcDrawBitmapOp(const wxBitmap &bmp, wxCoord x, wxCoord y,
+                        bool useMask = false) 
+            {m_bmp=bmp; m_x=x; m_y=y; m_useMask=useMask;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+        {
+            if (grey) dc->DrawBitmap(m_greybmp,m_x,m_y,m_useMask);
+            else dc->DrawBitmap(m_bmp,m_x,m_y,m_useMask);
+        }
+        virtual void CacheGrey() {m_greybmp=gwxGetGreyBitmap(m_bmp);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_x+=dx; m_y+=dy;}
+    protected:
+        wxBitmap m_bmp;
+        wxBitmap m_greybmp;
+        wxCoord m_x,m_y;
+        bool m_useMask;
+};
+
+class gpdcDrawLabelOp : public gpdcOp
+{
+    public:
+        gpdcDrawLabelOp(const wxString& text,
+                           const wxBitmap& image,
+                           const wxRect& rect,
+                           int alignment = wxALIGN_LEFT | wxALIGN_TOP,
+                           int indexAccel = -1)
+            {m_text=text; m_image=image; m_rect=rect; 
+             m_align=alignment; m_iAccel=indexAccel;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) 
+            {dc->DrawLabel(m_text,m_image,m_rect,m_align,m_iAccel);}
+        virtual void Translate(wxCoord dx, wxCoord dy) 
+            {m_rect.x+=dx; m_rect.y+=dy;}
+    protected:
+        wxString m_text;
+        wxBitmap m_image;
+        wxRect m_rect;
+        int m_align;
+        int m_iAccel;
+};
+
+#if wxUSE_SPLINES
+class gpdcDrawSplineOp : public gpdcOp
+{
+    public:
+        gpdcDrawSplineOp(int n, wxPoint points[]);
+        virtual ~gpdcDrawSplineOp();
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawSpline(m_n,m_points);}
+        virtual void Translate(wxCoord dx, wxCoord dy)
+        {
+            int i;
+            for(i=0; i<m_n; i++)
+                m_points[i].x+=dx; m_points[i].y+=dy;
+        }
+    protected:
+        wxPoint *m_points;
+        int m_n;
+};
+#endif // wxUSE_SPLINES
+
+#if wxUSE_PALETTE
+class gpdcSetPaletteOp : public gpdcOp
+{
+    public:
+        gpdcSetPaletteOp(const wxPalette& palette) {m_palette=palette;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->SetPalette(m_palette);}
+    protected:
+        wxPalette m_palette;
+};
+#endif // wxUSE_PALETTE
+
+class gpdcSetLogicalFunctionOp : public gpdcOp
+{
+    public:
+        gpdcSetLogicalFunctionOp(int function) {m_function=function;}
+        virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->SetLogicalFunction(m_function);}
+    protected:
+        int m_function;
+};
+
+//----------------------------------------------------------------------------
+// gpdcObject type to contain list of operations for each real (Python) object
+//----------------------------------------------------------------------------
+class gpdcObject
+{
+    public:
+        gpdcObject(int id) 
+            {m_id=id; m_bounded=false; m_oplist.DeleteContents(true);
+             m_greyedout=false;}
+
+        virtual ~gpdcObject() {m_oplist.Clear();}
+        
+        // Protected Member Access
+        void SetId(int id) {m_id=id;}
+        int  GetId() {return m_id;}
+        void   SetBounds(wxRect& rect) {m_bounds=rect; m_bounded=true;}
+        wxRect GetBounds() {return m_bounds;}
+        void SetBounded(bool bounded) {m_bounded=bounded;}
+        bool IsBounded() {return m_bounded;}
+        void SetGreyedOut(bool greyout=true);
+        bool GetGreyedOut() {return m_greyedout;}
+    
+        // Op List Management Methods
+        void Clear() {m_oplist.Clear();}
+        void AddOp(gpdcOp *op) 
+        {
+            m_oplist.Append(op);
+            if (m_greyedout) op->CacheGrey();
+        }
+        int  GetLen() {return m_oplist.GetCount();}
+        virtual void Translate(wxCoord dx, wxCoord dy);
+        
+        // Drawing Method
+        virtual void DrawToDC(wxDC *dc);
+    protected:
+        int m_id; // id of object (associates this gpdcObject
+                  //               with a Python object with same id)
+        wxRect m_bounds;  // bounding rect of this object
+        bool m_bounded;   // true if bounds is valid, false by default
+        gpdcOpList m_oplist; // list of operations for this object
+        bool m_greyedout; // if true then draw this object in greys only
+};
+
+
+//----------------------------------------------------------------------------
+// Declare a wxList to hold all the objects.  List order reflects drawing
+// order (Z order) and is the same order as objects are added to the list
+//----------------------------------------------------------------------------
+class gpdcObjectList;
+WX_DECLARE_LIST(gpdcObject, gpdcObjectList);
+
+//Declare a hashmap that maps from ids to nodes in the object list.
+WX_DECLARE_HASH_MAP(
+    int,
+    gpdcObject *,
+    wxIntegerHash,
+    wxIntegerEqual,
+    gpdcObjectHash
+);
+
+
+// ----------------------------------------------------------------------------
+// gwxPseudoDC class
+// ----------------------------------------------------------------------------
+// This is the actual PseudoDC class
+// This class stores a list of recorded dc operations in m_list
+// and plays them back to a real dc using DrawToDC or DrawToDCClipped.
+// Drawing methods are mirrored from wxDC but add nodes to m_list 
+// instead of doing any real drawing.
+// ----------------------------------------------------------------------------
+class gwxPseudoDC : public wxObject
+{
+public:
+    gwxPseudoDC() 
+        {m_currId=-1; m_lastObject=NULL; m_objectlist.DeleteContents(true);m_objectIndex.clear();}
+    ~gwxPseudoDC();
+    // ------------------------------------------------------------------------
+    // List managment methods
+    // 
+    void RemoveAll();
+    int GetLen();
+    
+    // ------------------------------------------------------------------------
+    // methods for managing operations by ID
+    // 
+    // Set the Id for all subsequent operations (until SetId is called again)
+    void SetId(int id) {m_currId = id;}
+    // Remove all the operations associated with an id so it can be redrawn
+    void ClearId(int id);
+    // Remove the object node (and all operations) associated with an id
+    void RemoveId(int id);
+    // Set the bounding rect of a given object
+    // This will create an object node if one doesn't exist
+    void SetIdBounds(int id, wxRect& rect);
+    void GetIdBounds(int id, wxRect& rect);
+    // Translate all the operations for this id
+    void TranslateId(int id, wxCoord dx, wxCoord dy);
+    // Grey-out an object
+    void SetIdGreyedOut(int id, bool greyout=true);
+    bool GetIdGreyedOut(int id);
+    // Find Objects at a point.  Returns Python list of id's
+    // sorted in reverse drawing order (result[0] is top object)
+    // This version looks at drawn pixels
+    PyObject *FindObjects(wxCoord x, wxCoord y, 
+                          wxCoord radius=1, const wxColor& bg=*wxWHITE);
+    // This version only looks at bounding boxes
+    PyObject *FindObjectsByBBox(wxCoord x, wxCoord y);
+
+    // ------------------------------------------------------------------------
+    // Playback Methods
+    //
+    // draw to dc but skip objects known to be outside of rect
+    // This is a coarse level of clipping to speed things up 
+    // when lots of objects are off screen and doesn't affect the dc level 
+    // clipping
+    void DrawToDCClipped(wxDC *dc, const wxRect& rect);
+        void DrawToDCClippedRgn(wxDC *dc, const wxRegion& region);
+    // draw to dc with no clipping (well the dc will still clip)
+    void DrawToDC(wxDC *dc);
+    // draw a single object to the dc
+    void DrawIdToDC(int id, wxDC *dc);
+
+    // ------------------------------------------------------------------------
+    // Hit Detection Methods
+    //
+    // returns list of object with a drawn pixel within radius pixels of (x,y)
+    // the list is in reverse draw order so last drawn is first in list
+    // PyObject *HitTest(wxCoord x, wxCoord y, double radius)
+    // returns list of objects whose bounding boxes include (x,y)
+    // PyObject *HitTestBB(wxCoord x, wxCoord y)
+    
+        
+    // ------------------------------------------------------------------------
+    // Methods mirrored from wxDC
+    //
+    void FloodFill(wxCoord x, wxCoord y, const wxColour& col,
+                   int style = wxFLOOD_SURFACE)
+        {AddToList(new gpdcFloodFillOp(x,y,col,style));}
+    void FloodFill(const wxPoint& pt, const wxColour& col,
+                   int style = wxFLOOD_SURFACE)
+        { FloodFill(pt.x, pt.y, col, style); }
+
+    void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
+        {AddToList(new gpdcDrawLineOp(x1, y1, x2, y2));}
+    void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
+        { DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
+
+    void CrossHair(wxCoord x, wxCoord y)
+        {AddToList(new gpdcCrossHairOp(x,y));}
+    void CrossHair(const wxPoint& pt)
+        { CrossHair(pt.x, pt.y); }
+
+    void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
+                 wxCoord xc, wxCoord yc)
+        {AddToList(new gpdcDrawArcOp(x1,y1,x2,y2,xc,yc));}
+    void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
+        { DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
+
+    void DrawCheckMark(wxCoord x, wxCoord y,
+                       wxCoord width, wxCoord height)
+        {AddToList(new gpdcDrawCheckMarkOp(x,y,width,height));}
+    void DrawCheckMark(const wxRect& rect)
+        { DrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
+
+    void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
+                         double sa, double ea)
+        {AddToList(new gpdcDrawEllipticArcOp(x,y,w,h,sa,ea));}
+    void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
+                         double sa, double ea)
+        { DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
+
+    void DrawPoint(wxCoord x, wxCoord y)
+        {AddToList(new gpdcDrawPointOp(x,y));}
+    void DrawPoint(const wxPoint& pt)
+        { DrawPoint(pt.x, pt.y); }
+
+    void DrawPolygon(int n, wxPoint points[],
+                     wxCoord xoffset = 0, wxCoord yoffset = 0,
+                     int fillStyle = wxODDEVEN_RULE)
+        {AddToList(new gpdcDrawPolygonOp(n,points,xoffset,yoffset,fillStyle));}
+
+    void DrawPolyPolygon(int n, int count[], wxPoint points[],
+                         wxCoord xoffset = 0, wxCoord yoffset = 0,
+                         int fillStyle = wxODDEVEN_RULE)
+        {AddToList(new gpdcDrawPolyPolygonOp(n,count,points,xoffset,yoffset,fillStyle));}
+
+    void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+        {AddToList(new gpdcDrawRectangleOp(x, y, width, height));}
+    void DrawRectangle(const wxPoint& pt, const wxSize& sz)
+        { DrawRectangle(pt.x, pt.y, sz.x, sz.y); }
+    void DrawRectangle(const wxRect& rect)
+        { DrawRectangle(rect.x, rect.y, rect.width, rect.height); }
+
+    void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
+                              double radius)
+        {AddToList(new gpdcDrawRoundedRectangleOp(x,y,width,height,radius));}
+    void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
+                             double radius)
+        { DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
+    void DrawRoundedRectangle(const wxRect& r, double radius)
+        { DrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
+
+    void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
+        { DrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
+    void DrawCircle(const wxPoint& pt, wxCoord radius)
+        { DrawCircle(pt.x, pt.y, radius); }
+
+    void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+        {AddToList(new gpdcDrawEllipseOp(x,y,width,height));}
+    void DrawEllipse(const wxPoint& pt, const wxSize& sz)
+        { DrawEllipse(pt.x, pt.y, sz.x, sz.y); }
+    void DrawEllipse(const wxRect& rect)
+        { DrawEllipse(rect.x, rect.y, rect.width, rect.height); }
+
+    void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
+        {AddToList(new gpdcDrawIconOp(icon,x,y));}
+    void DrawIcon(const wxIcon& icon, const wxPoint& pt)
+        { DrawIcon(icon, pt.x, pt.y); }
+
+    void DrawLines(int n, wxPoint points[],
+               wxCoord xoffset = 0, wxCoord yoffset = 0)
+        {AddToList(new gpdcDrawLinesOp(n,points,xoffset,yoffset));}
+
+    void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
+                    bool useMask = false)
+        {AddToList(new gpdcDrawBitmapOp(bmp,x,y,useMask));}
+    void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
+                    bool useMask = false)
+        { DrawBitmap(bmp, pt.x, pt.y, useMask); }
+
+    void DrawText(const wxString& text, wxCoord x, wxCoord y)
+        {AddToList(new gpdcDrawTextOp(text, x, y));}
+    void DrawText(const wxString& text, const wxPoint& pt)
+        { DrawText(text, pt.x, pt.y); }
+
+    void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
+        {AddToList(new gpdcDrawRotatedTextOp(text,x,y,angle));}
+    void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
+        { DrawRotatedText(text, pt.x, pt.y, angle); }
+
+    // this version puts both optional bitmap and the text into the given
+    // rectangle and aligns is as specified by alignment parameter; it also
+    // will emphasize the character with the given index if it is != -1 
+    void DrawLabel(const wxString& text,
+                           const wxBitmap& image,
+                           const wxRect& rect,
+                           int alignment = wxALIGN_LEFT | wxALIGN_TOP,
+                           int indexAccel = -1)
+        {AddToList(new gpdcDrawLabelOp(text,image,rect,alignment,indexAccel));}
+
+    void DrawLabel(const wxString& text, const wxRect& rect,
+                   int alignment = wxALIGN_LEFT | wxALIGN_TOP,
+                   int indexAccel = -1)
+        { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); }
+
+/*?????? I don't think that the source dc would stick around
+    void Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
+              wxDC *source, wxCoord xsrc, wxCoord ysrc,
+              int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
+                {AddToList(new gpdcBlitOp(xdest,ydest,width,height,source,xsrc,
+                                         ysrc,rop,useMask,xsrcMask,ysrcMask));}
+    void Blit(const wxPoint& destPt, const wxSize& sz,
+              wxDC *source, const wxPoint& srcPt,
+              int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition)
+    {
+        Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y, 
+             rop, useMask, srcPtMask.x, srcPtMask.y);
+    }
+??????*/
+
+#if wxUSE_SPLINES
+    void DrawSpline(int n, wxPoint points[])
+        {AddToList(new gpdcDrawSplineOp(n,points));}
+#endif // wxUSE_SPLINES
+
+#if wxUSE_PALETTE
+    void SetPalette(const wxPalette& palette)
+        {AddToList(new gpdcSetPaletteOp(palette));}
+#endif // wxUSE_PALETTE
+
+    void SetLogicalFunction(int function)
+        {AddToList(new gpdcSetLogicalFunctionOp(function));}
+    void SetFont(const wxFont& font) 
+        {AddToList(new gpdcSetFontOp(font));}
+    void SetPen(const wxPen& pen)
+        {AddToList(new gpdcSetPenOp(pen));}
+    void SetBrush(const wxBrush& brush)
+        {AddToList(new gpdcSetBrushOp(brush));}
+    void SetBackground(const wxBrush& brush)
+        {AddToList(new gpdcSetBackgroundOp(brush));}
+    void SetBackgroundMode(int mode)
+        {AddToList(new gpdcSetBackgroundModeOp(mode));}
+    void SetTextBackground(const wxColour& colour)
+        {AddToList(new gpdcSetTextBackgroundOp(colour));}
+    void SetTextForeground(const wxColour& colour)
+        {AddToList(new gpdcSetTextForegroundOp(colour));}
+
+    void Clear()
+        {AddToList(new gpdcClearOp());}
+    void BeginDrawing()
+        {AddToList(new gpdcBeginDrawingOp());}
+    void EndDrawing()
+        {AddToList(new gpdcEndDrawingOp());}
+
+protected:
+    // ------------------------------------------------------------------------
+    // protected helper methods
+    void AddToList(gpdcOp *newOp);
+    gpdcObject *FindObject(int id, bool create=false);
+    
+    // ------------------------------------------------------------------------
+    // Data members
+    // 
+    int m_currId; // id to use for operations done on the PseudoDC
+    gpdcObject *m_lastObject; // used to find last used object quickly
+    gpdcObjectList m_objectlist; // list of objects
+    gpdcObjectHash m_objectIndex; //id->object lookup index
+    
+};
+
+#endif
+

Copied: grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.i (from rev 35537, grass/trunk/gui/wxpython/vdigit/pseudodc.i)
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.i	                        (rev 0)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/pseudodc.i	2009-01-23 18:53:22 UTC (rev 35554)
@@ -0,0 +1,39 @@
+
+%{
+#include <wx/wxPython/wxPython.h>
+#include <wx/wxPython/pyclasses.h>
+%}
+
+%{
+#include "pseudodc.h"
+%}
+
+%rename(PseudoDC) gwxPseudoDC;
+
+%typemap(out) wxRect {
+	$result = Py_BuildValue("iiii", $1.x, $1.y, $1.width, $1.height);
+}
+
+class gwxPseudoDC
+{
+public:
+	gwxPseudoDC();
+	~gwxPseudoDC();
+	void Clear();
+	void RemoveAll();
+	void RemoveId(int id);
+	%extend {
+		void DrawToDC(void *dc) {
+			self->DrawToDC((wxDC *) dc);
+		}
+		void DrawToDCClipped(void *dc, const wxRect& rect) {
+			self->DrawToDCClipped((wxDC *) dc, rect);
+		}
+		wxRect GetIdBounds(int id) {
+			wxRect rect;
+			self->GetIdBounds(id, rect);
+			return rect;
+		}
+	}
+};
+



More information about the grass-commit mailing list