public bool DoTest() { // Position type IConverter converter = new Utility.Converters.FunctionConverter("Sin(x)", 100, 1, 0); IPath path = new Path(converter); IRecord record = new Record(path); for (int i = 0; i < record.Time.Length; i++) { if ((int)record.Time[i] != i) return false; } // Check some random values if (!Check(record.Position[10], -0.54402111088936977)) return false; if (!Check(record.Position[50], -0.26237485370392877)) return false; if (!Check(record.Position[90], 0.89399666360055785)) return false; return true; }
private void _ok_Click(object sender, EventArgs e) { int type = 0; int skip = 0; if (_box.SelectedItem == null) { MessageBox.Show("Please select a Function Type"); return; } if (string.Compare(_box.SelectedItem.ToString(), "Position vs. Time") == 0) type = 0; else if (string.Compare(_box.SelectedItem.ToString(), "Velocity vs. Time") == 0) type = 1; else if (string.Compare(_box.SelectedItem.ToString(), "Acceleration vs. Time") == 0) type = 2; else { MessageBox.Show("Please Select a Function Type"); skip = 1; } Expression ex = new Expression(_box1.Text.Replace("x", "1")); try { ex.Evaluate(); double timeStep; double totalTime; if (Double.TryParse(_box1step.Text, out timeStep)) { if (Double.TryParse(_box1length.Text, out totalTime)) { IConverter converter = new Utility.Converters.FunctionConverter(_box1.Text.ToString(), totalTime, timeStep, type); _mainForm.Project.Axis1 = new Axis(converter); _mainForm.MainPanel.SetMiddle(_mainForm.Project.Profile.Component); _mainForm.MainPanel.SetRight(_mainForm.Project.ChooseMotor.Component); _mainForm.Project.Profile.Solve(); if (this.OnClose != null) this.OnClose(this, EventArgs.Empty); _mainForm.MainPanel.SetMiddle(_mainForm.Project.Profile.Component); } else { MessageBox.Show("Invalid time length"); skip = 1; } } else { MessageBox.Show("Invalid time step"); skip = 1; } } catch (Exception a) { MessageBox.Show("Error caught: " + a.Message); Console.WriteLine("Error caught: " + a.Message); skip = 1; } if (skip != 1 && !_box2.Text.Equals("")) { Expression ex2 = new Expression(_box2.Text.Replace("x", "1")); try { ex2.Evaluate(); double timeStep; double totalTime; if (Double.TryParse(_box2step.Text, out timeStep)) { if (Double.TryParse(_box2length.Text, out totalTime)) { IConverter converter = new Utility.Converters.FunctionConverter(_box2.Text.ToString(), totalTime, timeStep, type); _mainForm.Project.Axis2 = new Axis(converter); _mainForm.MainPanel.SetMiddle(_mainForm.Project.Profile.Component); _mainForm.MainPanel.SetRight(_mainForm.Project.ChooseMotor.Component); _mainForm.Project.Profile.Solve(); if (this.OnClose != null) this.OnClose(this, EventArgs.Empty); _mainForm.MainPanel.SetMiddle(_mainForm.Project.Profile.Component); } else { MessageBox.Show("Invalid time length"); skip = 1; } } else { MessageBox.Show("Invalid time step"); skip = 1; } } catch (Exception a) { MessageBox.Show("Error caught: " + a.Message); Console.WriteLine("Error caught: " + a.Message); skip = 1; } } if (skip != 1 && !_box3.Text.Equals("")) { Expression ex3 = new Expression(_box3.Text.Replace("x", "1")); try { ex3.Evaluate(); double timeStep; double totalTime; if (Double.TryParse(_box3step.Text, out timeStep)) { if (Double.TryParse(_box3length.Text, out totalTime)) { IConverter converter = new Utility.Converters.FunctionConverter(_box3.Text.ToString(), totalTime, timeStep, type); _mainForm.Project.Axis3 = new Axis(converter); _mainForm.MainPanel.SetMiddle(_mainForm.Project.Profile.Component); _mainForm.MainPanel.SetRight(_mainForm.Project.ChooseMotor.Component); _mainForm.Project.Profile.Solve(); if (this.OnClose != null) this.OnClose(this, EventArgs.Empty); _mainForm.MainPanel.SetMiddle(_mainForm.Project.Profile.Component); } else MessageBox.Show("Invalid time length"); } else MessageBox.Show("Invalid time step"); } catch (Exception a) { MessageBox.Show("Error caught: " + a.Message); Console.WriteLine("Error caught: " + a.Message); } } }