//----------------------------------------------------------------------- // // 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.Popup { using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using global::SharedObjects.GUI.Popup; using global::UserInterface.GUI; using global::UserInterface.GUI.OBD; /// /// Engine for displaying hint balloons. /// public class HintEngine : IHintActivator { /// /// Location of main window to relate the hint balloons to. /// private Point origin; /// /// List of activated hints. /// private Dictionary hintList2 = new Dictionary(); /// /// Current displayed control. /// private UserControl currentUserControl = null; /// /// Flag to enable the hint engine. /// private bool activated = false; /// /// Initializes a new instance of the class. /// /// Origin position to relate to when drawing the hints. /// Preferences panel instance. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1", Justification = "Reviewed")] public HintEngine(Point origin, PreferencesPanel preferencesPanel) { this.origin = origin; this.activated = !preferencesPanel.advancedMode; preferencesPanel.registerHintEngine(this); } /// /// Set activation state of the hint engine. /// /// 'true' if hints shall be activated. public void activate(bool setActivated) { this.activated = setActivated; } /// /// Update the origin for the hints. /// /// Origin position to relate to when drawing the hints. public void setOrigin(Point newOrigin) { this.origin = newOrigin; this.showHints(null); } /// /// Display the application hints. /// /// Control for which hints shall be displayed. [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Reviewed.")] public void showHints(UserControl userControl) { if (this.activated) { if (userControl != null) { this.currentUserControl = userControl; } foreach (SpeakBalloon hint in this.hintList2.Values) { if (hint != null) { hint.Hide(); } } if (this.currentUserControl == null || this.currentUserControl is FirstPagePanel) { this.displayHint2("tree1", null, "Begin with selecting your interface.\r\nClick on a balloon to make it go away.\r\nSelect 'Advanced Mode' under 'Preferences' to disable the hint balloons.", 10, -45, 55, 175, 98); this.displayHint2("devices1", null, "You can also click on a device below.", 300, -45, 25, 175, 98); return; } if (this.currentUserControl is InterfacePanel) { InterfacePanel interfacePanel = (InterfacePanel)this.currentUserControl; if (!interfacePanel.protocolsEnabled) { this.displayHint2("vehicle1", null, "Select the vehicle to use. This will give you a set of pre-configured settings. You can add your own vehicle under Configuration in the menu.", 10, -45, 50, 375, 155); if (interfacePanel.iPassThru.isSerial()) { this.displayHint2("serial1", null, "Select the COM port and speed for the serial device. See your manual for the serial device for which speed to select.", 300, -45, 50, 175, 202); } this.displayHint2("open1", null, "Open the device. 'Quick Open' will use default values for the vehicle while 'Open' allows you to have finer control.", 750, -35, 50, 175, 98); } else { this.displayHint2("protocollist1", null, "List of potentially available protocols for the device.\r\nYou can select the desired protocol manually in this list.", 300, -45, 50, 255, 285); if (!interfacePanel.iPassThru.isSerial()) { this.displayHint2("detect1", null, "This button tries the protocols one by one and stops at the first detected protocol.", 600, -45, 25, 255, 285); } this.displayHint2("connection1", null, "Click this button to continue to the next step where you establish a connection with the vehicle.", 850, -45, 50, 85, 375); } return; } if (this.currentUserControl is ConnectionPanel) { ConnectionPanel connectionPanel = (ConnectionPanel)this.currentUserControl; if (connectionPanel.isSerial) { if (!connectionPanel.isConnected) { this.displayHint2("connectionProgress1", null, "Connection progress will be displayed here.", 100, -45, 25, 225, 175); this.displayHint2("connectionProtocol1", null, "Detected vehicle Protocol will be displayed here.", 380, -45, 25, 45, 225); } } else { if (!connectionPanel.isConnected) { this.displayHint2("connectionConfig1", null, "Adjust connection parameters here, default parameters are usually sufficient.", 100, -45, 25, 225, 155); } } if (!connectionPanel.isConnected) { this.displayHint2("connectVehicle1", null, "Connect to vehicle.", 680, -45, 25, 175, 160); } else { this.displayHint2("obdDisplay1", null, "Display OBD-2 data.", 680, -45, 25, 175, 255); } return; } if (this.currentUserControl is CurrentDataPanel) { this.displayHint2( "paramsTable1", null, "Select the parameters you are interested in.\r\n\r\n" + "Right-click on a green or yellow cell will bring up a menu where you can select/unselect" + " all rows from the selected row and below with the same plot behavior." + "\r\nThis will allow for a quick selection of multiple parameters.", 10, -45, 100, 305, 255); this.displayHint2( "toolTip1", null, "You will get more info when you put the mouse pointer over a button.", 250, -45, 25, 145, 105); return; } } } /// /// Display one hint. /// /// Name of hint. (not displayed to user) /// RTF formatted text to display to the user. /// Text to display to the user. (used if rtfText is 'null') /// Relative X-offset for hint. /// Relative Y-offset for hint. /// Height of text area. /// Relative X location for speak point. /// Relative Y location for speak point. private void displayHint2(string name, string rtfText, string text, int xOffset, int yOffset, int height, int speakPointX, int speakPointY) { SpeakBalloon hint = null; if (this.hintList2.ContainsKey(name)) { hint = this.hintList2[name]; } if (hint == null || hint.IsDisposed) { if (this.hintList2.ContainsKey(name)) { this.hintList2.Remove(name); } hint = new SpeakBalloon(height, rtfText, text, speakPointX, speakPointY); this.hintList2.Add(name, hint); } if (!hint.Visible) { hint.Visible = true; } hint.locate(this.origin, xOffset, yOffset); hint.BringToFront(); } } }