Layers sizer updating

This commit is contained in:
YuSanka 2019-05-30 12:41:16 +02:00
parent 765d4264ae
commit bf56d79354
5 changed files with 128 additions and 71 deletions

View file

@ -14,13 +14,17 @@
namespace Slic3r namespace Slic3r
{ {
namespace GUI namespace GUI
{ {
typedef std::map<t_layer_height_range, coordf_t> t_layer_height_ranges;
#define field_width 8
ObjectLayers::ObjectLayers(wxWindow* parent) : ObjectLayers::ObjectLayers(wxWindow* parent) :
OG_Settings(parent, true) OG_Settings(parent, true)
{ {
m_og->label_width = 0; m_og->label_width = 1;
m_og->set_grid_vgap(5); // m_og->set_grid_vgap(5);
// Legend for object layers // Legend for object layers
Line line = Line{ "", "" }; Line line = Line{ "", "" };
@ -36,6 +40,8 @@ ObjectLayers::ObjectLayers(wxWindow* parent) :
std::string label = boost::algorithm::replace_all_copy(axis, " ", "_"); std::string label = boost::algorithm::replace_all_copy(axis, " ", "_");
boost::algorithm::to_lower(label); boost::algorithm::to_lower(label);
line.append_option(Option(def, label + "_legend")); line.append_option(Option(def, label + "_legend"));
m_legends.push_back(label + "_legend");
} }
m_og->append_line(line); m_og->append_line(line);
@ -44,6 +50,83 @@ ObjectLayers::ObjectLayers(wxWindow* parent) :
m_bmp_add = ScalableBitmap(parent, "add_copies"); m_bmp_add = ScalableBitmap(parent, "add_copies");
} }
static Line create_new_layer(const t_layer_height_ranges::value_type& layer)
{
Line line = Line{ "", "" };
ConfigOptionDef def;
def.label = "";
def.gui_type = "";
def.type = coFloat;
def.width = field_width;
std::string label = (boost::format("min_z_%.2f") % layer.first.first).str();
def.set_default_value(new ConfigOptionFloat(layer.first.first));
line.append_option(Option(def, label));
label = (boost::format("max_z_%.2f") % layer.first.second).str();
def.set_default_value(new ConfigOptionFloat(layer.first.second));
line.append_option(Option(def, label));
label = (boost::format("layer_height_%.2f_%.2f") % layer.first.first % layer.first.second).str();
def.set_default_value(new ConfigOptionFloat(layer.second));
line.append_option(Option(def, label));
return line;
}
void ObjectLayers::create_layers_list()
{
auto create_btns = [this](wxWindow* parent) {
auto sizer = new wxBoxSizer(wxHORIZONTAL);
auto del_btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete);
del_btn->SetToolTip(_(L("Remove layer")));
sizer->Add(del_btn, 0, wxRIGHT, em_unit(parent));
del_btn->Bind(wxEVT_BUTTON, [this](wxEvent &event) {
del_layer();
// wxTheApp->CallAfter([this]() {
// wxWindowUpdateLocker noUpdates(m_parent);
// update_layers_list();
// m_parent->Layout();
// });
});
auto add_btn = new ScalableButton(parent, wxID_ANY, m_bmp_add);
add_btn->SetToolTip(_(L("Add layer")));
sizer->Add(add_btn, 0, wxRIGHT, em_unit(parent));
add_btn->Bind(wxEVT_BUTTON, [this](wxEvent &event) {
add_layer();
// wxTheApp->CallAfter([this]() {
// wxWindowUpdateLocker noUpdates(m_parent);
// update_layers_list();
// m_parent->Layout();
// });
});
return sizer;
};
for (const auto layer : m_object->layer_height_ranges)
{
Line line = create_new_layer(layer);
line.append_widget(create_btns);
m_og->append_line(line);
}
}
void ObjectLayers::create_layer()
{
for (const auto layer : m_object->layer_height_ranges)
{
m_og->append_line(create_new_layer(layer));
break;
}
}
void ObjectLayers::update_layers_list() void ObjectLayers::update_layers_list()
{ {
ObjectList* objects_ctrl = wxGetApp().obj_list(); ObjectList* objects_ctrl = wxGetApp().obj_list();
@ -58,78 +141,32 @@ void ObjectLayers::update_layers_list()
const ItemType type = objects_ctrl->GetModel()->GetItemType(item); const ItemType type = objects_ctrl->GetModel()->GetItemType(item);
if (!(type & (itLayerRoot | itLayer))) return; if (!(type & (itLayerRoot | itLayer))) return;
ModelObject* object = objects_ctrl->object(obj_idx); m_object = objects_ctrl->object(obj_idx);
if (!object || object->layer_height_ranges.empty()) return; if (!m_object || m_object->layer_height_ranges.empty()) return;
// Delete all controls from options group except of the legends
auto grid_sizer = m_og->get_grid_sizer(); auto grid_sizer = m_og->get_grid_sizer();
const int cols = grid_sizer->GetEffectiveColsCount();
const int cols = grid_sizer->GetCols(); const int rows = grid_sizer->GetEffectiveRowsCount();
const int rows = grid_sizer->GetRows();
for (int idx = cols*rows-1; idx >= cols; idx--) { for (int idx = cols*rows-1; idx >= cols; idx--) {
grid_sizer->Remove(idx); wxSizerItem* t = grid_sizer->GetItem(idx);
if (t->IsSizer())
t->GetSizer()->Clear(true);
grid_sizer->Remove(idx);
} }
ConfigOptionDef def; m_og->clear_fields_except_of(m_legends);
def.label = "";
def.gui_type = "";
def.type = coFloat; // Add new control according to the selected item
def.width = field_width;
if (type & itLayerRoot) if (type & itLayerRoot)
{ create_layers_list();
auto create_btns = [this](wxWindow* parent) { else
auto sizer = new wxBoxSizer(wxHORIZONTAL); create_layer();
auto del_btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete);
del_btn->SetToolTip(_(L("Remove layer"))); m_parent->Layout();
sizer->Add(del_btn, 0, wxRIGHT, em_unit(parent));
del_btn->Bind(wxEVT_BUTTON, [this](wxEvent &event) {
del_layer();
// wxTheApp->CallAfter([this]() {
// wxWindowUpdateLocker noUpdates(m_parent);
// update_layers_list();
// m_parent->Layout();
// });
});
auto add_btn = new ScalableButton(parent, wxID_ANY, m_bmp_add);
add_btn->SetToolTip(_(L("Add layer")));
sizer->Add(add_btn, 0, wxRIGHT, em_unit(parent));
add_btn->Bind(wxEVT_BUTTON, [this](wxEvent &event) {
add_layer();
// wxTheApp->CallAfter([this]() {
// wxWindowUpdateLocker noUpdates(m_parent);
// update_layers_list();
// m_parent->Layout();
// });
});
return sizer;
};
Line line{"",""};
for (const auto layer : object->layer_height_ranges)
{
std::string label = (boost::format("min_z_%.2f") % layer.first.first).str();
def.set_default_value(new ConfigOptionFloat(layer.first.first));
line.append_option(Option(def, label));
label = (boost::format("max_z_%.2f") % layer.first.second).str();
def.set_default_value(new ConfigOptionFloat(layer.first.second));
line.append_option(Option(def, label));
label = (boost::format("layer_height_%.2f_%.2f") % layer.first.first % layer.first.second).str();
def.set_default_value(new ConfigOptionFloat(layer.second));
line.append_option(Option(def, label));
line.append_widget(create_btns);
}
m_og->append_line(line);
}
} }
void ObjectLayers::UpdateAndShow(const bool show) void ObjectLayers::UpdateAndShow(const bool show)

View file

@ -14,15 +14,18 @@ class ConfigOptionsGroup;
class ObjectLayers : public OG_Settings class ObjectLayers : public OG_Settings
{ {
ScalableBitmap m_bmp_delete; ScalableBitmap m_bmp_delete;
ScalableBitmap m_bmp_add; ScalableBitmap m_bmp_add;
ModelObject* m_object {nullptr};
int field_width {8}; std::vector<std::string> m_legends;
public: public:
ObjectLayers(wxWindow* parent); ObjectLayers(wxWindow* parent);
~ObjectLayers() {} ~ObjectLayers() {}
void create_layers_list();
void create_layer();
void update_layers_list(); void update_layers_list();
void add_layer() {}; void add_layer() {};
void del_layer() {}; void del_layer() {};

View file

@ -1803,6 +1803,10 @@ void ObjectList::layers_editing()
{ {
const t_layer_height_range first_range = { 0.0f, 0.2f }; const t_layer_height_range first_range = { 0.0f, 0.2f };
object(obj_idx)->layer_height_ranges[first_range] = 0.1f; object(obj_idx)->layer_height_ranges[first_range] = 0.1f;
const t_layer_height_range second_range = { 0.2f, 0.4f };
object(obj_idx)->layer_height_ranges[second_range] = 0.05f;
layers_item = m_objects_model->AddLayersRoot(obj_item); layers_item = m_objects_model->AddLayersRoot(obj_item);
} }

View file

@ -320,6 +320,17 @@ Line OptionsGroup::create_single_option_line(const Option& option) const {
return retval; return retval;
} }
void OptionsGroup::clear_fields_except_of(const std::vector<std::string> left_fields)
{
auto it = m_fields.begin();
while (it != m_fields.end()) {
if (std::find(left_fields.begin(), left_fields.end(), it->first) == left_fields.end())
it = m_fields.erase(it);
else
it++;
}
}
void OptionsGroup::on_set_focus(const std::string& opt_key) void OptionsGroup::on_set_focus(const std::string& opt_key)
{ {
if (m_set_focus != nullptr) if (m_set_focus != nullptr)

View file

@ -160,6 +160,8 @@ public:
m_show_modified_btns = show; m_show_modified_btns = show;
} }
void clear_fields_except_of(const std::vector<std::string> left_fields);
OptionsGroup( wxWindow* _parent, const wxString& title, bool is_tab_opt = false, OptionsGroup( wxWindow* _parent, const wxString& title, bool is_tab_opt = false,
column_t extra_clmn = nullptr) : column_t extra_clmn = nullptr) :
m_parent(_parent), title(title), m_parent(_parent), title(title),