/***********************************************************************
**
**   airspace.h
**
**   This file is part of KFLog.
**
************************************************************************
**
**   Copyright (c):  2000 by Heiner Lamprecht, Florian Ehinger
**
**   This file is distributed under the terms of the General Public
**   Licence. See the file COPYING for more information.
**
**   $Id: airspace.h,v 1.6 2004/03/13 20:15:27 andre Exp $
**
***********************************************************************/

#ifndef AIRSPACE_H
#define AIRSPACE_H

#include "lineelement.h"
#include "altitude.h"

/**
  * @short Collection of distances to airspaces
  *
  * This class holds a set of six distances to airspaces, used to warn the user if he's getting
  * (too) close to an airspace.
  *
  * @author Andre Somers
  */
struct AirspaceWarningDistance {
  Distance horClose;
  Distance horVeryClose;
  Distance verAboveClose;
  Distance verAboveVeryClose;
  Distance verBelowClose;
  Distance verBelowVeryClose;
};


/**
 * @short Class to handle airspaces.
 *
 * This class is used for the several airspaces. The object can be
 * one of: AirC, AirCtemp, AirD, AirDtemp, ControlD, AirElow, AirEhigh,
 * AirF, Restricted, Danger, LowFlight
 * @author Heiner Lamprecht, Florian Ehinger
 * @version $Id: airspace.h,v 1.6 2004/03/13 20:15:27 andre Exp $
 * @see BaseMapElement#objectType
 */
class Airspace : public LineElement
{
  public:
    enum ConflictType {none=0, near=1, veryNear=2, inside=3};
      
    /**
     * Creates a new Airspace-object. n is the name, t the typeID. length
     * is the number of coordinates. upper and upperType give the upper limit
     * of the airspace and the type of value (MSL, GND, FL); lower and
     * lowerType give the value for the lower limit.
     */
    Airspace(QString n, BaseMapElement::objectType t, QPointArray pA,
           int upper, BaseMapElement::elevationType upperType,
           int lower, BaseMapElement::elevationType lowerType);
    /**
     * Destructor, does nothing special.
     */
    ~Airspace();
    /**
     * Draws the airspace into the given painter.
     * Return a pointer to the drawn region.
     * @param  targetP  The painter to draw the element into.
     * @param  maskP  The maskpainter for targetP
     */
    QRegion* drawRegion(QPainter* targetP, QPainter* maskP);
    /**
     * Returns the upper limit of the airspace.
     */
    unsigned int getUpperL() const { return (int)uLimit.getMeters(); };
    /**
     * Returns the lower limit of the airspace.
     */
    unsigned int getLowerL() const { return (int)lLimit.getMeters(); };

    /**
     * Returns the type of the upper limit (MSN, GND, FL)
     * @see BaseMapElement#elevationType
     * @see #uLimitType
     */
    BaseMapElement::elevationType getUpperT() const { return uLimitType; };

    /**
     * Returns the type of the lower limit (MSN, GND, FL)
     * @see BaseMapElement#elevationType
     * @see #lLimitType
     */
    BaseMapElement::elevationType getLowerT() const { return lLimitType; };

    /**
     * Returns a html-text-string about the airspace containing the name,
     * the type and the borders.
     * @return the infostring
     */
    QString getInfoString() const;

    /**
     * Returns a text representing the type of the airspace
     */
    static QString getTypeName (objectType);

    /**
     * Returns true if the given altitude conflicts with the airspace properties
     */
    ConflictType conflicts (const AltitudeCollection& alt, const AirspaceWarningDistance& dist) const;

  private:
    /**
     * Contains the lower limit.
     * @see #getLowerL
     */
    Altitude lLimit;
    /**
     * Contains the type of the lower limit
     * @see #lLimit
     * @see #getLowerT
     */
    BaseMapElement::elevationType lLimitType;
    /**
     * Contains the upper limit.
     * @see #getUpperL
     */
    Altitude uLimit;
    /**
     * Contains the type of the upper limit
     * @see #uLimit
     * @see #getUpperT
     */
    BaseMapElement::elevationType uLimitType;

    BaseMapElement::objectType type;
};

#endif
