Tab.pm 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. package Slic3r::GUI::Tab;
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use File::Basename qw(basename);
  6. use List::Util qw(first);
  7. use Wx qw(:bookctrl :dialog :keycode :icon :id :misc :panel :sizer :treectrl :window
  8. wxTheApp);
  9. use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN EVT_TREE_SEL_CHANGED);
  10. use base 'Wx::Panel';
  11. sub new {
  12. my $class = shift;
  13. my ($parent, %params) = @_;
  14. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
  15. $self->{options} = []; # array of option names handled by this tab
  16. $self->{$_} = $params{$_} for qw(on_value_change on_presets_changed);
  17. # horizontal sizer
  18. $self->{sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
  19. $self->{sizer}->SetSizeHints($self);
  20. $self->SetSizer($self->{sizer});
  21. # left vertical sizer
  22. my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
  23. $self->{sizer}->Add($left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
  24. my $left_col_width = 150;
  25. # preset chooser
  26. {
  27. # choice menu
  28. $self->{presets_choice} = Wx::Choice->new($self, -1, wxDefaultPosition, [$left_col_width, -1], []);
  29. $self->{presets_choice}->SetFont($Slic3r::GUI::small_font);
  30. # buttons
  31. $self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/disk.png", wxBITMAP_TYPE_PNG));
  32. $self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG));
  33. $self->{btn_save_preset}->SetToolTipString("Save current " . lc($self->title));
  34. $self->{btn_delete_preset}->SetToolTipString("Delete this preset");
  35. $self->{btn_delete_preset}->Disable;
  36. ### These cause GTK warnings:
  37. ###my $box = Wx::StaticBox->new($self, -1, "Presets:", wxDefaultPosition, [$left_col_width, 50]);
  38. ###my $hsizer = Wx::StaticBoxSizer->new($box, wxHORIZONTAL);
  39. my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
  40. $left_sizer->Add($hsizer, 0, wxEXPAND | wxBOTTOM, 5);
  41. $hsizer->Add($self->{presets_choice}, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 3);
  42. $hsizer->Add($self->{btn_save_preset}, 0, wxALIGN_CENTER_VERTICAL);
  43. $hsizer->Add($self->{btn_delete_preset}, 0, wxALIGN_CENTER_VERTICAL);
  44. }
  45. # tree
  46. $self->{treectrl} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [$left_col_width, -1], wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS);
  47. $left_sizer->Add($self->{treectrl}, 1, wxEXPAND);
  48. $self->{icons} = Wx::ImageList->new(16, 16, 1);
  49. $self->{treectrl}->AssignImageList($self->{icons});
  50. $self->{iconcount} = -1;
  51. $self->{treectrl}->AddRoot("root");
  52. $self->{pages} = [];
  53. $self->{treectrl}->SetIndent(0);
  54. EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub {
  55. my $page = first { $_->{title} eq $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) } @{$self->{pages}}
  56. or return;
  57. $_->Hide for @{$self->{pages}};
  58. $page->Show;
  59. $self->{sizer}->Layout;
  60. $self->Refresh;
  61. });
  62. EVT_KEY_DOWN($self->{treectrl}, sub {
  63. my ($treectrl, $event) = @_;
  64. if ($event->GetKeyCode == WXK_TAB) {
  65. $treectrl->Navigate($event->ShiftDown ? &Wx::wxNavigateBackward : &Wx::wxNavigateForward);
  66. } else {
  67. $event->Skip;
  68. }
  69. });
  70. EVT_CHOICE($parent, $self->{presets_choice}, sub {
  71. $self->on_select_preset;
  72. $self->on_presets_changed;
  73. });
  74. EVT_BUTTON($self, $self->{btn_save_preset}, sub { $self->save_preset });
  75. EVT_BUTTON($self, $self->{btn_delete_preset}, sub {
  76. my $i = $self->{presets_choice}->GetSelection;
  77. return if $i == 0; # this shouldn't happen but let's trap it anyway
  78. my $res = Wx::MessageDialog->new($self, "Are you sure you want to delete the selected preset?", 'Delete Preset', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION)->ShowModal;
  79. return unless $res == wxID_YES;
  80. if (-e $self->{presets}[$i]{file}) {
  81. unlink $self->{presets}[$i]{file};
  82. }
  83. splice @{$self->{presets}}, $i, 1;
  84. $self->set_dirty(0);
  85. $self->{presets_choice}->Delete($i);
  86. $self->{presets_choice}->SetSelection(0);
  87. $self->on_select_preset;
  88. $self->on_presets_changed;
  89. });
  90. $self->{config} = Slic3r::Config->new;
  91. $self->build;
  92. if ($self->hidden_options) {
  93. $self->{config}->apply(Slic3r::Config->new_from_defaults($self->hidden_options));
  94. push @{$self->{options}}, $self->hidden_options;
  95. }
  96. $self->load_presets;
  97. return $self;
  98. }
  99. sub current_preset {
  100. my $self = shift;
  101. return $self->{presets}[ $self->{presets_choice}->GetSelection ];
  102. }
  103. sub get_preset {
  104. my $self = shift;
  105. return $self->{presets}[ $_[0] ];
  106. }
  107. sub save_preset {
  108. my ($self, $name) = @_;
  109. # since buttons (and choices too) don't get focus on Mac, we set focus manually
  110. # to the treectrl so that the EVT_* events are fired for the input field having
  111. # focus currently. is there anything better than this?
  112. $self->{treectrl}->SetFocus;
  113. if (!defined $name) {
  114. my $preset = $self->current_preset;
  115. my $default_name = $preset->{default} ? 'Untitled' : basename($preset->{name});
  116. $default_name =~ s/\.ini$//i;
  117. my $dlg = Slic3r::GUI::SavePresetWindow->new($self,
  118. title => lc($self->title),
  119. default => $default_name,
  120. values => [ map { my $name = $_->{name}; $name =~ s/\.ini$//i; $name } @{$self->{presets}} ],
  121. );
  122. return unless $dlg->ShowModal == wxID_OK;
  123. $name = $dlg->get_name;
  124. }
  125. $self->config->save(sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $self->name, $name);
  126. $self->set_dirty(0);
  127. $self->load_presets;
  128. $self->{presets_choice}->SetSelection(first { basename($self->{presets}[$_]{file}) eq $name . ".ini" } 1 .. $#{$self->{presets}});
  129. $self->on_select_preset;
  130. $self->on_presets_changed;
  131. }
  132. # propagate event to the parent
  133. sub on_value_change {
  134. my $self = shift;
  135. $self->{on_value_change}->(@_) if $self->{on_value_change};
  136. }
  137. sub on_presets_changed {
  138. my $self = shift;
  139. $self->{on_presets_changed}->([$self->{presets_choice}->GetStrings], $self->{presets_choice}->GetSelection)
  140. if $self->{on_presets_changed};
  141. }
  142. sub on_preset_loaded {}
  143. sub hidden_options {}
  144. sub config { $_[0]->{config}->clone }
  145. sub select_default_preset {
  146. my $self = shift;
  147. $self->{presets_choice}->SetSelection(0);
  148. }
  149. sub select_preset {
  150. my $self = shift;
  151. $self->{presets_choice}->SetSelection($_[0]);
  152. $self->on_select_preset;
  153. }
  154. sub on_select_preset {
  155. my $self = shift;
  156. if (defined $self->{dirty}) {
  157. my $name = $self->{dirty} == 0 ? 'Default preset' : "Preset \"$self->{presets}[$self->{dirty}]{name}\"";
  158. my $confirm = Wx::MessageDialog->new($self, "$name has unsaved changes. Discard changes and continue anyway?",
  159. 'Unsaved Changes', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
  160. if ($confirm->ShowModal == wxID_NO) {
  161. $self->{presets_choice}->SetSelection($self->{dirty});
  162. return;
  163. }
  164. $self->set_dirty(0);
  165. }
  166. my $preset = $self->current_preset;
  167. my $preset_config = $self->get_preset_config($preset);
  168. eval {
  169. local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
  170. foreach my $opt_key (@{$self->{options}}) {
  171. $self->{config}->set($opt_key, $preset_config->get($opt_key))
  172. if $preset_config->has($opt_key);
  173. }
  174. ($preset->{default} || $preset->{external})
  175. ? $self->{btn_delete_preset}->Disable
  176. : $self->{btn_delete_preset}->Enable;
  177. $self->on_preset_loaded;
  178. $self->reload_values;
  179. $self->set_dirty(0);
  180. $Slic3r::GUI::Settings->{presets}{$self->name} = $preset->{file} ? basename($preset->{file}) : '';
  181. };
  182. if ($@) {
  183. $@ = "I was unable to load the selected config file: $@";
  184. Slic3r::GUI::catch_error($self);
  185. $self->select_default_preset;
  186. }
  187. wxTheApp->save_settings;
  188. }
  189. sub get_preset_config {
  190. my $self = shift;
  191. my ($preset) = @_;
  192. if ($preset->{default}) {
  193. return Slic3r::Config->new_from_defaults(@{$self->{options}});
  194. } else {
  195. if (!-e $preset->{file}) {
  196. Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($preset->{file}).");
  197. return;
  198. }
  199. # apply preset values on top of defaults
  200. my $external_config = Slic3r::Config->load($preset->{file});
  201. my $config = Slic3r::Config->new;
  202. $config->set($_, $external_config->get($_))
  203. for grep $external_config->has($_), @{$self->{options}};
  204. return $config;
  205. }
  206. }
  207. sub add_options_page {
  208. my $self = shift;
  209. my ($title, $icon, %params) = @_;
  210. if ($icon) {
  211. my $bitmap = Wx::Bitmap->new("$Slic3r::var/$icon", wxBITMAP_TYPE_PNG);
  212. $self->{icons}->Add($bitmap);
  213. $self->{iconcount}++;
  214. }
  215. {
  216. # get all config options being added to the current page; remove indexes; associate defaults
  217. my @options = map { $_ =~ s/#.+//; $_ } grep !ref($_), map @{$_->{options}}, @{$params{optgroups}};
  218. my %defaults_to_set = map { $_ => 1 } @options;
  219. # apply default values for the options we don't have already
  220. delete $defaults_to_set{$_} for @{$self->{options}};
  221. $self->{config}->apply(Slic3r::Config->new_from_defaults(keys %defaults_to_set)) if %defaults_to_set;
  222. # append such options to our list
  223. push @{$self->{options}}, @options;
  224. }
  225. my $page = Slic3r::GUI::Tab::Page->new($self, $title, $self->{iconcount}, %params, on_change => sub {
  226. $self->on_value_change(@_);
  227. $self->set_dirty(1);
  228. });
  229. $page->Hide;
  230. $self->{sizer}->Add($page, 1, wxEXPAND | wxLEFT, 5);
  231. push @{$self->{pages}}, $page;
  232. $self->update_tree;
  233. return $page;
  234. }
  235. sub set_value {
  236. my $self = shift;
  237. my ($opt_key, $value) = @_;
  238. my $changed = 0;
  239. foreach my $page (@{$self->{pages}}) {
  240. $changed = 1 if $page->set_value($opt_key, $value);
  241. }
  242. return $changed;
  243. }
  244. sub reload_values {
  245. my $self = shift;
  246. $self->set_value($_, $self->{config}->get($_))
  247. for @{$self->{config}->get_keys};
  248. }
  249. sub update_tree {
  250. my $self = shift;
  251. my ($select) = @_;
  252. $select //= 0; #/
  253. my $rootItem = $self->{treectrl}->GetRootItem;
  254. $self->{treectrl}->DeleteChildren($rootItem);
  255. foreach my $page (@{$self->{pages}}) {
  256. my $itemId = $self->{treectrl}->AppendItem($rootItem, $page->{title}, $page->{iconID});
  257. $self->{treectrl}->SelectItem($itemId) if $self->{treectrl}->GetChildrenCount($rootItem) == $select + 1;
  258. }
  259. }
  260. sub set_dirty {
  261. my $self = shift;
  262. my ($dirty) = @_;
  263. return if $dirty and $self->is_dirty;
  264. return if (not $dirty) and (not $self->is_dirty);
  265. my $selection = $self->{presets_choice}->GetSelection;
  266. my $i = $self->{dirty} // $selection; #/
  267. my $text = $self->{presets_choice}->GetString($i);
  268. if ($dirty) {
  269. $self->{dirty} = $i;
  270. if ($text !~ / \(modified\)$/) {
  271. $self->{presets_choice}->SetString($i, "$text (modified)");
  272. $self->{presets_choice}->SetSelection($selection); # http://trac.wxwidgets.org/ticket/13769
  273. }
  274. } else {
  275. $self->{dirty} = undef;
  276. $text =~ s/ \(modified\)$//;
  277. $self->{presets_choice}->SetString($i, $text);
  278. $self->{presets_choice}->SetSelection($selection); # http://trac.wxwidgets.org/ticket/13769
  279. }
  280. $self->on_presets_changed;
  281. }
  282. sub is_dirty {
  283. my $self = shift;
  284. return (defined $self->{dirty});
  285. }
  286. sub load_presets {
  287. my $self = shift;
  288. $self->{presets} = [{
  289. default => 1,
  290. name => '- default -',
  291. }];
  292. my %presets = wxTheApp->presets($self->name);
  293. foreach my $preset_name (sort keys %presets) {
  294. push @{$self->{presets}}, {
  295. name => $preset_name,
  296. file => $presets{$preset_name},
  297. };
  298. }
  299. $self->{presets_choice}->Clear;
  300. $self->{presets_choice}->Append($_->{name}) for @{$self->{presets}};
  301. {
  302. # load last used preset
  303. my $i = first { basename($self->{presets}[$_]{file}) eq ($Slic3r::GUI::Settings->{presets}{$self->name} || '') } 1 .. $#{$self->{presets}};
  304. $self->{presets_choice}->SetSelection($i || 0);
  305. $self->on_select_preset;
  306. }
  307. $self->on_presets_changed;
  308. }
  309. sub load_config_file {
  310. my $self = shift;
  311. my ($file) = @_;
  312. # look for the loaded config among the existing menu items
  313. my $i = first { $self->{presets}[$_]{file} eq $file && $self->{presets}[$_]{external} } 1..$#{$self->{presets}};
  314. if (!$i) {
  315. my $preset_name = basename($file); # keep the .ini suffix
  316. push @{$self->{presets}}, {
  317. file => $file,
  318. name => $preset_name,
  319. external => 1,
  320. };
  321. $self->{presets_choice}->Append($preset_name);
  322. $i = $#{$self->{presets}};
  323. }
  324. $self->{presets_choice}->SetSelection($i);
  325. $self->on_select_preset;
  326. $self->on_presets_changed;
  327. }
  328. package Slic3r::GUI::Tab::Print;
  329. use base 'Slic3r::GUI::Tab';
  330. sub name { 'print' }
  331. sub title { 'Print Settings' }
  332. sub build {
  333. my $self = shift;
  334. $self->add_options_page('Layers and perimeters', 'layers.png', optgroups => [
  335. {
  336. title => 'Layer height',
  337. options => [qw(layer_height first_layer_height)],
  338. },
  339. {
  340. title => 'Vertical shells',
  341. options => [qw(perimeters spiral_vase)],
  342. },
  343. {
  344. title => 'Horizontal shells',
  345. options => [qw(top_solid_layers bottom_solid_layers)],
  346. lines => [
  347. {
  348. label => 'Solid layers',
  349. options => [qw(top_solid_layers bottom_solid_layers)],
  350. },
  351. ],
  352. },
  353. {
  354. title => 'Quality (slower slicing)',
  355. options => [qw(extra_perimeters avoid_crossing_perimeters thin_walls overhangs)],
  356. lines => [
  357. Slic3r::GUI::OptionsGroup->single_option_line('extra_perimeters'),
  358. Slic3r::GUI::OptionsGroup->single_option_line('avoid_crossing_perimeters'),
  359. Slic3r::GUI::OptionsGroup->single_option_line('thin_walls'),
  360. Slic3r::GUI::OptionsGroup->single_option_line('overhangs'),
  361. ],
  362. },
  363. {
  364. title => 'Advanced',
  365. options => [qw(seam_position external_perimeters_first)],
  366. },
  367. ]);
  368. $self->add_options_page('Infill', 'shading.png', optgroups => [
  369. {
  370. title => 'Infill',
  371. options => [qw(fill_density fill_pattern solid_fill_pattern)],
  372. },
  373. {
  374. title => 'Reducing printing time',
  375. options => [qw(infill_every_layers infill_only_where_needed)],
  376. },
  377. {
  378. title => 'Advanced',
  379. options => [qw(solid_infill_every_layers fill_angle
  380. solid_infill_below_area only_retract_when_crossing_perimeters infill_first)],
  381. },
  382. ]);
  383. $self->add_options_page('Speed', 'time.png', optgroups => [
  384. {
  385. title => 'Speed for print moves',
  386. options => [qw(perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed solid_infill_speed top_solid_infill_speed support_material_speed support_material_interface_speed bridge_speed gap_fill_speed)],
  387. },
  388. {
  389. title => 'Speed for non-print moves',
  390. options => [qw(travel_speed)],
  391. },
  392. {
  393. title => 'Modifiers',
  394. options => [qw(first_layer_speed)],
  395. },
  396. {
  397. title => 'Acceleration control (advanced)',
  398. options => [qw(perimeter_acceleration infill_acceleration bridge_acceleration first_layer_acceleration default_acceleration)],
  399. },
  400. ]);
  401. $self->add_options_page('Skirt and brim', 'box.png', optgroups => [
  402. {
  403. title => 'Skirt',
  404. options => [qw(skirts skirt_distance skirt_height min_skirt_length)],
  405. },
  406. {
  407. title => 'Brim',
  408. options => [qw(brim_width)],
  409. },
  410. ]);
  411. $self->add_options_page('Support material', 'building.png', optgroups => [
  412. {
  413. title => 'Support material',
  414. options => [qw(support_material support_material_threshold support_material_enforce_layers)],
  415. },
  416. {
  417. title => 'Raft',
  418. options => [qw(raft_layers)],
  419. },
  420. {
  421. title => 'Options for support material and raft',
  422. options => [qw(support_material_pattern support_material_spacing support_material_angle
  423. support_material_interface_layers support_material_interface_spacing
  424. dont_support_bridges)],
  425. },
  426. ]);
  427. $self->add_options_page('Notes', 'note.png', optgroups => [
  428. {
  429. title => 'Notes',
  430. no_labels => 1,
  431. options => [qw(notes)],
  432. },
  433. ]);
  434. $self->add_options_page('Output options', 'page_white_go.png', optgroups => [
  435. {
  436. title => 'Sequential printing',
  437. options => [qw(complete_objects extruder_clearance_radius extruder_clearance_height)],
  438. lines => [
  439. Slic3r::GUI::OptionsGroup->single_option_line('complete_objects'),
  440. {
  441. label => 'Extruder clearance (mm)',
  442. options => [qw(extruder_clearance_radius extruder_clearance_height)],
  443. },
  444. ],
  445. },
  446. {
  447. title => 'Output file',
  448. options => [qw(gcode_comments output_filename_format)],
  449. },
  450. {
  451. title => 'Post-processing scripts',
  452. no_labels => 1,
  453. options => [qw(post_process)],
  454. },
  455. ]);
  456. $self->add_options_page('Multiple Extruders', 'funnel.png', optgroups => [
  457. {
  458. title => 'Extruders',
  459. options => [qw(perimeter_extruder infill_extruder support_material_extruder support_material_interface_extruder)],
  460. },
  461. {
  462. title => 'Ooze prevention',
  463. options => [qw(ooze_prevention standby_temperature_delta)],
  464. },
  465. {
  466. title => 'Advanced',
  467. options => [qw(interface_shells)],
  468. },
  469. ]);
  470. $self->add_options_page('Advanced', 'wrench.png', optgroups => [
  471. {
  472. title => 'Extrusion width',
  473. label_width => 180,
  474. options => [qw(extrusion_width first_layer_extrusion_width perimeter_extrusion_width external_perimeter_extrusion_width infill_extrusion_width solid_infill_extrusion_width top_infill_extrusion_width support_material_extrusion_width)],
  475. },
  476. {
  477. title => 'Flow',
  478. options => [qw(bridge_flow_ratio)],
  479. },
  480. {
  481. title => 'Other',
  482. options => [($Slic3r::have_threads ? qw(threads) : ()), qw(resolution xy_size_compensation)],
  483. },
  484. ]);
  485. }
  486. sub hidden_options { !$Slic3r::have_threads ? qw(threads) : () }
  487. package Slic3r::GUI::Tab::Filament;
  488. use base 'Slic3r::GUI::Tab';
  489. sub name { 'filament' }
  490. sub title { 'Filament Settings' }
  491. sub build {
  492. my $self = shift;
  493. $self->add_options_page('Filament', 'spool.png', optgroups => [
  494. {
  495. title => 'Filament',
  496. options => ['filament_diameter#0', 'extrusion_multiplier#0'],
  497. },
  498. {
  499. title => 'Temperature (°C)',
  500. options => ['temperature#0', 'first_layer_temperature#0', qw(bed_temperature first_layer_bed_temperature)],
  501. lines => [
  502. {
  503. label => 'Extruder',
  504. options => ['first_layer_temperature#0', 'temperature#0'],
  505. },
  506. {
  507. label => 'Bed',
  508. options => [qw(first_layer_bed_temperature bed_temperature)],
  509. },
  510. ],
  511. },
  512. ]);
  513. $self->add_options_page('Cooling', 'hourglass.png', optgroups => [
  514. {
  515. title => 'Enable',
  516. options => [qw(fan_always_on cooling)],
  517. lines => [
  518. Slic3r::GUI::OptionsGroup->single_option_line('fan_always_on'),
  519. Slic3r::GUI::OptionsGroup->single_option_line('cooling'),
  520. {
  521. label => '',
  522. full_width => 1,
  523. widget => sub {
  524. my ($parent) = @_;
  525. return $self->{description_line} = Slic3r::GUI::OptionsGroup::StaticTextLine->new($parent);
  526. },
  527. },
  528. ],
  529. },
  530. {
  531. title => 'Fan settings',
  532. options => [qw(min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers)],
  533. lines => [
  534. {
  535. label => 'Fan speed',
  536. options => [qw(min_fan_speed max_fan_speed)],
  537. },
  538. Slic3r::GUI::OptionsGroup->single_option_line('bridge_fan_speed'),
  539. Slic3r::GUI::OptionsGroup->single_option_line('disable_fan_first_layers'),
  540. ],
  541. },
  542. {
  543. title => 'Cooling thresholds',
  544. label_width => 250,
  545. options => [qw(fan_below_layer_time slowdown_below_layer_time min_print_speed)],
  546. },
  547. ]);
  548. }
  549. sub _update_description {
  550. my $self = shift;
  551. my $config = $self->config;
  552. my $msg = "";
  553. my $fan_other_layers = $config->fan_always_on
  554. ? sprintf "will always run at %d%%%s.", $config->min_fan_speed,
  555. ($config->disable_fan_first_layers > 1
  556. ? " except for the first " . $config->disable_fan_first_layers . " layers"
  557. : $config->disable_fan_first_layers == 1
  558. ? " except for the first layer"
  559. : "")
  560. : "will be turned off.";
  561. if ($config->cooling) {
  562. $msg = sprintf "If estimated layer time is below ~%ds, fan will run at %d%% and print speed will be reduced so that no less than %ds are spent on that layer (however, speed will never be reduced below %dmm/s).",
  563. $config->slowdown_below_layer_time, $config->max_fan_speed, $config->slowdown_below_layer_time, $config->min_print_speed;
  564. if ($config->fan_below_layer_time > $config->slowdown_below_layer_time) {
  565. $msg .= sprintf "\nIf estimated layer time is greater, but still below ~%ds, fan will run at a proportionally decreasing speed between %d%% and %d%%.",
  566. $config->fan_below_layer_time, $config->max_fan_speed, $config->min_fan_speed;
  567. }
  568. $msg .= "\nDuring the other layers, fan $fan_other_layers"
  569. } else {
  570. $msg = "Fan $fan_other_layers";
  571. }
  572. $self->{description_line}->SetText($msg);
  573. }
  574. sub on_value_change {
  575. my $self = shift;
  576. my ($opt_key) = @_;
  577. $self->SUPER::on_value_change(@_);
  578. $self->_update_description;
  579. }
  580. package Slic3r::GUI::Tab::Printer;
  581. use base 'Slic3r::GUI::Tab';
  582. use Wx qw(:sizer :button :bitmap :misc :id);
  583. use Wx::Event qw(EVT_BUTTON);
  584. sub name { 'printer' }
  585. sub title { 'Printer Settings' }
  586. sub build {
  587. my $self = shift;
  588. $self->{extruders_count} = 1;
  589. my $bed_shape_widget = sub {
  590. my ($parent) = @_;
  591. my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  592. $btn->SetFont($Slic3r::GUI::small_font);
  593. if ($Slic3r::GUI::have_button_icons) {
  594. $btn->SetBitmap(Wx::Bitmap->new("$Slic3r::var/cog.png", wxBITMAP_TYPE_PNG));
  595. }
  596. my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  597. $sizer->Add($btn);
  598. EVT_BUTTON($self, $btn, sub {
  599. my $dlg = Slic3r::GUI::BedShapeDialog->new($self, $self->{config}->bed_shape);
  600. if ($dlg->ShowModal == wxID_OK) {
  601. my $value = $dlg->GetValue;
  602. $self->{config}->set('bed_shape', $value);
  603. $self->on_value_change('bed_shape', $value);
  604. }
  605. });
  606. return $sizer;
  607. };
  608. $self->add_options_page('General', 'printer_empty.png', optgroups => [
  609. {
  610. title => 'Size and coordinates',
  611. options => [qw(bed_shape z_offset)],
  612. lines => [
  613. {
  614. label => 'Bed shape',
  615. widget => $bed_shape_widget,
  616. options => ['bed_shape'],
  617. },
  618. Slic3r::GUI::OptionsGroup->single_option_line('z_offset'),
  619. ],
  620. },
  621. {
  622. title => 'Firmware',
  623. options => [qw(gcode_flavor use_relative_e_distances)],
  624. },
  625. {
  626. class => 'Slic3r::GUI::OptionsGroup',
  627. title => 'Capabilities',
  628. options => [
  629. {
  630. opt_key => 'extruders_count',
  631. label => 'Extruders',
  632. tooltip => 'Number of extruders of the printer.',
  633. type => 'i',
  634. min => 1,
  635. default => 1,
  636. on_change => sub { $self->{extruders_count} = $_[0] },
  637. },
  638. ],
  639. },
  640. {
  641. title => 'Advanced',
  642. options => [qw(use_firmware_retraction vibration_limit)],
  643. },
  644. ]);
  645. $self->add_options_page('Custom G-code', 'cog.png', optgroups => [
  646. {
  647. title => 'Start G-code',
  648. no_labels => 1,
  649. options => [qw(start_gcode)],
  650. },
  651. {
  652. title => 'End G-code',
  653. no_labels => 1,
  654. options => [qw(end_gcode)],
  655. },
  656. {
  657. title => 'Layer change G-code',
  658. no_labels => 1,
  659. options => [qw(layer_gcode)],
  660. },
  661. {
  662. title => 'Tool change G-code',
  663. no_labels => 1,
  664. options => [qw(toolchange_gcode)],
  665. },
  666. ]);
  667. $self->{extruder_pages} = [];
  668. $self->_build_extruder_pages;
  669. }
  670. sub _extruder_options { qw(nozzle_diameter extruder_offset retract_length retract_lift retract_speed retract_restart_extra retract_before_travel wipe
  671. retract_layer_change retract_length_toolchange retract_restart_extra_toolchange) }
  672. sub _build_extruder_pages {
  673. my $self = shift;
  674. my $default_config = Slic3r::Config::Full->new;
  675. foreach my $extruder_idx (@{$self->{extruder_pages}} .. $self->{extruders_count}-1) {
  676. # extend options
  677. foreach my $opt_key ($self->_extruder_options) {
  678. my $values = $self->{config}->get($opt_key);
  679. if (!defined $values) {
  680. $values = [ $default_config->get_at($opt_key, 0) ];
  681. } else {
  682. # use last extruder's settings for the new one
  683. my $last_value = $values->[-1];
  684. $values->[$extruder_idx] //= $last_value;
  685. }
  686. $self->{config}->set($opt_key, $values)
  687. or die "Unable to extend $opt_key";
  688. }
  689. # build page
  690. $self->{extruder_pages}[$extruder_idx] = $self->add_options_page("Extruder " . ($extruder_idx + 1), 'funnel.png', optgroups => [
  691. {
  692. title => 'Size',
  693. options => ['nozzle_diameter#' . $extruder_idx],
  694. },
  695. {
  696. title => 'Position (for multi-extruder printers)',
  697. options => ['extruder_offset#' . $extruder_idx],
  698. },
  699. {
  700. title => 'Retraction',
  701. options => [
  702. map "${_}#${extruder_idx}",
  703. qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe)
  704. ],
  705. },
  706. {
  707. title => 'Retraction when tool is disabled (advanced settings for multi-extruder setups)',
  708. options => [
  709. map "${_}#${extruder_idx}",
  710. qw(retract_length_toolchange retract_restart_extra_toolchange)
  711. ],
  712. },
  713. ]);
  714. $self->{extruder_pages}[$extruder_idx]{disabled} = 0;
  715. }
  716. # remove extra pages
  717. if ($self->{extruders_count} <= $#{$self->{extruder_pages}}) {
  718. splice @{$self->{extruder_pages}}, $self->{extruders_count};
  719. }
  720. # remove extra config values
  721. foreach my $opt_key ($self->_extruder_options) {
  722. my $values = $self->{config}->get($opt_key);
  723. splice @$values, $self->{extruders_count} if $self->{extruders_count} <= $#$values;
  724. $self->{config}->set($opt_key, $values)
  725. or die "Unable to truncate $opt_key";
  726. }
  727. # rebuild page list
  728. @{$self->{pages}} = (
  729. (grep $_->{title} !~ /^Extruder \d+/, @{$self->{pages}}),
  730. @{$self->{extruder_pages}}[ 0 .. $self->{extruders_count}-1 ],
  731. );
  732. }
  733. sub on_value_change {
  734. my $self = shift;
  735. my ($opt_key) = @_;
  736. $self->SUPER::on_value_change(@_);
  737. if ($opt_key eq 'extruders_count') {
  738. # add extra pages or remove unused
  739. $self->_build_extruder_pages;
  740. # update page list and select first page (General)
  741. $self->update_tree(0);
  742. }
  743. }
  744. # this gets executed after preset is loaded and before GUI fields are updated
  745. sub on_preset_loaded {
  746. my $self = shift;
  747. # update the extruders count field
  748. {
  749. # update the GUI field according to the number of nozzle diameters supplied
  750. $self->set_value('extruders_count', scalar @{ $self->{config}->nozzle_diameter });
  751. # update extruder page list
  752. $self->on_value_change('extruders_count');
  753. }
  754. }
  755. sub load_config_file {
  756. my $self = shift;
  757. $self->SUPER::load_config_file(@_);
  758. Slic3r::GUI::warning_catcher($self)->(
  759. "Your configuration was imported. However, Slic3r is currently only able to import settings "
  760. . "for the first defined filament. We recommend you don't use exported configuration files "
  761. . "for multi-extruder setups and rely on the built-in preset management system instead.")
  762. if @{ $self->{config}->nozzle_diameter } > 1;
  763. }
  764. package Slic3r::GUI::Tab::Page;
  765. use Wx qw(:misc :panel :sizer);
  766. use base 'Wx::ScrolledWindow';
  767. sub new {
  768. my $class = shift;
  769. my ($parent, $title, $iconID, %params) = @_;
  770. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  771. $self->{optgroups} = [];
  772. $self->{title} = $title;
  773. $self->{iconID} = $iconID;
  774. $self->SetScrollbars(1, 1, 1, 1);
  775. $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
  776. $self->SetSizer($self->{vsizer});
  777. if ($params{optgroups}) {
  778. $self->append_optgroup(
  779. %$_,
  780. config => $parent->{config},
  781. on_change => $params{on_change},
  782. ) for @{$params{optgroups}};
  783. }
  784. return $self;
  785. }
  786. sub append_optgroup {
  787. my $self = shift;
  788. my %params = @_;
  789. my $class = $params{class} || 'Slic3r::GUI::ConfigOptionsGroup';
  790. my $optgroup = $class->new(
  791. parent => $self,
  792. config => $self->GetParent->{config},
  793. label_width => 200,
  794. %params,
  795. );
  796. $self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 5);
  797. push @{$self->{optgroups}}, $optgroup;
  798. }
  799. sub set_value {
  800. my $self = shift;
  801. my ($opt_key, $value) = @_;
  802. my $changed = 0;
  803. foreach my $optgroup (@{$self->{optgroups}}) {
  804. $changed = 1 if $optgroup->set_value($opt_key, $value);
  805. }
  806. return $changed;
  807. }
  808. package Slic3r::GUI::SavePresetWindow;
  809. use Wx qw(:combobox :dialog :id :misc :sizer);
  810. use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
  811. use base 'Wx::Dialog';
  812. sub new {
  813. my $class = shift;
  814. my ($parent, %params) = @_;
  815. my $self = $class->SUPER::new($parent, -1, "Save preset", wxDefaultPosition, wxDefaultSize);
  816. my @values = grep $_ ne '- default -', @{$params{values}};
  817. my $text = Wx::StaticText->new($self, -1, "Save " . lc($params{title}) . " as:", wxDefaultPosition, wxDefaultSize);
  818. $self->{combo} = Wx::ComboBox->new($self, -1, $params{default}, wxDefaultPosition, wxDefaultSize, \@values,
  819. wxTE_PROCESS_ENTER);
  820. my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  821. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  822. $sizer->Add($text, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10);
  823. $sizer->Add($self->{combo}, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  824. $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  825. EVT_BUTTON($self, wxID_OK, \&accept);
  826. EVT_TEXT_ENTER($self, $self->{combo}, \&accept);
  827. $self->SetSizer($sizer);
  828. $sizer->SetSizeHints($self);
  829. return $self;
  830. }
  831. sub accept {
  832. my ($self, $event) = @_;
  833. if (($self->{chosen_name} = $self->{combo}->GetValue)) {
  834. if ($self->{chosen_name} !~ /^[^<>:\/\\|?*\"]+$/i) {
  835. Slic3r::GUI::show_error($self, "The supplied name is not valid; the following characters are not allowed: <>:/\|?*\"");
  836. } elsif ($self->{chosen_name} eq '- default -') {
  837. Slic3r::GUI::show_error($self, "The supplied name is not available.");
  838. } else {
  839. $self->EndModal(wxID_OK);
  840. }
  841. }
  842. }
  843. sub get_name {
  844. my $self = shift;
  845. return $self->{chosen_name};
  846. }
  847. 1;