Imports System.Collections.ObjectModel Imports EgtUILib Namespace EgtCAM5 Public Class MachiningTreeExpanderViewModel Inherits ViewModelBase #Region "FIELDS & PROPERTIES" Private m_CodeCommand As Boolean = False 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 If Not value And Not m_CodeCommand Then Application.Msn.NotifyColleagues(Application.CANCELOPERATIONCOMMAND) End If m_CodeCommand = False 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 ' Operazione correntemente selezionata, che permette di aggiungere al posto giusto quella nuova Private m_nSelectedOperationId As Integer = -1 Public ReadOnly Property MachListHdr As String Get Return EgtMsg(5412) ' Nuove Lavorazioni End Get End Property ' Definizione comandi Private m_cmdTreeViewDoubleClick As ICommand Private m_cmdCancelNew 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.UPDATEOPERATIONMACHININGLIST, Sub() m_MachiningsList.Clear() LoadSelectedMachineMachinings() End Sub) Application.Msn.Register(Application.MACHININGTREEVIEWEXPANDERISENABLED, Sub(bValue As Boolean) m_CodeCommand = True IsEnabled = bValue End Sub) Application.Msn.Register(Application.SELECTEDOPERATION, Sub(SelectedOperation As OperationListBoxItem) m_nSelectedOperationId = SelectedOperation.Id 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) 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(Machining.Type) & "_1", Machining.Name) ' Se è abilitata l'opzione If Not OptionModule.m_bNewMachiningIsLastOne Then ' Sposto la lavorazione aggiunta subito dopo quella appena selezionata EgtRelocate(MachiningId, m_nSelectedOperationId, GDB_POS.AFTER) End If ' 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) If SelectedEntities.Count = 1 AndAlso EgtGetType(SelectedEntities(0)) = GDB_TY.SRF_MESH Then Dim nF As Integer = EgtSurfTmFacetFromTria(SelectedEntities(0), IniFile.m_LastSubEntityId) If nF < 0 Then nF = 0 Dim SubEntityArray As Integer() = {nF} EgtSetMachiningGeometry(SelectedEntities.ToArray, SubEntityArray) Else ' Imposto il vettore come geometria di lavorazione EgtSetMachiningGeometry(SelectedEntities.ToArray) End If ' Calcolo la lavorazione con la nuova geometria EgtApplyMachining(True) EgtDraw() ' Ricarico la lista operazioni per avere quella nuova Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, -1) ' disabilito la modalità nuova lavorazione Application.Msn.NotifyColleagues(Application.NEWMACHININGMODEISACTIVE, New NewMachOpParam(False, MachiningId)) End If End Sub Private Function MachiningTypeToString(Type As Integer) 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 "Mach" End Select End Function #End Region ' TreeViewDoubleClickCommand #Region "CancelNewCommand" ''' ''' Returns a command that do TreeViewDoubleClick. ''' Public ReadOnly Property CancelNewCommand As ICommand Get If m_cmdCancelNew Is Nothing Then m_cmdCancelNew = New RelayCommand(AddressOf CancelNew) End If Return m_cmdCancelNew End Get End Property ''' ''' Execute the TreeViewDoubleClick. This method is invoked by the TreeViewDoubleClickCommand. ''' Public Sub CancelNew(ByVal param As Object) Application.Msn.NotifyColleagues(Application.CANCELOPERATIONCOMMAND) End Sub #End Region ' CancelNewCommand #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 = MachineModel.ReadActiveMachiningsFamilies() For Each MachiningsType In ActiveMachiningsTypes Dim FamilyTreeView As New FamilyMachiningTreeViewExpanderItem(MachiningsType.TypeName, MachiningsType.TypeId) MachiningsList.Add(FamilyTreeView) Dim MachiningName As String = String.Empty Dim MachiningToolName As String = String.Empty EgtMdbGetFirstMachining(MachiningsType.TypeId, MachiningName) While Not String.IsNullOrEmpty(MachiningName) EgtMdbSetCurrMachining(MachiningName) EgtMdbGetCurrMachiningParam(MCH_MP.TOOL, MachiningToolName) FamilyTreeView.Items.Add(New MachiningTreeViewExpanderItem(MachiningName, MachiningsType.TypeId, MachiningToolName)) EgtMdbGetNextMachining(MachiningsType.TypeId, MachiningName) End While 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 #End Region End Class End Namespace