Skip to content

Commit

Permalink
Fix crashing in programming cut. Also fixes the cut z offset.
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisyfox committed Nov 5, 2023
1 parent 018b274 commit 9df2cf9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
6 changes: 0 additions & 6 deletions src/libslic3r/CutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,5 @@ const ModelObjectPtrs& Cut::perform_with_groove(const Groove& groove, const Tran
return m_model.objects;
}

ModelObjectPtrs Cut::cut_horizontal(const ModelObject *object, size_t instance_idx, double z, ModelObjectCutAttributes attributes)
{
Cut cut(object, instance_idx, Geometry::translation_transform(z * Vec3d::UnitZ()), attributes);
return cut.perform_with_plane();
}

} // namespace Slic3r

2 changes: 0 additions & 2 deletions src/libslic3r/CutUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class Cut {
const ModelObjectPtrs& perform_by_contour(std::vector<Part> parts, int dowels_count);
const ModelObjectPtrs& perform_with_groove(const Groove& groove, const Transform3d& rotation_m, bool keep_as_parts = false);

static ModelObjectPtrs cut_horizontal(const ModelObject *object, size_t instance_idx, double z, ModelObjectCutAttributes attributes);

}; // namespace Cut


Expand Down
19 changes: 4 additions & 15 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8426,23 +8426,12 @@ void Plater::cut_horizontal(size_t obj_idx, size_t instance_idx, double z, Model
return;

wxBusyCursor wait;
const auto new_objects = Cut::cut_horizontal(object, instance_idx, z, attributes);

remove(obj_idx);
p->load_model_objects(new_objects);
const Vec3d instance_offset = object->instances[instance_idx]->get_offset();
Cut cut(object, instance_idx, Geometry::translation_transform(z * Vec3d::UnitZ() - instance_offset), attributes);
const auto new_objects = cut.perform_with_plane();

// now process all updates of the 3d scene
update();

// Update InfoItems in ObjectList after update() to use of a correct value of the GLCanvas3D::is_sinking(),
// which is updated after a view3D->reload_scene(false, flags & (unsigned int)UpdateParams::FORCE_FULL_SCREEN_REFRESH) call
for (size_t idx = 0; idx < p->model.objects.size(); idx++)
wxGetApp().obj_list()->update_info_items(idx);

Selection& selection = p->get_selection();
size_t last_id = p->model.objects.size() - 1;
for (size_t i = 0; i < new_objects.size(); ++i)
selection.add_object((unsigned int)(last_id - i), i == 0);
apply_cut_object_to_model(obj_idx, new_objects);
}

void Plater::_calib_pa_tower(const Calib_Params& params) {
Expand Down
4 changes: 3 additions & 1 deletion src/slic3r/Utils/CalibUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ static void cut_model(Model &model, double z, ModelObjectCutAttributes attribute

auto* object = model.objects[0];

const auto new_objects = Cut::cut_horizontal(object, instance_idx, z, attributes);
const Vec3d instance_offset = object->instances[instance_idx]->get_offset();
Cut cut(object, instance_idx, Geometry::translation_transform(z * Vec3d::UnitZ() - instance_offset), attributes);
const auto new_objects = cut.perform_with_plane();
model.delete_object(obj_idx);

for (ModelObject *model_object : new_objects) {
Expand Down

0 comments on commit 9df2cf9

Please sign in to comment.