Start adding functions to work with presets

This commit is contained in:
YuSanka 2018-01-03 10:12:42 +01:00
parent 72d1f51146
commit f8a48f5c13
6 changed files with 63 additions and 46 deletions

View file

@ -152,7 +152,7 @@ sub _init_tabpanel {
}
#TODO this is an example of a Slic3r XS interface call to add a new preset editor page to the main view.
Slic3r::GUI::create_preset_tabs(wxTheApp->{preset_bundle});
Slic3r::GUI::create_preset_tabs(wxTheApp->{preset_bundle}, wxTheApp->{app_config});
if ($self->{plater}) {
$self->{plater}->on_select_preset(sub {

View file

@ -188,16 +188,16 @@ void add_debug_menu(wxMenuBar *menu)
#endif
}
void create_preset_tabs(PresetBundle *preset_bundle)
void create_preset_tabs(PresetBundle *preset_bundle, AppConfig *app_config)
{
add_created_tab(new CTabPrint (g_wxTabPanel, "Print"), preset_bundle);
add_created_tab(new CTabFilament(g_wxTabPanel, "Filament"), preset_bundle);
add_created_tab(new CTabPrinter (g_wxTabPanel, "Printer"), preset_bundle);
add_created_tab(new CTabPrint (g_wxTabPanel, "Print"), preset_bundle, app_config);
add_created_tab(new CTabFilament(g_wxTabPanel, "Filament"), preset_bundle, app_config);
add_created_tab(new CTabPrinter (g_wxTabPanel, "Printer"), preset_bundle, app_config);
}
void add_created_tab(CTab* panel, PresetBundle *preset_bundle)
void add_created_tab(CTab* panel, PresetBundle *preset_bundle, AppConfig *app_config)
{
panel->create_preset_tab(preset_bundle);
panel->create_preset_tab(preset_bundle, app_config);
g_wxTabPanel->AddPage(panel, panel->title());
}

View file

@ -13,6 +13,7 @@ class wxNotebook;
namespace Slic3r {
class PresetBundle;
class AppConfig;
namespace GUI {
@ -31,9 +32,9 @@ void set_tab_panel(wxNotebook *tab_panel);
void add_debug_menu(wxMenuBar *menu);
// Create a new preset tab (print, filament and printer),
void create_preset_tabs(PresetBundle *preset_bundle);
void create_preset_tabs(PresetBundle *preset_bundle, AppConfig *app_config);
// add it at the end of the tab panel.
void add_created_tab(CTab* panel, PresetBundle *preset_bundle);
void add_created_tab(CTab* panel, PresetBundle *preset_bundle, AppConfig *app_config);
void show_error(wxWindow* parent, std::string message);
void show_info(wxWindow* parent, std::string message, std::string title);

View file

@ -1,3 +1,4 @@
#include "../../libslic3r/GCodeSender.hpp"
#include <wx/app.h>
#include <wx/button.h>
#include <wx/scrolwin.h>
@ -13,15 +14,17 @@
#include "Tab.h"
#include "PresetBundle.hpp"
#include "../../libslic3r/Utils.hpp"
//#include "GCodeSender.hpp"
namespace Slic3r {
namespace GUI {
// sub new
void CTab::create_preset_tab(PresetBundle *preset_bundle)
void CTab::create_preset_tab(PresetBundle *preset_bundle, AppConfig *app_config)
{
m_preset_bundle = preset_bundle;
m_app_config = app_config;
// Vertical sizer to hold the choice menu and the rest of the page.
CTab *panel = this;
auto *sizer = new wxBoxSizer(wxVERTICAL);
@ -457,11 +460,11 @@ wxSizer* CTabFilament::description_line_widget(wxWindow* parent, wxStaticText* S
return sizer;
}
//#include "../../libslic3r/GCodeSender.hpp";
void CTabPrinter::build()
{
m_config = m_preset_bundle->printers.get_edited_preset().config;
m_config_def = m_config.def(); // It will be used in get_option_(const std::string title)
auto default_config = m_preset_bundle->full_config();
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config.option("nozzle_diameter"));
m_extruders_count = nozzle_diameter->values.size();
@ -516,22 +519,25 @@ void CTabPrinter::build()
// });
// });
// if (!$params{ no_controller })
// {
//if (!$params{ no_controller })
if (m_app_config->get("no_controller").empty())
{
optgroup = page->new_optgroup("USB/Serial connection");
line = {"Serial port", ""};
Option serial_port = get_option("serial_port");
serial_port.side_widget = ([](wxWindow* parent){
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);
/*if (btn->can('SetToolTipString')*/btn->SetToolTip("Rescan serial ports");
btn->SetToolTip("Rescan serial ports");
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [](wxCommandEvent e) {/*_update_serial_ports*/; });
return sizer;
});
auto serial_test = [this](wxWindow* parent){
Option serial_speed = get_option("serial_speed");
//! this serial_port & serial_speed have to be config !??
auto serial_test = [this, serial_port, serial_speed](wxWindow* parent){
auto btn = serial_test_btn = new wxButton(parent, wxID_ANY,
"Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont($Slic3r::GUI::small_font);
@ -539,27 +545,28 @@ void CTabPrinter::build()
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [parent](wxCommandEvent e){
// auto sender = new GCodeSender();
// auto res = true;// sender->connect(
// // s_cache_HostConfig.serial_port,
// // config_->serial_speed
// // );
// if (res && sender->wait_connected()) {
btn->Bind(wxEVT_BUTTON, [parent, serial_port, serial_speed](wxCommandEvent e){
auto sender = new GCodeSender();
auto res = sender->connect(
static_cast<const ConfigOptionString*>(serial_port.opt.default_value)->value, //! m_config.serial_port,
serial_speed.opt.default_value->getInt() //! m_config.serial_speed
);
if (res && sender->wait_connected()) {
show_info(parent, "Connection to printer works correctly.", "Success!");
// }
// else {
// show_error(parent, "Connection failed.");
// }
}
else {
show_error(parent, "Connection failed.");
}
});
return sizer;
};
line.append_option(serial_port);
line.append_option(get_option("serial_speed"));
line.append_option(serial_speed/*get_option("serial_speed")*/);
line.append_widget(serial_test);
optgroup->append_line(line);
// }
}
optgroup = page->new_optgroup("OctoPrint upload");
// # append two buttons to the Host line
auto octoprint_host_browse = [] (wxWindow* parent) {
@ -573,9 +580,9 @@ void CTabPrinter::build()
// btn->Disable;
// }
// btn->Bind(wxEVT_BUTTON, []{
btn->Bind(wxEVT_BUTTON, [parent](wxCommandEvent e){
// # look for devices
// my $entries;
// auto entries;
// {
// my $res = Net::Bonjour->new('http');
// $res->discover;
@ -587,10 +594,10 @@ void CTabPrinter::build()
// if $dlg->ShowModal == wxID_OK;
// }
// else {
// auto msg_window = new wxMessageDialog(parent, "No Bonjour device found", "Device Browser", wxOK | wxICON_INFORMATION);
// msg_window->ShowModal();
// }
// });
auto msg_window = new wxMessageDialog(parent, "No Bonjour device found", "Device Browser", wxOK | wxICON_INFORMATION);
msg_window->ShowModal();
// }
});
return sizer;
};
@ -603,7 +610,7 @@ void CTabPrinter::build()
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [](wxCommandEvent e) {
btn->Bind(wxEVT_BUTTON, [parent](wxCommandEvent e) {
// my $ua = LWP::UserAgent->new;
// $ua->timeout(10);
//
@ -612,10 +619,10 @@ void CTabPrinter::build()
// 'X-Api-Key' = > $self->{config}->octoprint_apikey,
// );
// if ($res->is_success) {
// Slic3r::GUI::show_info($self, "Connection to OctoPrint works correctly.", "Success!");
// show_info(parent, "Connection to OctoPrint works correctly.", "Success!");
// }
// else {
// Slic3r::GUI::show_error($self,
// show_error(parent,
// "I wasn't able to connect to OctoPrint (".$res->status_line . "). "
// . "Check hostname and OctoPrint version (at least 1.1.0 is required).");
// }
@ -685,6 +692,11 @@ void CTabPrinter::build()
build_extruder_pages();
// $self->_update_serial_ports if (!$params{ no_controller });
if (m_app_config->get("no_controller").empty()){
Field *field = optgroup->get_field("serial_port");
Choice *choice = static_cast<Choice *>(field);
choice->set_values(scan_serial_ports());
}
}
void CTabPrinter::build_extruder_pages(){

View file

@ -95,6 +95,7 @@ protected:
public:
PresetBundle* m_preset_bundle;
AppConfig* m_app_config;
DynamicPrintConfig m_config; //! tmp_val
const ConfigDef* m_config_def; // It will be used in get_option_(const std::string title)
@ -108,7 +109,7 @@ public:
wxWindow* parent() const { return m_parent; }
wxString title() const { return m_title; }
void create_preset_tab(PresetBundle *preset_bundle);
void create_preset_tab(PresetBundle *preset_bundle, AppConfig *app_config);
void rebuild_page_tree();
void select_preset(wxString preset_name){};
@ -125,8 +126,8 @@ public:
CPageShp add_options_page(wxString title, std::string icon, bool is_extruder_pages = false);
virtual void build() = 0;
// virtual void update();
virtual void build() = 0;
virtual void update() = 0;
Option get_option(const std::string title, int idx = -1){
return Option(*m_config_def->get(title), idx == -1 ? title : title + std::to_string(idx));
@ -141,7 +142,8 @@ public:
CTabPrint(wxNotebook* parent, const char *title) : CTab(parent, title) {}
~CTabPrint(){}
void build() override;
void build() override;
void update() override{};
};
//Slic3r::GUI::Tab::Filament;
@ -156,7 +158,8 @@ public:
wxSizer* description_line_widget(wxWindow* parent, wxStaticText* StaticText);
void build() override;
void build() override;
void update() override{};
};
//Slic3r::GUI::Tab::Printer;
@ -173,8 +176,9 @@ public:
CTabPrinter(wxNotebook* parent, const char *title) : CTab(parent, title) {}
~CTabPrinter(){}
void build() override;
void build_extruder_pages();
void build() override;
void update() override{};
void build_extruder_pages();
};
} // GUI

View file

@ -35,5 +35,5 @@ void set_tab_panel(SV *ui)
void add_debug_menu(SV *ui)
%code%{ Slic3r::GUI::add_debug_menu((wxMenuBar*)wxPli_sv_2_object(aTHX_ ui, "Wx::MenuBar")); %};
void create_preset_tabs(PresetBundle *preset_bundle)
%code%{ Slic3r::GUI::create_preset_tabs(preset_bundle); %};
void create_preset_tabs(PresetBundle *preset_bundle, AppConfig *app_config)
%code%{ Slic3r::GUI::create_preset_tabs(preset_bundle, app_config); %};