/// <inheritdoc/> public IRenderingElement Generate(IAtomContainer container, RendererModel model) { var highlight = container.GetProperty <IDictionary <IChemObject, int> >(IdMapKey); if (highlight == null) { return(null); } IPalette palette = model.GetHighlightPalette(); double radius = model.GetHighlightRadius() / model.GetScale(); var shapes = new Dictionary <int, Geometry>(); foreach (var atom in container.Atoms) { if (!highlight.TryGetValue(atom, out int id)) { continue; } var area = shapes[id]; var shape = CreateAtomHighlight(atom, radius); if (area == null) { shapes[id] = shape; } else { area = new CombinedGeometry(area, shape); } } foreach (var bond in container.Bonds) { if (!highlight.TryGetValue(bond, out int id)) { continue; } var area = shapes[id]; var shape = CreateBondHighlight(bond, radius); if (area == null) { shapes[id] = (area = shape); } else { area = new CombinedGeometry(area, shape); } // punch out the area occupied by atoms highlighted with a // different color var a1 = bond.Begin; var a2 = bond.End; if (highlight.TryGetValue(a1, out int a1Id)) { if (!a1Id.Equals(id)) { area = new CombinedGeometry(GeometryCombineMode.Exclude, area, shapes[a1Id]); } } if (highlight.TryGetValue(a2, out int a2Id)) { if (!a2Id.Equals(id)) { area = new CombinedGeometry(GeometryCombineMode.Exclude, area, shapes[a2Id]); } } } // create rendering elements for each highlight shape ElementGroup group = new ElementGroup(); foreach (var e in shapes) { group.Add(GeneralPath.ShapeOf(e.Value, palette.Color(e.Key))); } return(group); }