Files
OmagCUT/MachineButtonsUC.xaml.vb
T
Renzo Lanza 7be2395fc3 OmagCUT :
- Cambio tema disponibile nella OptionsPageUC (necessario riavvio programma per applicarlo)
2019-09-20 12:44:53 +00:00

481 lines
20 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_bOnlyLaser As Boolean = False
Private m_bFirst As Boolean = True
Private Const MAX_BUTTONS As Integer = 10
Private m_nCount As Integer = 0
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"
Public Sub New(Optional bOnlyLaser As Boolean = False)
' This call is required by the designer.
InitializeComponent()
' Imposto
m_bOnlyLaser = bOnlyLaser
End Sub
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
' Lettura configurazione bottoni da Ini di macchina
Dim m_nCount As Integer = 0
For nIndex As Integer = 0 To MAX_BUTTONS - 1
Dim sButton As String = K_BUTTON & (nIndex + 1).ToString()
Dim sButtonImage As String = String.Empty
Dim sButtonCommand As String = String.Empty
Dim sButtonStateFlag As String = String.Empty
If GetPrivateProfileMachineButtons(S_MACHBUTTONS, sButton & "Y", sButtonImage, sButtonCommand, sButtonStateFlag, m_MainWindow.GetMachIniFile()) And
(Not m_bOnlyLaser Or sButtonStateFlag = BTN_STATE_LASER) Then
ImageArrayY(m_nCount) = sButtonImage
CommandArrayY(m_nCount) = sButtonCommand
StateFlagArray(m_nCount) = sButtonStateFlag
If GetPrivateProfileMachineButtons(S_MACHBUTTONS, sButton & "N", sButtonImage, sButtonCommand, sButtonStateFlag, m_MainWindow.GetMachIniFile()) Then
ImageArrayN(m_nCount) = sButtonImage
CommandArrayN(m_nCount) = sButtonCommand
End If
m_nCount += 1
End If
Next
' Nascondo bottoni inutilizzati
For nIndex As Integer = m_nCount To MAX_BUTTONS - 1
GetToggleButton(nIndex + 1).Visibility = Windows.Visibility.Hidden
Next
' Se variabile di stato "Nothing" imposto immagine fissa
For nIndex As Integer = 0 To m_nCount - 1
If StateFlagArray(nIndex) = BTN_STATE_NOTHING Then
' mostra immagine fissa
Try
Dim s As String
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayY(nIndex)
End If
'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))
End Try
End If
Next
' Se non collegato a CN metto immagini fisse
If Not m_MainWindow.m_bNCLink Then
For nIndex As Integer = 0 To m_nCount - 1
Dim sImage As String = If(String.IsNullOrEmpty(ImageArrayN(nIndex)), ImageArrayY(nIndex), ImageArrayN(nIndex))
Try
Dim s As String
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sImage
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & sImage
End If
'Dim s As String = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sImage
Dim sButtonImageSource As ImageSource = ImageConverter.ConvertFromString(s)
GetImage(nIndex + 1).Source = sButtonImageSource
Catch ex As Exception
EgtOutLog("Error loading image " & sImage)
End Try
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 nIndex As Integer = GetToggleButtonIndex(CurrentBtn) - 1
Dim sBaseDir As String = m_MainWindow.m_CurrentMachine.sMachDir & "\DirectCmd\"
If CurrentBtn.IsChecked() Then
EgtLuaExecFile(sBaseDir & CommandArrayY(nIndex))
Else
If Not (StateFlagArray(nIndex) = BTN_STATE_THREEAXIS Or
StateFlagArray(nIndex) = BTN_STATE_FIVEAXIS) Then
EgtLuaExecFile(sBaseDir & CommandArrayN(nIndex))
Else
Return
End If
End If
Dim dFeed As Double = 0
If Not String.IsNullOrWhiteSpace(m_DirectCutPage.m_ManualAxesMove.FeedTxBx.Text) Then
StringToLen(m_DirectCutPage.m_ManualAxesMove.FeedTxBx.Text, dFeed)
Else
EgtTdbSetCurrTool(m_MainWindow.m_CurrentProjectPageUC.ToolTxBx.Text)
EgtTdbGetCurrToolParam(MCH_TP.FEED, dFeed)
End If
EgtLuaSetGlobNumVar("CMD.F", dFeed)
Dim dSpeed As Double = 0
If Not String.IsNullOrWhiteSpace(m_DirectCutPage.m_ManualAxesMove.SpeedTxBx.Text) Then
StringToDouble(m_DirectCutPage.m_ManualAxesMove.SpeedTxBx.Text, dSpeed)
Else
EgtTdbSetCurrTool(m_MainWindow.m_CurrentProjectPageUC.ToolTxBx.Text)
EgtTdbGetCurrToolParam(MCH_TP.SPEED, dSpeed)
End If
EgtLuaSetGlobNumVar("CMD.S", dSpeed)
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())
EgtLuaCallFunction("CmdString")
' Leggo variabili
Dim CmdString As String = String.Empty
EgtLuaGetGlobStringVar("CMD.CMDSTRING", CmdString)
Dim b2Start As Boolean = False
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(nIndex) = 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 nIndex = -1 Then Return
If SpindleState Then
GetToggleButton(nIndex + 1).IsChecked = True
Try
Dim s As String
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayY(nIndex)
End If
'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
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayN(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayN(nIndex)
End If
'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 nIndex = -1 Then Return
If CoolantState Then
GetToggleButton(nIndex + 1).IsChecked = True
Try
Dim s As String
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayY(nIndex)
End If
'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
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayN(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayN(nIndex)
End If
'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 nIndex = -1 Then Return
If LaserState Then
GetToggleButton(nIndex + 1).IsChecked = True
Try
Dim s As String
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayY(nIndex)
End If
'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
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayN(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayN(nIndex)
End If
'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 nIndex = -1 Then Return
If ThreeAxisState Then
GetToggleButton(nIndex + 1).IsChecked = True
Try
Dim s As String
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayY(nIndex)
End If
'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
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayY(nIndex)
End If
'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 nIndex = -1 Then Return
If FiveAxisState Then
GetToggleButton(nIndex + 1).IsChecked = True
Try
Dim s As String
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayY(nIndex)
End If
'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
If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & ImageArrayY(nIndex)
Else
s = m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\NewIcons\" & ImageArrayY(nIndex)
End If
'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 = BTN_STATE_NOTHING
End If
Return True
End If
Return False
End Function
End Class