ObjectPartsPanel.pm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. # Configuration of mesh modifiers and their parameters.
  2. # This panel is inserted into ObjectSettingsDialog.
  3. package Slic3r::GUI::Plater::ObjectPartsPanel;
  4. use strict;
  5. use warnings;
  6. use utf8;
  7. use File::Basename qw(basename);
  8. use Wx qw(:misc :sizer :treectrl :button :keycode wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG wxID_CANCEL wxMOD_CONTROL
  9. wxTheApp);
  10. use Wx::Event qw(EVT_BUTTON EVT_TREE_ITEM_COLLAPSING EVT_TREE_SEL_CHANGED EVT_TREE_KEY_DOWN);
  11. use base 'Wx::Panel';
  12. use constant ICON_OBJECT => 0;
  13. use constant ICON_SOLIDMESH => 1;
  14. use constant ICON_MODIFIERMESH => 2;
  15. sub new {
  16. my ($class, $parent, %params) = @_;
  17. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  18. # C++ type Slic3r::ModelObject
  19. my $object = $self->{model_object} = $params{model_object};
  20. # Save state for sliders.
  21. $self->{move_options} = {
  22. x => 0,
  23. y => 0,
  24. z => 0,
  25. };
  26. $self->{last_coords} = {
  27. x => 0,
  28. y => 0,
  29. z => 0,
  30. };
  31. # create TreeCtrl
  32. my $tree = $self->{tree} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [300, 100],
  33. wxTR_NO_BUTTONS | wxSUNKEN_BORDER | wxTR_HAS_VARIABLE_ROW_HEIGHT
  34. | wxTR_SINGLE);
  35. {
  36. $self->{tree_icons} = Wx::ImageList->new(16, 16, 1);
  37. $tree->AssignImageList($self->{tree_icons});
  38. $self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("brick.png"), wxBITMAP_TYPE_PNG)); # ICON_OBJECT
  39. $self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("package.png"), wxBITMAP_TYPE_PNG)); # ICON_SOLIDMESH
  40. $self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("plugin.png"), wxBITMAP_TYPE_PNG)); # ICON_MODIFIERMESH
  41. my $rootId = $tree->AddRoot("Object", ICON_OBJECT);
  42. $tree->SetPlData($rootId, { type => 'object' });
  43. }
  44. # buttons
  45. $self->{btn_load_part} = Wx::Button->new($self, -1, "Load part…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  46. $self->{btn_load_modifier} = Wx::Button->new($self, -1, "Load modifier…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  47. $self->{btn_load_lambda_modifier} = Wx::Button->new($self, -1, "Load generic…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  48. $self->{btn_delete} = Wx::Button->new($self, -1, "Delete part", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  49. $self->{btn_split} = Wx::Button->new($self, -1, "Split part", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  50. $self->{btn_move_up} = Wx::Button->new($self, -1, "", wxDefaultPosition, [40, -1], wxBU_LEFT);
  51. $self->{btn_move_down} = Wx::Button->new($self, -1, "", wxDefaultPosition, [40, -1], wxBU_LEFT);
  52. $self->{btn_load_part}->SetBitmap(Wx::Bitmap->new(Slic3r::var("brick_add.png"), wxBITMAP_TYPE_PNG));
  53. $self->{btn_load_modifier}->SetBitmap(Wx::Bitmap->new(Slic3r::var("brick_add.png"), wxBITMAP_TYPE_PNG));
  54. $self->{btn_load_lambda_modifier}->SetBitmap(Wx::Bitmap->new(Slic3r::var("brick_add.png"), wxBITMAP_TYPE_PNG));
  55. $self->{btn_delete}->SetBitmap(Wx::Bitmap->new(Slic3r::var("brick_delete.png"), wxBITMAP_TYPE_PNG));
  56. $self->{btn_split}->SetBitmap(Wx::Bitmap->new(Slic3r::var("shape_ungroup.png"), wxBITMAP_TYPE_PNG));
  57. $self->{btn_move_up}->SetBitmap(Wx::Bitmap->new(Slic3r::var("bullet_arrow_up.png"), wxBITMAP_TYPE_PNG));
  58. $self->{btn_move_down}->SetBitmap(Wx::Bitmap->new(Slic3r::var("bullet_arrow_down.png"), wxBITMAP_TYPE_PNG));
  59. # buttons sizer
  60. my $buttons_sizer = Wx::GridSizer->new(2, 3);
  61. $buttons_sizer->Add($self->{btn_load_part}, 0, wxEXPAND | wxBOTTOM | wxRIGHT, 5);
  62. $buttons_sizer->Add($self->{btn_load_modifier}, 0, wxEXPAND | wxBOTTOM | wxRIGHT, 5);
  63. $buttons_sizer->Add($self->{btn_load_lambda_modifier}, 0, wxEXPAND | wxBOTTOM, 5);
  64. $buttons_sizer->Add($self->{btn_delete}, 0, wxEXPAND | wxRIGHT, 5);
  65. $buttons_sizer->Add($self->{btn_split}, 0, wxEXPAND | wxRIGHT, 5);
  66. {
  67. my $up_down_sizer = Wx::GridSizer->new(1, 2);
  68. $up_down_sizer->Add($self->{btn_move_up}, 0, wxEXPAND | wxRIGHT, 5);
  69. $up_down_sizer->Add($self->{btn_move_down}, 0, wxEXPAND, 5);
  70. $buttons_sizer->Add($up_down_sizer, 0, wxEXPAND, 5);
  71. }
  72. $self->{btn_load_part}->SetFont($Slic3r::GUI::small_font);
  73. $self->{btn_load_modifier}->SetFont($Slic3r::GUI::small_font);
  74. $self->{btn_load_lambda_modifier}->SetFont($Slic3r::GUI::small_font);
  75. $self->{btn_delete}->SetFont($Slic3r::GUI::small_font);
  76. $self->{btn_split}->SetFont($Slic3r::GUI::small_font);
  77. $self->{btn_move_up}->SetFont($Slic3r::GUI::small_font);
  78. $self->{btn_move_down}->SetFont($Slic3r::GUI::small_font);
  79. # part settings panel
  80. $self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new($self, on_change => sub { $self->{part_settings_changed} = 1; });
  81. my $settings_sizer = Wx::StaticBoxSizer->new($self->{staticbox} = Wx::StaticBox->new($self, -1, "Part Settings"), wxVERTICAL);
  82. $settings_sizer->Add($self->{settings_panel}, 1, wxEXPAND | wxALL, 0);
  83. my $optgroup_movers;
  84. $optgroup_movers = $self->{optgroup_movers} = Slic3r::GUI::OptionsGroup->new(
  85. parent => $self,
  86. title => 'Move',
  87. on_change => sub {
  88. my ($opt_id) = @_;
  89. # There seems to be an issue with wxWidgets 3.0.2/3.0.3, where the slider
  90. # genates tens of events for a single value change.
  91. # Only trigger the recalculation if the value changes
  92. # or a live preview was activated and the mesh cut is not valid yet.
  93. if ($self->{move_options}{$opt_id} != $optgroup_movers->get_value($opt_id)) {
  94. $self->{move_options}{$opt_id} = $optgroup_movers->get_value($opt_id);
  95. wxTheApp->CallAfter(sub {
  96. $self->_update;
  97. });
  98. }
  99. },
  100. label_width => 20,
  101. );
  102. $optgroup_movers->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  103. opt_id => 'x',
  104. type => 'slider',
  105. label => 'X',
  106. default => 0,
  107. min => -($self->{model_object}->bounding_box->size->x)*4,
  108. max => $self->{model_object}->bounding_box->size->x*4,
  109. full_width => 1,
  110. ));
  111. $optgroup_movers->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  112. opt_id => 'y',
  113. type => 'slider',
  114. label => 'Y',
  115. default => 0,
  116. min => -($self->{model_object}->bounding_box->size->y)*4,
  117. max => $self->{model_object}->bounding_box->size->y*4,
  118. full_width => 1,
  119. ));
  120. $optgroup_movers->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
  121. opt_id => 'z',
  122. type => 'slider',
  123. label => 'Z',
  124. default => 0,
  125. min => -($self->{model_object}->bounding_box->size->z)*4,
  126. max => $self->{model_object}->bounding_box->size->z*4,
  127. full_width => 1,
  128. ));
  129. # left pane with tree
  130. my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
  131. $left_sizer->Add($tree, 3, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
  132. $left_sizer->Add($buttons_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
  133. $left_sizer->Add($settings_sizer, 5, wxEXPAND | wxALL, 0);
  134. $left_sizer->Add($optgroup_movers->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
  135. # right pane with preview canvas
  136. my $canvas;
  137. if ($Slic3r::GUI::have_OpenGL) {
  138. $canvas = $self->{canvas} = Slic3r::GUI::3DScene->new($self);
  139. $canvas->enable_picking(1);
  140. $canvas->select_by('volume');
  141. $canvas->on_select(sub {
  142. my ($volume_idx) = @_;
  143. # convert scene volume to model object volume
  144. $self->reload_tree(($volume_idx == -1) ? undef : $canvas->volumes->[$volume_idx]->volume_idx);
  145. });
  146. $canvas->load_object($self->{model_object}, undef, undef, [0]);
  147. $canvas->set_auto_bed_shape;
  148. $canvas->SetSize([500,700]);
  149. $canvas->zoom_to_volumes;
  150. }
  151. $self->{sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
  152. $self->{sizer}->Add($left_sizer, 0, wxEXPAND | wxALL, 0);
  153. $self->{sizer}->Add($canvas, 1, wxEXPAND | wxALL, 0) if $canvas;
  154. $self->SetSizer($self->{sizer});
  155. $self->{sizer}->SetSizeHints($self);
  156. # attach events
  157. EVT_TREE_ITEM_COLLAPSING($self, $tree, sub {
  158. my ($self, $event) = @_;
  159. $event->Veto;
  160. });
  161. EVT_TREE_SEL_CHANGED($self, $tree, sub {
  162. my ($self, $event) = @_;
  163. return if $self->{disable_tree_sel_changed_event};
  164. $self->selection_changed;
  165. });
  166. EVT_TREE_KEY_DOWN($self, $tree, \&on_tree_key_down);
  167. EVT_BUTTON($self, $self->{btn_load_part}, sub { $self->on_btn_load(0) });
  168. EVT_BUTTON($self, $self->{btn_load_modifier}, sub { $self->on_btn_load(1) });
  169. EVT_BUTTON($self, $self->{btn_load_lambda_modifier}, sub { $self->on_btn_lambda(1) });
  170. EVT_BUTTON($self, $self->{btn_delete}, \&on_btn_delete);
  171. EVT_BUTTON($self, $self->{btn_split}, \&on_btn_split);
  172. EVT_BUTTON($self, $self->{btn_move_up}, \&on_btn_move_up);
  173. EVT_BUTTON($self, $self->{btn_move_down}, \&on_btn_move_down);
  174. $self->reload_tree;
  175. return $self;
  176. }
  177. sub reload_tree {
  178. my ($self, $selected_volume_idx) = @_;
  179. $selected_volume_idx //= -1;
  180. my $object = $self->{model_object};
  181. my $tree = $self->{tree};
  182. my $rootId = $tree->GetRootItem;
  183. # despite wxWidgets states that DeleteChildren "will not generate any events unlike Delete() method",
  184. # the MSW implementation of DeleteChildren actually calls Delete() for each item, so
  185. # EVT_TREE_SEL_CHANGED is being called, with bad effects (the event handler is called; this
  186. # subroutine is never continued; an invisible EndModal is called on the dialog causing Plater
  187. # to continue its logic and rescheduling the background process etc. GH #2774)
  188. $self->{disable_tree_sel_changed_event} = 1;
  189. $tree->DeleteChildren($rootId);
  190. $self->{disable_tree_sel_changed_event} = 0;
  191. my $selectedId = $rootId;
  192. foreach my $volume_id (0..$#{$object->volumes}) {
  193. my $volume = $object->volumes->[$volume_id];
  194. my $icon = $volume->modifier ? ICON_MODIFIERMESH : ICON_SOLIDMESH;
  195. my $itemId = $tree->AppendItem($rootId, $volume->name || $volume_id, $icon);
  196. if ($volume_id == $selected_volume_idx) {
  197. $selectedId = $itemId;
  198. }
  199. $tree->SetPlData($itemId, {
  200. type => 'volume',
  201. volume_id => $volume_id,
  202. });
  203. }
  204. $tree->ExpandAll;
  205. Slic3r::GUI->CallAfter(sub {
  206. $self->{tree}->SelectItem($selectedId);
  207. # SelectItem() should trigger EVT_TREE_SEL_CHANGED as per wxWidgets docs,
  208. # but in fact it doesn't if the given item is already selected (this happens
  209. # on first load)
  210. $self->selection_changed;
  211. });
  212. }
  213. sub get_selection {
  214. my ($self) = @_;
  215. my $nodeId = $self->{tree}->GetSelection;
  216. if ($nodeId->IsOk) {
  217. return $self->{tree}->GetPlData($nodeId);
  218. }
  219. return undef;
  220. }
  221. sub selection_changed {
  222. my ($self) = @_;
  223. # deselect all meshes
  224. if ($self->{canvas}) {
  225. $_->set_selected(0) for @{$self->{canvas}->volumes};
  226. }
  227. # disable things as if nothing is selected
  228. $self->{'btn_' . $_}->Disable for (qw(delete move_up move_down split));
  229. $self->{settings_panel}->disable;
  230. $self->{settings_panel}->set_config(undef);
  231. # reset move sliders
  232. $self->{optgroup_movers}->set_value("x", 0);
  233. $self->{optgroup_movers}->set_value("y", 0);
  234. $self->{optgroup_movers}->set_value("z", 0);
  235. $self->{move_options} = {
  236. x => 0,
  237. y => 0,
  238. z => 0,
  239. };
  240. $self->{last_coords} = {
  241. x => 0,
  242. y => 0,
  243. z => 0,
  244. };
  245. if (my $itemData = $self->get_selection) {
  246. my ($config, @opt_keys);
  247. if ($itemData->{type} eq 'volume') {
  248. # select volume in 3D preview
  249. if ($self->{canvas}) {
  250. $self->{canvas}->volumes->[ $itemData->{volume_id} ]->set_selected(1);
  251. }
  252. $self->{btn_delete}->Enable;
  253. $self->{btn_split}->Enable;
  254. $self->{btn_move_up}->Enable if $itemData->{volume_id} > 0;
  255. $self->{btn_move_down}->Enable if $itemData->{volume_id} + 1 < $self->{model_object}->volumes_count;
  256. # attach volume config to settings panel
  257. my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ];
  258. if ($volume->modifier) {
  259. $self->{optgroup_movers}->enable;
  260. } else {
  261. $self->{optgroup_movers}->disable;
  262. }
  263. $config = $volume->config;
  264. $self->{staticbox}->SetLabel('Part Settings');
  265. # get default values
  266. @opt_keys = @{Slic3r::Config::PrintRegion->new->get_keys};
  267. } elsif ($itemData->{type} eq 'object') {
  268. # select nothing in 3D preview
  269. # attach object config to settings panel
  270. $self->{optgroup_movers}->disable;
  271. $self->{staticbox}->SetLabel('Object Settings');
  272. @opt_keys = (map @{$_->get_keys}, Slic3r::Config::PrintObject->new, Slic3r::Config::PrintRegion->new);
  273. $config = $self->{model_object}->config;
  274. }
  275. # get default values
  276. my $default_config = Slic3r::Config::new_from_defaults_keys(\@opt_keys);
  277. # append default extruder
  278. push @opt_keys, 'extruder';
  279. $default_config->set('extruder', 0);
  280. $config->set_ifndef('extruder', 0);
  281. $self->{settings_panel}->set_default_config($default_config);
  282. $self->{settings_panel}->set_config($config);
  283. $self->{settings_panel}->set_opt_keys(\@opt_keys);
  284. $self->{settings_panel}->set_fixed_options([qw(extruder)]);
  285. $self->{settings_panel}->enable;
  286. }
  287. $self->{canvas}->Render if $self->{canvas};
  288. }
  289. sub on_btn_load {
  290. my ($self, $is_modifier) = @_;
  291. my @input_files = wxTheApp->open_model($self);
  292. foreach my $input_file (@input_files) {
  293. my $model = eval { Slic3r::Model->read_from_file($input_file) };
  294. if ($@) {
  295. Slic3r::GUI::show_error($self, $@);
  296. next;
  297. }
  298. foreach my $object (@{$model->objects}) {
  299. foreach my $volume (@{$object->volumes}) {
  300. my $new_volume = $self->{model_object}->add_volume($volume);
  301. $new_volume->set_modifier($is_modifier);
  302. $new_volume->set_name(basename($input_file));
  303. # apply the same translation we applied to the object
  304. $new_volume->mesh->translate(@{$self->{model_object}->origin_translation});
  305. # set a default extruder value, since user can't add it manually
  306. $new_volume->config->set_ifndef('extruder', 0);
  307. $self->{parts_changed} = 1;
  308. }
  309. }
  310. }
  311. $self->_parts_changed;
  312. }
  313. sub on_btn_lambda {
  314. my ($self, $is_modifier) = @_;
  315. my $dlg = Slic3r::GUI::Plater::LambdaObjectDialog->new($self);
  316. if ($dlg->ShowModal() == wxID_CANCEL) {
  317. return;
  318. }
  319. my $params = $dlg->ObjectParameter;
  320. my $type = "".$params->{"type"};
  321. my $name = "lambda-".$params->{"type"};
  322. my $mesh;
  323. if ($type eq "box") {
  324. $mesh = Slic3r::TriangleMesh::cube($params->{"dim"}[0], $params->{"dim"}[1], $params->{"dim"}[2]);
  325. } elsif ($type eq "cylinder") {
  326. $mesh = Slic3r::TriangleMesh::cylinder($params->{"cyl_r"}, $params->{"cyl_h"});
  327. } elsif ($type eq "sphere") {
  328. $mesh = Slic3r::TriangleMesh::sphere($params->{"sph_rho"});
  329. } elsif ($type eq "slab") {
  330. $mesh = Slic3r::TriangleMesh::cube($self->{model_object}->bounding_box->size->x*1.5, $self->{model_object}->bounding_box->size->y*1.5, $params->{"slab_h"});
  331. # box sets the base coordinate at 0,0, move to center of plate and move it up to initial_z
  332. $mesh->translate(-$self->{model_object}->bounding_box->size->x*1.5/2.0, -$self->{model_object}->bounding_box->size->y*1.5/2.0, $params->{"slab_z"});
  333. } else {
  334. return;
  335. }
  336. $mesh->repair;
  337. my $new_volume = $self->{model_object}->add_volume(mesh => $mesh);
  338. $new_volume->set_modifier($is_modifier);
  339. $new_volume->set_name($name);
  340. # set a default extruder value, since user can't add it manually
  341. $new_volume->config->set_ifndef('extruder', 0);
  342. $self->{parts_changed} = 1;
  343. $self->_parts_changed;
  344. }
  345. sub on_tree_key_down {
  346. my ($self, $event) = @_;
  347. my $keycode = $event->GetKeyCode;
  348. # Wx >= 0.9911
  349. if (defined(&Wx::TreeEvent::GetKeyEvent) &&
  350. ($event->GetKeyEvent->GetModifiers & wxMOD_CONTROL)) {
  351. if ($keycode == WXK_UP) {
  352. $event->Skip;
  353. $self->on_btn_move_up;
  354. } elsif ($keycode == WXK_DOWN) {
  355. $event->Skip;
  356. $self->on_btn_move_down;
  357. }
  358. }
  359. }
  360. sub on_btn_move_up {
  361. my ($self) = @_;
  362. my $itemData = $self->get_selection;
  363. if ($itemData && $itemData->{type} eq 'volume') {
  364. my $volume_id = $itemData->{volume_id};
  365. if ($self->{model_object}->move_volume_up($volume_id)) {
  366. $self->{canvas}->volumes->move_volume_up($volume_id);
  367. $self->{parts_changed} = 1;
  368. $self->reload_tree($volume_id - 1);
  369. }
  370. }
  371. }
  372. sub on_btn_move_down {
  373. my ($self) = @_;
  374. my $itemData = $self->get_selection;
  375. if ($itemData && $itemData->{type} eq 'volume') {
  376. my $volume_id = $itemData->{volume_id};
  377. if ($self->{model_object}->move_volume_down($volume_id)) {
  378. $self->{canvas}->volumes->move_volume_down($volume_id);
  379. $self->{parts_changed} = 1;
  380. $self->reload_tree($volume_id + 1);
  381. }
  382. }
  383. }
  384. sub on_btn_delete {
  385. my ($self) = @_;
  386. my $itemData = $self->get_selection;
  387. if ($itemData && $itemData->{type} eq 'volume') {
  388. my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}];
  389. # if user is deleting the last solid part, throw error
  390. if (!$volume->modifier && scalar(grep !$_->modifier, @{$self->{model_object}->volumes}) == 1) {
  391. Slic3r::GUI::show_error($self, "You can't delete the last solid part from this object.");
  392. return;
  393. }
  394. $self->{model_object}->delete_volume($itemData->{volume_id});
  395. $self->{parts_changed} = 1;
  396. }
  397. $self->_parts_changed;
  398. }
  399. sub on_btn_split {
  400. my ($self) = @_;
  401. my $itemData = $self->get_selection;
  402. if ($itemData && $itemData->{type} eq 'volume') {
  403. my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}];
  404. $self->{parts_changed} = 1 if $volume->split > 1;
  405. }
  406. $self->_parts_changed;
  407. }
  408. sub _parts_changed {
  409. my ($self) = @_;
  410. $self->reload_tree;
  411. if ($self->{canvas}) {
  412. $self->{canvas}->reset_objects;
  413. $self->{canvas}->load_object($self->{model_object});
  414. $self->{canvas}->zoom_to_volumes;
  415. $self->{canvas}->Render;
  416. }
  417. }
  418. sub CanClose {
  419. my $self = shift;
  420. return 1; # skip validation for now
  421. # validate options before allowing user to dismiss the dialog
  422. # the validate method only works on full configs so we have
  423. # to merge our settings with the default ones
  424. my $config = $self->GetParent->GetParent->GetParent->GetParent->GetParent->config->clone;
  425. eval {
  426. $config->apply($self->model_object->config);
  427. $config->validate;
  428. };
  429. return ! Slic3r::GUI::catch_error($self);
  430. }
  431. sub PartsChanged {
  432. my ($self) = @_;
  433. return $self->{parts_changed};
  434. }
  435. sub PartSettingsChanged {
  436. my ($self) = @_;
  437. return $self->{part_settings_changed};
  438. }
  439. sub _update {
  440. my ($self) = @_;
  441. my ($m_x, $m_y, $m_z) = ($self->{move_options}{x}, $self->{move_options}{y}, $self->{move_options}{z});
  442. my ($l_x, $l_y, $l_z) = ($self->{last_coords}{x}, $self->{last_coords}{y}, $self->{last_coords}{z});
  443. my $itemData = $self->get_selection;
  444. if ($itemData && $itemData->{type} eq 'volume') {
  445. my $d = Slic3r::Pointf3->new($m_x - $l_x, $m_y - $l_y, $m_z - $l_z);
  446. my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}];
  447. $volume->mesh->translate(@{$d});
  448. $self->{last_coords}{x} = $m_x;
  449. $self->{last_coords}{y} = $m_y;
  450. $self->{last_coords}{z} = $m_z;
  451. }
  452. $self->{parts_changed} = 1;
  453. my @objects = ();
  454. push @objects, $self->{model_object};
  455. $self->{canvas}->reset_objects;
  456. $self->{canvas}->load_object($_, undef, [0]) for @objects;
  457. $self->{canvas}->Render;
  458. }
  459. 1;