|
|
@@ -1,4 +1,5 @@
|
|
|
-using Prism.Commands;
|
|
|
+using MaterialDesignThemes.Wpf;
|
|
|
+using Prism.Commands;
|
|
|
using Prism.Events;
|
|
|
using Prism.Ioc;
|
|
|
using Prism.Mvvm;
|
|
|
@@ -11,6 +12,7 @@ using System.Linq;
|
|
|
using System.Windows;
|
|
|
using TeamAAS_VP.Core;
|
|
|
using TeamAAS_VP.Core.PLCs;
|
|
|
+using TeamAAS_VP.DxfModule;
|
|
|
using TeamAAS_VP.Enums;
|
|
|
using TeamAAS_VP.Events;
|
|
|
using TeamAAS_VP.Interfaces;
|
|
|
@@ -18,6 +20,7 @@ using TeamAAS_VP.Models;
|
|
|
using TeamAAS_VP.Models.PLC;
|
|
|
using TeamAAS_VP.Models.Robot;
|
|
|
using TeamAAS_VP.Resources.Languages;
|
|
|
+using TeamAAS_VP.Views.Product;
|
|
|
|
|
|
namespace TeamAAS_VP.ViewModels.Product
|
|
|
{
|
|
|
@@ -214,7 +217,11 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
private DelegateCommand _MovePointDownCommand;
|
|
|
public DelegateCommand MovePointDownCommand => _MovePointDownCommand ?? (_MovePointDownCommand = new DelegateCommand(ExecuteMovePointDownCommand, CanMovePointDown));
|
|
|
|
|
|
+ private DelegateCommand _ImportCadPointCommand;
|
|
|
+ public DelegateCommand ImportCadPointCommand =>
|
|
|
+ _ImportCadPointCommand ?? (_ImportCadPointCommand = new DelegateCommand(ExecuteImportCadPointCommand));
|
|
|
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 事件
|
|
|
@@ -620,6 +627,75 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
_MovePointUpCommand?.RaiseCanExecuteChanged();
|
|
|
_MovePointDownCommand?.RaiseCanExecuteChanged();
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// CAD导入点位
|
|
|
+ /// </summary>
|
|
|
+ async void ExecuteImportCadPointCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var view = new DxfView();
|
|
|
+
|
|
|
+ //show the dialog
|
|
|
+ var result = await DialogHost.Show(view, "RootDialog", null, null, null);
|
|
|
+ if (result != null)
|
|
|
+ {
|
|
|
+ var cadPoints = view.Points;
|
|
|
+ if (cadPoints != null && cadPoints.Count > 0)
|
|
|
+ {
|
|
|
+ //要导入的开始点编号
|
|
|
+ int startNumber = view.StartIndex;
|
|
|
+
|
|
|
+ //弹窗提示用户是否确认要导入从该编号开始的点位,点位数量为cadPoints.Count
|
|
|
+ if (MessageBox.Show($"确认要从点位编号 {startNumber} 开始导入 {cadPoints.Count} 个点位吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //导入点位
|
|
|
+ for (int i = 0; i < cadPoints.Count; i++)
|
|
|
+ {
|
|
|
+ //如果点位编号已存在,则更新该点位,否则新增点位,只更新XY坐标
|
|
|
+ var point = cadPoints[i];
|
|
|
+ var existingPoint = Points.FirstOrDefault(p => p.Number == startNumber + i);
|
|
|
+ if (existingPoint != null)
|
|
|
+ {
|
|
|
+ existingPoint.X_Position = point.X;
|
|
|
+ existingPoint.Y_Position = point.Y;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Points.Add(new PlcPoint()
|
|
|
+ {
|
|
|
+ Number = startNumber + i,
|
|
|
+ X_Position = point.X,
|
|
|
+ Y_Position = point.Y,
|
|
|
+ Z_Position_Start = 0,
|
|
|
+ U_Position = 0,
|
|
|
+ R_Position = 0
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //对所有的点位重新编号,确保编号连续
|
|
|
+ var sortedPoints = Points.OrderBy(p => p.Number).ToList();
|
|
|
+ Points.Clear();
|
|
|
+ for (int i = 0; i < sortedPoints.Count; i++)
|
|
|
+ {
|
|
|
+ sortedPoints[i].Number = i + 1;
|
|
|
+ Points.Add(sortedPoints[i]);
|
|
|
+ }
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("导入CAD点位时出错!", ex);
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 继承
|