Tab.pm 78 KB

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