Exemple #1
0
        internal static ModelCreateResult TryCreate(XmlNode node, XmlNode log4NetNode, out ModelBase model)
        {
            model = null;

            switch (node.Name)
            {
            case Log4NetXmlConstants.Root:
                model = new RootLoggerModel(node, false, LoggerDescriptor.Root);
                return(ModelCreateResult.Success);

            case Log4NetXmlConstants.Logger:
                model = new LoggerModel(node, false, LoggerDescriptor.Logger);
                return(ModelCreateResult.Success);

            case Log4NetXmlConstants.Appender:
                if (AppenderModel.TryCreate(node, log4NetNode, out AppenderModel appenderModel))
                {
                    model = appenderModel;
                    return(ModelCreateResult.Success);
                }

                return(ModelCreateResult.UnknownAppender);

            case Log4NetXmlConstants.Renderer:
                model = new RendererModel(node);
                return(ModelCreateResult.Success);

            case Log4NetXmlConstants.Param:
                model = new ParamModel(node);
                return(ModelCreateResult.Success);

            default:
                return(ModelCreateResult.UnknownElement);
            }
        }
        /// <summary>
        /// Checks a carbon atom to see if it should be shown.
        /// </summary>
        /// <param name="carbonAtom">the carbon atom to check</param>
        /// <param name="container">the atom container</param>
        /// <param name="model">the renderer model</param>
        /// <returns>true if the carbon should be shown</returns>
        public virtual bool ShowCarbon(IAtom carbonAtom, IAtomContainer container, RendererModel model)
        {
            if (model.GetKekuleStructure())
            {
                return(true);
            }
            if (carbonAtom.FormalCharge != 0)
            {
                return(true);
            }
            int connectedBondCount = container.GetConnectedBonds(carbonAtom).Count();

            if (connectedBondCount < 1)
            {
                return(true);
            }
            if ((bool)model.GetShowEndCarbons() && connectedBondCount == 1)
            {
                return(true);
            }
            if (carbonAtom.GetProperty <bool>(ProblemMarker.ErrorMarker, false))
            {
                return(true);
            }
            if (container.GetConnectedSingleElectrons(carbonAtom).Any())
            {
                return(true);
            }
            return(false);
        }
        /// <inheritdoc/>
        public IRenderingElement Generate(IAtomContainer container, RendererModel model)
        {
            ElementGroup numbers = new ElementGroup();

            if (!model.GetWillDrawAtomNumbers())
            {
                return(numbers);
            }

            var     _offset = model.GetAtomNumberOffset();
            Vector2 offset  = new Vector2(_offset.X, -_offset.Y);

            offset *= (1 / model.GetScale());

            int number = 1;

            foreach (var atom in container.Atoms)
            {
                Vector2 point = atom.Point2D.Value + offset;
                numbers.Add(
                    new TextElement(ToPoint(point), number.ToString(),
                                    model.GetAtomNumberColorByType() ?
                                    model.GetAtomNumberColorer().GetAtomColor(atom) :
                                    model.GetAtomNumberTextColor()));
                number++;
            }
            return(numbers);
        }
Exemple #4
0
        private IRenderingElement GenerateStereoElement(IBond bond, RendererModel model)
        {
            BondStereo stereo = bond.Stereo;

            WedgeLineElement.WedgeType type = WedgeLineElement.WedgeType.Wedged;
            BondDirection dir = BondDirection.ToSecond;

            switch (stereo)
            {
            case BondStereo.Down:
            case BondStereo.DownInverted:
                type = WedgeLineElement.WedgeType.Dashed;
                break;

            case BondStereo.UpOrDown:
            case BondStereo.UpOrDownInverted:
                type = WedgeLineElement.WedgeType.Indiff;
                break;
            }
            switch (stereo)
            {
            case BondStereo.DownInverted:
            case BondStereo.UpInverted:
            case BondStereo.UpOrDownInverted:
                dir = BondDirection.ToFirst;
                break;
            }

            IRenderingElement base_ = GenerateBondElement(bond, BondOrder.Single, model);

            return(new WedgeLineElement((LineElement)base_, type, dir, GetColorForBond(bond, model)));
        }
Exemple #5
0
        /// <summary>
        /// Make the inner ring bond, which is slightly shorter than the outer bond.
        /// </summary>
        /// <param name="bond">the ring bond</param>
        /// <param name="ring">the ring that the bond is in</param>
        /// <param name="model">the renderer model</param>
        /// <returns>the line element</returns>
        public virtual LineElement GenerateInnerElement(IBond bond, IRing ring, RendererModel model)
        {
            Vector2 center = GeometryUtil.Get2DCenter(ring);
            Vector2 a      = bond.Begin.Point2D.Value;
            Vector2 b      = bond.End.Point2D.Value;

            // the proportion to move in towards the ring center
            double distanceFactor = model.GetTowardsRingCenterProportion();
            double ringDistance   = distanceFactor * IDEAL_RINGSIZE / ring.Atoms.Count;

            if (ringDistance < distanceFactor / MIN_RINGSIZE_FACTOR)
            {
                ringDistance = distanceFactor / MIN_RINGSIZE_FACTOR;
            }

            Vector2 w = Vector2.Lerp(a, center, ringDistance);
            Vector2 u = Vector2.Lerp(b, center, ringDistance);

            double  alpha = 0.2;
            Vector2 ww    = Vector2.Lerp(w, u, alpha);
            Vector2 uu    = Vector2.Lerp(u, w, alpha);

            double width = GetWidthForBond(bond, model);
            Color  color = GetColorForBond(bond, model);

            return(new LineElement(ToPoint(u), ToPoint(w), width, color));
        }
        /// <inheritdoc/>
        public IRenderingElement Generate(IReaction reaction, RendererModel model)
        {
            if (!model.GetShowReactionBoxes())
            {
                return(null);
            }
            if (reaction.Reactants.Count == 0)
            {
                return(new ElementGroup());
            }

            double separation  = model.GetBondLength() / model.GetScale() / 2;
            var    totalBounds = BoundsCalculator.CalculateBounds(reaction.Reactants);

            ElementGroup diagram         = new ElementGroup();
            double       minX            = totalBounds.Left;
            double       minY            = totalBounds.Top;
            double       maxX            = totalBounds.Right;
            double       maxY            = totalBounds.Bottom;
            var          foregroundColor = model.GetForegroundColor();

            diagram.Add(new RectangleElement(new Rect(minX - separation, minY - separation, maxX + separation, maxY + separation), foregroundColor));
            diagram.Add(new TextElement(new Point((minX + maxX) / 2, minY - separation), "Reactants", foregroundColor));
            return(diagram);
        }
Exemple #7
0
        /// <inheritdoc/>
        public IRenderingElement Generate(IReaction reaction, RendererModel model)
        {
            if (!model.GetShowReactionBoxes())
            {
                return(null);
            }
            var separation  = model.GetBondLength() / model.GetScale();
            var totalBounds = BoundsCalculator.CalculateBounds(reaction);

            if (totalBounds.IsEmpty)
            {
                return(null);
            }

            var diagram         = new ElementGroup();
            var foregroundColor = model.GetForegroundColor();

            diagram.Add(new RectangleElement(new Rect(totalBounds.Left - separation, totalBounds.Top - separation,
                                                      totalBounds.Right + separation, totalBounds.Bottom + separation),
                                             foregroundColor));
            if (reaction.Id != null)
            {
                diagram.Add(new TextElement(new Point((totalBounds.Left + totalBounds.Right) / 2, totalBounds.Top - separation),
                                            reaction.Id, foregroundColor));
            }
            return(diagram);
        }
Exemple #8
0
 /// <inheritdoc/>
 public override bool Visible(IAtom atom, IEnumerable <IBond> neighbors, RendererModel model)
 {
     if (IsSelected(atom, model) && (showAll || !HasSelectedBond(neighbors, model)))
     {
         return(true);
     }
     return(delegate_.Visible(atom, neighbors, model));
 }
Exemple #9
0
        public void SetUp()
        {
            XmlDocument xmlDoc = new XmlDocument();

            mRenderer = xmlDoc.CreateElement(RendererDescriptor.Renderer.ElementName);

            mSut = new RendererModel(mRenderer);
        }
        public void TestGetRendererModel()
        {
            DrawingVisual  drawingVisual = new DrawingVisual();
            DrawingContext g2d           = drawingVisual.RenderOpen();
            WPFDrawVisitor visitor       = new WPFDrawVisitor(g2d);
            RendererModel  model         = new RendererModel();

            visitor.RendererModel = model;
            Assert.AreEqual(model, visitor.RendererModel);
        }
        /// <inheritdoc/>
        public virtual IRenderingElement Generate(IAtomContainer container, RendererModel model)
        {
            ElementGroup elementGroup = new ElementGroup();

            foreach (var atom in container.Atoms)
            {
                elementGroup.Add(MarkedElement.MarkupAtom(this.Generate(container, atom, model), atom));
            }
            return(elementGroup);
        }
        /// <summary>
        /// Returns the drawing color of the given atom. An atom is colored as
        /// highlighted if highlighted. The atom is color marked if in a
        /// substructure. If not, the color from the CDK2DAtomColor is used (if
        /// selected). Otherwise, the atom is colored black.
        /// </summary>
        protected internal virtual Color GetAtomColor(IAtom atom, RendererModel model)
        {
            var atomColor = model.GetAtomColor();

            if (model.GetAtomColorByType())
            {
                atomColor = model.GetAtomColorer().GetAtomColor(atom);
            }
            return(atomColor);
        }
        private RendererModel CreateModel()
        {
            var model = new RendererModel();

            foreach (var p in templateModel.Parameters)
            {
                model.Parameters.Add(p);
            }
            return(model);
        }
Exemple #14
0
 /// <summary>
 /// Sets up the model and transform.
 /// Call from the 'Before' method in subclasses.
 /// </summary>
 public AbstractGeneratorTest()
 {
     if (model != null)
     {
         return; // things are already set up
     }
     model          = new RendererModel();
     elementUtil    = new ElementUtility();
     sceneGenerator = new BasicSceneGenerator();
 }
        /// <summary>
        /// Generate a bound element that is the title of the provided molecule. If title
        /// is not specified an empty bounds is returned.
        /// </summary>
        /// <param name="chemObj">molecule or reaction</param>
        /// <returns>bound element</returns>
        private Bounds GenerateTitle(RendererModel model, IChemObject chemObj, double scale)
        {
            var title = chemObj.GetProperty <string>(CDKPropertyName.Title);

            if (string.IsNullOrEmpty(title))
            {
                return(new Bounds());
            }
            scale = 1 / scale * model.GetTitleFontScale();
            return(new Bounds(MarkedElement.Markup(StandardGenerator.EmbedText(font, emSize, title, model.GetTitleColor(), scale), "title")));
        }
        private List <Bounds> Generate(IList <IAtomContainer> mols, RendererModel model, int atomNum)
        {
            var elems = new List <Bounds>();

            foreach (var mol in mols)
            {
                elems.Add(new Bounds(Generate(mol, model, atomNum)));
                atomNum += mol.Atoms.Count;
            }
            return(elems);
        }
Exemple #17
0
 /// <summary>
 /// Determines if any bond in the list is selected
 /// </summary>
 /// <param name="bonds">list of bonds</param>
 /// <returns>at least bond is selected</returns>
 internal static bool HasSelectedBond(IEnumerable <IBond> bonds, RendererModel model)
 {
     foreach (var bond in bonds)
     {
         if (IsSelected(bond, model))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #18
0
        /// <inheritdoc/>
        public IRenderingElement Generate(IAtomContainer ac, RendererModel model)
        {
            ElementGroup diagram = new ElementGroup
            {
                this.sceneGenerator.Generate(ac, model),
                this.bondGenerator.Generate(ac, model),
                this.atomGenerator.Generate(ac, model)
            };

            return(diagram);
        }
Exemple #19
0
        private IRenderingElement GenerateRingRingElement(IBond bond, IRing ring, RendererModel model)
        {
            var c = ToPoint(GeometryUtil.Get2DCenter(ring));

            var minmax = GeometryUtil.GetMinMax(ring);
            var width  = minmax[2] - minmax[0];
            var height = minmax[3] - minmax[1];
            var radius = Math.Min(width, height) * model.GetRingProportion();
            var color  = GetColorForBond(bond, model);

            return(new OvalElement(c, radius, false, color));
        }
Exemple #20
0
 /// <summary>
 /// Determine if an object is selected.
 /// </summary>
 /// <param name="obj">the object</param>
 /// <returns>object is selected</returns>
 internal static bool IsSelected(IChemObject obj, RendererModel model)
 {
     if (obj.GetProperty <Color?>(StandardGenerator.HighlightColorKey) != null)
     {
         return(true);
     }
     if (model.GetSelection() != null)
     {
         return(model.GetSelection().Contains(obj));
     }
     return(false);
 }
        public void Execute_ShouldAddModel_AndShouldAssignNode_WhenModelNodeIsNull()
        {
            ModelBase  model      = new RendererModel(null);
            XmlElement newElement = new XmlDocument().CreateElement("element");
            bool       addCalled  = false;

            ISaveStrategy sut = new AddSaveStrategy <ModelBase>(model, modelParam => { addCalled = true; }, newElement);

            sut.Execute();

            Assert.IsTrue(addCalled);
            Assert.AreSame(newElement, model.Node);
        }
Exemple #22
0
        /// <summary>
        /// Generate rendering Element(s) for the current bond, including ring
        /// elements if this bond is part of a ring.
        /// </summary>
        /// <param name="currentBond">the bond to use when generating elements</param>
        /// <param name="model">the renderer model</param>
        /// <returns>one or more rendering elements</returns>
        public virtual IRenderingElement Generate(IBond currentBond, RendererModel model)
        {
            IRing ring = RingSetManipulator.GetHeaviestRing(ringSet, currentBond);

            if (ring != null)
            {
                return(GenerateRingElements(currentBond, ring, model));
            }
            else
            {
                return(GenerateBond(currentBond, model));
            }
        }
Exemple #23
0
        /// <summary>
        /// Determine the width of a bond, returning either the width defined
        /// in the model, or the override width. Note that this will be scaled
        /// to the space of the model.
        /// </summary>
        /// <param name="bond">the bond to determine the width for</param>
        /// <param name="model">the renderer model</param>
        /// <returns>a double in chem-model space</returns>
        public virtual double GetWidthForBond(IBond bond, RendererModel model)
        {
            double scale = model.GetScale();

            if (this.overrideBondWidth != -1)
            {
                return(this.overrideBondWidth / scale);
            }
            else
            {
                return(model.GetBondWidth() / scale);
            }
        }
Exemple #24
0
        /// <summary>
        /// Determine the color of a bond, returning either the default color,
        /// the override color or whatever is in the color hash for that bond.
        /// </summary>
        /// <param name="bond">the bond we are generating an element for</param>
        /// <param name="model">the rendering model</param>
        /// <returns>the color to paint the bond</returns>
        public virtual Color GetColorForBond(IBond bond, RendererModel model)
        {
            if (this.overrideColor != null)
            {
                return(overrideColor.Value);
            }

            if (!model.GetColorHash().TryGetValue(bond, out Color color))
            {
                color = model.GetDefaultBondColor();
            }
            return(color);
        }
Exemple #25
0
        /// <inheritdoc/>
        public IRenderingElement Generate(IAtomContainer container, RendererModel model)
        {
            ElementGroup group = new ElementGroup();

            // TODO : put into RendererModel
            const double SCREEN_RADIUS = 1.0;
            // separation between centers
            const double SCREEN_SEPARATION = 2.5;
            Color        RADICAL_COLOR     = WPF.Media.Colors.Black;

            // XXX : is this the best option?
            double ATOM_RADIUS = model.GetAtomRadius();

            double scale            = model.GetScale();
            double modelAtomRadius  = ATOM_RADIUS / scale;
            double modelPointRadius = SCREEN_RADIUS / scale;
            double modelSeparation  = SCREEN_SEPARATION / scale;

            foreach (var lonePair in container.LonePairs)
            {
                IAtom   atom   = lonePair.Atom;
                Vector2 point  = atom.Point2D.Value;
                int     align  = GeometryUtil.GetBestAlignmentForLabelXY(container, atom);
                var     center = ToPoint(point);
                var     diff   = new WPF::Vector();
                if (align == 1)
                {
                    center.X += modelAtomRadius;
                    diff.Y   += modelSeparation;
                }
                else if (align == -1)
                {
                    center.X -= modelAtomRadius;
                    diff.Y   += modelSeparation;
                }
                else if (align == 2)
                {
                    center.Y -= modelAtomRadius;
                    diff.X   += modelSeparation;
                }
                else if (align == -2)
                {
                    center.Y += modelAtomRadius;
                    diff.X   += modelSeparation;
                }
                group.Add(new OvalElement(center + diff, modelPointRadius, true, RADICAL_COLOR));
                group.Add(new OvalElement(center - diff, modelPointRadius, true, RADICAL_COLOR));
            }
            return(group);
        }
        public void NullFormatCharge()
        {
            var mock_container = new Mock <IAtomContainer>(); var container = mock_container.Object;
            var mock_atom = new Mock <IAtom>(); var atom = mock_atom.Object;

            mock_atom.Setup(n => n.AtomicNumber).Returns(6);
            mock_atom.Setup(n => n.MassNumber).Returns(12);
            mock_atom.Setup(n => n.ImplicitHydrogenCount).Returns(0);
            mock_atom.Setup(n => n.FormalCharge).Returns((int?)null);
            var model      = new RendererModel();
            var atomSymbol = atomGenerator.GenerateSymbol(container, atom, HydrogenPosition.Left, model);
            var shapes     = atomSymbol.GetOutlines();

            Assert.AreEqual(2, shapes.Count);
        }
Exemple #27
0
        private Color?GetHighlightColor(IChemObject bond, RendererModel parameters)
        {
            var propCol = GetColorProperty(bond, HighlightColorKey);

            if (propCol != null)
            {
                return(propCol);
            }

            if (parameters.GetSelection() != null && parameters.GetSelection().Contains(bond))
            {
                return(parameters.GetSelectionColor());
            }

            return(null);
        }
Exemple #28
0
        private StandardSgroupGenerator(RendererModel parameters, StandardAtomGenerator atomGenerator, double stroke, Typeface font, double emSize, Color foreground)
        {
            this.font   = font;
            this.emSize = emSize;
            this.scale  = parameters.GetScale();
            this.stroke = stroke;
            double length = parameters.GetBondLength() / scale;

            this.bracketDepth = parameters.GetSgroupBracketDepth() * length;
            this.labelScale   = parameters.GetSgroupFontScale();

            // foreground is based on the carbon color
            this.foreground    = foreground;
            this.atomGenerator = atomGenerator;
            this.parameters    = parameters;
        }
        /// <summary>
        /// Generate an atom symbol element.
        /// </summary>
        /// <param name="atom">the atom to use</param>
        /// <param name="alignment">the alignment of the atom's label</param>
        /// <param name="model">the renderer model</param>
        /// <returns>an atom symbol element</returns>
        public virtual AtomSymbolElement GenerateElement(IAtom atom, int alignment, RendererModel model)
        {
            string text;

            if (atom is IPseudoAtom)
            {
                text = ((IPseudoAtom)atom).Label;
            }
            else
            {
                text = atom.Symbol;
            }
            return(new AtomSymbolElement(
                       ToPoint(atom.Point2D.Value), text, atom.FormalCharge,
                       atom.ImplicitHydrogenCount, alignment, GetAtomColor(atom, model)));
        }
        /// <inheritdoc/>
        public IRenderingElement Generate(IReaction reaction, RendererModel model)
        {
            if (!model.GetShowReactionBoxes())
            {
                return(null);
            }
            if (reaction.Products.Count == 0)
            {
                return(new ElementGroup());
            }
            double distance    = model.GetBondLength() / model.GetScale() / 2;
            Rect?  totalBounds = null;

            foreach (var molecule in reaction.Products)
            {
                var bounds = BoundsCalculator.CalculateBounds(molecule);
                if (totalBounds == null)
                {
                    totalBounds = bounds;
                }
                else
                {
                    totalBounds = Rect.Union(totalBounds.Value, bounds);
                }
            }
            if (totalBounds == null)
            {
                return(null);
            }

            ElementGroup diagram         = new ElementGroup();
            var          foregroundColor = model.GetForegroundColor();

            diagram.Add(new RectangleElement(
                            new Rect(
                                totalBounds.Value.Left - distance,
                                totalBounds.Value.Top - distance,
                                totalBounds.Value.Right + distance,
                                totalBounds.Value.Bottom + distance),
                            foregroundColor));
            diagram.Add(new TextElement(
                            new Point(
                                (totalBounds.Value.Left + totalBounds.Value.Right) / 2,
                                totalBounds.Value.Top - distance),
                            "Products", foregroundColor));
            return(diagram);
        }