1
#include "Maps/Painting.h"
2
#include "Maps/Projection.h"
3
#include "Maps/TrackPoint.h"
4
#include "Maps/Relation.h"
6
#include "Utils/LineF.h"
8
#include <QtGui/QPainter>
9
#include <QtGui/QPainterPath>
14
static void buildCubicPath(QPainterPath& Path, const QPointF& P1, const QPointF& P2, const QPointF& P3, const QPointF& P4)
17
double D2 = L.distance(P2);
18
double D3 = L.distance(P3);
19
if ( (D2 < 0.5) && (D3<0.5) )
23
QPointF H = (P2+P3)/2.0;
24
QPointF L2 = (P1+P2)/2.0;
25
QPointF R3 = (P3+P4)/2.0;
26
QPointF L3 = (L2+H)/2.0;
27
QPointF R2 = (H+R3)/2.0;
28
QPointF L4 = (L3+R2)/2.0;
29
buildCubicPath(Path,P1,L2,L3,L4);
30
buildCubicPath(Path,L4,R2,R3,P4);
35
//bool QRectInterstects(const QRect& r, const QLine& l, QPoint& a, QPoint& b)
37
// QLineF lF = QLineF(l);
39
// bool hasP1 = false;
40
// bool hasP2 = false;
42
// if (QLineF(r.topLeft(), r.bottomLeft()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
46
// if (QLineF(r.bottomLeft(), r.bottomRight()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
55
// if (QLineF(r.bottomRight(), r.topRight()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
64
// if (QLineF(r.topRight(), r.topLeft()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
74
// if (hasP1 && hasP2) {
75
// if (QLineF(a,b).angleTo(lF) > 15.0) {
87
//void buildPathFromRoad(Road *R, Projection const &theProjection, QPainterPath &Path, const QRect& clipRect)
89
// int first=0, last=R->size();
90
// //if (!theProjection.viewport().contains(R->boundingBox())) {
91
// // for (int i=0; i<R->size(); ++i) {
92
// // if (theProjection.viewport().contains(R->get(i)->boundingBox())) {
98
// // if (first) first--;
99
// // last=qMin(last+2, R->size());
102
// bool lastPointVisible = true;
103
// QPoint lastPoint = theProjection.project(R->get(first)->position());
104
// QPoint p = lastPoint;
106
// if (!clipRect.contains(p)) {
107
// p.setX(qMax(clipRect.left(), p.x()));
108
// p.setX(qMin(clipRect.right(), p.x()));
109
// p.setY(qMax(clipRect.top(), p.y()));
110
// p.setY(qMin(clipRect.bottom(), p.y()));
111
// lastPointVisible = false;
114
// if (R->smoothed().size())
116
// for (int i=3; i<R->smoothed().size(); i+=3)
118
// theProjection.project(R->smoothed()[i-2]),
119
// theProjection.project(R->smoothed()[i-1]),
120
// theProjection.project(R->smoothed()[i]));
123
// for (int j=first+1; j<last; ++j) {
124
// p = theProjection.project(R->get(j)->position());
125
// if (!clipRect.contains(p)) {
126
// if (!lastPointVisible) {
128
// if (QRectInterstects(clipRect, QLine(lastPoint, p), a, b)) {
134
// p.setX(qMax(clipRect.left(), p.x()));
135
// p.setX(qMin(clipRect.right(), p.x()));
136
// p.setY(qMax(clipRect.top(), p.y()));
137
// p.setY(qMin(clipRect.bottom(), p.y()));
141
// QRectInterstects(clipRect, QLine(lastPoint, p), a, b);
145
// lastPointVisible = false;
147
// if (!lastPointVisible) {
149
// QRectInterstects(clipRect, QLine(lastPoint, p), a, b);
153
// lastPointVisible = true;
159
void buildPolygonFromRoad(Road *R, Projection const &theProjection, QPolygonF &Polygon)
161
for (int i=0; i<R->size(); ++i)
162
Polygon.append(theProjection.project(R->getNode(i)));
165
/// draws way with oneway markers
166
void draw(QPainter& thePainter, QPen& thePen, MapFeature::TrafficDirectionType TT, const QPointF& FromF, const QPointF& ToF, double theWidth, const Projection&)
171
double DistFromCenter = theWidth*2;
172
if (distance(FromF,ToF) > qMax(40.0,DistFromCenter*2+4))
174
QPointF H(FromF+ToF);
176
double A = angle(FromF-ToF);
177
QPointF T(DistFromCenter*cos(A),DistFromCenter*sin(A));
178
QPointF V1(theWidth*cos(A+M_PI/6),theWidth*sin(A+M_PI/6));
179
QPointF V2(theWidth*cos(A-M_PI/6),theWidth*sin(A-M_PI/6));
180
// MapFeature::TrafficDirectionType TT = W->trafficDirection();
181
if ( (TT == MapFeature::OtherWay) || (TT == MapFeature::BothWays) )
183
thePainter.setPen(QColor(0,0,0));
184
thePainter.drawLine(H+T,H+T-V1);
185
thePainter.drawLine(H+T,H+T-V2);
187
if ( (TT == MapFeature::OneWay) || (TT == MapFeature::BothWays) )
189
thePainter.setPen(QColor(0,0,0));
190
thePainter.drawLine(H-T,H-T+V1);
191
thePainter.drawLine(H-T,H-T+V2);
194
thePainter.strokePath(Path,thePen);
197
void draw(QPainter& thePainter, QPen& thePen, MapFeature::TrafficDirectionType TT, const Coord& From, const Coord& To, double theWidth, const Projection& theProjection)
199
QPointF FromF(theProjection.project(From));
200
QPointF ToF(theProjection.project(To));
201
draw(thePainter,thePen,TT,FromF,ToF,theWidth,theProjection);
205
/* void draw(QPainter& thePainter, QPen& thePen, Way* W, const Projection& theProjection)
208
QPointF FromF(theProjection.project(W->from()));
209
QPointF ToF(theProjection.project(W->to()));
212
thePainter.strokePath(Path,thePen);