400 lines
15 KiB
C++
Executable File
400 lines
15 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* main
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include <nglapplication/nglapplication.h>
|
|
#include <NGLLogger/INGLLogger.h>
|
|
|
|
#include "../plan_editor.h"
|
|
|
|
#include <LtsWidgets/lts_base_layout_widget.h>
|
|
#include <LtsWidgets/lts_tab_widget.h>
|
|
#include <LtsPluginManager/lts_plugin_loader.h>
|
|
#include <PluginInterfaces/style_plugin_interface.h>
|
|
#include <PluginInterfaces/project_plugin_interface.h>
|
|
|
|
|
|
#include <Map/map.h>
|
|
#include <Map/grid.h>
|
|
|
|
#include <Rubberbands/rubberband_drawable.h>
|
|
|
|
#include <QtCore/QDir>
|
|
#include <QtCore/QPointer>
|
|
#include <QtCore/QStandardPaths>
|
|
|
|
#include <QtWidgets/QMainWindow>
|
|
#include <QtWidgets/QDesktopWidget>
|
|
#include <QtWidgets/QHBoxLayout>
|
|
#include <QtWidgets/QMessageBox>
|
|
#include <QtWidgets/QLabel>
|
|
|
|
#include <Map/object_factory.h>
|
|
#include <Map/map_initializer.h>
|
|
|
|
#include <MapObjectsImpl/polygon_impl.h>
|
|
#include <MapObjectsImpl/polyline_impl.h>
|
|
#include <MapObjectsImpl/text_impl.h>
|
|
#include <MapObjectsImpl/area_fire_impl.h>
|
|
#include <MapObjectsImpl/biological_agent_impl.h>
|
|
#include <MapObjectsImpl/chemical_agent_impl.h>
|
|
#include <MapObjectsImpl/building_outline_impl.h>
|
|
#include <MapObjectsImpl/danger_area_impl.h>
|
|
#include <MapObjectsImpl/functional_area_impl.h>
|
|
#include <MapObjectsImpl/geo_image_impl.h>
|
|
#include <MapObjectsImpl/hit_line_impl.h>
|
|
#include <MapObjectsImpl/map_object_indicator_impl.h>
|
|
#include <MapObjectsImpl/mine_impl.h>
|
|
#include <MapObjectsImpl/mine_field_impl.h>
|
|
#include <MapObjectsImpl/nuclear_agent_impl.h>
|
|
#include <MapObjectsImpl/participant_impl.h>
|
|
#include <MapObjectsImpl/single_fire_impl.h>
|
|
|
|
#include <MapImpl/sidc_symbol_impl.h>
|
|
#include <MapImpl/sight_fan_impl.h>
|
|
|
|
#include<Symbology/sidc_codec.h>
|
|
#include<Symbology/sidc_builder.h>
|
|
|
|
#include <FunctionDialog/function_dialog.h> // only for debug purpose
|
|
#include <iostream>
|
|
|
|
|
|
class MapInitializer : public SituationMap::MapInitializer
|
|
{
|
|
Q_OBJECT
|
|
|
|
typedef SituationMap::MapInitializer BaseClass;
|
|
|
|
public:
|
|
|
|
explicit MapInitializer( SituationMap::Map & map
|
|
, SituationMap::MapSettings & mapSettings
|
|
, const QString & debugName
|
|
, QObject *parent = nullptr) : BaseClass(map, mapSettings, debugName, parent), m_useSymbologyFromInitFile(true) {}
|
|
|
|
bool initializeObjectFactory() override
|
|
{
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::MapObjectIndicator), new SituationMap::GenericObjectFactory<SituationMap::MapObjectIndicatorImpl>() );
|
|
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::Polygon), new SituationMap::GenericObjectFactory<SituationMap::PolygonImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::Polyline), new SituationMap::GenericObjectFactory<SituationMap::PolylineImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::Text), new SituationMap::GenericObjectFactory<SituationMap::TextImpl>() );
|
|
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::Participant), new SituationMap::GenericObjectFactory<SituationMap::ParticipantImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::AreaFire), new SituationMap::GenericObjectFactory<SituationMap::AreaFireImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::BiologicalAgent), new SituationMap::GenericObjectFactory<SituationMap::BiologicalAgentImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::ChemicalAgent), new SituationMap::GenericObjectFactory<SituationMap::ChemicalAgentImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::BuildingOutline), new SituationMap::GenericObjectFactory<SituationMap::BuildingOutlineImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::DangerArea), new SituationMap::GenericObjectFactory<SituationMap::DangerAreaImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::FunctionalArea), new SituationMap::GenericObjectFactory<SituationMap::FunctionalAreaImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::GeoImage), new SituationMap::GenericObjectFactory<SituationMap::GeoImageImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::HitLine), new SituationMap::GenericObjectFactory<SituationMap::HitLineImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::Mine), new SituationMap::GenericObjectFactory<SituationMap::MineImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::MineField), new SituationMap::GenericObjectFactory<SituationMap::MineFieldImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::NuclearAgent), new SituationMap::GenericObjectFactory<SituationMap::NuclearAgentImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::SingleFire), new SituationMap::GenericObjectFactory<SituationMap::SingleFireImpl>() );
|
|
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::SidcSymbol), new SituationMap::GenericObjectFactory<SituationMap::SidcSymbolImpl>() );
|
|
SituationMap::ObjectFactory::registerMe(typeid(SituationMap::SightFan), new SituationMap::GenericObjectFactory<SituationMap::SightFanImpl>());
|
|
|
|
return true;
|
|
} // initializeObjectFactory()
|
|
|
|
|
|
AdvancedSymbology::SymbologyType symbologyType() const override
|
|
{
|
|
return (m_useSymbologyFromInitFile) ? SituationMap::MapInitializer::symbologyType() : m_symbologyType;
|
|
} // symbologyType
|
|
|
|
|
|
void setSymbologyType( AdvancedSymbology::SymbologyType symbologyType )
|
|
{
|
|
m_symbologyType = symbologyType;
|
|
m_useSymbologyFromInitFile = false;
|
|
}
|
|
|
|
protected :
|
|
|
|
bool m_useSymbologyFromInitFile;
|
|
AdvancedSymbology::SymbologyType m_symbologyType = AdvancedSymbology::SymbologyType::APP6B;
|
|
|
|
void onMapReady() override
|
|
{
|
|
BaseClass::onMapReady();
|
|
|
|
m_map.setExtent(-100000, -100000, 100000, 100000);
|
|
m_map.setMinScale(1000000000);
|
|
m_map.setMaxScale(100);
|
|
m_map.setRotation(0.0);
|
|
|
|
// own things should be added here
|
|
} // onMapReady()
|
|
|
|
}; // MapInitializer
|
|
|
|
#define USE_BASE_LAYOUT
|
|
|
|
class TestMainWindow : public QMainWindow
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestMainWindow( AdvancedSymbology::SymbologyType * symbolLib = nullptr) : QMainWindow(), m_planEdit(nullptr), m_logger(SituationMap::getLogger("PlanEditorTestMainWindow"))
|
|
{
|
|
QString title = QStringLiteral("PlanEditor Test Application");
|
|
setWindowTitle( title );
|
|
|
|
#ifdef USE_BASE_LAYOUT
|
|
|
|
// Todo: Uncomment false:
|
|
m_baseLay = new LtsWidgets::LtsBaseLayoutWidget(this);
|
|
setCentralWidget( m_baseLay );
|
|
|
|
m_mainTab = m_baseLay->getTabFromLayoutArea(LtsWidgets::LayoutArea::eMainTab);
|
|
m_dw = m_baseLay->getMenu();
|
|
|
|
m_map = SituationMap::Map::create(this);
|
|
|
|
QHBoxLayout * layout = new QHBoxLayout();
|
|
layout->addWidget(m_map);
|
|
delete m_mainTab->layout();
|
|
m_mainTab->setLayout(layout);
|
|
m_mainTab->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
|
|
const QString & iniFileName = QStringLiteral("plan_editor_map_defaults.ini");
|
|
QString initFilePath = QStandardPaths::locate(QStandardPaths::HomeLocation, iniFileName, QStandardPaths::LocateFile); // find map defaults in Home
|
|
|
|
if (initFilePath.isEmpty()) initFilePath = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, iniFileName, QStandardPaths::LocateFile); // if not look into the AppData Location
|
|
if (initFilePath.isEmpty()) initFilePath = QCoreApplication::applicationDirPath() + QLatin1String("/") + iniFileName; // still not found? last try AppDir
|
|
|
|
if (!QFile::exists(initFilePath))
|
|
FATAL_LOG(m_logger) << LOGFUNCTION << " MapIniFile location Failed";
|
|
else
|
|
DEBUG_LOG(m_logger) << LOGFUNCTION << " MapIniFile found: " << initFilePath;
|
|
|
|
SituationMap::MapSettings * mapSettings = new SituationMap::MapSettings(initFilePath, m_map);
|
|
MapInitializer *mapInitializer = new MapInitializer(*m_map, *mapSettings, QLatin1String("PlanEditorTest"), m_map);
|
|
|
|
if (mapInitializer->hasErrors())
|
|
{
|
|
FATAL_LOG(m_logger) << LOGFUNCTION << " MapInitializer-filename='" << mapInitializer->filename()
|
|
<< "'' has following errors: "
|
|
<< " exists = " << mapInitializer->exists()
|
|
<< " accessError = " << mapInitializer->accessError()
|
|
<< " formatError = " << mapInitializer->formatError() ;
|
|
m_map->deleteLater();;
|
|
m_map = nullptr;
|
|
return;
|
|
}
|
|
|
|
else
|
|
{
|
|
if (symbolLib) mapInitializer->setSymbologyType( *symbolLib );
|
|
else mapInitializer->setSymbologyType( AdvancedSymbology::SymbologyType::MIL2525D );
|
|
if (!mapInitializer->initMap(SituationMap::Mode::Mode_2D))
|
|
{
|
|
QMessageBox::critical(this, title, tr("Init situation map failed. Abort ..."));
|
|
m_map->deleteLater();;
|
|
m_map = nullptr;
|
|
return;
|
|
}
|
|
}
|
|
|
|
m_planEdit = new PlanEditor::PlanEditor( m_map, m_baseLay );
|
|
|
|
connect( m_planEdit.data(), &PlanEditor::PlanEditor::quitPlanEditor, this, [this]()
|
|
{
|
|
m_planEdit -> deleteLater();
|
|
m_planEdit.clear();
|
|
|
|
close(); // By by TestMainWindow
|
|
} );
|
|
|
|
#else
|
|
m_map = SituationMap::Map::create(this);
|
|
QSplitter * splitter = new QSplitter(this);
|
|
QLabel * label = new QLabel("Moin World"), this;
|
|
|
|
splitter->setOrientation(Qt::Orientation::Horizontal);
|
|
splitter->addWidget(m_map);
|
|
splitter->addWidget(label);
|
|
setCentralWidget(splitter);
|
|
#endif
|
|
|
|
// connect( m_map, &SituationMap::Map::mapObjectsClicked, this, &SuperDax::onMapObjectClicked );
|
|
|
|
// Prepaire FunctionDialog for debugging purpose only:
|
|
|
|
SituationMap::FunctionDialog::addButtonToMap(m_map);
|
|
|
|
resize(1600,1000);
|
|
|
|
if ((symbolLib) && ((AdvancedSymbology::SymbologyType::APP6D == *symbolLib) || (AdvancedSymbology::SymbologyType::MIL2525D == *symbolLib)))
|
|
{
|
|
AdvancedSymbology::SymbologyType symbologyType = *symbolLib;
|
|
// connect(m_planEdit.data(), &PlanEditor::PlanEditor::symbolModelLoaded, this, [this,symbologyType]()
|
|
{
|
|
QSet<QString> sidcs;
|
|
sidcs << AdvancedSymbology::SidcCodec::encodeComplete(symbologyType, QStringLiteral("10010100001205000000"));
|
|
sidcs << AdvancedSymbology::SidcCodec::encodeComplete(symbologyType, QStringLiteral("10010100001106000000"));
|
|
|
|
m_planEdit->setParticipantsSidcsInUse(sidcs);
|
|
}
|
|
// );
|
|
}
|
|
} // TestMainWindow
|
|
|
|
|
|
~TestMainWindow()
|
|
{
|
|
delete m_map; // Test situation from real life and remove map first, to test "wrong" cleanup
|
|
delete m_planEdit;
|
|
}
|
|
|
|
inline bool isValid() { return m_planEdit != nullptr; }
|
|
|
|
private:
|
|
|
|
|
|
LtsWidgets::LtsBaseLayoutWidget * m_baseLay;
|
|
LtsWidgets::LtsTabWidget * m_mainTab;
|
|
QWidget * m_dw;
|
|
|
|
SituationMap::Map * m_map;
|
|
QPointer<PlanEditor::PlanEditor> m_planEdit; // because the PlanEditor could delete itself use QPointer
|
|
|
|
SituationMap::LOGGER_T m_logger;
|
|
|
|
}; // TestMainWindow
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
int main (int argc, char* argv[])
|
|
{
|
|
// ESRI :
|
|
#ifdef Q_OS_WIN
|
|
// Force usage of OpenGL ES through ANGLE on Windows
|
|
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
|
|
#endif
|
|
// : ESRI
|
|
|
|
bool symbolTypeDefined = false;
|
|
AdvancedSymbology::SymbologyType symbologyType = AdvancedSymbology::SymbologyType::MIL2525C;
|
|
NGLApplication app ( argc, argv );
|
|
|
|
app.createLogger("planEditorApp", "log4cxx_planEditorTest.props");
|
|
|
|
STARTUP_LOG( app.baseLogger() );
|
|
|
|
app.setOrganizationName( QLatin1String( "RME" ) );
|
|
app.setApplicationName( QLatin1String( "Plan Editor Test Application" ) );
|
|
|
|
TRACE_LOG(app.baseLogger()) << LOGFUNCTION << " START";
|
|
|
|
if (argc < 2)
|
|
{
|
|
// usage:
|
|
std::cout << argv[0]
|
|
<< std::endl
|
|
<< " usage: append 'mil' | 'app' to argumentlist" << std::endl
|
|
<< " e.g " << argv[0] << " [QTest options] [testfunction] none" << std::endl
|
|
<< " e.g " << argv[0] << " [QTest options] [testfunction] mil" << std::endl
|
|
<< " e.g " << argv[0] << " [QTest options] [testfunction] app" << std::endl
|
|
<< std::endl;
|
|
|
|
symbologyType = AdvancedSymbology::SymbologyType::None;
|
|
}
|
|
else
|
|
{
|
|
const QString & strSymType = app.arguments().constLast(); // the last argument
|
|
if(strSymType.compare(QLatin1String("none"), Qt::CaseInsensitive) == 0)
|
|
{
|
|
symbolTypeDefined = true;
|
|
symbologyType = AdvancedSymbology::SymbologyType::None;
|
|
}
|
|
|
|
if(strSymType.compare(QLatin1String("mil2525c"), Qt::CaseInsensitive) == 0)
|
|
{
|
|
symbolTypeDefined = true;
|
|
symbologyType = AdvancedSymbology::SymbologyType::MIL2525C;
|
|
}
|
|
|
|
if (strSymType.compare(QLatin1String("mil2525d"), Qt::CaseInsensitive) == 0)
|
|
{
|
|
symbolTypeDefined = true;
|
|
symbologyType = AdvancedSymbology::SymbologyType::MIL2525D;
|
|
}
|
|
|
|
if(strSymType.compare(QLatin1String("app6b"), Qt::CaseInsensitive) == 0)
|
|
{
|
|
symbolTypeDefined = true;
|
|
symbologyType = AdvancedSymbology::SymbologyType::APP6B;
|
|
}
|
|
|
|
if (strSymType.compare(QLatin1String("app6d"), Qt::CaseInsensitive) == 0)
|
|
{
|
|
symbolTypeDefined = true;
|
|
symbologyType = AdvancedSymbology::SymbologyType::APP6D;
|
|
}
|
|
}
|
|
|
|
LtsPluginManager::LtsPluginLoader *pluginLoader = LtsPluginManager::LtsPluginLoader::getInstance();
|
|
|
|
pluginLoader->loadPlugins( LtsPluginManager::PluginType::STYLE , nullptr, QStringList() << QStringLiteral("rme.light") );
|
|
pluginLoader->loadPlugins( LtsPluginManager::PluginType::PROJECT, nullptr, QStringList() << QStringLiteral("legatus") );
|
|
|
|
|
|
// .. to keep some compatibility to old resource structure TODO: rm !
|
|
QDir::setSearchPaths( QLatin1String( "icon" ), QStringList( QLatin1String( ":/style/icons/" ) ) );
|
|
QDir::setSearchPaths( QLatin1String( "icon" ), QStringList( QLatin1String( ":/style/" ) ) ); // FIXME: does qt check for recursion ??
|
|
|
|
// if (SituationMap::Map::applyLicense())
|
|
// DEBUG_LOG(app.baseLogger()) << LOGFUNCTION << " applyLicense ok";
|
|
// else
|
|
// FATAL_LOG(app.baseLogger()) << LOGFUNCTION << " applyLicense failed";
|
|
|
|
#ifdef BUILD_STATIC_LIBRARIES
|
|
// For static linking under windows:
|
|
Q_INIT_RESOURCE(lts_resources);
|
|
#endif
|
|
|
|
TestMainWindow * mw = (symbolTypeDefined) ? new TestMainWindow( &symbologyType ) : new TestMainWindow();
|
|
|
|
if (!mw->isValid())
|
|
{
|
|
delete mw;
|
|
return -1;
|
|
}
|
|
|
|
int width = mw->frameGeometry().width();
|
|
int height = mw->frameGeometry().height();
|
|
|
|
QDesktopWidget wid;
|
|
const QRect & screenRect = wid.availableGeometry(mw);
|
|
|
|
int screenWidth = screenRect.width();
|
|
int screenHeight = screenRect.height();
|
|
|
|
mw->setGeometry((screenWidth/2)-(width/2),(screenHeight/2)-(height/2),width,height);
|
|
|
|
mw->show();
|
|
|
|
app.setQuitOnLastWindowClosed(true);
|
|
|
|
int retval = app.exec();
|
|
|
|
delete mw;
|
|
|
|
SHUTDOWN_LOG(app.baseLogger());
|
|
|
|
return retval;
|
|
}
|
|
|
|
#include "main.moc"
|