/// <inheritdoc/> public IRenderingElement Generate(IAtomContainer container, RendererModel model) { ElementGroup group = new ElementGroup(); // TODO : put into RendererModel const double SCREEN_RADIUS = 1.0; // separation between centers const double SCREEN_SEPARATION = 2.5; Color RADICAL_COLOR = WPF.Media.Colors.Black; // XXX : is this the best option? double ATOM_RADIUS = model.GetAtomRadius(); double scale = model.GetScale(); double modelAtomRadius = ATOM_RADIUS / scale; double modelPointRadius = SCREEN_RADIUS / scale; double modelSeparation = SCREEN_SEPARATION / scale; foreach (var lonePair in container.LonePairs) { IAtom atom = lonePair.Atom; Vector2 point = atom.Point2D.Value; int align = GeometryUtil.GetBestAlignmentForLabelXY(container, atom); var center = ToPoint(point); var diff = new WPF::Vector(); if (align == 1) { center.X += modelAtomRadius; diff.Y += modelSeparation; } else if (align == -1) { center.X -= modelAtomRadius; diff.Y += modelSeparation; } else if (align == 2) { center.Y -= modelAtomRadius; diff.X += modelSeparation; } else if (align == -2) { center.Y += modelAtomRadius; diff.X += modelSeparation; } group.Add(new OvalElement(center + diff, modelPointRadius, true, RADICAL_COLOR)); group.Add(new OvalElement(center - diff, modelPointRadius, true, RADICAL_COLOR)); } return(group); }
/// <inheritdoc/> public IRenderingElement Generate(IAtomContainer container, RendererModel model) { ElementGroup group = new ElementGroup(); // TODO : put into RendererModel const double ScreenRadius = 2.0; Color RadicalColor = WPF.Media.Colors.Black; // XXX : is this the best option? double AtomRadius = model.GetAtomRadius() / model.GetScale(); double modelRadius = ScreenRadius / model.GetScale(); double modelSpacing = modelRadius * 2.5; var singleElectronsPerAtom = new Dictionary <IAtom, int>(); foreach (var electron in container.SingleElectrons) { IAtom atom = electron.Atom; if (!singleElectronsPerAtom.ContainsKey(atom)) { singleElectronsPerAtom[atom] = 0; } Vector2 point = atom.Point2D.Value; int align = GeometryUtil.GetBestAlignmentForLabelXY(container, atom); var center = ToPoint(point); if (align == 1) { center.X += AtomRadius * 4 + singleElectronsPerAtom[atom] * modelSpacing; } else if (align == -1) { center.X -= AtomRadius * 4 + singleElectronsPerAtom[atom] * modelSpacing; } else if (align == 2) { center.Y += AtomRadius * 4 + singleElectronsPerAtom[atom] * modelSpacing; } else if (align == -2) { center.Y -= AtomRadius * 4 + singleElectronsPerAtom[atom] * modelSpacing; } singleElectronsPerAtom[atom] = singleElectronsPerAtom[atom] + 1; group.Add(new OvalElement(center, modelRadius, true, RadicalColor)); } return(group); }
/// <summary> /// Generate a compact element for an atom, such as a circle or a square, /// rather than text element. /// </summary> /// <param name="atom">the atom to generate the compact element for</param> /// <param name="model">the renderer model</param> /// <returns>a compact rendering element</returns> public virtual IRenderingElement GenerateCompactElement(IAtom atom, RendererModel model) { var point = atom.Point2D.Value; double radius = model.GetAtomRadius() / model.GetScale(); double distance = 2 * radius; if (model.GetCompactShape() == AtomShapeType.Square) { return(new RectangleElement( new WPF.Point(point.X - radius, point.Y - radius), distance, distance, true, GetAtomColor(atom, model))); } else { return(new OvalElement(ToPoint(point), radius, true, GetAtomColor(atom, model))); } }