Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEProhibitionFrame.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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
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 (TL("- Junction: ") + myProhibitionFrameParent->myCurrentConn->getEdgeFrom()->getToJunction()->getID() + "\n" +
75 TL("- From lane: ") + myProhibitionFrameParent->myCurrentConn->getLaneFrom()->getMicrosimID() + "\n" +
76 TL("- 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 TL("Selected"), nullptr, GUIDesignLabelFrameInformation);
95 legendLabel->setTipText(TL("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 TL("No conflict"), nullptr, GUIDesignLabelFrameInformation);
102 legendLabel->setTipText(TL("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 TL("Yields"), nullptr, GUIDesignLabelFrameInformation);
108 legendLabel->setTipText(TL("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 TL("Has right of way"), nullptr, GUIDesignLabelFrameInformation);
114 legendLabel->setTipText(TL("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 TL("Unregulated conflict"), nullptr, GUIDesignLabelFrameInformation);
120 legendLabel->setTipText(TL("Connection has an 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 TL("Mutual conflict"), nullptr, GUIDesignLabelFrameInformation);
126 legendLabel->setTipText(TL("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(TL("Save prohibition modifications (Enter)"));
176 // Create "Cancel" button
178 prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
179 TL("Unselect connection"),
181 myCancelButton->setTipText(TL("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, TL("Prohibitions")),
230 myCurrentConn(nullptr) {
231
232 // create RelativeToConnection
234
235 // create legend
236 myLegend = new Legend(this);
237
238 // create Selection module
239 mySelectionModul = new Selection(this);
240}
241
242
244
245
246void
251
252
253void
257
258
259void
263
264
269
270// ---------------------------------------------------------------------------
271// GNEProhibitionFrame - private methods
272// ---------------------------------------------------------------------------
273
274void
275GNEProhibitionFrame::buildProhibition(GNEConnection* conn, bool /* mayDefinitelyPass */, bool /* allowConflict */, bool /* toggle */) {
276 if (myCurrentConn != nullptr) {
277 mySelectionModul->onCmdCancel(nullptr, 0, nullptr);
278 }
279 if (conn != nullptr) {
280 myCurrentConn = conn;
282
283 // determine prohibition status of all other connections with respect to the selected one
285 std::vector<GNEConnection*> connections = junction->getGNEConnections();
286 NBNode* node = junction->getNBNode();
287 NBEdge* currentConnFrom = myCurrentConn->getEdgeFrom()->getNBEdge();
288
289 const int currentLinkIndex = node->getConnectionIndex(currentConnFrom, myCurrentConn->getNBEdgeConnection());
290 std::string currentFoesString = node->getFoes(currentLinkIndex);
291 std::string currentResponseString = node->getResponse(currentLinkIndex);
292 std::reverse(currentFoesString.begin(), currentFoesString.end());
293 std::reverse(currentResponseString.begin(), currentResponseString.end());
294 // iterate over all connections
295 for (const auto& connection : connections) {
296 if (connection != myCurrentConn) {
297 NBEdge* otherConnFrom = connection->getEdgeFrom()->getNBEdge();
298 const int linkIndex = node->getConnectionIndex(otherConnFrom, connection->getNBEdgeConnection());
299 std::string responseString = node->getResponse(linkIndex);
300 std::reverse(responseString.begin(), responseString.end());
301 // determine the prohibition status
302 bool foes = ((int)currentFoesString.size() > linkIndex) && (currentFoesString[linkIndex] == '1');
303 bool forbids = ((int)responseString.size() > currentLinkIndex) && (responseString[currentLinkIndex] == '1');
304 bool forbidden = ((int)currentResponseString.size() > linkIndex) && (currentResponseString[linkIndex] == '1');
305 // insert in myConcernedConns
306 myConcernedConns.insert(connection);
307 // change color depending of prohibition status
308 if (!foes) {
309 connection->setSpecialColor(&myLegend->getUndefinedColor());
310 } else {
311 if (forbids && forbidden) {
312 connection->setSpecialColor(&myLegend->getMutualConflictColor());
313 } else if (forbids) {
314 connection->setSpecialColor(&myLegend->getProhibitedColor());
315 } else if (forbidden) {
316 connection->setSpecialColor(&myLegend->getProhibitingColor());
317 } else {
318 connection->setSpecialColor(&myLegend->getUnregulatedConflictColor());
319 }
320 }
321 }
322 }
323 // update description
325 }
326}
327
328
329/****************************************************************************/
FXDEFMAP(GNEProhibitionFrame::Selection) SelectionMap[]
@ MID_CANCEL
Cancel-button pressed.
Definition GUIAppEnum.h:308
@ MID_OK
Ok-button pressed.
Definition GUIAppEnum.h:306
#define GUIDesignButton
Definition GUIDesigns.h:88
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:285
#define TL(string)
Definition MsgHandler.h:315
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:781
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
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 onCmdRequireConnection(FXObject *, FXSelector, void *)
Called when the user presses the OK-Button saves any prohibition modifications.
GNEProhibitionFrame::Selection * mySelectionModul
Selection.
GNEProhibitionFrame::Legend * myLegend
prohibition legend
void handleProhibitionClick(const GNEViewNetHelper::ViewObjectsSelector &viewObjects)
handle prohibitions and set the relative coloring
RelativeToConnection * myRelativeToConnection
Relative To Connection.
void hide()
hide prohibition frame
GNEProhibitionFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
GNEConnection * myCurrentConn
the connection which prohibits
GNEProhibitionFrame::Selection * getSelectionModul() const
get selection module
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
GNEViewParent * getViewParent() const
get the net object
A single child window which contains a view of the simulation area.
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:3951
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:1108
const std::string getFoes(int linkIndex) const
get the 'foes' string (conflict bit set) of the right-of-way logic
Definition NBNode.cpp:1098
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