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
2017-03-21 21:12:52 +01:00

197 lines
6.3 KiB
C++

#include "MainController.h"
#include "MainWindow.h"
#include "mapview/model/MapModel.h"
#include "mapview/model/MapModelElement.h"
#include "misc/LINTView.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 "params/LayerTree.h"
#include "params/MetaEditWidget.h"
#include "tree/MapTreeModel.h"
#include <QFileDialog>
#include <QTreeView>
#include "mapview/3DGrid/GridRenderer.h"
MainController::MainController() {
// Floorplan::Meta* meta = new Floorplan::Meta();
// meta->setVal("a", "b");
// meta->setVal("c", "d");
// MetaEditWidget* mew = new MetaEditWidget(meta);
// mew->resize(300,300);
// mew->show();
mw = new MainWindow();
mw->resize(1000, 700);
MapView2D* mapView2D = mw->getMapView2D();
MapView3D* mapView3D = mw->getMapView3D();
LayerTree* layerTree = mw->getTree();
// model setup
mapModel = new MapModel();
mapView2D->setModel(mapModel);
mapView3D->setModel(mapModel);
mapTreeModel = new MapTreeModel(mapModel);
layerTree->setModel(mapTreeModel);
moveMap = new ToolMoveMap();
ruler = new ToolRuler();
mapZoom = new ToolMapZoom();
mapGrid = new ToolMapGrid();
mapSelector = new ToolSelector();
mapView2D->getTools().addBackground(mapGrid);
mapView2D->getTools().addBackground(moveMap);
mapView2D->getTools().addBackground(mapZoom);
mapView2D->getTools().addBackground(ruler);
mapView2D->getTools().setDefaultMainTool(mapSelector);
mapView2D->getTools().setMainDefault();
//connect(layerTree, SIGNAL(activated(QModelIndex)), this, SLOT(layerSelected(QModelIndex)));
//connect(layerTree->getTree()->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(layerSelected(QModelIndex)));
connect(layerTree, SIGNAL(layerSelected(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()));
mapModel->addListener(this);
// 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/SHL36.xml");
//mapModel->resize(0.983, 0.983, 1, -0.2, -0.3, 0);
//mapModel->load("../IndoorMap/maps/test.xml");
//mapModel->load("../IndoorMap/maps/APs.xml");
//mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/CAR/CAR9.xml");
//mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/UAH/UAH9.xml");
//mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/UJI-TI/UJI-TI4.xml");
//mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/UJI-UB/UJI-UB4.xml");
//mapModel->load("/mnt/data/workspaces/Indoor/tests/data/WalkHeadingMap.xml");
//mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/test.xml");
// mapModel->startEmpty();
}
void MainController::onLayerChanged(MapLayer* layer) {
(void) layer;
mw->getMapView2D()->update();
mw->getMapView3D()->update();
mw->getLINT()->update(mapModel->getMap());
}
void MainController::onLayerElementAdded(MapLayer* layer, MapModelElement* elem) {
(void) layer;
mapSelector->focus(mw->getMapView2D(), elem);
mw->getLINT()->update(mapModel->getMap());
}
void MainController::onLayerElementRemoved(MapLayer* layer, const MapModelElement* elem) {
(void) layer;
(void) elem;
}
void MainController::onLayerVisibilityChanged(MapLayer *layer, const bool visible) {
(void) layer;
(void) visible;
}
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);
mw->getLINT()->update(mapModel->getMap());
}
void MainController::curMapElementChanged() {
mw->getElementParamWidget()->refresh();
mw->getLINT()->update(mapModel->getMap());
}
void MainController::mapElementSelected(MapModelElement* el) {
mw->getElementParamWidget()->setElement(el);
mw->getLINT()->update(mapModel->getMap());
}
void MainController::onMapModelAboutToReset() {
mw->getLayerParamWidget()->setElement(nullptr);
mw->getToolBoxWidget()->setSelectedLayer(nullptr);
mw->getMapView2D()->update();
}
void MainController::onMapModelNeedsRepaint() {
mw->getMapView2D()->update();
mw->getLINT()->update(mapModel->getMap());
}
void MainController::onMapModelReset() {
mw->getTree()->expandAll();
mw->getLINT()->update(mapModel->getMap());
}
void MainController::onLoad() {
QString file = QFileDialog::getOpenFileName(mw, "open a map");
if (file != "") {
mapModel->load(file.toStdString());
mw->getLINT()->update(mapModel->getMap());
}
}
void MainController::onSave() {
QString file = QFileDialog::getSaveFileName(mw, "save the map");
if (file != "") {
mapModel->save(file.toStdString());
}
}