Completed split of the GUI_ObjectParts

This commit is contained in:
YuSanka 2018-10-05 23:29:15 +02:00
parent bcedd71e99
commit ea30385fd0
21 changed files with 1524 additions and 1880 deletions

View file

@ -1,7 +1,9 @@
#include "GUI_ObjectManipulation.hpp"
#include "GUI_ObjectList.hpp"
#include "OptionsGroup.hpp"
#include "wxExtensions.hpp"
#include "PresetBundle.hpp"
#include "Model.hpp"
#include "Geometry.hpp"
@ -36,7 +38,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent):
std::vector<std::string> axes{ "x", "y", "z" };
for (auto axis : axes) {
std::string key = "scale_" + axis;
get_optgroup(ogFrequentlyObjectSettings)->set_side_text(key, selection);
m_og->set_side_text(key, selection);
}
m_is_percent_scale = selection == _("%");
@ -80,7 +82,9 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent):
auto btn = new PrusaLockButton(parent, wxID_ANY);
btn->Bind(wxEVT_BUTTON, [btn](wxCommandEvent &event){
event.Skip();
wxTheApp->CallAfter([btn]() { set_uniform_scaling(btn->IsLocked()); });
wxTheApp->CallAfter([btn]() {
wxGetApp().obj_manipul()->set_uniform_scaling(btn->IsLocked());
});
});
return btn;
};
@ -136,8 +140,8 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent):
def.default_value = new ConfigOptionBool{ false };
m_og->append_single_option_line(Option(def, "place_on_bed"));
m_extra_settings_sizer = new wxBoxSizer(wxVERTICAL);
m_og->sizer->Add(m_extra_settings_sizer, 1, wxEXPAND | wxLEFT, 5);
m_settings_list_sizer = new wxBoxSizer(wxVERTICAL);
m_og->sizer->Add(m_settings_list_sizer, 1, wxEXPAND | wxLEFT, 5);
m_og->disable();
}
@ -147,6 +151,117 @@ int ObjectManipulation::ol_selection()
return wxGetApp().sidebar().get_ol_selection();
}
void ObjectManipulation::update_settings_list()
{
#ifdef __WXGTK__
auto parent = m_og->get_parent();
#else
auto parent = m_og->parent();
#endif /* __WXGTK__ */
// There is a bug related to Ubuntu overlay scrollbars, see https://github.com/prusa3d/Slic3r/issues/898 and https://github.com/prusa3d/Slic3r/issues/952.
// The issue apparently manifests when Show()ing a window with overlay scrollbars while the UI is frozen. For this reason,
// we will Thaw the UI prematurely on Linux. This means destroing the no_updates object prematurely.
#ifdef __linux__
std::unique_ptr<wxWindowUpdateLocker> no_updates(new wxWindowUpdateLocker(parent));
#else
wxWindowUpdateLocker noUpdates(parent);
#endif
m_settings_list_sizer->Clear(true);
bool show_manipulations = true;
auto objects_ctrl = wxGetApp().obj_list()->m_objects_ctrl;
auto objects_model = wxGetApp().obj_list()->m_objects_model;
auto config = wxGetApp().obj_list()->m_config;
const auto item = objects_ctrl->GetSelection();
if (config && objects_model->IsSettingsItem(item))
{
auto extra_column = [config](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 wxBitmapButton(parent, wxID_ANY, wxBitmap(from_u8(var("colorchange_delete_on.png")), wxBITMAP_TYPE_PNG),
wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
#ifdef __WXMSW__
btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif // __WXMSW__
btn->Bind(wxEVT_BUTTON, [opt_key, config](wxEvent &event){
config->erase(opt_key);
wxTheApp->CallAfter([]() { wxGetApp().obj_manipul()->update_settings_list(); });
});
return btn;
};
std::map<std::string, std::vector<std::string>> cat_options;
auto opt_keys = config->keys();
m_og_settings.resize(0);
std::vector<std::string> categories;
if (!(opt_keys.size() == 1 && opt_keys[0] == "extruder"))// return;
{
auto extruders_cnt = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA ? 1 :
wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
for (auto& opt_key : opt_keys) {
auto category = config->def()->get(opt_key)->category;
if (category.empty() ||
(category == "Extruders" && extruders_cnt == 1)) continue;
std::vector< std::string > new_category;
auto& cat_opt = cat_options.find(category) == cat_options.end() ? new_category : cat_options.at(category);
cat_opt.push_back(opt_key);
if (cat_opt.size() == 1)
cat_options[category] = cat_opt;
}
for (auto& cat : cat_options) {
if (cat.second.size() == 1 && cat.second[0] == "extruder")
continue;
auto optgroup = std::make_shared<ConfigOptionsGroup>(parent, cat.first, config, false, ogDEFAULT, extra_column);
optgroup->label_width = 150;
optgroup->sidetext_width = 70;
for (auto& opt : cat.second)
{
if (opt == "extruder")
continue;
Option option = optgroup->get_option(opt);
option.opt.width = 70;
optgroup->append_single_option_line(option);
}
optgroup->reload_config();
m_settings_list_sizer->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 0);
m_og_settings.push_back(optgroup);
categories.push_back(cat.first);
}
}
if (m_og_settings.empty()) {
objects_ctrl->Select(objects_model->Delete(item));
wxGetApp().obj_list()->part_selection_changed();
}
else {
if (!categories.empty())
objects_model->UpdateSettingsDigest(item, categories);
show_manipulations = false;
}
}
show_manipulation_og(show_manipulations);
wxGetApp().sidebar().show_info_sizers(show_manipulations && item && objects_model->GetParent(item) == wxDataViewItem(0));
#ifdef __linux__
no_updates.reset(nullptr);
#endif
parent->Layout();
/*wxGetApp().sidebar().*/parent->GetParent()->Layout();
}
void ObjectManipulation::update_values()
{
int selection = ol_selection();
@ -298,7 +413,21 @@ void ObjectManipulation::update_rotation_value(const Vec3d& rotation)
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void ObjectManipulation::show_object_name(bool show)
{
wxGridSizer* grid_sizer = m_og->get_grid_sizer();
grid_sizer->Show(static_cast<size_t>(0), show);
grid_sizer->Show(static_cast<size_t>(1), show);
}
void ObjectManipulation::show_manipulation_og(const bool show)
{
wxGridSizer* grid_sizer = m_og->get_grid_sizer();
if (show == grid_sizer->IsShown(2))
return;
for (size_t id = 2; id < 12; id++)
grid_sizer->Show(id, show);
}
} //namespace GUI
} //namespace Slic3r