From 04045b01e367d868b0fc55a3bf7e7ffa93e02e88 Mon Sep 17 00:00:00 2001 From: lihanbo Date: Tue, 19 Nov 2024 11:56:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20MotorModel=20=E5=92=8C=20L?= =?UTF-8?q?ectotypeViewModel=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `MotorModel.cs` 文件中,添加了一个新的私有字段 `_occPartId` 和对应的公共属性 `OccPartId`,并在属性设置时调用 `OnPropertyChanged` 方法。 在 `BaseAppExt.cs` 文件中,新增了一个静态类 `BaseAppExt`,包含一个静态方法 `GetApplication`,用于获取当前活动的 `BaseApp` 实例。 在 `LectotypeViewModel.cs` 文件中: - 将变量 `doc` 重命名为 `designer`,并相应地修改了获取线材的代码。 - 添加了一个事件处理方法 `SelectSet_NodeSelected`,并在某个任务完成时订阅了 `designer.SelectSet.NodeSelected` 事件。 - 将 `ToMotorSource` 方法的参数 `motorName` 改为 `motorId`,并修改了获取部件和电缆的逻辑。 - 创建 `MotorModel` 实例时,新增了对 `OccPartId` 属性的赋值。 --- .../Models/MotorModel.cs | 14 +++++++++++++ .../Utils/BaseAppExt.cs | 12 +++++++++++ .../ViewModel/LectotypeViewModel.cs | 21 ++++++++++++++----- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/Utils/BaseAppExt.cs diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs index dbd80fe..0829f69 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs @@ -81,5 +81,19 @@ OnPropertyChanged(nameof(AxisNo)); } } + + private string _occPartId; + /// + /// 部件ID + /// + public string OccPartId + { + get => _occPartId; + set + { + _occPartId = value; + OnPropertyChanged(nameof(OccPartId)); + } + } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/BaseAppExt.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/BaseAppExt.cs new file mode 100644 index 0000000..c5d13ab --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/BaseAppExt.cs @@ -0,0 +1,12 @@ +using EPLAN.Harness.AppCore; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +{ + public static class BaseAppExt + { + public static BaseApp GetApplication() + { + return BaseApp.ActiveApplication; + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs index 83a48b4..a23fc85 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs @@ -150,9 +150,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { return Task.CompletedTask; } - var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); + var designer = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); // 获取所有存在的 - var wires = doc.GetOrganizerOccurrences(doc.ID); + var wires = designer.GetOrganizerOccurrences(designer.ID); //OriWires = wires.ToList(); // 所有的线材 // OccCableForked 多芯线? 对应设计器中Cables(电缆)下的内容 @@ -200,8 +200,18 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel .OrderBy(it => it?.CableName ?? "")]; Wires = StuffData(cables); + designer.SelectSet.NodeSelected += SelectSet_NodeSelected; return Task.CompletedTask; } + + private void SelectSet_NodeSelected(object sender, EPLAN.Harness.Common.Events.EventArgs e) + { + if (e != null) + { + + } + } + public string GetLectotypeName(string libraryName) { if (libraryName.Contains("&")) @@ -462,12 +472,12 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel FlexMessageBox.Error(ex.Message); } } - public void ToMotorSource(string motorName, string cableName) + public void ToMotorSource(string motorId, string cableName) { try { var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); - var part = doc.GetOccurrenceByName(motorName, typeof(OccSubPart)); + var part = doc.GetOccurrenceByID(motorId); var cable = doc.GetOccurrenceByName(cableName, typeof(OccCableForked)); if (part != null) { @@ -475,7 +485,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel var oriOcc = SelfControler.FindInstance(part.ID); oriOcc.SetVisibility(true, null); doc.SelectSet.Add(oriOcc.Children.First()); - if (cable != null) + if (!string.IsNullOrEmpty(cableName) && cable != null) { var cableOcc = SelfControler.FindInstance(cable.ID); cableOcc.SetVisibility(true, null); @@ -510,6 +520,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { MotorModelStr = part.Name, AxisNo = axisNo, + OccPartId = part.ID, IsError = string.IsNullOrEmpty(axisNo) }; if (motorPowerData != null)