Plater.pm 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683
  1. # The "Plater" tab. It contains the "3D", "2D", "Preview" and "Layers" subtabs.
  2. package Slic3r::GUI::Plater;
  3. use strict;
  4. use warnings;
  5. use utf8;
  6. use File::Basename qw(basename dirname);
  7. use List::Util qw(sum first max);
  8. use Slic3r::Geometry qw(X Y Z scale unscale deg2rad rad2deg);
  9. use Wx qw(:button :colour :cursor :dialog :filedialog :keycode :icon :font :id :listctrl :misc
  10. :panel :sizer :toolbar :window wxTheApp :notebook :combobox wxNullBitmap);
  11. use Wx::Event qw(EVT_BUTTON EVT_TOGGLEBUTTON EVT_COMMAND EVT_KEY_DOWN EVT_LIST_ITEM_ACTIVATED
  12. EVT_LIST_ITEM_DESELECTED EVT_LIST_ITEM_SELECTED EVT_LEFT_DOWN EVT_MOUSE_EVENTS EVT_PAINT EVT_TOOL
  13. EVT_CHOICE EVT_COMBOBOX EVT_TIMER EVT_NOTEBOOK_PAGE_CHANGED);
  14. use Slic3r::Geometry qw(PI);
  15. use base 'Wx::Panel';
  16. use constant TB_ADD => &Wx::NewId;
  17. use constant TB_REMOVE => &Wx::NewId;
  18. use constant TB_RESET => &Wx::NewId;
  19. use constant TB_ARRANGE => &Wx::NewId;
  20. use constant TB_EXPORT_GCODE => &Wx::NewId;
  21. use constant TB_EXPORT_STL => &Wx::NewId;
  22. use constant TB_MORE => &Wx::NewId;
  23. use constant TB_FEWER => &Wx::NewId;
  24. use constant TB_45CW => &Wx::NewId;
  25. use constant TB_45CCW => &Wx::NewId;
  26. use constant TB_SCALE => &Wx::NewId;
  27. use constant TB_SPLIT => &Wx::NewId;
  28. use constant TB_CUT => &Wx::NewId;
  29. use constant TB_SETTINGS => &Wx::NewId;
  30. use constant TB_LAYER_EDITING => &Wx::NewId;
  31. use Wx::Locale gettext => 'L';
  32. # Emitted from the worker thread when the G-code export is finished.
  33. our $SLICING_COMPLETED_EVENT = Wx::NewEventType;
  34. our $PROCESS_COMPLETED_EVENT = Wx::NewEventType;
  35. my $PreventListEvents = 0;
  36. our $appController;
  37. # XXX: VK: done, except callback handling and timer
  38. sub new {
  39. my ($class, $parent, %params) = @_;
  40. my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  41. Slic3r::GUI::set_plater($self);
  42. $self->{config} = Slic3r::Config::new_from_defaults_keys([qw(
  43. bed_shape complete_objects extruder_clearance_radius skirts skirt_distance brim_width variable_layer_height
  44. serial_port serial_speed host_type print_host printhost_apikey printhost_cafile
  45. nozzle_diameter single_extruder_multi_material wipe_tower wipe_tower_x wipe_tower_y wipe_tower_width
  46. wipe_tower_rotation_angle extruder_colour filament_colour max_print_height printer_model
  47. )]);
  48. # store input params
  49. $self->{event_object_selection_changed} = $params{event_object_selection_changed};
  50. $self->{event_object_settings_changed} = $params{event_object_settings_changed};
  51. $self->{event_remove_object} = $params{event_remove_object};
  52. $self->{event_update_scene} = $params{event_update_scene};
  53. # C++ Slic3r::Model with Perl extensions in Slic3r/Model.pm
  54. $self->{model} = Slic3r::Model->new;
  55. # C++ Slic3r::Print with Perl extensions in Slic3r/Print.pm
  56. $self->{print} = Slic3r::Print->new;
  57. # List of Perl objects Slic3r::GUI::Plater::Object, representing a 2D preview of the platter.
  58. $self->{objects} = [];
  59. $self->{gcode_preview_data} = Slic3r::GCode::PreviewData->new;
  60. $self->{background_slicing_process} = Slic3r::GUI::BackgroundSlicingProcess->new;
  61. $self->{background_slicing_process}->set_print($self->{print});
  62. $self->{background_slicing_process}->set_gcode_preview_data($self->{gcode_preview_data});
  63. $self->{background_slicing_process}->set_sliced_event($SLICING_COMPLETED_EVENT);
  64. $self->{background_slicing_process}->set_finished_event($PROCESS_COMPLETED_EVENT);
  65. # The C++ slicing core will post a wxCommand message to the main window.
  66. Slic3r::GUI::set_print_callback_event($self->{print}, $Slic3r::GUI::MainFrame::PROGRESS_BAR_EVENT);
  67. # Initialize preview notebook
  68. $self->{preview_notebook} = Wx::Notebook->new($self, -1, wxDefaultPosition, [-1,335], wxNB_BOTTOM);
  69. # Initialize handlers for canvases
  70. my $on_select_object = sub {
  71. my ($obj_idx, $vol_idx) = @_;
  72. if (($obj_idx != -1) && ($vol_idx == -1)) {
  73. # Ignore the special objects (the wipe tower proxy and such).
  74. $self->select_object((defined($obj_idx) && $obj_idx >= 0 && $obj_idx < 1000) ? $obj_idx : undef);
  75. $self->item_changed_selection($obj_idx) if (defined($obj_idx));
  76. }
  77. };
  78. my $on_right_click = sub {
  79. my ($canvas, $click_pos_x, $click_pos_y) = @_;
  80. my ($obj_idx, $object) = $self->selected_object;
  81. return if !defined $obj_idx;
  82. my $menu = $self->object_menu;
  83. $canvas->PopupMenu($menu, $click_pos_x, $click_pos_y);
  84. $menu->Destroy;
  85. };
  86. my $on_instances_moved = sub {
  87. $self->update;
  88. };
  89. # callback to enable/disable action buttons
  90. my $enable_action_buttons = sub {
  91. my ($enable) = @_;
  92. Slic3r::GUI::enable_action_buttons($enable);
  93. # $self->{btn_export_gcode}->Enable($enable);
  94. # $self->{btn_reslice}->Enable($enable);
  95. # $self->{btn_print}->Enable($enable);
  96. # $self->{btn_send_gcode}->Enable($enable);
  97. };
  98. # callback to react to gizmo scale
  99. my $on_gizmo_scale_uniformly = sub {
  100. my ($scale) = @_;
  101. my ($obj_idx, $object) = $self->selected_object;
  102. return if !defined $obj_idx;
  103. my $model_object = $self->{model}->objects->[$obj_idx];
  104. my $model_instance = $model_object->instances->[0];
  105. $self->stop_background_process;
  106. my $variation = $scale / $model_instance->scaling_factor;
  107. #FIXME Scale the layer height profile?
  108. foreach my $range (@{ $model_object->layer_height_ranges }) {
  109. $range->[0] *= $variation;
  110. $range->[1] *= $variation;
  111. }
  112. $_->set_scaling_factor($scale) for @{ $model_object->instances };
  113. # Set object scale on c++ side
  114. # Slic3r::GUI::set_object_scale($obj_idx, $model_object->instances->[0]->scaling_factor * 100);
  115. # $object->transform_thumbnail($self->{model}, $obj_idx);
  116. #update print and start background processing
  117. $self->{print}->add_model_object($model_object, $obj_idx);
  118. $self->selection_changed(1); # refresh info (size, volume etc.)
  119. $self->update;
  120. $self->schedule_background_process;
  121. };
  122. # callback to react to gizmo scale
  123. my $on_gizmo_scale_3D = sub {
  124. my ($scale_x, $scale_y, $scale_z) = @_;
  125. my ($obj_idx, $object) = $self->selected_object;
  126. return if !defined $obj_idx;
  127. my $model_object = $self->{model}->objects->[$obj_idx];
  128. my $model_instance = $model_object->instances->[0];
  129. $self->stop_background_process;
  130. #FIXME Scale the layer height profile?
  131. # my $variation = $scale / $model_instance->scaling_factor;
  132. # foreach my $range (@{ $model_object->layer_height_ranges }) {
  133. # $range->[0] *= $variation;
  134. # $range->[1] *= $variation;
  135. # }
  136. my $scale = Slic3r::Pointf3->new($scale_x, $scale_y, $scale_z);
  137. foreach my $inst (@{ $model_object->instances }) {
  138. $inst->set_scaling_factors($scale);
  139. }
  140. Slic3r::GUI::_3DScene::update_gizmos_data($self->{canvas3D}) if ($self->{canvas3D});
  141. #update print and start background processing
  142. $self->{print}->add_model_object($model_object, $obj_idx);
  143. $self->selection_changed(1); # refresh info (size, volume etc.)
  144. $self->update;
  145. $self->schedule_background_process;
  146. };
  147. # callback to react to gizmo rotate
  148. my $on_gizmo_rotate = sub {
  149. my ($angle) = @_;
  150. $self->rotate(rad2deg($angle), Z, 'absolute');
  151. };
  152. # callback to react to gizmo rotate
  153. my $on_gizmo_rotate_3D = sub {
  154. my ($angle_x, $angle_y, $angle_z) = @_;
  155. my ($obj_idx, $object) = $self->selected_object;
  156. return if !defined $obj_idx;
  157. my $model_object = $self->{model}->objects->[$obj_idx];
  158. my $model_instance = $model_object->instances->[0];
  159. $self->stop_background_process;
  160. my $rotation = Slic3r::Pointf3->new($angle_x, $angle_y, $angle_z);
  161. foreach my $inst (@{ $model_object->instances }) {
  162. $inst->set_rotations($rotation);
  163. }
  164. Slic3r::GUI::_3DScene::update_gizmos_data($self->{canvas3D}) if ($self->{canvas3D});
  165. # update print and start background processing
  166. $self->{print}->add_model_object($model_object, $obj_idx);
  167. $self->selection_changed; # refresh info (size etc.)
  168. $self->update;
  169. $self->schedule_background_process;
  170. };
  171. # callback to react to gizmo flatten
  172. my $on_gizmo_flatten = sub {
  173. my ($angle, $axis_x, $axis_y, $axis_z) = @_;
  174. $self->rotate(rad2deg($angle), undef, 'absolute', $axis_x, $axis_y, $axis_z) if $angle != 0;
  175. };
  176. # callback to react to gizmo flatten
  177. my $on_gizmo_flatten_3D = sub {
  178. my ($angle_x, $angle_y, $angle_z) = @_;
  179. my ($obj_idx, $object) = $self->selected_object;
  180. return if !defined $obj_idx;
  181. my $model_object = $self->{model}->objects->[$obj_idx];
  182. my $model_instance = $model_object->instances->[0];
  183. $self->stop_background_process;
  184. my $rotation = Slic3r::Pointf3->new($angle_x, $angle_y, $angle_z);
  185. foreach my $inst (@{ $model_object->instances }) {
  186. $inst->set_rotations($rotation);
  187. }
  188. Slic3r::GUI::_3DScene::update_gizmos_data($self->{canvas3D}) if ($self->{canvas3D});
  189. # update print and start background processing
  190. $self->{print}->add_model_object($model_object, $obj_idx);
  191. $self->selection_changed; # refresh info (size etc.)
  192. $self->update;
  193. $self->schedule_background_process;
  194. };
  195. # callback to update object's geometry info while using gizmos
  196. my $on_update_geometry_info = sub {
  197. my ($size_x, $size_y, $size_z, $scale_factor) = @_;
  198. my ($obj_idx, $object) = $self->selected_object;
  199. if ((defined $obj_idx) && ($self->{object_info_size})) { # have we already loaded the info pane?
  200. $self->{object_info_size}->SetLabel(sprintf("%.2f x %.2f x %.2f", $size_x, $size_y, $size_z));
  201. my $model_object = $self->{model}->objects->[$obj_idx];
  202. if (my $stats = $model_object->mesh_stats) {
  203. $self->{object_info_volume}->SetLabel(sprintf('%.2f', $stats->{volume} * $scale_factor**3));
  204. }
  205. }
  206. };
  207. # callback to update object's geometry info while using gizmos
  208. my $on_update_geometry_3D_info = sub {
  209. my ($size_x, $size_y, $size_z, $scale_x, $scale_y, $scale_z) = @_;
  210. my ($obj_idx, $object) = $self->selected_object;
  211. if ((defined $obj_idx) && ($self->{object_info_size})) { # have we already loaded the info pane?
  212. $self->{object_info_size}->SetLabel(sprintf("%.2f x %.2f x %.2f", $size_x, $size_y, $size_z));
  213. my $model_object = $self->{model}->objects->[$obj_idx];
  214. if (my $stats = $model_object->mesh_stats) {
  215. $self->{object_info_volume}->SetLabel(sprintf('%.2f', $stats->{volume} * $scale_x * $scale_y * $scale_z));
  216. }
  217. }
  218. };
  219. # callbacks for toolbar
  220. my $on_action_add = sub {
  221. $self->add;
  222. };
  223. my $on_action_delete = sub {
  224. $self->remove();
  225. };
  226. my $on_action_deleteall = sub {
  227. $self->reset;
  228. };
  229. my $on_action_arrange = sub {
  230. $self->arrange;
  231. };
  232. my $on_action_more = sub {
  233. $self->increase;
  234. };
  235. my $on_action_fewer = sub {
  236. $self->decrease;
  237. };
  238. my $on_action_split = sub {
  239. $self->split_object;
  240. };
  241. my $on_action_cut = sub {
  242. $self->object_cut_dialog;
  243. };
  244. my $on_action_settings = sub {
  245. $self->object_settings_dialog;
  246. };
  247. my $on_action_layersediting = sub {
  248. my $state = Slic3r::GUI::_3DScene::is_toolbar_item_pressed($self->{canvas3D}, "layersediting");
  249. $self->on_layer_editing_toggled($state);
  250. };
  251. my $on_action_selectbyparts = sub {
  252. my $curr = Slic3r::GUI::_3DScene::get_select_by($self->{canvas3D});
  253. if ($curr eq 'volume') {
  254. Slic3r::GUI::_3DScene::set_select_by($self->{canvas3D}, 'object');
  255. my $selections = $self->collect_selections;
  256. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  257. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1);
  258. }
  259. elsif ($curr eq 'object') {
  260. Slic3r::GUI::_3DScene::set_select_by($self->{canvas3D}, 'volume');
  261. my $selections = [];
  262. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  263. Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas3D});
  264. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1);
  265. my ($obj_idx, $object) = $self->selected_object;
  266. if (defined $obj_idx) {
  267. my $vol_idx = Slic3r::GUI::_3DScene::get_first_volume_id($self->{canvas3D}, $obj_idx);
  268. #Slic3r::GUI::_3DScene::select_volume($self->{canvas3D}, $vol_idx) if ($vol_idx != -1);
  269. my $inst_cnt = $self->{model}->objects->[$obj_idx]->instances_count;
  270. for (0..$inst_cnt-1){
  271. Slic3r::GUI::_3DScene::select_volume($self->{canvas3D}, $_ + $vol_idx) if ($vol_idx != -1);
  272. }
  273. my $volume_idx = Slic3r::GUI::_3DScene::get_in_object_volume_id($self->{canvas3D}, $vol_idx);
  274. Slic3r::GUI::select_current_volume($obj_idx, $volume_idx) if ($volume_idx != -1);
  275. }
  276. }
  277. };
  278. # Initialize 3D plater
  279. if ($Slic3r::GUI::have_OpenGL) {
  280. $self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{print}, $self->{config});
  281. $self->{preview_notebook}->AddPage($self->{canvas3D}, L('3D'));
  282. Slic3r::GUI::_3DScene::register_on_select_object_callback($self->{canvas3D}, $on_select_object);
  283. # Slic3r::GUI::_3DScene::register_on_double_click_callback($self->{canvas3D}, $on_double_click);
  284. Slic3r::GUI::_3DScene::register_on_right_click_callback($self->{canvas3D}, sub { $on_right_click->($self->{canvas3D}, @_); });
  285. Slic3r::GUI::_3DScene::register_on_arrange_callback($self->{canvas3D}, sub { $self->arrange });
  286. Slic3r::GUI::_3DScene::register_on_rotate_object_left_callback($self->{canvas3D}, sub { $self->rotate(-45, Z, 'relative') });
  287. Slic3r::GUI::_3DScene::register_on_rotate_object_right_callback($self->{canvas3D}, sub { $self->rotate( 45, Z, 'relative') });
  288. Slic3r::GUI::_3DScene::register_on_scale_object_uniformly_callback($self->{canvas3D}, sub { $self->changescale(undef) });
  289. Slic3r::GUI::_3DScene::register_on_increase_objects_callback($self->{canvas3D}, sub { $self->increase() });
  290. Slic3r::GUI::_3DScene::register_on_decrease_objects_callback($self->{canvas3D}, sub { $self->decrease() });
  291. Slic3r::GUI::_3DScene::register_on_remove_object_callback($self->{canvas3D}, sub { $self->remove() });
  292. Slic3r::GUI::_3DScene::register_on_instance_moved_callback($self->{canvas3D}, $on_instances_moved);
  293. Slic3r::GUI::_3DScene::register_on_enable_action_buttons_callback($self->{canvas3D}, $enable_action_buttons);
  294. Slic3r::GUI::_3DScene::register_on_gizmo_scale_uniformly_callback($self->{canvas3D}, $on_gizmo_scale_uniformly);
  295. Slic3r::GUI::_3DScene::register_on_gizmo_scale_3D_callback($self->{canvas3D}, $on_gizmo_scale_3D);
  296. Slic3r::GUI::_3DScene::register_on_gizmo_rotate_callback($self->{canvas3D}, $on_gizmo_rotate);
  297. Slic3r::GUI::_3DScene::register_on_gizmo_rotate_3D_callback($self->{canvas3D}, $on_gizmo_rotate_3D);
  298. Slic3r::GUI::_3DScene::register_on_gizmo_flatten_callback($self->{canvas3D}, $on_gizmo_flatten);
  299. Slic3r::GUI::_3DScene::register_on_gizmo_flatten_3D_callback($self->{canvas3D}, $on_gizmo_flatten_3D);
  300. Slic3r::GUI::_3DScene::register_on_update_geometry_info_callback($self->{canvas3D}, $on_update_geometry_info);
  301. Slic3r::GUI::_3DScene::register_on_update_geometry_3D_info_callback($self->{canvas3D}, $on_update_geometry_3D_info);
  302. Slic3r::GUI::_3DScene::register_action_add_callback($self->{canvas3D}, $on_action_add);
  303. Slic3r::GUI::_3DScene::register_action_delete_callback($self->{canvas3D}, $on_action_delete);
  304. Slic3r::GUI::_3DScene::register_action_deleteall_callback($self->{canvas3D}, $on_action_deleteall);
  305. Slic3r::GUI::_3DScene::register_action_arrange_callback($self->{canvas3D}, $on_action_arrange);
  306. Slic3r::GUI::_3DScene::register_action_more_callback($self->{canvas3D}, $on_action_more);
  307. Slic3r::GUI::_3DScene::register_action_fewer_callback($self->{canvas3D}, $on_action_fewer);
  308. Slic3r::GUI::_3DScene::register_action_split_callback($self->{canvas3D}, $on_action_split);
  309. Slic3r::GUI::_3DScene::register_action_cut_callback($self->{canvas3D}, $on_action_cut);
  310. Slic3r::GUI::_3DScene::register_action_settings_callback($self->{canvas3D}, $on_action_settings);
  311. Slic3r::GUI::_3DScene::register_action_layersediting_callback($self->{canvas3D}, $on_action_layersediting);
  312. Slic3r::GUI::_3DScene::register_action_selectbyparts_callback($self->{canvas3D}, $on_action_selectbyparts);
  313. Slic3r::GUI::_3DScene::enable_gizmos($self->{canvas3D}, 1);
  314. Slic3r::GUI::_3DScene::enable_toolbar($self->{canvas3D}, 1);
  315. Slic3r::GUI::_3DScene::enable_shader($self->{canvas3D}, 1);
  316. Slic3r::GUI::_3DScene::enable_force_zoom_to_bed($self->{canvas3D}, 1);
  317. Slic3r::GUI::_3DScene::register_on_wipe_tower_moved_callback($self->{canvas3D}, sub {
  318. my ($x, $y) = @_;
  319. my $cfg = Slic3r::Config->new;
  320. $cfg->set('wipe_tower_x', $x);
  321. $cfg->set('wipe_tower_y', $y);
  322. $self->GetFrame->{options_tabs}{print}->load_config($cfg);
  323. });
  324. Slic3r::GUI::_3DScene::register_on_model_update_callback($self->{canvas3D}, sub {
  325. if (wxTheApp->{app_config}->get("background_processing")) {
  326. $self->schedule_background_process;
  327. } else {
  328. # Hide the print info box, it is no more valid.
  329. $self->print_info_box_show(0);
  330. }
  331. });
  332. Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{canvas3D},
  333. sub {
  334. $self->{preview_iface}->set_viewport_from_scene($self->{canvas3D});
  335. });
  336. # Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{canvas3D}, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D}); });
  337. }
  338. Slic3r::GUI::register_on_request_update_callback(sub { $self->schedule_background_process; });
  339. # Initialize 3D toolpaths preview
  340. if ($Slic3r::GUI::have_OpenGL) {
  341. $self->{preview_iface} = Slic3r::GUI::create_preview_iface($self->{preview_notebook}, $self->{config}, $self->{print}, $self->{gcode_preview_data});
  342. $self->{preview_page_idx} = $self->{preview_notebook}->GetPageCount-1;
  343. $self->{preview_iface}->register_on_viewport_changed_callback(sub { $self->{preview_iface}->set_viewport_into_scene($self->{canvas3D}); });
  344. # $self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self->{preview_notebook}, $self->{print}, $self->{gcode_preview_data}, $self->{config});
  345. # Slic3r::GUI::_3DScene::enable_legend_texture($self->{preview3D}->canvas, 1);
  346. # Slic3r::GUI::_3DScene::enable_dynamic_background($self->{preview3D}->canvas, 1);
  347. # Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{preview3D}->canvas, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{canvas3D}, $self->{preview3D}->canvas); });
  348. # $self->{preview_notebook}->AddPage($self->{preview3D}, L('Preview'));
  349. $self->{preview3D_page_idx} = $self->{preview_notebook}->GetPageCount-1;
  350. }
  351. EVT_NOTEBOOK_PAGE_CHANGED($self, $self->{preview_notebook}, sub {
  352. my $preview = $self->{preview_notebook}->GetCurrentPage;
  353. my $page_id = $self->{preview_notebook}->GetSelection;
  354. if (($preview != $self->{canvas3D}) && ($page_id != $self->{preview_page_idx})) {
  355. # if (($preview != $self->{preview3D}) && ($preview != $self->{canvas3D})) {
  356. $preview->OnActivate if $preview->can('OnActivate');
  357. } elsif ($page_id == $self->{preview_page_idx}) {
  358. $self->{preview_iface}->reload_print;
  359. # sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably)
  360. $self->{preview_iface}->set_canvas_as_dirty;
  361. # } elsif ($preview == $self->{preview3D}) {
  362. # $self->{preview3D}->reload_print;
  363. # # sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably)
  364. # Slic3r::GUI::_3DScene::set_as_dirty($self->{preview3D}->canvas);
  365. } elsif ($preview == $self->{canvas3D}) {
  366. if (Slic3r::GUI::_3DScene::is_reload_delayed($self->{canvas3D})) {
  367. my $selections = $self->collect_selections;
  368. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  369. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1);
  370. }
  371. # sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably)
  372. Slic3r::GUI::_3DScene::set_as_dirty($self->{canvas3D});
  373. }
  374. });
  375. # # toolbar for object manipulation
  376. # if (!&Wx::wxMSW) {
  377. # Wx::ToolTip::Enable(1);
  378. # $self->{htoolbar} = Wx::ToolBar->new($self, -1, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxTB_TEXT | wxBORDER_SIMPLE | wxTAB_TRAVERSAL);
  379. # $self->{htoolbar}->AddTool(TB_ADD, L("Add…"), Wx::Bitmap->new(Slic3r::var("brick_add.png"), wxBITMAP_TYPE_PNG), '');
  380. # $self->{htoolbar}->AddTool(TB_REMOVE, L("Delete"), Wx::Bitmap->new(Slic3r::var("brick_delete.png"), wxBITMAP_TYPE_PNG), '');
  381. # $self->{htoolbar}->AddTool(TB_RESET, L("Delete All"), Wx::Bitmap->new(Slic3r::var("cross.png"), wxBITMAP_TYPE_PNG), '');
  382. # $self->{htoolbar}->AddTool(TB_ARRANGE, L("Arrange"), Wx::Bitmap->new(Slic3r::var("bricks.png"), wxBITMAP_TYPE_PNG), '');
  383. # $self->{htoolbar}->AddSeparator;
  384. # $self->{htoolbar}->AddTool(TB_MORE, L("More"), Wx::Bitmap->new(Slic3r::var("add.png"), wxBITMAP_TYPE_PNG), '');
  385. # $self->{htoolbar}->AddTool(TB_FEWER, L("Fewer"), Wx::Bitmap->new(Slic3r::var("delete.png"), wxBITMAP_TYPE_PNG), '');
  386. # $self->{htoolbar}->AddSeparator;
  387. # $self->{htoolbar}->AddTool(TB_45CCW, L("45° ccw"), Wx::Bitmap->new(Slic3r::var("arrow_rotate_anticlockwise.png"), wxBITMAP_TYPE_PNG), '');
  388. # $self->{htoolbar}->AddTool(TB_45CW, L("45° cw"), Wx::Bitmap->new(Slic3r::var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), '');
  389. # $self->{htoolbar}->AddTool(TB_SCALE, L("Scale…"), Wx::Bitmap->new(Slic3r::var("arrow_out.png"), wxBITMAP_TYPE_PNG), '');
  390. # $self->{htoolbar}->AddTool(TB_SPLIT, L("Split"), Wx::Bitmap->new(Slic3r::var("shape_ungroup.png"), wxBITMAP_TYPE_PNG), '');
  391. # $self->{htoolbar}->AddTool(TB_CUT, L("Cut…"), Wx::Bitmap->new(Slic3r::var("package.png"), wxBITMAP_TYPE_PNG), '');
  392. # $self->{htoolbar}->AddSeparator;
  393. # $self->{htoolbar}->AddTool(TB_SETTINGS, L("Settings…"), Wx::Bitmap->new(Slic3r::var("cog.png"), wxBITMAP_TYPE_PNG), '');
  394. # $self->{htoolbar}->AddTool(TB_LAYER_EDITING, L('Layer Editing'), Wx::Bitmap->new(Slic3r::var("variable_layer_height.png"), wxBITMAP_TYPE_PNG), wxNullBitmap, 1, 0, 'Layer Editing');
  395. # } else {
  396. # my %tbar_buttons = (
  397. # add => L("Add…"),
  398. # remove => L("Delete"),
  399. # reset => L("Delete All"),
  400. # arrange => L("Arrange"),
  401. # increase => "",
  402. # decrease => "",
  403. # rotate45ccw => "",
  404. # rotate45cw => "",
  405. # changescale => L("Scale…"),
  406. # split => L("Split"),
  407. # cut => L("Cut…"),
  408. # settings => L("Settings…"),
  409. # layer_editing => L("Layer editing"),
  410. # );
  411. # $self->{btoolbar} = Wx::BoxSizer->new(wxHORIZONTAL);
  412. # for (qw(add remove reset arrange increase decrease rotate45ccw rotate45cw changescale split cut settings)) {
  413. # $self->{"btn_$_"} = Wx::Button->new($self, -1, $tbar_buttons{$_}, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
  414. # $self->{btoolbar}->Add($self->{"btn_$_"});
  415. # }
  416. # $self->{"btn_layer_editing"} = Wx::ToggleButton->new($self, -1, $tbar_buttons{'layer_editing'}, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
  417. # $self->{btoolbar}->Add($self->{"btn_layer_editing"});
  418. # }
  419. ### Panel for right column
  420. $self->{right_panel} = Wx::Panel->new($self, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  421. # $self->{right_panel} = Wx::ScrolledWindow->new($self, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  422. # $self->{right_panel}->SetScrollbars(0, 1, 1, 1);
  423. ### Scrolled Window for panel without "Export G-code" and "Slice now" buttons
  424. my $scrolled_window_sizer = $self->{scrolled_window_sizer} = Wx::BoxSizer->new(wxVERTICAL);
  425. $scrolled_window_sizer->SetMinSize([320, -1]);
  426. my $scrolled_window_panel = $self->{scrolled_window_panel} = Wx::ScrolledWindow->new($self->{right_panel}, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
  427. $scrolled_window_panel->SetSizer($scrolled_window_sizer);
  428. $scrolled_window_panel->SetScrollbars(0, 1, 1, 1);
  429. # right pane buttons
  430. $self->{btn_export_gcode} = Wx::Button->new($self->{right_panel}, -1, L("Export G-code…"), wxDefaultPosition, [-1, 30],);# wxNO_BORDER);#, wxBU_LEFT);
  431. $self->{btn_reslice} = Wx::Button->new($self->{right_panel}, -1, L("Slice now"), wxDefaultPosition, [-1, 30]);#, wxNO_BORDER);#, wxBU_LEFT);
  432. # $self->{btn_print} = Wx::Button->new($self->{right_panel}, -1, L("Print…"), wxDefaultPosition, [-1, 30], wxBU_LEFT);
  433. # $self->{btn_send_gcode} = Wx::Button->new($self->{right_panel}, -1, L("Send to printer"), wxDefaultPosition, [-1, 30], wxBU_LEFT);
  434. $self->{btn_print} = Wx::Button->new($scrolled_window_panel, -1, L("Print…"), wxDefaultPosition, [-1, 30], wxBU_LEFT);
  435. $self->{btn_send_gcode} = Wx::Button->new($scrolled_window_panel, -1, L("Send to printer"), wxDefaultPosition, [-1, 30], wxBU_LEFT);
  436. #$self->{btn_export_stl} = Wx::Button->new($self->{right_panel}, -1, L("Export STL…"), wxDefaultPosition, [-1, 30], wxBU_LEFT);
  437. #$self->{btn_export_gcode}->SetFont($Slic3r::GUI::small_font);
  438. #$self->{btn_export_stl}->SetFont($Slic3r::GUI::small_font);
  439. $self->{btn_print}->Hide;
  440. $self->{btn_send_gcode}->Hide;
  441. # export_gcode cog_go.png
  442. #! reslice reslice.png
  443. my %icons = qw(
  444. print arrow_up.png
  445. send_gcode arrow_up.png
  446. export_stl brick_go.png
  447. );
  448. for (grep $self->{"btn_$_"}, keys %icons) {
  449. $self->{"btn_$_"}->SetBitmap(Wx::Bitmap->new(Slic3r::var($icons{$_}), wxBITMAP_TYPE_PNG));
  450. }
  451. $self->selection_changed(0);
  452. $self->object_list_changed;
  453. EVT_BUTTON($self, $self->{btn_export_gcode}, sub {
  454. $self->export_gcode;
  455. });
  456. EVT_BUTTON($self, $self->{btn_print}, sub {
  457. $self->{print_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir());
  458. });
  459. EVT_BUTTON($self, $self->{btn_send_gcode}, sub {
  460. $self->{send_gcode_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir());
  461. });
  462. EVT_BUTTON($self, $self->{btn_reslice}, \&reslice);
  463. EVT_BUTTON($self, $self->{btn_export_stl}, \&export_stl);
  464. # if ($self->{htoolbar}) {
  465. # EVT_TOOL($self, TB_ADD, sub { $self->add; });
  466. # EVT_TOOL($self, TB_REMOVE, sub { $self->remove() }); # explicitly pass no argument to remove
  467. # EVT_TOOL($self, TB_RESET, sub { $self->reset; });
  468. # EVT_TOOL($self, TB_ARRANGE, sub { $self->arrange; });
  469. # EVT_TOOL($self, TB_MORE, sub { $self->increase; });
  470. # EVT_TOOL($self, TB_FEWER, sub { $self->decrease; });
  471. # EVT_TOOL($self, TB_45CW, sub { $_[0]->rotate(-45, Z, 'relative') });
  472. # EVT_TOOL($self, TB_45CCW, sub { $_[0]->rotate(45, Z, 'relative') });
  473. # EVT_TOOL($self, TB_SCALE, sub { $self->changescale(undef); });
  474. # EVT_TOOL($self, TB_SPLIT, sub { $self->split_object; });
  475. # EVT_TOOL($self, TB_CUT, sub { $_[0]->object_cut_dialog });
  476. # EVT_TOOL($self, TB_SETTINGS, sub { $_[0]->object_settings_dialog });
  477. # EVT_TOOL($self, TB_LAYER_EDITING, sub {
  478. # my $state = Slic3r::GUI::_3DScene::is_layers_editing_enabled($self->{canvas3D});
  479. # $self->{htoolbar}->ToggleTool(TB_LAYER_EDITING, ! $state);
  480. # $self->on_layer_editing_toggled(! $state);
  481. # });
  482. # } else {
  483. # EVT_BUTTON($self, $self->{btn_add}, sub { $self->add; });
  484. # EVT_BUTTON($self, $self->{btn_remove}, sub { $self->remove() }); # explicitly pass no argument to remove
  485. # EVT_BUTTON($self, $self->{btn_remove}, sub { Slic3r::GUI::remove_obj() }); # explicitly pass no argument to remove
  486. # EVT_BUTTON($self, $self->{btn_reset}, sub { $self->reset; });
  487. # EVT_BUTTON($self, $self->{btn_arrange}, sub { $self->arrange; });
  488. # EVT_BUTTON($self, $self->{btn_increase}, sub { $self->increase; });
  489. # EVT_BUTTON($self, $self->{btn_decrease}, sub { $self->decrease; });
  490. # EVT_BUTTON($self, $self->{btn_rotate45cw}, sub { $_[0]->rotate(-45, Z, 'relative') });
  491. # EVT_BUTTON($self, $self->{btn_rotate45ccw}, sub { $_[0]->rotate(45, Z, 'relative') });
  492. # EVT_BUTTON($self, $self->{btn_changescale}, sub { $self->changescale(undef); });
  493. # EVT_BUTTON($self, $self->{btn_split}, sub { $self->split_object; });
  494. # EVT_BUTTON($self, $self->{btn_cut}, sub { $_[0]->object_cut_dialog });
  495. # EVT_BUTTON($self, $self->{btn_settings}, sub { $_[0]->object_settings_dialog });
  496. # EVT_TOGGLEBUTTON($self, $self->{btn_layer_editing}, sub { $self->on_layer_editing_toggled($self->{btn_layer_editing}->GetValue); });
  497. # }
  498. $_->SetDropTarget(Slic3r::GUI::Plater::DropTarget->new($self))
  499. for grep defined($_),
  500. $self, $self->{canvas3D}, $self->{preview_iface}, $self->{list};
  501. # $self, $self->{canvas3D}, $self->{preview3D}, $self->{list};
  502. # $self, $self->{canvas}, $self->{canvas3D}, $self->{preview3D};
  503. EVT_COMMAND($self, -1, $SLICING_COMPLETED_EVENT, sub {
  504. my ($self, $event) = @_;
  505. $self->on_update_print_preview;
  506. });
  507. EVT_COMMAND($self, -1, $PROCESS_COMPLETED_EVENT, sub {
  508. my ($self, $event) = @_;
  509. $self->on_process_completed($event->GetInt ? undef : $event->GetString);
  510. });
  511. # XXX: not done
  512. {
  513. my $timer_id = Wx::NewId();
  514. $self->{apply_config_timer} = Wx::Timer->new($self, $timer_id);
  515. EVT_TIMER($self, $timer_id, sub {
  516. my ($self, $event) = @_;
  517. $self->async_apply_config;
  518. });
  519. }
  520. # $self->{canvas}->update_bed_size;
  521. if ($self->{canvas3D}) {
  522. Slic3r::GUI::_3DScene::set_bed_shape($self->{canvas3D}, $self->{config}->bed_shape);
  523. Slic3r::GUI::_3DScene::zoom_to_bed($self->{canvas3D});
  524. }
  525. $self->{preview_iface}->set_bed_shape($self->{config}->bed_shape) if ($self->{preview_iface});
  526. # if ($self->{preview3D}) {
  527. # Slic3r::GUI::_3DScene::set_bed_shape($self->{preview3D}->canvas, $self->{config}->bed_shape);
  528. # }
  529. $self->update;
  530. {
  531. my $presets;
  532. {
  533. $presets = $self->{presets_sizer} = Wx::FlexGridSizer->new(4, 2, 1, 2);
  534. $presets->AddGrowableCol(1, 1);
  535. $presets->SetFlexibleDirection(wxHORIZONTAL);
  536. my %group_labels = (
  537. print => L('Print settings'),
  538. filament => L('Filament'),
  539. sla_material=> L('SLA material'),
  540. printer => L('Printer'),
  541. );
  542. # UI Combo boxes for a print, multiple filaments, SLA material and a printer.
  543. # Initially a single filament combo box is created, but the number of combo boxes for the filament selection may increase,
  544. # once a printer preset with multiple extruders is activated.
  545. # $self->{preset_choosers}{$group}[$idx]
  546. $self->{preset_choosers} = {};
  547. for my $group (qw(print filament sla_material printer)) {
  548. # my $text = Wx::StaticText->new($self->{right_panel}, -1, "$group_labels{$group}:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
  549. my $text = Wx::StaticText->new($scrolled_window_panel, -1, "$group_labels{$group}:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
  550. $text->SetFont($Slic3r::GUI::small_font);
  551. # my $choice = Wx::BitmapComboBox->new($self->{right_panel}, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_READONLY);
  552. my $choice = Wx::BitmapComboBox->new($scrolled_window_panel, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_READONLY);
  553. if ($group eq 'filament') {
  554. EVT_LEFT_DOWN($choice, sub { $self->filament_color_box_lmouse_down(0, @_); } );
  555. }
  556. $self->{preset_choosers}{$group} = [$choice];
  557. # setup the listener
  558. EVT_COMBOBOX($choice, $choice, sub {
  559. my ($choice) = @_;
  560. wxTheApp->CallAfter(sub {
  561. $self->_on_select_preset($group, $choice, 0);
  562. });
  563. });
  564. $presets->Add($text, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxRIGHT, 4);
  565. $presets->Add($choice, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxBOTTOM, 1);
  566. }
  567. $presets->Layout;
  568. }
  569. my $frequently_changed_parameters_sizer = $self->{frequently_changed_parameters_sizer} = Wx::BoxSizer->new(wxVERTICAL);
  570. #! Slic3r::GUI::add_frequently_changed_parameters($self->{right_panel}, $frequently_changed_parameters_sizer, $presets);
  571. Slic3r::GUI::add_frequently_changed_parameters($self->{scrolled_window_panel}, $frequently_changed_parameters_sizer, $presets);
  572. my $object_info_sizer;
  573. {
  574. my $box = Wx::StaticBox->new($scrolled_window_panel, -1, L("Info"));
  575. # my $box = Wx::StaticBox->new($self->{right_panel}, -1, L("Info"));
  576. $box->SetFont($Slic3r::GUI::small_bold_font);
  577. $object_info_sizer = Wx::StaticBoxSizer->new($box, wxVERTICAL);
  578. $object_info_sizer->SetMinSize([300,-1]);
  579. #!my $grid_sizer = Wx::FlexGridSizer->new(3, 4, 5, 5);
  580. my $grid_sizer = Wx::FlexGridSizer->new(2, 4, 5, 5);
  581. $grid_sizer->SetFlexibleDirection(wxHORIZONTAL);
  582. $grid_sizer->AddGrowableCol(1, 1);
  583. $grid_sizer->AddGrowableCol(3, 1);
  584. $object_info_sizer->Add($grid_sizer, 0, wxEXPAND);
  585. my @info = (
  586. size => L("Size"),
  587. volume => L("Volume"),
  588. facets => L("Facets"),
  589. materials => L("Materials"),
  590. manifold => L("Manifold"),
  591. );
  592. while (my $field = shift @info) {
  593. my $label = shift @info;
  594. my $text = Wx::StaticText->new($scrolled_window_panel, -1, "$label:", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  595. # my $text = Wx::StaticText->new($self->{right_panel}, -1, "$label:", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  596. $text->SetFont($Slic3r::GUI::small_font);
  597. #!$grid_sizer->Add($text, 0);
  598. $self->{"object_info_$field"} = Wx::StaticText->new($scrolled_window_panel, -1, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  599. # $self->{"object_info_$field"} = Wx::StaticText->new($self->{right_panel}, -1, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  600. $self->{"object_info_$field"}->SetFont($Slic3r::GUI::small_font);
  601. if ($field eq 'manifold') {
  602. $self->{object_info_manifold_warning_icon} = Wx::StaticBitmap->new($scrolled_window_panel, -1, Wx::Bitmap->new(Slic3r::var("error.png"), wxBITMAP_TYPE_PNG));
  603. # $self->{object_info_manifold_warning_icon} = Wx::StaticBitmap->new($self->{right_panel}, -1, Wx::Bitmap->new(Slic3r::var("error.png"), wxBITMAP_TYPE_PNG));
  604. #$self->{object_info_manifold_warning_icon}->Hide;
  605. $self->{"object_info_manifold_warning_icon_show"} = sub {
  606. if ($self->{object_info_manifold_warning_icon}->IsShown() != $_[0]) {
  607. # this fuction show/hide info_manifold_warning_icon on the c++ side now
  608. Slic3r::GUI::set_show_manifold_warning_icon($_[0]);
  609. #my $mode = wxTheApp->{app_config}->get("view_mode");
  610. #return if ($mode eq "" || $mode eq "simple");
  611. #$self->{object_info_manifold_warning_icon}->Show($_[0]);
  612. #$self->Layout
  613. }
  614. };
  615. $self->{"object_info_manifold_warning_icon_show"}->(0);
  616. my $h_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  617. $h_sizer->Add($text, 0);
  618. $h_sizer->Add($self->{object_info_manifold_warning_icon}, 0, wxLEFT, 2);
  619. $h_sizer->Add($self->{"object_info_$field"}, 0, wxLEFT, 2);
  620. #!$grid_sizer->Add($h_sizer, 0, wxEXPAND);
  621. $object_info_sizer->Add($h_sizer, 0, wxEXPAND|wxTOP, 4);
  622. } else {
  623. $grid_sizer->Add($text, 0);
  624. $grid_sizer->Add($self->{"object_info_$field"}, 0);
  625. }
  626. }
  627. }
  628. my $print_info_box = Wx::StaticBox->new($scrolled_window_panel, -1, L("Sliced Info"));
  629. $print_info_box->SetFont($Slic3r::GUI::small_bold_font);
  630. my $print_info_sizer = $self->{print_info_sizer} = Wx::StaticBoxSizer->new($print_info_box, wxVERTICAL);
  631. # Wx::StaticBox->new($self->{right_panel}, -1, L("Sliced Info")), wxVERTICAL);
  632. $print_info_sizer->SetMinSize([300,-1]);
  633. my $buttons_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
  634. $self->{buttons_sizer} = $buttons_sizer;
  635. $buttons_sizer->AddStretchSpacer(1);
  636. # $buttons_sizer->Add($self->{btn_export_stl}, 0, wxALIGN_RIGHT, 0);
  637. #! $buttons_sizer->Add($self->{btn_reslice}, 0, wxALIGN_RIGHT, 0);
  638. $buttons_sizer->Add($self->{btn_print}, 0, wxALIGN_RIGHT | wxBOTTOM | wxTOP, 5);
  639. $buttons_sizer->Add($self->{btn_send_gcode}, 0, wxALIGN_RIGHT | wxBOTTOM | wxTOP, 5);
  640. # $scrolled_window_sizer->Add($self->{list}, 1, wxEXPAND, 5);
  641. # $scrolled_window_sizer->Add($object_info_sizer, 0, wxEXPAND, 0);
  642. # $scrolled_window_sizer->Add($print_info_sizer, 0, wxEXPAND, 0);
  643. #$buttons_sizer->Add($self->{btn_export_gcode}, 0, wxALIGN_RIGHT, 0);
  644. ### Sizer for info boxes
  645. my $info_sizer = $self->{info_sizer} = Wx::BoxSizer->new(wxVERTICAL);
  646. $info_sizer->SetMinSize([318, -1]);
  647. $info_sizer->Add($object_info_sizer, 0, wxEXPAND | wxTOP, 20);
  648. $info_sizer->Add($print_info_sizer, 0, wxEXPAND | wxTOP, 20);
  649. $scrolled_window_sizer->Add($presets, 0, wxEXPAND | wxLEFT, 2) if defined $presets;
  650. $scrolled_window_sizer->Add($frequently_changed_parameters_sizer, 1, wxEXPAND | wxLEFT, 0) if defined $frequently_changed_parameters_sizer;
  651. $scrolled_window_sizer->Add($buttons_sizer, 0, wxEXPAND, 0);
  652. $scrolled_window_sizer->Add($info_sizer, 0, wxEXPAND | wxLEFT, 20);
  653. # Show the box initially, let it be shown after the slicing is finished.
  654. $self->print_info_box_show(0);
  655. ### Sizer for "Export G-code" & "Slice now" buttons
  656. my $btns_sizer = Wx::BoxSizer->new(wxVERTICAL);
  657. $btns_sizer->SetMinSize([318, -1]);
  658. $btns_sizer->Add($self->{btn_reslice}, 0, wxEXPAND, 0);
  659. $btns_sizer->Add($self->{btn_export_gcode}, 0, wxEXPAND | wxTOP, 5);
  660. my $right_sizer = Wx::BoxSizer->new(wxVERTICAL);
  661. $self->{right_panel}->SetSizer($right_sizer);
  662. $right_sizer->SetMinSize([320, -1]);
  663. #! $right_sizer->Add($presets, 0, wxEXPAND | wxTOP, 10) if defined $presets;
  664. #! $right_sizer->Add($frequently_changed_parameters_sizer, 1, wxEXPAND | wxTOP, 0) if defined $frequently_changed_parameters_sizer;
  665. #! $right_sizer->Add($buttons_sizer, 0, wxEXPAND | wxBOTTOM | wxTOP, 10);
  666. #! $right_sizer->Add($info_sizer, 0, wxEXPAND | wxLEFT, 20);
  667. # Show the box initially, let it be shown after the slicing is finished.
  668. #! $self->print_info_box_show(0);
  669. $right_sizer->Add($scrolled_window_panel, 1, wxEXPAND | wxTOP, 5);
  670. # $right_sizer->Add($self->{btn_reslice}, 0, wxEXPAND | wxLEFT | wxTOP, 20);
  671. # $right_sizer->Add($self->{btn_export_gcode}, 0, wxEXPAND | wxLEFT | wxTOP, 20);
  672. $right_sizer->Add($btns_sizer, 0, wxEXPAND | wxLEFT | wxTOP, 20);
  673. my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
  674. $hsizer->Add($self->{preview_notebook}, 1, wxEXPAND | wxTOP, 1);
  675. $hsizer->Add($self->{right_panel}, 0, wxEXPAND | wxLEFT | wxRIGHT, 0);#3);
  676. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  677. # $sizer->Add($self->{htoolbar}, 0, wxEXPAND, 0) if $self->{htoolbar};
  678. # $sizer->Add($self->{btoolbar}, 0, wxEXPAND, 0) if $self->{btoolbar};
  679. $sizer->Add($hsizer, 1, wxEXPAND, 0);
  680. $sizer->SetSizeHints($self);
  681. $self->SetSizer($sizer);
  682. # Send sizers/buttons to C++
  683. Slic3r::GUI::set_objects_from_perl( $self->{scrolled_window_panel},
  684. $frequently_changed_parameters_sizer,
  685. $info_sizer,
  686. $self->{btn_export_gcode},
  687. # $self->{btn_export_stl},
  688. $self->{btn_reslice},
  689. $self->{btn_print},
  690. $self->{btn_send_gcode},
  691. $self->{object_info_manifold_warning_icon} );
  692. Slic3r::GUI::set_model_events_from_perl( $self->{model},
  693. $self->{event_object_selection_changed},
  694. $self->{event_object_settings_changed},
  695. $self->{event_remove_object},
  696. $self->{event_update_scene});
  697. }
  698. # Last correct selected item for each preset
  699. {
  700. $self->{selected_item_print} = 0;
  701. $self->{selected_item_filament} = 0;
  702. $self->{selected_item_printer} = 0;
  703. }
  704. $self->update_ui_from_settings();
  705. $self->Layout;
  706. return $self;
  707. }
  708. # XXX: VK: WIP
  709. # sets the callback
  710. sub on_select_preset {
  711. my ($self, $cb) = @_;
  712. $self->{on_select_preset} = $cb;
  713. }
  714. # XXX: merged with on_select_preset
  715. # Called from the platter combo boxes selecting the active print, filament or printer.
  716. sub _on_select_preset {
  717. my ($self, $group, $choice, $idx) = @_;
  718. # If user changed a filament preset and the selected machine is equipped with multiple extruders,
  719. # there are multiple filament selection combo boxes shown at the platter. In that case
  720. # don't propagate the filament selection changes to the tab.
  721. if ($group eq 'filament') {
  722. wxTheApp->{preset_bundle}->set_filament_preset($idx, $choice->GetStringSelection);
  723. }
  724. if ($group eq 'filament' && @{$self->{preset_choosers}{filament}} > 1) {
  725. # Only update the platter UI for the 2nd and other filaments.
  726. wxTheApp->{preset_bundle}->update_platter_filament_ui($idx, $choice);
  727. } else {
  728. my $selected_item = $choice->GetSelection();
  729. return if ($selected_item == $self->{"selected_item_$group"} &&
  730. !Slic3r::GUI::get_preset_tab($group)->current_preset_is_dirty);
  731. my $selected_string = $choice->GetString($selected_item);
  732. if ($selected_string eq ("------- ".L("System presets")." -------") ||
  733. $selected_string eq ("------- ".L("User presets")." -------") ){
  734. $choice->SetSelection($self->{"selected_item_$group"});
  735. return;
  736. }
  737. # call GetSelection() in scalar context as it's context-aware
  738. # $self->{on_select_preset}->($group, $choice->GetStringSelection)
  739. $self->{on_select_preset}->($group, $selected_string)
  740. if $self->{on_select_preset};
  741. $self->{"selected_item_$group"} = $selected_item;
  742. }
  743. # Synchronize config.ini with the current selections.
  744. wxTheApp->{preset_bundle}->export_selections(wxTheApp->{app_config});
  745. # get new config and generate on_config_change() event for updating plater and other things
  746. $self->on_config_change(wxTheApp->{preset_bundle}->full_config);
  747. }
  748. # XXX: VK: done
  749. sub on_layer_editing_toggled {
  750. my ($self, $new_state) = @_;
  751. Slic3r::GUI::_3DScene::enable_layers_editing($self->{canvas3D}, $new_state);
  752. if ($new_state && ! Slic3r::GUI::_3DScene::is_layers_editing_enabled($self->{canvas3D})) {
  753. # Initialization of the OpenGL shaders failed. Disable the tool.
  754. # if ($self->{htoolbar}) {
  755. # $self->{htoolbar}->EnableTool(TB_LAYER_EDITING, 0);
  756. # $self->{htoolbar}->ToggleTool(TB_LAYER_EDITING, 0);
  757. # } else {
  758. # $self->{"btn_layer_editing"}->Disable;
  759. # $self->{"btn_layer_editing"}->SetValue(0);
  760. # }
  761. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "layersediting", 0);
  762. }
  763. $self->{canvas3D}->Refresh;
  764. $self->{canvas3D}->Update;
  765. }
  766. # XXX: VK: done (Plater::priv::main_frame)
  767. sub GetFrame {
  768. my ($self) = @_;
  769. return &Wx::GetTopLevelParent($self);
  770. }
  771. # XXX: not done
  772. # Called after the Preferences dialog is closed and the program settings are saved.
  773. # Update the UI based on the current preferences.
  774. sub update_ui_from_settings
  775. {
  776. my ($self) = @_;
  777. if (defined($self->{btn_reslice}) && $self->{buttons_sizer}->IsShown($self->{btn_reslice}) != (! wxTheApp->{app_config}->get("background_processing"))) {
  778. $self->{buttons_sizer}->Show($self->{btn_reslice}, ! wxTheApp->{app_config}->get("background_processing"));
  779. $self->{buttons_sizer}->Layout;
  780. }
  781. }
  782. # XXX: VK: done
  783. # Update preset combo boxes (Print settings, Filament, Material, Printer) from their respective tabs.
  784. # Called by
  785. # Slic3r::GUI::Tab::Print::_on_presets_changed
  786. # Slic3r::GUI::Tab::Filament::_on_presets_changed
  787. # Slic3r::GUI::Tab::Material::_on_presets_changed
  788. # Slic3r::GUI::Tab::Printer::_on_presets_changed
  789. # when the presets are loaded or the user selects another preset.
  790. # For Print settings and Printer, synchronize the selection index with their tabs.
  791. # For Filament, synchronize the selection index for a single extruder printer only, otherwise keep the selection.
  792. sub update_presets {
  793. # $group: one of qw(print filament sla_material printer)
  794. # $presets: PresetCollection
  795. my ($self, $group, $presets) = @_;
  796. my @choosers = @{$self->{preset_choosers}{$group}};
  797. if ($group eq 'filament') {
  798. my $choice_idx = 0;
  799. if (int(@choosers) == 1) {
  800. # Single filament printer, synchronize the filament presets.
  801. wxTheApp->{preset_bundle}->set_filament_preset(0, wxTheApp->{preset_bundle}->filament->get_selected_preset->name);
  802. }
  803. foreach my $choice (@choosers) {
  804. wxTheApp->{preset_bundle}->update_platter_filament_ui($choice_idx, $choice);
  805. $choice_idx += 1;
  806. }
  807. } elsif ($group eq 'print') {
  808. wxTheApp->{preset_bundle}->print->update_platter_ui($choosers[0]);
  809. } elsif ($group eq 'sla_material') {
  810. wxTheApp->{preset_bundle}->sla_material->update_platter_ui($choosers[0]);
  811. } elsif ($group eq 'printer') {
  812. # Update the print choosers to only contain the compatible presets, update the dirty flags.
  813. wxTheApp->{preset_bundle}->print->update_platter_ui($self->{preset_choosers}{print}->[0]);
  814. # Update the printer choosers, update the dirty flags.
  815. wxTheApp->{preset_bundle}->printer->update_platter_ui($choosers[0]);
  816. # Update the filament choosers to only contain the compatible presets, update the color preview,
  817. # update the dirty flags.
  818. my $choice_idx = 0;
  819. foreach my $choice (@{$self->{preset_choosers}{filament}}) {
  820. wxTheApp->{preset_bundle}->update_platter_filament_ui($choice_idx, $choice);
  821. $choice_idx += 1;
  822. }
  823. }
  824. # Synchronize config.ini with the current selections.
  825. wxTheApp->{preset_bundle}->export_selections(wxTheApp->{app_config});
  826. }
  827. # XXX: VK: done, in on_action_add()
  828. sub add {
  829. my ($self) = @_;
  830. my @input_files = wxTheApp->open_model($self);
  831. $self->load_files(\@input_files);
  832. }
  833. # XXX: VK: done
  834. sub load_files {
  835. my ($self, $input_files) = @_;
  836. return if ! defined($input_files) || ! scalar(@$input_files);
  837. my $nozzle_dmrs = $self->{config}->get('nozzle_diameter');
  838. # One of the files is potentionally a bundle of files. Don't bundle them, but load them one by one.
  839. # Only bundle .stls or .objs if the printer has multiple extruders.
  840. my $one_by_one = (@$nozzle_dmrs <= 1) || (@$input_files == 1) ||
  841. defined(first { $_ =~ /.[aA][mM][fF]$/ || $_ =~ /.[aA][mM][fF].[xX][mM][lL]$/ || $_ =~ /.[zZ][iI][pP].[aA][mM][fF]$/ || $_ =~ /.3[mM][fF]$/ || $_ =~ /.[pP][rR][uI][sS][aA]$/ } @$input_files);
  842. my $process_dialog = Wx::ProgressDialog->new(L('Loading…'), L("Processing input file\n") . basename($input_files->[0]), 100, $self, 0);
  843. $process_dialog->Pulse;
  844. local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
  845. # new_model to collect volumes, if all of them come from .stl or .obj and there is a chance, that they will be
  846. # possibly merged into a single multi-part object.
  847. my $new_model = $one_by_one ? undef : Slic3r::Model->new;
  848. # Object indices for the UI.
  849. my @obj_idx = ();
  850. # Collected file names to display the final message on the status bar.
  851. my @loaded_files = (); # XXX: used???
  852. # For all input files.
  853. for (my $i = 0; $i < @$input_files; $i += 1) {
  854. my $input_file = $input_files->[$i];
  855. $process_dialog->Update(100. * $i / @$input_files, L("Processing input file\n") . basename($input_file));
  856. my $model;
  857. if (($input_file =~ /.3[mM][fF]$/) || ($input_file =~ /.[zZ][iI][pP].[aA][mM][fF]$/))
  858. {
  859. $model = eval { Slic3r::Model->read_from_archive($input_file, wxTheApp->{preset_bundle}, 0) };
  860. Slic3r::GUI::show_error($self, $@) if $@;
  861. $_->load_current_preset for (values %{$self->GetFrame->{options_tabs}});
  862. wxTheApp->{app_config}->update_config_dir(dirname($input_file));
  863. # forces the update of the config here, or it will invalidate the imported layer heights profile if done using the timer
  864. # and if the config contains a "layer_height" different from the current defined one
  865. $self->async_apply_config;
  866. }
  867. else
  868. {
  869. $model = eval { Slic3r::Model->read_from_file($input_file, 0) };
  870. Slic3r::GUI::show_error($self, $@) if $@;
  871. }
  872. next if ! defined $model;
  873. if ($model->looks_like_multipart_object) {
  874. my $dialog = Wx::MessageDialog->new($self,
  875. L("This file contains several objects positioned at multiple heights. "
  876. . "Instead of considering them as multiple objects, should I consider\n"
  877. . "this file as a single object having multiple parts?\n"),
  878. L('Multi-part object detected'), wxICON_WARNING | wxYES | wxNO);
  879. $model->convert_multipart_object(scalar(@$nozzle_dmrs)) if $dialog->ShowModal() == wxID_YES;
  880. }
  881. # objects imported from 3mf require a call to center_around_origin to have gizmos working properly and this call
  882. # need to be done after looks_like_multipart_object detection
  883. if ($input_file =~ /[.]3[mM][fF]$/)
  884. {
  885. foreach my $model_object (@{$model->objects}) {
  886. $model_object->center_around_origin; # also aligns object to Z = 0
  887. }
  888. }
  889. if ($one_by_one) {
  890. push @obj_idx, $self->load_model_objects(@{$model->objects});
  891. } else {
  892. # This must be an .stl or .obj file, which may contain a maximum of one volume.
  893. $new_model->add_object($_) for (@{$model->objects});
  894. }
  895. }
  896. if ($new_model) {
  897. my $dialog = Wx::MessageDialog->new($self,
  898. L("Multiple objects were loaded for a multi-material printer.\n"
  899. . "Instead of considering them as multiple objects, should I consider\n"
  900. . "these files to represent a single object having multiple parts?\n"),
  901. L('Multi-part object detected'), wxICON_WARNING | wxYES | wxNO);
  902. $new_model->convert_multipart_object(scalar(@$nozzle_dmrs)) if $dialog->ShowModal() == wxID_YES;
  903. push @obj_idx, $self->load_model_objects(@{$new_model->objects});
  904. }
  905. # Note the current directory for the file open dialog.
  906. wxTheApp->{app_config}->update_skein_dir(dirname($input_files->[-1]));
  907. $process_dialog->Destroy;
  908. $self->statusbar->SetStatusText(L("Loaded ") . join(',', @loaded_files));
  909. return @obj_idx;
  910. }
  911. # XXX: VK: done, except a few todos
  912. sub load_model_objects {
  913. my ($self, @model_objects) = @_;
  914. my $bed_centerf = $self->bed_centerf;
  915. my $bed_shape = Slic3r::Polygon->new_scale(@{$self->{config}->bed_shape});
  916. my $bed_size = $bed_shape->bounding_box->size;
  917. my $need_arrange = 0;
  918. my $scaled_down = 0;
  919. my @obj_idx = ();
  920. foreach my $model_object (@model_objects) {
  921. my $o = $self->{model}->add_object($model_object);
  922. my $object_name = $model_object->name;
  923. $object_name = basename($model_object->input_file) if ($object_name eq '');
  924. push @{ $self->{objects} }, Slic3r::GUI::Plater::Object->new(name => $object_name);
  925. push @obj_idx, $#{ $self->{objects} };
  926. if ($model_object->instances_count == 0) {
  927. # if object has no defined position(s) we need to rearrange everything after loading
  928. $need_arrange = 1;
  929. # add a default instance and center object around origin
  930. $o->center_around_origin; # also aligns object to Z = 0
  931. $o->add_instance(offset => $bed_centerf);
  932. }
  933. {
  934. # if the object is too large (more than 5 times the bed), scale it down
  935. my $size = $o->bounding_box->size;
  936. my $ratio = max($size->x / unscale($bed_size->x), $size->y / unscale($bed_size->y));
  937. if ($ratio > 10000) {
  938. # the size of the object is too big -> this could lead to overflow when moving to clipper coordinates,
  939. # so scale down the mesh
  940. $o->scale_xyz(Slic3r::Pointf3->new(1/$ratio, 1/$ratio, 1/$ratio));
  941. $scaled_down = 1;
  942. }
  943. elsif ($ratio > 5) {
  944. $_->set_scaling_factor(1/$ratio) for @{$o->instances};
  945. $scaled_down = 1;
  946. }
  947. }
  948. $self->{print}->auto_assign_extruders($o);
  949. $self->{print}->add_model_object($o);
  950. }
  951. # if user turned autocentering off, automatic arranging would disappoint them
  952. if (! wxTheApp->{app_config}->get("autocenter")) {
  953. $need_arrange = 0;
  954. }
  955. if ($scaled_down) {
  956. Slic3r::GUI::show_info(
  957. $self,
  958. L('Your object appears to be too large, so it was automatically scaled down to fit your print bed.'),
  959. L('Object too large?'),
  960. );
  961. }
  962. foreach my $obj_idx (@obj_idx) {
  963. my $object = $self->{objects}[$obj_idx];
  964. my $model_object = $self->{model}->objects->[$obj_idx];
  965. # Add object to list on c++ side
  966. Slic3r::GUI::add_object_to_list($object->name, $model_object);
  967. # $self->reset_thumbnail($obj_idx);
  968. }
  969. $self->arrange if $need_arrange;
  970. $self->update;
  971. # zoom to objects
  972. Slic3r::GUI::_3DScene::zoom_to_volumes($self->{canvas3D}) if $self->{canvas3D};
  973. $self->object_list_changed;
  974. $self->schedule_background_process;
  975. return @obj_idx;
  976. }
  977. # XXX: Removed, replaced with bed_shape_bb()
  978. sub bed_centerf {
  979. my ($self) = @_;
  980. my $bed_shape = Slic3r::Polygon->new_scale(@{$self->{config}->bed_shape});
  981. my $bed_center = $bed_shape->bounding_box->center;
  982. return Slic3r::Pointf->new(unscale($bed_center->x), unscale($bed_center->y)); #)
  983. }
  984. # XXX: VK: done
  985. sub remove {
  986. my ($self, $obj_idx) = @_;
  987. $self->stop_background_process;
  988. # Prevent toolpaths preview from rendering while we modify the Print object
  989. $self->{preview_iface}->set_enabled(0) if $self->{preview_iface};
  990. # $self->{preview3D}->enabled(0) if $self->{preview3D};
  991. # If no object index is supplied, remove the selected one.
  992. if (! defined $obj_idx) {
  993. ($obj_idx, undef) = $self->selected_object;
  994. return if ! defined $obj_idx;
  995. }
  996. splice @{$self->{objects}}, $obj_idx, 1;
  997. $self->{model}->delete_object($obj_idx);
  998. $self->{print}->delete_object($obj_idx);
  999. # Delete object from list on c++ side
  1000. Slic3r::GUI::delete_object_from_list();
  1001. $self->object_list_changed;
  1002. $self->select_object(undef);
  1003. $self->update;
  1004. }
  1005. # XXX: VK: done
  1006. sub reset {
  1007. my ($self) = @_;
  1008. $self->stop_background_process;
  1009. # Prevent toolpaths preview from rendering while we modify the Print object
  1010. $self->{preview_iface}->set_enabled(0) if $self->{preview_iface};
  1011. # $self->{preview3D}->enabled(0) if $self->{preview3D};
  1012. @{$self->{objects}} = ();
  1013. $self->{model}->clear_objects;
  1014. $self->{print}->clear_objects;
  1015. # Delete all objects from list on c++ side
  1016. Slic3r::GUI::delete_all_objects_from_list();
  1017. $self->object_list_changed;
  1018. $self->select_object(undef);
  1019. $self->update;
  1020. }
  1021. # XXX: VK: done
  1022. sub increase {
  1023. my ($self, $copies) = @_;
  1024. $copies //= 1;
  1025. my ($obj_idx, $object) = $self->selected_object;
  1026. return if ! defined $obj_idx;
  1027. my $model_object = $self->{model}->objects->[$obj_idx];
  1028. my $instance = $model_object->instances->[-1];
  1029. $self->stop_background_process;
  1030. for my $i (1..$copies) {
  1031. $instance = $model_object->add_instance(
  1032. offset => Slic3r::Pointf->new(map 10+$_, @{$instance->offset}),
  1033. scaling_factor => $instance->scaling_factor,
  1034. rotation => $instance->rotation,
  1035. );
  1036. $self->{print}->objects->[$obj_idx]->add_copy($instance->offset);
  1037. }
  1038. # Set count of object on c++ side
  1039. Slic3r::GUI::set_object_count($obj_idx, $model_object->instances_count);
  1040. # only autoarrange if user has autocentering enabled
  1041. $self->stop_background_process;
  1042. if (wxTheApp->{app_config}->get("autocenter")) {
  1043. $self->arrange;
  1044. } else {
  1045. $self->update;
  1046. }
  1047. $self->selection_changed; # refresh info (size, volume etc.)
  1048. $self->schedule_background_process;
  1049. }
  1050. # XXX: VK: done
  1051. sub decrease {
  1052. my ($self, $copies_asked) = @_;
  1053. my $copies = $copies_asked // 1;
  1054. my ($obj_idx, $object) = $self->selected_object;
  1055. return if ! defined $obj_idx;
  1056. my $model_object = $self->{model}->objects->[$obj_idx];
  1057. if ($model_object->instances_count > $copies) {
  1058. $self->stop_background_process;
  1059. for my $i (1..$copies) {
  1060. $model_object->delete_last_instance;
  1061. $self->{print}->objects->[$obj_idx]->delete_last_copy;
  1062. }
  1063. # Set conut of object on c++ side
  1064. Slic3r::GUI::set_object_count($obj_idx, $model_object->instances_count);
  1065. } elsif (defined $copies_asked) {
  1066. # The "decrease" came from the "set number of copies" dialog.
  1067. $self->stop_background_process;
  1068. $self->remove;
  1069. } else {
  1070. # The "decrease" came from the "-" button. Don't allow the object to disappear.
  1071. return;
  1072. }
  1073. $self->update;
  1074. }
  1075. # XXX: VK: done
  1076. sub set_number_of_copies {
  1077. my ($self) = @_;
  1078. # get current number of copies
  1079. my ($obj_idx, $object) = $self->selected_object;
  1080. my $model_object = $self->{model}->objects->[$obj_idx];
  1081. # prompt user
  1082. my $copies = -1;
  1083. $copies = Wx::GetNumberFromUser("", L("Enter the number of copies of the selected object:"), L("Copies"), $model_object->instances_count, 0, 1000, $self);
  1084. my $diff = $copies - $model_object->instances_count;
  1085. if ($diff == 0 || $copies == -1) {
  1086. # no variation
  1087. } elsif ($diff > 0) {
  1088. $self->increase($diff);
  1089. } elsif ($diff < 0) {
  1090. $self->decrease(-$diff);
  1091. }
  1092. }
  1093. # XXX: VK: removed
  1094. sub _get_number_from_user {
  1095. my ($self, $title, $prompt_message, $error_message, $default, $only_positive) = @_;
  1096. for (;;) {
  1097. my $value = Wx::GetTextFromUser($prompt_message, $title, $default, $self);
  1098. # Accept both dashes and dots as a decimal separator.
  1099. $value =~ s/,/./;
  1100. # If scaling value is being entered, remove the trailing percent sign.
  1101. $value =~ s/%$// if $only_positive;
  1102. # User canceled the selection, return undef.
  1103. return if $value eq '';
  1104. # Validate a numeric value.
  1105. return $value if ($value =~ /^-?\d*(?:\.\d*)?$/) && (! $only_positive || $value > 0);
  1106. Wx::MessageBox(
  1107. $error_message .
  1108. (($only_positive && $value <= 0) ?
  1109. ": ".$value.L("\nNon-positive value.") :
  1110. ": ".$value.L("\nNot a numeric value.")),
  1111. L("Slic3r Error"), wxOK | wxICON_EXCLAMATION, $self);
  1112. $default = $value;
  1113. }
  1114. }
  1115. # XXX: not done
  1116. sub rotate {
  1117. my ($self, $angle, $axis, $relative_key, $axis_x, $axis_y, $axis_z) = @_;
  1118. $relative_key //= 'absolute'; # relative or absolute coordinates
  1119. $axis_x //= 0;
  1120. $axis_y //= 0;
  1121. $axis_z //= 0;
  1122. my $relative = $relative_key eq 'relative';
  1123. my ($obj_idx, $object) = $self->selected_object;
  1124. return if !defined $obj_idx;
  1125. my $model_object = $self->{model}->objects->[$obj_idx];
  1126. my $model_instance = $model_object->instances->[0];
  1127. if (!defined $angle) {
  1128. my $axis_name = $axis == X ? 'X' : $axis == Y ? 'Y' : 'Z';
  1129. my $default = $axis == Z ? rad2deg($model_instance->rotation) : 0;
  1130. $angle = $self->_get_number_from_user(L("Enter the rotation angle:"), L("Rotate around ").$axis_name.(" axis"), L("Invalid rotation angle entered"), $default);
  1131. return if $angle eq '';
  1132. }
  1133. # Let's calculate vector of rotation axis (if we don't have it already)
  1134. if (defined $axis) {
  1135. if ($axis == X) {
  1136. $axis_x = 1;
  1137. }
  1138. if ($axis == Y) {
  1139. $axis_y = 1;
  1140. }
  1141. }
  1142. $self->stop_background_process;
  1143. if (defined $axis && $axis == Z) {
  1144. my $new_angle = deg2rad($angle);
  1145. foreach my $inst (@{ $model_object->instances }) {
  1146. my $rotation = ($relative ? $inst->rotation : 0.) + $new_angle;
  1147. while ($rotation > 2.0 * PI) {
  1148. $rotation -= 2.0 * PI;
  1149. }
  1150. while ($rotation < 0.0) {
  1151. $rotation += 2.0 * PI;
  1152. }
  1153. $inst->set_rotation($rotation);
  1154. Slic3r::GUI::_3DScene::update_gizmos_data($self->{canvas3D}) if ($self->{canvas3D});
  1155. }
  1156. # $object->transform_thumbnail($self->{model}, $obj_idx);
  1157. } else {
  1158. if (defined $axis) {
  1159. # rotation around X and Y needs to be performed on mesh
  1160. # so we first apply any Z rotation
  1161. if ($model_instance->rotation != 0) {
  1162. $model_object->rotate($model_instance->rotation, Slic3r::Pointf3->new(0, 0, -1));
  1163. $_->set_rotation(0) for @{ $model_object->instances };
  1164. }
  1165. }
  1166. $model_object->rotate(deg2rad($angle), Slic3r::Pointf3->new($axis_x, $axis_y, $axis_z));
  1167. # # realign object to Z = 0
  1168. # $model_object->center_around_origin;
  1169. # $self->reset_thumbnail($obj_idx);
  1170. }
  1171. # update print and start background processing
  1172. $self->{print}->add_model_object($model_object, $obj_idx);
  1173. $self->selection_changed; # refresh info (size etc.)
  1174. $self->update;
  1175. }
  1176. # XXX: not done
  1177. sub mirror {
  1178. my ($self, $axis) = @_;
  1179. my ($obj_idx, $object) = $self->selected_object;
  1180. return if !defined $obj_idx;
  1181. my $model_object = $self->{model}->objects->[$obj_idx];
  1182. my $model_instance = $model_object->instances->[0];
  1183. # apply Z rotation before mirroring
  1184. if ($model_instance->rotation != 0) {
  1185. $model_object->rotate($model_instance->rotation, Slic3r::Pointf3->new(0, 0, 1));
  1186. $_->set_rotation(0) for @{ $model_object->instances };
  1187. }
  1188. $model_object->mirror($axis);
  1189. # # realign object to Z = 0
  1190. # $model_object->center_around_origin;
  1191. # $self->reset_thumbnail($obj_idx);
  1192. # update print and start background processing
  1193. $self->stop_background_process;
  1194. $self->{print}->add_model_object($model_object, $obj_idx);
  1195. $self->selection_changed; # refresh info (size etc.)
  1196. $self->update;
  1197. }
  1198. # XXX: not done, renamed as Plater::priv::scale()
  1199. sub changescale {
  1200. my ($self, $axis, $tosize) = @_;
  1201. my ($obj_idx, $object) = $self->selected_object;
  1202. return if !defined $obj_idx;
  1203. my $model_object = $self->{model}->objects->[$obj_idx];
  1204. my $model_instance = $model_object->instances->[0];
  1205. my $object_size = $model_object->instance_bounding_box(0)->size;
  1206. if (defined $axis) {
  1207. my $axis_name = $axis == X ? 'X' : $axis == Y ? 'Y' : 'Z';
  1208. my $scale;
  1209. if ($tosize) {
  1210. my $cursize = $object_size->[$axis];
  1211. my $newsize = $self->_get_number_from_user(
  1212. L('Enter the new size for the selected object:'),
  1213. L("Scale along ").$axis_name, L('Invalid scaling value entered'), $cursize, 1);
  1214. return if $newsize eq '';
  1215. $scale = $newsize / $cursize * 100;
  1216. } else {
  1217. $scale = $self->_get_number_from_user(L('Enter the scale % for the selected object:'), L("Scale along ").$axis_name, L('Invalid scaling value entered'), 100, 1);
  1218. return if $scale eq '';
  1219. }
  1220. # apply Z rotation before scaling
  1221. if ($model_instance->rotation != 0) {
  1222. $model_object->rotate($model_instance->rotation, Slic3r::Pointf3->new(0, 0, 1));
  1223. $_->set_rotation(0) for @{ $model_object->instances };
  1224. }
  1225. my $versor = [1,1,1];
  1226. $versor->[$axis] = $scale/100;
  1227. $model_object->scale_xyz(Slic3r::Pointf3->new(@$versor));
  1228. #FIXME Scale the layer height profile when $axis == Z?
  1229. #FIXME Scale the layer height ranges $axis == Z?
  1230. # object was already aligned to Z = 0, so no need to realign it
  1231. # $self->reset_thumbnail($obj_idx);
  1232. } else {
  1233. my $scale;
  1234. if ($tosize) {
  1235. my $cursize = max(@$object_size);
  1236. my $newsize = $self->_get_number_from_user(L('Enter the new max size for the selected object:'), L('Scale'), L('Invalid scaling value entered'), $cursize, 1);
  1237. return if ! defined($newsize) || $newsize eq '';
  1238. $scale = $model_instance->scaling_factor * $newsize / $cursize * 100;
  1239. } else {
  1240. # max scale factor should be above 2540 to allow importing files exported in inches
  1241. $scale = $self->_get_number_from_user(L('Enter the scale % for the selected object:'), L('Scale'), L('Invalid scaling value entered'), $model_instance->scaling_factor*100, 1);
  1242. return if ! defined($scale) || $scale eq '';
  1243. }
  1244. # Set object scale on c++ side
  1245. # Slic3r::GUI::set_object_scale($obj_idx, $scale);
  1246. $scale /= 100; # turn percent into factor
  1247. my $variation = $scale / $model_instance->scaling_factor;
  1248. #FIXME Scale the layer height profile?
  1249. foreach my $range (@{ $model_object->layer_height_ranges }) {
  1250. $range->[0] *= $variation;
  1251. $range->[1] *= $variation;
  1252. }
  1253. $_->set_scaling_factor($scale) for @{ $model_object->instances };
  1254. # $object->transform_thumbnail($self->{model}, $obj_idx);
  1255. }
  1256. # update print and start background processing
  1257. $self->stop_background_process;
  1258. $self->{print}->add_model_object($model_object, $obj_idx);
  1259. $self->selection_changed(1); # refresh info (size, volume etc.)
  1260. $self->update;
  1261. }
  1262. # XXX: VK: WIP
  1263. sub arrange {
  1264. my ($self) = @_;
  1265. $self->stop_background_process;
  1266. # my $bb = Slic3r::Geometry::BoundingBoxf->new_from_points($self->{config}->bed_shape);
  1267. # my $success = $self->{model}->arrange_objects(wxTheApp->{preset_bundle}->full_config->min_object_distance, $bb);
  1268. # Update is not implemented in C++ so we cannot call this for now
  1269. $self->{appController}->arrange_model;
  1270. # ignore arrange failures on purpose: user has visual feedback and we don't need to warn him
  1271. # when parts don't fit in print bed
  1272. # Force auto center of the aligned grid of of objects on the print bed.
  1273. $self->update(0);
  1274. }
  1275. # XXX: not done
  1276. sub split_object {
  1277. my $self = shift;
  1278. my ($obj_idx, $current_object) = $self->selected_object;
  1279. # we clone model object because split_object() adds the split volumes
  1280. # into the same model object, thus causing duplicates when we call load_model_objects()
  1281. my $new_model = $self->{model}->clone; # store this before calling get_object()
  1282. my $current_model_object = $new_model->get_object($obj_idx);
  1283. if ($current_model_object->volumes_count > 1) {
  1284. Slic3r::GUI::warning_catcher($self)->(L("The selected object can't be split because it contains more than one volume/material."));
  1285. return;
  1286. }
  1287. $self->stop_background_process;
  1288. my @model_objects = @{$current_model_object->split_object};
  1289. if (@model_objects == 1) {
  1290. Slic3r::GUI::warning_catcher($self)->(L("The selected object couldn't be split because it contains only one part."));
  1291. $self->schedule_background_process;
  1292. } else {
  1293. $_->center_around_origin for (@model_objects);
  1294. $self->remove($obj_idx);
  1295. $current_object = $obj_idx = undef;
  1296. # load all model objects at once, otherwise the plate would be rearranged after each one
  1297. # causing original positions not to be kept
  1298. $self->load_model_objects(@model_objects);
  1299. }
  1300. }
  1301. # XXX: not done
  1302. # Trigger $self->async_apply_config() after 500ms.
  1303. # The call is delayed to avoid restarting the background processing during typing into an edit field.
  1304. sub schedule_background_process {
  1305. my ($self) = @_;
  1306. $self->{apply_config_timer}->Start(0.5 * 1000, 1); # 1 = one shot, every half a second.
  1307. }
  1308. # XXX: not done
  1309. # Executed asynchronously by a timer every PROCESS_DELAY (0.5 second).
  1310. # The timer is started by schedule_background_process(),
  1311. sub async_apply_config {
  1312. my ($self) = @_;
  1313. # Apply new config to the possibly running background task.
  1314. my $was_running = $self->{background_slicing_process}->running;
  1315. my $invalidated = $self->{background_slicing_process}->apply_config(wxTheApp->{preset_bundle}->full_config);
  1316. # Just redraw the 3D canvas without reloading the scene to consume the update of the layer height profile.
  1317. $self->{canvas3D}->Refresh if Slic3r::GUI::_3DScene::is_layers_editing_enabled($self->{canvas3D});
  1318. # If the apply_config caused the calculation to stop, or it was not running yet:
  1319. if ($invalidated) {
  1320. if ($was_running) {
  1321. # Hide the slicing results if the current slicing status is no more valid.
  1322. $self->print_info_box_show(0)
  1323. }
  1324. if (wxTheApp->{app_config}->get("background_processing")) {
  1325. $self->{background_slicing_process}->start;
  1326. }
  1327. if ($was_running) {
  1328. # Reset preview canvases. If the print has been invalidated, the preview canvases will be cleared.
  1329. # Otherwise they will be just refreshed.
  1330. $self->{gcode_preview_data}->reset;
  1331. $self->{preview_iface}->reload_print if $self->{preview_iface};
  1332. # $self->{preview3D}->reload_print if $self->{preview3D};
  1333. # We also need to reload 3D scene because of the wipe tower preview box
  1334. if ($self->{config}->wipe_tower) {
  1335. my $selections = $self->collect_selections;
  1336. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  1337. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1) if $self->{canvas3D}
  1338. }
  1339. }
  1340. }
  1341. }
  1342. # XXX: not done
  1343. # Background processing is started either by the "Slice now" button, by the "Export G-code button" or by async_apply_config().
  1344. sub start_background_process {
  1345. my ($self) = @_;
  1346. return if ! @{$self->{objects}} || $self->{background_slicing_process}->running;
  1347. # Don't start process thread if config is not valid.
  1348. eval {
  1349. # this will throw errors if config is not valid
  1350. wxTheApp->{preset_bundle}->full_config->validate;
  1351. $self->{print}->validate;
  1352. };
  1353. if ($@) {
  1354. $self->statusbar->SetStatusText($@);
  1355. return;
  1356. }
  1357. # Copy the names of active presets into the placeholder parser.
  1358. wxTheApp->{preset_bundle}->export_selections_pp($self->{print}->placeholder_parser);
  1359. # Start the background process.
  1360. $self->{background_slicing_process}->start;
  1361. }
  1362. # XXX: not done
  1363. # Stop the background processing
  1364. sub stop_background_process {
  1365. my ($self) = @_;
  1366. $self->{background_slicing_process}->stop();
  1367. $self->{preview_iface}->reload_print if $self->{preview_iface};
  1368. # $self->{preview3D}->reload_print if $self->{preview3D};
  1369. }
  1370. # XXX: not done
  1371. # Called by the "Slice now" button, which is visible only if the background processing is disabled.
  1372. sub reslice {
  1373. # explicitly cancel a previous thread and start a new one.
  1374. my ($self) = @_;
  1375. # Don't reslice if export of G-code or sending to OctoPrint is running.
  1376. if (! defined($self->{export_gcode_output_file}) && ! defined($self->{send_gcode_file})) {
  1377. # Stop the background processing threads, stop the async update timer.
  1378. $self->stop_background_process;
  1379. # Rather perform one additional unnecessary update of the print object instead of skipping a pending async update.
  1380. $self->async_apply_config;
  1381. $self->statusbar->SetCancelCallback(sub {
  1382. $self->stop_background_process;
  1383. $self->statusbar->SetStatusText(L("Slicing cancelled"));
  1384. # this updates buttons status
  1385. $self->object_list_changed;
  1386. });
  1387. $self->start_background_process;
  1388. }
  1389. }
  1390. # XXX: VK: done
  1391. sub export_gcode {
  1392. my ($self, $output_file) = @_;
  1393. return if !@{$self->{objects}};
  1394. if ($self->{export_gcode_output_file}) {
  1395. Wx::MessageDialog->new($self, L("Another export job is currently running."), L('Error'), wxOK | wxICON_ERROR)->ShowModal;
  1396. return;
  1397. }
  1398. # if process is not running, validate config
  1399. # (we assume that if it is running, config is valid)
  1400. eval {
  1401. # this will throw errors if config is not valid
  1402. wxTheApp->{preset_bundle}->full_config->validate;
  1403. $self->{print}->validate;
  1404. };
  1405. Slic3r::GUI::catch_error($self) and return;
  1406. # apply config and validate print
  1407. my $config = wxTheApp->{preset_bundle}->full_config;
  1408. eval {
  1409. # this will throw errors if config is not valid
  1410. $config->validate;
  1411. #FIXME it shall use the background processing!
  1412. $self->{print}->apply_config($config);
  1413. $self->{print}->validate;
  1414. };
  1415. Slic3r::GUI::catch_error($self) and return;
  1416. # Copy the names of active presets into the placeholder parser.
  1417. wxTheApp->{preset_bundle}->export_selections_pp($self->{print}->placeholder_parser);
  1418. # select output file
  1419. if ($output_file) {
  1420. $self->{export_gcode_output_file} = eval { $self->{print}->output_filepath($output_file) };
  1421. Slic3r::GUI::catch_error($self) and return;
  1422. } else {
  1423. my $default_output_file = eval { $self->{print}->output_filepath($main::opt{output} // '') };
  1424. Slic3r::GUI::catch_error($self) and return;
  1425. # If possible, remove accents from accented latin characters.
  1426. # This function is useful for generating file names to be processed by legacy firmwares.
  1427. $default_output_file = Slic3r::GUI::fold_utf8_to_ascii($default_output_file);
  1428. my $dlg = Wx::FileDialog->new($self, L('Save G-code file as:'),
  1429. wxTheApp->{app_config}->get_last_output_dir(dirname($default_output_file)),
  1430. basename($default_output_file), &Slic3r::GUI::FILE_WILDCARDS->{gcode}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
  1431. if ($dlg->ShowModal != wxID_OK) {
  1432. $dlg->Destroy;
  1433. return;
  1434. }
  1435. my $path = $dlg->GetPath;
  1436. wxTheApp->{app_config}->update_last_output_dir(dirname($path));
  1437. $self->{export_gcode_output_file} = $path;
  1438. $dlg->Destroy;
  1439. }
  1440. $self->statusbar->StartBusy;
  1441. $self->statusbar->SetCancelCallback(sub {
  1442. $self->stop_background_process;
  1443. $self->statusbar->SetStatusText(L("Export cancelled"));
  1444. $self->{export_gcode_output_file} = undef;
  1445. $self->{send_gcode_file} = undef;
  1446. # this updates buttons status
  1447. $self->object_list_changed;
  1448. });
  1449. $self->{background_slicing_process}->set_output_path($self->{export_gcode_output_file});
  1450. # start background process, whose completion event handler
  1451. # will detect $self->{export_gcode_output_file} and proceed with export
  1452. $self->start_background_process;
  1453. # this updates buttons status
  1454. $self->object_list_changed;
  1455. return $self->{export_gcode_output_file};
  1456. }
  1457. # XXX: not done
  1458. # This message should be called by the background process synchronously.
  1459. sub on_update_print_preview {
  1460. my ($self) = @_;
  1461. $self->{preview_iface}->reload_print if $self->{preview_iface};
  1462. # $self->{preview3D}->reload_print if $self->{preview3D};
  1463. # in case this was MM print, wipe tower bounding box on 3D tab might need redrawing with exact depth:
  1464. my $selections = $self->collect_selections;
  1465. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  1466. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1);
  1467. }
  1468. # XXX: not done
  1469. # This gets called also if we have no threads.
  1470. sub on_progress_event {
  1471. my ($self, $percent, $message) = @_;
  1472. $self->statusbar->SetProgress($percent);
  1473. # TODO: three dot character is not properly translated into C++
  1474. # $self->statusbar->SetStatusText("$message…");
  1475. $self->statusbar->SetStatusText("$message...");
  1476. }
  1477. # XXX: not done
  1478. # Called when the G-code export finishes, either successfully or with an error.
  1479. # This gets called also if we don't have threads.
  1480. sub on_process_completed {
  1481. my ($self, $result) = @_;
  1482. # Stop the background task, wait until the thread goes into the "Idle" state.
  1483. # At this point of time the thread should be either finished or canceled,
  1484. # so the following call just confirms, that the produced data were consumed.
  1485. $self->{background_slicing_process}->stop;
  1486. $self->statusbar->ResetCancelCallback();
  1487. $self->statusbar->StopBusy;
  1488. $self->statusbar->SetStatusText("");
  1489. my $message;
  1490. my $send_gcode = 0;
  1491. my $do_print = 0;
  1492. # print "Process completed, message: ", $message, "\n";
  1493. if (defined($result)) {
  1494. $message = L("Export failed");
  1495. } else {
  1496. # G-code file exported successfully.
  1497. if ($self->{print_file}) {
  1498. $message = L("File added to print queue");
  1499. $do_print = 1;
  1500. } elsif ($self->{send_gcode_file}) {
  1501. $message = L("Sending G-code file to the Printer Host ...");
  1502. $send_gcode = 1;
  1503. } elsif (defined $self->{export_gcode_output_file}) {
  1504. $message = L("G-code file exported to ") . $self->{export_gcode_output_file};
  1505. } else {
  1506. $message = L("Slicing complete");
  1507. }
  1508. }
  1509. $self->{export_gcode_output_file} = undef;
  1510. wxTheApp->notify($message);
  1511. $self->do_print if $do_print;
  1512. # Send $self->{send_gcode_file} to OctoPrint.
  1513. if ($send_gcode) {
  1514. my $host = Slic3r::PrintHost::get_print_host($self->{config});
  1515. if ($host->send_gcode($self->{send_gcode_file})) {
  1516. $message = L("Upload to host finished.");
  1517. } else {
  1518. $message = "";
  1519. }
  1520. }
  1521. # As of now, the BackgroundProcessing thread posts status bar update messages to a queue on the MainFrame.pm,
  1522. # but the "Processing finished" message is posted to this window.
  1523. # Delay the following status bar update, so it will be called later than what is received by MainFrame.pm.
  1524. wxTheApp->CallAfter(sub {
  1525. $self->statusbar->SetStatusText($message);
  1526. });
  1527. $self->{print_file} = undef;
  1528. $self->{send_gcode_file} = undef;
  1529. $self->print_info_box_show(1);
  1530. # this updates buttons status
  1531. $self->object_list_changed;
  1532. # refresh preview
  1533. $self->{preview_iface}->reload_print if $self->{preview_iface};
  1534. # $self->{preview3D}->reload_print if $self->{preview3D};
  1535. }
  1536. # XXX: partially done in the Sidebar
  1537. # Fill in the "Sliced info" box with the result of the G-code generator.
  1538. sub print_info_box_show {
  1539. my ($self, $show) = @_;
  1540. # my $scrolled_window_panel = $self->{scrolled_window_panel};
  1541. # my $scrolled_window_sizer = $self->{scrolled_window_sizer};
  1542. # return if (!$show && ($scrolled_window_sizer->IsShown(2) == $show));
  1543. my $panel = $self->{scrolled_window_panel};#$self->{right_panel};
  1544. my $sizer = $self->{info_sizer};
  1545. # return if (!$sizer || !$show && ($sizer->IsShown(1) == $show));
  1546. return if (!$sizer);
  1547. Slic3r::GUI::set_show_print_info($show);
  1548. # return if (wxTheApp->{app_config}->get("view_mode") eq "simple");
  1549. # if ($show)
  1550. {
  1551. my $print_info_sizer = $self->{print_info_sizer};
  1552. $print_info_sizer->Clear(1);
  1553. my $grid_sizer = Wx::FlexGridSizer->new(2, 2, 5, 5);
  1554. $grid_sizer->SetFlexibleDirection(wxHORIZONTAL);
  1555. $grid_sizer->AddGrowableCol(1, 1);
  1556. $grid_sizer->AddGrowableCol(3, 1);
  1557. $print_info_sizer->Add($grid_sizer, 0, wxEXPAND);
  1558. my $is_wipe_tower = $self->{print}->total_wipe_tower_filament > 0;
  1559. my @info = (
  1560. L("Used Filament (m)")
  1561. => $is_wipe_tower ?
  1562. sprintf("%.2f (%.2f %s + %.2f %s)" , $self->{print}->total_used_filament / 1000,
  1563. ($self->{print}->total_used_filament - $self->{print}->total_wipe_tower_filament) / 1000,
  1564. L("objects"),
  1565. $self->{print}->total_wipe_tower_filament / 1000,
  1566. L("wipe tower")) :
  1567. sprintf("%.2f" , $self->{print}->total_used_filament / 1000),
  1568. L("Used Filament (mm³)")
  1569. => sprintf("%.2f" , $self->{print}->total_extruded_volume),
  1570. L("Used Filament (g)"),
  1571. => sprintf("%.2f" , $self->{print}->total_weight),
  1572. L("Cost"),
  1573. => $is_wipe_tower ?
  1574. sprintf("%.2f (%.2f %s + %.2f %s)" , $self->{print}->total_cost,
  1575. ($self->{print}->total_cost - $self->{print}->total_wipe_tower_cost),
  1576. L("objects"),
  1577. $self->{print}->total_wipe_tower_cost,
  1578. L("wipe tower")) :
  1579. sprintf("%.2f" , $self->{print}->total_cost),
  1580. L("Estimated printing time (normal mode)")
  1581. => $self->{print}->estimated_normal_print_time,
  1582. L("Estimated printing time (silent mode)")
  1583. => $self->{print}->estimated_silent_print_time
  1584. );
  1585. # if there is a wipe tower, insert number of toolchanges info into the array:
  1586. splice (@info, 8, 0, L("Number of tool changes") => sprintf("%.d", $self->{print}->wipe_tower_number_of_toolchanges)) if ($is_wipe_tower);
  1587. while ( my $label = shift @info) {
  1588. my $value = shift @info;
  1589. next if $value eq "N/A";
  1590. # my $text = Wx::StaticText->new($scrolled_window_panel, -1, "$label:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
  1591. my $text = Wx::StaticText->new($panel, -1, "$label:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
  1592. $text->SetFont($Slic3r::GUI::small_font);
  1593. $grid_sizer->Add($text, 0);
  1594. # my $field = Wx::StaticText->new($scrolled_window_panel, -1, $value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  1595. my $field = Wx::StaticText->new($panel, -1, $value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
  1596. $field->SetFont($Slic3r::GUI::small_font);
  1597. $grid_sizer->Add($field, 0);
  1598. }
  1599. }
  1600. # $scrolled_window_sizer->Show(2, $show);
  1601. # $scrolled_window_panel->Layout;
  1602. $sizer->Show(1, $show && wxTheApp->{app_config}->get("view_mode") ne "simple");
  1603. $self->Layout;
  1604. $panel->Refresh;
  1605. }
  1606. # XXX: not done - to be removed
  1607. sub do_print {
  1608. my ($self) = @_;
  1609. my $controller = $self->GetFrame->{controller};
  1610. my $printer_preset = wxTheApp->{preset_bundle}->printer->get_edited_preset;
  1611. my $printer_panel = $controller->add_printer($printer_preset->name, $printer_preset->config);
  1612. my $filament_stats = $self->{print}->filament_stats;
  1613. my $filament_names = wxTheApp->{preset_bundle}->filament_presets;
  1614. $filament_stats = { map { $filament_names->[$_] => $filament_stats->{$_} } keys %$filament_stats };
  1615. $printer_panel->load_print_job($self->{print_file}, $filament_stats);
  1616. }
  1617. # XXX: VK: done
  1618. sub export_stl {
  1619. my ($self) = @_;
  1620. return if !@{$self->{objects}};
  1621. # Ask user for a file name to write into.
  1622. my $output_file = $self->_get_export_file('STL') or return;
  1623. # Store a binary STL.
  1624. $self->{model}->store_stl($output_file, 1);
  1625. $self->statusbar->SetStatusText(L("STL file exported to ").$output_file);
  1626. }
  1627. # XXX: VK: done
  1628. sub reload_from_disk {
  1629. my ($self) = @_;
  1630. my ($obj_idx, $object) = $self->selected_object;
  1631. return if !defined $obj_idx;
  1632. my $model_object = $self->{model}->objects->[$obj_idx];
  1633. #FIXME convert to local file encoding
  1634. return if !$model_object->input_file
  1635. || !-e Slic3r::encode_path($model_object->input_file);
  1636. my @new_obj_idx = $self->load_files([$model_object->input_file]);
  1637. return if !@new_obj_idx;
  1638. foreach my $new_obj_idx (@new_obj_idx) {
  1639. my $o = $self->{model}->objects->[$new_obj_idx];
  1640. $o->clear_instances;
  1641. $o->add_instance($_) for @{$model_object->instances};
  1642. #$o->invalidate_bounding_box;
  1643. if ($o->volumes_count == $model_object->volumes_count) {
  1644. for my $i (0..($o->volumes_count-1)) {
  1645. $o->get_volume($i)->config->apply($model_object->get_volume($i)->config);
  1646. }
  1647. }
  1648. #FIXME restore volumes and their configs, layer_height_ranges, layer_height_profile, layer_height_profile_valid,
  1649. }
  1650. $self->remove($obj_idx);
  1651. }
  1652. # XXX: VK: integrated into Plater::export_stl()
  1653. sub export_object_stl {
  1654. my ($self) = @_;
  1655. my ($obj_idx, $object) = $self->selected_object;
  1656. return if !defined $obj_idx;
  1657. my $model_object = $self->{model}->objects->[$obj_idx];
  1658. # Ask user for a file name to write into.
  1659. my $output_file = $self->_get_export_file('STL') or return;
  1660. $model_object->mesh->write_binary($output_file);
  1661. $self->statusbar->SetStatusText(L("STL file exported to ").$output_file);
  1662. }
  1663. # XXX: not done
  1664. sub fix_through_netfabb {
  1665. my ($self) = @_;
  1666. my ($obj_idx, $object) = $self->selected_object;
  1667. return if !defined $obj_idx;
  1668. my $model_object = $self->{model}->objects->[$obj_idx];
  1669. my $model_fixed = Slic3r::Model->new;
  1670. Slic3r::GUI::fix_model_by_win10_sdk_gui($model_object, $self->{print}, $model_fixed);
  1671. my @new_obj_idx = $self->load_model_objects(@{$model_fixed->objects});
  1672. return if !@new_obj_idx;
  1673. foreach my $new_obj_idx (@new_obj_idx) {
  1674. my $o = $self->{model}->objects->[$new_obj_idx];
  1675. $o->clear_instances;
  1676. $o->add_instance($_) for @{$model_object->instances};
  1677. #$o->invalidate_bounding_box;
  1678. if ($o->volumes_count == $model_object->volumes_count) {
  1679. for my $i (0..($o->volumes_count-1)) {
  1680. $o->get_volume($i)->config->apply($model_object->get_volume($i)->config);
  1681. }
  1682. }
  1683. #FIXME restore volumes and their configs, layer_height_ranges, layer_height_profile, layer_height_profile_valid,
  1684. }
  1685. $self->remove($obj_idx);
  1686. }
  1687. # XXX: VK: done
  1688. sub export_amf {
  1689. my ($self) = @_;
  1690. return if !@{$self->{objects}};
  1691. # Ask user for a file name to write into.
  1692. my $output_file = $self->_get_export_file('AMF') or return;
  1693. my $res = $self->{model}->store_amf($output_file, $self->{print}, $self->{export_option});
  1694. if ($res)
  1695. {
  1696. $self->statusbar->SetStatusText(L("AMF file exported to ").$output_file);
  1697. }
  1698. else
  1699. {
  1700. $self->statusbar->SetStatusText(L("Error exporting AMF file ").$output_file);
  1701. }
  1702. }
  1703. # XXX: VK: done
  1704. sub export_3mf {
  1705. my ($self) = @_;
  1706. return if !@{$self->{objects}};
  1707. # Ask user for a file name to write into.
  1708. my $output_file = $self->_get_export_file('3MF') or return;
  1709. my $res = $self->{model}->store_3mf($output_file, $self->{print}, $self->{export_option});
  1710. if ($res)
  1711. {
  1712. $self->statusbar->SetStatusText(L("3MF file exported to ").$output_file);
  1713. }
  1714. else
  1715. {
  1716. $self->statusbar->SetStatusText(L("Error exporting 3MF file ").$output_file);
  1717. }
  1718. }
  1719. # XXX: VK: done
  1720. # Ask user to select an output file for a given file format (STl, AMF, 3MF).
  1721. # Propose a default file name based on the 'output_filename_format' configuration value.
  1722. sub _get_export_file {
  1723. my ($self, $format) = @_;
  1724. my $suffix = '';
  1725. my $wildcard = 'known';
  1726. if ($format eq 'STL')
  1727. {
  1728. $suffix = '.stl';
  1729. $wildcard = 'stl';
  1730. }
  1731. elsif ($format eq 'AMF')
  1732. {
  1733. if (&Wx::wxMAC) {
  1734. # It seems that MacOS does not like double extension
  1735. $suffix = '.amf';
  1736. } else {
  1737. $suffix = '.zip.amf';
  1738. }
  1739. $wildcard = 'amf';
  1740. }
  1741. elsif ($format eq '3MF')
  1742. {
  1743. $suffix = '.3mf';
  1744. $wildcard = 'threemf';
  1745. }
  1746. # Copy the names of active presets into the placeholder parser.
  1747. wxTheApp->{preset_bundle}->export_selections_pp($self->{print}->placeholder_parser);
  1748. my $output_file = eval { $self->{print}->output_filepath($main::opt{output} // '') };
  1749. Slic3r::GUI::catch_error($self) and return undef;
  1750. $output_file =~ s/\.[gG][cC][oO][dD][eE]$/$suffix/;
  1751. my $dlg = Wx::FileDialog->new($self, L("Save ").$format.L(" file as:"), dirname($output_file),
  1752. basename($output_file), &Slic3r::GUI::FILE_WILDCARDS->{$wildcard}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
  1753. Slic3r::GUI::add_export_option($dlg, $format);
  1754. if ($dlg->ShowModal != wxID_OK) {
  1755. $dlg->Destroy;
  1756. return undef;
  1757. }
  1758. $output_file = $dlg->GetPath;
  1759. $self->{export_option} = Slic3r::GUI::get_export_option($dlg);
  1760. $dlg->Destroy;
  1761. return $output_file;
  1762. }
  1763. #sub reset_thumbnail {
  1764. # my ($self, $obj_idx) = @_;
  1765. # $self->{objects}[$obj_idx]->thumbnail(undef);
  1766. #}
  1767. # XXX: VK: done
  1768. # this method gets called whenever print center is changed or the objects' bounding box changes
  1769. # (i.e. when an object is added/removed/moved/rotated/scaled)
  1770. sub update {
  1771. my ($self, $force_autocenter) = @_;
  1772. $self->Freeze;
  1773. if (wxTheApp->{app_config}->get("autocenter") || $force_autocenter) {
  1774. $self->{model}->center_instances_around_point($self->bed_centerf);
  1775. }
  1776. $self->stop_background_process;
  1777. $self->{print}->reload_model_instances();
  1778. $self->{canvas}->reload_scene if $self->{canvas};
  1779. # $self->{canvas}->reload_scene if $self->{canvas};
  1780. my $selections = $self->collect_selections;
  1781. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  1782. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 0);
  1783. $self->{preview_iface}->reset_gcode_preview_data if $self->{preview_iface};
  1784. $self->{preview_iface}->reload_print if $self->{preview_iface};
  1785. # $self->{preview3D}->reset_gcode_preview_data if $self->{preview3D};
  1786. # $self->{preview3D}->reload_print if $self->{preview3D};
  1787. $self->schedule_background_process;
  1788. $self->Thaw;
  1789. }
  1790. # XXX: YS: done
  1791. # When a printer technology is changed, the UI needs to be updated to show/hide needed preset combo boxes.
  1792. sub show_preset_comboboxes{
  1793. my ($self, $showSLA) = @_; #if showSLA is oposite value to "ptFFF"
  1794. my $choices = $self->{preset_choosers}{filament};
  1795. my $print_filament_ctrls_cnt = 2 + 2 * ($#$choices+1);
  1796. foreach (0..$print_filament_ctrls_cnt-1){
  1797. $self->{presets_sizer}->Show($_, !$showSLA);
  1798. }
  1799. $self->{presets_sizer}->Show($print_filament_ctrls_cnt , $showSLA);
  1800. $self->{presets_sizer}->Show($print_filament_ctrls_cnt+1, $showSLA);
  1801. $self->{frequently_changed_parameters_sizer}->Show(0,!$showSLA);
  1802. $self->Layout;
  1803. }
  1804. # XXX: YS: done
  1805. # When a number of extruders changes, the UI needs to be updated to show a single filament selection combo box per extruder.
  1806. # Also the wxTheApp->{preset_bundle}->filament_presets needs to be resized accordingly
  1807. # and some reasonable default has to be selected for the additional extruders.
  1808. sub on_extruders_change {
  1809. my ($self, $num_extruders) = @_;
  1810. my $choices = $self->{preset_choosers}{filament};
  1811. while (int(@$choices) < $num_extruders) {
  1812. # copy strings from first choice
  1813. my @presets = $choices->[0]->GetStrings;
  1814. # initialize new choice
  1815. # my $choice = Wx::BitmapComboBox->new($self->{right_panel}, -1, "", wxDefaultPosition, wxDefaultSize, [@presets], wxCB_READONLY);
  1816. my $choice = Wx::BitmapComboBox->new($self->{scrolled_window_panel}, -1, "", wxDefaultPosition, wxDefaultSize, [@presets], wxCB_READONLY);
  1817. my $extruder_idx = scalar @$choices;
  1818. EVT_LEFT_DOWN($choice, sub { $self->filament_color_box_lmouse_down($extruder_idx, @_); } );
  1819. push @$choices, $choice;
  1820. # copy icons from first choice
  1821. $choice->SetItemBitmap($_, $choices->[0]->GetItemBitmap($_)) for 0..$#presets;
  1822. # insert new choice into sizer
  1823. $self->{presets_sizer}->Insert(4 + ($#$choices-1)*2, 0, 0);
  1824. $self->{presets_sizer}->Insert(5 + ($#$choices-1)*2, $choice, 0, wxEXPAND | wxBOTTOM, 0);
  1825. # setup the listener
  1826. EVT_COMBOBOX($choice, $choice, sub {
  1827. my ($choice) = @_;
  1828. wxTheApp->CallAfter(sub {
  1829. $self->_on_select_preset('filament', $choice, $extruder_idx);
  1830. });
  1831. });
  1832. # initialize selection
  1833. wxTheApp->{preset_bundle}->update_platter_filament_ui($extruder_idx, $choice);
  1834. }
  1835. # remove unused choices if any
  1836. while (@$choices > $num_extruders) {
  1837. $self->{presets_sizer}->Remove(4 + ($#$choices-1)*2); # label
  1838. $self->{presets_sizer}->Remove(4 + ($#$choices-1)*2); # wxChoice
  1839. $choices->[-1]->Destroy;
  1840. pop @$choices;
  1841. }
  1842. $self->{right_panel}->Layout;
  1843. $self->Layout;
  1844. }
  1845. # XXX: not done
  1846. sub on_config_change {
  1847. my ($self, $config) = @_;
  1848. my $update_scheduled;
  1849. foreach my $opt_key (@{$self->{config}->diff($config)}) {
  1850. $self->{config}->set($opt_key, $config->get($opt_key));
  1851. if ($opt_key eq 'bed_shape') {
  1852. # $self->{canvas}->update_bed_size;
  1853. Slic3r::GUI::_3DScene::set_bed_shape($self->{canvas3D}, $self->{config}->bed_shape) if $self->{canvas3D};
  1854. $self->{preview_iface}->set_bed_shape($self->{config}->bed_shape) if ($self->{preview_iface});
  1855. # Slic3r::GUI::_3DScene::set_bed_shape($self->{preview3D}->canvas, $self->{config}->bed_shape) if $self->{preview3D};
  1856. $update_scheduled = 1;
  1857. } elsif ($opt_key =~ '^wipe_tower' || $opt_key eq 'single_extruder_multi_material') {
  1858. $update_scheduled = 1;
  1859. } elsif ($opt_key eq 'serial_port') {
  1860. $self->{btn_print}->Show($config->get('serial_port'));
  1861. $self->Layout;
  1862. } elsif ($opt_key eq 'print_host') {
  1863. $self->{btn_send_gcode}->Show($config->get('print_host'));
  1864. $self->Layout;
  1865. } elsif ($opt_key eq 'variable_layer_height') {
  1866. if ($config->get('variable_layer_height') != 1) {
  1867. # if ($self->{htoolbar}) {
  1868. # $self->{htoolbar}->EnableTool(TB_LAYER_EDITING, 0);
  1869. # $self->{htoolbar}->ToggleTool(TB_LAYER_EDITING, 0);
  1870. # } else {
  1871. # $self->{"btn_layer_editing"}->Disable;
  1872. # $self->{"btn_layer_editing"}->SetValue(0);
  1873. # }
  1874. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "layersediting", 0);
  1875. Slic3r::GUI::_3DScene::enable_layers_editing($self->{canvas3D}, 0);
  1876. $self->{canvas3D}->Refresh;
  1877. $self->{canvas3D}->Update;
  1878. } elsif (Slic3r::GUI::_3DScene::is_layers_editing_allowed($self->{canvas3D})) {
  1879. # Want to allow the layer editing, but do it only if the OpenGL supports it.
  1880. # if ($self->{htoolbar}) {
  1881. # $self->{htoolbar}->EnableTool(TB_LAYER_EDITING, 1);
  1882. # } else {
  1883. # $self->{"btn_layer_editing"}->Enable;
  1884. # }
  1885. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "layersediting", 1);
  1886. }
  1887. } elsif ($opt_key eq 'extruder_colour') {
  1888. $update_scheduled = 1;
  1889. my $extruder_colors = $config->get('extruder_colour');
  1890. $self->{preview_iface}->set_number_extruders(scalar(@{$extruder_colors}));
  1891. # $self->{preview3D}->set_number_extruders(scalar(@{$extruder_colors}));
  1892. } elsif ($opt_key eq 'max_print_height') {
  1893. $update_scheduled = 1;
  1894. } elsif ($opt_key eq 'printer_model') {
  1895. # update to force bed selection (for texturing)
  1896. Slic3r::GUI::_3DScene::set_bed_shape($self->{canvas3D}, $self->{config}->bed_shape) if $self->{canvas3D};
  1897. $self->{preview_iface}->set_bed_shape($self->{config}->bed_shape) if ($self->{preview_iface});
  1898. # Slic3r::GUI::_3DScene::set_bed_shape($self->{preview3D}->canvas, $self->{config}->bed_shape) if $self->{preview3D};
  1899. $update_scheduled = 1;
  1900. }
  1901. }
  1902. $self->update if $update_scheduled;
  1903. return if !$self->GetFrame->is_loaded;
  1904. # (re)start timer
  1905. $self->schedule_background_process;
  1906. }
  1907. # XXX: YS: WIP
  1908. sub item_changed_selection {
  1909. my ($self, $obj_idx) = @_;
  1910. if (($obj_idx >= 0) && ($obj_idx < 1000)) { # skip if wipe tower selected
  1911. if ($self->{canvas3D}) {
  1912. Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas3D});
  1913. if ($obj_idx >= 0) {
  1914. my $selections = $self->collect_selections;
  1915. Slic3r::GUI::_3DScene::update_volumes_selection($self->{canvas3D}, \@$selections);
  1916. }
  1917. # Slic3r::GUI::_3DScene::render($self->{canvas3D});
  1918. }
  1919. }
  1920. }
  1921. # XXX: VK: done
  1922. sub collect_selections {
  1923. my ($self) = @_;
  1924. my $selections = [];
  1925. foreach my $o (@{$self->{objects}}) {
  1926. push(@$selections, $o->selected);
  1927. }
  1928. return $selections;
  1929. }
  1930. # XXX: YS: done, lambda on LEFT_DOWN
  1931. # Called when clicked on the filament preset combo box.
  1932. # When clicked on the icon, show the color picker.
  1933. sub filament_color_box_lmouse_down
  1934. {
  1935. my ($self, $extruder_idx, $combobox, $event) = @_;
  1936. my $pos = $event->GetLogicalPosition(Wx::ClientDC->new($combobox));
  1937. my( $x, $y ) = ( $pos->x, $pos->y );
  1938. if ($x > 24) {
  1939. # Let the combo box process the mouse click.
  1940. $event->Skip;
  1941. } else {
  1942. # Swallow the mouse click and open the color picker.
  1943. my $data = Wx::ColourData->new;
  1944. $data->SetChooseFull(1);
  1945. my $dialog = Wx::ColourDialog->new($self->GetFrame, $data);
  1946. if ($dialog->ShowModal == wxID_OK) {
  1947. my $cfg = Slic3r::Config->new;
  1948. my $colors = wxTheApp->{preset_bundle}->full_config->get('extruder_colour');
  1949. $colors->[$extruder_idx] = $dialog->GetColourData->GetColour->GetAsString(wxC2S_HTML_SYNTAX);
  1950. $cfg->set('extruder_colour', $colors);
  1951. $self->GetFrame->{options_tabs}{printer}->load_config($cfg);
  1952. wxTheApp->{preset_bundle}->update_platter_filament_ui($extruder_idx, $combobox);
  1953. }
  1954. $dialog->Destroy();
  1955. }
  1956. }
  1957. #sub object_cut_dialog {
  1958. # my ($self, $obj_idx) = @_;
  1959. #
  1960. # if (!defined $obj_idx) {
  1961. # ($obj_idx, undef) = $self->selected_object;
  1962. # }
  1963. #
  1964. # if (!$Slic3r::GUI::have_OpenGL) {
  1965. # Slic3r::GUI::show_error($self, L("Please install the OpenGL modules to use this feature (see build instructions)."));
  1966. # return;
  1967. # }
  1968. #
  1969. # my $dlg = Slic3r::GUI::Plater::ObjectCutDialog->new($self,
  1970. # object => $self->{objects}[$obj_idx],
  1971. # model_object => $self->{model}->objects->[$obj_idx],
  1972. # );
  1973. # return unless $dlg->ShowModal == wxID_OK;
  1974. #
  1975. # if (my @new_objects = $dlg->NewModelObjects) {
  1976. # $self->remove($obj_idx);
  1977. # $self->load_model_objects(grep defined($_), @new_objects);
  1978. # $self->arrange;
  1979. # Slic3r::GUI::_3DScene::zoom_to_volumes($self->{canvas3D}) if $self->{canvas3D};
  1980. # }
  1981. #}
  1982. # XXX: YS: done
  1983. sub changed_object_settings {
  1984. my ($self, $obj_idx, $parts_changed, $part_settings_changed) = @_;
  1985. # update thumbnail since parts may have changed
  1986. if ($parts_changed) {
  1987. # recenter and re-align to Z = 0
  1988. my $model_object = $self->{model}->objects->[$obj_idx];
  1989. $model_object->center_around_origin;
  1990. # $self->reset_thumbnail($obj_idx);
  1991. }
  1992. # update print
  1993. if ($parts_changed || $part_settings_changed) {
  1994. $self->stop_background_process;
  1995. $self->{print}->reload_object($obj_idx);
  1996. $self->schedule_background_process;
  1997. $self->{canvas}->reload_scene if $self->{canvas};
  1998. my $selections = $self->collect_selections;
  1999. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  2000. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 0);
  2001. } else {
  2002. $self->schedule_background_process;
  2003. }
  2004. }
  2005. # XXX: VK: done
  2006. # Called to update various buttons depending on whether there are any objects or
  2007. # whether background processing (export of a G-code, sending to Octoprint, forced background re-slicing) is active.
  2008. sub object_list_changed {
  2009. my $self = shift;
  2010. # Enable/disable buttons depending on whether there are any objects on the platter.
  2011. my $have_objects = @{$self->{objects}} ? 1 : 0;
  2012. # if ($self->{htoolbar}) {
  2013. # # On OSX or Linux
  2014. # $self->{htoolbar}->EnableTool($_, $have_objects)
  2015. # for (TB_RESET, TB_ARRANGE);
  2016. # } else {
  2017. # # On MSW
  2018. # my $method = $have_objects ? 'Enable' : 'Disable';
  2019. # $self->{"btn_$_"}->$method
  2020. # for grep $self->{"btn_$_"}, qw(reset arrange reslice export_gcode export_stl print send_gcode);
  2021. # }
  2022. for my $toolbar_item (qw(deleteall arrange)) {
  2023. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, $toolbar_item, $have_objects);
  2024. }
  2025. my $export_in_progress = $self->{export_gcode_output_file} || $self->{send_gcode_file};
  2026. my $model_fits = $self->{canvas3D} ? Slic3r::GUI::_3DScene::check_volumes_outside_state($self->{canvas3D}, $self->{config}) : 1;
  2027. # $model_fits == 1 -> ModelInstance::PVS_Partly_Outside
  2028. my $method = ($have_objects && ! $export_in_progress && ($model_fits != 1)) ? 'Enable' : 'Disable';
  2029. $self->{"btn_$_"}->$method
  2030. for grep $self->{"btn_$_"}, qw(reslice export_gcode print send_gcode);
  2031. }
  2032. # XXX: VK: WIP
  2033. # Selection of an active 3D object changed.
  2034. sub selection_changed {
  2035. my ($self) = @_;
  2036. my ($obj_idx, $object) = $self->selected_object;
  2037. my $have_sel = defined $obj_idx;
  2038. my $layers_height_allowed = $self->{config}->variable_layer_height && Slic3r::GUI::_3DScene::is_layers_editing_allowed($self->{canvas3D}) && $have_sel;
  2039. $self->{right_panel}->Freeze;
  2040. # if ($self->{htoolbar}) {
  2041. # # On OSX or Linux
  2042. # $self->{htoolbar}->EnableTool($_, $have_sel)
  2043. # for (TB_REMOVE, TB_MORE, TB_45CW, TB_45CCW, TB_SCALE, TB_SPLIT, TB_CUT, TB_SETTINGS);
  2044. #
  2045. # $self->{htoolbar}->EnableTool(TB_LAYER_EDITING, $layers_height_allowed);
  2046. #
  2047. # if ($have_sel) {
  2048. # my $model_object = $self->{model}->objects->[$obj_idx];
  2049. # $self->{htoolbar}->EnableTool(TB_FEWER, $model_object->instances_count > 1);
  2050. # } else {
  2051. # $self->{htoolbar}->EnableTool(TB_FEWER, 0);
  2052. # }
  2053. #
  2054. # } else {
  2055. # # On MSW
  2056. # my $method = $have_sel ? 'Enable' : 'Disable';
  2057. # $self->{"btn_$_"}->$method
  2058. # for grep $self->{"btn_$_"}, qw(remove increase rotate45cw rotate45ccw changescale split cut settings);
  2059. #
  2060. # if ($layers_height_allowed) {
  2061. # $self->{"btn_layer_editing"}->Enable;
  2062. # } else {
  2063. # $self->{"btn_layer_editing"}->Disable;
  2064. # }
  2065. #
  2066. # if ($have_sel) {
  2067. # my $model_object = $self->{model}->objects->[$obj_idx];
  2068. # if ($model_object->instances_count > 1) {
  2069. # $self->{"btn_decrease"}->Enable;
  2070. # } else {
  2071. # $self->{"btn_decrease"}->Disable;
  2072. # }
  2073. # } else {
  2074. # $self->{"btn_decrease"}->Disable;
  2075. # }
  2076. # }
  2077. for my $toolbar_item (qw(delete more fewer split cut settings)) {
  2078. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, $toolbar_item, $have_sel);
  2079. }
  2080. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "layersediting", $layers_height_allowed);
  2081. my $can_select_by_parts = 0;
  2082. if ($have_sel) {
  2083. my $model_object = $self->{model}->objects->[$obj_idx];
  2084. $can_select_by_parts = ($obj_idx >= 0) && ($obj_idx < 1000) && ($model_object->volumes_count > 1);
  2085. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "fewer", $model_object->instances_count > 1);
  2086. }
  2087. if ($can_select_by_parts) {
  2088. # first disable to let the item in the toolbar to switch to the unpressed state
  2089. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "selectbyparts", 0);
  2090. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "selectbyparts", 1);
  2091. } else {
  2092. Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "selectbyparts", 0);
  2093. Slic3r::GUI::_3DScene::set_select_by($self->{canvas3D}, 'object');
  2094. }
  2095. if ($self->{object_info_size}) { # have we already loaded the info pane?
  2096. if ($have_sel) {
  2097. my $model_object = $self->{model}->objects->[$obj_idx];
  2098. #FIXME print_info runs model fixing in two rounds, it is very slow, it should not be performed here!
  2099. # $model_object->print_info;
  2100. my $model_instance = $model_object->instances->[0];
  2101. $self->{object_info_size}->SetLabel(sprintf("%.2f x %.2f x %.2f", @{$model_object->instance_bounding_box(0)->size}));
  2102. $self->{object_info_materials}->SetLabel($model_object->materials_count);
  2103. if (my $stats = $model_object->mesh_stats) {
  2104. $self->{object_info_volume}->SetLabel(sprintf('%.2f', $stats->{volume} * ($model_instance->scaling_factor**3)));
  2105. $self->{object_info_facets}->SetLabel(sprintf(L('%d (%d shells)'), $model_object->facets_count, $stats->{number_of_parts}));
  2106. if (my $errors = sum(@$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)})) {
  2107. $self->{object_info_manifold}->SetLabel(sprintf(L("Auto-repaired (%d errors)"), $errors));
  2108. #$self->{object_info_manifold_warning_icon}->Show;
  2109. $self->{"object_info_manifold_warning_icon_show"}->(1);
  2110. # we don't show normals_fixed because we never provide normals
  2111. # to admesh, so it generates normals for all facets
  2112. my $message = sprintf L('%d degenerate facets, %d edges fixed, %d facets removed, %d facets added, %d facets reversed, %d backwards edges'),
  2113. @$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)};
  2114. $self->{object_info_manifold}->SetToolTipString($message);
  2115. $self->{object_info_manifold_warning_icon}->SetToolTipString($message);
  2116. } else {
  2117. $self->{object_info_manifold}->SetLabel(L("Yes"));
  2118. #$self->{object_info_manifold_warning_icon}->Hide;
  2119. $self->{"object_info_manifold_warning_icon_show"}->(0);
  2120. $self->{object_info_manifold}->SetToolTipString("");
  2121. $self->{object_info_manifold_warning_icon}->SetToolTipString("");
  2122. }
  2123. } else {
  2124. $self->{object_info_facets}->SetLabel($object->facets);
  2125. }
  2126. } else {
  2127. $self->{"object_info_$_"}->SetLabel("") for qw(size volume facets materials manifold);
  2128. #$self->{object_info_manifold_warning_icon}->Hide;
  2129. $self->{"object_info_manifold_warning_icon_show"}->(0);
  2130. $self->{object_info_manifold}->SetToolTipString("");
  2131. $self->{object_info_manifold_warning_icon}->SetToolTipString("");
  2132. }
  2133. $self->Layout;
  2134. }
  2135. # prepagate the event to the frame (a custom Wx event would be cleaner)
  2136. $self->GetFrame->on_plater_selection_changed($have_sel);
  2137. $self->{right_panel}->Thaw;
  2138. }
  2139. # XXX: VK: done
  2140. sub select_object {
  2141. my ($self, $obj_idx, $child) = @_;
  2142. # remove current selection
  2143. foreach my $o (0..$#{$self->{objects}}) {
  2144. $self->{objects}->[$o]->selected(0);
  2145. }
  2146. if (defined $obj_idx) {
  2147. $self->{objects}->[$obj_idx]->selected(1);
  2148. # Select current object in the list on c++ side, if item isn't child
  2149. # if (!defined $child){
  2150. # Slic3r::GUI::select_current_object($obj_idx);} # all selections in the object list is on c++ side
  2151. } else {
  2152. # Unselect all objects in the list on c++ side
  2153. # Slic3r::GUI::unselect_objects(); # all selections in the object list is on c++ side
  2154. }
  2155. $self->selection_changed(1);
  2156. }
  2157. # XXX: YS: WIP
  2158. sub select_object_from_cpp {
  2159. my ($self, $obj_idx, $vol_idx) = @_;
  2160. # remove current selection
  2161. foreach my $o (0..$#{$self->{objects}}) {
  2162. $self->{objects}->[$o]->selected(0);
  2163. }
  2164. my $curr = Slic3r::GUI::_3DScene::get_select_by($self->{canvas3D});
  2165. if (defined $obj_idx) {
  2166. if ($vol_idx == -1){
  2167. if ($curr eq 'object') {
  2168. $self->{objects}->[$obj_idx]->selected(1);
  2169. }
  2170. elsif ($curr eq 'volume') {
  2171. Slic3r::GUI::_3DScene::set_select_by($self->{canvas3D}, 'object');
  2172. }
  2173. my $selections = $self->collect_selections;
  2174. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  2175. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1);
  2176. }
  2177. else {
  2178. if ($curr eq 'object') {
  2179. Slic3r::GUI::_3DScene::set_select_by($self->{canvas3D}, 'volume');
  2180. }
  2181. my $selections = [];
  2182. Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections);
  2183. Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas3D});
  2184. Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1);
  2185. my $volume_idx = Slic3r::GUI::_3DScene::get_first_volume_id($self->{canvas3D}, $obj_idx);
  2186. my $inst_cnt = $self->{model}->objects->[$obj_idx]->instances_count;
  2187. for (0..$inst_cnt-1){
  2188. Slic3r::GUI::_3DScene::select_volume($self->{canvas3D}, $vol_idx*$inst_cnt + $_ + $volume_idx) if ($volume_idx != -1);
  2189. }
  2190. }
  2191. }
  2192. $self->selection_changed(1);
  2193. }
  2194. # XXX: VK: done
  2195. sub selected_object {
  2196. my ($self) = @_;
  2197. my $obj_idx = first { $self->{objects}[$_]->selected } 0..$#{ $self->{objects} };
  2198. return defined $obj_idx ? ($obj_idx, $self->{objects}[$obj_idx]) : undef;
  2199. }
  2200. # XXX: VK: done
  2201. sub statusbar {
  2202. return $_[0]->GetFrame->{statusbar};
  2203. }
  2204. # XXX: not done, to be removed (?)
  2205. sub object_menu {
  2206. my ($self) = @_;
  2207. my $frame = $self->GetFrame;
  2208. my $menu = Wx::Menu->new;
  2209. my $accel = ($^O eq 'MSWin32') ? sub { $_[0] . "\t\xA0" . $_[1] } : sub { $_[0] };
  2210. $frame->_append_menu_item($menu, $accel->(L('Delete'), 'Del'), L('Remove the selected object'), sub {
  2211. $self->remove;
  2212. }, undef, 'brick_delete.png');
  2213. $frame->_append_menu_item($menu, $accel->(L('Increase copies'), '+'), L('Place one more copy of the selected object'), sub {
  2214. $self->increase;
  2215. }, undef, 'add.png');
  2216. $frame->_append_menu_item($menu, $accel->(L('Decrease copies'), '-'), L('Remove one copy of the selected object'), sub {
  2217. $self->decrease;
  2218. }, undef, 'delete.png');
  2219. $frame->_append_menu_item($menu, L("Set number of copies…"), L('Change the number of copies of the selected object'), sub {
  2220. $self->set_number_of_copies;
  2221. }, undef, 'textfield.png');
  2222. $menu->AppendSeparator();
  2223. $frame->_append_menu_item($menu, $accel->(L('Rotate 45° clockwise'), 'l'), L('Rotate the selected object by 45° clockwise'), sub {
  2224. $self->rotate(-45, Z, 'relative');
  2225. }, undef, 'arrow_rotate_clockwise.png');
  2226. $frame->_append_menu_item($menu, $accel->(L('Rotate 45° counter-clockwise'), 'r'), L('Rotate the selected object by 45° counter-clockwise'), sub {
  2227. $self->rotate(+45, Z, 'relative');
  2228. }, undef, 'arrow_rotate_anticlockwise.png');
  2229. my $rotateMenu = Wx::Menu->new;
  2230. my $rotateMenuItem = $menu->AppendSubMenu($rotateMenu, L("Rotate"), L('Rotate the selected object by an arbitrary angle'));
  2231. $frame->_set_menu_item_icon($rotateMenuItem, 'textfield.png');
  2232. $frame->_append_menu_item($rotateMenu, L("Around X axis…"), L('Rotate the selected object by an arbitrary angle around X axis'), sub {
  2233. $self->rotate(undef, X);
  2234. }, undef, 'bullet_red.png');
  2235. $frame->_append_menu_item($rotateMenu, L("Around Y axis…"), L('Rotate the selected object by an arbitrary angle around Y axis'), sub {
  2236. $self->rotate(undef, Y);
  2237. }, undef, 'bullet_green.png');
  2238. $frame->_append_menu_item($rotateMenu, L("Around Z axis…"), L('Rotate the selected object by an arbitrary angle around Z axis'), sub {
  2239. $self->rotate(undef, Z);
  2240. }, undef, 'bullet_blue.png');
  2241. my $mirrorMenu = Wx::Menu->new;
  2242. my $mirrorMenuItem = $menu->AppendSubMenu($mirrorMenu, L("Mirror"), L('Mirror the selected object'));
  2243. $frame->_set_menu_item_icon($mirrorMenuItem, 'shape_flip_horizontal.png');
  2244. $frame->_append_menu_item($mirrorMenu, L("Along X axis…"), L('Mirror the selected object along the X axis'), sub {
  2245. $self->mirror(X);
  2246. }, undef, 'bullet_red.png');
  2247. $frame->_append_menu_item($mirrorMenu, L("Along Y axis…"), L('Mirror the selected object along the Y axis'), sub {
  2248. $self->mirror(Y);
  2249. }, undef, 'bullet_green.png');
  2250. $frame->_append_menu_item($mirrorMenu, L("Along Z axis…"), L('Mirror the selected object along the Z axis'), sub {
  2251. $self->mirror(Z);
  2252. }, undef, 'bullet_blue.png');
  2253. my $scaleMenu = Wx::Menu->new;
  2254. my $scaleMenuItem = $menu->AppendSubMenu($scaleMenu, L("Scale"), L('Scale the selected object along a single axis'));
  2255. $frame->_set_menu_item_icon($scaleMenuItem, 'arrow_out.png');
  2256. $frame->_append_menu_item($scaleMenu, $accel->(L('Uniformly…'), 's'), L('Scale the selected object along the XYZ axes'), sub {
  2257. $self->changescale(undef);
  2258. });
  2259. $frame->_append_menu_item($scaleMenu, L("Along X axis…"), L('Scale the selected object along the X axis'), sub {
  2260. $self->changescale(X);
  2261. }, undef, 'bullet_red.png');
  2262. $frame->_append_menu_item($scaleMenu, L("Along Y axis…"), L('Scale the selected object along the Y axis'), sub {
  2263. $self->changescale(Y);
  2264. }, undef, 'bullet_green.png');
  2265. $frame->_append_menu_item($scaleMenu, L("Along Z axis…"), L('Scale the selected object along the Z axis'), sub {
  2266. $self->changescale(Z);
  2267. }, undef, 'bullet_blue.png');
  2268. my $scaleToSizeMenu = Wx::Menu->new;
  2269. my $scaleToSizeMenuItem = $menu->AppendSubMenu($scaleToSizeMenu, L("Scale to size"), L('Scale the selected object along a single axis'));
  2270. $frame->_set_menu_item_icon($scaleToSizeMenuItem, 'arrow_out.png');
  2271. $frame->_append_menu_item($scaleToSizeMenu, L("Uniformly…"), L('Scale the selected object along the XYZ axes'), sub {
  2272. $self->changescale(undef, 1);
  2273. });
  2274. $frame->_append_menu_item($scaleToSizeMenu, L("Along X axis…"), L('Scale the selected object along the X axis'), sub {
  2275. $self->changescale(X, 1);
  2276. }, undef, 'bullet_red.png');
  2277. $frame->_append_menu_item($scaleToSizeMenu, L("Along Y axis…"), L('Scale the selected object along the Y axis'), sub {
  2278. $self->changescale(Y, 1);
  2279. }, undef, 'bullet_green.png');
  2280. $frame->_append_menu_item($scaleToSizeMenu, L("Along Z axis…"), L('Scale the selected object along the Z axis'), sub {
  2281. $self->changescale(Z, 1);
  2282. }, undef, 'bullet_blue.png');
  2283. $frame->_append_menu_item($menu, L("Split"), L('Split the selected object into individual parts'), sub {
  2284. $self->split_object;
  2285. }, undef, 'shape_ungroup.png');
  2286. $frame->_append_menu_item($menu, L("Cut…"), L('Open the 3D cutting tool'), sub {
  2287. $self->object_cut_dialog;
  2288. }, undef, 'package.png');
  2289. $menu->AppendSeparator();
  2290. $frame->_append_menu_item($menu, L("Settings…"), L('Open the object editor dialog'), sub {
  2291. $self->object_settings_dialog;
  2292. }, undef, 'cog.png');
  2293. $menu->AppendSeparator();
  2294. $frame->_append_menu_item($menu, L("Reload from Disk"), L('Reload the selected file from Disk'), sub {
  2295. $self->reload_from_disk;
  2296. }, undef, 'arrow_refresh.png');
  2297. $frame->_append_menu_item($menu, L("Export object as STL…"), L('Export this single object as STL file'), sub {
  2298. $self->export_object_stl;
  2299. }, undef, 'brick_go.png');
  2300. if (Slic3r::GUI::is_windows10) {
  2301. $frame->_append_menu_item($menu, L("Fix STL through Netfabb"), L('Fix the model by sending it to a Netfabb cloud service through Windows 10 API'), sub {
  2302. $self->fix_through_netfabb;
  2303. }, undef, 'brick_go.png');
  2304. }
  2305. return $menu;
  2306. }
  2307. # XXX: not done
  2308. # Set a camera direction, zoom to all objects.
  2309. sub select_view {
  2310. my ($self, $direction) = @_;
  2311. my $idx_page = $self->{preview_notebook}->GetSelection;
  2312. my $page = ($idx_page == &Wx::wxNOT_FOUND) ? L('3D') : $self->{preview_notebook}->GetPageText($idx_page);
  2313. if ($page eq L('Preview')) {
  2314. $self->{preview_iface}->select_view($direction);
  2315. $self->{preview_iface}->set_viewport_into_scene($self->{canvas3D});
  2316. # Slic3r::GUI::_3DScene::select_view($self->{preview3D}->canvas, $direction);
  2317. # Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{canvas3D}, $self->{preview3D}->canvas);
  2318. } else {
  2319. Slic3r::GUI::_3DScene::select_view($self->{canvas3D}, $direction);
  2320. $self->{preview_iface}->set_viewport_from_scene($self->{canvas3D});
  2321. # Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D});
  2322. }
  2323. }
  2324. # XXX: VK: done, in PlaterDropTarget
  2325. package Slic3r::GUI::Plater::DropTarget;
  2326. use Wx::DND;
  2327. use base 'Wx::FileDropTarget';
  2328. sub new {
  2329. my ($class, $window) = @_;
  2330. my $self = $class->SUPER::new;
  2331. $self->{window} = $window;
  2332. return $self;
  2333. }
  2334. sub OnDropFiles {
  2335. my ($self, $x, $y, $filenames) = @_;
  2336. # stop scalars leaking on older perl
  2337. # https://rt.perl.org/rt3/Public/Bug/Display.html?id=70602
  2338. @_ = ();
  2339. # only accept STL, OBJ, AMF, 3MF and PRUSA files
  2340. return 0 if grep !/\.(?:[sS][tT][lL]|[oO][bB][jJ]|[aA][mM][fF]|[3][mM][fF]|[aA][mM][fF].[xX][mM][lL]|[zZ][iI][pP].[aA][mM][lL]|[pP][rR][uU][sS][aA])$/, @$filenames;
  2341. $self->{window}->load_files($filenames);
  2342. }
  2343. # 2D preview of an object. Each object is previewed by its convex hull.
  2344. package Slic3r::GUI::Plater::Object;
  2345. use Moo;
  2346. has 'name' => (is => 'rw', required => 1);
  2347. has 'selected' => (is => 'rw', default => sub { 0 });
  2348. 1;