From d44fd6631af59171abb0161161e754516016d2fc Mon Sep 17 00:00:00 2001 From: namdre Date: Tue, 25 Sep 2018 14:17:49 +0200 Subject: [PATCH] addendum refs #4622 --- src/netedit/GNEApplicationWindow.cpp | 1 + src/netedit/frames/GNETLSEditorFrame.cpp | 109 +++++--------------- src/netedit/frames/GNETLSEditorFrame.h | 3 - src/netimport/NIXMLTrafficLightsHandler.cpp | 7 +- 4 files changed, 27 insertions(+), 93 deletions(-) diff --git a/src/netedit/GNEApplicationWindow.cpp b/src/netedit/GNEApplicationWindow.cpp index 22fb0eed329..37131f33713 100644 --- a/src/netedit/GNEApplicationWindow.cpp +++ b/src/netedit/GNEApplicationWindow.cpp @@ -899,6 +899,7 @@ GNEApplicationWindow::onCmdOpenTLSPrograms(FXObject*, FXSelector, void*) { std::string file = opendialog.getFilename().text(); // Run parser myUndoList->p_begin("Loading TLS Programs from '" + file + "'"); + myNet->computeEverything(this); if (myNet->getViewNet()->getViewParent()->getTLSEditorFrame()->parseTLSPrograms(file) == false) { // Abort undo/redo myUndoList->abort(); diff --git a/src/netedit/frames/GNETLSEditorFrame.cpp b/src/netedit/frames/GNETLSEditorFrame.cpp index 9da8043fd23..82612d9fee5 100644 --- a/src/netedit/frames/GNETLSEditorFrame.cpp +++ b/src/netedit/frames/GNETLSEditorFrame.cpp @@ -182,15 +182,24 @@ GNETLSEditorFrame::isTLSSaved() { bool GNETLSEditorFrame::parseTLSPrograms(const std::string& file) { - myViewNet->getUndoList()->p_begin("Loading TLS"); - NBTrafficLightLogicCont& tllCont = myViewNet->getNet()->getTLLogicCont(); NBTrafficLightLogicCont tmpTLLCont;; NIXMLTrafficLightsHandler tllHandler(tmpTLLCont, myViewNet->getNet()->getEdgeCont()); // existing definitions must be available to update their programs + std::set origDefs; for (NBTrafficLightDefinition* def : tllCont.getDefinitions()) { - tmpTLLCont.insert(def); + // make a copy of every program + NBTrafficLightDefinition* copy = new NBLoadedSUMOTLDef(def, tllCont.getLogic(def->getID(), def->getProgramID())); + std::vector nodes = def->getNodes(); + for (auto it_node : nodes) { + GNEJunction* junction = myViewNet->getNet()->retrieveJunction(it_node->getID()); + myViewNet->getUndoList()->add(new GNEChange_TLS(junction, def, false, false), true); + myViewNet->getUndoList()->add(new GNEChange_TLS(junction, copy, true), true); + } + tmpTLLCont.insert(copy); + origDefs.insert(copy); } + //std::cout << " initialized tmpCont with " << origDefs.size() << " defs\n"; XMLSubSys::runParser(tllHandler, file); std::vector loadedTLS; @@ -201,22 +210,19 @@ GNETLSEditorFrame::parseTLSPrograms(const std::string& file) { } } myViewNet->setStatusBarText("Loaded " + toString(loadedTLS.size()) + " programs"); - if (myTLSFile->checkTLSValids(loadedTLS)) { - for (auto i : loadedTLS) { - const std::map& defs = tllCont.getPrograms(i->getID()); - if (defs.size() > 0) { - NBTrafficLightDefinition* def = defs.begin()->second; - std::vector nodes = def->getNodes(); - for (auto it_node : nodes) { - GNEJunction* junction = myViewNet->getNet()->retrieveJunction(it_node->getID()); - myViewNet->getUndoList()->add(new GNEChange_TLS(junction, i, true), true); - } - - } + for (auto def : loadedTLS) { + if (origDefs.count(def) != 0) { + // already add to undolist before + //std::cout << " skip " << def->getDescription() << "\n"; + continue; + } + std::vector nodes = def->getNodes(); + //std::cout << " add " << def->getDescription() << " for nodes=" << toString(nodes) << "\n"; + for (auto it_node : nodes) { + GNEJunction* junction = myViewNet->getNet()->retrieveJunction(it_node->getID()); + //myViewNet->getUndoList()->add(new GNEChange_TLS(junction, myTLSEditorParent->myEditedDef, false), true); + myViewNet->getUndoList()->add(new GNEChange_TLS(junction, def, true), true); } - myViewNet->getUndoList()->p_end(); - } else { - myViewNet->getUndoList()->p_abort(); } // clean up temporary container to avoid deletion of defs when it's destruct is called for (NBTrafficLightDefinition* def : tmpTLLCont.getDefinitions()) { @@ -1120,54 +1126,6 @@ GNETLSEditorFrame::TLSFile::disableTLSFile() { } -bool -GNETLSEditorFrame::TLSFile::checkTLSValids(std::vector& loadedTLS) { - std::vector definitionsJunctionsWithoutTL; - for (auto i : loadedTLS) { - if (myTLSEditorParent->getViewNet()->getNet()->getTLLogicCont().getPrograms(i->getID()).size() == 0) { - definitionsJunctionsWithoutTL.push_back(i); - } - } - // check if there is definitions loaded with an uncontrolled junction asociated - if (definitionsJunctionsWithoutTL.size() > 0) { - // write warning if netedit is running in testing mode - WRITE_DEBUG("Opening question FXMessageBox 'create TLS in uncontrolled junctions'"); - // open question box - FXuint answer = FXMessageBox::question(myTLSEditorParent, MBOX_YES_NO_CANCEL, - "Create TLS", "%s", - ("There is " + toString(definitionsJunctionsWithoutTL.size()) + " TLS without controlled junction.\nDo you want to create TLSs in uncontrolled Junctions?").c_str()); - if (answer == MBOX_CLICKED_YES) { //1:yes, 2:no, 4:esc/cancel - // write warning if netedit is running in testing mode - WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'Yes'"); - // convert Junctions in TLS - for (auto i : definitionsJunctionsWithoutTL) { - GNEJunction* junction = myTLSEditorParent->getViewNet()->getNet()->retrieveJunction(i->getID(), false); - if (junction != 0) { - junction->setAttribute(SUMO_ATTR_TYPE, "traffic_light", myTLSEditorParent->getViewNet()->getUndoList()); - } else { - WRITE_WARNING("Could not create traffic light '" + i->getID() + "' because there is no junction with the same id"); - } - } - } else if (answer == MBOX_CLICKED_NO) { - // write warning if netedit is running in testing mode - WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'No'"); - // delete loaded TLSs without associated controlled Junction - for (auto i : definitionsJunctionsWithoutTL) { - loadedTLS.erase(std::find(loadedTLS.begin(), loadedTLS.end(), i)); - delete i; - } - } else { - // write warning if netedit is running in testing mode - WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'Cancel'"); - // return false to abort loading of TLSs - return false; - } - } - - // return true to continue loading TLSs - return true; -} - long GNETLSEditorFrame::TLSFile::onCmdLoadTLSProgram(FXObject*, FXSelector, void*) { @@ -1212,12 +1170,7 @@ GNETLSEditorFrame::TLSFile::onCmdLoadTLSProgram(FXObject*, FXSelector, void*) { if (newDefSameProgram != nullptr) { // replace old program when loading the same program ID myTLSEditorParent->myEditedDef = newDefSameProgram; - //myTLSEditorParent->myEditedDef = new NBLoadedSUMOTLDef(newDefSameProgram, newDefSameProgram->getLogic()); - //myTLSEditorParent->getViewNet()->getUndoList()->add(new GNEChange_TLS(junction, myTLSEditorParent->myEditedDef, false), true); - //myTLSEditorParent->getViewNet()->getUndoList()->add(new GNEChange_TLS(junction, , true), true); WRITE_MESSAGE("Updated program '" + newDefSameProgram->getProgramID() + "' for tlLogic '" + myTLSEditorParent->myEditedDef->getID() + "'"); - } else { - //myTLSEditorParent->myEditedDef = new NBLoadedSUMOTLDef(newDefSameProgram, newDefSameProgram->getLogic()); } } else { myTLSEditorParent->getViewNet()->setStatusBarText("No programs found for traffic light '" + myTLSEditorParent->myEditedDef->getID() + "'"); @@ -1228,20 +1181,6 @@ GNETLSEditorFrame::TLSFile::onCmdLoadTLSProgram(FXObject*, FXSelector, void*) { tmpTLLCont.removeProgram(def->getID(), def->getProgramID(), false); } - //myTLSEditorParent->myEditedDef->cleanupStates(); - - // check that only a phase was loaded - /* for(auto i : myLoadedTLS) { - if(i->getID() == myTLSEditorParent->myTLSJunction->getCurrentJunction()->getID()) { - myTLSEditorParent->myEditedDef->getProgramID(); - - for (auto j : i.second) { - myTLSEditorParent->myEditedDef->getLogic()->addStep(j.duration, j.state, j.minDur, j.maxDur); - } - - } - } - */ myTLSEditorParent->myTLSPhases->initPhaseTable(); myTLSEditorParent->myTLSModifications->setHaveModifications(true); } diff --git a/src/netedit/frames/GNETLSEditorFrame.h b/src/netedit/frames/GNETLSEditorFrame.h index 0dcf3ad72a8..b5065c5b6d2 100644 --- a/src/netedit/frames/GNETLSEditorFrame.h +++ b/src/netedit/frames/GNETLSEditorFrame.h @@ -281,9 +281,6 @@ class GNETLSEditorFrame : public GNEFrame { /// @brief disable all elements TLSFile void disableTLSFile(); - /// @brief check if loaded TrafficLights corresponds to a TL controled junction in net - bool checkTLSValids(std::vector& loadedTLS); - /// @name FOX-callbacks /// @{ /// @brief load TLS Program from an additional file diff --git a/src/netimport/NIXMLTrafficLightsHandler.cpp b/src/netimport/NIXMLTrafficLightsHandler.cpp index fbc6c8d40f1..014b47011e6 100644 --- a/src/netimport/NIXMLTrafficLightsHandler.cpp +++ b/src/netimport/NIXMLTrafficLightsHandler.cpp @@ -105,11 +105,7 @@ void NIXMLTrafficLightsHandler::myEndElement(int element) { switch (element) { case SUMO_TAG_TLLOGIC: - if (!myCurrentTL && !myIgnoreUnknown) { - WRITE_ERROR("Unmatched closing tag for tlLogic."); - } else { - myCurrentTL = 0; - } + myCurrentTL = 0; break; default: break; @@ -195,6 +191,7 @@ NIXMLTrafficLightsHandler::initTrafficLightLogic(const SUMOSAXAttributes& attrs, for (std::vector::iterator it = nodes.begin(); it != nodes.end(); it++) { loadedDef->addNode(*it); } + //std::cout << " case3 oldDef=" << oldDef->getDescription() << " loadedDef=" << loadedDef->getDescription() << "\n"; myTLLCont.insert(loadedDef); } } else {