85 FXIMPLEMENT(
GNETLSEditorFrame, FXVerticalFrame, GNETLSEditorFrameMap, ARRAYNUMBER(GNETLSEditorFrameMap))
94 GNEFrame(horizontalFrameParent, viewNet, "Edit Traffic Light"),
95 myEditedDef(
nullptr) {
147 WRITE_DEBUG(
"Opening question FXMessageBox 'save TLS'");
149 FXuint answer = FXMessageBox::question(
this, MBOX_YES_NO_CANCEL,
150 "Save TLS Changes",
"%s",
151 "There is unsaved changes in current edited traffic light.\nDo you want to save it before changing mode?");
152 if (answer == MBOX_CLICKED_YES) {
154 WRITE_DEBUG(
"Closed FXMessageBox 'save TLS' with 'YES'");
158 }
else if (answer == MBOX_CLICKED_NO) {
160 WRITE_DEBUG(
"Closed FXMessageBox 'save TLS' with 'No'");
166 WRITE_DEBUG(
"Closed FXMessageBox 'save TLS' with 'Cancel'");
182 std::set<NBTrafficLightDefinition*> origDefs;
186 if (logic !=
nullptr) {
188 std::vector<NBNode*> nodes = def->getNodes();
189 for (
auto it_node : nodes) {
195 origDefs.insert(copy);
197 WRITE_WARNING(
"tlLogic '" + def->getID() +
"', program '" + def->getProgramID() +
"' could not be built");
203 std::vector<NBLoadedSUMOTLDef*> loadedTLS;
206 if (sdef !=
nullptr) {
207 loadedTLS.push_back(sdef);
211 for (
auto def : loadedTLS) {
212 if (origDefs.count(def) != 0) {
217 std::vector<NBNode*> nodes = def->getNodes();
219 for (
auto it_node : nodes) {
227 tmpTLLCont.
removeProgram(def->getID(), def->getProgramID(),
false);
249 std::vector<NBNode*> nodes = oldDefinition->
getNodes();
250 for (
auto it : nodes) {
282 WRITE_DEBUG(
"Opening warning FXMessageBox 'invalid TLS'");
284 FXMessageBox::warning(
this, MBOX_OK,
285 "TLS cannot be created",
"%s",
286 "Traffic Light cannot be created because junction must have\n at least one incoming edge and one outgoing edge.");
318 if (tllogic !=
nullptr) {
340 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE),
nullptr);
348 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE),
nullptr);
357 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE),
nullptr);
365 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE),
nullptr);
373 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE),
nullptr);
419 int tlIndex = it.first;
420 std::vector<GNEInternalLane*> lanes = it.second;
422 if (tlIndex >= 0 && tlIndex < (
int)phase.
state.size()) {
425 for (
auto it_lane : lanes) {
426 it_lane->setLinkState(state);
445 std::set<int> crossingIndices;
448 crossingIndices.insert(c->tlLinkIndex);
449 crossingIndices.insert(c->tlLinkIndex2);
454 bool haveGreen =
false;
455 bool haveYellow =
false;
456 for (
char c : state) {
464 if (haveGreen && haveYellow) {
467 for (
int i = 0; i < (int)state.size(); i++) {
474 }
else if (haveGreen) {
478 for (
int i = 0; i < (int)state.size(); i++) {
480 if (crossingIndices.count(i) == 0) {
487 }
else if (haveYellow) {
490 for (
int i = 0; i < (int)state.size(); i++) {
541 FXTablePos* tp = (FXTablePos*)ptr;
546 if (GNEAttributeCarrier::canParse<double>(value.text())) {
557 }
else if (!fixed && tp->col == 1) {
559 if (GNEAttributeCarrier::canParse<double>(value.text())) {
573 }
else if (!fixed && tp->col == 2) {
575 if (GNEAttributeCarrier::canParse<double>(value.text())) {
630 for (
auto it_intLanes : it.second) {
635 myInternalLanes.clear();
637 if (tlDef !=
nullptr) {
641 std::string innerID =
":" + nbn->
getID();
643 for (
auto it : links) {
644 int tlIndex = it.getTLIndex();
646 it.getTo(), it.getToLane()), NUM_POINTS);
649 myInternalLanes[tlIndex].push_back(ilane);
652 for (
auto c : nbn->getCrossings()) {
653 if (c->tlLinkIndex2 > 0 && c->tlLinkIndex2 != c->tlLinkIndex) {
659 myInternalLanes[c->tlLinkIndex].push_back(ilane);
665 myInternalLanes[c->tlLinkIndex2].push_back(ilane2);
670 myInternalLanes[c->tlLinkIndex].push_back(ilane);
684 const std::vector<NBTrafficLightLogic::PhaseDefinition>&
694 const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases =
getPhases();
695 for (
int row = 0; row < (int)phases.size(); row++) {
711 std::set<std::string> fromIDs;
716 for (
auto it_lane : edge.
getLanes()) {
717 fromIDs.insert(it_lane->getMicrosimID());
723 for (
auto it : edges) {
724 for (
auto it_lane : it->getLanes()) {
725 fromIDs.insert(it_lane->getMicrosimID());
732 for (
auto it_lane : lanes) {
733 fromIDs.insert(it_lane->getMicrosimID());
739 for (
auto it : links) {
740 if (fromIDs.count(it.getFrom()->getLaneID(it.getFromLane())) > 0) {
741 std::vector<GNEInternalLane*> lanes =
myInternalLanes[it.getTLIndex()];
742 for (
auto it_lane : lanes) {
743 it_lane->onDefault(obj, sel, eventData);
755 for (
auto it : links) {
767 assert(GNEAttributeCarrier::canParse<double>(
string.text()));
768 return TIME2STEPS(GNEAttributeCarrier::parse<double>(
string.text()));
777 myTLSEditorParent(TLSEditorParent) {
878 myCurrentJunction(nullptr) {
935 myNewTLProgram =
new FXButton(
this,
"Create TLS\t\tCreate a new traffic light program",
938 myDeleteTLProgram =
new FXButton(
this,
"Delete TLS\t\tDelete a traffic light program. If all programs are deleted the junction turns into a priority junction.",
954 myTableFont(new FXFont(getApp(),
"Courier New", 9)) {
957 myTableScroll =
new FXScrollWindow(
this, LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT);
965 myPhaseTable->setHelpText(
"phase duration in seconds | phase state");
1006 myPhaseTable->setTableSize((
int)phases.size(), fixed ? 2 : 4);
1009 for (
int row = 0; row < (int)phases.size(); row++) {
1015 myPhaseTable->setItemText(row, fixed ? 1 : 3, phases[row].state.c_str());
1016 myPhaseTable->getItem(row, 1)->setJustify(FXTableItem::LEFT);
1045 cycleDuration += it.duration;
1058 myHaveModifications(false) {
1105 FXFileDialog opendialog(
this,
"Load TLS Program");
1107 opendialog.setSelectMode(SELECTFILE_EXISTING);
1108 opendialog.setPatternList(
"*.xml");
1112 if (opendialog.execute()) {
1120 std::set<NBLoadedSUMOTLDef*> newDefsOtherProgram;
1125 newDefSameProgram = sdef;
1127 newDefsOtherProgram.insert(sdef);
1131 const int newPrograms = (int)newDefsOtherProgram.size();
1132 if (newPrograms > 0 || newDefSameProgram !=
nullptr) {
1134 for (
auto newProg : newDefsOtherProgram) {
1135 for (
auto it_node : nodes) {
1140 if (newPrograms > 0) {
1143 if (newDefSameProgram !=
nullptr) {
1154 tmpTLLCont.
removeProgram(def->getID(), def->getProgramID(),
false);
1167 "Save TLS Program as",
".xml",
1185 for (
auto j : phases) {
1189 if (varPhaseLength) {
1207 if (time == std::floor(time)) {
1217 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE),
nullptr);
GNETLSEditorFrame::TLSModifications * myTLSModifications
modul for load/Save TLS Modifications
TLIndexMap myInternalLanes
FXLabel * myLabelJunctionStatus
label for junction status
const std::map< std::string, NBTrafficLightDefinition * > & getPrograms(const std::string &id) const
Returns all programs for the given tl-id.
The link has green light, may pass.
long onCmdGuess(FXObject *, FXSelector, void *)
Called when the user presses the button Guess.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
std::vector< GNELane * > retrieveLanes(bool onlySelected=false)
return all lanes
void close()
Closes the device and removes it from the dictionary.
TLSDefinition(GNETLSEditorFrame *TLSEditorParent)
constructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
A structure which describes a connection between edges or lanes.
#define GUIDesignComboBoxNCol
number of column of every combo box
FXLabel * myCycleDuration
label with the cycle duration
long onUpdNeedsDefAndPhase(FXObject *, FXSelector, void *)
Called when occurs an update of needs definition an dphase.
long onCmdPhaseDelete(FXObject *, FXSelector, void *)
Called when the user deletes a Phase.
GNETLSEditorFrame::TLSPhases * myTLSPhases
modul for TLS Phases
bool removeProgram(const std::string id, const std::string programID, bool del=true)
Removes a program of a logic definition from the dictionary.
SUMOTime getOffset() const
Returns the offset of first switch.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
bool parseTLSPrograms(const std::string &file)
parse TLS Programs from a file
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
const std::vector< GNEEdge * > & getGNEOutgoingEdges() const
Returns incoming GNEEdges.
long onCmdDefCreate(FXObject *, FXSelector, void *)
Called when the user creates a TLS.
FXButton * myDiscardModificationsButtons
button for cancel modifications
void setPhaseMaxDuration(int phaseIndex, SUMOTime duration)
FXLabel * myOffsetLabel
offset label
long onCmdSaveTLSProgram(FXObject *, FXSelector, void *)
save TLS Programm to an additional file
void setOffset(SUMOTime offset)
Sets the offset of this tls.
int getNumLinks()
Returns the number of participating links.
A loaded (complete) traffic light logic.
FXFont * myTableFont
font for the phase table
GNEJunction * getCurrentJunction() const
get current modified junction
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
A container for traffic light definitions and built programs.
A SUMO-compliant built logic for a traffic light.
FXLabel * myNameLabel
name label
#define GUIDesignTableLimitedHeight
design for table extended over frame but with limited Height
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
The link has green light, has to brake.
long onCmdPhaseSwitch(FXObject *, FXSelector, void *)
Called when the user switchs a Phase.
void deletePhase(int index)
TrafficLightType getType() const
get the algorithm type (static etc..)
FXTextField * myTextFieldJunctionStatus
text field for junction status
selected junction von TLS
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
const NBConnectionVector & getControlledLinks() const
returns the controlled links (depends on previous call to collectLinks)
void removeAdditionalGLObject(GUIGlObject *o)
Removes an additional object (detector/shape/trigger) from being visualised.
The base class for traffic light logic definitions.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
FXComboBox * myProgramComboBox
the comboBox for selecting the tl-definition to edit
bool isTLSSaved()
check if modifications in TLS was saved
static const SUMOTime UNSPECIFIED_DURATION
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
void editJunction(GNEJunction *junction)
edits the traffic light for the given junction
long onCmdLoadTLSProgram(FXObject *, FXSelector, void *)
void initPhaseTable(int index=0)
initialies the phase table
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
PositionVector reverse() const
reverse position vector
FXString gCurrentFolder
The folder used as last.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
const std::string & getProgramID() const
Returns the ProgramID.
void selectTLS(bool selected)
notify the junction of being selected in tls-mode. (used to control drawing)
definition related controls
FXButton * mySaveTLSProgramButton
button for save TLS Programs
maximum duration of a phase
const std::string & getID() const
Returns the id.
void handleMultiChange(GNELane *lane, FXObject *obj, FXSelector sel, void *data)
update phase definition for the current traffic light and phase
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
The definition of a single phase of the logic.
FXLabel * myProgramLabel
program label
TLSJunction(GNETLSEditorFrame *TLSEditorParent)
constructor
long onUpdNeedsDef(FXObject *, FXSelector, void *)
Called when occurs an update of needs definition.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
A RT-tree for efficient storing of SUMO's GL-objects.
long onCmdCleanup(FXObject *, FXSelector, void *)
Called when the user cleans up states.
static FXString getFilename2Write(FXWindow *parent, const FXString &header, const FXString &extension, FXIcon *icon, FXString ¤tFolder)
Returns the file name to write.
bool myHaveModifications
whether the current tls was modified
LinkState getLinkState() const
whether link state has been modfied
long onCmdDefDelete(FXObject *, FXSelector, void *)
Called when the user deletes a TLS.
GNEViewNet * getViewNet() const
get view net
long onCmdDefOffset(FXObject *, FXSelector, void *)
Called when the user changes the offset of a TLS.
#define WRITE_WARNING(msg)
FXButton * myDeleteSelectedPhaseButton
delete phase button
long onCmdDefSwitch(FXObject *, FXSelector, void *)
Called when the user switchs a TLS.
long onCmdDefAddOff(FXObject *, FXSelector, void *)
Called when the user adds a OFF.
static OptionsCont & getOptions()
Retrieves the options.
bool changeAllPhases() const
change all phases
GNEViewNet * myViewNet
View Net for changes.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
FXScrollWindow * myTableScroll
window for oversized phase tables
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
void clearTLSAttributes()
clear TLS attributes
bool isTLControlled() const
Returns whether this node is controlled by any tls.
std::string getAttribute(SumoXMLAttr key) const
GNEUndoList * getUndoList() const
get the undoList object
FXTable * getPhaseTable() const
get phase table
void hideCycleDuration()
hide cycle duration
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditorParent
FXTextField * myNameTextField
name text field
#define GUIDesignTextField
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
void initTLSAttributes(GNEJunction *junction)
initializes the definitions and corresponding listbox
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button.
GNEEdge & getParentEdge()
Returns underlying parent edge.
NBEdgeCont & getEdgeCont()
returns the NBEdgeCont of the underlying netbuilder
NBTrafficLightDefinition * getCurrentTLSDefinition() const
get current definition
GNETLSEditorFrame::TLSJunction * myTLSJunction
modul for TLS Junction
const std::vector< GNEEdge * > & getGNEIncomingEdges() const
Returns incoming GNEEdges.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
GNEJunction * retrieveJunction(const std::string &id, bool failHard=true)
get junction by id
TLSAttributes(GNETLSEditorFrame *TLSEditorParent)
constructor
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
bool controlsEdge(GNEEdge &edge) const
whether the given edge is controlled by the currently edited tlDef
GNETLSEditorFrame::TLSAttributes * myTLSAttributes
modul for TLS attributes
long onUpdDefCreate(FXObject *, FXSelector, void *)
Called when occurs an update of create definition.
void buildIinternalLanes(NBTrafficLightDefinition *tlDef)
builds internal lanes for the given tlDef
replace program with a newly guessed program
TLSPhases(GNETLSEditorFrame *TLSEditorParent)
constructor
bool checkHaveModifications() const
check if current TLS was modified
long onCmdPhaseEdit(FXObject *, FXSelector, void *)
Called when the user edits a Phase.
std::string state
The state definition.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
void computeJunction(GNEJunction *junction)
trigger recomputation of junction shape and logic param[in] window The window to inform about delay ...
~GNETLSEditorFrame()
Destructor.
void handleChange(GNEInternalLane *lane)
update phase definition for the current traffic light and phase
int getTLIndex() const
get Traffic Light index
NBTrafficLightLogic * getLogic()
Returns the internal logic.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
FXDEFMAP(GNETLSEditorFrame) GNETLSEditorFrameMap[]
~TLSAttributes()
destructor
const std::string & getProgramID() const
Returns the ProgramID.
void p_abort()
reverts and discards ALL active command groups
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
void move2side(double amount)
move position vector to side using certain ammount
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
long onCmdAddUnused(FXObject *, FXSelector, void *)
Called when the user cleans up states.
FXTable * myPhaseTable
table for selecting and rearranging phases and for changing duration
static SUMOTime getSUMOTime(const FXString &string)
converts to SUMOTime
A road/street connecting two junctions (netedit-version)
int getNumberOfTLSDefinitions() const
get number of definitions
#define GUIDesignTextFieldNCol
Num of column of text field.
long onUpdDefSwitch(FXObject *, FXSelector, void *)
Called when occurs an update of switch definition.
GNEJunction * myCurrentJunction
the junction of the tls is being modified
static std::string varDurString(SUMOTime dur)
convert duration (potentially undefined) to string
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
FXButton * myLoadTLSProgramButton
button for load TLS Programs
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
void showCycleDuration()
show cycle duration
virtual void show()
show Frame
void updateCycleDuration()
recomputes cycle duration and updates label
int getNumberOfPrograms() const
get number of programs
std::vector< GNEEdge * > retrieveEdges(bool onlySelected=false)
return all edges
The link has yellow light, may pass.
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node (The set of tls that control this node) ...
TrafficLightType getType() const
get the algorithm type (static etc..)
long onCmdOK(FXObject *, FXSelector, void *)
SUMOTime getOffset() const
get current offset in SUMOTIme
void updateJunctionDescription() const
update descrition
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
long onCmdDefSubRename(FXObject *, FXSelector, void *)
Called when the user sub-renames a TLS.
The link has red light (must brake)
A storage for options typed value containers)
void setOffset(SUMOTime offset)
set new offset
const std::vector< NBTrafficLightLogic::PhaseDefinition > & getPhases()
the phase of the current traffic light
void setPhaseDuration(int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
GNENet * getNet() const
get the net object
#define GUIDesignTextFieldReal
text field extended over Frame with thick frame and limited to Doubles/doubles
long onCmdPhaseCreate(FXObject *, FXSelector, void *)
Called when the user creates a Phase.
FXButton * mySaveModificationsButtons
button for save modifications
Represents a single node (junction) during network building.
long onUpdNeedsDef(FXObject *, FXSelector, void *)
enable buttons, only when a tlLogic is being edited
void setHaveModifications(bool value)
set if current TLS was modified
void setCurrentJunction(GNEJunction *junction)
set current junction
A definition of a pedestrian crossing.
void setStatusBarText(const std::string &text)
set staturBar text
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
Static storage of an output device and its base (abstract) implementation.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
~TLSDefinition()
destructor
std::string writeSUMOTime(SUMOTime steps)
convert SUMOTime into string
Importer for edge connections stored in XML.
#define GUIDesignLabelLeft
The link has yellow light, has to brake anyway.
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
FXLabel * myLabelJunctionID
label for junction ID
long onCmdDefRename(FXObject *, FXSelector, void *)
Called when the user renames a TLS.
long onUpdModified(FXObject *, FXSelector, void *)
Called when occurs an update of modified.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
FXButton * myInsertDuplicateButton
insert new phase button
#define GUIDesignLabelAttribute
label extended over the matrix column with thick frame and height of 23
FXButton * myNewTLProgram
button for create new Traffic light program
#define WRITE_MESSAGE(msg)
FXTextField * myOffsetTextField
the control for modifying offset
FXButton * myDeleteTLProgram
button for delete traffic light program
NBNode * getNBNode() const
Return net build node.
NBTrafficLightLogic * getLogic(const std::string &id, const std::string &programID) const
Returns the computed logic for the given name.
FXTextField * myTextFieldJunctionID
text field for junction ID
NBTrafficLightLogicCont & getTLLogicCont()
returns the tllcont of the underlying netbuilder
NBLoadedSUMOTLDef * myEditedDef
the traffic light definition being edited
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
std::vector< NBTrafficLightDefinition * > myTLSDefinitions
the list of Definitions for the current junction
a single phase description
void cleanup()
cleans up previous lanes
TLSModifications(GNETLSEditorFrame *TLSEditorParent)
constructor
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definitions getDefinitions() const
~TLSModifications()
destructor