mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-22 04:28:05 +08:00
Implemented range's min/max Z editing
This commit is contained in:
parent
4756961678
commit
213635f559
@ -43,26 +43,31 @@ ObjectLayers::ObjectLayers(wxWindow* parent) :
|
|||||||
|
|
||||||
wxSizer* ObjectLayers::create_layer_without_buttons(const t_layer_config_ranges::value_type& layer)
|
wxSizer* ObjectLayers::create_layer_without_buttons(const t_layer_config_ranges::value_type& layer)
|
||||||
{
|
{
|
||||||
auto size = wxSize(field_width * em_unit(m_parent), wxDefaultCoord);
|
|
||||||
|
|
||||||
// Add control for the "Min Z"
|
// Add control for the "Min Z"
|
||||||
auto temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.first), size);
|
auto temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.first),
|
||||||
|
[layer](coordf_t min_z) {
|
||||||
|
wxGetApp().obj_list()->edit_layer_range(layer.first, { min_z, layer.first.second });
|
||||||
|
});
|
||||||
|
|
||||||
m_grid_sizer->Add(temp);
|
m_grid_sizer->Add(temp);
|
||||||
|
|
||||||
// Add control for the "Max Z"
|
// Add control for the "Max Z"
|
||||||
temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.second), size);
|
temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.second),
|
||||||
|
[layer](coordf_t max_z) {
|
||||||
|
wxGetApp().obj_list()->edit_layer_range(layer.first, { layer.first.first, max_z });
|
||||||
|
});
|
||||||
|
|
||||||
m_grid_sizer->Add(temp);
|
m_grid_sizer->Add(temp);
|
||||||
|
|
||||||
// Add control for the "Layer height"
|
// Add control for the "Layer height"
|
||||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
temp = new LayerRangeEditor(m_parent,
|
||||||
|
double_to_string(layer.second.option("layer_height")->getFloat()),
|
||||||
const wxString text_value = double_to_string(layer.second.option("layer_height")->getFloat());
|
[layer](coordf_t layer_height) {
|
||||||
|
|
||||||
temp = new LayerRangeEditor(m_parent, text_value, size, [temp, layer](coordf_t layer_height) {
|
|
||||||
wxGetApp().obj_list()->edit_layer_range(layer.first, layer_height);
|
wxGetApp().obj_list()->edit_layer_range(layer.first, layer_height);
|
||||||
} );
|
}, false );
|
||||||
sizer->Add(temp);
|
|
||||||
|
|
||||||
|
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
sizer->Add(temp);
|
||||||
m_grid_sizer->Add(sizer);
|
m_grid_sizer->Add(sizer);
|
||||||
|
|
||||||
return sizer;
|
return sizer;
|
||||||
@ -164,25 +169,28 @@ void ObjectLayers::msw_rescale()
|
|||||||
|
|
||||||
LayerRangeEditor::LayerRangeEditor( wxWindow* parent,
|
LayerRangeEditor::LayerRangeEditor( wxWindow* parent,
|
||||||
const wxString& value,
|
const wxString& value,
|
||||||
const wxSize& size,
|
std::function<void(coordf_t)> edit_fn,
|
||||||
std::function<void(coordf_t)> edit_fn
|
const bool deletable_after_change
|
||||||
) :
|
) :
|
||||||
wxTextCtrl(parent, wxID_ANY, value, wxDefaultPosition, size, wxTE_PROCESS_ENTER)
|
wxTextCtrl(parent, wxID_ANY, value, wxDefaultPosition,
|
||||||
|
wxSize(field_width * em_unit(parent), wxDefaultCoord), wxTE_PROCESS_ENTER)
|
||||||
{
|
{
|
||||||
this->SetFont(wxGetApp().normal_font());
|
this->SetFont(wxGetApp().normal_font());
|
||||||
|
|
||||||
this->Bind(wxEVT_TEXT_ENTER, ([this, edit_fn](wxEvent& e)
|
this->Bind(wxEVT_TEXT_ENTER, ([this, edit_fn](wxEvent& e)
|
||||||
{
|
{
|
||||||
edit_fn(get_value());
|
|
||||||
m_enter_pressed = true;
|
m_enter_pressed = true;
|
||||||
|
edit_fn(get_value());
|
||||||
}), this->GetId());
|
}), this->GetId());
|
||||||
|
|
||||||
this->Bind(wxEVT_KILL_FOCUS, ([this, edit_fn](wxEvent& e)
|
this->Bind(wxEVT_KILL_FOCUS, ([this, edit_fn, deletable_after_change](wxEvent& e)
|
||||||
{
|
{
|
||||||
e.Skip();
|
if (!deletable_after_change)
|
||||||
if (!m_enter_pressed)
|
e.Skip();
|
||||||
|
if (!m_enter_pressed) {
|
||||||
|
m_enter_pressed = false;
|
||||||
edit_fn(get_value());
|
edit_fn(get_value());
|
||||||
m_enter_pressed = false;
|
}
|
||||||
}), this->GetId());
|
}), this->GetId());
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ class LayerRangeEditor : public wxTextCtrl
|
|||||||
public:
|
public:
|
||||||
LayerRangeEditor( wxWindow* parent,
|
LayerRangeEditor( wxWindow* parent,
|
||||||
const wxString& value = wxEmptyString,
|
const wxString& value = wxEmptyString,
|
||||||
const wxSize& size = wxDefaultSize,
|
std::function<void(coordf_t val)> edit_fn = [](coordf_t) {},
|
||||||
std::function<void(coordf_t val)> edit_fn = [](coordf_t) {; }
|
const bool deletable_after_change = true
|
||||||
);
|
);
|
||||||
~LayerRangeEditor() {}
|
~LayerRangeEditor() {}
|
||||||
|
|
||||||
|
@ -2265,6 +2265,9 @@ void ObjectList::add_layer_range(const t_layer_height_range& range)
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selected_range->first.second > next_range->first.first)
|
||||||
|
return; // range devision has no mean
|
||||||
|
|
||||||
if (selected_range->first.second == next_range->first.first)
|
if (selected_range->first.second == next_range->first.first)
|
||||||
{
|
{
|
||||||
const coordf_t delta = (next_range->first.second - next_range->first.first);
|
const coordf_t delta = (next_range->first.second - next_range->first.first);
|
||||||
@ -2323,6 +2326,31 @@ void ObjectList::edit_layer_range(const t_layer_height_range& range, coordf_t la
|
|||||||
config->set_key_value("layer_height", new ConfigOptionFloat(layer_height));
|
config->set_key_value("layer_height", new ConfigOptionFloat(layer_height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectList::edit_layer_range(const t_layer_height_range& range, const t_layer_height_range& new_range)
|
||||||
|
{
|
||||||
|
const int obj_idx = get_selected_obj_idx();
|
||||||
|
if (obj_idx < 0) return;
|
||||||
|
|
||||||
|
t_layer_config_ranges& ranges = object(obj_idx)->layer_config_ranges;
|
||||||
|
|
||||||
|
const DynamicPrintConfig config = ranges[range];
|
||||||
|
|
||||||
|
ranges.erase(range);
|
||||||
|
ranges[new_range] = config;
|
||||||
|
|
||||||
|
wxDataViewItem root_item = m_objects_model->GetLayerRootItem(m_objects_model->GetItemById(obj_idx));
|
||||||
|
m_objects_model->DeleteChildren(root_item);
|
||||||
|
|
||||||
|
if (root_item.IsOk())
|
||||||
|
// create Layer item(s) according to the layer_config_ranges
|
||||||
|
for (const auto r : ranges)
|
||||||
|
add_layer_item(r.first, root_item);
|
||||||
|
|
||||||
|
// To update(recreate) layers sizer call select_item for LayerRoot item expand
|
||||||
|
select_item(root_item);
|
||||||
|
Expand(root_item);
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectList::init_objects()
|
void ObjectList::init_objects()
|
||||||
{
|
{
|
||||||
m_objects = wxGetApp().model_objects();
|
m_objects = wxGetApp().model_objects();
|
||||||
|
@ -277,6 +277,8 @@ public:
|
|||||||
const wxDataViewItem layers_item,
|
const wxDataViewItem layers_item,
|
||||||
const int layer_idx = -1);
|
const int layer_idx = -1);
|
||||||
void edit_layer_range(const std::pair<coordf_t, coordf_t>& range, coordf_t layer_height);
|
void edit_layer_range(const std::pair<coordf_t, coordf_t>& range, coordf_t layer_height);
|
||||||
|
void edit_layer_range(const std::pair<coordf_t, coordf_t>& range,
|
||||||
|
const std::pair<coordf_t, coordf_t>& new_range);
|
||||||
|
|
||||||
void init_objects();
|
void init_objects();
|
||||||
bool multiple_selection() const ;
|
bool multiple_selection() const ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user