Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/MachGroupPanel/PartVM.vb
T
Emmanuele Sassi 52eec22b63 - modifiche su verifica e simula per mantenere modifiche manuali
- aggiornato stile elemento selezionato sulle datagrid
- corretto posizionamento pezzo in grezzo con aree lavorate
2021-12-28 17:46:10 +01:00

418 lines
15 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.IO
Imports EgtBEAMWALL.Core
Imports EgtBEAMWALL.DataLayer.DatabaseModels
Imports EgtUILib
Imports EgtWPFLib5
Public Class PartVM
Inherits Core.PartVM
#Region "FIELDS & PROPERTIES"
#Region "Beam"
Public Overrides Property sOffset As String
Get
Return LenToString(m_PartM.dOffset, 3)
End Get
Set(value As String)
Dim dValue As Double
If StringToLen(value, dValue) Then
Dim dOldValue As Double = m_PartM.dOffset
m_PartM.dOffset = dValue
' se prima trave della barra sostituisco valore anche a startoffset
Dim BeamMachGroup As MyMachGroupVM = DirectCast(ParentMachGroupVM, MyMachGroupVM)
If ParentMachGroupVM.PartVMList(0) Is Me Then
BeamMachGroup.dStartCut = dValue
End If
If Not BeamMachGroup.ReDrawBeamMachgroup() Then
' rispristino vecchio valore
m_PartM.dOffset = dOldValue
BeamMachGroup.dStartCut = dOldValue
BeamMachGroup.ReDrawBeamMachgroup()
End If
' resetto validazione del pezzo
ResetCalcPart()
Else
NotifyPropertyChanged(NameOf(sOffset))
End If
End Set
End Property
#End Region ' Beam
#Region "Wall"
Public Overrides Property sPOSX As String
Get
Select Case Map.refProjectVM.BTLStructureVM.nPROJTYPE
Case BWType.WALL
' se parete, valuto angolo di posizionamento
Select Case CurrentMachine.NestingCorner
Case MCH_CR.TL, MCH_CR.BL
Return LenToString(m_PartM.dPOSX, 3)
Case Else ' MCH_CR.TR, MCH_CR.BR
Return LenToString(m_ParentMachGroupVM.dL - dL - m_PartM.dPOSX, 3)
End Select
Case Else
Return LenToString(m_PartM.dPOSX, 3)
End Select
End Get
Set(value As String)
Dim dValue As Double
If StringToLen(value, dValue) Then
Dim dOldValue As Double = m_PartM.dPOSX
Dim dNewValue As Double = dValue
Select Case Map.refProjectVM.BTLStructureVM.nPROJTYPE
Case BWType.WALL
' se parete, valuto angolo di posizionamento
Select Case CurrentMachine.NestingCorner
Case MCH_CR.TL, MCH_CR.BL
dNewValue = dValue
Case Else ' MCH_CR.TR, MCH_CR.BR
dNewValue = m_ParentMachGroupVM.dL - dL - dValue
End Select
Case Else
m_PartM.dPOSX = dValue
End Select
If EgtMovePartInRawPart(nPartId, New Vector3d(dNewValue - dOldValue, 0, 0)) Then
EgtSetInfo(nPartId, MGR_PRT_POSX, dValue)
NotifyPropertyChanged(NameOf(sPOSX))
' resetto validazione del pezzo
ResetCalcPart()
Else
' ripristino vecchio valore
m_PartM.dPOSX = dOldValue
End If
EgtDraw()
Else
NotifyPropertyChanged(NameOf(sPOSX))
End If
End Set
End Property
Public Overrides Property sPOSY As String
Get
Select Case Map.refProjectVM.BTLStructureVM.nPROJTYPE
Case BWType.WALL
' valuto angolo di posizionamento
Select Case CurrentMachine.NestingCorner
Case MCH_CR.TL, MCH_CR.TR
Return LenToString(m_ParentMachGroupVM.dW - dW - m_PartM.dPOSY, 3)
Case Else ' MCH_CR.BL, MCH_CR.BR
Return LenToString(m_PartM.dPOSY, 3)
End Select
Case Else
Return LenToString(m_PartM.dPOSY, 3)
End Select
End Get
Set(value As String)
Dim dValue As Double
If StringToLen(value, dValue) Then
Dim dOldValue As Double = m_PartM.dPOSY
Dim dNewValue As Double = dValue
' valuto angolo di posizionamento
Select Case Map.refProjectVM.BTLStructureVM.nPROJTYPE
Case BWType.WALL
Select Case CurrentMachine.NestingCorner
Case MCH_CR.TL, MCH_CR.TR
dNewValue = m_ParentMachGroupVM.dW - dW - dValue
Case MCH_CR.BL, MCH_CR.BR
dNewValue = dValue
End Select
Case Else
m_PartM.dPOSY = dValue
End Select
If EgtMovePartInRawPart(nPartId, New Vector3d(0, dNewValue - dOldValue, 0)) Then
EgtSetInfo(nPartId, MGR_PRT_POSY, dValue)
NotifyPropertyChanged(NameOf(sPOSY))
' resetto validazione del pezzo
ResetCalcPart()
Else
' ripristino vecchio valore
m_PartM.dPOSY = dOldValue
End If
EgtDraw()
Else
NotifyPropertyChanged(NameOf(sPOSY))
End If
End Set
End Property
Public Overrides Property bFLIP As Boolean
Get
Return m_PartM.bFLIP
End Get
Set(value As Boolean)
' se MachGroup gia' mandato in produzione, esco
If m_ParentMachGroupVM.nProduction_State >= ItemState.Assigned Then Return
If value <> m_PartM.bFLIP Then
' salvo posizione
Dim dTempPosX As Double = m_PartM.dPOSX
Dim dTempPosY As Double = m_PartM.dPOSY
' tolgo il pezzo dal grezzo
EgtRemovePartFromRawPart(nPartId)
' recupero layer del box
Dim nBoxLayerId As Integer = EgtGetFirstNameInGroup(nPartId, "Box")
' recupero box del layer box
Dim b3Box As New BBox3d
EgtGetBBoxGlob(nBoxLayerId, GDB_BB.STANDARD, b3Box)
If EgtRotate(nPartId, b3Box.Center, Vector3d.X_AX, 180, GDB_RT.GLOB) Then
m_PartM.bFLIP = value
EgtSetInfo(nPartId, MGR_PRT_FLIP, value)
Else
NotifyPropertyChanged(NameOf(bFLIP))
End If
' recupero box del pezzo
Dim b3Part As New BBox3d
EgtGetBBoxGlob(nPartId, GDB_BB.STANDARD, b3Part)
' calcolo distanza tra i box
Dim vtDeltaBox As Vector3d = b3Box.Min - b3Part.Min
' reinserisco il pezzo nel grezzo
EgtAddPartToRawPart(nPartId, New Point3d(dTempPosX - vtDeltaBox.x, dTempPosY - vtDeltaBox.y, 0), ParentMachGroupVM.MyMachGroupM.nRawPartId)
' lo riseleziono
EgtSelectObj(nPartId)
' resetto validazione del pezzo
ResetCalcPart()
EgtDraw()
End If
End Set
End Property
#End Region ' Wall
' Definizione comandi
Private m_cmdBackRotation As ICommand
Private m_cmdForwardRotation As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New(PartM As PartM, ParentMachGroupVM As MyMachGroupVM)
MyBase.New(PartM, ParentMachGroupVM)
' aggiorno stato calcolo
CalcGlobalUpdate()
' aggiorno stato di produzione
ReadProductionData()
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
#Region "Part"
Friend Sub ResetOffset()
m_PartM.dOffset = WarehouseHelper.GetOffset(nType)
NotifyPropertyChanged(NameOf(sOffset))
End Sub
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
Public Overrides Sub DeletePart()
' elimino pezzo copia
EgtRemovePartFromRawPart(Me.nPartId)
' Recupero Id BTLPart originale
Dim BTLPart As BTLPartVM = BTLPartVM.RetrieveBTLPartFromPart(nPartId)
EgtErase(Me.nPartId)
' rimuovo dalla lista pezzi
Dim Index As Integer = ParentMachGroupVM.PartVMList.IndexOf(ParentMachGroupVM.PartVMList.FirstOrDefault(Function(x) x.nPartId = nPartId))
If Index = 0 Then
If ParentMachGroupVM.PartVMList.Count > 1 Then
ParentMachGroupVM.SelPart = ParentMachGroupVM.PartVMList(0)
Else
ParentMachGroupVM.SelPart = Nothing
End If
ElseIf Index = ParentMachGroupVM.PartVMList.Count - 1 Then
If ParentMachGroupVM.PartVMList.Count > 1 Then
ParentMachGroupVM.SelPart = ParentMachGroupVM.PartVMList(ParentMachGroupVM.PartVMList.Count - 2)
Else
ParentMachGroupVM.SelPart = Nothing
End If
Else
ParentMachGroupVM.SelPart = ParentMachGroupVM.PartVMList(Index - 1)
End If
ParentMachGroupVM.PartVMList.Remove(Me)
If nType = MachineType.BEAM Then
Dim BeamParentMachGroup As MyMachGroupVM = DirectCast(ParentMachGroupVM, MyMachGroupVM)
If Not IsNothing(BeamParentMachGroup) Then BeamParentMachGroup.ReDrawBeamMachgroup()
End If
' aggiorno contatore pezzi usati in Prod
If Not IsNothing(BTLPart) Then BTLPart.RefreshPartInProd()
EgtDraw()
End Sub
Private Sub Rotate(IsPositive As Boolean)
' salvo posizione
Dim dTempPosX As Double = m_PartM.dPOSX
Dim dTempPosY As Double = m_PartM.dPOSY
' tolgo il pezzo dal grezzo
EgtRemovePartFromRawPart(nPartId)
' recupero layer del box
Dim nBoxLayerId As Integer = EgtGetFirstNameInGroup(nPartId, "Box")
' recupero box del layer box
Dim b3Box As New BBox3d
EgtGetBBoxGlob(nBoxLayerId, GDB_BB.STANDARD, b3Box)
' se invertito lo reinverto
Dim bFliped As Boolean = bFLIP
If bFliped Then EgtRotate(nPartId, b3Box.Center, Vector3d.X_AX, 180)
Dim dAng As Double = If(IsPositive, 90, -90)
' eseguo rotazione
Dim bOk As Boolean = EgtRotate(nPartId, b3Box.Center, -Vector3d.Z_AX, dAng)
If bOk Then
Dim TempRot = m_PartM.dROT
TempRot += dAng
If TempRot >= 360 Then
TempRot -= 360
ElseIf TempRot < 0 Then
TempRot += 360
End If
m_PartM.dROT = TempRot
EgtSetInfo(nPartId, MGR_PRT_ROT, m_PartM.dROT)
End If
' ripristino eventuale inversione
If bFliped Then EgtRotate(nPartId, b3Box.Center, Vector3d.X_AX, 180)
' recupero box del pezzo
Dim b3Part As New BBox3d
EgtGetBBoxGlob(nPartId, GDB_BB.STANDARD, b3Part)
'aggiorno box del box con rotazione
EgtGetBBoxGlob(nBoxLayerId, GDB_BB.STANDARD, b3Box)
' calcolo distanza tra i box
Dim vtDeltaBox As Vector3d = b3Box.Min - b3Part.Min ' Vector3d.NULL
' calcolo posizione rispetto al riferimento
Select Case Map.refProjectVM.BTLStructureVM.nPROJTYPE
Case BWType.WALL
' se parete, valuto angolo di posizionamento
Select Case CurrentMachine.NestingCorner
Case MCH_CR.TL
'vtDeltaBox = New Vector3d(b3Box.Min.x - b3Part.Min.x, b3Box.Max.y - b3Part.Max.y, 0)
dTempPosY = dTempPosY - dW + dL
Case MCH_CR.BL
'vtDeltaBox = b3Box.Min - b3Part.Min
' non cambio posizioni
Case MCH_CR.TR
'vtDeltaBox = b3Box.Max - b3Part.Max
dTempPosX = dTempPosX - dL
dTempPosY = dTempPosY + dW - dL
Case MCH_CR.BR
'vtDeltaBox = New Vector3d(b3Box.Max.x - b3Part.Max.x, b3Box.Min.y - b3Part.Min.y, 0)
dTempPosX = dTempPosX - dL
End Select
Case Else
' non cambio nulla
End Select
' reinserisco il pezzo nel grezzo
EgtAddPartToRawPart(nPartId, New Point3d(dTempPosX - vtDeltaBox.x, dTempPosY - vtDeltaBox.y, 0), ParentMachGroupVM.MyMachGroupM.nRawPartId)
' lo riseleziono
EgtSelectObj(nPartId)
' resetto validazione del pezzo
ResetCalcPart()
NotifyPropertyChanged(NameOf(sROT))
End Sub
Friend Sub SelectBTLPart()
' eseguo la selezione nella lista pezzi
Dim nBTLPartId As Integer = MyMachGroupPanelM.DuploGetOriginal(nPartId)
If Not IsNothing(nBTLPartId) Then
Map.refProjectVM.BTLStructureVM.SetSelBTLPart(Map.refProjectVM.BTLStructureVM.BTLPartVMList.FirstOrDefault(Function(x) x.nPartId = nBTLPartId))
End If
End Sub
Private Sub ReadProductionData()
If IsNothing(Map.refProdManagerVM.CurrProd) OrElse IsNothing(Map.refProdManagerVM.CurrProd.nProdId) Then Return
Dim PartModel As PartModel = DbControllers.m_PartController.FindByPartId(Map.refProdManagerVM.CurrProd.nProdId, nPartId)
If Not IsNothing(PartModel) Then
PartM.SetProductionState(PartModel.State)
PartM.dtStartTime = PartModel.DtStart
PartM.dtEndTime = PartModel.DtEnd
End If
End Sub
#End Region ' Part
#Region "Feature"
Protected Overrides Sub CreateBTLFeatureVMList()
Dim all As List(Of BTLFeatureVM) = (From BTLFeatureM In m_PartM.GetBTLFeatures()
Select New BTLFeatureVM(BTLFeatureM)).ToList()
For Each BTLFeatureVM As BTLFeatureVM In all
AddHandler BTLFeatureVM.PropertyChanged, AddressOf OnBTLFeatureVMPropertyChanged
Next
m_FeatureVMList = New ObservableCollection(Of Core.BTLFeatureVM)(all)
AddHandler m_FeatureVMList.CollectionChanged, AddressOf OnBTLFeatureVMListChanged
End Sub
Friend Sub ResetCalcTotalPart()
ResetCalcPart()
For Each Feature In FeatureVMList
DirectCast(Feature, BTLFeatureVM).ResetCalcFeature()
Next
End Sub
#End Region ' Feature
#End Region ' METHODS
#Region "COMMANDS"
#Region "BackRotation"
Public ReadOnly Property BackRotation_Command As ICommand
Get
If m_cmdBackRotation Is Nothing Then
m_cmdBackRotation = New Command(AddressOf BackRotation)
End If
Return m_cmdBackRotation
End Get
End Property
Public Sub BackRotation()
' se MachGroup gia' mandato in produzione, esco
If m_ParentMachGroupVM.nProduction_State >= ItemState.Assigned Then Return
Rotate(False)
EgtDraw()
End Sub
#End Region ' BackRotation
#Region "ForwardRotation"
Public ReadOnly Property ForwardRotation_Command As ICommand
Get
If m_cmdForwardRotation Is Nothing Then
m_cmdForwardRotation = New Command(AddressOf ForwardRotation)
End If
Return m_cmdForwardRotation
End Get
End Property
Public Sub ForwardRotation()
' se MachGroup gia' mandato in produzione, esco
If m_ParentMachGroupVM.nProduction_State >= ItemState.Assigned Then Return
Rotate(True)
EgtDraw()
End Sub
#End Region ' ForwardRotation
#End Region ' COMMANDS
#Region "EVENTS"
Protected Overrides Sub OnBTLFeatureVMPropertyChanged(sender As Object, e As PropertyChangedEventArgs)
Select Case e.PropertyName
Case NameOf(sender.bDO)
' setto pezzo da ricalcolare
ResetCalcTotalPart()
End Select
End Sub
#End Region ' EVENTS
End Class