using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DockableUI;

namespace Object_Editor
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        Windows.ModelView myEditor;
        Windows.ToolViewport myViewport;
        Windows.ModelViewFour myEditor4;

        ObjectManager.Mesh[] openedObject;

        private void FrmMain_Load(object sender, EventArgs e)
        {

            myEditor = new Windows.ModelView();
            //myEditor.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
            //myEditor.Owner = this;
            //myEditor.TopLevel = false;
            myEditor.Parent = this.dockContainer;
            myEditor.Dock = DockStyle.Fill;
            //myEditor.Dock = DockStyle.Left;
            myEditor.Show();
            //myEditor.Parent = this.dockContainer;
            //myEditor.MaximumSize = myEditor.Size;
            //myEditor.WindowState = FormWindowState.Maximized;
            myViewport = new Windows.ToolViewport();
            //myViewport.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
            //myViewport.Owner = this;
            myViewport.Parent = this.dockContainer;
            myViewport.Dock = DockStyle.Right;
            myViewport.Show();

            myEditor4 = new Windows.ModelViewFour();
            myEditor4.Parent = this.dockContainer;
            myEditor4.Dock = DockStyle.Fill;
            //myEditor4.Show();
        }

        private void sToolStripMenuItem_Click(object sender, EventArgs e)
        {
            myEditor.ClientSize = new Size(100, 100);
        }

        private void CommandOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog Dialog = new OpenFileDialog();
            Dialog.CheckFileExists = true;
            Dialog.Multiselect = false;
            Dialog.Filter = "openBVE Object Editor Object (*.oe.csv)|*.oe.csv|All files|*";
            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                //string f = Dialog.FileName;
                //IObjectParser CurrentParser = new CompatibleCsvParser();
                //string[] Messages;
                //FileOpener.Open(out GlobalMesh, new System.IO.FileStream(f, System.IO.FileMode.Open));//CurrentParser.LoadFile(f, out Messages);
                System.IO.FileStream fs = new System.IO.FileStream(Dialog.FileName, System.IO.FileMode.Open);
                ObjectFile.Open(out openedObject, fs);
                fs.Close();

                //pageObjs.treeView1.Nodes.Clear();
                //pageMsgs.listBox1.Items.Clear();

                //pageMsgs.listBox1.Items.AddRange(Messages);

                //TreeNode q = new TreeNode(System.IO.Path.GetFileName(f));
                //q.ToolTipText = f;
                //foreach (ObjectManager.Mesh i in openedObject)
                //{
                //    TreeNode x = new TreeNode("Mesh");
                //    TreeNode y = new TreeNode("Vertices");
                //    for (int j = 0; j < i.Vertices.Count; j++)//each (ObjectManager.Vertex  j in i.Vertices)
                //    {
                //        y.Nodes.Add(j.ToString() + " " + i.Vertices[j].Coordinates.ToString());
                //    }
                //    x.Nodes.Add(y);
                //    TreeNode z = new TreeNode("Faces");
                //    for (int j = 0; j < i.Faces.Count; j++)//each (ObjectManager.Vertex  j in i.Vertices)
                //    {
                //        z.Nodes.Add(i.Faces[j].BackVisible ? "Face2" : "Face " + " (" + ArrayToStringGeneric(i.Faces[j].Vertices, ", ") + ")");
                //    }
                //    x.Nodes.Add(z);
                //    x.Nodes.Add("Position " + i.StaticTranslation.ToString());
                //    x.Nodes.Add("Rotation (" + i.StaticXRotation + ", " + i.StaticYRotation + ", " + i.StaticZRotation + ")");
                //    q.Nodes.Add(x);
                //}
                //pageObjs.treeView1.Nodes.Add(q);
                myEditor.glControl.RenderMesh = openedObject;
                myEditor.glControl.Render();
            }
        }
    }
}
