Files
EgtCAM5/OptionPanel/MachiningOptionPanel/OperationExpander/OperationExpanderV.xaml.vb
T
Dario Sassi b5b9e459eb EgtCAM5 2.1g2 .
- correzioni nella gestione della lista lavorazioni (tolta virtualizzazione).
2019-07-08 07:20:31 +00:00

194 lines
9.3 KiB
VB.net

Imports EgtWPFLib5
Imports EgtWPFLib5.EgtFloating
Public Class OperationExpanderV
Private m_OperationExpanderVM As OperationExpanderVM
Private EgtFloatingTray As EgtFloatingTray
Private OptionPanelView As UserControl
Private OptionPanelViewStackPanel As StackPanel
'Private OperationParameters As ContentPresenter
Private MachiningTreeContentPresenter As ContentPresenter
Private MachiningTreeUserControl As UserControl
Private MachiningTreeExpander As Expander
Private SimulationContentPresenter As ContentPresenter
Private SimulationUserControl As UserControl
Private SimulationExpanderStackPanel As StackPanel
Private SimulationExpander As Expander
Private GenerateButton As Button
Private m_bFirst As Boolean = True
#Region "CONSTRUCTOR"
Sub New()
' Funzione che interpreta l'xaml
InitializeComponent()
' Assegno al riferimento locale al VM il VM preso dal DataContext
m_OperationExpanderVM = DirectCast(Me.DataContext, OperationExpanderVM)
End Sub
#End Region ' CONSTRUCTOR
#Region "EVENTS"
Private Sub MachiningOpListBoxItem_LostKeyboardFocus(sender As Object, e As KeyboardFocusChangedEventArgs)
Dim TextBox As TextBox = TryCast(sender, TextBox)
If IsNothing(TextBox) Then Return
Dim SelOp As MachiningOpListBoxItem = TryCast(TextBox.DataContext, MachiningOpListBoxItem)
If IsNothing(SelOp) Then Return
If MachiningOpListBoxItem.m_CloseModifyLostFocus Then
SelOp.ModifyNameEsc()
Else
If MachiningOpListBoxItem.m_Spy Then
MachiningOpListBoxItem.m_CloseModifyLostFocus = True
MachiningOpListBoxItem.m_Spy = False
End If
Keyboard.Focus(TextBox)
End If
End Sub
Private Sub MachiningOpListBoxItem_IsVisibleChanged(sender As Object, e As DependencyPropertyChangedEventArgs)
Dim bNewVal As Boolean = false
Try
bNewVal = CType( e.NewValue, Boolean)
Catch
End Try
If bNewVal Then
Dim inElem As IInputElement = TryCast( sender, IInputElement)
If Not IsNothing( inElem) Then Keyboard.Focus(inElem)
End If
End Sub
#End Region ' EVENTS
Private Sub OperationExpanderView_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
If m_bFirst Then
EgtFloatingTray = FindAncestor(Of EgtFloatingTray)(Me)
OptionPanelView = FindAncestor(Of UserControl)(Me)
OptionPanelViewStackPanel = DirectCast(OptionPanelView.Content, StackPanel)
MachiningTreeContentPresenter = DirectCast(OptionPanelViewStackPanel.Children(1), ContentPresenter)
MachiningTreeUserControl = DirectCast(MachiningTreeContentPresenter.Content, UserControl)
MachiningTreeExpander = DirectCast(MachiningTreeUserControl.Content, Expander)
SimulationContentPresenter = DirectCast(OptionPanelViewStackPanel.Children(2), ContentPresenter)
SimulationUserControl = DirectCast(SimulationContentPresenter.Content, UserControl)
SimulationExpanderStackPanel = DirectCast(SimulationUserControl.Content, StackPanel)
SimulationExpander = DirectCast(SimulationExpanderStackPanel.Children(0), Expander)
GenerateButton = DirectCast(SimulationExpanderStackPanel.Children(2), Button)
' Gestisco l'evento SizeChanged della Tray
AddHandler EgtFloatingTray.SizeChanged, AddressOf OperationExpanderTray_SizeChanged
m_bFirst = False
End If
CalculateOperationParametersStackPanelMaxHeight()
End Sub
Private Sub OperationExpanderTray_SizeChanged(sender As Object, e As System.Windows.SizeChangedEventArgs)
CalculateOperationParametersStackPanelMaxHeight()
'For Each Expander In OperationParametersStackPanel.Children
' If TypeOf Expander Is Expander Then
' Dim CurrExpander As Expander = DirectCast(Expander, Expander)
' CurrExpander.IsExpanded = False
' End If
'Next
End Sub
Private Sub CalculateOperationParametersStackPanelMaxHeight()
Dim OccupiedHeight As Double = 0
If Not MachiningTreeExpander.IsExpanded Then
OccupiedHeight += MachiningTreeExpander.ActualHeight
Else
Dim MachiningTreeExpanderContent As FrameworkElement = DirectCast(MachiningTreeExpander.Content, FrameworkElement)
MachiningTreeExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
OccupiedHeight += (MachiningTreeExpander.ActualHeight - MachiningTreeExpanderContent.DesiredSize.Height)
End If
If Not SimulationExpander.IsExpanded Then
OccupiedHeight += SimulationExpander.ActualHeight
Else
Dim SimulationExpanderContent As FrameworkElement = DirectCast(SimulationExpander.Content, FrameworkElement)
SimulationExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
OccupiedHeight += (SimulationExpander.ActualHeight - SimulationExpanderContent.DesiredSize.Height)
End If
OccupiedHeight += GenerateButton.ActualHeight
'Aggiungo altezza OperationsList header Expander
If Not OperationsListExpander.IsExpanded Then
OccupiedHeight += OperationsListExpander.ActualHeight
Else
Dim OperationsListExpanderContent As FrameworkElement = DirectCast(OperationsListExpander.Content, FrameworkElement)
OperationsListExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
OccupiedHeight += (OperationsListExpander.ActualHeight - OperationsListExpanderContent.DesiredSize.Height)
End If
If Not OperationParametersExpander.IsExpanded Then
OccupiedHeight += OperationParametersExpander.ActualHeight
Else
Dim OperationParametersExpanderContent As FrameworkElement = DirectCast(OperationParametersExpander.Content, FrameworkElement)
OperationParametersExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
OccupiedHeight += (OperationParametersExpander.ActualHeight - OperationParametersExpanderContent.DesiredSize.Height)
End If
'' Aggiungo altezza contenuto OperationParameters che però è fuori dallo Stackpanel
'OperationFirstParametersStackPanel.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
'If OperationFirstParametersStackPanel.DesiredSize.Height <> 0 Then
' OccupiedHeight += OperationFirstParametersStackPanel.DesiredSize.Height
'Else
' ' aggiungo il valore calcolato provando se non viene calcolato dal sistema al momento
' OccupiedHeight += 10
'End If
'OperationParametersStackPanel.MaxHeight = OptionPanelViewStackPanel.MaxHeight - OccupiedHeight
End Sub
' Funzione che permette di trovare il primo contenitore di tipo T di un elemento grafico dependencyObject
Public Function FindAncestor(Of T As Class)(dependencyObject As DependencyObject) As T
Dim target As DependencyObject = dependencyObject
Do
target = LogicalTreeHelper.GetParent(target)
Loop While target IsNot Nothing AndAlso Not (TypeOf target Is T)
If IsNothing(target) Then
target = dependencyObject
Do
target = VisualTreeHelper.GetParent(target)
Loop While target IsNot Nothing AndAlso Not (TypeOf target Is T)
End If
Return TryCast(target, T)
End Function
'Private Sub OperationList_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles OperationList.SelectionChanged
' Dim indexes As New List(Of Integer)()
' For index As Integer = 0 To OperationList.Items.Count - 1
' ' Verifico gli elementi selezionati e che tra di essi non vi siano Disposizioni
' If (OperationList.Items.Item(index).IsSelected And
' Not EgtUILib.EgtInterface.EgtGetOperationType(OperationList.Items.Item(index).Id).Equals(EgtUILib.EgtInterface.MCH_OY.DISP)) Then
' indexes.Add(index)
' End If
' Next
' Dim len As Integer = indexes.Count
' If len > 1 Then
' For index As Integer = 1 To len - 1
' If (indexes(index) - indexes(index - 1) = 1) Then
' btn_MoveUp.IsEnabled = True
' btn_MoveDown.IsEnabled = True
' Else
' btn_MoveUp.IsEnabled = False
' btn_MoveDown.IsEnabled = False
' Exit For
' End If
' Next
' End If
' ' Verifico se appena prima del primo indice selezionato o appena dopo l'ultimo selezionato ci sia una Disposizione
' If (EgtUILib.EgtInterface.EgtGetOperationType(OperationList.Items.Item(indexes(len - 1) + 1).Id).Equals(EgtUILib.EgtInterface.MCH_OY.DISP)) Then
' btn_MoveDown.IsEnabled = False
' Else
' btn_MoveDown.IsEnabled = True
' End If
' If (EgtUILib.EgtInterface.EgtGetOperationType(OperationList.Items.Item(indexes(0) - 1).Id).Equals(EgtUILib.EgtInterface.MCH_OY.DISP)) Then
' btn_MoveUp.IsEnabled = False
' Else
' btn_MoveUp.IsEnabled = True
' End If
'End Sub
''Private Sub OperationList_SelectedIndexChanged(sender As Object, e As SelectionChangedEventArgs)
''End Sub
End Class