PresetEditor.pm 74 KB

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