Tab.pm 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  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. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  535. label => '',
  536. full_width => 1,
  537. widget => sub {
  538. my ($parent) = @_;
  539. return $self->{recommended_thin_wall_thickness_description_line} = Slic3r::GUI::OptionsGroup::StaticText->new($parent);
  540. },
  541. );
  542. $optgroup->append_line($line);
  543. }
  544. {
  545. my $optgroup = $page->new_optgroup('Horizontal shells');
  546. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  547. label => 'Solid layers',
  548. );
  549. $line->append_option($optgroup->get_option('top_solid_layers'));
  550. $line->append_option($optgroup->get_option('bottom_solid_layers'));
  551. $optgroup->append_line($line);
  552. }
  553. {
  554. my $optgroup = $page->new_optgroup('Quality (slower slicing)');
  555. $optgroup->append_single_option_line('extra_perimeters');
  556. $optgroup->append_single_option_line('ensure_vertical_shell_thickness');
  557. $optgroup->append_single_option_line('avoid_crossing_perimeters');
  558. $optgroup->append_single_option_line('thin_walls');
  559. $optgroup->append_single_option_line('overhangs');
  560. }
  561. {
  562. my $optgroup = $page->new_optgroup('Advanced');
  563. $optgroup->append_single_option_line('seam_position');
  564. $optgroup->append_single_option_line('external_perimeters_first');
  565. }
  566. }
  567. {
  568. my $page = $self->add_options_page('Infill', 'infill.png');
  569. {
  570. my $optgroup = $page->new_optgroup('Infill');
  571. $optgroup->append_single_option_line('fill_density');
  572. $optgroup->append_single_option_line('fill_pattern');
  573. $optgroup->append_single_option_line('external_fill_pattern');
  574. }
  575. {
  576. my $optgroup = $page->new_optgroup('Reducing printing time');
  577. $optgroup->append_single_option_line('infill_every_layers');
  578. $optgroup->append_single_option_line('infill_only_where_needed');
  579. }
  580. {
  581. my $optgroup = $page->new_optgroup('Advanced');
  582. $optgroup->append_single_option_line('solid_infill_every_layers');
  583. $optgroup->append_single_option_line('fill_angle');
  584. $optgroup->append_single_option_line('solid_infill_below_area');
  585. $optgroup->append_single_option_line('bridge_angle');
  586. $optgroup->append_single_option_line('only_retract_when_crossing_perimeters');
  587. $optgroup->append_single_option_line('infill_first');
  588. }
  589. }
  590. {
  591. my $page = $self->add_options_page('Skirt and brim', 'box.png');
  592. {
  593. my $optgroup = $page->new_optgroup('Skirt');
  594. $optgroup->append_single_option_line('skirts');
  595. $optgroup->append_single_option_line('skirt_distance');
  596. $optgroup->append_single_option_line('skirt_height');
  597. $optgroup->append_single_option_line('min_skirt_length');
  598. }
  599. {
  600. my $optgroup = $page->new_optgroup('Brim');
  601. $optgroup->append_single_option_line('brim_width');
  602. }
  603. }
  604. {
  605. my $page = $self->add_options_page('Support material', 'building.png');
  606. {
  607. my $optgroup = $page->new_optgroup('Support material');
  608. $optgroup->append_single_option_line('support_material');
  609. $optgroup->append_single_option_line('support_material_threshold');
  610. $optgroup->append_single_option_line('support_material_enforce_layers');
  611. }
  612. {
  613. my $optgroup = $page->new_optgroup('Raft');
  614. $optgroup->append_single_option_line('raft_layers');
  615. # $optgroup->append_single_option_line('raft_contact_distance');
  616. }
  617. {
  618. my $optgroup = $page->new_optgroup('Options for support material and raft');
  619. $optgroup->append_single_option_line('support_material_contact_distance');
  620. $optgroup->append_single_option_line('support_material_pattern');
  621. $optgroup->append_single_option_line('support_material_with_sheath');
  622. $optgroup->append_single_option_line('support_material_spacing');
  623. $optgroup->append_single_option_line('support_material_angle');
  624. $optgroup->append_single_option_line('support_material_interface_layers');
  625. $optgroup->append_single_option_line('support_material_interface_spacing');
  626. $optgroup->append_single_option_line('support_material_interface_contact_loops');
  627. $optgroup->append_single_option_line('support_material_buildplate_only');
  628. $optgroup->append_single_option_line('support_material_xy_spacing');
  629. $optgroup->append_single_option_line('dont_support_bridges');
  630. $optgroup->append_single_option_line('support_material_synchronize_layers');
  631. }
  632. }
  633. {
  634. my $page = $self->add_options_page('Speed', 'time.png');
  635. {
  636. my $optgroup = $page->new_optgroup('Speed for print moves');
  637. $optgroup->append_single_option_line('perimeter_speed');
  638. $optgroup->append_single_option_line('small_perimeter_speed');
  639. $optgroup->append_single_option_line('external_perimeter_speed');
  640. $optgroup->append_single_option_line('infill_speed');
  641. $optgroup->append_single_option_line('solid_infill_speed');
  642. $optgroup->append_single_option_line('top_solid_infill_speed');
  643. $optgroup->append_single_option_line('support_material_speed');
  644. $optgroup->append_single_option_line('support_material_interface_speed');
  645. $optgroup->append_single_option_line('bridge_speed');
  646. $optgroup->append_single_option_line('gap_fill_speed');
  647. }
  648. {
  649. my $optgroup = $page->new_optgroup('Speed for non-print moves');
  650. $optgroup->append_single_option_line('travel_speed');
  651. }
  652. {
  653. my $optgroup = $page->new_optgroup('Modifiers');
  654. $optgroup->append_single_option_line('first_layer_speed');
  655. }
  656. {
  657. my $optgroup = $page->new_optgroup('Acceleration control (advanced)');
  658. $optgroup->append_single_option_line('perimeter_acceleration');
  659. $optgroup->append_single_option_line('infill_acceleration');
  660. $optgroup->append_single_option_line('bridge_acceleration');
  661. $optgroup->append_single_option_line('first_layer_acceleration');
  662. $optgroup->append_single_option_line('default_acceleration');
  663. }
  664. {
  665. my $optgroup = $page->new_optgroup('Autospeed (advanced)');
  666. $optgroup->append_single_option_line('max_print_speed');
  667. $optgroup->append_single_option_line('max_volumetric_speed');
  668. $optgroup->append_single_option_line('max_volumetric_extrusion_rate_slope_positive');
  669. $optgroup->append_single_option_line('max_volumetric_extrusion_rate_slope_negative');
  670. }
  671. }
  672. {
  673. my $page = $self->add_options_page('Multiple Extruders', 'funnel.png');
  674. {
  675. my $optgroup = $page->new_optgroup('Extruders');
  676. $optgroup->append_single_option_line('perimeter_extruder');
  677. $optgroup->append_single_option_line('infill_extruder');
  678. $optgroup->append_single_option_line('solid_infill_extruder');
  679. $optgroup->append_single_option_line('support_material_extruder');
  680. $optgroup->append_single_option_line('support_material_interface_extruder');
  681. }
  682. {
  683. my $optgroup = $page->new_optgroup('Ooze prevention');
  684. $optgroup->append_single_option_line('ooze_prevention');
  685. $optgroup->append_single_option_line('standby_temperature_delta');
  686. }
  687. {
  688. my $optgroup = $page->new_optgroup('Wipe tower');
  689. $optgroup->append_single_option_line('wipe_tower');
  690. $optgroup->append_single_option_line('wipe_tower_x');
  691. $optgroup->append_single_option_line('wipe_tower_y');
  692. $optgroup->append_single_option_line('wipe_tower_width');
  693. $optgroup->append_single_option_line('wipe_tower_per_color_wipe');
  694. }
  695. {
  696. my $optgroup = $page->new_optgroup('Advanced');
  697. $optgroup->append_single_option_line('interface_shells');
  698. }
  699. }
  700. {
  701. my $page = $self->add_options_page('Advanced', 'wrench.png');
  702. {
  703. my $optgroup = $page->new_optgroup('Extrusion width',
  704. label_width => 180,
  705. );
  706. $optgroup->append_single_option_line('extrusion_width');
  707. $optgroup->append_single_option_line('first_layer_extrusion_width');
  708. $optgroup->append_single_option_line('perimeter_extrusion_width');
  709. $optgroup->append_single_option_line('external_perimeter_extrusion_width');
  710. $optgroup->append_single_option_line('infill_extrusion_width');
  711. $optgroup->append_single_option_line('solid_infill_extrusion_width');
  712. $optgroup->append_single_option_line('top_infill_extrusion_width');
  713. $optgroup->append_single_option_line('support_material_extrusion_width');
  714. }
  715. {
  716. my $optgroup = $page->new_optgroup('Overlap');
  717. $optgroup->append_single_option_line('infill_overlap');
  718. }
  719. {
  720. my $optgroup = $page->new_optgroup('Flow');
  721. $optgroup->append_single_option_line('bridge_flow_ratio');
  722. }
  723. {
  724. my $optgroup = $page->new_optgroup('Other');
  725. $optgroup->append_single_option_line('clip_multipart_objects');
  726. $optgroup->append_single_option_line('elefant_foot_compensation');
  727. $optgroup->append_single_option_line('xy_size_compensation');
  728. # $optgroup->append_single_option_line('threads');
  729. $optgroup->append_single_option_line('resolution');
  730. }
  731. }
  732. {
  733. my $page = $self->add_options_page('Output options', 'page_white_go.png');
  734. {
  735. my $optgroup = $page->new_optgroup('Sequential printing');
  736. $optgroup->append_single_option_line('complete_objects');
  737. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  738. label => 'Extruder clearance (mm)',
  739. );
  740. foreach my $opt_key (qw(extruder_clearance_radius extruder_clearance_height)) {
  741. my $option = $optgroup->get_option($opt_key);
  742. $option->width(60);
  743. $line->append_option($option);
  744. }
  745. $optgroup->append_line($line);
  746. }
  747. {
  748. my $optgroup = $page->new_optgroup('Output file');
  749. $optgroup->append_single_option_line('gcode_comments');
  750. {
  751. my $option = $optgroup->get_option('output_filename_format');
  752. $option->full_width(1);
  753. $optgroup->append_single_option_line($option);
  754. }
  755. }
  756. {
  757. my $optgroup = $page->new_optgroup('Post-processing scripts',
  758. label_width => 0,
  759. );
  760. my $option = $optgroup->get_option('post_process');
  761. $option->full_width(1);
  762. $option->height(50);
  763. $optgroup->append_single_option_line($option);
  764. }
  765. }
  766. {
  767. my $page = $self->add_options_page('Notes', 'note.png');
  768. {
  769. my $optgroup = $page->new_optgroup('Notes',
  770. label_width => 0,
  771. );
  772. my $option = $optgroup->get_option('notes');
  773. $option->full_width(1);
  774. $option->height(250);
  775. $optgroup->append_single_option_line($option);
  776. }
  777. }
  778. {
  779. my $page = $self->add_options_page('Dependencies', 'wrench.png');
  780. {
  781. my $optgroup = $page->new_optgroup('Profile dependencies');
  782. {
  783. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  784. label => 'Compatible printers',
  785. widget => $self->_compatible_printers_widget,
  786. );
  787. $optgroup->append_line($line);
  788. my $option = $optgroup->get_option('compatible_printers_condition');
  789. $option->full_width(1);
  790. $optgroup->append_single_option_line($option);
  791. }
  792. }
  793. }
  794. }
  795. # Reload current $self->{config} (aka $self->{presets}->edited_preset->config) into the UI fields.
  796. sub _reload_config {
  797. my ($self) = @_;
  798. $self->_reload_compatible_printers_widget;
  799. $self->SUPER::_reload_config;
  800. }
  801. # 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.
  802. sub _update {
  803. my ($self) = @_;
  804. $self->Freeze;
  805. my $config = $self->{config};
  806. if ($config->spiral_vase && !($config->perimeters == 1 && $config->top_solid_layers == 0 && $config->fill_density == 0)) {
  807. my $dialog = Wx::MessageDialog->new($self,
  808. "The Spiral Vase mode requires:\n"
  809. . "- one perimeter\n"
  810. . "- no top solid layers\n"
  811. . "- 0% fill density\n"
  812. . "- no support material\n"
  813. . "- no ensure_vertical_shell_thickness\n"
  814. . "\nShall I adjust those settings in order to enable Spiral Vase?",
  815. 'Spiral Vase', wxICON_WARNING | wxYES | wxNO);
  816. my $new_conf = Slic3r::Config->new;
  817. if ($dialog->ShowModal() == wxID_YES) {
  818. $new_conf->set("perimeters", 1);
  819. $new_conf->set("top_solid_layers", 0);
  820. $new_conf->set("fill_density", 0);
  821. $new_conf->set("support_material", 0);
  822. $new_conf->set("ensure_vertical_shell_thickness", 0);
  823. } else {
  824. $new_conf->set("spiral_vase", 0);
  825. }
  826. $self->load_config($new_conf);
  827. }
  828. if ($config->wipe_tower &&
  829. ($config->first_layer_height != 0.2 || $config->layer_height < 0.15 || $config->layer_height > 0.35)) {
  830. my $dialog = Wx::MessageDialog->new($self,
  831. "The Wipe Tower currently supports only:\n"
  832. . "- first layer height 0.2mm\n"
  833. . "- layer height from 0.15mm to 0.35mm\n"
  834. . "\nShall I adjust those settings in order to enable the Wipe Tower?",
  835. 'Wipe Tower', wxICON_WARNING | wxYES | wxNO);
  836. my $new_conf = Slic3r::Config->new;
  837. if ($dialog->ShowModal() == wxID_YES) {
  838. $new_conf->set("first_layer_height", 0.2);
  839. $new_conf->set("layer_height", 0.15) if $config->layer_height < 0.15;
  840. $new_conf->set("layer_height", 0.35) if $config->layer_height > 0.35;
  841. } else {
  842. $new_conf->set("wipe_tower", 0);
  843. }
  844. $self->load_config($new_conf);
  845. }
  846. if ($config->wipe_tower && $config->support_material && $config->support_material_contact_distance > 0. &&
  847. ($config->support_material_extruder != 0 || $config->support_material_interface_extruder != 0)) {
  848. my $dialog = Wx::MessageDialog->new($self,
  849. "The Wipe Tower currently supports the non-soluble supports only\n"
  850. . "if they are printed with the current extruder without triggering a tool change.\n"
  851. . "(both support_material_extruder and support_material_interface_extruder need to be set to 0).\n"
  852. . "\nShall I adjust those settings in order to enable the Wipe Tower?",
  853. 'Wipe Tower', wxICON_WARNING | wxYES | wxNO);
  854. my $new_conf = Slic3r::Config->new;
  855. if ($dialog->ShowModal() == wxID_YES) {
  856. $new_conf->set("support_material_extruder", 0);
  857. $new_conf->set("support_material_interface_extruder", 0);
  858. } else {
  859. $new_conf->set("wipe_tower", 0);
  860. }
  861. $self->load_config($new_conf);
  862. }
  863. if ($config->wipe_tower && $config->support_material && $config->support_material_contact_distance == 0 &&
  864. ! $config->support_material_synchronize_layers) {
  865. my $dialog = Wx::MessageDialog->new($self,
  866. "For the Wipe Tower to work with the soluble supports, the support layers\n"
  867. . "need to be synchronized with the object layers.\n"
  868. . "\nShall I synchronize support layers in order to enable the Wipe Tower?",
  869. 'Wipe Tower', wxICON_WARNING | wxYES | wxNO);
  870. my $new_conf = Slic3r::Config->new;
  871. if ($dialog->ShowModal() == wxID_YES) {
  872. $new_conf->set("support_material_synchronize_layers", 1);
  873. } else {
  874. $new_conf->set("wipe_tower", 0);
  875. }
  876. $self->load_config($new_conf);
  877. }
  878. if ($config->support_material) {
  879. # Ask only once.
  880. if (! $self->{support_material_overhangs_queried}) {
  881. $self->{support_material_overhangs_queried} = 1;
  882. if ($config->overhangs != 1) {
  883. my $dialog = Wx::MessageDialog->new($self,
  884. "Supports work better, if the following feature is enabled:\n"
  885. . "- Detect bridging perimeters\n"
  886. . "\nShall I adjust those settings for supports?",
  887. 'Support Generator', wxICON_WARNING | wxYES | wxNO | wxCANCEL);
  888. my $answer = $dialog->ShowModal();
  889. my $new_conf = Slic3r::Config->new;
  890. if ($answer == wxID_YES) {
  891. # Enable "detect bridging perimeters".
  892. $new_conf->set("overhangs", 1);
  893. } elsif ($answer == wxID_NO) {
  894. # Do nothing, leave supports on and "detect bridging perimeters" off.
  895. } elsif ($answer == wxID_CANCEL) {
  896. # Disable supports.
  897. $new_conf->set("support_material", 0);
  898. $self->{support_material_overhangs_queried} = 0;
  899. }
  900. $self->load_config($new_conf);
  901. }
  902. }
  903. } else {
  904. $self->{support_material_overhangs_queried} = 0;
  905. }
  906. if ($config->fill_density == 100
  907. && !first { $_ eq $config->fill_pattern } @{$Slic3r::Config::Options->{external_fill_pattern}{values}}) {
  908. my $dialog = Wx::MessageDialog->new($self,
  909. "The " . $config->fill_pattern . " infill pattern is not supposed to work at 100% density.\n"
  910. . "\nShall I switch to rectilinear fill pattern?",
  911. 'Infill', wxICON_WARNING | wxYES | wxNO);
  912. my $new_conf = Slic3r::Config->new;
  913. if ($dialog->ShowModal() == wxID_YES) {
  914. $new_conf->set("fill_pattern", 'rectilinear');
  915. $new_conf->set("fill_density", 100);
  916. } else {
  917. $new_conf->set("fill_density", 40);
  918. }
  919. $self->load_config($new_conf);
  920. }
  921. my $have_perimeters = $config->perimeters > 0;
  922. $self->get_field($_)->toggle($have_perimeters)
  923. for qw(extra_perimeters ensure_vertical_shell_thickness thin_walls overhangs seam_position external_perimeters_first
  924. external_perimeter_extrusion_width
  925. perimeter_speed small_perimeter_speed external_perimeter_speed);
  926. my $have_infill = $config->fill_density > 0;
  927. # infill_extruder uses the same logic as in Print::extruders()
  928. $self->get_field($_)->toggle($have_infill)
  929. for qw(fill_pattern infill_every_layers infill_only_where_needed solid_infill_every_layers
  930. solid_infill_below_area infill_extruder);
  931. my $have_solid_infill = ($config->top_solid_layers > 0) || ($config->bottom_solid_layers > 0);
  932. # solid_infill_extruder uses the same logic as in Print::extruders()
  933. $self->get_field($_)->toggle($have_solid_infill)
  934. for qw(external_fill_pattern infill_first solid_infill_extruder solid_infill_extrusion_width
  935. solid_infill_speed);
  936. $self->get_field($_)->toggle($have_infill || $have_solid_infill)
  937. for qw(fill_angle bridge_angle infill_extrusion_width infill_speed bridge_speed);
  938. $self->get_field('gap_fill_speed')->toggle($have_perimeters && $have_infill);
  939. my $have_top_solid_infill = $config->top_solid_layers > 0;
  940. $self->get_field($_)->toggle($have_top_solid_infill)
  941. for qw(top_infill_extrusion_width top_solid_infill_speed);
  942. my $have_default_acceleration = $config->default_acceleration > 0;
  943. $self->get_field($_)->toggle($have_default_acceleration)
  944. for qw(perimeter_acceleration infill_acceleration bridge_acceleration first_layer_acceleration);
  945. my $have_skirt = $config->skirts > 0 || $config->min_skirt_length > 0;
  946. $self->get_field($_)->toggle($have_skirt)
  947. for qw(skirt_distance skirt_height);
  948. my $have_brim = $config->brim_width > 0;
  949. # perimeter_extruder uses the same logic as in Print::extruders()
  950. $self->get_field('perimeter_extruder')->toggle($have_perimeters || $have_brim);
  951. my $have_raft = $config->raft_layers > 0;
  952. my $have_support_material = $config->support_material || $have_raft;
  953. my $have_support_interface = $config->support_material_interface_layers > 0;
  954. my $have_support_soluble = $have_support_material && $config->support_material_contact_distance == 0;
  955. $self->get_field($_)->toggle($have_support_material)
  956. for qw(support_material_threshold support_material_pattern support_material_with_sheath
  957. support_material_spacing support_material_angle
  958. support_material_interface_layers dont_support_bridges
  959. support_material_extrusion_width support_material_contact_distance support_material_xy_spacing);
  960. $self->get_field($_)->toggle($have_support_material && $have_support_interface)
  961. for qw(support_material_interface_spacing support_material_interface_extruder
  962. support_material_interface_speed support_material_interface_contact_loops);
  963. $self->get_field('support_material_synchronize_layers')->toggle($have_support_soluble);
  964. $self->get_field('perimeter_extrusion_width')->toggle($have_perimeters || $have_skirt || $have_brim);
  965. $self->get_field('support_material_extruder')->toggle($have_support_material || $have_skirt);
  966. $self->get_field('support_material_speed')->toggle($have_support_material || $have_brim || $have_skirt);
  967. my $have_sequential_printing = $config->complete_objects;
  968. $self->get_field($_)->toggle($have_sequential_printing)
  969. for qw(extruder_clearance_radius extruder_clearance_height);
  970. my $have_ooze_prevention = $config->ooze_prevention;
  971. $self->get_field($_)->toggle($have_ooze_prevention)
  972. for qw(standby_temperature_delta);
  973. my $have_wipe_tower = $config->wipe_tower;
  974. $self->get_field($_)->toggle($have_wipe_tower)
  975. for qw(wipe_tower_x wipe_tower_y wipe_tower_width wipe_tower_per_color_wipe);
  976. $self->{recommended_thin_wall_thickness_description_line}->SetText(
  977. Slic3r::GUI::PresetHints::recommended_thin_wall_thickness(wxTheApp->{preset_bundle}));
  978. $self->Thaw;
  979. }
  980. # Update on activation to recalculate the estimates if the nozzle diameter changed
  981. # and the extrusion width values were left to zero (automatic, nozzle dependent).
  982. sub OnActivate {
  983. my ($self) = @_;
  984. $self->{recommended_thin_wall_thickness_description_line}->SetText(
  985. Slic3r::GUI::PresetHints::recommended_thin_wall_thickness(wxTheApp->{preset_bundle}));
  986. }
  987. package Slic3r::GUI::Tab::Filament;
  988. use base 'Slic3r::GUI::Tab';
  989. use Wx qw(wxTheApp);
  990. sub name { 'filament' }
  991. sub title { 'Filament Settings' }
  992. sub build {
  993. my $self = shift;
  994. $self->{presets} = wxTheApp->{preset_bundle}->filament;
  995. $self->{config} = $self->{presets}->get_edited_preset->config;
  996. {
  997. my $page = $self->add_options_page('Filament', 'spool.png');
  998. {
  999. my $optgroup = $page->new_optgroup('Filament');
  1000. $optgroup->append_single_option_line('filament_colour', 0);
  1001. $optgroup->append_single_option_line('filament_diameter', 0);
  1002. $optgroup->append_single_option_line('extrusion_multiplier', 0);
  1003. $optgroup->append_single_option_line('filament_density', 0);
  1004. $optgroup->append_single_option_line('filament_cost', 0);
  1005. }
  1006. {
  1007. my $optgroup = $page->new_optgroup('Temperature (°C)');
  1008. {
  1009. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1010. label => 'Extruder',
  1011. );
  1012. $line->append_option($optgroup->get_option('first_layer_temperature', 0));
  1013. $line->append_option($optgroup->get_option('temperature', 0));
  1014. $optgroup->append_line($line);
  1015. }
  1016. {
  1017. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1018. label => 'Bed',
  1019. );
  1020. $line->append_option($optgroup->get_option('first_layer_bed_temperature', 0));
  1021. $line->append_option($optgroup->get_option('bed_temperature', 0));
  1022. $optgroup->append_line($line);
  1023. }
  1024. }
  1025. }
  1026. {
  1027. my $page = $self->add_options_page('Cooling', 'hourglass.png');
  1028. {
  1029. my $optgroup = $page->new_optgroup('Enable');
  1030. $optgroup->append_single_option_line('fan_always_on', 0);
  1031. $optgroup->append_single_option_line('cooling', 0);
  1032. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1033. label => '',
  1034. full_width => 1,
  1035. widget => sub {
  1036. my ($parent) = @_;
  1037. return $self->{cooling_description_line} = Slic3r::GUI::OptionsGroup::StaticText->new($parent);
  1038. },
  1039. );
  1040. $optgroup->append_line($line);
  1041. }
  1042. {
  1043. my $optgroup = $page->new_optgroup('Fan settings');
  1044. {
  1045. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1046. label => 'Fan speed',
  1047. );
  1048. $line->append_option($optgroup->get_option('min_fan_speed', 0));
  1049. $line->append_option($optgroup->get_option('max_fan_speed', 0));
  1050. $optgroup->append_line($line);
  1051. }
  1052. $optgroup->append_single_option_line('bridge_fan_speed', 0);
  1053. $optgroup->append_single_option_line('disable_fan_first_layers', 0);
  1054. }
  1055. {
  1056. my $optgroup = $page->new_optgroup('Cooling thresholds',
  1057. label_width => 250,
  1058. );
  1059. $optgroup->append_single_option_line('fan_below_layer_time', 0);
  1060. $optgroup->append_single_option_line('slowdown_below_layer_time', 0);
  1061. $optgroup->append_single_option_line('min_print_speed', 0);
  1062. }
  1063. }
  1064. {
  1065. my $page = $self->add_options_page('Advanced', 'wrench.png');
  1066. {
  1067. my $optgroup = $page->new_optgroup('Filament properties');
  1068. $optgroup->append_single_option_line('filament_type', 0);
  1069. $optgroup->append_single_option_line('filament_soluble', 0);
  1070. $optgroup = $page->new_optgroup('Print speed override');
  1071. $optgroup->append_single_option_line('filament_max_volumetric_speed', 0);
  1072. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1073. label => '',
  1074. full_width => 1,
  1075. widget => sub {
  1076. my ($parent) = @_;
  1077. return $self->{volumetric_speed_description_line} = Slic3r::GUI::OptionsGroup::StaticText->new($parent);
  1078. },
  1079. );
  1080. $optgroup->append_line($line);
  1081. }
  1082. }
  1083. {
  1084. my $page = $self->add_options_page('Custom G-code', 'cog.png');
  1085. {
  1086. my $optgroup = $page->new_optgroup('Start G-code',
  1087. label_width => 0,
  1088. );
  1089. my $option = $optgroup->get_option('start_filament_gcode', 0);
  1090. $option->full_width(1);
  1091. $option->height(150);
  1092. $optgroup->append_single_option_line($option);
  1093. }
  1094. {
  1095. my $optgroup = $page->new_optgroup('End G-code',
  1096. label_width => 0,
  1097. );
  1098. my $option = $optgroup->get_option('end_filament_gcode', 0);
  1099. $option->full_width(1);
  1100. $option->height(150);
  1101. $optgroup->append_single_option_line($option);
  1102. }
  1103. }
  1104. {
  1105. my $page = $self->add_options_page('Notes', 'note.png');
  1106. {
  1107. my $optgroup = $page->new_optgroup('Notes',
  1108. label_width => 0,
  1109. );
  1110. my $option = $optgroup->get_option('filament_notes', 0);
  1111. $option->full_width(1);
  1112. $option->height(250);
  1113. $optgroup->append_single_option_line($option);
  1114. }
  1115. }
  1116. {
  1117. my $page = $self->add_options_page('Dependencies', 'wrench.png');
  1118. {
  1119. my $optgroup = $page->new_optgroup('Profile dependencies');
  1120. {
  1121. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1122. label => 'Compatible printers',
  1123. widget => $self->_compatible_printers_widget,
  1124. );
  1125. $optgroup->append_line($line);
  1126. my $option = $optgroup->get_option('compatible_printers_condition');
  1127. $option->full_width(1);
  1128. $optgroup->append_single_option_line($option);
  1129. }
  1130. }
  1131. }
  1132. }
  1133. # Reload current $self->{config} (aka $self->{presets}->edited_preset->config) into the UI fields.
  1134. sub _reload_config {
  1135. my ($self) = @_;
  1136. $self->_reload_compatible_printers_widget;
  1137. $self->SUPER::_reload_config;
  1138. }
  1139. # 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.
  1140. sub _update {
  1141. my ($self) = @_;
  1142. $self->{cooling_description_line}->SetText(
  1143. Slic3r::GUI::PresetHints::cooling_description($self->{presets}->get_edited_preset));
  1144. $self->{volumetric_speed_description_line}->SetText(
  1145. Slic3r::GUI::PresetHints::maximum_volumetric_flow_description(wxTheApp->{preset_bundle}));
  1146. my $cooling = $self->{config}->cooling->[0];
  1147. my $fan_always_on = $cooling || $self->{config}->fan_always_on->[0];
  1148. $self->get_field($_, 0)->toggle($cooling)
  1149. for qw(max_fan_speed fan_below_layer_time slowdown_below_layer_time min_print_speed);
  1150. $self->get_field($_, 0)->toggle($fan_always_on)
  1151. for qw(min_fan_speed disable_fan_first_layers);
  1152. }
  1153. sub OnActivate {
  1154. my ($self) = @_;
  1155. $self->{volumetric_speed_description_line}->SetText(
  1156. Slic3r::GUI::PresetHints::maximum_volumetric_flow_description(wxTheApp->{preset_bundle}));
  1157. }
  1158. package Slic3r::GUI::Tab::Printer;
  1159. use base 'Slic3r::GUI::Tab';
  1160. use Wx qw(wxTheApp :sizer :button :bitmap :misc :id :icon :dialog);
  1161. use Wx::Event qw(EVT_BUTTON);
  1162. sub name { 'printer' }
  1163. sub title { 'Printer Settings' }
  1164. sub build {
  1165. my ($self, %params) = @_;
  1166. $self->{presets} = wxTheApp->{preset_bundle}->printer;
  1167. $self->{config} = $self->{presets}->get_edited_preset->config;
  1168. $self->{extruders_count} = scalar @{$self->{config}->nozzle_diameter};
  1169. my $bed_shape_widget = sub {
  1170. my ($parent) = @_;
  1171. my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize,
  1172. wxBU_LEFT | wxBU_EXACTFIT);
  1173. $btn->SetFont($Slic3r::GUI::small_font);
  1174. $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("printer_empty.png"), wxBITMAP_TYPE_PNG));
  1175. my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  1176. $sizer->Add($btn);
  1177. EVT_BUTTON($self, $btn, sub {
  1178. my $dlg = Slic3r::GUI::BedShapeDialog->new($self, $self->{config}->bed_shape);
  1179. $self->_load_key_value('bed_shape', $dlg->GetValue) if $dlg->ShowModal == wxID_OK;
  1180. });
  1181. return $sizer;
  1182. };
  1183. {
  1184. my $page = $self->add_options_page('General', 'printer_empty.png');
  1185. {
  1186. my $optgroup = $page->new_optgroup('Size and coordinates');
  1187. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1188. label => 'Bed shape',
  1189. widget => $bed_shape_widget,
  1190. );
  1191. $optgroup->append_line($line);
  1192. $optgroup->append_single_option_line('z_offset');
  1193. }
  1194. {
  1195. my $optgroup = $page->new_optgroup('Capabilities');
  1196. {
  1197. my $option = Slic3r::GUI::OptionsGroup::Option->new(
  1198. opt_id => 'extruders_count',
  1199. type => 'i',
  1200. default => 1,
  1201. label => 'Extruders',
  1202. tooltip => 'Number of extruders of the printer.',
  1203. min => 1,
  1204. );
  1205. $optgroup->append_single_option_line($option);
  1206. $optgroup->append_single_option_line('single_extruder_multi_material');
  1207. }
  1208. $optgroup->on_change(sub {
  1209. my ($opt_key, $value) = @_;
  1210. wxTheApp->CallAfter(sub {
  1211. if ($opt_key eq 'extruders_count') {
  1212. $self->_extruders_count_changed($optgroup->get_value('extruders_count'));
  1213. $self->update_dirty;
  1214. } else {
  1215. $self->update_dirty;
  1216. $self->_on_value_change($opt_key, $value);
  1217. }
  1218. });
  1219. });
  1220. }
  1221. if (!$params{no_controller})
  1222. {
  1223. my $optgroup = $page->new_optgroup('USB/Serial connection');
  1224. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1225. label => 'Serial port',
  1226. );
  1227. my $serial_port = $optgroup->get_option('serial_port');
  1228. $serial_port->side_widget(sub {
  1229. my ($parent) = @_;
  1230. my $btn = Wx::BitmapButton->new($parent, -1, Wx::Bitmap->new(Slic3r::var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG),
  1231. wxDefaultPosition, wxDefaultSize, &Wx::wxBORDER_NONE);
  1232. $btn->SetToolTipString("Rescan serial ports")
  1233. if $btn->can('SetToolTipString');
  1234. EVT_BUTTON($self, $btn, \&_update_serial_ports);
  1235. return $btn;
  1236. });
  1237. my $serial_test = sub {
  1238. my ($parent) = @_;
  1239. my $btn = $self->{serial_test_btn} = Wx::Button->new($parent, -1,
  1240. "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
  1241. $btn->SetFont($Slic3r::GUI::small_font);
  1242. $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("wrench.png"), wxBITMAP_TYPE_PNG));
  1243. EVT_BUTTON($self, $btn, sub {
  1244. my $sender = Slic3r::GCode::Sender->new;
  1245. my $res = $sender->connect(
  1246. $self->{config}->serial_port,
  1247. $self->{config}->serial_speed,
  1248. );
  1249. if ($res && $sender->wait_connected) {
  1250. Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!");
  1251. } else {
  1252. Slic3r::GUI::show_error($self, "Connection failed.");
  1253. }
  1254. });
  1255. return $btn;
  1256. };
  1257. $line->append_option($serial_port);
  1258. $line->append_option($optgroup->get_option('serial_speed'));
  1259. $line->append_widget($serial_test);
  1260. $optgroup->append_line($line);
  1261. }
  1262. {
  1263. my $optgroup = $page->new_optgroup('OctoPrint upload');
  1264. # append two buttons to the Host line
  1265. my $octoprint_host_browse = sub {
  1266. my ($parent) = @_;
  1267. my $btn = Wx::Button->new($parent, -1, "Browse…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  1268. $btn->SetFont($Slic3r::GUI::small_font);
  1269. $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("zoom.png"), wxBITMAP_TYPE_PNG));
  1270. if (!eval "use Net::Bonjour; 1") {
  1271. $btn->Disable;
  1272. }
  1273. EVT_BUTTON($self, $btn, sub {
  1274. # look for devices
  1275. my $entries;
  1276. {
  1277. my $res = Net::Bonjour->new('http');
  1278. $res->discover;
  1279. $entries = [ $res->entries ];
  1280. }
  1281. if (@{$entries}) {
  1282. my $dlg = Slic3r::GUI::BonjourBrowser->new($self, $entries);
  1283. $self->_load_key_value('octoprint_host', $dlg->GetValue . ":" . $dlg->GetPort)
  1284. if $dlg->ShowModal == wxID_OK;
  1285. } else {
  1286. Wx::MessageDialog->new($self, 'No Bonjour device found', 'Device Browser', wxOK | wxICON_INFORMATION)->ShowModal;
  1287. }
  1288. });
  1289. return $btn;
  1290. };
  1291. my $octoprint_host_test = sub {
  1292. my ($parent) = @_;
  1293. my $btn = $self->{octoprint_host_test_btn} = Wx::Button->new($parent, -1,
  1294. "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
  1295. $btn->SetFont($Slic3r::GUI::small_font);
  1296. $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("wrench.png"), wxBITMAP_TYPE_PNG));
  1297. EVT_BUTTON($self, $btn, sub {
  1298. my $ua = LWP::UserAgent->new;
  1299. $ua->timeout(10);
  1300. my $res = $ua->get(
  1301. "http://" . $self->{config}->octoprint_host . "/api/version",
  1302. 'X-Api-Key' => $self->{config}->octoprint_apikey,
  1303. );
  1304. if ($res->is_success) {
  1305. Slic3r::GUI::show_info($self, "Connection to OctoPrint works correctly.", "Success!");
  1306. } else {
  1307. Slic3r::GUI::show_error($self,
  1308. "I wasn't able to connect to OctoPrint (" . $res->status_line . "). "
  1309. . "Check hostname and OctoPrint version (at least 1.1.0 is required).");
  1310. }
  1311. });
  1312. return $btn;
  1313. };
  1314. my $host_line = $optgroup->create_single_option_line('octoprint_host');
  1315. $host_line->append_widget($octoprint_host_browse);
  1316. $host_line->append_widget($octoprint_host_test);
  1317. $optgroup->append_line($host_line);
  1318. $optgroup->append_single_option_line('octoprint_apikey');
  1319. }
  1320. {
  1321. my $optgroup = $page->new_optgroup('Firmware');
  1322. $optgroup->append_single_option_line('gcode_flavor');
  1323. }
  1324. {
  1325. my $optgroup = $page->new_optgroup('Advanced');
  1326. $optgroup->append_single_option_line('use_relative_e_distances');
  1327. $optgroup->append_single_option_line('use_firmware_retraction');
  1328. $optgroup->append_single_option_line('use_volumetric_e');
  1329. $optgroup->append_single_option_line('variable_layer_height');
  1330. }
  1331. }
  1332. {
  1333. my $page = $self->add_options_page('Custom G-code', 'cog.png');
  1334. {
  1335. my $optgroup = $page->new_optgroup('Start G-code',
  1336. label_width => 0,
  1337. );
  1338. my $option = $optgroup->get_option('start_gcode');
  1339. $option->full_width(1);
  1340. $option->height(150);
  1341. $optgroup->append_single_option_line($option);
  1342. }
  1343. {
  1344. my $optgroup = $page->new_optgroup('End G-code',
  1345. label_width => 0,
  1346. );
  1347. my $option = $optgroup->get_option('end_gcode');
  1348. $option->full_width(1);
  1349. $option->height(150);
  1350. $optgroup->append_single_option_line($option);
  1351. }
  1352. {
  1353. my $optgroup = $page->new_optgroup('Before layer change G-code',
  1354. label_width => 0,
  1355. );
  1356. my $option = $optgroup->get_option('before_layer_gcode');
  1357. $option->full_width(1);
  1358. $option->height(150);
  1359. $optgroup->append_single_option_line($option);
  1360. }
  1361. {
  1362. my $optgroup = $page->new_optgroup('After layer change G-code',
  1363. label_width => 0,
  1364. );
  1365. my $option = $optgroup->get_option('layer_gcode');
  1366. $option->full_width(1);
  1367. $option->height(150);
  1368. $optgroup->append_single_option_line($option);
  1369. }
  1370. {
  1371. my $optgroup = $page->new_optgroup('Tool change G-code',
  1372. label_width => 0,
  1373. );
  1374. my $option = $optgroup->get_option('toolchange_gcode');
  1375. $option->full_width(1);
  1376. $option->height(150);
  1377. $optgroup->append_single_option_line($option);
  1378. }
  1379. {
  1380. my $optgroup = $page->new_optgroup('Between objects G-code (for sequential printing)',
  1381. label_width => 0,
  1382. );
  1383. my $option = $optgroup->get_option('between_objects_gcode');
  1384. $option->full_width(1);
  1385. $option->height(150);
  1386. $optgroup->append_single_option_line($option);
  1387. }
  1388. }
  1389. {
  1390. my $page = $self->add_options_page('Notes', 'note.png');
  1391. {
  1392. my $optgroup = $page->new_optgroup('Notes',
  1393. label_width => 0,
  1394. );
  1395. my $option = $optgroup->get_option('printer_notes');
  1396. $option->full_width(1);
  1397. $option->height(250);
  1398. $optgroup->append_single_option_line($option);
  1399. }
  1400. }
  1401. $self->{extruder_pages} = [];
  1402. $self->_build_extruder_pages;
  1403. $self->_update_serial_ports if (!$params{no_controller});
  1404. }
  1405. sub _update_serial_ports {
  1406. my ($self) = @_;
  1407. $self->get_field('serial_port')->set_values([ Slic3r::GUI::scan_serial_ports ]);
  1408. }
  1409. sub _extruders_count_changed {
  1410. my ($self, $extruders_count) = @_;
  1411. $self->{extruders_count} = $extruders_count;
  1412. wxTheApp->{preset_bundle}->printer->get_edited_preset->set_num_extruders($extruders_count);
  1413. wxTheApp->{preset_bundle}->update_multi_material_filament_presets;
  1414. $self->_build_extruder_pages;
  1415. $self->_on_value_change('extruders_count', $extruders_count);
  1416. }
  1417. sub _build_extruder_pages {
  1418. my ($self) = @_;
  1419. my $default_config = Slic3r::Config::Full->new;
  1420. foreach my $extruder_idx (@{$self->{extruder_pages}} .. $self->{extruders_count}-1) {
  1421. # build page
  1422. my $page = $self->{extruder_pages}[$extruder_idx] = $self->add_options_page("Extruder " . ($extruder_idx + 1), 'funnel.png');
  1423. {
  1424. my $optgroup = $page->new_optgroup('Size');
  1425. $optgroup->append_single_option_line('nozzle_diameter', $extruder_idx);
  1426. }
  1427. {
  1428. my $optgroup = $page->new_optgroup('Layer height limits');
  1429. $optgroup->append_single_option_line($_, $extruder_idx)
  1430. for qw(min_layer_height max_layer_height);
  1431. }
  1432. {
  1433. my $optgroup = $page->new_optgroup('Position (for multi-extruder printers)');
  1434. $optgroup->append_single_option_line('extruder_offset', $extruder_idx);
  1435. }
  1436. {
  1437. my $optgroup = $page->new_optgroup('Retraction');
  1438. $optgroup->append_single_option_line($_, $extruder_idx)
  1439. for qw(retract_length retract_lift);
  1440. {
  1441. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  1442. label => 'Only lift Z',
  1443. );
  1444. $line->append_option($optgroup->get_option('retract_lift_above', $extruder_idx));
  1445. $line->append_option($optgroup->get_option('retract_lift_below', $extruder_idx));
  1446. $optgroup->append_line($line);
  1447. }
  1448. $optgroup->append_single_option_line($_, $extruder_idx)
  1449. for qw(retract_speed deretract_speed retract_restart_extra retract_before_travel retract_layer_change wipe retract_before_wipe);
  1450. }
  1451. {
  1452. my $optgroup = $page->new_optgroup('Retraction when tool is disabled (advanced settings for multi-extruder setups)');
  1453. $optgroup->append_single_option_line($_, $extruder_idx)
  1454. for qw(retract_length_toolchange retract_restart_extra_toolchange);
  1455. }
  1456. {
  1457. my $optgroup = $page->new_optgroup('Preview');
  1458. $optgroup->append_single_option_line('extruder_colour', $extruder_idx);
  1459. }
  1460. }
  1461. # remove extra pages
  1462. if ($self->{extruders_count} <= $#{$self->{extruder_pages}}) {
  1463. $_->Destroy for @{$self->{extruder_pages}}[$self->{extruders_count}..$#{$self->{extruder_pages}}];
  1464. splice @{$self->{extruder_pages}}, $self->{extruders_count};
  1465. }
  1466. # rebuild page list
  1467. my @pages_without_extruders = (grep $_->{title} !~ /^Extruder \d+/, @{$self->{pages}});
  1468. my $page_notes = pop @pages_without_extruders;
  1469. @{$self->{pages}} = (
  1470. @pages_without_extruders,
  1471. @{$self->{extruder_pages}}[ 0 .. $self->{extruders_count}-1 ],
  1472. $page_notes
  1473. );
  1474. $self->rebuild_page_tree;
  1475. }
  1476. # 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.
  1477. sub _update {
  1478. my ($self) = @_;
  1479. $self->Freeze;
  1480. my $config = $self->{config};
  1481. my $serial_speed = $self->get_field('serial_speed');
  1482. if ($serial_speed) {
  1483. $self->get_field('serial_speed')->toggle($config->get('serial_port'));
  1484. if ($config->get('serial_speed') && $config->get('serial_port')) {
  1485. $self->{serial_test_btn}->Enable;
  1486. } else {
  1487. $self->{serial_test_btn}->Disable;
  1488. }
  1489. }
  1490. if ($config->get('octoprint_host') && eval "use LWP::UserAgent; 1") {
  1491. $self->{octoprint_host_test_btn}->Enable;
  1492. } else {
  1493. $self->{octoprint_host_test_btn}->Disable;
  1494. }
  1495. $self->get_field('octoprint_apikey')->toggle($config->get('octoprint_host'));
  1496. my $have_multiple_extruders = $self->{extruders_count} > 1;
  1497. $self->get_field('toolchange_gcode')->toggle($have_multiple_extruders);
  1498. $self->get_field('single_extruder_multi_material')->toggle($have_multiple_extruders);
  1499. for my $i (0 .. ($self->{extruders_count}-1)) {
  1500. my $have_retract_length = $config->get_at('retract_length', $i) > 0;
  1501. # when using firmware retraction, firmware decides retraction length
  1502. $self->get_field('retract_length', $i)->toggle(!$config->use_firmware_retraction);
  1503. # user can customize travel length if we have retraction length or we're using
  1504. # firmware retraction
  1505. $self->get_field('retract_before_travel', $i)->toggle($have_retract_length || $config->use_firmware_retraction);
  1506. # user can customize other retraction options if retraction is enabled
  1507. my $retraction = ($have_retract_length || $config->use_firmware_retraction);
  1508. $self->get_field($_, $i)->toggle($retraction)
  1509. for qw(retract_lift retract_layer_change);
  1510. # retract lift above/below only applies if using retract lift
  1511. $self->get_field($_, $i)->toggle($retraction && $config->get_at('retract_lift', $i) > 0)
  1512. for qw(retract_lift_above retract_lift_below);
  1513. # some options only apply when not using firmware retraction
  1514. $self->get_field($_, $i)->toggle($retraction && !$config->use_firmware_retraction)
  1515. for qw(retract_speed deretract_speed retract_before_wipe retract_restart_extra wipe);
  1516. my $wipe = $config->get_at('wipe', $i);
  1517. $self->get_field('retract_before_wipe', $i)->toggle($wipe);
  1518. if ($config->use_firmware_retraction && $wipe) {
  1519. my $dialog = Wx::MessageDialog->new($self,
  1520. "The Wipe option is not available when using the Firmware Retraction mode.\n"
  1521. . "\nShall I disable it in order to enable Firmware Retraction?",
  1522. 'Firmware Retraction', wxICON_WARNING | wxYES | wxNO);
  1523. my $new_conf = Slic3r::Config->new;
  1524. if ($dialog->ShowModal() == wxID_YES) {
  1525. my $wipe = $config->wipe;
  1526. $wipe->[$i] = 0;
  1527. $new_conf->set("wipe", $wipe);
  1528. } else {
  1529. $new_conf->set("use_firmware_retraction", 0);
  1530. }
  1531. $self->load_config($new_conf);
  1532. }
  1533. $self->get_field('retract_length_toolchange', $i)->toggle($have_multiple_extruders);
  1534. my $toolchange_retraction = $config->get_at('retract_length_toolchange', $i) > 0;
  1535. $self->get_field('retract_restart_extra_toolchange', $i)->toggle
  1536. ($have_multiple_extruders && $toolchange_retraction);
  1537. }
  1538. $self->Thaw;
  1539. }
  1540. # this gets executed after preset is loaded and before GUI fields are updated
  1541. sub on_preset_loaded {
  1542. my ($self) = @_;
  1543. # update the extruders count field
  1544. my $extruders_count = scalar @{ $self->{config}->nozzle_diameter };
  1545. $self->set_value('extruders_count', $extruders_count);
  1546. # update the GUI field according to the number of nozzle diameters supplied
  1547. $self->_extruders_count_changed($extruders_count);
  1548. }
  1549. # Single Tab page containing a {vsizer} of {optgroups}
  1550. package Slic3r::GUI::Tab::Page;
  1551. use Wx qw(wxTheApp :misc :panel :sizer);
  1552. use base 'Wx::ScrolledWindow';
  1553. sub new {
  1554. my ($class, $parent, $title, $iconID) = @_;
  1555. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  1556. $self->{optgroups} = [];
  1557. $self->{title} = $title;
  1558. $self->{iconID} = $iconID;
  1559. $self->SetScrollbars(1, 1, 1, 1);
  1560. $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
  1561. $self->SetSizer($self->{vsizer});
  1562. return $self;
  1563. }
  1564. sub new_optgroup {
  1565. my ($self, $title, %params) = @_;
  1566. my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
  1567. parent => $self,
  1568. title => $title,
  1569. config => $self->GetParent->{config},
  1570. label_width => $params{label_width} // 200,
  1571. on_change => sub {
  1572. my ($opt_key, $value) = @_;
  1573. wxTheApp->CallAfter(sub {
  1574. $self->GetParent->update_dirty;
  1575. $self->GetParent->_on_value_change($opt_key, $value);
  1576. });
  1577. },
  1578. );
  1579. push @{$self->{optgroups}}, $optgroup;
  1580. $self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);
  1581. return $optgroup;
  1582. }
  1583. sub reload_config {
  1584. my ($self) = @_;
  1585. $_->reload_config for @{$self->{optgroups}};
  1586. }
  1587. sub get_field {
  1588. my ($self, $opt_key, $opt_index) = @_;
  1589. foreach my $optgroup (@{ $self->{optgroups} }) {
  1590. my $field = $optgroup->get_fieldc($opt_key, $opt_index);
  1591. return $field if defined $field;
  1592. }
  1593. return undef;
  1594. }
  1595. sub set_value {
  1596. my ($self, $opt_key, $value) = @_;
  1597. my $changed = 0;
  1598. foreach my $optgroup (@{$self->{optgroups}}) {
  1599. $changed = 1 if $optgroup->set_value($opt_key, $value);
  1600. }
  1601. return $changed;
  1602. }
  1603. # Dialog to select a new file name for a modified preset to be saved.
  1604. # Called from Tab::save_preset().
  1605. package Slic3r::GUI::SavePresetWindow;
  1606. use Wx qw(:combobox :dialog :id :misc :sizer);
  1607. use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
  1608. use base 'Wx::Dialog';
  1609. sub new {
  1610. my ($class, $parent, %params) = @_;
  1611. my $self = $class->SUPER::new($parent, -1, "Save preset", wxDefaultPosition, wxDefaultSize);
  1612. my @values = @{$params{values}};
  1613. my $text = Wx::StaticText->new($self, -1, "Save " . lc($params{title}) . " as:", wxDefaultPosition, wxDefaultSize);
  1614. $self->{combo} = Wx::ComboBox->new($self, -1, $params{default}, wxDefaultPosition, wxDefaultSize, \@values,
  1615. wxTE_PROCESS_ENTER);
  1616. my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  1617. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  1618. $sizer->Add($text, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10);
  1619. $sizer->Add($self->{combo}, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  1620. $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  1621. EVT_BUTTON($self, wxID_OK, \&accept);
  1622. EVT_TEXT_ENTER($self, $self->{combo}, \&accept);
  1623. $self->SetSizer($sizer);
  1624. $sizer->SetSizeHints($self);
  1625. return $self;
  1626. }
  1627. sub accept {
  1628. my ($self, $event) = @_;
  1629. if (($self->{chosen_name} = Slic3r::normalize_utf8_nfc($self->{combo}->GetValue))) {
  1630. if ($self->{chosen_name} !~ /^[^<>:\/\\|?*\"]+$/) {
  1631. Slic3r::GUI::show_error($self, "The supplied name is not valid; the following characters are not allowed: <>:/\|?*\"");
  1632. } elsif ($self->{chosen_name} eq '- default -') {
  1633. Slic3r::GUI::show_error($self, "The supplied name is not available.");
  1634. } else {
  1635. $self->EndModal(wxID_OK);
  1636. }
  1637. }
  1638. }
  1639. sub get_name {
  1640. my ($self) = @_;
  1641. return $self->{chosen_name};
  1642. }
  1643. 1;