ec4eb8adb5
Spostamento VM Machgroup
216 lines
8.7 KiB
VB.net
216 lines
8.7 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class MyMachGroupPanelVM
|
|
Inherits MachGroupPanelVM
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
#End Region ' FIELDS & PROPERTIES
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
MyBase.New()
|
|
' Recupero la macchina di default
|
|
Dim sDefaultMachine As String = String.Empty
|
|
GetMainPrivateProfileString(S_MACH, K_CURRMACH, "", sDefaultMachine)
|
|
' Creo riferimento a questa classe in Map
|
|
Map.SetRefMachGroupPanelVM(Me)
|
|
InitMachGroupPanel(True, Map.refMachinePanelVM.MachineList.ToList(), sDefaultMachine)
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
Public Overrides Function InitMachGroupList(Optional bUseDefaults As Boolean = False) As Boolean
|
|
' Svuoto precedente lista di MachGroup
|
|
MachGroupList.Clear()
|
|
' aggiorno copie
|
|
UpdateDuplo()
|
|
' verifico se esistono già gruppi di lavorazione o se devo creare il primo
|
|
Dim bOk As Boolean = False
|
|
Dim nId = EgtGetFirstMachGroup()
|
|
If nId <> GDB_ID.NULL Then
|
|
bOk = EgtSetCurrMachGroup(nId)
|
|
End If
|
|
If Not bOk Then Return True
|
|
' carico lista dei gruppi di lavorazione
|
|
LoadMachGroupList()
|
|
' elimino copie da cancellare
|
|
DeleteDuplo()
|
|
If bOk Then SelectedMachGroup = MachGroupList(0)
|
|
EgtZoom(ZM.ALL)
|
|
Return True
|
|
End Function
|
|
|
|
Public Overrides Sub AddMachGroup()
|
|
Dim nNewMachGroupID As Integer = EgtAddMachGroup(NewMachGroupID().ToString, Map.refMachinePanelVM.SelectedMachine.Name)
|
|
If nNewMachGroupID <> GDB_ID.NULL Then
|
|
' creo oggetto gruppo creato
|
|
Dim sNewMachGroupName As String = String.Empty
|
|
Dim sNewMachGroupMachineName As String = String.Empty
|
|
EgtGetMachGroupName(nNewMachGroupID, sNewMachGroupName)
|
|
EgtGetMachGroupMachineName(nNewMachGroupID, sNewMachGroupMachineName)
|
|
Dim MyMachGroup As Core.MyMachGroupM
|
|
If Map.refMachinePanelVM.SelectedMachine.nType = MachineType.BEAM Then
|
|
MyMachGroup = New BeamMachGroup(nNewMachGroupID, sNewMachGroupName, sNewMachGroupMachineName)
|
|
Else
|
|
MyMachGroup = New WallMachGroup(nNewMachGroupID, sNewMachGroupName, sNewMachGroupMachineName)
|
|
End If
|
|
' lo aggiungo alla lista
|
|
MachGroupList.Add(MyMachGroup)
|
|
' e lo seleziono
|
|
SelectedMachGroup = MyMachGroup
|
|
End If
|
|
End Sub
|
|
|
|
Public Overrides Sub LoadMachGroupList()
|
|
' Carico i gruppi di lavorazione nella lista
|
|
Dim nId = EgtGetFirstMachGroup()
|
|
While nId <> GDB_ID.NULL
|
|
EgtSetCurrMachGroup(nId)
|
|
Dim sName As String = String.Empty
|
|
Dim sMachine As String = String.Empty
|
|
EgtGetMachGroupName(nId, sName)
|
|
EgtGetMachGroupMachineName(nId, sMachine)
|
|
' cerco la macchina tra quelle presenti
|
|
Dim MachGroupMachine As MyMachine = Nothing
|
|
Machine.SearchMachine(sMachine, Map.refMachinePanelVM.MachineList, MachGroupMachine)
|
|
If IsNothing(MachGroupMachine) OrElse MachGroupMachine.nType = MachineType.NULL Then
|
|
EgtOutLog("Machine incompatible with beam & wall machining!!")
|
|
Return
|
|
ElseIf MachGroupMachine.nType = MachineType.BEAM Then
|
|
MachGroupList.Add(New BeamMachGroup(nId, sName, sMachine))
|
|
ElseIf MachGroupMachine.nType = MachineType.WALL Then
|
|
MachGroupList.Add(New WallMachGroup(nId, sName, sMachine))
|
|
End If
|
|
nId = EgtGetNextMachGroup(nId)
|
|
End While
|
|
EgtResetCurrMachGroup()
|
|
End Sub
|
|
|
|
Public Overrides Function OnPreNewMachGroup() As Boolean
|
|
EgtSetCurrentContext(Map.refSceneHostVM.MainScene.GetCtx())
|
|
Return True
|
|
End Function
|
|
|
|
' NB: Anche se ho già aggiunto il nuovo gruppo di lavorazione, non l'ho ancora reso corrente (viene fatto dopo), quindi
|
|
' non posso usare CurrentMachine perchè è ancora impostata quella precedente!!!
|
|
Public Overrides Function OnPostNewMachGroup() As Boolean
|
|
' Salvo macchina del gruppo come nuovo default
|
|
Dim sCurrMachName As String = String.Empty
|
|
EgtGetCurrMachineName(sCurrMachName)
|
|
WriteMainPrivateProfileString(S_MACH, K_CURRMACH, sCurrMachName)
|
|
' leggo nome attrezzaggio di default
|
|
Dim sDefaultSetUpName As String = String.Empty
|
|
Dim sMachineIniPath As String = Map.refMainWindowVM.MainWindowM.sMachinesRoot & "\" & sCurrMachName & "\" & sCurrMachName & ".ini"
|
|
EgtUILib.GetPrivateProfileString(S_SETUP, K_DEFAULT, "", sDefaultSetUpName, sMachineIniPath)
|
|
' se è attiva l'opzione, rendo corrente l'attrezzaggio di default
|
|
If Not String.IsNullOrEmpty(sDefaultSetUpName) Then
|
|
If Not EgtImportSetup(sDefaultSetUpName) Then
|
|
EgtOutLog("Error loading default setup " & sDefaultSetUpName)
|
|
MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 9) & " " & sDefaultSetUpName, EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Exclamation)
|
|
End If
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Public Overrides Function OnPreSetCurrMachGroup() As Boolean
|
|
EgtSetCurrentContext(Map.refSceneHostVM.MainScene.GetCtx())
|
|
Return True
|
|
End Function
|
|
|
|
Public Overrides Function OnPostSetCurrMachGroup() As Boolean
|
|
' Imposto vista solo tavola
|
|
EgtSetMachineLook(MCH_LOOK.TAB)
|
|
EgtSetView(VT.ISO_SW, False)
|
|
EgtZoom(ZM.ALL)
|
|
Return True
|
|
End Function
|
|
|
|
Public Overrides Function OnPreRemoveCurrMachGroup() As Boolean
|
|
EgtSetCurrentContext(Map.refSceneHostVM.MainScene.GetCtx())
|
|
Return True
|
|
End Function
|
|
|
|
Private Function NewMachGroupID() As Integer
|
|
If Not IsNothing(MachGroupList) AndAlso MachGroupList.Count > 0 Then Return MachGroupList.Max(Function(x) x.Name) + 1
|
|
Return 1
|
|
End Function
|
|
|
|
' funzione che fa l'update di tutte le copie dei pezzi modificati
|
|
Friend Sub UpdateDuplo()
|
|
Dim nPartId As Integer = EgtGetFirstPart()
|
|
While nPartId <> GDB_ID.NULL
|
|
Dim bIsModified As Boolean = False
|
|
If EgtDuploGetModified(nPartId, bIsModified) AndAlso bIsModified Then
|
|
EgtDuploUpdate(nPartId)
|
|
End If
|
|
nPartId = EgtGetNextPart(nPartId)
|
|
End While
|
|
End Sub
|
|
|
|
' funzione che cancella tutti i pezzi segnati da eliminare
|
|
Friend Sub DeleteDuplo()
|
|
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
|
|
' cancello tutti i pezzi copia nelle barre
|
|
For Each nDuploId In DuploList
|
|
' reset necessario per poter accedere direttamente al grezzo dalle info pezzo e al MachGroup tramite la gerarchia Db geometrico
|
|
EgtResetCurrMachGroup()
|
|
' recupero grezzo cui appartiene
|
|
Dim nRawPartId As Integer
|
|
EgtGetInfo(nDuploId, "!LST", nRawPartId)
|
|
' recupero gruppo di lavorazione
|
|
Dim nMachGroupId As Integer = EgtGetParent(EgtGetParent(EgtGetParent(nRawPartId)))
|
|
' recupero gruppo di lavorazione e trave dell'interfaccia
|
|
Dim BeamMachGroup As BeamMachGroup = Map.refProjectVM.MachGroupPanelVM.MachGroupList.FirstOrDefault(Function(x) x.Id = nMachGroupId)
|
|
Dim Beam As Beam = BeamMachGroup.PartList.FirstOrDefault(Function(x) x.nPartId = nDuploId)
|
|
EgtSetCurrMachGroup(BeamMachGroup.Id)
|
|
Beam.DeletePart()
|
|
Next
|
|
End If
|
|
DuploResetToDelete(nPartId)
|
|
End If
|
|
nPartId = EgtGetNextPart(nPartId)
|
|
End While
|
|
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
|
|
|
|
Friend Shared Function DuploSetToDelete(nSouId As Integer) As Boolean
|
|
If IsNothing(nSouId) Then Return False
|
|
Return EgtSetInfo(nSouId, DUPLO_TODELETE, True)
|
|
End Function
|
|
|
|
Private Function DuploResetToDelete(nSouId As Integer) As Boolean
|
|
If IsNothing(nSouId) Then Return False
|
|
Return EgtSetInfo(nSouId, DUPLO_TODELETE, "")
|
|
End Function
|
|
|
|
' funzione che seleziona ultimo gruppo
|
|
Friend Sub SelLastMachGroup()
|
|
If Not IsNothing(Me) AndAlso Not IsNothing(MachGroupList) AndAlso MachGroupList.Count > 0 Then
|
|
SelectedMachGroup = MachGroupList(MachGroupList.Count - 1)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' METHODS
|
|
|
|
End Class
|