diff --git a/VECTO3GUI/App.xaml b/VECTO3GUI/App.xaml index f5680c761579f90937bb84f549d7fb7880721b2a..b87d524d8e2738c2642d13b9bbc49eddf3f31ff9 100644 --- a/VECTO3GUI/App.xaml +++ b/VECTO3GUI/App.xaml @@ -10,7 +10,7 @@ <Setter Property="Focusable" Value="False"/> </Style> <Style TargetType="{x:Type TextBox}"> - <Setter Property="Validation.ErrorTemplate"> + <!--<Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate> <DockPanel> @@ -30,7 +30,7 @@ <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> - </Style.Triggers> + </Style.Triggers>--> </Style> </ResourceDictionary> diff --git a/VECTO3GUI/Helper/XmlComponentReaderHelper.cs b/VECTO3GUI/Helper/XmlComponentReaderHelper.cs index 5f614614186835409f6370616863ebf9a468af85..ccc23cd42d9f80b8b634857ee2d3309508cfdda4 100644 --- a/VECTO3GUI/Helper/XmlComponentReaderHelper.cs +++ b/VECTO3GUI/Helper/XmlComponentReaderHelper.cs @@ -33,5 +33,15 @@ namespace VECTO3GUI.Helper DigestValue = new DigestData(GetNode(XMLNames.DI_Signature)) }; } + + public SquareMeter ReadTransferredCdxA() + { + return GetDouble("TransferredCdxA").SI<SquareMeter>(); + } + + public SquareMeter ReadCdxA_0() + { + return GetDouble("CdxA_0").SI<SquareMeter>(); + } } } diff --git a/VECTO3GUI/Helper/XmlHelper.cs b/VECTO3GUI/Helper/XmlHelper.cs index e719f90c0fcde39764885193129658cf7795ad02..3b5cf49f43b24d0341e9e115b21c44db0b578d1d 100644 --- a/VECTO3GUI/Helper/XmlHelper.cs +++ b/VECTO3GUI/Helper/XmlHelper.cs @@ -53,5 +53,13 @@ namespace VECTO3GUI.Helper var validator = new XMLValidator(xmlDocument, null, XMLValidator.CallBackExceptionOnError); return validator.ValidateXML(documentType.Value); ; } + + public static string GetXmlAbsoluteFilePath(string baseUri) + { + if (baseUri == null) + return null; + + return new Uri(baseUri).AbsolutePath; + } } } diff --git a/VECTO3GUI/Model/AlternatorTechnologyModel.cs b/VECTO3GUI/Model/AlternatorTechnologyModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..010d6be42c5c10deca5f08789a4932358d9a49ba --- /dev/null +++ b/VECTO3GUI/Model/AlternatorTechnologyModel.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Remoting.Channels; +using System.Text; +using System.Threading.Tasks; +using VECTO3GUI.ViewModel.Impl; + +namespace VECTO3GUI.Model +{ + public enum AlternatorTechnology + { + Empty, + Default + } + + public static class AlternatorTechnologyHelper + { + public static string GetLabel(this AlternatorTechnology technology) + { + switch (technology) { + case AlternatorTechnology.Default: + return nameof(AlternatorTechnology.Default).ToLower(); + default: + return string.Empty; + } + } + + public static AlternatorTechnology Parse(string technologyName) + { + switch (technologyName.ToLower()) { + case "default": + return AlternatorTechnology.Default; + default: + return AlternatorTechnology.Empty; + } + } + } + + public class AlternatorTechnologyModel : ObservableObject + { + public AlternatorTechnology _alternatorTechnology; + + public AlternatorTechnology AlternatorTechnology + { + get { return _alternatorTechnology; } + set { SetProperty(ref _alternatorTechnology, value); } + } + } +} diff --git a/VECTO3GUI/Model/InterfacesImpl.cs b/VECTO3GUI/Model/InterfacesImpl.cs deleted file mode 100644 index fbd920efde9104dbc673435b0a82ab9d96fbd88e..0000000000000000000000000000000000000000 --- a/VECTO3GUI/Model/InterfacesImpl.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TUGraz.VectoCommon.InputData; - -namespace VECTO3GUI.Model -{ - - public class AlternatorDeclarationInputData : IAlternatorDeclarationInputData - { - public string Technology { get; set; } - public double Ratio { get; set; } - } - -} diff --git a/VECTO3GUI/Model/TempDataObject/AirdragComponentData.cs b/VECTO3GUI/Model/TempDataObject/AirdragComponentData.cs index ef0153e65d736811236018d35c77065a795e9680..b92fd10401b96a5629c1e1c790eea708d5476076 100644 --- a/VECTO3GUI/Model/TempDataObject/AirdragComponentData.cs +++ b/VECTO3GUI/Model/TempDataObject/AirdragComponentData.cs @@ -17,6 +17,7 @@ namespace VECTO3GUI.Model.TempDataObject public string Model { get; set; } public string CertificationNumber { get; set; } public DateTime? Date { get; set; } + public bool NoAirdragData { get; set; } public bool UseMeasuredValues { get; set; } public SquareMeter CdxA_0 { get; set; } public SquareMeter TransferredCdxA { get; set; } @@ -47,6 +48,7 @@ namespace VECTO3GUI.Model.TempDataObject public void ResetToComponentValues(IAirdragViewModel viewModel) { + viewModel.NoAirdragData = NoAirdragData; viewModel.Model = Model; viewModel.Manufacturer = Manufacturer; viewModel.CertificationNumber = CertificationNumber; @@ -73,6 +75,7 @@ namespace VECTO3GUI.Model.TempDataObject private void SetValues(IAirdragViewModel viewModel) { + NoAirdragData = viewModel.NoAirdragData; Model = viewModel.Model; Manufacturer = viewModel.Manufacturer; CertificationNumber = viewModel.CertificationNumber; diff --git a/VECTO3GUI/Model/TempDataObject/AuxiliariesBusComponentData.cs b/VECTO3GUI/Model/TempDataObject/AuxiliariesBusComponentData.cs index 678c6f0b9bbfa1122ea5e910f7cbf670a989d5bc..e855a78dacf8f9364da06f5e54360ead8f234923 100644 --- a/VECTO3GUI/Model/TempDataObject/AuxiliariesBusComponentData.cs +++ b/VECTO3GUI/Model/TempDataObject/AuxiliariesBusComponentData.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.Utils; +using VECTO3GUI.Helper; using VECTO3GUI.ViewModel.Interfaces; namespace VECTO3GUI.Model.TempDataObject @@ -14,7 +14,8 @@ namespace VECTO3GUI.Model.TempDataObject { #region IAuxiliariesBus Interface - public ObservableCollection<string> AlternatorTechnologies { get; set; } + public ObservableCollectionEx<AlternatorTechnologyModel> AlternatorTechnologies { get; set; } + public List<AlternatorTechnologyModel> OriginAlternatorTechnologies { get; private set; } public bool DayrunninglightsLED { get; set; } public bool HeadlightsLED { get; set; } public bool PositionlightsLED { get; set; } @@ -50,7 +51,7 @@ namespace VECTO3GUI.Model.TempDataObject public void ResetToComponentValues(IAuxiliariesViewModel viewModel) { - viewModel.AlternatorTechnologies = AlternatorTechnologies; + viewModel.AlternatorTechnologies = GetAlternatorTechnology(); viewModel.DayrunninglightsLED = DayrunninglightsLED; viewModel.HeadlightsLED = HeadlightsLED; viewModel.PositionlightsLED = PositionlightsLED; @@ -67,9 +68,19 @@ namespace VECTO3GUI.Model.TempDataObject viewModel.DoorDriveTechnology = viewModel.DoorDriveTechnology; } + private ObservableCollectionEx<AlternatorTechnologyModel> GetAlternatorTechnology() + { + var res = new ObservableCollectionEx<AlternatorTechnologyModel>(); + for (int i = 0; i < OriginAlternatorTechnologies.Count; i++) { + res.Add(new AlternatorTechnologyModel{AlternatorTechnology = OriginAlternatorTechnologies[i].AlternatorTechnology}); + } + + return res; + } + public void ClearValues(IAuxiliariesViewModel viewModel) { - viewModel.AlternatorTechnologies = default(ObservableCollection<string>); + viewModel.AlternatorTechnologies = default(ObservableCollectionEx<AlternatorTechnologyModel>); viewModel.DayrunninglightsLED = default(bool); viewModel.HeadlightsLED = default(bool); viewModel.PositionlightsLED = default(bool); @@ -88,7 +99,8 @@ namespace VECTO3GUI.Model.TempDataObject private void SetValues(IAuxiliariesViewModel auxiliaries) { - AlternatorTechnologies = new ObservableCollection<string>(auxiliaries.AlternatorTechnologies); + OriginAlternatorTechnologies = GetOriginAlternatorTechnologies(auxiliaries); + AlternatorTechnologies = GetAlternatorTechnology(); DayrunninglightsLED = auxiliaries.DayrunninglightsLED; HeadlightsLED = auxiliaries.HeadlightsLED; PositionlightsLED = auxiliaries.PositionlightsLED; @@ -105,5 +117,18 @@ namespace VECTO3GUI.Model.TempDataObject DoorDriveTechnology = auxiliaries.DoorDriveTechnology; } + private List<AlternatorTechnologyModel> GetOriginAlternatorTechnologies(IAuxiliariesViewModel auxiliaries) + { + if (auxiliaries.AlternatorTechnologies == null) + return null; + + var result = new List<AlternatorTechnologyModel>(); + for (int i = 0; i < auxiliaries.AlternatorTechnologies.Count; i++) { + result.Add(new AlternatorTechnologyModel { + AlternatorTechnology = auxiliaries.AlternatorTechnologies[i].AlternatorTechnology + }); + } + return result; + } } } diff --git a/VECTO3GUI/Util/XML/XMLCompletedBus.cs b/VECTO3GUI/Util/XML/XMLCompletedBus.cs index 078b13ad18f4476b7fb768b5fc0e0f9d29a0d2ca..6654662a1dc0cbce34b7e056ca0fe86f94f3a35d 100644 --- a/VECTO3GUI/Util/XML/XMLCompletedBus.cs +++ b/VECTO3GUI/Util/XML/XMLCompletedBus.cs @@ -12,6 +12,7 @@ using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Resources; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider; +using VECTO3GUI.Model; using VECTO3GUI.ViewModel.Interfaces; @@ -126,6 +127,9 @@ namespace VECTO3GUI.Util.XML private XElement GetAirdrag(IAirdrag airdrag) { + if (airdrag.NoAirdragData) + return null; + return new XElement(_v26 + XMLNames.Component_AirDrag, new XAttribute("xmlns", _v20), @@ -191,18 +195,23 @@ namespace VECTO3GUI.Util.XML ); } - private XElement[] GetAlternatorTechnology(IList<string> alternatorTechnologies) + private XElement[] GetAlternatorTechnology(IList<AlternatorTechnologyModel> alternatorTechnologies) { if (alternatorTechnologies.IsNullOrEmpty()) return null; - var result = new XElement[alternatorTechnologies.Count]; + var result = new List<XElement>(); for (int i = 0; i < alternatorTechnologies.Count; i++) { - result [i] = new XElement(_v26 + XMLNames.BusAux_ElectricSystem_AlternatorTechnology, alternatorTechnologies[i]); + + if(alternatorTechnologies[i].AlternatorTechnology == AlternatorTechnology.Empty) + continue; + + result.Add(new XElement(_v26 + XMLNames.BusAux_ElectricSystem_AlternatorTechnology, + alternatorTechnologies[i].AlternatorTechnology.GetLabel())); } - return result; + return result.Count > 0 ? result.ToArray() : null; } } } diff --git a/VECTO3GUI/VECTO3GUI.csproj b/VECTO3GUI/VECTO3GUI.csproj index 0d9cbb0c7978339b89c6dfb9011e420b19c6b6af..cc8bb460cf0728d5b42e9ff1e67a62e986f674f6 100644 --- a/VECTO3GUI/VECTO3GUI.csproj +++ b/VECTO3GUI/VECTO3GUI.csproj @@ -117,6 +117,7 @@ <Reference Include="Microsoft.Expression.Interactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <HintPath>..\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\Microsoft.Expression.Interactions.dll</HintPath> </Reference> + <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> <Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\packages\WindowsAPICodePack-Core.1.1.2\lib\Microsoft.WindowsAPICodePack.dll</HintPath> </Reference> @@ -176,7 +177,7 @@ <Compile Include="Helper\ViewModelBase.cs" /> <Compile Include="Helper\XmlComponentReaderHelper.cs" /> <Compile Include="Helper\XmlHelper.cs" /> - <Compile Include="Model\InterfacesImpl.cs" /> + <Compile Include="Model\AlternatorTechnologyModel.cs" /> <Compile Include="Model\JobListModel.cs" /> <Compile Include="Model\SettingsModel.cs" /> <Compile Include="Model\TempDataObject\AirdragComponentData.cs" /> diff --git a/VECTO3GUI/ViewModel/Impl/AbstractBusJobViewModel.cs b/VECTO3GUI/ViewModel/Impl/AbstractBusJobViewModel.cs index 37c5556ff67357e1263700f690d733ee443e4d07..e1e0968684c9650ebcc26389ea38f75a6b4a96b4 100644 --- a/VECTO3GUI/ViewModel/Impl/AbstractBusJobViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/AbstractBusJobViewModel.cs @@ -126,14 +126,14 @@ namespace VECTO3GUI.ViewModel.Impl _editJob = true; } - private void Init(IKernel kernel, JobType jobType) + private void Init(IKernel kernel, JobType jobType) { SecondLabelText = $"Select {JobFileType.CompletedBusFile.GetLable()}"; Settings = new SettingsModel(); SetFileTypes(jobType); Kernel = kernel; } - + private void SetFileTypes(JobType jobType) { JobType = jobType; @@ -180,7 +180,7 @@ namespace VECTO3GUI.ViewModel.Impl { SecondFilePath = OpenFileSelector(jobFileType, nameof(SecondFilePath)); } - + public ICommand CancelCommand { get { return _cancelCommand ?? (_cancelCommand = new RelayCommand<Window>(DoCancelCommand)); } @@ -201,9 +201,9 @@ namespace VECTO3GUI.ViewModel.Impl private void DoSaveCommand(Window window) { window.DialogResult = true; - if (!_editJob) + if (!_editJob) SaveJob(window); - else + else UpdateJobData(); } @@ -212,19 +212,21 @@ namespace VECTO3GUI.ViewModel.Impl private void SaveJob(Window window) { var jobFilePath = FileDialogHelper.SaveJobFileToDialog(Settings.XmlFilePathFolder); - if (jobFilePath != null) { - - var job = new JobEntry { - JobEntryFilePath = jobFilePath, - FirstFilePath = FirstFilePath, - SecondFilePath = SecondFilePath, - JobType = JobType - }; - - SerializeHelper.SerializeToFile(jobFilePath, job); - SavedJobEntry = job; - DoCancelCommand(window); - } + if (jobFilePath == null) + return; + + var job = new JobEntry + { + JobEntryFilePath = jobFilePath, + FirstFilePath = FirstFilePath, + SecondFilePath = SecondFilePath, + JobType = JobType + }; + + SerializeHelper.SerializeToFile(jobFilePath, job); + SavedJobEntry = job; + DoCancelCommand(window); + } private void UpdateJobData() @@ -232,7 +234,7 @@ namespace VECTO3GUI.ViewModel.Impl SavedJobEntry.FirstFilePath = FirstFilePath; SavedJobEntry.SecondFilePath = SecondFilePath; } - + private string OpenFileSelector(JobFileType jobFileType, string textPropertyName) { diff --git a/VECTO3GUI/ViewModel/Impl/AbstractJobViewModel.cs b/VECTO3GUI/ViewModel/Impl/AbstractJobViewModel.cs index 76044356820eff24bb397fba78bcfd9eeb07d99c..484e89205a605fce2e166ad69d3ada6b666a2753 100644 --- a/VECTO3GUI/ViewModel/Impl/AbstractJobViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/AbstractJobViewModel.cs @@ -121,11 +121,7 @@ namespace VECTO3GUI.ViewModel.Impl protected void SetXmlFilePath(string baseUri) { - if (baseUri == null) - return; - - var uri = new Uri(baseUri); - XmlFilePath = uri.AbsolutePath; + XmlFilePath = XmlHelper.GetXmlAbsoluteFilePath(baseUri); } protected bool CloseWindowDialog() diff --git a/VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs b/VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs index 70ae9f5f19bdfe9d8f88fc9166903539ffbdbb78..51bde59179dd72029cc63bba0e1a1636dba93dc8 100644 --- a/VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Input; +using System.Xml; using Castle.Core.Internal; using Ninject; using TUGraz.VectoCommon.Hashing; @@ -65,7 +66,7 @@ namespace VECTO3GUI.ViewModel.Impl private bool _isEditable; private bool _useMeasurementData; private bool _noAirdragData; - + private string _xmlFilePath; private ICommand _airdragConfig; private ICommand _loadFileCommand; @@ -155,6 +156,18 @@ namespace VECTO3GUI.ViewModel.Impl public DigestData DigestValue { get; set; } + + public bool NoAirdragData + { + get { return _noAirdragData; } + set + { + SetProperty(ref _noAirdragData, value); + IsDataChanged(_noAirdragData, _componentData); + UseMeasurementData = !_noAirdragData; + } + } + #endregion public bool IsEditable @@ -169,27 +182,24 @@ namespace VECTO3GUI.ViewModel.Impl set { SetProperty(ref _useMeasurementData, value); } } - public bool NoAirdragData - { - get { return _noAirdragData; } - set { SetProperty(ref _noAirdragData, value); } - } - - + protected override void InputDataChanged() { var inputData = JobViewModel.InputDataProvider as IDeclarationInputDataProvider; _airdragData = inputData?.JobInputData.Vehicle.Components.AirdragInputData; + var xmlUri = inputData?.JobInputData.Vehicle.XMLSource.BaseURI; + _xmlFilePath = XmlHelper.GetXmlAbsoluteFilePath(xmlUri); + SetAirdragValues(_airdragData); - UseMeasurementData = _airdragData != null; + UseMeasurementData = _airdragData.AirDragArea != null; NoAirdragData = !UseMeasurementData; IsEditable = false; } private void SetAirdragValues(IAirdragDeclarationInputData airdrag) { - UseMeasuredValues = airdrag != null; - if (airdrag == null) + UseMeasuredValues = airdrag.AirDragArea != null; + if (airdrag.AirDragArea == null) { _componentData = new AirdragComponentData(this, true); return; @@ -201,14 +211,22 @@ namespace VECTO3GUI.ViewModel.Impl Date = airdrag.Date; AppVersion = airdrag.AppVersion; DeclaredCdxA = airdrag.AirDragArea; - CdxA_0 = DeclaredCdxA; - TransferredCdxA = DeclaredCdxA; DigestValue = airdrag.DigestValue; + ReadAdditionalAirdragValues(); _componentData = new AirdragComponentData(this); ClearChangedProperties(); } + private void ReadAdditionalAirdragValues() + { + var xmlNodes = GetXmlNodes(_xmlFilePath); + var compReader = new XmlComponentReaderHelper(xmlNodes[0].ParentNode); + CdxA_0 = compReader.ReadCdxA_0(); + TransferredCdxA = compReader.ReadTransferredCdxA(); + } + + #region Commands public ICommand AirdragConfigCommand @@ -221,7 +239,14 @@ namespace VECTO3GUI.ViewModel.Impl private void DoAirdragConfig(AirdragConfig config) { - + switch (config) { + case AirdragConfig.WithoutAirdrag: + NoAirdragData = true; + break; + case AirdragConfig.UseMeasurementData: + NoAirdragData = false; + break; + } } @@ -260,20 +285,24 @@ namespace VECTO3GUI.ViewModel.Impl private void ReadSelectedXml(string filePath) { - if (filePath.IsNullOrEmpty()) - return; - - var xmlDocument = XmlHelper.ReadXmlDocument(filePath); - var nodes = XmlHelper.GetComponentNodes(xmlDocument, - XMLNames.VectoInputDeclaration, VectoComponents.Airdrag.XMLElementName()); - - if(nodes.IsNullOrEmpty()) + var xmlNodes = GetXmlNodes(filePath); + if (xmlNodes.IsNullOrEmpty()) return; - var compReader = new XmlComponentReaderHelper(nodes[0].ParentNode); + var compReader = new XmlComponentReaderHelper(xmlNodes[0].ParentNode); SetLoadedAirdragData(compReader.GetAirdragComponentData()); } + private XmlNodeList GetXmlNodes(string filePath) + { + if (filePath.IsNullOrEmpty()) + return null; + + var xmlDocument = XmlHelper.ReadXmlDocument(filePath); + return XmlHelper.GetComponentNodes(xmlDocument, + XMLNames.VectoInputDeclaration, VectoComponents.Airdrag.XMLElementName()); + } + private void SetLoadedAirdragData(AirdragComponentData airdrag) { if (airdrag == null) diff --git a/VECTO3GUI/ViewModel/Impl/AuxiliariesViewModel.cs b/VECTO3GUI/ViewModel/Impl/AuxiliariesViewModel.cs index 61fa55736a855f19eb2346021d7ecf9502a07355..f977b6e4633c93928e781116553bd09874696347 100644 --- a/VECTO3GUI/ViewModel/Impl/AuxiliariesViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/AuxiliariesViewModel.cs @@ -1,26 +1,27 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.ComponentModel; using System.Linq; -using System.Windows.Documents; using System.Windows.Input; using Castle.Core.Internal; -using Ninject; using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Declaration; +using VECTO3GUI.Helper; using VECTO3GUI.Util; -using VECTO3GUI.ViewModel.Adapter; using VECTO3GUI.ViewModel.Interfaces; using VECTO3GUI.Model; using VECTO3GUI.Model.TempDataObject; -using Component = VECTO3GUI.Util.Component; + namespace VECTO3GUI.ViewModel.Impl { + + + public class AuxiliariesViewModel : AbstractComponentViewModel, IAuxiliariesViewModel { #region Members @@ -33,7 +34,8 @@ namespace VECTO3GUI.ViewModel.Impl private IAxlesViewModel axlesViewModel; private IBusAuxiliariesDeclarationData _busAuxiliaries; - private ObservableCollection<string> _alternatorTechnologies; + + private ObservableCollectionEx<AlternatorTechnologyModel> _alternatorTechnologies; private bool _dayRunningLightsLED; private bool _headlightyLED; private bool _positionlightsLED; @@ -57,7 +59,7 @@ namespace VECTO3GUI.ViewModel.Impl #region Implementation of IAuxiliariesViewModel - + public IAuxiliariesDeclarationInputData ModelData { get { return AdapterFactory.AuxiliariesDeclarationAdapter(this); } } public string PneumaticSystemTechnology @@ -131,9 +133,10 @@ namespace VECTO3GUI.ViewModel.Impl #endregion + #region Implementation of IBusAuxiliaries - public ObservableCollection<string> AlternatorTechnologies + public ObservableCollectionEx<AlternatorTechnologyModel> AlternatorTechnologies { get { return _alternatorTechnologies; } set { SetProperty(ref _alternatorTechnologies, value); } @@ -149,6 +152,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_dayRunningLightsLED, _componentData); } } + public bool HeadlightsLED { get { return _headlightyLED; } @@ -160,6 +164,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_headlightyLED, _componentData); } } + public bool PositionlightsLED { get { return _positionlightsLED; } @@ -170,6 +175,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_positionlightsLED, _componentData); } } + public bool BrakelightsLED { get { return _breaklightsLED; } @@ -180,6 +186,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_breaklightsLED, _componentData); } } + public bool InteriorLightsLED { get { return _interiorLightsLED; } @@ -202,6 +209,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_systemConfiguration, _componentData); } } + public ACCompressorType CompressorTypeDriver { get { return _compressorTypeDriver; } @@ -212,6 +220,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_compressorTypeDriver, _componentData); } } + public ACCompressorType CompressorTypePassenger { get { return _compressorTypePassenger; } @@ -232,6 +241,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_auxHeaterPower, _componentData); } } + public bool DoubleGlasing { get { return _doubleGlasing; } @@ -242,6 +252,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_doubleGlasing, _componentData); } } + public bool HeatPump { get { return _heatPump; } @@ -252,6 +263,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_heatPump, _componentData); } } + public bool AdjustableAuxiliaryHeater { get { return _adjustableAuxiliaryHeater; } @@ -262,6 +274,7 @@ namespace VECTO3GUI.ViewModel.Impl IsDataChanged(_adjustableAuxiliaryHeater, _componentData); } } + public bool SeparateAirDistributionDucts { get { return _separateAirDistributionDucts; } @@ -279,9 +292,7 @@ namespace VECTO3GUI.ViewModel.Impl public AllowedEntry<BusHVACSystemConfiguration>[] AllowedSystemConfigurations { get; private set; } public AllowedEntry<ACCompressorType>[] AllowedDriverACCompressorTypes { get; private set; } public AllowedEntry<ACCompressorType>[] AllowedPassengerACCompressorTypes { get; private set; } - public AllowedEntry<ConsumerTechnology>[] AllowedConsumerTechnologies { get; private set; } - - + public AllowedEntry<AlternatorTechnology>[] AllowedAlternatorTechnology { get; private set; } #endregion @@ -314,15 +325,18 @@ namespace VECTO3GUI.ViewModel.Impl if (!busAux.ElectricSupply.Alternators.IsNullOrEmpty()) { - AlternatorTechnologies = new ObservableCollection<string>(); + AlternatorTechnologies = new ObservableCollectionEx<AlternatorTechnologyModel>(); + + AlternatorTechnologies.CollectionChanged += AlternatorTechnologiesOnCollectionChanged; + AlternatorTechnologies.CollectionItemChanged += AlternatorTechnologiesOnCollectionItemChanged; for (int i = 0; i < busAux.ElectricSupply.Alternators.Count; i++) { - AlternatorTechnologies.Add(busAux.ElectricSupply.Alternators[i].Technology); + AlternatorTechnologies.Add(new AlternatorTechnologyModel + { + AlternatorTechnology = AlternatorTechnologyHelper.Parse(busAux.ElectricSupply.Alternators[i].Technology) + }); } - - //AlternatorTechnologies.Add("blu"); - //AlternatorTechnologies.Add("bla"); } DayrunninglightsLED = busAux.ElectricConsumers.DayrunninglightsLED; @@ -344,6 +358,39 @@ namespace VECTO3GUI.ViewModel.Impl ClearChangedProperties(); } + private void AlternatorTechnologiesOnCollectionItemChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName != "AlternatorTechnology") + return; + + var changed = IsAlternatorTechnologyChanged(); + SetChangedProperty(changed, nameof(AlternatorTechnologies)); + } + + private void AlternatorTechnologiesOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + var changed = IsAlternatorTechnologyChanged(); + SetChangedProperty(changed, nameof(AlternatorTechnologies)); + } + + private bool IsAlternatorTechnologyChanged() + { + if (AlternatorTechnologies == null || _componentData?.OriginAlternatorTechnologies == null) + return true; + + if (AlternatorTechnologies.Count != _componentData.OriginAlternatorTechnologies.Count) + return true; + + for (int i = 0; i < AlternatorTechnologies.Count; i++) + { + if (AlternatorTechnologies[i].AlternatorTechnology != + _componentData.OriginAlternatorTechnologies[i].AlternatorTechnology) + return true; + } + + return false; + } + private void SetAllowedValues() { AllowedSystemConfigurations = Enum.GetValues(typeof(BusHVACSystemConfiguration)).Cast<BusHVACSystemConfiguration>() @@ -354,13 +401,18 @@ namespace VECTO3GUI.ViewModel.Impl AllowedPassengerACCompressorTypes = AllowedDriverACCompressorTypes; - AllowedConsumerTechnologies = Enum.GetValues(typeof(ConsumerTechnology)).Cast<ConsumerTechnology>() + AllowedAlternatorTechnology = Enum.GetValues(typeof(AlternatorTechnology)).Cast<AlternatorTechnology>() .Select(sc => AllowedEntry.Create(sc, sc.GetLabel())).ToArray(); } public override void ResetComponentData() { _componentData.ResetToComponentValues(this); + AlternatorTechnologies.CollectionChanged += AlternatorTechnologiesOnCollectionChanged; + AlternatorTechnologies.CollectionItemChanged += AlternatorTechnologiesOnCollectionItemChanged; + + var changed = IsAlternatorTechnologyChanged(); + SetChangedProperty(changed, nameof(AlternatorTechnologies)); } public override object SaveComponentData() @@ -406,20 +458,16 @@ namespace VECTO3GUI.ViewModel.Impl get { return _addAlternatorCommand ?? - (_addAlternatorCommand = new RelayCommand(DoAddAlternator, CanAddAlternator)); + (_addAlternatorCommand = new RelayCommand(DoAddAlternator)); } } - private bool CanAddAlternator() - { - return false; - } - private void DoAddAlternator() { - AlternatorTechnologies?.Add(string.Empty); - OnPropertyChanged(nameof(AlternatorTechnologies)); - + AlternatorTechnologies.Add(new AlternatorTechnologyModel + { + AlternatorTechnology = AlternatorTechnology.Empty + }); } #endregion diff --git a/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusJobViewModel.cs b/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusJobViewModel.cs index d414dcacfcf0548f5b2f56dd2e19855c1b766db4..ccae3e62319f5e41e4c59ea231d4bb99e3da3aaa 100644 --- a/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusJobViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusJobViewModel.cs @@ -94,6 +94,8 @@ namespace VECTO3GUI.ViewModel.Impl protected override void DoSaveToJob(Window window) { var filePath = FileDialogHelper.SaveXmlFileToDialog(SettingsModel.XmlFilePathFolder); + if(filePath == null) + return; SetCurrentDataToSave(); var xDocument = _xmlCompletedBus.GenerateCompletedBusDocument(CompleteVehicleBusData); diff --git a/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusViewModel.cs b/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusViewModel.cs index 2f434ae487a226509112b7dfa3ae69f57199b59b..2f2262e6ef01e69d39781dfa75435695d4a63f81 100644 --- a/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusViewModel.cs @@ -247,7 +247,7 @@ namespace VECTO3GUI.ViewModel.Impl public AllowedEntry<VehicleCode>[] AllowedVehicleCodes { get; private set; } public AllowedEntry<ConsumerTechnology>[] AllowedConsumerTechnologies { get; private set; } public AllowedEntry<RegistrationClass>[] AllowedRegisteredClasses { get; private set; } - public AllowedEntry<TankSystem>[] AllowedTankSystems { get; private set; } + public AllowedEntry<TankSystem?>[] AllowedTankSystems { get; private set; } #endregion @@ -310,11 +310,12 @@ namespace VECTO3GUI.ViewModel.Impl .Select(vc => AllowedEntry.Create(vc, vc.GetLabel())).ToArray(); var tankSystems = Enum.GetValues(typeof(TankSystem)).Cast<TankSystem>().ToArray(); - var tank = new AllowedEntry<TankSystem> [tankSystems.Length+1]; + var tank = new AllowedEntry<TankSystem?> [tankSystems.Length+1]; - tank[0] = AllowedEntry.Create(TankSystem.Compressed, null); + tank[0] = AllowedEntry.Create((TankSystem?)null, null); for (int i = 1; i < tankSystems.Length + 1; i++) { - tank[i] = AllowedEntry.Create(tankSystems[i-1], tankSystems[i-1].ToString()); + + tank[i] = AllowedEntry.Create<TankSystem?>(tankSystems[i-1], tankSystems[i-1].ToString()); } AllowedTankSystems = tank; diff --git a/VECTO3GUI/ViewModel/Interfaces/IAirdrag.cs b/VECTO3GUI/ViewModel/Interfaces/IAirdrag.cs index 9d28b8a68a3ddf97d127fb88035228bca6a2f91f..aa59c689eef35fd1513f53adddac63f8b403e180 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IAirdrag.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IAirdrag.cs @@ -10,6 +10,7 @@ namespace VECTO3GUI.ViewModel.Interfaces { public interface IAirdrag : ICommonComponentParameters { + bool NoAirdragData { get; set; } bool UseMeasuredValues { get; set; } SquareMeter CdxA_0 { get; set; } SquareMeter TransferredCdxA { get; set; } diff --git a/VECTO3GUI/ViewModel/Interfaces/IAirdragViewModel.cs b/VECTO3GUI/ViewModel/Interfaces/IAirdragViewModel.cs index f85fd276dd766072df66eafa7d583ee6da975e85..3bfe460225a825cefba20807d424dc66caa5458a 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IAirdragViewModel.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IAirdragViewModel.cs @@ -9,7 +9,6 @@ namespace VECTO3GUI.ViewModel.Interfaces IAirdragDeclarationInputData ModelData { get; } bool IsEditable { get; } - bool NoAirdragData { get; } bool UseMeasurementData { get; } ICommand LoadFileCommand { get; } diff --git a/VECTO3GUI/ViewModel/Interfaces/IAuxiliariesBus.cs b/VECTO3GUI/ViewModel/Interfaces/IAuxiliariesBus.cs index 2e849ec87e7c41c7912a3947ab4226e03626253e..360c983d94150cc8320040bee24fa65b086904ba 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IAuxiliariesBus.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IAuxiliariesBus.cs @@ -6,6 +6,8 @@ using System.Text; using System.Threading.Tasks; using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.Utils; +using VECTO3GUI.Helper; +using VECTO3GUI.Model; namespace VECTO3GUI.ViewModel.Interfaces { @@ -13,7 +15,7 @@ namespace VECTO3GUI.ViewModel.Interfaces { #region Electric System - ObservableCollection<string> AlternatorTechnologies { get; set; } + ObservableCollectionEx<AlternatorTechnologyModel> AlternatorTechnologies { get; set; } bool DayrunninglightsLED { get; set; } bool HeadlightsLED { get; set; } bool PositionlightsLED { get; set; } diff --git a/VECTO3GUI/ViewModel/Interfaces/IAuxiliariesViewModel.cs b/VECTO3GUI/ViewModel/Interfaces/IAuxiliariesViewModel.cs index 74a5851b89cc302329ff208d22816904568a32ad..04e2f00b54b9361d792068eaaef35573a0f152b7 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IAuxiliariesViewModel.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IAuxiliariesViewModel.cs @@ -4,6 +4,7 @@ using System.Windows.Input; using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Utils; +using VECTO3GUI.Model; using VECTO3GUI.Util; namespace VECTO3GUI.ViewModel.Interfaces { @@ -41,7 +42,7 @@ namespace VECTO3GUI.ViewModel.Interfaces { AllowedEntry<BusHVACSystemConfiguration>[] AllowedSystemConfigurations { get; } AllowedEntry<ACCompressorType>[] AllowedDriverACCompressorTypes { get; } AllowedEntry<ACCompressorType>[] AllowedPassengerACCompressorTypes { get; } - AllowedEntry<ConsumerTechnology>[] AllowedConsumerTechnologies { get; } + AllowedEntry<AlternatorTechnology>[] AllowedAlternatorTechnology { get; } #endregion } diff --git a/VECTO3GUI/ViewModel/Interfaces/ICompleteVehicleBusViewModel.cs b/VECTO3GUI/ViewModel/Interfaces/ICompleteVehicleBusViewModel.cs index 58cb9e56c6915dd7c03688a672dc1a5b7e45402f..ac3472e25bdd7e7c5d4d7f2f5bee549137b69d59 100644 --- a/VECTO3GUI/ViewModel/Interfaces/ICompleteVehicleBusViewModel.cs +++ b/VECTO3GUI/ViewModel/Interfaces/ICompleteVehicleBusViewModel.cs @@ -13,6 +13,6 @@ namespace VECTO3GUI.ViewModel.Interfaces AllowedEntry<VehicleCode>[] AllowedVehicleCodes { get; } AllowedEntry<ConsumerTechnology>[] AllowedConsumerTechnologies { get; } AllowedEntry<RegistrationClass>[] AllowedRegisteredClasses { get; } - AllowedEntry<TankSystem>[] AllowedTankSystems { get; } + AllowedEntry<TankSystem?>[] AllowedTankSystems { get; } } } diff --git a/VECTO3GUI/Views/ComponentViews/Declaration/AuxiliariesDeclarationView.xaml b/VECTO3GUI/Views/ComponentViews/Declaration/AuxiliariesDeclarationView.xaml index 0ba6e184858a7bc21235e43719a6541b17dcd22f..e918f7beeaed9755c9e2c53cf73be4a79f54035c 100644 --- a/VECTO3GUI/Views/ComponentViews/Declaration/AuxiliariesDeclarationView.xaml +++ b/VECTO3GUI/Views/ComponentViews/Declaration/AuxiliariesDeclarationView.xaml @@ -49,32 +49,35 @@ </Grid> - <DataGrid x:Name="AlternatorDataGrid" AutoGenerateColumns="False" ColumnWidth="*" IsReadOnly="False" CanUserAddRows="False" VerticalAlignment="Top" - HeadersVisibility="All" RowHeaderWidth="10" Height="150" Margin="0,10,0,0" BorderThickness="1" + <DataGrid x:Name="AlternatorDataGrid" AutoGenerateColumns="False" ColumnWidth="*" IsReadOnly="False" CanUserAddRows="False" VerticalAlignment="Top" + HeadersVisibility="All" RowHeaderWidth="10" Height="120" Margin="0,10,0,0" BorderThickness="1" ItemsSource="{Binding AlternatorTechnologies}"> <DataGrid.Resources> <DataTemplate x:Key="EntryDeleteControl"> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"> - <Button Width="100" Content="Remove" + <Button Width="30" Command="{Binding DataContext.RemoveAlternatorCommand, RelativeSource={RelativeSource AncestorType=local:AuxiliariesDeclarationView}}" CommandParameter="{Binding ElementName=AlternatorDataGrid, Path=SelectedIndex}"> + <iconPacks:PackIconModern Width="30" Height="15" Kind="Delete" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Button> </StackPanel> </DataTemplate> - - <DataTemplate x:Key="AtlernatorText"> - <TextBox Text="{Binding}" /> + <DataTemplate x:Key="AlternatorTechCombobox"> + <ComboBox DisplayMemberPath="Label" SelectedValuePath="Value" + ItemsSource="{Binding DataContext.AllowedAlternatorTechnology, + RelativeSource={RelativeSource AncestorType=local:AuxiliariesDeclarationView}}" + SelectedValue="{Binding AlternatorTechnology, UpdateSourceTrigger=PropertyChanged}"> + </ComboBox> </DataTemplate> </DataGrid.Resources> <DataGrid.Columns> - <!--<DataGridTemplateColumn Header="Technology" CellTemplate="{StaticResource AtlernatorText}" Width="110" />--> - <DataGridTextColumn Header="Alternator Technology" Binding="{Binding }" /> - <DataGridTemplateColumn CellTemplate="{StaticResource EntryDeleteControl}" Width="110" /> + <DataGridTemplateColumn Header="Alternator Technology" CellTemplate="{StaticResource AlternatorTechCombobox}"/> + <DataGridTemplateColumn CellTemplate="{StaticResource EntryDeleteControl}" Width="40" /> </DataGrid.Columns> </DataGrid> diff --git a/VectoCommon/VectoCommon/InputData/DeclarationInputData.cs b/VectoCommon/VectoCommon/InputData/DeclarationInputData.cs index 2736f510fb26b629d73964168824fa07c8a07c64..91ffd963d9a2e5c8ce834c2049f3522e0c20f26a 100644 --- a/VectoCommon/VectoCommon/InputData/DeclarationInputData.cs +++ b/VectoCommon/VectoCommon/InputData/DeclarationInputData.cs @@ -335,6 +335,22 @@ namespace TUGraz.VectoCommon.InputData Compressed } + public static class TankSystemHelper + { + public static TankSystem? Parse(string parse) + { + switch (parse) { + case nameof(TankSystem.Liquefied): + return TankSystem.Liquefied; + case nameof(TankSystem.Compressed): + return TankSystem.Compressed; + default: + return null; + } + } + } + + public interface IAirdragDeclarationInputData : IComponentInputData { /// <summary> diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationVehicleDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationVehicleDataProvider.cs index 4ee888c49eb114f28aed857f7ef6d2a78bac4d2e..c36e0e8cfcc5f57b55e59fcd9fb4fc84bdcdda3e 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationVehicleDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationVehicleDataProvider.cs @@ -818,7 +818,12 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider public override TankSystem? TankSystem { - get { return ElementExists(XMLNames.Vehicle_NgTankSystem) ? GetString(XMLNames.Vehicle_NgTankSystem).ParseEnum<TankSystem>() : (TankSystem?)null; } + get + { + return ElementExists(XMLNames.Vehicle_NgTankSystem) + ? EnumHelper.ParseEnum<TankSystem>(GetString(XMLNames.Vehicle_NgTankSystem)) + : (TankSystem?)null; + } } public override int NumberOfPassengersLowerDeck