public static double USBHeight(MachineParameters Machine, double WheelDiameter, double JigProjectionLength, double TargetAngle) { // we need a machine to do the calculations if (Machine == null) { throw new ArgumentException("The machine parameters are required for the calculation!"); } // the diameter is 150 to 250 mm if (WheelDiameter <= 0) { throw new ArgumentException("The wheel diameter should be greater than 0"); } if (JigProjectionLength <= 0) { throw new ArgumentException("The JigProjectionLength should be greater than 0"); } if (TargetAngle <= 0) { throw new ArgumentException("The target angle should be greater than 0"); } // the radius of the wheel double r = WheelDiameter / 2.0; // the jig projection length minus half of the diameter of the USB (12mm for Tormek) double k = JigProjectionLength - Machine.USBdiameter / 2; // the length from below the USB to the blade double l = Math.Sqrt(k * k + Machine.USBdiameter * Machine.USBdiameter); // target angle minus the angle build by jigprojectionlength and USB double alpha = TargetAngle - RadianToDegree(12 / (JigProjectionLength - Machine.USBdiameter / 2)); // and finally the height in two steps double m = Math.Pow(r, 2) + Math.Pow(l, 2) - 2 * r * l * Math.Cos(DegreeToRadian(alpha + 90)); return(Math.Sqrt(m - Machine.USBdx * Machine.USBdx) - Machine.USBdy + Machine.USBdiameter / 2); }
public static double USB2Wheel(MachineParameters Machine, double WheelDiameter, double JigProjectionLength, double TargetAngle) { // we need a machine to do the calculations if (Machine == null) { throw new ArgumentException("The machine parameters are required for the calculation!"); } // the diameter is 150 to 250 mm if (WheelDiameter <= 0) { throw new ArgumentException("The wheel diameter should be greater than 0"); } if (JigProjectionLength <= 0) { throw new ArgumentException("The JigProjectionLength should be greater than 0"); } if (TargetAngle <= 0) { throw new ArgumentException("The target angle should be greater than 0"); } // the radius of the wheel double r = WheelDiameter / 2.0; // correcting the angle double alpha = TargetAngle - RadianToDegree(Machine.USBdiameter / (JigProjectionLength - Machine.USBdiameter / 2)); // and finally the distance in two steps double k = Math.Sqrt(Math.Pow(JigProjectionLength - Machine.USBdiameter / 2, 2) + Math.Pow(Machine.USBdiameter, 2)); double m = Math.Sqrt(Math.Pow(r, 2) + Math.Pow(k, 2) - 2 * r * k * Math.Cos(DegreeToRadian(alpha + 90))); return(m - r + Machine.USBdiameter / 2); }
private void fMain_FormClosing(object sender, FormClosingEventArgs e) { // check if there were changes in the machine list if (_machinesChanged) { // show a dialog box if (MessageBox.Show("You made changes in the machine list. Do you want to save these changes?", "Please confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { // write the file MachineParameters.WriteMachineParametersToFile(_machines, _machinesConfigFile); } catch (Exception ex) { // something went wrong MessageBox.Show("Error writing " + _machinesConfigFile + ". Error message is: " + ex.Message, "Error", MessageBoxButtons.OK); } } } // save defaults Properties.Settings.Default.SelectedMachineIndex = cbMachines.SelectedIndex; Properties.Settings.Default.WheelDiameter = double.Parse(txtWheelDiameter.Text); Properties.Settings.Default.JigProjectionLength = double.Parse(txtJigProjectionLength.Text); Properties.Settings.Default.TargetAngle = double.Parse(txtTargetAngle.Text); Properties.Settings.Default.Save(); }
private void Calculate() { // get the values double wheelDiameter; double.TryParse(txtWheelDiameter.Text, out wheelDiameter); double jigProjectionLength; double.TryParse(txtJigProjectionLength.Text, out jigProjectionLength); double targetAngle; double.TryParse(txtTargetAngle.Text, out targetAngle); // check them if ((wheelDiameter <= 0) || (jigProjectionLength <= 0) || (targetAngle <= 0)) { lblUSBtoHousing.Text = "-"; lblUSBtoWheel.Text = "-"; return; } // get the selected machine MachineParameters machine = _machines[cbMachines.SelectedIndex]; // calculate it lblUSBtoHousing.Text = Calculator.USBHeight(machine, wheelDiameter, jigProjectionLength, targetAngle).ToString("0.00"); lblUSBtoWheel.Text = Calculator.USB2Wheel(machine, wheelDiameter, jigProjectionLength, targetAngle).ToString("0.00"); }
private void btnAdd_Click(object sender, EventArgs e) { // create a show a dialog to enter the name for this machine fNewMachineName dlg = new fNewMachineName(); if (dlg.ShowDialog() == DialogResult.OK) { // check the name if ((dlg.txtName.Text == "") || (dlg.txtName.Text.Trim() == "Custom")) { MessageBox.Show("Please provide a valid name for this machine. Don't use the name 'Custom' as this is a reserved name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // create a new machine MachineParameters newMachine = new MachineParameters(dlg.txtName.Text, double.Parse(txtUSBDx.Text), double.Parse(txtUSBDy.Text), double.Parse(txtUSBdiameter.Text)); // add it to our list _machines.Add(newMachine); // add it to the combo cbMachines.Items.Add(newMachine.Name); // select it cbMachines.SelectedIndex = _machines.Count - 1; // flag that the machines have been changed _machinesChanged = true; } }
private void miLoadMachineList_Click(object sender, EventArgs e) { // execute the open file dialog if (ofd.ShowDialog() == DialogResult.OK) { try { // load the database List <MachineParameters> machines = MachineParameters.ReadMachineParametersFromFile(ofd.FileName); // save the new machines _machines = machines; // clear the combo box cbMachines.Items.Clear(); // add the machines to the combo box foreach (MachineParameters machine in _machines) { cbMachines.Items.Add(machine.Name); } // select the first cbMachines.SelectedIndex = 0; } catch (Exception ex) { // display a hint MessageBox.Show("Error loading machine database: " + ex.Message, "Error loading file!"); } } }
private void miSaveMachineList_Click(object sender, EventArgs e) { // execute the save file dialog if (sfd.ShowDialog() == DialogResult.OK) { try { // save the database MachineParameters.WriteMachineParametersToFile(_machines, sfd.FileName); } catch (Exception ex) { // display a hint MessageBox.Show("Error saving machine database: " + ex.Message, "Error writing file!"); } } }
private void miRestoreDefaultMachineList_Click(object sender, EventArgs e) { // load the default machine data _machines = MachineParameters.BuildDefaultMachineList(); // create a custom machine MachineParameters custom = new MachineParameters("Custom", 50, 29, 12); // add it to the list _machines.Add(custom); // clear the combo box cbMachines.Items.Clear(); // add the machines to the combo box foreach (MachineParameters machine in _machines) { cbMachines.Items.Add(machine.Name); } // select the first cbMachines.SelectedIndex = 0; // flag that the machines have been changed _machinesChanged = true; }
private void fMain_Load(object sender, EventArgs e) { // the filename for our settings file _machinesConfigFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cmbTea\\MachineParameters.machinedb"); // try to load it _machines = MachineParameters.ReadMachineParametersFromFile(_machinesConfigFile); // if it fails, build the default list if (_machines == null) { _machines = MachineParameters.BuildDefaultMachineList(); // and save it try { // write the file MachineParameters.WriteMachineParametersToFile(_machines, _machinesConfigFile); } catch (Exception ex) { // something went wrong MessageBox.Show("Error writing " + _machinesConfigFile + ". Error message is: " + ex.Message, "Error", MessageBoxButtons.OK); } } // create a custom machine MachineParameters custom = new MachineParameters("Custom", 50, 29, 12); // add it to the list _machines.Add(custom); // add the machines to the combo box foreach (MachineParameters machine in _machines) { cbMachines.Items.Add(machine.Name); } // load defaults cbMachines.SelectedIndex = Properties.Settings.Default.SelectedMachineIndex; txtWheelDiameter.Text = Properties.Settings.Default.WheelDiameter.ToString("0.0"); txtJigProjectionLength.Text = Properties.Settings.Default.JigProjectionLength.ToString("0.0"); txtTargetAngle.Text = Properties.Settings.Default.TargetAngle.ToString("0.0"); // calculate it Calculate(); }