Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5

Public Class WallMachGroupVM
   Inherits MyMachGroupVM

   ' definizione comandi
   Private m_cmdDeleteMachGroup As ICommand

   Sub New(nId As Integer, sName As String, sMachine As String)
      MyBase.New(nId, sName, sMachine)
      SetMachineType(MachineType.WALL)
      m_nRawPartId = EgtGetFirstRawPart()
      EgtGetInfo(nId, MGR_RPT_PANELLEN, dL)
      EgtGetInfo(nId, MGR_RPT_PANELWIDTH, dW)
      EgtGetInfo(nId, MGR_RPT_PANELHEIGHT, dH)
      m_dTotMat = dL * dW
      For Each Part In PartMList
         m_dMatForPart += (Part.dL * Part.dW)
      Next
   End Sub

   Friend Sub UpdateUsage()
      m_dTotMat = dL * dW
      m_dMatForPart = 0
      For Each Part In PartMList
         m_dMatForPart += (Part.dL * Part.dW)
      Next
      '''NotifyPropertyChanged("dUsage")
      '''NotifyPropertyChanged("dWaste")
   End Sub

   Public Overrides Sub RefreshPartList()
      m_nRawPartId = EgtGetFirstRawPart()
      PartMList.Clear()
      Dim nPartId As Integer = EgtGetFirstPartInRawPart(m_nRawPartId)
      While nPartId <> GDB_ID.NULL
         PartMList.Add(New Wall(Me, nPartId))
         nPartId = EgtGetNextPartInRawPart(nPartId)
      End While
   End Sub

   Public Function CnFilePath() As String
      Return Map.refSupervisorManagerVM.CurrProd.sProdDirPath & "\" & Name & ".cnc"
   End Function

#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

   ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
   Public Overrides 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)
      ' rimuovo dalla lista grezzi
      '''Dim Index As Integer = Map.refMachGroupPanelVM.MachGroupVMList.IndexOf(Me) 
      '''If Index = 0 Then
      '''   If Map.refMachGroupPanelVM.MachGroupVMList.Count > 0 Then
      '''      Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(0)
      '''   Else
      '''      Map.refMachGroupPanelVM.SelectedMachGroup = Nothing
      '''   End If
      '''ElseIf Index = Map.refMachGroupPanelVM.MachGroupvmList.Count - 1 Then
      '''   If Map.refMachGroupPanelVM.MachGroupVMList.Count > 1 Then
      '''      Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(Map.refMachGroupPanelVM.MachGroupVMList.Count - 2)
      '''   Else
      '''      Map.refMachGroupPanelVM.SelectedMachGroup = Nothing
      '''   End If
      '''Else
      '''   Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(Index - 1)
      '''End If
      '''Map.refMachGroupPanelVM.MachGroupVMList.Remove(Me)
   End Sub

#End Region ' DeleteMachGroup

#End Region    ' COMMANDS

End Class
