Tab.pm 75 KB

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