Skip to content

New renderer architecture

rwst edited this page May 23, 2012 · 4 revisions

Renderer Architecture

The renderer in CDK trunk is designed to be used from both AWT/Swing and SWT and to be application independent. It will be usable from a Bioclipse, and from JChemPaint, and other user-defined applications.

A UML diagram of the interaction between the basic components of the Renderer is shown below:

this shows a client program displaying an IChemModel by passing it to a class that implements the IAWTRenderer interface, along with a Graphics object to which the rendering calls are finally passed. The 'flow' of the application is shown by annotating that static picture:

here, the arrows indicate the dynamics of this architecture. A collection of IRenderingElements are created from the IChemObject by the generator. These rendering elements are then acted upon by various IRenderingVisitors to actually do the work of translating, scaling, and painting. Of these operations, only painting is specific to a graphical environment (AWT or SWT).

Generator Modules

The generator can be modular to allow for generation of rendering elements at various levels of complexity. Some examples of these levels, with associated images, are shown here : Jchempaint-rendering-modules.

Visitors

The Visitor pattern allows extension of functionality by implementing a Visitor interface, and then applying an instance of the new visitor to each of the model objects. In less abstract terminology; the rendering elements (the bond, atom, ring, etc.) are transformed by the visitor which has a method for each element type. A typical use of visitors might be:

     double dx = boundsCenterX - atomContainerCenter.x;
     double dy = boundsCenterY - atomContainerCenter.y;
     diagram.accept(new TranslateVisitor(dx, dy));
     diagram.accept(new ScaleVisitor(boundsCenterX, boundsCenterY, 50));
     diagram.accept(new DrawVisitor(g));
where dx/dy are the differences between the diagram center and the center of the bounds, and the boundsCenterX and boundsCenterY are the center point of the bounds.