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, GUIDesignComboBoxVisibleItems,
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->hideAttributesEditor();
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 // get current meanData type
334 SumoXMLTag meanDataTag = myMeanDataFrameParent->myMeanDataTypeSelector->getCurrentMeanData().getTag();
335 // get mean datas sorted by ID
336 std::map<std::string, GNEMeanData*> sortedMeanDatas;
337 for (const auto& meanData : myMeanDataFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getMeanDatas().at(meanDataTag)) {
338 sortedMeanDatas[meanData.second->getID()] = meanData.second;
339 }
340 // clear items
341 myMeanDataComboBox->clearItems();
342 // fill myMeanDataMatchBox with meanDatas
343 for (const auto& sortedMeanData : sortedMeanDatas) {
344 myMeanDataComboBox->appendIconItem(sortedMeanData.first.c_str(), sortedMeanData.second->getACIcon());
345 }
346 // make sure that mean data exists
347 if (myCurrentMeanData && myMeanDataFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveMeanData(myCurrentMeanData->getTagProperty().getTag(), myCurrentMeanData->getID(), false)) {
348 bool validMeanData = false;
349 for (int i = 0; i < (int)myMeanDataComboBox->getNumItems(); i++) {
350 if (myMeanDataComboBox->getItemText(i) == myCurrentMeanData->getID()) {
351 myMeanDataComboBox->setCurrentItem(i);
352 validMeanData = true;
353 }
354 }
355 if (!validMeanData) {
356 myCurrentMeanData = nullptr;
357 }
358 } else {
359 myCurrentMeanData = nullptr;
360 }
361 // check if enable or disable comboBox
362 if (sortedMeanDatas.size() > 0) {
363 myMeanDataComboBox->enable();
364 // check ifupdate myCurrentMeanData
365 if (myCurrentMeanData == nullptr) {
366 myCurrentMeanData = sortedMeanDatas.begin()->second;
367 }
368 } else {
369 myMeanDataComboBox->disable();
370 }
371 // refresh meanData editor module
372 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
373 // check if show attribute editor
374 if (!afterChangingID) {
375 if (myCurrentMeanData) {
376 myMeanDataFrameParent->myMeanDataAttributesEditor->showAttributesEditor(myCurrentMeanData);
377 } else {
378 myMeanDataFrameParent->myMeanDataAttributesEditor->hideAttributesEditor();
379 }
380 }
381}
382
383
384void
386 if (myCurrentMeanData) {
387 myMeanDataComboBox->updateIconItem(myMeanDataComboBox->getCurrentItem(), myCurrentMeanData->getID().c_str(), myCurrentMeanData->getACIcon());
388 }
389}
390
391
392long
394 // get current meanData type
395 SumoXMLTag meanDataTag = myMeanDataFrameParent->myMeanDataTypeSelector->getCurrentMeanData().getTag();
396 // Check if value of myMeanDataMatchBox correspond of an allowed additional tags
397 for (const auto& meanData : myMeanDataFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getMeanDatas().at(meanDataTag)) {
398 if (meanData.second->getID() == myMeanDataComboBox->getText().text()) {
399 // set pointer
400 myCurrentMeanData = meanData.second;
401 // set color of myMeanDataMatchBox to black (valid)
402 myMeanDataComboBox->setTextColor(FXRGB(0, 0, 0));
403 // refresh meanData editor module
404 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
405 // show modules if selected item is valid
406 myMeanDataFrameParent->myMeanDataAttributesEditor->showAttributesEditor(myCurrentMeanData);
407 // Write Warning in console if we're in testing mode
408 WRITE_DEBUG(("Selected item '" + myMeanDataComboBox->getText() + "' in MeanDataSelector").text());
409 // update viewNet
410 myMeanDataFrameParent->getViewNet()->updateViewNet();
411 return 1;
412 }
413 }
414 myCurrentMeanData = nullptr;
415 // refresh meanData editor module
416 myMeanDataFrameParent->myMeanDataEditor->refreshMeanDataEditorModule();
417 // hide all modules if selected item isn't valid
418 myMeanDataFrameParent->myMeanDataAttributesEditor->hideAttributesEditor();
419 // set color of myMeanDataMatchBox to red (invalid)
420 myMeanDataComboBox->setTextColor(FXRGB(255, 0, 0));
421 // Write Warning in console if we're in testing mode
422 WRITE_DEBUG("Selected invalid item in MeanDataSelector");
423 // update viewNet
424 myMeanDataFrameParent->getViewNet()->updateViewNet();
425 return 1;
426}
427
428// ---------------------------------------------------------------------------
429// GNEMeanDataFrame - methods
430// ---------------------------------------------------------------------------
431
433 GNEFrame(viewParent, viewNet, TL("MeanData")) {
434 // build meanData type selector
436 // build meanData editor
438 // build meanData selector
440 // build meanData attributes editor
442}
443
444
447
448
449void
451 // refresh meanData type selector
453 // show frame
455}
456
457
458void
460 // hide frame
462}
463
464
465void
471
472
473void
476
477/****************************************************************************/
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:82
#define GUIDesignComboBox
Definition GUIDesigns.h:293
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:311
#define GUIDesignComboBoxVisibleItems
Definition GUIDesigns.h:49
@ 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 *)
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.
GNEAttributesEditor * myMeanDataAttributesEditor
meanData attributes editor
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.