我的 WPF Powermill 工具

xaml界面:

cs 复制代码
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Powermill编程工具
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        //定义刀具列表全局变量
        public ObservableCollection<string> tool_list { get; set; }

        //定义后处理器列表全局变量
        public ObservableCollection<string> post_list { get; set; }

        //定义刀路信息列表全局变量
        public ObservableCollection<path_inf> path_infs { get; set; }

        private void DeleteSelectedItem_Click(object sender, RoutedEventArgs e)
        {
            // 判断是否选中行
            if (lvList.SelectedItem == null)
                return;

            // 获取选中的数据项
            path_inf selectedItem = (path_inf)lvList.SelectedItem;

            // 从 ObservableCollection 中删除(自动刷新UI)
            if (DataContext is MainWindow vm)
            {
                vm.path_infs.Remove(selectedItem);
            }
        }

        public MainWindow()
        {
            InitializeComponent();

            //初始化 运行中的Powermill 下拉选项
            ObservableCollection<pm_project> pm_projects = new ObservableCollection<pm_project>
            {
                new pm_project { Name = "Alice" },
                new pm_project { Name = "Bob" },
                new pm_project { Name = "Charlie" }
            };
            Powermill_list.ItemsSource = pm_projects;
            Powermill_list.SelectedIndex = 0;

            //初始化刀具列表
            tool_list = new ObservableCollection<string>
            {
                "D63R8","D35R5","D16R0.8","D10R0","D20R0","D30R0"
            };

            //初始化刀路信息
            path_infs = new ObservableCollection<path_inf>
            {
                new path_inf { path_name = "开粗",tool_name="D10R0",offset=@"0.5/0.2",spindle="2000",feedrate="3000" },
                new path_inf { path_name = "光平面",tool_name="D20R0",offset=@"0.2/0.2",spindle="3000",feedrate="1000" },
                new path_inf { path_name = "清角",tool_name="D30R0",offset=@"0.3/0.2",spindle="4000",feedrate="500" }
            };
            lvList.ItemsSource = path_infs;

            //初始化后处理器列
            post_list = new ObservableCollection<string>
            {
                "发那科",
                "西门子",
                "北京精雕"
            };
            post_ComboBox.ItemsSource = post_list;
            post_ComboBox.SelectedIndex = 0;

            // 绑定数据源上下文
            DataContext = this;
        }
    }

    //运行中的pm项目
    public class pm_project
    {
        public string Name { get; set; }
    }

    //列表行数据模型
    public class path_inf
    {
        public string path_name { get; set; }   //刀路名
        public string tool_name { get; set; }   //刀具名
        public string offset { get; set; }      //余量
        public string spindle { get; set; }     //转速
        public string feedrate { get; set; }     //进给
    }
}

CS后台:

cs 复制代码
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Powermill编程工具
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        //定义刀具列表全局变量
        public ObservableCollection<string> tool_list { get; set; }

        //定义后处理器列表全局变量
        public ObservableCollection<string> post_list { get; set; }

        //定义刀路信息列表全局变量
        public ObservableCollection<path_inf> path_infs { get; set; }

        private void DeleteSelectedItem_Click(object sender, RoutedEventArgs e)
        {
            // 判断是否选中行
            if (lvList.SelectedItem == null)
                return;

            // 获取选中的数据项
            path_inf selectedItem = (path_inf)lvList.SelectedItem;

            // 从 ObservableCollection 中删除(自动刷新UI)
            if (DataContext is MainWindow vm)
            {
                vm.path_infs.Remove(selectedItem);
            }
        }

        public MainWindow()
        {
            InitializeComponent();

            //初始化 运行中的Powermill 下拉选项
            ObservableCollection<pm_project> pm_projects = new ObservableCollection<pm_project>
            {
                new pm_project { Name = "Alice" },
                new pm_project { Name = "Bob" },
                new pm_project { Name = "Charlie" }
            };
            Powermill_list.ItemsSource = pm_projects;
            Powermill_list.SelectedIndex = 0;

            //初始化刀具列表
            tool_list = new ObservableCollection<string>
            {
                "D63R8","D35R5","D16R0.8","D10R0","D20R0","D30R0"
            };

            //初始化刀路信息
            path_infs = new ObservableCollection<path_inf>
            {
                new path_inf { path_name = "开粗",tool_name="D10R0",offset=@"0.5/0.2",spindle="2000",feedrate="3000" },
                new path_inf { path_name = "光平面",tool_name="D20R0",offset=@"0.2/0.2",spindle="3000",feedrate="1000" },
                new path_inf { path_name = "清角",tool_name="D30R0",offset=@"0.3/0.2",spindle="4000",feedrate="500" }
            };
            lvList.ItemsSource = path_infs;

            //初始化后处理器列
            post_list = new ObservableCollection<string>
            {
                "发那科",
                "西门子",
                "北京精雕"
            };
            post_ComboBox.ItemsSource = post_list;
            post_ComboBox.SelectedIndex = 0;

            // 绑定数据源上下文
            DataContext = this;
        }
    }

    //运行中的pm项目
    public class pm_project
    {
        public string Name { get; set; }
    }

    //列表行数据模型
    public class path_inf
    {
        public string path_name { get; set; }   //刀路名
        public string tool_name { get; set; }   //刀具名
        public string offset { get; set; }      //余量
        public string spindle { get; set; }     //转速
        public string feedrate { get; set; }     //进给
    }
}
相关推荐
myenjoy_114 小时前
大规模采集架构——从单台网关到千点集群
架构·wpf
Chris _data19 小时前
c#学习WPF笔记(一)
学习·c#·wpf
FuckPatience1 天前
WPF 自定义容器控件的布局
wpf
逆境不可逃1 天前
深入理解 SingleFlight:从单机到分布式的请求合并方案全解析
分布式·wpf
TDengine (老段)2 天前
TDengine 逻辑计划生成 — 从 AST 到关系代数算子树
大数据·数据库·物联网·wpf·时序数据库·tdengine·涛思数据
小二·3 天前
微服务架构设计与实践
微服务·架构·wpf
暖馒3 天前
WPF-Prism学习入门步骤记录
学习·wpf
baivfhpwxf20233 天前
雷赛(Leadshine)EtherCAT 数字 I/O 模块(如 EMC-E5064-8)的状态指示灯(I/O 状态)说明
c#·wpf
故渊at4 天前
第二板块:Android 四大组件标准化学理 | 第十二篇:四大组件全景总结与系统服务(System Server)架构
android·架构·wpf·四大组件·system service
伶俜664 天前
# [特殊字符] 零基础学 ArkUI 数据持久化(专题三):5 种存储方案深度对比
学习·华为·wpf·harmonyos