SimpleTab.pm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package Slic3r::GUI::SimpleTab;
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use File::Basename qw(basename);
  6. use List::Util qw(first);
  7. use Wx qw(:bookctrl :dialog :keycode :icon :id :misc :panel :sizer :window :systemsettings);
  8. use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN);
  9. use base 'Wx::ScrolledWindow';
  10. sub new {
  11. my $class = shift;
  12. my ($parent, %params) = @_;
  13. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
  14. $self->{options} = []; # array of option names handled by this tab
  15. $self->{$_} = $params{$_} for qw(on_value_change);
  16. $self->SetScrollbars(1, 1, 1, 1);
  17. $self->{config} = Slic3r::Config->new;
  18. $self->{optgroups} = [];
  19. $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
  20. $self->SetSizer($self->{vsizer});
  21. $self->build;
  22. {
  23. my $label = Wx::StaticText->new($self, -1, "Want more options? Switch to the Expert Mode.", wxDefaultPosition, wxDefaultSize);
  24. $label->SetFont(Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
  25. $self->{vsizer}->Add($label, 0, wxEXPAND | wxALL, 10);
  26. }
  27. return $self;
  28. }
  29. sub append_optgroup {
  30. my $self = shift;
  31. my %params = @_;
  32. # apply default values
  33. {
  34. my @options = @{$params{options}};
  35. $_ =~ s/#.+// for @options;
  36. my $config = Slic3r::Config->new_from_defaults(@options);
  37. $self->{config}->apply($config);
  38. }
  39. my $class = $params{class} || 'Slic3r::GUI::ConfigOptionsGroup';
  40. my $optgroup = $class->new(
  41. parent => $self,
  42. config => $self->{config},
  43. label_width => 200,
  44. on_change => sub { $self->on_value_change(@_) },
  45. %params,
  46. );
  47. push @{$self->{optgroups}}, $optgroup;
  48. ($params{sizer} || $self->{vsizer})->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);
  49. }
  50. sub load_config_file {
  51. my $self = shift;
  52. my ($file) = @_;
  53. my $config = Slic3r::Config->load($file);
  54. $self->load_config($config);
  55. }
  56. sub load_config {
  57. my $self = shift;
  58. my ($config) = @_;
  59. foreach my $opt_key (grep $self->{config}->has($_), @{$config->get_keys}) {
  60. my $value = $config->get($opt_key);
  61. $self->{config}->set($opt_key, $value);
  62. $_->set_value($opt_key, $value) for @{$self->{optgroups}};
  63. }
  64. }
  65. sub set_value {
  66. my $self = shift;
  67. my ($opt_key, $value) = @_;
  68. my $changed = 0;
  69. foreach my $optgroup (@{$self->{optgroups}}) {
  70. $changed = 1 if $optgroup->set_value($opt_key, $value);
  71. }
  72. return $changed;
  73. }
  74. sub is_dirty { 0 }
  75. sub config { $_[0]->{config}->clone }
  76. # propagate event to the parent
  77. sub on_value_change {
  78. my $self = shift;
  79. $self->{on_value_change}->(@_) if $self->{on_value_change};
  80. }
  81. package Slic3r::GUI::SimpleTab::Print;
  82. use base 'Slic3r::GUI::SimpleTab';
  83. use Wx qw(:sizer);
  84. sub name { 'print' }
  85. sub title { 'Print Settings' }
  86. sub build {
  87. my $self = shift;
  88. $self->append_optgroup(
  89. title => 'General',
  90. options => [qw(layer_height perimeters top_solid_layers bottom_solid_layers)],
  91. lines => [
  92. Slic3r::GUI::OptionsGroup->single_option_line('layer_height'),
  93. Slic3r::GUI::OptionsGroup->single_option_line('perimeters'),
  94. {
  95. label => 'Solid layers',
  96. options => [qw(top_solid_layers bottom_solid_layers)],
  97. },
  98. ],
  99. );
  100. $self->append_optgroup(
  101. title => 'Infill',
  102. options => [qw(fill_density fill_pattern)],
  103. );
  104. $self->append_optgroup(
  105. title => 'Support material',
  106. options => [qw(support_material support_material_spacing raft_layers)],
  107. );
  108. $self->append_optgroup(
  109. title => 'Speed',
  110. options => [qw(perimeter_speed infill_speed travel_speed)],
  111. );
  112. $self->append_optgroup(
  113. title => 'Brim',
  114. options => [qw(brim_width)],
  115. );
  116. $self->append_optgroup(
  117. title => 'Sequential printing',
  118. options => [qw(complete_objects extruder_clearance_radius extruder_clearance_height)],
  119. lines => [
  120. Slic3r::GUI::OptionsGroup->single_option_line('complete_objects'),
  121. {
  122. label => 'Extruder clearance (mm)',
  123. options => [qw(extruder_clearance_radius extruder_clearance_height)],
  124. },
  125. ],
  126. );
  127. }
  128. package Slic3r::GUI::SimpleTab::Filament;
  129. use base 'Slic3r::GUI::SimpleTab';
  130. sub name { 'filament' }
  131. sub title { 'Filament Settings' }
  132. sub build {
  133. my $self = shift;
  134. $self->append_optgroup(
  135. title => 'Filament',
  136. options => ['filament_diameter#0', 'extrusion_multiplier#0'],
  137. );
  138. $self->append_optgroup(
  139. title => 'Temperature (°C)',
  140. options => ['temperature#0', 'first_layer_temperature#0', qw(bed_temperature first_layer_bed_temperature)],
  141. lines => [
  142. {
  143. label => 'Extruder',
  144. options => ['first_layer_temperature#0', 'temperature#0'],
  145. },
  146. {
  147. label => 'Bed',
  148. options => [qw(first_layer_bed_temperature bed_temperature)],
  149. },
  150. ],
  151. );
  152. }
  153. package Slic3r::GUI::SimpleTab::Printer;
  154. use base 'Slic3r::GUI::SimpleTab';
  155. sub name { 'printer' }
  156. sub title { 'Printer Settings' }
  157. sub build {
  158. my $self = shift;
  159. $self->append_optgroup(
  160. title => 'Size and coordinates',
  161. options => [qw(bed_size z_offset)],
  162. );
  163. $self->append_optgroup(
  164. title => 'Firmware',
  165. options => [qw(gcode_flavor)],
  166. );
  167. $self->append_optgroup(
  168. title => 'Extruder',
  169. options => ['nozzle_diameter#0'],
  170. );
  171. $self->append_optgroup(
  172. title => 'Retraction',
  173. options => ['retract_length#0', 'retract_lift#0'],
  174. );
  175. $self->append_optgroup(
  176. title => 'Start G-code',
  177. no_labels => 1,
  178. options => [qw(start_gcode)],
  179. );
  180. $self->append_optgroup(
  181. title => 'End G-code',
  182. no_labels => 1,
  183. options => [qw(end_gcode)],
  184. );
  185. }
  186. 1;