| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2024-02-16 16:31:12 +00:00
										 |  |  | // Copyright (C) 2021-2024 Jon Beniston, M7RCE <jon@beniston.com>                //
 | 
					
						
							| 
									
										
										
										
											2023-11-18 13:12:18 +01:00
										 |  |  | // Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>          //
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 as version 3 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 V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <cmath>
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | #include <QLineEdit>
 | 
					
						
							|  |  |  | #include <QDesktopServices>
 | 
					
						
							|  |  |  | #include <QAction>
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | #include <QClipboard>
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "feature/featureuiset.h"
 | 
					
						
							|  |  |  | #include "feature/featurewebapiutils.h"
 | 
					
						
							|  |  |  | #include "gui/basicfeaturesettingsdialog.h"
 | 
					
						
							| 
									
										
										
										
											2022-12-20 10:31:15 +00:00
										 |  |  | #include "gui/tabletapandhold.h"
 | 
					
						
							|  |  |  | #include "gui/dialogpositioner.h"
 | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  | #include "util/mmsi.h"
 | 
					
						
							| 
									
										
										
										
											2024-04-08 22:40:24 +02:00
										 |  |  | #include "maincore.h"
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "ui_aisgui.h"
 | 
					
						
							|  |  |  | #include "ais.h"
 | 
					
						
							|  |  |  | #include "aisgui.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "SWGMapItem.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | // Models to use for ships when type is unknown
 | 
					
						
							|  |  |  | // Use as many as possibly, so it doesn't look too samey, but don't use
 | 
					
						
							|  |  |  | // the massive ships
 | 
					
						
							|  |  |  | QStringList AISGUI::m_shipModels = { | 
					
						
							|  |  |  |     "ship_27m.glbe", "ship_65m.glbe", | 
					
						
							|  |  |  |     "tug_20m.glbe", "tug_30m_1.glbe", "tug_30m_2.glbe", "tug_30m_3.glbe", | 
					
						
							|  |  |  |     "cargo_75m.glbe", "tanker_50m.glbe", "dredger_53m.glbe", | 
					
						
							|  |  |  |     "trawler_22m.glbe", | 
					
						
							| 
									
										
										
										
											2024-02-16 16:31:12 +00:00
										 |  |  |     "speedboat_8m.glbe", /*"yacht_10m.glbe",*/ "yacht_20m.glbe", "yacht_42m.glbe" | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QStringList AISGUI::m_sailboatModels = { | 
					
						
							|  |  |  |     "sailboat_8m.glbe", "sailboat_17m.glbe" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QHash<QString, float> AISGUI::m_labelOffset = { | 
					
						
							|  |  |  |     {"helicopter.glb", 4.0f}, | 
					
						
							|  |  |  |     {"antenna.glb", 4.5f}, | 
					
						
							|  |  |  |     {"buoy.glb", 1.5f}, | 
					
						
							|  |  |  |     {"ship_27m.glbe", 13.0f}, | 
					
						
							|  |  |  |     {"dredger_53m.glbe", 19.0f}, | 
					
						
							|  |  |  |     {"ship_65m.glbe", 26.0f}, | 
					
						
							|  |  |  |     {"tug_20m.glbe", 10.0f}, | 
					
						
							|  |  |  |     {"tug_30m_1.glbe", 17.0f}, | 
					
						
							|  |  |  |     {"tug_30m_2.glbe", 17.0f}, | 
					
						
							|  |  |  |     {"tug_30m_3.glbe", 17.0f}, | 
					
						
							|  |  |  |     {"coastguard.glbe", 4.0}, | 
					
						
							|  |  |  |     {"cargo_75m.glbe", 22.0f}, | 
					
						
							|  |  |  |     {"cargo_190m.glbe", 42.0f}, | 
					
						
							|  |  |  |     {"cargo_230m.glbe", 42.0f}, | 
					
						
							|  |  |  |     {"tanker_50m.glbe", 12.0f}, | 
					
						
							|  |  |  |     {"tanker_180m.glbe", 35.0f}, | 
					
						
							|  |  |  |     {"tanker_245m_1.glbe", 30.0f}, | 
					
						
							|  |  |  |     {"tanker_380m_1.glbe", 42.0f}, | 
					
						
							|  |  |  |     {"passenger_100m.glbe", 34.0f}, | 
					
						
							|  |  |  |     {"dredger_53m.glbe", 19.0f}, | 
					
						
							|  |  |  |     {"trawler_22m.glbe", 15.0f}, | 
					
						
							|  |  |  |     {"sailboat_8m.glbe", 11.0f}, | 
					
						
							|  |  |  |     {"sailboat_17m.glbe", 24.0f}, | 
					
						
							|  |  |  |     {"speedboat_8m.glbe", 3.0f}, | 
					
						
							|  |  |  |     {"yacht_10m.glbe", 3.0f}, | 
					
						
							|  |  |  |     {"yacht_20m.glbe", 7.5f}, | 
					
						
							|  |  |  |     {"yacht_42m.glbe", 10.0f}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QHash<QString, float> AISGUI::m_modelOffset = { | 
					
						
							|  |  |  |     {"helicopter.glb", 4.0f}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | AISGUI* AISGUI::create(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     AISGUI* gui = new AISGUI(pluginAPI, featureUISet, feature); | 
					
						
							|  |  |  |     return gui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.resetToDefaults(); | 
					
						
							|  |  |  |     displaySettings(); | 
					
						
							|  |  |  |     applySettings(true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray AISGUI::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AISGUI::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  |         m_feature->setWorkspaceIndex(m_settings.m_workspaceIndex); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         displaySettings(); | 
					
						
							|  |  |  |         applySettings(true); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AISGUI::handleMessage(const Message& message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (AIS::MsgConfigureAIS::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("AISGUI::handleMessage: AIS::MsgConfigureAIS"); | 
					
						
							|  |  |  |         const AIS::MsgConfigureAIS& cfg = (AIS::MsgConfigureAIS&) message; | 
					
						
							| 
									
										
										
										
											2022-11-20 19:54:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (cfg.getForce()) { | 
					
						
							|  |  |  |             m_settings = cfg.getSettings(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         blockApplySettings(true); | 
					
						
							|  |  |  |         displaySettings(); | 
					
						
							|  |  |  |         blockApplySettings(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MainCore::MsgPacket::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MainCore::MsgPacket& report = (MainCore::MsgPacket&) message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Decode the message
 | 
					
						
							|  |  |  |         AISMessage *ais = AISMessage::decode(report.getPacket()); | 
					
						
							|  |  |  |         // Update table
 | 
					
						
							| 
									
										
										
										
											2024-06-20 22:00:15 +01:00
										 |  |  |         if (ais) { | 
					
						
							|  |  |  |             updateVessels(ais, report.getDateTime()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::handleInputMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ((message = getInputMessageQueue()->pop())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (handleMessage(*message)) { | 
					
						
							|  |  |  |             delete message; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::onWidgetRolled(QWidget* widget, bool rollDown) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) widget; | 
					
						
							|  |  |  |     (void) rollDown; | 
					
						
							| 
									
										
										
										
											2021-11-23 13:35:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-24 19:34:48 +02:00
										 |  |  |     RollupContents *rollupContents = getRollupContents(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rollupContents->saveState(m_rollupState); | 
					
						
							| 
									
										
										
										
											2021-11-23 13:35:57 +00:00
										 |  |  |     applySettings(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AISGUI::AISGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent) : | 
					
						
							|  |  |  |     FeatureGUI(parent), | 
					
						
							|  |  |  |     ui(new Ui::AISGUI), | 
					
						
							|  |  |  |     m_pluginAPI(pluginAPI), | 
					
						
							|  |  |  |     m_featureUISet(featureUISet), | 
					
						
							|  |  |  |     m_doApplySettings(true), | 
					
						
							|  |  |  |     m_lastFeatureState(0) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  |     m_feature = feature; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     setAttribute(Qt::WA_DeleteOnClose, true); | 
					
						
							| 
									
										
										
										
											2022-04-24 19:34:48 +02:00
										 |  |  |     m_helpURL = "plugins/feature/ais/readme.md"; | 
					
						
							|  |  |  |     RollupContents *rollupContents = getRollupContents(); | 
					
						
							|  |  |  | 	ui->setupUi(rollupContents); | 
					
						
							|  |  |  |     rollupContents->arrangeRollups(); | 
					
						
							|  |  |  | 	connect(rollupContents, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     m_ais = reinterpret_cast<AIS*>(feature); | 
					
						
							|  |  |  |     m_ais->setMessageQueueToGUI(&m_inputMessageQueue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); | 
					
						
							|  |  |  |     connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     // Timer to remove vessels we haven't heard from in a while
 | 
					
						
							|  |  |  |     connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeOldVessels())); | 
					
						
							|  |  |  |     m_timer.start(60*1000); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Resize the table using dummy data
 | 
					
						
							|  |  |  |     resizeTable(); | 
					
						
							|  |  |  |     // Allow user to reorder columns
 | 
					
						
							|  |  |  |     ui->vessels->horizontalHeader()->setSectionsMovable(true); | 
					
						
							|  |  |  |     // Allow user to sort table by clicking on headers
 | 
					
						
							|  |  |  |     ui->vessels->setSortingEnabled(true); | 
					
						
							|  |  |  |     // Add context menu to allow hiding/showing of columns
 | 
					
						
							|  |  |  |     vesselsMenu = new QMenu(ui->vessels); | 
					
						
							|  |  |  |     for (int i = 0; i < ui->vessels->horizontalHeader()->count(); i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString text = ui->vessels->horizontalHeaderItem(i)->text(); | 
					
						
							|  |  |  |         vesselsMenu->addAction(createCheckableItem(text, i, true, SLOT(vesselsColumnSelectMenuChecked()))); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ui->vessels->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu); | 
					
						
							|  |  |  |     connect(ui->vessels->horizontalHeader(), SIGNAL(customContextMenuRequested(QPoint)), SLOT(vesselsColumnSelectMenu(QPoint))); | 
					
						
							|  |  |  |     // Get signals when columns change
 | 
					
						
							|  |  |  |     connect(ui->vessels->horizontalHeader(), SIGNAL(sectionMoved(int, int, int)), SLOT(vessels_sectionMoved(int, int, int))); | 
					
						
							|  |  |  |     connect(ui->vessels->horizontalHeader(), SIGNAL(sectionResized(int, int, int)), SLOT(vessels_sectionResized(int, int, int))); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     // Context menu
 | 
					
						
							|  |  |  |     ui->vessels->setContextMenuPolicy(Qt::CustomContextMenu); | 
					
						
							|  |  |  |     connect(ui->vessels, SIGNAL(customContextMenuRequested(QPoint)), SLOT(vessels_customContextMenuRequested(QPoint))); | 
					
						
							| 
									
										
										
										
											2022-12-20 10:31:15 +00:00
										 |  |  |     TableTapAndHold *tableTapAndHold = new TableTapAndHold(ui->vessels); | 
					
						
							|  |  |  |     connect(tableTapAndHold, &TableTapAndHold::tapAndHold, this, &AISGUI::vessels_customContextMenuRequested); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  |     m_settings.setRollupState(&m_rollupState); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     displaySettings(); | 
					
						
							|  |  |  |     applySettings(true); | 
					
						
							| 
									
										
										
										
											2024-02-16 16:31:12 +00:00
										 |  |  |     m_resizer.enableChildMouseTracking(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AISGUI::~AISGUI() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-02-16 14:30:55 +00:00
										 |  |  |     // Remove all ships from map
 | 
					
						
							|  |  |  |     for (int row = ui->vessels->rowCount() - 1; row >= 0; row--) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString mmsi = ui->vessels->item(row, VESSEL_COL_MMSI)->text(); | 
					
						
							|  |  |  |         sendToMap(mmsi, "", | 
					
						
							|  |  |  |             "", "", | 
					
						
							|  |  |  |             "", 0.0f, 0.0f, | 
					
						
							|  |  |  |             0.0f, 0.0f, QDateTime(), | 
					
						
							|  |  |  |             0.0f); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     qDeleteAll(m_vessels); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     delete ui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  | void AISGUI::setWorkspaceIndex(int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_workspaceIndex = index; | 
					
						
							|  |  |  |     m_feature->setWorkspaceIndex(index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | void AISGUI::blockApplySettings(bool block) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_doApplySettings = !block; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::displaySettings() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     setTitleColor(m_settings.m_rgbColor); | 
					
						
							|  |  |  |     setWindowTitle(m_settings.m_title); | 
					
						
							| 
									
										
										
										
											2022-04-04 10:23:52 +02:00
										 |  |  |     setTitle(m_settings.m_title); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     blockApplySettings(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Order and size columns
 | 
					
						
							|  |  |  |     QHeaderView *header = ui->vessels->horizontalHeader(); | 
					
						
							|  |  |  |     for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         bool hidden = m_settings.m_vesselColumnSizes[i] == 0; | 
					
						
							|  |  |  |         header->setSectionHidden(i, hidden); | 
					
						
							|  |  |  |         vesselsMenu->actions().at(i)->setChecked(!hidden); | 
					
						
							| 
									
										
										
										
											2022-11-20 19:54:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         if (m_settings.m_vesselColumnSizes[i] > 0) { | 
					
						
							|  |  |  |             ui->vessels->setColumnWidth(i, m_settings.m_vesselColumnSizes[i]); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-11-20 19:54:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         header->moveSection(header->visualIndex(i), m_settings.m_vesselColumnIndexes[i]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 10:23:52 +02:00
										 |  |  |     getRollupContents()->restoreState(m_rollupState); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     blockApplySettings(false); | 
					
						
							| 
									
										
										
										
											2022-04-04 10:23:52 +02:00
										 |  |  |     getRollupContents()->arrangeRollups(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::onMenuDialogCalled(const QPoint &p) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         BasicFeatureSettingsDialog dialog(this); | 
					
						
							|  |  |  |         dialog.setTitle(m_settings.m_title); | 
					
						
							|  |  |  |         dialog.setUseReverseAPI(m_settings.m_useReverseAPI); | 
					
						
							|  |  |  |         dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress); | 
					
						
							|  |  |  |         dialog.setReverseAPIPort(m_settings.m_reverseAPIPort); | 
					
						
							|  |  |  |         dialog.setReverseAPIFeatureSetIndex(m_settings.m_reverseAPIFeatureSetIndex); | 
					
						
							|  |  |  |         dialog.setReverseAPIFeatureIndex(m_settings.m_reverseAPIFeatureIndex); | 
					
						
							| 
									
										
										
										
											2022-04-18 12:08:33 +02:00
										 |  |  |         dialog.setDefaultTitle(m_displayedName); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         dialog.move(p); | 
					
						
							| 
									
										
										
										
											2022-12-20 10:31:15 +00:00
										 |  |  |         new DialogPositioner(&dialog, false); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         dialog.exec(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_settings.m_title = dialog.getTitle(); | 
					
						
							|  |  |  |         m_settings.m_useReverseAPI = dialog.useReverseAPI(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIPort = dialog.getReverseAPIPort(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIFeatureSetIndex = dialog.getReverseAPIFeatureSetIndex(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIFeatureIndex = dialog.getReverseAPIFeatureIndex(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-18 12:08:33 +02:00
										 |  |  |         setTitle(m_settings.m_title); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         setTitleColor(m_settings.m_rgbColor); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-20 20:14:07 +01:00
										 |  |  |         m_settingsKeys.append("title"); | 
					
						
							|  |  |  |         m_settingsKeys.append("rgbColor"); | 
					
						
							| 
									
										
										
										
											2022-11-20 19:54:13 +01:00
										 |  |  |         m_settingsKeys.append("useReverseAPI"); | 
					
						
							|  |  |  |         m_settingsKeys.append("reverseAPIAddress"); | 
					
						
							|  |  |  |         m_settingsKeys.append("reverseAPIPort"); | 
					
						
							|  |  |  |         m_settingsKeys.append("reverseAPIFeatureSetIndex"); | 
					
						
							|  |  |  |         m_settingsKeys.append("reverseAPIFeatureIndex"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         applySettings(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resetContextMenuType(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | void AISGUI::removeOldVessels() | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     // Remove if we haven't received a message in 10 minutes
 | 
					
						
							|  |  |  |     QDateTime currentDateTime = QDateTime::currentDateTime(); | 
					
						
							|  |  |  |     for (int row = ui->vessels->rowCount() - 1; row >= 0; row--) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QDateTime lastDateTime = ui->vessels->item(row, VESSEL_COL_LAST_UPDATE)->data(Qt::DisplayRole).toDateTime(); | 
					
						
							|  |  |  |         if (lastDateTime.isValid()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qint64 diff = lastDateTime.secsTo(currentDateTime); | 
					
						
							|  |  |  |             if (diff > 10*60) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QString mmsi = ui->vessels->item(row, VESSEL_COL_MMSI)->text(); | 
					
						
							|  |  |  |                 // Remove from map
 | 
					
						
							|  |  |  |                 sendToMap(mmsi, "", | 
					
						
							|  |  |  |                     "", "", | 
					
						
							|  |  |  |                     "", 0.0f, 0.0f, | 
					
						
							|  |  |  |                     0.0f, 0.0f, QDateTime(), | 
					
						
							|  |  |  |                     0.0f); | 
					
						
							|  |  |  |                 // Remove from table
 | 
					
						
							|  |  |  |                 ui->vessels->removeRow(row); | 
					
						
							| 
									
										
										
										
											2023-02-16 14:30:55 +00:00
										 |  |  |                 // Remove from hash and free memory
 | 
					
						
							|  |  |  |                 delete m_vessels.take(mmsi); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::applySettings(bool force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_doApplySettings) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-11-20 19:54:13 +01:00
										 |  |  |         AIS::MsgConfigureAIS* message = AIS::MsgConfigureAIS::create(m_settings, m_settingsKeys, force); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         m_ais->getInputMessageQueue()->push(message); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-11-20 19:54:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_settingsKeys.clear(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::resizeTable() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Fill table with a row of dummy data that will size the columns nicely
 | 
					
						
							|  |  |  |     int row = ui->vessels->rowCount(); | 
					
						
							|  |  |  |     ui->vessels->setRowCount(row + 1); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_MMSI, new QTableWidgetItem("123456789")); | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |     ui->vessels->setItem(row, VESSEL_COL_COUNTRY, new QTableWidgetItem("flag")); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     ui->vessels->setItem(row, VESSEL_COL_TYPE, new QTableWidgetItem("Base station")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_LATITUDE, new QTableWidgetItem("90.000000-")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_LONGITUDE, new QTableWidgetItem("180.00000-")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_COURSE, new QTableWidgetItem("360.0")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_SPEED, new QTableWidgetItem("120")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_HEADING, new QTableWidgetItem("360")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_STATUS, new QTableWidgetItem("Under way using engine")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_IMO, new QTableWidgetItem("123456789")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_NAME, new QTableWidgetItem("12345678901234567890")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_CALLSIGN, new QTableWidgetItem("1234567")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_SHIP_TYPE, new QTableWidgetItem("Passenger")); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     ui->vessels->setItem(row, VESSEL_COL_LENGTH, new QTableWidgetItem("400")); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     ui->vessels->setItem(row, VESSEL_COL_DESTINATION, new QTableWidgetItem("12345678901234567890")); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     ui->vessels->setItem(row, VESSEL_COL_POSITION_UPDATE, new QTableWidgetItem("12/12/2022 12:00")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_LAST_UPDATE, new QTableWidgetItem("12/12/2022 12:00")); | 
					
						
							|  |  |  |     ui->vessels->setItem(row, VESSEL_COL_MESSAGES, new QTableWidgetItem("1000")); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     ui->vessels->resizeColumnsToContents(); | 
					
						
							|  |  |  |     ui->vessels->removeRow(row); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Columns in table reordered
 | 
					
						
							|  |  |  | void AISGUI::vessels_sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) oldVisualIndex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_settings.m_vesselColumnIndexes[logicalIndex] = newVisualIndex; | 
					
						
							| 
									
										
										
										
											2022-11-20 19:54:13 +01:00
										 |  |  |     m_settingsKeys.append("vesselColumnIndexes"); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Column in table resized (when hidden size is 0)
 | 
					
						
							|  |  |  | void AISGUI::vessels_sectionResized(int logicalIndex, int oldSize, int newSize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) oldSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_settings.m_vesselColumnSizes[logicalIndex] = newSize; | 
					
						
							| 
									
										
										
										
											2022-11-20 19:54:13 +01:00
										 |  |  |     m_settingsKeys.append("vesselColumnSizes"); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Right click in table header - show column select menu
 | 
					
						
							|  |  |  | void AISGUI::vesselsColumnSelectMenu(QPoint pos) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     vesselsMenu->popup(ui->vessels->horizontalHeader()->viewport()->mapToGlobal(pos)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Hide/show column when menu selected
 | 
					
						
							|  |  |  | void AISGUI::vesselsColumnSelectMenuChecked(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) checked; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QAction* action = qobject_cast<QAction*>(sender()); | 
					
						
							|  |  |  |     if (action != nullptr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int idx = action->data().toInt(nullptr); | 
					
						
							|  |  |  |         ui->vessels->setColumnHidden(idx, !action->isChecked()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Create column select menu item
 | 
					
						
							|  |  |  | QAction *AISGUI::createCheckableItem(QString &text, int idx, bool checked, const char *slot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QAction *action = new QAction(text, this); | 
					
						
							|  |  |  |     action->setCheckable(true); | 
					
						
							|  |  |  |     action->setChecked(checked); | 
					
						
							|  |  |  |     action->setData(QVariant(idx)); | 
					
						
							|  |  |  |     connect(action, SIGNAL(triggered()), this, slot); | 
					
						
							|  |  |  |     return action; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | // Send to Map feature
 | 
					
						
							|  |  |  | void AISGUI::sendToMap(const QString &name, const QString &label, | 
					
						
							|  |  |  |     const QString &image, const QString &text, | 
					
						
							|  |  |  |     const QString &model, float modelOffset, float labelOffset, | 
					
						
							|  |  |  |     float latitude, float longitude, QDateTime positionDateTime, | 
					
						
							|  |  |  |     float heading | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-29 20:12:15 +02:00
										 |  |  |     QList<ObjectPipe*> mapPipes; | 
					
						
							|  |  |  |     MainCore::instance()->getMessagePipes().getMessagePipes(m_ais, "mapitems", mapPipes); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-29 20:12:15 +02:00
										 |  |  |     for (const auto& pipe : mapPipes) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MessageQueue *messageQueue = qobject_cast<MessageQueue*>(pipe->m_element); | 
					
						
							|  |  |  |         SWGSDRangel::SWGMapItem *swgMapItem = new SWGSDRangel::SWGMapItem(); | 
					
						
							|  |  |  |         swgMapItem->setName(new QString(name)); | 
					
						
							|  |  |  |         swgMapItem->setLatitude(latitude); | 
					
						
							|  |  |  |         swgMapItem->setLongitude(longitude); | 
					
						
							|  |  |  |         swgMapItem->setAltitude(0); | 
					
						
							|  |  |  |         swgMapItem->setAltitudeReference(1); // CLAMP_TO_GROUND
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-16 14:30:55 +00:00
										 |  |  |         if (positionDateTime.isValid()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-03-29 20:12:15 +02:00
										 |  |  |             swgMapItem->setPositionDateTime(new QString(positionDateTime.toString(Qt::ISODateWithMs))); | 
					
						
							| 
									
										
										
										
											2023-02-16 14:30:55 +00:00
										 |  |  |             swgMapItem->setOrientationDateTime(new QString(positionDateTime.toString(Qt::ISODateWithMs))); | 
					
						
							|  |  |  |             swgMapItem->setAvailableUntil(new QString(positionDateTime.addSecs(10*60).toString(Qt::ISODateWithMs))); | 
					
						
							| 
									
										
										
										
											2022-03-29 20:12:15 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-29 20:12:15 +02:00
										 |  |  |         swgMapItem->setImageRotation(heading); | 
					
						
							|  |  |  |         swgMapItem->setText(new QString(text)); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-29 20:12:15 +02:00
										 |  |  |         if (image.isEmpty()) { | 
					
						
							|  |  |  |             swgMapItem->setImage(new QString("")); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             swgMapItem->setImage(new QString(QString("qrc:///ais/map/%1").arg(image))); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-29 20:12:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         swgMapItem->setModel(new QString(model)); | 
					
						
							|  |  |  |         swgMapItem->setModelAltitudeOffset(modelOffset); | 
					
						
							|  |  |  |         swgMapItem->setLabel(new QString(label)); | 
					
						
							|  |  |  |         swgMapItem->setLabelAltitudeOffset(labelOffset); | 
					
						
							|  |  |  |         swgMapItem->setFixedPosition(false); | 
					
						
							|  |  |  |         swgMapItem->setOrientation(1); | 
					
						
							|  |  |  |         swgMapItem->setHeading(heading); | 
					
						
							|  |  |  |         swgMapItem->setPitch(0.0); | 
					
						
							|  |  |  |         swgMapItem->setRoll(0.0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MainCore::MsgMapItem *msg = MainCore::MsgMapItem::create(m_ais, swgMapItem); | 
					
						
							|  |  |  |         messageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Update table with received message
 | 
					
						
							|  |  |  | void AISGUI::updateVessels(AISMessage *ais, QDateTime dateTime) | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QTableWidgetItem *mmsiItem; | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |     QTableWidgetItem *countryItem; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     QTableWidgetItem *typeItem; | 
					
						
							|  |  |  |     QTableWidgetItem *latitudeItem; | 
					
						
							|  |  |  |     QTableWidgetItem *longitudeItem; | 
					
						
							|  |  |  |     QTableWidgetItem *courseItem; | 
					
						
							|  |  |  |     QTableWidgetItem *speedItem; | 
					
						
							|  |  |  |     QTableWidgetItem *headingItem; | 
					
						
							|  |  |  |     QTableWidgetItem *statusItem; | 
					
						
							|  |  |  |     QTableWidgetItem *imoItem; | 
					
						
							|  |  |  |     QTableWidgetItem *nameItem; | 
					
						
							|  |  |  |     QTableWidgetItem *callsignItem; | 
					
						
							|  |  |  |     QTableWidgetItem *shipTypeItem; | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     QTableWidgetItem *lengthItem; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     QTableWidgetItem *destinationItem; | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     QTableWidgetItem *positionUpdateItem; | 
					
						
							|  |  |  |     QTableWidgetItem *lastUpdateItem; | 
					
						
							|  |  |  |     QTableWidgetItem *messagesItem; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString previousType; | 
					
						
							|  |  |  |     QString previousShipType; | 
					
						
							|  |  |  |     Vessel *vessel; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // See if vessel is already in table
 | 
					
						
							|  |  |  |     QString messageMMSI = QString("%1").arg(ais->m_mmsi, 9, 10, QChar('0')); | 
					
						
							|  |  |  |     bool found = false; | 
					
						
							|  |  |  |     for (int row = 0; row < ui->vessels->rowCount(); row++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString itemMMSI = ui->vessels->item(row, VESSEL_COL_MMSI)->text(); | 
					
						
							|  |  |  |         if (messageMMSI == itemMMSI) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Update existing item
 | 
					
						
							|  |  |  |             mmsiItem = ui->vessels->item(row, VESSEL_COL_MMSI); | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |             countryItem = ui->vessels->item(row, VESSEL_COL_COUNTRY); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |             typeItem = ui->vessels->item(row, VESSEL_COL_TYPE); | 
					
						
							|  |  |  |             latitudeItem = ui->vessels->item(row, VESSEL_COL_LATITUDE); | 
					
						
							|  |  |  |             longitudeItem = ui->vessels->item(row, VESSEL_COL_LONGITUDE); | 
					
						
							|  |  |  |             courseItem = ui->vessels->item(row, VESSEL_COL_COURSE); | 
					
						
							|  |  |  |             speedItem = ui->vessels->item(row, VESSEL_COL_SPEED); | 
					
						
							|  |  |  |             headingItem = ui->vessels->item(row, VESSEL_COL_HEADING); | 
					
						
							|  |  |  |             statusItem = ui->vessels->item(row, VESSEL_COL_STATUS); | 
					
						
							|  |  |  |             imoItem = ui->vessels->item(row, VESSEL_COL_IMO); | 
					
						
							|  |  |  |             nameItem = ui->vessels->item(row, VESSEL_COL_NAME); | 
					
						
							|  |  |  |             callsignItem = ui->vessels->item(row, VESSEL_COL_CALLSIGN); | 
					
						
							|  |  |  |             shipTypeItem = ui->vessels->item(row, VESSEL_COL_SHIP_TYPE); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             lengthItem = ui->vessels->item(row, VESSEL_COL_LENGTH); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |             destinationItem = ui->vessels->item(row, VESSEL_COL_DESTINATION); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             positionUpdateItem = ui->vessels->item(row, VESSEL_COL_POSITION_UPDATE); | 
					
						
							|  |  |  |             lastUpdateItem = ui->vessels->item(row, VESSEL_COL_LAST_UPDATE); | 
					
						
							|  |  |  |             messagesItem = ui->vessels->item(row, VESSEL_COL_MESSAGES); | 
					
						
							|  |  |  |             vessel = m_vessels.value(messageMMSI); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |             found = true; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!found) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Add new vessel
 | 
					
						
							|  |  |  |         ui->vessels->setSortingEnabled(false); | 
					
						
							|  |  |  |         int row = ui->vessels->rowCount(); | 
					
						
							|  |  |  |         ui->vessels->setRowCount(row + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         mmsiItem = new QTableWidgetItem(); | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |         countryItem = new QTableWidgetItem(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         typeItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         latitudeItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         longitudeItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         courseItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         speedItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         headingItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         statusItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         imoItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         nameItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         callsignItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         shipTypeItem = new QTableWidgetItem(); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |         lengthItem = new QTableWidgetItem(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         destinationItem = new QTableWidgetItem(); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |         positionUpdateItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         lastUpdateItem = new QTableWidgetItem(); | 
					
						
							|  |  |  |         messagesItem = new QTableWidgetItem(); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         ui->vessels->setItem(row, VESSEL_COL_MMSI, mmsiItem); | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |         ui->vessels->setItem(row, VESSEL_COL_COUNTRY, countryItem); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         ui->vessels->setItem(row, VESSEL_COL_TYPE, typeItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_LATITUDE, latitudeItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_LONGITUDE, longitudeItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_COURSE, courseItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_SPEED, speedItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_HEADING, headingItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_STATUS, statusItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_IMO, imoItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_NAME, nameItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_CALLSIGN, callsignItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_SHIP_TYPE, shipTypeItem); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |         ui->vessels->setItem(row, VESSEL_COL_LENGTH, lengthItem); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         ui->vessels->setItem(row, VESSEL_COL_DESTINATION, destinationItem); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |         ui->vessels->setItem(row, VESSEL_COL_POSITION_UPDATE, positionUpdateItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_LAST_UPDATE, lastUpdateItem); | 
					
						
							|  |  |  |         ui->vessels->setItem(row, VESSEL_COL_MESSAGES, messagesItem); | 
					
						
							|  |  |  |         messagesItem->setData(Qt::DisplayRole, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         vessel = new Vessel(); | 
					
						
							|  |  |  |         m_vessels.insert(messageMMSI, vessel); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     previousType = typeItem->text(); | 
					
						
							|  |  |  |     previousShipType = shipTypeItem->text(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |     QString mmsi = QString("%1").arg(ais->m_mmsi, 9, 10, QChar('0')); | 
					
						
							|  |  |  |     mmsiItem->setText(mmsi); | 
					
						
							|  |  |  |     QIcon *flag = MMSI::getFlagIcon(mmsi); | 
					
						
							|  |  |  |     if (flag) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         countryItem->setSizeHint(QSize(40, 20)); | 
					
						
							|  |  |  |         countryItem->setIcon(*flag); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     lastUpdateItem->setData(Qt::DisplayRole, dateTime); | 
					
						
							|  |  |  |     messagesItem->setData(Qt::DisplayRole, messagesItem->data(Qt::DisplayRole).toInt() + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     if ((ais->m_id <= 3) || (ais->m_id == 5) || (ais->m_id == 18) || (ais->m_id == 19)) { | 
					
						
							|  |  |  |         typeItem->setText("Vessel"); | 
					
						
							|  |  |  |     } else if (ais->m_id == 4) { | 
					
						
							|  |  |  |         typeItem->setText("Base station"); | 
					
						
							|  |  |  |     } else if (ais->m_id == 9) { | 
					
						
							|  |  |  |         typeItem->setText("Aircraft"); | 
					
						
							|  |  |  |     } else if (ais->m_id == 21) { | 
					
						
							|  |  |  |         typeItem->setText("Aid-to-nav"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (ais->m_id == 21) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |          AISAidsToNavigationReport *aids = dynamic_cast<AISAidsToNavigationReport*>(ais); | 
					
						
							|  |  |  |          if (aids) { | 
					
						
							|  |  |  |              nameItem->setText(aids->m_name); | 
					
						
							|  |  |  |          } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (ais->m_id == 5) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |          AISShipStaticAndVoyageData *vd = dynamic_cast<AISShipStaticAndVoyageData*>(ais); | 
					
						
							|  |  |  |          if (vd) | 
					
						
							|  |  |  |          { | 
					
						
							|  |  |  |              if (vd->m_imo != 0) { | 
					
						
							|  |  |  |                  imoItem->setData(Qt::DisplayRole, vd->m_imo); | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |              nameItem->setText(vd->m_name); | 
					
						
							|  |  |  |              callsignItem->setText(vd->m_callsign); | 
					
						
							|  |  |  |              shipTypeItem->setText(AISMessage::typeToString(vd->m_type)); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |              lengthItem->setData(Qt::DisplayRole, vd->m_a + vd->m_b); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |              destinationItem->setText(vd->m_destination); | 
					
						
							|  |  |  |          } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (ais->hasPosition()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             latitudeItem->setData(Qt::DisplayRole, ais->getLatitude()); | 
					
						
							|  |  |  |             longitudeItem->setData(Qt::DisplayRole, ais->getLongitude()); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             positionUpdateItem->setData(Qt::DisplayRole, dateTime); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (ais->hasCourse()) { | 
					
						
							|  |  |  |             courseItem->setData(Qt::DisplayRole, ais->getCourse()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (ais->hasSpeed()) { | 
					
						
							|  |  |  |             speedItem->setData(Qt::DisplayRole, ais->getSpeed()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (ais->hasHeading()) { | 
					
						
							|  |  |  |             headingItem->setData(Qt::DisplayRole, ais->getHeading()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         AISPositionReport *pr = dynamic_cast<AISPositionReport*>(ais); | 
					
						
							|  |  |  |         if (pr) { | 
					
						
							|  |  |  |             statusItem->setText(AISPositionReport::getStatusString(pr->m_status)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         AISLongRangePositionReport *lrpr = dynamic_cast<AISLongRangePositionReport*>(ais); | 
					
						
							|  |  |  |         if (lrpr) { | 
					
						
							|  |  |  |             statusItem->setText(AISPositionReport::getStatusString(lrpr->m_status)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-11 10:05:25 +01:00
										 |  |  |     if (ais->m_id == 19) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         AISExtendedClassBPositionReport *ext = dynamic_cast<AISExtendedClassBPositionReport*>(ais); | 
					
						
							|  |  |  |         if (ext) { | 
					
						
							|  |  |  |              shipTypeItem->setText(AISMessage::typeToString(ext->m_type)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     if (ais->m_id == 24) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         AISStaticDataReport *dr = dynamic_cast<AISStaticDataReport*>(ais); | 
					
						
							|  |  |  |         if (dr) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (dr->m_partNumber == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 nameItem->setText(dr->m_name); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (dr->m_partNumber == 1) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 callsignItem->setText(dr->m_callsign); | 
					
						
							|  |  |  |                 shipTypeItem->setText(AISMessage::typeToString(dr->m_type)); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ui->vessels->setSortingEnabled(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVariant latitudeV = latitudeItem->data(Qt::DisplayRole); | 
					
						
							|  |  |  |     QVariant longitudeV = longitudeItem->data(Qt::DisplayRole); | 
					
						
							|  |  |  |     QString type = typeItem->text(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!latitudeV.isNull() && !longitudeV.isNull() && !type.isEmpty()) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |         // Image and model to use on map
 | 
					
						
							|  |  |  |         QString shipType = shipTypeItem->text(); | 
					
						
							|  |  |  |         int length = lengthItem->data(Qt::DisplayRole).toInt(); | 
					
						
							|  |  |  |         QString status = statusItem->text(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Only update model if change in type - so we don't keeping picking new
 | 
					
						
							| 
									
										
										
										
											2022-02-09 16:39:22 +00:00
										 |  |  |         // random models.
 | 
					
						
							|  |  |  |         // Check if image is empty to handle case where ShipStaticData is received
 | 
					
						
							|  |  |  |         // before position
 | 
					
						
							|  |  |  |         if ((previousType != type) || (previousShipType != shipType) || vessel->m_image.isEmpty()) { | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             getImageAndModel(type, shipType, length, status, vessel); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         float labelOffset = m_labelOffset.value(vessel->m_model); | 
					
						
							|  |  |  |         float modelOffset = 0.0f; | 
					
						
							|  |  |  |         if (m_modelOffset.contains(vessel->m_model)) { | 
					
						
							|  |  |  |             modelOffset = m_modelOffset.value(vessel->m_model); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Text to display in info box
 | 
					
						
							|  |  |  |         QStringList text; | 
					
						
							|  |  |  |         QVariant courseV = courseItem->data(Qt::DisplayRole); | 
					
						
							|  |  |  |         QVariant speedV = speedItem->data(Qt::DisplayRole); | 
					
						
							|  |  |  |         QVariant headingV = headingItem->data(Qt::DisplayRole); | 
					
						
							|  |  |  |         QString name = nameItem->text(); | 
					
						
							|  |  |  |         QString callsign = callsignItem->text(); | 
					
						
							|  |  |  |         QString destination = destinationItem->text(); | 
					
						
							|  |  |  |         float heading = 0.0f; | 
					
						
							|  |  |  |         if (!name.isEmpty()) { | 
					
						
							|  |  |  |             text.append(QString("Name: %1").arg(name)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!callsign.isEmpty()) { | 
					
						
							|  |  |  |             text.append(QString("Callsign: %1").arg(callsign)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!destination.isEmpty()) { | 
					
						
							|  |  |  |             text.append(QString("Destination: %1").arg(destination)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!courseV.isNull()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             float course = courseV.toFloat(); | 
					
						
							|  |  |  |             text.append(QString("Course: %1%2").arg(course).arg(QChar(0xb0))); | 
					
						
							|  |  |  |             heading = course; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!speedV.isNull()) { | 
					
						
							|  |  |  |             text.append(QString("Speed: %1 knts").arg(speedV.toFloat())); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!headingV.isNull()) | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             heading = headingV.toFloat(); | 
					
						
							|  |  |  |             text.append(QString("Heading: %1%2").arg(heading).arg(QChar(0xb0))); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!shipType.isEmpty()) { | 
					
						
							|  |  |  |             text.append(QString("Ship type: %1").arg(shipType)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!status.isEmpty()) { | 
					
						
							|  |  |  |             text.append(QString("Status: %1").arg(status)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // Send to map feature
 | 
					
						
							|  |  |  |         sendToMap(mmsiItem->text(), callsign, | 
					
						
							|  |  |  |             vessel->m_image, text.join("<br>"), | 
					
						
							|  |  |  |             vessel->m_model, modelOffset, labelOffset, | 
					
						
							|  |  |  |             latitudeV.toFloat(), longitudeV.toFloat(), positionUpdateItem->data(Qt::DisplayRole).toDateTime(), | 
					
						
							|  |  |  |             heading); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::getImageAndModel(const QString &type, const QString &shipType, int length, const QString &status, Vessel *vessel) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-02-09 16:39:22 +00:00
										 |  |  |     if (type == "Aircraft") | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // I presume search and rescue aircraft are more likely to be helicopters
 | 
					
						
							|  |  |  |         vessel->m_image = "helicopter.png"; | 
					
						
							|  |  |  |         vessel->m_model = "helicopter.glb"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (type == "Base station") | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         vessel->m_image = "anchor.png"; | 
					
						
							|  |  |  |         vessel->m_model = "antenna.glb"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (type == "Aid-to-nav") | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         vessel->m_image = "bouy.png"; | 
					
						
							|  |  |  |         vessel->m_model = "buoy.glb"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         vessel->m_image = "ship.png"; | 
					
						
							|  |  |  |         if (status == "Under way sailing") { | 
					
						
							|  |  |  |             vessel->m_model = m_sailboatModels[m_random.bounded(m_sailboatModels.size())]; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             vessel->m_model = m_shipModels[m_random.bounded(m_shipModels.size())]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!shipType.isEmpty()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (shipType == "Ship") | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 if (length < 40) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "ship_27m.glbe"; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 else if (length < 60) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "dredger_53m.glbe"; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "ship_65m.glbe"; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-02-09 16:39:22 +00:00
										 |  |  |             else if ((shipType == "Tug") || (shipType == "Port tender") || (shipType == "Pilot vessel") || (shipType == "Vessel - Towing")) | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             { | 
					
						
							|  |  |  |                 vessel->m_image = "tug.png"; | 
					
						
							|  |  |  |                 if (length < 25) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "tug_20m.glbe"; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     int rand = m_random.bounded(1, 3); | 
					
						
							|  |  |  |                     vessel->m_model = QString("tug_30m_%1.glbe").arg(rand); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if ((shipType == "Law enforcement vessel") || (shipType == "Search and rescue vessel")) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 vessel->m_model = "coastguard.glbe"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (shipType == "Cargo") | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 vessel->m_image = "cargo.png"; | 
					
						
							|  |  |  |                 if (length < 120) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "cargo_75m.glbe"; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2024-02-16 16:31:12 +00:00
										 |  |  |                 else /*if (length < 200)*/ | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "cargo_190m.glbe"; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2024-02-16 16:31:12 +00:00
										 |  |  |                 /*else
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "cargo_230m.glbe"; | 
					
						
							| 
									
										
										
										
											2024-02-16 16:31:12 +00:00
										 |  |  |                 }*/ | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             else if (shipType == "Tanker") | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 vessel->m_image = "tanker.png"; | 
					
						
							|  |  |  |                 if (length < 120) | 
					
						
							| 
									
										
										
										
											2021-07-04 11:25:53 +02:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                     vessel->m_model = "tanker_50m.glbe"; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 else if (length < 210) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "tanker_180m.glbe"; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 else if (length < 300) | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                     int rand = m_random.bounded(1, 4); | 
					
						
							|  |  |  |                     vessel->m_model = QString("tanker_245m_%1.glbe").arg(rand); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     int rand = m_random.bounded(1, 3); | 
					
						
							|  |  |  |                     vessel->m_model = QString("tanker_380m_%1.glbe").arg(rand); | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             else if (shipType == "Passenger") | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 vessel->m_model = "passenger_100m.glbe"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (shipType == "Vessel - Dredging or underwater operations") | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 vessel->m_model = "dredger_53m.glbe"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (shipType == "Vessel - Fishing") | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 vessel->m_model = "trawler_22m.glbe"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (shipType == "Vessel - Sailing") | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (length < 13) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "sailboat_8m.glbe"; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "sailboat_17m.glbe"; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (shipType.contains("Pleasure craft")) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (length < 9) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "speedboat_8m.glbe"; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2024-02-16 16:31:12 +00:00
										 |  |  |                 /*else if (length < 18)
 | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "yacht_10m.glbe"; | 
					
						
							| 
									
										
										
										
											2024-02-16 16:31:12 +00:00
										 |  |  |                 }*/ | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |                 else if (length < 32) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "yacht_20m.glbe"; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     vessel->m_model = "yacht_42m.glbe"; | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AISGUI::on_vessels_cellDoubleClicked(int row, int column) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (column == VESSEL_COL_MMSI) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Get MMSI of vessel in row double clicked
 | 
					
						
							|  |  |  |         QString mmsi = ui->vessels->item(row, VESSEL_COL_MMSI)->text(); | 
					
						
							|  |  |  |         // Search for MMSI on www.vesselfinder.com
 | 
					
						
							|  |  |  |         QDesktopServices::openUrl(QUrl(QString("https://www.vesselfinder.com/vessels?name=%1").arg(mmsi))); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |     else if ((column == VESSEL_COL_LATITUDE) || (column == VESSEL_COL_LONGITUDE) || (column == VESSEL_COL_SHIP_TYPE)) | 
					
						
							| 
									
										
										
										
											2021-05-07 21:50:27 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         // Get MMSI of vessel in row double clicked
 | 
					
						
							|  |  |  |         QString mmsi = ui->vessels->item(row, VESSEL_COL_MMSI)->text(); | 
					
						
							|  |  |  |         // Find MMSI on Map
 | 
					
						
							|  |  |  |         FeatureWebAPIUtils::mapFind(mmsi); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (column == VESSEL_COL_IMO) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString imo = ui->vessels->item(row, VESSEL_COL_IMO)->text(); | 
					
						
							|  |  |  |         if (!imo.isEmpty() && (imo != "0")) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Search for IMO on www.vesselfinder.com
 | 
					
						
							|  |  |  |             QDesktopServices::openUrl(QUrl(QString("https://www.vesselfinder.com/vessels?name=%1").arg(imo))); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (column == VESSEL_COL_NAME) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString name = ui->vessels->item(row, VESSEL_COL_NAME)->text(); | 
					
						
							|  |  |  |         if (!name.isEmpty()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Search for name on www.vesselfinder.com
 | 
					
						
							|  |  |  |             QDesktopServices::openUrl(QUrl(QString("https://www.vesselfinder.com/vessels?name=%1").arg(name))); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (column == VESSEL_COL_DESTINATION) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString destination = ui->vessels->item(row, VESSEL_COL_DESTINATION)->text(); | 
					
						
							|  |  |  |         if (!destination.isEmpty()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // Find destination on Map
 | 
					
						
							|  |  |  |             FeatureWebAPIUtils::mapFind(destination); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Table cells context menu
 | 
					
						
							|  |  |  | void AISGUI::vessels_customContextMenuRequested(QPoint pos) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QTableWidgetItem *item =  ui->vessels->itemAt(pos); | 
					
						
							|  |  |  |     if (item) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int row = item->row(); | 
					
						
							|  |  |  |         QString mmsi = ui->vessels->item(row, VESSEL_COL_MMSI)->text(); | 
					
						
							|  |  |  |         QString imo = ui->vessels->item(row, VESSEL_COL_IMO)->text(); | 
					
						
							|  |  |  |         QString name = ui->vessels->item(row, VESSEL_COL_NAME)->text(); | 
					
						
							|  |  |  |         QVariant latitudeV = ui->vessels->item(row, VESSEL_COL_LATITUDE)->data(Qt::DisplayRole); | 
					
						
							|  |  |  |         QVariant longitudeV = ui->vessels->item(row, VESSEL_COL_LONGITUDE)->data(Qt::DisplayRole); | 
					
						
							|  |  |  |         QString destination = ui->vessels->item(row, VESSEL_COL_DESTINATION)->text(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QMenu* tableContextMenu = new QMenu(ui->vessels); | 
					
						
							|  |  |  |         connect(tableContextMenu, &QMenu::aboutToHide, tableContextMenu, &QMenu::deleteLater); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Copy current cell
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QAction* copyAction = new QAction("Copy", tableContextMenu); | 
					
						
							|  |  |  |         const QString text = item->text(); | 
					
						
							|  |  |  |         connect(copyAction, &QAction::triggered, this, [text]()->void { | 
					
						
							|  |  |  |             QClipboard *clipboard = QGuiApplication::clipboard(); | 
					
						
							|  |  |  |             clipboard->setText(text); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         tableContextMenu->addAction(copyAction); | 
					
						
							|  |  |  |         tableContextMenu->addSeparator(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // View vessel on various websites
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QAction* mmsiAISHubAction = new QAction(QString("View MMSI %1 on aishub.net...").arg(mmsi), tableContextMenu); | 
					
						
							|  |  |  |         connect(mmsiAISHubAction, &QAction::triggered, this, [mmsi]()->void { | 
					
						
							|  |  |  |             QDesktopServices::openUrl(QUrl(QString("https://www.aishub.net/vessels?Ship%5Bmmsi%5D=%1&mmsi=%1").arg(mmsi))); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         tableContextMenu->addAction(mmsiAISHubAction); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QAction* mmsiAction = new QAction(QString("View MMSI %1 on vesselfinder.com...").arg(mmsi), tableContextMenu); | 
					
						
							|  |  |  |         connect(mmsiAction, &QAction::triggered, this, [mmsi]()->void { | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |             QDesktopServices::openUrl(QUrl(QString("https://www.vesselfinder.com/vessels?name=%1").arg(mmsi))); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |         }); | 
					
						
							|  |  |  |         tableContextMenu->addAction(mmsiAction); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!imo.isEmpty()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |             QAction* imoAction = new QAction(QString("View IMO %1 on vesselfinder.com...").arg(imo), tableContextMenu); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             connect(imoAction, &QAction::triggered, this, [imo]()->void { | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |                 QDesktopServices::openUrl(QUrl(QString("https://www.vesselfinder.com/vessels?name=%1").arg(imo))); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             }); | 
					
						
							|  |  |  |             tableContextMenu->addAction(imoAction); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!name.isEmpty()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |             QAction* nameAction = new QAction(QString("View %1 on vesselfinder.com...").arg(name), tableContextMenu); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             connect(nameAction, &QAction::triggered, this, [name]()->void { | 
					
						
							| 
									
										
										
										
											2023-05-16 10:17:17 +01:00
										 |  |  |                 QDesktopServices::openUrl(QUrl(QString("https://www.vesselfinder.com/vessels?name=%1").arg(name))); | 
					
						
							| 
									
										
										
										
											2022-02-04 17:06:00 +00:00
										 |  |  |             }); | 
					
						
							|  |  |  |             tableContextMenu->addAction(nameAction); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Find on Map
 | 
					
						
							|  |  |  |         if (!latitudeV.isNull()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             tableContextMenu->addSeparator(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             QAction* findMapFeatureAction = new QAction(QString("Find MMSI %1 on map").arg(mmsi), tableContextMenu); | 
					
						
							|  |  |  |             connect(findMapFeatureAction, &QAction::triggered, this, [mmsi]()->void { | 
					
						
							|  |  |  |                 FeatureWebAPIUtils::mapFind(mmsi); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |             tableContextMenu->addAction(findMapFeatureAction); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!destination.isEmpty()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             tableContextMenu->addSeparator(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             QAction* findDestinationFeatureAction = new QAction(QString("Find %1 on map").arg(destination), tableContextMenu); | 
					
						
							|  |  |  |             connect(findDestinationFeatureAction, &QAction::triggered, this, [destination]()->void { | 
					
						
							|  |  |  |                 FeatureWebAPIUtils::mapFind(destination); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |             tableContextMenu->addAction(findDestinationFeatureAction); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         tableContextMenu->popup(ui->vessels->viewport()->mapToGlobal(pos)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |