Imports System.Collections.ObjectModel Imports EgtUILib Public Class ChooseMachining ' Riferimento alla MainWindow Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow) Private m_CurrentMachine As CurrentMachine = m_MainWindow.m_CurrentMachine ' Liste che contengono gli elementi appartenenti alle ComboBox Private m_SawingList As New List(Of String) Private m_AuxMachTypeList As New List(Of StringIdCmBx) Private m_DrillingList As New List(Of String) Private m_MillingList As New List(Of String) Private m_WJettingList As New List(Of String) ' Numero righe della finestra, necessario per non ridimensionarla quando si cambia il tipo di utensile ausiliario Private m_RowNumber As Integer = 6 Sub New(Owner As Window) Me.Owner = Owner InitializeComponent() ShowDialog() End Sub Private Sub ChooseMachining_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized Me.Top = Owner.Top + Owner.Height / 2 - Me.Height / 2 Me.Left = Owner.Left + Owner.Width / 2 - Me.Width / 2 CurrSawingCmBx.ItemsSource = m_SawingList AuxiliaryMachiningCmBx.ItemsSource = m_AuxMachTypeList CurrDrillingCmBx.ItemsSource = m_DrillingList CurrMillingCmBx.ItemsSource = m_MillingList CurrWJettingCmBx.ItemsSource = m_WJettingList CurrSawingTxBl.Text = EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 1) AuxiliaryMachiningTxBl.Text = EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 2) CurrDrillingTxBl.Text = EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 3) CurrMillingTxBl.Text = EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 4) CurrWJettingTxBl.Text = EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 10) End Sub Private Sub ChooseMachining_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded InitializeMachiningLists() End Sub Private Sub InitializeMachiningLists() 'Creo lista lavorazioni di lama CreateMachiningList(MCH_MY.SAWING, m_CurrentMachine.sCurrSaw, m_SawingList) ' Verifico la configurazione della macchina per creare i combobox Select Case m_CurrentMachine.MountedToolConfig Case CurrentMachine.MountedToolConfigs.SAW ChooseMachiningGrid.Children.Remove(AuxiliaryMachiningTxBl) ChooseMachiningGrid.Children.Remove(AuxiliaryMachiningCmBx) Case CurrentMachine.MountedToolConfigs.SAWANDAUXTOOL, CurrentMachine.MountedToolConfigs.MANUALTOOLCHANGER, CurrentMachine.MountedToolConfigs.TOOLCHANGER ' Creo lista lavorazioni foretto e fresa If m_CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.SAWANDAUXTOOL Then CreateMachiningList(MCH_MY.DRILLING, m_CurrentMachine.sCurrDrill, m_DrillingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_DrillingList.Count = 0 Then m_CurrentMachine.sCurrDrilling = String.Empty End If CreateMachiningList(MCH_MY.MILLING, m_CurrentMachine.sCurrMill, m_MillingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_MillingList.Count = 0 Then m_CurrentMachine.sCurrMilling = String.Empty End If CreateMachiningList(MCH_MY.WATERJETTING, m_CurrentMachine.sCurrWaterJet, m_WJettingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_WJettingList.Count = 0 Then m_CurrentMachine.sCurrWaterJetting = String.Empty End If ElseIf m_CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.MANUALTOOLCHANGER Or m_CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.TOOLCHANGER Then CreateMachiningList(MCH_MY.DRILLING, m_DrillingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_DrillingList.Count = 0 Then m_CurrentMachine.sCurrDrilling = String.Empty End If CreateMachiningList(MCH_MY.MILLING, m_MillingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_MillingList.Count = 0 Then m_CurrentMachine.sCurrMilling = String.Empty End If CreateMachiningList(MCH_MY.WATERJETTING, m_WJettingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_WJettingList.Count = 0 Then m_CurrentMachine.sCurrWaterJetting = String.Empty End If End If ' Definizione di due righe della tabella con la giusta altezza For Index = 0 To 1 Dim Row As New RowDefinition Row.Height = New GridLength(0.5, GridUnitType.Star) ChooseMachiningGrid.RowDefinitions.Add(Row) Next AuxiliaryMachiningTxBl.SetValue(Grid.RowProperty, 2) AuxiliaryMachiningCmBx.SetValue(Grid.RowProperty, 3) ButtonsGrid.SetValue(Grid.RowProperty, 5) AuxiliaryMachiningTxBl.Visibility = Windows.Visibility.Visible AuxiliaryMachiningCmBx.Visibility = Windows.Visibility.Visible Me.Height = 341.2 m_RowNumber += 2 End Select If m_SawingList.Count > 0 Then CurrSawingCmBx.SelectedItem = m_SawingList(0) Else m_MainWindow.m_CurrentMachine.sCurrSawing = String.Empty End If If Not m_CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.SAW Then If m_CurrentMachine.bDrilling Then m_AuxMachTypeList.Add(New StringIdCmBx(1, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 6))) If m_CurrentMachine.bMilling Then m_AuxMachTypeList.Add(New StringIdCmBx(2, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 7))) If m_CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.MANUALTOOLCHANGER Or m_CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.TOOLCHANGER Then m_AuxMachTypeList.Add(New StringIdCmBx(3, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 8))) End If End If ElseIf m_CurrentMachine.bMilling Then m_AuxMachTypeList.Add(New StringIdCmBx(2, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 7))) ElseIf m_CurrentMachine.bWaterJetting Then m_AuxMachTypeList.Add(New StringIdCmBx(4, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 11))) End If ' Aggiungo nessuna come ultimo elemento della lista m_AuxMachTypeList.Add(New StringIdCmBx(0, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 5))) If m_CurrentMachine.sCurrDrilling <> String.Empty Then If m_CurrentMachine.sCurrMilling <> String.Empty Then AuxiliaryMachiningCmBx.SelectedItem = StringIdCmBx.FromIdToStringIdCmBx(3, m_AuxMachTypeList) Else AuxiliaryMachiningCmBx.SelectedItem = StringIdCmBx.FromIdToStringIdCmBx(1, m_AuxMachTypeList) End If ElseIf m_CurrentMachine.sCurrMilling <> String.Empty Then AuxiliaryMachiningCmBx.SelectedItem = StringIdCmBx.FromIdToStringIdCmBx(2, m_AuxMachTypeList) ElseIf m_CurrentMachine.sCurrWaterJetting <> String.Empty Then AuxiliaryMachiningCmBx.SelectedItem = StringIdCmBx.FromIdToStringIdCmBx(4, m_AuxMachTypeList) Else AuxiliaryMachiningCmBx.SelectedItem = StringIdCmBx.FromIdToStringIdCmBx(0, m_AuxMachTypeList) End If End If End Sub Private Sub CreateMachiningList(MachiningType As Integer, CurrTool As String, MachiningList As List(Of String)) ' Recupero UUID dell'utensile Dim sTuuid As String = String.Empty EgtTdbSetCurrTool(CurrTool) EgtTdbGetCurrToolParam(MCH_TP.UUID, sTuuid) ' Cerco tutte le lavorazioni che utilizzano l'utensile corrente e le aggiungo alla lista Dim MachiningName As String = String.Empty Dim bOk As Boolean = EgtMdbGetFirstMachining(MachiningType, MachiningName) While bOk EgtMdbSetCurrMachining(MachiningName) Dim sMachTuuid As String = String.Empty EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sMachTuuid) If sMachTuuid = sTuuid And VerifyMatThickCompatibility() Then MachiningList.Add(MachiningName) End If bOk = EgtMdbGetNextMachining(MachiningType, MachiningName) End While End Sub ' Funzione che data la stringa di materiali e spessori della lavorazione, e i dati del grezzo corrente, restituisce se la lavorazione è valida oppure no Private Function VerifyMatThickCompatibility() As Boolean If Not IsNothing(m_CurrentMachine.CurrMat) Then Dim SysNotes As String = String.Empty EgtMdbGetCurrMachiningParam(MCH_MP.SYSNOTES, SysNotes) If SysNotes <> String.Empty Then Dim MachiningMaterials() = SysNotes.Split(";".ToCharArray) SysNotes = String.Empty For Each Material In MachiningMaterials Dim Param() As String = Material.Split(",".ToCharArray) If Param(0) = m_CurrentMachine.CurrMat.nId.ToString() Then Dim dRawHeight = GetRawHeight() Dim MatMinH As Double = 0 StringToDouble(Param(1), MatMinH) Dim MatMaxH As Double = 0 StringToDouble(Param(2), MatMaxH) If dRawHeight > MatMinH - EPS_SMALL And dRawHeight < MatMaxH + EPS_SMALL Then Return True End If End If Next Return False Else Return False End If Else Return True End If End Function Private Sub CreateMachiningList(MachiningType As Integer, MachiningList As List(Of String)) ' Recupero UUID di tutti gli utensili attrezzati (nel ToolChanger e nel ManualToolChanger) Dim TuuidList As New List(Of String) For Each ToolChangerPos In m_CurrentMachine.ToolChanger Dim sTuuid As String = String.Empty EgtTdbSetCurrTool(ToolChangerPos.sTool) EgtTdbGetCurrToolParam(MCH_TP.UUID, sTuuid) TuuidList.Add(sTuuid) Next For Each ToolChangerPos In m_CurrentMachine.ManualToolChanger Dim sTuuid As String = String.Empty EgtTdbSetCurrTool(ToolChangerPos.sTool) EgtTdbGetCurrToolParam(MCH_TP.UUID, sTuuid) TuuidList.Add(sTuuid) Next ' Cerco tutte le lavorazioni che utilizzano un utensile presente e le aggiungo alla lista Dim MachiningName As String = String.Empty Dim bOk As Boolean = EgtMdbGetFirstMachining(MachiningType, MachiningName) While bOk ' Recupero UUID dell'utensile richiamato dalla lavorazione EgtMdbSetCurrMachining(MachiningName) Dim sMachTuuid As String = String.Empty EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sMachTuuid) ' Cerco UUID nella lista degli attrezzati For Each Tuuid In TuuidList If sMachTuuid = Tuuid Then If VerifyMatThickCompatibility() Then MachiningList.Add(MachiningName) Exit For End If End If Next ' Passo alla lavorazione successiva bOk = EgtMdbGetNextMachining(MachiningType, MachiningName) End While End Sub Private Sub AuxiliaryMachiningCmBx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles AuxiliaryMachiningCmBx.SelectionChanged CurrDrillingTxBl.Visibility = Windows.Visibility.Hidden CurrDrillingCmBx.Visibility = Windows.Visibility.Hidden CurrMillingTxBl.Visibility = Windows.Visibility.Hidden CurrMillingCmBx.Visibility = Windows.Visibility.Hidden CurrWJettingTxBl.Visibility = Windows.Visibility.Hidden CurrWJettingCmBx.Visibility = Windows.Visibility.Hidden Dim SelectedItem As StringIdCmBx = DirectCast(AuxiliaryMachiningCmBx.SelectedItem, StringIdCmBx) Select Case SelectedItem.nId Case 0 ' Nessuna If m_RowNumber > 8 Then For Index = m_RowNumber - 1 To 8 Step -1 ChooseMachiningGrid.RowDefinitions.RemoveAt(Index) Next m_RowNumber = 8 End If ButtonsGrid.SetValue(Grid.RowProperty, 5) m_MainWindow.m_CurrentMachine.sCurrDrilling = String.Empty m_MainWindow.m_CurrentMachine.sCurrMilling = String.Empty m_MainWindow.m_CurrentMachine.sCurrWaterJetting = String.Empty Me.Height = 341.2 Case 1 ' Foratura ' Definizione di due righe della tabella con la giusta altezza If m_RowNumber < 10 Then For Index = 1 To 10 - m_RowNumber Dim Row As New RowDefinition Row.Height = New GridLength(0.5, GridUnitType.Star) ChooseMachiningGrid.RowDefinitions.Add(Row) Next m_RowNumber = 10 End If CurrDrillingTxBl.SetValue(Grid.RowProperty, 4) CurrDrillingCmBx.SetValue(Grid.RowProperty, 5) ButtonsGrid.SetValue(Grid.RowProperty, 7) If m_CurrentMachine.sCurrDrilling <> String.Empty Then CurrDrillingCmBx.SelectedItem = m_CurrentMachine.sCurrDrilling End If m_MainWindow.m_CurrentMachine.sCurrMilling = String.Empty m_MainWindow.m_CurrentMachine.sCurrWaterJetting = String.Empty CurrDrillingTxBl.Visibility = Windows.Visibility.Visible CurrDrillingCmBx.Visibility = Windows.Visibility.Visible Me.Height = 426.5 Case 2 ' Fresatura ' Definizione di due righe della tabella con la giusta altezza If m_RowNumber < 10 Then For Index = 1 To 10 - m_RowNumber Dim Row As New RowDefinition Row.Height = New GridLength(0.5, GridUnitType.Star) ChooseMachiningGrid.RowDefinitions.Add(Row) Next m_RowNumber = 10 End If CurrMillingTxBl.SetValue(Grid.RowProperty, 4) CurrMillingCmBx.SetValue(Grid.RowProperty, 5) ButtonsGrid.SetValue(Grid.RowProperty, 7) If m_CurrentMachine.sCurrMilling <> String.Empty Then CurrMillingCmBx.SelectedItem = m_CurrentMachine.sCurrMilling End If m_MainWindow.m_CurrentMachine.sCurrDrilling = String.Empty m_MainWindow.m_CurrentMachine.sCurrWaterJetting = String.Empty CurrMillingTxBl.Visibility = Windows.Visibility.Visible CurrMillingCmBx.Visibility = Windows.Visibility.Visible Me.Height = 426.5 Case 3 ' Foratura + Fresatura (Entrambe) ' Definizione di quattro righe della tabella con la giusta altezza If m_RowNumber < 12 Then For Index = 1 To 12 - m_RowNumber Dim Row As New RowDefinition Row.Height = New GridLength(0.5, GridUnitType.Star) ChooseMachiningGrid.RowDefinitions.Add(Row) Next m_RowNumber = 12 End If If m_CurrentMachine.sCurrDrilling <> String.Empty Then CurrDrillingCmBx.SelectedItem = m_CurrentMachine.sCurrDrilling End If If m_CurrentMachine.sCurrMilling <> String.Empty Then CurrMillingCmBx.SelectedItem = m_CurrentMachine.sCurrMilling End If m_MainWindow.m_CurrentMachine.sCurrWaterJetting = String.Empty CurrDrillingTxBl.SetValue(Grid.RowProperty, 4) CurrDrillingCmBx.SetValue(Grid.RowProperty, 5) CurrMillingTxBl.SetValue(Grid.RowProperty, 6) CurrMillingCmBx.SetValue(Grid.RowProperty, 7) ButtonsGrid.SetValue(Grid.RowProperty, 9) CurrDrillingTxBl.Visibility = Windows.Visibility.Visible CurrDrillingCmBx.Visibility = Windows.Visibility.Visible CurrMillingTxBl.Visibility = Windows.Visibility.Visible CurrMillingCmBx.Visibility = Windows.Visibility.Visible Me.Height = 511.8 Case 4 ' WaterJetting ' Definizione di due righe della tabella con la giusta altezza If m_RowNumber < 10 Then For Index = 1 To 10 - m_RowNumber Dim Row As New RowDefinition Row.Height = New GridLength(0.5, GridUnitType.Star) ChooseMachiningGrid.RowDefinitions.Add(Row) Next m_RowNumber = 10 End If CurrWJettingTxBl.SetValue(Grid.RowProperty, 4) CurrWJettingCmBx.SetValue(Grid.RowProperty, 5) ButtonsGrid.SetValue(Grid.RowProperty, 7) If m_CurrentMachine.sCurrWaterJetting <> String.Empty Then CurrWJettingCmBx.SelectedItem = m_CurrentMachine.sCurrWaterJetting End If m_MainWindow.m_CurrentMachine.sCurrDrilling = String.Empty m_MainWindow.m_CurrentMachine.sCurrMilling = String.Empty CurrWJettingTxBl.Visibility = Windows.Visibility.Visible CurrWJettingCmBx.Visibility = Windows.Visibility.Visible Me.Height = 426.5 End Select End Sub Private Sub CurrSawingCmBx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles CurrSawingCmBx.SelectionChanged m_MainWindow.m_CurrentMachine.sCurrSawing = CurrSawingCmBx.SelectedItem.ToString() End Sub Private Sub CurrDrillingCmBx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles CurrDrillingCmBx.SelectionChanged m_MainWindow.m_CurrentMachine.sCurrDrilling = CurrDrillingCmBx.SelectedItem.ToString() End Sub Private Sub CurrMillingCmBx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles CurrMillingCmBx.SelectionChanged m_MainWindow.m_CurrentMachine.sCurrMilling = CurrMillingCmBx.SelectedItem.ToString() End Sub Private Sub CurrWJettingCmBx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles CurrWJettingCmBx.SelectionChanged m_MainWindow.m_CurrentMachine.sCurrWaterJetting = CurrWJettingCmBx.SelectedItem.ToString() End Sub Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click DialogResult = True End Sub Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExitBtn.Click DialogResult = False End Sub End Class Class StringIdCmBx Private m_nId As Integer Private m_sName As String Friend Overloads Shared Function FromIdToStringIdCmBx(nId As Integer, List As List(Of StringIdCmBx)) As StringIdCmBx For Each Item In List If Item.nId = nId Then Return Item End If Next Return Nothing End Function Friend Overloads Shared Function FromIdToStringIdCmBx(nId As Integer, List As ObservableCollection(Of StringIdCmBx)) As StringIdCmBx For Each Item In List If Item.nId = nId Then Return Item End If Next Return Nothing End Function Friend ReadOnly Property nId As Integer Get Return m_nId End Get End Property Public ReadOnly Property sName As String Get Return m_sName End Get End Property Sub New(Id As Integer, sName As String) m_nId = Id m_sName = sName End Sub End Class