ConfigWizard.pm 12 KB

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