<Page x:Class="FLY.Thick.Base.UI.PgScanCorr"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      xmlns:local ="clr-namespace:FLY.Thick.Base.UI"
      xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
      xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
      d:DesignHeight="1500" d:DesignWidth="1280"
      Background="WhiteSmoke"
	Title="Page_ScanCorr">
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/FLY.Thick.Base.UI;component/Themes/Styles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/FLY.Thick.Base.UI;component/Converter/Dictionary_MyConv.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:PgScanCorrVmUt x:Key="viewModel" Enable="True"/>
        </ResourceDictionary>
    </Page.Resources>
    <Grid Background="{StaticResource Brushes.Card.Background}" d:DataContext="{StaticResource viewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Background="{StaticResource Brushes.TitleBar.Background}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal" >
                <Button Style="{StaticResource Styles.TitleBar.BackButton2}" Command="BrowseBack"/>
                <TextBlock Style="{StaticResource Styles.TitleBar.Text}" Text="机架修正"/>
            </StackPanel>
            <local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/>
        </Grid>
        <ScrollViewer Grid.Row="1"
                      CanContentScroll="False" PanningMode="Both" >
            <StackPanel Margin="{StaticResource ControlMargin}">
                <Border Style="{StaticResource Styles.Card.Border}" >
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="状态"/>
                        <StackPanel Orientation="Horizontal">
                            <StackPanel>
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="使能"/>
                                <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" IsChecked="{Binding Enable}"/>
                            </StackPanel>
                        </StackPanel>
                        
                        
                        <StackPanel Orientation="Horizontal">
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock >
                                    <TextBlock.Style>
                                        <Style TargetType="TextBlock" BasedOn="{StaticResource Styles.Text.FieldHeader}">
                                            <Setter Property="Text" Value="数据完整"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsDataOK}" Value="false">
                                                    <Setter Property="Text" Value="数据与系统参数不一致,需要重新录制"/>
                                                    <Setter Property="Foreground" Value="{StaticResource Brushes.Validation}"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                            </StackPanel>
                        </StackPanel>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <Button  Content="开始录制" 
                                        Command="{Binding StartCmd}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square.Accent2}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsRunning}" Value="True">
                                                    <Setter Property="IsEnabled" Value="False"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                </Button>
                                <Button Content="停止" Background="{StaticResource Brushes.Validation}" 
                                        Command="{Binding StopCmd}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square.Accent2}">
                                            <Setter Property="IsEnabled" Value="False"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsRunning}" Value="True">
                                                    <Setter Property="IsEnabled" Value="True"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                </Button>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                        组<Run Text="{Binding CurrGroupIndex}"/>
                                    </TextBlock>
                                    <Grid Width="100"/>
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent}" 
                                                           Text="{Binding Progress}"/>
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" 
                                                           Text="%"/>
                                </StackPanel>

                            </StackPanel>

                        </Grid>

                    </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}" >
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="扫描图"/>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <Button  Content="组0" 
                                        Command="{Binding SelectedGroup0Cmd}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square2}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding SelectedGroupIndex}" Value="0">
                                                    <Setter Property="Background" Value="{StaticResource Brushes.Activity}"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                </Button>
                                <Button  Content="组1" 
                                        Command="{Binding SelectedGroup1Cmd}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square2}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding SelectedGroupIndex}" Value="1">
                                                    <Setter Property="Background" Value="{StaticResource Brushes.Activity}"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                </Button>
                            </StackPanel>

                            <StackPanel Orientation="Horizontal" Grid.Column="1">
                                <Button  Content="删除" Style="{StaticResource Styles.Button.Square2}"
                                        Command="{Binding ClearCmd}"/>

                            </StackPanel>
                        </Grid>
                        

                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="平均:"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent}" 
                                                           Text="{Binding AvgAd}"/>
                            </StackPanel>
                            <ItemsControl Grid.Column="1" ItemsSource="{Binding SeriesInfos}" Margin="{StaticResource ControlMargin}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <WrapPanel Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border x:Name="bd" Background="{Binding Color}" BorderBrush="LightGray" BorderThickness="2" Margin="2" Padding="10,5" >
                                            <TextBlock x:Name="tb" Text="{Binding Name}" FontSize="15" Foreground="WhiteSmoke" FontWeight="Bold"  VerticalAlignment="Center" HorizontalAlignment="Center"  />
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Grid>
                        
                        
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="2" Margin="{StaticResource ControlMargin}">
                                <lvc:CartesianChart x:Name="chart1"  Height="350" 
                                            DisableAnimations="True" Hoverable="False" DataTooltip="{x:Null}"
                                            MouseMove="UIElement_OnMouseMove" MouseDown="UIElement_MouseDown" MouseUp="UIElement_MouseUp"
                                            Series="{Binding Series}"
                                                    
                                            >
                                    <lvc:CartesianChart.AxisX>
                                        <lvc:Axis LabelFormatter="{Binding XFormatter}" 
                                                  Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
                                                  MaxValue="{Binding XMax}" MinValue="{Binding XMin}" >
                                            <lvc:Axis.Separator>
                                                <lvc:Separator Stroke="LightGray"/>
                                            </lvc:Axis.Separator>
                                        </lvc:Axis>
                                    </lvc:CartesianChart.AxisX>
                                    <lvc:CartesianChart.AxisY>
                                        <lvc:Axis Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
                                                  LabelFormatter="{Binding YFormatter}" 
                                                  MaxValue="{Binding YMax}" MinValue="{Binding YMin}">
                                            <lvc:Axis.Separator>
                                                <lvc:Separator Stroke="LightGray"/>
                                            </lvc:Axis.Separator>
                                        </lvc:Axis>
                                    </lvc:CartesianChart.AxisY>
                                </lvc:CartesianChart>

                            </Grid>
                            <Controls:RangeSlider Grid.Row="2" Grid.Column="1"
                                                  Margin="{StaticResource ControlMargin}"
                                                  Controls:SliderHelper.ChangeValueBy="LargeChange"
                                                  Controls:SliderHelper.EnableMouseWheel="MouseHover"
                                                  AutoToolTipPlacement="TopLeft"
                                                  Orientation="Vertical"
                                                  LargeChange="10"
                                                  SmallChange="1"
                                                  Maximum="{Binding YRangeSliderMax}"
                                                  Minimum="{Binding YRangeSliderMin}"
                                                  
                                                  LowerValue="{Binding YMin}"
                                                  UpperValue="{Binding YMax}" />

                        </Grid>
                    </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}" >
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="修改"/>
                        <TabControl 
                                    Margin="{StaticResource ControlMargin}"
                            MinHeight="150"
                            Controls:TabControlHelper.Underlined="TabPanel"
                            Controls:TabControlHelper.UnderlinePlacement="Bottom"
                            Controls:HeaderedControlHelper.HeaderFontSize="18">
                            <TabItem Header="平滑滤波方式">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <StackPanel>

                                        <StackPanel Orientation="Horizontal">
                                            <StackPanel Margin="{StaticResource ControlMargin}">
                                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="平滑" />
                                                <StackPanel Orientation="Horizontal" >
                                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}"
                                                        Text="{Binding SmoothFactor}" />
                                                </StackPanel>
                                            </StackPanel>
                                            <StackPanel Orientation="Horizontal">
                                                <Button Content="生成" Command="{Binding CreateCorrBySmoothCmd}" >
                                                    <Button.Style>
                                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square.Accent2}">

                                                        </Style>
                                                    </Button.Style>
                                                </Button>
                                            </StackPanel>
                                        </StackPanel>
                                    </StackPanel>

                                    
                                </Grid>
                            </TabItem>
                            <TabItem Header="关键点方式">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <StackPanel>

                                        <StackPanel Orientation="Horizontal">
                                            <StackPanel Orientation="Horizontal">
                                                <Button Content="添加" Command="{Binding AddKeyPointModeCmd}" >
                                                    <Button.Style>
                                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square2}">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding KpSelectMode}" Value="{x:Static local:KeyPointsSelectMode.Add}" >
                                                                    <Setter Property="IsEnabled" Value="False"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Button.Style>
                                                </Button>
                                                <Button Content="删除" Command="{Binding RemoveKeyPointModeCmd}" >
                                                    <Button.Style>
                                                        <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Square2}">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding KpSelectMode}" Value="{x:Static local:KeyPointsSelectMode.Remove}" >
                                                                    <Setter Property="IsEnabled" Value="False"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Button.Style>
                                                </Button>
                                                <Button Style="{StaticResource Styles.Button.Square.Accent2}" 
                                                        Content="生成" Command="{Binding CreateCorrByKeyPointCmd}" />

                                            </StackPanel>
                                        </StackPanel>
                                    </StackPanel>
                                </Grid>
                            </TabItem>
                        </TabControl>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <Button Content="应用" Style="{StaticResource Styles.Button.Square.Accent2}" Command="{Binding SetCorrDataCmd}"/>
                            </StackPanel>
                            
                            <StackPanel Grid.Column="1"
                                        Orientation="Horizontal">
                                <Button Style="{StaticResource Styles.Button.Square2}" Content="导出" 
                                        Command="{Binding SaveXlsxCmd}"/>
                                <Button Style="{StaticResource Styles.Button.Square2}" Content="导入" 
                                        Command="{Binding LoadXlsxCmd}"/>
                            </StackPanel>
                        </Grid>
                        
                    </StackPanel>
                </Border>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>
