Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/network/GNEProhibitionFrame.cpp
169685 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file GNEProhibitionFrame.cpp
15
/// @author Mirko Barthauer (Technische Universitaet Braunschweig)
16
/// @date May 2018
17
///
18
// The Widget for editing connection prohibits
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNEViewNet.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/elements/network/GNEConnection.h>
25
#include <netedit/elements/network/GNEEdge.h>
26
#include <netedit/elements/network/GNEJunction.h>
27
#include <netedit/elements/network/GNELane.h>
28
#include <utils/foxtools/MFXLabelTooltip.h>
29
#include <utils/gui/div/GUIDesigns.h>
30
31
#include "GNEProhibitionFrame.h"
32
33
// ===========================================================================
34
// FOX callback mapping
35
// ===========================================================================
36
37
FXDEFMAP(GNEProhibitionFrame::Selection) SelectionMap[] = {
38
FXMAPFUNC(SEL_COMMAND, MID_OK, GNEProhibitionFrame::Selection::onCmdOK),
39
FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNEProhibitionFrame::Selection::onCmdCancel),
40
FXMAPFUNC(SEL_UPDATE, MID_CANCEL, GNEProhibitionFrame::Selection::onCmdRequireConnection),
41
};
42
43
// Object implementation
44
FXIMPLEMENT(GNEProhibitionFrame::Selection, FXVerticalFrame, SelectionMap, ARRAYNUMBER(SelectionMap))
45
46
// ===========================================================================
47
// method definitions
48
// ===========================================================================
49
50
// ---------------------------------------------------------------------------
51
// GNEProhibitionFrame::RelativeToConnection - methods
52
// ---------------------------------------------------------------------------
53
54
GNEProhibitionFrame::RelativeToConnection::RelativeToConnection(GNEProhibitionFrame* prohibitionFrameParent) :
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
64
GNEProhibitionFrame::RelativeToConnection::~RelativeToConnection() {}
65
66
67
void
68
GNEProhibitionFrame::RelativeToConnection::updateDescription() const {
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
84
GNEProhibitionFrame::Legend::Legend(GNEProhibitionFrame* prohibitionFrameParent) :
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
92
MFXLabelTooltip* legendLabel = new MFXLabelTooltip(getCollapsableFrame(),
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
131
GNEProhibitionFrame::Legend::~Legend() {}
132
133
134
const RGBColor&
135
GNEProhibitionFrame::Legend::getUndefinedColor() const {
136
return myUndefinedColor;
137
}
138
139
140
const RGBColor&
141
GNEProhibitionFrame::Legend::getProhibitedColor() const {
142
return myProhibitedColor;
143
}
144
145
146
const RGBColor&
147
GNEProhibitionFrame::Legend::getProhibitingColor() const {
148
return myProhibitingColor;
149
}
150
151
152
const RGBColor&
153
GNEProhibitionFrame::Legend::getUnregulatedConflictColor() const {
154
return myUnregulatedConflictColor;
155
}
156
157
158
const RGBColor&
159
GNEProhibitionFrame::Legend::getMutualConflictColor() const {
160
return myMutualConflictColor;
161
}
162
163
// ---------------------------------------------------------------------------
164
// GNEProhibitionFrame::Selection - methods
165
// ---------------------------------------------------------------------------
166
167
GNEProhibitionFrame::Selection::Selection(GNEProhibitionFrame* prohibitionFrameParent) :
168
MFXGroupBoxModule(prohibitionFrameParent, TL("Selection")),
169
myProhibitionFrameParent(prohibitionFrameParent) {
170
// Create "OK" button
171
mySaveButton = new MFXButtonTooltip(getCollapsableFrame(),
172
prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
173
TL("OK"),
174
GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_OK, GUIDesignButton);
175
mySaveButton->setTipText(TL("Save prohibition modifications (Enter)"));
176
// Create "Cancel" button
177
myCancelButton = new MFXButtonTooltip(getCollapsableFrame(),
178
prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
179
TL("Unselect connection"),
180
GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_CANCEL, GUIDesignButton);
181
myCancelButton->setTipText(TL("Unselect connection (Esc)"));
182
// Currently mySaveButton is hidden
183
mySaveButton->hide();
184
}
185
186
187
GNEProhibitionFrame::Selection::~Selection() {}
188
189
190
long
191
GNEProhibitionFrame::Selection::onCmdOK(FXObject*, FXSelector, void*) {
192
return 1;
193
}
194
195
196
long
197
GNEProhibitionFrame::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
212
long
213
GNEProhibitionFrame::Selection::onCmdRequireConnection(FXObject*, FXSelector, void*) {
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
228
GNEProhibitionFrame::GNEProhibitionFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :
229
GNEFrame(viewParent, viewNet, TL("Prohibitions")),
230
myCurrentConn(nullptr) {
231
232
// create RelativeToConnection
233
myRelativeToConnection = new RelativeToConnection(this);
234
235
// create legend
236
myLegend = new Legend(this);
237
238
// create Selection module
239
mySelectionModul = new Selection(this);
240
}
241
242
243
GNEProhibitionFrame::~GNEProhibitionFrame() {}
244
245
246
void
247
GNEProhibitionFrame::handleProhibitionClick(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {
248
// build prohibition
249
buildProhibition(viewObjects.getConnectionFront(), myViewNet->getMouseButtonKeyPressed().shiftKeyPressed(), myViewNet->getMouseButtonKeyPressed().controlKeyPressed(), true);
250
}
251
252
253
void
254
GNEProhibitionFrame::show() {
255
GNEFrame::show();
256
}
257
258
259
void
260
GNEProhibitionFrame::hide() {
261
GNEFrame::hide();
262
}
263
264
265
GNEProhibitionFrame::Selection*
266
GNEProhibitionFrame::getSelectionModul() const {
267
return mySelectionModul;
268
}
269
270
// ---------------------------------------------------------------------------
271
// GNEProhibitionFrame - private methods
272
// ---------------------------------------------------------------------------
273
274
void
275
GNEProhibitionFrame::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;
281
myCurrentConn->setSpecialColor(&myViewNet->getVisualisationSettings().colorSettings.selectedProhibitionColor);
282
283
// determine prohibition status of all other connections with respect to the selected one
284
GNEJunction* junction = myCurrentConn->getEdgeFrom()->getToJunction();
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
324
myRelativeToConnection->updateDescription();
325
}
326
}
327
328
329
/****************************************************************************/
330
331