diff --git a/VECTO3GUI2020/Helper/Converter/SIToUnitString.cs b/VECTO3GUI2020/Helper/Converter/SIToUnitString.cs index 54701cba7670eff3e1c0a00357e25c191460c6d9..351050e16f18b635e41fa0c0c499bdcf1582be12 100644 --- a/VECTO3GUI2020/Helper/Converter/SIToUnitString.cs +++ b/VECTO3GUI2020/Helper/Converter/SIToUnitString.cs @@ -30,11 +30,8 @@ namespace VECTO3GUI2020.Helper.Converter } - return Binding.DoNothing; - - - } + } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { diff --git a/VECTO3GUI2020/Helper/Converter/SIValueToStringConverter.cs b/VECTO3GUI2020/Helper/Converter/SIValueToStringConverter.cs index 985d766feadc7b6f5e094ead3c00a9b0578e6797..337978a6b9d79e3c0fd7b39b0ec14f51421a9cfd 100644 --- a/VECTO3GUI2020/Helper/Converter/SIValueToStringConverter.cs +++ b/VECTO3GUI2020/Helper/Converter/SIValueToStringConverter.cs @@ -25,8 +25,8 @@ namespace VECTO3GUI2020.Helper.Converter } - return Binding.DoNothing; - } + return value; + } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { diff --git a/VECTO3GUI2020/Helper/XMLExtension.cs b/VECTO3GUI2020/Helper/XMLExtension.cs index e9e391f6569f1fea53e142d13abf5be4a6ca1a82..f9ab57c71ccab2403bfcff4711053b9a6fe2a3e0 100644 --- a/VECTO3GUI2020/Helper/XMLExtension.cs +++ b/VECTO3GUI2020/Helper/XMLExtension.cs @@ -1,9 +1,12 @@ using System; using System.Diagnostics; +using System.Xml; using System.Xml.Linq; +using System.Xml.Schema; using Castle.Core.Resource; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCore.Utils; using TUGraz.VectoHashing.Impl; using VECTO3GUI2020.Util.XML; using VECTO3GUI2020.Util.XML.Interfaces; @@ -39,5 +42,59 @@ namespace VECTO3GUI2020.Helper return signatureElement; } - } + + + public static XmlDocument ToXmlDocument(this XDocument xDocument) + { + var xmlDocument = new XmlDocument(); + using (var reader = xDocument.CreateReader()) + { + xmlDocument.Load(reader); + } + + var xDeclaration = xDocument.Declaration; + if (xDeclaration != null) + { + var xmlDeclaration = xmlDocument.CreateXmlDeclaration( + xDeclaration.Version, + xDeclaration.Encoding, + xDeclaration.Standalone); + + xmlDocument.InsertBefore(xmlDeclaration, xmlDocument.FirstChild); + } + + return xmlDocument; + } + + public static XmlNode ToXmlNode(this XElement element) + { + using (XmlReader xmlReader = element.CreateReader()) + { + XmlDocument xmlDocument = new XmlDocument(); + xmlDocument.Load(xmlReader); + return xmlDocument; + } + } + + public static string GetVersion(this XElement element) + { + return element.ToXmlNode().GetVersion(); + } + + public static string GetVersion(this XmlNode node) + { + if (node == null) + { + return null; + } + var version = XMLHelper.GetXsdType(node.SchemaInfo.SchemaType); + if (string.IsNullOrWhiteSpace(version)) + { + version = XMLHelper.GetVersionFromNamespaceUri((node.SchemaInfo.SchemaType?.Parent as XmlSchemaElement)?.QualifiedName.Namespace); + } + + return version; + } + +} } \ No newline at end of file diff --git a/VECTO3GUI2020/Helper/XmlHelper.cs b/VECTO3GUI2020/Helper/XmlHelper.cs index 75ea3988078864a3c4b590db9bc4f848cdf4170f..0f3a71178eb5b07edc5cedad0c07c6abdc9020b2 100644 --- a/VECTO3GUI2020/Helper/XmlHelper.cs +++ b/VECTO3GUI2020/Helper/XmlHelper.cs @@ -1,6 +1,10 @@ using System; using System.Xml; +using System.Xml.Linq; +using System.Xml.Schema; using Castle.Core.Internal; +using TUGraz.VectoCommon.Exceptions; +using TUGraz.VectoCore.Utils; namespace VECTO3GUI2020.Helper { @@ -13,9 +17,8 @@ namespace VECTO3GUI2020.Helper var xmlDocument = new XmlDocument(); - using (var reader = new XmlTextReader(filePath)) { - xmlDocument.Load(reader); - } + + xmlDocument.Load(filePath); return xmlDocument; } @@ -29,22 +32,22 @@ namespace VECTO3GUI2020.Helper return xmlDocument.SelectNodes($"//*[local-name()='{parentNode}']//*[local-name()='{nodeName}']"); } - //public static bool ValidateXDocument(XDocument xDocument, Action<bool> resultAction = null, - // Action<XmlSeverityType, ValidationEvent> validationErrorAction = null) - //{ - // var xmlDocument = xDocument.ToXmlDocument(); - // if (xmlDocument == null) - // return false; - - // var documentType = XMLHelper.GetDocumentType(xmlDocument.DocumentElement.LocalName); - // if (documentType == null) - // { - // throw new VectoException("unknown xml file! {0}", xmlDocument.DocumentElement.LocalName); - // } - - // var validator = new XMLValidator(xmlDocument, resultAction, validationErrorAction); - // return validator.ValidateXML(documentType.Value); ; - //} + public static bool ValidateXDocument(XDocument xDocument, Action<bool> resultAction = null, + Action<XmlSeverityType, ValidationEvent> validationErrorAction = null) + { + var xmlDocument = xDocument.ToXmlDocument(); + if (xmlDocument == null) + return false; + + var documentType = XMLHelper.GetDocumentType(xmlDocument.DocumentElement.LocalName); + if (documentType == null) + { + throw new VectoException("unknown xml file! {0}", xmlDocument.DocumentElement.LocalName); + } + + var validator = new XMLValidator(xmlDocument, resultAction, validationErrorAction); + return validator.ValidateXML(documentType.Value); ; + } public static string GetXmlAbsoluteFilePath(string baseUri) { diff --git a/VECTO3GUI2020/Ninject/Vehicle/ComponentModule.cs b/VECTO3GUI2020/Ninject/Vehicle/ComponentModule.cs index f065c4e26e315c38da7b5e11167467b06a238fc4..edbbce58125ff6731a7d06984f093e08a7a5814c 100644 --- a/VECTO3GUI2020/Ninject/Vehicle/ComponentModule.cs +++ b/VECTO3GUI2020/Ninject/Vehicle/ComponentModule.cs @@ -35,6 +35,7 @@ namespace VECTO3GUI2020.Ninject.Vehicle Bind<IComponentViewModel>().To<AirDragViewModel_v1_0>().Named(AirDragViewModel_v1_0.VERSION); Bind<IComponentViewModel>().To<AirDragViewModel_v2_0>().Named(AirDragViewModel_v2_0.VERSION); + Bind<IComponentViewModel>().To<AirDragViewModel_v2_8>().Named(AirDragViewModel_v2_8.VERSION); Bind<IComponentViewModel>().To<AxleWheelsViewModel_v1_0>().Named(AxleWheelsViewModel_v1_0.VERSION); Bind<IComponentViewModel>().To<AxleWheelsViewModel_v2_0>().Named(AxleWheelsViewModel_v2_0.VERSION); diff --git a/VECTO3GUI2020/Resources/ViewModelBindings.xaml b/VECTO3GUI2020/Resources/ViewModelBindings.xaml index 710e06cad4b37e4f9a34d9473764aff4df0feacb..8ffe02b00f64e1cda88c2b3599c26858f7440e18 100644 --- a/VECTO3GUI2020/Resources/ViewModelBindings.xaml +++ b/VECTO3GUI2020/Resources/ViewModelBindings.xaml @@ -193,6 +193,11 @@ <componentviews:EngineFuelView/> </DataTemplate> <!--#endregion--> + + <DataTemplate DataType="{x:Type componentimpl:AirDragViewModel_v2_8}"> + <multistageviews:AirDragView_v2_8></multistageviews:AirDragView_v2_8> + </DataTemplate> + <!--#region Multistage --> <DataTemplate DataType="{x:Type multistageimpl:NewMultiStageJobViewModel}"> <multistageviews:NewMultistageFileView/> diff --git a/VECTO3GUI2020/VECTO3GUI2020.csproj b/VECTO3GUI2020/VECTO3GUI2020.csproj index f3e1c83aeceec0de48a903cbd413a92e65765ab8..c2effc26c9d51c21435aea8609effe5f4089833a 100644 --- a/VECTO3GUI2020/VECTO3GUI2020.csproj +++ b/VECTO3GUI2020/VECTO3GUI2020.csproj @@ -345,9 +345,15 @@ <Compile Include="Views\MessageView.xaml.cs"> <DependentUpon>MessageView.xaml</DependentUpon> </Compile> + <Compile Include="Views\Multistage\AirDragView_v2_8.xaml.cs"> + <DependentUpon>AirDragView_v2_8.xaml</DependentUpon> + </Compile> <Compile Include="Views\Multistage\CustomControls\FilePicker.xaml.cs"> <DependentUpon>FilePicker.xaml</DependentUpon> </Compile> + <Compile Include="Views\Multistage\CustomControls\LabledTextBoxMultistage.xaml.cs"> + <DependentUpon>LabledTextBoxMultistage.xaml</DependentUpon> + </Compile> <Compile Include="Views\Multistage\CustomControls\MultiStageParameter.xaml.cs"> <DependentUpon>MultiStageParameter.xaml</DependentUpon> </Compile> @@ -536,10 +542,18 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\Multistage\AirDragView_v2_8.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Views\Multistage\CustomControls\FilePicker.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\Multistage\CustomControls\LabledTextBoxMultistage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Views\Multistage\CustomControls\MultiStageParameter.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/VECTO3GUI2020/ViewModel/Implementation/JobEdit/Vehicle/Components/AirDragViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/JobEdit/Vehicle/Components/AirDragViewModel.cs index b1d08176a28f4140a912cca9e111e50331da6dd7..d0af0de58898daabcef66995e4c9329ca4bf8ae0 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/JobEdit/Vehicle/Components/AirDragViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/JobEdit/Vehicle/Components/AirDragViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Reflection.Emit; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; @@ -31,7 +32,9 @@ namespace VECTO3GUI2020.ViewModel.Implementation.JobEdit.Vehicle.Components public AirDragViewModel(IXMLAirdragDeclarationInputData inputData, IComponentViewModelFactory vmFactory) - { + { + LabelVisible = true; + IsReadOnly = false; _inputData = inputData as IAirdragDeclarationInputData; Debug.Assert(_inputData != null); _isPresent = (_inputData?.DataSource?.SourceFile != null); @@ -49,6 +52,11 @@ namespace VECTO3GUI2020.ViewModel.Implementation.JobEdit.Vehicle.Components #region Implementation of IAirDragDeclarationInputData protected SquareMeter _airDragArea; + protected SquareMeter _transferredAirDragArea; + protected SquareMeter _airDragArea_0; + private bool _isReadOnly; + private bool _labelVisible; + public DataSource DataSource { get => _commonComponentViewModel.DataSource; @@ -100,11 +108,33 @@ namespace VECTO3GUI2020.ViewModel.Implementation.JobEdit.Vehicle.Components public string AppVersion => _commonComponentViewModel.AppVersion; - public virtual SquareMeter AirDragArea {get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public SquareMeter TransferredAirDragArea { get => throw new NotImplementedException(); } - public SquareMeter AirDragArea_0 { get => throw new NotImplementedException(); } + public virtual SquareMeter AirDragArea + { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } + public virtual SquareMeter TransferredAirDragArea { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } + public virtual SquareMeter AirDragArea_0 { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } #endregion + + public bool LabelVisible + { + get => _labelVisible; + set => SetProperty(ref _labelVisible, value); + } + + public bool IsReadOnly + { + get => _isReadOnly; + set => SetProperty(ref _isReadOnly, value); + } } @@ -142,4 +172,40 @@ namespace VECTO3GUI2020.ViewModel.Implementation.JobEdit.Vehicle.Components set => SetProperty(ref _airDragArea, value); } } + + public class AirDragViewModel_v2_8 : AirDragViewModel_v2_0 + { + public static new readonly string VERSION = typeof(XMLDeclarationAirdragDataProviderV28).FullName; + + public AirDragViewModel_v2_8(IXMLAirdragDeclarationInputData inputData, IComponentViewModelFactory vmFactory) : base(inputData, vmFactory) + { + LabelVisible = false; + IsReadOnly = true; + } + + public override void SetProperties() + { + _airDragArea = _inputData.AirDragArea; + _airDragArea_0 = _inputData.AirDragArea_0; + _transferredAirDragArea = _inputData.TransferredAirDragArea; + + } + + public override SquareMeter AirDragArea + { + get => _airDragArea; + set => SetProperty(ref _airDragArea, value); + } + + public override SquareMeter TransferredAirDragArea { + get => _transferredAirDragArea; + set => SetProperty(ref _transferredAirDragArea, value); + } + + public override SquareMeter AirDragArea_0 + { + get => _airDragArea_0; + set => SetProperty(ref _airDragArea_0, value); + } + } } diff --git a/VECTO3GUI2020/ViewModel/Interfaces/JobEdit/Vehicle/Components/IAirDragViewModel.cs b/VECTO3GUI2020/ViewModel/Interfaces/JobEdit/Vehicle/Components/IAirDragViewModel.cs index 866e9164f3d8b1c42d062ff3b109bfa460076c34..a78893acfa813411925d0bf9a123f75ea050eeea 100644 --- a/VECTO3GUI2020/ViewModel/Interfaces/JobEdit/Vehicle/Components/IAirDragViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Interfaces/JobEdit/Vehicle/Components/IAirDragViewModel.cs @@ -4,5 +4,7 @@ namespace VECTO3GUI2020.ViewModel.Interfaces.JobEdit.Vehicle.Components { public interface IAirDragViewModel : IAirdragDeclarationInputData, IComponentViewModel { + bool LabelVisible { get; set; } + bool IsReadOnly { get; set; } } } diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/ManufacturingStageViewModel_v0_1.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/ManufacturingStageViewModel_v0_1.cs index cd9b60973777cef42dc8134d65d8b5d750eafda2..c9e869725505e0e87083903fbcbad2f2421ab84b 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/ManufacturingStageViewModel_v0_1.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/ManufacturingStageViewModel_v0_1.cs @@ -88,7 +88,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation Components.Add(VehicleViewModel.Name, VehicleViewModel as IViewModelBase); - var airDragEditViewModel = viewModelFactory.GetMultistageAirdragViewModel(); + var airDragEditViewModel = viewModelFactory.GetMultistageAirdragViewModel(_consolidatedManufacturingStageInputData.Vehicle.Components.AirdragInputData); Components.Add("Airdrag", airDragEditViewModel as IViewModelBase); var auxiliariesViewModel = diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAirdragViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAirdragViewModel.cs index b38a051acdc11cc275e7a2b942112e053b488eba..295f958d8139bce9c11c96440e7ba22741543535 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAirdragViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAirdragViewModel.cs @@ -1,11 +1,20 @@ using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Windows; using System.Windows.Input; using System.Xml; +using System.Xml.Linq; +using System.Xml.Schema; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.XML; +using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider; +using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Factory; +using TUGraz.VectoCore.Utils; using VECTO3GUI2020.Helper; using VECTO3GUI2020.Properties; using VECTO3GUI2020.Util; @@ -19,7 +28,6 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation public class MultistageAirdragViewModel : ViewModelBase, IMultistageAirdragViewModel { private IDialogHelper _dialogHelper; - private IXMLInputDataReader _inputDataReader; private IComponentViewModelFactory _componentViewModelFactory; private IAirDragViewModel _airdragViewModel; private bool _airdragModified; @@ -31,21 +39,21 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation set => SetProperty(ref _airdragViewModel, value); } + public IAirdragDeclarationInputData ConsolidatedAirdragData + { + get => _consolidatedAirdragInputData; + set => SetProperty(ref _consolidatedAirdragInputData, value); + } + #region Commands private ICommand _loadAirdragFileCommand; + + private Dictionary<string, string> _validationErrors; + private IAirdragDeclarationInputData _consolidatedAirdragInputData; - private DataSource _dataSource; - private bool _savedInDeclarationMode; - private string _manufacturer; - private string _model; - private DateTime _date; - private string _appVersion; - private CertificationMethod _certificationMethod; - private string _certificationNumber; - private DigestData _digestValue; - private SquareMeter _airDragArea; + private readonly IDeclarationInjectFactory _injectFactory; public ICommand LoadAirdragFileCommand { @@ -55,67 +63,99 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation public void LoadAirdragFileCommandExecute() { var fileName = _dialogHelper.OpenXMLFileDialog(Settings.Default.DefaultFilePath); - + var success = true; + var errorStringBuilder = new StringBuilder(); try { - var xDoc = new XmlDocument(); - xDoc.Load(fileName); - - //_inputDataReader.Create(); - //var xmlNodes = GetXmlNodes(filePath); - //if (xmlNodes.IsNullOrEmpty()) - // return; - - //var compReader = new XmlComponentReaderHelper(xmlNodes[0].ParentNode); - //SetLoadedAirdragData(compReader.GetAirdragComponentData()); - + var xDoc = XDocument.Load(fileName); + var doc = new XmlDocument(); + doc.Load(fileName); + + var airdragElements = xDoc.Descendants().Where(e => e.Name.LocalName == XMLNames.Component_AirDrag); + if (airdragElements.Count() == 1) { + //GET FROM FILE + var dataProviderVersion = XMLDeclarationAirdragDataProviderV28.QUALIFIED_XSD_TYPE; + //var dataProviderVersion = XMLDeclarationAirdragDataProviderV28.QUALIFIED_XSD_TYPE; + + XElement airdragElement = airdragElements.First(); + XmlNode airdragNode = airdragElement.ToXmlNode(); + + var airDragInputData = _injectFactory.CreateAirdragData(dataProviderVersion, null, airdragNode, fileName); + AirDragViewModel = _componentViewModelFactory.CreateComponentViewModel(airDragInputData) as IAirDragViewModel; + success = false; + } else { + success = false; + } + + + } catch (Exception e) { - _dialogHelper.ShowMessageBox(e.Message, "Invalid File", MessageBoxButton.OK, + _dialogHelper.ShowMessageBox(e.Message, + "Invalid File", + MessageBoxButton.OK, MessageBoxImage.Error); } + + if (!success) { + + } } + private void ValidationErrorAction(XmlSeverityType arg1, ValidationEvent arg2) + { + var xmlException = arg2?.ValidationEventArgs?.Exception as XmlSchemaValidationException; + if (xmlException != null) + { + var message = xmlException.InnerException; + var sourceObject = xmlException.SourceObject as XmlElement; + var localName = sourceObject?.LocalName; + + if (sourceObject != null) + _validationErrors.Add(localName, message?.Message); + } + } #endregion - public MultistageAirdragViewModel(IDialogHelper dialogHelper, IXMLInputDataReader inputDataReader, IComponentViewModelFactory componentViewModelFactory) + public MultistageAirdragViewModel(IDialogHelper dialogHelper, IDeclarationInjectFactory injectFactory, IComponentViewModelFactory componentViewModelFactory) { _dialogHelper = dialogHelper; - _inputDataReader = inputDataReader; + _injectFactory = injectFactory; _componentViewModelFactory = componentViewModelFactory; } public MultistageAirdragViewModel(IAirdragDeclarationInputData consolidatedAirdragInputData, IDialogHelper dialogHelper, - IXMLInputDataReader inputDataReader, - IComponentViewModelFactory componentViewModelFactory) : this(dialogHelper, inputDataReader, componentViewModelFactory) + IDeclarationInjectFactory injectFactory, + IComponentViewModelFactory componentViewModelFactory) : this(dialogHelper, injectFactory, componentViewModelFactory) { - _consolidatedAirdragInputData = consolidatedAirdragInputData; - + ConsolidatedAirdragData = consolidatedAirdragInputData; } - public DataSource DataSource => _dataSource; + public DataSource DataSource => _airdragViewModel.DataSource; + + public bool SavedInDeclarationMode => _airdragViewModel.SavedInDeclarationMode; + + public string Manufacturer => _airdragViewModel.Manufacturer; - public bool SavedInDeclarationMode => _savedInDeclarationMode; + public string Model => _airdragViewModel.Model; - public string Manufacturer => _manufacturer; + public DateTime Date => _airdragViewModel.Date; - public string Model => _model; + public string AppVersion => _airdragViewModel.AppVersion; - public DateTime Date => _date; + public CertificationMethod CertificationMethod => _airdragViewModel.CertificationMethod; - public string AppVersion => _appVersion; + public string CertificationNumber => _airdragViewModel.CertificationNumber; - public CertificationMethod CertificationMethod => _certificationMethod; + public DigestData DigestValue => _airdragViewModel.DigestValue; - public string CertificationNumber => _certificationNumber; + public SquareMeter AirDragArea => _airdragViewModel.AirDragArea; - public DigestData DigestValue => _digestValue; + public SquareMeter TransferredAirDragArea => _airdragViewModel.TransferredAirDragArea; - public SquareMeter AirDragArea => _airDragArea; - public SquareMeter TransferredAirDragArea { get; } - public SquareMeter AirDragArea_0 { get; } + public SquareMeter AirDragArea_0 => _airdragViewModel.AirDragArea_0; } } \ No newline at end of file diff --git a/VECTO3GUI2020/Views/CustomControls/CustomControlExtensionMethods.cs b/VECTO3GUI2020/Views/CustomControls/CustomControlExtensionMethods.cs index f531832eb089cb5201e5b9e247d05f371e2fc239..02d770aea57acf1958af03e4342b42a216abe70e 100644 --- a/VECTO3GUI2020/Views/CustomControls/CustomControlExtensionMethods.cs +++ b/VECTO3GUI2020/Views/CustomControls/CustomControlExtensionMethods.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Resources; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using TUGraz.VectoCommon.Utils; namespace VECTO3GUI2020.Views.CustomControls { @@ -46,5 +48,56 @@ namespace VECTO3GUI2020.Views.CustomControls var PropertyType = Binding?.ResolvedSource?.GetType().GetProperty(PropertyName).PropertyType; return PropertyType; } + + public static object CreateDummyContent(this UserControl userControl, DependencyPropertyChangedEventArgs e) + { + var type = userControl.GetPropertyType(e.Property); + if (type == null) + { + return null; + } + try + { + dynamic dynType = type; + var baseType = dynType.BaseType; + //Create SI Dummy + + if (baseType.BaseType == typeof(SI)) + { + var createMethod = baseType.GetMethod("Create"); + var dummyContent = createMethod?.Invoke(null, new object[] { (new double()) }); + return dummyContent; + } + else + { + var bindingProperty = userControl.GetBindingExpression(e.Property); + 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]); + } + + return dummyEnum; + } + + } + catch (Exception ex) + { + Debug.WriteLine(ex.Message); + return null; + } + + return null; + } + } } diff --git a/VECTO3GUI2020/Views/Multistage/AirDragView_v2_8.xaml b/VECTO3GUI2020/Views/Multistage/AirDragView_v2_8.xaml new file mode 100644 index 0000000000000000000000000000000000000000..f09fcfaecd01282da28029b2559b740a029aaecc --- /dev/null +++ b/VECTO3GUI2020/Views/Multistage/AirDragView_v2_8.xaml @@ -0,0 +1,35 @@ +<UserControl x:Class="VECTO3GUI2020.Views.Multistage.AirDragView_v2_8" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage" + xmlns:customControls="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls" + xmlns:implementation="clr-namespace:VECTO3GUI2020.ViewModel.Implementation.JobEdit.Vehicle.Components" d:DataContext="{d:DesignInstance Type=implementation:AirDragViewModel_v2_8}" + mc:Ignorable="d" + d:DesignHeight="450" d:DesignWidth="800"> + <Grid> + <StackPanel> + <Label + Visibility="{Binding LabelVisible, Converter={StaticResourceExtension BooleanToVisibilityConverter}}">Airdrag</Label> + <customControls:LabledTextBoxMultistage + Content="{Binding Manufacturer}" + ReadOnly="{Binding IsReadOnly}"/> + <customControls:LabledTextBoxMultistage + Content="{Binding Model}" + ReadOnly="{Binding IsReadOnly}"/> + <customControls:LabledTextBoxMultistage + Content="{Binding CertificationNumber}" + ReadOnly="{Binding IsReadOnly}"/> + <customControls:LabledTextBoxMultistage + Content="{Binding AirDragArea}" + ReadOnly="{Binding IsReadOnly}"/> + <customControls:LabledTextBoxMultistage + Content="{Binding AirDragArea_0}" + ReadOnly="{Binding IsReadOnly}"/> + <customControls:LabledTextBoxMultistage + Content="{Binding TransferredAirDragArea}" + ReadOnly="{Binding IsReadOnly}"/> + </StackPanel> + </Grid> +</UserControl> diff --git a/VECTO3GUI2020/Views/Multistage/AirDragView_v2_8.xaml.cs b/VECTO3GUI2020/Views/Multistage/AirDragView_v2_8.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..581e3209f91c2731f29a91b6a9a7809575b6fb3e --- /dev/null +++ b/VECTO3GUI2020/Views/Multistage/AirDragView_v2_8.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace VECTO3GUI2020.Views.Multistage +{ + /// <summary> + /// Interaction logic for AirDragView_v2_8.xaml + /// </summary> + public partial class AirDragView_v2_8 : UserControl + { + public AirDragView_v2_8() + { + InitializeComponent(); + } + } +} diff --git a/VECTO3GUI2020/Views/Multistage/CustomControls/FilePicker.xaml b/VECTO3GUI2020/Views/Multistage/CustomControls/FilePicker.xaml index 3678da4594f7616e639489fef7dc336aceccb3f6..6c152faf1c3586ff94d682900b597a628dcc564b 100644 --- a/VECTO3GUI2020/Views/Multistage/CustomControls/FilePicker.xaml +++ b/VECTO3GUI2020/Views/Multistage/CustomControls/FilePicker.xaml @@ -5,19 +5,20 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls" mc:Ignorable="d" - d:DesignHeight="30" d:DesignWidth="800" Name="filepickercustomcontrol"> - <Grid> - <Grid Margin="4" DockPanel.Dock="Top"> - <Grid.ColumnDefinitions> + d:DesignHeight="30" d:DesignWidth="800" Name="filepickercustomcontrol" MinHeight="40" MaxHeight="30"> + <Grid Margin="4" VerticalAlignment="Stretch"> + <Grid.RowDefinitions> + <RowDefinition></RowDefinition> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> <ColumnDefinition Width="30px"></ColumnDefinition> </Grid.ColumnDefinitions> - <TextBox VerticalContentAlignment="Center" Height="Auto" Padding="4" Margin = "0 0 0 0" IsReadOnly="True" + <TextBox VerticalContentAlignment="Center" Padding="4" Margin = "0 0 0 0" IsReadOnly="True" Text="{Binding Text, ElementName=filepickercustomcontrol}" HorizontalAlignment="Stretch"/> <Button Padding="4" Margin="4 0 0 0" Grid.Column="1" Command="{Binding Command, ElementName=filepickercustomcontrol}"> <Image Source="../../../Resources/folderpicker.ico"> </Image> </Button> </Grid> - </Grid> </UserControl> diff --git a/VECTO3GUI2020/Views/Multistage/CustomControls/LabledTextBoxMultistage.xaml b/VECTO3GUI2020/Views/Multistage/CustomControls/LabledTextBoxMultistage.xaml new file mode 100644 index 0000000000000000000000000000000000000000..1fa1e051c49de67e53d343f66e92b6d167968fab --- /dev/null +++ b/VECTO3GUI2020/Views/Multistage/CustomControls/LabledTextBoxMultistage.xaml @@ -0,0 +1,29 @@ +<UserControl x:Class="VECTO3GUI2020.Views.Multistage.CustomControls.LabledTextBoxMultistage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls" + mc:Ignorable="d" + Name="labledTextBoxMultistage" + d:DesignHeight="450" d:DesignWidth="800"> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="4*" SharedSizeGroup="W"/> + <ColumnDefinition Width="4*" SharedSizeGroup="W"/> + <ColumnDefinition Width="1*" SharedSizeGroup="N"/> + </Grid.ColumnDefinitions> + + <Label Content="{Binding LabelText, ElementName=labledTextBoxMultistage}"/> + <TextBox Grid.Column="1" Name ="TextBoxContent" VerticalAlignment="Center" Margin="2 0 2 0" + Text="{Binding ElementName=labledTextBoxMultistage, Path=Content, + Converter={StaticResourceExtension SIValueToStringConverter}, + ValidatesOnExceptions=True, + UpdateSourceTrigger=PropertyChanged}" + + IsReadOnly="{Binding ElementName=labledTextBoxMultistage, Path=ReadOnly}"/> + <Label Grid.Column="2" x:Name="AutoUnitLabel" + Content="{Binding DummyContent, ElementName=labledTextBoxMultistage, Converter={StaticResource SIToUnitStringConverter}}"> + </Label> + </Grid> +</UserControl> diff --git a/VECTO3GUI2020/Views/Multistage/CustomControls/LabledTextBoxMultistage.xaml.cs b/VECTO3GUI2020/Views/Multistage/CustomControls/LabledTextBoxMultistage.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..bdaf1c6c12b5b598c0b02eeeb9d426a43c436132 --- /dev/null +++ b/VECTO3GUI2020/Views/Multistage/CustomControls/LabledTextBoxMultistage.xaml.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using VECTO3GUI2020.Properties; +using VECTO3GUI2020.Views.CustomControls; + +namespace VECTO3GUI2020.Views.Multistage.CustomControls +{ + + + + + /// <summary> + /// Interaction logic for LabledTextBoxMultistage.xaml + /// </summary> + public partial class LabledTextBoxMultistage : UserControl + { + #region Dependency Properties + + public static readonly DependencyProperty ReadOnlyProperty = DependencyProperty.Register( + "ReadOnly", typeof(bool), typeof(LabledTextBoxMultistage), new PropertyMetadata(default(bool))); + + public bool ReadOnly + { + get { return (bool)GetValue(ReadOnlyProperty); } + set { SetValue(ReadOnlyProperty, value); } + } + + + public static readonly DependencyProperty DummyContentProperty = DependencyProperty.Register( + "DummyContent", typeof(object), typeof(LabledTextBoxMultistage), new PropertyMetadata(default(object))); + + public object DummyContent + { + get { return (object)GetValue(DummyContentProperty); } + set { SetValue(DummyContentProperty, value); } + } + + public new static readonly DependencyProperty ContentProperty = + DependencyProperty.Register("Content", + typeof(object), + typeof(LabledTextBoxMultistage), + new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(ContentChanged))); //TODO Default value null breaks it for SIs default value "" for strings + + public new object Content + { + get { return (object)GetValue(ContentProperty); } + set + { + SetCurrentValue(ContentProperty, value); + } + } + + + public static readonly DependencyProperty LabelTextProperty = DependencyProperty.Register( + "LabelText", typeof(string), typeof(LabledTextBoxMultistage), new PropertyMetadata(null)); + + public string LabelText + { + get { return (string)GetValue(LabelTextProperty); } + set { SetValue(LabelTextProperty, value); } + } + + #endregion + + private static void ContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var labledTextBoxMultistage = (CustomControls.LabledTextBoxMultistage)d; + + + labledTextBoxMultistage.DummyContent = labledTextBoxMultistage.CreateDummyContent(e); + + if (labledTextBoxMultistage.LabelText != null) + { + return; + } + labledTextBoxMultistage.LabelText = labledTextBoxMultistage.GetLabelByPropertyName( + LabledTextBoxMultistage.ContentProperty, + Strings.ResourceManager); + } + + public LabledTextBoxMultistage() + { + InitializeComponent(); + } + } +} diff --git a/VECTO3GUI2020/Views/Multistage/ManufacturingStageView.xaml b/VECTO3GUI2020/Views/Multistage/ManufacturingStageView.xaml index 61edf5344a0221799b0c8ea34275379041434b20..28147f41d9eabd6c00550e51d3cc5c5c4938d078 100644 --- a/VECTO3GUI2020/Views/Multistage/ManufacturingStageView.xaml +++ b/VECTO3GUI2020/Views/Multistage/ManufacturingStageView.xaml @@ -7,7 +7,7 @@ xmlns:implementation="clr-namespace:VECTO3GUI2020.ViewModel.MultiStage.Implementation" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance implementation:ManufacturingStageViewModel_v0_1 }"> - <Grid MaxWidth="900"> + <Grid> <DockPanel> <Grid Margin="4" DockPanel.Dock="Top"> <Grid.ColumnDefinitions> diff --git a/VECTO3GUI2020/Views/Multistage/MultistageAirDragView.xaml b/VECTO3GUI2020/Views/Multistage/MultistageAirDragView.xaml index 61ba5e753f8159e6f3c0cdea009de6d4e6c65ace..35d0db362caa78173842cb8d0241be7a264c2dc0 100644 --- a/VECTO3GUI2020/Views/Multistage/MultistageAirDragView.xaml +++ b/VECTO3GUI2020/Views/Multistage/MultistageAirDragView.xaml @@ -4,17 +4,26 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage" - xmlns:customControls="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls" - xmlns:customControls1="clr-namespace:VECTO3GUI2020.Views.CustomControls" + xmlns:customControlsMultistage="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls" + xmlns:customControls="clr-namespace:VECTO3GUI2020.Views.CustomControls" xmlns:impl="clr-namespace:VECTO3GUI2020.ViewModel.MultiStage.Implementation" + xmlns:properties="clr-namespace:VECTO3GUI2020.Properties" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" BorderBrush="Aquamarine" BorderThickness="2" Margin="4" d:DataContext="{d:DesignInstance impl:MultistageAirdragViewModel}"> <Grid> <StackPanel> <Label Content="AIRDRAG" HorizontalAlignment="Stretch" Background="Aquamarine"/> - <customControls1:LabledCheckBoxAutomatic Content="{Binding AirdragModified}"></customControls1:LabledCheckBoxAutomatic> - <customControls:FilePicker Height="30px" VerticalAlignment="Top" Text="Test" Command="{Binding LoadAirdragFileCommand}"></customControls:FilePicker> + <customControlsMultistage:FilePicker Text="Test" Command="{Binding LoadAirdragFileCommand}"/> + <StackPanel HorizontalAlignment="Stretch" Margin="4"> + <Label>Consolidated Airdrag Data</Label> + <customControlsMultistage:LabledTextBoxMultistage Content="{Binding ConsolidatedAirdragData.Manufacturer, Mode=OneWay}" ReadOnly="True"/> + <customControlsMultistage:LabledTextBoxMultistage Content="{Binding ConsolidatedAirdragData.Model, Mode=OneWay}" ReadOnly="True"/> + <customControlsMultistage:LabledTextBoxMultistage Content="{Binding ConsolidatedAirdragData.AirDragArea, Mode=OneWay}" ReadOnly="True"/> + <Separator/> + <Label>Data from File</Label> + <ContentControl Margin="0" Padding="0" Content="{Binding AirDragViewModel}"/> + </StackPanel> </StackPanel> </Grid> diff --git a/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml b/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml index ac0ac999b7bc8da565663053300b00d0d649d96d..9bcdc5a5d8877ffb5c2ef43ab285b7625169ddc8 100644 --- a/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml +++ b/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml @@ -5,22 +5,14 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage" xmlns:implementation="clr-namespace:VECTO3GUI2020.ViewModel.MultiStage.Implementation" + xmlns:customControls="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance implementation:NewMultiStageJobViewModel }"> <Grid> <Grid MaxWidth="900"> <DockPanel> - <Grid Margin="4" DockPanel.Dock="Top"> - <Grid.ColumnDefinitions> - <ColumnDefinition></ColumnDefinition> - <ColumnDefinition Width="30px"></ColumnDefinition> - </Grid.ColumnDefinitions> - <TextBox VerticalContentAlignment="Center" Height="Auto" Padding="4" Margin = "0 0 0 0" IsReadOnly="True" - Text="{Binding VifPath}" HorizontalAlignment="Stretch"/> - <Button Padding="4" Margin="4 0 0 0" Grid.Column="1" Command="{Binding AddVifFile}"> - <Image Source="../../Resources/folderpicker.ico"> - </Image> - </Button> + <Grid DockPanel.Dock="Top"> + <customControls:FilePicker Grid.Row="0" Text="{Binding VifPath}" HorizontalAlignment="Stretch" Command="{Binding AddVifFile}"/> </Grid> <ContentControl Grid.Row="2" Content="{Binding MultiStageJobViewModel}"/> </DockPanel> diff --git a/VECTO3GUI2020/Views/Multistage/VehicleView_v2_8.xaml b/VECTO3GUI2020/Views/Multistage/VehicleView_v2_8.xaml index 591c174aa641f6ddccf344cad4b849329df641a8..4092b83895ba3d5bba379018f1af5de5bcca7a9b 100644 --- a/VECTO3GUI2020/Views/Multistage/VehicleView_v2_8.xaml +++ b/VECTO3GUI2020/Views/Multistage/VehicleView_v2_8.xaml @@ -44,6 +44,9 @@ HideCheckBox="True"/> <Separator/> + <custom:MultiStageParameter PreviousContent="{Binding ConsolidatedVehicleData.AirdragModifiedMultistage}" + Content="{Binding AirdragModifiedMultistage}" Mode="CHECKBOX"/> + <custom:MultiStageParameter PreviousContent="{Binding ConsolidatedVehicleData.GrossVehicleMassRating}" Content="{Binding GrossVehicleMassRating}"/> <custom:MultiStageParameter PreviousContent="{Binding ConsolidatedVehicleData.DoorDriveTechnology}" diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/Factory/IDeclarationInjectFactory.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/Factory/IDeclarationInjectFactory.cs index 05845d89eaec489a105fdacaf6d42463cdb33192..1adb5bfc09c3bda19d1affb11afc181b029c068a 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/Factory/IDeclarationInjectFactory.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/Factory/IDeclarationInjectFactory.cs @@ -128,6 +128,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Factory IXMLAxleReader CreateAxleReader(string version, IXMLDeclarationVehicleData vehicle, XmlNode componentsNode); IXMLGearboxReader CreateGearboxReader(string version, IXMLDeclarationVehicleData vehicle, XmlNode componentsNode); IXMLAuxiliaryReader CreateAuxiliariesReader(string version, IXMLDeclarationVehicleData vehicle, XmlNode componentsNode); + IXMLApplicationInformationData CreateApplicationInformationReader(string version, XmlNode applicationNode); diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/SchemaVersionMultistage.0.1/AirdragLoadTestFile.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/SchemaVersionMultistage.0.1/AirdragLoadTestFile.xml index 3baab2fa609ec00fcb3b5095be0d7a63a5211f9d..1942b81b05fbfe38985c80819d8e76337e948751 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/SchemaVersionMultistage.0.1/AirdragLoadTestFile.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/SchemaVersionMultistage.0.1/AirdragLoadTestFile.xml @@ -1,5 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> -<tns:VectoInputDeclaration xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v1.0" xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v1.0 https://webgate.ec.europa.eu/CITnet/svn/VECTO/trunk/Share/XML/XSD/VectoComponent.xsd"> +<tns:VectoInputDeclaration xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" + xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v1.0" + xmlns:di="http://www.w3.org/2000/09/xmldsig#" + schemaVersion="1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v1.0 C:\Users\Harry\source\repos\vecto-dev\VectoCore\VectoCore\Resources\XSD\VectoDeclarationComponent.xsd"> <tns:AirDrag> <Data id="TestAirDrag1234" xsi:type="AirDragDataDeclarationType"> <Manufacturer>Test AirDrag Manufacturer</Manufacturer>