| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307 |
- using ICSharpCode.AvalonEdit.Search;
- using MaterialDesignThemes.Wpf;
- using NPOI.SS.Formula.Functions;
- using Opc.Ua;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Ioc;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Drawing.Drawing2D;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using Team.FFFeederService.Interfaces;
- using TeamAAS_VP.Controls;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Core.Cameras;
- using TeamAAS_VP.Core.Lights;
- using TeamAAS_VP.Enums;
- using TeamAAS_VP.Events;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- using TeamAAS_VP.Models.Lights;
- using TeamAAS_VP.Resources.Languages;
- using TeamAAS_VP.Services;
- using TeamAAS_VP.ViewModels.User;
- using TouchSocket.Core;
- using WPFLocalizeExtension.Engine;
- namespace TeamAAS_VP.ViewModels
- {
- public class SettingViewModel : BindableBase, IConfirmNavigationRequest
- {
- IRegionManager _regionManager;
- IEventAggregator _eventAggregator;
- IContainerProvider _container;
- IDialogService _dialogService;
- IConfigService _configService;
- IRobotService _robotService;
- ICameraService _cameraService;
- IFeederService _feeder_service;
- IFeederService _feederService;
- IPlcService _plcService;
- IProductService _productService;
- ISystemDatabaseService _systemDatabaseService;
- bool isFirstLoad = true;
- #region 属性
- private Management _management;
- public Management management
- {
- get { return _management; }
- set { SetProperty(ref _management, value); }
- }
- private ObservableCollection<RobotInfo> _RobotList;
- public ObservableCollection<RobotInfo> RobotList
- {
- get { return _RobotList; }
- set { SetProperty(ref _RobotList, value); }
- }
- private ObservableCollection<CameraInfo> _CameraList;
- public ObservableCollection<CameraInfo> CameraList
- {
- get { return _CameraList; }
- set { SetProperty(ref _CameraList, value); }
- }
- private ObservableCollection<FeederInfo> _FeederList;
- public ObservableCollection<FeederInfo> FeederList
- {
- get { return _FeederList; }
- set { SetProperty(ref _FeederList, value); }
- }
- private ObservableCollection<PlcInfo> _PlcList;
- public ObservableCollection<PlcInfo> PlcList
- {
- get { return _PlcList; }
- set { SetProperty(ref _PlcList, value); }
- }
- private Language _CurrentLanguage;
- public Language CurrentLanguage
- {
- get { return _CurrentLanguage; }
- set { SetProperty(ref _CurrentLanguage, value); }
- }
- private RobotInfo _SelectRobot;
- /// <summary>
- /// 选中的机器人
- /// </summary>
- public RobotInfo SelectRobot
- {
- get { return _SelectRobot; }
- set
- {
- SetProperty(ref _SelectRobot, value);
- if (value != null && (value.RobotBrand == RobotBrand.XYZ_Platform || value.RobotBrand == RobotBrand.XYZU_Platform))
- {
- RobotSelectedPlc = PlcList.FirstOrDefault(p => p.Id == value.PLC);
- var root = _robotService.GetRobot(SelectRobot.Id);
- if (root != null)
- {
- //ResultsValues.Clear();
- //var res = root.GetNodesValue();
- //for (int i = 0; i < res.Count; i++)
- //{
- // if (res[i].StatusCode.Code != 2150891520)
- // {
- // ResultsValues.Add(res[i].Value.ToString());
- // }
- // else
- // {
- // break;
- // }
- //}
- }
- }
- }
- }
- private FeederInfo _SelectFeeder;
- /// <summary>
- /// 选中的Feeder
- /// </summary>
- public FeederInfo SelectFeeder
- {
- get { return _SelectFeeder; }
- set { SetProperty(ref _SelectFeeder, value); }
- }
- private PlcInfo _SelectPlc;
- public PlcInfo SelectPlc
- {
- get { return _SelectPlc; }
- set { SetProperty(ref _SelectPlc, value); }
- }
- private ObservableCollection<string> _ResultsValues = new ObservableCollection<string>();
- public ObservableCollection<string> ResultsValues { get => _ResultsValues; set => _ResultsValues = value; }
- private CameraInfo _SelectCamera;
- /// <summary>
- /// 选中的Camera
- /// </summary>
- public CameraInfo SelectCamera
- {
- get { return _SelectCamera; }
- set { SetProperty(ref _SelectCamera, value); }
- }
- private double _Title1;
- public double Title1
- {
- get { return _Title1; }
- set { SetProperty(ref _Title1, value); }
- }
- private double _Title2;
- public double Title2
- {
- get { return _Title2; }
- set { SetProperty(ref _Title2, value); }
- }
- private double _Title3;
- public double Title3
- {
- get { return _Title3; }
- set { SetProperty(ref _Title3, value); }
- }
- private double _Title4;
- public double Title4
- {
- get { return _Title4; }
- set { SetProperty(ref _Title4, value); }
- }
- private double _Body1;
- public double Body1
- {
- get { return _Body1; }
- set { SetProperty(ref _Body1, value); }
- }
- private double _Body2;
- public double Body2
- {
- get { return _Body2; }
- set { SetProperty(ref _Body2, value); }
- }
- private double _Body3;
- public double Body3
- {
- get { return _Body3; }
- set { SetProperty(ref _Body3, value); }
- }
- private double _Body4;
- public double Body4
- {
- get { return _Body4; }
- set { SetProperty(ref _Body4, value); }
- }
- private double _Captions1;
- public double Captions1
- {
- get { return _Captions1; }
- set { SetProperty(ref _Captions1, value); }
- }
- private double _Captions2;
- public double Captions2
- {
- get { return _Captions2; }
- set { SetProperty(ref _Captions2, value); }
- }
- private double _Captions3;
- public double Captions3
- {
- get { return _Captions3; }
- set { SetProperty(ref _Captions3, value); }
- }
- private double _Captions4;
- public double Captions4
- {
- get { return _Captions4; }
- set { SetProperty(ref _Captions4, value); }
- }
- private PlcInfo _RobotSelectedPlc;
- public PlcInfo RobotSelectedPlc
- {
- get { return _RobotSelectedPlc; }
- set
- {
- SetProperty(ref _RobotSelectedPlc, value);
- if (SelectRobot != null)
- {
- if (value != null)
- {
- SelectRobot.PLC = value.Id;
- }
- else
- {
- SelectRobot.PLC = Guid.Empty;
- }
- }
- }
- }
- private BgModbusTcp _BgModbus;
- public BgModbusTcp BgModbus
- {
- get { return _BgModbus; }
- set { SetProperty(ref _BgModbus, value); }
- }
- private BgTcpIP _BgTcp;
- public BgTcpIP BgTcp
- {
- get { return _BgTcp; }
- set { SetProperty(ref _BgTcp, value); }
- }
- private ObservableCollection<LightControllerConfig> _LightControllerList;
- public ObservableCollection<LightControllerConfig> LightControllerList
- {
- get { return _LightControllerList; }
- set { SetProperty(ref _LightControllerList, value); }
- }
- private LightControllerConfig _SelectLightController;
- public LightControllerConfig SelectLightController
- {
- get { return _SelectLightController; }
- set { SetProperty(ref _SelectLightController, value); }
- }
- #endregion
- #region 命令
- public DelegateCommand LoadedCommand { get; set; }
- private DelegateCommand _SaveSystemParametersCommand;
- public DelegateCommand SaveSystemParametersCommand =>
- _SaveSystemParametersCommand ?? (_SaveSystemParametersCommand = new DelegateCommand(ExecuteSaveSystemParametersCommand));
- private DelegateCommand _AddRobotCommand;
- public DelegateCommand AddRobotCommand =>
- _AddRobotCommand ?? (_AddRobotCommand = new DelegateCommand(ExecuteAddRobotCommand));
- private DelegateCommand _RemoveCommand;
- public DelegateCommand RemoveCommand =>
- _RemoveCommand ?? (_RemoveCommand = new DelegateCommand(ExecuteRemoveCommand));
- private DelegateCommand _AddFeederCommand;
- public DelegateCommand AddFeederCommand =>
- _AddFeederCommand ?? (_AddFeederCommand = new DelegateCommand(ExecuteAddFeederCommand));
- private DelegateCommand _RemoveFeederCommand;
- public DelegateCommand RemoveFeederCommand =>
- _RemoveFeederCommand ?? (_RemoveFeederCommand = new DelegateCommand(ExecuteRemoveFeederCommand));
- private DelegateCommand<string> _SelectLanguageCommand;
- public DelegateCommand<string> SelectLanguageCommand =>
- _SelectLanguageCommand ?? (_SelectLanguageCommand = new DelegateCommand<string>(ExecuteSelectLanguageCommand));
- private DelegateCommand _SaveRobotsCommand;
- public DelegateCommand SaveRobotsCommand =>
- _SaveRobotsCommand ?? (_SaveRobotsCommand = new DelegateCommand(ExecuteSaveRobotsCommand));
- private DelegateCommand _SaveFeedersCommand;
- public DelegateCommand SaveFeedersCommand =>
- _SaveFeedersCommand ?? (_SaveFeedersCommand = new DelegateCommand(ExecuteSaveFeedersCommand));
- private DelegateCommand<string> _SaveCommunicateCommand;
- public DelegateCommand<string> SaveCommunicateCommand =>
- _SaveCommunicateCommand ?? (_SaveCommunicateCommand = new DelegateCommand<string>(ExecuteSaveCommunicateCommand));
- private DelegateCommand _AddCameraCommand;
- public DelegateCommand AddCameraCommand =>
- _AddCameraCommand ?? (_AddCameraCommand = new DelegateCommand(ExecuteAddCameraCommand));
- private DelegateCommand _EditCameraCommand;
- public DelegateCommand EditCameraCommand =>
- _EditCameraCommand ?? (_EditCameraCommand = new DelegateCommand(ExecuteEditCameraCommand));
- private DelegateCommand _RemoveCameraCommand;
- public DelegateCommand RemoveCameraCommand =>
- _RemoveCameraCommand ?? (_RemoveCameraCommand = new DelegateCommand(ExecuteRemoveCameraCommand));
- private DelegateCommand _SaveCamerasCommand;
- public DelegateCommand SaveCamerasCommand =>
- _SaveCamerasCommand ?? (_SaveCamerasCommand = new DelegateCommand(ExecuteSaveCamerasCommand));
- private DelegateCommand _AddPlcCommand;
- public DelegateCommand AddPlcCommand =>
- _AddPlcCommand ?? (_AddPlcCommand = new DelegateCommand(ExecuteAddPlcCommand));
- private DelegateCommand _RemovePlcCommand;
- public DelegateCommand RemovePlcCommand =>
- _RemovePlcCommand ?? (_RemovePlcCommand = new DelegateCommand(ExecuteRemovePlcCommand));
- private DelegateCommand _SavePlcsCommand;
- public DelegateCommand SavePlcsCommand =>
- _SavePlcsCommand ?? (_SavePlcsCommand = new DelegateCommand(ExecuteSavePlcsCommand));
- private DelegateCommand _AddLightControllerCommand;
- public DelegateCommand AddLightControllerCommand => _AddLightControllerCommand ?? (_AddLightControllerCommand = new DelegateCommand(ExecuteAddLightControllerCommand));
- private DelegateCommand _RemoveLightControllerCommand;
- public DelegateCommand RemoveLightControllerCommand => _RemoveLightControllerCommand ?? (_RemoveLightControllerCommand = new DelegateCommand(ExecuteRemoveLightControllerCommand));
- private DelegateCommand _SaveLightControllersCommand;
- public DelegateCommand SaveLightControllersCommand => _SaveLightControllersCommand ?? (_SaveLightControllersCommand = new DelegateCommand(ExecuteSaveLightControllersCommand));
- #endregion
- #region 事件
- #endregion
- public SettingViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
- IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService,
- IProductService productService, ISystemDatabaseService systemDatabaseService)
- {
- _regionManager = regionManager;
- _eventAggregator = ea;
- _container = container;
- _dialogService = dialogService;
- _configService = configService;
- _robotService = robotService;
- _cameraService = cameraService;
- _feederService = feederService;
- _plcService = plcService;
- _productService = productService;
- _systemDatabaseService = systemDatabaseService;
- management = _container.Resolve<Management>();
- LoadedCommand = new DelegateCommand(OnLoad);
- //订阅权限登录事件
- _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
- }
- #region 方法
- #region 机器人
- private void ExecuteAddRobotCommand()
- {
- _dialogService.ShowDialog("AddRobot", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<RobotInfo>("Robot");
- var robot = new RobotInfo()
- {
- Id = param.Id,
- RobotName = param.RobotName,
- ConnectType = param.ConnectType,
- RobotBrand = param.RobotBrand,
- IP = param.IP,
- Port = param.Port,
- Terminator = param.Terminator,
- };
- RobotList.Add(robot);
- _configService.AddOrUpdateRobot(robot);
- _robotService.CreateRobot(robot.Id, robot);
- //对所有产品也进行添加
- _productService.AddRobotPointToProduct(robot.Id, robot.RobotName);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
- }
- });
- }
- void ExecuteRemoveCommand()
- {
- if (MessageBox.Show(Lang.是否移除机器人, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- // 找到要删除的机器人
- var robotToRemove = RobotList.FirstOrDefault(r => r.Id == SelectRobot.Id);
- if (robotToRemove != null)
- {
- RobotList.Remove(robotToRemove);
- _configService.RemoveRobot(robotToRemove.Id);
- _robotService.RemoveRobot(robotToRemove.Id);
- //对所有产品也进行移除
- _productService.RemoveRobotPointFromProduct(robotToRemove.Id);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
- }
- }
- }
- async void ExecuteSaveRobotsCommand()
- {
- var view = new ShowMessage($"AAS", Lang.是否保存机器人);
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool)
- {
- if (((bool)result))
- {
- foreach (var item in RobotList)
- {
- _configService.AddOrUpdateRobot(item);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- #endregion
- #region 相机
- /// <summary>
- /// 保存所有相机
- /// </summary>
- async void ExecuteSaveCamerasCommand()
- {
- var view = new ShowMessage($"AAS", Lang.是否保存相机配置);
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool)
- {
- if (((bool)result))
- {
- //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
- //management.SaveCamerasDeviceConfig();
- //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 移除相机
- /// </summary>
- void ExecuteRemoveCameraCommand()
- {
- if (MessageBox.Show(Lang.是否移除相机, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- // 找到要删除的相机
- var cameraToRemove = CameraList.FirstOrDefault(r => r.Id == SelectCamera.Id);
- if (cameraToRemove != null)
- {
- _configService.RemoveCamera(cameraToRemove.Id);
- _cameraService.RemoveCamera(cameraToRemove.Id);
- var root = _configService.GetAllCameras();
- CameraList = new ObservableCollection<CameraInfo>(root);
- foreach (var item in CameraList)
- {
- _cameraService.UpdateCameraNumber(item.Id, item.CameraNo);
- }
- //对所有产品也进行移除
- _productService.RemoveCameraFromProduct(cameraToRemove.Id);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 编辑相机
- /// </summary>
- void ExecuteEditCameraCommand()
- {
- if (SelectCamera == null) return;
- bool isSelectedCameraBrandSucced = false;
- CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
- IDialogParameters parameters1 = new DialogParameters();
- parameters1.Add("CameraBrand", SelectCamera.CameraBrand);
- _dialogService.ShowDialog("SelectCameraBrand", parameters1, rst =>
- {
- if (rst.Result == ButtonResult.OK)
- {
- isSelectedCameraBrandSucced = true;
- cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
- }
- else
- {
- return;
- }
- });
- if (!isSelectedCameraBrandSucced) { return; }
- (bool isInstalled, string version) result = (false, "");
- string softwarename = "";
- switch (cameraBrand)
- {
- case CameraBrand.HikRobot_MVS:
- softwarename = "MVS";
- result = MvCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.Basler_Pylon:
- softwarename = "Pylon 7";
- result = BaslerCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.IRayple:
- softwarename = "MV Viewer";
- result = AHuaCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.Cognex:
- softwarename = "Cognex VisionPro";
- result = CognexCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.Galaxy:
- softwarename = "Galaxy Viewer";
- result = GalaxyCamera.CheckSoftwareInstalled();
- break;
- default:
- break;
- }
- if (!result.isInstalled)
- {
- if (string.IsNullOrEmpty(result.version))
- {
- //未安装
- MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
- }
- else
- {
- //版本较低
- MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
- }
- return;
- }
- //编辑前的相机名称
- string oldCameraName = SelectCamera.CameraName;
- IDialogParameters parameters = new DialogParameters();
- parameters.Add("CameraBrand", cameraBrand);
- parameters.Add("Camera", SelectCamera.Copy());
- _dialogService.ShowDialog("EditCamera", parameters, rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<CameraInfo>("Camera");
- SelectCamera.CameraName = param.CameraName;
- SelectCamera.SerialNumber = param.SerialNumber;
- SelectCamera.Model = param.Model;
- SelectCamera.ManufacturerName = param.ManufacturerName;
- SelectCamera.CameraType = param.CameraType;
- SelectCamera.CameraBrand = param.CameraBrand;
- SelectCamera.CameraIp = param.CameraIp;
- _configService.AddOrUpdateCamera(SelectCamera);
- if (oldCameraName != param.CameraName)
- {
- //对所有产品也进行修改
- _productService.UpdateCameraNameInProduct(SelectCamera.Id, SelectCamera.CameraName);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- /// <summary>
- /// 增加相机
- /// </summary>
- void ExecuteAddCameraCommand()
- {
- bool isSelectedCameraBrandSucced = false;
- CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
- _dialogService.ShowDialog("SelectCameraBrand", rst =>
- {
- if (rst.Result == ButtonResult.OK)
- {
- isSelectedCameraBrandSucced = true;
- cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
- }
- else
- {
- return;
- }
- });
- if (!isSelectedCameraBrandSucced) { return; }
- ;
- (bool isInstalled, string version) result = (false, "");
- string softwarename = "";
- switch (cameraBrand)
- {
- case CameraBrand.HikRobot_MVS:
- softwarename = "MVS";
- result = MvCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.Basler_Pylon:
- softwarename = "Pylon 7";
- result = BaslerCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.IRayple:
- softwarename = "MV Viewer";
- result = AHuaCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.Cognex:
- softwarename = "Cognex VisionPro";
- result = CognexCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.Galaxy:
- softwarename = "Galaxy Viewer";
- result = GalaxyCamera.CheckSoftwareInstalled();
- break;
- default:
- break;
- }
- if (!result.isInstalled)
- {
- if (string.IsNullOrEmpty(result.version))
- {
- //未安装
- MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
- }
- else
- {
- //版本较低
- MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
- }
- return;
- }
- IDialogParameters parameters = new DialogParameters();
- parameters.Add("CameraBrand", cameraBrand);
- _dialogService.ShowDialog("AddCamera", parameters, rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<CameraInfo>("Camera");
- var camera = new CameraInfo()
- {
- Id = param.Id,
- CameraName = param.CameraName,
- SerialNumber = param.SerialNumber,
- Model = param.Model,
- ManufacturerName = param.ManufacturerName,
- CameraType = param.CameraType,
- CameraBrand = param.CameraBrand,
- CameraIp = param.CameraIp
- };
- CameraList.Add(camera);
- _configService.AddOrUpdateCamera(camera);
- _cameraService.CreateCamera(camera.Id, camera);
- //对所有产品也进行添加
- _productService.AddCameraToProduct(camera.Id, camera.CameraName);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- #endregion
- #region Feeder
- void ExecuteAddFeederCommand()
- {
- _dialogService.ShowDialog("AddFeeder", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<FeederInfo>("Feeder");
- var feeder = new FeederInfo()
- {
- Id = param.Id,
- FeederName = param.FeederName,
- ConnectType = param.ConnectType,
- FeederBrand = param.FeederBrand,
- IP = param.IP,
- Port = param.Port
- };
- FeederList.Add(feeder);
- _configService.AddOrUpdateFeeder(feeder);
- _feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
- }
- });
- }
- void ExecuteRemoveFeederCommand()
- {
- if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- // 找到要删除的机器人
- var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
- if (feederToRemove != null)
- {
- _configService.RemoveFeeder(feederToRemove.Id);
- _feederService.RemoveFeeder(feederToRemove.Id);
- var root = _configService.GetAllFeeders();
- FeederList = new ObservableCollection<FeederInfo>(root);
- foreach (var item in FeederList)
- {
- _feederService.UpdateFeederNo(item.Id, item.FeederNo);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
- }
- }
- }
- async void ExecuteSaveFeedersCommand()
- {
- var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool)
- {
- if (((bool)result))
- {
- foreach (var item in FeederList)
- {
- _configService.AddOrUpdateFeeder(item);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- #endregion
- #region PLC
- /// <summary>
- /// 保存PLC
- /// </summary>
- async void ExecuteSavePlcsCommand()
- {
- var view = new ShowMessage($"AAS", Lang.是否保存PLC);
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool)
- {
- if (((bool)result))
- {
- foreach (var item in PlcList)
- {
- _configService.AddOrUpdatePlc(item);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 移除PLC
- /// </summary>
- void ExecuteRemovePlcCommand()
- {
- if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- // 找到要删除的plc
- var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
- if (plcToRemove != null)
- {
- _configService.RemovePlc(plcToRemove.Id);
- _plcService.RemovePlc(plcToRemove.Id);
- var root = _configService.GetAllPlcs();
- PlcList = new ObservableCollection<PlcInfo>(root);
- foreach (var item in PlcList)
- {
- _plcService.UpdatePlcNumber(item.Id, item.Index);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 增加PLC
- /// </summary>
- void ExecuteAddPlcCommand()
- {
- _dialogService.ShowDialog("AddPlc", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<PlcInfo>("PLC");
- var plc = new PlcInfo()
- {
- Id = param.Id,
- Name = param.Name,
- CommunicationType = param.CommunicationType,
- EndpointUrl = param.EndpointUrl,
- };
- PlcList.Add(plc);
- _configService.AddOrUpdatePlc(plc);
- _plcService.CreatePlc(plc.Id, plc);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
- }
- });
- }
- #endregion
- #region Light handlers
- void ExecuteAddLightControllerCommand()
- {
- // open dialog to add light controller (similar to robots)
- _dialogService.ShowDialog("AddLightController", rst =>
- {
- if (rst.Result == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
- // assign id and defaults if needed
- if (param.Id == 0)
- param.Id = (LightControllerList?.Count ?? 0) + 1;
- LightControllerList.Add(param);
- _configService.AddOrUpdateLightController(param);
- SelectLightController = param;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加完成", Duration = 1 });
- }
- });
- }
- void ExecuteRemoveLightControllerCommand()
- {
- if (SelectLightController == null) return;
- if (MessageBox.Show("是否移除光源控制器?", "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- _configService.RemoveLightController(SelectLightController.Id);
- LightControllerList.Remove(SelectLightController);
- SelectLightController = null;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "移除完成", Duration = 1 });
- }
- }
- async void ExecuteSaveLightControllersCommand()
- {
- var view = new ShowMessage($"AAS", "是否保存光源控制器配置?");
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool && (bool)result)
- {
- foreach (var item in LightControllerList)
- {
- _configService.AddOrUpdateLightController(item);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成", Duration = 1 });
- }
- }
- #endregion
- #region 通讯
- async void ExecuteSaveCommunicateCommand(string parm)
- {
- if (parm == "TCPIP")
- {
- var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool)
- {
- if (((bool)result))
- {
- _configService.SetBgTcp(BgTcp);
- _configService.SaveBgTcp();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- else if (parm == "ModbusTCP")
- {
- var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool)
- {
- if (((bool)result))
- {
- _configService.SetBgModbusTcp(BgModbus);
- _configService.SaveBgModbusTcp();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- else
- {
- return;
- }
- }
- #endregion
- #region 语言
- void ExecuteSelectLanguageCommand(string language)
- {
- if (string.Equals(language, "ChineseSimplified"))
- {
- CurrentLanguage = Enums.Language.ChineseSimplified;
- var sysConfig = _configService.GetSystemConfiguration();
- sysConfig.CurrentLanguage = CurrentLanguage;
- _configService.SaveSystemConfiguration(sysConfig);
- var culture = new CultureInfo("zh-CN");
- App.Current.Dispatcher.Thread.CurrentCulture = culture;
- App.Current.Dispatcher.Thread.CurrentUICulture = culture;
- LocalizeDictionary.Instance.Culture = culture;
- Lang.Culture = culture;
- Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- else if (string.Equals(language, "ChineseTraditional"))
- {
- CurrentLanguage = Enums.Language.ChineseTraditional;
- var sysConfig = _configService.GetSystemConfiguration();
- sysConfig.CurrentLanguage = CurrentLanguage;
- _configService.SaveSystemConfiguration(sysConfig);
- var culture = new CultureInfo("zh-TW");
- App.Current.Dispatcher.Thread.CurrentCulture = culture;
- App.Current.Dispatcher.Thread.CurrentUICulture = culture;
- LocalizeDictionary.Instance.Culture = culture;
- Lang.Culture = culture;
- Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- else if (string.Equals(language, "English"))
- {
- CurrentLanguage = Enums.Language.English;
- var sysConfig = _configService.GetSystemConfiguration();
- sysConfig.CurrentLanguage = CurrentLanguage;
- _configService.SaveSystemConfiguration(sysConfig);
- var culture = new CultureInfo("en");
- App.Current.Dispatcher.Thread.CurrentCulture = culture;
- App.Current.Dispatcher.Thread.CurrentUICulture = culture;
- LocalizeDictionary.Instance.Culture = culture;
- Lang.Culture = culture;
- Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- else if (string.Equals(language, "Japanese"))
- {
- CurrentLanguage = Enums.Language.Japanese;
- var sysConfig = _configService.GetSystemConfiguration();
- sysConfig.CurrentLanguage = CurrentLanguage;
- _configService.SaveSystemConfiguration(sysConfig);
- var culture = new CultureInfo("ja-JP");
- App.Current.Dispatcher.Thread.CurrentCulture = culture;
- App.Current.Dispatcher.Thread.CurrentUICulture = culture;
- LocalizeDictionary.Instance.Culture = culture;
- Lang.Culture = culture;
- Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- }
- #endregion
- private void OnLoad()
- {
- }
- private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- switch (e.PropertyName)
- {
- case "Title1":
- Application.Current.Resources["Font.Size.Title1"] = Title1;
- break;
- case "Title2":
- Application.Current.Resources["Font.Size.Title2"] = Title2;
- break;
- case "Title3":
- Application.Current.Resources["Font.Size.Title3"] = Title3;
- break;
- case "Title4":
- Application.Current.Resources["Font.Size.Title4"] = Title4;
- break;
- case "Body1":
- Application.Current.Resources["Font.Size.Body1"] = Body1;
- break;
- case "Body2":
- Application.Current.Resources["Font.Size.Body2"] = Body2;
- break;
- case "Body3":
- Application.Current.Resources["Font.Size.Body3"] = Body3;
- break;
- case "Body4":
- Application.Current.Resources["Font.Size.Body4"] = Body4;
- break;
- case "Captions1":
- Application.Current.Resources["Font.Size.Captions1"] = Captions1;
- break;
- case "Captions2":
- Application.Current.Resources["Font.Size.Captions2"] = Captions2;
- break;
- case "Captions3":
- Application.Current.Resources["Font.Size.Captions3"] = Captions3;
- break;
- case "Captions4":
- Application.Current.Resources["Font.Size.Captions4"] = Captions4;
- break;
- default:
- break;
- }
- }
- #endregion
- #region 继承
- /// <summary>
- /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <param name="continuationCallback"></param>
- public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
- {
- continuationCallback(true);
- }
- /// <summary>
- /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <exception cref="NotImplementedException"></exception>
- public async void OnNavigatedTo(NavigationContext navigationContext)
- {
- if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- if (RobotList == null)
- {
- RobotList = new ObservableCollection<RobotInfo>();
- var robots = _configService.GetAllRobots();
- foreach (var robot in robots)
- {
- RobotList.Add(robot);
- }
- }
- if (CameraList == null)
- {
- CameraList = new ObservableCollection<CameraInfo>();
- var cameras = _configService.GetAllCameras();
- foreach (var camera in cameras)
- {
- CameraList.Add(camera);
- }
- }
- if (FeederList == null)
- {
- FeederList = new ObservableCollection<FeederInfo>();
- var feeders = _configService.GetAllFeeders();
- foreach (var feeder in feeders)
- {
- FeederList.Add(feeder);
- }
- }
- if (PlcList == null)
- {
- PlcList = new ObservableCollection<PlcInfo>();
- var plcs = _configService.GetAllPlcs();
- foreach (var plc in plcs)
- {
- PlcList.Add(plc);
- }
- }
- // load light controllers
- if (LightControllerList == null)
- {
- LightControllerList = new ObservableCollection<LightControllerConfig>();
- var controllers = _configService.GetAllLightControllers();
- foreach (var ctrl in controllers)
- {
- LightControllerList.Add(ctrl);
- }
- }
- if (BgTcp == null)
- {
- BgTcp = _configService.GetBgTcp();
- }
- if (BgModbus == null)
- {
- BgModbus = _configService.GetBgModbusTcp();
- }
- CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
- // load system parameters into UI
- var sys = _configService.GetSystemConfiguration();
- if (sys != null)
- {
- WorkMode = sys.WorkMode;
- PickPointNum = sys.PickPointNum;
- CameraShotCount = sys.CameraShotCount;
- UpperCameraPickShotCount = sys.UpperCameraPickShotCount;
- UpperCameraPlaceShotCount = sys.UpperCameraPlaceShotCount;
- UpperCameraLockAssembleCount = sys.UpperCameraLockAssembleCount;
- FixedPickCameraCount = sys.PickFixedPositionProductCameraCount;
- FixedLockAssembleCameraCount = sys.LockFixedPositionProductCameraCount;
- FixedCameraDetectLockAssembleCount = sys.FixedCameraDetectLockAssembleCount;
- }
- if (isFirstLoad)
- {
- Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
- Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
- Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
- Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
- Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
- Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
- Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
- Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
- Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
- Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
- Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
- Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
- this.PropertyChanged += OnPropertyChanged;
- isFirstLoad = false;
- }
- }
- /// <summary>
- /// 是否允许导航到此视图模型。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <returns></returns>
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- /// <summary>
- /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
- /// </summary>
- /// <param name="navigationContext"></param>
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- #endregion
- private bool _IsAllowEdit = false;
- public bool IsAllowEdit
- {
- get { return _IsAllowEdit; }
- set { SetProperty(ref _IsAllowEdit, value); }
- }
- private void LoginChange(Models.User user)
- {
- if (user.userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- }
- #region 系统参数
- private int _WorkMode=0;
- public int WorkMode
- {
- get { return _WorkMode; }
- set { SetProperty(ref _WorkMode, value); }
- }
- private int _PickPointNum;
- public int PickPointNum
- {
- get { return _PickPointNum; }
- set { SetProperty(ref _PickPointNum, value); }
- }
- private int _CameraShotCount;
- public int CameraShotCount { get => _CameraShotCount; set => SetProperty(ref _CameraShotCount, value); }
- private int _UpperCameraPickShotCount;
- public int UpperCameraPickShotCount { get => _UpperCameraPickShotCount; set => SetProperty(ref _UpperCameraPickShotCount, value); }
- private int _UpperCameraPlaceShotCount;
- public int UpperCameraPlaceShotCount { get => _UpperCameraPlaceShotCount; set => SetProperty(ref _UpperCameraPlaceShotCount, value); }
- private int _UpperCameraLockAssembleCount;
- public int UpperCameraLockAssembleCount { get => _UpperCameraLockAssembleCount; set => SetProperty(ref _UpperCameraLockAssembleCount, value); }
- private int _FixedPickCameraCount;
- public int FixedPickCameraCount { get => _FixedPickCameraCount; set => SetProperty(ref _FixedPickCameraCount, value); }
- private int _FixedLockAssembleCameraCount;
- public int FixedLockAssembleCameraCount { get => _FixedLockAssembleCameraCount; set => SetProperty(ref _FixedLockAssembleCameraCount, value); }
- private int _FixedCameraDetectLockAssembleCount;
- public int FixedCameraDetectLockAssembleCount { get => _FixedCameraDetectLockAssembleCount; set => SetProperty(ref _FixedCameraDetectLockAssembleCount, value); }
- async void ExecuteSaveSystemParametersCommand()
- {
- var view = new ShowMessage($"AAS", "是否保存系统参数?");
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool && (bool)result)
- {
- try
- {
- var sysConfig = _configService.GetSystemConfiguration();
- sysConfig.WorkMode = WorkMode;
- sysConfig.PickPointNum = PickPointNum;
- sysConfig.CameraShotCount = CameraShotCount;
- sysConfig.UpperCameraPickShotCount = UpperCameraPickShotCount;
- sysConfig.UpperCameraPlaceShotCount = UpperCameraPlaceShotCount;
- sysConfig.UpperCameraLockAssembleCount = UpperCameraLockAssembleCount;
- sysConfig.PickFixedPositionProductCameraCount = FixedPickCameraCount;
- sysConfig.LockFixedPositionProductCameraCount = FixedLockAssembleCameraCount;
- sysConfig.FixedCameraDetectLockAssembleCount = FixedCameraDetectLockAssembleCount;
- _configService.SaveSystemConfiguration(sysConfig);
- await management.WriteSystemParameterToPlcAsync(sysConfig);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg =ex.Message, Duration = 1 });
- }
- }
- }
- #endregion
- }
- }
|