refs #789, added signal when adding models fails

Signatures in context and simulator
This commit is contained in:
Klaus Basan
2016-10-25 04:34:30 +02:00
parent 42737faf2c
commit df60474510
9 changed files with 37 additions and 13 deletions

View File

@@ -65,6 +65,5 @@ namespace BlackCore
if (!isSimulatorAvailable() || !getSimulatorStatusEnum().testFlag(ISimulator::Simulating)) { return false; }
return true;
}
} // namespace
} // namespace

View File

@@ -96,6 +96,9 @@ namespace BlackCore
//! A single model has been matched for given aircraft
void modelMatchingCompleted(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Adding a remote aircraft failed
void addingRemoteModelFailed(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CStatusMessage &message);
//! Aircraft rendering changed
void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);

View File

@@ -357,6 +357,8 @@ namespace BlackCore
bool c = connect(simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged);
Q_ASSERT(c);
c = connect(simulator, &ISimulator::physicallyAddingRemoteModelFailed, this, &CContextSimulator::ps_addingRemoteAircraftFailed);
Q_ASSERT(c);
c = connect(simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
Q_ASSERT(c);
c = connect(simulator, &ISimulator::aircraftRenderingChanged, this, &IContextSimulator::aircraftRenderingChanged);
@@ -483,13 +485,13 @@ namespace BlackCore
const CCallsign callsign = remoteAircraft.getCallsign();
CStatusMessageList matchingMessages;
CStatusMessageList *pMatchingMessages = m_enableMatchingMessages ? &matchingMessages : nullptr;
CMatchingUtils::addLogDetailsToList(pMatchingMessages, callsign, QString("Matching remote Aircraft"));
const CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(remoteAircraft, pMatchingMessages);
addMatchingMessages(callsign, matchingMessages);
Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns");
updateAircraftModel(callsign, aircraftModel, identifier());
const CSimulatedAircraft aircraftAfterModelApplied = getAircraftInRangeForCallsign(remoteAircraft.getCallsign());
m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied);
CMatchingUtils::addLogDetailsToList(pMatchingMessages, callsign, QString("Logically added remote aircraft: %1").arg(aircraftAfterModelApplied.toQString()));
addMatchingMessages(callsign, matchingMessages);
emit modelMatchingCompleted(remoteAircraft);
}
@@ -560,6 +562,12 @@ namespace BlackCore
m_simulatorPlugin.second->changeRemoteAircraftEnabled(aircraft);
}
void CContextSimulator::ps_addingRemoteAircraftFailed(const CSimulatedAircraft &remoteAircraft, const CStatusMessage &message)
{
if (!isSimulatorSimulating()) { return; }
emit addingRemoteModelFailed(remoteAircraft, message);
}
void CContextSimulator::ps_updateSimulatorCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator)
{
if (!isSimulatorSimulating()) { return; }

View File

@@ -140,6 +140,9 @@ namespace BlackCore
//! Enable / disable aircraft
void ps_changedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Failed adding remote aircraft
void ps_addingRemoteAircraftFailed(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::CStatusMessage &message);
//! Update simulator cockpit from context, because someone else has changed cockpit (e.g. GUI, 3rd party)
//! \remarks set by runtime, only to be used locally (not via DBus)
void ps_updateSimulatorCockpitFromContext(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft, const BlackMisc::CIdentifier &originator);

View File

@@ -62,6 +62,9 @@ namespace BlackCore
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"weatherGridReceived", this, SIGNAL(weatherGridReceived(BlackMisc::Weather::CWeatherGrid, BlackMisc::CIdentifier)));
Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"addingRemoteModelFailed", this, SIGNAL(addingRemoteModelFailed(BlackMisc::Simulation::CSimulatedAircraft,BlackMisc::CStatusMessage&)));
Q_ASSERT(s);
Q_UNUSED(s);
this->relayBaseClassSignals(serviceName, connection, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName());
}

View File

@@ -191,6 +191,9 @@ namespace BlackCore
//! Aircraft rendering changed
void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Adding the remote model failed
void physicallyAddingRemoteModelFailed(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::CStatusMessage &message);
//! An airspace snapshot was handled
void airspaceSnapshotHandled();

View File

@@ -73,7 +73,6 @@ namespace BlackSimPlugin
//! Set own model
void setOwnAircraftModel(const QString &modelName);
};
} // namespace
} // namespace

View File

@@ -158,13 +158,13 @@ namespace BlackSimPlugin
// create AI
bool adding = false;
const CAircraftModel aircraftModel = newRemoteAircraft.getModel();
CSimulatedAircraft remoteAircraftCopy(newRemoteAircraft);
CSimulatedAircraft addedAircraft(newRemoteAircraft);
if (isConnected())
{
// initial position
setInitialAircraftSituation(remoteAircraftCopy); // set interpolated data/parts if available
setInitialAircraftSituation(addedAircraft); // set interpolated data/parts if available
SIMCONNECT_DATA_INITPOSITION initialPosition = aircraftSituationToFsxInitPosition(remoteAircraftCopy.getSituation());
SIMCONNECT_DATA_INITPOSITION initialPosition = aircraftSituationToFsxInitPosition(addedAircraft.getSituation());
const QByteArray m = aircraftModel.getModelString().toLocal8Bit();
const int requestId = m_requestId;
@@ -172,7 +172,9 @@ namespace BlackSimPlugin
HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, m.constData(), qPrintable(callsign.toQString().left(12)), initialPosition, static_cast<SIMCONNECT_DATA_REQUEST_ID>(requestId));
if (hr != S_OK)
{
CLogMessage(this).error("SimConnect, can not create AI traffic: '%1' '%2'") << callsign.toQString() << aircraftModel.getModelString();
const CStatusMessage msg = CStatusMessage(this).error("SimConnect, can not create AI traffic: '%1' '%2'") << callsign.toQString() << aircraftModel.getModelString();
CLogMessage::preformatted(msg);
emit physicallyAddingRemoteModelFailed(addedAircraft, msg);
}
else
{
@@ -304,7 +306,10 @@ namespace BlackSimPlugin
CCallsignSet CSimulatorFsx::physicallyRenderedAircraft() const
{
return CCollection<CCallsign>(this->m_simConnectObjects.keys());
CCallsignSet callsigns(this->m_simConnectObjects.keys());
callsigns.push_back(m_aircraftToAddAgainWhenRemoved.getCallsigns()); // not really rendered right now, but very soon
callsigns.push_back(m_outOfRealityBubble.getCallsigns()); // not really rendered, but for the logic it should look like it is
return CCallsignSet(this->m_simConnectObjects.keys());
}
void CSimulatorFsx::setSimConnected()
@@ -950,6 +955,5 @@ namespace BlackSimPlugin
emit simulatorStarted(this->getPluginInfo());
}
}
} // namespace
} // namespace

View File

@@ -141,12 +141,15 @@ namespace BlackSimPlugin
case SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID:
{
SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *event = static_cast<SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *>(pData);
DWORD requestID = event->dwRequestID;
DWORD objectID = event->dwObjectID;
const DWORD requestID = event->dwRequestID;
const DWORD objectID = event->dwObjectID;
const bool success = simulatorFsx->aiAircraftWasAddedInSimulator(requestID, objectID);
if (!success)
{
CLogMessage(simulatorFsx).warning("Cannot find CSimConnectObject for request %1") << requestID;
const CSimulatedAircraft remoteAircraft(simulatorFsx->getSimObjectForObjectId(objectID).getAircraft());
const QString msg("Object id for request " + QString::number(requestID) + " not avialable");
emit simulatorFsx->physicallyAddingRemoteModelFailed(remoteAircraft, CStatusMessage(simulatorFsx, CStatusMessage::SeverityError, msg));
}
break;
}
@@ -246,6 +249,5 @@ namespace BlackSimPlugin
} // main switch
} // method
} // namespace
} // namespace