Eclipse 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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // The Widget for editing connection prohibits
19 /****************************************************************************/
20 #include <config.h>
21 
28 #include <netedit/GNEViewNet.h>
29 
30 #include "GNEProhibitionFrame.h"
31 
32 // ===========================================================================
33 // FOX callback mapping
34 // ===========================================================================
35 
36 FXDEFMAP(GNEProhibitionFrame) GNEProhibitionFrameMap[] = {
37  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNEProhibitionFrame::onCmdCancel),
38  FXMAPFUNC(SEL_COMMAND, MID_OK, GNEProhibitionFrame::onCmdOK)
39 };
40 
41 // Object implementation
42 FXIMPLEMENT(GNEProhibitionFrame, FXVerticalFrame, GNEProhibitionFrameMap, ARRAYNUMBER(GNEProhibitionFrameMap))
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 
48 // ---------------------------------------------------------------------------
49 // GNEProhibitionFrame::RelativeToConnection - methods
50 // ---------------------------------------------------------------------------
51 
53  FXGroupBox(prohibitionFrameParent->myContentFrame, "Relative to connection", GUIDesignGroupBoxFrame),
54  myProhibitionFrameParent(prohibitionFrameParent) {
55  // Create label for current connection description and update it
56  myConnDescriptionLabel = new FXLabel(this, "", nullptr, GUIDesignLabelFrameInformation);
57  // update description
58  updateDescription();
59 }
60 
61 
63 
64 
65 void
67  // update depending of myCurrentConn
68  if (myProhibitionFrameParent->myCurrentConn == nullptr) {
69  myConnDescriptionLabel->setText("No Connection selected\n");
70  } else {
71  myConnDescriptionLabel->setText(("from lane " + myProhibitionFrameParent->myCurrentConn->getLaneFrom()->getMicrosimID() +
72  "\nto lane " + myProhibitionFrameParent->myCurrentConn->getLaneTo()->getMicrosimID()).c_str());
73  }
74 }
75 
76 // ---------------------------------------------------------------------------
77 // GNEProhibitionFrame::ProhibitionLegend - methods
78 // ---------------------------------------------------------------------------
79 
81  FXGroupBox(prohibitionFrameParent->myContentFrame, "Legend", GUIDesignGroupBoxFrame),
82  myUndefinedColor(RGBColor::GREY),
83  myProhibitedColor(RGBColor(0, 179, 0)),
84  myProhibitingColor(RGBColor::RED),
85  myUnregulatedConflictColor(RGBColor::ORANGE),
86  myMutualConflictColor(RGBColor::CYAN) {
87  // Create labels for color legend
88  FXLabel* legendLabel = new FXLabel(this, "Selected", nullptr, GUIDesignLabelFrameInformation);
89  legendLabel->setTextColor(MFXUtils::getFXColor(RGBColor::WHITE));
90  legendLabel->setBackColor(MFXUtils::getFXColor(prohibitionFrameParent->myViewNet->getVisualisationSettings().colorSettings.selectedProhibitionColor));
91  // label for conflicts
92  legendLabel = new FXLabel(this, "No conflict", nullptr, GUIDesignLabelFrameInformation);
93  legendLabel->setBackColor(MFXUtils::getFXColor(myUndefinedColor));
94  // label for yields
95  legendLabel = new FXLabel(this, "Yields", nullptr, GUIDesignLabelFrameInformation);
96  legendLabel->setBackColor(MFXUtils::getFXColor(myProhibitedColor));
97  // label for right of way
98  legendLabel = new FXLabel(this, "Has right of way", nullptr, GUIDesignLabelFrameInformation);
99  legendLabel->setBackColor(MFXUtils::getFXColor(myProhibitingColor));
100  // label for unregulated conflict
101  legendLabel = new FXLabel(this, "Unregulated conflict", nullptr, GUIDesignLabelFrameInformation);
102  legendLabel->setBackColor(MFXUtils::getFXColor(myUnregulatedConflictColor));
103  // label for mutual conflict
104  legendLabel = new FXLabel(this, "Mutual conflict", nullptr, GUIDesignLabelFrameInformation);
105  legendLabel->setBackColor(MFXUtils::getFXColor(myMutualConflictColor));
106 }
107 
108 
110 
111 
112 const RGBColor&
114  return myUndefinedColor;
115 }
116 
117 
118 const RGBColor&
120  return myProhibitedColor;
121 }
122 
123 
124 const RGBColor&
126  return myProhibitingColor;
127 }
128 
129 
130 const RGBColor&
132  return myUnregulatedConflictColor;
133 }
134 
135 
136 const RGBColor&
138  return myMutualConflictColor;
139 }
140 
141 // ---------------------------------------------------------------------------
142 // GNEProhibitionFrame::Modifications - methods
143 // ---------------------------------------------------------------------------
144 
146  FXGroupBox(prohibitionFrameParent->myContentFrame, "Modifications", GUIDesignGroupBoxFrame) {
147 
148  // Create "OK" button
149  mySaveButton = new FXButton(this, "OK\t\tSave prohibition modifications (Enter)",
150  GUIIconSubSys::getIcon(GUIIcon::ACCEPT), prohibitionFrameParent, MID_OK, GUIDesignButton);
151 
152  // Create "Cancel" button
153  myCancelButton = new FXButton(this, "Cancel\t\tDiscard prohibition modifications (Esc)",
155 
156  // Currently mySaveButton is disabled
157  mySaveButton->disable();
158  mySaveButton->hide();
159 }
160 
161 
163 
164 // ---------------------------------------------------------------------------
165 // GNEProhibitionFrame - methods
166 // ---------------------------------------------------------------------------
167 
168 GNEProhibitionFrame::GNEProhibitionFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
169  GNEFrame(horizontalFrameParent, viewNet, "Prohibits"),
170  myCurrentConn(nullptr) {
171  // set frame header label
172  getFrameHeaderLabel()->setText("Prohibitions");
173 
174  // create RelativeToConnection
176 
177  // create ProhibitionLegend
179 
180  // create Modifications
181  myModifications = new Modifications(this);
182 }
183 
184 
186 
187 
188 void
190  // build prohibition
192 }
193 
194 
195 void
197  GNEFrame::show();
198 }
199 
200 
201 void
203  GNEFrame::hide();
204 }
205 
206 
207 long
208 GNEProhibitionFrame::onCmdCancel(FXObject*, FXSelector, void*) {
209  if (myCurrentConn != nullptr) {
210  for (auto conn : myConcernedConns) {
211  conn->setSpecialColor(nullptr);
212  }
213  myCurrentConn->setSpecialColor(nullptr);
214  myCurrentConn = nullptr;
215  myConcernedConns.clear();
218  }
219  return 1;
220 }
221 
222 
223 long
224 GNEProhibitionFrame::onCmdOK(FXObject*, FXSelector, void*) {
225  return 1;
226 }
227 
228 // ---------------------------------------------------------------------------
229 // GNEProhibitionFrame - private methods
230 // ---------------------------------------------------------------------------
231 
232 void
233 GNEProhibitionFrame::buildProhibition(GNEConnection* conn, bool /* mayDefinitelyPass */, bool /* allowConflict */, bool /* toggle */) {
234  if (myCurrentConn == nullptr) {
235  myCurrentConn = conn;
237 
238  // determine prohibition status of all other connections with respect to the selected one
239  GNEJunction* junction = myCurrentConn->getEdgeFrom()->getParentJunctions().back();
240  std::vector<GNEConnection*> allConns = junction->getGNEConnections();
241  NBNode* node = junction->getNBNode();
242  NBEdge* currentConnFrom = myCurrentConn->getEdgeFrom()->getNBEdge();
243 
244  const int currentLinkIndex = node->getConnectionIndex(currentConnFrom, myCurrentConn->getNBEdgeConnection());
245  std::string currentFoesString = node->getFoes(currentLinkIndex);
246  std::string currentResponseString = node->getResponse(currentLinkIndex);
247  std::reverse(currentFoesString.begin(), currentFoesString.end());
248  std::reverse(currentResponseString.begin(), currentResponseString.end());
249  // iterate over all connections
250  for (const auto& i : allConns) {
251  if (i != myCurrentConn) {
252  NBEdge* otherConnFrom = i->getEdgeFrom()->getNBEdge();
253  const int linkIndex = node->getConnectionIndex(otherConnFrom, i->getNBEdgeConnection());
254  std::string responseString = node->getResponse(linkIndex);
255  std::reverse(responseString.begin(), responseString.end());
256  // determine the prohibition status
257  bool foes = ((int)currentFoesString.size() > linkIndex) && (currentFoesString[linkIndex] == '1');
258  bool forbids = ((int)responseString.size() > currentLinkIndex) && (responseString[currentLinkIndex] == '1');
259  bool forbidden = ((int)currentResponseString.size() > linkIndex) && (currentResponseString[linkIndex] == '1');
260  // insert in myConcernedConns
261  myConcernedConns.insert(i);
262  // change color depending of prohibition status
263  if (!foes) {
264  i->setSpecialColor(&myProhibitionLegend->getUndefinedColor());
265  } else {
266  if (forbids && forbidden) {
267  i->setSpecialColor(&myProhibitionLegend->getMutualConflictColor());
268  } else if (forbids) {
269  i->setSpecialColor(&myProhibitionLegend->getProhibitedColor());
270  } else if (forbidden) {
271  i->setSpecialColor(&myProhibitionLegend->getProhibitingColor());
272  } else {
273  i->setSpecialColor(&myProhibitionLegend->getUnregulatedConflictColor());
274  }
275  }
276  }
277  }
278  // update description
280  }
281 }
282 
283 
284 /****************************************************************************/
FXDEFMAP(GNEProhibitionFrame) GNEProhibitionFrameMap[]
@ MID_CANCEL
Cancel-button pressed.
Definition: GUIAppEnum.h:247
@ MID_OK
Ok-button pressed.
Definition: GUIAppEnum.h:245
#define GUIDesignButton
Definition: GUIDesigns.h:62
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:278
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:223
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
void setSpecialColor(const RGBColor *Color2)
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:399
FXLabel * getFrameHeaderLabel() const
get the label for the frame's header
Definition: GNEFrame.cpp:139
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:113
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:116
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
const std::vector< GNEJunction * > & getParentJunctions() const
get parent junctions
std::vector< GNEConnection * > getGNEConnections() const
Returns all GNEConnections vinculated with this junction.
NBNode * getNBNode() const
Return net build node.
Modifications(GNEProhibitionFrame *prohibitionFrameParent)
constructor
FXButton * myCancelButton
"Cancel" button
const RGBColor & getUndefinedColor() const
get color for non-conflicting pairs of connections
RGBColor myUndefinedColor
color for non-conflicting pairs of connections
const RGBColor & getMutualConflictColor() const
get color for mutual conflicts
const RGBColor & getProhibitedColor() const
get color for waiting connections
RGBColor myProhibitingColor
color for connections with precedence
RGBColor myProhibitedColor
color for waiting connections
RGBColor myUnregulatedConflictColor
color for unregulated conflicts
const RGBColor & getUnregulatedConflictColor() const
get color for unregulated conflicts
RGBColor myMutualConflictColor
color for mutual conflicts
const RGBColor & getProhibitingColor() const
get color for connections with precedence
ProhibitionLegend(GNEProhibitionFrame *prohibitionFrameParent)
constructor
void updateDescription() const
update description
RelativeToConnection * myRelativeToConnection
Relative To Connection.
void hide()
hide prohibition frame
long onCmdOK(FXObject *, FXSelector, void *)
GNEProhibitionFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
void handleProhibitionClick(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor)
handle prohibitions and set the relative colouring
GNEConnection * myCurrentConn
the connection which prohibits
ProhibitionLegend * myProhibitionLegend
prohibition legend
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button discards any prohibition modifications.
Modifications * myModifications
Modifications.
void show()
show prohibition frame
void buildProhibition(GNEConnection *conn, bool mayDefinitelyPass, bool allowConflict, bool toggle)
build prohibition
std::set< GNEConnection * > myConcernedConns
the set of connections which
class used to group all variables related with objects under cursor after a click over view
GNEConnection * getConnectionFront() const
get front connection or a pointer to nullptr
const GNEViewNetHelper::MouseButtonKeyPressed & getMouseButtonKeyPressed() const
get Key Pressed modul
Definition: GNEViewNet.cpp:497
void updateViewNet() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:318
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
GUIVisualizationColorSettings colorSettings
color settings
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:112
The representation of a single edge during network building.
Definition: NBEdge.h:91
Represents a single node (junction) during network building.
Definition: NBNode.h:66
int getConnectionIndex(const NBEdge *from, const NBEdge::Connection &con) const
return the index of the given connection
Definition: NBNode.cpp:3329
const std::string getResponse(int linkIndex) const
get the 'response' string (right-of-way bit set) of the right-of-way logic
Definition: NBNode.cpp:1013
const std::string getFoes(int linkIndex) const
get the 'foes' string (conflict bit set) of the right-of-way logic
Definition: NBNode.cpp:1003
static const RGBColor WHITE
Definition: RGBColor.h:187
bool shiftKeyPressed() const
check if SHIFT is pressed during current event
bool controlKeyPressed() const
check if CONTROL is pressed during current event
RGBColor selectedProhibitionColor
prohibition selection color