PresetEditor.pm 73 KB

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