RammingChart: increase y-range, allow uniform dragging (while holding Ctrl)

This commit is contained in:
Lukas Matena 2023-06-13 08:38:07 +02:00
parent 61e20a8cfa
commit 79b8b180fc
3 changed files with 29 additions and 14 deletions

View File

@ -115,6 +115,7 @@ void Chart::mouse_right_button_clicked(wxMouseEvent& event) {
void Chart::mouse_clicked(wxMouseEvent& event) {
m_uniform = (event.GetModifiers() == wxMOD_CONTROL);
wxPoint point = event.GetPosition();
int button_index = which_button_is_clicked(point);
if ( button_index != -1) {
@ -136,7 +137,13 @@ void Chart::mouse_moved(wxMouseEvent& event) {
}
int delta_x = pos.x - m_previous_mouse.x;
int delta_y = pos.y - m_previous_mouse.y;
m_dragged->move(fixed_x?0:double(delta_x)/m_rect.GetWidth() * visible_area.m_width,-double(delta_y)/m_rect.GetHeight() * visible_area.m_height);
if (m_uniform)
for (ButtonToDrag& b : m_buttons)
b.move(fixed_x?0:double(delta_x)/m_rect.GetWidth() * visible_area.m_width, m_dragged->get_pos().m_y - b.get_pos().m_y + -double(delta_y)/m_rect.GetHeight() * visible_area.m_height);
else
m_dragged->move(fixed_x?0:double(delta_x)/m_rect.GetWidth() * visible_area.m_width, -double(delta_y)/m_rect.GetHeight() * visible_area.m_height);
m_previous_mouse = pos;
recalculate_line();
}
@ -263,7 +270,7 @@ std::vector<float> Chart::get_ramming_speed(float sampling) const {
std::vector<float> speeds_out;
const int number_of_samples = std::round( visible_area.m_width / sampling);
if (number_of_samples>0) {
if (number_of_samples>0 && !m_line_to_draw.empty()) {
const int dx = (m_line_to_draw.size()-1) / number_of_samples;
for (int j=0;j<number_of_samples;++j) {
float left = screen_to_math(wxPoint(0,m_line_to_draw[j*dx])).m_y;

View File

@ -23,7 +23,7 @@ public:
{
SetBackgroundStyle(wxBG_STYLE_PAINT);
m_rect = wxRect(wxPoint(legend_side,0),rect.GetSize()-wxSize(legend_side,legend_side));
visible_area = wxRect2DDouble(0.0, 0.0, sampling*ramming_speed_size, 20.);
visible_area = wxRect2DDouble(0.0, 0.0, sampling*ramming_speed_size, 40.);
m_buttons.clear();
if (initial_buttons.size()>0)
for (const auto& pair : initial_buttons)
@ -31,7 +31,7 @@ public:
recalculate_line();
}
void set_xy_range(float x,float y) {
x = int(x/0.5) * 0.5;
x = int(x/0.25) * 0.25;
if (x>=0) visible_area.SetRight(x);
if (y>=0) visible_area.SetBottom(y);
recalculate_line();
@ -104,20 +104,18 @@ private:
}
return (-1);
}
void recalculate_line();
void recalculate_volume();
wxRect m_rect; // rectangle on screen the chart is mapped into (screen coordinates)
wxPoint m_previous_mouse;
std::vector<ButtonToDrag> m_buttons;
std::vector<int> m_line_to_draw;
wxRect2DDouble visible_area;
ButtonToDrag* m_dragged = nullptr;
float m_total_volume = 0.f;
float m_total_volume = 0.f;
bool m_uniform = false; // testing only
};

View File

@ -8,6 +8,7 @@
#include "BitmapCache.hpp"
#include "GUI.hpp"
#include "I18N.hpp"
#include "slic3r/GUI/format.hpp"
#include "GUI_App.hpp"
#include "MsgDialog.hpp"
@ -109,11 +110,11 @@ RammingPanel::RammingPanel(wxWindow* parent, const std::string& parameters)
#endif
sizer_chart->Add(m_chart, 0, wxALL, 5);
m_widget_time = new ::SpinInputDouble(this,"", wxEmptyString, wxDefaultPosition, wxSize(ITEM_WIDTH(), -1), style, 0., 5., 3., 0.5);
m_widget_time = new ::SpinInputDouble(this,"", wxEmptyString, wxDefaultPosition, wxSize(ITEM_WIDTH(), -1), style, 0., 5., 3., 0.25);
m_widget_time->SetDigits(2);
m_widget_volume = new ::SpinInput(this,"",wxEmptyString,wxDefaultPosition,wxSize(ITEM_WIDTH(), -1),style,0,10000,0);
m_widget_ramming_line_width_multiplicator = new ::SpinInput(this,"",wxEmptyString,wxDefaultPosition,wxSize(ITEM_WIDTH(), -1),style,10,200,100);
m_widget_ramming_step_multiplicator = new ::SpinInput(this,"",wxEmptyString,wxDefaultPosition,wxSize(ITEM_WIDTH(), -1),style,10,200,100);
m_widget_ramming_line_width_multiplicator = new ::SpinInput(this,"",wxEmptyString,wxDefaultPosition,wxSize(ITEM_WIDTH(), -1),style,10,300,100);
m_widget_ramming_step_multiplicator = new ::SpinInput(this,"",wxEmptyString,wxDefaultPosition,wxSize(ITEM_WIDTH(), -1),style,10,300,100);
#ifdef _WIN32
update_ui(m_widget_time->GetText());
@ -133,6 +134,15 @@ RammingPanel::RammingPanel(wxWindow* parent, const std::string& parameters)
gsizer_param->Add(m_widget_ramming_line_width_multiplicator);
gsizer_param->Add(new wxStaticText(this, wxID_ANY, wxString(_(L("Ramming line spacing")) + " (%):")), 0, wxALIGN_CENTER_VERTICAL);
gsizer_param->Add(m_widget_ramming_step_multiplicator);
gsizer_param->AddSpacer(40);
gsizer_param->AddSpacer(40);
std::string ctrl_str = shortkey_ctrl_prefix();
if (! ctrl_str.empty() && ctrl_str.back() == '+')
ctrl_str.pop_back();
// TRN: The placeholder expands to Ctrl or Cmd (on macOS).
gsizer_param->Add(new wxStaticText(this, wxID_ANY, format_wxstr(_L("For constant flow rate, hold %1% while dragging."), ctrl_str)), 0, wxALIGN_CENTER_VERTICAL);
sizer_param->Add(gsizer_param, 0, wxTOP, scale(10));