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-2019 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 /****************************************************************************/
14 // The Widget for editing connection prohibits
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
29 #include <netedit/GNEViewNet.h>
30 
31 #include "GNEProhibitionFrame.h"
32 
33 // ===========================================================================
34 // FOX callback mapping
35 // ===========================================================================
36 
37 FXDEFMAP(GNEProhibitionFrame) GNEProhibitionFrameMap[] = {
38  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNEProhibitionFrame::onCmdCancel),
39  FXMAPFUNC(SEL_COMMAND, MID_OK, GNEProhibitionFrame::onCmdOK)
40 };
41 
42 // Object implementation
43 FXIMPLEMENT(GNEProhibitionFrame, FXVerticalFrame, GNEProhibitionFrameMap, ARRAYNUMBER(GNEProhibitionFrameMap))
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 
49 // ---------------------------------------------------------------------------
50 // GNEProhibitionFrame::RelativeToConnection - methods
51 // ---------------------------------------------------------------------------
52 
54  FXGroupBox(prohibitionFrameParent->myContentFrame, "Relative to connection", GUIDesignGroupBoxFrame),
55  myProhibitionFrameParent(prohibitionFrameParent) {
56  // Create label for current connection description and update it
57  myConnDescriptionLabel = new FXLabel(this, "", nullptr, GUIDesignLabelFrameInformation);
58  // update description
59  updateDescription();
60 }
61 
62 
64 
65 
66 void
68  // update depending of myCurrentConn
69  if (myProhibitionFrameParent->myCurrentConn == nullptr) {
70  myConnDescriptionLabel->setText("No Connection selected\n");
71  } else {
72  myConnDescriptionLabel->setText(("from lane " + myProhibitionFrameParent->myCurrentConn->getLaneFrom()->getMicrosimID() +
73  "\nto lane " + myProhibitionFrameParent->myCurrentConn->getLaneTo()->getMicrosimID()).c_str());
74  }
75 }
76 
77 // ---------------------------------------------------------------------------
78 // GNEProhibitionFrame::ProhibitionLegend - methods
79 // ---------------------------------------------------------------------------
80 
82  FXGroupBox(prohibitionFrameParent->myContentFrame, "Legend", GUIDesignGroupBoxFrame),
83  myUndefinedColor(RGBColor::GREY),
84  myProhibitedColor(RGBColor(0, 179, 0)),
85  myProhibitingColor(RGBColor::RED),
86  myUnregulatedConflictColor(RGBColor::ORANGE),
87  myMutualConflictColor(RGBColor::CYAN) {
88  // Create labels for color legend
89  FXLabel* legendLabel = new FXLabel(this, "Selected", nullptr, GUIDesignLabelFrameInformation);
90  legendLabel->setTextColor(MFXUtils::getFXColor(RGBColor::WHITE));
91  legendLabel->setBackColor(MFXUtils::getFXColor(prohibitionFrameParent->myViewNet->getVisualisationSettings()->colorSettings.selectedProhibitionColor));
92  // label for conflicts
93  legendLabel = new FXLabel(this, "No conflict", nullptr, GUIDesignLabelFrameInformation);
94  legendLabel->setBackColor(MFXUtils::getFXColor(myUndefinedColor));
95  // label for yields
96  legendLabel = new FXLabel(this, "Yields", nullptr, GUIDesignLabelFrameInformation);
97  legendLabel->setBackColor(MFXUtils::getFXColor(myProhibitedColor));
98  // label for right of way
99  legendLabel = new FXLabel(this, "Has right of way", nullptr, GUIDesignLabelFrameInformation);
100  legendLabel->setBackColor(MFXUtils::getFXColor(myProhibitingColor));
101  // label for unregulated conflict
102  legendLabel = new FXLabel(this, "Unregulated conflict", nullptr, GUIDesignLabelFrameInformation);
103  legendLabel->setBackColor(MFXUtils::getFXColor(myUnregulatedConflictColor));
104  // label for mutual conflict
105  legendLabel = new FXLabel(this, "Mutual conflict", nullptr, GUIDesignLabelFrameInformation);
106  legendLabel->setBackColor(MFXUtils::getFXColor(myMutualConflictColor));
107 }
108 
109 
111 
112 
113 const RGBColor&
115  return myUndefinedColor;
116 }
117 
118 
119 const RGBColor&
121  return myProhibitedColor;
122 }
123 
124 
125 const RGBColor&
127  return myProhibitingColor;
128 }
129 
130 
131 const RGBColor&
133  return myUnregulatedConflictColor;
134 }
135 
136 
137 const RGBColor&
139  return myMutualConflictColor;
140 }
141 
142 // ---------------------------------------------------------------------------
143 // GNEProhibitionFrame::Modifications - methods
144 // ---------------------------------------------------------------------------
145 
147  FXGroupBox(prohibitionFrameParent->myContentFrame, "Modifications", GUIDesignGroupBoxFrame) {
148 
149  // Create "OK" button
150  mySaveButton = new FXButton(this, "OK\t\tSave prohibition modifications (Enter)",
151  GUIIconSubSys::getIcon(ICON_ACCEPT), prohibitionFrameParent, MID_OK, GUIDesignButton);
152 
153  // Create "Cancel" button
154  myCancelButton = new FXButton(this, "Cancel\t\tDiscard prohibition modifications (Esc)",
155  GUIIconSubSys::getIcon(ICON_CANCEL), prohibitionFrameParent, MID_CANCEL, GUIDesignButton);
156 
157  // Currently mySaveButton is disabled
158  mySaveButton->disable();
159  mySaveButton->hide();
160 }
161 
162 
164 
165 // ---------------------------------------------------------------------------
166 // GNEProhibitionFrame - methods
167 // ---------------------------------------------------------------------------
168 
169 GNEProhibitionFrame::GNEProhibitionFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
170  GNEFrame(horizontalFrameParent, viewNet, "Prohibits"),
171  myCurrentConn(nullptr) {
172  // set frame header label
173  getFrameHeaderLabel()->setText("Prohibitions");
174 
175  // create RelativeToConnection
177 
178  // create ProhibitionLegend
180 
181  // create Modifications
182  myModifications = new Modifications(this);
183 }
184 
185 
187 
188 
189 void
191  // build prohibition
193 }
194 
195 
196 void
198  GNEFrame::show();
199 }
200 
201 
202 void
204  GNEFrame::hide();
205 }
206 
207 
208 long
209 GNEProhibitionFrame::onCmdCancel(FXObject*, FXSelector, void*) {
210  if (myCurrentConn != nullptr) {
211  for (auto conn : myConcernedConns) {
212  conn->setSpecialColor(nullptr);
213  }
214  myCurrentConn->setSpecialColor(nullptr);
215  myCurrentConn = nullptr;
216  myConcernedConns.clear();
218  myViewNet->update();
219  }
220  return 1;
221 }
222 
223 
224 long
225 GNEProhibitionFrame::onCmdOK(FXObject*, FXSelector, void*) {
226  return 1;
227 }
228 
229 // ---------------------------------------------------------------------------
230 // GNEProhibitionFrame - private methods
231 // ---------------------------------------------------------------------------
232 
233 void
234 GNEProhibitionFrame::buildProhibition(GNEConnection* conn, bool /* mayDefinitelyPass */, bool /* allowConflict */, bool /* toggle */) {
235  if (myCurrentConn == nullptr) {
236  myCurrentConn = conn;
238 
239  // determine prohibition status of all other connections with respect to the selected one
241  std::vector<GNEConnection*> allConns = junction->getGNEConnections();
242  NBNode* node = junction->getNBNode();
243  NBEdge* currentConnFrom = myCurrentConn->getEdgeFrom()->getNBEdge();
244 
245  const int currentLinkIndex = node->getConnectionIndex(currentConnFrom, myCurrentConn->getNBEdgeConnection());
246  std::string currentFoesString = node->getFoes(currentLinkIndex);
247  std::string currentResponseString = node->getResponse(currentLinkIndex);
248  std::reverse(currentFoesString.begin(), currentFoesString.end());
249  std::reverse(currentResponseString.begin(), currentResponseString.end());
250  // iterate over all connections
251  for (const auto& i : allConns) {
252  if (i != myCurrentConn) {
253  NBEdge* otherConnFrom = i->getEdgeFrom()->getNBEdge();
254  const int linkIndex = node->getConnectionIndex(otherConnFrom, i->getNBEdgeConnection());
255  std::string responseString = node->getResponse(linkIndex);
256  std::reverse(responseString.begin(), responseString.end());
257  // determine the prohibition status
258  bool foes = ((int)currentFoesString.size() > linkIndex) && (currentFoesString[linkIndex] == '1');
259  bool forbids = ((int)responseString.size() > currentLinkIndex) && (responseString[currentLinkIndex] == '1');
260  bool forbidden = ((int)currentResponseString.size() > linkIndex) && (currentResponseString[linkIndex] == '1');
261  // insert in myConcernedConns
262  myConcernedConns.insert(i);
263  // change color depending of prohibition status
264  if (!foes) {
265  i->setSpecialColor(&myProhibitionLegend->getUndefinedColor());
266  } else {
267  if (forbids && forbidden) {
268  i->setSpecialColor(&myProhibitionLegend->getMutualConflictColor());
269  } else if (forbids) {
270  i->setSpecialColor(&myProhibitionLegend->getProhibitedColor());
271  } else if (forbidden) {
272  i->setSpecialColor(&myProhibitionLegend->getProhibitingColor());
273  } else {
274  i->setSpecialColor(&myProhibitionLegend->getUnregulatedConflictColor());
275  }
276  }
277  }
278  }
279  // update description
281  }
282 }
283 
284 /****************************************************************************/
NBNode::getResponse
const std::string getResponse(int linkIndex) const
Definition: NBNode.cpp:978
ICON_ACCEPT
Definition: GUIIcons.h:386
GNEProhibitionFrame::handleProhibitionClick
void handleProhibitionClick(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor)
handle prohibitions and set the relative colouring
Definition: GNEProhibitionFrame.cpp:190
GNEProhibitionFrame::ProhibitionLegend::getUndefinedColor
const RGBColor & getUndefinedColor() const
get color for non-conflicting pairs of connections
Definition: GNEProhibitionFrame.cpp:114
GNEViewNetHelper::KeyPressed::shiftKeyPressed
bool shiftKeyPressed() const
check if SHIFT key was pressed during click
Definition: GNEViewNetHelper.cpp:376
GNEProhibitionFrame
Definition: GNEProhibitionFrame.h:38
GNEProhibitionFrame::ProhibitionLegend::getMutualConflictColor
const RGBColor & getMutualConflictColor() const
get color for mutual conflicts
Definition: GNEProhibitionFrame.cpp:138
GNEProhibitionFrame::ProhibitionLegend::ProhibitionLegend
ProhibitionLegend(GNEProhibitionFrame *prohibitionFrameParent)
constructor
Definition: GNEProhibitionFrame.cpp:81
GNEViewNetHelper::KeyPressed::controlKeyPressed
bool controlKeyPressed() const
check if CONTROL key was pressed during click
Definition: GNEViewNetHelper.cpp:386
GNEProhibitionFrame::ProhibitionLegend::myProhibitingColor
RGBColor myProhibitingColor
color for connections with precedence
Definition: GNEProhibitionFrame.h:111
GNEJunction::getGNEConnections
std::vector< GNEConnection * > getGNEConnections() const
Returns all GNEConnections vinculated with this junction.
Definition: GNEJunction.cpp:499
GNEFrame
Definition: GNEFrame.h:34
GNEViewNet
Definition: GNEViewNet.h:42
GNEProhibitionFrame::Modifications::~Modifications
~Modifications()
destructor
Definition: GNEProhibitionFrame.cpp:163
GNEProhibitionFrame::Modifications::mySaveButton
FXButton * mySaveButton
"Save" button
Definition: GNEProhibitionFrame.h:135
GUIDesigns.h
MID_CANCEL
Cancel-button pressed.
Definition: GUIAppEnum.h:230
GNEViewNet::update
void update() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:299
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:609
GNEFrame::myContentFrame
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:124
GUIDesignButton
#define GUIDesignButton
Definition: GUIDesigns.h:50
GUIVisualizationColorSettings::selectedProhibitionColor
RGBColor selectedProhibitionColor
prohibition selection color
Definition: GUIVisualizationSettings.h:141
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
GUIAppEnum.h
GNEJunction.h
GUIDesignLabelFrameInformation
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:194
GNEProhibitionFrame::Modifications
Definition: GNEProhibitionFrame.h:124
GNEJunction::getNBNode
NBNode * getNBNode() const
Return net build node.
Definition: GNEJunction.cpp:398
RGBColor
Definition: RGBColor.h:39
GNEConnection::setSpecialColor
void setSpecialColor(const RGBColor *Color2)
Definition: GNEConnection.cpp:361
GNEProhibitionFrame.h
GNEProhibitionFrame::onCmdCancel
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button discards any prohibition modifications.
Definition: GNEProhibitionFrame.cpp:209
GNEProhibitionFrame::myCurrentConn
GNEConnection * myCurrentConn
the connection which prohibits
Definition: GNEProhibitionFrame.h:188
GNEProhibitionFrame::buildProhibition
void buildProhibition(GNEConnection *conn, bool mayDefinitelyPass, bool allowConflict, bool toggle)
build prohibition
Definition: GNEProhibitionFrame.cpp:234
GNEProhibitionFrame::ProhibitionLegend::~ProhibitionLegend
~ProhibitionLegend()
destructor
Definition: GNEProhibitionFrame.cpp:110
GUISUMOAbstractView::getVisualisationSettings
GUIVisualizationSettings * getVisualisationSettings() const
get visualitation settings
Definition: GUISUMOAbstractView.cpp:1395
GNEConnection::getEdgeFrom
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
Definition: GNEConnection.cpp:166
GNEEdge::getNBEdge
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:631
GNEViewNetHelper::ObjectsUnderCursor
class used to group all variables related with objects under cursor after a click over view
Definition: GNEViewNetHelper.h:148
GNEConnection::getNBEdgeConnection
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
Definition: GNEConnection.cpp:202
NBNode::getConnectionIndex
int getConnectionIndex(const NBEdge *from, const NBEdge::Connection &con) const
return the index of the given connection
Definition: NBNode.cpp:3155
GNEProhibitionFrame::ProhibitionLegend::myProhibitedColor
RGBColor myProhibitedColor
color for waiting connections
Definition: GNEProhibitionFrame.h:108
MID_OK
Ok-button pressed.
Definition: GUIAppEnum.h:228
GNEViewNet.h
GNEProhibitionFrame::RelativeToConnection::updateDescription
void updateDescription() const
update description
Definition: GNEProhibitionFrame.cpp:67
GNEProhibitionFrame::~GNEProhibitionFrame
~GNEProhibitionFrame()
Destructor.
Definition: GNEProhibitionFrame.cpp:186
GNEViewNet::getKeyPressed
const GNEViewNetHelper::KeyPressed & getKeyPressed() const
get Key Pressed modul
Definition: GNEViewNet.cpp:464
GNEEdge.h
GNEFrame::myViewNet
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:121
GUIDesignGroupBoxFrame
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:239
GNEProhibitionFrame::show
void show()
show prohibition frame
Definition: GNEProhibitionFrame.cpp:197
GNEViewNetHelper::ObjectsUnderCursor::getConnectionFront
GNEConnection * getConnectionFront() const
get front connection (or a pointer to nullptr if there isn't)
Definition: GNEViewNetHelper.cpp:298
GNEEdge::getGNEJunctionDestiny
GNEJunction * getGNEJunctionDestiny() const
returns the destination-junction
Definition: GNEEdge.cpp:493
GNELane.h
GNEProhibitionFrame::RelativeToConnection
Definition: GNEProhibitionFrame.h:55
GNEProhibitionFrame::RelativeToConnection::~RelativeToConnection
~RelativeToConnection()
destructor
Definition: GNEProhibitionFrame.cpp:63
GUIVisualizationSettings::colorSettings
GUIVisualizationColorSettings colorSettings
color settings
Definition: GUIVisualizationSettings.h:677
GNEProhibitionFrame::myConcernedConns
std::set< GNEConnection * > myConcernedConns
the set of connections which
Definition: GNEProhibitionFrame.h:191
GNEProhibitionFrame::Modifications::myCancelButton
FXButton * myCancelButton
"Cancel" button
Definition: GNEProhibitionFrame.h:138
GNEProhibitionFrame::GNEProhibitionFrame
GNEProhibitionFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
Definition: GNEProhibitionFrame.cpp:169
GNEProhibitionFrame::hide
void hide()
hide prohibition frame
Definition: GNEProhibitionFrame.cpp:203
FXDEFMAP
FXDEFMAP(GNEProhibitionFrame) GNEProhibitionFrameMap[]
ICON_CANCEL
Definition: GUIIcons.h:387
GNEProhibitionFrame::ProhibitionLegend::getUnregulatedConflictColor
const RGBColor & getUnregulatedConflictColor() const
get color for unregulated conflicts
Definition: GNEProhibitionFrame.cpp:132
GNEProhibitionFrame::ProhibitionLegend::myMutualConflictColor
RGBColor myMutualConflictColor
color for mutual conflicts
Definition: GNEProhibitionFrame.h:117
GNEProhibitionFrame::onCmdOK
long onCmdOK(FXObject *, FXSelector, void *)
Definition: GNEProhibitionFrame.cpp:225
GNEConnection
Definition: GNEConnection.h:38
config.h
GNEProhibitionFrame::ProhibitionLegend::myUnregulatedConflictColor
RGBColor myUnregulatedConflictColor
color for unregulated conflicts
Definition: GNEProhibitionFrame.h:114
MFXUtils::getFXColor
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:113
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
GNEJunction
Definition: GNEJunction.h:47
GNEProhibitionFrame::myRelativeToConnection
RelativeToConnection * myRelativeToConnection
Relative To Connection.
Definition: GNEProhibitionFrame.h:179
GNEProhibitionFrame::myModifications
Modifications * myModifications
Modifications.
Definition: GNEProhibitionFrame.h:185
GNEProhibitionFrame::ProhibitionLegend
Definition: GNEProhibitionFrame.h:79
GNEFrame::show
virtual void show()
show Frame
Definition: GNEFrame.cpp:107
GNEProhibitionFrame::Modifications::Modifications
Modifications(GNEProhibitionFrame *prohibitionFrameParent)
constructor
Definition: GNEProhibitionFrame.cpp:146
GNEProhibitionFrame::ProhibitionLegend::getProhibitedColor
const RGBColor & getProhibitedColor() const
get color for waiting connections
Definition: GNEProhibitionFrame.cpp:120
GNEProhibitionFrame::ProhibitionLegend::myUndefinedColor
RGBColor myUndefinedColor
color for non-conflicting pairs of connections
Definition: GNEProhibitionFrame.h:105
NBNode::getFoes
const std::string getFoes(int linkIndex) const
Definition: NBNode.cpp:968
GNEFrame::getFrameHeaderLabel
FXLabel * getFrameHeaderLabel() const
get the label for the frame's header
Definition: GNEFrame.cpp:138
GNEFrame::hide
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:116
GNEProhibitionFrame::myProhibitionLegend
ProhibitionLegend * myProhibitionLegend
prohibition legend
Definition: GNEProhibitionFrame.h:182
RGBColor::WHITE
static const RGBColor WHITE
Definition: RGBColor.h:196
GNEProhibitionFrame::ProhibitionLegend::getProhibitingColor
const RGBColor & getProhibitingColor() const
get color for connections with precedence
Definition: GNEProhibitionFrame.cpp:126
GNEConnection.h