Files
EgtCAM5/MachiningsDbWindow/MachiningsDbViewModel.vb
T
Dario Sassi 6172fdc1f7 EgtCAM5 1.6u1 :
- modifiche per nuovo gruppo di lavoro con macchina corrente
- modifiche per utensili speciali.
2016-09-14 09:33:30 +00:00

614 lines
23 KiB
VB.net

Imports System.Windows.Forms.Integration
Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Namespace EgtCAM5
Public Class MachiningsDbViewModel
Inherits TabViewModel
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
#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 OverLapStrTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 101)
End Get
End Property
Public ReadOnly Property OffsetStrTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 102)
End Get
End Property
Public ReadOnly Property SubTypeTxBl As String
Get
Return EgtMsg(MSG_MACHININGSDBPAGE + 103)
End Get
End Property
#End Region
''' <summary>
''' Constructor
''' </summary>
Sub New()
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
''' <summary>
''' Method that search the machines in the correct folder and add to the MachinesList those valid.
''' </summary>
Private Sub LoadSelectedMachineMachinings()
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
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
If EgtMdbGetFirstMachining(MachiningsType.TypeId, MachiningName) Then
FamilyTreeView.Items.Add(New MachiningTreeViewItem(MachiningName, MachiningsType.TypeId))
While EgtMdbGetNextMachining(MachiningsType.TypeId, MachiningName)
FamilyTreeView.Items.Add(New MachiningTreeViewItem(MachiningName, MachiningsType.TypeId))
End While
End If
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
''' <summary>
''' Method that search the machines in the correct folder and add to the MachinesList those valid.
''' </summary>
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
''' <summary>
''' Structure that represent a tool's family, containing family type and family name
''' </summary>
Structure MachiningsType
Friend TypeId As MCH_MY
Friend TypeName As String
End Structure
#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, AddressOf CanNew)
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
NewMachiningItem.IsSelected = True
NewMachiningItem.NotifyPropertyChanged("IsSelected")
Exit For
End If
Next
End If
End If
End Sub
''' <summary>
''' Returns true if the selected treeviewitem is valid for new tool creation.
''' </summary>
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
Return DirectCast(param, MachiningTreeViewItem).IsValid
Else
Return False
End If
End Function
#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, AddressOf CanSave)
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)
EgtMdbSaveCurrMachining()
EgtMdbSave()
End Sub
''' <summary>
''' Returns true if the selected machining is valid and can be saved.
''' </summary>
Private Function CanSave(ByVal param As Object) As Boolean
' Verifico che sia selezionata una lavorazione
If TypeOf param Is MachiningTreeViewItem Then
' Verifico che i parametri della lavorazione siano validi
Return DirectCast(param, MachiningTreeViewItem).IsValid And EgtMdbIsCurrMachiningModified()
Else
Return False
End If
End Function
#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, AddressOf CanRemove)
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)
Dim MachiningToRemove As MachiningTreeViewItem = DirectCast(param, MachiningTreeViewItem)
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
' Salvo il tipo di lavorazione per poterla cancellare
Dim MachiningType As Integer = MachiningToRemove.Type
' Cancello la lavorazione
EgtMdbRemoveMachining(MachiningToRemove.Name)
' Rimuovo il nome dell'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
''' <summary>
''' Returns true if the selected machining can be removed.
''' </summary>
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
End Class
End Namespace