3D.pm 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. package Slic3r::GUI::Plater::3D;
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use List::Util qw();
  6. use Wx qw(:misc :pen :brush :sizer :font :cursor :keycode wxTAB_TRAVERSAL);
  7. #==============================================================================================================================
  8. #use Wx::Event qw(EVT_KEY_DOWN EVT_CHAR);
  9. #==============================================================================================================================
  10. use base qw(Slic3r::GUI::3DScene Class::Accessor);
  11. #==============================================================================================================================
  12. #use Wx::Locale gettext => 'L';
  13. #
  14. #__PACKAGE__->mk_accessors(qw(
  15. # on_arrange on_rotate_object_left on_rotate_object_right on_scale_object_uniformly
  16. # on_remove_object on_increase_objects on_decrease_objects on_enable_action_buttons));
  17. #==============================================================================================================================
  18. sub new {
  19. my $class = shift;
  20. my ($parent, $objects, $model, $print, $config) = @_;
  21. my $self = $class->SUPER::new($parent);
  22. #==============================================================================================================================
  23. Slic3r::GUI::_3DScene::enable_picking($self, 1);
  24. Slic3r::GUI::_3DScene::enable_moving($self, 1);
  25. Slic3r::GUI::_3DScene::set_select_by($self, 'object');
  26. Slic3r::GUI::_3DScene::set_drag_by($self, 'instance');
  27. Slic3r::GUI::_3DScene::set_model($self, $model);
  28. Slic3r::GUI::_3DScene::set_print($self, $print);
  29. Slic3r::GUI::_3DScene::set_config($self, $config);
  30. # $self->enable_picking(1);
  31. # $self->enable_moving(1);
  32. # $self->select_by('object');
  33. # $self->drag_by('instance');
  34. #
  35. # $self->{objects} = $objects;
  36. # $self->{model} = $model;
  37. # $self->{print} = $print;
  38. # $self->{config} = $config;
  39. # $self->{on_select_object} = sub {};
  40. # $self->{on_instances_moved} = sub {};
  41. # $self->{on_wipe_tower_moved} = sub {};
  42. #
  43. # $self->{objects_volumes_idxs} = [];
  44. #
  45. # $self->on_select(sub {
  46. # my ($volume_idx) = @_;
  47. # $self->{on_select_object}->(($volume_idx == -1) ? undef : $self->volumes->[$volume_idx]->object_idx)
  48. # if ($self->{on_select_object});
  49. # });
  50. #
  51. # $self->on_move(sub {
  52. # my @volume_idxs = @_;
  53. # my %done = (); # prevent moving instances twice
  54. # my $object_moved;
  55. # my $wipe_tower_moved;
  56. # foreach my $volume_idx (@volume_idxs) {
  57. # my $volume = $self->volumes->[$volume_idx];
  58. # my $obj_idx = $volume->object_idx;
  59. # my $instance_idx = $volume->instance_idx;
  60. # next if $done{"${obj_idx}_${instance_idx}"};
  61. # $done{"${obj_idx}_${instance_idx}"} = 1;
  62. # if ($obj_idx < 1000) {
  63. # # Move a regular object.
  64. # my $model_object = $self->{model}->get_object($obj_idx);
  65. # $model_object
  66. # ->instances->[$instance_idx]
  67. # ->offset
  68. # ->translate($volume->origin->x, $volume->origin->y); #))
  69. # $model_object->invalidate_bounding_box;
  70. # $object_moved = 1;
  71. # } elsif ($obj_idx == 1000) {
  72. # # Move a wipe tower proxy.
  73. # $wipe_tower_moved = $volume->origin;
  74. # }
  75. # }
  76. #
  77. # $self->{on_instances_moved}->()
  78. # if $object_moved && $self->{on_instances_moved};
  79. # $self->{on_wipe_tower_moved}->($wipe_tower_moved)
  80. # if $wipe_tower_moved && $self->{on_wipe_tower_moved};
  81. # });
  82. #
  83. # EVT_KEY_DOWN($self, sub {
  84. # my ($s, $event) = @_;
  85. # if ($event->HasModifiers) {
  86. # $event->Skip;
  87. # } else {
  88. # my $key = $event->GetKeyCode;
  89. # if ($key == WXK_DELETE) {
  90. # $self->on_remove_object->() if $self->on_remove_object;
  91. # } else {
  92. # $event->Skip;
  93. # }
  94. # }
  95. # });
  96. #
  97. # EVT_CHAR($self, sub {
  98. # my ($s, $event) = @_;
  99. # if ($event->HasModifiers) {
  100. # $event->Skip;
  101. # } else {
  102. # my $key = $event->GetKeyCode;
  103. # if ($key == ord('a')) {
  104. # $self->on_arrange->() if $self->on_arrange;
  105. # } elsif ($key == ord('l')) {
  106. # $self->on_rotate_object_left->() if $self->on_rotate_object_left;
  107. # } elsif ($key == ord('r')) {
  108. # $self->on_rotate_object_right->() if $self->on_rotate_object_right;
  109. # } elsif ($key == ord('s')) {
  110. # $self->on_scale_object_uniformly->() if $self->on_scale_object_uniformly;
  111. # } elsif ($key == ord('+')) {
  112. # $self->on_increase_objects->() if $self->on_increase_objects;
  113. # } elsif ($key == ord('-')) {
  114. # $self->on_decrease_objects->() if $self->on_decrease_objects;
  115. # } else {
  116. # $event->Skip;
  117. # }
  118. # }
  119. # });
  120. #==============================================================================================================================
  121. return $self;
  122. }
  123. #==============================================================================================================================
  124. #sub set_on_select_object {
  125. # my ($self, $cb) = @_;
  126. # $self->{on_select_object} = $cb;
  127. #}
  128. #
  129. #sub set_on_double_click {
  130. # my ($self, $cb) = @_;
  131. # $self->on_double_click($cb);
  132. #}
  133. #
  134. #sub set_on_right_click {
  135. # my ($self, $cb) = @_;
  136. # $self->on_right_click($cb);
  137. #}
  138. #
  139. #sub set_on_arrange {
  140. # my ($self, $cb) = @_;
  141. # $self->on_arrange($cb);
  142. #}
  143. #
  144. #sub set_on_rotate_object_left {
  145. # my ($self, $cb) = @_;
  146. # $self->on_rotate_object_left($cb);
  147. #}
  148. #
  149. #sub set_on_rotate_object_right {
  150. # my ($self, $cb) = @_;
  151. # $self->on_rotate_object_right($cb);
  152. #}
  153. #
  154. #sub set_on_scale_object_uniformly {
  155. # my ($self, $cb) = @_;
  156. # $self->on_scale_object_uniformly($cb);
  157. #}
  158. #
  159. #sub set_on_increase_objects {
  160. # my ($self, $cb) = @_;
  161. # $self->on_increase_objects($cb);
  162. #}
  163. #
  164. #sub set_on_decrease_objects {
  165. # my ($self, $cb) = @_;
  166. # $self->on_decrease_objects($cb);
  167. #}
  168. #
  169. #sub set_on_remove_object {
  170. # my ($self, $cb) = @_;
  171. # $self->on_remove_object($cb);
  172. #}
  173. #
  174. #sub set_on_instances_moved {
  175. # my ($self, $cb) = @_;
  176. # $self->{on_instances_moved} = $cb;
  177. #}
  178. #
  179. #sub set_on_wipe_tower_moved {
  180. # my ($self, $cb) = @_;
  181. # $self->{on_wipe_tower_moved} = $cb;
  182. #}
  183. #
  184. #sub set_on_model_update {
  185. # my ($self, $cb) = @_;
  186. # $self->on_model_update($cb);
  187. #}
  188. #
  189. #sub set_on_enable_action_buttons {
  190. # my ($self, $cb) = @_;
  191. # $self->on_enable_action_buttons($cb);
  192. #}
  193. #
  194. #sub update_volumes_selection {
  195. # my ($self) = @_;
  196. #
  197. # foreach my $obj_idx (0..$#{$self->{model}->objects}) {
  198. # if ($self->{objects}[$obj_idx]->selected) {
  199. # my $volume_idxs = $self->{objects_volumes_idxs}->[$obj_idx];
  200. # $self->select_volume($_) for @{$volume_idxs};
  201. # }
  202. # }
  203. #}
  204. #
  205. #sub reload_scene {
  206. # my ($self, $force) = @_;
  207. #
  208. # $self->reset_objects;
  209. # $self->update_bed_size;
  210. #
  211. # if (! $self->IsShown && ! $force) {
  212. # $self->{reload_delayed} = 1;
  213. # return;
  214. # }
  215. #
  216. # $self->{reload_delayed} = 0;
  217. #
  218. # $self->{objects_volumes_idxs} = [];
  219. # foreach my $obj_idx (0..$#{$self->{model}->objects}) {
  220. # my @volume_idxs = $self->load_object($self->{model}, $self->{print}, $obj_idx);
  221. # push(@{$self->{objects_volumes_idxs}}, \@volume_idxs);
  222. # }
  223. #
  224. # $self->update_volumes_selection;
  225. #
  226. # if (defined $self->{config}->nozzle_diameter) {
  227. # # Should the wipe tower be visualized?
  228. # my $extruders_count = scalar @{ $self->{config}->nozzle_diameter };
  229. # # Height of a print.
  230. # my $height = $self->{model}->bounding_box->z_max;
  231. # # Show at least a slab.
  232. # $height = 10 if $height < 10;
  233. # if ($extruders_count > 1 && $self->{config}->single_extruder_multi_material && $self->{config}->wipe_tower &&
  234. # ! $self->{config}->complete_objects) {
  235. # $self->volumes->load_wipe_tower_preview(1000,
  236. # $self->{config}->wipe_tower_x, $self->{config}->wipe_tower_y, $self->{config}->wipe_tower_width,
  237. # #$self->{config}->wipe_tower_per_color_wipe# 15 * ($extruders_count - 1), # this is just a hack when the config parameter became obsolete
  238. # 15 * ($extruders_count - 1),
  239. # $self->{model}->bounding_box->z_max, $self->{config}->wipe_tower_rotation_angle, $self->UseVBOs);
  240. # }
  241. # }
  242. #
  243. # $self->update_volumes_colors_by_extruder($self->{config});
  244. #
  245. # # checks for geometry outside the print volume to render it accordingly
  246. # if (scalar @{$self->volumes} > 0)
  247. # {
  248. # my $contained = $self->volumes->check_outside_state($self->{config});
  249. # if (!$contained) {
  250. # $self->set_warning_enabled(1);
  251. # Slic3r::GUI::_3DScene::generate_warning_texture(L("Detected object outside print volume"));
  252. # $self->on_enable_action_buttons->(0) if ($self->on_enable_action_buttons);
  253. # } else {
  254. # $self->set_warning_enabled(0);
  255. # $self->volumes->reset_outside_state();
  256. # Slic3r::GUI::_3DScene::reset_warning_texture();
  257. # $self->on_enable_action_buttons->(scalar @{$self->{model}->objects} > 0) if ($self->on_enable_action_buttons);
  258. # }
  259. # } else {
  260. # $self->set_warning_enabled(0);
  261. # Slic3r::GUI::_3DScene::reset_warning_texture();
  262. # }
  263. #}
  264. #
  265. #sub update_bed_size {
  266. # my ($self) = @_;
  267. # $self->set_bed_shape($self->{config}->bed_shape);
  268. #}
  269. #
  270. ## Called by the Platter wxNotebook when this page is activated.
  271. #sub OnActivate {
  272. # my ($self) = @_;
  273. # $self->reload_scene(1) if ($self->{reload_delayed});
  274. #}
  275. #==============================================================================================================================
  276. 1;