Fixed code review issues

This commit is contained in:
YuSanka 2017-12-26 23:04:54 +01:00
parent 61247fe8d3
commit 838a0885fe
4 changed files with 242 additions and 253 deletions

View File

@ -177,6 +177,12 @@ add_library(libslic3r_gui STATIC
${LIBDIR}/slic3r/GUI/PresetHints.hpp ${LIBDIR}/slic3r/GUI/PresetHints.hpp
${LIBDIR}/slic3r/GUI/GUI.cpp ${LIBDIR}/slic3r/GUI/GUI.cpp
${LIBDIR}/slic3r/GUI/GUI.hpp ${LIBDIR}/slic3r/GUI/GUI.hpp
${LIBDIR}/slic3r/GUI/Tab.cpp
${LIBDIR}/slic3r/GUI/Tab.h
${LIBDIR}/slic3r/GUI/Field.cpp
${LIBDIR}/slic3r/GUI/Field.hpp
${LIBDIR}/slic3r/GUI/OptionsGroup.cpp
${LIBDIR}/slic3r/GUI/OptionsGroup.hpp
) )
add_library(admesh STATIC add_library(admesh STATIC

View File

@ -19,16 +19,6 @@
//#include "slic3r_gui.hpp" //#include "slic3r_gui.hpp"
#include "GUI.hpp" #include "GUI.hpp"
#if SLIC3R_CPPVER==11
// C++14 has make_unique, C++11 doesn't. This is really useful so we're going to steal it.
template<class T, class...Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
std::unique_ptr<T> ret (new T(std::forward<Args>(args)...));
return ret;
}
#endif
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
class Field; class Field;
@ -196,9 +186,7 @@ public:
void BUILD() override; void BUILD() override;
void set_selection(); void set_selection();
void set_value(const std::string value);// { void set_value(const std::string value);
// dynamic_cast<wxComboBox*>(window)->SetValue(value);
// }
void set_value(boost::any value) { void set_value(boost::any value) {
dynamic_cast<wxComboBox*>(window)->SetValue(boost::any_cast<std::string>(value)); dynamic_cast<wxComboBox*>(window)->SetValue(boost::any_cast<std::string>(value));
} }
@ -252,21 +240,16 @@ public:
void BUILD() override; void BUILD() override;
void set_value(const Pointf value);// { void set_value(const Pointf value);
// dynamic_cast<wxColourPickerCtrl*>(sizer)->SetColour(value);
// }
void set_value(boost::any value) { void set_value(boost::any value) {
// dynamic_cast<wxColourPickerCtrl*>(sizer)->SetColour(boost::any_cast<std::string>(value)); // dynamic_cast<wxColourPickerCtrl*>(sizer)->SetColour(boost::any_cast<std::string>(value));
} }
boost::any get_value() override; //{ boost::any get_value() override;
// return boost::any(dynamic_cast<wxColourPickerCtrl*>(sizer)->GetColour());
// }
void enable() override { /*dynamic_cast<wxTextCtrl*>(window)*/ void enable() override {
x_textctrl->Enable(); x_textctrl->Enable();
y_textctrl->Enable(); }; y_textctrl->Enable(); };
void disable() override{ /*dynamic_cast<wxTextCtrl*>(window)*/ void disable() override{
x_textctrl->Disable(); x_textctrl->Disable();
y_textctrl->Disable(); }; y_textctrl->Disable(); };
wxSizer* getSizer() override { return sizer; } wxSizer* getSizer() override { return sizer; }

View File

@ -12,6 +12,7 @@
#include "Tab.h" #include "Tab.h"
#include "PresetBundle.hpp" #include "PresetBundle.hpp"
#include "../../libslic3r/Utils.hpp"
//#include "GCodeSender.hpp" //#include "GCodeSender.hpp"
namespace Slic3r { namespace Slic3r {
@ -20,7 +21,7 @@ namespace GUI {
// sub new // sub new
void CTab::create_preset_tab(PresetBundle *preset_bundle) void CTab::create_preset_tab(PresetBundle *preset_bundle)
{ {
preset_bundle_ = preset_bundle; m_preset_bundle = preset_bundle;
// Vertical sizer to hold the choice menu and the rest of the page. // Vertical sizer to hold the choice menu and the rest of the page.
CTab *panel = this; CTab *panel = this;
auto *sizer = new wxBoxSizer(wxVERTICAL); auto *sizer = new wxBoxSizer(wxVERTICAL);
@ -37,65 +38,65 @@ void CTab::create_preset_tab(PresetBundle *preset_bundle)
_T("Third") _T("Third")
}; };
presets_choice_ = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1)/*, nCntEl, choices, wxCB_READONLY*/); m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1)/*, nCntEl, choices, wxCB_READONLY*/);
const wxBitmap* bmp = new wxBitmap(wxT("var\\flag-green-icon.png"), wxBITMAP_TYPE_PNG); const wxBitmap* bmp = new wxBitmap(wxString::FromUTF8(Slic3r::var("flag-green-icon.png").c_str()), wxBITMAP_TYPE_PNG);
for (auto el:choices) for (auto el:choices)
presets_choice_->Append(wxString::FromUTF8(el).c_str(), *bmp); m_presets_choice->Append(wxString::FromUTF8(el).c_str(), *bmp);
presets_choice_->SetSelection(presets_choice_->GetCount() - 1); m_presets_choice->SetSelection(m_presets_choice->GetCount() - 1);
//buttons //buttons
wxBitmap bmpMenu; wxBitmap bmpMenu;
bmpMenu = wxBitmap(wxT("var\\disk.png"), wxBITMAP_TYPE_PNG); bmpMenu = wxBitmap(wxString::FromUTF8(Slic3r::var("disk.png").c_str()), wxBITMAP_TYPE_PNG);
btn_save_preset_ = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); m_btn_save_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
bmpMenu = wxBitmap(wxT("var\\delete.png"), wxBITMAP_TYPE_PNG); bmpMenu = wxBitmap(wxString::FromUTF8(Slic3r::var("delete.png").c_str()), wxBITMAP_TYPE_PNG);
btn_delete_preset_ = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); m_btn_delete_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
// $self->{show_incompatible_presets} = 0; // !!! // $self->{show_incompatible_presets} = 0; // !!!
bmp_show_incompatible_presets_ = new wxBitmap(wxT("var\\flag-red-icon.png"), wxBITMAP_TYPE_PNG); m_bmp_show_incompatible_presets = new wxBitmap(wxString::FromUTF8(Slic3r::var("flag-red-icon.png").c_str()), wxBITMAP_TYPE_PNG);
bmp_hide_incompatible_presets_ = new wxBitmap(wxT("var\\flag-green-icon.png"), wxBITMAP_TYPE_PNG); m_bmp_hide_incompatible_presets = new wxBitmap(wxString::FromUTF8(Slic3r::var("flag-green-icon.png").c_str()), wxBITMAP_TYPE_PNG);
btn_hide_incompatible_presets_ = new wxBitmapButton(panel, wxID_ANY, *bmp_hide_incompatible_presets_, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); m_btn_hide_incompatible_presets = new wxBitmapButton(panel, wxID_ANY, *m_bmp_hide_incompatible_presets, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
btn_save_preset_->SetToolTip(wxT("Save current ") + wxString(title_));// (stTitle); m_btn_save_preset->SetToolTip(wxT("Save current ") + wxString(m_title));// (stTitle);
btn_delete_preset_->SetToolTip(_T("Delete this preset")); m_btn_delete_preset->SetToolTip(_T("Delete this preset"));
btn_delete_preset_->Disable(); m_btn_delete_preset->Disable();
hsizer_ = new wxBoxSizer(wxHORIZONTAL); m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(hsizer_, 0, wxBOTTOM, 3); sizer->Add(m_hsizer, 0, wxBOTTOM, 3);
hsizer_->Add(presets_choice_, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); m_hsizer->Add(m_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
hsizer_->AddSpacer(4); m_hsizer->AddSpacer(4);
hsizer_->Add(btn_save_preset_, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->Add(m_btn_save_preset, 0, wxALIGN_CENTER_VERTICAL);
hsizer_->AddSpacer(4); m_hsizer->AddSpacer(4);
hsizer_->Add(btn_delete_preset_, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->Add(m_btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL);
hsizer_->AddSpacer(16); m_hsizer->AddSpacer(16);
hsizer_->Add(btn_hide_incompatible_presets_, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->Add(m_btn_hide_incompatible_presets, 0, wxALIGN_CENTER_VERTICAL);
//Horizontal sizer to hold the tree and the selected page. //Horizontal sizer to hold the tree and the selected page.
hsizer_ = new wxBoxSizer(wxHORIZONTAL); m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(hsizer_, 1, wxEXPAND, 0); sizer->Add(m_hsizer, 1, wxEXPAND, 0);
//left vertical sizer //left vertical sizer
left_sizer_ = new wxBoxSizer(wxVERTICAL); m_left_sizer = new wxBoxSizer(wxVERTICAL);
hsizer_->Add(left_sizer_, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3); m_hsizer->Add(m_left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
// tree // tree
treectrl_ = new wxTreeCtrl(panel, wxID_ANY/*ID_TAB_TREE*/, wxDefaultPosition, wxSize(185, -1), wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS); m_treectrl = new wxTreeCtrl(panel, wxID_ANY/*ID_TAB_TREE*/, wxDefaultPosition, wxSize(185, -1), wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS);
left_sizer_->Add(treectrl_, 1, wxEXPAND); m_left_sizer->Add(m_treectrl, 1, wxEXPAND);
icons_ = new wxImageList(16, 16, true, 1/*, 1*/); m_icons = new wxImageList(16, 16, true, 1/*, 1*/);
// Index of the last icon inserted into $self->{icons}. // Index of the last icon inserted into $self->{icons}.
icon_count = -1; m_icon_count = -1;
treectrl_->AssignImageList(icons_); m_treectrl->AssignImageList(m_icons);
treectrl_->AddRoot("root"); m_treectrl->AddRoot("root");
treectrl_->SetIndent(0); m_treectrl->SetIndent(0);
disable_tree_sel_changed_event_ = 0; m_disable_tree_sel_changed_event = 0;
treectrl_->Bind(wxEVT_TREE_SEL_CHANGED, &CTab::OnTreeSelChange, this); m_treectrl->Bind(wxEVT_TREE_SEL_CHANGED, &CTab::OnTreeSelChange, this);
treectrl_->Bind(wxEVT_KEY_DOWN, &CTab::OnKeyDown, this); m_treectrl->Bind(wxEVT_KEY_DOWN, &CTab::OnKeyDown, this);
treectrl_->Bind(wxEVT_COMBOBOX, &CTab::OnComboBox, this); m_treectrl->Bind(wxEVT_COMBOBOX, &CTab::OnComboBox, this);
btn_save_preset_->Bind(wxEVT_BUTTON, &CTab::save_preset, this); m_btn_save_preset->Bind(wxEVT_BUTTON, &CTab::save_preset, this);
btn_delete_preset_->Bind(wxEVT_BUTTON, &CTab::delete_preset, this); m_btn_delete_preset->Bind(wxEVT_BUTTON, &CTab::delete_preset, this);
btn_hide_incompatible_presets_->Bind(wxEVT_BUTTON, &CTab::_toggle_show_hide_incompatible, this); m_btn_hide_incompatible_presets->Bind(wxEVT_BUTTON, &CTab::toggle_show_hide_incompatible, this);
// Initialize the DynamicPrintConfig by default keys/values. // Initialize the DynamicPrintConfig by default keys/values.
// Possible %params keys: no_controller // Possible %params keys: no_controller
@ -104,34 +105,34 @@ void CTab::create_preset_tab(PresetBundle *preset_bundle)
// _update(); // _update();
} }
CPageShp CTab::add_options_page(wxString title, wxString icon) CPageShp CTab::add_options_page(wxString title, std::string icon)
{ {
// Index of icon in an icon list $self->{icons}. // Index of icon in an icon list $self->{icons}.
auto icon_idx = 0; auto icon_idx = 0;
if (!icon.IsEmpty()) { if (!icon.empty()) {
try { icon_idx = icon_index_.at(icon);} try { icon_idx = m_icon_index.at(icon);}
catch (std::out_of_range e) { icon_idx = -1; } catch (std::out_of_range e) { icon_idx = -1; }
if (icon_idx == -1) { if (icon_idx == -1) {
// Add a new icon to the icon list. // Add a new icon to the icon list.
const auto img_icon = new wxIcon(wxT("var\\") + icon, wxBITMAP_TYPE_PNG); const auto img_icon = new wxIcon(wxString::FromUTF8(Slic3r::var(/*"" + */icon).c_str()), wxBITMAP_TYPE_PNG);
icons_->Add(*img_icon); m_icons->Add(*img_icon);
icon_idx = ++icon_count; // $icon_idx = $self->{icon_count} + 1; $self->{icon_count} = $icon_idx; icon_idx = ++m_icon_count; // $icon_idx = $self->{icon_count} + 1; $self->{icon_count} = $icon_idx;
icon_index_[icon] = icon_idx; m_icon_index[icon] = icon_idx;
} }
} }
// Initialize the page. // Initialize the page.
CPageShp page(new CPage(this, title, icon_idx)); CPageShp page(new CPage(this, title, icon_idx));
page->SetScrollbars(1, 1, 1, 1); page->SetScrollbars(1, 1, 1, 1);
page->Hide(); page->Hide();
hsizer_->Add(page.get(), 1, wxEXPAND | wxLEFT, 5); m_hsizer->Add(page.get(), 1, wxEXPAND | wxLEFT, 5);
pages_.push_back(page); m_pages.push_back(page);
page->set_config(&config_); page->set_config(&m_config);
return page; return page;
} }
void CTab::load_key_value_(std::string opt_key, std::vector<std::string> value) void CTab::load_key_value(std::string opt_key, std::vector<std::string> value)
{ {
// # To be called by custom widgets, load a value into a config, // # To be called by custom widgets, load a value into a config,
// # update the preset selection boxes (the dirty flags) // # update the preset selection boxes (the dirty flags)
@ -149,8 +150,8 @@ void CTab::load_key_value_(std::string opt_key, std::vector<std::string> value)
void CTabPrint::build() void CTabPrint::build()
{ {
config_ = preset_bundle_->prints.get_edited_preset().config; m_config = m_preset_bundle->prints.get_edited_preset().config;
config_def_ = config_.def(); m_config_def = m_config.def();
auto page = add_options_page("Layers and perimeters", "layers.png"); auto page = add_options_page("Layers and perimeters", "layers.png");
auto optgroup = page->new_optgroup("Layer height"); auto optgroup = page->new_optgroup("Layer height");
@ -342,14 +343,16 @@ void CTabPrint::build()
page = add_options_page("Dependencies", "wrench.png"); page = add_options_page("Dependencies", "wrench.png");
optgroup = page->new_optgroup("Profile dependencies"); optgroup = page->new_optgroup("Profile dependencies");
line = Line{ "Compatible printers", "" }; line = Line{ "Compatible printers", "" };
line.widget = compatible_printers_widget_; line.widget = [this](wxWindow* parent){
return compatible_printers_widget(parent, m_compatible_printers_checkbox, m_compatible_printers_btn);
};
optgroup->append_line(line); optgroup->append_line(line);
} }
void CTabFilament::build() void CTabFilament::build()
{ {
config_ = preset_bundle_->filaments.get_edited_preset().config; m_config = m_preset_bundle->filaments.get_edited_preset().config;
config_def_ = config_.def(); m_config_def = m_config.def();
auto page = add_options_page("Filament", "spool.png"); auto page = add_options_page("Filament", "spool.png");
auto optgroup = page->new_optgroup("Filament"); auto optgroup = page->new_optgroup("Filament");
@ -377,7 +380,9 @@ void CTabFilament::build()
line = { "", "" }; line = { "", "" };
line.full_width = 1; line.full_width = 1;
line.widget = cooling_description_line_widget_; line.widget = [this](wxWindow* parent) {
return description_line_widget(parent, m_cooling_description_line);
};
optgroup->append_line(line); optgroup->append_line(line);
optgroup = page->new_optgroup("Fan settings"); optgroup = page->new_optgroup("Fan settings");
@ -404,7 +409,9 @@ void CTabFilament::build()
line = {"",""}; line = {"",""};
line.full_width = 1; line.full_width = 1;
line.widget = volumetric_speed_description_line_widget_; line.widget = [this](wxWindow* parent) {
return description_line_widget(parent, m_volumetric_speed_description_line);
};
optgroup->append_line(line); optgroup->append_line(line);
page = add_options_page("Custom G-code", "cog.png"); page = add_options_page("Custom G-code", "cog.png");
@ -431,13 +438,13 @@ void CTabFilament::build()
page = add_options_page("Dependencies", "wrench.png"); page = add_options_page("Dependencies", "wrench.png");
optgroup = page->new_optgroup("Profile dependencies"); optgroup = page->new_optgroup("Profile dependencies");
line = {"Compatible printers", ""}; line = {"Compatible printers", ""};
line.widget = compatible_printers_widget_; line.widget = [this](wxWindow* parent){
return compatible_printers_widget(parent, m_compatible_printers_checkbox, m_compatible_printers_btn);
};
optgroup->append_line(line); optgroup->append_line(line);
} }
wxStaticText* CTabFilament::cooling_description_line_; wxSizer* CTabFilament::description_line_widget(wxWindow* parent, wxStaticText* StaticText)
wxStaticText* CTabFilament::volumetric_speed_description_line_;
wxSizer* CTabFilament::description_line_widget_(wxWindow* parent, wxStaticText* StaticText)
{ {
StaticText = new wxStaticText(parent, wxID_ANY, "gfghjkkl;\n fgdsufhsreotklg\n iesrftorsikgyfkh\nauiwrhfidj", wxDefaultPosition, wxDefaultSize); StaticText = new wxStaticText(parent, wxID_ANY, "gfghjkkl;\n fgdsufhsreotklg\n iesrftorsikgyfkh\nauiwrhfidj", wxDefaultPosition, wxDefaultSize);
auto font = (new wxSystemSettings)->GetFont(wxSYS_DEFAULT_GUI_FONT); auto font = (new wxSystemSettings)->GetFont(wxSYS_DEFAULT_GUI_FONT);
@ -453,18 +460,35 @@ wxSizer* CTabFilament::description_line_widget_(wxWindow* parent, wxStaticText*
//#include "../../libslic3r/GCodeSender.hpp"; //#include "../../libslic3r/GCodeSender.hpp";
void CTabPrinter::build() void CTabPrinter::build()
{ {
config_ = preset_bundle_->printers.get_edited_preset().config; m_config = m_preset_bundle->printers.get_edited_preset().config;
config_def_ = config_.def(); // It will be used in get_option_(const std::string title) m_config_def = m_config.def(); // It will be used in get_option_(const std::string title)
// $self->{extruders_count} = scalar @{$self->{config}->nozzle_diameter}; // $self->{extruders_count} = scalar @{$self->{config}->nozzle_diameter};
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(config_.option("nozzle_diameter")); auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config.option("nozzle_diameter"));
// size_t extruders_count = nozzle_diameter->values.size(); // size_t extruders_count = nozzle_diameter->values.size();
auto page = add_options_page("General", "printer_empty.png"); auto page = add_options_page("General", "printer_empty.png");
auto optgroup = page->new_optgroup("Size and coordinates"); auto optgroup = page->new_optgroup("Size and coordinates");
Line line = { "Bed shape", "" }; Line line = { "Bed shape", "" };
line.widget = bed_shape_widget_; line.widget = [](wxWindow* parent){
auto btn = new wxButton(parent, wxID_ANY, "Set…", wxDefaultPosition, wxDefaultSize,
wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(Slic3r::GUI::small_font);
btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("printer_empty.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, ([](wxCommandEvent e)
{
// auto dlg = new BedShapeDialog->new($self, $self->{config}->bed_shape);
// if (dlg->ShowModal == wxID_OK)
;// load_key_value_("bed_shape", dlg->GetValue);
}));
return sizer;
};
optgroup->append_line(line); optgroup->append_line(line);
optgroup->append_single_option_line(get_option_("z_offset")); optgroup->append_single_option_line(get_option_("z_offset"));
@ -499,38 +523,38 @@ void CTabPrinter::build()
line = {"Serial port", ""}; line = {"Serial port", ""};
Option serial_port = get_option_("serial_port"); Option serial_port = get_option_("serial_port");
serial_port.side_widget = ([](wxWindow* parent){ serial_port.side_widget = ([](wxWindow* parent){
auto btn = new wxBitmapButton(parent, wxID_ANY, wxBitmap(wxT("var\\arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), auto btn = new wxBitmapButton(parent, wxID_ANY, wxBitmap(wxString::FromUTF8(Slic3r::var("arrow_rotate_clockwise.png").c_str()), wxBITMAP_TYPE_PNG),
wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
/*if (btn->can('SetToolTipString')*/btn->SetToolTip("Rescan serial ports"); /*if (btn->can('SetToolTipString')*/btn->SetToolTip("Rescan serial ports");
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn); sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent e) {/*_update_serial_ports*/; }); btn->Bind(wxEVT_BUTTON, [](wxCommandEvent e) {/*_update_serial_ports*/; });
return sizer; return sizer;
}); });
auto serial_test = ([/*serial_test_btn*/](wxWindow* parent){ auto serial_test = [this](wxWindow* parent){
auto btn = /*serial_test_btn =*/ new wxButton(parent, wxID_ANY, auto btn = serial_test_btn = new wxButton(parent, wxID_ANY,
"Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont($Slic3r::GUI::small_font); // btn->SetFont($Slic3r::GUI::small_font);
btn->SetBitmap(wxBitmap(wxT("var\\wrench.png"), wxBITMAP_TYPE_PNG)); btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("wrench.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn); sizer->Add(btn);
// btn->Bind(wxEVT_BUTTON, []{ btn->Bind(wxEVT_BUTTON, [parent](wxCommandEvent e){
// auto sender = new GCodeSender(); // auto sender = new GCodeSender();
// auto res = true;// sender->connect( // auto res = true;// sender->connect(
// // s_cache_HostConfig.serial_port, // // s_cache_HostConfig.serial_port,
// // config_->serial_speed // // config_->serial_speed
// // ); // // );
// if (res && sender->wait_connected()) { // if (res && sender->wait_connected()) {
// show_info(parent, "Connection to printer works correctly.", "Success!"); show_info(parent, "Connection to printer works correctly.", "Success!");
// } // }
// else { // else {
// show_error(parent, "Connection failed."); // show_error(parent, "Connection failed.");
// } // }
// });
return sizer;
}); });
return sizer;
};
line.append_option(serial_port); line.append_option(serial_port);
line.append_option(get_option_("serial_speed")); line.append_option(get_option_("serial_speed"));
@ -539,10 +563,10 @@ void CTabPrinter::build()
// } // }
optgroup = page->new_optgroup("OctoPrint upload"); optgroup = page->new_optgroup("OctoPrint upload");
// # append two buttons to the Host line // # append two buttons to the Host line
auto octoprint_host_browse = ([] (wxWindow* parent) { auto octoprint_host_browse = [] (wxWindow* parent) {
auto btn = new wxButton(parent, wxID_ANY, "Browse…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT); auto btn = new wxButton(parent, wxID_ANY, "Browse…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
// btn->SetFont($Slic3r::GUI::small_font); // btn->SetFont($Slic3r::GUI::small_font);
btn->SetBitmap(wxBitmap(wxT("var\\zoom.png"), wxBITMAP_TYPE_PNG)); btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("zoom.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn); sizer->Add(btn);
@ -570,12 +594,13 @@ void CTabPrinter::build()
// }); // });
return sizer; return sizer;
}); };
auto octoprint_host_test = ([/*serial_test_btn*/](wxWindow* parent) {
auto btn = /*serial_test_btn =*/ new wxButton(parent, wxID_ANY, auto octoprint_host_test = [this](wxWindow* parent) {
auto btn = octoprint_host_test_btn = new wxButton(parent, wxID_ANY,
"Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont($Slic3r::GUI::small_font); // btn->SetFont($Slic3r::GUI::small_font);
btn->SetBitmap(wxBitmap(wxT("var\\wrench.png"), wxBITMAP_TYPE_PNG)); btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("wrench.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn); sizer->Add(btn);
@ -597,7 +622,7 @@ void CTabPrinter::build()
// } // }
}); });
return sizer; return sizer;
}); };
Line host_line = optgroup->create_single_option_line(get_option_("octoprint_host")); Line host_line = optgroup->create_single_option_line(get_option_("octoprint_host"));
host_line.append_widget(octoprint_host_browse); host_line.append_widget(octoprint_host_browse);
@ -659,12 +684,12 @@ void CTabPrinter::build()
optgroup->append_single_option_line(option); optgroup->append_single_option_line(option);
// $self->{extruder_pages} = []; // $self->{extruder_pages} = [];
build_extruder_pages_(); build_extruder_pages();
// $self->_update_serial_ports if (!$params{ no_controller }); // $self->_update_serial_ports if (!$params{ no_controller });
} }
void CTabPrinter::build_extruder_pages_(){ void CTabPrinter::build_extruder_pages(){
// my $default_config = Slic3r::Config::Full->new; // my $default_config = Slic3r::Config::Full->new;
// //
// foreach my $extruder_idx(@{$self->{extruder_pages}} ..$self->{extruders_count}-1) { // foreach my $extruder_idx(@{$self->{extruder_pages}} ..$self->{extruders_count}-1) {
@ -727,34 +752,34 @@ void CTab::rebuild_page_tree()
{ {
Freeze(); Freeze();
// get label of the currently selected item // get label of the currently selected item
auto selected = treectrl_->GetItemText(treectrl_->GetSelection()); auto selected = m_treectrl->GetItemText(m_treectrl->GetSelection());
auto rootItem = treectrl_->GetRootItem(); auto rootItem = m_treectrl->GetRootItem();
treectrl_->DeleteChildren(rootItem); m_treectrl->DeleteChildren(rootItem);
auto have_selection = 0; auto have_selection = 0;
for (auto p : pages_) for (auto p : m_pages)
{ {
auto itemId = treectrl_->AppendItem(rootItem, p->title(), p->iconID()); auto itemId = m_treectrl->AppendItem(rootItem, p->title(), p->iconID());
if (p->title() == selected) { if (p->title() == selected) {
disable_tree_sel_changed_event_ = 1; m_disable_tree_sel_changed_event = 1;
treectrl_->SelectItem(itemId); m_treectrl->SelectItem(itemId);
disable_tree_sel_changed_event_ = 0; m_disable_tree_sel_changed_event = 0;
have_selection = 1; have_selection = 1;
} }
} }
if (!have_selection) { if (!have_selection) {
// this is triggered on first load, so we don't disable the sel change event // this is triggered on first load, so we don't disable the sel change event
treectrl_->SelectItem(treectrl_->GetFirstVisibleItem());//! (treectrl->GetFirstChild(rootItem)); m_treectrl->SelectItem(m_treectrl->GetFirstVisibleItem());//! (treectrl->GetFirstChild(rootItem));
} }
Thaw(); Thaw();
} }
void CTab::OnTreeSelChange(wxTreeEvent& event) void CTab::OnTreeSelChange(wxTreeEvent& event)
{ {
if (disable_tree_sel_changed_event_) return; if (m_disable_tree_sel_changed_event) return;
CPage* page = nullptr; CPage* page = nullptr;
auto selection = treectrl_->GetItemText(treectrl_->GetSelection()); auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
for (auto p : pages_) for (auto p : m_pages)
if (p->title() == selection) if (p->title() == selection)
{ {
page = p.get(); page = p.get();
@ -762,33 +787,33 @@ void CTab::OnTreeSelChange(wxTreeEvent& event)
} }
if (page == nullptr) return; if (page == nullptr) return;
for (auto& el : pages_) for (auto& el : m_pages)
el.get()->Hide(); el.get()->Hide();
page->Show(); page->Show();
hsizer_->Layout(); m_hsizer->Layout();
Refresh(); Refresh();
} }
void CTab::OnKeyDown(wxKeyEvent& event) void CTab::OnKeyDown(wxKeyEvent& event)
{ {
event.GetKeyCode() == WXK_TAB ? event.GetKeyCode() == WXK_TAB ?
treectrl_->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward) : m_treectrl->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward) :
event.Skip(); event.Skip();
}; };
void CTab::save_preset(wxCommandEvent &event){}; void CTab::save_preset(wxCommandEvent &event){};
void CTab::delete_preset(wxCommandEvent &event){}; void CTab::delete_preset(wxCommandEvent &event){};
void CTab::_toggle_show_hide_incompatible(wxCommandEvent &event){}; void CTab::toggle_show_hide_incompatible(wxCommandEvent &event){};
// # Return a callback to create a Tab widget to mark the preferences as compatible / incompatible to the current printer. // # Return a callback to create a Tab widget to mark the preferences as compatible / incompatible to the current printer.
wxSizer* CTab::compatible_printers_widget_(wxWindow* parent) wxSizer* CTab::compatible_printers_widget(wxWindow* parent, wxCheckBox* checkbox, wxButton* btn)
{ {
auto checkbox /*= compatible_printers_checkbox*/ = new wxCheckBox(parent, wxID_ANY, "All"); checkbox = new wxCheckBox(parent, wxID_ANY, "All");
auto btn /*= compatible_printers_btn*/ = new wxButton(parent, wxID_ANY, "Set…", wxDefaultPosition, wxDefaultSize, btn = new wxButton(parent, wxID_ANY, "Set…", wxDefaultPosition, wxDefaultSize,
wxBU_LEFT | wxBU_EXACTFIT); wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(GUI::small_font); // btn->SetFont(GUI::small_font);
btn->SetBitmap(wxBitmap(wxT("var\\printer_empty.png"), wxBITMAP_TYPE_PNG)); btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("printer_empty.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(checkbox, 0, wxALIGN_CENTER_VERTICAL); sizer->Add(checkbox, 0, wxALIGN_CENTER_VERTICAL);
@ -852,31 +877,11 @@ wxSizer* CTab::compatible_printers_widget_(wxWindow* parent)
return sizer; return sizer;
} }
wxSizer* CTab::bed_shape_widget_(wxWindow* parent)
{
auto btn = new wxButton(parent, wxID_ANY, "Set…", wxDefaultPosition, wxDefaultSize,
wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(Slic3r::GUI::small_font);
btn->SetBitmap(wxBitmap(wxT("var\\printer_empty.png"), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, ([=](wxCommandEvent e)
{
// auto dlg = new BedShapeDialog->new($self, $self->{config}->bed_shape);
// if (dlg->ShowModal == wxID_OK)
;// load_key_value_("bed_shape", dlg->GetValue);
}));
return sizer;
}
// package Slic3r::GUI::Tab::Page; // package Slic3r::GUI::Tab::Page;
ConfigOptionsGroupShp CPage::new_optgroup(std::string title, int noncommon_label_width /*= -1*/) ConfigOptionsGroupShp CPage::new_optgroup(std::string title, int noncommon_label_width /*= -1*/)
{ {
//! config_ have to be "right" //! config_ have to be "right"
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, config_); ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config);
if (noncommon_label_width >= 0) if (noncommon_label_width >= 0)
optgroup->label_width = noncommon_label_width; optgroup->label_width = noncommon_label_width;
@ -889,7 +894,7 @@ ConfigOptionsGroupShp CPage::new_optgroup(std::string title, int noncommon_label
// }, // },
vsizer()->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 10); vsizer()->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 10);
optgroups.push_back(optgroup); m_optgroups.push_back(optgroup);
return optgroup; return optgroup;
} }

View File

@ -38,31 +38,31 @@ namespace GUI {
using ConfigOptionsGroupShp = std::shared_ptr<ConfigOptionsGroup>; using ConfigOptionsGroupShp = std::shared_ptr<ConfigOptionsGroup>;
class CPage : public wxScrolledWindow class CPage : public wxScrolledWindow
{ {
wxWindow* parent_; wxWindow* m_parent;
wxString title_; wxString m_title;
size_t iconID_; size_t m_iconID;
wxBoxSizer* vsizer_; wxBoxSizer* m_vsizer;
public: public:
CPage(wxWindow* parent, const wxString title, const int iconID) : CPage(wxWindow* parent, const wxString title, const int iconID) :
parent_(parent), m_parent(parent),
title_(title), m_title(title),
iconID_(iconID) m_iconID(iconID)
{ {
Create(parent_, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); Create(m_parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
vsizer_ = new wxBoxSizer(wxVERTICAL); m_vsizer = new wxBoxSizer(wxVERTICAL);
SetSizer(vsizer_); SetSizer(m_vsizer);
} }
~CPage(){} ~CPage(){}
public: public:
std::vector <ConfigOptionsGroupShp> optgroups; // $self->{optgroups} = []; std::vector <ConfigOptionsGroupShp> m_optgroups; // $self->{optgroups} = [];
DynamicPrintConfig* config_; DynamicPrintConfig* m_config;
wxBoxSizer* vsizer() const { return vsizer_; } wxBoxSizer* vsizer() const { return m_vsizer; }
wxWindow* parent() const { return parent_; } wxWindow* parent() const { return m_parent; }
wxString title() const { return title_; } wxString title() const { return m_title; }
size_t iconID() const { return iconID_; } size_t iconID() const { return m_iconID; }
void set_config(DynamicPrintConfig* config_in) { config_ = config_in; } void set_config(DynamicPrintConfig* config_in) { m_config = config_in; }
ConfigOptionsGroupShp new_optgroup(std::string title, int noncommon_label_width = -1); ConfigOptionsGroupShp new_optgroup(std::string title, int noncommon_label_width = -1);
}; };
@ -72,65 +72,64 @@ public:
using CPageShp = std::shared_ptr<CPage>; using CPageShp = std::shared_ptr<CPage>;
class CTab: public wxPanel class CTab: public wxPanel
{ {
wxNotebook* parent_; wxNotebook* m_parent;
protected: protected:
const wxString title_; const wxString m_title;
wxBitmapComboBox* presets_choice_; wxBitmapComboBox* m_presets_choice;
wxBitmapButton* btn_save_preset_; wxBitmapButton* m_btn_save_preset;
wxBitmapButton* btn_delete_preset_; wxBitmapButton* m_btn_delete_preset;
wxBitmap* bmp_show_incompatible_presets_; wxBitmap* m_bmp_show_incompatible_presets;
wxBitmap* bmp_hide_incompatible_presets_; wxBitmap* m_bmp_hide_incompatible_presets;
wxBitmapButton* btn_hide_incompatible_presets_; wxBitmapButton* m_btn_hide_incompatible_presets;
wxBoxSizer* hsizer_; wxBoxSizer* m_hsizer;
wxBoxSizer* left_sizer_; wxBoxSizer* m_left_sizer;
wxTreeCtrl* treectrl_; wxTreeCtrl* m_treectrl;
wxImageList* icons_; wxImageList* m_icons;
wxCheckBox* compatible_printers_checkbox_; wxCheckBox* m_compatible_printers_checkbox;
wxButton* compatible_printers_btn; wxButton* m_compatible_printers_btn;
int icon_count; int m_icon_count;
std::map<wxString, size_t> icon_index_; // Map from an icon file name to its index in $self->{icons}. std::map<std::string, size_t> m_icon_index; // Map from an icon file name to its index in $self->{icons}.
std::vector<CPageShp> pages_; // $self->{pages} = []; std::vector<CPageShp> m_pages; // $self->{pages} = [];
bool disable_tree_sel_changed_event_; bool m_disable_tree_sel_changed_event;
public: public:
PresetBundle* preset_bundle_; PresetBundle* m_preset_bundle;
DynamicPrintConfig config_; //! tmp_val DynamicPrintConfig m_config; //! tmp_val
const ConfigDef* config_def_; // It will be used in get_option_(const std::string title) const ConfigDef* m_config_def; // It will be used in get_option_(const std::string title)
public: public:
CTab() {} CTab() {}
CTab(wxNotebook* parent, const char *title) : parent_(parent), title_(title) { CTab(wxNotebook* parent, const char *title) : m_parent(parent), m_title(title) {
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL); Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
} }
~CTab(){} ~CTab(){}
wxWindow* parent() const { return parent_; } wxWindow* parent() const { return m_parent; }
wxString title() const { return title_; } wxString title() const { return m_title; }
void create_preset_tab(PresetBundle *preset_bundle); void create_preset_tab(PresetBundle *preset_bundle);
void rebuild_page_tree(); void rebuild_page_tree();
void select_preset(wxString preset_name){}; void select_preset(wxString preset_name){};
static wxSizer* compatible_printers_widget_(wxWindow* parent); wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox* checkbox, wxButton* btn);
static wxSizer* bed_shape_widget_(wxWindow* parent);
void load_key_value_(std::string opt_key, std::vector<std::string> value); void load_key_value(std::string opt_key, std::vector<std::string> value);
void OnTreeSelChange(wxTreeEvent& event); void OnTreeSelChange(wxTreeEvent& event);
void OnKeyDown(wxKeyEvent& event); void OnKeyDown(wxKeyEvent& event);
void OnComboBox(wxCommandEvent& event) { select_preset(presets_choice_->GetStringSelection()); } void OnComboBox(wxCommandEvent& event) { select_preset(m_presets_choice->GetStringSelection()); }
void save_preset(wxCommandEvent &event); void save_preset(wxCommandEvent &event);
void delete_preset(wxCommandEvent &event); void delete_preset(wxCommandEvent &event);
void _toggle_show_hide_incompatible(wxCommandEvent &event); void toggle_show_hide_incompatible(wxCommandEvent &event);
std::shared_ptr<CPage> add_options_page(wxString title, wxString icon); CPageShp add_options_page(wxString title, std::string icon);
virtual void build() = 0; virtual void build() = 0;
// virtual void _update(); // virtual void update();
Option get_option_(const std::string title){ Option get_option_(const std::string title){
return Option(*config_def_->get(title), title); return Option(*m_config_def->get(title), title);
} }
}; };
@ -145,26 +144,22 @@ public:
void build() override; void build() override;
}; };
//Slic3r::GUI::Tab::Print; //Slic3r::GUI::Tab::Filament;
class CTabFilament : public CTab class CTabFilament : public CTab
{ {
static wxStaticText* cooling_description_line_; wxStaticText* m_cooling_description_line;
static wxStaticText* volumetric_speed_description_line_; wxStaticText* m_volumetric_speed_description_line;
public: public:
CTabFilament() {} CTabFilament() {}
CTabFilament(wxNotebook* parent, const char *title) : CTab(parent, title) {} CTabFilament(wxNotebook* parent, const char *title) : CTab(parent, title) {}
~CTabFilament(){} ~CTabFilament(){}
static wxSizer* description_line_widget_(wxWindow* parent, wxStaticText* StaticText); wxSizer* description_line_widget(wxWindow* parent, wxStaticText* StaticText);
static wxSizer* cooling_description_line_widget_(wxWindow* parent) {
return description_line_widget_(parent, cooling_description_line_); }
static wxSizer* volumetric_speed_description_line_widget_(wxWindow* parent) {
return description_line_widget_(parent, volumetric_speed_description_line_); }
void build() override; void build() override;
}; };
//Slic3r::GUI::Tab::Print; //Slic3r::GUI::Tab::Printer;
class CTabPrinter : public CTab class CTabPrinter : public CTab
{ {
public: public:
@ -176,7 +171,7 @@ public:
~CTabPrinter(){} ~CTabPrinter(){}
void build() override; void build() override;
void build_extruder_pages_(); void build_extruder_pages();
}; };
} // GUI } // GUI