Files
EgtCAM5/MachiningDbWindow/MachiningDbVM.vb
T
Emmanuele Sassi 6dd2abf95d EgtCAM5 :
- Altri nomi modificati.
- Eliminato namespace.
2018-04-11 10:43:14 +00:00

688 lines
22 KiB
VB.net

Imports System.Windows.Forms.Integration
Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Public Class MachiningDbVM
Inherits TabViewModel
Friend Shared m_bActive As Boolean = False
Private m_Title As String
Public ReadOnly Property Title As String
Get
Return EgtMsg(MSG_MAINWINDOW + 4)
End Get
End Property
' Lista delle lavorazioni
Private m_MachiningsList As New ObservableCollection(Of FamilyMachiningTreeViewItem)
Public Property MachiningsList As ObservableCollection(Of FamilyMachiningTreeViewItem)
Get
Return m_MachiningsList
End Get
Set(value As ObservableCollection(Of FamilyMachiningTreeViewItem))
m_MachiningsList = value
End Set
End Property
Private m_IsEnabledNewBtn As Boolean
Public ReadOnly Property IsEnabledNewBtn As Boolean
Get
Return m_IsEnabledNewBtn
End Get
End Property
Private m_IsEnabledSaveBtn As Boolean
Public ReadOnly Property IsEnabledSaveBtn As Boolean
Get
Return m_IsEnabledSaveBtn
End Get
End Property
Private m_IsEnabledRemoveBtn As Boolean
Public ReadOnly Property IsEnabledRemoveBtn As Boolean
Get
Return m_IsEnabledRemoveBtn
End Get
End Property
' Definizione comandi
Private m_cmdNew As ICommand
Private m_cmdSave As ICommand
Private m_cmdRemove As ICommand
Private m_cmdReloadMachining As ICommand
Private m_cmdCloseMachiningsDb As ICommand
#Region "MESSAGES"
'Definizione dei messaggi della pagina
Public ReadOnly Property InvertTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 51)
End Get
End Property
Public ReadOnly Property LeaveTabTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 52)
End Get
End Property
Public ReadOnly Property WorkSideTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 54)
End Get
End Property
Public ReadOnly Property HeadSideTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 55)
End Get
End Property
Public ReadOnly Property LeadInTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 56)
End Get
End Property
Public ReadOnly Property ExtLinkTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 57)
End Get
End Property
Public ReadOnly Property LeadOutTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 58)
End Get
End Property
Public ReadOnly Property CurveUseTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 59)
End Get
End Property
Public ReadOnly Property StepTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 60)
End Get
End Property
Public ReadOnly Property LeadLinkTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 62)
End Get
End Property
Public ReadOnly Property InvertToolDirTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 151)
End Get
End Property
Public ReadOnly Property FaceUseTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 152)
End Get
End Property
Public ReadOnly Property AxRotRefTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 164)
End Get
End Property
Public ReadOnly Property BlockedAxesRefTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 165)
End Get
End Property
Public ReadOnly Property SolChoiceTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 104)
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 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
Public ReadOnly Property TipFeedTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 67)
End Get
End Property
Public ReadOnly Property OffSrTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 68)
End Get
End Property
Public ReadOnly Property OffSlTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 69)
End Get
End Property
Public ReadOnly Property SideAngleTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 71)
End Get
End Property
Public ReadOnly Property ApproxTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 72)
End Get
End Property
Public ReadOnly Property StartPosTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 73)
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 ThrouAddLenTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 76)
End Get
End Property
Public ReadOnly Property StepParTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 77)
End Get
End Property
Public ReadOnly Property ReturnPosTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 78)
End Get
End Property
Public ReadOnly Property TabLenTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 79)
End Get
End Property
Public ReadOnly Property TabDistTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 80)
End Get
End Property
Public ReadOnly Property TabHeightTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 81)
End Get
End Property
Public ReadOnly Property TabAngleTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 82)
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 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 StartAddLenTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 91)
End Get
End Property
Public ReadOnly Property EndAddLenTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 92)
End Get
End Property
Public ReadOnly Property StepExtArcTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 93)
End Get
End Property
Public ReadOnly Property StepIntArcTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 94)
End Get
End Property
Public ReadOnly Property SideStepTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 95)
End Get
End Property
Public ReadOnly Property VertFeedTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 96)
End Get
End Property
Public ReadOnly Property NameParTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 97)
End Get
End Property
Public ReadOnly Property ToolTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 98)
End Get
End Property
Public ReadOnly Property DepthStrTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 99)
End Get
End Property
Public ReadOnly Property UserNotesTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 100)
End Get
End Property
Public ReadOnly Property OverLapTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 101)
End Get
End Property
Public ReadOnly Property SubTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 103)
End Get
End Property
#End Region
#Region "CONSTRUCTOR"
Sub New()
m_bActive = True
' Passo all'item della lista il delegato alla funzuione che permette di cancellare una lavorazione
MachiningTreeViewItem.m_delRemoveMachining = AddressOf RemoveMachining
' Passo all'item della lista il delegato alla funzuione che permette di disattivare la lista delle lavorazioni
MachiningTreeViewItem.m_delErrorOnMachining = AddressOf ErrorOnMachining
' Passo all'item della lista il delegato alla funzuione che permette di disattivare la lista delle lavorazioni
MachiningTreeViewItem.m_delIsEnabledBtns = AddressOf IsEnabledBtns
FamilyMachiningTreeViewItem.m_delIsEnabledBtns = AddressOf IsEnabledBtns
' Carico la lista delle lavorazioni della macchina selezionata
LoadSelectedMachineMachinings()
End Sub
#End Region ' Constructor
#Region "METHODS"
Private Sub IsEnabledBtns(bIsEnabledNewBtn As Boolean, bIsEnabledSaveBtn As Boolean, bIsEnabledDeleteBtn As Boolean)
m_IsEnabledNewBtn = bIsEnabledNewBtn
m_IsEnabledSaveBtn = bIsEnabledSaveBtn
m_IsEnabledRemoveBtn = bIsEnabledDeleteBtn
OnPropertyChanged("IsEnabledNewBtn")
OnPropertyChanged("IsEnabledSaveBtn")
OnPropertyChanged("IsEnabledRemoveBtn")
End Sub
' Quando chiamato, disattiva tutti gli item dell'albero o li riattiva a seconda che ci sia o meno un errore
Private Sub ErrorOnMachining(bIsEnabled As Boolean)
For Each FamilyMachiningItem In MachiningsList
FamilyMachiningItem.IsEnabled = Not bIsEnabled
Next
End Sub
''' <summary>
''' Method that search the machines in the correct folder and add to the MachinesList those valid.
''' </summary>
Private Sub LoadSelectedMachineMachinings()
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
Dim ActiveMachiningsTypes() As MachiningsType = MachineModel.ReadActiveMachiningsFamilies()
For Each MachiningsType In ActiveMachiningsTypes
Dim FamilyTreeView As New FamilyMachiningTreeViewItem(MachiningsType.TypeName, MachiningsType.TypeId)
MachiningsList.Add(FamilyTreeView)
Dim MachiningName As String = String.Empty
EgtMdbGetFirstMachining(MachiningsType.TypeId, MachiningName)
While Not String.IsNullOrWhiteSpace(MachiningName)
FamilyTreeView.Items.Add(New MachiningTreeViewItem(MachiningName, MachiningsType.TypeId))
EgtMdbGetNextMachining(MachiningsType.TypeId, MachiningName)
End While
Next
' Se esiste almeno una famiglia di lavorazioni, la seleziono
If MachiningsList.Count > 0 Then
MachiningsList(0).IsSelected = True
MachiningsList(0).NotifyPropertyChanged("IsSelected")
End If
End Sub
#End Region ' Methods
#Region "COMMANDS"
#Region "NewCommand"
''' <summary>
''' Returns a command that create a new machining.
''' </summary>
Public ReadOnly Property NewCommand As ICommand
Get
If m_cmdNew Is Nothing Then
m_cmdNew = New RelayCommand(AddressOf NewPar)
End If
Return m_cmdNew
End Get
End Property
''' <summary>
''' Creata the new machining. This method is invoked by the NewCommand.
''' </summary>
Public Sub NewPar(ByVal param As Object)
' Verifico se sia selezionata una famiglia
Dim NewMachiningItem As MachiningTreeViewItem
If TypeOf param Is FamilyMachiningTreeViewItem Then
Dim MachiningFamily As FamilyMachiningTreeViewItem = DirectCast(param, FamilyMachiningTreeViewItem)
Dim NewName As String = MachiningFamily.Name
EgtMdbGetMachiningNewName(NewName)
If EgtMdbAddMachining(NewName, MachiningFamily.MachiningType) Then
NewMachiningItem = New MachiningTreeViewItem(NewName, MachiningFamily.MachiningType)
MachiningFamily.Items.Add(NewMachiningItem)
EgtMdbSaveCurrMachining()
NewMachiningItem.NewMachining = True
If Not MachiningFamily.IsExpanded Then MachiningFamily.IsExpanded = True
NewMachiningItem.IsSelected = True
NewMachiningItem.NotifyPropertyChanged("IsSelected")
End If
' Verifico se sia selezionata una lavorazione
ElseIf TypeOf param Is MachiningTreeViewItem Then
Dim MachiningCopied As MachiningTreeViewItem = DirectCast(param, MachiningTreeViewItem)
Dim NewName As String = MachiningCopied.Name
EgtMdbGetMachiningNewName(NewName)
If EgtMdbCopyMachining(MachiningCopied.Name, NewName) Then
Dim CurrType As Integer
EgtMdbGetCurrMachiningParam(MCH_MP.TYPE, CurrType)
For Each MachiningFamily In MachiningsList
If (MachiningFamily.MachiningType And CurrType) <> 0 Then
NewMachiningItem = New MachiningTreeViewItem(NewName, MachiningFamily.MachiningType)
MachiningFamily.Items.Add(NewMachiningItem)
EgtMdbSaveCurrMachining()
NewMachiningItem.NewMachining = True
' Reimposto la lavorazione vecchia nel Db per deselezionarla e fare le verifiche correttamente
EgtMdbSetCurrMachining(MachiningCopied.Name)
MachiningCopied.IsSelected = False
MachiningCopied.NotifyPropertyChanged("IsSelected")
NewMachiningItem.IsSelected = True
Exit For
End If
Next
End If
End If
End Sub
#End Region ' NewCommand
#Region "SaveCommand"
''' <summary>
''' Returns a command that save the current selected machining.
''' </summary>
Public ReadOnly Property SaveCommand() As ICommand
Get
If m_cmdSave Is Nothing Then
m_cmdSave = New RelayCommand(AddressOf Save)
End If
Return m_cmdSave
End Get
End Property
''' <summary>
''' Saves the current machining. This method is invoked by the SaveCommand.
''' </summary>
Public Sub Save(ByVal param As Object)
Dim CurrMachining As MachiningTreeViewItem = DirectCast(param, MachiningTreeViewItem)
CurrMachining.WriteMachiningParam()
CurrMachining.m_Name = CurrMachining.m_Name.Trim()
CurrMachining.WriteMachiningName()
EgtMdbSaveCurrMachining()
CurrMachining.NewMachining = False
CurrMachining.IsModifiedReset()
IsEnabledBtns(CurrMachining.IsValid And Not CurrMachining.IsModified, False, True)
End Sub
#End Region ' SaveCommand
#Region "RemoveCommand"
''' <summary>
''' Returns a command that remove the current selected machining.
''' </summary>
Public ReadOnly Property RemoveCommand() As ICommand
Get
If m_cmdRemove Is Nothing Then
m_cmdRemove = New RelayCommand(AddressOf Remove)
End If
Return m_cmdRemove
End Get
End Property
''' <summary>
''' Remove the current selected machining from Db and TreeView. This method is invoked by the RemoveCommand.
''' </summary>
Public Sub Remove(ByVal param As Object)
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
Dim MachiningToRemove As MachiningTreeViewItem = DirectCast(param, MachiningTreeViewItem)
' Chiedo conferma cancellazione lavorazione
If MessageBox.Show(EgtMsg(MSG_MACHININGSERRORS + 4) & " " & MachiningToRemove.Name & EgtMsg(MSG_MACHININGSERRORS + 5), EgtMsg(MSG_MACHININGSERRORS + 6), MessageBoxButton.YesNo, MessageBoxImage.Question) <> MessageBoxResult.Yes Then
Return
End If
RemoveMachining(MachiningToRemove)
End Sub
Public Sub RemoveMachining(MachiningToRemove As MachiningTreeViewItem)
' Salvo il tipo di lavorazione per poterla cancellare
Dim MachiningType As Integer = MachiningToRemove.Type
' Cancello la lavorazione
Dim CurrMachiningOriginalName As String = String.Empty
EgtMdbGetMachiningFromUUID(MachiningToRemove.Uuid, CurrMachiningOriginalName)
EgtMdbRemoveMachining(CurrMachiningOriginalName)
' Rimuovo il nome dall'albero
For Each MachiningFamily In MachiningsList
If (MachiningFamily.MachiningType And MachiningType) <> 0 Then
MachiningFamily.Items.Remove(MachiningToRemove)
End If
Next
ErrorOnMachining(False)
End Sub
#End Region ' RemoveCommand
#Region "ReloadMachiningCommand"
''' <summary>
''' Returns a command that reload the current selected tool.
''' </summary>
Public ReadOnly Property ReloadMachiningCommand() As ICommand
Get
If m_cmdReloadMachining Is Nothing Then
m_cmdReloadMachining = New RelayCommand(AddressOf ReloadMachining)
End If
Return m_cmdReloadMachining
End Get
End Property
''' <summary>
''' Reload the current selected tools. This method is invoked by the RemoveCommand.
''' </summary>
Public Sub ReloadMachining(ByVal param As Object)
If TypeOf param Is FamilyMachiningTreeViewItem Then
Return
' Verifico se sia selezionato un utensile
ElseIf TypeOf param Is MachiningTreeViewItem Then
Dim MachiningToReload As MachiningTreeViewItem = DirectCast(param, MachiningTreeViewItem)
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
MachiningToReload.ReadMachiningParam()
MachiningToReload.ReadMachiningName()
MachiningToReload.IsModifiedReset()
End If
End Sub
#End Region ' ReloadMachiningCommand
#Region "CloseMachiningsDbCommand"
''' <summary>
''' Returns a command that remove the current selected machining.
''' </summary>
Public ReadOnly Property CloseMachiningsDbCommand() As ICommand
Get
If m_cmdCloseMachiningsDb Is Nothing Then
m_cmdCloseMachiningsDb = New RelayCommand(AddressOf CloseMachiningsDb)
End If
Return m_cmdCloseMachiningsDb
End Get
End Property
''' <summary>
''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand.
''' </summary>
Public Sub CloseMachiningsDb(param As Object)
m_bActive = False
' Se selezionata una lavorazione, verifico salvataggio
If TypeOf param Is MachiningTreeViewItem Then
Dim CurrMachining As MachiningTreeViewItem = DirectCast(param, MachiningTreeViewItem)
If CurrMachining.IsValid Then
CurrMachining.WriteMachiningParam()
If EgtMdbIsCurrMachiningModified() Or CurrMachining.m_IsModifiedName Or CurrMachining.NewMachining Then
Select Case MsgBox(EgtMsg(MSG_MACHININGSERRORS), MsgBoxStyle.YesNo, EgtMsg(MSG_MACHININGSERRORS + 1))
Case MsgBoxResult.Yes
CurrMachining.NewMachining = False
CurrMachining.m_Name = CurrMachining.m_Name.Trim()
CurrMachining.WriteMachiningName()
EgtMdbSaveCurrMachining()
Case MsgBoxResult.No
If CurrMachining.NewMachining Then
RemoveMachining(CurrMachining)
ElseIf CurrMachining.m_IsModifiedName Then
Dim DbName As String = String.Empty
EgtMdbGetCurrMachiningParam(MCH_MP.NAME, DbName)
CurrMachining.NamePar = DbName
End If
End Select
End If
Else
MessageBox.Show("Utensile non valido, correggerlo o cancellarlo prima di uscire.", "ERRORE")
Return
End If
End If
' Salvataggio DB lavorazioni
EgtMdbSave()
Application.Msn.NotifyColleagues(Application.UPDATEOPERATIONMACHININGLIST)
' Chiusura finestra
MachiningTreeViewItem.m_delRemoveMachining = Nothing
MachiningTreeViewItem.m_delErrorOnMachining = Nothing
MachiningTreeViewItem.m_delIsEnabledBtns = Nothing
FamilyMachiningTreeViewItem.m_delIsEnabledBtns = Nothing
For Each Window In Application.Current.Windows
If TypeOf Window Is MachiningDbV Then
Dim MachiningsDbWindow As MachiningDbV = DirectCast(Window, MachiningDbV)
MachiningsDbWindow.DataContext = Nothing
MachiningsDbWindow.Close()
End If
Next
End Sub
#End Region ' CloseMachiningDbCommand
#End Region ' Commands
End Class