Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/GNECrashDialog.cpp
185787 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 GNECrashDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Sep 2025
17
///
18
// Dialog used for handling crashes produced in Netedit
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <utils/common/MsgHandler.h>
23
#include <utils/foxtools/MFXLinkLabel.h>
24
#include <utils/foxtools/MFXTextFieldIcon.h>
25
#include <utils/gui/images/GUIIconSubSys.h>
26
#include <utils/gui/div/GUIDesigns.h>
27
28
#ifdef _MSC_VER
29
#pragma warning(push)
30
#pragma warning(disable: 4266) // mask warning about hidden member function FX::FXTextCodec::utf2mblen
31
#endif
32
#include <FX88591Codec.h>
33
#include <FXUTF16Codec.h>
34
#ifdef _MSC_VER
35
#pragma warning(pop)
36
#endif
37
38
#include "GNECrashDialog.h"
39
40
// ===========================================================================
41
// FOX callback mapping
42
// ===========================================================================
43
44
// Map
45
FXDEFMAP(GNECrashDialog) GNECrashDialogMap[] = {
46
FXMAPFUNC(SEL_CLIPBOARD_REQUEST, 0, GNECrashDialog::onClipboardRequest),
47
};
48
49
// Object implementation
50
FXIMPLEMENT(GNECrashDialog, GNEDialog, GNECrashDialogMap, ARRAYNUMBER(GNECrashDialogMap))
51
52
// ===========================================================================
53
// method definitions
54
// ===========================================================================
55
56
GNECrashDialog::GNECrashDialog(GNEApplicationWindow* applicationWindow, const ProcessError& processError) :
57
GNEDialog(applicationWindow, TL("Critical error"), GUIIcon::ERROR_SMALL,
58
DialogType::ABOUT, GNEDialog::Buttons::OK_COPY_REPORT, OpenType::MODAL, ResizeMode::RESIZABLE, 800, 600),
59
myTraceText(processError.getTrace()) {
60
// create dialog layout (obtained from FXMessageBox)
61
auto contents = new FXVerticalFrame(myContentFrame, LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 10, 10, 10, 10);
62
// add information label
63
new FXLabel(contents, TL("Netedit found an internal critical error and will be closed:"), NULL, GUIDesignLabel(JUSTIFY_NORMAL));
64
// create text field for exception
65
myExceptionTextField = new MFXTextFieldIcon(contents, applicationWindow->getStaticTooltipMenu(), GUIIcon::EMPTY, nullptr, 0, GUIDesignTextField);
66
myExceptionTextField->setEditable(FALSE);
67
myExceptionTextField->setText(processError.what());
68
// add information label
69
new FXLabel(contents, TL("ErrorTrace:"), NULL, GUIDesignLabel(JUSTIFY_NORMAL));
70
FXText* text = new FXText(contents, nullptr, 0, TEXT_WORDWRAP | LAYOUT_FILL_X | LAYOUT_FILL_Y);
71
text->setEditable(FALSE);
72
text->setText(myTraceText.c_str());
73
// disable copy button if trace is empty
74
if (myTraceText.size() == 0) {
75
myCopyButton->disable();
76
}
77
// open modal dialog
78
openDialog();
79
}
80
81
82
GNECrashDialog::~GNECrashDialog() {
83
}
84
85
86
void
87
GNECrashDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
88
// nothing to do
89
}
90
91
92
long
93
GNECrashDialog::onCmdCopy(FXObject*, FXSelector, void*) {
94
FXDragType types[4];
95
types[0] = stringType;
96
types[1] = textType;
97
types[2] = utf8Type;
98
types[3] = utf16Type;
99
// Acquire clipboard in different formats
100
acquireClipboard(types, 4);
101
return 1;
102
}
103
104
105
long
106
GNECrashDialog::onCmdReport(FXObject*, FXSelector, void*) {
107
// open new issue
108
return MFXLinkLabel::fxexecute("https://github.com/eclipse-sumo/sumo/issues/new");
109
}
110
111
112
long
113
GNECrashDialog::onClipboardRequest(FXObject* sender, FXSelector sel, void* ptr) {
114
FXEvent* event = (FXEvent*)ptr;
115
// Perhaps the target wants to supply its own data for the clipboard
116
if (GNEDialog::onClipboardRequest(sender, sel, ptr)) {
117
return 1;
118
}
119
// Recognize the request?
120
if (event->target == stringType || event->target == textType || event->target == utf8Type || event->target == utf16Type) {
121
// Return myClippedText text as as UTF-8
122
if (event->target == utf8Type) {
123
setDNDData(FROM_CLIPBOARD, event->target, myTraceText.c_str());
124
return 1;
125
}
126
// Return myClippedText text translated to 8859-1
127
if (event->target == stringType || event->target == textType) {
128
FX88591Codec ascii;
129
setDNDData(FROM_CLIPBOARD, event->target, ascii.utf2mb(myTraceText.c_str()));
130
return 1;
131
}
132
// Return text of the selection translated to UTF-16
133
if (event->target == utf16Type) {
134
FXUTF16LECodec unicode; // FIXME maybe other endianness for unix
135
setDNDData(FROM_CLIPBOARD, event->target, unicode.utf2mb(myTraceText.c_str()));
136
return 1;
137
}
138
}
139
return 0;
140
}
141
142
143
/****************************************************************************/
144
145