Arrangement is still not working, update is probably broken.

This commit is contained in:
tamasmeszaros 2018-11-21 11:07:08 +01:00
parent 897ca1aa44
commit 2fffb0c2ff
2 changed files with 28 additions and 22 deletions

View File

@ -508,32 +508,36 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) {
ret.reserve(s); ret.reserve(s);
for(auto objptr : model.objects) { for(ModelObject* objptr : model.objects) {
if(objptr) { 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) { if(objinst) {
Slic3r::TriangleMesh tmpmesh = rmesh;
ClipperLib::PolygonImpl pn; ClipperLib::PolygonImpl pn;
pn.Contour = clpath;
// 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 );
// Efficient conversion to item. // Efficient conversion to item.
Item item(std::move(pn)); Item item(std::move(pn));
// Invalid geometries would throw exceptions when arranging // Invalid geometries would throw exceptions when arranging
if(item.vertexCount() > 3) { 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.rotation(objinst->get_rotation(Z));
item.translation({ item.translation({
ClipperLib::cInt(objinst->get_offset(X)/SCALING_FACTOR), ClipperLib::cInt(objinst->get_offset(X)/SCALING_FACTOR),
@ -565,9 +569,10 @@ void applyResult(
// appropriately // appropriately
auto off = item.translation(); auto off = item.translation();
Radians rot = item.rotation(); Radians rot = item.rotation();
Vec3d foff(off.X*SCALING_FACTOR + batch_offset, Vec3d foff(off.X*SCALING_FACTOR + batch_offset,
off.Y*SCALING_FACTOR, off.Y*SCALING_FACTOR,
inst_ptr->get_offset()(2)); inst_ptr->get_offset()(Z));
// write the transformation data into the model instance // write the transformation data into the model instance
inst_ptr->set_rotation(Z, rot); inst_ptr->set_rotation(Z, rot);

View File

@ -1589,6 +1589,7 @@ void Plater::priv::arrange()
// Guard the arrange process // Guard the arrange process
arranging.store(true); arranging.store(true);
// Disable the arrange button (to prevent reentrancies, we will call wxYied)
_3DScene::enable_toolbar_item(canvas3D, "arrange", can_arrange()); _3DScene::enable_toolbar_item(canvas3D, "arrange", can_arrange());
this->background_process.stop(); this->background_process.stop();
@ -1608,7 +1609,8 @@ void Plater::priv::arrange()
statusbar()->set_status_text(msg); statusbar()->set_status_text(msg);
// ok, this is dangerous, but we are protected by the atomic flag // 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(); wxYieldIfNeeded();
}; };
@ -1657,12 +1659,11 @@ void Plater::priv::arrange()
statusbar()->set_cancel_callback(); // remove cancel button statusbar()->set_cancel_callback(); // remove cancel button
arranging.store(false); arranging.store(false);
this->schedule_background_process(); // We enable back the arrange button
// 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
_3DScene::enable_toolbar_item(canvas3D, "arrange", can_arrange()); _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(); update();
} }