mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-09 07:56:24 -06:00
FIX: fix save preset problem
Change-Id: I0e6f53b0386e8f04babe2d6c7d18f515c37caae3
This commit is contained in:
parent
7910e681e4
commit
a98b781425
5 changed files with 102 additions and 25 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "MsgDialog.hpp"
|
#include "MsgDialog.hpp"
|
||||||
#include "../../libslic3r/Calib.hpp"
|
#include "../../libslic3r/Calib.hpp"
|
||||||
#include "Tabbook.hpp"
|
#include "Tabbook.hpp"
|
||||||
|
#include "MainFrame.hpp"
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
@ -1864,38 +1865,70 @@ int CalibrationWizard::get_bed_temp(DynamicPrintConfig* config)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CalibrationWizard::save_presets(Preset* preset, const std::string& config_key, ConfigOption* config_value, const std::string& name)
|
bool CalibrationWizard::save_presets(Preset *preset, const std::string &config_key, ConfigOption *config_value, const std::string &new_preset_name, std::string& message)
|
||||||
{
|
{
|
||||||
auto filament_presets = &wxGetApp().preset_bundle->filaments;
|
PresetCollection* filament_presets = &wxGetApp().preset_bundle->filaments;
|
||||||
DynamicPrintConfig* filament_config = &preset->config;
|
|
||||||
|
|
||||||
bool save_to_project = false;
|
std::string new_name = filament_presets->get_preset_name_by_alias(new_preset_name);
|
||||||
|
std::string curr_preset_name = preset->name;
|
||||||
|
preset = filament_presets->find_preset(curr_preset_name);
|
||||||
|
Preset temp_preset = *preset;
|
||||||
|
|
||||||
|
bool exist_preset = false;
|
||||||
|
// If name is current, get the editing preset
|
||||||
|
Preset *new_preset = filament_presets->find_preset(new_name);
|
||||||
|
if (new_preset) {
|
||||||
|
if (new_preset->is_system) {
|
||||||
|
message = "The name cannot be the same as the system preset name.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_preset != preset) {
|
||||||
|
message = "The name is the same as another existing preset name";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (new_preset != &filament_presets->get_edited_preset())
|
||||||
|
new_preset = &temp_preset;
|
||||||
|
exist_preset = true;
|
||||||
|
} else {
|
||||||
|
new_preset = &temp_preset;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_preset->config.set_key_value(config_key, config_value);
|
||||||
|
|
||||||
filament_config->set_key_value(config_key, config_value);
|
|
||||||
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
|
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
|
||||||
filament_presets->save_current_preset(name, false, save_to_project, preset);
|
filament_presets->save_current_preset(new_name, false, false, new_preset);
|
||||||
|
|
||||||
Preset* new_preset = filament_presets->find_preset(name, false, true);
|
// BBS create new settings
|
||||||
|
new_preset = filament_presets->find_preset(new_name, false, true);
|
||||||
|
// Preset* preset = &m_presets.preset(it - m_presets.begin(), true);
|
||||||
if (!new_preset) {
|
if (!new_preset) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "create new preset failed";
|
BOOST_LOG_TRIVIAL(info) << "create new preset failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_preset->sync_info = "create";
|
// set sync_info for sync service
|
||||||
if (wxGetApp().is_user_login())
|
if (exist_preset) {
|
||||||
new_preset->user_id = wxGetApp().getAgent()->get_user_id();
|
new_preset->sync_info = "update";
|
||||||
BOOST_LOG_TRIVIAL(info) << "sync_preset: create preset = " << new_preset->name;
|
BOOST_LOG_TRIVIAL(info) << "sync_preset: update preset = " << new_preset->name;
|
||||||
|
} else {
|
||||||
|
new_preset->sync_info = "create";
|
||||||
|
if (wxGetApp().is_user_login()) new_preset->user_id = wxGetApp().getAgent()->get_user_id();
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "sync_preset: create preset = " << new_preset->name;
|
||||||
|
}
|
||||||
new_preset->save_info();
|
new_preset->save_info();
|
||||||
|
|
||||||
// Mark the print & filament enabled if they are compatible with the currently selected preset.
|
// Mark the print & filament enabled if they are compatible with the currently selected preset.
|
||||||
// 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.
|
||||||
wxGetApp().preset_bundle->update_compatible(PresetSelectCompatibleType::Never);
|
wxGetApp().preset_bundle->update_compatible(PresetSelectCompatibleType::Never);
|
||||||
|
|
||||||
// update current comboBox selected preset
|
// BBS if create a new prset name, preset changed from preset name to new preset name
|
||||||
std::string curr_preset_name = filament_presets->get_edited_preset().name;
|
if (!exist_preset) {
|
||||||
wxGetApp().plater()->sidebar().update_presets_from_to(Preset::TYPE_FILAMENT, curr_preset_name, new_preset->name);
|
wxGetApp().plater()->sidebar().update_presets_from_to(Preset::Type::TYPE_FILAMENT, curr_preset_name, new_preset->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxGetApp().mainframe->update_filament_tab_ui();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3326,8 +3359,14 @@ bool FlowRateWizard::save_calibration_result()
|
||||||
if (it != m_high_end_save_names.end() && !it->second.empty()) {
|
if (it != m_high_end_save_names.end() && !it->second.empty()) {
|
||||||
if (m_filament_presets.find(m_calib_results[i].tray_id) == m_filament_presets.end())
|
if (m_filament_presets.find(m_calib_results[i].tray_id) == m_filament_presets.end())
|
||||||
return false;
|
return false;
|
||||||
save_presets(m_filament_presets.at(m_calib_results[i].tray_id), "filament_flow_ratio", new ConfigOptionFloats{ m_calib_results[i].flow_ratio }, it->second);
|
std::string message;
|
||||||
return true;
|
if(save_presets(m_filament_presets.at(m_calib_results[i].tray_id), "filament_flow_ratio", new ConfigOptionFloats{ m_calib_results[i].flow_ratio }, it->second, message))
|
||||||
|
return true;
|
||||||
|
else {
|
||||||
|
MessageDialog msg_dlg(nullptr, _L(message), wxEmptyString, wxICON_WARNING | wxOK);
|
||||||
|
msg_dlg.ShowModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it != m_high_end_save_names.end() && it->second.empty()) {
|
if (it != m_high_end_save_names.end() && it->second.empty()) {
|
||||||
|
@ -3369,7 +3408,12 @@ bool FlowRateWizard::save_calibration_result()
|
||||||
msg_dlg.ShowModal();
|
msg_dlg.ShowModal();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
save_presets(m_filament_presets.begin()->second, "filament_flow_ratio", new ConfigOptionFloats{ result_value }, m_save_name);
|
std::string message;
|
||||||
|
if (!save_presets(m_filament_presets.begin()->second, "filament_flow_ratio", new ConfigOptionFloats{ result_value }, m_save_name, message)) {
|
||||||
|
MessageDialog msg_dlg(nullptr, _L(message), wxEmptyString, wxICON_WARNING | wxOK);
|
||||||
|
msg_dlg.ShowModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
reset_reuse_panels();
|
reset_reuse_panels();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3656,7 +3700,12 @@ bool MaxVolumetricSpeedWizard::save_calibration_result()
|
||||||
msg_dlg.ShowModal();
|
msg_dlg.ShowModal();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
save_presets(m_filament_presets.begin()->second, "filament_max_volumetric_speed", new ConfigOptionFloats{ max_volumetric_speed }, m_save_name);
|
std::string message;
|
||||||
|
if (!save_presets(m_filament_presets.begin()->second, "filament_max_volumetric_speed", new ConfigOptionFloats{ max_volumetric_speed }, m_save_name, message)) {
|
||||||
|
MessageDialog msg_dlg(nullptr, _L(message), wxEmptyString, wxICON_WARNING | wxOK);
|
||||||
|
msg_dlg.ShowModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3892,7 +3941,12 @@ bool TemperatureWizard::save_calibration_result()
|
||||||
msg_dlg.ShowModal();
|
msg_dlg.ShowModal();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
save_presets(m_filament_presets.begin()->second, "nozzle_temperature", new ConfigOptionInts(1, temp), m_save_name);
|
std::string message;
|
||||||
|
if (!save_presets(m_filament_presets.begin()->second, "nozzle_temperature", new ConfigOptionInts(1, temp), m_save_name, message)) {
|
||||||
|
MessageDialog msg_dlg(nullptr, _L(message), wxEmptyString, wxICON_WARNING | wxOK);
|
||||||
|
msg_dlg.ShowModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4157,7 +4211,12 @@ bool RetractionWizard::save_calibration_result()
|
||||||
msg_dlg.ShowModal();
|
msg_dlg.ShowModal();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
save_presets(m_filament_presets.begin()->second, "retraction_length", new ConfigOptionFloats{ length }, m_save_name);
|
std::string message;
|
||||||
|
if (!save_presets(m_filament_presets.begin()->second, "retraction_length", new ConfigOptionFloats{ length }, m_save_name, message)) {
|
||||||
|
MessageDialog msg_dlg(nullptr, _L(message), wxEmptyString, wxICON_WARNING | wxOK);
|
||||||
|
msg_dlg.ShowModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ protected:
|
||||||
void reset_printing_values();
|
void reset_printing_values();
|
||||||
|
|
||||||
// save
|
// save
|
||||||
bool save_presets(Preset* preset, const std::string& config_key, ConfigOption* config_value, const std::string& name);
|
bool save_presets(Preset* preset, const std::string& config_key, ConfigOption* config_value, const std::string& name, std::string& message);
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
void on_select_nozzle(wxCommandEvent& evt);
|
void on_select_nozzle(wxCommandEvent& evt);
|
||||||
|
|
|
@ -857,6 +857,13 @@ void MainFrame::shutdown()
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "MainFrame::shutdown exit";
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "MainFrame::shutdown exit";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainFrame::update_filament_tab_ui()
|
||||||
|
{
|
||||||
|
wxGetApp().get_tab(Preset::Type::TYPE_FILAMENT)->reload_config();
|
||||||
|
wxGetApp().get_tab(Preset::Type::TYPE_FILAMENT)->update_dirty();
|
||||||
|
wxGetApp().get_tab(Preset::Type::TYPE_FILAMENT)->update_tab_ui();
|
||||||
|
}
|
||||||
|
|
||||||
void MainFrame::update_title()
|
void MainFrame::update_title()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -248,6 +248,9 @@ public:
|
||||||
// BBS
|
// BBS
|
||||||
BBLTopbar* topbar() { return m_topbar; }
|
BBLTopbar* topbar() { return m_topbar; }
|
||||||
|
|
||||||
|
// for cali to update tab when save new preset
|
||||||
|
void update_filament_tab_ui();
|
||||||
|
|
||||||
void update_title();
|
void update_title();
|
||||||
void set_max_recent_count(int max);
|
void set_max_recent_count(int max);
|
||||||
|
|
||||||
|
|
|
@ -1515,10 +1515,18 @@ void GUI::CalibrateFilamentComboBox::update()
|
||||||
|
|
||||||
void GUI::CalibrateFilamentComboBox::OnSelect(wxCommandEvent &evt)
|
void GUI::CalibrateFilamentComboBox::OnSelect(wxCommandEvent &evt)
|
||||||
{
|
{
|
||||||
|
auto marker = reinterpret_cast<Marker>(this->GetClientData(evt.GetSelection()));
|
||||||
|
if (marker >= LABEL_ITEM_DISABLED && marker < LABEL_ITEM_MAX) {
|
||||||
|
this->SetSelection(evt.GetSelection() + 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_is_compatible = true;
|
m_is_compatible = true;
|
||||||
static_cast<FilamentComboBox*>(m_parent)->Enable(true);
|
static_cast<FilamentComboBox*>(m_parent)->Enable(true);
|
||||||
std::string preset_name = m_collection->get_preset_name_by_alias(evt.GetString().ToUTF8().data());
|
std::string selected_name = evt.GetString().ToUTF8().data();
|
||||||
m_selected_preset = m_collection->find_preset(preset_name);
|
selected_name = Preset::remove_suffix_modified(selected_name);
|
||||||
|
m_selected_preset = m_collection->find_preset(selected_name);
|
||||||
|
std::string preset_name = m_collection->get_preset_name_by_alias(selected_name);
|
||||||
|
m_selected_preset = m_collection->find_preset(preset_name);
|
||||||
SimpleEvent e(EVT_CALIBRATION_TRAY_SELECTION_CHANGED);
|
SimpleEvent e(EVT_CALIBRATION_TRAY_SELECTION_CHANGED);
|
||||||
auto cali_tab = wxGetApp().mainframe->m_calibration->get_tabpanel();
|
auto cali_tab = wxGetApp().mainframe->m_calibration->get_tabpanel();
|
||||||
auto calibration_wizard = static_cast<CalibrationWizard*>(cali_tab->GetPage(cali_tab->GetSelection()));
|
auto calibration_wizard = static_cast<CalibrationWizard*>(cali_tab->GetPage(cali_tab->GetSelection()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue