Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEElementList.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-2025 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// Table used in GNEElementList
19/****************************************************************************/
20
26#include <netedit/GNENet.h>
28#include <netedit/GNEUndoList.h>
30
31#include "GNEElementList.h"
32#include "GNEElementTable.h"
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
38FXDEFMAP(GNEElementList) GNEElementListMap[] = {
41};
42
43// Object implementation
44FXIMPLEMENT_ABSTRACT(GNEElementList, FXVerticalFrame, GNEElementListMap, ARRAYNUMBER(GNEElementListMap))
45
46// ===========================================================================
47// method definitions
48// ===========================================================================
49
50GNEElementList::GNEElementList(GNEDialog* parentDialog, FXVerticalFrame* contentFrame, SumoXMLTag tag, GNEElementList::Options options) :
51 FXVerticalFrame(contentFrame, GUIDesignAuxiliarVerticalFrame),
52 myDialogParent(parentDialog),
53 myTagProperty(parentDialog->getApplicationWindow()->getTagPropertiesDatabase()->getTagProperty(tag, true)) {
54 // horizontal frame for buttons
55 FXHorizontalFrame* buttonFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
56 // create add button
57 myAddButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::ADD),
59 // add label with tag
60 myLabel = new FXLabel(buttonFrame, TLF("%s", myTagProperty->getTagStr()).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
61 // check if add sort button
63 mySortButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::RELOAD),
65 }
66 // create element table
67 myElementTable = new GNEElementTable(this, myTagProperty, options);
68}
69
70
72
73
74void
76 myLabel->enable();
77 myLabel->setText(TLF("%s", myTagProperty->getTagStr()).c_str());
78 myAddButton->enable();
79 if (mySortButton) {
80 mySortButton->enable();
81 }
82 myElementTable->enable();
83}
84
85
86void
87GNEElementList::disableList(const std::string& reason) {
88 myLabel->disable();
89 myLabel->setText(reason.c_str());
90 myAddButton->disable();
91 if (mySortButton) {
92 mySortButton->disable();
93 }
94 myElementTable->disable();
95}
96
97
98bool
102
103
108
109
110long
111GNEElementList::onCmdAddRow(FXObject*, FXSelector, void*) {
112 return addNewElement();
113}
114
115
116long
117GNEElementList::onCmdSort(FXObject*, FXSelector, void*) {
118 return sortRows();
119}
120
121
122void
124 // iterate over all children and delete it recursively
125 const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = additionalElement->getChildAdditionals();
126 for (const auto& additionalChild : additionalChildren) {
127 removeElementRecursively(additionalChild);
128 }
129 const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = additionalElement->getChildDemandElements();
130 for (const auto& demandChild : demandChildren) {
131 removeElementRecursively(demandChild);
132 }
133 // delete element
134 additionalElement->getNet()->getUndoList()->add(new GNEChange_Additional(additionalElement, false), true);
135}
136
137
138void
140 // iterate over all children and delete it recursively
141 const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = demandElement->getChildAdditionals();
142 for (const auto& additionalChild : additionalChildren) {
143 removeElementRecursively(additionalChild);
144 }
146 for (const auto& demandChild : demandChildren) {
147 removeElementRecursively(demandChild);
148 }
149 // delete element
150 demandElement->getNet()->getUndoList()->add(new GNEChange_DemandElement(demandElement, false), true);
151}
152
153/****************************************************************************/
FXDEFMAP(GNEElementList) GNEElementListMap[]
std::vector< ChildType > GNEHierarchicalContainerChildren
@ MID_GNE_ELEMENTLIST_SORT
sort elements in ElementList
@ MID_GNE_ELEMENTLIST_ADD
add element in ElementList
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:109
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:430
#define GUIDesignAuxiliarVerticalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:439
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:251
#define TLF(string,...)
Definition MsgHandler.h:306
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNENet * getNet() const
get pointer to net
~GNEElementList()
destructor
long onCmdAddRow(FXObject *sender, FXSelector, void *)
called when user press add button
virtual long sortRows()=0
open dialog
Options
FOX-declaration.
void disableList(const std::string &reason)
disable list
void enableList()
enable list
const GNETagProperties * myTagProperty
pointer to tag property
FXLabel * myLabel
label
virtual long addNewElement()=0
add element
GNEElementTable * myElementTable
element table
long onCmdSort(FXObject *sender, FXSelector, void *)
called when user press sort button
FXButton * mySortButton
sort button
GNEDialog * myDialogParent
FOX needs this.
bool isListValid() const
check if the current list is valid
FXButton * myAddButton
add button
void removeElementRecursively(GNEAdditional *additionalElement) const
delete additional element recursively
GNEDialog * getDialogParent()
pointer to dialog parent
bool isValid() const
check if the current values of the table are valid
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
GNEUndoList * getUndoList() const
get undo list(used for simplify code)
Definition GNENet.cpp:156
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
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