diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index e3e773f7d0..146696d1ea 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -527,12 +527,16 @@ void TabPrint::build() sizer->Add(m_wipe_tower_btn); m_wipe_tower_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent& e) { - std::vector init_data = (m_config->option("wiping_volumes_matrix"))->values; - WipingDialog dlg(this,std::vector(init_data.begin(), init_data.end())); // dlg lives on stack, no need to call Destroy + std::vector init_matrix = (m_config->option("wiping_volumes_matrix"))->values; + std::vector init_extruders = (m_config->option("wiping_volumes_extruders"))->values; + + WipingDialog dlg(this,std::vector(init_matrix.begin(),init_matrix.end()),std::vector(init_extruders.begin(),init_extruders.end())); if (dlg.ShowModal() == wxID_OK) { - //load_key_value("wiping_volumes_matrix", dlg.GetValue()); - //std::cout << std::endl << "dialog returned: " << dlg.GetValue() << std::endl; + std::vector matrix = dlg.get_matrix(); + std::vector extruders = dlg.get_extruders(); + (m_config->option("wiping_volumes_matrix"))->values = std::vector(matrix.begin(),matrix.end()); + (m_config->option("wiping_volumes_extruders"))->values = std::vector(extruders.begin(),extruders.end()); } })); return sizer; diff --git a/xs/src/slic3r/GUI/WipeTowerDialog.cpp b/xs/src/slic3r/GUI/WipeTowerDialog.cpp index 1c69285b7b..fc3d30a5d4 100644 --- a/xs/src/slic3r/GUI/WipeTowerDialog.cpp +++ b/xs/src/slic3r/GUI/WipeTowerDialog.cpp @@ -2,6 +2,11 @@ #include #include "WipeTowerDialog.hpp" +//! macro used to mark string used at localization, +//! return same string +#define L(s) s + + RammingDialog::RammingDialog(wxWindow* parent,const std::string& parameters) : wxDialog(parent, -1, wxT("Ramming customization"), wxPoint(50,50), wxSize(800,550), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) @@ -97,37 +102,12 @@ std::string RammingPanel::get_parameters() - - - - -/* -void WipingPanel::fill_parameters(Slic3r::WipeTowerParameters& p) { - p.wipe_volumes.clear(); - p.filament_wipe_volumes.clear(); - for (int i=0;i<4;++i) { - // first go through the full matrix: - p.wipe_volumes.push_back(std::vector()); - for (int j=0;j<4;++j) { - double val = 0.; - edit_boxes[j][i]->GetValue().ToDouble(&val); - p.wipe_volumes[i].push_back((float)val); - } - - // now the filament volumes: - p.filament_wipe_volumes.push_back(std::make_pair(m_old[i]->GetValue(),m_new[i]->GetValue())); - } -} -*/ - - - -WipingDialog::WipingDialog(wxWindow* parent,const std::vector& init_data) -: wxDialog(parent, -1, wxT("Wiping customization"), wxPoint(50,50), wxSize(800,550), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) +WipingDialog::WipingDialog(wxWindow* parent,const std::vector& matrix, const std::vector& extruders) +: wxDialog(parent, -1, wxT(L("Wipe tower - Purging volume adjustment")), wxPoint(50,50), wxSize(800,550), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { this->Centre(); - m_panel_wiping = new WipingPanel(this,init_data); + m_panel_wiping = new WipingPanel(this,matrix,extruders); this->Show(); auto main_sizer = new wxBoxSizer(wxVERTICAL); @@ -140,59 +120,85 @@ WipingDialog::WipingDialog(wxWindow* parent,const std::vector& init_data) this->Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& e) { EndModal(wxCANCEL); }); this->Bind(wxEVT_BUTTON,[this](wxCommandEvent&) { - //m_output_data=read_dialog_values(); + m_output_matrix = m_panel_wiping->read_matrix_values(); + m_output_extruders = m_panel_wiping->read_extruders_values(); EndModal(wxID_OK); },wxID_OK); } -WipingPanel::WipingPanel(wxWindow* parent,const std::vector& data) -: wxPanel(parent,wxID_ANY,wxPoint(50,50), wxSize(800,350),wxBORDER_RAISED) + +WipingPanel::WipingPanel(wxWindow* parent, const std::vector& matrix, const std::vector& extruders) +: wxPanel(parent,wxID_ANY,wxPoint(50,50), wxSize(500,350),wxBORDER_RAISED) { - const int N = 4; // number of extruders - new wxStaticText(this,wxID_ANY,wxString("Volume to wipe when the filament is being"),wxPoint(40,55) ,wxSize(500,25)); - new wxStaticText(this,wxID_ANY,wxString("unloaded"),wxPoint(110,75) ,wxSize(500,25)); - new wxStaticText(this,wxID_ANY,wxString("loaded"),wxPoint(195,75) ,wxSize(500,25)); - m_widget_button = new wxButton(this,wxID_ANY,"-> Fill in the matrix ->",wxPoint(300,130),wxSize(175,50)); - for (int i=0;i(0)); - new wxStaticText(this,wxID_ANY,wxString("")<Disable(); else - edit_boxes[i][j]->SetValue(wxString("")<SetValue(wxString("")<Bind(wxEVT_BUTTON,[this](wxCommandEvent&){fill_in_matrix();}); - Refresh(this); + + m_widget_button->Bind(wxEVT_BUTTON,[this](wxCommandEvent&){toggle_advanced(true);}); + toggle_advanced(); } + + + + +std::vector WipingPanel::read_matrix_values() { + if (!m_advanced) + fill_in_matrix(); + std::vector output; + for (unsigned int i=0;iGetValue().ToDouble(&val); + output.push_back((float)val); + } + } + return output; +} + + +std::vector WipingPanel::read_extruders_values() { + std::vector output; + for (unsigned int i=0;iGetValue()); + output.push_back(m_new[i]->GetValue()); + } + return output; +} + + void WipingPanel::fill_in_matrix() { - wxArrayString choices; - choices.Add("sum"); - choices.Add("maximum"); - wxSingleChoiceDialog dialog(this,"How shall I calculate volume for any given pair?\n\nI can either sum volumes for old and new filament, or just use the higher value.","DEBUGGING",choices); - if (dialog.ShowModal() == wxID_CANCEL) - return; - for (unsigned i=0;i<4;++i) { - for (unsigned j=0;j<4;++j) { + for (unsigned i=0;iSetValue(wxString("")<< (m_old[i]->GetValue() + m_new[j]->GetValue())); - else - edit_boxes[j][i]->SetValue(wxString("")<< (std::max(m_old[i]->GetValue(), m_new[j]->GetValue()))); + edit_boxes[j][i]->SetValue(wxString("")<< (m_old[i]->GetValue() + m_new[j]->GetValue())); } } } @@ -200,7 +206,52 @@ void WipingPanel::fill_in_matrix() { +bool WipingPanel::advanced_matches_simple() { + for (unsigned i=0;iGetValue() != (wxString("")<< (m_old[i]->GetValue() + m_new[j]->GetValue()))) + return false; + } + } + return true; +} +void WipingPanel::toggle_advanced(bool user_button) { + if (m_advanced && !advanced_matches_simple() && user_button) { + if (wxMessageDialog(this,wxString(L("Switching to simple settings will discard changes done in the advanced mode!\n\nDo you want to proceed?")), + wxString(L("Warning")),wxYES_NO|wxICON_EXCLAMATION).ShowModal() != wxID_YES) + return; + } + m_advanced = !m_advanced; + + if (!user_button) { // we were called from constructor + if (advanced_matches_simple()) // advanced and simple match - let's show simple version + m_advanced = false; + else + m_advanced = true; + } + + for (unsigned i=0;iShow(m_advanced); + m_old[i]->Show(!m_advanced); + m_new[i]->Show(!m_advanced); + } + for (const auto& widget : m_advanced_widgets) // shows/hides other widgets + widget->Show(m_advanced); + for (const auto& widget : m_notadvanced_widgets) + widget->Show(!m_advanced); + + if (m_advanced) { + if (user_button) fill_in_matrix(); // otherwise keep values loaded from config + m_widget_button->SetLabel(L("Show simplified settings")); + } + else + m_widget_button->SetLabel(L("Show advanced settings")); + + this->Refresh(); +} \ No newline at end of file diff --git a/xs/src/slic3r/GUI/WipeTowerDialog.hpp b/xs/src/slic3r/GUI/WipeTowerDialog.hpp index 8e84f3dc16..0adefe5f27 100644 --- a/xs/src/slic3r/GUI/WipeTowerDialog.hpp +++ b/xs/src/slic3r/GUI/WipeTowerDialog.hpp @@ -46,18 +46,28 @@ private: + + + class WipingPanel : public wxPanel { public: - WipingPanel(wxWindow* parent,const std::vector& data); - void fill_parameters(Slic3r::WipeTowerParameters& p); + WipingPanel(wxWindow* parent, const std::vector& matrix, const std::vector& extruders); + std::vector read_matrix_values(); + std::vector read_extruders_values(); private: void fill_in_matrix(); + void toggle_advanced(bool user_button = false); + bool advanced_matches_simple(); std::vector m_old; std::vector m_new; + std::vector m_advanced_widgets; + std::vector m_notadvanced_widgets; std::vector> edit_boxes; - wxButton* m_widget_button=nullptr; + wxButton* m_widget_button = nullptr; + unsigned int m_number_of_extruders = 0; + bool m_advanced = false; }; @@ -66,19 +76,15 @@ private: class WipingDialog : public wxDialog { public: - WipingDialog(wxWindow* parent,const std::vector& init_data); - std::vector get_value() const { return m_output_data; } - - + WipingDialog(wxWindow* parent,const std::vector& matrix, const std::vector& extruders); + std::vector get_matrix() const { return m_output_matrix; } + std::vector get_extruders() const { return m_output_extruders; } + + private: WipingPanel* m_panel_wiping = nullptr; - std::vector m_output_data; - - std::string read_dialog_values() { - Slic3r::WipeTowerParameters p; - m_panel_wiping ->fill_parameters(p); - //return p.to_string(); - } + std::vector m_output_matrix; + std::vector m_output_extruders; }; #endif // _WIPE_TOWER_DIALOG_H_ \ No newline at end of file