ConfigWizard.pm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. # The config wizard is executed when the Slic3r is first started.
  2. # The wizard helps the user to specify the 3D printer properties.
  3. package Slic3r::GUI::ConfigWizard;
  4. use strict;
  5. use warnings;
  6. use utf8;
  7. use Wx;
  8. use base 'Wx::Wizard';
  9. use Slic3r::Geometry qw(unscale);
  10. # adhere to various human interface guidelines
  11. our $wizard = 'Wizard';
  12. $wizard = 'Assistant' if &Wx::wxMAC || &Wx::wxGTK;
  13. sub new {
  14. my $class = shift;
  15. my ($parent) = @_;
  16. my $self = $class->SUPER::new($parent, -1, "Configuration $wizard");
  17. # initialize an empty repository
  18. $self->{config} = Slic3r::Config->new;
  19. $self->add_page(Slic3r::GUI::ConfigWizard::Page::Welcome->new($self));
  20. $self->add_page(Slic3r::GUI::ConfigWizard::Page::Firmware->new($self));
  21. $self->add_page(Slic3r::GUI::ConfigWizard::Page::Bed->new($self));
  22. $self->add_page(Slic3r::GUI::ConfigWizard::Page::Nozzle->new($self));
  23. $self->add_page(Slic3r::GUI::ConfigWizard::Page::Filament->new($self));
  24. $self->add_page(Slic3r::GUI::ConfigWizard::Page::Temperature->new($self));
  25. $self->add_page(Slic3r::GUI::ConfigWizard::Page::BedTemperature->new($self));
  26. $self->add_page(Slic3r::GUI::ConfigWizard::Page::Finished->new($self));
  27. $_->build_index for @{$self->{pages}};
  28. return $self;
  29. }
  30. sub add_page {
  31. my $self = shift;
  32. my ($page) = @_;
  33. my $n = push @{$self->{pages}}, $page;
  34. # add first page to the page area sizer
  35. $self->GetPageAreaSizer->Add($page) if $n == 1;
  36. # link pages
  37. $self->{pages}[$n-2]->set_next_page($page) if $n >= 2;
  38. $page->set_previous_page($self->{pages}[$n-2]) if $n >= 2;
  39. }
  40. sub run {
  41. my $self = shift;
  42. if (Wx::Wizard::RunWizard($self, $self->{pages}[0])) {
  43. # it would be cleaner to have these defined inside each page class,
  44. # in some event getting called before leaving the page
  45. {
  46. # set first_layer_height + layer_height based on nozzle_diameter
  47. my $nozzle = $self->{config}->nozzle_diameter;
  48. $self->{config}->set('first_layer_height', $nozzle->[0]);
  49. $self->{config}->set('layer_height', $nozzle->[0] - 0.1);
  50. # set first_layer_temperature to temperature + 5
  51. $self->{config}->set('first_layer_temperature', [$self->{config}->temperature->[0] + 5]);
  52. # set first_layer_bed_temperature to temperature + 5
  53. $self->{config}->set('first_layer_bed_temperature',
  54. ($self->{config}->bed_temperature > 0) ? ($self->{config}->bed_temperature + 5) : 0);
  55. }
  56. $self->Destroy;
  57. return $self->{config};
  58. } else {
  59. $self->Destroy;
  60. return undef;
  61. }
  62. }
  63. package Slic3r::GUI::ConfigWizard::Index;
  64. use Wx qw(:bitmap :dc :font :misc :sizer :systemsettings :window);
  65. use Wx::Event qw(EVT_ERASE_BACKGROUND EVT_PAINT);
  66. use base 'Wx::Panel';
  67. sub new {
  68. my $class = shift;
  69. my ($parent, $title) = @_;
  70. my $self = $class->SUPER::new($parent);
  71. push @{$self->{titles}}, $title;
  72. $self->{own_index} = 0;
  73. $self->{bullets}->{before} = Wx::Bitmap->new($Slic3r::var->("bullet_black.png"), wxBITMAP_TYPE_PNG);
  74. $self->{bullets}->{own} = Wx::Bitmap->new($Slic3r::var->("bullet_blue.png"), wxBITMAP_TYPE_PNG);
  75. $self->{bullets}->{after} = Wx::Bitmap->new($Slic3r::var->("bullet_white.png"), wxBITMAP_TYPE_PNG);
  76. $self->{background} = Wx::Bitmap->new($Slic3r::var->("Slic3r_192px_transparent.png"), wxBITMAP_TYPE_PNG);
  77. $self->SetMinSize(Wx::Size->new($self->{background}->GetWidth, $self->{background}->GetHeight));
  78. EVT_PAINT($self, \&repaint);
  79. return $self;
  80. }
  81. sub repaint {
  82. my ($self, $event) = @_;
  83. my $size = $self->GetClientSize;
  84. my $gap = 5;
  85. my $dc = Wx::PaintDC->new($self);
  86. $dc->SetBackgroundMode(wxTRANSPARENT);
  87. $dc->SetFont($self->GetFont);
  88. $dc->SetTextForeground($self->GetForegroundColour);
  89. my $background_h = $self->{background}->GetHeight;
  90. my $background_w = $self->{background}->GetWidth;
  91. $dc->DrawBitmap($self->{background}, ($size->GetWidth - $background_w) / 2, ($size->GetHeight - $background_h) / 2, 1);
  92. my $label_h = $self->{bullets}->{own}->GetHeight;
  93. $label_h = $dc->GetCharHeight if $dc->GetCharHeight > $label_h;
  94. my $label_w = $size->GetWidth;
  95. my $i = 0;
  96. foreach (@{$self->{titles}}) {
  97. my $bullet = $self->{bullets}->{own};
  98. $bullet = $self->{bullets}->{before} if $i < $self->{own_index};
  99. $bullet = $self->{bullets}->{after} if $i > $self->{own_index};
  100. $dc->SetTextForeground(Wx::Colour->new(128, 128, 128)) if $i > $self->{own_index};
  101. $dc->DrawLabel($_, $bullet, Wx::Rect->new(0, $i * ($label_h + $gap), $label_w, $label_h));
  102. $i++;
  103. }
  104. $event->Skip;
  105. }
  106. sub prepend_title {
  107. my $self = shift;
  108. my ($title) = @_;
  109. unshift @{$self->{titles}}, $title;
  110. $self->{own_index}++;
  111. $self->Refresh;
  112. }
  113. sub append_title {
  114. my $self = shift;
  115. my ($title) = @_;
  116. push @{$self->{titles}}, $title;
  117. $self->Refresh;
  118. }
  119. package Slic3r::GUI::ConfigWizard::Page;
  120. use Wx qw(:font :misc :sizer :staticline :systemsettings);
  121. use base 'Wx::WizardPage';
  122. sub new {
  123. my $class = shift;
  124. my ($parent, $title, $short_title) = @_;
  125. my $self = $class->SUPER::new($parent);
  126. my $sizer = Wx::FlexGridSizer->new(0, 2, 10, 10);
  127. $sizer->AddGrowableCol(1, 1);
  128. $sizer->AddGrowableRow(1, 1);
  129. $sizer->AddStretchSpacer(0);
  130. $self->SetSizer($sizer);
  131. # title
  132. my $text = Wx::StaticText->new($self, -1, $title, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  133. my $bold_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
  134. $bold_font->SetWeight(wxFONTWEIGHT_BOLD);
  135. $bold_font->SetPointSize(14);
  136. $text->SetFont($bold_font);
  137. $sizer->Add($text, 0, wxALIGN_LEFT, 0);
  138. # index
  139. $self->{short_title} = $short_title ? $short_title : $title;
  140. $self->{index} = Slic3r::GUI::ConfigWizard::Index->new($self, $self->{short_title});
  141. $sizer->Add($self->{index}, 1, wxEXPAND | wxTOP | wxRIGHT, 10);
  142. # contents
  143. $self->{width} = 430;
  144. $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
  145. $sizer->Add($self->{vsizer}, 1);
  146. return $self;
  147. }
  148. sub append_text {
  149. my $self = shift;
  150. my ($text) = @_;
  151. my $para = Wx::StaticText->new($self, -1, $text, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  152. $para->Wrap($self->{width});
  153. $para->SetMinSize([$self->{width}, -1]);
  154. $self->{vsizer}->Add($para, 0, wxALIGN_LEFT | wxTOP | wxBOTTOM, 10);
  155. }
  156. sub append_option {
  157. my $self = shift;
  158. my ($full_key) = @_;
  159. # populate repository with the factory default
  160. my ($opt_key, $opt_index) = split /#/, $full_key, 2;
  161. $self->config->apply(Slic3r::Config->new_from_defaults($opt_key));
  162. # draw the control
  163. my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
  164. parent => $self,
  165. title => '',
  166. config => $self->config,
  167. full_labels => 1,
  168. );
  169. $optgroup->append_single_option_line($opt_key, $opt_index);
  170. $self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
  171. }
  172. sub append_panel {
  173. my ($self, $panel) = @_;
  174. $self->{vsizer}->Add($panel, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
  175. }
  176. sub set_previous_page {
  177. my $self = shift;
  178. my ($previous_page) = @_;
  179. $self->{previous_page} = $previous_page;
  180. }
  181. sub GetPrev {
  182. my $self = shift;
  183. return $self->{previous_page};
  184. }
  185. sub set_next_page {
  186. my $self = shift;
  187. my ($next_page) = @_;
  188. $self->{next_page} = $next_page;
  189. }
  190. sub GetNext {
  191. my $self = shift;
  192. return $self->{next_page};
  193. }
  194. sub get_short_title {
  195. my $self = shift;
  196. return $self->{short_title};
  197. }
  198. sub build_index {
  199. my $self = shift;
  200. my $page = $self;
  201. $self->{index}->prepend_title($page->get_short_title) while ($page = $page->GetPrev);
  202. $page = $self;
  203. $self->{index}->append_title($page->get_short_title) while ($page = $page->GetNext);
  204. }
  205. sub config {
  206. my ($self) = @_;
  207. return $self->GetParent->{config};
  208. }
  209. package Slic3r::GUI::ConfigWizard::Page::Welcome;
  210. use base 'Slic3r::GUI::ConfigWizard::Page';
  211. sub new {
  212. my $class = shift;
  213. my ($parent) = @_;
  214. my $self = $class->SUPER::new($parent, "Welcome to the Slic3r Configuration $wizard", 'Welcome');
  215. $self->append_text('Hello, welcome to Slic3r! This '.lc($wizard).' helps you with the initial configuration; just a few settings and you will be ready to print.');
  216. $self->append_text('To import an existing configuration instead, cancel this '.lc($wizard).' and use the Open Config menu item found in the File menu.');
  217. $self->append_text('To continue, click Next.');
  218. return $self;
  219. }
  220. package Slic3r::GUI::ConfigWizard::Page::Firmware;
  221. use base 'Slic3r::GUI::ConfigWizard::Page';
  222. sub new {
  223. my $class = shift;
  224. my ($parent) = @_;
  225. my $self = $class->SUPER::new($parent, 'Firmware Type');
  226. $self->append_text('Choose the type of firmware used by your printer, then click Next.');
  227. $self->append_option('gcode_flavor');
  228. return $self;
  229. }
  230. package Slic3r::GUI::ConfigWizard::Page::Bed;
  231. use base 'Slic3r::GUI::ConfigWizard::Page';
  232. sub new {
  233. my $class = shift;
  234. my ($parent) = @_;
  235. my $self = $class->SUPER::new($parent, 'Bed Size');
  236. $self->append_text('Set the shape of your printer\'s bed, then click Next.');
  237. $self->config->apply(Slic3r::Config->new_from_defaults('bed_shape'));
  238. $self->{bed_shape_panel} = my $panel = Slic3r::GUI::BedShapePanel->new($self, $self->config->bed_shape);
  239. $self->{bed_shape_panel}->on_change(sub {
  240. $self->config->set('bed_shape', $self->{bed_shape_panel}->GetValue);
  241. });
  242. $self->append_panel($self->{bed_shape_panel});
  243. return $self;
  244. }
  245. package Slic3r::GUI::ConfigWizard::Page::Nozzle;
  246. use base 'Slic3r::GUI::ConfigWizard::Page';
  247. sub new {
  248. my $class = shift;
  249. my ($parent) = @_;
  250. my $self = $class->SUPER::new($parent, 'Nozzle Diameter');
  251. $self->append_text('Enter the diameter of your printer\'s hot end nozzle, then click Next.');
  252. $self->append_option('nozzle_diameter#0');
  253. return $self;
  254. }
  255. package Slic3r::GUI::ConfigWizard::Page::Filament;
  256. use base 'Slic3r::GUI::ConfigWizard::Page';
  257. sub new {
  258. my $class = shift;
  259. my ($parent) = @_;
  260. my $self = $class->SUPER::new($parent, 'Filament Diameter');
  261. $self->append_text('Enter the diameter of your filament, then click Next.');
  262. $self->append_text('Good precision is required, so use a caliper and do multiple measurements along the filament, then compute the average.');
  263. $self->append_option('filament_diameter#0');
  264. return $self;
  265. }
  266. package Slic3r::GUI::ConfigWizard::Page::Temperature;
  267. use base 'Slic3r::GUI::ConfigWizard::Page';
  268. sub new {
  269. my $class = shift;
  270. my ($parent) = @_;
  271. my $self = $class->SUPER::new($parent, 'Extrusion Temperature');
  272. $self->append_text('Enter the temperature needed for extruding your filament, then click Next.');
  273. $self->append_text('A rule of thumb is 160 to 230 °C for PLA, and 215 to 250 °C for ABS.');
  274. $self->append_option('temperature#0');
  275. return $self;
  276. }
  277. package Slic3r::GUI::ConfigWizard::Page::BedTemperature;
  278. use base 'Slic3r::GUI::ConfigWizard::Page';
  279. sub new {
  280. my $class = shift;
  281. my ($parent) = @_;
  282. my $self = $class->SUPER::new($parent, 'Bed Temperature');
  283. $self->append_text('Enter the bed temperature needed for getting your filament to stick to your heated bed, then click Next.');
  284. $self->append_text('A rule of thumb is 60 °C for PLA and 110 °C for ABS. Leave zero if you have no heated bed.');
  285. $self->append_option('bed_temperature');
  286. return $self;
  287. }
  288. package Slic3r::GUI::ConfigWizard::Page::Finished;
  289. use base 'Slic3r::GUI::ConfigWizard::Page';
  290. sub new {
  291. my $class = shift;
  292. my ($parent) = @_;
  293. my $self = $class->SUPER::new($parent, 'Congratulations!', 'Finish');
  294. $self->append_text("You have successfully completed the Slic3r Configuration $wizard. " .
  295. 'Slic3r is now configured for your printer and filament.');
  296. $self->append_text('To close this '.lc($wizard).' and apply the newly created configuration, click Finish.');
  297. return $self;
  298. }
  299. 1;