Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/globjects/GUIPointOfInterest.cpp
193863 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GUIPointOfInterest.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date June 2006
19
///
20
// The GUI-version of a point of interest
21
/****************************************************************************/
22
23
#include <utils/common/StringTokenizer.h>
24
#include <utils/gui/div/GUIParameterTableWindow.h>
25
#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
26
#include <utils/gui/div/GUIGlobalSelection.h>
27
#include <utils/gui/images/GUITextureSubSys.h>
28
#include <utils/gui/div/GLHelper.h>
29
#include <utils/gui/globjects/GLIncludes.h>
30
31
#include "GUIPointOfInterest.h"
32
33
34
// ===========================================================================
35
// method definitions
36
// ===========================================================================
37
38
GUIPointOfInterest::GUIPointOfInterest(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos,
39
bool geo, const std::string& lane, double posOverLane, bool friendlyPos, double posLat,
40
const std::string& icon, double layer, double angle, const std::string& imgFile,
41
double width, double height) :
42
PointOfInterest(id, type, color, pos, geo, lane, posOverLane, friendlyPos, posLat, icon, layer, angle, imgFile, width, height),
43
GUIGlObject_AbstractAdd(GLO_POI, id,
44
(lane.size() > 0) ? GUIIconSubSys::getIcon(GUIIcon::POILANE) : geo ? GUIIconSubSys::getIcon(GUIIcon::POIGEO) : GUIIconSubSys::getIcon(GUIIcon::POI)) {
45
}
46
47
48
GUIPointOfInterest::~GUIPointOfInterest() {}
49
50
51
GUIGLObjectPopupMenu*
52
GUIPointOfInterest::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
53
GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
54
// build shape header
55
buildShapePopupOptions(app, ret, getShapeType());
56
return ret;
57
}
58
59
60
GUIParameterTableWindow*
61
GUIPointOfInterest::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {
62
GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
63
// add items
64
ret->mkItem("type", false, getShapeType());
65
ret->mkItem("icon", false, getIconStr());
66
ret->mkItem("layer", false, getShapeLayer());
67
ret->closeBuilding(this);
68
return ret;
69
}
70
71
72
double
73
GUIPointOfInterest::getExaggeration(const GUIVisualizationSettings& s) const {
74
return s.poiSize.getExaggeration(s, this);
75
}
76
77
78
Boundary
79
GUIPointOfInterest::getCenteringBoundary() const {
80
Boundary b;
81
b.add(x(), y());
82
if (getShapeImgFile() != DEFAULT_IMG_FILE) {
83
b.growWidth(myHalfImgWidth);
84
b.growHeight(myHalfImgHeight);
85
} else {
86
b.grow(3);
87
}
88
return b;
89
}
90
91
92
void
93
GUIPointOfInterest::drawGL(const GUIVisualizationSettings& s) const {
94
// check if POI can be drawn
95
if (checkDraw(s, this)) {
96
// push name (needed for getGUIGlObjectsUnderCursor(...)
97
GLHelper::pushName(getGlID());
98
// draw inner polygon
99
const double exaggeration = getExaggeration(s);
100
const double layer = s.poiUseCustomLayer ? s.poiCustomLayer : getShapeLayer();
101
GLHelper::pushMatrix();
102
// set POI Color
103
setPOIColor(s, getShapeColor(), this, false);
104
// add extra offset z provided by icon to avoid overlapping
105
glTranslated(x(), y(), layer + (double)getIcon());
106
glRotated(-getShapeNaviDegree(), 0, 0, 1);
107
// check if has to be drawn as a circle or with an image
108
if (getShapeImgFile() != DEFAULT_IMG_FILE) {
109
int textureID = GUITexturesHelper::getTextureID(getShapeImgFile());
110
if (textureID > 0) {
111
GUITexturesHelper::drawTexturedBox(textureID,
112
getWidth() * -0.5 * exaggeration, getHeight() * -0.5 * exaggeration,
113
getWidth() * 0.5 * exaggeration, getHeight() * 0.5 * exaggeration);
114
}
115
} else {
116
// fallback if no image is defined
117
GLHelper::drawFilledCircle(std::max(getWidth(), getHeight()) * 0.5 * exaggeration, s.poiDetail);
118
// check if draw polygon
119
if (getIcon() != POIIcon::NONE) {
120
// translate
121
glTranslated(0, 0, 0.1);
122
// rotate
123
glRotated(180, 0, 0, 1);
124
// draw texture
125
GUITexturesHelper::drawTexturedBox(GUITextureSubSys::getPOITexture(getIcon()), exaggeration * 0.8);
126
}
127
}
128
GLHelper::popMatrix();
129
if (!s.drawForRectangleSelection) {
130
const Position namePos = *this;
131
drawName(namePos, s.scale, s.poiName, s.angle);
132
if (s.poiType.show(this)) {
133
const Position p = namePos + Position(0, -0.6 * s.poiType.size / s.scale);
134
GLHelper::drawTextSettings(s.poiType, getShapeType(), p, s.scale, s.angle);
135
}
136
if (s.poiText.show(this)) {
137
GLHelper::pushMatrix();
138
glTranslated(x(), y(), 0);
139
std::string value = getParameter(s.poiTextParam, "");
140
if (value != "") {
141
auto lines = StringTokenizer(value, StringTokenizer::NEWLINE).getVector();
142
glRotated(-s.angle, 0, 0, 1);
143
glTranslated(0, 0.7 * s.poiText.scaledSize(s.scale) * (double)lines.size(), 0);
144
glRotated(s.angle, 0, 0, 1);
145
// FONS_ALIGN_LEFT = 1
146
// FONS_ALIGN_CENTER = 2
147
// FONS_ALIGN_MIDDLE = 16
148
const int align = (lines.size() > 1 ? 1 : 2) | 16;
149
for (std::string& line : lines) {
150
GLHelper::drawTextSettings(s.poiText, line, Position(0, 0), s.scale, s.angle, GLO_MAX, align);
151
glRotated(-s.angle, 0, 0, 1);
152
glTranslated(0, -0.7 * s.poiText.scaledSize(s.scale), 0);
153
glRotated(s.angle, 0, 0, 1);
154
}
155
}
156
GLHelper::popMatrix();
157
}
158
}
159
// pop name
160
GLHelper::popName();
161
}
162
}
163
164
165
bool
166
GUIPointOfInterest::checkDraw(const GUIVisualizationSettings& s, const GUIGlObject* o) {
167
// only continue if scale is valid
168
if (s.scale * (1.3 / 3.0) * o->getExaggeration(s) < s.poiSize.minSize) {
169
return false;
170
}
171
return true;
172
}
173
174
175
void
176
GUIPointOfInterest::setPOIColor(const GUIVisualizationSettings& s, const RGBColor& shapeColor, const GUIGlObject* o, const bool disableSelectionColor) {
177
const GUIColorer& c = s.poiColorer;
178
const int active = c.getActive();
179
if (s.netedit && active != 1 && gSelected.isSelected(o->getType(), o->getGlID()) && disableSelectionColor) {
180
// override with special colors (unless the color scheme is based on selection)
181
GLHelper::setColor(RGBColor(0, 0, 204));
182
} else if (active == 0) {
183
GLHelper::setColor(shapeColor);
184
} else if (active == 1) {
185
GLHelper::setColor(c.getScheme().getColor(gSelected.isSelected(o->getType(), o->getGlID())));
186
} else {
187
GLHelper::setColor(c.getScheme().getColor(0));
188
}
189
}
190
191
/****************************************************************************/
192
193