Files
infineon_cs_hmi/uniper_hmi/UniperHMI/Pages/ViewModels/MachineOverviewPageVM.cs

378 lines
11 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Heisig.HMI.AdsManager;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Windows;
using System.Windows.Controls;
using Common;
using InfineonHMI.Common;
using TcEventLoggerAdsProxyLib;
namespace InfineonHMI;
public sealed partial class MachineOverviewPageVM : ObservableObject, IRecipient<NavigateMessage>, IDisposable
{
[ObservableProperty] private StringControlButtonVM dummyStringVM;
[ObservableProperty] private Page currentDetailPage;
[ObservableProperty] private PackMLControlVM machinePackMLControlVM;
public bool CanUserChangePageAlignment
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageEtching1
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageEtching2
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageHighVoltage
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageHotCoolplate
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageKukaRobot
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageMediaCabinet
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageNIOStation
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageProductionOverview
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangePageReceipe
{
get { return currentUser.UserLevel == 100; }
}
public bool CanUserChangePageTrayFeeder
{
get { return currentUser.UserLevel > 50; }
}
public bool CanUserChangeMachineState
{
get { return currentUser.UserLevel > 50; }
}
private readonly IAdsManager _adsManager;
private readonly IConfiguration _config;
private User currentUser;
// Last active event
[ObservableProperty] private string currentActiveEvent = "";
// Empty page
private readonly Page _emptyPage;
// Last navigate message
private readonly Stack<NavigateMessage> _messageStack = new();
NavigateMessage? _currentMessage;
// Hot Coolplate page view model
HotCoolPlatePageVM? _hotCoolplatePageVM;
AlignmentStationPageVM? _alignmentStationPageVM;
EtchingStation1PageVM? _etchingStation1PageVm;
EtchingStation2PageVM? _etchingStation2PageVm;
HighVoltageStationPageVM? _highVoltageStationPageVm;
MediaCabinetPageVM? _mediaCabinetPageVM;
NIOStationPageVM? _nioStationPageVm;
TrayFeederPageVM? _trayFeederPageVm;
private ProductionOverviewPageVM? _prodVM;
private MainWindowVM _mainVm;
// Kuka Robot page view model
KukaRobotPageVM? _kukaRobotPageVM;
public MachineOverviewPageVM()
{
// default ctor
MachinePackMLControlVM = new();
MachinePackMLControlVM.STitle = "Betriebszustand\n Gesamtanlage";
currentUser = Users.getCurrentUser();
}
public MachineOverviewPageVM(IAdsManager adsManager, IConfiguration config,MainWindowVM mainVm, ProductionOverviewPageVM prodVm, TcEventLogger eventLogger)
{
_adsManager = adsManager;
_config = config;
_prodVM = prodVm;
_mainVm = mainVm;
// Create dummy string
DummyStringVM = new StringControlButtonVM();
currentUser = Users.getCurrentUser();
MachinePackMLControlVM = new(_adsManager, "GVL_SCADA.stMachine.stMachineCmds");
MachinePackMLControlVM.STitle = "Betriebszustand\n Gesamtanlage";
// Create empty page
_emptyPage = new();
CurrentDetailPage = _emptyPage;
_currentMessage = new NavigateMessage("", typeof(Page));
_messageStack.Push(_currentMessage);
WeakReferenceMessenger.Default.Register<NavigateMessage>(this);
//CanUserChangePageAlignment = currentUser.UserLevel > 50;
//CanUserChangePageEtching1 = currentUser.UserLevel > 50;
//CanUserChangePageEtching2 = currentUser.UserLevel > 50;
//CanUserChangePageHighVoltage = currentUser.UserLevel > 50;
//CanUserChangePageHotCoolplate = currentUser.UserLevel > 50;
//CanUserChangePageKukaRobot = currentUser.UserLevel > 50;
//CanUserChangePageMediaCabinet = currentUser.UserLevel > 50;
//CanUserChangePageNIOStation = currentUser.UserLevel > 50;
//CanUserChangePageProductionOverview = currentUser.UserLevel > 50;
//CanUserChangePageReceipe = currentUser.UserLevel == 100;
//CanUserChangePageTrayFeeder = currentUser.UserLevel > 50;
//CanUserChangeMachineState = currentUser.UserLevel > 50;
}
[RelayCommand]
public void TrayfeederPageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(TrayFeederPage));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
[RelayCommand]
public void AlignerPageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(AlignmentStationPage));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
[RelayCommand]
public void Etching1PageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(EtchingStation1Page));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
[RelayCommand]
public void Etching2PageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(EtchingStation2Page));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
[RelayCommand]
public void HVTestPageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(HighVoltageStationPage));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
[RelayCommand]
public void HotCoolplatePageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(HotCoolPlatePage));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
[RelayCommand]
public void NIOStationPageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(NIOStationPage));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
[RelayCommand]
public void KukaPageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(KukaRobotPage));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
[RelayCommand]
public void MediaCabinetPageClicked()
{
NavigateMessage message = new("", typeof(ProductionOverviewPage));
NavigateMessage nextMessage = new("", typeof(MediaCabinetPage));
this.Dispose();
_mainVm?.NavigateFromOuterPage(message, nextMessage);
}
// Only use for forward traversal!
public void Receive(NavigateMessage message)
{
// Only change page if its a new page type
if (CurrentDetailPage.GetType() == message.type)
return;
// Push current message
if (_currentMessage != null)
_messageStack.Push(_currentMessage);
// Save current message for later push
_currentMessage = message;
// Set can navigate back
Navigate(message);
}
private void Navigate(NavigateMessage message)
{
// Dispose current pages viewmodel
if (CurrentDetailPage.DataContext is IDisposable viewModel)
{
CurrentDetailPage.DataContext = null;
viewModel.Dispose();
}
// Create new page
switch (message.type.Name)
{
case nameof(TrayFeederPage):
if (_trayFeederPageVm == null)
_trayFeederPageVm = new(_adsManager, "GVL_SCADA.stMachine.TrayFeeder"); //In and Out ist set directly in ViewModel
TrayFeederPage trayFeederPage = new() { DataContext = _trayFeederPageVm };
CurrentDetailPage = trayFeederPage;
break;
case nameof(AlignmentStationPage):
// Create seetings page view model only once
if (_alignmentStationPageVM == null)
_alignmentStationPageVM = new(_adsManager, "GVL_SCADA.stMachine.stAligner");
AlignmentStationPage settingsPage = new() { DataContext = _alignmentStationPageVM };
CurrentDetailPage = settingsPage;
break;
case nameof(EtchingStation1Page):
if (_etchingStation1PageVm == null)
_etchingStation1PageVm = new(_adsManager, "GVL_SCADA.stMachine.stEtcher1");
EtchingStation1Page etchingStation1Page = new() { DataContext = _etchingStation1PageVm };
CurrentDetailPage = etchingStation1Page;
break;
case nameof(EtchingStation2Page):
if (_etchingStation2PageVm == null)
_etchingStation2PageVm = new(_adsManager, "GVL_SCADA.stMachine.stEtcher2");
EtchingStation2Page etchingStation2Page = new() { DataContext = _etchingStation2PageVm };
CurrentDetailPage = etchingStation2Page;
break;
case nameof(HighVoltageStationPage):
if (_highVoltageStationPageVm == null)
_highVoltageStationPageVm = new(_adsManager, "GVL_SCADA.stMachine.stHVTester"); // Hot/Cold is Set directly in VM
HighVoltageStationPage highVoltageStationPage = new() { DataContext = _highVoltageStationPageVm };
CurrentDetailPage = highVoltageStationPage;
break;
case nameof(HotCoolPlatePage):
if (_hotCoolplatePageVM == null)
_hotCoolplatePageVM = new(_adsManager, "GVL_SCADA.stMachine"); //".stHotplate /.stCoolplate is set directly in VM
HotCoolPlatePage hotCoolPlatePage = new() {DataContext = _hotCoolplatePageVM };
CurrentDetailPage = hotCoolPlatePage;
break;
case nameof(NIOStationPage):
if (_nioStationPageVm == null)
_nioStationPageVm = new(_adsManager, "GVL_SCADA.stMachine.stNOK");
NIOStationPage nIOStationPage = new() { DataContext = _nioStationPageVm };
CurrentDetailPage = nIOStationPage;
break;
case nameof(KukaRobotPage):
// Create page view model only once
if (_kukaRobotPageVM == null)
_kukaRobotPageVM = new(_adsManager); // Variablenames are set directly in Viewmodel
KukaRobotPage kukaRobotPage = new() { DataContext = _kukaRobotPageVM };
CurrentDetailPage = kukaRobotPage;
break;
case nameof(MediaCabinetPage):
if (_mediaCabinetPageVM == null)
_mediaCabinetPageVM = new(_adsManager, "GVL_SCADA.stMachine.stMediaCabinet"); //TODO not Implemented on PLC yet
MediaCabinetPage mediaCabinetPage = new() { DataContext= _mediaCabinetPageVM };
CurrentDetailPage = mediaCabinetPage;
break;
default:
CurrentDetailPage = new Page();
break;
}
}
[RelayCommand]
private void AckAlarms()
{
_adsManager.WriteValue("GVL_SCADA.stConfirmAlarmsBtn.xRequest", true);
}
public void Dispose()
{
// Dispose current pages viewmodel
if (CurrentDetailPage.DataContext is IDisposable viewModel)
{
CurrentDetailPage.DataContext = null;
viewModel.Dispose();
}
DummyStringVM.Dispose();
}
}