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 Private m_IsExpanded As Boolean Public Property IsExpanded As Boolean Get Return m_IsExpanded End Get Set(value As Boolean) If value <> m_IsExpanded Then m_IsExpanded = value OnPropertyChanged("IsExpanded") End If 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 ' 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 Dim x = 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 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 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 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 #End Region ' Definizione comandi Private m_cmdNewMachining As ICommand Private m_cmdNewPositioning As ICommand Private m_cmdCancelOperation As ICommand Private m_cmdMoveUp As ICommand Private m_cmdMoveDown As ICommand Private m_cmdReloadMachining As ICommand Sub New() Application.Msn.Register(Application.LOADOPERATIONLIST, Sub() LoadOperationList() 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) 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, AddressOf CanNewMachining) 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 ''' ''' Returns always true. ''' Private Function CanNewMachining(ByVal param As Object) As Boolean Return True End Function #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, AddressOf CanNewPositioning) 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 ''' ''' Returns always true. ''' Private Function CanNewPositioning(ByVal param As Object) As Boolean Return True End Function #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, AddressOf CanCancelOperation) 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) End If End If End Sub ''' ''' Returns always true. ''' Private Function CanCancelOperation(ByVal param As Object) As Boolean Return True End Function #End Region ' CancelOperationCommand #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(ByVal param As Object) 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à precedente a quella selezionata Dim PreviousId As Integer = OperationList(SelectedIndex - 1).Id ' Sposto l'entità selezionata EgtRelocate(SelectedOperation.Id, PreviousId, GDB_POS.BEFORE) ' Ricarico la lista delle operazioni Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST) ' Riseleziono l'entità selezionata Me.SelectedOperation = SelectedOperation 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(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) 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 "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 #End Region ' Methods End Class End Namespace