92 FXIMPLEMENT(
GNETLSEditorFrame, FXVerticalFrame, GNETLSEditorFrameMap, ARRAYNUMBER(GNETLSEditorFrameMap))
101 GNEFrame(horizontalFrameParent, viewNet, "Edit Traffic Light"),
154 WRITE_DEBUG(
"Opening question FXMessageBox 'save TLS'");
156 FXuint answer = FXMessageBox::question(
this, MBOX_YES_NO_CANCEL,
157 "Save TLS Changes",
"%s",
158 "There is unsaved changes in current edited traffic light.\nDo you want to save it before changing mode?");
159 if (answer == MBOX_CLICKED_YES) {
161 WRITE_DEBUG(
"Closed FXMessageBox 'save TLS' with 'YES'");
165 }
else if (answer == MBOX_CLICKED_NO) {
167 WRITE_DEBUG(
"Closed FXMessageBox 'save TLS' with 'No'");
173 WRITE_DEBUG(
"Closed FXMessageBox 'save TLS' with 'Cancel'");
218 std::vector<NBNode*> nodes = oldDefinition->
getNodes();
219 for (
auto it : nodes) {
251 WRITE_DEBUG(
"Opening warning FXMessageBox 'invalid TLS'");
253 FXMessageBox::warning(
this, MBOX_OK,
254 "TLS cannot be created",
"%s",
255 "Traffic Light cannot be created because junction must have\n at least one incoming edge and one outgoing edge.");
309 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
317 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
326 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
334 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
342 o->handle(
this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
388 int tlIndex = it.first;
389 std::vector<GNEInternalLane*> lanes = it.second;
391 if (tlIndex >= 0 && tlIndex < (
int)phase.
state.size()) {
394 for (
auto it_lane : lanes) {
395 it_lane->setLinkState(state);
415 bool haveGreen =
false;
416 bool haveYellow =
false;
417 for (
char c : state) {
425 if (haveGreen && haveYellow) {
428 for (
int i = 0; i < (int)state.size(); i++) {
435 }
else if (haveGreen) {
439 for (
int i = 0; i < (int)state.size(); i++) {
444 }
else if (haveYellow) {
447 for (
int i = 0; i < (int)state.size(); i++) {
498 FXTablePos* tp = (FXTablePos*)ptr;
503 if (GNEAttributeCarrier::canParse<double>(value.text())) {
514 }
else if (!fixed && tp->col == 1) {
516 if (GNEAttributeCarrier::canParse<double>(value.text())) {
530 }
else if (!fixed && tp->col == 2) {
532 if (GNEAttributeCarrier::canParse<double>(value.text())) {
587 for (
auto it_intLanes : it.second) {
592 myInternalLanes.clear();
598 std::string innerID =
":" + nbn->
getID();
600 for (
auto it : links) {
601 int tlIndex = it.getTLIndex();
603 it.getTo(), it.getToLane()), NUM_POINTS);
606 myInternalLanes[tlIndex].push_back(ilane);
608 for (
auto c : nbn->getCrossings()) {
609 if (c->tlLinkIndex2 > 0 && c->tlLinkIndex2 != c->tlLinkIndex) {
615 myInternalLanes[c->tlLinkIndex].push_back(ilane);
621 myInternalLanes[c->tlLinkIndex2].push_back(ilane2);
626 myInternalLanes[c->tlLinkIndex].push_back(ilane);
639 const std::vector<NBTrafficLightLogic::PhaseDefinition>&
649 const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases =
getPhases();
650 for (
int row = 0; row < (int)phases.size(); row++) {
666 std::set<std::string> fromIDs;
671 for (
auto it_lane : edge.
getLanes()) {
672 fromIDs.insert(it_lane->getMicrosimID());
678 for (
auto it : edges) {
679 for (
auto it_lane : it->getLanes()) {
680 fromIDs.insert(it_lane->getMicrosimID());
687 for (
auto it_lane : lanes) {
688 fromIDs.insert(it_lane->getMicrosimID());
694 for (
auto it : links) {
695 if (fromIDs.count(it.getFrom()->getLaneID(it.getFromLane())) > 0) {
696 std::vector<GNEInternalLane*> lanes =
myInternalLanes[it.getTLIndex()];
697 for (
auto it_lane : lanes) {
698 it_lane->onDefault(obj, sel, eventData);
710 for (
auto it : links) {
722 assert(GNEAttributeCarrier::canParse<double>(
string.text()));
723 return TIME2STEPS(GNEAttributeCarrier::parse<double>(
string.text()));
732 myTLSEditorParent(TLSEditorParent) {
837 myCurrentJunction(nullptr) {
894 myNewTLProgram =
new FXButton(
this,
"Create TLS\t\tCreate a new traffic light program",
897 myDeleteTLProgram =
new FXButton(
this,
"Delete TLS\t\tDelete a traffic light program. If all programs are deleted the junction turns into a priority junction.",
913 myTableFont(new FXFont(getApp(),
"Courier New", 9)) {
916 myTableScroll =
new FXScrollWindow(
this, LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT);
924 myPhaseTable->setHelpText(
"phase duration in seconds | phase state");
965 myPhaseTable->setTableSize((
int)phases.size(), fixed ? 2 : 4);
968 for (
int row = 0; row < (int)phases.size(); row++) {
974 myPhaseTable->setItemText(row, fixed ? 1 : 3, phases[row].state.c_str());
975 myPhaseTable->getItem(row, 1)->setJustify(FXTableItem::LEFT);
1004 cycleDuration += it.duration;
1017 myHaveModifications(false) {
1080 WRITE_ERROR(
"Traffic light '" +
id +
"' has unknown type '" + typeS +
"'.");
1123 myLoadedTLS.clear();
1127 const std::vector<NBLoadedSUMOTLDef*>&
1135 std::vector<NBLoadedSUMOTLDef*> definitionsJunctionsWithoutTL;
1138 definitionsJunctionsWithoutTL.push_back(i);
1142 if (definitionsJunctionsWithoutTL.size() > 0) {
1144 WRITE_DEBUG(
"Opening question FXMessageBox 'create TLS in uncontrolled junctions'");
1148 (
"There is " +
toString(definitionsJunctionsWithoutTL.size()) +
" TLS without controlled junction.\nDo you want to create TLSs in uncontrolled Junctions?").c_str());
1149 if (answer == MBOX_CLICKED_YES) {
1151 WRITE_DEBUG(
"Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'Yes'");
1153 for (
auto i : definitionsJunctionsWithoutTL) {
1157 }
else if (answer == MBOX_CLICKED_NO) {
1159 WRITE_DEBUG(
"Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'No'");
1161 for (
auto i : definitionsJunctionsWithoutTL) {
1162 myLoadedTLS.erase(std::find(myLoadedTLS.begin(), myLoadedTLS.end(), i));
1167 WRITE_DEBUG(
"Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'Cancel'");
1180 FXFileDialog opendialog(
this,
"Load TLS Program");
1182 opendialog.setSelectMode(SELECTFILE_EXISTING);
1183 opendialog.setPatternList(
"*.xml");
1187 if (opendialog.execute()) {
1217 "Save TLS Program as",
".xml",
1234 for (
auto j : phases) {
1238 if (varPhaseLength) {
1256 if (time == std::floor(time)) {
GNETLSEditorFrame::TLSModifications * myTLSModifications
modul for load/Save TLS Modifications
TLIndexMap myInternalLanes
FXLabel * myLabelJunctionStatus
label for junction status
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
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.
void enableTLSFile()
enable all elements TLSFile
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
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag.
SAX-handler base for SUMO-files.
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.
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.
void disableTLSFile()
disable all elements TLSFile
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.
Encapsulated SAX-Attributes.
NBTrafficLightDefinition * getCurrentTLSDefinition() const
get current definition
GNETLSEditorFrame::TLSJunction * myTLSJunction
modul for TLS Junction
const std::vector< GNEEdge * > & getGNEIncomingEdges() const
Returns incoming GNEEdges.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
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::TLSFile * myTLSFile
modul for load/Save TLS Programs
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
T get(const std::string &str) const
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
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
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
static std::string varDurString(SUMOTime dur)
convert duration (potentially undefined) to string
const std::vector< NBLoadedSUMOTLDef * > & getLoadedTLS() const
get loaded phases
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
bool checkTLSValids()
check if loaded TrafficLights corresponds to a TL controled junction in net
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
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a 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.
void setHaveModifications(bool value)
set if current TLS was modified
void setCurrentJunction(GNEJunction *junction)
set current junction
void setStatusBarText(const std::string &text)
set staturBar text
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 clearLoadedTLS()
clear loaded phases
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
~TLSDefinition()
destructor
std::string writeSUMOTime(SUMOTime steps)
convert SUMOTime into string
#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
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.
std::vector< NBLoadedSUMOTLDef * > myLoadedTLS
container used to save loaded TLSs
~TLSModifications()
destructor