|
|
@@ -4,10 +4,13 @@ using Prism.Mvvm;
|
|
|
using Prism.Services.Dialogs;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Windows;
|
|
|
using TeamAAS_VP.Core;
|
|
|
+using TeamAAS_VP.Interfaces;
|
|
|
using TeamAAS_VP.Models;
|
|
|
+using TeamAAS_VP.Models.PLC;
|
|
|
using TeamAAS_VP.Resources.Languages;
|
|
|
using TouchSocket.Core;
|
|
|
|
|
|
@@ -15,6 +18,7 @@ namespace TeamAAS_VP.ViewModels.Setting
|
|
|
{
|
|
|
public class AddRobotViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
+ private readonly IConfigService _configService;
|
|
|
private RobotInfo _Robot;
|
|
|
/// <summary>
|
|
|
/// 机器人
|
|
|
@@ -22,7 +26,17 @@ namespace TeamAAS_VP.ViewModels.Setting
|
|
|
public RobotInfo Robot
|
|
|
{
|
|
|
get { return _Robot; }
|
|
|
- set { SetProperty(ref _Robot, value); }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref _Robot, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ObservableCollection<PlcInfo> _AllPlc;
|
|
|
+ public ObservableCollection<PlcInfo> AllPlc
|
|
|
+ {
|
|
|
+ get { return _AllPlc; }
|
|
|
+ set { SetProperty(ref _AllPlc, value); }
|
|
|
}
|
|
|
|
|
|
private PlcInfo _SelectedPlc;
|
|
|
@@ -35,25 +49,47 @@ namespace TeamAAS_VP.ViewModels.Setting
|
|
|
if (value != null)
|
|
|
{
|
|
|
Robot.PLC = value.Id;
|
|
|
+ if (Robot.PlcRobotParameter == null)
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter = new PlcRobotParameter();
|
|
|
+ }
|
|
|
+ if (Robot.PlcRobotParameter.AxixList == null)
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter.AxixList = new List<Core.Robots.Axis>();
|
|
|
+ if (Robot.RobotBrand == Enums.RobotBrand.XYZ_Platform)
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("X", 1));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Y", 2));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Z", 3));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("X", 1));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Y", 2));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Z", 3));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("U", 4));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Robot.PLC = Guid.Empty;
|
|
|
+ Robot.PlcRobotParameter = null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private DelegateCommand _ConfirmCommand;
|
|
|
public DelegateCommand ConfirmCommand =>
|
|
|
- _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand).ObservesProperty(()=> Robot.RobotName));
|
|
|
+ _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand).ObservesProperty(() => Robot.RobotName));
|
|
|
|
|
|
private DelegateCommand _CancelCommand;
|
|
|
public DelegateCommand CancelCommand =>
|
|
|
_CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
|
|
|
|
|
|
- public AddRobotViewModel()
|
|
|
+ public AddRobotViewModel(IConfigService configService)
|
|
|
{
|
|
|
-
|
|
|
+ _configService = configService;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -62,7 +98,7 @@ namespace TeamAAS_VP.ViewModels.Setting
|
|
|
/// <returns></returns>
|
|
|
bool CanExecuteConfirmCommand()
|
|
|
{
|
|
|
- return Robot!=null && Robot.RobotName!=null && !string.IsNullOrEmpty(Robot.RobotName.Trim());
|
|
|
+ return Robot != null && Robot.RobotName != null && !string.IsNullOrEmpty(Robot.RobotName.Trim());
|
|
|
}
|
|
|
|
|
|
void ExecuteConfirmCommand()
|
|
|
@@ -76,6 +112,38 @@ namespace TeamAAS_VP.ViewModels.Setting
|
|
|
MessageBox.Show(Lang.AddCameraVM_message1, "AAS", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
return;
|
|
|
}
|
|
|
+ if (Robot.RobotBrand == Enums.RobotBrand.XYZ_Platform)
|
|
|
+ {
|
|
|
+ if (Robot.PlcRobotParameter == null)
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter = new PlcRobotParameter();
|
|
|
+ }
|
|
|
+ if (Robot.PlcRobotParameter.AxixList == null)
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter.AxixList = new List<Core.Robots.Axis>();
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("X", 1));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Y", 2));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Z", 3));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (Robot.RobotBrand == Enums.RobotBrand.XYZU_Platform)
|
|
|
+ {
|
|
|
+ if (Robot.PlcRobotParameter == null)
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter = new PlcRobotParameter();
|
|
|
+ }
|
|
|
+ if (Robot.PlcRobotParameter.AxixList == null)
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("X", 1));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Y", 2));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("Z", 3));
|
|
|
+ Robot.PlcRobotParameter.AxixList.Add(new Core.Robots.Axis("U", 4));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Robot.PlcRobotParameter = null;
|
|
|
+ }
|
|
|
|
|
|
IDialogParameters parameters = new DialogParameters();
|
|
|
parameters.Add("Robot", Robot);
|
|
|
@@ -111,7 +179,8 @@ namespace TeamAAS_VP.ViewModels.Setting
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
|
{
|
|
|
Title = Lang.增加机器人;
|
|
|
- Robot = new RobotInfo() { Id = Guid.NewGuid(),RobotBrand= Enums.RobotBrand.Default,ConnectType= Enums.TCPConnectType.Client, Terminator= Enums.Terminator.CRLF, DataEncoding= Enums.DataEncoding.Default };
|
|
|
+ Robot = new RobotInfo() { Id = Guid.NewGuid(), RobotBrand = Enums.RobotBrand.Default, ConnectType = Enums.TCPConnectType.Client, Terminator = Enums.Terminator.CRLF, DataEncoding = Enums.DataEncoding.Default };
|
|
|
+ AllPlc = new ObservableCollection<PlcInfo>(_configService.GetAllPlcs());
|
|
|
}
|
|
|
}
|
|
|
}
|