Imports System.Collections.ObjectModel
Imports EgtUILib
Namespace EgtCAM5
Public Class OperationExpanderViewModel
Inherits ViewModelBase
' Variabili che indicano per ogni tipo di lavorazione quale geometria è selezionabile
Private m_SelGeomSawing As SceneSelModeOpt
Private m_SelGeomDrilling As SceneSelModeOpt
Private m_SelGeomMilling As SceneSelModeOpt
Private m_SelGeomPocketing As SceneSelModeOpt
Private m_SelGeomMortising As SceneSelModeOpt
Private m_SelGeomSawRoughing As SceneSelModeOpt
Private m_SelGeomSawFinishing As SceneSelModeOpt
' 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 la selezione delle lavorazioni
Application.Msn.NotifyColleagues(Application.SETSCENESELTYPE, SceneSelTypeOpt.MACHINING)
' Abilito la selezione di curve e superfici
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, SceneSelModeOpt.PARTCURVESANDSURFACES)
' 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
' Disabilito e chiudo l'expander con l'albero delle lavorazioni
Application.Msn.NotifyColleagues(Application.MACHININGTREEVIEWEXPANDERISENABLED, False)
' Disabilito la selezione
Application.Msn.NotifyColleagues(Application.SETSCENESELTYPE, SceneSelTypeOpt.NULL)
' Disabilito la selezione di curve e superfici del pezzo
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, SceneSelModeOpt.NULL)
' Apro i parametri della lavorazione aggiunta
Dim Temp As OperationListBoxItem = SelectedOperation
SelectedOperation = Nothing
SelectedOperation = Temp
ParametersIsExpanded = True
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
Select Case SelectedOperation.m_Type
Case MCH_OY.DISP
' Abilito la selezione di tutti i tipi di geometria
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, SceneSelModeOpt.ALL)
' Verifico se c'è un grezzo nella disposizione corrente
Dim bFirstRaw As Boolean = True
Dim nCurrPhase As Integer = EgtGetCurrPhase()
Dim nRawPartId As Integer = EgtGetFirstRawPart()
While nRawPartId <> GDB_ID.NULL
If EgtVerifyRawPartPhase(nRawPartId, nCurrPhase) Then
bFirstRaw = False
Exit While
End If
nRawPartId = EgtGetNextRawPart(nRawPartId)
End While
' Lancio funzione che inizializza la disposizione
m_OpenDispositionFunction(bFirstRaw)
' Nascondo tutte le lavorazioni
Dim nOpId As Integer = EgtGetFirstOperation()
While nOpId <> GDB_ID.NULL
Dim nOpType As Integer = EgtGetOperationType(nOpId)
If nOpType = MCH_OY.DRILLING OrElse nOpType = MCH_OY.SAWING OrElse nOpType = MCH_OY.MILLING OrElse nOpType = MCH_OY.POCKETING OrElse nOpType = MCH_OY.MORTISING _
OrElse nOpType = MCH_OY.SAWROUGHING OrElse nOpType = MCH_OY.SAWFINISHING Then
EgtSetStatus(nOpId, GDB_ST.OFF)
End If
nOpId = EgtGetNextOperation(nOpId)
End While
EgtDraw()
Case MCH_OY.DRILLING, MCH_OY.SAWING, MCH_OY.MILLING, MCH_OY.MORTISING, MCH_OY.POCKETING, MCH_OY.SAWROUGHING, MCH_OY.SAWFINISHING
' Leggo il tipo di operazione per impostare il tipo di selezione
Dim OperationType As Integer = -1
EgtGetMachiningParam(MCH_MP.TYPE, OperationType)
' Abilito la selezione delle lavorazioni
Application.Msn.NotifyColleagues(Application.SETSCENESELTYPE, SceneSelTypeOpt.MACHINING)
' Abilito la selezione dei giusti tipi di geometria
Select Case OperationType
Case MCH_OY.SAWING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, m_SelGeomSawing)
Case MCH_OY.DRILLING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, m_SelGeomDrilling)
Case MCH_OY.MILLING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, m_SelGeomMilling)
Case MCH_OY.POCKETING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, m_SelGeomPocketing)
Case MCH_OY.MORTISING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, m_SelGeomMortising)
Case MCH_OY.SAWROUGHING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, m_SelGeomSawRoughing)
Case MCH_OY.SAWFINISHING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, m_SelGeomSawFinishing)
End Select
End Select
Else
If m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONLIST Then
ListIsExpanded = True
End If
If SelectedOperation.m_Type = MCH_OY.DISP Then
' Riattivo tutte le lavorazioni
Dim nOpId As Integer = EgtGetFirstOperation()
While nOpId <> GDB_ID.NULL
Dim nOpType As Integer = EgtGetOperationType(nOpId)
If nOpType = MCH_OY.DRILLING OrElse nOpType = MCH_OY.SAWING OrElse nOpType = MCH_OY.MILLING OrElse nOpType = MCH_OY.POCKETING OrElse nOpType = MCH_OY.MORTISING _
OrElse nOpType = MCH_OY.SAWROUGHING OrElse nOpType = MCH_OY.SAWFINISHING Then
EgtSetStatus(nOpId, GDB_ST.ON_)
End If
nOpId = EgtGetNextOperation(nOpId)
End While
EgtDraw()
End If
ParametersExpanderName = String.Empty
' Disabilito la selezione delle lavorazioni
Application.Msn.NotifyColleagues(Application.SETSCENESELTYPE, SceneSelTypeOpt.NULL)
' Resetto il tipo di selezione
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, SceneSelModeOpt.NULL)
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()
End If
' Imposto la fase di lavorazione corrente
Dim nPhase As Integer = EgtGetOperationPhase(value.Id)
If nPhase <> 0 Then
EgtSetCurrPhase(nPhase)
End If
' Verifico se l'operazione è una disposizione
If EgtGetOperationType(value.Id) = MCH_OY.DISP Then
'' Abilito la selezione delle Fixture
'Application.Msn.NotifyColleagues(Application.SETSCENESELTYPE, SceneSelTypeOpt.FIXTURE)
'' Abilito la selezione di tutti i tipi di geometria
'Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, SceneSelModeOpt.ALL)
' L'operazione è una lavorazione
Else
'' Disabilito la selezione di qualunque cosa
'Application.Msn.NotifyColleagues(Application.SETSCENESELTYPE, SceneSelTypeOpt.NULL)
' 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
' La salvo come ultima operazione selezionata
m_LastMarkedOperationId = value.Id
End If
m_SelectedOperation = value
' Notifico al contentcontrol OperationParameter di aggiornarsi
OnPropertyChanged("OperationParameters")
' Notifico l'operazione selezionata all'expander con l'albero delle lavorazioni aggiungibili
Application.Msn.NotifyColleagues(Application.SELECTEDOPERATION, value)
' Aggiorno visualizzazione
EgtDraw()
End If
End If
'OnPropertyChanged("ToolExpanderHeader")
OnPropertyChanged("SelectedOperation")
End Set
End Property
' Actions
Private m_UpdateParamValues As Action
Private m_OpenDispositionFunction As Action(Of Boolean)
Private m_MachiningParameterExpander As MachiningParameterExpanderView
Private m_DispositionParameterExpander As DispositionParameterExpanderView
Public ReadOnly Property OperationParameters As ContentControl
Get
If m_SelectedOperation.m_Type = MCH_OY.DISP Then
If IsNothing(m_DispositionParameterExpander) Then
m_DispositionParameterExpander = New DispositionParameterExpanderView
m_DispositionParameterExpander.DataContext = New DispositionParameterExpanderViewModel(m_OpenDispositionFunction)
End If
Return m_DispositionParameterExpander
Else
If IsNothing(m_MachiningParameterExpander) Then
m_MachiningParameterExpander = New MachiningParameterExpanderView
m_MachiningParameterExpander.DataContext = New MachiningParameterExpanderViewModel(m_UpdateParamValues)
End If
m_UpdateParamValues()
Return m_MachiningParameterExpander
End If
End Get
End Property
#Region "Messages"
Public ReadOnly Property OperationListHeader As String
Get
Return EgtMsg(MSG_OPERATION + 1)
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 MoveUpMsg As String
Get
Return EgtMsg(MSG_OPERATION + 8)
End Get
End Property
Public ReadOnly Property MoveDownMsg As String
Get
Return EgtMsg(MSG_OPERATION + 9)
End Get
End Property
Public ReadOnly Property UpdateMsg As String
Get
Return EgtMsg(MSG_OPERATION + 10)
End Get
End Property
#End Region ' Messages
' 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()
Dim Temp As Integer = 0
Temp = GetPrivateProfileInt(S_MACH, K_SELGEOMSAWING, -1)
m_SelGeomSawing = If(Temp < 0 Or Temp > 3, SceneSelModeOpt.PARTCURVESANDSURFACES, DirectCast(Temp, SceneSelModeOpt))
Temp = GetPrivateProfileInt(S_MACH, K_SELGEOMDRILLING, -1)
m_SelGeomDrilling = If(Temp < 0 Or Temp > 3, SceneSelModeOpt.PARTCURVESANDSURFACES, DirectCast(Temp, SceneSelModeOpt))
Temp = GetPrivateProfileInt(S_MACH, K_SELGEOMMILLING, -1)
m_SelGeomMilling = If(Temp < 0 Or Temp > 3, SceneSelModeOpt.PARTCURVESANDSURFACES, DirectCast(Temp, SceneSelModeOpt))
Temp = GetPrivateProfileInt(S_MACH, K_SELGEOMPOCKETING, -1)
m_SelGeomPocketing = If(Temp < 0 Or Temp > 3, SceneSelModeOpt.PARTCURVESANDSURFACES, DirectCast(Temp, SceneSelModeOpt))
Temp = GetPrivateProfileInt(S_MACH, K_SELGEOMMORTISING, -1)
m_SelGeomMortising = If(Temp < 0 Or Temp > 3, SceneSelModeOpt.PARTCURVESANDSURFACES, DirectCast(Temp, SceneSelModeOpt))
Temp = GetPrivateProfileInt(S_MACH, K_SELGEOMSAWROUGHING, -1)
m_SelGeomSawRoughing = If(Temp < 0 Or Temp > 3, SceneSelModeOpt.PARTCURVESANDSURFACES, DirectCast(Temp, SceneSelModeOpt))
Temp = GetPrivateProfileInt(S_MACH, K_SELGEOMSAWFINISHING, -1)
m_SelGeomSawFinishing = If(Temp < 0 Or Temp > 3, SceneSelModeOpt.PARTCURVESANDSURFACES, DirectCast(Temp, SceneSelModeOpt))
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
If NewMachining Then NewMachining = False
ListIsExpanded = False
ParametersIsExpanded = False
m_CurrExpandedExpander = MachiningOptionPanelExpander.SIMULATION
Else
' Deseleziono e riseleziono la lavorazione corrente per fargli riselezionare la geometria
' di lavorazione che è stata deselezionata dalla simulazione
Dim CurrSelectedOperation As OperationListBoxItem
CurrSelectedOperation = SelectedOperation
SelectedOperation = Nothing
SelectedOperation = CurrSelectedOperation
End If
End Sub)
Application.Msn.Register(Application.DRAWMODE_ISCHECKED, Sub()
If NewMachining Then NewMachining = False
End Sub)
Application.Msn.Register(Application.CANCELOPERATIONCOMMAND, Sub()
CancelOperation(String.Empty)
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)
' Recupero grezzi e bloccaggi dell'ultima fase
Dim nLastPhase As Integer = EgtGetPhaseCount()
EgtSetCurrPhase(nLastPhase)
Dim vRawId As New List(Of Integer)
Dim nRawId As Integer = EgtGetFirstRawPart()
While nRawId <> GDB_ID.NULL
If EgtVerifyRawPartPhase(nRawId, nLastPhase) Then
vRawId.Add(nRawId)
End If
nRawId = EgtGetNextRawPart(nRawId)
End While
Dim vFxtId As New List(Of Integer)
Dim nFxtId As Integer = EgtGetFirstFixture()
While nFxtId <> GDB_ID.NULL
vFxtId.Add(nFxtId)
nFxtId = EgtGetNextFixture(nFxtId)
End While
' Aggiungo la nuova fase
Dim nPhase As Integer = EgtAddPhase()
Dim nDispId As Integer = EgtGetPhaseDisposition(nPhase)
' Confermo grezzi e bloccaggi sopra salvati
For Each nId As Integer In vRawId
EgtKeepRawPart(nId, nLastPhase)
Next
For Each nId As Integer In vFxtId
EgtKeepFixture(nId, nLastPhase)
Next
' Ricarico la lista delle operazioni
Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, nDispId)
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)
' Se viene premuto il tasto Esc
If DirectCast(param, String) = "Escape" Then
If m_NewMachining Then
NewMachining = False
ListIsExpanded = True
End If
Return
End If
' Se sto inserendo una nuova lavorazione
If m_NewMachining Then
NewMachining = False
ListIsExpanded = True
' altrimenti sto cancellandone una vecchia
Else
If Not IsNothing(SelectedOperation) Then
' Salvo indice operazione precedente a selezionata
Dim nPrevOperId As Integer = EgtGetPrevOperation(SelectedOperation.Id)
If SelectedOperation.Type = MCH_OY.DISP Then
' Posso cancellare solo l'ultima disposizione
If EgtGetOperationPhase(SelectedOperation.Id) = EgtGetPhaseCount() Then
EgtRemoveLastPhase()
Else
Return
End If
Else
' Smarco e deseleziono la geometria selezionata
EgtResetMark(m_LastMarkedOperationId)
EgtDeselectAll()
EgtDraw()
' Rimuovo l'operazione selezionata
EgtRemoveOperation(SelectedOperation.Id)
End If
' Ricarico la lista delle operazioni
Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, nPrevOperId)
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)
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)
' Posso spostare solo se la precedente non è una disposizione (per non cambiare fase)
If OperationList(SelectedIndex - 1).Type = MCH_OY.DISP Then Return
' 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(SelectedId, 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
#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)
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
' Posso spostare solo se la successiva non è una disposizione (per non cambiare fase)
If OperationList(SelectedIndex + 1).Type = MCH_OY.DISP Then Return
' 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(SelectedId, 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
#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()
' Recupero fase corrente
Dim nCurrPhase As Integer = EgtGetCurrPhase()
' Ricalcolo la lavorazione per tutte le operazioni della lista
For Each Operation In OperationList
If Operation.Type = MCH_OY.DISP Then
EgtSetCurrPhase(EgtGetOperationPhase(Operation.Id))
Else
EgtSetCurrMachining(Operation.Id)
EgtApplyMachining(True)
End If
Next
' Ripristino la fase inizialmente corrente
EgtSetCurrPhase(nCurrPhase)
EgtDraw()
End Sub
#End Region ' UpdateCommand
#Region "ReloadMachiningCommand"
'''
''' Restituisce funzione per ricalcolo lavorazione.
'''
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
'''
''' Ricalcola una lavorazione.
'''
Public Sub ReloadMachining(ByVal param As Object)
' Aggiorno valore depth
SelectedOperation.NotifyPropertyChanged("Depth")
' 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
' Verifico se la geometria è cambiata, confrontando selezione attuale con geometria di lavorazione
Dim ModifiedGeometry As Boolean = False
Dim CountIndex As Integer = 0
EntityIndex = 0
Dim SubEntityIndex As Integer = 0 ' Sottocomponente, per ora non usato ma necessario
While EgtGetMachiningGeometry(CountIndex, EntityIndex, SubEntityIndex)
If SubEntityIndex = GDB_ID.NULL And CountIndex < SelectedGeometry.Count() Then
If SelectedGeometry(CountIndex) <> EntityIndex Then
ModifiedGeometry = True
Exit While
End If
Else
ModifiedGeometry = True
Exit While
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)
' 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 OpStatus As Boolean = True
Dim OpName As String = String.Empty
Dim OpType As Integer = 0
Dim OpTool As String = String.Empty
Dim OpMach 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)
OpStatus = EgtGetOperationMode(Id)
EgtGetMachiningParam(MCH_MP.TOOL, OpTool)
EgtGetMachiningParam(MCH_MP.NAME, OpMach)
OperationList.Add(New MachiningOpListBoxItem(Id, OpStatus, OpName, OpType, OpTool, OpMach))
Case MCH_OY.DISP
OpStatus = True
OpTool = String.Empty
OpMach = String.Empty
OperationList.Add(New DispositionOpListBoxItem(Id, OpName, OpType))
End Select
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