private void Calc(State state, TrainPacket packet, double lim, bool high, bool unlock, bool euler, bool slip) { new Task(() => { double dist = 0; List <double> vels = new List <double>(); BtnCalc.Invoke(new Action(() => BtnCalc.Enabled = false)); BtnClear.Invoke(new Action(() => BtnClear.Enabled = false)); while (state.Invoke()) { if (euler) { if (slip) { if (high) { if (unlock) { TrainController.DoMotionWithSlip(packet, 8.0); } else { TrainController.DoMotionWithSlip(packet, 5.0); } } else { TrainController.DoMotionWithSlip(packet, 3.5); } } else { if (high) { if (unlock) { TrainController.DoMotionWithEuler(packet, 8.0); } else { TrainController.DoMotionWithEuler(packet, 5.0); } } else { TrainController.DoMotionWithEuler(packet, 3.5); } } } else { if (high) { if (unlock) { TrainController.DoMotionWithAirHighEx(packet); } else { TrainController.DoMotionWithAirHigh(packet); } } else { TrainController.DoMotionWithAir(packet); } } dist += packet.Velocity; vels.Add(packet.Velocity); if (dist > MAX) { BoxDist.Invoke(new Action(() => BoxDist.Text = "NULL")); BtnCalc.Invoke(new Action(() => BtnCalc.Enabled = true)); BtnClear.Invoke(new Action(() => BtnClear.Enabled = true)); return; } } BtnCalc.Invoke(new Action(() => BtnCalc.Enabled = true)); BtnClear.Invoke(new Action(() => BtnClear.Enabled = true)); BoxDist.Invoke(new Action(() => BoxDist.Text = dist.ToString("F1"))); double max = Max(vels); double step = (double)BoxGraph.Width / (double)vels.Count; double scale = (double)BoxGraph.Height / max; for (int i = 0; i < vels.Count - 1; i++) { g.DrawLine( Pens.Black, (float)(i * step), (float)((double)BoxGraph.Height - vels[i] * scale), (float)((i + 1) * step), (float)((double)BoxGraph.Height - vels[i + 1] * scale) ); } vels.Clear(); }).Start(); }
private void BtnClear_Click(object sender, EventArgs e) { BoxV.Clear(); BoxP.Clear(); BoxR.Clear(); BoxLim.Clear(); BoxDist.Clear(); BoxCode.Clear(); }