Imports System.Collections.ObjectModel
Imports EgtBEAMWALL.Core
Imports EgtWPFLib5
Public Class OptimizePanelVM
Friend Enum PartType As Integer
MATERIAL = 0
ALL = 1
End Enum
Friend Enum OriginType As Integer
STANDARD = 0
FROM_BTL = 1
End Enum
Private m_PartTypeList As New List(Of IdNameStruct)({New IdNameStruct(PartType.MATERIAL, "Materiale"),
New IdNameStruct(PartType.ALL, "Tutti")})
Public ReadOnly Property PartTypeList As List(Of IdNameStruct)
Get
Return m_PartTypeList
End Get
End Property
Private m_SelPartType As IdNameStruct
Public Property SelPartType As IdNameStruct
Get
Return m_SelPartType
End Get
Set(value As IdNameStruct)
m_SelPartType = value
End Set
End Property
Private m_OriginTypeList As New List(Of IdNameStruct)({New IdNameStruct(OriginType.STANDARD, "Standard"),
New IdNameStruct(OriginType.FROM_BTL, "Da BTL")})
Public ReadOnly Property OriginTypeList As List(Of IdNameStruct)
Get
Return m_OriginTypeList
End Get
End Property
Private m_SelOriginType As IdNameStruct
Public Property SelOriginType As IdNameStruct
Get
Return m_SelOriginType
End Get
Set(value As IdNameStruct)
m_SelOriginType = value
End Set
End Property
' Definizione comandi
Private m_cmdOptimize As ICommand
Private m_cmdWarehouse As ICommand
Sub New()
m_SelPartType = PartTypeList(0)
m_SelOriginType = OriginTypeList(0)
End Sub
#Region "COMMANDS"
#Region "Optimize"
'''
''' Returns a command that do Open.
'''
Public ReadOnly Property Optimize_Command As ICommand
Get
If m_cmdOptimize Is Nothing Then
m_cmdOptimize = New Command(AddressOf Optimize)
End If
Return m_cmdOptimize
End Get
End Property
'''
''' Execute the Open. This method is invoked by the OpenCommand.
'''
Friend Sub Optimize()
If IsNothing(m_SelPartType) OrElse IsNothing(m_SelOriginType) Then Return
If IsNothing(Map.refProjectVM.BTLStructureVM.BTLPartVMList) OrElse Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count = 0 Then Return
Dim sLogPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\RawPartLog.txt"
Dim SectionList As New List(Of SParam)
' se ho selezionato nest per materiale e c'è una sezione selezionata diversa da sezione nulla
If m_SelPartType.Id = PartType.MATERIAL AndAlso Not IsNothing(Map.refProjectVM.BTLStructureVM.SelSection) AndAlso Map.refProjectVM.BTLStructureVM.SelSection.dH <> -1 Then
SectionList.Add(New SParam(Map.refProjectVM.BTLStructureVM.SelSection, 0, 0))
Else
For Each Section In Map.refProjectVM.BTLStructureVM.SectionList
If Section.dH = -1 Then Continue For
SectionList.Add(New SParam(Section, 0, 0))
Next
End If
Dim dRawL As Double = 0
Dim dRawW As Double = 0
Dim WhType = GetMainPrivateProfileInt(S_GENERAL, K_WAREHOUSE, 1)
Dim sWarehouseIniPath As String = ""
Dim dOffset As Double = 0
Dim dStartOffset As Double = 0
Dim dKerf As Double = 0
Select Case WhType
Case WarehouseType.BASIC
Dim nQuantity As Integer = 0
sWarehouseIniPath = Map.refMainWindowVM.MainWindowM.sWarehouseDir & "\" & WH_BASIC_INI_FILE_NAME
If Map.refMachinePanelVM.SelectedMachine.nType = MachineType.BEAM Then
' leggo lunghezza barra
Dim nCurrentL As Integer = EgtUILib.GenInterface.GetPrivateProfileInt(WRH_BEAM, WRH_CURRENT & WRH_S, 1, sWarehouseIniPath)
dRawL = EgtUILib.GenInterface.GetPrivateProfileInt(WRH_BEAM, WRH_L & nCurrentL, 0, sWarehouseIniPath)
' leggo start offset, offset e quantity
dStartOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_STARTOFFSET, 0, sWarehouseIniPath)
dOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_OFFSET, 0, sWarehouseIniPath)
Integer.TryParse(EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_QUANTITY, 0, sWarehouseIniPath), nQuantity)
' riporto la stessa lunghezza in tutte le sezioni
For Each Section In SectionList
Section.dL = dRawL
Section.nQuantity = nQuantity
Next
ElseIf Map.refMachinePanelVM.SelectedMachine.nType = MachineType.WALL Then
Dim nCurrentS As Integer = EgtUILib.GenInterface.GetPrivateProfileInt(WRH_WALL, WRH_CURRENT & WRH_S, nCurrentS, sWarehouseIniPath)
Dim sPanelDim As String = ""
Dim sPanelDims() As String
EgtUILib.GenInterface.GetPrivateProfileString(WRH_WALL, WRH_S & nCurrentS, "", sPanelDim, sWarehouseIniPath)
If Not String.IsNullOrWhiteSpace(sPanelDim) Then sPanelDims = sPanelDim.Split(","c)
If Not sPanelDims.Count = 2 OrElse Not StringToDouble(sPanelDims(0), dRawL) OrElse Not StringToDouble(sPanelDims(1), dRawW) Then Return
' leggo start offset, offset e quantity
dOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_OFFSET, 0, sWarehouseIniPath)
dKerf = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_KERF, 0, sWarehouseIniPath)
Integer.TryParse(EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_QUANTITY, 0, sWarehouseIniPath), nQuantity)
' riporto le stesse dimensioni in tutte le sezioni
For Each Section In SectionList
Section.dL = dRawL
Section.dW = dRawW
Section.nQuantity = nQuantity
Next
End If
Case WarehouseType.MEDIUM
Dim sCurrL As String
Dim nIndex As Integer = 1
sWarehouseIniPath = Map.refMainWindowVM.MainWindowM.sWarehouseDir & "\" & WH_MEDIUM_INI_FILE_NAME
' aggiungo le sezioni con diverse lunghezze in base al warehouse
If Map.refMachinePanelVM.SelectedMachine.nType = MachineType.BEAM Then
' leggo start offset ed offset
dStartOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_STARTOFFSET, 0, sWarehouseIniPath)
dOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_OFFSET, 0, sWarehouseIniPath)
' leggo lunghezza barra e quantity
While EgtUILib.GenInterface.GetPrivateProfileString(WRH_BEAM, WRH_CURRENT & nIndex, "", sCurrL, sWarehouseIniPath) > 0
Dim sLValues() As String = sCurrL.Split(","c)
For Each Section In SectionList
If Section.SectXMat.dW = sLValues(0) AndAlso Section.SectXMat.dH = sLValues(1) AndAlso Section.SectXMat.MaterialForSameSection_List(0) = sLValues(2) Then
StringToDouble(sLValues(3), Section.dL)
Integer.TryParse(sLValues(4), Section.nQuantity)
End If
Next
nIndex += 1
End While
ElseIf Map.refMachinePanelVM.SelectedMachine.nType = MachineType.WALL Then
Dim nCurrentS As Integer = EgtUILib.GenInterface.GetPrivateProfileInt(WRH_WALL, WRH_CURRENT & WRH_S, nCurrentS, sWarehouseIniPath)
Dim sPanelDim As String = ""
Dim sPanelDims() As String
EgtUILib.GenInterface.GetPrivateProfileString(WRH_WALL, WRH_S & nCurrentS, "", sPanelDim, sWarehouseIniPath)
If Not String.IsNullOrWhiteSpace(sPanelDim) Then sPanelDims = sPanelDim.Split(","c)
If Not sPanelDims.Count = 2 OrElse Not StringToDouble(sPanelDims(0), dRawL) OrElse Not StringToDouble(sPanelDims(1), dRawW) Then Return
dOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_OFFSET, 0, sWarehouseIniPath)
dKerf = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_KERF, 0, sWarehouseIniPath)
' leggo lunghezza barra e quantity
While EgtUILib.GenInterface.GetPrivateProfileString(WRH_WALL, WRH_CURRENT & nIndex, "", sCurrL, sWarehouseIniPath) > 0
Dim sLValues() As String = sCurrL.Split(","c)
For Each Section In SectionList
If Section.SectXMat.dH = sLValues(0) AndAlso Section.SectXMat.MaterialForSameSection_List(0) = sLValues(1) Then
StringToDouble(sLValues(2), Section.dW)
StringToDouble(sLValues(3), Section.dL)
Integer.TryParse(sLValues(4), Section.nQuantity)
End If
Next
nIndex += 1
End While
End If
End Select
' attivo loading progress
Map.refMyStatusBarVM.StartLoading("Nesting started", True)
For Each Section In SectionList
'Dim SectionPartList As New List(Of BTLPartM)(Map.refProjectVM.BTLStructureVM.BTLPartVMList.Where(Function(x) x.Section = Section.SectXMat).ToList())
Dim SectionPartList As List(Of BTLPartM) = (From x In Map.refProjectVM.BTLStructureVM.BTLPartVMList
Where x.Section = Section.SectXMat AndAlso x.bDO
Select x.BTLPartM).ToList()
' passo a lua lista id pezzi da nestare
ExecNesting(sLogPath, CurrentMachine.sMachineName, SectionPartList, Section.dL, Section.dW, dStartOffset, dOffset, dKerf, Section.nQuantity)
Next
' update liste grezzi e pezzi della grafica
Map.refProjectVM.MachGroupPanelVM.RefreshMachGroupList()
' disattivo loading progress
Map.refMyStatusBarVM.EndLoading("Nesting completed")
' seleziono ultimo gruppo
Map.refProjectVM.MachGroupPanelVM.SelLastMachGroup()
End Sub
#End Region ' Optimize
#Region "Warehouse"
'''
''' Returns a command that do Open.
'''
Public ReadOnly Property Warehouse_Command As ICommand
Get
If m_cmdWarehouse Is Nothing Then
m_cmdWarehouse = New Command(AddressOf Warehouse)
End If
Return m_cmdWarehouse
End Get
End Property
'''
''' Execute the Open. This method is invoked by the OpenCommand.
'''
Friend Sub Warehouse()
Dim WarehouseWnd As New WarehouseWndV(Application.Current.MainWindow, New WarehouseWndVM())
WarehouseWnd.ShowDialog()
End Sub
#End Region ' Warehouse
#End Region ' COMMANDS
End Class