Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 63078a3a authored by Franz KOBER josef's avatar Franz KOBER josef
Browse files

added edit component File, added to load airdrag data from xml file

parent c02614c7
No related branches found
No related tags found
No related merge requests found
Showing
with 241 additions and 42 deletions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Resources;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.InputData.FileIO.XML.Common;
using VECTO3GUI.Model.TempDataObject;
namespace VECTO3GUI.Helper
{
public class XmlComponentReaderHelper : AbstractXMLType
{
public XmlComponentReaderHelper(XmlNode node) : base(node) { }
public AirdragComponentData GetAirdragComponentData()
{
if (!ElementExists(XMLNames.Component_AirDrag))
return null;
return new AirdragComponentData {
Manufacturer = GetString(XMLNames.Component_Manufacturer),
Model = GetString(XMLNames.Component_Model),
CertificationNumber = GetString(XMLNames.Component_CertificationNumber),
Date = DateTime.Parse(GetString(XMLNames.Component_Date)).ToUniversalTime(),
AppVersion = GetString(XMLNames.Component_AppVersion),
CdxA_0 = GetDouble("CdxA_0").SI<SquareMeter>(),
TransferredCdxA = GetDouble("TransferredCdxA").SI<SquareMeter>(),
DeclaredCdxA = GetDouble(XMLNames.AirDrag_DeclaredCdxA).SI<SquareMeter>(),
DigestValue = new DigestData(GetNode(XMLNames.DI_Signature))
};
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Castle.Core.Internal;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using TUGraz.VectoCommon.Resources;
namespace VECTO3GUI.Helper
{
public static class XmlReaderHelper
{
public static XmlDocument ReadXmlDocument(string filePath)
{
if (filePath.IsNullOrEmpty())
return null;
var xmlDocument = new XmlDocument();
using (var reader = new XmlTextReader(filePath)) {
xmlDocument.Load(reader);
}
return xmlDocument;
}
public static XmlNodeList GetComponentNodes(XmlDocument xmlDocument, string parentNode, string nodeName)
{
if (xmlDocument == null || parentNode.IsNullOrEmpty() || nodeName.IsNullOrEmpty())
return null;
return xmlDocument.SelectNodes($"//*[local-name()='{parentNode}']//*[local-name()='{nodeName}']");
}
}
}
......@@ -7,6 +7,7 @@
xmlns:interfaces="clr-namespace:VECTO3GUI.ViewModel.Interfaces"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:impl="clr-namespace:VECTO3GUI.ViewModel.Impl"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d"
Title="{Binding Version}" Height="515.36" Width="972.48" WindowStartupLocation="CenterScreen"
d:DataContext="{d:DesignInstance Type=impl:MainWindowViewModel, IsDesignTimeCreatable=False}">
......@@ -22,7 +23,7 @@
<StackPanel Orientation="Vertical">
<Menu IsMainMenu="True" Style="{DynamicResource MetroMenu}">
<MenuItem Header="File">
<MenuItem Header="File" VerticalAlignment="Center">
<MenuItem Header="New" Style="{DynamicResource MetroMenuItem}" Margin="0"
Command="{Binding CurrentViewModel.CreateNewJob}"/>
<MenuItem Header="Edit" Style="{DynamicResource MetroMenuItem}" Margin="0"
......@@ -37,7 +38,10 @@
<MenuItem Header="Tools">
<MenuItem Header="Tools" VerticalAlignment="Center">
<!--<MenuItem.Icon>
<iconPacks:PackIconModern Width="15" Height="15" Kind="Tools" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Green" />
</MenuItem.Icon>-->
<MenuItem Header="Single Bus Job"
Command="{Binding CurrentViewModel.AddBusJob}" CommandParameter="{Binding Source={x:Static impl:JobType.SingleBusJob}}"/>
<MenuItem Header="Completed Bus Job"
......@@ -49,7 +53,7 @@
</MenuItem>
<MenuItem Header="Help">
<MenuItem Header="Help" VerticalAlignment="Center">
<MenuItem Header="User Manual"/>
<MenuItem Header="About Vecto"/>
<MenuItem Header="Relase Notes"/>
......
......@@ -27,6 +27,7 @@ namespace VECTO3GUI.Model.TempDataObject
#endregion
public AirdragComponentData(){}
public AirdragComponentData(IAirdragViewModel viewModel , bool defaultValues)
{
......
<?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:AirDrag>
<Data id="TestAirDrag1234" xsi:type="AirDragDataDeclarationType">
<Manufacturer>Test AirDrag Manufacturer</Manufacturer>
<Model>Test AirDrag Model</Model>
<CertificationNumber>e12*0815/8051*2020/05E0000*66</CertificationNumber>
<Date>2020-04-28T09:16:15.1270795Z</Date>
<AppVersion>Vecto AirDrag Test Load</AppVersion>
<CdxA_0>6.12</CdxA_0>
<TransferredCdxA>7.12</TransferredCdxA>
<DeclaredCdxA>8.12</DeclaredCdxA>
</Data>
<Signature>
<di:Reference URI="#TestAirDrag1234">
<di:Transforms>
<di:Transform Algorithm="urn:vecto:xml:2017:canonicalization" />
<di:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</di:Transforms>
<di:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<di:DigestValue>Yd3UDJ/zKPhsmPadJeC4Ez/q7o3G82Zbq3mX3tSqLDw=</di:DigestValue>
</di:Reference>
</Signature>
</tns:AirDrag>
</tns:VectoInputDeclaration>
\ No newline at end of file
......@@ -171,6 +171,8 @@
<Compile Include="Helper\Converter\SaveButtonLabelConverter.cs" />
<Compile Include="Helper\SerializeHelper.cs" />
<Compile Include="Helper\ViewModelBase.cs" />
<Compile Include="Helper\XmlComponentReaderHelper.cs" />
<Compile Include="Helper\XmlReaderHelper.cs" />
<Compile Include="Model\InterfacesImpl.cs" />
<Compile Include="Model\JobListModel.cs" />
<Compile Include="Model\SettingsModel.cs" />
......@@ -623,7 +625,9 @@
<Name>VectoCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="Resources\AirdragLoadTestFile.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
......@@ -148,7 +148,7 @@ namespace VECTO3GUI.ViewModel.Impl
private void SetJobEntryData(JobEntry jobEntry)
{
FirstFilePath = jobEntry.FirstFilePath;
SecondFilePath = jobEntry.FirstFilePath;
SecondFilePath = jobEntry.SecondFilePath;
}
protected abstract void SetFirstFileLabel();
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Input;
using System.Xml;
using Castle.Core.Internal;
using Ninject;
using TUGraz.VectoCommon.Hashing;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Resources;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.InputData.FileIO.XML;
using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Reader;
using TUGraz.VectoCore.Utils;
using VECTO3GUI.Helper;
using VECTO3GUI.Model.TempDataObject;
using VECTO3GUI.Util;
......@@ -65,7 +63,10 @@ namespace VECTO3GUI.ViewModel.Impl
private IAirdragDeclarationInputData _airdragData;
private AirdragComponentData _componentData;
private bool _isEditable;
private bool _useMeasurementData;
private bool _noAirdragData;
private ICommand _airdragConfig;
private ICommand _loadFileCommand;
......@@ -126,7 +127,6 @@ namespace VECTO3GUI.ViewModel.Impl
{
if (!SetProperty(ref _date, value))
return;
IsDataChanged(_date, _componentData);
}
}
......@@ -138,9 +138,7 @@ namespace VECTO3GUI.ViewModel.Impl
{
if (!SetProperty(ref _declaredCdxA, value))
return;
IsDataChanged(_declaredCdxA, _componentData);
SetAirdragArea(_airdragData);
}
}
......@@ -165,13 +163,27 @@ namespace VECTO3GUI.ViewModel.Impl
set { SetProperty(ref _isEditable, value); }
}
public bool UseMeasurementData
{
get { return _useMeasurementData; }
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;
SetAirdragValues(_airdragData);
IsEditable = true;
UseMeasurementData = _airdragData != null;
NoAirdragData = !UseMeasurementData;
IsEditable = false;
}
private void SetAirdragValues(IAirdragDeclarationInputData airdrag)
......@@ -188,7 +200,9 @@ namespace VECTO3GUI.ViewModel.Impl
CertificationNumber = airdrag.CertificationNumber;
Date = airdrag.Date;
AppVersion = airdrag.AppVersion;
SetAirdragArea(airdrag);
DeclaredCdxA = airdrag.AirDragArea;
CdxA_0 = DeclaredCdxA;
TransferredCdxA = DeclaredCdxA;
DigestValue = airdrag.DigestValue;
_componentData = new AirdragComponentData(this);
......@@ -207,7 +221,7 @@ namespace VECTO3GUI.ViewModel.Impl
private void DoAirdragConfig(AirdragConfig config)
{
IsEditable = config == AirdragConfig.UseMeasurementData;
}
......@@ -221,25 +235,17 @@ namespace VECTO3GUI.ViewModel.Impl
private bool CanLoadFile()
{
return IsEditable;
return UseMeasurementData;
}
private void DoLoadFile()
{
var filePath = FileDialogHelper.ShowSelectFilesDialog(false)?.FirstOrDefault();
ReadSelectedXml(null);
ReadSelectedXml(filePath);
}
#endregion
private void SetAirdragArea(IAirdragDeclarationInputData airdrag)
{
DeclaredCdxA = airdrag.AirDragArea;
CdxA_0 = DeclaredCdxA;
TransferredCdxA = DeclaredCdxA;
}
public override void ResetComponentData()
{
_componentData.ResetToComponentValues(this);
......@@ -254,8 +260,34 @@ namespace VECTO3GUI.ViewModel.Impl
private void ReadSelectedXml(string filePath)
{
if (filePath == null)
if (filePath.IsNullOrEmpty())
return;
var xmlDocument = XmlReaderHelper.ReadXmlDocument(filePath);
var nodes = XmlReaderHelper.GetComponentNodes(xmlDocument,
XMLNames.VectoInputDeclaration, VectoComponents.Airdrag.XMLElementName());
if(nodes.IsNullOrEmpty())
return;
var compReader = new XmlComponentReaderHelper(nodes[0].ParentNode);
SetLoadedAirdragData(compReader.GetAirdragComponentData());
}
private void SetLoadedAirdragData(AirdragComponentData airdrag)
{
if (airdrag == null)
return;
Model = airdrag.Model;
Manufacturer = airdrag.Manufacturer;
CertificationNumber = airdrag.CertificationNumber;
Date = airdrag.Date;
AppVersion = airdrag.AppVersion;
DeclaredCdxA = airdrag.DeclaredCdxA;
CdxA_0 = airdrag.CdxA_0;
TransferredCdxA = airdrag.TransferredCdxA;
DigestValue = airdrag.DigestValue;
}
}
}
......@@ -7,7 +7,10 @@ using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Xml;
using Ninject;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCore.InputData.FileIO.XML;
using VECTO3GUI.Util;
using VECTO3GUI.ViewModel.Interfaces;
using VECTO3GUI.Helper;
......@@ -43,6 +46,7 @@ namespace VECTO3GUI.ViewModel.Impl
private ICommand _exitCommand;
private ICommand _exitMainCommand;
private ICommand _addBusJobCommand;
private ICommand _editCompletedFileCommand;
#endregion
......@@ -143,6 +147,31 @@ namespace VECTO3GUI.ViewModel.Impl
}
}
public ICommand EditCompletedFile
{
get
{
return _editCompletedFileCommand ??
(_editCompletedFileCommand =
new RelayCommand<JobEntry>(DoEditCompletedFile, CanEditCompletdFile));
}
}
private bool CanEditCompletdFile(JobEntry jobEntry)
{
return jobEntry != null;
}
private void DoEditCompletedFile(JobEntry jobEntry)
{
var viewModel = ReadCompletedXmlFile(jobEntry);
if (viewModel == null)
return;
var window = OutputWindowHelper.CreateOutputWindow(Kernel, viewModel);
window.Show();
}
private bool CanEditJob(JobEntry jobEntry)
{
return jobEntry != null;
......@@ -231,7 +260,6 @@ namespace VECTO3GUI.ViewModel.Impl
var window = OutputWindowHelper.CreateOutputWindow(Kernel, viewModel, "Settings", 440, 200,
ResizeMode.NoResize);
window.ShowDialog();
}
public ICommand ExitMainCommand
......@@ -271,10 +299,7 @@ namespace VECTO3GUI.ViewModel.Impl
#endregion
private object GetBusJobViewModel(JobType jobType, JobEntry jobEntry = null)
{
var currentJobType = jobEntry?.JobType ?? jobType;
......@@ -320,6 +345,25 @@ namespace VECTO3GUI.ViewModel.Impl
{
SerializeHelper.SerializeToFile(jobEntry.JobEntryFilePath, jobEntry);
}
private IJobEditViewModel ReadCompletedXmlFile(JobEntry jobEntry)
{
var xmlInputReader = Kernel.Get<IXMLInputDataReader>();
using (var reader = XmlReader.Create(jobEntry.SecondFilePath)) {
var readerResult = xmlInputReader.Create(reader) as IDeclarationInputDataProvider;
return CreateCompleteBusVehicleViewModel(readerResult);
}
}
private IJobEditViewModel CreateCompleteBusVehicleViewModel(IDeclarationInputDataProvider dataProvider)
{
_messages.Add(new MessageEntry
{
Message = "Edit File"
});
return dataProvider == null ? null : new CompleteVehicleBusJobViewModel(Kernel, dataProvider);
}
//private IJobEditViewModel ReadJob(string jobFile)
//{
// if (jobFile == null)
......
......@@ -8,6 +8,10 @@ namespace VECTO3GUI.ViewModel.Interfaces
{
IAirdragDeclarationInputData ModelData { get; }
bool IsEditable { get; }
bool NoAirdragData { get; }
bool UseMeasurementData { get; }
ICommand LoadFileCommand { get; }
ICommand AirdragConfigCommand { get; }
......
......@@ -17,6 +17,7 @@ namespace VECTO3GUI.ViewModel.Interfaces
ICommand MoveJobDown { get; }
ICommand StartSimulation { get; }
ICommand EditJob { get; }
ICommand EditCompletedFile { get; }
ICommand JobEntrySetActive { get; }
ICommand CreateNewJob { get; }
ICommand OpenJob { get; }
......
......@@ -32,12 +32,13 @@
<StackPanel Orientation="Vertical">
<RadioButton GroupName="AirdragConfig" Margin="5"
Content="{Binding Source={x:Static impl:AirdragConfig.WithoutAirdrag}, Converter={converter:EnumConverter}}"
Command="{Binding AirdragConfigCommand}" CommandParameter="{Binding Source={x:Static impl:AirdragConfig.WithoutAirdrag}}"/>
Command="{Binding AirdragConfigCommand}" CommandParameter="{Binding Source={x:Static impl:AirdragConfig.WithoutAirdrag}}"
IsChecked="{Binding NoAirdragData}"/>
<RadioButton GroupName="AirdragConfig" Margin="5"
Content="{Binding Source={x:Static impl:AirdragConfig.UseMeasurementData}, Converter={converter:EnumConverter}}"
Command="{Binding AirdragConfigCommand}" CommandParameter="{ Binding Source={x:Static impl:AirdragConfig.UseMeasurementData}}"
IsChecked="{Binding IsEditable}"/>
IsChecked="{Binding UseMeasurementData}"/>
<StackPanel Orientation="Horizontal" Margin="30,10,10,10">
<Label Content="Load Component File:"/>
......@@ -51,18 +52,18 @@
</GroupBox>
<GroupBox Header="Aridrag Data" Width="500" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1" Height="250" VerticalAlignment="Top"
Visibility="{Binding IsEditable, Converter={converter:BoolVisibilityConverter}}">
Visibility="{Binding UseMeasurementData, Converter={converter:BoolVisibilityConverter}}">
<StackPanel Orientation="Vertical" Width="450" HorizontalAlignment="Left" Grid.IsSharedSizeScope="True">
<customControls:VectoParameterControl
Caption="Manufacturer" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth"
Value="{Binding Manufacturer}" IsEnabled="{Binding IsEditable}" />
Value="{Binding Manufacturer}" IsEnabled="{Binding IsEditable, UpdateSourceTrigger=PropertyChanged}" />
<customControls:VectoParameterControl
Caption="Model" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth"
Value="{Binding Model}" IsEnabled="{Binding IsEditable}" />
Value="{Binding Model}" IsEnabled="{Binding IsEditable, UpdateSourceTrigger=PropertyChanged}" />
<!-- <mah:DateTimePicker -->
<!-- SelectedDate="{Binding Date}" -->
......
......@@ -40,9 +40,10 @@
<customControls:VectoParameterControl
Caption="VIN" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth"
Value="{Binding VIN}" />
<customControls:VectoParameterControl
<!--<customControls:VectoParameterControl
Caption="Date" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth"
Value="{Binding Date}" />
Value="{Binding Date}" />-->
<customControls:ComboParameter
Caption="Legislative Class"
......
......@@ -22,7 +22,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition/>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
......@@ -84,10 +84,14 @@
<Grid Grid.Row="1" Grid.Column="2" Margin="0,0,10,0">
<StackPanel Orientation="Vertical" Margin="0,30,0,0">
<Button Margin="0,5,0,0" Content="Edit Job"
<Button Margin="0,5,0,0" Content="Edit Job" Width="110"
Command="{Binding EditJob}"
CommandParameter="{Binding ElementName=JobList, Path=SelectedItem}"/>
<Button Margin="0,5,0,0" Content="Edit Completed File" Width="110"
Command="{Binding EditCompletedFile}"
CommandParameter="{Binding ElementName=JobList, Path=SelectedItem}" />
<!--<Button Margin="0,5,0,0" Command="{Binding AddBusJob}" Content="Add Bus Job"/>
<Button Margin="0,5,0,0" Command="{Binding EditJob}" Content="Edit File" />
......
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