PresetEditor.pm 71 KB

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