<Page x:Class="FLY.FilmCasting.AutoDie.UI.Client.PgHeatAnalyse"
      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" 
      
      xmlns:local="clr-namespace:FLY.FilmCasting.AutoDie.UI.Client"
      xmlns:sys="clr-namespace:System;assembly=mscorlib" 
      xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" 

      
      xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
      xmlns:lvc1="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Feng.Wpf"
      mc:Ignorable="d" 
      d:DesignWidth="1024"
      Background="#E6E6E6" >
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Dictionary_MyStyle.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/FLY.Thick.Base.UI;component/Converter/Dictionary_MyConv.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/FLY.FilmCasting.AutoDie.UI.Client;component/Themes/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <sys:Boolean x:Key="False">False</sys:Boolean>
            <local:HeatEffectConverter x:Key="heconv"/>
            <local:PgHeatAnalyseVmUt x:Key="viewModel" IsUsedMap="True"/>
        </ResourceDictionary>

    </Page.Resources>
    <Grid d:DataContext="{StaticResource viewModel}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" Background="{StaticResource Brushes.TitleBar.Background}" >
            <Button Style="{StaticResource Styles.TitleBar.BackButton2}" Command="BrowseBack"/>
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                <TextBlock Style="{StaticResource Styles.TitleBar.Text}"  Text="对位分析"/>
                <TextBlock Style="{StaticResource Styles.TitleBar.Text.Sub}" Text="加热与厚度"/>
            </StackPanel>

        </StackPanel>

        <ScrollViewer CanContentScroll="False" PanningMode="Both" Grid.Row="1"  >
            <StackPanel>
                <local:UcThickHeat x:Name="ucThickHeat0"/>
                <local:UcThickHeat x:Name="ucThickHeat1"/>
                <Border Style="{StaticResource Styles.Card.Border}" >
                    <StackPanel>

                        <Grid Margin="48,0,0,-20" Panel.ZIndex="10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Visibility="{Binding IsError,Converter={StaticResource visbilityconv}, ConverterParameter=HiddenWhenTrue}">
                                    <StackPanel Orientation="Horizontal" Background="{StaticResource Badges.Background}" Margin="{StaticResource Badges.Margin}">
                                        <TextBlock Style="{StaticResource Text.FieldHeader2}" Text="相关性:" />
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Style="{StaticResource Text.FieldContent2}" Text="{Binding CurrHeatThickR, StringFormat={}{0:F2}}" />
                                        </StackPanel>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Background="{StaticResource Badges.Background}" Margin="{StaticResource Badges.Margin}">
                                        <TextBlock Style="{StaticResource Text.FieldHeader2}" Text="加热极差:" />
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Style="{StaticResource Text.FieldContent2}" Text="{Binding CurrMaxMin, StringFormat={}{0:F1}}" />
                                            <TextBlock Style="{StaticResource Text.FieldContentMm2}" Text="%" />
                                        </StackPanel>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Background="{StaticResource Badges.Background}" Margin="{StaticResource Badges.Margin}">
                                        <TextBlock Style="{StaticResource Text.FieldHeader2}" Text="比例:" />
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Style="{StaticResource Text.FieldContent2}" Text="{Binding CurrKp, StringFormat={}{0:F1}}" />
                                            <TextBlock Style="{StaticResource Text.FieldContentMm2}" Text="加热/厚度" FontSize="15"/>
                                        </StackPanel>
                                    </StackPanel>
                                </StackPanel>
                                <TextBlock Style="{StaticResource Text.FieldContent2}" 
                                           FontSize="20"
                                           Foreground="Red"
                                           Text="数据异常,无法比较" 
                                           Visibility="{Binding IsError,Converter={StaticResource visbilityconv}}"/>
                            </Grid>
                            
                            <TextBlock Grid.Column="1" Style="{StaticResource Styles.Card.Title}" Text="偏差" />
                        </Grid>
                        <lvc:CartesianChart Height="300" Margin="5,2,2,2" 
                                    DisableAnimations="True" Hoverable="False" DataTooltip="{x:Null}"  >
                            <lvc:CartesianChart.Series>
                                <!--<lvc1:Column2Series 
                                PointGeometry="{x:Null}"
                                StrokeThickness ="1"
                                Stroke="Black"
                                Fill="{StaticResource Brushes.PreHeat}"
                                Values="{Binding HeatDiffs}"
                                Configuration="{Binding MapperHeats}"/>-->
                                
                                    <lvc1:Column2Series 
                                    PointGeometry="{x:Null}"
                                    StrokeThickness ="1"
                                    Stroke="Black"
                                    Fill="{StaticResource Brushes.PreHeat}"
                                    Values="{Binding HeatDiffEffects}"
                                    Configuration="{Binding MapperHeats}"/>
                                    <!--<lvc:LineSeries 
                                    PointGeometry="{x:Null}"
                                    StrokeThickness ="3"
                                    Stroke="{StaticResource Brushes.Heat}"
                                    Fill="Transparent"
                                    Values="{Binding HeatDiffEffects}"
                                    Configuration="{Binding MapperHeats}"/>-->
                                
                                <lvc:LineSeries 
                                    PointGeometry="{x:Null}"
                                    StrokeThickness ="3"
                                    Stroke="{StaticResource Brushes.Thick}"
                                    Fill="Transparent"
                                    Values="{Binding ThickPercentDiffs}"
                                    Configuration="{Binding MapperThickPercents}"/>
                                
                            </lvc:CartesianChart.Series>
                            <lvc:CartesianChart.AxisX>
                                <lvc:Axis Foreground="{StaticResource Brushes.AxisLabel}"
                                      MinValue="0" MaxValue="{Binding XMax}">
                                    <lvc:Axis.Separator>
                                        <lvc:Separator Stroke="{StaticResource Brushes.AxisSeparator}" Step="5"/>
                                    </lvc:Axis.Separator>
                                    <lvc:Axis.Sections>
                                        <lvc:AxisSection Style="{StaticResource AxisSectionStyle}" StrokeThickness="0" Stroke="{StaticResource Color_theme_activity}"
                                Value="{Binding OrgBoltNo}" 
                            />
                                    </lvc:Axis.Sections>
                                </lvc:Axis>
                            </lvc:CartesianChart.AxisX>
                            <lvc:CartesianChart.AxisY>
                                <lvc:Axis Foreground="{StaticResource Brushes.AxisLabel}"
                                LabelFormatter="{Binding YFormatter}" FontFamily="Courier New" 
                                      MinValue="-100" MaxValue="100">
                                    <lvc:Axis.Separator>
                                        <lvc:Separator Stroke="{StaticResource Brushes.AxisSeparator}" Step="10"/>
                                    </lvc:Axis.Separator>
                                </lvc:Axis>
                            </lvc:CartesianChart.AxisY>
                        </lvc:CartesianChart>

                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="1" Margin="5,0,5,-20" Style="{StaticResource Styles.Button.Apply}"
                                    Command="{Binding ApplyCmd}"/>

                            <WrapPanel 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 HeatEffectCurve,Converter={StaticResource heconv}}"/>
                                    </StackPanel>
                                </StackPanel>
                                <StackPanel Margin="{StaticResource ControlMargin}" x:Name="stackpanel_isUsedBoltMap">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="使用分区表" />
                                    <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" HorizontalAlignment="Left" IsChecked="{Binding IsUsedMap}"/>
                                </StackPanel>
                                <WrapPanel Orientation="Horizontal">
                                    <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 Kp, StringFormat={}{0:F1}}"/>
                                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="输出/厚度" />
                                            </StackPanel>
                                        </StackPanel>
                                        <Button Style="{StaticResource Styles.Button.Icon.Rectangle}" Command="{Binding KpCollapseCmd}" >
                                            <iconPacks:PackIconMaterial Kind="ArrowCollapseVertical" />
                                        </Button>
                                        <Button Style="{StaticResource Styles.Button.Icon.Rectangle}" Command="{Binding KpExpandCmd}" >
                                            <iconPacks:PackIconMaterial Kind="ArrowExpandVertical" />
                                        </Button>
                                    </StackPanel>
                                </WrapPanel>
                            </WrapPanel>
                        </Grid>




                    </StackPanel>

                </Border>
                <Border Style="{StaticResource Styles.Card.Border}" Visibility="{Binding IsUsedMap,Converter={StaticResource visbilityconv}}">
                    <StackPanel>
                        <TextBlock Grid.Column="1" Style="{StaticResource Styles.Card.Title}" Text="分区表"/>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">

                                <Button Style="{StaticResource Styles.Button.Icon}" Margin="{StaticResource ControlMargin}" 
                                        Command="{Binding TestMapCmd}" >
                                    <StackPanel>
                                        <iconPacks:PackIconMaterial Kind="PlayCircle" />
                                        <TextBlock Text="测试" HorizontalAlignment="Center" />
                                    </StackPanel>
                                </Button>
                                <Button Style="{StaticResource Styles.Button.Icon}" Margin="{StaticResource ControlMargin}" 
                                        Command="{Binding DelMapCmd}" >
                                    <StackPanel>
                                        <iconPacks:PackIconMaterial Kind="DeleteCircle" />
                                        <TextBlock Text="删除" HorizontalAlignment="Center" />
                                    </StackPanel>
                                </Button>
                            </StackPanel>

                            <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding BoltMap}" MinWidth="204" MinHeight="100" TextBlock.FontSize="18" TextBlock.FontWeight="Normal">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Header="原始No" Binding="{Binding OldNo}" Width="100"/>
                                    <DataGridTextColumn Header="新No" Binding="{Binding NewNo}" Width="100"/>
                                </DataGrid.Columns>
                            </DataGrid>
                        </StackPanel>
                    </StackPanel>

                </Border>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>