2019-05-28 14:38:04 +00:00
|
|
|
#include "GUI_ObjectLayers.hpp"
|
|
|
|
#include "GUI_ObjectList.hpp"
|
|
|
|
|
|
|
|
#include "OptionsGroup.hpp"
|
|
|
|
#include "PresetBundle.hpp"
|
|
|
|
#include "libslic3r/Model.hpp"
|
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
#include "I18N.hpp"
|
|
|
|
|
|
|
|
#include <wx/wupdlock.h>
|
|
|
|
|
|
|
|
namespace Slic3r
|
|
|
|
{
|
|
|
|
namespace GUI
|
2019-05-30 10:41:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
#define field_width 8
|
2019-05-28 14:38:04 +00:00
|
|
|
|
|
|
|
ObjectLayers::ObjectLayers(wxWindow* parent) :
|
|
|
|
OG_Settings(parent, true)
|
|
|
|
{
|
2019-05-30 10:41:16 +00:00
|
|
|
m_og->label_width = 1;
|
2019-05-30 12:41:16 +00:00
|
|
|
m_og->set_grid_vgap(5);
|
2019-05-28 14:38:04 +00:00
|
|
|
|
|
|
|
// Legend for object layers
|
|
|
|
Line line = Line{ "", "" };
|
|
|
|
|
|
|
|
ConfigOptionDef def;
|
|
|
|
def.label = "";
|
|
|
|
def.gui_type = "legend";
|
|
|
|
def.type = coString;
|
|
|
|
def.width = field_width;
|
|
|
|
|
|
|
|
for (const std::string axis : { "Min Z", "Max Z", "Layer height" }) {
|
|
|
|
def.set_default_value(new ConfigOptionString{ axis });
|
|
|
|
std::string label = boost::algorithm::replace_all_copy(axis, " ", "_");
|
|
|
|
boost::algorithm::to_lower(label);
|
|
|
|
line.append_option(Option(def, label + "_legend"));
|
2019-05-30 10:41:16 +00:00
|
|
|
|
|
|
|
m_legends.push_back(label + "_legend");
|
2019-05-28 14:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_og->append_line(line);
|
|
|
|
|
2019-05-30 14:53:17 +00:00
|
|
|
m_bmp_delete = ScalableBitmap(parent, "remove_copies"/*"cross"*/);
|
2019-05-28 14:38:04 +00:00
|
|
|
m_bmp_add = ScalableBitmap(parent, "add_copies");
|
|
|
|
}
|
|
|
|
|
2019-05-30 10:41:16 +00:00
|
|
|
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()
|
|
|
|
{
|
2019-05-31 08:54:52 +00:00
|
|
|
for (const auto layer : m_object->layer_height_ranges)
|
|
|
|
{
|
|
|
|
auto create_btns = [this, layer](wxWindow* parent) {
|
|
|
|
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
2019-05-30 10:41:16 +00:00
|
|
|
|
2019-05-31 08:54:52 +00:00
|
|
|
auto del_btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete);
|
|
|
|
del_btn->SetToolTip(_(L("Remove layer")));
|
2019-05-30 10:41:16 +00:00
|
|
|
|
2019-05-31 08:54:52 +00:00
|
|
|
sizer->Add(del_btn, 0, wxRIGHT, em_unit(parent));
|
2019-05-30 10:41:16 +00:00
|
|
|
|
2019-05-31 08:54:52 +00:00
|
|
|
del_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) {
|
|
|
|
wxGetApp().obj_list()->del_layer_range(layer.first);
|
|
|
|
});
|
2019-05-30 10:41:16 +00:00
|
|
|
|
2019-05-31 08:54:52 +00:00
|
|
|
auto add_btn = new ScalableButton(parent, wxID_ANY, m_bmp_add);
|
|
|
|
add_btn->SetToolTip(_(L("Add layer")));
|
2019-05-30 10:41:16 +00:00
|
|
|
|
2019-05-31 08:54:52 +00:00
|
|
|
sizer->Add(add_btn, 0, wxRIGHT, em_unit(parent));
|
2019-05-30 10:41:16 +00:00
|
|
|
|
2019-05-31 08:54:52 +00:00
|
|
|
add_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) {
|
|
|
|
wxGetApp().obj_list()->add_layer_range(layer.first);
|
|
|
|
});
|
2019-05-30 10:41:16 +00:00
|
|
|
|
2019-05-31 08:54:52 +00:00
|
|
|
return sizer;
|
|
|
|
};
|
2019-05-30 10:41:16 +00:00
|
|
|
|
|
|
|
Line line = create_new_layer(layer);
|
|
|
|
line.append_widget(create_btns);
|
|
|
|
m_og->append_line(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 12:41:16 +00:00
|
|
|
void ObjectLayers::create_layer(int id)
|
2019-05-30 10:41:16 +00:00
|
|
|
{
|
2019-05-30 12:41:16 +00:00
|
|
|
t_layer_height_ranges::iterator layer_range = m_object->layer_height_ranges.begin();
|
|
|
|
|
2019-05-31 08:54:52 +00:00
|
|
|
// May be not a best solution #ys_FIXME
|
2019-05-30 12:41:16 +00:00
|
|
|
while (id > 0 && layer_range != m_object->layer_height_ranges.end()) {
|
|
|
|
layer_range++;
|
|
|
|
id--;
|
2019-05-30 10:41:16 +00:00
|
|
|
}
|
2019-05-30 12:41:16 +00:00
|
|
|
|
|
|
|
m_og->append_line(create_new_layer(*layer_range));
|
2019-05-30 10:41:16 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:38:04 +00:00
|
|
|
void ObjectLayers::update_layers_list()
|
|
|
|
{
|
|
|
|
ObjectList* objects_ctrl = wxGetApp().obj_list();
|
|
|
|
if (objects_ctrl->multiple_selection()) return;
|
|
|
|
|
|
|
|
const auto item = objects_ctrl->GetSelection();
|
|
|
|
if (!item) return;
|
|
|
|
|
|
|
|
const int obj_idx = objects_ctrl->get_selected_obj_idx();
|
|
|
|
if (obj_idx < 0) return;
|
|
|
|
|
|
|
|
const ItemType type = objects_ctrl->GetModel()->GetItemType(item);
|
|
|
|
if (!(type & (itLayerRoot | itLayer))) return;
|
|
|
|
|
2019-05-30 10:41:16 +00:00
|
|
|
m_object = objects_ctrl->object(obj_idx);
|
|
|
|
if (!m_object || m_object->layer_height_ranges.empty()) return;
|
2019-05-28 14:38:04 +00:00
|
|
|
|
2019-05-30 10:41:16 +00:00
|
|
|
// Delete all controls from options group except of the legends
|
2019-05-28 14:38:04 +00:00
|
|
|
|
2019-05-30 10:41:16 +00:00
|
|
|
auto grid_sizer = m_og->get_grid_sizer();
|
|
|
|
const int cols = grid_sizer->GetEffectiveColsCount();
|
|
|
|
const int rows = grid_sizer->GetEffectiveRowsCount();
|
2019-05-28 14:38:04 +00:00
|
|
|
for (int idx = cols*rows-1; idx >= cols; idx--) {
|
2019-05-30 10:41:16 +00:00
|
|
|
wxSizerItem* t = grid_sizer->GetItem(idx);
|
|
|
|
if (t->IsSizer())
|
|
|
|
t->GetSizer()->Clear(true);
|
|
|
|
grid_sizer->Remove(idx);
|
2019-05-28 14:38:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 10:41:16 +00:00
|
|
|
m_og->clear_fields_except_of(m_legends);
|
2019-05-28 14:38:04 +00:00
|
|
|
|
|
|
|
|
2019-05-30 10:41:16 +00:00
|
|
|
// Add new control according to the selected item
|
|
|
|
|
|
|
|
if (type & itLayerRoot)
|
|
|
|
create_layers_list();
|
|
|
|
else
|
2019-05-30 12:41:16 +00:00
|
|
|
create_layer(objects_ctrl->GetModel()->GetLayerIdByItem(item));
|
2019-05-30 10:41:16 +00:00
|
|
|
|
|
|
|
m_parent->Layout();
|
2019-05-28 14:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectLayers::UpdateAndShow(const bool show)
|
|
|
|
{
|
|
|
|
if (show)
|
|
|
|
update_layers_list();
|
|
|
|
|
|
|
|
OG_Settings::UpdateAndShow(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectLayers::msw_rescale()
|
|
|
|
{
|
|
|
|
m_bmp_delete.msw_rescale();
|
|
|
|
m_bmp_add.msw_rescale();
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace GUI
|
|
|
|
} //namespace Slic3r
|