Tab.pm 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. # The "Expert" tab at the right of the main tabbed window.
  2. # This file implements following packages:
  3. # Slic3r::GUI::Tab;
  4. # Slic3r::GUI::Tab::Print;
  5. # Slic3r::GUI::Tab::Filament;
  6. # Slic3r::GUI::Tab::Printer;
  7. # Slic3r::GUI::Tab::Page
  8. # - Option page: For example, the Slic3r::GUI::Tab::Print has option pages "Layers and perimeters", "Infill", "Skirt and brim" ...
  9. # Slic3r::GUI::SavePresetWindow
  10. # - Dialog to select a new preset name to store the configuration.
  11. # Slic3r::GUI::Tab::Preset;
  12. # - Single preset item: name, file is default or external.
  13. package Slic3r::GUI::Tab;
  14. use strict;
  15. use warnings;
  16. use utf8;
  17. use File::Basename qw(basename);
  18. use List::Util qw(first);
  19. use Wx qw(:bookctrl :dialog :keycode :icon :id :misc :panel :sizer :treectrl :window
  20. :button wxTheApp);
  21. use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN EVT_TREE_SEL_CHANGED);
  22. use base qw(Wx::Panel Class::Accessor);
  23. # Index of the currently active preset.
  24. __PACKAGE__->mk_accessors(qw(current_preset));
  25. sub new {
  26. my $class = shift;
  27. my ($parent, %params) = @_;
  28. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
  29. # Vertical sizer to hold the choice menu and the rest of the page.
  30. $self->{sizer} = Wx::BoxSizer->new(wxVERTICAL);
  31. $self->{sizer}->SetSizeHints($self);
  32. $self->SetSizer($self->{sizer});
  33. # preset chooser
  34. {
  35. # choice menu
  36. $self->{presets_choice} = Wx::Choice->new($self, -1, wxDefaultPosition, [270, -1], []);
  37. $self->{presets_choice}->SetFont($Slic3r::GUI::small_font);
  38. # buttons
  39. $self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("disk.png"), wxBITMAP_TYPE_PNG),
  40. wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
  41. $self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("delete.png"), wxBITMAP_TYPE_PNG),
  42. wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
  43. $self->{btn_save_preset}->SetToolTipString("Save current " . lc($self->title));
  44. $self->{btn_delete_preset}->SetToolTipString("Delete this preset");
  45. $self->{btn_delete_preset}->Disable;
  46. my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
  47. $self->{sizer}->Add($hsizer, 0, wxBOTTOM, 3);
  48. $hsizer->Add($self->{presets_choice}, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
  49. $hsizer->Add($self->{btn_save_preset}, 0, wxALIGN_CENTER_VERTICAL);
  50. $hsizer->Add($self->{btn_delete_preset}, 0, wxALIGN_CENTER_VERTICAL);
  51. }
  52. # Horizontal sizer to hold the tree and the selected page.
  53. $self->{hsizer} = Wx::BoxSizer->new(wxHORIZONTAL);
  54. $self->{sizer}->Add($self->{hsizer}, 1, wxEXPAND, 0);
  55. # left vertical sizer
  56. my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
  57. $self->{hsizer}->Add($left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
  58. # tree
  59. $self->{treectrl} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [185, -1], wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS);
  60. $left_sizer->Add($self->{treectrl}, 1, wxEXPAND);
  61. $self->{icons} = Wx::ImageList->new(16, 16, 1);
  62. $self->{treectrl}->AssignImageList($self->{icons});
  63. $self->{iconcount} = -1;
  64. $self->{treectrl}->AddRoot("root");
  65. $self->{pages} = [];
  66. $self->{treectrl}->SetIndent(0);
  67. $self->{disable_tree_sel_changed_event} = 0;
  68. EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub {
  69. return if $self->{disable_tree_sel_changed_event};
  70. my $page = first { $_->{title} eq $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) } @{$self->{pages}}
  71. or return;
  72. $_->Hide for @{$self->{pages}};
  73. $page->Show;
  74. $self->{hsizer}->Layout;
  75. $self->Refresh;
  76. });
  77. EVT_KEY_DOWN($self->{treectrl}, sub {
  78. my ($treectrl, $event) = @_;
  79. if ($event->GetKeyCode == WXK_TAB) {
  80. $treectrl->Navigate($event->ShiftDown ? &Wx::wxNavigateBackward : &Wx::wxNavigateForward);
  81. } else {
  82. $event->Skip;
  83. }
  84. });
  85. EVT_CHOICE($parent, $self->{presets_choice}, sub {
  86. $self->on_select_preset;
  87. $self->_on_presets_changed;
  88. });
  89. EVT_BUTTON($self, $self->{btn_save_preset}, sub { $self->save_preset });
  90. EVT_BUTTON($self, $self->{btn_delete_preset}, sub {
  91. my $i = $self->current_preset;
  92. # Don't let the user delete the '- default -' configuration.
  93. # This shall not happen as the 'delete' button is disabled for the '- default -' entry,
  94. # but better be safe than sorry.
  95. return if ($i == 0 && $self->get_current_preset->{default});
  96. 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;
  97. return unless $res == wxID_YES;
  98. # Delete the file.
  99. my $path = $self->{presets}[$i]->file;
  100. my $enc_path = Slic3r::encode_path($path);
  101. if (-e $enc_path && ! unlink $enc_path) {
  102. # Cannot delete the file, therefore the item will not be removed from the selection.
  103. Slic3r::GUI::show_error($self, "Cannot delete file $path : $!");
  104. return;
  105. }
  106. # Delete the preset.
  107. splice @{$self->{presets}}, $i, 1;
  108. # Delete the item from the UI component.
  109. $self->{presets_choice}->Delete($i - $self->{default_suppressed});
  110. $self->current_preset(undef);
  111. if ($self->{default_suppressed} && scalar(@{$self->{presets}}) == 1) {
  112. # Empty selection. Add the '- default -' item into the drop down selection.
  113. $self->{presets_choice}->Append($self->{presets}->[0]->name);
  114. # and remember that the '- default -' is shown.
  115. $self->{default_suppressed} = 0;
  116. }
  117. # Select the 0th item. If default is suppressed, select the first valid.
  118. $self->select_preset($self->{default_suppressed});
  119. $self->_on_presets_changed;
  120. });
  121. # C++ instance DynamicPrintConfig
  122. $self->{config} = Slic3r::Config->new;
  123. # Initialize the DynamicPrintConfig by default keys/values.
  124. # Possible %params keys: no_controller
  125. $self->build(%params);
  126. $self->update_tree;
  127. $self->_update;
  128. if ($self->hidden_options) {
  129. $self->{config}->apply(Slic3r::Config->new_from_defaults($self->hidden_options));
  130. }
  131. return $self;
  132. }
  133. # Are the '- default -' selections suppressed by the Slic3r GUI preferences?
  134. sub no_defaults {
  135. return $Slic3r::GUI::Settings->{_}{no_defaults} ? 1 : 0;
  136. }
  137. # Get a currently active preset (Perl class Slic3r::GUI::Tab::Preset).
  138. sub get_current_preset {
  139. my $self = shift;
  140. return $self->get_preset($self->current_preset);
  141. }
  142. # Get a preset (Perl class Slic3r::GUI::Tab::Preset) with an index $i.
  143. sub get_preset {
  144. my ($self, $i) = @_;
  145. return $self->{presets}[$i];
  146. }
  147. sub save_preset {
  148. my ($self, $name) = @_;
  149. # since buttons (and choices too) don't get focus on Mac, we set focus manually
  150. # to the treectrl so that the EVT_* events are fired for the input field having
  151. # focus currently. is there anything better than this?
  152. $self->{treectrl}->SetFocus;
  153. if (!defined $name) {
  154. my $preset = $self->get_current_preset;
  155. my $default_name = $preset->default ? 'Untitled' : $preset->name;
  156. $default_name =~ s/\.[iI][nN][iI]$//;
  157. my $dlg = Slic3r::GUI::SavePresetWindow->new($self,
  158. title => lc($self->title),
  159. default => $default_name,
  160. values => [ map $_->name, grep !$_->default && !$_->external, @{$self->{presets}} ],
  161. );
  162. return unless $dlg->ShowModal == wxID_OK;
  163. $name = $dlg->get_name;
  164. }
  165. $self->config->save(sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $self->name, $name);
  166. $self->load_presets;
  167. $self->select_preset_by_name($name);
  168. $self->_on_presets_changed;
  169. }
  170. sub on_value_change {
  171. my ($self, $cb) = @_;
  172. $self->{on_value_change} = $cb;
  173. }
  174. sub on_presets_changed {
  175. my ($self, $cb) = @_;
  176. $self->{on_presets_changed} = $cb;
  177. }
  178. # This method is called whenever an option field is changed by the user.
  179. # Propagate event to the parent through the 'on_value_changed' callback
  180. # and call _update.
  181. sub _on_value_change {
  182. my ($self, $key, $value) = @_;
  183. $self->{on_value_change}->($key, $value) if $self->{on_value_change};
  184. $self->_update({ $key => 1 });
  185. }
  186. # Override this to capture changes of configuration caused either by loading or switching a preset,
  187. # or by a user changing an option field.
  188. sub _update {}
  189. sub _on_presets_changed {
  190. my $self = shift;
  191. $self->{on_presets_changed}->(
  192. $self->{presets},
  193. $self->{default_suppressed},
  194. scalar($self->{presets_choice}->GetSelection) + $self->{default_suppressed},
  195. $self->is_dirty,
  196. ) if $self->{on_presets_changed};
  197. }
  198. sub on_preset_loaded {}
  199. sub hidden_options {}
  200. sub config { $_[0]->{config}->clone }
  201. sub select_default_preset {
  202. my $self = shift;
  203. $self->select_preset(0);
  204. }
  205. sub select_preset {
  206. my ($self, $i) = @_;
  207. if ($self->{default_suppressed} && $i == 0) {
  208. # Selecting the '- default -'. Add it to the combo box.
  209. $self->{default_suppressed} = 0;
  210. $self->{presets_choice}->Insert($self->{presets}->[0]->name, 0);
  211. } elsif ($self->no_defaults && ! $self->{default_suppressed} && $i > 0) {
  212. # The user wants to hide the '- default -' items and a non-default item has been added to the presets.
  213. # Hide the '- default -' item.
  214. $self->{presets_choice}->Delete(0);
  215. $self->{default_suppressed} = 1;
  216. }
  217. $self->{presets_choice}->SetSelection($i - $self->{default_suppressed});
  218. $self->on_select_preset;
  219. }
  220. sub select_preset_by_name {
  221. my ($self, $name) = @_;
  222. $name = Slic3r::normalize_utf8_nfc($name);
  223. $self->select_preset(first { $self->{presets}[$_]->name eq $name } 0 .. $#{$self->{presets}});
  224. }
  225. sub on_select_preset {
  226. my $self = shift;
  227. if ($self->is_dirty) {
  228. # Display a dialog showing the dirty options in a human readable form.
  229. my $old_preset = $self->get_current_preset;
  230. my $name = $old_preset->default ? 'Default preset' : "Preset \"" . $old_preset->name . "\"";
  231. my @option_names = ();
  232. foreach my $opt_key (@{$self->dirty_options}) {
  233. my $opt = $Slic3r::Config::Options->{$opt_key};
  234. my $name = $opt->{full_label} // $opt->{label};
  235. if ($opt->{category}) {
  236. $name = $opt->{category} . " > $name";
  237. }
  238. push @option_names, $name;
  239. }
  240. my $changes = join "\n", map "- $_", @option_names;
  241. my $confirm = Wx::MessageDialog->new($self, "$name has unsaved changes:\n$changes\n\nDiscard changes and continue anyway?",
  242. 'Unsaved Changes', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
  243. if ($confirm->ShowModal == wxID_NO) {
  244. $self->{presets_choice}->SetSelection($self->current_preset - $self->{default_suppressed});
  245. # trigger the on_presets_changed event so that we also restore the previous value
  246. # in the plater selector
  247. $self->_on_presets_changed;
  248. return;
  249. }
  250. }
  251. $self->current_preset($self->{presets_choice}->GetSelection + $self->{default_suppressed});
  252. my $preset = $self->get_current_preset;
  253. my $preset_config = $self->get_preset_config($preset);
  254. eval {
  255. local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
  256. my %keys_modified = ();
  257. foreach my $opt_key (@{$self->{config}->get_keys}) {
  258. if ($preset_config->has($opt_key)) {
  259. if ($self->{config}->serialize($opt_key) ne $preset_config->serialize($opt_key)) {
  260. $self->{config}->set($opt_key, $preset_config->get($opt_key));
  261. $keys_modified{$opt_key} = 1;
  262. }
  263. }
  264. }
  265. ($preset->default || $preset->external)
  266. ? $self->{btn_delete_preset}->Disable
  267. : $self->{btn_delete_preset}->Enable;
  268. $self->_update(\%keys_modified);
  269. $self->on_preset_loaded;
  270. $self->reload_config;
  271. $Slic3r::GUI::Settings->{presets}{$self->name} = $preset->file ? basename($preset->file) : '';
  272. };
  273. if ($@) {
  274. $@ = "I was unable to load the selected config file: $@";
  275. Slic3r::GUI::catch_error($self);
  276. $self->select_default_preset;
  277. }
  278. # use CallAfter because some field triggers schedule on_change calls using CallAfter,
  279. # and we don't want them to be called after this update_dirty() as they would mark the
  280. # preset dirty again
  281. # (not sure this is true anymore now that update_dirty is idempotent)
  282. wxTheApp->CallAfter(sub {
  283. $self->_on_presets_changed;
  284. $self->update_dirty;
  285. });
  286. wxTheApp->save_settings;
  287. }
  288. sub init_config_options {
  289. my ($self, @opt_keys) = @_;
  290. $self->{config}->apply(Slic3r::Config->new_from_defaults(@opt_keys));
  291. }
  292. sub add_options_page {
  293. my $self = shift;
  294. my ($title, $icon, %params) = @_;
  295. if ($icon) {
  296. my $bitmap = Wx::Bitmap->new($Slic3r::var->($icon), wxBITMAP_TYPE_PNG);
  297. $self->{icons}->Add($bitmap);
  298. $self->{iconcount}++;
  299. }
  300. my $page = Slic3r::GUI::Tab::Page->new($self, $title, $self->{iconcount});
  301. $page->Hide;
  302. $self->{hsizer}->Add($page, 1, wxEXPAND | wxLEFT, 5);
  303. push @{$self->{pages}}, $page;
  304. return $page;
  305. }
  306. sub reload_config {
  307. my $self = shift;
  308. $_->reload_config for @{$self->{pages}};
  309. }
  310. sub update_tree {
  311. my ($self) = @_;
  312. # get label of the currently selected item
  313. my $selected = $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection);
  314. my $rootItem = $self->{treectrl}->GetRootItem;
  315. $self->{treectrl}->DeleteChildren($rootItem);
  316. my $have_selection = 0;
  317. foreach my $page (@{$self->{pages}}) {
  318. my $itemId = $self->{treectrl}->AppendItem($rootItem, $page->{title}, $page->{iconID});
  319. if ($page->{title} eq $selected) {
  320. $self->{disable_tree_sel_changed_event} = 1;
  321. $self->{treectrl}->SelectItem($itemId);
  322. $self->{disable_tree_sel_changed_event} = 0;
  323. $have_selection = 1;
  324. }
  325. }
  326. if (!$have_selection) {
  327. # this is triggered on first load, so we don't disable the sel change event
  328. $self->{treectrl}->SelectItem($self->{treectrl}->GetFirstChild($rootItem));
  329. }
  330. }
  331. sub update_dirty {
  332. my $self = shift;
  333. my $list_updated;
  334. foreach my $i ($self->{default_suppressed}..$#{$self->{presets}}) {
  335. my $preset = $self->get_preset($i);
  336. my $label = ($i == $self->current_preset && $self->is_dirty) ? $preset->name . " (modified)" : $preset->name;
  337. my $idx = $i - $self->{default_suppressed};
  338. if ($self->{presets_choice}->GetString($idx) ne $label) {
  339. $self->{presets_choice}->SetString($idx, $label);
  340. $list_updated = 1;
  341. }
  342. }
  343. $self->{presets_choice}->SetSelection($self->current_preset - $self->{default_suppressed}) if ($list_updated); # http://trac.wxwidgets.org/ticket/13769
  344. $self->_on_presets_changed;
  345. }
  346. sub is_dirty {
  347. my $self = shift;
  348. return @{$self->dirty_options} > 0;
  349. }
  350. sub dirty_options {
  351. my $self = shift;
  352. return [] if !defined $self->current_preset; # happens during initialization
  353. return $self->get_preset_config($self->get_current_preset)->diff($self->{config});
  354. }
  355. sub load_presets {
  356. my $self = shift;
  357. $self->{presets} = [
  358. Slic3r::GUI::Tab::Preset->new(
  359. default => 1,
  360. name => '- default -',
  361. ),
  362. ];
  363. my %presets = wxTheApp->presets($self->name);
  364. foreach my $preset_name (sort keys %presets) {
  365. push @{$self->{presets}}, Slic3r::GUI::Tab::Preset->new(
  366. name => $preset_name,
  367. file => $presets{$preset_name},
  368. );
  369. }
  370. $self->current_preset(undef);
  371. $self->{default_suppressed} = Slic3r::GUI::Tab->no_defaults && scalar(@{$self->{presets}}) > 1;
  372. $self->{presets_choice}->Clear;
  373. foreach my $preset (@{$self->{presets}}) {
  374. next if ($preset->default && $self->{default_suppressed});
  375. $self->{presets_choice}->Append($preset->name);
  376. }
  377. {
  378. # load last used preset
  379. my $i = first { basename($self->{presets}[$_]->file) eq ($Slic3r::GUI::Settings->{presets}{$self->name} || '') } 1 .. $#{$self->{presets}};
  380. $self->select_preset($i || $self->{default_suppressed});
  381. }
  382. $self->_on_presets_changed;
  383. }
  384. sub load_config_file {
  385. my $self = shift;
  386. my ($file) = @_;
  387. # look for the loaded config among the existing menu items
  388. my $i = first { $self->{presets}[$_]{file} eq $file && $self->{presets}[$_]{external} } 1..$#{$self->{presets}};
  389. if (!$i) {
  390. my $preset_name = basename($file); # keep the .ini suffix
  391. my $preset_new = Slic3r::GUI::Tab::Preset->new(
  392. file => $file,
  393. name => $preset_name,
  394. external => 1,
  395. );
  396. # Try to load the config file before it is entered into the list. If the loading fails, an undef is returned.
  397. return undef if ! defined $preset_new->config;
  398. push @{$self->{presets}}, $preset_new;
  399. $self->{presets_choice}->Append($preset_name);
  400. $i = $#{$self->{presets}};
  401. }
  402. $self->{presets_choice}->SetSelection($i - $self->{default_suppressed});
  403. $self->on_select_preset;
  404. $self->_on_presets_changed;
  405. return 1;
  406. }
  407. sub load_config {
  408. my $self = shift;
  409. my ($config) = @_;
  410. my %keys_modified = ();
  411. foreach my $opt_key (@{$self->{config}->diff($config)}) {
  412. $self->{config}->set($opt_key, $config->get($opt_key));
  413. $keys_modified{$opt_key} = 1;
  414. }
  415. if (keys(%keys_modified)) {
  416. $self->update_dirty;
  417. # Initialize UI components with the config values.
  418. $self->reload_config;
  419. $self->_update(\%keys_modified);
  420. }
  421. }
  422. sub get_preset_config {
  423. my ($self, $preset) = @_;
  424. return $preset->config($self->{config}->get_keys);
  425. }
  426. sub get_field {
  427. my ($self, $opt_key, $opt_index) = @_;
  428. foreach my $page (@{ $self->{pages} }) {
  429. my $field = $page->get_field($opt_key, $opt_index);
  430. return $field if defined $field;
  431. }
  432. return undef;
  433. }
  434. sub set_value {
  435. my $self = shift;
  436. my ($opt_key, $value) = @_;
  437. my $changed = 0;
  438. foreach my $page (@{ $self->{pages} }) {
  439. $changed = 1 if $page->set_value($opt_key, $value);
  440. }
  441. return $changed;
  442. }
  443. package Slic3r::GUI::Tab::Print;
  444. use base 'Slic3r::GUI::Tab';
  445. use List::Util qw(first);
  446. use Wx qw(:icon :dialog :id);
  447. sub name { 'print' }
  448. sub title { 'Print Settings' }
  449. sub build {
  450. my $self = shift;
  451. $self->init_config_options(qw(
  452. layer_height first_layer_height
  453. perimeters spiral_vase
  454. top_solid_layers bottom_solid_layers
  455. extra_perimeters ensure_vertical_shell_thickness avoid_crossing_perimeters thin_walls overhangs
  456. seam_position external_perimeters_first
  457. fill_density fill_pattern top_fill_pattern bottom_fill_pattern
  458. infill_every_layers infill_only_where_needed
  459. solid_infill_every_layers fill_angle bridge_angle solid_infill_below_area
  460. only_retract_when_crossing_perimeters infill_first
  461. max_print_speed max_volumetric_speed
  462. max_volumetric_extrusion_rate_slope_positive max_volumetric_extrusion_rate_slope_negative
  463. perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed
  464. solid_infill_speed top_solid_infill_speed support_material_speed
  465. support_material_xy_spacing
  466. support_material_interface_speed bridge_speed gap_fill_speed
  467. travel_speed
  468. first_layer_speed
  469. perimeter_acceleration infill_acceleration bridge_acceleration
  470. first_layer_acceleration default_acceleration
  471. skirts skirt_distance skirt_height min_skirt_length
  472. brim_width
  473. support_material support_material_threshold support_material_enforce_layers
  474. raft_layers
  475. support_material_pattern support_material_with_sheath support_material_spacing support_material_synchronize_layers support_material_angle
  476. support_material_interface_layers support_material_interface_spacing support_material_interface_contact_loops
  477. support_material_contact_distance support_material_buildplate_only dont_support_bridges
  478. notes
  479. complete_objects extruder_clearance_radius extruder_clearance_height
  480. gcode_comments output_filename_format
  481. post_process
  482. perimeter_extruder infill_extruder solid_infill_extruder
  483. support_material_extruder support_material_interface_extruder
  484. ooze_prevention standby_temperature_delta
  485. interface_shells
  486. extrusion_width first_layer_extrusion_width perimeter_extrusion_width
  487. external_perimeter_extrusion_width infill_extrusion_width solid_infill_extrusion_width
  488. top_infill_extrusion_width support_material_extrusion_width
  489. infill_overlap bridge_flow_ratio
  490. clip_multipart_objects elefant_foot_compensation xy_size_compensation threads resolution
  491. wipe_tower wipe_tower_x wipe_tower_y wipe_tower_width wipe_tower_per_color_wipe
  492. ));
  493. $self->{config}->set('print_settings_id', '');
  494. {
  495. my $page = $self->add_options_page('Layers and perimeters', 'layers.png');
  496. {
  497. my $optgroup = $page->new_optgroup('Layer height');
  498. $optgroup->append_single_option_line('layer_height');
  499. $optgroup->append_single_option_line('first_layer_height');
  500. }
  501. {
  502. my $optgroup = $page->new_optgroup('Vertical shells');
  503. $optgroup->append_single_option_line('perimeters');
  504. $optgroup->append_single_option_line('spiral_vase');
  505. }
  506. {
  507. my $optgroup = $page->new_optgroup('Horizontal shells');
  508. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  509. label => 'Solid layers',
  510. );
  511. $line->append_option($optgroup->get_option('top_solid_layers'));
  512. $line->append_option($optgroup->get_option('bottom_solid_layers'));
  513. $optgroup->append_line($line);
  514. }
  515. {
  516. my $optgroup = $page->new_optgroup('Quality (slower slicing)');
  517. $optgroup->append_single_option_line('extra_perimeters');
  518. $optgroup->append_single_option_line('ensure_vertical_shell_thickness');
  519. $optgroup->append_single_option_line('avoid_crossing_perimeters');
  520. $optgroup->append_single_option_line('thin_walls');
  521. $optgroup->append_single_option_line('overhangs');
  522. }
  523. {
  524. my $optgroup = $page->new_optgroup('Advanced');
  525. $optgroup->append_single_option_line('seam_position');
  526. $optgroup->append_single_option_line('external_perimeters_first');
  527. }
  528. }
  529. {
  530. my $page = $self->add_options_page('Infill', 'infill.png');
  531. {
  532. my $optgroup = $page->new_optgroup('Infill');
  533. $optgroup->append_single_option_line('fill_density');
  534. $optgroup->append_single_option_line('fill_pattern');
  535. $optgroup->append_single_option_line('top_fill_pattern');
  536. $optgroup->append_single_option_line('bottom_fill_pattern');
  537. }
  538. {
  539. my $optgroup = $page->new_optgroup('Reducing printing time');
  540. $optgroup->append_single_option_line('infill_every_layers');
  541. $optgroup->append_single_option_line('infill_only_where_needed');
  542. }
  543. {
  544. my $optgroup = $page->new_optgroup('Advanced');
  545. $optgroup->append_single_option_line('solid_infill_every_layers');
  546. $optgroup->append_single_option_line('fill_angle');
  547. $optgroup->append_single_option_line('solid_infill_below_area');
  548. $optgroup->append_single_option_line('bridge_angle');
  549. $optgroup->append_single_option_line('only_retract_when_crossing_perimeters');
  550. $optgroup->append_single_option_line('infill_first');
  551. }
  552. }
  553. {
  554. my $page = $self->add_options_page('Skirt and brim', 'box.png');
  555. {
  556. my $optgroup = $page->new_optgroup('Skirt');
  557. $optgroup->append_single_option_line('skirts');
  558. $optgroup->append_single_option_line('skirt_distance');
  559. $optgroup->append_single_option_line('skirt_height');
  560. $optgroup->append_single_option_line('min_skirt_length');
  561. }
  562. {
  563. my $optgroup = $page->new_optgroup('Brim');
  564. $optgroup->append_single_option_line('brim_width');
  565. }
  566. }
  567. {
  568. my $page = $self->add_options_page('Support material', 'building.png');
  569. {
  570. my $optgroup = $page->new_optgroup('Support material');
  571. $optgroup->append_single_option_line('support_material');
  572. $optgroup->append_single_option_line('support_material_threshold');
  573. $optgroup->append_single_option_line('support_material_enforce_layers');
  574. }
  575. {
  576. my $optgroup = $page->new_optgroup('Raft');
  577. $optgroup->append_single_option_line('raft_layers');
  578. # $optgroup->append_single_option_line('raft_contact_distance');
  579. }
  580. {
  581. my $optgroup = $page->new_optgroup('Options for support material and raft');
  582. $optgroup->append_single_option_line('support_material_contact_distance');
  583. $optgroup->append_single_option_line('support_material_pattern');
  584. $optgroup->append_single_option_line('support_material_with_sheath');
  585. $optgroup->append_single_option_line('support_material_spacing');
  586. $optgroup->append_single_option_line('support_material_angle');
  587. $optgroup->append_single_option_line('support_material_interface_layers');
  588. $optgroup->append_single_option_line('support_material_interface_spacing');
  589. $optgroup->append_single_option_line('support_material_interface_contact_loops');
  590. $optgroup->append_single_option_line('support_material_buildplate_only');
  591. $optgroup->append_single_option_line('support_material_xy_spacing');
  592. $optgroup->append_single_option_line('dont_support_bridges');
  593. $optgroup->append_single_option_line('support_material_synchronize_layers');
  594. }
  595. }
  596. {
  597. my $page = $self->add_options_page('Speed', 'time.png');
  598. {
  599. my $optgroup = $page->new_optgroup('Speed for print moves');
  600. $optgroup->append_single_option_line('perimeter_speed');
  601. $optgroup->append_single_option_line('small_perimeter_speed');
  602. $optgroup->append_single_option_line('external_perimeter_speed');
  603. $optgroup->append_single_option_line('infill_speed');
  604. $optgroup->append_single_option_line('solid_infill_speed');
  605. $optgroup->append_single_option_line('top_solid_infill_speed');
  606. $optgroup->append_single_option_line('support_material_speed');
  607. $optgroup->append_single_option_line('support_material_interface_speed');
  608. $optgroup->append_single_option_line('bridge_speed');
  609. $optgroup->append_single_option_line('gap_fill_speed');
  610. }
  611. {
  612. my $optgroup = $page->new_optgroup('Speed for non-print moves');
  613. $optgroup->append_single_option_line('travel_speed');
  614. }
  615. {
  616. my $optgroup = $page->new_optgroup('Modifiers');
  617. $optgroup->append_single_option_line('first_layer_speed');
  618. }
  619. {
  620. my $optgroup = $page->new_optgroup('Acceleration control (advanced)');
  621. $optgroup->append_single_option_line('perimeter_acceleration');
  622. $optgroup->append_single_option_line('infill_acceleration');
  623. $optgroup->append_single_option_line('bridge_acceleration');
  624. $optgroup->append_single_option_line('first_layer_acceleration');
  625. $optgroup->append_single_option_line('default_acceleration');
  626. }
  627. {
  628. my $optgroup = $page->new_optgroup('Autospeed (advanced)');
  629. $optgroup->append_single_option_line('max_print_speed');
  630. $optgroup->append_single_option_line('max_volumetric_speed');
  631. $optgroup->append_single_option_line('max_volumetric_extrusion_rate_slope_positive');
  632. $optgroup->append_single_option_line('max_volumetric_extrusion_rate_slope_negative');
  633. }
  634. }
  635. {
  636. my $page = $self->add_options_page('Multiple Extruders', 'funnel.png');
  637. {
  638. my $optgroup = $page->new_optgroup('Extruders');
  639. $optgroup->append_single_option_line('perimeter_extruder');
  640. $optgroup->append_single_option_line('infill_extruder');
  641. $optgroup->append_single_option_line('solid_infill_extruder');
  642. $optgroup->append_single_option_line('support_material_extruder');
  643. $optgroup->append_single_option_line('support_material_interface_extruder');
  644. }
  645. {
  646. my $optgroup = $page->new_optgroup('Ooze prevention');
  647. $optgroup->append_single_option_line('ooze_prevention');
  648. $optgroup->append_single_option_line('standby_temperature_delta');
  649. }
  650. {
  651. my $optgroup = $page->new_optgroup('Wipe tower');
  652. $optgroup->append_single_option_line('wipe_tower');
  653. $optgroup->append_single_option_line('wipe_tower_x');
  654. $optgroup->append_single_option_line('wipe_tower_y');
  655. $optgroup->append_single_option_line('wipe_tower_width');
  656. $optgroup->append_single_option_line('wipe_tower_per_color_wipe');
  657. }
  658. {
  659. my $optgroup = $page->new_optgroup('Advanced');
  660. $optgroup->append_single_option_line('interface_shells');
  661. }
  662. }
  663. {
  664. my $page = $self->add_options_page('Advanced', 'wrench.png');
  665. {
  666. my $optgroup = $page->new_optgroup('Extrusion width',
  667. label_width => 180,
  668. );
  669. $optgroup->append_single_option_line('extrusion_width');
  670. $optgroup->append_single_option_line('first_layer_extrusion_width');
  671. $optgroup->append_single_option_line('perimeter_extrusion_width');
  672. $optgroup->append_single_option_line('external_perimeter_extrusion_width');
  673. $optgroup->append_single_option_line('infill_extrusion_width');
  674. $optgroup->append_single_option_line('solid_infill_extrusion_width');
  675. $optgroup->append_single_option_line('top_infill_extrusion_width');
  676. $optgroup->append_single_option_line('support_material_extrusion_width');
  677. }
  678. {
  679. my $optgroup = $page->new_optgroup('Overlap');
  680. $optgroup->append_single_option_line('infill_overlap');
  681. }
  682. {
  683. my $optgroup = $page->new_optgroup('Flow');
  684. $optgroup->append_single_option_line('bridge_flow_ratio');
  685. }
  686. {
  687. my $optgroup = $page->new_optgroup('Other');
  688. $optgroup->append_single_option_line('clip_multipart_objects');
  689. $optgroup->append_single_option_line('elefant_foot_compensation');
  690. $optgroup->append_single_option_line('xy_size_compensation');
  691. $optgroup->append_single_option_line('threads') if $Slic3r::have_threads;
  692. $optgroup->append_single_option_line('resolution');
  693. }
  694. }
  695. {
  696. my $page = $self->add_options_page('Output options', 'page_white_go.png');
  697. {
  698. my $optgroup = $page->new_optgroup('Sequential printing');
  699. $optgroup->append_single_option_line('complete_objects');
  700. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  701. label => 'Extruder clearance (mm)',
  702. );
  703. foreach my $opt_key (qw(extruder_clearance_radius extruder_clearance_height)) {
  704. my $option = $optgroup->get_option($opt_key);
  705. $option->width(60);
  706. $line->append_option($option);
  707. }
  708. $optgroup->append_line($line);
  709. }
  710. {
  711. my $optgroup = $page->new_optgroup('Output file');
  712. $optgroup->append_single_option_line('gcode_comments');
  713. {
  714. my $option = $optgroup->get_option('output_filename_format');
  715. $option->full_width(1);
  716. $optgroup->append_single_option_line($option);
  717. }
  718. }
  719. {
  720. my $optgroup = $page->new_optgroup('Post-processing scripts',
  721. label_width => 0,
  722. );
  723. my $option = $optgroup->get_option('post_process');
  724. $option->full_width(1);
  725. $option->height(50);
  726. $optgroup->append_single_option_line($option);
  727. }
  728. }
  729. {
  730. my $page = $self->add_options_page('Notes', 'note.png');
  731. {
  732. my $optgroup = $page->new_optgroup('Notes',
  733. label_width => 0,
  734. );
  735. my $option = $optgroup->get_option('notes');
  736. $option->full_width(1);
  737. $option->height(250);
  738. $optgroup->append_single_option_line($option);
  739. }
  740. }
  741. }
  742. # Slic3r::GUI::Tab::Print::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
  743. sub _update {
  744. # $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
  745. my ($self, $keys_modified) = @_;
  746. $keys_modified //= {};
  747. my $config = $self->{config};
  748. if ($config->spiral_vase && !($config->perimeters == 1 && $config->top_solid_layers == 0 && $config->fill_density == 0)) {
  749. my $dialog = Wx::MessageDialog->new($self,
  750. "The Spiral Vase mode requires:\n"
  751. . "- one perimeter\n"
  752. . "- no top solid layers\n"
  753. . "- 0% fill density\n"
  754. . "- no support material\n"
  755. . "- no ensure_vertical_shell_thickness\n"
  756. . "\nShall I adjust those settings in order to enable Spiral Vase?",
  757. 'Spiral Vase', wxICON_WARNING | wxYES | wxNO);
  758. my $new_conf = Slic3r::Config->new;
  759. if ($dialog->ShowModal() == wxID_YES) {
  760. $new_conf->set("perimeters", 1);
  761. $new_conf->set("top_solid_layers", 0);
  762. $new_conf->set("fill_density", 0);
  763. $new_conf->set("support_material", 0);
  764. $new_conf->set("ensure_vertical_shell_thickness", 0);
  765. } else {
  766. $new_conf->set("spiral_vase", 0);
  767. }
  768. $self->load_config($new_conf);
  769. }
  770. if ($config->wipe_tower &&
  771. ($config->first_layer_height != 0.2 || $config->layer_height < 0.15 || $config->layer_height > 0.35)) {
  772. my $dialog = Wx::MessageDialog->new($self,
  773. "The Wipe Tower currently supports only:\n"
  774. . "- first layer height 0.2mm\n"
  775. . "- layer height from 0.15mm to 0.35mm\n"
  776. . "\nShall I adjust those settings in order to enable the Wipe Tower?",
  777. 'Wipe Tower', wxICON_WARNING | wxYES | wxNO);
  778. my $new_conf = Slic3r::Config->new;
  779. if ($dialog->ShowModal() == wxID_YES) {
  780. $new_conf->set("first_layer_height", 0.2);
  781. $new_conf->set("layer_height", 0.15) if $config->layer_height < 0.15;
  782. $new_conf->set("layer_height", 0.35) if $config->layer_height > 0.35;
  783. } else {
  784. $new_conf->set("wipe_tower", 0);
  785. }
  786. $self->load_config($new_conf);
  787. }
  788. if ($config->wipe_tower && $config->support_material && $config->support_material_contact_distance > 0. &&
  789. ($config->support_material_extruder != 0 || $config->support_material_interface_extruder != 0)) {
  790. my $dialog = Wx::MessageDialog->new($self,
  791. "The Wipe Tower currently supports the non-soluble supports only\n"
  792. . "if they are printed with the current extruder without triggering a tool change.\n"
  793. . "(both support_material_extruder and support_material_interface_extruder need to be set to 0).\n"
  794. . "\nShall I adjust those settings in order to enable the Wipe Tower?",
  795. 'Wipe Tower', wxICON_WARNING | wxYES | wxNO);
  796. my $new_conf = Slic3r::Config->new;
  797. if ($dialog->ShowModal() == wxID_YES) {
  798. $new_conf->set("support_material_extruder", 0);
  799. $new_conf->set("support_material_interface_extruder", 0);
  800. } else {
  801. $new_conf->set("wipe_tower", 0);
  802. }
  803. $self->load_config($new_conf);
  804. }
  805. if ($config->wipe_tower && $config->support_material && $config->support_material_contact_distance == 0 &&
  806. ! $config->support_material_synchronize_layers) {
  807. my $dialog = Wx::MessageDialog->new($self,
  808. "For the Wipe Tower to work with the soluble supports, the support layers\n"
  809. . "need to be synchronized with the object layers.\n"
  810. . "\nShall I synchronize support layers in order to enable the Wipe Tower?",
  811. 'Wipe Tower', wxICON_WARNING | wxYES | wxNO);
  812. my $new_conf = Slic3r::Config->new;
  813. if ($dialog->ShowModal() == wxID_YES) {
  814. $new_conf->set("support_material_synchronize_layers", 1);
  815. } else {
  816. $new_conf->set("wipe_tower", 0);
  817. }
  818. $self->load_config($new_conf);
  819. }
  820. if ($keys_modified->{'layer_height'}) {
  821. # If the user had set the variable layer height, reset it and let the user know.
  822. }
  823. if ($config->support_material) {
  824. # Ask only once.
  825. if (! $self->{support_material_overhangs_queried}) {
  826. $self->{support_material_overhangs_queried} = 1;
  827. if ($config->overhangs != 1) {
  828. my $dialog = Wx::MessageDialog->new($self,
  829. "Supports work better, if the following feature is enabled:\n"
  830. . "- Detect bridging perimeters\n"
  831. . "\nShall I adjust those settings for supports?",
  832. 'Support Generator', wxICON_WARNING | wxYES | wxNO | wxCANCEL);
  833. my $answer = $dialog->ShowModal();
  834. my $new_conf = Slic3r::Config->new;
  835. if ($answer == wxID_YES) {
  836. # Enable "detect bridging perimeters".
  837. $new_conf->set("overhangs", 1);
  838. } elsif ($answer == wxID_NO) {
  839. # Do nothing, leave supports on and "detect bridging perimeters" off.
  840. } elsif ($answer == wxID_CANCEL) {
  841. # Disable supports.
  842. $new_conf->set("support_material", 0);
  843. $self->{support_material_overhangs_queried} = 0;
  844. }
  845. $self->load_config($new_conf);
  846. }
  847. }
  848. } else {
  849. $self->{support_material_overhangs_queried} = 0;
  850. }
  851. if ($config->fill_density == 100
  852. && (!first { $_ eq $config->fill_pattern } @{$Slic3r::Config::Options->{top_fill_pattern}{values}}
  853. || !first { $_ eq $config->fill_pattern } @{$Slic3r::Config::Options->{bottom_fill_pattern}{values}})) {
  854. my $dialog = Wx::MessageDialog->new($self,
  855. "The " . $config->fill_pattern . " infill pattern is not supposed to work at 100% density.\n"
  856. . "\nShall I switch to rectilinear fill pattern?",
  857. 'Infill', wxICON_WARNING | wxYES | wxNO);
  858. my $new_conf = Slic3r::Config->new;
  859. if ($dialog->ShowModal() == wxID_YES) {
  860. $new_conf->set("fill_pattern", 'rectilinear');
  861. $new_conf->set("fill_density", 100);
  862. } else {
  863. $new_conf->set("fill_density", 40);
  864. }
  865. $self->load_config($new_conf);
  866. }
  867. my $have_perimeters = $config->perimeters > 0;
  868. $self->get_field($_)->toggle($have_perimeters)
  869. for qw(extra_perimeters ensure_vertical_shell_thickness thin_walls overhangs seam_position external_perimeters_first
  870. external_perimeter_extrusion_width
  871. perimeter_speed small_perimeter_speed external_perimeter_speed);
  872. my $have_infill = $config->fill_density > 0;
  873. # infill_extruder uses the same logic as in Print::extruders()
  874. $self->get_field($_)->toggle($have_infill)
  875. for qw(fill_pattern infill_every_layers infill_only_where_needed solid_infill_every_layers
  876. solid_infill_below_area infill_extruder);
  877. my $have_solid_infill = ($config->top_solid_layers > 0) || ($config->bottom_solid_layers > 0);
  878. # solid_infill_extruder uses the same logic as in Print::extruders()
  879. $self->get_field($_)->toggle($have_solid_infill)
  880. for qw(infill_first solid_infill_extruder solid_infill_extrusion_width
  881. solid_infill_speed);
  882. $self->get_field($_)->toggle($have_infill || $have_solid_infill)
  883. for qw(fill_angle bridge_angle infill_extrusion_width infill_speed bridge_speed);
  884. $self->get_field('gap_fill_speed')->toggle($have_perimeters && $have_infill);
  885. my $have_top_solid_infill = $config->top_solid_layers > 0;
  886. $self->get_field($_)->toggle($have_top_solid_infill)
  887. for qw(top_fill_pattern top_infill_extrusion_width top_solid_infill_speed);
  888. my $have_bottom_solid_infill = $config->bottom_solid_layers > 0;
  889. $self->get_field($_)->toggle($have_bottom_solid_infill)
  890. for qw(bottom_fill_pattern);
  891. my $have_default_acceleration = $config->default_acceleration > 0;
  892. $self->get_field($_)->toggle($have_default_acceleration)
  893. for qw(perimeter_acceleration infill_acceleration bridge_acceleration first_layer_acceleration);
  894. my $have_skirt = $config->skirts > 0 || $config->min_skirt_length > 0;
  895. $self->get_field($_)->toggle($have_skirt)
  896. for qw(skirt_distance skirt_height);
  897. my $have_brim = $config->brim_width > 0;
  898. # perimeter_extruder uses the same logic as in Print::extruders()
  899. $self->get_field('perimeter_extruder')->toggle($have_perimeters || $have_brim);
  900. my $have_raft = $config->raft_layers > 0;
  901. my $have_support_material = $config->support_material || $have_raft;
  902. my $have_support_interface = $config->support_material_interface_layers > 0;
  903. my $have_support_soluble = $have_support_material && $config->support_material_contact_distance == 0;
  904. $self->get_field($_)->toggle($have_support_material)
  905. for qw(support_material_threshold support_material_pattern support_material_with_sheath
  906. support_material_spacing support_material_angle
  907. support_material_interface_layers dont_support_bridges
  908. support_material_extrusion_width support_material_contact_distance support_material_xy_spacing);
  909. $self->get_field($_)->toggle($have_support_material && $have_support_interface)
  910. for qw(support_material_interface_spacing support_material_interface_extruder
  911. support_material_interface_speed support_material_interface_contact_loops);
  912. $self->get_field('support_material_synchronize_layers')->toggle($have_support_soluble);
  913. $self->get_field('perimeter_extrusion_width')->toggle($have_perimeters || $have_skirt || $have_brim);
  914. $self->get_field('support_material_extruder')->toggle($have_support_material || $have_skirt);
  915. $self->get_field('support_material_speed')->toggle($have_support_material || $have_brim || $have_skirt);
  916. my $have_sequential_printing = $config->complete_objects;
  917. $self->get_field($_)->toggle($have_sequential_printing)
  918. for qw(extruder_clearance_radius extruder_clearance_height);
  919. my $have_ooze_prevention = $config->ooze_prevention;
  920. $self->get_field($_)->toggle($have_ooze_prevention)
  921. for qw(standby_temperature_delta);
  922. my $have_wipe_tower = $config->wipe_tower;
  923. $self->get_field($_)->toggle($have_wipe_tower)
  924. for qw(wipe_tower_x wipe_tower_y wipe_tower_width wipe_tower_per_color_wipe);
  925. }
  926. sub hidden_options { !$Slic3r::have_threads ? qw(threads) : () }
  927. package Slic3r::GUI::Tab::Filament;
  928. use base 'Slic3r::GUI::Tab';
  929. sub name { 'filament' }
  930. sub title { 'Filament Settings' }
  931. sub build {
  932. my $self = shift;
  933. $self->init_config_options(qw(
  934. filament_colour filament_diameter filament_type filament_soluble filament_notes filament_max_volumetric_speed extrusion_multiplier filament_density filament_cost
  935. temperature first_layer_temperature bed_temperature first_layer_bed_temperature
  936. fan_always_on cooling
  937. min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers
  938. fan_below_layer_time slowdown_below_layer_time min_print_speed
  939. start_filament_gcode end_filament_gcode
  940. ));
  941. $self->{config}->set('filament_settings_id', '');
  942. {
  943. my $page = $self->add_options_page('Filament', 'spool.png');
  944. {
  945. my $optgroup = $page->new_optgroup('Filament');
  946. $optgroup->append_single_option_line('filament_colour', 0);
  947. $optgroup->append_single_option_line('filament_diameter', 0);
  948. $optgroup->append_single_option_line('extrusion_multiplier', 0);
  949. $optgroup->append_single_option_line('filament_density', 0);
  950. $optgroup->append_single_option_line('filament_cost', 0);
  951. }
  952. {
  953. my $optgroup = $page->new_optgroup('Temperature (°C)');
  954. {
  955. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  956. label => 'Extruder',
  957. );
  958. $line->append_option($optgroup->get_option('first_layer_temperature', 0));
  959. $line->append_option($optgroup->get_option('temperature', 0));
  960. $optgroup->append_line($line);
  961. }
  962. {
  963. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  964. label => 'Bed',
  965. );
  966. $line->append_option($optgroup->get_option('first_layer_bed_temperature', 0));
  967. $line->append_option($optgroup->get_option('bed_temperature', 0));
  968. $optgroup->append_line($line);
  969. }
  970. }
  971. }
  972. {
  973. my $page = $self->add_options_page('Cooling', 'hourglass.png');
  974. {
  975. my $optgroup = $page->new_optgroup('Enable');
  976. $optgroup->append_single_option_line('fan_always_on', 0);
  977. $optgroup->append_single_option_line('cooling', 0);
  978. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  979. label => '',
  980. full_width => 1,
  981. widget => sub {
  982. my ($parent) = @_;
  983. return $self->{description_line} = Slic3r::GUI::OptionsGroup::StaticText->new($parent);
  984. },
  985. );
  986. $optgroup->append_line($line);
  987. }
  988. {
  989. my $optgroup = $page->new_optgroup('Fan settings');
  990. {
  991. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  992. label => 'Fan speed',
  993. );
  994. $line->append_option($optgroup->get_option('min_fan_speed', 0));
  995. $line->append_option($optgroup->get_option('max_fan_speed', 0));
  996. $optgroup->append_line($line);
  997. }
  998. $optgroup->append_single_option_line('bridge_fan_speed', 0);
  999. $optgroup->append_single_option_line('disable_fan_first_layers', 0);
  1000. }
  1001. {
  1002. my $optgroup = $page->new_optgroup('Cooling thresholds',
  1003. label_width => 250,
  1004. );
  1005. $optgroup->append_single_option_line('fan_below_layer_time', 0);
  1006. $optgroup->append_single_option_line('slowdown_below_layer_time', 0);
  1007. $optgroup->append_single_option_line('min_print_speed', 0);
  1008. }
  1009. }
  1010. {
  1011. my $page = $self->add_options_page('Advanced', 'wrench.png');
  1012. {
  1013. my $optgroup = $page->new_optgroup('Filament properties');
  1014. $optgroup->append_single_option_line('filament_type', 0);
  1015. $optgroup->append_single_option_line('filament_soluble', 0);
  1016. $optgroup = $page->new_optgroup('Print speed override');
  1017. $optgroup->append_single_option_line('filament_max_volumetric_speed', 0);
  1018. }
  1019. }
  1020. {
  1021. my $page = $self->add_options_page('Custom G-code', 'cog.png');
  1022. {
  1023. my $optgroup = $page->new_optgroup('Start G-code',
  1024. label_width => 0,
  1025. );
  1026. my $option = $optgroup->get_option('start_filament_gcode', 0);
  1027. $option->full_width(1);
  1028. $option->height(150);
  1029. $optgroup->append_single_option_line($option);
  1030. }
  1031. {
  1032. my $optgroup = $page->new_optgroup('End G-code',
  1033. label_width => 0,
  1034. );
  1035. my $option = $optgroup->get_option('end_filament_gcode', 0);
  1036. $option->full_width(1);
  1037. $option->height(150);
  1038. $optgroup->append_single_option_line($option);
  1039. }
  1040. }
  1041. {
  1042. my $page = $self->add_options_page('Notes', 'note.png');
  1043. {
  1044. my $optgroup = $page->new_optgroup('Notes',
  1045. label_width => 0,
  1046. );
  1047. my $option = $optgroup->get_option('filament_notes', 0);
  1048. $option->full_width(1);
  1049. $option->height(250);
  1050. $optgroup->append_single_option_line($option);
  1051. }
  1052. }
  1053. }
  1054. # Slic3r::GUI::Tab::Filament::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
  1055. sub _update {
  1056. # $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
  1057. my ($self, $keys_modified) = @_;
  1058. $self->_update_description;
  1059. my $cooling = $self->{config}->cooling->[0];
  1060. my $fan_always_on = $cooling || $self->{config}->fan_always_on->[0];
  1061. $self->get_field($_, 0)->toggle($cooling)
  1062. for qw(max_fan_speed fan_below_layer_time slowdown_below_layer_time min_print_speed);
  1063. $self->get_field($_, 0)->toggle($fan_always_on)
  1064. for qw(min_fan_speed disable_fan_first_layers);
  1065. }
  1066. sub _update_description {
  1067. my $self = shift;
  1068. my $config = $self->config;
  1069. my $msg = "";
  1070. my $fan_other_layers = $config->fan_always_on->[0]
  1071. ? sprintf "will always run at %d%%%s.", $config->min_fan_speed->[0],
  1072. ($config->disable_fan_first_layers->[0] > 1
  1073. ? " except for the first " . $config->disable_fan_first_layers->[0] . " layers"
  1074. : $config->disable_fan_first_layers->[0] == 1
  1075. ? " except for the first layer"
  1076. : "")
  1077. : "will be turned off.";
  1078. if ($config->cooling->[0]) {
  1079. $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).",
  1080. $config->slowdown_below_layer_time->[0], $config->max_fan_speed->[0], $config->slowdown_below_layer_time->[0], $config->min_print_speed->[0];
  1081. if ($config->fan_below_layer_time->[0] > $config->slowdown_below_layer_time->[0]) {
  1082. $msg .= sprintf "\nIf estimated layer time is greater, but still below ~%ds, fan will run at a proportionally decreasing speed between %d%% and %d%%.",
  1083. $config->fan_below_layer_time->[0], $config->max_fan_speed->[0], $config->min_fan_speed->[0];
  1084. }
  1085. $msg .= "\nDuring the other layers, fan $fan_other_layers"
  1086. } else {
  1087. $msg = "Fan $fan_other_layers";
  1088. }
  1089. $self->{description_line}->SetText($msg);
  1090. }
  1091. package Slic3r::GUI::Tab::Printer;
  1092. use base 'Slic3r::GUI::Tab';
  1093. use Wx qw(wxTheApp :sizer :button :bitmap :misc :id :icon :dialog);
  1094. use Wx::Event qw(EVT_BUTTON);
  1095. sub name { 'printer' }
  1096. sub title { 'Printer Settings' }
  1097. sub build {
  1098. my $self = shift;
  1099. my (%params) = @_;
  1100. $self->init_config_options(qw(
  1101. bed_shape z_offset
  1102. gcode_flavor use_relative_e_distances
  1103. serial_port serial_speed
  1104. octoprint_host octoprint_apikey
  1105. use_firmware_retraction
  1106. use_volumetric_e variable_layer_height
  1107. single_extruder_multi_material start_gcode end_gcode before_layer_gcode layer_gcode toolchange_gcode
  1108. nozzle_diameter extruder_offset
  1109. retract_length retract_lift retract_speed deretract_speed retract_before_wipe retract_restart_extra retract_before_travel retract_layer_change wipe
  1110. retract_length_toolchange retract_restart_extra_toolchange
  1111. extruder_colour printer_notes
  1112. ));
  1113. $self->{config}->set('printer_settings_id', '');
  1114. my $bed_shape_widget = sub {
  1115. my ($parent) = @_;
  1116. my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize,
  1117. wxBU_LEFT | wxBU_EXACTFIT);
  1118. $btn->SetFont($Slic3r::GUI::small_font);
  1119. $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG));
  1120. my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  1121. $sizer->Add($btn);
  1122. EVT_BUTTON($self, $btn, sub {
  1123. my $dlg = Slic3r::GUI::BedShapeDialog->new($self, $self->{config}->bed_shape);
  1124. if ($dlg->ShowModal == wxID_OK) {
  1125. my $value = $dlg->GetValue;
  1126. $self->{config}->set('bed_shape', $value);
  1127. $self->update_dirty;
  1128. $self->_on_value_change('bed_shape', $value);
  1129. }
  1130. });
  1131. return $sizer;
  1132. };
  1133. $self->{extruders_count} = 1;
  1134. {
  1135. my $page = $self->add_options_page('General', 'printer_empty.png');
  1136. {
  1137. my $optgroup = $page->new_optgroup('Size and coordinates');
  1138. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1139. label => 'Bed shape',
  1140. widget => $bed_shape_widget,
  1141. );
  1142. $optgroup->append_line($line);
  1143. $optgroup->append_single_option_line('z_offset');
  1144. }
  1145. {
  1146. my $optgroup = $page->new_optgroup('Capabilities');
  1147. {
  1148. my $option = Slic3r::GUI::OptionsGroup::Option->new(
  1149. opt_id => 'extruders_count',
  1150. type => 'i',
  1151. default => 1,
  1152. label => 'Extruders',
  1153. tooltip => 'Number of extruders of the printer.',
  1154. min => 1,
  1155. );
  1156. $optgroup->append_single_option_line($option);
  1157. $optgroup->append_single_option_line('single_extruder_multi_material');
  1158. }
  1159. $optgroup->on_change(sub {
  1160. my ($opt_id) = @_;
  1161. if ($opt_id eq 'extruders_count') {
  1162. wxTheApp->CallAfter(sub {
  1163. $self->_extruders_count_changed($optgroup->get_value('extruders_count'));
  1164. });
  1165. $self->update_dirty;
  1166. }
  1167. });
  1168. }
  1169. if (!$params{no_controller})
  1170. {
  1171. my $optgroup = $page->new_optgroup('USB/Serial connection');
  1172. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1173. label => 'Serial port',
  1174. );
  1175. my $serial_port = $optgroup->get_option('serial_port');
  1176. $serial_port->side_widget(sub {
  1177. my ($parent) = @_;
  1178. my $btn = Wx::BitmapButton->new($parent, -1, Wx::Bitmap->new($Slic3r::var->("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG),
  1179. wxDefaultPosition, wxDefaultSize, &Wx::wxBORDER_NONE);
  1180. $btn->SetToolTipString("Rescan serial ports")
  1181. if $btn->can('SetToolTipString');
  1182. EVT_BUTTON($self, $btn, \&_update_serial_ports);
  1183. return $btn;
  1184. });
  1185. my $serial_test = sub {
  1186. my ($parent) = @_;
  1187. my $btn = $self->{serial_test_btn} = Wx::Button->new($parent, -1,
  1188. "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
  1189. $btn->SetFont($Slic3r::GUI::small_font);
  1190. $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("wrench.png"), wxBITMAP_TYPE_PNG));
  1191. EVT_BUTTON($self, $btn, sub {
  1192. my $sender = Slic3r::GCode::Sender->new;
  1193. my $res = $sender->connect(
  1194. $self->{config}->serial_port,
  1195. $self->{config}->serial_speed,
  1196. );
  1197. if ($res && $sender->wait_connected) {
  1198. Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!");
  1199. } else {
  1200. Slic3r::GUI::show_error($self, "Connection failed.");
  1201. }
  1202. });
  1203. return $btn;
  1204. };
  1205. $line->append_option($serial_port);
  1206. $line->append_option($optgroup->get_option('serial_speed'));
  1207. $line->append_widget($serial_test);
  1208. $optgroup->append_line($line);
  1209. }
  1210. {
  1211. my $optgroup = $page->new_optgroup('OctoPrint upload');
  1212. # append two buttons to the Host line
  1213. my $octoprint_host_browse = sub {
  1214. my ($parent) = @_;
  1215. my $btn = Wx::Button->new($parent, -1, "Browse…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  1216. $btn->SetFont($Slic3r::GUI::small_font);
  1217. $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("zoom.png"), wxBITMAP_TYPE_PNG));
  1218. if (!eval "use Net::Bonjour; 1") {
  1219. $btn->Disable;
  1220. }
  1221. EVT_BUTTON($self, $btn, sub {
  1222. # look for devices
  1223. my $entries;
  1224. {
  1225. my $res = Net::Bonjour->new('http');
  1226. $res->discover;
  1227. $entries = [ $res->entries ];
  1228. }
  1229. if (@{$entries}) {
  1230. my $dlg = Slic3r::GUI::BonjourBrowser->new($self, $entries);
  1231. if ($dlg->ShowModal == wxID_OK) {
  1232. my $value = $dlg->GetValue . ":" . $dlg->GetPort;
  1233. $self->{config}->set('octoprint_host', $value);
  1234. $self->update_dirty;
  1235. $self->_on_value_change('octoprint_host', $value);
  1236. $self->reload_config;
  1237. }
  1238. } else {
  1239. Wx::MessageDialog->new($self, 'No Bonjour device found', 'Device Browser', wxOK | wxICON_INFORMATION)->ShowModal;
  1240. }
  1241. });
  1242. return $btn;
  1243. };
  1244. my $octoprint_host_test = sub {
  1245. my ($parent) = @_;
  1246. my $btn = $self->{octoprint_host_test_btn} = Wx::Button->new($parent, -1,
  1247. "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
  1248. $btn->SetFont($Slic3r::GUI::small_font);
  1249. $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("wrench.png"), wxBITMAP_TYPE_PNG));
  1250. EVT_BUTTON($self, $btn, sub {
  1251. my $ua = LWP::UserAgent->new;
  1252. $ua->timeout(10);
  1253. my $res = $ua->get(
  1254. "http://" . $self->{config}->octoprint_host . "/api/version",
  1255. 'X-Api-Key' => $self->{config}->octoprint_apikey,
  1256. );
  1257. if ($res->is_success) {
  1258. Slic3r::GUI::show_info($self, "Connection to OctoPrint works correctly.", "Success!");
  1259. } else {
  1260. Slic3r::GUI::show_error($self,
  1261. "I wasn't able to connect to OctoPrint (" . $res->status_line . "). "
  1262. . "Check hostname and OctoPrint version (at least 1.1.0 is required).");
  1263. }
  1264. });
  1265. return $btn;
  1266. };
  1267. my $host_line = $optgroup->create_single_option_line('octoprint_host');
  1268. $host_line->append_widget($octoprint_host_browse);
  1269. $host_line->append_widget($octoprint_host_test);
  1270. $optgroup->append_line($host_line);
  1271. $optgroup->append_single_option_line('octoprint_apikey');
  1272. }
  1273. {
  1274. my $optgroup = $page->new_optgroup('Firmware');
  1275. $optgroup->append_single_option_line('gcode_flavor');
  1276. }
  1277. {
  1278. my $optgroup = $page->new_optgroup('Advanced');
  1279. $optgroup->append_single_option_line('use_relative_e_distances');
  1280. $optgroup->append_single_option_line('use_firmware_retraction');
  1281. $optgroup->append_single_option_line('use_volumetric_e');
  1282. $optgroup->append_single_option_line('variable_layer_height');
  1283. }
  1284. }
  1285. {
  1286. my $page = $self->add_options_page('Custom G-code', 'cog.png');
  1287. {
  1288. my $optgroup = $page->new_optgroup('Start G-code',
  1289. label_width => 0,
  1290. );
  1291. my $option = $optgroup->get_option('start_gcode');
  1292. $option->full_width(1);
  1293. $option->height(150);
  1294. $optgroup->append_single_option_line($option);
  1295. }
  1296. {
  1297. my $optgroup = $page->new_optgroup('End G-code',
  1298. label_width => 0,
  1299. );
  1300. my $option = $optgroup->get_option('end_gcode');
  1301. $option->full_width(1);
  1302. $option->height(150);
  1303. $optgroup->append_single_option_line($option);
  1304. }
  1305. {
  1306. my $optgroup = $page->new_optgroup('Before layer change G-code',
  1307. label_width => 0,
  1308. );
  1309. my $option = $optgroup->get_option('before_layer_gcode');
  1310. $option->full_width(1);
  1311. $option->height(150);
  1312. $optgroup->append_single_option_line($option);
  1313. }
  1314. {
  1315. my $optgroup = $page->new_optgroup('After layer change G-code',
  1316. label_width => 0,
  1317. );
  1318. my $option = $optgroup->get_option('layer_gcode');
  1319. $option->full_width(1);
  1320. $option->height(150);
  1321. $optgroup->append_single_option_line($option);
  1322. }
  1323. {
  1324. my $optgroup = $page->new_optgroup('Tool change G-code',
  1325. label_width => 0,
  1326. );
  1327. my $option = $optgroup->get_option('toolchange_gcode');
  1328. $option->full_width(1);
  1329. $option->height(150);
  1330. $optgroup->append_single_option_line($option);
  1331. }
  1332. }
  1333. {
  1334. my $page = $self->add_options_page('Notes', 'note.png');
  1335. {
  1336. my $optgroup = $page->new_optgroup('Notes',
  1337. label_width => 0,
  1338. );
  1339. my $option = $optgroup->get_option('printer_notes');
  1340. $option->full_width(1);
  1341. $option->height(250);
  1342. $optgroup->append_single_option_line($option);
  1343. }
  1344. }
  1345. $self->{extruder_pages} = [];
  1346. $self->_build_extruder_pages;
  1347. $self->_update_serial_ports if (!$params{no_controller});
  1348. }
  1349. sub _update_serial_ports {
  1350. my ($self) = @_;
  1351. $self->get_field('serial_port')->set_values([ wxTheApp->scan_serial_ports ]);
  1352. }
  1353. sub _extruders_count_changed {
  1354. my ($self, $extruders_count) = @_;
  1355. $self->{extruders_count} = $extruders_count;
  1356. $self->_build_extruder_pages;
  1357. $self->_on_value_change('extruders_count', $extruders_count);
  1358. }
  1359. sub _extruder_options {
  1360. qw(nozzle_diameter min_layer_height max_layer_height extruder_offset
  1361. retract_length retract_lift retract_lift_above retract_lift_below retract_speed deretract_speed
  1362. retract_before_wipe retract_restart_extra retract_before_travel wipe
  1363. retract_layer_change retract_length_toolchange retract_restart_extra_toolchange extruder_colour) }
  1364. sub _build_extruder_pages {
  1365. my $self = shift;
  1366. my $default_config = Slic3r::Config::Full->new;
  1367. foreach my $extruder_idx (@{$self->{extruder_pages}} .. $self->{extruders_count}-1) {
  1368. # extend options
  1369. foreach my $opt_key ($self->_extruder_options) {
  1370. my $values = $self->{config}->get($opt_key);
  1371. if (!defined $values) {
  1372. $values = [ $default_config->get_at($opt_key, 0) ];
  1373. } else {
  1374. # use last extruder's settings for the new one
  1375. my $last_value = $values->[-1];
  1376. $values->[$extruder_idx] //= $last_value;
  1377. }
  1378. $self->{config}->set($opt_key, $values)
  1379. or die "Unable to extend $opt_key";
  1380. }
  1381. # build page
  1382. my $page = $self->{extruder_pages}[$extruder_idx] = $self->add_options_page("Extruder " . ($extruder_idx + 1), 'funnel.png');
  1383. {
  1384. my $optgroup = $page->new_optgroup('Size');
  1385. $optgroup->append_single_option_line('nozzle_diameter', $extruder_idx);
  1386. }
  1387. {
  1388. my $optgroup = $page->new_optgroup('Layer height limits');
  1389. $optgroup->append_single_option_line($_, $extruder_idx)
  1390. for qw(min_layer_height max_layer_height);
  1391. }
  1392. {
  1393. my $optgroup = $page->new_optgroup('Position (for multi-extruder printers)');
  1394. $optgroup->append_single_option_line('extruder_offset', $extruder_idx);
  1395. }
  1396. {
  1397. my $optgroup = $page->new_optgroup('Retraction');
  1398. $optgroup->append_single_option_line($_, $extruder_idx)
  1399. for qw(retract_length retract_lift);
  1400. {
  1401. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1402. label => 'Only lift Z',
  1403. );
  1404. $line->append_option($optgroup->get_option('retract_lift_above', $extruder_idx));
  1405. $line->append_option($optgroup->get_option('retract_lift_below', $extruder_idx));
  1406. $optgroup->append_line($line);
  1407. }
  1408. $optgroup->append_single_option_line($_, $extruder_idx)
  1409. for qw(retract_speed deretract_speed retract_restart_extra retract_before_travel retract_layer_change wipe retract_before_wipe);
  1410. }
  1411. {
  1412. my $optgroup = $page->new_optgroup('Retraction when tool is disabled (advanced settings for multi-extruder setups)');
  1413. $optgroup->append_single_option_line($_, $extruder_idx)
  1414. for qw(retract_length_toolchange retract_restart_extra_toolchange);
  1415. }
  1416. {
  1417. my $optgroup = $page->new_optgroup('Preview');
  1418. $optgroup->append_single_option_line('extruder_colour', $extruder_idx);
  1419. }
  1420. }
  1421. # remove extra pages
  1422. if ($self->{extruders_count} <= $#{$self->{extruder_pages}}) {
  1423. $_->Destroy for @{$self->{extruder_pages}}[$self->{extruders_count}..$#{$self->{extruder_pages}}];
  1424. splice @{$self->{extruder_pages}}, $self->{extruders_count};
  1425. }
  1426. # remove extra config values
  1427. foreach my $opt_key ($self->_extruder_options) {
  1428. my $values = $self->{config}->get($opt_key);
  1429. splice @$values, $self->{extruders_count} if $self->{extruders_count} <= $#$values;
  1430. $self->{config}->set($opt_key, $values)
  1431. or die "Unable to truncate $opt_key";
  1432. }
  1433. # rebuild page list
  1434. my @pages_without_extruders = (grep $_->{title} !~ /^Extruder \d+/, @{$self->{pages}});
  1435. my $page_notes = pop @pages_without_extruders;
  1436. @{$self->{pages}} = (
  1437. @pages_without_extruders,
  1438. @{$self->{extruder_pages}}[ 0 .. $self->{extruders_count}-1 ],
  1439. $page_notes
  1440. );
  1441. $self->update_tree;
  1442. }
  1443. # Slic3r::GUI::Tab::Printer::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
  1444. sub _update {
  1445. # $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
  1446. my ($self, $keys_modified) = @_;
  1447. my $config = $self->{config};
  1448. my $serial_speed = $self->get_field('serial_speed');
  1449. if ($serial_speed) {
  1450. $self->get_field('serial_speed')->toggle($config->get('serial_port'));
  1451. if ($config->get('serial_speed') && $config->get('serial_port')) {
  1452. $self->{serial_test_btn}->Enable;
  1453. } else {
  1454. $self->{serial_test_btn}->Disable;
  1455. }
  1456. }
  1457. if ($config->get('octoprint_host') && eval "use LWP::UserAgent; 1") {
  1458. $self->{octoprint_host_test_btn}->Enable;
  1459. } else {
  1460. $self->{octoprint_host_test_btn}->Disable;
  1461. }
  1462. $self->get_field('octoprint_apikey')->toggle($config->get('octoprint_host'));
  1463. my $have_multiple_extruders = $self->{extruders_count} > 1;
  1464. $self->get_field('toolchange_gcode')->toggle($have_multiple_extruders);
  1465. $self->get_field('single_extruder_multi_material')->toggle($have_multiple_extruders);
  1466. for my $i (0 .. ($self->{extruders_count}-1)) {
  1467. my $have_retract_length = $config->get_at('retract_length', $i) > 0;
  1468. # when using firmware retraction, firmware decides retraction length
  1469. $self->get_field('retract_length', $i)->toggle(!$config->use_firmware_retraction);
  1470. # user can customize travel length if we have retraction length or we're using
  1471. # firmware retraction
  1472. $self->get_field('retract_before_travel', $i)->toggle($have_retract_length || $config->use_firmware_retraction);
  1473. # user can customize other retraction options if retraction is enabled
  1474. my $retraction = ($have_retract_length || $config->use_firmware_retraction);
  1475. $self->get_field($_, $i)->toggle($retraction)
  1476. for qw(retract_lift retract_layer_change);
  1477. # retract lift above/below only applies if using retract lift
  1478. $self->get_field($_, $i)->toggle($retraction && $config->get_at('retract_lift', $i) > 0)
  1479. for qw(retract_lift_above retract_lift_below);
  1480. # some options only apply when not using firmware retraction
  1481. $self->get_field($_, $i)->toggle($retraction && !$config->use_firmware_retraction)
  1482. for qw(retract_speed deretract_speed retract_before_wipe retract_restart_extra wipe);
  1483. my $wipe = $config->get_at('wipe', $i);
  1484. $self->get_field('retract_before_wipe', $i)->toggle($wipe);
  1485. if ($config->use_firmware_retraction && $wipe) {
  1486. my $dialog = Wx::MessageDialog->new($self,
  1487. "The Wipe option is not available when using the Firmware Retraction mode.\n"
  1488. . "\nShall I disable it in order to enable Firmware Retraction?",
  1489. 'Firmware Retraction', wxICON_WARNING | wxYES | wxNO);
  1490. my $new_conf = Slic3r::Config->new;
  1491. if ($dialog->ShowModal() == wxID_YES) {
  1492. my $wipe = $config->wipe;
  1493. $wipe->[$i] = 0;
  1494. $new_conf->set("wipe", $wipe);
  1495. } else {
  1496. $new_conf->set("use_firmware_retraction", 0);
  1497. }
  1498. $self->load_config($new_conf);
  1499. }
  1500. $self->get_field('retract_length_toolchange', $i)->toggle($have_multiple_extruders);
  1501. my $toolchange_retraction = $config->get_at('retract_length_toolchange', $i) > 0;
  1502. $self->get_field('retract_restart_extra_toolchange', $i)->toggle
  1503. ($have_multiple_extruders && $toolchange_retraction);
  1504. }
  1505. }
  1506. # this gets executed after preset is loaded and before GUI fields are updated
  1507. sub on_preset_loaded {
  1508. my $self = shift;
  1509. # update the extruders count field
  1510. {
  1511. # update the GUI field according to the number of nozzle diameters supplied
  1512. my $extruders_count = scalar @{ $self->{config}->nozzle_diameter };
  1513. $self->set_value('extruders_count', $extruders_count);
  1514. $self->_extruders_count_changed($extruders_count);
  1515. }
  1516. }
  1517. sub load_config_file {
  1518. my $self = shift;
  1519. if ($self->SUPER::load_config_file(@_)) {
  1520. Slic3r::GUI::warning_catcher($self)->(
  1521. "Your configuration was imported. However, Slic3r is currently only able to import settings "
  1522. . "for the first defined filament. We recommend you don't use exported configuration files "
  1523. . "for multi-extruder setups and rely on the built-in preset management system instead.")
  1524. if @{ $self->{config}->nozzle_diameter } > 1;
  1525. return 1;
  1526. }
  1527. return undef;
  1528. }
  1529. package Slic3r::GUI::Tab::Page;
  1530. use Wx qw(wxTheApp :misc :panel :sizer);
  1531. use base 'Wx::ScrolledWindow';
  1532. sub new {
  1533. my $class = shift;
  1534. my ($parent, $title, $iconID) = @_;
  1535. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  1536. $self->{optgroups} = [];
  1537. $self->{title} = $title;
  1538. $self->{iconID} = $iconID;
  1539. $self->SetScrollbars(1, 1, 1, 1);
  1540. $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
  1541. $self->SetSizer($self->{vsizer});
  1542. return $self;
  1543. }
  1544. sub new_optgroup {
  1545. my ($self, $title, %params) = @_;
  1546. my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
  1547. parent => $self,
  1548. title => $title,
  1549. config => $self->GetParent->{config},
  1550. label_width => $params{label_width} // 200,
  1551. on_change => sub {
  1552. my ($opt_key, $value) = @_;
  1553. wxTheApp->CallAfter(sub {
  1554. $self->GetParent->update_dirty;
  1555. $self->GetParent->_on_value_change($opt_key, $value);
  1556. });
  1557. },
  1558. );
  1559. push @{$self->{optgroups}}, $optgroup;
  1560. $self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);
  1561. return $optgroup;
  1562. }
  1563. sub reload_config {
  1564. my ($self) = @_;
  1565. $_->reload_config for @{$self->{optgroups}};
  1566. }
  1567. sub get_field {
  1568. my ($self, $opt_key, $opt_index) = @_;
  1569. foreach my $optgroup (@{ $self->{optgroups} }) {
  1570. my $field = $optgroup->get_fieldc($opt_key, $opt_index);
  1571. return $field if defined $field;
  1572. }
  1573. return undef;
  1574. }
  1575. sub set_value {
  1576. my $self = shift;
  1577. my ($opt_key, $value) = @_;
  1578. my $changed = 0;
  1579. foreach my $optgroup (@{$self->{optgroups}}) {
  1580. $changed = 1 if $optgroup->set_value($opt_key, $value);
  1581. }
  1582. return $changed;
  1583. }
  1584. package Slic3r::GUI::SavePresetWindow;
  1585. use Wx qw(:combobox :dialog :id :misc :sizer);
  1586. use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
  1587. use base 'Wx::Dialog';
  1588. sub new {
  1589. my $class = shift;
  1590. my ($parent, %params) = @_;
  1591. my $self = $class->SUPER::new($parent, -1, "Save preset", wxDefaultPosition, wxDefaultSize);
  1592. my @values = @{$params{values}};
  1593. my $text = Wx::StaticText->new($self, -1, "Save " . lc($params{title}) . " as:", wxDefaultPosition, wxDefaultSize);
  1594. $self->{combo} = Wx::ComboBox->new($self, -1, $params{default}, wxDefaultPosition, wxDefaultSize, \@values,
  1595. wxTE_PROCESS_ENTER);
  1596. my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  1597. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  1598. $sizer->Add($text, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10);
  1599. $sizer->Add($self->{combo}, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  1600. $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  1601. EVT_BUTTON($self, wxID_OK, \&accept);
  1602. EVT_TEXT_ENTER($self, $self->{combo}, \&accept);
  1603. $self->SetSizer($sizer);
  1604. $sizer->SetSizeHints($self);
  1605. return $self;
  1606. }
  1607. sub accept {
  1608. my ($self, $event) = @_;
  1609. if (($self->{chosen_name} = $self->{combo}->GetValue)) {
  1610. if ($self->{chosen_name} !~ /^[^<>:\/\\|?*\"]+$/) {
  1611. Slic3r::GUI::show_error($self, "The supplied name is not valid; the following characters are not allowed: <>:/\|?*\"");
  1612. } elsif ($self->{chosen_name} eq '- default -') {
  1613. Slic3r::GUI::show_error($self, "The supplied name is not available.");
  1614. } else {
  1615. $self->EndModal(wxID_OK);
  1616. }
  1617. }
  1618. }
  1619. sub get_name {
  1620. my $self = shift;
  1621. return $self->{chosen_name};
  1622. }
  1623. package Slic3r::GUI::Tab::Preset;
  1624. use Moo;
  1625. use List::Util qw(any);
  1626. # The preset represents a "default" set of properties.
  1627. has 'default' => (is => 'ro', default => sub { 0 });
  1628. has 'external' => (is => 'ro', default => sub { 0 });
  1629. has 'name' => (is => 'rw', required => 1);
  1630. has 'file' => (is => 'rw');
  1631. sub config {
  1632. my ($self, $keys) = @_;
  1633. if ($self->default) {
  1634. # Perl class Slic3r::Config extends the C++ class Slic3r::DynamicPrintConfig
  1635. return Slic3r::Config->new_from_defaults(@$keys);
  1636. } else {
  1637. if (!-e Slic3r::encode_path($self->file)) {
  1638. Slic3r::GUI::show_error(undef, "The selected preset does not exist anymore (" . $self->file . ").");
  1639. return undef;
  1640. }
  1641. # apply preset values on top of defaults
  1642. my $config = Slic3r::Config->new_from_defaults(@$keys);
  1643. my $external_config = eval { Slic3r::Config->load($self->file); };
  1644. if ($@) {
  1645. Slic3r::GUI::show_error(undef, $@);
  1646. return undef;
  1647. }
  1648. $config->set($_, $external_config->get($_))
  1649. for grep $external_config->has($_), @$keys;
  1650. if (any { $_ eq 'nozzle_diameter' } @$keys) {
  1651. # Loaded the Printer settings. Verify, that all extruder dependent values have enough values.
  1652. my $nozzle_diameter = $config->nozzle_diameter;
  1653. my $num_extruders = scalar(@{$nozzle_diameter});
  1654. foreach my $key (qw(deretract_speed extruder_colour retract_before_wipe)) {
  1655. my $vec = $config->get($key);
  1656. push @{$vec}, ($vec->[0]) x ($num_extruders - @{$vec});
  1657. $config->set($key, $vec);
  1658. }
  1659. }
  1660. return $config;
  1661. }
  1662. }
  1663. 1;