Imports System.Collections.ObjectModel Imports System.IO Imports EgtUILib Public Class OperationExpanderVM Inherits ViewModelBase ' Modalità di aggiunta attiva/disattiva Private m_NewMachining As Boolean = False Private Sub StartNewMachining() m_NewMachining = True ' Smarco e deseleziono le geometrie If Not IsNothing(m_LastMarkedOperationId) Then EgtResetMark(EgtGetFirstNameInGroup(m_LastMarkedOperationId, MCH_MGR_CL)) EgtDeselectAll() EgtDraw() ' Reset lista facce SelData.ClearIdSub() ' 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 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 ESTIMATIONS 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) ElseIf m_CurrExpandedExpander = MachiningOptionPanelExpander.ESTIMATIONS Then Application.Msn.NotifyColleagues(Application.ESTIMATIONSEXPANDER_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) ElseIf m_CurrExpandedExpander = MachiningOptionPanelExpander.ESTIMATIONS Then m_CurrExpandedExpander = MachiningOptionPanelExpander.OPERATIONPARAMETERS Application.Msn.NotifyColleagues(Application.ESTIMATIONSEXPANDER_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, MachiningParameterExpanderVM).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, MachiningParameterExpanderVM).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 ' Imposto come corrente la lavorazione selezionata EgtSetCurrMachining(value.Id) ' Evidenzio la lavorazione(operazione) selezionata Dim bEnabModif As Boolean = EgtGetEnableModified() EgtDisableModified() EgtSetMark(EgtGetFirstNameInGroup(value.Id, MCH_MGR_CL)) If bEnabModif Then EgtEnableModified() ' Seleziono la geometria della lavorazione SelData.ClearIdSub() Dim CountIndex As Integer = 0 Dim EntityIndex As Integer = 0 Dim SubEntityIndex As Integer = 0 While EgtGetMachiningGeometry(CountIndex, EntityIndex, SubEntityIndex) EgtSelectObj(EntityIndex) If EgtGetType(EntityIndex) = GDB_TY.SRF_MESH Then SelData.AddIdSub(EntityIndex, SubEntityIndex) 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 'OnPropertyChanged("ToolExpanderHeader") OnPropertyChanged("SelectedOperation") OnPropertyChanged("DuplicateCmd_IsEnabled") OnPropertyChanged("MachToDb_IsEnabled") End Set End Property Public ReadOnly Property DuplicateCmd_IsEnabled As Boolean Get Return Not m_SelectedOperation.Type = MCH_OY.DISP End Get End Property Public ReadOnly Property MachToDb_IsEnabled As Boolean Get Return Not m_SelectedOperation.Type = MCH_OY.DISP End Get End Property Public ReadOnly Property OperationParameters As ContentControl Get If m_SelectedOperation.m_Type = MCH_OY.DISP Then If IsNothing(m_DispositionParameterExpander) Then m_DispositionParameterExpander = New DispositionParameterExpanderV m_DispositionParameterExpander.DataContext = New DispositionParameterExpanderVM(m_OpenDispositionFunction) End If Return m_DispositionParameterExpander Else If IsNothing(m_MachiningParameterExpander) Then m_MachiningParameterExpander = New MachiningParameterExpanderV m_MachiningParameterExpander.DataContext = New MachiningParameterExpanderVM(m_UpdateParamValues) End If m_UpdateParamValues() Return m_MachiningParameterExpander End If End Get End Property ' Actions Private m_UpdateParamValues As Action Private m_OpenDispositionFunction As Action(Of Boolean) Private m_MachiningParameterExpander As MachiningParameterExpanderV Private m_DispositionParameterExpander As DispositionParameterExpanderV #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 Public ReadOnly Property DuplicateMachMsg As String Get Return EgtMsg(MSG_OPERATION + 16) End Get End Property Public ReadOnly Property MachToDbMsg As String Get Return EgtMsg(MSG_OPERATION + 17) 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 Private m_cmdDuplicateMach As ICommand Private m_cmdMachToDb 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.ESTIMATIONEXPANDER_GET_ISEXPANDED, Sub(bValue As Boolean) If m_CurrExpandedExpander = MachiningOptionPanelExpander.ESTIMATIONS Then ListIsExpanded = True End If If bValue Then If m_NewMachining Then EndNewMachining(GDB_ID.NULL) ListIsExpanded = False ParametersIsExpanded = False m_CurrExpandedExpander = MachiningOptionPanelExpander.ESTIMATIONS 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, MachiningParameterExpanderVM).ViewTool = False End If 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) StartNewMachining() 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 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" ''' ''' 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() If EgtGetOperationMode(SelectedOperation.Id) Then ParametersIsExpanded = True End If 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 Application.Msn.NotifyColleagues(Application.EMITTITLE) 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 Application.Msn.NotifyColleagues(Application.EMITTITLE) 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() ' 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" ''' ''' Returns a command that do Point. ''' 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 ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' 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 #Region "DuplicateMachCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property DuplicateMachCommand As ICommand Get If m_cmdDuplicateMach Is Nothing Then m_cmdDuplicateMach = New RelayCommand(AddressOf DuplicateMach) End If Return m_cmdDuplicateMach End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub DuplicateMach() ' Verifico che l'operazione selezionata sia una lavorazione If IsNothing(m_SelectedOperation) Or m_SelectedOperation.m_Type = MCH_OY.NONE Or m_SelectedOperation.m_Type = MCH_OY.DISP Then Return ' Eseguo la copia Dim MachiningId As Integer = EgtCopyMachining(m_SelectedOperation.Name, m_SelectedOperation.Name) ' Se è abilitata l'opzione If Not OptionModule.m_bNewMachiningIsLastOne Then ' Sposto la lavorazione aggiunta subito dopo quella appena selezionata EgtRelocate(MachiningId, m_SelectedOperation.Id, GDB_POS.AFTER) End If ' Ricarico la lista operazioni aggiornata Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, MachiningId) End Sub #End Region ' DuplicateMachCommand #Region "MachToDbCommand" ''' ''' Returns a command that do Point. ''' Public ReadOnly Property MachToDbCommand As ICommand Get If m_cmdMachToDb Is Nothing Then m_cmdMachToDb = New RelayCommand(AddressOf MachToDb) End If Return m_cmdMachToDb End Get End Property ''' ''' Execute the Point. This method is invoked by the PointCommand. ''' Public Sub MachToDb() 'verifico che l'operazione selezionata sia una lavorazione If IsNothing(m_SelectedOperation) Or m_SelectedOperation.m_Type = MCH_OY.NONE Or m_SelectedOperation.m_Type = MCH_OY.DISP Then Return ' apro la finetra che chiede il nome e verifica che non sia già utilizzato (Nome lavorazione nel Db) Dim NameDialogVM As New EgtWPFLib5.NameDialogVM With { .Title = EgtMsg(MSG_OPERATION + 18), .Name = TryCast(m_SelectedOperation, MachiningOpListBoxItem).LibMach, .NameVerifyer = AddressOf NameVerifyer} Dim NameWnd As New EgtWPFLib5.NameDialogV(Application.Current.MainWindow, NameDialogVM) If Not NameWnd.ShowDialog() Then Return ' creo lavorazione nel Db EgtMdbAddMachining(NameDialogVM.Name, m_SelectedOperation.m_Type) ' copio i parametri Dim bMachParList As Integer() = {MCH_MP.INVERT, MCH_MP.LEAVETAB, MCH_MP.TOOLINVERT} Dim nMachParList As Integer() = {MCH_MP.TYPE, MCH_MP.WORKSIDE, MCH_MP.HEADSIDE, MCH_MP.LEADINTYPE, MCH_MP.EXTLINKTYPE, MCH_MP.LEADOUTTYPE, MCH_MP.CURVEUSE, MCH_MP.STEPTYPE, MCH_MP.SUBTYPE, MCH_MP.LEADLINKTYPE, MCH_MP.SOLCHOICETYPE, MCH_MP.FACEUSE} Dim dMachParList As Integer() = {MCH_MP.SPEED, MCH_MP.FEED, MCH_MP.STARTFEED, MCH_MP.ENDFEED, MCH_MP.TIPFEED, MCH_MP.OFFSR, MCH_MP.OFFSL, MCH_MP.DEPTH, MCH_MP.SIDEANGLE, MCH_MP.APPROX, MCH_MP.STARTPOS, MCH_MP.STARTSLOWLEN, MCH_MP.ENDSLOWLEN, MCH_MP.THROUADDLEN, MCH_MP.STEP_, MCH_MP.RETURNPOS, MCH_MP.OVERLAP, MCH_MP.TABLEN, MCH_MP.TABDIST, MCH_MP.TABHEIGHT, MCH_MP.TABANGLE, MCH_MP.LITANG, MCH_MP.LIPERP, MCH_MP.LIELEV, MCH_MP.LICOMPLEN, MCH_MP.LOTANG, MCH_MP.LOPERP, MCH_MP.LOELEV, MCH_MP.LOCOMPLEN, MCH_MP.STARTADDLEN, MCH_MP.ENDADDLEN, MCH_MP.OFFSET, MCH_MP.STEPEXTARC, MCH_MP.STEPINTARC, MCH_MP.SIDESTEP, MCH_MP.VERTFEED, MCH_MP.STEPSIDEANG, MCH_MP.OVERL, MCH_MP.STEPBACK, MCH_MP.STEPSIDEANGBACK, MCH_MP.BACKFEED} Dim sMachParList As Integer() = {MCH_MP.NAME, MCH_MP.TOOL, MCH_MP.DEPTH_STR, MCH_MP.TUUID, MCH_MP.UUID, MCH_MP.SYSNOTES, MCH_MP.USERNOTES, MCH_MP.OVERLAP_STR, MCH_MP.OFFSET_STR, MCH_MP.INITANGS, MCH_MP.BLOCKEDAXIS} For Each Parameter In bMachParList Dim bTemp As Boolean = False EgtGetMachiningParam(Parameter, bTemp) EgtMdbSetCurrMachiningParam(Parameter, bTemp) Next For Each Parameter In nMachParList Dim nTemp As Integer = 0 EgtGetMachiningParam(Parameter, nTemp) EgtMdbSetCurrMachiningParam(Parameter, nTemp) Next For Each Parameter In dMachParList Dim dnTemp As Double = 0 EgtGetMachiningParam(Parameter, dnTemp) EgtMdbSetCurrMachiningParam(Parameter, dnTemp) Next For Each Parameter In sMachParList Dim snTemp As String = 0 EgtGetMachiningParam(Parameter, snTemp) EgtMdbSetCurrMachiningParam(Parameter, snTemp) Next EgtMdbSaveCurrMachining() EgtMdbSave() End Sub ' verifico che il nome non sia già utilizzato Private Function NameVerifyer(Name As String) As Boolean If String.IsNullOrWhiteSpace(Name) Then MessageBox.Show(EgtMsg(MSG_EGTSAVEFILEDIALOG + 8), EgtMsg(MSG_EGTSAVEFILEDIALOG + 7), MessageBoxButton.OK, MessageBoxImage.Error) Return False End If Dim TempName As String = Name EgtMdbGetMachiningNewName(TempName) If String.Compare(TempName, Name, True) = 0 Then Return True MessageBox.Show(Name & " " & EgtMsg(MSG_EGTSAVEFILEDIALOG + 3), EgtMsg(MSG_EGTSAVEFILEDIALOG + 7), MessageBoxButton.OK, MessageBoxImage.Error) Return False End Function #End Region ' MachToDbCommand #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