[wxPython-users] select object by box in PseudoDC
Christopher Barker
Chris.Barker at noaa.gov
Thu Jul 5 09:44:33 PDT 2007
Martin Landa wrote:
> maybe a silly question, but anyway. I am trying to select ids of
> objects in PseudoDC by box (rectangle bounding box). Is there any way
> how to do it? I am trying to use FindObjects() or
> FindObjectsByBBox()...
wx.DCs don't have any thing like this. It's up to you to keep track of
what you've drawn. I suppose PseudoDC could add this feature, but as
you've noticed, it doesn't appear to.
There are a number of ways of doing it. in wx.lib.floatcanvas, I set it
up so that an extra bitmap is kept in memory in which you draw the
objects you want to find, each in a different color. checking the color
of pixel tells you which object is hit. This creates some overhead when
drawing, but is lightning fast when doing the hit-testing. However, this
approach doesn't allow you to find multiple overlapping objects.
It wouldn't be that hard to just store the Bounding Boxes of all your
objects and search that list. If you have a LOT, and need to search
fast, you might need a spatial index (quad tree, B-tree, etc).
wx.GraphicsContext has methods for checking the bounding box of objects.
It might be nice to make a PseudoDC that uses that -- for better drawing
as well.
Good luck!
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list