Tab.pm 77 KB

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