<UserControl x:Class="MainShell.DeviceMaintance.View.NeedleCaliView"
             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:MainShell.DeviceMaintance.View"
             xmlns:mwControls="http://www.maxwell-gp.com/"
             xmlns:Att="clr-namespace:MainShell.Common.ControlAttribute"
             xmlns:customControl="clr-namespace:MainShell.Resources.CustomControl"
             mc:Ignorable="d" 
             d:DesignHeight="850" d:DesignWidth="800">
    <UserControl.Resources>
        <Style TargetType="GroupBox" BasedOn="{StaticResource GroupStepControl}"/>
        <Style TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
            <Setter Property="HorizontalContentAlignment" Value="Right"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalAlignment" Value="Right"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Height" Value="35"/>
            <Setter Property="Width" Value="80"/>
        </Style>
        <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="Margin" Value="3"/>
            <Setter Property="Height" Value="35"/>
            <Setter Property="Width" Value="90"/>
        </Style>
    </UserControl.Resources>
    <Grid mwControls:ParameterAttach.DelayAcceptValue="{Binding ParameterHelper}">
        <ScrollViewer VerticalScrollBarVisibility="Visible" Margin="5" ClipToBounds="True">
            <StackPanel>
                <GroupBox Header="【第一步】对刀仪偏差设置" IsEnabled="{Binding UiEnable}">
                    <StackPanel Margin="5" HorizontalAlignment="Center" Orientation="Horizontal">
                        <Label Content="对刀时偏差：" />
                        <mwControls:NumberBox Value="{Binding NeedleZCalibrationItem.KnifeOffset}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="-1000" Maximum="1000" HorizontalAlignment="Left" Margin="2" Width="80" Height="35" />
                    </StackPanel>
                </GroupBox>
                <GroupBox Header="【第二步】SZ / StagePlatform设置" IsEnabled="{Binding UiEnable}">
                    <customControl:AxisMoveControl LableContent1="SZ(mm)："
                                 Value1="{Binding NeedleZCalibrationItem.CZHeight}"
                                 LableContent2="StagePlatform高度："
                                 Value2="{Binding NeedleZCalibrationItem.StageHeight}"
                                 IsAllShow="{Binding HasStagePlatform}"
                                 MoveCommand="{mwControls:Action MoveCzCurrentLocation}"/>
                </GroupBox>
                <GroupBox Header="【第三步】龙门2的避让位置" IsEnabled="{Binding UiEnable}">
                    <customControl:AxisMoveControl LableContent1="X2(mm)："
                             Value1="{Binding NeedleZCalibrationItem.Gantry2AvoidPositionX}"
                             LableContent2="Y2(mm)："
                             Value2="{Binding NeedleZCalibrationItem.Gantry2AvoidPositionY}"
                             ReadCommand="{mwControls:Action ReadGantry2CurrentLocation}"
                             MoveCommand="{mwControls:Action MoveGantry2ToCurrentLocation}"/>
                </GroupBox>
                <GroupBox Header="【第四步】针尖对准对刀仪位置" IsEnabled="{Binding UiEnable}">
                    <customControl:AxisMoveControl LableContent1="X1(mm)："
                          Value1="{Binding NeedleZCalibrationItem.SupportPinPositionX}"
                          LableContent2="Y1(mm)："
                          Value2="{Binding NeedleZCalibrationItem.SupportPinPositionY}"
                          ReadCommand="{mwControls:Action ReadSupportPinCurrentLocation}"
                          MoveCommand="{mwControls:Action MoveSupportPinToCurrentLocation}"/>
                </GroupBox>
                <GroupBox Header="【第五步】Z1设置" IsEnabled="{Binding UiEnable}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <UniformGrid Columns="4" Rows="1">
                            <Label Content="开始位置(mm)" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" />
                            <mwControls:NumberBox Value="{Binding NeedleZCalibrationItem.Z1StartPosition}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="-1000" Maximum="1000" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Margin="2" Width="80" Height="35" />
                            <Label Content="速度(mm/s)" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right" />
                            <mwControls:NumberBox Value="{Binding NeedleZCalibrationItem.Z1Speed}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="-1000" Maximum="1000" Grid.Row="0" Grid.Column="3" HorizontalAlignment="Left" Margin="2" Width="80" Height="35" />
                        </UniformGrid>
                        <UniformGrid Columns="2" Rows="1" Grid.Column="1">
                            <Label Content="下降距离(mm)" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" />
                            <mwControls:NumberBox Value="{Binding NeedleZCalibrationItem.Z1DropMaxPosition}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="-1000" Maximum="1000" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="2" Width="80" Height="35" />
                        </UniformGrid>
                    </Grid>
                </GroupBox>
                <GroupBox Header="【第六步】刺针触碰到对刀仪" IsEnabled="{Binding UiEnable}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Label Visibility="Visible" Content="基准值(mm)：" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" />
                        <mwControls:NumberBox Visibility="Visible" IsReadOnly="True" Value="{Binding NeedleZCalibrationItem.NeedleTouchHeightBase}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="-1000" Maximum="1000" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Margin="5" Width="80" Height="35" />

                        <Label Content="Z1平均高度(mm)：" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" />
                        <mwControls:NumberBox IsReadOnly="True" Value="{Binding NeedleZCalibrationItem.NeedleTouchHeightAve}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="-1000" Maximum="1000" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="5" Width="80" Height="35" />

                        <Label Content="对刀次数：" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" />
                        <mwControls:NumberBox Value="{Binding NeedleZCalibrationItem.NeedleTouchCount}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="1" Maximum="100" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Margin="5" Width="80" Height="35" />

                        <Label Content="当前使用对刀高度(mm)：" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" Width="140"/>
                        <mwControls:NumberBox IsEnabled="False" Grid.Row="3" Value="{Binding NeedleZCalibrationItem.CurrentNeedleTouchHeight}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="-1000" Maximum="1000" Grid.Column="1" HorizontalAlignment="Left" Margin="5" Width="80" Height="35" />

                        <Label Content="对刀与基准偏差(mm)：" Grid.Row="4" Grid.Column="0" HorizontalAlignment="Right" />
                        <mwControls:NumberBox IsReadOnly="True" Grid.Row="4" Value="{Binding NeedleZCalibrationItem.NeedleTouchOffset}" mwControls:NumericKeypadAttach.IsEnabled="True" Minimum="-1000" Maximum="1000" Grid.Column="1" HorizontalAlignment="Left" Margin="5" Width="80" Height="35" />

                        <Grid Grid.Column="2" Grid.ColumnSpan="2" Grid.RowSpan="5">
                            <ListView ItemsSource="{Binding NeedleZCalibrationItem.NeedleTouchRecords}" SelectedItem="{Binding SelectedRecord}">
                                <ListView.View>
                                    <GridView>
                                        <GridViewColumn Header="当前次数" DisplayMemberBinding="{Binding CurrentCount}" Width="100"/>
                                        <GridViewColumn Header="Z1高度(mm)" DisplayMemberBinding="{Binding Height}" Width="210"/>
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </Grid>
                    </Grid>
                </GroupBox>
                <GroupBox Header="【第七步】对刀控制" IsEnabled="{Binding IsEnabledNeedleCalibrationControl}">
                    <StackPanel>
                        <StackPanel Margin="4" IsEnabled="{Binding UiEnable}" Orientation="Horizontal" HorizontalAlignment="Left">
                            <CheckBox Content="自动抬高" Margin="6,0" IsChecked="{Binding AutoRaiseZ1}"/>
                            <Button Visibility="Collapsed" Content="设置当前基准值" Tag="设置当前基准值" Click="{mwControls:Action SetBaseHeight}" Margin="6,0" />
                            <Button Content="Z1对刀" Tag="Z1对刀" Margin="6,0" Click="{mwControls:Action StartSingleZ1CalibrationAsync}"/>
                            <Button Content="使用当前对刀高度" Width="120" Tag="使用当前对刀高度" Click="{mwControls:Action UseCurrentZ1Height}" Margin="6,0" />
                        </StackPanel>
                        <StackPanel Margin="4" Orientation="Horizontal">
                            <Button Content="开始" Tag="开始" Click="{mwControls:Action StartCalibrationAsync}" Margin="6,0" IsEnabled="{Binding UiEnable}"/>
                            <Button Content="停止" Tag="停止" Click="{mwControls:Action StopCalibrationAsync}" Margin="6,0" IsEnabled="{Binding UiEnable, Converter={StaticResource boolToInversionConverter}}"/>
                            <Button Content="保存" Tag="保存" Click="{mwControls:Action SaveCalibration}" Margin="6,0" IsEnabled="{Binding UiEnable}"/>
                        </StackPanel>
                    </StackPanel>
                </GroupBox>

            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>
