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 NewIcosahedron : Form {

        public double edgelen;
        public double cx, cy, cz;

        public NewIcosahedron() {
            InitializeComponent();
        }

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

        private void NewIcosahedron_FormClosing(object sender, FormClosingEventArgs e) {
            if (this.DialogResult == DialogResult.OK) {
                if (tbEdgeLength.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(tbEdgeLength.Text, out edgelen)) {
                    MessageBox.Show("Incorrect number format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
            }
        }

    }
}