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-2018 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 
32 
33 #include "GNEProhibitionFrame.h"
34 
35 // ===========================================================================
36 // FOX callback mapping
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 // static members
48 // ===========================================================================
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 
60 GNEProhibitionFrame::GNEProhibitionFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
61  GNEFrame(horizontalFrameParent, viewNet, "Prohibits"), myCurrentConn(nullptr) {
62  getFrameHeaderLabel()->setText("Prohibitions");
63 
64  // init colors here
67  prohibitedColor = RGBColor(0, 179, 0);
71 
72  // Create groupbox for current connection information
73  myGroupBoxDescription = new FXGroupBox(myContentFrame, "Relative to connection", GUIDesignGroupBoxFrame);
74 
75  // Create label for current connection description and update it
78 
79  // Create groupbox for color legend
80  myGroupBoxLegend = new FXGroupBox(myContentFrame, "Legend", GUIDesignGroupBoxFrame);
81 
82  // Create labels for color legend
83  mySelectedLabel = new FXLabel(myGroupBoxLegend, "Selected", nullptr, GUIDesignLabelFrameInformation);
86  myUndefinedLabel = new FXLabel(myGroupBoxLegend, "No conflict", nullptr, GUIDesignLabelFrameInformation);
88  myProhibitedLabel = new FXLabel(myGroupBoxLegend, "Yields", nullptr, GUIDesignLabelFrameInformation);
90  myProhibitingLabel = new FXLabel(myGroupBoxLegend, "Has right of way", nullptr, GUIDesignLabelFrameInformation);
92  myProhibitingLabel = new FXLabel(myGroupBoxLegend, "Unregulated conflict", nullptr, GUIDesignLabelFrameInformation);
94  myProhibitingLabel = new FXLabel(myGroupBoxLegend, "Mutual conflict", nullptr, GUIDesignLabelFrameInformation);
96 
97  // Create "Cancel" button
98  myCancelButton = new FXButton(this, "Cancel\t\tDiscard prohibition modifications (Esc)",
100  // Create "OK" button
101  //mySaveButton = new FXButton(this, "OK\t\tSave prohibition modifications (Enter)",
102  // GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_OK, GUIDesignButton);
103 }
104 
105 
107 
108 
109 void
111  // build prohibition
113 }
114 
115 
116 void
118  GNEFrame::show();
119 }
120 
121 
122 void
124  GNEFrame::hide();
125 }
126 
127 
128 void
130  if (myCurrentConn == nullptr) {
131  myConnDescriptionLabel->setText("No Connection selected\n");
132  } else {
133  myConnDescriptionLabel->setText(("from lane " + myCurrentConn->getLaneFrom()->getMicrosimID() + "\nto lane " + myCurrentConn->getLaneTo()->getMicrosimID()).c_str());
134  }
135 }
136 
137 
138 long
139 GNEProhibitionFrame::onCmdCancel(FXObject*, FXSelector, void*) {
140  if (myCurrentConn != nullptr) {
141  for (auto conn : myConcernedConns) {
142  conn->setSpecialColor(nullptr);
143  }
144  myCurrentConn->setSpecialColor(nullptr);
145  myCurrentConn = nullptr;
146  myConcernedConns.clear();
148  myViewNet->update();
149  }
150  return 1;
151 }
152 
153 
154 void
155 GNEProhibitionFrame::buildProhibition(GNEConnection* conn, bool /* mayDefinitelyPass */, bool /* allowConflict */, bool /* toggle */) {
156  if (myCurrentConn == nullptr) {
157  myCurrentConn = conn;
159 
160  // determine prohibition status of all other connections with respect to the selected one
162  std::vector<GNEConnection*> allConns = junction->getGNEConnections();
163  NBNode* node = junction->getNBNode();
164  NBEdge* currentConnFrom = myCurrentConn->getEdgeFrom()->getNBEdge();
165 
166  const int currentLinkIndex = node->getConnectionIndex(currentConnFrom, myCurrentConn->getNBEdgeConnection());
167  std::string currentFoesString = node->getFoes(currentLinkIndex);
168  std::string currentResponseString = node->getResponse(currentLinkIndex);
169  std::reverse(currentFoesString.begin(), currentFoesString.end());
170  std::reverse(currentResponseString.begin(), currentResponseString.end());
171 
172  for (auto i : allConns) {
173  if (i != myCurrentConn) {
174  NBEdge* otherConnFrom = i->getEdgeFrom()->getNBEdge();
175  const int linkIndex = node->getConnectionIndex(otherConnFrom, i->getNBEdgeConnection());
176  std::string responseString = node->getResponse(linkIndex);
177  std::reverse(responseString.begin(), responseString.end());
178  // determine the prohibition status
179  bool foes = (int)currentFoesString.size() > linkIndex && currentFoesString[linkIndex] == '1';
180  bool forbids = (int)responseString.size() > currentLinkIndex && responseString[currentLinkIndex] == '1';
181  bool forbidden = (int)currentResponseString.size() > linkIndex && currentResponseString[linkIndex] == '1';
182 
183  myConcernedConns.insert(i);
184 
185  if (!foes) {
186  i->setSpecialColor(&undefinedColor);
187  } else {
188  if (forbids && forbidden) {
189  i->setSpecialColor(&mutualConflictColor);
190  } else if (forbids) {
191  i->setSpecialColor(&prohibitedColor);
192  } else if (forbidden) {
193  i->setSpecialColor(&prohibitingColor);
194  } else {
195  i->setSpecialColor(&unregulatedConflictColor);
196  }
197  }
198  }
199  }
200 
202  }
203 }
204 
205 
206 long
207 GNEProhibitionFrame::onCmdOK(FXObject*, FXSelector, void*) {
208  return 1;
209 }
210 
211 
212 /****************************************************************************/
int getConnectionIndex(const NBEdge *from, const NBEdge::Connection &con) const
return the index of the given connection
Definition: NBNode.cpp:3007
std::vector< GNEConnection * > getGNEConnections() const
Returns all GNEConnections vinculated with this junction.
void show()
show prohibition frame
const KeyPressed & getKeyPressed() const
get Key Pressed modul
FXLabel * getFrameHeaderLabel() const
get the label for the frame&#39;s header
Definition: GNEFrame.cpp:1726
static const RGBColor WHITE
Definition: RGBColor.h:191
FXDEFMAP(GNEProhibitionFrame) GNEProhibitionFrameMap[]
GUIVisualizationSettings * getVisualisationSettings() const
get visualitation settings
The representation of a single edge during network building.
Definition: NBEdge.h:65
FXGroupBox * myGroupBoxDescription
Groupbox for description.
static const RGBColor ORANGE
Definition: RGBColor.h:190
static RGBColor undefinedColor
color for non-conflicting pairs of connections
static RGBColor mutualConflictColor
color for mutual conflicts
static RGBColor unregulatedConflictColor
color for unregulated conflicts
void setSpecialColor(const RGBColor *Color2)
GNELane * getLaneFrom() const
get lane of the incoming lane
GNEViewNet * myViewNet
View Net for changes.
Definition: GNEFrame.h:612
void updateDescription() const
update description
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
std::set< GNEConnection * > myConcernedConns
the set of connections which
FXLabel * myProhibitingLabel
"prohibiting" label
static const RGBColor GREY
Definition: RGBColor.h:193
FXGroupBox * myGroupBoxLegend
group box for legend
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:615
static RGBColor prohibitingColor
color for connections with precedence
GNELane * getLaneTo() const
get lane of the outgoing lane
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
GNEConnection * myCurrentConn
"OK" button
GNEJunction * getGNEJunctionDestiny() const
returns the destination-junction
Definition: GNEEdge.cpp:464
bool controlKeyPressed() const
check if CONTROL key was pressed during click
Definition: GNEViewNet.cpp:475
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
FXLabel * myConnDescriptionLabel
the label that shows the currently selected connection
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:184
GNEProhibitionFrame()
FOX needs this.
FXButton * myCancelButton
"Cancel" button
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button discards any prohibition modifications.
FXLabel * mySelectedLabel
selected connection label
FXLabel * myUndefinedLabel
"undefined" yielding label
long onCmdOK(FXObject *, FXSelector, void *)
#define GUIDesignButton
Definition: GUIDesigns.h:54
static const RGBColor RED
named colors
Definition: RGBColor.h:184
~GNEProhibitionFrame()
Destructor.
virtual void show()
show Frame
Definition: GNEFrame.cpp:1695
static const RGBColor CYAN
Definition: RGBColor.h:188
void handleProhibitionClick(const GNEViewNet::ObjectsUnderCursor &objectsUnderCursor)
handle prohibitions and set the relative colouring
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:227
const std::string getFoes(int linkIndex) const
Definition: NBNode.cpp:927
Ok-button pressed.
Definition: GUIAppEnum.h:56
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:1704
static RGBColor selectedColor
color for selected connection whose prohibition shall be shown
Cancel-button pressed.
Definition: GUIAppEnum.h:58
static RGBColor prohibitedColor
color for waiting connections
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
const std::string getResponse(int linkIndex) const
Definition: NBNode.cpp:937
GNEConnection * getConnectionFront() const
get front connection (or a pointer to nullptr if there isn&#39;t)
Definition: GNEViewNet.cpp:387
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:613
bool shiftKeyPressed() const
check if SHIFT key was pressed during click
Definition: GNEViewNet.cpp:465
NBNode * getNBNode() const
Return net build node.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
FXLabel * myProhibitedLabel
"prohibited" label
void hide()
hide prohibition frame
void buildProhibition(GNEConnection *conn, bool mayDefinitelyPass, bool allowConflict, bool toggle)
build prohibition