1 #include "SysInfoDialog.hpp"
2 #include "I18N.hpp"
3 #include "3DScene.hpp"
4 #include "GUI.hpp"
5 #include "../Utils/UndoRedo.hpp"
6 #include "Plater.hpp"
7
8 #include <string>
9
10 #include <Eigen/Core>
11
12 #include <wx/clipbrd.h>
13 #include <wx/platinfo.h>
14 #include "GUI_App.hpp"
15 #include "MainFrame.hpp"
16 #include "wxExtensions.hpp"
17
18 #ifdef _WIN32
19 // The standard Windows includes.
20 #define WIN32_LEAN_AND_MEAN
21 #define NOMINMAX
22 #include <Windows.h>
23 #include <psapi.h>
24 #endif /* _WIN32 */
25
26 namespace Slic3r {
27 namespace GUI {
28
get_main_info(bool format_as_html)29 std::string get_main_info(bool format_as_html)
30 {
31 std::stringstream out;
32
33 std::string b_start = format_as_html ? "<b>" : "";
34 std::string b_end = format_as_html ? "</b>" : "";
35 std::string line_end = format_as_html ? "<br>" : "\n";
36
37 if (!format_as_html)
38 out << b_start << (wxGetApp().is_editor() ? SLIC3R_APP_NAME : GCODEVIEWER_APP_NAME) << b_end << line_end;
39 out << b_start << "Version: " << b_end << SLIC3R_VERSION << line_end;
40 out << b_start << "Build: " << b_end << (wxGetApp().is_editor() ? SLIC3R_BUILD_ID : GCODEVIEWER_BUILD_ID) << line_end;
41 out << line_end;
42 out << b_start << "Operating System: " << b_end << wxPlatformInfo::Get().GetOperatingSystemFamilyName() << line_end;
43 out << b_start << "System Architecture: " << b_end << wxPlatformInfo::Get().GetArchName() << line_end;
44 out << b_start <<
45 #if defined _WIN32
46 "Windows Version: "
47 #else
48 // Hopefully some kind of unix / linux.
49 "System Version: "
50 #endif
51 << b_end << wxPlatformInfo::Get().GetOperatingSystemDescription() << line_end;
52 out << b_start << "Total RAM size [MB]: " << b_end << Slic3r::format_memsize_MB(Slic3r::total_physical_memory());
53
54 return out.str();
55 }
56
get_mem_info(bool format_as_html)57 std::string get_mem_info(bool format_as_html)
58 {
59 std::stringstream out;
60
61 std::string b_start = format_as_html ? "<b>" : "";
62 std::string b_end = format_as_html ? "</b>" : "";
63 std::string line_end = format_as_html ? "<br>" : "\n";
64
65 std::string mem_info_str = log_memory_info(true);
66 std::istringstream mem_info(mem_info_str);
67 std::string value;
68 while (std::getline(mem_info, value, ':')) {
69 out << b_start << (value+": ") << b_end;
70 std::getline(mem_info, value, ';');
71 out << value << line_end;
72 }
73
74 const Slic3r::UndoRedo::Stack &stack = wxGetApp().plater()->undo_redo_stack_main();
75 out << b_start << "RAM size reserved for the Undo / Redo stack: " << b_end << Slic3r::format_memsize_MB(stack.get_memory_limit()) << line_end;
76 out << b_start << "RAM size occupied by the Undo / Redo stack: " << b_end << Slic3r::format_memsize_MB(stack.memsize()) << line_end << line_end;
77
78 return out.str();
79 }
80
SysInfoDialog()81 SysInfoDialog::SysInfoDialog()
82 : DPIDialog(static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, (wxGetApp().is_editor() ? wxString(SLIC3R_APP_NAME) : wxString(GCODEVIEWER_APP_NAME)) + " - " + _L("System Information"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
83 {
84 wxColour bgr_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
85 SetBackgroundColour(bgr_clr);
86 SetFont(wxGetApp().normal_font());
87
88 wxBoxSizer* hsizer = new wxBoxSizer(wxHORIZONTAL);
89 hsizer->SetMinSize(wxSize(50 * wxGetApp().em_unit(), -1));
90
91 auto main_sizer = new wxBoxSizer(wxVERTICAL);
92 main_sizer->Add(hsizer, 1, wxEXPAND | wxALL, 10);
93
94 // logo
95 m_logo_bmp = ScalableBitmap(this, wxGetApp().is_editor() ? "PrusaSlicer_192px.png" : "PrusaSlicer-gcodeviewer_192px.png", 192);
96 m_logo = new wxStaticBitmap(this, wxID_ANY, m_logo_bmp.bmp());
97 hsizer->Add(m_logo, 0, wxALIGN_CENTER_VERTICAL);
98
99 wxBoxSizer* vsizer = new wxBoxSizer(wxVERTICAL);
100 hsizer->Add(vsizer, 1, wxEXPAND|wxLEFT, 20);
101
102 // title
103 {
104 wxStaticText* title = new wxStaticText(this, wxID_ANY, wxGetApp().is_editor() ? SLIC3R_APP_NAME : GCODEVIEWER_APP_NAME, wxDefaultPosition, wxDefaultSize);
105 wxFont title_font = wxGetApp().bold_font();
106 title_font.SetFamily(wxFONTFAMILY_ROMAN);
107 title_font.SetPointSize(22);
108 title->SetFont(title_font);
109 vsizer->Add(title, 0, wxEXPAND | wxALIGN_LEFT | wxTOP, wxGetApp().em_unit()/*50*/);
110 }
111
112 // main_info_text
113 wxFont font = get_default_font(this);
114 const auto text_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
115 auto text_clr_str = wxString::Format(wxT("#%02X%02X%02X"), text_clr.Red(), text_clr.Green(), text_clr.Blue());
116 auto bgr_clr_str = wxString::Format(wxT("#%02X%02X%02X"), bgr_clr.Red(), bgr_clr.Green(), bgr_clr.Blue());
117
118 const int fs = font.GetPointSize() - 1;
119 int size[] = { static_cast<int>(fs*1.5), static_cast<int>(fs*1.4), static_cast<int>(fs*1.3), fs, fs, fs, fs };
120
121 m_html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER);
122 {
123 m_html->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
124 m_html->SetBorders(2);
125 const auto text = wxString::Format(
126 "<html>"
127 "<body bgcolor= %s link= %s>"
128 "<font color=%s>"
129 "%s"
130 "</font>"
131 "</body>"
132 "</html>", bgr_clr_str, text_clr_str, text_clr_str,
133 get_main_info(true));
134 m_html->SetPage(text);
135 vsizer->Add(m_html, 1, wxEXPAND | wxBOTTOM, wxGetApp().em_unit());
136 }
137
138 // opengl_info
139 m_opengl_info_html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO);
140 {
141 m_opengl_info_html->SetMinSize(wxSize(-1, 16 * wxGetApp().em_unit()));
142 m_opengl_info_html->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
143 m_opengl_info_html->SetBorders(10);
144 const auto text = wxString::Format(
145 "<html>"
146 "<body bgcolor= %s link= %s>"
147 "<font color=%s>"
148 "%s"
149 "</font>"
150 "</body>"
151 "</html>", bgr_clr_str, text_clr_str, text_clr_str,
152 get_mem_info(true) + "<br>" + wxGetApp().get_gl_info(true, true) + "<br>Eigen vectorization supported: " + Eigen::SimdInstructionSetsInUse());
153 m_opengl_info_html->SetPage(text);
154 main_sizer->Add(m_opengl_info_html, 1, wxEXPAND | wxBOTTOM, 15);
155 }
156
157 wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK);
158 m_btn_copy_to_clipboard = new wxButton(this, wxID_ANY, _L("Copy to Clipboard"), wxDefaultPosition, wxDefaultSize);
159
160 buttons->Insert(0, m_btn_copy_to_clipboard, 0, wxLEFT, 5);
161 m_btn_copy_to_clipboard->Bind(wxEVT_BUTTON, &SysInfoDialog::onCopyToClipboard, this);
162
163 this->SetEscapeId(wxID_OK);
164 this->Bind(wxEVT_BUTTON, &SysInfoDialog::onCloseDialog, this, wxID_OK);
165 main_sizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3);
166
167 // this->Bind(wxEVT_LEFT_DOWN, &SysInfoDialog::onCloseDialog, this);
168 // logo->Bind(wxEVT_LEFT_DOWN, &SysInfoDialog::onCloseDialog, this);
169
170 SetSizer(main_sizer);
171 main_sizer->SetSizeHints(this);
172 }
173
on_dpi_changed(const wxRect & suggested_rect)174 void SysInfoDialog::on_dpi_changed(const wxRect &suggested_rect)
175 {
176 m_logo_bmp.msw_rescale();
177 m_logo->SetBitmap(m_logo_bmp.bmp());
178
179 wxFont font = get_default_font(this);
180 const int fs = font.GetPointSize() - 1;
181 int font_size[] = { static_cast<int>(fs*1.5), static_cast<int>(fs*1.4), static_cast<int>(fs*1.3), fs, fs, fs, fs };
182
183 m_html->SetFonts(font.GetFaceName(), font.GetFaceName(), font_size);
184 m_html->Refresh();
185
186 const int& em = em_unit();
187
188 msw_buttons_rescale(this, em, { wxID_OK, m_btn_copy_to_clipboard->GetId() });
189
190 m_opengl_info_html->SetMinSize(wxSize(-1, 16 * em));
191 m_opengl_info_html->SetFonts(font.GetFaceName(), font.GetFaceName(), font_size);
192 m_opengl_info_html->Refresh();
193
194 const wxSize& size = wxSize(65 * em, 55 * em);
195
196 SetMinSize(size);
197 Fit();
198
199 Refresh();
200 }
201
onCopyToClipboard(wxEvent &)202 void SysInfoDialog::onCopyToClipboard(wxEvent &)
203 {
204 wxTheClipboard->Open();
205 const auto text = get_main_info(false) + "\n" + wxGetApp().get_gl_info(false, true);
206 wxTheClipboard->SetData(new wxTextDataObject(text));
207 wxTheClipboard->Close();
208 }
209
onCloseDialog(wxEvent &)210 void SysInfoDialog::onCloseDialog(wxEvent &)
211 {
212 this->EndModal(wxID_CLOSE);
213 }
214
215 } // namespace GUI
216 } // namespace Slic3r
217