views:

492

answers:

4

Will the individual UML diagram shapes be NSView subclasses or NSBezierPaths? How are the diagrams created and managed?

+2  A: 

Have you looked at OmniGraffle? It may do what you need.

[non-programming-related answer...]

Matthew Schinckel
+2  A: 

Have you looked at the Sketch example project, found in /Developer/Examples/AppKit? It should get you at least halfway to where you're going.

Sherm Pendley
Thanks. That's a great suggestion. Immediately after posting the question, I was browsing through the AppKit examples and found the Sketch project. It's a good way to kick-start my learning.
Akbar ibrahim
+2  A: 

You would typically start with an NSView subclass to represent your "canvas" and handle drawing and mouse/keyboard events. You would probably use NSBezierPath inside your drawing methods to fill and outline the shapes. Depending on how complex the drawing code is, you might put everything in your NSView subclass, or make an NSCell subclass that would take some work out of the NSView. In either case you would want to define a data source protocol (or create bindings) to provide data to the NSView from the objects in your data model which represent UML items.

Core Animation would be worth considering too, although I would start with NSView at the beginning, at least for a simple prototype.

Marc Charbonneau
+2  A: 

One way to do this is to:

  • Create a document-based app
  • Design model classes for the different objects the end-user will be able to draw in your canvas, all sharing one abstract superclass
  • In your CanvasView class, implement drawRect and have it call the NSDocument subclass, or for more granular classes it's viewcontroller, to get all the objects that should be drawn in the right order to draw them.
  • For each of these objects, call a drawInteriorInView:rect: method or something similar that they all have implemented, from within your CanvasView's drawRect: implementation.

The advantage of such a granular design is that you can decide to replace NSBezierPath drawing with straight CoreGraphics calls if you find a need to do so, without having to completely re-architect the app.

Typical Cocoa controls, like for instance a tableView, implement a bunch of different drawing methods, one for the background, one for the gridlines, etc. etc. all of them called (when applicable) from the view's drawRect:.

Or you could of course look at GCDrawKit, which seems to have a pretty functional implementation. Especially check out the sample app that comes with it.

Dirk Stoop