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 {
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&
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 /****************************************************************************/
RGBColor myUnregulatedConflictColor
color for unregulated conflicts
int getConnectionIndex(const NBEdge *from, const NBEdge::Connection &con) const
return the index of the given connection
Definition: NBNode.cpp:3175
std::vector< GNEConnection * > getGNEConnections() const
Returns all GNEConnections vinculated with this junction.
void show()
show prohibition frame
Modifications * myModifications
Modifications.
ProhibitionLegend(GNEProhibitionFrame *prohibitionFrameParent)
constructor
void update() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:292
FXLabel * getFrameHeaderLabel() const
get the label for the frame&#39;s header
Definition: GNEFrame.cpp:139
bool controlKeyPressed() const
check if CONTROL key was pressed during click
RGBColor myProhibitingColor
color for connections with precedence
static const RGBColor WHITE
Definition: RGBColor.h:197
const RGBColor & getProhibitingColor() const
get color for connections with precedence
FXDEFMAP(GNEProhibitionFrame) GNEProhibitionFrameMap[]
GUIVisualizationSettings * getVisualisationSettings() const
get visualitation settings
The representation of a single edge during network building.
Definition: NBEdge.h:86
ProhibitionLegend * myProhibitionLegend
prohibition legend
void setSpecialColor(const RGBColor *Color2)
GNELane * getLaneFrom() const
get lane of the incoming lane
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:120
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:625
Modifications(GNEProhibitionFrame *prohibitionFrameParent)
constructor
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
std::set< GNEConnection * > myConcernedConns
the set of connections which
RGBColor myProhibitedColor
color for waiting connections
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:123
void handleProhibitionClick(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor)
handle prohibitions and set the relative colouring
RGBColor selectedProhibitionColor
prohibition selection color
GNELane * getLaneTo() const
get lane of the outgoing lane
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
GNEConnection * myCurrentConn
the connection which prohibits
GNEJunction * getGNEJunctionDestiny() const
returns the destination-junction
Definition: GNEEdge.cpp:505
class used to group all variables related with objects under cursor after a click over view ...
FXButton * myCancelButton
"Cancel" button
const GNEViewNetHelper::KeyPressed & getKeyPressed() const
get Key Pressed modul
Definition: GNEViewNet.cpp:423
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
#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()
FOX needs this.
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button discards any prohibition modifications.
FXButton * mySaveButton
"Save" button
GNEProhibitionFrame * myProhibitionFrameParent
pointer to prohibition frame parent
bool shiftKeyPressed() const
check if SHIFT key was pressed during click
FXLabel * myConnDescriptionLabel
the label that shows the currently selected connection
long onCmdOK(FXObject *, FXSelector, void *)
#define GUIDesignButton
Definition: GUIDesigns.h:66
~GNEProhibitionFrame()
Destructor.
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
RGBColor myMutualConflictColor
color for mutual conflicts
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:255
const std::string getFoes(int linkIndex) const
Definition: NBNode.cpp:971
RGBColor myUndefinedColor
color for non-conflicting pairs of connections
RelativeToConnection * myRelativeToConnection
Relative To Connection.
Ok-button pressed.
Definition: GUIAppEnum.h:213
const RGBColor & getUnregulatedConflictColor() const
get color for unregulated conflicts
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
Cancel-button pressed.
Definition: GUIAppEnum.h:215
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:114
Represents a single node (junction) during network building.
Definition: NBNode.h:68
GNEConnection * getConnectionFront() const
get front connection (or a pointer to nullptr if there isn&#39;t)
const std::string getResponse(int linkIndex) const
Definition: NBNode.cpp:981
GUIVisualizationColorSettings colorSettings
color settings
const RGBColor & getProhibitedColor() const
get color for waiting connections
const RGBColor & getUndefinedColor() const
get color for non-conflicting pairs of connections
NBNode * getNBNode() const
Return net build node.
const RGBColor & getMutualConflictColor() const
get color for mutual conflicts
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
void hide()
hide prohibition frame
void updateDescription() const
update description
void buildProhibition(GNEConnection *conn, bool mayDefinitelyPass, bool allowConflict, bool toggle)
build prohibition