[Drawkit] Object manipulation notification

Graham Cox graham.cox at bigpond.com
Mon Jun 30 08:43:50 PDT 2008


I agree with you that notifications for object adding/removal would be  
useful - in fact when I read that my first thought was that I already  
added that ages ago but you're right - they are not there. So I will  
add that.

For general notification when any object changes, you might be able to  
make use of the update mechanism. When any object changes in any way  
that alters its appearance, it calls -notifyVisualChange. Ultimately  
this passes up to the view(s) and invokes the -setNeedsDisplayInRect:  
method, but you can also intercept it at a variety of levels to find  
out when objects change. If you need to know which object changed, the  
highest point you can get that information is in DKObjectOwnerLayer - 
drawable:needsDisplayInRect: After that the information about the  
object is not propagated as it just becomes a generic rect update.  
 From there it goes to:

DKLayer - setNeedsDisplayInRect:
DKDrawing -setNeedsDisplayInRect:
DKViewController -setViewNeedsDisplayInRect:
NSView -setNeedsDisplayInRect:

One thing to bear in mind is that if you hook into this, you will get  
a flood of notifications, because in many situations an object needs  
to call this both before and after making the change to ensure that  
its old appearance gets erased if necessary. You can't tell the  
difference between the 'before' and 'after' messages easily either.

There is also a -notifyStatusChange for non-visual changes but at  
present it's not called by very much.

I could buy an argument for having specific notifications for these,  
but until now I haven't thought that necessary. If you can give me  
more info about why your logic requires this I might be able to think  
of a better way.

cheers, Graham

On 1 Jul 2008, at 1:17 am, Linan Wang wrote:

> Hi everyone,
>
> I'm working on a program that uses DrawKit to help architects  
> conduct site analysis. Basically I'm using DKDrawing as a site map,  
> and DKDrawableObject as arbitrary objects like buildings, streets  
> etc. The logic of the program need to know when an object is  
> modified (resize, rotate, etc), and the site map is modified (add  
> new object(s), remove object(s)).
>
> My basic idea is to post notifications when those events happen.  
> I've added posting notifications codes to DKObjectOwnerLayer to  
> watch add/remove objects. I'm little bit confused where to add  
> resize/rotate/move notifications, since methods of DKDrawableObject  
> is not always called by subclasses.
>
> My question is if it's the best approach? if it is, I feel it's  
> valuable to add this kind of notifications into the framework since  
> for application developers, those notifications are important. It  
> would make developers lives a lot easier. I'd love to contribute to  
> this part of work if it's valuable.
>
> (btw, congrat, it's a great framework!)
>
> -- 
> Best regards
>
> Linan Wang
> _______________________________________________
> Drawkit mailing list
> Drawkit at lists.apptree.net
> http://lists.apptree.net/listinfo.cgi/drawkit-apptree.net



More information about the Drawkit mailing list