PhysicalPrinters improvements:
- Added possibility to correct delete presets considering with the physical printers - Smart switching to the printer preset if physical printer was selected
This commit is contained in:
parent
5eac36a310
commit
72ec414f1e
@ -1436,6 +1436,11 @@ bool PhysicalPrinter::add_preset(const std::string& preset_name)
|
|||||||
return preset_names.emplace(preset_name).second;
|
return preset_names.emplace(preset_name).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PhysicalPrinter::delete_preset(const std::string& preset_name)
|
||||||
|
{
|
||||||
|
return preset_names.erase(preset_name) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) :
|
PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) :
|
||||||
name(name)
|
name(name)
|
||||||
{
|
{
|
||||||
@ -1521,7 +1526,6 @@ void PhysicalPrinterCollection::load_printers(const std::string& dir_path, const
|
|||||||
}
|
}
|
||||||
m_printers.insert(m_printers.end(), std::make_move_iterator(printers_loaded.begin()), std::make_move_iterator(printers_loaded.end()));
|
m_printers.insert(m_printers.end(), std::make_move_iterator(printers_loaded.begin()), std::make_move_iterator(printers_loaded.end()));
|
||||||
std::sort(m_printers.begin(), m_printers.end());
|
std::sort(m_printers.begin(), m_printers.end());
|
||||||
//! this->select_preset(first_visible_idx());
|
|
||||||
if (!errors_cummulative.empty())
|
if (!errors_cummulative.empty())
|
||||||
throw std::runtime_error(errors_cummulative);
|
throw std::runtime_error(errors_cummulative);
|
||||||
}
|
}
|
||||||
@ -1542,8 +1546,11 @@ std::string PhysicalPrinterCollection::path_from_name(const std::string& new_nam
|
|||||||
return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
|
return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_printer, const std::string& renamed_from)
|
void PhysicalPrinterCollection::save_printer(PhysicalPrinter& edited_printer, const std::string& renamed_from/* = ""*/)
|
||||||
{
|
{
|
||||||
|
// controll and update preset_names in edited_printer config
|
||||||
|
edited_printer.update_preset_names_in_config();
|
||||||
|
|
||||||
std::string name = renamed_from.empty() ? edited_printer.name : renamed_from;
|
std::string name = renamed_from.empty() ? edited_printer.name : renamed_from;
|
||||||
// 1) Find the printer with a new_name or create a new one,
|
// 1) Find the printer with a new_name or create a new one,
|
||||||
// initialize it with the edited config.
|
// initialize it with the edited config.
|
||||||
@ -1605,6 +1612,33 @@ bool PhysicalPrinterCollection::delete_selected_printer()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PhysicalPrinterCollection::delete_preset_from_printers( const std::string& preset_name, bool first_check /*=true*/)
|
||||||
|
{
|
||||||
|
if (first_check) {
|
||||||
|
for (auto printer: m_printers)
|
||||||
|
if (printer.preset_names.size()==1 && *printer.preset_names.begin() == preset_name)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> printers_for_delete;
|
||||||
|
for (PhysicalPrinter& printer : m_printers)
|
||||||
|
if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name)
|
||||||
|
printers_for_delete.emplace_back(printer.name);
|
||||||
|
else if (printer.delete_preset(preset_name)) {
|
||||||
|
if (printer.name == get_selected_printer_name() &&
|
||||||
|
preset_name == get_selected_printer_preset_name())
|
||||||
|
select_printer(printer);
|
||||||
|
save_printer(printer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!printers_for_delete.empty()) {
|
||||||
|
for (const std::string& printer_name : printers_for_delete)
|
||||||
|
delete_printer(printer_name);
|
||||||
|
unselect_printer();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::string PhysicalPrinterCollection::get_selected_full_printer_name() const
|
std::string PhysicalPrinterCollection::get_selected_full_printer_name() const
|
||||||
{
|
{
|
||||||
return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset);
|
return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset);
|
||||||
@ -1625,6 +1659,23 @@ PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::st
|
|||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PhysicalPrinter& PhysicalPrinterCollection::select_printer(const std::string& printer_name)
|
||||||
|
{
|
||||||
|
auto it = this->find_printer_internal(printer_name);
|
||||||
|
assert(it != m_printers.end());
|
||||||
|
|
||||||
|
// update idx_selected
|
||||||
|
m_idx_selected = it - m_printers.begin();
|
||||||
|
// update name of the currently selected preset
|
||||||
|
m_selected_preset = *it->preset_names.begin();
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhysicalPrinter& PhysicalPrinterCollection::select_printer(const PhysicalPrinter& printer)
|
||||||
|
{
|
||||||
|
return select_printer(printer.name);
|
||||||
|
}
|
||||||
|
|
||||||
bool PhysicalPrinterCollection::has_selection() const
|
bool PhysicalPrinterCollection::has_selection() const
|
||||||
{
|
{
|
||||||
return m_idx_selected != size_t(-1);
|
return m_idx_selected != size_t(-1);
|
||||||
|
@ -569,6 +569,7 @@ public:
|
|||||||
// add preset to the preset_names
|
// add preset to the preset_names
|
||||||
// return false, if preset with this name is already exist in the set
|
// return false, if preset with this name is already exist in the set
|
||||||
bool add_preset(const std::string& preset_name);
|
bool add_preset(const std::string& preset_name);
|
||||||
|
bool delete_preset(const std::string& preset_name);
|
||||||
void reset_presets();
|
void reset_presets();
|
||||||
|
|
||||||
// Return a printer technology, return ptFFF if the printer technology is not set.
|
// Return a printer technology, return ptFFF if the printer technology is not set.
|
||||||
@ -629,7 +630,7 @@ public:
|
|||||||
// Save the printer under a new name. If the name is different from the old one,
|
// Save the printer under a new name. If the name is different from the old one,
|
||||||
// a new printer is stored into the list of printers.
|
// a new printer is stored into the list of printers.
|
||||||
// New printer is activated.
|
// New printer is activated.
|
||||||
void save_printer(const PhysicalPrinter& printer, const std::string& renamed_from);
|
void save_printer(PhysicalPrinter& printer, const std::string& renamed_from = "");
|
||||||
|
|
||||||
// Delete the current preset, activate the first visible preset.
|
// Delete the current preset, activate the first visible preset.
|
||||||
// returns true if the preset was deleted successfully.
|
// returns true if the preset was deleted successfully.
|
||||||
@ -637,6 +638,10 @@ public:
|
|||||||
// Delete the selected preset
|
// Delete the selected preset
|
||||||
// returns true if the preset was deleted successfully.
|
// returns true if the preset was deleted successfully.
|
||||||
bool delete_selected_printer();
|
bool delete_selected_printer();
|
||||||
|
// Delete preset_name preset from all printers:
|
||||||
|
// If there is last preset for the printer and first_check== false, then delete this printer
|
||||||
|
// returns true if all presets were deleted successfully.
|
||||||
|
bool delete_preset_from_printers(const std::string& preset_name, bool first_check = true);
|
||||||
|
|
||||||
// Return the selected preset, without the user modifications applied.
|
// Return the selected preset, without the user modifications applied.
|
||||||
PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; }
|
PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; }
|
||||||
@ -659,6 +664,8 @@ public:
|
|||||||
|
|
||||||
// select printer with name and return reference on it
|
// select printer with name and return reference on it
|
||||||
PhysicalPrinter& select_printer_by_name(const std::string& full_name);
|
PhysicalPrinter& select_printer_by_name(const std::string& full_name);
|
||||||
|
PhysicalPrinter& select_printer(const std::string &printer_name);
|
||||||
|
PhysicalPrinter& select_printer(const PhysicalPrinter& printer);
|
||||||
bool has_selection() const;
|
bool has_selection() const;
|
||||||
void unselect_printer() ;
|
void unselect_printer() ;
|
||||||
bool is_selected(ConstIterator it, const std::string &preset_name) const;
|
bool is_selected(ConstIterator it, const std::string &preset_name) const;
|
||||||
|
@ -357,6 +357,8 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers()
|
|||||||
wxGetApp().get_tab(m_type)->update_preset_choice();
|
wxGetApp().get_tab(m_type)->update_preset_choice();
|
||||||
else if (dynamic_cast<TabPresetComboBox*>(this)!=nullptr)
|
else if (dynamic_cast<TabPresetComboBox*>(this)!=nullptr)
|
||||||
wxGetApp().sidebar().update_presets(m_type);
|
wxGetApp().sidebar().update_presets(m_type);
|
||||||
|
|
||||||
|
this->update();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,6 +616,8 @@ void PlaterPresetComboBox::show_edit_menu()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_preset_bundle->physical_printers.delete_selected_printer();
|
m_preset_bundle->physical_printers.delete_selected_printer();
|
||||||
|
|
||||||
|
wxGetApp().get_tab(m_type)->update_preset_choice();
|
||||||
update();
|
update();
|
||||||
}, "cross", menu, []() { return true; }, wxGetApp().plater());
|
}, "cross", menu, []() { return true; }, wxGetApp().plater());
|
||||||
|
|
||||||
@ -855,9 +859,16 @@ void TabPresetComboBox::update()
|
|||||||
set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
|
set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
|
||||||
int idx_selected = m_collection->get_selected_idx();
|
int idx_selected = m_collection->get_selected_idx();
|
||||||
|
|
||||||
std::string sel_preset_name = m_preset_bundle->physical_printers.get_selected_printer_preset_name();
|
PrinterTechnology proper_pt = ptAny;
|
||||||
PrinterTechnology proper_pt = (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) ?
|
if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) {
|
||||||
m_collection->find_preset(sel_preset_name)->printer_technology() : ptAny;
|
std::string sel_preset_name = m_preset_bundle->physical_printers.get_selected_printer_preset_name();
|
||||||
|
Preset* preset = m_collection->find_preset(sel_preset_name);
|
||||||
|
if (preset)
|
||||||
|
proper_pt = preset->printer_technology();
|
||||||
|
else
|
||||||
|
m_preset_bundle->physical_printers.unselect_printer();
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i)
|
for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i)
|
||||||
{
|
{
|
||||||
const Preset& preset = presets[i];
|
const Preset& preset = presets[i];
|
||||||
@ -868,7 +879,7 @@ void TabPresetComboBox::update()
|
|||||||
bool is_enabled = true;
|
bool is_enabled = true;
|
||||||
// check this value just for printer presets, when physical printer is selected
|
// check this value just for printer presets, when physical printer is selected
|
||||||
if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection())
|
if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection())
|
||||||
is_enabled = m_enable_all ? true : preset.printer_technology() == proper_pt;//m_preset_bundle->physical_printers.get_selected_printer_technology();
|
is_enabled = m_enable_all ? true : preset.printer_technology() == proper_pt;
|
||||||
|
|
||||||
std::string bitmap_key = "tab";
|
std::string bitmap_key = "tab";
|
||||||
std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||||
@ -1017,8 +1028,49 @@ void TabPresetComboBox::update_dirty()
|
|||||||
|
|
||||||
void TabPresetComboBox::update_physical_printers( const std::string& preset_name)
|
void TabPresetComboBox::update_physical_printers( const std::string& preset_name)
|
||||||
{
|
{
|
||||||
if (m_type == Preset::TYPE_PRINTER && update_ph_printers)
|
if (m_type != Preset::TYPE_PRINTER || !m_allow_to_update_physical_printers)
|
||||||
update_ph_printers(preset_name);
|
return;
|
||||||
|
|
||||||
|
m_allow_to_update_physical_printers = false;
|
||||||
|
|
||||||
|
PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers;
|
||||||
|
if (!physical_printers.has_selection())
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string printer_preset_name = physical_printers.get_selected_printer_preset_name();
|
||||||
|
|
||||||
|
if (Preset::remove_suffix_modified(preset_name) == printer_preset_name) {
|
||||||
|
if (!this->is_selected_physical_printer())
|
||||||
|
physical_printers.unselect_printer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ChangePresetForPhysicalPrinterDialog dlg(Preset::remove_suffix_modified(preset_name));
|
||||||
|
if(dlg.ShowModal() == wxID_OK)
|
||||||
|
{
|
||||||
|
if (dlg.m_selection == ChangePresetForPhysicalPrinterDialog::Switch)
|
||||||
|
// unselect physical printer, if it was selected
|
||||||
|
m_preset_bundle->physical_printers.unselect_printer();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PhysicalPrinter printer = physical_printers.get_selected_printer();
|
||||||
|
|
||||||
|
if (dlg.m_selection == ChangePresetForPhysicalPrinterDialog::ChangePreset)
|
||||||
|
printer.delete_preset(printer_preset_name);
|
||||||
|
|
||||||
|
if (printer.add_preset(preset_name))
|
||||||
|
physical_printers.save_printer(printer);
|
||||||
|
else {
|
||||||
|
wxMessageDialog dialog(nullptr, _L("This preset is already exist for this physical printer. Please, select another one."), _L("Information"), wxICON_INFORMATION | wxOK);
|
||||||
|
dialog.ShowModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
physical_printers.select_printer_by_name(printer.get_full_name(preset_name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wxGetApp().get_tab(Preset::TYPE_PRINTER)->select_preset(printer_preset_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1123,7 +1175,6 @@ void PresetForPrinter::msw_rescale()
|
|||||||
// PhysicalPrinterDialog
|
// PhysicalPrinterDialog
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name)
|
PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name)
|
||||||
: DPIDialog(NULL, wxID_ANY, _L("Physical Printer"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
: DPIDialog(NULL, wxID_ANY, _L("Physical Printer"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||||
{
|
{
|
||||||
@ -1427,9 +1478,6 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
|
|||||||
|
|
||||||
if (dialog.ShowModal() == wxID_NO)
|
if (dialog.ShowModal() == wxID_NO)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Remove the printer from the list.
|
|
||||||
printers.delete_printer(into_u8(printer_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::string> repeat_presets;
|
std::set<std::string> repeat_presets;
|
||||||
@ -1438,8 +1486,6 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
|
|||||||
if (!m_printer.add_preset(preset->get_preset_name()))
|
if (!m_printer.add_preset(preset->get_preset_name()))
|
||||||
repeat_presets.emplace(preset->get_preset_name());
|
repeat_presets.emplace(preset->get_preset_name());
|
||||||
}
|
}
|
||||||
// update preset_names in printer config
|
|
||||||
m_printer.update_preset_names_in_config();
|
|
||||||
|
|
||||||
if (!repeat_presets.empty())
|
if (!repeat_presets.empty())
|
||||||
{
|
{
|
||||||
@ -1467,16 +1513,10 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
|
|||||||
// save new physical printer
|
// save new physical printer
|
||||||
printers.save_printer(m_printer, renamed_from);
|
printers.save_printer(m_printer, renamed_from);
|
||||||
|
|
||||||
// update selection on the tab only when it was changed
|
printers.select_printer(m_printer);
|
||||||
/*
|
|
||||||
if (m_printer.get_preset_name() != wxGetApp().preset_bundle->printers.get_selected_preset_name()) {
|
// refresh preset list on Printer Settings Tab
|
||||||
Tab* tab = wxGetApp().get_tab(Preset::TYPE_PRINTER);
|
wxGetApp().get_tab(Preset::TYPE_PRINTER)->update_preset_choice();
|
||||||
if (tab) {
|
|
||||||
wxString preset_name = m_printer_presets->GetString(m_printer_presets->GetSelection());
|
|
||||||
tab->select_preset(into_u8(preset_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
@ -1520,4 +1560,74 @@ void PhysicalPrinterDialog::DeletePreset(PresetForPrinter* preset_for_printer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
||||||
|
// ChangePresetForPhysicalPrinterDialog
|
||||||
|
//-----------------------------------------------
|
||||||
|
|
||||||
|
ChangePresetForPhysicalPrinterDialog::ChangePresetForPhysicalPrinterDialog(const std::string& preset_name)
|
||||||
|
: DPIDialog(nullptr, wxID_ANY, _L("Warning"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING/* | wxRESIZE_BORDER*/)
|
||||||
|
{
|
||||||
|
SetFont(wxGetApp().normal_font());
|
||||||
|
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||||
|
|
||||||
|
PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers;
|
||||||
|
std::string printer_name = printers.get_selected_printer_name();
|
||||||
|
std::string old_preset_name = printers.get_selected_printer_preset_name();
|
||||||
|
|
||||||
|
wxString msg_text = from_u8((boost::format(_u8L("You have selected physical printer \"%1%\"\n"
|
||||||
|
"with related printer preset \"%2%\"")) %
|
||||||
|
printer_name % old_preset_name).str());
|
||||||
|
wxStaticText* label_top = new wxStaticText(this, wxID_ANY, msg_text);
|
||||||
|
label_top->SetFont(wxGetApp().bold_font());
|
||||||
|
|
||||||
|
wxString choices[] = { from_u8((boost::format(_u8L("Just switch to \"%1%\"")) % preset_name).str()),
|
||||||
|
from_u8((boost::format(_u8L("Change \"%1%\" to \"%2%\" for this physical printer")) % old_preset_name % preset_name).str()),
|
||||||
|
from_u8((boost::format(_u8L("Add \"%1%\" as a next preset for the the physical printer")) % preset_name).str()) };
|
||||||
|
|
||||||
|
wxRadioBox* selection_type_box = new wxRadioBox(this, wxID_ANY, _L("What would you like to do?"), wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices,
|
||||||
|
3, wxRA_SPECIFY_ROWS);
|
||||||
|
selection_type_box->SetFont(wxGetApp().normal_font());
|
||||||
|
selection_type_box->SetSelection(0);
|
||||||
|
|
||||||
|
selection_type_box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) {
|
||||||
|
int selection = e.GetSelection();
|
||||||
|
m_selection = (SelectionType)selection;
|
||||||
|
});
|
||||||
|
|
||||||
|
auto radio_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
radio_sizer->Add(selection_type_box, 1, wxALIGN_CENTER_VERTICAL);
|
||||||
|
|
||||||
|
wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
|
||||||
|
wxButton* btnOK = static_cast<wxButton*>(this->FindWindowById(wxID_OK, this));
|
||||||
|
btnOK->Bind(wxEVT_BUTTON, &ChangePresetForPhysicalPrinterDialog::OnOK, this);
|
||||||
|
|
||||||
|
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
|
||||||
|
topSizer->Add(label_top, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W);
|
||||||
|
topSizer->Add(radio_sizer, 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W);
|
||||||
|
topSizer->Add(btns, 0, wxEXPAND | wxALL, BORDER_W);
|
||||||
|
|
||||||
|
SetSizer(topSizer);
|
||||||
|
topSizer->SetSizeHints(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangePresetForPhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||||
|
{
|
||||||
|
const int& em = em_unit();
|
||||||
|
|
||||||
|
msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL });
|
||||||
|
|
||||||
|
const wxSize& size = wxSize(45 * em, 35 * em);
|
||||||
|
SetMinSize(size);
|
||||||
|
|
||||||
|
Fit();
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangePresetForPhysicalPrinterDialog::OnOK(wxEvent& event)
|
||||||
|
{
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}} // namespace Slic3r::GUI
|
}} // namespace Slic3r::GUI
|
||||||
|
@ -166,7 +166,7 @@ class TabPresetComboBox : public PresetComboBox
|
|||||||
bool show_incompatible {false};
|
bool show_incompatible {false};
|
||||||
bool m_enable_all {false};
|
bool m_enable_all {false};
|
||||||
|
|
||||||
std::function<void(std::string)> update_ph_printers { nullptr };
|
bool m_allow_to_update_physical_printers {false};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TabPresetComboBox(wxWindow *parent, Preset::Type preset_type);
|
TabPresetComboBox(wxWindow *parent, Preset::Type preset_type);
|
||||||
@ -174,8 +174,8 @@ public:
|
|||||||
void set_show_incompatible_presets(bool show_incompatible_presets) {
|
void set_show_incompatible_presets(bool show_incompatible_presets) {
|
||||||
show_incompatible = show_incompatible_presets;
|
show_incompatible = show_incompatible_presets;
|
||||||
}
|
}
|
||||||
void set_update_physical_printers_function(std::function<void(std::string)> update_fn) {
|
void allow_to_update_physical_printers() {
|
||||||
update_ph_printers = update_fn;
|
m_allow_to_update_physical_printers = m_type == Preset::TYPE_PRINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
@ -263,6 +263,32 @@ protected:
|
|||||||
void on_sys_color_changed() override {};
|
void on_sys_color_changed() override {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------
|
||||||
|
// ChangePresetForPhysicalPrinterDialog
|
||||||
|
//------------------------------------------------
|
||||||
|
|
||||||
|
class ChangePresetForPhysicalPrinterDialog : public DPIDialog
|
||||||
|
{
|
||||||
|
void OnOK(wxEvent& event);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum SelectionType
|
||||||
|
{
|
||||||
|
Switch,
|
||||||
|
ChangePreset,
|
||||||
|
AddPreset
|
||||||
|
} m_selection {Switch};
|
||||||
|
|
||||||
|
ChangePresetForPhysicalPrinterDialog(const std::string& preset_name);
|
||||||
|
~ChangePresetForPhysicalPrinterDialog() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||||
|
void on_sys_color_changed() override {};
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace GUI
|
} // namespace GUI
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
@ -164,17 +164,14 @@ void Tab::create_preset_tab()
|
|||||||
m_presets_choice->set_selection_changed_function([this](int selection) {
|
m_presets_choice->set_selection_changed_function([this](int selection) {
|
||||||
if (!m_presets_choice->selection_is_changed_according_to_physical_printers())
|
if (!m_presets_choice->selection_is_changed_according_to_physical_printers())
|
||||||
{
|
{
|
||||||
// for the printer presets set callback for the updating of the physical printers
|
// For the printer presets allow to update a physical printer if it is needed.
|
||||||
|
// After call of the update_physical_printers() this possibility will be disabled again to avoid a case,
|
||||||
|
// when select_preset is called from the others than this place
|
||||||
if (m_type == Preset::TYPE_PRINTER)
|
if (m_type == Preset::TYPE_PRINTER)
|
||||||
m_presets_choice->set_update_physical_printers_function([this](std::string preset_name) { update_physical_printers(preset_name);});
|
m_presets_choice->allow_to_update_physical_printers();
|
||||||
|
|
||||||
// select preset
|
// select preset
|
||||||
select_preset(m_presets_choice->GetString(selection).ToUTF8().data());
|
select_preset(m_presets_choice->GetString(selection).ToUTF8().data());
|
||||||
|
|
||||||
// Disable callback for the updating of the physical printers to avoid a case,
|
|
||||||
// when select_preset is called from the others than this place
|
|
||||||
if (m_type == Preset::TYPE_PRINTER)
|
|
||||||
m_presets_choice->set_update_physical_printers_function(nullptr);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -772,36 +769,6 @@ void Tab::update_tab_ui()
|
|||||||
m_presets_choice->update();
|
m_presets_choice->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::update_physical_printers(std::string preset_name)
|
|
||||||
{
|
|
||||||
PhysicalPrinterCollection& physical_printers = wxGetApp().preset_bundle->physical_printers;
|
|
||||||
if (physical_printers.has_selection() &&
|
|
||||||
Preset::remove_suffix_modified(preset_name) != physical_printers.get_selected_printer_preset_name())
|
|
||||||
{
|
|
||||||
std::string printer_name = physical_printers.get_selected_full_printer_name();
|
|
||||||
wxString msg_text = from_u8((boost::format(_u8L("You have selected physical printer \"%1%\".")) % printer_name).str());
|
|
||||||
msg_text += "\n\n" + _L("Would you like to change related preset for this printer?") + "\n\n" +
|
|
||||||
_L("Select YES if you want to change related preset for this printer \n"
|
|
||||||
"or NO to switch to the another preset (logical printer).");
|
|
||||||
wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO);
|
|
||||||
|
|
||||||
if (dialog.ShowModal() == wxID_YES) {
|
|
||||||
preset_name = Preset::remove_suffix_modified(preset_name);
|
|
||||||
Preset* preset = m_presets->find_preset(preset_name);
|
|
||||||
assert(preset);
|
|
||||||
Preset& edited_preset = m_presets->get_edited_preset();
|
|
||||||
if (preset->name == edited_preset.name)
|
|
||||||
preset = &edited_preset;
|
|
||||||
physical_printers.get_selected_printer().update_from_preset(*preset);
|
|
||||||
physical_printers.select_printer_by_name(physical_printers.get_selected_printer().get_full_name(preset_name));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// unselect physical printer, if it was selected
|
|
||||||
m_preset_bundle->physical_printers.unselect_printer();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load a provied DynamicConfig into the tab, modifying the active preset.
|
// Load a provied DynamicConfig into the tab, modifying the active preset.
|
||||||
// This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view.
|
// This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view.
|
||||||
void Tab::load_config(const DynamicPrintConfig& config)
|
void Tab::load_config(const DynamicPrintConfig& config)
|
||||||
@ -2822,7 +2789,8 @@ void Tab::load_current_preset()
|
|||||||
{
|
{
|
||||||
const Preset& preset = m_presets->get_edited_preset();
|
const Preset& preset = m_presets->get_edited_preset();
|
||||||
|
|
||||||
(preset.is_default || preset.is_system) ? m_btn_delete_preset->Disable() : m_btn_delete_preset->Enable(true);
|
// (preset.is_default || preset.is_system) ? m_btn_delete_preset->Disable() : m_btn_delete_preset->Enable(true);
|
||||||
|
update_delete_preset_btn();
|
||||||
|
|
||||||
update();
|
update();
|
||||||
if (m_type == Slic3r::Preset::TYPE_PRINTER) {
|
if (m_type == Slic3r::Preset::TYPE_PRINTER) {
|
||||||
@ -2959,9 +2927,23 @@ void Tab::update_page_tree_visibility()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tab::update_delete_preset_btn()
|
||||||
|
{
|
||||||
|
if (m_type == Preset::TYPE_PRINTER && m_presets_choice->is_selected_physical_printer() &&
|
||||||
|
m_preset_bundle->physical_printers.has_selection()) {
|
||||||
|
// we can't delete last preset from the physical printer
|
||||||
|
m_btn_delete_preset->Enable(m_preset_bundle->physical_printers.get_selected_printer().preset_names.size() > 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const Preset& preset = m_presets->get_edited_preset();
|
||||||
|
m_btn_delete_preset->Enable(!preset.is_default && !preset.is_system);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Tab::update_preset_choice()
|
void Tab::update_preset_choice()
|
||||||
{
|
{
|
||||||
m_presets_choice->update();
|
m_presets_choice->update();
|
||||||
|
update_delete_preset_btn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by the UI combo box when the user switches profiles, and also to delete the current profile.
|
// Called by the UI combo box when the user switches profiles, and also to delete the current profile.
|
||||||
@ -2971,16 +2953,55 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/,
|
|||||||
{
|
{
|
||||||
if (preset_name.empty()) {
|
if (preset_name.empty()) {
|
||||||
if (delete_current) {
|
if (delete_current) {
|
||||||
// Find an alternate preset to be selected after the current preset is deleted.
|
PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers;
|
||||||
const std::deque<Preset> &presets = this->m_presets->get_presets();
|
if (m_presets_choice->is_selected_physical_printer()) {
|
||||||
size_t idx_current = this->m_presets->get_idx_selected();
|
PhysicalPrinter& printer = physical_printers.get_selected_printer();
|
||||||
// Find the next visible preset.
|
|
||||||
size_t idx_new = idx_current + 1;
|
if (printer.preset_names.size()==1) {
|
||||||
if (idx_new < presets.size())
|
wxMessageDialog dialog(nullptr, _L("It's a last for this physical printer. We can't delete it"), _L("Information"), wxICON_INFORMATION | wxOK);
|
||||||
for (; idx_new < presets.size() && ! presets[idx_new].is_visible; ++ idx_new) ;
|
dialog.ShowModal();
|
||||||
if (idx_new == presets.size())
|
}
|
||||||
for (idx_new = idx_current - 1; idx_new > 0 && ! presets[idx_new].is_visible; -- idx_new);
|
else {
|
||||||
preset_name = presets[idx_new].name;
|
// just delete this preset from the current physical printer
|
||||||
|
printer.delete_preset(m_presets->get_edited_preset().name);
|
||||||
|
// select first from the possible presets for this printer
|
||||||
|
physical_printers.select_printer(printer);
|
||||||
|
|
||||||
|
preset_name = physical_printers.get_selected_printer_preset_name();
|
||||||
|
// revert delete_current value to avoid deleting of the new selected preset
|
||||||
|
delete_current = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Check preset for delete in physical printers
|
||||||
|
// Ask a customer about next action , if there is a printer with just one preset and this preset is equal to delete
|
||||||
|
if (m_type == Preset::TYPE_PRINTER && !physical_printers.empty() )
|
||||||
|
{
|
||||||
|
// try to delete selected preset from the all printers it has
|
||||||
|
if (!physical_printers.delete_preset_from_printers(m_presets->get_edited_preset().name))
|
||||||
|
{
|
||||||
|
wxMessageDialog dialog(nullptr, _L("There is/are a physical printer(s), which has/have one and only this printer preset.\n"
|
||||||
|
"This/Those printer(s) will be deletede after deleting of the selected preset.\n"
|
||||||
|
"Are you sure you want to delete the selected preset?"), _L("Warning"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
|
||||||
|
if (dialog.ShowModal() == wxID_NO)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// delete selected preset from printers and printer, if it's needed
|
||||||
|
physical_printers.delete_preset_from_printers(m_presets->get_edited_preset().name, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find an alternate preset to be selected after the current preset is deleted.
|
||||||
|
const std::deque<Preset> &presets = this->m_presets->get_presets();
|
||||||
|
size_t idx_current = this->m_presets->get_idx_selected();
|
||||||
|
// Find the next visible preset.
|
||||||
|
size_t idx_new = idx_current + 1;
|
||||||
|
if (idx_new < presets.size())
|
||||||
|
for (; idx_new < presets.size() && ! presets[idx_new].is_visible; ++ idx_new) ;
|
||||||
|
if (idx_new == presets.size())
|
||||||
|
for (idx_new = idx_current - 1; idx_new > 0 && ! presets[idx_new].is_visible; -- idx_new);
|
||||||
|
preset_name = presets[idx_new].name;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// If no name is provided, select the "-- default --" preset.
|
// If no name is provided, select the "-- default --" preset.
|
||||||
preset_name = m_presets->default_preset().name;
|
preset_name = m_presets->default_preset().name;
|
||||||
@ -3075,23 +3096,16 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (canceled) {
|
if (canceled) {
|
||||||
update_tab_ui();
|
if (m_type == Preset::TYPE_PRINTER) {
|
||||||
/*
|
if (!last_selected_ph_printer_name.empty() &&
|
||||||
// unselect physical printer selection to the correct synchronization of the printer presets between Tab and Plater
|
m_presets->get_edited_preset().name == PhysicalPrinter::get_preset_name(last_selected_ph_printer_name)) {
|
||||||
if (m_type == Preset::TYPE_PRINTER)
|
// If preset selection was canceled and previously was selected physical printer, we should select it back
|
||||||
m_preset_bundle->physical_printers.unselect_printer();
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// Check if preset really was changed.
|
|
||||||
// If preset selection was canceled and previously was selected physical printer, we should select it back
|
|
||||||
if (m_type == Preset::TYPE_PRINTER && !last_selected_ph_printer_name.empty()) {
|
|
||||||
if (m_presets->get_edited_preset().name == PhysicalPrinter::get_preset_name(last_selected_ph_printer_name)) {
|
|
||||||
m_preset_bundle->physical_printers.select_printer_by_name(last_selected_ph_printer_name);
|
m_preset_bundle->physical_printers.select_printer_by_name(last_selected_ph_printer_name);
|
||||||
m_presets_choice->update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_tab_ui();
|
||||||
|
|
||||||
// Trigger the on_presets_changed event so that we also restore the previous value in the plater selector,
|
// Trigger the on_presets_changed event so that we also restore the previous value in the plater selector,
|
||||||
// if this action was initiated from the plater.
|
// if this action was initiated from the plater.
|
||||||
on_presets_changed();
|
on_presets_changed();
|
||||||
@ -3334,6 +3348,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach)
|
|||||||
// If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible.
|
// If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible.
|
||||||
m_preset_bundle->update_compatible(PresetSelectCompatibleType::Never);
|
m_preset_bundle->update_compatible(PresetSelectCompatibleType::Never);
|
||||||
//update physical printer's related printer preset if it's needed
|
//update physical printer's related printer preset if it's needed
|
||||||
|
m_presets_choice->allow_to_update_physical_printers();
|
||||||
m_presets_choice->update_physical_printers(name);
|
m_presets_choice->update_physical_printers(name);
|
||||||
// Add the new item into the UI component, remove dirty flags and activate the saved item.
|
// Add the new item into the UI component, remove dirty flags and activate the saved item.
|
||||||
update_tab_ui();
|
update_tab_ui();
|
||||||
@ -3389,7 +3404,9 @@ void Tab::delete_preset()
|
|||||||
// Don't let the user delete the ' - default - ' configuration.
|
// Don't let the user delete the ' - default - ' configuration.
|
||||||
std::string action = current_preset.is_external ? _utf8(L("remove")) : _utf8(L("delete"));
|
std::string action = current_preset.is_external ? _utf8(L("remove")) : _utf8(L("delete"));
|
||||||
// TRN remove/delete
|
// TRN remove/delete
|
||||||
const wxString msg = from_u8((boost::format(_utf8(L("Are you sure you want to %1% the selected preset?"))) % action).str());
|
const wxString msg = m_presets_choice->is_selected_physical_printer() ?
|
||||||
|
from_u8((boost::format(_utf8(L("Are you sure you want to delete \"%1%\" preset from the physical printer?"))) % current_preset.name).str()) :
|
||||||
|
from_u8((boost::format(_utf8(L("Are you sure you want to %1% the selected preset?"))) % action).str());
|
||||||
action = current_preset.is_external ? _utf8(L("Remove")) : _utf8(L("Delete"));
|
action = current_preset.is_external ? _utf8(L("Remove")) : _utf8(L("Delete"));
|
||||||
// TRN Remove/Delete
|
// TRN Remove/Delete
|
||||||
wxString title = from_u8((boost::format(_utf8(L("%1% Preset"))) % action).str()); //action + _(L(" Preset"));
|
wxString title = from_u8((boost::format(_utf8(L("%1% Preset"))) % action).str()); //action + _(L(" Preset"));
|
||||||
|
@ -275,6 +275,7 @@ public:
|
|||||||
void load_current_preset();
|
void load_current_preset();
|
||||||
void rebuild_page_tree();
|
void rebuild_page_tree();
|
||||||
void update_page_tree_visibility();
|
void update_page_tree_visibility();
|
||||||
|
void update_delete_preset_btn();
|
||||||
void update_preset_choice();
|
void update_preset_choice();
|
||||||
// Select a new preset, possibly delete the current one.
|
// Select a new preset, possibly delete the current one.
|
||||||
void select_preset(std::string preset_name = "", bool delete_current = false, const std::string& last_selected_ph_printer_name = "");
|
void select_preset(std::string preset_name = "", bool delete_current = false, const std::string& last_selected_ph_printer_name = "");
|
||||||
@ -307,7 +308,6 @@ public:
|
|||||||
void load_initial_data();
|
void load_initial_data();
|
||||||
void update_dirty();
|
void update_dirty();
|
||||||
void update_tab_ui();
|
void update_tab_ui();
|
||||||
void update_physical_printers(std::string preset_name);
|
|
||||||
void load_config(const DynamicPrintConfig& config);
|
void load_config(const DynamicPrintConfig& config);
|
||||||
virtual void reload_config();
|
virtual void reload_config();
|
||||||
void update_mode();
|
void update_mode();
|
||||||
|
Loading…
Reference in New Issue
Block a user