3DPreview.pm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. package Slic3r::GUI::Plater::3DPreview;
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use Slic3r::Print::State ':steps';
  6. use Wx qw(:misc :sizer :slider :statictext :keycode wxWHITE wxCB_READONLY);
  7. use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN EVT_CHECKBOX EVT_CHOICE EVT_CHECKLISTBOX);
  8. use base qw(Wx::Panel Class::Accessor);
  9. use Wx::Locale gettext => 'L';
  10. __PACKAGE__->mk_accessors(qw(print gcode_preview_data enabled _loaded canvas slider_low slider_high single_layer));
  11. sub new {
  12. my $class = shift;
  13. my ($parent, $print, $gcode_preview_data, $config) = @_;
  14. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition);
  15. $self->{config} = $config;
  16. $self->{number_extruders} = 1;
  17. # Show by feature type by default.
  18. $self->{preferred_color_mode} = 'feature';
  19. # init GUI elements
  20. my $canvas = Slic3r::GUI::3DScene->new($self);
  21. Slic3r::GUI::_3DScene::enable_shader($canvas, 1);
  22. Slic3r::GUI::_3DScene::set_config($canvas, $config);
  23. $self->canvas($canvas);
  24. my $slider_low = Wx::Slider->new(
  25. $self, -1,
  26. 0, # default
  27. 0, # min
  28. # we set max to a bogus non-zero value because the MSW implementation of wxSlider
  29. # will skip drawing the slider if max <= min:
  30. 1, # max
  31. wxDefaultPosition,
  32. wxDefaultSize,
  33. wxVERTICAL | wxSL_INVERSE,
  34. );
  35. $self->slider_low($slider_low);
  36. my $slider_high = Wx::Slider->new(
  37. $self, -1,
  38. 0, # default
  39. 0, # min
  40. # we set max to a bogus non-zero value because the MSW implementation of wxSlider
  41. # will skip drawing the slider if max <= min:
  42. 1, # max
  43. wxDefaultPosition,
  44. wxDefaultSize,
  45. wxVERTICAL | wxSL_INVERSE,
  46. );
  47. $self->slider_high($slider_high);
  48. my $z_label_low = $self->{z_label_low} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
  49. [40,-1], wxALIGN_CENTRE_HORIZONTAL);
  50. $z_label_low->SetFont($Slic3r::GUI::small_font);
  51. my $z_label_high = $self->{z_label_high} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
  52. [40,-1], wxALIGN_CENTRE_HORIZONTAL);
  53. $z_label_high->SetFont($Slic3r::GUI::small_font);
  54. my $z_label_low_idx = $self->{z_label_low_idx} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
  55. [40,-1], wxALIGN_CENTRE_HORIZONTAL);
  56. $z_label_low_idx->SetFont($Slic3r::GUI::small_font);
  57. my $z_label_high_idx = $self->{z_label_high_idx} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
  58. [40,-1], wxALIGN_CENTRE_HORIZONTAL);
  59. $z_label_high_idx->SetFont($Slic3r::GUI::small_font);
  60. $self->single_layer(0);
  61. my $checkbox_singlelayer = $self->{checkbox_singlelayer} = Wx::CheckBox->new($self, -1, L("1 Layer"));
  62. my $label_view_type = $self->{label_view_type} = Wx::StaticText->new($self, -1, L("View"));
  63. my $choice_view_type = $self->{choice_view_type} = Wx::Choice->new($self, -1);
  64. $choice_view_type->Append(L("Feature type"));
  65. $choice_view_type->Append(L("Height"));
  66. $choice_view_type->Append(L("Width"));
  67. $choice_view_type->Append(L("Speed"));
  68. $choice_view_type->Append(L("Volumetric flow rate"));
  69. $choice_view_type->Append(L("Tool"));
  70. $choice_view_type->Append(L("Filament"));
  71. $choice_view_type->SetSelection(0);
  72. # the following value needs to be changed if new items are added into $choice_view_type before "Tool"
  73. $self->{tool_idx} = 5;
  74. $self->{filament_idx} = 6;
  75. my $label_show_features = $self->{label_show_features} = Wx::StaticText->new($self, -1, L("Show"));
  76. my $combochecklist_features = $self->{combochecklist_features} = Wx::ComboCtrl->new();
  77. $combochecklist_features->Create($self, -1, L("Feature types"), wxDefaultPosition, [200, -1], wxCB_READONLY);
  78. my $feature_text = L("Feature types");
  79. my $feature_items = L("Perimeter")."|"
  80. .L("External perimeter")."|"
  81. .L("Overhang perimeter")."|"
  82. .L("Internal infill")."|"
  83. .L("Solid infill")."|"
  84. .L("Top solid infill")."|"
  85. .L("Bridge infill")."|"
  86. .L("Gap fill")."|"
  87. .L("Skirt")."|"
  88. .L("Support material")."|"
  89. .L("Support material interface")."|"
  90. .L("Wipe tower")."|"
  91. .L("Custom");
  92. Slic3r::GUI::create_combochecklist($combochecklist_features, $feature_text, $feature_items, 1);
  93. my $checkbox_travel = $self->{checkbox_travel} = Wx::CheckBox->new($self, -1, L("Travel"));
  94. my $checkbox_retractions = $self->{checkbox_retractions} = Wx::CheckBox->new($self, -1, L("Retractions"));
  95. my $checkbox_unretractions = $self->{checkbox_unretractions} = Wx::CheckBox->new($self, -1, L("Unretractions"));
  96. my $checkbox_shells = $self->{checkbox_shells} = Wx::CheckBox->new($self, -1, L("Shells"));
  97. my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
  98. my $vsizer = Wx::BoxSizer->new(wxVERTICAL);
  99. my $vsizer_outer = Wx::BoxSizer->new(wxVERTICAL);
  100. $vsizer->Add($slider_low, 3, wxALIGN_CENTER_HORIZONTAL, 0);
  101. $vsizer->Add($z_label_low_idx, 0, wxALIGN_CENTER_HORIZONTAL, 0);
  102. $vsizer->Add($z_label_low, 0, wxALIGN_CENTER_HORIZONTAL, 0);
  103. $hsizer->Add($vsizer, 0, wxEXPAND, 0);
  104. $vsizer = Wx::BoxSizer->new(wxVERTICAL);
  105. $vsizer->Add($slider_high, 3, wxALIGN_CENTER_HORIZONTAL, 0);
  106. $vsizer->Add($z_label_high_idx, 0, wxALIGN_CENTER_HORIZONTAL, 0);
  107. $vsizer->Add($z_label_high, 0, 0, 0);
  108. $hsizer->Add($vsizer, 0, wxEXPAND, 0);
  109. $vsizer_outer->Add($hsizer, 3, wxALIGN_CENTER_HORIZONTAL, 0);
  110. $vsizer_outer->Add($checkbox_singlelayer, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5);
  111. my $bottom_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  112. $bottom_sizer->Add($label_view_type, 0, wxALIGN_CENTER_VERTICAL, 5);
  113. $bottom_sizer->Add($choice_view_type, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
  114. $bottom_sizer->AddSpacer(10);
  115. $bottom_sizer->Add($label_show_features, 0, wxALIGN_CENTER_VERTICAL, 5);
  116. $bottom_sizer->Add($combochecklist_features, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
  117. $bottom_sizer->AddSpacer(20);
  118. $bottom_sizer->Add($checkbox_travel, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
  119. $bottom_sizer->AddSpacer(10);
  120. $bottom_sizer->Add($checkbox_retractions, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
  121. $bottom_sizer->AddSpacer(10);
  122. $bottom_sizer->Add($checkbox_unretractions, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
  123. $bottom_sizer->AddSpacer(10);
  124. $bottom_sizer->Add($checkbox_shells, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
  125. my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  126. $sizer->Add($canvas, 1, wxALL | wxEXPAND, 0);
  127. $sizer->Add($vsizer_outer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5);
  128. my $main_sizer = Wx::BoxSizer->new(wxVERTICAL);
  129. $main_sizer->Add($sizer, 1, wxALL | wxEXPAND, 0);
  130. $main_sizer->Add($bottom_sizer, 0, wxALL | wxEXPAND, 0);
  131. EVT_SLIDER($self, $slider_low, sub {
  132. $slider_high->SetValue($slider_low->GetValue) if $self->single_layer;
  133. $self->set_z_idx_low ($slider_low ->GetValue)
  134. });
  135. EVT_SLIDER($self, $slider_high, sub {
  136. $slider_low->SetValue($slider_high->GetValue) if $self->single_layer;
  137. $self->set_z_idx_high($slider_high->GetValue)
  138. });
  139. EVT_KEY_DOWN($canvas, sub {
  140. my ($s, $event) = @_;
  141. my $key = $event->GetKeyCode;
  142. if ($event->HasModifiers) {
  143. $event->Skip;
  144. } else {
  145. if ($key == ord('U')) {
  146. $slider_high->SetValue($slider_high->GetValue + 1);
  147. $slider_low->SetValue($slider_high->GetValue) if ($event->ShiftDown());
  148. $self->set_z_idx_high($slider_high->GetValue);
  149. } elsif ($key == ord('D')) {
  150. $slider_high->SetValue($slider_high->GetValue - 1);
  151. $slider_low->SetValue($slider_high->GetValue) if ($event->ShiftDown());
  152. $self->set_z_idx_high($slider_high->GetValue);
  153. } elsif ($key == ord('S')) {
  154. $checkbox_singlelayer->SetValue(! $checkbox_singlelayer->GetValue());
  155. $self->single_layer($checkbox_singlelayer->GetValue());
  156. if ($self->single_layer) {
  157. $slider_low->SetValue($slider_high->GetValue);
  158. $self->set_z_idx_high($slider_high->GetValue);
  159. }
  160. } else {
  161. $event->Skip;
  162. }
  163. }
  164. });
  165. EVT_KEY_DOWN($slider_low, sub {
  166. my ($s, $event) = @_;
  167. my $key = $event->GetKeyCode;
  168. if ($event->HasModifiers) {
  169. $event->Skip;
  170. } else {
  171. if ($key == WXK_LEFT) {
  172. } elsif ($key == WXK_RIGHT) {
  173. $slider_high->SetFocus;
  174. } else {
  175. $event->Skip;
  176. }
  177. }
  178. });
  179. EVT_KEY_DOWN($slider_high, sub {
  180. my ($s, $event) = @_;
  181. my $key = $event->GetKeyCode;
  182. if ($event->HasModifiers) {
  183. $event->Skip;
  184. } else {
  185. if ($key == WXK_LEFT) {
  186. $slider_low->SetFocus;
  187. } elsif ($key == WXK_RIGHT) {
  188. } else {
  189. $event->Skip;
  190. }
  191. }
  192. });
  193. EVT_CHECKBOX($self, $checkbox_singlelayer, sub {
  194. $self->single_layer($checkbox_singlelayer->GetValue());
  195. if ($self->single_layer) {
  196. $slider_low->SetValue($slider_high->GetValue);
  197. $self->set_z_idx_high($slider_high->GetValue);
  198. }
  199. });
  200. EVT_CHOICE($self, $choice_view_type, sub {
  201. my $selection = $choice_view_type->GetCurrentSelection();
  202. $self->{preferred_color_mode} = ($selection == $self->{tool_idx}) ? 'tool' : 'feature';
  203. $self->gcode_preview_data->set_type($selection);
  204. $self->reload_print;
  205. });
  206. EVT_CHECKLISTBOX($self, $combochecklist_features, sub {
  207. my $flags = Slic3r::GUI::combochecklist_get_flags($combochecklist_features);
  208. $self->gcode_preview_data->set_extrusion_flags($flags);
  209. $self->refresh_print;
  210. });
  211. EVT_CHECKBOX($self, $checkbox_travel, sub {
  212. $self->gcode_preview_data->set_travel_visible($checkbox_travel->IsChecked());
  213. $self->refresh_print;
  214. });
  215. EVT_CHECKBOX($self, $checkbox_retractions, sub {
  216. $self->gcode_preview_data->set_retractions_visible($checkbox_retractions->IsChecked());
  217. $self->refresh_print;
  218. });
  219. EVT_CHECKBOX($self, $checkbox_unretractions, sub {
  220. $self->gcode_preview_data->set_unretractions_visible($checkbox_unretractions->IsChecked());
  221. $self->refresh_print;
  222. });
  223. EVT_CHECKBOX($self, $checkbox_shells, sub {
  224. $self->gcode_preview_data->set_shells_visible($checkbox_shells->IsChecked());
  225. $self->refresh_print;
  226. });
  227. $self->SetSizer($main_sizer);
  228. $self->SetMinSize($self->GetSize);
  229. $sizer->SetSizeHints($self);
  230. # init canvas
  231. $self->print($print);
  232. $self->gcode_preview_data($gcode_preview_data);
  233. # sets colors for gcode preview extrusion roles
  234. my @extrusion_roles_colors = (
  235. 'Perimeter' => 'FFFF66',
  236. 'External perimeter' => 'FFA500',
  237. 'Overhang perimeter' => '0000FF',
  238. 'Internal infill' => 'B1302A',
  239. 'Solid infill' => 'D732D7',
  240. 'Top solid infill' => 'FF1A1A',
  241. 'Bridge infill' => '9999FF',
  242. 'Gap fill' => 'FFFFFF',
  243. 'Skirt' => '845321',
  244. 'Support material' => '00FF00',
  245. 'Support material interface' => '008000',
  246. 'Wipe tower' => 'B3E3AB',
  247. 'Custom' => '28CC94',
  248. );
  249. $self->gcode_preview_data->set_extrusion_paths_colors(\@extrusion_roles_colors);
  250. $self->show_hide_ui_elements('none');
  251. $self->reload_print;
  252. return $self;
  253. }
  254. sub reload_print {
  255. my ($self, $force) = @_;
  256. Slic3r::GUI::_3DScene::reset_volumes($self->canvas);
  257. $self->_loaded(0);
  258. if (! $self->IsShown && ! $force) {
  259. # $self->{reload_delayed} = 1;
  260. return;
  261. }
  262. $self->load_print;
  263. }
  264. sub refresh_print {
  265. my ($self) = @_;
  266. $self->_loaded(0);
  267. if (! $self->IsShown) {
  268. return;
  269. }
  270. $self->load_print;
  271. }
  272. sub reset_gcode_preview_data {
  273. my ($self) = @_;
  274. $self->gcode_preview_data->reset;
  275. Slic3r::GUI::_3DScene::reset_legend_texture();
  276. }
  277. sub load_print {
  278. my ($self) = @_;
  279. return if $self->_loaded;
  280. # we require that there's at least one object and the posSlice step
  281. # is performed on all of them (this ensures that _shifted_copies was
  282. # populated and we know the number of layers)
  283. my $n_layers = 0;
  284. if ($self->print->object_step_done(STEP_SLICE)) {
  285. my %z = (); # z => 1
  286. foreach my $object (@{$self->{print}->objects}) {
  287. foreach my $layer (@{$object->layers}, @{$object->support_layers}) {
  288. $z{$layer->print_z} = 1;
  289. }
  290. }
  291. $self->{layers_z} = [ sort { $a <=> $b } keys %z ];
  292. $n_layers = scalar(@{$self->{layers_z}});
  293. }
  294. if ($n_layers == 0) {
  295. $self->reset_sliders;
  296. Slic3r::GUI::_3DScene::reset_legend_texture();
  297. $self->canvas->Refresh; # clears canvas
  298. return;
  299. }
  300. if ($self->{preferred_color_mode} eq 'tool_or_feature') {
  301. # It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature.
  302. # Color by feature if it is a single extruder print.
  303. my $extruders = $self->{print}->extruders;
  304. my $type = (scalar(@{$extruders}) > 1) ? $self->{tool_idx} : 0;
  305. $self->gcode_preview_data->set_type($type);
  306. $self->{choice_view_type}->SetSelection($type);
  307. # If the ->SetSelection changed the following line, revert it to "decide yourself".
  308. $self->{preferred_color_mode} = 'tool_or_feature';
  309. }
  310. # Collect colors per extruder.
  311. my @colors = ();
  312. if (! $self->gcode_preview_data->empty() || $self->gcode_preview_data->type == $self->{tool_idx}) {
  313. my @extruder_colors = @{$self->{config}->extruder_colour};
  314. my @filament_colors = @{$self->{config}->filament_colour};
  315. for (my $i = 0; $i <= $#extruder_colors; $i += 1) {
  316. my $color = $extruder_colors[$i];
  317. $color = $filament_colors[$i] if (! defined($color) || $color !~ m/^#[[:xdigit:]]{6}/);
  318. $color = '#FFFFFF' if (! defined($color) || $color !~ m/^#[[:xdigit:]]{6}/);
  319. push @colors, $color;
  320. }
  321. }
  322. if($self->gcode_preview_data->type == $self->{filament_idx}) {
  323. my @extruder_colors = @{$self->{config}->extruder_colour};
  324. my @filament_colors = @{$self->{config}->filament_colour};
  325. for (my $i = 0; $i <= $#extruder_colors; $i += 1) {
  326. my $color = $filament_colors[$i];
  327. $color = '#FFFFFF' if (! defined($color) || $color !~ m/^#[[:xdigit:]]{6}/);
  328. push @colors, $color;
  329. }
  330. }
  331. if ($self->IsShown) {
  332. # used to set the sliders to the extremes of the current zs range
  333. $self->{force_sliders_full_range} = 0;
  334. if ($self->gcode_preview_data->empty) {
  335. # load skirt and brim
  336. Slic3r::GUI::_3DScene::set_print($self->canvas, $self->print);
  337. Slic3r::GUI::_3DScene::load_preview($self->canvas, \@colors);
  338. $self->show_hide_ui_elements('simple');
  339. } else {
  340. $self->{force_sliders_full_range} = (Slic3r::GUI::_3DScene::get_volumes_count($self->canvas) == 0);
  341. Slic3r::GUI::_3DScene::set_print($self->canvas, $self->print);
  342. Slic3r::GUI::_3DScene::load_gcode_preview($self->canvas, $self->gcode_preview_data, \@colors);
  343. $self->show_hide_ui_elements('full');
  344. # recalculates zs and update sliders accordingly
  345. $self->{layers_z} = Slic3r::GUI::_3DScene::get_current_print_zs($self->canvas, 1);
  346. $n_layers = scalar(@{$self->{layers_z}});
  347. if ($n_layers == 0) {
  348. # all layers filtered out
  349. $self->reset_sliders;
  350. $self->canvas->Refresh; # clears canvas
  351. }
  352. }
  353. $self->update_sliders($n_layers) if ($n_layers > 0);
  354. $self->_loaded(1);
  355. }
  356. }
  357. sub reset_sliders {
  358. my ($self) = @_;
  359. $self->enabled(0);
  360. $self->set_z_range(0,0);
  361. $self->slider_low->Hide;
  362. $self->slider_high->Hide;
  363. $self->{z_label_low}->SetLabel("");
  364. $self->{z_label_high}->SetLabel("");
  365. $self->{z_label_low_idx}->SetLabel("");
  366. $self->{z_label_high_idx}->SetLabel("");
  367. }
  368. sub update_sliders
  369. {
  370. my ($self, $n_layers) = @_;
  371. my $z_idx_low = $self->slider_low->GetValue;
  372. my $z_idx_high = $self->slider_high->GetValue;
  373. $self->enabled(1);
  374. $self->slider_low->SetRange(0, $n_layers - 1);
  375. $self->slider_high->SetRange(0, $n_layers - 1);
  376. if ($self->{force_sliders_full_range}) {
  377. $z_idx_low = 0;
  378. $z_idx_high = $n_layers - 1;
  379. } elsif ($z_idx_high < $n_layers && ($self->single_layer || $z_idx_high != 0)) {
  380. # search new indices for nearest z (size of $self->{layers_z} may change in dependence of what is shown)
  381. if (defined($self->{z_low})) {
  382. for (my $i = scalar(@{$self->{layers_z}}) - 1; $i >= 0; $i -= 1) {
  383. if ($self->{layers_z}[$i] <= $self->{z_low}) {
  384. $z_idx_low = $i;
  385. last;
  386. }
  387. }
  388. }
  389. if (defined($self->{z_high})) {
  390. for (my $i = scalar(@{$self->{layers_z}}) - 1; $i >= 0; $i -= 1) {
  391. if ($self->{layers_z}[$i] <= $self->{z_high}) {
  392. $z_idx_high = $i;
  393. last;
  394. }
  395. }
  396. }
  397. } elsif ($z_idx_high >= $n_layers) {
  398. # Out of range. Disable 'single layer' view.
  399. $self->single_layer(0);
  400. $self->{checkbox_singlelayer}->SetValue(0);
  401. $z_idx_low = 0;
  402. $z_idx_high = $n_layers - 1;
  403. } else {
  404. $z_idx_low = 0;
  405. $z_idx_high = $n_layers - 1;
  406. }
  407. $self->slider_low->SetValue($z_idx_low);
  408. $self->slider_high->SetValue($z_idx_high);
  409. $self->slider_low->Show;
  410. $self->slider_high->Show;
  411. $self->set_z_range($self->{layers_z}[$z_idx_low], $self->{layers_z}[$z_idx_high]);
  412. $self->Layout;
  413. }
  414. sub set_z_range
  415. {
  416. my ($self, $z_low, $z_high) = @_;
  417. return if !$self->enabled;
  418. $self->{z_low} = $z_low;
  419. $self->{z_high} = $z_high;
  420. $self->{z_label_low}->SetLabel(sprintf '%.2f', $z_low);
  421. $self->{z_label_high}->SetLabel(sprintf '%.2f', $z_high);
  422. my $layers_z = Slic3r::GUI::_3DScene::get_current_print_zs($self->canvas, 0);
  423. for (my $i = 0; $i < scalar(@{$layers_z}); $i += 1) {
  424. if (($z_low - 1e-6 < @{$layers_z}[$i]) && (@{$layers_z}[$i] < $z_low + 1e-6)) {
  425. $self->{z_label_low_idx}->SetLabel(sprintf '%d', $i + 1);
  426. last;
  427. }
  428. }
  429. for (my $i = 0; $i < scalar(@{$layers_z}); $i += 1) {
  430. if (($z_high - 1e-6 < @{$layers_z}[$i]) && (@{$layers_z}[$i] < $z_high + 1e-6)) {
  431. $self->{z_label_high_idx}->SetLabel(sprintf '%d', $i + 1);
  432. last;
  433. }
  434. }
  435. Slic3r::GUI::_3DScene::set_toolpaths_range($self->canvas, $z_low - 1e-6, $z_high + 1e-6);
  436. $self->canvas->Refresh if $self->IsShown;
  437. }
  438. sub set_z_idx_low
  439. {
  440. my ($self, $idx_low) = @_;
  441. if ($self->enabled) {
  442. my $idx_high = $self->slider_high->GetValue;
  443. if ($idx_low >= $idx_high) {
  444. $idx_high = $idx_low;
  445. $self->slider_high->SetValue($idx_high);
  446. }
  447. $self->set_z_range($self->{layers_z}[$idx_low], $self->{layers_z}[$idx_high]);
  448. }
  449. }
  450. sub set_z_idx_high
  451. {
  452. my ($self, $idx_high) = @_;
  453. if ($self->enabled) {
  454. my $idx_low = $self->slider_low->GetValue;
  455. if ($idx_low > $idx_high) {
  456. $idx_low = $idx_high;
  457. $self->slider_low->SetValue($idx_low);
  458. }
  459. $self->set_z_range($self->{layers_z}[$idx_low], $self->{layers_z}[$idx_high]);
  460. }
  461. }
  462. sub set_number_extruders {
  463. my ($self, $number_extruders) = @_;
  464. if ($self->{number_extruders} != $number_extruders) {
  465. $self->{number_extruders} = $number_extruders;
  466. my $type = ($number_extruders > 1) ?
  467. $self->{tool_idx} # color by a tool number
  468. : 0; # color by a feature type
  469. $self->{choice_view_type}->SetSelection($type);
  470. $self->gcode_preview_data->set_type($type);
  471. $self->{preferred_color_mode} = ($type == $self->{tool_idx}) ? 'tool_or_feature' : 'feature';
  472. }
  473. }
  474. sub show_hide_ui_elements {
  475. my ($self, $what) = @_;
  476. my $method = ($what eq 'full') ? 'Enable' : 'Disable';
  477. $self->{$_}->$method for qw(label_show_features combochecklist_features checkbox_travel checkbox_retractions checkbox_unretractions checkbox_shells);
  478. $method = ($what eq 'none') ? 'Disable' : 'Enable';
  479. $self->{$_}->$method for qw(label_view_type choice_view_type);
  480. }
  481. # Called by the Platter wxNotebook when this page is activated.
  482. sub OnActivate {
  483. # my ($self) = @_;
  484. # $self->reload_print(1) if ($self->{reload_delayed});
  485. }
  486. 1;