Files
Emmanuele Sassi fa0bdaba59 Num funzionante
2021-11-03 18:51:05 +01:00

124 lines
3.3 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtWPFLib5
Imports EgtUILib
Public Class AxesPanelVM
Inherits VMBase
Private m_AxesList As New ObservableCollection(Of Axis)
Public ReadOnly Property AxesList As ObservableCollection(Of Axis)
Get
Return m_AxesList
End Get
End Property
Sub New()
' immposto riferimento in Map
Map.SetRefAxesPanelVM(Me)
' leggo assi da ini
Dim nIndex As Integer = 1
Dim Axis As Axis = GetPrivateProfileAxis(S_AXES, nIndex.ToString(), Map.refMainWindowVM.MainWindowM.sMachIniFile)
' leggo assi lineari
While Not IsNothing(Axis)
AxesList.Add(Axis)
nIndex += 1
Axis = GetPrivateProfileAxis(S_AXES, nIndex, Map.refMainWindowVM.MainWindowM.sMachIniFile)
End While
End Sub
Private Function GetPrivateProfileAxis(IpAppName As String, IpKeyName As String, IpFileName As String) As Axis
Dim sAxis As String = ""
EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sAxis, IpFileName)
Dim sAxisValues() As String = sAxis.Split(","c)
If Not sAxisValues.Count >= 3 Then Return Nothing
For Each Value In sAxisValues
Value = Value.Trim()
Next
Dim nId As Integer = 0
Dim Type As Axis.AxisTypes = Axis.AxisTypes.NULL
Integer.TryParse(sAxisValues(1), nId)
Select Case sAxisValues(0).ToLower()
Case "l"
Type = Axis.AxisTypes.LINEAR
Case "r"
Type = Axis.AxisTypes.ROTATIONAL
Case Else
Type = Axis.AxisTypes.NULL
End Select
Return New Axis(nId, Type, sAxisValues(2))
End Function
Friend Sub AxisCoordinatesCallbackDlg(AxisValue As Double, AxisIndex As Integer)
Dim Axis As Axis = m_AxesList.FirstOrDefault(Function(x) x.nId = AxisIndex)
If Not IsNothing(Axis) Then
Axis.SetValue(AxisValue)
End If
End Sub
Private Sub SetAxisValue(VarName As String, VarValue As String)
Dim Axis As Axis = m_AxesList.FirstOrDefault(Function(x) x.sName = VarName)
If Not IsNothing(Axis) Then
Axis.SetValue(VarValue)
End If
End Sub
End Class
Public Class Axis
Inherits VMBase
Public Enum AxisTypes As Integer
NULL = 0
LINEAR = 1
ROTATIONAL = 2
End Enum
Private m_nId As String
Public ReadOnly Property nId As String
Get
Return m_nId
End Get
End Property
Private m_sName As String
Public ReadOnly Property sName As String
Get
Return m_sName
End Get
End Property
Private m_Type As AxisTypes
Public ReadOnly Property Type As AxisTypes
Get
Return m_Type
End Get
End Property
Private m_dValue As Double
Public ReadOnly Property dValue As Double
Get
Return m_dValue
End Get
End Property
Friend Sub SetValue(value As Double)
Select Case Type
Case AxisTypes.LINEAR
m_dValue = value / 1000
Case AxisTypes.ROTATIONAL
m_dValue = value / 10000
Case Else
m_dValue = value
End Select
NotifyPropertyChanged(NameOf(dValue))
End Sub
Public Sub New(nId As String, Type As AxisTypes, sName As String)
m_nId = nId
m_Type = Type
m_sName = sName
End Sub
End Class