Ported show_preset_comboboxes function

This commit is contained in:
YuSanka 2018-10-09 12:41:05 +02:00
parent 9f1613bffb
commit 085020a814
8 changed files with 93 additions and 58 deletions

View file

@ -132,7 +132,8 @@ void MainFrame::init_tabpanel()
m_tabpanel->AddPage(m_plater, _(L("Plater")));
}
// The following event is emited by the C++ Tab implementation on config value change.
// The following event is emited by Tab implementation on config value change.
Bind(EVT_TAB_VALUE_CHANGED, &MainFrame::on_value_changed, this);
// EVT_COMMAND($self, -1, $VALUE_CHANGE_EVENT, sub {
// my($self, $event) = @_;
// auto str = event->GetString;
@ -145,10 +146,6 @@ void MainFrame::init_tabpanel()
// auto value = event->GetInt();
// m_plater->on_extruders_change(value);
// }
// if (opt_key == "printer_technology"){
// auto value = event->GetInt(); // 0 ~"ptFFF"; 1 ~"ptSLA"
// m_plater->show_preset_comboboxes(value);
// }
// }
// // don't save while loading for the first time
// if (Slic3r::GUI::autosave && m_loaded)
@ -759,21 +756,14 @@ void MainFrame::on_presets_changed(SimpleEvent &event)
auto reload_dependent_tabs = tab->get_dependent_tabs();
// FIXME: The preset type really should be a property of Tab instead
Slic3r::Preset::Type preset_type;
if (tab == m_options_tabs["print"]) { preset_type = Slic3r::Preset::TYPE_PRINT; }
else if (tab == m_options_tabs["filament"]) { preset_type = Slic3r::Preset::TYPE_FILAMENT; }
else if (tab == m_options_tabs["sla_material"]) { preset_type = Slic3r::Preset::TYPE_SLA_MATERIAL; }
else if (tab == m_options_tabs["printer"]) { preset_type = Slic3r::Preset::TYPE_PRINTER; }
else {
Slic3r::Preset::Type preset_type = tab->type();
if (preset_type == Slic3r::Preset::TYPE_INVALID){
wxASSERT(false);
return;
}
m_plater->sidebar().update_presets(preset_type);
// XXX: ???
// m_plater->{"selected_item_$tab_name"} = tab->get_selected_preset_item();
if (preset_type == Slic3r::Preset::TYPE_PRINTER) {
// Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors.
// XXX: Do this in a more C++ way
@ -789,12 +779,18 @@ void MainFrame::on_presets_changed(SimpleEvent &event)
else
cur_tab->load_current_preset();
}
m_plater->sidebar().show_preset_comboboxes(static_cast<TabPrinter*>(tab)->m_printer_technology == ptSLA);
}
// XXX: ?
// m_plater->on_config_change(tab->get_config());
}
}
void MainFrame::on_value_changed(wxCommandEvent&)
{
;
}
// Called after the Preferences dialog is closed and the program settings are saved.
// Update the UI based on the current preferences.
void MainFrame::update_ui_from_settings()

View file

@ -73,6 +73,7 @@ class MainFrame : public wxFrame
std::string get_dir_name(const wxString full_name) const ;
void on_presets_changed(SimpleEvent&);
void on_value_changed(wxCommandEvent&);
Tab* get_tab(const std::string& name);
public:

View file

@ -168,21 +168,6 @@ SlicedInfo::SlicedInfo(wxWindow *parent) :
Add(grid_sizer, 0, wxEXPAND);
}
class PresetComboBox : public wxBitmapComboBox
{
public:
PresetComboBox(wxWindow *parent, Preset::Type preset_type);
~PresetComboBox();
private:
typedef std::size_t Marker;
enum { LABEL_ITEM_MARKER = 0x4d };
Preset::Type preset_type;
int last_selected;
};
PresetComboBox::PresetComboBox(wxWindow *parent, Preset::Type preset_type) :
wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY),
preset_type(preset_type),
@ -198,6 +183,7 @@ PresetComboBox::PresetComboBox(wxWindow *parent, Preset::Type preset_type) :
} else if (this->last_selected != selected_item) {
this->last_selected = selected_item;
evt.SetInt(this->preset_type);
evt.Skip();
} else {
evt.StopPropagation();
}
@ -207,6 +193,11 @@ PresetComboBox::PresetComboBox(wxWindow *parent, Preset::Type preset_type) :
PresetComboBox::~PresetComboBox() {}
void PresetComboBox::set_label_marker(int item)
{
this->SetClientData(item, (void*)LABEL_ITEM_MARKER);
}
// Frequently changed parameters
class FreqChangedParams : public OG_Settings
@ -520,6 +511,22 @@ void Sidebar::update_presets(Preset::Type preset_type)
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
}
void Sidebar::show_preset_comboboxes(bool showSLA)
{
// wxWindowUpdateLocker noUpdates(wxGetApp().mainframe);
for (size_t i = 0; i < 4; ++i)
p->sizer_presets->Show(i, !showSLA);
p->sizer_presets->Show(4, showSLA);
p->sizer_presets->Show(5, showSLA);
p->frequently_changed_parameters->get_sizer()->Show(!showSLA);
wxGetApp().plater()->Layout();
wxGetApp().mainframe->Layout();
}
ObjectManipulation* Sidebar::obj_manipul()
{
return p->object_manipulation;
@ -578,6 +585,11 @@ void Sidebar::enable_buttons(bool enable)
p->btn_send_gcode->Enable(enable);
}
bool Sidebar::is_multifilament()
{
return p->combos_filament.size() > 0;
}
// Plater::Object
struct PlaterObject
@ -1305,26 +1317,29 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
auto preset_type = static_cast<Preset::Type>(evt.GetInt());
auto *combo = static_cast<wxBitmapComboBox*>(evt.GetEventObject());
auto idx = 0;// evt.GetId();
if (preset_type == Preset::TYPE_FILAMENT) {
// FIXME:
// wxTheApp->{preset_bundle}->set_filament_preset($idx, $choice->GetStringSelection);
wxGetApp().preset_bundle->set_filament_preset(idx, combo->GetStringSelection().ToStdString());
}
// TODO: ?
if (false) {
// if ($group eq 'filament' && @{$self->{preset_choosers}{filament}} > 1) {
// # Only update the platter UI for the 2nd and other filaments.
// wxTheApp->{preset_bundle}->update_platter_filament_ui($idx, $choice);
if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) {
// Only update the platter UI for the 2nd and other filaments.
wxGetApp().preset_bundle->update_platter_filament_ui(idx, combo);
// }
} else {
auto selected_item = combo->GetSelection();
// TODO: Handle by an event handler in MainFrame, if needed
for (Tab* tab : wxGetApp().tabs_list) {
if (tab->type() == preset_type) {
tab->select_preset(combo->GetStringSelection().ToStdString());
break;
}
}
}
// Synchronize config.ini with the current selections.
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
// TODO:
// # Synchronize config.ini with the current selections.
// wxTheApp->{preset_bundle}->export_selections(wxTheApp->{app_config});
// # get new config and generate on_config_change() event for updating plater and other things
// $self->on_config_change(wxTheApp->{preset_bundle}->full_config);
}

View file

@ -6,6 +6,7 @@
#include <boost/filesystem/path.hpp>
#include <wx/panel.h>
#include <wx/bmpcbox.h>
#include "Preset.hpp"
@ -27,6 +28,22 @@ using t_optgroups = std::vector <std::shared_ptr<ConfigOptionsGroup>>;
class Plater;
class PresetComboBox : public wxBitmapComboBox
{
public:
PresetComboBox(wxWindow *parent, Preset::Type preset_type);
~PresetComboBox();
void set_label_marker(int item);
private:
typedef std::size_t Marker;
enum { LABEL_ITEM_MARKER = 0x4d };
Preset::Type preset_type;
int last_selected;
};
class Sidebar : public wxPanel
{
public:
@ -38,8 +55,9 @@ public:
~Sidebar();
void update_presets(Slic3r::Preset::Type preset_type);
void show_preset_comboboxes(bool showSLA);
ObjectManipulation* obj_manipul();
ObjectManipulation* obj_manipul();
ObjectList* obj_list();
ConfigOptionsGroup* og_freq_chng_params();
@ -49,6 +67,7 @@ public:
void show_info_sizers(const bool show);
void show_buttons(const bool show);
void enable_buttons(bool enable);
bool is_multifilament();
private:
struct priv;

View file

@ -28,6 +28,7 @@
#include "../../libslic3r/libslic3r.h"
#include "../../libslic3r/Utils.hpp"
#include "../../libslic3r/PlaceholderParser.hpp"
#include "Plater.hpp"
using boost::property_tree::ptree;
@ -734,7 +735,7 @@ size_t PresetCollection::update_compatible_with_printer_internal(const Preset &a
// Update the wxChoice UI component from this list of presets.
// Hide the
void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
{
if (ui == nullptr)
return;
@ -751,7 +752,7 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
std::map<wxString, wxBitmap*> nonsys_presets;
wxString selected = "";
if (!this->m_presets.front().is_visible)
ui->Append("------- " +_(L("System presets")) + " -------", wxNullBitmap);
ui->set_label_marker(ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap));
for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++i) {
const Preset &preset = this->m_presets[i];
if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected))
@ -791,11 +792,11 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str());
}
if (i + 1 == m_num_default_presets)
ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap);
ui->set_label_marker(ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap));
}
if (!nonsys_presets.empty())
{
ui->Append("------- " + _(L("User presets")) + " -------", wxNullBitmap);
ui->set_label_marker(ui->Append("------- " + _(L("User presets")) + " -------", wxNullBitmap));
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
ui->Append(it->first, *it->second);
if (it->first == selected)

View file

@ -22,6 +22,7 @@ class PresetBundle;
namespace GUI {
class BitmapCache;
class PresetComboBox;
}
enum ConfigFileType
@ -355,7 +356,7 @@ public:
// Update the choice UI from the list of presets.
// Only the compatible presets are shown.
// If an incompatible preset is selected, it is shown as well.
void update_platter_ui(wxBitmapComboBox *ui);
void update_platter_ui(GUI::PresetComboBox *ui);
// Update a dirty floag of the current preset, update the labels of the UI component accordingly.
// Return true if the dirty flag changed.

View file

@ -38,6 +38,15 @@ wxDEFINE_EVENT(EVT_TAB_VALUE_CHANGED, wxCommandEvent);
wxDEFINE_EVENT(EVT_TAB_PRESETS_CHANGED, SimpleEvent);
void Tab::set_type()
{
if (m_name == "print") { m_type = Slic3r::Preset::TYPE_PRINT; }
else if (m_name == "filament") { m_type = Slic3r::Preset::TYPE_FILAMENT; }
else if (m_name == "sla_material") { m_type = Slic3r::Preset::TYPE_SLA_MATERIAL; }
else if (m_name == "printer") { m_type = Slic3r::Preset::TYPE_PRINTER; }
else { m_type = Slic3r::Preset::TYPE_INVALID; }
}
// sub new
void Tab::create_preset_tab()
{
@ -672,14 +681,6 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
event.SetInt(val);
}
if (opt_key == "printer_technology")
{
int val = boost::any_cast<PrinterTechnology>(value);
event.SetInt(val);
wxPostEvent(this, event);
return;
}
wxPostEvent(this, event);
@ -1461,8 +1462,6 @@ void TabPrinter::build()
m_printer_technology = m_presets->get_selected_preset().printer_technology();
m_presets->get_selected_preset().printer_technology() == ptSLA ? build_sla() : build_fff();
// on_value_change("printer_technology", m_printer_technology); // to update show/hide preset ComboBoxes
}
void TabPrinter::build_fff()
@ -2044,8 +2043,6 @@ void TabPrinter::update_pages()
m_pages_sla.empty() ? build_sla() : m_pages.swap(m_pages_sla);
rebuild_page_tree(true);
on_value_change("printer_technology", m_presets->get_edited_preset().printer_technology()); // to update show/hide preset ComboBoxes
}
void TabPrinter::update()

View file

@ -108,6 +108,7 @@ class Tab: public wxPanel
int m_size_move = -1;
#endif // __WXOSX__
protected:
Preset::Type m_type;
std::string m_name;
const wxString m_title;
wxBitmapComboBox* m_presets_choice;
@ -183,6 +184,8 @@ protected:
size_t m_selected_preset_item{ 0 };
void set_type();
public:
PresetBundle* m_preset_bundle;
bool m_show_btn_incompatible_presets = false;
@ -196,6 +199,7 @@ public:
Tab(wxNotebook* parent, const wxString& title, const char* name) :
m_parent(parent), m_title(title), m_name(name) {
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL, name);
set_type();
wxGetApp().tabs_list.push_back(this);
}
~Tab(){
@ -205,6 +209,7 @@ public:
wxWindow* parent() const { return m_parent; }
wxString title() const { return m_title; }
std::string name() const { return m_name; }
Preset::Type type() const { return m_type; }
void create_preset_tab();
void load_current_preset();