SkeinPanel.pm 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package Slic3r::GUI::SkeinPanel;
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use File::Basename qw(basename);
  6. use Wx qw(:sizer :progressdialog wxOK wxICON_INFORMATION wxICON_WARNING wxICON_ERROR wxID_OK wxFD_OPEN
  7. wxFD_SAVE wxDEFAULT wxNORMAL);
  8. use Wx::Event qw(EVT_BUTTON);
  9. use base 'Wx::Panel';
  10. sub new {
  11. my $class = shift;
  12. my ($parent) = @_;
  13. my $self = $class->SUPER::new($parent, -1);
  14. my %panels = (
  15. printer => {
  16. title => 'Printer',
  17. options => [qw(nozzle_diameter print_center use_relative_e_distances no_extrusion z_offset)],
  18. },
  19. filament => {
  20. title => 'Filament',
  21. options => [qw(filament_diameter extrusion_multiplier temperature)],
  22. },
  23. print_speed => {
  24. title => 'Print speed',
  25. options => [qw(perimeter_feed_rate infill_feed_rate solid_infill_feed_rate bridge_feed_rate)],
  26. },
  27. speed => {
  28. title => 'Other speed settings',
  29. options => [qw(travel_feed_rate bottom_layer_speed_ratio)],
  30. },
  31. accuracy => {
  32. title => 'Accuracy',
  33. options => [qw(layer_height infill_every_layers)],
  34. },
  35. print => {
  36. title => 'Print settings',
  37. options => [qw(perimeters solid_layers fill_density fill_angle fill_pattern solid_fill_pattern)],
  38. },
  39. retract => {
  40. title => 'Retraction',
  41. options => [qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel)],
  42. },
  43. skirt => {
  44. title => 'Skirt',
  45. options => [qw(skirts skirt_distance skirt_height)],
  46. },
  47. transform => {
  48. title => 'Transform',
  49. options => [qw(scale rotate duplicate_x duplicate_y duplicate_distance)],
  50. },
  51. gcode => {
  52. title => 'Custom GCODE',
  53. options => [qw(start_gcode end_gcode)],
  54. },
  55. extrusion => {
  56. title => 'Extrusion',
  57. options => [qw(extrusion_width_ratio)],
  58. },
  59. );
  60. $self->{panels} = \%panels;
  61. my $tabpanel = Wx::Notebook->new($self, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, &Wx::wxNB_TOP);
  62. my $make_tab = sub {
  63. my @cols = @_;
  64. my $tab = Wx::Panel->new($tabpanel, -1);
  65. my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  66. foreach my $col (@cols) {
  67. my $vertical_sizer = Wx::BoxSizer->new(wxVERTICAL);
  68. for my $optgroup (@$col) {
  69. my $optpanel = Slic3r::GUI::OptionsGroup->new($tab, %{$panels{$optgroup}});
  70. $vertical_sizer->Add($optpanel, 0, wxEXPAND | wxALL, 10);
  71. }
  72. $sizer->Add($vertical_sizer);
  73. }
  74. $tab->SetSizer($sizer);
  75. return $tab;
  76. };
  77. my @tabs = (
  78. $make_tab->([qw(transform accuracy skirt)], [qw(print retract)]),
  79. $make_tab->([qw(printer filament)], [qw(print_speed speed)]),
  80. $make_tab->([qw(gcode)]),
  81. $make_tab->([qw(extrusion)]),
  82. );
  83. $tabpanel->AddPage($tabs[0], "Print Settings");
  84. $tabpanel->AddPage($tabs[1], "Printer and Filament");
  85. $tabpanel->AddPage($tabs[2], "Start/End GCODE");
  86. $tabpanel->AddPage($tabs[3], "Advanced");
  87. my $buttons_sizer;
  88. {
  89. $buttons_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  90. my $slice_button = Wx::Button->new($self, -1, "Slice...");
  91. $buttons_sizer->Add($slice_button, 0);
  92. EVT_BUTTON($self, $slice_button, \&do_slice);
  93. my $save_button = Wx::Button->new($self, -1, "Save configuration...");
  94. $buttons_sizer->Add($save_button, 0);
  95. EVT_BUTTON($self, $save_button, \&save_config);
  96. my $load_button = Wx::Button->new($self, -1, "Load configuration...");
  97. $buttons_sizer->Add($load_button, 0);
  98. EVT_BUTTON($self, $load_button, \&load_config);
  99. my $text = Wx::StaticText->new($self, -1, "Remember to check for updates at http://slic3r.org/\nVersion: $Slic3r::VERSION", Wx::wxDefaultPosition, Wx::wxDefaultSize, wxALIGN_RIGHT);
  100. my $font = Wx::Font->new(10, wxDEFAULT, wxNORMAL, wxNORMAL);
  101. $text->SetFont($font);
  102. $buttons_sizer->Add($text, 1, wxEXPAND | wxALIGN_RIGHT);
  103. }
  104. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  105. $sizer->Add($buttons_sizer, 0, wxEXPAND | wxALL, 10);
  106. $sizer->Add($tabpanel);
  107. $sizer->SetSizeHints($self);
  108. $self->SetSizer($sizer);
  109. $self->Layout;
  110. return $self;
  111. }
  112. sub do_slice {
  113. my $self = shift;
  114. my $process_dialog;
  115. eval {
  116. # validate configuration
  117. Slic3r::Config->validate;
  118. # select input file
  119. my $dialog = Wx::FileDialog->new($self, 'Choose a STL file to slice:', "", "", "STL files *.stl|*.stl;*.STL", wxFD_OPEN);
  120. return unless $dialog->ShowModal == wxID_OK;
  121. my ($input_file) = $dialog->GetPaths;
  122. my $input_file_basename = basename($input_file);
  123. # show processbar dialog
  124. $process_dialog = Wx::ProgressDialog->new('Slicing...', "Processing $input_file_basename...",
  125. 100, $self, wxPD_APP_MODAL);
  126. $process_dialog->Pulse;
  127. my $skein = Slic3r::Skein->new(
  128. input_file => $input_file,
  129. output_file => $main::opt{output},
  130. status_cb => sub {
  131. my ($percent, $message) = @_;
  132. if (&Wx::wxVERSION_STRING =~ / 2\.(8\.|9\.[2-9])/) {
  133. $process_dialog->Update($percent, $message);
  134. }
  135. },
  136. );
  137. {
  138. local $SIG{__WARN__} = sub {
  139. my $message = shift;
  140. Wx::MessageDialog->new($self, $message, 'Non-manifold object',
  141. wxOK | wxICON_WARNING)->ShowModal;
  142. };
  143. $skein->go;
  144. }
  145. $process_dialog->Destroy;
  146. undef $process_dialog;
  147. if (!$main::opt{close_after_slicing}) {
  148. my $message = sprintf "%s was successfully sliced in %d minutes and %.3f seconds.",
  149. $input_file_basename, int($skein->processing_time/60),
  150. $skein->processing_time - int($skein->processing_time/60)*60;
  151. Wx::MessageDialog->new($self, $message, 'Done!',
  152. wxOK | wxICON_INFORMATION)->ShowModal;
  153. } else {
  154. $self->GetParent->Destroy(); # quit
  155. }
  156. };
  157. $self->catch_error(sub { $process_dialog->Destroy if $process_dialog });
  158. }
  159. my $ini_wildcard = "INI files *.ini|*.ini;*.INI";
  160. sub save_config {
  161. my $self = shift;
  162. my $dlg = Wx::FileDialog->new($self, 'Save configuration as:', "", "config.ini",
  163. $ini_wildcard, wxFD_SAVE);
  164. if ($dlg->ShowModal == wxID_OK) {
  165. Slic3r::Config->save($dlg->GetPath);
  166. }
  167. }
  168. sub load_config {
  169. my $self = shift;
  170. my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', "", "config.ini",
  171. $ini_wildcard, wxFD_OPEN);
  172. if ($dlg->ShowModal == wxID_OK) {
  173. my ($file) = $dlg->GetPaths;
  174. eval {
  175. Slic3r::Config->load($file);
  176. };
  177. $self->catch_error();
  178. $_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks;
  179. }
  180. }
  181. sub catch_error {
  182. my ($self, $cb) = @_;
  183. if (my $err = $@) {
  184. $cb->() if $cb;
  185. Wx::MessageDialog->new($self, $err, 'Error', wxOK | wxICON_ERROR)->ShowModal;
  186. }
  187. }
  188. 1;