From 1043e6f7f51702f753d2aeb33505c032b231d7e8 Mon Sep 17 00:00:00 2001 From: portree_kid Date: Sat, 25 Dec 2021 21:52:01 +0100 Subject: [PATCH] Remove FGATCDialogNew --- src/ATC/CMakeLists.txt | 2 - src/ATC/GroundController.cxx | 2 +- src/ATC/atc_mgr.cxx | 2 +- src/ATC/atc_mgr.hxx | 1 - src/ATC/atcdialog.cxx | 310 ----------------------------------- src/ATC/atcdialog.hxx | 92 ----------- src/ATC/trafficcontrol.cxx | 4 +- src/Main/fg_init.cxx | 2 +- 8 files changed, 5 insertions(+), 410 deletions(-) delete mode 100644 src/ATC/atcdialog.cxx delete mode 100644 src/ATC/atcdialog.hxx diff --git a/src/ATC/CMakeLists.txt b/src/ATC/CMakeLists.txt index 934338115..eb77c3d10 100644 --- a/src/ATC/CMakeLists.txt +++ b/src/ATC/CMakeLists.txt @@ -2,7 +2,6 @@ include(FlightGearComponent) set(SOURCES atc_mgr.cxx - atcdialog.cxx trafficcontrol.cxx CommStation.cxx ATISEncoder.cxx @@ -13,7 +12,6 @@ set(SOURCES set(HEADERS atc_mgr.hxx - atcdialog.hxx trafficcontrol.hxx CommStation.hxx ATISEncoder.hxx diff --git a/src/ATC/GroundController.cxx b/src/ATC/GroundController.cxx index 9c2a1f516..f08d861aa 100644 --- a/src/ATC/GroundController.cxx +++ b/src/ATC/GroundController.cxx @@ -196,7 +196,7 @@ bool FGGroundController::checkTransmissionState(int minState, int maxState, Traf // PopupCallback(n); SG_LOG(SG_ATC, SG_DEBUG, "Selected transmission message " << n); //FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc"); - FGATCDialogNew::instance()->removeEntry(1); + //FGATCDialogNew::instance()->removeEntry(1); } else { SG_LOG(SG_ATC, SG_DEBUG, "creating message for " << i->getAircraft()->getCallSign()); transmit(&(*i), dynamics, msgId, msgDir, false); diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index 927d1a254..509c847f3 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -355,7 +355,7 @@ void FGATCManager::update ( double time ) { controller = user_ai_ac->getATCController(); // Update the ATC dialog - FGATCDialogNew::instance()->update(time); + //FGATCDialogNew::instance()->update(time); // Controller manager - if controller is set, then will update controller if (controller) { diff --git a/src/ATC/atc_mgr.hxx b/src/ATC/atc_mgr.hxx index 5704903a5..9e7a20dd0 100644 --- a/src/ATC/atc_mgr.hxx +++ b/src/ATC/atc_mgr.hxx @@ -37,7 +37,6 @@ #include #include -#include #include #include #include diff --git a/src/ATC/atcdialog.cxx b/src/ATC/atcdialog.cxx deleted file mode 100644 index 54b1ef276..000000000 --- a/src/ATC/atcdialog.cxx +++ /dev/null @@ -1,310 +0,0 @@ -// atcdialog.cxx - classes to manage user interactions with AI traffic -// Written by Durk Talsma, started April 3, 2011 -// Based on earlier code written by Alexander Kappes and David Luff -// -// 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. -// -// 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, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "atcdialog.hxx" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include
-#include
-#include
-#include // mkDialog -#include -#include -#include - -using std::string; - -static SGPropertyNode *getNamedNode(SGPropertyNode *prop, const std::string& name) -{ - SGPropertyNode* p; - - for (int i = 0; i < prop->nChildren(); i++) - if ((p = getNamedNode(prop->getChild(i), name))) - return p; - - if (prop->getStringValue("name") == name) - return prop; - return 0; -} - -// help function to make a string all uppercase -static void atcUppercase(string &s) { - for(unsigned int i=0; icommStations().empty()); - } -}; - -void FGATCDialogNew::frequencySearch() -{ - const char *dialog_name = "atc-freq-search"; - SGPropertyNode_ptr dlg = _gui->getDialogProperties(dialog_name); - if (!dlg) - return; - - _gui->closeDialog(dialog_name); - - SGPropertyNode_ptr button_group = getNamedNode(dlg, "quick-buttons"); - // remove all dynamic airport/ATC buttons - button_group->removeChildren("button"); - - AirportsWithATC filt; - FGPositionedList results = FGPositioned::findWithinRange(globals->get_aircraft_position(), 50.0, &filt); - FGPositioned::sortByRange(results, globals->get_aircraft_position()); - for (unsigned int r=0; (rgetNode("button", r, true); - copyProperties(button_group->getNode("button-template", true), entry); - entry->removeChildren("enabled"); - entry->setStringValue("legend", results[r]->ident()); - entry->setStringValue("binding[0]/icao", results[r]->ident()); - } - - // (un)hide message saying no things in range - SGPropertyNode_ptr range_error = getNamedNode(dlg, "no-atc-in-range"); - range_error->setBoolValue("visible", !results.empty()); - - _gui->showDialog(dialog_name); -} - -void FGATCDialogNew::frequencyDisplay(const std::string& ident) -{ - const char *dialog_name = "atc-freq-display"; - SGPropertyNode_ptr dlg = _gui->getDialogProperties(dialog_name); - if (!dlg) - return; - - _gui->closeDialog(dialog_name); - - SGPropertyNode_ptr freq_group = getNamedNode(dlg, "frequency-list"); - // remove all frequency entries - freq_group->removeChildren("group"); - - std::string uident(ident); - atcUppercase(uident); - string label; - - const FGAirport *a = fgFindAirportID(uident); - if (!a) { - label = "Airport " + ident + " not found in database."; - mkDialog(label.c_str()); - return; - } - - // set title - label = uident + " Frequencies"; - dlg->setStringValue("text/label", label.c_str()); - - const flightgear::CommStationList& comms(a->commStations()); - if (comms.empty()) { - label = "No frequencies found for airport " + uident; - mkDialog(label.c_str()); - return; - } - - for (unsigned int c=0; c < comms.size(); ++c) { - flightgear::CommStation* comm = comms[c]; - - // add frequency line (modified copy of ) - SGPropertyNode *entry = freq_group->getNode("group", c, true); - copyProperties(freq_group->getNode("group-template", true), entry); - entry->removeChildren("enabled"); - - entry->setStringValue("text[0]/label", comm->ident()); - - char buf[9]; - ::snprintf(buf, 9, "%.3f", comm->freqMHz()); - buf[8] = '\0'; - - entry->setStringValue("text[1]/label", buf); - entry->setStringValue("button[0]/binding/value", buf); - entry->setStringValue("button[1]/binding/value", buf); - } - - _gui->showDialog(dialog_name); -} - -static bool doFrequencySearch( const SGPropertyNode*, SGPropertyNode * ) -{ - FGATCDialogNew::instance()->frequencySearch(); - return true; -} - -static bool doFrequencyDisplay( const SGPropertyNode* args, SGPropertyNode * root) -{ - std::string icao = args->getStringValue("icao"); - if (icao.empty()) { - icao = fgGetString("/sim/atc/freq-airport"); - } - - FGATCDialogNew::instance()->frequencyDisplay(icao); - return true; -} - -// Initialize instance variable to NULL - first instance not yet generated -// first call to instance() will create a new instance, therafter return that instance -FGATCDialogNew * FGATCDialogNew::_instance = NULL; - -// Constructor function, assign values -FGATCDialogNew::FGATCDialogNew() - : _gui(NULL), - dialogVisible(true) -{ -} - -// Destructor -FGATCDialogNew::~FGATCDialogNew() -{ -} - -// Init function, sets up instance of FGATCDialogNew on first call of instance() -void FGATCDialogNew::init() { - // Add ATC-dialog to the command list - globals->get_commands()->addCommand("ATC-dialog", FGATCDialogNew::popup ); - // Add ATC-freq-search to the command list - globals->get_commands()->addCommand("ATC-freq-search", doFrequencySearch); - globals->get_commands()->addCommand("ATC-freq-display", doFrequencyDisplay); - - // initialize properties polled in Update() - //globals->get_props()->setStringValue("/sim/atc/freq-airport", ""); - globals->get_props()->setIntValue("/sim/atc/transmission-num", -1); -} - -void FGATCDialogNew::shutdown() -{ - auto commands = globals->get_commands(); - commands->removeCommand("ATC-dialog"); - commands->removeCommand("ATC-freq-search"); - commands->removeCommand("ATC-freq-display"); -} - -// Display the ATC popup dialog box with options relevant to the users current situation. -// -// So, the first thing we need to do is check the frequency that our pilot's nav radio -// is currently tuned to. The dialog should always contain an option to to tune the -// to a particular frequency, - -// Okay, let's see, according to my interpretation of David Luff's original code, -// his ATC subsystem wrote properties to a named node, called "transmission-choice" - - -void FGATCDialogNew::addEntry(int nr, const std::string& txt) { - commands.clear(); - // Append the text to the string list - commands.push_back(txt); - // Always will show this option - commands.push_back(string("Toggle ground network visibility")); -} - -void FGATCDialogNew::removeEntry(int nr) { - commands.clear(); -} - -// toggle state of dialogVisible -void FGATCDialogNew::PopupDialog() { - dialogVisible = !dialogVisible; - return; -} - -void FGATCDialogNew::hackyReset() -{ - if (_instance) { - _instance->shutdown(); - delete _instance; - _instance = nullptr; - } -} - -void FGATCDialogNew::update(double dt) { -// double onBoardRadioFreq0 = -// fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz"); -// double onBoardRadioFreq1 = -// fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz"); - - const char *dialog_name = "atc-dialog"; - - // check gui subsystem - _gui = (NewGUI *)globals->get_subsystem("gui"); - if (!_gui) { - return; - } - - SGPropertyNode_ptr dlg = _gui->getDialogProperties(dialog_name); - if (!dlg) - return; - - _gui->closeDialog(dialog_name); - SGPropertyNode_ptr button_group = getNamedNode(dlg, "transmission-choice"); - button_group->removeChildren("button"); - - const int bufsize = 32; - char buf[bufsize]; - int commandNr = 0; - // loop over all entries that should fill up the dialog; use 10 items for now... - for (const auto& i : commands) { - snprintf(buf, bufsize, "/sim/atc/opt[%d]", commandNr); - fgSetBool(buf, false); - SGPropertyNode *entry = button_group->getNode("button", commandNr, true); - copyProperties(button_group->getNode("button-template", true), entry); - entry->removeChildren("enabled"); - entry->setStringValue("property", buf); - entry->setIntValue("keynum", '1' + commandNr); - if (commandNr == 0) - entry->setBoolValue("default", true); - - snprintf(buf, bufsize, "%d", 1 + commandNr); - string legend = string(buf) + i; //"; // + current->menuentry; - entry->setStringValue("legend", legend.c_str()); - entry->setIntValue("binding/value", commandNr); - commandNr++; - //current++; - } - - if (dialogVisible) { - _gui->closeDialog(dialog_name); - } else { - _gui->showDialog(dialog_name); - } -} diff --git a/src/ATC/atcdialog.hxx b/src/ATC/atcdialog.hxx deleted file mode 100644 index c223787be..000000000 --- a/src/ATC/atcdialog.hxx +++ /dev/null @@ -1,92 +0,0 @@ -// atcdialog.hxx - classes to manage user interactions with AI traffic -// Written by Durk Talsma, started April 3, 2011 -// Based on earlier code written by Alexander Kappes and David Luff -// -// 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. -// -// 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, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - - -#ifndef _ATC_DIALOG_HXX_ -#define _ATC_DIALOG_HXX_ - - -#ifndef __cplusplus -# error This library requires C++ -#endif - -#include -#include -#include -#include - -class NewGUI; -class SGPropertyNode; - -/** - * despite looking like a subsystem, this is not, at the moment. - * So don't assume it has subsystem semantics or behaviour. - * For 'next' we're fixing this, but it's too complex a change for 2020.3 - */ -class FGATCDialogNew -{ -private: - NewGUI *_gui; - bool dialogVisible; - string_list commands; - - static FGATCDialogNew *_instance; -public: - - FGATCDialogNew(); - ~FGATCDialogNew(); - - void frequencySearch(); - void frequencyDisplay(const std::string& ident); - - void init(); - void shutdown(); - - void update(double dt); - void PopupDialog(); - void addEntry(int, const std::string&); - void removeEntry(int); - - static bool popup( const SGPropertyNode *, SGPropertyNode * root) { - instance()->PopupDialog(); - return true; - } - - /** - * hacky fix for various crashes on reset: give a way to reset instance - * back to null-ptr, so that we get a new instance created. - * Without this, we crash in various exciting ways due to stale pointers - * - */ - static void hackyReset(); - - // Generate new instance of FGATCDialogNew if it hasn't yet been generated - // Call constructor and init() functions - // If it has been generated, will return that instance - inline static FGATCDialogNew * instance() { - if( _instance != NULL ) return _instance; - _instance = new FGATCDialogNew(); - _instance->init(); - return _instance; - } -}; - - -#endif // _ATC_DIALOG_HXX_ \ No newline at end of file diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index d02b2e003..9fab23755 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -886,7 +886,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent, } } } else { - FGATCDialogNew::instance()->addEntry(1, text); + //FGATCDialogNew::instance()->addEntry(1, text); } } @@ -1286,7 +1286,7 @@ bool FGStartupController::checkTransmissionState(int st, time_t now, time_t star trans_num->setIntValue(-1); // PopupCallback(n); SG_LOG(SG_ATC, SG_BULK, "Selected transmission message " << n); - FGATCDialogNew::instance()->removeEntry(1); + //FGATCDialogNew::instance()->removeEntry(1); } else { SG_LOG(SG_ATC, SG_BULK, "Creating message for " << i->getAircraft()->getCallSign()); transmit(&(*i), &(*parent), msgId, msgDir, false); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index b28e983ff..b91e38ed9 100755 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1288,7 +1288,7 @@ void fgStartNewReset() // hack fix for many reset crashes relating to the static instance // of this class. Will be fixed better for future versions by making // this a proper subsystem. - FGATCDialogNew::hackyReset(); + //FGATCDialogNew::hackyReset(); // remove most subsystems, with a few exceptions. for (int g=0; g