This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/MainController.cpp
2016-12-01 19:42:13 +01:00

155 lines
5.2 KiB
C++

#include "MainController.h"
#include "MainWindow.h"
#include "mapview/model/MapModel.h"
#include "mapview/model/MapModelElement.h"
#include "mapview/2D/tools/ToolSelector.h"
#include "mapview/2D/tools/ToolMoveMap.h"
#include "mapview/2D/tools/ToolMapZoom.h"
#include "mapview/2D/tools/ToolRuler.h"
#include "mapview/2D/tools/ToolMapGrid.h"
#include "params/ElementParamWidget.h"
#include "params/LayerParamWidget.h"
#include "params/ToolBoxWidget.h"
#include "params/ActionWidget.h"
#include "tree/MapTreeModel.h"
#include <QFileDialog>
#include <QTreeView>
#include "mapview/3DGrid/GridRenderer.h"
MainController::MainController() {
mw = new MainWindow();
mw->resize(1000, 700);
MapView2D* mapView2D = mw->getMapView2D();
MapView3D* mapView3D = mw->getMapView3D();
QTreeView* layerTree = mw->getTree();
// model setup
mapModel = new MapModel();
mapView2D->setModel(mapModel);
mapView3D->setModel(mapModel);
mapTreeModel = new MapTreeModel(mapModel);
layerTree->setModel(mapTreeModel);
ToolMoveMap* moveMap = new ToolMoveMap();
ToolRuler* ruler = new ToolRuler();
ToolMapZoom* mapZoom = new ToolMapZoom();
ToolMapGrid* mapGrid = new ToolMapGrid();
ToolSelector* mapSelector = new ToolSelector();
mapView2D->getTools().addBackground(mapGrid);
mapView2D->getTools().addBackground(moveMap);
mapView2D->getTools().addBackground(mapZoom);
mapView2D->getTools().addBackground(ruler);
mapView2D->getTools().setMain(mapSelector);
//connect(layerTree, SIGNAL(activated(QModelIndex)), this, SLOT(layerSelected(QModelIndex)));
connect(layerTree->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(layerSelected(QModelIndex)));
connect(mapSelector, SIGNAL(onMapElementSelected(MapModelElement*)), this, SLOT(mapElementSelected(MapModelElement*)));
connect(mw->getMapView2D(), SIGNAL(onElementChange(MV2DElement*)), this, SLOT(curMapElementChanged()));
// model events
connect(mapModel, SIGNAL(aboutToReset()), this, SLOT(onMapModelAboutToReset()));
connect(mapModel, SIGNAL(reset()), this, SLOT(onMapModelReset()));
// load/save
connect(mw->getActionWidget(), SIGNAL(onLoad()), this, SLOT(onLoad()));
connect(mw->getActionWidget(), SIGNAL(onSave()), this, SLOT(onSave()));
// 3D view change
connect(mw, SIGNAL(onShow3DFloorplan()), this, SLOT(onShow3DFloorplan()));
connect(mw, SIGNAL(onShow3DGrid()), this, SLOT(onShow3DGrid()));
// 3D grid view config
connect(mw, &MainWindow::onGridNodeColorImp, [&] () {mw->getMapView3D()->getGridRenderer()->setNodeColorMode(GridRendererColorMode::SHOW_NODE_IMPORTANCE);} );
connect(mw, &MainWindow::onGridNodeColorType, [&] () {mw->getMapView3D()->getGridRenderer()->setNodeColorMode(GridRendererColorMode::SHOW_NODE_TYPE);} );
connect(mw, &MainWindow::onGridShowEdges, [&] (const bool show) {mw->getMapView3D()->getGridRenderer()->setShowEdges(show);} );
//mapModel->load("../IndoorMap/maps/SHL21.xml");
//mapModel->load("../IndoorMap/maps/test.xml");
//mapModel->load("/home/toni/Documents/programme/localization/IPIN2016/competition/src/competition/map/CAR/CAR10.xml");
mapModel->load("/home/toni/Documents/programme/localization/IPIN2016/competition/src/competition/map/UAH/UAH12_rawObstacles.xml");
//mapModel->load("/home/toni/Documents/programme/localization/IPIN2016/competition/src/competition/map/SHL/SHL25.xml");
//mapModel->load("/home/toni/Documents/programme/localization/IPIN2016/competition/src/competition/map/UJI-UB/UJI-UB5.xml");
//mapModel->load("/home/toni/Documents/programme/localization/IPIN2016/competition/src/competition/map/UJI-TI/UJI-TI4.xml");
//mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/UJI-TI/UJI-TI4.xml");
//mapModel->load("/home/toni/Documents/programme/localization/IPIN2016/competition/src/competition/map/UJI-UB/UJI-UB5.xml");
//mapModel->load("/mnt/data/workspaces/Indoor/tests/data/WalkHeadingMap.xml");
//mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/test.xml");
}
void MainController::onShow3DFloorplan() {
mw->getMapView3D()->showFloorplan();
}
void MainController::onShow3DGrid() {
mw->getMapView3D()->showGrid();
}
void MainController::layerSelected(QModelIndex idx) {
mw->getMapView2D()->layerChange();
MapLayer* ml = static_cast<MapLayer*>(idx.internalPointer());
mapModel->setSelectedLayer(ml);
mw->getMapView2D()->layerChange();
mw->getMapView3D()->layerChange();
mw->getLayerParamWidget()->setElement(ml);
mw->getToolBoxWidget()->setSelectedLayer(ml);
}
void MainController::curMapElementChanged() {
mw->getElementParamWidget()->refresh();
}
void MainController::mapElementSelected(MapModelElement* el) {
mw->getElementParamWidget()->setElement(el);
}
void MainController::onMapModelAboutToReset() {
mw->getLayerParamWidget()->setElement(nullptr);
mw->getToolBoxWidget()->setSelectedLayer(nullptr);
mw->getMapView2D()->update();
}
void MainController::onMapModelReset() {
mw->getTree()->expandAll();
}
void MainController::onLoad() {
QString file = QFileDialog::getOpenFileName(mw, "open a map");
if (file != "") {
mapModel->load(file.toStdString());
}
}
void MainController::onSave() {
QString file = QFileDialog::getSaveFileName(mw, "save the map");
if (file != "") {
mapModel->save(file.toStdString());
}
}