From 2fffb0c2ffedea7a1482498b71fe5cd44c316214 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 21 Nov 2018 11:07:08 +0100 Subject: [PATCH] Arrangement is still not working, update is probably broken. --- src/libslic3r/ModelArrange.cpp | 37 +++++++++++++++++++--------------- src/slic3r/GUI/Plater.cpp | 13 ++++++------ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/libslic3r/ModelArrange.cpp b/src/libslic3r/ModelArrange.cpp index 9d59238fa..d182f1501 100644 --- a/src/libslic3r/ModelArrange.cpp +++ b/src/libslic3r/ModelArrange.cpp @@ -508,32 +508,36 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) { ret.reserve(s); - for(auto objptr : model.objects) { + for(ModelObject* objptr : model.objects) { if(objptr) { - auto rmesh = objptr->raw_mesh(); + TriangleMesh rmesh = objptr->raw_mesh(); - for(auto objinst : objptr->instances) { + ModelInstance * finst = objptr->instances.front(); + + // Object instances should carry the same scaling and + // x, y rotation that is why we use the first instance + rmesh.scale(finst->get_scaling_factor()); + rmesh.rotate_x(float(finst->get_rotation()(X))); + rmesh.rotate_y(float(finst->get_rotation()(Y))); + + // TODO export the exact 2D projection + auto p = rmesh.convex_hull(); + + p.make_clockwise(); + p.append(p.first_point()); + auto clpath = Slic3rMultiPoint_to_ClipperPath(p); + + for(ModelInstance* objinst : objptr->instances) { if(objinst) { - Slic3r::TriangleMesh tmpmesh = rmesh; ClipperLib::PolygonImpl pn; - - // CHECK_ME -> is the following correct ? - tmpmesh.scale(objinst->get_scaling_factor()); - - // TODO export the exact 2D projection - auto p = tmpmesh.convex_hull(); - - p.make_clockwise(); - p.append(p.first_point()); - pn.Contour = Slic3rMultiPoint_to_ClipperPath( p ); + pn.Contour = clpath; // Efficient conversion to item. Item item(std::move(pn)); // Invalid geometries would throw exceptions when arranging if(item.vertexCount() > 3) { - // CHECK_ME -> is the following correct or it should take in account all three rotations ? item.rotation(objinst->get_rotation(Z)); item.translation({ ClipperLib::cInt(objinst->get_offset(X)/SCALING_FACTOR), @@ -565,9 +569,10 @@ void applyResult( // appropriately auto off = item.translation(); Radians rot = item.rotation(); + Vec3d foff(off.X*SCALING_FACTOR + batch_offset, off.Y*SCALING_FACTOR, - inst_ptr->get_offset()(2)); + inst_ptr->get_offset()(Z)); // write the transformation data into the model instance inst_ptr->set_rotation(Z, rot); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index bbb3aac88..5f6be2197 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1589,6 +1589,7 @@ void Plater::priv::arrange() // Guard the arrange process arranging.store(true); + // Disable the arrange button (to prevent reentrancies, we will call wxYied) _3DScene::enable_toolbar_item(canvas3D, "arrange", can_arrange()); this->background_process.stop(); @@ -1608,7 +1609,8 @@ void Plater::priv::arrange() statusbar()->set_status_text(msg); // ok, this is dangerous, but we are protected by the atomic flag - // 'arranging'. This call is needed for the cancel button to work. + // 'arranging' and the arrange button is also disabled. + // This call is needed for the cancel button to work. wxYieldIfNeeded(); }; @@ -1657,12 +1659,11 @@ void Plater::priv::arrange() statusbar()->set_cancel_callback(); // remove cancel button arranging.store(false); - this->schedule_background_process(); - - // ignore arrange failures on purpose: user has visual feedback and we - // don't need to warn him when parts don't fit in print bed - + // We enable back the arrange button _3DScene::enable_toolbar_item(canvas3D, "arrange", can_arrange()); + + // FIXME: none of the following seem to work now. (update did the job previously) + // _3DScene::reload_scene(canvas3D, false); update(); }