Imports System.Collections.ObjectModel
Imports EgtUILib
Namespace EgtCAM5
Public Class MachiningTreeExpanderViewModel
Inherits ViewModelBase
#Region "FIELDS & PROPERTIES"
Private m_IsEnabled As Boolean
Public Property IsEnabled As Boolean
Get
Return m_IsEnabled
End Get
Set(value As Boolean)
If value <> m_IsEnabled Then
m_IsEnabled = value
OnPropertyChanged("IsEnabled")
End If
End Set
End Property
' Lista delle lavorazioni
Private m_MachiningsList As New ObservableCollection(Of FamilyMachiningTreeViewExpanderItem)
Public Property MachiningsList As ObservableCollection(Of FamilyMachiningTreeViewExpanderItem)
Get
Return m_MachiningsList
End Get
Set(value As ObservableCollection(Of FamilyMachiningTreeViewExpanderItem))
m_MachiningsList = value
End Set
End Property
' Definizione comandi
Private m_cmdTreeViewDoubleClick As ICommand
#End Region
#Region "CONSTRUCTOR"
Sub New()
' Per caricare l'albero la prima volta che viene aperto
IsEnabled = False
LoadSelectedMachineMachinings()
Application.Msn.Register(Application.MACHININGMODE_ISCHECKED, Sub()
m_MachiningsList.Clear()
LoadSelectedMachineMachinings()
End Sub)
Application.Msn.Register(Application.MACHININGTREEVIEWEXPANDERISENABLED, Sub(bValue As Boolean)
IsEnabled = bValue
End Sub)
End Sub
#End Region
#Region "COMMANDS"
#Region "TreeViewDoubleClickCommand"
'''
''' Returns a command that do TreeViewDoubleClick.
'''
Public ReadOnly Property TreeViewDoubleClickCommand As ICommand
Get
If m_cmdTreeViewDoubleClick Is Nothing Then
m_cmdTreeViewDoubleClick = New RelayCommand(AddressOf TreeViewDoubleClick, AddressOf CanTreeViewDoubleClick)
End If
Return m_cmdTreeViewDoubleClick
End Get
End Property
'''
''' Execute the TreeViewDoubleClick. This method is invoked by the TreeViewDoubleClickCommand.
'''
Public Sub TreeViewDoubleClick(ByVal param As Object)
If TypeOf param Is MachiningTreeViewExpanderItem Then
Dim Machining As MachiningTreeViewExpanderItem = DirectCast(param, MachiningTreeViewExpanderItem)
' Creo nuova lavorazione(operazione) con la lavorazione selezionata
Dim MachiningId As Integer = EgtAddMachining(MachiningTypeToString(DirectCast(Machining.Type, MCH_MY)) & "_1", Machining.Name)
' Recupero geometria correntemente selezionata e la metto in un vettore
Dim SelectedEntities As New List(Of Integer)
Dim EntityId As Integer = EgtGetFirstSelectedObj()
While EntityId <> GDB_ID.NULL
SelectedEntities.Add(EntityId)
EntityId = EgtGetNextSelectedObj()
End While
' Imposto l'operazione appena creata come corrente
EgtSetCurrMachining(MachiningId)
' Imposto il vettore come geometria di lavorazione
EgtSetMachiningGeometry(SelectedEntities.ToArray)
' Calcolo la lavorazione con la nuova geometria
EgtApplyMachining(True)
EgtDraw()
' Ricarico la lista operazioni per avere quella nuova
Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST)
' disabilito la modalità nuova lavorazione
Application.Msn.NotifyColleagues(Application.NEWMACHININGMODEISACTIVE, False)
End If
End Sub
'''
''' Returns always true.
'''
Private Function CanTreeViewDoubleClick(ByVal param As Object) As Boolean
Return True
End Function
Private Function MachiningTypeToString(Type As MCH_MY) As String
Select Case Type
Case MCH_MY.DRILLING
Return EgtMsg(MSG_MACHININGSDBPAGE + 1)
Case MCH_MY.SAWING
Return EgtMsg(MSG_MACHININGSDBPAGE + 2)
Case MCH_MY.MILLING
Return EgtMsg(MSG_MACHININGSDBPAGE + 3)
Case MCH_MY.POCKETING
Return EgtMsg(MSG_MACHININGSDBPAGE + 4)
Case MCH_MY.MORTISING
Return EgtMsg(MSG_MACHININGSDBPAGE + 5)
Case MCH_MY.SAWROUGHING
Return EgtMsg(MSG_MACHININGSDBPAGE + 6)
Case MCH_MY.SAWFINISHING
Return EgtMsg(MSG_MACHININGSDBPAGE + 7)
Case Else
Return String.Empty
End Select
End Function
#End Region ' TreeViewDoubleClickCommand
#End Region ' Commands
#Region "METHODS"
'''
''' Method that search the machines in the correct folder and add to the MachinesList those valid.
'''
Private Sub LoadSelectedMachineMachinings()
Dim ActiveMachiningsTypes() As MachiningsType = ReadActiveMachiningsFamilies()
For Each MachiningsType In ActiveMachiningsTypes
Dim FamilyTreeView As New FamilyMachiningTreeViewExpanderItem(MachiningsType.TypeName, MachiningsType.TypeId)
MachiningsList.Add(FamilyTreeView)
Dim MachiningName As String = String.Empty
If EgtMdbGetFirstMachining(MachiningsType.TypeId, MachiningName) Then
FamilyTreeView.Items.Add(New MachiningTreeViewExpanderItem(MachiningName, MachiningsType.TypeId))
While EgtMdbGetNextMachining(MachiningsType.TypeId, MachiningName)
FamilyTreeView.Items.Add(New MachiningTreeViewExpanderItem(MachiningName, MachiningsType.TypeId))
End While
End If
Next
' Se esiste almeno una famiglia di lavorazioni, la seleziono
If MachiningsList.Count > 0 Then
MachiningsList(0).IsSelected = True
MachiningsList(0).NotifyPropertyChanged("IsSelected")
End If
End Sub
'''
''' Method that search the machines in the correct folder and add to the MachinesList those valid.
'''
Private Function ReadActiveMachiningsFamilies() As MachiningsType()
Dim ActiveMachiningsFamiliesList As New List(Of MachiningsType)
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_DRILLING, 0, m_sDbsCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.DRILLING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 1)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWING, 0, m_sDbsCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.SAWING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 2)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_MILLING, 0, m_sDbsCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.MILLING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 3)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_POCKETING, 0, m_sDbsCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.POCKETING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 4)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_MORTISING, 0, m_sDbsCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.MORTISING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 5)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWROUGHING, 0, m_sDbsCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.SAWROUGHING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 6)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWFINISHING, 0, m_sDbsCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.SAWFINISHING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 7)})
End If
Return ActiveMachiningsFamiliesList.ToArray
End Function
'''
''' Structure that represent a tool's family, containing family type and family name
'''
Structure MachiningsType
Friend TypeId As MCH_MY
Friend TypeName As String
End Structure
#End Region
End Class
End Namespace