예제 #1
0
        //draws the isotope label at ten-o-clock
        private LabelMetrics DrawIsotopeLabel(DrawingContext drawingContext, AtomTextMetrics mainAtomMetrics, AtomTextMetrics hMetrics)
        {
            Debug.Assert(Isotope != null);

            string isoLabel    = Isotope.ToString();
            var    isotopeText = new IsotopeLabelText(isoLabel, PixelsPerDip());

            Vector isotopeOffsetVector = BasicGeometry.ScreenNorth * GlyphText.SymbolSize;
            Matrix rotator             = new Matrix();
            double angle = -60;

            //avoid overlap of label and hydrogens
            if (hMetrics != null && ParentAtom.GetDefaultHOrientation() == CompassPoints.West)
            {
                angle = -35;
            }

            rotator.Rotate(angle);
            isotopeOffsetVector = isotopeOffsetVector * rotator;
            Point isoCenter = mainAtomMetrics.Geocenter + isotopeOffsetVector;

            isotopeText.MeasureAtCenter(isoCenter);
            isotopeText.Fill = Fill;
            isotopeText.DrawAtBottomLeft(isotopeText.TextMetrics.BoundingBox.BottomLeft, drawingContext);
            return(isotopeText.TextMetrics);
        }
        public void AddIsotopeWithExistingMassNumber()
        {
            var elementC = new Element("C", 6, 12.0106);

            elementC.AddIsotope(12, 12, 0.9893);
            elementC.AddIsotope(13, 13.00335483507, 0.0107);
            Isotope isotope = elementC[13];

            Assert.AreEqual("C{13}", isotope.ToString());
            Assert.AreEqual(6, isotope.Protons);
            Assert.AreEqual(7, isotope.Neutrons);
        }
예제 #3
0
        private Geometry DrawIsotopeLabel(Atom parentAtom, Geometry symbolGeometry)
        {
            Point startingPoint = parentAtom.Position;
            Point nextPos;

            if (parentAtom.IsotopeNumber == null)
            {
                return(symbolGeometry);
            }
            else
            {
                Geometry atomGeo  = null;
                string   isoLabel = Isotope.ToString();

                if (!(symbolGeometry is EllipseGeometry)) //that is, weve got an explcit, non carbon element
                {
                    var atomText = BuildSymbolLabel(parentAtom.SymbolText, ref startingPoint, out nextPos);

                    atomGeo = atomText.BuildGeometry(startingPoint);
                }
                else //its a vertex carbon
                {
                    atomGeo = symbolGeometry;
                }

                //have a stab at placing the isotope label.

                //placementvector gives the CENTRE of the charge text!
                //first generate  a vector pointing straight up
                Vector placementVector = new Vector(0.0, -Math.Max(atomGeo.Bounds.Width, atomGeo.Bounds.Height));
                Matrix rotator         = new Matrix();
                //isotope labels always go  in at 10-o-clock from the atom.
                rotator.Rotate(-60);
                placementVector *= rotator;

                //Point firstPlacementPoint = new Point(atomGeo.Bounds.Right, atomGeo.Bounds.Top - chargeText.Height/2);

                FormattedText isoText = GetSubscriptText(isoLabel);

                Point firstPlacementPoint = parentAtom.Position + placementVector -
                                            new Vector(isoText.Width / 2, isoText.Height / 2);

                System.Windows.Media.Geometry isoGeo = isoText.BuildGeometry(firstPlacementPoint);

                return(new CombinedGeometry(symbolGeometry, isoGeo));
            }
        }