mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-10 16:27:54 -06:00
Merge remote-tracking branch 'origin/master' into ys_ph_printers
This commit is contained in:
commit
f138978fe7
51 changed files with 2297 additions and 917 deletions
66
deps/CMakeLists.txt
vendored
66
deps/CMakeLists.txt
vendored
|
@ -129,19 +129,6 @@ else()
|
|||
include("deps-linux.cmake")
|
||||
endif()
|
||||
|
||||
# Patch the boost::polygon library with a custom one.
|
||||
ExternalProject_Add(dep_boost_polygon
|
||||
EXCLUDE_FROM_ALL ON
|
||||
GIT_REPOSITORY "https://github.com/prusa3d/polygon"
|
||||
GIT_TAG prusaslicer_gmp
|
||||
DEPENDS dep_boost
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/dep_boost_polygon-prefix/src/dep_boost_polygon/include/boost/polygon"
|
||||
"${DESTDIR}/usr/local/include/boost/polygon"
|
||||
)
|
||||
|
||||
set(ZLIB_PKG "")
|
||||
if (NOT ZLIB_FOUND)
|
||||
include(ZLIB/ZLIB.cmake)
|
||||
|
@ -170,19 +157,14 @@ if (NOT "${ZLIB_PKG}" STREQUAL "")
|
|||
add_dependencies(dep_openexr ${ZLIB_PKG})
|
||||
endif ()
|
||||
|
||||
if (MSVC)
|
||||
|
||||
add_custom_target(deps ALL
|
||||
DEPENDS
|
||||
set(_dep_list
|
||||
dep_boost
|
||||
dep_boost_polygon
|
||||
dep_tbb
|
||||
dep_libcurl
|
||||
dep_wxWidgets
|
||||
dep_gtest
|
||||
dep_cereal
|
||||
dep_nlopt
|
||||
# dep_qhull # Experimental
|
||||
dep_openvdb
|
||||
dep_OpenCSG
|
||||
dep_CGAL
|
||||
|
@ -191,29 +173,33 @@ if (MSVC)
|
|||
${EXPAT_PKG}
|
||||
)
|
||||
|
||||
else()
|
||||
|
||||
add_custom_target(deps ALL
|
||||
DEPENDS
|
||||
dep_boost
|
||||
dep_boost_polygon
|
||||
dep_tbb
|
||||
dep_libcurl
|
||||
dep_wxWidgets
|
||||
dep_gtest
|
||||
dep_cereal
|
||||
dep_nlopt
|
||||
dep_qhull
|
||||
dep_openvdb
|
||||
dep_OpenCSG
|
||||
dep_CGAL
|
||||
${PNG_PKG}
|
||||
${ZLIB_PKG}
|
||||
${EXPAT_PKG}
|
||||
# dep_libigl # Not working, static build has different Eigen
|
||||
if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
|
||||
# Patch the boost::polygon library with a custom one.
|
||||
ExternalProject_Add(dep_boost_polygon
|
||||
EXCLUDE_FROM_ALL ON
|
||||
GIT_REPOSITORY "https://github.com/prusa3d/polygon"
|
||||
GIT_TAG prusaslicer_gmp
|
||||
DEPENDS dep_boost
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/dep_boost_polygon-prefix/src/dep_boost_polygon/include/boost/polygon"
|
||||
"${DESTDIR}/usr/local/include/boost/polygon"
|
||||
)
|
||||
|
||||
# Only override boost::Polygon Voronoi implementation with Vojtech's GMP hacks on 64bit platforms.
|
||||
list(APPEND _dep_list "dep_boost_polygon")
|
||||
endif ()
|
||||
|
||||
if (MSVC)
|
||||
# Experimental
|
||||
#list(APPEND _dep_list "dep_qhull")
|
||||
else()
|
||||
list(APPEND _dep_list "dep_qhull")
|
||||
# Not working, static build has different Eigen
|
||||
#list(APPEND _dep_list "dep_libigl")
|
||||
endif()
|
||||
|
||||
add_custom_target(deps ALL DEPENDS ${_dep_list})
|
||||
|
||||
# Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands
|
||||
# because they seem to generate bogus build files (possibly a bug in ExternalProject).
|
||||
|
|
2
deps/deps-macos.cmake
vendored
2
deps/deps-macos.cmake
vendored
|
@ -9,6 +9,8 @@ set(DEP_CMAKE_OPTS
|
|||
"-DCMAKE_OSX_DEPLOYMENT_TARGET=${DEP_OSX_TARGET}"
|
||||
"-DCMAKE_CXX_FLAGS=${DEP_WERRORS_SDK}"
|
||||
"-DCMAKE_C_FLAGS=${DEP_WERRORS_SDK}"
|
||||
"-DCMAKE_FIND_FRAMEWORK=LAST"
|
||||
"-DCMAKE_FIND_APPBUNDLE=LAST"
|
||||
)
|
||||
|
||||
include("deps-unix-common.cmake")
|
||||
|
|
|
@ -53,7 +53,7 @@ void BridgeDetector::initialize()
|
|||
this->_edges = intersection_pl(to_polylines(grown), contours);
|
||||
|
||||
#ifdef SLIC3R_DEBUG
|
||||
printf(" bridge has " PRINTF_ZU " support(s)\n", this->_edges.size());
|
||||
printf(" bridge has %zu support(s)\n", this->_edges.size());
|
||||
#endif
|
||||
|
||||
// detect anchors as intersection between our bridge expolygon and the lower slices
|
||||
|
|
|
@ -194,6 +194,7 @@ add_library(libslic3r STATIC
|
|||
MTUtils.hpp
|
||||
VoronoiOffset.cpp
|
||||
VoronoiOffset.hpp
|
||||
VoronoiVisualUtils.hpp
|
||||
Zipper.hpp
|
||||
Zipper.cpp
|
||||
MinAreaBoundingBox.hpp
|
||||
|
|
|
@ -1586,12 +1586,17 @@ std::vector<std::pair<EdgeGrid::Grid::ContourEdge, EdgeGrid::Grid::ContourEdge>>
|
|||
++ cnt;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<EdgeGrid::Grid::ContourEdge, EdgeGrid::Grid::ContourEdge>> out;
|
||||
if (cnt > 0) {
|
||||
len /= double(cnt);
|
||||
bbox.offset(20);
|
||||
EdgeGrid::Grid grid;
|
||||
grid.set_bbox(bbox);
|
||||
grid.create(polygons, len);
|
||||
return grid.intersecting_edges();
|
||||
out = grid.intersecting_edges();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Find all pairs of intersectiong edges from the set of polygons, highlight them in an SVG.
|
||||
|
|
|
@ -404,7 +404,7 @@ void ExPolygon::triangulate_pp(Polygons* polygons) const
|
|||
{
|
||||
TPPLPoly p;
|
||||
p.Init(int(ex->contour.points.size()));
|
||||
//printf(PRINTF_ZU "\n0\n", ex->contour.points.size());
|
||||
//printf("%zu\n0\n", ex->contour.points.size());
|
||||
for (const Point &point : ex->contour.points) {
|
||||
size_t i = &point - &ex->contour.points.front();
|
||||
p[i].x = point(0);
|
||||
|
@ -419,7 +419,7 @@ void ExPolygon::triangulate_pp(Polygons* polygons) const
|
|||
for (Polygons::const_iterator hole = ex->holes.begin(); hole != ex->holes.end(); ++hole) {
|
||||
TPPLPoly p;
|
||||
p.Init(hole->points.size());
|
||||
//printf(PRINTF_ZU "\n1\n", hole->points.size());
|
||||
//printf("%zu\n1\n", hole->points.size());
|
||||
for (const Point &point : hole->points) {
|
||||
size_t i = &point - &hole->points.front();
|
||||
p[i].x = point(0);
|
||||
|
|
|
@ -312,8 +312,8 @@ std::string ExtrusionEntity::role_to_string(ExtrusionRole role)
|
|||
case erOverhangPerimeter : return L("Overhang perimeter");
|
||||
case erInternalInfill : return L("Internal infill");
|
||||
case erSolidInfill : return L("Solid infill");
|
||||
case erIroning : return L("Ironing");
|
||||
case erTopSolidInfill : return L("Top solid infill");
|
||||
case erIroning : return L("Ironing");
|
||||
case erBridgeInfill : return L("Bridge infill");
|
||||
case erGapFill : return L("Gap fill");
|
||||
case erSkirt : return L("Skirt");
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "../GCode.hpp"
|
||||
#include "../Geometry.hpp"
|
||||
#include "../GCode/ThumbnailData.hpp"
|
||||
#include "../Time.hpp"
|
||||
|
||||
#include "../I18N.hpp"
|
||||
|
||||
|
@ -1991,7 +1992,7 @@ namespace Slic3r {
|
|||
bool _add_content_types_file_to_archive(mz_zip_archive& archive);
|
||||
bool _add_thumbnail_file_to_archive(mz_zip_archive& archive, const ThumbnailData& thumbnail_data);
|
||||
bool _add_relationships_file_to_archive(mz_zip_archive& archive);
|
||||
bool _add_model_file_to_archive(mz_zip_archive& archive, const Model& model, IdToObjectDataMap &objects_data);
|
||||
bool _add_model_file_to_archive(const std::string& filename, mz_zip_archive& archive, const Model& model, IdToObjectDataMap& objects_data);
|
||||
bool _add_object_to_model_stream(std::stringstream& stream, unsigned int& object_id, ModelObject& object, BuildItemsList& build_items, VolumeToOffsetsMap& volumes_offsets);
|
||||
bool _add_mesh_to_object_stream(std::stringstream& stream, ModelObject& object, VolumeToOffsetsMap& volumes_offsets);
|
||||
bool _add_build_to_model_stream(std::stringstream& stream, const BuildItemsList& build_items);
|
||||
|
@ -2054,7 +2055,7 @@ namespace Slic3r {
|
|||
// Adds model file ("3D/3dmodel.model").
|
||||
// This is the one and only file that contains all the geometry (vertices and triangles) of all ModelVolumes.
|
||||
IdToObjectDataMap objects_data;
|
||||
if (!_add_model_file_to_archive(archive, model, objects_data))
|
||||
if (!_add_model_file_to_archive(filename, archive, model, objects_data))
|
||||
{
|
||||
close_zip_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
|
@ -2203,7 +2204,7 @@ namespace Slic3r {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool _3MF_Exporter::_add_model_file_to_archive(mz_zip_archive& archive, const Model& model, IdToObjectDataMap &objects_data)
|
||||
bool _3MF_Exporter::_add_model_file_to_archive(const std::string& filename, mz_zip_archive& archive, const Model& model, IdToObjectDataMap& objects_data)
|
||||
{
|
||||
std::stringstream stream;
|
||||
// https://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10
|
||||
|
@ -2214,6 +2215,19 @@ namespace Slic3r {
|
|||
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
stream << "<" << MODEL_TAG << " unit=\"millimeter\" xml:lang=\"en-US\" xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\" xmlns:slic3rpe=\"http://schemas.slic3r.org/3mf/2017/06\">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"" << SLIC3RPE_3MF_VERSION << "\">" << VERSION_3MF << "</" << METADATA_TAG << ">\n";
|
||||
std::string name = boost::filesystem::path(filename).stem().string();
|
||||
stream << " <" << METADATA_TAG << " name=\"Title\">" << name << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Designer\">" << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Description\">" << name << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Copyright\">" << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"LicenseTerms\">" << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Rating\">" << "</" << METADATA_TAG << ">\n";
|
||||
std::string date = Slic3r::Utils::utc_timestamp(Slic3r::Utils::get_current_time_utc());
|
||||
// keep only the date part of the string
|
||||
date = date.substr(0, 10);
|
||||
stream << " <" << METADATA_TAG << " name=\"CreationDate\">" << date << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"ModificationDate\">" << date << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Application\">" << SLIC3R_APP_KEY << "-" << SLIC3R_VERSION << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << RESOURCES_TAG << ">\n";
|
||||
|
||||
// Instance transformations, indexed by the 3MF object ID (which is a linear serialization of all instances of all ModelObjects).
|
||||
|
|
|
@ -1218,7 +1218,7 @@ bool store_amf(const char* path, Model* model, const DynamicPrintConfig* config,
|
|||
for (ModelInstance *instance : object->instances) {
|
||||
char buf[512];
|
||||
sprintf(buf,
|
||||
" <instance objectid=\"" PRINTF_ZU "\">\n"
|
||||
" <instance objectid=\"%zu\">\n"
|
||||
" <deltax>%lf</deltax>\n"
|
||||
" <deltay>%lf</deltay>\n"
|
||||
" <deltaz>%lf</deltaz>\n"
|
||||
|
|
|
@ -617,6 +617,15 @@ std::vector<GCode::LayerToPrint> GCode::collect_layers_to_print(const PrintObjec
|
|||
|
||||
layers_to_print.emplace_back(layer_to_print);
|
||||
|
||||
bool has_extrusions = (layer_to_print.object_layer && layer_to_print.object_layer->has_extrusions())
|
||||
|| (layer_to_print.support_layer && layer_to_print.support_layer->has_extrusions());
|
||||
|
||||
// Check that there are extrusions on the very first layer.
|
||||
if (layers_to_print.size() == 1u) {
|
||||
if (! has_extrusions)
|
||||
throw std::runtime_error(_(L("There is an object with no extrusions on the first layer.")));
|
||||
}
|
||||
|
||||
// In case there are extrusions on this layer, check there is a layer to lay it on.
|
||||
if ((layer_to_print.object_layer && layer_to_print.object_layer->has_extrusions())
|
||||
// Allow empty support layers, as the support generator may produce no extrusions for non-empty support regions.
|
||||
|
@ -630,17 +639,17 @@ std::vector<GCode::LayerToPrint> GCode::collect_layers_to_print(const PrintObjec
|
|||
// Negative support_contact_z is not taken into account, it can result in false positives in cases
|
||||
// where previous layer has object extrusions too (https://github.com/prusa3d/PrusaSlicer/issues/2752)
|
||||
|
||||
// Only check this layer in case it has some extrusions.
|
||||
bool has_extrusions = (layer_to_print.object_layer && layer_to_print.object_layer->has_extrusions())
|
||||
|| (layer_to_print.support_layer && layer_to_print.support_layer->has_extrusions());
|
||||
|
||||
if (has_extrusions && layer_to_print.print_z() > maximal_print_z + 2. * EPSILON)
|
||||
throw std::runtime_error(_(L("Empty layers detected, the output would not be printable.")) + "\n\n" +
|
||||
if (has_extrusions && layer_to_print.print_z() > maximal_print_z + 2. * EPSILON) {
|
||||
const_cast<Print*>(object.print())->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL,
|
||||
_(L("Empty layers detected, the output would not be printable.")) + "\n\n" +
|
||||
_(L("Object name")) + ": " + object.model_object()->name + "\n" + _(L("Print z")) + ": " +
|
||||
std::to_string(layers_to_print.back().print_z()) + "\n\n" + _(L("This is "
|
||||
"usually caused by negligibly small extrusions or by a faulty model. Try to repair "
|
||||
"the model or change its orientation on the bed.")));
|
||||
}
|
||||
|
||||
// Remember last layer with extrusions.
|
||||
if (has_extrusions)
|
||||
last_extrusion_layer = &layers_to_print.back();
|
||||
}
|
||||
}
|
||||
|
@ -1939,7 +1948,6 @@ void GCode::process_layer(
|
|||
const size_t single_object_instance_idx)
|
||||
{
|
||||
assert(! layers.empty());
|
||||
// assert(! layer_tools.extruders.empty());
|
||||
// Either printing all copies of all objects, or just a single copy of a single object.
|
||||
assert(single_object_instance_idx == size_t(-1) || layers.size() == 1);
|
||||
|
||||
|
|
|
@ -393,7 +393,7 @@ GCodeSender::on_read(const boost::system::error_code& error,
|
|||
}
|
||||
this->send();
|
||||
} else {
|
||||
printf("Cannot resend " PRINTF_ZU " (oldest we have is " PRINTF_ZU ")\n", toresend, this->sent - this->last_sent.size());
|
||||
printf("Cannot resend %zu (oldest we have is %zu)\n", toresend, this->sent - this->last_sent.size());
|
||||
}
|
||||
} else if (boost::starts_with(line, "wait")) {
|
||||
// ignore
|
||||
|
|
|
@ -471,7 +471,7 @@ Pointfs arrange(size_t num_parts, const Vec2d &part_size, coordf_t gap, const Bo
|
|||
size_t cellw = size_t(floor((bed_bbox.size()(0) + gap) / cell_size(0)));
|
||||
size_t cellh = size_t(floor((bed_bbox.size()(1) + gap) / cell_size(1)));
|
||||
if (num_parts > cellw * cellh)
|
||||
throw std::invalid_argument(PRINTF_ZU " parts won't fit in your print area!\n", num_parts);
|
||||
throw std::invalid_argument("%zu parts won't fit in your print area!\n", num_parts);
|
||||
|
||||
// Get a bounding box of cellw x cellh cells, centered at the center of the bed.
|
||||
Vec2d cells_size(cellw * cell_size(0) - gap, cellh * cell_size(1) - gap);
|
||||
|
|
|
@ -115,32 +115,94 @@ inline bool segment_segment_intersection(const Vec2d &p1, const Vec2d &v1, const
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline int segments_could_intersect(
|
||||
inline bool segments_intersect(
|
||||
const Slic3r::Point &ip1, const Slic3r::Point &ip2,
|
||||
const Slic3r::Point &jp1, const Slic3r::Point &jp2)
|
||||
{
|
||||
assert(ip1 != ip2);
|
||||
assert(jp1 != jp2);
|
||||
|
||||
auto segments_could_intersect = [](
|
||||
const Slic3r::Point &ip1, const Slic3r::Point &ip2,
|
||||
const Slic3r::Point &jp1, const Slic3r::Point &jp2) -> std::pair<int, int>
|
||||
{
|
||||
Vec2i64 iv = (ip2 - ip1).cast<int64_t>();
|
||||
Vec2i64 vij1 = (jp1 - ip1).cast<int64_t>();
|
||||
Vec2i64 vij2 = (jp2 - ip1).cast<int64_t>();
|
||||
int64_t tij1 = cross2(iv, vij1);
|
||||
int64_t tij2 = cross2(iv, vij2);
|
||||
int sij1 = (tij1 > 0) ? 1 : ((tij1 < 0) ? -1 : 0); // signum
|
||||
int sij2 = (tij2 > 0) ? 1 : ((tij2 < 0) ? -1 : 0);
|
||||
return sij1 * sij2;
|
||||
return std::make_pair(
|
||||
// signum
|
||||
(tij1 > 0) ? 1 : ((tij1 < 0) ? -1 : 0),
|
||||
(tij2 > 0) ? 1 : ((tij2 < 0) ? -1 : 0));
|
||||
};
|
||||
|
||||
std::pair<int, int> sign1 = segments_could_intersect(ip1, ip2, jp1, jp2);
|
||||
std::pair<int, int> sign2 = segments_could_intersect(jp1, jp2, ip1, ip2);
|
||||
int test1 = sign1.first * sign1.second;
|
||||
int test2 = sign2.first * sign2.second;
|
||||
if (test1 <= 0 && test2 <= 0) {
|
||||
// The segments possibly intersect. They may also be collinear, but not intersect.
|
||||
if (test1 != 0 || test2 != 0)
|
||||
// Certainly not collinear, then the segments intersect.
|
||||
return true;
|
||||
// If the first segment is collinear with the other, the other is collinear with the first segment.
|
||||
assert((sign1.first == 0 && sign1.second == 0) == (sign2.first == 0 && sign2.second == 0));
|
||||
if (sign1.first == 0 && sign1.second == 0) {
|
||||
// The segments are certainly collinear. Now verify whether they overlap.
|
||||
Slic3r::Point vi = ip2 - ip1;
|
||||
// Project both on the longer coordinate of vi.
|
||||
int axis = std::abs(vi.x()) > std::abs(vi.y()) ? 0 : 1;
|
||||
coord_t i = ip1(axis);
|
||||
coord_t j = ip2(axis);
|
||||
coord_t k = jp1(axis);
|
||||
coord_t l = jp2(axis);
|
||||
if (i > j)
|
||||
std::swap(i, j);
|
||||
if (k > l)
|
||||
std::swap(k, l);
|
||||
return (k >= i && k <= j) || (i >= k && i <= l);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool segments_intersect(
|
||||
const Slic3r::Point &ip1, const Slic3r::Point &ip2,
|
||||
const Slic3r::Point &jp1, const Slic3r::Point &jp2)
|
||||
template<typename T> inline T foot_pt(const T &line_pt, const T &line_dir, const T &pt)
|
||||
{
|
||||
return segments_could_intersect(ip1, ip2, jp1, jp2) <= 0 &&
|
||||
segments_could_intersect(jp1, jp2, ip1, ip2) <= 0;
|
||||
T v = pt - line_pt;
|
||||
auto l2 = line_dir.squaredNorm();
|
||||
auto t = (l2 == 0) ? 0 : v.dot(line_dir) / l2;
|
||||
return line_pt + line_dir * t;
|
||||
}
|
||||
|
||||
inline Vec2d foot_pt(const Line &iline, const Point &ipt)
|
||||
{
|
||||
return foot_pt<Vec2d>(iline.a.cast<double>(), (iline.b - iline.a).cast<double>(), ipt.cast<double>());
|
||||
}
|
||||
|
||||
template<typename T> inline auto ray_point_distance_squared(const T &ray_pt, const T &ray_dir, const T &pt)
|
||||
{
|
||||
return (foot_pt(ray_pt, ray_dir, pt) - pt).squaredNorm();
|
||||
}
|
||||
|
||||
template<typename T> inline auto ray_point_distance(const T &ray_pt, const T &ray_dir, const T &pt)
|
||||
{
|
||||
return (foot_pt(ray_pt, ray_dir, pt) - pt).norm();
|
||||
}
|
||||
|
||||
inline double ray_point_distance_squared(const Line &iline, const Point &ipt)
|
||||
{
|
||||
return (foot_pt(iline, ipt) - ipt.cast<double>()).squaredNorm();
|
||||
}
|
||||
|
||||
inline double ray_point_distance(const Line &iline, const Point &ipt)
|
||||
{
|
||||
return (foot_pt(iline, ipt) - ipt.cast<double>()).norm();
|
||||
}
|
||||
|
||||
// Based on Liang-Barsky function by Daniel White @ http://www.skytopia.com/project/articles/compsci/clipping.html
|
||||
template<typename T>
|
||||
bool liang_barsky_line_clipping(
|
||||
inline bool liang_barsky_line_clipping(
|
||||
// Start and end points of the source line, result will be stored there as well.
|
||||
Eigen::Matrix<T, 2, 1, Eigen::DontAlign> &x0,
|
||||
Eigen::Matrix<T, 2, 1, Eigen::DontAlign> &x1,
|
||||
|
|
|
@ -264,7 +264,7 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly
|
|||
this->flow(frInfill, true).scaled_width()
|
||||
);
|
||||
#ifdef SLIC3R_DEBUG
|
||||
printf("Processing bridge at layer " PRINTF_ZU ":\n", this->layer()->id());
|
||||
printf("Processing bridge at layer %zu:\n", this->layer()->id());
|
||||
#endif
|
||||
double custom_angle = Geometry::deg2rad(this->region()->config().bridge_angle.value);
|
||||
if (bd.detect_angle(custom_angle)) {
|
||||
|
|
|
@ -135,4 +135,4 @@ BoundingBox get_extents(const Lines &lines)
|
|||
return bbox;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -103,7 +103,7 @@ public:
|
|||
Vec3d b;
|
||||
};
|
||||
|
||||
extern BoundingBox get_extents(const Lines &lines);
|
||||
BoundingBox get_extents(const Lines &lines);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
|
@ -125,4 +125,4 @@ namespace boost { namespace polygon {
|
|||
} }
|
||||
// end Boost
|
||||
|
||||
#endif
|
||||
#endif // slic3r_Line_hpp_
|
||||
|
|
|
@ -153,9 +153,11 @@ inline Lines to_lines(const Polygon &poly)
|
|||
{
|
||||
Lines lines;
|
||||
lines.reserve(poly.points.size());
|
||||
if (poly.points.size() > 2) {
|
||||
for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
|
||||
lines.push_back(Line(*it, *(it + 1)));
|
||||
lines.push_back(Line(poly.points.back(), poly.points.front()));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
|
|
@ -395,6 +395,13 @@ public:
|
|||
const PrintObjectPtrs& objects() const { return m_objects; }
|
||||
PrintObject* get_object(size_t idx) { return m_objects[idx]; }
|
||||
const PrintObject* get_object(size_t idx) const { return m_objects[idx]; }
|
||||
// PrintObject by its ObjectID, to be used to uniquely bind slicing warnings to their source PrintObjects
|
||||
// in the notification center.
|
||||
const PrintObject* get_object(ObjectID object_id) const {
|
||||
auto it = std::find_if(m_objects.begin(), m_objects.end(),
|
||||
[object_id](const PrintObject *obj) { return *static_cast<const ObjectID*>(obj) == object_id; });
|
||||
return (it == m_objects.end()) ? nullptr : *it;
|
||||
}
|
||||
const PrintRegionPtrs& regions() const { return m_regions; }
|
||||
// How many of PrintObject::copies() over all print objects are there?
|
||||
// If zero, then the print is empty and the print shall not be executed.
|
||||
|
|
|
@ -88,6 +88,14 @@ std::string PrintBase::output_filepath(const std::string &path, const std::strin
|
|||
return path;
|
||||
}
|
||||
|
||||
void PrintBase::status_update_warnings(ObjectID object_id, int step, PrintStateBase::WarningLevel /* warning_level */, const std::string &message)
|
||||
{
|
||||
if (this->m_status_callback)
|
||||
m_status_callback(SlicingStatus(*this, step));
|
||||
else if (! message.empty())
|
||||
printf("%s warning: %s\n", (object_id == ObjectID(*this)) ? "print" : "print object", message.c_str());
|
||||
}
|
||||
|
||||
tbb::mutex& PrintObjectBase::state_mutex(PrintBase *print)
|
||||
{
|
||||
return print->state_mutex();
|
||||
|
@ -98,4 +106,9 @@ std::function<void()> PrintObjectBase::cancel_callback(PrintBase *print)
|
|||
return print->cancel_callback();
|
||||
}
|
||||
|
||||
void PrintObjectBase::status_update_warnings(PrintBase *print, int step, PrintStateBase::WarningLevel warning_level, const std::string &message)
|
||||
{
|
||||
print->status_update_warnings(*this, step, warning_level, message);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#endif
|
||||
#include "tbb/mutex.h"
|
||||
|
||||
#include "ObjectID.hpp"
|
||||
#include "Model.hpp"
|
||||
#include "PlaceholderParser.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
|
@ -32,6 +33,11 @@ public:
|
|||
DONE,
|
||||
};
|
||||
|
||||
enum class WarningLevel {
|
||||
NON_CRITICAL,
|
||||
CRITICAL
|
||||
};
|
||||
|
||||
typedef size_t TimeStamp;
|
||||
|
||||
// A new unique timestamp is being assigned to the step every time the step changes its state.
|
||||
|
@ -42,6 +48,28 @@ public:
|
|||
TimeStamp timestamp;
|
||||
};
|
||||
|
||||
struct Warning
|
||||
{
|
||||
// Critical warnings will be displayed on G-code export in a modal dialog, so that the user cannot miss them.
|
||||
WarningLevel level;
|
||||
// If the warning is not current, then it is in an unknown state. It may or may not be valid.
|
||||
// A current warning will become non-current if its milestone gets invalidated.
|
||||
// A non-current warning will either become current or it will be removed at the end of a milestone.
|
||||
bool current;
|
||||
// Message to be shown to the user, UTF8, localized.
|
||||
std::string message;
|
||||
// If message_id == 0, then the message is expected to identify the warning uniquely.
|
||||
// Otherwise message_id identifies the message. For example, if the message contains a varying number, then
|
||||
// it cannot itself identify the message type.
|
||||
int message_id;
|
||||
};
|
||||
|
||||
struct StateWithWarnings : public StateWithTimeStamp
|
||||
{
|
||||
void mark_warnings_non_current() { for (auto &w : warnings) w.current = false; }
|
||||
std::vector<Warning> warnings;
|
||||
};
|
||||
|
||||
protected:
|
||||
//FIXME last timestamp is shared between Print & SLAPrint,
|
||||
// and if multiple Print or SLAPrint instances are executed in parallel, modification of g_last_timestamp
|
||||
|
@ -62,6 +90,12 @@ public:
|
|||
return state;
|
||||
}
|
||||
|
||||
StateWithWarnings state_with_warnings(StepType step, tbb::mutex &mtx) const {
|
||||
tbb::mutex::scoped_lock lock(mtx);
|
||||
StateWithWarnings state = m_state[step];
|
||||
return state;
|
||||
}
|
||||
|
||||
bool is_started(StepType step, tbb::mutex &mtx) const {
|
||||
return this->state_with_timestamp(step, mtx).state == STARTED;
|
||||
}
|
||||
|
@ -91,24 +125,53 @@ public:
|
|||
tbb::mutex::scoped_lock lock(mtx);
|
||||
// If canceled, throw before changing the step state.
|
||||
throw_if_canceled();
|
||||
#ifndef NDEBUG
|
||||
// The following test is not necessarily valid after the background processing thread
|
||||
// is stopped with throw_if_canceled(), as the CanceledException is not being catched
|
||||
// by the Print or PrintObject to update m_step_active or m_state[...].state.
|
||||
// This should not be a problem as long as the caller calls set_started() / set_done() /
|
||||
// active_step_add_warning() consistently. From the robustness point of view it would be
|
||||
// be better to catch CanceledException and do the updates. From the performance point of view,
|
||||
// the current implementation is optimal.
|
||||
//
|
||||
// assert(m_step_active == -1);
|
||||
// for (int i = 0; i < int(COUNT); ++ i)
|
||||
// assert(m_state[i].state != STARTED);
|
||||
#endif // NDEBUG
|
||||
if (m_state[step].state == DONE)
|
||||
return false;
|
||||
m_state[step].state = STARTED;
|
||||
m_state[step].timestamp = ++ g_last_timestamp;
|
||||
PrintStateBase::StateWithWarnings &state = m_state[step];
|
||||
state.state = STARTED;
|
||||
state.timestamp = ++ g_last_timestamp;
|
||||
state.mark_warnings_non_current();
|
||||
m_step_active = static_cast<int>(step);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set the step as done. Block on mutex while the Print / PrintObject / PrintRegion objects are being
|
||||
// modified by the UI thread.
|
||||
// Return value:
|
||||
// Timestamp when this stepentered the DONE state.
|
||||
// bool indicates whether the UI has to update the slicing warnings of this step or not.
|
||||
template<typename ThrowIfCanceled>
|
||||
TimeStamp set_done(StepType step, tbb::mutex &mtx, ThrowIfCanceled throw_if_canceled) {
|
||||
std::pair<TimeStamp, bool> set_done(StepType step, tbb::mutex &mtx, ThrowIfCanceled throw_if_canceled) {
|
||||
tbb::mutex::scoped_lock lock(mtx);
|
||||
// If canceled, throw before changing the step state.
|
||||
throw_if_canceled();
|
||||
assert(m_state[step].state != DONE);
|
||||
m_state[step].state = DONE;
|
||||
m_state[step].timestamp = ++ g_last_timestamp;
|
||||
return m_state[step].timestamp;
|
||||
assert(m_state[step].state == STARTED);
|
||||
assert(m_step_active == static_cast<int>(step));
|
||||
PrintStateBase::StateWithWarnings &state = m_state[step];
|
||||
state.state = DONE;
|
||||
state.timestamp = ++ g_last_timestamp;
|
||||
m_step_active = -1;
|
||||
// Remove all non-current warnings.
|
||||
auto it = std::remove_if(state.warnings.begin(), state.warnings.end(), [](const auto &w) { return ! w.current; });
|
||||
bool update_warning_ui = false;
|
||||
if (it != state.warnings.end()) {
|
||||
state.warnings.erase(it, state.warnings.end());
|
||||
update_warning_ui = true;
|
||||
}
|
||||
return std::make_pair(state.timestamp, update_warning_ui);
|
||||
}
|
||||
|
||||
// Make the step invalid.
|
||||
|
@ -124,13 +187,18 @@ public:
|
|||
printf("Not held!\n");
|
||||
}
|
||||
#endif
|
||||
m_state[step].state = INVALID;
|
||||
m_state[step].timestamp = ++ g_last_timestamp;
|
||||
PrintStateBase::StateWithWarnings &state = m_state[step];
|
||||
state.state = INVALID;
|
||||
state.timestamp = ++ g_last_timestamp;
|
||||
// Raise the mutex, so that the following cancel() callback could cancel
|
||||
// the background processing.
|
||||
// Internally the cancel() callback shall unlock the PrintBase::m_status_mutex to let
|
||||
// the working thread to proceed.
|
||||
// the working thread proceed.
|
||||
cancel();
|
||||
// Now the worker thread should be stopped, therefore it cannot write into the warnings field.
|
||||
// It is safe to modify it.
|
||||
state.mark_warnings_non_current();
|
||||
m_step_active = -1;
|
||||
}
|
||||
return invalidated;
|
||||
}
|
||||
|
@ -157,6 +225,11 @@ public:
|
|||
// Internally the cancel() callback shall unlock the PrintBase::m_status_mutex to let
|
||||
// the working thread to proceed.
|
||||
cancel();
|
||||
// Now the worker thread should be stopped, therefore it cannot write into the warnings field.
|
||||
// It is safe to modify the warnings.
|
||||
for (StepTypeIterator it = step_begin; it != step_end; ++ it)
|
||||
m_state[*it].mark_warnings_non_current();
|
||||
m_step_active = -1;
|
||||
}
|
||||
return invalidated;
|
||||
}
|
||||
|
@ -176,18 +249,62 @@ public:
|
|||
state.timestamp = ++ g_last_timestamp;
|
||||
}
|
||||
}
|
||||
if (invalidated)
|
||||
if (invalidated) {
|
||||
cancel();
|
||||
// Now the worker thread should be stopped, therefore it cannot write into the warnings field.
|
||||
// It is safe to modify the warnings.
|
||||
for (size_t i = 0; i < COUNT; ++ i)
|
||||
m_state[i].mark_warnings_non_current();
|
||||
m_step_active = -1;
|
||||
}
|
||||
return invalidated;
|
||||
}
|
||||
|
||||
// Update list of warnings of the current milestone with a new warning.
|
||||
// The warning may already exist in the list, marked as current or not current.
|
||||
// If it already exists, mark it as current.
|
||||
// Return value:
|
||||
// Current milestone (StepType).
|
||||
// bool indicates whether the UI has to be updated or not.
|
||||
std::pair<StepType, bool> active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id, tbb::mutex &mtx)
|
||||
{
|
||||
tbb::mutex::scoped_lock lock(mtx);
|
||||
assert(m_step_active != -1);
|
||||
StateWithWarnings &state = m_state[m_step_active];
|
||||
assert(state.state == STARTED);
|
||||
std::pair<StepType, bool> retval(static_cast<StepType>(m_step_active), true);
|
||||
// Does a warning of the same level and message or message_id exist already?
|
||||
auto it = (message_id == 0) ?
|
||||
std::find_if(state.warnings.begin(), state.warnings.end(), [&message](const auto &w) { return w.message_id == 0 && w.message == message; }) :
|
||||
std::find_if(state.warnings.begin(), state.warnings.end(), [message_id](const auto& w) { return w.message_id == message_id; });
|
||||
if (it == state.warnings.end())
|
||||
// No, create a new warning and update UI.
|
||||
state.warnings.emplace_back(PrintStateBase::Warning{ warning_level, true, message, message_id });
|
||||
else if (it->message != message || it->level != warning_level) {
|
||||
// Yes, however it needs an update.
|
||||
it->message = message;
|
||||
it->level = warning_level;
|
||||
it->current = true;
|
||||
} else if (it->current)
|
||||
// Yes, and it is current. Don't update UI.
|
||||
retval.second = false;
|
||||
else
|
||||
// Yes, but it is not current. Mark it as current.
|
||||
it->current = true;
|
||||
return retval;
|
||||
}
|
||||
|
||||
private:
|
||||
StateWithTimeStamp m_state[COUNT];
|
||||
StateWithWarnings m_state[COUNT];
|
||||
// Active class StepType or -1 if none is active.
|
||||
// If the background processing is canceled, m_step_active may not be resetted
|
||||
// to -1, see the comment in this->set_started().
|
||||
int m_step_active = -1;
|
||||
};
|
||||
|
||||
class PrintBase;
|
||||
|
||||
class PrintObjectBase
|
||||
class PrintObjectBase : public ObjectID
|
||||
{
|
||||
public:
|
||||
const ModelObject* model_object() const { return m_model_object; }
|
||||
|
@ -199,6 +316,10 @@ protected:
|
|||
// Declared here to allow access from PrintBase through friendship.
|
||||
static tbb::mutex& state_mutex(PrintBase *print);
|
||||
static std::function<void()> cancel_callback(PrintBase *print);
|
||||
// Notify UI about a new warning of a milestone "step" on this PrintObjectBase.
|
||||
// The UI will be notified by calling a status callback registered on print.
|
||||
// If no status callback is registered, the message is printed to console.
|
||||
void status_update_warnings(PrintBase *print, int step, PrintStateBase::WarningLevel warning_level, const std::string &message);
|
||||
|
||||
ModelObject *m_model_object;
|
||||
};
|
||||
|
@ -214,7 +335,7 @@ protected:
|
|||
* The PrintBase class will abstract this flow for different technologies.
|
||||
*
|
||||
*/
|
||||
class PrintBase
|
||||
class PrintBase : public ObjectID
|
||||
{
|
||||
public:
|
||||
PrintBase() : m_placeholder_parser(&m_full_print_config) { this->restart(); }
|
||||
|
@ -264,7 +385,11 @@ public:
|
|||
|
||||
struct SlicingStatus {
|
||||
SlicingStatus(int percent, const std::string &text, unsigned int flags = 0) : percent(percent), text(text), flags(flags) {}
|
||||
int percent;
|
||||
SlicingStatus(const PrintBase &print, int warning_step) :
|
||||
flags(UPDATE_PRINT_STEP_WARNINGS), warning_object_id(print), warning_step(warning_step) {}
|
||||
SlicingStatus(const PrintObjectBase &print_object, int warning_step) :
|
||||
flags(UPDATE_PRINT_OBJECT_STEP_WARNINGS), warning_object_id(print_object), warning_step(warning_step) {}
|
||||
int percent { -1 };
|
||||
std::string text;
|
||||
// Bitmap of flags.
|
||||
enum FlagBits {
|
||||
|
@ -272,9 +397,17 @@ public:
|
|||
RELOAD_SCENE = 1 << 1,
|
||||
RELOAD_SLA_SUPPORT_POINTS = 1 << 2,
|
||||
RELOAD_SLA_PREVIEW = 1 << 3,
|
||||
// UPDATE_PRINT_STEP_WARNINGS is mutually exclusive with UPDATE_PRINT_OBJECT_STEP_WARNINGS.
|
||||
UPDATE_PRINT_STEP_WARNINGS = 1 << 4,
|
||||
UPDATE_PRINT_OBJECT_STEP_WARNINGS = 1 << 5
|
||||
};
|
||||
// Bitmap of FlagBits
|
||||
unsigned int flags;
|
||||
// set to an ObjectID of a Print or a PrintObject based on flags
|
||||
// (whether UPDATE_PRINT_STEP_WARNINGS or UPDATE_PRINT_OBJECT_STEP_WARNINGS is set).
|
||||
ObjectID warning_object_id;
|
||||
// For which Print or PrintObject step a new warning is beeing issued?
|
||||
int warning_step { -1 };
|
||||
};
|
||||
typedef std::function<void(const SlicingStatus&)> status_callback_type;
|
||||
// Default status console print out in the form of percent => message.
|
||||
|
@ -329,6 +462,10 @@ protected:
|
|||
tbb::mutex& state_mutex() const { return m_state_mutex; }
|
||||
std::function<void()> cancel_callback() { return m_cancel_callback; }
|
||||
void call_cancel_callback() { m_cancel_callback(); }
|
||||
// Notify UI about a new warning of a milestone "step" on this PrintBase.
|
||||
// The UI will be notified by calling a status callback.
|
||||
// If no status callback is registered, the message is printed to console.
|
||||
void status_update_warnings(ObjectID object_id, int step, PrintStateBase::WarningLevel warning_level, const std::string &message);
|
||||
|
||||
// If the background processing stop was requested, throw CanceledException.
|
||||
// To be called by the worker thread and its sub-threads (mostly launched on the TBB thread pool) regularly.
|
||||
|
@ -343,11 +480,12 @@ protected:
|
|||
DynamicPrintConfig m_full_print_config;
|
||||
PlaceholderParser m_placeholder_parser;
|
||||
|
||||
private:
|
||||
tbb::atomic<CancelStatus> m_cancel_status;
|
||||
// Callback to be evoked regularly to update state of the UI thread.
|
||||
status_callback_type m_status_callback;
|
||||
|
||||
private:
|
||||
tbb::atomic<CancelStatus> m_cancel_status;
|
||||
|
||||
// Callback to be evoked to stop the background processing before a state is updated.
|
||||
cancel_callback_type m_cancel_callback = [](){};
|
||||
|
||||
|
@ -363,10 +501,16 @@ class PrintBaseWithState : public PrintBase
|
|||
public:
|
||||
bool is_step_done(PrintStepEnum step) const { return m_state.is_done(step, this->state_mutex()); }
|
||||
PrintStateBase::StateWithTimeStamp step_state_with_timestamp(PrintStepEnum step) const { return m_state.state_with_timestamp(step, this->state_mutex()); }
|
||||
PrintStateBase::StateWithWarnings step_state_with_warnings(PrintStepEnum step) const { return m_state.state_with_warnings(step, this->state_mutex()); }
|
||||
|
||||
protected:
|
||||
bool set_started(PrintStepEnum step) { return m_state.set_started(step, this->state_mutex(), [this](){ this->throw_if_canceled(); }); }
|
||||
PrintStateBase::TimeStamp set_done(PrintStepEnum step) { return m_state.set_done(step, this->state_mutex(), [this](){ this->throw_if_canceled(); }); }
|
||||
PrintStateBase::TimeStamp set_done(PrintStepEnum step) {
|
||||
std::pair<PrintStateBase::TimeStamp, bool> status = m_state.set_done(step, this->state_mutex(), [this](){ this->throw_if_canceled(); });
|
||||
if (status.second)
|
||||
this->status_update_warnings(*this, static_cast<int>(step), PrintStateBase::WarningLevel::NON_CRITICAL, std::string());
|
||||
return status.first;
|
||||
}
|
||||
bool invalidate_step(PrintStepEnum step)
|
||||
{ return m_state.invalidate(step, this->cancel_callback()); }
|
||||
template<typename StepTypeIterator>
|
||||
|
@ -380,6 +524,15 @@ protected:
|
|||
bool is_step_started_unguarded(PrintStepEnum step) const { return m_state.is_started_unguarded(step); }
|
||||
bool is_step_done_unguarded(PrintStepEnum step) const { return m_state.is_done_unguarded(step); }
|
||||
|
||||
// Add a slicing warning to the active Print step and send a status notification.
|
||||
// This method could be called multiple times between this->set_started() and this->set_done().
|
||||
void active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id = 0) {
|
||||
std::pair<PrintStepEnum, bool> active_step = m_state.active_step_add_warning(warning_level, message, message_id, this->state_mutex());
|
||||
if (active_step.second)
|
||||
// Update UI.
|
||||
this->status_update_warnings(*this, static_cast<int>(active_step.first), warning_level, message);
|
||||
}
|
||||
|
||||
private:
|
||||
PrintState<PrintStepEnum, COUNT> m_state;
|
||||
};
|
||||
|
@ -394,14 +547,19 @@ public:
|
|||
typedef PrintState<PrintObjectStepEnum, COUNT> PrintObjectState;
|
||||
bool is_step_done(PrintObjectStepEnum step) const { return m_state.is_done(step, PrintObjectBase::state_mutex(m_print)); }
|
||||
PrintStateBase::StateWithTimeStamp step_state_with_timestamp(PrintObjectStepEnum step) const { return m_state.state_with_timestamp(step, PrintObjectBase::state_mutex(m_print)); }
|
||||
PrintStateBase::StateWithWarnings step_state_with_warnings(PrintObjectStepEnum step) const { return m_state.state_with_warnings(step, PrintObjectBase::state_mutex(m_print)); }
|
||||
|
||||
protected:
|
||||
PrintObjectBaseWithState(PrintType *print, ModelObject *model_object) : PrintObjectBase(model_object), m_print(print) {}
|
||||
|
||||
bool set_started(PrintObjectStepEnum step)
|
||||
{ return m_state.set_started(step, PrintObjectBase::state_mutex(m_print), [this](){ this->throw_if_canceled(); }); }
|
||||
PrintStateBase::TimeStamp set_done(PrintObjectStepEnum step)
|
||||
{ return m_state.set_done(step, PrintObjectBase::state_mutex(m_print), [this](){ this->throw_if_canceled(); }); }
|
||||
PrintStateBase::TimeStamp set_done(PrintObjectStepEnum step) {
|
||||
std::pair<PrintStateBase::TimeStamp, bool> status = m_state.set_done(step, PrintObjectBase::state_mutex(m_print), [this](){ this->throw_if_canceled(); });
|
||||
if (status.second)
|
||||
this->status_update_warnings(m_print, static_cast<int>(step), PrintStateBase::WarningLevel::NON_CRITICAL, std::string());
|
||||
return status.first;
|
||||
}
|
||||
|
||||
bool invalidate_step(PrintObjectStepEnum step)
|
||||
{ return m_state.invalidate(step, PrintObjectBase::cancel_callback(m_print)); }
|
||||
|
@ -416,6 +574,14 @@ protected:
|
|||
bool is_step_started_unguarded(PrintObjectStepEnum step) const { return m_state.is_started_unguarded(step); }
|
||||
bool is_step_done_unguarded(PrintObjectStepEnum step) const { return m_state.is_done_unguarded(step); }
|
||||
|
||||
// Add a slicing warning to the active PrintObject step and send a status notification.
|
||||
// This method could be called multiple times between this->set_started() and this->set_done().
|
||||
void active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id = 0) {
|
||||
std::pair<PrintObjectStepEnum, bool> active_step = m_state.active_step_add_warning(warning_level, message, message_id, PrintObjectBase::state_mutex(m_print));
|
||||
if (active_step.second)
|
||||
this->status_update_warnings(m_print, static_cast<int>(active_step.first), warning_level, message);
|
||||
}
|
||||
|
||||
protected:
|
||||
// If the background processing stop was requested, throw CanceledException.
|
||||
// To be called by the worker thread and its sub-threads (mostly launched on the TBB thread pool) regularly.
|
||||
|
|
|
@ -1153,7 +1153,7 @@ void PrintConfigDef::init_fff_params()
|
|||
|
||||
def = this->add("ironing_spacing", coFloat);
|
||||
def->label = L("Spacing between ironing passes");
|
||||
def->tooltip = L("Distance between ironing lins");
|
||||
def->tooltip = L("Distance between ironing lines");
|
||||
def->sidetext = L("mm");
|
||||
def->min = 0;
|
||||
def->mode = comExpert;
|
||||
|
|
|
@ -1431,7 +1431,7 @@ void PrintObject::bridge_over_infill()
|
|||
}
|
||||
|
||||
#ifdef SLIC3R_DEBUG
|
||||
printf("Bridging " PRINTF_ZU " internal areas at layer " PRINTF_ZU "\n", to_bridge.size(), layer->id());
|
||||
printf("Bridging %zu internal areas at layer %zu\n", to_bridge.size(), layer->id());
|
||||
#endif
|
||||
|
||||
// compute the remaning internal solid surfaces as difference
|
||||
|
@ -1577,7 +1577,9 @@ bool PrintObject::update_layer_height_profile(const ModelObject &model_object, c
|
|||
bool updated = false;
|
||||
|
||||
if (layer_height_profile.empty()) {
|
||||
layer_height_profile = model_object.layer_height_profile;
|
||||
// use the constructor because the assignement is crashing on ASAN OsX
|
||||
layer_height_profile = std::vector<coordf_t>(model_object.layer_height_profile);
|
||||
// layer_height_profile = model_object.layer_height_profile;
|
||||
updated = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ std::unique_ptr<TriangleMesh> generate_interior(const TriangleMesh & mesh,
|
|||
_generate_interior(mesh, ctl, hc.min_thickness, voxel_scale,
|
||||
hc.closing_distance));
|
||||
|
||||
if (meshptr) {
|
||||
if (meshptr && !meshptr->empty()) {
|
||||
|
||||
// This flips the normals to be outward facing...
|
||||
meshptr->require_shared_vertices();
|
||||
|
|
|
@ -28,17 +28,25 @@ void reproject_support_points(const EigenMesh3D &mesh, std::vector<PointType> &p
|
|||
inline void reproject_points_and_holes(ModelObject *object)
|
||||
{
|
||||
bool has_sppoints = !object->sla_support_points.empty();
|
||||
bool has_holes = !object->sla_drain_holes.empty();
|
||||
|
||||
if (!object || (!has_holes && !has_sppoints)) return;
|
||||
// Disabling reprojection of holes as they have a significant offset away
|
||||
// from the model body which tolerates minor geometrical changes.
|
||||
//
|
||||
// TODO: uncomment and ensure the right offset of the hole points if
|
||||
// reprojection would still be necessary.
|
||||
// bool has_holes = !object->sla_drain_holes.empty();
|
||||
|
||||
EigenMesh3D emesh{object->raw_mesh()};
|
||||
if (!object || (/*!has_holes &&*/ !has_sppoints)) return;
|
||||
|
||||
TriangleMesh rmsh = object->raw_mesh();
|
||||
rmsh.require_shared_vertices();
|
||||
EigenMesh3D emesh{rmsh};
|
||||
|
||||
if (has_sppoints)
|
||||
reproject_support_points(emesh, object->sla_support_points);
|
||||
|
||||
if (has_holes)
|
||||
reproject_support_points(emesh, object->sla_drain_holes);
|
||||
// if (has_holes)
|
||||
// reproject_support_points(emesh, object->sla_drain_holes);
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
|
@ -429,6 +429,13 @@ public:
|
|||
bool finished() const override { return this->is_step_done(slaposSliceSupports) && this->Inherited::is_step_done(slapsRasterize); }
|
||||
|
||||
const PrintObjects& objects() const { return m_objects; }
|
||||
// PrintObject by its ObjectID, to be used to uniquely bind slicing warnings to their source PrintObjects
|
||||
// in the notification center.
|
||||
const SLAPrintObject* get_object(ObjectID object_id) const {
|
||||
auto it = std::find_if(m_objects.begin(), m_objects.end(),
|
||||
[object_id](const SLAPrintObject *obj) { return *static_cast<const ObjectID*>(obj) == object_id; });
|
||||
return (it == m_objects.end()) ? nullptr : *it;
|
||||
}
|
||||
|
||||
const SLAPrintConfig& print_config() const { return m_print_config; }
|
||||
const SLAPrinterConfig& printer_config() const { return m_printer_config; }
|
||||
|
|
|
@ -21,6 +21,7 @@ bool SVG::open(const char* afilename)
|
|||
" <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
|
||||
" </marker>\n"
|
||||
);
|
||||
fprintf(this->f, "<rect fill='white' stroke='none' x='0' y='0' width='%f' height='%f'/>\n", 2000.f, 2000.f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,6 +43,7 @@ bool SVG::open(const char* afilename, const BoundingBox &bbox, const coord_t bbo
|
|||
" <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
|
||||
" </marker>\n",
|
||||
h, w);
|
||||
fprintf(this->f, "<rect fill='white' stroke='none' x='0' y='0' width='%f' height='%f'/>\n", w, h);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,5 +51,11 @@
|
|||
// Enable error logging for OpenGL calls when SLIC3R_LOGLEVEL >= 5
|
||||
#define ENABLE_OPENGL_ERROR_LOGGING (1 && ENABLE_2_3_0_ALPHA1)
|
||||
|
||||
// Enable built-in DPI changed event handler of wxWidgets 3.1.3
|
||||
#define ENABLE_WX_3_1_3_DPI_CHANGED_EVENT (1 && ENABLE_2_3_0_ALPHA1)
|
||||
|
||||
// Enable changing application layout without the need to restart
|
||||
#define ENABLE_LAYOUT_NO_RESTART (1 && ENABLE_2_3_0_ALPHA1)
|
||||
|
||||
|
||||
#endif // _prusaslicer_technologies_h_
|
||||
|
|
|
@ -952,7 +952,7 @@ void TriangleMeshSlicer::slice(const std::vector<float> &z, SlicingMode mode, co
|
|||
[&layers_p, mode, closing_radius, layers, throw_on_cancel, this](const tbb::blocked_range<size_t>& range) {
|
||||
for (size_t layer_id = range.begin(); layer_id < range.end(); ++ layer_id) {
|
||||
#ifdef SLIC3R_TRIANGLEMESH_DEBUG
|
||||
printf("Layer " PRINTF_ZU " (slice_z = %.2f):\n", layer_id, z[layer_id]);
|
||||
printf("Layer %zu (slice_z = %.2f):\n", layer_id, z[layer_id]);
|
||||
#endif
|
||||
throw_on_cancel();
|
||||
ExPolygons &expolygons = (*layers)[layer_id];
|
||||
|
@ -1779,7 +1779,7 @@ void TriangleMeshSlicer::make_expolygons(const Polygons &loops, const float clos
|
|||
size_t holes_count = 0;
|
||||
for (ExPolygons::const_iterator e = ex_slices.begin(); e != ex_slices.end(); ++ e)
|
||||
holes_count += e->holes.size();
|
||||
printf(PRINTF_ZU " surface(s) having " PRINTF_ZU " holes detected from " PRINTF_ZU " polylines\n",
|
||||
printf("%zu surface(s) having %zu holes detected from %zu polylines\n",
|
||||
ex_slices.size(), holes_count, loops.size());
|
||||
#endif
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,3 +1,5 @@
|
|||
// Polygon offsetting using Voronoi diagram prodiced by boost::polygon.
|
||||
|
||||
#ifndef slic3r_VoronoiOffset_hpp_
|
||||
#define slic3r_VoronoiOffset_hpp_
|
||||
|
||||
|
@ -7,7 +9,16 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
Polygons voronoi_offset(const Geometry::VoronoiDiagram &vd, const Lines &lines, double offset_distance, double discretization_error);
|
||||
// Offset a polygon or a set of polygons possibly with holes by traversing a Voronoi diagram.
|
||||
// The input polygons are stored in lines and lines are referenced by vd.
|
||||
// Outer curve will be extracted for a positive offset_distance,
|
||||
// inner curve will be extracted for a negative offset_distance.
|
||||
// Circular arches will be discretized to achieve discretization_error.
|
||||
Polygons voronoi_offset(
|
||||
const Geometry::VoronoiDiagram &vd,
|
||||
const Lines &lines,
|
||||
double offset_distance,
|
||||
double discretization_error);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
415
src/libslic3r/VoronoiVisualUtils.hpp
Normal file
415
src/libslic3r/VoronoiVisualUtils.hpp
Normal file
|
@ -0,0 +1,415 @@
|
|||
#include <stack>
|
||||
|
||||
#include <libslic3r/Geometry.hpp>
|
||||
#include <libslic3r/Line.hpp>
|
||||
#include <libslic3r/Polygon.hpp>
|
||||
#include <libslic3r/SVG.hpp>
|
||||
|
||||
namespace boost { namespace polygon {
|
||||
|
||||
// The following code for the visualization of the boost Voronoi diagram is based on:
|
||||
//
|
||||
// Boost.Polygon library voronoi_graphic_utils.hpp header file
|
||||
// Copyright Andrii Sydorchuk 2010-2012.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
template <typename CT>
|
||||
class voronoi_visual_utils {
|
||||
public:
|
||||
// Discretize parabolic Voronoi edge.
|
||||
// Parabolic Voronoi edges are always formed by one point and one segment
|
||||
// from the initial input set.
|
||||
//
|
||||
// Args:
|
||||
// point: input point.
|
||||
// segment: input segment.
|
||||
// max_dist: maximum discretization distance.
|
||||
// discretization: point discretization of the given Voronoi edge.
|
||||
//
|
||||
// Template arguments:
|
||||
// InCT: coordinate type of the input geometries (usually integer).
|
||||
// Point: point type, should model point concept.
|
||||
// Segment: segment type, should model segment concept.
|
||||
//
|
||||
// Important:
|
||||
// discretization should contain both edge endpoints initially.
|
||||
template <class InCT1, class InCT2,
|
||||
template<class> class Point,
|
||||
template<class> class Segment>
|
||||
static
|
||||
typename enable_if<
|
||||
typename gtl_and<
|
||||
typename gtl_if<
|
||||
typename is_point_concept<
|
||||
typename geometry_concept< Point<InCT1> >::type
|
||||
>::type
|
||||
>::type,
|
||||
typename gtl_if<
|
||||
typename is_segment_concept<
|
||||
typename geometry_concept< Segment<InCT2> >::type
|
||||
>::type
|
||||
>::type
|
||||
>::type,
|
||||
void
|
||||
>::type discretize(
|
||||
const Point<InCT1>& point,
|
||||
const Segment<InCT2>& segment,
|
||||
const CT max_dist,
|
||||
std::vector< Point<CT> >* discretization) {
|
||||
// Apply the linear transformation to move start point of the segment to
|
||||
// the point with coordinates (0, 0) and the direction of the segment to
|
||||
// coincide the positive direction of the x-axis.
|
||||
CT segm_vec_x = cast(x(high(segment))) - cast(x(low(segment)));
|
||||
CT segm_vec_y = cast(y(high(segment))) - cast(y(low(segment)));
|
||||
CT sqr_segment_length = segm_vec_x * segm_vec_x + segm_vec_y * segm_vec_y;
|
||||
|
||||
// Compute x-coordinates of the endpoints of the edge
|
||||
// in the transformed space.
|
||||
CT projection_start = sqr_segment_length *
|
||||
get_point_projection((*discretization)[0], segment);
|
||||
CT projection_end = sqr_segment_length *
|
||||
get_point_projection((*discretization)[1], segment);
|
||||
|
||||
// Compute parabola parameters in the transformed space.
|
||||
// Parabola has next representation:
|
||||
// f(x) = ((x-rot_x)^2 + rot_y^2) / (2.0*rot_y).
|
||||
CT point_vec_x = cast(x(point)) - cast(x(low(segment)));
|
||||
CT point_vec_y = cast(y(point)) - cast(y(low(segment)));
|
||||
CT rot_x = segm_vec_x * point_vec_x + segm_vec_y * point_vec_y;
|
||||
CT rot_y = segm_vec_x * point_vec_y - segm_vec_y * point_vec_x;
|
||||
|
||||
// Save the last point.
|
||||
Point<CT> last_point = (*discretization)[1];
|
||||
discretization->pop_back();
|
||||
|
||||
// Use stack to avoid recursion.
|
||||
std::stack<CT> point_stack;
|
||||
point_stack.push(projection_end);
|
||||
CT cur_x = projection_start;
|
||||
CT cur_y = parabola_y(cur_x, rot_x, rot_y);
|
||||
|
||||
// Adjust max_dist parameter in the transformed space.
|
||||
const CT max_dist_transformed = max_dist * max_dist * sqr_segment_length;
|
||||
while (!point_stack.empty()) {
|
||||
CT new_x = point_stack.top();
|
||||
CT new_y = parabola_y(new_x, rot_x, rot_y);
|
||||
|
||||
// Compute coordinates of the point of the parabola that is
|
||||
// furthest from the current line segment.
|
||||
CT mid_x = (new_y - cur_y) / (new_x - cur_x) * rot_y + rot_x;
|
||||
CT mid_y = parabola_y(mid_x, rot_x, rot_y);
|
||||
|
||||
// Compute maximum distance between the given parabolic arc
|
||||
// and line segment that discretize it.
|
||||
CT dist = (new_y - cur_y) * (mid_x - cur_x) -
|
||||
(new_x - cur_x) * (mid_y - cur_y);
|
||||
dist = dist * dist / ((new_y - cur_y) * (new_y - cur_y) +
|
||||
(new_x - cur_x) * (new_x - cur_x));
|
||||
if (dist <= max_dist_transformed) {
|
||||
// Distance between parabola and line segment is less than max_dist.
|
||||
point_stack.pop();
|
||||
CT inter_x = (segm_vec_x * new_x - segm_vec_y * new_y) /
|
||||
sqr_segment_length + cast(x(low(segment)));
|
||||
CT inter_y = (segm_vec_x * new_y + segm_vec_y * new_x) /
|
||||
sqr_segment_length + cast(y(low(segment)));
|
||||
discretization->push_back(Point<CT>(inter_x, inter_y));
|
||||
cur_x = new_x;
|
||||
cur_y = new_y;
|
||||
} else {
|
||||
point_stack.push(mid_x);
|
||||
}
|
||||
}
|
||||
|
||||
// Update last point.
|
||||
discretization->back() = last_point;
|
||||
}
|
||||
|
||||
private:
|
||||
// Compute y(x) = ((x - a) * (x - a) + b * b) / (2 * b).
|
||||
static CT parabola_y(CT x, CT a, CT b) {
|
||||
return ((x - a) * (x - a) + b * b) / (b + b);
|
||||
}
|
||||
|
||||
// Get normalized length of the distance between:
|
||||
// 1) point projection onto the segment
|
||||
// 2) start point of the segment
|
||||
// Return this length divided by the segment length. This is made to avoid
|
||||
// sqrt computation during transformation from the initial space to the
|
||||
// transformed one and vice versa. The assumption is made that projection of
|
||||
// the point lies between the start-point and endpoint of the segment.
|
||||
template <class InCT,
|
||||
template<class> class Point,
|
||||
template<class> class Segment>
|
||||
static
|
||||
typename enable_if<
|
||||
typename gtl_and<
|
||||
typename gtl_if<
|
||||
typename is_point_concept<
|
||||
typename geometry_concept< Point<int> >::type
|
||||
>::type
|
||||
>::type,
|
||||
typename gtl_if<
|
||||
typename is_segment_concept<
|
||||
typename geometry_concept< Segment<long> >::type
|
||||
>::type
|
||||
>::type
|
||||
>::type,
|
||||
CT
|
||||
>::type get_point_projection(
|
||||
const Point<CT>& point, const Segment<InCT>& segment) {
|
||||
CT segment_vec_x = cast(x(high(segment))) - cast(x(low(segment)));
|
||||
CT segment_vec_y = cast(y(high(segment))) - cast(y(low(segment)));
|
||||
CT point_vec_x = x(point) - cast(x(low(segment)));
|
||||
CT point_vec_y = y(point) - cast(y(low(segment)));
|
||||
CT sqr_segment_length =
|
||||
segment_vec_x * segment_vec_x + segment_vec_y * segment_vec_y;
|
||||
CT vec_dot = segment_vec_x * point_vec_x + segment_vec_y * point_vec_y;
|
||||
return vec_dot / sqr_segment_length;
|
||||
}
|
||||
|
||||
template <typename InCT>
|
||||
static CT cast(const InCT& value) {
|
||||
return static_cast<CT>(value);
|
||||
}
|
||||
};
|
||||
|
||||
} } // namespace boost::polygon
|
||||
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
|
||||
// The following code for the visualization of the boost Voronoi diagram is based on:
|
||||
//
|
||||
// Boost.Polygon library voronoi_visualizer.cpp file
|
||||
// Copyright Andrii Sydorchuk 2010-2012.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
namespace Voronoi { namespace Internal {
|
||||
|
||||
using VD = Geometry::VoronoiDiagram;
|
||||
typedef double coordinate_type;
|
||||
typedef boost::polygon::point_data<coordinate_type> point_type;
|
||||
typedef boost::polygon::segment_data<coordinate_type> segment_type;
|
||||
typedef boost::polygon::rectangle_data<coordinate_type> rect_type;
|
||||
typedef VD::cell_type cell_type;
|
||||
typedef VD::cell_type::source_index_type source_index_type;
|
||||
typedef VD::cell_type::source_category_type source_category_type;
|
||||
typedef VD::edge_type edge_type;
|
||||
typedef VD::cell_container_type cell_container_type;
|
||||
typedef VD::cell_container_type vertex_container_type;
|
||||
typedef VD::edge_container_type edge_container_type;
|
||||
typedef VD::const_cell_iterator const_cell_iterator;
|
||||
typedef VD::const_vertex_iterator const_vertex_iterator;
|
||||
typedef VD::const_edge_iterator const_edge_iterator;
|
||||
|
||||
static const std::size_t EXTERNAL_COLOR = 1;
|
||||
|
||||
inline void color_exterior(const VD::edge_type* edge)
|
||||
{
|
||||
if (edge->color() == EXTERNAL_COLOR)
|
||||
return;
|
||||
edge->color(EXTERNAL_COLOR);
|
||||
edge->twin()->color(EXTERNAL_COLOR);
|
||||
const VD::vertex_type* v = edge->vertex1();
|
||||
if (v == NULL || !edge->is_primary())
|
||||
return;
|
||||
v->color(EXTERNAL_COLOR);
|
||||
const VD::edge_type* e = v->incident_edge();
|
||||
do {
|
||||
color_exterior(e);
|
||||
e = e->rot_next();
|
||||
} while (e != v->incident_edge());
|
||||
}
|
||||
|
||||
inline point_type retrieve_point(const Points &points, const std::vector<segment_type> &segments, const cell_type& cell)
|
||||
{
|
||||
assert(cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_START_POINT || cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_END_POINT ||
|
||||
cell.source_category() == boost::polygon::SOURCE_CATEGORY_SINGLE_POINT);
|
||||
return cell.source_category() == boost::polygon::SOURCE_CATEGORY_SINGLE_POINT ?
|
||||
Voronoi::Internal::point_type(double(points[cell.source_index()].x()), double(points[cell.source_index()].y())) :
|
||||
(cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_START_POINT) ?
|
||||
low(segments[cell.source_index()]) : high(segments[cell.source_index()]);
|
||||
}
|
||||
|
||||
inline void clip_infinite_edge(const Points &points, const std::vector<segment_type> &segments, const edge_type& edge, coordinate_type bbox_max_size, std::vector<point_type>* clipped_edge)
|
||||
{
|
||||
const cell_type& cell1 = *edge.cell();
|
||||
const cell_type& cell2 = *edge.twin()->cell();
|
||||
point_type origin, direction;
|
||||
// Infinite edges could not be created by two segment sites.
|
||||
if (! cell1.contains_point() && ! cell2.contains_point()) {
|
||||
printf("Error! clip_infinite_edge - infinite edge separates two segment cells\n");
|
||||
return;
|
||||
}
|
||||
if (cell1.contains_point() && cell2.contains_point()) {
|
||||
point_type p1 = retrieve_point(points, segments, cell1);
|
||||
point_type p2 = retrieve_point(points, segments, cell2);
|
||||
origin.x((p1.x() + p2.x()) * 0.5);
|
||||
origin.y((p1.y() + p2.y()) * 0.5);
|
||||
direction.x(p1.y() - p2.y());
|
||||
direction.y(p2.x() - p1.x());
|
||||
} else {
|
||||
origin = cell1.contains_segment() ? retrieve_point(points, segments, cell2) : retrieve_point(points, segments, cell1);
|
||||
segment_type segment = cell1.contains_segment() ? segments[cell1.source_index()] : segments[cell2.source_index()];
|
||||
coordinate_type dx = high(segment).x() - low(segment).x();
|
||||
coordinate_type dy = high(segment).y() - low(segment).y();
|
||||
if ((low(segment) == origin) ^ cell1.contains_point()) {
|
||||
direction.x(dy);
|
||||
direction.y(-dx);
|
||||
} else {
|
||||
direction.x(-dy);
|
||||
direction.y(dx);
|
||||
}
|
||||
}
|
||||
coordinate_type koef = bbox_max_size / (std::max)(fabs(direction.x()), fabs(direction.y()));
|
||||
if (edge.vertex0() == NULL) {
|
||||
clipped_edge->push_back(point_type(
|
||||
origin.x() - direction.x() * koef,
|
||||
origin.y() - direction.y() * koef));
|
||||
} else {
|
||||
clipped_edge->push_back(
|
||||
point_type(edge.vertex0()->x(), edge.vertex0()->y()));
|
||||
}
|
||||
if (edge.vertex1() == NULL) {
|
||||
clipped_edge->push_back(point_type(
|
||||
origin.x() + direction.x() * koef,
|
||||
origin.y() + direction.y() * koef));
|
||||
} else {
|
||||
clipped_edge->push_back(
|
||||
point_type(edge.vertex1()->x(), edge.vertex1()->y()));
|
||||
}
|
||||
}
|
||||
|
||||
inline void sample_curved_edge(const Points &points, const std::vector<segment_type> &segments, const edge_type& edge, std::vector<point_type> &sampled_edge, coordinate_type max_dist)
|
||||
{
|
||||
point_type point = edge.cell()->contains_point() ?
|
||||
retrieve_point(points, segments, *edge.cell()) :
|
||||
retrieve_point(points, segments, *edge.twin()->cell());
|
||||
segment_type segment = edge.cell()->contains_point() ?
|
||||
segments[edge.twin()->cell()->source_index()] :
|
||||
segments[edge.cell()->source_index()];
|
||||
::boost::polygon::voronoi_visual_utils<coordinate_type>::discretize(point, segment, max_dist, &sampled_edge);
|
||||
}
|
||||
|
||||
} /* namespace Internal */ } // namespace Voronoi
|
||||
|
||||
BoundingBox get_extents(const Lines &lines);
|
||||
|
||||
static inline void dump_voronoi_to_svg(
|
||||
const char *path,
|
||||
const Geometry::VoronoiDiagram &vd,
|
||||
const Points &points,
|
||||
const Lines &lines,
|
||||
const Polygons &offset_curves = Polygons(),
|
||||
const Lines &helper_lines = Lines(),
|
||||
double scale = 0)
|
||||
{
|
||||
BoundingBox bbox;
|
||||
bbox.merge(get_extents(points));
|
||||
bbox.merge(get_extents(lines));
|
||||
bbox.merge(get_extents(offset_curves));
|
||||
bbox.merge(get_extents(helper_lines));
|
||||
bbox.min -= (0.01 * bbox.size().cast<double>()).cast<coord_t>();
|
||||
bbox.max += (0.01 * bbox.size().cast<double>()).cast<coord_t>();
|
||||
|
||||
if (scale == 0)
|
||||
scale =
|
||||
// 0.1
|
||||
0.01
|
||||
* std::min(bbox.size().x(), bbox.size().y());
|
||||
else
|
||||
scale /= SCALING_FACTOR;
|
||||
|
||||
const std::string inputSegmentPointColor = "lightseagreen";
|
||||
const coord_t inputSegmentPointRadius = coord_t(0.09 * scale);
|
||||
const std::string inputSegmentColor = "lightseagreen";
|
||||
const coord_t inputSegmentLineWidth = coord_t(0.03 * scale);
|
||||
|
||||
const std::string voronoiPointColor = "black";
|
||||
const coord_t voronoiPointRadius = coord_t(0.06 * scale);
|
||||
const std::string voronoiLineColorPrimary = "black";
|
||||
const std::string voronoiLineColorSecondary = "green";
|
||||
const std::string voronoiArcColor = "red";
|
||||
const coord_t voronoiLineWidth = coord_t(0.02 * scale);
|
||||
|
||||
const std::string offsetCurveColor = "magenta";
|
||||
const coord_t offsetCurveLineWidth = coord_t(0.02 * scale);
|
||||
|
||||
const std::string helperLineColor = "orange";
|
||||
const coord_t helperLineWidth = coord_t(0.04 * scale);
|
||||
|
||||
const bool internalEdgesOnly = false;
|
||||
const bool primaryEdgesOnly = false;
|
||||
|
||||
::Slic3r::SVG svg(path, bbox);
|
||||
|
||||
// For clipping of half-lines to some reasonable value.
|
||||
// The line will then be clipped by the SVG viewer anyway.
|
||||
const double bbox_dim_max = double(std::max(bbox.size().x(), bbox.size().y()));
|
||||
// For the discretization of the Voronoi parabolic segments.
|
||||
const double discretization_step = 0.0002 * bbox_dim_max;
|
||||
|
||||
// Make a copy of the input segments with the double type.
|
||||
std::vector<Voronoi::Internal::segment_type> segments;
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++ it)
|
||||
segments.push_back(Voronoi::Internal::segment_type(
|
||||
Voronoi::Internal::point_type(double(it->a(0)), double(it->a(1))),
|
||||
Voronoi::Internal::point_type(double(it->b(0)), double(it->b(1)))));
|
||||
|
||||
// Color exterior edges.
|
||||
for (boost::polygon::voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it)
|
||||
if (!it->is_finite())
|
||||
Voronoi::Internal::color_exterior(&(*it));
|
||||
|
||||
// Draw the end points of the input polygon.
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it) {
|
||||
svg.draw(it->a, inputSegmentPointColor, inputSegmentPointRadius);
|
||||
svg.draw(it->b, inputSegmentPointColor, inputSegmentPointRadius);
|
||||
}
|
||||
// Draw the input polygon.
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it)
|
||||
svg.draw(Line(Point(coord_t(it->a(0)), coord_t(it->a(1))), Point(coord_t(it->b(0)), coord_t(it->b(1)))), inputSegmentColor, inputSegmentLineWidth);
|
||||
|
||||
#if 1
|
||||
// Draw voronoi vertices.
|
||||
for (boost::polygon::voronoi_diagram<double>::const_vertex_iterator it = vd.vertices().begin(); it != vd.vertices().end(); ++it)
|
||||
if (! internalEdgesOnly || it->color() != Voronoi::Internal::EXTERNAL_COLOR)
|
||||
svg.draw(Point(coord_t(it->x()), coord_t(it->y())), voronoiPointColor, voronoiPointRadius);
|
||||
|
||||
for (boost::polygon::voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it) {
|
||||
if (primaryEdgesOnly && !it->is_primary())
|
||||
continue;
|
||||
if (internalEdgesOnly && (it->color() == Voronoi::Internal::EXTERNAL_COLOR))
|
||||
continue;
|
||||
std::vector<Voronoi::Internal::point_type> samples;
|
||||
std::string color = voronoiLineColorPrimary;
|
||||
if (!it->is_finite()) {
|
||||
Voronoi::Internal::clip_infinite_edge(points, segments, *it, bbox_dim_max, &samples);
|
||||
if (! it->is_primary())
|
||||
color = voronoiLineColorSecondary;
|
||||
} else {
|
||||
// Store both points of the segment into samples. sample_curved_edge will split the initial line
|
||||
// until the discretization_step is reached.
|
||||
samples.push_back(Voronoi::Internal::point_type(it->vertex0()->x(), it->vertex0()->y()));
|
||||
samples.push_back(Voronoi::Internal::point_type(it->vertex1()->x(), it->vertex1()->y()));
|
||||
if (it->is_curved()) {
|
||||
Voronoi::Internal::sample_curved_edge(points, segments, *it, samples, discretization_step);
|
||||
color = voronoiArcColor;
|
||||
} else if (! it->is_primary())
|
||||
color = voronoiLineColorSecondary;
|
||||
}
|
||||
for (std::size_t i = 0; i + 1 < samples.size(); ++i)
|
||||
svg.draw(Line(Point(coord_t(samples[i].x()), coord_t(samples[i].y())), Point(coord_t(samples[i+1].x()), coord_t(samples[i+1].y()))), color, voronoiLineWidth);
|
||||
}
|
||||
#endif
|
||||
|
||||
svg.draw_outline(offset_curves, offsetCurveColor, offsetCurveLineWidth);
|
||||
svg.draw(helper_lines, helperLineColor, helperLineWidth);
|
||||
|
||||
svg.Close();
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
|
@ -27,7 +27,7 @@
|
|||
// Saves around 32% RAM after slicing step, 6.7% after G-code export (tested on PrusaSlicer 2.2.0 final).
|
||||
using coord_t = int32_t;
|
||||
#else
|
||||
//FIXME At least FillRectilinear2 requires coord_t to be 32bit.
|
||||
//FIXME At least FillRectilinear2 and std::boost Voronoi require coord_t to be 32bit.
|
||||
typedef int64_t coord_t;
|
||||
#endif
|
||||
|
||||
|
@ -74,13 +74,6 @@ inline std::string debug_out_path(const char *name, ...)
|
|||
return std::string(SLIC3R_DEBUG_OUT_PATH_PREFIX) + std::string(buffer);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Visual Studio older than 2015 does not support the prinf type specifier %zu. Use %Iu instead.
|
||||
#define PRINTF_ZU "%Iu"
|
||||
#else
|
||||
#define PRINTF_ZU "%zu"
|
||||
#endif
|
||||
|
||||
#ifndef UNUSED
|
||||
#define UNUSED(x) (void)(x)
|
||||
#endif /* UNUSED */
|
||||
|
|
|
@ -239,7 +239,7 @@ void show_error_id(int id, const std::string& message)
|
|||
|
||||
void show_info(wxWindow* parent, const wxString& message, const wxString& title)
|
||||
{
|
||||
wxMessageDialog msg_wingow(parent, message, wxString(SLIC3R_APP_NAME " - ") + (title.empty() ? _(L("Notice")) : title), wxOK | wxICON_INFORMATION);
|
||||
wxMessageDialog msg_wingow(parent, message, wxString(SLIC3R_APP_NAME " - ") + (title.empty() ? _L("Notice") : title), wxOK | wxICON_INFORMATION);
|
||||
msg_wingow.ShowModal();
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ void show_info(wxWindow* parent, const char* message, const char* title)
|
|||
|
||||
void warning_catcher(wxWindow* parent, const wxString& message)
|
||||
{
|
||||
wxMessageDialog msg(parent, message, _(L("Warning")), wxOK | wxICON_WARNING);
|
||||
wxMessageDialog msg(parent, message, _L("Warning"), wxOK | wxICON_WARNING);
|
||||
msg.ShowModal();
|
||||
}
|
||||
|
||||
|
@ -261,13 +261,13 @@ void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string
|
|||
return;
|
||||
|
||||
wxCheckListBoxComboPopup* popup = new wxCheckListBoxComboPopup;
|
||||
if (popup != nullptr)
|
||||
{
|
||||
if (popup != nullptr) {
|
||||
// FIXME If the following line is removed, the combo box popup list will not react to mouse clicks.
|
||||
// On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10.
|
||||
comboCtrl->UseAltPopupWindow();
|
||||
|
||||
comboCtrl->EnablePopupAnimation(false);
|
||||
// the following line messes up the popup size the first time it is shown on wxWidgets 3.1.3
|
||||
// comboCtrl->EnablePopupAnimation(false);
|
||||
comboCtrl->SetPopupControl(popup);
|
||||
popup->SetStringValue(from_u8(text));
|
||||
popup->Bind(wxEVT_CHECKLISTBOX, [popup](wxCommandEvent& evt) { popup->OnCheckListBox(evt); });
|
||||
|
@ -278,13 +278,11 @@ void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string
|
|||
std::vector<std::string> items_str;
|
||||
boost::split(items_str, items, boost::is_any_of("|"), boost::token_compress_off);
|
||||
|
||||
for (const std::string& item : items_str)
|
||||
{
|
||||
for (const std::string& item : items_str) {
|
||||
popup->Append(from_u8(item));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < popup->GetCount(); ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < popup->GetCount(); ++i) {
|
||||
popup->Check(i, initial_value);
|
||||
}
|
||||
}
|
||||
|
@ -295,10 +293,8 @@ int combochecklist_get_flags(wxComboCtrl* comboCtrl)
|
|||
int flags = 0;
|
||||
|
||||
wxCheckListBoxComboPopup* popup = wxDynamicCast(comboCtrl->GetPopupControl(), wxCheckListBoxComboPopup);
|
||||
if (popup != nullptr)
|
||||
{
|
||||
for (unsigned int i = 0; i < popup->GetCount(); ++i)
|
||||
{
|
||||
if (popup != nullptr) {
|
||||
for (unsigned int i = 0; i < popup->GetCount(); ++i) {
|
||||
if (popup->IsChecked(i))
|
||||
flags |= 1 << i;
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ wxString file_wildcards(FileType file_type, const std::string &custom_extension)
|
|||
static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str().data(); }
|
||||
|
||||
#ifdef WIN32
|
||||
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
static void register_win32_dpi_event()
|
||||
{
|
||||
enum { WM_DPICHANGED_ = 0x02e0 };
|
||||
|
@ -121,13 +122,12 @@ static void register_win32_dpi_event()
|
|||
return true;
|
||||
});
|
||||
}
|
||||
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
|
||||
|
||||
static GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 };
|
||||
|
||||
static void register_win32_device_notification_event()
|
||||
{
|
||||
enum { WM_DPICHANGED_ = 0x02e0 };
|
||||
|
||||
wxWindow::MSWRegisterMessageHandler(WM_DEVICECHANGE, [](wxWindow *win, WXUINT /* nMsg */, WXWPARAM wParam, WXLPARAM lParam) {
|
||||
// Some messages are sent to top level windows by default, some messages are sent to only registered windows, and we explictely register on MainFrame only.
|
||||
auto main_frame = dynamic_cast<MainFrame*>(win);
|
||||
|
@ -410,7 +410,9 @@ bool GUI_App::on_init_inner()
|
|||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
register_win32_dpi_event();
|
||||
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
|
||||
register_win32_device_notification_event();
|
||||
#endif // WIN32
|
||||
|
||||
|
@ -631,9 +633,9 @@ void GUI_App::recreate_GUI(const wxString& msg_name)
|
|||
{
|
||||
mainframe->shutdown();
|
||||
|
||||
wxProgressDialog dlg(msg_name, msg_name);
|
||||
wxProgressDialog dlg(msg_name, msg_name, 100, nullptr, wxPD_AUTO_HIDE);
|
||||
dlg.Pulse();
|
||||
dlg.Update(10, _(L("Recreating")) + dots);
|
||||
dlg.Update(10, _L("Recreating") + dots);
|
||||
|
||||
MainFrame *old_main_frame = mainframe;
|
||||
mainframe = new MainFrame();
|
||||
|
@ -643,17 +645,17 @@ void GUI_App::recreate_GUI(const wxString& msg_name)
|
|||
sidebar().obj_list()->init_objects();
|
||||
SetTopWindow(mainframe);
|
||||
|
||||
dlg.Update(30, _(L("Recreating")) + dots);
|
||||
dlg.Update(30, _L("Recreating") + dots);
|
||||
old_main_frame->Destroy();
|
||||
// For this moment ConfigWizard is deleted, invalidate it.
|
||||
m_wizard = nullptr;
|
||||
|
||||
dlg.Update(80, _(L("Loading of current presets")) + dots);
|
||||
dlg.Update(80, _L("Loading of current presets") + dots);
|
||||
m_printhost_job_queue.reset(new PrintHostJobQueue(mainframe->printhost_queue_dlg()));
|
||||
load_current_presets();
|
||||
mainframe->Show(true);
|
||||
|
||||
dlg.Update(90, _(L("Loading of a mode view")) + dots);
|
||||
dlg.Update(90, _L("Loading of a mode view") + dots);
|
||||
/* Temporary workaround for the correct behavior of the Scrolled sidebar panel:
|
||||
* change min hight of object list to the normal min value (15 * wxGetApp().em_unit())
|
||||
* after first whole Mainframe updating/layouting
|
||||
|
@ -1059,17 +1061,34 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
|
|||
break;
|
||||
case ConfigMenuPreferences:
|
||||
{
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
bool app_layout_changed = false;
|
||||
#else
|
||||
bool recreate_app = false;
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
{
|
||||
// the dialog needs to be destroyed before the call to recreate_GUI()
|
||||
// or sometimes the application crashes into wxDialogBase() destructor
|
||||
// so we put it into an inner scope
|
||||
PreferencesDialog dlg(mainframe);
|
||||
dlg.ShowModal();
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
app_layout_changed = dlg.settings_layout_changed();
|
||||
#else
|
||||
recreate_app = dlg.settings_layout_changed();
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
}
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
if (app_layout_changed) {
|
||||
mainframe->GetSizer()->Hide((size_t)0);
|
||||
mainframe->update_layout();
|
||||
mainframe->select_tab(0);
|
||||
mainframe->GetSizer()->Show((size_t)0);
|
||||
}
|
||||
#else
|
||||
if (recreate_app)
|
||||
recreate_GUI(_L("Changing of the settings layout") + dots);
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
break;
|
||||
}
|
||||
case ConfigMenuLanguage:
|
||||
|
@ -1386,7 +1405,9 @@ void GUI_App::window_pos_restore(wxTopLevelWindow* window, const std::string &na
|
|||
return;
|
||||
}
|
||||
|
||||
window->SetSize(metrics->get_rect());
|
||||
const wxRect& rect = metrics->get_rect();
|
||||
window->SetPosition(rect.GetPosition());
|
||||
window->SetSize(rect.GetSize());
|
||||
window->Maximize(metrics->get_maximized());
|
||||
}
|
||||
|
||||
|
|
|
@ -347,7 +347,7 @@ void ObjectList::get_selection_indexes(std::vector<int>& obj_idxs, std::vector<i
|
|||
else {
|
||||
for (wxDataViewItem item : sels) {
|
||||
const ItemType type = m_objects_model->GetItemType(item);
|
||||
assert(type & itObject | itInstance | itInstanceRoot);
|
||||
assert(type & (itObject | itInstance | itInstanceRoot));
|
||||
|
||||
obj_idxs.emplace_back(type & itObject ? m_objects_model->GetIdByItem(item) :
|
||||
m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item)));
|
||||
|
|
|
@ -250,6 +250,7 @@ bool Preview::init(wxWindow* parent, Model* model)
|
|||
_(L("Internal infill")) + "|" +
|
||||
_(L("Solid infill")) + "|" +
|
||||
_(L("Top solid infill")) + "|" +
|
||||
_(L("Ironing")) + "|" +
|
||||
_(L("Bridge infill")) + "|" +
|
||||
_(L("Gap fill")) + "|" +
|
||||
_(L("Skirt")) + "|" +
|
||||
|
|
|
@ -61,7 +61,9 @@ void on_window_geometry(wxTopLevelWindow *tlw, std::function<void()> callback)
|
|||
#endif
|
||||
}
|
||||
|
||||
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
wxDEFINE_EVENT(EVT_DPI_CHANGED_SLICER, DpiChangedEvent);
|
||||
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
|
||||
|
||||
#ifdef _WIN32
|
||||
template<class F> typename F::FN winapi_get_function(const wchar_t *dll, const char *fn_name) {
|
||||
|
|
|
@ -24,6 +24,11 @@ class wxCheckBox;
|
|||
class wxTopLevelWindow;
|
||||
class wxRect;
|
||||
|
||||
#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||
#define wxVERSION_EQUAL_OR_GREATER_THAN(major, minor, release) ((wxMAJOR_VERSION > major) || ((wxMAJOR_VERSION == major) && (wxMINOR_VERSION > minor)) || ((wxMAJOR_VERSION == major) && (wxMINOR_VERSION == minor) && (wxRELEASE_NUMBER >= release)))
|
||||
#else
|
||||
#define wxVERSION_EQUAL_OR_GREATER_THAN(major, minor, release) 0
|
||||
#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
@ -51,6 +56,7 @@ enum { DPI_DEFAULT = 96 };
|
|||
int get_dpi_for_window(wxWindow *window);
|
||||
wxFont get_default_font_for_dpi(int dpi);
|
||||
|
||||
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
struct DpiChangedEvent : public wxEvent {
|
||||
int dpi;
|
||||
wxRect rect;
|
||||
|
@ -66,6 +72,7 @@ struct DpiChangedEvent : public wxEvent {
|
|||
};
|
||||
|
||||
wxDECLARE_EVENT(EVT_DPI_CHANGED_SLICER, DpiChangedEvent);
|
||||
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
|
||||
|
||||
template<class P> class DPIAware : public P
|
||||
{
|
||||
|
@ -86,10 +93,32 @@ public:
|
|||
this->SetFont(m_normal_font);
|
||||
#endif
|
||||
// initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window.
|
||||
#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||
m_em_unit = std::max<size_t>(10, 10.0f * m_scale_factor);
|
||||
#else
|
||||
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
|
||||
#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||
|
||||
// recalc_font();
|
||||
|
||||
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
this->Bind(wxEVT_DPI_CHANGED, [this](wxDPIChangedEvent& evt) {
|
||||
m_scale_factor = (float)evt.GetNewDPI().x / (float)DPI_DEFAULT;
|
||||
|
||||
m_new_font_point_size = get_default_font_for_dpi(evt.GetNewDPI().x).GetPointSize();
|
||||
|
||||
if (!m_can_rescale)
|
||||
return;
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
if (m_force_rescale || is_new_scale_factor())
|
||||
rescale(wxRect());
|
||||
#else
|
||||
if (is_new_scale_factor())
|
||||
rescale(wxRect());
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
});
|
||||
#else
|
||||
this->Bind(EVT_DPI_CHANGED_SLICER, [this](const DpiChangedEvent& evt) {
|
||||
m_scale_factor = (float)evt.dpi / (float)DPI_DEFAULT;
|
||||
|
||||
|
@ -98,9 +127,15 @@ public:
|
|||
if (!m_can_rescale)
|
||||
return;
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
if (m_force_rescale || is_new_scale_factor())
|
||||
rescale(evt.rect);
|
||||
#else
|
||||
if (is_new_scale_factor())
|
||||
rescale(evt.rect);
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
});
|
||||
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
|
||||
|
||||
this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event)
|
||||
{
|
||||
|
@ -140,6 +175,9 @@ public:
|
|||
int em_unit() const { return m_em_unit; }
|
||||
// int font_size() const { return m_font_size; }
|
||||
const wxFont& normal_font() const { return m_normal_font; }
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
void enable_force_rescale() { m_force_rescale = true; }
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
protected:
|
||||
virtual void on_dpi_changed(const wxRect &suggested_rect) = 0;
|
||||
|
@ -153,6 +191,9 @@ private:
|
|||
wxFont m_normal_font;
|
||||
float m_prev_scale_factor;
|
||||
bool m_can_rescale{ true };
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
bool m_force_rescale{ false };
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
int m_new_font_point_size;
|
||||
|
||||
|
@ -192,17 +233,27 @@ private:
|
|||
{
|
||||
this->Freeze();
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART && wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
if (m_force_rescale) {
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
// rescale fonts of all controls
|
||||
scale_controls_fonts(this, m_new_font_point_size);
|
||||
// rescale current window font
|
||||
scale_win_font(this, m_new_font_point_size);
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART && wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
m_force_rescale = false;
|
||||
}
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
// set normal application font as a current window font
|
||||
m_normal_font = this->GetFont();
|
||||
|
||||
// update em_unit value for new window font
|
||||
#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||
m_em_unit = std::max<int>(10, 10.0f * m_scale_factor);
|
||||
#else
|
||||
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
|
||||
#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||
|
||||
// rescale missed controls sizes and images
|
||||
on_dpi_changed(suggested_rect);
|
||||
|
@ -341,7 +392,7 @@ public:
|
|||
static WindowMetrics from_window(wxTopLevelWindow *window);
|
||||
static boost::optional<WindowMetrics> deserialize(const std::string &str);
|
||||
|
||||
wxRect get_rect() const { return rect; }
|
||||
const wxRect& get_rect() const { return rect; }
|
||||
bool get_maximized() const { return maximized; }
|
||||
|
||||
void sanitize_for_display(const wxRect &screen_rect);
|
||||
|
|
|
@ -448,6 +448,7 @@ void SupportsClipper::render_cut() const
|
|||
|
||||
// Get transformation of supports
|
||||
Geometry::Transformation supports_trafo = trafo;
|
||||
supports_trafo.set_scaling_factor(Vec3d::Ones());
|
||||
supports_trafo.set_offset(Vec3d(trafo.get_offset()(0), trafo.get_offset()(1), sel_info->get_sla_shift()));
|
||||
supports_trafo.set_rotation(Vec3d(0., 0., trafo.get_rotation()(2)));
|
||||
// I don't know why, but following seems to be correct.
|
||||
|
|
|
@ -42,10 +42,44 @@
|
|||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
enum class ERescaleTarget
|
||||
{
|
||||
Mainframe,
|
||||
SettingsDialog
|
||||
};
|
||||
|
||||
static void rescale_dialog_after_dpi_change(MainFrame& mainframe, SettingsDialog& dialog, ERescaleTarget target)
|
||||
{
|
||||
int mainframe_dpi = get_dpi_for_window(&mainframe);
|
||||
int dialog_dpi = get_dpi_for_window(&dialog);
|
||||
if (mainframe_dpi != dialog_dpi) {
|
||||
if (target == ERescaleTarget::SettingsDialog) {
|
||||
dialog.enable_force_rescale();
|
||||
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
dialog.GetEventHandler()->AddPendingEvent(wxDPIChangedEvent(wxSize(mainframe_dpi, mainframe_dpi), wxSize(dialog_dpi, dialog_dpi)));
|
||||
#else
|
||||
dialog.GetEventHandler()->AddPendingEvent(DpiChangedEvent(EVT_DPI_CHANGED_SLICER, dialog_dpi, dialog.GetRect()));
|
||||
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
|
||||
} else {
|
||||
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
mainframe.GetEventHandler()->AddPendingEvent(wxDPIChangedEvent(wxSize(dialog_dpi, dialog_dpi), wxSize(mainframe_dpi, mainframe_dpi)));
|
||||
#else
|
||||
mainframe.enable_force_rescale();
|
||||
mainframe.GetEventHandler()->AddPendingEvent(DpiChangedEvent(EVT_DPI_CHANGED_SLICER, mainframe_dpi, mainframe.GetRect()));
|
||||
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
MainFrame::MainFrame() :
|
||||
DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "mainframe"),
|
||||
m_printhost_queue_dlg(new PrintHostQueueDialog(this))
|
||||
, m_recent_projects(9)
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
, m_settings_dialog(this)
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
{
|
||||
// Fonts were created by the DPIFrame constructor for the monitor, on which the window opened.
|
||||
wxGetApp().update_fonts(this);
|
||||
|
@ -85,6 +119,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||
|
||||
m_loaded = true;
|
||||
|
||||
#if !ENABLE_LAYOUT_NO_RESTART
|
||||
#ifdef __APPLE__
|
||||
// Using SetMinSize() on Mac messes up the window position in some cases
|
||||
// cf. https://groups.google.com/forum/#!topic/wx-users/yUKPBBfXWO0
|
||||
|
@ -98,8 +133,19 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||
m_tabpanel->SetMinSize(size);
|
||||
}
|
||||
#endif
|
||||
#endif // !ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
// initialize layout
|
||||
auto sizer = new wxBoxSizer(wxVERTICAL);
|
||||
m_main_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
|
||||
sizer->Add(m_main_sizer, 1, wxEXPAND);
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
SetSizer(sizer);
|
||||
// initialize layout from config
|
||||
update_layout();
|
||||
sizer->SetSizeHints(this);
|
||||
Fit();
|
||||
#else
|
||||
if (m_plater && m_layout != slOld)
|
||||
sizer->Add(m_plater, 1, wxEXPAND);
|
||||
|
||||
|
@ -109,6 +155,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||
sizer->SetSizeHints(this);
|
||||
SetSizer(sizer);
|
||||
Fit();
|
||||
#endif // !ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
const wxSize min_size = wxGetApp().get_min_size(); //wxSize(76*wxGetApp().em_unit(), 49*wxGetApp().em_unit());
|
||||
#ifdef __APPLE__
|
||||
|
@ -200,8 +247,12 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||
});
|
||||
|
||||
wxGetApp().persist_window_geometry(this, true);
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
wxGetApp().persist_window_geometry(&m_settings_dialog, true);
|
||||
#else
|
||||
if (m_settings_dialog != nullptr)
|
||||
wxGetApp().persist_window_geometry(m_settings_dialog, true);
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
update_ui_from_settings(); // FIXME (?)
|
||||
|
||||
|
@ -209,6 +260,123 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||
m_plater->show_action_buttons(true);
|
||||
}
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
void MainFrame::update_layout()
|
||||
{
|
||||
auto restore_to_creation = [this]() {
|
||||
auto clean_sizer = [](wxSizer* sizer) {
|
||||
while (!sizer->GetChildren().IsEmpty()) {
|
||||
sizer->Detach(0);
|
||||
}
|
||||
};
|
||||
|
||||
// On Linux m_plater needs to be removed from m_tabpanel before to reparent it
|
||||
int plater_page_id = m_tabpanel->FindPage(m_plater);
|
||||
if (plater_page_id != wxNOT_FOUND)
|
||||
m_tabpanel->RemovePage(plater_page_id);
|
||||
|
||||
if (m_plater->GetParent() != this)
|
||||
m_plater->Reparent(this);
|
||||
|
||||
if (m_tabpanel->GetParent() != this)
|
||||
m_tabpanel->Reparent(this);
|
||||
|
||||
plater_page_id = (m_plater_page != nullptr) ? m_tabpanel->FindPage(m_plater_page) : wxNOT_FOUND;
|
||||
if (plater_page_id != wxNOT_FOUND) {
|
||||
m_tabpanel->DeletePage(plater_page_id);
|
||||
m_plater_page = nullptr;
|
||||
}
|
||||
|
||||
if (m_layout == ESettingsLayout::Dlg)
|
||||
rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::Mainframe);
|
||||
|
||||
clean_sizer(m_main_sizer);
|
||||
clean_sizer(m_settings_dialog.GetSizer());
|
||||
|
||||
if (m_settings_dialog.IsShown())
|
||||
m_settings_dialog.Close();
|
||||
|
||||
m_tabpanel->Hide();
|
||||
m_plater->Hide();
|
||||
|
||||
Layout();
|
||||
};
|
||||
|
||||
ESettingsLayout layout = wxGetApp().app_config->get("old_settings_layout_mode") == "1" ? ESettingsLayout::Old :
|
||||
wxGetApp().app_config->get("new_settings_layout_mode") == "1" ? ESettingsLayout::New :
|
||||
wxGetApp().app_config->get("dlg_settings_layout_mode") == "1" ? ESettingsLayout::Dlg : ESettingsLayout::Old;
|
||||
|
||||
if (m_layout == layout)
|
||||
return;
|
||||
|
||||
wxBusyCursor busy;
|
||||
|
||||
Freeze();
|
||||
|
||||
// Remove old settings
|
||||
if (m_layout != ESettingsLayout::Unknown)
|
||||
restore_to_creation();
|
||||
|
||||
m_layout = layout;
|
||||
|
||||
// From the very beginning the Print settings should be selected
|
||||
m_last_selected_tab = m_layout == ESettingsLayout::Dlg ? 0 : 1;
|
||||
|
||||
// Set new settings
|
||||
switch (m_layout)
|
||||
{
|
||||
case ESettingsLayout::Old:
|
||||
{
|
||||
m_plater->Reparent(m_tabpanel);
|
||||
m_tabpanel->InsertPage(0, m_plater, _L("Plater"));
|
||||
m_main_sizer->Add(m_tabpanel, 1, wxEXPAND);
|
||||
m_plater->Show();
|
||||
m_tabpanel->Show();
|
||||
break;
|
||||
}
|
||||
case ESettingsLayout::New:
|
||||
{
|
||||
m_main_sizer->Add(m_plater, 1, wxEXPAND);
|
||||
m_tabpanel->Hide();
|
||||
m_main_sizer->Add(m_tabpanel, 1, wxEXPAND);
|
||||
m_plater_page = new wxPanel(m_tabpanel);
|
||||
m_tabpanel->InsertPage(0, m_plater_page, _L("Plater")); // empty panel just for Plater tab */
|
||||
m_plater->Show();
|
||||
break;
|
||||
}
|
||||
case ESettingsLayout::Dlg:
|
||||
{
|
||||
m_main_sizer->Add(m_plater, 1, wxEXPAND);
|
||||
m_tabpanel->Reparent(&m_settings_dialog);
|
||||
m_settings_dialog.GetSizer()->Add(m_tabpanel, 1, wxEXPAND);
|
||||
|
||||
rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::SettingsDialog);
|
||||
|
||||
m_tabpanel->Show();
|
||||
m_plater->Show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//#ifdef __APPLE__
|
||||
// // Using SetMinSize() on Mac messes up the window position in some cases
|
||||
// // cf. https://groups.google.com/forum/#!topic/wx-users/yUKPBBfXWO0
|
||||
// // So, if we haven't possibility to set MinSize() for the MainFrame,
|
||||
// // set the MinSize() as a half of regular for the m_plater and m_tabpanel, when settings layout is in slNew mode
|
||||
// // Otherwise, MainFrame will be maximized by height
|
||||
// if (m_layout == ESettingsLayout::New) {
|
||||
// wxSize size = wxGetApp().get_min_size();
|
||||
// size.SetHeight(int(0.5 * size.GetHeight()));
|
||||
// m_plater->SetMinSize(size);
|
||||
// m_tabpanel->SetMinSize(size);
|
||||
// }
|
||||
//#endif
|
||||
|
||||
Layout();
|
||||
Thaw();
|
||||
}
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
// Called when closing the application and when switching the application language.
|
||||
void MainFrame::shutdown()
|
||||
{
|
||||
|
@ -241,6 +409,11 @@ void MainFrame::shutdown()
|
|||
// In addition, there were some crashes due to the Paint events sent to already destructed windows.
|
||||
this->Show(false);
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
if (m_settings_dialog.IsShown())
|
||||
// call Close() to trigger call to lambda defined into GUI_App::persist_window_geometry()
|
||||
m_settings_dialog.Close();
|
||||
#else
|
||||
if (m_settings_dialog != nullptr)
|
||||
{
|
||||
if (m_settings_dialog->IsShown())
|
||||
|
@ -249,6 +422,7 @@ void MainFrame::shutdown()
|
|||
|
||||
m_settings_dialog->Destroy();
|
||||
}
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
// Stop the background thread (Windows and Linux).
|
||||
// Disconnect from a 3DConnextion driver (OSX).
|
||||
|
@ -307,6 +481,16 @@ void MainFrame::update_title()
|
|||
|
||||
void MainFrame::init_tabpanel()
|
||||
{
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
// wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on Windows 10
|
||||
// with multiple high resolution displays connected.
|
||||
m_tabpanel = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME);
|
||||
#ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
|
||||
m_tabpanel->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||
#endif
|
||||
m_tabpanel->Hide();
|
||||
m_settings_dialog.set_tabpanel(m_tabpanel);
|
||||
#else
|
||||
m_layout = wxGetApp().app_config->get("old_settings_layout_mode") == "1" ? slOld :
|
||||
wxGetApp().app_config->get("new_settings_layout_mode") == "1" ? slNew :
|
||||
wxGetApp().app_config->get("dlg_settings_layout_mode") == "1" ? slDlg : slOld;
|
||||
|
@ -326,13 +510,14 @@ void MainFrame::init_tabpanel()
|
|||
m_tabpanel->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||
#endif
|
||||
}
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxEvent&) {
|
||||
wxWindow* panel = m_tabpanel->GetCurrentPage();
|
||||
Tab* tab = dynamic_cast<Tab*>(panel);
|
||||
|
||||
// There shouldn't be a case, when we try to select a tab, which doesn't support a printer technology
|
||||
if (panel == nullptr || (tab && ! tab->supports_printer_technology(m_plater->printer_technology())))
|
||||
if (panel == nullptr || (tab != nullptr && !tab->supports_printer_technology(m_plater->printer_technology())))
|
||||
return;
|
||||
|
||||
auto& tabs_list = wxGetApp().tabs_list;
|
||||
|
@ -346,6 +531,10 @@ void MainFrame::init_tabpanel()
|
|||
select_tab(0); // select Plater
|
||||
});
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
m_plater = new Plater(this, this);
|
||||
m_plater->Hide();
|
||||
#else
|
||||
if (m_layout == slOld) {
|
||||
m_plater = new Plater(m_tabpanel, this);
|
||||
m_tabpanel->AddPage(m_plater, _L("Plater"));
|
||||
|
@ -355,6 +544,7 @@ void MainFrame::init_tabpanel()
|
|||
if (m_layout == slNew)
|
||||
m_tabpanel->AddPage(new wxPanel(m_tabpanel), _L("Plater")); // empty panel just for Plater tab
|
||||
}
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
wxGetApp().plater_ = m_plater;
|
||||
|
||||
wxGetApp().obj_list()->create_popup_menus();
|
||||
|
@ -496,6 +686,18 @@ bool MainFrame::can_slice() const
|
|||
|
||||
bool MainFrame::can_change_view() const
|
||||
{
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
switch (m_layout)
|
||||
{
|
||||
default: { return false; }
|
||||
case ESettingsLayout::New: { return m_plater->IsShown(); }
|
||||
case ESettingsLayout::Dlg: { return true; }
|
||||
case ESettingsLayout::Old: {
|
||||
int page_id = m_tabpanel->GetSelection();
|
||||
return page_id != wxNOT_FOUND && dynamic_cast<const Slic3r::GUI::Plater*>(m_tabpanel->GetPage((size_t)page_id)) != nullptr;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (m_layout == slNew)
|
||||
return m_plater->IsShown();
|
||||
if (m_layout == slDlg)
|
||||
|
@ -503,6 +705,7 @@ bool MainFrame::can_change_view() const
|
|||
// slOld layout mode
|
||||
int page_id = m_tabpanel->GetSelection();
|
||||
return page_id != wxNOT_FOUND && dynamic_cast<const Slic3r::GUI::Plater*>(m_tabpanel->GetPage((size_t)page_id)) != nullptr;
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
}
|
||||
|
||||
bool MainFrame::can_select() const
|
||||
|
@ -532,14 +735,22 @@ bool MainFrame::can_reslice() const
|
|||
|
||||
void MainFrame::on_dpi_changed(const wxRect& suggested_rect)
|
||||
{
|
||||
#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||
wxGetApp().update_fonts(this);
|
||||
#else
|
||||
wxGetApp().update_fonts();
|
||||
#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||
this->SetFont(this->normal_font());
|
||||
|
||||
// update Plater
|
||||
wxGetApp().plater()->msw_rescale();
|
||||
|
||||
// update Tabs
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
if (m_layout != ESettingsLayout::Dlg) // Do not update tabs if the Settings are in the separated dialog
|
||||
#else
|
||||
if (m_layout != slDlg) // Update tabs later, from the SettingsDialog, when the Settings are in the separated dialog
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
for (auto tab : wxGetApp().tabs_list)
|
||||
tab->msw_rescale();
|
||||
|
||||
|
@ -567,6 +778,11 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect)
|
|||
this->SetSize(sz);
|
||||
|
||||
this->Maximize(is_maximized);
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
if (m_layout == ESettingsLayout::Dlg)
|
||||
rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::SettingsDialog);
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
}
|
||||
|
||||
void MainFrame::on_sys_color_changed()
|
||||
|
@ -1075,10 +1291,10 @@ void MainFrame::quick_slice(const int qs)
|
|||
}
|
||||
|
||||
// show processbar dialog
|
||||
m_progress_dialog = new wxProgressDialog(_(L("Slicing")) + dots,
|
||||
m_progress_dialog = new wxProgressDialog(_L("Slicing") + dots,
|
||||
// TRN "Processing input_file_basename"
|
||||
from_u8((boost::format(_utf8(L("Processing %s"))) % (input_file_basename + dots)).str()),
|
||||
100, this, 4);
|
||||
100, nullptr, wxPD_AUTO_HIDE);
|
||||
m_progress_dialog->Pulse();
|
||||
{
|
||||
// my @warnings = ();
|
||||
|
@ -1299,15 +1515,41 @@ void MainFrame::load_config(const DynamicPrintConfig& config)
|
|||
|
||||
void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
|
||||
{
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
if (m_layout == ESettingsLayout::Dlg) {
|
||||
#else
|
||||
if (m_layout == slDlg) {
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
if (tab==0) {
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
if (m_settings_dialog.IsShown())
|
||||
this->SetFocus();
|
||||
#else
|
||||
if (m_settings_dialog->IsShown())
|
||||
this->SetFocus();
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
// plater should be focused for correct navigation inside search window
|
||||
if (m_plater->canvas3D()->is_search_pressed())
|
||||
m_plater->SetFocus();
|
||||
return;
|
||||
}
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
// Show/Activate Settings Dialog
|
||||
#ifdef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
|
||||
if (m_settings_dialog.IsShown())
|
||||
m_settings_dialog.Hide();
|
||||
|
||||
m_tabpanel->Show();
|
||||
m_settings_dialog.Show();
|
||||
#else
|
||||
if (m_settings_dialog.IsShown())
|
||||
m_settings_dialog.SetFocus();
|
||||
else {
|
||||
m_tabpanel->Show();
|
||||
m_settings_dialog.Show();
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
// Show/Activate Settings Dialog
|
||||
if (m_settings_dialog->IsShown())
|
||||
#ifdef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
|
||||
|
@ -1317,10 +1559,17 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
|
|||
else
|
||||
#endif
|
||||
m_settings_dialog->Show();
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
}
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
else if (m_layout == ESettingsLayout::New) {
|
||||
m_main_sizer->Show(m_plater, tab == 0);
|
||||
m_main_sizer->Show(m_tabpanel, tab != 0);
|
||||
#else
|
||||
else if (m_layout == slNew) {
|
||||
m_plater->Show(tab == 0);
|
||||
m_tabpanel->Show(tab != 0);
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
// plater should be focused for correct navigation inside search window
|
||||
if (tab == 0 && m_plater->canvas3D()->is_search_pressed())
|
||||
|
@ -1328,8 +1577,12 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/)
|
|||
Layout();
|
||||
}
|
||||
|
||||
// when tab == -1, it means we should to show the last selected tab
|
||||
// when tab == -1, it means we should show the last selected tab
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
m_tabpanel->SetSelection(tab == (size_t)(-1) ? m_last_selected_tab : (m_layout == ESettingsLayout::Dlg && tab != 0) ? tab - 1 : tab);
|
||||
#else
|
||||
m_tabpanel->SetSelection(tab == (size_t)(-1) ? m_last_selected_tab : (m_layout == slDlg && tab != 0) ? tab-1 : tab);
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
}
|
||||
|
||||
// Set a camera direction, zoom to all objects.
|
||||
|
@ -1440,14 +1693,12 @@ std::string MainFrame::get_dir_name(const wxString &full_name) const
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
SettingsDialog::SettingsDialog(MainFrame* mainframe)
|
||||
: DPIDialog(nullptr, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings"), wxDefaultPosition, wxDefaultSize,
|
||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxDIALOG_NO_PARENT, "settings_dialog"),
|
||||
: DPIDialog(mainframe, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings"), wxDefaultPosition, wxDefaultSize,
|
||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX, "settings_dialog"),
|
||||
m_main_frame(mainframe)
|
||||
{
|
||||
this->SetFont(wxGetApp().normal_font());
|
||||
|
||||
wxColour bgr_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
this->SetBackgroundColour(bgr_clr);
|
||||
this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
|
||||
// Load the icon either from the exe, or from the ico file.
|
||||
#if _WIN32
|
||||
|
@ -1460,6 +1711,7 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe)
|
|||
SetIcon(wxIcon(var("PrusaSlicer_128px.png"), wxBITMAP_TYPE_PNG));
|
||||
#endif // _WIN32
|
||||
|
||||
#if !ENABLE_LAYOUT_NO_RESTART
|
||||
// wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on Windows 10
|
||||
// with multiple high resolution displays connected.
|
||||
m_tabpanel = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxGetApp().get_min_size(), wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME);
|
||||
|
@ -1484,10 +1736,45 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe)
|
|||
}
|
||||
}
|
||||
});
|
||||
#endif // !ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
this->Bind(wxEVT_SHOW, [this](wxShowEvent& evt) {
|
||||
|
||||
auto key_up_handker = [this](wxKeyEvent& evt) {
|
||||
if ((evt.GetModifiers() & wxMOD_CONTROL) != 0) {
|
||||
switch (evt.GetKeyCode()) {
|
||||
case '1': { m_main_frame->select_tab(0); break; }
|
||||
case '2': { m_main_frame->select_tab(1); break; }
|
||||
case '3': { m_main_frame->select_tab(2); break; }
|
||||
case '4': { m_main_frame->select_tab(3); break; }
|
||||
#ifdef __APPLE__
|
||||
case 'f':
|
||||
#else /* __APPLE__ */
|
||||
case WXK_CONTROL_F:
|
||||
#endif /* __APPLE__ */
|
||||
case 'F': { m_main_frame->plater()->search(false); break; }
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (evt.IsShown()) {
|
||||
if (m_tabpanel != nullptr)
|
||||
m_tabpanel->Bind(wxEVT_KEY_UP, key_up_handker);
|
||||
}
|
||||
else {
|
||||
if (m_tabpanel != nullptr)
|
||||
m_tabpanel->Unbind(wxEVT_KEY_UP, key_up_handker);
|
||||
}
|
||||
});
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
// initialize layout
|
||||
auto sizer = new wxBoxSizer(wxVERTICAL);
|
||||
#if !ENABLE_LAYOUT_NO_RESTART
|
||||
sizer->Add(m_tabpanel, 1, wxEXPAND);
|
||||
#endif // !ENABLE_LAYOUT_NO_RESTART
|
||||
sizer->SetSizeHints(this);
|
||||
SetSizer(sizer);
|
||||
Fit();
|
||||
|
|
|
@ -55,7 +55,11 @@ class SettingsDialog : public DPIDialog
|
|||
public:
|
||||
SettingsDialog(MainFrame* mainframe);
|
||||
~SettingsDialog() {}
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
void set_tabpanel(wxNotebook* tabpanel) { m_tabpanel = tabpanel; }
|
||||
#else
|
||||
wxNotebook* get_tabpanel() { return m_tabpanel; }
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
protected:
|
||||
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||
|
@ -72,6 +76,7 @@ class MainFrame : public DPIFrame
|
|||
wxMenuItem* m_menu_item_repeat { nullptr }; // doesn't used now
|
||||
#endif
|
||||
wxMenuItem* m_menu_item_reslice_now { nullptr };
|
||||
wxSizer* m_main_sizer{ nullptr };
|
||||
|
||||
PrintHostQueueDialog *m_printhost_queue_dlg;
|
||||
|
||||
|
@ -114,11 +119,23 @@ class MainFrame : public DPIFrame
|
|||
|
||||
wxFileHistory m_recent_projects;
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
enum class ESettingsLayout
|
||||
{
|
||||
Unknown,
|
||||
Old,
|
||||
New,
|
||||
Dlg,
|
||||
};
|
||||
|
||||
ESettingsLayout m_layout{ ESettingsLayout::Unknown };
|
||||
#else
|
||||
enum SettingsLayout {
|
||||
slOld = 0,
|
||||
slNew,
|
||||
slDlg,
|
||||
} m_layout;
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
protected:
|
||||
virtual void on_dpi_changed(const wxRect &suggested_rect);
|
||||
|
@ -128,6 +145,10 @@ public:
|
|||
MainFrame();
|
||||
~MainFrame() = default;
|
||||
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
void update_layout();
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
// Called when closing the application and when switching the application language.
|
||||
void shutdown();
|
||||
|
||||
|
@ -169,7 +190,12 @@ public:
|
|||
|
||||
Plater* m_plater { nullptr };
|
||||
wxNotebook* m_tabpanel { nullptr };
|
||||
#if ENABLE_LAYOUT_NO_RESTART
|
||||
SettingsDialog m_settings_dialog;
|
||||
wxWindow* m_plater_page{ nullptr };
|
||||
#else
|
||||
SettingsDialog* m_settings_dialog { nullptr };
|
||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||
wxProgressDialog* m_progress_dialog { nullptr };
|
||||
std::shared_ptr<ProgressStatusBar> m_statusbar;
|
||||
|
||||
|
|
|
@ -1929,9 +1929,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
|||
// collapse sidebar according to saved value
|
||||
bool is_collapsed = wxGetApp().app_config->get("collapsed_sidebar") == "1";
|
||||
sidebar->collapse(is_collapsed);
|
||||
// Update an enable of the collapse_toolbar: if sidebar is collapsed, then collapse_toolbar should be visible
|
||||
if (is_collapsed)
|
||||
wxGetApp().app_config->set("show_collapse_button", "1");
|
||||
}
|
||||
|
||||
Plater::priv::~priv()
|
||||
|
@ -2055,17 +2052,17 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||
}
|
||||
|
||||
const auto loading = _L("Loading") + dots;
|
||||
wxProgressDialog dlg(loading, loading);
|
||||
wxProgressDialog dlg(loading, "", 100, q, wxPD_AUTO_HIDE);
|
||||
dlg.Pulse();
|
||||
|
||||
auto *new_model = (!load_model || one_by_one) ? nullptr : new Slic3r::Model();
|
||||
std::vector<size_t> obj_idxs;
|
||||
|
||||
for (size_t i = 0; i < input_files.size(); i++) {
|
||||
for (size_t i = 0; i < input_files.size(); ++i) {
|
||||
const auto &path = input_files[i];
|
||||
const auto filename = path.filename();
|
||||
const auto dlg_info = format_wxstr(_L("Processing input file %s"), from_path(filename)) + "\n";
|
||||
dlg.Update(100 * i / input_files.size(), dlg_info);
|
||||
const auto dlg_info = _L("Loading file") + ": " + from_path(filename);
|
||||
dlg.Update(static_cast<int>(100.0f * static_cast<float>(i) / static_cast<float>(input_files.size())), dlg_info);
|
||||
|
||||
const bool type_3mf = std::regex_match(path.string(), pattern_3mf);
|
||||
const bool type_zip_amf = !type_3mf && std::regex_match(path.string(), pattern_zip_amf);
|
||||
|
@ -3268,6 +3265,27 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt)
|
|||
// Update the SLA preview. Only called if not RELOAD_SLA_SUPPORT_POINTS, as the block above will refresh the preview anyways.
|
||||
this->preview->reload_print();
|
||||
}
|
||||
|
||||
if (evt.status.flags & (PrintBase::SlicingStatus::UPDATE_PRINT_STEP_WARNINGS | PrintBase::SlicingStatus::UPDATE_PRINT_OBJECT_STEP_WARNINGS)) {
|
||||
// Update notification center with warnings of object_id and its warning_step.
|
||||
ObjectID object_id = evt.status.warning_object_id;
|
||||
int warning_step = evt.status.warning_step;
|
||||
PrintStateBase::StateWithWarnings state;
|
||||
if (evt.status.flags & PrintBase::SlicingStatus::UPDATE_PRINT_STEP_WARNINGS) {
|
||||
state = this->printer_technology == ptFFF ?
|
||||
this->fff_print.step_state_with_warnings(static_cast<PrintStep>(warning_step)) :
|
||||
this->sla_print.step_state_with_warnings(static_cast<SLAPrintStep>(warning_step));
|
||||
} else if (this->printer_technology == ptFFF) {
|
||||
const PrintObject *print_object = this->fff_print.get_object(object_id);
|
||||
if (print_object)
|
||||
state = print_object->step_state_with_warnings(static_cast<PrintObjectStep>(warning_step));
|
||||
} else {
|
||||
const SLAPrintObject *print_object = this->sla_print.get_object(object_id);
|
||||
if (print_object)
|
||||
state = print_object->step_state_with_warnings(static_cast<SLAPrintObjectStep>(warning_step));
|
||||
}
|
||||
// Now process state.warnings.
|
||||
}
|
||||
}
|
||||
|
||||
void Plater::priv::on_slicing_completed(wxCommandEvent &)
|
||||
|
@ -4704,25 +4722,33 @@ void Plater::export_stl(bool extended, bool selection_only)
|
|||
? Transform3d::Identity()
|
||||
: object->model_object()->instances[instance_idx]->get_transformation().get_matrix();
|
||||
|
||||
TriangleMesh inst_mesh;
|
||||
|
||||
if (has_pad_mesh)
|
||||
{
|
||||
TriangleMesh inst_pad_mesh = pad_mesh;
|
||||
inst_pad_mesh.transform(inst_transform, is_left_handed);
|
||||
mesh.merge(inst_pad_mesh);
|
||||
inst_mesh.merge(inst_pad_mesh);
|
||||
}
|
||||
|
||||
if (has_supports_mesh)
|
||||
{
|
||||
TriangleMesh inst_supports_mesh = supports_mesh;
|
||||
inst_supports_mesh.transform(inst_transform, is_left_handed);
|
||||
mesh.merge(inst_supports_mesh);
|
||||
inst_mesh.merge(inst_supports_mesh);
|
||||
}
|
||||
|
||||
TriangleMesh inst_object_mesh = object->get_mesh_to_print();
|
||||
inst_object_mesh.transform(mesh_trafo_inv);
|
||||
inst_object_mesh.transform(inst_transform, is_left_handed);
|
||||
|
||||
mesh.merge(inst_object_mesh);
|
||||
inst_mesh.merge(inst_object_mesh);
|
||||
|
||||
// ensure that the instance lays on the bed
|
||||
inst_mesh.translate(0.0f, 0.0f, -inst_mesh.bounding_box().min[2]);
|
||||
|
||||
// merge instance with global mesh
|
||||
mesh.merge(inst_mesh);
|
||||
|
||||
if (one_inst_only)
|
||||
break;
|
||||
|
|
|
@ -161,7 +161,7 @@ void PreferencesDialog::build()
|
|||
}
|
||||
};
|
||||
|
||||
def.label = L("Show the button for the collapse sidebar");
|
||||
def.label = L("Show sidebar collapse/expand button");
|
||||
def.type = coBool;
|
||||
def.tooltip = L("If enabled, the button for the collapse sidebar will be appeared in top right corner of the 3D Scene");
|
||||
def.set_default_value(new ConfigOptionBool{ app_config->get("show_collapse_button") == "1" });
|
||||
|
@ -234,6 +234,7 @@ void PreferencesDialog::accept()
|
|||
}
|
||||
}
|
||||
|
||||
#if !ENABLE_LAYOUT_NO_RESTART
|
||||
if (m_settings_layout_changed) {
|
||||
// the dialog needs to be destroyed before the call to recreate_gui()
|
||||
// or sometimes the application crashes into wxDialogBase() destructor
|
||||
|
@ -255,6 +256,7 @@ void PreferencesDialog::accept()
|
|||
return;
|
||||
}
|
||||
}
|
||||
#endif // !ENABLE_LAYOUT_NO_RESTART
|
||||
|
||||
for (std::map<std::string, std::string>::iterator it = m_values.begin(); it != m_values.end(); ++it)
|
||||
app_config->set(it->first, it->second);
|
||||
|
@ -351,9 +353,9 @@ void PreferencesDialog::create_icon_size_slider()
|
|||
|
||||
void PreferencesDialog::create_settings_mode_widget()
|
||||
{
|
||||
wxString choices[] = { _L("Old regular layout with tab bar"),
|
||||
_L("New layout without the tab bar on the platter"),
|
||||
_L("Settings will be shown in non-modal dialog") };
|
||||
wxString choices[] = { _L("Old regular layout with the tab bar"),
|
||||
_L("New layout without the tab bar on the plater"),
|
||||
_L("Settings will be shown in the non-modal dialog") };
|
||||
|
||||
auto app_config = get_app_config();
|
||||
int selection = app_config->get("old_settings_layout_mode") == "1" ? 0 :
|
||||
|
|
|
@ -617,7 +617,8 @@ void SearchDialog::update_list()
|
|||
for (const FoundOption& item : filters)
|
||||
search_list_model->Prepend(item.label);
|
||||
|
||||
// select first item
|
||||
// select first item, if search_list
|
||||
if (search_list_model->GetCount() > 0)
|
||||
search_list->Select(search_list_model->GetItem(0));
|
||||
prevent_list_events = false;
|
||||
}
|
||||
|
|
|
@ -337,8 +337,8 @@ void fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx)
|
|||
|
||||
// Open a progress dialog.
|
||||
wxProgressDialog progress_dialog(
|
||||
_(L("Model fixing")),
|
||||
_(L("Exporting model...")),
|
||||
_L("Model fixing"),
|
||||
_L("Exporting model") + "...",
|
||||
100, nullptr, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
|
||||
// Executing the calculation in a background thread, so that the COM context could be created with its own threading model.
|
||||
// (It seems like wxWidgets initialize the COM contex as single threaded and we need a multi-threaded context).
|
||||
|
|
|
@ -19,5 +19,9 @@ add_executable(${_TEST_NAME}_tests
|
|||
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
|
||||
if (WIN32)
|
||||
prusaslicer_copy_dlls(${_TEST_NAME}_tests)
|
||||
endif()
|
||||
|
||||
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
|
||||
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests ${CATCH_EXTRA_ARGS})
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
#include <catch2/catch.hpp>
|
||||
#include <test_utils.hpp>
|
||||
|
||||
#include <stack>
|
||||
|
||||
#include <libslic3r/Polygon.hpp>
|
||||
#include <libslic3r/Polyline.hpp>
|
||||
#include <libslic3r/EdgeGrid.hpp>
|
||||
#include <libslic3r/Geometry.hpp>
|
||||
|
||||
#include <libslic3r/VoronoiOffset.hpp>
|
||||
|
||||
#define BOOST_VORONOI_USE_GMP 1
|
||||
#include "boost/polygon/voronoi.hpp"
|
||||
#include <numeric>
|
||||
|
||||
// #define VORONOI_DEBUG_OUT
|
||||
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
#include <libslic3r/VoronoiVisualUtils.hpp>
|
||||
#endif
|
||||
|
||||
using boost::polygon::voronoi_builder;
|
||||
using boost::polygon::voronoi_diagram;
|
||||
|
@ -19,400 +23,6 @@ using namespace Slic3r;
|
|||
|
||||
using VD = Geometry::VoronoiDiagram;
|
||||
|
||||
// #define VORONOI_DEBUG_OUT
|
||||
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
#include <libslic3r/SVG.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
namespace boost { namespace polygon {
|
||||
|
||||
// The following code for the visualization of the boost Voronoi diagram is based on:
|
||||
//
|
||||
// Boost.Polygon library voronoi_graphic_utils.hpp header file
|
||||
// Copyright Andrii Sydorchuk 2010-2012.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
template <typename CT>
|
||||
class voronoi_visual_utils {
|
||||
public:
|
||||
// Discretize parabolic Voronoi edge.
|
||||
// Parabolic Voronoi edges are always formed by one point and one segment
|
||||
// from the initial input set.
|
||||
//
|
||||
// Args:
|
||||
// point: input point.
|
||||
// segment: input segment.
|
||||
// max_dist: maximum discretization distance.
|
||||
// discretization: point discretization of the given Voronoi edge.
|
||||
//
|
||||
// Template arguments:
|
||||
// InCT: coordinate type of the input geometries (usually integer).
|
||||
// Point: point type, should model point concept.
|
||||
// Segment: segment type, should model segment concept.
|
||||
//
|
||||
// Important:
|
||||
// discretization should contain both edge endpoints initially.
|
||||
template <class InCT1, class InCT2,
|
||||
template<class> class Point,
|
||||
template<class> class Segment>
|
||||
static
|
||||
typename enable_if<
|
||||
typename gtl_and<
|
||||
typename gtl_if<
|
||||
typename is_point_concept<
|
||||
typename geometry_concept< Point<InCT1> >::type
|
||||
>::type
|
||||
>::type,
|
||||
typename gtl_if<
|
||||
typename is_segment_concept<
|
||||
typename geometry_concept< Segment<InCT2> >::type
|
||||
>::type
|
||||
>::type
|
||||
>::type,
|
||||
void
|
||||
>::type discretize(
|
||||
const Point<InCT1>& point,
|
||||
const Segment<InCT2>& segment,
|
||||
const CT max_dist,
|
||||
std::vector< Point<CT> >* discretization) {
|
||||
// Apply the linear transformation to move start point of the segment to
|
||||
// the point with coordinates (0, 0) and the direction of the segment to
|
||||
// coincide the positive direction of the x-axis.
|
||||
CT segm_vec_x = cast(x(high(segment))) - cast(x(low(segment)));
|
||||
CT segm_vec_y = cast(y(high(segment))) - cast(y(low(segment)));
|
||||
CT sqr_segment_length = segm_vec_x * segm_vec_x + segm_vec_y * segm_vec_y;
|
||||
|
||||
// Compute x-coordinates of the endpoints of the edge
|
||||
// in the transformed space.
|
||||
CT projection_start = sqr_segment_length *
|
||||
get_point_projection((*discretization)[0], segment);
|
||||
CT projection_end = sqr_segment_length *
|
||||
get_point_projection((*discretization)[1], segment);
|
||||
|
||||
// Compute parabola parameters in the transformed space.
|
||||
// Parabola has next representation:
|
||||
// f(x) = ((x-rot_x)^2 + rot_y^2) / (2.0*rot_y).
|
||||
CT point_vec_x = cast(x(point)) - cast(x(low(segment)));
|
||||
CT point_vec_y = cast(y(point)) - cast(y(low(segment)));
|
||||
CT rot_x = segm_vec_x * point_vec_x + segm_vec_y * point_vec_y;
|
||||
CT rot_y = segm_vec_x * point_vec_y - segm_vec_y * point_vec_x;
|
||||
|
||||
// Save the last point.
|
||||
Point<CT> last_point = (*discretization)[1];
|
||||
discretization->pop_back();
|
||||
|
||||
// Use stack to avoid recursion.
|
||||
std::stack<CT> point_stack;
|
||||
point_stack.push(projection_end);
|
||||
CT cur_x = projection_start;
|
||||
CT cur_y = parabola_y(cur_x, rot_x, rot_y);
|
||||
|
||||
// Adjust max_dist parameter in the transformed space.
|
||||
const CT max_dist_transformed = max_dist * max_dist * sqr_segment_length;
|
||||
while (!point_stack.empty()) {
|
||||
CT new_x = point_stack.top();
|
||||
CT new_y = parabola_y(new_x, rot_x, rot_y);
|
||||
|
||||
// Compute coordinates of the point of the parabola that is
|
||||
// furthest from the current line segment.
|
||||
CT mid_x = (new_y - cur_y) / (new_x - cur_x) * rot_y + rot_x;
|
||||
CT mid_y = parabola_y(mid_x, rot_x, rot_y);
|
||||
|
||||
// Compute maximum distance between the given parabolic arc
|
||||
// and line segment that discretize it.
|
||||
CT dist = (new_y - cur_y) * (mid_x - cur_x) -
|
||||
(new_x - cur_x) * (mid_y - cur_y);
|
||||
dist = dist * dist / ((new_y - cur_y) * (new_y - cur_y) +
|
||||
(new_x - cur_x) * (new_x - cur_x));
|
||||
if (dist <= max_dist_transformed) {
|
||||
// Distance between parabola and line segment is less than max_dist.
|
||||
point_stack.pop();
|
||||
CT inter_x = (segm_vec_x * new_x - segm_vec_y * new_y) /
|
||||
sqr_segment_length + cast(x(low(segment)));
|
||||
CT inter_y = (segm_vec_x * new_y + segm_vec_y * new_x) /
|
||||
sqr_segment_length + cast(y(low(segment)));
|
||||
discretization->push_back(Point<CT>(inter_x, inter_y));
|
||||
cur_x = new_x;
|
||||
cur_y = new_y;
|
||||
} else {
|
||||
point_stack.push(mid_x);
|
||||
}
|
||||
}
|
||||
|
||||
// Update last point.
|
||||
discretization->back() = last_point;
|
||||
}
|
||||
|
||||
private:
|
||||
// Compute y(x) = ((x - a) * (x - a) + b * b) / (2 * b).
|
||||
static CT parabola_y(CT x, CT a, CT b) {
|
||||
return ((x - a) * (x - a) + b * b) / (b + b);
|
||||
}
|
||||
|
||||
// Get normalized length of the distance between:
|
||||
// 1) point projection onto the segment
|
||||
// 2) start point of the segment
|
||||
// Return this length divided by the segment length. This is made to avoid
|
||||
// sqrt computation during transformation from the initial space to the
|
||||
// transformed one and vice versa. The assumption is made that projection of
|
||||
// the point lies between the start-point and endpoint of the segment.
|
||||
template <class InCT,
|
||||
template<class> class Point,
|
||||
template<class> class Segment>
|
||||
static
|
||||
typename enable_if<
|
||||
typename gtl_and<
|
||||
typename gtl_if<
|
||||
typename is_point_concept<
|
||||
typename geometry_concept< Point<int> >::type
|
||||
>::type
|
||||
>::type,
|
||||
typename gtl_if<
|
||||
typename is_segment_concept<
|
||||
typename geometry_concept< Segment<long> >::type
|
||||
>::type
|
||||
>::type
|
||||
>::type,
|
||||
CT
|
||||
>::type get_point_projection(
|
||||
const Point<CT>& point, const Segment<InCT>& segment) {
|
||||
CT segment_vec_x = cast(x(high(segment))) - cast(x(low(segment)));
|
||||
CT segment_vec_y = cast(y(high(segment))) - cast(y(low(segment)));
|
||||
CT point_vec_x = x(point) - cast(x(low(segment)));
|
||||
CT point_vec_y = y(point) - cast(y(low(segment)));
|
||||
CT sqr_segment_length =
|
||||
segment_vec_x * segment_vec_x + segment_vec_y * segment_vec_y;
|
||||
CT vec_dot = segment_vec_x * point_vec_x + segment_vec_y * point_vec_y;
|
||||
return vec_dot / sqr_segment_length;
|
||||
}
|
||||
|
||||
template <typename InCT>
|
||||
static CT cast(const InCT& value) {
|
||||
return static_cast<CT>(value);
|
||||
}
|
||||
};
|
||||
|
||||
} } // namespace boost::polygon
|
||||
|
||||
// The following code for the visualization of the boost Voronoi diagram is based on:
|
||||
//
|
||||
// Boost.Polygon library voronoi_visualizer.cpp file
|
||||
// Copyright Andrii Sydorchuk 2010-2012.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
namespace Voronoi { namespace Internal {
|
||||
|
||||
typedef double coordinate_type;
|
||||
typedef boost::polygon::point_data<coordinate_type> point_type;
|
||||
typedef boost::polygon::segment_data<coordinate_type> segment_type;
|
||||
typedef boost::polygon::rectangle_data<coordinate_type> rect_type;
|
||||
typedef boost::polygon::voronoi_diagram<coordinate_type> VD;
|
||||
typedef VD::cell_type cell_type;
|
||||
typedef VD::cell_type::source_index_type source_index_type;
|
||||
typedef VD::cell_type::source_category_type source_category_type;
|
||||
typedef VD::edge_type edge_type;
|
||||
typedef VD::cell_container_type cell_container_type;
|
||||
typedef VD::cell_container_type vertex_container_type;
|
||||
typedef VD::edge_container_type edge_container_type;
|
||||
typedef VD::const_cell_iterator const_cell_iterator;
|
||||
typedef VD::const_vertex_iterator const_vertex_iterator;
|
||||
typedef VD::const_edge_iterator const_edge_iterator;
|
||||
|
||||
static const std::size_t EXTERNAL_COLOR = 1;
|
||||
|
||||
inline void color_exterior(const VD::edge_type* edge)
|
||||
{
|
||||
if (edge->color() == EXTERNAL_COLOR)
|
||||
return;
|
||||
edge->color(EXTERNAL_COLOR);
|
||||
edge->twin()->color(EXTERNAL_COLOR);
|
||||
const VD::vertex_type* v = edge->vertex1();
|
||||
if (v == NULL || !edge->is_primary())
|
||||
return;
|
||||
v->color(EXTERNAL_COLOR);
|
||||
const VD::edge_type* e = v->incident_edge();
|
||||
do {
|
||||
color_exterior(e);
|
||||
e = e->rot_next();
|
||||
} while (e != v->incident_edge());
|
||||
}
|
||||
|
||||
inline point_type retrieve_point(const Points &points, const std::vector<segment_type> &segments, const cell_type& cell)
|
||||
{
|
||||
assert(cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_START_POINT || cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_END_POINT ||
|
||||
cell.source_category() == boost::polygon::SOURCE_CATEGORY_SINGLE_POINT);
|
||||
return cell.source_category() == boost::polygon::SOURCE_CATEGORY_SINGLE_POINT ?
|
||||
Voronoi::Internal::point_type(double(points[cell.source_index()].x()), double(points[cell.source_index()].y())) :
|
||||
(cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_START_POINT) ?
|
||||
low(segments[cell.source_index()]) : high(segments[cell.source_index()]);
|
||||
}
|
||||
|
||||
inline void clip_infinite_edge(const Points &points, const std::vector<segment_type> &segments, const edge_type& edge, coordinate_type bbox_max_size, std::vector<point_type>* clipped_edge)
|
||||
{
|
||||
const cell_type& cell1 = *edge.cell();
|
||||
const cell_type& cell2 = *edge.twin()->cell();
|
||||
point_type origin, direction;
|
||||
// Infinite edges could not be created by two segment sites.
|
||||
if (! cell1.contains_point() && ! cell2.contains_point()) {
|
||||
printf("Error! clip_infinite_edge - infinite edge separates two segment cells\n");
|
||||
return;
|
||||
}
|
||||
if (cell1.contains_point() && cell2.contains_point()) {
|
||||
point_type p1 = retrieve_point(points, segments, cell1);
|
||||
point_type p2 = retrieve_point(points, segments, cell2);
|
||||
origin.x((p1.x() + p2.x()) * 0.5);
|
||||
origin.y((p1.y() + p2.y()) * 0.5);
|
||||
direction.x(p1.y() - p2.y());
|
||||
direction.y(p2.x() - p1.x());
|
||||
} else {
|
||||
origin = cell1.contains_segment() ? retrieve_point(points, segments, cell2) : retrieve_point(points, segments, cell1);
|
||||
segment_type segment = cell1.contains_segment() ? segments[cell1.source_index()] : segments[cell2.source_index()];
|
||||
coordinate_type dx = high(segment).x() - low(segment).x();
|
||||
coordinate_type dy = high(segment).y() - low(segment).y();
|
||||
if ((low(segment) == origin) ^ cell1.contains_point()) {
|
||||
direction.x(dy);
|
||||
direction.y(-dx);
|
||||
} else {
|
||||
direction.x(-dy);
|
||||
direction.y(dx);
|
||||
}
|
||||
}
|
||||
coordinate_type koef = bbox_max_size / (std::max)(fabs(direction.x()), fabs(direction.y()));
|
||||
if (edge.vertex0() == NULL) {
|
||||
clipped_edge->push_back(point_type(
|
||||
origin.x() - direction.x() * koef,
|
||||
origin.y() - direction.y() * koef));
|
||||
} else {
|
||||
clipped_edge->push_back(
|
||||
point_type(edge.vertex0()->x(), edge.vertex0()->y()));
|
||||
}
|
||||
if (edge.vertex1() == NULL) {
|
||||
clipped_edge->push_back(point_type(
|
||||
origin.x() + direction.x() * koef,
|
||||
origin.y() + direction.y() * koef));
|
||||
} else {
|
||||
clipped_edge->push_back(
|
||||
point_type(edge.vertex1()->x(), edge.vertex1()->y()));
|
||||
}
|
||||
}
|
||||
|
||||
inline void sample_curved_edge(const Points &points, const std::vector<segment_type> &segments, const edge_type& edge, std::vector<point_type> &sampled_edge, coordinate_type max_dist)
|
||||
{
|
||||
point_type point = edge.cell()->contains_point() ?
|
||||
retrieve_point(points, segments, *edge.cell()) :
|
||||
retrieve_point(points, segments, *edge.twin()->cell());
|
||||
segment_type segment = edge.cell()->contains_point() ?
|
||||
segments[edge.twin()->cell()->source_index()] :
|
||||
segments[edge.cell()->source_index()];
|
||||
::boost::polygon::voronoi_visual_utils<coordinate_type>::discretize(point, segment, max_dist, &sampled_edge);
|
||||
}
|
||||
|
||||
} /* namespace Internal */ } // namespace Voronoi
|
||||
|
||||
static inline void dump_voronoi_to_svg(
|
||||
const char *path,
|
||||
/* const */ VD &vd,
|
||||
const Points &points,
|
||||
const Lines &lines,
|
||||
const Polygons &offset_curves = Polygons(),
|
||||
const double scale = 0.7) // 0.2?
|
||||
{
|
||||
const std::string inputSegmentPointColor = "lightseagreen";
|
||||
const coord_t inputSegmentPointRadius = coord_t(0.09 * scale / SCALING_FACTOR);
|
||||
const std::string inputSegmentColor = "lightseagreen";
|
||||
const coord_t inputSegmentLineWidth = coord_t(0.03 * scale / SCALING_FACTOR);
|
||||
|
||||
const std::string voronoiPointColor = "black";
|
||||
const coord_t voronoiPointRadius = coord_t(0.06 * scale / SCALING_FACTOR);
|
||||
const std::string voronoiLineColorPrimary = "black";
|
||||
const std::string voronoiLineColorSecondary = "green";
|
||||
const std::string voronoiArcColor = "red";
|
||||
const coord_t voronoiLineWidth = coord_t(0.02 * scale / SCALING_FACTOR);
|
||||
|
||||
const std::string offsetCurveColor = "magenta";
|
||||
const coord_t offsetCurveLineWidth = coord_t(0.09 * scale / SCALING_FACTOR);
|
||||
|
||||
const bool internalEdgesOnly = false;
|
||||
const bool primaryEdgesOnly = false;
|
||||
|
||||
BoundingBox bbox;
|
||||
bbox.merge(get_extents(points));
|
||||
bbox.merge(get_extents(lines));
|
||||
bbox.min -= (0.01 * bbox.size().cast<double>()).cast<coord_t>();
|
||||
bbox.max += (0.01 * bbox.size().cast<double>()).cast<coord_t>();
|
||||
|
||||
::Slic3r::SVG svg(path, bbox);
|
||||
|
||||
// bbox.scale(1.2);
|
||||
// For clipping of half-lines to some reasonable value.
|
||||
// The line will then be clipped by the SVG viewer anyway.
|
||||
const double bbox_dim_max = double(std::max(bbox.size().x(), bbox.size().y()));
|
||||
// For the discretization of the Voronoi parabolic segments.
|
||||
const double discretization_step = 0.05 * bbox_dim_max;
|
||||
|
||||
// Make a copy of the input segments with the double type.
|
||||
std::vector<Voronoi::Internal::segment_type> segments;
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++ it)
|
||||
segments.push_back(Voronoi::Internal::segment_type(
|
||||
Voronoi::Internal::point_type(double(it->a(0)), double(it->a(1))),
|
||||
Voronoi::Internal::point_type(double(it->b(0)), double(it->b(1)))));
|
||||
|
||||
// Color exterior edges.
|
||||
for (boost::polygon::voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it)
|
||||
if (!it->is_finite())
|
||||
Voronoi::Internal::color_exterior(&(*it));
|
||||
|
||||
// Draw the end points of the input polygon.
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it) {
|
||||
svg.draw(it->a, inputSegmentPointColor, inputSegmentPointRadius);
|
||||
svg.draw(it->b, inputSegmentPointColor, inputSegmentPointRadius);
|
||||
}
|
||||
// Draw the input polygon.
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it)
|
||||
svg.draw(Line(Point(coord_t(it->a(0)), coord_t(it->a(1))), Point(coord_t(it->b(0)), coord_t(it->b(1)))), inputSegmentColor, inputSegmentLineWidth);
|
||||
|
||||
#if 1
|
||||
// Draw voronoi vertices.
|
||||
for (boost::polygon::voronoi_diagram<double>::const_vertex_iterator it = vd.vertices().begin(); it != vd.vertices().end(); ++it)
|
||||
if (! internalEdgesOnly || it->color() != Voronoi::Internal::EXTERNAL_COLOR)
|
||||
svg.draw(Point(coord_t(it->x()), coord_t(it->y())), voronoiPointColor, voronoiPointRadius);
|
||||
|
||||
for (boost::polygon::voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it) {
|
||||
if (primaryEdgesOnly && !it->is_primary())
|
||||
continue;
|
||||
if (internalEdgesOnly && (it->color() == Voronoi::Internal::EXTERNAL_COLOR))
|
||||
continue;
|
||||
std::vector<Voronoi::Internal::point_type> samples;
|
||||
std::string color = voronoiLineColorPrimary;
|
||||
if (!it->is_finite()) {
|
||||
Voronoi::Internal::clip_infinite_edge(points, segments, *it, bbox_dim_max, &samples);
|
||||
if (! it->is_primary())
|
||||
color = voronoiLineColorSecondary;
|
||||
} else {
|
||||
// Store both points of the segment into samples. sample_curved_edge will split the initial line
|
||||
// until the discretization_step is reached.
|
||||
samples.push_back(Voronoi::Internal::point_type(it->vertex0()->x(), it->vertex0()->y()));
|
||||
samples.push_back(Voronoi::Internal::point_type(it->vertex1()->x(), it->vertex1()->y()));
|
||||
if (it->is_curved()) {
|
||||
Voronoi::Internal::sample_curved_edge(points, segments, *it, samples, discretization_step);
|
||||
color = voronoiArcColor;
|
||||
} else if (! it->is_primary())
|
||||
color = voronoiLineColorSecondary;
|
||||
}
|
||||
for (std::size_t i = 0; i + 1 < samples.size(); ++i)
|
||||
svg.draw(Line(Point(coord_t(samples[i].x()), coord_t(samples[i].y())), Point(coord_t(samples[i+1].x()), coord_t(samples[i+1].y()))), color, voronoiLineWidth);
|
||||
}
|
||||
#endif
|
||||
|
||||
svg.draw_outline(offset_curves, offsetCurveColor, offsetCurveLineWidth);
|
||||
svg.Close();
|
||||
}
|
||||
#endif
|
||||
|
||||
// https://svn.boost.org/trac10/ticket/12067
|
||||
// This bug seems to be confirmed.
|
||||
// Vojtech supposes that there may be no Voronoi edges produced for
|
||||
|
@ -1586,10 +1196,16 @@ TEST_CASE("Voronoi NaN coordinates 12139", "[Voronoi][!hide][!mayfail]")
|
|||
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-NaNs.svg").c_str(),
|
||||
vd, Points(), lines, Polygons(), 0.015);
|
||||
vd, Points(), lines, Polygons(), Lines(), 0.015);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct OffsetTest {
|
||||
double distance;
|
||||
size_t num_outer;
|
||||
size_t num_inner;
|
||||
};
|
||||
|
||||
TEST_CASE("Voronoi offset", "[VoronoiOffset]")
|
||||
{
|
||||
Polygons poly_with_hole = { Polygon {
|
||||
|
@ -1602,16 +1218,180 @@ TEST_CASE("Voronoi offset", "[VoronoiOffset]")
|
|||
}
|
||||
};
|
||||
|
||||
double area = std::accumulate(poly_with_hole.begin(), poly_with_hole.end(), 0., [](double a, auto &poly){ return a + poly.area(); });
|
||||
REQUIRE(area > 0.);
|
||||
|
||||
VD vd;
|
||||
Lines lines = to_lines(poly_with_hole);
|
||||
construct_voronoi(lines.begin(), lines.end(), &vd);
|
||||
|
||||
Polygons offsetted_polygons = voronoi_offset(vd, lines, scale_(0.2), scale_(0.005));
|
||||
for (const OffsetTest &ot : {
|
||||
OffsetTest { scale_(0.2), 1, 1 },
|
||||
OffsetTest { scale_(0.4), 1, 1 },
|
||||
OffsetTest { scale_(0.5), 1, 1 },
|
||||
OffsetTest { scale_(0.505), 1, 2 },
|
||||
OffsetTest { scale_(0.51), 1, 2 },
|
||||
OffsetTest { scale_(0.52), 1, 1 },
|
||||
OffsetTest { scale_(0.53), 1, 1 },
|
||||
OffsetTest { scale_(0.54), 1, 1 },
|
||||
OffsetTest { scale_(0.55), 1, 0 }
|
||||
}) {
|
||||
|
||||
Polygons offsetted_polygons_out = voronoi_offset(vd, lines, ot.distance, scale_(0.005));
|
||||
REQUIRE(offsetted_polygons_out.size() == ot.num_outer);
|
||||
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-offset.svg").c_str(),
|
||||
vd, Points(), lines, offsetted_polygons);
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-offset-out-%lf.svg", ot.distance).c_str(),
|
||||
vd, Points(), lines, offsetted_polygons_out);
|
||||
#endif
|
||||
|
||||
REQUIRE(offsetted_polygons.size() == 2);
|
||||
Polygons offsetted_polygons_in = voronoi_offset(vd, lines, - ot.distance, scale_(0.005));
|
||||
REQUIRE(offsetted_polygons_in.size() == ot.num_inner);
|
||||
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-offset-in-%lf.svg", ot.distance).c_str(),
|
||||
vd, Points(), lines, offsetted_polygons_in);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Voronoi offset 2", "[VoronoiOffset]")
|
||||
{
|
||||
coord_t mm = coord_t(scale_(1.));
|
||||
Polygons poly = {
|
||||
Polygon {
|
||||
{ 0, 0 },
|
||||
{ 1, 0 },
|
||||
{ 1, 1 },
|
||||
{ 2, 1 },
|
||||
{ 2, 0 },
|
||||
{ 3, 0 },
|
||||
{ 3, 2 },
|
||||
{ 0, 2 }
|
||||
},
|
||||
Polygon {
|
||||
{ 0, - 1 - 2 },
|
||||
{ 3, - 1 - 2 },
|
||||
{ 3, - 1 - 0 },
|
||||
{ 2, - 1 - 0 },
|
||||
{ 2, - 1 - 1 },
|
||||
{ 1, - 1 - 1 },
|
||||
{ 1, - 1 - 0 },
|
||||
{ 0, - 1 - 0 }
|
||||
},
|
||||
};
|
||||
for (Polygon &p : poly)
|
||||
for (Point &pt : p.points)
|
||||
pt *= mm;
|
||||
|
||||
double area = std::accumulate(poly.begin(), poly.end(), 0., [](double a, auto &poly){ return a + poly.area(); });
|
||||
REQUIRE(area > 0.);
|
||||
|
||||
VD vd;
|
||||
Lines lines = to_lines(poly);
|
||||
construct_voronoi(lines.begin(), lines.end(), &vd);
|
||||
|
||||
for (const OffsetTest &ot : {
|
||||
OffsetTest { scale_(0.2), 2, 2 },
|
||||
OffsetTest { scale_(0.4), 2, 2 },
|
||||
OffsetTest { scale_(0.45), 2, 2 },
|
||||
OffsetTest { scale_(0.48), 2, 2 },
|
||||
//FIXME Exact intersections of an Offset curve with any Voronoi vertex are not handled correctly yet.
|
||||
// OffsetTest { scale_(0.5), 2, 2 },
|
||||
OffsetTest { scale_(0.505), 2, 4 },
|
||||
OffsetTest { scale_(0.7), 2, 0 },
|
||||
OffsetTest { scale_(0.8), 1, 0 }
|
||||
}) {
|
||||
|
||||
Polygons offsetted_polygons_out = voronoi_offset(vd, lines, ot.distance, scale_(0.005));
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-offset2-out-%lf.svg", ot.distance).c_str(),
|
||||
vd, Points(), lines, offsetted_polygons_out);
|
||||
#endif
|
||||
REQUIRE(offsetted_polygons_out.size() == ot.num_outer);
|
||||
|
||||
Polygons offsetted_polygons_in = voronoi_offset(vd, lines, - ot.distance, scale_(0.005));
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-offset2-in-%lf.svg", ot.distance).c_str(),
|
||||
vd, Points(), lines, offsetted_polygons_in);
|
||||
#endif
|
||||
REQUIRE(offsetted_polygons_in.size() == ot.num_inner);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Voronoi offset 3", "[VoronoiOffset]")
|
||||
{
|
||||
coord_t mm = coord_t(scale_(1.));
|
||||
Polygons poly = {
|
||||
Polygon {
|
||||
{ 0, 0 },
|
||||
{ 2, 0 },
|
||||
{ 2, 1 },
|
||||
{ 3, 1 },
|
||||
{ 3, 0 },
|
||||
{ 5, 0 },
|
||||
{ 5, 2 },
|
||||
{ 4, 2 },
|
||||
{ 4, 3 },
|
||||
{ 1, 3 },
|
||||
{ 1, 2 },
|
||||
{ 0, 2 }
|
||||
},
|
||||
Polygon {
|
||||
{ 0, -1 - 2 },
|
||||
{ 1, -1 - 2 },
|
||||
{ 1, -1 - 3 },
|
||||
{ 4, -1 - 3 },
|
||||
{ 4, -1 - 2 },
|
||||
{ 5, -1 - 2 },
|
||||
{ 5, -1 - 0 },
|
||||
{ 3, -1 - 0 },
|
||||
{ 3, -1 - 1 },
|
||||
{ 2, -1 - 1 },
|
||||
{ 2, -1 - 0 },
|
||||
{ 0, -1 - 0 }
|
||||
},
|
||||
};
|
||||
for (Polygon &p : poly) {
|
||||
REQUIRE(p.area() > 0.);
|
||||
for (Point &pt : p.points)
|
||||
pt *= mm;
|
||||
}
|
||||
|
||||
VD vd;
|
||||
Lines lines = to_lines(poly);
|
||||
construct_voronoi(lines.begin(), lines.end(), &vd);
|
||||
|
||||
for (const OffsetTest &ot : {
|
||||
OffsetTest { scale_(0.2), 2, 2 },
|
||||
OffsetTest { scale_(0.4), 2, 2 },
|
||||
OffsetTest { scale_(0.49), 2, 2 },
|
||||
//FIXME this fails
|
||||
// OffsetTest { scale_(0.5), 2, 2 },
|
||||
OffsetTest { scale_(0.51), 2, 2 },
|
||||
OffsetTest { scale_(0.56), 2, 2 },
|
||||
OffsetTest { scale_(0.6), 2, 2 },
|
||||
OffsetTest { scale_(0.7), 2, 2 },
|
||||
OffsetTest { scale_(0.8), 1, 6 },
|
||||
OffsetTest { scale_(0.9), 1, 6 },
|
||||
OffsetTest { scale_(0.99), 1, 6 },
|
||||
//FIXME this fails
|
||||
// OffsetTest { scale_(1.0), 1, 6 },
|
||||
OffsetTest { scale_(1.01), 1, 0 },
|
||||
}) {
|
||||
|
||||
Polygons offsetted_polygons_out = voronoi_offset(vd, lines, ot.distance, scale_(0.005));
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-offset2-out-%lf.svg", ot.distance).c_str(),
|
||||
vd, Points(), lines, offsetted_polygons_out);
|
||||
#endif
|
||||
REQUIRE(offsetted_polygons_out.size() == ot.num_outer);
|
||||
|
||||
Polygons offsetted_polygons_in = voronoi_offset(vd, lines, - ot.distance, scale_(0.005));
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-offset2-in-%lf.svg", ot.distance).c_str(),
|
||||
vd, Points(), lines, offsetted_polygons_in);
|
||||
#endif
|
||||
REQUIRE(offsetted_polygons_in.size() == ot.num_inner);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,6 +185,16 @@ if (MSVC)
|
|||
string(REPLACE "/" "\\" PROPS_CMAKE_SOURCE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
configure_file("../cmake/msvc/xs.wperl.props.in" "${CMAKE_BINARY_DIR}/xs.wperl.props" NEWLINE_STYLE CRLF)
|
||||
set_target_properties(XS PROPERTIES VS_USER_PROPS "${CMAKE_BINARY_DIR}/xs.wperl.props")
|
||||
|
||||
if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
|
||||
set(_bits 64)
|
||||
elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
||||
set(_bits 32)
|
||||
endif ()
|
||||
add_custom_command(TARGET XS POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${TOP_LEVEL_PROJECT_DIR}/deps/GMP/gmp/lib/win${_bits}/libgmp-10.dll "${PERL_LOCAL_LIB_ARCH_DIR}/auto/Slic3r/XS/"
|
||||
COMMENT "Installing gmp runtime into the local-lib directory ..."
|
||||
VERBATIM)
|
||||
endif()
|
||||
|
||||
# Installation
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// #include <libslic3r/GCodeSender.hpp>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
/* extern "C" { */
|
||||
#endif
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
|
@ -14,7 +14,7 @@ extern "C" {
|
|||
#undef do_open
|
||||
#undef do_close
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
/* } */
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
// #include <libslic3r.h>
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
extern "C" {
|
||||
// extern "C" {
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
|
@ -88,7 +88,7 @@ extern "C" {
|
|||
#undef Zero
|
||||
#undef Packet
|
||||
#undef _
|
||||
}
|
||||
// }
|
||||
#endif
|
||||
|
||||
#include <ClipperUtils.hpp>
|
||||
|
|
|
@ -13,7 +13,7 @@ Pointfs arrange(size_t total_parts, Vec2d* part, coordf_t dist, BoundingBoxf* bb
|
|||
%code{%
|
||||
Pointfs points;
|
||||
if (! Slic3r::Geometry::arrange(total_parts, *part, dist, bb, points))
|
||||
CONFESS(PRINTF_ZU " parts won't fit in your print area!\n", total_parts);
|
||||
CONFESS("%zu parts won't fit in your print area!\n", total_parts);
|
||||
RETVAL = points;
|
||||
%};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue