Пример #1
0
        private int GetRingSizeFromEdge(BondVisual start, Point currentPoint)
        {
            var bond = start.ParentBond;
            var midPoint = bond.MidPoint;
            var uncrowdedSideVector = bond.GetUncrowdedSideVector();
            if (uncrowdedSideVector != null)
            {
                Vector perp = GetProjection(uncrowdedSideVector.Value, midPoint,
                                               currentPoint);
                var distance = Math.Abs((currentPoint - midPoint).Length);
                return GetRingSize(Math.Abs(bond.BondVector.Length), distance);
            }

            return 3;
        }
Пример #2
0
        private void RedrawBond(Bond bond)
        {
            int        refCount = 1;
            BondVisual bv       = null;

            if (chemicalVisuals.ContainsKey(bond))
            {
                bv       = (BondVisual)chemicalVisuals[bond];
                refCount = bv.RefCount;
                BondRemoved(bond);
            }

            BondAdded(bond);

            bv          = (BondVisual)chemicalVisuals[bond];
            bv.RefCount = refCount;
        }
Пример #3
0
        private void BondAdded(Bond bond)
        {
            if (!chemicalVisuals.ContainsKey(bond)) //it's already in the list
            {
                chemicalVisuals[bond] = new BondVisual(bond);
            }

            BondVisual bv = (BondVisual)chemicalVisuals[bond];

            if (bv.RefCount == 0) // it hasn't been added before
            {
                bv.ChemicalVisuals = chemicalVisuals;
                bv.BondThickness   = Globals.BondThickness;

                bv.Render();
                AddVisual(bv);
            }

            bv.RefCount++;
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
 public BondHoverAdorner(UIElement adornedElement, BondVisual targetedVisual) : this(adornedElement)
 {
     _targetedVisual = targetedVisual;
     _targetedBond   = _targetedVisual.ParentBond;
 }