Files
egtbeamwall/EgtBEAMWALL.Supervisor/MachGroupPanel/MyMachGroupVM.vb
T
2021-04-28 14:10:19 +02:00

254 lines
7.2 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Windows.Input
Imports System.Windows.Media
Imports EgtBEAMWALL.Core
Imports EgtUILib
Imports EgtWPFLib5
Public MustInherit Class MyMachGroupVM
Inherits MachGroupVM
Public ReadOnly Property MyMachGroupM As MyMachGroupM
Get
Return m_MachGroupM
End Get
End Property
Public ReadOnly Property nMachineType As MachineType
Get
Return MyMachGroupM.nMachineType
End Get
End Property
Public Property dL As Double
Get
Return MyMachGroupM.dL
End Get
Set(value As Double)
MyMachGroupM.dL = value
End Set
End Property
Public Property dW As Double
Get
Return MyMachGroupM.dW
End Get
Set(value As Double)
MyMachGroupM.dW = value
End Set
End Property
Public Property dH As Double
Get
Return MyMachGroupM.dH
End Get
Set(value As Double)
MyMachGroupM.dH = value
End Set
End Property
Public Property dtStartTime As DateTime
Get
Return MyMachGroupM.dtStartTime
End Get
Set(value As DateTime)
MyMachGroupM.dtStartTime = value
NotifyPropertyChanged(NameOf(Calc_Background))
End Set
End Property
Public Property dtEndTime As DateTime
Get
Return MyMachGroupM.dtEndTime
End Get
Set(value As DateTime)
MyMachGroupM.dtEndTime = value
NotifyPropertyChanged(NameOf(Calc_Background))
End Set
End Property
Public ReadOnly Property dUsage As Double
Get
Return If(MyMachGroupM.dMatForPart > 0 AndAlso MyMachGroupM.dTotMat > 0, MyMachGroupM.dMatForPart / MyMachGroupM.dTotMat * 100, 0)
End Get
End Property
Public ReadOnly Property dWaste As Double
Get
Return If(MyMachGroupM.dMatForPart > 0 AndAlso MyMachGroupM.dTotMat > 0, (MyMachGroupM.dTotMat - MyMachGroupM.dMatForPart) / MyMachGroupM.dTotMat * 100, 0)
End Get
End Property
Public ReadOnly Property sUsage As String
Get
Return dUsage & "%"
End Get
End Property
Public ReadOnly Property sWaste As String
Get
Return dWaste & "%"
End Get
End Property
Public Property sMATERIAL As String
Get
Return MyMachGroupM.sMATERIAL
End Get
Set(value As String)
MyMachGroupM.sMATERIAL = value
End Set
End Property
' lista dei pezzi che sono nel grezzo
Protected m_PartVMList As New ObservableCollection(Of PartVM)
Public Property PartVMList As ObservableCollection(Of PartVM)
Get
Return m_PartVMList
End Get
Set(value As ObservableCollection(Of PartVM))
m_PartVMList = value
End Set
End Property
Protected m_SelPart As PartVM
Public Overridable Property SelPart As PartVM
Get
Return m_SelPart
End Get
Set(value As PartVM)
m_SelPart = value
' seleziono pezzo
EgtDeselectAll()
If Not IsNothing(value) Then EgtSelectObj(SelPart.nPartId)
EgtDraw()
NotifyPropertyChanged(NameOf(SelPart))
End Set
End Property
Public ReadOnly Property nState As CalcStates
Get
Return MyMachGroupM.nState
End Get
End Property
Public ReadOnly Property Calc_Background As SolidColorBrush
Get
If dtEndTime <> DateTime.MinValue Then ' barra finita
Return Brushes.LightGray
ElseIf dtStartTime <> DateTime.MinValue Then ' barra iniziata
Return Brushes.Green
ElseIf m_bToBeProduced Then ' barra in attesa
Return Brushes.Yellow
Else ' barra in coda
Return Brushes.White
End If
End Get
End Property
' indica se il pezzo deve essere tagliato
Private m_bToBeProduced As Boolean = False
Public ReadOnly Property bToBeProduced As Boolean
Get
Return m_bToBeProduced
End Get
End Property
' indica se il pezzo e' gia' stato ricalcolato e quindi pronto a partire
Private m_bCNReCalculated As Boolean = False
Public ReadOnly Property bReadyForMachining As Boolean
Get
Return m_bToBeProduced AndAlso m_bCNReCalculated
End Get
End Property
' definizione comandi
Private m_cmdProduceMachGroup As ICommand
Sub New(MyMachGroupM As MyMachGroupM)
MyBase.New(MyMachGroupM)
'aggiorno lista pezzi
RefreshPartList()
End Sub
#Region "METHODS"
Friend Sub ResetProduce()
m_bCNReCalculated = False
m_bToBeProduced = False
End Sub
#End Region ' METHODS
Public MustOverride Sub RefreshPartList()
Public MustOverride Sub RefreshGroupData()
Public Overridable Sub DeleteMachGroup()
' elimino tutte le copie
Dim nRawPartId As Integer = EgtGetFirstRawPart()
Dim nBeamId As Integer = EgtGetFirstPartInRawPart(nRawPartId)
While nRawPartId <> GDB_ID.NULL
EgtRemovePartFromRawPart(nBeamId)
EgtErase(nBeamId)
nRawPartId = EgtGetNextRawPart(nRawPartId)
nBeamId = EgtGetFirstPartInRawPart(nRawPartId)
End While
' elimino MachGroup
EgtRemoveMachGroup(Me.Id)
End Sub
Public Sub CalcMachGroupUpdate()
MyMachGroupM.SetState(CalcStates.OK)
For Each Part In PartVMList
If Part.nGlobalState > 0 AndAlso nState = CalcStates.OK Then
MyMachGroupM.SetState(CalcStates.ERROR_)
End If
Next
NotifyPropertyChanged(NameOf(Calc_Background))
End Sub
Public Function CnFilePath() As String
Return Map.refSupervisorManagerVM.CurrProd.sProdDirPath & "\" & Id & ".cnc"
End Function
#Region "COMMANDS"
#Region "ProduceMachGroup"
' Returns a command that manage the MainWindow_Unloaded command
Public ReadOnly Property ProduceMachGroup_Command As ICommand
Get
If m_cmdProduceMachGroup Is Nothing Then
m_cmdProduceMachGroup = New Command(AddressOf ProduceMachGroup)
End If
Return m_cmdProduceMachGroup
End Get
End Property
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
Public Sub ProduceMachGroup()
' cerco primo indice di pezzo non in produzione
Dim NewIndex As Integer = Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.IndexOf(Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x) DirectCast(x, MyMachGroupVM).dtStartTime = DateTime.MinValue AndAlso DirectCast(x, MyMachGroupVM).bToBeProduced = False))
' segno pezzo da produrre
m_bToBeProduced = True
' ricalcolo il CN
m_bCNReCalculated = True
' sposto MachGroup in lista come ultimo dei pronti da produrre
Dim OldIndex As Integer = Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.IndexOf(Me)
DbControllers.m_MachGroupController.UpdateOrder(Map.refSupervisorManagerVM.CurrProd.nProdId, Id, NewIndex)
Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.Move(OldIndex, NewIndex)
NotifyPropertyChanged(NameOf(nState))
NotifyPropertyChanged(NameOf(Calc_Background))
End Sub
#End Region ' DeleteMachGroup
#End Region ' COMMANDS
End Class