2018-04-10 14:27:42 +00:00
|
|
|
#include "ConfigSnapshotDialog.hpp"
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "I18N.hpp"
|
2018-04-10 14:27:42 +00:00
|
|
|
|
|
|
|
#include "../Config/Snapshot.hpp"
|
|
|
|
#include "../Utils/Time.hpp"
|
|
|
|
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "libslic3r/Utils.hpp"
|
2019-02-04 09:35:16 +00:00
|
|
|
#include "GUI_App.hpp"
|
2019-04-25 13:06:44 +00:00
|
|
|
#include "wxExtensions.hpp"
|
2018-04-10 14:27:42 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
namespace GUI {
|
|
|
|
|
2018-05-02 11:20:36 +00:00
|
|
|
static wxString format_reason(const Config::Snapshot::Reason reason)
|
2018-04-12 09:24:03 +00:00
|
|
|
{
|
|
|
|
switch (reason) {
|
|
|
|
case Config::Snapshot::SNAPSHOT_UPGRADE:
|
2018-05-02 11:20:36 +00:00
|
|
|
return wxString(_(L("Upgrade")));
|
2018-04-12 09:24:03 +00:00
|
|
|
case Config::Snapshot::SNAPSHOT_DOWNGRADE:
|
2018-05-02 11:20:36 +00:00
|
|
|
return wxString(_(L("Downgrade")));
|
2018-04-20 08:26:23 +00:00
|
|
|
case Config::Snapshot::SNAPSHOT_BEFORE_ROLLBACK:
|
2018-05-02 11:20:36 +00:00
|
|
|
return wxString(_(L("Before roll back")));
|
2018-04-12 09:24:03 +00:00
|
|
|
case Config::Snapshot::SNAPSHOT_USER:
|
2018-05-02 11:20:36 +00:00
|
|
|
return wxString(_(L("User")));
|
2018-04-12 09:24:03 +00:00
|
|
|
case Config::Snapshot::SNAPSHOT_UNKNOWN:
|
|
|
|
default:
|
2018-05-02 11:20:36 +00:00
|
|
|
return wxString(_(L("Unknown")));
|
2018-04-12 09:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-02 11:20:36 +00:00
|
|
|
static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_even, bool snapshot_active)
|
2018-04-10 14:27:42 +00:00
|
|
|
{
|
|
|
|
// Start by declaring a row with an alternating background color.
|
2018-05-02 11:20:36 +00:00
|
|
|
wxString text = "<tr bgcolor=\"";
|
2018-04-20 08:26:23 +00:00
|
|
|
text += snapshot_active ? "#B3FFCB" : (row_even ? "#FFFFFF" : "#D5D5D5");
|
2018-04-10 14:27:42 +00:00
|
|
|
text += "\">";
|
|
|
|
text += "<td>";
|
2018-04-12 09:24:03 +00:00
|
|
|
// Format the row header.
|
2019-05-11 21:29:25 +00:00
|
|
|
text += wxString("<font size=\"5\"><b>") + (snapshot_active ? _(L("Active")) + ": " : "") +
|
2018-04-20 08:26:23 +00:00
|
|
|
Utils::format_local_date_time(snapshot.time_captured) + ": " + format_reason(snapshot.reason);
|
2018-04-12 09:24:03 +00:00
|
|
|
if (! snapshot.comment.empty())
|
2019-03-17 08:32:53 +00:00
|
|
|
text += " (" + wxString::FromUTF8(snapshot.comment.data()) + ")";
|
2018-04-12 09:24:03 +00:00
|
|
|
text += "</b></font><br>";
|
|
|
|
// End of row header.
|
2018-04-20 08:26:23 +00:00
|
|
|
text += _(L("slic3r version")) + ": " + snapshot.slic3r_version_captured.to_string() + "<br>";
|
|
|
|
text += _(L("print")) + ": " + snapshot.print + "<br>";
|
|
|
|
text += _(L("filaments")) + ": " + snapshot.filaments.front() + "<br>";
|
|
|
|
text += _(L("printer")) + ": " + snapshot.printer + "<br>";
|
2018-04-10 14:27:42 +00:00
|
|
|
|
2018-04-25 11:44:06 +00:00
|
|
|
bool compatible = true;
|
2018-04-10 14:27:42 +00:00
|
|
|
for (const Config::Snapshot::VendorConfig &vc : snapshot.vendor_configs) {
|
2018-05-02 11:20:36 +00:00
|
|
|
text += _(L("vendor")) + ": " + vc.name +", " + _(L("version")) + ": " + vc.version.config_version.to_string() +
|
|
|
|
", " + _(L("min slic3r version")) + ": " + vc.version.min_slic3r_version.to_string();
|
2018-04-25 11:44:06 +00:00
|
|
|
if (vc.version.max_slic3r_version != Semver::inf())
|
2018-05-02 11:20:36 +00:00
|
|
|
text += ", " + _(L("max slic3r version")) + ": " + vc.version.max_slic3r_version.to_string();
|
2018-04-11 10:21:15 +00:00
|
|
|
text += "<br>";
|
|
|
|
for (const std::pair<std::string, std::set<std::string>> &model : vc.models_variants_installed) {
|
2018-04-20 08:26:23 +00:00
|
|
|
text += _(L("model")) + ": " + model.first + ", " + _(L("variants")) + ": ";
|
2018-04-11 10:21:15 +00:00
|
|
|
for (const std::string &variant : model.second) {
|
|
|
|
if (&variant != &*model.second.begin())
|
|
|
|
text += ", ";
|
|
|
|
text += variant;
|
|
|
|
}
|
|
|
|
text += "<br>";
|
|
|
|
}
|
2018-04-25 11:44:06 +00:00
|
|
|
if (! vc.version.is_current_slic3r_supported()) { compatible = false; }
|
2018-04-10 14:27:42 +00:00
|
|
|
}
|
|
|
|
|
2018-04-25 11:44:06 +00:00
|
|
|
if (! compatible) {
|
2019-04-26 09:05:00 +00:00
|
|
|
text += "<p align=\"right\">" + wxString::Format(_(L("Incompatible with this %s")), SLIC3R_APP_NAME) + "</p>";
|
2018-04-25 11:44:06 +00:00
|
|
|
}
|
|
|
|
else if (! snapshot_active)
|
2018-04-20 08:26:23 +00:00
|
|
|
text += "<p align=\"right\"><a href=\"" + snapshot.id + "\">" + _(L("Activate")) + "</a></p>";
|
2018-04-10 14:27:42 +00:00
|
|
|
text += "</td>";
|
|
|
|
text += "</tr>";
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2018-05-02 11:20:36 +00:00
|
|
|
static wxString generate_html_page(const Config::SnapshotDB &snapshot_db, const wxString &on_snapshot)
|
2018-04-10 14:27:42 +00:00
|
|
|
{
|
2018-05-02 11:20:36 +00:00
|
|
|
wxString text =
|
2018-04-10 14:27:42 +00:00
|
|
|
"<html>"
|
|
|
|
"<body bgcolor=\"#ffffff\" cellspacing=\"2\" cellpadding=\"0\" border=\"0\" link=\"#800000\">"
|
|
|
|
"<font color=\"#000000\">";
|
|
|
|
text += "<table style=\"width:100%\">";
|
|
|
|
for (size_t i_row = 0; i_row < snapshot_db.snapshots().size(); ++ i_row) {
|
2018-04-11 10:21:15 +00:00
|
|
|
const Config::Snapshot &snapshot = snapshot_db.snapshots()[snapshot_db.snapshots().size() - i_row - 1];
|
2018-04-20 08:26:23 +00:00
|
|
|
text += generate_html_row(snapshot, i_row & 1, snapshot.id == on_snapshot);
|
2018-04-10 14:27:42 +00:00
|
|
|
}
|
|
|
|
text +=
|
|
|
|
"</table>"
|
|
|
|
"</font>"
|
|
|
|
"</body>"
|
|
|
|
"</html>";
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2018-05-02 11:20:36 +00:00
|
|
|
ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db, const wxString &on_snapshot)
|
2019-04-18 13:05:17 +00:00
|
|
|
: DPIDialog(NULL, wxID_ANY, _(L("Configuration Snapshots")), wxDefaultPosition,
|
2019-02-04 09:35:16 +00:00
|
|
|
wxSize(45 * wxGetApp().em_unit(), 40 * wxGetApp().em_unit()),
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX)
|
2018-04-10 14:27:42 +00:00
|
|
|
{
|
2019-04-18 13:05:17 +00:00
|
|
|
this->SetFont(wxGetApp().normal_font());
|
2018-04-10 14:27:42 +00:00
|
|
|
this->SetBackgroundColour(*wxWHITE);
|
|
|
|
|
|
|
|
wxBoxSizer* vsizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
this->SetSizer(vsizer);
|
|
|
|
|
|
|
|
// text
|
2019-04-18 13:05:17 +00:00
|
|
|
html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO);
|
2018-04-10 14:27:42 +00:00
|
|
|
{
|
2019-04-18 13:05:17 +00:00
|
|
|
wxFont font = wxGetApp().normal_font();//wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
2018-04-10 14:27:42 +00:00
|
|
|
#ifdef __WXMSW__
|
2019-04-18 13:05:17 +00:00
|
|
|
const int fs = font.GetPointSize();
|
|
|
|
const int fs1 = static_cast<int>(0.8f*fs);
|
|
|
|
const int fs2 = static_cast<int>(1.1f*fs);
|
|
|
|
int size[] = {fs1, fs1, fs1, fs1, fs2, fs2, fs2};
|
|
|
|
// int size[] = {8,8,8,8,11,11,11};
|
2018-04-10 14:27:42 +00:00
|
|
|
#else
|
2018-04-12 09:24:03 +00:00
|
|
|
int size[] = {11,11,11,11,14,14,14};
|
2018-04-10 14:27:42 +00:00
|
|
|
#endif
|
|
|
|
html->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
|
|
|
|
html->SetBorders(2);
|
2018-05-02 11:20:36 +00:00
|
|
|
wxString text = generate_html_page(snapshot_db, on_snapshot);
|
|
|
|
html->SetPage(text);
|
2018-04-10 14:27:42 +00:00
|
|
|
vsizer->Add(html, 1, wxEXPAND | wxALIGN_LEFT | wxRIGHT | wxBOTTOM, 0);
|
|
|
|
html->Bind(wxEVT_HTML_LINK_CLICKED, &ConfigSnapshotDialog::onLinkClicked, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxCLOSE);
|
|
|
|
this->SetEscapeId(wxID_CLOSE);
|
|
|
|
this->Bind(wxEVT_BUTTON, &ConfigSnapshotDialog::onCloseDialog, this, wxID_CLOSE);
|
|
|
|
vsizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3);
|
|
|
|
}
|
|
|
|
|
2019-04-18 13:05:17 +00:00
|
|
|
void ConfigSnapshotDialog::on_dpi_changed(const wxRect &suggested_rect)
|
|
|
|
{
|
|
|
|
wxFont font = GetFont();
|
|
|
|
const int fs = font.GetPointSize();
|
|
|
|
const int fs1 = static_cast<int>(0.8f*fs);
|
|
|
|
const int fs2 = static_cast<int>(1.1f*fs);
|
|
|
|
int font_size[] = { fs1, fs1, fs1, fs1, fs2, fs2, fs2 };
|
|
|
|
|
|
|
|
html->SetFonts(font.GetFaceName(), font.GetFaceName(), font_size);
|
|
|
|
html->Refresh();
|
|
|
|
|
|
|
|
const int& em = em_unit();
|
|
|
|
|
2019-04-25 13:06:44 +00:00
|
|
|
msw_buttons_rescale(this, em, { wxID_CLOSE});
|
|
|
|
|
|
|
|
const wxSize& size = wxSize(45 * em, 40 * em);
|
2019-04-18 13:05:17 +00:00
|
|
|
SetMinSize(size);
|
2019-04-25 13:06:44 +00:00
|
|
|
Fit();
|
2019-04-18 13:05:17 +00:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2018-04-10 14:27:42 +00:00
|
|
|
void ConfigSnapshotDialog::onLinkClicked(wxHtmlLinkEvent &event)
|
|
|
|
{
|
2018-04-11 10:21:15 +00:00
|
|
|
m_snapshot_to_activate = event.GetLinkInfo().GetHref();
|
|
|
|
this->EndModal(wxID_CLOSE);
|
|
|
|
this->Close();
|
2018-04-10 14:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigSnapshotDialog::onCloseDialog(wxEvent &)
|
|
|
|
{
|
|
|
|
this->EndModal(wxID_CLOSE);
|
|
|
|
this->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|