From bfb9d9b880f629696b59477a1a4d2e687083af6a Mon Sep 17 00:00:00 2001 From: lihanbo Date: Thu, 5 Dec 2024 14:37:31 +0800 Subject: [PATCH] 105040 Clear code --- .../ConnectionTypeConverter.cs | 8 ++- .../{Utils => Converter}/FlagEnumConverter.cs | 8 ++- .../{Utils => Converter}/NameTypeConverter.cs | 8 ++- .../{Utils => Enum}/ConnectionType.cs | 2 +- .../{Utils => Enum}/DataGridType.cs | 2 +- .../{Utils => Enum}/ExportFileNameType.cs | 2 +- .../{Utils => Enum}/WireFlagType.cs | 2 +- .../{Utils => Extension}/ApplicationExt.cs | 2 +- .../{Utils => Extension}/BaseAppExt.cs | 2 +- .../{Utils => Extension}/CheckedModelExt.cs | 2 +- .../{Utils => Extension}/PropertyListExt.cs | 2 +- .../LectotypeLengthDataTemplateSelector.cs | 2 +- .../Sinvo.EplanHpD.Plugin.WPFUI.csproj | 24 ++++---- .../Utils/LectotypeManager.cs | 1 - .../View/CableLectotypeWindow.xaml | 9 +-- .../View/LayoutHelperWindow.xaml.cs | 56 ++++++++++++++++++- .../View/LectotypeWindow.xaml | 30 +++++----- .../View/LectotypeWindow.xaml.cs | 54 ++---------------- .../View/MainWindow.xaml | 18 +++--- .../View/MainWindow.xaml.cs | 2 + .../ViewModel/CableLectotypeViewModel.cs | 1 + .../ViewModel/LectotypeViewModel.cs | 1 + .../ViewModel/MainViewModel.Check.cs | 3 +- .../ViewModel/MainViewModel.cs | 9 +-- 24 files changed, 134 insertions(+), 116 deletions(-) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Converter}/ConnectionTypeConverter.cs (80%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Converter}/FlagEnumConverter.cs (77%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Converter}/NameTypeConverter.cs (77%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Enum}/ConnectionType.cs (87%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Enum}/DataGridType.cs (62%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Enum}/ExportFileNameType.cs (87%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Enum}/WireFlagType.cs (84%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Extension}/ApplicationExt.cs (95%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Extension}/BaseAppExt.cs (80%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Extension}/CheckedModelExt.cs (90%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Extension}/PropertyListExt.cs (90%) rename Sinvo.EplanHpD.Plugin.WPFUI/{Utils => Selector}/LectotypeLengthDataTemplateSelector.cs (97%) diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionTypeConverter.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Converter/ConnectionTypeConverter.cs similarity index 80% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionTypeConverter.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Converter/ConnectionTypeConverter.cs index 340e613..33a209e 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionTypeConverter.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Converter/ConnectionTypeConverter.cs @@ -1,4 +1,6 @@ -using System; +using EPLAN.Harness.Core.Platform; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -6,14 +8,14 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Data; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Converter { public class ConnectionTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var flag = (ConnectionType)value; - if (!Enum.IsDefined(typeof(ConnectionType), flag)) + if (!System.Enum.IsDefined(typeof(ConnectionType), flag)) { return false; } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/FlagEnumConverter.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Converter/FlagEnumConverter.cs similarity index 77% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/FlagEnumConverter.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Converter/FlagEnumConverter.cs index 0f1ff65..bca7cb7 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/FlagEnumConverter.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Converter/FlagEnumConverter.cs @@ -1,15 +1,17 @@ -using System; +using Sinvo.EplanHpD.Plugin.WPFUI.Enum; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; +using System; using System.Globalization; using System.Windows.Data; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Converter { public class FlagEnumConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var flag = (WireFlagType)value; - if (!Enum.IsDefined(typeof(WireFlagType), flag)) + if (!System.Enum.IsDefined(typeof(WireFlagType), flag)) { return false; } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/NameTypeConverter.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Converter/NameTypeConverter.cs similarity index 77% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/NameTypeConverter.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Converter/NameTypeConverter.cs index deb91e7..d02a94f 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/NameTypeConverter.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Converter/NameTypeConverter.cs @@ -1,15 +1,17 @@ -using System; +using Sinvo.EplanHpD.Plugin.WPFUI.Enum; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; +using System; using System.Globalization; using System.Windows.Data; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Converter { public class NameTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var flag = (ExportFileNameType)value; - if (!Enum.IsDefined(typeof(ExportFileNameType), flag)) + if (!System.Enum.IsDefined(typeof(ExportFileNameType), flag)) { return false; } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionType.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Enum/ConnectionType.cs similarity index 87% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionType.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Enum/ConnectionType.cs index 8a03677..6336cb6 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionType.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Enum/ConnectionType.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Enum { public enum ConnectionType { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/DataGridType.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Enum/DataGridType.cs similarity index 62% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/DataGridType.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Enum/DataGridType.cs index 3be5b60..8740b2e 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/DataGridType.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Enum/DataGridType.cs @@ -1,4 +1,4 @@ -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Enum { public enum DataGridType { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExportFileNameType.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Enum/ExportFileNameType.cs similarity index 87% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExportFileNameType.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Enum/ExportFileNameType.cs index 191e63a..537bcdd 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ExportFileNameType.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Enum/ExportFileNameType.cs @@ -1,4 +1,4 @@ -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Enum { public enum ExportFileNameType { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/WireFlagType.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Enum/WireFlagType.cs similarity index 84% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/WireFlagType.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Enum/WireFlagType.cs index 1142b90..d5f645e 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/WireFlagType.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Enum/WireFlagType.cs @@ -1,6 +1,6 @@ using System.ComponentModel; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Enum { public enum WireFlagType { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ApplicationExt.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/ApplicationExt.cs similarity index 95% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/ApplicationExt.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Extension/ApplicationExt.cs index 5f29bde..db818fb 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ApplicationExt.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/ApplicationExt.cs @@ -1,7 +1,7 @@ using System; using System.Windows; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Extension { public static class ApplicationExt { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/BaseAppExt.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/BaseAppExt.cs similarity index 80% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/BaseAppExt.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Extension/BaseAppExt.cs index c5d13ab..03b87a2 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/BaseAppExt.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/BaseAppExt.cs @@ -1,6 +1,6 @@ using EPLAN.Harness.AppCore; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Extension { public static class BaseAppExt { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/CheckedModelExt.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/CheckedModelExt.cs similarity index 90% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/CheckedModelExt.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Extension/CheckedModelExt.cs index ee0573b..f4d16ed 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/CheckedModelExt.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/CheckedModelExt.cs @@ -1,6 +1,6 @@ using Sinvo.EplanHpD.Plugin.WPFUI.Models; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Extension { public static class CheckedModelExt { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/PropertyListExt.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/PropertyListExt.cs similarity index 90% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/PropertyListExt.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Extension/PropertyListExt.cs index c21944c..249adc3 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/PropertyListExt.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Extension/PropertyListExt.cs @@ -1,7 +1,7 @@ using EPLAN.Harness.Core.Props.Collections; using System.Linq; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Extension { public static class PropertyListExt { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeLengthDataTemplateSelector.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Selector/LectotypeLengthDataTemplateSelector.cs similarity index 97% rename from Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeLengthDataTemplateSelector.cs rename to Sinvo.EplanHpD.Plugin.WPFUI/Selector/LectotypeLengthDataTemplateSelector.cs index e8d73b9..23ee774 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeLengthDataTemplateSelector.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Selector/LectotypeLengthDataTemplateSelector.cs @@ -3,7 +3,7 @@ using System.Reflection; using System.Windows; using System.Windows.Controls; -namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +namespace Sinvo.EplanHpD.Plugin.WPFUI.Selector { internal class LectotypeLengthDataTemplateSelector : DataTemplateSelector { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj index 21da661..426b720 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj @@ -136,6 +136,17 @@ + + + + + + + + + + + @@ -150,28 +161,17 @@ + TestWindow.xaml - - - - - - - - - - - - diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs index 3e43c8d..54fc1e9 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/LectotypeManager.cs @@ -14,7 +14,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils { public static class LectotypeManager { - public static MotorModel Motor; public class LectotypeViewModelFactory diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml index 9f8aee4..1eabdfc 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/CableLectotypeWindow.xaml @@ -2,11 +2,12 @@ x:Class="Sinvo.EplanHpD.Plugin.WPFUI.View.CableLectotypeWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:converter="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:enum="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Enum" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:util="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Utils" xmlns:viewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel" Height="750" d:DataContext="{d:DesignInstance Type=viewmodel:CableLectotypeViewModel}" @@ -19,7 +20,7 @@ - + @@ -102,8 +103,8 @@ VerticalAlignment="Center" Text="线材链接方式:" /> - - + + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs index abe47b2..d2ffa47 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs @@ -1,5 +1,10 @@ -using System; +using EPLAN.Harness.API; +using EPLAN.Harness.Core.Controls; +using EPLAN.Harness.ProjectCore; +using EPLAN.Harness.ProjectCore.Occurrences.Designer; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -17,11 +22,58 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View /// /// LayoutHelperWindow.xaml 的交互逻辑 /// - public partial class LayoutHelperWindow : Window + public partial class LayoutHelperWindow { + private FlexDesigner _currentFlexDesigner; public LayoutHelperWindow() { InitializeComponent(); + OnInit(); + } + private void OnInit() + { + GetCurrentDoc(); + _currentFlexDesigner.SelectSet.SelectionChanged += SelectSet_SelectionChanged; + + } + + private void SelectSet_SelectionChanged(object sender, EventArgs e) + { + if (sender is OccSelectSet selectSet) + { + var item = selectSet.SelectedItem; + if (item is OccSubPart part) + { + Debug.WriteLine($"Select part -> {part.Name} / {part.ID}"); + if (part.Parents != null) + { + Debug.WriteLine($"Select part parent -> {part.Parents.First()?.Name} / {part.Parents.First()?.ID}"); + } + } + } + } + + public void GetCurrentDoc() + { + try + { + HpdApi api = HpdApi.GetInstance(); + var currentDocId = api.CurrentProject.GetActiveDocument()?.ID; + var designer = SelfControler.FindInstance(currentDocId) as FlexDesigner; + if (designer != null) + { + _currentFlexDesigner = designer; + } + else + { + FlexMessageBox.Warning("未找到当前打开的工作区,请先打开工作区"); + } + } + catch (Exception ex) + { + FlexMessageBox.Error(ex.Message); + } } } + } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml index 4c3da21..026b0f1 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml @@ -7,6 +7,7 @@ xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pdf="clr-namespace:PdfiumViewer;assembly=PdfiumViewer" + xmlns:selecter="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Selector" xmlns:util="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Utils" xmlns:view="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View" xmlns:viewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel" @@ -66,28 +67,28 @@ - - + + - - + + - - + + - - + + - - + + -