diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 64dc7cd1cb..bb00782599 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -716,21 +716,7 @@ void GLGizmoEmboss::volume_transformation_changed() // inform slicing process that model changed // SLA supports, processing // ensure on bed - const ModelObjectPtrs objects = m_parent.get_model()->objects; - ModelObject *object = m_volume->get_object(); - object->invalidate_bounding_box(); - object->ensure_on_bed(); - - int obj_idx = -1; - for (int i = 0; i < objects.size(); i++) - if (objects[i]->id() == object->id()) { - obj_idx = i; - break; - } - wxGetApp().plater()->changed_object(obj_idx); - - // Check outside bed - m_parent.requires_check_outside_state(); + wxGetApp().plater()->changed_object(*m_volume->get_object()); } // Show correct value of height & depth inside of inputs diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index 2064567ade..4178c75bd9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -339,21 +339,7 @@ void GLGizmoSVG::volume_transformation_changed() // inform slicing process that model changed // SLA supports, processing // ensure on bed - const ModelObjectPtrs objects = m_parent.get_model()->objects; - ModelObject *object = m_volume->get_object(); - object->invalidate_bounding_box(); - object->ensure_on_bed(); - - int obj_idx = -1; - for (int i = 0; i < objects.size(); i++) - if (objects[i]->id() == object->id()) { - obj_idx = i; - break; - } - wxGetApp().plater()->changed_object(obj_idx); - - // Check outside bed - m_parent.requires_check_outside_state(); + wxGetApp().plater()->changed_object(*m_volume->get_object()); } // Show correct value of height & depth inside of inputs @@ -716,6 +702,7 @@ void wu_draw_line_side(Linef line, } } +#ifdef MORE_DRAWING // Wu's line algorithm - https://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm void wu_draw_line(Linef line, const std::function& plot) { @@ -786,6 +773,36 @@ void wu_draw_line(Linef line, } } +void draw(const ExPolygonsWithIds &shapes_with_ids, unsigned max_size) +{ + ImVec2 actual_pos = ImGui::GetCursorPos(); + // draw shapes + BoundingBox bb; + for (const ExPolygonsWithId &shape : shapes_with_ids) + bb.merge(get_extents(shape.expoly)); + + Point bb_size = bb.size(); + double scale = max_size / (double) std::max(bb_size.x(), bb_size.y()); + ImVec2 win_offset = ImGui::GetWindowPos(); + Point offset(win_offset.x + actual_pos.x, win_offset.y + actual_pos.y); + offset += bb_size / 2 * scale; + auto draw_polygon = [&scale, offset](Slic3r::Polygon p) { + p.scale(scale, -scale); // Y mirror + p.translate(offset); + ImGuiWrapper::draw(p); + }; + + for (const ExPolygonsWithId &shape : shapes_with_ids) { + for (const ExPolygon &expoly : shape.expoly) { + draw_polygon(expoly.contour); + for (const Slic3r::Polygon &hole : expoly.holes) + draw_polygon(hole); + } + } +} + +#endif // MORE_DRAWING + template // N .. count of channels per pixel void draw_side_outline(const ExPolygons &shape, const std::array &color, std::vector &data, size_t data_width, double scale) { @@ -878,7 +895,7 @@ void draw_filled(const ExPolygons &shape, const std::array& co size_t offset = get_offset(x, y); if (data[offset + N - 1] != 0) return; // already setted by line - for (size_t i = 0; i < N; ++i) + for (int i = 0; i < N; ++i) data[offset + i] = color[i]; }; @@ -1372,35 +1389,6 @@ void GLGizmoSVG::draw_window() draw_model_type(); } } -namespace { -void draw(const ExPolygonsWithIds& shapes_with_ids, unsigned max_size) -{ - ImVec2 actual_pos = ImGui::GetCursorPos(); - // draw shapes - BoundingBox bb; - for (const ExPolygonsWithId &shape : shapes_with_ids) - bb.merge(get_extents(shape.expoly)); - - Point bb_size = bb.size(); - double scale = max_size / (double) std::max(bb_size.x(), bb_size.y()); - ImVec2 win_offset = ImGui::GetWindowPos(); - Point offset(win_offset.x + actual_pos.x, win_offset.y + actual_pos.y); - offset += bb_size / 2 * scale; - auto draw_polygon = [&scale, offset](Slic3r::Polygon p) { - p.scale(scale, -scale); // Y mirror - p.translate(offset); - ImGuiWrapper::draw(p); - }; - - for (const ExPolygonsWithId &shape : shapes_with_ids) { - for (const ExPolygon &expoly : shape.expoly) { - draw_polygon(expoly.contour); - for (const Slic3r::Polygon &hole : expoly.holes) - draw_polygon(hole); - } - } -} -} void GLGizmoSVG::draw_preview(){ // init texture when not initialized yet. diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 2565389960..08fc0501bc 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -12,6 +12,7 @@ #include // load_obj for default mesh #include // use surface cuts #include // create object +#include #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/NotificationManager.hpp" @@ -419,8 +420,6 @@ void UpdateJob::update_volume(ModelVolume *volume, TriangleMesh &&mesh, const Da volume->set_mesh(std::move(mesh)); volume->set_new_unique_id(); volume->calculate_convex_hull(); - ModelObject *object = volume->get_object(); - object->invalidate_bounding_box(); // write data from base into volume base.write(*volume); @@ -434,17 +433,15 @@ void UpdateJob::update_volume(ModelVolume *volume, TriangleMesh &&mesh, const Da update_name_in_list(*obj_list, *volume); } - // Get object id to set object as changed - Plater* plater = app.plater(); - ModelObjectPtrs objects = plater->model().objects; - int obj_idx = -1; - for (int i = 0; i < objects.size(); ++i) - if (objects[i]->id() == object->id()) { - obj_idx = i; - break; - } - assert(obj_idx >= 0); - plater->changed_object(obj_idx); + ModelObject *object = volume->get_object(); + assert(object != nullptr); + if (object == nullptr) + return; + + Plater *plater = app.plater(); + if (plater->printer_technology() == ptSLA) + sla::reproject_points_and_holes(object); + plater->changed_object(*object); } ///////////////// diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c5fb715352..bba200017f 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7815,22 +7815,35 @@ void Plater::changed_mesh(int obj_idx) p->schedule_background_process(); } +void Plater::changed_object(ModelObject &object){ + assert(object.get_model() == &p->model); // is object from same model? + object.invalidate_bounding_box(); + + // recenter and re - align to Z = 0 + object.ensure_on_bed(p->printer_technology != ptSLA); + + if (p->printer_technology == ptSLA) { + // Update the SLAPrint from the current Model, so that the reload_scene() + // pulls the correct data, update the 3D scene. + p->update_restart_background_process(true, false); + } else + p->view3D->reload_scene(false); + + // update print + p->schedule_background_process(); + + // Check outside bed + get_current_canvas3D()->requires_check_outside_state(); +} + void Plater::changed_object(int obj_idx) { if (obj_idx < 0) return; - // recenter and re - align to Z = 0 - p->model.objects[obj_idx]->ensure_on_bed(p->printer_technology != ptSLA); - if (this->p->printer_technology == ptSLA) { - // Update the SLAPrint from the current Model, so that the reload_scene() - // pulls the correct data, update the 3D scene. - this->p->update_restart_background_process(true, false); - } - else - p->view3D->reload_scene(false); - - // update print - this->p->schedule_background_process(); + ModelObject *object = p->model.objects[obj_idx]; + if (object == nullptr) + return; + changed_object(*object); } void Plater::changed_objects(const std::vector& object_idxs) diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index b311dfcd5a..46ffcefbac 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -298,6 +298,7 @@ public: void clear_before_change_mesh(int obj_idx, const std::string ¬ification_msg); void changed_mesh(int obj_idx); + void changed_object(ModelObject &object); void changed_object(int obj_idx); void changed_objects(const std::vector& object_idxs); void schedule_background_process(bool schedule = true); diff --git a/src/slic3r/GUI/SurfaceDrag.cpp b/src/slic3r/GUI/SurfaceDrag.cpp index 7f29414790..eb2e414481 100644 --- a/src/slic3r/GUI/SurfaceDrag.cpp +++ b/src/slic3r/GUI/SurfaceDrag.cpp @@ -359,16 +359,6 @@ bool face_selected_volume_to_camera(const Camera &camera, GLCanvas3D &canvas, co if (volume.type() == ModelVolumeType::MODEL_PART) object.ensure_on_bed(); - - //int obj_idx = -1; - //for (int i = 0; i < objects.size(); i++) - // if (objects[i]->id() == object.id()) { - // obj_idx = i; - // break; - // } - // object change !!! - // Plater::changed_object(obj_idx); - return true; }