Imports EgtUILib Imports System.IO Public Class MachiningOptionPanelVM Inherits ViewModelBase ' GRAPHICAL ELEMENTS Private m_OperationsListExpander As OperationsListExpanderV Public ReadOnly Property OperationsListExpander As ContentControl Get If IsNothing(m_OperationsListExpander) Then m_OperationsListExpander = New OperationsListExpanderV With { .DataContext = New OperationsListExpanderVM} End If Map.refOperationsListExpanderVM.LoadOperationList(GDB_ID.NULL) Return m_OperationsListExpander End Get End Property Private m_OperationParametersExpander As OperationParametersExpanderV Public ReadOnly Property OperationParametersExpander As ContentControl Get If IsNothing(m_OperationParametersExpander) Then m_OperationParametersExpander = New OperationParametersExpanderV With { .DataContext = New OperationParametersExpanderVM} End If Return m_OperationParametersExpander End Get End Property Private m_MachiningsTreeExpander As MachiningTreeExpanderV Public ReadOnly Property MachiningsTreeExpander As ContentControl Get If IsNothing(m_MachiningsTreeExpander) Then m_MachiningsTreeExpander = New MachiningTreeExpanderV m_MachiningsTreeExpander.DataContext = New MachiningTreeExpanderVM End If Return m_MachiningsTreeExpander End Get End Property Private m_SimulationExpander As SimulationExpanderV Public ReadOnly Property SimulationExpander As ContentControl Get If IsNothing(m_SimulationExpander) Then m_SimulationExpander = New SimulationExpanderV m_SimulationExpander.DataContext = New SimulationExpanderVM End If Map.refSimulationExpanderVM.Simulation_IsEnabled = True Return m_SimulationExpander End Get End Property Private m_EstimationsExpander As EstimationsExpanderV Public ReadOnly Property EstimationsExpander As ContentControl Get If IsNothing(m_EstimationsExpander) Then m_EstimationsExpander = New EstimationsExpanderV m_EstimationsExpander.DataContext = New EstimationsExpanderVM End If Map.refEstimationsExpanderVM.Estimation_IsEnabled = (EgtUILib.GetPrivateProfileInt(S_ESTIMATIONS, K_EST_ENABLE, 0, IniFile.m_sCurrMachIniFilePath) <> 0) Return m_EstimationsExpander End Get End Property 'Expander aperto tra quelli presenti nel MachiningOptionPanel Friend Enum MachiningOptionPanelExpander NONE OPERATIONLIST OPERATIONPARAMETERS NEWMACHININGS SIMULATION ESTIMATIONS End Enum Friend Sub Set_IsExpanded(exp As MachiningOptionPanelExpander, flag As Boolean) If flag Then OpenExpander = exp Else ' se il flag passato è False vuol dire che nessun Expander è attualmente aperto OpenExpander = MachiningOptionPanelExpander.NONE End If End Sub Private m_OpenExpander As Integer = MachiningOptionPanelExpander.OPERATIONLIST Public Property OpenExpander As Integer Get Return m_OpenExpander End Get Set(value As Integer) Dim bOk As Boolean = False ' Esco dallo stato corrente Select Case m_OpenExpander Case MachiningOptionPanelExpander.OPERATIONLIST bOk = Map.refOperationsListExpanderVM.ExitOperationsList() Case MachiningOptionPanelExpander.OPERATIONPARAMETERS bOk = Map.refOperationParametersExpanderVM.ExitOperationParameters() Case MachiningOptionPanelExpander.NEWMACHININGS bOk = Map.refOperationsListExpanderVM.ExitOperationsList() bOk = Map.refMachiningTreeExpanderVM.ExitMachiningTreeExpander() Case MachiningOptionPanelExpander.SIMULATION bOk = Map.refSimulationExpanderVM.ExitSimulation() Case MachiningOptionPanelExpander.ESTIMATIONS bOk = Map.refEstimationsExpanderVM.ExitEstimations() Case MachiningOptionPanelExpander.NONE bOk = True End Select If bOk Then ' Entro nel nuovo stato m_OpenExpander = value Select Case m_OpenExpander Case MachiningOptionPanelExpander.OPERATIONLIST Map.refOperationsListExpanderVM.InitOperationsList() Case MachiningOptionPanelExpander.OPERATIONPARAMETERS Map.refOperationParametersExpanderVM.InitOperationParameters() Case MachiningOptionPanelExpander.NEWMACHININGS Map.refOperationsListExpanderVM.InitOperationsList() Map.refMachiningTreeExpanderVM.InitMachiningTreeExpander() Case MachiningOptionPanelExpander.SIMULATION Map.refSimulationExpanderVM.InitSimulation() Case MachiningOptionPanelExpander.ESTIMATIONS Map.refEstimationsExpanderVM.InitEstimations() End Select OnPropertyChanged("OpenExpander") End If End Set End Property Public ReadOnly Property GenerateIsEnabled As Boolean Get Return Not Map.refSimulationExpanderVM.Simulation_IsExpanded End Get End Property Private m_OperationsListRowIsExpanded As Boolean = True Public ReadOnly Property OperationsListRowIsExpanded As Boolean Get Return m_OperationsListRowIsExpanded End Get End Property Friend Sub SetOperationsListRowIsExpanded(value As Boolean) m_OperationsListRowIsExpanded = value OnPropertyChanged("OperationsListRowIsExpanded") End Sub #Region "Messages" Public ReadOnly Property GenerateMsg As String Get Return EgtMsg(MSG_SIMULATION + 30) 'GENERA End Get End Property #End Region #Region "CONSTRUCTOR" Sub New() ' Creo riferimento a questa classe in Map Map.SetRefMachiningOptionPanelVM(Me) End Sub #End Region ' CONSTRUCTOR #Region "METHODS" Friend Function InitMachiningOptionPanel() As Boolean 'EgtZoom(ZM.ALL) Return True End Function Friend Function ExitMachiningOptionPanel() As Boolean Return True End Function #End Region ' METHODS #Region "COMMANDS" ' Definizione comandi Private m_cmdGenerate As ICommand #Region "GenerateCommand" ''' ''' Returns a command that create a new tool. ''' Public ReadOnly Property GenerateCommand As ICommand Get If m_cmdGenerate Is Nothing Then m_cmdGenerate = New RelayCommand(AddressOf Generate) End If Return m_cmdGenerate End Get End Property ''' ''' Creata the new tool. This method is invoked by the NewCommand. ''' Public Sub Generate(ByVal param As Object) Map.refSimulationExpanderVM.Generate(param) End Sub #End Region ' GenerateCommand #End Region ' COMMANDS #Region "DEPENCY PROPERTY" Public Shared ReadOnly IsExpandedProperty As DependencyProperty = DependencyProperty.RegisterAttached( "IsExpanded", GetType(Boolean), GetType(MachiningOptionPanelVM), New PropertyMetadata(True, AddressOf OnIsExpandedChanged) ) Public Shared Sub SetIsExpanded(element As DependencyObject, value As Boolean) element.SetValue(IsExpandedProperty, value) End Sub Public Shared Function GetIsExpanded(element As DependencyObject) As Boolean Return CType(element.GetValue(IsExpandedProperty), Boolean) End Function Public Shared Function GetTargetSplitter(d As DependencyObject) As GridSplitter Return CType(d.GetValue(TargetSplitterProperty), GridSplitter) End Function Public Shared Sub SetTargetSplitter(d As DependencyObject, value As GridSplitter) d.SetValue(TargetSplitterProperty, value) End Sub Public Shared ReadOnly TargetSplitterProperty As DependencyProperty = DependencyProperty.RegisterAttached( "TargetSplitter", GetType(GridSplitter), GetType(MachiningOptionPanelVM), New PropertyMetadata(Nothing) ) Private Shared Sub OnIsExpandedChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs) Dim row As RowDefinition = TryCast(d, RowDefinition) If IsNothing(row) Then Return Dim isExpanded As Boolean = CBool(e.NewValue) Dim splitter = MachiningOptionPanelVM.GetTargetSplitter(row) If Not IsNothing(splitter) Then splitter.IsEnabled = isExpanded splitter.Visibility = If(isExpanded, Visibility.Visible, Visibility.Collapsed) End If If Not isExpanded Then row.ClearValue(RowDefinition.HeightProperty) row.Height = New GridLength(1, GridUnitType.Auto) row.MinHeight = 0 Else If File.Exists(Map.refMainWindowVM.DimensionDir) Then DynamicGridModule.RestoreMachiningGridLayout(Map.refMachiningOptionPanelV.MachiningGrid, If(IniFile.IsActivePlugin(), DynamicGridModule.PROJECT_MACHINING_PLUGIN, DynamicGridModule.PROJECT_MACHINING)) Map.refMachiningOptionPanelV.MachiningGrid.UpdateLayout() Else row.Height = New GridLength(350) End If End If End Sub #End Region ' Depency Property End Class