public FanCurveEditor(IList <FanPoint> curve, FanCurveKind curveKind) { this.Curve = curve; this.CurveKind = curveKind; this.InitializeComponent(); #region Grid this.GridPoints = new FanGraphPoint[11]; for (int i = 0; i < this.GridPoints.Length; ++i) { FanPoint p = new FanPoint(i * 10.0, i * 0.1); this.GridPoints[i] = new FanGraphPoint(this, () => p, null); } for (int i = 0; i < this.GridPoints.Length; ++i) { Line vLine = new Line { Stroke = Brushes.Gray }; this.canvas.Children.Add(vLine); vLine.SetBinding(Line.X1Property, $"GridPoints[{i}].X"); vLine.Y1 = 0.0; vLine.SetBinding(Line.X2Property, $"GridPoints[{i}].X"); vLine.SetBinding(Line.Y2Property, $"Canvas.ActualHeight"); Line hLine = new Line { Stroke = Brushes.Gray }; this.canvas.Children.Add(hLine); hLine.X1 = 0.0; hLine.SetBinding(Line.Y1Property, $"GridPoints[{i}].Y"); hLine.SetBinding(Line.X2Property, $"Canvas.ActualWidth"); hLine.SetBinding(Line.Y2Property, $"GridPoints[{i}].Y"); TextBlock text = new TextBlock(); this.canvas.Children.Add(text); text.SetBinding(TextBlock.TextProperty, $"GridPoints[{i}].Temperature"); text.SetBinding(Canvas.LeftProperty, $"GridPoints[{i}].X"); Canvas.SetBottom(text, 0.0); } #endregion this.updatePoints(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { //失能对比按钮 btnAddCompare.IsEnabled = false; this.Title = this.CompanyName + "---" + this.WindFieldName + "---第 " + this.FanNumber + " 号风机"; //获取当前风机的风场信息 windFieldOfFan = AllWindFieldDAL.GetWindFieldByName(this.CompanyName, this.WindFieldName); //获得当前风机的最新数据 FanPoint fp = FanPointDAL.GetSinglePoint(windFieldOfFan.BranchTableName, this.WindFieldName, this.FanNumber); txtbkDigital.Text = "业主名称:" + windFieldOfFan.CompanyName + "\n" + "风场名称:" + windFieldOfFan.WindFieldName + "\n" + "地址:" + windFieldOfFan.Province + windFieldOfFan.City + windFieldOfFan.DetailAddress + "\n\n" + "-------------------------------\n" + "风机型号:" + windFieldOfFan.FanModelNumber + "\n" + "风机高度:" + windFieldOfFan.FanHeight + "\n" + "测风仪型号:" + windFieldOfFan.AnemoscopeModelNumber + "\n" + "-------------------------------\n" + "经纬度:" + fp.GPS_lng + "E " + fp.GPS_lat + "N\n" + "风机号:" + fp.FanNumber + "\n" + "风速:" + fp.WindSpeed + "\n" + "风向:" + fp.WindDirection + "\n" + "临时IP:" + fp.TempIp + "\n" + "海拔:" + fp.Elevation + "\n" + "航向:" + fp.Course + "\n" + "航速:" + fp.NavigationalSpeed + "\n" + "温度:" + fp.Temperature + "\n" + "湿度:" + fp.Humidity + "\n" + "气压:" + fp.AirPressure + "\n"; //预加载省份 provinceArray = AllWindFieldDAL.GetAllProvince(); if (provinceArray != null) { //如果查到了省份,则加载到复选框 List <string> provinceList = new List <string>(); provinceList.Add("全国范围"); provinceList.AddRange(provinceArray); cmbProvince.ItemsSource = provinceList;//加载省份 cmbProvince.SelectedItem = "全国范围"; } //预加载所有公司名称 companyArray = AllWindFieldDAL.GetCompanyName(); LoadCompany("全国范围", companyArray); }
private Point pointToCanvas(FanPoint p) { Point s = this.getGraphSize(); return(new Point(p.Temperature / 100 * s.X, (1.0 - p.FanSpeed) * s.Y)); }
private void updatePoints(int?focused = null) { if (this.graphElements != null) { foreach (UIElement el in this.graphElements) { this.canvas.Children.Remove(el); } } this.graphElements = new List <UIElement>(); this.Points = new FanGraphPoint[this.Curve.Count]; for (int i = 0; i < this.Points.Length; ++i) { int j = i; this.Points[i] = new FanGraphPoint(this, () => this.Curve[j], v => this.Curve[j] = v); } Brush lineBrush = new SolidColorBrush(Colors.DodgerBlue); Ellipse focusedEllipse = null; for (int i = 0; i < this.Points.Length; ++i) { int j = i; Ellipse ellipse = new Ellipse { Focusable = true, Style = (Style)this.Resources["EllipseStyle"], Tag = i }; if (focused != null && focused.Value == i) { focusedEllipse = ellipse; } ellipse.SetBinding(Canvas.LeftProperty, $"Points[{i}].EllipseX"); ellipse.SetBinding(Canvas.TopProperty, $"Points[{i}].EllipseY"); ellipse.SetBinding(WidthProperty, $"Points[{i}].EllipseW"); ellipse.SetBinding(HeightProperty, $"Points[{i}].EllipseH"); if (i < this.Points.Length - 1) { if (this.CurveKind == FanCurveKind.Step) { Line line1 = new Line { StrokeThickness = 2, Stroke = lineBrush, }; this.graphElements.Add(line1); Line line2 = new Line { StrokeThickness = 2, Stroke = lineBrush, }; this.graphElements.Add(line2); line1.SetBinding(Line.X1Property, $"Points[{i}].X"); line1.SetBinding(Line.Y1Property, $"Points[{i}].Y"); line1.SetBinding(Line.X2Property, $"Points[{i + 1}].X"); line1.SetBinding(Line.Y2Property, $"Points[{i}].Y"); line2.SetBinding(Line.X1Property, $"Points[{i + 1}].X"); line2.SetBinding(Line.Y1Property, $"Points[{i}].Y"); line2.SetBinding(Line.X2Property, $"Points[{i + 1}].X"); line2.SetBinding(Line.Y2Property, $"Points[{i + 1}].Y"); } else if (this.CurveKind == FanCurveKind.Linear) { Line line = new Line { StrokeThickness = 2, Stroke = lineBrush, }; this.graphElements.Add(line); line.SetBinding(Line.X1Property, $"Points[{i}].X"); line.SetBinding(Line.Y1Property, $"Points[{i}].Y"); line.SetBinding(Line.X2Property, $"Points[{i + 1}].X"); line.SetBinding(Line.Y2Property, $"Points[{i + 1}].Y"); } } this.graphElements.Add(ellipse); void updateLabel() { this.infoLabel.Text = $"Point {j}: {this.Points[j].Point.FanSpeed * 100.0:F1}% at {this.Points[j].Point.Temperature:F1}°C"; } ellipse.MouseDown += (s, e) => { ellipse.Focus(); ellipse.CaptureMouse(); updateLabel(); }; ellipse.MouseUp += (s, e) => { ellipse.ReleaseMouseCapture(); this.infoLabel.Text = ""; }; ellipse.MouseMove += (s, e) => { if (!ellipse.IsMouseCaptured) { return; } FanPoint p = this.canvasToPoint(e.GetPosition(this.canvas)); p.Temperature = Math.Max(0.0, Math.Min(100.0, p.Temperature)); p.FanSpeed = Math.Max(0.0, Math.Min(1.0, p.FanSpeed)); if (j == 0) { p.Temperature = 0.0; } if (j > 0) { FanPoint p2 = this.Points[j - 1].Point; if (p.Temperature < p2.Temperature) { p.Temperature = p2.Temperature; } //if (p.Y < p2.Y) // p.Y = p2.Y; } if (j < this.Points.Length - 1) { FanPoint p2 = this.Points[j + 1].Point; if (p.Temperature > p2.Temperature) { p.Temperature = p2.Temperature; } //if (p.Y > p2.Y) // p.Y = p2.Y; } if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0) { p.FanSpeed = Math.Round(p.FanSpeed, 2); p.Temperature = Math.Round(p.Temperature); } this.Points[j].Point = p; updateLabel(); }; } foreach (UIElement el in this.graphElements) { this.canvas.Children.Add(el); } focusedEllipse?.Focus(); }