SUMO - Simulation of Urban MObility
GNEProhibitionFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // The Widget for editing connection prohibits
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <iostream>
25 #include <set>
37 #include <netedit/GNENet.h>
45 #include <netedit/GNEUndoList.h>
46 #include <netedit/GNEViewNet.h>
47 #include <netedit/GNEViewParent.h>
48 
49 #include "GNEProhibitionFrame.h"
50 
51 // ===========================================================================
52 // FOX callback mapping
53 // ===========================================================================
54 FXDEFMAP(GNEProhibitionFrame) GNEProhibitionFrameMap[] = {
55  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNEProhibitionFrame::onCmdCancel),
56  FXMAPFUNC(SEL_COMMAND, MID_OK, GNEProhibitionFrame::onCmdOK)
57 };
58 
59 // Object implementation
60 FXIMPLEMENT(GNEProhibitionFrame, FXVerticalFrame, GNEProhibitionFrameMap, ARRAYNUMBER(GNEProhibitionFrameMap))
61 
62 // ===========================================================================
63 // static members
64 // ===========================================================================
71 
72 // ===========================================================================
73 // method definitions
74 // ===========================================================================
75 
76 GNEProhibitionFrame::GNEProhibitionFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
77  GNEFrame(horizontalFrameParent, viewNet, "Prohibits"), myCurrentConn(0) {
78  getFrameHeaderLabel()->setText("Prohibitions");
79 
80  // init colors here
83  prohibitedColor = RGBColor(0, 179, 0);
87 
88  // Create groupbox for current connection information
89  myGroupBoxDescription = new FXGroupBox(myContentFrame, "Relative to connection", GUIDesignGroupBoxFrame);
90 
91  // Create label for current connection description and update it
94 
95  // Create groupbox for color legend
96  myGroupBoxLegend = new FXGroupBox(myContentFrame, "Legend", GUIDesignGroupBoxFrame);
97 
98  // Create labels for color legend
102  myUndefinedLabel = new FXLabel(myGroupBoxLegend, "No conflict", 0, GUIDesignLabelFrameInformation);
106  myProhibitingLabel = new FXLabel(myGroupBoxLegend, "Has right of way", 0, GUIDesignLabelFrameInformation);
108  myProhibitingLabel = new FXLabel(myGroupBoxLegend, "Unregulated conflict", 0, GUIDesignLabelFrameInformation);
110  myProhibitingLabel = new FXLabel(myGroupBoxLegend, "Mutual conflict", 0, GUIDesignLabelFrameInformation);
112 
113  // Create "Cancel" button
114  myCancelButton = new FXButton(this, "Cancel\t\tDiscard prohibition modifications (Esc)",
116  // Create "OK" button
117  //mySaveButton = new FXButton(this, "OK\t\tSave prohibition modifications (Enter)",
118  // GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_OK, GUIDesignButton);
119 }
120 
122 
123 void
124 GNEProhibitionFrame::handleConnectionClick(GNEConnection* conn, bool /* mayDefinitelyPass */, bool /* allowConflict */, bool /* toggle */) {
125 
126  if (myCurrentConn == 0) {
127  myCurrentConn = conn;
129 
130  // determine prohibition status of all other connections with respect to the selected one
132  std::vector<GNEConnection*> allConns = junction->getGNEConnections();
133  NBNode* node = junction->getNBNode();
134  NBEdge* currentConnFrom = myCurrentConn->getEdgeFrom()->getNBEdge();
135  NBEdge* currentConnTo = myCurrentConn->getEdgeTo()->getNBEdge();
136 
137  for (auto conn : allConns) {
138  if (conn != myCurrentConn) {
139  NBEdge* otherConnFrom = conn->getEdgeFrom()->getNBEdge();
140  NBEdge* otherConnTo = conn->getEdgeTo()->getNBEdge();
141 
142  // determine the prohibition status
143  bool foes = node->foes(currentConnFrom, currentConnTo, otherConnFrom, otherConnTo);
144  bool forbids = node->forbids(currentConnFrom, currentConnTo, otherConnFrom, otherConnTo, true);
145  bool forbidden = node->forbids(otherConnFrom, otherConnTo, currentConnFrom, currentConnTo, true);
146 
147  myConcernedConns.insert(conn);
148 
149  if (!foes) {
151  } else {
152  if (forbids && forbidden) {
154  } else if (forbids) {
156  } else if (forbidden) {
158  } else {
160  }
161  }
162  }
163  }
164 
166  }
167 }
168 
169 void
171  GNEFrame::show();
172 }
173 
174 void
176  GNEFrame::hide();
177 }
178 
179 void
181  if (myCurrentConn == 0) {
182  myConnDescriptionLabel->setText("No Connection selected\n");
183  } else {
184  myConnDescriptionLabel->setText(("from lane " + myCurrentConn->getLaneFrom()->getMicrosimID() + "\nto lane " + myCurrentConn->getLaneTo()->getMicrosimID()).c_str());
185  }
186 }
187 
188 long
189 GNEProhibitionFrame::onCmdCancel(FXObject*, FXSelector, void*) {
190  if (myCurrentConn != 0) {
191  for (auto conn : myConcernedConns) {
192  conn->setSpecialColor(0);
193  }
195  myCurrentConn = 0;
196  myConcernedConns.clear();
198  myViewNet->update();
199  }
200  return 1;
201 }
202 
203 long
204 GNEProhibitionFrame::onCmdOK(FXObject*, FXSelector, void*) {
205  return 1;
206 }
207 
208 
209 /****************************************************************************/
std::vector< GNEConnection * > getGNEConnections() const
Returns all GNEConnections vinculated with this junction.
void show()
show prohibition frame
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
Definition: NBNode.cpp:1608
FXLabel * getFrameHeaderLabel() const
get the label for the frame&#39;s header
Definition: GNEFrame.cpp:772
static const RGBColor WHITE
Definition: RGBColor.h:179
FXDEFMAP(GNEProhibitionFrame) GNEProhibitionFrameMap[]
The representation of a single edge during network building.
Definition: NBEdge.h:65
FXGroupBox * myGroupBoxDescription
Groupbox for description.
static const RGBColor ORANGE
Definition: RGBColor.h:178
static RGBColor undefinedColor
color for non-conflicting pairs of connections
static RGBColor mutualConflictColor
color for mutual conflicts
static RGBColor unregulatedConflictColor
color for unregulated conflicts
void setSpecialColor(const RGBColor *Color2)
GNEEdge * getEdgeTo() const
get the name of the edge the vehicles may reach when leaving "from"
GNELane * getLaneFrom() const
get lane of the incoming lane
GNEViewNet * myViewNet
View Net for changes.
Definition: GNEFrame.h:232
void updateDescription() const
update description
std::set< GNEConnection * > myConcernedConns
the set of connections which
FXLabel * myProhibitingLabel
"prohibiting" label
static const RGBColor GREY
Definition: RGBColor.h:181
FXGroupBox * myGroupBoxLegend
group box for legend
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:235
static RGBColor prohibitingColor
color for connections with precedence
void handleConnectionClick(GNEConnection *conn, bool mayDefinitelyPass, bool allowConflict, bool toggle)
handle prohibitions and set teh relative colouring
GNELane * getLaneTo() const
get lane of the outgoing lane
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
GNEConnection * myCurrentConn
"OK" button
GNEJunction * getGNEJunctionDestiny() const
returns the destination-junction
Definition: GNEEdge.cpp:453
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
FXLabel * myConnDescriptionLabel
the label that shows the currently selected connection
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:184
GNEProhibitionFrame()
FOX needs this.
FXButton * myCancelButton
"Cancel" button
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button discards any prohibition modifications.
FXLabel * mySelectedLabel
selected connection label
FXLabel * myUndefinedLabel
"undefined" yielding label
long onCmdOK(FXObject *, FXSelector, void *)
#define GUIDesignButton
Definition: GUIDesigns.h:54
static const RGBColor RED
named colors
Definition: RGBColor.h:172
~GNEProhibitionFrame()
Destructor.
virtual void show()
show Frame
Definition: GNEFrame.cpp:741
static const RGBColor CYAN
Definition: RGBColor.h:176
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:227
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBNode.cpp:1598
static const RGBColor selectedConnectionColor
color of selected connection
Definition: GNENet.h:102
Ok-button pressed.
Definition: GUIAppEnum.h:56
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:750
static RGBColor selectedColor
color for selected connection whose prohibition shall be shown
Cancel-button pressed.
Definition: GUIAppEnum.h:58
static RGBColor prohibitedColor
color for waiting connections
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:114
Represents a single node (junction) during network building.
Definition: NBNode.h:68
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:586
NBNode * getNBNode() const
Return net build node.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
FXLabel * myProhibitedLabel
"prohibited" label
void hide()
hide prohibition frame