Fix clearing FlightPlan elements from Nasal.
Clearing the departure or destination elements, including the SID, STAR or approach to nil, now works, e.g: var fp = flightplan(); fp.departure = nil;
This commit is contained in:
parent
194d17ec94
commit
ddea3929f8
3 changed files with 79 additions and 12 deletions
|
@ -429,7 +429,7 @@ void FlightPlan::setDeparture(FGAirport* apt)
|
|||
_departureChanged = true;
|
||||
_departure = apt;
|
||||
_departureRunway = nullptr;
|
||||
setSID((SID*) nullptr);
|
||||
clearSID();
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
|
@ -445,11 +445,21 @@ void FlightPlan::setDeparture(FGRunway* rwy)
|
|||
_departureRunway = rwy;
|
||||
if (rwy->airport() != _departure) {
|
||||
_departure = rwy->airport();
|
||||
setSID((SID*)nullptr);
|
||||
clearSID();
|
||||
}
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
void FlightPlan::clearDeparture()
|
||||
{
|
||||
lockDelegates();
|
||||
_departureChanged = true;
|
||||
_departure = nullptr;
|
||||
_departureRunway = nullptr;
|
||||
clearSID();
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
void FlightPlan::setSID(SID* sid, const std::string& transition)
|
||||
{
|
||||
if (sid == _sid) {
|
||||
|
@ -476,6 +486,15 @@ void FlightPlan::setSID(Transition* trans)
|
|||
setSID((SID*) trans->parent(), trans->ident());
|
||||
}
|
||||
|
||||
void FlightPlan::clearSID()
|
||||
{
|
||||
lockDelegates();
|
||||
_departureChanged = true;
|
||||
_sid = nullptr;
|
||||
_sidTransition.clear();
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
Transition* FlightPlan::sidTransition() const
|
||||
{
|
||||
if (!_sid || _sidTransition.empty()) {
|
||||
|
@ -495,7 +514,7 @@ void FlightPlan::setDestination(FGAirport* apt)
|
|||
_arrivalChanged = true;
|
||||
_destination = apt;
|
||||
_destinationRunway = nullptr;
|
||||
setSTAR((STAR*)nullptr);
|
||||
clearSTAR();
|
||||
setApproach(nullptr);
|
||||
unlockDelegates();
|
||||
}
|
||||
|
@ -511,12 +530,23 @@ void FlightPlan::setDestination(FGRunway* rwy)
|
|||
_destinationRunway = rwy;
|
||||
if (_destination != rwy->airport()) {
|
||||
_destination = rwy->airport();
|
||||
setSTAR((STAR*)NULL);
|
||||
clearSTAR();
|
||||
}
|
||||
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
void FlightPlan::clearDestination()
|
||||
{
|
||||
lockDelegates();
|
||||
_arrivalChanged = true;
|
||||
_destination = nullptr;
|
||||
_destinationRunway = nullptr;
|
||||
clearSTAR();
|
||||
setApproach(nullptr);
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
void FlightPlan::setSTAR(STAR* star, const std::string& transition)
|
||||
{
|
||||
if (_star == star) {
|
||||
|
@ -543,6 +573,16 @@ void FlightPlan::setSTAR(Transition* trans)
|
|||
setSTAR((STAR*) trans->parent(), trans->ident());
|
||||
}
|
||||
|
||||
void FlightPlan::clearSTAR()
|
||||
{
|
||||
|
||||
lockDelegates();
|
||||
_arrivalChanged = true;
|
||||
_star = nullptr;
|
||||
_starTransition.clear();
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
Transition* FlightPlan::starTransition() const
|
||||
{
|
||||
if (!_star || _starTransition.empty()) {
|
||||
|
|
|
@ -185,6 +185,8 @@ public:
|
|||
void setDeparture(FGAirport* apt);
|
||||
void setDeparture(FGRunway* rwy);
|
||||
|
||||
void clearDeparture();
|
||||
|
||||
SID* sid() const
|
||||
{ return _sid; }
|
||||
|
||||
|
@ -194,9 +196,13 @@ public:
|
|||
|
||||
void setSID(Transition* sidWithTrans);
|
||||
|
||||
void clearSID();
|
||||
|
||||
void setDestination(FGAirport* apt);
|
||||
void setDestination(FGRunway* rwy);
|
||||
|
||||
void clearDestination();
|
||||
|
||||
/**
|
||||
* note setting an approach will implicitly update the destination
|
||||
* airport and runway to match
|
||||
|
@ -212,6 +218,8 @@ public:
|
|||
|
||||
void setSTAR(Transition* starWithTrans);
|
||||
|
||||
void clearSTAR();
|
||||
|
||||
double totalDistanceNm() const
|
||||
{ return _totalDistance; }
|
||||
|
||||
|
|
|
@ -615,10 +615,10 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
|||
}
|
||||
|
||||
if (naIsNil(value)) {
|
||||
fp->setDeparture(static_cast<FGAirport*>(NULL));
|
||||
fp->clearDeparture();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
naRuntimeError(c, "bad argument type setting departure");
|
||||
} else if (!strcmp(fieldName, "destination")) {
|
||||
FGAirport* apt = airportGhost(value);
|
||||
|
@ -633,6 +633,11 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
|||
return;
|
||||
}
|
||||
|
||||
if (naIsNil(value)) {
|
||||
fp->clearDestination();
|
||||
return;
|
||||
}
|
||||
|
||||
naRuntimeError(c, "bad argument type setting destination");
|
||||
} else if (!strcmp(fieldName, "departure_runway")) {
|
||||
FGRunway* rwy = runwayGhost(value);
|
||||
|
@ -661,13 +666,18 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
|||
fp->setSID((Transition*) proc);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (naIsString(value)) {
|
||||
FGAirport* apt = fp->departureAirport();
|
||||
fp->setSID(apt->findSIDWithIdent(naStr_data(value)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (naIsNil(value)) {
|
||||
fp->clearSID();
|
||||
return;
|
||||
}
|
||||
|
||||
naRuntimeError(c, "bad argument type setting SID");
|
||||
} else if (!strcmp(fieldName, "star")) {
|
||||
Procedure* proc = procedureGhost(value);
|
||||
|
@ -687,6 +697,11 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
|||
return;
|
||||
}
|
||||
|
||||
if (naIsNil(value)) {
|
||||
fp->clearSTAR();
|
||||
return;
|
||||
}
|
||||
|
||||
naRuntimeError(c, "bad argument type setting STAR");
|
||||
} else if (!strcmp(fieldName, "approach")) {
|
||||
Procedure* proc = procedureGhost(value);
|
||||
|
@ -701,17 +716,21 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
|||
return;
|
||||
}
|
||||
|
||||
if (naIsNil(value)) {
|
||||
fp->setApproach(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
naRuntimeError(c, "bad argument type setting approach");
|
||||
} else if (!strcmp(fieldName, "aircraftCategory")) {
|
||||
if (!naIsString(value)) naRuntimeError(c, "aircraftCategory must be a string");
|
||||
fp->setIcaoAircraftCategory(naStr_data(value));
|
||||
if (!naIsString(value)) naRuntimeError(c, "aircraftCategory must be a string");
|
||||
fp->setIcaoAircraftCategory(naStr_data(value));
|
||||
} else if (!strcmp(fieldName, "followLegTrackToFix")) {
|
||||
int b = (int) value.num;
|
||||
fp->setFollowLegTrackToFixes(b);
|
||||
int b = (int) value.num;
|
||||
fp->setFollowLegTrackToFixes(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static naRef procedureTpType(naContext c, ProcedureType ty)
|
||||
{
|
||||
switch (ty) {
|
||||
|
|
Loading…
Add table
Reference in a new issue