Imports System.Collections.ObjectModel Imports System.ComponentModel Imports EgtUILib Public Class ControlsMachineButtonUC Implements INotifyPropertyChanged ' Costanti per nomi stati dei bottoni Private Const BTN_STATE_NOTHING As String = "Nothing" Private Enum MachineButtonType As Integer NOSTATE = 0 TWOSTATE = 1 THREESTATE = 2 DOUBLECOMMAND = 3 PRESSEDCOMMAND = 4 End Enum ' Dichiarazione delle Page UserControl Private 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 ' Creazione converter da String a ImageSource Dim ImageConverter As New ImageSourceConverter Private m_ButtonList As New ObservableCollection(Of MachineButton) Public ReadOnly Property ButtonList As ObservableCollection(Of MachineButton) Get Return m_ButtonList End Get End Property Private Sub ControlsMachineButtonUC_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized Me.DataContext = Me End Sub Private Sub ControlsMachineButtonUC_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded If m_bFirst Then m_DirectCutPage = m_MainWindow.m_DirectCutPageUC m_bFirst = False ' Lettura configurazione bottoni da Ini di macchina Dim m_nCount As Integer = 1 Dim bFoundBtn As Boolean = True While bFoundBtn Dim sNameBtn As String = K_BUTTON & (m_nCount).ToString() Dim sMachineButtonType As String = String.Empty Dim sTImageName As String = String.Empty Dim sTLuaScriptName As String = String.Empty Dim sFImageName As String = String.Empty Dim sFLuaScriptName As String = String.Empty Dim sStateFlag As String = String.Empty bFoundBtn = GetPrivateProfileMachineButtons(S_CONTROLMACHBUTTONS, sNameBtn, sMachineButtonType, sTImageName, sTLuaScriptName, sFImageName, sFLuaScriptName, sStateFlag, m_MainWindow.GetMachIniFile()) If bFoundBtn Then m_nCount += 1 Dim ButtonToAdd As MachineButton = Nothing Select Case sMachineButtonType Case MachineButtonType.NOSTATE ButtonToAdd = New NoStateButton(sTImageName, sTLuaScriptName, sFImageName, sFLuaScriptName, sStateFlag) Case MachineButtonType.TWOSTATE ButtonToAdd = New TwoStateButton(sTImageName, sTLuaScriptName, sFImageName, sFLuaScriptName, sStateFlag) Case MachineButtonType.THREESTATE ButtonToAdd = New ThreeStateButton(sTImageName, sTLuaScriptName, sFImageName, sFLuaScriptName, sStateFlag) Case MachineButtonType.DOUBLECOMMAND ButtonToAdd = New DoubleCommandButton(sTImageName, sTLuaScriptName, sFImageName, sFLuaScriptName, sStateFlag) Case MachineButtonType.PRESSEDCOMMAND ButtonToAdd = New PressedCommandButton(sTImageName, sTLuaScriptName, sFImageName, sFLuaScriptName, sStateFlag) End Select If Not IsNothing(ButtonToAdd) Then m_ButtonList.Add(ButtonToAdd) End If End While NotifyPropertyChanged("ButtonList") End If End Sub Friend Sub SpindleStateChanged(SpindleState As Boolean) Dim SpindleButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_SPINDLE Then SpindleButton = MachineButton End If Next If Not IsNothing(SpindleButton) Then SpindleButton.SetIsChecked(SpindleState) End If End Sub Friend Sub LaserStateChanged(LaserState As Boolean) Dim LaserButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_LASER Then LaserButton = MachineButton End If Next If Not IsNothing(LaserButton) Then LaserButton.SetIsChecked(LaserState) End If End Sub Friend Sub LaserTracStateChanged(LaserTracState As Boolean) Dim LaserTracButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_LASERTRAC Then LaserTracButton = MachineButton End If Next If Not IsNothing(LaserTracButton) Then LaserTracButton.SetIsChecked(LaserTracState) End If End Sub Friend Sub CoolantStateChanged(CoolantState As Boolean) Dim CoolantButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_COOLANT Then CoolantButton = MachineButton End If Next If Not IsNothing(CoolantButton) Then CoolantButton.SetIsChecked(CoolantState) End If End Sub Friend Sub InternalCoolantStateChanged(InternalCoolantState As Boolean) Dim IntCoolantButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_INTERNALCOOLANT Then IntCoolantButton = MachineButton End If Next If Not IsNothing(IntCoolantButton) Then IntCoolantButton.SetIsChecked(InternalCoolantState) End If End Sub Friend Sub ExternCoolantStateChanged(ExternCoolantState As Boolean) Dim ExtCoolantButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_EXTERNCOOLANT Then ExtCoolantButton = MachineButton End If Next If Not IsNothing(ExtCoolantButton) Then ExtCoolantButton.SetIsChecked(ExternCoolantState) End If End Sub Friend Sub CBAxesStateChanged(CBAxesState As Boolean) Dim CAxesButton As TwoStateButton = Nothing Dim BAxesButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_CAXES Then CAxesButton = MachineButton ElseIf MachineButton.StateFlag = K_BAXES Then BAxesButton = MachineButton End If Next If Not IsNothing(CAxesButton) Then CAxesButton.SetIsChecked(CBAxesState) End If If Not IsNothing(BAxesButton) Then BAxesButton.SetIsChecked(Not CBAxesState) End If End Sub Friend Sub AirBlowStateChanged(AirBlowState As Boolean) Dim AirBlowButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_AIRBLOW Then AirBlowButton = MachineButton End If Next If Not IsNothing(AirBlowButton) Then AirBlowButton.SetIsChecked(AirBlowState) End If End Sub Friend Sub HomeStateChanged(HomeState As Boolean) Dim HomeButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_HOME Then HomeButton = MachineButton End If Next If Not IsNothing(HomeButton) Then HomeButton.SetIsChecked(HomeState) End If End Sub Friend Sub TableUpChanged(TableUpState As Boolean) Dim TableUpButton As PressedCommandButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_TABLEUP Then TableUpButton = MachineButton End If Next If Not IsNothing(TableUpButton) Then TableUpButton.SetIsPressed(TableUpState) End If End Sub Friend Sub TableDownChanged(TableDownState As Boolean) Dim TableDownButton As PressedCommandButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_TABLEDOWN Then TableDownButton = MachineButton End If Next If Not IsNothing(TableDownButton) Then TableDownButton.SetIsPressed(TableDownState) End If End Sub Friend Sub DoorClosedChanged(DoorClosedState As Integer) Dim DoorClosedButton As ThreeStateButton = Nothing Dim DoorOpenedButton As ThreeStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_DOORCLOSED Then 'If TypeOf MachineButton Is NoStateButton Then ' DoorClosedButton = DirectCast(MachineButton, NoStateButton) 'ElseIf TypeOf MachineButton Is TwoStateButton Then ' DoorClosedButton = DirectCast(MachineButton, TwoStateButton) 'ElseIf TypeOf MachineButton Is ThreeStateButton Then ' DoorClosedButton = DirectCast(MachineButton, ThreeStateButton) 'ElseIf TypeOf MachineButton Is DoubleCommandButton Then ' DoorClosedButton = DirectCast(MachineButton, DoubleCommandButton) 'ElseIf TypeOf MachineButton Is PressedCommandButton Then ' DoorClosedButton = DirectCast(MachineButton, PressedCommandButton) 'End If DoorClosedButton = MachineButton End If If MachineButton.StateFlag = "DoorOpened" Then DoorOpenedButton = MachineButton End If Next If Not IsNothing(DoorClosedButton) Then Select Case DoorClosedState Case 0 DoorClosedButton.Background = Application.Current.FindResource("OmagCut_Red") Case 1, 2 DoorClosedButton.Background = Application.Current.FindResource("OmagCut_LightGray") End Select End If If Not IsNothing(DoorOpenedButton) Then Select Case DoorClosedState Case 0 DoorOpenedButton.Background = Application.Current.FindResource("OmagCut_LightGray") Case 1 DoorOpenedButton.Background = Application.Current.FindResource("OmagCut_Yellow") Case 2 DoorOpenedButton.Background = Application.Current.FindResource("OmagCut_Green") End Select End If End Sub Friend Sub LimitZChanged(LimitZState As Boolean) Dim LimitZButton As DoubleCommandButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_LIMITZ Then LimitZButton = MachineButton End If Next If Not IsNothing(LimitZButton) Then LimitZButton.SetIsChecked(LimitZState) End If End Sub Friend Sub FiveAxisStateChanged(FiveAxisState As Boolean) Dim ThreeAxesButton As TwoStateButton = Nothing Dim FiveAxesButton As TwoStateButton = Nothing For Each MachineButton In m_ButtonList If MachineButton.StateFlag = K_THREEAXES Then ThreeAxesButton = MachineButton ElseIf MachineButton.StateFlag = K_FIVEAXES Then FiveAxesButton = MachineButton End If Next If Not IsNothing(ThreeAxesButton) Then ThreeAxesButton.SetIsChecked(Not FiveAxisState) End If If Not IsNothing(FiveAxesButton) Then FiveAxesButton.SetIsChecked(FiveAxisState) End If End Sub Public Function GetPrivateProfileMachineButtons( ByVal lpAppName As String, ByVal lpKeyName As String, ByRef lpMachineButtonType As String, ByRef lpTImageName As String, ByRef lpTLuaScriptName As String, ByRef lpFImageName As String, ByRef lpFLuaScriptName 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() >= 3 Then lpMachineButtonType = sItems(0) lpTImageName = sItems(1) lpTLuaScriptName = sItems(2) If sItems.Count() >= 4 Then lpStateFlag = sItems(3) If sItems.Count() >= 6 Then lpFImageName = sItems(4) lpFLuaScriptName = sItems(5) End If Else lpStateFlag = BTN_STATE_NOTHING End If Return True End If Return False End Function Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged Public Sub NotifyPropertyChanged(propName As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName)) End Sub #Region "EVENTS" Private Sub PressedCommandButton_PreviewMouseUp(sender As Object, e As MouseButtonEventArgs) Dim Button As Button = DirectCast(sender, Button) If TypeOf Button.DataContext Is PressedCommandButton Then Dim PressedButton As PressedCommandButton = DirectCast(Button.DataContext, PressedCommandButton) PressedButton.OnMouseUp() End If End Sub Private Sub PressedCommandButton_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) Dim Button As Button = DirectCast(sender, Button) If TypeOf Button.DataContext Is PressedCommandButton Then Dim PressedButton As PressedCommandButton = DirectCast(Button.DataContext, PressedCommandButton) PressedButton.OnMouseDown() End If End Sub #End Region End Class Public MustInherit Class MachineButton Implements INotifyPropertyChanged ' Costanti per nomi stati dei bottoni Friend Const BTN_STATE_SPINDLE As String = "Spindle" Friend Const BTN_STATE_COOLANT As String = "Coolant" Friend Const BTN_STATE_LASER As String = "Laser" Friend Const BTN_STATE_THREEAXIS As String = "ThreeAxis" Friend Const BTN_STATE_FIVEAXIS As String = "FiveAxis" Friend Const BTN_STATE_NOTHING As String = "Nothing" ' Dichiarazione delle Page UserControl Friend Shared m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow) Friend Shared m_DirectCutPage As DirectCutPageUC = m_MainWindow.m_DirectCutPageUC Friend Shared m_CN As CN_generico = m_MainWindow.m_DirectCutPageUC.m_CN Private m_TImageName As String Public ReadOnly Property TImageName As String Get Return m_TImageName End Get End Property Private m_TLuaScriptName As String Public ReadOnly Property TLuaScriptName As String Get Return m_TLuaScriptName End Get End Property Private m_FImageName As String Public ReadOnly Property FImageName As String Get Return m_FImageName End Get End Property Private m_FLuaScriptName As String Public ReadOnly Property FLuaScriptName As String Get Return m_FLuaScriptName End Get End Property Private m_StateFlag As String Public ReadOnly Property StateFlag As String Get Return m_StateFlag End Get End Property Sub New(TImagePath As String, TLuaScriptPath As String, FImagePath As String, FLuaScriptPath As String, StateFlag As String) m_TImageName = TImagePath m_TLuaScriptName = TLuaScriptPath m_FImageName = FImagePath m_FLuaScriptName = FLuaScriptPath m_StateFlag = StateFlag End Sub #Region "METHODS" Friend Sub ExecuteMDICommand(sLuaFileName As String) If String.IsNullOrWhiteSpace(sLuaFileName) Then Return Dim CmdString As String = String.Empty Dim b2Start As Boolean = False Dim EActive As Boolean = False Dim ENumber As String = String.Empty Dim EValue As String = String.Empty ExecuteDirectCmdLua(sLuaFileName, CmdString, b2Start, EActive, ENumber, EValue) ' se attiva variabile E, la scrivo ed esco If EActive Then m_CN.DVariables_WriteVariables2(ENumber, EValue) Return End If 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 End Sub Friend Sub ExecuteDirectCmdLua(LuaFileName As String, ByRef CmdString As String, ByRef b2Start As Boolean, ByRef EActive As Boolean, ByRef ENumber As String, ByRef EValue As String) Dim sBaseDir As String = m_MainWindow.m_CurrentMachine.sMachDir & "\DirectCmd\" EgtLuaExecFile(sBaseDir & LuaFileName) 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 CmdString = String.Empty EgtLuaGetGlobStringVar("CMD.CMDSTRING", CmdString) b2Start = False EgtLuaGetGlobBoolVar("CMD.DOUBLESTART", b2Start) EActive = False EgtLuaGetGlobBoolVar("CMD.EACTIVE", EActive) ENumber = String.Empty EgtLuaGetGlobStringVar("CMD.ENUMBER", ENumber) EValue = String.Empty EgtLuaGetGlobStringVar("CMD.EVALUE", EValue) ' Reset lua EgtLuaResetGlobVar("CmdString") EgtLuaResetGlobVar("CMD") ' Log del comando EgtOutLog("CmdString=" & CmdString & " b2Start=" & b2Start.ToString() & " EActive=" & EActive & " ENumber=" & ENumber & " EValue=" & EValue) End Sub #End Region ' METHODS Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged Public Sub NotifyPropertyChanged(propName As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName)) End Sub End Class Public Class TwoStateButton Inherits MachineButton Private m_IsChecked As Boolean Public Property IsChecked As Boolean Get Return m_IsChecked End Get Set(value As Boolean) m_IsChecked = value If value Then ExecuteMDICommand(TLuaScriptName) Else ExecuteMDICommand(FLuaScriptName) End If End Set End Property Friend Sub SetIsChecked(value As Boolean) m_IsChecked = value NotifyPropertyChanged("IsChecked") NotifyPropertyChanged("ImageSource") End Sub Public ReadOnly Property ImageSource As String Get Dim sNewIcons As String If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then sNewIcons = "" Else sNewIcons = "NewIcons\" End If ' Se variabile di stato "Nothing" o non collegato a CN, imposto immagine fissa If StateFlag = BTN_STATE_NOTHING Or Not m_MainWindow.m_bNCLink Or IsNothing(FImageName) Or String.IsNullOrWhiteSpace(FImageName) Then ' ritorno immagine dello stato true Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & TImageName End If If m_IsChecked Then ' ritorno immagine dello stato true Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & TImageName Else ' ritorno immagine dello stato false Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & FImageName End If End Get End Property #Region "METHODS" Sub New(TImagePath As String, TLuaScriptPath As String, FImagePath As String, FLuaScriptPath As String, StateFlag As String) MyBase.New(TImagePath, TLuaScriptPath, FImagePath, FLuaScriptPath, StateFlag) End Sub #End Region ' METHODS End Class Public Class NoStateButton Inherits MachineButton ' definizione comandi Private m_cmdExecute As ICommand Public ReadOnly Property ImageSource As String Get Dim sNewIcons As String If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then sNewIcons = "" Else sNewIcons = "NewIcons\" End If Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & TImageName End Get End Property #Region "METHODS" Sub New(TImagePath As String, TLuaScriptPath As String, FImagePath As String, FLuaScriptPath As String, StateFlag As String) MyBase.New(TImagePath, TLuaScriptPath, Nothing, Nothing, StateFlag) End Sub #End Region ' METHODS #Region "COMMANDS" #Region "Execute" ' Returns a command that manage the MainWindow_Unloaded command Public ReadOnly Property ExecuteCommand() As ICommand Get If m_cmdExecute Is Nothing Then m_cmdExecute = New Command(AddressOf Execute) End If Return m_cmdExecute End Get End Property ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. Public Sub Execute() If StateFlag = K_MANUAL Then m_CN.DGeneralFunctions_WriteCncMode(7) ' Modalità manuale Else ExecuteMDICommand(TLuaScriptName) End If End Sub #End Region ' Execute #End Region ' COMMANDS End Class Public Class ThreeStateButton Inherits MachineButton ' definizione comandi Private m_cmdExecute As ICommand Private m_Background As SolidColorBrush Public Property Background As SolidColorBrush Get Return m_Background End Get Set(value As SolidColorBrush) m_Background = value NotifyPropertyChanged("Background") End Set End Property Public ReadOnly Property ImageSource As String Get Dim sNewIcons As String If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then sNewIcons = "" Else sNewIcons = "NewIcons\" End If ' ritorno immagine dello stato true Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & TImageName End Get End Property #Region "METHODS" Sub New(TImagePath As String, TLuaScriptPath As String, FImagePath As String, FLuaScriptPath As String, StateFlag As String) MyBase.New(TImagePath, TLuaScriptPath, FImagePath, FLuaScriptPath, StateFlag) End Sub #End Region ' METHODS #Region "COMMANDS" #Region "Execute" ' Returns a command that manage the MainWindow_Unloaded command Public ReadOnly Property ExecuteCommand() As ICommand Get If m_cmdExecute Is Nothing Then m_cmdExecute = New Command(AddressOf Execute) End If Return m_cmdExecute End Get End Property ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. Public Sub Execute() ExecuteMDICommand(TLuaScriptName) ExecuteMDICommand(FLuaScriptName) End Sub #End Region ' Execute #End Region ' COMMANDS End Class Public Class DoubleCommandButton Inherits MachineButton Private m_IsChecked As Boolean Public Property IsChecked As Boolean Get Return m_IsChecked End Get Set(value As Boolean) m_IsChecked = value ExecuteMDICommand(TLuaScriptName) System.Threading.Thread.Sleep(100) ExecuteMDICommand(FLuaScriptName) End Set End Property Friend Sub SetIsChecked(value As Boolean) m_IsChecked = value NotifyPropertyChanged("IsChecked") NotifyPropertyChanged("ImageSource") End Sub Public ReadOnly Property ImageSource As String Get Dim sNewIcons As String If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then sNewIcons = "" Else sNewIcons = "NewIcons\" End If ' Se variabile di stato "Nothing" o non collegato a CN, imposto immagine fissa If StateFlag = BTN_STATE_NOTHING Or Not m_MainWindow.m_bNCLink Or IsNothing(FImageName) Or String.IsNullOrWhiteSpace(FImageName) Then ' ritorno immagine dello stato true Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & TImageName End If If m_IsChecked Then ' ritorno immagine dello stato true Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & TImageName Else ' ritorno immagine dello stato false Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & FImageName End If End Get End Property #Region "METHODS" Sub New(TImagePath As String, TLuaScriptPath As String, FImagePath As String, FLuaScriptPath As String, StateFlag As String) MyBase.New(TImagePath, TLuaScriptPath, FImagePath, FLuaScriptPath, StateFlag) End Sub #End Region ' METHODS End Class Public Class PressedCommandButton Inherits MachineButton Private m_IsPressed As Boolean Friend Sub SetIsPressed(value As Boolean) m_IsPressed = value NotifyPropertyChanged("ImageSource") End Sub Public ReadOnly Property ImageSource As String Get Dim sNewIcons As String If (m_MainWindow.m_OptionsPageUC.ThemesCmBx.SelectedIndex = 0) Then sNewIcons = "" Else sNewIcons = "NewIcons\" End If ' Se variabile di stato "Nothing" o non collegato a CN, imposto immagine fissa If StateFlag = BTN_STATE_NOTHING Or Not m_MainWindow.m_bNCLink Or IsNothing(FImageName) Or String.IsNullOrWhiteSpace(FImageName) Then ' ritorno immagine dello stato true Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & TImageName End If If m_IsPressed Then ' ritorno immagine dello stato true Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & TImageName Else ' ritorno immagine dello stato false Return m_MainWindow.GetResourcesDir() & "\MachineButtonsImage\" & sNewIcons & FImageName End If End Get End Property #Region "METHODS" Sub New(TImagePath As String, TLuaScriptPath As String, FImagePath As String, FLuaScriptPath As String, StateFlag As String) MyBase.New(TImagePath, TLuaScriptPath, FImagePath, FLuaScriptPath, StateFlag) End Sub Friend Sub OnMouseDown() ExecuteMDICommand(TLuaScriptName) SetIsPressed(True) End Sub Friend Sub OnMouseUp() ExecuteMDICommand(FLuaScriptName) SetIsPressed(False) End Sub #End Region ' METHODS End Class