Files
EgtCAM5/OptionPanel/MachiningOptionPanel/OperationExpander/OperationExpanderViewModel.vb
T
Emmanuele Sassi a4b5cd4834 EgtCAM5 :
- Cambiati nomi classi e file.
2018-04-10 17:08:35 +00:00

857 lines
39 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Namespace EgtCAM5
Public Class OperationExpanderViewModel
Inherits ViewModelBase
' Modalità di aggiunta attiva/disattiva
Private m_NewMachining As Boolean = False
Private Sub StartNewMachining()
m_NewMachining = True
' Smarco la geometria eventualmente marcata
If Not IsNothing(m_LastMarkedOperationId) Then EgtResetMark(EgtGetFirstNameInGroup(m_LastMarkedOperationId, MCH_MGR_CL))
' Deseleziono eventuali geometrie selezionate
EgtDeselectAll()
EgtDraw()
' Blocco la lista operazioni
IsEnabledOperationList = False
' Abilito la selezione delle geometrie da lavorare
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)
End Sub
Private Sub EndNewMachining(SelOpId As Integer)
' 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
If SelOpId <> GDB_ID.NULL Then
For Index = 0 To OperationList.Count - 1
If OperationList(Index).Id = SelOpId Then
SelectedOperation = OperationList(Index)
End If
Next
End If
ParametersIsExpanded = True
m_NewMachining = False
End Sub
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_OperViewIsEnabled As Boolean = True
Public Property OperViewIsEnabled As Boolean
Get
Return m_OperViewIsEnabled
End Get
Set(value As Boolean)
m_OperViewIsEnabled = value
OnPropertyChanged("OperViewIsEnabled")
End Set
End Property
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
m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONPARAMETERS
If IsValidDispositionType(SelectedOperation.m_Type) Then
ParametersExpanderName = m_SelectedOperation.Name
' 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 nRawPartId As Integer = EgtGetFirstRawPart()
While nRawPartId <> GDB_ID.NULL
If EgtVerifyRawPartCurrPhase(nRawPartId) 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
If IsValidMachiningType(EgtGetOperationType(nOpId)) Then
EgtSetOperationStatus(nOpId, False)
End If
nOpId = EgtGetNextOperation(nOpId)
End While
EgtDraw()
ElseIf IsValidMachiningType(SelectedOperation.m_Type) Then
' Leggo il tipo di operazione per impostare il tipo di selezione
EgtSetCurrMachining(SelectedOperation.m_Id)
Dim sOpMach As String = String.Empty
EgtGetMachiningParam(MCH_MP.NAME, sOpMach)
ParametersExpanderName = m_SelectedOperation.Name & " (" & sOpMach & ")"
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, OptionModule.m_SelGeomSawing)
Case MCH_OY.DRILLING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, OptionModule.m_SelGeomDrilling)
Case MCH_OY.MILLING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, OptionModule.m_SelGeomMilling)
Case MCH_OY.POCKETING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, OptionModule.m_SelGeomPocketing)
Case MCH_OY.MORTISING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, OptionModule.m_SelGeomMortising)
Case MCH_OY.SAWROUGHING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, OptionModule.m_SelGeomSawRoughing)
Case MCH_OY.SAWFINISHING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, OptionModule.m_SelGeomSawFinishing)
Case MCH_OY.GENMACHINING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, OptionModule.m_SelGeomGenMachining)
Case MCH_OY.CHISELING
Application.Msn.NotifyColleagues(Application.SETSCENESELMODE, OptionModule.m_SelGeomChiseling)
End Select
' Imposto visualizzazione utensile
DirectCast(m_MachiningParameterExpander.DataContext, MachiningParameterExpanderViewModel).ViewTool = True
End If
Else
If m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONLIST Then
ListIsExpanded = True
End If
If SelectedOperation.m_Type = MCH_OY.DISP Then
' Visualizzo tutte le lavorazioni della fase corrente
Dim nCurrPhase = EgtGetCurrPhase()
Dim nOpId As Integer = EgtGetFirstOperation()
While nOpId <> GDB_ID.NULL
If IsValidMachiningType(EgtGetOperationType(nOpId)) Then
EgtSetOperationStatus(nOpId, (EgtGetOperationPhase(nOpId) = nCurrPhase))
End If
nOpId = EgtGetNextOperation(nOpId)
End While
EgtDraw()
Else
' Nascondo visualizzazione utensile
DirectCast(m_MachiningParameterExpander.DataContext, MachiningParameterExpanderViewModel).ViewTool = False
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
Application.Msn.NotifyColleagues(Application.EMITTITLE)
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 Not IsNothing(value) Then
' Verifico se c'è l'operazione precedente
If m_LastMarkedOperationId <> GDB_ID.NULL Then
' La de-evidenzio
Dim bEnabModif As Boolean = EgtGetEnableModified()
EgtDisableModified()
EgtResetMark(EgtGetFirstNameInGroup(m_LastMarkedOperationId, MCH_MGR_CL))
If bEnabModif Then EgtEnableModified()
' Ne deseleziono la geometria
EgtDeselectAll()
End If
' Imposto la fase di lavorazione corrente
EgtSetCurrPhase(EgtGetOperationPhase(value.Id))
' 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)
Dim bEnabModif As Boolean = EgtGetEnableModified()
EgtDisableModified()
EgtSetMark(EgtGetFirstNameInGroup(value.Id, MCH_MGR_CL))
If bEnabModif Then EgtEnableModified()
' 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)
EgtSelectObj(EntityIndex)
IniFile.m_LastSubEntityId = SubEntityIndex
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
'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
Public ReadOnly Property SetUpMsg As String
Get
Return EgtMsg(MSG_SETUP + 1)
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_cmdSetUp 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(EgtGetFirstNameInGroup(m_LastMarkedOperationId, MCH_MGR_CL))
End Sub)
Application.Msn.Register(Application.NEWMACHININGMODEISACTIVE, Sub(Params As NewMachOpParam)
If Params.bActive Then
StartNewMachining()
Else
EndNewMachining(Params.SelMachOpId)
End If
End Sub)
Application.Msn.Register(Application.OPERATIONVIEWEXPANDERISENABLED, Sub(bEnable As Boolean)
OperViewIsEnabled = bEnable
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 m_NewMachining Then EndNewMachining(GDB_ID.NULL)
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()
' Annullo creazione nuova lavorazione
If m_NewMachining Then EndNewMachining(GDB_ID.NULL)
' Disabilito visualizzazione utensile
If Not IsNothing(m_MachiningParameterExpander) Then
DirectCast(m_MachiningParameterExpander.DataContext, MachiningParameterExpanderViewModel).ViewTool = False
End If
End Sub)
Application.Msn.Register(Application.CANCELOPERATIONCOMMAND, Sub()
CancelOperation(String.Empty)
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)
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)
StartNewMachining()
End Sub
#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)
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)
' 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"
''' <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)
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)
' Se viene premuto il tasto Esc
If DirectCast(param, String) = "Escape" Then
If m_NewMachining Then
EndNewMachining(GDB_ID.NULL)
ListIsExpanded = True
End If
Return
End If
' Se sto inserendo una nuova lavorazione
If m_NewMachining Then
EndNewMachining(GDB_ID.NULL)
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(EgtGetFirstNameInGroup(m_LastMarkedOperationId, MCH_MGR_CL))
EgtDeselectAll()
EgtDraw()
' Rimuovo l'operazione selezionata
EgtRemoveOperation(SelectedOperation.Id)
End If
' Ricarico la lista delle operazioni
Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, nPrevOperId)
End If
Application.Msn.NotifyColleagues(Application.EMITTITLE)
End If
End Sub
#End Region ' CancelOperationCommand
#Region "OperationListDoubleClickCommand"
''' <summary>
''' Returns a command that do Point.
''' </summary>
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
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
Public Sub OperationListDoubleClick()
If EgtGetOperationMode(SelectedOperation.Id) Then
ParametersIsExpanded = True
End If
End Sub
#End Region ' OperationListDoubleClickCommand
#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)
End If
Return m_cmdMoveUp
End Get
End Property
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
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
Application.Msn.NotifyColleagues(Application.EMITTITLE)
End If
End Sub
#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)
End If
Return m_cmdMoveDown
End Get
End Property
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
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
Application.Msn.NotifyColleagues(Application.EMITTITLE)
End If
End Sub
#End Region ' MoveDownCommand
#Region "UpdateCommand"
''' <summary>
''' Returns a command that do Point.
''' </summary>
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
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
Public Sub Update()
' Cursore di attesa
Application.Current.MainWindow.ForceCursor = True
Application.Current.MainWindow.Cursor = Cursors.Wait
' Eseguo ricalcolo
Dim bRecalc As Boolean = ((Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift)
Dim sErr As String = String.Empty
Dim bOk As Boolean = EgtApplyAllMachinings(bRecalc, False, sErr)
EgtSetModified()
' Aggiorno visualizzazione e ritorno a cursore standard
EgtDraw()
Application.Current.MainWindow.ForceCursor = False
Application.Current.MainWindow.Cursor = Cursors.Arrow
' In caso di errori, li segnalo
If Not bOk Then
If Not String.IsNullOrEmpty(sErr) Then
MessageBox.Show(sErr, EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Exclamation)
Else
MessageBox.Show(EgtMsg(MSG_SIMULATION + 6), EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Else
Application.Msn.NotifyColleagues(Application.NOTIFYSTATUSOUTPUT, EgtMsg(MSG_OPERATION + 11))
End If
Application.Msn.NotifyColleagues(Application.EMITTITLE)
End Sub
#End Region ' UpdateCommand
#Region "SetUpCommand"
''' <summary>
''' Returns a command that do Point.
''' </summary>
Public ReadOnly Property SetUpCommand As ICommand
Get
If m_cmdSetUp Is Nothing Then
m_cmdSetUp = New RelayCommand(AddressOf SetUp)
End If
Return m_cmdSetUp
End Get
End Property
''' <summary>
''' Execute the Point. This method is invoked by the PointCommand.
''' </summary>
Public Sub SetUp()
' verifico che il file di configurazione attrezzaggio (lua) della macchina esista
If Not File.Exists(IniFile.m_sCurrMachScriptsDirPath & "\" & SETUP_LUA) Then
EgtOutLog("SetUp error: SetUp configuration file doesn't exist ")
MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 7), EgtMsg(MSG_SETUPERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
' carico Lua che contiene le funzioni per ottenere le posizioni valide dell'utensile selezionato,
' e testa e uscita dell'utensile attrezzato
EgtLuaExecFile(IniFile.m_sCurrMachScriptsDirPath & "\" & SETUP_LUA)
' verifico che le teste riportate in configurazione esistano
Dim Index As Integer = 1
Dim nErr As Integer = 0
While nErr = 0
Dim sHead As String = String.Empty
nErr = 999
EgtLuaSetGlobIntVar("STU.INDEX", Index)
EgtLuaCallFunction("STU.GetTcPosHeadGroupFromPos")
' Leggo variabili
EgtLuaGetGlobStringVar("STU.HEAD", sHead)
EgtLuaGetGlobIntVar("STU.ERR", nErr)
If nErr = 0 Then
If EgtGetHeadExitCount(sHead) = 0 Then
MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 8), EgtMsg(MSG_SETUPERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
End If
Index += 1
End While
' creo ed apro finestra SetUp
Dim SetUpWindow As New SetUpWindowV
SetUpWindow.Height = 614
SetUpWindow.Width = 1024
SetUpWindow.DataContext = New SetUpWindowVM
SetUpWindow.Owner = Application.Current.MainWindow
SetUpWindow.ShowDialog()
Application.Msn.NotifyColleagues(Application.EMITTITLE)
End Sub
#End Region ' SetUpCommand
#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)
If IsValidMachiningType(OpType) Then
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))
ElseIf IsValidDispositionType(OpType) Then
OpStatus = True
OpTool = String.Empty
OpMach = String.Empty
OperationList.Add(New DispositionOpListBoxItem(Id, OpName, OpType))
End If
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