update:控制点位

This commit is contained in:
ltx 2026-01-22 11:52:15 +08:00
parent 6d93c2332b
commit 2a9b19b741
4 changed files with 201 additions and 7 deletions

View File

@ -39,6 +39,8 @@ namespace AiSportsMicrospaceDB.Entities
public Point? Point9 { get; set; }
public Point? Point10 { get; set; }
public Point? ControlPoint { get; set; }
public int? KeyPointIndex { get; set; }
public Point? AreaSize { get; set; }
}
}

View File

@ -40,8 +40,24 @@ namespace Common
ControlPoint = groupData.ControlPoint;
AreaSize = groupData.AreaSize;
}
else
HandyControl.Controls.MessageBox.Show("请先设置点位并重启应用!");
else
{
db.GroupPoints.Add(new AiSportsMicrospaceDB.Entities.GroupPoints
{
Code= Code,
Point1 = new AiSportsMicrospaceDB.Entities.Point { X = 0.21, Y = 0.88 },
Point2 = new AiSportsMicrospaceDB.Entities.Point { X = 0.36, Y = 0.58 },
Point3 = new AiSportsMicrospaceDB.Entities.Point { X = 0.50, Y = 0.88 },
Point4 = new AiSportsMicrospaceDB.Entities.Point { X = 0.64, Y = 0.58 },
Point5 = new AiSportsMicrospaceDB.Entities.Point { X = 0.78, Y = 0.88 },
Point6 = new AiSportsMicrospaceDB.Entities.Point { X = 0.92, Y = 0.58 },
ControlPoint = new AiSportsMicrospaceDB.Entities.Point { X = 0.50, Y = 0.88 },
KeyPointIndex = 3,
});
ControlPoint = new AiSportsMicrospaceDB.Entities.Point { X = 0.50, Y = 0.88 };
db.SaveChanges();
}
//HandyControl.Controls.MessageBox.Show("请先设置点位并重启应用!");
SchoolCode = configuration["SchoolCode"] ?? "";
BackendUrl = configuration["BackendUrl"] ?? "";

View File

@ -119,7 +119,14 @@
Click="ResetPointsButton_Click"
Margin="0,5" Height="35" Background="#EF4444" Foreground="White"
FontSize="14" FontWeight="Bold"/>
<!-- 重要点位选择 -->
<TextBlock Text="控制点位:" FontSize="14" Margin="0,10,0,5"/>
<ComboBox x:Name="KeyPointComboBox"
SelectionChanged="KeyPointComboBox_SelectionChanged"
Height="32" FontSize="14"
Margin="0,5,0,10">
<ComboBoxItem Content="不设置"/>
</ComboBox>
<!-- 状态显示 -->
<TextBlock x:Name="StatusText" Text="就绪"
Margin="0,15,0,0" TextWrapping="Wrap"

View File

@ -56,6 +56,12 @@ namespace Wpf_AiSportsMicrospace.Views
private int _lastFrameNumber = -1;
private WriteableBitmap _videoBitmap;
/// <summary>
/// 重要点位索引(0 表示不设置)
/// </summary>
private int _keyPointIndex = 0;
#endregion
#region 构造函数
@ -277,8 +283,8 @@ namespace Wpf_AiSportsMicrospace.Views
if (xProp != null && yProp != null)
{
point.X = (double)(xProp.GetValue(dbPoint) ?? 0) * 1080;
point.Y = (double)(yProp.GetValue(dbPoint) ?? 0) * 1920;
point.X = (double)(xProp.GetValue(dbPoint) ?? 0) * 1920;
point.Y = (double)(yProp.GetValue(dbPoint) ?? 0) * 1080;
}
}
}
@ -292,9 +298,21 @@ namespace Wpf_AiSportsMicrospace.Views
_points.Add(point);
CreatePointControl(point);
}
// 加载控制点位索引
var keyPointProperty = typeof(GroupPoints).GetProperty("KeyPointIndex");
if (keyPointProperty != null)
{
_keyPointIndex = (int)(keyPointProperty.GetValue(data) ?? 0);
}
else
{
_keyPointIndex = 0;
}
RefreshPointsDataList();
UpdateConnectionLine();
RefreshKeyPointComboBox();
}
/// <summary>
@ -319,6 +337,7 @@ namespace Wpf_AiSportsMicrospace.Views
RefreshPointsDataList();
UpdateConnectionLine();
RefreshKeyPointComboBox();
}
/// <summary>
@ -463,6 +482,141 @@ namespace Wpf_AiSportsMicrospace.Views
PointsDataList.ItemsSource = items;
}
/// <summary>
/// 刷新控制点位下拉框
/// </summary>
private void RefreshKeyPointComboBox()
{
// 保存当前选择
int previousSelection = KeyPointComboBox.SelectedIndex;
// 清除并重新填充选项
KeyPointComboBox.Items.Clear();
// 添加"不设置"选项
var noneItem = new ComboBoxItem
{
Content = "不设置",
Tag = 0
};
KeyPointComboBox.Items.Add(noneItem);
// 添加所有点位选项
foreach (var point in _points)
{
var item = new ComboBoxItem
{
Content = $"点位 {point.Id}",
Tag = point.Id
};
KeyPointComboBox.Items.Add(item);
}
// 恢复选择或默认选择
if (previousSelection > 0 && previousSelection <= _points.Count)
{
KeyPointComboBox.SelectedIndex = previousSelection;
}
else if (_keyPointIndex > 0)
{
// 恢复保存的控制点位选择
int comboIndex = _points.FindIndex(p => p.Id == _keyPointIndex);
if (comboIndex >= 0)
{
KeyPointComboBox.SelectedIndex = comboIndex + 1; // +1 因为第一个是"不设置"
}
else
{
KeyPointComboBox.SelectedIndex = 0;
}
}
else
{
KeyPointComboBox.SelectedIndex = 0;
}
}
/// <summary>
/// 控制点位选择改变事件
/// </summary>
private void KeyPointComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (KeyPointComboBox.SelectedItem is ComboBoxItem selectedItem)
{
_keyPointIndex = (int)(selectedItem.Tag ?? 0);
if (_keyPointIndex > 0)
{
UpdateStatus($"已设置点位 {_keyPointIndex} 为控制点位");
HighlightKeyPoint(_keyPointIndex);
}
else
{
UpdateStatus("已取消控制点位设置");
ResetAllPointsHighlight();
}
}
}
/// <summary>
/// 高亮显示控制点位
/// </summary>
private void HighlightKeyPoint(int pointId)
{
// 重置所有点位样式
ResetAllPointsHighlight();
// 高亮控制点位
var ellipse = MainCanvas.Children
.OfType<Ellipse>()
.FirstOrDefault(e => e.Name == $"PointEllipse_{pointId}");
if (ellipse != null)
{
ellipse.Fill = new LinearGradientBrush
{
StartPoint = new Point(0.5, 0),
EndPoint = new Point(0.5, 1),
GradientStops = new GradientStopCollection
{
new GradientStop((Color)ColorConverter.ConvertFromString("#EF4444"), 0),
new GradientStop((Color)ColorConverter.ConvertFromString("#DC2626"), 1)
}
};
ellipse.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#B91C1C"));
ellipse.StrokeThickness = 3;
}
}
/// <summary>
/// 重置所有点位的高亮样式
/// </summary>
private void ResetAllPointsHighlight()
{
foreach (var point in _points)
{
var ellipse = MainCanvas.Children
.OfType<Ellipse>()
.FirstOrDefault(e => e.Name == $"PointEllipse_{point.Id}");
if (ellipse != null)
{
ellipse.Fill = new LinearGradientBrush
{
StartPoint = new Point(0.5, 0),
EndPoint = new Point(0.5, 1),
GradientStops = new GradientStopCollection
{
new GradientStop((Color)ColorConverter.ConvertFromString("#34D399"), 0),
new GradientStop((Color)ColorConverter.ConvertFromString("#059669"), 1)
}
};
ellipse.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#059669"));
ellipse.StrokeThickness = 2;
}
}
}
/// <summary>
/// 更新连接线
/// </summary>
@ -903,14 +1057,29 @@ namespace Wpf_AiSportsMicrospace.Views
if (pointProperty != null)
{
// 创建 Point 实例并保存
var pointInstance = Activator.CreateInstance(pointType, point.X / 1080, point.Y / 1920);
var pointInstance = Activator.CreateInstance(pointType, point.X / 1920, point.Y / 1080);
var pointNew = new AiSportsMicrospaceDB.Entities.Point {
X =point.X / 1080,Y= point.Y / 1920
X =point.X / 1920,Y= point.Y / 1080
};
pointProperty.SetValue(pointsData, pointNew);
}
}
}
// 保存重要点位索引
var keyPointProperty = typeof(GroupPoints).GetProperty("KeyPointIndex");
var controlPoint = typeof(GroupPoints).GetProperty("ControlPoint");
var controlPointNew = new AiSportsMicrospaceDB.Entities.Point
{
X = _points[_keyPointIndex].X / 1920,
Y = _points[_keyPointIndex].Y / 1080
};
if (keyPointProperty != null)
{
keyPointProperty.SetValue(pointsData, _keyPointIndex);
controlPoint.SetValue(pointsData, controlPointNew);
}
db.SaveChanges();
UpdateStatus("点数据保存成功");
}