long GNETLSEditorFrame::onCmdOK(FXObject*, FXSelector, void*) { if (myCurrentJunction != 0) { if (myHaveModifications) { NBTrafficLightDefinition* old = myDefinitions[myProgramComboBox->getCurrentItem()]; std::vector<NBNode*> nodes = old->getNodes(); for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) { GNEJunction* junction = myViewNet->getNet()->retrieveJunction((*it)->getID()); myViewNet->getUndoList()->add(new GNEChange_TLS(junction, old, false), true); myViewNet->getUndoList()->add(new GNEChange_TLS(junction, myEditedDef, true), true); } myEditedDef = 0; myViewNet->getUndoList()->p_end(); cleanup(); myViewNet->update(); } else { onCmdCancel(0, 0, 0); } } return 1; }
NBLoadedSUMOTLDef* NIXMLTrafficLightsHandler::initTrafficLightLogic(const SUMOSAXAttributes& attrs, NBLoadedSUMOTLDef* currentTL) { if (currentTL) { WRITE_ERROR("Definition of tlLogic '" + currentTL->getID() + "' was not finished."); return 0; } bool ok = true; std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); std::string programID = attrs.getOpt<std::string>(SUMO_ATTR_PROGRAMID, id.c_str(), ok, "<unknown>"); SUMOTime offset = attrs.hasAttribute(SUMO_ATTR_OFFSET) ? TIME2STEPS(attrs.get<SUMOReal>(SUMO_ATTR_OFFSET, id.c_str(), ok)) : 0; std::string typeS = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, 0, ok, OptionsCont::getOptions().getString("tls.default-type")); TrafficLightType type; if (SUMOXMLDefinitions::TrafficLightTypes.hasString(typeS)) { type = SUMOXMLDefinitions::TrafficLightTypes.get(typeS); } else { WRITE_ERROR("Unknown traffic light type '" + typeS + "' for tlLogic '" + id + "'."); return 0; } // there are two scenarios to consider // 1) the tll.xml is loaded to update traffic lights defined in a net.xml: // simply retrieve the loaded definitions and update them // 2) the tll.xml is loaded to define new traffic lights // nod.xml will have triggered building of NBOwnTLDef. Replace it with NBLoadedSUMOTLDef NBLoadedSUMOTLDef* loadedDef = dynamic_cast<NBLoadedSUMOTLDef*>(myTLLCont.getDefinition(id, programID)); if (loadedDef == 0) { // case 2 NBTrafficLightDefinition* newDef = dynamic_cast<NBOwnTLDef*>(myTLLCont.getDefinition( id, NBTrafficLightDefinition::DefaultProgramID)); if (newDef == 0) { // the default program may have already been replaced with a loaded program newDef = dynamic_cast<NBLoadedSUMOTLDef*>(myTLLCont.getDefinition( id, NBTrafficLightDefinition::DefaultProgramID)); if (newDef == 0) { WRITE_ERROR("Cannot load traffic light program for unknown id '" + id + "', programID '" + programID + "'."); return 0; } } assert(newDef != 0); loadedDef = new NBLoadedSUMOTLDef(id, programID, offset, type); // copy nodes and controlled inner edges std::vector<NBNode*> nodes = newDef->getNodes(); for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) { loadedDef->addNode(*it); } loadedDef->addControlledInnerEdges(newDef->getControlledInnerEdges()); if (programID == NBTrafficLightDefinition::DefaultProgramID) { // replace default Program std::vector<NBNode*> nodes = newDef->getNodes(); for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) { (*it)->removeTrafficLight(newDef); } myTLLCont.removeProgram(id, NBTrafficLightDefinition::DefaultProgramID); } myTLLCont.insert(loadedDef); } if (ok) { myResetPhases = true; return loadedDef; } else { return 0; } }