ConfigWizard.pm 12 KB

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