Eclipse SUMO - Simulation of Urban MObility
GNEAttributesCreator.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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
21#include <netedit/GNEViewNet.h>
25
28#include "GNEFlowEditor.h"
29
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
35FXDEFMAP(GNEAttributesCreator) AttributesCreatorMap[] = {
36 FXMAPFUNC(SEL_COMMAND, MID_GNE_RESET, GNEAttributesCreator::onCmdReset),
37 FXMAPFUNC(SEL_COMMAND, MID_HELP, GNEAttributesCreator::onCmdHelp),
38};
39
40// Object implementation
41FXIMPLEMENT(GNEAttributesCreator, MFXGroupBoxModule, AttributesCreatorMap, ARRAYNUMBER(AttributesCreatorMap))
42
43
44// ===========================================================================
45// method definitions
46// ===========================================================================
47
49 MFXGroupBoxModule(frameParent, TL("Internal attributes")),
50 myFrameParent(frameParent),
51 myTemplateAC(nullptr) {
52 // resize myAttributesCreatorRows
53 myAttributesCreatorRows.resize(GNEAttributeCarrier::MAXNUMBEROFATTRIBUTES, nullptr);
54 // create myFlowEditor
55 myFlowEditor = new GNEFlowEditor(frameParent->getViewNet(), frameParent);
56 // create reset and help button
57 myFrameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
58 myResetButton = new FXButton(myFrameButtons, "", GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_RESET, GUIDesignButtonIcon);
59 new FXButton(myFrameButtons, TL("Help"), nullptr, this, MID_HELP, GUIDesignButtonRectangular);
60}
61
62
64
65
66void
67GNEAttributesCreator::showAttributesCreatorModule(GNEAttributeCarrier* templateAC, const std::vector<SumoXMLAttr>& hiddenAttributes) {
68 // destroy all rows
69 for (auto& row : myAttributesCreatorRows) {
70 // destroy and delete all rows
71 if (row != nullptr) {
72 row->destroy();
73 delete row;
74 row = nullptr;
75 }
76 }
77 if (templateAC) {
78 // set current template AC and hidden attributes
79 myTemplateAC = templateAC;
80 myHiddenAttributes = hiddenAttributes;
81 // refresh rows (new rows will be created)
82 refreshRows(true);
83 // enable reset
84 myResetButton->enable();
85 // show
86 show();
87 } else {
88 throw ProcessError("invalid templateAC in showAttributesCreatorModule");
89 }
90}
91
92
93void
95 // hide attributes creator flow
97 // hide modul
98 hide();
99}
100
101
104 return myFrameParent;
105}
106
107
108void
110 // get standard parameters
111 for (const auto& row : myAttributesCreatorRows) {
112 if (row && row->getAttrProperties().getAttr() != SUMO_ATTR_NOTHING) {
113 const auto& attrProperties = row->getAttrProperties();
114 // flag for row enabled
115 const bool rowEnabled = row->isAttributesCreatorRowEnabled();
116 // flag for default attributes
117 const bool hasDefaultStaticValue = !attrProperties.hasDefaultValue() || (attrProperties.getDefaultValue() != row->getValue());
118 // flag for enablitables attributes
119 const bool isFlowDefinitionAttribute = attrProperties.isFlowDefinition();
120 // flag for Terminatel attributes
121 const bool isActivatableAttribute = attrProperties.isActivatable() && row->getAttributeCheckButtonCheck();
122 // check if flags configuration allow to include values
123 if (rowEnabled && (includeAll || hasDefaultStaticValue || isFlowDefinitionAttribute || isActivatableAttribute)) {
124 // add attribute depending of type
125 if (attrProperties.isInt()) {
126 const int intValue = GNEAttributeCarrier::canParse<int>(row->getValue()) ? GNEAttributeCarrier::parse<int>(row->getValue()) : GNEAttributeCarrier::parse<int>(attrProperties.getDefaultValue());
127 baseObject->addIntAttribute(attrProperties.getAttr(), intValue);
128 } else if (attrProperties.isFloat()) {
129 const double doubleValue = GNEAttributeCarrier::canParse<double>(row->getValue()) ? GNEAttributeCarrier::parse<double>(row->getValue()) : GNEAttributeCarrier::parse<double>(attrProperties.getDefaultValue());
130 baseObject->addDoubleAttribute(attrProperties.getAttr(), doubleValue);
131 } else if (attrProperties.isBool()) {
132 const bool boolValue = GNEAttributeCarrier::canParse<bool>(row->getValue()) ? GNEAttributeCarrier::parse<bool>(row->getValue()) : GNEAttributeCarrier::parse<bool>(attrProperties.getDefaultValue());
133 baseObject->addBoolAttribute(attrProperties.getAttr(), boolValue);
134 } else if (attrProperties.isposition()) {
135 const Position positionValue = GNEAttributeCarrier::canParse<Position>(row->getValue()) ? GNEAttributeCarrier::parse<Position>(row->getValue()) : GNEAttributeCarrier::parse<Position>(attrProperties.getDefaultValue());
136 baseObject->addPositionAttribute(attrProperties.getAttr(), positionValue);
137 } else if (attrProperties.isSUMOTime()) {
138 const SUMOTime timeValue = GNEAttributeCarrier::canParse<SUMOTime>(row->getValue()) ? GNEAttributeCarrier::parse<SUMOTime>(row->getValue()) : GNEAttributeCarrier::parse<SUMOTime>(attrProperties.getDefaultValue());
139 baseObject->addTimeAttribute(attrProperties.getAttr(), timeValue);
140 } else if (attrProperties.isColor()) {
141 const RGBColor colorValue = GNEAttributeCarrier::canParse<RGBColor>(row->getValue()) ? GNEAttributeCarrier::parse<RGBColor>(row->getValue()) : GNEAttributeCarrier::parse<RGBColor>(attrProperties.getDefaultValue());
142 baseObject->addColorAttribute(attrProperties.getAttr(), colorValue);
143 } else if (attrProperties.isList()) {
144 if (attrProperties.isposition()) {
145 const PositionVector positionVectorValue = GNEAttributeCarrier::canParse<PositionVector>(row->getValue()) ? GNEAttributeCarrier::parse<PositionVector>(row->getValue()) : GNEAttributeCarrier::parse<PositionVector>(attrProperties.getDefaultValue());
146 baseObject->addPositionVectorAttribute(attrProperties.getAttr(), positionVectorValue);
147 } else {
148 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());
149 baseObject->addStringListAttribute(attrProperties.getAttr(), stringVectorValue);
150 }
151 } else {
152 baseObject->addStringAttribute(attrProperties.getAttr(), row->getValue());
153 }
154 }
155 }
156 }
157 // add extra flow attributes (only will updated if myFlowEditor is shown)
159 myFlowEditor->getFlowAttributes(baseObject);
160 }
161}
162
163
166 return myTemplateAC;
167}
168
169
170void
172 std::string errorMessage;
173 // show warning box if input parameters aren't invalid
174 if (extra.size() == 0) {
175 errorMessage = "Invalid input parameter of " + myTemplateAC->getTagProperty().getTagStr();
176 } else {
177 errorMessage = "Invalid input parameter of " + myTemplateAC->getTagProperty().getTagStr() + ": " + extra;
178 }
179 // set message in status bar
180 myFrameParent->getViewNet()->setStatusBarText(errorMessage);
181 // Write Warning in console if we're in testing mode
182 WRITE_DEBUG(errorMessage);
183}
184
185
186void
188 // just refresh row without creating new rows
189 if (shown() && myTemplateAC) {
190 refreshRows(false);
191 }
192}
193
194
195void
197 // disable all rows
198 for (const auto& row : myAttributesCreatorRows) {
199 if (row) {
200 row->disableRow();
201 }
202 }
203 // also disable reset
204 myResetButton->disable();
205}
206
207
208bool
210 // iterate over standar parameters
211 for (const auto& attribute : myTemplateAC->getTagProperty()) {
212 // Return false if error message of attriuve isn't empty
213 if (myAttributesCreatorRows.at(attribute.getPositionListed()) && !myAttributesCreatorRows.at(attribute.getPositionListed())->isAttributeValid()) {
214 return false;
215 }
216 }
217 // check flow attributes
220 }
221 return true;
222}
223
224
225long
226GNEAttributesCreator::onCmdReset(FXObject*, FXSelector, void*) {
227 if (myTemplateAC) {
229 refreshRows(false);
230 }
231 return 1;
232}
233
234
235long
236GNEAttributesCreator::onCmdHelp(FXObject*, FXSelector, void*) {
237 // open Help attributes dialog
239 return 1;
240}
241
242
243void
244GNEAttributesCreator::refreshRows(const bool createRows) {
245 // declare a flag to show Flow editor
246 bool showFlowEditor = false;
247 // iterate over tag attributes and create AttributesCreatorRows for every attribute
248 for (const auto& attribute : myTemplateAC->getTagProperty()) {
249 // declare falg to check conditions for show attribute
250 bool showAttribute = true;
251 // check that only non-unique attributes (except ID) are created (And depending of includeExtendedAttributes)
252 if (attribute.isUnique() && (attribute.getAttr() != SUMO_ATTR_ID)) {
253 showAttribute = false;
254 }
255 // check if attribute must stay hidden
256 if (std::find(myHiddenAttributes.begin(), myHiddenAttributes.end(), attribute.getAttr()) != myHiddenAttributes.end()) {
257 showAttribute = false;
258 }
259 // check if attribute is a flow definitionattribute
260 if (attribute.isFlowDefinition()) {
261 showAttribute = false;
262 showFlowEditor = true;
263 }
264 // check special case for vaporizer IDs
265 if ((attribute.getAttr() == SUMO_ATTR_ID) && (attribute.getTagPropertyParent().getTag() == SUMO_TAG_VAPORIZER)) {
266 showAttribute = false;
267 }
268 // check special case for VType IDs in vehicle and person Frame
269 if ((attribute.getAttr() == SUMO_ATTR_TYPE) && (myFrameParent->getViewNet()->getEditModes().isCurrentSupermodeDemand()) &&
273 showAttribute = false;
274 }
275 // show attribute depending of showAttribute flag
276 if (showAttribute) {
277 // check if we have to create a new row
278 if (createRows) {
279 myAttributesCreatorRows.at(attribute.getPositionListed()) = new GNEAttributesCreatorRow(this, attribute);
280 } else {
281 myAttributesCreatorRows.at(attribute.getPositionListed())->refreshRow();
282 }
283 }
284 }
285 // reparent help button (to place it at bottom)
287 // recalc
288 recalc();
289 // check if flow editor has to be shown
290 if (showFlowEditor) {
292 } else {
294 }
295}
296
297/****************************************************************************/
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:641
@ MID_GNE_RESET
reset element
Definition: GUIAppEnum.h:878
#define GUIDesignButtonIcon
button only with icon
Definition: GUIDesigns.h:86
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:397
#define GUIDesignButtonRectangular
little button rectangula used in frames (For example, in "help" buttons)
Definition: GUIDesigns.h:83
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:276
#define TL(string)
Definition: MsgHandler.h:282
@ SUMO_TAG_VAPORIZER
vaporizer of vehicles
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_NOTHING
invalid attribute
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)
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
Definition: GNEViewNet.cpp:632
void setStatusBarText(const std::string &text)
set statusBar text
Definition: GNEViewNet.cpp:768
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