long GNETLSEditorFrame::onCmdDefSwitch(FXObject*, FXSelector, void*) { assert(myCurrentJunction != 0); assert((int)myDefinitions.size() == myProgramComboBox->getNumItems()); NBTrafficLightDefinition* tlDef = myDefinitions[myProgramComboBox->getCurrentItem()]; // logic may not have been recomputed yet. recompute to be sure NBTrafficLightLogicCont& tllCont = myViewNet->getNet()->getTLLogicCont(); myViewNet->getNet()->computeJunction(myCurrentJunction); NBTrafficLightLogic* tllogic = tllCont.getLogic(tlDef->getID(), tlDef->getProgramID()); if (tllogic != 0) { // now we can be sure that the tlDef is up to date (i.e. re-guessed) buildIinternalLanes(tlDef); // create working copy from original def delete myEditedDef; myEditedDef = new NBLoadedSUMOTLDef(tlDef, tllogic); myOffset->setText(toString(STEPS2TIME(myEditedDef->getLogic()->getOffset())).c_str()); initPhaseTable(); updateCycleDuration(); } else { // tlDef has no valid logic (probably because id does not control any links onCmdCancel(0, 0, 0); myViewNet->setStatusBarText("Traffic light does not control any links"); } return 1; }
long GNETLSEditorFrame::onCmdPhaseDelete(FXObject*, FXSelector, void*) { myHaveModifications = true; const int newRow = MAX2((int)0, (int)myPhaseTable->getCurrentRow() - 1); myEditedDef->getLogic()->deletePhase(myPhaseTable->getCurrentRow()); initPhaseTable(newRow); myPhaseTable->setFocus(); return 1; }
void GNETLSEditorFrame::handleChange(GNEInternalLane* lane) { myHaveModifications = true; if (myViewNet->changeAllPhases()) { const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = getPhases(); for (int row = 0; row < (int)phases.size(); row++) { myEditedDef->getLogic()->setPhaseState(row, lane->getTLIndex(), lane->getLinkState()); } } else { myEditedDef->getLogic()->setPhaseState(myPhaseTable->getCurrentRow(), lane->getTLIndex(), lane->getLinkState()); } initPhaseTable(myPhaseTable->getCurrentRow()); myPhaseTable->setFocus(); }
long GNETLSEditorFrame::onCmdPhaseCreate(FXObject*, FXSelector, void*) { myHaveModifications = true; // allows insertion at first position by deselecting via arrow keys int newIndex = myPhaseTable->getSelStartRow() + 1; int oldIndex = MAX2(0, myPhaseTable->getSelStartRow()); // copy current row const SUMOTime duration = getSUMOTime(myPhaseTable->getItemText(oldIndex, 0)); const std::string state = myPhaseTable->getItemText(oldIndex, 1).text(); myEditedDef->getLogic()->addStep(duration, state, newIndex); myPhaseTable->setCurrentItem(newIndex, 0); initPhaseTable(newIndex); myPhaseTable->setFocus(); return 1; }
void GNETLSEditorFrame::cleanup() { if (myCurrentJunction) { myCurrentJunction->selectTLS(false); } // clean data structures myCurrentJunction = 0; myHaveModifications = false; delete myEditedDef; myEditedDef = 0; buildIinternalLanes(0); // only clears // clean up controls myOffset->setText(""); myDefinitions.clear(); myDefBox->hide(); initPhaseTable(); // only clears when there are no definitions myCycleDuration->hide(); updateDescription(); }