Imports System.Windows.Threading Imports EgtBEAMWALL.Core Imports EgtWPFLib5 Public Class NestingRunningWndVM Inherits VMBase #Region "FIELDS & PROPERTIES" Friend Event m_CloseWindow(bDialogResult As Boolean) Private m_Waiting_Timer As New DispatcherTimer Private m_TotIntervals As Integer = 0 Private m_Step As Double = 1 Private m_Progress_Value As Double = 0 Private m_SectionList As List(Of SParam) Public Property Progress_Value As Double Get Return m_Progress_Value End Get Set(value As Double) m_Progress_Value = value End Set End Property #Region "Messages" Public ReadOnly Property NestingRunning_Msg As String Get Return "Nesting running..." End Get End Property #End Region ' Messages ' Definizione comandi Private m_cmdCancel As ICommand #End Region ' FIELDS & PROPERTIES Sub New(SectionList As List(Of SParam), TimeToWait As Double) m_SectionList = SectionList m_TotIntervals = Math.Ceiling(TimeToWait) m_Step = 100 / m_TotIntervals ' avvio contatore m_Waiting_Timer.Interval = TimeSpan.FromMilliseconds(1000) AddHandler m_Waiting_Timer.Tick, AddressOf WaitingTimer_Tick m_Waiting_Timer.Start() End Sub Private Sub WaitingTimer_Tick() m_Progress_Value += m_Step NotifyPropertyChanged(NameOf(Progress_Value)) End Sub Friend Sub DoNesting() 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) ' recupero parametri di calcolo 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 = WarehouseHelper.GetOffset(Map.refProjectVM.BTLStructureVM.nPROJTYPE) Dim dStartOffset As Double = 0 Dim dKerf As Double = 0 Select Case WhType Case WarehouseType.BASIC Dim nQuantity As Integer = WarehouseHelper.GetQuantity(Map.refProjectVM.BTLStructureVM.nPROJTYPE) If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then ' leggo lunghezza barra WarehouseHelper.GetCurrentDimensions(Map.refProjectVM.BTLStructureVM.nPROJTYPE, 0, dRawL) ' leggo start offset e quantity dStartOffset = WarehouseHelper.GetStartOffset() ' riporto la stessa lunghezza in tutte le sezioni For Each Section In m_SectionList Section.dL = dRawL Section.nQuantity = nQuantity Next ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then If Not WarehouseHelper.GetCurrentDimensions(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dRawW, dRawL) Then ' riabilito interfaccia Map.refProjectVM.SetCalcRunning(False) CloseNesting() Return End If ' leggo kerf e quantity dKerf = WarehouseHelper.GetKerf() ' riporto le stesse dimensioni in tutte le sezioni For Each Section In m_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 ' aggiungo le sezioni con diverse lunghezze in base al warehouse If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then ' leggo start offset dStartOffset = WarehouseHelper.GetStartOffset() ' leggo lunghezza barra e quantity WarehouseHelper.GetDimensionsAndQuantityForList(Map.refProjectVM.BTLStructureVM.nPROJTYPE, m_SectionList) ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then dKerf = WarehouseHelper.GetKerf() If Not WarehouseHelper.GetDimensionsAndQuantityForList(Map.refProjectVM.BTLStructureVM.nPROJTYPE, m_SectionList) Then ' riabilito interfaccia Map.refProjectVM.SetCalcRunning(False) CloseNesting() Return End If End If End Select ' attivo loading progress Map.refMyStatusBarVM.StartLoading("Nesting started", True) Dim DimensionsList As New List(Of List(Of SParam)) ' le raggruppo per sezione For Each Section In m_SectionList Dim Dimension As List(Of SParam) = DimensionsList.FirstOrDefault(Function(x) x(0).SectXMat = Section.SectXMat) If Not IsNothing(Dimension) Then Dimension.Add(Section) Else DimensionsList.Add(New List(Of SParam)({Section})) End If Next ' per ogni gruppo di sezioni For Each Dimension In DimensionsList '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 = Dimension(0).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 If Not ExecNesting(sLogPath, CurrentMachine.sMachineName, SectionPartList, Dimension, dStartOffset, dOffset, dKerf, nNestTime) Then Exit For End If 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.SetCalcRunning(False) ' fermo timer e chiudo finestra CloseNesting() End Sub Private Function CloseNesting() ' fermo timer e chiudo finestra m_Waiting_Timer.Stop() RaiseEvent m_CloseWindow(True) End Function #Region "COMMANDS" #Region "Cancel" ''' ''' Returns a command that do Open. ''' Public ReadOnly Property Cancel_Command As ICommand Get If m_cmdCancel Is Nothing Then m_cmdCancel = New Command(AddressOf Cancel) End If Return m_cmdCancel End Get End Property ''' ''' Execute the Open. This method is invoked by the OpenCommand. ''' Friend Sub Cancel() ' chiedo conferma If MessageBox.Show("Are you sure you want to stop the nesting?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.No Then Return ' fermo il nesting Map.refMyStatusBarVM.StopProgress() '' fermo timer e chiudo finestra 'CloseNesting() End Sub #End Region ' Cancel #End Region ' COMMANDS End Class