Changed context menu for DoubleSlider

This commit is contained in:
YuSanka 2019-10-31 15:24:20 +01:00
parent 8ebd9ce7c4
commit 8d27cfd4a6
3 changed files with 77 additions and 21 deletions

View File

@ -604,6 +604,9 @@ void Preview::update_view_type(bool slice_completed)
m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type; m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type;
m_preferred_color_mode = "feature"; m_preferred_color_mode = "feature";
} }
if (type != GCodePreviewData::Extrusion::EViewType::ColorPrint)
m_extruder_selector->SetSelection(0);
} }
void Preview::update_extruder_selector() void Preview::update_extruder_selector()
@ -726,7 +729,11 @@ void Preview::update_double_slider(const std::vector<double>& layers_z, bool kee
// #ys_FIXME_COLOR // #ys_FIXME_COLOR
// std::vector<double> &ticks_from_config = (wxGetApp().preset_bundle->project_config.option<ConfigOptionFloats>("colorprint_heights"))->values; // std::vector<double> &ticks_from_config = (wxGetApp().preset_bundle->project_config.option<ConfigOptionFloats>("colorprint_heights"))->values;
// check_slider_values(ticks_from_config, layers_z); // check_slider_values(ticks_from_config, layers_z);
std::vector<Model::CustomGCode> &ticks_from_model = wxGetApp().plater()->model().custom_gcode_per_height; std::vector<Model::CustomGCode> tmp_ticks_from_model;
if (m_selected_extruder != 0)
tmp_ticks_from_model = wxGetApp().plater()->model().custom_gcode_per_height;
std::vector<Model::CustomGCode> &ticks_from_model = m_selected_extruder != 0 ? tmp_ticks_from_model :
wxGetApp().plater()->model().custom_gcode_per_height;
check_slider_values(ticks_from_model, layers_z); check_slider_values(ticks_from_model, layers_z);
m_slider->SetSliderValues(layers_z); m_slider->SetSliderValues(layers_z);

View File

@ -2552,7 +2552,7 @@ void DoubleSlider::SetTicksValues_(const std::vector<t_custom_code>& heights)
m_ticks_.insert(TICK_CODE(it-m_values.begin(), h.gcode, h.extruder)); m_ticks_.insert(TICK_CODE(it-m_values.begin(), h.gcode, h.extruder));
} }
if (!was_empty && m_ticks_.empty()) if (!was_empty && m_ticks_.empty() && m_state != msMultiExtruder)
// Switch to the "Feature type"/"Tool" from the very beginning of a new object slicing after deleting of the old one // Switch to the "Feature type"/"Tool" from the very beginning of a new object slicing after deleting of the old one
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
} }
@ -3232,6 +3232,33 @@ void DoubleSlider::OnLeftUp(wxMouseEvent& event)
return; return;
this->ReleaseMouse(); this->ReleaseMouse();
m_is_left_down = false; m_is_left_down = false;
if (m_show_context_menu)
{
if (m_state == msMultiExtruderWholePrint)
{
wxMenu menu;
const int extruders_cnt = Slic3r::GUI::wxGetApp().extruders_edited_cnt();
if (extruders_cnt > 1)
{
const int initial_extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value);
wxMenu* add_color_change_menu = new wxMenu();
for (int i = 1; i <= extruders_cnt; i++)
append_menu_radio_item(add_color_change_menu, wxID_ANY, wxString::Format(_(L("Extruder %d")), i), "",
[this, i](wxCommandEvent&) { add_code("M600", i); }, &menu)->Check(i == initial_extruder);
const wxString menu_name = from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % "M600").str());
wxMenuItem* add_color_change_menu_item = menu.AppendSubMenu(add_color_change_menu, menu_name, "");
add_color_change_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "colorchange_add_off.png"));
}
Slic3r::GUI::wxGetApp().plater()->PopupMenu(&menu);
m_show_context_menu = false;
}
}
Refresh(); Refresh();
Update(); Update();
event.Skip(); event.Skip();
@ -3295,17 +3322,25 @@ void DoubleSlider::action_tick(const TicksAction action)
// m_ticks.erase(tick); // m_ticks.erase(tick);
// } // }
if (action == taOnIcon) { const auto it = m_ticks_.find(tick);
if (!m_ticks_.insert(TICK_CODE(tick)).second)
m_ticks_.erase(TICK_CODE(tick)); if (it != m_ticks_.end())
{
if (action == taAdd)
return;
m_ticks_.erase(TICK_CODE(tick));
} }
else { else if (action == taDel)
const auto it = m_ticks_.find(tick); return;
if (it == m_ticks_.end() && action == taAdd) else if (m_state == msMultiExtruderWholePrint)
m_ticks_.insert(tick); {
else if (it != m_ticks_.end() && action == taDel) if (action == taAdd)
m_ticks_.erase(tick); return;
m_show_context_menu = true;
return;
} }
else
m_ticks_.insert(TICK_CODE(tick, "M600", m_state == msSingleExtruder ? 0 : m_current_extruder));
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh(); Refresh();
@ -3443,25 +3478,35 @@ void DoubleSlider::OnRightUp(wxMouseEvent& event)
if (m_state == msMultiExtruderWholePrint) if (m_state == msMultiExtruderWholePrint)
{ {
const wxString name = _(L("Change extruder"));
const int extruders_cnt = Slic3r::GUI::wxGetApp().extruders_edited_cnt(); const int extruders_cnt = Slic3r::GUI::wxGetApp().extruders_edited_cnt();
if (extruders_cnt > 1) if (extruders_cnt > 1)
{ {
const int initial_extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value); const int initial_extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value);
wxMenu* change_extruder_menu = new wxMenu(); wxMenu* change_extruder_menu = new wxMenu();
wxMenu* add_color_change_menu = new wxMenu();
for (int i = 0; i <= extruders_cnt; i++) { for (int i = 0; i <= extruders_cnt; i++) {
const wxString& item_name = i == 0 ? _(L("Default")) : wxString::Format("%d", i); const wxString item_name = i == 0 ? _(L("Default")) : wxString::Format(_(L("Extruder %d")), i);
append_menu_radio_item(change_extruder_menu, wxID_ANY, item_name, "", append_menu_radio_item(change_extruder_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { change_extruder(i); }, &menu)->Check(i == initial_extruder); [this, i](wxCommandEvent&) { change_extruder(i); }, &menu)->Check(i == initial_extruder);
if (i==0) // don't use M600 for default extruder, if multimaterial print is selected
continue;
append_menu_radio_item(add_color_change_menu, wxID_ANY, /*i == 0 ? _(L("current extruder")) : */item_name, "",
[this, i](wxCommandEvent&) { add_code("M600", i); }, &menu)->Check(i == initial_extruder);
} }
menu.AppendSubMenu(change_extruder_menu, name, _(L("Use another extruder"))); wxMenuItem* change_extruder_menu_item = menu.AppendSubMenu(change_extruder_menu, _(L("Change extruder")), _(L("Use another extruder")));
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "change_extruder"));
const wxString menu_name = from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % "M600").str());
wxMenuItem* add_color_change_menu_item = menu.AppendSubMenu(add_color_change_menu, menu_name, "");
add_color_change_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "colorchange_add_off.png"));
} }
} }
else
append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "", append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "",
[this](wxCommandEvent&) { add_code("M600"); }, "colorchange_add_off.png", &menu); [this](wxCommandEvent&) { add_code("M600"); }, "colorchange_add_off.png", &menu);
@ -3482,7 +3527,7 @@ void DoubleSlider::OnRightUp(wxMouseEvent& event)
event.Skip(); event.Skip();
} }
void DoubleSlider::add_code(std::string code) void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
{ {
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value; const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
// if on this Y doesn't exist tick // if on this Y doesn't exist tick
@ -3504,8 +3549,12 @@ void DoubleSlider::add_code(std::string code)
} }
int extruder = 0; int extruder = 0;
if (m_state == msMultiExtruderWholePrint && m_custom_gcode != "M600" ) if (m_state == msMultiExtruderWholePrint) {
extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value); if (code == "M600" && selected_extruder >= 0)
extruder = selected_extruder;
else
extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value);
}
else if (m_state == msMultiExtruder && m_current_extruder > 0) else if (m_state == msMultiExtruder && m_current_extruder > 0)
extruder = m_current_extruder; extruder = m_current_extruder;

View File

@ -851,9 +851,9 @@ public:
void OnKeyUp(wxKeyEvent &event); void OnKeyUp(wxKeyEvent &event);
void OnChar(wxKeyEvent &event); void OnChar(wxKeyEvent &event);
void OnRightDown(wxMouseEvent& event); void OnRightDown(wxMouseEvent& event);
int get_extruder_for_tick(int tick); int get_extruder_for_tick(int tick);
void OnRightUp(wxMouseEvent& event); void OnRightUp(wxMouseEvent& event);
void add_code(std::string code); void add_code(std::string code, int selected_extruder = -1);
void change_extruder(int extruder); void change_extruder(int extruder);
protected: protected: