Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAttributesEditor.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-2024 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// Row used for edit attributes
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
35
36#include "GNEAttributesEditor.h"
38
39// ===========================================================================
40// FOX callback mapping
41// ===========================================================================
42
49
50// Object implementation
51FXIMPLEMENT(GNEAttributesEditor, MFXGroupBoxModule, GNEAttributeTableMap, ARRAYNUMBER(GNEAttributeTableMap))
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
56
57GNEAttributesEditor::GNEAttributesEditor(GNEFrame* frameParent, const std::string attributesEditorName, const int editorOptions) :
58 MFXGroupBoxModule(frameParent, attributesEditorName.c_str()),
59 myFrameParent(frameParent),
60 myEditorOptions(editorOptions) {
61 // adjust max number of rows
62 if ((myEditorOptions & EditorOptions::BASIC_ATTRIBUTES) != 0) {
64 } else if ((myEditorOptions & EditorOptions::FLOW_ATTRIBUTES) != 0) {
66 } else if ((myEditorOptions & EditorOptions::GEO_ATTRIBUTES) != 0) {
68 } else if ((myEditorOptions & EditorOptions::NETEDIT_ATTRIBUTES) != 0) {
70 // create netedit editor buttons
71 myFrontButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Front element"), "", "", GUIIconSubSys::getIcon(GUIIcon::FRONTELEMENT), this, MID_GNE_ATTRIBUTESEDITOR_FRONT, GUIDesignButton);
72 myFrontButton->hide();
73 myOpenDialogButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Open element dialog"), "", "", nullptr, this, MID_GNE_ATTRIBUTESEDITOR_DIALOG, GUIDesignButton);
74 myOpenDialogButton->hide();
75 } else if ((myEditorOptions & EditorOptions::EXTENDED_ATTRIBUTES) != 0) {
76 // create extended attributes
77 myOpenExtendedAttributesButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Edit extended attributes"), "", "", nullptr, this, MID_GNE_ATTRIBUTESEDITOR_EXTENDED, GUIDesignButton);
78 myOpenExtendedAttributesButton->hide();
79 } else {
80 throw ProcessError("Invalid editor option");
81 }
82 // resize myAttributesEditorRows and fill it with attribute rows
83 myAttributesEditorRows.resize(myMaxNumberOfRows);
84 for (int i = 0; i < myMaxNumberOfRows; i++) {
85 myAttributesEditorRows[i] = new GNEAttributesEditorRow(this);
86 }
87 // Create help button
88 myHelpButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Help"), "", "", nullptr, this, MID_GNE_ATTRIBUTESEDITOR_HELP, GUIDesignButtonRectangular);
89}
90
91
96
97
98void
104
105
106void
107GNEAttributesEditor::showAttributesEditor(const std::unordered_set<GNEAttributeCarrier*>& ACs) {
108 myEditedACs.clear();
109 for (const auto& AC : ACs) {
110 myEditedACs.push_back(AC);
111 }
113}
114
115
116void
118 myEditedACs.clear();
119 // hide all rows before hidding table
120 for (const auto& row : myAttributesEditorRows) {
121 row->hideAttributeRow();
122 }
123 hide();
124}
125
126
127void
129 if (myEditedACs.size() > 0) {
130 const auto& tagProperty = myEditedACs.front()->getTagProperty();
131 int itRows = 0;
132 bool showButtons = false;
133 // check if show netedit attributes (only for single edited ACs)
135 // front button
136 if (tagProperty.isDrawable()) {
137 myFrontButton->show();
138 // disable if we're reparenting
139 if (isReparenting()) {
140 myOpenDialogButton->disable();
141 } else {
142 myOpenDialogButton->enable();
143 }
144 showButtons = true;
145 } else {
146 myFrontButton->hide();
147 }
148 // specific for single edited attributes
149 if (myEditedACs.size() == 1) {
150 // edit dialog
151 if (tagProperty.hasDialog()) {
152 // set text and icon
153 myOpenDialogButton->setText(TLF("Open % dialog", tagProperty.getTagStr()).c_str());
154 myOpenDialogButton->setIcon(GUIIconSubSys::getIcon(tagProperty.getGUIIcon()));
155 // disable if we're reparenting
156 if (isReparenting()) {
157 myOpenDialogButton->disable();
158 } else {
159 myOpenDialogButton->enable();
160 }
161 myOpenDialogButton->show();
162 showButtons = true;
163 } else {
164 myOpenDialogButton->hide();
165 }
166
167 }
168 }
171 showButtons = true;
172 } else {
173 // Iterate over tag property of first AC and show row for every attribute
174 for (const auto& attrProperty : tagProperty) {
175 bool showAttributeRow = true;
176 // check show conditions
177 if (attrProperty.isExtended()) {
178 showAttributeRow = false;
179 } else if (((myEditorOptions & EditorOptions::FLOW_ATTRIBUTES) == 0) && attrProperty.isFlow()) {
180 showAttributeRow = false;
181 } else if (((myEditorOptions & EditorOptions::FLOW_ATTRIBUTES) != 0) && !attrProperty.isFlow()) {
182 showAttributeRow = false;
183 } else if (((myEditorOptions & EditorOptions::GEO_ATTRIBUTES) == 0) && attrProperty.isGEO()) {
184 showAttributeRow = false;
185 } else if (((myEditorOptions & EditorOptions::GEO_ATTRIBUTES) != 0) && !attrProperty.isGEO()) {
186 showAttributeRow = false;
187 } else if (((myEditorOptions & EditorOptions::NETEDIT_ATTRIBUTES) == 0) && attrProperty.isNetedit()) {
188 showAttributeRow = false;
189 } else if (((myEditorOptions & EditorOptions::NETEDIT_ATTRIBUTES) != 0) && !attrProperty.isNetedit()) {
190 showAttributeRow = false;
192 showAttributeRow = true;
193 }
194 if (showAttributeRow) {
195 if (itRows < myMaxNumberOfRows) {
196 // only update if row was show successfully
197 if (myAttributesEditorRows[itRows]->showAttributeRow(attrProperty, isReparenting())) {
198 itRows++;
199 }
200 } else {
201 throw ProcessError("Invalid maximum number of rows");
202 }
203 }
204 }
205 }
206 // hide rest of rows before showing table
207 for (int i = itRows; i < myMaxNumberOfRows; i++) {
208 myAttributesEditorRows[i]->hideAttributeRow();
209 }
210 // only show if at least one row or button was shown
211 if ((itRows == 0) && !showButtons) {
213 } else {
214 // check if show help button
215 if (itRows > 0) {
216 myHelpButton->show();
217 } else {
218 myHelpButton->hide();
219 }
220 show();
221 }
222 } else {
224 }
225}
226
227
228bool
232
233
234bool
238
239
240void
245
246
247void
252
253
254long
255GNEAttributesEditor::onCmdMarkAsFront(FXObject*, FXSelector, void*) {
256 // front all edited ACs
257 for (auto& AC : myEditedACs) {
258 AC->markForDrawingFront();
259 }
260 return 1;
261}
262
263
264long
265GNEAttributesEditor::onCmdOpenElementDialog(FXObject*, FXSelector, void*) {
266 // check number of inspected elements
267 if (myEditedACs.size() == 1) {
268 const auto editedTag = myEditedACs.front()->getTagProperty().getTag();
269 // check AC
270 if (editedTag == SUMO_TAG_REROUTER) {
271 // Open rerouter dialog
272 GNERerouterDialog(dynamic_cast<GNERerouter*>(myEditedACs.front()));
273 } else if ((editedTag == SUMO_TAG_CALIBRATOR) || (editedTag == GNE_TAG_CALIBRATOR_LANE)) {
274 // Open calibrator dialog
275 GNECalibratorDialog(dynamic_cast<GNECalibrator*>(myEditedACs.front()));
276 } else if (editedTag == SUMO_TAG_VSS) {
277 // Open VSS dialog
279 }
280 }
281 return 1;
282}
283
284
285long
287 // obtain edited AC (temporal), until unification of
288 const auto demandElement = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveDemandElement(myEditedACs.front()->getTagProperty().getTag(), myEditedACs.front()->getID(), false);
289 // open vehicle type dialog
290 if (demandElement) {
291 GNEVehicleTypeDialog(demandElement, true); // NOSONAR, constructor returns after dialog has been closed
293 }
294 return 1;
295}
296
297
298long
300 if (myEditedACs.size() > 0) {
302 }
303 return 1;
304}
305
306
307void
308GNEAttributesEditor::setAttribute(SumoXMLAttr attr, const std::string& value) {
309 const auto undoList = myFrameParent->getViewNet()->getUndoList();
310 const auto& tagProperty = myEditedACs.front()->getTagProperty();
311 // first check if we're editing a single attribute or an ID
312 if (myEditedACs.size() > 1) {
313 undoList->begin(tagProperty.getGUIIcon(), TLF("change multiple % attributes", tagProperty.getTagStr()));
314 } else if (attr == SUMO_ATTR_ID) {
315 // IDs attribute has to be encapsulated because implies multiple changes in different additionals (due references)
316 undoList->begin(tagProperty.getGUIIcon(), TLF("change % attribute", tagProperty.getTagStr()));
317 }
318 // Set new value of attribute in all edited ACs
319 for (const auto& editedAC : myEditedACs) {
320 editedAC->setAttribute(attr, value, undoList);
321 }
322 // finish change multiple attributes or ID Attributes
323 if ((myEditedACs.size() > 1) || (attr == SUMO_ATTR_ID)) {
324 undoList->end();
325 }
327 // update frame parent (needed to update other attribute tables)
329}
330
331
332void
334 const auto undoList = myFrameParent->getViewNet()->getUndoList();
335 const auto& tagProperty = myEditedACs.front()->getTagProperty();
336 // first check if we're editing a single attribute
337 if (myEditedACs.size() > 1) {
338 undoList->begin(tagProperty.getGUIIcon(), TLF("change multiple % attributes", tagProperty.getTagStr()));
339 }
340 // Set new value of attribute in all edited ACs
341 for (const auto& editedAC : myEditedACs) {
342 if (value) {
343 editedAC->enableAttribute(attr, undoList);
344 } else {
345 editedAC->disableAttribute(attr, undoList);
346 }
347 }
348 // finish change multiple attributes or ID Attributes
349 if ((myEditedACs.size() > 1) || (attr == SUMO_ATTR_ID)) {
350 undoList->end();
351 }
353 // update frame parent (needed to update other attribute tables)
355}
356
357
358void
360 if (myEditedACs.front()->getTagProperty().getParentTags().size() > 0) {
361 myReparentTag = myEditedACs.front()->getTagProperty().getParentTags().front();
363 myFrameParent->getViewNet()->update();
364 }
365}
366
367
368void
375
376
377void
379 const auto lane = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveLane(myEditedACs.front()->getAttribute(SUMO_ATTR_LANE), false);
380 if (lane) {
381 // set next lane
382 setAttribute(SUMO_ATTR_LANE, lane->getParentEdge()->getLanes().at(lane->getIndex() + 1)->getID());
383 }
384}
385
386
387void
389 const auto lane = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveLane(myEditedACs.front()->getAttribute(SUMO_ATTR_LANE), false);
390 if (lane) {
391 // set previous lane
392 setAttribute(SUMO_ATTR_LANE, lane->getParentEdge()->getLanes().at(lane->getIndex() - 1)->getID());
393 }
394}
395
396/****************************************************************************/
FXDEFMAP(GNEAttributesEditor) GNEAttributeTableMap[]
@ MID_GNE_ATTRIBUTESEDITOR_FRONT
mark element as front
@ MID_GNE_ATTRIBUTESEDITOR_DIALOG
open element dialog
@ MID_GNE_ATTRIBUTESEDITOR_EXTENDED
open extended attributes
@ MID_GNE_ATTRIBUTESEDITOR_HELP
open help dialog
#define GUIDesignButton
Definition GUIDesigns.h:82
#define GUIDesignButtonRectangular
little rectangular button used in frames (For example, in "help" buttons)
Definition GUIDesigns.h:94
@ FRONTELEMENT
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
@ SUMO_TAG_REROUTER
A rerouter.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ GNE_TAG_CALIBRATOR_LANE
A calibrator placed over lane.
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
@ SUMO_TAG_VSS
A variable speed sign.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
static int maxNumberOfGeoAttributes
max number of geo attributes (needed for geo attributes editor)
const std::string getID() const
get ID (all Attribute Carriers have one)
static int maxNumberOfNeteditAttributes
max number of netedit attributes (needed for netedit attributes editor)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
static int maxNumberOfEditableAttributes
max number of editable (non extended) attributes (needed for attributes editor)
static int maxNumberOfFlowAttributes
max number of flow attributes (needed for geo attributes editor)
long onCmdAttributesEditorHelp(FXObject *, FXSelector, void *)
called when user press the help button
GNEFrame * getFrameParent() const
pointer to GNEFrame parent
long onCmdOpenElementDialog(FXObject *, FXSelector, void *)
called when user press the "Open element dialog" button
void setNewParent(const GNEAttributeCarrier *AC)
set new parent
std::vector< GNEAttributeCarrier * > myEditedACs
current edited ACs
long onCmdMarkAsFront(FXObject *, FXSelector, void *)
GNEFrame * myFrameParent
pointer to GNEFrame parent
int myMaxNumberOfRows
maximum number of rows used in this attributes editor
void refreshAttributesEditor()
refresh attribute editor
int myEditorOptions
variable use for packing attribute editor options
void toggleEnableAttribute(SumoXMLAttr attr, const bool value)
set attribute in the current ACs (Callend from row)
bool checkNewParent(const GNEAttributeCarrier *AC) const
check if the given AC can be a new parent
void moveLaneDown()
move lane down
void inspectParent()
inspect parent (Callend from row)
void enableReparent()
void enable reparent
std::vector< GNEAttributesEditorRow * > myAttributesEditorRows
list of attributes editor rows
void showAttributesEditor(GNEAttributeCarrier *AC)
edit attributes of the given AC (usually the edited template AC)
SumoXMLTag myReparentTag
check if we're reparent
long onCmdOpenExtendedAttributesDialog(FXObject *, FXSelector, void *)
called when user press the "Open extended attributes" button
void abortReparenting()
abort selecting parent
void hideAttributesEditor()
hide attribute editor
FXButton * myFrontButton
pointer to front button
FXButton * myOpenExtendedAttributesButton
pointer to open extended attributes button
void moveLaneUp()
move lane up
FXButton * myOpenDialogButton
pointer to open dialog button (usually additionals)
void setAttribute(SumoXMLAttr attr, const std::string &value)
set attribute in the current ACs (Callend from row)
FXButton * myHelpButton
button for help
Dialog for edit calibrators.
virtual void attributeUpdated(SumoXMLAttr attribute)
function called after set a valid attribute in AttributeCreator/AttributeEditor/ParametersEditor/....
Definition GNEFrame.cpp:286
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
void openHelpAttributesDialog(const GNEAttributeCarrier *AC) const
Open help attributes dialog.
Definition GNEFrame.cpp:184
void inspectElement(GNEAttributeCarrier *AC, GNEAttributeCarrier *previousInspectedAC=nullptr)
Inspect a single element.
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
Dialog for edit rerouters.
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
Dialog for editing calibrator vehicle types.
GNENet * getNet() const
get the net object
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
GNEInspectorFrame * getInspectorFrame() const
get frame for inspect elements
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXGroupBoxModule (based on FXGroupBox)
Definition json.hpp:4471