Files
OmagCUT/MachiningDbPageUC.xaml.vb
T
Emmanuele Sassi 8f912cae70 OmagCUT :
- Miglioramento comunicazione per prove su macchina.
- Aggiunto componente checkbox nel dictionary.
- Usato checkbox per parametro di lavorazione inveti.
2015-11-20 09:03:31 +00:00

433 lines
20 KiB
VB.net

Imports System.Collections.ObjectModel
Imports OmagCUT.TreeViewItem
Imports EgtUILib
Public Class MachiningDbPageUC
' Riferimento alla MainWindow
Private m_MainWindow As MainWindow = Application.Current.MainWindow
' Lista degli utensili
Dim MachiningsList As New ObservableCollection(Of CathegoryItem)
' Proprietà
Private m_bFirst As Boolean = True
Private m_sMachiningName As String = String.Empty
'Array che contengono le variabili per Combobox
Dim WorkSide() As String = {"Centro", "Sinistra", "Destra"}
Dim HeadSide() As String = {"Sinistra", "Destra"}
Dim LeadInType() As String = {"Centrato", "Interno", "Esterno", "Esteso centrato", "Esteso esterno"}
Dim ExtLinkType() As String = {"Centrato", "Esteso precedente", "Esteso successivo", "Estesi entrambi"}
Dim LeadOutType() As String = {"Centrata", "Interna", "Esterna"}
Dim CurveUse() As String = {"Salta", "Approssima", "Convesso"}
Dim StepType() As String = {"Step", "Una via", "Spirale"}
Dim Tool As New List(Of String)
'Variabile che conserva la lavorazione precedentemente selezionata, usata nel caso si selezioni annulla quando si cambia lavorazione selezionata
Private m_OldItem As Object
Private Sub MachiningDbPage_Initialized(sender As Object, e As EventArgs)
' Assegno la lista degli utensili come sorgente del treeview
MachiningTreeView.ItemsSource = MachiningsList
'Assegno array a combobox
WorkSideCmBx.ItemsSource = WorkSide
HeadSideCmBx.ItemsSource = HeadSide
LeadInTypeCmBx.ItemsSource = LeadInType
ExtLinkTypeCmBx.ItemsSource = ExtLinkType
LeadOutTypeCmBx.ItemsSource = LeadOutType
CurveUseCmBx.ItemsSource = CurveUse
StepTypeCmBx.ItemsSource = StepType
ToolCmBx.ItemsSource = Tool
'Imposto i messaggi letti dal file dei messaggi
NameTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 1)
DepthTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 2)
SideAngleTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 3)
InvertTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 4)
StepTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 5)
WorkSideTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 6)
HeadSideTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 7)
LeadInTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 8)
ExtLinkTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 9)
LeadOutTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 10)
CurveUseTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 11)
ApproxTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 12)
ToolTxBl.Text = "Utensile"
' Associo TextBox e Label
End Sub
Private Sub MachiningDbPage_Loaded(sender As Object, e As RoutedEventArgs)
If m_bFirst Then
' Inizializzo le famiglie di utensili nell'albero
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
InitializeToolFamily(K_SAWING, MCH_MY.SAWING, EgtMsg(MSG_MACHININGSDBPAGEUC + 21))
'InitializeToolFamily(K_DRILLING, MCH_MY.DRILLING, EgtMsg(MSG_MACHININGSDBPAGEUC + 22))
'InitializeToolFamily(K_MILLING, MCH_MY.MILLING, EgtMsg(MSG_MACHININGSDBPAGEUC + 23))
m_bFirst = False
Else
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
End If
InitializeFirstSelectedItem()
End Sub
'Funzione che permette l'inizializzazione di albero e parametri all'apertura della pagina ToolsDb
Private Sub InitializeFirstSelectedItem()
If MachiningsList.Count > 0 Then
For Each ToolFamily In MachiningsList
If ToolFamily.Items.Count > 0 Then
ToolFamily.IsExpanded = True
ToolFamily.Items(0).IsSelected = True
EgtMdbSetCurrMachining(ToolFamily.Items(0).Name)
m_OldItem = ToolFamily.Items(0)
GetMachiningParams()
ViewMachiningParams()
Exit Sub
End If
Next
MachiningsList.Item(0).IsSelected = True
HideMachiningParams()
End If
End Sub
'Private Sub MoveParam()
' SpeedBrd.SetValue(Grid.RowProperty, 1)
' FeedBrd.SetValue(Grid.RowProperty, 2)
' CoolantTxBl.SetValue(Grid.RowProperty, 4)
' CoolantCmBx.SetValue(Grid.RowProperty, 4)
' CorrTxBl.SetValue(Grid.RowProperty, 4)
' CorrTxBx.SetValue(Grid.RowProperty, 4)
' OffsetBrd.SetValue(Grid.RowProperty, 5)
' AbsorptionBrd.SetValue(Grid.RowProperty, 6)
' MaxMatTxBl.SetValue(Grid.RowProperty, 7)
' MaxMatTxBx.SetValue(Grid.RowProperty, 7)
'End Sub
Private Sub NewBtn_Click(sender As Object, e As RoutedEventArgs) Handles NewBtn.Click
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
If TypeOf MachiningTreeView.SelectedItem Is CathegoryItem Then
Dim SelectedCathegory As CathegoryItem = MachiningTreeView.SelectedItem
Dim NewName As String = SelectedCathegory.Name
EgtMdbGetMachiningNewName(NewName)
If EgtMdbAddMachining(NewName, SelectedCathegory.nFType) Then
For Each MachiningFamily In MachiningsList
If MachiningFamily.nFType = SelectedCathegory.nFType Then
Dim NewMachiningItem As New CustomItem(NewName, SelectedCathegory.nFType)
MachiningFamily.Items.Add(NewMachiningItem)
NewMachiningItem.IsSelected = True
MachiningFamily.IsExpanded = True
m_OldItem = MachiningTreeView.SelectedItem
End If
Next
GetMachiningParams()
ViewMachiningParams()
End If
ElseIf TypeOf MachiningTreeView.SelectedItem Is CustomItem Then
Dim SelectedCathegory As CustomItem = MachiningTreeView.SelectedItem
Dim NewName As String = SelectedCathegory.Name
EgtMdbGetMachiningNewName(NewName)
If EgtMdbCopyMachining(SelectedCathegory.Name, NewName) Then
'Dim CurrType As Integer
'EgtMdbGetCurrMachiningParam(MCH_TP.TYPE, CurrType)
For Each MachiningFamily In MachiningsList
If (MachiningFamily.nFType And MCH_MY.SAWING) <> 0 Then 'CurrType al posto di MCH_MY.SAWING
Dim NewMachiningItem As New CustomItem(NewName, MCH_MY.SAWING) 'CurrType al posto di MCH_MY.SAWING
MachiningFamily.Items.Add(NewMachiningItem)
NewMachiningItem.IsSelected = True
GetMachiningParams()
m_OldItem = MachiningTreeView.SelectedItem
End If
Next
End If
End If
End Sub
Private Sub SaveBtn_Click(sender As Object, e As RoutedEventArgs) Handles SaveBtn.Click
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
SetMachiningParams()
EgtMdbSaveCurrMachining()
Dim CurrTool As CustomItem = TryCast(m_OldItem, CustomItem)
If CurrTool IsNot Nothing Then
CurrTool.Name = NameTxBx.Text
End If
End Sub
Private Sub RemoveBtn_Click(sender As Object, e As RoutedEventArgs) Handles RemoveBtn.Click
If TypeOf MachiningTreeView.SelectedItem Is CustomItem Then
Dim SelectedItem As CustomItem = MachiningTreeView.SelectedItem
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
EgtMdbRemoveMachining(SelectedItem.Name)
For Each MachiningFamily In MachiningsList
If (MachiningFamily.nFType And SelectedItem.nType) <> 0 Then
MachiningFamily.Items.Remove(SelectedItem)
If MachiningFamily.Items.Count = 0 Then
MachiningFamily.IsSelected = True
HideMachiningParams()
Else
MachiningFamily.Items(0).IsSelected = True
EgtMdbSetCurrMachining(MachiningFamily.Items(0).Name)
m_OldItem = MachiningFamily.Items(0)
GetMachiningParams()
ViewMachiningParams()
End If
End If
Next
End If
End Sub
Private Sub InitializeToolFamily(sFIniConst As String, nFType As Integer, sFName As String)
If GetPrivateProfileInt(S_MACHININGS, sFIniConst, 0, m_MainWindow.m_sMachIniFile) = 1 Then
Dim MachiningCathegory As New CathegoryItem(sFName, nFType)
Dim MachiningName As String = String.Empty
If EgtMdbGetFirstMachining(nFType, MachiningName) Then
MachiningCathegory.Items.Add(New CustomItem(MachiningName, nFType))
While EgtMdbGetNextMachining(nFType, MachiningName)
MachiningCathegory.Items.Add(New CustomItem(MachiningName, nFType))
End While
End If
MachiningsList.Add(MachiningCathegory)
End If
End Sub
Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
' Se necessario, chiedo se salvare ll lavorazione corrente
If Not SaveCurrMachining() Then
Exit Sub
End If
' Salvo il DB utensili
EgtMdbSave()
' Esco dalla pagina
m_MainWindow.m_MachinePageUC.MachinePageGrid.Children.Remove(m_MainWindow.m_MachinePageUC.m_MachiningDbPageUC)
m_MainWindow.m_MachinePageUC.MachinePageGrid.Children.Add(m_MainWindow.m_MachinePageUC.m_AlarmsPageUC)
m_MainWindow.m_MachinePageUC.m_ActiveMachinePage = MachinePageUC.MachinePages.Alarms
m_MainWindow.m_MachinePageUC.MachiningDBBtn.IsChecked = False
m_MainWindow.m_MachinePageUC.AlarmsBtn.IsChecked = True
End Sub
Private Sub GetMachiningParams()
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
Dim ToolString As String = String.Empty
Dim ToolInt As Integer = 0
Dim ToolDouble As Double = 0
Dim ToolBool As Boolean
EgtMdbGetCurrMachiningParam(MCH_MP.NAME, m_sMachiningName)
NameTxBx.Text = m_sMachiningName
EgtMdbGetCurrMachiningParam(MCH_MP.DEPTH_STR, ToolString)
DepthTxBx.Text = ToolString
EgtMdbGetCurrMachiningParam(MCH_MP.SIDEANGLE, ToolDouble)
SideAngleTxBx.Text = ToolDouble
EgtMdbGetCurrMachiningParam(MCH_MP.INVERT, ToolBool)
InvertChBx.IsChecked = ToolBool
EgtMdbGetCurrMachiningParam(MCH_MP.STEPTYPE, ToolInt)
StepTypeCmBx.SelectedIndex = ToolInt
EgtMdbGetCurrMachiningParam(MCH_MP.WORKSIDE, ToolInt)
WorkSideCmBx.SelectedIndex = ToolInt
EgtMdbGetCurrMachiningParam(MCH_MP.HEADSIDE, ToolInt)
HeadSideCmBx.SelectedIndex = ToolInt - 1
EgtMdbGetCurrMachiningParam(MCH_MP.LEADINTYPE, ToolInt)
LeadInTypeCmBx.SelectedIndex = ToolInt
EgtMdbGetCurrMachiningParam(MCH_MP.EXTLINKTYPE, ToolInt)
ExtLinkTypeCmBx.SelectedIndex = ToolInt
EgtMdbGetCurrMachiningParam(MCH_MP.LEADOUTTYPE, ToolInt)
LeadOutTypeCmBx.SelectedIndex = ToolInt
EgtMdbGetCurrMachiningParam(MCH_MP.CURVEUSE, ToolInt)
CurveUseCmBx.SelectedIndex = ToolInt
EgtMdbGetCurrMachiningParam(MCH_MP.APPROX, ToolDouble)
ApproxTxBx.Text = ToolDouble
EgtMdbGetCurrMachiningParam(MCH_MP.TOOL, ToolString)
Tool.Clear()
Dim ToolName As String = String.Empty
Dim nType As Integer = MCH_TY.NONE
If EgtTdbGetFirstTool(MCH_TF.SAWBLADE, ToolName, nType) Then
Tool.Add(ToolName)
While EgtTdbGetNextTool(MCH_TF.SAWBLADE, ToolName, nType)
Tool.Add(ToolName)
End While
End If
'For Index = 0 To Tool.Count - 1
' If Tool(Index) = ToolString Then
' ToolCmBx.SelectedIndex = Index
' Exit For
' End If
'Next
ToolCmBx.SelectedItem = ToolString
End Sub
Friend Sub SetMachiningParams()
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
Dim dTemp As Double
Dim bTemp As Boolean
EgtMdbSetCurrMachiningParam(MCH_MP.NAME, NameTxBx.Text)
EgtMdbSetCurrMachiningParam(MCH_MP.DEPTH_STR, DepthTxBx.Text)
StringToDouble(SideAngleTxBx.Text, dTemp)
EgtMdbSetCurrMachiningParam(MCH_MP.SIDEANGLE, dTemp)
bTemp = InvertChBx.IsChecked
EgtMdbSetCurrMachiningParam(MCH_MP.INVERT, bTemp)
EgtMdbSetCurrMachiningParam(MCH_MP.STEPTYPE, StepTypeCmBx.SelectedIndex)
EgtMdbSetCurrMachiningParam(MCH_MP.WORKSIDE, WorkSideCmBx.SelectedIndex)
EgtMdbSetCurrMachiningParam(MCH_MP.HEADSIDE, HeadSideCmBx.SelectedIndex + 1)
EgtMdbSetCurrMachiningParam(MCH_MP.LEADINTYPE, LeadInTypeCmBx.SelectedIndex)
EgtMdbSetCurrMachiningParam(MCH_MP.EXTLINKTYPE, ExtLinkTypeCmBx.SelectedIndex)
EgtMdbSetCurrMachiningParam(MCH_MP.LEADOUTTYPE, LeadOutTypeCmBx.SelectedIndex)
EgtMdbSetCurrMachiningParam(MCH_MP.CURVEUSE, CurveUseCmBx.SelectedIndex)
StringToDouble(ApproxTxBx.Text, dTemp)
EgtMdbSetCurrMachiningParam(MCH_MP.APPROX, dTemp)
EgtMdbSetCurrMachiningParam(MCH_MP.TOOL, ToolCmBx.SelectedItem.ToString)
End Sub
Private Sub ViewMachiningParams()
NameTxBl.Visibility = Windows.Visibility.Visible
NameTxBx.Visibility = Windows.Visibility.Visible
DepthTxBl.Visibility = Windows.Visibility.Visible
DepthTxBx.Visibility = Windows.Visibility.Visible
SideAngleTxBl.Visibility = Windows.Visibility.Visible
SideAngleTxBx.Visibility = Windows.Visibility.Visible
InvertTxBl.Visibility = Windows.Visibility.Visible
InvertChBx.Visibility = Windows.Visibility.Visible
StepTypeTxBl.Visibility = Windows.Visibility.Visible
StepTypeCmBx.Visibility = Windows.Visibility.Visible
SideBrd.Visibility = Windows.Visibility.Visible
TypeBrd.Visibility = Windows.Visibility.Visible
CurveBrd.Visibility = Windows.Visibility.Visible
End Sub
Private Sub HideMachiningParams()
NameTxBl.Visibility = Windows.Visibility.Hidden
NameTxBx.Visibility = Windows.Visibility.Hidden
DepthTxBl.Visibility = Windows.Visibility.Hidden
DepthTxBx.Visibility = Windows.Visibility.Hidden
SideAngleTxBl.Visibility = Windows.Visibility.Hidden
SideAngleTxBx.Visibility = Windows.Visibility.Hidden
InvertTxBl.Visibility = Windows.Visibility.Hidden
InvertChBx.Visibility = Windows.Visibility.Hidden
StepTypeTxBl.Visibility = Windows.Visibility.Hidden
StepTypeCmBx.Visibility = Windows.Visibility.Hidden
SideBrd.Visibility = Windows.Visibility.Hidden
TypeBrd.Visibility = Windows.Visibility.Hidden
CurveBrd.Visibility = Windows.Visibility.Hidden
End Sub
Private Sub MachiningTreeView_PreviewMouseUp(sender As Object, e As MouseButtonEventArgs) Handles MachiningTreeView.PreviewMouseUp
' Se necessario, chiedo se salvare l'utensile corrente
If Not SaveCurrMachining() Then
Dim PreviousMachining As CustomItem = m_OldItem
PreviousMachining.IsSelected = True
Exit Sub
End If
' Aggiorno
If TypeOf MachiningTreeView.SelectedItem Is CathegoryItem Then
Dim SelectedCathegory As CathegoryItem = MachiningTreeView.SelectedItem
SelectedCathegory.IsExpanded = Not SelectedCathegory.IsExpanded
HideMachiningParams()
ElseIf TypeOf MachiningTreeView.SelectedItem Is CustomItem Then
Dim SelectedMachining As CustomItem = MachiningTreeView.SelectedItem
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
EgtMdbSetCurrMachining(SelectedMachining.Name)
GetMachiningParams()
ViewMachiningParams()
End If
m_OldItem = MachiningTreeView.SelectedItem
End Sub
Friend Function SaveCurrMachining() As Boolean
SetMachiningParams()
If EgtMdbIsCurrMachiningModified() Then
Dim SaveCurrProj As New SaveCurrProjWD
SaveCurrProj.sTextString = "Salvare la lavorazione corrente?"
SaveCurrProj.ShowDialog()
Select Case SaveCurrProj.DialogResult
Case 0 ' Annulla
Return False
Case 1 ' Si
EgtMdbSaveCurrMachining()
Dim CurrMachining As CustomItem = TryCast(m_OldItem, CustomItem)
If CurrMachining IsNot Nothing Then
CurrMachining.Name = NameTxBx.Text
End If
Case 2 ' No
EgtMdbSetCurrMachining(m_sMachiningName)
GetMachiningParams()
End Select
End If
Return True
End Function
Private Sub NameTxBx_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) Handles NameTxBx.PreviewMouseDown
MachiningDrawTxBx.Text = NameTxBx.Text
Dim Keyboard As New Keyboard
Keyboard.Owner = m_MainWindow
Keyboard.m_CurrTxBx = MachiningDrawTxBx
Keyboard.m_CurrTxBl = NameTxBl.Text
' Imposto nome nel Title e valore nella TextBox
Keyboard.CurrTextTxBx.Text = Keyboard.m_CurrTxBx.Text
Keyboard.CurrNameTxBl.Text = Keyboard.m_CurrTxBl
' Imposto Dimensioni e posizione della tastiera
Keyboard.Top = m_MainWindow.Top + (m_MainWindow.Height / 2 - Keyboard.Height / 2)
Keyboard.Left = m_MainWindow.Left + (m_MainWindow.Width / 2 - Keyboard.Width / 2)
'Keyboard.Height = m_MainWindow.Height / 12 * 5
'Keyboard.Width = m_MainWindow.Width / 15 * 5
' Visualizzo
Keyboard.ShowDialog()
If MachiningDrawTxBx.Text <> m_sMachiningName Then
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
Dim TempName As String = MachiningDrawTxBx.Text
EgtTdbGetToolNewName(TempName)
If TempName = MachiningDrawTxBx.Text Then
NameTxBx.Text = MachiningDrawTxBx.Text
Else
MsgBox("Nome già utilizzato")
End If
Else
NameTxBx.Text = m_sMachiningName
End If
MachiningDrawTxBx.Text = String.Empty
End Sub
Private Sub DepthTxBx_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) Handles DepthTxBx.PreviewMouseDown
MachiningDrawTxBx.Text = DepthTxBx.Text
Dim Keyboard As New Keyboard
Keyboard.Owner = m_MainWindow
Keyboard.m_CurrTxBx = MachiningDrawTxBx
Keyboard.m_CurrTxBl = DepthTxBl.Text
' Imposto nome nel Title e valore nella TextBox
Keyboard.CurrTextTxBx.Text = Keyboard.m_CurrTxBx.Text
Keyboard.CurrNameTxBl.Text = Keyboard.m_CurrTxBl
' Imposto Dimensioni e posizione della tastiera
Keyboard.Top = m_MainWindow.Top + (m_MainWindow.Height / 2 - Keyboard.Height / 2)
Keyboard.Left = m_MainWindow.Left + (m_MainWindow.Width / 2 - Keyboard.Width / 2)
'Keyboard.Height = m_MainWindow.Height / 12 * 5
'Keyboard.Width = m_MainWindow.Width / 15 * 5
' Visualizzo
Keyboard.ShowDialog()
'If MachiningDrawTxBx.Text <> m_sMachiningName Then
' EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
' Dim TempName As String = MachiningDrawTxBx.Text
' EgtTdbGetToolNewName(TempName)
' If TempName = MachiningDrawTxBx.Text Then
' NameTxBx.Text = MachiningDrawTxBx.Text
' Else
' MsgBox("Nome già utilizzato")
' End If
'Else
' NameTxBx.Text = m_sMachiningName
'End If
DepthTxBx.Text = MachiningDrawTxBx.Text
MachiningDrawTxBx.Text = String.Empty
End Sub
End Class