102 lines
3.9 KiB
C#
102 lines
3.9 KiB
C#
using KDCS.Utils;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace KMBIM
|
|
{
|
|
public partial class Radius : Form
|
|
{
|
|
public const double PI = 3.14159265358;
|
|
|
|
public double m_xdst = 0.0;
|
|
public double m_ydst = 0.0;
|
|
|
|
public Radius()
|
|
{
|
|
InitializeComponent();
|
|
m_xdst = 0.0;
|
|
|
|
m_ydst = 0.0;
|
|
}
|
|
|
|
private void txt_radius_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (txt_radius.Text == "") txt_radius.Text = "0";
|
|
if (txt_length1.Text == "") txt_length1.Text = "0";
|
|
if (txt_length2.Text == "") txt_length2.Text = "0";
|
|
if (txt_cnt1.Text == "") txt_cnt1.Text = "0";
|
|
if (txt_cnt2.Text == "") txt_cnt2.Text = "0";
|
|
if (double.IsNaN(m_xdst)) return;
|
|
if (double.IsNaN(m_ydst)) return;
|
|
|
|
bool flg = false;
|
|
double convert_Radius = Unit.MMToFeet(Convert.ToDouble(txt_radius.Text));
|
|
//double convert_Radius = Unit.CovertToAPI(Convert.ToDouble(txt_radius.Text), DisplayUnitType.DUT_MILLIMETERS);
|
|
double ang = 45 / 180.0 * PI;
|
|
//m_ydst = 2 * (Convert.ToDouble(txt_radius.Text) / 0.00328) * System.Math.Sin(ang);
|
|
//m_xdst = 2 * (Convert.ToDouble(txt_radius.Text) / 0.00328) * System.Math.Cos(ang);
|
|
m_ydst = 2 * Convert.ToDouble(txt_radius.Text) * Math.Sin(ang);
|
|
m_xdst = 2 * Convert.ToDouble(txt_radius.Text) * Math.Cos(ang);
|
|
|
|
txt_cnt1.Text = (Math.Floor(Convert.ToDouble(txt_length1.Text) / m_xdst)).ToString();
|
|
txt_cnt2.Text = (Math.Floor(Convert.ToDouble(txt_length2.Text) / m_ydst)).ToString();
|
|
|
|
if (Convert.ToDouble(txt_length1.Text) > Convert.ToInt32(txt_cnt1.Text) * m_xdst)
|
|
{//면적에 꽉 차는가?
|
|
txt_cnt1.Text = (Convert.ToInt32(txt_cnt1.Text) + 1).ToString();
|
|
m_xdst = Convert.ToDouble(txt_length1.Text) / Convert.ToInt32(txt_cnt1.Text);
|
|
m_ydst = Math.Sqrt((Convert.ToDouble(txt_radius.Text) / 0.00328) * (Convert.ToDouble(txt_radius.Text) / 0.00328) - Math.Pow(0.5 * m_xdst, 2.0)) * 2.0;
|
|
flg = true;
|
|
}
|
|
if (Convert.ToDouble(txt_length2.Text) > Convert.ToInt32(txt_cnt2.Text) * m_ydst)
|
|
{
|
|
txt_cnt2.Text = (Convert.ToInt32(txt_cnt2.Text) + 1).ToString();
|
|
m_ydst = Convert.ToDouble(txt_length2.Text) / Convert.ToInt32(txt_cnt2.Text);
|
|
if (!flg) m_xdst = Math.Sqrt((Convert.ToDouble(txt_radius.Text) / 0.00328) * (Convert.ToDouble(txt_radius.Text) / 0.00328) - Math.Pow(0.5 * m_ydst, 2.0)) * 2.0;
|
|
}
|
|
}
|
|
|
|
private void txt_cnt1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
m_xdst = Convert.ToDouble(txt_length1.Text) / Convert.ToInt32(txt_cnt1.Text);
|
|
}
|
|
|
|
private void txt_cnt2_TextChanged(object sender, EventArgs e)
|
|
{
|
|
m_ydst = Convert.ToDouble(txt_length2.Text) / Convert.ToInt32(txt_cnt2.Text);
|
|
}
|
|
|
|
private void Radius_Load(object sender, EventArgs e)
|
|
{
|
|
this.KeyPreview = true;
|
|
}
|
|
|
|
private void Radius_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Escape)
|
|
{
|
|
//this.Close();
|
|
this.DialogResult = DialogResult.Cancel;
|
|
}
|
|
else if (e.KeyCode == Keys.Enter)
|
|
{
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
|
|
private void txt_radius_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
int keyCode = (int)e.KeyChar;
|
|
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46)
|
|
e.Handled = true;
|
|
|
|
if (keyCode == 46)
|
|
{
|
|
if (string.IsNullOrEmpty(txt_radius.Text) || txt_radius.Text.Contains('.') == true)
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|