Imports System.Windows.Forms.Integration
Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Namespace EgtCAM5
Public Class MachiningsDbViewModel
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
' Definizione comandi
Private m_cmdNew As ICommand
Private m_cmdSave As ICommand
Private m_cmdRemove 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 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
'''
''' Constructor
'''
Sub New()
m_bActive = True
LoadSelectedMachineMachinings()
Application.Msn.Register(Application.REMOVEMACHINING, Sub(MachiningToRemove As MachiningTreeViewItem)
Remove(MachiningToRemove)
End Sub)
' Quando chiamato, disattiva tutti gli item dell'albero o li riattiva a seconda che ci sia o meno un errore
Application.Msn.Register(Application.ERRORONMACHINING, Sub(WrongMachining As MachiningTreeViewItem)
For Each FamilyMachiningItem In MachiningsList
If IsNothing(WrongMachining) Then
FamilyMachiningItem.IsEnabled = True
Else
FamilyMachiningItem.IsEnabled = False
End If
For Each MachiningItem In FamilyMachiningItem.Items
If IsNothing(WrongMachining) Then
MachiningItem.IsEnabled = True
ElseIf MachiningItem IsNot WrongMachining Then
MachiningItem.IsEnabled = False
Else
MachiningItem.IsEnabled = True
End If
Next
Next
End Sub)
Application.Msn.Register(Application.UPDATESTATUSUNITS, Sub(bMmUnits As Boolean)
Dim MachiningFounded As Boolean = False
For Each FamilyMachiningItem In MachiningsList
If FamilyMachiningItem.IsSelected Then Exit For
For Each MachiningItem In FamilyMachiningItem.Items
If MachiningItem.IsSelected = True Then
MachiningFounded = True
MachiningItem.IsSelected = False
MachiningItem.IsSelected = True
MachiningItem.NotifyPropertyChanged("IsSelected")
End If
Next
If MachiningFounded Then Exit For
Next
End Sub)
End Sub
'''
''' Method that search the machines in the correct folder and add to the MachinesList those valid.
'''
Private Sub LoadSelectedMachineMachinings()
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
Dim ActiveMachiningsTypes() As MachiningsType = 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
'''
''' Method that search the machines in the correct folder and add to the MachinesList those valid.
'''
Private Function ReadActiveMachiningsFamilies() As MachiningsType()
Dim ActiveMachiningsFamiliesList As New List(Of MachiningsType)
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_DRILLING, 0, m_sCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.DRILLING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 1)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWING, 0, m_sCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.SAWING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 2)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_MILLING, 0, m_sCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.MILLING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 3)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_POCKETING, 0, m_sCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.POCKETING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 4)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_MORTISING, 0, m_sCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.MORTISING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 5)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWROUGHING, 0, m_sCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.SAWROUGHING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 6)})
End If
If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWFINISHING, 0, m_sCurrMachIniFilePath) <> 0 Then
ActiveMachiningsFamiliesList.Add(New MachiningsType With {.TypeId = MCH_MY.SAWFINISHING, .TypeName = EgtMsg(MSG_MACHININGSDBPAGE + 7)})
End If
Return ActiveMachiningsFamiliesList.ToArray
End Function
'''
''' Structure that represent a tool's family, containing family type and family name
'''
Structure MachiningsType
Friend TypeId As MCH_MY
Friend TypeName As String
End Structure
#Region "NewCommand"
'''
''' Returns a command that create a new machining.
'''
Public ReadOnly Property NewCommand As ICommand
Get
If m_cmdNew Is Nothing Then
m_cmdNew = New RelayCommand(AddressOf NewPar, AddressOf CanNew)
End If
Return m_cmdNew
End Get
End Property
'''
''' Creata the new machining. This method is invoked by the NewCommand.
'''
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 ll 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
'''
''' Returns true if the selected treeviewitem is valid for new tool creation.
'''
Private Function CanNew(ByVal param As Object) As Boolean
' Verifico se sia selezionata una famiglia
If TypeOf param Is FamilyMachiningTreeViewItem Then
Return True
' Verifico se sia selezionata una lavorazione
ElseIf TypeOf param Is MachiningTreeViewItem Then
' Verifico che i parametri della lavorazione siano validi
Dim SelectedMachining As MachiningTreeViewItem = DirectCast(param, MachiningTreeViewItem)
Return SelectedMachining.IsValid And Not SelectedMachining.IsModified
Else
Return False
End If
End Function
#End Region ' NewCommand
#Region "SaveCommand"
'''
''' Returns a command that save the current selected machining.
'''
Public ReadOnly Property SaveCommand() As ICommand
Get
If m_cmdSave Is Nothing Then
m_cmdSave = New RelayCommand(AddressOf Save, AddressOf CanSave)
End If
Return m_cmdSave
End Get
End Property
'''
''' Saves the current machining. This method is invoked by the SaveCommand.
'''
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()
End Sub
'''
''' Returns true if the selected machining is valid and can be saved.
'''
Private Function CanSave(ByVal param As Object) As Boolean
' Verifico che sia selezionata una lavorazione
If TypeOf param Is MachiningTreeViewItem Then
Dim Machining As MachiningTreeViewItem = DirectCast(param, MachiningTreeViewItem)
' Verifico che i parametri della lavorazione siano validi
Return (Machining.IsValid And (Machining.IsModified Or Machining.NewMachining))
Else
Return False
End If
End Function
#End Region ' SaveCommand
#Region "RemoveCommand"
'''
''' Returns a command that remove the current selected machining.
'''
Public ReadOnly Property RemoveCommand() As ICommand
Get
If m_cmdRemove Is Nothing Then
m_cmdRemove = New RelayCommand(AddressOf Remove, AddressOf CanRemove)
End If
Return m_cmdRemove
End Get
End Property
'''
''' Remove the current selected machining from Db and TreeView. This method is invoked by the RemoveCommand.
'''
Public Sub Remove(ByVal param As Object)
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
Dim MachiningToRemove As MachiningTreeViewItem = DirectCast(param, 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
Application.Msn.NotifyColleagues(Application.ERRORONMACHINING, Nothing)
End Sub
'''
''' Returns true if the selected machining can be removed.
'''
Private Function CanRemove(ByVal param As Object) As Boolean
' Verifico se sia selezionata una famiglia
If TypeOf param Is FamilyMachiningTreeViewItem Then
Return False
' Verifico se sia selezionata una lavorazione
ElseIf TypeOf param Is MachiningTreeViewItem Then
Return True
Else
Return False
End If
End Function
#End Region ' RemoveCommand
#Region "CloseMachiningsDbCommand"
'''
''' Returns a command that remove the current selected machining.
'''
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
'''
''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand.
'''
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
Application.Msn.NotifyColleagues(Application.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
Return
End If
End If
' Salvataggio DB lavorazioni
EgtMdbSave()
Application.Msn.NotifyColleagues(Application.UPDATEOPERATIONMACHININGLIST)
' Chiusura finestra
For Each Window In Application.Current.Windows
If TypeOf Window Is MachiningsDbView Then
Dim MachiningsDbWindow As MachiningsDbView = DirectCast(Window, MachiningsDbView)
MachiningsDbWindow.Close()
End If
Next
End Sub
#End Region ' CloseMachiningDbCommand
End Class
End Namespace