private Geometry GetAtomAdornerGeometry(Atom atom) { if (atom.SymbolText == "") { return(new EllipseGeometry(atom.Position, RenderRadius * 1.5, RenderRadius * 1.5)); } else { return(CurrentEditor.GetAtomVisual(atom).HullGeometry); } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); double renderRadius = (EditViewModel.Model.XamlBondLength * Globals.FontSizePercentageBond) / 4; SolidColorBrush renderBrush = new SolidColorBrush(SystemColors.HighlightColor); renderBrush.Opacity = 0.25; if (AdornedAtom.SymbolText == "") { drawingContext.DrawEllipse(renderBrush, null, AdornedAtom.Position, renderRadius, renderRadius); } else { drawingContext.DrawGeometry(renderBrush, null, CurrentEditor.GetAtomVisual(AdornedAtom).HullGeometry); } }
protected override void OnRender(DrawingContext drawingContext) { _ghostBrush = (SolidColorBrush)FindResource(Globals.GhostBrush); _ghostPen = new Pen(_ghostBrush, Globals.BondThickness); HashSet <Bond> bondSet = new HashSet <Bond>(); Dictionary <Atom, Point> transformedPositions = new Dictionary <Atom, Point>(); //compile a set of all the neighbours of the selected atoms foreach (Atom atom in _atomList) { foreach (Atom neighbour in atom.Neighbours) { //add in all the existing position for neigbours not in selected atoms if (!_atomList.Contains(neighbour)) { //neighbourSet.Add(neighbour); //don't worry about adding them twice transformedPositions[neighbour] = neighbour.Position; } } //add in the bonds foreach (Bond bond in atom.Bonds) { bondSet.Add(bond); //don't worry about adding them twice } //if we're just getting an overlay then don't bother transforming if (_shear != null) { transformedPositions[atom] = _shear.Transform(atom.Position); } else { transformedPositions[atom] = atom.Position; } } var modelXamlBondLength = CurrentViewModel.Model.XamlBondLength; double atomRadius = modelXamlBondLength / 7.50; foreach (Bond bond in bondSet) { List <Point> throwaway = new List <Point>(); var startAtomPosition = transformedPositions[bond.StartAtom]; var endAtomPosition = transformedPositions[bond.EndAtom]; if (bond.OrderValue != 1.0 || !(bond.Stereo == Globals.BondStereo.Hatch | bond.Stereo == Globals.BondStereo.Wedge)) { var descriptor = BondVisual.GetBondDescriptor(CurrentEditor.GetAtomVisual(bond.StartAtom), CurrentEditor.GetAtomVisual(bond.EndAtom), modelXamlBondLength, bond.Stereo, startAtomPosition, endAtomPosition, bond.OrderValue, bond.Placement, bond.Centroid, bond.SubsidiaryRing?.Centroid); descriptor.Start = startAtomPosition; descriptor.End = endAtomPosition; var bondgeom = descriptor.DefiningGeometry; drawingContext.DrawGeometry(_ghostBrush, _ghostPen, bondgeom); } else { drawingContext.DrawLine(_ghostPen, startAtomPosition, endAtomPosition); } } foreach (Atom atom in transformedPositions.Keys) { var newPosition = transformedPositions[atom]; if (atom.SymbolText != "") { drawingContext.DrawEllipse(SystemColors.WindowBrush, _ghostPen, newPosition, atomRadius, atomRadius); } } }
private Geometry GetBondAdornerGeometry(Bond bond) { //work out the actual visible extent of the bond Point startPoint, endPoint; Vector unitVector = bond.BondVector; unitVector.Normalize(); AtomVisual startAtomVisual = CurrentEditor.GetAtomVisual(bond.StartAtom); AtomVisual endAtomVisual = CurrentEditor.GetAtomVisual(bond.EndAtom); Point?sp; //work out where the bond vector intersects the start and end points of the bond if (!string.IsNullOrEmpty(bond.StartAtom.SymbolText) && (sp = startAtomVisual.GetIntersection(bond.StartAtom.Position, bond.EndAtom.Position)) != null) { startPoint = sp.Value; } else { startPoint = bond.StartAtom.Position + unitVector * RenderRadius; } Point?ep; if (!string.IsNullOrEmpty(bond.EndAtom.SymbolText) && (ep = endAtomVisual.GetIntersection(bond.StartAtom.Position, bond.EndAtom.Position)) != null) { endPoint = ep.Value; } else { endPoint = bond.EndAtom.Position - unitVector * RenderRadius; } //get the perpendiculars to the bond Matrix toLeft = new Matrix(); toLeft.Rotate(-90); Matrix toRight = new Matrix(); toRight.Rotate(90); Vector right = bond.BondVector * toRight; right.Normalize(); Vector left = bond.BondVector * toLeft; left.Normalize(); //draw the rectangle on top of the bond PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = startPoint + right * RenderRadius; pathFigure.IsClosed = true; LineSegment lineSegment1 = new LineSegment(); lineSegment1.Point = startPoint + left * RenderRadius; pathFigure.Segments.Add(lineSegment1); LineSegment lineSegment2 = new LineSegment(); lineSegment2.Point = endPoint + left * RenderRadius; pathFigure.Segments.Add(lineSegment2); LineSegment lineSegment3 = new LineSegment(); lineSegment3.Point = endPoint + right * RenderRadius; pathFigure.Segments.Add(lineSegment3); //add in the figure List <PathFigure> figures = new List <PathFigure>(); figures.Add(pathFigure); //now create the geometry PathGeometry pathGeometry = new PathGeometry(figures); //work out the end caps Geometry start = new EllipseGeometry(startPoint, RenderRadius, RenderRadius); Geometry end = new EllipseGeometry(endPoint, RenderRadius, RenderRadius); //add them in CombinedGeometry result = new CombinedGeometry(GeometryCombineMode.Union, pathGeometry, start); result = new CombinedGeometry(GeometryCombineMode.Union, result, end); //and return return(result); }