EPLAN_PROD_Plugin/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/ScannerViewModel.cs

581 lines
18 KiB
C#
Raw Normal View History

2024-12-02 09:28:54 +08:00
using CommunityToolkit.Mvvm.Messaging;
using EPLAN.Harness.API;
using EPLAN.Harness.AppCore.StudioCommon.TreeView;
using EPLAN.Harness.Common;
2024-12-02 09:28:54 +08:00
using EPLAN.Harness.Core.Controls;
using EPLAN.Harness.Core.Extensions;
using EPLAN.Harness.Core.LibEntities;
2024-12-02 09:28:54 +08:00
using EPLAN.Harness.Primitives.Treeviews;
using EPLAN.Harness.ProjectCore;
using EPLAN.Harness.ProjectCore.Occurrences;
2024-12-02 09:28:54 +08:00
using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using HandyControl.Tools.Extension;
2024-12-02 09:28:54 +08:00
using Sinvo.EplanHpD.Plugin.WPFUI.Common;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
2024-12-02 09:28:54 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{
public class ScannerViewModel : INotifyPropertyChanged, INotifyDataErrorInfo
{
private FlexDesigner _currentFlexDesigner;
private bool _othersWireShow = true;
private bool _continueScan = true;
private bool _enableEvent = true;
private bool _isIncludeAnnotation = true;
private bool _scanAndAssembled = true;
private int _scanedIndex = 1;
public int ScanedIndex
{
get => _scanedIndex;
set
{
_scanedIndex = value;
OnPropertyChanged(nameof(ScanedIndex));
WeakReferenceMessenger.Default.Send(new CommonMessage(value), "ScanedIndexChanged");
}
}
private string _inputCode;
public string InputCode
{
get => _inputCode;
set
{
if (_inputCode != value)
{
_inputCode = value;
OnPropertyChanged(nameof(InputCode));
if (_enableEvent)
{
2025-01-20 15:55:43 +08:00
// 扫描输入框防抖,延迟一秒后触发
// 由于扫描枪不一定有发送回车事件,所以需要自动进行触发
2024-12-02 09:28:54 +08:00
if (_debounceTimer == null)
{
_debounceTimer = new DispatcherTimer();
_debounceTimer.Interval = TimeSpan.FromMilliseconds(1000);
_debounceTimer.Tick += DebounceTimer_Tick;
}
_debounceTimer.Stop();
_debounceTimer.Start();
}
}
}
}
public ObservableCollection<ScanCableModel> ScanCableModels { get; set; } = [];
public ObservableCollection<ScanCableModel> _ScanCableModels
{
get => ScanCableModels;
set
{
if (ScanCableModels != value)
{
ScanCableModels = value;
OnPropertyChanged(nameof(_ScanCableModels));
}
}
}
#region
private string _S_part;
public string S_part
{
get => _S_part;
set
{
_S_part = value;
OnPropertyChanged(nameof(S_part));
}
}
private string _E_part;
public string E_part
{
get => _E_part;
set
{
_E_part = value;
OnPropertyChanged(nameof(E_part));
}
}
private string _S_pin;
public string S_pin
{
get => _S_pin;
set
{
_S_pin = value;
OnPropertyChanged(nameof(S_pin));
}
}
private string _E_pin;
public string E_pin
{
get => _E_pin;
set
{
_E_pin = value;
OnPropertyChanged(nameof(E_pin));
}
}
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 _Length;
public string Length
{
get => _Length;
set
{
_Length = value;
OnPropertyChanged(nameof(Length));
}
}
private string _Imprint;
public string Imprint
{
get => _Imprint;
set
{
_Imprint = value;
OnPropertyChanged(nameof(Imprint));
}
}
#endregion
2025-01-20 15:55:43 +08:00
private DispatcherTimer _debounceTimer;
2024-12-02 09:28:54 +08:00
public ScannerViewModel()
{
}
2024-12-02 09:28:54 +08:00
public void GetAllCables()
{
ScanCableModels.Clear();
string s_pinid = "";
string e_pinid = "";
2024-12-02 09:28:54 +08:00
_currentFlexDesigner.GetOrganizerOccurrences().ToList().ForEach(occ =>
{
if (occ is OccWire wire)
{
if (wire.Name.StartsWith("w_", StringComparison.OrdinalIgnoreCase))
{
//获取线两端管脚id,id唯一
var wire_pin = wire.DBG_GetPins.Split(';');
if (wire_pin.Length != 0)
{
s_pinid = wire_pin[0].Substring(1, 32);
e_pinid = wire_pin[1].Trim().Substring(1, 32);
}
//保存线材基础属性
2024-12-02 09:28:54 +08:00
ScanCableModels.Add(new ScanCableModel()
{
Index = ScanCableModels.Count + 1,
105040 优化与完善功能实现 重构和功能增强 删除了无用的注释和文件,添加了新的属性和方法,调整了窗口布局和视图模型引用。具体更改包括: - 删除 `MotorModel.cs` 中 `_motorPower` 的 `inheritdoc` 注释。 - `ScanCableModel.cs` 中添加 `Id` 属性及其私有字段 `_id`。 - 更新 `Sinvo.EplanHpD.Plugin.WPFUI.csproj`,删除 `Utils\DrawPDFHelper.cs` 和 `Utils\MessageSend.cs` 的编译引用,添加 `ViewModel\LayoutHelperViewModel.cs` 的编译引用,并添加 `KissStudio.DotNetDetour` 包的引用。 - 删除 `DrawPDFHelper.cs` 和 `MessageSend.cs` 文件内容。 - `LayoutHelperWindow.xaml` 中增加 `viewmodel` 命名空间引用,调整窗口高度和最小高度,设置 `d:DataContext`,并在窗口加载时调用 `GlowWindow_Loaded` 方法,修改部分 `TextBlock` 和 `ListView` 的内容绑定。 - `LayoutHelperWindow.xaml.cs` 中添加 `LayoutHelperViewModel` 的引用,并在构造函数中初始化 `viewModel`,设置 `DataContext`,在 `OnInit` 方法中调用 `GetMotorCables`,添加 `GlowWindow_Loaded`、`PrevBtn_Click` 和 `NextBtn_Click` 方法。 - `LectotypeWindow.xaml.cs` 中修改 `StartLayoutBtn_Click` 方法,传递 `motorIds` 给 `LayoutHelperWindow` 的构造函数。 - `ScannerViewModel.cs` 中添加 `Id` 属性的赋值,修改 `PerformSearch` 方法以根据 `Imprint` 进行搜索,添加 `ToSourceById` 方法用于根据 `occId` 定位线缆。 - 在 `DesignPluginEntry.cs`、`PluginEntry.cs` 和 `ScanPluginEntry.cs` 中添加 `Sinvo.EplanHpD.Plugin.WPFUI.Extension` 的引用。 - 新增 `LayoutHelperViewModel.cs` 文件,定义 `LayoutHelperViewModel` 类及其相关属性和方法,用于处理电机和线缆的选择和切换逻辑。
2024-12-10 17:02:58 +08:00
Id = wire.ID,
S_Pin = wire.ConnectedPinsUI.Substring(0, wire.ConnectedPinsUI.IndexOf("<>")),
E_Pin = wire.ConnectedPinsUI.Substring(wire.ConnectedPinsUI.IndexOf("<>") + 3, wire.ConnectedPinsUI.Length - wire.ConnectedPinsUI.IndexOf("<>") - 3),
S_pinID = s_pinid,
E_pinID = e_pinid,
2024-12-02 09:28:54 +08:00
Name = wire.LibraryName,
Length = Math.Ceiling(wire.Length_VH.GetValueInUnit(UNIT_CLASS.LENGTH)).ToString(),
2024-12-02 09:28:54 +08:00
Code = wire.Name,
Imprint = wire.Imprint
});
}
}
});
}
2025-01-20 15:55:43 +08:00
/// <summary>
/// scaninfo界面数据 和找到管脚上级部件
/// </summary>
/// <param name="scanCableModel"></param>
public void ToMotorSource(ScanCableModel scanCableModel)
{
try
{
S_pin = scanCableModel.E_Pin;
E_pin = scanCableModel.E_Pin;
S_part = scanCableModel.S_part;
Length = scanCableModel.Length;
Name = scanCableModel.Name;
Code = scanCableModel.Code;
Imprint = scanCableModel.Imprint;
_currentFlexDesigner.GetOrganizerOccurrences().ToList().ForEach(occ =>
{
//if (occ is OccConnector Assembly)
//{
//var Assembly = occ;
//根据管脚id获取上级部件信息
if (occ.ID.Equals(scanCableModel.S_pinID))
{
var oriOcc = SelfControler<BaseOccurrence>.FindInstance(occ.ID);
var parent = oriOcc.Parents?.FirstOrDefault();
var grandparent = parent.Parents?.FirstOrDefault();
scanCableModel.S_part = grandparent.Name;
S_part = scanCableModel.S_part;
}
if (occ.ID.Equals(scanCableModel.E_pinID))
{
var oriOcc = SelfControler<BaseOccurrence>.FindInstance(occ.ID);
var parent = oriOcc.Parents?.FirstOrDefault();
var grandparent = parent.Parents?.FirstOrDefault();
scanCableModel.E_part = grandparent.Name;
E_part = scanCableModel.E_part;
}
//}
}
);
2024-12-02 09:28:54 +08:00
}
catch (Exception ex)
{
FlexMessageBox.Error(ex.Message);
}
}
2025-01-20 17:03:35 +08:00
/// <summary>
2025-01-20 15:55:43 +08:00
/// 获取当前设计器
/// </summary>
2024-12-02 09:28:54 +08:00
public void GetCurrentDoc()
{
try
{
HpdApi api = HpdApi.GetInstance();
var currentDocId = api.CurrentProject.GetActiveDocument()?.ID;
var designer = SelfControler<FlexBaseOrganizer>.FindInstance(currentDocId) as FlexDesigner;
if (designer != null)
{
_currentFlexDesigner = designer;
}
else
{
FlexMessageBox.Warning("未找到当前打开的工作区,请先打开工作区");
}
}
catch (Exception ex)
{
FlexMessageBox.Error(ex.Message);
}
}
2024-12-02 09:28:54 +08:00
private void DebounceTimer_Tick(object sender, EventArgs e)
{
_debounceTimer.Stop();
string searchText = InputCode;
PerformSearch(searchText);
}
2025-01-20 15:55:43 +08:00
/// <summary>
/// 扫描条码(印记/名称)
/// </summary>
/// <param name="searchText"></param>
2024-12-02 09:28:54 +08:00
private void PerformSearch(string searchText)
{
// 清除错误信息
ClearErrors(nameof(InputCode));
105040 优化与完善功能实现 重构和功能增强 删除了无用的注释和文件,添加了新的属性和方法,调整了窗口布局和视图模型引用。具体更改包括: - 删除 `MotorModel.cs` 中 `_motorPower` 的 `inheritdoc` 注释。 - `ScanCableModel.cs` 中添加 `Id` 属性及其私有字段 `_id`。 - 更新 `Sinvo.EplanHpD.Plugin.WPFUI.csproj`,删除 `Utils\DrawPDFHelper.cs` 和 `Utils\MessageSend.cs` 的编译引用,添加 `ViewModel\LayoutHelperViewModel.cs` 的编译引用,并添加 `KissStudio.DotNetDetour` 包的引用。 - 删除 `DrawPDFHelper.cs` 和 `MessageSend.cs` 文件内容。 - `LayoutHelperWindow.xaml` 中增加 `viewmodel` 命名空间引用,调整窗口高度和最小高度,设置 `d:DataContext`,并在窗口加载时调用 `GlowWindow_Loaded` 方法,修改部分 `TextBlock` 和 `ListView` 的内容绑定。 - `LayoutHelperWindow.xaml.cs` 中添加 `LayoutHelperViewModel` 的引用,并在构造函数中初始化 `viewModel`,设置 `DataContext`,在 `OnInit` 方法中调用 `GetMotorCables`,添加 `GlowWindow_Loaded`、`PrevBtn_Click` 和 `NextBtn_Click` 方法。 - `LectotypeWindow.xaml.cs` 中修改 `StartLayoutBtn_Click` 方法,传递 `motorIds` 给 `LayoutHelperWindow` 的构造函数。 - `ScannerViewModel.cs` 中添加 `Id` 属性的赋值,修改 `PerformSearch` 方法以根据 `Imprint` 进行搜索,添加 `ToSourceById` 方法用于根据 `occId` 定位线缆。 - 在 `DesignPluginEntry.cs`、`PluginEntry.cs` 和 `ScanPluginEntry.cs` 中添加 `Sinvo.EplanHpD.Plugin.WPFUI.Extension` 的引用。 - 新增 `LayoutHelperViewModel.cs` 文件,定义 `LayoutHelperViewModel` 类及其相关属性和方法,用于处理电机和线缆的选择和切换逻辑。
2024-12-10 17:02:58 +08:00
var cable = ScanCableModels.FirstOrDefault(c => c.Code.Equals(searchText, StringComparison.OrdinalIgnoreCase) || c.Imprint.StartsWith(searchText, StringComparison.OrdinalIgnoreCase));
2024-12-02 09:28:54 +08:00
if (cable != null)
{
2025-01-20 15:55:43 +08:00
// 处理其他线是否隐藏
2024-12-02 09:28:54 +08:00
OthersOccShow(!OthersWireShow);
if (_continueScan)
{
2025-01-20 15:55:43 +08:00
// 清空输入框
2024-12-02 09:28:54 +08:00
_enableEvent = false;
InputCode = string.Empty;
_enableEvent = true;
}
2025-01-20 15:55:43 +08:00
// 扫描即装配
2024-12-02 09:28:54 +08:00
if (ScanAndAssembled)
{
//cable.IsChecked = true;
ScanCableModel scanCableModel = new ScanCableModel();
scanCableModel = cable;
_ScanCableModels.Remove(cable);
_ScanCableModels.Insert(0, scanCableModel);
_ScanCableModels.FirstOrDefault().IsChecked = true;
ToMotorSource(scanCableModel);
2024-12-02 09:28:54 +08:00
}
ScanedIndex = 0;//Math.Max(cable.Index - 1, 0);
105040 优化与完善功能实现 重构和功能增强 删除了无用的注释和文件,添加了新的属性和方法,调整了窗口布局和视图模型引用。具体更改包括: - 删除 `MotorModel.cs` 中 `_motorPower` 的 `inheritdoc` 注释。 - `ScanCableModel.cs` 中添加 `Id` 属性及其私有字段 `_id`。 - 更新 `Sinvo.EplanHpD.Plugin.WPFUI.csproj`,删除 `Utils\DrawPDFHelper.cs` 和 `Utils\MessageSend.cs` 的编译引用,添加 `ViewModel\LayoutHelperViewModel.cs` 的编译引用,并添加 `KissStudio.DotNetDetour` 包的引用。 - 删除 `DrawPDFHelper.cs` 和 `MessageSend.cs` 文件内容。 - `LayoutHelperWindow.xaml` 中增加 `viewmodel` 命名空间引用,调整窗口高度和最小高度,设置 `d:DataContext`,并在窗口加载时调用 `GlowWindow_Loaded` 方法,修改部分 `TextBlock` 和 `ListView` 的内容绑定。 - `LayoutHelperWindow.xaml.cs` 中添加 `LayoutHelperViewModel` 的引用,并在构造函数中初始化 `viewModel`,设置 `DataContext`,在 `OnInit` 方法中调用 `GetMotorCables`,添加 `GlowWindow_Loaded`、`PrevBtn_Click` 和 `NextBtn_Click` 方法。 - `LectotypeWindow.xaml.cs` 中修改 `StartLayoutBtn_Click` 方法,传递 `motorIds` 给 `LayoutHelperWindow` 的构造函数。 - `ScannerViewModel.cs` 中添加 `Id` 属性的赋值,修改 `PerformSearch` 方法以根据 `Imprint` 进行搜索,添加 `ToSourceById` 方法用于根据 `occId` 定位线缆。 - 在 `DesignPluginEntry.cs`、`PluginEntry.cs` 和 `ScanPluginEntry.cs` 中添加 `Sinvo.EplanHpD.Plugin.WPFUI.Extension` 的引用。 - 新增 `LayoutHelperViewModel.cs` 文件,定义 `LayoutHelperViewModel` 类及其相关属性和方法,用于处理电机和线缆的选择和切换逻辑。
2024-12-10 17:02:58 +08:00
ToSourceById(cable.Id);
2024-12-02 09:28:54 +08:00
}
else
{
// 添加错误信息
AddError(nameof(InputCode), "该条码不存在于列表中");
}
}
private void ToSourceByName(string wireName)
{
var occWire = _currentFlexDesigner.GetOccurrenceByName(wireName, typeof(OccWire));
if (occWire != null)
{
occWire.SetVisibility(true, null);
_currentFlexDesigner.SelectSet.Clear();
105040 优化与完善功能实现 重构和功能增强 删除了无用的注释和文件,添加了新的属性和方法,调整了窗口布局和视图模型引用。具体更改包括: - 删除 `MotorModel.cs` 中 `_motorPower` 的 `inheritdoc` 注释。 - `ScanCableModel.cs` 中添加 `Id` 属性及其私有字段 `_id`。 - 更新 `Sinvo.EplanHpD.Plugin.WPFUI.csproj`,删除 `Utils\DrawPDFHelper.cs` 和 `Utils\MessageSend.cs` 的编译引用,添加 `ViewModel\LayoutHelperViewModel.cs` 的编译引用,并添加 `KissStudio.DotNetDetour` 包的引用。 - 删除 `DrawPDFHelper.cs` 和 `MessageSend.cs` 文件内容。 - `LayoutHelperWindow.xaml` 中增加 `viewmodel` 命名空间引用,调整窗口高度和最小高度,设置 `d:DataContext`,并在窗口加载时调用 `GlowWindow_Loaded` 方法,修改部分 `TextBlock` 和 `ListView` 的内容绑定。 - `LayoutHelperWindow.xaml.cs` 中添加 `LayoutHelperViewModel` 的引用,并在构造函数中初始化 `viewModel`,设置 `DataContext`,在 `OnInit` 方法中调用 `GetMotorCables`,添加 `GlowWindow_Loaded`、`PrevBtn_Click` 和 `NextBtn_Click` 方法。 - `LectotypeWindow.xaml.cs` 中修改 `StartLayoutBtn_Click` 方法,传递 `motorIds` 给 `LayoutHelperWindow` 的构造函数。 - `ScannerViewModel.cs` 中添加 `Id` 属性的赋值,修改 `PerformSearch` 方法以根据 `Imprint` 进行搜索,添加 `ToSourceById` 方法用于根据 `occId` 定位线缆。 - 在 `DesignPluginEntry.cs`、`PluginEntry.cs` 和 `ScanPluginEntry.cs` 中添加 `Sinvo.EplanHpD.Plugin.WPFUI.Extension` 的引用。 - 新增 `LayoutHelperViewModel.cs` 文件,定义 `LayoutHelperViewModel` 类及其相关属性和方法,用于处理电机和线缆的选择和切换逻辑。
2024-12-10 17:02:58 +08:00
_currentFlexDesigner.SelectSet.Add(occWire);
_currentFlexDesigner.FitToSelectSet();
_currentFlexDesigner.SelectSet.OnSelectionChanged();
//_currentFlexDesigner.Camera.GraphicControl._HighlightNode()
/*
List<DatTreeNodeEx<BaseOccurrence>> nodeByEntity = this._occTreeView.GetNodeByEntity(baseOccurrence);
if (nodeByEntity != null)
{
foreach (DatTreeNodeEx<BaseOccurrence> datTreeNodeEx in nodeByEntity)
{
if (!this._occTreeView.SelectedNodes.Contains(datTreeNodeEx))
{
this._occTreeView.SelectedNodes.Add(datTreeNodeEx);
}
}
}
*/
}
}
2025-01-20 15:55:43 +08:00
/// <summary>
/// 将设计器聚焦到对应的线
/// </summary>
/// <param name="occId"></param>
105040 优化与完善功能实现 重构和功能增强 删除了无用的注释和文件,添加了新的属性和方法,调整了窗口布局和视图模型引用。具体更改包括: - 删除 `MotorModel.cs` 中 `_motorPower` 的 `inheritdoc` 注释。 - `ScanCableModel.cs` 中添加 `Id` 属性及其私有字段 `_id`。 - 更新 `Sinvo.EplanHpD.Plugin.WPFUI.csproj`,删除 `Utils\DrawPDFHelper.cs` 和 `Utils\MessageSend.cs` 的编译引用,添加 `ViewModel\LayoutHelperViewModel.cs` 的编译引用,并添加 `KissStudio.DotNetDetour` 包的引用。 - 删除 `DrawPDFHelper.cs` 和 `MessageSend.cs` 文件内容。 - `LayoutHelperWindow.xaml` 中增加 `viewmodel` 命名空间引用,调整窗口高度和最小高度,设置 `d:DataContext`,并在窗口加载时调用 `GlowWindow_Loaded` 方法,修改部分 `TextBlock` 和 `ListView` 的内容绑定。 - `LayoutHelperWindow.xaml.cs` 中添加 `LayoutHelperViewModel` 的引用,并在构造函数中初始化 `viewModel`,设置 `DataContext`,在 `OnInit` 方法中调用 `GetMotorCables`,添加 `GlowWindow_Loaded`、`PrevBtn_Click` 和 `NextBtn_Click` 方法。 - `LectotypeWindow.xaml.cs` 中修改 `StartLayoutBtn_Click` 方法,传递 `motorIds` 给 `LayoutHelperWindow` 的构造函数。 - `ScannerViewModel.cs` 中添加 `Id` 属性的赋值,修改 `PerformSearch` 方法以根据 `Imprint` 进行搜索,添加 `ToSourceById` 方法用于根据 `occId` 定位线缆。 - 在 `DesignPluginEntry.cs`、`PluginEntry.cs` 和 `ScanPluginEntry.cs` 中添加 `Sinvo.EplanHpD.Plugin.WPFUI.Extension` 的引用。 - 新增 `LayoutHelperViewModel.cs` 文件,定义 `LayoutHelperViewModel` 类及其相关属性和方法,用于处理电机和线缆的选择和切换逻辑。
2024-12-10 17:02:58 +08:00
private void ToSourceById(string occId)
{
2025-01-20 15:55:43 +08:00
// 从设计器中获取线实例
105040 优化与完善功能实现 重构和功能增强 删除了无用的注释和文件,添加了新的属性和方法,调整了窗口布局和视图模型引用。具体更改包括: - 删除 `MotorModel.cs` 中 `_motorPower` 的 `inheritdoc` 注释。 - `ScanCableModel.cs` 中添加 `Id` 属性及其私有字段 `_id`。 - 更新 `Sinvo.EplanHpD.Plugin.WPFUI.csproj`,删除 `Utils\DrawPDFHelper.cs` 和 `Utils\MessageSend.cs` 的编译引用,添加 `ViewModel\LayoutHelperViewModel.cs` 的编译引用,并添加 `KissStudio.DotNetDetour` 包的引用。 - 删除 `DrawPDFHelper.cs` 和 `MessageSend.cs` 文件内容。 - `LayoutHelperWindow.xaml` 中增加 `viewmodel` 命名空间引用,调整窗口高度和最小高度,设置 `d:DataContext`,并在窗口加载时调用 `GlowWindow_Loaded` 方法,修改部分 `TextBlock` 和 `ListView` 的内容绑定。 - `LayoutHelperWindow.xaml.cs` 中添加 `LayoutHelperViewModel` 的引用,并在构造函数中初始化 `viewModel`,设置 `DataContext`,在 `OnInit` 方法中调用 `GetMotorCables`,添加 `GlowWindow_Loaded`、`PrevBtn_Click` 和 `NextBtn_Click` 方法。 - `LectotypeWindow.xaml.cs` 中修改 `StartLayoutBtn_Click` 方法,传递 `motorIds` 给 `LayoutHelperWindow` 的构造函数。 - `ScannerViewModel.cs` 中添加 `Id` 属性的赋值,修改 `PerformSearch` 方法以根据 `Imprint` 进行搜索,添加 `ToSourceById` 方法用于根据 `occId` 定位线缆。 - 在 `DesignPluginEntry.cs`、`PluginEntry.cs` 和 `ScanPluginEntry.cs` 中添加 `Sinvo.EplanHpD.Plugin.WPFUI.Extension` 的引用。 - 新增 `LayoutHelperViewModel.cs` 文件,定义 `LayoutHelperViewModel` 类及其相关属性和方法,用于处理电机和线缆的选择和切换逻辑。
2024-12-10 17:02:58 +08:00
var occWire = _currentFlexDesigner.GetOccurrenceByID(occId);
if (occWire != null)
{
2025-01-20 15:55:43 +08:00
// 设置线显示
105040 优化与完善功能实现 重构和功能增强 删除了无用的注释和文件,添加了新的属性和方法,调整了窗口布局和视图模型引用。具体更改包括: - 删除 `MotorModel.cs` 中 `_motorPower` 的 `inheritdoc` 注释。 - `ScanCableModel.cs` 中添加 `Id` 属性及其私有字段 `_id`。 - 更新 `Sinvo.EplanHpD.Plugin.WPFUI.csproj`,删除 `Utils\DrawPDFHelper.cs` 和 `Utils\MessageSend.cs` 的编译引用,添加 `ViewModel\LayoutHelperViewModel.cs` 的编译引用,并添加 `KissStudio.DotNetDetour` 包的引用。 - 删除 `DrawPDFHelper.cs` 和 `MessageSend.cs` 文件内容。 - `LayoutHelperWindow.xaml` 中增加 `viewmodel` 命名空间引用,调整窗口高度和最小高度,设置 `d:DataContext`,并在窗口加载时调用 `GlowWindow_Loaded` 方法,修改部分 `TextBlock` 和 `ListView` 的内容绑定。 - `LayoutHelperWindow.xaml.cs` 中添加 `LayoutHelperViewModel` 的引用,并在构造函数中初始化 `viewModel`,设置 `DataContext`,在 `OnInit` 方法中调用 `GetMotorCables`,添加 `GlowWindow_Loaded`、`PrevBtn_Click` 和 `NextBtn_Click` 方法。 - `LectotypeWindow.xaml.cs` 中修改 `StartLayoutBtn_Click` 方法,传递 `motorIds` 给 `LayoutHelperWindow` 的构造函数。 - `ScannerViewModel.cs` 中添加 `Id` 属性的赋值,修改 `PerformSearch` 方法以根据 `Imprint` 进行搜索,添加 `ToSourceById` 方法用于根据 `occId` 定位线缆。 - 在 `DesignPluginEntry.cs`、`PluginEntry.cs` 和 `ScanPluginEntry.cs` 中添加 `Sinvo.EplanHpD.Plugin.WPFUI.Extension` 的引用。 - 新增 `LayoutHelperViewModel.cs` 文件,定义 `LayoutHelperViewModel` 类及其相关属性和方法,用于处理电机和线缆的选择和切换逻辑。
2024-12-10 17:02:58 +08:00
occWire.SetVisibility(true, null);
2025-01-20 15:55:43 +08:00
// 清空已选择项并加入当前线
105040 优化与完善功能实现 重构和功能增强 删除了无用的注释和文件,添加了新的属性和方法,调整了窗口布局和视图模型引用。具体更改包括: - 删除 `MotorModel.cs` 中 `_motorPower` 的 `inheritdoc` 注释。 - `ScanCableModel.cs` 中添加 `Id` 属性及其私有字段 `_id`。 - 更新 `Sinvo.EplanHpD.Plugin.WPFUI.csproj`,删除 `Utils\DrawPDFHelper.cs` 和 `Utils\MessageSend.cs` 的编译引用,添加 `ViewModel\LayoutHelperViewModel.cs` 的编译引用,并添加 `KissStudio.DotNetDetour` 包的引用。 - 删除 `DrawPDFHelper.cs` 和 `MessageSend.cs` 文件内容。 - `LayoutHelperWindow.xaml` 中增加 `viewmodel` 命名空间引用,调整窗口高度和最小高度,设置 `d:DataContext`,并在窗口加载时调用 `GlowWindow_Loaded` 方法,修改部分 `TextBlock` 和 `ListView` 的内容绑定。 - `LayoutHelperWindow.xaml.cs` 中添加 `LayoutHelperViewModel` 的引用,并在构造函数中初始化 `viewModel`,设置 `DataContext`,在 `OnInit` 方法中调用 `GetMotorCables`,添加 `GlowWindow_Loaded`、`PrevBtn_Click` 和 `NextBtn_Click` 方法。 - `LectotypeWindow.xaml.cs` 中修改 `StartLayoutBtn_Click` 方法,传递 `motorIds` 给 `LayoutHelperWindow` 的构造函数。 - `ScannerViewModel.cs` 中添加 `Id` 属性的赋值,修改 `PerformSearch` 方法以根据 `Imprint` 进行搜索,添加 `ToSourceById` 方法用于根据 `occId` 定位线缆。 - 在 `DesignPluginEntry.cs`、`PluginEntry.cs` 和 `ScanPluginEntry.cs` 中添加 `Sinvo.EplanHpD.Plugin.WPFUI.Extension` 的引用。 - 新增 `LayoutHelperViewModel.cs` 文件,定义 `LayoutHelperViewModel` 类及其相关属性和方法,用于处理电机和线缆的选择和切换逻辑。
2024-12-10 17:02:58 +08:00
_currentFlexDesigner.SelectSet.Clear();
2024-12-02 09:28:54 +08:00
_currentFlexDesigner.SelectSet.Add(occWire);
2024-12-17 15:16:37 +08:00
2025-01-20 15:55:43 +08:00
// 缩放设计器且触发选中事件
_currentFlexDesigner.FitToSelectSet();
2024-12-02 09:28:54 +08:00
_currentFlexDesigner.SelectSet.OnSelectionChanged();
2024-12-02 09:28:54 +08:00
//_currentFlexDesigner.Camera.GraphicControl._HighlightNode()
/*
List<DatTreeNodeEx<BaseOccurrence>> nodeByEntity = this._occTreeView.GetNodeByEntity(baseOccurrence);
if (nodeByEntity != null)
{
foreach (DatTreeNodeEx<BaseOccurrence> datTreeNodeEx in nodeByEntity)
{
if (!this._occTreeView.SelectedNodes.Contains(datTreeNodeEx))
{
this._occTreeView.SelectedNodes.Add(datTreeNodeEx);
}
}
}
*/
}
}
2024-12-02 09:28:54 +08:00
public void OthersOccShow(bool show = false)
{
2025-01-20 15:55:43 +08:00
// 获取设计器中所有的Occurrence
2024-12-02 09:28:54 +08:00
_currentFlexDesigner.GetOrganizerOccurrences().ToList().ForEach(occ =>
{
2025-01-20 15:55:43 +08:00
// 导线
2024-12-02 09:28:54 +08:00
if (occ is OccWire wire)
{
wire.SetVisibility(show, null);
}
2025-01-20 15:55:43 +08:00
// 电缆
2024-12-02 09:28:54 +08:00
if (occ is OccCableForked cable)
{
cable.SetVisibility(show, null);
}
2025-01-20 15:55:43 +08:00
// 是否包含注解
2024-12-02 09:28:54 +08:00
if (_isIncludeAnnotation)
{
2025-01-20 15:55:43 +08:00
// 注解
2024-12-02 09:28:54 +08:00
if (occ is OccAnnotation annotation)
{
Debug.WriteLine($"BaseOccurrence -> {annotation.Name} Type: {annotation.GetType().Name}");
annotation.SetVisibility(show, null);
}
}
});
if (show)
{
2025-01-20 15:55:43 +08:00
// 放大到选中的线
2024-12-02 09:28:54 +08:00
_currentFlexDesigner.FitToSelectSet();
}
}
// 添加属性以绑定界面上的控件,例如复选框等
public bool OthersWireShow
{
get => _othersWireShow;
set
{
if (_othersWireShow != value)
{
_othersWireShow = value;
OnPropertyChanged(nameof(OthersWireShow));
}
}
}
public bool ContinueScan
{
get => _continueScan;
set
{
if (_continueScan != value)
{
_continueScan = value;
OnPropertyChanged(nameof(ContinueScan));
}
}
}
public bool IsIncludeAnnotation
{
get => _isIncludeAnnotation;
set
{
if (_isIncludeAnnotation != value)
{
_isIncludeAnnotation = value;
OnPropertyChanged(nameof(IsIncludeAnnotation));
}
}
}
public bool ScanAndAssembled
{
get => _scanAndAssembled;
set
{
if (_scanAndAssembled != value)
{
_scanAndAssembled = value;
OnPropertyChanged(nameof(ScanAndAssembled));
}
}
}
public void ExportWires(string path)
{
MiniExcelLibs.MiniExcel.SaveAs(path, ScanCableModels.Select(it => new
{
= it.Index,
线 = it.Code,
线 = it.Name,
线 = it.IsChecked ? "是" : "否"
}));
}
#region Notify
// 实现 INotifyPropertyChanged 接口
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
// 实现 INotifyDataErrorInfo 接口
private readonly Dictionary<string, List<string>> _errors = new Dictionary<string, List<string>>();
public bool HasErrors => _errors.Any();
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
public IEnumerable GetErrors(string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
return null;
_errors.TryGetValue(propertyName, out var errorsForName);
return errorsForName;
}
protected void OnErrorsChanged(string propertyName)
{
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
}
private void AddError(string propertyName, string error)
{
if (!_errors.ContainsKey(propertyName))
{
_errors[propertyName] = new List<string>();
}
if (!_errors[propertyName].Contains(error))
{
_errors[propertyName].Add(error);
OnErrorsChanged(propertyName);
}
}
private void ClearErrors(string propertyName)
{
if (_errors.ContainsKey(propertyName))
{
_errors.Remove(propertyName);
OnErrorsChanged(propertyName);
}
}
#endregion
}
}