using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChemAxon.NET.API;
using ChemAxon.NET.IKVM.Chemistry;
using ChemAxon.NET.Windows.Forms.MarvinViewControl;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace ChemAxon.NET.UnitTest.API.Examples.Workflow
{
    public class WorkflowExample
    {
        public void EditMolecule_Example()
        {
            IJChemMolecule molecule = MainFactory.Chemistry.CreateMolecule("benzene");
            IJChemMolecule newMolecule;

            bool isMoleculeChanged = MainFactory.Workflow.EditMolecule(molecule, out newMolecule);

            if (isMoleculeChanged)
                Console.WriteLine(string.Format("The molecule has changed to: {0}", newMolecule.Formula));
        }

        public void ShowMolecule_Example()
        {
            IJChemMolecule molecule = MainFactory.Chemistry.CreateMolecule("benzene");

            IMoleculeViewer moleculeViewer = new CustomMoleculeViewer();
            moleculeViewer.Caption = molecule.Formula;
            moleculeViewer.DisplayHeight = 100;
            moleculeViewer.DisplayWidth = 100;
            moleculeViewer.Readonly = true;

            MainFactory.Workflow.ShowMolecule(molecule, moleculeViewer);            
        }
    }



    public class CustomMoleculeViewer : IMoleculeViewer
    {
        public string Caption { get;set;}

        public int DisplayHeight { get; set; }

        public int DisplayWidth { get; set; }

        public bool Readonly { get; set; }
       
        public void ShowMolecule(IJChemMolecule molecule)
        {
            molecule.Renderer.Settings.DrawingInfo.Size = new Size(DisplayWidth, DisplayHeight);
            Image image = molecule.Renderer.RenderToImage(ImageFormat.Emf);

            Form frm = new Form();
            frm.Text = Caption;
            frm.Height = DisplayHeight;
            frm.Width = DisplayWidth;

            PictureBox pb = new PictureBox();
            frm.Controls.Add(pb);
            pb.Visible = true;
            pb.Dock = DockStyle.Fill;
            pb.Image = image;

            frm.ShowDialog();
        }        
    }
}