diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Common/CommonMessage.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Common/CommonMessage.cs new file mode 100644 index 0000000..24f3848 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Common/CommonMessage.cs @@ -0,0 +1,16 @@ +using CommunityToolkit.Mvvm.Messaging.Messages; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Common +{ + public class CommonMessage : ValueChangedMessage + { + public CommonMessage(int value) : base(value) + { + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/ScanCableModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/ScanCableModel.cs new file mode 100644 index 0000000..0c633cc --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/ScanCableModel.cs @@ -0,0 +1,55 @@ +using EPLAN.Harness.Core.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Models +{ + public class ScanCableModel : CheckedModel + { + private int _index; + public int Index + { + get => _index; set + { + _index = value; + OnPropertyChanged(nameof(Index)); + } + } + + private string _name; + + public string Name + { + get => _name; set + { + _name = value; + OnPropertyChanged(nameof(Name)); + } + } + + private string _code; + public string Code + { + get => _code; + set + { + _code = value; + OnPropertyChanged(nameof(Code)); + } + } + private string _imprint; + public string Imprint + { + get => _imprint; + set + { + _imprint = value; + OnPropertyChanged(nameof(Imprint)); + } + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj index 2103e6f..19470f4 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj @@ -135,6 +135,7 @@ + @@ -146,6 +147,7 @@ + @@ -164,6 +166,8 @@ + + @@ -172,6 +176,7 @@ + CableLectotypeWindow.xaml @@ -181,6 +186,9 @@ MainWindow.xaml + + ScannerWindow.xaml + Designer MSBuild:Compile @@ -201,6 +209,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + @@ -235,6 +247,9 @@ + + 8.4.0-preview3 + 3.5.1 @@ -252,7 +267,6 @@ - \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/TestWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/TestWindow.xaml.cs index 9f2f585..0d15547 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/TestWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/TestWindow.xaml.cs @@ -40,13 +40,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI [STAThread] public static void Main() { - var window = new CableLectotypeWindow(new Models.MotorModel - { - AxisNo = "MRJ001", - MotorPower = "1000W(220V)", - MotorModelStr = "HK-KT103WJK", - MotorSerie = "HK-KT" - }); + //var window = new CableLectotypeWindow(new Models.MotorModel + //{ + // AxisNo = "MRJ001", + // MotorPower = "1000W(220V)", + // MotorModelStr = "HK-KT103WJK", + // MotorSerie = "HK-KT" + //}); + //window.ShowDialog(); + + var window = new ScannerWindow(); window.ShowDialog(); } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs new file mode 100644 index 0000000..2576969 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs @@ -0,0 +1,53 @@ +using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Markup; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +{ + public static class LectotypeManager + { + public static MotorModel Motor; + + + public class LectotypeViewModelFactory + { + private static readonly IDictionary _motorViewModel = new Dictionary(); + + public static CableLectotypeViewModel CreateOrGet(MotorModel motor) + { + if (motor == null || string.IsNullOrEmpty(motor.OccPartId)) + { + Debug.WriteLine($"CreateOrGet Create for null-> {motor?.MotorModelStr} => {motor?.OccPartId}"); + + return new CableLectotypeViewModel(new MotorModel()); + } + if (_motorViewModel.ContainsKey(motor.OccPartId)) + { + Debug.WriteLine($"CreateOrGet Get -> {motor.MotorModelStr} => {motor.OccPartId}"); + return _motorViewModel[motor.OccPartId]; + } + else + { + var viewModel = new CableLectotypeViewModel(motor); + _motorViewModel.Add(motor.OccPartId, viewModel); + Debug.WriteLine($"CreateOrGet Create -> {motor.MotorModelStr} => {motor.OccPartId}"); + return viewModel; + } + } + + public static void Register(MotorModel motor, CableLectotypeViewModel viewModel) + { + if (!_motorViewModel.ContainsKey(motor.OccPartId)) + { + _motorViewModel.Add(motor.OccPartId, viewModel); + } + } + } + } +} \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MessageSend.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MessageSend.cs new file mode 100644 index 0000000..27aedb6 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MessageSend.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +{ + /// + /// 消息发送与接收 + /// + public class MessageSend + { + private static readonly Dictionary>> _subscribers = new(); + + public static void Subscribe(string message, Action callback) + { + if (!_subscribers.ContainsKey(message)) + { + _subscribers[message] = new List>(); + } + _subscribers[message].Add(callback); + } + + public static void Unsubscribe(string message, Action callback) + { + if (_subscribers.ContainsKey(message)) + { + _subscribers[message].Remove(callback); + if (_subscribers[message].Count == 0) + { + _subscribers.Remove(message); + } + } + } + + public static void Publish(string message, object parameter = null) + { + if (_subscribers.ContainsKey(message)) + { + foreach (var callback in _subscribers[message]) + { + callback(parameter); + } + } + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml index e1acc3e..2f5d25a 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml @@ -1,4 +1,4 @@ - - + + + + + + + - + @@ -44,7 +56,16 @@ VerticalAlignment="Top" Panel.ZIndex="99" /> + - + + Text="{Binding OccPartId}" /> - + + Text="{Binding MotorModelStr}" /> + Text="{Binding MotorPower}" /> - + +