FocusAnalyzerControl.xaml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <UserControl x:Class="TeamAAS_VP.Controls.FocusAnalyzerControl"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:c="clr-namespace:TeamAAS_VP.ValueConverter"
  7. xmlns:local="clr-namespace:TeamAAS_VP.Controls"
  8. xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
  9. xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
  10. xmlns:oxy="http://oxyplot.org/wpf"
  11. mc:Ignorable="d"
  12. d:DesignHeight="600"
  13. d:DesignWidth="800">
  14. <UserControl.Resources>
  15. <!-- 样式 -->
  16. <Style x:Key="CardStyle"
  17. TargetType="Border">
  18. <Setter Property="Background"
  19. Value="#FFFFFF" />
  20. <Setter Property="CornerRadius"
  21. Value="4" />
  22. <Setter Property="BorderBrush"
  23. Value="#E0E0E0" />
  24. <Setter Property="BorderThickness"
  25. Value="1" />
  26. <Setter Property="Padding"
  27. Value="8" />
  28. <Setter Property="Margin"
  29. Value="4" />
  30. </Style>
  31. <Style x:Key="ToolButtonStyle"
  32. TargetType="RadioButton">
  33. <Setter Property="Width"
  34. Value="30" />
  35. <Setter Property="Height"
  36. Value="30" />
  37. <Setter Property="Margin"
  38. Value="2" />
  39. <Setter Property="Cursor"
  40. Value="Hand" />
  41. <Setter Property="Template">
  42. <Setter.Value>
  43. <ControlTemplate TargetType="RadioButton">
  44. <Border Background="{TemplateBinding Background}"
  45. BorderBrush="{TemplateBinding BorderBrush}"
  46. BorderThickness="1"
  47. CornerRadius="4">
  48. <ContentPresenter HorizontalAlignment="Center"
  49. VerticalAlignment="Center" />
  50. </Border>
  51. <ControlTemplate.Triggers>
  52. <Trigger Property="IsChecked"
  53. Value="True">
  54. <Setter Property="Background"
  55. Value="#007ACC" />
  56. <Setter Property="Foreground"
  57. Value="White" />
  58. </Trigger>
  59. <Trigger Property="IsMouseOver"
  60. Value="True">
  61. <Setter Property="Background"
  62. Value="#F0F0F0" />
  63. </Trigger>
  64. </ControlTemplate.Triggers>
  65. </ControlTemplate>
  66. </Setter.Value>
  67. </Setter>
  68. </Style>
  69. <!-- ROI控制点样式 -->
  70. <Style x:Key="RoiHandleStyle"
  71. TargetType="Ellipse">
  72. <Setter Property="Width"
  73. Value="8" />
  74. <Setter Property="Height"
  75. Value="8" />
  76. <Setter Property="Fill"
  77. Value="White" />
  78. <Setter Property="Stroke"
  79. Value="Red" />
  80. <Setter Property="StrokeThickness"
  81. Value="1" />
  82. <Setter Property="Cursor"
  83. Value="SizeAll" />
  84. </Style>
  85. <!-- 旋转控制点样式 -->
  86. <Style x:Key="RotateHandleStyle"
  87. TargetType="Path">
  88. <Setter Property="Fill"
  89. Value="Red" />
  90. <Setter Property="Stroke"
  91. Value="White" />
  92. <Setter Property="StrokeThickness"
  93. Value="1" />
  94. <Setter Property="Cursor"
  95. Value="SizeAll" />
  96. <Setter Property="Data"
  97. Value="M 0,0 L 5,0 L 2.5,5 Z" />
  98. </Style>
  99. <c:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
  100. </UserControl.Resources>
  101. <Grid>
  102. <Grid.ColumnDefinitions>
  103. <ColumnDefinition Width="*" />
  104. <ColumnDefinition Width="280" />
  105. </Grid.ColumnDefinitions>
  106. <!-- 左侧:图像显示区 -->
  107. <Border Grid.Column="0"
  108. Style="{StaticResource CardStyle}"
  109. Margin="10">
  110. <Grid>
  111. <!-- 图像容器 -->
  112. <Grid x:Name="ImageContainer">
  113. <!-- 图像显示 -->
  114. <Image x:Name="ImageDisplay"
  115. Source="{Binding CurrentImage}"
  116. Stretch="Uniform"
  117. MouseLeftButtonDown="ImageDisplay_MouseLeftButtonDown"
  118. MouseLeftButtonUp="ImageDisplay_MouseLeftButtonUp"
  119. MouseMove="ImageDisplay_MouseMove">
  120. <!--<b:Interaction.Triggers>
  121. <b:EventTrigger EventName="MouseLeftButtonDown">
  122. <b:InvokeCommandAction Command="{Binding ImageMouseDownCommand}" />
  123. </b:EventTrigger>
  124. <b:EventTrigger EventName="MouseMove">
  125. <b:InvokeCommandAction Command="{Binding ImageMouseMoveCommand}" />
  126. </b:EventTrigger>
  127. <b:EventTrigger EventName="MouseLeftButtonUp">
  128. <b:InvokeCommandAction Command="{Binding ImageMouseUpCommand}" />
  129. </b:EventTrigger>
  130. </b:Interaction.Triggers>-->
  131. </Image>
  132. <!-- ROI绘制层 -->
  133. <Canvas x:Name="RoiCanvas"
  134. IsHitTestVisible="False">
  135. <!-- ROI矩形(带旋转) -->
  136. <Rectangle x:Name="RoiRectangle"
  137. Visibility="{Binding ShowRoi, Converter={StaticResource BooleanToVisibilityConverter}}">
  138. <Rectangle.Style>
  139. <Style TargetType="Rectangle">
  140. <Setter Property="Stroke"
  141. Value="Red" />
  142. <Setter Property="StrokeThickness"
  143. Value="2" />
  144. <Setter Property="StrokeDashArray"
  145. Value="4,4" />
  146. <Setter Property="RenderTransformOrigin"
  147. Value="0.5,0.5" />
  148. <Style.Triggers>
  149. <DataTrigger Binding="{Binding RoiMode}"
  150. Value="Draw">
  151. <Setter Property="StrokeDashArray"
  152. Value="2,2" />
  153. </DataTrigger>
  154. </Style.Triggers>
  155. </Style>
  156. </Rectangle.Style>
  157. <Rectangle.RenderTransform>
  158. <RotateTransform Angle="{Binding CurrentRoi.Angle}" />
  159. </Rectangle.RenderTransform>
  160. </Rectangle>
  161. <!-- ROI控制点 -->
  162. <Canvas Visibility="{Binding ShowRoi, Converter={StaticResource BooleanToVisibilityConverter}}">
  163. <!-- 角点控制点 -->
  164. <Ellipse x:Name="TopLeftHandle"
  165. Style="{StaticResource RoiHandleStyle}" />
  166. <Ellipse x:Name="TopRightHandle"
  167. Style="{StaticResource RoiHandleStyle}" />
  168. <Ellipse x:Name="BottomLeftHandle"
  169. Style="{StaticResource RoiHandleStyle}" />
  170. <Ellipse x:Name="BottomRightHandle"
  171. Style="{StaticResource RoiHandleStyle}" />
  172. <!-- 边中点控制点 -->
  173. <Ellipse x:Name="TopHandle"
  174. Style="{StaticResource RoiHandleStyle}" />
  175. <Ellipse x:Name="RightHandle"
  176. Style="{StaticResource RoiHandleStyle}" />
  177. <Ellipse x:Name="BottomHandle"
  178. Style="{StaticResource RoiHandleStyle}" />
  179. <Ellipse x:Name="LeftHandle"
  180. Style="{StaticResource RoiHandleStyle}" />
  181. <!-- 旋转控制点 -->
  182. <Path x:Name="RotateHandle"
  183. Style="{StaticResource RotateHandleStyle}" />
  184. </Canvas>
  185. </Canvas>
  186. <!-- 操作提示 -->
  187. <Border Background="#80000000"
  188. CornerRadius="4"
  189. Padding="8"
  190. VerticalAlignment="Bottom"
  191. HorizontalAlignment="Center"
  192. Margin="0,0,0,10">
  193. <StackPanel>
  194. <TextBlock Text="ROI操作提示"
  195. Foreground="White"
  196. FontWeight="Bold"
  197. Margin="0,0,0,4" />
  198. <TextBlock Text="拖动: 移动ROI"
  199. Foreground="White"
  200. FontSize="11" />
  201. <TextBlock Text="角点拖动: 调整大小"
  202. Foreground="White"
  203. FontSize="11" />
  204. <TextBlock Text="旋转点拖动: 旋转"
  205. Foreground="White"
  206. FontSize="11" />
  207. </StackPanel>
  208. </Border>
  209. </Grid>
  210. </Grid>
  211. </Border>
  212. <!-- 右侧:控制面板 -->
  213. <Grid Grid.Column="1"
  214. Margin="0,10,10,10">
  215. <Grid.RowDefinitions>
  216. <RowDefinition Height="Auto" />
  217. <RowDefinition Height="Auto" />
  218. <RowDefinition Height="Auto" />
  219. <RowDefinition Height="Auto" />
  220. <RowDefinition Height="*" />
  221. </Grid.RowDefinitions>
  222. <!-- ROI工具栏 -->
  223. <Border Grid.Row="0"
  224. Style="{StaticResource CardStyle}">
  225. <StackPanel>
  226. <TextBlock Text="ROI工具"
  227. FontWeight="Bold"
  228. Margin="0,0,0,8" />
  229. <StackPanel Orientation="Horizontal"
  230. HorizontalAlignment="Center">
  231. <!-- 绘制模式 -->
  232. <RadioButton Content="📐"
  233. Style="{StaticResource ToolButtonStyle}"
  234. ToolTip="绘制ROI"
  235. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Draw}"
  236. Command="{Binding SetRoiModeCommand}"
  237. CommandParameter="{x:Static local:RoiOperationMode.Draw}" />
  238. <!-- 移动模式 -->
  239. <RadioButton Content="↔"
  240. Style="{StaticResource ToolButtonStyle}"
  241. ToolTip="移动ROI"
  242. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Move}"
  243. Command="{Binding SetRoiModeCommand}"
  244. CommandParameter="{x:Static local:RoiOperationMode.Move}" />
  245. <!-- 调整大小模式 -->
  246. <RadioButton Content="⤢"
  247. Style="{StaticResource ToolButtonStyle}"
  248. ToolTip="调整大小"
  249. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Resize}"
  250. Command="{Binding SetRoiModeCommand}"
  251. CommandParameter="{x:Static local:RoiOperationMode.Resize}" />
  252. <!-- 旋转模式 -->
  253. <RadioButton Content="↻"
  254. Style="{StaticResource ToolButtonStyle}"
  255. ToolTip="旋转ROI"
  256. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Rotate}"
  257. Command="{Binding SetRoiModeCommand}"
  258. CommandParameter="{x:Static local:RoiOperationMode.Rotate}" />
  259. <!-- 清除ROI -->
  260. <Button Width="30"
  261. Height="30"
  262. Margin="10,0,0,0"
  263. Padding="0"
  264. ToolTip="清除ROI"
  265. Command="{Binding ClearRoiCommand}">
  266. <materialDesign:PackIcon Kind="RemoveCircle"
  267. Width="26"
  268. Height="26" />
  269. </Button>
  270. </StackPanel>
  271. <!-- ROI信息 -->
  272. <Border Background="#F5F5F5"
  273. CornerRadius="3"
  274. Padding="6"
  275. Margin="0,8,0,0">
  276. <StackPanel>
  277. <TextBlock Text="ROI信息"
  278. FontWeight="SemiBold"
  279. FontSize="11" />
  280. <TextBlock Text="{Binding CurrentRoi}"
  281. FontSize="10"
  282. Foreground="#666"
  283. TextWrapping="Wrap"
  284. Margin="0,2,0,0" />
  285. </StackPanel>
  286. </Border>
  287. </StackPanel>
  288. </Border>
  289. <!-- 参数设置 -->
  290. <Border Grid.Row="1"
  291. Style="{StaticResource CardStyle}"
  292. Margin="0,8,0,0">
  293. <StackPanel>
  294. <TextBlock Text="分析参数"
  295. FontWeight="Bold"
  296. Margin="0,0,0,8" />
  297. <Grid>
  298. <Grid.RowDefinitions>
  299. <RowDefinition Height="Auto" />
  300. <RowDefinition Height="Auto" />
  301. <RowDefinition Height="Auto" />
  302. </Grid.RowDefinitions>
  303. <Grid.ColumnDefinitions>
  304. <ColumnDefinition Width="80" />
  305. <ColumnDefinition Width="*" />
  306. </Grid.ColumnDefinitions>
  307. <TextBlock Grid.Row="0"
  308. Grid.Column="0"
  309. Text="算法:"
  310. VerticalAlignment="Center" />
  311. <ComboBox Grid.Row="0"
  312. Grid.Column="1"
  313. ItemsSource="{Binding FocusMethods}"
  314. SelectedValue="{Binding Parameters.FocusMethod}"
  315. Margin="0,0,0,4" />
  316. <TextBlock Grid.Row="1"
  317. Grid.Column="0"
  318. Text="模式:"
  319. VerticalAlignment="Center" />
  320. <ComboBox Grid.Row="1"
  321. Grid.Column="1"
  322. ItemsSource="{Binding AnalysisModes}"
  323. SelectedValue="{Binding Parameters.AnalysisMode}"
  324. Margin="0,0,0,4" />
  325. <TextBlock Grid.Row="2"
  326. Grid.Column="0"
  327. Text="实时分析:"
  328. VerticalAlignment="Center" />
  329. <CheckBox Grid.Row="2"
  330. Grid.Column="1"
  331. IsChecked="{Binding Parameters.EnableRealtimeAnalysis}"
  332. VerticalAlignment="Center" />
  333. </Grid>
  334. </StackPanel>
  335. </Border>
  336. <!-- 控制按钮 -->
  337. <Border Grid.Row="2"
  338. Style="{StaticResource CardStyle}"
  339. Margin="0,8,0,0">
  340. <StackPanel>
  341. <StackPanel Orientation="Horizontal"
  342. HorizontalAlignment="Center">
  343. <Button Content="开始分析"
  344. Command="{Binding StartAnalysisCommand}"
  345. Padding="20,8"
  346. Margin="0,0,8,0" />
  347. <Button Content="停止分析"
  348. Command="{Binding StopAnalysisCommand}"
  349. Padding="20,8" />
  350. </StackPanel>
  351. <StackPanel Orientation="Horizontal"
  352. HorizontalAlignment="Center"
  353. Margin="0,8,0,0">
  354. <Button Content="重置"
  355. Command="{Binding ResetCommand}"
  356. Padding="15,4"
  357. Margin="0,0,8,0" />
  358. <Button Content="导出报告"
  359. Command="{Binding ExportCommand}"
  360. Padding="15,4" />
  361. </StackPanel>
  362. </StackPanel>
  363. </Border>
  364. <!-- 实时结果 -->
  365. <Border Grid.Row="3"
  366. Style="{StaticResource CardStyle}"
  367. Margin="0,8,0,0">
  368. <StackPanel>
  369. <TextBlock Text="实时结果"
  370. FontWeight="Bold"
  371. Margin="0,0,0,8" />
  372. <Grid>
  373. <Grid.ColumnDefinitions>
  374. <ColumnDefinition Width="*" />
  375. <ColumnDefinition Width="*" />
  376. </Grid.ColumnDefinitions>
  377. <StackPanel Grid.Column="0">
  378. <TextBlock Text="清晰度"
  379. FontSize="11"
  380. Foreground="#666" />
  381. <TextBlock Text="{Binding CurrentResult.Sharpness, StringFormat=F2}"
  382. FontSize="18"
  383. FontWeight="Bold"
  384. Foreground="#007ACC" />
  385. <TextBlock Text="{Binding StatusText}"
  386. FontSize="10"
  387. Foreground="#666"
  388. Margin="0,2,0,0" />
  389. </StackPanel>
  390. <StackPanel Grid.Column="1">
  391. <TextBlock Text="质量评分"
  392. FontSize="11"
  393. Foreground="#666" />
  394. <TextBlock Text="{Binding CurrentResult.QualityScore, StringFormat=F1}"
  395. FontSize="18"
  396. FontWeight="Bold"
  397. Foreground="#4CAF50" />
  398. <TextBlock Text="/100"
  399. FontSize="11"
  400. Foreground="#999" />
  401. </StackPanel>
  402. </Grid>
  403. <ProgressBar Value="{Binding CurrentResult.Sharpness}"
  404. Maximum="50"
  405. Height="6"
  406. Margin="0,8,0,0" />
  407. <!-- 最佳值显示 -->
  408. <Border Background="#F8F9FA"
  409. CornerRadius="3"
  410. Padding="6"
  411. Margin="0,8,0,0">
  412. <StackPanel Orientation="Horizontal">
  413. <TextBlock Text="最佳清晰度:"
  414. FontSize="10"
  415. Foreground="#666" />
  416. <TextBlock Text="{Binding BestSharpnessText}"
  417. FontSize="10"
  418. FontWeight="Bold"
  419. Margin="5,0,0,0" />
  420. <TextBlock Text="{Binding FrameCountText}"
  421. FontSize="10"
  422. Foreground="#666"
  423. Margin="10,0,0,0" />
  424. </StackPanel>
  425. </Border>
  426. </StackPanel>
  427. </Border>
  428. <!-- 图表 -->
  429. <Border Grid.Row="4"
  430. Style="{StaticResource CardStyle}"
  431. Margin="0,8,0,0">
  432. <oxy:PlotView Model="{Binding PlotModel}"
  433. Height="200" />
  434. </Border>
  435. </Grid>
  436. </Grid>
  437. </UserControl>