Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 0bacecca authored by Harald Martini's avatar Harald Martini
Browse files

Stored Editing Enabled in ViewModel,

Fixed issue with combobox bindings
parent dd1038a1
No related branches found
No related tags found
No related merge requests found
Showing
with 459 additions and 144 deletions
......@@ -10,6 +10,7 @@ using VECTO3GUI2020.Helper;
using VECTO3GUI2020.Model.Implementation;
using VECTO3GUI2020.Ninject;
using VECTO3GUI2020.Ninject.Vehicle;
using VECTO3GUI2020.ViewModel;
namespace VECTO3GUI2020
{
......@@ -44,7 +45,7 @@ namespace VECTO3GUI2020
container.Bind<IMainWindowViewModel>().To<MainWindowViewModel>();
container.Bind<IMainViewModel>().To<JobListViewModel>();
container.Bind<ISettingsViewModel>().To<SettingsViewModel>();
container.Bind<IOutputViewModel>().To<OutputViewModel>().InSingletonScope();
container.Bind<ISettingsModel>().To<SettingsModel>();
container.Bind<IDialogHelper>().To<DialogHelper>().InSingletonScope();
......
using System;
using System.Globalization;
using System.Windows.Data;
namespace VECTO3GUI2020.Helper.Converter
{
public class BoolToIntConverter : IValueConverter
{
#region Implementation of IValueConverter
/// <summary>
/// Returns -1 if value is false, 0 if value is true
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value == false ? -1 : 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
#endregion
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VECTO3GUI2020.Helper
{
//Helper class that can be used to store values of the same type that are identified by a string
public class IndexedStorage<T> where T : IEquatable<T>
{
private Dictionary<string, T> indexedStorageDictionary = new Dictionary<string, T>();
private readonly Action _onValueChanged;
public IndexedStorage(Action onValueChanged = null)
{
_onValueChanged = onValueChanged;
}
public T this[string identifier]
{
get
{
if (!indexedStorageDictionary.ContainsKey(identifier))
{
indexedStorageDictionary.Add(identifier, default(T));
}
return indexedStorageDictionary[identifier];
}
set
{
var oldValue = default(T);
if (indexedStorageDictionary.ContainsKey(identifier))
{
oldValue = indexedStorageDictionary[identifier];
}
else
{
indexedStorageDictionary.Add(identifier, default(T));
}
indexedStorageDictionary[identifier] = value;
if (value.Equals(oldValue))
{
_onValueChanged?.Invoke();
}
}
}
}
}
using System;
using System.Windows.Markup;
namespace VECTO3GUI2020.Helper
{
public class NameOfMarkUpExtension : MarkupExtension
{
#region Overrides of MarkupExtension
public override object ProvideValue(IServiceProvider serviceProvider)
{
throw new NotImplementedException();
return null;
}
#endregion
}
}
\ No newline at end of file
......@@ -19,11 +19,11 @@
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="1.5*"/>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<StackPanel Orientation="Vertical">
<StackPanel Grid.Row="0" Orientation="Vertical">
<Menu x:Name="menu" IsMainMenu="True">
<MenuItem Header="File" VerticalAlignment="Stretch">
<MenuItem Header="Settings" Command="{Binding OpenSettings}"/>
......@@ -32,15 +32,11 @@
</MenuItem>
</Menu>
</StackPanel>
</Grid>
<Grid Grid.Row="1" Margin="0,4,0,0">
<ContentControl Content="{Binding CurrentViewModelTop}"/>
</Grid>
<Grid Grid.Row="2" Margin="0,0,0,0">
<ContentControl Name="ContentControlBottom" Content="{Binding CurrentViewModelBottom}" Visibility="Collapsed"/>
</Grid>
<ContentControl Grid.Row="1" Margin="0, 4, 0 0" Content="{Binding CurrentViewModelTop}"/>
<GridSplitter Grid.Row="2" HorizontalAlignment="Stretch" Height="5"/>
<ContentControl Grid.Row="3" Margin="0,0,0,0" Name="ContentControlBottom" Content="{Binding CurrentViewModelBottom}"/>
</Grid>
</Window>
......@@ -15,5 +15,6 @@
<converter:XToBoolConverter x:Key="XToBoolConverter"/>
<converter:EnumConverter x:Key="EnumConverter"></converter:EnumConverter>
<converter:NullToUnsetValueConverter x:Key="NullToUnsetValue"></converter:NullToUnsetValueConverter>
<converter:BoolToIntConverter x:Key="BoolToIntConverter"></converter:BoolToIntConverter>
</ResourceDictionary>
......@@ -40,161 +40,161 @@
<!--#region HeavyLorry -->
<DataTemplate DataType="{x:Type vehicleimpl:VehicleViewModel_v1_0 }">
<DataTemplate x:Shared="False" DataType="{x:Type vehicleimpl:VehicleViewModel_v1_0 }">
<vehicleviews:VehicleView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type vehicleimpl:VehicleViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type vehicleimpl:VehicleViewModel_v2_0}">
<vehicleviews:VehicleView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:CommonComponentViewModel}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:CommonComponentViewModel}">
<componentviews:CommonComponentView/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:EngineViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:EngineViewModel_v2_0}">
<componentviews:EngineView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:EngineViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:EngineViewModel_v1_0}">
<componentviews:EngineView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AirDragViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AirDragViewModel_v2_0}">
<componentviews:AirDragView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AirDragViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AirDragViewModel_v1_0}">
<componentviews:AirDragView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AxleWheelsViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AxleWheelsViewModel_v1_0}">
<componentviews:AxleWheelsView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AxleWheelsViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AxleWheelsViewModel_v2_0}">
<componentviews:AxleWheelsView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AxleGearViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AxleGearViewModel_v1_0}">
<componentviews:AxleGearView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentviews:AxleGearView_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentviews:AxleGearView_v2_0}">
<componentviews:AxleGearView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:RetarderViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:RetarderViewModel_v1_0}">
<componentviews:RetarderView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:RetarderViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:RetarderViewModel_v2_0}">
<componentviews:RetarderView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:GearboxViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:GearboxViewModel_v1_0}">
<componentviews:GearboxView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:GearboxViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:GearboxViewModel_v2_0}">
<componentviews:GearboxView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AuxiliariesViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AuxiliariesViewModel_v1_0}">
<componentviews:AuxiliariesView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AuxiliariesViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AuxiliariesViewModel_v2_0}">
<componentviews:AuxiliariesView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AuxiliariesViewModel_v2_3}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AuxiliariesViewModel_v2_3}">
<componentviews:AuxiliariesView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AxleViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AxleViewModel_v1_0}">
<componentviews:AxleView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AxleViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AxleViewModel_v2_0}">
<componentviews:AxleView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:TyreViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:TyreViewModel_v1_0}">
<componentviews:TyreView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:TyreViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:TyreViewModel_v2_0}">
<componentviews:TyreView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:TyreViewModel_v2_2}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:TyreViewModel_v2_2}">
<componentviews:TyreView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:TyreViewModel_v2_3}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:TyreViewModel_v2_3}">
<componentviews:TyreView_v2_3/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:GearViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:GearViewModel_v1_0}">
<componentviews:GearView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:GearViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:GearViewModel_v2_0}">
<componentviews:GearView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:PTOViewModel_V1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:PTOViewModel_V1_0}">
<componentviews:PTOView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:PTOViewModel_V2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:PTOViewModel_V2_0}">
<componentviews:PTOView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AngleDriveViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AngleDriveViewModel_v1_0}">
<componentviews:AngleDriveView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AngleDriveViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AngleDriveViewModel_v2_0}">
<componentviews:AngleDriveView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AuxiliaryViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AuxiliaryViewModel_v1_0}">
<componentviews:AuxiliaryView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AuxiliaryViewModel_v2_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AuxiliaryViewModel_v2_0}">
<componentviews:AuxiliaryView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:AuxiliaryViewModel_v2_3}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AuxiliaryViewModel_v2_3}">
<componentviews:AuxiliaryView_v2_0/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:ADASViewModel_v1_0}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:ADASViewModel_v1_0}">
<componentviews:ADASView_v2_3/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:ADASViewModel_v2_1}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:ADASViewModel_v2_1}">
<componentviews:ADASView_v2_3/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:ADASViewModel_v2_3}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:ADASViewModel_v2_3}">
<componentviews:ADASView_v2_3/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:EngineModeViewModelSingleFuel}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:EngineModeViewModelSingleFuel}">
<componentviews:EngineModeViewSingleFuel/>
</DataTemplate>
<DataTemplate DataType="{x:Type componentimpl:EngineFuelViewModel}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:EngineFuelViewModel}">
<componentviews:EngineFuelView/>
</DataTemplate>
<!--#endregion-->
<DataTemplate DataType="{x:Type componentimpl:AirDragViewModel_v2_8}">
<DataTemplate x:Shared="False" DataType="{x:Type componentimpl:AirDragViewModel_v2_8}">
<multistageviews:AirDragView_v2_8></multistageviews:AirDragView_v2_8>
</DataTemplate>
......
......@@ -13,12 +13,12 @@
<!--https://www.thomasclaudiushuber.com/2008/01/10/bind-to-methods-with-objectdataprovider/-->
<StackPanel>
<customControls:MultiStageParameter Content="{Binding ConvertedSI}" DummyContent="{Binding Source={StaticResource milimeterDummy}}"/>
<!--<customControls:MultiStageParameter Content="{Binding ConvertedSI}" DummyContent="{Binding Source={StaticResource milimeterDummy}}"/>
<customControls:MultiStageParameter Content="{Binding ConvertedSI1}" DummyContent="{Binding Source={StaticResource milimeterDummy}}"/>
<customControls:MultiStageParameter Content="{Binding Meter}"/>
<customControls:MultiStageParameter Mode="COMBOBOX" Content="{Binding HeatPumpMode}" ListItems="{Binding HeatPumpModeListItems}"></customControls:MultiStageParameter>
<customControls:MultiStageParameter Mode="COMBOBOX" Content="{Binding HeatPumpMode2}"></customControls:MultiStageParameter>
<customControls:MultiStageParameter Mode="TEXTBOX" Content="{Binding TestString, ValidatesOnExceptions=True}"></customControls:MultiStageParameter>
<customControls:MultiStageParameter Content="{Binding Meter}"/>-->
<customControls:MultiStageParameter Mode="COMBOBOX" Content="{Binding HeatPumpMode}" EditingEnabled="{Binding enabled}" ListItems="{Binding HeatPumpModeListItems}"></customControls:MultiStageParameter>
<!--<customControls:MultiStageParameter Mode="COMBOBOX" Content="{Binding HeatPumpMode2}" EditingEnabled="{Binding enabled}"></customControls:MultiStageParameter>-->
<!--<customControls:MultiStageParameter Mode="TEXTBOX" Content="{Binding TestString, ValidatesOnExceptions=True}"></customControls:MultiStageParameter>-->
</StackPanel>
</Grid>
</UserControl>
......@@ -59,7 +59,8 @@ namespace VECTO3GUI2020
};
private HeatPumpMode? _heatpumpMode2;
private bool _enabled;
public bool enabled { get => _enabled; set => SetProperty(ref _enabled, value); }
public HeatPumpMode? HeatPumpMode2
{
get => _heatpumpMode2;
......@@ -86,7 +87,8 @@ namespace VECTO3GUI2020
public TestViewModel()
{
_enabled = true;
}
}
}
......@@ -148,6 +148,7 @@
<Compile Include="Helper\Converter\JobTypeStringConverter.cs" />
<Compile Include="Helper\Converter\LabledTextBoxLabelConverter.cs" />
<Compile Include="Helper\Converter\MultistageParameterModeToVisibilityConverter.cs" />
<Compile Include="Helper\Converter\BoolToIntConverter.cs" />
<Compile Include="Helper\Converter\NullToUnsetValueConverter.cs" />
<Compile Include="Helper\Converter\NullToVisibilityConverter.cs" />
<Compile Include="Helper\Converter\LabledTextBoxConverter.cs" />
......@@ -158,8 +159,10 @@
<Compile Include="Helper\DoubleValidation.cs" />
<Compile Include="Helper\Exceptions.cs" />
<Compile Include="Helper\EnumHelper.cs" />
<Compile Include="Helper\IndexedStorage.cs" />
<Compile Include="Helper\IWindowHelper.cs" />
<Compile Include="Helper\DialogHelper.cs" />
<Compile Include="Helper\NameOfMarkUpExtension.cs" />
<Compile Include="Helper\WindowHelper.cs" />
<Compile Include="Helper\XMLExtension.cs" />
<Compile Include="Helper\XmlHelper.cs" />
......@@ -291,6 +294,7 @@
<Compile Include="ViewModel\MultiStage\Implementation\MultistageJobViewModel_v0_1.cs" />
<Compile Include="ViewModel\MultiStage\Interfaces\IMultistageAirdragViewModel.cs" />
<Compile Include="ViewModel\MultiStage\Interfaces\IMultiStageViewModelFactory.cs" />
<Compile Include="ViewModel\Implementation\OutputViewModel.cs" />
<Compile Include="Views\CustomControls\ComboParameter.xaml.cs">
<DependentUpon>ComboParameter.xaml</DependentUpon>
</Compile>
......
......@@ -4,6 +4,7 @@ using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
......@@ -61,6 +62,8 @@ namespace VECTO3GUI2020.ViewModel.Implementation
private IMultiStageViewModelFactory _multiStageViewModelFactory;
private IAsyncRelayCommand _addJobAsync;
private readonly IXMLInputDataReader _inputDataReader;
private IAsyncRelayCommand _simulationCommand;
private readonly IOutputViewModel _outputViewModel;
#endregion
......@@ -79,13 +82,14 @@ namespace VECTO3GUI2020.ViewModel.Implementation
IXMLInputDataReader inputDataReader,
IDialogHelper dialogHelper,
IWindowHelper windowHelper,
IMultiStageViewModelFactory multiStageViewModelFactory) : this()
IMultiStageViewModelFactory multiStageViewModelFactory, IOutputViewModel outputViewModel) : this()
{
_documentViewModelFactory = documentViewModelFactory;
_dialogHelper = dialogHelper;
_windowHelper = windowHelper;
_inputDataReader = inputDataReader;
_multiStageViewModelFactory = multiStageViewModelFactory;
_outputViewModel = outputViewModel;
}
......@@ -116,7 +120,21 @@ namespace VECTO3GUI2020.ViewModel.Implementation
#region Commands
public ICommand NewManufacturingStageFile
public IAsyncRelayCommand SimulationCommand
{
get => _simulationCommand ?? new AsyncRelayCommand(RunSimulationAsync, () => true);
}
private Task RunSimulationAsync(CancellationToken arg)
{
_outputViewModel.Messages.Add("hi");
return null;
}
public ICommand NewManufacturingStageFile
{
get
{
......
......@@ -50,7 +50,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation
}
#region CommandImplementations
#region CommandImplementations
#region CommandOpenSettings
public ICommand OpenSettings
{
......
using System;
using System.Collections.ObjectModel;
using System.Windows.Data;
using VECTO3GUI2020.ViewModel.Implementation.Common;
using VECTO3GUI2020.ViewModel.Interfaces.Common;
namespace VECTO3GUI2020.ViewModel
{
public class OutputViewModel : ViewModelBase, IOutputViewModel
{
private object _messageLock = new Object();
private ObservableCollection<string> _messages = new ObservableCollection<string>();
public ObservableCollection<string> Messages
{
get
{
return _messages;
}
}
public OutputViewModel()
{
BindingOperations.EnableCollectionSynchronization(Messages, _messageLock );
}
}
public interface IOutputViewModel
{
ObservableCollection<string> Messages { get; }
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
......@@ -139,6 +140,8 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
_multiStageViewModelFactory.GetAuxiliariesViewModel(consolidatedVehicleData?.Components?
.BusAuxiliaries);
AirdragModifiedMultistageEditingEnabled = false;
_editingEnabledDictionary = new IndexedStorage<bool>(() => OnPropertyChanged(nameof(EditingEnabledDictionary)));
}
public IVehicleDeclarationInputData ConsolidatedVehicleData
......@@ -418,6 +421,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
}
set {
AirdragModifiedMultistage = value?.toNullableBool();
}
}
......@@ -874,5 +878,21 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
}
}
#endregion
private IndexedStorage<bool> _editingEnabledDictionary;
public IndexedStorage<bool> EditingEnabledDictionary
{
get
{
return _editingEnabledDictionary;
}
}
}
}
\ No newline at end of file
......@@ -76,6 +76,16 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
set => SetProperty(ref _primaryVehicleHybridElectric, value);
}
private IndexedStorage<bool> _editingEnabledDictionary;
public IndexedStorage<bool> EditingEnabledDictionary
{
get
{
return _editingEnabledDictionary;
}
}
#region HVAC
......@@ -182,12 +192,12 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
if (value == HeatPumpType.none) {
HeatPumpModeDriverCompartmentAllowedValues =
EnumHelper.GetValuesAsObservableCollectionIncluding<Enum, HeatPumpMode>(items:HeatPumpMode.N_A);
//HeatPumpModeDriverCompartment = HeatPumpMode.N_A;
} else {
HeatPumpModeDriverCompartmentAllowedValues =
EnumHelper.GetValuesAsObservableCollectionExcluding<Enum, HeatPumpMode>(
items: HeatPumpMode.N_A);
//HeatPumpModeDriverCompartment = HeatPumpMode.cooling;
}
......@@ -421,6 +431,10 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
public MultistageAuxiliariesViewModel(IBusAuxiliariesDeclarationData consolidatedAuxiliariesInputData)
{
ConsolidatedInputData = consolidatedAuxiliariesInputData;
HeatPumpGroupEditingEnabled = true;
_editingEnabledDictionary = new IndexedStorage<bool>(() => {
OnPropertyChanged(nameof(EditingEnabledDictionary));
});
}
#region Implementation of IElectricSupplyDeclarationData
......
......@@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.Utils;
using VECTO3GUI2020.Annotations;
......@@ -27,12 +28,15 @@ namespace VECTO3GUI2020.Views.CustomControls
/// <returns></returns>
public static string GetLabelByPropertyName(this UserControl userControl, DependencyProperty dependencyProperty, params ResourceManager[] resourceManagers)
{
string name = null;
var binding = userControl.GetBindingExpression(dependencyProperty);
var propertyName = binding?.ResolvedSourcePropertyName;
if (propertyName == null || binding == null)
{
if (propertyName == null || binding == null) {
var status = binding?.Status;
throw new VectoException("Could not resolve binding");
return name;
}
......
......@@ -16,8 +16,8 @@
<Label>
<PriorityBinding>
<Binding ElementName="lableTextBoxMultistage" Path="Label" Converter="{StaticResource NullToUnsetValue}"></Binding>
<Binding ElementName="labledTextBoxMultistage" Path="GeneratedLabelText"></Binding>
<Binding Path="Label" ElementName="labledTextBoxMultistage" Converter="{StaticResource NullToUnsetValue}"></Binding>
<Binding Path="GeneratedLabelText" ElementName="labledTextBoxMultistage"></Binding>
</PriorityBinding>
</Label>
......
......@@ -96,16 +96,17 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!--ItemsSource="{Binding ListItems, ElementName=MultistageParameterControl}"-->
<ComboBox x:Name="comboBox1" Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="2 0 2 0"
SelectedValue="{Binding Content, Mode=TwoWay, ElementName=MultistageParameterControl, ValidatesOnExceptions=True}"
IsEnabled="{Binding EditingEnabled, ElementName=MultistageParameterControl}"
IsEditable="False" MouseDoubleClick="Control_OnMouseDoubleClick">
<!--ItemsSource="{Binding ListItems, ElementName=MultistageParameterControl}"-->
<ComboBox x:Name="comboBoxCurrent" Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="2 0 2 0"
SelectedIndex="{Binding EditingEnabled, ElementName=MultistageParameterControl, Converter={StaticResource BoolToIntConverter}}"
SelectedItem="{Binding Content, Mode=TwoWay, ElementName=MultistageParameterControl, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding EditingEnabled, ElementName=MultistageParameterControl}"
IsEditable="False" MouseDoubleClick="Control_OnMouseDoubleClick">
<ComboBox.ItemsSource>
<PriorityBinding>
<Binding Path="ListItems" ElementName="MultistageParameterControl" Converter="{StaticResource NullToUnsetValue}"/>
<Binding Path="GeneratedListItems" ElementName="MultistageParameterControl"/>
<Binding Path="ListItems" ElementName="MultistageParameterControl" Converter="{StaticResource NullToUnsetValue}" UpdateSourceTrigger="PropertyChanged"/>
<Binding Path="GeneratedListItems" ElementName="MultistageParameterControl" UpdateSourceTrigger="PropertyChanged"/>
</PriorityBinding>
</ComboBox.ItemsSource>
<ComboBox.ItemTemplate>
......@@ -153,7 +154,7 @@
</CheckBox>
<CheckBox x:Name="checkBox1" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Center" IsEnabled="{Binding ElementName=MultistageParameterControl,
Path=EditingEnabled}">
Path=EditingEnabled, UpdateSourceTrigger=PropertyChanged}">
</CheckBox>
<Label x:Name="label4" Grid.Column="4"
......
......@@ -12,6 +12,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms.VisualStyles;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
......@@ -97,15 +98,27 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
}
public static readonly DependencyProperty GeneratedLabelTextProperty = DependencyProperty.Register(
"GeneratedLabelText", typeof(string), typeof(MultiStageParameter), new PropertyMetadata(null));
//public static readonly DependencyProperty GeneratedLabelTextProperty = DependencyProperty.Register(
// "GeneratedLabelText", typeof(string), typeof(MultiStageParameter), new PropertyMetadata(null));
//public string GeneratedLabelText
//{
// get { return (string)GetValue(GeneratedLabelTextProperty); }
// set { SetValue(GeneratedLabelTextProperty, value); }
//}
private string _generatedLabelText;
public string GeneratedLabelText
{
get { return (string)GetValue(GeneratedLabelTextProperty); }
set { SetValue(GeneratedLabelTextProperty, value); }
get { return _generatedLabelText; }
set
{
_generatedLabelText = value;
OnPropertyChanged(nameof(GeneratedLabelText));
}
}
public static readonly DependencyProperty NameLookUpResourceManagerProperty = DependencyProperty.Register(
"NameLookUpResourceManager", typeof(ResourceManager), typeof(MultiStageParameter), new PropertyMetadata(default(ResourceManager), NameLookUpResourceManagerChanged));
......@@ -145,7 +158,18 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
public object DummyContent
{
get { return (object)GetValue(DummyContentProperty); }
set { SetValue(DummyContentProperty, value); }
set { SetCurrentValue(DummyContentProperty, value); }
}
private object _dummyContent = null;
public object DummyContentGenerated
{
get { return _dummyContent;}
set
{
_dummyContent = value;
OnPropertyChanged(nameof(DummyContentGenerated));
}
}
......@@ -164,7 +188,21 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
DependencyProperty.Register("Content",
typeof(object),
typeof(MultiStageParameter),
new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ContentChanged)); //TODO Default value null breaks it for SIs default value "" for strings
new FrameworkPropertyMetadata(defaultValue: null,
flags: FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
propertyChangedCallback: OnContentChanged,
coerceValueCallback: ContentCoerced)); //TODO Default value null breaks it for SIs default value "" for strings
private static object ContentCoerced(DependencyObject d, object basevalue)
{
((MultiStageParameter)d).ContentChanged();
return basevalue;
}
public new object Content
{
......@@ -172,16 +210,27 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
set
{
SetCurrentValue(ContentProperty, value);
OnPropertyChanged(nameof(Content));
}
}
public static readonly DependencyProperty ListItemsProperty = DependencyProperty.Register(
"ListItems", typeof(ObservableCollection<Enum>), typeof(MultiStageParameter),
new FrameworkPropertyMetadata(default(ObservableCollection<Enum>), ListItemsChanged));
new FrameworkPropertyMetadata(defaultValue:default(ObservableCollection<Enum>), propertyChangedCallback:ListItemsChanged));
private static void ListItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//throw new NotImplementedException();
return;
var listItems = e.NewValue as ObservableCollection<Enum>;
var multistageParameter = (MultiStageParameter)d;
if (multistageParameter.Mode == MultistageParameterViewMode.COMBOBOX && listItems != null) {
if (!listItems.Contains(multistageParameter.Content as Enum)) {
multistageParameter.Content = listItems[0];
}
}
}
public ObservableCollection<Enum> ListItems
......@@ -194,22 +243,37 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
public static readonly DependencyProperty GeneratedListItemsProperty = DependencyProperty.Register(
"GeneratedListItems", typeof(List<object>), typeof(MultiStageParameter), new PropertyMetadata(defaultValue:null));
public List<object> GeneratedListItems
{
get { return (List<object>)GetValue(GeneratedListItemsProperty); }
set { SetValue(GeneratedListItemsProperty, value); }
set { SetCurrentValue(GeneratedListItemsProperty, value); }
}
private object StoredContent { get; set; } = null;
public bool resolvedContentProperty { get; set; } = false;
#endregion
#endregion
private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((MultiStageParameter)d).ContentChanged();
}
private static void ContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
public void ContentChanged()
{
var multiStageParameter = (CustomControls.MultiStageParameter) d;
var multiStageParameter = (CustomControls.MultiStageParameter)this;
var binding = multiStageParameter.GetBindingExpression(ContentProperty);
if (binding?.Status != BindingStatus.Active || resolvedContentProperty) {
return;
}
if (multiStageParameter.DummyContent == null) {
multiStageParameter.DummyContent = multiStageParameter.CreateDummyContent(e, multiStageParameter);
multiStageParameter.DummyContent = multiStageParameter.CreateDummyContent();
}
if (multiStageParameter.Content != null) {
......@@ -217,7 +281,6 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
}
if (multiStageParameter.Mode == MultistageParameterViewMode.COMBOBOX) {
multiStageParameter.GenerateListItemsAndSetComboboxValue();
}
......@@ -225,11 +288,16 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
if (multiStageParameter.GeneratedLabelText == null) {
multiStageParameter.SetLabelText();
}
resolvedContentProperty = true;
EditingEnabledChanged(EditingEnabled);
}
public void SetLabelText()
{
if (Label == null) {
var binding = this.GetBindingExpression(ContentProperty);
if (Label == null && binding != null) {
this.GeneratedLabelText = this.GetLabelByPropertyName(
MultiStageParameter.ContentProperty,
this.NameLookUpResourceManager,
......@@ -243,36 +311,26 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
return;
if (GeneratedListItems == null) {
if (DummyContent is Enum dummyEnum)
{
if (DummyContent is Enum dummyEnum) {
var enType = dummyEnum.GetType();
GeneratedListItems = Enum.GetValues(enType).Cast<object>().ToList();
}
if (Content is Enum contentEnum)
{
}else if (Content is Enum contentEnum) {
var enType = contentEnum.GetType();
GeneratedListItems = Enum.GetValues(enType).Cast<object>().ToList();
}
//ListItems = GeneratedListItems;
}
}
private object CreateDummyContent(DependencyPropertyChangedEventArgs e, UserControl userControl)
private object CreateDummyContent()
{
var type = userControl.GetPropertyType(e.Property);
var type = this.GetPropertyType(ContentProperty);
if (type == null) {
return null;
}
if (type == typeof(ConvertedSI)) {
//var dummyContent = new ConvertedSI(0, (userControl.Content as ConvertedSI).Units);
return null; //dummyContent;
}
try {
dynamic dynType = type;
var baseType = dynType.BaseType;
......@@ -285,22 +343,29 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
var createMethod = baseType.GetMethod("Create");
var dummyContent = createMethod?.Invoke(null, new object[] { (new double()) });
return dummyContent;
}else if(Mode == MultistageParameterViewMode.COMBOBOX) {
var bindingProperty = userControl.GetBindingExpression(e.Property);
}
if(Mode == MultistageParameterViewMode.COMBOBOX) {
var bindingProperty = this.GetBindingExpression(ContentProperty);
var dataItemType = bindingProperty?.DataItem?.GetType();
var sourcePropertyType =
dataItemType?.GetProperty(bindingProperty?.ResolvedSourcePropertyName)?.PropertyType;
var underlyingType = Nullable.GetUnderlyingType(dynType);
Enum dummyEnum;
if (underlyingType != null) {
dummyEnum = Enum.Parse(underlyingType, underlyingType.GetEnumNames()[0]);
} else {
dummyEnum = Enum.Parse(dynType, dynType.GetEnumNames()[0]);
try {
if (underlyingType != null) {
dummyEnum = Enum.Parse(underlyingType, underlyingType.GetEnumNames()[0]);
} else {
dummyEnum = Enum.Parse(dynType, dynType.GetEnumNames()[0]);
}
} catch (Exception ex) {
Debug.WriteLine(ex.Message);
return null;
}
return dummyEnum;
}
......@@ -314,26 +379,61 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
private static void EditingEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MultiStageParameter multiStageParameter = (MultiStageParameter)d;
if((bool)e.NewValue == false) {
if (!Validation.GetHasError(multiStageParameter.TextBoxContent)) {
multiStageParameter.DummyContent = multiStageParameter.Content;
((MultiStageParameter) d).EditingEnabledChanged((bool)e.NewValue);
}
public void EditingEnabledChanged(bool editingEnabled)
{
if (GetBindingExpression(EditingEnabledProperty)?.Status != BindingStatus.Active) {
return;
}
this.CoerceValue(ContentProperty);
this.CoerceValue(ListItemsProperty);
MultiStageParameter multistageParameter = this;
if (editingEnabled == false)
{
//Temporary store current value
if (!Validation.GetHasError(multistageParameter.TextBoxContent))
{
multistageParameter.StoredContent = multistageParameter.Content;
}
multiStageParameter.Content = null;
} else {
if (multiStageParameter.Content != null) {
multiStageParameter.DummyContent = multiStageParameter.Content;
}else if (multiStageParameter.DummyContent != null) {
if (multiStageParameter.Mode == MultistageParameterViewMode.COMBOBOX) {
if (multiStageParameter.ListItems != null && !multiStageParameter.ListItems.Contains(multiStageParameter.DummyContent)) {
multiStageParameter.Content = multiStageParameter.ListItems[0];
} else {
multiStageParameter.Content = multiStageParameter.DummyContent;
if (multistageParameter.Content != null) {
multistageParameter.Content = null;
}
}
else
{
if (Content == null) {
if (multistageParameter.StoredContent != null)
{
//Restore previous value
multistageParameter.Content = multistageParameter.StoredContent;
}
else
{
if (multistageParameter.Mode == MultistageParameterViewMode.COMBOBOX)
{
//Set default value;
multistageParameter.GetBindingExpression(ListItemsProperty)?.UpdateTarget();
multistageParameter.GetBindingExpression(ContentProperty)?.UpdateTarget();
/*
multistageParameter.Content = multistageParameter.ListItems?[0] ??
multistageParameter.GeneratedListItems?[0];
//Debug.Assert(false);
*/
}
else
{
if (multistageParameter.Content == null && multistageParameter.DummyContent != null)
{
multistageParameter.Content = multistageParameter.DummyContent;
}
}
} else {
multiStageParameter.Content = multiStageParameter.DummyContent;
}
}
}
}
......@@ -343,10 +443,10 @@ namespace VECTO3GUI2020.Views.Multistage.CustomControls
public MultiStageParameter()
{
InitializeComponent();
}
private void Control_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
......
......@@ -16,44 +16,49 @@
<Label Background="{DynamicResource ButtonHighlightColor}" FontSize="15" HorizontalAlignment="Stretch">AUXILIARIES</Label>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.ElectricConsumers.InteriorLightsLED}"
Content="{Binding InteriorLightsLED}"/>
Content="{Binding InteriorLightsLED}"
EditingEnabled="{Binding EditingEnabledDictionary[InteriorLightsLED]}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.ElectricConsumers.DayrunninglightsLED}"
Content="{Binding DayrunninglightsLED}"/>
Content="{Binding DayrunninglightsLED}"
EditingEnabled="{Binding EditingEnabledDictionary[DayrunninglightsLED]}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.ElectricConsumers.PositionlightsLED}"
Content="{Binding PositionlightsLED}"/>
Content="{Binding PositionlightsLED}"
EditingEnabled="{Binding EditingEnabledDictionary[PositionLightsLED]}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.ElectricConsumers.BrakelightsLED}"
Content="{Binding BrakelightsLED}"/>
Content="{Binding BrakelightsLED}"
EditingEnabled="{Binding EditingEnabledDictionary[PositionLightsLED]}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.ElectricConsumers.HeadlightsLED}"
Content="{Binding HeadlightsLED}"/>
Content="{Binding HeadlightsLED}"
EditingEnabled="{Binding EditingEnabledDictionary[HeadLightsLED]}"/>
<Separator/>
<customControls:MultiStageParameter Mode="COMBOBOX"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled}"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled, Mode=TwoWay}"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.SystemConfiguration}"
Content="{Binding HVACAux.SystemConfiguration}"/>
<customControls:MultiStageParameter Mode="COMBOBOX"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled}"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled, Mode=TwoWay}"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.HeatPumpTypeDriverCompartment}"
Content="{Binding HeatPumpTypeDriverCompartment}"
ShowCheckBox="False"/>
<customControls:MultiStageParameter Mode="COMBOBOX"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled}"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled, Mode=TwoWay}"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.HeatPumpModeDriverCompartment}"
Content="{Binding HeatPumpModeDriverCompartment}"
ListItems="{Binding HeatPumpModeDriverCompartmentAllowedValues}"
ShowCheckBox="False"/>
<customControls:MultiStageParameter Mode="COMBOBOX"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled}"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled, Mode=TwoWay}"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.HeatPumpTypePassengerCompartment}"
Content="{Binding HeatPumpTypePassengerCompartment}"
ShowCheckBox="False"/>
<customControls:MultiStageParameter Mode="COMBOBOX"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled}"
EditingEnabled="{Binding HeatPumpGroupEditingEnabled, Mode=TwoWay}"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.HeatPumpModePassengerCompartment}"
Content="{Binding HeatPumpModePassengerCompartment}"
ListItems="{Binding HeatPumpModePassengerCompartmentAllowedValues}"
......@@ -62,29 +67,39 @@
<!--<customControls:MultiStageParameter Mode="COMBOBOX"
PreviousContent="{Binding ConsolidatedInputData.PneumaticSupply.CompressorDrive}"
Content="{Binding CompressorDrive}"></customControls:MultiStageParameter>-->
<customControls:MultiStageParameter Mode="TEXTBOX"
Validation.ErrorTemplate="{DynamicResource multistageParameterControlErrorTemplate}"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.AuxHeaterPower}"
Content="{Binding AuxHeaterPower}"/>
Content="{Binding AuxHeaterPower}"
EditingEnabled="{Binding EditingEnabledDictionary[AuxHeaterPower]}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.DoubleGlazing}"
Content="{Binding DoubleGlazing}"/>
Content="{Binding DoubleGlazing}"
EditingEnabled="{Binding EditingEnabledDictionary[DoubleGlazing]}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.AdjustableAuxiliaryHeater}"
EditingEnabled="{Binding EditingEnabledDictionary[AdjustableAuxiliaryHeater]}"
Content="{Binding AdjustableAuxiliaryHeater}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.SeparateAirDistributionDucts}"
EditingEnabled="{Binding EditingEnabledDictionary[SeparateAirDistributionDucts]}"
Content="{Binding SeparateAirDistributionDucts}"/>
<StackPanel Visibility="{Binding PrimaryVehicleHybridElectric, Converter={StaticResource BooleanToVisibilityConverter}}">
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.WaterElectricHeater}"
Content="{Binding WaterElectricHeater}"/>
Content="{Binding WaterElectricHeater}"
EditingEnabled="{Binding EditingEnabledDictionary[WaterElectricHeater]}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.AirElectricHeater}"
EditingEnabled="{Binding AirElectricHeater}"
Content="{Binding AirElectricHeater}"/>
<customControls:MultiStageParameter Mode="CHECKBOX"
PreviousContent="{Binding ConsolidatedInputData.HVACAux.OtherHeatingTechnology}"
EditingEnabled="{Binding OtherHeatingTechnology}"
Content="{Binding OtherHeatingTechnology}"/>
</StackPanel>
<Separator/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment