/***************************************************************************
                          speed.h  -  description
                             -------------------
    begin                : Sat Jul 20 2002
    copyright            : (C) 2002 by Andre Somers
    email                : andre@kflog.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SPEED_H
#define SPEED_H

#include <qstring.h>

/**
  * @short Abstract speed
  *
  * This class can contain a speed. It provides set and get functions for all popular units.
  *
  * @author Andre Somers
  */
  const double toKph=3.6;
  const double toMph=2.2369;
  const double toKnot=1.9438;
  const double toFpm=196.8504;

class Speed
{

public:
  enum speedUnit{metersPerSecond=0, kilometersPerHour=1, knots=2, milesPerHour=3, feetPerMinute};
  /**
   * Constructor
   */
  Speed();
  /**
   * Constructor
   *
   * Sets the speed to Mps meters per second.
   */
  Speed(double Mps);
  /**
   * Destructor
   */
  virtual ~Speed();
  /**
   * Get speed in Knots.
   */
  double getKnots() const;
  /**
   * Get speed in Kilometers per hour
   */
  double getKph() const;
  /**
   * Get speed in Meters per Second
   */
  double getMps() const;
  /**
   * Get speed in Nautical Miles per hour
   */
  double getMph() const;
  /**
   * Get speed in Nautical Miles per hour
   */
  double getFpm() const;
  /**
   * Set speed in Nautical miles per hour
   */
  void setMph(double speed);
  /**
   * Set speed in knots
   */
  void setKnot(double speed);
  /**
   * Set speed in Kilometers per hour
   */
  void setKph(double speed);
  /**
   * Set speed in meters per second.
   */
  void setMps(double speed);
  /**
   * Set speed in feet per minute.
   */
  void setFpm(double speed);
  /**
   * Set speed in selected horizontal unit.
   */
  void setValueHorizontal(double speed);
  /**
   * Set speed in selected vertical unit.
   */
  void setValueVertical(double speed);
  /**
   * set the horizontal unit
   */
  static void setHorizontalUnit(speedUnit unit);
  /**
   * set the vertical unit
   */
  static void setVerticalUnit(speedUnit unit);
  /**
   * get the horizontal unit
   */
  static speedUnit getHorizontalUnit();
  /**
   * get the vertical unit
   */
  static speedUnit getVerticalUnit();
  /**
   * Returns a formatted string for the default vertical speed units.
   */
  QString getTextVertical(bool withUnit=true, uint prec=1)const;
  /**
   * Returns a formatted string for the default horizontal unit-setting.
   */
  QString getTextHorizontal(bool withUnit=true, uint prec=1)const;

  /**
   * Sets the distance to be invalid
   */
  inline void setInvalid() {_isValid=false; _speed=0;};
  /**
   * Gets if the distance is valid
   */
  inline bool isValid() {return _isValid;};

/*Operators */
  /**
   * + operator for speed.
   */
  Speed operator + (const Speed& x) const;
  /**
   * - operator for speed.
   */
  Speed operator - (const Speed& x) const;
  /**
   * / operator for speed.
   */
  double operator / (const Speed& x) const;
  /**
   * * operator for speed.
   */
  double operator * (const Speed& x) const;
  /**
   * != operator for Speed
   */
  bool operator != (const Speed& x) const;
  /**
   * == operator for Speed
   */
  bool operator == (const Speed& x) const;
  /**
   * minus prefix operator for speed
   */
  Speed operator - () const;

protected:
  /**
   * This attribute contains the stored speed in meters per second.
   */
  double _speed;
  /**
   * value valid?
   */
  bool _isValid;


  /**
   * Contains the unit used for horizontal speeds
   */
  static speedUnit _horizontalUnit;
  /**
   * Contains the unit used for vertical speeds
   */
  static speedUnit _verticalUnit;

  /**
   * called if the value has been changed. Can be overridden in derived classes
   */
  virtual void changed();
};

/**
 * - operator for speed.
 */
Speed operator - (double left, const Speed& right);
/**
 * + operator for speed.
 */
Speed operator + (double left, const Speed& right);
/**
 * * operator for speed.
 */
Speed operator * (double left, const Speed& right);

#endif
