Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/GNETemplateElementDialog.h
169685 views
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
/****************************************************************************/
14
/// @file GNETemplateElementDialog.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Aug 2025
17
///
18
// A template based on GNEDialog used for editing elements
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <netedit/dialogs/GNEDialog.h>
24
#include <netedit/GNETagPropertiesDatabase.h>
25
26
// ===========================================================================
27
// class definitions
28
// ===========================================================================
29
30
template <typename T>
31
class GNETemplateElementDialog : public GNEDialog {
32
33
public:
34
/// @brief constructor
35
GNETemplateElementDialog(T* element, DialogType type) :
36
GNEDialog(element->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(),
37
TLF("Edit % '%'", element->getTagStr(), element->getID()).c_str(),
38
element->getTagProperty()->getGUIIcon(), type, Buttons::ACCEPT_CANCEL_RESET,
39
OpenType::MODAL, ResizeMode::STATIC),
40
myElement(element),
41
myChangesDescription(TLF("change % values", element->getTagStr())) {
42
// init commandGroup
43
myElement->getNet()->getViewNet()->getUndoList()->begin(myElement, myChangesDescription);
44
}
45
46
/// @brief destructor
47
~GNETemplateElementDialog() {}
48
49
/// @brief get edited element
50
T* getElement() const {
51
return myElement;
52
}
53
54
/// @brief run internal test
55
virtual void runInternalTest(const InternalTestStep::DialogArgument* dialogArgument) = 0;
56
57
/// @name FOX-callbacks
58
/// @{
59
/// @brief event after press accept button
60
virtual long onCmdAccept(FXObject* sender, FXSelector sel, void* ptr) = 0;
61
62
/// @brief event after press cancel button
63
virtual long onCmdReset(FXObject*, FXSelector, void*) = 0;
64
65
/// @brief called when cancel or no button is pressed
66
long onCmdCancel(FXObject*, FXSelector, void*) {
67
myElement->getNet()->getViewNet()->getUndoList()->abortLastChangeGroup();
68
return closeDialogCanceling();
69
}
70
71
/// @brief called when abort is called either closing dialog or pressing abort button
72
long onCmdAbort(FXObject*, FXSelector, void*) {
73
myElement->getNet()->getViewNet()->getUndoList()->abortLastChangeGroup();
74
return closeDialogAborting();
75
}
76
77
/// @}
78
79
protected:
80
/// @brief default constructor
81
GNETemplateElementDialog() :
82
GNEDialog() {}
83
84
/// @brief pointer to edited element
85
T* myElement = nullptr;
86
87
/// @brief close dialog commiting changes
88
long acceptElementDialog() {
89
myElement->getNet()->getViewNet()->getUndoList()->end();
90
return closeDialogAccepting();
91
}
92
93
/// @brief reset changes did in this dialog.
94
void resetChanges() {
95
// abort last command group an start editing again
96
myElement->getNet()->getViewNet()->getUndoList()->abortLastChangeGroup();
97
myElement->getNet()->getViewNet()->getUndoList()->begin(myElement, myChangesDescription);
98
}
99
100
private:
101
/// @brief description of changes did in this element dialog
102
std::string myChangesDescription;
103
104
/// @brief Invalidated copy constructor
105
GNETemplateElementDialog(const GNETemplateElementDialog&) = delete;
106
107
/// @brief Invalidated assignment operator
108
GNETemplateElementDialog& operator=(const GNETemplateElementDialog&) = delete;
109
};
110
111