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 NewEllipsoid : Form {
        public double radx, rady, radz;
        public int hdiv, vdiv;
        public double cx, cy, cz;

        public NewEllipsoid() {
            InitializeComponent();
        }

        private void cbCenter_CheckedChanged(object sender, EventArgs e) {
            if (!cbCenter.Checked) gbCenter.Enabled = true; else gbCenter.Enabled = false;
        }

        private void NewEllipsoid_FormClosing(object sender, FormClosingEventArgs e) {
            if (this.DialogResult == DialogResult.OK) {
                if (tbRadX.Text == "" || tbRadY.Text == "" || tbRadZ.Text == "" || tbHdiv.Text == "" || tbVdiv.Text == "") {
                    MessageBox.Show("Empty parameter fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (gbCenter.Enabled && (tbCX.Text == "" || tbCY.Text == "" || tbCZ.Text == "")) {
                    MessageBox.Show("Empty parameter fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (gbCenter.Enabled && (!Double.TryParse(tbCX.Text, out cx) || !Double.TryParse(tbCY.Text, out cy) || !Double.TryParse(tbCZ.Text, out cz))) {
                    MessageBox.Show("Incorrect number format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (!Double.TryParse(tbRadX.Text, out radx) || !Double.TryParse(tbRadY.Text, out rady) || !Double.TryParse(tbRadZ.Text, out radz) ||
                    !Int32.TryParse(tbHdiv.Text, out hdiv) || !Int32.TryParse(tbVdiv.Text, out vdiv)) {
                    MessageBox.Show("Incorrect number format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (hdiv < 3 || hdiv > 360 || vdiv < 3 || vdiv > 360) {
                    MessageBox.Show("Horizontal and vertical division must be between 3 and 360!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
            }
        }
    }
}