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

162 lines
4.3 KiB
C++
Raw 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 "MV2DElementFloorObstacleDoor.h"
#include "MV2DElement.h"
#include "MapViewElementHelper.h"
#include "HasMoveableNodes.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include <chrono>
MV2DElementFloorObstacleDoor::MV2DElementFloorObstacleDoor(Floorplan::FloorObstacleDoor* fo) : fo(fo) {
;
}
BBox2 MV2DElementFloorObstacleDoor::getBoundingBox() const {
BBox2 bbox;
bbox.add(fo->from);
bbox.add(fo->to);
return bbox;
}
ClickDist MV2DElementFloorObstacleDoor::getMinDistanceXY(const Point2 p) const {
return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p) * 0.95;
}
void MV2DElementFloorObstacleDoor::paint(Painter& p) {
// invisible? -> leave
if (!p.isVisible( (fo->from+fo->to)/2 )) {
return;
}
// DEPRECATED
// // selected endpoints?
// if (hasFocus()) {
// p.setPenBrush(Qt::NoPen, CFG::SEL_COLOR);
// if (selectedUserIdx == 0) {p.drawCircle(fo->from);}
// if (selectedUserIdx == 1) {p.drawCircle(fo->to);}
// }
QPen pen;
pen.setColor(QColor(255,0,0));
pen.setStyle(Qt::PenStyle::DotLine);
p.setPenBrush(pen, Qt::NoBrush);
if (Floorplan::DoorType::SWING == fo->type) {
// opening indicator
const float open = (fo->swap) ? (-M_PI * 0.5) : (+M_PI * 0.5);
const float len = (fo->to - fo->from).length();
const float angle1 = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
const float angle2 = angle1 + open;
const Point2 pOpen = Point2( std::cos(angle2) * len, std::sin(angle2) * len ) + fo->from;
pen.setWidth(2); p.setPen(pen);
p.drawLine(fo->from, fo->to);
pen.setWidth(1); p.setPen(pen);
p.drawLine(fo->from, pOpen);
p.drawArc(fo->from, len, angle1, open);
} else if (Floorplan::DoorType::REVOLVING == fo->type) {
const float angle_rad = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
// arcs
const Point2 cen = (fo->from + fo->to) / 2;
const float rad = (fo->to - fo->from).length() / 2;
p.drawArc(cen, rad, (40-90)/180.0f*M_PI+angle_rad, 100/180.0f*M_PI);
p.drawArc(cen, rad, (180+40-90)/180.0f*M_PI+angle_rad, 100/180.0f*M_PI);
const int funAngle = (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() / 50) % 360;
// inner spinner
int numDoors = 3;
for (int i = 0; i < numDoors; ++i) {
const int deg = 360 * i / numDoors + angle_rad*180.0f/M_PI + funAngle;
const float sx = std::cos(deg / 180.0f * M_PI);
const float sy = std::sin(deg / 180.0f * M_PI);
const Point2 dst = cen + Point2(sx,sy) * rad;
p.drawLine(cen, dst);
}
}
// DEPRECATED
// // available endpoints
// if (hasFocus()) {
// p.setPenBrush(Qt::black, Qt::NoBrush);
// p.drawCircle(fo->from);
// p.drawCircle(fo->to);
// }
// obstacle length
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
}
}
void MV2DElementFloorObstacleDoor::onFocus() {
;
}
void MV2DElementFloorObstacleDoor::onUnfocus() {
selectedUserIdx = -1; // clear selection
}
void MV2DElementFloorObstacleDoor::mousePressed(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
void MV2DElementFloorObstacleDoor::mouseMove(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
void MV2DElementFloorObstacleDoor::mouseReleased(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
std::vector<MoveableNode> MV2DElementFloorObstacleDoor::getMoveableNodes() const {
std::vector<MoveableNode> nodes = {
MoveableNode(0, fo->from),
MoveableNode(1, fo->to)
};
return nodes;
}
void MV2DElementFloorObstacleDoor::onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
void MV2DElementFloorObstacleDoor::onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) v;
switch (userIdx) {
case 0: fo->from = newPos; break;
case 1: fo->to = newPos; break;
}
// emit v->onElementChange(this);
}
bool MV2DElementFloorObstacleDoor::keyPressEvent(MapView2D* v, QKeyEvent *e) {
(void) v;
(void) e;
return false;
}