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

namespace CSGBuilder {
    public partial class RotateForm : Form {
        double angle;

        public RotateForm() {
            InitializeComponent();
            cbAxis.SelectedIndex = 0;
        }

        private void cbAxis_SelectedIndexChanged(object sender, EventArgs e) {
            if (cbAxis.SelectedIndex == 3)
                gbUDA.Enabled = true;
            else
                gbUDA.Enabled = false;
        }

        private void RotateForm_FormClosing(object sender, FormClosingEventArgs e) {
            if (this.DialogResult == DialogResult.OK) {
                if (tbAngle.Text == "") {
                    MessageBox.Show("Empty fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (!Double.TryParse(tbAngle.Text, out angle)) {
                    MessageBox.Show("Incorrect number format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (gbUDA.Enabled && (tbUX1.Text == "" || tbUY1.Text == "" || tbUZ1.Text == "" ||
                    tbUX2.Text == "" || tbUY2.Text == "" || tbUZ2.Text == "")) {
                    MessageBox.Show("Empty fields in User Defined Axis!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                double x;
                if (gbUDA.Enabled && (!Double.TryParse(tbUX1.Text, out x) || !Double.TryParse(tbUY1.Text, out x) || !Double.TryParse(tbUZ1.Text, out x) ||
                    !Double.TryParse(tbUX2.Text, out x) || !Double.TryParse(tbUY2.Text, out x) || !Double.TryParse(tbUZ2.Text, out x))) {
                    MessageBox.Show("Incorrect number format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
            }
        }
    }
}