Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUILaneSpeedTrigger.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-2024 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// Changes the speed allowed on a set of lanes (gui version)
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
27#include <utils/geom/Boundary.h>
31#include <microsim/MSNet.h>
32#include <microsim/MSLane.h>
33#include <microsim/MSEdge.h>
34#include <guisim/GUINet.h>
35#include <guisim/GUIEdge.h>
36#include "GUILaneSpeedTrigger.h"
39#include <gui/GUIGlobals.h>
48
49
50// ===========================================================================
51// FOX callback mapping
52// ===========================================================================
53/* -------------------------------------------------------------------------
54 * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - mapping
55 * ----------------------------------------------------------------------- */
61
62// Object implementation
64
65
66/* -------------------------------------------------------------------------
67 * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - mapping
68 * ----------------------------------------------------------------------- */
77
78FXIMPLEMENT(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger, GUIManipulator, GUIManip_LaneSpeedTriggerMap, ARRAYNUMBER(GUIManip_LaneSpeedTriggerMap))
79
80
81// ===========================================================================
82// method definitions
83// ===========================================================================
84/* -------------------------------------------------------------------------
85 * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - methods
86 * ----------------------------------------------------------------------- */
88 GUIMainWindow& app,
89 const std::string& name, GUILaneSpeedTrigger& o,
90 int /*xpos*/, int /*ypos*/)
91 : GUIManipulator(app, name, 0, 0),
92 myParent(&app), myChosenValue(0), myChosenTarget(myChosenValue, nullptr, MID_OPTION),
93 mySpeed(o.getDefaultSpeed()), mySpeedTarget(mySpeed),
94 myObject(&o) {
95 myChosenTarget.setTarget(this);
96 FXVerticalFrame* f1 =
97 new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
98
99 FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
100 GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
101 0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
102 {
103 // default
104 FXHorizontalFrame* gf1 =
105 new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
106 new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
107 ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
108 0, 0, 0, 0, 2, 2, 0, 0);
109 }
110 {
111 // loaded
112 FXHorizontalFrame* gf0 =
113 new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
114 new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
115 ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
116 0, 0, 0, 0, 2, 2, 0, 0);
117 }
118 {
119 // predefined
120 FXHorizontalFrame* gf2 =
121 new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
122 new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
123 ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
124 0, 0, 0, 0, 2, 2, 0, 0);
125 myPredefinedValues =
126 new MFXComboBoxIcon(gf2, 10, false, GUIDesignComboBoxVisibleItemsSmall, this, MID_PRE_DEF,
127 ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
128 myPredefinedValues->appendIconItem("20 km/h");
129 myPredefinedValues->appendIconItem("40 km/h");
130 myPredefinedValues->appendIconItem("60 km/h");
131 myPredefinedValues->appendIconItem("80 km/h");
132 myPredefinedValues->appendIconItem("100 km/h");
133 myPredefinedValues->appendIconItem("120 km/h");
134 myPredefinedValues->appendIconItem("140 km/h");
135 myPredefinedValues->appendIconItem("160 km/h");
136 myPredefinedValues->appendIconItem("180 km/h");
137 myPredefinedValues->appendIconItem("200 km/h");
138 }
139 {
140 // free
141 FXHorizontalFrame* gf12 =
142 new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
143 new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
144 ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
145 0, 0, 0, 0, 2, 2, 0, 0);
146 myUserDefinedSpeed =
147 new FXRealSpinner(gf12, 10, this, MID_USER_DEF,
148 LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
149 //myUserDefinedSpeed->setFormatString("%.0f km/h");
150 //myUserDefinedSpeed->setIncrements(1, 10, 10);
151 myUserDefinedSpeed->setIncrement(10);
152 myUserDefinedSpeed->setRange(0, 300);
153 myUserDefinedSpeed->setValue(myObject->getDefaultSpeed() * 3.6);
154 }
155 GUIDesigns::buildFXButton(f1, "Close", "", "", nullptr, this, MID_CLOSE,
156 BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
157 myObject->setOverriding(true);
158}
159
160
162
163
164long
166 destroy();
167 return 1;
168}
169
170
171long
173 mySpeed = myUserDefinedSpeed->getValue() / 3.6;
174 myObject->setOverridingValue(mySpeed);
175 myParent->updateChildren();
176 return 1;
177}
178
179
180long
181GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger::onUpdUserDef(FXObject* sender, FXSelector, void* ptr) {
182 sender->handle(this,
183 myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
184 ptr);
185 myParent->updateChildren();
186 return 1;
187}
188
189
190long
192 mySpeed = ((double)myPredefinedValues->getCurrentItem() * 20. + 20.) / 3.6;
193 myObject->setOverridingValue(mySpeed);
194 myParent->updateChildren();
195 return 1;
196}
197
198
199long
200GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger::onUpdPreDef(FXObject* sender, FXSelector, void* ptr) {
201 sender->handle(this,
202 myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
203 ptr);
204 myParent->updateChildren();
205 return 1;
206}
207
208
209long
211 myObject->setOverriding(true);
212 switch (myChosenValue) {
213 case 0:
214 mySpeed = myObject->getDefaultSpeed();
215 break;
216 case 1:
217 mySpeed = myObject->getLoadedSpeed();
218 break;
219 case 2:
220 mySpeed = ((double)myPredefinedValues->getCurrentItem() * 20. + 20.) / 3.6;
221 break;
222 case 3:
223 mySpeed = myUserDefinedSpeed->getValue() / 3.6;
224 break;
225 default:
226 // hmmm, should not happen
227 break;
228 }
229 myObject->setOverridingValue(mySpeed);
230 myParent->updateChildren();
231 if (myChosenValue == 1) {
232 // !!! lock in between
233 myObject->setOverriding(false);
234 }
235 return 1;
236}
237
238
239
240/* -------------------------------------------------------------------------
241 * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - methods
242 * ----------------------------------------------------------------------- */
247
248
250
251
252long
254 FXSelector,
255 void*) {
256 static_cast<GUILaneSpeedTrigger*>(myObject)->openManipulator(
257 *myApplication, *myParent);
258 return 1;
259}
260
261// -------------------------------------------------------------------------
262// GUILaneSpeedTrigger - methods
263// -------------------------------------------------------------------------
264
266 const std::string& id, const std::vector<MSLane*>& destLanes,
267 const std::string& aXMLFilename) :
268 MSLaneSpeedTrigger(id, destLanes, aXMLFilename),
270 myShowAsKMH(true), myLastValue(-1) {
271 myFGPositions.reserve(destLanes.size());
272 myFGRotations.reserve(destLanes.size());
273 std::vector<MSLane*>::const_iterator i;
274 for (i = destLanes.begin(); i != destLanes.end(); ++i) {
275 const PositionVector& v = (*i)->getShape();
276 myFGPositions.push_back(v.positionAtOffset(0));
278 myFGRotations.push_back(-v.rotationDegreeAtOffset(0));
279 }
280}
281
282
284
285
299
300
305 // add items
306 ret->mkItem(TL("speed [m/s]"), true,
308 // close building
309 ret->closeBuilding();
310 return ret;
311}
312
313
314void
318 glTranslated(0, 0, getType());
319 const double exaggeration = getExaggeration(s);
320 for (int i = 0; i < (int)myFGPositions.size(); ++i) {
321 const Position& pos = myFGPositions[i];
322 double rot = myFGRotations[i];
324 glTranslated(pos.x(), pos.y(), 0);
325 glRotated(rot, 0, 0, 1);
326 glTranslated(0, -1.5, 0);
327 glScaled(exaggeration, exaggeration, 1);
328 int noPoints = 9;
329 if (s.scale > 25) {
330 noPoints = (int)(9.0 + s.scale / 10.0);
331 if (noPoints > 36) {
332 noPoints = 36;
333 }
334 }
335 glColor3d(1, 0, 0);
336 GLHelper::drawFilledCircle((double) 1.3, noPoints);
337 if (s.scale >= 5) {
338 glTranslated(0, 0, .1);
339 glColor3d(0, 0, 0);
340 GLHelper::drawFilledCircle((double) 1.1, noPoints);
341 // draw the speed string
342 // not if scale to low
343 // compute
344 double value = (double) getCurrentSpeed();
345 if (myShowAsKMH) {
346 value *= 3.6f;
347 if (((int) value + 1) % 10 == 0) {
348 value = (double)(((int) value + 1) / 10 * 10);
349 }
350 }
351 if (value != myLastValue) {
352 myLastValue = value;
353 myLastValueString = toString<double>(myLastValue);
354 std::string::size_type idx = myLastValueString.find('.');
355 if (idx != std::string::npos) {
356 if (idx > myLastValueString.length()) {
357 idx = myLastValueString.length();
358 }
359 myLastValueString = myLastValueString.substr(0, idx);
360 }
361 }
362 //draw
363 glColor3d(1, 1, 0);
364 glTranslated(0, 0, .1);
365 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
366 // draw last value string
367 GLHelper::drawText(myLastValueString.c_str(), Position(0, 0), .1, 1.2, RGBColor(255, 255, 0), 180);
368 }
370 }
372 drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
374}
375
376
377double
381
382
386 b.grow(20);
387 return b;
388}
389
390
395 new GUIManip_LaneSpeedTrigger(app, getFullName(), *this, 0, 0);
396 gui->create();
397 gui->show();
398 return gui;
399}
400
401
402/****************************************************************************/
@ MID_MANIP
Open the object's manipulator.
Definition GUIAppEnum.h:489
#define GUIDesignComboBoxVisibleItemsSmall
Definition GUIDesigns.h:49
@ GLO_VSS
a Variable Speed Sign
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ VARIABLESPEEDSIGN
GUILaneSpeedTriggerPopupMenuMap[]
FXDEFMAP(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger) GUIManip_LaneSpeedTriggerMap[]
#define TL(string)
Definition MsgHandler.h:315
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:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:343
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:139
static void drawFilledCircle(const double widradiusth, const int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:569
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void popName()
pop Name
Definition GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition GLHelper.cpp:756
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
The popup menu of a globject.
void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the manipulator window.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
const std::string & getFullName() const
Definition GUIGlObject.h:94
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
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
long onCmdOpenManip(FXObject *, FXSelector, void *)
Called if the object's manipulator shall be shown.
long onCmdClose(FXObject *, FXSelector, void *)
long onCmdChangeOption(FXObject *, FXSelector, void *)
long onUpdPreDef(FXObject *, FXSelector, void *)
long onCmdUserDef(FXObject *, FXSelector, void *)
long onCmdPreDef(FXObject *, FXSelector, void *)
long onUpdUserDef(FXObject *, FXSelector, void *)
Changes the speed allowed on a set of lanes (gui version)
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string myLastValueString
Storage for speed string to avoid recomputation.
GUIManipulator * openManipulator(GUIMainWindow &app, GUISUMOAbstractView &parent)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
bool myShowAsKMH
The information whether the speed shall be shown in m/s or km/h.
PosCont myFGPositions
The positions in full-geometry mode.
RotCont myFGRotations
The rotations in full-geometry mode.
double myLastValue
Storage for last value to avoid string recomputation.
Boundary myBoundary
The boundary of this rerouter.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
GUILaneSpeedTrigger(const std::string &id, const std::vector< MSLane * > &destLanes, const std::string &file)
Constructor.
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.
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
GUIVisualizationSizeSettings addSize
double scale
information about a lane's width (temporary, used for a single view)
ComboBox with icon.
Changes the speed allowed on a set of lanes.
double getCurrentSpeed() const
Returns the current speed.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:55
double y() const
Returns the y-position.
Definition Position.h:60
A list of positions.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition json.hpp:4471
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values