Files
egtbeamwall/EgtBEAMWALL.Optimizer/MachGroupPanel/MyMachGroupVM.vb
T
2026-05-05 10:25:41 +02:00

1296 lines
54 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Windows.Threading
Imports EgtBEAMWALL.Core
Imports EgtBEAMWALL.DataLayer.DatabaseModels
Imports EgtUILib
Imports EgtWPFLib5
Public Class MyMachGroupVM
Inherits Core.MyMachGroupVM
#Region "FIELDS & PROPERTIES"
#Region "General"
Private m_RefreshPartList_Timer As New DispatcherTimer
Public Overrides Property SelPart As Core.PartVM
Get
Return m_SelPart
End Get
Set(value As Core.PartVM)
' mostro pezzi selezionati
Map.refShowBeamPanelVM.bShowAll = False
' se pezzo evidenziato da ultima selezione precedente
If Map.refProjectVM.BTLStructureVM.SelBTLParts.Count = 1 Then
' deevidenzio MachGroup e Duplo di questo pezzo
If Not IsNothing(Map.refProjectVM.MachGroupPanelVM) Then
Dim MachGroupList As New List(Of MyMachGroupVM)
For Each Machgroup As MyMachGroupVM In Map.refProjectVM.MachGroupPanelVM.MachGroupVMList
Dim bFound As Boolean = False
For Each Part As PartVM In Machgroup.PartVMList
If EgtDuploGetOriginal(Part.nPartId) = Map.refProjectVM.BTLStructureVM.SelBTLParts(0).nPartId Then
Part.ResetSearchFound()
bFound = True
End If
Next
If bFound Then
Machgroup.ResetSearchFound()
End If
Next
End If
End If
If Not IsNothing(m_SelPart) Then
' deevidenzio BTLPart di questo pezzo
If Not IsNothing(Map.refProjectVM.BTLStructureVM) Then
For BTLPartIndex = 0 To Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count - 1
Dim nDuploOriginalId As Integer = 0
If EgtGetInfo(m_SelPart.nPartId, GDB_SI_DUPSOU, nDuploOriginalId) AndAlso nDuploOriginalId > 0 AndAlso nDuploOriginalId = Map.refProjectVM.BTLStructureVM.BTLPartVMList(BTLPartIndex).nPartId Then
Map.refProjectVM.BTLStructureVM.BTLPartVMList(BTLPartIndex).ResetSearchFound()
Exit For
End If
Next
End If
Map.refProjectVM.SetFeatureListVisibility(False)
End If
' se modalita' assemblato
If Map.refShowBeamPanelVM.ShowBuilding_IsChecked AndAlso Map.refShowBeamPanelVM.bShowAll Then
' devo smontarlo prima di calcolare le travi, altrimenti non trova i pezzi
Map.refProjectVM.BTLStructureVM.ShowBuilding(False, False)
End If
m_SelPart = value
' seleziono pezzo
EgtDeselectAll()
If Not IsNothing(value) Then
Map.refProjectVM.SetFeatureListVisibility(True)
EgtSelectObj(SelPart.nPartId)
' trovo ed evidenzio BTLPart di questo pezzo
If Not IsNothing(Map.refProjectVM.MachGroupPanelVM) Then
For BTLPartIndex = 0 To Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count - 1
Dim nDuploOriginalId As Integer = 0
If EgtGetInfo(m_SelPart.nPartId, GDB_SI_DUPSOU, nDuploOriginalId) AndAlso nDuploOriginalId > 0 AndAlso nDuploOriginalId = Map.refProjectVM.BTLStructureVM.BTLPartVMList(BTLPartIndex).nPartId Then
Map.refProjectVM.BTLStructureVM.BTLPartVMList(BTLPartIndex).SetSearchFound()
Exit For
End If
Next
End If
End If
If Not IsNothing(value) Then EgtDraw()
NotifyPropertyChanged(NameOf(SelPart))
' se modalità building, la tolgo
If Map.refShowBeamPanelVM.ShowBuilding_IsChecked Then
Map.refProjectVM.SetSceneShowBuldingVisibility(False)
Map.refProjectVM.BTLStructureVM.ShowBuilding(False, False)
Map.refShowBeamPanelVM.SetShowBuilding(False)
Map.refProjectVM.SetManagerTabVisibility(True)
If Not IsNothing(Map.refProjectVM.MachGroupPanelVM) Then Map.refProjectVM.SetFeatureListVisibility(True)
End If
End Set
End Property
Friend Sub SetSelPart(value As Core.PartVM)
m_SelPart = value
EgtDeselectAll()
EgtSelectObj(SelPart.nPartId)
NotifyPropertyChanged(NameOf(SelPart))
End Sub
Public Property sL As String
Get
Return LenToString(MyMachGroupM.dL, 3)
End Get
Set(value As String)
Dim dValue As Double
If StringToLenAdv(value, dValue, True) Then
Dim nRawPartId As Integer = EgtGetFirstRawPart()
If dValue <> MyMachGroupM.dL Then
Select Case nType
Case BWType.BEAM
' se c'e' almeno un pezzo
If m_PartVMList.Count > 0 Then
' verifico se la dimensione e' maggiore dello spazio occupato dai pezzi
Dim dTotLength As Double = 0
For Each Part In m_PartVMList
dTotLength += Part.dL + Part.dOffset
Next
If dValue < dTotLength Then
dValue = dTotLength
End If
End If
EgtSetInfo(Id, MGR_RPT_BARLEN, dValue)
If Not ReDrawBeamMachgroup() Then
' rispristino vecchio valore
EgtSetInfo(Id, MGR_RPT_BARLEN, MyMachGroupM.dL)
ReDrawBeamMachgroup()
NotifyPropertyChanged(NameOf(sL))
Else
MyMachGroupM.dL = dValue
End If
EgtDraw()
Case BWType.WALL
' se c'e' almeno un pezzo
If m_PartVMList.Count > 0 Then
' verifico se la dimensione e' maggiore del box minimo dei pezzi
Dim b3Parts As New BBox3d
Dim nBoxLayerId As Integer = EgtGetFirstNameInGroup(m_PartVMList(0).nPartId, "Box")
EgtGetBBoxGlob(nBoxLayerId, GDB_BB.EXACT, b3Parts)
For PartIndex = 1 To m_PartVMList.Count - 1
Dim b3Part As New BBox3d
nBoxLayerId = EgtGetFirstNameInGroup(m_PartVMList(PartIndex).nPartId, "Box")
EgtGetBBoxGlob(nBoxLayerId, GDB_BB.EXACT, b3Part)
b3Parts.Add(b3Part)
Next
Dim b3RawPart As New BBox3d
EgtGetRawPartBBox(nRawPartId, b3RawPart)
Dim dMinValue As Double = 0
Select Case CurrentMachine.NestingCorner
Case MCH_CR.BL, MCH_CR.TL
dMinValue = b3Parts.DimX + (b3Parts.Min.x - b3RawPart.Min.x) + WarehouseHelper.GetKerf()
Case MCH_CR.BR, MCH_CR.TR
dMinValue = b3Parts.DimX + (b3RawPart.Max.x - b3Parts.Max.x) + WarehouseHelper.GetKerf()
End Select
If dValue < dMinValue Then
dValue = dMinValue
End If
End If
If EgtModifyRawPartSize(nRawPartId, dValue, MyMachGroupM.dW, MyMachGroupM.dH) Then
' riporto il grezzo nell'angolo tavola di origine
Dim b3Tab As New BBox3d
EgtGetTableArea(1, b3Tab)
Dim p3OrigOnTab As Point3d
Select Case CurrentMachine.OrigCorner
Case MCH_CR.BL
p3OrigOnTab = New Point3d(CurrentMachine.OrigOffsX, CurrentMachine.OrigOffsY, 0)
Case MCH_CR.BR
p3OrigOnTab = New Point3d(b3Tab.DimX() - CurrentMachine.OrigOffsX, CurrentMachine.OrigOffsY, 0)
Case MCH_CR.TL
p3OrigOnTab = New Point3d(CurrentMachine.OrigOffsX, b3Tab.DimY() - CurrentMachine.OrigOffsY, 0)
Case MCH_CR.TR
p3OrigOnTab = New Point3d(b3Tab.DimX() - CurrentMachine.OrigOffsX, b3Tab.DimY() - CurrentMachine.OrigOffsY, 0)
End Select
EgtMoveToCornerRawPart(nRawPartId, p3OrigOnTab, CurrentMachine.OrigCorner)
' sposto tutti i pezzi di quanto si e' accorciato il grezzo
If CurrentMachine.NestingCorner = MCH_CR.TR OrElse CurrentMachine.NestingCorner = MCH_CR.BR Then
For Each Part In m_PartVMList
EgtMovePartInRawPart(Part.nPartId, New Vector3d(dValue - MyMachGroupM.dL, 0, 0))
Next
End If
' ripristino eventuale PosZ
If MyMachGroupM.dPosZ >= 0 Then
EgtMoveRawPart(nRawPartId, New Vector3d(0, 0, MyMachGroupM.dPosZ))
End If
EgtSetInfo(Id, MGR_RPT_PANELLEN, dValue)
EgtDraw()
MyMachGroupM.dL = dValue
Else
NotifyPropertyChanged(NameOf(sL))
End If
End Select
UpdateUsage()
ResetCalcTotalMachGroup()
End If
End If
End Set
End Property
Public Property sW As String
Get
Return LenToString(MyMachGroupM.dW, 3)
End Get
Set(value As String)
Dim dValue As Double
If StringToLenAdv(value, dValue, True) Then
If nType = BWType.WALL Then
Dim nRawPartId As Integer = EgtGetFirstRawPart()
If dValue <> MyMachGroupM.dW Then
' se c'e' almeno un pezzo
If m_PartVMList.Count > 0 Then
' verifico se la dimensione e' maggiore del box minimo dei pezzi
Dim b3Parts As New BBox3d
Dim nBoxLayerId As Integer = EgtGetFirstNameInGroup(m_PartVMList(0).nPartId, "Box")
EgtGetBBoxGlob(nBoxLayerId, GDB_BB.EXACT, b3Parts)
For PartIndex = 1 To m_PartVMList.Count - 1
Dim b3Part As New BBox3d
nBoxLayerId = EgtGetFirstNameInGroup(m_PartVMList(PartIndex).nPartId, "Box")
EgtGetBBoxGlob(nBoxLayerId, GDB_BB.EXACT, b3Part)
b3Parts.Add(b3Part)
Next
Dim b3RawPart As New BBox3d
EgtGetRawPartBBox(nRawPartId, b3RawPart)
Dim dMinValue As Double = 0
Select Case CurrentMachine.NestingCorner
Case MCH_CR.BL, MCH_CR.BR
dMinValue = b3Parts.DimY + (b3Parts.Min.y - b3RawPart.Min.y) + WarehouseHelper.GetKerf()
Case MCH_CR.TL, MCH_CR.TR
dMinValue = b3Parts.DimY + (b3RawPart.Max.y - b3Parts.Max.y) + WarehouseHelper.GetKerf()
End Select
If dValue < dMinValue Then
dValue = dMinValue
End If
End If
If EgtModifyRawPartSize(nRawPartId, MyMachGroupM.dL, dValue, MyMachGroupM.dH) Then
' riporto il grezzo nell'angolo tavola di origine
Dim b3Tab As New BBox3d
EgtGetTableArea(1, b3Tab)
Dim p3OrigOnTab As Point3d
Select Case CurrentMachine.OrigCorner
Case MCH_CR.BL
p3OrigOnTab = New Point3d(CurrentMachine.OrigOffsX, CurrentMachine.OrigOffsY, 0)
Case MCH_CR.BR
p3OrigOnTab = New Point3d(b3Tab.DimX() - CurrentMachine.OrigOffsX, CurrentMachine.OrigOffsY, 0)
Case MCH_CR.TL
p3OrigOnTab = New Point3d(CurrentMachine.OrigOffsX, b3Tab.DimY() - CurrentMachine.OrigOffsY, 0)
Case MCH_CR.TR
p3OrigOnTab = New Point3d(b3Tab.DimX() - CurrentMachine.OrigOffsX, b3Tab.DimY() - CurrentMachine.OrigOffsY, 0)
End Select
EgtMoveToCornerRawPart(nRawPartId, p3OrigOnTab, CurrentMachine.OrigCorner)
' sposto tutti i pezzi di quanto si e' accorciato il grezzo
If CurrentMachine.NestingCorner = MCH_CR.TR OrElse CurrentMachine.NestingCorner = MCH_CR.TL Then
For Each Part In m_PartVMList
EgtMovePartInRawPart(Part.nPartId, New Vector3d(0, dValue - MyMachGroupM.dW, 0))
Next
End If
' ripristino eventuale PosZ
If MyMachGroupM.dPosZ >= 0 Then
EgtMoveRawPart(nRawPartId, New Vector3d(0, 0, MyMachGroupM.dPosZ))
End If
EgtSetInfo(Id, MGR_RPT_PANELWIDTH, dValue)
EgtDraw()
MyMachGroupM.dW = dValue
Else
NotifyPropertyChanged(NameOf(sW))
End If
UpdateUsage()
ResetCalcTotalMachGroup()
End If
End If
End If
End Set
End Property
Public Property sH As String
Get
Return LenToString(MyMachGroupM.dH, 3)
End Get
Set(value As String)
Dim dValue As Double
If StringToLenAdv(value, dValue, True) Then
MyMachGroupM.dH = value
End If
End Set
End Property
Private m_bSearchFound As Boolean
Public ReadOnly Property bSearchFound As Boolean
Get
Return m_bSearchFound
End Get
End Property
Friend Sub SetSearchFound()
m_bSearchFound = True
NotifyPropertyChanged(NameOf(Search_Background))
End Sub
Friend Sub ResetSearchFound()
m_bSearchFound = False
NotifyPropertyChanged(NameOf(Search_Background))
End Sub
Public ReadOnly Property Search_Background As SolidColorBrush
Get
Return If(m_bSearchFound, Brushes.Gold, Brushes.Transparent)
End Get
End Property
Private m_IsRowEnabled As Boolean = True
Public ReadOnly Property IsRowEnabled As Boolean
Get
Return m_IsRowEnabled
End Get
End Property
Friend Sub SetIsRowEnabled(bIsRowEnabled As Boolean)
m_IsRowEnabled = bIsRowEnabled
NotifyPropertyChanged(NameOf(IsRowEnabled))
End Sub
Public ReadOnly Property ButtonIsEnabled As Boolean
Get
Return nProduction_State < ItemState.Assigned
End Get
End Property
#Region "Messages"
Public ReadOnly Property Verify_ToolTip As String
Get
Return EgtMsg(61901)
End Get
End Property
Public ReadOnly Property Simulate_ToolTip As String
Get
Return EgtMsg(61902)
End Get
End Property
Public ReadOnly Property ProduceRawPart_ToolTip As String
Get
Return EgtMsg(61912)
End Get
End Property
Public ReadOnly Property CopyRawPart_ToolTip As String
Get
Return EgtMsg(61914)
End Get
End Property
Public ReadOnly Property RemoveRawPart_ToolTip As String
Get
Return EgtMsg(61915)
End Get
End Property
Public ReadOnly Property ReOrderPart_ToolTip As String
Get
Return EgtMsg(61916)
End Get
End Property
Public ReadOnly Property ResetCalc_ToolTip As String
Get
Return EgtMsg(61940)
End Get
End Property
#End Region ' Messages
' Definizione comandi
Private m_cmdVerify As ICommand
Private m_cmdSimulate As ICommand
Private m_cmdProduceRawPart As ICommand
Private m_cmdCopyRawPart As ICommand
Private m_cmdRemoveRawPart As ICommand
Private m_cmdReOrderPart As ICommand
Private m_cmdResetCalc As ICommand
#End Region ' General
#Region "Beam"
Public Overrides Property sStartCut As String
Get
Return LenToString(MyMachGroupM.dStartCut, 3)
End Get
Set(value As String)
Dim dValue As Double
If StringToLenAdv(value, dValue, True) Then
Dim dOldValue As Double = MyMachGroupM.dStartCut
' verifico se con il nuovo StartCut tutti i pezzi stanno nella barra
Dim dTotLength As Double = 0
For PartIndex = 0 To m_PartVMList.Count - 1
Dim Part As PartVM = m_PartVMList(PartIndex)
If PartIndex = 0 Then
dTotLength += Part.dL + dValue
Else
dTotLength += Part.dL + Part.dOffset
End If
Next
If Me.dL < dTotLength Then
NotifyPropertyChanged(NameOf(sStartCut))
Return
End If
MyMachGroupM.dStartCut = dValue
If Not ReDrawBeamMachgroup() Then
' rispristino vecchio valore
MyMachGroupM.dStartCut = dOldValue
ReDrawBeamMachgroup()
NotifyPropertyChanged(NameOf(sStartCut))
End If
EgtDraw()
If PartVMList.Count > 0 Then
Dim Beam As PartVM = PartVMList(0)
Beam.PartM.UpdateOffset()
Beam.NotifyPropertyChanged(NameOf(Beam.sOffset))
End If
' resetto validazione del pezzo primo pezzo
If PartVMList.Count > 0 Then
PartVMList(0).ResetCalcPart()
Else
ResetCalcMachGroup()
End If
UpdateUsage()
Else
NotifyPropertyChanged(NameOf(sStartCut))
End If
End Set
End Property
#End Region ' Beam
#Region "Wall"
Public Property sPosZ As String
Get
Return LenToString(MyMachGroupM.dPosZ, 3)
End Get
Set(value As String)
Dim dValue As Double
If StringToLenAdv(value, dValue, True) Then
Dim nRawPartId As Integer = EgtGetFirstRawPart()
If Math.Abs(dValue - MyMachGroupM.dPosZ) > EPS_SMALL Then
Select Case nType
Case BWType.BEAM
' non utilizzato
Case BWType.WALL
' se operazione di spostamento in z ha successo
If dValue >= 0 AndAlso EgtMoveRawPart(nRawPartId, New Vector3d(0, 0, dValue - MyMachGroupM.dPosZ)) Then
EgtSetInfo(Id, MGR_RPT_PANELPOSZ, dValue)
EgtDraw()
MyMachGroupM.dPosZ = dValue
Else
NotifyPropertyChanged(NameOf(sPosZ))
End If
End Select
ResetCalcTotalMachGroup()
End If
End If
End Set
End Property
#End Region ' Wall
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTORS"
Sub New(MyMachGroupM As MyMachGroupM)
MyBase.New(MyMachGroupM)
' aggiorno stato di produzione
ReadProductionState()
m_RefreshPartList_Timer.Interval = TimeSpan.FromMilliseconds(50)
AddHandler m_RefreshPartList_Timer.Tick, AddressOf RefreshPartList_Tick
End Sub
#End Region ' CONSTRUCTORS
#Region "METHODS"
#Region "Machgroup"
Friend Sub SetSelPart(PartVM As PartVM)
m_SelPart = PartVM
NotifyPropertyChanged(NameOf(SelPart))
End Sub
Public Overrides Sub RefreshGroupData()
End Sub
Public Shadows Function Copy(Optional Qty As Integer = 1) As Core.MyMachGroupVM
Dim BeamWallMachGroup As MyMachGroupVM = Nothing
If nType = BWType.BEAM Then
EgtResetCurrMachGroup()
' recupero lista dei pezzi BTL originali
Dim PartList As New List(Of BTLPartVM)
For Each Part In m_PartVMList
PartList.Add(BTLPartVM.RetrieveBTLPartFromPart(Part.nPartId))
Next
' verifico che nessun pezzo da copiare abbia raggiunto il numero massimo
If Not VerifyPartCount(PartList, Qty) Then Return Nothing
' creo nuovi gruppi di lavorazione
For Ind = 1 To Qty
Map.refMachGroupPanelVM.AddMachGroup()
Dim nCurrMachGroup As Integer = EgtGetCurrMachGroup()
Dim sCurrMachGroupName As String = ""
EgtGetMachGroupName(nCurrMachGroup, sCurrMachGroupName)
' 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_MATERIAL, sMATERIAL)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PATTID, nCurrMachGroup)
' scrivo dati costruzione grezzo in gruppo di lavorazione
EgtSetInfo(nCurrMachGroup, MGR_RPT_BARLEN, dL)
For Index = 0 To m_PartVMList.Count - 1
' creo copia del pezzo
Dim nPartDuploId As Integer = EgtDuploNew(PartList(Index).nPartId)
' elimino valori calcolo dell'originale
MyMachGroupPanelVM.DuploRemoveProjCalc(nPartDuploId)
' lo rendo std
EgtSetMode(nPartDuploId, GDB_MD.STD)
' scrivo dati costruzione grezzo in gruppo di lavorazione
EgtSetInfo(nCurrMachGroup, MGR_RPT_PART & (Index + 1), nPartDuploId & "," & m_PartVMList(Index).sPOSX)
Next
BeamWallMachGroup = Map.refMachGroupPanelVM.GetLastMachGroup()
' eseguo script creazione grezzo
Dim sLogPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\RawPartLog.txt"
If Not ExecBeam(sLogPath, ProjectManagerVM.CurrProd.sMachine, CalcIntegration.CmdTypes.RAWPART, False) Then
BeamWallMachGroup.DeleteMachGroup()
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
Return Nothing
End If
' aggiorno contatore pezzi usati in Prod
For Each Part In PartList
Part.RefreshPartInProd()
Next
'aggiorno lista pezzi
BeamWallMachGroup.MyMachGroupM.RefreshPartList()
BeamWallMachGroup.MyMachGroupM.RefreshGroupData()
' aggiorno dati ultilizzo barra
BeamWallMachGroup.UpdateUsage()
Core.ViewPanelVM.BWSetView(VT.ISO_SW, False)
Next
' se pareti
Else
' recupero lista dei pezzi BTL originali
Dim CopyPartList As New List(Of CopyPart)
Dim PartList As New List(Of BTLPartVM)
For Each Part As PartVM In m_PartVMList
Dim BTLPartVM As BTLPartVM = BTLPartVM.RetrieveBTLPartFromPart(Part.nPartId)
CopyPartList.Add(New CopyPart(BTLPartVM, Part.sPOSX, Part.sPOSY, Part.dROT, Part.nFLIP))
PartList.Add(BTLPartVM)
Next
EgtResetCurrMachGroup()
' verifico che nessun pezzo da copiare abbia raggiunto il numero massimo
If Not VerifyPartCount(PartList, Qty) Then Return Nothing
' creo nuovi gruppi di lavorazione
For ind = 1 To Qty
Map.refMachGroupPanelVM.AddMachGroup()
Dim nCurrMachGroup As Integer = EgtGetCurrMachGroup()
Dim sCurrMachGroupName As String = ""
EgtGetMachGroupName(nCurrMachGroup, sCurrMachGroupName)
' 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_MATERIAL, sMATERIAL)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PATTID, nCurrMachGroup)
' scrivo dati costruzione grezzo in gruppo di lavorazione
EgtSetInfo(nCurrMachGroup, MGR_RPT_PANELLEN, dL)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PANELWIDTH, dW)
For Index = 0 To CopyPartList.Count - 1
Dim CopyPart As CopyPart = CopyPartList(Index)
' creo copia del pezzo
Dim nPartDuploId As Integer = EgtDuploNew(CopyPart.BTLPart.nPartId)
' elimino valori calcolo dell'originale
MyMachGroupPanelVM.DuploRemoveProjCalc(nPartDuploId)
' lo rendo std
EgtSetMode(nPartDuploId, GDB_MD.STD)
' annullo eventuale inversione del pezzo originale
Dim b3Duplo As New BBox3d
EgtGetBBoxGlob(nPartDuploId, GDB_BB.STANDARD, b3Duplo)
If CopyPart.BTLPart.nINVERTED > 0 Then
EgtRotate(nPartDuploId, b3Duplo.Center(), Vector3d.X_AX, 180, GDB_RT.GLOB)
End If
' calcolo rotazione
Dim dRot As Double = CopyPart.dRot - CopyPart.BTLPart.nROTATED
If dRot <> 0 Then
EgtRotate(nPartDuploId, b3Duplo.Center(), -Vector3d.Z_AX, dRot, GDB_RT.GLOB)
End If
' effettuo eventuale flip
If CopyPart.nFlip > 0 Then
EgtRotate(nPartDuploId, b3Duplo.Center(), Vector3d.X_AX, 180, GDB_RT.GLOB)
End If
EgtSetInfo(nPartDuploId, MGR_PRT_ROT, CopyPart.dRot)
EgtSetInfo(nPartDuploId, MGR_PRT_FLIP, CopyPart.nFlip)
' scrivo dati costruzione grezzo in gruppo di lavorazione
EgtSetInfo(nCurrMachGroup, MGR_RPT_PART & (Index + 1), nPartDuploId & "," & CopyPart.sPosX & "," & CopyPart.sPosY & ",0,0")
Next
BeamWallMachGroup = Map.refMachGroupPanelVM.GetLastMachGroup()
' eseguo script creazione grezzo
Dim sLogPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\RawPartLog.txt"
If Not ExecWall(sLogPath, ProjectManagerVM.CurrProd.sMachine, CalcIntegration.CmdTypes.RAWPART, False, False) Then
BeamWallMachGroup.DeleteMachGroup()
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
Return Nothing
End If
' aggiorno contatore pezzi usati in Prod
For Each Part In PartList
Part.RefreshPartInProd()
Next
'aggiorno lista pezzi
BeamWallMachGroup.MyMachGroupM.RefreshPartList()
BeamWallMachGroup.MyMachGroupM.RefreshGroupData()
' aggiorno dati ultilizzo barra
BeamWallMachGroup.UpdateUsage()
Core.ViewPanelVM.BWSetView(VT.TOP, False)
Next
End If
Return BeamWallMachGroup
End Function
Friend Function ReDrawBeamMachgroup() As Boolean
' scrivo dati di tutti i pezzi
Dim dPosX As Double = MyMachGroupM.dStartCut
Dim nIndex As Integer
For nIndex = 0 To PartVMList.Count - 1
If nIndex <> 0 Then
dPosX += PartVMList(nIndex).PartM.dOffset
End If
PartVMList(nIndex).dPOSX = dPosX
EgtSetInfo(Id, MGR_RPT_PART & nIndex + 1, PartVMList(nIndex).nPartId & "," & DoubleToString(dPosX, 3))
dPosX += PartVMList(nIndex).dL
Next
' elimino eventuali successive info pezzi di troppo
nIndex = PartVMList.Count + 1
Dim sTemp As String = ""
While EgtGetInfo(Id, MGR_RPT_PART & nIndex, sTemp)
EgtSetInfo(Id, MGR_RPT_PART & nIndex, "")
nIndex += 1
End While
' elimino vecchio grezzo ed eseguo script creazione nuovo
Dim nRawId As Integer = EgtGetFirstRawPart()
While nRawId <> GDB_ID.NULL
EgtRemovePartFromRawPart(EgtGetFirstPartInRawPart(nRawId))
EgtRemoveRawPart(nRawId)
nRawId = EgtGetFirstRawPart()
End While
Dim sLogPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\RawPartLog.txt"
Return ExecBeam(sLogPath, ProjectManagerVM.CurrProd.sMachine, CalcIntegration.CmdTypes.RAWPART, False)
End Function
Friend Sub MoveBeam(Beam As PartVM, MoveDirection As MoveDirections)
Dim nBeamIndex As Integer = PartVMList.IndexOf(Beam)
If nBeamIndex = 0 AndAlso MoveDirection = MoveDirections.UP Then Return
If nBeamIndex = PartVMList.Count - 1 AndAlso MoveDirection = MoveDirections.DOWN Then Return
' se pezzo mosso diventa primo
Dim FirstBeam As PartVM = PartVMList(0)
If (nBeamIndex = 1 AndAlso MoveDirection = MoveDirections.UP) OrElse (nBeamIndex = 0 AndAlso MoveDirection = MoveDirections.DOWN) Then
'' resetto offset per vecchio primo
FirstBeam.ResetOffset()
End If
PartVMList.Move(nBeamIndex, nBeamIndex + MoveDirection)
ReDrawBeamMachgroup()
' aggiorno offset primo pezzo
PartVMList(0).PartM.UpdateOffset()
PartVMList(0).NotifyPropertyChanged(NameOf(FirstBeam.sOffset))
End Sub
Friend Sub ReorderBeam()
Dim TempPartList = PartVMList.OrderBy(Function(x) x.dL).ToList()
' verifico se sono già in oridne
Dim bSort As Boolean = True
For PartIndex = 0 To PartVMList.Count - 1
If PartVMList(PartIndex).nPartId <> TempPartList(PartIndex).nPartId Then
bSort = False
Exit For
End If
Next
If bSort Then Return
' resetto offset primo pezzo
Dim FirstBeam As PartVM = PartVMList(0)
FirstBeam.ResetOffset()
For PartIndex = 0 To TempPartList.Count - 1
If PartVMList(PartIndex).nPartId <> TempPartList(PartIndex).nPartId Then
PartVMList.Move(PartVMList.IndexOf(TempPartList(PartIndex)), PartIndex)
End If
Next
ReDrawBeamMachgroup()
' aggiorno offset primo pezzo
FirstBeam.PartM.UpdateOffset()
FirstBeam.NotifyPropertyChanged(NameOf(FirstBeam.sOffset))
End Sub
Private Function VerifyPartCount(SelParts As List(Of BTLPartVM), Optional Qty As Integer = 1) As Boolean
Dim sPartToAdd As String = "Raggiunto numero di pezzi da produrre per:"
Dim bPartToAdd As Boolean = False
For Each Part In SelParts
' verifico se ci sono pezzi da aggiungere
If Not Part.CanAddPartToCount(Qty) Then
bPartToAdd = True
sPartToAdd &= Environment.NewLine & "- PDN" & Part.nPDN & " | BTL QTY " & Part.nCNT & " | ADDED QTY " & Part.nADDED
End If
Next
sPartToAdd &= Environment.NewLine & "Aggiungerli?"
If bPartToAdd Then
If EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, sPartToAdd, "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
For Each Part In SelParts
If Not Part.CanAddPartToCount() Then Part.AddNewPartToAdded()
Next
Else
Return False
End If
End If
Return True
End Function
Private Sub ReadProductionState()
If IsNothing(Map.refProdManagerVM) OrElse IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(ProjectManagerVM.CurrProd.nProdId) Then Return
Dim MachGroupModel As MachGroupModel = DbControllers.m_MachGroupController.FindByMachGroupId(ProjectManagerVM.CurrProd.nProdId, Id)
If Not IsNothing(MachGroupModel) Then
If Not String.IsNullOrEmpty(MachGroupModel.SupervisorId) Then
SetSupervisorId(MachGroupModel.SupervisorId)
End If
nProduction_State = MachGroupModel.State
dtStartTime = MachGroupModel.DtStart
dtEndTime = MachGroupModel.DtEnd
NotifyPropertyChanged(NameOf(ButtonIsEnabled))
End If
End Sub
Friend Sub ResetCalcTotalMachGroup()
ResetCalcMachGroup()
For Each Part In PartVMList
Part.ResetCalcPart()
For Each Feature As BTLFeatureVM In Part.FeatureVMList
Feature.ResetCalcFeature()
Next
Next
End Sub
Public Sub ResetSupervisorId()
' resetto stato per MachGroup
nProduction_State = ItemState.ND
SetSupervisorId("")
Dim bTotDuploToUpdate As Boolean = False
Dim bTotIsModified As Boolean = False
' sblocco duplo di tutti i part
For Each Part In PartVMList
' recupero se Duplo da aggiornare
Dim bDuploToUpdate As Boolean = False
If EgtGetInfo(Part.nPartId, GDB_SI_DUPTOUPDATE, bDuploToUpdate) AndAlso bDuploToUpdate Then
bTotDuploToUpdate = True
End If
' verifico tipo di progetto
Dim nBtlInfoId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, BTLINFO)
Dim nBWType As Integer = 0
EgtGetInfo(nBtlInfoId, BTL_GEN_PROJTYPE, nBWType)
Dim DuploRot As Integer = 0
Dim DuploFlip As Integer = 0
' se da aggiornare, leggo info del duplo che verrebbero perse
If bDuploToUpdate Then
' recupero ROT (gradi) e FLIP (gradi) per non perderli
EgtGetInfo(Part.nPartId, MGR_PRT_ROT, DuploRot)
EgtGetInfo(Part.nPartId, MGR_PRT_FLIP, DuploFlip)
If DuploFlip <> 0 Then DuploFlip = 180
If nBWType = BWType.WALL Then
' ciclo sugli outline
Dim nOutlineLayer As Integer = EgtGetFirstNameInGroup(Part.nPartId, OUTLINE)
If nOutlineLayer <> GDB_ID.NULL Then
Dim nGlobPRId As Integer = 1
Dim nOutlineId As Integer = EgtGetFirstInGroup(nOutlineLayer)
While nOutlineId <> GDB_ID.NULL
' verifico che sia outline
Dim nPRC As Integer
If EgtGetInfo(nOutlineId, MGR_FTR_PRC, nPRC) Then
Dim nPRId As Integer = 0
If Not EgtGetInfo(nOutlineId, MGR_FTR_PRID, nPRId) Then
EgtSetInfo(nOutlineId, MGR_FTR_PRID, nGlobPRId)
nPRId = nGlobPRId
bTotIsModified = True
nGlobPRId += 1
End If
End If
nOutlineId = EgtGetNext(nOutlineId)
End While
End If
End If
End If
' disabilito impostazione modificato
Dim DisableMgr As New DisableModifiedMgr
' sblocco Duplo
EgtDuploResetLocked(Part.nPartId)
' ripristino precedente impostazione modificato
DisableMgr.ReEnable()
' se da aggiornare, ripristino info del duplo che verrebbero perse
If bDuploToUpdate Then
' ripristino i valori di ROT e FLIP
EgtSetInfo(Part.nPartId, MGR_PRT_ROT, DuploRot)
EgtSetInfo(Part.nPartId, MGR_PRT_FLIP, DuploFlip)
End If
Part.nProduction_State = ItemState.ND
Part.NotifyPropertyChanged(NameOf(Part.Background))
If bDuploToUpdate Then
Dim Duplo As PartVM = CALCPanelVM.GetPartVMFromPartId(Part.nPartId)
Duplo.ResetCalcTotalPart()
End If
Next
If bTotDuploToUpdate Then
m_RefreshPartList_Timer.Start()
End If
If bTotIsModified Then
Dim CurrFilePath As String = ""
EgtGetCurrFilePath(CurrFilePath)
EgtSaveFile(CurrFilePath, NGE.CMPTEXT)
End If
NotifyPropertyChanged(NameOf(IsReadOnly))
NotifyPropertyChanged(NameOf(Background))
End Sub
Private Sub RefreshPartList_Tick()
m_RefreshPartList_Timer.Stop()
Dim nCurrMachGroupId As Integer = EgtGetCurrMachGroup()
EgtSetCurrMachGroup(Id)
DirectCast(MachGroupM, MyMachGroupM).RefreshPartList()
EgtSetCurrMachGroup(nCurrMachGroupId)
End Sub
Public Overrides Sub RefreshMachGroup()
For Each Part In PartVMList
Part.RefreshPart()
Next
End Sub
#End Region ' Machgroup
#Region "Parts"
Protected Overrides Sub CreatePartVMList()
Dim all As List(Of PartVM) = (From PartM In MyMachGroupM.GetParts()
Select New PartVM(PartM, Me)).ToList()
For Each PartVM As PartVM In all
AddHandler PartVM.PropertyChanged, AddressOf OnPartVMPropertyChanged
Next
m_PartVMList = New ObservableCollection(Of Core.PartVM)(all)
AddHandler m_PartVMList.CollectionChanged, AddressOf OnPartVMListChanged
End Sub
Public Overrides Sub RefreshPartList()
If nType = BWType.BEAM Then
' leggo StartCut da posizione primo pezzo
Dim sInfo As String = ""
Dim sSplitInfo() As String
Dim bFound As Boolean = False
EgtGetInfo(Id, MGR_RPT_PART & 1, sInfo)
If Not String.IsNullOrWhiteSpace(sInfo) Then
sSplitInfo = sInfo.Split(","c)
StringToDoubleAdv(sSplitInfo(1), MyMachGroupM.dStartCut)
Else
MyMachGroupM.dStartCut = 0
End If
End If
End Sub
#End Region ' Parts
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
Public Overrides Sub DeleteMachGroup(Optional bMultipleCommand As Boolean = False)
If EgtSetCurrMachGroup(Me.Id) Then
' elimino tutte le copie
Dim nRawPartId As Integer = EgtGetFirstRawPart()
If nType = BWType.BEAM Then
Dim nBeamId As Integer = EgtGetFirstPartInRawPart(nRawPartId)
While nRawPartId <> GDB_ID.NULL
If EgtRemovePartFromRawPart(nBeamId) Then
Dim BTLPart As BTLPartVM = BTLPartVM.RetrieveBTLPartFromPart(nBeamId)
EgtErase(nBeamId)
If Not IsNothing(BTLPart) Then BTLPart.RefreshPartInProd()
End If
nRawPartId = EgtGetNextRawPart(nRawPartId)
nBeamId = EgtGetFirstPartInRawPart(nRawPartId)
End While
Else
Dim nWallId As Integer = EgtGetFirstPartInRawPart(nRawPartId)
While nWallId <> GDB_ID.NULL
If EgtRemovePartFromRawPart(nWallId) Then
Dim BTLPart As BTLPartVM = BTLPartVM.RetrieveBTLPartFromPart(nWallId)
EgtErase(nWallId)
If Not IsNothing(BTLPart) Then BTLPart.RefreshPartInProd()
End If
nWallId = EgtGetFirstPartInRawPart(nRawPartId)
End While
End If
' elimino MachGroup
EgtRemoveMachGroup(Me.Id)
End If
' cambio pezzo selezionato
If bMultipleCommand Then
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(1)
Else
Map.refMachGroupPanelVM.SelectedMachGroup = Nothing
EgtDraw()
End If
ElseIf Index = Map.refMachGroupPanelVM.MachGroupVMList.Count - 1 Then
If Map.refMachGroupPanelVM.MachGroupVMList.Count > 1 Then
Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(Map.refMachGroupPanelVM.MachGroupVMList.Count - 2)
Else
Map.refMachGroupPanelVM.SelectedMachGroup = Nothing
EgtDraw()
End If
Else
Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(Index - 1)
End If
End If
' rimuovo dalla lista grezzi
Map.refMachGroupPanelVM.MachGroupVMList.Remove(Me)
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "VerifyCommand"
Public ReadOnly Property Verify_Command As ICommand
Get
If m_cmdVerify Is Nothing Then
m_cmdVerify = New Command(AddressOf Verify)
End If
Return m_cmdVerify
End Get
End Property
Friend Sub Verify()
If ((IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM))) Then Return
Map.refProjectVM.BTLStructureVM.SelBTLPart.SetIsRowEnabled(False)
Map.refCALCPanelVM.Verify(ProjectType.PROD, CalcIntegration.CmdTypes.CHECKGEN)
Return
End Sub
#End Region ' VerifyCommand
#Region "SimulateCommand"
Public ReadOnly Property Simulate_Command As ICommand
Get
If m_cmdSimulate Is Nothing Then
m_cmdSimulate = New Command(AddressOf Simulate)
End If
Return m_cmdSimulate
End Get
End Property
Friend Sub Simulate()
If ((IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.BTLStructureVM)) AndAlso (IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM))) Then Return
Dim ProjType As BWType
Dim BarList() As EgtBEAMWALL.Core.Bar = Nothing
ProjType = Map.refProdManagerVM.CurrProd.nType
If Not CreateBarToSimulate(ProjType, BarList) Then Return
' lancio simulazione
EgtBEAMWALL.Core.CalcIntegration.Run(BarList, ProjectManagerVM.CurrProd.sProdDirPath, AddressOf ManageCalc)
End Sub
Private Function CreateBarToSimulate(ProjType As BWType, ByRef BarList As Bar()) As Boolean
If Not IsNothing(Map.refMachGroupPanelVM.SelectedMachGroup) Then
Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
Dim TempBarList(0) As EgtBEAMWALL.Core.Bar
Dim MachineName As String = ""
EgtGetMachGroupMachineName(SelMachGroup.Id, MachineName)
Dim Bar As New EgtBEAMWALL.Core.Bar With {.nBarId = SelMachGroup.Id,
.nProgramPage = ProjectType.PROD,
.nProjType = ProjType,
.bBarOk = True,
.nMachineName = MachineName,
.nCmdType = CalcIntegration.CmdTypes.SIMULATE,
.nGlobState = SelMachGroup.nGlobalState}
If SelMachGroup.nGlobalState = CalcStates.NOTCALCULATED Then
Dim sMachGroupFilePath As String = ProjectManagerVM.CurrProd.sProdDirPath & "\" & SelMachGroup.Name.ToString() & ".ori.bwe"
If File.Exists(sMachGroupFilePath) Then File.Delete(sMachGroupFilePath)
End If
TempBarList(0) = Bar
BarList = TempBarList
Else
Return False
End If
' disabilito interfaccia
Map.refProjectVM.SetCalcRunning(True)
' End If
Return True
End Function
' funzione che gestisce risposta da thread di verifica, aggiorna progress e segnala comando di interruzione
Private Sub ManageCalc(dProgress As Double, sProgress As String, ByRef bCancel As Boolean)
If dProgress = 0 Then
Map.refMyStatusBarVM.SetLoadingProgress_Visibility(True)
Map.refMyStatusBarVM.SetStopProgress_IsActive(True)
Map.refMyStatusBarVM.SetStopProgress_IsEnabled(True)
Map.refMyStatusBarVM.SetOutputMessage(sProgress)
Map.refMyStatusBarVM.SetStopProgress_IsActive(True)
Map.refMyStatusBarVM.SetStopProgress_IsEnabled(True)
ElseIf dProgress = 1 Then
Map.refMyStatusBarVM.SetLoadingProgress_Visibility(False)
Map.refMyStatusBarVM.SetStopProgress_IsActive(False)
Map.refMyStatusBarVM.SetStopProgress_IsEnabled(False)
Map.refMyStatusBarVM.SetOutputMessage(sProgress, 3)
End If
bCancel = Map.refMyStatusBarVM.bStopProgress
Map.refMyStatusBarVM.SetLoadingProgress(dProgress * 100)
Map.refMyStatusBarVM.SetOutputMessage(sProgress)
End Sub
#End Region ' SimulateCommand
#Region "ProduceRawPart"
Public ReadOnly Property ProduceRawPart_Command As ICommand
Get
If m_cmdProduceRawPart Is Nothing Then
m_cmdProduceRawPart = New Command(AddressOf ProduceRawPart)
End If
Return m_cmdProduceRawPart
End Get
End Property
Public Sub ProduceRawPart()
If IsNothing(ProjectManagerVM.CurrProd) Then Return
Dim ErrorMsg As String = ""
' se attiva opzione e non ancora calcolato
If GetMainPrivateProfileInt(S_GENERAL, K_FASTPRODUCE, 0) = 1 And Map.refMachGroupPanelVM.SelectedMachGroup.nGlobalState = CalcStates.NOTCALCULATED Then
Map.refCALCPanelVM.SetFromProduce(CALCPanelVM.ProduceType.PRODUCE)
Map.refCALCPanelVM.Verify(ProjectType.PROD, CalcIntegration.CmdTypes.CHECKNOSIM)
Return
End If
' verifico se modalita' supervisore attiva
If GetPrivateProfileInt(S_GENERAL, K_SUPERVISOR, 1, CurrentMachine.sMachIniFile) = 1 Then
If Not Produce(Map.refMachGroupPanelVM.SelectedMachGroup, ErrorMsg) AndAlso Not String.IsNullOrWhiteSpace(ErrorMsg) Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, ErrorMsg)
End If
Else
' altrimenti lo copio se path disponibile
If Map.refMachGroupPanelVM.SelectedMachGroup.nGlobalState = CalcStates.OK Or Map.refMachGroupPanelVM.SelectedMachGroup.nGlobalState = CalcStates.INFO Then
Dim sSaveCncPath As String = ""
GetPrivateProfileString(S_GENERAL, K_SAVECNCPATH, "", sSaveCncPath, CurrentMachine.sMachIniFile)
Dim sSaveExt As String = ""
GetPrivateProfileString(S_GENERAL, K_SAVEEXT, "", sSaveExt, CurrentMachine.sMachIniFile)
If String.IsNullOrWhiteSpace(sSaveExt) Then
sSaveExt = ".cnc"
ElseIf sSaveExt(0) <> "." Then
sSaveExt = "." & sSaveExt
End If
Try
Dim sMachGroupFilePath As String = Map.refProdManagerVM.CurrProd.sProdDirPath & "\" & Map.refMachGroupPanelVM.SelectedMachGroup.Name.ToString() & ".cnc"
Dim sNewPath As String = sSaveCncPath & "\" & Map.refProdManagerVM.CurrProd.sProdId & "-" & Map.refMachGroupPanelVM.SelectedMachGroup.Name.ToString() & sSaveExt
File.Copy(sMachGroupFilePath, sNewPath, True)
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, String.Format(EgtMsg(62584), {sNewPath}), EgtMsg(15003), MessageBoxButton.OK, MessageBoxImage.Information)
Catch ex As Exception
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, String.Format(EgtMsg(62585), {sSaveCncPath}), EgtMsg(15001), MessageBoxButton.OK, MessageBoxImage.Error)
End Try
End If
End If
End Sub
Private Function Produce(MachGroup As MyMachGroupVM, ByRef ErrorMsg As String) As Boolean
If IsNothing(MachGroup) Then Return False
' se barra gia' assegnata a supervisore, esco
If MachGroup.nProduction_State >= ItemState.Assigned Then Return False
If MachGroup.nGlobalState = CalcStates.OK Or MachGroup.nGlobalState = CalcStates.INFO Then
' se ci sono modifiche, salvo il pogetto
If EgtGetModified() Then
Map.refProdManagerVM.Save()
End If
' mando al supervisore
DbControllers.m_MachGroupController.UpdateOrder(ProjectManagerVM.CurrProd.nProdId, MachGroup.Id, DbControllers.m_MachGroupController.GetMinIndex(ProjectManagerVM.CurrProd.nProdId) + 1)
DbControllers.m_MachGroupController.UpdateSupervisor(ProjectManagerVM.CurrProd.nProdId, MachGroup.Id, DbControllers.m_SupervisorId)
MachGroup.SentToSupervisor()
For Each Part As PartVM In MachGroup.PartVMList
DbControllers.m_PartController.UpdateStatus(ProjectManagerVM.CurrProd.nProdId, MachGroup.Id, Part.nPartId, ItemState.Assigned)
Part.nProduction_State = ItemState.Assigned
Part.NotifyPropertyChanged(NameOf(Part.Background))
MachGroup.NotifyPropertyChanged(NameOf(MachGroup.ButtonIsEnabled))
Part.NotifyPropertyChanged(NameOf(Part.ButtonIsEnabled))
For Each Feature As BTLFeatureVM In Part.FeatureVMList
Feature.NotifyPropertyChanged(NameOf(Feature.IsEnabled))
Next
' disabilito impostazione modificato
Dim DisableMgr As New DisableModifiedMgr
' blocco modifica del pezzo
EgtDuploSetLocked(Part.nPartId)
' ripristino precedente impostazione modificato
DisableMgr.ReEnable()
Next
Return True
Else
ErrorMsg = String.Format(EgtMsg(62568), MachGroup.Name)
Return False
End If
End Function
#End Region ' ProduceRawPart
#Region "CopyRawPart"
Public ReadOnly Property CopyRawPart_Command As ICommand
Get
If m_cmdCopyRawPart Is Nothing Then
m_cmdCopyRawPart = New Command(AddressOf CopyRawPart)
End If
Return m_cmdCopyRawPart
End Get
End Property
Public Sub CopyRawPart()
If IsNothing(ProjectManagerVM.CurrProd) Then Return
Dim nQty As Integer = 1
' se premuto shift
If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then
Dim MultiCopyRawPartWndVM As New MultiCopyRawPartWndVM()
Dim MultiCopyRawPartWnd As New MultiCopyRawPartWndV(Application.Current.MainWindow, MultiCopyRawPartWndVM)
If Not MultiCopyRawPartWnd.ShowDialog() Then Return
nQty = MultiCopyRawPartWndVM.nQuantity
End If
Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
If IsNothing(SelMachGroup) Then Return
' creo copia
Dim NewMachGroup As MyMachGroupVM = SelMachGroup.Copy(nQty)
If Not IsNothing(NewMachGroup) Then
' lo seleziono
Map.refProjectVM.MachGroupPanelVM.SelectedMachGroup = NewMachGroup
End If
End Sub
#End Region ' CopyRawPart
#Region "RemoveRawPart"
Public ReadOnly Property RemoveRawPart_Command As ICommand
Get
If m_cmdRemoveRawPart Is Nothing Then
m_cmdRemoveRawPart = New Command(AddressOf RemoveRawPartCmd)
End If
Return m_cmdRemoveRawPart
End Get
End Property
Public Sub RemoveRawPartCmd()
If EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(62574) & Map.refProjectVM.MachGroupPanelVM.SelectedMachGroup.Name & " ?", EgtMsg(30009), MessageBoxButton.OKCancel, MessageBoxImage.Exclamation) = MessageBoxResult.OK Then
RemoveRawPart()
Else
Return
End If
End Sub
Public Sub RemoveRawPart(Optional bAll As Boolean = False)
If IsNothing(ProjectManagerVM.CurrProd) Then Return
' se tutti
If bAll Then
' cancello tutti
For Index = Map.refMachGroupPanelVM.MachGroupVMList.Count - 1 To 0 Step -1
Dim CurrMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.MachGroupVMList(Index)
' se barra gia' assegnata a supervisore, esco
If CurrMachGroup.nProduction_State >= ItemState.Assigned Then Continue For
CurrMachGroup.DeleteMachGroup(True)
Next
Else
Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
If IsNothing(SelMachGroup) Then Return
' se barra gia' assegnata a supervisore, esco
If SelMachGroup.nProduction_State >= ItemState.Assigned Then Return
SelMachGroup.DeleteMachGroup()
If Not IsNothing(Map.refMachGroupPanelVM.SelectedMachGroup) Then
Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(0)
End If
End If
EgtDraw()
' se nessun grezzo, rimetto tutti i pezzi invisibili
If Map.refProjectVM.MachGroupPanelVM.MachGroupVMList.Count = 0 Then
Map.refProjectVM.BTLStructureVM.HideAll(True)
End If
End Sub
#End Region ' RemoveRawPart
#Region "ReOrderPart"
Public ReadOnly Property ReOrderPart_Command As ICommand
Get
If m_cmdReOrderPart Is Nothing Then
m_cmdReOrderPart = New Command(AddressOf ReOrderPart)
End If
Return m_cmdReOrderPart
End Get
End Property
Public Sub ReOrderPart()
If IsNothing(ProjectManagerVM.CurrProd) Then Return
Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
If IsNothing(SelMachGroup) Then Return
' se barra gia' assegnata a supervisore, esco
If SelMachGroup.nProduction_State >= ItemState.Assigned Then Return
If SelMachGroup.nType = MachineType.BEAM Then
SelMachGroup.ReorderBeam()
EgtDraw()
End If
SelMachGroup.ResetCalcMachGroup()
End Sub
#End Region ' ReOrderPart
#Region "ResetCalc"
Public ReadOnly Property ResetCalc_Command As ICommand
Get
If m_cmdResetCalc Is Nothing Then
m_cmdResetCalc = New Command(AddressOf ResetCalc)
End If
Return m_cmdResetCalc
End Get
End Property
Public Sub ResetCalc()
If IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM) Then Return
Map.refShowBeamPanelVM.ShowBuilding_IsEnabled = True
Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
If IsNothing(SelMachGroup) Then Return
' se barra gia' assegnata a supervisore, esco
If SelMachGroup.nProduction_State >= ItemState.Assigned Then Return
If SelMachGroup.nGlobalState <> CalcStates.NOTCALCULATED Then
SelMachGroup.ResetCalcTotalMachGroup()
End If
End Sub
#End Region ' ResetCalc
#End Region ' COMMANDS
#Region "EVENTS"
Protected Overrides Sub OnPartAdded(sender As Object, e As PartAddedEventArgs)
Dim PartVM As PartVM = New PartVM(e.NewPart, Me)
PartVMList.Add(PartVM)
End Sub
#End Region ' EVENTS
End Class
Class CopyPart
Private m_BTLPart As BTLPartVM
Public ReadOnly Property BTLPart As BTLPartVM
Get
Return m_BTLPart
End Get
End Property
Private m_sPosX As String
Public ReadOnly Property sPosX As String
Get
Return m_sPosX
End Get
End Property
Private m_sPosY As String
Public ReadOnly Property sPosY As String
Get
Return m_sPosY
End Get
End Property
Private m_dRot As Double
Public ReadOnly Property dRot As Double
Get
Return m_dRot
End Get
End Property
Private m_nFlip As Integer
Public ReadOnly Property nFlip As Integer
Get
Return m_nFlip
End Get
End Property
Sub New(BTLPart As BTLPartVM, sPosX As String, sPosY As String, dRot As Double, nFlip As Integer)
m_BTLPart = BTLPart
m_sPosX = sPosX
m_sPosY = sPosY
m_dRot = dRot
m_nFlip = nFlip
End Sub
End Class