ConfigWizard.pm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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, $parent, $presets, $fresh_start) = @_;
  14. my $self = $class->SUPER::new($parent, -1, "Configuration $wizard");
  15. # initialize an empty repository
  16. $self->{config} = Slic3r::Config->new;
  17. my $welcome_page = Slic3r::GUI::ConfigWizard::Page::Welcome->new($self, $fresh_start);
  18. $self->add_page($welcome_page);
  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. $welcome_page->set_selection_presets([@{$presets}, 'Other']);
  28. return $self;
  29. }
  30. sub add_page {
  31. my ($self, $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) = @_;
  41. my $result;
  42. if (Wx::Wizard::RunWizard($self, $self->{pages}[0])) {
  43. my $preset_name = $self->{pages}[0]->{preset_name};
  44. $result = {
  45. preset_name => $preset_name,
  46. reset_user_profile => $self->{pages}[0]->{reset_user_profile}
  47. };
  48. if ($preset_name eq 'Other') {
  49. # it would be cleaner to have these defined inside each page class,
  50. # in some event getting called before leaving the page
  51. # set first_layer_height + layer_height based on nozzle_diameter
  52. my $nozzle = $self->{config}->nozzle_diameter;
  53. $self->{config}->set('first_layer_height', $nozzle->[0]);
  54. $self->{config}->set('layer_height', $nozzle->[0] - 0.1);
  55. # set first_layer_temperature to temperature + 5
  56. $self->{config}->set('first_layer_temperature', [$self->{config}->temperature->[0] + 5]);
  57. # set first_layer_bed_temperature to temperature + 5
  58. $self->{config}->set('first_layer_bed_temperature',
  59. [ ($self->{config}->bed_temperature->[0] > 0) ? ($self->{config}->bed_temperature->[0] + 5) : 0 ]);
  60. $result->{config} = $self->{config};
  61. }
  62. }
  63. $self->Destroy;
  64. return $result;
  65. }
  66. package Slic3r::GUI::ConfigWizard::Index;
  67. use Wx qw(:bitmap :dc :font :misc :sizer :systemsettings :window);
  68. use Wx::Event qw(EVT_ERASE_BACKGROUND EVT_PAINT);
  69. use base 'Wx::Panel';
  70. sub new {
  71. my $class = shift;
  72. my ($parent, $title) = @_;
  73. my $self = $class->SUPER::new($parent);
  74. push @{$self->{titles}}, $title;
  75. $self->{own_index} = 0;
  76. $self->{bullets}->{before} = Wx::Bitmap->new(Slic3r::var("bullet_black.png"), wxBITMAP_TYPE_PNG);
  77. $self->{bullets}->{own} = Wx::Bitmap->new(Slic3r::var("bullet_blue.png"), wxBITMAP_TYPE_PNG);
  78. $self->{bullets}->{after} = Wx::Bitmap->new(Slic3r::var("bullet_white.png"), wxBITMAP_TYPE_PNG);
  79. $self->{background} = Wx::Bitmap->new(Slic3r::var("Slic3r_192px_transparent.png"), wxBITMAP_TYPE_PNG);
  80. $self->SetMinSize(Wx::Size->new($self->{background}->GetWidth, $self->{background}->GetHeight));
  81. EVT_PAINT($self, \&repaint);
  82. return $self;
  83. }
  84. sub repaint {
  85. my ($self, $event) = @_;
  86. my $size = $self->GetClientSize;
  87. my $gap = 5;
  88. my $dc = Wx::PaintDC->new($self);
  89. $dc->SetBackgroundMode(wxTRANSPARENT);
  90. $dc->SetFont($self->GetFont);
  91. $dc->SetTextForeground($self->GetForegroundColour);
  92. my $background_h = $self->{background}->GetHeight;
  93. my $background_w = $self->{background}->GetWidth;
  94. $dc->DrawBitmap($self->{background}, ($size->GetWidth - $background_w) / 2, ($size->GetHeight - $background_h) / 2, 1);
  95. my $label_h = $self->{bullets}->{own}->GetHeight;
  96. $label_h = $dc->GetCharHeight if $dc->GetCharHeight > $label_h;
  97. my $label_w = $size->GetWidth;
  98. my $i = 0;
  99. foreach (@{$self->{titles}}) {
  100. my $bullet = $self->{bullets}->{own};
  101. $bullet = $self->{bullets}->{before} if $i < $self->{own_index};
  102. $bullet = $self->{bullets}->{after} if $i > $self->{own_index};
  103. $dc->SetTextForeground(Wx::Colour->new(128, 128, 128)) if $i > $self->{own_index};
  104. $dc->DrawLabel($_, $bullet, Wx::Rect->new(0, $i * ($label_h + $gap), $label_w, $label_h));
  105. # Only show the first bullet if this is the only wizard page to be displayed.
  106. last if $i == 0 && $self->{just_welcome};
  107. $i++;
  108. }
  109. $event->Skip;
  110. }
  111. sub prepend_title {
  112. my $self = shift;
  113. my ($title) = @_;
  114. unshift @{$self->{titles}}, $title;
  115. $self->{own_index}++;
  116. $self->Refresh;
  117. }
  118. sub append_title {
  119. my $self = shift;
  120. my ($title) = @_;
  121. push @{$self->{titles}}, $title;
  122. $self->Refresh;
  123. }
  124. package Slic3r::GUI::ConfigWizard::Page;
  125. use Wx qw(:font :misc :sizer :staticline :systemsettings);
  126. use base 'Wx::WizardPage';
  127. sub new {
  128. my $class = shift;
  129. my ($parent, $title, $short_title) = @_;
  130. my $self = $class->SUPER::new($parent);
  131. my $sizer = Wx::FlexGridSizer->new(0, 2, 10, 10);
  132. $sizer->AddGrowableCol(1, 1);
  133. $sizer->AddGrowableRow(1, 1);
  134. $sizer->AddStretchSpacer(0);
  135. $self->SetSizer($sizer);
  136. # title
  137. my $text = Wx::StaticText->new($self, -1, $title, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  138. my $bold_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
  139. $bold_font->SetWeight(wxFONTWEIGHT_BOLD);
  140. $bold_font->SetPointSize(14);
  141. $text->SetFont($bold_font);
  142. $sizer->Add($text, 0, wxALIGN_LEFT, 0);
  143. # index
  144. $self->{short_title} = $short_title ? $short_title : $title;
  145. $self->{index} = Slic3r::GUI::ConfigWizard::Index->new($self, $self->{short_title});
  146. $sizer->Add($self->{index}, 1, wxEXPAND | wxTOP | wxRIGHT, 10);
  147. # contents
  148. $self->{width} = 430;
  149. $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
  150. $sizer->Add($self->{vsizer}, 1);
  151. return $self;
  152. }
  153. sub append_text {
  154. my $self = shift;
  155. my ($text) = @_;
  156. my $para = Wx::StaticText->new($self, -1, $text, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  157. $para->Wrap($self->{width});
  158. $para->SetMinSize([$self->{width}, -1]);
  159. $self->{vsizer}->Add($para, 0, wxALIGN_LEFT | wxTOP | wxBOTTOM, 10);
  160. }
  161. sub append_option {
  162. my $self = shift;
  163. my ($full_key) = @_;
  164. # populate repository with the factory default
  165. my ($opt_key, $opt_index) = split /#/, $full_key, 2;
  166. $self->config->apply(Slic3r::Config::new_from_defaults_keys([$opt_key]));
  167. # draw the control
  168. my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
  169. parent => $self,
  170. title => '',
  171. config => $self->config,
  172. full_labels => 1,
  173. );
  174. $optgroup->append_single_option_line($opt_key, $opt_index);
  175. $self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
  176. }
  177. sub append_panel {
  178. my ($self, $panel) = @_;
  179. $self->{vsizer}->Add($panel, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
  180. }
  181. sub set_previous_page {
  182. my $self = shift;
  183. my ($previous_page) = @_;
  184. $self->{previous_page} = $previous_page;
  185. }
  186. sub GetPrev {
  187. my $self = shift;
  188. return $self->{previous_page};
  189. }
  190. sub set_next_page {
  191. my $self = shift;
  192. my ($next_page) = @_;
  193. $self->{next_page} = $next_page;
  194. }
  195. sub GetNext {
  196. my $self = shift;
  197. return $self->{next_page};
  198. }
  199. sub get_short_title {
  200. my $self = shift;
  201. return $self->{short_title};
  202. }
  203. sub build_index {
  204. my $self = shift;
  205. my $page = $self;
  206. $self->{index}->prepend_title($page->get_short_title) while ($page = $page->GetPrev);
  207. $page = $self;
  208. $self->{index}->append_title($page->get_short_title) while ($page = $page->GetNext);
  209. }
  210. sub config {
  211. my ($self) = @_;
  212. return $self->GetParent->{config};
  213. }
  214. package Slic3r::GUI::ConfigWizard::Page::Welcome;
  215. use base 'Slic3r::GUI::ConfigWizard::Page';
  216. use Wx qw(:misc :sizer wxID_FORWARD);
  217. use Wx::Event qw(EVT_ACTIVATE EVT_CHOICE EVT_CHECKBOX);
  218. sub new {
  219. my ($class, $parent, $fresh_start) = @_;
  220. my $self = $class->SUPER::new($parent, "Welcome to the Slic3r Configuration $wizard", 'Welcome');
  221. $self->{full_wizard_workflow} = 1;
  222. $self->{reset_user_profile} = 0;
  223. # Test for the existence of the old config path.
  224. my $message_has_legacy;
  225. {
  226. my $datadir = Slic3r::data_dir;
  227. if ($datadir =~ /Slic3rPE/) {
  228. # Check for existence of the legacy Slic3r directory.
  229. my $datadir_legacy = substr $datadir, 0, -2;
  230. my $dir_enc = Slic3r::encode_path($datadir_legacy);
  231. if (-e $dir_enc && -d $dir_enc &&
  232. -e ($dir_enc . '/print') && -d ($dir_enc . '/print') &&
  233. -e ($dir_enc . '/filament') && -d ($dir_enc . '/filament') &&
  234. -e ($dir_enc . '/printer') && -d ($dir_enc . '/printer') &&
  235. -e ($dir_enc . '/slic3r.ini')) {
  236. $message_has_legacy = "Starting with Slic3r 1.38.4, the user profile directory has been renamed to $datadir. You may consider closing Slic3r and renaming $datadir_legacy to $datadir.";
  237. }
  238. }
  239. }
  240. $self->append_text('Hello, welcome to Slic3r Prusa Edition! This '.lc($wizard).' helps you with the initial configuration; just a few settings and you will be ready to print.');
  241. $self->append_text('Please select your printer vendor and printer type. If your printer is not listed, you may try your luck and select a similar one. If you select "Other", this ' . lc($wizard) . ' will let you set the basic 3D printer parameters.');
  242. $self->append_text($message_has_legacy) if defined $message_has_legacy;
  243. # To import an existing configuration instead, cancel this '.lc($wizard).' and use the Open Config menu item found in the File menu.');
  244. $self->append_text('If you received a configuration file or a config bundle from your 3D printer vendor, cancel this '.lc($wizard).' and use the "File->Load Config" or "File->Load Config Bundle" menu.');
  245. $self->{choice} = my $choice = Wx::Choice->new($self, -1, wxDefaultPosition, wxDefaultSize, []);
  246. $self->{vsizer}->Add($choice, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
  247. if (! $fresh_start) {
  248. $self->{reset_checkbox} = Wx::CheckBox->new($self, -1, "Reset user profile, install from scratch");
  249. $self->{vsizer}->Add($self->{reset_checkbox}, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
  250. }
  251. EVT_CHOICE($parent, $choice, sub {
  252. my $sel = $self->{choice}->GetStringSelection;
  253. $self->{preset_name} = $sel;
  254. $self->set_full_wizard_workflow(($sel eq 'Other') || ($sel eq ''));
  255. });
  256. if (! $fresh_start) {
  257. EVT_CHECKBOX($self, $self->{reset_checkbox}, sub {
  258. $self->{reset_user_profile} = $self->{reset_checkbox}->GetValue();
  259. });
  260. }
  261. EVT_ACTIVATE($parent, sub {
  262. $self->set_full_wizard_workflow($self->{preset_name} eq 'Other');
  263. });
  264. return $self;
  265. }
  266. sub set_full_wizard_workflow {
  267. my ($self, $full_workflow) = @_;
  268. $self->{full_wizard_workflow} = $full_workflow;
  269. $self->{index}->{just_welcome} = !$full_workflow;
  270. $self->{index}->Refresh;
  271. my $next_button = $self->GetParent->FindWindow(wxID_FORWARD);
  272. $next_button->SetLabel($full_workflow ? "&Next >" : "&Finish");
  273. }
  274. # Set the preset names, select the first item.
  275. sub set_selection_presets {
  276. my ($self, $names) = @_;
  277. $self->{choice}->Append($names);
  278. $self->{choice}->SetSelection(0);
  279. $self->{preset_name} = $names->[0];
  280. }
  281. sub GetNext {
  282. my $self = shift;
  283. return $self->{full_wizard_workflow} ? $self->{next_page} : undef;
  284. }
  285. package Slic3r::GUI::ConfigWizard::Page::Firmware;
  286. use base 'Slic3r::GUI::ConfigWizard::Page';
  287. sub new {
  288. my $class = shift;
  289. my ($parent) = @_;
  290. my $self = $class->SUPER::new($parent, 'Firmware Type');
  291. $self->append_text('Choose the type of firmware used by your printer, then click Next.');
  292. $self->append_option('gcode_flavor');
  293. return $self;
  294. }
  295. package Slic3r::GUI::ConfigWizard::Page::Bed;
  296. use base 'Slic3r::GUI::ConfigWizard::Page';
  297. sub new {
  298. my $class = shift;
  299. my ($parent) = @_;
  300. my $self = $class->SUPER::new($parent, 'Bed Size');
  301. $self->append_text('Set the shape of your printer\'s bed, then click Next.');
  302. $self->config->apply(Slic3r::Config::new_from_defaults_keys(['bed_shape']));
  303. $self->{bed_shape_panel} = my $panel = Slic3r::GUI::BedShapePanel->new($self, $self->config->bed_shape);
  304. $self->{bed_shape_panel}->on_change(sub {
  305. $self->config->set('bed_shape', $self->{bed_shape_panel}->GetValue);
  306. });
  307. $self->append_panel($self->{bed_shape_panel});
  308. return $self;
  309. }
  310. package Slic3r::GUI::ConfigWizard::Page::Nozzle;
  311. use base 'Slic3r::GUI::ConfigWizard::Page';
  312. sub new {
  313. my $class = shift;
  314. my ($parent) = @_;
  315. my $self = $class->SUPER::new($parent, 'Nozzle Diameter');
  316. $self->append_text('Enter the diameter of your printer\'s hot end nozzle, then click Next.');
  317. $self->append_option('nozzle_diameter#0');
  318. return $self;
  319. }
  320. package Slic3r::GUI::ConfigWizard::Page::Filament;
  321. use base 'Slic3r::GUI::ConfigWizard::Page';
  322. sub new {
  323. my $class = shift;
  324. my ($parent) = @_;
  325. my $self = $class->SUPER::new($parent, 'Filament Diameter');
  326. $self->append_text('Enter the diameter of your filament, then click Next.');
  327. $self->append_text('Good precision is required, so use a caliper and do multiple measurements along the filament, then compute the average.');
  328. $self->append_option('filament_diameter#0');
  329. return $self;
  330. }
  331. package Slic3r::GUI::ConfigWizard::Page::Temperature;
  332. use base 'Slic3r::GUI::ConfigWizard::Page';
  333. sub new {
  334. my $class = shift;
  335. my ($parent) = @_;
  336. my $self = $class->SUPER::new($parent, 'Extrusion Temperature');
  337. $self->append_text('Enter the temperature needed for extruding your filament, then click Next.');
  338. $self->append_text('A rule of thumb is 160 to 230 °C for PLA, and 215 to 250 °C for ABS.');
  339. $self->append_option('temperature#0');
  340. return $self;
  341. }
  342. package Slic3r::GUI::ConfigWizard::Page::BedTemperature;
  343. use base 'Slic3r::GUI::ConfigWizard::Page';
  344. sub new {
  345. my $class = shift;
  346. my ($parent) = @_;
  347. my $self = $class->SUPER::new($parent, 'Bed Temperature');
  348. $self->append_text('Enter the bed temperature needed for getting your filament to stick to your heated bed, then click Next.');
  349. $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.');
  350. $self->append_option('bed_temperature#0');
  351. return $self;
  352. }
  353. package Slic3r::GUI::ConfigWizard::Page::Finished;
  354. use base 'Slic3r::GUI::ConfigWizard::Page';
  355. sub new {
  356. my $class = shift;
  357. my ($parent) = @_;
  358. my $self = $class->SUPER::new($parent, 'Congratulations!', 'Finish');
  359. $self->append_text("You have successfully completed the Slic3r Configuration $wizard. " .
  360. 'Slic3r is now configured for your printer and filament.');
  361. $self->append_text('To close this '.lc($wizard).' and apply the newly created configuration, click Finish.');
  362. return $self;
  363. }
  364. 1;