private void DrawPitchTick(double pitch, double offset) { Line line = new Line(); line.X1 = 0; line.X2 = 40; line.Y1 = 0; line.Y2 = 0; line.Stroke = Brushes.LimeGreen; line.StrokeThickness = 2; Canvas.SetLeft(line, -20); Canvas.SetTop(line, offset); Canvas_ViewPortMiddle.Children.Add(line); var textblock = new BorderTextLabel(); textblock.Width = 22; textblock.Stroke = Brushes.LimeGreen; textblock.HorizontalContentAlignment = HorizontalAlignment.Center; textblock.Text = pitch.ToString("##0"); textblock.Foreground = Brushes.LimeGreen; textblock.FontSize = 16; textblock.FontWeight = FontWeights.Bold; Canvas.SetTop(textblock, offset - 8); Canvas.SetLeft(textblock, -textblock.Width - 26); Canvas_ViewPortMiddle.Children.Add(textblock); }
private void DrawRollTick(double cycleR, double angle) { Line line = new Line(); line.X1 = 0; line.X2 = 0; line.Y1 = 6; line.Y2 = 0; line.Stroke = Brushes.LimeGreen; line.StrokeThickness = 2; Canvas.SetTop(line, -cycleR); line.RenderTransform = new RotateTransform(angle, 0, cycleR); Canvas_ViewPortMiddle.Children.Add(line); var textblock = new BorderTextLabel(); textblock.Width = 20; textblock.Stroke = Brushes.LimeGreen; textblock.StrokeThickness = 0; textblock.HorizontalContentAlignment = HorizontalAlignment.Center; textblock.Text = Math.Abs(angle).ToString("##0"); textblock.Foreground = Brushes.LimeGreen; textblock.FontSize = 14; textblock.FontWeight = FontWeights.Bold; Canvas.SetTop(textblock, -cycleR - 20); Canvas.SetLeft(textblock, -textblock.Width / 2); textblock.RenderTransform = new RotateTransform(angle, textblock.Width / 2, cycleR + 20); Canvas_ViewPortMiddle.Children.Add(textblock); }
//绘制左边速度(空速 )矩形 private void RedrawSpeed() { Rectangle rectangle = new Rectangle(); rectangle.Width = 50; rectangle.Height = 150; rectangle.StrokeThickness = 2; rectangle.Stroke = Brushes.White; Canvas.SetTop(rectangle, -rectangle.Height / 2); Canvas.SetLeft(rectangle, 0); Canvas_ViewPortLeft.Children.Add(rectangle); double from = AirSpeed - AirSpeed % 5 + 15; if (from < 25) { from = 25; } double space = (rectangle.Height - 20) / 5; for (int i = 0; i < 6; i++) { Line li = new Line(); li.X1 = rectangle.Width; li.Y1 = -rectangle.Height / 2 + 10 + space * i; li.X2 = li.X1 - 10; li.Y2 = li.Y1; li.StrokeThickness = 2; li.Stroke = Brushes.White; Canvas_ViewPortLeft.Children.Add(li); BorderTextLabel texti = new BorderTextLabel(); texti.Width = 22; texti.Stroke = Brushes.DimGray; texti.HorizontalContentAlignment = HorizontalAlignment.Right; texti.Text = (from - i * 5).ToString("##0"); texti.Foreground = Brushes.White; texti.FontSize = 16; texti.FontWeight = FontWeights.Bold; Canvas.SetLeft(texti, li.X2 - texti.Width - 4); Canvas.SetTop(texti, li.Y1 - 10); Canvas_ViewPortLeft.Children.Add(texti); } TextBlock textblock = new TextBlock(); textblock.Width = 30; textblock.Padding = new Thickness(2, 0, 0, 0); textblock.TextAlignment = TextAlignment.Left; textblock.Text = AirSpeed.ToString("##0.#"); textblock.Foreground = Brushes.White; textblock.Background = Brushes.Red; textblock.FontSize = 12; textblock.FontWeight = FontWeights.Bold; double offset = (from - AirSpeed) / 25 * (rectangle.Height - 20) - rectangle.Height / 2 + 10; Canvas.SetTop(textblock, offset - 8); Canvas.SetLeft(textblock, 0); Canvas_ViewPortLeft.Children.Add(textblock); }
private void DrawStaffTicks(Canvas yawstaffCanvas, bool isrightcanvas) { yawstaffCanvas.Children.Clear(); double wl = yawstaffCanvas.ActualWidth; Line left_l1 = new Line(); left_l1.X1 = 0; left_l1.Y1 = 30; left_l1.X2 = wl; left_l1.Y2 = 30; left_l1.Stroke = Brushes.LimeGreen; left_l1.StrokeThickness = 1; yawstaffCanvas.Children.Add(left_l1); for (int d = 1; d < 90 / tickcount - 1; d++) { Line left_tl = new Line(); left_tl.X1 = d * wl / tickcount; left_tl.Y1 = 20; left_tl.X2 = left_tl.X1; left_tl.Y2 = 30; left_tl.Stroke = Brushes.LimeGreen; left_tl.StrokeThickness = 1; yawstaffCanvas.Children.Add(left_tl); if ((isrightcanvas && d % 2 == 1) || (!isrightcanvas && d % 2 == 0)) { continue; //间隔显示 } var ticktext = new BorderTextLabel(); ticktext.FontWeight = FontWeights.ExtraBold; ticktext.Stroke = Brushes.LimeGreen; ticktext.FontSize = 14; if (isrightcanvas) { ticktext.Text = (d * 90 / tickcount).ToString(); } else { ticktext.Text = (90 - d * 90 / tickcount).ToString(); } ticktext.Foreground = Brushes.LimeGreen; ticktext.StrokeThickness = 0; Canvas.SetTop(ticktext, 2); Canvas.SetLeft(ticktext, left_tl.X1 - 10); yawstaffCanvas.Children.Add(ticktext); } }
private void RedrawOthersInfoText() { BorderTextLabel airspeedlabel = new BorderTextLabel(); airspeedlabel.Stroke = Brushes.DimGray; airspeedlabel.Foreground = Brushes.White; airspeedlabel.FontSize = 14; airspeedlabel.FontWeight = FontWeights.Bold; airspeedlabel.Text = "空速 " + AirSpeed.ToString("0.0"); Canvas.SetLeft(airspeedlabel, 4); Canvas.SetTop(airspeedlabel, 80); Canvas_ViewPortLeft.Children.Add(airspeedlabel); BorderTextLabel groundspeedlabel = new BorderTextLabel(); groundspeedlabel.Stroke = Brushes.DimGray; groundspeedlabel.Foreground = Brushes.White; groundspeedlabel.FontSize = 14; groundspeedlabel.FontWeight = FontWeights.Bold; groundspeedlabel.Text = "地速 " + GroundSpeed.ToString("0.0"); Canvas.SetLeft(groundspeedlabel, 4); Canvas.SetTop(groundspeedlabel, 100); Canvas_ViewPortLeft.Children.Add(groundspeedlabel); BorderTextLabel batteryabel = new BorderTextLabel(); batteryabel.Stroke = Brushes.DimGray; batteryabel.Foreground = Brushes.White; batteryabel.FontSize = 14; batteryabel.FontWeight = FontWeights.Bold; batteryabel.Text = string.Format("电池 {0} v {1} A {2}%", Voltage.ToString("0.00"), Galvanic.ToString("0.0"), BatteryPercent * 100); Canvas.SetLeft(batteryabel, 10); Canvas.SetTop(batteryabel, 130); Canvas_ViewPortLeft.Children.Add(batteryabel); if (HasEKF) { BorderTextLabel ekflabel = new BorderTextLabel(); ekflabel.Stroke = Brushes.DimGray; ekflabel.Foreground = Brushes.White; ekflabel.FontSize = 14; ekflabel.FontWeight = FontWeights.Bold; ekflabel.Text = "EKF"; Canvas.SetLeft(ekflabel, 200); Canvas.SetTop(ekflabel, 130); Canvas_ViewPortLeft.Children.Add(ekflabel); } if (HasVibe) { BorderTextLabel vibelabel = new BorderTextLabel(); vibelabel.Stroke = Brushes.DimGray; vibelabel.Foreground = Brushes.Red; vibelabel.FontSize = 14; vibelabel.FontWeight = FontWeights.Bold; vibelabel.Text = "Vibe"; Canvas.SetLeft(vibelabel, 250); Canvas.SetTop(vibelabel, 130); Canvas_ViewPortLeft.Children.Add(vibelabel); } BorderTextLabel gpslabel = new BorderTextLabel(); gpslabel.Stroke = Brushes.DimGray; gpslabel.Foreground = Brushes.Red; gpslabel.FontSize = 14; gpslabel.FontWeight = FontWeights.Bold; string s = HasGPS ? "有GPS" : "无GPS"; gpslabel.Text = "GPS: " + s; Canvas.SetLeft(gpslabel, 300); Canvas.SetTop(gpslabel, 130); Canvas_ViewPortLeft.Children.Add(gpslabel); BorderTextLabel flytimelabel = new BorderTextLabel(); flytimelabel.Stroke = Brushes.DimGray; flytimelabel.Foreground = Brushes.White; flytimelabel.FontSize = 14; flytimelabel.FontWeight = FontWeights.Bold; flytimelabel.Text = new TimeSpan(FlyTime).ToString(@"hh\:mm\:ss"); Canvas.SetLeft(flytimelabel, -80); Canvas.SetTop(flytimelabel, -110); Canvas_ViewPortRight.Children.Add(flytimelabel); }
//绘制右边海拔(高度)矩形 private void RedrawHeight() { Rectangle rectangle = new Rectangle(); rectangle.Width = 50; rectangle.Height = 150; rectangle.StrokeThickness = 2; rectangle.Stroke = Brushes.White; Canvas.SetTop(rectangle, -rectangle.Height / 2); Canvas.SetRight(rectangle, 0); Canvas_ViewPortRight.Children.Add(rectangle); double from = FlyHeight - FlyHeight % 5 + 15; double space = (rectangle.Height - 20) / 5; for (int i = 0; i < 6; i++) { Line li = new Line(); li.X1 = -rectangle.Width; li.Y1 = -rectangle.Height / 2 + 10 + space * i; li.X2 = li.X1 + 10; li.Y2 = li.Y1; li.StrokeThickness = 2; li.Stroke = Brushes.White; Canvas_ViewPortRight.Children.Add(li); BorderTextLabel texti = new BorderTextLabel(); texti.Width = 22; texti.Stroke = Brushes.DimGray; texti.HorizontalContentAlignment = HorizontalAlignment.Left; texti.Text = (from - i * 5).ToString("##0"); texti.Foreground = Brushes.White; texti.FontSize = 16; texti.FontWeight = FontWeights.Bold; Canvas.SetLeft(texti, li.X2 + 4); Canvas.SetTop(texti, li.Y1 - 10); Canvas_ViewPortRight.Children.Add(texti); } Line l1 = new Line(); l1.X1 = -rectangle.Width + 1; l1.Y1 = -rectangle.Height / 2 + 1; l1.X2 = l1.X1 - 16; l1.Y2 = l1.Y1 + 16; l1.StrokeThickness = 2; l1.Stroke = Brushes.White; Canvas_ViewPortRight.Children.Add(l1); Line l2 = new Line(); l2.X1 = l1.X2; l2.Y1 = l1.Y2 - 1; l2.X2 = l2.X1; l2.Y2 = l2.Y1 + rectangle.Height - 32; l2.StrokeThickness = 2; l2.Stroke = Brushes.White; Canvas_ViewPortRight.Children.Add(l2); Line l3 = new Line(); l3.X1 = l2.X2; l3.Y1 = l2.Y2 - 1; l3.X2 = l1.X1; l3.Y2 = l1.Y1 + rectangle.Height - 2; l3.StrokeThickness = 2; l3.Stroke = Brushes.White; Canvas_ViewPortRight.Children.Add(l3); space = (rectangle.Height - 36) / 9; for (int i = 0; i < 10; i++) { Line li = new Line(); li.X1 = l1.X2; li.X2 = li.X1 + 8; li.Y1 = l1.Y2 + 2 + space * i; li.Y2 = li.Y1; li.StrokeThickness = 2; li.Stroke = Brushes.White; Canvas_ViewPortRight.Children.Add(li); } TextBlock textblock = new TextBlock(); textblock.Width = 30; textblock.Padding = new Thickness(0, 0, 2, 0); textblock.TextAlignment = TextAlignment.Right; textblock.Text = FlyHeight.ToString("##0.#"); textblock.Foreground = Brushes.White; textblock.Background = Brushes.Red; textblock.FontSize = 12; textblock.FontWeight = FontWeights.Bold; double offset = (from - FlyHeight) / 25 * (rectangle.Height - 20) - rectangle.Height / 2 + 10; Canvas.SetTop(textblock, offset - 8); Canvas.SetRight(textblock, 0); Canvas_ViewPortRight.Children.Add(textblock); }
private void DrawYawIndicator(Canvas yawstaffCanvas, float yaw, bool is_right) { yawstaffCanvas.Children.Clear(); double wl = yawstaffCanvas.ActualWidth; // 绘制底部刻度线 Line left_l1 = new Line(); left_l1.X1 = 0; left_l1.Y1 = 30; left_l1.X2 = wl; left_l1.Y2 = 30; left_l1.Stroke = Brushes.LimeGreen; left_l1.StrokeThickness = 1; yawstaffCanvas.Children.Add(left_l1); // 绘制刻度线 int start_yaw = (int)((is_right) ? (yaw + yaw_mid_span) : (yaw - yaw_mid_span - yaw_total_span)); start_yaw %= 360; if (start_yaw < 0) { start_yaw += 360; } int end_yaw = start_yaw + yaw_total_span; int yaw_indic_step = 20, inc_step = 1; int half_yaw_indic_step = yaw_indic_step / 2; for (int d = start_yaw; d < end_yaw; d += inc_step) { if (d % half_yaw_indic_step == 0) { for (int d2 = d; d2 < end_yaw; d2 += half_yaw_indic_step) { Line left_tl = new Line(); left_tl.X1 = (float)(d2 - start_yaw) * wl / yaw_total_span; left_tl.Y1 = 20; left_tl.X2 = left_tl.X1; left_tl.Y2 = 30; left_tl.Stroke = Brushes.LimeGreen; left_tl.StrokeThickness = 1; yawstaffCanvas.Children.Add(left_tl); if (d2 % yaw_indic_step == 0 && ((is_right == false && wl - left_tl.X1 > 15) || ((is_right == true && left_tl.X1 > 15)))) { var ticktext = new BorderTextLabel(); //ticktext.FontWeight = FontWeights.ExtraBold; ticktext.Stroke = Brushes.LimeGreen; ticktext.FontSize = 14; ticktext.Text = (d2 % 360).ToString(); ticktext.Foreground = Brushes.LimeGreen; ticktext.StrokeThickness = 0; Canvas.SetTop(ticktext, 2); Canvas.SetLeft(ticktext, left_tl.X1 - 10); yawstaffCanvas.Children.Add(ticktext); } } break; } } }