Tab.pm 77 KB

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