Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEFrameAttributeModules.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// Auxiliary class for GNEFrame Modules (only for attributes edition)
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
37
39#include "GNEFlowEditor.h"
40
41// ===========================================================================
42// FOX callback mapping
43// ===========================================================================
44
49
50// Object implementation
51FXIMPLEMENT(GNEFrameAttributeModules::GenericDataAttributes, MFXGroupBoxModule, GenericDataAttributesMap, ARRAYNUMBER(GenericDataAttributesMap))
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
56
57// ---------------------------------------------------------------------------
58// GNEFrameAttributeModules::GenericDataAttributes - methods
59// ---------------------------------------------------------------------------
60
62 MFXGroupBoxModule(frameParent, TL("Attributes")),
63 myFrameParent(frameParent) {
64 // create textfield and buttons
65 myTextFieldParameters = new FXTextField(getCollapsableFrame(), GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
66 myButtonEditParameters = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Edit attributes"), "", "", nullptr, this, MID_GNE_ATTRIBUTESEDITOR_PARAMETERS, GUIDesignButton);
67}
68
69
71
72
73void
75 // refresh GenericDataAttributes
76 refreshGenericDataAttributes();
77 // show groupbox
78 show();
79}
80
81
82void
87
88
89void
91 myTextFieldParameters->setText(getParametersStr().c_str());
92 myTextFieldParameters->setTextColor(FXRGB(0, 0, 0));
93 myTextFieldParameters->killFocus();
94}
95
96
101
102
103std::string
105 std::string result;
106 // Generate an string using the following structure: "key1=value1|key2=value2|...
107 for (const auto& parameter : myParameters) {
108 result += parameter.first + "=" + parameter.second + "|";
109 }
110 // remove the last "|"
111 if (!result.empty()) {
112 result.pop_back();
113 }
114 return result;
115}
116
117
118std::vector<std::pair<std::string, std::string> >
120 std::vector<std::pair<std::string, std::string> > result;
121 // Generate a vector string using the following structure: "<key1,value1>, <key2, value2>,...
122 for (const auto& parameter : myParameters) {
123 result.push_back(std::make_pair(parameter.first, parameter.second));
124 }
125 return result;
126}
127
128
129void
130GNEFrameAttributeModules::GenericDataAttributes::setParameters(const std::vector<std::pair<std::string, std::string> >& parameters) {
131 // declare result string
132 std::string result;
133 // Generate an string using the following structure: "key1=value1|key2=value2|...
134 for (const auto& parameter : parameters) {
135 result += parameter.first + "=" + parameter.second + "|";
136 }
137 // remove the last "|"
138 if (!result.empty()) {
139 result.pop_back();
140 }
141 // set result in textField (and call onCmdEditParameters)
142 myTextFieldParameters->setText(result.c_str(), TRUE);
143}
144
145
150
151
152bool
154 if (myTextFieldParameters->getText().empty()) {
155 return true;
156 } else if (myTextFieldParameters->getTextColor() == FXRGB(255, 0, 0)) {
157 return false;
158 } else {
159 return Parameterised::areAttributesValid(getParametersStr());
160 }
161}
162
163
164long
166 if (GNESingleParametersDialog(this).execute()) {
167 // Refresh parameter EditorCreator
168 refreshGenericDataAttributes();
169 }
170 return 1;
171}
172
173
174long
176 // clear current existent parameters
177 myParameters.clear();
178 // check if current given string is valid
179 if (Parameterised::areParametersValid(myTextFieldParameters->getText().text(), true)) {
180 // parsed parameters ok, then set text field black and continue
181 myTextFieldParameters->setTextColor(FXRGB(0, 0, 0));
182 myTextFieldParameters->killFocus();
183 // obtain parameters "key=value"
184 std::vector<std::string> parameters = StringTokenizer(myTextFieldParameters->getText().text(), "|", true).getVector();
185 // iterate over parameters
186 for (const auto& parameter : parameters) {
187 // obtain key, value
188 std::vector<std::string> keyParam = StringTokenizer(parameter, "=", true).getVector();
189 // save it in myParameters
190 myParameters[keyParam.front()] = keyParam.back();
191 }
192 // overwrite myTextFieldParameters (to remove duplicated parameters
193 myTextFieldParameters->setText(getParametersStr().c_str(), FALSE);
194 } else {
195 myTextFieldParameters->setTextColor(FXRGB(255, 0, 0));
196 }
197 return 1;
198}
199
200
201bool
203 const auto tagProperty = AC->getTagProperty();
204 if (viewNet->getEditModes().isCurrentSupermodeNetwork()) {
205 if (tagProperty->isNetworkElement() || tagProperty->isAdditionalElement()) {
206 return true;
207 } else if ((tagProperty->getTag() == SUMO_TAG_TAZSOURCE) || (tagProperty->getTag() == SUMO_TAG_TAZSINK)) {
208 return true;
209 } else {
210 return false;
211 }
212 } else if (viewNet->getEditModes().isCurrentSupermodeDemand() &&
213 tagProperty->isDemandElement()) {
214 return true;
215 } else if (viewNet->getEditModes().isCurrentSupermodeData() &&
216 (tagProperty->isDataElement() || tagProperty->isMeanData())) {
217 return true;
218 } else {
219 return false;
220 }
221}
222
223
224bool
226 if (attributeProperties->getTagPropertyParent()->isNetworkElement() || attributeProperties->getTagPropertyParent()->isAdditionalElement()) {
227 return (viewNet->getEditModes().isCurrentSupermodeNetwork());
228 } else if (attributeProperties->getTagPropertyParent()->isDemandElement()) {
229 return (viewNet->getEditModes().isCurrentSupermodeDemand());
230 } else if (attributeProperties->getTagPropertyParent()->isDataElement() || attributeProperties->getTagPropertyParent()->isMeanData()) {
231 return (viewNet->getEditModes().isCurrentSupermodeData());
232 } else {
233 return false;
234 }
235}
236
237/****************************************************************************/
FXDEFMAP(GNEFrameAttributeModules::GenericDataAttributes) GenericDataAttributesMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:939
@ MID_GNE_ATTRIBUTESEDITOR_PARAMETERS
open generic parameters editor
#define GUIDesignButton
Definition GUIDesigns.h:82
#define GUIDesignTextField
Definition GUIDesigns.h:59
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:74
#define TL(string)
Definition MsgHandler.h:301
@ SUMO_TAG_TAZSINK
a sink within a district (connection road)
@ SUMO_TAG_TAZSOURCE
a source within a district (connection road)
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
const GNETagProperties * getTagPropertyParent() const
get reference to tagProperty parent
long onCmdSetParameters(FXObject *, FXSelector, void *)
Called when user udpate the parameter text field.
bool areAttributesValid() const
check if current attributes are valid
const Parameterised::Map & getParametersMap() const
get parameters as map
void refreshGenericDataAttributes()
refresh netedit attributes
void showGenericDataAttributes()
show netedit attributes EditorCreator
long onCmdEditParameters(FXObject *, FXSelector, void *)
GNEFrame * getFrameParent() const
pointer to frame parent
std::vector< std::pair< std::string, std::string > > getParameters() const
get parameters as vector of strings
std::string getParametersStr() const
get parameters as string
void hideGenericDataAttributes()
hide netedit attributes EditorCreator
void setParameters(const std::vector< std::pair< std::string, std::string > > &parameters)
set parameters
static bool isSupermodeValid(const GNEViewNet *viewNet, const GNEAttributeCarrier *AC)
return true if AC can be edited in the current supermode
Dialog for edit parameters.
bool isMeanData() const
return true if tag correspond to a mean data element
bool isNetworkElement() const
element sets
bool isDataElement() const
return true if tag correspond to a data element
bool isDemandElement() const
return true if tag correspond to a demand element
bool isAdditionalElement() const
return true if tag correspond to an additional element (note: this include TAZ, shapes and wires)
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
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
MFXGroupBoxModule (based on FXGroupBox)
static bool areAttributesValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to an attributes map "key1=value1|key2=value2|....
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
std::vector< std::string > getVector()
return vector of strings
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand
bool isCurrentSupermodeData() const
@check if current supermode is Data
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network