PresetEditor.pm 74 KB

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