16a5857627
- adeguamento expander Operazioni (aggiunta GpBx Avanzati) in caso di Lavorazioni Marmo (riflette la creazione di pagine "Stone5" apposta per Db Lav di EgtCAM5 in EgtWPFLib5)
449 lines
16 KiB
VB.net
449 lines
16 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class MyMachinePanelVM
|
|
Inherits MachinePanelVM
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
' Definizione comandi
|
|
Private m_cmdToolDb As ICommand
|
|
Private m_cmdMachDb As ICommand
|
|
Private m_cmdSetUpDb As ICommand
|
|
Private m_cmdMachOptions As ICommand
|
|
|
|
Private m_ToolDb_IsEnabled As Boolean = True
|
|
Public ReadOnly Property ToolDb_IsEnabled As Boolean
|
|
Get
|
|
Return m_ToolDb_IsEnabled
|
|
End Get
|
|
End Property
|
|
|
|
Private m_MachDb_IsEnabled As Boolean = True
|
|
Public ReadOnly Property MachDb_IsEnabled As Boolean
|
|
Get
|
|
Return m_MachDb_IsEnabled
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SetUpDb_IsEnabled As Boolean = True
|
|
Public ReadOnly Property SetUpDb_IsEnabled As Boolean
|
|
Get
|
|
Return m_SetUpDb_IsEnabled
|
|
End Get
|
|
End Property
|
|
|
|
' Lista delle macchine disponibili nel programma
|
|
Private m_MachinesList As New ObservableCollection(Of Machine)
|
|
Public Property MachinesList As ObservableCollection(Of Machine)
|
|
Get
|
|
Return m_MachinesList
|
|
End Get
|
|
Set(value As ObservableCollection(Of Machine))
|
|
m_MachinesList = value
|
|
End Set
|
|
End Property
|
|
|
|
' Macchina correntemente selezionata e quindi attiva
|
|
Private m_SelectedMachine As Machine
|
|
Public Overloads Property SelectedMachine As Machine
|
|
Get
|
|
Return m_SelectedMachine
|
|
End Get
|
|
Set(value As Machine)
|
|
If IsNothing(value) Then
|
|
m_SelectedMachine = Nothing
|
|
ElseIf value IsNot m_SelectedMachine Then
|
|
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
|
|
If EgtSetCurrMachine(value.Name) Then
|
|
m_SelectedMachine = value
|
|
IniFile.m_sMachineName = m_SelectedMachine.Name
|
|
IniFile.m_sCurrMachIniFilePath = m_SelectedMachine.MachineDirPath & "\" & m_SelectedMachine.Name & ".ini"
|
|
IniFile.m_sCurrMachToolsDirPath = m_SelectedMachine.MachineDirPath & "\Tools"
|
|
IniFile.m_sCurrMachSetUpDirPath = m_SelectedMachine.MachineDirPath & "\SetUp"
|
|
IniFile.m_sCurrMachScriptsDirPath = m_SelectedMachine.MachineDirPath & "\Scripts"
|
|
UpdateToolAndMachDbParamVisibility()
|
|
NotifyPropertyChanged("SelectedMachine")
|
|
End If
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_MachineListIsEnabled As Boolean
|
|
Public Property MachineListIsEnabled As Boolean
|
|
Get
|
|
Return m_MachineListIsEnabled
|
|
End Get
|
|
Set(value As Boolean)
|
|
m_MachineListIsEnabled = value
|
|
NotifyPropertyChanged("MachineListIsEnabled")
|
|
End Set
|
|
End Property
|
|
|
|
#Region "Messages"
|
|
|
|
Public ReadOnly Property ToolDBMsg As String
|
|
Get
|
|
Return EgtMsg(MSG_MAINWINDOW + 6)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property MachiningDbMsg As String
|
|
Get
|
|
Return EgtMsg(MSG_MAINWINDOW + 7)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property SetUpDbMsg As String
|
|
Get
|
|
Return EgtMsg(MSG_MAINWINDOW + 9)
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' Messages
|
|
|
|
#Region "ToolTip"
|
|
|
|
Public ReadOnly Property ToolDBToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_MAINWINDOW + 3)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property MachiningDbToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_MAINWINDOW + 4)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property SetUpDbToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_MAINWINDOW + 10)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property MachOptionsToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_MAINWINDOW + 8)
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' ToolTip
|
|
|
|
#End Region 'FIELDS & PROPERTIES
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' Creo riferimento a questa classe in Map
|
|
Map.SetRefMachinePanelVM(Me)
|
|
|
|
SearchMachines()
|
|
End Sub
|
|
|
|
#End Region ' Constructor
|
|
|
|
#Region "METHODS"
|
|
|
|
Friend Sub LoadCurrentMachine()
|
|
If m_MachinesList.Count = 0 Then Return
|
|
Dim CurrMach As String = String.Empty
|
|
GetPrivateProfileString(S_MACH, K_CURRMACH, String.Empty, CurrMach)
|
|
Dim bFound As Boolean = False
|
|
If Not String.IsNullOrEmpty(CurrMach) Then
|
|
For Each Mach In MachinesList
|
|
If Mach.Name = CurrMach Then
|
|
bFound = True
|
|
SelectedMachine = Mach
|
|
Exit For
|
|
End If
|
|
Next
|
|
End If
|
|
If Not bFound And MachinesList.Count > 0 Then
|
|
SelectedMachine = MachinesList(0)
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub SaveCurrentMachine()
|
|
If IsNothing(m_SelectedMachine) Then Return
|
|
WritePrivateProfileString(S_MACH, K_CURRMACH, SelectedMachine.Name)
|
|
End Sub
|
|
|
|
Friend Sub UpdateCurrentMachine()
|
|
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
|
|
Dim sMachName As String = String.Empty
|
|
If EgtGetCurrMachineName(sMachName) Then
|
|
For Each Mach In MachinesList
|
|
If Mach.Name = sMachName Then
|
|
SelectedMachine = Mach
|
|
Exit For
|
|
End If
|
|
Next
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub ToolMachSetUpIsEnabled(ToolDb_IsEnabled As Boolean, MachDb_IsEnabled As Boolean, SetUpDb_IsEnabled As Boolean)
|
|
m_ToolDb_IsEnabled = ToolDb_IsEnabled
|
|
m_MachDb_IsEnabled = MachDb_IsEnabled
|
|
m_SetUpDb_IsEnabled = SetUpDb_IsEnabled
|
|
NotifyPropertyChanged("ToolDb_IsEnabled")
|
|
NotifyPropertyChanged("MachDb_IsEnabled")
|
|
NotifyPropertyChanged("SetUpDb_IsEnabled")
|
|
End Sub
|
|
#End Region ' Methods
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "ToolDbCommand"
|
|
|
|
Public Overloads Shared Sub ToolDb()
|
|
If Not EgtVerifyMachinesDir() 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_TOOLSERRORS + 30), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return
|
|
End If
|
|
|
|
Dim sMachineDir As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName
|
|
Dim ToolDbWindowVM As New MyToolDbWindowVM(sMachineDir, IniFile.m_sCurrMachIniFilePath, IniFile.m_ProjectSceneContext, "Wood")
|
|
Dim ToolDbWindowV As New EgtWPFLib5.ToolDbWindowV(Application.Current.MainWindow, ToolDbWindowVM)
|
|
If ToolDbWindowVM.MatType <> 0 Then
|
|
ToolDbWindowV.Height = 674
|
|
ToolDbWindowV.Width = 1024
|
|
ToolDbWindowV.Owner = Application.Current.MainWindow
|
|
ToolDbWindowV.ShowDialog()
|
|
End If
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Execute the Exec. This method is invoked by the ExecCommand.
|
|
''' </summary>
|
|
Public Overrides Sub ToolDb(ByVal param As Object)
|
|
If Not EgtVerifyMachinesDir() 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_TOOLSERRORS + 30), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return
|
|
End If
|
|
'Dim ToolDbWindow As New ToolsDbV
|
|
'ToolDbWindow.Height = 640
|
|
'ToolDbWindow.Width = 1024
|
|
'ToolDbWindow.DataContext = New ToolsDbVM
|
|
'ToolDbWindow.Owner = Application.Current.MainWindow
|
|
'ToolDbWindow.ShowDialog()
|
|
|
|
Dim sMachineDir As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName
|
|
Dim ToolDbWindowVM As New MyToolDbWindowVM(sMachineDir, IniFile.m_sCurrMachIniFilePath, IniFile.m_ProjectSceneContext, "Wood")
|
|
Dim ToolDbWindowV As New EgtWPFLib5.ToolDbWindowV(Application.Current.MainWindow, ToolDbWindowVM)
|
|
If ToolDbWindowVM.MatType <> 0 Then
|
|
ToolDbWindowV.Height = 674
|
|
ToolDbWindowV.Width = 1024
|
|
ToolDbWindowV.Owner = Application.Current.MainWindow
|
|
ToolDbWindowV.ShowDialog()
|
|
End If
|
|
|
|
End Sub
|
|
|
|
#End Region ' ToolDbCommand
|
|
|
|
#Region "MachDbCommand"
|
|
|
|
Public Overloads Shared Sub MachDb()
|
|
If Not EgtVerifyMachinesDir() 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_MACHININGSERRORS + 7), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return
|
|
End If
|
|
Dim MachDbWindowVM As New EgtWPFLib5.MachiningDbWindowVM(IniFile.m_sCurrMachIniFilePath, IniFile.m_ProjectSceneContext, "Wood", True)
|
|
Dim MachDbWindowV As New EgtWPFLib5.MachiningDbWindowV(Application.Current.MainWindow, MachDbWindowVM)
|
|
If EgtWPFLib5.MachiningTreeViewItem.m_MatType <> 0 Then
|
|
MachDbWindowV.Height = 784 '674
|
|
MachDbWindowV.Width = 1024
|
|
MachDbWindowV.Owner = Application.Current.MainWindow
|
|
MachDbWindowV.ShowDialog()
|
|
End If
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Execute the Exec. This method is invoked by the ExecCommand.
|
|
''' </summary>
|
|
Public Overrides Sub MachDb(ByVal param As Object)
|
|
If Not EgtVerifyMachinesDir() 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_MACHININGSERRORS + 7), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return
|
|
End If
|
|
Dim MachDbWindowVM As New EgtWPFLib5.MachiningDbWindowVM(IniFile.m_sCurrMachIniFilePath, IniFile.m_ProjectSceneContext, "Wood", True)
|
|
Dim MachDbWindowV As New EgtWPFLib5.MachiningDbWindowV(Application.Current.MainWindow, MachDbWindowVM)
|
|
If EgtWPFLib5.MachiningTreeViewItem.m_MatType <> 0 Then
|
|
MachDbWindowV.Height = 784 '674
|
|
MachDbWindowV.Width = 1024
|
|
MachDbWindowV.Owner = Application.Current.MainWindow
|
|
MachDbWindowV.ShowDialog()
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' MachDbCommand
|
|
|
|
#Region "SetUpCommand"
|
|
|
|
''' <summary>
|
|
''' Execute the Exec. This method is invoked by the ExecCommand.
|
|
''' </summary>
|
|
Public Overrides Sub SetUp(ByVal param As Object)
|
|
' verifico che il file di configurazione attrezzaggio (lua) della macchina esista
|
|
If Not File.Exists(IniFile.m_sCurrMachScriptsDirPath & "\" & 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(IniFile.m_sCurrMachScriptsDirPath & "\" & 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
|
|
' Verifico esistenza direttorio per attrezzaggi
|
|
Dim sDir As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\SetUp"
|
|
If Not Directory.Exists(sDir) Then
|
|
Try
|
|
Directory.CreateDirectory(sDir)
|
|
Catch ex As Exception
|
|
EgtOutLog("Error in SetupDir creation " & ex.ToString())
|
|
Return
|
|
End Try
|
|
End If
|
|
' creo ed apro finestra SetUp
|
|
Dim SetUpDbWindow As New SetUpDbV(Application.Current.MainWindow, New SetUpDbVM)
|
|
SetUpDbWindow.ShowDialog()
|
|
Map.refProjectVM.EmitTitle()
|
|
End Sub
|
|
|
|
#End Region ' SetUpCommand
|
|
|
|
#Region "MachOptionsCommand"
|
|
|
|
''' <summary>
|
|
''' Execute the Exec. This method is invoked by the ExecCommand.
|
|
''' </summary>
|
|
Public Overrides Sub MachOptions(ByVal param As Object)
|
|
Dim MachOptionWindow As New MachOptionV
|
|
'MachOptionWindow.Height = 614
|
|
'MachOptionWindow.Width = 256
|
|
MachOptionWindow.DataContext = New MachOptionVM
|
|
MachOptionWindow.Owner = Application.Current.MainWindow
|
|
MachOptionWindow.ShowDialog()
|
|
End Sub
|
|
|
|
#End Region ' MachOptionsCommand
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
''' <summary>
|
|
''' Method that search the machines in the correct folder and add to the MachinesList those valid.
|
|
''' </summary>
|
|
Private Sub SearchMachines()
|
|
' Svuoto la lista delle macchine
|
|
m_MachinesList.Clear()
|
|
' Se direttorio base macchine non definito o non esiste, ritorno
|
|
If String.IsNullOrWhiteSpace(IniFile.m_sMachinesRoot) OrElse
|
|
Not Directory.Exists(IniFile.m_sMachinesRoot) OrElse Directory.GetDirectories(IniFile.m_sMachinesRoot).Count = 0 Then
|
|
IniFile.m_ProjectMode = ProjectModeOpt.ONLYDRAW
|
|
EgtOutLog(EgtMsg(MSG_STATUSBAR + 1))
|
|
Return
|
|
End If
|
|
' Cerco le macchine
|
|
Dim TempArray As String() = Directory.GetDirectories(IniFile.m_sMachinesRoot)
|
|
For i As Integer = 0 To TempArray.Count - 1
|
|
AddMachine(TempArray(i))
|
|
Next
|
|
If m_MachinesList.Count = 0 Then
|
|
IniFile.m_ProjectMode = ProjectModeOpt.ONLYDRAW
|
|
EgtOutLog(EgtMsg(MSG_STATUSBAR + 1))
|
|
Return
|
|
End If
|
|
End Sub
|
|
|
|
Private Function AddMachine(sPath As String) As Boolean
|
|
' Verifico presenza file caratteristici
|
|
Dim sName As String = Path.GetFileName(sPath)
|
|
Dim MachineIniPath As String = sPath & "\" & sName & ".ini"
|
|
Dim MachineMldePath As String = sPath & "\" & sName & ".mlde"
|
|
If Not File.Exists(MachineIniPath) Or Not File.Exists(MachineMldePath) Then Return False
|
|
' Aggiungo alla lista
|
|
m_MachinesList.Add(New Machine With {.Name = sName, .MachineDirPath = sPath})
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function InsertMachine(sPath As String) As Boolean
|
|
' Verifico presenza file caratteristici
|
|
Dim sName As String = Path.GetFileName(sPath)
|
|
Dim MachineIniPath As String = sPath & "\" & sName & ".ini"
|
|
Dim MachineMldePath As String = sPath & "\" & sName & ".mlde"
|
|
If Not File.Exists(MachineIniPath) Or Not File.Exists(MachineMldePath) Then Return False
|
|
' Cerco la posizione di inserimento
|
|
Dim nPos As Integer = 0
|
|
For nI As Integer = 0 To m_MachinesList.Count() - 1
|
|
Dim nRes As Integer = String.Compare(sName, m_MachinesList(nI).Name, True)
|
|
If nRes = 0 Then
|
|
Return True
|
|
ElseIf nRes < 0 Then
|
|
Exit For
|
|
Else
|
|
nPos += 1
|
|
End If
|
|
Next
|
|
' Inserisco nella lista
|
|
m_MachinesList.Insert(nPos, New Machine With {.Name = sName, .MachineDirPath = sPath})
|
|
Return True
|
|
End Function
|
|
|
|
''' <summary>
|
|
''' Class that create the association Name/IniPath for the machine's
|
|
''' </summary>
|
|
Class Machine
|
|
|
|
Private m_sName As String
|
|
Public Property Name As String
|
|
Get
|
|
Return m_sName
|
|
End Get
|
|
Set(value As String)
|
|
m_sName = value
|
|
End Set
|
|
End Property
|
|
|
|
Friend MachineDirPath As String
|
|
|
|
End Class
|
|
|
|
Private Sub UpdateToolAndMachDbParamVisibility()
|
|
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWINGONARCS, 0, IniFile.m_sCurrMachIniFilePath) <> 0 Then
|
|
Sawing(39) = Visibility.Visible ' StepExtArc
|
|
Sawing(40) = Visibility.Visible ' StepIntArc
|
|
Else
|
|
Sawing(39) = Visibility.Collapsed ' StepExtArc
|
|
Sawing(40) = Visibility.Collapsed ' StepIntArc
|
|
End If
|
|
End Sub
|
|
|
|
End Class |