PresetEditor.pm 74 KB

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