Tab.pm 59 KB

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