public RadicalGenerator() {}
public IRenderingElement generate(IAtomContainer ac, RendererModel model) {
JChemPaintRendererModel jcpModel = (JChemPaintRendererModel) model;
ElementGroup group = new ElementGroup();
// TODO : put into RendererModel
final double SCREEN_RADIUS = 2.0;
final Color RADICAL_COLOR = Color.BLACK;
// XXX : is this the best option?
final double ATOM_RADIUS = jcpModel.getAtomRadius() / jcpModel.getScale();
double modelRadius = SCREEN_RADIUS / jcpModel.getScale();
Map<IAtom,Integer> singleElectronsPerAtom = new HashMap<IAtom, Integer>();
for (ISingleElectron e : ac.singleElectrons()) {
IAtom atom = e.getAtom();
if(singleElectronsPerAtom.get(atom)==null)
singleElectronsPerAtom.put(atom,0);
Point2d p = atom.getPoint2d();
int align = GeometryTools.getBestAlignmentForLabelXY(ac, atom);
double rx = p.x;
double ry = p.y;
if (align == 1) {
rx += ATOM_RADIUS+singleElectronsPerAtom.get(atom)*ATOM_RADIUS;
} else if (align == -1) {
rx -= ATOM_RADIUS+singleElectronsPerAtom.get(atom)*ATOM_RADIUS;
} else if (align == 2) {
ry -= ATOM_RADIUS;
} else if (align == -2) {
ry += ATOM_RADIUS;
}
singleElectronsPerAtom.put(atom, singleElectronsPerAtom.get(atom)+1);
group.add(
new OvalElement(rx, ry, modelRadius, true, RADICAL_COLOR));
}
return group;
}