Files
EgtCAM5/ProjectPage/OptionPanel/MachiningOptionPanel/OperationExpander/OperationExpanderViewModel.vb
T
Emmanuele Sassi 45cbfa745f EgtCAM5 :
- Miglioramenti Db utensili.
2016-08-06 20:05:40 +00:00

670 lines
23 KiB
VB.net

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
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 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
#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()
Me.IsExpanded = True
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"
''' <summary>
''' Returns a command that do Point.
''' </summary>
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
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
Public Sub NewMachiningCmd(ByVal param As Object)
NewMachining = True
End Sub
''' <summary>
''' Returns always true.
''' </summary>
Private Function CanNewMachining(ByVal param As Object) As Boolean
Return True
End Function
#End Region ' NewMachiningCommand
#Region "NewPositioningCommand"
''' <summary>
''' Returns a command that do Point.
''' </summary>
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
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
Public Sub NewPositioning(ByVal param As Object)
End Sub
''' <summary>
''' Returns always true.
''' </summary>
Private Function CanNewPositioning(ByVal param As Object) As Boolean
Return True
End Function
#End Region ' NewPositioningCommand
#Region "CancelOperationCommand"
''' <summary>
''' Returns a command that do Point.
''' </summary>
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
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
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
''' <summary>
''' Returns always true.
''' </summary>
Private Function CanCancelOperation(ByVal param As Object) As Boolean
Return True
End Function
#End Region ' CancelOperationCommand
#Region "MoveUpCommand"
''' <summary>
''' Returns a command that do Point.
''' </summary>
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
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
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à 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
''' <summary>
''' Returns always true.
''' </summary>
Private Function CanMoveUp(ByVal param As Object) As Boolean
Return True
End Function
#End Region ' MoveUpCommand
#Region "MoveDownCommand"
''' <summary>
''' Returns a command that do Point.
''' </summary>
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
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
Public Sub MoveDown(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 < 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
''' <summary>
''' Returns always true.
''' </summary>
Private Function CanMoveDown(ByVal param As Object) As Boolean
Return True
End Function
#End Region ' MoveDownCommand
#Region "ReloadMachiningCommand"
''' <summary>
''' Returns a command that do Point.
''' </summary>
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
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
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
''' <summary>
''' Returns always true.
''' </summary>
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