public LonePairGenerator() {}
public IRenderingElement generate(IAtomContainer ac, RendererModel model) {
JChemPaintRendererModel jcpModel = (JChemPaintRendererModel) model;
ElementGroup group = new ElementGroup();
// TODO : put into RendererModel
final double SCREEN_RADIUS = 1.0;
// separation between centers
final double SCREEN_SEPARATION = 2.5;
final Color RADICAL_COLOR = Color.BLACK;
// XXX : is this the best option?
final double ATOM_RADIUS = jcpModel.getAtomRadius();
double scale = jcpModel.getScale();
double modelAtomRadius = ATOM_RADIUS / scale;
double modelPointRadius = SCREEN_RADIUS / scale;
double modelSeparation = SCREEN_SEPARATION / scale;
for (ILonePair lp : ac.lonePairs()) {
IAtom atom = lp.getAtom();
Point2d p = atom.getPoint2d();
int align = GeometryTools.getBestAlignmentForLabelXY(ac, atom);
double rx = p.x;
double ry = p.y;
double dx = 0;
double dy = 0;
if (align == 1) {
rx += modelAtomRadius;
dy += modelSeparation;
} else if (align == -1) {
rx -= modelAtomRadius;
dy += modelSeparation;
} else if (align == 2) {
ry -= modelAtomRadius;
dx += modelSeparation;
} else if (align == -2) {
ry += modelAtomRadius;
dx += modelSeparation;
}
group.add(
new OvalElement(rx + dx, ry + dy,
modelPointRadius, true, RADICAL_COLOR));
group.add(
new OvalElement(rx - dx, ry - dy,
modelPointRadius, true, RADICAL_COLOR));
}
return group;
}