更新 MotorModel 和 LectotypeViewModel 逻辑

在 `MotorModel.cs` 文件中,添加了一个新的私有字段 `_occPartId` 和对应的公共属性 `OccPartId`,并在属性设置时调用 `OnPropertyChanged` 方法。

在 `BaseAppExt.cs` 文件中,新增了一个静态类 `BaseAppExt`,包含一个静态方法 `GetApplication`,用于获取当前活动的 `BaseApp` 实例。

在 `LectotypeViewModel.cs` 文件中:
- 将变量 `doc` 重命名为 `designer`,并相应地修改了获取线材的代码。
- 添加了一个事件处理方法 `SelectSet_NodeSelected`,并在某个任务完成时订阅了 `designer.SelectSet.NodeSelected` 事件。
- 将 `ToMotorSource` 方法的参数 `motorName` 改为 `motorId`,并修改了获取部件和电缆的逻辑。
- 创建 `MotorModel` 实例时,新增了对 `OccPartId` 属性的赋值。
This commit is contained in:
lihanbo 2024-11-19 11:56:06 +08:00
parent 0acb2f7bb4
commit 04045b01e3
3 changed files with 42 additions and 5 deletions

View File

@ -81,5 +81,19 @@
OnPropertyChanged(nameof(AxisNo));
}
}
private string _occPartId;
/// <summary>
/// 部件ID
/// </summary>
public string OccPartId
{
get => _occPartId;
set
{
_occPartId = value;
OnPropertyChanged(nameof(OccPartId));
}
}
}
}

View File

@ -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;
}
}
}

View File

@ -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<BaseOccurrence> 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<BaseOccurrence>.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<BaseOccurrence>.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)