//----------------------------------------------------------------------- // // Copyright © 2012 Nils Hammar. All rights reserved. // //----------------------------------------------------------------------- /* * Software to access vehicle information via the OBD-II connector. * * Copyright © 2012 Nils Hammar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Alternative licensing is possible, see the licensing document. * * The above text may not be removed or modified. */ namespace UserInterface.GUI { using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using global::SharedObjects.Misc; /// /// ECU:s component. /// public partial class Ecus : UserControl { /// /// Current vehicle. /// private XmlClass.vehicle vehicle; /// /// Gets All ECU:s for vehicle. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Reviewed, intentional.")] public XmlClass.vehicle.ecuData[] allEcus { get; private set; } /// /// Gets Selected ECU:s for vehicle. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Reviewed, intentional.")] public XmlClass.vehicle.ecuData[] selectedEcus { get; private set; } /// /// Initializes a new instance of the class. /// public Ecus() { this.InitializeComponent(); } /// /// Initialize the component. /// /// Current Vehicle. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "vehicle", Justification = "Reviewed, intentional.")] public void init(XmlClass.vehicle vehicle) { this.vehicle = vehicle; this.allEcus = new XmlClass.vehicle.ecuData[0]; this.selectedEcus = new XmlClass.vehicle.ecuData[0]; this.configValues(vehicle); this.setToolTips(); this.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); } /// /// Configurate the ECU values. /// /// Current Vehicle. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "vehicle", Justification = "Reviewed, intentional.")] public void configValues(XmlClass.vehicle vehicle) { this.vehicle = vehicle; this.ecuCLB.Items.Clear(); this.allEcus = this.vehicle.ecus.ToArray(); if (this.vehicle.ecus != null) { for (int i = 0; i < this.vehicle.ecus.Count(); i++) { this.ecuCLB.Items.Add(this.vehicle.ecus[i].name); } } } /// /// When the selected index has changed. /// /// Sending object. /// Event data. private void ecuCLB_SelectedIndexChanged(object sender, EventArgs e) { CheckedListBox clb = (CheckedListBox)sender; if (clb.CheckedItems.Count > 8) { clb.SetItemChecked(clb.SelectedIndex, false); MessageBox.Show( "Max 8 ECU:s can be checked simultaneously.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { List selectedEcuList = new List(); CheckedListBox.CheckedIndexCollection cic = clb.CheckedIndices; foreach (int ci in cic) { selectedEcuList.Add(this.allEcus[ci]); } this.selectedEcus = selectedEcuList.ToArray(); } } /// /// Set tool tips for items. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "CanApp.CustomToolTip", Justification = "Reviewed, intentional.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Reviewed, intentional.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Reviewed.")] private void setToolTips() { this.toolTip1.SetToolTip( this.ecuCLB, "List of known ECU:s for vehicle type.\r\n" + "This list may be empty and then the default list is sufficient.\r\n" + "Mostly useful when doing 29 bit addressing."); } } }