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 NewCone : Form {
        public double rad, height;
        public int div;
        public double cx, cy, cz;

        public NewCone() {
            InitializeComponent();
        }

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

        private void NewCone_FormClosing(object sender, FormClosingEventArgs e) {
            if (this.DialogResult == DialogResult.OK) {
                if (tbRad.Text == "" || tbHeight.Text == "" || tbDiv.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(tbRad.Text, out rad) || !Double.TryParse(tbHeight.Text, out height) ||
                    !Int32.TryParse(tbDiv.Text, out div)) {
                    MessageBox.Show("Incorrect number format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (div < 3 || div > 360) {
                    MessageBox.Show("Mesh division must be between 3 and 360!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
            }
        }
    }
}