Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAttributesCreator.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// Attribute creator
19/****************************************************************************/
20
22#include <netedit/GNEViewNet.h>
26
29#include "GNEFlowEditor.h"
30
31
32// ===========================================================================
33// FOX callback mapping
34// ===========================================================================
35
36FXDEFMAP(GNEAttributesCreator) AttributesCreatorMap[] = {
37 FXMAPFUNC(SEL_COMMAND, MID_GNE_RESET, GNEAttributesCreator::onCmdReset),
38 FXMAPFUNC(SEL_COMMAND, MID_HELP, GNEAttributesCreator::onCmdHelp),
39};
40
41// Object implementation
42FXIMPLEMENT(GNEAttributesCreator, MFXGroupBoxModule, AttributesCreatorMap, ARRAYNUMBER(AttributesCreatorMap))
43
44
45// ===========================================================================
46// method definitions
47// ===========================================================================
48
50 MFXGroupBoxModule(frameParent, TL("Internal attributes")),
51 myFrameParent(frameParent),
52 myTemplateAC(nullptr) {
53 // resize myAttributesCreatorRows
54 myAttributesCreatorRows.resize(GNEAttributeCarrier::MAXNUMBEROFATTRIBUTES, nullptr);
55 // create myFlowEditor
56 myFlowEditor = new GNEFlowEditor(frameParent->getViewNet(), frameParent);
57 // create reset and help button
58 myFrameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
59 myResetButton = GUIDesigns::buildFXButton(myFrameButtons, "", "", "", GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_RESET, GUIDesignButtonIcon);
60 GUIDesigns::buildFXButton(myFrameButtons, TL("Help"), "", "", nullptr, this, MID_HELP, GUIDesignButtonRectangular);
61}
62
63
65
66
67void
68GNEAttributesCreator::showAttributesCreatorModule(GNEAttributeCarrier* templateAC, const std::vector<SumoXMLAttr>& hiddenAttributes) {
69 // destroy all rows
70 for (auto& row : myAttributesCreatorRows) {
71 // destroy and delete all rows
72 if (row != nullptr) {
73 row->destroy();
74 delete row;
75 row = nullptr;
76 }
77 }
78 if (templateAC) {
79 // set current template AC and hidden attributes
80 myTemplateAC = templateAC;
81 myHiddenAttributes = hiddenAttributes;
82 // refresh rows (new rows will be created)
83 refreshRows(true);
84 // enable reset
85 myResetButton->enable();
86 // show
87 show();
88 } else {
89 throw ProcessError("invalid templateAC in showAttributesCreatorModule");
90 }
91}
92
93
94void
96 // hide attributes creator flow
98 // hide modul
99 hide();
100}
101
102
107
108
109void
111 // get standard parameters
112 for (const auto& row : myAttributesCreatorRows) {
113 if (row && row->getAttrProperties().getAttr() != SUMO_ATTR_NOTHING) {
114 const auto& attrProperties = row->getAttrProperties();
115 // flag for row enabled
116 const bool rowEnabled = row->isAttributesCreatorRowEnabled();
117 // flag for default attributes
118 const bool hasDefaultStaticValue = !attrProperties.hasDefaultValue() || (attrProperties.getDefaultValue() != row->getValue());
119 // flag for enablitables attributes
120 const bool isFlowDefinitionAttribute = attrProperties.isFlowDefinition();
121 // flag for Terminatel attributes
122 const bool isActivatableAttribute = attrProperties.isActivatable() && row->getAttributeCheckButtonCheck();
123 // check if flags configuration allow to include values
124 if (rowEnabled && (includeAll || hasDefaultStaticValue || isFlowDefinitionAttribute || isActivatableAttribute)) {
125 // add attribute depending of type
126 if (attrProperties.isInt()) {
127 const int intValue = GNEAttributeCarrier::canParse<int>(row->getValue()) ? GNEAttributeCarrier::parse<int>(row->getValue()) : GNEAttributeCarrier::parse<int>(attrProperties.getDefaultValue());
128 baseObject->addIntAttribute(attrProperties.getAttr(), intValue);
129 } else if (attrProperties.isFloat()) {
130 const double doubleValue = GNEAttributeCarrier::canParse<double>(row->getValue()) ? GNEAttributeCarrier::parse<double>(row->getValue()) : GNEAttributeCarrier::parse<double>(attrProperties.getDefaultValue());
131 baseObject->addDoubleAttribute(attrProperties.getAttr(), doubleValue);
132 } else if (attrProperties.isBool()) {
133 const bool boolValue = GNEAttributeCarrier::canParse<bool>(row->getValue()) ? GNEAttributeCarrier::parse<bool>(row->getValue()) : GNEAttributeCarrier::parse<bool>(attrProperties.getDefaultValue());
134 baseObject->addBoolAttribute(attrProperties.getAttr(), boolValue);
135 } else if (attrProperties.isPosition()) {
136 const Position positionValue = GNEAttributeCarrier::canParse<Position>(row->getValue()) ? GNEAttributeCarrier::parse<Position>(row->getValue()) : GNEAttributeCarrier::parse<Position>(attrProperties.getDefaultValue());
137 baseObject->addPositionAttribute(attrProperties.getAttr(), positionValue);
138 } else if (attrProperties.isSUMOTime()) {
139 const SUMOTime timeValue = GNEAttributeCarrier::canParse<SUMOTime>(row->getValue()) ? GNEAttributeCarrier::parse<SUMOTime>(row->getValue()) : GNEAttributeCarrier::parse<SUMOTime>(attrProperties.getDefaultValue());
140 baseObject->addTimeAttribute(attrProperties.getAttr(), timeValue);
141 } else if (attrProperties.isColor()) {
142 const RGBColor colorValue = GNEAttributeCarrier::canParse<RGBColor>(row->getValue()) ? GNEAttributeCarrier::parse<RGBColor>(row->getValue()) : GNEAttributeCarrier::parse<RGBColor>(attrProperties.getDefaultValue());
143 baseObject->addColorAttribute(attrProperties.getAttr(), colorValue);
144 } else if (attrProperties.isList()) {
145 if (attrProperties.isPosition()) {
146 const PositionVector positionVectorValue = GNEAttributeCarrier::canParse<PositionVector>(row->getValue()) ? GNEAttributeCarrier::parse<PositionVector>(row->getValue()) : GNEAttributeCarrier::parse<PositionVector>(attrProperties.getDefaultValue());
147 baseObject->addPositionVectorAttribute(attrProperties.getAttr(), positionVectorValue);
148 } else {
149 const std::vector<std::string> stringVectorValue = GNEAttributeCarrier::canParse<std::vector<std::string> >(row->getValue()) ? GNEAttributeCarrier::parse<std::vector<std::string> >(row->getValue()) : GNEAttributeCarrier::parse<std::vector<std::string> >(attrProperties.getDefaultValue());
150 baseObject->addStringListAttribute(attrProperties.getAttr(), stringVectorValue);
151 }
152 } else {
153 baseObject->addStringAttribute(attrProperties.getAttr(), row->getValue());
154 }
155 }
156 }
157 }
158 // add extra flow attributes (only will updated if myFlowEditor is shown)
160 myFlowEditor->getFlowAttributes(baseObject);
161 }
162}
163
164
169
170
171void
173 std::string errorMessage;
174 // show warning box if input parameters aren't invalid
175 if (extra.size() == 0) {
176 errorMessage = TL("Invalid input parameter of ") + myTemplateAC->getTagProperty().getTagStr();
177 } else {
178 errorMessage = TL("Invalid input parameter of ") + myTemplateAC->getTagProperty().getTagStr() + ": " + extra;
179 }
180 // set message in status bar
181 myFrameParent->getViewNet()->setStatusBarText(errorMessage);
182 // Write Warning in console if we're in testing mode
183 WRITE_DEBUG(errorMessage);
184}
185
186
187void
189 // just refresh row without creating new rows
190 if (shown() && myTemplateAC) {
191 refreshRows(false);
192 }
193}
194
195
196void
198 // disable all rows
199 for (const auto& row : myAttributesCreatorRows) {
200 if (row) {
201 row->disableRow();
202 }
203 }
204 // also disable reset
205 myResetButton->disable();
206}
207
208
209bool
211 // iterate over standar parameters
212 for (const auto& attribute : myTemplateAC->getTagProperty()) {
213 // Return false if error message of attriuve isn't empty
214 if (myAttributesCreatorRows.at(attribute.getPositionListed()) && !myAttributesCreatorRows.at(attribute.getPositionListed())->isAttributeValid()) {
215 return false;
216 }
217 }
218 // check flow attributes
221 }
222 return true;
223}
224
225
226long
227GNEAttributesCreator::onCmdReset(FXObject*, FXSelector, void*) {
228 if (myTemplateAC) {
230 refreshRows(false);
231 }
232 return 1;
233}
234
235
236long
237GNEAttributesCreator::onCmdHelp(FXObject*, FXSelector, void*) {
238 // open Help attributes dialog
240 return 1;
241}
242
243
244void
245GNEAttributesCreator::refreshRows(const bool createRows) {
246 // declare a flag to show Flow editor
247 bool showFlowEditor = false;
248 // iterate over tag attributes and create AttributesCreatorRows for every attribute
249 for (const auto& attribute : myTemplateAC->getTagProperty()) {
250 // declare falg to check conditions for show attribute
251 bool showAttribute = true;
252 // check that only non-unique attributes (except ID) are created (And depending of includeExtendedAttributes)
253 if (attribute.isUnique() && (attribute.getAttr() != SUMO_ATTR_ID)) {
254 showAttribute = false;
255 }
256 // check if attribute must stay hidden
257 if (std::find(myHiddenAttributes.begin(), myHiddenAttributes.end(), attribute.getAttr()) != myHiddenAttributes.end()) {
258 showAttribute = false;
259 }
260 // check if attribute is a flow definitionattribute
261 if (attribute.isFlowDefinition()) {
262 showAttribute = false;
263 showFlowEditor = true;
264 }
265 // check special case for vaporizer IDs
266 if ((attribute.getAttr() == SUMO_ATTR_ID) && (attribute.getTagPropertyParent().getTag() == SUMO_TAG_VAPORIZER)) {
267 showAttribute = false;
268 }
269 // check special case for VType IDs in vehicle and person Frame
270 if ((attribute.getAttr() == SUMO_ATTR_TYPE) && (myFrameParent->getViewNet()->getEditModes().isCurrentSupermodeDemand()) &&
274 showAttribute = false;
275 }
276 // show attribute depending of showAttribute flag
277 if (showAttribute) {
278 // check if we have to create a new row
279 if (createRows) {
280 myAttributesCreatorRows.at(attribute.getPositionListed()) = new GNEAttributesCreatorRow(this, attribute);
281 } else {
282 myAttributesCreatorRows.at(attribute.getPositionListed())->refreshRow();
283 }
284 }
285 }
286 // reparent help button (to place it at bottom)
288 // recalc
289 recalc();
290 // check if flow editor has to be shown
291 if (showFlowEditor) {
293 } else {
295 }
296}
297
298/****************************************************************************/
FXDEFMAP(GNEAttributesCreator) AttributesCreatorMap[]
@ DEMAND_CONTAINER
Mode for editing container.
@ DEMAND_PERSON
Mode for editing person.
@ DEMAND_VEHICLE
Mode for editing vehicles.
long long int SUMOTime
Definition GUI.h:36
@ MID_HELP
help button
Definition GUIAppEnum.h:653
@ MID_GNE_RESET
reset element
Definition GUIAppEnum.h:947
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:97
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:405
#define GUIDesignButtonRectangular
little rectangular button used in frames (For example, in "help" buttons)
Definition GUIDesigns.h:100
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
@ SUMO_TAG_VAPORIZER
vaporizer of vehicles
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_NOTHING
invalid attribute, must be the last one
void addIntAttribute(const SumoXMLAttr attr, const int value)
add int attribute into current SumoBaseObject node
void addPositionVectorAttribute(const SumoXMLAttr attr, const PositionVector &value)
add PositionVector attribute into current SumoBaseObject node
void addBoolAttribute(const SumoXMLAttr attr, const bool value)
add bool attribute into current SumoBaseObject node
void addTimeAttribute(const SumoXMLAttr attr, const SUMOTime value)
add time attribute into current SumoBaseObject node
void addStringListAttribute(const SumoXMLAttr attr, const std::vector< std::string > &value)
add string list attribute into current SumoBaseObject node
void addDoubleAttribute(const SumoXMLAttr attr, const double value)
add double attribute into current SumoBaseObject node
void addPositionAttribute(const SumoXMLAttr attr, const Position &value)
add Position attribute into current SumoBaseObject node
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
add string attribute into current SumoBaseObject node
void addColorAttribute(const SumoXMLAttr attr, const RGBColor &value)
add color attribute into current SumoBaseObject node
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void resetDefaultValues()
reset attribute carrier to their default values
static const size_t MAXNUMBEROFATTRIBUTES
max number of attributes allowed for every tag
void refreshRows(const bool createRows)
refresh rows
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
bool areValuesValid() const
check if parameters of attributes are valid
GNEAttributeCarrier * getCurrentTemplateAC() const
get current template AC
void showAttributesCreatorModule(GNEAttributeCarrier *templateAC, const std::vector< SumoXMLAttr > &hiddenAttributes)
show GNEAttributesCreator modul
GNEAttributeCarrier * myTemplateAC
current templateAC
FXHorizontalFrame * myFrameButtons
frame buttons
long onCmdReset(FXObject *, FXSelector, void *)
void hideAttributesCreatorModule()
hide group box
void showWarningMessage(std::string extra="") const
show warning message with information about non-valid attributes
std::vector< GNEAttributesCreatorRow * > myAttributesCreatorRows
vector with the GNEAttributesCreatorRow
void disableAttributesCreator()
disable GNEAttributesCreator
GNEFlowEditor * myFlowEditor
pointer to myFlowEditor
GNEFrame * getFrameParent() const
return frame parent
void refreshAttributesCreator()
refresh attribute creator
FXButton * myResetButton
reset button
long onCmdHelp(FXObject *, FXSelector, void *)
Called when help button is pressed.
GNEFrame * myFrameParent
pointer to Frame Parent
std::vector< SumoXMLAttr > myHiddenAttributes
hidden attributes
void getFlowAttributes(CommonXMLStructure::SumoBaseObject *baseObject)
get flow attributes
void hideFlowEditor()
hide group box
void showFlowEditor(const std::vector< GNEAttributeCarrier * > editedFlows)
show GNEFlowEditor modul
bool shownFlowEditor() const
shown GNEFlowEditor modul
bool areFlowValuesValid() const
check if parameters of attributes are valid
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
void openHelpAttributesDialog(const GNEAttributeCarrier *AC) const
Open help attributes dialog.
Definition GNEFrame.cpp:184
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
void setStatusBarText(const std::string &text)
set statusBar text
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)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
DemandEditMode demandEditMode
the current Demand edit mode
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand