Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMeanDataFrame.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// The Widget for edit meanData elements
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
24#include <netedit/GNEUndoList.h>
31
32#include "GNEMeanDataFrame.h"
33
34
35// ===========================================================================
36// FOX callback mapping
37// ===========================================================================
38
42
48
52
53// Object implementation
54FXIMPLEMENT(GNEMeanDataFrame::MeanDataTypeSelector, MFXGroupBoxModule, meanDataSelectorMap, ARRAYNUMBER(meanDataSelectorMap))
55FXIMPLEMENT(GNEMeanDataFrame::MeanDataEditor, MFXGroupBoxModule, meanDataEditorMap, ARRAYNUMBER(meanDataEditorMap))
56FXIMPLEMENT(GNEMeanDataFrame::MeanDataSelector, MFXGroupBoxModule, meanDataTypeSelectorMap, ARRAYNUMBER(meanDataTypeSelectorMap))
57
58
59// ===========================================================================
60// method definitions
61// ===========================================================================
62
63// ---------------------------------------------------------------------------
64// GNEMeanDataFrame::MeanDataTypeSelector - methods
65// ---------------------------------------------------------------------------
66
68 MFXGroupBoxModule(meanDataFrameParent, TL("MeanData Type")),
69 myMeanDataFrameParent(meanDataFrameParent) {
70 // Create MFXComboBoxIcon
71 myTypeComboBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItemsMedium,
73 // add mean data types
75 for (const auto& meanDataType : meanDataTypes) {
76 myTypeComboBox->appendIconItem(meanDataType.getTagStr().c_str(), GUIIconSubSys::getIcon(meanDataType.getGUIIcon()));
77 }
78 // set DEFAULT_VEHTYPE as default VType
79 myCurrentMeanData = meanDataTypes.front();
80 // MeanDataTypeSelector is always shown
81 show();
82}
83
84
86
87
90 return myCurrentMeanData;
91}
92
93
94void
96 // clear items
97 myTypeComboBox->clearItems();
98 // add mean data types
100 for (const auto& meanDataType : meanDataTypes) {
101 myTypeComboBox->appendIconItem(meanDataType.getTagStr().c_str(), GUIIconSubSys::getIcon(meanDataType.getGUIIcon()));
102 }
103 // make sure that tag is in myTypeMatchBox
104 if (myCurrentMeanData.getTagStr() != myInvalidMeanData.getTagStr()) {
105 for (int i = 0; i < (int)myTypeComboBox->getNumItems(); i++) {
106 if (myTypeComboBox->getItemText(i) == myCurrentMeanData.getTagStr()) {
107 myTypeComboBox->setCurrentItem(i);
108 }
109 }
110 } else {
111 myCurrentMeanData = meanDataTypes.front();
112 }
113 // refresh meanData editor module
114 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
115 // show modules
116 myMeanDataFrameParent->myMeanDataEditor->showMeanDataEditorModule();
117 myMeanDataFrameParent->myMeanDataSelector->showMeanDataSelector();
118}
119
120
121long
123 // add mean data types
125 // Check if value of myTypeMatchBox correspond of an allowed additional tags
126 for (const auto& meanDataType : meanDataTypes) {
127 if (meanDataType.getTagStr() == myTypeComboBox->getText().text()) {
128 // set pointer
129 myCurrentMeanData = meanDataType;
130 // set color of myTypeMatchBox to black (valid)
131 myTypeComboBox->setTextColor(FXRGB(0, 0, 0));
132 // refresh meanData editor module
133 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
134 // show modules if selected item is valid
135 myMeanDataFrameParent->myMeanDataEditor->showMeanDataEditorModule();
136 myMeanDataFrameParent->myMeanDataSelector->showMeanDataSelector();
137 // Write Warning in console if we're in testing mode
138 WRITE_DEBUG(("Selected item '" + myTypeComboBox->getText() + "' in MeanDataTypeSelector").text());
139 return 1;
140 }
141 }
142 myCurrentMeanData = myInvalidMeanData;
143 // refresh meanData editor module
144 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
145 // hide all modules if selected item isn't valid
146 myMeanDataFrameParent->myMeanDataEditor->hideMeanDataEditorModule();
147 myMeanDataFrameParent->myMeanDataSelector->hideMeanDataSelector();
148 // set color of myTypeMatchBox to red (invalid)
149 myTypeComboBox->setTextColor(FXRGB(255, 0, 0));
150 // Write Warning in console if we're in testing mode
151 WRITE_DEBUG("Selected invalid item in MeanDataTypeSelector");
152 return 1;
153}
154
155// ---------------------------------------------------------------------------
156// GNEMeanDataFrame::MeanDataEditor - methods
157// ---------------------------------------------------------------------------
158
160 MFXGroupBoxModule(meanDataFrameParent, TL("MeanData Editor")),
161 myMeanDataFrameParent(meanDataFrameParent) {
162 // Create new meanData
165 // Create delete/reset meanData
168 // Create copy meanData
171}
172
173
175
176
177void
179 refreshMeanDataEditorModule();
180 show();
181}
182
183
184void
188
189
190void
192 // first check if selected VMeanData is valid
193 if (myMeanDataFrameParent->myMeanDataSelector->getCurrentMeanData() == nullptr) {
194 // disable buttons
195 myDeleteMeanDataButton->disable();
196 myCopyMeanDataButton->disable();
197 } else {
198 // enable buttons
199 myDeleteMeanDataButton->enable();
200 myCopyMeanDataButton->enable();
201 }
202 // update module
203 recalc();
204}
205
206
207long
209 // get current meanData type
210 SumoXMLTag meanDataTag = myMeanDataFrameParent->myMeanDataTypeSelector->getCurrentMeanData().getTag();
211 // obtain a new valid MeanData ID
212 const std::string typeID = myMeanDataFrameParent->myViewNet->getNet()->getAttributeCarriers()->generateMeanDataID(meanDataTag);
213 // create new meanData
214 GNEMeanData* meanData = new GNEMeanData(myMeanDataFrameParent->myViewNet->getNet(),
215 myMeanDataFrameParent->myMeanDataTypeSelector->getCurrentMeanData().getTag(), typeID);
216 // add it using undoList (to allow undo-redo)
217 myMeanDataFrameParent->myViewNet->getUndoList()->begin(meanData, "create meanData");
218 myMeanDataFrameParent->myViewNet->getUndoList()->add(new GNEChange_MeanData(meanData, true), true);
219 myMeanDataFrameParent->myViewNet->getUndoList()->end();
220 // set created meanData in selector
221 myMeanDataFrameParent->myMeanDataSelector->setCurrentMeanData(meanData);
222 return 1;
223}
224
225
226long
228 // begin undo list operation
229 myMeanDataFrameParent->myViewNet->getUndoList()->begin(GUIIcon::MODEDELETE, "delete meanData");
230 // remove meanData (and all of their children)
231 myMeanDataFrameParent->myViewNet->getNet()->deleteMeanData(myMeanDataFrameParent->myMeanDataSelector->getCurrentMeanData(),
232 myMeanDataFrameParent->myViewNet->getUndoList());
233 // end undo list operation
234 myMeanDataFrameParent->myViewNet->getUndoList()->end();
235 // set created meanData in selector
236 myMeanDataFrameParent->myMeanDataSelector->refreshMeanDataSelector(false);
237 return 1;
238}
239
240
241long
243 // get current meanData type
244 SumoXMLTag meanDataTag = myMeanDataFrameParent->myMeanDataTypeSelector->getCurrentMeanData().getTag();
245 // obtain a new valid MeanData ID
246 const std::string typeID = myMeanDataFrameParent->myViewNet->getNet()->getAttributeCarriers()->generateMeanDataID(meanDataTag);
247 // obtain meanData in which new MeanData will be based
248 GNEMeanData* meanData = dynamic_cast<GNEMeanData*>(myMeanDataFrameParent->myMeanDataSelector->getCurrentMeanData());
249 // check that meanData exist
250 if (meanData) {
251 // create a new MeanData based on the current selected meanData
252 GNEMeanData* meanDataCopy = new GNEMeanData(myMeanDataFrameParent->myViewNet->getNet(),
253 myMeanDataFrameParent->myMeanDataTypeSelector->getCurrentMeanData().getTag(), typeID);
254 // begin undo list operation
255 myMeanDataFrameParent->myViewNet->getUndoList()->begin(meanDataCopy, "copy meanData");
256 // add it using undoList (to allow undo-redo)
257 myMeanDataFrameParent->myViewNet->getUndoList()->add(new GNEChange_MeanData(meanDataCopy, true), true);
258 // end undo list operation
259 myMeanDataFrameParent->myViewNet->getUndoList()->end();
260 // refresh MeanData Selector (to show the new VMeanData)
261 myMeanDataFrameParent->myMeanDataSelector->refreshMeanDataSelector(false);
262 // set created meanData in selector
263 myMeanDataFrameParent->myMeanDataSelector->setCurrentMeanData(meanDataCopy);
264 // refresh MeanData Editor Module
265 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
266 }
267 return 1;
268}
269
270// ---------------------------------------------------------------------------
271// GNEMeanDataFrame::MeanDataSelector - methods
272// ---------------------------------------------------------------------------
273
275 MFXGroupBoxModule(typeFrameParent, TL("Current MeanData")),
276 myMeanDataFrameParent(typeFrameParent),
277 myCurrentMeanData(nullptr) {
278 // get current meanData type
280 // Create MFXComboBoxIcon
283 // add meanDatas
284 for (const auto& meanData : myMeanDataFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getMeanDatas().at(meanDataTag)) {
285 myMeanDataComboBox->appendIconItem(meanData.second->getID().c_str(), meanData.second->getACIcon());
286 }
287 if (myMeanDataFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getMeanDatas().at(meanDataTag).size() > 0) {
289 } else {
290 myCurrentMeanData = nullptr;
291 }
292 // MeanDataSelector is always shown
293 show();
294}
295
296
298
299
300void
302 // refresh mean data selector
303 refreshMeanDataSelector(false);
304 // show
305 show();
306}
307
308
309void
311 // hide attributes editor
312 myMeanDataFrameParent->myMeanDataAttributesEditor->hideAttributesEditorModule();
313 // hide
314 hide();
315}
316
317
320 return myCurrentMeanData;
321}
322
323
324void
326 myCurrentMeanData = vMeanData;
327 refreshMeanDataSelector(false);
328}
329
330
331void
333 auto& inspectedElements = myMeanDataFrameParent->getViewNet()->getInspectedElements();
334 // get current meanData type
335 SumoXMLTag meanDataTag = myMeanDataFrameParent->myMeanDataTypeSelector->getCurrentMeanData().getTag();
336 // get mean datas sorted by ID
337 std::map<std::string, GNEMeanData*> sortedMeanDatas;
338 for (const auto& meanData : myMeanDataFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getMeanDatas().at(meanDataTag)) {
339 sortedMeanDatas[meanData.second->getID()] = meanData.second;
340 }
341 // clear items
342 myMeanDataComboBox->clearItems();
343 // fill myMeanDataMatchBox with meanDatas
344 for (const auto& sortedMeanData : sortedMeanDatas) {
345 myMeanDataComboBox->appendIconItem(sortedMeanData.first.c_str(), sortedMeanData.second->getACIcon());
346 }
347 // make sure that mean data exists
348 if (myCurrentMeanData && myMeanDataFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveMeanData(myCurrentMeanData->getTagProperty().getTag(), myCurrentMeanData->getID(), false)) {
349 bool validMeanData = false;
350 for (int i = 0; i < (int)myMeanDataComboBox->getNumItems(); i++) {
351 if (myMeanDataComboBox->getItemText(i) == myCurrentMeanData->getID()) {
352 myMeanDataComboBox->setCurrentItem(i);
353 validMeanData = true;
354 }
355 }
356 if (!validMeanData) {
357 myCurrentMeanData = nullptr;
358 }
359 } else {
360 myCurrentMeanData = nullptr;
361 }
362 // check if enable or disable comboBox
363 if (sortedMeanDatas.size() > 0) {
364 myMeanDataComboBox->enable();
365 // check ifupdate myCurrentMeanData
366 if (myCurrentMeanData == nullptr) {
367 myCurrentMeanData = sortedMeanDatas.begin()->second;
368 }
369 } else {
370 myMeanDataComboBox->disable();
371 }
372 // refresh meanData editor module
373 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
374 // check if show attribute editor
375 if (!afterChangingID) {
376 if (myCurrentMeanData) {
377 // set myCurrentMeanData as inspected element (needed for attribute editor)
378 inspectedElements.inspectAC(myCurrentMeanData);
379 myMeanDataFrameParent->myMeanDataAttributesEditor->showAttributeEditorModule(false);
380 } else {
381 // set myCurrentMeanData as inspected element (needed for attribute editor)
382 inspectedElements.inspectAC({});
383 myMeanDataFrameParent->myMeanDataAttributesEditor->hideAttributesEditorModule();
384 }
385 }
386}
387
388
389void
391 if (myCurrentMeanData) {
392 myMeanDataComboBox->updateIconItem(myMeanDataComboBox->getCurrentItem(), myCurrentMeanData->getID().c_str(), myCurrentMeanData->getACIcon());
393 }
394}
395
396
397long
399 // get current meanData type
400 SumoXMLTag meanDataTag = myMeanDataFrameParent->myMeanDataTypeSelector->getCurrentMeanData().getTag();
401 // Check if value of myMeanDataMatchBox correspond of an allowed additional tags
402 for (const auto& meanData : myMeanDataFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getMeanDatas().at(meanDataTag)) {
403 if (meanData.second->getID() == myMeanDataComboBox->getText().text()) {
404 // set pointer
405 myCurrentMeanData = meanData.second;
406 // set color of myMeanDataMatchBox to black (valid)
407 myMeanDataComboBox->setTextColor(FXRGB(0, 0, 0));
408 // refresh meanData editor module
409 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
410 // set myCurrentMeanData as inspected element
411 myMeanDataFrameParent->getViewNet()->getInspectedElements().inspectAC(myCurrentMeanData);
412 // show modules if selected item is valid
413 myMeanDataFrameParent->myMeanDataAttributesEditor->showAttributeEditorModule(false);
414 // Write Warning in console if we're in testing mode
415 WRITE_DEBUG(("Selected item '" + myMeanDataComboBox->getText() + "' in MeanDataSelector").text());
416 // update viewNet
417 myMeanDataFrameParent->getViewNet()->updateViewNet();
418 return 1;
419 }
420 }
421 myCurrentMeanData = nullptr;
422 // refresh meanData editor module
423 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
424 // hide all modules if selected item isn't valid
425 myMeanDataFrameParent->myMeanDataAttributesEditor->hideAttributesEditorModule();
426 // set color of myMeanDataMatchBox to red (invalid)
427 myMeanDataComboBox->setTextColor(FXRGB(255, 0, 0));
428 // Write Warning in console if we're in testing mode
429 WRITE_DEBUG("Selected invalid item in MeanDataSelector");
430 // update viewNet
431 myMeanDataFrameParent->getViewNet()->updateViewNet();
432 return 1;
433}
434
435// ---------------------------------------------------------------------------
436// GNEMeanDataFrame - methods
437// ---------------------------------------------------------------------------
438
440 GNEFrame(viewParent, viewNet, TL("MeanData")) {
441 // build meanData type selector
443 // build meanData editor
445 // build meanData selector
447 // build meanData attributes editor
449}
450
451
454
455
456void
458 // refresh meanData type selector
460 // show frame
462}
463
464
465void
467 // hide frame
469}
470
471
472void
478
479
480void
483
484/****************************************************************************/
FXDEFMAP(GNEMeanDataFrame::MeanDataTypeSelector) meanDataSelectorMap[]
@ MID_GNE_DELETE
delete element
Definition GUIAppEnum.h:943
@ MID_GNE_COPY
copy element
Definition GUIAppEnum.h:953
@ MID_GNE_CREATE
create element
Definition GUIAppEnum.h:941
@ MID_GNE_SET_TYPE
used to select a type of element in a combo box
Definition GUIAppEnum.h:959
#define GUIDesignButton
Definition GUIDesigns.h:88
#define GUIDesignComboBox
Definition GUIDesigns.h:299
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:317
#define GUIDesignComboBoxVisibleItemsMedium
combo box medium small
Definition GUIDesigns.h:53
@ MODEMEANDATA
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ID
static const std::vector< GNETagProperties > getTagPropertiesByType(const int tagPropertyCategory, const bool mergeCommonPlans)
get tagProperties associated to the given GNETagProperties::TagType (NETWORKELEMENT,...
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
virtual void show()
show Frame
Definition GNEFrame.cpp:115
virtual void hide()
hide Frame
Definition GNEFrame.cpp:124
void hideMeanDataEditorModule()
hide MeanDataEditor box
void refreshMeanDataEditorModule()
update MeanDataEditor modul
FXButton * myCopyMeanDataButton
"copy meanData"
FXButton * myCreateMeanDataButton
"create meanData" button
long onCmdCopyMeanData(FXObject *, FXSelector, void *)
Called when "Copy Vehicle MeanData" button is clicked.
long onCmdCreateMeanData(FXObject *, FXSelector, void *)
MeanDataEditor(GNEMeanDataFrame *meanDataFrameParent)
FOX-declaration.
void showMeanDataEditorModule()
show MeanDataEditor modul
long onCmdDeletetMeanData(FXObject *, FXSelector, void *)
Called when "Delete Vehicle MeanData" button is clicked.
FXButton * myDeleteMeanDataButton
"delete meanData" button
void showMeanDataSelector()
show MeanDataSelector
void hideMeanDataSelector()
hide MeanDataSelector
GNEMeanData * myCurrentMeanData
pointer to current meanData
MeanDataSelector(GNEMeanDataFrame *typeFrameParent)
FOX-declaration.
GNEMeanData * getCurrentMeanData() const
get current Vehicle MeanData
void refreshMeanDataSelectorIDs()
refresh meanData selector (only IDs, without refreshing attributes)
MFXComboBoxIcon * myMeanDataComboBox
comboBox with the list of meanDatas
void refreshMeanDataSelector(bool afterChangingID)
refresh meanData selector
void setCurrentMeanData(GNEMeanData *vMeanData)
set current Vehicle MeanData
GNEMeanDataFrame * myMeanDataFrameParent
pointer to Frame Parent
long onCmdSelectItem(FXObject *, FXSelector, void *)
void refreshMeanDataTypeSelector()
refresh meanData selector
const GNETagProperties & getCurrentMeanData() const
get current MeanData
long onCmdSelectItem(FXObject *, FXSelector, void *)
GNEFrameAttributeModules::AttributesEditor * myMeanDataAttributesEditor
meanData attributes editor
void hide()
hide Frame
void attributeUpdated(SumoXMLAttr attribute)
function called after set a valid attribute in AttributeCreator/AttributeEditor/ParametersEditor/....
MeanDataSelector * myMeanDataSelector
meanData selector
void show()
show Frame
~GNEMeanDataFrame()
Destructor.
GNEMeanDataFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor (protected due GNEMeanDataFrame is abtract)
MeanDataTypeSelector * myMeanDataTypeSelector
meanData type selector
void updateFrameAfterUndoRedo()
function called after undo/redo in the current frame
MeanDataEditor * myMeanDataEditor
meanData editor
An Element which don't belong to GNENet but has influence in the simulation.
Definition GNEMeanData.h:33
const std::unordered_map< SumoXMLTag, std::map< const std::string, GNEMeanData * > > & getMeanDatas() const
get meanDatas
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
GNENet * getNet() const
get the net object
A single child window which contains a view of the simulation area.
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
ComboBox with icon.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon item in the last position
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
C++ TraCI client API implementation.