This commit is contained in:
2024-09-25 15:44:59 +08:00
parent a76546ebe6
commit 6bf0d5d7ba
72 changed files with 21606 additions and 1608 deletions

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace CapMachine.Shared.Controls
{
public class BoolNgConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool booleanValue)
{
return !booleanValue;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool booleanValue)
{
return !booleanValue;
}
return value;
}
}
}

View File

@@ -8,10 +8,12 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="MeterConfigInstance"
d:DesignHeight="330"
d:DesignWidth="360"
d:DesignHeight="400"
d:DesignWidth="300"
mc:Ignorable="d">
<UserControl.Resources>
<local:BoolNgConvert x:Key="BoolNgConverter" />
<local:SecToStrConvert x:Key="SecToStrConverter" />
<Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="FontSize" Value="24" />
<Setter Property="Width" Value="218" />
@@ -23,134 +25,297 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="70" />
<RowDefinition Height="40" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.ColumnSpan="3" Margin="1">
<Border
Padding="3"
Background="LightSteelBlue"
CornerRadius="3">
<DockPanel Background="White">
<!--<StackPanel DockPanel.Dock="Left" Orientation="Horizontal">
<TextBlock
FontSize="18"
Foreground="Blue"
Text="{Binding ElementName=MeterConfigInstance, Path=MeterName}" />
</Border>
Margin="15,0,5,0"
VerticalAlignment="Center"
Text="常值/斜率:" />
<ToggleButton
x:Name="TBSwitchConstSlop"
Command="{Binding ElementName=MeterConfigInstance, Path=SwitchConstSlopCommand}"
CommandParameter="{Binding ElementName=TBSwitchConstSlop, Path=IsChecked}"
IsChecked="{Binding ElementName=MeterConfigInstance, Path=SwitchConstSlopPar}"
Style="{StaticResource MaterialDesignSwitchToggleButton}"
ToolTip="常值和斜率选项" />
-->
<!-- IsChecked="{Binding ElementName=MeterConfigInstance, Path=SwitchConstSlopPar}" -->
<!--
</StackPanel>-->
</StackPanel>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Margin="5,10,0,0">
<TextBox
Height="55"
VerticalAlignment="Top"
materialDesign:HintAssist.Hint="起始速度"
AcceptsReturn="True"
FontSize="18"
Style="{StaticResource MaterialDesignOutlinedTextBox}"
Text="{Binding ElementName=MeterConfigInstance, Path=SelectedMeter.StartValue}"
TextWrapping="NoWrap"
VerticalScrollBarVisibility="Disabled" />
</StackPanel>
<StackPanel Grid.Column="1" Margin="5,10,0,0">
<TextBox
Height="55"
VerticalAlignment="Top"
materialDesign:HintAssist.Hint="结束速度"
AcceptsReturn="True"
FontSize="18"
Style="{StaticResource MaterialDesignOutlinedTextBox}"
Text="{Binding ElementName=MeterConfigInstance, Path=SelectedMeter.EndValue}"
TextWrapping="NoWrap"
VerticalScrollBarVisibility="Disabled" />
</StackPanel>
<StackPanel Grid.Column="2" Margin="5,10,0,0">
<TextBox
Height="55"
VerticalAlignment="Top"
materialDesign:HintAssist.Hint="维持时间"
AcceptsReturn="True"
FontSize="18"
Style="{StaticResource MaterialDesignOutlinedTextBox}"
Text="{Binding ElementName=MeterConfigInstance, Path=SelectedMeter.KeepTime}"
TextWrapping="NoWrap"
VerticalScrollBarVisibility="Disabled" />
</StackPanel>
</Grid>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<Button
Margin="5,3"
Background="IndianRed"
Command="{Binding ElementName=MeterConfigInstance, Path=AddCommand}"
Content="增加"
Foreground="White"
Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
ToolTip="增加程序步骤内的速度设置" />
<Button
Margin="5,3"
Background="IndianRed"
Command="{Binding ElementName=MeterConfigInstance, Path=EditCommand}"
Content="修改"
Foreground="White"
Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
ToolTip="修改程序步骤内的速度设置,请先选中" />
<Button
Margin="5,3"
Background="IndianRed"
Command="{Binding ElementName=MeterConfigInstance, Path=DeleteCommand}"
Content="删除"
Foreground="White"
Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
ToolTip="删除程序步骤内的速度设置,请先选中" />
</StackPanel>
<Border
Grid.Row="3"
Margin="3,0"
BorderBrush="Black"
BorderThickness="1">
<ListView
x:Name="listviewMeter"
Foreground="Black"
ItemsSource="{Binding ElementName=MeterConfigInstance, Path=ListMeter}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ElementName=MeterConfigInstance, Path=MeterSelectedChangedCmd}" CommandParameter="{Binding ElementName=listviewMeter, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.View>
<TextBlock
Margin="0,0,5,0"
VerticalAlignment="Center"
DockPanel.Dock="Right"
FontSize="18"
Foreground="Blue"
Text="{Binding ElementName=MeterConfigInstance, Path=MeterName}"
TextAlignment="Right" />
</DockPanel>
<TabControl
x:Name="MainTabControl"
Grid.Row="1"
SelectedIndex="{Binding ElementName=MeterConfigInstance, Path=ConstSlopSelectedIndex}">
<TabControl.Style>
<Style BasedOn="{StaticResource MaterialDesignFilledTabControl}" TargetType="TabControl">
<!--<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=TBSwitchConstSlop}" Value="True">
<Setter Property="SelectedIndex" Value="1" />
</DataTrigger>
<DataTrigger Binding="{Binding IsChecked, ElementName=TBSwitchConstSlop}" Value="False">
<Setter Property="SelectedIndex" Value="0" />
</DataTrigger>
</Style.Triggers>-->
</Style>
</TabControl.Style>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ElementName=MeterConfigInstance, Path=SwitchConstSlopCommand}" CommandParameter="{Binding ElementName=MainTabControl, Path=SelectedIndex}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<!-- IsEnabled="{Binding IsChecked, ElementName=TBSwitchConstSlop, Converter={StaticResource BoolNgConverter}}" -->
<TabItem Header="常值">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="40" />
<RowDefinition />
</Grid.RowDefinitions>
<GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle1}">
<GridViewColumn
Width="60"
DisplayMemberBinding="{Binding StepNo}"
Header="序号" />
<GridViewColumn
<StackPanel Margin="10" Orientation="Vertical">
<TextBlock HorizontalAlignment="Center" FontSize="16">常值数据</TextBlock>
<TextBox
Width="200"
HorizontalContentAlignment="Center"
FontSize="20"
Text="{Binding ElementName=MeterConfigInstance, Path=ConstantValue}" />
</StackPanel>
<StackPanel Grid.Row="1" VerticalAlignment="Center">
<Button
Width="80"
DisplayMemberBinding="{Binding StartValue}"
Header="起始速度" />
<GridViewColumn
Width="80"
DisplayMemberBinding="{Binding EndValue}"
Header="终止速度" />
<GridViewColumn
Width="80"
DisplayMemberBinding="{Binding KeepTime}"
Header="持续时间" />
</GridView>
Margin="0,0,20,0"
Command="{Binding ElementName=MeterConfigInstance, Path=ConstantSaveCommand}"
Content="确定"
Foreground="White" />
</StackPanel>
</Grid>
</TabItem>
<!-- IsEnabled="{Binding IsChecked, ElementName=TBSwitchConstSlop}" -->
<TabItem Header="斜率">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="40" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.8*" />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="1.4*" />
</Grid.ColumnDefinitions>
<StackPanel Margin="1,10,0,0">
<TextBox
VerticalAlignment="Top"
materialDesign:HintAssist.Hint="序号"
FontSize="13"
FontWeight="Bold"
Style="{StaticResource MaterialDesignOutlinedTextBox}"
Text="{Binding ElementName=MeterConfigInstance, Path=SelectedMeter.StepNo}"
TextWrapping="NoWrap"
VerticalScrollBarVisibility="Disabled">
<TextBox.ToolTip>
<TextBlock
FontSize="14"
FontWeight="Bold"
Text="新增时自动填充序号;可手动修改序号" />
</TextBox.ToolTip>
</TextBox>
</StackPanel>
<StackPanel Grid.Column="1" Margin="1,10,0,0">
<TextBox
VerticalAlignment="Top"
materialDesign:HintAssist.Hint="起始值"
FontSize="13"
FontWeight="Bold"
Style="{StaticResource MaterialDesignOutlinedTextBox}"
Text="{Binding ElementName=MeterConfigInstance, Path=SelectedMeter.StartValue}"
TextWrapping="NoWrap"
VerticalScrollBarVisibility="Disabled">
<TextBox.ToolTip>
<TextBlock
FontSize="14"
FontWeight="Bold"
Text="起始值" />
</TextBox.ToolTip>
</TextBox>
</StackPanel>
<StackPanel Grid.Column="2" Margin="1,10,0,0">
<TextBox
VerticalAlignment="Top"
materialDesign:HintAssist.Hint="结束值"
FontSize="13"
FontWeight="Bold"
Style="{StaticResource MaterialDesignOutlinedTextBox}"
Text="{Binding ElementName=MeterConfigInstance, Path=SelectedMeter.EndValue}"
TextWrapping="NoWrap"
VerticalScrollBarVisibility="Disabled">
<TextBox.ToolTip>
<TextBlock
FontSize="14"
FontWeight="Bold"
Text="结束值" />
</TextBox.ToolTip>
</TextBox>
</StackPanel>
<StackPanel Grid.Column="3" Margin="1,10,3,0">
<TextBox
VerticalAlignment="Top"
materialDesign:HintAssist.Hint="维持时间"
FontSize="13"
FontWeight="Bold"
IsEnabled="True"
Style="{StaticResource MaterialDesignOutlinedTextBox}"
Text="{Binding ElementName=MeterConfigInstance, Path=SelectedMeter.KeepTime, Converter={StaticResource SecToStrConverter}}"
TextWrapping="NoWrap"
VerticalScrollBarVisibility="Disabled">
<TextBox.ToolTip>
<TextBlock
FontSize="14"
FontWeight="Bold"
Text="维持时间" />
</TextBox.ToolTip>
</TextBox>
</StackPanel>
</Grid>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button
Margin="2,2"
Background="IndianRed"
Command="{Binding ElementName=MeterConfigInstance, Path=AddCommand}"
Content="增加"
Foreground="White"
Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
ToolTip="增加程序步骤内的速度设置" />
<Button
Margin="1,2"
Background="IndianRed"
Command="{Binding ElementName=MeterConfigInstance, Path=EditCommand}"
Content="修改"
Foreground="White"
Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
ToolTip="修改程序步骤内的速度设置,请先选中" />
<Button
Margin="1,2"
Background="IndianRed"
Command="{Binding ElementName=MeterConfigInstance, Path=DeleteCommand}"
Content="删除"
Foreground="White"
Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
ToolTip="删除程序步骤内的速度设置,请先选中" />
<StackPanel Margin="2,2,2,2" Orientation="Vertical">
<TextBlock
HorizontalAlignment="Center"
Foreground="Blue"
Text="时间" />
<TextBlock
VerticalAlignment="Center"
FontSize="16"
Foreground="Blue"
Text="{Binding ElementName=MeterConfigInstance, Path=TotalSlopTime, Converter={StaticResource SecToStrConverter}}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MeterConfigInstance, Path=IsTimeOk}" Value="true">
<Setter Property="Background" Value="LimeGreen" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=MeterConfigInstance, Path=IsTimeOk}" Value="false">
<Setter Property="Background" Value="OrangeRed" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
</ListView.View>
<!-- 设置ListViewItem的背景色模拟网格效果 -->
<!--<ListView.ItemContainerStyle>
<StackPanel Margin="1,2,2,2" Orientation="Vertical">
<TextBlock
HorizontalAlignment="Center"
Foreground="Blue"
Text="循环" />
<TextBlock
VerticalAlignment="Center"
FontSize="16"
Foreground="Blue"
Text="{Binding ElementName=MeterConfigInstance, Path=Cycle, StringFormat=0.0}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MeterConfigInstance, Path=IsTimeOk}" Value="true">
<Setter Property="Background" Value="LimeGreen" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=MeterConfigInstance, Path=IsTimeOk}" Value="false">
<Setter Property="Background" Value="OrangeRed" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
</StackPanel>
<Border
Grid.Row="2"
Margin="1,0"
BorderBrush="Black"
BorderThickness="1">
<ListView
x:Name="listviewMeter"
Foreground="Black"
ItemsSource="{Binding ElementName=MeterConfigInstance, Path=ListMeter}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ElementName=MeterConfigInstance, Path=MeterSelectedChangedCmd}" CommandParameter="{Binding ElementName=listviewMeter, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle1}">
<GridViewColumn
Width="40"
DisplayMemberBinding="{Binding StepNo}"
Header="序号" />
<GridViewColumn
Width="60"
DisplayMemberBinding="{Binding StartValue}"
Header="起始值" />
<GridViewColumn
Width="60"
DisplayMemberBinding="{Binding EndValue}"
Header="结束值" />
<GridViewColumn
Width="100"
DisplayMemberBinding="{Binding KeepTime, Converter={StaticResource SecToStrConverter}}"
Header="维持时间" />
</GridView>
</ListView.View>
<!-- 设置ListViewItem的背景色模拟网格效果 -->
<!--<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Background" Value="LightGray" />
</Style>
</ListView.ItemContainerStyle>-->
</ListView>
</Border>
</ListView>
</Border>
</Grid>
</TabItem>
</TabControl>
</Grid>
</UserControl>

View File

@@ -27,6 +27,44 @@ namespace CapMachine.Shared.Controls
InitializeComponent();
}
//ConstSlopSelectedIndex
/// <summary>
/// TabControl选择的Index
/// </summary>
public int ConstSlopSelectedIndex
{
get
{
return (int)base.GetValue(MeterConfig.ConstSlopSelectedIndexProperty);
}
set
{
base.SetValue(MeterConfig.ConstSlopSelectedIndexProperty, value);
}
}
public static readonly DependencyProperty ConstSlopSelectedIndexProperty = DependencyProperty.Register("ConstSlopSelectedIndex", typeof(int), typeof(MeterConfig), new PropertyMetadata(1));
/// <summary>
/// 常量数据
/// </summary>
public double ConstantValue
{
get
{
return (double)base.GetValue(MeterConfig.ConstantValueProperty);
}
set
{
base.SetValue(MeterConfig.ConstantValueProperty, value);
}
}
public static readonly DependencyProperty ConstantValueProperty = DependencyProperty.Register("ConstantValue", typeof(double), typeof(MeterConfig), new PropertyMetadata(0.0));
/// <summary>
/// 仪表名称
/// </summary>
public string MeterName
{
get
@@ -38,7 +76,7 @@ namespace CapMachine.Shared.Controls
base.SetValue(MeterConfig.MeterNameProperty, value);
}
}
public static readonly DependencyProperty MeterNameProperty = DependencyProperty.Register("MeterName", typeof(string), typeof(MeterConfig), new PropertyMetadata("速度"));
public static readonly DependencyProperty MeterNameProperty = DependencyProperty.Register("MeterName", typeof(string), typeof(MeterConfig), new PropertyMetadata("变量"));
//MeterSlopCell
@@ -107,7 +145,7 @@ namespace CapMachine.Shared.Controls
//MeterSelectedChangedCmd
/// <summary>
/// Add 命令
/// MeterSelectedChanged 命令
/// </summary>
public ICommand MeterSelectedChangedCmd
{
@@ -118,5 +156,96 @@ namespace CapMachine.Shared.Controls
DependencyProperty.Register("MeterSelectedChangedCmd", typeof(ICommand), typeof(MeterConfig), new PropertyMetadata(default(ICommand)));
/// <summary>
/// Constant 保存 命令
/// </summary>
public ICommand ConstantSaveCommand
{
get { return (ICommand)GetValue(ConstantSaveCommandProperty); }
set { SetValue(ConstantSaveCommandProperty, value); }
}
public static readonly DependencyProperty ConstantSaveCommandProperty =
DependencyProperty.Register("ConstantSaveCommand", typeof(ICommand), typeof(MeterConfig), new PropertyMetadata(default(ICommand)));
/// <summary>
/// Constant/Slop 常值和斜率切换 命令
/// </summary>
public ICommand SwitchConstSlopCommand
{
get { return (ICommand)GetValue(SwitchConstSlopCommandProperty); }
set { SetValue(SwitchConstSlopCommandProperty, value); }
}
public static readonly DependencyProperty SwitchConstSlopCommandProperty =
DependencyProperty.Register("SwitchConstSlopCommand", typeof(ICommand), typeof(MeterConfig), new PropertyMetadata(default(ICommand)));
///// <summary>
///// Constant/Slop 切换命令的参数值
///// </summary>
//public bool SwitchConstSlopPar
//{
// get
// {
// return (bool)base.GetValue(MeterConfig.SwitchConstSlopParProperty);
// }
// set
// {
// base.SetValue(MeterConfig.SwitchConstSlopParProperty, value);
// }
//}
//public static readonly DependencyProperty SwitchConstSlopParProperty = DependencyProperty.Register("SwitchConstSlopPar", typeof(bool), typeof(MeterConfig), new PropertyMetadata(true));
/// <summary>
/// 斜率列表总时间
/// </summary>
public int TotalSlopTime
{
get
{
return (int)base.GetValue(MeterConfig.TotalSlopTimeProperty);
}
set
{
base.SetValue(MeterConfig.TotalSlopTimeProperty, value);
}
}
public static readonly DependencyProperty TotalSlopTimeProperty = DependencyProperty.Register("TotalSlopTime", typeof(int), typeof(MeterConfig), new PropertyMetadata(0));
/// <summary>
/// 斜率循环的次数
/// </summary>
public double Cycle
{
get
{
return (double)base.GetValue(MeterConfig.CycleProperty);
}
set
{
base.SetValue(MeterConfig.CycleProperty, value);
}
}
public static readonly DependencyProperty CycleProperty = DependencyProperty.Register("Cycle", typeof(double), typeof(MeterConfig), new PropertyMetadata(1.0));
/// <summary>
/// 斜率列表 是否满足要求
/// </summary>
public bool IsTimeOk
{
get
{
return (bool)base.GetValue(MeterConfig.IsTimeOkProperty);
}
set
{
base.SetValue(MeterConfig.IsTimeOkProperty, value);
}
}
public static readonly DependencyProperty IsTimeOkProperty = DependencyProperty.Register("IsTimeOk", typeof(bool), typeof(MeterConfig), new PropertyMetadata(false));
}
}

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace CapMachine.Shared.Controls
{
/// <summary>
/// 秒到字符串类型的展示
/// </summary>
public class SecToStrConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
return SecToString((int)value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
return StringToSec((string)value);
}
/// <summary>
/// 秒时间到 00:00:00字符串
/// </summary>
/// <returns></returns>
private string SecToString(int TotalSec)
{
try
{
TimeSpan TimeInfo = TimeSpan.FromSeconds(TotalSec);
return TimeInfo.ToString();
}
catch (Exception ex)
{
MessageBox.Show("请检查输入时间数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
return "00:00:00";
}
}
/// <summary>
/// 00:00:00到秒时间
/// </summary>
/// <returns></returns>
private int StringToSec(string timeString)
{
try
{
TimeSpan TimeInfo = TimeSpan.Parse(timeString);
return (int)TimeInfo.TotalSeconds;
}
catch (Exception ex)
{
MessageBox.Show("请按照时间样式输入时间数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
return 0;
}
}
}
}