Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUINet.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-2023 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/****************************************************************************/
21// A MSNet extended by some values for usage within the gui
22/****************************************************************************/
23#include <config.h>
24
25#include <utility>
26#include <set>
27#include <vector>
28#include <map>
37#include <utils/xml/XMLSubSys.h>
42#include <microsim/MSNet.h>
44#include <microsim/MSJunction.h>
46#include <microsim/MSEdge.h>
53#include <guisim/GUIEdge.h>
54#include <guisim/GUILane.h>
62#include <gui/GUIGlobals.h>
64#include "GUINet.h"
65
67
68
69// ===========================================================================
70// definition of static variables used for visualisation of objects' values
71// ===========================================================================
72template std::vector< GLObjectValuePassConnector<double>* > GLObjectValuePassConnector<double>::myContainer;
74
75template std::vector< GLObjectValuePassConnector<std::pair<int, class MSPhaseDefinition> >* > GLObjectValuePassConnector<std::pair<int, class MSPhaseDefinition> >::myContainer;
77
78
79// ===========================================================================
80// member method definitions
81// ===========================================================================
83 MSEventControl* endOfTimestepEvents,
84 MSEventControl* insertionEvents) :
85 MSNet(vc, beginOfTimestepEvents, endOfTimestepEvents, insertionEvents, new GUIShapeContainer(myGrid)),
86 GUIGlObject(GLO_NETWORK, "", nullptr),
87 myLastSimDuration(0), /*myLastVisDuration(0),*/ myLastIdleDuration(0),
88 myLastVehicleMovementCount(0), myOverallVehicleCount(0), myOverallSimDuration(0) {
90}
91
92
94 if (myLock.locked()) {
95 myLock.unlock();
96 }
97 // delete allocated wrappers
98 // of junctions
99 for (std::vector<GUIJunctionWrapper*>::iterator i1 = myJunctionWrapper.begin(); i1 != myJunctionWrapper.end(); i1++) {
100 delete (*i1);
101 }
102 // of additional structures
104 // of tl-logics
105 for (Logics2WrapperMap::iterator i3 = myLogics2Wrapper.begin(); i3 != myLogics2Wrapper.end(); i3++) {
106 delete (*i3).second;
107 }
108 // of detectors
109 for (std::vector<GUIDetectorWrapper*>::iterator i = myDetectorWrapper.begin(); i != myDetectorWrapper.end(); ++i) {
110 delete *i;
111 }
112 // of calibrators
114 delete cw;
115 }
116 for (auto& item : myLoadedEdgeData) {
117 delete item.second;
118 }
119}
120
121
122const Boundary&
124 return myBoundary;
125}
126
127
130 if (myPersonControl == nullptr) {
132 }
133 return *myPersonControl;
134}
135
136
139 if (myContainerControl == nullptr) {
141 }
142 return *myContainerControl;
143}
144
145
146void
148 // go through the loaded tl-logics
149 for (MSTrafficLightLogic* const tll : getTLSControl().getAllLogics()) {
150 createTLWrapper(tll);
151 }
152}
153
154
155void
157 if (myLogics2Wrapper.count(tll) > 0) {
158 return;
159 }
160 // get the links
162 if (links.size() == 0) { // @legacy this should never happen in 0.13.0+ networks
163 return;
164 }
165 // build the wrapper
167 if (tll->knowsParameter("hotkeyAbort")) {
169 }
170 // build the association link->wrapper
171 MSTrafficLightLogic::LinkVectorVector::const_iterator j;
172 for (j = links.begin(); j != links.end(); ++j) {
173 MSTrafficLightLogic::LinkVector::const_iterator j2;
174 for (j2 = (*j).begin(); j2 != (*j).end(); ++j2) {
175 myLinks2Logic[*j2] = tll->getID();
176 }
177 }
179 myLogics2Wrapper[tll] = tllw;
180}
181
182
184GUINet::getJunctionPosition(const std::string& name) const {
185 // !!! no check for existance!
186 return myJunctions->get(name)->getPosition();
187}
188
189
190bool
191GUINet::vehicleExists(const std::string& name) const {
192 return myVehicleControl->getVehicle(name) != nullptr;
193}
194
195
196int
197GUINet::getLinkTLID(const MSLink* const link) const {
198 if (myLinks2Logic.count(link) == 0) {
199 assert(false);
200 return 0;
201 }
202 MSTrafficLightLogic* tll = myLogics->getActive(myLinks2Logic.find(link)->second);
203 if (myLogics2Wrapper.count(tll) == 0) {
204 // tll may have been added via traci. @see ticket #459
205 return 0;
206 }
207 return myLogics2Wrapper.find(tll)->second->getGlID();
208}
209
210
211int
212GUINet::getLinkTLIndex(const MSLink* const link) const {
213 Links2LogicMap::const_iterator i = myLinks2Logic.find(link);
214 if (i == myLinks2Logic.end()) {
215 return -1;
216 }
217 if (myLogics2Wrapper.find(myLogics->getActive((*i).second)) == myLogics2Wrapper.end()) {
218 return -1;
219 }
220 return myLogics2Wrapper.find(myLogics->getActive((*i).second))->second->getLinkIndex(link);
221}
222
223
224void
229
230
231void
233 FXMutexLock locker(myLock);
235}
236
237
238std::vector<GUIGlID>
239GUINet::getJunctionIDs(bool includeInternal) const {
240 std::vector<GUIGlID> ret;
241 for (std::vector<GUIJunctionWrapper*>::const_iterator i = myJunctionWrapper.begin(); i != myJunctionWrapper.end(); ++i) {
242 if (!(*i)->isInternal() || includeInternal) {
243 ret.push_back((*i)->getGlID());
244 }
245 }
246 return ret;
247}
248
249
250std::vector<GUIGlID>
252 std::vector<GUIGlID> ret;
253 std::vector<std::string> ids;
254 for (std::map<MSTrafficLightLogic*, GUITrafficLightLogicWrapper*>::const_iterator i = myLogics2Wrapper.begin(); i != myLogics2Wrapper.end(); ++i) {
255 std::string sid = (*i).second->getMicrosimID();
256 if (find(ids.begin(), ids.end(), sid) == ids.end()) {
257 ret.push_back((*i).second->getGlID());
258 ids.push_back(sid);
259 }
260 }
261 return ret;
262}
263
264
265void
267 // initialise detector storage for gui
268 const std::vector<SumoXMLTag> types = myDetectorControl->getAvailableTypes();
269 for (std::vector<SumoXMLTag>::const_iterator i = types.begin(); i != types.end(); ++i) {
270 for (const auto& j : myDetectorControl->getTypedDetectors(*i)) {
271 GUIDetectorWrapper* wrapper = j.second->buildDetectorGUIRepresentation();
272 if (wrapper != nullptr) {
273 myDetectorWrapper.push_back(wrapper);
275 }
276 }
277 }
278 // let's always track emission parameters for the GUI
280 // initialise calibrators
281 for (auto& item : MSCalibrator::getInstances()) {
282 GUICalibrator* wrapper = new GUICalibrator(item.second);
283 myCalibratorWrapper.push_back(wrapper);
285 }
286 // initialise the tl-map
287 initTLMap();
288 // initialise edge storage for gui
289 const MSEdgeVector& edges = MSEdge::getAllEdges();
290 myEdgeWrapper.reserve(edges.size());
291 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
292 // VISIM connector edges shall be drawn (they have lanes)
293 if (!(*i)->isTazConnector() || (*i)->getLanes().size() > 0) {
294 myEdgeWrapper.push_back(static_cast<GUIEdge*>(*i));
295 }
296 }
297 // initialise junction storage for gui
298 int size = myJunctions->size();
299 myJunctionWrapper.reserve(size);
300 std::map<MSJunction*, std::string> junction2TLL;
301 for (const auto tls : getTLSControl().getAllLogics()) {
302 for (const auto& links : tls->getLinks()) {
303 for (const MSLink* l : links) {
304 junction2TLL[l->getJunction()] = l->getTLLogic()->getID();
305 }
306 }
307 }
308 for (const auto& i : *myJunctions) {
309 myJunctionWrapper.push_back(new GUIJunctionWrapper(*i.second, junction2TLL[i.second]));
310 }
311 // build the visualization tree
312 for (std::vector<GUIEdge*>::iterator i = myEdgeWrapper.begin(); i != myEdgeWrapper.end(); ++i) {
313 GUIEdge* edge = *i;
314 Boundary b;
315 const std::vector<MSLane*>& lanes = edge->getLanes();
316 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
317 b.add((*j)->getShape().getBoxBoundary());
318 }
319 // make sure persons are always drawn and selectable since they depend on their edge being drawn
320 b.grow(MSPModel::SIDEWALK_OFFSET + 1 + lanes.front()->getWidth() / 2);
321 const float cmin[2] = { (float)b.xmin(), (float)b.ymin() };
322 const float cmax[2] = { (float)b.xmax(), (float)b.ymax() };
323 myGrid.Insert(cmin, cmax, edge);
324 myBoundary.add(b);
325 if (myBoundary.getWidth() > 10e16 || myBoundary.getHeight() > 10e16) {
326 throw ProcessError(TL("Network size exceeds 1 Lightyear. Please reconsider your inputs.\n"));
327 }
328 }
329 for (std::vector<GUIJunctionWrapper*>::iterator i = myJunctionWrapper.begin(); i != myJunctionWrapper.end(); ++i) {
330 GUIJunctionWrapper* junction = *i;
331 Boundary b = junction->getBoundary();
332 b.grow(2.);
333 const float cmin[2] = { (float)b.xmin(), (float)b.ymin() };
334 const float cmax[2] = { (float)b.xmax(), (float)b.ymax() };
335 myGrid.Insert(cmin, cmax, junction);
336 myBoundary.add(b);
337 }
339
340 if (OptionsCont::getOptions().isSet("alternative-net-file")) {
341 // build secondary visualization tree
342 for (GUIEdge* edge : myEdgeWrapper) {
343 Boundary b;
344 for (MSLane* lane : edge->getLanes()) {
345 b.add(static_cast<GUILane*>(lane)->getShape(true).getBoxBoundary());
346 }
347 // make sure persons are always drawn and selectable since they depend on their edge being drawn
349 const float cmin[2] = { (float)b.xmin(), (float)b.ymin() };
350 const float cmax[2] = { (float)b.xmax(), (float)b.ymax() };
351 myGrid2.Insert(cmin, cmax, edge);
352 }
353 for (std::vector<GUIJunctionWrapper*>::iterator i = myJunctionWrapper.begin(); i != myJunctionWrapper.end(); ++i) {
354 GUIJunctionWrapper* junction = *i;
355 Position pos = junction->getJunction().getPosition(true);
356 Boundary b = Boundary(pos.x() - 3., pos.y() - 3., pos.x() + 3., pos.y() + 3.);
357 const float cmin[2] = { (float)b.xmin(), (float)b.ymin() };
358 const float cmax[2] = { (float)b.xmax(), (float)b.ymax() };
359 myGrid2.Insert(cmin, cmax, junction);
360 }
361 }
362}
363
364
365void
374
375
376int
378 return myLastSimDuration +/*myLastVisDuration+*/myLastIdleDuration;
379}
380
381
382int
384 return myLastSimDuration;
385}
386
387/*
388int
389GUINet::getVisDuration() const
390{
391 return myLastVisDuration;
392}
393*/
394
395
396double
398 if (myLastSimDuration == 0) {
399 return -1;
400 }
401 return (double)DELTA_T / (double)myLastSimDuration;
402}
403
404
405double
407 if (myLastSimDuration == 0) {
408 return -1;
409 }
410 return (double) myLastVehicleMovementCount / (double) myLastSimDuration * (double) 1000.;
411}
412
413
414double
415GUINet::getMeanRTFactor(int duration) const {
416 if (myOverallSimDuration == 0) {
417 return -1;
418 }
419 return ((double)(duration) * (double) 1000. / (double)myOverallSimDuration);
420}
421
422
423double
425 if (myOverallSimDuration == 0) {
426 return -1;
427 }
428 return ((double)myVehiclesMoved / (double)myOverallSimDuration * (double) 1000.);
429}
430
431
432int
436
437
438void
445
446/*
447void
448GUINet::setVisDuration(int val)
449{
450 myLastVisDuration = val;
451}
452*/
453
454void
458
459
462 GUISUMOAbstractView& parent) {
463 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
464 buildPopupHeader(ret, app);
467 buildPositionCopyEntry(ret, app);
468 if (GeoConvHelper::getFinal().usingGeoProjection()) {
469 GUIDesigns::buildFXMenuCommand(ret, "Copy view geo-boundary to clipboard", nullptr, ret, MID_COPY_VIEW_GEOBOUNDARY);
470 }
471 return ret;
472}
473
474
477 GUISUMOAbstractView& parent) {
479 // add items
480 ret->mkItem("loaded vehicles [#]", true,
482 ret->mkItem("insertion-backlogged vehicles [#]", true,
484 ret->mkItem("departed vehicles [#]", true,
486 ret->mkItem("running vehicles [#]", true,
488 ret->mkItem("arrived vehicles [#]", true,
490 ret->mkItem("discarded vehicles [#]", true,
492 ret->mkItem("collisions [#]", true,
494 ret->mkItem("teleports [#]", true,
496 ret->mkItem("halting [#]", true,
498 ret->mkItem("stopped [#]", true,
500 ret->mkItem("avg. speed [m/s]", true,
502 ret->mkItem("avg. relative speed", true,
504 if (myPersonControl != nullptr) {
505 ret->mkItem("loaded persons [#]", true,
507 ret->mkItem("running persons [#]", true,
509 ret->mkItem("jammed persons [#]", true,
511 }
512 ret->mkItem("end time [s]", false, OptionsCont::getOptions().getString("end"));
513 ret->mkItem("begin time [s]", false, OptionsCont::getOptions().getString("begin"));
514// ret->mkItem("time step [s]", true, new FunctionBinding<GUINet, SUMOTime>(this, &GUINet::getCurrentTimeStep));
515 if (logSimulationDuration()) {
516 ret->mkItem("step duration [ms]", true, new FunctionBinding<GUINet, int>(this, &GUINet::getWholeDuration));
518 ret->mkItem("simulation duration [ms]", true, new FunctionBinding<GUINet, int>(this, &GUINet::getSimDuration));
519 /*
520 ret->mkItem("visualisation duration [ms]", true,
521 new CastingFunctionBinding<GUINet, double, int>(
522 &(getNet()), &GUINet::getVisDuration));
523 */
524 ret->mkItem("idle duration [ms]", true, new FunctionBinding<GUINet, int>(this, &GUINet::getIdleDuration));
525 ret->mkItem("duration factor", true, new FunctionBinding<GUINet, double>(this, &GUINet::getRTFactor));
526 /*
527 ret->mkItem("mean duration factor []", true,
528 new FuncBinding_IntParam<GUINet, double>(
529 &(getNet()), &GUINet::getMeanRTFactor), 1);
530 */
531 ret->mkItem("updates per second", true, new FunctionBinding<GUINet, double>(this, &GUINet::getUPS));
532 ret->mkItem("avg. updates per second", true, new FunctionBinding<GUINet, double>(this, &GUINet::getMeanUPS));
533 }
534 if (OptionsCont::getOptions().isSet("tripinfo-output") || OptionsCont::getOptions().getBool("duration-log.statistics")) {
535 ret->mkItem("avg. trip length [m]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgRouteLength));
536 ret->mkItem("avg. trip duration [s]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgDuration));
537 ret->mkItem("avg. trip waiting time [s]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgWaitingTime));
538 ret->mkItem("avg. trip time loss [s]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgTimeLoss));
539 ret->mkItem("avg. trip depart delay [s]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgDepartDelay));
540 ret->mkItem("avg. trip speed [m/s]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgTripSpeed));
541 if (myPersonControl != nullptr) {
542 ret->mkItem("avg. walk length [m]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgWalkRouteLength));
543 ret->mkItem("avg. walk duration [s]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgWalkDuration));
544 ret->mkItem("avg. walk time loss [s]", true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgWalkTimeLoss));
545 }
546 }
547 ret->mkItem("nodes [#]", false, (int)getJunctionIDs(false).size());
548 ret->mkItem("edges [#]", false, (int)GUIEdge::getIDs(false).size());
549 ret->mkItem("total edge length [km]", false, GUIEdge::getTotalLength(false, false) / 1000);
550 ret->mkItem("total lane length [km]", false, GUIEdge::getTotalLength(false, true) / 1000);
551 ret->mkItem("network version ", false, toString(myVersion));
552
553 // close building
554 ret->closeBuilding();
555 return ret;
556}
557
558
559void
561}
562
563
566 return getBoundary();
567}
568
569
570GUINet*
572 GUINet* net = dynamic_cast<GUINet*>(MSNet::getInstance());
573 if (net != nullptr) {
574 return net;
575 }
576 throw ProcessError("A gui-network was not yet constructed.");
577}
578
579
584
585
586void
588 myLock.lock();
589}
590
591
592void
594 myLock.unlock();
595}
596
601
602
603double
604GUINet::getEdgeData(const MSEdge* edge, const std::string& attr) {
605 auto it = myLoadedEdgeData.find(attr);
606 if (it != myLoadedEdgeData.end()) {
607 double value;
608 bool found = it->second->retrieveExistingEffort(edge, STEPS2TIME(getCurrentTimeStep()), value);
609 if (found) {
610 return value;
611 } else {
613 }
614 } else {
616 }
617}
618
619
620double
621GUINet::getMeanData(const MSLane* lane, const std::string& id, const std::string& attr) {
622 auto item = myDetectorControl->getMeanData().find(id);
623 if (item != myDetectorControl->getMeanData().end() && !item->second.empty()) {
625 return item->second.front()->getAttributeValue(lane, a, GUIVisualizationSettings::MISSING_DATA);
626 } else {
628 }
629}
630
631
632void
634 if (element == SUMO_TAG_EDGE || element == SUMO_TAG_LANE) {
635 std::vector<std::string> tmp = attrs.getAttributeNames();
636 edgeAttrs.insert(tmp.begin(), tmp.end());
637 } else if (element == SUMO_TAG_EDGEREL) {
638 for (const std::string& a : attrs.getAttributeNames()) {
639 if (a != "from" && a != "to") {
640 edgeAttrs.insert(a);
641 }
642 }
643 } else if (element == SUMO_TAG_INTERVAL) {
644 bool ok;
645 numIntervals++;
648 }
649}
650
651
652std::vector<std::string>
654 edgeAttrs.erase(toString(SUMO_ATTR_ID));
655 return std::vector<std::string>(edgeAttrs.begin(), edgeAttrs.end());
656}
657
658
659void
661 double value, double begTime, double endTime) const {
662 MSEdge* const edge = MSEdge::dictionary(id);
663 if (edge != nullptr) {
664 myWeightStorage->addEffort(edge, begTime, endTime, value);
665 } else {
666 WRITE_WARNINGF(TL("Trying to set data value for the unknown edge '%'."), id);
667 }
668}
669
670
671void
672GUINet::EdgeFloatTimeLineRetriever_GUI::addEdgeRelWeight(const std::string& from, const std::string& to,
673 double val, double beg, double end) const {
674 MSEdge* const fromEdge = MSEdge::dictionary(from);
675 MSEdge* const toEdge = MSEdge::dictionary(to);
676 bool haveRel = false;
677 if (fromEdge != nullptr && toEdge != nullptr) {
678 for (auto item : fromEdge->getViaSuccessors()) {
679 if (item.first == toEdge) {
680 const MSEdge* edge = item.second;
681 while (edge != nullptr && edge->isInternal()) {
682 myWeightStorage->addEffort(edge, beg, end, val);
683 edge = edge->getViaSuccessors().front().second;
684 haveRel = true;
685 }
686 }
687 }
688 }
689 if (!haveRel) {
690 WRITE_WARNINGF(TL("Trying to set data value for the unknown relation from edge '%' to edge '%'."), from, to);
691 }
692}
693
694
695bool
696GUINet::loadEdgeData(const std::string& file) {
697 // discover edge attributes
698 DiscoverAttributes discoveryHandler(file);
699 XMLSubSys::runParser(discoveryHandler, file);
700 std::vector<std::string> attrs = discoveryHandler.getEdgeAttrs();
701 WRITE_MESSAGE("Loading edgedata from '" + file + "':"
702 + "\n " + toString(discoveryHandler.numIntervals) + " intervals between"
703 + " " + time2string(discoveryHandler.firstIntervalBegin) + " and"
704 + " " + time2string(discoveryHandler.lastIntervalEnd)
705 + ".\n Found " + toString(attrs.size())
706 + " attributes: " + toString(attrs));
707 if (discoveryHandler.lastIntervalEnd < string2time(OptionsCont::getOptions().getString("begin"))) {
708 WRITE_WARNING(TL("No data defined after simulation begin time."));
709 }
711 // create a retriever for each attribute
712 std::vector<EdgeFloatTimeLineRetriever_GUI> retrieverDefsInternal;
713 retrieverDefsInternal.reserve(attrs.size());
714 std::vector<SAXWeightsHandler::ToRetrieveDefinition*> retrieverDefs;
715 for (const std::string& attr : attrs) {
717 myLoadedEdgeData[attr] = ws;
718 retrieverDefsInternal.push_back(EdgeFloatTimeLineRetriever_GUI(ws));
719 retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition(attr, true, retrieverDefsInternal.back()));
720 }
721 SAXWeightsHandler handler(retrieverDefs, "");
722 return XMLSubSys::runParser(handler, file);
723}
724
725
726std::vector<std::string>
728 std::vector<std::string> result;
729 for (const auto& item : myLoadedEdgeData) {
730 result.push_back(item.first);
731 }
732 return result;
733}
734
735
736std::vector<std::string>
738 std::vector<std::string> result;
739
740 for (auto item : myDetectorControl->getMeanData()) {
741 result.push_back(item.first);
742 }
743 std::sort(result.begin(), result.end());
744 return result;
745}
746
747std::vector<std::string>
748GUINet::getMeanDataAttrs(const std::string& meanDataID) const {
749 auto item = myDetectorControl->getMeanData().find(meanDataID);
750 if (item != myDetectorControl->getMeanData().end() && !item->second.empty()) {
751 return item->second.front()->getAttributeNames();
752 } else {
753 return std::vector<std::string>();
754 }
755}
756
757
758bool
760 const auto it = myLogics2Wrapper.find(const_cast<MSTrafficLightLogic*>(tll));
761 return it != myLogics2Wrapper.end() && gSelected.isSelected(GLO_TLLOGIC, it->second->getGlID());
762}
763
764void
766 try {
767 // gui only
769 // update the view
770 aw->handleEvent_SimulationStep(nullptr);
771 } catch (ProcessError&) { }
772}
773
774void
775GUINet::addHotkey(int key, Command* press, Command* release) {
776 try {
777 // gui only
779 // update the view
780 aw->addHotkey(key, press, release);
781 } catch (ProcessError&) { }
782}
783
784void
786 mySkipFinalReset = true;
789 // update tracker windows
791}
792
793#ifdef HAVE_OSG
794void
795GUINet::updateColor(const GUIVisualizationSettings& s) {
796 for (std::vector<GUIEdge*>::const_iterator i = myEdgeWrapper.begin(); i != myEdgeWrapper.end(); ++i) {
797 if (!(*i)->isInternal()) {
798 const std::vector<MSLane*>& lanes = (*i)->getLanes();
799 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
800 static_cast<GUILane*>(*j)->updateColor(s);
801 }
802 }
803 }
804 for (std::vector<GUIJunctionWrapper*>::iterator i = myJunctionWrapper.begin(); i != myJunctionWrapper.end(); ++i) {
805 (*i)->updateColor(s);
806 }
807}
808#endif
809
810
811/****************************************************************************/
@ MID_COPY_VIEW_GEOBOUNDARY
Copy view geo-coordinate boundary - popup entry.
Definition GUIAppEnum.h:458
@ GLO_NETWORK
The network - empty.
@ GLO_TLLOGIC
a tl-logic
GUISelectedStorage gSelected
A global holder of selected objects.
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:271
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:272
#define WRITE_WARNING(msg)
Definition MsgHandler.h:270
#define TL(string)
Definition MsgHandler.h:287
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define SIMSTEP
Definition SUMOTime.h:61
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_EDGEREL
a relation between two edges
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_EDGE
begin/end of the description of an edge
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
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
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:130
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:118
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:300
double getHeight() const
Returns the height of the boundary (y-axis)
Definition Boundary.cpp:160
double getWidth() const
Returns the width of the boudary (x-axis)
Definition Boundary.cpp:154
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:136
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:124
static bool registerHotkey(const std::string &key, MSTrafficLightLogic &tll)
register hotkey actions
Base (microsim) event class.
Definition Command.h:50
Class passing values from a GUIGlObject to another object.
static void updateAll()
Updates all instances (passes values)
The main window of the SUMO-gui.
void handleEvent_SimulationStep(GUIEvent *e)
called when event "simulation step" ocurred
void addHotkey(int key, Command *press, Command *release)
register custom hotkey action
Changes the speed allowed on a set of lanes (gui version)
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
A road/street connecting two junctions (gui-version)
Definition GUIEdge.h:51
static double getTotalLength(bool includeInternal, bool eachLane)
Definition GUIEdge.cpp:118
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition GUIEdge.cpp:103
The popup menu of a globject.
static void clearDictionary()
Clears the dictionary (the objects will not be deleted)
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
void setNetObject(GUIGlObject *object)
Sets the given object as the "network" object.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
static bool gSecondaryShape
whether secondary shapes are currently being drawn
Definition GUIGlobals.h:49
const MSJunction & getJunction() const
Returns the represented junction.
Boundary getBoundary() const
Returns the boundary of the junction.
Representation of a lane in the micro simulation (gui-version)
Definition GUILane.h:60
const PositionVector & getShape(bool secondary) const override
Definition GUILane.cpp:1060
The class responsible for building and deletion of vehicles (gui-version)
static GUIMainWindow * getInstance()
get instance
class for discovering edge attributes
Definition GUINet.h:419
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Callback method for an opening tag to implement by derived classes.
Definition GUINet.cpp:633
std::set< std::string > edgeAttrs
Definition GUINet.h:430
std::vector< std::string > getEdgeAttrs()
Definition GUINet.cpp:653
void addEdgeWeight(const std::string &id, double val, double beg, double end) const
Adds an effort for a given edge and time period.
Definition GUINet.cpp:660
void addEdgeRelWeight(const std::string &from, const std::string &to, double val, double beg, double end) const
Definition GUINet.cpp:672
A MSNet extended by some values for usage within the gui.
Definition GUINet.h:82
double getAvgTripSpeed() const
Definition GUINet.h:221
double getAvgRouteLength() const
Definition GUINet.h:206
double getAvgDuration() const
Definition GUINet.h:209
int getWholeDuration() const
Returns the duration of the last step (sim+visualisation+idle) (in ms)
Definition GUINet.cpp:377
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
Definition GUINet.cpp:565
void setIdleDuration(int val)
Sets the duration of the last step's idle part.
Definition GUINet.cpp:455
GUIVehicleControl * getGUIVehicleControl()
Returns the vehicle control.
Definition GUINet.cpp:581
void unlock()
release exclusive access to the simulation state
Definition GUINet.cpp:593
double getUPS() const
Returns the update per seconds rate.
Definition GUINet.cpp:406
bool loadEdgeData(const std::string &file)
load edgeData from file
Definition GUINet.cpp:696
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Definition GUINet.cpp:560
long myLastVehicleMovementCount
Definition GUINet.h:410
std::vector< GUIGlID > getJunctionIDs(bool includeInternal) const
Definition GUINet.cpp:239
MSTransportableControl & getPersonControl() override
Returns the person control.
Definition GUINet.cpp:129
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition GUINet.h:460
void flushOutputsAtEnd()
flush outputs once the simulation has reached its end
Definition GUINet.cpp:785
bool mySkipFinalReset
Definition GUINet.h:416
bool isSelected(const MSTrafficLightLogic *tll) const override
return wheter the given logic (or rather it's wrapper) is selected in the GUI
Definition GUINet.cpp:759
~GUINet()
Destructor.
Definition GUINet.cpp:93
long myOverallVehicleCount
Definition GUINet.h:410
void simulationStep()
Performs a single simulation step (locking the simulation)
Definition GUINet.cpp:232
int getSimDuration() const
Returns the duration of the last step's simulation part (in ms)
Definition GUINet.cpp:383
SUMORTree myGrid2
The visualization speed-up for secondary shapes.
Definition GUINet.h:378
void initGUIStructures()
Initialises gui wrappers.
Definition GUINet.cpp:266
long myOverallSimDuration
Definition GUINet.h:411
std::vector< std::string > getEdgeDataAttrs() const
return list of loaded edgeData attributes
Definition GUINet.cpp:727
const Boundary & getBoundary() const
returns the bounder of the network
Definition GUINet.cpp:123
double getRTFactor() const
Returns the simulation speed as a factor to real time.
Definition GUINet.cpp:397
void registerRenderedObject(GUIGlObject *o)
add object into rtree
Definition GUINet.cpp:366
std::vector< GUIEdge * > myEdgeWrapper
Wrapped MS-edges.
Definition GUINet.h:384
double getAvgWalkDuration() const
Definition GUINet.h:227
int getLinkTLID(const MSLink *const link) const
Definition GUINet.cpp:197
void setSimDuration(int val)
Sets the duration of the last step's simulation part.
Definition GUINet.cpp:439
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition GUINet.h:285
std::vector< GUICalibrator * > myCalibratorWrapper
A calibrator dictionary.
Definition GUINet.h:393
std::vector< std::string > getMeanDataIDs() const
return list of loaded edgeData ids (being computed in the current simulation)
Definition GUINet.cpp:737
double getMeanUPS() const
Returns the update per seconds rate.
Definition GUINet.cpp:424
double getMeanData(const MSLane *lane, const std::string &id, const std::string &attr)
retrieve live lane/edge weight for the given meanData id and attribute
Definition GUINet.cpp:621
void initTLMap()
Initialises the tl-logic map and wrappers.
Definition GUINet.cpp:147
int getLinkTLIndex(const MSLink *const link) const
Definition GUINet.cpp:212
Boundary myBoundary
The networks boundary.
Definition GUINet.h:381
double getAvgWalkTimeLoss() const
Definition GUINet.h:230
std::vector< GUIGlID > getTLSIDs() const
Returns the gl-ids of all traffic light logics within the net.
Definition GUINet.cpp:251
std::map< std::string, MSEdgeWeightsStorage * > myLoadedEdgeData
loaded edge data for visualization
Definition GUINet.h:414
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own parameter window.
Definition GUINet.cpp:476
Logics2WrapperMap myLogics2Wrapper
The traffic light-to-wrapper map.
Definition GUINet.h:404
int getIdleDuration() const
Returns the duration of the last step's idle part (in ms)
Definition GUINet.cpp:433
double getMeanRTFactor(int duration) const
Returns the simulation speed as a factor to real time.
Definition GUINet.cpp:415
void createTLWrapper(MSTrafficLightLogic *tll) override
creates a wrapper for the given logic
Definition GUINet.cpp:156
bool vehicleExists(const std::string &name) const
returns the information whether the vehicle still exists
Definition GUINet.cpp:191
std::vector< GUIDetectorWrapper * > myDetectorWrapper
A detector dictionary.
Definition GUINet.h:390
void addHotkey(int key, Command *press, Command *release=nullptr)
register custom hotkey action
Definition GUINet.cpp:775
double getAvgWalkRouteLength() const
Definition GUINet.h:224
void lock()
grant exclusive access to the simulation state
Definition GUINet.cpp:587
std::vector< GUIJunctionWrapper * > myJunctionWrapper
Wrapped MS-junctions.
Definition GUINet.h:387
void updateGUI() const override
update view after simulation.loadState
Definition GUINet.cpp:765
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
Definition GUINet.cpp:571
double getAvgTimeLoss() const
Definition GUINet.h:215
double getAvgDepartDelay() const
Definition GUINet.h:218
double getEdgeData(const MSEdge *edge, const std::string &attr)
retrieve loaded edged weight for the given attribute and the current simulation time
Definition GUINet.cpp:604
double getAvgWaitingTime() const
Definition GUINet.h:212
friend class GUITrafficLightLogicWrapper
Definition GUINet.h:84
std::vector< std::string > getMeanDataAttrs(const std::string &meanDataID) const
return list of available attributes for the given meanData id
Definition GUINet.cpp:748
int myLastSimDuration
The step durations (simulation, /*visualisation, *‍/idle)
Definition GUINet.h:408
Position getJunctionPosition(const std::string &name) const
returns the position of a junction
Definition GUINet.cpp:184
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
Definition GUINet.cpp:461
int myLastIdleDuration
Definition GUINet.h:408
void guiSimulationStep()
Some further steps needed for gui processing.
Definition GUINet.cpp:225
MSTransportableControl & getContainerControl() override
Returns the container control.
Definition GUINet.cpp:138
GUINet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents)
Constructor.
Definition GUINet.cpp:82
GUIMEVehicleControl * getGUIMEVehicleControl()
Returns the vehicle control.
Definition GUINet.cpp:598
Links2LogicMap myLinks2Logic
The link-to-logic-id map.
Definition GUINet.h:398
LayeredRTree myGrid
The visualization speed-up.
Definition GUINet.h:375
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.
double getFPS() const
retrieve FPS
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
Storage for geometrical objects extended by mutexes.
GUI-version of the transportable control for building gui persons and containers.
The class responsible for building and deletion of vehicles (gui-version)
Stores the information about how to visualize structures.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void Insert(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Insert entry (delegate to appropriate layer)
static const std::map< std::string, MSCalibrator * > & getInstances()
return all calibrator instances
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
const std::map< std::string, std::vector< MSMeanData * > > & getMeanData() const
void close(SUMOTime step)
Closes the detector outputs.
const std::vector< SumoXMLTag > getAvailableTypes() const
Returns the list of available detector types.
A road/street connecting two junctions.
Definition MSEdge.h:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition MSEdge.cpp:984
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
const MSConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges with internal vias, restricted by vClass.
Definition MSEdge.cpp:1186
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:265
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition MSEdge.cpp:945
A storage for edge travel times and efforts.
Stores time-dependant events and executes them at the proper time.
static bool gHaveEmissions
Whether emission output of some type is needed (files or GUI)
Definition MSGlobals.h:178
int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
const Position & getPosition(bool secondaryShape=false) const
Representation of a lane in the micro simulation.
Definition MSLane.h:84
The simulated network and simulation perfomer.
Definition MSNet.h:88
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition MSNet.h:880
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:183
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition MSNet.h:886
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition MSNet.h:453
MMVersion myVersion
the network version
Definition MSNet.h:980
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition MSNet.h:878
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:322
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition MSNet.h:882
void simulationStep(const bool onlyMove=false)
Performs a single simulation step.
Definition MSNet.cpp:710
SUMOTime myEdgeDataEndTime
end of loaded edgeData
Definition MSNet.h:983
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition MSNet.h:888
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition MSNet.cpp:1166
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition MSNet.h:928
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:433
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition MSNet.h:892
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:380
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition MSPModel.h:127
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
MSTrafficLightLogic * getActive(const std::string &id) const
Returns the active program of a named tls.
The parent class for traffic light logics.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
int getLinkIndex(const MSLink *const link) const
Returns the index of the given link.
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
int getRunningNumber() const
Returns the number of build and inserted, but not yet deleted transportables.
int getLoadedNumber() const
Returns the number of build transportables.
int getJammedNumber() const
Returns the number of times a transportables was jammed.
The class responsible for building and deletion of vehicles.
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
int getLoadedVehicleNo() const
Returns the number of build vehicles.
int getCollisionCount() const
return the number of collisions
int getStoppedVehiclesCount() const
return the number of vehicles that are currently stopped
double getVehicleMeanSpeed() const
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
int getArrivedVehicleNo() const
Returns the number of arrived vehicles.
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
int getTeleportCount() const
return the number of teleports (including collisions)
double getVehicleMeanSpeedRelative() const
int getDiscardedVehicleNo() const
Returns the number of discarded vehicles.
const std::string & getID() const
Returns the id.
Definition Named.h:74
T get(const std::string &id) const
Retrieves an item.
int size() const
Returns the number of stored items within the container.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static OptionsCont & getOptions()
Retrieves the options.
static void flushAll()
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
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
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Complete definition about what shall be retrieved and where to store it.
An XML-handler for network weights.
void addAdditionalGLObject(GUIGlObject *o, const double exaggeration=1)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition SUMORTree.h:124
virtual void Insert(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Insert entry.
Definition SUMORTree.h:91
Encapsulated SAX-Attributes.
virtual std::vector< std::string > getAttributeNames() const =0
Retrieves all attribute names.
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
static StringBijection< int > Attrs
The names of SUMO-XML attributes for use in netbuild.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.