PrusaSlicer-NonPlainar/xs/src/slic3r/GUI/Tab.cpp

904 lines
37 KiB
C++
Raw Normal View History

2017-12-05 14:54:01 +00:00
#include <wx/app.h>
#include <wx/button.h>
#include <wx/scrolwin.h>
2017-12-05 14:54:01 +00:00
#include <wx/menu.h>
#include <wx/sizer.h>
#include <wx/bmpcbox.h>
#include <wx/bmpbuttn.h>
#include <wx/treectrl.h>
#include <wx/imaglist.h>
#include <wx/settings.h>
2017-12-05 14:54:01 +00:00
#include "Tab.h"
#include "PresetBundle.hpp"
2017-12-26 22:04:54 +00:00
#include "../../libslic3r/Utils.hpp"
//#include "GCodeSender.hpp"
2017-12-05 14:54:01 +00:00
namespace Slic3r {
namespace GUI {
// sub new
void CTab::create_preset_tab(PresetBundle *preset_bundle)
2017-12-05 14:54:01 +00:00
{
2017-12-26 22:04:54 +00:00
m_preset_bundle = preset_bundle;
2017-12-05 14:54:01 +00:00
// Vertical sizer to hold the choice menu and the rest of the page.
CTab *panel = this;
auto *sizer = new wxBoxSizer(wxVERTICAL);
sizer->SetSizeHints(panel);
panel->SetSizer(sizer);
// preset chooser
//! Add Preset from PrintPreset
2017-12-05 14:54:01 +00:00
// choice menu for Experiments
wxString choices[] =
{
_T("First"),
_T("Second"),
_T("Third")
2017-12-05 14:54:01 +00:00
};
2017-12-26 22:04:54 +00:00
m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1)/*, nCntEl, choices, wxCB_READONLY*/);
const wxBitmap* bmp = new wxBitmap(wxString::FromUTF8(Slic3r::var("flag-green-icon.png").c_str()), wxBITMAP_TYPE_PNG);
for (auto el:choices)
2017-12-26 22:04:54 +00:00
m_presets_choice->Append(wxString::FromUTF8(el).c_str(), *bmp);
m_presets_choice->SetSelection(m_presets_choice->GetCount() - 1);
2017-12-05 14:54:01 +00:00
//buttons
wxBitmap bmpMenu;
2017-12-26 22:04:54 +00:00
bmpMenu = wxBitmap(wxString::FromUTF8(Slic3r::var("disk.png").c_str()), wxBITMAP_TYPE_PNG);
m_btn_save_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
bmpMenu = wxBitmap(wxString::FromUTF8(Slic3r::var("delete.png").c_str()), wxBITMAP_TYPE_PNG);
m_btn_delete_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
2017-12-05 14:54:01 +00:00
// $self->{show_incompatible_presets} = 0; // !!!
2017-12-26 22:04:54 +00:00
m_bmp_show_incompatible_presets = new wxBitmap(wxString::FromUTF8(Slic3r::var("flag-red-icon.png").c_str()), wxBITMAP_TYPE_PNG);
m_bmp_hide_incompatible_presets = new wxBitmap(wxString::FromUTF8(Slic3r::var("flag-green-icon.png").c_str()), wxBITMAP_TYPE_PNG);
m_btn_hide_incompatible_presets = new wxBitmapButton(panel, wxID_ANY, *m_bmp_hide_incompatible_presets, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
2017-12-26 22:04:54 +00:00
m_btn_save_preset->SetToolTip(wxT("Save current ") + wxString(m_title));// (stTitle);
m_btn_delete_preset->SetToolTip(_T("Delete this preset"));
m_btn_delete_preset->Disable();
2017-12-26 22:04:54 +00:00
m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_hsizer, 0, wxBOTTOM, 3);
m_hsizer->Add(m_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
m_hsizer->AddSpacer(4);
m_hsizer->Add(m_btn_save_preset, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(4);
m_hsizer->Add(m_btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(16);
m_hsizer->Add(m_btn_hide_incompatible_presets, 0, wxALIGN_CENTER_VERTICAL);
2017-12-05 14:54:01 +00:00
//Horizontal sizer to hold the tree and the selected page.
2017-12-26 22:04:54 +00:00
m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_hsizer, 1, wxEXPAND, 0);
2017-12-05 14:54:01 +00:00
//left vertical sizer
2017-12-26 22:04:54 +00:00
m_left_sizer = new wxBoxSizer(wxVERTICAL);
m_hsizer->Add(m_left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
2017-12-05 14:54:01 +00:00
// tree
2017-12-26 22:04:54 +00:00
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);
m_left_sizer->Add(m_treectrl, 1, wxEXPAND);
m_icons = new wxImageList(16, 16, true, 1/*, 1*/);
2017-12-05 14:54:01 +00:00
// Index of the last icon inserted into $self->{icons}.
2017-12-26 22:04:54 +00:00
m_icon_count = -1;
m_treectrl->AssignImageList(m_icons);
m_treectrl->AddRoot("root");
m_treectrl->SetIndent(0);
m_disable_tree_sel_changed_event = 0;
2017-12-26 22:04:54 +00:00
m_treectrl->Bind(wxEVT_TREE_SEL_CHANGED, &CTab::OnTreeSelChange, this);
m_treectrl->Bind(wxEVT_KEY_DOWN, &CTab::OnKeyDown, this);
m_treectrl->Bind(wxEVT_COMBOBOX, &CTab::OnComboBox, this);
2017-12-26 22:04:54 +00:00
m_btn_save_preset->Bind(wxEVT_BUTTON, &CTab::save_preset, this);
m_btn_delete_preset->Bind(wxEVT_BUTTON, &CTab::delete_preset, this);
m_btn_hide_incompatible_presets->Bind(wxEVT_BUTTON, &CTab::toggle_show_hide_incompatible, this);
2017-12-05 14:54:01 +00:00
// Initialize the DynamicPrintConfig by default keys/values.
// Possible %params keys: no_controller
build();
rebuild_page_tree();
2017-12-05 14:54:01 +00:00
// _update();
}
2017-12-26 22:04:54 +00:00
CPageShp CTab::add_options_page(wxString title, std::string icon)
2017-12-05 14:54:01 +00:00
{
// Index of icon in an icon list $self->{icons}.
auto icon_idx = 0;
2017-12-26 22:04:54 +00:00
if (!icon.empty()) {
try { icon_idx = m_icon_index.at(icon);}
catch (std::out_of_range e) { icon_idx = -1; }
if (icon_idx == -1) {
// Add a new icon to the icon list.
2017-12-26 22:04:54 +00:00
const auto img_icon = new wxIcon(wxString::FromUTF8(Slic3r::var(/*"" + */icon).c_str()), wxBITMAP_TYPE_PNG);
m_icons->Add(*img_icon);
icon_idx = ++m_icon_count; // $icon_idx = $self->{icon_count} + 1; $self->{icon_count} = $icon_idx;
m_icon_index[icon] = icon_idx;
}
}
// Initialize the page.
CPageShp page(new CPage(this, title, icon_idx));
page->SetScrollbars(1, 1, 1, 1);
page->Hide();
2017-12-26 22:04:54 +00:00
m_hsizer->Add(page.get(), 1, wxEXPAND | wxLEFT, 5);
m_pages.push_back(page);
2017-12-26 22:04:54 +00:00
page->set_config(&m_config);
return page;
}
2017-12-26 22:04:54 +00:00
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,
// # update the preset selection boxes (the dirty flags)
// $self->{config}->set($opt_key, $value);
// # Mark the print & filament enabled if they are compatible with the currently selected preset.
if (opt_key.compare("compatible_printers") == 0) {
// wxTheApp->{preset_bundle}->update_compatible_with_printer(0);
// $self->{presets}->update_tab_ui($self->{presets_choice}, $self->{show_incompatible_presets});
// } else {
// $self->{presets}->update_dirty_ui($self->{presets_choice});
}
// $self->_on_presets_changed;
// $self->_update;
}
void CTabPrint::build()
{
2017-12-26 22:04:54 +00:00
m_config = m_preset_bundle->prints.get_edited_preset().config;
m_config_def = m_config.def();
auto page = add_options_page("Layers and perimeters", "layers.png");
auto optgroup = page->new_optgroup("Layer height");
optgroup->append_single_option_line(get_option_("layer_height"));
optgroup->append_single_option_line(get_option_("first_layer_height"));
optgroup = page->new_optgroup("Vertical shells");
optgroup->append_single_option_line(get_option_("perimeters"));
optgroup->append_single_option_line(get_option_("spiral_vase"));
optgroup = page->new_optgroup("Horizontal shells");
Line line{ "Solid layers", "" };
line.append_option(get_option_("top_solid_layers"));
line.append_option(get_option_("bottom_solid_layers"));
optgroup->append_line(line);
optgroup = page->new_optgroup("Quality (slower slicing)");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("extra_perimeters"));
optgroup->append_single_option_line(get_option_("ensure_vertical_shell_thickness"));
optgroup->append_single_option_line(get_option_("avoid_crossing_perimeters"));
optgroup->append_single_option_line(get_option_("thin_walls"));
optgroup->append_single_option_line(get_option_("overhangs"));
optgroup = page->new_optgroup("Advanced");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("seam_position"));
optgroup->append_single_option_line(get_option_("external_perimeters_first"));
page = add_options_page("Infill", "infill.png");
optgroup = page->new_optgroup("Infill");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("fill_density"));
optgroup->append_single_option_line(get_option_("fill_pattern"));
optgroup->append_single_option_line(get_option_("external_fill_pattern"));
optgroup = page->new_optgroup("Reducing printing time");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("infill_every_layers"));
optgroup->append_single_option_line(get_option_("infill_only_where_needed"));
optgroup = page->new_optgroup("Advanced");
optgroup->append_single_option_line(get_option_("solid_infill_every_layers"));
optgroup->append_single_option_line(get_option_("fill_angle"));
optgroup->append_single_option_line(get_option_("solid_infill_below_area"));
optgroup->append_single_option_line(get_option_("bridge_angle"));
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("only_retract_when_crossing_perimeters"));
optgroup->append_single_option_line(get_option_("infill_first"));
page = add_options_page("Skirt and brim", "box.png");
optgroup = page->new_optgroup("Skirt");
optgroup->append_single_option_line(get_option_("skirts"));
optgroup->append_single_option_line(get_option_("skirt_distance"));
optgroup->append_single_option_line(get_option_("skirt_height"));
optgroup->append_single_option_line(get_option_("min_skirt_length"));
optgroup = page->new_optgroup("Brim");
optgroup->append_single_option_line(get_option_("brim_width"));
page = add_options_page("Support material", "building.png");
optgroup = page->new_optgroup("Support material");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("support_material"));
optgroup->append_single_option_line(get_option_("support_material_threshold"));
optgroup->append_single_option_line(get_option_("support_material_enforce_layers"));
optgroup = page->new_optgroup("Raft");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("raft_layers"));
// # optgroup->append_single_option_line(get_option_("raft_contact_distance"));
optgroup = page->new_optgroup("Options for support material and raft");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("support_material_contact_distance"));
optgroup->append_single_option_line(get_option_("support_material_pattern"));
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("support_material_with_sheath"));
optgroup->append_single_option_line(get_option_("support_material_spacing"));
optgroup->append_single_option_line(get_option_("support_material_angle"));
optgroup->append_single_option_line(get_option_("support_material_interface_layers"));
optgroup->append_single_option_line(get_option_("support_material_interface_spacing"));
optgroup->append_single_option_line(get_option_("support_material_interface_contact_loops"));
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("support_material_buildplate_only"));
optgroup->append_single_option_line(get_option_("support_material_xy_spacing"));
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("dont_support_bridges"));
optgroup->append_single_option_line(get_option_("support_material_synchronize_layers"));
page = add_options_page("Speed", "time.png");
optgroup = page->new_optgroup("Speed for print moves");
optgroup->append_single_option_line(get_option_("perimeter_speed"));
optgroup->append_single_option_line(get_option_("small_perimeter_speed"));
optgroup->append_single_option_line(get_option_("external_perimeter_speed"));
optgroup->append_single_option_line(get_option_("infill_speed"));
optgroup->append_single_option_line(get_option_("solid_infill_speed"));
optgroup->append_single_option_line(get_option_("top_solid_infill_speed"));
optgroup->append_single_option_line(get_option_("support_material_speed"));
optgroup->append_single_option_line(get_option_("support_material_interface_speed"));
optgroup->append_single_option_line(get_option_("bridge_speed"));
optgroup->append_single_option_line(get_option_("gap_fill_speed"));
optgroup = page->new_optgroup("Speed for non-print moves");
optgroup->append_single_option_line(get_option_("travel_speed"));
optgroup = page->new_optgroup("Modifiers");
optgroup->append_single_option_line(get_option_("first_layer_speed"));
optgroup = page->new_optgroup("Acceleration control (advanced)");
optgroup->append_single_option_line(get_option_("perimeter_acceleration"));
optgroup->append_single_option_line(get_option_("infill_acceleration"));
optgroup->append_single_option_line(get_option_("bridge_acceleration"));
optgroup->append_single_option_line(get_option_("first_layer_acceleration"));
optgroup->append_single_option_line(get_option_("default_acceleration"));
optgroup = page->new_optgroup("Autospeed (advanced)");
optgroup->append_single_option_line(get_option_("max_print_speed"));
optgroup->append_single_option_line(get_option_("max_volumetric_speed"));
optgroup->append_single_option_line(get_option_("max_volumetric_extrusion_rate_slope_positive"));
optgroup->append_single_option_line(get_option_("max_volumetric_extrusion_rate_slope_negative"));
page = add_options_page("Multiple Extruders", "funnel.png");
optgroup = page->new_optgroup("Extruders");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("perimeter_extruder"));
optgroup->append_single_option_line(get_option_("infill_extruder"));
optgroup->append_single_option_line(get_option_("solid_infill_extruder"));
optgroup->append_single_option_line(get_option_("support_material_extruder"));
optgroup->append_single_option_line(get_option_("support_material_interface_extruder"));
optgroup = page->new_optgroup("Ooze prevention");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("ooze_prevention"));
optgroup->append_single_option_line(get_option_("standby_temperature_delta"));
optgroup = page->new_optgroup("Wipe tower");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("wipe_tower"));
optgroup->append_single_option_line(get_option_("wipe_tower_x"));
optgroup->append_single_option_line(get_option_("wipe_tower_y"));
optgroup->append_single_option_line(get_option_("wipe_tower_width"));
optgroup->append_single_option_line(get_option_("wipe_tower_per_color_wipe"));
optgroup = page->new_optgroup("Advanced");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("interface_shells"));
page = add_options_page("Advanced", "wrench.png");
optgroup = page->new_optgroup("Extrusion width", 180);
optgroup->append_single_option_line(get_option_("extrusion_width"));
optgroup->append_single_option_line(get_option_("first_layer_extrusion_width"));
optgroup->append_single_option_line(get_option_("perimeter_extrusion_width"));
optgroup->append_single_option_line(get_option_("external_perimeter_extrusion_width"));
optgroup->append_single_option_line(get_option_("infill_extrusion_width"));
optgroup->append_single_option_line(get_option_("solid_infill_extrusion_width"));
optgroup->append_single_option_line(get_option_("top_infill_extrusion_width"));
optgroup->append_single_option_line(get_option_("support_material_extrusion_width"));
optgroup = page->new_optgroup("Overlap");
optgroup->append_single_option_line(get_option_("infill_overlap"));
optgroup = page->new_optgroup("Flow");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("bridge_flow_ratio"));
optgroup = page->new_optgroup("Other");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("clip_multipart_objects"));
optgroup->append_single_option_line(get_option_("elefant_foot_compensation"));
optgroup->append_single_option_line(get_option_("xy_size_compensation"));
// # optgroup->append_single_option_line(get_option_("threads"));
optgroup->append_single_option_line(get_option_("resolution"));
page = add_options_page("Output options", "page_white_go.png");
2017-12-26 22:04:54 +00:00
optgroup = page->new_optgroup("Sequential printing");
optgroup->append_single_option_line(get_option_("complete_objects"));
line = Line{ "Extruder clearance (mm)", "" };
Option option = get_option_("extruder_clearance_radius");
option.opt.width = 60;
line.append_option(option);
option = get_option_("extruder_clearance_height");
option.opt.width = 60;
line.append_option(option);
optgroup->append_line(line);
optgroup = page->new_optgroup("Output file");
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(get_option_("gcode_comments"));
option = get_option_("output_filename_format");
option.opt.full_width = true;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup("Post-processing scripts", 0);
option = get_option_("post_process");
option.opt.full_width = true;
option.opt.height = 50;
optgroup->append_single_option_line(option);
page = add_options_page("Notes", "note.png");
optgroup = page->new_optgroup("Notes", 0);
option = get_option_("notes");
option.opt.full_width = true;
option.opt.height = 250;
optgroup->append_single_option_line(option);
page = add_options_page("Dependencies", "wrench.png");
2017-12-26 22:04:54 +00:00
optgroup = page->new_optgroup("Profile dependencies");
line = Line{ "Compatible printers", "" };
2017-12-26 22:04:54 +00:00
line.widget = [this](wxWindow* parent){
return compatible_printers_widget(parent, m_compatible_printers_checkbox, m_compatible_printers_btn);
};
optgroup->append_line(line);
}
void CTabFilament::build()
{
2017-12-26 22:04:54 +00:00
m_config = m_preset_bundle->filaments.get_edited_preset().config;
m_config_def = m_config.def();
2017-12-26 22:04:54 +00:00
auto page = add_options_page("Filament", "spool.png");
auto optgroup = page->new_optgroup("Filament");
optgroup->append_single_option_line(get_option_("filament_colour"));
optgroup->append_single_option_line(get_option_("filament_diameter"));
optgroup->append_single_option_line(get_option_("extrusion_multiplier"));
optgroup->append_single_option_line(get_option_("filament_density"));
optgroup->append_single_option_line(get_option_("filament_cost"));
optgroup = page->new_optgroup("Temperature (<28>C)");
2017-12-26 22:04:54 +00:00
Line line = { "Extruder", "" };
line.append_option(get_option_("first_layer_temperature"));
line.append_option(get_option_("temperature"));
optgroup->append_line(line);
line = { "Bed", "" };
line.append_option(get_option_("first_layer_bed_temperature"));
line.append_option(get_option_("bed_temperature"));
optgroup->append_line(line);
page = add_options_page("Cooling", "hourglass.png");
optgroup = page->new_optgroup("Enable");
optgroup->append_single_option_line(get_option_("fan_always_on"));
optgroup->append_single_option_line(get_option_("cooling"));
line = { "", "" };
line.full_width = 1;
2017-12-26 22:04:54 +00:00
line.widget = [this](wxWindow* parent) {
return description_line_widget(parent, m_cooling_description_line);
};
optgroup->append_line(line);
optgroup = page->new_optgroup("Fan settings");
line = {"Fan speed",""};
line.append_option(get_option_("min_fan_speed"));
line.append_option(get_option_("max_fan_speed"));
optgroup->append_line(line);
optgroup->append_single_option_line(get_option_("bridge_fan_speed"));
optgroup->append_single_option_line(get_option_("disable_fan_first_layers"));
optgroup = page->new_optgroup("Cooling thresholds", 250);
optgroup->append_single_option_line(get_option_("fan_below_layer_time"));
optgroup->append_single_option_line(get_option_("slowdown_below_layer_time"));
optgroup->append_single_option_line(get_option_("min_print_speed"));
page = add_options_page("Advanced", "wrench.png");
optgroup = page->new_optgroup("Filament properties");
optgroup->append_single_option_line(get_option_("filament_type"));
optgroup->append_single_option_line(get_option_("filament_soluble"));
2017-12-26 22:04:54 +00:00
optgroup = page->new_optgroup("Print speed override");
optgroup->append_single_option_line(get_option_("filament_max_volumetric_speed"));
line = {"",""};
line.full_width = 1;
2017-12-26 22:04:54 +00:00
line.widget = [this](wxWindow* parent) {
return description_line_widget(parent, m_volumetric_speed_description_line);
};
optgroup->append_line(line);
page = add_options_page("Custom G-code", "cog.png");
optgroup = page->new_optgroup("Start G-code", 0);
Option option = get_option_("start_filament_gcode");
option.opt.full_width = true;
option.opt.height = 150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup("End G-code", 0);
option = get_option_("end_filament_gcode");
option.opt.full_width = true;
option.opt.height = 150;
optgroup->append_single_option_line(option);
page = add_options_page("Notes", "note.png");
optgroup = page->new_optgroup("Notes", 0);
optgroup->label_width = 0;
option = get_option_("filament_notes");
option.opt.full_width = true;
option.opt.height = 250;
2017-12-26 22:04:54 +00:00
optgroup->append_single_option_line(option);
page = add_options_page("Dependencies", "wrench.png");
optgroup = page->new_optgroup("Profile dependencies");
line = {"Compatible printers", ""};
2017-12-26 22:04:54 +00:00
line.widget = [this](wxWindow* parent){
return compatible_printers_widget(parent, m_compatible_printers_checkbox, m_compatible_printers_btn);
};
optgroup->append_line(line);
}
2017-12-26 22:04:54 +00:00
wxSizer* CTabFilament::description_line_widget(wxWindow* parent, wxStaticText* StaticText)
{
StaticText = new wxStaticText(parent, wxID_ANY, "gfghjkkl;\n fgdsufhsreotklg\n iesrftorsikgyfkh\nauiwrhfidj", wxDefaultPosition, wxDefaultSize);
auto font = (new wxSystemSettings)->GetFont(wxSYS_DEFAULT_GUI_FONT);
StaticText->SetFont(font);
StaticText->Wrap(400);
StaticText->GetParent()->Layout();
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(StaticText);
return sizer;
}
//#include "../../libslic3r/GCodeSender.hpp";
void CTabPrinter::build()
{
2017-12-26 22:04:54 +00:00
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)
// $self->{extruders_count} = scalar @{$self->{config}->nozzle_diameter};
2017-12-26 22:04:54 +00:00
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config.option("nozzle_diameter"));
// size_t extruders_count = nozzle_diameter->values.size();
auto page = add_options_page("General", "printer_empty.png");
auto optgroup = page->new_optgroup("Size and coordinates");
Line line = { "Bed shape", "" };
2017-12-26 22:04:54 +00:00
line.widget = [](wxWindow* parent){
auto btn = new wxButton(parent, wxID_ANY, "Set<EFBFBD>", 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_single_option_line(get_option_("z_offset"));
optgroup = page->new_optgroup("Capabilities");
ConfigOptionDef def;
def.type = coInt,
def.default_value = new ConfigOptionInt(1);
def.label = "Extruders";
def.tooltip = "Number of extruders of the printer.";
def.min = 1;
Option option(def, "extruders_count");
optgroup->append_single_option_line(option);
optgroup->append_single_option_line(get_option_("single_extruder_multi_material"));
// $optgroup->on_change(sub{
// my($opt_key, $value) = @_;
// wxTheApp->CallAfter(sub{
// if ($opt_key eq 'extruders_count') {
// $self->_extruders_count_changed($optgroup->get_value('extruders_count'));
// $self->update_dirty;
// }
// else {
// $self->update_dirty;
// $self->_on_value_change($opt_key, $value);
// }
// });
// });
// if (!$params{ no_controller })
// {
optgroup = page->new_optgroup("USB/Serial connection");
line = {"Serial port", ""};
Option serial_port = get_option_("serial_port");
serial_port.side_widget = ([](wxWindow* parent){
2017-12-26 22:04:54 +00:00
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");
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
2017-12-26 22:04:54 +00:00
btn->Bind(wxEVT_BUTTON, [](wxCommandEvent e) {/*_update_serial_ports*/; });
return sizer;
});
2017-12-26 22:04:54 +00:00
auto serial_test = [this](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);
2017-12-26 22:04:54 +00:00
btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("wrench.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
2017-12-26 22:04:54 +00:00
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()) {
2017-12-26 22:04:54 +00:00
show_info(parent, "Connection to printer works correctly.", "Success!");
// }
// else {
// show_error(parent, "Connection failed.");
// }
2017-12-26 22:04:54 +00:00
});
return sizer;
2017-12-26 22:04:54 +00:00
};
line.append_option(serial_port);
line.append_option(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
2017-12-26 22:04:54 +00:00
auto octoprint_host_browse = [] (wxWindow* parent) {
auto btn = new wxButton(parent, wxID_ANY, "Browse<EFBFBD>", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
// btn->SetFont($Slic3r::GUI::small_font);
2017-12-26 22:04:54 +00:00
btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("zoom.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
// if (!eval "use Net::Bonjour; 1") {
// btn->Disable;
// }
// btn->Bind(wxEVT_BUTTON, []{
// # look for devices
// my $entries;
// {
// my $res = Net::Bonjour->new('http');
// $res->discover;
// $entries = [$res->entries];
// }
// if (@{$entries}) {
// my $dlg = Slic3r::GUI::BonjourBrowser->new($self, $entries);
// $self->_load_key_value('octoprint_host', $dlg->GetValue . ":".$dlg->GetPort)
// if $dlg->ShowModal == wxID_OK;
// }
// else {
// auto msg_window = new wxMessageDialog(parent, "No Bonjour device found", "Device Browser", wxOK | wxICON_INFORMATION);
// msg_window->ShowModal();
// }
// });
return sizer;
2017-12-26 22:04:54 +00:00
};
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);
// btn->SetFont($Slic3r::GUI::small_font);
2017-12-26 22:04:54 +00:00
btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("wrench.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [](wxCommandEvent e) {
// my $ua = LWP::UserAgent->new;
// $ua->timeout(10);
//
// my $res = $ua->get(
// "http://".$self->{config}->octoprint_host . "/api/version",
// 'X-Api-Key' = > $self->{config}->octoprint_apikey,
// );
// if ($res->is_success) {
// Slic3r::GUI::show_info($self, "Connection to OctoPrint works correctly.", "Success!");
// }
// else {
// Slic3r::GUI::show_error($self,
// "I wasn't able to connect to OctoPrint (".$res->status_line . "). "
// . "Check hostname and OctoPrint version (at least 1.1.0 is required).");
// }
});
return sizer;
2017-12-26 22:04:54 +00:00
};
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_test);
optgroup->append_line(host_line);
optgroup->append_single_option_line(get_option_("octoprint_apikey"));
optgroup = page->new_optgroup("Firmware");
optgroup->append_single_option_line(get_option_("gcode_flavor"));
optgroup = page->new_optgroup("Advanced");
optgroup->append_single_option_line(get_option_("use_relative_e_distances"));
optgroup->append_single_option_line(get_option_("use_firmware_retraction"));
optgroup->append_single_option_line(get_option_("use_volumetric_e"));
optgroup->append_single_option_line(get_option_("variable_layer_height"));
page = add_options_page("Custom G-code", "cog.png");
optgroup = page->new_optgroup("Start G-code", 0);
option = get_option_("start_gcode");
option.opt.full_width = true;
option.opt.height = 150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup("End G-code", 0);
option = get_option_("end_gcode");
option.opt.full_width = true;
option.opt.height = 150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup("Before layer change G-code", 0);
option = get_option_("before_layer_gcode");
option.opt.full_width = true;
option.opt.height = 150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup("After layer change G-code", 0);
option = get_option_("layer_gcode");
option.opt.full_width = true;
option.opt.height = 150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup("Tool change G-code", 0);
option = get_option_("toolchange_gcode");
option.opt.full_width = true;
option.opt.height = 150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup("Between objects G-code (for sequential printing)", 0);
option = get_option_("between_objects_gcode");
option.opt.full_width = true;
option.opt.height = 150;
optgroup->append_single_option_line(option);
page = add_options_page("Notes", "note.png");
optgroup = page->new_optgroup("Notes", 0);
option = get_option_("printer_notes");
option.opt.full_width = true;
option.opt.height = 250;
optgroup->append_single_option_line(option);
// $self->{extruder_pages} = [];
2017-12-26 22:04:54 +00:00
build_extruder_pages();
// $self->_update_serial_ports if (!$params{ no_controller });
}
2017-12-26 22:04:54 +00:00
void CTabPrinter::build_extruder_pages(){
// my $default_config = Slic3r::Config::Full->new;
//
// foreach my $extruder_idx(@{$self->{extruder_pages}} ..$self->{extruders_count}-1) {
//# build page
auto page = /*$self->{extruder_pages}[$extruder_idx] =*/ add_options_page("Extruder "/* . ($extruder_idx + 1)*/, "funnel.png");
auto optgroup = page->new_optgroup("Size");
optgroup->append_single_option_line(get_option_("nozzle_diameter"/*, $extruder_idx*/));
optgroup = page->new_optgroup("Layer height limits");
optgroup->append_single_option_line(get_option_("min_layer_height"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("max_layer_height"/*, $extruder_idx*/));
optgroup = page->new_optgroup("Position (for multi-extruder printers)");
optgroup->append_single_option_line(get_option_("extruder_offset"/*, $extruder_idx*/));
optgroup = page->new_optgroup("Retraction");
optgroup->append_single_option_line(get_option_("retract_length"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("retract_lift"/*, $extruder_idx*/));
Line line = { "Only lift Z", "" };
line.append_option(get_option_("retract_lift_above"/*, $extruder_idx*/));
line.append_option(get_option_("retract_lift_below"/*, $extruder_idx*/));
optgroup->append_line(line);
optgroup->append_single_option_line(get_option_("retract_speed"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("deretract_speed"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("retract_restart_extra"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("retract_before_travel"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("retract_layer_change"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("wipe"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("retract_before_wipe"/*, $extruder_idx*/));
optgroup = page->new_optgroup("Retraction when tool is disabled (advanced settings for multi-extruder setups)");
optgroup->append_single_option_line(get_option_("retract_length_toolchange"/*, $extruder_idx*/));
optgroup->append_single_option_line(get_option_("retract_restart_extra_toolchange"/*, $extruder_idx*/));
optgroup = page->new_optgroup("Preview");
optgroup->append_single_option_line(get_option_("extruder_colour"/*, $extruder_idx*/));
// }
//
// // # remove extra pages
// if ($self->{extruders_count} <= $#{$self->{extruder_pages}}) {
// $_->Destroy for @{$self->{extruder_pages}}[$self->{extruders_count}..$#{$self->{extruder_pages}}];
// splice @{$self->{extruder_pages}}, $self->{extruders_count};
// }
//
// // # rebuild page list
// my @pages_without_extruders = (grep $_->{title} !~/ ^Extruder \d + / , @{$self->{pages}});
// my $page_notes = pop @pages_without_extruders;
// @{$self->{pages}} = (
// @pages_without_extruders,
// @{$self->{extruder_pages}}[0 ..$self->{extruders_count}-1],
// $page_notes
// );
rebuild_page_tree();
}
//Regerenerate content of the page tree.
void CTab::rebuild_page_tree()
{
Freeze();
// get label of the currently selected item
2017-12-26 22:04:54 +00:00
auto selected = m_treectrl->GetItemText(m_treectrl->GetSelection());
auto rootItem = m_treectrl->GetRootItem();
m_treectrl->DeleteChildren(rootItem);
auto have_selection = 0;
2017-12-26 22:04:54 +00:00
for (auto p : m_pages)
{
2017-12-26 22:04:54 +00:00
auto itemId = m_treectrl->AppendItem(rootItem, p->title(), p->iconID());
if (p->title() == selected) {
2017-12-26 22:04:54 +00:00
m_disable_tree_sel_changed_event = 1;
m_treectrl->SelectItem(itemId);
m_disable_tree_sel_changed_event = 0;
have_selection = 1;
}
}
if (!have_selection) {
// this is triggered on first load, so we don't disable the sel change event
2017-12-26 22:04:54 +00:00
m_treectrl->SelectItem(m_treectrl->GetFirstVisibleItem());//! (treectrl->GetFirstChild(rootItem));
}
Thaw();
}
void CTab::OnTreeSelChange(wxTreeEvent& event)
{
2017-12-26 22:04:54 +00:00
if (m_disable_tree_sel_changed_event) return;
2017-12-05 14:54:01 +00:00
CPage* page = nullptr;
2017-12-26 22:04:54 +00:00
auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
for (auto p : m_pages)
if (p->title() == selection)
2017-12-05 14:54:01 +00:00
{
page = p.get();
2017-12-05 14:54:01 +00:00
break;
}
if (page == nullptr) return;
2017-12-26 22:04:54 +00:00
for (auto& el : m_pages)
el.get()->Hide();
2017-12-05 14:54:01 +00:00
page->Show();
2017-12-26 22:04:54 +00:00
m_hsizer->Layout();
Refresh();
}
2017-12-05 14:54:01 +00:00
void CTab::OnKeyDown(wxKeyEvent& event)
{
event.GetKeyCode() == WXK_TAB ?
2017-12-26 22:04:54 +00:00
m_treectrl->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward) :
2017-12-05 14:54:01 +00:00
event.Skip();
};
void CTab::save_preset(wxCommandEvent &event){};
void CTab::delete_preset(wxCommandEvent &event){};
2017-12-26 22:04:54 +00:00
void CTab::toggle_show_hide_incompatible(wxCommandEvent &event){};
2017-12-05 14:54:01 +00:00
// # Return a callback to create a Tab widget to mark the preferences as compatible / incompatible to the current printer.
2017-12-26 22:04:54 +00:00
wxSizer* CTab::compatible_printers_widget(wxWindow* parent, wxCheckBox* checkbox, wxButton* btn)
{
2017-12-26 22:04:54 +00:00
checkbox = new wxCheckBox(parent, wxID_ANY, "All");
2017-12-26 22:04:54 +00:00
btn = new wxButton(parent, wxID_ANY, "Set<EFBFBD>", wxDefaultPosition, wxDefaultSize,
wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(GUI::small_font);
2017-12-26 22:04:54 +00:00
btn->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var("printer_empty.png").c_str()), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(checkbox, 0, wxALIGN_CENTER_VERTICAL);
sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL);
checkbox->Bind(wxEVT_CHECKBOX, ([=](wxCommandEvent e)
{
btn->Enable(!checkbox->GetValue());
// # All printers have been made compatible with this preset.
// _load_key_value('compatible_printers', []) if checkbox->GetValue();
}) );
btn->Bind(wxEVT_BUTTON, ([=](wxCommandEvent e)
{
PresetCollection *prints = new PresetCollection(Preset::TYPE_PRINT, Preset::print_options());
prints->preset(0).config.opt_string("print_settings_id", true);
prints->preset(0).config.optptr("compatible_printers", true);
DynamicPrintConfig config_ = prints->get_edited_preset().config;
// # Collect names of non-default non-external printer profiles.
PresetCollection *printers = new PresetCollection(Preset::TYPE_PRINTER, Preset::print_options());
printers->preset(0).config.opt_string("print_settings_id", true);
wxArrayString presets;
for (size_t idx = 0; idx < printers->size(); ++idx)
{
Preset& preset = printers->preset(idx);
if (!preset.is_default && !preset.is_external)
presets.Add(preset.name);
}
auto dlg = new wxMultiChoiceDialog(parent,
"Select the printers this profile is compatible with.",
"Compatible printers", presets);
// # Collect and set indices of printers marked as compatible.
wxArrayInt selections;
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(config_.option("compatible_printers"));
if (compatible_printers != nullptr || !compatible_printers->values.empty())
for (auto preset_name : compatible_printers->values)
for (size_t idx = 0; idx < presets.GetCount(); ++idx)
if (presets[idx].compare(preset_name) == 0)
{
selections.Add(idx);
break;
}
dlg->SetSelections(selections);
// # Show the dialog.
if (dlg->ShowModal() == wxID_OK) {
selections.Clear();
selections = dlg->GetSelections();
std::vector<std::string> value;
for (auto idx : selections)
value.push_back(presets[idx].ToStdString());
if (/*!@$value*/value.empty()) {
checkbox->SetValue(1);
btn->Disable();
}
// # All printers have been made compatible with this preset.
// _load_key_value('compatible_printers', $value);
}
}));
return sizer;
}
// package Slic3r::GUI::Tab::Page;
ConfigOptionsGroupShp CPage::new_optgroup(std::string title, int noncommon_label_width /*= -1*/)
{
//! config_ have to be "right"
2017-12-26 22:04:54 +00:00
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config);
if (noncommon_label_width >= 0)
optgroup->label_width = noncommon_label_width;
// on_change => sub {
// my ($opt_key, $value) = @_;
// wxTheApp->CallAfter(sub {
// $self->GetParent->update_dirty;
// $self->GetParent->_on_value_change($opt_key, $value);
// });
// },
vsizer()->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 10);
2017-12-26 22:04:54 +00:00
m_optgroups.push_back(optgroup);
return optgroup;
}
2017-12-05 14:54:01 +00:00
} // GUI
} // Slic3r