90 lines
3.2 KiB
C#
90 lines
3.2 KiB
C#
using Prism.Mvvm;
|
|
using XplorePlane.Models;
|
|
|
|
namespace XplorePlane.ViewModels.Cnc
|
|
{
|
|
/// <summary>
|
|
/// CNC 节点 ViewModel,将 CncNode 模型封装为可绑定的 WPF ViewModel
|
|
/// CNC node ViewModel that wraps a CncNode model into a bindable WPF ViewModel
|
|
/// </summary>
|
|
public class CncNodeViewModel : BindableBase
|
|
{
|
|
private int _index;
|
|
private string _name;
|
|
private CncNodeType _nodeType;
|
|
private string _icon;
|
|
|
|
/// <summary>
|
|
/// 构造函数,从 CncNode 模型初始化 ViewModel
|
|
/// Constructor that initializes the ViewModel from a CncNode model
|
|
/// </summary>
|
|
public CncNodeViewModel(CncNode model)
|
|
{
|
|
Model = model;
|
|
_index = model.Index;
|
|
_name = model.Name;
|
|
_nodeType = model.NodeType;
|
|
_icon = GetIconForNodeType(model.NodeType);
|
|
}
|
|
|
|
/// <summary>底层 CNC 节点模型(只读)| Underlying CNC node model (read-only)</summary>
|
|
public CncNode Model { get; }
|
|
|
|
/// <summary>节点在程序中的索引 | Node index in the program</summary>
|
|
public int Index
|
|
{
|
|
get => _index;
|
|
set => SetProperty(ref _index, value);
|
|
}
|
|
|
|
/// <summary>节点显示名称 | Node display name</summary>
|
|
public string Name
|
|
{
|
|
get => _name;
|
|
set => SetProperty(ref _name, value);
|
|
}
|
|
|
|
/// <summary>节点类型 | Node type</summary>
|
|
public CncNodeType NodeType
|
|
{
|
|
get => _nodeType;
|
|
set
|
|
{
|
|
if (SetProperty(ref _nodeType, value))
|
|
{
|
|
// 类型变更时自动更新图标 | Auto-update icon when type changes
|
|
Icon = GetIconForNodeType(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>节点图标路径 | Node icon path</summary>
|
|
public string Icon
|
|
{
|
|
get => _icon;
|
|
set => SetProperty(ref _icon, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据节点类型返回对应的图标路径
|
|
/// Returns the icon path for the given node type
|
|
/// </summary>
|
|
public static string GetIconForNodeType(CncNodeType nodeType)
|
|
{
|
|
return nodeType switch
|
|
{
|
|
CncNodeType.ReferencePoint => "/Resources/Icons/cnc_reference_point.png",
|
|
CncNodeType.SaveNodeWithImage => "/Resources/Icons/cnc_save_with_image.png",
|
|
CncNodeType.SaveNode => "/Resources/Icons/cnc_save_node.png",
|
|
CncNodeType.SavePosition => "/Resources/Icons/cnc_save_position.png",
|
|
CncNodeType.InspectionModule => "/Resources/Icons/cnc_inspection_module.png",
|
|
CncNodeType.InspectionMarker => "/Resources/Icons/cnc_inspection_marker.png",
|
|
CncNodeType.PauseDialog => "/Resources/Icons/cnc_pause_dialog.png",
|
|
CncNodeType.WaitDelay => "/Resources/Icons/cnc_wait_delay.png",
|
|
CncNodeType.CompleteProgram => "/Resources/Icons/cnc_complete_program.png",
|
|
_ => "/Resources/Icons/cnc_default.png",
|
|
};
|
|
}
|
|
}
|
|
}
|