@@ -6,10 +6,6 @@ | |||||
<Nullable>enable</Nullable> | <Nullable>enable</Nullable> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | |||||
<Folder Include="Hepler\" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<Reference Include="Antlr3.Runtime"> | <Reference Include="Antlr3.Runtime"> | ||||
<HintPath>DLL\Antlr3.Runtime.dll</HintPath> | <HintPath>DLL\Antlr3.Runtime.dll</HintPath> | ||||
@@ -4,7 +4,7 @@ using System.Linq; | |||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace BPASmartClient.SCADAControl | |||||
namespace BPASmartClient.Compiler | |||||
{ | { | ||||
public interface IExecutable | public interface IExecutable | ||||
{ | { |
@@ -0,0 +1,27 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace BPASmartClient.MessageName.Enum.物料仓 | |||||
{ | |||||
/// <summary> | |||||
/// 物料仓数据设置-Model | |||||
/// </summary> | |||||
public class SilosMessageModel | |||||
{ | |||||
/// <summary> | |||||
/// 物料仓:仓号 | |||||
/// </summary> | |||||
public string id { get; set; } | |||||
/// <summary> | |||||
/// 物料仓:标题 | |||||
/// </summary> | |||||
public string Title { get; set; } | |||||
/// <summary> | |||||
/// 物料仓:重量(G) 35.23 | |||||
/// </summary> | |||||
public string Value { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,27 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace BPASmartClient.MessageName.Enum.运行状态 | |||||
{ | |||||
/// <summary> | |||||
/// 运行状态-枚举 | |||||
/// </summary> | |||||
public enum RunEnum | |||||
{ | |||||
/// <summary> | |||||
/// 运行(滚动线默认右转) | |||||
/// </summary> | |||||
Run, | |||||
/// <summary> | |||||
/// 运行-左转(滚动线独有) | |||||
/// </summary> | |||||
Run_Left, | |||||
/// <summary> | |||||
/// 停止 | |||||
/// </summary> | |||||
Stop | |||||
} | |||||
} |
@@ -66,6 +66,7 @@ namespace BPASmartClient.MessageName | |||||
/// 物料仓数据设置 | /// 物料仓数据设置 | ||||
/// </summary> | /// </summary> | ||||
SilosSetData, | SilosSetData, | ||||
/// <summary> | /// <summary> | ||||
/// 滚动线运行状态 | /// 滚动线运行状态 | ||||
/// </summary> | /// </summary> | ||||
@@ -1,4 +1,5 @@ | |||||
using System; | |||||
using BPASmartClient.Compiler; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.ComponentModel; | using System.ComponentModel; | ||||
using System.Linq; | using System.Linq; | ||||
@@ -12,6 +12,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPASmartClient.Compiler\BPASmartClient.Compiler.csproj" /> | <ProjectReference Include="..\BPASmartClient.Compiler\BPASmartClient.Compiler.csproj" /> | ||||
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.MessageName\BPASmartClient.MessageName.csproj" /> | <ProjectReference Include="..\BPASmartClient.MessageName\BPASmartClient.MessageName.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -1,4 +1,8 @@ | |||||
using BPASmartClient.MessageName; | |||||
using BPASmartClient.Compiler; | |||||
using BPASmartClient.MessageCommunication; | |||||
using BPASmartClient.MessageCommunication.MsgControl; | |||||
using BPASmartClient.MessageName; | |||||
using BPASmartClient.MessageName.Enum.运行状态; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.ObjectModel; | using System.Collections.ObjectModel; | ||||
@@ -24,10 +28,14 @@ namespace BPASmartClient.SCADAControl | |||||
/// </summary> | /// </summary> | ||||
public partial class NewConveyorBelt : UserControl, IExecutable | public partial class NewConveyorBelt : UserControl, IExecutable | ||||
{ | { | ||||
#region 临时变量 | |||||
Path Path_mp = null; | Path Path_mp = null; | ||||
Path Path_cb = null; | Path Path_cb = null; | ||||
Storyboard storyboard = new Storyboard(); | Storyboard storyboard = new Storyboard(); | ||||
Storyboard storyboard1 = new Storyboard(); | Storyboard storyboard1 = new Storyboard(); | ||||
#endregion | |||||
public NewConveyorBelt() | public NewConveyorBelt() | ||||
{ | { | ||||
InitializeComponent(); | InitializeComponent(); | ||||
@@ -43,7 +51,6 @@ namespace BPASmartClient.SCADAControl | |||||
} | } | ||||
public string ControlType => "滚动线"; | public string ControlType => "滚动线"; | ||||
private bool isExecuteState; | private bool isExecuteState; | ||||
public bool IsExecuteState | public bool IsExecuteState | ||||
{ | { | ||||
@@ -60,11 +67,7 @@ namespace BPASmartClient.SCADAControl | |||||
} | } | ||||
} | } | ||||
public void Register() | |||||
{ | |||||
} | |||||
#region 内部函数 | |||||
public void VisualStateManagerData() | public void VisualStateManagerData() | ||||
{ | { | ||||
storyboard.RepeatBehavior = RepeatBehavior.Forever; | storyboard.RepeatBehavior = RepeatBehavior.Forever; | ||||
@@ -163,35 +166,13 @@ namespace BPASmartClient.SCADAControl | |||||
} | } | ||||
} | } | ||||
} | } | ||||
#endregion | |||||
#region 属性 | |||||
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||||
{ | { | ||||
(d as NewConveyorBelt)?.Refursh(); | (d as NewConveyorBelt)?.Refursh(); | ||||
} | } | ||||
private void Refursh() | |||||
{ | |||||
if (Direction == 1) | |||||
{ | |||||
storyboard.Begin(); | |||||
storyboard1.Stop(); | |||||
// VisualStateManager.GoToState(this, "Left", false); | |||||
} | |||||
else if (Direction == 2) | |||||
{ | |||||
storyboard.Stop(); | |||||
storyboard1.Begin(); | |||||
//VisualStateManager.GoToState(this, "Right", false); | |||||
} | |||||
else | |||||
{ | |||||
storyboard.Stop(); | |||||
storyboard1.Stop(); | |||||
//VisualStateManager.GoToState(this, "Stop", false); | |||||
} | |||||
} | |||||
public DoubleCollection StrokeDashArray | public DoubleCollection StrokeDashArray | ||||
{ | { | ||||
get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); } | get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); } | ||||
@@ -252,7 +233,7 @@ namespace BPASmartClient.SCADAControl | |||||
DependencyProperty.Register("Direction", typeof(int), typeof(NewConveyorBelt), | DependencyProperty.Register("Direction", typeof(int), typeof(NewConveyorBelt), | ||||
new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged))); | new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged))); | ||||
[Category("主题订阅")] | [Category("主题订阅")] | ||||
public string ConveyorBeltLeft | public string ConveyorBeltLeft | ||||
{ | { | ||||
@@ -278,22 +259,68 @@ namespace BPASmartClient.SCADAControl | |||||
public static readonly DependencyProperty ConveyorBeltStopProperty = | public static readonly DependencyProperty ConveyorBeltStopProperty = | ||||
DependencyProperty.Register("ConveyorBeltStop", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty)); | DependencyProperty.Register("ConveyorBeltStop", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty)); | ||||
//[Category("事件名称集合")] | |||||
//public ObservableCollection<string> EventList | |||||
//{ | |||||
// get { return (ObservableCollection<string>)GetValue(EventListProperty); } | |||||
// set { SetValue(EventListProperty, value); } | |||||
//} | |||||
//public static readonly DependencyProperty EventListProperty = | |||||
// DependencyProperty.Register("EventList", typeof(ObservableCollection<string>), typeof(NewConveyorBelt), new PropertyMetadata(new ObservableCollection<string>())); | |||||
[Category("消息名称")] | [Category("消息名称")] | ||||
public MessageNameEnum EventName | |||||
public MessageNameEnum EventRunName | |||||
{ | |||||
get { return (MessageNameEnum)GetValue(EventRunNameProperty); } | |||||
set { SetValue(EventRunNameProperty, value); } | |||||
} | |||||
public static readonly DependencyProperty EventRunNameProperty = | |||||
DependencyProperty.Register("EventRunName", typeof(MessageNameEnum), typeof(NewConveyorBelt), new PropertyMetadata(MessageNameEnum.Null, onEventRunNameChanged)); | |||||
private static void onEventRunNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as NewConveyorBelt)?.RunNameRefresh(); | |||||
#endregion | |||||
#region 属性变更事件 | |||||
public void Register() | |||||
{ | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this, EventRunName.ToString(), "EventRunNameHandler"); | |||||
} | |||||
public void EventRunNameHandler(object sender, InnerMessageEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
if (IsExecuteState = true) | |||||
{ | |||||
if (e.obj_MessageObj is RunEnum) | |||||
{ | |||||
RunEnum runEnum = (RunEnum)e.obj_MessageObj; | |||||
Direction = runEnum == RunEnum.Run ? 1 : ((runEnum == RunEnum.Run_Left)?2:0); | |||||
} | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
} | |||||
} | |||||
private void Refursh() | |||||
{ | |||||
if (Direction == 1) | |||||
{ | |||||
storyboard.Begin(); | |||||
storyboard1.Stop(); | |||||
} | |||||
else if (Direction == 2) | |||||
{ | |||||
storyboard.Stop(); | |||||
storyboard1.Begin(); | |||||
} | |||||
else | |||||
{ | |||||
storyboard.Stop(); | |||||
storyboard1.Stop(); | |||||
} | |||||
} | |||||
public void RunNameRefresh() | |||||
{ | { | ||||
get { return (MessageNameEnum)GetValue(EventNameProperty); } | |||||
set { SetValue(EventNameProperty, value); } | |||||
} | } | ||||
public static readonly DependencyProperty EventNameProperty = | |||||
DependencyProperty.Register("EventName", typeof(MessageNameEnum), typeof(NewConveyorBelt), new PropertyMetadata(MessageNameEnum.Null)); | |||||
#endregion | |||||
} | } | ||||
@@ -1,4 +1,9 @@ | |||||
using BPASmartClient.MessageName; | |||||
using BPASmartClient.Compiler; | |||||
using BPASmartClient.MessageCommunication; | |||||
using BPASmartClient.MessageCommunication.MsgControl; | |||||
using BPASmartClient.MessageName; | |||||
using BPASmartClient.MessageName.Enum.物料仓; | |||||
using BPASmartClient.MessageName.Enum.运行状态; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.ComponentModel; | using System.ComponentModel; | ||||
@@ -24,26 +29,26 @@ namespace BPASmartClient.SCADAControl | |||||
/// </summary> | /// </summary> | ||||
public partial class Silos : UserControl, IExecutable | public partial class Silos : UserControl, IExecutable | ||||
{ | { | ||||
#region 临时变量 | |||||
TextBlock textBlockCLKZ = null; | TextBlock textBlockCLKZ = null; | ||||
Ellipse ellipseControl = null; | Ellipse ellipseControl = null; | ||||
Storyboard storyboard = new Storyboard(); | Storyboard storyboard = new Storyboard(); | ||||
#endregion | |||||
public Silos() | public Silos() | ||||
{ | { | ||||
InitializeComponent(); | InitializeComponent(); | ||||
this.DataContext = this; | this.DataContext = this; | ||||
Width = 180; | Width = 180; | ||||
Height = 270; | Height = 270; | ||||
Value = 25.23; | |||||
Value = "25.23"; | |||||
Title = "香料"; | Title = "香料"; | ||||
Text = "1"; | Text = "1"; | ||||
this.SizeChanged += Silos_SizeChanged; ; | this.SizeChanged += Silos_SizeChanged; ; | ||||
} | } | ||||
public string ControlType => "物料仓"; | public string ControlType => "物料仓"; | ||||
private bool isExecuteState; | private bool isExecuteState; | ||||
public bool IsExecuteState | public bool IsExecuteState | ||||
{ | { | ||||
@@ -127,16 +132,13 @@ namespace BPASmartClient.SCADAControl | |||||
#region 属性 | #region 属性 | ||||
[Category("值设定")] | [Category("值设定")] | ||||
public double Value | |||||
public string Value | |||||
{ | { | ||||
get { return (double)GetValue(ValueProperty); } | |||||
get { return (string)GetValue(ValueProperty); } | |||||
set { SetValue(ValueProperty, value); } | set { SetValue(ValueProperty, value); } | ||||
} | } | ||||
public static readonly DependencyProperty ValueProperty = | public static readonly DependencyProperty ValueProperty = | ||||
DependencyProperty.Register("Value", typeof(double), typeof(Silos), new PropertyMetadata(0d, OnValueChanged)); | |||||
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as Silos)?.Refresh(); | |||||
DependencyProperty.Register("Value", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); | |||||
[Category("值设定")] | [Category("值设定")] | ||||
public string Text | public string Text | ||||
{ | { | ||||
@@ -156,14 +158,23 @@ namespace BPASmartClient.SCADAControl | |||||
DependencyProperty.Register("Title", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); | DependencyProperty.Register("Title", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); | ||||
[Category("消息名称")] | [Category("消息名称")] | ||||
public MessageNameEnum EventName | |||||
public MessageNameEnum EventRunName | |||||
{ | { | ||||
get { return (MessageNameEnum)GetValue(EventNameProperty); } | |||||
set { SetValue(EventNameProperty, value); } | |||||
get { return (MessageNameEnum)GetValue(EventRunNameProperty); } | |||||
set { SetValue(EventRunNameProperty, value); } | |||||
} | } | ||||
public static readonly DependencyProperty EventNameProperty = | |||||
DependencyProperty.Register("EventName", typeof(MessageNameEnum), typeof(Silos), new PropertyMetadata(MessageNameEnum.Null,onEventValueChanged)); | |||||
private static void onEventValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as Silos)?.Refresh(); | |||||
public static readonly DependencyProperty EventRunNameProperty = | |||||
DependencyProperty.Register("EventRunName", typeof(MessageNameEnum), typeof(Silos), new PropertyMetadata(MessageNameEnum.Null, onEventRunNameChanged)); | |||||
private static void onEventRunNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as Silos)?.RunNameRefresh(); | |||||
[Category("消息名称")] | |||||
public MessageNameEnum EventDataName | |||||
{ | |||||
get { return (MessageNameEnum)GetValue(EventDataNameProperty); } | |||||
set { SetValue(EventDataNameProperty, value); } | |||||
} | |||||
public static readonly DependencyProperty EventDataNameProperty = | |||||
DependencyProperty.Register("EventDataName", typeof(MessageNameEnum), typeof(Silos), new PropertyMetadata(MessageNameEnum.Null, onEventDataNameChanged)); | |||||
private static void onEventDataNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as Silos)?.DataNameRefresh(); | |||||
[Category("值设定")] | [Category("值设定")] | ||||
public int Direction | public int Direction | ||||
{ | { | ||||
@@ -180,6 +191,9 @@ namespace BPASmartClient.SCADAControl | |||||
#endregion | #endregion | ||||
#region 函数 | #region 函数 | ||||
/// <summary> | |||||
/// 值变化刷新 | |||||
/// </summary> | |||||
public void Refresh() | public void Refresh() | ||||
{ | { | ||||
if (ellipseControl != null) | if (ellipseControl != null) | ||||
@@ -204,12 +218,72 @@ namespace BPASmartClient.SCADAControl | |||||
} | } | ||||
} | } | ||||
} | |||||
/// <summary> | |||||
/// 运行名称变化事件 | |||||
/// </summary> | |||||
public void RunNameRefresh() | |||||
{ | |||||
} | |||||
/// <summary> | |||||
/// 数据名称变化事件 | |||||
/// </summary> | |||||
public void DataNameRefresh() | |||||
{ | |||||
} | } | ||||
#endregion | #endregion | ||||
#region 运行事件 | |||||
public void Register() | public void Register() | ||||
{ | { | ||||
Class_InnerMessageBus.GetInstance().ListenMessage(this, EventRunName.ToString(), "EventRunNameHandler"); | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this, EventDataName.ToString(), "EventDataNameHandler"); | |||||
} | |||||
public void EventRunNameHandler(object sender, InnerMessageEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
if (IsExecuteState = true) | |||||
{ | |||||
if (e.obj_MessageObj is RunEnum) | |||||
{ | |||||
RunEnum runEnum = (RunEnum)e.obj_MessageObj; | |||||
Direction = runEnum == RunEnum.Run ? 1 : 2; | |||||
} | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
} | |||||
} | |||||
public void EventDataNameHandler(object sender, InnerMessageEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
if (IsExecuteState = true) | |||||
{ | |||||
if (e.obj_MessageObj is SilosMessageModel) | |||||
{ | |||||
SilosMessageModel silosMessageModel = (SilosMessageModel)e.obj_MessageObj; | |||||
if (silosMessageModel.id == Text) | |||||
{ | |||||
Title=silosMessageModel.Title; | |||||
Value= silosMessageModel.Value; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
} | |||||
} | } | ||||
#endregion | |||||
} | } | ||||
} | } |
@@ -0,0 +1,9 @@ | |||||
<Application x:Class="SCADA.Test.App" | |||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||||
xmlns:local="clr-namespace:SCADA.Test" | |||||
StartupUri="MainWindow.xaml"> | |||||
<Application.Resources> | |||||
</Application.Resources> | |||||
</Application> |
@@ -0,0 +1,17 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Configuration; | |||||
using System.Data; | |||||
using System.Linq; | |||||
using System.Threading.Tasks; | |||||
using System.Windows; | |||||
namespace SCADA.Test | |||||
{ | |||||
/// <summary> | |||||
/// Interaction logic for App.xaml | |||||
/// </summary> | |||||
public partial class App : Application | |||||
{ | |||||
} | |||||
} |
@@ -0,0 +1,10 @@ | |||||
using System.Windows; | |||||
[assembly: ThemeInfo( | |||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | |||||
//(used if a resource is not found in the page, | |||||
// or application resource dictionaries) | |||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | |||||
//(used if a resource is not found in the page, | |||||
// app, or any theme specific resource dictionaries) | |||||
)] |
@@ -0,0 +1,32 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Globalization; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using System.Windows.Data; | |||||
namespace SCADA.Test.Converters | |||||
{ | |||||
public class ZoomConverter : IValueConverter | |||||
{ | |||||
public bool IsHeight { get; set; } | |||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |||||
{ | |||||
if (double.TryParse(value.ToString(), out double zoom)) | |||||
{ | |||||
return IsHeight ? zoom * 1080 : zoom * 1920; | |||||
} | |||||
else | |||||
{ | |||||
return IsHeight ? 1080 : 1920; | |||||
} | |||||
} | |||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |||||
{ | |||||
return value; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,18 @@ | |||||
<Window x:Class="SCADA.Test.MainWindow" | |||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||||
xmlns:local="clr-namespace:SCADA.Test" | |||||
mc:Ignorable="d" | |||||
Title="MainWindow" Height="450" Width="800"> | |||||
<Grid> | |||||
<Grid.RowDefinitions> | |||||
<RowDefinition Height="40"/> | |||||
<RowDefinition/> | |||||
</Grid.RowDefinitions> | |||||
<Button Click="Button_Click">加载文件</Button> | |||||
<local:RunCanvas Grid.Row="1" x:Name="runCanvas"/> | |||||
</Grid> | |||||
</Window> |
@@ -0,0 +1,74 @@ | |||||
using Microsoft.Win32; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.IO; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using System.Windows; | |||||
using System.Windows.Controls; | |||||
using System.Windows.Data; | |||||
using System.Windows.Documents; | |||||
using System.Windows.Input; | |||||
using System.Windows.Markup; | |||||
using System.Windows.Media; | |||||
using System.Windows.Media.Imaging; | |||||
using System.Windows.Navigation; | |||||
using System.Windows.Shapes; | |||||
namespace SCADA.Test | |||||
{ | |||||
/// <summary> | |||||
/// Interaction logic for MainWindow.xaml | |||||
/// </summary> | |||||
public partial class MainWindow : Window | |||||
{ | |||||
List<FrameworkElement> Children = new List<FrameworkElement>(); | |||||
public MainWindow() | |||||
{ | |||||
InitializeComponent(); | |||||
} | |||||
#region 加载数据 | |||||
/// <summary> | |||||
/// 加载数据 | |||||
/// </summary> | |||||
public void LoadingData(string path) | |||||
{ | |||||
//加载控件 | |||||
Children.Clear(); | |||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | |||||
using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.Unicode)) | |||||
{ | |||||
while (sr.Peek() > -1) | |||||
{ | |||||
string str = sr.ReadLine(); | |||||
//if (!str.Contains("NewConveyorBelt")) | |||||
{ | |||||
var ele = XamlReader.Parse(str) as FrameworkElement; | |||||
Children.Add(ele); | |||||
} | |||||
} | |||||
} | |||||
if (Children.Count > 0) | |||||
{ | |||||
runCanvas.Run(Children); | |||||
} | |||||
} | |||||
#endregion | |||||
private void Button_Click(object sender, RoutedEventArgs e) | |||||
{ | |||||
OpenFileDialog ofd = new OpenFileDialog(); | |||||
ofd.Filter = "布局文件|*.lay"; | |||||
if (ofd.ShowDialog() ==true) | |||||
{ | |||||
LoadingData(ofd.FileName); | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
<UserControl x:Class="SCADA.Test.RunCanvas" | |||||
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:con="clr-namespace:SCADA.Test.Converters" | |||||
xmlns:local="clr-namespace:SCADA.Test" | |||||
mc:Ignorable="d" | |||||
d:DesignHeight="450" d:DesignWidth="800"> | |||||
<UserControl.Resources> | |||||
<con:ZoomConverter x:Key="ZoomX" IsHeight="False"/> | |||||
<con:ZoomConverter x:Key="ZoomY" IsHeight="True"/> | |||||
</UserControl.Resources> | |||||
<Grid ClipToBounds="True"> | |||||
<Canvas x:Name="RootCanvas" ClipToBounds="True" Background="Transparent" MouseLeftButtonUp="RootCanvas_MouseLeftButtonUp" | |||||
MouseMove="RootCanvas_MouseMove" MouseLeftButtonDown="RootCanvas_MouseLeftButtoDown" MouseWheel="RootCanvas_MouseWheel"> | |||||
<Canvas.RenderTransform> | |||||
<TransformGroup> | |||||
<ScaleTransform x:Name="Scale"/> | |||||
<TranslateTransform x:Name="Translate"/> | |||||
</TransformGroup> | |||||
</Canvas.RenderTransform> | |||||
</Canvas> | |||||
<Grid VerticalAlignment="Bottom" Background="#4B959595"> | |||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="8 0"> | |||||
<CheckBox x:Name="DragEnable" Content="拖动" Margin="4"/> | |||||
<CheckBox x:Name="ZoomEnable" Content="缩放" Margin="4"/> | |||||
</StackPanel> | |||||
</Grid> | |||||
</Grid> | |||||
</UserControl> |
@@ -0,0 +1,132 @@ | |||||
using BPASmartClient.Compiler; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using System.Windows; | |||||
using System.Windows.Controls; | |||||
using System.Windows.Data; | |||||
using System.Windows.Documents; | |||||
using System.Windows.Input; | |||||
using System.Windows.Media; | |||||
using System.Windows.Media.Imaging; | |||||
using System.Windows.Navigation; | |||||
using System.Windows.Shapes; | |||||
namespace SCADA.Test | |||||
{ | |||||
/// <summary> | |||||
/// RunCanvas.xaml 的交互逻辑 | |||||
/// </summary> | |||||
public partial class RunCanvas : UserControl | |||||
{ | |||||
public RunCanvas() | |||||
{ | |||||
InitializeComponent(); | |||||
Unloaded += (s, e) => Destory(); | |||||
} | |||||
/// <summary> | |||||
/// Dispose子集 | |||||
/// </summary> | |||||
public void Destory() | |||||
{ | |||||
foreach (var item in RootCanvas.Children) | |||||
{ | |||||
if (item is IDisposable disposable) | |||||
{ | |||||
disposable.Dispose(); | |||||
} | |||||
} | |||||
} | |||||
public void Run(List<FrameworkElement> canvas) | |||||
{ | |||||
RootCanvas.Children.Clear(); | |||||
foreach (FrameworkElement element in canvas) | |||||
{ | |||||
if (element.GetType().GetInterface("IExecutable") != null) | |||||
{ | |||||
element.GetType().GetProperty("IsExecuteState").SetValue(element, true); | |||||
} | |||||
if (element is IExecutable executable) | |||||
executable.IsExecuteState = true; | |||||
RootCanvas.Children.Add(element); | |||||
RegisterJsName(element); | |||||
} | |||||
} | |||||
// 注册名称到Js | |||||
static void RegisterJsName(FrameworkElement element) | |||||
{ | |||||
Config.GetInstance().SetVariable(element.Name, element); | |||||
if (element is Panel panel) | |||||
{ | |||||
foreach (var item in panel.Children) | |||||
{ | |||||
RegisterJsName(item as FrameworkElement); | |||||
} | |||||
} | |||||
} | |||||
#region 拖动与缩放 | |||||
private void RootCanvas_MouseMove(object sender, MouseEventArgs e) | |||||
{ | |||||
if (DragEnable.IsChecked == false) | |||||
{ | |||||
return; | |||||
} | |||||
if (e.LeftButton == MouseButtonState.Pressed && isPressed) | |||||
{ | |||||
Point point = e.GetPosition(this); | |||||
var movex = (point.X - last.X); | |||||
var movey = (point.Y - last.Y); | |||||
Translate.X += movex; | |||||
Translate.Y += movey; | |||||
last = point; | |||||
} | |||||
} | |||||
bool isPressed = false; | |||||
Point last;//记录上次鼠标坐标位置 | |||||
private void RootCanvas_MouseLeftButtoDown(object sender, MouseButtonEventArgs e) | |||||
{ | |||||
last = e.GetPosition(this); | |||||
isPressed = true; | |||||
} | |||||
private void RootCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) | |||||
{ | |||||
isPressed = false; | |||||
} | |||||
// 缩放 | |||||
private void RootCanvas_MouseWheel(object sender, MouseWheelEventArgs e) | |||||
{ | |||||
if (ZoomEnable.IsChecked == false) | |||||
{ | |||||
return; | |||||
} | |||||
var zoomS = (e.Delta / 960d); | |||||
var zoom = zoomS + Scale.ScaleX; | |||||
if (zoom > 3 || zoom < 0.8) | |||||
{ | |||||
return; | |||||
} | |||||
Scale.ScaleX = Scale.ScaleY = zoom; | |||||
Point mouse = e.GetPosition(RootCanvas); | |||||
Point newMouse = new Point(mouse.X * zoomS, mouse.Y * zoomS); | |||||
Translate.X -= newMouse.X; | |||||
Translate.Y -= newMouse.Y; | |||||
} | |||||
#endregion | |||||
} | |||||
} |
@@ -0,0 +1,15 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<OutputType>WinExe</OutputType> | |||||
<TargetFramework>net6.0-windows</TargetFramework> | |||||
<Nullable>enable</Nullable> | |||||
<UseWPF>true</UseWPF> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\BPASmartClient.Compiler\BPASmartClient.Compiler.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.SCADAControl\BPASmartClient.SCADAControl.csproj" /> | |||||
</ItemGroup> | |||||
</Project> |
@@ -148,7 +148,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.消息名称管理", "2. | |||||
EndProject | EndProject | ||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3.组态控件集", "3.组态控件集", "{5300552F-560D-474A-8D96-0A2747D08F64}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3.组态控件集", "3.组态控件集", "{5300552F-560D-474A-8D96-0A2747D08F64}" | ||||
EndProject | EndProject | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPASmartClient.Compiler", "BPASmartClient.Compiler\BPASmartClient.Compiler.csproj", "{B6213013-2A0E-41DD-BA9F-775D53C19374}" | |||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.Compiler", "BPASmartClient.Compiler\BPASmartClient.Compiler.csproj", "{B6213013-2A0E-41DD-BA9F-775D53C19374}" | |||||
EndProject | |||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4.界面加载实例", "4.界面加载实例", "{309D579E-DDA8-4B01-A0AA-0F381BC37801}" | |||||
EndProject | |||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SCADA.Test", "SCADA.Test\SCADA.Test.csproj", "{1696D557-C908-4136-A5F2-FF59D69E642C}" | |||||
EndProject | EndProject | ||||
Global | Global | ||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
@@ -1384,6 +1388,26 @@ Global | |||||
{B6213013-2A0E-41DD-BA9F-775D53C19374}.Release|x64.Build.0 = Release|Any CPU | {B6213013-2A0E-41DD-BA9F-775D53C19374}.Release|x64.Build.0 = Release|Any CPU | ||||
{B6213013-2A0E-41DD-BA9F-775D53C19374}.Release|x86.ActiveCfg = Release|Any CPU | {B6213013-2A0E-41DD-BA9F-775D53C19374}.Release|x86.ActiveCfg = Release|Any CPU | ||||
{B6213013-2A0E-41DD-BA9F-775D53C19374}.Release|x86.Build.0 = Release|Any CPU | {B6213013-2A0E-41DD-BA9F-775D53C19374}.Release|x86.Build.0 = Release|Any CPU | ||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|ARM.ActiveCfg = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|ARM.Build.0 = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|ARM64.ActiveCfg = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|ARM64.Build.0 = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|x64.ActiveCfg = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|x64.Build.0 = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|x86.ActiveCfg = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Debug|x86.Build.0 = Debug|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|ARM.ActiveCfg = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|ARM.Build.0 = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|ARM64.ActiveCfg = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|ARM64.Build.0 = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|x64.ActiveCfg = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|x64.Build.0 = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|x86.ActiveCfg = Release|Any CPU | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C}.Release|x86.Build.0 = Release|Any CPU | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
@@ -1453,6 +1477,8 @@ Global | |||||
{28BE5235-2399-4EBA-B1F0-88E0F32AC869} = {7B0175AD-BB74-4A98-B9A7-1E289032485E} | {28BE5235-2399-4EBA-B1F0-88E0F32AC869} = {7B0175AD-BB74-4A98-B9A7-1E289032485E} | ||||
{5300552F-560D-474A-8D96-0A2747D08F64} = {7B0175AD-BB74-4A98-B9A7-1E289032485E} | {5300552F-560D-474A-8D96-0A2747D08F64} = {7B0175AD-BB74-4A98-B9A7-1E289032485E} | ||||
{B6213013-2A0E-41DD-BA9F-775D53C19374} = {5300552F-560D-474A-8D96-0A2747D08F64} | {B6213013-2A0E-41DD-BA9F-775D53C19374} = {5300552F-560D-474A-8D96-0A2747D08F64} | ||||
{309D579E-DDA8-4B01-A0AA-0F381BC37801} = {7B0175AD-BB74-4A98-B9A7-1E289032485E} | |||||
{1696D557-C908-4136-A5F2-FF59D69E642C} = {309D579E-DDA8-4B01-A0AA-0F381BC37801} | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(ExtensibilityGlobals) = postSolution | GlobalSection(ExtensibilityGlobals) = postSolution | ||||
SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC} | SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC} | ||||