c437a3721e
- varie modifiche per conversione tipi e valori di ritorno - corrette alcune assegnazione a info con , come separatore dei decimali.
443 lines
18 KiB
VB.net
443 lines
18 KiB
VB.net
Imports EgtUILib
|
|
|
|
Public Class MachineButtonsUC
|
|
|
|
'Riferimento alla MainWindow
|
|
Dim m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
|
|
Private m_DirectCutPage As DirectCutPageUC
|
|
Friend m_CN As CN_generico
|
|
|
|
Private m_bFirst As Boolean = True
|
|
|
|
Private Const MAX_BUTTONS As Integer = 10
|
|
Private ImageArrayY(MAX_BUTTONS - 1) As String
|
|
Private ImageArrayN(MAX_BUTTONS - 1) As String
|
|
Private CommandArrayY(MAX_BUTTONS - 1) As String
|
|
Private CommandArrayN(MAX_BUTTONS - 1) As String
|
|
Private StateFlagArray(MAX_BUTTONS - 1) As String
|
|
|
|
' Creazione converter da String a ImageSource
|
|
Dim ImageConverter As New ImageSourceConverter
|
|
|
|
' Costanti per nomi stati dei bottoni
|
|
Private Const BTN_STATE_SPINDLE As String = "Spindle"
|
|
Private Const BTN_STATE_COOLANT As String = "Coolant"
|
|
Private Const BTN_STATE_LASER As String = "Laser"
|
|
Private Const BTN_STATE_THREEAXIS As String = "ThreeAxis"
|
|
Private Const BTN_STATE_FIVEAXIS As String = "FiveAxis"
|
|
Private Const BTN_STATE_NOTHING As String = "Nothing"
|
|
|
|
Private Sub MachineButtons_Loaded(sender As Object, e As RoutedEventArgs)
|
|
|
|
If m_bFirst Then
|
|
m_DirectCutPage = m_MainWindow.m_DirectCutPageUC
|
|
m_bFirst = False
|
|
End If
|
|
|
|
Dim sButtonImage As String = String.Empty
|
|
'Dim sButtonImageSource As ImageSource
|
|
Dim sButtonCommand As String = String.Empty
|
|
Dim sButtonStateFlag As String = String.Empty
|
|
Dim nIndex As Integer = 0
|
|
While nIndex < MAX_BUTTONS 'And GetPrivateProfileMachineButtons(S_MACHBUTTONS, K_BUTTON & (nIndex + 1) & "Y", sButtonImage, sButtonCommand, sButtonStateFlag, m_MainWindow.GetMachIniFile())
|
|
If GetPrivateProfileMachineButtons(S_MACHBUTTONS, K_BUTTON & (nIndex + 1) & "Y", sButtonImage, sButtonCommand, sButtonStateFlag, m_MainWindow.GetMachIniFile()) Then
|
|
ImageArrayY(nIndex) = sButtonImage
|
|
CommandArrayY(nIndex) = sButtonCommand
|
|
StateFlagArray(nIndex) = sButtonStateFlag
|
|
End If
|
|
'If CommandArray(nIndex) = "3Axes.lua" Then
|
|
' MachineButtonsGrid.Children.Remove(GetButton(nIndex + 1))
|
|
' ThreeAxisBtn.SetValue(Grid.ColumnProperty, nIndex)
|
|
' ThreeAxisBtn.Visibility = Windows.Visibility.Visible
|
|
' Try
|
|
' Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sButtonImage
|
|
' sButtonImageSource = ImageConverter.ConvertFromString(s)
|
|
' ThreeAxisImg.Source = sButtonImageSource
|
|
' Catch ex As Exception
|
|
' EgtOutLog("Error loading image " & sButtonImage)
|
|
' End Try
|
|
'ElseIf CommandArray(nIndex) = "5Axes.lua" Then
|
|
' MachineButtonsGrid.Children.Remove(GetButton(nIndex + 1))
|
|
' FiveAxisBtn.SetValue(Grid.ColumnProperty, nIndex)
|
|
' FiveAxisBtn.Visibility = Windows.Visibility.Visible
|
|
' Try
|
|
' Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sButtonImage
|
|
' sButtonImageSource = ImageConverter.ConvertFromString(s)
|
|
' FiveAxisImg.Source = sButtonImageSource
|
|
' Catch ex As Exception
|
|
' EgtOutLog("Error loading image " & sButtonImage)
|
|
' End Try
|
|
'Else
|
|
|
|
'End If
|
|
'Try
|
|
' Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sButtonImage
|
|
' sButtonImageSource = ImageConverter.ConvertFromString(s)
|
|
' GetImage(nIndex + 1).Source = sButtonImageSource
|
|
'Catch ex As Exception
|
|
' EgtOutLog("Error loading image " & sButtonImage)
|
|
'End Try
|
|
nIndex += 1
|
|
End While
|
|
nIndex = 0
|
|
While nIndex < MAX_BUTTONS 'And GetPrivateProfileMachineButtons(S_MACHBUTTONS, K_BUTTON & (nIndex + 1) & "N", sButtonImage, sButtonCommand, sButtonStateFlag, m_MainWindow.GetMachIniFile())
|
|
If GetPrivateProfileMachineButtons(S_MACHBUTTONS, K_BUTTON & (nIndex + 1) & "N", sButtonImage, sButtonCommand, sButtonStateFlag, m_MainWindow.GetMachIniFile()) Then
|
|
ImageArrayN(nIndex) = sButtonImage
|
|
CommandArrayN(nIndex) = sButtonCommand
|
|
End If
|
|
nIndex += 1
|
|
End While
|
|
|
|
'Se variabile da leggere nothing imposto immagine fissa
|
|
For nIndex = 0 To StateFlagArray.Count - 1
|
|
If StateFlagArray(nIndex) = BTN_STATE_NOTHING Then
|
|
' mostra immagine fissa
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayN(nIndex + 1))
|
|
End Try
|
|
End If
|
|
Next
|
|
|
|
' Nascondo bottoni inutilizzati
|
|
Dim nYNum As Integer = 0
|
|
For Each Item In CommandArrayY
|
|
If Not String.IsNullOrEmpty(Item) Then
|
|
nYNum += 1
|
|
End If
|
|
Next
|
|
Dim nNNum As Integer = 0
|
|
For Each Item In CommandArrayN
|
|
If Not String.IsNullOrEmpty(Item) Then
|
|
nNNum += 1
|
|
End If
|
|
Next
|
|
Dim nBtnNum As Integer = Math.Max(nYNum, nNNum)
|
|
nIndex = nBtnNum
|
|
While nIndex < MAX_BUTTONS
|
|
GetToggleButton(nIndex + 1).Visibility = Windows.Visibility.Hidden
|
|
nIndex += 1
|
|
End While
|
|
|
|
' Se modalità Debug metto immaginette fisse e tolgo bottoni in eccesso
|
|
If Not m_MainWindow.m_bNCLink Then
|
|
For nIndex = 0 To 2
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayN(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayN(nIndex + 1))
|
|
End Try
|
|
Next
|
|
For nIndex = 3 To 4
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayN(nIndex + 1))
|
|
End Try
|
|
Next
|
|
For I = 7 To 10
|
|
GetToggleButton(I).Visibility = Windows.Visibility.Hidden
|
|
Next
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Sub MachineButton_Click(sender As Object, e As RoutedEventArgs) Handles MachineButton1.Click, MachineButton2.Click, MachineButton3.Click, MachineButton4.Click, MachineButton5.Click, MachineButton6.Click, MachineButton7.Click,
|
|
MachineButton8.Click, MachineButton9.Click, MachineButton10.Click
|
|
Dim CurrentBtn As Primitives.ToggleButton = e.Source
|
|
Dim nTemp As Integer = 0
|
|
Dim dTemp As Double = 0
|
|
Dim sTemp As String = String.Empty
|
|
Dim b2Start As Boolean = False
|
|
Dim CmdString As String = String.Empty
|
|
If CurrentBtn.IsChecked() Then
|
|
EgtLuaExecFile(m_MainWindow.GetMachinesRootDir() & "\" & m_MainWindow.GetCurrMachine() & "\DirectCmd\" & CommandArrayY(GetToggleButtonIndex(CurrentBtn) - 1))
|
|
Else
|
|
If Not (StateFlagArray(GetToggleButtonIndex(CurrentBtn) - 1) = BTN_STATE_THREEAXIS Or StateFlagArray(GetToggleButtonIndex(CurrentBtn) - 1) = BTN_STATE_FIVEAXIS) Then
|
|
EgtLuaExecFile(m_MainWindow.GetMachinesRootDir() & "\" & m_MainWindow.GetCurrMachine() & "\DirectCmd\" & CommandArrayN(GetToggleButtonIndex(CurrentBtn) - 1))
|
|
Else
|
|
Return
|
|
End If
|
|
End If
|
|
StringToLen(m_DirectCutPage.m_ManualAxesMove.FeedTxBx.Text, dTemp)
|
|
EgtLuaSetGlobNumVar("CMD.F", dTemp)
|
|
StringToDouble(m_DirectCutPage.m_ManualAxesMove.SpeedTxBx.Text, dTemp)
|
|
EgtLuaSetGlobNumVar("CMD.S", dTemp)
|
|
Dim dL1, dL2, dL3, dR1, dR2 As Double
|
|
m_MainWindow.m_CNCommunication.GetAxesPositions(dL1, dL2, dL3, dR1, dR2)
|
|
EgtLuaSetGlobNumVar("CMD.L1", dL1)
|
|
EgtLuaSetGlobNumVar("CMD.L2", dL2)
|
|
EgtLuaSetGlobNumVar("CMD.L3", dL3)
|
|
EgtLuaSetGlobNumVar("CMD.R1", dR1)
|
|
EgtLuaSetGlobNumVar("CMD.R2", dR2)
|
|
EgtLuaSetGlobBoolVar("CMD.INCHES", m_MainWindow.m_CNCommunication.GetMachineInInches())
|
|
EgtLuaExecLine("CmdString()")
|
|
' Leggo variabili
|
|
EgtLuaGetGlobStringVar("CMD.CMDSTRING", CmdString)
|
|
EgtLuaGetGlobBoolVar("CMD.DOUBLESTART", b2Start)
|
|
' Reset lua
|
|
EgtLuaResetGlobVar("CmdString")
|
|
EgtLuaResetGlobVar("CMD")
|
|
' Log del comando
|
|
EgtOutLog("CmdString=" & CmdString & " b2Start=" & b2Start.ToString())
|
|
|
|
Dim nResult As Short
|
|
Select Case m_MainWindow.m_CNCommunication.m_nNCType
|
|
Case 1, 2
|
|
nResult = m_CN.DGeneralFunctions_WriteCncMode(2) ' Modalità MDI per controlli num
|
|
Case 3
|
|
'Per il siemens non devo fare nulla
|
|
End Select
|
|
m_CN.sz_ManualDataInput = CmdString
|
|
m_CN.MDI_command()
|
|
Select Case m_MainWindow.m_CNCommunication.m_nNCType
|
|
Case 1, 2
|
|
System.Threading.Thread.Sleep(300)
|
|
m_CN.DGeneralFunctions_CycleStart()
|
|
Case 3
|
|
'Per il siemens non devo fare nulla
|
|
End Select
|
|
|
|
If b2Start Then
|
|
System.Threading.Thread.Sleep(300)
|
|
m_CN.DGeneralFunctions_CycleStart()
|
|
End If
|
|
System.Threading.Thread.Sleep(300)
|
|
nResult = m_CN.DGeneralFunctions_WriteCncMode(7) ' Modalità manuale
|
|
|
|
' se non ha stato e quindi è un bottone normale, tolgo il check
|
|
If StateFlagArray(GetToggleButtonIndex(CurrentBtn) - 1) = BTN_STATE_NOTHING Then
|
|
CurrentBtn.IsChecked = False
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Friend Sub SpindleStateChanged(SpindleState As Boolean)
|
|
Dim nIndex As Integer = Array.IndexOf(StateFlagArray, BTN_STATE_SPINDLE)
|
|
If SpindleState Then
|
|
GetToggleButton(nIndex + 1).IsChecked = True
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayY(nIndex + 1))
|
|
End Try
|
|
Else
|
|
GetToggleButton(nIndex + 1).IsChecked = False
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayN(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayN(nIndex + 1))
|
|
End Try
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub CoolantStateChanged(CoolantState As Boolean)
|
|
Dim nIndex As Integer = Array.IndexOf(StateFlagArray, BTN_STATE_COOLANT)
|
|
If CoolantState Then
|
|
GetToggleButton(nIndex + 1).IsChecked = True
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayY(nIndex + 1))
|
|
End Try
|
|
Else
|
|
GetToggleButton(nIndex + 1).IsChecked = False
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayN(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayN(nIndex + 1))
|
|
End Try
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub LaserStateChanged(LaserState As Boolean)
|
|
Dim nIndex As Integer = Array.IndexOf(StateFlagArray, BTN_STATE_LASER)
|
|
If LaserState Then
|
|
GetToggleButton(nIndex + 1).IsChecked = True
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayY(nIndex + 1))
|
|
End Try
|
|
Else
|
|
GetToggleButton(nIndex + 1).IsChecked = False
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayN(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayN(nIndex + 1))
|
|
End Try
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub ThreeAxisStateChanged(ThreeAxisState As Boolean)
|
|
Dim nIndex As Integer = Array.IndexOf(StateFlagArray, BTN_STATE_THREEAXIS)
|
|
If ThreeAxisState Then
|
|
GetToggleButton(nIndex + 1).IsChecked = True
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayY(nIndex + 1))
|
|
End Try
|
|
Else
|
|
GetToggleButton(nIndex + 1).IsChecked = False
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayN(nIndex + 1))
|
|
End Try
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub FiveAxisStateChanged(FiveAxisState As Boolean)
|
|
Dim nIndex As Integer = Array.IndexOf(StateFlagArray, BTN_STATE_FIVEAXIS)
|
|
If FiveAxisState Then
|
|
GetToggleButton(nIndex + 1).IsChecked = True
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayY(nIndex + 1))
|
|
End Try
|
|
Else
|
|
GetToggleButton(nIndex + 1).IsChecked = False
|
|
Try
|
|
Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
|
|
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
|
|
GetImage(nIndex + 1).Source = sButtonImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & ImageArrayN(nIndex + 1))
|
|
End Try
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Private Function GetToggleButton(ByVal nIndex As Integer) As Primitives.ToggleButton
|
|
Select Case nIndex
|
|
Case 1
|
|
Return MachineButton1
|
|
Case 2
|
|
Return MachineButton2
|
|
Case 3
|
|
Return MachineButton3
|
|
Case 4
|
|
Return MachineButton4
|
|
Case 5
|
|
Return MachineButton5
|
|
Case 6
|
|
Return MachineButton6
|
|
Case 7
|
|
Return MachineButton7
|
|
Case 8
|
|
Return MachineButton8
|
|
Case 9
|
|
Return MachineButton9
|
|
Case Else
|
|
Return MachineButton10
|
|
End Select
|
|
End Function
|
|
|
|
Private Function GetToggleButtonIndex(ByVal nBtnName As Primitives.ToggleButton) As Integer
|
|
Select Case nBtnName.Name
|
|
Case MachineButton1.Name
|
|
Return 1
|
|
Case MachineButton2.Name
|
|
Return 2
|
|
Case MachineButton3.Name
|
|
Return 3
|
|
Case MachineButton4.Name
|
|
Return 4
|
|
Case MachineButton5.Name
|
|
Return 5
|
|
Case MachineButton6.Name
|
|
Return 6
|
|
Case MachineButton7.Name
|
|
Return 7
|
|
Case MachineButton8.Name
|
|
Return 8
|
|
Case MachineButton9.Name
|
|
Return 9
|
|
Case Else
|
|
Return 10
|
|
End Select
|
|
End Function
|
|
|
|
Private Function GetImage(ByVal nInd As Integer) As Image
|
|
Select Case nInd
|
|
Case 1
|
|
Return ImageButton1
|
|
Case 2
|
|
Return ImageButton2
|
|
Case 3
|
|
Return ImageButton3
|
|
Case 4
|
|
Return ImageButton4
|
|
Case 5
|
|
Return ImageButton5
|
|
Case 6
|
|
Return ImageButton6
|
|
Case 7
|
|
Return ImageButton7
|
|
Case 8
|
|
Return ImageButton8
|
|
Case 9
|
|
Return ImageButton9
|
|
Case Else
|
|
Return ImageButton10
|
|
End Select
|
|
End Function
|
|
|
|
Public Function GetPrivateProfileMachineButtons(
|
|
ByVal lpAppName As String,
|
|
ByVal lpKeyName As String,
|
|
ByRef lpButtonImage As String,
|
|
ByRef lpCommand As String,
|
|
ByRef lpStateFlag As String,
|
|
ByVal lpFileName As String) As Boolean
|
|
|
|
Dim sVal As String = String.Empty
|
|
GetPrivateProfileString(lpAppName, lpKeyName, "", sVal, lpFileName)
|
|
Dim sItems() As String = sVal.Split(",".ToCharArray)
|
|
If sItems.Count() >= 2 Then
|
|
lpButtonImage = sItems(0)
|
|
lpCommand = sItems(1)
|
|
If sItems.Count() >= 3 Then
|
|
lpStateFlag = sItems(2)
|
|
Else
|
|
lpStateFlag = String.Empty
|
|
End If
|
|
Return True
|
|
End If
|
|
Return False
|
|
|
|
End Function
|
|
|
|
End Class
|