Eclipse SUMO - Simulation of Urban MObility
GUIPointOfInterest.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 #include <config.h>
23 
33 #include <utils/gui/div/GLHelper.h>
35 #include "GUIPointOfInterest.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 
42 GUIPointOfInterest::GUIPointOfInterest(const std::string& id, const std::string& type,
43  const RGBColor& color, const Position& pos, bool geo, const std::string& lane,
44  double posOverLane, bool friendlyPos, double posLat, double layer, double angle,
45  const std::string& imgFile, bool relativePath, double width, double height) :
46  PointOfInterest(id, type, color, pos, geo, lane, posOverLane, friendlyPos, posLat, layer, angle, imgFile, relativePath, width, height),
48 }
49 
50 
52 
53 
56  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
57  // build shape header
59  return ret;
60 }
61 
62 
65  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
66  // add items
67  ret->mkItem("type", false, getShapeType());
68  ret->mkItem("layer", false, getShapeLayer());
69  ret->closeBuilding(this);
70  return ret;
71 }
72 
73 
74 double
76  return s.poiSize.getExaggeration(s, this);
77 }
78 
79 
82  Boundary b;
83  b.add(x(), y());
87  } else {
88  b.grow(3);
89  }
90  return b;
91 }
92 
93 
94 void
96  // check if POI can be drawn
97  if (checkDraw(s, this)) {
98  // push name (needed for getGUIGlObjectsUnderCursor(...)
100  // draw inner polygon
101  drawInnerPOI(s, this, this, false, getShapeLayer(), getWidth(), getHeight());
102  // pop name
104  }
105 }
106 
107 
108 bool
110  // only continue if scale is valid
111  if (s.scale * (1.3 / 3.0) * o->getExaggeration(s) < s.poiSize.minSize) {
112  return false;
113  }
114  return true;
115 }
116 
117 
118 void
119 GUIPointOfInterest::setColor(const GUIVisualizationSettings& s, const PointOfInterest* POI, const GUIGlObject* o, bool disableSelectionColor) {
120  const GUIColorer& c = s.poiColorer;
121  const int active = c.getActive();
122  if (s.netedit && active != 1 && gSelected.isSelected(GLO_POI, o->getGlID()) && disableSelectionColor) {
123  // override with special colors (unless the color scheme is based on selection)
124  GLHelper::setColor(RGBColor(0, 0, 204));
125  } else if (active == 0) {
126  GLHelper::setColor(POI->getShapeColor());
127  } else if (active == 1) {
129  } else {
131  }
132 }
133 
134 
135 void
137  const bool disableSelectionColor, const double layer, const double width, const double height) {
138  const double exaggeration = o->getExaggeration(s);
140  setColor(s, POI, o, disableSelectionColor);
141  glTranslated(POI->x(), POI->y(), layer);
142  glRotated(-POI->getShapeNaviDegree(), 0, 0, 1);
143  // check if has to be drawn as a circle or with an image
144  if (POI->getShapeImgFile() != DEFAULT_IMG_FILE) {
145  int textureID = GUITexturesHelper::getTextureID(POI->getShapeImgFile());
146  if (textureID > 0) {
148  width * -0.5 * exaggeration, height * -0.5 * exaggeration,
149  width * 0.5 * exaggeration, height * 0.5 * exaggeration);
150  }
151  } else {
152  // fallback if no image is defined
153  if (s.drawForPositionSelection) {
154  GLHelper::drawFilledCircle((double) 1.3 * exaggeration, MIN2(8, s.poiDetail));
155  } else {
156  // draw filled circle saving vertices
157  GLHelper::drawFilledCircle((double) 1.3 * exaggeration, s.poiDetail);
158  }
159  }
161  if (!s.drawForRectangleSelection) {
162  const Position namePos = *POI;
163  o->drawName(namePos, s.scale, s.poiName, s.angle);
164  if (s.poiType.show(o)) {
165  const Position p = namePos + Position(0, -0.6 * s.poiType.size / s.scale);
166  GLHelper::drawTextSettings(s.poiType, POI->getShapeType(), p, s.scale, s.angle);
167  }
168  if (s.poiText.show(o)) {
170  glTranslated(POI->x(), POI->y(), 0);
171  std::string value = POI->getParameter(s.poiTextParam, "");
172  if (value != "") {
173  auto lines = StringTokenizer(value, StringTokenizer::NEWLINE).getVector();
174  glRotated(-s.angle, 0, 0, 1);
175  glTranslated(0, 0.7 * s.poiText.scaledSize(s.scale) * lines.size(), 0);
176  glRotated(s.angle, 0, 0, 1);
177  // FONS_ALIGN_LEFT = 1
178  // FONS_ALIGN_CENTER = 2
179  // FONS_ALIGN_MIDDLE = 16
180  const int align = (lines.size() > 1 ? 1 : 2) | 16;
181  for (std::string& line : lines) {
182  GLHelper::drawTextSettings(s.poiText, line, Position(0, 0), s.scale, s.angle, GLO_MAX, align);
183  glRotated(-s.angle, 0, 0, 1);
184  glTranslated(0, -0.7 * s.poiText.scaledSize(s.scale), 0);
185  glRotated(s.angle, 0, 0, 1);
186  }
187  }
189  }
190  }
191 }
192 
193 
194 /****************************************************************************/
@ GLO_MAX
empty max
@ GLO_POI
a poi
GUISelectedStorage gSelected
A global holder of selected objects.
T MIN2(T a, T b)
Definition: StdDefs.h:74
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:77
void growHeight(double by)
Increases the height of the boundary (y-axis)
Definition: Boundary.cpp:324
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
void growWidth(double by)
Increases the width of the boundary (x-axis)
Definition: Boundary.cpp:317
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:431
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
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:640
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
virtual double getExaggeration(const GUIVisualizationSettings &s) const =0
return exaggeration asociated 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.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
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, double layer, double angle, const std::string &imgFile, bool relativePath, double width, double height)
Constructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
static bool checkDraw(const GUIVisualizationSettings &s, const GUIGlObject *o)
check if POI can be drawn
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
static void drawInnerPOI(const GUIVisualizationSettings &s, const PointOfInterest *POI, const GUIGlObject *o, const bool disableSelectionColor, const double layer, const double width, const double height)
draw inner POI (before pushName() )
virtual ~GUIPointOfInterest()
Destructor.
static void setColor(const GUIVisualizationSettings &s, const PointOfInterest *POI, const GUIGlObject *o, bool forceSelectionColor)
set color
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
const 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 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 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
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
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.
Definition: GUI.h:31
A point-of-interest.
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.
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:55
double y() const
Returns the y-position.
Definition: Position.h:60
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:104
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:46
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:90
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:76
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