3DPreview.pm 22 KB

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