Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIPointOfInterest.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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/****************************************************************************/
20// The GUI-version of a point of interest
21/****************************************************************************/
22
30
31#include "GUIPointOfInterest.h"
32
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37
38GUIPointOfInterest::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),
44 (lane.size() > 0) ? GUIIconSubSys::getIcon(GUIIcon::POILANE) : geo ? GUIIconSubSys::getIcon(GUIIcon::POIGEO) : GUIIconSubSys::getIcon(GUIIcon::POI)) {
45}
46
47
49
50
53 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
54 // build shape header
56 return ret;
57}
58
59
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
72double
76
77
80 Boundary b;
81 b.add(x(), y());
85 } else {
86 b.grow(3);
87 }
88 return b;
89}
90
91
92void
94 // check if POI can be drawn
95 if (checkDraw(s, this)) {
96 // push name (needed for getGUIGlObjectsUnderCursor(...)
98 // draw inner polygon
99 const double exaggeration = getExaggeration(s);
100 const double layer = s.poiUseCustomLayer ? s.poiCustomLayer : getShapeLayer();
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
110 if (textureID > 0) {
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
126 }
127 }
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);
135 }
136 if (s.poiText.show(this)) {
138 glTranslated(x(), y(), 0);
139 std::string value = getParameter(s.poiTextParam, "");
140 if (value != "") {
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 }
157 }
158 }
159 // pop name
161 }
162}
163
164
165bool
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
175void
176GUIPointOfInterest::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) {
186 } else {
188 }
189}
190
191/****************************************************************************/
@ GLO_MAX
empty max
@ GLO_POI
poi (over view, geo and lane)
GUISelectedStorage gSelected
A global holder of selected objects.
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:75
void growHeight(double by)
Increases the height of the boundary (y-axis)
Definition Boundary.cpp:366
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:340
void growWidth(double by)
Increases the width of the boundary (x-axis)
Definition Boundary.cpp:359
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:140
static void drawFilledCircle(const double widradiusth, const int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:564
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void popName()
pop Name
Definition GLHelper.cpp:149
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition GLHelper.cpp:773
The popup menu of a globject.
void buildShapePopupOptions(GUIMainWindow &app, GUIGLObjectPopupMenu *ret, const std::string &type)
build basic shape popup options. Used to unify pop-ups menu in netedit and SUMO-GUI
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
GUIGlID getGlID() const
Returns the numerical id of the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
static void setPOIColor(const GUIVisualizationSettings &s, const RGBColor &shapeColor, const GUIGlObject *o, const bool forceSelectionColor)
set POI color
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own parameter window.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
GUIPointOfInterest(const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, const std::string &lane, double posOverLane, bool friendlyPos, double posLat, const std::string &icon, double layer, double angle, const std::string &imgFile, double width, double height)
Constructor.
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
static bool checkDraw(const GUIVisualizationSettings &s, const GUIGlObject *o)
check if POI can be drawn
virtual ~GUIPointOfInterest()
Destructor.
T getColor(const double value) const
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
static GUIGlID getPOITexture(POIIcon POIIcon)
returns texture associated to the given POI image
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
Stores the information about how to visualize structures.
bool poiUseCustomLayer
whether the rendering layer of POIs should be overriden
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationTextSettings poiType
GUIVisualizationSizeSettings poiSize
GUIColorer poiColorer
The POI colorer.
GUIVisualizationTextSettings poiName
double poiCustomLayer
the custom layer for POIs
double scale
information about a lane's width (temporary, used for a single view)
bool netedit
Whether the settings are for Netedit.
GUIVisualizationTextSettings poiText
std::string poiTextParam
key for rendering poi textual parameter
int poiDetail
The detail level for drawing POIs.
double angle
The current view rotation angle.
C++ TraCI client API implementation.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
A point-of-interest.
POIIcon getIcon() const
get icon
double myHalfImgHeight
The half height of the image when rendering this POI.
double getHeight() const
Returns the image height of the POI.
double getWidth() const
Returns the image width of the POI.
const std::string & getIconStr() const
get icon(in string format)
double myHalfImgWidth
The half width of the image when rendering this POI.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
Position()
default constructor
Definition Position.h:40
double x() const
Returns the x-position.
Definition Position.h:52
double y() const
Returns the y-position.
Definition Position.h:57
static const std::string DEFAULT_IMG_FILE
Definition Shape.h:47
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition Shape.cpp:103
double getShapeLayer() const
Returns the layer of the Shape.
Definition Shape.cpp:115
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition Shape.cpp:127
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition Shape.cpp:109
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition Shape.cpp:121
static const int NEWLINE
identifier for splitting the given string at all newline characters
std::vector< std::string > getVector()
return vector of strings
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
double minSize
The minimum size to draw this object.
bool show(const GUIGlObject *o) const
whether to show the text
double scaledSize(double scale, double constFactor=0.1) const
get scale size