Eclipse SUMO - Simulation of Urban MObility
GNENeteditAttributes.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-2022 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/****************************************************************************/
18// Modul for edit NETEDIT attributes
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
27
29
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
35FXDEFMAP(GNENeteditAttributes) NeteditAttributesMap[] = {
37 FXMAPFUNC(SEL_COMMAND, MID_HELP, GNENeteditAttributes::onCmdHelp)
38};
39
40// Object implementation
41FXIMPLEMENT(GNENeteditAttributes, MFXGroupBoxModule, NeteditAttributesMap, ARRAYNUMBER(NeteditAttributesMap))
42
43
44// ===========================================================================
45// method definitions
46// ===========================================================================
47
49 MFXGroupBoxModule(frameParent, TL("Netedit attributes")),
50 myFrameParent(frameParent),
51 myCurrentLengthValid(true),
52 myActualAdditionalReferencePoint(AdditionalReferencePoint::LEFT) {
53 // Create FXListBox for the reference points and fill it
54 myReferencePointMatchBox = new FXComboBox(getCollapsableFrame(), GUIDesignComboBoxNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignComboBox);
55 myReferencePointMatchBox->appendItem("reference left");
56 myReferencePointMatchBox->appendItem("reference right");
57 myReferencePointMatchBox->appendItem("reference center");
58 // Create Frame for Length Label and textField
59 myLengthFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
60 new FXLabel(myLengthFrame, toString(SUMO_ATTR_LENGTH).c_str(), 0, GUIDesignLabelAttribute);
61 myLengthTextField = new FXTextField(myLengthFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
62 myLengthTextField->setText("10");
63 // Create Frame for block close polygon and checkBox (By default disabled)
64 myCloseShapeFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
65 new FXLabel(myCloseShapeFrame, "Close shape", 0, GUIDesignLabelAttribute);
66 myCloseShapeCheckButton = new FXCheckButton(myCloseShapeFrame, TL("false"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
67 // Create Frame for center element after creation (By default enabled)
68 myCenterViewAfterCreationFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
69 new FXLabel(myCenterViewAfterCreationFrame, "Center view", 0, GUIDesignLabelAttribute);
70 myCenterViewAfterCreationButton = new FXCheckButton(myCenterViewAfterCreationFrame, TL("false"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
71 myCenterViewAfterCreationButton->setCheck(true);
72 // Create help button
73 helpReferencePoint = new FXButton(getCollapsableFrame(), TL("Help"), 0, this, MID_HELP, GUIDesignButtonRectangular);
74 // Set visible items
75 myReferencePointMatchBox->setNumVisible((int)myReferencePointMatchBox->getNumItems());
76}
77
78
80
81
82void
84 // we assume that frame will not be show
85 bool showFrame = false;
86 // check if length text field has to be showed
87 if (templateAC->getTagProperty().canMaskStartEndPos()) {
88 myLengthFrame->show();
90 showFrame = true;
91 } else {
92 myLengthFrame->hide();
94 }
95 // check if close shape check button has to be show
96 if (templateAC->getTagProperty().canCloseShape()) {
97 myCloseShapeFrame->show();
98 showFrame = true;
99 } else {
100 myCloseShapeFrame->hide();
101 }
102 // check if center camera after creation check button has to be show
103 if (templateAC->getTagProperty().canCenterCameraAfterCreation()) {
105 showFrame = true;
106 } else {
108 }
109 // if at least one element is show, show modul
110 if (showFrame) {
111 recalc();
112 show();
113 } else {
114 hide();
115 }
116}
117
118
119void
121 hide();
122}
123
124
125bool
127 // check if we need to obtain a start and end position over an edge
128 if (myReferencePointMatchBox->shown()) {
129 // we need a valid lane to calculate position over lane
130 if (lane == nullptr) {
131 return false;
132 } else if (myCurrentLengthValid) {
133 // Obtain position of the mouse over lane (limited over grid)
135 // check if current reference point is valid
137 std::string errorMessage = "Current selected reference point isn't valid";
138 myFrameParent->getViewNet()->setStatusBarText(errorMessage);
139 // Write Warning in console if we're in testing mode
140 WRITE_DEBUG(errorMessage);
141 return false;
142 } else {
143 // obtain length
144 double length = GNEAttributeCarrier::parse<double>(myLengthTextField->getText().text());
145 // set start and end position
146 baseObject->addDoubleAttribute(SUMO_ATTR_STARTPOS, setStartPosition(mousePositionOverLane, length));
147 baseObject->addDoubleAttribute(SUMO_ATTR_ENDPOS, setEndPosition(mousePositionOverLane, length));
148 }
149 } else {
150 return false;
151 }
152 }
153 // Save close shape value if shape's element can be closed
154 if (myCloseShapeCheckButton->shown()) {
156 }
157 // check center element after creation
158 if (myCenterViewAfterCreationButton->shown()) {
160 }
161 // all ok, then return true to continue creating element
162 return true;
163}
164
165
166long
167GNENeteditAttributes::onCmdSetNeteditAttribute(FXObject* obj, FXSelector, void*) {
168 if (obj == myCloseShapeCheckButton) {
169 if (myCloseShapeCheckButton->getCheck()) {
170 myCloseShapeCheckButton->setText(TL("true"));
171 } else {
172 myCloseShapeCheckButton->setText(TL("false"));
173 }
174 } else if (obj == myCenterViewAfterCreationButton) {
175 if (myCenterViewAfterCreationButton->getCheck()) {
176 myCenterViewAfterCreationButton->setText(TL("true"));
177 } else {
178 myCenterViewAfterCreationButton->setText(TL("false"));
179 }
180 } else if (obj == myLengthTextField) {
181 // change color of text field depending of the input length
182 if (GNEAttributeCarrier::canParse<double>(myLengthTextField->getText().text()) &&
183 GNEAttributeCarrier::parse<double>(myLengthTextField->getText().text()) > 0) {
184 myLengthTextField->setTextColor(FXRGB(0, 0, 0));
185 myLengthTextField->killFocus();
187 } else {
188 myLengthTextField->setTextColor(FXRGB(255, 0, 0));
189 myCurrentLengthValid = false;
190 }
191 // Update additional frame
192 update();
193 } else if (obj == myReferencePointMatchBox) {
194 // Cast actual reference point type
195 if (myReferencePointMatchBox->getText() == "reference left") {
196 myReferencePointMatchBox->setTextColor(FXRGB(0, 0, 0));
197 myReferencePointMatchBox->killFocus();
199 myLengthTextField->enable();
200 } else if (myReferencePointMatchBox->getText() == "reference right") {
201 myReferencePointMatchBox->setTextColor(FXRGB(0, 0, 0));
202 myReferencePointMatchBox->killFocus();
204 myLengthTextField->enable();
205 } else if (myReferencePointMatchBox->getText() == "reference center") {
206 myLengthTextField->enable();
207 myReferencePointMatchBox->setTextColor(FXRGB(0, 0, 0));
208 myReferencePointMatchBox->killFocus();
210 myLengthTextField->enable();
211 } else {
212 myReferencePointMatchBox->setTextColor(FXRGB(255, 0, 0));
214 myLengthTextField->disable();
215 }
216 }
217
218 return 1;
219}
220
221
222long
223GNENeteditAttributes::onCmdHelp(FXObject*, FXSelector, void*) {
224 // Create dialog box
225 FXDialogBox* additionalNeteditAttributesHelpDialog = new FXDialogBox(getCollapsableFrame(), "Netedit Parameters Help", GUIDesignDialogBox);
226 additionalNeteditAttributesHelpDialog->setIcon(GUIIconSubSys::getIcon(GUIIcon::MODEADDITIONAL));
227 // set help text
228 std::ostringstream help;
229 help
230 << TL("- Reference point: Mark the initial position of the additional element.\n")
231 << TL(" Example: If you want to create a busStop with a length of 30 in the point 100 of the lane:\n")
232 << TL(" - Reference Left will create it with startPos = 70 and endPos = 100.\n")
233 << TL(" - Reference Right will create it with startPos = 100 and endPos = 130.\n")
234 << TL(" - Reference Center will create it with startPos = 85 and endPos = 115.\n")
235 << "\n"
236 << TL("- Block movement: if is enabled, the created additional element will be blocked. i.e. cannot be moved with\n")
237 << " the mouse. This option can be modified inspecting element.\n"
238 << TL("- Center view: if is enabled, view will be center over created element.");
239 // Create label with the help text
240 new FXLabel(additionalNeteditAttributesHelpDialog, help.str().c_str(), 0, GUIDesignLabelFrameInformation);
241 // Create horizontal separator
242 new FXHorizontalSeparator(additionalNeteditAttributesHelpDialog, GUIDesignHorizontalSeparator);
243 // Create frame for OK Button
244 FXHorizontalFrame* myHorizontalFrameOKButton = new FXHorizontalFrame(additionalNeteditAttributesHelpDialog, GUIDesignAuxiliarHorizontalFrame);
245 // Create Button Close (And two more horizontal frames to center it)
246 new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
247 new FXButton(myHorizontalFrameOKButton, TL("OK\t\tclose"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), additionalNeteditAttributesHelpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
248 new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
249 // Write Warning in console if we're in testing mode
250 WRITE_DEBUG("Opening GNENeteditAttributes help dialog");
251 // create Dialog
252 additionalNeteditAttributesHelpDialog->create();
253 // show in the given position
254 additionalNeteditAttributesHelpDialog->show(PLACEMENT_CURSOR);
255 // refresh APP
256 getApp()->refresh();
257 // open as modal dialog (will block all windows until stop() or stopModal() is called)
258 getApp()->runModalFor(additionalNeteditAttributesHelpDialog);
259 // Write Warning in console if we're in testing mode
260 WRITE_DEBUG("Closing GNENeteditAttributes help dialog");
261 return 1;
262 /**********
263 help from ShapeFrame
264 << TL("- Block movement: If enabled, the created polygon element will be blocked. i.e. cannot be moved with\n")
265 << " the mouse. This option can be modified inspecting element.\n"
266 << "\n"
267 << TL("- Block shape: If enabled, the shape of created polygon element will be blocked. i.e. their geometry points\n")
268 << " cannot be edited be moved with the mouse. This option can be modified inspecting element.\n"
269 << "\n"
270 << TL("- Close shape: If enabled, the created polygon element will be closed. i.e. the last created geometry point\n")
271 << " will be connected with the first geometry point automatically. This option can be modified inspecting element.";
272
273 ****************/
274}
275
276
277double
278GNENeteditAttributes::setStartPosition(double positionOfTheMouseOverLane, double lengthOfAdditional) const {
281 return positionOfTheMouseOverLane;
283 return positionOfTheMouseOverLane - lengthOfAdditional;
285 return positionOfTheMouseOverLane - lengthOfAdditional / 2;
286 default:
287 throw InvalidArgument("Reference Point invalid");
288 }
289}
290
291
292double
293GNENeteditAttributes::setEndPosition(double positionOfTheMouseOverLane, double lengthOfAdditional) const {
296 return positionOfTheMouseOverLane + lengthOfAdditional;
298 return positionOfTheMouseOverLane;
300 return positionOfTheMouseOverLane + lengthOfAdditional / 2;
301 default:
302 throw InvalidArgument("Reference Point invalid");
303 }
304}
305
306/****************************************************************************/
FXDEFMAP(GNENeteditAttributes) NeteditAttributesMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:870
@ MID_HELP
help button
Definition: GUIAppEnum.h:641
#define GUIDesignComboBox
Definition: GUIDesigns.h:306
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:321
#define GUIDesignTextField
Definition: GUIDesigns.h:48
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:397
#define GUIDesignLabelAttribute
label extended over the matrix column with thick frame
Definition: GUIDesigns.h:241
#define GUIDesignDialogBox
Definition: GUIDesigns.h:584
#define GUIDesignButtonRectangular
little button rectangula used in frames (For example, in "help" buttons)
Definition: GUIDesigns.h:83
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:69
#define GUIDesignButtonOK
Definition: GUIDesigns.h:142
#define GUIDesignCheckButton
checkButton placed in left position
Definition: GUIDesigns.h:169
#define GUIDesignHorizontalSeparator
Definition: GUIDesigns.h:452
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:271
@ MODEADDITIONAL
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:276
#define TL(string)
Definition: MsgHandler.h:282
@ SUMO_ATTR_STARTPOS
@ GNE_ATTR_CENTER_AFTER_CREATION
flag to center camera after element creation
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_CLOSE_SHAPE
Close shape of a polygon (Used by GNEPolys)
@ SUMO_ATTR_LENGTH
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void addBoolAttribute(const SumoXMLAttr attr, const bool value)
add bool attribute into current SumoBaseObject node
void addDoubleAttribute(const SumoXMLAttr attr, const double value)
add double attribute into current SumoBaseObject node
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:150
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
const PositionVector & getLaneShape() const
get elements shape
Definition: GNELane.cpp:142
double getLengthGeometryFactor() const
get length geometry factor
Definition: GNELane.cpp:1807
FXHorizontalFrame * myLengthFrame
horizontal frame for length
FXHorizontalFrame * myCenterViewAfterCreationFrame
horizontal frame for center view after creation frame
double setEndPosition(double positionOfTheMouseOverLane, double lengthOfAdditional) const
obtain the End position values of StoppingPlaces and E2 detector over the lane
long onCmdSetNeteditAttribute(FXObject *, FXSelector, void *)
double setStartPosition(double positionOfTheMouseOverLane, double lengthOfAdditional) const
obtain the Start position values of StoppingPlaces and E2 detector over the lane
AdditionalReferencePoint myActualAdditionalReferencePoint
actual additional reference point selected in the match Box
FXComboBox * myReferencePointMatchBox
match box with the list of reference points
long onCmdHelp(FXObject *, FXSelector, void *)
Called when user press the help button.
bool myCurrentLengthValid
Flag to check if current length is valid.
FXTextField * myLengthTextField
textField for length
FXCheckButton * myCenterViewAfterCreationButton
checkbox to enable/disable center element after creation
void showNeteditAttributesModule(GNEAttributeCarrier *templateAC)
show Netedit attributes modul
FXHorizontalFrame * myCloseShapeFrame
horizontal frame for close polygon
void hideNeteditAttributesModule()
hide Netedit attributes modul
FXCheckButton * myCloseShapeCheckButton
checkbox to enable/disable close polygon
bool getNeteditAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, const GNELane *lane) const
fill valuesMap with netedit attributes
AdditionalReferencePoint
list of the reference points
GNEFrame * myFrameParent
pointer to frame parent
bool canMaskStartEndPos() const
return true if tag correspond to an element that can mask the attributes "start" and "end" position a...
bool canCenterCameraAfterCreation() const
return true if tag correspond to an element that center camera after creation
bool canCloseShape() const
return true if tag correspond to an element that can close their shape
void setStatusBarText(const std::string &text)
set statusBar text
Definition: GNEViewNet.cpp:768
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D