Imports System.Collections.ObjectModel Imports EgtUILib Public Class MachiningTreeExpanderVM Inherits ViewModelBase #Region "FIELDS & PROPERTIES" Friend 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 Map.refMachiningOptionPanelVM.Set_IsExpanded(MachiningOptionPanelVM.MachiningOptionPanelExpander.NEWMACHININGS, value) 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 Friend nSelectedOperationId As Integer = GDB_ID.NULL Public ReadOnly Property MachListHdr As String Get Return EgtMsg(MSG_OPERATION + 12) ' Nuove Lavorazioni End Get End Property ' Definizione comandi Private m_cmdTreeViewDoubleClick As ICommand Private m_cmdCancelNew As ICommand #End Region #Region "CONSTRUCTOR" Sub New() Map.SetRefMachiningTreeExpanderVM(Me) ' Per caricare l'albero la prima volta che viene aperto IsEnabled = False LoadSelectedMachineMachinings() 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 l'operazione non è andata a buon fine If MachiningId = GDB_ID.NULL Then ' Inserimento lavorazione non riuscito ERRORE MessageBox.Show(EgtMsg(MSG_OPERATION + 19), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error) Map.refOperationsListExpanderVM.CancelOperationCmd() Return End If ' Se è abilitata l'opzione If Not OptionModule.m_bNewMachiningIsLastOne Then ' Sposto la lavorazione aggiunta subito dopo quella appena selezionata EgtRelocate(MachiningId, 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) ' Gestione speciale per superfici ( si aggiunge l'identificazione della faccia) If SelectedEntities.Count() > 0 AndAlso EgtGetType(SelectedEntities(0)) = GDB_TY.SRF_MESH Then Dim vId() As Integer = Nothing Dim vSub() As Integer = Nothing SelData.GetAllIdSub(vId, vSub) EgtSetMachiningGeometry(vId, vSub) ' Gestione standard per altre entità (curve, regioni, ...) 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 Map.refOperationsListExpanderVM.LoadOperationList(MachiningId) ' disabilito la modalità nuova lavorazione Map.refOperationsListExpanderVM.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 MCH_MY.GENMACHINING Return EgtMsg(MSG_MACHININGSDBPAGE + 8) Case MCH_MY.CHISELING Return EgtMsg(MSG_MACHININGSDBPAGE + 9) Case MCH_MY.SURFROUGHING Return EgtMsg(MSG_MACHININGSDBPAGE + 10) Case MCH_MY.SURFFINISHING Return EgtMsg(MSG_MACHININGSDBPAGE + 11) Case MCH_MY.WATERJETTING Return EgtMsg(MSG_MACHININGSDBPAGE + 12) 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) Map.refOperationsListExpanderVM.CancelOperationCmd() End Sub #End Region ' CancelNewCommand #End Region ' Commands #Region "METHODS" Friend Function InitMachiningTreeExpander() As Boolean m_IsEnabled = True Map.refOperationParametersExpanderVM.OperParamsViewIsEnabled = False Map.refSimulationExpanderVM.Simulation_IsEnabled = False Map.refEstimationsExpanderVM.Estimation_IsEnabled = False ' Abilito la selezione delle geometrie di lavorazione Map.refProjectVM.SceneSelType = SceneSelTypeOpt.MACHINING ' Abilito la selezione di curve e superfici del pezzo Map.refProjectVM.SceneSelMode = SceneSelModeOpt.ALL CodeCommand = False OnPropertyChanged("IsEnabled") Return True End Function Friend Function ExitMachiningTreeExpander() As Boolean m_IsEnabled = False Map.refOperationParametersExpanderVM.OperParamsViewIsEnabled = True Map.refSimulationExpanderVM.Simulation_IsEnabled = True Map.refEstimationsExpanderVM.Estimation_IsEnabled = True If Not CodeCommand Then Map.refOperationsListExpanderVM.CancelOperationCmd() CodeCommand = False OnPropertyChanged("IsEnabled") Return False End If CodeCommand = False OnPropertyChanged("IsEnabled") Return True End Function ''' ''' 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 Friend Sub UpdateOperationMachiningList() m_MachiningsList.Clear() LoadSelectedMachineMachinings() End Sub #End Region End Class