Looks like good progress!

A couple notes, having looked at this VERY quickly:

https://vid.me/GuFR
>
>
cool! -- but yes, I see your issue.


> The angle of the box and the arrow is updated in the OnMove function in
> logicCanvas.py. In that same file, here is the section of code where I'm
> grabbing a rotated image from self.Image:
>
>
> https://github.com/Castronova/EMIT/blob/mike-experiment/gui/controller/logicCanvas.py#L52-69
>
> As you suggested, I tried to make a subclass of ScaledBitmap with a
> rotation feature. I'm still fairly new to Python, so I apologize if any of
> this a poor implementation. Perhaps there is something I'm doing wrong
> there, because it does not appear to rotate around the CENTER of the image,
> as you can see in those videos.
>

I see this:

# Using ImageMidPoint seems to do the same thing as (0,0)
Img = self.Image.Rotate(self.RotationAngle, (0,0))

so maybe some sort of bug in wx.Image. I"d try some test code ans use
wx.Image.SaveFile() to save it out and see if produces what you expect when
you change the centre_of_rotation parameter.

But another issue is that when you rotate a rectangular image, the
resulting image may not be the same size (or it would cut off the corners.
So when you rotate the image, you may have to re-set something in
ScaledBitmap, so it can place the new one in the right place. note that wx
naturally draws images placed on a location on the corner, so to place it
relative to the center point, it needs to know what size it is -- if the
size is wrong, the shift to the center point will be wrong.

re-setting self.self.Height and self.Width should do it.

Also, you may want to derive from FloatCanvas.Bitmap, rather than from
ScaledBitmap, though it may make no difference since you are overriding the
differences, anyway...

If you'd like to run this yourself, feel free to pull down the latest
> commit of my branch called 'mike-experiment':
> https://github.com/Castronova/EMIT/tree/mike-experiment
>

no time for that now -- but it looks good.


> One more issue that we're having that you might be able to help with is
> bindings. For some reason, the bindings are not being added. There is no
> warning or error - they simply don't work. Here is where we add them:
>
>
> https://github.com/Castronova/EMIT/blob/mike-experiment/gui/controller/logicCanvas.py#L368-369
>
> When our arrow was a simple Polygon object, it worked just fine. You can
> see the code for that old function in createArrowOld. If you have any ideas
> what might be causing either of those issues, it would be greatly helpful
> for us!
>

I think so -- Floatcanvas does hit detection by drawing each object in a
unique color on an offscreen bitmap -- then it can check the color of a
pixel to know what got hit. For an object to be hit-able, it must
impoliment drawing to teh Hit Test bitmap in its _Draw method. Somethign
like:

            if HTdc and self.HitAble:
                HTdc.SetPen(self.HitPen)
                HTdc.SetBrush(self.HitBrush)
                HTdc.DrawRectanglePointSize(XY, (W, H) )

See the ScaledBitmap example.

That should do it

   -CHB


> On Tue, Jun 23, 2015 at 9:17 AM, Chris Barker <[email protected]>
> wrote:
>
>> On Tue, Jun 23, 2015 at 7:33 AM, Michael Gallagher <
>> [email protected]> wrote:
>>
>>> Thank you very much for getting back to me. I had a quick glance over
>>> the ScaledBitmap class, and I think I have a grasp on what might need to
>>> happen. I'll be able to dig back into this next week most likely, and I'm
>>> sure I'll have more questions.
>>>
>>
>> Sounds good -- feel free to send question, and also be sure to let us
>> know once you get it all figured out!
>>
>> -Chris
>>
>>
>>
>>> Mike
>>>
>>> On Mon, Jun 22, 2015 at 2:11 PM, Chris Barker <[email protected]>
>>> wrote:
>>>
>>>> By the way,
>>>>
>>>> If you do add rotation to bitmaps, I'll probably want to add it to FC
>>>> as a regular feature. So let me know how it works out.
>>>>
>>>> -CHB
>>>>
>>>>
>>>> On Mon, Jun 22, 2015 at 12:03 PM, Chris Barker <[email protected]>
>>>> wrote:
>>>>
>>>>> Note: I've cc-d this to the floatcanvas mailing list:
>>>>>
>>>>> http://mail.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
>>>>>
>>>>> please keep the conversation there, so it will get archived.
>>>>>
>>>>> It is a VERY low traffic list!
>>>>>
>>>>>
>>>>> Hi Michael,
>>>>>
>>>>> Glad you're finding FC useful!
>>>>>
>>>>> I'm currently a CS student for Utah State University and I'm working
>>>>>> with the Utah Water Research Lab on this project
>>>>>> <https://github.com/Castronova/EMIT>, where we're using wxPython and
>>>>>> your wonderful project, FloatCanvas. I'm not a hydrologist, and I'm 
>>>>>> fairly
>>>>>> new on this project so I'm not quite sure what our project is entirely 
>>>>>> for.
>>>>>> Needless to say though, it's going to help the University's research.
>>>>>>
>>>>>
>>>>> at a glance it does look pretty cool.
>>>>>
>>>>>
>>>>>> One of the things I've been assigned is to improve the UI a bit.
>>>>>> Here's our FloatCanvas part of the application:
>>>>>>
>>>>>> [image: Inline image 1]
>>>>>>
>>>>>> Unfortunately the way this spline is being drawn (the folks who wrote
>>>>>> this didn't realize that there was an existing spline object in
>>>>>> floatcanvas) is very inefficient.
>>>>>>
>>>>>
>>>>> at a glance, I saw a bunch of code for drawing the arrow -- did you
>>>>> look at the code for the Arrow and ArrowLIne objects?
>>>>>
>>>>> but it looks like you may want to use a bitmap for the arrow anyway --
>>>>> it does let you make it prettier.
>>>>>
>>>>>
>>>>>
>>>>>> When these boxes are dragged around, we get major frame-rate drops.
>>>>>> Luckily I've been able to begin the work on sorting this out to improve
>>>>>> dragging-and-dropping, and one of the things I'm struggling with is 
>>>>>> knowing
>>>>>> what to do about rotating a bitmap. I have this icon here:
>>>>>>
>>>>>> [image: Inline image 2]
>>>>>>
>>>>>> I would like this PNG to replace the arrow you see above in the main
>>>>>> screenshot. However, this requires us to rotate the bitmap as these boxes
>>>>>> are dragged around.
>>>>>>
>>>>> Currently I don't think there's a way to do this in FloatCanvas.
>>>>>>
>>>>>
>>>>> nope -- I only supported axis-aligned bitmaps so far.
>>>>>
>>>>> The best solution I can come up with for now is to remove, and rotate
>>>>>> the icon as a wxImage, and then re-add it on each frame draw. I'm not 
>>>>>> sure
>>>>>> this is the best way of doing it though, and I thought I'd reach out to 
>>>>>> you
>>>>>> and get your opinion on the matter.
>>>>>>
>>>>>
>>>>> yeah, you should be able to do better.
>>>>>
>>>>> You probably don't want the arrow to change size as you zoom, so you
>>>>> are likely using a Bitmap object.
>>>>>
>>>>> But take a look at the ScaledBitmap object code to get an idea:
>>>>>
>>>>> it stores a wx.Image object.
>>>>>
>>>>> In the _Draw method, it scales the Image, then draws it.
>>>>>
>>>>> Note that it caches the scaled version, so that it doesn't need to
>>>>> re-scale unless the size changes.
>>>>>
>>>>> So: I'd subclass, or simply copy the Bitmap object, and add an
>>>>> attribute for rotation angle, then write a _Draw method that does the
>>>>> rotation on the fly, similarly to how the ScaledImage object does the
>>>>> re-scaling.
>>>>>
>>>>> That should be pretty fast, and if you cache the rotated bitmap, then
>>>>> it will be blazingly fast when the angle hasn't changed.
>>>>>
>>>>> Also -- once you'
>>>>> ve got that working, I'd either:
>>>>>
>>>>> Make a Group object that puts teh line and the arrow together.
>>>>>
>>>>> or
>>>>>
>>>>> make Custom DrawObject that draws both the line and the arrow.
>>>>>
>>>>> I always intended it to be easy to write your own DrawObjects -- but
>>>>> never documented it very well...
>>>>>
>>>>> Do take a look at:
>>>>>
>>>>> http://trac.paulmcnett.com/floatcanvas
>>>>>
>>>>> if you haven't already -- there are a few examples there.
>>>>>
>>>>> And I hope you've found the examples in the demos dir in teh source:
>>>>>
>>>>> http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/
>>>>>
>>>>> There is a lot there!
>>>>>
>>>>> -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
>>>>>
>>>>> [email protected]
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> 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
>>>>
>>>> [email protected]
>>>>
>>>
>>>
>>
>>
>> --
>>
>> 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
>>
>> [email protected]
>>
>
>


-- 

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

[email protected]
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to