mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-11 05:19:07 +08:00
Added LayerRangeEditor class for universally editing of the layer_range's parameters
+ Implemented layer_height editing
This commit is contained in:
parent
79a89c4c8f
commit
4756961678
@ -46,44 +46,21 @@ wxSizer* ObjectLayers::create_layer_without_buttons(const t_layer_config_ranges:
|
|||||||
auto size = wxSize(field_width * em_unit(m_parent), wxDefaultCoord);
|
auto size = wxSize(field_width * em_unit(m_parent), wxDefaultCoord);
|
||||||
|
|
||||||
// Add control for the "Min Z"
|
// Add control for the "Min Z"
|
||||||
wxString text_value = double_to_string(layer.first.first);
|
auto temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.first), size);
|
||||||
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER);
|
|
||||||
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
|
||||||
|
|
||||||
temp->Bind(wxEVT_TEXT_ENTER, ([this, temp](wxEvent& e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}), temp->GetId());
|
|
||||||
|
|
||||||
temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}), temp->GetId());
|
|
||||||
|
|
||||||
|
|
||||||
temp->Bind(wxEVT_CHAR, ([temp](wxKeyEvent& event)
|
|
||||||
{
|
|
||||||
// select all text using Ctrl+A
|
|
||||||
if (wxGetKeyState(wxKeyCode('A')) && wxGetKeyState(WXK_CONTROL))
|
|
||||||
temp->SetSelection(-1, -1); //select all
|
|
||||||
event.Skip();
|
|
||||||
}));
|
|
||||||
|
|
||||||
m_grid_sizer->Add(temp);
|
m_grid_sizer->Add(temp);
|
||||||
|
|
||||||
// Add control for the "Max Z"
|
// Add control for the "Max Z"
|
||||||
text_value = double_to_string(layer.first.second);
|
temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.second), size);
|
||||||
temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER);
|
|
||||||
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
|
||||||
|
|
||||||
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);
|
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
|
||||||
text_value = double_to_string(layer.second.option("layer_height")->getFloat());
|
const wxString text_value = double_to_string(layer.second.option("layer_height")->getFloat());
|
||||||
temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER);
|
|
||||||
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
temp = new LayerRangeEditor(m_parent, text_value, size, [temp, layer](coordf_t layer_height) {
|
||||||
|
wxGetApp().obj_list()->edit_layer_range(layer.first, layer_height);
|
||||||
|
} );
|
||||||
sizer->Add(temp);
|
sizer->Add(temp);
|
||||||
|
|
||||||
m_grid_sizer->Add(sizer);
|
m_grid_sizer->Add(sizer);
|
||||||
@ -185,5 +162,59 @@ void ObjectLayers::msw_rescale()
|
|||||||
m_bmp_add.msw_rescale();
|
m_bmp_add.msw_rescale();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LayerRangeEditor::LayerRangeEditor( wxWindow* parent,
|
||||||
|
const wxString& value,
|
||||||
|
const wxSize& size,
|
||||||
|
std::function<void(coordf_t)> edit_fn
|
||||||
|
) :
|
||||||
|
wxTextCtrl(parent, wxID_ANY, value, wxDefaultPosition, size, wxTE_PROCESS_ENTER)
|
||||||
|
{
|
||||||
|
this->SetFont(wxGetApp().normal_font());
|
||||||
|
|
||||||
|
this->Bind(wxEVT_TEXT_ENTER, ([this, edit_fn](wxEvent& e)
|
||||||
|
{
|
||||||
|
edit_fn(get_value());
|
||||||
|
m_enter_pressed = true;
|
||||||
|
}), this->GetId());
|
||||||
|
|
||||||
|
this->Bind(wxEVT_KILL_FOCUS, ([this, edit_fn](wxEvent& e)
|
||||||
|
{
|
||||||
|
e.Skip();
|
||||||
|
if (!m_enter_pressed)
|
||||||
|
edit_fn(get_value());
|
||||||
|
m_enter_pressed = false;
|
||||||
|
}), this->GetId());
|
||||||
|
|
||||||
|
|
||||||
|
this->Bind(wxEVT_CHAR, ([this](wxKeyEvent& event)
|
||||||
|
{
|
||||||
|
// select all text using Ctrl+A
|
||||||
|
if (wxGetKeyState(wxKeyCode('A')) && wxGetKeyState(WXK_CONTROL))
|
||||||
|
this->SetSelection(-1, -1); //select all
|
||||||
|
event.Skip();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
coordf_t LayerRangeEditor::get_value()
|
||||||
|
{
|
||||||
|
wxString str = GetValue();
|
||||||
|
|
||||||
|
coordf_t layer_height;
|
||||||
|
// Replace the first occurence of comma in decimal number.
|
||||||
|
str.Replace(",", ".", false);
|
||||||
|
if (str == ".")
|
||||||
|
layer_height = 0.0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!str.ToCDouble(&layer_height) || layer_height < 0.0f)
|
||||||
|
{
|
||||||
|
show_error(m_parent, _(L("Invalid numeric input.")));
|
||||||
|
SetValue(double_to_string(layer_height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return layer_height;
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace GUI
|
} //namespace GUI
|
||||||
} //namespace Slic3r
|
} //namespace Slic3r
|
@ -12,6 +12,22 @@ class ModelObject;
|
|||||||
namespace GUI {
|
namespace GUI {
|
||||||
class ConfigOptionsGroup;
|
class ConfigOptionsGroup;
|
||||||
|
|
||||||
|
class LayerRangeEditor : public wxTextCtrl
|
||||||
|
{
|
||||||
|
bool m_enter_pressed { false };
|
||||||
|
public:
|
||||||
|
LayerRangeEditor( wxWindow* parent,
|
||||||
|
const wxString& value = wxEmptyString,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
std::function<void(coordf_t val)> edit_fn = [](coordf_t) {; }
|
||||||
|
);
|
||||||
|
~LayerRangeEditor() {}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
coordf_t get_value();
|
||||||
|
};
|
||||||
|
|
||||||
class ObjectLayers : public OG_Settings
|
class ObjectLayers : public OG_Settings
|
||||||
{
|
{
|
||||||
ScalableBitmap m_bmp_delete;
|
ScalableBitmap m_bmp_delete;
|
||||||
|
@ -2312,9 +2312,15 @@ void ObjectList::add_layer_item(const t_layer_height_range& range,
|
|||||||
m_objects_model->AddLayersChild(layers_item, label, layer_idx);
|
m_objects_model->AddLayersChild(layers_item, label, layer_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectList::edit_layer_range(const std::pair<coordf_t, coordf_t>& range)
|
void ObjectList::edit_layer_range(const t_layer_height_range& range, coordf_t layer_height)
|
||||||
{
|
{
|
||||||
|
const int obj_idx = get_selected_obj_idx();
|
||||||
|
if (obj_idx < 0) return;
|
||||||
|
|
||||||
|
t_layer_config_ranges& ranges = object(obj_idx)->layer_config_ranges;
|
||||||
|
|
||||||
|
DynamicPrintConfig* config = &ranges[range];
|
||||||
|
config->set_key_value("layer_height", new ConfigOptionFloat(layer_height));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectList::init_objects()
|
void ObjectList::init_objects()
|
||||||
|
@ -276,7 +276,7 @@ public:
|
|||||||
void add_layer_item (const std::pair<coordf_t, coordf_t>& range,
|
void add_layer_item (const std::pair<coordf_t, coordf_t>& range,
|
||||||
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);
|
void edit_layer_range(const std::pair<coordf_t, coordf_t>& range, coordf_t layer_height);
|
||||||
|
|
||||||
void init_objects();
|
void init_objects();
|
||||||
bool multiple_selection() const ;
|
bool multiple_selection() const ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user