Imports System.Collections.ObjectModel Imports EgtUILib Namespace EgtCAM5 Public Class OperationExpanderViewModel Inherits ViewModelBase ' Modalità di aggiunta attiva/disattiva Private m_NewMachining As Boolean = False Public Property NewMachining As Boolean Get Return m_NewMachining End Get Set(value As Boolean) If value <> m_NewMachining Then If value Then ' Smarco la geometria eventualmente marcata If Not IsNothing(m_LastMarkedOperationId) Then EgtResetMark(m_LastMarkedOperationId) ' Deseleziono eventuali geometrie selezionate EgtDeselectAll() EgtDraw() ' Blocco la lista operazioni IsEnabledOperationList = False ' Abilito ed apro l'expander con l'albero delle lavorazioni Application.Msn.NotifyColleagues(Application.MACHININGTREEVIEWEXPANDERISENABLED, True) Else ' Deseleziono eventuali geometrie selezionate EgtDeselectAll() EgtDraw() ' Sblocco la lista operazioni IsEnabledOperationList = True ' Disbilito e chiudo l'expander con l'albero delle lavorazioni Application.Msn.NotifyColleagues(Application.MACHININGTREEVIEWEXPANDERISENABLED, False) End If m_NewMachining = value End If End Set End Property Private m_NewPositioning As Boolean = False ' Ultima lavorazione evidenziata Private m_LastMarkedOperationId As Integer = GDB_ID.NULL 'Expander aperto tra quelli presenti nel MachiningOptionPanel Private m_CurrExpandedExpander As MachiningOptionPanelExpander = MachiningOptionPanelExpander.OPERATIONLIST Friend Enum MachiningOptionPanelExpander OPERATIONLIST OPERATIONPARAMETERS SIMULATION End Enum Private m_ListIsExpanded As Boolean Public Property ListIsExpanded As Boolean Get Return m_ListIsExpanded End Get Set(value As Boolean) If value <> m_ListIsExpanded Then m_ListIsExpanded = value If value Then If m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONPARAMETERS Then ParametersIsExpanded = False ElseIf m_CurrExpandedExpander = MachiningOptionPanelExpander.SIMULATION Then Application.Msn.NotifyColleagues(Application.SIMULATIONEXPANDER_SET_ISEXPANDED, False) End If m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONLIST End If OnPropertyChanged("ListIsExpanded") End If End Set End Property Private m_ParametersIsExpanded As Boolean Public Property ParametersIsExpanded As Boolean Get Return m_ParametersIsExpanded End Get Set(value As Boolean) If value <> m_ParametersIsExpanded Then m_ParametersIsExpanded = value If value Then If m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONLIST Then ListIsExpanded = False ElseIf m_CurrExpandedExpander = MachiningOptionPanelExpander.SIMULATION Then m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONPARAMETERS Application.Msn.NotifyColleagues(Application.SIMULATIONEXPANDER_SET_ISEXPANDED, False) End If ParametersExpanderName = m_SelectedOperation.Name m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONPARAMETERS Else If m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONLIST Then ListIsExpanded = True End If ParametersExpanderName = String.Empty End If OnPropertyChanged("ParametersIsExpanded") End If End Set End Property Private m_ParametersExpanderName As String Public Property ParametersExpanderName As String Get If String.IsNullOrEmpty(m_ParametersExpanderName) Then Return EgtMsg(MSG_OPERATION + 2) Else Return m_ParametersExpanderName End If End Get Set(value As String) If value <> m_ParametersExpanderName Then m_ParametersExpanderName = value End If OnPropertyChanged("ParametersExpanderName") End Set End Property Private m_IsEnabledOperationList As Boolean = True Public Property IsEnabledOperationList As Boolean Get Return m_IsEnabledOperationList End Get Set(value As Boolean) If value <> m_IsEnabledOperationList Then m_IsEnabledOperationList = value OnPropertyChanged("IsEnabledOperationList") End If End Set End Property Private m_OperationList As New ObservableCollection(Of OperationListBoxItem) Public Property OperationList As ObservableCollection(Of OperationListBoxItem) Get Return m_OperationList End Get Set(value As ObservableCollection(Of OperationListBoxItem)) m_OperationList = value End Set End Property Private m_SelectedOperation As OperationListBoxItem Public Property SelectedOperation As OperationListBoxItem Get Return m_SelectedOperation End Get Set(value As OperationListBoxItem) If value IsNot m_SelectedOperation Then If Not IsNothing(value) Then ' Verifico se c'è l'operazione precedente If m_LastMarkedOperationId <> GDB_ID.NULL Then ' La deevidenzio EgtResetMark(m_LastMarkedOperationId) ' Ne deseleziono la geometria EgtDeselectAll() EgtDraw() End If ' Verifico se l'operazione è una disposizione If EgtGetOperationType(value.Id) = MCH_OY.DISP Then ' L'operazione è una lavorazione Else ' Imposto come corrente la lavorazione(operazione) selezionata EgtSetCurrMachining(value.Id) ' Evidenzio la lavorazione(operazione) selezionata EgtSetMark(value.Id) ' Seleziono la geometria della lavorazione Dim CountIndex = 0 Dim EntityIndex As Integer = 0 Dim SubEntityIndex As Integer = 0 ' Nell'interfaccia non si usa ma devo comunque definirla perchè la funzione la restituisce obbligatoriamente While EgtGetMachiningGeometry(CountIndex, EntityIndex, SubEntityIndex) If SubEntityIndex = GDB_ID.NULL Then EgtSelectObj(EntityIndex) End If CountIndex += 1 End While EgtDraw() ' La salvo come ultima operazione selezionata m_LastMarkedOperationId = value.Id ' Notifico l'operazione selezionata all'expander dei parametri operazione Application.Msn.NotifyColleagues(Application.SELECTEDOPERATION, value) End If End If m_SelectedOperation = value End If OnPropertyChanged("SelectedOperation") End Set End Property #Region "Messaggi per parametri operazioni" Public ReadOnly Property InvertTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 51) End Get End Property Public ReadOnly Property DepthTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 99) End Get End Property Public ReadOnly Property WorkSideTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 54) End Get End Property Public ReadOnly Property UserNotesTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 100) End Get End Property Public ReadOnly Property UserNotesTooltip As String Get Return SelectedOperation.UserNotes End Get End Property Public ReadOnly Property StartPosTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 73) End Get End Property Public ReadOnly Property OverLapTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 101) End Get End Property Public ReadOnly Property ThrouAddLenTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 76) End Get End Property Public ReadOnly Property StepTypeTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 60) End Get End Property Public ReadOnly Property StepParTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 77) End Get End Property Public ReadOnly Property StartSlowLenTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 74) End Get End Property Public ReadOnly Property EndSlowLenTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 75) End Get End Property Public ReadOnly Property SideAngleTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 71) End Get End Property Public ReadOnly Property OffsetSrTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 68) End Get End Property Public ReadOnly Property OffsetSlTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 69) End Get End Property Public ReadOnly Property LeadInTypeTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 56) End Get End Property Public ReadOnly Property StartAddLenTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 91) End Get End Property Public ReadOnly Property LiTangTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 83) End Get End Property Public ReadOnly Property LiPerpTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 84) End Get End Property Public ReadOnly Property LiElevTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 85) End Get End Property Public ReadOnly Property LiCompLenTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 86) End Get End Property Public ReadOnly Property LeadOutTypeTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 58) End Get End Property Public ReadOnly Property EndAddLenTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 92) End Get End Property Public ReadOnly Property LoTangTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 87) End Get End Property Public ReadOnly Property LoPerpTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 88) End Get End Property Public ReadOnly Property LoElevTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 89) End Get End Property Public ReadOnly Property LoCompLenTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 90) End Get End Property Public ReadOnly Property LeaveTabTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 52) End Get End Property Public ReadOnly Property TabLenTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 79) End Get End Property Public ReadOnly Property TabHeightTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 80) End Get End Property Public ReadOnly Property TabAngleTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 81) End Get End Property Public ReadOnly Property TabDistTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 82) End Get End Property Public ReadOnly Property SpeedTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 63) End Get End Property Public ReadOnly Property FeedTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 64) End Get End Property Public ReadOnly Property TipFeedTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 67) End Get End Property Public ReadOnly Property StartFeedTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 65) End Get End Property Public ReadOnly Property EndFeedTxBl As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 66) End Get End Property Public ReadOnly Property OperationListHeader As String Get Return EgtMsg(MSG_OPERATION + 1) End Get End Property Public ReadOnly Property ApplyMachiningBtnContent As String Get Return EgtMsg(MSG_OPERATION + 3) End Get End Property Public ReadOnly Property NewMachiningBtnContent As String Get Return EgtMsg(MSG_OPERATION + 4) End Get End Property Public ReadOnly Property NewPositioningBtnContent As String Get Return EgtMsg(MSG_OPERATION + 5) End Get End Property Public ReadOnly Property CancelOperationBtnContent As String Get Return EgtMsg(MSG_OPERATION + 6) End Get End Property Public ReadOnly Property GenericExpanderHeader As String Get Return EgtMsg(MSG_OPERATION + 7) End Get End Property Public ReadOnly Property ToolExpanderHeader As String Get Return EgtMsg(MSG_MACHININGSDBPAGE + 98) End Get End Property #End Region ' Definizione comandi Private m_cmdNewMachining As ICommand Private m_cmdNewPositioning As ICommand Private m_cmdCancelOperation As ICommand Private m_cmdOperationListDoubleClick As ICommand Private m_cmdMoveUp As ICommand Private m_cmdMoveDown As ICommand Private m_cmdUpdate As ICommand Private m_cmdReloadMachining As ICommand Sub New() Me.ListIsExpanded = True Application.Msn.Register(Application.LOADOPERATIONLIST, Sub(nSelectedOperation As Integer) LoadOperationList() SelectOperation(nSelectedOperation) ListIsExpanded = True End Sub) Application.Msn.Register(Application.REMOVEMARKFROMLASTOPERATION, Sub() EgtResetMark(m_LastMarkedOperationId) End Sub) Application.Msn.Register(Application.NEWMACHININGMODEISACTIVE, Sub(bValue As Boolean) NewMachining = bValue End Sub) Application.Msn.Register(Application.SIMULATIONEXPANDER_GET_ISEXPANDED, Sub(bValue As Boolean) If m_CurrExpandedExpander = MachiningOptionPanelExpander.SIMULATION Then ListIsExpanded = True End If If bValue Then ListIsExpanded = False ParametersIsExpanded = False m_CurrExpandedExpander = MachiningOptionPanelExpander.SIMULATION End If End Sub) End Sub #Region "COMMANDS" #Region "NewMachiningCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property NewMachiningCommand As ICommand Get If m_cmdNewMachining Is Nothing Then m_cmdNewMachining = New RelayCommand(AddressOf NewMachiningCmd) End If Return m_cmdNewMachining End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub NewMachiningCmd(ByVal param As Object) NewMachining = True End Sub #End Region ' NewMachiningCommand #Region "NewPositioningCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property NewPositioningCommand As ICommand Get If m_cmdNewPositioning Is Nothing Then m_cmdNewPositioning = New RelayCommand(AddressOf NewPositioning) End If Return m_cmdNewPositioning End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub NewPositioning(ByVal param As Object) End Sub #End Region ' NewPositioningCommand #Region "CancelOperationCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property CancelOperationCommand As ICommand Get If m_cmdCancelOperation Is Nothing Then m_cmdCancelOperation = New RelayCommand(AddressOf CancelOperation) End If Return m_cmdCancelOperation End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub CancelOperation(ByVal param As Object) If m_NewMachining Then NewMachining = False Else If Not IsNothing(SelectedOperation) Then ' Smarco e deseleziono la geometria selezionata EgtResetMark(m_LastMarkedOperationId) EgtDeselectAll() EgtDraw() ' Rimuovo l'operazione selezionata EgtRemoveOperation(SelectedOperation.Id) ' Ricarico la lista delle operazioni Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, -1) End If End If End Sub #End Region ' CancelOperationCommand #Region "OperationListDoubleClickCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property OperationListDoubleClickCommand As ICommand Get If m_cmdOperationListDoubleClick Is Nothing Then m_cmdOperationListDoubleClick = New RelayCommand(AddressOf OperationListDoubleClick) End If Return m_cmdOperationListDoubleClick End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub OperationListDoubleClick() ParametersIsExpanded = True End Sub #End Region ' OperationListDoubleClickCommand #Region "MoveUpCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property MoveUpCommand As ICommand Get If m_cmdMoveUp Is Nothing Then m_cmdMoveUp = New RelayCommand(AddressOf MoveUp, AddressOf CanMoveUp) End If Return m_cmdMoveUp End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub MoveUp() If Not IsNothing(SelectedOperation) Then ' Verifico se l'entità selezionata è una lavorazione o una disposizione, ' se è una disposizione esco perchè non si possono spostare If SelectedOperation.Type = MCH_OY.DISP Then Return ' Trovo indice dell'entità selezionata Dim SelectedIndex As Integer = OperationList.IndexOf(SelectedOperation) ' Verifico che l'indice sia >= 2 perchè il primo è e deve essere una disposizione If SelectedIndex < 2 Then Return End If ' Recupero Id entità selezionata e precedente a quella selezionata Dim SelectedId As Integer = OperationList(SelectedIndex).Id Dim PreviousId As Integer = OperationList(SelectedIndex - 1).Id ' Sposto l'operazione selezionata nell'ambiente Egt If EgtRelocate(SelectedOperation.Id, PreviousId, GDB_POS.BEFORE) Then ' Sposto l'operazione selezionata nella grafica OperationList.Move(SelectedIndex, SelectedIndex - 1) ' Ricalcolo la lavorazione selezionata e la precedente EgtSetCurrMachining(PreviousId) EgtApplyMachining(False) EgtSetCurrMachining(SelectedId) EgtApplyMachining(False) EgtDraw() End If End If End Sub ''' ''' Returns always true. ''' Private Function CanMoveUp(ByVal param As Object) As Boolean Return True End Function #End Region ' MoveUpCommand #Region "MoveDownCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property MoveDownCommand As ICommand Get If m_cmdMoveDown Is Nothing Then m_cmdMoveDown = New RelayCommand(AddressOf MoveDown, AddressOf CanMoveDown) End If Return m_cmdMoveDown End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub MoveDown() If Not IsNothing(SelectedOperation) Then ' Verifico se l'entità selezionata è una lavorazione o una disposizione, ' se è una disposizione esco perchè non si possono spostare If SelectedOperation.Type = MCH_OY.DISP Then Return ' Trovo indice dell'entità selezionata Dim SelectedIndex As Integer = OperationList.IndexOf(SelectedOperation) ' Verifico che l'indice sia < della lunghezza della lista delle operazioni,altrimenti è già ultima e quindi non la posso spostare If SelectedIndex > OperationList.Count - 2 Then Return End If ' Recupero Id entitàselezionata e successiva a quella selezionata Dim SelectedId As Integer = OperationList(SelectedIndex).Id Dim PostId As Integer = OperationList(SelectedIndex + 1).Id ' Sposto l'operazione selezionata nell'ambiente Egt If EgtRelocate(SelectedOperation.Id, PostId, GDB_POS.AFTER) Then ' Sposto l'operazione selezionata nella grafica OperationList.Move(SelectedIndex, SelectedIndex + 1) ' Ricalcolo la lavorazione selezionata e la successiva EgtSetCurrMachining(SelectedId) EgtApplyMachining(False) EgtSetCurrMachining(PostId) EgtApplyMachining(False) EgtDraw() End If End If End Sub ''' ''' Returns always true. ''' Private Function CanMoveDown(ByVal param As Object) As Boolean Return True End Function #End Region ' MoveDownCommand #Region "UpdateCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property UpdateCommand As ICommand Get If m_cmdUpdate Is Nothing Then m_cmdUpdate = New RelayCommand(AddressOf Update) End If Return m_cmdUpdate End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub Update() ' Ricalcolo la lavorazione per tutte le operazioni della lista, saltando le disposizioni For Each Operation In OperationList If Not Operation.Type = MCH_OY.DISP Then EgtSetCurrMachining(Operation.Id) EgtApplyMachining(True) End If Next EgtDraw() End Sub #End Region ' UpdateCommand #Region "ReloadMachiningCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property ReloadMachiningCommand As ICommand Get If m_cmdReloadMachining Is Nothing Then m_cmdReloadMachining = New RelayCommand(AddressOf ReloadMachining, AddressOf CanReloadMachining) End If Return m_cmdReloadMachining End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub ReloadMachining(ByVal param As Object) ' Verifico se la geometria è cambiata ' Parametro che indica se ci sono state modifiche Dim ModifiedGeometry As Boolean = False ' Carico tutta la geometria selezionata in una lista Dim SelectedGeometry As New List(Of Integer) Dim EntityIndex As Integer = EgtGetFirstSelectedObj() While EntityIndex <> GDB_ID.NULL SelectedGeometry.Add(EntityIndex) EntityIndex = EgtGetNextSelectedObj() End While ' Carico un elemento della geometria di lavorazione Dim CountIndex = 0 EntityIndex = 0 Dim SubEntityIndex As Integer = 0 ' Nell'interfaccia non si usa ma devo comunque definirla perchè la funzione la restituisce obbligatoriamente While EgtGetMachiningGeometry(CountIndex, EntityIndex, SubEntityIndex) If SubEntityIndex = GDB_ID.NULL Then If SelectedGeometry.IndexOf(EntityIndex) < 0 Then ModifiedGeometry = True Exit While End If End If CountIndex += 1 End While If SelectedGeometry.Count <> CountIndex Then ModifiedGeometry = True End If ' Imposto geometria selezionata come geometria di lavorazione If ModifiedGeometry Then EgtSetMachiningGeometry(SelectedGeometry.ToArray) ' Verifico se i parametri sono cambiati ' Se necessario ricalcolo la lavorazione EgtApplyMachining(ModifiedGeometry) EgtDraw() End Sub ''' ''' Returns always true. ''' Private Function CanReloadMachining(ByVal param As Object) As Boolean Return True End Function #End Region ' ReloadMachiningCommand #End Region ' Commands #Region "METHODS" Private Sub LoadOperationList() OperationList.Clear() Dim Id As Integer Dim OpName As String = String.Empty Dim OpType As Integer = 0 Dim OpTool As String = String.Empty Id = EgtGetFirstOperation() While Id <> GDB_ID.NULL EgtGetOperationName(Id, OpName) OpType = EgtGetOperationType(Id) Select Case OpType Case MCH_OY.DRILLING, MCH_OY.SAWING, MCH_OY.MILLING, MCH_OY.POCKETING, MCH_OY.MORTISING, MCH_OY.SAWROUGHING, MCH_OY.SAWFINISHING EgtSetCurrMachining(Id) EgtGetMachiningParam(MCH_MP.TOOL, OpTool) Case MCH_OY.DISP OpTool = String.Empty End Select OperationList.Add(New OperationListBoxItem(Id, OpName, OpType, OpTool)) Id = EgtGetNextOperation(Id) End While End Sub Private Sub SelectOperation(nSelectedOperation As Integer) If nSelectedOperation < 0 Then SelectedOperation = OperationList(0) Else Dim OperationFound = False For Each Operation In OperationList If Operation.Id = nSelectedOperation Then OperationFound = True SelectedOperation = Operation Exit For End If Next If Not OperationFound Then SelectedOperation = OperationList(0) End If End If End Sub #End Region ' Methods End Class End Namespace