// public Rectangle PaintReactionSet( // IReactionSet reactionSet, IDrawVisitor drawVisitor) { // // total up the bounding boxes // Rectangle2D totalBounds = CreateRectangle(); // foreach (var reaction in reactionSet.reactions()) { // Rectangle2D modelBounds = BoundsCalculator.CalculateBounds(reaction); // if (totalBounds == null) { // totalBounds = modelBounds; // } else { // totalBounds = totalBounds.CreateUnion(modelBounds); // } // } // // // setup and draw // this.SetupTransformNatural(totalBounds); // ElementGroup diagram = new ElementGroup(); // foreach (var reaction in reactionSet.reactions()) { // diagram.Add(this.GenerateDiagram(reaction)); // } // this.Paint(drawVisitor, diagram); // // // the size of the painted diagram is returned // return this.ConvertToDiagramBounds(totalBounds); // } // // public Rectangle PaintReaction( // IReaction reaction, IDrawVisitor drawVisitor) { // // // calculate the bounds // Rectangle2D modelBounds = BoundsCalculator.CalculateBounds(reaction); // // // setup and draw // this.SetupTransformNatural(modelBounds); // IRenderingElement diagram = this.GenerateDiagram(reaction); // this.Paint(drawVisitor, diagram); // // return this.ConvertToDiagramBounds(modelBounds); // } /// <summary> /// Paint a ChemModel. /// </summary> /// <param name="chemModel"></param> /// <param name="drawVisitor">the visitor that does the drawing</param> /// <param name="bounds">the bounds of the area to paint on.</param> /// <param name="resetCenter">if true, set the modelCenter to the center of the ChemModel's bounds.</param> public void Paint(IChemModel chemModel, IDrawVisitor drawVisitor, Rect bounds, bool resetCenter) { // check for an empty model var moleculeSet = chemModel.MoleculeSet; IReactionSet reactionSet = chemModel.ReactionSet; // nasty, but it seems that reactions can be read in as ChemModels // with BOTH a ReactionSet AND a MoleculeSet... if (moleculeSet == null || reactionSet != null) { if (reactionSet != null) { reactionSetRenderer.Paint(reactionSet, drawVisitor, bounds, resetCenter); } return; } // calculate the total bounding box var modelBounds = BoundsCalculator.CalculateBounds(moleculeSet); this.SetupTransformToFit(bounds, modelBounds, AverageBondLengthCalculator.CalculateAverageBondLength(chemModel), resetCenter); // generate the elements IRenderingElement diagram = moleculeSetRenderer.GenerateDiagram(moleculeSet); // paint it this.Paint(drawVisitor, diagram); }
public void TestCalculateBounds_IAtomContainer_SingleAtom() { IAtomContainer container = new AtomContainer(); container.Atoms.Add(container.Builder.NewAtom("C")); BoundsCalculator.CalculateBounds(container); }
/// <summary> /// Paint a molecule (an IAtomContainer). /// </summary> /// <param name="atomContainer">the molecule to paint</param> /// <param name="drawVisitor">the visitor that does the drawing</param> /// <param name="bounds">the bounds on the screen</param> /// <param name="resetCenter">if true, set the draw center to be the center of bounds</param> public void Paint(IAtomContainer atomContainer, IDrawVisitor drawVisitor, Rect bounds, bool resetCenter) { if (atomContainer.Bonds.Count > 0 || atomContainer.Atoms.Count == 1) { rendererModel.SetScale( CalculateScaleForBondLength(GeometryUtil.GetBondLengthAverage(atomContainer))); } else if (atomContainer.Atoms.Count > 1) { rendererModel.SetScale( CalculateScaleForBondLength(EstimatedBondLength(atomContainer))); } // the diagram to draw var diagram = GenerateDiagram(atomContainer); // the bounds of the model from 'Bounds' elements // no bounding elements, use the atom coordinates var modelBounds = GetBounds(diagram); if (modelBounds.IsEmpty) { modelBounds = BoundsCalculator.CalculateBounds(atomContainer); } SetupTransformToFit(bounds, modelBounds, resetCenter); this.Paint(drawVisitor, diagram); }
/// <inheritdoc/> public Rect CalculateDiagramBounds(IChemObjectSet <IAtomContainer> moleculeSet) { if (moleculeSet == null) { return(this.CalculateScreenBounds(new Rect())); } return(this.CalculateScreenBounds(BoundsCalculator.CalculateBounds(moleculeSet))); }
/// <summary> /// Setup the transformations necessary to draw this Atom Container. /// </summary> /// <param name="atomContainer">the atom container to use in the setup</param> /// <param name="screen">the area to draw on</param> public void Setup(IAtomContainer atomContainer, Rect screen) { this.SetScale(atomContainer); var bounds = BoundsCalculator.CalculateBounds(atomContainer); this.modelCenter = new Point(bounds.CenterX(), bounds.CenterY()); this.drawCenter = new Point(screen.CenterX(), screen.CenterY()); this.Setup(); }
/// <summary> /// Setup the transformations necessary to draw this Reaction Set. /// </summary> /// <param name="reactionSet"></param> /// <param name="screen"></param> public void Setup(IReactionSet reactionSet, Rect screen) { this.SetScale(reactionSet); var bounds = BoundsCalculator.CalculateBounds(reactionSet); this.modelCenter = new Point((bounds.Left + bounds.Right) / 2, (bounds.Top + bounds.Right) / 2); this.drawCenter = new Point((screen.Left + screen.Right) / 2, (screen.Top + screen.Right) / 2); this.Setup(); }
/// <summary> /// Setup the transformations necessary to draw this Reaction. /// </summary> /// <param name="reaction"></param> /// <param name="screen"></param> public void Setup(IReaction reaction, Rect screen) { this.SetScale(reaction); var bounds = BoundsCalculator.CalculateBounds(reaction); this.modelCenter = new Point(bounds.Value.CenterX(), bounds.Value.CenterY()); this.drawCenter = new Point(screen.CenterX(), screen.CenterY()); this.Setup(); }
public void TestCalculateBounds_IReaction_SingleAtom() { IAtomContainer container = new AtomContainer(); container.Atoms.Add(container.Builder.NewAtom("C")); IReaction reaction = container.Builder.NewReaction(); reaction.Reactants.Add(container.Builder.NewAtomContainer(container)); BoundsCalculator.CalculateBounds(reaction); }
public void TestCalculateBounds_IAtomContainerSet() { IAtomContainer container = new AtomContainer(); container.Atoms.Add(container.Builder.NewAtom("C")); container.Atoms.Add(container.Builder.NewAtom("C")); var set = container.Builder.NewAtomContainerSet(); set.Add(container); BoundsCalculator.CalculateBounds(set); }
/// <summary> /// Setup the transformations necessary to draw this <see cref="IChemObjectSet{T}"/>. /// </summary> /// <param name="moleculeSet">the <see cref="IChemObjectSet{T}"/> for what to set the scale</param> /// <param name="screen">the <see cref="Rect"/> for which to calculate the scale</param> public void Setup(IChemObjectSet <IAtomContainer> moleculeSet, Rect screen) { this.SetScale(moleculeSet); var bounds = BoundsCalculator.CalculateBounds(moleculeSet); if (bounds != null) { this.modelCenter = new Point(bounds.CenterX(), bounds.CenterY()); } this.drawCenter = new Point(screen.CenterX(), screen.CenterY()); this.Setup(); }
/// <summary> /// Paint a set of molecules. /// </summary> /// <param name="molecules">the <see cref="IChemObjectSet{T}"/> to paint</param> /// <param name="drawVisitor">the visitor that does the drawing</param> /// <param name="bounds">the bounds on the screen</param> /// <param name="resetCenter">if true, set the draw center to be the center of bounds</param> public void Paint(IChemObjectSet <IAtomContainer> molecules, IDrawVisitor drawVisitor, Rect bounds, bool resetCenter) { // total up the bounding boxes var totalBounds = BoundsCalculator.CalculateBounds(molecules); this.SetupTransformToFit(bounds, totalBounds, AverageBondLengthCalculator.CalculateAverageBondLength(molecules), resetCenter); IRenderingElement diagram = this.GenerateDiagram(molecules); this.Paint(drawVisitor, diagram); }
/// <summary> /// Setup the transformations necessary to draw this Chem Model. /// </summary> /// <param name="chemModel"></param> /// <param name="screen"></param> public void Setup(IChemModel chemModel, Rect screen) { this.SetScale(chemModel); var bounds = BoundsCalculator.CalculateBounds(chemModel); if (bounds != null) { this.modelCenter = new Point((bounds.Left + bounds.Right) / 2, (bounds.Top + bounds.Bottom) / 2); } this.drawCenter = new Point((screen.Left + screen.Right) / 2, (screen.Top + screen.Bottom) / 2); this.Setup(); }
/// <summary> /// Paint a reaction. /// </summary> /// <param name="reaction">the reaction to paint</param> /// <param name="drawVisitor">the visitor that does the drawing</param> /// <param name="bounds">the bounds on the screen</param> /// <param name="resetCenter">/// if true, set the draw center to be the center of bounds</param> public void Paint(IReaction reaction, IDrawVisitor drawVisitor, Rect bounds, bool resetCenter) { // calculate the bounds var modelBounds = BoundsCalculator.CalculateBounds(reaction).Value; this.SetupTransformToFit(bounds, modelBounds, AverageBondLengthCalculator.CalculateAverageBondLength(reaction), resetCenter); // generate the elements var diagram = this.GenerateDiagram(reaction); // paint it this.Paint(drawVisitor, diagram); }
/// <inheritdoc/> public Rect Paint(IReaction reaction, IDrawVisitor drawVisitor) { // calculate the bounds var modelBounds = BoundsCalculator.CalculateBounds(reaction).Value; // setup and draw this.SetupTransformNatural(modelBounds); var diagram = this.GenerateDiagram(reaction); this.Paint(drawVisitor, diagram); return(this.ConvertToDiagramBounds(modelBounds)); }
/// <inheritdoc/> public Rect Paint(IAtomContainer atomContainer, IDrawVisitor drawVisitor) { // the bounds of the model var modelBounds = BoundsCalculator.CalculateBounds(atomContainer); // setup and draw this.SetupTransformNatural(modelBounds); IRenderingElement diagram = GenerateDiagram(atomContainer); this.Paint(drawVisitor, diagram); return(this.ConvertToDiagramBounds(modelBounds)); }
public void TestCalculateBounds_IChemModel_SingleAtom() { IAtomContainer container = new AtomContainer(); container.Atoms.Add(container.Builder.NewAtom("C")); var set = container.Builder.NewAtomContainerSet(); set.Add(container); IChemModel model = container.Builder.NewChemModel(); model.MoleculeSet = set; BoundsCalculator.CalculateBounds(model); }
/// <inheritdoc/> public Rect Paint(IChemObjectSet <IAtomContainer> moleculeSet, IDrawVisitor drawVisitor) { // total up the bounding boxes var totalBounds = BoundsCalculator.CalculateBounds(moleculeSet); // setup and draw this.SetupTransformNatural(totalBounds); IRenderingElement diagram = this.GenerateDiagram(moleculeSet); this.Paint(drawVisitor, diagram); return(this.ConvertToDiagramBounds(totalBounds)); }
/// <summary> /// Paint a set of reactions. /// </summary> /// <param name="reactionSet">the reaction to paint</param> /// <param name="drawVisitor">the visitor that does the drawing</param> /// <param name="bounds">the bounds on the screen</param> /// <param name="resetCenter">if true, set the draw center to be the center of bounds</param> public void Paint(IReactionSet reactionSet, IDrawVisitor drawVisitor, Rect bounds, bool resetCenter) { // total up the bounding boxes var totalBounds = BoundsCalculator.CalculateBounds(reactionSet); this.SetupTransformToFit(bounds, totalBounds, AverageBondLengthCalculator.CalculateAverageBondLength(reactionSet), resetCenter); ElementGroup diagram = new ElementGroup(); foreach (var reaction in reactionSet) { diagram.Add(reactionRenderer.GenerateDiagram(reaction)); } // paint them all this.Paint(drawVisitor, diagram); }
/// <inheritdoc/> public Rect Paint(IReactionSet reactionSet, IDrawVisitor drawVisitor) { // total up the bounding boxes var totalBounds = BoundsCalculator.CalculateBounds(reactionSet); // setup and draw this.SetupTransformNatural(totalBounds); var diagram = new ElementGroup(); foreach (var reaction in reactionSet) { diagram.Add(reactionRenderer.GenerateDiagram(reaction)); } this.Paint(drawVisitor, diagram); // the size of the painted diagram is returned return(this.ConvertToDiagramBounds(totalBounds)); }
/// <summary> /// Paint an IChemModel using the IDrawVisitor at a scale determined by the /// bond length in RendererModel. /// </summary> /// <param name="chemModel">the chem model to draw</param> /// <param name="drawVisitor">the visitor used to draw with</param> /// <returns>the rectangular area that the diagram will occupy on screen</returns> public Rect Paint(IChemModel chemModel, IDrawVisitor drawVisitor) { var moleculeSet = chemModel.MoleculeSet; var reactionSet = chemModel.ReactionSet; if (moleculeSet == null && reactionSet != null) { Rect totalBounds = BoundsCalculator.CalculateBounds(reactionSet); this.SetupTransformNatural(totalBounds); IRenderingElement diagram = reactionSetRenderer.GenerateDiagram(reactionSet); this.Paint(drawVisitor, diagram); return(this.ConvertToDiagramBounds(totalBounds)); } if (moleculeSet != null && reactionSet == null) { Rect totalBounds = BoundsCalculator.CalculateBounds(moleculeSet); this.SetupTransformNatural(totalBounds); IRenderingElement diagram = moleculeSetRenderer.GenerateDiagram(moleculeSet); this.Paint(drawVisitor, diagram); return(this.ConvertToDiagramBounds(totalBounds)); } if (moleculeSet != null && reactionSet != null) { var totalBounds = BoundsCalculator.CalculateBounds(chemModel); this.SetupTransformNatural(totalBounds); ElementGroup diagram = new ElementGroup { reactionSetRenderer.GenerateDiagram(reactionSet), moleculeSetRenderer.GenerateDiagram(moleculeSet) }; this.Paint(drawVisitor, diagram); // the size of the painted diagram is returned return(this.ConvertToDiagramBounds(totalBounds)); } return(new Rect(0, 0, 0, 0)); }
/// <summary> /// Given a chem model, calculates the bounding rectangle in screen space. /// </summary> /// <param name="model">the model to draw.</param> /// <returns>a rectangle in screen space.</returns> public Rect CalculateDiagramBounds(IChemModel model) { var moleculeSet = model.MoleculeSet; var reactionSet = model.ReactionSet; if ((moleculeSet == null && reactionSet == null)) { return(Rect.Empty); } var moleculeBounds = Rect.Empty; var reactionBounds = Rect.Empty; if (moleculeSet != null) { moleculeBounds = BoundsCalculator.CalculateBounds(moleculeSet); } if (reactionSet != null) { reactionBounds = BoundsCalculator.CalculateBounds(reactionSet); } if (moleculeBounds.IsEmpty) { return(this.CalculateScreenBounds(reactionBounds)); } else if (reactionBounds.IsEmpty) { return(this.CalculateScreenBounds(moleculeBounds)); } else { var allbounds = Rect.Union(moleculeBounds, reactionBounds); return(this.CalculateScreenBounds(allbounds)); } }
/// <summary> /// Given a chem model, calculates the bounding rectangle in screen space. /// </summary> /// <param name="model">the model to draw.</param> /// <returns>a rectangle in screen space.</returns> public Rect CalculateDiagramBounds(IChemModel model) { var moleculeSet = model.MoleculeSet; IReactionSet reactionSet = model.ReactionSet; if ((moleculeSet == null && reactionSet == null)) { return(new Rect()); } Rect?moleculeBounds = null; Rect?reactionBounds = null; if (moleculeSet != null) { moleculeBounds = BoundsCalculator.CalculateBounds(moleculeSet); } if (reactionSet != null) { reactionBounds = BoundsCalculator.CalculateBounds(reactionSet); } if (moleculeBounds == null) { return(this.CalculateScreenBounds(reactionBounds.Value)); } else if (reactionBounds == null) { return(this.CalculateScreenBounds(moleculeBounds.Value)); } else { Rect allbounds = Rect.Union(moleculeBounds.Value, reactionBounds.Value); return(this.CalculateScreenBounds(allbounds)); } }
/// <inheritdoc/> public Rect CalculateDiagramBounds(IReactionSet reactionSet) { return(this.CalculateScreenBounds(BoundsCalculator.CalculateBounds(reactionSet))); }
/// <inheritdoc/> public Rect CalculateDiagramBounds(IAtomContainer atomContainer) { return(CalculateScreenBounds(BoundsCalculator.CalculateBounds(atomContainer))); }
/// <inheritdoc/> public Rect CalculateDiagramBounds(IReaction reaction) { return(this.CalculateScreenBounds(BoundsCalculator.CalculateBounds(reaction).Value)); }