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

Skip to content
Snippets Groups Projects
GearboxForm.vb 51 KiB
Newer Older
                s.Points.DataBindXY(
                    shiftLines.Downshift.Select(Function(pt) pt.AngularSpeed.AsRPM) _
                                       .ToArray(),
                    shiftLines.Downshift.Select(Function(pt) pt.Torque.Value()).ToArray())
                end If
                s.ChartType = SeriesChartType.FastLine
                s.BorderWidth = 2
                s.Color = Color.DarkRed
                s.BorderDashStyle = ChartDashStyle.Dash
                s.Name = "Downshift curve (generic)"
                chart.Series.Add(s)
            End If
            'End If
        End If
    End Sub

    Private Function GetShiftLines(emFld As ElectricMotorFullLoadCurve, vehicle As IVehicleEngineeringInputData, gears As IList(Of ITransmissionInputData), gear As Integer) As ShiftPolygon
        
        Dim maxTqStr As String = LvGears.Items(gear).SubItems(GearboxTbl.MaxTorque).Text
        
        If gears.Count <= 1 Then
            Return Nothing
        End If
        Dim rDyn As Meter = vehicle.DynamicTyreRadius
        If rDyn.IsEqual(0) Then
            If (vehicle.Components.AxleWheels.AxlesEngineering.Count < 2) Then
                Return Nothing
            End If
            rdyn = vehicle.Components.AxleWheels.AxlesEngineering.Where(Function(axle)  axle.AxleType = AxleType.VehicleDriven) _
                .Select(Function(da) DeclarationData.Wheels.Lookup(da.Tyre.Dimension).DynamicTyreRadius) _
                .Average()
        End If
        If (rDyn.IsEqual(0)) Then
            Return Nothing
        End If

        Dim tmpRunData as VectoRunData = New VectoRunData() With {
                .GearboxData = New GearboxData() with {
                .Type = CType(CbGStype.SelectedValue, GearboxType)
                },
                .GearshiftParameters = New  ShiftStrategyParameters(), 
                .JobType = VectoSimulationJobType.BatteryElectricVehicle
                }
        Dim tmpStrategy as IShiftPolygonCalculator = PowertrainBuilder.GetShiftStrategy(new SimplePowertrainContainer(tmpRunData))
        
        dim em as ElectricMotorData = ConvertToElectricMotorData(emFld, gear)

        Dim shiftLines As ShiftPolygon = tmpStrategy.ComputeDeclarationShiftPolygon(
            CType(CbGStype.SelectedValue, GearboxType), gear - 1,
            Nothing, gears, nothing,
            Double.Parse(LvGears.Items(0).SubItems(GearboxTbl.Ratio).Text, CultureInfo.InvariantCulture),
            (rDyn), em)
        Return shiftLines
    End Function
    Private Function GetShiftLines(idleSpeed As PerSecond, engineFullLoadCurve As EngineFullLoadCurve, vehicle As IVehicleEngineeringInputData, gears As IList(Of ITransmissionInputData), gear As Integer) _
        As ShiftPolygon
        Dim maxTqStr As String = LvGears.Items(gear).SubItems(GearboxTbl.MaxTorque).Text
        Dim engine As CombustionEngineData = ConvertToEngineData(engineFullLoadCurve, idleSpeed, gear,
                                                                If(String.IsNullOrWhiteSpace(maxTqStr), Nothing, maxTqStr.ToDouble(0).SI(Of NewtonMeter)))
        If gears.Count <= 1 Then
            Return Nothing
        End If
        Dim rDyn As Meter = vehicle.DynamicTyreRadius
        If rDyn.IsEqual(0) Then
			If (vehicle.Components.AxleWheels.AxlesEngineering.Count < 2) Then
                Return Nothing
            End If
			rdyn = vehicle.Components.AxleWheels.AxlesEngineering.Where(Function(axle)  axle.AxleType = AxleType.VehicleDriven) _
				.Select(Function(da) DeclarationData.Wheels.Lookup(da.Tyre.Dimension).DynamicTyreRadius) _
				.Average()
        End If
        If (rDyn.IsEqual(0)) Then
            Return Nothing
        End If

        Dim tmpRunData as VectoRunData = New VectoRunData() With {
            .GearboxData = New GearboxData() with {
                .Type = CType(CbGStype.SelectedValue, GearboxType)
            },
            .JobType = _vehicleJobType
        Dim tmpStrategy as IShiftPolygonCalculator = PowertrainBuilder.GetShiftStrategy(new SimplePowertrainContainer(tmpRunData))
            

        Dim shiftLines As ShiftPolygon = tmpStrategy.ComputeDeclarationShiftPolygon(
            CType(CbGStype.SelectedValue, GearboxType), gear - 1,
            engine.FullLoadCurves(CType(gear, UInteger)), gears, engine,
            Double.Parse(LvGears.Items(0).SubItems(GearboxTbl.Ratio).Text, CultureInfo.InvariantCulture),
            (rDyn))
        Return shiftLines
    End Function

    Private Function ConvertToGears(gbx As ListView.ListViewItemCollection) As IList(Of ITransmissionInputData)
        Dim retVal As List(Of ITransmissionInputData) = New List(Of ITransmissionInputData)
        Dim value As Double

        For i As Integer = 1 To gbx.Count - 1
            If _
                gbx(i).SubItems(GearboxTbl.Ratio).Text <> "" AndAlso Double.TryParse(gbx(i).SubItems(GearboxTbl.Ratio).Text, value) _
                Then
                Dim maxSpeed As PerSecond =
                        If _
                        (String.IsNullOrWhiteSpace(gbx(i).SubItems(GearboxTbl.MaxSpeed).Text), Nothing,
                        gbx(i).SubItems(GearboxTbl.MaxSpeed).Text.ToDouble().RPMtoRad())
                retVal.Add(
                    New TransmissionInputData() _
                            With {.Ratio = value, .MaxInputSpeed = maxSpeed})

            End If
        Next
        Return retVal
    End Function
    'Browse TC file
    Private Sub BtTCfileBrowse_Click(sender As Object, e As EventArgs) Handles BtTCfileBrowse.Click
        If TorqueConverterFileBrowser.OpenDialog(FileRepl(TbTCfile.Text, GetPath(_gbxFile))) Then
            TbTCfile.Text = GetFilenameWithoutDirectory(TorqueConverterFileBrowser.Files(0), GetPath(_gbxFile))
        End If
    End Sub
    'Open TC file
    Private Sub BtTCfileOpen_Click(sender As Object, e As EventArgs) Handles BtTCfileOpen.Click
        OpenFiles(FileRepl(TbTCfile.Text, GetPath(_gbxFile)))
    End Sub
    Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
    End Sub

    Public Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
    End Sub

    Private Sub BtTCShiftFileBrowse_Click(sender As Object, e As EventArgs) Handles BtTCShiftFileBrowse.Click
        If TorqueConverterShiftPolygonFileBrowser.OpenDialog(FileRepl(TBTCShiftPolygon.Text, GetPath(_gbxFile))) Then
            TBTCShiftPolygon.Text = GetFilenameWithoutDirectory(TorqueConverterShiftPolygonFileBrowser.Files(0),
                                                                GetPath(_gbxFile))
        End If
    End Sub

    Private Sub btnExportXML_Click(sender As Object, e As EventArgs) Handles btnExportXML.Click
        If Not Cfg.DeclMode Then
            MsgBox("XML Export is only supported in Declaration Mode")
            Exit Sub
        End If
        If Not FolderFileBrowser.OpenDialog("") Then
            Exit Sub
        End If
        Dim filePath As String = FolderFileBrowser.Files(0)

        Dim data As Gearbox = FillGearboxData(_gbxFile)
        If (Cfg.DeclMode) Then
            Dim export As XDocument = New XMLDeclarationWriter(data.Manufacturer).GenerateVectoComponent(data, data)
            export.Save(Path.Combine(filePath, data.ModelName + ".xml"))
        Else
		    Dim kernel As IKernel = new StandardKernel(new VectoNinjectModule)
		    dim writer As IXMLEngineeringWriter = kernel.Get(of IXMLEngineeringWriter)()
		    writer.Configuration = new WriterConfiguration() With { .SingleFile = true, .BasePath = filePath }
			Dim export As XDocument = writer.WriteComponent(TryCast(data, IGearboxEngineeringInputData))
            export.Save(Path.Combine(filePath, data.ModelName + ".xml"))
        End If
    End Sub

    Private Sub btnExportAxlGearXML_Click(sender As Object, e As EventArgs) Handles btnExportAxlGearXML.Click
        If Not Cfg.DeclMode Then
            MsgBox("XML Export is only supported in Declaration Mode")
            Exit Sub
        End If
        If Not FolderFileBrowser.OpenDialog("") Then
            Exit Sub
        End If
        Dim filePath As String = FolderFileBrowser.Files(0)

        Dim data As Gearbox = FillGearboxData(_gbxFile)
        If (Cfg.DeclMode) Then
            Dim export As XDocument = New XMLDeclarationWriter(data.Manufacturer).GenerateVectoComponent(data)
            export.Save(Path.Combine(filePath, data.ModelName + ".xml"))
        Else
		    Dim kernel As IKernel = new StandardKernel(new VectoNinjectModule)
		    dim writer As IXMLEngineeringWriter = kernel.Get(of IXMLEngineeringWriter)()
		    writer.Configuration = new WriterConfiguration() With { .SingleFile = true, .BasePath = filePath }
			Dim export As XDocument = writer.WriteComponent(TryCast(data, IAxleGearInputData))
            export.Save(Path.Combine(filePath, data.ModelName + ".xml"))
        End If
    End Sub

    Private Sub btExportVGBS_Click(sender As Object, e As EventArgs) Handles btExportVGBS.Click
        If LvGears.Items.Count <= 1 Then Exit Sub

        Dim shiftPolygon As ShiftPolygon = Nothing
        Dim path As String
        Dim gear As Integer
        Try
            If LvGears.SelectedItems.Count > 0 AndAlso LvGears.SelectedIndices(0) > 0 Then
                path = FileRepl(LvGears.SelectedItems(0).SubItems(GearboxTbl.ShiftPolygons).Text, GetPath(_gbxFile))
                gear = LvGears.SelectedIndices(0)
            Else
                path = FileRepl(LvGears.Items(1).SubItems(GearboxTbl.ShiftPolygons).Text, GetPath(_gbxFile))
                gear = 1
            End If

            If File.Exists(path) Then shiftPolygon = ShiftPolygonReader.ReadFromFile(path)

            If Not shiftPolygon Is Nothing Then
                ShiftPolygonExport.WriteShiftPolygon(shiftPolygon, path & ".vgbs")
            End If
        Catch ex As Exception
        End Try

        Dim jobFile As String = VectoJobForm.VectoFile
        If Not jobFile Is Nothing AndAlso File.Exists(jobFile) Then
            Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadJsonJob(jobFile), 
                                                                    IEngineeringInputDataProvider)
            If (inputData Is Nothing) Then
                Exit Sub
            End If

            Dim vehicle As IVehicleEngineeringInputData = inputData.JobInputData.Vehicle
			Dim engine As IEngineEngineeringInputData = vehicle.Components.EngineInputData
			Dim engineFld As EngineFullLoadCurve = FullLoadCurveReader.Create(engine.EngineModes.First().FullLoadCurve)
			If VectoJobForm.Visible AndAlso engine.EngineModes.First().IdleSpeed > 0 Then
                Dim gears As IList(Of ITransmissionInputData) = ConvertToGears(LvGears.Items)
				Dim shiftLines As ShiftPolygon = GetShiftLines(engine.EngineModes.First().IdleSpeed, engineFld, vehicle, gears, gear)
                If (Not IsNothing(shiftLines)) Then
                    ShiftPolygonExport.WriteShiftPolygon(shiftLines, jobFile & "_Gear " & gear & ".vgbs")
                End If
            End If
        End If
    End Sub