Skip to content

Commit

Permalink
Refactoring and cleanup in BGL reading code
Browse files Browse the repository at this point in the history
  • Loading branch information
albar965 committed Dec 23, 2024
1 parent 95a1c2f commit d775841
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 59 deletions.
79 changes: 41 additions & 38 deletions src/fs/bgl/ap/airport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Airport::Airport(const NavDatabaseOptions *options, BinaryStream *stream, atools
return;
}

region = converter::intToIcao(stream->readUInt()); // TODO wiki is always null
region = converter::intToIcao(stream->readUInt()); // Always null

fuelFlags = static_cast<ap::FuelFlags>(stream->readUInt());

Expand Down Expand Up @@ -432,7 +432,7 @@ Airport::Airport(const NavDatabaseOptions *options, BinaryStream *stream, atools
updateTaxiPaths(taxipoints, taxinames);

// Set the jetway flag on parking
updateParking(jetways, parkingNumberIndex);
updateJetwayParking(jetways, parkingNumberIndex);

removeVehicleParking();

Expand Down Expand Up @@ -650,41 +650,41 @@ void Airport::updateSummaryFields()
}
}

for(const Parking& p : qAsConst(parkings))
for(const Parking& parking : qAsConst(parkings))
{
reportFarCoordinate(p.getPosition().getPos(), "parking");
points.append(p.getPosition().getPos());
reportFarCoordinate(parking.getPosition().getPos(), "parking");
points.append(parking.getPosition().getPos());

// Assign fuel from parking if not set in flags
// https://devsupport.flightsimulator.com/questions/10232/su10-u3-removed-fuel-flags-from-bgl-files.html
if(p.isFuel() && msfs && fuelFlags == ap::NO_FUEL_FLAGS)
if(parking.isFuel() && msfs && fuelFlags == ap::NO_FUEL_FLAGS)
fuelFlags = atools::fs::bgl::ap::MSFS_DEFAULT_FUEL;

if(p.hasJetway())
if(parking.hasJetway())
numJetway++;

if(p.isGate())
if(parking.isGate())
{
numParkingGate++;

if(largestParkingGate == ap::UNKNOWN || largestParkingGate < p.getType())
largestParkingGate = p.getType();
if(largestParkingGate == ap::UNKNOWN || largestParkingGate < parking.getType())
largestParkingGate = parking.getType();
}

if(p.isGaRamp())
if(parking.isGaRamp())
{
numParkingGaRamp++;
if(largestParkingGaRamp == ap::UNKNOWN || largestParkingGaRamp < p.getType())
largestParkingGaRamp = p.getType();
if(largestParkingGaRamp == ap::UNKNOWN || largestParkingGaRamp < parking.getType())
largestParkingGaRamp = parking.getType();
}

if(p.getType() == ap::RAMP_CARGO)
if(parking.getType() == ap::RAMP_CARGO)
numParkingCargo++;

if(p.getType() == ap::RAMP_MIL_CARGO)
if(parking.getType() == ap::RAMP_MIL_CARGO)
numParkingMilitaryCargo++;

if(p.getType() == ap::RAMP_MIL_COMBAT)
if(parking.getType() == ap::RAMP_MIL_COMBAT)
numParkingMilitaryCombat++;
}

Expand Down Expand Up @@ -734,24 +734,24 @@ void Airport::updateSummaryFields()
boundingRect = atools::geo::bounding(points);
}

void Airport::updateParking(const QList<atools::fs::bgl::Jetway>& jetways,
const QHash<ParkingKey, int>& parkingNumberIndex)
void Airport::updateJetwayParking(const QList<atools::fs::bgl::Jetway>& jetways,
const QHash<ParkingKey, int>& parkingNumberIndex)
{
for(const Jetway& jw : jetways)
for(const Jetway& jetway : jetways)
{
int index = parkingNumberIndex.value({jw.getParkingNumber(), jw.getGateName()}, -1);
int index = parkingNumberIndex.value({jetway.getParkingNumber(), jetway.getGateName()}, -1);

if(index != -1 && index < parkings.size())
{
if(parkings.at(index).jetway)
qWarning().nospace().noquote() << Q_FUNC_INFO << "Parking for jetway " << jw << " already set" << dec
qWarning().nospace().noquote() << Q_FUNC_INFO << "Parking for jetway " << jetway << " already set" << dec
<< " for parking " << parkings.at(index)
<< " for ident " << ident;
else
parkings[index].jetway = true;
}
else
qWarning().nospace().noquote() << Q_FUNC_INFO << "Parking for jetway " << jw << " not found" << dec
qWarning().nospace().noquote() << Q_FUNC_INFO << "Parking for jetway " << jetway << " not found" << dec
<< " for ident " << ident;
}
}
Expand All @@ -763,8 +763,7 @@ void Airport::updateHelipads()
int startIdx = 1;
for(const Start& start : qAsConst(starts))
{
if(start.getPosition().getPos().almostEqual(helipad.getPosition().getPos(),
atools::geo::Pos::POS_EPSILON_5M))
if(start.getPosition().getPos().almostEqual(helipad.getPosition().getPos(), atools::geo::Pos::POS_EPSILON_5M))
helipad.setStartIndex(startIdx);
startIdx++;
}
Expand All @@ -787,15 +786,17 @@ void Airport::updateTaxiPaths(const QList<TaxiPoint>& taxipoints, const QStringL
{
switch(taxiPath.type)
{
case atools::fs::bgl::taxipath::UNKNOWN:
case atools::fs::bgl::taxipath::CLOSED:
case atools::fs::bgl::taxipath::VEHICLE:
case atools::fs::bgl::taxipath::RUNWAY:
case taxipath::UNKNOWN:
case taxipath::CLOSED:
case taxipath::VEHICLE:
case taxipath::RUNWAY:
case taxipath::ROAD:
case taxipath::PAINTEDLINE:
break;

case atools::fs::bgl::taxipath::PATH:
case atools::fs::bgl::taxipath::TAXI:
case atools::fs::bgl::taxipath::PARKING:
case taxipath::PATH:
case taxipath::TAXI:
case taxipath::PARKING:
if(inRange(taxinames, taxiPath.nameIndex))
taxiPath.taxiName = taxinames.at(taxiPath.nameIndex);
else
Expand All @@ -810,22 +811,24 @@ void Airport::updateTaxiPaths(const QList<TaxiPoint>& taxipoints, const QStringL
{
switch(taxiPath.type)
{
case atools::fs::bgl::taxipath::UNKNOWN:
case atools::fs::bgl::taxipath::CLOSED:
case atools::fs::bgl::taxipath::VEHICLE:
case atools::fs::bgl::taxipath::RUNWAY:
case taxipath::UNKNOWN:
case taxipath::CLOSED:
case taxipath::VEHICLE:
case taxipath::RUNWAY:
case taxipath::ROAD:
case taxipath::PAINTEDLINE:
break;

case atools::fs::bgl::taxipath::PATH:
case atools::fs::bgl::taxipath::TAXI:
case taxipath::PATH:
case taxipath::TAXI:
if(inRange(taxipoints, taxiPath.startIndex) && inRange(taxipoints, taxiPath.endIndex))
{
taxiPath.startPos = taxipoints.at(taxiPath.startIndex);
taxiPath.endPos = taxipoints.at(taxiPath.endIndex);
}
break;

case atools::fs::bgl::taxipath::PARKING:
case taxipath::PARKING:
if(inRange(taxipoints, taxiPath.startIndex) && inRange(parkings, taxiPath.endIndex))
{
taxiPath.startPos = taxipoints.at(taxiPath.startIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/fs/bgl/ap/airport.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class Airport :
friend QDebug operator<<(QDebug out, const atools::fs::bgl::Airport& record);

void updateTaxiPaths(const QList<TaxiPoint>& taxipoints, const QStringList& taxinames);
void updateParking(const QList<atools::fs::bgl::Jetway>& jetways,
void updateJetwayParking(const QList<atools::fs::bgl::Jetway>& jetways,
const QHash<atools::fs::bgl::ParkingKey, int>& parkingNumberIndex);
void updateSummaryFields();
void removeVehicleParking();
Expand Down
2 changes: 1 addition & 1 deletion src/fs/bgl/ap/helipad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Helipad::Helipad(const NavDatabaseOptions *options, BinaryStream *stream)
position = BglPosition(stream, true, 1000.f);
length = stream->readFloat();
width = stream->readFloat();
heading = stream->readFloat(); // TODO wiki heading is float degrees
heading = stream->readFloat(); // Heading is float degrees
}

QDebug operator<<(QDebug out, const Helipad& record)
Expand Down
2 changes: 1 addition & 1 deletion src/fs/bgl/ap/parking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Parking::Parking(BinaryStream *stream, atools::fs::bgl::StructureType structureT
int numAirlineCodes = (flags >> 24) & 0xff;

radius = stream->readFloat();
heading = stream->readFloat(); // TODO wiki heading is float degrees
heading = stream->readFloat(); // Heading is float degrees

if(structureType == STRUCT_FSX || structureType == STRUCT_P3DV4 || structureType == STRUCT_P3DV5 || structureType == STRUCT_MSFS)
stream->skip(16); // teeOffset 1-4 not FS9
Expand Down
2 changes: 1 addition & 1 deletion src/fs/bgl/ap/rw/runwayapplights.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum ApproachLightSystem
MALS = 0x0b,
SALS = 0x0c,
SSALS = 0x0d,
SALSF = 0x0e // TODO add to wiki
SALSF = 0x0e
};

} // namespace rw
Expand Down
4 changes: 2 additions & 2 deletions src/fs/bgl/ap/taxipoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ enum PointType
NORMAL = 1,
HOLD_SHORT = 2,
ILS_HOLD_SHORT = 4,
HOLD_SHORT_NO_DRAW = 5, // TODO wiki add
ILS_HOLD_SHORT_NO_DRAW = 6, // TODO wiki add
HOLD_SHORT_NO_DRAW = 5,
ILS_HOLD_SHORT_NO_DRAW = 6,
PARKING /* not a BGL type */
};

Expand Down
1 change: 0 additions & 1 deletion src/fs/bgl/nav/marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ QString Marker::getObjectName() const
Marker::Marker(const NavDatabaseOptions *options, BinaryStream *stream)
: Record(options, stream)
{
// TODO wiki clarify structure
heading = static_cast<float>(stream->readUByte()) / 255.f * 360.f;
type = static_cast<nav::MarkerType>(stream->readUByte());

Expand Down
3 changes: 1 addition & 2 deletions src/fs/bgl/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ bool Record::checkSubRecord(const Record& r)
{
if(r.getSize() == 0)
{
qWarning().nospace().noquote() << "Ignoring airport. Size of record is zero. 0x"
<< hex << r.getId<int>() << dec << getObjectName();
qWarning().nospace().noquote() << "Ignoring record. Size of record is zero. 0x" << hex << r.getId<int>() << dec << getObjectName();

// Stop reading when the first subrecord is already invalid
seekToStart();
Expand Down
4 changes: 2 additions & 2 deletions src/fs/bgl/surface.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2020 Alexander Barthel [email protected]
* Copyright 2015-2024 Alexander Barthel [email protected]
*
* 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
Expand Down Expand Up @@ -30,7 +30,7 @@ enum Surface
CONCRETE = 0x0000,
GRASS = 0x0001,
WATER = 0x0002,
CEMENT = 0x0003, // TODO wiki error report
CEMENT = 0x0003,
ASPHALT = 0x0004,
// GRASS = 0x0005, invalid ADE interprets it as grass
CLAY = 0x0007,
Expand Down
5 changes: 2 additions & 3 deletions src/fs/common/metadatawriter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2020 Alexander Barthel [email protected]
* Copyright 2015-2024 Alexander Barthel [email protected]
*
* 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
Expand Down Expand Up @@ -59,8 +59,7 @@ void MetadataWriter::writeSceneryArea(const QString& filepath, const QString& sc
insertSceneryQuery->bindValue(":number", curSceneryId);
insertSceneryQuery->bindValue(":layer", curSceneryId);
insertSceneryQuery->bindValue(":title", sceneryName);
insertSceneryQuery->bindValue(":local_path", filepath.isEmpty() ?
QVariant(QVariant::String) : QFileInfo(filepath).filePath());
insertSceneryQuery->bindValue(":local_path", filepath.isEmpty() ? QVariant(QVariant::String) : QFileInfo(filepath).filePath());
insertSceneryQuery->bindValue(":active", true);
insertSceneryQuery->bindValue(":required", true);
insertSceneryQuery->exec();
Expand Down
4 changes: 2 additions & 2 deletions src/fs/db/ap/airportwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ void AirportWriter::writeObject(const Airport *type)
}
else
{
bind(":longest_runway_length", 0.f);
bind(":longest_runway_width", 0.f);
bind(":longest_runway_length", 0);
bind(":longest_runway_width", 0);
bind(":longest_runway_heading", 0.f);
bind(":longest_runway_surface", surfaceToDbStr(atools::fs::bgl::UNKNOWN));
}
Expand Down
4 changes: 2 additions & 2 deletions src/fs/db/ap/startwriter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2020 Alexander Barthel [email protected]
* Copyright 2015-2024 Alexander Barthel [email protected]
*
* 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
Expand Down Expand Up @@ -56,7 +56,7 @@ void StartWriter::writeObject(const Start *type)
else
bindNullInt(":number");

// TODO comment in wiki: helipads have no runway
// Helipads have no runway
if(!apIdent.isEmpty() && type->getType() != bgl::start::HELIPAD)
{
// Get associated runway for start position
Expand Down
26 changes: 23 additions & 3 deletions src/io/binarystream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ quint32 BinaryStream::readUInt()
return retval;
}

quint64 BinaryStream::readULong()
{
quint64 retval;
is >> retval;

checkStream("readLong");

return retval;
}

int BinaryStream::readBytes(char bytes[], int size)
{
int numRead = is.readRawData(bytes, size);
Expand Down Expand Up @@ -138,6 +148,16 @@ quint8 BinaryStream::readUByte()
return retval;
}

qint16 BinaryStream::readShort()
{
qint16 retval;
is >> retval;

checkStream("readShort");

return retval;
}

qint32 BinaryStream::readInt()
{
qint32 retval;
Expand All @@ -148,12 +168,12 @@ qint32 BinaryStream::readInt()
return retval;
}

qint16 BinaryStream::readShort()
qint64 BinaryStream::readLong()
{
qint16 retval;
qint64 retval;
is >> retval;

checkStream("readShort");
checkStream("readLong");

return retval;
}
Expand Down
2 changes: 2 additions & 0 deletions src/io/binarystream.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ class BinaryStream
qint8 readByte();
qint16 readShort();
qint32 readInt();
qint64 readLong();

quint8 readUByte();
quint16 readUShort();
quint32 readUInt();
quint64 readULong();

float readFloat();

Expand Down

0 comments on commit d775841

Please sign in to comment.