GUITLLogicPhasesTrackerWindow::GUITLLogicPhasesTrackerWindow( GUIMainWindow& app, MSTrafficLightLogic& logic, GUITrafficLightLogicWrapper& /*wrapper*/, const MSSimpleTrafficLightLogic::Phases& /*phases*/) : FXMainWindow(app.getApp(), "TLS-Tracker", NULL, NULL, DECOR_ALL, 20, 20, 300, 200), myApplication(&app), myTLLogic(&logic), myAmInTrackingMode(false), myToolBarDrag(0), myBeginOffset(0) { myConnector = 0; FXint height = (FXint)(myTLLogic->getLinks().size() * 20 + 30 + 8); setTitle("TLS-Tracker"); app.addChild(this, true); for (size_t i = 0; i < myTLLogic->getLinks().size(); ++i) { myLinkNames.push_back(toString<size_t>(i)); } FXVerticalFrame* glcanvasFrame = new FXVerticalFrame(this, FRAME_SUNKEN | LAYOUT_SIDE_TOP | LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0); myPanel = new GUITLLogicPhasesTrackerPanel(glcanvasFrame, *myApplication, *this); setTitle((logic.getID() + " - " + logic.getProgramID() + " - tracker").c_str()); setIcon(GUIIconSubSys::getIcon(ICON_APP_TLSTRACKER)); setHeight(height); }
/* ------------------------------------------------------------------------- * GUITLLogicPhasesTrackerWindow-methods * ----------------------------------------------------------------------- */ GUITLLogicPhasesTrackerWindow::GUITLLogicPhasesTrackerWindow( GUIMainWindow& app, MSTrafficLightLogic& logic, GUITrafficLightLogicWrapper& wrapper, ValueSource<std::pair<SUMOTime, MSPhaseDefinition> >* src) : FXMainWindow(app.getApp(), "TLS-Tracker", NULL, NULL, DECOR_ALL, 20, 20, 300, 200), myApplication(&app), myTLLogic(&logic), myAmInTrackingMode(true) { // build the toolbar myToolBarDrag = new FXToolBarShell(this, FRAME_NORMAL); myToolBar = new FXToolBar(this, myToolBarDrag, LAYOUT_SIDE_TOP | LAYOUT_FILL_X | FRAME_RAISED); new FXToolBarGrip(myToolBar, myToolBar, FXToolBar::ID_TOOLBARGRIP, TOOLBARGRIP_DOUBLE); // interval manipulation myBeginOffset = new FXRealSpinDial(myToolBar, 10, this, MID_SIMSTEP, LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK); myBeginOffset->setFormatString("%.0f"); myBeginOffset->setIncrements(1, 10, 100); myBeginOffset->setRange(60, 3600); myBeginOffset->setValue(240); new FXLabel(myToolBar, "(s)", 0, LAYOUT_CENTER_Y); // myConnector = new GLObjectValuePassConnector<std::pair<SUMOTime, MSPhaseDefinition> >(wrapper, src, this); FXint height = (FXint)(myTLLogic->getLinks().size() * 20 + 30 + 8 + 30); app.addChild(this, true); for (size_t i = 0; i < myTLLogic->getLinks().size(); ++i) { myLinkNames.push_back(toString<size_t>(i)); } FXVerticalFrame* glcanvasFrame = new FXVerticalFrame(this, FRAME_SUNKEN | LAYOUT_SIDE_TOP | LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0); myPanel = new GUITLLogicPhasesTrackerPanel(glcanvasFrame, *myApplication, *this); setTitle((logic.getID() + " - " + logic.getProgramID() + " - tracker").c_str()); setIcon(GUIIconSubSys::getIcon(ICON_APP_TLSTRACKER)); setHeight(height); }
void GUINet::initTLMap() { // get the list of loaded tl-logics const std::vector<MSTrafficLightLogic*> &logics = getTLSControl().getAllLogics(); // allocate storage for the wrappers myTLLogicWrappers.reserve(logics.size()); // go through the logics for (std::vector<MSTrafficLightLogic*>::const_iterator i=logics.begin(); i!=logics.end(); ++i) { // get the logic MSTrafficLightLogic *tll = (*i); // get the links const MSTrafficLightLogic::LinkVectorVector &links = tll->getLinks(); if (links.size()==0) { continue; } // build the wrapper GUITrafficLightLogicWrapper *tllw = new GUITrafficLightLogicWrapper(GUIGlObjectStorage::gIDStorage, *myLogics, *tll); // build the association link->wrapper MSTrafficLightLogic::LinkVectorVector::const_iterator j; for (j=links.begin(); j!=links.end(); j++) { MSTrafficLightLogic::LinkVector::const_iterator j2; for (j2=(*j).begin(); j2!=(*j).end(); j2++) { myLinks2Logic[*j2] = tll->getID(); } } myLogics2Wrapper[tll] = tllw; } }
void GUIViewTraffic::onGamingClick(Position pos) { MSTLLogicControl& tlsControl = MSNet::getInstance()->getTLSControl(); const std::vector<MSTrafficLightLogic*>& logics = tlsControl.getAllLogics(); MSTrafficLightLogic* minTll = 0; SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity(); for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) { // get the logic MSTrafficLightLogic* tll = (*i); if (tlsControl.isActive(tll)) { // get the links const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0); if (lanes.size() > 0) { const Position& endPos = lanes[0]->getShape().back(); if (endPos.distanceTo(pos) < minDist) { minDist = endPos.distanceTo(pos); minTll = tll; } } } } if (minTll != 0) { const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID()); const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics(); if (logics.size() > 1) { MSSimpleTrafficLightLogic* l = (MSSimpleTrafficLightLogic*) logics[0]; for (unsigned int i = 0; i < logics.size() - 1; ++i) { if (minTll->getProgramID() == logics[i]->getProgramID()) { l = (MSSimpleTrafficLightLogic*) logics[i + 1]; tlsControl.switchTo(minTll->getID(), l->getProgramID()); } } if (l == logics[0]) { tlsControl.switchTo(minTll->getID(), l->getProgramID()); } l->changeStepAndDuration(tlsControl, MSNet::getInstance()->getCurrentTimeStep(), 0, l->getPhase(0).duration); update(); } } }
SUMOTime Command_SaveTLSSwitches::execute(SUMOTime currentTime) { MSTrafficLightLogic* light = myLogics.getActive(); const MSTrafficLightLogic::LinkVectorVector& links = light->getLinks(); const std::string& state = light->getCurrentPhaseDef().getState(); for (unsigned int i = 0; i < (unsigned int) links.size(); i++) { if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) { if (myPreviousLinkStates.find(i) == myPreviousLinkStates.end()) { // was not saved before myPreviousLinkStates[i] = currentTime; continue; } } else { if (myPreviousLinkStates.find(i) == myPreviousLinkStates.end()) { // was not yet green continue; } const MSTrafficLightLogic::LinkVector& currLinks = links[i]; const MSTrafficLightLogic::LaneVector& currLanes = light->getLanesAt(i); SUMOTime lastOn = myPreviousLinkStates[i]; for (int j = 0; j < (int) currLinks.size(); j++) { MSLink* link = currLinks[j]; myOutputDevice << " <tlsSwitch id=\"" << light->getID() << "\" programID=\"" << light->getProgramID() << "\" fromLane=\"" << currLanes[j]->getID() << "\" toLane=\"" << link->getLane()->getID() << "\" begin=\"" << time2string(lastOn) << "\" end=\"" << time2string(currentTime) << "\" duration=\"" << time2string(currentTime - lastOn) << "\"/>\n"; } myPreviousLinkStates.erase(myPreviousLinkStates.find(i)); } } return DELTA_T; }
/* ------------------------------------------------------------------------- * GUITrafficLightLogicWrapper - methods * ----------------------------------------------------------------------- */ GUITrafficLightLogicWrapper::GUITrafficLightLogicWrapper( MSTLLogicControl& control, MSTrafficLightLogic& tll) : GUIGlObject(GLO_TLLOGIC, tll.getID()), myTLLogicControl(control), myTLLogic(tll) {}