using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VisimBox.Scene;
using VisiMath;


namespace VisimBuilder
{
    public partial class ImportModelSettings : Form
    {
        public ImportModelSettings()
        {
            InitializeComponent();
        }

        

        private void button3_Click(object sender, EventArgs e)
        {
            //set defaults
            if (setts == null)
                return;
            setts.SetDefaults();
            if (setts.DefaultTrans == null)
            {
                checkBox1.Checked = false;                
            }
            else
            {
                checkBox1.Checked = true;
            }
            transformationControl1.ChangeTrans(setts.DefaultTrans);
            propertyGrid1.SelectedObject = null;
            propertyGrid1.SelectedObject = setts;
            
        }

        NodeImportSettings setts;

        public NodeImportSettings Settings
        {
            get { return setts; }
            set 
            { 
                setts = value;
                propertyGrid1.SelectedObject = setts;
            }
        }

        ITransformation trans;

        private void Startup(object sender, EventArgs e)
        {
            propertyGrid1.SelectedObject = setts;
            trans = setts.DefaultTrans;
            transformationControl1.ChangeTrans(trans);
            if (trans != null)
                checkBox1.Checked = true;
            else
                checkBox1.Checked = false;
        }

        private void PretransChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                if (trans == null)
                    trans = new Transformation();
                setts.DefaultTrans = trans;
                propertyGrid1.SelectedObject = null;
                propertyGrid1.SelectedObject = setts;
                transformationControl1.ChangeTrans(trans);
            }
            else
            {                
                setts.DefaultTrans = null;
                propertyGrid1.SelectedObject = null;
                propertyGrid1.SelectedObject = setts;
                transformationControl1.ChangeTrans(null);
            }
        }

        private void ClosingForm(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                if (trans != null)
                {
                    setts.DefaultTrans = trans;
                }
            }
        }
        
    }
}
