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
k-a-z-u ba9c8359d7 added support for object-sizing
added support for wall-heights
2018-07-04 20:29:09 +02:00

252 lines
8.3 KiB
C++

#include "fixC11.h"
#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/3D/grid/GridRenderer.h"
#include <Indoor/wifi/estimate/ray3/OBJPool.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);
// new/load/save
connect(mw->getActionWidget(), SIGNAL(onNew()), this, SLOT(onNew()));
connect(mw->getActionWidget(), SIGNAL(onLoad()), this, SLOT(onLoad()));
connect(mw->getActionWidget(), SIGNAL(onSave()), this, SLOT(onSave()));
// 3D view change
connect(mw, SIGNAL(onShow3DFloorplan(bool)), this, SLOT(onSetShow3DFloorplan(bool)));
connect(mw, SIGNAL(onShow3DGrid(bool)), this, SLOT(onSetShow3DGrid(bool)));
connect(mw, SIGNAL(onShow3DNavMesh(bool)), this, SLOT(onSetShow3DNavMesh(bool)));
connect(mapView3D, SIGNAL(onShow3DFloorplan(bool)), this, SLOT(onSetShow3DFloorplan(bool)));
connect(mapView3D, SIGNAL(onShow3DGrid(bool)), this, SLOT(onSetShow3DGrid(bool)));
connect(mapView3D, SIGNAL(onShow3DNavMesh(bool)), this, SLOT(onSetShow3DNavMesh(bool)));
// 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);} );
//Ray3D::OBJPool::get().init("/mnt/vm/paper/diss/code/IndoorMap/res/mdl/");
//Ray3D::OBJPool::get().init("/apps/paper/diss/code/IndoorMap/res/mdl/");
Ray3D::OBJPool::get().init({
"/mnt/vm/paper/diss/code/IndoorMap/res/mdl/",
"/apps/paper/diss/code/IndoorMap/res/mdl/",
});
//mapModel->load("../IndoorMap/maps/SHL36_noel.xml");
//mapModel->load("../IndoorMap/maps/SHL38_no_elev.xml");
//mapModel->load("/apps/testmap.xml");
//mapModel->load("/apps/map24b.xml");
//mapModel->load("/apps/SHL41.xml");
//mapModel->load("/mnt/vm/paper/diss/data/maps/test_in_out_overlap.xml");
//mapModel->load("/mnt/vm/paper/diss/data/maps/walkmodel_stairs3.xml");
//mapModel->load("/apps/paper/diss/data/maps/walkmodel_2D_2.xml");
//mapModel->load("/apps/paper/diss/data/maps/walkmodel_2D_2.xml");
//mapModel->load("/apps/paper/diss/data/maps/walkmodel_stairs3.xml");
mapModel->load("/apps/paper/maps/museum/map43_svg.xml");
//mapModel->load("/apps/paper/diss/data/maps/SHL41_nm.xml");
//mapModel->load("/mnt/sdcard/SHL41_nm.xml");
//mapModel->load("/apps/paper/diss/data/maps/map_elevator2.xml");
//mapModel->load("/apps/paper/diss/data/maps/map_issue6.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;
mw->getMapView3D()->layerChange();
}
void MainController::onLayerVisibilityChanged(MapLayer *layer, const bool visible) {
(void) layer;
(void) visible;
mw->getMapView3D()->layerChange();
}
void MainController::onSetShow3DFloorplan(bool show) {
mw->getMapView3D()->setShowFloorplan(show);
}
void MainController::onSetShow3DGrid(bool show) {
mw->getMapView3D()->setShowGrid(show);
}
void MainController::onSetShow3DNavMesh(bool show) {
mw->getMapView3D()->setShowNavMesh(show);
}
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();
mw->getMapView3D()->update();
//mw->getToolBoxWidget()->
}
void MainController::onMapModelNeedsRepaint() {
mw->getMapView2D()->update();
mw->getLINT()->update(mapModel->getMap());
}
void MainController::onMapModelReset() {
mw->getTree()->expandAll();
mw->getLINT()->update(mapModel->getMap());
mw->getMapView3D()->layerChange();
}
void MainController::onNew() {
const int res = QMessageBox::question(nullptr, "New Map", "really start a new map?", QMessageBox::Yes, QMessageBox::No);
if (res == QMessageBox::Yes) {
mapModel->startEmpty();
}
}
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());
}
}