Tab.pm 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. package Slic3r::GUI::Tab;
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use File::Basename qw(basename);
  6. use List::Util qw(first);
  7. use Wx qw(:bookctrl :dialog :keycode :icon :id :misc :panel :sizer :treectrl :window
  8. wxTheApp);
  9. use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN EVT_TREE_SEL_CHANGED);
  10. use base 'Wx::Panel';
  11. sub new {
  12. my $class = shift;
  13. my ($parent, %params) = @_;
  14. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
  15. # horizontal sizer
  16. $self->{sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
  17. $self->{sizer}->SetSizeHints($self);
  18. $self->SetSizer($self->{sizer});
  19. # left vertical sizer
  20. my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
  21. $self->{sizer}->Add($left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
  22. my $left_col_width = 150;
  23. # preset chooser
  24. {
  25. # choice menu
  26. $self->{presets_choice} = Wx::Choice->new($self, -1, wxDefaultPosition, [$left_col_width, -1], []);
  27. $self->{presets_choice}->SetFont($Slic3r::GUI::small_font);
  28. # buttons
  29. $self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/disk.png", wxBITMAP_TYPE_PNG));
  30. $self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG));
  31. $self->{btn_save_preset}->SetToolTipString("Save current " . lc($self->title));
  32. $self->{btn_delete_preset}->SetToolTipString("Delete this preset");
  33. $self->{btn_delete_preset}->Disable;
  34. ### These cause GTK warnings:
  35. ###my $box = Wx::StaticBox->new($self, -1, "Presets:", wxDefaultPosition, [$left_col_width, 50]);
  36. ###my $hsizer = Wx::StaticBoxSizer->new($box, wxHORIZONTAL);
  37. my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
  38. $left_sizer->Add($hsizer, 0, wxEXPAND | wxBOTTOM, 5);
  39. $hsizer->Add($self->{presets_choice}, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 3);
  40. $hsizer->Add($self->{btn_save_preset}, 0, wxALIGN_CENTER_VERTICAL);
  41. $hsizer->Add($self->{btn_delete_preset}, 0, wxALIGN_CENTER_VERTICAL);
  42. }
  43. # tree
  44. $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);
  45. $left_sizer->Add($self->{treectrl}, 1, wxEXPAND);
  46. $self->{icons} = Wx::ImageList->new(16, 16, 1);
  47. $self->{treectrl}->AssignImageList($self->{icons});
  48. $self->{iconcount} = -1;
  49. $self->{treectrl}->AddRoot("root");
  50. $self->{pages} = [];
  51. $self->{treectrl}->SetIndent(0);
  52. EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub {
  53. my $page = first { $_->{title} eq $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) } @{$self->{pages}}
  54. or return;
  55. $_->Hide for @{$self->{pages}};
  56. $page->Show;
  57. $self->{sizer}->Layout;
  58. $self->Refresh;
  59. });
  60. EVT_KEY_DOWN($self->{treectrl}, sub {
  61. my ($treectrl, $event) = @_;
  62. if ($event->GetKeyCode == WXK_TAB) {
  63. $treectrl->Navigate($event->ShiftDown ? &Wx::wxNavigateBackward : &Wx::wxNavigateForward);
  64. } else {
  65. $event->Skip;
  66. }
  67. });
  68. EVT_CHOICE($parent, $self->{presets_choice}, sub {
  69. $self->on_select_preset;
  70. $self->_on_presets_changed;
  71. });
  72. EVT_BUTTON($self, $self->{btn_save_preset}, sub { $self->save_preset });
  73. EVT_BUTTON($self, $self->{btn_delete_preset}, sub {
  74. my $i = $self->{presets_choice}->GetSelection;
  75. return if $i == 0; # this shouldn't happen but let's trap it anyway
  76. 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;
  77. return unless $res == wxID_YES;
  78. if (-e $self->{presets}[$i]{file}) {
  79. unlink $self->{presets}[$i]{file};
  80. }
  81. splice @{$self->{presets}}, $i, 1;
  82. $self->set_dirty(0);
  83. $self->{presets_choice}->Delete($i);
  84. $self->{presets_choice}->SetSelection(0);
  85. $self->on_select_preset;
  86. $self->_on_presets_changed;
  87. });
  88. $self->{config} = Slic3r::Config->new;
  89. $self->build;
  90. $self->_update;
  91. if ($self->hidden_options) {
  92. $self->{config}->apply(Slic3r::Config->new_from_defaults($self->hidden_options));
  93. }
  94. return $self;
  95. }
  96. sub current_preset {
  97. my $self = shift;
  98. return $self->{presets}[ $self->{presets_choice}->GetSelection ];
  99. }
  100. sub get_preset {
  101. my $self = shift;
  102. return $self->{presets}[ $_[0] ];
  103. }
  104. sub save_preset {
  105. my ($self, $name) = @_;
  106. # since buttons (and choices too) don't get focus on Mac, we set focus manually
  107. # to the treectrl so that the EVT_* events are fired for the input field having
  108. # focus currently. is there anything better than this?
  109. $self->{treectrl}->SetFocus;
  110. if (!defined $name) {
  111. my $preset = $self->current_preset;
  112. my $default_name = $preset->{default} ? 'Untitled' : basename($preset->{name});
  113. $default_name =~ s/\.ini$//i;
  114. my $dlg = Slic3r::GUI::SavePresetWindow->new($self,
  115. title => lc($self->title),
  116. default => $default_name,
  117. values => [ map { my $name = $_->{name}; $name =~ s/\.ini$//i; $name } @{$self->{presets}} ],
  118. );
  119. return unless $dlg->ShowModal == wxID_OK;
  120. $name = $dlg->get_name;
  121. }
  122. $self->config->save(sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $self->name, $name);
  123. $self->set_dirty(0);
  124. $self->load_presets;
  125. $self->select_preset(first { basename($self->{presets}[$_]{file}) eq $name . ".ini" } 1 .. $#{$self->{presets}});
  126. $self->_on_presets_changed;
  127. }
  128. sub on_value_change {
  129. my ($self, $cb) = @_;
  130. $self->{on_value_change} = $cb;
  131. }
  132. sub on_presets_changed {
  133. my ($self, $cb) = @_;
  134. $self->{on_presets_changed} = $cb;
  135. }
  136. # This method is supposed to be called whenever new values are loaded
  137. # or changed by user (so also when a preset is loaded).
  138. # propagate event to the parent
  139. sub _on_value_change {
  140. my $self = shift;
  141. $self->{on_value_change}->(@_) if $self->{on_value_change};
  142. $self->_update;
  143. }
  144. sub _update {}
  145. sub _on_presets_changed {
  146. my $self = shift;
  147. $self->{on_presets_changed}->([$self->{presets_choice}->GetStrings], $self->{presets_choice}->GetSelection)
  148. if $self->{on_presets_changed};
  149. }
  150. sub on_preset_loaded {}
  151. sub hidden_options {}
  152. sub config { $_[0]->{config}->clone }
  153. sub select_default_preset {
  154. my $self = shift;
  155. $self->{presets_choice}->SetSelection(0);
  156. }
  157. sub select_preset {
  158. my $self = shift;
  159. $self->{presets_choice}->SetSelection($_[0]);
  160. $self->on_select_preset;
  161. }
  162. sub on_select_preset {
  163. my $self = shift;
  164. if ($self->{dirty}) {
  165. my $name = $self->{dirty} == 0 ? 'Default preset' : "Preset \"$self->{presets}[$self->{dirty}]{name}\"";
  166. my $confirm = Wx::MessageDialog->new($self, "$name has unsaved changes. Discard changes and continue anyway?",
  167. 'Unsaved Changes', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
  168. if ($confirm->ShowModal == wxID_NO) {
  169. $self->{presets_choice}->SetSelection($self->{dirty});
  170. return;
  171. }
  172. $self->set_dirty(0);
  173. }
  174. my $preset = $self->current_preset;
  175. my $preset_config = $self->get_preset_config($preset);
  176. eval {
  177. local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
  178. foreach my $opt_key (@{$self->{config}->get_keys}) {
  179. $self->{config}->set($opt_key, $preset_config->get($opt_key))
  180. if $preset_config->has($opt_key);
  181. }
  182. ($preset->{default} || $preset->{external})
  183. ? $self->{btn_delete_preset}->Disable
  184. : $self->{btn_delete_preset}->Enable;
  185. $self->_update;
  186. $self->on_preset_loaded;
  187. $self->reload_config;
  188. # use CallAfter because some field triggers schedule on_change calls using CallAfter,
  189. # and we don't want them to be called after this set_dirty(0) as they would mark the
  190. # preset dirty again
  191. wxTheApp->CallAfter(sub {
  192. $self->set_dirty(0);
  193. });
  194. $Slic3r::GUI::Settings->{presets}{$self->name} = $preset->{file} ? basename($preset->{file}) : '';
  195. };
  196. if ($@) {
  197. $@ = "I was unable to load the selected config file: $@";
  198. Slic3r::GUI::catch_error($self);
  199. $self->select_default_preset;
  200. }
  201. wxTheApp->save_settings;
  202. }
  203. sub get_preset_config {
  204. my $self = shift;
  205. my ($preset) = @_;
  206. if ($preset->{default}) {
  207. return Slic3r::Config->new_from_defaults(@{$self->{config}->get_keys});
  208. } else {
  209. if (!-e $preset->{file}) {
  210. Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($preset->{file}).");
  211. return;
  212. }
  213. # apply preset values on top of defaults
  214. my $external_config = Slic3r::Config->load($preset->{file});
  215. my $config = Slic3r::Config->new;
  216. $config->set($_, $external_config->get($_))
  217. for grep $external_config->has($_), @{$self->{config}->get_keys};
  218. return $config;
  219. }
  220. }
  221. sub init_config_options {
  222. my ($self, @opt_keys) = @_;
  223. $self->{config}->apply(Slic3r::Config->new_from_defaults(@opt_keys));
  224. }
  225. sub add_options_page {
  226. my $self = shift;
  227. my ($title, $icon, %params) = @_;
  228. if ($icon) {
  229. my $bitmap = Wx::Bitmap->new("$Slic3r::var/$icon", wxBITMAP_TYPE_PNG);
  230. $self->{icons}->Add($bitmap);
  231. $self->{iconcount}++;
  232. }
  233. my $page = Slic3r::GUI::Tab::Page->new($self, $title, $self->{iconcount});
  234. $page->Hide;
  235. $self->{sizer}->Add($page, 1, wxEXPAND | wxLEFT, 5);
  236. push @{$self->{pages}}, $page;
  237. $self->update_tree;
  238. return $page;
  239. }
  240. sub reload_config {
  241. my $self = shift;
  242. $_->reload_config for @{$self->{pages}};
  243. }
  244. sub update_tree {
  245. my $self = shift;
  246. my ($select) = @_;
  247. $select //= 0; #/
  248. my $rootItem = $self->{treectrl}->GetRootItem;
  249. $self->{treectrl}->DeleteChildren($rootItem);
  250. foreach my $page (@{$self->{pages}}) {
  251. my $itemId = $self->{treectrl}->AppendItem($rootItem, $page->{title}, $page->{iconID});
  252. $self->{treectrl}->SelectItem($itemId) if $self->{treectrl}->GetChildrenCount($rootItem) == $select + 1;
  253. }
  254. }
  255. sub set_dirty {
  256. my $self = shift;
  257. my ($dirty) = @_;
  258. return if $dirty and $self->is_dirty;
  259. return if (not $dirty) and (not $self->is_dirty);
  260. my $selection = $self->{presets_choice}->GetSelection;
  261. my $i = $self->{dirty} // $selection; #/
  262. my $text = $self->{presets_choice}->GetString($i);
  263. if ($dirty) {
  264. $self->{dirty} = $i;
  265. if ($text !~ / \(modified\)$/) {
  266. $self->{presets_choice}->SetString($i, "$text (modified)");
  267. $self->{presets_choice}->SetSelection($selection); # http://trac.wxwidgets.org/ticket/13769
  268. }
  269. } else {
  270. $self->{dirty} = undef;
  271. $text =~ s/ \(modified\)$//;
  272. $self->{presets_choice}->SetString($i, $text);
  273. $self->{presets_choice}->SetSelection($selection); # http://trac.wxwidgets.org/ticket/13769
  274. }
  275. $self->_on_presets_changed;
  276. }
  277. sub is_dirty {
  278. my $self = shift;
  279. return (defined $self->{dirty});
  280. }
  281. sub load_presets {
  282. my $self = shift;
  283. $self->{presets} = [{
  284. default => 1,
  285. name => '- default -',
  286. }];
  287. my %presets = wxTheApp->presets($self->name);
  288. foreach my $preset_name (sort keys %presets) {
  289. push @{$self->{presets}}, {
  290. name => $preset_name,
  291. file => $presets{$preset_name},
  292. };
  293. }
  294. $self->{presets_choice}->Clear;
  295. $self->{presets_choice}->Append($_->{name}) for @{$self->{presets}};
  296. {
  297. # load last used preset
  298. my $i = first { basename($self->{presets}[$_]{file}) eq ($Slic3r::GUI::Settings->{presets}{$self->name} || '') } 1 .. $#{$self->{presets}};
  299. $self->select_preset($i || 0);
  300. }
  301. $self->_on_presets_changed;
  302. }
  303. sub load_config_file {
  304. my $self = shift;
  305. my ($file) = @_;
  306. # look for the loaded config among the existing menu items
  307. my $i = first { $self->{presets}[$_]{file} eq $file && $self->{presets}[$_]{external} } 1..$#{$self->{presets}};
  308. if (!$i) {
  309. my $preset_name = basename($file); # keep the .ini suffix
  310. push @{$self->{presets}}, {
  311. file => $file,
  312. name => $preset_name,
  313. external => 1,
  314. };
  315. $self->{presets_choice}->Append($preset_name);
  316. $i = $#{$self->{presets}};
  317. }
  318. $self->{presets_choice}->SetSelection($i);
  319. $self->on_select_preset;
  320. $self->_on_presets_changed;
  321. }
  322. sub load_config {
  323. my $self = shift;
  324. my ($config) = @_;
  325. foreach my $opt_key (@{$self->{config}->diff($config)}) {
  326. $self->{config}->set($opt_key, $config->get($opt_key));
  327. $self->set_dirty(1);
  328. }
  329. $self->reload_config;
  330. }
  331. sub get_field {
  332. my ($self, $opt_key, $opt_index) = @_;
  333. foreach my $page (@{ $self->{pages} }) {
  334. my $field = $page->get_field($opt_key, $opt_index);
  335. return $field if defined $field;
  336. }
  337. return undef;
  338. }
  339. sub set_value {
  340. my $self = shift;
  341. my ($opt_key, $value) = @_;
  342. my $changed = 0;
  343. foreach my $page (@{ $self->{pages} }) {
  344. $changed = 1 if $page->set_value($opt_key, $value);
  345. }
  346. return $changed;
  347. }
  348. package Slic3r::GUI::Tab::Print;
  349. use base 'Slic3r::GUI::Tab';
  350. sub name { 'print' }
  351. sub title { 'Print Settings' }
  352. sub build {
  353. my $self = shift;
  354. $self->init_config_options(qw(
  355. layer_height first_layer_height
  356. perimeters spiral_vase
  357. top_solid_layers bottom_solid_layers
  358. extra_perimeters avoid_crossing_perimeters thin_walls overhangs
  359. seam_position external_perimeters_first
  360. fill_density fill_pattern solid_fill_pattern
  361. infill_every_layers infill_only_where_needed
  362. solid_infill_every_layers fill_angle solid_infill_below_area
  363. only_retract_when_crossing_perimeters infill_first
  364. perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed
  365. solid_infill_speed top_solid_infill_speed support_material_speed
  366. support_material_interface_speed bridge_speed gap_fill_speed
  367. travel_speed
  368. first_layer_speed
  369. perimeter_acceleration infill_acceleration bridge_acceleration
  370. first_layer_acceleration default_acceleration
  371. skirts skirt_distance skirt_height min_skirt_length
  372. brim_width
  373. support_material support_material_threshold support_material_enforce_layers
  374. raft_layers
  375. support_material_pattern support_material_spacing support_material_angle
  376. support_material_interface_layers support_material_interface_spacing
  377. dont_support_bridges
  378. notes
  379. complete_objects extruder_clearance_radius extruder_clearance_height
  380. gcode_comments output_filename_format
  381. post_process
  382. perimeter_extruder infill_extruder support_material_extruder support_material_interface_extruder
  383. ooze_prevention standby_temperature_delta
  384. interface_shells
  385. extrusion_width first_layer_extrusion_width perimeter_extrusion_width
  386. external_perimeter_extrusion_width infill_extrusion_width solid_infill_extrusion_width
  387. top_infill_extrusion_width support_material_extrusion_width
  388. bridge_flow_ratio
  389. xy_size_compensation threads resolution
  390. ));
  391. {
  392. my $page = $self->add_options_page('Layers and perimeters', 'layers.png');
  393. {
  394. my $optgroup = $page->new_optgroup('Layer height');
  395. $optgroup->append_single_option_line('layer_height');
  396. $optgroup->append_single_option_line('first_layer_height');
  397. }
  398. {
  399. my $optgroup = $page->new_optgroup('Vertical shells');
  400. $optgroup->append_single_option_line('perimeters');
  401. $optgroup->append_single_option_line('spiral_vase');
  402. }
  403. {
  404. my $optgroup = $page->new_optgroup('Horizontal shells');
  405. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  406. label => 'Solid layers',
  407. );
  408. $line->append_option($optgroup->get_option('top_solid_layers'));
  409. $line->append_option($optgroup->get_option('bottom_solid_layers'));
  410. $optgroup->append_line($line);
  411. }
  412. {
  413. my $optgroup = $page->new_optgroup('Quality (slower slicing)');
  414. $optgroup->append_single_option_line('extra_perimeters');
  415. $optgroup->append_single_option_line('avoid_crossing_perimeters');
  416. $optgroup->append_single_option_line('thin_walls');
  417. $optgroup->append_single_option_line('overhangs');
  418. }
  419. {
  420. my $optgroup = $page->new_optgroup('Advanced');
  421. $optgroup->append_single_option_line('seam_position');
  422. $optgroup->append_single_option_line('external_perimeters_first');
  423. }
  424. }
  425. {
  426. my $page = $self->add_options_page('Infill', 'shading.png');
  427. {
  428. my $optgroup = $page->new_optgroup('Infill');
  429. $optgroup->append_single_option_line('fill_density');
  430. $optgroup->append_single_option_line('fill_pattern');
  431. $optgroup->append_single_option_line('solid_fill_pattern');
  432. }
  433. {
  434. my $optgroup = $page->new_optgroup('Reducing printing time');
  435. $optgroup->append_single_option_line('infill_every_layers');
  436. $optgroup->append_single_option_line('infill_only_where_needed');
  437. }
  438. {
  439. my $optgroup = $page->new_optgroup('Advanced');
  440. $optgroup->append_single_option_line('solid_infill_every_layers');
  441. $optgroup->append_single_option_line('fill_angle');
  442. $optgroup->append_single_option_line('solid_infill_below_area');
  443. $optgroup->append_single_option_line('only_retract_when_crossing_perimeters');
  444. $optgroup->append_single_option_line('infill_first');
  445. }
  446. }
  447. {
  448. my $page = $self->add_options_page('Speed', 'time.png');
  449. {
  450. my $optgroup = $page->new_optgroup('Speed for print moves');
  451. $optgroup->append_single_option_line('perimeter_speed');
  452. $optgroup->append_single_option_line('small_perimeter_speed');
  453. $optgroup->append_single_option_line('external_perimeter_speed');
  454. $optgroup->append_single_option_line('infill_speed');
  455. $optgroup->append_single_option_line('solid_infill_speed');
  456. $optgroup->append_single_option_line('top_solid_infill_speed');
  457. $optgroup->append_single_option_line('support_material_speed');
  458. $optgroup->append_single_option_line('support_material_interface_speed');
  459. $optgroup->append_single_option_line('bridge_speed');
  460. $optgroup->append_single_option_line('gap_fill_speed');
  461. }
  462. {
  463. my $optgroup = $page->new_optgroup('Speed for non-print moves');
  464. $optgroup->append_single_option_line('travel_speed');
  465. }
  466. {
  467. my $optgroup = $page->new_optgroup('Modifiers');
  468. $optgroup->append_single_option_line('first_layer_speed');
  469. }
  470. {
  471. my $optgroup = $page->new_optgroup('Acceleration control (advanced)');
  472. $optgroup->append_single_option_line('perimeter_acceleration');
  473. $optgroup->append_single_option_line('infill_acceleration');
  474. $optgroup->append_single_option_line('bridge_acceleration');
  475. $optgroup->append_single_option_line('first_layer_acceleration');
  476. $optgroup->append_single_option_line('default_acceleration');
  477. }
  478. }
  479. {
  480. my $page = $self->add_options_page('Skirt and brim', 'box.png');
  481. {
  482. my $optgroup = $page->new_optgroup('Skirt');
  483. $optgroup->append_single_option_line('skirts');
  484. $optgroup->append_single_option_line('skirt_distance');
  485. $optgroup->append_single_option_line('skirt_height');
  486. $optgroup->append_single_option_line('min_skirt_length');
  487. }
  488. {
  489. my $optgroup = $page->new_optgroup('Brim');
  490. $optgroup->append_single_option_line('brim_width');
  491. }
  492. }
  493. {
  494. my $page = $self->add_options_page('Support material', 'building.png');
  495. {
  496. my $optgroup = $page->new_optgroup('Support material');
  497. $optgroup->append_single_option_line('support_material');
  498. $optgroup->append_single_option_line('support_material_threshold');
  499. $optgroup->append_single_option_line('support_material_enforce_layers');
  500. }
  501. {
  502. my $optgroup = $page->new_optgroup('Raft');
  503. $optgroup->append_single_option_line('raft_layers');
  504. }
  505. {
  506. my $optgroup = $page->new_optgroup('Options for support material and raft');
  507. $optgroup->append_single_option_line('support_material_pattern');
  508. $optgroup->append_single_option_line('support_material_spacing');
  509. $optgroup->append_single_option_line('support_material_angle');
  510. $optgroup->append_single_option_line('support_material_interface_layers');
  511. $optgroup->append_single_option_line('support_material_interface_spacing');
  512. $optgroup->append_single_option_line('dont_support_bridges');
  513. }
  514. }
  515. {
  516. my $page = $self->add_options_page('Notes', 'note.png');
  517. {
  518. my $optgroup = $page->new_optgroup('Notes',
  519. label_width => 0,
  520. );
  521. my $option = $optgroup->get_option('notes');
  522. $option->full_width(1);
  523. $option->height(250);
  524. $optgroup->append_single_option_line($option);
  525. }
  526. }
  527. {
  528. my $page = $self->add_options_page('Output options', 'page_white_go.png');
  529. {
  530. my $optgroup = $page->new_optgroup('Sequential printing');
  531. $optgroup->append_single_option_line('complete_objects');
  532. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  533. label => 'Extruder clearance (mm)',
  534. );
  535. foreach my $opt_key (qw(extruder_clearance_radius extruder_clearance_height)) {
  536. my $option = $optgroup->get_option($opt_key);
  537. $option->width(60);
  538. $line->append_option($option);
  539. }
  540. $optgroup->append_line($line);
  541. }
  542. {
  543. my $optgroup = $page->new_optgroup('Output file');
  544. $optgroup->append_single_option_line('gcode_comments');
  545. {
  546. my $option = $optgroup->get_option('output_filename_format');
  547. $option->full_width(1);
  548. $optgroup->append_single_option_line($option);
  549. }
  550. }
  551. {
  552. my $optgroup = $page->new_optgroup('Post-processing scripts',
  553. label_width => 0,
  554. );
  555. my $option = $optgroup->get_option('post_process');
  556. $option->full_width(1);
  557. $option->height(50);
  558. $optgroup->append_single_option_line($option);
  559. }
  560. }
  561. {
  562. my $page = $self->add_options_page('Multiple Extruders', 'funnel.png');
  563. {
  564. my $optgroup = $page->new_optgroup('Extruders');
  565. $optgroup->append_single_option_line('perimeter_extruder');
  566. $optgroup->append_single_option_line('infill_extruder');
  567. $optgroup->append_single_option_line('support_material_extruder');
  568. $optgroup->append_single_option_line('support_material_interface_extruder');
  569. }
  570. {
  571. my $optgroup = $page->new_optgroup('Ooze prevention');
  572. $optgroup->append_single_option_line('ooze_prevention');
  573. $optgroup->append_single_option_line('standby_temperature_delta');
  574. }
  575. {
  576. my $optgroup = $page->new_optgroup('Advanced');
  577. $optgroup->append_single_option_line('interface_shells');
  578. }
  579. }
  580. {
  581. my $page = $self->add_options_page('Advanced', 'wrench.png');
  582. {
  583. my $optgroup = $page->new_optgroup('Extrusion width',
  584. label_width => 180,
  585. );
  586. $optgroup->append_single_option_line('extrusion_width');
  587. $optgroup->append_single_option_line('first_layer_extrusion_width');
  588. $optgroup->append_single_option_line('perimeter_extrusion_width');
  589. $optgroup->append_single_option_line('external_perimeter_extrusion_width');
  590. $optgroup->append_single_option_line('infill_extrusion_width');
  591. $optgroup->append_single_option_line('solid_infill_extrusion_width');
  592. $optgroup->append_single_option_line('top_infill_extrusion_width');
  593. $optgroup->append_single_option_line('support_material_extrusion_width');
  594. }
  595. {
  596. my $optgroup = $page->new_optgroup('Flow');
  597. $optgroup->append_single_option_line('bridge_flow_ratio');
  598. }
  599. {
  600. my $optgroup = $page->new_optgroup('Other');
  601. $optgroup->append_single_option_line('xy_size_compensation');
  602. $optgroup->append_single_option_line('threads') if $Slic3r::have_threads;
  603. $optgroup->append_single_option_line('resolution');
  604. }
  605. }
  606. }
  607. sub _update {
  608. my ($self) = @_;
  609. my $config = $self->{config};
  610. # we enable spiral vase if other settings are compatible with it
  611. # or if it is enabled (this prevents the checkbox from being disabled
  612. # when an incompatible setting is set)
  613. $self->get_field('spiral_vase')->toggle(
  614. ($config->perimeters == 1 && $config->top_solid_layers == 0 && $config->fill_density == 0)
  615. || $config->spiral_vase
  616. );
  617. my $have_perimeters = $config->perimeters > 0;
  618. $self->get_field($_)->toggle($have_perimeters)
  619. for qw(extra_perimeters thin_walls overhangs seam_position external_perimeters_first);
  620. my $have_infill = $config->fill_density > 0;
  621. $self->get_field($_)->toggle($have_infill)
  622. for qw(fill_pattern infill_every_layers infill_only_where_needed solid_infill_every_layers);
  623. my $have_default_acceleration = $config->default_acceleration > 0;
  624. $self->get_field($_)->toggle($have_default_acceleration)
  625. for qw(perimeter_acceleration infill_acceleration bridge_acceleration first_layer_acceleration);
  626. my $have_skirt = $config->skirts > 0 || $config->min_skirt_length > 0;
  627. $self->get_field($_)->toggle($have_skirt)
  628. for qw(skirt_distance skirt_height);
  629. my $have_support_material = $config->support_material || $config->raft_layers > 0;
  630. my $have_support_interface = $config->support_material_interface_layers > 0;
  631. $self->get_field($_)->toggle($have_support_material)
  632. for qw(support_material_threshold support_material_enforce_layers
  633. support_material_pattern support_material_spacing support_material_angle
  634. support_material_interface_layers dont_support_bridges
  635. support_material_extruder);
  636. $self->get_field($_)->toggle($have_support_material && $have_support_interface)
  637. for qw(support_material_interface_spacing support_material_interface_extruder);
  638. my $have_sequential_printing = $config->complete_objects;
  639. $self->get_field($_)->toggle($have_sequential_printing)
  640. for qw(extruder_clearance_radius extruder_clearance_height);
  641. my $have_ooze_prevention = $config->ooze_prevention;
  642. $self->get_field($_)->toggle($have_ooze_prevention)
  643. for qw(standby_temperature_delta);
  644. }
  645. sub hidden_options { !$Slic3r::have_threads ? qw(threads) : () }
  646. package Slic3r::GUI::Tab::Filament;
  647. use base 'Slic3r::GUI::Tab';
  648. sub name { 'filament' }
  649. sub title { 'Filament Settings' }
  650. sub build {
  651. my $self = shift;
  652. $self->init_config_options(qw(
  653. filament_diameter extrusion_multiplier
  654. temperature first_layer_temperature bed_temperature first_layer_bed_temperature
  655. fan_always_on cooling
  656. min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers
  657. fan_below_layer_time slowdown_below_layer_time min_print_speed
  658. ));
  659. {
  660. my $page = $self->add_options_page('Filament', 'spool.png');
  661. {
  662. my $optgroup = $page->new_optgroup('Filament');
  663. $optgroup->append_single_option_line('filament_diameter', 0);
  664. $optgroup->append_single_option_line('extrusion_multiplier', 0);
  665. }
  666. {
  667. my $optgroup = $page->new_optgroup('Temperature (°C)');
  668. {
  669. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  670. label => 'Extruder',
  671. );
  672. $line->append_option($optgroup->get_option('first_layer_temperature', 0));
  673. $line->append_option($optgroup->get_option('temperature', 0));
  674. $optgroup->append_line($line);
  675. }
  676. {
  677. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  678. label => 'Bed',
  679. );
  680. $line->append_option($optgroup->get_option('first_layer_bed_temperature'));
  681. $line->append_option($optgroup->get_option('bed_temperature'));
  682. $optgroup->append_line($line);
  683. }
  684. }
  685. }
  686. {
  687. my $page = $self->add_options_page('Cooling', 'hourglass.png');
  688. {
  689. my $optgroup = $page->new_optgroup('Enable');
  690. $optgroup->append_single_option_line('fan_always_on');
  691. $optgroup->append_single_option_line('cooling');
  692. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  693. label => '',
  694. full_width => 1,
  695. widget => sub {
  696. my ($parent) = @_;
  697. return $self->{description_line} = Slic3r::GUI::OptionsGroup::StaticText->new($parent);
  698. },
  699. );
  700. $optgroup->append_line($line);
  701. }
  702. {
  703. my $optgroup = $page->new_optgroup('Fan settings');
  704. {
  705. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  706. label => 'Fan speed',
  707. );
  708. $line->append_option($optgroup->get_option('min_fan_speed'));
  709. $line->append_option($optgroup->get_option('max_fan_speed'));
  710. $optgroup->append_line($line);
  711. }
  712. $optgroup->append_single_option_line('bridge_fan_speed');
  713. $optgroup->append_single_option_line('disable_fan_first_layers');
  714. }
  715. {
  716. my $optgroup = $page->new_optgroup('Cooling thresholds',
  717. label_width => 250,
  718. );
  719. $optgroup->append_single_option_line('fan_below_layer_time');
  720. $optgroup->append_single_option_line('slowdown_below_layer_time');
  721. $optgroup->append_single_option_line('min_print_speed');
  722. }
  723. }
  724. }
  725. sub _update {
  726. my ($self) = @_;
  727. $self->_update_description;
  728. my $cooling = $self->{config}->cooling;
  729. $self->get_field($_)->toggle($cooling)
  730. for qw(max_fan_speed fan_below_layer_time slowdown_below_layer_time min_print_speed);
  731. $self->get_field($_)->toggle($cooling || $self->{config}->fan_always_on)
  732. for qw(min_fan_speed disable_fan_first_layers);
  733. }
  734. sub _update_description {
  735. my $self = shift;
  736. my $config = $self->config;
  737. my $msg = "";
  738. my $fan_other_layers = $config->fan_always_on
  739. ? sprintf "will always run at %d%%%s.", $config->min_fan_speed,
  740. ($config->disable_fan_first_layers > 1
  741. ? " except for the first " . $config->disable_fan_first_layers . " layers"
  742. : $config->disable_fan_first_layers == 1
  743. ? " except for the first layer"
  744. : "")
  745. : "will be turned off.";
  746. if ($config->cooling) {
  747. $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).",
  748. $config->slowdown_below_layer_time, $config->max_fan_speed, $config->slowdown_below_layer_time, $config->min_print_speed;
  749. if ($config->fan_below_layer_time > $config->slowdown_below_layer_time) {
  750. $msg .= sprintf "\nIf estimated layer time is greater, but still below ~%ds, fan will run at a proportionally decreasing speed between %d%% and %d%%.",
  751. $config->fan_below_layer_time, $config->max_fan_speed, $config->min_fan_speed;
  752. }
  753. $msg .= "\nDuring the other layers, fan $fan_other_layers"
  754. } else {
  755. $msg = "Fan $fan_other_layers";
  756. }
  757. $self->{description_line}->SetText($msg);
  758. }
  759. package Slic3r::GUI::Tab::Printer;
  760. use base 'Slic3r::GUI::Tab';
  761. use Wx qw(:sizer :button :bitmap :misc :id);
  762. use Wx::Event qw(EVT_BUTTON);
  763. sub name { 'printer' }
  764. sub title { 'Printer Settings' }
  765. sub build {
  766. my $self = shift;
  767. $self->init_config_options(qw(
  768. bed_shape z_offset
  769. gcode_flavor use_relative_e_distances
  770. use_firmware_retraction vibration_limit
  771. start_gcode end_gcode layer_gcode toolchange_gcode
  772. nozzle_diameter extruder_offset
  773. retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe
  774. retract_length_toolchange retract_restart_extra_toolchange
  775. ));
  776. my $bed_shape_widget = sub {
  777. my ($parent) = @_;
  778. my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  779. $btn->SetFont($Slic3r::GUI::small_font);
  780. if ($Slic3r::GUI::have_button_icons) {
  781. $btn->SetBitmap(Wx::Bitmap->new("$Slic3r::var/cog.png", wxBITMAP_TYPE_PNG));
  782. }
  783. my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  784. $sizer->Add($btn);
  785. EVT_BUTTON($self, $btn, sub {
  786. my $dlg = Slic3r::GUI::BedShapeDialog->new($self, $self->{config}->bed_shape);
  787. if ($dlg->ShowModal == wxID_OK) {
  788. my $value = $dlg->GetValue;
  789. $self->{config}->set('bed_shape', $value);
  790. $self->set_dirty(1);
  791. $self->_on_value_change('bed_shape', $value);
  792. }
  793. });
  794. return $sizer;
  795. };
  796. $self->{extruders_count} = 1;
  797. {
  798. my $page = $self->add_options_page('General', 'printer_empty.png');
  799. {
  800. my $optgroup = $page->new_optgroup('Size and coordinates');
  801. my $line = Slic3r::GUI::OptionsGroup::Line->new(
  802. label => 'Bed shape',
  803. widget => $bed_shape_widget,
  804. );
  805. $optgroup->append_line($line);
  806. $optgroup->append_single_option_line('z_offset');
  807. }
  808. {
  809. my $optgroup = $page->new_optgroup('Firmware');
  810. $optgroup->append_single_option_line('gcode_flavor');
  811. $optgroup->append_single_option_line('use_relative_e_distances');
  812. }
  813. {
  814. my $optgroup = $page->new_optgroup('Capabilities');
  815. {
  816. my $option = Slic3r::GUI::OptionsGroup::Option->new(
  817. opt_id => 'extruders_count',
  818. type => 'i',
  819. default => 1,
  820. label => 'Extruders',
  821. tooltip => 'Number of extruders of the printer.',
  822. min => 1,
  823. );
  824. $optgroup->append_single_option_line($option);
  825. }
  826. $optgroup->on_change(sub {
  827. my ($opt_id) = @_;
  828. if ($opt_id eq 'extruders_count') {
  829. $self->set_dirty(1);
  830. $self->_extruders_count_changed($optgroup->get_value('extruders_count'));
  831. }
  832. });
  833. }
  834. {
  835. my $optgroup = $page->new_optgroup('Advanced');
  836. $optgroup->append_single_option_line('use_firmware_retraction');
  837. $optgroup->append_single_option_line('vibration_limit');
  838. }
  839. }
  840. {
  841. my $page = $self->add_options_page('Custom G-code', 'cog.png');
  842. {
  843. my $optgroup = $page->new_optgroup('Start G-code',
  844. label_width => 0,
  845. );
  846. my $option = $optgroup->get_option('start_gcode');
  847. $option->full_width(1);
  848. $option->height(150);
  849. $optgroup->append_single_option_line($option);
  850. }
  851. {
  852. my $optgroup = $page->new_optgroup('End G-code',
  853. label_width => 0,
  854. );
  855. my $option = $optgroup->get_option('end_gcode');
  856. $option->full_width(1);
  857. $option->height(150);
  858. $optgroup->append_single_option_line($option);
  859. }
  860. {
  861. my $optgroup = $page->new_optgroup('Layer change G-code',
  862. label_width => 0,
  863. );
  864. my $option = $optgroup->get_option('layer_gcode');
  865. $option->full_width(1);
  866. $option->height(150);
  867. $optgroup->append_single_option_line($option);
  868. }
  869. {
  870. my $optgroup = $page->new_optgroup('Tool change G-code',
  871. label_width => 0,
  872. );
  873. my $option = $optgroup->get_option('toolchange_gcode');
  874. $option->full_width(1);
  875. $option->height(150);
  876. $optgroup->append_single_option_line($option);
  877. }
  878. }
  879. $self->{extruder_pages} = [];
  880. $self->_build_extruder_pages;
  881. }
  882. sub _extruders_count_changed {
  883. my ($self, $extruders_count) = @_;
  884. $self->{extruders_count} = $extruders_count;
  885. $self->_build_extruder_pages;
  886. $self->_on_value_change('extruders_count', $extruders_count);
  887. $self->_update;
  888. }
  889. sub _extruder_options { qw(nozzle_diameter extruder_offset retract_length retract_lift retract_speed retract_restart_extra retract_before_travel wipe
  890. retract_layer_change retract_length_toolchange retract_restart_extra_toolchange) }
  891. sub _build_extruder_pages {
  892. my $self = shift;
  893. my $default_config = Slic3r::Config::Full->new;
  894. foreach my $extruder_idx (@{$self->{extruder_pages}} .. $self->{extruders_count}-1) {
  895. # extend options
  896. foreach my $opt_key ($self->_extruder_options) {
  897. my $values = $self->{config}->get($opt_key);
  898. if (!defined $values) {
  899. $values = [ $default_config->get_at($opt_key, 0) ];
  900. } else {
  901. # use last extruder's settings for the new one
  902. my $last_value = $values->[-1];
  903. $values->[$extruder_idx] //= $last_value;
  904. }
  905. $self->{config}->set($opt_key, $values)
  906. or die "Unable to extend $opt_key";
  907. }
  908. # build page
  909. my $page = $self->{extruder_pages}[$extruder_idx] = $self->add_options_page("Extruder " . ($extruder_idx + 1), 'funnel.png');
  910. {
  911. my $optgroup = $page->new_optgroup('Size');
  912. $optgroup->append_single_option_line('nozzle_diameter', $extruder_idx);
  913. }
  914. {
  915. my $optgroup = $page->new_optgroup('Position (for multi-extruder printers)');
  916. $optgroup->append_single_option_line('extruder_offset', $extruder_idx);
  917. }
  918. {
  919. my $optgroup = $page->new_optgroup('Retraction');
  920. $optgroup->append_single_option_line($_, $extruder_idx)
  921. for qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe);
  922. }
  923. {
  924. my $optgroup = $page->new_optgroup('Retraction when tool is disabled (advanced settings for multi-extruder setups)');
  925. $optgroup->append_single_option_line($_, $extruder_idx)
  926. for qw(retract_length_toolchange retract_restart_extra_toolchange);
  927. }
  928. $self->{extruder_pages}[$extruder_idx]{disabled} = 0;
  929. }
  930. # remove extra pages
  931. if ($self->{extruders_count} <= $#{$self->{extruder_pages}}) {
  932. splice @{$self->{extruder_pages}}, $self->{extruders_count};
  933. }
  934. # remove extra config values
  935. foreach my $opt_key ($self->_extruder_options) {
  936. my $values = $self->{config}->get($opt_key);
  937. splice @$values, $self->{extruders_count} if $self->{extruders_count} <= $#$values;
  938. $self->{config}->set($opt_key, $values)
  939. or die "Unable to truncate $opt_key";
  940. }
  941. # rebuild page list
  942. @{$self->{pages}} = (
  943. (grep $_->{title} !~ /^Extruder \d+/, @{$self->{pages}}),
  944. @{$self->{extruder_pages}}[ 0 .. $self->{extruders_count}-1 ],
  945. );
  946. $self->update_tree(0);
  947. }
  948. sub _update {
  949. my ($self) = @_;
  950. my $config = $self->{config};
  951. $self->get_field('toolchange_gcode')->toggle($self->{extruders_count} > 1);
  952. for my $i (0 .. ($self->{extruders_count}-1)) {
  953. # disable extruder offset for first extruder
  954. $self->get_field('extruder_offset', $i)->toggle($i != 0);
  955. my $have_retract_length = $config->get_at('retract_length', $i) > 0;
  956. # when using firmware retraction, firmware decides retraction length
  957. $self->get_field('retract_length', $i)->toggle(!$config->use_firmware_retraction);
  958. # user can customize travel length if we have retraction length or we're using
  959. # firmware retraction
  960. $self->get_field('retract_before_travel', $i)->toggle($have_retract_length || $config->use_firmware_retraction);
  961. # user can customize other retraction options if retraction is enabled
  962. my $retraction = ($have_retract_length || $config->use_firmware_retraction);
  963. $self->get_field($_, $i)->toggle($retraction)
  964. for qw(retract_lift retract_layer_change);
  965. # some options only apply when not using firmware retraction
  966. $self->get_field($_, $i)->toggle($retraction && !$config->use_firmware_retraction)
  967. for qw(retract_speed retract_restart_extra wipe);
  968. my $toolchange_retraction = $config->get_at('retract_length_toolchange', $i) > 0;
  969. $self->get_field($_, $i)->toggle($toolchange_retraction)
  970. for qw(retract_restart_extra_toolchange);
  971. }
  972. }
  973. # this gets executed after preset is loaded and before GUI fields are updated
  974. sub on_preset_loaded {
  975. my $self = shift;
  976. # update the extruders count field
  977. {
  978. # update the GUI field according to the number of nozzle diameters supplied
  979. my $extruders_count = scalar @{ $self->{config}->nozzle_diameter };
  980. $self->set_value('extruders_count', $extruders_count);
  981. $self->_extruders_count_changed($extruders_count);
  982. }
  983. }
  984. sub load_config_file {
  985. my $self = shift;
  986. $self->SUPER::load_config_file(@_);
  987. Slic3r::GUI::warning_catcher($self)->(
  988. "Your configuration was imported. However, Slic3r is currently only able to import settings "
  989. . "for the first defined filament. We recommend you don't use exported configuration files "
  990. . "for multi-extruder setups and rely on the built-in preset management system instead.")
  991. if @{ $self->{config}->nozzle_diameter } > 1;
  992. }
  993. package Slic3r::GUI::Tab::Page;
  994. use Wx qw(:misc :panel :sizer);
  995. use base 'Wx::ScrolledWindow';
  996. sub new {
  997. my $class = shift;
  998. my ($parent, $title, $iconID) = @_;
  999. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  1000. $self->{optgroups} = [];
  1001. $self->{title} = $title;
  1002. $self->{iconID} = $iconID;
  1003. $self->SetScrollbars(1, 1, 1, 1);
  1004. $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
  1005. $self->SetSizer($self->{vsizer});
  1006. return $self;
  1007. }
  1008. sub new_optgroup {
  1009. my ($self, $title, %params) = @_;
  1010. my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
  1011. parent => $self,
  1012. title => $title,
  1013. config => $self->GetParent->{config},
  1014. label_width => $params{label_width} // 200,
  1015. on_change => sub {
  1016. $self->GetParent->set_dirty(1);
  1017. $self->GetParent->_on_value_change(@_);
  1018. },
  1019. );
  1020. push @{$self->{optgroups}}, $optgroup;
  1021. $self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);
  1022. return $optgroup;
  1023. }
  1024. sub reload_config {
  1025. my ($self) = @_;
  1026. $_->reload_config for @{$self->{optgroups}};
  1027. }
  1028. sub get_field {
  1029. my ($self, $opt_key, $opt_index) = @_;
  1030. foreach my $optgroup (@{ $self->{optgroups} }) {
  1031. my $field = $optgroup->get_fieldc($opt_key, $opt_index);
  1032. return $field if defined $field;
  1033. }
  1034. return undef;
  1035. }
  1036. sub set_value {
  1037. my $self = shift;
  1038. my ($opt_key, $value) = @_;
  1039. my $changed = 0;
  1040. foreach my $optgroup (@{$self->{optgroups}}) {
  1041. $changed = 1 if $optgroup->set_value($opt_key, $value);
  1042. }
  1043. return $changed;
  1044. }
  1045. package Slic3r::GUI::SavePresetWindow;
  1046. use Wx qw(:combobox :dialog :id :misc :sizer);
  1047. use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
  1048. use base 'Wx::Dialog';
  1049. sub new {
  1050. my $class = shift;
  1051. my ($parent, %params) = @_;
  1052. my $self = $class->SUPER::new($parent, -1, "Save preset", wxDefaultPosition, wxDefaultSize);
  1053. my @values = grep $_ ne '- default -', @{$params{values}};
  1054. my $text = Wx::StaticText->new($self, -1, "Save " . lc($params{title}) . " as:", wxDefaultPosition, wxDefaultSize);
  1055. $self->{combo} = Wx::ComboBox->new($self, -1, $params{default}, wxDefaultPosition, wxDefaultSize, \@values,
  1056. wxTE_PROCESS_ENTER);
  1057. my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  1058. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  1059. $sizer->Add($text, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10);
  1060. $sizer->Add($self->{combo}, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  1061. $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  1062. EVT_BUTTON($self, wxID_OK, \&accept);
  1063. EVT_TEXT_ENTER($self, $self->{combo}, \&accept);
  1064. $self->SetSizer($sizer);
  1065. $sizer->SetSizeHints($self);
  1066. return $self;
  1067. }
  1068. sub accept {
  1069. my ($self, $event) = @_;
  1070. if (($self->{chosen_name} = $self->{combo}->GetValue)) {
  1071. if ($self->{chosen_name} !~ /^[^<>:\/\\|?*\"]+$/i) {
  1072. Slic3r::GUI::show_error($self, "The supplied name is not valid; the following characters are not allowed: <>:/\|?*\"");
  1073. } elsif ($self->{chosen_name} eq '- default -') {
  1074. Slic3r::GUI::show_error($self, "The supplied name is not available.");
  1075. } else {
  1076. $self->EndModal(wxID_OK);
  1077. }
  1078. }
  1079. }
  1080. sub get_name {
  1081. my $self = shift;
  1082. return $self->{chosen_name};
  1083. }
  1084. 1;