Files
omagoffice/MachinePanel/MachinePanelVM.vb
T
Emmanuele Sassi 4c679fbd48 OmagOFFICE :
- Migliorato AboutBox.
- Miglioramenti per compatibilità con nuova versione WPFLib5.
2017-11-25 16:55:39 +00:00

355 lines
12 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class MachinePanelVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
' Radice del direttorio delle macchine
Private m_sMachinesRoot As String
Friend ReadOnly Property sMachinesRoot As String
Get
Return m_sMachinesRoot
End Get
End Property
' Lista delle macchine disponibili
Private m_MachineList As New ObservableCollection(Of Machine)
Public Property MachineList As ObservableCollection(Of Machine)
Get
Return m_MachineList
End Get
Set(value As ObservableCollection(Of Machine))
m_MachineList = value
End Set
End Property
' Macchina correntemente selezionata e quindi attiva
Private m_SelectedMachine As Machine
Public Property SelectedMachine As Machine
Get
Return m_SelectedMachine
End Get
Set(value As Machine)
If value IsNot m_SelectedMachine Then
'EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
If EgtSetCurrMachine(value.Name) Then
m_SelectedMachine = value
NotifyPropertyChanged("SelectedMachine")
End If
End If
End Set
End Property
Private m_SetUp_Background As Brush = New BrushConverter().ConvertFrom("#FFDDDDDD")
Public Property SetUp_Background As Brush
Get
Return m_SetUp_Background
End Get
Set(value As Brush)
m_SetUp_Background = value
NotifyPropertyChanged("SetUp_Background")
End Set
End Property
#Region "Messages"
Public ReadOnly Property ToolDBMsg As String
Get
Return EgtMsg(MSG_MACHINEPAGEUC + 6)
End Get
End Property
Public ReadOnly Property MachiningDbMsg As String
Get
Return EgtMsg(MSG_MACHINEPAGEUC + 7)
End Get
End Property
Public ReadOnly Property SetUpMsg As String
Get
Return EgtMsg(MSG_ALARMSPAGEUC + 33)
End Get
End Property
#End Region ' Messages
#Region "ToolTip"
Public ReadOnly Property ToolDBToolTip As String
Get
Return "Tool DB"
End Get
End Property
Public ReadOnly Property MachiningDbToolTip As String
Get
Return "Machining DB"
End Get
End Property
Public ReadOnly Property SetUpToolTip As String
Get
Return "SetUp"
End Get
End Property
#End Region ' ToolTip
' Definizione comandi
Private m_cmdToolDb As ICommand
Private m_cmdMachDb As ICommand
Private m_cmdSetUp As ICommand
Private m_cmdMachOptions As ICommand
#End Region 'FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Creo riferimento a questa classe in OmagOFFICEMap
OmagOFFICEMap.SetRefMachinePanelVM(Me)
' recupero cartella radice delle macchine
m_sMachinesRoot = OmagOFFICEMap.refMainWindowVM.MainWindowM.sMachinesRoot
' Carica macchine da cartella delle macchine
Machine.MachineListInit(sMachinesRoot, MachineList)
' Inizializzo valori visibilità parametri Db utensili e lavorazioni
OmagOFFICETMDbParamVisibility.Init()
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
#End Region
#Region "COMMANDS"
#Region "ToolDbCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property ToolDbCommand As ICommand
Get
If m_cmdToolDb Is Nothing Then
m_cmdToolDb = New Command(AddressOf ToolDb)
End If
Return m_cmdToolDb
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub ToolDb(ByVal param As Object)
If Not VerifyMachinesDir(m_sMachinesRoot) Then Return
' ricarico il database per intercettare eventuali aggiornamenti fatti da altre istanze del programma (se la cartella Machines è condivisa)
If Not EgtTdbReload() Then
EgtOutLog("Impossible reloading tool Db")
MessageBox.Show(EgtMsg(MSG_TOOLDBERRORS + 30), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
Dim ToolDbWindow As New ToolDbWindowV(Application.Current.MainWindow, New ToolDbWindowVM(CurrentMachine.sMachDir, CurrentMachine.sMachIniFile, OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx()))
ToolDbWindow.Height = 640
ToolDbWindow.Width = 1024
ToolDbWindow.ShowDialog()
If Not SetUpUtility.IsValidToolHeadExitInSetUp() Then
SetUp_Background = Brushes.Red
Else
SetUp_Background = OmagOFFICEDictionary.Button_Static_Background
End If
End Sub
#End Region ' ToolDbCommand
#Region "MachDbCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property MachDbCommand As ICommand
Get
If m_cmdMachDb Is Nothing Then
m_cmdMachDb = New Command(AddressOf MachDb)
End If
Return m_cmdMachDb
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub MachDb(ByVal param As Object)
If Not VerifyMachinesDir(m_sMachinesRoot) Then Return
' ricarico il database per intercettare eventuali aggiornamenti fatti da altre istanze del programma (se la cartella Machines è condivisa)
If Not EgtMdbReload() Then
EgtOutLog("Impossible reloading machining Db")
MessageBox.Show(EgtMsg(MSG_MACHININGDBERRORS + 8), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
Dim MachDbWindow As New MyMachiningDbWindowV(Application.Current.MainWindow, New MyMachiningDbWindowVM(CurrentMachine.sMachIniFile, OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx()))
MachDbWindow.Height = 614
MachDbWindow.Width = 1024
MachDbWindow.ShowDialog()
' Verifico che gli utensili delle lavorazioni correnti siano attrezzati (necessario perchè potrei aver cambiato gli utensili delle lavorazioni)
' e che le lavorazioni correnti siano compatibili con materiale e spessore
' Lama
Dim bOkSetUp As Boolean = True
Dim bOkMatThick As Boolean = True
Dim sTUUID As String = String.Empty
If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrSawing) Then
EgtMdbSetCurrMachining(CurrentMachine.sCurrSawing)
EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID)
bOkSetUp = bOkSetUp And SetUpUtility.IsToolInSetUp(sTUUID)
bOkMatThick = bOkMatThick And CurrMachWindowVM.VerifyMatThickCompatibility()
End If
' Fresa
If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrMilling) Then
EgtMdbSetCurrMachining(CurrentMachine.sCurrMilling)
sTUUID = String.Empty
EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID)
bOkSetUp = bOkSetUp And SetUpUtility.IsToolInSetUp(sTUUID)
bOkMatThick = bOkMatThick And CurrMachWindowVM.VerifyMatThickCompatibility()
End If
' Foretto
If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrDrilling) Then
EgtMdbSetCurrMachining(CurrentMachine.sCurrDrilling)
sTUUID = String.Empty
EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID)
bOkSetUp = bOkSetUp And SetUpUtility.IsToolInSetUp(sTUUID)
bOkMatThick = bOkMatThick And CurrMachWindowVM.VerifyMatThickCompatibility()
End If
If Not bOkSetUp Then
SetUp_Background = Brushes.Red
Else
SetUp_Background = New BrushConverter().ConvertFrom("#FFDDDDDD")
End If
If Not bOkMatThick Then
OmagOFFICEMap.refOptionPanelVM.RawPart_Background = Brushes.Red
OmagOFFICEMap.refRawPartTabVM.CurrMach_Background = Brushes.Red
Else
OmagOFFICEMap.refOptionPanelVM.RawPart_Background = OmagOFFICEDictionary.TabControl_Header_Background
OmagOFFICEMap.refRawPartTabVM.CurrMach_Background = New BrushConverter().ConvertFrom("#FFDDDDDD")
End If
End Sub
#End Region ' MachDbCommand
#Region "SetUpCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property SetUpCommand As ICommand
Get
If m_cmdSetUp Is Nothing Then
m_cmdSetUp = New Command(AddressOf SetUp)
End If
Return m_cmdSetUp
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub SetUp(ByVal param As Object)
' verifico che il file di configurazione attrezzaggio (lua) della macchina esista
If Not File.Exists(CurrentMachine.sMachDir & "\Scripts\" & SETUP_LUA) Then
EgtOutLog("SetUp error: SetUp configuration file doesn't exist ")
MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 7), EgtMsg(MSG_SETUPERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
' carico Lua che contiene le funzioni per ottenere le posizioni valide dell'utensile selezionato,
' e testa e uscita dell'utensile attrezzato
EgtLuaExecFile(CurrentMachine.sMachDir & "\Scripts\" & SETUP_LUA)
' verifico che le teste riportate in configurazione esistano
Dim Index As Integer = 1
Dim nErr As Integer = 0
While nErr = 0
Dim sHead As String = String.Empty
nErr = 999
EgtLuaSetGlobIntVar("STU.INDEX", Index)
EgtLuaCallFunction("STU.GetTcPosHeadGroupFromPos")
' Leggo variabili
EgtLuaGetGlobStringVar("STU.HEAD", sHead)
EgtLuaGetGlobIntVar("STU.ERR", nErr)
If nErr = 0 Then
If EgtGetHeadExitCount(sHead) = 0 Then
MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 8), EgtMsg(MSG_SETUPERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
End If
Index += 1
End While
' Reset lua
EgtLuaResetGlobVar("STU")
Dim SetUpWindow As New SetUpWindowV(Application.Current.MainWindow, New MySetUpWindowVM(CurrentMachine.sMachDir, CurrentMachine.sMachineName))
SetUpWindow.Height = 614
SetUpWindow.Width = 1024
SetUpWindow.ShowDialog()
' Verifico che gli utensili delle lavorazioni correnti siano attrezzati (necessario perchè potrei aver cambiato gli utensili delle lavorazioni)
' Lama
Dim bOk As Boolean = True
Dim sTUUID As String = String.Empty
If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrSawing) Then
EgtMdbSetCurrMachining(CurrentMachine.sCurrSawing)
EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID)
bOk = bOk And SetUpUtility.IsToolInSetUp(sTUUID)
End If
' Fresa
If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrMilling) Then
EgtMdbSetCurrMachining(CurrentMachine.sCurrMilling)
sTUUID = String.Empty
EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID)
bOk = bOk And SetUpUtility.IsToolInSetUp(sTUUID)
End If
' Foretto
If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrDrilling) Then
EgtMdbSetCurrMachining(CurrentMachine.sCurrDrilling)
sTUUID = String.Empty
EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID)
bOk = bOk And SetUpUtility.IsToolInSetUp(sTUUID)
End If
If Not bOk Then
SetUp_Background = Brushes.Red
Else
SetUp_Background = New BrushConverter().ConvertFrom("#FFDDDDDD")
End If
End Sub
#End Region ' SetUpCommand
#Region "MachOptionsCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property MachOptionsCommand As ICommand
Get
If m_cmdMachOptions Is Nothing Then
m_cmdMachOptions = New Command(AddressOf MachOptions)
End If
Return m_cmdMachOptions
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub MachOptions(ByVal param As Object)
Dim MachOptionWindow As New MachOptionWindowV(Application.Current.MainWindow, New MachOptionWindowVM)
MachOptionWindow.Height = 546
MachOptionWindow.Width = 546
MachOptionWindow.ShowDialog()
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx())
End Sub
#End Region ' MachOptionsCommand
#End Region ' COMMANDS
End Class