]> git.mxchange.org Git - flightgear.git/commitdiff
Add helipad support to the diagram.
authorJames Turner <zakalawe@mac.com>
Tue, 24 Nov 2015 21:46:05 +0000 (21:46 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 24 Nov 2015 21:46:14 +0000 (21:46 +0000)
- stops crashes selecting a heliport.

src/GUI/AirportDiagram.cxx
src/GUI/AirportDiagram.hxx
src/GUI/LocationWidget.cxx

index d268bc2f9d9f3a37d6a8dac39ab0677f94aaa1e4..dbe4fc3531cd2e35324b57455cf1661c5be64089 100644 (file)
@@ -111,6 +111,7 @@ void AirportDiagram::setAirport(FGAirportRef apt)
     m_runways.clear();
     m_approachDistanceNm = -1.0;
     m_parking.clear();
+    m_helipads.clear();
 
     if (apt) {
         buildTaxiways();
@@ -139,6 +140,11 @@ void AirportDiagram::setSelectedRunway(FGRunwayRef r)
     update();
 }
 
+void AirportDiagram::setSelectedHelipad(FGHelipadRef pad)
+{
+
+}
+
 void AirportDiagram::setApproachExtensionDistance(double distanceNm)
 {
     m_approachDistanceNm = distanceNm;
@@ -181,6 +187,10 @@ void AirportDiagram::doComputeBounds()
         extendBounds(p.pt);
     }
 
+    Q_FOREACH(const HelipadData& p, m_helipads) {
+        extendBounds(p.pt);
+    }
+
     if (m_selectedRunway && (m_approachDistanceNm > 0.0)) {
         double d = SG_NM_TO_METER * m_approachDistanceNm;
         QPointF pt = project(m_selectedRunway->pointOnCenterline(-d));
@@ -196,6 +206,14 @@ void AirportDiagram::addParking(FGParkingRef park)
     update();
 }
 
+void AirportDiagram::addHelipad(FGHelipadRef pad)
+{
+    HelipadData pd = { project(pad->geod()), pad };
+    m_helipads.push_back(pd);
+    recomputeBounds(false);
+    update();
+}
+
 
 void AirportDiagram::paintContents(QPainter* p)
 {
@@ -215,7 +233,7 @@ void AirportDiagram::paintContents(QPainter* p)
         p->drawLine(t.p1, t.p2);
     }
 
-
+    drawHelipads(p);
     drawParkings(p);
 
 // runways
@@ -303,6 +321,20 @@ void AirportDiagram::paintContents(QPainter* p)
     }
 }
 
+void AirportDiagram::drawHelipads(QPainter* painter)
+{
+    QTransform t = painter->transform();
+    QPixmap icon(":/heliport-icon");
+
+    QRect r = icon.rect();
+    r.moveCenter(QPoint(0, 0));
+
+    Q_FOREACH(const HelipadData& p, m_helipads) {
+        painter->setTransform(t);
+        painter->translate(p.pt);
+        painter->drawPixmap(r, icon);
+    }
+}
 
 void AirportDiagram::drawParkings(QPainter* painter)
 {
index c5c87004dd62e26596d103a74c01a2803faa416f..207a14deebaf2b9f2858d35d8641afb834ce332d 100644 (file)
@@ -38,10 +38,13 @@ public:
 
     void addRunway(FGRunwayRef rwy);
     void addParking(FGParkingRef park);
-    
+    void addHelipad(FGHelipadRef pad);
+
     FGRunwayRef selectedRunway() const;
     void setSelectedRunway(FGRunwayRef r);
 
+    void setSelectedHelipad(FGHelipadRef pad);
+
     void setApproachExtensionDistance(double distanceNm);
 Q_SIGNALS:
     void clickedRunway(FGRunwayRef rwy);
@@ -61,6 +64,7 @@ private:
 
     void drawILS(QPainter *painter, FGRunwayRef runway) const;
     void drawParkings(QPainter *p);
+    void drawHelipads(QPainter *painter);
 
     FGAirportRef m_airport;
 
@@ -93,6 +97,14 @@ private:
 
     QVector<ParkingData> m_parking;
 
+    struct HelipadData
+    {
+        QPointF pt;
+        FGHelipadRef parking;
+    };
+
+    QVector<HelipadData> m_helipads;
+
     QPainterPath m_parkingIconPath, // arrow points right
         m_parkingIconLeftPath; // arrow points left
     double m_approachDistanceNm;
index cdcd5a93a7b66bc71a9a29a2987c4648163e3047..f4e2e96e2c7c5413109804df2d762c19e7503141 100644 (file)
@@ -527,24 +527,35 @@ void LocationWidget::setLocationOptions()
         opt->addOption("airport", apt->ident());
 
         if (m_ui->runwayRadio->isChecked()) {
-            int index = m_ui->runwayCombo->itemData(m_ui->runwayCombo->currentIndex()).toInt();
-            if (index >= 0) {
-                // explicit runway choice
-                FGRunwayRef runway = apt->getRunwayByIndex(index);
-                opt->addOption("runway", runway->ident());
-
-                // set nav-radio 1 based on selected runway
-                if (runway->ILS()) {
-                    double mhz = runway->ILS()->get_freq() / 100.0;
-                    QString navOpt = QString("%1:%2").arg(runway->headingDeg()).arg(mhz);
-                    opt->addOption("nav1", navOpt.toStdString());
+            if (apt->type() == FGPositioned::AIRPORT) {
+                int index = m_ui->runwayCombo->itemData(m_ui->runwayCombo->currentIndex()).toInt();
+                if (index >= 0) {
+                    // explicit runway choice
+                    FGRunwayRef runway = apt->getRunwayByIndex(index);
+                    opt->addOption("runway", runway->ident());
+
+                    // set nav-radio 1 based on selected runway
+                    if (runway->ILS()) {
+                        double mhz = runway->ILS()->get_freq() / 100.0;
+                        QString navOpt = QString("%1:%2").arg(runway->headingDeg()).arg(mhz);
+                        opt->addOption("nav1", navOpt.toStdString());
+                    }
                 }
-            }
 
-            if (m_ui->onFinalCheckbox->isChecked()) {
-                opt->addOption("glideslope", "3.0");
-                double offsetNm = m_ui->approachDistanceSpin->value();
-                opt->addOption("offset-distance", QString::number(offsetNm).toStdString());
+                if (m_ui->onFinalCheckbox->isChecked()) {
+                    opt->addOption("glideslope", "3.0");
+                    double offsetNm = m_ui->approachDistanceSpin->value();
+                    opt->addOption("offset-distance", QString::number(offsetNm).toStdString());
+                }
+            } else if (apt->type() == FGPositioned::HELIPORT) {
+                int index = m_ui->runwayCombo->itemData(m_ui->runwayCombo->currentIndex()).toInt();
+                if (index >= 0)  {
+                    // explicit pad choice
+                    FGHelipadRef pad = apt->getHelipadByIndex(index);
+                    opt->addOption("runway", pad->ident());
+                }
+            } else {
+                qWarning() << Q_FUNC_INFO << "implement me";
             }
 
         } else if (m_ui->parkingRadio->isChecked()) {
@@ -667,12 +678,23 @@ void LocationWidget::onLocationChanged()
 
         m_ui->runwayCombo->clear();
         m_ui->runwayCombo->addItem("Automatic", -1);
-        for (unsigned int r=0; r<apt->numRunways(); ++r) {
-            FGRunwayRef rwy = apt->getRunwayByIndex(r);
-            // add runway with index as data role
-            m_ui->runwayCombo->addItem(QString::fromStdString(rwy->ident()), r);
 
-            m_ui->airportDiagram->addRunway(rwy);
+        if (apt->type() == FGPositioned::HELIPORT) {
+            for (unsigned int r=0; r<apt->numHelipads(); ++r) {
+                FGHelipadRef pad = apt->getHelipadByIndex(r);
+                // add pad with index as data role
+                m_ui->runwayCombo->addItem(QString::fromStdString(pad->ident()), r);
+
+                m_ui->airportDiagram->addHelipad(pad);
+            }
+        } else {
+            for (unsigned int r=0; r<apt->numRunways(); ++r) {
+                FGRunwayRef rwy = apt->getRunwayByIndex(r);
+                // add runway with index as data role
+                m_ui->runwayCombo->addItem(QString::fromStdString(rwy->ident()), r);
+
+                m_ui->airportDiagram->addRunway(rwy);
+            }
         }
 
         m_ui->parkingCombo->clear();
@@ -817,10 +839,17 @@ void LocationWidget::updateDescription()
         if (m_ui->runwayRadio->isChecked()) {
             int comboIndex = m_ui->runwayCombo->currentIndex();
             int runwayIndex = m_ui->runwayCombo->itemData(comboIndex).toInt();
-            // we can't figure out the active runway in the launcher (yet)
-            FGRunwayRef rwy = (runwayIndex >= 0) ?
-                apt->getRunwayByIndex(runwayIndex) : FGRunwayRef();
-            m_ui->airportDiagram->setSelectedRunway(rwy);
+            if (apt->type() == FGPositioned::HELIPORT) {
+                m_ui->airportDiagram->setSelectedRunway(FGRunwayRef());
+                FGHelipadRef pad = (runwayIndex >= 0) ?
+                            apt->getHelipadByIndex(runwayIndex) : FGHelipadRef();
+                m_ui->airportDiagram->setSelectedHelipad(pad);
+            } else {
+                // we can't figure out the active runway in the launcher (yet)
+                FGRunwayRef rwy = (runwayIndex >= 0) ?
+                    apt->getRunwayByIndex(runwayIndex) : FGRunwayRef();
+                m_ui->airportDiagram->setSelectedRunway(rwy);
+            }
         }
 
         if (m_ui->onFinalCheckbox->isChecked()) {