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-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// Auxiliary class for GNEFrame Modules (only for attributes edition)
19/****************************************************************************/
20#include <config.h>
21
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
37
39#include "GNEFlowEditor.h"
40
41
42// ===========================================================================
43// FOX callback mapping
44// ===========================================================================
45
50
55
56// Object implementation
57FXIMPLEMENT(GNEFrameAttributeModules::GenericDataAttributes, MFXGroupBoxModule, GenericDataAttributesMap, ARRAYNUMBER(GenericDataAttributesMap))
58FXIMPLEMENT(GNEFrameAttributeModules::ParametersEditor, MFXGroupBoxModule, ParametersEditorMap, ARRAYNUMBER(ParametersEditorMap))
59
60// ===========================================================================
61// method definitions
62// ===========================================================================
63
64// ---------------------------------------------------------------------------
65// GNEFrameAttributeModules::GenericDataAttributes - methods
66// ---------------------------------------------------------------------------
67
69 MFXGroupBoxModule(frameParent, TL("Attributes")),
70 myFrameParent(frameParent) {
71 // create textfield and buttons
72 myTextFieldParameters = new FXTextField(getCollapsableFrame(), GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
73 myButtonEditParameters = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Edit attributes"), "", "", nullptr, this, MID_GNE_OPEN_PARAMETERS_DIALOG, GUIDesignButton);
74}
75
76
78
79
80void
82 // refresh GenericDataAttributes
83 refreshGenericDataAttributes();
84 // show groupbox
85 show();
86}
87
88
89void
94
95
96void
98 myTextFieldParameters->setText(getParametersStr().c_str());
99 myTextFieldParameters->setTextColor(FXRGB(0, 0, 0));
100 myTextFieldParameters->killFocus();
101}
102
103
108
109
110std::string
112 std::string result;
113 // Generate an string using the following structure: "key1=value1|key2=value2|...
114 for (const auto& parameter : myParameters) {
115 result += parameter.first + "=" + parameter.second + "|";
116 }
117 // remove the last "|"
118 if (!result.empty()) {
119 result.pop_back();
120 }
121 return result;
122}
123
124
125std::vector<std::pair<std::string, std::string> >
127 std::vector<std::pair<std::string, std::string> > result;
128 // Generate a vector string using the following structure: "<key1,value1>, <key2, value2>,...
129 for (const auto& parameter : myParameters) {
130 result.push_back(std::make_pair(parameter.first, parameter.second));
131 }
132 return result;
133}
134
135
136void
137GNEFrameAttributeModules::GenericDataAttributes::setParameters(const std::vector<std::pair<std::string, std::string> >& parameters) {
138 // declare result string
139 std::string result;
140 // Generate an string using the following structure: "key1=value1|key2=value2|...
141 for (const auto& parameter : parameters) {
142 result += parameter.first + "=" + parameter.second + "|";
143 }
144 // remove the last "|"
145 if (!result.empty()) {
146 result.pop_back();
147 }
148 // set result in textField (and call onCmdEditParameters)
149 myTextFieldParameters->setText(result.c_str(), TRUE);
150}
151
152
157
158
159bool
161 if (myTextFieldParameters->getText().empty()) {
162 return true;
163 } else if (myTextFieldParameters->getTextColor() == FXRGB(255, 0, 0)) {
164 return false;
165 } else {
166 return Parameterised::areAttributesValid(getParametersStr());
167 }
168}
169
170
171long
173 // write debug information
174 WRITE_DEBUG("Open single parameters dialog");
175 if (GNESingleParametersDialog(this).execute()) {
176 // write debug information
177 WRITE_DEBUG("Close single parameters dialog");
178 // Refresh parameter EditorCreator
179 refreshGenericDataAttributes();
180 } else {
181 // write debug information
182 WRITE_DEBUG("Cancel single parameters dialog");
183 }
184 return 1;
185}
186
187
188long
190 // clear current existent parameters
191 myParameters.clear();
192 // check if current given string is valid
193 if (Parameterised::areParametersValid(myTextFieldParameters->getText().text(), true)) {
194 // parsed parameters ok, then set text field black and continue
195 myTextFieldParameters->setTextColor(FXRGB(0, 0, 0));
196 myTextFieldParameters->killFocus();
197 // obtain parameters "key=value"
198 std::vector<std::string> parameters = StringTokenizer(myTextFieldParameters->getText().text(), "|", true).getVector();
199 // iterate over parameters
200 for (const auto& parameter : parameters) {
201 // obtain key, value
202 std::vector<std::string> keyParam = StringTokenizer(parameter, "=", true).getVector();
203 // save it in myParameters
204 myParameters[keyParam.front()] = keyParam.back();
205 }
206 // overwrite myTextFieldParameters (to remove duplicated parameters
207 myTextFieldParameters->setText(getParametersStr().c_str(), FALSE);
208 } else {
209 myTextFieldParameters->setTextColor(FXRGB(255, 0, 0));
210 }
211 return 1;
212}
213
214// ---------------------------------------------------------------------------
215// GNEFrameAttributeModules::ParametersEditor - methods
216// ---------------------------------------------------------------------------
217
219 MFXGroupBoxModule(inspectorFrameParent, TL("Parameters")),
220 myInspectorFrameParent(inspectorFrameParent) {
221 // create textfield and buttons
224}
225
226
228 MFXGroupBoxModule(typeFrameParent, TL("Parameters")),
229 myTypeFrameParent(typeFrameParent) {
230 // create textfield and buttons
233}
234
235
237
238
241 return myInspectorFrameParent ? myInspectorFrameParent->getViewNet() : myTypeFrameParent->getViewNet();
242}
243
244
245void
247 if (myInspectorFrameParent) {
248 const auto& inspectedElements = myInspectorFrameParent->getViewNet()->getInspectedElements();
249 if (inspectedElements.getFirstAC() && inspectedElements.getFirstAC()->getTagProperty().hasParameters()) {
250 // refresh ParametersEditor
251 refreshParametersEditor();
252 // show groupbox
253 show();
254 } else {
255 hideParametersEditor();
256 }
257 } else if (myTypeFrameParent) {
258 if (myTypeFrameParent->getTypeSelector()->getCurrentType() != nullptr) {
260 refreshParametersEditor();
261 // show groupbox
262 show();
263 } else {
264 hideParametersEditor();
265 }
266 } else {
267 hideParametersEditor();
268 }
269}
270
271
272void
277
278
279void
281 if (myInspectorFrameParent) {
282 const auto& inspectedElements = myInspectorFrameParent->getViewNet()->getInspectedElements();
283 // continue depending of markAC
284 if (inspectedElements.getFirstAC() && inspectedElements.getFirstAC()->getTagProperty().hasParameters()) {
285 // check if we're editing a single or a multiple AC
286 if (inspectedElements.isInspectingSingleElement()) {
287 // set text field parameters
288 myTextFieldParameters->setText(inspectedElements.getFirstAC()->getAttribute(GNE_ATTR_PARAMETERS).c_str());
289 } else {
290 // check if parameters of all inspected ACs are different
291 std::string parameters = inspectedElements.getFirstAC()->getAttribute(GNE_ATTR_PARAMETERS);
292 for (const auto& AC : inspectedElements.getACs()) {
293 if (parameters != AC->getAttribute(GNE_ATTR_PARAMETERS)) {
294 parameters = "different parameters";
295 }
296 }
297 // set text field
298 myTextFieldParameters->setText(parameters.c_str());
299 }
300 // reset color
301 myTextFieldParameters->setTextColor(FXRGB(0, 0, 0));
302 // disable myTextFieldParameters if Tag correspond to an network element but we're in demand mode (or vice versa), disable all elements
303 if (GNEFrameAttributeModules::isSupermodeValid(myInspectorFrameParent->getViewNet(), inspectedElements.getFirstAC())) {
304 myTextFieldParameters->enable();
305 myButtonEditParameters->enable();
306 } else {
307 myTextFieldParameters->disable();
308 myButtonEditParameters->disable();
309 }
310 }
311 } else if (myTypeFrameParent) {
312 // get type
313 GNEDemandElement* type = myTypeFrameParent->getTypeSelector()->getCurrentType();
314 // continue depending of markAC
315 if (type) {
316 // set text field parameters
317 myTextFieldParameters->setText(type->getAttribute(GNE_ATTR_PARAMETERS).c_str());
318 // reset color
319 myTextFieldParameters->setTextColor(FXRGB(0, 0, 0));
320 // disable myTextFieldParameters if Tag correspond to an network element but we're in demand mode (or vice versa), disable all elements
321 if (GNEFrameAttributeModules::isSupermodeValid(myTypeFrameParent->getViewNet(), type)) {
322 myTextFieldParameters->enable();
323 myButtonEditParameters->enable();
324 } else {
325 myTextFieldParameters->disable();
326 myButtonEditParameters->disable();
327 }
328 }
329 }
330}
331
332
335 return myInspectorFrameParent;
336}
337
338
341 return myTypeFrameParent;
342}
343
344
345long
347 if (myInspectorFrameParent) {
348 const auto& inspectedElements = myInspectorFrameParent->getViewNet()->getInspectedElements();
349 // continue depending of markAC
350 if (inspectedElements.getFirstAC() && inspectedElements.getFirstAC()->getTagProperty().hasParameters()) {
351 if (inspectedElements.isInspectingMultipleElements()) {
352 // write debug information
353 WRITE_DEBUG("Open multiple parameters dialog");
354 // open multiple parameters dialog
355 if (GNEMultipleParametersDialog(this).execute()) {
356 // write debug information
357 WRITE_DEBUG("Close multiple parameters dialog");
358 // update frame parent after attribute successfully set
359 myInspectorFrameParent->attributeUpdated(GNE_ATTR_PARAMETERS);
360 // Refresh parameter EditorInspector
361 refreshParametersEditor();
362 } else {
363 // write debug information
364 WRITE_DEBUG("Cancel multiple parameters dialog");
365 }
366 } else {
367 // write debug information
368 WRITE_DEBUG("Open single parameters dialog");
369 if (GNESingleParametersDialog(this).execute()) {
370 // write debug information
371 WRITE_DEBUG("Close single parameters dialog");
372 // update frame parent after attribute successfully set
373 myInspectorFrameParent->attributeUpdated(GNE_ATTR_PARAMETERS);
374 // Refresh parameter EditorInspector
375 refreshParametersEditor();
376 } else {
377 // write debug information
378 WRITE_DEBUG("Cancel single parameters dialog");
379 }
380 }
381 }
382 } else if (myTypeFrameParent) {
383 // get type
384 GNEDemandElement* type = myTypeFrameParent->getTypeSelector()->getCurrentType();
385 // continue depending of type
386 if (type) {
387 // write debug information
388 WRITE_DEBUG("Open single parameters dialog");
389 if (GNESingleParametersDialog(this).execute()) {
390 // write debug information
391 WRITE_DEBUG("Close single parameters dialog");
392 // Refresh parameter EditorInspector
393 refreshParametersEditor();
394 } else {
395 // write debug information
396 WRITE_DEBUG("Cancel single parameters dialog");
397 }
398 }
399 }
400 return 1;
401}
402
403
404long
406 if (myInspectorFrameParent) {
407 const auto& inspectedElements = myInspectorFrameParent->getViewNet()->getInspectedElements();
408 // continue depending of markAC
409 if (inspectedElements.getFirstAC() && inspectedElements.getFirstAC()->getTagProperty().hasParameters()) {
410 // check if current given string is valid
411 if (inspectedElements.getFirstAC()->isValid(GNE_ATTR_PARAMETERS, myTextFieldParameters->getText().text())) {
412 // parsed parameters ok, then set text field black and continue
413 myTextFieldParameters->setTextColor(FXRGB(0, 0, 0));
414 myTextFieldParameters->killFocus();
415 // check inspected parameters
416 if (inspectedElements.isInspectingSingleElement()) {
417 // begin undo list
418 myInspectorFrameParent->getViewNet()->getUndoList()->begin(inspectedElements.getFirstAC(), "change parameters");
419 // set parameters
420 inspectedElements.getFirstAC()->setACParameters(myTextFieldParameters->getText().text(), myInspectorFrameParent->getViewNet()->getUndoList());
421 // end undo list
422 myInspectorFrameParent->getViewNet()->getUndoList()->end();
423 } else if (inspectedElements.isInspectingMultipleElements()) {
424 // begin undo list
425 myInspectorFrameParent->getViewNet()->getUndoList()->begin(inspectedElements.getFirstAC(), "change multiple parameters");
426 // set parameters in all ACs
427 for (const auto& inspectedAC : inspectedElements.getACs()) {
428 inspectedAC->setACParameters(myTextFieldParameters->getText().text(), myInspectorFrameParent->getViewNet()->getUndoList());
429 }
430 // end undo list
431 myInspectorFrameParent->getViewNet()->getUndoList()->end();
432 }
433 // update frame parent after attribute successfully set
434 myInspectorFrameParent->attributeUpdated(GNE_ATTR_PARAMETERS);
435 } else {
436 myTextFieldParameters->setTextColor(FXRGB(255, 0, 0));
437 }
438 }
439 } else if (myTypeFrameParent) {
440 // get type
441 GNEDemandElement* type = myTypeFrameParent->getTypeSelector()->getCurrentType();
442 // continue depending of markAC
443 if (type) {
444 // check if current given string is valid
445 if (type->isValid(GNE_ATTR_PARAMETERS, myTextFieldParameters->getText().text())) {
446 // parsed parameters ok, then set text field black and continue
447 myTextFieldParameters->setTextColor(FXRGB(0, 0, 0));
448 myTextFieldParameters->killFocus();
449 // begin undo list
450 myTypeFrameParent->getViewNet()->getUndoList()->begin(type, "change parameters");
451 // set parameters
452 type->setACParameters(myTextFieldParameters->getText().text(), myTypeFrameParent->getViewNet()->getUndoList());
453 // end undo list
454 myTypeFrameParent->getViewNet()->getUndoList()->end();
455 } else {
456 myTextFieldParameters->setTextColor(FXRGB(255, 0, 0));
457 }
458 }
459 }
460 return 1;
461}
462
463
464bool
466 if (viewNet->getEditModes().isCurrentSupermodeNetwork() &&
468 return true;
469 } else if (viewNet->getEditModes().isCurrentSupermodeDemand() &&
471 return true;
472 } else if (viewNet->getEditModes().isCurrentSupermodeData() &&
474 return true;
475 } else {
476 return false;
477 }
478}
479
480
481bool
484 return (viewNet->getEditModes().isCurrentSupermodeNetwork());
485 } else if (ACAttr.getTagPropertyParent().isDemandElement()) {
486 return (viewNet->getEditModes().isCurrentSupermodeDemand());
487 } else if (ACAttr.getTagPropertyParent().isDataElement() || ACAttr.getTagPropertyParent().isMeanData()) {
488 return (viewNet->getEditModes().isCurrentSupermodeData());
489 } else {
490 return false;
491 }
492}
493
494/****************************************************************************/
FXDEFMAP(GNEFrameAttributeModules::GenericDataAttributes) GenericDataAttributesMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:939
@ MID_GNE_OPEN_PARAMETERS_DIALOG
open parameters dialog
Definition GUIAppEnum.h:977
#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 WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
void setACParameters(const std::string &parameters, GNEUndoList *undoList)
set parameters (string)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
const GNETagProperties & getTagPropertyParent() const
get reference to tagProperty parent
virtual std::string getAttribute(SumoXMLAttr key) const =0
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
method for checking if the key and their conrrespond attribute are valids
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
void refreshParametersEditor()
refresh netedit attributes
long onCmdSetParameters(FXObject *, FXSelector, void *)
Called when user udpate the parameter text field.
long onCmdEditParameters(FXObject *, FXSelector, void *)
ParametersEditor(GNEInspectorFrame *inspectorFrameParent)
FOX-declaration.
void hideParametersEditor()
hide netedit attributes EditorInspector
GNEInspectorFrame * getInspectorFrameParent() const
get inspector frame parent
FXButton * myButtonEditParameters
button for edit parameters using specific dialog
FXTextField * myTextFieldParameters
text field for write parameters
GNETypeFrame * getTypeFrameParent() const
get type frame parent
void showParametersEditor()
show netedit attributes EditorInspector
static bool isSupermodeValid(const GNEViewNet *viewNet, const GNEAttributeCarrier *AC)
return true if AC can be edited in the current supermode
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
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
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
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)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
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