Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNENeteditAttributes.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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
23#include <netedit/GNENet.h>
24#include <netedit/GNEViewNet.h>
28
30
31
32// ===========================================================================
33// FOX callback mapping
34// ===========================================================================
35
36FXDEFMAP(GNENeteditAttributes) NeteditAttributesMap[] = {
38 FXMAPFUNC(SEL_COMMAND, MID_HELP, GNENeteditAttributes::onCmdHelp)
39};
40
41// Object implementation
42FXIMPLEMENT(GNENeteditAttributes, MFXGroupBoxModule, NeteditAttributesMap, ARRAYNUMBER(NeteditAttributesMap))
43
44
45// ===========================================================================
46// method definitions
47// ===========================================================================
48
50 MFXGroupBoxModule(frameParent, TL("Netedit attributes")),
51 myFrameParent(frameParent),
52 myCurrentLengthValid(true),
53 myActualAdditionalReferencePoint(AdditionalReferencePoint::LEFT) {
54 // Create FXListBox for the reference points and fill it
55 myReferencePointMatchBox = new FXComboBox(getCollapsableFrame(), GUIDesignComboBoxNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignComboBox);
56 myReferencePointMatchBox->appendItem(TL("reference left"));
57 myReferencePointMatchBox->appendItem(TL("reference right"));
58 myReferencePointMatchBox->appendItem(TL("reference center"));
59 // Create Frame for Length Label and textField
60 myLengthFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
61 new FXLabel(myLengthFrame, toString(SUMO_ATTR_LENGTH).c_str(), 0, GUIDesignLabelThickedFixed(100));
62 myLengthTextField = new FXTextField(myLengthFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
63 myLengthTextField->setText("10");
64 // Create Frame for block close polygon and checkBox (By default disabled)
65 myCloseShapeFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
66 new FXLabel(myCloseShapeFrame, TL("Close shape"), 0, GUIDesignLabelThickedFixed(100));
67 myCloseShapeCheckButton = new FXCheckButton(myCloseShapeFrame, "false", this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
68 // Create Frame for center element after creation (By default enabled)
69 myCenterViewAfterCreationFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
70 new FXLabel(myCenterViewAfterCreationFrame, TL("Center view"), 0, GUIDesignLabelThickedFixed(100));
71 myCenterViewAfterCreationButton = new FXCheckButton(myCenterViewAfterCreationFrame, "false", this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
72 myCenterViewAfterCreationButton->setCheck(true);
73 // Create help button
74 helpReferencePoint = new FXButton(getCollapsableFrame(), TL("Help"), 0, this, MID_HELP, GUIDesignButtonRectangular);
75 // Set visible items
76 myReferencePointMatchBox->setNumVisible((int)myReferencePointMatchBox->getNumItems());
77}
78
79
81
82
83void
85 // we assume that frame will not be show
86 bool showFrame = false;
87 // check if length text field has to be showed
88 if (templateAC->getTagProperty().canMaskStartEndPos()) {
89 myLengthFrame->show();
91 showFrame = true;
92 } else {
93 myLengthFrame->hide();
95 }
96 // check if close shape check button has to be show
97 if (templateAC->getTagProperty().canCloseShape()) {
98 myCloseShapeFrame->show();
99 showFrame = true;
100 } else {
101 myCloseShapeFrame->hide();
102 }
103 // check if center camera after creation check button has to be show
104 if (templateAC->getTagProperty().canCenterCameraAfterCreation()) {
106 showFrame = true;
107 } else {
109 }
110 // if at least one element is show, show modul
111 if (showFrame) {
112 recalc();
113 show();
114 } else {
115 hide();
116 }
117}
118
119
120void
124
125
126bool
128 // check if we need to obtain a start and end position over an edge
129 if (myReferencePointMatchBox->shown()) {
130 // we need a valid lane to calculate position over lane
131 if (lane == nullptr) {
132 return false;
133 } else if (myCurrentLengthValid) {
134 // Obtain position of the mouse over lane (limited over grid)
136 // check if current reference point is valid
138 std::string errorMessage = TL("Current selected reference point isn't valid");
139 myFrameParent->getViewNet()->setStatusBarText(errorMessage);
140 // Write Warning in console if we're in testing mode
141 WRITE_DEBUG(errorMessage);
142 return false;
143 } else {
144 // obtain length
145 double length = GNEAttributeCarrier::parse<double>(myLengthTextField->getText().text());
146 // set start and end position
147 baseObject->addDoubleAttribute(SUMO_ATTR_STARTPOS, setStartPosition(mousePositionOverLane, length));
148 baseObject->addDoubleAttribute(SUMO_ATTR_ENDPOS, setEndPosition(mousePositionOverLane, length));
149 }
150 } else {
151 return false;
152 }
153 }
154 // Save close shape value if shape's element can be closed
155 if (myCloseShapeCheckButton->shown()) {
157 }
158 // check center element after creation
159 if (myCenterViewAfterCreationButton->shown()) {
161 }
162 // all ok, then return true to continue creating element
163 return true;
164}
165
166
167long
168GNENeteditAttributes::onCmdSetNeteditAttribute(FXObject* obj, FXSelector, void*) {
169 if (obj == myCloseShapeCheckButton) {
170 if (myCloseShapeCheckButton->getCheck()) {
171 myCloseShapeCheckButton->setText("true");
172 } else {
173 myCloseShapeCheckButton->setText("false");
174 }
175 } else if (obj == myCenterViewAfterCreationButton) {
176 if (myCenterViewAfterCreationButton->getCheck()) {
177 myCenterViewAfterCreationButton->setText("true");
178 } else {
179 myCenterViewAfterCreationButton->setText("false");
180 }
181 } else if (obj == myLengthTextField) {
182 // change color of text field depending of the input length
183 if (GNEAttributeCarrier::canParse<double>(myLengthTextField->getText().text()) &&
184 GNEAttributeCarrier::parse<double>(myLengthTextField->getText().text()) > 0) {
185 myLengthTextField->setTextColor(FXRGB(0, 0, 0));
186 myLengthTextField->killFocus();
188 } else {
189 myLengthTextField->setTextColor(FXRGB(255, 0, 0));
190 myCurrentLengthValid = false;
191 }
192 // Update additional frame
193 update();
194 } else if (obj == myReferencePointMatchBox) {
195 // Cast actual reference point type
196 if (myReferencePointMatchBox->getText() == TL("reference left")) {
197 myReferencePointMatchBox->setTextColor(FXRGB(0, 0, 0));
198 myReferencePointMatchBox->killFocus();
200 myLengthTextField->enable();
201 } else if (myReferencePointMatchBox->getText() == TL("reference right")) {
202 myReferencePointMatchBox->setTextColor(FXRGB(0, 0, 0));
203 myReferencePointMatchBox->killFocus();
205 myLengthTextField->enable();
206 } else if (myReferencePointMatchBox->getText() == TL("reference center")) {
207 myLengthTextField->enable();
208 myReferencePointMatchBox->setTextColor(FXRGB(0, 0, 0));
209 myReferencePointMatchBox->killFocus();
211 myLengthTextField->enable();
212 } else {
213 myReferencePointMatchBox->setTextColor(FXRGB(255, 0, 0));
215 myLengthTextField->disable();
216 }
217 }
218
219 return 1;
220}
221
222
223long
224GNENeteditAttributes::onCmdHelp(FXObject*, FXSelector, void*) {
225 // Create dialog box
226 FXDialogBox* additionalNeteditAttributesHelpDialog = new FXDialogBox(getCollapsableFrame(), "Netedit Parameters Help", GUIDesignDialogBox);
227 additionalNeteditAttributesHelpDialog->setIcon(GUIIconSubSys::getIcon(GUIIcon::MODEADDITIONAL));
228 // set help text
229 std::ostringstream help;
230 help
231 << TL("- Reference point: Mark the initial position of the additional element.") << "\n"
232 << TL(" Example: If you want to create a busStop with a length of 30 in the point 100 of the lane:") << "\n"
233 << TL(" - Reference Left will create it with startPos = 70 and endPos = 100.") << "\n"
234 << TL(" - Reference Right will create it with startPos = 100 and endPos = 130.") << "\n"
235 << TL(" - Reference Center will create it with startPos = 85 and endPos = 115.") << "\n"
236 << TL("- Block movement: if is enabled, the created additional element will be blocked. i.e. cannot be moved with") << "\n"
237 << TL(" 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") + std::string("\t\t") + TL("close")).c_str(), 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
264
265double
266GNENeteditAttributes::setStartPosition(double positionOfTheMouseOverLane, double lengthOfAdditional) const {
269 return positionOfTheMouseOverLane;
271 return positionOfTheMouseOverLane - lengthOfAdditional;
273 return positionOfTheMouseOverLane - lengthOfAdditional / 2;
274 default:
275 throw InvalidArgument("Reference Point invalid");
276 }
277}
278
279
280double
281GNENeteditAttributes::setEndPosition(double positionOfTheMouseOverLane, double lengthOfAdditional) const {
284 return positionOfTheMouseOverLane + lengthOfAdditional;
286 return positionOfTheMouseOverLane;
288 return positionOfTheMouseOverLane + lengthOfAdditional / 2;
289 default:
290 throw InvalidArgument("Reference Point invalid");
291 }
292}
293
294/****************************************************************************/
FXDEFMAP(GNENeteditAttributes) NeteditAttributesMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:907
@ MID_HELP
help button
Definition GUIAppEnum.h:645
#define GUIDesignComboBox
Definition GUIDesigns.h:288
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:306
#define GUIDesignTextField
Definition GUIDesigns.h:51
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:394
#define GUIDesignDialogBox
Definition GUIDesigns.h:588
#define GUIDesignButtonRectangular
little rectangular button used in frames (For example, in "help" buttons)
Definition GUIDesigns.h:80
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:66
#define GUIDesignButtonOK
Definition GUIDesigns.h:148
#define GUIDesignCheckButton
checkButton placed in left position
Definition GUIDesigns.h:187
#define GUIDesignHorizontalSeparator
Definition GUIDesigns.h:452
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:247
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:274
@ MODEADDITIONAL
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:281
#define TL(string)
Definition MsgHandler.h:287
@ LEFT
At the leftmost side of the lane.
@ 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:136
double getLengthGeometryFactor() const
get length geometry factor
Definition GNELane.cpp:1824
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
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