Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/OptimizePanel/OptimizePanelVM.vb
T
Emmanuele Sassi 891bbd4a08 Aggiunto materiale su Machgroup
Corretta sezione
Rimossa selezione grezzo
Gestione blocco interfaccia su verifica e simula
Aggiunta correzione con cancellazione cartelle progetti
Tolto ricaricmento progetto nel passaggio da proj a prod
Iniziat studio esportazione statistiche
Migliorati messaggi su nesting
Cambiata gestione tipo progetto
2021-06-29 11:38:19 +02:00

289 lines
12 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtBEAMWALL.Core
Imports EgtUILib
Imports EgtWPFLib5
Public Class OptimizePanelVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
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
Private m_OptimizePanel_IsEnabled As Boolean = True
Public ReadOnly Property OptimizePanel_IsEnabled As Boolean
Get
Return m_OptimizePanel_IsEnabled
End Get
End Property
#Region "Messages"
Public ReadOnly Property Optimize_Msg As String
Get
Return EgtMsg(61833)
End Get
End Property
Public ReadOnly Property Warehouse_ToolTip As String
Get
Return EgtMsg(61920)
End Get
End Property
#End Region ' Messages
' Definizione comandi
Private m_cmdOptimize As ICommand
Private m_cmdWarehouse As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' aggiungo riferimento a Map
Map.SetRefOptimizePanelVM(Me)
m_SelPartType = PartTypeList(0)
m_SelOriginType = OriginTypeList(0)
NotifyPropertyChanged(NameOf(SelPartType))
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub SetOptimizePanelIsEnabled(bIsEnabled As Boolean)
m_OptimizePanel_IsEnabled = bIsEnabled
NotifyPropertyChanged(NameOf(OptimizePanel_IsEnabled))
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "Optimize"
''' <summary>
''' Returns a command that do Open.
''' </summary>
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
''' <summary>
''' Execute the Open. This method is invoked by the OpenCommand.
''' </summary>
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 dSectionTime As Double = GetMainPrivateProfileDouble(S_NEST, K_SECTIONTIME, 1)
Dim dPartTime As Double = GetMainPrivateProfileDouble(S_NEST, K_PARTTIME, 1)
Dim SectionList As New List(Of SParam)
' disabilito interfaccia
Map.refProjectVM.ManageIsEnabled(False)
' 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
' altrimenti prendo tutte le sezioni
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.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
' leggo lunghezza barra
Dim nCurrentL As Integer = EgtUILib.GenInterface.GetPrivateProfileInt(WRH_BEAM, WRH_CURRENT & WRH_L, 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.refProjectVM.BTLStructureVM.nPROJTYPE = 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
' riabilito interfaccia
Map.refProjectVM.ManageIsEnabled(True)
Return
End If
' 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.refProjectVM.BTLStructureVM.nPROJTYPE = 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.refProjectVM.BTLStructureVM.nPROJTYPE = 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
' riabilito interfaccia
Map.refProjectVM.ManageIsEnabled(True)
Return
End If
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()
Dim nNestTime As Integer = Math.Max(5, dSectionTime) + (dPartTime * SectionPartList.Count)
' passo a lua lista id pezzi da nestare
ExecNesting(sLogPath, CurrentMachine.sMachineName, SectionPartList, Section.dL, Section.dW, dStartOffset, dOffset, dKerf, Section.nQuantity, nNestTime)
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()
' riabilito interfaccia
Map.refProjectVM.ManageIsEnabled(True)
End Sub
#End Region ' Optimize
#Region "Warehouse"
''' <summary>
''' Returns a command that do Open.
''' </summary>
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
''' <summary>
''' Execute the Open. This method is invoked by the OpenCommand.
''' </summary>
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