2018-03-01 09:19:34 +01:00
#include <algorithm>
2018-03-15 14:04:12 +01:00
#include <sstream>
2018-02-28 16:04:56 +01:00
#include "WipeTowerDialog.hpp"
2018-06-07 22:10:23 +02:00
#include "GUI.hpp"
2018-11-26 14:41:58 +01:00
#include "I18N.hpp"
2018-02-28 16:04:56 +01:00
2018-03-22 13:07:45 +01:00
#include <wx/sizer.h>
2018-03-15 14:04:12 +01:00
RammingDialog :: RammingDialog ( wxWindow * parent , const std :: string & parameters )
2018-03-29 12:04:09 +02:00
: wxDialog ( parent , wxID_ANY , _ ( L ( "Ramming customization" )), wxDefaultPosition , wxDefaultSize , wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/ )
2018-03-13 15:54:29 +01:00
{
2018-03-15 14:04:12 +01:00
m_panel_ramming = new RammingPanel ( this , parameters );
2018-04-10 10:50:18 +02:00
// Not found another way of getting the background colours of RammingDialog, RammingPanel and Chart correct than setting
// them all explicitely. Reading the parent colour yielded colour that didn't really match it, no wxSYS_COLOUR_... matched
// colour used for the dialog. Same issue (and "solution") here : https://forums.wxwidgets.org/viewtopic.php?f=1&t=39608
// Whoever can fix this, feel free to do so.
this -> SetBackgroundColour ( wxSystemSettings :: GetColour ( wxSYS_COLOUR_FRAMEBK ));
m_panel_ramming -> SetBackgroundColour ( wxSystemSettings :: GetColour ( wxSYS_COLOUR_FRAMEBK ));
2018-03-13 15:54:29 +01:00
m_panel_ramming -> Show ( true );
this -> Show ();
auto main_sizer = new wxBoxSizer ( wxVERTICAL );
2018-03-28 20:31:36 +02:00
main_sizer -> Add ( m_panel_ramming , 1 , wxEXPAND | wxTOP | wxLEFT | wxRIGHT , 5 );
main_sizer -> Add ( CreateButtonSizer ( wxOK | wxCANCEL ), 0 , wxALIGN_CENTER_HORIZONTAL | wxTOP | wxBOTTOM , 10 );
2018-03-13 15:54:29 +01:00
SetSizer ( main_sizer );
main_sizer -> SetSizeHints ( this );
2018-03-22 13:07:45 +01:00
2018-03-13 15:54:29 +01:00
this -> Bind ( wxEVT_CLOSE_WINDOW , [ this ]( wxCloseEvent & e ) { EndModal ( wxCANCEL ); });
2018-03-22 13:07:45 +01:00
2018-03-13 15:54:29 +01:00
this -> Bind ( wxEVT_BUTTON ,[ this ]( wxCommandEvent & ) {
2018-03-15 14:04:12 +01:00
m_output_data = m_panel_ramming -> get_parameters ();
2018-03-13 15:54:29 +01:00
EndModal ( wxID_OK );
}, wxID_OK );
2018-03-29 14:23:45 +02:00
this -> Show ();
2018-04-03 22:07:59 +02:00
wxMessageDialog ( this , _ ( L ( "Ramming denotes the rapid extrusion just before a tool change in a single-extruder MM printer. Its purpose is to "
2018-03-29 14:23:45 +02:00
"properly shape the end of the unloaded filament so it does not prevent insertion of the new filament and can itself "
"be reinserted later. This phase is important and different materials can require different extrusion speeds to get "
"the good shape. For this reason, the extrusion rates during ramming are adjustable. \n\n This is an expert-level "
2018-04-03 22:07:59 +02:00
"setting, incorrect adjustment will likely lead to jams, extruder wheel grinding into filament etc." )), _ ( L ( "Warning" )), wxOK | wxICON_EXCLAMATION ). ShowModal ();
2018-03-13 15:54:29 +01:00
}
2018-02-28 16:04:56 +01:00
2018-03-15 14:04:12 +01:00
RammingPanel :: RammingPanel ( wxWindow * parent , const std :: string & parameters )
2018-03-29 12:04:09 +02:00
: wxPanel ( parent , wxID_ANY , wxDefaultPosition , wxDefaultSize /*,wxPoint(50,50), wxSize(800,350),wxBORDER_RAISED*/ )
2018-02-28 16:04:56 +01:00
{
2018-03-28 20:31:36 +02:00
auto sizer_chart = new wxBoxSizer ( wxVERTICAL );
auto sizer_param = new wxBoxSizer ( wxVERTICAL );
std :: stringstream stream { parameters };
stream >> m_ramming_line_width_multiplicator >> m_ramming_step_multiplicator ;
int ramming_speed_size = 0 ;
float dummy = 0.f ;
while ( stream >> dummy )
++ ramming_speed_size ;
stream . clear ();
stream . get ();
std :: vector < std :: pair < float , float >> buttons ;
float x = 0.f ;
float y = 0.f ;
while ( stream >> x >> y )
buttons . push_back ( std :: make_pair ( x , y ));
m_chart = new Chart ( this , wxRect ( 10 , 10 , 480 , 360 ), buttons , ramming_speed_size , 0.25f );
2018-04-10 10:50:18 +02:00
m_chart -> SetBackgroundColour ( parent -> GetBackgroundColour ()); // see comment in RammingDialog constructor
2018-03-28 20:31:36 +02:00
sizer_chart -> Add ( m_chart , 0 , wxALL , 5 );
m_widget_time = new wxSpinCtrlDouble ( this , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 75 , - 1 ), wxSP_ARROW_KEYS , 0. , 5.0 , 3. , 0.5 );
m_widget_volume = new wxSpinCtrl ( this , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 75 , - 1 ), wxSP_ARROW_KEYS , 0 , 10000 , 0 );
m_widget_ramming_line_width_multiplicator = new wxSpinCtrl ( this , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 75 , - 1 ), wxSP_ARROW_KEYS , 10 , 200 , 100 );
m_widget_ramming_step_multiplicator = new wxSpinCtrl ( this , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 75 , - 1 ), wxSP_ARROW_KEYS , 10 , 200 , 100 );
auto gsizer_param = new wxFlexGridSizer ( 2 , 5 , 15 );
2018-05-02 13:20:36 +02:00
gsizer_param -> Add ( new wxStaticText ( this , wxID_ANY , wxString ( _ ( L ( "Total ramming time" )) + " (" + _ ( L ( "s" )) + "):" )), 0 , wxALIGN_CENTER_VERTICAL );
2018-03-28 20:31:36 +02:00
gsizer_param -> Add ( m_widget_time );
2018-06-07 22:10:23 +02:00
gsizer_param -> Add ( new wxStaticText ( this , wxID_ANY , wxString ( _ ( L ( "Total rammed volume" )) + " (" + _ ( L ( "mm" )) + wxString ( "³):" , wxConvUTF8 ))), 0 , wxALIGN_CENTER_VERTICAL );
2018-03-28 20:31:36 +02:00
gsizer_param -> Add ( m_widget_volume );
gsizer_param -> AddSpacer ( 20 );
gsizer_param -> AddSpacer ( 20 );
2018-05-02 13:20:36 +02:00
gsizer_param -> Add ( new wxStaticText ( this , wxID_ANY , wxString ( _ ( L ( "Ramming line width" )) + " (%):" )), 0 , wxALIGN_CENTER_VERTICAL );
2018-03-28 20:31:36 +02:00
gsizer_param -> Add ( m_widget_ramming_line_width_multiplicator );
2018-05-02 13:20:36 +02:00
gsizer_param -> Add ( new wxStaticText ( this , wxID_ANY , wxString ( _ ( L ( "Ramming line spacing" )) + " (%):" )), 0 , wxALIGN_CENTER_VERTICAL );
2018-03-28 20:31:36 +02:00
gsizer_param -> Add ( m_widget_ramming_step_multiplicator );
sizer_param -> Add ( gsizer_param , 0 , wxTOP , 100 );
2018-02-28 16:04:56 +01:00
m_widget_time -> SetValue ( m_chart -> get_time ());
m_widget_time -> SetDigits ( 2 );
m_widget_volume -> SetValue ( m_chart -> get_volume ());
m_widget_volume -> Disable ();
2018-03-13 15:54:29 +01:00
m_widget_ramming_line_width_multiplicator -> SetValue ( m_ramming_line_width_multiplicator );
m_widget_ramming_step_multiplicator -> SetValue ( m_ramming_step_multiplicator );
2018-02-28 16:04:56 +01:00
m_widget_ramming_step_multiplicator -> Bind ( wxEVT_TEXT ,[ this ]( wxCommandEvent & ) { line_parameters_changed (); });
m_widget_ramming_line_width_multiplicator -> Bind ( wxEVT_TEXT ,[ this ]( wxCommandEvent & ) { line_parameters_changed (); });
2018-03-28 20:31:36 +02:00
auto sizer = new wxBoxSizer ( wxHORIZONTAL );
sizer -> Add ( sizer_chart , 0 , wxALL , 5 );
sizer -> Add ( sizer_param , 0 , wxALL , 10 );
sizer -> SetSizeHints ( this );
SetSizer ( sizer );
2018-02-28 16:04:56 +01:00
m_widget_time -> Bind ( wxEVT_TEXT ,[ this ]( wxCommandEvent & ) { m_chart -> set_xy_range ( m_widget_time -> GetValue (), - 1 );});
m_widget_time -> Bind ( wxEVT_CHAR ,[]( wxKeyEvent & ){}); // do nothing - prevents the user to change the value
m_widget_volume -> Bind ( wxEVT_CHAR ,[]( wxKeyEvent & ){}); // do nothing - prevents the user to change the value
2018-03-13 15:54:29 +01:00
Bind ( EVT_WIPE_TOWER_CHART_CHANGED ,[ this ]( wxCommandEvent & ) { m_widget_volume -> SetValue ( m_chart -> get_volume ()); m_widget_time -> SetValue ( m_chart -> get_time ());} );
2018-11-07 14:57:50 +01:00
Refresh ( true ); // erase background
2018-02-28 16:04:56 +01:00
}
void RammingPanel :: line_parameters_changed () {
2018-03-13 15:54:29 +01:00
m_ramming_line_width_multiplicator = m_widget_ramming_line_width_multiplicator -> GetValue ();
m_ramming_step_multiplicator = m_widget_ramming_step_multiplicator -> GetValue ();
2018-02-28 16:04:56 +01:00
}
2018-03-15 14:04:12 +01:00
std :: string RammingPanel :: get_parameters ()
{
std :: vector < float > speeds = m_chart -> get_ramming_speed ( 0.25f );
std :: vector < std :: pair < float , float >> buttons = m_chart -> get_buttons ();
std :: stringstream stream ;
stream << m_ramming_line_width_multiplicator << " " << m_ramming_step_multiplicator ;
for ( const float & speed_value : speeds )
stream << " " << speed_value ;
stream << "|" ;
for ( const auto & button : buttons )
stream << " " << button . first << " " << button . second ;
return stream . str ();
}
2018-02-28 16:04:56 +01:00
2018-03-28 02:17:51 +02:00
#define ITEM_WIDTH 60
2018-03-22 13:07:45 +01:00
// Parent dialog for purging volume adjustments - it fathers WipingPanel widget (that contains all controls) and a button to toggle simple/advanced mode:
2018-03-20 13:50:51 +01:00
WipingDialog :: WipingDialog ( wxWindow * parent , const std :: vector < float >& matrix , const std :: vector < float >& extruders )
2018-03-29 12:04:09 +02:00
: wxDialog ( parent , wxID_ANY , _ ( L ( "Wipe tower - Purging volume adjustment" )), wxDefaultPosition , wxDefaultSize , wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/ )
2018-03-15 14:04:12 +01:00
{
2018-03-22 13:07:45 +01:00
auto widget_button = new wxButton ( this , wxID_ANY , "-" , wxPoint ( 0 , 0 ), wxDefaultSize );
m_panel_wiping = new WipingPanel ( this , matrix , extruders , widget_button );
2018-03-15 14:04:12 +01:00
auto main_sizer = new wxBoxSizer ( wxVERTICAL );
2018-03-22 13:07:45 +01:00
2018-03-28 02:17:51 +02:00
// set min sizer width according to extruders count
const auto sizer_width = ( int )(( sqrt ( matrix . size ()) + 2.8 ) * ITEM_WIDTH );
main_sizer -> SetMinSize ( wxSize ( sizer_width , - 1 ));
2018-03-22 13:07:45 +01:00
2018-03-28 02:17:51 +02:00
main_sizer -> Add ( m_panel_wiping , 0 , wxEXPAND | wxALL , 5 );
main_sizer -> Add ( widget_button , 0 , wxALIGN_CENTER_HORIZONTAL | wxCENTER | wxBOTTOM , 5 );
2018-03-15 14:04:12 +01:00
main_sizer -> Add ( CreateButtonSizer ( wxOK | wxCANCEL ), 0 , wxALIGN_CENTER_HORIZONTAL | wxBOTTOM , 10 );
SetSizer ( main_sizer );
main_sizer -> SetSizeHints ( this );
2018-03-22 13:07:45 +01:00
2018-03-15 14:04:12 +01:00
this -> Bind ( wxEVT_CLOSE_WINDOW , [ this ]( wxCloseEvent & e ) { EndModal ( wxCANCEL ); });
2018-03-22 13:07:45 +01:00
this -> Bind ( wxEVT_BUTTON ,[ this ]( wxCommandEvent & ) { // if OK button is clicked..
m_output_matrix = m_panel_wiping -> read_matrix_values (); // ..query wiping panel and save returned values
m_output_extruders = m_panel_wiping -> read_extruders_values (); // so they can be recovered later by calling get_...()
2018-03-15 14:04:12 +01:00
EndModal ( wxID_OK );
}, wxID_OK );
2018-03-22 13:07:45 +01:00
this -> Show ();
2018-03-15 14:04:12 +01:00
}
2018-03-28 02:17:51 +02:00
// This function allows to "play" with sizers parameters (like align or border)
void WipingPanel :: format_sizer ( wxSizer * sizer , wxPanel * page , wxGridSizer * grid_sizer , const wxString & info , const wxString & table_title , int table_lshift /*=0*/ )
{
2018-03-29 12:04:09 +02:00
sizer -> Add ( new wxStaticText ( page , wxID_ANY , info , wxDefaultPosition , wxSize ( 0 , 50 )), 0 , wxEXPAND | wxLEFT , 15 );
2018-03-28 02:17:51 +02:00
auto table_sizer = new wxBoxSizer ( wxVERTICAL );
2018-03-29 12:04:09 +02:00
sizer -> Add ( table_sizer , 0 , wxALIGN_CENTER | wxCENTER , table_lshift );
2018-03-28 02:17:51 +02:00
table_sizer -> Add ( new wxStaticText ( page , wxID_ANY , table_title ), 0 , wxALIGN_CENTER | wxTOP , 50 );
table_sizer -> Add ( grid_sizer , 0 , wxALIGN_CENTER | wxTOP , 10 );
}
2018-03-15 14:04:12 +01:00
2018-03-22 13:07:45 +01:00
// This panel contains all control widgets for both simple and advanced mode (these reside in separate sizers)
WipingPanel :: WipingPanel ( wxWindow * parent , const std :: vector < float >& matrix , const std :: vector < float >& extruders , wxButton * widget_button )
2018-03-29 12:04:09 +02:00
: wxPanel ( parent , wxID_ANY , wxDefaultPosition , wxDefaultSize /*,wxBORDER_RAISED*/ )
2018-02-28 16:04:56 +01:00
{
2018-03-22 13:07:45 +01:00
m_widget_button = widget_button ; // pointer to the button in parent dialog
m_widget_button -> Bind ( wxEVT_BUTTON ,[ this ]( wxCommandEvent & ){ toggle_advanced ( true ); });
m_number_of_extruders = ( int )( sqrt ( matrix . size ()) + 0.001 );
2018-03-28 02:17:51 +02:00
// Create two switched panels with their own sizers
2018-03-22 13:07:45 +01:00
m_sizer_simple = new wxBoxSizer ( wxVERTICAL );
m_sizer_advanced = new wxBoxSizer ( wxVERTICAL );
2018-03-28 02:17:51 +02:00
m_page_simple = new wxPanel ( this , wxID_ANY , wxDefaultPosition , wxDefaultSize , wxTAB_TRAVERSAL );
m_page_advanced = new wxPanel ( this , wxID_ANY , wxDefaultPosition , wxDefaultSize , wxTAB_TRAVERSAL );
m_page_simple -> SetSizer ( m_sizer_simple );
m_page_advanced -> SetSizer ( m_sizer_advanced );
2018-03-22 13:07:45 +01:00
2018-03-28 02:17:51 +02:00
auto gridsizer_simple = new wxGridSizer ( 3 , 5 , 10 );
2018-03-29 14:23:45 +02:00
m_gridsizer_advanced = new wxGridSizer ( m_number_of_extruders + 1 , 5 , 1 );
2018-03-22 13:07:45 +01:00
2018-03-28 02:17:51 +02:00
// First create controls for advanced mode and assign them to m_page_advanced:
for ( unsigned int i = 0 ; i < m_number_of_extruders ; ++ i ) {
edit_boxes . push_back ( std :: vector < wxTextCtrl *> ( 0 ));
2018-03-22 13:07:45 +01:00
2018-03-28 02:17:51 +02:00
for ( unsigned int j = 0 ; j < m_number_of_extruders ; ++ j ) {
edit_boxes . back (). push_back ( new wxTextCtrl ( m_page_advanced , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( ITEM_WIDTH , - 1 )));
if ( i == j )
edit_boxes [ i ][ j ] -> Disable ();
else
edit_boxes [ i ][ j ] -> SetValue ( wxString ( "" ) << int ( matrix [ m_number_of_extruders * j + i ]));
}
}
2018-03-29 14:23:45 +02:00
m_gridsizer_advanced -> Add ( new wxStaticText ( m_page_advanced , wxID_ANY , wxString ( "" )));
2018-03-28 02:17:51 +02:00
for ( unsigned int i = 0 ; i < m_number_of_extruders ; ++ i )
2018-03-29 14:23:45 +02:00
m_gridsizer_advanced -> Add ( new wxStaticText ( m_page_advanced , wxID_ANY , wxString ( "" ) << i + 1 ), 0 , wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL );
2018-03-28 02:17:51 +02:00
for ( unsigned int i = 0 ; i < m_number_of_extruders ; ++ i ) {
2018-03-29 14:23:45 +02:00
m_gridsizer_advanced -> Add ( new wxStaticText ( m_page_advanced , wxID_ANY , wxString ( "" ) << i + 1 ), 0 , wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL );
2018-03-28 02:17:51 +02:00
for ( unsigned int j = 0 ; j < m_number_of_extruders ; ++ j )
2018-03-29 14:23:45 +02:00
m_gridsizer_advanced -> Add ( edit_boxes [ j ][ i ], 0 );
2018-03-28 02:17:51 +02:00
}
2018-03-20 13:50:51 +01:00
2018-03-28 02:17:51 +02:00
// collect and format sizer
2018-03-29 14:23:45 +02:00
format_sizer ( m_sizer_advanced , m_page_advanced , m_gridsizer_advanced ,
2018-06-07 22:10:23 +02:00
_ ( L ( "Here you can adjust required purging volume (mm³) for any given pair of tools." )),
2018-03-29 12:04:09 +02:00
_ ( L ( "Extruder changed to" )));
2018-03-20 13:50:51 +01:00
2018-03-28 02:17:51 +02:00
// Hide preview page before new page creating
// It allows to do that from a beginning of the main panel
m_page_advanced -> Hide ();
2018-03-22 13:07:45 +01:00
2018-03-28 02:17:51 +02:00
// Now the same for simple mode:
gridsizer_simple -> Add ( new wxStaticText ( m_page_simple , wxID_ANY , wxString ( "" )), 0 , wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL );
gridsizer_simple -> Add ( new wxStaticText ( m_page_simple , wxID_ANY , wxString ( _ ( L ( "unloaded" )))), 0 , wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL );
gridsizer_simple -> Add ( new wxStaticText ( m_page_simple , wxID_ANY , wxString ( _ ( L ( "loaded" )))), 0 , wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL );
2018-03-22 13:07:45 +01:00
2018-03-28 02:17:51 +02:00
for ( unsigned int i = 0 ; i < m_number_of_extruders ; ++ i ) {
m_old . push_back ( new wxSpinCtrl ( m_page_simple , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 80 , - 1 ), wxSP_ARROW_KEYS | wxALIGN_RIGHT , 0 , 300 , extruders [ 2 * i ]));
m_new . push_back ( new wxSpinCtrl ( m_page_simple , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 80 , - 1 ), wxSP_ARROW_KEYS | wxALIGN_RIGHT , 0 , 300 , extruders [ 2 * i + 1 ]));
gridsizer_simple -> Add ( new wxStaticText ( m_page_simple , wxID_ANY , wxString ( _ ( L ( "Tool #" ))) << i + 1 << ": " ), 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
gridsizer_simple -> Add ( m_old . back (), 0 );
gridsizer_simple -> Add ( m_new . back (), 0 );
}
2018-03-20 13:50:51 +01:00
2018-03-28 02:17:51 +02:00
// collect and format sizer
format_sizer ( m_sizer_simple , m_page_simple , gridsizer_simple ,
_ ( L ( "Total purging volume is calculated by summing two values below, depending on which tools are loaded/unloaded." )),
2018-06-07 22:10:23 +02:00
_ ( L ( "Volume to purge (mm³) when the filament is being" )), 50 );
2018-03-22 13:07:45 +01:00
2018-03-28 02:17:51 +02:00
m_sizer = new wxBoxSizer ( wxVERTICAL );
m_sizer -> Add ( m_page_simple , 0 , wxEXPAND | wxALL , 25 );
m_sizer -> Add ( m_page_advanced , 0 , wxEXPAND | wxALL , 25 );
m_sizer -> SetSizeHints ( this );
SetSizer ( m_sizer );
2018-03-22 13:07:45 +01:00
toggle_advanced (); // to show/hide what is appropriate
2018-03-29 12:04:09 +02:00
m_page_advanced -> Bind ( wxEVT_PAINT ,[ this ]( wxPaintEvent & ) {
wxPaintDC dc ( m_page_advanced );
int y_pos = 0.5 * ( edit_boxes [ 0 ][ 0 ] -> GetPosition (). y + edit_boxes [ 0 ][ edit_boxes . size () - 1 ] -> GetPosition (). y + edit_boxes [ 0 ][ edit_boxes . size () - 1 ] -> GetSize (). y );
2018-04-03 22:07:59 +02:00
wxString label = _ ( L ( "From" ));
2018-03-29 12:04:09 +02:00
int text_width = 0 ;
int text_height = 0 ;
dc . GetTextExtent ( label , & text_width , & text_height );
2018-03-29 14:23:45 +02:00
int xpos = m_gridsizer_advanced -> GetPosition (). x ;
dc . DrawRotatedText ( label , xpos - text_height , y_pos + text_width / 2.f , 90 );
2018-03-29 12:04:09 +02:00
});
2018-02-28 16:04:56 +01:00
}
2018-03-20 13:50:51 +01:00
2018-03-22 13:07:45 +01:00
// Reads values from the (advanced) wiping matrix:
2018-03-20 13:50:51 +01:00
std :: vector < float > WipingPanel :: read_matrix_values () {
if ( ! m_advanced )
fill_in_matrix ();
std :: vector < float > output ;
for ( unsigned int i = 0 ; i < m_number_of_extruders ; ++ i ) {
for ( unsigned int j = 0 ; j < m_number_of_extruders ; ++ j ) {
double val = 0. ;
edit_boxes [ j ][ i ] -> GetValue (). ToDouble ( & val );
output . push_back (( float ) val );
}
}
return output ;
}
2018-03-22 13:07:45 +01:00
// Reads values from simple mode to save them for next time:
2018-03-20 13:50:51 +01:00
std :: vector < float > WipingPanel :: read_extruders_values () {
std :: vector < float > output ;
for ( unsigned int i = 0 ; i < m_number_of_extruders ; ++ i ) {
output . push_back ( m_old [ i ] -> GetValue ());
output . push_back ( m_new [ i ] -> GetValue ());
}
return output ;
}
2018-03-22 13:07:45 +01:00
// This updates the "advanced" matrix based on values from "simple" mode
2018-02-28 16:04:56 +01:00
void WipingPanel :: fill_in_matrix () {
2018-03-20 13:50:51 +01:00
for ( unsigned i = 0 ; i < m_number_of_extruders ; ++ i ) {
for ( unsigned j = 0 ; j < m_number_of_extruders ; ++ j ) {
2018-02-28 16:04:56 +01:00
if ( i == j ) continue ;
2018-03-20 13:50:51 +01:00
edit_boxes [ j ][ i ] -> SetValue ( wxString ( "" ) << ( m_old [ i ] -> GetValue () + m_new [ j ] -> GetValue ()));
2018-02-28 16:04:56 +01:00
}
}
}
2018-03-22 13:07:45 +01:00
// Function to check if simple and advanced settings are matching
2018-03-20 13:50:51 +01:00
bool WipingPanel :: advanced_matches_simple () {
for ( unsigned i = 0 ; i < m_number_of_extruders ; ++ i ) {
for ( unsigned j = 0 ; j < m_number_of_extruders ; ++ j ) {
if ( i == j ) continue ;
if ( edit_boxes [ j ][ i ] -> GetValue () != ( wxString ( "" ) << ( m_old [ i ] -> GetValue () + m_new [ j ] -> GetValue ())))
return false ;
}
}
return true ;
}
2018-02-28 16:04:56 +01:00
2018-03-22 13:07:45 +01:00
// Switches the dialog from simple to advanced mode and vice versa
void WipingPanel :: toggle_advanced ( bool user_action ) {
if ( m_advanced && ! advanced_matches_simple () && user_action ) {
2018-04-03 22:07:59 +02:00
if ( wxMessageDialog ( this , wxString ( _ ( L ( "Switching to simple settings will discard changes done in the advanced mode! \n\n Do you want to proceed?" ))),
wxString ( _ ( L ( "Warning" ))), wxYES_NO | wxICON_EXCLAMATION ). ShowModal () != wxID_YES )
2018-03-20 13:50:51 +01:00
return ;
}
2018-03-22 13:07:45 +01:00
if ( user_action )
m_advanced = ! m_advanced ; // user demands a change -> toggle
2018-03-28 02:17:51 +02:00
else
2018-03-22 13:07:45 +01:00
m_advanced = ! advanced_matches_simple (); // if called from constructor, show what is appropriate
2018-03-20 13:50:51 +01:00
2018-03-28 02:17:51 +02:00
( m_advanced ? m_page_advanced : m_page_simple ) -> Show ();
( ! m_advanced ? m_page_advanced : m_page_simple ) -> Hide ();
2018-03-20 13:50:51 +01:00
2018-04-03 22:07:59 +02:00
m_widget_button -> SetLabel ( m_advanced ? _ ( L ( "Show simplified settings" )) : _ ( L ( "Show advanced settings" )));
2018-03-22 13:07:45 +01:00
if ( m_advanced )
if ( user_action ) fill_in_matrix (); // otherwise keep values loaded from config
2018-03-20 13:50:51 +01:00
2018-03-28 02:17:51 +02:00
m_sizer -> Layout ();
Refresh ();
2018-03-29 09:47:12 +02:00
}