From 584e3f26af80f68ff1910e10fcf4fde17ce36400 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Wed, 26 Apr 2017 13:26:11 +0200 Subject: [PATCH] allow exporting gearbox and axlegear data as XML from GUI --- VECTO/GUI/GearboxForm.Designer.vb | 22 ++++++-- VECTO/GUI/GearboxForm.vb | 36 +++++++++---- .../OutputData/XML/XMLDeclarationWriter.cs | 8 +-- .../OutputData/XML/XMLEngineeringWriter.cs | 54 ++++++++++++------- VectoCore/VectoCoreTest/XML/XMLWritingTest.cs | 4 +- 5 files changed, 85 insertions(+), 39 deletions(-) diff --git a/VECTO/GUI/GearboxForm.Designer.vb b/VECTO/GUI/GearboxForm.Designer.vb index 73232fd36e..a825d496d4 100644 --- a/VECTO/GUI/GearboxForm.Designer.vb +++ b/VECTO/GUI/GearboxForm.Designer.vb @@ -135,6 +135,7 @@ Partial Class GearboxForm Me.gbTCAccMin = New System.Windows.Forms.GroupBox() Me.lblGbxInfo = New System.Windows.Forms.Label() Me.btnExportXML = New System.Windows.Forms.Button() + Me.btnExportAxlGearXML = New System.Windows.Forms.Button() Me.ToolStrip1.SuspendLayout() Me.StatusStrip1.SuspendLayout() CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit() @@ -250,7 +251,7 @@ Partial Class GearboxForm ' Me.ButCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.ButCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel - Me.ButCancel.Location = New System.Drawing.Point(790, 648) + Me.ButCancel.Location = New System.Drawing.Point(798, 648) Me.ButCancel.Name = "ButCancel" Me.ButCancel.Size = New System.Drawing.Size(75, 23) Me.ButCancel.TabIndex = 7 @@ -260,7 +261,7 @@ Partial Class GearboxForm 'ButOK ' Me.ButOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) - Me.ButOK.Location = New System.Drawing.Point(709, 648) + Me.ButOK.Location = New System.Drawing.Point(717, 648) Me.ButOK.Name = "ButOK" Me.ButOK.Size = New System.Drawing.Size(75, 23) Me.ButOK.TabIndex = 6 @@ -1044,13 +1045,22 @@ Partial Class GearboxForm ' 'btnExportXML ' - Me.btnExportXML.Location = New System.Drawing.Point(468, 648) + Me.btnExportXML.Location = New System.Drawing.Point(459, 648) Me.btnExportXML.Name = "btnExportXML" - Me.btnExportXML.Size = New System.Drawing.Size(102, 23) + Me.btnExportXML.Size = New System.Drawing.Size(119, 23) Me.btnExportXML.TabIndex = 52 - Me.btnExportXML.Text = "Export as XML" + Me.btnExportXML.Text = "Exp. Gearbox as XML" Me.btnExportXML.UseVisualStyleBackColor = True ' + 'btnExportAxlGearXML + ' + Me.btnExportAxlGearXML.Location = New System.Drawing.Point(584, 648) + Me.btnExportAxlGearXML.Name = "btnExportAxlGearXML" + Me.btnExportAxlGearXML.Size = New System.Drawing.Size(118, 23) + Me.btnExportAxlGearXML.TabIndex = 53 + Me.btnExportAxlGearXML.Text = "Exp. AxlGear as XML" + Me.btnExportAxlGearXML.UseVisualStyleBackColor = True + ' 'GearboxForm ' Me.AcceptButton = Me.ButOK @@ -1058,6 +1068,7 @@ Partial Class GearboxForm Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.CancelButton = Me.ButCancel Me.ClientSize = New System.Drawing.Size(877, 696) + Me.Controls.Add(Me.btnExportAxlGearXML) Me.Controls.Add(Me.btnExportXML) Me.Controls.Add(Me.lblGbxInfo) Me.Controls.Add(Me.gbTCAccMin) @@ -1210,4 +1221,5 @@ Partial Class GearboxForm Friend WithEvents gbTCAccMin As System.Windows.Forms.GroupBox Friend WithEvents lblGbxInfo As System.Windows.Forms.Label Friend WithEvents btnExportXML As System.Windows.Forms.Button + Friend WithEvents btnExportAxlGearXML As System.Windows.Forms.Button End Class diff --git a/VECTO/GUI/GearboxForm.vb b/VECTO/GUI/GearboxForm.vb index 8a37f6d239..cc5afc7246 100644 --- a/VECTO/GUI/GearboxForm.vb +++ b/VECTO/GUI/GearboxForm.vb @@ -104,7 +104,7 @@ Public Class GearboxForm TbMinTimeBetweenShifts.Text = DeclarationData.Gearbox.MinTimeBetweenGearshifts.ToGUIFormat() 'cDeclaration.MinTimeBetweenGearshift(GStype) - TbTqResv.Text = (DeclarationData.Gearbox.TorqueReserve * 100).ToGUIFormat() ' cDeclaration.TqResv + TbTqResv.Text = (DeclarationData.Gearbox.TorqueReserve * 100).ToGUIFormat() ' cDeclaration.TqResv TbTqResvStart.Text = (DeclarationData.Gearbox.TorqueReserveStart * 100).ToGUIFormat() 'cDeclaration.TqResvStart TbStartSpeed.Text = DeclarationData.Gearbox.StartSpeed.ToGUIFormat() 'cDeclaration.StartSpeed TbStartAcc.Text = DeclarationData.Gearbox.StartAcceleration.ToGUIFormat() ' cDeclaration.StartAcc @@ -368,7 +368,6 @@ Public Class GearboxForm Dim gearbox As Gearbox = FillGearboxData(file) - If Not gearbox.SaveFile Then MsgBox("Cannot safe to " & file, MsgBoxStyle.Critical) Return False @@ -968,17 +967,34 @@ Public Class GearboxForm End Sub Private Sub btnExportXML_Click(sender As Object, e As EventArgs) Handles btnExportXML.Click - + Dim dialog As CommonOpenFileDialog = New CommonOpenFileDialog() + dialog.IsFolderPicker = True + If (dialog.ShowDialog() = CommonFileDialogResult.Cancel) Then + Exit Sub + End If + Dim data As Gearbox = FillGearboxData(_gbxFile) If (Cfg.DeclMode) Then - Dim dialog As CommonOpenFileDialog = New CommonOpenFileDialog() - dialog.IsFolderPicker = True - If (dialog.ShowDialog() = CommonFileDialogResult.Cancel) Then - Exit Sub - End If - Dim data As Gearbox = FillGearboxData(_gbxFile) - Dim export As XDocument = New XMLDeclarationWriter(data.Vendor).GenerateVectoComponent(data, data) export.Save(Path.Combine(dialog.FileName, data.ModelName + ".xml")) + Else + Dim export As XDocument = New XMLEngineeringWriter(_gbxFile, True, data.Vendor).GenerateVectoComponent(data, data) + export.Save(Path.Combine(dialog.FileName, data.ModelName + ".xml")) + End If + End Sub + + Private Sub btnExportAxlGearXML_Click(sender As Object, e As EventArgs) Handles btnExportAxlGearXML.Click + Dim dialog As CommonOpenFileDialog = New CommonOpenFileDialog() + dialog.IsFolderPicker = True + If (dialog.ShowDialog() = CommonFileDialogResult.Cancel) Then + Exit Sub + End If + Dim data As Gearbox = FillGearboxData(_gbxFile) + If (Cfg.DeclMode) Then + Dim export As XDocument = New XMLDeclarationWriter(data.Vendor).GenerateVectoComponent(data) + export.Save(Path.Combine(dialog.FileName, data.ModelName + ".xml")) + Else + Dim export As XDocument = New XMLEngineeringWriter(_gbxFile, True, data.Vendor).GenerateVectoComponent(data) + export.Save(Path.Combine(dialog.FileName, data.ModelName + ".xml")) End If End Sub End Class diff --git a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationWriter.cs b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationWriter.cs index 86ff41cbfd..ce8f7f32bd 100644 --- a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationWriter.cs +++ b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationWriter.cs @@ -10,6 +10,7 @@ namespace TUGraz.IVT.VectoXML.Writer { public class XMLDeclarationWriter : AbstractXMLWriter { + private XNamespace componentNamespace; //private readonly XNamespace _vectoNs = @"../../../API/VectoInput.xsd"; @@ -17,6 +18,7 @@ namespace TUGraz.IVT.VectoXML.Writer { tns = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6"; rootNamespace = "urn:tugraz:ivt:VectoAPI:DeclarationInput:v0.6"; + componentNamespace = "urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.6"; } public XDocument GenerateVectoJob(IDeclarationInputDataProvider data) @@ -56,13 +58,13 @@ namespace TUGraz.IVT.VectoXML.Writer { var xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"); var component = new XDocument(); - component.Add(new XElement(rootNamespace + XMLNames.VectoInputDeclaration, + component.Add(new XElement(componentNamespace + XMLNames.VectoInputDeclaration, new XAttribute("schemaVersion", SchemaVersion), new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName), new XAttribute("xmlns", tns), - new XAttribute(XNamespace.Xmlns + "tns", rootNamespace), + new XAttribute(XNamespace.Xmlns + "tns", componentNamespace), new XAttribute(xsi + "schemaLocation", - string.Format("{0} {1}VectoInput.xsd", rootNamespace, SchemaLocationBaseUrl)), + string.Format("{0} {1}VectoComponent.xsd", componentNamespace, SchemaLocationBaseUrl)), content) ); return component; diff --git a/VectoCore/VectoCore/OutputData/XML/XMLEngineeringWriter.cs b/VectoCore/VectoCore/OutputData/XML/XMLEngineeringWriter.cs index a822798b2e..5b1b4a3c23 100644 --- a/VectoCore/VectoCore/OutputData/XML/XMLEngineeringWriter.cs +++ b/VectoCore/VectoCore/OutputData/XML/XMLEngineeringWriter.cs @@ -55,6 +55,35 @@ namespace TUGraz.IVT.VectoXML.Writer return job; } + public XDocument GenerateVectoComponent(IGearboxEngineeringInputData gearbox, + ITorqueConverterEngineeringInputData torqueConverter) + { + return GenerateComponentDocument(CreateGearbox(gearbox, torqueConverter)); + } + + public XDocument GenerateVectoComponent(IAxleGearInputData data) + { + return GenerateComponentDocument(CreateAxlegear(data)); + } + + protected XDocument GenerateComponentDocument(XElement content) + { + var xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"); + + var component = new XDocument(); + component.Add(new XElement(rootNamespace + XMLNames.VectoComponentEngineering, + new XAttribute("schemaVersion", SchemaVersion), + new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName), + new XAttribute("xmlns", tns), + new XAttribute(XNamespace.Xmlns + "tns", rootNamespace), + new XAttribute(XNamespace.Xmlns + "vdecdef", _declarationNamespace), + new XAttribute(xsi + "schemaLocation", + string.Format("{0} {1}VectoEngineeringInput.xsd", rootNamespace, SchemaLocationBaseUrl)), + content) + ); + return component; + } + protected XElement[] CreateEngineOnly(IEngineeringInputDataProvider data) { return new[] { @@ -180,7 +209,7 @@ namespace TUGraz.IVT.VectoXML.Writer GetCrossWindCorrectionData(vehicle), new XElement(tns + XMLNames.Vehicle_Components, CreateEngine(data.EngineInputData), - CreateGearbox(gearbox), + CreateGearbox(gearbox, gearbox.TorqueConverter), angledrive.Type == AngledriveType.SeparateAngledrive ? CreateAngleDrive(angledrive) : null, retarder.Type.IsDedicatedComponent() ? CreateRetarder(retarder) : null, CreateAxlegear(data.AxleGearInputData), @@ -357,7 +386,7 @@ namespace TUGraz.IVT.VectoXML.Writer // string.Format("RET_{0}.xml", RemoveInvalidFileCharacters(data.ModelName))); } - protected XElement CreateGearbox(IGearboxEngineeringInputData data) + protected XElement CreateGearbox(IGearboxEngineeringInputData data, ITorqueConverterEngineeringInputData tcData) { var gears = new XElement(tns + XMLNames.Gearbox_Gears); var i = 1; @@ -386,7 +415,7 @@ namespace TUGraz.IVT.VectoXML.Writer new XElement(tns + XMLNames.Gearbox_TransmissionType, GearboxtypeToXML(data.Type)), new XElement(tns + XMLNames.Gearbox_Inertia, data.Inertia.Value()), new XElement(tns + XMLNames.Gearbox_TractionInterruption, data.TractionInterruption.Value()), gears), - data.Type.AutomaticTransmission() ? CreateTorqueConverter(data) : null); + data.Type.AutomaticTransmission() ? CreateTorqueConverter(tcData) : null); if (_singleFile) { return gbx; @@ -394,9 +423,8 @@ namespace TUGraz.IVT.VectoXML.Writer return ExtComponent(XMLNames.Component_Gearbox, gbx, string.Format("GBX-{0}.xml", data.ModelName)); } - private XElement CreateTorqueConverter(IGearboxEngineeringInputData data) + private XElement CreateTorqueConverter(ITorqueConverterEngineeringInputData torqueConverterData) { - var torqueConverterData = data.TorqueConverter; var tc = new XElement(tns + XMLNames.Component_TorqueConverter, new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.TorqueConverter_ReferenceRPM, torqueConverterData.ReferenceRPM.AsRPM), @@ -446,21 +474,9 @@ namespace TUGraz.IVT.VectoXML.Writer return ExtComponent(XMLNames.Component_Engine, engine, string.Format("ENG-{0}.xml", data.ModelName)); } - private XElement ExtComponent(string component, XElement engine, string filename) + private XElement ExtComponent(string component, XElement componentXML, string filename) { - var xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"); - var xsd = XNamespace.Get("http://www.w3.org/2001/XMLSchema"); - - - var xml = new XDocument(); - xml.Add(new XElement(rootNamespace + XMLNames.VectoComponentEngineering, - new XAttribute("schemaVersion", SchemaVersion), new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName), - new XAttribute("xmlns", tns), new XAttribute(XNamespace.Xmlns + "tns", rootNamespace), - new XAttribute(XNamespace.Xmlns + "vdecdef", _declarationNamespace), - new XAttribute(xsi + "schemaLocation", - string.Format("{0} {1}VectoEngineeringInput.xsd", rootNamespace, SchemaLocationBaseUrl)), engine)); - - xml.Save(Path.Combine(BasePath, filename)); + GenerateComponentDocument(componentXML).Save(Path.Combine(BasePath, filename)); var retVal = new XElement(tns + XMLNames.ExternalResource, new XAttribute(XMLNames.ExtResource_Type_Attr, XMLNames.ExtResource_Type_Value_XML), diff --git a/VectoCore/VectoCoreTest/XML/XMLWritingTest.cs b/VectoCore/VectoCoreTest/XML/XMLWritingTest.cs index 684b35bdec..9835b6d870 100644 --- a/VectoCore/VectoCoreTest/XML/XMLWritingTest.cs +++ b/VectoCore/VectoCoreTest/XML/XMLWritingTest.cs @@ -122,7 +122,7 @@ namespace TUGraz.VectoCore.Tests.XML var inputData = JSONInputDataFactory.ReadJsonJob(DeclarationJob); - var job = new XMLDeclarationWriter(".", "TUG_IVT").GenerateVectoJob((IDeclarationInputDataProvider)inputData); + var job = new XMLDeclarationWriter("TUG_IVT").GenerateVectoJob((IDeclarationInputDataProvider)inputData); job.Save(outputFile); @@ -144,7 +144,7 @@ namespace TUGraz.VectoCore.Tests.XML var inputData = JSONInputDataFactory.ReadJsonJob(DeclarationJobFull); - var job = new XMLDeclarationWriter(".", "TUG_IVT").GenerateVectoJob((IDeclarationInputDataProvider)inputData); + var job = new XMLDeclarationWriter( "TUG_IVT").GenerateVectoJob((IDeclarationInputDataProvider)inputData); job.Save(outputFile); -- GitLab