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