using System;
using System.Windows.Forms;
using ChemAxon.NET.Base.View;
using ChemAxon.NET.Base.Chemistry.Data;
using ChemAxon.NET.Base.Chemistry.Formats;
using ChemAxon.NET.Windows.Forms.MarvinViewControl;
using ChemAxon.NET.Windows.Forms.MarvinEditorControl;
using ChemAxon.NET.API;

namespace _2013_Developer_training {

    public class ShowMarvinSketch {
        public static void DisplayMolecule() {
            var benzeneData = new MoleculeData("[O-]C1=CC=CC=C1", MoleculeFormat.SMILES);
            var benzeneMolecule = MainFactory.Chemistry.CreateMolecule(benzeneData);
            ////////////////////////////////////////////////////
            // viewer
            var viewer = new MarvinViewControl();
            viewer.Molecule = "C1=CC=CC=C1";
            ShowMoleculeControl(viewer, "Viewer Control with Molecule string");

            viewer = new MarvinViewControl();
            viewer.MoleculeData = benzeneData;
            ShowMoleculeControl(viewer, "Viewer Control with Molecule Data");

            viewer = new MarvinViewControl();
            viewer.MoleculeObject = benzeneMolecule.Transformations.AddHAtoms();
            ShowMoleculeControl(viewer, "Viewer Control with Molecule Object");

            // actions, context menu, resize, readonly mode
            new MarvinViewControlTester().ShowDialog();
        }

        public static void  EditMolecule() {
            var benzeneData = new MoleculeData("[O-]C1=CC=CC=C1", MoleculeFormat.SMILES);
            var benzeneMolecule = MainFactory.Chemistry.CreateMolecule(benzeneData);

            /////////////////////////////////////////////////////////
            // editor
            var editor = new MarvinEditorControl();
            editor.Molecule = "C1=CC=CC=C1";
            editor.MoleculeFormat = MoleculeFormat.SMILES.GetDescription().CodeName;
            ShowMoleculeControl(editor, "Editor Control with Molecule string");

            editor = new MarvinEditorControl();
            editor.MoleculeData = benzeneData;
            ShowMoleculeControl(editor, "Editor Control with Molecule Data");

            editor = new MarvinEditorControl();
            editor.MoleculeObject = benzeneMolecule.Transformations.AddHAtoms();
            ShowMoleculeControl(editor, "Editor Control with Molecule Object");
        }

        public static void ShowEditorDialog() {
            var benzeneData = new MoleculeData("[O-]C1=CC=CC=C1", MoleculeFormat.SMILES);
            //////////////////////////////////////////////////////////////
            // sketcher form
            IMoleculeEditorView view = new MarvinSketchForm();
            view.MoleculeData = benzeneData;
            if (view.ShowAsDialog() == DialogResponse.OK) {
                Console.WriteLine("Molecule has been amended ...");
            }
            else {
                Console.WriteLine("Editing cancelled ...");
            }
        }

        private static void ShowMoleculeControl(Control c, string title) {
            var frm = new Form();
            frm.Text = title;
            frm.Controls.Add(c);
            c.Dock = DockStyle.Fill;
            frm.ShowDialog();
        }
    }

}