Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/MachGroupPanel/MyMachGroupPanelVM.vb
T
Demetrio Cassarino a12ab8f531 -pulizia codice
2024-06-13 17:36:10 +02:00

261 lines
11 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtBEAMWALL.Core
Imports EgtUILib
Public Class MyMachGroupPanelVM
Inherits Core.MyMachGroupPanelVM
#Region "FIELDS & PROPERTIES"
Public Shadows Property SelectedMachGroup As MyMachGroupVM
Get
Return m_SelectedMachGroup
End Get
Set(value As MyMachGroupVM)
' deevidenzio BTLPart di questo pezzo
If Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE Then
' mostro pezzi selezionati
If Map.refProjectVM.BTLStructureVM.SelBTLParts.Count = 1 Then
' se pezzo evidenziato da selezione precedente
If Map.refProjectVM.LastSelGridType = ProjectVM.GridSelTypes.PARTLIST Then
Dim nSelBTLPartId As Integer = Map.refProjectVM.BTLStructureVM.SelBTLParts(0).nPartId
' deevidenzio MachGroup e Duplo di questo pezzo
Configuration.ResetSearchPiece(nSelBTLPartId)
End If
End If
If Not IsNothing(SelectedMachGroup) AndAlso Not IsNothing(SelectedMachGroup.SelPart) AndAlso Not IsNothing(Map.refProjectVM.BTLStructureVM) Then
Configuration.ResetSearch(SelectedMachGroup.SelPart.nPartId)
End If
' se modalita' assemblato
Configuration.AssembledMode(Map.refShowBeamPanelVM.ShowBuilding_IsChecked)
' se precedente pezzo selezionato
If Not IsNothing(value) AndAlso Map.refProjectVM.LastSelGridType = ProjectVM.GridSelTypes.PART AndAlso Map.refProjectVM.BTLStructureVM.SelBTLParts.Count > 0 Then
Dim SelBTLPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLParts(0)
' deseleziono pezzo in lista BTLPart
For BTLPartIndex = Map.refProjectVM.BTLStructureVM.SelBTLParts.Count - 1 To 0 Step -1
Map.refProjectVM.BTLStructureVM.SelBTLParts.RemoveFromList(Map.refProjectVM.BTLStructureVM.SelBTLParts(BTLPartIndex))
Next
' e lo evidenzio
If Map.refShowBeamPanelVM.ShowBuilding_IsChecked Then
Map.refProdProjManagerVM.SelProdProj = ProdProj.NULL
Map.refShowBeamPanelVM.SetShowSolid(False)
Else
Map.refProjectVM.BTLStructureVM.SetSelectionType(BTLStructureVM.SelectionTypes.HIGHLIGHT)
End If
Map.refProjectVM.BTLStructureVM.SelBTLParts.Add(SelBTLPart)
End If
End If
If Map.refMainMenuVM.SelPage <> Pages.ONLYPRODPAGE Then Map.refShowBeamPanelVM.bShowAll = False
m_SelectedMachGroup = value
If Not IsNothing(value) Then
OnPreSetCurrMachGroup()
EgtSetCurrMachGroup(value.Id)
OnPostSetCurrMachGroup()
End If
NotifyPropertyChanged(NameOf(SelectedMachGroup))
' imposto tipo di grid selezionata
If Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE AndAlso Not IsNothing(value) Then
Map.refProjectVM.SetLastSelGridType(ProjectVM.GridSelTypes.MACHGROUP)
Map.refStatisticsTimePanelVM.SetMachiningPage_Visibility(Visibility.Visible)
Map.refStatisticsTimePanelVM.SetViewPage_Visibility(Visibility.Collapsed)
End If
' se MachGroup gia' mandato in produzione,disabilito pulsanti verify e reset
If Not IsNothing(SelectedMachGroup) AndAlso SelectedMachGroup.nProduction_State >= ItemState.Assigned Then
Map.refCALCPanelVM.SetVerifyIsEnabled(False)
Else
Map.refCALCPanelVM.SetCalcPanelIsEnabled(True)
End If
End Set
End Property
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New(MachGroupPanelM As MachGroupPanelM)
MyBase.New(MachGroupPanelM)
' elimino copie da cancellare
DeleteDuplo()
' verifico se volume grezzi calcolato
For Each MachGroup As MyMachGroupVM In m_MachGroupVMList
Dim bIsCalculated As Boolean = False
For Each Part In MachGroup.PartVMList
If Part.dVolume > 0 Then Continue For
Part.PartM.ReadVolume()
bIsCalculated = True
Next
If bIsCalculated Then
MachGroup.UpdateUsage()
End If
Next
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Protected Overrides Sub CreateMachGroupVMList()
Dim all As New List(Of MachGroupVM)
For Each MachGroupM In m_MachGroupPanelM.GetMachGroups()
all.Add(New MyMachGroupVM(MachGroupM))
Next
For Each MachGroupvM As MachGroupVM In all
AddHandler MachGroupvM.PropertyChanged, AddressOf OnMachGroupVMPropertyChanged
Next
MachGroupVMList = New ObservableCollection(Of MachGroupVM)(all)
AddHandler MachGroupVMList.CollectionChanged, AddressOf OnMachGroupVMListChanged
End Sub
Protected Overrides Sub OnMachGroupAdded(sender As Object, e As MachGroupAddedEventArgs)
Dim MachGroupVM As MachGroupVM = Nothing
Select Case DirectCast(e.NewMachGroupM, MyMachGroupM).nType
Case Core.ConstBeam.MachineType.BEAM, Core.ConstBeam.MachineType.WALL
MachGroupVM = New MyMachGroupVM(e.NewMachGroupM)
Case Core.ConstBeam.MachineType.NULL
Return
End Select
MachGroupVMList.Add(MachGroupVM)
NotifyPropertyChanged(NameOf(MachGroupVMList))
End Sub
Public Function RefreshMachGroupList() As Boolean
' carico lista dei gruppi di lavorazione
For Each MachGroup As MyMachGroupM In MyMachGroupPanelM.UpdateFromNestingMyMachGroups(Map.refMachinePanelVM.MachineList.ToList())
m_MachGroupPanelM.AddMachGroup(MachGroup)
Next
' aggiorno contatore pezzi in produzione
For Each MachGroup As MyMachGroupVM In MachGroupVMList
For Each Part In MachGroup.PartVMList
' aggiorno calcolo pezzi in produzione
Dim BTLPart As BTLPartVM = BTLPartVM.RetrieveBTLPartFromPart(Part.nPartId)
If Not IsNothing(BTLPart) Then BTLPart.RefreshPartInProd()
Next
Next
' seleziono primo MachGroup
If MachGroupVMList.Count > 0 Then SelectedMachGroup = MachGroupVMList(0)
EgtZoom(ZM.ALL)
Return True
End Function
' funzione utilizzata per caricare in lista gruppo aggiunto al progetto dal supervisore
Public Function AddMachGroupToList(nId As Integer) As Boolean
' carico gruppo di lavorazione
Dim MachGroup As MyMachGroupM = MyMachGroupPanelM.LoadMyMachGroupFromId(nId, Map.refMachinePanelVM.MachineList.ToList())
If Not IsNothing(MachGroup) Then
m_MachGroupPanelM.AddMachGroup(MachGroup)
Return True
End If
Return False
End Function
' funzione che cancella tutti i pezzi segnati da eliminare
Public Sub DeleteDuplo()
' reset necessario per poter accedere direttamente al grezzo dalle info pezzo e al MachGroup tramite la gerarchia Db geometrico
EgtResetCurrMachGroup()
Dim bDuploToDeleteFound As Boolean = False
Dim nPartId As Integer = EgtGetFirstPart()
While nPartId <> GDB_ID.NULL
Dim bIsToDelete As Boolean = False
If DuploGetToDelete(nPartId, bIsToDelete) AndAlso bIsToDelete Then
' verifico se ci sono copie
Dim nDuploCount As Integer = 0
EgtDuploCount(nPartId, nDuploCount)
Dim DuploList As New List(Of Integer)
If nDuploCount > 0 AndAlso EgtDuploList(nPartId, DuploList) Then
bDuploToDeleteFound = True
' cancello tutti i pezzi copia nelle barre
For Each nDuploId In DuploList
' recupero grezzo cui appartiene
Dim nRawPartId As Integer = MyMachGroupPanelM.DuploGetRawPart(nDuploId)
' recupero gruppo di lavorazione
Dim nMachGroupId As Integer = EgtGetParent(EgtGetParent(nRawPartId))
' lo setto come corrente
EgtSetCurrMachGroup(nMachGroupId)
' elimino pezzo copia
EgtRemovePartFromRawPart(nDuploId)
EgtErase(nDuploId)
' recupero gruppo di lavorazione e trave dell'interfaccia
Dim BeamMachGroup As MyMachGroupVM = MachGroupVMList.FirstOrDefault(Function(x) x.Id = nMachGroupId)
If Not IsNothing(BeamMachGroup) Then
Dim Beam As PartVM = BeamMachGroup.PartVMList.FirstOrDefault(Function(x) x.nPartId = nDuploId)
EgtSetCurrMachGroup(BeamMachGroup.Id)
Beam.DeletePart()
End If
' reset necessario per poter ottenere nMachGroupId corretto
EgtResetCurrMachGroup()
' aggiorno dati utilizzo barra
BeamMachGroup.UpdateUsage()
Next
' aggiorno quantita' in prod
Dim BTLPart As BTLPartVM = CALCPanelVM.GetBTLPartVMFromBTLPartId(nPartId)
BTLPart.RefreshPartInProd()
End If
DuploResetToDelete(nPartId)
End If
nPartId = EgtGetNextPart(nPartId)
End While
' se cancellato almeno un pezzo
If bDuploToDeleteFound Then
If Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE Then
Map.refOnlyProdManagerVM.Save()
Else
Map.refProdManagerVM.Save()
End If
End If
EgtResetCurrMachGroup()
End Sub
Friend Shared Function DuploGetToDelete(nSouId As Integer, ByRef bToDelete As Boolean) As Boolean
If IsNothing(nSouId) Then Return False
Return EgtGetInfo(nSouId, DUPLO_TODELETE, bToDelete)
End Function
Public Shared Function DuploSetToDelete(nSouId As Integer) As Boolean
If IsNothing(nSouId) Then Return False
Return EgtSetInfo(nSouId, DUPLO_TODELETE, True)
End Function
Private Shared Function DuploResetToDelete(nSouId As Integer) As Boolean
If IsNothing(nSouId) Then Return False
Return EgtSetInfo(nSouId, DUPLO_TODELETE, "")
End Function
Public Overrides Sub AddMachGroup()
Dim MyMachGroupM As MyMachGroupM = m_MyMachGroupPanelM.NewMyMachGroup(CurrentMachine.sMachineName, Map.refProjectVM.BTLStructureVM.nPROJTYPE)
' e lo seleziono
SelectedMachGroup = MachGroupVMList.FirstOrDefault(Function(x) x.MachGroupM Is MyMachGroupM)
End Sub
' funzione che seleziona primo gruppo
Friend Sub SelFirstMachGroup()
If Not IsNothing(Me) AndAlso Not IsNothing(MachGroupVMList) AndAlso MachGroupVMList.Count > 0 Then
SelectedMachGroup = MachGroupVMList(0)
Else
SelectedMachGroup = Nothing
EgtResetCurrMachGroup()
' nascondo tutti i pezzi
Map.refProjectVM.BTLStructureVM.HideAll()
' mostro tutti i pezzi
Map.refShowBeamPanelVM.ShowAll(True)
End If
End Sub
Public Overrides Function OnPostSetCurrMachGroup() As Boolean
' resetto eventuale selezione pezzo
Dim SelMachGroup As MyMachGroupVM = DirectCast(SelectedMachGroup, MyMachGroupVM)
SelMachGroup.SetSelPart(Nothing)
' Imposto vista solo tavola
EgtSetMachineLook(MCH_LOOK.TAB)
Core.ViewPanelVM.BWSetView(If(Core.ViewPanelVM.Type = BWType.BEAM, VT.ISO_SW, VT.TOP), False)
EgtZoom(ZM.ALL)
Return True
End Function
#End Region ' METHODS
End Class