<Page x:Class="FLY.Thick.Base.UI.PgFlyAd"
      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.Thick.Base.UI"  
      xmlns:common="clr-namespace:FLY.Thick.Base.Common;assembly=FLY.Thick.Base"
      mc:Ignorable="d" 
      d:DesignHeight="1200" d:DesignWidth="1024"
      Background="WhiteSmoke"
      d:DataContext="{d:DesignInstance local:PgFlyAdVm}"
	>
    <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.MergedDictionaries>
            <Style TargetType="TextBlock" BasedOn="{StaticResource Styles.Text.FieldContent.Unit}" x:Key="Styles.Text.FieldContent.Error">
                <Setter Property="Foreground" Value="{StaticResource Brushes.Validation}"/>
            </Style>
        </ResourceDictionary>
    </Page.Resources>
    <Grid >
        <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="AD盒"/>
            </StackPanel>
            <local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/>
        </Grid>
        <ScrollViewer PanningMode="Both" Grid.Row="1" >
            <StackPanel Margin="{StaticResource ControlMargin}">
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="AD盒参数"/>
                        <StackPanel >
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="IP地址:端口" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding EP, Converter={StaticResource ipepconv}}" Tag="Full"  />
                                </StackPanel>
                            </StackPanel>
                            <WrapPanel Orientation="Horizontal">
                                <StackPanel Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="CRC" />
                                    <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" IsChecked="{Binding HasCRC}"/>
                                </StackPanel>
                                <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 PosOfGrid}" />
                                    </StackPanel>
                                    
                                </StackPanel>
                                <StackPanel Margin="{StaticResource ControlMargin}" >
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="数据平滑" />
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding GridSmooth}" />
                                </StackPanel>
                                <StackPanel Margin="{StaticResource ControlMargin}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="电机类型" />
                                    </StackPanel>

                                    <ComboBox Width="120" HorizontalAlignment="Left" MinHeight="{StaticResource FontSize.FieldContent}">
                                        <ComboBoxItem IsSelected="{Binding MotorType, Converter={StaticResource e2bconv}, ConverterParameter={x:Static common:MOTORTYPE.SERVO}}">
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent}"  FontSize="{StaticResource FontSize.FieldContent.Middle}" Text="伺服"/>
                                        </ComboBoxItem>
                                        <ComboBoxItem IsSelected="{Binding MotorType, Converter={StaticResource e2bconv}, ConverterParameter={x:Static common:MOTORTYPE.VF0}}" >
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent}"  FontSize="{StaticResource FontSize.FieldContent.Middle}" Text="变频器"/>
                                        </ComboBoxItem>
                                        <ComboBoxItem IsSelected="{Binding MotorType, Converter={StaticResource e2bconv}, ConverterParameter={x:Static common:MOTORTYPE.NULL}}" >
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent}"  FontSize="{StaticResource FontSize.FieldContent.Middle}" Text="无"/>
                                        </ComboBoxItem>
                                    </ComboBox>
                                </StackPanel>
                                <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 Ratio01}" />
                                    </StackPanel>
                                    
                                </StackPanel>
                                <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 Ratio02}" />
                                    </StackPanel>
                                    
                                </StackPanel>
                                <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 PosOffset}" />
                                    </StackPanel>
                                    
                                </StackPanel>
                                <StackPanel Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="独立位置范围" />
                                    <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" IsChecked="{Binding HasPosMaxMin}" HorizontalAlignment="Left"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Visibility="{Binding HasPosMaxMin,Converter={StaticResource visbilityconv},ConverterParameter=Collapsed}">
                                    <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 PosMin}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="脉冲"/>
                                        </StackPanel>
                                    </StackPanel>
                                    <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 PosMax}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="脉冲"/>
                                        </StackPanel>
                                    </StackPanel>
                                </StackPanel>

                                <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 JogVelocity}" />
                                    </StackPanel>
                                </StackPanel>
                                <StackPanel  Margin="{StaticResource ControlMargin}" >
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="AD延时" />
                                    <StackPanel Orientation="Horizontal">
                                        <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding ADLag}" HorizontalAlignment="Left"/>
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="ms"/>
                                    </StackPanel>
                                </StackPanel>
                                <StackPanel  Margin="{StaticResource ControlMargin}" >
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="AD盒版本" />
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="v"/>
                                        <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding HardwareVersion}" />
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}"/>
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}">
                                            通讯版本:v<Run Text="{Binding Version}"/>
                                        </TextBlock>
                                    </StackPanel>
                                </StackPanel>
                            </WrapPanel>
                            <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
                                <Button Style="{StaticResource Styles.Button.Square.Accent2}" Content="应用" Command="{Binding ApplyCmd}"/>
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="系统参数"/>
                        <StackPanel >
                            <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 PosLength}" />
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}"/>
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                            <Run>
                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                    <Binding Path="PosLength" />
                                    <Binding Path="Encoder1_mmpp"/>
                                </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                        </TextBlock>
                                    </StackPanel>

                                </StackPanel>
                                <StackPanel  Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="编码器1比例" />
                                    <StackPanel Orientation="Horizontal">
                                        <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding Encoder1_mmpp}" HorizontalAlignment="Left"/>
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="mm/脉冲"/>
                                    </StackPanel>

                                </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 VJOG}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                <Run>
                                    <MultiBinding Converter="{StaticResource outsp2mpminconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                            <Binding Path="VJOG" />
                                            <Binding Path="Encoder1_mmpp" />
                                            <Binding Path="Speed1Scale" />
                                        </MultiBinding>
                                </Run>
                                <Run Text="m/min" />
                                            </TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                </StackPanel>


                                <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 SVelocity}" />
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                <Run >
                                    <MultiBinding Converter="{StaticResource outsp2mpminconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                            <Binding Path="SVelocity" />
                                            <Binding Path="Encoder1_mmpp" />
                                            <Binding Path="Speed1Scale" />
                                        </MultiBinding>
                                </Run>
                                <Run Text="m/min" />
                                        </TextBlock>
                                    </StackPanel>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel  Margin="{StaticResource ControlMargin}">
                                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="归零速度1" />
                                        <StackPanel Orientation="Horizontal">
                                            <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding HVelocity1}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                <Run >
                                                                            <MultiBinding Converter="{StaticResource outsp2mpminconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                            <Binding Path="HVelocity1" />
                                            <Binding Path="Encoder1_mmpp" />
                                            <Binding Path="Speed1Scale" />
                                        </MultiBinding>
                                </Run>
                                <Run Text="m/min" />
                                            </TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                    <StackPanel  Margin="{StaticResource ControlMargin}">
                                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="归零速度2" />
                                        <StackPanel Orientation="Horizontal">
                                            <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding HVelocity2}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                <Run >
                                    <MultiBinding Converter="{StaticResource outsp2mpminconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                            <Binding Path="HVelocity2" />
                                            <Binding Path="Encoder1_mmpp" />
                                            <Binding Path="Speed1Scale" />
                                        </MultiBinding>
                                </Run>
                                <Run Text="m/min" />
                                            </TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                </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 ATime}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                <Run Text="ms" />
                                            </TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                    <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 DTime}" />
                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                <Run Text="ms" />
                                            </TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                </StackPanel>

                            </WrapPanel>
                            <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
                                <Button Style="{StaticResource Styles.Button.Square.Accent2}" Content="应用" Command="{Binding Apply2Cmd}"/>
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="动作"/>
                        <StackPanel Orientation="Horizontal">
                            <Button Style="{StaticResource Styles.Button.Square2}" Content="反行" Command="{Binding BackwCmd}"/>
                            <Button Style="{StaticResource Styles.Button.Square2}" Content="正行" Command="{Binding ForwCmd}" />
                            <Button Style="{StaticResource Styles.Button.Square2}" Content="归零" Command="{Binding OrgCmd}" />
                            <Button Style="{StaticResource Styles.Button.Square.Accent2}" Background="{StaticResource Brushes.Validation}" Content="停止" Command="{Binding StopCmd}" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Button Style="{StaticResource Styles.Button.Square.Accent2}" Content="运行至" Command="{Binding RunToCmd}"/>
                            <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 TargetPos}" HorizontalAlignment="Left"/>
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="脉冲"/>
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </Border>

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