Files
OrcaSlicer-bambulab/src/slic3r/GUI/GUI_ObjectSettings.cpp
T

286 lines
9.6 KiB
C++
Raw Normal View History

2018-11-09 18:39:07 +01:00
#include "GUI_ObjectSettings.hpp"
#include "GUI_ObjectList.hpp"
2021-03-15 10:04:45 +01:00
#include "GUI_Factories.hpp"
2018-11-09 18:39:07 +01:00
#include "OptionsGroup.hpp"
2020-05-26 17:42:57 +02:00
#include "GUI_App.hpp"
2018-11-09 18:39:07 +01:00
#include "wxExtensions.hpp"
2020-05-26 17:42:57 +02:00
#include "Plater.hpp"
#include "libslic3r/PresetBundle.hpp"
2018-11-26 14:41:58 +01:00
#include "libslic3r/Model.hpp"
2018-11-09 18:39:07 +01:00
#include <boost/algorithm/string.hpp>
2018-11-26 14:41:58 +01:00
#include "I18N.hpp"
#include "ConfigManipulation.hpp"
2018-11-26 14:41:58 +01:00
#include <wx/wupdlock.h>
2018-11-09 18:39:07 +01:00
namespace Slic3r
{
namespace GUI
{
OG_Settings::OG_Settings(wxWindow* parent, const bool staticbox) :
m_parent(parent)
{
wxString title = staticbox ? " " : ""; // temporary workaround - #ys_FIXME
m_og = std::make_shared<ConfigOptionsGroup>(parent, title);
}
bool OG_Settings::IsShown()
{
return m_og->sizer->IsEmpty() ? false : m_og->sizer->IsShown(size_t(0));
}
void OG_Settings::Show(const bool show)
{
m_og->Show(show);
}
void OG_Settings::Hide()
{
Show(false);
}
void OG_Settings::UpdateAndShow(const bool show)
{
Show(show);
// m_parent->Layout();
2018-11-09 18:39:07 +01:00
}
wxSizer* OG_Settings::get_sizer()
{
return m_og->sizer;
}
ObjectSettings::ObjectSettings(wxWindow* parent) :
OG_Settings(parent, true)
{
m_og->activate();
2018-11-09 18:39:07 +01:00
m_og->set_name(_(L("Additional Settings")));
m_settings_list_sizer = new wxBoxSizer(wxVERTICAL);
m_og->sizer->Add(m_settings_list_sizer, 1, wxEXPAND | wxLEFT, 5);
2019-04-13 23:46:52 +02:00
m_bmp_delete = ScalableBitmap(parent, "cross");
m_bmp_delete_focus = ScalableBitmap(parent, "cross_focus");
2018-11-09 18:39:07 +01:00
}
2019-07-11 23:46:23 +02:00
bool ObjectSettings::update_settings_list()
2018-11-09 18:39:07 +01:00
{
m_settings_list_sizer->Clear(true);
2019-07-11 23:46:23 +02:00
m_og_settings.resize(0);
2018-11-09 18:39:07 +01:00
auto objects_ctrl = wxGetApp().obj_list();
2019-05-28 16:38:04 +02:00
auto objects_model = wxGetApp().obj_list()->GetModel();
auto config = wxGetApp().obj_list()->config();
2018-11-09 18:39:07 +01:00
const auto item = objects_ctrl->GetSelection();
2019-07-11 23:46:23 +02:00
if (!item || !objects_model->IsSettingsItem(item) || !config || objects_ctrl->multiple_selection())
return false;
const bool is_object_settings = objects_model->GetItemType(objects_model->GetParent(item)) == itObject;
2021-03-15 10:04:45 +01:00
SettingsFactory::Bundle cat_options = SettingsFactory::get_bundle(&config->get(), is_object_settings);
2019-07-11 23:46:23 +02:00
if (!cat_options.empty())
{
std::vector<std::string> categories;
categories.reserve(cat_options.size());
2018-11-09 18:39:07 +01:00
auto extra_column = [config, this](wxWindow* parent, const Line& line)
{
auto opt_key = (line.get_options())[0].opt_id; //we assume that we have one option per line
auto btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete);
2019-05-10 17:10:12 +02:00
btn->SetToolTip(_(L("Remove parameter")));
btn->SetBitmapFocus(m_bmp_delete_focus.bmp());
btn->SetBitmapHover(m_bmp_delete_focus.bmp());
2018-11-09 18:39:07 +01:00
btn->Bind(wxEVT_BUTTON, [opt_key, config, this](wxEvent &event) {
wxGetApp().plater()->take_snapshot(from_u8((boost::format(_utf8(L("Delete Option %s"))) % opt_key).str()));
2018-11-09 18:39:07 +01:00
config->erase(opt_key);
wxGetApp().obj_list()->changed_object();
wxTheApp->CallAfter([this]() {
wxWindowUpdateLocker noUpdates(m_parent);
2018-11-09 18:39:07 +01:00
update_settings_list();
m_parent->Layout();
});
/* Check overriden options list after deleting.
* Some options couldn't be deleted because of another one.
* Like, we couldn't delete fill pattern, if fill density is set to 100%
*/
update_config_values(config);
2018-11-09 18:39:07 +01:00
});
return btn;
};
2019-07-11 23:46:23 +02:00
for (auto& cat : cat_options)
2018-11-09 18:39:07 +01:00
{
2019-07-11 23:46:23 +02:00
categories.push_back(cat.first);
2018-11-09 18:39:07 +01:00
2019-07-11 23:46:23 +02:00
auto optgroup = std::make_shared<ConfigOptionsGroup>(m_og->ctrl_parent(), _(cat.first), config, false, extra_column);
optgroup->label_width = 15;
optgroup->sidetext_width = 5;
2018-11-09 18:39:07 +01:00
optgroup->m_on_change = [this, config](const t_config_option_key& opt_id, const boost::any& value) {
this->update_config_values(config);
2019-07-11 23:46:23 +02:00
wxGetApp().obj_list()->changed_object(); };
2018-11-09 18:39:07 +01:00
2019-07-11 23:46:23 +02:00
// call back for rescaling of the extracolumn control
optgroup->rescale_extra_column_item = [this](wxWindow* win) {
auto *ctrl = dynamic_cast<ScalableButton*>(win);
if (ctrl == nullptr)
return;
ctrl->SetBitmap_(m_bmp_delete);
ctrl->SetBitmapFocus(m_bmp_delete_focus.bmp());
ctrl->SetBitmapHover(m_bmp_delete_focus.bmp());
2019-07-11 23:46:23 +02:00
};
const bool is_extruders_cat = cat.first == "Extruders";
for (auto& opt : cat.second)
{
Option option = optgroup->get_option(opt);
option.opt.width = 12;
if (is_extruders_cat)
option.opt.max = wxGetApp().extruders_edited_cnt();
optgroup->append_single_option_line(option);
2020-09-22 11:17:43 +02:00
}
optgroup->activate();
for (auto& opt : cat.second)
2019-07-22 13:38:53 +02:00
optgroup->get_field(opt)->m_on_change = [optgroup](const std::string& opt_id, const boost::any& value) {
// first of all take a snapshot and then change value in configuration
wxGetApp().plater()->take_snapshot(from_u8((boost::format(_utf8(L("Change Option %s"))) % opt_id).str()));
2019-07-22 13:38:53 +02:00
optgroup->on_change_OG(opt_id, value);
};
2019-07-11 23:46:23 +02:00
optgroup->reload_config();
m_settings_list_sizer->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 0);
m_og_settings.push_back(optgroup);
2018-11-09 18:39:07 +01:00
}
if (!categories.empty()) {
2019-07-11 23:46:23 +02:00
objects_model->UpdateSettingsDigest(item, categories);
update_config_values(config);
}
2019-07-11 23:46:23 +02:00
}
else
{
objects_ctrl->select_item(objects_model->Delete(item));
return false;
}
return true;
2018-11-09 18:39:07 +01:00
}
bool ObjectSettings::add_missed_options(ModelConfig* config_to, const DynamicPrintConfig& config_from)
{
bool is_added = false;
if (wxGetApp().plater()->printer_technology() == ptFFF)
{
if (config_to->has("fill_density") && !config_to->has("fill_pattern"))
{
if (config_from.option<ConfigOptionPercent>("fill_density")->value == 100) {
config_to->set_key_value("fill_pattern", config_from.option("fill_pattern")->clone());
is_added = true;
}
}
}
return is_added;
}
void ObjectSettings::update_config_values(ModelConfig* config)
{
const auto objects_model = wxGetApp().obj_list()->GetModel();
const auto item = wxGetApp().obj_list()->GetSelection();
const auto printer_technology = wxGetApp().plater()->printer_technology();
const bool is_object_settings = objects_model->GetItemType(objects_model->GetParent(item)) == itObject;
if (!item || !objects_model->IsSettingsItem(item) || !config)
return;
// update config values according to configuration hierarchy
DynamicPrintConfig main_config = printer_technology == ptFFF ?
wxGetApp().preset_bundle->prints.get_edited_preset().config :
wxGetApp().preset_bundle->sla_prints.get_edited_preset().config;
auto load_config = [this, config, &main_config]()
{
/* Additional check for overrided options.
* There is a case, when some options should to be added,
* to avoid check loop in the next configuration update
*/
bool is_added = add_missed_options(config, main_config);
// load checked values from main_config to config
config->apply_only(main_config, config->keys(), true);
// Initialize UI components with the config values.
for (auto og : m_og_settings)
og->reload_config();
// next config check
update_config_values(config);
if (is_added) {
wxTheApp->CallAfter([this]() {
wxWindowUpdateLocker noUpdates(m_parent);
update_settings_list();
m_parent->Layout();
});
}
};
2020-09-22 11:17:43 +02:00
auto toggle_field = [this](const t_config_option_key & opt_key, bool toggle, int opt_index)
{
Field* field = nullptr;
for (auto og : m_og_settings) {
field = og->get_fieldc(opt_key, opt_index);
if (field != nullptr)
2020-09-22 11:17:43 +02:00
break;
}
2020-09-22 11:17:43 +02:00
if (field)
field->toggle(toggle);
};
2020-09-22 11:17:43 +02:00
ConfigManipulation config_manipulation(load_config, toggle_field, nullptr, config);
if (!is_object_settings)
{
const int obj_idx = objects_model->GetObjectIdByItem(item);
assert(obj_idx >= 0);
main_config.apply(wxGetApp().model().objects[obj_idx]->config.get(), true);
printer_technology == ptFFF ? config_manipulation.update_print_fff_config(&main_config) :
config_manipulation.update_print_sla_config(&main_config) ;
}
main_config.apply(config->get(), true);
printer_technology == ptFFF ? config_manipulation.update_print_fff_config(&main_config) :
config_manipulation.update_print_sla_config(&main_config) ;
printer_technology == ptFFF ? config_manipulation.toggle_print_fff_options(&main_config) :
config_manipulation.toggle_print_sla_options(&main_config) ;
}
2018-11-09 18:39:07 +01:00
void ObjectSettings::UpdateAndShow(const bool show)
{
2019-07-11 23:46:23 +02:00
OG_Settings::UpdateAndShow(show ? update_settings_list() : false);
2018-11-09 18:39:07 +01:00
}
void ObjectSettings::msw_rescale()
2019-04-13 23:46:52 +02:00
{
m_bmp_delete.msw_rescale();
m_bmp_delete_focus.msw_rescale();
2019-04-13 23:46:52 +02:00
for (auto group : m_og_settings)
group->msw_rescale();
2019-04-13 23:46:52 +02:00
}
2018-11-09 18:39:07 +01:00
} //namespace GUI
} //namespace Slic3r