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-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/****************************************************************************/
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>
43#include <microsim/MSNet.h>
45#include <microsim/MSJunction.h>
47#include <microsim/MSEdge.h>
54#include <guisim/GUIEdge.h>
55#include <guisim/GUILane.h>
63#include <gui/GUIGlobals.h>
65#include "GUINet.h"
66
68
69
70// ===========================================================================
71// definition of static variables used for visualisation of objects' values
72// ===========================================================================
73template std::vector< GLObjectValuePassConnector<double>* > GLObjectValuePassConnector<double>::myContainer;
75
76template std::vector< GLObjectValuePassConnector<std::pair<int, class MSPhaseDefinition> >* > GLObjectValuePassConnector<std::pair<int, class MSPhaseDefinition> >::myContainer;
78
79
80// ===========================================================================
81// member method definitions
82// ===========================================================================
84 MSEventControl* endOfTimestepEvents,
85 MSEventControl* insertionEvents) :
86 MSNet(vc, beginOfTimestepEvents, endOfTimestepEvents, insertionEvents, new GUIShapeContainer(myGrid)),
87 GUIGlObject(GLO_NETWORK, "", nullptr),
88 myLastSimDuration(0), /*myLastVisDuration(0),*/ myLastIdleDuration(0),
89 myLastVehicleMovementCount(0), myOverallVehicleCount(0), myOverallSimDuration(0) {
91}
92
93
95 if (myLock.locked()) {
96 myLock.unlock();
97 }
98 // delete allocated wrappers
99 // of junctions
100 for (std::vector<GUIJunctionWrapper*>::iterator i1 = myJunctionWrapper.begin(); i1 != myJunctionWrapper.end(); i1++) {
101 delete (*i1);
102 }
103 // of additional structures
105 // of tl-logics
106 for (Logics2WrapperMap::iterator i3 = myLogics2Wrapper.begin(); i3 != myLogics2Wrapper.end(); i3++) {
107 delete (*i3).second;
108 }
109 // of detectors
110 for (std::vector<GUIDetectorWrapper*>::iterator i = myDetectorWrapper.begin(); i != myDetectorWrapper.end(); ++i) {
111 delete *i;
112 }
113 // of calibrators
115 delete cw;
116 }
117 for (auto& item : myLoadedEdgeData) {
118 delete item.second;
119 }
120}
121
122
123const Boundary&
125 return myBoundary;
126}
127
128
131 if (myPersonControl == nullptr) {
133 }
134 return *myPersonControl;
135}
136
137
140 if (myContainerControl == nullptr) {
142 }
143 return *myContainerControl;
144}
145
146
147void
149 // go through the loaded tl-logics
150 for (MSTrafficLightLogic* const tll : getTLSControl().getAllLogics()) {
151 createTLWrapper(tll);
152 }
153}
154
155
156void
158 if (myLogics2Wrapper.count(tll) > 0) {
159 return;
160 }
161 // get the links
163 if (links.size() == 0) { // @legacy this should never happen in 0.13.0+ networks
164 return;
165 }
166 // build the wrapper
168 if (tll->hasParameter("hotkeyAbort")) {
170 }
171 // build the association link->wrapper
172 MSTrafficLightLogic::LinkVectorVector::const_iterator j;
173 for (j = links.begin(); j != links.end(); ++j) {
174 MSTrafficLightLogic::LinkVector::const_iterator j2;
175 for (j2 = (*j).begin(); j2 != (*j).end(); ++j2) {
176 myLinks2Logic[*j2] = tll->getID();
177 }
178 }
180 myLogics2Wrapper[tll] = tllw;
181}
182
183
185GUINet::getJunctionPosition(const std::string& name) const {
186 // !!! no check for existance!
187 return myJunctions->get(name)->getPosition();
188}
189
190
191bool
192GUINet::vehicleExists(const std::string& name) const {
193 return myVehicleControl->getVehicle(name) != nullptr;
194}
195
196
197int
198GUINet::getLinkTLID(const MSLink* const link) const {
199 if (myLinks2Logic.count(link) == 0) {
200 //assert(false);
201 return 0;
202 }
203 MSTrafficLightLogic* tll = myLogics->getActive(myLinks2Logic.find(link)->second);
204 if (myLogics2Wrapper.count(tll) == 0) {
205 // tll may have been added via traci. @see ticket #459
206 return 0;
207 }
208 return myLogics2Wrapper.find(tll)->second->getGlID();
209}
210
211
212int
213GUINet::getLinkTLIndex(const MSLink* const link) const {
214 Links2LogicMap::const_iterator i = myLinks2Logic.find(link);
215 if (i == myLinks2Logic.end()) {
216 return -1;
217 }
218 if (myLogics2Wrapper.find(myLogics->getActive((*i).second)) == myLogics2Wrapper.end()) {
219 return -1;
220 }
221 return myLogics2Wrapper.find(myLogics->getActive((*i).second))->second->getLinkIndex(link);
222}
223
224
227 if (myLogics2Wrapper.find(tll) == myLogics2Wrapper.end()) {
228 return nullptr;
229 }
230 return myLogics2Wrapper.find(tll)->second;
231}
232
233
234void
239
240
241void
243 FXMutexLock locker(myLock);
245}
246
247
248std::vector<GUIGlID>
249GUINet::getJunctionIDs(bool includeInternal) const {
250 std::vector<GUIGlID> ret;
251 for (std::vector<GUIJunctionWrapper*>::const_iterator i = myJunctionWrapper.begin(); i != myJunctionWrapper.end(); ++i) {
252 if (!(*i)->isInternal() || includeInternal) {
253 ret.push_back((*i)->getGlID());
254 }
255 }
256 return ret;
257}
258
259
260std::vector<GUIGlID>
262 std::vector<GUIGlID> ret;
263 std::vector<std::string> ids;
264 for (std::map<MSTrafficLightLogic*, GUITrafficLightLogicWrapper*>::const_iterator i = myLogics2Wrapper.begin(); i != myLogics2Wrapper.end(); ++i) {
265 std::string sid = (*i).second->getMicrosimID();
266 if (find(ids.begin(), ids.end(), sid) == ids.end()) {
267 ret.push_back((*i).second->getGlID());
268 ids.push_back(sid);
269 }
270 }
271 return ret;
272}
273
274
275void
277 // initialise detector storage for gui
278 const std::vector<SumoXMLTag> types = myDetectorControl->getAvailableTypes();
279 for (std::vector<SumoXMLTag>::const_iterator i = types.begin(); i != types.end(); ++i) {
280 for (const auto& j : myDetectorControl->getTypedDetectors(*i)) {
281 GUIDetectorWrapper* wrapper = j.second->buildDetectorGUIRepresentation();
282 if (wrapper != nullptr) {
283 myDetectorWrapper.push_back(wrapper);
285 }
286 }
287 }
288 // let's always track emission parameters for the GUI
290 // initialise calibrators
291 for (auto& item : MSCalibrator::getInstances()) {
292 GUICalibrator* wrapper = new GUICalibrator(item.second);
293 myCalibratorWrapper.push_back(wrapper);
295 }
296 // initialise the tl-map
297 initTLMap();
298 // initialise edge storage for gui
299 const MSEdgeVector& edges = MSEdge::getAllEdges();
300 myEdgeWrapper.reserve(edges.size());
301 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
302 // VISIM connector edges shall be drawn (they have lanes)
303 if (!(*i)->isTazConnector() || (*i)->getLanes().size() > 0) {
304 myEdgeWrapper.push_back(static_cast<GUIEdge*>(*i));
305 }
306 }
307 // initialise junction storage for gui
308 int size = myJunctions->size();
309 myJunctionWrapper.reserve(size);
310 std::map<MSJunction*, std::string> junction2TLL;
311 for (const auto tls : getTLSControl().getAllLogics()) {
312 for (const auto& links : tls->getLinks()) {
313 for (const MSLink* l : links) {
314 junction2TLL[l->getJunction()] = l->getTLLogic()->getID();
315 }
316 }
317 }
318 for (const auto& i : *myJunctions) {
319 myJunctionWrapper.push_back(new GUIJunctionWrapper(*i.second, junction2TLL[i.second]));
320 }
321 // build the visualization tree
322 for (std::vector<GUIEdge*>::iterator i = myEdgeWrapper.begin(); i != myEdgeWrapper.end(); ++i) {
323 GUIEdge* edge = *i;
324 Boundary b;
325 const std::vector<MSLane*>& lanes = edge->getLanes();
326 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
327 b.add((*j)->getShape().getBoxBoundary());
328 }
329 // make sure persons are always drawn and selectable since they depend on their edge being drawn
330 b.grow(MSPModel::SIDEWALK_OFFSET + 1 + lanes.front()->getWidth() / 2);
331 const float cmin[2] = { (float)b.xmin(), (float)b.ymin() };
332 const float cmax[2] = { (float)b.xmax(), (float)b.ymax() };
333 myGrid.Insert(cmin, cmax, edge);
334 myBoundary.add(b);
335 if (myBoundary.getWidth() > 10e16 || myBoundary.getHeight() > 10e16) {
336 throw ProcessError(TL("Network size exceeds 1 Lightyear. Please reconsider your inputs.\n"));
337 }
338 }
339 for (std::vector<GUIJunctionWrapper*>::iterator i = myJunctionWrapper.begin(); i != myJunctionWrapper.end(); ++i) {
340 GUIJunctionWrapper* junction = *i;
341 Boundary b = junction->getBoundary();
342 b.grow(2.);
343 const float cmin[2] = { (float)b.xmin(), (float)b.ymin() };
344 const float cmax[2] = { (float)b.xmax(), (float)b.ymax() };
345 myGrid.Insert(cmin, cmax, junction);
346 myBoundary.add(b);
347 }
349
350 if (OptionsCont::getOptions().isSet("alternative-net-file")) {
351 // build secondary visualization tree
352 for (GUIEdge* edge : myEdgeWrapper) {
353 Boundary b;
354 for (MSLane* lane : edge->getLanes()) {
355 b.add(static_cast<GUILane*>(lane)->getShape(true).getBoxBoundary());
356 }
357 // make sure persons are always drawn and selectable since they depend on their edge being drawn
359 const float cmin[2] = { (float)b.xmin(), (float)b.ymin() };
360 const float cmax[2] = { (float)b.xmax(), (float)b.ymax() };
361 myGrid2.Insert(cmin, cmax, edge);
362 }
363 for (std::vector<GUIJunctionWrapper*>::iterator i = myJunctionWrapper.begin(); i != myJunctionWrapper.end(); ++i) {
364 GUIJunctionWrapper* junction = *i;
365 Position pos = junction->getJunction().getPosition(true);
366 Boundary b = Boundary(pos.x() - 3., pos.y() - 3., pos.x() + 3., pos.y() + 3.);
367 const float cmin[2] = { (float)b.xmin(), (float)b.ymin() };
368 const float cmax[2] = { (float)b.xmax(), (float)b.ymax() };
369 myGrid2.Insert(cmin, cmax, junction);
370 }
371 }
372}
373
374
375void
384
385
386int
388 return myLastSimDuration +/*myLastVisDuration+*/myLastIdleDuration;
389}
390
391
392int
394 return myLastSimDuration;
395}
396
397/*
398int
399GUINet::getVisDuration() const
400{
401 return myLastVisDuration;
402}
403*/
404
405
406double
408 if (myLastSimDuration == 0) {
409 return -1;
410 }
411 return (double)DELTA_T / (double)myLastSimDuration;
412}
413
414
415double
417 if (myLastSimDuration == 0) {
418 return -1;
419 }
420 return (double) myLastVehicleMovementCount / (double) myLastSimDuration * (double) 1000.;
421}
422
423
424double
425GUINet::getMeanRTFactor(int duration) const {
426 if (myOverallSimDuration == 0) {
427 return -1;
428 }
429 return ((double)(duration) * (double) 1000. / (double)myOverallSimDuration);
430}
431
432
433double
435 if (myOverallSimDuration == 0) {
436 return -1;
437 }
438 return ((double)myVehiclesMoved / (double)myOverallSimDuration * (double) 1000.);
439}
440
441
442int
446
447
448void
455
456/*
457void
458GUINet::setVisDuration(int val)
459{
460 myLastVisDuration = val;
461}
462*/
463
464void
468
469
472 GUISUMOAbstractView& parent) {
473 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
474 buildPopupHeader(ret, app);
477 buildPositionCopyEntry(ret, app);
478 if (GeoConvHelper::getFinal().usingGeoProjection()) {
479 GUIDesigns::buildFXMenuCommand(ret, TL("Copy view geo-boundary to clipboard"), nullptr, ret, MID_COPY_VIEW_GEOBOUNDARY);
480 }
481 return ret;
482}
483
484
487 GUISUMOAbstractView& parent) {
489 // add items
490 ret->mkItem(TL("loaded vehicles [#]"), true,
492 ret->mkItem(TL("insertion-backlogged vehicles [#]"), true,
494 ret->mkItem(TL("departed vehicles [#]"), true,
496 ret->mkItem(TL("running vehicles [#]"), true,
498 ret->mkItem(TL("arrived vehicles [#]"), true,
500 ret->mkItem(TL("discarded vehicles [#]"), true,
502 ret->mkItem(TL("collisions [#]"), true,
504 ret->mkItem(TL("teleports [#]"), true,
506 ret->mkItem(TL("halting [#]"), true,
508 ret->mkItem(TL("stopped [#]"), true,
510 ret->mkItem(TL("avg. speed [m/s]"), true,
512 ret->mkItem(TL("avg. relative speed"), true,
514 if (myPersonControl != nullptr) {
515 ret->mkItem(TL("loaded persons [#]"), true,
517 ret->mkItem(TL("running persons [#]"), true,
519 ret->mkItem(TL("jammed persons [#]"), true,
521 }
522 ret->mkItem(TL("end time [s]"), false, OptionsCont::getOptions().getString("end"));
523 ret->mkItem(TL("begin time [s]"), false, OptionsCont::getOptions().getString("begin"));
524// ret->mkItem(TL("time step [s]"), true, new FunctionBinding<GUINet, SUMOTime>(this, &GUINet::getCurrentTimeStep));
525 if (logSimulationDuration()) {
526 ret->mkItem(TL("step duration [ms]"), true, new FunctionBinding<GUINet, int>(this, &GUINet::getWholeDuration));
528 ret->mkItem(TL("simulation duration [ms]"), true, new FunctionBinding<GUINet, int>(this, &GUINet::getSimDuration));
529 /*
530 ret->mkItem(TL("visualisation duration [ms]"), true,
531 new CastingFunctionBinding<GUINet, double, int>(
532 &(getNet()), &GUINet::getVisDuration));
533 */
534 ret->mkItem(TL("idle duration [ms]"), true, new FunctionBinding<GUINet, int>(this, &GUINet::getIdleDuration));
535 ret->mkItem(TL("duration factor"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getRTFactor));
536 /*
537 ret->mkItem(TL("mean duration factor []"), true,
538 new FuncBinding_IntParam<GUINet, double>(
539 &(getNet()), &GUINet::getMeanRTFactor), 1);
540 */
541 ret->mkItem(TL("updates per second"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getUPS));
542 ret->mkItem(TL("avg. updates per second"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getMeanUPS));
543 }
544 if (OptionsCont::getOptions().isSet("tripinfo-output") || OptionsCont::getOptions().getBool("duration-log.statistics")) {
545 ret->mkItem(TL("avg. trip length [m]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgRouteLength));
546 ret->mkItem(TL("avg. trip duration [s]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgDuration));
547 ret->mkItem(TL("avg. trip waiting time [s]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgWaitingTime));
548 ret->mkItem(TL("avg. trip time loss [s]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgTimeLoss));
549 ret->mkItem(TL("avg. trip depart delay [s]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgDepartDelay));
550 ret->mkItem(TL("avg. trip speed [m/s]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgTripSpeed));
551 if (myPersonControl != nullptr) {
552 ret->mkItem(TL("avg. walk length [m]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgWalkRouteLength));
553 ret->mkItem(TL("avg. walk duration [s]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgWalkDuration));
554 ret->mkItem(TL("avg. walk time loss [s]"), true, new FunctionBinding<GUINet, double>(this, &GUINet::getAvgWalkTimeLoss));
555 }
556 }
557 ret->mkItem(TL("nodes [#]"), false, (int)getJunctionIDs(false).size());
558 ret->mkItem(TL("edges [#]"), false, (int)GUIEdge::getIDs(false).size());
559 ret->mkItem(TL("total edge length [km]"), false, GUIEdge::getTotalLength(false, false) / 1000);
560 ret->mkItem(TL("total lane length [km]"), false, GUIEdge::getTotalLength(false, true) / 1000);
561 ret->mkItem(TL("network version "), false, toString(myVersion));
562
563 // close building
564 ret->closeBuilding();
565 return ret;
566}
567
568
569void
571}
572
573
576 return getBoundary();
577}
578
579
580GUINet*
582 GUINet* net = dynamic_cast<GUINet*>(MSNet::getInstance());
583 if (net != nullptr) {
584 return net;
585 }
586 throw ProcessError("A gui-network was not yet constructed.");
587}
588
589
594
595
596void
598 myLock.lock();
599}
600
601
602void
604 myLock.unlock();
605}
606
611
612
613double
614GUINet::getEdgeData(const MSEdge* edge, const std::string& attr) {
615 auto it = myLoadedEdgeData.find(attr);
616 if (it != myLoadedEdgeData.end()) {
617 double value;
618 bool found = it->second->retrieveExistingEffort(edge, STEPS2TIME(getCurrentTimeStep()), value);
619 if (found) {
620 return value;
621 } else {
623 }
624 } else {
626 }
627}
628
629
630double
631GUINet::getMeanData(const MSLane* lane, const std::string& id, const std::string& attr) {
632 auto item = myDetectorControl->getMeanData().find(id);
633 if (item != myDetectorControl->getMeanData().end() && !item->second.empty()) {
635 return item->second.front()->getAttributeValue(lane, a, GUIVisualizationSettings::MISSING_DATA);
636 } else {
638 }
639}
640
641
642void
644 if (element == SUMO_TAG_EDGE || element == SUMO_TAG_LANE) {
645 std::vector<std::string> tmp = attrs.getAttributeNames();
646 edgeAttrs.insert(tmp.begin(), tmp.end());
647 } else if (element == SUMO_TAG_EDGEREL) {
648 for (const std::string& a : attrs.getAttributeNames()) {
649 if (a != "from" && a != "to") {
650 edgeAttrs.insert(a);
651 }
652 }
653 } else if (element == SUMO_TAG_INTERVAL) {
654 bool ok;
655 numIntervals++;
658 }
659}
660
661
662std::vector<std::string>
664 edgeAttrs.erase(toString(SUMO_ATTR_ID));
665 return std::vector<std::string>(edgeAttrs.begin(), edgeAttrs.end());
666}
667
668
669void
671 double value, double begTime, double endTime) const {
672 MSEdge* const edge = MSEdge::dictionary(id);
673 if (edge != nullptr) {
674 myWeightStorage->addEffort(edge, begTime, endTime, value);
675 } else {
676 WRITE_WARNINGF(TL("Trying to set data value for the unknown edge '%'."), id);
677 }
678}
679
680
681void
682GUINet::EdgeFloatTimeLineRetriever_GUI::addEdgeRelWeight(const std::string& from, const std::string& to,
683 double val, double beg, double end) const {
684 MSEdge* const fromEdge = MSEdge::dictionary(from);
685 MSEdge* const toEdge = MSEdge::dictionary(to);
686 bool haveRel = false;
687 if (fromEdge != nullptr && toEdge != nullptr) {
688 for (auto item : fromEdge->getViaSuccessors()) {
689 if (item.first == toEdge) {
690 const MSEdge* edge = item.second;
691 while (edge != nullptr && edge->isInternal()) {
692 myWeightStorage->addEffort(edge, beg, end, val);
693 edge = edge->getViaSuccessors().front().second;
694 haveRel = true;
695 }
696 }
697 }
698 }
699 if (!haveRel) {
700 WRITE_WARNINGF(TL("Trying to set data value for the unknown relation from edge '%' to edge '%'."), from, to);
701 }
702}
703
704
705bool
706GUINet::loadEdgeData(const std::string& file) {
707 // discover edge attributes
708 DiscoverAttributes discoveryHandler(file);
709 XMLSubSys::runParser(discoveryHandler, file);
710 std::vector<std::string> attrs = discoveryHandler.getEdgeAttrs();
711 WRITE_MESSAGE("Loading edgedata from '" + file + "':"
712 + "\n " + toString(discoveryHandler.numIntervals) + " intervals between"
713 + " " + time2string(discoveryHandler.firstIntervalBegin) + " and"
714 + " " + time2string(discoveryHandler.lastIntervalEnd)
715 + ".\n Found " + toString(attrs.size())
716 + " attributes: " + toString(attrs));
717 if (discoveryHandler.lastIntervalEnd < string2time(OptionsCont::getOptions().getString("begin"))) {
718 WRITE_WARNING(TL("No data defined after simulation begin time."));
719 }
721 // create a retriever for each attribute
722 std::vector<EdgeFloatTimeLineRetriever_GUI> retrieverDefsInternal;
723 retrieverDefsInternal.reserve(attrs.size());
724 std::vector<SAXWeightsHandler::ToRetrieveDefinition*> retrieverDefs;
725 for (const std::string& attr : attrs) {
727 myLoadedEdgeData[attr] = ws;
728 retrieverDefsInternal.push_back(EdgeFloatTimeLineRetriever_GUI(ws));
729 retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition(attr, true, retrieverDefsInternal.back()));
730 }
731 SAXWeightsHandler handler(retrieverDefs, "");
732 // temporarily modify warning threshold to avoid swamping the UI
735 bool ok = XMLSubSys::runParser(handler, file);
738 return ok;
739}
740
741
742std::vector<std::string>
744 std::vector<std::string> result;
745 for (const auto& item : myLoadedEdgeData) {
746 result.push_back(item.first);
747 }
748 return result;
749}
750
751
752std::vector<std::string>
754 std::vector<std::string> result;
755
756 for (auto item : myDetectorControl->getMeanData()) {
757 result.push_back(item.first);
758 }
759 std::sort(result.begin(), result.end());
760 return result;
761}
762
763std::vector<std::string>
764GUINet::getMeanDataAttrs(const std::string& meanDataID) const {
765 auto item = myDetectorControl->getMeanData().find(meanDataID);
766 if (item != myDetectorControl->getMeanData().end() && !item->second.empty()) {
767 return item->second.front()->getAttributeNames();
768 } else {
769 return std::vector<std::string>();
770 }
771}
772
773
774bool
776 const auto it = myLogics2Wrapper.find(const_cast<MSTrafficLightLogic*>(tll));
777 return it != myLogics2Wrapper.end() && gSelected.isSelected(GLO_TLLOGIC, it->second->getGlID());
778}
779
780void
782 try {
783 // gui only
785 // update the view
786 aw->handleEvent_SimulationStep(nullptr);
787 } catch (ProcessError&) { }
788}
789
790void
791GUINet::addHotkey(int key, Command* press, Command* release) {
792 try {
793 // gui only
795 // update the view
796 aw->addHotkey(key, press, release);
797 } catch (ProcessError&) { }
798}
799
800void
802 mySkipFinalReset = true;
805 // update tracker windows
807}
808
809#ifdef HAVE_OSG
810void
811GUINet::updateColor(const GUIVisualizationSettings& s) {
812 for (std::vector<GUIEdge*>::const_iterator i = myEdgeWrapper.begin(); i != myEdgeWrapper.end(); ++i) {
813 if (!(*i)->isInternal()) {
814 const std::vector<MSLane*>& lanes = (*i)->getLanes();
815 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
816 static_cast<GUILane*>(*j)->updateColor(s);
817 }
818 }
819 }
820 for (std::vector<GUIJunctionWrapper*>::iterator i = myJunctionWrapper.begin(); i != myJunctionWrapper.end(); ++i) {
821 (*i)->updateColor(s);
822 }
823}
824#endif
825
826
827/****************************************************************************/
@ MID_COPY_VIEW_GEOBOUNDARY
Copy view geo-coordinate boundary - popup entry.
Definition GUIAppEnum.h:467
@ 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:287
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:288
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
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:91
#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:80
T MAX2(T a, T b)
Definition StdDefs.h:86
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:75
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:127
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:115
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:340
double getHeight() const
Returns the height of the boundary (y-axis)
Definition Boundary.cpp:157
double getWidth() const
Returns the width of the boudary (x-axis)
Definition Boundary.cpp:151
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:133
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:121
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, const bool disable=false)
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:121
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition GUIEdge.cpp:106
The popup menu of a globject.
static void clearDictionary()
Clears the dictionary (the objects will not be deleted)
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app, bool addSeparator=true) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
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 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:1119
The class responsible for building and deletion of vehicles (gui-version)
static GUIMainWindow * getInstance()
get instance
class for discovering edge attributes
Definition GUINet.h:421
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Callback method for an opening tag to implement by derived classes.
Definition GUINet.cpp:643
std::set< std::string > edgeAttrs
Definition GUINet.h:432
std::vector< std::string > getEdgeAttrs()
Definition GUINet.cpp:663
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:670
void addEdgeRelWeight(const std::string &from, const std::string &to, double val, double beg, double end) const
Definition GUINet.cpp:682
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:387
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
Definition GUINet.cpp:575
void setIdleDuration(int val)
Sets the duration of the last step's idle part.
Definition GUINet.cpp:465
GUIVehicleControl * getGUIVehicleControl()
Returns the vehicle control.
Definition GUINet.cpp:591
void unlock()
release exclusive access to the simulation state
Definition GUINet.cpp:603
double getUPS() const
Returns the update per seconds rate.
Definition GUINet.cpp:416
bool loadEdgeData(const std::string &file)
load edgeData from file
Definition GUINet.cpp:706
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Definition GUINet.cpp:570
long myLastVehicleMovementCount
Definition GUINet.h:412
std::vector< GUIGlID > getJunctionIDs(bool includeInternal) const
Definition GUINet.cpp:249
MSTransportableControl & getPersonControl() override
Returns the person control.
Definition GUINet.cpp:130
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition GUINet.h:462
void flushOutputsAtEnd()
flush outputs once the simulation has reached its end
Definition GUINet.cpp:801
bool mySkipFinalReset
Definition GUINet.h:418
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:775
~GUINet()
Destructor.
Definition GUINet.cpp:94
long myOverallVehicleCount
Definition GUINet.h:412
void simulationStep()
Performs a single simulation step (locking the simulation)
Definition GUINet.cpp:242
int getSimDuration() const
Returns the duration of the last step's simulation part (in ms)
Definition GUINet.cpp:393
SUMORTree myGrid2
The visualization speed-up for secondary shapes.
Definition GUINet.h:380
void initGUIStructures()
Initialises gui wrappers.
Definition GUINet.cpp:276
long myOverallSimDuration
Definition GUINet.h:413
std::vector< std::string > getEdgeDataAttrs() const
return list of loaded edgeData attributes
Definition GUINet.cpp:743
const Boundary & getBoundary() const
returns the bounder of the network
Definition GUINet.cpp:124
double getRTFactor() const
Returns the simulation speed as a factor to real time.
Definition GUINet.cpp:407
void registerRenderedObject(GUIGlObject *o)
add object into rtree
Definition GUINet.cpp:376
std::vector< GUIEdge * > myEdgeWrapper
Wrapped MS-edges.
Definition GUINet.h:386
GUITrafficLightLogicWrapper * getTLLWrapper(MSTrafficLightLogic *tll)
Definition GUINet.cpp:226
double getAvgWalkDuration() const
Definition GUINet.h:227
int getLinkTLID(const MSLink *const link) const
Definition GUINet.cpp:198
void setSimDuration(int val)
Sets the duration of the last step's simulation part.
Definition GUINet.cpp:449
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition GUINet.h:287
std::vector< GUICalibrator * > myCalibratorWrapper
A calibrator dictionary.
Definition GUINet.h:395
std::vector< std::string > getMeanDataIDs() const
return list of loaded edgeData ids (being computed in the current simulation)
Definition GUINet.cpp:753
double getMeanUPS() const
Returns the update per seconds rate.
Definition GUINet.cpp:434
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:631
void initTLMap()
Initialises the tl-logic map and wrappers.
Definition GUINet.cpp:148
int getLinkTLIndex(const MSLink *const link) const
Definition GUINet.cpp:213
Boundary myBoundary
The networks boundary.
Definition GUINet.h:383
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:261
std::map< std::string, MSEdgeWeightsStorage * > myLoadedEdgeData
loaded edge data for visualization
Definition GUINet.h:416
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own parameter window.
Definition GUINet.cpp:486
Logics2WrapperMap myLogics2Wrapper
The traffic light-to-wrapper map.
Definition GUINet.h:406
int getIdleDuration() const
Returns the duration of the last step's idle part (in ms)
Definition GUINet.cpp:443
double getMeanRTFactor(int duration) const
Returns the simulation speed as a factor to real time.
Definition GUINet.cpp:425
void createTLWrapper(MSTrafficLightLogic *tll) override
creates a wrapper for the given logic
Definition GUINet.cpp:157
bool vehicleExists(const std::string &name) const
returns the information whether the vehicle still exists
Definition GUINet.cpp:192
std::vector< GUIDetectorWrapper * > myDetectorWrapper
A detector dictionary.
Definition GUINet.h:392
void addHotkey(int key, Command *press, Command *release=nullptr)
register custom hotkey action
Definition GUINet.cpp:791
double getAvgWalkRouteLength() const
Definition GUINet.h:224
void lock()
grant exclusive access to the simulation state
Definition GUINet.cpp:597
std::vector< GUIJunctionWrapper * > myJunctionWrapper
Wrapped MS-junctions.
Definition GUINet.h:389
void updateGUI() const override
update view after simulation.loadState
Definition GUINet.cpp:781
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
Definition GUINet.cpp:581
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:614
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:764
int myLastSimDuration
The step durations (simulation, /*visualisation, *‍/idle)
Definition GUINet.h:410
Position getJunctionPosition(const std::string &name) const
returns the position of a junction
Definition GUINet.cpp:185
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
Definition GUINet.cpp:471
int myLastIdleDuration
Definition GUINet.h:410
void guiSimulationStep()
Some further steps needed for gui processing.
Definition GUINet.cpp:235
MSTransportableControl & getContainerControl() override
Returns the container control.
Definition GUINet.cpp:139
GUINet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents)
Constructor.
Definition GUINet.cpp:83
GUIMEVehicleControl * getGUIMEVehicleControl()
Returns the vehicle control.
Definition GUINet.cpp:608
Links2LogicMap myLinks2Logic
The link-to-logic-id map.
Definition GUINet.h:400
LayeredRTree myGrid
The visualization speed-up.
Definition GUINet.h:377
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:1096
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
const MSConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Returns the following edges with internal vias, restricted by vClass.
Definition MSEdge.cpp:1298
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:268
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:1057
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:183
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:89
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition MSNet.h:898
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition MSNet.h:904
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition MSNet.h:465
MMVersion myVersion
the network version
Definition MSNet.h:1002
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition MSNet.h:896
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:334
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition MSNet.h:900
void simulationStep(const bool onlyMove=false)
Performs a single simulation step.
Definition MSNet.cpp:771
SUMOTime myEdgeDataEndTime
end of loaded edgeData
Definition MSNet.h:1005
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition MSNet.h:906
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition MSNet.cpp:1244
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition MSNet.h:946
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:445
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition MSNet.h:910
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:392
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition MSPModel.h:62
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.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
virtual void clear(bool resetInformed=true)
Clears information whether an error occurred previously and print aggregated message summary.
void setAggregationThreshold(const int thresh)
Definition MsgHandler.h:164
int getAggregationThreshold() const
Definition MsgHandler.h:168
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()
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
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:52
double y() const
Returns the y-position.
Definition Position.h:57
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:122
virtual void Insert(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Insert entry.
Definition SUMORTree.h:89
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 SequentialStringBijection 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.