示例#1
0
        public void TestSquareMolecule()
        {
            IAtomContainer square = MakeSquare();

            var generators = new List <IGenerator <IAtomContainer> >
            {
                new BasicSceneGenerator(),
                new BasicBondGenerator()
            };
            BasicAtomGenerator atomGenerator = new BasicAtomGenerator();

            generators.Add(atomGenerator);

            AtomContainerRenderer renderer = new AtomContainerRenderer(generators, new WPFFontManager());
            RendererModel         model    = renderer.GetRenderer2DModel();

            model.SetCompactShape(AtomShapeType.Oval);
            model.SetCompactAtom(true);
            model.SetKekuleStructure(true);
            model.SetShowEndCarbons(true);

            ElementUtility visitor = new ElementUtility();
            var            screen  = new Rect(0, 0, 100, 100);

            renderer.Setup(square, screen);
            renderer.Paint(square, visitor);

            foreach (var element in visitor.GetElements())
            {
                Assert.IsTrue(visitor.ToString(element).Contains("Line") || visitor.ToString(element).Contains("Oval"));
            }
        }
示例#2
0
 protected internal ReactionSetRenderer(RendererModel rendererModel, IEnumerable <IGenerator <IAtomContainer> > generators, IEnumerable <IGenerator <IReaction> > reactionGenerators, IFontManager fontManager)
     : base(rendererModel)
 {
     this.fontManager = fontManager;
     reactionRenderer = new ReactionRenderer(generators, reactionGenerators, fontManager);
     this.Setup();
 }
示例#3
0
 public ReactionSetRenderer(RendererModel rendererModel, IEnumerable <IGenerator <IAtomContainer> > generators, IFontManager fontManager)
     : base(rendererModel)
 {
     this.fontManager = fontManager;
     reactionRenderer = new ReactionRenderer(rendererModel, generators, fontManager);
     this.Setup();
 }
示例#4
0
        public void TestMerge()
        {
            RendererModel model = new RendererModel();

            Assert.IsNotNull(model.Merge);
            // any further testing I can do here?
        }
示例#5
0
 public MoleculeSetRenderer(RendererModel rendererModel, IEnumerable <IGenerator <IAtomContainer> > generators, IFontManager fontManager)
     : base(rendererModel)
 {
     this.fontManager      = fontManager;
     atomContainerRenderer = new AtomContainerRenderer(rendererModel, generators, fontManager);
     this.generators       = Array.Empty <IGenerator <IChemObjectSet <IAtomContainer> > >();
     this.Setup();
 }
示例#6
0
        public void TestNoDefaultToolTips()
        {
            RendererModel model = new RendererModel();

            // test: no default tool tips
            Assert.IsNull(model.GetToolTipText(new Atom()));
            // but a non-null map
            Assert.IsNotNull(model.GetToolTipTextMap());
        }
示例#7
0
        public void TestGetSetNotification()
        {
            RendererModel model = new RendererModel();

            // test the default setting
            Assert.IsTrue(model.Notification);
            model.Notification = false;
            Assert.IsFalse(model.Notification);
            model.Notification = true;
            Assert.IsTrue(model.Notification);
        }
示例#8
0
        public void TestToolTipFunctionality()
        {
            var   tips     = new Dictionary <IAtom, string>();
            IAtom anonAtom = new Atom();

            tips[anonAtom] = "Repelsteeltje";
            RendererModel model = new RendererModel();

            model.SetToolTipTextMap(tips);
            Assert.AreEqual(tips, model.GetToolTipTextMap());
            Assert.AreEqual("Repelsteeltje", model.GetToolTipText(anonAtom));
        }
示例#9
0
        public void TestHighlightedAtom()
        {
            RendererModel model = new RendererModel();

            // test default
            Assert.IsNull(model.GetHighlightedAtom());
            IAtom content = new Atom();

            model.SetHighlightedAtom(content);
            Assert.AreEqual(content, model.GetHighlightedAtom());
            model.SetHighlightedAtom(null);
            Assert.IsNull(model.GetHighlightedAtom());
        }
示例#10
0
        public void TestExternalSelectedPart()
        {
            RendererModel model = new RendererModel();

            // test default
            Assert.IsNull(model.GetExternalSelectedPart());
            IAtomContainer content = new AtomContainer();

            model.SetExternalSelectedPart(content);
            Assert.AreEqual(content, model.GetExternalSelectedPart());
            model.SetExternalSelectedPart(null);
            Assert.IsNull(model.GetExternalSelectedPart());
        }
示例#11
0
        public void TestSelection()
        {
            RendererModel model = new RendererModel();

            // test default
            Assert.IsNull(model.GetSelection());
            IChemObjectSelection content = new MockSelection();

            model.SetSelection(content);
            Assert.AreEqual(content, model.GetSelection());
            model.SetSelection(null);
            Assert.IsNull(model.GetSelection());
        }
示例#12
0
        public void TestListening()
        {
            RendererModel model = new RendererModel();
            // test default
            MockListener listener = new MockListener();

            model.Listeners.Add(listener);
            Assert.IsFalse(listener.IsChanged);
            model.OnStateChanged(null);
            Assert.IsTrue(listener.IsChanged);

            // test unregistering
            listener.IsChanged = false;
            Assert.IsFalse(listener.IsChanged);
            model.Listeners.Remove(listener);
            model.OnStateChanged(null);
            Assert.IsFalse(listener.IsChanged);
        }
示例#13
0
        public void IupacCarbonParallel()
        {
            IAtom a1 = new Atom("C");
            IAtom a2 = new Atom("C");
            IAtom a3 = new Atom("C");

            a1.Point2D = new Vector2(0, 0);
            a2.Point2D = new Vector2(0, -0.5);
            a3.Point2D = new Vector2(0, 0.5);

            IBond bond1 = new Bond(a1, a2);
            IBond bond2 = new Bond(a1, a3);

            a1.ImplicitHydrogenCount = 2;
            a2.ImplicitHydrogenCount = 3;
            a3.ImplicitHydrogenCount = 3;

            var model = new RendererModel();

            Assert.IsTrue(SymbolVisibility.IupacRecommendations.Visible(a1, new[] { bond1, bond2 }, model));
        }
示例#14
0
            /// <inheritdoc/>
            public override bool Visible(IAtom atom, IEnumerable <IBond> bonds_, RendererModel model)
            {
                var bonds = bonds_.ToList();

                // all non-carbons are displayed
                if (atom.AtomicNumber != AtomicNumbers.Carbon)
                {
                    return(true);
                }

                // methane
                if (bonds.Count == 0)
                {
                    return(true);
                }

                // methyl (optional)
                if (bonds.Count == 1 && terminal)
                {
                    return(true);
                }

                // abnormal valence, could be due to charge or unpaired electrons
                if (!IsFourValent(atom, bonds))
                {
                    return(true);
                }

                // charge, normally caught by previous rule but can have bad input: C=[CH-]C
                if (atom.FormalCharge != null &&
                    atom.FormalCharge != 0)
                {
                    return(true);
                }

                // carbon isotopes are displayed
                var mass = atom.MassNumber;

                if (mass != null)
                {
                    return(true);
                }

                // no kink between bonds to imply the presence of a carbon and it must
                // be displayed if the bonds have the same bond order
                if (bonds.Count == 2 &&
                    bonds[0].Order == bonds[1].Order)
                {
                    var bndord = bonds[0].Order;
                    if (bndord == BondOrder.Double || HasParallelBonds(atom, bonds))
                    {
                        return(true);
                    }
                }

                // special case ethane
                if (bonds.Count == 1)
                {
                    var begHcnt = atom.ImplicitHydrogenCount;
                    var end     = bonds[0].GetOther(atom);
                    var endHcnt = end.ImplicitHydrogenCount;
                    if (begHcnt != null && endHcnt != null && begHcnt == 3 && endHcnt == 3)
                    {
                        return(true);
                    }
                }

                // ProblemMarker ?

                return(false);
            }
示例#15
0
 public override bool Visible(IAtom atom, IEnumerable <IBond> neighbors, RendererModel model) => true;
示例#16
0
 /// <summary>
 /// Determine if an atom with the specified bonds is visible.
 /// </summary>
 /// <param name="atom">an atom</param>
 /// <param name="neighbors">neighboring bonds</param>
 /// <returns>whether the atom symbol is visible</returns>
 public abstract bool Visible(IAtom atom, IEnumerable <IBond> neighbors, RendererModel model);
示例#17
0
 public AtomContainerRenderer(RendererModel rendererModel, IEnumerable <IGenerator <IAtomContainer> > generators, IFontManager fontManager)
     : base(rendererModel)
 {
     this.generators  = generators.ToList();
     this.fontManager = fontManager;
 }
示例#18
0
 public AbstractRenderer(RendererModel rendererModel)
 {
     this.rendererModel = rendererModel;
 }
示例#19
0
 public IRenderingElement Generate(IChemObject obj, RendererModel model) => null;