From 9a07790ec68631af029d4395e04745581946194c Mon Sep 17 00:00:00 2001 From: kazu Date: Thu, 26 Jul 2018 08:44:53 +0200 Subject: [PATCH] fixes focus issue --- MainController.cpp | 4 +- mapview/2D/MV2DElementFloorObstacleWall.cpp | 4 +- mapview/2D/Painter.cpp | 4 +- mapview/2D/tools/ToolSelector.h | 51 ++++++++++----------- mapview/model/MMFloorObstacleWall.h | 18 ++++---- 5 files changed, 39 insertions(+), 42 deletions(-) diff --git a/MainController.cpp b/MainController.cpp index 2479596..ed2fcf0 100644 --- a/MainController.cpp +++ b/MainController.cpp @@ -126,8 +126,8 @@ MainController::MainController() { //mapModel->load("/apps/paper/diss/data/maps/walkmodel_stairs3.xml"); //mapModel->load("/apps/paper/maps/museum/map43_svg.xml"); - //mapModel->load("/apps/paper/maps/shl/SHL45_nm.xml"); - mapModel->load("/apps/paper/maps/test/doors1.xml"); + mapModel->load("/apps/paper/maps/shl/SHL46_nm.xml"); + //mapModel->load("/apps/paper/maps/test/doors1.xml"); //mapModel->load("/mnt/sdcard/SHL41_nm.xml"); diff --git a/mapview/2D/MV2DElementFloorObstacleWall.cpp b/mapview/2D/MV2DElementFloorObstacleWall.cpp index f0b2d60..5f490b1 100644 --- a/mapview/2D/MV2DElementFloorObstacleWall.cpp +++ b/mapview/2D/MV2DElementFloorObstacleWall.cpp @@ -252,8 +252,8 @@ void MV2DElementFloorObstacleWall::onNodeMove(MapView2D* v, const int userIdx, c Point2 p; float u = 0; bool isects = intersects(l2, l1, true, p, &u); - if (u < 0.1) {u = 0.1;} - if (u > 0.9) {u = 0.9;} + if (u < 0.01) {u = 0.01;} + if (u > 0.99) {u = 0.99;} if (userIdx >= 1000 && userIdx < 2000) { diff --git a/mapview/2D/Painter.cpp b/mapview/2D/Painter.cpp index 354fa95..f52f69d 100644 --- a/mapview/2D/Painter.cpp +++ b/mapview/2D/Painter.cpp @@ -134,14 +134,14 @@ void Painter::drawPolygon(const std::vector& points) { for (const Point2 p : points) { vec.push_back(QPointF(s.xms(p.x), s.yms(p.y))); } - p->drawConvexPolygon(vec.data(), vec.size()); + p->drawPolygon(vec.data(), vec.size()); } void Painter::drawPolygon(const std::vector& points) { std::vector vec; for (const Point3 p : points) { vec.push_back(QPointF(s.xms(p.x), s.yms(p.y))); } - p->drawConvexPolygon(vec.data(), vec.size()); + p->drawPolygon(vec.data(), vec.size()); } void Painter::drawPixmap(const Point2 pt, const QPixmap& img) { diff --git a/mapview/2D/tools/ToolSelector.h b/mapview/2D/tools/ToolSelector.h index dae6238..4dddf73 100644 --- a/mapview/2D/tools/ToolSelector.h +++ b/mapview/2D/tools/ToolSelector.h @@ -72,22 +72,24 @@ private: } - void processPress(QMouseEvent* e, MapView2D* m, const Point2 p, MapModelElement* elem) { + bool processPress(QMouseEvent* e, MapView2D* m, const Point2 p, MapModelElement* elem) { MV2DElement* me = elem->getMV2D(); - if (!me) {return;} + if (!me) {return false;} // left mouse button? if (e->button() == Qt::MouseButton::LeftButton) { // element has selectedable nodes? try to select one if (dynamic_cast(me)) { - if (selectNode(m, p, dynamic_cast(me))) {return;} + if (selectNode(m, p, dynamic_cast(me))) {return true;} } } // let the element itself process all events me->mousePressed(m, p); + return false; + } void processMove(QMouseEvent* e, MapView2D* m, const Point2 p, MapModelElement* elem) { @@ -248,34 +250,29 @@ private: const float g = m->getScaler().sm(15); // increase each BBox by 15 px (needed mainly for hor/ver lines) -#pragma message "which elements to select? among all currently visible? or only among the selected layer?" - // get all elements with bounding-box matchings - std::vector possible; -// for (MapModelElement* el : m->getModel()->getSelectedLayerElements()) { - for (MapModelElement* el : m->getModel()->getVisibleElements()) { - if (!el->getMV2D()) {continue;} - BBox2 bbox = el->getMV2D()->getBoundingBox(); // elements 2D bbox - bbox.grow(Point2(g, g)); // grow a little (needed for straight lines) - if (bbox.contains(p2)) {possible.push_back(el);} // intersection? - } - - // among those, find the best-matching one (smallest distance to an intersection) - auto lambda = [&] (const MapModelElement* el1, const MapModelElement* el2) {return el1->getMV2D()->getMinDistanceXY(p2) < el2->getMV2D()->getMinDistanceXY(p2);}; - auto it = std::min_element(possible.begin(), possible.end(), lambda); - MapModelElement* el = (it == possible.end()) ? (nullptr) : (*it); - - - - // focus changed? -> unfocus the old one (if any) - if (setFocused(m, el)) { + if (focused && processPress(e, m, p2, focused)) { ; - } else { - // focus kept. provide the currently focused element with events - if (focused) { - processPress(e, m, p2, focused); + // get all elements with bounding-box matchings + std::vector possible; + // for (MapModelElement* el : m->getModel()->getSelectedLayerElements()) { + for (MapModelElement* el : m->getModel()->getVisibleElements()) { + if (!el->getMV2D()) {continue;} + BBox2 bbox = el->getMV2D()->getBoundingBox(); // elements 2D bbox + bbox.grow(Point2(g, g)); // grow a little (needed for straight lines) + if (bbox.contains(p2)) {possible.push_back(el);} // intersection? + } + + // among those, find the best-matching one (smallest distance to an intersection) + auto lambda = [&] (const MapModelElement* el1, const MapModelElement* el2) {return el1->getMV2D()->getMinDistanceXY(p2) < el2->getMV2D()->getMinDistanceXY(p2);}; + auto it = std::min_element(possible.begin(), possible.end(), lambda); + MapModelElement* el = (it == possible.end()) ? (nullptr) : (*it); + + // focus the new element, unfocus the old one + if (setFocused(m, el)) { + ; } } diff --git a/mapview/model/MMFloorObstacleWall.h b/mapview/model/MMFloorObstacleWall.h index e29b0d6..47e460f 100644 --- a/mapview/model/MMFloorObstacleWall.h +++ b/mapview/model/MMFloorObstacleWall.h @@ -73,19 +73,19 @@ public: case 0: return Param("thickness (m)", ParamType::FLOAT); case 1: return Param("height (m)", ParamType::FLOAT); case 2: return Param("length", ParamType::FLOAT, true); - } + } break; case 1: switch(idx) { case 0: return Param("width (m)", ParamType::FLOAT); case 1: return Param("height (m)", ParamType::FLOAT); case 2: return Param("left/right", ParamType::BOOL); case 3: return Param("in/out", ParamType::BOOL); - } + } break; case 2: switch(idx) { case 0: return Param("above ground (m)", ParamType::FLOAT); case 1: return Param("width (m)", ParamType::FLOAT); case 2: return Param("height (m)", ParamType::FLOAT); case 3: return Param("in/out", ParamType::BOOL); - } + } break; } throw 1; } @@ -96,19 +96,19 @@ public: case 0: return wall->thickness_m; case 1: return wall->height_m; case 2: return wall->from.getDistance(wall->to); - } + } break; case 1: switch(idx) { case 0: return getCurDoor()->width; case 1: return getCurDoor()->height; case 2: return getCurDoor()->leftRight; case 3: return getCurDoor()->inOut; - } + } break; case 2 : switch(idx) { case 0: return getCurWindow()->startsAtHeight; case 1: return getCurWindow()->width; case 2: return getCurWindow()->height; case 3: return getCurWindow()->inOut; - } + } break; } throw 1; } @@ -119,19 +119,19 @@ public: case 0: wall->thickness_m = val.toFloat(); return; case 1: wall->height_m = val.toFloat(); return; case 2: return; - } + } break; case 1: switch(idx) { case 0: getCurDoor()->width = val.toFloat(); return; case 1: getCurDoor()->height = val.toFloat(); return; case 2: getCurDoor()->leftRight = val.toBool(); return; case 3: getCurDoor()->inOut = val.toBool(); return; - } + } break; case 2: switch(idx) { case 0: getCurWindow()->startsAtHeight = val.toFloat(); return; case 1: getCurWindow()->width = val.toFloat(); return; case 2: getCurWindow()->height = val.toFloat(); return; case 3: getCurWindow()->inOut = val.toBool(); return; - } + } break; } } };