Launcher shows polygon/polyline data
This commit is contained in:
parent
e52e20b54f
commit
bfb539f090
3 changed files with 118 additions and 4 deletions
|
@ -30,6 +30,7 @@
|
|||
#include <Navaids/navrecord.hxx>
|
||||
#include <Navaids/positioned.hxx>
|
||||
#include <Airports/airport.hxx>
|
||||
#include <Navaids/PolyLine.hxx>
|
||||
|
||||
#include "QtLauncher_fwd.hxx"
|
||||
|
||||
|
@ -112,6 +113,8 @@ void BaseDiagram::paintEvent(QPaintEvent* pe)
|
|||
QTransform t(transform());
|
||||
p.setTransform(t);
|
||||
|
||||
paintCoastlines(&p);
|
||||
|
||||
paintNavaids(&p);
|
||||
|
||||
paintContents(&p);
|
||||
|
@ -132,6 +135,81 @@ void BaseDiagram::paintAirplaneIcon(QPainter* painter, const SGGeod& geod, int h
|
|||
painter->drawPixmap(airplaneIconRect, pix);
|
||||
}
|
||||
|
||||
void BaseDiagram::paintCoastlines(QPainter* painter)
|
||||
{
|
||||
QTransform xf = painter->transform();
|
||||
QTransform invT = xf.inverted();
|
||||
|
||||
SGGeod topLeft = unproject(invT.map(rect().topLeft()), m_projectionCenter);
|
||||
SGGeod viewCenter = unproject(invT.map(rect().center()), m_projectionCenter);
|
||||
SGGeod bottomRight = unproject(invT.map(rect().bottomRight()), m_projectionCenter);
|
||||
|
||||
double drawRangeNm = std::max(SGGeodesy::distanceNm(viewCenter, topLeft),
|
||||
SGGeodesy::distanceNm(viewCenter, bottomRight));
|
||||
|
||||
flightgear::PolyLineList lines(flightgear::PolyLine::linesNearPos(viewCenter, drawRangeNm,
|
||||
flightgear::PolyLine::COASTLINE));
|
||||
|
||||
QPen waterPen(QColor(64, 64, 255), 1);
|
||||
waterPen.setCosmetic(true);
|
||||
painter->setPen(waterPen);
|
||||
flightgear::PolyLineList::const_iterator it;
|
||||
for (it=lines.begin(); it != lines.end(); ++it) {
|
||||
paintGeodVec(painter, (*it)->points());
|
||||
}
|
||||
|
||||
lines = flightgear::PolyLine::linesNearPos(viewCenter, drawRangeNm,
|
||||
flightgear::PolyLine::URBAN);
|
||||
for (it=lines.begin(); it != lines.end(); ++it) {
|
||||
fillClosedGeodVec(painter, QColor(192, 192, 96), (*it)->points());
|
||||
}
|
||||
|
||||
lines = flightgear::PolyLine::linesNearPos(viewCenter, drawRangeNm,
|
||||
flightgear::PolyLine::RIVER);
|
||||
|
||||
painter->setPen(waterPen);
|
||||
for (it=lines.begin(); it != lines.end(); ++it) {
|
||||
paintGeodVec(painter, (*it)->points());
|
||||
}
|
||||
|
||||
|
||||
lines = flightgear::PolyLine::linesNearPos(viewCenter, drawRangeNm,
|
||||
flightgear::PolyLine::LAKE);
|
||||
|
||||
for (it=lines.begin(); it != lines.end(); ++it) {
|
||||
fillClosedGeodVec(painter, QColor(128, 128, 255),
|
||||
(*it)->points());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void BaseDiagram::paintGeodVec(QPainter* painter, const flightgear::SGGeodVec& vec)
|
||||
{
|
||||
QVector<QPointF> projected;
|
||||
projected.reserve(vec.size());
|
||||
flightgear::SGGeodVec::const_iterator it;
|
||||
for (it=vec.begin(); it != vec.end(); ++it) {
|
||||
projected.append(project(*it));
|
||||
}
|
||||
|
||||
painter->drawPolyline(projected.data(), projected.size());
|
||||
}
|
||||
|
||||
void BaseDiagram::fillClosedGeodVec(QPainter* painter, const QColor& color, const flightgear::SGGeodVec& vec)
|
||||
{
|
||||
QVector<QPointF> projected;
|
||||
projected.reserve(vec.size());
|
||||
flightgear::SGGeodVec::const_iterator it;
|
||||
for (it=vec.begin(); it != vec.end(); ++it) {
|
||||
projected.append(project(*it));
|
||||
}
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(color);
|
||||
painter->drawPolygon(projected.data(), projected.size());
|
||||
}
|
||||
|
||||
class MapFilter : public FGPositioned::TypeFilter
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <Navaids/positioned.hxx>
|
||||
#include <Airports/airport.hxx>
|
||||
#include <Navaids/PolyLine.hxx>
|
||||
|
||||
#include "QtLauncher_fwd.hxx"
|
||||
|
||||
|
@ -128,6 +129,9 @@ private:
|
|||
void paintNavaid(QPainter *painter,
|
||||
const QTransform& t,
|
||||
const FGPositionedRef &pos);
|
||||
void paintCoastlines(QPainter *painter);
|
||||
void paintGeodVec(QPainter *painter, const flightgear::SGGeodVec &vec);
|
||||
void fillClosedGeodVec(QPainter *painter, const QColor &color, const flightgear::SGGeodVec &vec);
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BaseDiagram::IconOptions)
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include <Main/globals.hxx>
|
||||
#include <Navaids/NavDataCache.hxx>
|
||||
#include <Navaids/navrecord.hxx>
|
||||
#include <Navaids/SHPParser.hxx>
|
||||
|
||||
#include <Main/options.hxx>
|
||||
#include <Main/fg_init.hxx>
|
||||
|
@ -344,12 +345,41 @@ void initApp(int& argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
void loadNaturalEarthFile(const std::string& aFileName,
|
||||
flightgear::PolyLine::Type aType,
|
||||
bool areClosed)
|
||||
{
|
||||
SGPath path(globals->get_fg_root());
|
||||
path.append( "Geodata" );
|
||||
path.append(aFileName);
|
||||
flightgear::PolyLineList lines;
|
||||
flightgear::SHPParser::parsePolyLines(path, aType, lines, areClosed);
|
||||
flightgear::PolyLineList::iterator it;
|
||||
for (it=lines.begin(); it != lines.end(); ++it) {
|
||||
(*it)->addToSpatialIndex();
|
||||
}
|
||||
}
|
||||
|
||||
void loadNaturalEarthData()
|
||||
{
|
||||
SGTimeStamp st;
|
||||
st.stamp();
|
||||
|
||||
loadNaturalEarthFile("ne_10m_coastline.shp", flightgear::PolyLine::COASTLINE, false);
|
||||
loadNaturalEarthFile("ne_10m_rivers_lake_centerlines.shp", flightgear::PolyLine::RIVER, false);
|
||||
loadNaturalEarthFile("ne_10m_lakes.shp", flightgear::PolyLine::LAKE, true);
|
||||
|
||||
qDebug() << "load basic data took" << st.elapsedMSec();
|
||||
|
||||
|
||||
st.stamp();
|
||||
loadNaturalEarthFile("ne_10m_urban_areas.shp", flightgear::PolyLine::URBAN, true);
|
||||
|
||||
qDebug() << "loading urban areas took:" << st.elapsedMSec();
|
||||
}
|
||||
|
||||
bool runLauncherDialog()
|
||||
{
|
||||
sglog().setLogLevels( SG_ALL, SG_INFO );
|
||||
|
||||
initQtResources(); // can't be called inside a namespaceb
|
||||
|
||||
// startup the nav-cache now. This pre-empts normal startup of
|
||||
// the cache, but no harm done. (Providing scenery paths are consistent)
|
||||
|
||||
|
@ -364,6 +394,8 @@ bool runLauncherDialog()
|
|||
// will happen as normal
|
||||
http->init();
|
||||
|
||||
loadNaturalEarthData();
|
||||
|
||||
// setup scenery paths now, especially TerraSync path for airport
|
||||
// parking locations (after they're downloaded)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue