Files
egtbeamwall/EgtBEAMWALL.Optimizer/OptimizePanel/OptimizePanelVM.vb
T
Emmanuele Sassi afe74550ff - correzione su bDo della feature nella barra
- riattivazione righe dopo errore di calcolo
- riaggiunte operazioni da fare a fine calcolo tipo salvataggio
- corretta gestione focus tagella grezzi che selezionava due righe aggiungendo una nuova barra
- corretto errore con solido portato in barra
2026-08-04 09:45:38 +02:00

841 lines
36 KiB
VB.net

Imports System.Threading
Imports EgtBEAMWALL.Core
Imports EgtUILib
Imports EgtWPFLib5
Imports System.IO
Public Class OptimizePanelVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Friend m_bNestingRunning As Boolean = False
Friend m_StopNesting As Boolean = False
Public 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, EgtMsg(61957)),
New IdNameStruct(PartType.ALL, EgtMsg(61956))})
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, EgtMsg(61964)),
New IdNameStruct(OriginType.FROM_BTL, EgtMsg(61965))})
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
NotifyPropertyChanged(NameOf(NestingOption_Visibility))
End Set
End Property
Private m_bLDIntersOther As Boolean = False
Public Property bLDIntersOther As Boolean
Get
Return m_bLDIntersOther
End Get
Set(value As Boolean)
m_bLDIntersOther = value
WriteMainPrivateProfileString(S_NEST, K_LDINTERSOTHER, If(m_bLDIntersOther, 1, 0))
End Set
End Property
Public ReadOnly Property NestingOption_Visibility As Visibility
Get
If CurrentMachine.nType = MachineType.WALL OrElse CurrentMachine.nType = MachineType.BOTH Then
If CurrentMachine.dHorDrillDiam > 0 And Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.NESTING_AUTO) And m_SelOriginType.Id = OriginType.STANDARD Then
Return Visibility.Visible
End If
End If
Return Visibility.Collapsed
End Get
End Property
Private m_nMinScore As Integer
Public Property dMinScore As Double
Get
Return m_nMinScore
End Get
Set(value As Double)
m_nMinScore = Math.Floor(Math.Min(100, Math.Max(value, 0)))
WriteMainPrivateProfileString(S_NEST, K_MINSCORE, m_nMinScore)
End Set
End Property
Private m_Optimize_IsEnabled As Boolean = True
Public ReadOnly Property Optimize_IsEnabled As Boolean
Get
Return m_Optimize_IsEnabled
End Get
End Property
Private m_CalcRotFlip_IsEnabled As Boolean = True
Public ReadOnly Property CalcRotFlip_IsEnabled As Boolean
Get
Return m_CalcRotFlip_IsEnabled
End Get
End Property
Public ReadOnly Property CalcRotFlip_Visibility As Visibility
Get
Return If(Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.NESTING_AUTO), Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Public ReadOnly Property Optimize_Visibility As Visibility
Get
Return If(Not IsNothing(Map.refProjectVM.BTLStructureVM) AndAlso
(ProjectManagerVM.CurrProd.nType = BWType.BEAM OrElse
(ProjectManagerVM.CurrProd.nType = BWType.WALL AndAlso Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.NESTING_AUTO))), Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Public ReadOnly Property OriginType_Visibility As Visibility
Get
Return If(Optimize_Visibility = Visibility.Visible AndAlso OriginTypeList.Count > 1, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
#Region "Messages"
Public ReadOnly Property LongDrillArea_Msg As String
Get
Return EgtMsg(61889)
End Get
End Property
Public ReadOnly Property MinScore_Msg As String
Get
Return EgtMsg(61890)
End Get
End Property
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
Public ReadOnly Property CalcRotFlip_ToolTip As String
Get
Return EgtMsg(61932)
End Get
End Property
Public ReadOnly Property UnlockFlip_ToolTip As String
Get
Return EgtMsg(61933)
End Get
End Property
Public ReadOnly Property UnlockRot_ToolTip As String
Get
Return EgtMsg(61934)
End Get
End Property
Public ReadOnly Property NewRawPart_ToolTip As String
Get
Return EgtMsg(61903)
End Get
End Property
#End Region ' Messages
' Definizione comandi
Private m_cmdOptimize As ICommand
Private m_cmdCalcRotFlip As ICommand
Private m_cmdUnlockRot As ICommand
Private m_cmdUnlockFlip As ICommand
Private m_cmdWarehouse As ICommand
Private m_cmdNewRawPart 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)
m_bLDIntersOther = False
NotifyPropertyChanged(NameOf(SelPartType))
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub SetOptimizePanelIsEnabled(bIsEnabled As Boolean)
' se pareti e senza opzione nesting, lascio disabilitato
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL AndAlso Not Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.NESTING_AUTO) Then
m_Optimize_IsEnabled = False
m_CalcRotFlip_IsEnabled = False
Else
m_Optimize_IsEnabled = bIsEnabled
m_CalcRotFlip_IsEnabled = bIsEnabled
End If
NotifyPropertyChanged(NameOf(Optimize_IsEnabled))
NotifyPropertyChanged(NameOf(CalcRotFlip_IsEnabled))
End Sub
Friend Function ProcessEvents(ByVal nProg As Integer, ByVal nPause As Integer) As Integer
If nProg > 0 And nProg <= 100 Then
NestingRunningWndVM.m_CurrState = SectionProgress.NestStates.NEST
NestingRunningWndVM.m_CurrTime = nProg
ElseIf nProg > 100 And nProg <= 200 Then
NestingRunningWndVM.m_CurrState = SectionProgress.NestStates.ADDPART
NestingRunningWndVM.m_CurrTime = nProg - 100
ElseIf nProg > 200 And nProg <= 300 Then
NestingRunningWndVM.m_CurrState = SectionProgress.NestStates.CALCRAWPART
NestingRunningWndVM.m_CurrTime = nProg - 200
End If
' Costringo ad aggiornare
UpdateUI()
' Eventuale attesa
Thread.Sleep(nPause)
' Ritorno eventuale stop
If m_StopNesting Then
m_StopNesting = False
Return 1
Else
Return 0
End If
End Function
Private Sub StartCalcRotFlip(BTLPart As BTLPartVM)
' ricalcolo rotflip
m_bNestingRunning = True
Dim NestingRunningWndVM As New NestingRunningWndVM(m_SelPartType.Id, BTLPart)
Dim NestingRunningWnd As New NestingRunningWndV(Application.Current.MainWindow, NestingRunningWndVM)
NestingRunningWnd.ShowDialog()
m_bNestingRunning = False
End Sub
Friend Sub UpdateOriginTypeList(bFromBtl As Boolean)
m_OriginTypeList = New List(Of IdNameStruct)
If Not IsNothing(Map.refProjectVM.BTLStructureVM) AndAlso
(Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM OrElse (Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL And Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.NESTING_AUTO))) Then
m_OriginTypeList.Add(New IdNameStruct(OriginType.STANDARD, EgtMsg(61964)))
End If
If bFromBtl Then
m_OriginTypeList.Add(New IdNameStruct(OriginType.FROM_BTL, EgtMsg(61965)))
End If
NotifyPropertyChanged(NameOf(OriginTypeList))
NotifyPropertyChanged(NameOf(OriginType_Visibility))
NotifyPropertyChanged(NameOf(SelOriginType))
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "CalcRotFlip"
Public ReadOnly Property CalcRotFlip_Command As ICommand
Get
If m_cmdCalcRotFlip Is Nothing Then
m_cmdCalcRotFlip = New Command(AddressOf CalcRotFlip)
End If
Return m_cmdCalcRotFlip
End Get
End Property
Friend Sub CalcRotFlip()
If IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.BTLStructureVM.BTLPartVMList) OrElse Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count = 0 Then Return
' lancio calcolo RotFlip
StartCalcRotFlip(Nothing)
End Sub
#End Region ' CalcRotFlip
#Region "UnlockRot"
Public ReadOnly Property UnlockRot_Command As ICommand
Get
If m_cmdUnlockRot Is Nothing Then
m_cmdUnlockRot = New Command(AddressOf UnlockRot)
End If
Return m_cmdUnlockRot
End Get
End Property
Friend Sub UnlockRot()
If IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.BTLStructureVM.BTLPartVMList) OrElse Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count = 0 Then Return
If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then
For Each BTLPart In Map.refProjectVM.BTLStructureVM.BTLPartVMList
If IsNothing(BTLPart) Then Continue For
If BTLPart.bLockRotation Then
BTLPart.bLockRotation = False
End If
Next
' lancio calcolo RotFlip
StartCalcRotFlip(Nothing)
Else
Dim SelBTLPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
If IsNothing(SelBTLPart) Then Return
If SelBTLPart.bLockRotation Then
SelBTLPart.bLockRotation = False
' lancio calcolo RotFlip
StartCalcRotFlip(SelBTLPart)
End If
End If
End Sub
#End Region ' UnlockRot
#Region "UnlockFlip"
Public ReadOnly Property UnlockFlip_Command As ICommand
Get
If m_cmdUnlockFlip Is Nothing Then
m_cmdUnlockFlip = New Command(AddressOf UnlockFlip)
End If
Return m_cmdUnlockFlip
End Get
End Property
Friend Sub UnlockFlip()
If IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.BTLStructureVM.BTLPartVMList) OrElse Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count = 0 Then Return
If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then
For Each BTLPart In Map.refProjectVM.BTLStructureVM.BTLPartVMList
If IsNothing(BTLPart) Then Continue For
BTLPart.bLockInversion = False
Next
' lancio calcolo RotFlip
StartCalcRotFlip(Nothing)
Else
Dim SelBTLPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
If IsNothing(SelBTLPart) Then Return
SelBTLPart.bLockInversion = False
' lancio calcolo RotFlip
StartCalcRotFlip(SelBTLPart)
End If
End Sub
#End Region ' UnlockFlip
#Region "Optimize"
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
Friend Sub Optimize()
If IsNothing(m_SelPartType) OrElse IsNothing(m_SelOriginType) Then Return
If IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.BTLStructureVM.BTLPartVMList) OrElse Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count = 0 Then Return
'' se nessun grezzo, rendo tutti i pezzi visibili
'If Map.refProjectVM.MachGroupPanelVM.MachGroupVMList.Count = 0 Then
' Map.refProjectVM.BTLStructureVM.ShowAll(False)
'End If
' apro finestra di attesa nesting
m_bNestingRunning = True
Dim NestingRunningWnd As Object = Nothing
Dim NestingRunningWndVM As NestingRunningWndVM
If m_SelOriginType.Id = OriginType.FROM_BTL Then
NestingRunningWndVM = New NestingRunningWndVM(m_SelPartType.Id)
Else
NestingRunningWndVM = New NestingRunningWndVM(m_SelPartType.Id, m_bLDIntersOther, m_nMinScore)
End If
NestingRunningWnd = New NestingRunningWndV(Application.Current.MainWindow, NestingRunningWndVM)
NestingRunningWnd.ShowDialog()
m_bNestingRunning = False
'' se nessun grezzo, rimetto tutti i pezzi invisibili
'If Map.refProjectVM.MachGroupPanelVM.MachGroupVMList.Count = 0 Then
' Map.refProjectVM.BTLStructureVM.HideAll(True)
'End If
' mostro risultati
Dim sResult As String = ""
Dim dStartOffset As Double = WarehouseHelper.GetStartOffset()
For Each Section In NestingRunningWndVM.SectionProgressList
Dim bSectionInitiated As Boolean = False
If Section.SectionPartList.Count > 0 AndAlso Section.SParamList.Count = 0 Then
sResult &= "Section " & Section.Section.sSectionXMaterial & ": no raw part found in the warehouse!" & Environment.NewLine
bSectionInitiated = True
End If
For Each Part In Section.SectionPartList
If Part.nINPROD <> Part.nCNT + Part.nADDED Then
' verifico se inizializzare sezione
If Not bSectionInitiated Then
sResult &= "Section " & Section.Section.sSectionXMaterial & ":" & Environment.NewLine
bSectionInitiated = True
End If
' recupero VM
Dim PartVM As BTLPartVM = Map.refProjectVM.BTLStructureVM.BTLPartVMList.FirstOrDefault(Function(x) x.BTLPartM Is Part)
If Not IsNothing(PartVM) AndAlso Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM AndAlso Section.SParamList.Count > 0 Then
Dim dMaxL As Double = Section.SParamList.Max(Function(x) x.dL)
If PartVM.dL + dStartOffset < dMaxL Then
sResult &= " - " & Part.nPDN & ": material L(" & dMaxL & ") too short for a part with L(" & PartVM.dL & ")!" & Environment.NewLine
Else
sResult &= " - " & Part.nPDN & ": partially nested!" & "(" & Part.nINPROD & "/" & Part.nCNT + Part.nADDED & ")" & Environment.NewLine
End If
ElseIf Not IsNothing(PartVM) AndAlso Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL Then
If Not Section.SParamList.Any(Function(x) x.dL > PartVM.dL AndAlso x.dW > PartVM.dW) Then
sResult &= " - " & Part.nPDN & ": no material can fit part dimensions(" & PartVM.dW & " x " & PartVM.dL & ")!" & Environment.NewLine
Else
sResult &= " - " & Part.nPDN & ": partially nested!" & "(" & Part.nINPROD & "/" & Part.nCNT + Part.nADDED & ")" & Environment.NewLine
End If
Else
sResult &= " - " & Part.nPDN & ": partially nested!" & "(" & Part.nINPROD & "/" & Part.nCNT + Part.nADDED & ")" & Environment.NewLine
End If
End If
Next
Next
If Not String.IsNullOrWhiteSpace(sResult) Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, sResult, "", MessageBoxButton.OK, MessageBoxImage.Warning)
End If
End Sub
#End Region ' Optimize
#Region "Warehouse"
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
Friend Sub Warehouse()
If Not IsNothing(Map.refProjectVM.BTLStructureVM) Then
Dim WarehouseWnd As New WarehouseWndV(Application.Current.MainWindow, New WarehouseWndVM())
WarehouseWnd.ShowDialog()
End If
End Sub
#End Region ' Warehouse
#Region "NewRawPart"
Public ReadOnly Property NewRawPart_Command As ICommand
Get
If m_cmdNewRawPart Is Nothing Then
m_cmdNewRawPart = New Command(AddressOf NewRawPartCmd)
End If
Return m_cmdNewRawPart
End Get
End Property
Public Sub NewRawPartCmd()
NewRawPart(False)
End Sub
Public Sub NewRawPart(bLast As Boolean)
If IsNothing(ProjectManagerVM.CurrProd) Then Return
Dim SelParts As List(Of BTLPartVM) = Map.refProjectVM.BTLStructureVM.SelBTLParts.ToList()
If IsNothing(SelParts) OrElse SelParts.Count <= 0 Then Return
' se solido attivo, lo riporto normale
If Map.refShowBeamPanelVM.ShowSolid_IsChecked Then Map.refProjectVM.BTLStructureVM.ShowSolid(GDB_ID.NULL, False, False)
Map.refShowBeamPanelVM.SetShowSolid(False)
' verifico che abbiano tutti la stessa sezione
Dim dHSection As Double = SelParts(0).dH
Dim dWSection As Double = SelParts(0).dW
For PartIndex = 0 To SelParts.Count - 1
Dim Part As BTLPartVM = SelParts(PartIndex)
If Not IsNothing(Part) Then
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then
If Part.dH <> dHSection OrElse Part.dW <> dWSection Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(61970), EgtMsg(30007))
Return
End If
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL Then
If Part.dH <> dHSection Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(61970), EgtMsg(30007))
Return
End If
End If
Else
SelParts.Remove(Part)
End If
Next
' se pareti e piu' di uno selezionato, esco
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL And SelParts.Count > 1 Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(61971), EgtMsg(30007))
Return
End If
' verifico se sono gia' stati messi tutti i pezzi richiesti
If Not VerifyPartCount(SelParts) Then Return
Dim dRawL As Double = SelParts(0).dL
Dim dRawW As Double = SelParts(0).dW
Dim dStartOffset As Double = 0
Dim dKerf As Double = 0
Dim dOffset As Double = WarehouseHelper.GetOffset(Map.refProjectVM.BTLStructureVM.nPROJTYPE)
' se tipo di definizione grezzo esplicito
If WarehouseHelper.GetRawPartDef = 1 OrElse ((Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift AndAlso WarehouseHelper.GetWarehouseType = WarehouseType.BASIC) Then
' chiedo lunghezza grezzo
Dim sWarehouseIniPath As String = Map.refMainWindowVM.MainWindowM.sWarehouseDir & "\" & WH_BASIC_INI_FILE_NAME
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
dStartOffset = WarehouseHelper.GetStartOffset()
dRawL += dStartOffset
Else
dKerf = WarehouseHelper.GetKerf()
dRawL += 2 * dKerf
dRawW += 2 * dKerf
End If
Dim AddRawPartWndVM As New AddRawPartWndVM(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dRawL, dRawW, dStartOffset)
Dim AddRawPartWnd As Object = New AddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM)
If Not AddRawPartWnd.ShowDialog() Then Return
dRawL = AddRawPartWndVM.VariableList(0).dValue
dRawW = AddRawPartWndVM.VariableList(1).dValue
dStartOffset = AddRawPartWndVM.VariableList(1).dValue
' se altrimenti definizione grezzo da warehouse
Else
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then
dStartOffset = WarehouseHelper.GetStartOffset()
Else
dKerf = WarehouseHelper.GetKerf()
End If
' se warehouse basic
Select Case WarehouseHelper.GetWarehouseType()
Case WarehouseType.BASIC
WarehouseHelper.GetCurrentDimensions(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dRawW, dRawL)
Case WarehouseType.MEDIUM
Dim SectionList As List(Of SParam) = WarehouseHelper.GetSectionList()
Dim SParamlist As List(Of SParam) = SectionList.FindAll(Function(x) x.SectXMat = SelParts(0).Section)
If bLast Then
Dim LastMaterial As SParam = WarehouseHelper.GetLastMaterial(SelParts(0).Section)
If Not IsNothing(LastMaterial) Then
dRawL = LastMaterial.dL
dRawW = LastMaterial.dW
ElseIf SParamlist.Count > 0 Then
dRawL = SParamlist(0).dL
dRawW = SParamlist(0).dW
Else
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(61975), EgtMsg(30007))
Return
End If
Else
If SParamlist.Count = 0 Then
' se pareti aumento dimensioni del kerf
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL Then
dRawW += (2 * dKerf)
dRawL += (2 * dKerf)
End If
' apro finestra con solo edit
If AddRawPartWnd(AddRawPartWndVM.EditTypes.ONLY_TEXT, SParamlist, dRawW, dRawL, dStartOffset, dOffset, dKerf) Then
WarehouseHelper.SetOffset(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dOffset)
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then
WarehouseHelper.SetStartOffset(dStartOffset)
Else
WarehouseHelper.SetKerf(dKerf)
End If
Else
Return
End If
ElseIf SParamlist.Count > 0 Then
' imposto finestra con anche edit
If AddRawPartWnd(AddRawPartWndVM.EditTypes.TEXT_AND_COMBO, SParamlist, dRawW, dRawL, dStartOffset, dOffset, dKerf) Then
WarehouseHelper.SetOffset(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dOffset)
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then
WarehouseHelper.SetStartOffset(dStartOffset)
Else
WarehouseHelper.SetKerf(dKerf)
End If
Else
Return
End If
End If
End If
End Select
End If
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
' verifico se lunghezza barra e' maggiore della lunghezza dei pezzi
Dim dTotLen As Double = WarehouseHelper.GetStartOffset()
For PartIndex = 0 To SelParts.Count - 1
If PartIndex <> 0 Then
dTotLen += WarehouseHelper.GetOffset(BWType.BEAM)
End If
dTotLen += SelParts(PartIndex).dL
Next
If dTotLen > dRawL Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(61972), EgtMsg(30007))
Return
End If
End If
' creo nuovo gruppo di lavorazione
Map.refMachGroupPanelVM.AddMachGroup()
Dim nCurrMachGroup As Integer = EgtGetCurrMachGroup()
Dim sCurrMachGroupName As String = ""
EgtGetMachGroupName(nCurrMachGroup, sCurrMachGroupName)
Dim sLogPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\RawPartLog.txt"
' scrivo dati per variabili P di comunicazione con la macchina in gruppo di lavorazione
EgtSetInfo(nCurrMachGroup, MGR_RPT_PRODID, ProjectManagerVM.CurrProd.nProdId)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PATTID, nCurrMachGroup)
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
' ordino i pezzi per lunghezza
SelParts = SelParts.OrderBy(Function(x) x.dL).ToList
' creo copie dei pezzi
Dim nPartDuploIdList As New List(Of Integer)
For Each Part In SelParts
Dim nDuploId As Integer = EgtDuploNew(Part.nPartId)
' elimino valori calcolo dell'originale
MyMachGroupPanelVM.DuploRemoveProjCalc(nDuploId)
' lo rendo std
EgtSetMode(nDuploId, GDB_MD.STD)
nPartDuploIdList.Add(nDuploId)
Next
' scrivo dati costruzione grezzo in gruppo di lavorazione
EgtSetInfo(nCurrMachGroup, MGR_RPT_BARLEN, dRawL)
EgtSetInfo(nCurrMachGroup, MGR_RPT_MATERIAL, SelParts(0).sMATERIAL)
' scrivo dati di tutti i pezzi
Dim dPosX As Double = WarehouseHelper.GetStartOffset()
' ciclo sui pezzi
For nIndex = 0 To nPartDuploIdList.Count - 1
' se non è primo, aggiungo offset tra barre standard
If nIndex <> 0 Then
dPosX += WarehouseHelper.GetOffset(BWType.BEAM)
End If
EgtSetInfo(nCurrMachGroup, MGR_RPT_PART & nIndex + 1, nPartDuploIdList(nIndex) & "," & DoubleToString(dPosX, 3))
' incremento posizione della sua lunghezza
dPosX += SelParts(nIndex).dL
Next
Dim BeamMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.GetLastMachGroup()
' eseguo script creazione grezzo
Dim nERR As Integer = 0
If Not ExecBeam(sLogPath, ProjectManagerVM.CurrProd.sMachine, CalcIntegration.CmdTypes.RAWPART, False) Then
' elimino duplo e gruppo di lavorazione
For Each nDuploId In nPartDuploIdList
EgtErase(nDuploId)
Next
BeamMachGroup.DeleteMachGroup()
If File.Exists(sLogPath) Then
Dim LogFile As String() = File.ReadAllLines(sLogPath)
If LogFile.Count >= 2 AndAlso Not IsNothing(LogFile(1)) Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, LogFile(1), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Else
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(61973), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Return
End If
For nDuploIndex = 0 To SelParts.Count - 1
EgtSetInfo(nPartDuploIdList(nDuploIndex), MGR_PRT_ROT, SelParts(nDuploIndex).nROTATED)
EgtSetInfo(nPartDuploIdList(nDuploIndex), MGR_PRT_FLIP, SelParts(nDuploIndex).nINVERTED)
Next
' aggiorno contatore pezzi usati in Prod
For Each SelPart In SelParts
SelPart.RefreshPartInProd()
Next
'aggiorno lista pezzi
BeamMachGroup.MyMachGroupM.RefreshPartList()
BeamMachGroup.MyMachGroupM.RefreshGroupData()
' aggiorno dati utilizzo barra
BeamMachGroup.UpdateUsage()
Core.ViewPanelVM.BWSetView(VT.ISO_SW, False)
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then
Dim nPartDuploId As Integer = EgtDuploNew(SelParts(0).nPartId)
' scrivo dati in gruppo di lavorazione
Dim dPosX As Double = dKerf
Dim dPosY As Double = dKerf
EgtSetInfo(nCurrMachGroup, MGR_RPT_PANELLEN, dRawL)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PANELWIDTH, dRawW)
EgtSetInfo(nCurrMachGroup, MGR_RPT_MATERIAL, SelParts(0).sMATERIAL)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PART & 1,
nPartDuploId & "," & DoubleToString(dPosX, 3) & "," & DoubleToString(dPosY, 3) & ",0,0")
Dim WallMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.MachGroupVMList(Map.refMachGroupPanelVM.MachGroupVMList.Count - 1)
' eseguo script creazione grezzo
If Not ExecWall(sLogPath, ProjectManagerVM.CurrProd.sMachine, CalcIntegration.CmdTypes.RAWPART, False, False) Then
' elimino duplo e gruppo di lavorazione
EgtErase(nPartDuploId)
WallMachGroup.DeleteMachGroup()
If File.Exists(sLogPath) Then
Dim LogFile As String() = File.ReadAllLines(sLogPath)
If LogFile.Count >= 2 AndAlso Not IsNothing(LogFile(1)) Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, LogFile(1), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Else
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(61973), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
'' se nessun grezzo, rimetto tutti i pezzi invisibili
'If Map.refProjectVM.MachGroupPanelVM.MachGroupVMList.Count = 0 Then
' Map.refProjectVM.BTLStructureVM.HideAll(True)
'End If
Return
End If
' scrivo dati pezzo
EgtSetInfo(nPartDuploId, MGR_PRT_POSX, dPosX)
EgtSetInfo(nPartDuploId, MGR_PRT_POSY, dPosY)
EgtSetInfo(nPartDuploId, MGR_PRT_ROT, SelParts(0).nROTATED)
EgtSetInfo(nPartDuploId, MGR_PRT_FLIP, SelParts(0).nINVERTED)
' aggiorno contatore pezzi usati in Prod
SelParts(0).RefreshPartInProd()
' aggiorno lista pezzi
WallMachGroup.MyMachGroupM.RefreshPartList()
WallMachGroup.MyMachGroupM.RefreshGroupData()
' aggiorno dati ultilizzo barra
WallMachGroup.UpdateUsage()
Core.ViewPanelVM.BWSetView(VT.TOP, False)
End If
EgtZoom(ZM.ALL)
End Sub
' funzione che apre finestra di scelta dimensioni grezzo
Private Function AddRawPartWnd(EditType As AddRawPartWndVM.EditTypes, SParamlist As List(Of SParam), ByRef dRawW As Double, ByRef dRawL As Double,
ByRef dStartOffset As Double, ByRef dOffset As Double, ByRef dKerf As Double) As Boolean
' apro finestra con solo edit
Dim AddRawPartWndVM As New AddRawPartWndVM(EditType, Map.refProjectVM.BTLStructureVM.nPROJTYPE, SParamlist, dRawL, dRawW, dStartOffset, dOffset, dKerf)
Dim AddRawPartWndV As New AddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM)
If Not AddRawPartWndV.ShowDialog() Then Return False
Select Case Map.refProjectVM.BTLStructureVM.nPROJTYPE
Case BWType.BEAM
dRawL = AddRawPartWndVM.VariableList(0).dValue
dStartOffset = AddRawPartWndVM.VariableList(1).dValue
dOffset = AddRawPartWndVM.VariableList(2).dValue
Case BWType.WALL
dRawW = AddRawPartWndVM.VariableList(0).dValue
dRawL = AddRawPartWndVM.VariableList(1).dValue
dKerf = AddRawPartWndVM.VariableList(2).dValue
dOffset = AddRawPartWndVM.VariableList(3).dValue
End Select
' verifico se il materiale esiste in magazzino o devo aggiungerlo
Dim CurrSParam As SParam = Nothing
Select Case EditType
Case AddRawPartWndVM.EditTypes.ONLY_TEXT
' lo aggiungo a lista materiali in magazzino
CurrSParam = AddRawMaterial(dRawW, dRawL)
Case AddRawPartWndVM.EditTypes.ONLY_COMBO
' non faccio nulla
Case AddRawPartWndVM.EditTypes.TEXT_AND_COMBO
' verifico se lunghezza testo corrisponde a materiale
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then
CurrSParam = SParamlist.FirstOrDefault(Function(x) x.dL = AddRawPartWndVM.VariableList(0).dValue)
Else
CurrSParam = SParamlist.FirstOrDefault(Function(x) x.dL = AddRawPartWndVM.VariableList(1).dValue AndAlso x.dW = AddRawPartWndVM.VariableList(0).dValue)
End If
If IsNothing(CurrSParam) Then
' lo aggiungo a lista materiali in magazzino
CurrSParam = AddRawMaterial(dRawW, dRawL)
End If
End Select
' imposto il materiale selezionato come ultimo utilizzato
SetLastMaterial(CurrSParam.SectXMat, CurrSParam)
Return True
End Function
Private Function AddRawMaterial(dRawW As Double, ByRef dRawL As Double) As SParam
Dim sWarehousePath As String = Map.refMainWindowVM.MainWindowM.sWarehouseDir & "\" & WH_MEDIUM_INI_FILE_NAME
Dim nQuantity As Integer = GetMainPrivateProfileInt(S_WAREHOUSE, K_DEFAULTQUANTITY, 1)
Dim CurrSParam = Nothing
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
' creo sParam
If Not IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLParts(0)) Then CurrSParam = New SParam(Map.refProjectVM.BTLStructureVM.SelBTLParts(0).Section, dRawL, nQuantity, False)
Dim sL As String = String.Empty
sL = LenToString(CurrSParam.dL, 3)
' ricavo l'indice del SecionXMaterial dalla Beam_List
Dim SectXMatIndex As Integer = GetSectIndexFromSection(MachineType.BEAM, CurrSParam.SectXMat)
' ricavo nuovo indice materiale
Dim ParamIndex As Integer = 1
Dim sParam As String = ""
While GetPrivateProfileString(S_BEAM, K_L & ParamIndex, "", sParam, sWarehousePath) > 0
ParamIndex += 1
End While
If SectXMatIndex > 0 Then
' lo aggiungo in warehouse
WritePrivateProfileString(S_BEAM, K_L & ParamIndex,
SectXMatIndex & "," & sL & "," & CurrSParam.nQuantity & "," & If(CurrSParam.bActive, 1, 0),
sWarehousePath)
Else
EgtOutLog("Error in material creation, section not found!")
End If
Return CurrSParam
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then
' creo sParam
If Not IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLParts(0)) Then CurrSParam = New SParam(Map.refProjectVM.BTLStructureVM.SelBTLParts(0).Section, dRawW, dRawL, nQuantity, False)
Dim sW As String = String.Empty
Dim sL As String = String.Empty
sW = LenToString(CurrSParam.dW, 3)
sL = LenToString(CurrSParam.dL, 3)
' ricavo l'indice del SecionXMaterial dalla Wall_List
Dim SectXMatIndex As Integer = GetSectIndexFromSection(MachineType.WALL, CurrSParam.SectXMat)
' ricavo nuovo indice materiale
Dim ParamIndex As Integer = 1
Dim sParam As String = ""
While GetPrivateProfileString(S_WALL, K_S & ParamIndex, "", sParam, sWarehousePath) > 0
ParamIndex += 1
End While
' lo aggiungo in warehouse
WritePrivateProfileString(S_WALL, K_S & ParamIndex,
SectXMatIndex & "," & sW & "," & sL & "," & CurrSParam.nQuantity & "," & If(CurrSParam.bActive, 1, 0),
sWarehousePath)
Return CurrSParam
End If
Return Nothing
End Function
Private Function VerifyPartCount(SelParts As List(Of BTLPartVM)) As Boolean
' verifico se ci sono pezzi da aggiungere
Dim ToAddList As New List(Of String)
Dim ToAddVM As New List(Of BTLPartVM)
For Each SelPart In SelParts
If Not SelPart.CanAddPartToCount Then
ToAddList.Add(SelPart.nCNT & EgtMsg(61864) & SelPart.nADDED & EgtMsg(61865))
ToAddVM.Add(SelPart)
End If
Next
' se non ci sono, chiedo se aggiungerne uno nuovo
If ToAddList.Count > 0 Then
Dim sMessage As String = EgtMsg(61863) & Environment.NewLine
For Each sPart In ToAddList
sMessage &= " - " & sPart & Environment.NewLine
Next
If EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, sMessage & EgtMsg(61893), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
For Each PartVM In ToAddVM
PartVM.AddNewPartToAdded()
Next
Else
Return False
End If
End If
Return True
End Function
#End Region ' NewRawPart
#End Region ' COMMANDS
End Class