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/mapview/2D/MV2DElementFloorObstacleObject.cpp
2018-10-25 12:15:13 +02:00

150 lines
4.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#include "MV2DElementFloorObstacleObject.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include <Indoor/floorplan/3D/objects/OBJPool.h>
#include "../../UIHelper.h"
MV2DElementFloorObstacleObject::MV2DElementFloorObstacleObject(Floorplan::FloorObstacleObject* fo) : fo(fo) {
;
}
BBox2 MV2DElementFloorObstacleObject::getBoundingBox() const {
BBox2 bbox;
bbox.add(Point2(fo->pos.x, fo->pos.y));
bbox.grow(Point2(0.1, 0.1));
return bbox;
}
ClickDist MV2DElementFloorObstacleObject::getMinDistanceXY(const Point2 p) const {
return ClickDist(p.getDistance(fo->pos.xy()), ClickDistType::DIRECT);
}
//#include <unordered_map>
//struct Cache {
// struct Line {
// Point2 p1;
// Point2 p2;
// Line(Point2 p1, Point2 p2) : p1(p1), p2(p2) {;}
// };
// struct Entry {
// const Floorplan::FloorObstacleObject* obj = nullptr;
// std::vector<Line> lines;
// };
// Entry e;
// const Entry& get(const Floorplan::FloorObstacleObject* obj) {
// if (e.obj == nullptr || e.obj->file != obj->file || e.obj->pos != obj->pos || e.obj->rot != obj->rot) {
// e.obj = obj;
// e.lines.clear();
// const Ray3D::Obstacle3D obs = Ray3D::OBJPool::get().getObject(obj->file).rotated_deg(obj->rot).translated(obj->pos);
// for (const Triangle3& tria : obs.triangles) {
// if (tria.p1.xy() != tria.p2.xy()) {
// e.lines.push_back( Line (tria.p1.xy(), tria.p2.xy()) );
// }
// }
// return e;
// }
// }
//} cache;
void MV2DElementFloorObstacleObject::paint(Painter& p) {
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("objects", CFG::UNFOCUS_COLOR, 16);
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("objects", CFG::FOCUS_COLOR, 16);
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("objects", CFG::SEL_COLOR, 16);
// invisible? -> leave
if (!p.isVisible(fo->pos.xy())) {
return;
}
if (p.getScaler().getScale() >= 40) {
// TODO: quite costly... cache??
p.setPenBrush(Qt::black, Qt::NoBrush);
// const Cache::Entry& e = cache.get(fo);
// for (const Cache::Line& l : e.lines) {
// p.drawLine(l.p1, l.p2);
// }
const Floorplan3D::Obstacle3D obs = Floorplan3D::OBJPool::get().getObject(fo->file).rotated_deg(fo->rot).translated(fo->pos);
for (const Triangle3& tria : obs.triangles) {
if (tria.p1.xy() != tria.p2.xy()) {
p.drawLine( tria.p1.xy(), tria.p2.xy() );
}
}
}
if (p.getScaler().getScale() >= 20) {
if (selectedUserIdx == 0) {
p.drawPixmap(fo->pos.xy(), pixmapSel);
} else if (hasFocus()) {
p.drawPixmap(fo->pos.xy(), pixmapFocused);
} else {
p.drawPixmap(fo->pos.xy(), pixmapUnfocused);
}
}
//p.setPenBrush(Qt::black, Qt::NoBrush);
//p.drawDot(fo->pos.xy());
}
std::vector<MoveableNode> MV2DElementFloorObstacleObject::getMoveableNodes() const {
return { MoveableNode(0, fo->pos.xy()) };
}
void MV2DElementFloorObstacleObject::onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) v;
if (userIdx == 0) {fo->pos.x = newPos.x; fo->pos.y = newPos.y;}
}
void MV2DElementFloorObstacleObject::onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
void MV2DElementFloorObstacleObject::mousePressed(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
void MV2DElementFloorObstacleObject::mouseMove(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
void MV2DElementFloorObstacleObject::mouseReleased(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
bool MV2DElementFloorObstacleObject::keyPressEvent(MapView2D* v, QKeyEvent *e) {
(void) v;
(void) e;
return false;
}
void MV2DElementFloorObstacleObject::onFocus() {
;
}
void MV2DElementFloorObstacleObject::onUnfocus() {
;
}