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(FXVerticalFrame* contentFrame, const GNETagProperties* tagProperty, GNEElementList::Options options) :
51 FXVerticalFrame(contentFrame, GUIDesignAuxiliarVerticalFrame),
52 myTagProperty(tagProperty) {
53 // horizontal frame for buttons
54 FXHorizontalFrame* buttonFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
55 // create add button
56 myAddButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::ADD),
58 // add label with tag
59 myLabel = new FXLabel(buttonFrame, TLF("%s", myTagProperty->getTagStr()).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
60 // check if add sort button
62 mySortButton = GUIDesigns::buildFXButton(buttonFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::RELOAD),
64 }
65 // create element table
66 myElementTable = new GNEElementTable(this, myTagProperty, options);
67}
68
69
71
72
73void
75 myLabel->enable();
76 myLabel->setText(TLF("%s", myTagProperty->getTagStr()).c_str());
77 myAddButton->enable();
78 mySortButton->enable();
79 myElementTable->enable();
80}
81
82
83void
84GNEElementList::disableList(const std::string& reason) {
85 myLabel->disable();
86 myLabel->setText(reason.c_str());
87 myAddButton->disable();
88 mySortButton->disable();
89 myElementTable->disable();
90}
91
92
93bool
97
98
99long
100GNEElementList::onCmdAddRow(FXObject*, FXSelector, void*) {
101 return addNewElement();
102}
103
104
105long
106GNEElementList::onCmdSort(FXObject*, FXSelector, void*) {
107 return sortRows();
108}
109
110
111void
113 // iterate over all children and delete it recursively
114 const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = additionalElement->getChildAdditionals();
115 for (const auto& additionalChild : additionalChildren) {
116 removeElementRecursively(additionalChild);
117 }
118 const GNEHierarchicalContainerChildren<GNEDemandElement*> demandChildren = additionalElement->getChildDemandElements();
119 for (const auto& demandChild : demandChildren) {
120 removeElementRecursively(demandChild);
121 }
122 // delete element
123 additionalElement->getNet()->getViewNet()->getUndoList()->add(new GNEChange_Additional(additionalElement, false), true);
124}
125
126
127void
129 // iterate over all children and delete it recursively
130 const GNEHierarchicalContainerChildren<GNEAdditional*> additionalChildren = demandElement->getChildAdditionals();
131 for (const auto& additionalChild : additionalChildren) {
132 removeElementRecursively(additionalChild);
133 }
135 for (const auto& demandChild : demandChildren) {
136 removeElementRecursively(demandChild);
137 }
138 // delete element
139 demandElement->getNet()->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(demandElement, false), true);
140}
141
142/****************************************************************************/
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:307
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
FOX needs this.
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
bool isListValid() const
check if the current list is valid
FXButton * myAddButton
add button
void removeElementRecursively(GNEAdditional *additionalElement) const
delete additional element recursively
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
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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...
GNEUndoList * getUndoList() const
get the undoList object
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