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-2022 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
26#include <netedit/GNEViewNet.h>
29
30#include "GNEProhibitionFrame.h"
31
32
33// ===========================================================================
34// FOX callback mapping
35// ===========================================================================
36
38 FXMAPFUNC(SEL_COMMAND, MID_OK, GNEProhibitionFrame::Selection::onCmdOK),
41};
42
43// Object implementation
44FXIMPLEMENT(GNEProhibitionFrame::Selection, FXVerticalFrame, SelectionMap, ARRAYNUMBER(SelectionMap))
45
46// ===========================================================================
47// method definitions
48// ===========================================================================
49
50// ---------------------------------------------------------------------------
51// GNEProhibitionFrame::RelativeToConnection - methods
52// ---------------------------------------------------------------------------
53
55 MFXGroupBoxModule(prohibitionFrameParent, TL("Selected connection")),
56 myProhibitionFrameParent(prohibitionFrameParent) {
57 // Create label for current connection description and update it
58 myConnDescriptionLabel = new FXLabel(getCollapsableFrame(), "", nullptr, GUIDesignLabelFrameInformation);
59 // update description
60 updateDescription();
61}
62
63
65
66
67void
69 // update depending of myCurrentConn
70 if (myProhibitionFrameParent->myCurrentConn == nullptr) {
71 myConnDescriptionLabel->setText(TL("No Connection selected\n"));
72 } else {
73 myConnDescriptionLabel->setText(
74 ("- Junction: " + myProhibitionFrameParent->myCurrentConn->getEdgeFrom()->getToJunction()->getID() + "\n" +
75 "- From lane: " + myProhibitionFrameParent->myCurrentConn->getLaneFrom()->getMicrosimID() + "\n" +
76 "- To lane: " + myProhibitionFrameParent->myCurrentConn->getLaneTo()->getMicrosimID()).c_str());
77 }
78}
79
80// ---------------------------------------------------------------------------
81// GNEProhibitionFrame::ProhibitionLegend - methods
82// ---------------------------------------------------------------------------
83
85 MFXGroupBoxModule(prohibitionFrameParent, TL("Information")),
86 myUndefinedColor(RGBColor::GREY),
87 myProhibitedColor(RGBColor(0, 179, 0)),
88 myProhibitingColor(RGBColor::RED),
89 myUnregulatedConflictColor(RGBColor::ORANGE),
90 myMutualConflictColor(RGBColor::CYAN) {
91 // Create labels for color legend
93 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
94 "Selected", nullptr, GUIDesignLabelFrameInformation);
95 legendLabel->setTipText("Current selected connection");
96 legendLabel->setTextColor(MFXUtils::getFXColor(RGBColor::WHITE));
97 legendLabel->setBackColor(MFXUtils::getFXColor(prohibitionFrameParent->myViewNet->getVisualisationSettings().colorSettings.selectedProhibitionColor));
98 // label for conflicts
99 legendLabel = new MFXLabelTooltip(getCollapsableFrame(),
100 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
101 "No conflict", nullptr, GUIDesignLabelFrameInformation);
102 legendLabel->setTipText("No conflict with the selected connection");
103 legendLabel->setBackColor(MFXUtils::getFXColor(myUndefinedColor));
104 // label for yields
105 legendLabel = new MFXLabelTooltip(getCollapsableFrame(),
106 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
107 "Yields", nullptr, GUIDesignLabelFrameInformation);
108 legendLabel->setTipText("Connection yields the selected connection");
109 legendLabel->setBackColor(MFXUtils::getFXColor(myProhibitedColor));
110 // label for right of way
111 legendLabel = new MFXLabelTooltip(getCollapsableFrame(),
112 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
113 "Has right of way", nullptr, GUIDesignLabelFrameInformation);
114 legendLabel->setTipText("Connection has right of way with the selected connection");
115 legendLabel->setBackColor(MFXUtils::getFXColor(myProhibitingColor));
116 // label for unregulated conflict
117 legendLabel = new MFXLabelTooltip(getCollapsableFrame(),
118 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
119 "Unregulated conflict", nullptr, GUIDesignLabelFrameInformation);
120 legendLabel->setTipText("Connection has a unregulated conflict with the selected connection");
121 legendLabel->setBackColor(MFXUtils::getFXColor(myUnregulatedConflictColor));
122 // label for mutual conflict
123 legendLabel = new MFXLabelTooltip(getCollapsableFrame(),
124 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
125 "Mutual conflict", nullptr, GUIDesignLabelFrameInformation);
126 legendLabel->setTipText("Connection has a mutual conflict with the selected connection");
127 legendLabel->setBackColor(MFXUtils::getFXColor(myMutualConflictColor));
128}
129
130
132
133
134const RGBColor&
136 return myUndefinedColor;
137}
138
139
140const RGBColor&
142 return myProhibitedColor;
143}
144
145
146const RGBColor&
148 return myProhibitingColor;
149}
150
151
152const RGBColor&
154 return myUnregulatedConflictColor;
155}
156
157
158const RGBColor&
160 return myMutualConflictColor;
161}
162
163// ---------------------------------------------------------------------------
164// GNEProhibitionFrame::Selection - methods
165// ---------------------------------------------------------------------------
166
168 MFXGroupBoxModule(prohibitionFrameParent, TL("Selection")),
169 myProhibitionFrameParent(prohibitionFrameParent) {
170 // Create "OK" button
172 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
173 TL("OK"),
175 mySaveButton->setTipText("Save prohibition modifications (Enter)");
176 // Create "Cancel" button
178 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
179 TL("Unselect connection"),
181 myCancelButton->setTipText("Unselect connection (Esc)");
182 // Currently mySaveButton is hidden
183 mySaveButton->hide();
184}
185
186
188
189
190long
191GNEProhibitionFrame::Selection::onCmdOK(FXObject*, FXSelector, void*) {
192 return 1;
193}
194
195
196long
197GNEProhibitionFrame::Selection::onCmdCancel(FXObject*, FXSelector, void*) {
198 if (myProhibitionFrameParent->myCurrentConn != nullptr) {
199 for (const auto &conn : myProhibitionFrameParent->myConcernedConns) {
200 conn->setSpecialColor(nullptr);
201 }
202 myProhibitionFrameParent->myCurrentConn->setSpecialColor(nullptr);
203 myProhibitionFrameParent->myCurrentConn = nullptr;
204 myProhibitionFrameParent->myConcernedConns.clear();
205 myProhibitionFrameParent->myRelativeToConnection->updateDescription();
206 myProhibitionFrameParent->myViewNet->updateViewNet();
207 }
208 return 1;
209}
210
211
212long
214 if (myProhibitionFrameParent->myCurrentConn) {
215 mySaveButton->enable();
216 myCancelButton->enable();
217 } else {
218 mySaveButton->disable();
219 myCancelButton->disable();
220 }
221 return 1;
222}
223
224// ---------------------------------------------------------------------------
225// GNEProhibitionFrame - methods
226// ---------------------------------------------------------------------------
227
229 GNEFrame(viewParent, viewNet, "Prohibits"),
230 myCurrentConn(nullptr) {
231 // set frame header label
232 getFrameHeaderLabel()->setText(TL("Prohibitions"));
233
234 // create RelativeToConnection
236
237 // create legend
238 myLegend = new Legend(this);
239
240 // create Selection modul
241 mySelectionModul = new Selection(this);
242}
243
244
246
247
248void
250 // build prohibition
252}
253
254
255void
258}
259
260
261void
264}
265
266
269 return mySelectionModul;
270}
271
272// ---------------------------------------------------------------------------
273// GNEProhibitionFrame - private methods
274// ---------------------------------------------------------------------------
275
276void
277GNEProhibitionFrame::buildProhibition(GNEConnection* conn, bool /* mayDefinitelyPass */, bool /* allowConflict */, bool /* toggle */) {
278 if (myCurrentConn != nullptr) {
279 mySelectionModul->onCmdCancel(nullptr, 0, nullptr);
280 }
281 if (conn != nullptr){
282 myCurrentConn = conn;
284
285 // determine prohibition status of all other connections with respect to the selected one
287 std::vector<GNEConnection*> connections = junction->getGNEConnections();
288 NBNode* node = junction->getNBNode();
289 NBEdge* currentConnFrom = myCurrentConn->getEdgeFrom()->getNBEdge();
290
291 const int currentLinkIndex = node->getConnectionIndex(currentConnFrom, myCurrentConn->getNBEdgeConnection());
292 std::string currentFoesString = node->getFoes(currentLinkIndex);
293 std::string currentResponseString = node->getResponse(currentLinkIndex);
294 std::reverse(currentFoesString.begin(), currentFoesString.end());
295 std::reverse(currentResponseString.begin(), currentResponseString.end());
296 // iterate over all connections
297 for (const auto& connection : connections) {
298 if (connection != myCurrentConn) {
299 NBEdge* otherConnFrom = connection->getEdgeFrom()->getNBEdge();
300 const int linkIndex = node->getConnectionIndex(otherConnFrom, connection->getNBEdgeConnection());
301 std::string responseString = node->getResponse(linkIndex);
302 std::reverse(responseString.begin(), responseString.end());
303 // determine the prohibition status
304 bool foes = ((int)currentFoesString.size() > linkIndex) && (currentFoesString[linkIndex] == '1');
305 bool forbids = ((int)responseString.size() > currentLinkIndex) && (responseString[currentLinkIndex] == '1');
306 bool forbidden = ((int)currentResponseString.size() > linkIndex) && (currentResponseString[linkIndex] == '1');
307 // insert in myConcernedConns
308 myConcernedConns.insert(connection);
309 // change color depending of prohibition status
310 if (!foes) {
311 connection->setSpecialColor(&myLegend->getUndefinedColor());
312 } else {
313 if (forbids && forbidden) {
314 connection->setSpecialColor(&myLegend->getMutualConflictColor());
315 } else if (forbids) {
316 connection->setSpecialColor(&myLegend->getProhibitedColor());
317 } else if (forbidden) {
318 connection->setSpecialColor(&myLegend->getProhibitingColor());
319 } else {
320 connection->setSpecialColor(&myLegend->getUnregulatedConflictColor());
321 }
322 }
323 }
324 }
325 // update description
327 }
328}
329
330
331/****************************************************************************/
FXDEFMAP(GNEProhibitionFrame::Selection) SelectionMap[]
@ MID_CANCEL
Cancel-button pressed.
Definition: GUIAppEnum.h:261
@ MID_OK
Ok-button pressed.
Definition: GUIAppEnum.h:259
#define GUIDesignButton
Definition: GUIDesigns.h:77
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:271
#define TL(string)
Definition: MsgHandler.h:282
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:481
GNEJunction * getToJunction() const
get from Junction (only used to increase readability)
Definition: GNEEdge.h:82
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:150
FXLabel * getFrameHeaderLabel() const
get the label for the frame's header
Definition: GNEFrame.cpp:162
GNEViewNet * myViewNet
FOX need this.
Definition: GNEFrame.h:117
virtual void show()
show Frame
Definition: GNEFrame.cpp:115
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:124
std::vector< GNEConnection * > getGNEConnections() const
Returns all GNEConnections vinculated with this junction.
NBNode * getNBNode() const
Return net build node.
Legend(GNEProhibitionFrame *prohibitionFrameParent)
constructor
const RGBColor & getProhibitingColor() const
get color for connections with precedence
RGBColor myUndefinedColor
color for non-conflicting pairs of connections
const RGBColor & getProhibitedColor() const
get color for waiting connections
RGBColor myMutualConflictColor
color for mutual conflicts
const RGBColor & getUndefinedColor() const
get color for non-conflicting pairs of connections
RGBColor myProhibitedColor
color for waiting connections
RGBColor myUnregulatedConflictColor
color for unregulated conflicts
const RGBColor & getMutualConflictColor() const
get color for mutual conflicts
const RGBColor & getUnregulatedConflictColor() const
get color for unregulated conflicts
RGBColor myProhibitingColor
color for connections with precedence
void updateDescription() const
update description
MFXButtonTooltip * mySaveButton
"Save" button
MFXButtonTooltip * myCancelButton
"Cancel" button
long onCmdOK(FXObject *, FXSelector, void *)
Called when the user presses the OK-Button saves any prohibition modifications.
Selection(GNEProhibitionFrame *prohibitionFrameParent)
FOX-declaration.
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button discards any prohibition modifications.
long onCmdRequiereConnection(FXObject *, FXSelector, void *)
Called when the user presses the OK-Button saves any prohibition modifications.
GNEProhibitionFrame::Selection * mySelectionModul
Selection.
GNEProhibitionFrame::Legend * myLegend
prohibition legend
RelativeToConnection * myRelativeToConnection
Relative To Connection.
void hide()
hide prohibition frame
GNEProhibitionFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void handleProhibitionClick(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor)
handle prohibitions and set the relative colouring
GNEConnection * myCurrentConn
the connection which prohibits
GNEProhibitionFrame::Selection * getSelectionModul() const
get selection modul
void show()
show prohibition frame
void buildProhibition(GNEConnection *conn, bool mayDefinitelyPass, bool allowConflict, bool toggle)
FOX needs this.
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 module
Definition: GNEViewNet.cpp:662
GNEViewParent * getViewParent() const
get the net object
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:84
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXStaticToolTip * getStaticTooltipMenu() const
get static toolTip for menus
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
GUIVisualizationColorSettings colorSettings
color settings
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
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:92
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:3619
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:1049
const std::string getFoes(int linkIndex) const
get the 'foes' string (conflict bit set) of the right-of-way logic
Definition: NBNode.cpp:1039
static const RGBColor WHITE
Definition: RGBColor.h:192
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