From: James Turner Date: Tue, 24 Nov 2015 21:46:05 +0000 (+0000) Subject: Add helipad support to the diagram. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cfcdd9da450cd7dccb4a58418f674da8e1c5eb44;p=flightgear.git Add helipad support to the diagram. - stops crashes selecting a heliport. --- diff --git a/src/GUI/AirportDiagram.cxx b/src/GUI/AirportDiagram.cxx index d268bc2f9..dbe4fc353 100644 --- a/src/GUI/AirportDiagram.cxx +++ b/src/GUI/AirportDiagram.cxx @@ -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) { diff --git a/src/GUI/AirportDiagram.hxx b/src/GUI/AirportDiagram.hxx index c5c87004d..207a14dee 100644 --- a/src/GUI/AirportDiagram.hxx +++ b/src/GUI/AirportDiagram.hxx @@ -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 m_parking; + struct HelipadData + { + QPointF pt; + FGHelipadRef parking; + }; + + QVector m_helipads; + QPainterPath m_parkingIconPath, // arrow points right m_parkingIconLeftPath; // arrow points left double m_approachDistanceNm; diff --git a/src/GUI/LocationWidget.cxx b/src/GUI/LocationWidget.cxx index cdcd5a93a..f4e2e96e2 100644 --- a/src/GUI/LocationWidget.cxx +++ b/src/GUI/LocationWidget.cxx @@ -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; rnumRunways(); ++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; rnumHelipads(); ++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; rnumRunways(); ++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()) {