Imports System.Collections.ObjectModel 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.BTLStructure.PartList) OrElse Map.refProjectVM.BTLStructure.PartList.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.BTLStructure.SelSection) AndAlso Map.refProjectVM.BTLStructure.SelSection.dH <> -1 Then SectionList.Add(New SParam(Map.refProjectVM.BTLStructure.SelSection, 0, 0)) Else For Each Section In Map.refProjectVM.BTLStructure.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 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 ed offset dStartOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_STARTOFFSET, 0, sWarehouseIniPath) dOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_OFFSET, 0, sWarehouseIniPath) ' riporto la stessa lunghezza in tutte le sezioni For Each Section In SectionList Section.dL = dRawL 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 dOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_OFFSET, 0, sWarehouseIniPath) dKerf = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_KERF, 0, sWarehouseIniPath) ' riporto le stesse dimensioni in tutte le sezioni For Each Section In SectionList Section.dL = dRawL Section.dW = dRawW Next End If Case WarehouseType.MEDIUM 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 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 ed offset dStartOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_STARTOFFSET, 0, sWarehouseIniPath) dOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_OFFSET, 0, sWarehouseIniPath) ' riporto la stessa lunghezza in tutte le sezioni For Each Section In SectionList Section.dL = dRawL 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 dOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_OFFSET, 0, sWarehouseIniPath) dKerf = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_KERF, 0, sWarehouseIniPath) ' riporto le stesse dimensioni in tutte le sezioni For Each Section In SectionList Section.dL = dRawL Section.dW = dRawW Next End If End Select ' attivo loading progress Map.refMyStatusBarVM.StartLoading("Nesting started", True) For Each Section In SectionList Dim SectionPartList As New List(Of Core.BTLPart)(Map.refProjectVM.BTLStructure.PartList.Where(Function(x) x.Section = Section.SectXMat).ToList()) ' passo a lua lista id pezzi da nestare ExecNesting(sLogPath, CurrentMachine.sMachineName, SectionPartList, Section.dL, Section.dW, dStartOffset, dOffset, dKerf) Next ' update liste grezzi e pezzi della grafica Map.refProjectVM.MachGroupPanelVM.InitMachGroupList() ' 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