Miglioramento gestione nesting

This commit is contained in:
Emmanuele Sassi
2021-10-08 12:47:27 +02:00
parent a957ae1183
commit aae8557dca
9 changed files with 360 additions and 94 deletions
+1 -1
View File
@@ -549,7 +549,7 @@ Public MustInherit Class PartVM
Public Sub CalcGlobalUpdate()
m_PartM.nCALC_GlobalState = nCALC_State
For Each Feature In FeatureVMList
If Feature.bDO Then Continue For
If Not Feature.bDO Then Continue For
If Feature.nState > m_PartM.nCALC_GlobalState Then
m_PartM.nCALC_GlobalState = Feature.nState
m_PartM.nCALC_GlobalERR = Feature.nCALC_ERR
@@ -201,6 +201,10 @@
<Compile Include="MachGroupPanel\MyMachGroupPanelVM.vb" />
<Compile Include="MachGroupPanel\MyMachGroupVM.vb" />
<Compile Include="MachGroupPanel\PartVM.vb" />
<Compile Include="NestingRunningWnd\NestingRunningWndV.xaml.vb">
<DependentUpon>NestingRunningWndV.xaml</DependentUpon>
</Compile>
<Compile Include="NestingRunningWnd\NestingRunningWndVM.vb" />
<Compile Include="ProjectTypeWnd\ProjectTypeWndV.xaml.vb">
<DependentUpon>ProjectTypeWndV.xaml</DependentUpon>
</Compile>
@@ -378,6 +382,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="NestingRunningWnd\NestingRunningWndV.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ProjectTypeWnd\ProjectTypeWndV.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@@ -350,7 +350,7 @@ Public Class MyMachGroupVM
Dim Index As Integer = Map.refMachGroupPanelVM.MachGroupVMList.IndexOf(Me)
If Index = 0 Then
If Map.refMachGroupPanelVM.MachGroupVMList.Count > 1 Then
Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(0)
Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(1)
Else
Map.refMachGroupPanelVM.SelectedMachGroup = Nothing
EgtDraw()
@@ -0,0 +1,37 @@
<EgtWPFLib5:EgtCustomWindow x:Class="NestingRunningWndV"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:EgtWPFLib5="clr-namespace:EgtWPFLib5;assembly=EgtWPFLib5"
Style="{DynamicResource {x:Type EgtWPFLib5:EgtCustomWindow}}"
Height="200" Width="300"
IsClosable="False" IsMinimizable="False"
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="1"
Text="{Binding NestingRunning_Msg}"
TextAlignment="Center"/>
<ProgressBar Grid.Row="3"
Minimum="0"
Maximum="100"
Value="{Binding Progress_Value}"
Height="20"
Margin="40,0,40,0"/>
<Button Grid.Row="5" Content="Cancel"
IsDefault="False"
IsCancel="True"
Width="70"
Style="{StaticResource ToolBar_Button}"
Command="{Binding Cancel_Command}"/>
</Grid>
</EgtWPFLib5:EgtCustomWindow>
@@ -0,0 +1,22 @@
Public Class NestingRunningWndV
Private WithEvents m_NestingRunningWndVM As NestingRunningWndVM
Sub New(Owner As Window, NestingRunningWndVM As NestingRunningWndVM)
MyBase.New(Owner)
' This call is required by the designer.
InitializeComponent()
Me.DataContext = NestingRunningWndVM
' Assegno al riferimento locale al VM il VM preso dal DataContext
m_NestingRunningWndVM = NestingRunningWndVM
End Sub
Private Sub CloseWindow(bDialogResult As Boolean) Handles m_NestingRunningWndVM.m_CloseWindow
Me.DialogResult = bDialogResult
End Sub
Private Sub Me_ContentRendered() Handles Me.ContentRendered
m_NestingRunningWndVM.DoNesting()
End Sub
End Class
@@ -0,0 +1,191 @@
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"
''' <summary>
''' Returns a command that do Open.
''' </summary>
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
''' <summary>
''' Execute the Open. This method is invoked by the OpenCommand.
''' </summary>
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
@@ -61,7 +61,6 @@ Public Class OptimizePanelVM
End Get
End Property
#Region "Messages"
Public ReadOnly Property Optimize_Msg As String
@@ -130,102 +129,115 @@ Public Class OptimizePanelVM
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 dTotSectionTime As Double = 0
Dim dTotPartTime As Double = 0
Dim SectionList As New List(Of SParam)
' disabilito interfaccia
Map.refProjectVM.SetCalcRunning(True)
' 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))
dTotSectionTime = dSectionTime
dTotPartTime = dPartTime * Map.refProjectVM.BTLStructureVM.BTLPartVMList.Sum(Function(x) If(x.bDO AndAlso x.Section = SectionList(0).SectXMat, 1, 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))
For Each CurrSection In Map.refProjectVM.BTLStructureVM.SectionList
If CurrSection.dH = -1 Then Continue For
SectionList.Add(New SParam(CurrSection, 0, 0))
dTotSectionTime += dSectionTime
Next
dTotPartTime = dPartTime * Map.refProjectVM.BTLStructureVM.BTLPartVMList.Sum(Function(x) If(x.bDO AndAlso SectionList.Any(Function(y) y.SectXMat = x.Section), 1, 0))
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 = 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 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)
Return
End If
' leggo kerf e quantity
dKerf = WarehouseHelper.GetKerf()
' 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
' 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, SectionList)
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then
dKerf = WarehouseHelper.GetKerf()
If Not WarehouseHelper.GetDimensionsAndQuantityForList(Map.refProjectVM.BTLStructureVM.nPROJTYPE, SectionList) Then
' riabilito interfaccia
Map.refProjectVM.SetCalcRunning(False)
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 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
ExecNesting(sLogPath, CurrentMachine.sMachineName, SectionPartList, Dimension, dStartOffset, dOffset, dKerf, 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.SetCalcRunning(False)
' apro finestra di attesa nesting
Dim NestingRunninWndVM As New NestingRunningWndVM(SectionList, dTotSectionTime + dTotPartTime)
Dim NestingRunningWnd As New NestingRunningWndV(Application.Current.MainWindow, NestingRunninWndVM)
NestingRunningWnd.ShowDialog()
'' 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 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)
' Return
' End If
' ' leggo kerf e quantity
' dKerf = WarehouseHelper.GetKerf()
' ' 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
' ' 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, SectionList)
' ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then
' dKerf = WarehouseHelper.GetKerf()
' If Not WarehouseHelper.GetDimensionsAndQuantityForList(Map.refProjectVM.BTLStructureVM.nPROJTYPE, SectionList) Then
' ' riabilito interfaccia
' Map.refProjectVM.SetCalcRunning(False)
' 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 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
' ExecNesting(sLogPath, CurrentMachine.sMachineName, SectionPartList, Dimension, dStartOffset, dOffset, dKerf, 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.SetCalcRunning(False)
'' chiudo finestra di attesa nesting
'NestingRunninWndVM.Cancel()
End Sub
#End Region ' Optimize
@@ -100,7 +100,7 @@ Public Class MyStatusBarVM
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub StopProgress(ByVal param As Object)
Public Sub StopProgress()
m_bStopProgress = True
End Sub
@@ -144,10 +144,6 @@ Module WarehouseHelper
End Select
nIndex += 1
End While
'If CheckList.Count <> SectionList.Count Then Return False
'For i = 0 To CheckList.Count - 1
' If Not CheckList.Contains(i) Then Return False
'Next
SectionList = NewSectionList
Return True
End Function