Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/MachGroupPanel/MyMachGroupVM.vb
T
Emmanuele Sassi bac7b490be Correzioni e migliorie
Aggiunto reset stato calc in prod su modifiche
2021-06-16 09:31:07 +02:00

378 lines
11 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
End Set
End Property
Public Property dtEndTime As DateTime
Get
Return MyMachGroupM.dtEndTime
End Get
Set(value As DateTime)
MyMachGroupM.dtEndTime = value
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 DoubleToString(dUsage, 3)
End Get
End Property
Public ReadOnly Property sWaste As String
Get
Return DoubleToString(dWaste, 3)
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 nCALC_ERR As Integer
Get
Return MyMachGroupM.nCALC_ERR
End Get
End Property
Public ReadOnly Property nCALC_FALL As Integer
Get
Return MyMachGroupM.nCALC_FALL
End Get
End Property
Public ReadOnly Property sCALC_MSG As String
Get
Return MyMachGroupM.sCALC_MSG
End Get
End Property
Public Property nCALC_ROT As Integer
Get
Return MyMachGroupM.nCALC_ROT
End Get
Set(value As Integer)
MyMachGroupM.nCALC_ROT = value
End Set
End Property
Public Property nCALC_TIME As Integer
Get
Return MyMachGroupM.nCALC_TIME
End Get
Set(value As Integer)
MyMachGroupM.nCALC_TIME = value
End Set
End Property
Public Property nGlobalState As CalcStates
Get
Return MyMachGroupM.nCALC_GlobalState
End Get
Set(value As CalcStates)
MyMachGroupM.nCALC_GlobalState = value
End Set
End Property
Public Property nState As CalcStates
Get
Return MyMachGroupM.nCALC_State
End Get
Set(value As CalcStates)
MyMachGroupM.nCALC_State = value
End Set
End Property
Public ReadOnly Property nProductionState As Integer
Get
Return MyMachGroupM.nProductionState
End Get
End Property
Public ReadOnly Property Calc_Background As SolidColorBrush
Get
If MyMachGroupM.nCALC_GlobalState = CalcStates.OK Then
Return Brushes.Green
ElseIf MyMachGroupM.nCALC_GlobalState = CalcStates.NOTCALCULATED Then
Return Brushes.LightGray
ElseIf MyMachGroupM.nCALC_GlobalState = CalcStates.INFO Then
Return Brushes.Green
ElseIf MyMachGroupM.nCALC_GlobalState = CalcStates.WARNING Then
Return Brushes.Gold
ElseIf MyMachGroupM.nCALC_GlobalState = CalcStates.ERROR_ Then
Return Brushes.Red
Else
Return Brushes.Red
End If
End Get
End Property
Public ReadOnly Property CALC_ROT_Visibility As Visibility
Get
Return If(MyMachGroupM.nCALC_ROT <> 0, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Public ReadOnly Property CALC_FALL_Visibility As Visibility
Get
Return If(MyMachGroupM.nCALC_FALL <> 0, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Public ReadOnly Property CALC_ERR_Letter As String
Get
Select Case MyMachGroupM.nCALC_GlobalERR
Case 22
Return "c"
Case 19, 23, 24, 25
Return "e"
Case 17
Return "w"
Case < 0
Return "i"
Case Else
Return ""
End Select
End Get
End Property
Public ReadOnly Property CALC_ERR_Foreground As SolidColorBrush
Get
Select Case MyMachGroupM.m_nCALC_GlobalState
Case CalcStates.ERROR_
Return Brushes.Red
Case CalcStates.WARNING
Return Brushes.Orange
Case CalcStates.INFO
Return Brushes.Green
Case Else
Return Brushes.Red
End Select
End Get
End Property
' definizione comandi
Private m_cmdDeleteMachGroup As ICommand
Sub New(MyMachGroupM As MyMachGroupM)
MyBase.New(MyMachGroupM)
'aggiorno lista pezzi
RefreshPartList()
End Sub
#Region "METHODS"
Friend MustOverride Function Copy() As MyMachGroupVM
#End Region ' METHODS
Public MustOverride Sub RefreshPartList()
Public MustOverride Sub RefreshGroupData()
' funzione che aggiorna lo stato e gli errori dopo calcolo
Friend Sub CalcMachGroupUpdate(ERR As Integer, ROT As Integer, MSG As String)
EgtSetInfo(Id, ITG_PROD_ERR, ERR, True)
EgtSetInfo(Id, ITG_PROD_MSG, MSG, True)
EgtSetInfo(Id, ITG_PROD_ROT, ROT, True)
MyMachGroupM.nCALC_ERR = ERR
MyMachGroupM.nCALC_ROT = ROT
MyMachGroupM.sCALC_MSG = MSG
If ERR = 0 Then
nState = CalcStates.OK
ElseIf ERR = 17 Then
nState = CalcStates.WARNING
ElseIf ERR > 0 Then
nState = CalcStates.ERROR_
ElseIf ERR < 0 Then
nState = CalcStates.INFO
End If
NotifyPropertyChanged(NameOf(Calc_Background))
End Sub
Friend Sub ResetCalcMachGroup()
EgtRemoveInfo(Id, ITG_PROJ_ERR)
EgtRemoveInfo(Id, ITG_PROJ_MSG)
EgtRemoveInfo(Id, ITG_PROJ_ROT)
MyMachGroupM.nCALC_GlobalState = CalcStates.NOTCALCULATED
MyMachGroupM.nCALC_State = CalcStates.NOTCALCULATED
MyMachGroupM.nCALC_GlobalERR = 0
MyMachGroupM.nCALC_ERR = 0
MyMachGroupM.nCALC_ROT = 0
MyMachGroupM.nCALC_FALL = 0
MyMachGroupM.sCALC_MSG = ""
NotifyPropertyChanged(NameOf(Calc_Background))
NotifyPropertyChanged(NameOf(CALC_FALL_Visibility))
NotifyPropertyChanged(NameOf(CALC_ROT_Visibility))
NotifyPropertyChanged(NameOf(CALC_ERR_Letter))
NotifyPropertyChanged(NameOf(CALC_ERR_Foreground))
End Sub
' funzione che aggiorna lo stato e gli errori dopo calcolo
Friend Sub CalcGlobalUpdate()
MyMachGroupM.nCALC_GlobalERR = nCALC_ERR
MyMachGroupM.nCALC_GlobalState = nState
For Each Part In MyMachGroupM.PartMList
If Part.nCALC_GlobalState = CalcStates.NOTCALCULATED Then
MyMachGroupM.nCALC_GlobalState = CalcStates.NOTCALCULATED
Exit For
ElseIf Part.nCALC_GlobalState = CalcStates.OK AndAlso MyMachGroupM.m_nCALC_GlobalState = Core.CalcStates.NOTCALCULATED Then
MyMachGroupM.nCALC_GlobalState = CalcStates.OK
ElseIf Part.nCALC_GlobalState = CalcStates.INFO And (MyMachGroupM.nCALC_GlobalState = CalcStates.OK Or MyMachGroupM.nCALC_GlobalState = CalcStates.NOTCALCULATED) Then
MyMachGroupM.nCALC_GlobalState = CalcStates.INFO
ElseIf Part.nCALC_GlobalState = CalcStates.WARNING And (MyMachGroupM.nCALC_GlobalState = CalcStates.OK Or MyMachGroupM.nCALC_GlobalState = CalcStates.INFO Or MyMachGroupM.nCALC_GlobalState = CalcStates.NOTCALCULATED) Then
MyMachGroupM.nCALC_GlobalState = CalcStates.WARNING
ElseIf Part.nCALC_GlobalState = CalcStates.ERROR_ And (MyMachGroupM.nCALC_GlobalState = CalcStates.OK Or MyMachGroupM.nCALC_GlobalState = CalcStates.INFO Or MyMachGroupM.nCALC_GlobalState = CalcStates.WARNING Or MyMachGroupM.nCALC_GlobalState = CalcStates.NOTCALCULATED) Then
MyMachGroupM.nCALC_GlobalState = CalcStates.ERROR_
End If
If Part.nCALC_GlobalERR = 22 Then
MyMachGroupM.nCALC_GlobalERR = 22
ElseIf Part.nCALC_GlobalERR > 0 And MyMachGroupM.nCALC_GlobalERR <= 0 Then
MyMachGroupM.nCALC_GlobalERR = Part.nCALC_GlobalERR
ElseIf Part.nCALC_GlobalERR < 0 And MyMachGroupM.nCALC_GlobalERR = 0 Then
MyMachGroupM.nCALC_GlobalERR = Part.nCALC_GlobalERR
End If
If Part.nCALC_ROT <> 0 Then
MyMachGroupM.m_nCALC_ROT = Part.nCALC_ROT
End If
If Part.nCALC_FALL <> 0 Then
MyMachGroupM.nCALC_FALL = Part.nCALC_FALL
End If
Next
NotifyPropertyChanged(NameOf(Calc_Background))
NotifyPropertyChanged(NameOf(CALC_FALL_Visibility))
NotifyPropertyChanged(NameOf(CALC_ROT_Visibility))
NotifyPropertyChanged(NameOf(CALC_ERR_Letter))
NotifyPropertyChanged(NameOf(CALC_ERR_Foreground))
End Sub
#Region "COMMANDS"
#Region "DeleteMachGroup"
' Returns a command that manage the MainWindow_Unloaded command
Public ReadOnly Property DeleteMachGroup_Command As ICommand
Get
If m_cmdDeleteMachGroup Is Nothing Then
m_cmdDeleteMachGroup = New Command(AddressOf DeleteMachGroup)
End If
Return m_cmdDeleteMachGroup
End Get
End Property
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
#End Region ' DeleteMachGroup
#End Region ' COMMANDS
End Class