Imports System.Collections.ObjectModel Imports System.Runtime.InteropServices Imports System.IO Imports EgtUILib Imports System.Threading Imports EgtWPFLib5 Public Class MyStatusBarVM Inherits StatusBarVM #Region "FIELDS & PROPERTIES" ' Funzioni di callback per output in interfaccia da LUA Private m_ProcEventsCallback As New ProcessEventsCallback(AddressOf ProcessEvents) Private m_OutTextCallback As New OutTextCallback(AddressOf OutText) ' GRAPHICAL ELEMENTS 'Private m_StatusOutput As String 'Public Property StatusOutput As String ' Get ' Return m_StatusOutput ' End Get ' Set(value As String) ' m_StatusOutput = value ' NotifyPropertyChanged("StatusOutput") ' End Set 'End Property 'Private m_StatusCurrPos As String 'Public Property StatusCurrPos As String ' Get ' Return m_StatusCurrPos ' End Get ' Set(value As String) ' m_StatusCurrPos = value ' NotifyPropertyChanged("StatusCurrPos") ' End Set 'End Property 'Private m_StatusProgress As Integer 'Public Property StatusProgress As Integer ' Get ' Return m_StatusProgress ' End Get ' Set(value As Integer) ' m_StatusProgress = value ' NotifyPropertyChanged("StatusProgress") ' End Set 'End Property 'Private m_StatusStopIsEnabled As Boolean 'Public Property StatusStopIsEnabled As Boolean ' Get ' Return m_StatusStopIsEnabled ' End Get ' Set(value As Boolean) ' m_StatusStopIsEnabled = value ' NotifyPropertyChanged("StatusStopIsEnabled") ' End Set 'End Property Private m_GridDimensionText As String Public Property GridDimensionText As String Get Return m_GridDimensionText End Get Set(value As String) m_GridDimensionText = value NotifyPropertyChanged("GridDimensionText") End Set End Property Private m_StatusGridText As String Public Property StatusGridText As String Get Return m_StatusGridText End Get Set(value As String) m_StatusGridText = value NotifyPropertyChanged("StatusGridText") End Set End Property Private m_CurrPosTypeText As String Public Property CurrPosTypeText As String Get Return m_CurrPosTypeText End Get Set(value As String) m_CurrPosTypeText = value NotifyPropertyChanged("CurrPosTypeText") End Set End Property 'Private m_StatusUnitsText As String 'Public Property StatusUnitsText As String ' Get ' Return m_StatusUnitsText ' End Get ' Set(value As String) ' m_StatusUnitsText = value ' NotifyPropertyChanged("StatusUnitsText") ' End Set 'End Property 'Private m_SnapPointTypeText As String 'Public Property SnapPointTypeText As String ' Get ' Return m_SnapPointTypeText ' End Get ' Set(value As String) ' m_SnapPointTypeText = value ' NotifyPropertyChanged("SnapPointTypeText") ' End Set 'End Property 'Private m_SnapPointTypeBackground As SolidColorBrush 'Public Property SnapPointTypeBackground As SolidColorBrush ' Get ' Return m_SnapPointTypeBackground ' End Get ' Set(value As SolidColorBrush) ' m_SnapPointTypeBackground = value ' NotifyPropertyChanged("SnapPointTypeBackground") ' End Set '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 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 ' Commands definition Private m_cmdGridDimension As ICommand Private m_cmdGridDimensionLostFocus As ICommand Private m_cmdStatusGrid As ICommand Private m_cmdCurrPosType As ICommand Private m_cmdStatusUnits As ICommand Private m_cmdStatusStop As ICommand Private m_cmdClearOutputMessage As ICommand #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New() ' Creo riferimento a questa classe in EgtCAM5Map Map.SetRefStatusBarVM(Me) ' Installo funzione gestione eventi per lua EgtSetProcessEvents(m_ProcEventsCallback) ' Installo funzione output testo su status per lua EgtSetOutText(m_OutTextCallback) End Sub #End Region ' Constructor #Region "COMMANDS" #Region "GridDimensionCommand" ''' ''' Returns a command that set grid status. ''' Public ReadOnly Property GridDimensionCommand As ICommand Get If m_cmdGridDimension Is Nothing Then m_cmdGridDimension = New RelayCommand(AddressOf GridDimension) End If Return m_cmdGridDimension End Get End Property ''' ''' Notify the function to set the status. This method is invoked by the StatusGridCommand. ''' Public Sub GridDimension(ByVal param As Object) If IniFile.m_bMmUnits Then StringToLen(GridDimensionText, IniFile.dSnapStepMm) EgtSetGridGeo(IniFile.dSnapStepMm, IniFile.nMinLineSStep, IniFile.nMajLineSStep, IniFile.nExtSStep) Else StringToLen(GridDimensionText, IniFile.dSnapStepInch) EgtSetGridGeo(IniFile.dSnapStepInch, IniFile.nMinLineSStep, IniFile.nMajLineSStep, IniFile.nExtSStep) End If EgtSetGridColor(IniFile.MinLnColor, IniFile.MajLnColor) Keyboard.ClearFocus() EgtDraw() End Sub #End Region ' GridDimensionCommand #Region "GridDimensionLostFocusCommand" ''' ''' Returns a command that set grid status. ''' Public ReadOnly Property GridDimensionLostFocusCommand As ICommand Get If m_cmdGridDimensionLostFocus Is Nothing Then m_cmdGridDimensionLostFocus = New RelayCommand(AddressOf GridDimensionLostFocus) End If Return m_cmdGridDimensionLostFocus End Get End Property ''' ''' Notify the function to set the status. This method is invoked by the StatusGridCommand. ''' Public Sub GridDimensionLostFocus(ByVal param As Object) If IniFile.m_bMmUnits Then GridDimensionText = LenToString(IniFile.dSnapStepMm, 4) Else GridDimensionText = LenToString(IniFile.dSnapStepInch, 4) End If End Sub #End Region ' GridDimensionLostFocusCommand #Region "StatusGridCommand" ''' ''' Returns a command that set grid status. ''' Public ReadOnly Property StatusGridCommand As ICommand Get If m_cmdStatusGrid Is Nothing Then m_cmdStatusGrid = New RelayCommand(AddressOf StatusGrid) End If Return m_cmdStatusGrid End Get End Property ''' ''' Notify the function to set the status. This method is invoked by the StatusGridCommand. ''' Public Sub StatusGrid(ByVal param As Object) Dim bGridState As Boolean If IniFile.m_ProjectMode = ProjectModeOpt.DRAW OrElse IniFile.m_ProjectMode = ProjectModeOpt.ONLYDRAW Then IniFile.m_bDrawShowGrid = Not IniFile.m_bDrawShowGrid bGridState = m_bDrawShowGrid ElseIf IniFile.m_ProjectMode = ProjectModeOpt.MACHINING Then IniFile.m_bMachiningShowGrid = Not IniFile.m_bMachiningShowGrid bGridState = m_bMachiningShowGrid End If Map.refStatusBarVM.UpdateStatusGrid(New UpdateStatusGridParam(bGridState, IniFile.m_bShowGridFrame)) EgtDraw() End Sub #End Region ' StatusGridCommand #Region "CurrPosTypeCommand" ''' ''' Returns a command that choose the current reference. ''' Public ReadOnly Property CurrPosTypeCommand As ICommand Get If m_cmdCurrPosType Is Nothing Then m_cmdCurrPosType = New RelayCommand(AddressOf CurrPosType) End If Return m_cmdCurrPosType End Get End Property ''' ''' Execute the Point. This method is invoked by the CurrPosTypeCommand. ''' Public Sub CurrPosType(ByVal param As Object) Map.refProjectVM.StatusCurrPosTypeCommand() End Sub #End Region ' CurrPosTypeCommand #Region "StatusUnitsCommand" ''' ''' Returns a command that choose the current reference. ''' Public ReadOnly Property StatusUnitsCommand As ICommand Get If m_cmdStatusUnits Is Nothing Then m_cmdStatusUnits = New RelayCommand(AddressOf StatusUnits) End If Return m_cmdStatusUnits End Get End Property ''' ''' Execute the Point. This method is invoked by the CurrPosTypeCommand. ''' Public Sub StatusUnits(ByVal param As Object) Map.refProjectVM.StatusUnitsCommand() If IniFile.m_bMmUnits Then GridDimensionText = LenToString(IniFile.dSnapStepMm, 4) Else GridDimensionText = LenToString(IniFile.dSnapStepInch, 4) End If End Sub #End Region ' StatusUnitsCommand #Region "StatusStopCommand" ''' ''' Returns a command that choose the current reference. ''' Public ReadOnly Property StatusStopCommand As ICommand Get If m_cmdStatusStop Is Nothing Then m_cmdStatusStop = New RelayCommand(AddressOf StatusStop) End If Return m_cmdStatusStop End Get End Property ''' ''' Execute the Point. This method is invoked by the StatusStopCommand. ''' Public Sub StatusStop(ByVal param As Object) m_bStopScript = True End Sub #End Region ' StatusStopCommand #Region "ClearOutputMessageCommand" ''' ''' Returns a command that choose the current reference. ''' Public Overrides ReadOnly Property ClearOutputMessage_Command As ICommand Get If m_cmdClearOutputMessage Is Nothing Then m_cmdClearOutputMessage = New RelayCommand(AddressOf ClearOutputMessage) End If Return m_cmdClearOutputMessage End Get End Property ''' ''' Execute the Point. This method is invoked by the ClearOutPutMessage_Command. ''' Public Overloads Sub ClearOutputMessage(ByVal param As Object) OutputMessage = String.Empty SetLoadingProgress(0) NotifyPropertyChanged("OutputMessage") End Sub #End Region ' ClearStatusOutputCommand #End Region ' Commands #Region "METHODS" Friend Sub NotifyStatusOutput(sStatusOutput As String) SetOutputMessage(sStatusOutput) End Sub Friend Sub NotifyCurrPos(sCursorPos As String) SetCurrPos(sCursorPos) End Sub Friend Sub NotifyStatusProgress(sStatusProgress As Integer) SetLoadingProgress(sStatusProgress) End Sub Friend Sub NotifyStatusStop(sStatusStop As Boolean) SetStopProgress_IsEnabled(sStatusStop) End Sub Friend Sub UpdateStatusGrid(UpdateStatusGridParam As UpdateStatusGridParam) UpdateStatusGrid(UpdateStatusGridParam.m_bShowGrid, UpdateStatusGridParam.m_bShowGridFrame) End Sub Friend Sub StatusCurrPosTypeText(sString As String) CurrPosTypeText = sString End Sub Friend Sub UpdateStatusUnits(bMmUnits As Boolean) SetMeasureUnit(If(bMmUnits, 1, 0)) 'StatusUnitsText = If(bMmUnits, "mm", "in") EgtSetUiUnits(bMmUnits) End Sub Friend Sub StatusSnapPointTypeText(sString As String) SetSnapPointType(sString) End Sub Friend Sub StatusSnapPointTypeBackground(Color As SolidColorBrush) SetSnapPointType_Background(Color) End Sub Private Sub UpdateStatusGrid(bShowGrid As Boolean, bShowGridFrame As Boolean) 'tsStatusGrid.ForeColor = If(m_bShowGrid, Color.Black, Color.Gray) StatusGridText = If(bShowGrid, "GRID ON ", "GRID OFF") EgtSetGridShow(bShowGrid, bShowGrid And bShowGridFrame) End Sub '''' '''' Method that search the machines in the correct folder and add to the MachinesList those valid. '''' '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 '''' '''' Class that create the association Name/IniPath for the machine's '''' '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 Public Function OutText(ByRef psText As IntPtr) As Boolean ' Assegno stringa OutputMessage = (Marshal.PtrToStringUni(psText)) ' Costringo ad aggiornare UpdateUI() Return True End Function Private Function ProcessEvents(ByVal nProg As Integer, ByVal nPause As Integer) As Integer ' Se previsto, imposto progress If nProg > 0 Then SetLoadingProgress(Math.Min(nProg, 100)) ' Notifico a simulazione aggiornamento dati If Not IsNothing( Map.refSimulationExpanderVM) Then ' Uso i valori negativi del primo parametro come flag per la Simulazione Dim nFlag As Integer = If( nProg < 0, -nProg, 0) Map.refSimulationExpanderVM.SimulationExpander_Update_CncData( nFlag) End If ' Costringo ad aggiornare UpdateUI() ' Eventuale attesa Thread.Sleep(nPause) ' Ritorno eventuale stop If m_bStopScript Then m_bStopScript = False Return 1 Else Return 0 End If End Function Public Sub SetSnapPointType_Background(SnapPntTypeBackground As SolidColorBrush) SnapPointType_Background = SnapPntTypeBackground NotifyPropertyChanged("SnapPointType_Background") End Sub #End Region ' Methods End Class