From 708037158e78dfe0552b3ed5d9498da1832e031b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 25 Apr 2019 15:06:44 +0200 Subject: [PATCH 1/4] Added msw_buttons_rescale() - Function for a scaling Dialog's buttons under MSW --- src/slic3r/GUI/AboutDialog.cpp | 4 ++- src/slic3r/GUI/ConfigSnapshotDialog.cpp | 7 ++-- src/slic3r/GUI/ConfigWizard.cpp | 23 ++++++++++-- src/slic3r/GUI/ConfigWizard_private.hpp | 4 +++ src/slic3r/GUI/Field.cpp | 18 +++++++--- src/slic3r/GUI/Field.hpp | 2 ++ src/slic3r/GUI/FirmwareDialog.cpp | 47 +++++++++++++++++-------- src/slic3r/GUI/FirmwareDialog.hpp | 10 +++++- src/slic3r/GUI/KBShortcutsDialog.cpp | 7 ++-- src/slic3r/GUI/OptionsGroup.cpp | 8 +++-- src/slic3r/GUI/Preferences.cpp | 11 +++--- src/slic3r/GUI/PrintHostDialogs.cpp | 15 ++++++-- src/slic3r/GUI/PrintHostDialogs.hpp | 4 ++- src/slic3r/GUI/SysInfoDialog.cpp | 11 +++--- src/slic3r/GUI/SysInfoDialog.hpp | 2 ++ src/slic3r/GUI/wxExtensions.cpp | 16 +++++++++ src/slic3r/GUI/wxExtensions.hpp | 3 +- 17 files changed, 149 insertions(+), 43 deletions(-) diff --git a/src/slic3r/GUI/AboutDialog.cpp b/src/slic3r/GUI/AboutDialog.cpp index fb1450ba1..b1a2556e7 100644 --- a/src/slic3r/GUI/AboutDialog.cpp +++ b/src/slic3r/GUI/AboutDialog.cpp @@ -133,13 +133,15 @@ void AboutDialog::on_dpi_changed(const wxRect &suggested_rect) const int& em = em_unit(); + msw_buttons_rescale(this, em, { wxID_CLOSE }); + m_html->SetMinSize(wxSize(-1, 16 * em)); m_html->Refresh(); const wxSize& size = wxSize(65 * em, 30 * em); SetMinSize(size); - SetSize(size); + Fit(); Refresh(); } diff --git a/src/slic3r/GUI/ConfigSnapshotDialog.cpp b/src/slic3r/GUI/ConfigSnapshotDialog.cpp index dd3e46229..b8634918b 100644 --- a/src/slic3r/GUI/ConfigSnapshotDialog.cpp +++ b/src/slic3r/GUI/ConfigSnapshotDialog.cpp @@ -6,6 +6,7 @@ #include "libslic3r/Utils.hpp" #include "GUI_App.hpp" +#include "wxExtensions.hpp" namespace Slic3r { namespace GUI { @@ -144,10 +145,12 @@ void ConfigSnapshotDialog::on_dpi_changed(const wxRect &suggested_rect) html->Refresh(); const int& em = em_unit(); - const wxSize& size = wxSize(45 * em, 40 * em); + msw_buttons_rescale(this, em, { wxID_CLOSE}); + + const wxSize& size = wxSize(45 * em, 40 * em); SetMinSize(size); - SetSize(size); + Fit(); Refresh(); } diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 3d41285bb..93cf1c73f 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -194,6 +194,9 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxSt title_sizer->Add(sel_all_std, 0, wxRIGHT, BTN_SPACING); title_sizer->Add(sel_all, 0, wxRIGHT, BTN_SPACING); title_sizer->Add(sel_none); + + // fill button indexes used later for buttons rescaling + m_button_indexes = { sel_all_std->GetId(), sel_all->GetId(), sel_none->GetId() }; } sizer->Add(title_sizer, 0, wxEXPAND | wxBOTTOM, BTN_SPACING); @@ -1057,8 +1060,8 @@ ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason) topsizer->AddSpacer(INDEX_MARGIN); topsizer->Add(p->hscroll, 1, wxEXPAND); - auto *btn_sel_all = new wxButton(this, wxID_ANY, _(L("Select all standard printers"))); - p->btnsizer->Add(btn_sel_all); + p->btn_sel_all = new wxButton(this, wxID_ANY, _(L("Select all standard printers"))); + p->btnsizer->Add(p->btn_sel_all); p->btn_prev = new wxButton(this, wxID_ANY, _(L("< &Back"))); p->btn_next = new wxButton(this, wxID_ANY, _(L("&Next >"))); @@ -1130,7 +1133,7 @@ ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason) p->btn_finish->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { this->EndModal(wxID_OK); }); p->btn_finish->Hide(); - btn_sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { + p->btn_sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { p->page_fff->select_all(true, false); p->page_msla->select_all(true, false); p->index->go_to(p->page_update); @@ -1179,6 +1182,20 @@ const wxString& ConfigWizard::name(const bool from_menu/* = false*/) void ConfigWizard::on_dpi_changed(const wxRect &suggested_rect) { p->index->msw_rescale(); + + const int& em = em_unit(); + + msw_buttons_rescale(this, em, { wxID_APPLY, + wxID_CANCEL, + p->btn_sel_all->GetId(), + p->btn_next->GetId(), + p->btn_prev->GetId() }); + + for (auto printer_picker: p->page_fff->printer_pickers) + msw_buttons_rescale(this, em, printer_picker->get_button_indexes()); + + // FIXME VK SetSize(???) + Refresh(); } diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index 31a990b60..95411e2aa 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -69,8 +69,11 @@ struct PrinterPicker: wxPanel void on_checkbox(const Checkbox *cbox, bool checked); int get_width() const { return width; } + const std::vector& get_button_indexes() { return m_button_indexes; } private: int width; + + std::vector m_button_indexes; }; struct ConfigWizardPage: wxPanel @@ -267,6 +270,7 @@ struct ConfigWizard::priv wxBoxSizer *btnsizer = nullptr; ConfigWizardPage *page_current = nullptr; ConfigWizardIndex *index = nullptr; + wxButton *btn_sel_all = nullptr; wxButton *btn_prev = nullptr; wxButton *btn_next = nullptr; wxButton *btn_finish = nullptr; diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 822361c5d..738ec2e00 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -379,8 +379,8 @@ void TextCtrl::change_field_value(wxEvent& event) void CheckBox::BUILD() { auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height); - if (m_opt.width >= 0) size.SetWidth(m_opt.width); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); bool check_value = m_opt.type == coBool ? m_opt.default_value->getBool() : m_opt.type == coBools ? @@ -413,6 +413,14 @@ boost::any& CheckBox::get_value() return m_value; } +void CheckBox::msw_rescale() +{ + Field::msw_rescale(); + + wxCheckBox* field = dynamic_cast(window); + field->SetMinSize(wxSize(-1, int(1.5f*field->GetFont().GetPixelSize().y +0.5f))); +} + int undef_spin_val = -9999; //! Probably, It's not necessary void SpinCtrl::BUILD() { @@ -849,9 +857,11 @@ void Choice::msw_rescale() */ field->Clear(); wxSize size(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit); size.SetWidth((m_opt.width > 0 ? m_opt.width : m_width) * m_em_unit); - + + // Set rescaled min height to correct layout + field->SetMinSize(wxSize(-1, int(1.5f*field->GetFont().GetPixelSize().y + 0.5f))); + // Set rescaled size field->SetSize(size); size_t idx, counter = idx = 0; diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 516570ea8..88ea39036 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -319,6 +319,8 @@ public: } boost::any& get_value() override; + void msw_rescale() override; + void enable() override { dynamic_cast(window)->Enable(); } void disable() override { dynamic_cast(window)->Disable(); } wxWindow* getWindow() override { return window; } diff --git a/src/slic3r/GUI/FirmwareDialog.cpp b/src/slic3r/GUI/FirmwareDialog.cpp index 4fdc57679..5de5626db 100644 --- a/src/slic3r/GUI/FirmwareDialog.cpp +++ b/src/slic3r/GUI/FirmwareDialog.cpp @@ -18,6 +18,7 @@ #include "MsgDialog.hpp" #include "../Utils/HexFile.hpp" #include "../Utils/Serial.hpp" +#include "wxExtensions.hpp" // wx includes need to come after asio because of the WinSock.h problem #include "FirmwareDialog.hpp" @@ -118,6 +119,10 @@ struct FirmwareDialog::priv wxTimer timer_pulse; + int min_width; + int min_height; + int min_height_expanded; + // Async modal dialog during flashing std::mutex mutex; int modal_response; @@ -735,18 +740,10 @@ FirmwareDialog::FirmwareDialog(wxWindow *parent) : GUI::DPIDialog(parent, wxID_ANY, _(L("Firmware flasher")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), p(new priv(this)) { - enum { - DIALOG_MARGIN = 15, - SPACING = 10, - MIN_WIDTH = 50, - MIN_HEIGHT = 18, - MIN_HEIGHT_EXPANDED = 40, - }; - const int em = GUI::wxGetApp().em_unit(); - int min_width = MIN_WIDTH * em; - int min_height = MIN_HEIGHT * em; - int min_height_expanded = MIN_HEIGHT_EXPANDED * em; + p->min_width = MIN_WIDTH * em; + p->min_height = MIN_HEIGHT * em; + p->min_height_expanded = MIN_HEIGHT_EXPANDED * em; /* get current font from application, * because of wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) function @@ -825,10 +822,10 @@ FirmwareDialog::FirmwareDialog(wxWindow *parent) : auto *topsizer = new wxBoxSizer(wxVERTICAL); topsizer->Add(panel, 1, wxEXPAND | wxALL, DIALOG_MARGIN); - SetMinSize(wxSize(min_width, min_height)); + SetMinSize(wxSize(p->min_width, p->min_height)); SetSizerAndFit(topsizer); const auto size = GetSize(); - SetSize(std::max(size.GetWidth(), static_cast(min_width)), std::max(size.GetHeight(), static_cast(min_height))); + SetSize(std::max(size.GetWidth(), static_cast(p->min_width)), std::max(size.GetHeight(), static_cast(p->min_height))); Layout(); SetEscapeId(wxID_CLOSE); // To close the dialog using "Esc" button @@ -844,11 +841,11 @@ FirmwareDialog::FirmwareDialog(wxWindow *parent) : p->spoiler->Bind(wxEVT_COLLAPSIBLEPANE_CHANGED, [=](wxCollapsiblePaneEvent &evt) { if (evt.GetCollapsed()) { - this->SetMinSize(wxSize(min_width, min_height)); + this->SetMinSize(wxSize(p->min_width, p->min_height)); const auto new_height = this->GetSize().GetHeight() - this->p->txt_stdout->GetSize().GetHeight(); this->SetSize(this->GetSize().GetWidth(), new_height); } else { - this->SetMinSize(wxSize(min_width, min_height_expanded)); + this->SetMinSize(wxSize(p->min_width, p->min_height_expanded)); } this->Layout(); @@ -903,5 +900,25 @@ void FirmwareDialog::run(wxWindow *parent) dialog.ShowModal(); } +void FirmwareDialog::on_dpi_changed(const wxRect &suggested_rect) +{ + const int& em = em_unit(); + + msw_buttons_rescale(this, em, { p->btn_close->GetId(), + p->btn_rescan->GetId(), + p->btn_flash->GetId(), + p->hex_picker->GetPickerCtrl()->GetId() + }); + + p->min_width = MIN_WIDTH * em; + p->min_height = MIN_HEIGHT * em; + p->min_height_expanded = MIN_HEIGHT_EXPANDED * em; + + const int min_height = p->spoiler->IsExpanded() ? p->min_height_expanded : p->min_height; + SetMinSize(wxSize(p->min_width, min_height)); + Fit(); + + Refresh(); +} } diff --git a/src/slic3r/GUI/FirmwareDialog.hpp b/src/slic3r/GUI/FirmwareDialog.hpp index a1eac00de..7c688d379 100644 --- a/src/slic3r/GUI/FirmwareDialog.hpp +++ b/src/slic3r/GUI/FirmwareDialog.hpp @@ -12,6 +12,14 @@ namespace Slic3r { class FirmwareDialog: public GUI::DPIDialog { + enum { + DIALOG_MARGIN = 15, + SPACING = 10, + MIN_WIDTH = 50, + MIN_HEIGHT = /*18*/25, + MIN_HEIGHT_EXPANDED = 40, + }; + public: FirmwareDialog(wxWindow *parent); FirmwareDialog(FirmwareDialog &&) = delete; @@ -23,7 +31,7 @@ public: static void run(wxWindow *parent); protected: - void on_dpi_changed(const wxRect &suggested_rect) override{;} + void on_dpi_changed(const wxRect &suggested_rect) override; private: struct priv; std::unique_ptr p; diff --git a/src/slic3r/GUI/KBShortcutsDialog.cpp b/src/slic3r/GUI/KBShortcutsDialog.cpp index 7f77474f2..066bc54fa 100644 --- a/src/slic3r/GUI/KBShortcutsDialog.cpp +++ b/src/slic3r/GUI/KBShortcutsDialog.cpp @@ -196,11 +196,14 @@ void KBShortcutsDialog::on_dpi_changed(const wxRect &suggested_rect) for (wxStaticBitmap* bmp : m_head_bitmaps) bmp->SetBitmap(m_logo_bmp.bmp()); - const int& em = em_unit(); + const int em = em_unit(); + + msw_buttons_rescale(this, em, { wxID_OK }); + const wxSize& size = wxSize(85 * em, 75 * em); SetMinSize(size); - SetSize(size); + Fit(); Refresh(); } diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index fdbe3b038..099ebc8ba 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -516,17 +516,19 @@ void ConfigOptionsGroup::msw_rescale() { auto label = dynamic_cast(label_item->GetWindow()); if (label != nullptr) { - label->SetMinSize(wxSize(label_width*em, -1)); + const int label_height = int(1.5f*label->GetFont().GetPixelSize().y + 0.5f); + label->SetMinSize(wxSize(label_width*em, /*-1*/label_height)); } } - else if (label_item->IsSizer()) // case when we nave near_label_widget + else if (label_item->IsSizer()) // case when we have near_label_widget { const wxSizerItem* l_item = label_item->GetSizer()->GetItem(1); if (l_item->IsWindow()) { auto label = dynamic_cast(l_item->GetWindow()); if (label != nullptr) { - label->SetMinSize(wxSize(label_width*em, -1)); + const int label_height = int(1.5f*label->GetFont().GetPixelSize().y + 0.5f); + label->SetMinSize(wxSize(label_width*em, /*-1*/label_height)); } } } diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 69f4e3493..81d242d4f 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -8,7 +8,7 @@ namespace GUI { PreferencesDialog::PreferencesDialog(wxWindow* parent) : DPIDialog(parent, wxID_ANY, _(L("Preferences")), wxDefaultPosition, - wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) + wxDefaultSize, wxDEFAULT_DIALOG_STYLE) { build(); } @@ -146,11 +146,14 @@ void PreferencesDialog::on_dpi_changed(const wxRect &suggested_rect) { m_optgroup->msw_rescale(); - const int& em = em_unit(); - const wxSize& size = wxSize(50 * em, 29 * em); + const int em = em_unit(); + + msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); + + const wxSize& size = wxSize(47 * em, 28 * em); SetMinSize(size); - SetSize(size); + Fit(); Refresh(); } diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index 4fb03594b..2b6e4f2a2 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -19,6 +19,7 @@ #include "MsgDialog.hpp" #include "I18N.hpp" #include "../Utils/PrintHost.hpp" +#include "wxExtensions.hpp" namespace fs = boost::filesystem; @@ -136,8 +137,6 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent) , on_error_evt(this, EVT_PRINTHOST_ERROR, &PrintHostQueueDialog::on_error, this) , on_cancel_evt(this, EVT_PRINTHOST_CANCEL, &PrintHostQueueDialog::on_cancel, this) { - enum { HEIGHT = 60, WIDTH = 30, SPACING = 5 }; - const auto em = GetTextExtent("m").x; SetSize(wxSize(HEIGHT * em, WIDTH * em)); @@ -202,6 +201,18 @@ void PrintHostQueueDialog::append_job(const PrintHostJob &job) job_list->AppendItem(fields, static_cast(ST_NEW)); } +void PrintHostQueueDialog::on_dpi_changed(const wxRect &suggested_rect) +{ + const int& em = em_unit(); + + msw_buttons_rescale(this, em, { wxID_DELETE, wxID_CANCEL, btn_error->GetId() }); + + SetMinSize(wxSize(HEIGHT * em, WIDTH * em)); + + Fit(); + Refresh(); +} + PrintHostQueueDialog::JobState PrintHostQueueDialog::get_state(int idx) { wxCHECK_MSG(idx >= 0 && idx < job_list->GetItemCount(), ST_ERROR, "Out of bounds access to job list"); diff --git a/src/slic3r/GUI/PrintHostDialogs.hpp b/src/slic3r/GUI/PrintHostDialogs.hpp index e6c46aae6..427c4f6bf 100644 --- a/src/slic3r/GUI/PrintHostDialogs.hpp +++ b/src/slic3r/GUI/PrintHostDialogs.hpp @@ -64,7 +64,7 @@ public: void append_job(const PrintHostJob &job); protected: - void on_dpi_changed(const wxRect &suggested_rect) override { Refresh(); } + void on_dpi_changed(const wxRect &suggested_rect) override; private: enum Column { @@ -85,6 +85,8 @@ private: ST_COMPLETED, }; + enum { HEIGHT = 60, WIDTH = 30, SPACING = 5 }; + wxButton *btn_cancel; wxButton *btn_error; wxDataViewListCtrl *job_list; diff --git a/src/slic3r/GUI/SysInfoDialog.cpp b/src/slic3r/GUI/SysInfoDialog.cpp index 31f75a926..162a36c75 100644 --- a/src/slic3r/GUI/SysInfoDialog.cpp +++ b/src/slic3r/GUI/SysInfoDialog.cpp @@ -117,9 +117,10 @@ SysInfoDialog::SysInfoDialog() } wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK); - auto btn_copy_to_clipboard = new wxButton(this, wxID_ANY, "Copy to Clipboard", wxDefaultPosition, wxDefaultSize); - buttons->Insert(0, btn_copy_to_clipboard, 0, wxLEFT, 5); - btn_copy_to_clipboard->Bind(wxEVT_BUTTON, &SysInfoDialog::onCopyToClipboard, this); + m_btn_copy_to_clipboard = new wxButton(this, wxID_ANY, "Copy to Clipboard", wxDefaultPosition, wxDefaultSize); + + buttons->Insert(0, m_btn_copy_to_clipboard, 0, wxLEFT, 5); + m_btn_copy_to_clipboard->Bind(wxEVT_BUTTON, &SysInfoDialog::onCopyToClipboard, this); this->SetEscapeId(wxID_OK); this->Bind(wxEVT_BUTTON, &SysInfoDialog::onCloseDialog, this, wxID_OK); @@ -146,6 +147,8 @@ void SysInfoDialog::on_dpi_changed(const wxRect &suggested_rect) const int& em = em_unit(); + msw_buttons_rescale(this, em, { wxID_OK, m_btn_copy_to_clipboard->GetId() }); + m_opengl_info_html->SetMinSize(wxSize(-1, 16 * em)); m_opengl_info_html->SetFonts(font.GetFaceName(), font.GetFaceName(), font_size); m_opengl_info_html->Refresh(); @@ -153,7 +156,7 @@ void SysInfoDialog::on_dpi_changed(const wxRect &suggested_rect) const wxSize& size = wxSize(65 * em, 55 * em); SetMinSize(size); - SetSize(size); + Fit(); Refresh(); } diff --git a/src/slic3r/GUI/SysInfoDialog.hpp b/src/slic3r/GUI/SysInfoDialog.hpp index dec4b5635..3b1459648 100644 --- a/src/slic3r/GUI/SysInfoDialog.hpp +++ b/src/slic3r/GUI/SysInfoDialog.hpp @@ -17,6 +17,8 @@ class SysInfoDialog : public DPIDialog wxHtmlWindow* m_opengl_info_html; wxHtmlWindow* m_html; + wxButton* m_btn_copy_to_clipboard; + public: SysInfoDialog(); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 277494034..573106ae7 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -267,6 +267,22 @@ void wxDataViewTreeCtrlComboPopup::OnDataViewTreeCtrlSelection(wxCommandEvent& e cmb->SetText(selected); } +/* Function for rescale of buttons in Dialog under MSW if dpi is changed. + * btn_ids - vector of buttons identifiers + */ +void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector& btn_ids) +{ + const wxSize& btn_size = wxSize(-1, int(2.5f * em_unit + 0.5f)); + + for (int btn_id : btn_ids) { + // There is a case [FirmwareDialog], when we have wxControl instead of wxButton + // so let casting everything to the wxControl + wxControl* btn = static_cast(dlg->FindWindowById(btn_id, dlg)); + if (btn) + btn->SetMinSize(btn_size); + } +} + /* Function for getting of em_unit value from correct parent. * In most of cases it is m_em_unit value from GUI_App, * but for DPIDialogs it's its own value. diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 7d63438c0..69369b3ff 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -31,7 +31,8 @@ wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxStrin wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, const wxString& description, std::function cb, wxEvtHandler* event_handler); -int em_unit(wxWindow* win); +void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector& btn_ids); +int em_unit(wxWindow* win); wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, const int px_cnt = 16, const bool is_horizontal = false); From 545d9df3c0db94615d87a83b6872f6cf733c4ef9 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 25 Apr 2019 16:23:50 +0200 Subject: [PATCH 2/4] Added missed class declaration under OSX --- src/slic3r/GUI/wxExtensions.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 69369b3ff..e40306ea1 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -31,6 +31,7 @@ wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxStrin wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, const wxString& description, std::function cb, wxEvtHandler* event_handler); +class wxDialog; void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector& btn_ids); int em_unit(wxWindow* win); From ca50d1b55a0d17a29d7658e82665e9b875c1901d Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 25 Apr 2019 18:03:17 +0200 Subject: [PATCH 3/4] Memory optimization of SLA export, logging of memory consumption during SLA slicing (just on Windows as of now). --- src/libslic3r/Rasterizer/Rasterizer.hpp | 15 ++++++--------- src/libslic3r/SLAPrint.cpp | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/Rasterizer/Rasterizer.hpp b/src/libslic3r/Rasterizer/Rasterizer.hpp index d4d2277c4..09b166d98 100644 --- a/src/libslic3r/Rasterizer/Rasterizer.hpp +++ b/src/libslic3r/Rasterizer/Rasterizer.hpp @@ -20,29 +20,26 @@ class RawBytes { void operator()(std::uint8_t *rawptr); }; - std::unique_ptr m_buffer = nullptr; - size_t m_size = 0; + std::vector m_buffer; public: RawBytes() = default; - RawBytes(std::uint8_t *rawptr, size_t s): m_buffer(rawptr), m_size(s) {} + RawBytes(std::uint8_t *rawptr, size_t s): m_buffer(rawptr, rawptr + s) { MinzDeleter()(rawptr); } - size_t size() const { return m_size; } - const uint8_t * data() { return m_buffer.get(); } + size_t size() const { return m_buffer.size(); } + const uint8_t * data() { return m_buffer.data(); } // ///////////////////////////////////////////////////////////////////////// // FIXME: the following is needed for MSVC2013 compatibility // ///////////////////////////////////////////////////////////////////////// RawBytes(const RawBytes&) = delete; - RawBytes(RawBytes&& mv): - m_buffer(std::move(mv.m_buffer)), m_size(mv.m_size) {} + RawBytes(RawBytes&& mv) : m_buffer(std::move(mv.m_buffer)) {} RawBytes& operator=(const RawBytes&) = delete; RawBytes& operator=(RawBytes&& mv) { - m_buffer.swap(mv.m_buffer); - m_size = mv.m_size; + m_buffer = std::move(mv.m_buffer); return *this; } diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 284073ca4..2bbcc700a 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -1823,7 +1823,7 @@ void SLAPrint::StatusReporter::operator()( SLAPrint &p, double st, const std::string &msg, unsigned flags) { m_st = st; - BOOST_LOG_TRIVIAL(info) << st << "% " << msg; + BOOST_LOG_TRIVIAL(info) << st << "% " << msg << log_memory_info(); p.set_status(int(std::round(st)), msg, flags); } From afbe0d9e60bcb5bd7c4efa75585be417ee8ccb62 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 25 Apr 2019 18:48:31 +0200 Subject: [PATCH 4/4] Further optimizations for SLA memory usage. --- src/libslic3r/Rasterizer/Rasterizer.cpp | 29 ++++++++++++------------- src/libslic3r/Rasterizer/Rasterizer.hpp | 10 ++------- src/libslic3r/SLA/SLASupportTree.cpp | 11 ++++++++++ src/libslic3r/SLAPrint.cpp | 12 +++++++--- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/libslic3r/Rasterizer/Rasterizer.cpp b/src/libslic3r/Rasterizer/Rasterizer.cpp index 8eb721b43..6384a241f 100644 --- a/src/libslic3r/Rasterizer/Rasterizer.cpp +++ b/src/libslic3r/Rasterizer/Rasterizer.cpp @@ -248,20 +248,21 @@ RawBytes Raster::save(Raster::Compression comp) { assert(m_impl); - std::uint8_t *ptr = nullptr; size_t s = 0; + std::vector data; size_t s = 0; switch(comp) { case Compression::PNG: { - void *rawdata = tdefl_write_image_to_png_file_in_memory( m_impl->buffer().data(), int(resolution().width_px), int(resolution().height_px), 1, &s); if(rawdata == nullptr) break; - - ptr = static_cast(rawdata); - + auto ptr = static_cast(rawdata); + + data.reserve(s); std::copy(ptr, ptr + s, std::back_inserter(data)); + + MZ_FREE(rawdata); break; } case Compression::RAW: { @@ -270,21 +271,19 @@ RawBytes Raster::save(Raster::Compression comp) std::to_string(m_impl->resolution().height_px) + " " + "255 "; auto sz = m_impl->buffer().size()*sizeof(Impl::TBuffer::value_type); - s = sz + header.size(); - ptr = static_cast(MZ_MALLOC(s)); - + + data.reserve(s); + auto buff = reinterpret_cast(m_impl->buffer().data()); - std::copy(buff, buff+sz, ptr + header.size()); + std::copy(header.begin(), header.end(), std::back_inserter(data)); + std::copy(buff, buff+sz, std::back_inserter(data)); + + break; } } - return {ptr, s}; -} - -void RawBytes::MinzDeleter::operator()(uint8_t *rawptr) -{ - MZ_FREE(rawptr); + return {std::move(data)}; } } diff --git a/src/libslic3r/Rasterizer/Rasterizer.hpp b/src/libslic3r/Rasterizer/Rasterizer.hpp index 09b166d98..3fffe1a36 100644 --- a/src/libslic3r/Rasterizer/Rasterizer.hpp +++ b/src/libslic3r/Rasterizer/Rasterizer.hpp @@ -15,18 +15,12 @@ class ExPolygon; // Raw byte buffer paired with its size. Suitable for compressed PNG data. class RawBytes { - class MinzDeleter { - public: - void operator()(std::uint8_t *rawptr); - }; - std::vector m_buffer; - public: RawBytes() = default; - RawBytes(std::uint8_t *rawptr, size_t s): m_buffer(rawptr, rawptr + s) { MinzDeleter()(rawptr); } - + RawBytes(std::vector&& data): m_buffer(std::move(data)) {} + size_t size() const { return m_buffer.size(); } const uint8_t * data() { return m_buffer.data(); } diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp index 75f9b0140..1e139ebfb 100644 --- a/src/libslic3r/SLA/SLASupportTree.cpp +++ b/src/libslic3r/SLA/SLASupportTree.cpp @@ -846,6 +846,16 @@ public: if(!meshcache_valid) merged_mesh(); return model_height; } + + // Intended to be called after the generation is fully complete + void clear_support_data() { + merged_mesh(); // in case the mesh is not generated, it should be... + m_heads.clear(); + m_pillars.clear(); + m_junctions.clear(); + m_bridges.clear(); + m_compact_bridges.clear(); + } }; @@ -2285,6 +2295,7 @@ SLASupportTree::SLASupportTree(const std::vector &points, { m_impl->ground_level = emesh.ground_level() - cfg.object_elevation_mm; generate(points, emesh, cfg, ctl); + m_impl->clear_support_data(); } SLASupportTree::SLASupportTree(const SLASupportTree &c): diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 2bbcc700a..ecae36cc5 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -436,6 +436,12 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, const DynamicPrintConf if (new_objects) update_apply_status(false); } + + if(m_objects.empty()) { + m_printer.release(); + m_printer_input.clear(); + m_print_statistics.clear(); + } #ifdef _DEBUG check_model_ids_equal(m_model, model); @@ -669,7 +675,7 @@ void SLAPrint::process() // Slicing the model object. This method is oversimplified and needs to // be compared with the fff slicing algorithm for verification auto slice_model = [this, ilhs, ilh](SLAPrintObject& po) { - TriangleMesh mesh = po.transformed_mesh(); + const TriangleMesh& mesh = po.transformed_mesh(); // We need to prepare the slice index... @@ -708,7 +714,7 @@ void SLAPrint::process() po.m_model_height_levels.emplace_back(it->slice_level()); } - mesh.require_shared_vertices(); // TriangleMeshSlicer needs this +// mesh.require_shared_vertices(); // TriangleMeshSlicer needs this TriangleMeshSlicer slicer(&mesh); po.m_model_slices.clear(); @@ -1534,7 +1540,7 @@ SLAPrintObject::SLAPrintObject(SLAPrint *print, ModelObject *model_object): Inherited(print, model_object), m_stepmask(slaposCount, true), m_transformed_rmesh( [this](TriangleMesh& obj){ - obj = m_model_object->raw_mesh(); obj.transform(m_trafo); + obj = m_model_object->raw_mesh(); obj.transform(m_trafo); obj.require_shared_vertices(); }) { }