PresetEditor.pm 74 KB

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