How do you develop an application to draw, edit and save UML models in Cocoa?

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

+1


source to share


4 answers


One way to do it:

  • Create a document-based application
  • Design model classes for different objects that the end user can draw on your canvas and all share one abstract superclass
  • In your CanvasView class, implement drawRect and call the NSDocument subclass or, for more granular classes, that the viewcontroller manages to get all the objects that need to be drawn in the correct order in order to draw them.
  • For each of these objects, call the drawInteriorInView: rect: method, or something similar, that they are all implemented, from within the CanvasView's drawRect: implementation.

The advantage of this granular design is that you can decide to replace the NSBezierPath drawing with direct calls to CoreGraphics if you need to, without having to completely redesign the application.



Typical Cocoa controls like tableView implement many different drawing methods, one for the background, one for grid lines, etc. and so on, and they are all named (if applicable) from the drawRect: view.

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

+3


source


Have you looked at OmniGraffle? He can do what you need.



[non-programming answer ...]

+2


source


Have you looked at the example Sketch project found at / Developer / Examples / AppKit? This should get you at least halfway to where you are going.

+2


source


Typically you start with a subclass of NSView to present your canvas and handle graphics and mouse / keyboard events. You are probably using NSBezierPath inside your drawing methods to fill and outline shapes. Depending on how complex the drawing code is, you can put everything in an NSView subclass, or create an NSCell subclass, which will require some work from NSView. Either way, you would like to define a data source protocol (or create bindings) to provide NSView data from objects in your data model that represent UML elements.

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

+2


source







All Articles