diff --git a/src/libseqarrange/src/seq_interface.cpp b/src/libseqarrange/src/seq_interface.cpp index 120ec293af..e8872c80b2 100644 --- a/src/libseqarrange/src/seq_interface.cpp +++ b/src/libseqarrange/src/seq_interface.cpp @@ -177,7 +177,7 @@ bool check_ScheduledObjectsForSequentialPrintability(const SolverConfiguration std::vector > unreachable_polygons; std::map flat_index_map; - + for (unsigned int i = 0; i < objects_to_print.size(); ++i) { std::vector convex_level_polygons; @@ -210,8 +210,8 @@ bool check_ScheduledObjectsForSequentialPrintability(const SolverConfiguration scale_down_unreachable_polygons); unreachable_polygons.push_back(scale_down_unreachable_polygons); - polygons.push_back(scale_down_object_polygon); - } + polygons.push_back(scale_down_object_polygon); + } for (const auto& scheduled_plate: scheduled_plates) { @@ -228,6 +228,22 @@ bool check_ScheduledObjectsForSequentialPrintability(const SolverConfiguration { const auto& flat_index = flat_index_map.find(scheduled_object.id)->second; + assert(!objects_to_print[flat_index].pgns_at_height.empty()); + + if (!check_PolygonPositionWithinPlate(solver_configuration, + SEQ_SLICER_SCALE_FACTOR, + scheduled_object.x, + scheduled_object.y, + objects_to_print[flat_index].pgns_at_height[0].second)) + { + #ifdef DEBUG + { + printf("Object placed outside plate.\n"); + } + #endif + return false; + } + plate_polygons.push_back(polygons[flat_index]); plate_unreachable_polygons.push_back(unreachable_polygons[flat_index]); diff --git a/src/libseqarrange/src/seq_preprocess.cpp b/src/libseqarrange/src/seq_preprocess.cpp index 528ed9f0ca..f2c265c27f 100644 --- a/src/libseqarrange/src/seq_preprocess.cpp +++ b/src/libseqarrange/src/seq_preprocess.cpp @@ -694,7 +694,7 @@ void prepare_ExtruderPolygons(const SolverConfiguration &solver bool extra_safety) { for (unsigned int j = 0; j < object_to_print.pgns_at_height.size(); ++j) - { + { coord_t height = object_to_print.pgns_at_height[j].first; if (!object_to_print.pgns_at_height[j].second.points.empty()) @@ -780,14 +780,14 @@ void prepare_UnreachableZonePolygons(const SolverConfiguration std::vector &unreachable_polygons) { std::vector > scaled_unreachable_polygons; - + for (unsigned int i = 0; i < extruder_convex_level_polygons.size(); ++i) { std::vector scaled_level_unreachable_polygons; extend_PolygonConvexUnreachableZone(solver_configuration, polygon, extruder_convex_level_polygons[i], - scaled_level_unreachable_polygons); + scaled_level_unreachable_polygons); scaled_unreachable_polygons.push_back(scaled_level_unreachable_polygons); } @@ -826,19 +826,18 @@ void prepare_UnreachableZonePolygons(const SolverConfiguration { std::vector > scaled_unreachable_polygons; assert(extruder_convex_level_polygons.size() == convex_level_polygons.size()); - + for (unsigned int i = 0; i < extruder_convex_level_polygons.size(); ++i) { - std::vector scaled_level_unreachable_polygons; - extend_PolygonConvexUnreachableZone(solver_configuration, - convex_level_polygons[i], - extruder_convex_level_polygons[i], - scaled_level_unreachable_polygons); - scaled_unreachable_polygons.push_back(scaled_level_unreachable_polygons); + std::vector scaled_level_unreachable_polygons; + extend_PolygonConvexUnreachableZone(solver_configuration, + convex_level_polygons[i], + extruder_convex_level_polygons[i], + scaled_level_unreachable_polygons); + scaled_unreachable_polygons.push_back(scaled_level_unreachable_polygons); } - assert(extruder_box_level_polygons.size() == box_level_polygons.size()); - + for (unsigned int i = 0; i < extruder_box_level_polygons.size(); ++i) { std::vector scaled_level_unreachable_polygons; @@ -884,6 +883,21 @@ bool check_PolygonSizeFitToPlate(const SolverConfiguration &solver_configuration return true; } +bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configuration, coord_t x, coord_t y, const Slic3r::Polygon &polygon) +{ + BoundingBox polygon_box = get_extents(polygon); + + if (x + polygon_box.min.x() < 0 || x + polygon_box.max.x() > solver_configuration.x_plate_bounding_box_size) + { + return false; + } + if (y + polygon_box.min.y() < 0 || y + polygon_box.max.y() > solver_configuration.y_plate_bounding_box_size) + { + return false; + } + return true; +} + bool check_PolygonSizeFitToPlate(const SolverConfiguration &solver_configuration, coord_t scale_factor, const Slic3r::Polygon &polygon) { @@ -905,6 +919,31 @@ bool check_PolygonSizeFitToPlate(const SolverConfiguration &solver_configuration } +bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configuration, coord_t scale_factor, coord_t x, coord_t y, const Slic3r::Polygon &polygon) +{ + BoundingBox polygon_box = get_extents(polygon); + + #ifdef DEBUG + { + printf("x: %d,%d\n", polygon_box.min.x() + x, polygon_box.max.x() + x); + printf("y: %d,%d\n", polygon_box.min.y() + y, polygon_box.max.y() + y); + printf("X: %d\n", solver_configuration.x_plate_bounding_box_size * scale_factor); + printf("Y: %d\n", solver_configuration.y_plate_bounding_box_size * scale_factor); + } + #endif + + if (x + polygon_box.min.x() < 0 || x + polygon_box.max.x() > solver_configuration.x_plate_bounding_box_size * scale_factor) + { + return false; + } + if (y + polygon_box.min.y() < 0 || y + polygon_box.max.y() > solver_configuration.y_plate_bounding_box_size * scale_factor) + { + return false; + } + return true; +} + + /*----------------------------------------------------------------*/ bool check_PolygonConsumation(const std::vector &polygons, const std::vector &consumer_polygons) diff --git a/src/libseqarrange/src/seq_preprocess.hpp b/src/libseqarrange/src/seq_preprocess.hpp index 0aacdcb616..9cab9a7f6d 100644 --- a/src/libseqarrange/src/seq_preprocess.hpp +++ b/src/libseqarrange/src/seq_preprocess.hpp @@ -194,8 +194,10 @@ void prepare_UnreachableZonePolygons(const SolverConfiguration std::vector &unreachable_polygons); bool check_PolygonSizeFitToPlate(const SolverConfiguration &solver_configuration, const Slic3r::Polygon &polygon); +bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configuration, coord_t x, coord_t y, const Slic3r::Polygon &polygon); + bool check_PolygonSizeFitToPlate(const SolverConfiguration &solver_configuration, coord_t scale_factor, const Slic3r::Polygon &polygon); - +bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configuration, coord_t scale_factor, coord_t x, coord_t y, const Slic3r::Polygon &polygon); /*----------------------------------------------------------------*/ diff --git a/src/libseqarrange/src/seq_sequential.cpp b/src/libseqarrange/src/seq_sequential.cpp index 94fc7662c3..ef9208869e 100644 --- a/src/libseqarrange/src/seq_sequential.cpp +++ b/src/libseqarrange/src/seq_sequential.cpp @@ -9,6 +9,7 @@ */ /*================================================================*/ +#include #include #include "seq_defs.hpp" @@ -6238,6 +6239,147 @@ bool check_PointsOutsidePolygons(const std::vector const std::vector &polygons, const std::vector > &unreachable_polygons) { + #ifdef DEBUG + { + printf("Levels U %d,%d\n", unreachable_polygons[0].size(), unreachable_polygons[1].size()); + + int c = 0; + string svg_filename = "collision_checking.svg"; + SVG checking_svg(svg_filename); + + for (unsigned int i = 0; i < polygons.size() - 1; ++i) + { + Polygon display_polygon = polygons[i]; + + for (unsigned int j = 0; j < display_polygon.points.size(); ++j) + { + display_polygon.points[j] = Point(SEQ_SVG_SCALE_FACTOR * (display_polygon.points[j].x() + dec_values_X[i].as_double()), + SEQ_SVG_SCALE_FACTOR * (display_polygon.points[j].y() + dec_values_Y[i].as_double())); + } + + string color; + + switch(c % 8) + { + case 0: + { + color = "green"; + break; + } + case 1: + { + color = "blue"; + break; + } + case 2: + { + color = "red"; + break; + } + case 3: + { + color = "grey"; + break; + } + case 4: + { + color = "cyan"; + break; + } + case 5: + { + color = "magenta"; + break; + } + case 6: + { + color = "yellow"; + break; + } + case 7: + { + color = "black"; + break; + } + case 8: + { + color = "indigo"; + break; + } + } + checking_svg.draw(display_polygon, color); + ++c; + } + for (unsigned int i = 1; i < unreachable_polygons.size(); ++i) + { + for (unsigned int k = 0; k < unreachable_polygons[i].size(); ++k) + { + Polygon display_polygon = unreachable_polygons[i][k]; + + for (unsigned int j = 0; j < display_polygon.points.size(); ++j) + { + display_polygon.points[j] = Point(SEQ_SVG_SCALE_FACTOR * (display_polygon.points[j].x() + dec_values_X[i].as_double()), + SEQ_SVG_SCALE_FACTOR * (display_polygon.points[j].y() + dec_values_Y[i].as_double())); + } + + string color; + + switch(c % 8) + { + case 0: + { + color = "green"; + break; + } + case 1: + { + color = "blue"; + break; + } + case 2: + { + color = "red"; + break; + } + case 3: + { + color = "grey"; + break; + } + case 4: + { + color = "cyan"; + break; + } + case 5: + { + color = "magenta"; + break; + } + case 6: + { + color = "yellow"; + break; + } + case 7: + { + color = "black"; + break; + } + case 8: + { + color = "indigo"; + break; + } + } + checking_svg.draw(display_polygon, color); + ++c; + } + } + checking_svg.Close(); + } + #endif + if (!polygons.empty()) { for (unsigned int i = 0; i < polygons.size() - 1; ++i) @@ -6354,7 +6496,7 @@ bool check_PointsOutsidePolygons(const std::vector printf("X[i]: %.3f, Y[i]: %.3f, X[j]: %.3f, Y[j]: %.3f\n", dec_values_X[i].as_double(), dec_values_Y[i].as_double(), dec_values_X[j].as_double(), dec_values_Y[j].as_double()); printf("Outside 2: %.3f\n", outside); } - #endif + #endif if (outside > -EPSILON) { diff --git a/src/slic3r/GUI/ArrangeHelper.cpp b/src/slic3r/GUI/ArrangeHelper.cpp index e22da31724..9bcbe716e9 100644 --- a/src/slic3r/GUI/ArrangeHelper.cpp +++ b/src/slic3r/GUI/ArrangeHelper.cpp @@ -25,12 +25,12 @@ static Sequential::PrinterGeometry get_printer_geometry() { // Just hardcode MK4 geometry for now. std::vector slices; - slices.push_back(ExtruderSlice{ 0, CONVEX, { { { -5000000, -5000000 }, { 5000000, -5000000 }, { 5000000, 5000000 }, { -5000000, 5000000 } } } }); - slices.push_back(ExtruderSlice{ 3000000, CONVEX, { { { -10000000, -21000000 }, { 37000000, -21000000 }, { 37000000, 44000000 }, { -10000000, 44000000 } }, - { { -40000000, -45000000 }, { 38000000, -45000000 }, { 38000000, 20000000 }, { -40000000, 20000000 } } } }); - slices.push_back(ExtruderSlice{ 11000000, BOX, { { {-350000000, -23000000 }, {350000000, -23000000 }, {350000000, -35000000 }, {-350000000, -35000000 } } } }); - slices.push_back(ExtruderSlice{ 13000000, BOX, { { { -12000000, -350000000 }, { 9000000, -350000000 }, { 9000000, -39000000 }, { -12000000, -39000000 } }, - { { -12000000, -250000000 }, {300000000, -250000000 }, {300000000, -82000000 }, { -12000000, -82000000} } } }); + slices.push_back(ExtruderSlice{ 0, CONVEX, { { { -5000000, -5000000 }, { 5000000, -5000000 }, { 5000000, 5000000 }, { -5000000, 5000000 } } } }); + slices.push_back(ExtruderSlice{ 3000000, CONVEX, { { { -10000000, -21000000 }, { 37000000, -21000000 }, { 37000000, 44000000 }, { -10000000, 44000000 } }, + { { -40000000, -45000000 }, { 38000000, -45000000 }, { 38000000, 20000000 }, { -40000000, 20000000 } } } }); + slices.push_back(ExtruderSlice{ 11000000, BOX, { { {-350000000, -23000000 }, { 350000000, -23000000 }, { 350000000, -35000000 }, {-350000000, -35000000 } } } }); + slices.push_back(ExtruderSlice{ 13000000, BOX, { { { -13000000, -84000000 }, { 11000000, -84000000 }, { 11000000, -38000000 }, { -13000000, -38000000 } }, + { { 11000000, -300000000 }, { 300000000, -300000000 }, { 300000000, -84000000 }, { 11000000, -84000000 } } } }); // Geometry (simplified head model) for the MK3S printer