Merge branch 'master' into SoftFever

# Conflicts:
#	bbl/i18n/zh_cn/BambuStudio_zh_CN.po
#	resources/i18n/de/BambuStudio.mo
#	resources/i18n/en/BambuStudio.mo
#	resources/i18n/es/BambuStudio.mo
#	resources/i18n/fr/BambuStudio.mo
#	resources/i18n/hu/BambuStudio.mo
#	resources/i18n/nl/BambuStudio.mo
#	resources/i18n/sv/BambuStudio.mo
#	resources/i18n/zh_cn/BambuStudio.mo
#	resources/profiles/Creality.json
#	resources/profiles/Voron.json
#	resources/web/guide/3/index.html
#	src/libslic3r/AppConfig.cpp
#	src/libslic3r/GCode.cpp
#	src/libslic3r/GCode/GCodeProcessor.cpp
#	src/libslic3r/LayerRegion.cpp
#	src/libslic3r/Preset.cpp
#	src/libslic3r/Print.cpp
#	src/libslic3r/PrintConfig.cpp
#	src/libslic3r/PrintConfig.hpp
#	src/libslic3r/PrintObject.cpp
#	src/slic3r/GUI/AboutDialog.cpp
#	src/slic3r/GUI/BBLTopbar.cpp
#	src/slic3r/GUI/ConfigManipulation.cpp
#	src/slic3r/GUI/ConfigWizard.cpp
#	src/slic3r/GUI/GCodeViewer.cpp
#	src/slic3r/GUI/GUI_App.cpp
#	src/slic3r/GUI/GUI_Factories.cpp
#	src/slic3r/GUI/MainFrame.cpp
#	src/slic3r/GUI/Plater.cpp
#	src/slic3r/GUI/Tab.cpp
#	version.inc
This commit is contained in:
SoftFever 2022-12-16 13:59:30 +08:00
commit bf8a9fee1f
689 changed files with 46784 additions and 10006 deletions

File diff suppressed because it is too large Load diff

View file

@ -7,6 +7,7 @@ add_subdirectory(admesh)
# boost/nowide
add_subdirectory(boost)
add_subdirectory(clipper)
add_subdirectory(clipper2)
add_subdirectory(miniz)
add_subdirectory(minilzo)
add_subdirectory(glu-libtess)
@ -133,7 +134,7 @@ elseif (MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
else ()
# Boost on Raspberry-Pi does not link to pthreads explicitely.
target_link_libraries(BambuStudio ${CMAKE_DL_LIBS} -lstdc++ Threads::Threads)
target_link_libraries(BambuStudio ${CMAKE_DL_LIBS} -lstdc++ Threads::Threads pangoft2-1.0)
endif ()
# Add the Slic3r GUI library, libcurl, OpenGL and GLU libraries.

View file

@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.10)
project(Clipper2 VERSION 1.0.6 LANGUAGES C CXX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
option(BUILD_SHARED_LIBS "Build shared libs" OFF)
include(GNUInstallDirs)
set(CLIPPER2_INC
Clipper2Lib/include/clipper2/clipper.h
Clipper2Lib/include/clipper2/clipper.core.h
Clipper2Lib/include/clipper2/clipper.engine.h
Clipper2Lib/include/clipper2/clipper.export.h
Clipper2Lib/include/clipper2/clipper.minkowski.h
Clipper2Lib/include/clipper2/clipper.offset.h
Clipper2Lib/include/clipper2/clipper.rectclip.h
)
set(CLIPPER2_SRC
Clipper2Lib/src/clipper.engine.cpp
Clipper2Lib/src/clipper.offset.cpp
Clipper2Lib/src/clipper.rectclip.cpp
)
# 2d version of Clipper2
add_library(Clipper2 ${CLIPPER2_INC} ${CLIPPER2_SRC})
target_include_directories(Clipper2
PUBLIC Clipper2Lib/include
)
if (WIN32)
target_compile_options(Clipper2 PRIVATE /W4 /WX)
else()
target_compile_options(Clipper2 PRIVATE -Wall -Wextra -Wpedantic -Werror)
target_link_libraries(Clipper2 PUBLIC -lm)
endif()
set_target_properties(Clipper2 PROPERTIES FOLDER Libraries
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER "${CLIPPER2_INC}"
)

View file

@ -0,0 +1,653 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 4 November 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : Core Clipper Library structures and functions *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
#ifndef CLIPPER_CORE_H
#define CLIPPER_CORE_H
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <climits>
//#define NO_EXCEPTIONS
namespace Clipper2Lib
{
#ifndef NO_EXCEPTIONS
static const char* precision_error =
"Precision exceeds the permitted range";
#endif
static double const PI = 3.141592653589793238;
static int64_t const MAX_COORD = LLONG_MAX / 2;
//By far the most widely used filling rules for polygons are EvenOdd
//and NonZero, sometimes called Alternate and Winding respectively.
//https://en.wikipedia.org/wiki/Nonzero-rule
enum class FillRule { EvenOdd, NonZero, Positive, Negative };
// Point ------------------------------------------------------------------------
template <typename T>
struct Point {
T x;
T y;
#ifdef USINGZ
int64_t z;
template <typename T2>
inline void Init(const T2 x_ = 0, const T2 y_ = 0, const int64_t z_ = 0)
{
if constexpr (std::numeric_limits<T>::is_integer &&
!std::numeric_limits<T2>::is_integer)
{
x = static_cast<T>(std::round(x_));
y = static_cast<T>(std::round(y_));
z = z_;
}
else
{
x = static_cast<T>(x_);
y = static_cast<T>(y_);
z = z_;
}
}
explicit Point() : x(0), y(0), z(0) {};
template <typename T2>
Point(const T2 x_, const T2 y_, const int64_t z_ = 0)
{
Init(x_, y_);
z = z_;
}
template <typename T2>
explicit Point<T>(const Point<T2>& p)
{
Init(p.x, p.y, p.z);
}
Point operator * (const double scale) const
{
return Point(x * scale, y * scale, z);
}
friend std::ostream& operator<<(std::ostream& os, const Point& point)
{
os << point.x << "," << point.y << "," << point.z;
return os;
}
#else
template <typename T2>
inline void Init(const T2 x_ = 0, const T2 y_ = 0)
{
if constexpr (std::numeric_limits<T>::is_integer &&
!std::numeric_limits<T2>::is_integer)
{
x = static_cast<T>(std::round(x_));
y = static_cast<T>(std::round(y_));
}
else
{
x = static_cast<T>(x_);
y = static_cast<T>(y_);
}
}
explicit Point() : x(0), y(0) {};
template <typename T2>
Point(const T2 x_, const T2 y_) { Init(x_, y_); }
template <typename T2>
explicit Point<T>(const Point<T2>& p) { Init(p.x, p.y); }
Point operator * (const double scale) const
{
return Point(x * scale, y * scale);
}
friend std::ostream& operator<<(std::ostream& os, const Point& point)
{
os << point.x << "," << point.y;
return os;
}
#endif
friend bool operator==(const Point &a, const Point &b)
{
return a.x == b.x && a.y == b.y;
}
friend bool operator!=(const Point& a, const Point& b)
{
return !(a == b);
}
inline Point<T> operator-() const
{
return Point<T>(-x,-y);
}
inline Point operator+(const Point &b) const
{
return Point(x+b.x, y+b.y);
}
inline Point operator-(const Point &b) const
{
return Point(x-b.x, y-b.y);
}
inline void Negate() { x = -x; y = -y; }
};
//nb: using 'using' here (instead of typedef) as they can be used in templates
using Point64 = Point<int64_t>;
using PointD = Point<double>;
template <typename T>
using Path = std::vector<Point<T>>;
template <typename T>
using Paths = std::vector<Path<T>>;
using Path64 = Path<int64_t>;
using PathD = Path<double>;
using Paths64 = std::vector< Path64>;
using PathsD = std::vector< PathD>;
template <typename T>
std::ostream& operator << (std::ostream& outstream, const Path<T>& path)
{
if (!path.empty())
{
auto pt = path.cbegin(), last = path.cend() - 1;
while (pt != last)
outstream << *pt++ << ", ";
outstream << *last << std::endl;
}
return outstream;
}
template <typename T>
std::ostream& operator << (std::ostream& outstream, const Paths<T>& paths)
{
for (auto p : paths)
outstream << p;
return outstream;
}
template <typename T1, typename T2>
inline Path<T1> ScalePath(const Path<T2>& path, double scale)
{
Path<T1> result;
result.reserve(path.size());
#ifdef USINGZ
for (const Point<T2>& pt : path)
result.push_back(Point<T1>(pt.x * scale, pt.y * scale, pt.z));
#else
for (const Point<T2>& pt : path)
result.push_back(Point<T1>(pt.x * scale, pt.y * scale));
#endif
return result;
}
template <typename T1, typename T2>
inline Paths<T1> ScalePaths(const Paths<T2>& paths, double scale)
{
Paths<T1> result;
result.reserve(paths.size());
for (const Path<T2>& path : paths)
result.push_back(ScalePath<T1, T2>(path, scale));
return result;
}
template <typename T1, typename T2>
inline Path<T1> TransformPath(const Path<T2>& path)
{
Path<T1> result;
result.reserve(path.size());
std::transform(path.cbegin(), path.cend(), std::back_inserter(result),
[](const Point<T2>& pt) {return Point<T1>(pt); });
return result;
}
template <typename T1, typename T2>
inline Paths<T1> TransformPaths(const Paths<T2>& paths)
{
Paths<T1> result;
std::transform(paths.cbegin(), paths.cend(), std::back_inserter(result),
[](const Path<T2>& path) {return TransformPath<T1, T2>(path); });
return result;
}
inline PathD Path64ToPathD(const Path64& path)
{
return TransformPath<double, int64_t>(path);
}
inline PathsD Paths64ToPathsD(const Paths64& paths)
{
return TransformPaths<double, int64_t>(paths);
}
inline Path64 PathDToPath64(const PathD& path)
{
return TransformPath<int64_t, double>(path);
}
inline Paths64 PathsDToPaths64(const PathsD& paths)
{
return TransformPaths<int64_t, double>(paths);
}
template<typename T>
inline double Sqr(T val)
{
return static_cast<double>(val) * static_cast<double>(val);
}
template<typename T>
inline bool NearEqual(const Point<T>& p1,
const Point<T>& p2, double max_dist_sqrd)
{
return Sqr(p1.x - p2.x) + Sqr(p1.y - p2.y) < max_dist_sqrd;
}
template<typename T>
inline Path<T> StripNearEqual(const Path<T>& path,
double max_dist_sqrd, bool is_closed_path)
{
if (path.size() == 0) return Path<T>();
Path<T> result;
result.reserve(path.size());
typename Path<T>::const_iterator path_iter = path.cbegin();
Point<T> first_pt = *path_iter++, last_pt = first_pt;
result.push_back(first_pt);
for (; path_iter != path.cend(); ++path_iter)
{
if (!NearEqual(*path_iter, last_pt, max_dist_sqrd))
{
last_pt = *path_iter;
result.push_back(last_pt);
}
}
if (!is_closed_path) return result;
while (result.size() > 1 &&
NearEqual(result.back(), first_pt, max_dist_sqrd)) result.pop_back();
return result;
}
template<typename T>
inline Paths<T> StripNearEqual(const Paths<T>& paths,
double max_dist_sqrd, bool is_closed_path)
{
Paths<T> result;
result.reserve(paths.size());
for (typename Paths<T>::const_iterator paths_citer = paths.cbegin();
paths_citer != paths.cend(); ++paths_citer)
{
result.push_back(StripNearEqual(*paths_citer, max_dist_sqrd, is_closed_path));
}
return result;
}
template<typename T>
inline Path<T> StripDuplicates(const Path<T>& path, bool is_closed_path)
{
if (path.size() == 0) return Path<T>();
Path<T> result;
result.reserve(path.size());
typename Path<T>::const_iterator path_iter = path.cbegin();
Point<T> first_pt = *path_iter++, last_pt = first_pt;
result.push_back(first_pt);
for (; path_iter != path.cend(); ++path_iter)
{
if (*path_iter != last_pt)
{
last_pt = *path_iter;
result.push_back(last_pt);
}
}
if (!is_closed_path) return result;
while (result.size() > 1 && result.back() == first_pt) result.pop_back();
return result;
}
template<typename T>
inline Paths<T> StripDuplicates(const Paths<T>& paths, bool is_closed_path)
{
Paths<T> result;
result.reserve(paths.size());
for (typename Paths<T>::const_iterator paths_citer = paths.cbegin();
paths_citer != paths.cend(); ++paths_citer)
{
result.push_back(StripDuplicates(*paths_citer, is_closed_path));
}
return result;
}
// Rect ------------------------------------------------------------------------
template <typename T>
struct Rect;
using Rect64 = Rect<int64_t>;
using RectD = Rect<double>;
template <typename T>
struct Rect {
T left;
T top;
T right;
T bottom;
Rect() :
left(0),
top(0),
right(0),
bottom(0) {}
Rect(T l, T t, T r, T b) :
left(l),
top(t),
right(r),
bottom(b) {}
T Width() const { return right - left; }
T Height() const { return bottom - top; }
void Width(T width) { right = left + width; }
void Height(T height) { bottom = top + height; }
Point<T> MidPoint() const
{
return Point<T>((left + right) / 2, (top + bottom) / 2);
}
Path<T> AsPath() const
{
Path<T> result;
result.reserve(4);
result.push_back(Point<T>(left, top));
result.push_back(Point<T>(right, top));
result.push_back(Point<T>(right, bottom));
result.push_back(Point<T>(left, bottom));
return result;
}
bool Contains(const Point<T>& pt) const
{
return pt.x > left && pt.x < right&& pt.y > top && pt.y < bottom;
}
bool Contains(const Rect<T>& rec) const
{
return rec.left >= left && rec.right <= right &&
rec.top >= top && rec.bottom <= bottom;
}
void Scale(double scale) {
left *= scale;
top *= scale;
right *= scale;
bottom *= scale;
}
bool IsEmpty() const { return bottom <= top || right <= left; };
bool Intersects(const Rect<T>& rec) const
{
return (std::max(left, rec.left) < std::min(right, rec.right)) &&
(std::max(top, rec.top) < std::min(bottom, rec.bottom));
};
friend std::ostream &operator<<(std::ostream &os, const Rect<T> &rect) {
os << "("
<< rect.left << "," << rect.top << "," << rect.right << "," << rect.bottom
<< ")";
return os;
}
};
template <typename T1, typename T2>
inline Rect<T1> ScaleRect(const Rect<T2>& rect, double scale)
{
Rect<T1> result;
if constexpr (std::numeric_limits<T1>::is_integer &&
!std::numeric_limits<T2>::is_integer)
{
result.left = static_cast<T1>(std::round(rect.left * scale));
result.top = static_cast<T1>(std::round(rect.top * scale));
result.right = static_cast<T1>(std::round(rect.right * scale));
result.bottom = static_cast<T1>(std::round(rect.bottom * scale));
}
else
{
result.left = rect.left * scale;
result.top = rect.top * scale;
result.right = rect.right * scale;
result.bottom = rect.bottom * scale;
}
return result;
}
// clipper2Exception ---------------------------------------------------------
#ifndef NO_EXCEPTIONS
class Clipper2Exception : public std::exception {
public:
explicit Clipper2Exception(const char *description) :
m_descr(description) {}
virtual const char *what() const throw() { return m_descr.c_str(); }
private:
std::string m_descr;
};
#endif
// Miscellaneous ------------------------------------------------------------
inline void CheckPrecision(int& precision)
{
if (precision >= -8 && precision <= 8) return;
#ifdef NO_EXCEPTIONS
precision = precision > 8 ? 8 : -8;
#else
throw Clipper2Exception(precision_error);
#endif
}
template <typename T>
inline double CrossProduct(const Point<T>& pt1, const Point<T>& pt2, const Point<T>& pt3) {
return (static_cast<double>(pt2.x - pt1.x) * static_cast<double>(pt3.y -
pt2.y) - static_cast<double>(pt2.y - pt1.y) * static_cast<double>(pt3.x - pt2.x));
}
template <typename T>
inline double CrossProduct(const Point<T>& vec1, const Point<T>& vec2)
{
return static_cast<double>(vec1.y * vec2.x) - static_cast<double>(vec2.y * vec1.x);
}
template <typename T>
inline double DotProduct(const Point<T>& pt1, const Point<T>& pt2, const Point<T>& pt3) {
return (static_cast<double>(pt2.x - pt1.x) * static_cast<double>(pt3.x - pt2.x) +
static_cast<double>(pt2.y - pt1.y) * static_cast<double>(pt3.y - pt2.y));
}
template <typename T>
inline double DotProduct(const Point<T>& vec1, const Point<T>& vec2)
{
return static_cast<double>(vec1.x * vec2.x) + static_cast<double>(vec1.y * vec2.y);
}
template <typename T>
inline double DistanceSqr(const Point<T> pt1, const Point<T> pt2)
{
return Sqr(pt1.x - pt2.x) + Sqr(pt1.y - pt2.y);
}
template <typename T>
inline double DistanceFromLineSqrd(const Point<T>& pt, const Point<T>& ln1, const Point<T>& ln2)
{
//perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²)
//see http://en.wikipedia.org/wiki/Perpendicular_distance
double A = static_cast<double>(ln1.y - ln2.y);
double B = static_cast<double>(ln2.x - ln1.x);
double C = A * ln1.x + B * ln1.y;
C = A * pt.x + B * pt.y - C;
return (C * C) / (A * A + B * B);
}
template <typename T>
inline double Area(const Path<T>& path)
{
size_t cnt = path.size();
if (cnt < 3) return 0.0;
double a = 0.0;
typename Path<T>::const_iterator it1, it2 = path.cend() - 1, stop = it2;
if (!(cnt & 1)) ++stop;
for (it1 = path.cbegin(); it1 != stop;)
{
a += static_cast<double>(it2->y + it1->y) * (it2->x - it1->x);
it2 = it1 + 1;
a += static_cast<double>(it1->y + it2->y) * (it1->x - it2->x);
it1 += 2;
}
if (cnt & 1)
a += static_cast<double>(it2->y + it1->y) * (it2->x - it1->x);
return a * 0.5;
}
template <typename T>
inline double Area(const Paths<T>& paths)
{
double a = 0.0;
for (typename Paths<T>::const_iterator paths_iter = paths.cbegin();
paths_iter != paths.cend(); ++paths_iter)
{
a += Area<T>(*paths_iter);
}
return a;
}
template <typename T>
inline bool IsPositive(const Path<T>& poly)
{
// A curve has positive orientation [and area] if a region 'R'
// is on the left when traveling around the outside of 'R'.
//https://mathworld.wolfram.com/CurveOrientation.html
//nb: This statement is premised on using Cartesian coordinates
return Area<T>(poly) >= 0;
}
inline bool SegmentsIntersect(const Point64& seg1a, const Point64& seg1b,
const Point64& seg2a, const Point64& seg2b, bool inclusive = false)
{
if (inclusive)
{
double res1 = CrossProduct(seg1a, seg2a, seg2b);
double res2 = CrossProduct(seg1b, seg2a, seg2b);
if (res1 * res2 > 0) return false;
double res3 = CrossProduct(seg2a, seg1a, seg1b);
double res4 = CrossProduct(seg2b, seg1a, seg1b);
if (res3 * res4 > 0) return false;
return (res1 || res2 || res3 || res4); // ensures not collinear
}
else {
double dx1 = static_cast<double>(seg1a.x - seg1b.x);
double dy1 = static_cast<double>(seg1a.y - seg1b.y);
double dx2 = static_cast<double>(seg2a.x - seg2b.x);
double dy2 = static_cast<double>(seg2a.y - seg2b.y);
return (((dy1 * (seg2a.x - seg1a.x) - dx1 * (seg2a.y - seg1a.y)) *
(dy1 * (seg2b.x - seg1a.x) - dx1 * (seg2b.y - seg1a.y)) < 0) &&
((dy2 * (seg1a.x - seg2a.x) - dx2 * (seg1a.y - seg2a.y)) *
(dy2 * (seg1b.x - seg2a.x) - dx2 * (seg1b.y - seg2a.y)) < 0));
}
}
enum class PointInPolygonResult { IsOn, IsInside, IsOutside };
template <typename T>
inline PointInPolygonResult PointInPolygon(const Point<T>& pt, const Path<T>& polygon)
{
if (polygon.size() < 3)
return PointInPolygonResult::IsOutside;
int val = 0;
typename Path<T>::const_iterator start = polygon.cbegin(), cit = start;
typename Path<T>::const_iterator cend = polygon.cend(), pit = cend - 1;
while (pit->y == pt.y)
{
if (pit == start) return PointInPolygonResult::IsOutside;
--pit;
}
bool is_above = pit->y < pt.y;
while (cit != cend)
{
if (is_above)
{
while (cit != cend && cit->y < pt.y) ++cit;
if (cit == cend) break;
}
else
{
while (cit != cend && cit->y > pt.y) ++cit;
if (cit == cend) break;
}
if (cit == start) pit = cend - 1;
else pit = cit - 1;
if (cit->y == pt.y)
{
if (cit->x == pt.x || (cit->y == pit->y &&
((pt.x < pit->x) != (pt.x < cit->x))))
return PointInPolygonResult::IsOn;
++cit;
continue;
}
if (pt.x < cit->x && pt.x < pit->x)
{
// we're only interested in edges crossing on the left
}
else if (pt.x > pit->x && pt.x > cit->x)
val = 1 - val; // toggle val
else
{
double d = CrossProduct(*pit, *cit, pt);
if (d == 0) return PointInPolygonResult::IsOn;
if ((d < 0) == is_above) val = 1 - val;
}
is_above = !is_above;
++cit;
}
return (val == 0) ?
PointInPolygonResult::IsOutside :
PointInPolygonResult::IsInside;
}
} // namespace
#endif // CLIPPER_CORE_H

View file

@ -0,0 +1,586 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 4 November 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : This is the main polygon clipping module *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
#ifndef CLIPPER_ENGINE_H
#define CLIPPER_ENGINE_H
constexpr auto CLIPPER2_VERSION = "1.0.6";
#include <cstdlib>
#include <queue>
#include <stdexcept>
#include <vector>
#include <functional>
#include "clipper.core.h"
namespace Clipper2Lib {
struct Scanline;
struct IntersectNode;
struct Active;
struct Vertex;
struct LocalMinima;
struct OutRec;
struct Joiner;
//Note: all clipping operations except for Difference are commutative.
enum class ClipType { None, Intersection, Union, Difference, Xor };
enum class PathType { Subject, Clip };
enum class VertexFlags : uint32_t {
None = 0, OpenStart = 1, OpenEnd = 2, LocalMax = 4, LocalMin = 8
};
constexpr enum VertexFlags operator &(enum VertexFlags a, enum VertexFlags b)
{
return (enum VertexFlags)(uint32_t(a) & uint32_t(b));
}
constexpr enum VertexFlags operator |(enum VertexFlags a, enum VertexFlags b)
{
return (enum VertexFlags)(uint32_t(a) | uint32_t(b));
}
struct Vertex {
Point64 pt;
Vertex* next = nullptr;
Vertex* prev = nullptr;
VertexFlags flags = VertexFlags::None;
};
struct OutPt {
Point64 pt;
OutPt* next = nullptr;
OutPt* prev = nullptr;
OutRec* outrec;
Joiner* joiner = nullptr;
OutPt(const Point64& pt_, OutRec* outrec_): pt(pt_), outrec(outrec_) {
next = this;
prev = this;
}
};
class PolyPath;
class PolyPath64;
class PolyPathD;
using PolyTree64 = PolyPath64;
using PolyTreeD = PolyPathD;
struct OutRec;
typedef std::vector<OutRec*> OutRecList;
//OutRec: contains a path in the clipping solution. Edges in the AEL will
//have OutRec pointers assigned when they form part of the clipping solution.
struct OutRec {
size_t idx = 0;
OutRec* owner = nullptr;
OutRecList* splits = nullptr;
Active* front_edge = nullptr;
Active* back_edge = nullptr;
OutPt* pts = nullptr;
PolyPath* polypath = nullptr;
Rect64 bounds = {};
Path64 path;
bool is_open = false;
~OutRec() { if (splits) delete splits; };
};
///////////////////////////////////////////////////////////////////
//Important: UP and DOWN here are premised on Y-axis positive down
//displays, which is the orientation used in Clipper's development.
///////////////////////////////////////////////////////////////////
struct Active {
Point64 bot;
Point64 top;
int64_t curr_x = 0; //current (updated at every new scanline)
double dx = 0.0;
int wind_dx = 1; //1 or -1 depending on winding direction
int wind_cnt = 0;
int wind_cnt2 = 0; //winding count of the opposite polytype
OutRec* outrec = nullptr;
//AEL: 'active edge list' (Vatti's AET - active edge table)
// a linked list of all edges (from left to right) that are present
// (or 'active') within the current scanbeam (a horizontal 'beam' that
// sweeps from bottom to top over the paths in the clipping operation).
Active* prev_in_ael = nullptr;
Active* next_in_ael = nullptr;
//SEL: 'sorted edge list' (Vatti's ST - sorted table)
// linked list used when sorting edges into their new positions at the
// top of scanbeams, but also (re)used to process horizontals.
Active* prev_in_sel = nullptr;
Active* next_in_sel = nullptr;
Active* jump = nullptr;
Vertex* vertex_top = nullptr;
LocalMinima* local_min = nullptr; // the bottom of an edge 'bound' (also Vatti)
bool is_left_bound = false;
};
struct LocalMinima {
Vertex* vertex;
PathType polytype;
bool is_open;
LocalMinima(Vertex* v, PathType pt, bool open) :
vertex(v), polytype(pt), is_open(open){}
};
struct IntersectNode {
Point64 pt;
Active* edge1;
Active* edge2;
IntersectNode() : pt(Point64(0, 0)), edge1(NULL), edge2(NULL) {}
IntersectNode(Active* e1, Active* e2, Point64& pt_) :
pt(pt_), edge1(e1), edge2(e2)
{
}
};
#ifdef USINGZ
typedef std::function<void(const Point64& e1bot, const Point64& e1top,
const Point64& e2bot, const Point64& e2top, Point64& pt)> ZCallback64;
typedef std::function<void(const PointD& e1bot, const PointD& e1top,
const PointD& e2bot, const PointD& e2top, PointD& pt)> ZCallbackD;
#endif
// ClipperBase -------------------------------------------------------------
class ClipperBase {
private:
ClipType cliptype_ = ClipType::None;
FillRule fillrule_ = FillRule::EvenOdd;
FillRule fillpos = FillRule::Positive;
int64_t bot_y_ = 0;
bool minima_list_sorted_ = false;
bool using_polytree_ = false;
Active* actives_ = nullptr;
Active *sel_ = nullptr;
Joiner *horz_joiners_ = nullptr;
std::vector<LocalMinima*> minima_list_; //pointers in case of memory reallocs
std::vector<LocalMinima*>::iterator current_locmin_iter_;
std::vector<Vertex*> vertex_lists_;
std::priority_queue<int64_t> scanline_list_;
std::vector<IntersectNode> intersect_nodes_;
std::vector<Joiner*> joiner_list_; //pointers in case of memory reallocs
void Reset();
void InsertScanline(int64_t y);
bool PopScanline(int64_t &y);
bool PopLocalMinima(int64_t y, LocalMinima *&local_minima);
void DisposeAllOutRecs();
void DisposeVerticesAndLocalMinima();
void DeleteEdges(Active*& e);
void AddLocMin(Vertex &vert, PathType polytype, bool is_open);
bool IsContributingClosed(const Active &e) const;
inline bool IsContributingOpen(const Active &e) const;
void SetWindCountForClosedPathEdge(Active &edge);
void SetWindCountForOpenPathEdge(Active &e);
void InsertLocalMinimaIntoAEL(int64_t bot_y);
void InsertLeftEdge(Active &e);
inline void PushHorz(Active &e);
inline bool PopHorz(Active *&e);
inline OutPt* StartOpenPath(Active &e, const Point64& pt);
inline void UpdateEdgeIntoAEL(Active *e);
OutPt* IntersectEdges(Active &e1, Active &e2, const Point64& pt);
inline void DeleteFromAEL(Active &e);
inline void AdjustCurrXAndCopyToSEL(const int64_t top_y);
void DoIntersections(const int64_t top_y);
void AddNewIntersectNode(Active &e1, Active &e2, const int64_t top_y);
bool BuildIntersectList(const int64_t top_y);
void ProcessIntersectList();
void SwapPositionsInAEL(Active& edge1, Active& edge2);
OutPt* AddOutPt(const Active &e, const Point64& pt);
OutPt* AddLocalMinPoly(Active &e1, Active &e2,
const Point64& pt, bool is_new = false);
OutPt* AddLocalMaxPoly(Active &e1, Active &e2, const Point64& pt);
void DoHorizontal(Active &horz);
bool ResetHorzDirection(const Active &horz, const Active *max_pair,
int64_t &horz_left, int64_t &horz_right);
void DoTopOfScanbeam(const int64_t top_y);
Active *DoMaxima(Active &e);
void JoinOutrecPaths(Active &e1, Active &e2);
void CompleteSplit(OutPt* op1, OutPt* op2, OutRec& outrec);
bool ValidateClosedPathEx(OutPt*& outrec);
void CleanCollinear(OutRec* outrec);
void FixSelfIntersects(OutRec* outrec);
void DoSplitOp(OutRec* outRec, OutPt* splitOp);
Joiner* GetHorzTrialParent(const OutPt* op);
bool OutPtInTrialHorzList(OutPt* op);
void SafeDisposeOutPts(OutPt*& op);
void SafeDeleteOutPtJoiners(OutPt* op);
void AddTrialHorzJoin(OutPt* op);
void DeleteTrialHorzJoin(OutPt* op);
void ConvertHorzTrialsToJoins();
void AddJoin(OutPt* op1, OutPt* op2);
void DeleteJoin(Joiner* joiner);
void ProcessJoinerList();
OutRec* ProcessJoin(Joiner* joiner);
protected:
bool has_open_paths_ = false;
bool succeeded_ = true;
std::vector<OutRec*> outrec_list_; //pointers in case list memory reallocated
bool ExecuteInternal(ClipType ct, FillRule ft, bool use_polytrees);
bool DeepCheckOwner(OutRec* outrec, OutRec* owner);
#ifdef USINGZ
ZCallback64 zCallback_ = nullptr;
void SetZ(const Active& e1, const Active& e2, Point64& pt);
#endif
void CleanUp(); // unlike Clear, CleanUp preserves added paths
void AddPath(const Path64& path, PathType polytype, bool is_open);
void AddPaths(const Paths64& paths, PathType polytype, bool is_open);
public:
virtual ~ClipperBase();
bool PreserveCollinear = true;
bool ReverseSolution = false;
void Clear();
};
// PolyPath / PolyTree --------------------------------------------------------
//PolyTree: is intended as a READ-ONLY data structure for CLOSED paths returned
//by clipping operations. While this structure is more complex than the
//alternative Paths structure, it does preserve path 'ownership' - ie those
//paths that contain (or own) other paths. This will be useful to some users.
class PolyPath {
protected:
PolyPath* parent_;
public:
PolyPath(PolyPath* parent = nullptr): parent_(parent){}
virtual ~PolyPath() { Clear(); };
//https://en.cppreference.com/w/cpp/language/rule_of_three
PolyPath(const PolyPath&) = delete;
PolyPath& operator=(const PolyPath&) = delete;
unsigned Level() const
{
unsigned result = 0;
const PolyPath* p = parent_;
while (p) { ++result; p = p->parent_; }
return result;
}
virtual PolyPath* AddChild(const Path64& path) = 0;
virtual void Clear() {};
virtual size_t Count() const { return 0; }
const PolyPath* Parent() const { return parent_; }
bool IsHole() const
{
const PolyPath* pp = parent_;
bool is_hole = pp;
while (pp) {
is_hole = !is_hole;
pp = pp->parent_;
}
return is_hole;
}
};
class PolyPath64 : public PolyPath {
private:
std::vector<PolyPath64*> childs_;
Path64 polygon_;
typedef typename std::vector<PolyPath64*>::const_iterator pp64_itor;
public:
PolyPath64(PolyPath64* parent = nullptr) : PolyPath(parent) {}
PolyPath64* operator [] (size_t index) { return static_cast<PolyPath64*>(childs_[index]); }
pp64_itor begin() const { return childs_.cbegin(); }
pp64_itor end() const { return childs_.cend(); }
PolyPath64* AddChild(const Path64& path) override
{
PolyPath64* result = new PolyPath64(this);
childs_.push_back(result);
result->polygon_ = path;
return result;
}
void Clear() override
{
for (const PolyPath64* child : childs_) delete child;
childs_.resize(0);
}
size_t Count() const override
{
return childs_.size();
}
const Path64& Polygon() const { return polygon_; };
double Area() const
{
double result = Clipper2Lib::Area<int64_t>(polygon_);
for (const PolyPath64* child : childs_)
result += child->Area();
return result;
}
friend std::ostream& operator << (std::ostream& outstream, const PolyPath64& polypath)
{
const size_t level_indent = 4;
const size_t coords_per_line = 4;
const size_t last_on_line = coords_per_line - 1;
unsigned level = polypath.Level();
if (level > 0)
{
std::string level_padding;
level_padding.insert(0, (level - 1) * level_indent, ' ');
std::string caption = polypath.IsHole() ? "Hole " : "Outer Polygon ";
std::string childs = polypath.Count() == 1 ? " child" : " children";
outstream << level_padding.c_str() << caption << "with " << polypath.Count() << childs << std::endl;
outstream << level_padding;
size_t i = 0, highI = polypath.Polygon().size() - 1;
for (; i < highI; ++i)
{
outstream << polypath.Polygon()[i] << ' ';
if ((i % coords_per_line) == last_on_line)
outstream << std::endl << level_padding;
}
if (highI > 0) outstream << polypath.Polygon()[i];
outstream << std::endl;
}
for (auto child : polypath)
outstream << *child;
return outstream;
}
};
class PolyPathD : public PolyPath {
private:
std::vector<PolyPathD*> childs_;
double inv_scale_;
PathD polygon_;
typedef typename std::vector<PolyPathD*>::const_iterator ppD_itor;
public:
PolyPathD(PolyPathD* parent = nullptr) : PolyPath(parent)
{
inv_scale_ = parent ? parent->inv_scale_ : 1.0;
}
PolyPathD* operator [] (size_t index)
{
return static_cast<PolyPathD*>(childs_[index]);
}
ppD_itor begin() const { return childs_.cbegin(); }
ppD_itor end() const { return childs_.cend(); }
void SetInvScale(double value) { inv_scale_ = value; }
double InvScale() { return inv_scale_; }
PolyPathD* AddChild(const Path64& path) override
{
PolyPathD* result = new PolyPathD(this);
childs_.push_back(result);
result->polygon_ = ScalePath<double, int64_t>(path, inv_scale_);
return result;
}
void Clear() override
{
for (const PolyPathD* child : childs_) delete child;
childs_.resize(0);
}
size_t Count() const override
{
return childs_.size();
}
const PathD& Polygon() const { return polygon_; };
double Area() const
{
double result = Clipper2Lib::Area<double>(polygon_);
for (const PolyPathD* child : childs_)
result += child->Area();
return result;
}
};
class Clipper64 : public ClipperBase
{
private:
void BuildPaths64(Paths64& solutionClosed, Paths64* solutionOpen);
void BuildTree64(PolyPath64& polytree, Paths64& open_paths);
public:
#ifdef USINGZ
void SetZCallback(ZCallback64 cb) { zCallback_ = cb; }
#endif
void AddSubject(const Paths64& subjects)
{
AddPaths(subjects, PathType::Subject, false);
}
void AddOpenSubject(const Paths64& open_subjects)
{
AddPaths(open_subjects, PathType::Subject, true);
}
void AddClip(const Paths64& clips)
{
AddPaths(clips, PathType::Clip, false);
}
bool Execute(ClipType clip_type,
FillRule fill_rule, Paths64& closed_paths)
{
Paths64 dummy;
return Execute(clip_type, fill_rule, closed_paths, dummy);
}
bool Execute(ClipType clip_type, FillRule fill_rule,
Paths64& closed_paths, Paths64& open_paths)
{
closed_paths.clear();
open_paths.clear();
if (ExecuteInternal(clip_type, fill_rule, false))
BuildPaths64(closed_paths, &open_paths);
CleanUp();
return succeeded_;
}
bool Execute(ClipType clip_type, FillRule fill_rule, PolyTree64& polytree)
{
Paths64 dummy;
return Execute(clip_type, fill_rule, polytree, dummy);
}
bool Execute(ClipType clip_type,
FillRule fill_rule, PolyTree64& polytree, Paths64& open_paths)
{
if (ExecuteInternal(clip_type, fill_rule, true))
{
open_paths.clear();
polytree.Clear();
BuildTree64(polytree, open_paths);
}
CleanUp();
return succeeded_;
}
};
class ClipperD : public ClipperBase {
private:
double scale_ = 1.0, invScale_ = 1.0;
#ifdef USINGZ
ZCallbackD zCallback_ = nullptr;
#endif
void BuildPathsD(PathsD& solutionClosed, PathsD* solutionOpen);
void BuildTreeD(PolyPathD& polytree, PathsD& open_paths);
public:
explicit ClipperD(int precision = 2) : ClipperBase()
{
CheckPrecision(precision);
// to optimize scaling / descaling precision
// set the scale to a power of double's radix (2) (#25)
scale_ = std::pow(std::numeric_limits<double>::radix,
std::ilogb(std::pow(10, precision)) + 1);
invScale_ = 1 / scale_;
}
#ifdef USINGZ
void SetZCallback(ZCallbackD cb) { zCallback_ = cb; };
void ZCB(const Point64& e1bot, const Point64& e1top,
const Point64& e2bot, const Point64& e2top, Point64& pt)
{
// de-scale (x & y)
// temporarily convert integers to their initial float values
// this will slow clipping marginally but will make it much easier
// to understand the coordinates passed to the callback function
PointD tmp = PointD(pt) * invScale_;
PointD e1b = PointD(e1bot) * invScale_;
PointD e1t = PointD(e1top) * invScale_;
PointD e2b = PointD(e2bot) * invScale_;
PointD e2t = PointD(e2top) * invScale_;
zCallback_(e1b,e1t, e2b, e2t, tmp);
pt.z = tmp.z; // only update 'z'
};
void CheckCallback()
{
if(zCallback_)
// if the user defined float point callback has been assigned
// then assign the proxy callback function
ClipperBase::zCallback_ =
std::bind(&ClipperD::ZCB, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4, std::placeholders::_5);
else
ClipperBase::zCallback_ = nullptr;
}
#endif
void AddSubject(const PathsD& subjects)
{
AddPaths(ScalePaths<int64_t, double>(subjects, scale_), PathType::Subject, false);
}
void AddOpenSubject(const PathsD& open_subjects)
{
AddPaths(ScalePaths<int64_t, double>(open_subjects, scale_), PathType::Subject, true);
}
void AddClip(const PathsD& clips)
{
AddPaths(ScalePaths<int64_t, double>(clips, scale_), PathType::Clip, false);
}
bool Execute(ClipType clip_type, FillRule fill_rule, PathsD& closed_paths)
{
PathsD dummy;
return Execute(clip_type, fill_rule, closed_paths, dummy);
}
bool Execute(ClipType clip_type,
FillRule fill_rule, PathsD& closed_paths, PathsD& open_paths)
{
#ifdef USINGZ
CheckCallback();
#endif
if (ExecuteInternal(clip_type, fill_rule, false))
{
BuildPathsD(closed_paths, &open_paths);
}
CleanUp();
return succeeded_;
}
bool Execute(ClipType clip_type, FillRule fill_rule, PolyTreeD& polytree)
{
PathsD dummy;
return Execute(clip_type, fill_rule, polytree, dummy);
}
bool Execute(ClipType clip_type,
FillRule fill_rule, PolyTreeD& polytree, PathsD& open_paths)
{
#ifdef USINGZ
CheckCallback();
#endif
if (ExecuteInternal(clip_type, fill_rule, true))
{
polytree.Clear();
polytree.SetInvScale(invScale_);
open_paths.clear();
BuildTreeD(polytree, open_paths);
}
CleanUp();
return succeeded_;
}
};
} // namespace
#endif // CLIPPER_ENGINE_H

View file

@ -0,0 +1,830 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 30 October 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : This module exports the Clipper2 Library (ie DLL/so) *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
// The exported functions below refer to simple structures that
// can be understood across multiple languages. Consequently
// Path64, PathD, Polytree64 etc are converted from C++ classes
// (std::vector<> etc) into the following data structures:
//
// CPath64 (int64_t*) & CPathD (double_t*):
// Path64 and PathD are converted into arrays of x,y coordinates.
// However in these arrays the first x,y coordinate pair is a
// counter with 'x' containing the number of following coordinate
// pairs. ('y' should be 0, with one exception explained below.)
// __________________________________
// |counter|coord1|coord2|...|coordN|
// |N ,0 |x1, y1|x2, y2|...|xN, yN|
// __________________________________
//
// CPaths64 (int64_t**) & CPathsD (double_t**):
// These are arrays of pointers to CPath64 and CPathD where
// the first pointer is to a 'counter path'. This 'counter
// path' has a single x,y coord pair with 'y' (not 'x')
// containing the number of paths that follow. ('x' = 0).
// _______________________________
// |counter|path1|path2|...|pathN|
// |addr0 |addr1|addr2|...|addrN| (*addr0[0]=0; *addr0[1]=N)
// _______________________________
//
// The structures of CPolytree64 and CPolytreeD are defined
// below and these structures don't need to be explained here.
#ifndef CLIPPER2_EXPORT_H
#define CLIPPER2_EXPORT_H
#include <cstdlib>
#include <vector>
#include "clipper2/clipper.core.h"
#include "clipper2/clipper.engine.h"
#include "clipper2/clipper.offset.h"
#include "clipper2/clipper.rectclip.h"
namespace Clipper2Lib {
typedef int64_t* CPath64;
typedef int64_t** CPaths64;
typedef double* CPathD;
typedef double** CPathsD;
typedef struct CPolyPath64 {
CPath64 polygon;
uint32_t is_hole;
uint32_t child_count;
CPolyPath64* childs;
}
CPolyTree64;
typedef struct CPolyPathD {
CPathD polygon;
uint32_t is_hole;
uint32_t child_count;
CPolyPathD* childs;
}
CPolyTreeD;
template <typename T>
struct CRect {
T left;
T top;
T right;
T bottom;
};
typedef CRect<int64_t> CRect64;
typedef CRect<double> CRectD;
template <typename T>
inline bool CRectIsEmpty(const CRect<T>& rect)
{
return (rect.right <= rect.left) || (rect.bottom <= rect.top);
}
template <typename T>
inline Rect<T> CRectToRect(const CRect<T>& rect)
{
Rect<T> result;
result.left = rect.left;
result.top = rect.top;
result.right = rect.right;
result.bottom = rect.bottom;
return result;
}
#define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport)
//////////////////////////////////////////////////////
// EXPORTED FUNCTION DEFINITIONS
//////////////////////////////////////////////////////
EXTERN_DLL_EXPORT const char* Version();
// Some of the functions below will return data in the various CPath
// and CPolyTree structures which are pointers to heap allocated
// memory. Eventually this memory will need to be released with one
// of the following 'DisposeExported' functions. (This may be the
// only safe way to release this memory since the executable
// accessing these exported functions may use a memory manager that
// allocates and releases heap memory in a different way. Also,
// CPath structures that have been constructed by the executable
// should not be destroyed using these 'DisposeExported' functions.)
EXTERN_DLL_EXPORT void DisposeExportedCPath64(CPath64 p);
EXTERN_DLL_EXPORT void DisposeExportedCPaths64(CPaths64& pp);
EXTERN_DLL_EXPORT void DisposeExportedCPathD(CPathD p);
EXTERN_DLL_EXPORT void DisposeExportedCPathsD(CPathsD& pp);
EXTERN_DLL_EXPORT void DisposeExportedCPolyTree64(CPolyTree64*& cpt);
EXTERN_DLL_EXPORT void DisposeExportedCPolyTreeD(CPolyTreeD*& cpt);
// Boolean clipping:
// cliptype: None=0, Intersection=1, Union=2, Difference=3, Xor=4
// fillrule: EvenOdd=0, NonZero=1, Positive=2, Negative=3
EXTERN_DLL_EXPORT int BooleanOp64(uint8_t cliptype,
uint8_t fillrule, const CPaths64 subjects,
const CPaths64 subjects_open, const CPaths64 clips,
CPaths64& solution, CPaths64& solution_open,
bool preserve_collinear = true, bool reverse_solution = false);
EXTERN_DLL_EXPORT int BooleanOpPt64(uint8_t cliptype,
uint8_t fillrule, const CPaths64 subjects,
const CPaths64 subjects_open, const CPaths64 clips,
CPolyTree64*& solution, CPaths64& solution_open,
bool preserve_collinear = true, bool reverse_solution = false);
EXTERN_DLL_EXPORT int BooleanOpD(uint8_t cliptype,
uint8_t fillrule, const CPathsD subjects,
const CPathsD subjects_open, const CPathsD clips,
CPathsD& solution, CPathsD& solution_open, int precision = 2,
bool preserve_collinear = true, bool reverse_solution = false);
EXTERN_DLL_EXPORT int BooleanOpPtD(uint8_t cliptype,
uint8_t fillrule, const CPathsD subjects,
const CPathsD subjects_open, const CPathsD clips,
CPolyTreeD*& solution, CPathsD& solution_open, int precision = 2,
bool preserve_collinear = true, bool reverse_solution = false);
// Polygon offsetting (inflate/deflate):
// jointype: Square=0, Round=1, Miter=2
// endtype: Polygon=0, Joined=1, Butt=2, Square=3, Round=4
EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
double delta, uint8_t jointype, uint8_t endtype,
double miter_limit = 2.0, double arc_tolerance = 0.0,
bool reverse_solution = false);
EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
double delta, uint8_t jointype, uint8_t endtype,
int precision = 2, double miter_limit = 2.0,
double arc_tolerance = 0.0, bool reverse_solution = false);
// RectClip & RectClipLines:
EXTERN_DLL_EXPORT CPaths64 RectClip64(const CRect64& rect,
const CPaths64 paths);
EXTERN_DLL_EXPORT CPathsD RectClipD(const CRectD& rect,
const CPathsD paths, int precision = 2);
EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const CRect64& rect,
const CPaths64 paths);
EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const CRectD& rect,
const CPathsD paths, int precision = 2);
//////////////////////////////////////////////////////
// INTERNAL FUNCTIONS
//////////////////////////////////////////////////////
inline CPath64 CreateCPath64(size_t cnt1, size_t cnt2);
inline CPath64 CreateCPath64(const Path64& p);
inline CPaths64 CreateCPaths64(const Paths64& pp);
inline Path64 ConvertCPath64(const CPath64& p);
inline Paths64 ConvertCPaths64(const CPaths64& pp);
inline CPathD CreateCPathD(size_t cnt1, size_t cnt2);
inline CPathD CreateCPathD(const PathD& p);
inline CPathsD CreateCPathsD(const PathsD& pp);
inline PathD ConvertCPathD(const CPathD& p);
inline PathsD ConvertCPathsD(const CPathsD& pp);
// the following function avoid multiple conversions
inline CPathD CreateCPathD(const Path64& p, double scale);
inline CPathsD CreateCPathsD(const Paths64& pp, double scale);
inline Path64 ConvertCPathD(const CPathD& p, double scale);
inline Paths64 ConvertCPathsD(const CPathsD& pp, double scale);
inline CPolyTree64* CreateCPolyTree64(const PolyTree64& pt);
inline CPolyTreeD* CreateCPolyTreeD(const PolyTree64& pt, double scale);
EXTERN_DLL_EXPORT const char* Version()
{
return CLIPPER2_VERSION;
}
EXTERN_DLL_EXPORT void DisposeExportedCPath64(CPath64 p)
{
if (p) delete[] p;
}
EXTERN_DLL_EXPORT void DisposeExportedCPaths64(CPaths64& pp)
{
if (!pp) return;
CPaths64 v = pp;
CPath64 cnts = *v;
const size_t cnt = static_cast<size_t>(cnts[1]);
for (size_t i = 0; i <= cnt; ++i) //nb: cnt +1
DisposeExportedCPath64(*v++);
delete[] pp;
pp = nullptr;
}
EXTERN_DLL_EXPORT void DisposeExportedCPathD(CPathD p)
{
if (p) delete[] p;
}
EXTERN_DLL_EXPORT void DisposeExportedCPathsD(CPathsD& pp)
{
if (!pp) return;
CPathsD v = pp;
CPathD cnts = *v;
size_t cnt = static_cast<size_t>(cnts[1]);
for (size_t i = 0; i <= cnt; ++i) //nb: cnt +1
DisposeExportedCPathD(*v++);
delete[] pp;
pp = nullptr;
}
EXTERN_DLL_EXPORT int BooleanOp64(uint8_t cliptype,
uint8_t fillrule, const CPaths64 subjects,
const CPaths64 subjects_open, const CPaths64 clips,
CPaths64& solution, CPaths64& solution_open,
bool preserve_collinear, bool reverse_solution)
{
if (cliptype > static_cast<uint8_t>(ClipType::Xor)) return -4;
if (fillrule > static_cast<uint8_t>(FillRule::Negative)) return -3;
Paths64 sub, sub_open, clp, sol, sol_open;
sub = ConvertCPaths64(subjects);
sub_open = ConvertCPaths64(subjects_open);
clp = ConvertCPaths64(clips);
Clipper64 clipper;
clipper.PreserveCollinear = preserve_collinear;
clipper.ReverseSolution = reverse_solution;
if (sub.size() > 0) clipper.AddSubject(sub);
if (sub_open.size() > 0) clipper.AddOpenSubject(sub_open);
if (clp.size() > 0) clipper.AddClip(clp);
if (!clipper.Execute(ClipType(cliptype), FillRule(fillrule), sol, sol_open))
return -1; // clipping bug - should never happen :)
solution = CreateCPaths64(sol);
solution_open = CreateCPaths64(sol_open);
return 0; //success !!
}
EXTERN_DLL_EXPORT int BooleanOpPt64(uint8_t cliptype,
uint8_t fillrule, const CPaths64 subjects,
const CPaths64 subjects_open, const CPaths64 clips,
CPolyTree64*& solution, CPaths64& solution_open,
bool preserve_collinear, bool reverse_solution)
{
if (cliptype > static_cast<uint8_t>(ClipType::Xor)) return -4;
if (fillrule > static_cast<uint8_t>(FillRule::Negative)) return -3;
Paths64 sub, sub_open, clp, sol_open;
sub = ConvertCPaths64(subjects);
sub_open = ConvertCPaths64(subjects_open);
clp = ConvertCPaths64(clips);
PolyTree64 pt;
Clipper64 clipper;
clipper.PreserveCollinear = preserve_collinear;
clipper.ReverseSolution = reverse_solution;
if (sub.size() > 0) clipper.AddSubject(sub);
if (sub_open.size() > 0) clipper.AddOpenSubject(sub_open);
if (clp.size() > 0) clipper.AddClip(clp);
if (!clipper.Execute(ClipType(cliptype), FillRule(fillrule), pt, sol_open))
return -1; // clipping bug - should never happen :)
solution = CreateCPolyTree64(pt);
solution_open = CreateCPaths64(sol_open);
return 0; //success !!
}
EXTERN_DLL_EXPORT int BooleanOpD(uint8_t cliptype,
uint8_t fillrule, const CPathsD subjects,
const CPathsD subjects_open, const CPathsD clips,
CPathsD& solution, CPathsD& solution_open, int precision,
bool preserve_collinear, bool reverse_solution)
{
if (precision < -8 || precision > 8) return -5;
if (cliptype > static_cast<uint8_t>(ClipType::Xor)) return -4;
if (fillrule > static_cast<uint8_t>(FillRule::Negative)) return -3;
const double scale = std::pow(10, precision);
Paths64 sub, sub_open, clp, sol, sol_open;
sub = ConvertCPathsD(subjects, scale);
sub_open = ConvertCPathsD(subjects_open, scale);
clp = ConvertCPathsD(clips, scale);
Clipper64 clipper;
clipper.PreserveCollinear = preserve_collinear;
clipper.ReverseSolution = reverse_solution;
if (sub.size() > 0) clipper.AddSubject(sub);
if (sub_open.size() > 0)
clipper.AddOpenSubject(sub_open);
if (clp.size() > 0) clipper.AddClip(clp);
if (!clipper.Execute(ClipType(cliptype),
FillRule(fillrule), sol, sol_open)) return -1;
if (sol.size() > 0) solution = CreateCPathsD(sol, 1 / scale);
if (sol_open.size() > 0)
solution_open = CreateCPathsD(sol_open, 1 / scale);
return 0;
}
EXTERN_DLL_EXPORT int BooleanOpPtD(uint8_t cliptype,
uint8_t fillrule, const CPathsD subjects,
const CPathsD subjects_open, const CPathsD clips,
CPolyTreeD*& solution, CPathsD& solution_open, int precision,
bool preserve_collinear, bool reverse_solution)
{
if (precision < -8 || precision > 8) return -5;
if (cliptype > static_cast<uint8_t>(ClipType::Xor)) return -4;
if (fillrule > static_cast<uint8_t>(FillRule::Negative)) return -3;
const double scale = std::pow(10, precision);
Paths64 sub, sub_open, clp, sol_open;
sub = ConvertCPathsD(subjects, scale);
sub_open = ConvertCPathsD(subjects_open, scale);
clp = ConvertCPathsD(clips, scale);
PolyTree64 sol;
Clipper64 clipper;
clipper.PreserveCollinear = preserve_collinear;
clipper.ReverseSolution = reverse_solution;
if (sub.size() > 0) clipper.AddSubject(sub);
if (sub_open.size() > 0)
clipper.AddOpenSubject(sub_open);
if (clp.size() > 0) clipper.AddClip(clp);
if (!clipper.Execute(ClipType(cliptype),
FillRule(fillrule), sol, sol_open)) return -1;
solution = CreateCPolyTreeD(sol, 1 / scale);
if (sol_open.size() > 0)
solution_open = CreateCPathsD(sol_open, 1 / scale);
return 0;
}
EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
double delta, uint8_t jointype, uint8_t endtype, double miter_limit,
double arc_tolerance, bool reverse_solution)
{
Paths64 pp;
pp = ConvertCPaths64(paths);
ClipperOffset clip_offset( miter_limit,
arc_tolerance, reverse_solution);
clip_offset.AddPaths(pp, JoinType(jointype), EndType(endtype));
Paths64 result = clip_offset.Execute(delta);
return CreateCPaths64(result);
}
EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
double delta, uint8_t jointype, uint8_t endtype,
int precision, double miter_limit,
double arc_tolerance, bool reverse_solution)
{
if (precision < -8 || precision > 8 || !paths) return nullptr;
const double scale = std::pow(10, precision);
ClipperOffset clip_offset(miter_limit, arc_tolerance, reverse_solution);
Paths64 pp = ConvertCPathsD(paths, scale);
clip_offset.AddPaths(pp, JoinType(jointype), EndType(endtype));
Paths64 result = clip_offset.Execute(delta * scale);
return CreateCPathsD(result, 1/scale);
}
EXTERN_DLL_EXPORT CPaths64 RectClip64(const CRect64& rect,
const CPaths64 paths)
{
if (CRectIsEmpty(rect) || !paths) return nullptr;
Rect64 r64 = CRectToRect(rect);
class RectClip rc(r64);
Paths64 pp = ConvertCPaths64(paths);
Paths64 result;
result.reserve(pp.size());
for (const Path64& p : pp)
{
Rect64 pathRec = Bounds(p);
if (!r64.Intersects(pathRec)) continue;
if (r64.Contains(pathRec))
result.push_back(p);
else
{
Path64 p2 = rc.Execute(p);
if (!p2.empty()) result.push_back(std::move(p2));
}
}
return CreateCPaths64(result);
}
EXTERN_DLL_EXPORT CPathsD RectClipD(const CRectD& rect,
const CPathsD paths, int precision)
{
if (CRectIsEmpty(rect) || !paths) return nullptr;
if (precision < -8 || precision > 8) return nullptr;
const double scale = std::pow(10, precision);
Rect64 r = ScaleRect<int64_t, double>(CRectToRect(rect), scale);
Paths64 pp = ConvertCPathsD(paths, scale);
class RectClip rc(r);
Paths64 result;
result.reserve(pp.size());
for (const Path64& p : pp)
{
Rect64 pathRec = Bounds(p);
if (!r.Intersects(pathRec)) continue;
if (r.Contains(pathRec))
result.push_back(p);
else
{
Path64 p2 = rc.Execute(p);
if (!p2.empty()) result.push_back(std::move(p2));
}
}
return CreateCPathsD(result, 1/scale);
}
EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const CRect64& rect,
const CPaths64 paths)
{
if (CRectIsEmpty(rect) || !paths) return nullptr;
Rect64 r = CRectToRect(rect);
class RectClipLines rcl (r);
Paths64 pp = ConvertCPaths64(paths);
Paths64 result;
result.reserve(pp.size());
for (const Path64& p : pp)
{
Rect64 pathRec = Bounds(p);
if (!r.Intersects(pathRec)) continue;
if (r.Contains(pathRec))
result.push_back(p);
else
{
Paths64 pp2 = rcl.Execute(p);
if (!pp2.empty())
result.insert(result.end(), pp2.begin(), pp2.end());
}
}
return CreateCPaths64(result);
}
EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const CRectD& rect,
const CPathsD paths, int precision)
{
Paths64 result;
if (CRectIsEmpty(rect) || !paths) return nullptr;
if (precision < -8 || precision > 8) return nullptr;
const double scale = std::pow(10, precision);
Rect64 r = ScaleRect<int64_t, double>(CRectToRect(rect), scale);
class RectClipLines rcl(r);
Paths64 pp = ConvertCPathsD(paths, scale);
result.reserve(pp.size());
for (const Path64& p : pp)
{
Rect64 pathRec = Bounds(p);
if (!r.Intersects(pathRec)) continue;
if (r.Contains(pathRec))
result.push_back(p);
else
{
Paths64 pp2 = rcl.Execute(p);
if (pp2.empty()) continue;
result.insert(result.end(), pp2.begin(), pp2.end());
}
}
return CreateCPathsD(result, 1/scale);
}
inline CPath64 CreateCPath64(size_t cnt1, size_t cnt2)
{
// allocates memory for CPath64, fills in the counter, and
// returns the structure ready to be filled with path data
CPath64 result = new int64_t[2 + cnt1 *2];
result[0] = cnt1;
result[1] = cnt2;
return result;
}
inline CPath64 CreateCPath64(const Path64& p)
{
// allocates memory for CPath64, fills the counter
// and returns the memory filled with path data
size_t cnt = p.size();
if (!cnt) return nullptr;
CPath64 result = CreateCPath64(cnt, 0);
CPath64 v = result;
v += 2; // skip counters
for (const Point64& pt : p)
{
*v++ = pt.x;
*v++ = pt.y;
}
return result;
}
inline Path64 ConvertCPath64(const CPath64& p)
{
Path64 result;
if (p && *p)
{
CPath64 v = p;
const size_t cnt = static_cast<size_t>(p[0]);
v += 2; // skip counters
result.reserve(cnt);
for (size_t i = 0; i < cnt; ++i)
{
// x,y here avoids right to left function evaluation
// result.push_back(Point64(*v++, *v++));
int64_t x = *v++;
int64_t y = *v++;
result.push_back(Point64(x, y));
}
}
return result;
}
inline CPaths64 CreateCPaths64(const Paths64& pp)
{
// allocates memory for multiple CPath64 and
// and returns this memory filled with path data
size_t cnt = pp.size(), cnt2 = cnt;
// don't allocate space for empty paths
for (size_t i = 0; i < cnt; ++i)
if (!pp[i].size()) --cnt2;
if (!cnt2) return nullptr;
CPaths64 result = new int64_t* [cnt2 + 1];
CPaths64 v = result;
*v++ = CreateCPath64(0, cnt2); // assign a counter path
for (const Path64& p : pp)
{
*v = CreateCPath64(p);
if (*v) ++v;
}
return result;
}
inline Paths64 ConvertCPaths64(const CPaths64& pp)
{
Paths64 result;
if (pp)
{
CPaths64 v = pp;
CPath64 cnts = pp[0];
const size_t cnt = static_cast<size_t>(cnts[1]); // nb 2nd cnt
++v; // skip cnts
result.reserve(cnt);
for (size_t i = 0; i < cnt; ++i)
result.push_back(ConvertCPath64(*v++));
}
return result;
}
inline CPathD CreateCPathD(size_t cnt1, size_t cnt2)
{
// allocates memory for CPathD, fills in the counter, and
// returns the structure ready to be filled with path data
CPathD result = new double[2 + cnt1 * 2];
result[0] = static_cast<double>(cnt1);
result[1] = static_cast<double>(cnt2);
return result;
}
inline CPathD CreateCPathD(const PathD& p)
{
// allocates memory for CPath, fills the counter
// and returns the memory fills with path data
size_t cnt = p.size();
if (!cnt) return nullptr;
CPathD result = CreateCPathD(cnt, 0);
CPathD v = result;
v += 2; // skip counters
for (const PointD& pt : p)
{
*v++ = pt.x;
*v++ = pt.y;
}
return result;
}
inline PathD ConvertCPathD(const CPathD& p)
{
PathD result;
if (p)
{
CPathD v = p;
size_t cnt = static_cast<size_t>(v[0]);
v += 2; // skip counters
result.reserve(cnt);
for (size_t i = 0; i < cnt; ++i)
{
// x,y here avoids right to left function evaluation
// result.push_back(PointD(*v++, *v++));
double x = *v++;
double y = *v++;
result.push_back(PointD(x, y));
}
}
return result;
}
inline CPathsD CreateCPathsD(const PathsD& pp)
{
size_t cnt = pp.size(), cnt2 = cnt;
// don't allocate space for empty paths
for (size_t i = 0; i < cnt; ++i)
if (!pp[i].size()) --cnt2;
if (!cnt2) return nullptr;
CPathsD result = new double * [cnt2 + 1];
CPathsD v = result;
*v++ = CreateCPathD(0, cnt2); // assign counter path
for (const PathD& p : pp)
{
*v = CreateCPathD(p);
if (*v) { ++v; }
}
return result;
}
inline PathsD ConvertCPathsD(const CPathsD& pp)
{
PathsD result;
if (pp)
{
CPathsD v = pp;
CPathD cnts = v[0];
size_t cnt = static_cast<size_t>(cnts[1]);
++v; // skip cnts path
result.reserve(cnt);
for (size_t i = 0; i < cnt; ++i)
result.push_back(ConvertCPathD(*v++));
}
return result;
}
inline Path64 ConvertCPathD(const CPathD& p, double scale)
{
Path64 result;
if (p)
{
CPathD v = p;
size_t cnt = static_cast<size_t>(*v);
v += 2; // skip counters
result.reserve(cnt);
for (size_t i = 0; i < cnt; ++i)
{
// x,y here avoids right to left function evaluation
// result.push_back(PointD(*v++, *v++));
double x = *v++ * scale;
double y = *v++ * scale;
result.push_back(Point64(x, y));
}
}
return result;
}
inline Paths64 ConvertCPathsD(const CPathsD& pp, double scale)
{
Paths64 result;
if (pp)
{
CPathsD v = pp;
CPathD cnts = v[0];
size_t cnt = static_cast<size_t>(cnts[1]);
result.reserve(cnt);
++v; // skip cnts path
for (size_t i = 0; i < cnt; ++i)
result.push_back(ConvertCPathD(*v++, scale));
}
return result;
}
inline CPathD CreateCPathD(const Path64& p, double scale)
{
// allocates memory for CPathD, fills in the counter, and
// returns the structure filled with *scaled* path data
size_t cnt = p.size();
if (!cnt) return nullptr;
CPathD result = CreateCPathD(cnt, 0);
CPathD v = result;
v += 2; // skip cnts
for (const Point64& pt : p)
{
*v++ = pt.x * scale;
*v++ = pt.y * scale;
}
return result;
}
inline CPathsD CreateCPathsD(const Paths64& pp, double scale)
{
// allocates memory for *multiple* CPathD, and
// returns the structure filled with scaled path data
size_t cnt = pp.size(), cnt2 = cnt;
// don't allocate space for empty paths
for (size_t i = 0; i < cnt; ++i)
if (!pp[i].size()) --cnt2;
if (!cnt2) return nullptr;
CPathsD result = new double* [cnt2 + 1];
CPathsD v = result;
*v++ = CreateCPathD(0, cnt2);
for (const Path64& p : pp)
{
*v = CreateCPathD(p, scale);
if (*v) ++v;
}
return result;
}
inline void InitCPolyPath64(CPolyTree64* cpt,
bool is_hole, const PolyPath64* pp)
{
cpt->polygon = CreateCPath64(pp->Polygon());
cpt->is_hole = is_hole;
size_t child_cnt = pp->Count();
cpt->child_count = static_cast<uint32_t>(child_cnt);
cpt->childs = nullptr;
if (!child_cnt) return;
cpt->childs = new CPolyPath64[child_cnt];
CPolyPath64* child = cpt->childs;
for (const PolyPath64* pp_child : *pp)
InitCPolyPath64(child++, !is_hole, pp_child);
}
inline CPolyTree64* CreateCPolyTree64(const PolyTree64& pt)
{
CPolyTree64* result = new CPolyTree64();
result->polygon = nullptr;
result->is_hole = false;
size_t child_cnt = pt.Count();
result->childs = nullptr;
result->child_count = static_cast<uint32_t>(child_cnt);
if (!child_cnt) return result;
result->childs = new CPolyPath64[child_cnt];
CPolyPath64* child = result->childs;
for (const PolyPath64* pp : pt)
InitCPolyPath64(child++, true, pp);
return result;
}
inline void DisposeCPolyPath64(CPolyPath64* cpp)
{
if (!cpp->child_count) return;
CPolyPath64* child = cpp->childs;
for (size_t i = 0; i < cpp->child_count; ++i)
DisposeCPolyPath64(child);
delete[] cpp->childs;
}
EXTERN_DLL_EXPORT void DisposeExportedCPolyTree64(CPolyTree64*& cpt)
{
if (!cpt) return;
DisposeCPolyPath64(cpt);
delete cpt;
cpt = nullptr;
}
inline void InitCPolyPathD(CPolyTreeD* cpt,
bool is_hole, const PolyPath64* pp, double scale)
{
cpt->polygon = CreateCPathD(pp->Polygon(), scale);
cpt->is_hole = is_hole;
size_t child_cnt = pp->Count();
cpt->child_count = static_cast<uint32_t>(child_cnt);
cpt->childs = nullptr;
if (!child_cnt) return;
cpt->childs = new CPolyPathD[child_cnt];
CPolyPathD* child = cpt->childs;
for (const PolyPath64* pp_child : *pp)
InitCPolyPathD(child++, !is_hole, pp_child, scale);
}
inline CPolyTreeD* CreateCPolyTreeD(const PolyTree64& pt, double scale)
{
CPolyTreeD* result = new CPolyTreeD();
result->polygon = nullptr;
result->is_hole = false;
size_t child_cnt = pt.Count();
result->child_count = static_cast<uint32_t>(child_cnt);
result->childs = nullptr;
if (!child_cnt) return result;
result->childs = new CPolyPathD[child_cnt];
CPolyPathD* child = result->childs;
for (const PolyPath64* pp : pt)
InitCPolyPathD(child++, true, pp, scale);
return result;
}
inline void DisposeCPolyPathD(CPolyPathD* cpp)
{
if (!cpp->child_count) return;
CPolyPathD* child = cpp->childs;
for (size_t i = 0; i < cpp->child_count; ++i)
DisposeCPolyPathD(child++);
delete[] cpp->childs;
}
EXTERN_DLL_EXPORT void DisposeExportedCPolyTreeD(CPolyTreeD*& cpt)
{
if (!cpt) return;
DisposeCPolyPathD(cpt);
delete cpt;
cpt = nullptr;
}
} // end Clipper2Lib namespace
#endif // CLIPPER2_EXPORT_H

View file

@ -0,0 +1,762 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 29 October 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : This module provides a simple interface to the Clipper Library *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
#ifndef CLIPPER_H
#define CLIPPER_H
#include <cstdlib>
#include <vector>
#include "clipper.core.h"
#include "clipper.engine.h"
#include "clipper.offset.h"
#include "clipper.minkowski.h"
#include "clipper.rectclip.h"
namespace Clipper2Lib {
static const Rect64 MaxInvalidRect64 = Rect64(
(std::numeric_limits<int64_t>::max)(),
(std::numeric_limits<int64_t>::max)(),
(std::numeric_limits<int64_t>::lowest)(),
(std::numeric_limits<int64_t>::lowest)());
static const RectD MaxInvalidRectD = RectD(
(std::numeric_limits<double>::max)(),
(std::numeric_limits<double>::max)(),
(std::numeric_limits<double>::lowest)(),
(std::numeric_limits<double>::lowest)());
inline Paths64 BooleanOp(ClipType cliptype, FillRule fillrule,
const Paths64& subjects, const Paths64& clips)
{
Paths64 result;
Clipper64 clipper;
clipper.AddSubject(subjects);
clipper.AddClip(clips);
clipper.Execute(cliptype, fillrule, result);
return result;
}
inline void BooleanOp(ClipType cliptype, FillRule fillrule,
const Paths64& subjects, const Paths64& clips, PolyTree64& solution)
{
Paths64 sol_open;
Clipper64 clipper;
clipper.AddSubject(subjects);
clipper.AddClip(clips);
clipper.Execute(cliptype, fillrule, solution, sol_open);
}
inline PathsD BooleanOp(ClipType cliptype, FillRule fillrule,
const PathsD& subjects, const PathsD& clips, int decimal_prec = 2)
{
CheckPrecision(decimal_prec);
PathsD result;
ClipperD clipper(decimal_prec);
clipper.AddSubject(subjects);
clipper.AddClip(clips);
clipper.Execute(cliptype, fillrule, result);
return result;
}
inline void BooleanOp(ClipType cliptype, FillRule fillrule,
const PathsD& subjects, const PathsD& clips,
PolyTreeD& polytree, int decimal_prec = 2)
{
CheckPrecision(decimal_prec);
PathsD result;
ClipperD clipper(decimal_prec);
clipper.AddSubject(subjects);
clipper.AddClip(clips);
clipper.Execute(cliptype, fillrule, polytree);
}
inline Paths64 Intersect(const Paths64& subjects, const Paths64& clips, FillRule fillrule)
{
return BooleanOp(ClipType::Intersection, fillrule, subjects, clips);
}
inline PathsD Intersect(const PathsD& subjects, const PathsD& clips, FillRule fillrule, int decimal_prec = 2)
{
return BooleanOp(ClipType::Intersection, fillrule, subjects, clips, decimal_prec);
}
inline Paths64 Union(const Paths64& subjects, const Paths64& clips, FillRule fillrule)
{
return BooleanOp(ClipType::Union, fillrule, subjects, clips);
}
inline PathsD Union(const PathsD& subjects, const PathsD& clips, FillRule fillrule, int decimal_prec = 2)
{
return BooleanOp(ClipType::Union, fillrule, subjects, clips, decimal_prec);
}
inline Paths64 Union(const Paths64& subjects, FillRule fillrule)
{
Paths64 result;
Clipper64 clipper;
clipper.AddSubject(subjects);
clipper.Execute(ClipType::Union, fillrule, result);
return result;
}
inline PathsD Union(const PathsD& subjects, FillRule fillrule, int decimal_prec = 2)
{
CheckPrecision(decimal_prec);
PathsD result;
ClipperD clipper(decimal_prec);
clipper.AddSubject(subjects);
clipper.Execute(ClipType::Union, fillrule, result);
return result;
}
inline Paths64 Difference(const Paths64& subjects, const Paths64& clips, FillRule fillrule)
{
return BooleanOp(ClipType::Difference, fillrule, subjects, clips);
}
inline PathsD Difference(const PathsD& subjects, const PathsD& clips, FillRule fillrule, int decimal_prec = 2)
{
return BooleanOp(ClipType::Difference, fillrule, subjects, clips, decimal_prec);
}
inline Paths64 Xor(const Paths64& subjects, const Paths64& clips, FillRule fillrule)
{
return BooleanOp(ClipType::Xor, fillrule, subjects, clips);
}
inline PathsD Xor(const PathsD& subjects, const PathsD& clips, FillRule fillrule, int decimal_prec = 2)
{
return BooleanOp(ClipType::Xor, fillrule, subjects, clips, decimal_prec);
}
inline Paths64 InflatePaths(const Paths64& paths, double delta,
JoinType jt, EndType et, double miter_limit = 2.0)
{
ClipperOffset clip_offset(miter_limit);
clip_offset.AddPaths(paths, jt, et);
return clip_offset.Execute(delta);
}
inline PathsD InflatePaths(const PathsD& paths, double delta,
JoinType jt, EndType et, double miter_limit = 2.0, int precision = 2)
{
CheckPrecision(precision);
const double scale = std::pow(10, precision);
ClipperOffset clip_offset(miter_limit);
clip_offset.AddPaths(ScalePaths<int64_t,double>(paths, scale), jt, et);
Paths64 tmp = clip_offset.Execute(delta * scale);
return ScalePaths<double, int64_t>(tmp, 1 / scale);
}
inline Path64 TranslatePath(const Path64& path, int64_t dx, int64_t dy)
{
Path64 result;
result.reserve(path.size());
for (const Point64& pt : path)
result.push_back(Point64(pt.x + dx, pt.y + dy));
return result;
}
inline PathD TranslatePath(const PathD& path, double dx, double dy)
{
PathD result;
result.reserve(path.size());
for (const PointD& pt : path)
result.push_back(PointD(pt.x + dx, pt.y + dy));
return result;
}
inline Paths64 TranslatePaths(const Paths64& paths, int64_t dx, int64_t dy)
{
Paths64 result;
result.reserve(paths.size());
for (const Path64& path : paths)
result.push_back(TranslatePath(path, dx, dy));
return result;
}
inline PathsD TranslatePaths(const PathsD& paths, double dx, double dy)
{
PathsD result;
result.reserve(paths.size());
for (const PathD& path : paths)
result.push_back(TranslatePath(path, dx, dy));
return result;
}
inline Rect64 Bounds(const Path64& path)
{
Rect64 rec = MaxInvalidRect64;
for (const Point64& pt : path)
{
if (pt.x < rec.left) rec.left = pt.x;
if (pt.x > rec.right) rec.right = pt.x;
if (pt.y < rec.top) rec.top = pt.y;
if (pt.y > rec.bottom) rec.bottom = pt.y;
}
if (rec.IsEmpty()) return Rect64();
return rec;
}
inline Rect64 Bounds(const Paths64& paths)
{
Rect64 rec = MaxInvalidRect64;
for (const Path64& path : paths)
for (const Point64& pt : path)
{
if (pt.x < rec.left) rec.left = pt.x;
if (pt.x > rec.right) rec.right = pt.x;
if (pt.y < rec.top) rec.top = pt.y;
if (pt.y > rec.bottom) rec.bottom = pt.y;
}
if (rec.IsEmpty()) return Rect64();
return rec;
}
inline RectD Bounds(const PathD& path)
{
RectD rec = MaxInvalidRectD;
for (const PointD& pt : path)
{
if (pt.x < rec.left) rec.left = pt.x;
if (pt.x > rec.right) rec.right = pt.x;
if (pt.y < rec.top) rec.top = pt.y;
if (pt.y > rec.bottom) rec.bottom = pt.y;
}
if (rec.IsEmpty()) return RectD();
return rec;
}
inline RectD Bounds(const PathsD& paths)
{
RectD rec = MaxInvalidRectD;
for (const PathD& path : paths)
for (const PointD& pt : path)
{
if (pt.x < rec.left) rec.left = pt.x;
if (pt.x > rec.right) rec.right = pt.x;
if (pt.y < rec.top) rec.top = pt.y;
if (pt.y > rec.bottom) rec.bottom = pt.y;
}
if (rec.IsEmpty()) return RectD();
return rec;
}
inline Path64 RectClip(const Rect64& rect, const Path64& path)
{
if (rect.IsEmpty() || path.empty()) return Path64();
Rect64 pathRec = Bounds(path);
if (!rect.Intersects(pathRec)) return Path64();
if (rect.Contains(pathRec)) return path;
class RectClip rc(rect);
return rc.Execute(path);
}
inline Paths64 RectClip(const Rect64& rect, const Paths64& paths)
{
if (rect.IsEmpty() || paths.empty()) return Paths64();
class RectClip rc(rect);
Paths64 result;
result.reserve(paths.size());
for (const Path64& p : paths)
{
Rect64 pathRec = Bounds(p);
if (!rect.Intersects(pathRec))
continue;
else if (rect.Contains(pathRec))
result.push_back(p);
else
{
Path64 p2 = rc.Execute(p);
if (!p2.empty()) result.push_back(std::move(p2));
}
}
return result;
}
inline PathD RectClip(const RectD& rect, const PathD& path, int precision = 2)
{
if (rect.IsEmpty() || path.empty() ||
!rect.Contains(Bounds(path))) return PathD();
CheckPrecision(precision);
const double scale = std::pow(10, precision);
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
class RectClip rc(r);
Path64 p = ScalePath<int64_t, double>(path, scale);
return ScalePath<double, int64_t>(rc.Execute(p), 1 / scale);
}
inline PathsD RectClip(const RectD& rect, const PathsD& paths, int precision = 2)
{
if (rect.IsEmpty() || paths.empty()) return PathsD();
CheckPrecision(precision);
const double scale = std::pow(10, precision);
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
class RectClip rc(r);
PathsD result;
result.reserve(paths.size());
for (const PathD& path : paths)
{
RectD pathRec = Bounds(path);
if (!rect.Intersects(pathRec))
continue;
else if (rect.Contains(pathRec))
result.push_back(path);
else
{
Path64 p = ScalePath<int64_t, double>(path, scale);
p = rc.Execute(p);
if (!p.empty())
result.push_back(ScalePath<double, int64_t>(p, 1 / scale));
}
}
return result;
}
inline Paths64 RectClipLines(const Rect64& rect, const Path64& path)
{
Paths64 result;
if (rect.IsEmpty() || path.empty()) return result;
Rect64 pathRec = Bounds(path);
if (!rect.Intersects(pathRec)) return result;
if (rect.Contains(pathRec))
{
result.push_back(path);
return result;
}
class RectClipLines rcl(rect);
return rcl.Execute(path);
}
inline Paths64 RectClipLines(const Rect64& rect, const Paths64& paths)
{
Paths64 result;
if (rect.IsEmpty() || paths.empty()) return result;
class RectClipLines rcl(rect);
for (const Path64& p : paths)
{
Rect64 pathRec = Bounds(p);
if (!rect.Intersects(pathRec))
continue;
else if (rect.Contains(pathRec))
result.push_back(p);
else
{
Paths64 pp = rcl.Execute(p);
if (!pp.empty())
result.insert(result.end(), pp.begin(), pp.end());
}
}
return result;
}
inline PathsD RectClipLines(const RectD& rect, const PathD& path, int precision = 2)
{
if (rect.IsEmpty() || path.empty() ||
!rect.Contains(Bounds(path))) return PathsD();
CheckPrecision(precision);
const double scale = std::pow(10, precision);
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
class RectClipLines rcl(r);
Path64 p = ScalePath<int64_t, double>(path, scale);
return ScalePaths<double, int64_t>(rcl.Execute(p), 1 / scale);
}
inline PathsD RectClipLines(const RectD& rect, const PathsD& paths, int precision = 2)
{
PathsD result;
if (rect.IsEmpty() || paths.empty()) return result;
CheckPrecision(precision);
const double scale = std::pow(10, precision);
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
class RectClipLines rcl(r);
result.reserve(paths.size());
for (const PathD& path : paths)
{
RectD pathRec = Bounds(path);
if (!rect.Intersects(pathRec))
continue;
else if (rect.Contains(pathRec))
result.push_back(path);
else
{
Path64 p = ScalePath<int64_t, double>(path, scale);
Paths64 pp = rcl.Execute(p);
if (pp.empty()) continue;
PathsD ppd = ScalePaths<double, int64_t>(pp, 1 / scale);
result.insert(result.end(), ppd.begin(), ppd.end());
}
}
return result;
}
namespace details
{
inline void PolyPathToPaths64(const PolyPath64& polypath, Paths64& paths)
{
paths.push_back(polypath.Polygon());
for (const PolyPath* child : polypath)
PolyPathToPaths64(*(PolyPath64*)(child), paths);
}
inline void PolyPathToPathsD(const PolyPathD& polypath, PathsD& paths)
{
paths.push_back(polypath.Polygon());
for (const PolyPath* child : polypath)
PolyPathToPathsD(*(PolyPathD*)(child), paths);
}
inline bool PolyPath64ContainsChildren(const PolyPath64& pp)
{
for (auto ch : pp)
{
PolyPath64* child = (PolyPath64*)ch;
for (const Point64& pt : child->Polygon())
if (PointInPolygon(pt, pp.Polygon()) == PointInPolygonResult::IsOutside)
return false;
if (child->Count() > 0 && !PolyPath64ContainsChildren(*child))
return false;
}
return true;
}
inline bool GetInt(std::string::const_iterator& iter, const
std::string::const_iterator& end_iter, int64_t& val)
{
val = 0;
bool is_neg = *iter == '-';
if (is_neg) ++iter;
std::string::const_iterator start_iter = iter;
while (iter != end_iter &&
((*iter >= '0') && (*iter <= '9')))
{
val = val * 10 + (static_cast<int64_t>(*iter++) - '0');
}
if (is_neg) val = -val;
return (iter != start_iter);
}
inline bool GetFloat(std::string::const_iterator& iter, const
std::string::const_iterator& end_iter, double& val)
{
val = 0;
bool is_neg = *iter == '-';
if (is_neg) ++iter;
int dec_pos = 1;
const std::string::const_iterator start_iter = iter;
while (iter != end_iter && (*iter == '.' ||
((*iter >= '0') && (*iter <= '9'))))
{
if (*iter == '.')
{
if (dec_pos != 1) break;
dec_pos = 0;
++iter;
continue;
}
if (dec_pos != 1) --dec_pos;
val = val * 10 + ((int64_t)(*iter++) - '0');
}
if (iter == start_iter || dec_pos == 0) return false;
if (dec_pos < 0)
val *= std::pow(10, dec_pos);
if (is_neg)
val *= -1;
return true;
}
inline void SkipWhiteSpace(std::string::const_iterator& iter,
const std::string::const_iterator& end_iter)
{
while (iter != end_iter && *iter <= ' ') ++iter;
}
inline void SkipSpacesWithOptionalComma(std::string::const_iterator& iter,
const std::string::const_iterator& end_iter)
{
bool comma_seen = false;
while (iter != end_iter)
{
if (*iter == ' ') ++iter;
else if (*iter == ',')
{
if (comma_seen) return; // don't skip 2 commas!
comma_seen = true;
++iter;
}
else return;
}
}
inline bool has_one_match(const char c, char* chrs)
{
while (*chrs > 0 && c != *chrs) ++chrs;
if (!*chrs) return false;
*chrs = ' '; // only match once per char
return true;
}
inline void SkipUserDefinedChars(std::string::const_iterator& iter,
const std::string::const_iterator& end_iter, const std::string& skip_chars)
{
const size_t MAX_CHARS = 16;
char buff[MAX_CHARS] = {0};
std::copy(skip_chars.cbegin(), skip_chars.cend(), &buff[0]);
while (iter != end_iter &&
(*iter <= ' ' || has_one_match(*iter, buff))) ++iter;
return;
}
} // end details namespace
inline Paths64 PolyTreeToPaths64(const PolyTree64& polytree)
{
Paths64 result;
for (auto child : polytree)
details::PolyPathToPaths64(*(PolyPath64*)(child), result);
return result;
}
inline PathsD PolyTreeToPathsD(const PolyTreeD& polytree)
{
PathsD result;
for (auto child : polytree)
details::PolyPathToPathsD(*(PolyPathD*)(child), result);
return result;
}
inline bool CheckPolytreeFullyContainsChildren(const PolyTree64& polytree)
{
for (auto child : polytree)
if (child->Count() > 0 &&
!details::PolyPath64ContainsChildren(*(PolyPath64*)(child)))
return false;
return true;
}
inline Path64 MakePath(const std::string& s)
{
const std::string skip_chars = " ,(){}[]";
Path64 result;
std::string::const_iterator s_iter = s.cbegin();
details::SkipUserDefinedChars(s_iter, s.cend(), skip_chars);
while (s_iter != s.cend())
{
int64_t y = 0, x = 0;
if (!details::GetInt(s_iter, s.cend(), x)) break;
details::SkipSpacesWithOptionalComma(s_iter, s.cend());
if (!details::GetInt(s_iter, s.cend(), y)) break;
result.push_back(Point64(x, y));
details::SkipUserDefinedChars(s_iter, s.cend(), skip_chars);
}
return result;
}
inline PathD MakePathD(const std::string& s)
{
const std::string skip_chars = " ,(){}[]";
PathD result;
std::string::const_iterator s_iter = s.cbegin();
details::SkipUserDefinedChars(s_iter, s.cend(), skip_chars);
while (s_iter != s.cend())
{
double y = 0, x = 0;
if (!details::GetFloat(s_iter, s.cend(), x)) break;
details::SkipSpacesWithOptionalComma(s_iter, s.cend());
if (!details::GetFloat(s_iter, s.cend(), y)) break;
result.push_back(PointD(x, y));
details::SkipUserDefinedChars(s_iter, s.cend(), skip_chars);
}
return result;
}
inline Path64 TrimCollinear(const Path64& p, bool is_open_path = false)
{
size_t len = p.size();
if (len < 3)
{
if (!is_open_path || len < 2 || p[0] == p[1]) return Path64();
else return p;
}
Path64 dst;
dst.reserve(len);
Path64::const_iterator srcIt = p.cbegin(), prevIt, stop = p.cend() - 1;
if (!is_open_path)
{
while (srcIt != stop && !CrossProduct(*stop, *srcIt, *(srcIt + 1)))
++srcIt;
while (srcIt != stop && !CrossProduct(*(stop - 1), *stop, *srcIt))
--stop;
if (srcIt == stop) return Path64();
}
prevIt = srcIt++;
dst.push_back(*prevIt);
for (; srcIt != stop; ++srcIt)
{
if (CrossProduct(*prevIt, *srcIt, *(srcIt + 1)))
{
prevIt = srcIt;
dst.push_back(*prevIt);
}
}
if (is_open_path)
dst.push_back(*srcIt);
else if (CrossProduct(*prevIt, *stop, dst[0]))
dst.push_back(*stop);
else
{
while (dst.size() > 2 &&
!CrossProduct(dst[dst.size() - 1], dst[dst.size() - 2], dst[0]))
dst.pop_back();
if (dst.size() < 3) return Path64();
}
return dst;
}
inline PathD TrimCollinear(const PathD& path, int precision, bool is_open_path = false)
{
CheckPrecision(precision);
const double scale = std::pow(10, precision);
Path64 p = ScalePath<int64_t, double>(path, scale);
p = TrimCollinear(p, is_open_path);
return ScalePath<double, int64_t>(p, 1/scale);
}
template <typename T>
inline double Distance(const Point<T> pt1, const Point<T> pt2)
{
return std::sqrt(DistanceSqr(pt1, pt2));
}
template <typename T>
inline double Length(const Path<T>& path, bool is_closed_path = false)
{
double result = 0.0;
if (path.size() < 2) return result;
auto it = path.cbegin(), stop = path.end() - 1;
for (; it != stop; ++it)
result += Distance(*it, *(it + 1));
if (is_closed_path)
result += Distance(*stop, *path.cbegin());
return result;
}
template <typename T>
inline bool NearCollinear(const Point<T>& pt1, const Point<T>& pt2, const Point<T>& pt3, double sin_sqrd_min_angle_rads)
{
double cp = std::abs(CrossProduct(pt1, pt2, pt3));
return (cp * cp) / (DistanceSqr(pt1, pt2) * DistanceSqr(pt2, pt3)) < sin_sqrd_min_angle_rads;
}
template <typename T>
inline Path<T> Ellipse(const Rect<T>& rect, int steps = 0)
{
return Ellipse(rect.MidPoint(),
static_cast<double>(rect.Width()) *0.5,
static_cast<double>(rect.Height()) * 0.5, steps);
}
template <typename T>
inline Path<T> Ellipse(const Point<T>& center,
double radiusX, double radiusY = 0, int steps = 0)
{
if (radiusX <= 0) return Path<T>();
if (radiusY <= 0) radiusY = radiusX;
if (steps <= 2)
steps = static_cast<int>(PI * sqrt((radiusX + radiusY) / 2));
double si = std::sin(2 * PI / steps);
double co = std::cos(2 * PI / steps);
double dx = co, dy = si;
Path<T> result;
result.reserve(steps);
result.push_back(Point<T>(center.x + radiusX, static_cast<double>(center.y)));
for (int i = 1; i < steps; ++i)
{
result.push_back(Point<T>(center.x + radiusX * dx, center.y + radiusY * dy));
double x = dx * co - dy * si;
dy = dy * co + dx * si;
dx = x;
}
return result;
}
template <typename T>
inline double PerpendicDistFromLineSqrd(const Point<T>& pt,
const Point<T>& line1, const Point<T>& line2)
{
double a = static_cast<double>(pt.x - line1.x);
double b = static_cast<double>(pt.y - line1.y);
double c = static_cast<double>(line2.x - line1.x);
double d = static_cast<double>(line2.y - line1.y);
if (c == 0 && d == 0) return 0;
return Sqr(a * d - c * b) / (c * c + d * d);
}
template <typename T>
inline void RDP(const Path<T> path, std::size_t begin,
std::size_t end, double epsSqrd, std::vector<bool>& flags)
{
typename Path<T>::size_type idx = 0;
double max_d = 0;
while (end > begin && path[begin] == path[end]) flags[end--] = false;
for (typename Path<T>::size_type i = begin + 1; i < end; ++i)
{
// PerpendicDistFromLineSqrd - avoids expensive Sqrt()
double d = PerpendicDistFromLineSqrd(path[i], path[begin], path[end]);
if (d <= max_d) continue;
max_d = d;
idx = i;
}
if (max_d <= epsSqrd) return;
flags[idx] = true;
if (idx > begin + 1) RDP(path, begin, idx, epsSqrd, flags);
if (idx < end - 1) RDP(path, idx, end, epsSqrd, flags);
}
template <typename T>
inline Path<T> RamerDouglasPeucker(const Path<T>& path, double epsilon)
{
const typename Path<T>::size_type len = path.size();
if (len < 5) return Path<T>(path);
std::vector<bool> flags(len);
flags[0] = true;
flags[len - 1] = true;
RDP(path, 0, len - 1, Sqr(epsilon), flags);
Path<T> result;
result.reserve(len);
for (typename Path<T>::size_type i = 0; i < len; ++i)
if (flags[i])
result.push_back(path[i]);
return result;
}
template <typename T>
inline Paths<T> RamerDouglasPeucker(const Paths<T>& paths, double epsilon)
{
Paths<T> result;
result.reserve(paths.size());
for (const Path<T>& path : paths)
result.push_back(RamerDouglasPeucker<T>(path, epsilon));
return result;
}
} // end Clipper2Lib namespace
#endif // CLIPPER_H

View file

@ -0,0 +1,118 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 15 October 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : Minkowski Sum and Difference *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
#ifndef CLIPPER_MINKOWSKI_H
#define CLIPPER_MINKOWSKI_H
#include <cstdlib>
#include <vector>
#include <string>
#include "clipper.core.h"
namespace Clipper2Lib
{
namespace detail
{
inline Paths64 Minkowski(const Path64& pattern, const Path64& path, bool isSum, bool isClosed)
{
size_t delta = isClosed ? 0 : 1;
size_t patLen = pattern.size(), pathLen = path.size();
if (patLen == 0 || pathLen == 0) return Paths64();
Paths64 tmp;
tmp.reserve(pathLen);
if (isSum)
{
for (const Point64& p : path)
{
Path64 path2(pattern.size());
std::transform(pattern.cbegin(), pattern.cend(),
path2.begin(), [p](const Point64& pt2) {return p + pt2; });
tmp.push_back(path2);
}
}
else
{
for (const Point64& p : path)
{
Path64 path2(pattern.size());
std::transform(pattern.cbegin(), pattern.cend(),
path2.begin(), [p](const Point64& pt2) {return p - pt2; });
tmp.push_back(path2);
}
}
Paths64 result;
result.reserve((pathLen - delta) * patLen);
size_t g = isClosed ? pathLen - 1 : 0;
for (size_t h = patLen - 1, i = delta; i < pathLen; ++i)
{
for (size_t j = 0; j < patLen; j++)
{
Path64 quad;
quad.reserve(4);
{
quad.push_back(tmp[g][h]);
quad.push_back(tmp[i][h]);
quad.push_back(tmp[i][j]);
quad.push_back(tmp[g][j]);
};
if (!IsPositive(quad))
std::reverse(quad.begin(), quad.end());
result.push_back(quad);
h = j;
}
g = i;
}
return result;
}
inline Paths64 Union(const Paths64& subjects, FillRule fillrule)
{
Paths64 result;
Clipper64 clipper;
clipper.AddSubject(subjects);
clipper.Execute(ClipType::Union, fillrule, result);
return result;
}
} // namespace internal
inline Paths64 MinkowskiSum(const Path64& pattern, const Path64& path, bool isClosed)
{
return detail::Union(detail::Minkowski(pattern, path, true, isClosed), FillRule::NonZero);
}
inline PathsD MinkowskiSum(const PathD& pattern, const PathD& path, bool isClosed, int decimalPlaces = 2)
{
double scale = pow(10, decimalPlaces);
Path64 pat64 = ScalePath<int64_t, double>(pattern, scale);
Path64 path64 = ScalePath<int64_t, double>(path, scale);
Paths64 tmp = detail::Union(detail::Minkowski(pat64, path64, true, isClosed), FillRule::NonZero);
return ScalePaths<double, int64_t>(tmp, 1 / scale);
}
inline Paths64 MinkowskiDiff(const Path64& pattern, const Path64& path, bool isClosed)
{
return detail::Union(detail::Minkowski(pattern, path, false, isClosed), FillRule::NonZero);
}
inline PathsD MinkowskiDiff(const PathD& pattern, const PathD& path, bool isClosed, int decimalPlaces = 2)
{
double scale = pow(10, decimalPlaces);
Path64 pat64 = ScalePath<int64_t, double>(pattern, scale);
Path64 path64 = ScalePath<int64_t, double>(path, scale);
Paths64 tmp = detail::Union(detail::Minkowski(pat64, path64, false, isClosed), FillRule::NonZero);
return ScalePaths<double, int64_t>(tmp, 1 / scale);
}
} // Clipper2Lib namespace
#endif // CLIPPER_MINKOWSKI_H

View file

@ -0,0 +1,107 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 15 October 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : Path Offset (Inflate/Shrink) *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
#ifndef CLIPPER_OFFSET_H_
#define CLIPPER_OFFSET_H_
#include "clipper.core.h"
namespace Clipper2Lib {
enum class JoinType { Square, Round, Miter };
enum class EndType {Polygon, Joined, Butt, Square, Round};
//Butt : offsets both sides of a path, with square blunt ends
//Square : offsets both sides of a path, with square extended ends
//Round : offsets both sides of a path, with round extended ends
//Joined : offsets both sides of a path, with joined ends
//Polygon: offsets only one side of a closed path
class ClipperOffset {
private:
class Group {
public:
Paths64 paths_in_;
Paths64 paths_out_;
Path64 path_;
bool is_reversed_ = false;
JoinType join_type_;
EndType end_type_;
Group(const Paths64& paths, JoinType join_type, EndType end_type) :
paths_in_(paths), join_type_(join_type), end_type_(end_type) {}
};
double group_delta_ = 0.0;
double abs_group_delta_ = 0.0;
double temp_lim_ = 0.0;
double steps_per_rad_ = 0.0;
PathD norms;
Paths64 solution;
std::vector<Group> groups_;
JoinType join_type_ = JoinType::Square;
double miter_limit_ = 0.0;
double arc_tolerance_ = 0.0;
bool merge_groups_ = true;
bool preserve_collinear_ = false;
bool reverse_solution_ = false;
void DoSquare(Group& group, const Path64& path, size_t j, size_t k);
void DoMiter(Group& group, const Path64& path, size_t j, size_t k, double cos_a);
void DoRound(Group& group, const Path64& path, size_t j, size_t k, double angle);
void BuildNormals(const Path64& path);
void OffsetPolygon(Group& group, Path64& path);
void OffsetOpenJoined(Group& group, Path64& path);
void OffsetOpenPath(Group& group, Path64& path, EndType endType);
void OffsetPoint(Group& group, Path64& path, size_t j, size_t& k);
void DoGroupOffset(Group &group, double delta);
public:
ClipperOffset(double miter_limit = 2.0,
double arc_tolerance = 0.0,
bool preserve_collinear = false,
bool reverse_solution = false) :
miter_limit_(miter_limit), arc_tolerance_(arc_tolerance),
preserve_collinear_(preserve_collinear),
reverse_solution_(reverse_solution) { };
~ClipperOffset() { Clear(); };
void AddPath(const Path64& path, JoinType jt_, EndType et_);
void AddPaths(const Paths64& paths, JoinType jt_, EndType et_);
void AddPath(const PathD &p, JoinType jt_, EndType et_);
void AddPaths(const PathsD &p, JoinType jt_, EndType et_);
void Clear() { groups_.clear(); norms.clear(); };
Paths64 Execute(double delta);
double MiterLimit() const { return miter_limit_; }
void MiterLimit(double miter_limit) { miter_limit_ = miter_limit; }
//ArcTolerance: needed for rounded offsets (See offset_triginometry2.svg)
double ArcTolerance() const { return arc_tolerance_; }
void ArcTolerance(double arc_tolerance) { arc_tolerance_ = arc_tolerance; }
//MergeGroups: A path group is one or more paths added via the AddPath or
//AddPaths methods. By default these path groups will be offset
//independently of other groups and this may cause overlaps (intersections).
//However, when MergeGroups is enabled, any overlapping offsets will be
//merged (via a clipping union operation) to remove overlaps.
bool MergeGroups() const { return merge_groups_; }
void MergeGroups(bool merge_groups) { merge_groups_ = merge_groups; }
bool PreserveCollinear() const { return preserve_collinear_; }
void PreserveCollinear(bool preserve_collinear){preserve_collinear_ = preserve_collinear;}
bool ReverseSolution() const { return reverse_solution_; }
void ReverseSolution(bool reverse_solution) {reverse_solution_ = reverse_solution;}
};
}
#endif /* CLIPPER_OFFSET_H_ */

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 26 October 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : FAST rectangular clipping *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
#ifndef CLIPPER_RECTCLIP_H
#define CLIPPER_RECTCLIP_H
#include <cstdlib>
#include <vector>
#include "clipper.h"
#include "clipper.core.h"
namespace Clipper2Lib
{
enum class Location { Left, Top, Right, Bottom, Inside };
class RectClip {
protected:
const Rect64 rect_;
const Point64 mp_;
const Path64 rectPath_;
Path64 result_;
std::vector<Location> start_locs_;
void GetNextLocation(const Path64& path,
Location& loc, int& i, int highI);
void AddCorner(Location prev, Location curr);
void AddCorner(Location& loc, bool isClockwise);
public:
RectClip(const Rect64& rect) :
rect_(rect),
mp_(rect.MidPoint()),
rectPath_(rect.AsPath()) {}
Path64 Execute(const Path64& path);
};
class RectClipLines : public RectClip {
public:
RectClipLines(const Rect64& rect) : RectClip(rect) {};
Paths64 Execute(const Path64& path);
};
} // Clipper2Lib namespace
#endif // CLIPPER_RECTCLIP_H

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,485 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 15 October 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : Path Offset (Inflate/Shrink) *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
#include <cmath>
#include "clipper2/clipper.h"
#include "clipper2/clipper.offset.h"
namespace Clipper2Lib {
const double default_arc_tolerance = 0.25;
const double floating_point_tolerance = 1e-12;
//------------------------------------------------------------------------------
// Miscellaneous methods
//------------------------------------------------------------------------------
Paths64::size_type GetLowestPolygonIdx(const Paths64& paths)
{
Paths64::size_type result = 0;
Point64 lp = Point64(static_cast<int64_t>(0),
std::numeric_limits<int64_t>::min());
for (Paths64::size_type i = 0 ; i < paths.size(); ++i)
for (const Point64& p : paths[i])
{
if (p.y < lp.y || (p.y == lp.y && p.x >= lp.x)) continue;
result = i;
lp = p;
}
return result;
}
PointD GetUnitNormal(const Point64& pt1, const Point64& pt2)
{
double dx, dy, inverse_hypot;
if (pt1 == pt2) return PointD(0.0, 0.0);
dx = static_cast<double>(pt2.x - pt1.x);
dy = static_cast<double>(pt2.y - pt1.y);
inverse_hypot = 1.0 / hypot(dx, dy);
dx *= inverse_hypot;
dy *= inverse_hypot;
return PointD(dy, -dx);
}
inline bool AlmostZero(double value, double epsilon = 0.001)
{
return std::fabs(value) < epsilon;
}
inline double Hypot(double x, double y)
{
//see https://stackoverflow.com/a/32436148/359538
return std::sqrt(x * x + y * y);
}
inline PointD NormalizeVector(const PointD& vec)
{
double h = Hypot(vec.x, vec.y);
if (AlmostZero(h)) return PointD(0,0);
double inverseHypot = 1 / h;
return PointD(vec.x * inverseHypot, vec.y * inverseHypot);
}
inline PointD GetAvgUnitVector(const PointD& vec1, const PointD& vec2)
{
return NormalizeVector(PointD(vec1.x + vec2.x, vec1.y + vec2.y));
}
inline bool IsClosedPath(EndType et)
{
return et == EndType::Polygon || et == EndType::Joined;
}
inline Point64 GetPerpendic(const Point64& pt, const PointD& norm, double delta)
{
return Point64(pt.x + norm.x * delta, pt.y + norm.y * delta);
}
inline PointD GetPerpendicD(const Point64& pt, const PointD& norm, double delta)
{
return PointD(pt.x + norm.x * delta, pt.y + norm.y * delta);
}
//------------------------------------------------------------------------------
// ClipperOffset methods
//------------------------------------------------------------------------------
void ClipperOffset::AddPath(const Path64& path, JoinType jt_, EndType et_)
{
Paths64 paths;
paths.push_back(path);
AddPaths(paths, jt_, et_);
}
void ClipperOffset::AddPaths(const Paths64 &paths, JoinType jt_, EndType et_)
{
if (paths.size() == 0) return;
groups_.push_back(Group(paths, jt_, et_));
}
void ClipperOffset::AddPath(const Clipper2Lib::PathD& path, JoinType jt_, EndType et_)
{
PathsD paths;
paths.push_back(path);
AddPaths(paths, jt_, et_);
}
void ClipperOffset::AddPaths(const PathsD& paths, JoinType jt_, EndType et_)
{
if (paths.size() == 0) return;
groups_.push_back(Group(PathsDToPaths64(paths), jt_, et_));
}
void ClipperOffset::BuildNormals(const Path64& path)
{
norms.clear();
norms.reserve(path.size());
if (path.size() == 0) return;
Path64::const_iterator path_iter, path_last_iter = --path.cend();
for (path_iter = path.cbegin(); path_iter != path_last_iter; ++path_iter)
norms.push_back(GetUnitNormal(*path_iter,*(path_iter +1)));
norms.push_back(GetUnitNormal(*path_last_iter, *(path.cbegin())));
}
inline PointD TranslatePoint(const PointD& pt, double dx, double dy)
{
return PointD(pt.x + dx, pt.y + dy);
}
inline PointD ReflectPoint(const PointD& pt, const PointD& pivot)
{
return PointD(pivot.x + (pivot.x - pt.x), pivot.y + (pivot.y - pt.y));
}
PointD IntersectPoint(const PointD& pt1a, const PointD& pt1b,
const PointD& pt2a, const PointD& pt2b)
{
if (pt1a.x == pt1b.x) //vertical
{
if (pt2a.x == pt2b.x) return PointD(0, 0);
double m2 = (pt2b.y - pt2a.y) / (pt2b.x - pt2a.x);
double b2 = pt2a.y - m2 * pt2a.x;
return PointD(pt1a.x, m2 * pt1a.x + b2);
}
else if (pt2a.x == pt2b.x) //vertical
{
double m1 = (pt1b.y - pt1a.y) / (pt1b.x - pt1a.x);
double b1 = pt1a.y - m1 * pt1a.x;
return PointD(pt2a.x, m1 * pt2a.x + b1);
}
else
{
double m1 = (pt1b.y - pt1a.y) / (pt1b.x - pt1a.x);
double b1 = pt1a.y - m1 * pt1a.x;
double m2 = (pt2b.y - pt2a.y) / (pt2b.x - pt2a.x);
double b2 = pt2a.y - m2 * pt2a.x;
if (m1 == m2) return PointD(0, 0);
double x = (b2 - b1) / (m1 - m2);
return PointD(x, m1 * x + b1);
}
}
void ClipperOffset::DoSquare(Group& group, const Path64& path, size_t j, size_t k)
{
PointD vec;
if (j == k)
vec = PointD(norms[0].y, -norms[0].x);
else
vec = GetAvgUnitVector(
PointD(-norms[k].y, norms[k].x),
PointD(norms[j].y, -norms[j].x));
// now offset the original vertex delta units along unit vector
PointD ptQ = PointD(path[j]);
ptQ = TranslatePoint(ptQ, abs_group_delta_ * vec.x, abs_group_delta_ * vec.y);
// get perpendicular vertices
PointD pt1 = TranslatePoint(ptQ, group_delta_ * vec.y, group_delta_ * -vec.x);
PointD pt2 = TranslatePoint(ptQ, group_delta_ * -vec.y, group_delta_ * vec.x);
// get 2 vertices along one edge offset
PointD pt3 = GetPerpendicD(path[k], norms[k], group_delta_);
if (j == k)
{
PointD pt4 = PointD(pt3.x + vec.x * group_delta_, pt3.y + vec.y * group_delta_);
PointD pt = IntersectPoint(pt1, pt2, pt3, pt4);
//get the second intersect point through reflecion
group.path_.push_back(Point64(ReflectPoint(pt, ptQ)));
group.path_.push_back(Point64(pt));
}
else
{
PointD pt4 = GetPerpendicD(path[j], norms[k], group_delta_);
PointD pt = IntersectPoint(pt1, pt2, pt3, pt4);
group.path_.push_back(Point64(pt));
//get the second intersect point through reflecion
group.path_.push_back(Point64(ReflectPoint(pt, ptQ)));
}
}
void ClipperOffset::DoMiter(Group& group, const Path64& path, size_t j, size_t k, double cos_a)
{
double q = group_delta_ / (cos_a + 1);
group.path_.push_back(Point64(
path[j].x + (norms[k].x + norms[j].x) * q,
path[j].y + (norms[k].y + norms[j].y) * q));
}
void ClipperOffset::DoRound(Group& group, const Path64& path, size_t j, size_t k, double angle)
{
//even though angle may be negative this is a convex join
Point64 pt = path[j];
int steps = static_cast<int>(std::ceil(steps_per_rad_ * std::abs(angle)));
double step_sin = std::sin(angle / steps);
double step_cos = std::cos(angle / steps);
PointD pt2 = PointD(norms[k].x * group_delta_, norms[k].y * group_delta_);
if (j == k) pt2.Negate();
group.path_.push_back(Point64(pt.x + pt2.x, pt.y + pt2.y));
for (int i = 0; i < steps; i++)
{
pt2 = PointD(pt2.x * step_cos - step_sin * pt2.y,
pt2.x * step_sin + pt2.y * step_cos);
group.path_.push_back(Point64(pt.x + pt2.x, pt.y + pt2.y));
}
group.path_.push_back(GetPerpendic(path[j], norms[j], group_delta_));
}
void ClipperOffset::OffsetPoint(Group& group, Path64& path, size_t j, size_t& k)
{
// Let A = change in angle where edges join
// A == 0: ie no change in angle (flat join)
// A == PI: edges 'spike'
// sin(A) < 0: right turning
// cos(A) < 0: change in angle is more than 90 degree
if (path[j] == path[k]) { k = j; return; }
double sin_a = CrossProduct(norms[j], norms[k]);
double cos_a = DotProduct(norms[j], norms[k]);
if (sin_a > 1.0) sin_a = 1.0;
else if (sin_a < -1.0) sin_a = -1.0;
bool almostNoAngle = AlmostZero(sin_a) && cos_a > 0;
// when there's almost no angle of deviation or it's concave
if (almostNoAngle || (sin_a * group_delta_ < 0))
{
Point64 p1 = Point64(
path[j].x + norms[k].x * group_delta_,
path[j].y + norms[k].y * group_delta_);
Point64 p2 = Point64(
path[j].x + norms[j].x * group_delta_,
path[j].y + norms[j].y * group_delta_);
group.path_.push_back(p1);
if (p1 != p2)
{
// when concave add an extra vertex to ensure neat clipping
if (!almostNoAngle) group.path_.push_back(path[j]);
group.path_.push_back(p2);
}
}
else // it's convex
{
if (join_type_ == JoinType::Round)
DoRound(group, path, j, k, std::atan2(sin_a, cos_a));
else if (join_type_ == JoinType::Miter)
{
// miter unless the angle is so acute the miter would exceeds ML
if (cos_a > temp_lim_ - 1) DoMiter(group, path, j, k, cos_a);
else DoSquare(group, path, j, k);
}
// don't bother squaring angles that deviate < ~20 degrees because
// squaring will be indistinguishable from mitering and just be a lot slower
else if (cos_a > 0.9)
DoMiter(group, path, j, k, cos_a);
else
DoSquare(group, path, j, k);
}
k = j;
}
void ClipperOffset::OffsetPolygon(Group& group, Path64& path)
{
group.path_.clear();
for (Path64::size_type i = 0, j = path.size() -1; i < path.size(); j = i, ++i)
OffsetPoint(group, path, i, j);
group.paths_out_.push_back(group.path_);
}
void ClipperOffset::OffsetOpenJoined(Group& group, Path64& path)
{
OffsetPolygon(group, path);
std::reverse(path.begin(), path.end());
BuildNormals(path);
OffsetPolygon(group, path);
}
void ClipperOffset::OffsetOpenPath(Group& group, Path64& path, EndType end_type)
{
group.path_.clear();
// do the line start cap
switch (end_type)
{
case EndType::Butt:
group.path_.push_back(Point64(
path[0].x - norms[0].x * group_delta_,
path[0].y - norms[0].y * group_delta_));
group.path_.push_back(GetPerpendic(path[0], norms[0], group_delta_));
break;
case EndType::Round:
DoRound(group, path, 0,0, PI);
break;
default:
DoSquare(group, path, 0, 0);
break;
}
size_t highI = path.size() - 1;
// offset the left side going forward
for (Path64::size_type i = 1, k = 0; i < highI; ++i)
OffsetPoint(group, path, i, k);
// reverse normals
for (size_t i = highI; i > 0; --i)
norms[i] = PointD(-norms[i - 1].x, -norms[i - 1].y);
norms[0] = norms[highI];
// do the line end cap
switch (end_type)
{
case EndType::Butt:
group.path_.push_back(Point64(
path[highI].x - norms[highI].x * group_delta_,
path[highI].y - norms[highI].y * group_delta_));
group.path_.push_back(GetPerpendic(path[highI], norms[highI], group_delta_));
break;
case EndType::Round:
DoRound(group, path, highI, highI, PI);
break;
default:
DoSquare(group, path, highI, highI);
break;
}
for (size_t i = highI, k = 0; i > 0; --i)
OffsetPoint(group, path, i, k);
group.paths_out_.push_back(group.path_);
}
void ClipperOffset::DoGroupOffset(Group& group, double delta)
{
if (group.end_type_ != EndType::Polygon) delta = std::abs(delta) * 0.5;
bool isClosedPaths = IsClosedPath(group.end_type_);
if (isClosedPaths)
{
//the lowermost polygon must be an outer polygon. So we can use that as the
//designated orientation for outer polygons (needed for tidy-up clipping)
Paths64::size_type lowestIdx = GetLowestPolygonIdx(group.paths_in_);
// nb: don't use the default orientation here ...
double area = Area(group.paths_in_[lowestIdx]);
if (area == 0) return;
group.is_reversed_ = (area < 0);
if (group.is_reversed_) delta = -delta;
}
else
group.is_reversed_ = false;
group_delta_ = delta;
abs_group_delta_ = std::abs(group_delta_);
join_type_ = group.join_type_;
double arcTol = (arc_tolerance_ > floating_point_tolerance ? arc_tolerance_
: std::log10(2 + abs_group_delta_) * default_arc_tolerance); // empirically derived
//calculate a sensible number of steps (for 360 deg for the given offset
if (group.join_type_ == JoinType::Round || group.end_type_ == EndType::Round)
{
steps_per_rad_ = PI / std::acos(1 - arcTol / abs_group_delta_) / (PI *2);
}
bool is_closed_path = IsClosedPath(group.end_type_);
Paths64::const_iterator path_iter;
for(path_iter = group.paths_in_.cbegin(); path_iter != group.paths_in_.cend(); ++path_iter)
{
Path64 path = StripDuplicates(*path_iter, is_closed_path);
Path64::size_type cnt = path.size();
if (cnt == 0) continue;
if (cnt == 1) // single point - only valid with open paths
{
group.path_ = Path64();
//single vertex so build a circle or square ...
if (group.join_type_ == JoinType::Round)
{
double radius = abs_group_delta_;
group.path_ = Ellipse(path[0], radius, radius);
}
else
{
int d = (int)std::ceil(abs_group_delta_);
Rect64 r = Rect64(path[0].x - d, path[0].y - d, path[0].x + d, path[0].y + d);
group.path_ = r.AsPath();
}
group.paths_out_.push_back(group.path_);
}
else
{
BuildNormals(path);
if (group.end_type_ == EndType::Polygon) OffsetPolygon(group, path);
else if (group.end_type_ == EndType::Joined) OffsetOpenJoined(group, path);
else OffsetOpenPath(group, path, group.end_type_);
}
}
if (!merge_groups_)
{
//clean up self-intersections ...
Clipper64 c;
c.PreserveCollinear = false;
//the solution should retain the orientation of the input
c.ReverseSolution = reverse_solution_ != group.is_reversed_;
c.AddSubject(group.paths_out_);
if (group.is_reversed_)
c.Execute(ClipType::Union, FillRule::Negative, group.paths_out_);
else
c.Execute(ClipType::Union, FillRule::Positive, group.paths_out_);
}
solution.reserve(solution.size() + group.paths_out_.size());
copy(group.paths_out_.begin(), group.paths_out_.end(), back_inserter(solution));
group.paths_out_.clear();
}
Paths64 ClipperOffset::Execute(double delta)
{
solution.clear();
if (std::abs(delta) < default_arc_tolerance)
{
for (const Group& group : groups_)
{
solution.reserve(solution.size() + group.paths_in_.size());
copy(group.paths_in_.begin(), group.paths_in_.end(), back_inserter(solution));
}
return solution;
}
temp_lim_ = (miter_limit_ <= 1) ?
2.0 :
2.0 / (miter_limit_ * miter_limit_);
std::vector<Group>::iterator groups_iter;
for (groups_iter = groups_.begin();
groups_iter != groups_.end(); ++groups_iter)
{
DoGroupOffset(*groups_iter, delta);
}
if (merge_groups_ && groups_.size() > 0)
{
//clean up self-intersections ...
Clipper64 c;
c.PreserveCollinear = false;
//the solution should retain the orientation of the input
c.ReverseSolution = reverse_solution_ != groups_[0].is_reversed_;
c.AddSubject(solution);
if (groups_[0].is_reversed_)
c.Execute(ClipType::Union, FillRule::Negative, solution);
else
c.Execute(ClipType::Union, FillRule::Positive, solution);
}
return solution;
}
} // namespace

View file

@ -0,0 +1,547 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 26 October 2022 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2022 *
* Purpose : FAST rectangular clipping *
* License : http://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
#include <cmath>
#include "clipper2/clipper.h"
#include "clipper2/clipper.rectclip.h"
namespace Clipper2Lib {
//------------------------------------------------------------------------------
// Miscellaneous methods
//------------------------------------------------------------------------------
inline PointInPolygonResult Path1ContainsPath2(Path64 path1, Path64 path2)
{
PointInPolygonResult result = PointInPolygonResult::IsOn;
for(const Point64& pt : path2)
{
result = PointInPolygon(pt, path1);
if (result != PointInPolygonResult::IsOn) break;
}
return result;
}
inline bool GetLocation(const Rect64& rec,
const Point64& pt, Location& loc)
{
if (pt.x == rec.left && pt.y >= rec.top && pt.y <= rec.bottom)
{
loc = Location::Left;
return false;
}
else if (pt.x == rec.right && pt.y >= rec.top && pt.y <= rec.bottom)
{
loc = Location::Right;
return false;
}
else if (pt.y == rec.top && pt.x >= rec.left && pt.x <= rec.right)
{
loc = Location::Top;
return false;
}
else if (pt.y == rec.bottom && pt.x >= rec.left && pt.x <= rec.right)
{
loc = Location::Bottom;
return false;
}
else if (pt.x < rec.left) loc = Location::Left;
else if (pt.x > rec.right) loc = Location::Right;
else if (pt.y < rec.top) loc = Location::Top;
else if (pt.y > rec.bottom) loc = Location::Bottom;
else loc = Location::Inside;
return true;
}
Point64 GetIntersectPoint64(const Point64& ln1a, const Point64& ln1b,
const Point64& ln2a, const Point64& ln2b)
{
// see http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/
if (ln1b.x == ln1a.x)
{
if (ln2b.x == ln2a.x) return Point64(); // parallel lines
double m2 = static_cast<double>(ln2b.y - ln2a.y) / (ln2b.x - ln2a.x);
double b2 = ln2a.y - m2 * ln2a.x;
return Point64(ln1a.x, static_cast<int64_t>(std::round(m2 * ln1a.x + b2)));
}
else if (ln2b.x == ln2a.x)
{
double m1 = static_cast<double>(ln1b.y - ln1a.y) / (ln1b.x - ln1a.x);
double b1 = ln1a.y - m1 * ln1a.x;
return Point64(ln2a.x, static_cast<int64_t>(std::round(m1 * ln2a.x + b1)));
}
else
{
double m1 = static_cast<double>(ln1b.y - ln1a.y) / (ln1b.x - ln1a.x);
double b1 = ln1a.y - m1 * ln1a.x;
double m2 = static_cast<double>(ln2b.y - ln2a.y) / (ln2b.x - ln2a.x);
double b2 = ln2a.y - m2 * ln2a.x;
if (std::fabs(m1 - m2) > 1.0E-15)
{
double x = (b2 - b1) / (m1 - m2);
return Point64(x, m1 * x + b1);
}
else
return Point64((ln1a.x + ln1b.x) * 0.5, (ln1a.y + ln1b.y) * 0.5);
}
}
inline bool GetIntersection(const Path64& rectPath,
const Point64& p, const Point64& p2, Location& loc, Point64& ip)
{
// gets the intersection closest to 'p'
// when Result = false, loc will remain unchanged
switch (loc)
{
case Location::Left:
if (SegmentsIntersect(p, p2, rectPath[0], rectPath[3], true))
ip = GetIntersectPoint64(p, p2, rectPath[0], rectPath[3]);
else if (p.y < rectPath[0].y &&
SegmentsIntersect(p, p2, rectPath[0], rectPath[1], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[0], rectPath[1]);
loc = Location::Top;
}
else if (SegmentsIntersect(p, p2, rectPath[2], rectPath[3], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[2], rectPath[3]);
loc = Location::Bottom;
}
else return false;
break;
case Location::Top:
if (SegmentsIntersect(p, p2, rectPath[0], rectPath[1], true))
ip = GetIntersectPoint64(p, p2, rectPath[0], rectPath[1]);
else if (p.x < rectPath[0].x &&
SegmentsIntersect(p, p2, rectPath[0], rectPath[3], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[0], rectPath[3]);
loc = Location::Left;
}
else if (p.x > rectPath[1].x &&
SegmentsIntersect(p, p2, rectPath[1], rectPath[2], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[1], rectPath[2]);
loc = Location::Right;
}
else return false;
break;
case Location::Right:
if (SegmentsIntersect(p, p2, rectPath[1], rectPath[2], true))
ip = GetIntersectPoint64(p, p2, rectPath[1], rectPath[2]);
else if (p.y < rectPath[0].y &&
SegmentsIntersect(p, p2, rectPath[0], rectPath[1], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[0], rectPath[1]);
loc = Location::Top;
}
else if (SegmentsIntersect(p, p2, rectPath[2], rectPath[3], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[2], rectPath[3]);
loc = Location::Bottom;
}
else return false;
break;
case Location::Bottom:
if (SegmentsIntersect(p, p2, rectPath[2], rectPath[3], true))
ip = GetIntersectPoint64(p, p2, rectPath[2], rectPath[3]);
else if (p.x < rectPath[3].x &&
SegmentsIntersect(p, p2, rectPath[0], rectPath[3], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[0], rectPath[3]);
loc = Location::Left;
}
else if (p.x > rectPath[2].x &&
SegmentsIntersect(p, p2, rectPath[1], rectPath[2], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[1], rectPath[2]);
loc = Location::Right;
}
else return false;
break;
default: // loc == rInside
if (SegmentsIntersect(p, p2, rectPath[0], rectPath[3], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[0], rectPath[3]);
loc = Location::Left;
}
else if (SegmentsIntersect(p, p2, rectPath[0], rectPath[1], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[0], rectPath[1]);
loc = Location::Top;
}
else if (SegmentsIntersect(p, p2, rectPath[1], rectPath[2], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[1], rectPath[2]);
loc = Location::Right;
}
else if (SegmentsIntersect(p, p2, rectPath[2], rectPath[3], true))
{
ip = GetIntersectPoint64(p, p2, rectPath[2], rectPath[3]);
loc = Location::Bottom;
}
else return false;
break;
}
return true;
}
inline Location GetAdjacentLocation(Location loc, bool isClockwise)
{
int delta = (isClockwise) ? 1 : 3;
return static_cast<Location>((static_cast<int>(loc) + delta) % 4);
}
inline bool HeadingClockwise(Location prev, Location curr)
{
return (static_cast<int>(prev) + 1) % 4 == static_cast<int>(curr);
}
inline bool AreOpposites(Location prev, Location curr)
{
return abs(static_cast<int>(prev) - static_cast<int>(curr)) == 2;
}
inline bool IsClockwise(Location prev, Location curr,
Point64 prev_pt, Point64 curr_pt, Point64 rect_mp)
{
if (AreOpposites(prev, curr))
return CrossProduct(prev_pt, rect_mp, curr_pt) < 0;
else
return HeadingClockwise(prev, curr);
}
//----------------------------------------------------------------------------
// RectClip64
//----------------------------------------------------------------------------
void RectClip::AddCorner(Location prev, Location curr)
{
if (HeadingClockwise(prev, curr))
result_.push_back(rectPath_[static_cast<int>(prev)]);
else
result_.push_back(rectPath_[static_cast<int>(curr)]);
}
void RectClip::AddCorner(Location& loc, bool isClockwise)
{
if (isClockwise)
{
result_.push_back(rectPath_[static_cast<int>(loc)]);
loc = GetAdjacentLocation(loc, true);
}
else
{
loc = GetAdjacentLocation(loc, false);
result_.push_back(rectPath_[static_cast<int>(loc)]);
}
}
void RectClip::GetNextLocation(const Path64& path,
Location& loc, int& i, int highI)
{
switch (loc)
{
case Location::Left:
while (i <= highI && path[i].x <= rect_.left) ++i;
if (i > highI) break;
else if (path[i].x >= rect_.right) loc = Location::Right;
else if (path[i].y <= rect_.top) loc = Location::Top;
else if (path[i].y >= rect_.bottom) loc = Location::Bottom;
else loc = Location::Inside;
break;
case Location::Top:
while (i <= highI && path[i].y <= rect_.top) ++i;
if (i > highI) break;
else if (path[i].y >= rect_.bottom) loc = Location::Bottom;
else if (path[i].x <= rect_.left) loc = Location::Left;
else if (path[i].x >= rect_.right) loc = Location::Right;
else loc = Location::Inside;
break;
case Location::Right:
while (i <= highI && path[i].x >= rect_.right) ++i;
if (i > highI) break;
else if (path[i].x <= rect_.left) loc = Location::Left;
else if (path[i].y <= rect_.top) loc = Location::Top;
else if (path[i].y >= rect_.bottom) loc = Location::Bottom;
else loc = Location::Inside;
break;
case Location::Bottom:
while (i <= highI && path[i].y >= rect_.bottom) ++i;
if (i > highI) break;
else if (path[i].y <= rect_.top) loc = Location::Top;
else if (path[i].x <= rect_.left) loc = Location::Left;
else if (path[i].x >= rect_.right) loc = Location::Right;
else loc = Location::Inside;
break;
case Location::Inside:
while (i <= highI)
{
if (path[i].x < rect_.left) loc = Location::Left;
else if (path[i].x > rect_.right) loc = Location::Right;
else if (path[i].y > rect_.bottom) loc = Location::Bottom;
else if (path[i].y < rect_.top) loc = Location::Top;
else { result_.push_back(path[i]); ++i; continue; }
break; //inner loop
}
break;
} //switch
}
Path64 RectClip::Execute(const Path64& path)
{
if (rect_.IsEmpty() || path.size() < 3) return Path64();
result_.clear();
start_locs_.clear();
int i = 0, highI = static_cast<int>(path.size()) - 1;
Location prev = Location::Inside, loc;
Location crossing_loc = Location::Inside;
Location first_cross_ = Location::Inside;
if (!GetLocation(rect_, path[highI], loc))
{
i = highI - 1;
while (i >= 0 && !GetLocation(rect_, path[i], prev)) --i;
if (i < 0) return path;
if (prev == Location::Inside) loc = Location::Inside;
i = 0;
}
Location starting_loc = loc;
///////////////////////////////////////////////////
while (i <= highI)
{
prev = loc;
Location crossing_prev = crossing_loc;
GetNextLocation(path, loc, i, highI);
if (i > highI) break;
Point64 ip, ip2;
Point64 prev_pt = (i) ? path[static_cast<size_t>(i - 1)] : path[highI];
crossing_loc = loc;
if (!GetIntersection(rectPath_, path[i], prev_pt, crossing_loc, ip))
{
// ie remaining outside
if (crossing_prev == Location::Inside)
{
bool isClockw = IsClockwise(prev, loc, prev_pt, path[i], mp_);
do {
start_locs_.push_back(prev);
prev = GetAdjacentLocation(prev, isClockw);
} while (prev != loc);
crossing_loc = crossing_prev; // still not crossed
}
else if (prev != Location::Inside && prev != loc)
{
bool isClockw = IsClockwise(prev, loc, prev_pt, path[i], mp_);
do {
AddCorner(prev, isClockw);
} while (prev != loc);
}
++i;
continue;
}
////////////////////////////////////////////////////
// we must be crossing the rect boundary to get here
////////////////////////////////////////////////////
if (loc == Location::Inside) // path must be entering rect
{
if (first_cross_ == Location::Inside)
{
first_cross_ = crossing_loc;
start_locs_.push_back(prev);
}
else if (prev != crossing_loc)
{
bool isClockw = IsClockwise(prev, crossing_loc, prev_pt, path[i], mp_);
do {
AddCorner(prev, isClockw);
} while (prev != crossing_loc);
}
}
else if (prev != Location::Inside)
{
// passing right through rect. 'ip' here will be the second
// intersect pt but we'll also need the first intersect pt (ip2)
loc = prev;
GetIntersection(rectPath_, prev_pt, path[i], loc, ip2);
if (crossing_prev != Location::Inside)
AddCorner(crossing_prev, loc);
if (first_cross_ == Location::Inside)
{
first_cross_ = loc;
start_locs_.push_back(prev);
}
loc = crossing_loc;
result_.push_back(ip2);
if (ip == ip2)
{
// it's very likely that path[i] is on rect
GetLocation(rect_, path[i], loc);
AddCorner(crossing_loc, loc);
crossing_loc = loc;
continue;
}
}
else // path must be exiting rect
{
loc = crossing_loc;
if (first_cross_ == Location::Inside)
first_cross_ = crossing_loc;
}
result_.push_back(ip);
} //while i <= highI
///////////////////////////////////////////////////
if (first_cross_ == Location::Inside)
{
if (starting_loc == Location::Inside) return path;
Rect64 tmp_rect = Bounds(path);
if (tmp_rect.Contains(rect_) &&
Path1ContainsPath2(path, rectPath_) !=
PointInPolygonResult::IsOutside) return rectPath_;
else
return Path64();
}
if (loc != Location::Inside &&
(loc != first_cross_ || start_locs_.size() > 2))
{
if (start_locs_.size() > 0)
{
prev = loc;
for (auto loc2 : start_locs_)
{
if (prev == loc2) continue;
AddCorner(prev, HeadingClockwise(prev, loc2));
prev = loc2;
}
loc = prev;
}
if (loc != first_cross_)
AddCorner(loc, HeadingClockwise(loc, first_cross_));
}
if (result_.size() < 3) return Path64();
// tidy up duplicates and collinear segments
Path64 res;
res.reserve(result_.size());
size_t k = 0; highI = static_cast<int>(result_.size()) - 1;
Point64 prev_pt = result_[highI];
res.push_back(result_[0]);
Path64::const_iterator cit;
for (cit = result_.cbegin() + 1; cit != result_.cend(); ++cit)
{
if (CrossProduct(prev_pt, res[k], *cit))
{
prev_pt = res[k++];
res.push_back(*cit);
}
else
res[k] = *cit;
}
if (k < 2) return Path64();
// and a final check for collinearity
else if (!CrossProduct(res[0], res[k - 1], res[k])) res.pop_back();
return res;
}
Paths64 RectClipLines::Execute(const Path64& path)
{
result_.clear();
Paths64 result;
if (rect_.IsEmpty() || path.size() == 0) return result;
int i = 1, highI = static_cast<int>(path.size()) - 1;
Location prev = Location::Inside, loc;
Location crossing_loc = Location::Inside;
if (!GetLocation(rect_, path[0], loc))
{
while (i <= highI && !GetLocation(rect_, path[i], prev)) ++i;
if (i > highI) {
result.push_back(path);
return result;
}
if (prev == Location::Inside) loc = Location::Inside;
i = 1;
}
if (loc == Location::Inside) result_.push_back(path[0]);
///////////////////////////////////////////////////
while (i <= highI)
{
prev = loc;
GetNextLocation(path, loc, i, highI);
if (i > highI) break;
Point64 ip, ip2;
Point64 prev_pt = path[static_cast<size_t>(i - 1)];
crossing_loc = loc;
if (!GetIntersection(rectPath_, path[i], prev_pt, crossing_loc, ip))
{
// ie remaining outside
++i;
continue;
}
////////////////////////////////////////////////////
// we must be crossing the rect boundary to get here
////////////////////////////////////////////////////
if (loc == Location::Inside) // path must be entering rect
{
result_.push_back(ip);
}
else if (prev != Location::Inside)
{
// passing right through rect. 'ip' here will be the second
// intersect pt but we'll also need the first intersect pt (ip2)
crossing_loc = prev;
GetIntersection(rectPath_, prev_pt, path[i], crossing_loc, ip2);
result_.push_back(ip2);
result_.push_back(ip);
result.push_back(result_);
result_.clear();
}
else // path must be exiting rect
{
result_.push_back(ip);
result.push_back(result_);
result_.clear();
}
} //while i <= highI
///////////////////////////////////////////////////
if (result_.size() > 1)
result.push_back(result_);
return result;
}
} // namespace

View file

@ -14,3 +14,7 @@ add_library(imgui STATIC
imgui_draw.cpp
imgui_widgets.cpp
)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()

View file

@ -139,16 +139,21 @@ namespace ImGui
const wchar_t EjectHoverButton = 0x13;
const wchar_t CancelButton = 0x14;
const wchar_t CancelHoverButton = 0x15;
const wchar_t CloseNotifDarkButton = 0x16;
const wchar_t CloseNotifHoverDarkButton = 0x17;
// const wchar_t VarLayerHeightMarker = 0x16;
const wchar_t RightArrowButton = 0x18;
const wchar_t RightArrowHoverButton = 0x19;
const wchar_t PreferencesButton = 0x1A;
const wchar_t PreferencesHoverButton = 0x1B;
const wchar_t DocumentationDarkButton = 0x1C;
const wchar_t DocumentationHoverDarkButton = 0x1D;
// const wchar_t SinkingObjectMarker = 0x1C;
// const wchar_t CustomSupportsMarker = 0x1D;
// const wchar_t CustomSeamMarker = 0x1E;
// const wchar_t MmuSegmentationMarker = 0x1F;
// Do not forget use following letters only in wstring
//BBS use 08xx to avoid unicode character which may be used
const wchar_t DocumentationButton = 0x0800;
@ -167,6 +172,20 @@ namespace ImGui
const wchar_t SphereButtonIcon = 0x0816;
const wchar_t GapFillIcon = 0x0817;
const wchar_t MinimalizeDarkButton = 0x081C;
const wchar_t MinimalizeHoverDarkButton = 0x081D;
const wchar_t RightArrowDarkButton = 0x081E;
const wchar_t RightArrowHoverDarkButton = 0x081F;
const wchar_t PreferencesDarkButton = 0x0820;
const wchar_t PreferencesHoverDarkButton = 0x0821;
const wchar_t CircleButtonDarkIcon = 0x0822;
const wchar_t TriangleButtonDarkIcon = 0x0823;
const wchar_t FillButtonDarkIcon = 0x0824;
const wchar_t HeightRangeDarkIcon = 0x0825;
const wchar_t SphereButtonDarkIcon = 0x0826;
const wchar_t GapFillDarkIcon = 0x0827;
// void MyFunction(const char* name, const MyMatrix44& v);
}

View file

@ -620,6 +620,7 @@ namespace ImGui
// - A selectable highlights when hovered, and can display another color when selected.
// - Neighbors selectable extend their highlight bounds in order to leave no gap between them. This is so a series of selected Selectable appear contiguous.
IMGUI_API bool Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0, 0)); // "bool selected" carry the selection state (read-only). Selectable() is clicked is returns true so you can modify your selection state. size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height
IMGUI_API bool BBLImageSelectable(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& font_size, int font_line, const ImVec4& tint_col, const ImVec2& uv0, const ImVec2& uv1, bool selected = false);
IMGUI_API bool BBLSelectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0, 0)); // "bool selected" carry the selection state (read-only). Selectable() is clicked is returns true so you can modify your selection state. size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height
IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0, 0)); // "bool* p_selected" point to the selection state (read-write), as a convenient helper.
@ -659,7 +660,7 @@ namespace ImGui
IMGUI_API void EndMainMenuBar(); // only call EndMainMenuBar() if BeginMainMenuBar() returns true!
IMGUI_API bool BeginMenu(const char* label, bool enabled = true); // create a sub-menu entry. only call EndMenu() if this returns true!
IMGUI_API void EndMenu(); // only call EndMenu() if BeginMenu() returns true!
IMGUI_API bool BBLMenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated.
IMGUI_API bool BBLMenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true, float size_arg_y = 0.0f); // return true when activated.
IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated.
IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL
@ -2648,6 +2649,8 @@ struct ImFontAtlas
// NB: Make sure that your string are UTF-8 and NOT in your local code page. In C++11, you can create UTF-8 string literal using the u8"Hello world" syntax. See FAQ for details.
// NB: Consider using ImFontGlyphRangesBuilder to build glyph ranges from textual data.
IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
IMGUI_API const ImWchar* GetGlyphRangesBasic(); // Basic
IMGUI_API const ImWchar* GetGlyphRangesEnglish(); // Basic Latin + Latin Supplement
IMGUI_API const ImWchar* GetGlyphRangesKorean(); // Default + Korean characters
IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 2999 Ideographs
IMGUI_API const ImWchar* GetGlyphRangesChineseFull(); // Default + Half-Width + Japanese Hiragana/Katakana + full set of about 21000 CJK Unified Ideographs
@ -2655,6 +2658,7 @@ struct ImFontAtlas
IMGUI_API const ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters
IMGUI_API const ImWchar* GetGlyphRangesThai(); // Default + Thai characters
IMGUI_API const ImWchar* GetGlyphRangesVietnamese(); // Default + Vietnamese characters
IMGUI_API const ImWchar* GetGlyphRangesOthers();
//-------------------------------------------
// [BETA] Custom Rectangles/Glyphs API

View file

@ -53,6 +53,7 @@ Index of this file:
#include <stdlib.h> // alloca
#endif
#endif
#include <boost/log/trivial.hpp>
// Visual Studio warnings
#ifdef _MSC_VER
@ -2345,7 +2346,6 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
dst_tmp_array.resize(atlas->Fonts.Size);
memset(src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
memset(dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());
// 1. Initialize font loading structure, check font data validity
for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
{
@ -2365,9 +2365,15 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
}
// Initialize helper structure for font loading and verify that the TTF/OTF data is correct
const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)cfg.FontData, cfg.FontNo);
if (font_offset < 0)
BOOST_LOG_TRIVIAL(info) << "font_name: " << cfg.Name << ", font_offset: " << font_offset << ", font_no: " << cfg.FontNo << ", font_data_tag:"
<< ((unsigned char*)cfg.FontData)[0] << ((unsigned char*)cfg.FontData)[1] << ((unsigned char*)cfg.FontData)[2] << ((unsigned char*)cfg.FontData)[3];
IM_ASSERT(font_offset >= 0 && "FontData is incorrect, or FontNo cannot be found.");
if (!stbtt_InitFont(&src_tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset))
if (!stbtt_InitFont(&src_tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset)) {
BOOST_LOG_TRIVIAL(info) << "stbtt_InitFont failed, font_name: " << cfg.Name << ", font_data_tag:"
<< ((unsigned char*)cfg.FontData)[0] << ((unsigned char*)cfg.FontData)[1] << ((unsigned char*)cfg.FontData)[2] << ((unsigned char*)cfg.FontData)[3];;
return false;
}
// Measure highest codepoints
ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
@ -2806,12 +2812,49 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
}
}
const ImWchar* ImFontAtlas::GetGlyphRangesBasic()
{
static const ImWchar ranges[] =
{
0x0041, 0x005A, // A-Z
0x0061, 0x007A, // a-z
0x0020, 0x0021,
0,
};
return &ranges[0];
}
const ImWchar* ImFontAtlas::GetGlyphRangesEnglish()
{
static const ImWchar ranges[] =
{
0x0020, 0x00FF, // Basic Latin + Latin Supplement
0,
};
return &ranges[0];
}
// Retrieve list of range (2 int per range, values are inclusive)
const ImWchar* ImFontAtlas::GetGlyphRangesOthers()
{
static const ImWchar ranges[] =
{
0x0020, 0x00FF, // Basic Latin + Latin Supplement
0x0100, 0x017F, // Latin Extended-A
0x0180, 0x024F, // Latin Extended-B
0x2000, 0x206F, // General Punctuation
0xFF00, 0xFFEF, // Half-width characters
0,
};
return &ranges[0];
}
// Retrieve list of range (2 int per range, values are inclusive)
const ImWchar* ImFontAtlas::GetGlyphRangesDefault()
{
static const ImWchar ranges[] =
{
0x0020, 0x01FF, // Basic Latin + Latin Supplement
0x0020, 0x00FF, // Basic Latin + Latin Supplement
0x2000, 0x206F, // General Punctuation
0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
0x31F0, 0x31FF, // Katakana Phonetic Extensions
@ -2862,8 +2905,7 @@ static void UnpackAccumulativeOffsetsIntoRanges(int base_codepoint, const short*
//-------------------------------------------------------------------------
// [SECTION] ImFontAtlas glyph ranges helpers
//-------------------------------------------------------------------------
const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon()
const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon() // used in bold_font only
{
// Store 2500 regularly used characters for Simplified Chinese.
// Sourced from https://zh.wiktionary.org/wiki/%E9%99%84%E5%BD%95:%E7%8E%B0%E4%BB%A3%E6%B1%89%E8%AF%AD%E5%B8%B8%E7%94%A8%E5%AD%97%E8%A1%A8
@ -2919,14 +2961,15 @@ const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon()
0x2000, 0x206F, // General Punctuation
0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
0x31F0, 0x31FF, // Katakana Phonetic Extensions
0x4e00, 0x9FAF, // CJK Ideograms
0xFF00, 0xFFEF // Half-width characters
0xFF00, 0xFFEF, // Half-width characters
0X5C4F, 0X5C50,
0x2103, 0x2104,
};
static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00) * 2 + 1] = { 0 };
if (!full_ranges[0])
{
memcpy(full_ranges, base_ranges, sizeof(base_ranges));
//UnpackAccumulativeOffsetsIntoRanges(0x4E00, accumulative_offsets_from_0x4E00, IM_ARRAYSIZE(accumulative_offsets_from_0x4E00), full_ranges + IM_ARRAYSIZE(base_ranges));
UnpackAccumulativeOffsetsIntoRanges(0x4E00, accumulative_offsets_from_0x4E00, IM_ARRAYSIZE(accumulative_offsets_from_0x4E00), full_ranges + IM_ARRAYSIZE(base_ranges));
}
return &full_ranges[0];
}

View file

@ -7064,6 +7064,161 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
return pressed;
}
bool ImGui::BBLImageSelectable(ImTextureID user_texture_id, const ImVec2& size_arg, const ImVec2& font_size, int font_line, const ImVec4& tint_col, const ImVec2& uv0, const ImVec2& uv1, bool selected)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems) return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
PushID((void*)(intptr_t)user_texture_id);
const ImGuiID id = window->GetID("#BBLImageSelectable");
PopID();
ImGuiSelectableFlags flags = 0;
// Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle.
ImVec2 size(size_arg.x != 0.0f ? size_arg.x : 0.0f, size_arg.y != 0.0f ? size_arg.y : 0.0f);
ImVec2 pos = window->DC.CursorPos;
pos.y += window->DC.CurrLineTextBaseOffset;
ItemSize(size, 0.0f);
// Fill horizontal space
// We don't support (size < 0.0f) in Selectable() because the ItemSpacing extension would make explicitly right-aligned sizes not visibly match other widgets.
const bool span_all_columns = (flags & ImGuiSelectableFlags_SpanAllColumns) != 0;
const float min_x = span_all_columns ? window->ParentWorkRect.Min.x : pos.x;
const float max_x = span_all_columns ? window->ParentWorkRect.Max.x : window->WorkRect.Max.x;
if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_SpanAvailWidth)) size.x = ImMax(0.0f, max_x - min_x);
// Text stays at the submission position, but bounding box may be extended on both sides
const float arrow_size = (flags & ImGuiComboFlags_NoArrowButton) ? 0.0f : GetFrameHeight();
const ImVec2 text_min = ImVec2(pos.x + arrow_size, pos.y);
const ImVec2 text_max(min_x + size.x, pos.y + size.y);
// Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable.
ImRect bb(min_x, pos.y, text_max.x, text_max.y);
if ((flags & ImGuiSelectableFlags_NoPadWithHalfSpacing) == 0) {
const float spacing_x = span_all_columns ? 0.0f : style.ItemSpacing.x;
const float spacing_y = style.ItemSpacing.y;
const float spacing_L = IM_FLOOR(spacing_x * 0.50f);
const float spacing_U = IM_FLOOR(spacing_y * 0.50f);
bb.Min.x -= spacing_L;
bb.Min.y -= spacing_U;
bb.Max.x += (spacing_x - spacing_L);
bb.Max.y += (spacing_y - spacing_U);
}
// if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(0, 255, 0, 255)); }
// Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackground for every Selectable..
const float backup_clip_rect_min_x = window->ClipRect.Min.x;
const float backup_clip_rect_max_x = window->ClipRect.Max.x;
if (span_all_columns) {
window->ClipRect.Min.x = window->ParentWorkRect.Min.x;
window->ClipRect.Max.x = window->ParentWorkRect.Max.x;
}
bool item_add;
if (flags & ImGuiSelectableFlags_Disabled) {
ImGuiItemFlags backup_item_flags = g.CurrentItemFlags;
g.CurrentItemFlags |= ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNavDefaultFocus;
item_add = ItemAdd(bb, id);
g.CurrentItemFlags = backup_item_flags;
}
else {
item_add = ItemAdd(bb, id);
}
if (span_all_columns) {
window->ClipRect.Min.x = backup_clip_rect_min_x;
window->ClipRect.Max.x = backup_clip_rect_max_x;
}
if (!item_add) return false;
// FIXME: We can standardize the behavior of those two, we could also keep the fast path of override ClipRect + full push on render only,
// which would be advantageous since most selectable are not selected.
if (span_all_columns && window->DC.CurrentColumns)
PushColumnsBackground();
else if (span_all_columns && g.CurrentTable)
TablePushBackgroundChannel();
// We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries
ImGuiButtonFlags button_flags = 0;
if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveId; }
if (flags & ImGuiSelectableFlags_SelectOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; }
if (flags & ImGuiSelectableFlags_SelectOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; }
if (flags & ImGuiSelectableFlags_Disabled) { button_flags |= ImGuiButtonFlags_Disabled; }
if (flags & ImGuiSelectableFlags_AllowDoubleClick) { button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; }
if (flags & ImGuiSelectableFlags_AllowItemOverlap) { button_flags |= ImGuiButtonFlags_AllowItemOverlap; }
if (flags & ImGuiSelectableFlags_Disabled) selected = false;
const bool was_selected = selected;
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags);
if (hovered || g.ActiveId == id) {
ImGui::PushStyleColor(ImGuiCol_Border, GetColorU32(ImGuiCol_BorderActive));
if (arrow_size == 0) {
RenderFrameBorder(bb.Min, ImVec2(bb.Max.x - style.WindowPadding.x, bb.Max.y), style.FrameRounding);
}
else {
RenderFrameBorder(ImVec2(bb.Min.x + style.WindowPadding.x, bb.Min.y), ImVec2(bb.Max.x - style.WindowPadding.x, bb.Max.y), style.FrameRounding);
}
ImGui::PopStyleColor(1);
}
// Update NavId when clicking or when Hovering (this doesn't happen on most widgets), so navigation can be resumed with gamepad/keyboard
if (pressed || (hovered && (flags & ImGuiSelectableFlags_SetNavIdOnHover))) {
if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent) {
SetNavID(id, window->DC.NavLayerCurrent, window->DC.NavFocusScopeIdCurrent, ImRect(bb.Min - window->Pos, bb.Max - window->Pos));
g.NavDisableHighlight = true;
}
}
if (pressed) MarkItemEdited(id);
if (flags & ImGuiSelectableFlags_AllowItemOverlap) SetItemAllowOverlap();
// In this branch, Selectable() cannot toggle the selection so this will never trigger.
if (selected != was_selected) //-V547
window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_ToggledSelection;
// Render
if (held && (flags & ImGuiSelectableFlags_DrawHoveredWhenHeld)) hovered = true;
if (hovered || selected) {
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
if (arrow_size == 0) {
RenderFrame(bb.Min, ImVec2(bb.Max.x - style.WindowPadding.x, bb.Max.y), col, false, 0.0f);
}
else {
RenderFrame(ImVec2(bb.Min.x + style.WindowPadding.x, bb.Min.y), ImVec2(bb.Max.x - style.WindowPadding.x, bb.Max.y), col, false, 0.0f);
}
RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding);
}
if (span_all_columns && window->DC.CurrentColumns)
PopColumnsBackground();
else if (span_all_columns && g.CurrentTable)
TablePopBackgroundChannel();
if (flags & ImGuiSelectableFlags_Disabled) PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]);
// Render
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
ImVec2 p_min = bb.Min + ImVec2(2 * style.ItemSpacing.x, (bb.Max.y - bb.Min.y - font_size.y) / 2);
ImVec2 p_max = p_min + font_size;
window->DrawList->AddImage(user_texture_id, p_min, p_max, uv0, uv1, GetColorU32(tint_col));
if (flags & ImGuiSelectableFlags_Disabled) PopStyleColor();
// Automatically close popups
if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(g.CurrentItemFlags & ImGuiItemFlags_SelectableDontClosePopup))
CloseCurrentPopup();
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
return pressed;
}
bool ImGui::BBLSelectable(const char *label, bool selected, ImGuiSelectableFlags flags, const ImVec2 &size_arg)
{
ImGuiWindow *window = GetCurrentWindow();
@ -7917,7 +8072,7 @@ void ImGui::EndMenu()
EndPopup();
}
bool ImGui::BBLMenuItem(const char* label, const char* shortcut, bool selected, bool enabled)
bool ImGui::BBLMenuItem(const char* label, const char* shortcut, bool selected, bool enabled, float size_arg_y)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
@ -7939,7 +8094,7 @@ bool ImGui::BBLMenuItem(const char* label, const char* shortcut, bool selected,
float w = label_size.x;
window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * 0.5f);
PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y));
pressed = BBLSelectable(label, selected, flags, ImVec2(w, 0.0f));
pressed = BBLSelectable(label, selected, flags, ImVec2(w, size_arg_y));
PopStyleVar();
window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar().
}
@ -7951,7 +8106,7 @@ bool ImGui::BBLMenuItem(const char* label, const char* shortcut, bool selected,
float shortcut_w = shortcut ? CalcTextSize(shortcut, NULL).x : 0.0f;
float min_w = window->DC.MenuColumns.DeclColumns(label_size.x, shortcut_w, IM_FLOOR(g.FontSize * 1.20f)); // Feedback for next frame
float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w);
pressed = BBLSelectable(label, false, flags | ImGuiSelectableFlags_SpanAvailWidth | ImGuiComboFlags_NoArrowButton, ImVec2(min_w, 0.0f));
pressed = BBLSelectable(label, false, flags | ImGuiSelectableFlags_SpanAvailWidth | ImGuiComboFlags_NoArrowButton, ImVec2(min_w, size_arg_y));
if (shortcut_w > 0.0f)
{
PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);

View file

@ -1311,11 +1311,11 @@ static int stbtt_GetFontOffsetForIndex_internal(unsigned char *font_collection,
if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) {
stbtt_int32 n = ttLONG(font_collection+8);
if (index >= n)
return -1;
return -2;
return ttULONG(font_collection+12+index*4);
}
}
return -1;
return -3;
}
static int stbtt_GetNumberOfFonts_internal(unsigned char *font_collection)
@ -1365,19 +1365,28 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
info->kern = stbtt__find_table(data, fontstart, "kern"); // not required
info->gpos = stbtt__find_table(data, fontstart, "GPOS"); // not required
if (!cmap || !info->head || !info->hhea || !info->hmtx)
if (!cmap || !info->head || !info->hhea || !info->hmtx) {
BOOST_LOG_TRIVIAL(info) << "Cannot find cmap/head/hhea/hmtx table";
return 0;
}
if (info->glyf) {
// required for truetype
if (!info->loca) return 0;
if (!info->loca) {
BOOST_LOG_TRIVIAL(info) << "Cannot find loca table";
return 0;
}
} else {
// initialization for CFF / Type2 fonts (OTF)
BOOST_LOG_TRIVIAL(info) << "initialization for CFF / Type2 fonts (OTF)";
stbtt__buf b, topdict, topdictidx;
stbtt_uint32 cstype = 2, charstrings = 0, fdarrayoff = 0, fdselectoff = 0;
stbtt_uint32 cff;
cff = stbtt__find_table(data, fontstart, "CFF ");
if (!cff) return 0;
if (!cff) {
BOOST_LOG_TRIVIAL(info) << "Cannot find cff table";
return 0;
}
info->fontdicts = stbtt__new_buf(NULL, 0);
info->fdselect = stbtt__new_buf(NULL, 0);

View file

@ -261,6 +261,8 @@ inline TMultiShape<PolygonImpl> merge(const TMultiShape<PolygonImpl>& shapes)
return Slic3r::union_ex(shapes);
}
inline TMultiShape<PolygonImpl> subtract(const TMultiShape<PolygonImpl> &outerBinNfp, const TMultiShape<PolygonImpl> &shapes) { return Slic3r::diff_ex(outerBinNfp, shapes); }
} // namespace nfp
} // namespace libnest2d

View file

@ -179,6 +179,42 @@ inline TPoint<RawShape> referenceVertex(const RawShape& sh)
return rightmostUpVertex(sh);
}
template<class RawBox, class RawShape, class Ratio = double> inline NfpResult<RawShape> nfpInnerRectBed(const RawBox &bed, const RawShape &other)
{
using Vertex = TPoint<RawShape>;
using Edge = _Segment<Vertex>;
namespace sl = shapelike;
auto sbox = sl::boundingBox(other);
auto sheight = sbox.height();
auto swidth = sbox.width();
Vertex slidingTop = rightmostUpVertex(other);
auto leftOffset = slidingTop.x() - sbox.minCorner().x();
auto rightOffset = slidingTop.x() - sbox.maxCorner().x();
auto topOffset = 0;
auto bottomOffset = sheight;
auto boxWidth = bed.width();
auto boxHeight = bed.height();
auto bedMinx = bed.minCorner().x();
auto bedMiny = bed.minCorner().y();
auto bedMaxx = bed.maxCorner().x();
auto bedMaxy = bed.maxCorner().y();
RawShape innerNfp{{bedMinx + leftOffset, bedMaxy + topOffset},
{bedMaxx + rightOffset, bedMaxy + topOffset},
{bedMaxx + rightOffset, bedMiny + bottomOffset},
{bedMinx + leftOffset, bedMiny + bottomOffset},
{bedMinx + leftOffset, bedMaxy + topOffset}};
if (sheight > boxHeight || swidth > boxWidth) {
return {{}, {0, 0}};
} else {
return {innerNfp, {0, 0}};
}
}
/**
* The "trivial" Cuninghame-Green implementation of NFP for convex polygons.
*

View file

@ -481,7 +481,7 @@ public:
auto d = bbin.center() - bb.center();
_Rectangle<RawShape> rect(bb.width(), bb.height());
rect.translate(bb.minCorner() + d);
return sl::isInside(rect.transformedShape(), bin) ? -1.0 : 1;
return sl::isInside(rect.transformedShape(), bin) ? -1.5 : 1;
}
static inline double overfit(const RawShape& chull, const RawShape& bin) {
@ -565,7 +565,7 @@ private:
using Shapes = TMultiShape<RawShape>;
Shapes calcnfp(const Item &trsh, Lvl<nfp::NfpLevel::CONVEX_ONLY>)
Shapes calcnfp(const Item &trsh, const Box& bed ,Lvl<nfp::NfpLevel::CONVEX_ONLY>)
{
using namespace nfp;
@ -598,7 +598,8 @@ private:
nfps[n] = subnfp_r.first;
});
return nfp::merge(nfps);
RawShape innerNfp = nfpInnerRectBed(bed, trsh.transformedShape()).first;
return nfp::subtract({innerNfp}, nfps);
}
@ -738,7 +739,7 @@ private:
// it is disjunct from the current merged pile
placeOutsideOfBin(item);
nfps = calcnfp(item, Lvl<MaxNfpLevel::value>());
nfps = calcnfp(item, binbb, Lvl<MaxNfpLevel::value>());
auto iv = item.referenceVertex();
@ -907,7 +908,7 @@ private:
}
}
if( best_score < global_score && best_score< LARGE_COST_TO_REJECT) {
if( best_score < global_score) {
auto d = (getNfpPoint(optimum) - iv) + startpos;
final_tr = d;
final_rot = initial_rot + rot;
@ -922,7 +923,10 @@ private:
#ifdef SVGTOOLS_HPP
svg::SVGWriter<RawShape> svgwriter;
svgwriter.setSize(binbb);
Box binbb2(binbb.width() * 2, binbb.height() * 2, binbb.center()); // expand bbox to allow object be drawed outside
svgwriter.setSize(binbb2);
svgwriter.conf_.x0 = binbb.width();
svgwriter.conf_.y0 = -binbb.height()/2; // origin is top left corner
svgwriter.writeShape(box2RawShape(binbb), "none", "black");
for (int i = 0; i < nfps.size(); i++)
svgwriter.writeShape(nfps[i], "none", "blue");
@ -1031,51 +1035,50 @@ private:
if (!item.is_virt_object)
bb = sl::boundingBox(item.boundingBox(), bb);
// BBS TODO assume the nonprefered regions are at the bottom left corner
Box bin_reduced = bbin;
for (const auto& region : config_.m_nonprefered_regions)
{
Box bb1 = region.boundingBox();
if (bb1.maxCorner().y()<bbin.height()/5 &&
bbin.height() - bb1.maxCorner().y() > bb.height() && bb.height()>bbin.height()-2*bb1.maxCorner().y()) {
// could use a tighter bound by moving bed center higher
bin_reduced.minCorner().y() = bb1.maxCorner().y();
continue;
}
if (bb1.maxCorner().x()<bbin.width()/5 &&
bbin.width() - bb1.maxCorner().x() > bb.width() && bb.width()>bbin.width()-2*bb1.maxCorner().x()) {
// could use a tighter bound
bin_reduced.minCorner().x() = bb1.maxCorner().x();
continue;
// if move to center is infeasible, move to topright corner instead
auto alignment = config_.alignment;
if (!config_.m_excluded_regions.empty() && alignment== Config::Alignment::CENTER) {
Box bb2 = bb;
auto d = bbin.center() - bb2.center();
d.x() = std::max(d.x(), 0);
d.y() = std::max(d.y(), 0);
bb2.minCorner() += d;
bb2.maxCorner() += d;
for (auto& region : config_.m_excluded_regions) {
auto region_bb = region.boundingBox();
if (bb2.intersection(region_bb).area()>0) {
alignment = Config::Alignment::TOP_RIGHT;
break;
}
}
}
Vertex ci, cb;
switch(config_.alignment) {
switch(alignment) {
case Config::Alignment::CENTER: {
ci = bb.center();
cb = bin_reduced.center();
cb = bbin.center();
break;
}
case Config::Alignment::BOTTOM_LEFT: {
ci = bb.minCorner();
cb = bin_reduced.minCorner();
cb = bbin.minCorner();
break;
}
case Config::Alignment::BOTTOM_RIGHT: {
ci = {getX(bb.maxCorner()), getY(bb.minCorner())};
cb = {getX(bin_reduced.maxCorner()), getY(bin_reduced.minCorner())};
cb = {getX(bbin.maxCorner()), getY(bbin.minCorner())};
break;
}
case Config::Alignment::TOP_LEFT: {
ci = {getX(bb.minCorner()), getY(bb.maxCorner())};
cb = {getX(bin_reduced.minCorner()), getY(bin_reduced.maxCorner())};
cb = {getX(bbin.minCorner()), getY(bbin.maxCorner())};
break;
}
case Config::Alignment::TOP_RIGHT: {
ci = bb.maxCorner();
cb = bin_reduced.maxCorner();
cb = bbin.maxCorner();
break;
}
default: ; // DONT_ALIGN

View file

@ -43,7 +43,7 @@ public:
public:
operator bool() { return item_ptr_ != nullptr; }
double overfit() const { return overfit_; }
double score_ = -1;
double score_ = -1.11;
double score() { return score_; }
int plate_id = 0; // BBS
};

View file

@ -35,8 +35,9 @@ public:
};
private:
Config conf_;
private:
std::vector<std::string> svg_layers_;
bool finished_ = false;
public:

View file

@ -185,13 +185,13 @@ void AppConfig::set_defaults()
#ifdef SUPPORT_DARK_MODE
if (get("dark_color_mode").empty())
set_bool("dark_color_mode", false);
set("dark_color_mode", "0");
#endif
#ifdef SUPPORT_SYS_MENU
//#ifdef SUPPORT_SYS_MENU
if (get("sys_menu_enabled").empty())
set_bool("sys_menu_enabled", true);
#endif
set("sys_menu_enabled", "1");
//#endif
#endif // _WIN32
// BBS
@ -288,9 +288,9 @@ void AppConfig::set_defaults()
if (get("backup_interval").empty()) {
set("backup_interval", "10");
}
if (get("curr_bed_type").empty()) {
set("curr_bed_type", "0");
set("curr_bed_type", "1");
}
// #if BBL_RELEASE_TO_PUBLIC
@ -458,7 +458,6 @@ std::string AppConfig::load()
} else if (it.key() == "presets") {
for (auto iter = it.value().begin(); iter != it.value().end(); iter++) {
if (iter.key() == "filaments") {
// BBS: filament presets is now considered as project config instead of app config
int idx = 0;
for(auto& element: iter.value()) {
if (idx == 0)
@ -480,7 +479,14 @@ std::string AppConfig::load()
} else {
m_storage[it.key()][iter.key()] = "false";
}
} else {
} else if (iter.key() == "filament_presets") {
m_filament_presets = iter.value().get<std::vector<std::string>>();
} else if (iter.key() == "filament_colors") {
m_filament_colors = iter.value().get<std::vector<std::string>>();
} else if (iter.key() == "flushing_volumes") {
m_flush_volumes_matrix = iter.value().get<std::vector<float>>();
}
else {
if (iter.value().is_string())
m_storage[it.key()][iter.key()] = iter.value().get<std::string>();
else {
@ -531,7 +537,7 @@ void AppConfig::save()
{
// Returns "undefined" if the thread naming functionality is not supported by the operating system.
std::optional<std::string> current_thread_name = get_current_thread_name();
if (current_thread_name && *current_thread_name != "bambustu_main") {
if (current_thread_name && *current_thread_name != "bambustu_main" && *current_thread_name != "main") {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<<", current_thread_name is " << *current_thread_name;
throw CriticalException("Calling AppConfig::save() from a worker thread, thread name: " + *current_thread_name);
}
@ -563,6 +569,18 @@ void AppConfig::save()
j["app"][kvp.first] = kvp.second;
}
for (const auto &filament_preset : m_filament_presets) {
j["app"]["filament_presets"].push_back(filament_preset);
}
for (const auto &filament_color : m_filament_colors) {
j["app"]["filament_colors"].push_back(filament_color);
}
for (double flushing_volume : m_flush_volumes_matrix) {
j["app"]["flushing_volumes"].push_back(flushing_volume);
}
// Write the other categories.
for (const auto& category : m_storage) {
if (category.first.empty())
@ -577,7 +595,7 @@ void AppConfig::save()
} else if (category.first == "presets") {
json j_filament_array;
for(const auto& kvp : category.second) {
if (boost::starts_with(kvp.first, "filament")) {
if (boost::starts_with(kvp.first, "filament") && kvp.first != "filament_colors") {
j_filament_array.push_back(kvp.second);
} else {
j[category.first][kvp.first] = kvp.second;
@ -930,7 +948,9 @@ void AppConfig::set_recent_projects(const std::vector<std::string>& recent_proje
it->second.clear();
for (unsigned int i = 0; i < (unsigned int)recent_projects.size(); ++i)
{
it->second[std::to_string(i + 1)] = recent_projects[i];
auto n = std::to_string(i + 1);
if (n.length() == 1) n = "0" + n;
it->second[n] = recent_projects[i];
}
}

View file

@ -17,6 +17,9 @@ using namespace nlohmann;
#define ENV_PRE_HOST "2"
#define ENV_PRODUCT_HOST "3"
#define SUPPORT_DARK_MODE
//#define _MSW_DARK_MODE
namespace Slic3r {
@ -164,6 +167,22 @@ public:
void set_vendors(VendorMap &&vendors) { m_vendors = std::move(vendors); m_dirty = true; }
const VendorMap& vendors() const { return m_vendors; }
const std::vector<std::string> &get_filament_presets() const { return m_filament_presets; }
void set_filament_presets(const std::vector<std::string> &filament_presets){
m_filament_presets = filament_presets;
m_dirty = true;
}
const std::vector<std::string> &get_filament_colors() const { return m_filament_colors; }
void set_filament_colors(const std::vector<std::string> &filament_colors){
m_filament_colors = filament_colors;
m_dirty = true;
}
const std::vector<float> &get_flush_volumes_matrix() const { return m_flush_volumes_matrix; }
void set_flush_volumes_matrix(const std::vector<float> &flush_volumes_matrix){
m_flush_volumes_matrix = flush_volumes_matrix;
m_dirty = true;
}
// return recent/last_opened_folder or recent/settings_folder or empty string.
std::string get_last_dir() const;
void update_config_dir(const std::string &dir);
@ -259,6 +278,10 @@ private:
bool m_legacy_datadir;
std::string m_loading_path;
std::vector<std::string> m_filament_presets;
std::vector<std::string> m_filament_colors;
std::vector<float> m_flush_volumes_matrix;
};
} // namespace Slic3r

View file

@ -84,7 +84,7 @@ const double BIG_ITEM_TRESHOLD = 0.02;
template<class PConf>
void fill_config(PConf& pcfg, const ArrangeParams &params) {
if (params.is_seq_print) {
if (params.is_seq_print || params.excluded_regions.empty()==false) {
// Align the arranged pile into the center of the bin
pcfg.alignment = PConf::Alignment::CENTER;
// Start placing the items from the center of the print bed
@ -137,7 +137,7 @@ static double fixed_overfit(const std::tuple<double, Box>& result, const Box &bi
}
// useful for arranging big circle objects
static double fixed_overfit_topright_sliding(const std::tuple<double, Box>& result, const Box& binbb)
static double fixed_overfit_topright_sliding(const std::tuple<double, Box> &result, const Box &binbb, const std::vector<Box> &excluded_boxes)
{
double score = std::get<0>(result);
Box pilebb = std::get<1>(result);
@ -152,6 +152,12 @@ static double fixed_overfit_topright_sliding(const std::tuple<double, Box>& resu
auto diff = double(fullbb.area()) - binbb.area();
if (diff > 0) score += diff;
// excluded regions and nonprefered regions should not intersect the translated pilebb
for (auto &bb : excluded_boxes) {
auto area_ = pilebb.intersection(bb).area();
if (area_ > 0) score += area_;
}
return score;
}
@ -190,6 +196,7 @@ protected:
Box m_pilebb; // The bounding box of the merged pile.
ItemGroup m_remaining; // Remaining items
ItemGroup m_items; // allready packed items
std::vector<Box> m_excluded_and_extruCali_regions; // excluded and extrusion calib regions
size_t m_item_count = 0; // Number of all items to be packed
ArrangeParams params;
@ -202,14 +209,20 @@ protected:
// 1) Y distance of item corner to bed corner. Must be put above bed corner. (high weight)
// 2) X distance of item corner to bed corner (low weight)
// 3) item row occupancy (useful when rotation is enabled)
// 4需要允许往屏蔽区域的左边或下边去一点不然很多物体可能认为摆不进去实际上我们最后是可以做平移的
double dist_for_BOTTOM_LEFT(Box ibb, const ClipperLib::IntPoint& origin_pack)
{
double dist_corner_y = ibb.minCorner().y() - origin_pack.y();
double dist_corner_x = ibb.minCorner().x() - origin_pack.x();
if (dist_corner_y < 0 || dist_corner_x<0)
return LARGE_COST_TO_REJECT;
double bindist = norm(dist_corner_y + 1 * dist_corner_x
+ 1 * double(ibb.maxCorner().y() - ibb.minCorner().y())); // occupy as few rows as possible
// occupy as few rows as possible if we have rotations
double bindist = double(ibb.maxCorner().y() - ibb.minCorner().y());
if (dist_corner_x >= 0 && dist_corner_y >= 0)
bindist += dist_corner_y + 1 * dist_corner_x;
else {
if (dist_corner_x < 0) bindist += 10 * (-dist_corner_x);
if (dist_corner_y < 0) bindist += 10 * (-dist_corner_y);
}
bindist = norm(bindist);
return bindist;
}
@ -350,9 +363,10 @@ protected:
score = dist_for_BOTTOM_LEFT(ibb, origin_pack);
}
else {
score = 0.5 * norm(pl::distance(ibb.center(), origin_pack));
if (m_pilebb.defined)
score += 0.5 * norm(pl::distance(ibb.center(), m_pilebb.center()));
score = 0.5 * norm(pl::distance(ibb.center(), m_pilebb.center()));
else
score = 0.5 * norm(pl::distance(ibb.center(), origin_pack));
}
break;
}
@ -411,6 +425,7 @@ protected:
if (p.is_virt_object) continue;
score += lambda3 * (item.bed_temp - p.vitrify_temp > 0);
}
score += lambda3 * (item.bed_temp - item.vitrify_temp > 0);
score += lambda4 * hasRowHeightConflict + lambda4 * hasLidHeightConflict;
}
else {
@ -418,12 +433,20 @@ protected:
Item& p = m_items[i];
if (p.is_virt_object) {
// Better not put items above wipe tower
if (p.is_wipe_tower)
score += ibb.maxCorner().y() > p.boundingBox().maxCorner().y();
if (p.is_wipe_tower) {
if (ibb.maxCorner().y() > p.boundingBox().maxCorner().y())
score += 1;
else if(m_pilebb.defined)
score += norm(pl::distance(ibb.center(), m_pilebb.center()));
}
else
continue;
} else
} else {
// 高度接近的件尽量摆到一起
score += (1- std::abs(item.height - p.height) / params.printable_height)
* norm(pl::distance(ibb.center(), p.boundingBox().center()));
score += LARGE_COST_TO_REJECT * (item.bed_temp - p.bed_temp != 0);
}
}
}
@ -461,6 +484,14 @@ public:
m_norm = std::sqrt(m_bin_area);
fill_config(m_pconf, params);
this->params = params;
for (auto& region : m_pconf.m_excluded_regions) {
Box bb = region.boundingBox();
m_excluded_and_extruCali_regions.emplace_back(bb);
}
for (auto& region : m_pconf.m_nonprefered_regions) {
Box bb = region.boundingBox();
m_excluded_and_extruCali_regions.emplace_back(bb);
}
// Set up a callback that is called just before arranging starts
// This functionality is provided by the Nester class (m_pack).
@ -498,28 +529,19 @@ public:
m_pconf.object_function = get_objfn();
auto bbox2expoly = [](Box bb) {
ExPolygon bin_poly;
auto c0 = bb.minCorner();
auto c1 = bb.maxCorner();
bin_poly.contour.points.emplace_back(c0);
bin_poly.contour.points.emplace_back(c1.x(), c0.y());
bin_poly.contour.points.emplace_back(c1);
bin_poly.contour.points.emplace_back(c0.x(), c1.y());
return bin_poly;
};
// preload fixed items (and excluded regions) on plate
m_pconf.on_preload = [this](const ItemGroup &items, PConfig &cfg) {
if (items.empty()) return;
auto bb = sl::boundingBox(m_bin);
auto binbb = sl::boundingBox(m_bin);
// BBS: excluded region (virtual object but not wipe tower) should not affect final alignment
bool all_is_excluded_region = std::all_of(items.begin(), items.end(), [](Item &itm) { return itm.is_virt_object && !itm.is_wipe_tower; });
if (!all_is_excluded_region)
cfg.alignment = PConfig::Alignment::DONT_ALIGN;
else
cfg.alignment = PConfig::Alignment::CENTER;
auto starting_point = cfg.starting_point == PConfig::Alignment::BOTTOM_LEFT ? bb.minCorner() : bb.center();
auto starting_point = cfg.starting_point == PConfig::Alignment::BOTTOM_LEFT ? binbb.minCorner() : binbb.center();
// if we have wipe tower, items should be arranged around wipe tower
for (Item itm : items) {
if (itm.is_wipe_tower) {
@ -528,12 +550,16 @@ public:
}
}
cfg.object_function = [this, bb, starting_point](const Item& item, const ItemGroup& packed_items) {
bool packed_are_excluded_region = std::all_of(packed_items.begin(), packed_items.end(), [](Item& itm) { return itm.is_virt_object && !itm.is_wipe_tower; });
if(packed_are_excluded_region)
return fixed_overfit_topright_sliding(objfunc(item, starting_point), bb);
else
return fixed_overfit(objfunc(item, starting_point), bb);
cfg.object_function = [this, binbb, starting_point](const Item &item, const ItemGroup &packed_items) {
// 在我们的摆盘中,没有天然的固定对象。固定对象只有:屏蔽区域、挤出补偿区域、料塔。
// 对于屏蔽区域,摆入的对象仍然是可以向右上滑动的;
// 对挤出料塔,摆入的对象不能滑动(必须围绕料塔)
bool pack_around_wipe_tower = std::any_of(packed_items.begin(), packed_items.end(), [](Item& itm) { return itm.is_wipe_tower; });
//if(pack_around_wipe_tower)
return fixed_overfit(objfunc(item, starting_point), binbb);
//else {
// return fixed_overfit_topright_sliding(objfunc(item, starting_point), binbb, m_excluded_and_extruCali_regions);
//}
};
};
@ -611,16 +637,18 @@ template<> std::function<double(const Item&, const ItemGroup&)> AutoArranger<Box
double score = std::get<0>(result);
auto& fullbb = std::get<1>(result);
if (m_pconf.starting_point == PConfig::Alignment::BOTTOM_LEFT)
{
if (!sl::isInside(fullbb, m_bin))
score += LARGE_COST_TO_REJECT;
}
else
//if (m_pconf.starting_point == PConfig::Alignment::BOTTOM_LEFT)
//{
// if (!sl::isInside(fullbb, m_bin))
// score += LARGE_COST_TO_REJECT;
//}
//else
{
double miss = Placer::overfit(fullbb, m_bin);
miss = miss > 0 ? miss : 0;
score += miss * miss;
if (score > LARGE_COST_TO_REJECT)
score = 1.5 * LARGE_COST_TO_REJECT;
}
return score;
@ -821,7 +849,7 @@ static void process_arrangeable(const ArrangePolygon &arrpoly,
item.binId(arrpoly.bed_idx);
item.priority(arrpoly.priority);
item.itemId(arrpoly.itemid);
item.extrude_id = arrpoly.extrude_ids.back();
item.extrude_id = arrpoly.extrude_ids.front();
item.height = arrpoly.height;
item.name = arrpoly.name;
//BBS: add virtual object logic

View file

@ -124,6 +124,7 @@ struct ArrangeParams {
float clearance_height_to_rod = 0;
float clearance_height_to_lid = 0;
float cleareance_radius = 0;
float printable_height = 256.0;
ArrangePolygons excluded_regions; // regions cant't be used
ArrangePolygons nonprefered_regions; // regions can be used but not prefered

View file

@ -122,6 +122,7 @@ bool BridgeDetector::detect_angle(double bridge_direction_override)
double max_length = 0;
{
Lines clipped_lines = intersection_ln(lines, clip_area);
size_t archored_line_num = 0;
for (size_t i = 0; i < clipped_lines.size(); ++i) {
const Line &line = clipped_lines[i];
if (expolygons_contain(this->_anchor_regions, line.a) && expolygons_contain(this->_anchor_regions, line.b)) {
@ -129,8 +130,12 @@ bool BridgeDetector::detect_angle(double bridge_direction_override)
double len = line.length();
total_length += len;
max_length = std::max(max_length, len);
archored_line_num++;
}
}
}
if (clipped_lines.size() > 0 && archored_line_num > 0) {
candidates[i_angle].archored_percent = (double)archored_line_num / (double)clipped_lines.size();
}
}
if (total_length == 0.)
continue;
@ -155,7 +160,7 @@ bool BridgeDetector::detect_angle(double bridge_direction_override)
// if any other direction is within extrusion width of coverage, prefer it if shorter
// TODO: There are two options here - within width of the angle with most coverage, or within width of the currently perferred?
size_t i_best = 0;
for (size_t i = 1; i < candidates.size() && candidates[i_best].coverage - candidates[i].coverage < this->spacing; ++ i)
for (size_t i = 1; i < candidates.size() && abs(candidates[i_best].archored_percent - candidates[i].archored_percent) < EPSILON; ++ i)
if (candidates[i].max_length < candidates[i_best].max_length)
i_best = i;

View file

@ -44,15 +44,16 @@ private:
void initialize();
struct BridgeDirection {
BridgeDirection(double a = -1.) : angle(a), coverage(0.), max_length(0.) {}
BridgeDirection(double a = -1.) : angle(a), coverage(0.), max_length(0.), archored_percent(0.){}
// the best direction is the one causing most lines to be bridged (thus most coverage)
bool operator<(const BridgeDirection &other) const {
// Initial sort by coverage only - comparator must obey strict weak ordering
return this->coverage > other.coverage;
return this->archored_percent > other.archored_percent;
};
double angle;
double coverage;
double max_length;
double archored_percent;
};
// Get possible briging direction candidates.

View file

@ -876,6 +876,8 @@ static ExPolygons outer_inner_brim_area(const Print& print,
brimToWrite.insert({ objectWithExtruder.first, {true,true} });
ExPolygons objectIslands;
auto bedPoly = Model::getBedPolygon();
auto bedExPoly = diff_ex((offset(bedPoly, scale_(30.), jtRound, SCALED_RESOLUTION)), { bedPoly });
for (unsigned int extruderNo : printExtruders) {
++extruderNo;
@ -1036,7 +1038,9 @@ static ExPolygons outer_inner_brim_area(const Print& print,
}
}
}
for (const PrintObject* object : print.objects())
if (!bedExPoly.empty())
no_brim_area.push_back(bedExPoly.front());
for (const PrintObject* object : print.objects())
if (brimAreaMap.find(object->id()) != brimAreaMap.end()) {
brimAreaMap[object->id()] = diff_ex(brimAreaMap[object->id()], no_brim_area);

View file

@ -35,6 +35,8 @@ set(lisbslic3r_sources
clipper.hpp
ClipperUtils.cpp
ClipperUtils.hpp
Clipper2Utils.cpp
Clipper2Utils.hpp
Config.cpp
Config.hpp
CurveAnalyzer.cpp
@ -108,6 +110,8 @@ set(lisbslic3r_sources
Format/STL.hpp
Format/SL1.hpp
Format/SL1.cpp
Format/svg.hpp
Format/svg.cpp
GCode/ThumbnailData.cpp
GCode/ThumbnailData.hpp
GCode/CoolingBuffer.cpp
@ -474,6 +478,7 @@ target_link_libraries(libslic3r
PNG::PNG
ZLIB::ZLIB
${OCCT_LIBS}
Clipper2
)
if(NOT WIN32)

View file

@ -0,0 +1,60 @@
#include "Clipper2Utils.hpp"
namespace Slic3r {
//BBS: FIXME
Slic3r::Polylines Paths64_to_polylines(const Clipper2Lib::Paths64& in)
{
Slic3r::Polylines out;
out.reserve(in.size());
for (const Clipper2Lib::Path64& path64 : in) {
Slic3r::Points points;
points.reserve(path64.size());
for (const Clipper2Lib::Point64& point64 : path64)
points.emplace_back(std::move(Slic3r::Point(point64.x, point64.y)));
out.emplace_back(std::move(Slic3r::Polyline(points)));
}
return out;
}
//BBS: FIXME
template <typename T>
Clipper2Lib::Paths64 Slic3rPoints_to_Paths64(const std::vector<T>& in)
{
Clipper2Lib::Paths64 out;
out.reserve(in.size());
for (const T item: in) {
Clipper2Lib::Path64 path;
path.reserve(item.size());
for (const Slic3r::Point& point : item.points)
path.emplace_back(std::move(Clipper2Lib::Point64(point.x(), point.y())));
out.emplace_back(std::move(path));
}
return out;
}
Polylines _clipper2_pl_open(Clipper2Lib::ClipType clipType, const Slic3r::Polylines& subject, const Slic3r::Polygons& clip)
{
Clipper2Lib::Clipper64 c;
c.AddOpenSubject(Slic3rPoints_to_Paths64(subject));
c.AddClip(Slic3rPoints_to_Paths64(clip));
Clipper2Lib::ClipType ct = clipType;
Clipper2Lib::FillRule fr = Clipper2Lib::FillRule::NonZero;
Clipper2Lib::Paths64 solution, solution_open;
c.Execute(ct, fr, solution, solution_open);
Slic3r::Polylines out;
out.reserve(solution.size() + solution_open.size());
polylines_append(out, std::move(Paths64_to_polylines(solution)));
polylines_append(out, std::move(Paths64_to_polylines(solution_open)));
return out;
}
Slic3r::Polylines intersection_pl_2(const Slic3r::Polylines& subject, const Slic3r::Polygons& clip)
{ return _clipper2_pl_open(Clipper2Lib::ClipType::Intersection, subject, clip); }
Slic3r::Polylines diff_pl_2(const Slic3r::Polylines& subject, const Slic3r::Polygons& clip)
{ return _clipper2_pl_open(Clipper2Lib::ClipType::Difference, subject, clip); }
}

View file

@ -0,0 +1,17 @@
#ifndef slic3r_Clipper2Utils_hpp_
#define slic3r_Clipper2Utils_hpp_
#include "libslic3r.h"
#include "clipper2/clipper.h"
#include "Polygon.hpp"
#include "Polyline.hpp"
namespace Slic3r {
Slic3r::Polylines intersection_pl_2(const Slic3r::Polylines& subject, const Slic3r::Polygons& clip);
Slic3r::Polylines diff_pl_2(const Slic3r::Polylines& subject, const Slic3r::Polygons& clip);
}
#endif

View file

@ -534,7 +534,7 @@ bool ConfigBase::set_deserialize_nothrow(const t_config_option_key &opt_key_src,
this->handle_legacy(opt_key, value);
if (opt_key.empty()) {
// Ignore the option.
//BBS: record these options, keep only one repeated opt_key
//BBS: record these options, keep only one repeated opt_key
auto iter = std::find(substitutions_ctxt.unrecogized_keys.begin(), substitutions_ctxt.unrecogized_keys.end(), opt_key_src);
if (iter == substitutions_ctxt.unrecogized_keys.end())
substitutions_ctxt.unrecogized_keys.push_back(opt_key_src);
@ -615,7 +615,7 @@ bool ConfigBase::set_deserialize_raw(const t_config_option_key &opt_key_src, con
if (! success && substitutions_ctxt.rule != ForwardCompatibilitySubstitutionRule::Disable &&
// Only allow substitutions of an enum value by another enum value or a boolean value with an enum value.
// That means, we expect enum values being added in the future and possibly booleans being converted to enums.
(optdef->type == coEnum || optdef->type == coBool) && ConfigHelpers::looks_like_enum_value(value)) {
(optdef->type == coEnum || optdef->type == coEnums || optdef->type == coBool) /*&& ConfigHelpers::looks_like_enum_value(value)*/) {
// Deserialize failed, try to substitute with a default value.
//assert(substitutions_ctxt.rule == ForwardCompatibilitySubstitutionRule::Enable || substitutions_ctxt.rule == ForwardCompatibilitySubstitutionRule::EnableSilent);
if (optdef->type == coBool)
@ -757,6 +757,9 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
if (boost::iequals(it.key(),BBL_JSON_KEY_VERSION)) {
key_values.emplace(BBL_JSON_KEY_VERSION, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_IS_CUSTOM)) {
key_values.emplace(BBL_JSON_KEY_IS_CUSTOM, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) {
key_values.emplace(BBL_JSON_KEY_NAME, it.value());
}
@ -1209,14 +1212,15 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo
}
//BBS: add json support
void ConfigBase::save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version) const
void ConfigBase::save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version, const std::string is_custom) const
{
json j;
//record the headers
j[BBL_JSON_KEY_VERSION] = version;
j[BBL_JSON_KEY_NAME] = name;
j[BBL_JSON_KEY_FROM] = from;
if (!is_custom.empty())
j[BBL_JSON_KEY_IS_CUSTOM] = is_custom;
//record all the key-values
for (const std::string &opt_key : this->keys())

View file

@ -1701,12 +1701,12 @@ public:
while (std::getline(is, item_str, ',')) {
boost::trim(item_str);
if (item_str == "nil") {
throw ConfigurationError("Deserializing nil into a non-nullable object");
return false;
}
else {
auto it = this->keys_map->find(item_str);
if (it == this->keys_map->end())
throw ConfigurationError(std::string("Unknown enum type: ") + item_str);
return false;
this->values.push_back(it->second);
}
}
@ -2139,7 +2139,7 @@ public:
void save(const std::string &file) const;
//BBS: add json support
void save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version) const;
void save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version, const std::string is_custom = "") const;
// Set all the nullable values to nils.
void null_nullables();

View file

@ -92,6 +92,12 @@ bool ExPolygon::contains(const Line &line) const
bool ExPolygon::contains(const Polyline &polyline) const
{
BoundingBox bbox1 = get_extents(*this);
BoundingBox bbox2 = get_extents(polyline);
bbox2.inflated(1);
if (!bbox1.overlap(bbox2))
return false;
return diff_pl(polyline, *this).empty();
}

View file

@ -24,7 +24,17 @@ SLIC3R_DERIVE_EXCEPTION(HostNetworkError, IOError);
SLIC3R_DERIVE_EXCEPTION(ExportError, CriticalException);
SLIC3R_DERIVE_EXCEPTION(PlaceholderParserError, RuntimeError);
// Runtime exception produced by Slicer. Such exception cancels the slicing process and it shall be shown in notifications.
SLIC3R_DERIVE_EXCEPTION(SlicingError, Exception);
//SLIC3R_DERIVE_EXCEPTION(SlicingError, Exception);
class SlicingError : public Exception
{
public:
using Exception::Exception;
SlicingError(std::string const &msg, size_t objectId) : Exception(msg), objectId_(objectId) {}
size_t objectId() const { return objectId_; }
private:
size_t objectId_ = 0;
};
#undef SLIC3R_DERIVE_EXCEPTION
} // namespace Slic3r

View file

@ -147,6 +147,7 @@ public:
// Height of the extrusion, used for visualization purposes.
float height;
ExtrusionPath() : mm3_per_mm(-1), width(-1), height(-1), m_role(erNone), m_no_extrusion(false) {}
ExtrusionPath(ExtrusionRole role) : mm3_per_mm(-1), width(-1), height(-1), m_role(role), m_no_extrusion(false) {}
ExtrusionPath(ExtrusionRole role, double mm3_per_mm, float width, float height, bool no_extrusion = false) : mm3_per_mm(mm3_per_mm), width(width), height(height), m_role(role), m_no_extrusion(no_extrusion) {}
ExtrusionPath(int overhang_degree, int curve_degree, ExtrusionRole role, double mm3_per_mm, float width, float height) : overhang_degree(overhang_degree), curve_degree(curve_degree), mm3_per_mm(mm3_per_mm), width(width), height(height), m_role(role) {}
@ -235,6 +236,8 @@ public:
void simplify_by_fitting_arc(double tolerance);
//BBS:
bool is_force_no_extrusion() const { return m_no_extrusion; }
void set_force_no_extrusion(bool no_extrusion) { m_no_extrusion = no_extrusion; }
void set_extrusion_role(ExtrusionRole extrusion_role) { m_role = extrusion_role; }
private:
void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const;
@ -251,7 +254,7 @@ class ExtrusionMultiPath : public ExtrusionEntity
{
public:
ExtrusionPaths paths;
ExtrusionMultiPath() {}
ExtrusionMultiPath(const ExtrusionMultiPath &rhs) : paths(rhs.paths) {}
ExtrusionMultiPath(ExtrusionMultiPath &&rhs) : paths(std::move(rhs.paths)) {}
@ -288,7 +291,7 @@ public:
double min_mm3_per_mm() const override;
Polyline as_polyline() const override;
void collect_polylines(Polylines &dst) const override { Polyline pl = this->as_polyline(); if (! pl.empty()) dst.emplace_back(std::move(pl)); }
void collect_points(Points &dst) const override {
void collect_points(Points &dst) const override {
size_t n = std::accumulate(paths.begin(), paths.end(), 0, [](const size_t n, const ExtrusionPath &p){ return n + p.polyline.size(); });
dst.reserve(dst.size() + n);
for (const ExtrusionPath &p : this->paths)
@ -302,11 +305,11 @@ class ExtrusionLoop : public ExtrusionEntity
{
public:
ExtrusionPaths paths;
ExtrusionLoop(ExtrusionLoopRole role = elrDefault) : m_loop_role(role) {}
ExtrusionLoop(const ExtrusionPaths &paths, ExtrusionLoopRole role = elrDefault) : paths(paths), m_loop_role(role) {}
ExtrusionLoop(ExtrusionPaths &&paths, ExtrusionLoopRole role = elrDefault) : paths(std::move(paths)), m_loop_role(role) {}
ExtrusionLoop(const ExtrusionPath &path, ExtrusionLoopRole role = elrDefault) : m_loop_role(role)
ExtrusionLoop(const ExtrusionPath &path, ExtrusionLoopRole role = elrDefault) : m_loop_role(role)
{ this->paths.push_back(path); }
ExtrusionLoop(const ExtrusionPath &&path, ExtrusionLoopRole role = elrDefault) : m_loop_role(role)
{ this->paths.emplace_back(std::move(path)); }
@ -339,6 +342,7 @@ public:
bool has_overhang_point(const Point &point) const;
ExtrusionRole role() const override { return this->paths.empty() ? erNone : this->paths.front().role(); }
ExtrusionLoopRole loop_role() const { return m_loop_role; }
void set_loop_role(ExtrusionLoopRole role) { m_loop_role = role; }
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width.
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
void polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const override;
@ -354,7 +358,7 @@ public:
double min_mm3_per_mm() const override;
Polyline as_polyline() const override { return this->polygon().split_at_first_point(); }
void collect_polylines(Polylines &dst) const override { Polyline pl = this->as_polyline(); if (! pl.empty()) dst.emplace_back(std::move(pl)); }
void collect_points(Points &dst) const override {
void collect_points(Points &dst) const override {
size_t n = std::accumulate(paths.begin(), paths.end(), 0, [](const size_t n, const ExtrusionPath &p){ return n + p.polyline.size(); });
dst.reserve(dst.size() + n);
for (const ExtrusionPath &p : this->paths)

View file

@ -46,6 +46,8 @@ struct SurfaceFillParams
// 1000mm is roughly the maximum length line that fits into a 32bit coord_t.
float anchor_length = 1000.f;
float anchor_length_max = 1000.f;
//BBS
bool with_loop = false;
// width, height of extrusion, nozzle diameter, is bridge
// For the output, for fill generator.
@ -77,6 +79,7 @@ struct SurfaceFillParams
// RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, dont_adjust);
RETURN_COMPARE_NON_EQUAL(anchor_length);
RETURN_COMPARE_NON_EQUAL(anchor_length_max);
RETURN_COMPARE_NON_EQUAL(with_loop);
RETURN_COMPARE_NON_EQUAL(flow.width());
RETURN_COMPARE_NON_EQUAL(flow.height());
RETURN_COMPARE_NON_EQUAL(flow.nozzle_diameter());
@ -97,6 +100,7 @@ struct SurfaceFillParams
// this->dont_adjust == rhs.dont_adjust &&
this->anchor_length == rhs.anchor_length &&
this->anchor_length_max == rhs.anchor_length_max &&
this->with_loop == rhs.with_loop &&
this->flow == rhs.flow &&
this->extrusion_role == rhs.extrusion_role;
}
@ -147,6 +151,8 @@ std::vector<SurfaceFill> group_fills(const Layer &layer)
params.extruder = layerm.region().extruder(extrusion_role);
params.pattern = region_config.sparse_infill_pattern.value;
params.density = float(region_config.sparse_infill_density);
//BBS
params.with_loop = surface.surface_type == stInternalWithLoop;
if (surface.is_solid()) {
params.density = 100.f;
@ -363,8 +369,8 @@ std::vector<SurfaceFill> group_fills(const Layer &layer)
surface_fills.back().region_id = surface_fills[i].region_id;
surface_fills.back().surface.surface_type = stInternalSolid;
surface_fills.back().surface.thickness = surface_fills[i].surface.thickness;
surface_fills.back().region_id_group = surface_fills[i].region_id_group;
surface_fills.back().no_overlap_expolygons = surface_fills[i].no_overlap_expolygons;
surface_fills.back().region_id_group = surface_fills[i].region_id_group;
surface_fills.back().no_overlap_expolygons = surface_fills[i].no_overlap_expolygons;
for (size_t j = 0; j < narrow_expolygons_index.size(); j++) {
// BBS: move the narrow expolygons to new surface_fills.back();
surface_fills.back().expolygons.emplace_back(std::move(surface_fills[i].expolygons[narrow_expolygons_index[j]]));
@ -478,11 +484,12 @@ void Layer::make_fills(FillAdaptive::Octree* adaptive_fill_octree, FillAdaptive:
params.extrusion_role = surface_fill.params.extrusion_role;
params.using_internal_flow = using_internal_flow;
params.no_extrusion_overlap = surface_fill.params.overlap;
params.with_loop = surface_fill.params.with_loop;
LayerRegion* layerm = this->m_regions[surface_fill.region_id];
params.config = &layerm->region().config();
for (ExPolygon& expoly : surface_fill.expolygons) {
f->no_overlap_expolygons = intersection_ex(surface_fill.no_overlap_expolygons, ExPolygons() = {expoly});
f->no_overlap_expolygons = intersection_ex(surface_fill.no_overlap_expolygons, ExPolygons() = {expoly});
// Spacing is modified by the filler to indicate adjustments. Reset it for each expolygon.
f->spacing = surface_fill.params.spacing;
surface_fill.surface.expolygon = std::move(expoly);

View file

@ -29,7 +29,7 @@
namespace Slic3r {
//BBS: 0% of sparse_infill_line_width, no anchor at the start of sparse infill
float Fill::infill_anchor = 0;
float Fill::infill_anchor = 400;
//BBS: 20mm
float Fill::infill_anchor_max = 20;
@ -54,9 +54,7 @@ Fill* Fill::new_from_type(const InfillPattern type)
case ipAdaptiveCubic: return new FillAdaptive::Filler();
case ipSupportCubic: return new FillAdaptive::Filler();
case ipSupportBase: return new FillSupportBase();
#if HAS_LIGHTNING_INFILL
case ipLightning: return new FillLightning::Filler();
#endif // HAS_LIGHTNING_INFILL
// BBS: for internal solid infill only
case ipConcentricInternal: return new FillConcentricInternal();
// BBS: for bottom and top surface only
@ -122,13 +120,57 @@ void Fill::fill_surface_extrusion(const Surface* surface, const FillParams& para
{
Polylines polylines;
ThickPolylines thick_polylines;
try {
if (params.use_arachne)
thick_polylines = this->fill_surface_arachne(surface, params);
else
polylines = this->fill_surface(surface, params);
if (!params.with_loop) {
try {
if (params.use_arachne)
thick_polylines = this->fill_surface_arachne(surface, params);
else
polylines = this->fill_surface(surface, params);
}
catch (InfillFailedException&) {}
}
//BBS: add handling for infill pattern with loop
else {
Slic3r::ExPolygons expp = offset_ex(surface->expolygon, float(scale_(this->overlap - 0.5 * this->spacing)));
Polylines loop_polylines = to_polylines(expp);
{
//BBS: clip the loop
size_t j = 0;
for (size_t i = 0; i < loop_polylines.size(); ++i) {
loop_polylines[i].clip_end(this->loop_clipping);
if (loop_polylines[i].is_valid()) {
if (j < i)
loop_polylines[j] = std::move(loop_polylines[i]);
++j;
}
}
if (j < loop_polylines.size())
loop_polylines.erase(loop_polylines.begin() + int(j), loop_polylines.end());
}
if (!loop_polylines.empty()) {
if (params.use_arachne)
append(thick_polylines, to_thick_polylines(std::move(loop_polylines), scaled<coord_t>(this->spacing)));
else
append(polylines, std::move(loop_polylines));
expp = offset_ex(expp, float(scale_(0 - 0.5 * this->spacing)));
} else {
//BBS: the area is too narrow to place a loop, return to original expolygon
expp = { surface->expolygon };
}
Surface temp_surface = *surface;
for (ExPolygon& ex : expp) {
temp_surface.expolygon = ex;
try {
if (params.use_arachne)
append(thick_polylines, std::move(this->fill_surface_arachne(&temp_surface, params)));
else
append(polylines, std::move(this->fill_surface(&temp_surface, params)));
}
catch (InfillFailedException&) {}
}
}
catch (InfillFailedException&) {}
if (!polylines.empty() || !thick_polylines.empty()) {
// calculate actual flow from spacing (which might have been adjusted by the infill

View file

@ -67,6 +67,8 @@ struct FillParams
bool use_arachne{ false };
// Layer height for Concentric infill with Arachne.
coordf_t layer_height { 0.f };
//BBS
bool with_loop { false };
// BBS
Flow flow;

View file

@ -5,6 +5,7 @@
#include "Arachne/WallToolPaths.hpp"
#include "FillConcentric.hpp"
#include <libslic3r/ShortestPath.hpp>
namespace Slic3r {
@ -133,6 +134,8 @@ void FillConcentric::_fill_surface_single(const FillParams& params,
}
if (j < thick_polylines_out.size())
thick_polylines_out.erase(thick_polylines_out.begin() + int(j), thick_polylines_out.end());
reorder_by_shortest_traverse(thick_polylines_out);
}
else {
Polylines polylines;

View file

@ -5,6 +5,7 @@
#include "Arachne/WallToolPaths.hpp"
#include "FillConcentricInternal.hpp"
#include <libslic3r/ShortestPath.hpp>
namespace Slic3r {
@ -22,7 +23,7 @@ void FillConcentricInternal::fill_surface_extrusion(const Surface* surface, cons
coord_t min_spacing = params.flow.scaled_spacing();
coord_t loops_count = std::max(bbox_size.x(), bbox_size.y()) / min_spacing + 1;
Polygons polygons = offset(expolygon, 0);
Polygons polygons = to_polygons(expolygon);
double min_nozzle_diameter = *std::min_element(print_config->nozzle_diameter.values.begin(), print_config->nozzle_diameter.values.end());
Arachne::WallToolPathsParams input_params;
@ -76,6 +77,8 @@ void FillConcentricInternal::fill_surface_extrusion(const Surface* surface, cons
}
if (j < thick_polylines_out.size())
thick_polylines_out.erase(thick_polylines_out.begin() + int(j), thick_polylines_out.end());
reorder_by_shortest_traverse(thick_polylines_out);
}
ExtrusionEntityCollection *coll_nosort = new ExtrusionEntityCollection();

View file

@ -26,9 +26,9 @@ void GeneratorDeleter::operator()(Generator *p) {
delete p;
}
GeneratorPtr build_generator(const PrintObject &print_object)
GeneratorPtr build_generator(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback)
{
return GeneratorPtr(new Generator(print_object));
return GeneratorPtr(new Generator(print_object, throw_on_cancel_callback));
}
} // namespace Slic3r::FillAdaptive

View file

@ -3,13 +3,6 @@
#include "FillBase.hpp"
/*
* A few modifications based on dba1179(2022.06.10) from Prusa, mainly in Generator.hpp and .cpp:
* 1. delete the second parameter(a throw back function) of Generator(), since I didnt find corresponding throw back function in BBS code
* 2. those codes that call the functions above
* 3. add codes of generating lightning in TreeSupport.cpp
*/
namespace Slic3r {
class PrintObject;
@ -21,7 +14,7 @@ class Generator;
struct GeneratorDeleter { void operator()(Generator *p); };
using GeneratorPtr = std::unique_ptr<Generator, GeneratorDeleter>;
GeneratorPtr build_generator(const PrintObject &print_object);
GeneratorPtr build_generator(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback);
class Filler : public Slic3r::Fill
{

View file

@ -43,7 +43,8 @@ DistanceField::DistanceField(const coord_t& radius, const Polygons& current_outl
m_supporting_radius2 = Slic3r::sqr(int64_t(radius));
// Sample source polygons with a regular grid sampling pattern.
const BoundingBox overhang_bbox = get_extents(current_overhang);
for (const ExPolygon &expoly : union_ex(current_overhang)) {
ExPolygons expolys = offset2_ex(union_ex(current_overhang), -m_cell_size / 2, m_cell_size / 2); // remove dangling lines which causes sample_grid_pattern crash (fails the OUTER_LOW assertions)
for (const ExPolygon &expoly : expolys) {
const Points sampled_points = sample_grid_pattern(expoly, m_cell_size, overhang_bbox);
const size_t unsupported_points_prev_size = m_unsupported_points.size();
m_unsupported_points.resize(unsupported_points_prev_size + sampled_points.size());
@ -94,10 +95,6 @@ DistanceField::DistanceField(const coord_t& radius, const Polygons& current_outl
void DistanceField::update(const Point& to_node, const Point& added_leaf)
{
std::ofstream out1("z:/misc/lightning.txt", std::ios::app);
out1 << m_unsupported_points.size() << std::endl;
out1.close();
Vec2d v = (added_leaf - to_node).cast<double>();
auto l2 = v.squaredNorm();
Vec2d extent = Vec2d(-v.y(), v.x()) * m_supporting_radius / sqrt(l2);

View file

@ -63,7 +63,7 @@ Slic3r::SVG draw_two_overhangs_to_svg(size_t ts_layer, const ExPolygons& overhan
namespace Slic3r::FillLightning {
Generator::Generator(const PrintObject &print_object)
Generator::Generator(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback)
{
const PrintConfig &print_config = print_object.print()->config();
const PrintObjectConfig &object_config = print_object.config();
@ -87,11 +87,11 @@ Generator::Generator(const PrintObject &print_object)
m_prune_length = coord_t(layer_thickness * std::tan(lightning_infill_prune_angle));
m_straightening_max_distance = coord_t(layer_thickness * std::tan(lightning_infill_straightening_angle));
generateInitialInternalOverhangs(print_object);
generateTrees(print_object);
generateInitialInternalOverhangs(print_object, throw_on_cancel_callback);
generateTrees(print_object, throw_on_cancel_callback);
}
Generator::Generator(PrintObject* m_object, std::vector<Polygons>& contours, std::vector<Polygons>& overhangs, float density)
Generator::Generator(PrintObject* m_object, std::vector<Polygons>& contours, std::vector<Polygons>& overhangs, const std::function<void()> &throw_on_cancel_callback, float density)
{
const PrintConfig &print_config = m_object->print()->config();
const PrintObjectConfig &object_config = m_object->config();
@ -120,7 +120,7 @@ Generator::Generator(PrintObject* m_object, std::vector<Polygons>& contours, std
m_overhang_per_layer = overhangs;
generateTreesforSupport(contours);
generateTreesforSupport(contours, throw_on_cancel_callback);
//for (size_t i = 0; i < overhangs.size(); i++)
//{
@ -130,13 +130,14 @@ Generator::Generator(PrintObject* m_object, std::vector<Polygons>& contours, std
//}
}
void Generator::generateInitialInternalOverhangs(const PrintObject &print_object)
void Generator::generateInitialInternalOverhangs(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback)
{
m_overhang_per_layer.resize(print_object.layers().size());
Polygons infill_area_above;
//Iterate from top to bottom, to subtract the overhang areas above from the overhang areas on the layer below, to get only overhang in the top layer where it is overhanging.
for (int layer_nr = int(print_object.layers().size()) - 1; layer_nr >= 0; --layer_nr) {
throw_on_cancel_callback();
Polygons infill_area_here;
for (const LayerRegion* layerm : print_object.get_layer(layer_nr)->regions())
for (const Surface& surface : layerm->fill_surfaces.surfaces)
@ -157,7 +158,7 @@ const Layer& Generator::getTreesForLayer(const size_t& layer_id) const
return m_lightning_layers[layer_id];
}
void Generator::generateTrees(const PrintObject &print_object)
void Generator::generateTrees(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback)
{
m_lightning_layers.resize(print_object.layers().size());
bboxs.resize(print_object.layers().size());
@ -165,6 +166,7 @@ void Generator::generateTrees(const PrintObject &print_object)
// For-each layer from top to bottom:
for (int layer_id = int(print_object.layers().size()) - 1; layer_id >= 0; layer_id--) {
throw_on_cancel_callback();
for (const LayerRegion *layerm : print_object.get_layer(layer_id)->regions())
for (const Surface &surface : layerm->fill_surfaces.surfaces)
if (surface.surface_type == stInternal || surface.surface_type == stInternalVoid)
@ -178,6 +180,7 @@ void Generator::generateTrees(const PrintObject &print_object)
// For-each layer from top to bottom:
for (int layer_id = int(top_layer_id); layer_id >= 0; layer_id--) {
throw_on_cancel_callback();
Layer &current_lightning_layer = m_lightning_layers[layer_id];
const Polygons &current_outlines = infill_outlines[layer_id];
const BoundingBox &current_outlines_bbox = get_extents(current_outlines);
@ -187,7 +190,7 @@ void Generator::generateTrees(const PrintObject &print_object)
// register all trees propagated from the previous layer as to-be-reconnected
std::vector<NodeSPtr> to_be_reconnected_tree_roots = current_lightning_layer.tree_roots;
current_lightning_layer.generateNewTrees(m_overhang_per_layer[layer_id], current_outlines, current_outlines_bbox, outlines_locator, m_supporting_radius, m_wall_supporting_radius);
current_lightning_layer.generateNewTrees(m_overhang_per_layer[layer_id], current_outlines, current_outlines_bbox, outlines_locator, m_supporting_radius, m_wall_supporting_radius, throw_on_cancel_callback);
current_lightning_layer.reconnectRoots(to_be_reconnected_tree_roots, current_outlines, current_outlines_bbox, outlines_locator, m_supporting_radius, m_wall_supporting_radius);
// Initialize trees for next lower layer from the current one.
@ -211,8 +214,10 @@ void Generator::generateTrees(const PrintObject &print_object)
}
}
void Generator::generateTreesforSupport(std::vector<Polygons>& contours)
void Generator::generateTreesforSupport(std::vector<Polygons>& contours, const std::function<void()> &throw_on_cancel_callback)
{
if (contours.empty()) return;
m_lightning_layers.resize(contours.size());
bboxs.resize(contours.size());
@ -223,6 +228,7 @@ void Generator::generateTreesforSupport(std::vector<Polygons>& contours)
// For-each layer from top to bottom:
for (int layer_id = int(top_layer_id); layer_id >= 0; layer_id--) {
throw_on_cancel_callback();
Layer& current_lightning_layer = m_lightning_layers[layer_id];
const Polygons& current_outlines = contours[layer_id];
const BoundingBox& current_outlines_bbox = get_extents(current_outlines);
@ -232,7 +238,7 @@ void Generator::generateTreesforSupport(std::vector<Polygons>& contours)
// register all trees propagated from the previous layer as to-be-reconnected
std::vector<NodeSPtr> to_be_reconnected_tree_roots = current_lightning_layer.tree_roots;
current_lightning_layer.generateNewTrees(m_overhang_per_layer[layer_id], current_outlines, current_outlines_bbox, outlines_locator, m_supporting_radius, m_wall_supporting_radius);
current_lightning_layer.generateNewTrees(m_overhang_per_layer[layer_id], current_outlines, current_outlines_bbox, outlines_locator, m_supporting_radius, m_wall_supporting_radius, throw_on_cancel_callback);
current_lightning_layer.reconnectRoots(to_be_reconnected_tree_roots, current_outlines, current_outlines_bbox, outlines_locator, m_supporting_radius, m_wall_supporting_radius);
// Initialize trees for next lower layer from the current one.

View file

@ -44,7 +44,7 @@ public:
* Lightning Infill for the infill areas in that mesh. The infill areas must
* already be calculated at this point.
*/
explicit Generator(const PrintObject &print_object);
explicit Generator(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback);
/*!
* Get a tree of paths generated for a certain layer of the mesh.
@ -61,7 +61,7 @@ public:
float infilll_extrusion_width() const { return m_infill_extrusion_width; }
Generator(PrintObject* m_object, std::vector<Polygons>& contours, std::vector<Polygons>& overhangs, float density = 0.15);
Generator(PrintObject* m_object, std::vector<Polygons>& contours, std::vector<Polygons>& overhangs, const std::function<void()> &throw_on_cancel_callback, float density = 0.15);
protected:
/*!
@ -72,13 +72,13 @@ protected:
* only when support is generated. For this pattern, we also need to
* generate overhang areas for the inside of the model.
*/
void generateInitialInternalOverhangs(const PrintObject &print_object);
void generateInitialInternalOverhangs(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback);
/*!
* Calculate the tree structure of all layers.
*/
void generateTrees(const PrintObject &print_object);
void generateTreesforSupport(std::vector<Polygons>& contours);
void generateTrees(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback);
void generateTreesforSupport(std::vector<Polygons>& contours, const std::function<void()> &throw_on_cancel_callback);
float m_infill_extrusion_width;

View file

@ -48,10 +48,12 @@ void Layer::generateNewTrees
const BoundingBox& current_outlines_bbox,
const EdgeGrid::Grid& outlines_locator,
const coord_t supporting_radius,
const coord_t wall_supporting_radius
const coord_t wall_supporting_radius,
const std::function<void()> &throw_on_cancel_callback
)
{
DistanceField distance_field(supporting_radius, current_outlines, current_outlines_bbox, current_overhang);
throw_on_cancel_callback();
SparseNodeGrid tree_node_locator;
fillLocator(tree_node_locator, current_outlines_bbox);
@ -61,6 +63,7 @@ void Layer::generateNewTrees
size_t unsupported_cell_idx = 0;
Point unsupported_location;
while (distance_field.tryGetNextPoint(&unsupported_location, &unsupported_cell_idx, unsupported_cell_idx)) {
throw_on_cancel_callback();
GroundingLocation grounding_loc = getBestGroundingLocation(
unsupported_location, current_outlines, current_outlines_bbox, outlines_locator, supporting_radius, wall_supporting_radius, tree_node_locator);

View file

@ -44,7 +44,8 @@ public:
const BoundingBox& current_outlines_bbox,
const EdgeGrid::Grid& outline_locator,
coord_t supporting_radius,
coord_t wall_supporting_radius
coord_t wall_supporting_radius,
const std::function<void()> &throw_on_cancel_callback
);
/*! Determine & connect to connection point in tree/outline.

View file

@ -661,7 +661,7 @@ ModelVolumeType type_from_string(const std::string &s)
: m_version(0)
, m_check_version(false)
, m_xml_parser(nullptr)
, m_model(nullptr)
, m_model(nullptr)
, m_unit_factor(1.0f)
, m_curr_metadata_name("")
, m_curr_characters("")
@ -934,6 +934,18 @@ ModelVolumeType type_from_string(const std::string &s)
++object_idx;
}
//BBS: copy object isteadof instance
int object_size = model.objects.size();
for (int obj_index = 0; obj_index < object_size; obj_index ++) {
ModelObject* object = model.objects[obj_index];
while (object->instances.size() > 1) {
ModelObject* new_model_object = model.add_object(*object);
new_model_object->clear_instances();
new_model_object->add_instance(*object->instances.back());
object->delete_last_instance();
}
}
// // fixes the min z of the model if negative
// model.adjust_min_z();
@ -1005,8 +1017,8 @@ ModelVolumeType type_from_string(const std::string &s)
}
void _3MF_Importer::_extract_print_config_from_archive(
mz_zip_archive& archive, const mz_zip_archive_file_stat& stat,
DynamicPrintConfig& config, ConfigSubstitutionContext& config_substitutions,
mz_zip_archive& archive, const mz_zip_archive_file_stat& stat,
DynamicPrintConfig& config, ConfigSubstitutionContext& config_substitutions,
const std::string& archive_filename)
{
if (stat.m_uncomp_size > 0) {
@ -1227,7 +1239,7 @@ ModelVolumeType type_from_string(const std::string &s)
}
}
}
void _3MF_Importer::_extract_sla_drain_holes_from_archive(mz_zip_archive& archive, const mz_zip_archive_file_stat& stat)
{
if (stat.m_uncomp_size > 0) {
@ -1237,13 +1249,13 @@ ModelVolumeType type_from_string(const std::string &s)
add_error("Error while reading sla support points data to buffer");
return;
}
if (buffer.back() == '\n')
buffer.pop_back();
std::vector<std::string> objects;
boost::split(objects, buffer, boost::is_any_of("\n"), boost::token_compress_off);
// Info on format versioning - see 3mf.hpp
int version = 0;
std::string key("drain_holes_format_version=");
@ -1252,38 +1264,38 @@ ModelVolumeType type_from_string(const std::string &s)
version = std::stoi(objects[0]);
objects.erase(objects.begin()); // pop the header
}
for (const std::string& object : objects) {
std::vector<std::string> object_data;
boost::split(object_data, object, boost::is_any_of("|"), boost::token_compress_off);
if (object_data.size() != 2) {
add_error("Error while reading object data");
continue;
}
std::vector<std::string> object_data_id;
boost::split(object_data_id, object_data[0], boost::is_any_of("="), boost::token_compress_off);
if (object_data_id.size() != 2) {
add_error("Error while reading object id");
continue;
}
int object_id = std::atoi(object_data_id[1].c_str());
if (object_id == 0) {
add_error("Found invalid object id");
continue;
}
IdToSlaDrainHolesMap::iterator object_item = m_sla_drain_holes.find(object_id);
if (object_item != m_sla_drain_holes.end()) {
add_error("Found duplicated SLA drain holes");
continue;
}
std::vector<std::string> object_data_points;
boost::split(object_data_points, object_data[1], boost::is_any_of(" "), boost::token_compress_off);
sla::DrainHoles sla_drain_holes;
if (version == 1) {
@ -1306,7 +1318,7 @@ ModelVolumeType type_from_string(const std::string &s)
hole.pos += hole.normal.normalized();
hole.height -= 1.f;
}
if (!sla_drain_holes.empty())
m_sla_drain_holes.insert({ object_id, sla_drain_holes });
}
@ -1394,11 +1406,11 @@ ModelVolumeType type_from_string(const std::string &s)
pt::ptree attr_tree = tree.find("<xmlattr>")->second;
if (attr_tree.find("type") == attr_tree.not_found()) {
// It means that data was saved in old version (2.2.0 and older) of PrusaSlicer
// read old data ...
// read old data ...
std::string gcode = tree.get<std::string> ("<xmlattr>.gcode");
// ... and interpret them to the new data
type = gcode == "M600" ? CustomGCode::ColorChange :
gcode == "M601" ? CustomGCode::PausePrint :
type = gcode == "M600" ? CustomGCode::ColorChange :
gcode == "M601" ? CustomGCode::PausePrint :
gcode == "tool_change" ? CustomGCode::ToolChange : CustomGCode::Custom;
extra = type == CustomGCode::PausePrint ? color :
type == CustomGCode::Custom ? gcode : "";
@ -2113,7 +2125,7 @@ ModelVolumeType type_from_string(const std::string &s)
tri_id -= min_id;
}
if (m_prusaslicer_generator_version &&
if (m_prusaslicer_generator_version &&
*m_prusaslicer_generator_version >= *Semver::parse("2.4.0-alpha1") &&
*m_prusaslicer_generator_version < *Semver::parse("2.4.0-alpha3"))
// PrusaSlicer 2.4.0-alpha2 contained a bug, where all vertices of a single object were saved for each volume the object contained.
@ -2227,7 +2239,7 @@ ModelVolumeType type_from_string(const std::string &s)
if (importer != nullptr)
importer->_handle_start_config_xml_element(name, attributes);
}
void XMLCALL _3MF_Importer::_handle_end_config_xml_element(void* userData, const char* name)
{
_3MF_Importer* importer = (_3MF_Importer*)userData;
@ -2340,7 +2352,7 @@ ModelVolumeType type_from_string(const std::string &s)
}
}
// Adds relationships file ("_rels/.rels").
// Adds relationships file ("_rels/.rels").
// The content of this file is the same for each PrusaSlicer 3mf.
// The relationshis file contains a reference to the geometry file "3D/3dmodel.model", the name was chosen to be compatible with CURA.
if (!_add_relationships_file_to_archive(archive)) {
@ -2384,13 +2396,13 @@ ModelVolumeType type_from_string(const std::string &s)
boost::filesystem::remove(filename);
return false;
}
if (!_add_sla_drain_holes_file_to_archive(archive, model)) {
close_zip_writer(&archive);
boost::filesystem::remove(filename);
return false;
}
// Adds custom gcode per height file ("Metadata/Prusa_Slicer_custom_gcode_per_print_z.xml").
// All custom gcode per height of whole Model are stored here
@ -2502,11 +2514,11 @@ ModelVolumeType type_from_string(const std::string &s)
bool _3MF_Exporter::_add_model_file_to_archive(const std::string& filename, mz_zip_archive& archive, const Model& model, IdToObjectDataMap& objects_data)
{
mz_zip_writer_staged_context context;
if (!mz_zip_writer_add_staged_open(&archive, &context, MODEL_FILE.c_str(),
m_zip64 ?
if (!mz_zip_writer_add_staged_open(&archive, &context, MODEL_FILE.c_str(),
m_zip64 ?
// Maximum expected and allowed 3MF file size is 16GiB.
// This switches the ZIP file to a 64bit mode, which adds a tiny bit of overhead to file records.
(uint64_t(1) << 30) * 16 :
(uint64_t(1) << 30) * 16 :
// Maximum expected 3MF file size is 4GB-1. This is a workaround for interoperability with Windows 10 3D model fixing API, see
// GH issue #6193.
(uint64_t(1) << 32) - 1,
@ -2589,7 +2601,7 @@ ModelVolumeType type_from_string(const std::string &s)
}
stream << "</" << MODEL_TAG << ">\n";
std::string buf = stream.str();
if ((! buf.empty() && ! mz_zip_writer_add_staged_data(&context, buf.data(), buf.size())) ||
@ -2877,7 +2889,7 @@ ModelVolumeType type_from_string(const std::string &s)
sprintf(buffer, (i == 0) ? "%f" : ";%f", layer_height_profile[i]);
out += buffer;
}
out += "\n";
}
}
@ -2936,8 +2948,8 @@ ModelVolumeType type_from_string(const std::string &s)
boost::replace_all(out, "><option", ">\n <option");
boost::replace_all(out, "></range>", ">\n </range>");
boost::replace_all(out, "></object>", ">\n </object>");
// OR just
boost::replace_all(out, "><", ">\n<");
// OR just
boost::replace_all(out, "><", ">\n<");
}
if (!out.empty()) {
@ -2984,13 +2996,13 @@ ModelVolumeType type_from_string(const std::string &s)
}
return true;
}
bool _3MF_Exporter::_add_sla_drain_holes_file_to_archive(mz_zip_archive& archive, Model& model)
{
assert(is_decimal_separator_point());
const char *const fmt = "object_id=%d|";
std::string out;
unsigned int count = 0;
for (const ModelObject* object : model.objects) {
++count;
@ -3007,7 +3019,7 @@ ModelVolumeType type_from_string(const std::string &s)
if (!drain_holes.empty()) {
out += string_printf(fmt, count);
// Store the layer height profile as a single space separated list.
for (size_t i = 0; i < drain_holes.size(); ++i)
out += string_printf((i == 0 ? "%f %f %f %f %f %f %f %f" : " %f %f %f %f %f %f %f %f"),
@ -3019,15 +3031,15 @@ ModelVolumeType type_from_string(const std::string &s)
drain_holes[i].normal(2),
drain_holes[i].radius,
drain_holes[i].height);
out += "\n";
}
}
if (!out.empty()) {
// Adds version header at the beginning:
out = std::string("drain_holes_format_version=") + std::to_string(drain_holes_format_version) + std::string("\n") + out;
if (!mz_zip_writer_add_mem(&archive, SLA_DRAIN_HOLES_FILE.c_str(), static_cast<const void*>(out.data()), out.length(), mz_uint(MZ_DEFAULT_COMPRESSION))) {
add_error("Unable to add sla support points file to archive");
return false;
@ -3099,7 +3111,7 @@ ModelVolumeType type_from_string(const std::string &s)
if (volume->is_modifier())
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << MODIFIER_KEY << "\" " << VALUE_ATTR << "=\"1\"/>\n";
// stores volume's type (overrides the modifier field above)
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << VOLUME_TYPE_KEY << "\" " <<
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << VOLUME_TYPE_KEY << "\" " <<
VALUE_ATTR << "=\"" << ModelVolume::type_to_string(volume->type()) << "\"/>\n";
// stores volume's local matrix
@ -3137,7 +3149,7 @@ ModelVolumeType type_from_string(const std::string &s)
for (const std::string& key : volume->config.keys()) {
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << volume->config.opt_serialize(key) << "\"/>\n";
}
// stores mesh's statistics
const RepairedMeshErrors& stats = volume->mesh().stats().repaired_errors;
stream << " <" << MESH_TAG << " ";
@ -3190,12 +3202,12 @@ bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archiv
std::string gcode = //code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") :
code.type == CustomGCode::PausePrint ? config->opt_string("machine_pause_gcode") :
code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") :
code.type == CustomGCode::ToolChange ? "tool_change" : code.extra;
code.type == CustomGCode::ToolChange ? "tool_change" : code.extra;
code_tree.put("<xmlattr>.gcode" , gcode );
}
pt::ptree& mode_tree = main_tree.add("mode", "");
// store mode of a custom_gcode_per_print_z
// store mode of a custom_gcode_per_print_z
mode_tree.put("<xmlattr>.value", model.custom_gcode_per_print_z.mode == CustomGCode::Mode::SingleExtruder ? CustomGCode::SingleExtruderMode :
model.custom_gcode_per_print_z.mode == CustomGCode::Mode::MultiAsSingle ? CustomGCode::MultiAsSingleMode :
CustomGCode::MultiExtruderMode);
@ -3208,7 +3220,7 @@ bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archiv
// Post processing("beautification") of the output string
boost::replace_all(out, "><", ">\n<");
}
}
}
if (!out.empty()) {
if (!mz_zip_writer_add_mem(&archive, CUSTOM_GCODE_PER_PRINT_Z_FILE.c_str(), (const void*)out.data(), out.length(), MZ_DEFAULT_COMPRESSION)) {

File diff suppressed because it is too large Load diff

View file

@ -57,6 +57,7 @@ struct PlateData
int plate_index;
std::vector<std::pair<int, int>> objects_and_instances;
std::map<int, std::pair<int, int>> obj_inst_map;
std::string gcode_file;
std::string gcode_file_md5;
std::string thumbnail_file;
@ -67,6 +68,8 @@ struct PlateData
std::string gcode_prediction;
std::string gcode_weight;
std::vector<FilamentInfo> slice_filaments_info;
DynamicPrintConfig config;
bool is_support_used {false};
bool is_sliced_valid = false;
bool toolpath_outside {false};
@ -202,7 +205,8 @@ struct StoreParams
//BBS: add plate data list related logic
// add restore logic
// Load the content of a 3mf file into the given model and preset bundle.
extern bool load_bbs_3mf(const char* path, DynamicPrintConfig* config, ConfigSubstitutionContext* config_substitutions, Model* model, PlateDataPtrs* plate_data_list, std::vector<Preset*>* project_presets, bool* is_bbl_3mf, Semver* file_version, Import3mfProgressFn proFn = nullptr, LoadStrategy strategy = LoadStrategy::Default, BBLProject *project = nullptr);
extern bool load_bbs_3mf(const char* path, DynamicPrintConfig* config, ConfigSubstitutionContext* config_substitutions, Model* model, PlateDataPtrs* plate_data_list, std::vector<Preset*>* project_presets,
bool* is_bbl_3mf, Semver* file_version, Import3mfProgressFn proFn = nullptr, LoadStrategy strategy = LoadStrategy::Default, BBLProject *project = nullptr, int plate_id = 0);
extern std::string bbs_3mf_get_thumbnail(const char * path);

View file

@ -0,0 +1,341 @@
#include "../libslic3r.h"
#include "../Model.hpp"
#include "../TriangleMesh.hpp"
#include "svg.hpp"
#include "nanosvg/nanosvg.h"
#include <string>
#include <boost/log/trivial.hpp>
#include "BRepBuilderAPI_MakeWire.hxx"
#include "BRepBuilderAPI_MakeEdge.hxx"
#include "BRepBuilderAPI_MakeFace.hxx"
#include "BRepPrimAPI_MakePrism.hxx"
#include "BRepBuilderAPI_Transform.hxx"
#include "BRepMesh_IncrementalMesh.hxx"
#include "TopoDS_Face.hxx"
#include "TopExp_Explorer.hxx"
#include "TopoDS.hxx"
#include "BRepExtrema_SelfIntersection.hxx"
namespace Slic3r {
const double STEP_TRANS_CHORD_ERROR = 0.005;
const double STEP_TRANS_ANGLE_RES = 1;
struct Element_Info
{
std::string name;
unsigned int color;
TopoDS_Shape shape;
};
bool is_same_points(gp_Pnt pt1, gp_Pnt pt2) {
return abs(pt1.X() - pt2.X()) < 0.001
&& abs(pt1.Y() - pt2.Y()) < 0.001
&& abs(pt1.Z() - pt2.Z()) < 0.001;
}
struct Point_2D
{
Point_2D(float in_x, float in_y) : x(in_x), y(in_y) {}
float x;
float y;
};
void interp_v2_v2v2(float r[2], const float a[2], const float b[2], const float t)
{
const float s = 1.0f - t;
r[0] = s * a[0] + t * b[0];
r[1] = s * a[1] + t * b[1];
}
void interp_v2_v2v2v2v2_cubic(float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float u)
{
float q0[2], q1[2], q2[2], r0[2], r1[2];
interp_v2_v2v2(q0, v1, v2, u);
interp_v2_v2v2(q1, v2, v3, u);
interp_v2_v2v2(q2, v3, v4, u);
interp_v2_v2v2(r0, q0, q1, u);
interp_v2_v2v2(r1, q1, q2, u);
interp_v2_v2v2(p, r0, r1, u);
}
bool is_two_lines_interaction(gp_Pnt pL1, gp_Pnt pL2, gp_Pnt pR1, gp_Pnt pR2) {
Vec3d point1(pL1.X(), pL1.Y(), 0);
Vec3d point2(pL2.X(), pL2.Y(), 0);
Vec3d point3(pR1.X(), pR1.Y(), 0);
Vec3d point4(pR2.X(), pR2.Y(), 0);
Vec3d line1 = point2 - point1;
Vec3d line2 = point4 - point3;
Vec3d line_pos1 = point1 - point3;
Vec3d line_pos2 = point2 - point3;
Vec3d line_pos3 = point3 - point1;
Vec3d line_pos4 = point4 - point1;
Vec3d cross_1 = line2.cross(line_pos1);
Vec3d cross_2 = line2.cross(line_pos2);
Vec3d cross_3 = line1.cross(line_pos3);
Vec3d cross_4 = line1.cross(line_pos4);
return (cross_1.dot(cross_2) < 0) && (cross_3.dot(cross_4) < 0);
}
bool is_profile_self_interaction(std::vector<std::pair<gp_Pnt, gp_Pnt>> profile_line_points)
{
for (int i = 0; i < profile_line_points.size(); ++i) {
for (int j = i + 2; j < profile_line_points.size(); ++j)
if (is_two_lines_interaction(profile_line_points[i].first, profile_line_points[i].second, profile_line_points[j].first, profile_line_points[j].second))
return true;
}
return false;
}
double get_profile_area(std::vector<std::pair<gp_Pnt, gp_Pnt>> profile_line_points)
{
double min_x = 0;
for (auto line_points : profile_line_points) {
if (line_points.first.X() < min_x) min_x = line_points.first.X();
}
double area = 0;
for (auto line_points : profile_line_points) {
bool flag = true;
if (line_points.second.Y() < line_points.first.Y()) flag = false;
area += (line_points.second.X() + line_points.first.X() - 2 * min_x) * (line_points.second.Y() - line_points.first.Y()) / 2;
}
return abs(area);
}
bool get_svg_profile(const char *path, std::vector<Element_Info> &element_infos, std::string& message)
{
NSVGimage *svg_data = nullptr;
svg_data = nsvgParseFromFile(path, "mm", 96.0f);
if (svg_data == nullptr) {
message = "import svg failed: could not open svg.";
return false;
}
if (svg_data->shapes == nullptr) {
message = "import svg failed: could not parse imported svg data.";
return false;
}
int name_index = 1;
for (NSVGshape *shape = svg_data->shapes; shape; shape = shape->next) {
char * id = shape->id;
int interpolation_precision = 10; // Number of interpolation points
float step = 1.0f / float(interpolation_precision - 1);
// get the path point
std::vector<std::vector<std::vector<Point_2D>>> all_path_points; // paths<profiles<curves<points>>>
for (NSVGpath *path = shape->paths; path; path = path->next) {
std::vector<std::vector<Point_2D>> profile_points;
int index = 0;
for (int i = 0; i < path->npts - 1; i += 3) {
float * p = &path->pts[i * 2];
float a = 0.0f;
std::vector<Point_2D> curve_points; // points on a curve
for (int v = 0; v < interpolation_precision; v++) {
float pt[2];
// get interpolation points of Bezier curve
interp_v2_v2v2v2v2_cubic(pt, &p[0], &p[2], &p[4], &p[6], a);
Point_2D point(pt[0], -pt[1]);
curve_points.push_back(point);
a += step;
}
profile_points.push_back(curve_points);
// keep the adjacent curves end-to-end
if (profile_points.size() > 1) {
profile_points[index - 1].back() = profile_points[index].front();
}
index++;
}
if (!profile_points.empty())
all_path_points.push_back(profile_points);
}
// remove duplicate points and ensure the profile is closed
std::vector<std::vector<std::pair<gp_Pnt, gp_Pnt>>> path_line_points;
for (auto profile_points : all_path_points) {
std::vector<std::pair<gp_Pnt, gp_Pnt>> profile_line_points;
for (int i = 0; i < profile_points.size(); ++i) {
for (int j = 0; j + 1 < profile_points[i].size(); j++) {
gp_Pnt pt1(profile_points[i][j].x, profile_points[i][j].y, 0);
gp_Pnt pt2(profile_points[i][j + 1].x, profile_points[i][j + 1].y, 0);
if (is_same_points(pt1, pt2))
continue;
profile_line_points.push_back({pt1, pt2});
}
}
// keep the start and end points of profile connected
profile_line_points.back().second = profile_line_points[0].first;
if (is_profile_self_interaction(profile_line_points))
BOOST_LOG_TRIVIAL(warning) << "the profile is self interaction.";
path_line_points.push_back(profile_line_points);
}
// generate all profile curves
std::vector<TopoDS_Wire> wires;
int index = 0;
double max_area = 0;
for (int i = 0; i < path_line_points.size(); ++i) {
BRepBuilderAPI_MakeWire wire_build;
for (auto point_item : path_line_points[i]) {
TopoDS_Edge edge_build = BRepBuilderAPI_MakeEdge(point_item.first, point_item.second);
wire_build.Add(edge_build);
}
TopoDS_Wire wire = wire_build.Wire();
double profile_area = get_profile_area(path_line_points[i]);
if (profile_area > max_area) {
max_area = profile_area;
index = i;
}
wires.emplace_back(wire);
}
gp_Vec dir(0, 0, 10);
BRepBuilderAPI_MakeFace face_make(wires[index]);
for (int i = 0; i < wires.size(); ++i) {
if (index == i)
continue;
face_make.Add(wires[i]);
}
TopoDS_Face face = face_make.Face();
TopoDS_Shape element_shape = BRepPrimAPI_MakePrism(face, dir, false, false).Shape();
Element_Info element_info;
element_info.name = "part_" + std::to_string(name_index);
element_info.color = shape->fill.color;
element_info.shape = element_shape;
element_infos.push_back(element_info);
name_index++;
}
nsvgDelete(svg_data);
return true;
}
bool load_svg(const char *path, Model *model, std::string &message)
{
std::vector<Element_Info> namedSolids;
if (!get_svg_profile(path, namedSolids, message))
return false;
std::vector<stl_file> stl;
stl.resize(namedSolids.size());
// todo: zhimin, Can be accelerated in parallel with tbb
for (size_t i = 0 ; i < namedSolids.size(); i++) {
BRepMesh_IncrementalMesh mesh(namedSolids[i].shape, STEP_TRANS_CHORD_ERROR, false, STEP_TRANS_ANGLE_RES, true);
// BBS: calculate total number of the nodes and triangles
int aNbNodes = 0;
int aNbTriangles = 0;
for (TopExp_Explorer anExpSF(namedSolids[i].shape, TopAbs_FACE); anExpSF.More(); anExpSF.Next()) {
TopLoc_Location aLoc;
Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(TopoDS::Face(anExpSF.Current()), aLoc);
if (!aTriangulation.IsNull()) {
aNbNodes += aTriangulation->NbNodes();
aNbTriangles += aTriangulation->NbTriangles();
}
}
if (aNbTriangles == 0 || aNbNodes == 0)
// BBS: No triangulation on the shape.
continue;
stl[i].stats.type = inmemory;
stl[i].stats.number_of_facets = (uint32_t) aNbTriangles;
stl[i].stats.original_num_facets = stl[i].stats.number_of_facets;
stl_allocate(&stl[i]);
std::vector<Vec3f> points;
points.reserve(aNbNodes);
// BBS: count faces missing triangulation
Standard_Integer aNbFacesNoTri = 0;
// BBS: fill temporary triangulation
Standard_Integer aNodeOffset = 0;
Standard_Integer aTriangleOffet = 0;
for (TopExp_Explorer anExpSF(namedSolids[i].shape, TopAbs_FACE); anExpSF.More(); anExpSF.Next()) {
const TopoDS_Shape &aFace = anExpSF.Current();
TopLoc_Location aLoc;
Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(TopoDS::Face(aFace), aLoc);
if (aTriangulation.IsNull()) {
++aNbFacesNoTri;
continue;
}
// BBS: copy nodes
gp_Trsf aTrsf = aLoc.Transformation();
for (Standard_Integer aNodeIter = 1; aNodeIter <= aTriangulation->NbNodes(); ++aNodeIter) {
gp_Pnt aPnt = aTriangulation->Node(aNodeIter);
aPnt.Transform(aTrsf);
points.emplace_back(std::move(Vec3f(aPnt.X(), aPnt.Y(), aPnt.Z())));
}
// BBS: copy triangles
const TopAbs_Orientation anOrientation = anExpSF.Current().Orientation();
Standard_Integer anId[3];
for (Standard_Integer aTriIter = 1; aTriIter <= aTriangulation->NbTriangles(); ++aTriIter) {
Poly_Triangle aTri = aTriangulation->Triangle(aTriIter);
aTri.Get(anId[0], anId[1], anId[2]);
if (anOrientation == TopAbs_REVERSED) std::swap(anId[1], anId[2]);
// BBS: save triangles facets
stl_facet facet;
facet.vertex[0] = points[anId[0] + aNodeOffset - 1].cast<float>();
facet.vertex[1] = points[anId[1] + aNodeOffset - 1].cast<float>();
facet.vertex[2] = points[anId[2] + aNodeOffset - 1].cast<float>();
facet.extra[0] = 0;
facet.extra[1] = 0;
stl_normal normal;
stl_calculate_normal(normal, &facet);
stl_normalize_vector(normal);
facet.normal = normal;
stl[i].facet_start[aTriangleOffet + aTriIter - 1] = facet;
}
aNodeOffset += aTriangulation->NbNodes();
aTriangleOffet += aTriangulation->NbTriangles();
}
}
ModelObject *new_object = model->add_object();
// new_object->name ?
new_object->input_file = path;
auto stage_unit3 = stl.size() / LOAD_STEP_STAGE_UNIT_NUM + 1;
for (size_t i = 0; i < stl.size(); i++) {
// BBS: maybe mesh is empty from step file. Don't add
if (stl[i].stats.number_of_facets > 0) {
TriangleMesh triangle_mesh;
triangle_mesh.from_stl(stl[i]);
ModelVolume *new_volume = new_object->add_volume(std::move(triangle_mesh));
new_volume->name = namedSolids[i].name;
new_volume->source.input_file = path;
new_volume->source.object_idx = (int) model->objects.size() - 1;
new_volume->source.volume_idx = (int) new_object->volumes.size() - 1;
}
}
return true;
}
} // namespace Slic3r

View file

@ -0,0 +1,7 @@
#pragma once
namespace Slic3r {
class Model;
extern bool load_svg(const char *path, Model *model, std::string &message);
}; // namespace Slic3r

View file

@ -682,8 +682,7 @@ std::vector<GCode::LayerToPrint> GCode::collect_layers_to_print(const PrintObjec
// first layer may result in skirt/brim in the air and maybe other issues.
if (layers_to_print.size() == 1u) {
if (!has_extrusions)
throw Slic3r::SlicingError(_(L("One object has empty initial layer and can't be printed. Please Cut the bottom or enable supports.")) + "\n" +
_(L("Object")) + ": " + object.model_object()->name);
throw Slic3r::SlicingError(_(L("One object has empty initial layer and can't be printed. Please Cut the bottom or enable supports.")), object.id().id);
}
// In case there are extrusions on this layer, check there is a layer to lay it on.
@ -1379,10 +1378,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
file.write(full_config);
// SoftFever: write compatiple image
std::vector<int> temps_per_bed;
int first_layer_bed_temperature = 0;
get_bed_temperature(0, true, temps_per_bed,
first_layer_bed_temperature);
int first_layer_bed_temperature = get_bed_temperature(0, true, print.config().curr_bed_type);
file.write_format("; first_layer_bed_temperature = %d\n",
first_layer_bed_temperature);
file.write_format(
@ -1501,12 +1497,6 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
// Emit machine envelope limits for the Marlin firmware.
this->print_machine_envelope(file, print);
//BBS: emit printing accelerate if has non-zero value
if (m_config.default_acceleration.value > 0) {
float acceleration = m_config.default_acceleration.value;
file.write(m_writer.set_acceleration((unsigned int)floor(acceleration + 0.5)));
}
// Disable fan.
if (m_config.auxiliary_fan.value && print.config().close_fan_the_first_x_layers.get_at(initial_extruder_id)) {
file.write(m_writer.set_fan(0));
@ -1874,9 +1864,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
file.write(full_config);
// SoftFever: write compatiple info
std::vector<int> temps_per_bed;
int first_layer_bed_temperature = 0;
get_bed_temperature(0, true, temps_per_bed, first_layer_bed_temperature);
int first_layer_bed_temperature = get_bed_temperature(0, true, print.config().curr_bed_type);
file.write_format("; first_layer_bed_temperature = %d\n",
first_layer_bed_temperature);
file.write_format(
@ -1885,7 +1873,9 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
file.write_format(
"; first_layer_height = %.3f\n",
print.config().initial_layer_print_height.value);
file.write_format("; variable_layer_height = %d\n", m_config.adaptive_layer_height ? 1 : 0);
//SF TODO
// file.write_format("; variable_layer_height = %d\n", print.ad.adaptive_layer_height ? 1 : 0);
file.write("; CONFIG_BLOCK_END\n\n");
@ -2135,17 +2125,11 @@ void GCode::print_machine_envelope(GCodeOutputStream &file, Print &print)
}
// BBS
void GCode::get_bed_temperature(const int extruder_id, const bool is_first_layer, std::vector<int>& temps_per_bed, int& default_temp) const
int GCode::get_bed_temperature(const int extruder_id, const bool is_first_layer, const BedType bed_type) const
{
temps_per_bed.resize((int)BedType::btCount, 0);
for (int bed_type = 0; bed_type < BedType::btCount; bed_type++) {
std::string bed_temp_key = is_first_layer ? get_bed_temp_1st_layer_key((BedType)bed_type) : get_bed_temp_key((BedType)bed_type);
const ConfigOptionInts* bed_temp_opt = m_config.option<ConfigOptionInts>(bed_temp_key);
temps_per_bed[bed_type] = bed_temp_opt->get_at(extruder_id);
if (bed_type == m_config.curr_bed_type)
default_temp = temps_per_bed[bed_type];
}
std::string bed_temp_key = is_first_layer ? get_bed_temp_1st_layer_key(bed_type) : get_bed_temp_key(bed_type);
const ConfigOptionInts* bed_temp_opt = m_config.option<ConfigOptionInts>(bed_temp_key);
return bed_temp_opt->get_at(extruder_id);
}
// Write 1st layer bed temperatures into the G-code.
@ -2157,8 +2141,7 @@ void GCode::_print_first_layer_bed_temperature(GCodeOutputStream &file, Print &p
// Initial bed temperature based on the first extruder.
// BBS
std::vector<int> temps_per_bed;
int default_temp = 0;
get_bed_temperature(first_printing_extruder_id, true, temps_per_bed, default_temp);
int bed_temp = get_bed_temperature(first_printing_extruder_id, true, print.config().curr_bed_type);
// Is the bed temperature set by the provided custom G-code?
int temp_by_gcode = -1;
@ -2171,7 +2154,7 @@ void GCode::_print_first_layer_bed_temperature(GCodeOutputStream &file, Print &p
// Always call m_writer.set_bed_temperature() so it will set the internal "current" state of the bed temp as if
// the custom start G-code emited these.
std::string set_temp_gcode = m_writer.set_bed_temperature(temps_per_bed, default_temp, wait);
std::string set_temp_gcode = m_writer.set_bed_temperature(bed_temp, wait);
if (! temp_set_by_gcode)
file.write(set_temp_gcode);
}
@ -2639,10 +2622,8 @@ GCode::LayerResult GCode::process_layer(
}
// BBS
std::vector<int> temps_per_bed;
int default_temp = 0;
get_bed_temperature(first_extruder_id, false, temps_per_bed, default_temp);
gcode += m_writer.set_bed_temperature(temps_per_bed, default_temp);
int bed_temp = get_bed_temperature(first_extruder_id, false, print.config().curr_bed_type);
gcode += m_writer.set_bed_temperature(bed_temp);
// Mark the temperature transition from 1st to 2nd layer to be finished.
m_second_layer_things_done = true;
}
@ -3297,11 +3278,8 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
// get a copy; don't modify the orientation of the original loop object otherwise
// next copies (if any) would not detect the correct orientation
//BBS: extrude contour of wall ccw, hole of wall cw, except spiral mode
bool was_clockwise = loop.is_clockwise();
if (m_config.spiral_mode || !is_perimeter(loop.role()))
loop.make_counter_clockwise();
bool current_clockwise = loop.is_clockwise();
// extrude all loops ccw
bool was_clockwise = loop.make_counter_clockwise();
// find the point of the loop that is closest to the current extruder position
// or randomize if requested
@ -3371,7 +3349,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
//FIXME improve the algorithm in case the loop is split into segments with a low number of points (see the Point b query).
Point a = paths.front().polyline.points[1]; // second point
Point b = *(paths.back().polyline.points.end()-3); // second to last point
if (was_clockwise != current_clockwise) {
if (was_clockwise) {
// swap points
Point c = a; a = b; b = c;
}
@ -3379,7 +3357,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
double angle = paths.front().first_point().ccw_angle(a, b) / 3;
// turn left if contour, turn right if hole
if (was_clockwise != current_clockwise) angle *= -1;
if (was_clockwise) angle *= -1;
// create the destination point along the first segment and rotate it
// we make sure we don't exceed the segment length because we don't know
@ -3391,7 +3369,12 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
double l2 = v.squaredNorm();
// Shift by no more than a nozzle diameter.
//FIXME Hiding the seams will not work nicely for very densely discretized contours!
Point pt = ((nd * nd >= l2) ? p2 : (p1 + v * (nd / sqrt(l2)))).cast<coord_t>();
//BBS. shorten the travel distant before the wipe path
double threshold = 0.2;
Point pt = (p1 + v * threshold).cast<coord_t>();
if (nd * nd < l2)
pt = (p1 + threshold * v * (nd / sqrt(l2))).cast<coord_t>();
//Point pt = ((nd * nd >= l2) ? (p1+v*0.4): (p1 + 0.2 * v * (nd / sqrt(l2)))).cast<coord_t>();
pt.rotate(angle, paths.front().polyline.points.front());
// generate the travel move
gcode += m_writer.travel_to_xy(this->point_to_gcode(pt), "move inwards before travel");
@ -3654,8 +3637,6 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
acceleration = m_config.first_layer_acceleration_over_raft.value;
} else if (m_config.bridge_acceleration.value > 0 && is_bridge(path.role())) {
acceleration = m_config.bridge_acceleration.value;
} else if (m_config.perimeter_acceleration.value > 0 && is_perimeter(path.role())) {
acceleration = m_config.perimeter_acceleration.value;
#endif
} else if (m_config.outer_wall_acceleration.value > 0 && is_external_perimeter(path.role())) {
acceleration = m_config.outer_wall_acceleration.value;
@ -3807,11 +3788,21 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
std::string comment;
if (m_enable_cooling_markers) {
if (EXTRUDER_CONFIG(enable_overhang_bridge_fan) &&
(path.get_overhang_degree() > EXTRUDER_CONFIG(overhang_fan_threshold) || is_bridge(path.role())))
gcode += ";_OVERHANG_FAN_START\n";
else
if (EXTRUDER_CONFIG(enable_overhang_bridge_fan)) {
//BBS: Overhang_threshold_none means Overhang_threshold_1_4 and forcing cooling for all external perimeter
int overhang_threshold = EXTRUDER_CONFIG(overhang_fan_threshold) == Overhang_threshold_none ?
Overhang_threshold_none : EXTRUDER_CONFIG(overhang_fan_threshold) - 1;
if ((EXTRUDER_CONFIG(overhang_fan_threshold) == Overhang_threshold_none && path.role() == erExternalPerimeter) ||
path.get_overhang_degree() > overhang_threshold ||
is_bridge(path.role()))
gcode += ";_OVERHANG_FAN_START\n";
else
comment = ";_EXTRUDE_SET_SPEED";
}
else {
comment = ";_EXTRUDE_SET_SPEED";
}
if (path.role() == erExternalPerimeter)
comment += ";_EXTERNAL_PERIMETER";
}
@ -3875,10 +3866,22 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
}
}
}
if (m_enable_cooling_markers)
gcode += (EXTRUDER_CONFIG(enable_overhang_bridge_fan) &&
(is_bridge(path.role()) || path.get_overhang_degree() > EXTRUDER_CONFIG(overhang_fan_threshold))) ?
";_OVERHANG_FAN_END\n" : ";_EXTRUDE_END\n";
if (m_enable_cooling_markers) {
if (EXTRUDER_CONFIG(enable_overhang_bridge_fan)) {
//BBS: Overhang_threshold_none means Overhang_threshold_1_4 and forcing cooling for all external perimeter
int overhang_threshold = EXTRUDER_CONFIG(overhang_fan_threshold) == Overhang_threshold_none ?
Overhang_threshold_none : EXTRUDER_CONFIG(overhang_fan_threshold) - 1;
if ((EXTRUDER_CONFIG(overhang_fan_threshold) == Overhang_threshold_none && path.role() == erExternalPerimeter) ||
path.get_overhang_degree() > overhang_threshold ||
is_bridge(path.role()))
gcode += ";_OVERHANG_FAN_END\n";
else
gcode += ";_EXTRUDE_END\n";
}
else {
gcode += ";_EXTRUDE_END\n";
}
}
this->set_last_pos(path.last_point());
return gcode;
@ -4122,13 +4125,13 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z)
std::vector<float> flush_matrix(cast<float>(m_config.flush_volumes_matrix.values));
const unsigned int number_of_extruders = (unsigned int)(sqrt(flush_matrix.size()) + EPSILON);
assert(m_writer.extruder()->id() < number_of_extruders);
assert(new_retract_length < number_of_extruders);
int previous_extruder_id = m_writer.extruder()->id();
old_retract_length = m_config.retraction_length.get_at(previous_extruder_id);
old_retract_length_toolchange = m_config.retract_length_toolchange.get_at(previous_extruder_id);
old_filament_temp = this->on_first_layer()? m_config.nozzle_temperature_initial_layer.get_at(previous_extruder_id) : m_config.nozzle_temperature.get_at(previous_extruder_id);
wipe_volume = flush_matrix[previous_extruder_id * number_of_extruders + extruder_id];
wipe_volume *= m_config.flush_multiplier;
old_filament_e_feedrate = (int)(60.0 * m_config.filament_max_volumetric_speed.get_at(previous_extruder_id) / filament_area);
old_filament_e_feedrate = old_filament_e_feedrate == 0 ? 100 : old_filament_e_feedrate;
}

View file

@ -492,7 +492,7 @@ private:
static bool gcode_label_objects;
// BBS
void get_bed_temperature(const int extruder_id, const bool is_first_layer, std::vector<int>& temps_per_bed, int& default_temp) const;
int get_bed_temperature(const int extruder_id, const bool is_first_layer, const BedType bed_type) const;
std::string _extrude(const ExtrusionPath &path, std::string description = "", double speed = -1);
void print_machine_envelope(GCodeOutputStream &file, Print &print);

View file

@ -722,7 +722,7 @@ std::string CoolingBuffer::apply_layer_cooldown(
new_gcode.reserve(gcode.size() * 2);
bool overhang_fan_control= false;
int overhang_fan_speed = 0;
auto change_extruder_set_fan = [ this, layer_id, layer_time, &new_gcode, &overhang_fan_control, &overhang_fan_speed]() {
auto change_extruder_set_fan = [ this, layer_id, layer_time, &new_gcode, &overhang_fan_control, &overhang_fan_speed](bool immediately_apply) {
#define EXTRUDER_CONFIG(OPT) m_config.OPT.get_at(m_current_extruder)
int fan_min_speed = EXTRUDER_CONFIG(fan_min_speed);
int fan_speed_new = EXTRUDER_CONFIG(reduce_fan_stop_start_freq) ? fan_min_speed : 0;
@ -771,18 +771,20 @@ std::string CoolingBuffer::apply_layer_cooldown(
m_fan_speed = fan_speed_new;
//BBS
m_current_fan_speed = fan_speed_new;
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed);
if (immediately_apply)
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed);
}
//BBS
if (additional_fan_speed_new != m_additional_fan_speed && m_config.auxiliary_fan.value) {
m_additional_fan_speed = additional_fan_speed_new;
new_gcode += GCodeWriter::set_additional_fan(m_additional_fan_speed);
if (immediately_apply)
new_gcode += GCodeWriter::set_additional_fan(m_additional_fan_speed);
}
};
const char *pos = gcode.c_str();
int current_feedrate = 0;
change_extruder_set_fan();
change_extruder_set_fan(true);
for (const CoolingLine *line : lines) {
const char *line_start = gcode.c_str() + line->line_start;
const char *line_end = gcode.c_str() + line->line_end;
@ -792,7 +794,7 @@ std::string CoolingBuffer::apply_layer_cooldown(
unsigned int new_extruder = (unsigned int)atoi(line_start + m_toolchange_prefix.size());
if (new_extruder != m_current_extruder) {
m_current_extruder = new_extruder;
change_extruder_set_fan();
change_extruder_set_fan(false); //BBS: will force to resume fan speed when filament change is finished
}
new_gcode.append(line_start, line_end - line_start);
} else if (line->type & CoolingLine::TYPE_OVERHANG_FAN_START) {

View file

@ -36,6 +36,7 @@ static const float DEFAULT_TRAVEL_ACCELERATION = 1250.0f;
static const size_t MIN_EXTRUDERS_COUNT = 5;
static const float DEFAULT_FILAMENT_DIAMETER = 1.75f;
static const int DEFAULT_FILAMENT_HRC = 0;
static const float DEFAULT_FILAMENT_DENSITY = 1.245f;
static const int DEFAULT_FILAMENT_VITRIFICATION_TEMPERATURE = 0;
static const Slic3r::Vec3f DEFAULT_EXTRUDER_OFFSET = Slic3r::Vec3f::Zero();
@ -472,7 +473,16 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st
PrintEstimatedStatistics::ETimeMode mode = static_cast<PrintEstimatedStatistics::ETimeMode>(i);
if (mode == PrintEstimatedStatistics::ETimeMode::Normal || machine.enabled) {
char buf[128];
sprintf(buf, "; estimated printing time: %s\n", get_time_dhms(machine.time).c_str());
if(!s_IsBBLPrinter)
sprintf(buf, "; estimated printing time: %s\n", get_time_dhms(machine.time).c_str());
else {
//sprintf(buf, "; estimated printing time (%s mode) = %s\n",
// (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent",
// get_time_dhms(machine.time).c_str());
sprintf(buf, "; model printing time: %s; total estimated time: %s\n",
get_time_dhms(machine.time - machine.roles_time[ExtrusionRole::erCustom]).c_str(),
get_time_dhms(machine.time).c_str());
}
ret += buf;
}
}
@ -794,6 +804,7 @@ void GCodeProcessorResult::reset() {
extruders_count = 0;
extruder_colors = std::vector<std::string>();
filament_diameters = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER);
required_nozzle_HRC = std::vector<int>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_HRC);
filament_densities = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY);
custom_gcode_per_print_z = std::vector<CustomGCode::Item>();
warnings.clear();
@ -899,14 +910,17 @@ void GCodeProcessor::apply_config(const PrintConfig& config)
m_extruder_offsets.resize(extruders_count);
m_extruder_colors.resize(extruders_count);
m_result.filament_diameters.resize(extruders_count);
m_result.required_nozzle_HRC.resize(extruders_count);
m_result.filament_densities.resize(extruders_count);
m_result.filament_vitrification_temperature.resize(extruders_count);
m_extruder_temps.resize(extruders_count);
m_result.nozzle_hrc = static_cast<int>(config.nozzle_hrc.getInt());
for (size_t i = 0; i < extruders_count; ++ i) {
m_extruder_offsets[i] = to_3d(config.extruder_offset.get_at(i).cast<float>().eval(), 0.f);
m_extruder_colors[i] = static_cast<unsigned char>(i);
m_result.filament_diameters[i] = static_cast<float>(config.filament_diameter.get_at(i));
m_result.required_nozzle_HRC[i] = static_cast<int>(config.required_nozzle_HRC.get_at(i));
m_result.filament_densities[i] = static_cast<float>(config.filament_density.get_at(i));
m_result.filament_vitrification_temperature[i] = static_cast<float>(config.temperature_vitrification.get_at(i));
}
@ -958,6 +972,9 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
if (nozzle_volume != nullptr)
m_nozzle_volume = nozzle_volume->value;
const ConfigOptionInt *nozzle_HRC = config.option<ConfigOptionInt>("nozzle_hrc");
if (nozzle_HRC != nullptr) m_result.nozzle_hrc = nozzle_HRC->value;
const ConfigOptionEnum<GCodeFlavor>* gcode_flavor = config.option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor");
if (gcode_flavor != nullptr)
m_flavor = gcode_flavor->value;
@ -1001,6 +1018,18 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
}
}
const ConfigOptionInts *filament_HRC = config.option<ConfigOptionInts>("required_nozzle_HRC");
if (filament_HRC != nullptr) {
m_result.required_nozzle_HRC.clear();
m_result.required_nozzle_HRC.resize(filament_HRC->values.size());
for (size_t i = 0; i < filament_HRC->values.size(); ++i) { m_result.required_nozzle_HRC[i] = static_cast<float>(filament_HRC->values[i]); }
}
if (m_result.required_nozzle_HRC.size() < m_result.extruders_count) {
for (size_t i = m_result.required_nozzle_HRC.size(); i < m_result.extruders_count; ++i) { m_result.required_nozzle_HRC.emplace_back(DEFAULT_FILAMENT_HRC);
}
}
const ConfigOptionFloats* filament_densities = config.option<ConfigOptionFloats>("filament_density");
if (filament_densities != nullptr) {
m_result.filament_densities.clear();
@ -2720,10 +2749,11 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
get_retract_acceleration(static_cast<PrintEstimatedStatistics::ETimeMode>(i)) :
get_acceleration(static_cast<PrintEstimatedStatistics::ETimeMode>(i)));
//BBS
for (unsigned char a = X; a <= E; ++a) {
float axis_max_acceleration = get_axis_max_acceleration(static_cast<PrintEstimatedStatistics::ETimeMode>(i), static_cast<Axis>(a));
if (acceleration * std::abs(delta_pos[a]) * inv_distance > axis_max_acceleration)
acceleration = axis_max_acceleration;
acceleration = axis_max_acceleration / (std::abs(delta_pos[a]) * inv_distance);
}
block.acceleration = acceleration;
@ -2752,23 +2782,30 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
float v_factor = 1.0f;
bool limited = false;
//BBS: currently jerk in x,y,z axis are combined to one value and be limited together in MC side
//So we only need to handle Z axis
for (unsigned char a = X; a <= E; ++a) {
// Limit an axis. We have to differentiate coasting from the reversal of an axis movement, or a full stop.
//BBS
float jerk = 0;
if (a == X) {
Vec3f exit_v = prev.feedrate * (prev.exit_direction);
exit_v(2, 0) = 0;
if (prev_speed_larger)
exit_v *= smaller_speed_factor;
Vec3f entry_v = block.feedrate_profile.cruise * (curr.enter_direction);
Vec3f jerk_v = entry_v - exit_v;
jerk = jerk_v.norm();
} else if (a == Y || a == Z) {
jerk_v = Vec3f(abs(jerk_v.x()), abs(jerk_v.y()), abs(jerk_v.z()));
Vec3f max_xyz_jerk_v = get_xyz_max_jerk(static_cast<PrintEstimatedStatistics::ETimeMode>(i));
for (size_t i = 0; i < 3; i++)
{
if (jerk_v[i] > max_xyz_jerk_v[i]) {
v_factor *= max_xyz_jerk_v[i] / jerk_v[i];
jerk_v *= v_factor;
limited = true;
}
}
}
else if (a == Y || a == Z) {
continue;
} else {
}
else {
float v_exit = prev.axis_feedrate[a];
float v_entry = curr.axis_feedrate[a];
@ -2781,7 +2818,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
}
// Calculate the jerk depending on whether the axis is coasting in the same direction or reversing a direction.
jerk =
float jerk =
(v_exit > v_entry) ?
(((v_entry > 0.0f) || (v_exit < 0.0f)) ?
// coasting
@ -2794,12 +2831,13 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
(v_entry - v_exit) :
// axis reversal
std::max(-v_exit, v_entry));
}
float axis_max_jerk = get_axis_max_jerk(static_cast<PrintEstimatedStatistics::ETimeMode>(i), static_cast<Axis>(a));
if (jerk > axis_max_jerk) {
v_factor *= axis_max_jerk / jerk;
limited = true;
float axis_max_jerk = get_axis_max_jerk(static_cast<PrintEstimatedStatistics::ETimeMode>(i), static_cast<Axis>(a));
if (jerk > axis_max_jerk) {
v_factor *= axis_max_jerk / jerk;
limited = true;
}
}
}
@ -2866,7 +2904,8 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
}
else if (type == EMoveType::Extrude && m_extrusion_role == erExternalPerimeter) {
m_seams_detector.activate(true);
m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id]);
Vec3f plate_offset = {(float) m_x_offset, (float) m_y_offset, 0.0f};
m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id] - plate_offset);
}
// store move
@ -3147,22 +3186,30 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line)
float v_factor = 1.0f;
bool limited = false;
//BBS: currently jerk in x,y,z axis are combined to one value and be limited together in MC side
//So we only need to handle Z axis
for (unsigned char a = X; a <= E; ++a) {
//BBS: Limit an axis. We have to differentiate coasting from the reversal of an axis movement, or a full stop.
float jerk = 0;
if (a == X) {
Vec3f exit_v = prev.feedrate * (prev.exit_direction);
exit_v(2, 0) = 0;
if (prev_speed_larger)
exit_v *= smaller_speed_factor;
Vec3f entry_v = block.feedrate_profile.cruise * (curr.enter_direction);
Vec3f jerk_v = entry_v - exit_v;
jerk = jerk_v.norm();
} else if (a == Y || a == Z) {
jerk_v = Vec3f(abs(jerk_v.x()), abs(jerk_v.y()), abs(jerk_v.z()));
Vec3f max_xyz_jerk_v = get_xyz_max_jerk(static_cast<PrintEstimatedStatistics::ETimeMode>(i));
for (size_t i = 0; i < 3; i++)
{
if (jerk_v[i] > max_xyz_jerk_v[i]) {
v_factor *= max_xyz_jerk_v[i] / jerk_v[i];
jerk_v *= v_factor;
limited = true;
}
}
}
else if (a == Y || a == Z) {
continue;
} else {
}
else {
float v_exit = prev.axis_feedrate[a];
float v_entry = curr.axis_feedrate[a];
@ -3175,7 +3222,7 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line)
}
//BBS: Calculate the jerk depending on whether the axis is coasting in the same direction or reversing a direction.
jerk =
float jerk =
(v_exit > v_entry) ?
(((v_entry > 0.0f) || (v_exit < 0.0f)) ?
//BBS: coasting
@ -3187,12 +3234,13 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line)
(v_entry - v_exit) :
//BBS: axis reversal
std::max(-v_exit, v_entry));
}
float axis_max_jerk = get_axis_max_jerk(static_cast<PrintEstimatedStatistics::ETimeMode>(i), static_cast<Axis>(a));
if (jerk > axis_max_jerk) {
v_factor *= axis_max_jerk / jerk;
limited = true;
float axis_max_jerk = get_axis_max_jerk(static_cast<PrintEstimatedStatistics::ETimeMode>(i), static_cast<Axis>(a));
if (jerk > axis_max_jerk) {
v_factor *= axis_max_jerk / jerk;
limited = true;
}
}
}
@ -3229,18 +3277,20 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line)
}
//BBS: seam detector
Vec3f plate_offset = {(float) m_x_offset, (float) m_y_offset, 0.0f};
if (m_seams_detector.is_active()) {
//BBS: check for seam starting vertex
if (type == EMoveType::Extrude && m_extrusion_role == erExternalPerimeter && !m_seams_detector.has_first_vertex())
m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id]);
if (type == EMoveType::Extrude && m_extrusion_role == erExternalPerimeter && !m_seams_detector.has_first_vertex()) {
m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id] - plate_offset);
}
//BBS: check for seam ending vertex and store the resulting move
else if ((type != EMoveType::Extrude || (m_extrusion_role != erExternalPerimeter && m_extrusion_role != erOverhangPerimeter)) && m_seams_detector.has_first_vertex()) {
auto set_end_position = [this](const Vec3f& pos) {
m_end_position[X] = pos.x(); m_end_position[Y] = pos.y(); m_end_position[Z] = pos.z();
};
const Vec3f curr_pos(m_end_position[X], m_end_position[Y], m_end_position[Z]);
const Vec3f new_pos = m_result.moves.back().position - m_extruder_offsets[m_extruder_id];
const Vec3f new_pos = m_result.moves.back().position - m_extruder_offsets[m_extruder_id] - plate_offset;
const std::optional<Vec3f> first_vertex = m_seams_detector.get_first_vertex();
//BBS: the threshold value = 0.0625f == 0.25 * 0.25 is arbitrary, we may find some smarter condition later
@ -3255,7 +3305,7 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line)
}
else if (type == EMoveType::Extrude && m_extrusion_role == erExternalPerimeter) {
m_seams_detector.activate(true);
m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id]);
m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id] - plate_offset);
}
//BBS: store move
store_move_vertex(type, m_move_path_type);
@ -3821,7 +3871,7 @@ void GCodeProcessor::store_move_vertex(EMoveType type, EMovePathType path_type)
m_interpolation_points[i] =
Vec3f(m_interpolation_points[i].x() + m_x_offset,
m_interpolation_points[i].y() + m_y_offset,
m_processing_start_custom_gcode ? m_zero_layer_height : m_interpolation_points[i].z()) +
m_processing_start_custom_gcode ? m_first_layer_height : m_interpolation_points[i].z()) +
m_extruder_offsets[m_extruder_id];
}
@ -3832,7 +3882,7 @@ void GCodeProcessor::store_move_vertex(EMoveType type, EMovePathType path_type)
m_extruder_id,
m_cp_color.current,
//BBS: add plate's offset to the rendering vertices
Vec3f(m_end_position[X] + m_x_offset, m_end_position[Y] + m_y_offset, m_processing_start_custom_gcode ? m_zero_layer_height : m_end_position[Z]) + m_extruder_offsets[m_extruder_id],
Vec3f(m_end_position[X] + m_x_offset, m_end_position[Y] + m_y_offset, m_processing_start_custom_gcode ? m_first_layer_height : m_end_position[Z]) + m_extruder_offsets[m_extruder_id],
static_cast<float>(m_end_position[E] - m_start_position[E]),
m_feedrate,
m_width,
@ -3917,6 +3967,13 @@ float GCodeProcessor::get_axis_max_jerk(PrintEstimatedStatistics::ETimeMode mode
}
}
Vec3f GCodeProcessor::get_xyz_max_jerk(PrintEstimatedStatistics::ETimeMode mode) const
{
return Vec3f(get_option_value(m_time_processor.machine_limits.machine_max_jerk_x, static_cast<size_t>(mode)),
get_option_value(m_time_processor.machine_limits.machine_max_jerk_y, static_cast<size_t>(mode)),
get_option_value(m_time_processor.machine_limits.machine_max_jerk_z, static_cast<size_t>(mode)));
}
float GCodeProcessor::get_retract_acceleration(PrintEstimatedStatistics::ETimeMode mode) const
{
size_t id = static_cast<size_t>(mode);
@ -4074,7 +4131,27 @@ void GCodeProcessor::update_slice_warnings()
}
if (!warning.params.empty()) {
warning.msg = BED_TEMP_TOO_HIGH_THAN_FILAMENT;
warning.msg = BED_TEMP_TOO_HIGH_THAN_FILAMENT;
warning.error_code = "1000C001";
m_result.warnings.push_back(warning);
}
//bbs:HRC checker
warning.params.clear();
warning.level=1;
if (m_result.nozzle_hrc!=0) {
for (size_t i = 0; i < used_extruders.size(); i++) {
int HRC=0;
if (used_extruders[i] < m_result.required_nozzle_HRC.size())
HRC = m_result.required_nozzle_HRC[used_extruders[i]];
if (HRC != 0 && (m_result.nozzle_hrc<HRC))
warning.params.push_back(std::to_string(used_extruders[i]));
}
}
if (!warning.params.empty()) {
warning.msg = NOZZLE_HRC_CHECKER;
warning.error_code = "1000C002";
m_result.warnings.push_back(warning);
}

View file

@ -17,7 +17,8 @@
namespace Slic3r {
// slice warnings enum strings
#define BED_TEMP_TOO_HIGH_THAN_FILAMENT "bed_temperature_too_high_than_filament"
#define NOZZLE_HRC_CHECKER "the_actual_nozzle_hrc_smaller_than_the_required_nozzle_hrc"
#define BED_TEMP_TOO_HIGH_THAN_FILAMENT "bed_temperature_too_high_than_filament"
enum class EMoveType : unsigned char
{
@ -86,6 +87,7 @@ namespace Slic3r {
struct GCodeProcessorResult
{
struct SettingsIds
{
std::string print;
@ -134,6 +136,7 @@ namespace Slic3r {
struct SliceWarning {
int level; // 0: normal tips, 1: warning; 2: error
std::string msg; // enum string
std::string error_code; // error code for studio
std::vector<std::string> params; // extra msg info
};
@ -152,12 +155,14 @@ namespace Slic3r {
size_t extruders_count;
std::vector<std::string> extruder_colors;
std::vector<float> filament_diameters;
std::vector<int> required_nozzle_HRC;
std::vector<float> filament_densities;
std::vector<int> filament_vitrification_temperature;
PrintEstimatedStatistics print_statistics;
std::vector<CustomGCode::Item> custom_gcode_per_print_z;
//BBS
std::vector<SliceWarning> warnings;
int nozzle_hrc;
#if ENABLE_GCODE_VIEWER_STATISTICS
int64_t time{ 0 };
@ -578,7 +583,6 @@ namespace Slic3r {
std::vector<Vec3f> m_extruder_offsets;
GCodeFlavor m_flavor;
float m_nozzle_volume;
AxisCoords m_start_position; // mm
AxisCoords m_end_position; // mm
AxisCoords m_origin; // mm
@ -829,6 +833,7 @@ namespace Slic3r {
float get_axis_max_feedrate(PrintEstimatedStatistics::ETimeMode mode, Axis axis) const;
float get_axis_max_acceleration(PrintEstimatedStatistics::ETimeMode mode, Axis axis) const;
float get_axis_max_jerk(PrintEstimatedStatistics::ETimeMode mode, Axis axis) const;
Vec3f get_xyz_max_jerk(PrintEstimatedStatistics::ETimeMode mode) const;
float get_retract_acceleration(PrintEstimatedStatistics::ETimeMode mode) const;
void set_retract_acceleration(PrintEstimatedStatistics::ETimeMode mode, float value);
float get_acceleration(PrintEstimatedStatistics::ETimeMode mode) const;
@ -838,7 +843,6 @@ namespace Slic3r {
float get_filament_load_time(size_t extruder_id);
float get_filament_unload_time(size_t extruder_id);
int get_filament_vitrification_temperature(size_t extrude_id);
void process_custom_gcode_time(CustomGCode::Type code);
void process_filaments(CustomGCode::Type code);

View file

@ -12,6 +12,7 @@ void ThumbnailData::set(unsigned int w, unsigned int h)
width = w;
height = h;
// defaults to white texture
pixels.clear();
pixels = std::vector<unsigned char>(width * height * 4, 255);
}
}

View file

@ -76,6 +76,7 @@ struct PlateBBoxData
bool is_seq_print = false;
int first_extruder = 0;
float nozzle_diameter = 0.4;
std::string bed_type;
// version 1: use view type ColorPrint (filament color)
// version 2: use view type FilamentId (filament id)
int version = 2;
@ -88,6 +89,7 @@ struct PlateBBoxData
j["first_extruder"] = first_extruder;
j["nozzle_diameter"] = nozzle_diameter;
j["version"] = version;
j["bed_type"] = bed_type;
for (const auto& bbox : bbox_objs) {
nlohmann::json j_bbox;
bbox.to_json(j_bbox);
@ -102,6 +104,7 @@ struct PlateBBoxData
j.at("first_extruder").get_to(first_extruder);
j.at("nozzle_diameter").get_to(nozzle_diameter);
j.at("version").get_to(version);
j.at("bed_type").get_to(bed_type);
for (auto& bbox_j : j.at("bbox_objects")) {
BBoxData bbox_data;
bbox_data.from_json(bbox_j);

View file

@ -244,6 +244,45 @@ public:
return (*this);
}
WipeTowerWriter &rectangle_fill_box(const WipeTower* wipe_tower, const Vec2f &ld, float width, float height, const float f = 0.f)
{
bool need_change_flow = wipe_tower->need_thick_bridge_flow(ld.y());
Vec2f corners[4];
corners[0] = ld;
corners[1] = ld + Vec2f(width, 0.f);
corners[2] = ld + Vec2f(width, height);
corners[3] = ld + Vec2f(0.f, height);
int index_of_closest = 0;
if (x() - ld.x() > ld.x() + width - x()) // closer to the right
index_of_closest = 1;
if (y() - ld.y() > ld.y() + height - y()) // closer to the top
index_of_closest = (index_of_closest == 0 ? 3 : 2);
travel(corners[index_of_closest].x(), y()); // travel to the closest corner
travel(x(), corners[index_of_closest].y());
int i = index_of_closest;
bool flow_changed = false;
do {
++i;
if (i == 4) i = 0;
if (need_change_flow) {
if (i == 1) {
// using bridge flow in bridge area, and add notes for gcode-check when flow changed
set_extrusion_flow(wipe_tower->extrusion_flow(0.2));
append(";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height) + std::to_string(0.2) + "\n");
flow_changed = true;
} else if (i == 2 && flow_changed) {
set_extrusion_flow(wipe_tower->get_extrusion_flow());
append(";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height) + std::to_string(m_layer_height) + "\n");
}
}
extrude(corners[i], f);
} while (i != index_of_closest);
return (*this);
}
WipeTowerWriter& rectangle(const WipeTower::box_coordinates& box, const float f = 0.f)
{
rectangle(Vec2f(box.ld.x(), box.ld.y()),
@ -664,7 +703,7 @@ std::vector<WipeTower::ToolChangeResult> WipeTower::prime(
return std::vector<ToolChangeResult>();
}
WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool, bool extrude_perimeter)
WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool, bool extrude_perimeter, bool first_toolchange_to_nonsoluble)
{
size_t old_tool = m_current_tool;
@ -733,6 +772,12 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool, bool extrude_per
writer.rectangle(wt_box);
writer.travel(initial_position);
}
if (first_toolchange_to_nonsoluble) {
writer.travel(Vec2f(0, 0));
writer.travel(initial_position);
}
toolchange_Wipe(writer, cleaning_box, wipe_length); // Wipe the newly loaded filament until the end of the assigned wipe area.
++ m_num_tool_changes;
} else
@ -974,6 +1019,12 @@ void WipeTower::toolchange_Wipe(
// Increase flow on first layer, slow down print.
writer.set_extrusion_flow(m_extrusion_flow * (is_first_layer() ? 1.15f : 1.f))
.append("; CP TOOLCHANGE WIPE\n");
// BBS: add the note for gcode-check, when the flow changed, the width should follow the change
if (is_first_layer()) {
writer.append(";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Width) + std::to_string(1.15 * m_perimeter_width) + "\n");
}
const float& xl = cleaning_box.ld.x();
const float& xr = cleaning_box.rd.x();
@ -1005,6 +1056,7 @@ void WipeTower::toolchange_Wipe(
writer.travel(xl, writer.y() + dy);
#endif
bool need_change_flow = false;
// now the wiping itself:
for (int i = 0; true; ++i) {
if (i!=0) {
@ -1014,11 +1066,24 @@ void WipeTower::toolchange_Wipe(
else wipe_speed = std::min(target_speed, wipe_speed + 50.f);
}
// BBS: check the bridging area and use the bridge flow
if (need_change_flow || need_thick_bridge_flow(writer.y())) {
writer.set_extrusion_flow(extrusion_flow(0.2));
writer.append(";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height) + std::to_string(0.2) + "\n");
need_change_flow = true;
}
if (m_left_to_right)
writer.extrude(xr + 0.25f * m_perimeter_width, writer.y(), wipe_speed);
else
writer.extrude(xl - 0.25f * m_perimeter_width, writer.y(), wipe_speed);
// BBS: recover the flow in non-bridging area
if (need_change_flow) {
writer.set_extrusion_flow(m_extrusion_flow);
writer.append(";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height) + std::to_string(m_layer_height) + "\n");
}
if (writer.y() - float(EPSILON) > cleaning_box.lu.y())
break; // in case next line would not fit
@ -1044,6 +1109,10 @@ void WipeTower::toolchange_Wipe(
m_left_to_right = !m_left_to_right;
writer.set_extrusion_flow(m_extrusion_flow); // Reset the extrusion flow.
// BBS: add the note for gcode-check when the flow changed
if (is_first_layer()) {
writer.append(";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Width) + std::to_string(m_perimeter_width) + "\n");
}
}
@ -1099,7 +1168,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer(bool extrude_perimeter, bool
// inner perimeter of the sparse section, if there is space for it:
if (fill_box.ru.y() - fill_box.rd.y() > m_perimeter_width - WT_EPSILON)
writer.rectangle(fill_box.ld, fill_box.rd.x() - fill_box.ld.x(), fill_box.ru.y() - fill_box.rd.y(), feedrate);
writer.rectangle_fill_box(this, fill_box.ld, fill_box.rd.x() - fill_box.ld.x(), fill_box.ru.y() - fill_box.rd.y(), feedrate);
// we are in one of the corners, travel to ld along the perimeter:
if (writer.x() > fill_box.ld.x() + EPSILON) writer.travel(fill_box.ld.x(), writer.y());
@ -1241,6 +1310,10 @@ void WipeTower::plan_toolchange(float z_par, float layer_height_par, unsigned in
float depth = 0.f;
float width = m_wipe_tower_width - 2 * m_perimeter_width;
// BBS: if the wipe tower width is too small, the depth will be infinity
if (width <= EPSILON)
return;
// BBS: remove old filament ramming and first line
#if 0
float length_to_extrude = volume_to_length(0.25f * std::accumulate(m_filpar[old_tool].ramming_speed.begin(), m_filpar[old_tool].ramming_speed.end(), 0.f),
@ -1518,7 +1591,11 @@ void WipeTower::generate(std::vector<std::vector<WipeTower::ToolChangeResult>> &
finish_layer_tcr = finish_layer(false, layer.extruder_fill);
}
else {
layer_result.emplace_back(tool_change(layer.tool_changes[i].new_tool));
if (idx == -1 && i == 0) {
layer_result.emplace_back(tool_change(layer.tool_changes[i].new_tool, false, true));
} else {
layer_result.emplace_back(tool_change(layer.tool_changes[i].new_tool));
}
}
}
@ -1585,4 +1662,30 @@ WipeTower::ToolChangeResult WipeTower::only_generate_out_wall()
return construct_tcr(writer, false, old_tool, true, 0.f);
}
bool WipeTower::get_floating_area(float &start_pos_y, float &end_pos_y) const {
if (m_layer_info == m_plan.begin() || (m_layer_info - 1) == m_plan.begin())
return false;
float last_layer_fill_box_y = (m_layer_info - 1)->toolchanges_depth() + m_perimeter_width;
float last_layer_wipe_depth = (m_layer_info - 1)->depth;
if (last_layer_wipe_depth - last_layer_fill_box_y <= 2 * m_perimeter_width)
return false;
start_pos_y = last_layer_fill_box_y + m_perimeter_width;
end_pos_y = last_layer_wipe_depth - m_perimeter_width;
return true;
}
bool WipeTower::need_thick_bridge_flow(float pos_y) const {
if (m_extrusion_flow >= extrusion_flow(0.2))
return false;
float y_min = 0., y_max = 0.;
if (get_floating_area(y_min, y_max)) {
return pos_y > y_min && pos_y < y_max;
}
return false;
}
} // namespace Slic3r

View file

@ -217,12 +217,23 @@ public:
// Returns gcode for a toolchange and a final print head position.
// On the first layer, extrude a brim around the future wipe tower first.
// BBS
ToolChangeResult tool_change(size_t new_tool, bool extrude_perimeter = false);
ToolChangeResult tool_change(size_t new_tool, bool extrude_perimeter = false, bool first_toolchange_to_nonsoluble = false);
// Fill the unfilled space with a sparse infill.
// Call this method only if layer_finished() is false.
ToolChangeResult finish_layer(bool extruder_perimeter = true, bool extruder_fill = true);
// Calculates extrusion flow needed to produce required line width for given layer height
float extrusion_flow(float layer_height = -1.f) const // negative layer_height - return current m_extrusion_flow
{
if (layer_height < 0) return m_extrusion_flow;
return layer_height * (m_perimeter_width - layer_height * (1.f - float(M_PI) / 4.f)) / filament_area();
}
bool get_floating_area(float& start_pos_y, float& end_pos_y) const;
bool need_thick_bridge_flow(float pos_y) const;
float get_extrusion_flow() const { return m_extrusion_flow; }
// Is the current layer finished?
bool layer_finished() const {
return m_current_layer_finished;
@ -336,14 +347,6 @@ private:
bool is_first_layer() const { return size_t(m_layer_info - m_plan.begin()) == m_first_layer_idx; }
// Calculates extrusion flow needed to produce required line width for given layer height
float extrusion_flow(float layer_height = -1.f) const // negative layer_height - return current m_extrusion_flow
{
if ( layer_height < 0 )
return m_extrusion_flow;
return layer_height * ( m_perimeter_width - layer_height * (1.f-float(M_PI)/4.f)) / filament_area();
}
// Calculates length of extrusion line to extrude given volume
float volume_to_length(float volume, float line_width, float layer_height) const {
return std::max(0.f, volume / (layer_height * (line_width - layer_height * (1.f - float(M_PI) / 4.f))));

View file

@ -125,13 +125,12 @@ std::string GCodeWriter::set_temperature(unsigned int temperature, bool wait, in
}
// BBS
std::string GCodeWriter::set_bed_temperature(std::vector<int> temps_per_bed, int default_temp, bool wait)
std::string GCodeWriter::set_bed_temperature(int temperature, bool wait)
{
if (temps_per_bed == m_last_bed_temperature && (! wait || m_last_bed_temperature_reached))
if (temperature == m_last_bed_temperature && (! wait || m_last_bed_temperature_reached))
return std::string();
bool target_temp_changed = (temps_per_bed != m_last_bed_temperature);
m_last_bed_temperature = temps_per_bed;
m_last_bed_temperature = temperature;
m_last_bed_temperature_reached = wait;
std::string code, comment;
@ -146,7 +145,7 @@ std::string GCodeWriter::set_bed_temperature(std::vector<int> temps_per_bed, int
comment = "set bed temperature";
}
gcode << code << " S" << default_temp << " ; " << comment << "\n";
gcode << code << " S" << temperature << " ; " << comment << "\n";
return gcode.str();
}

View file

@ -43,8 +43,7 @@ public:
std::string preamble();
std::string postamble() const;
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1) const;
// BBS
std::string set_bed_temperature(std::vector<int> temps_per_bed, int default_temp, bool wait = false);
std::string set_bed_temperature(int temperature, bool wait = false);
std::string set_acceleration(unsigned int acceleration);
std::string set_jerk_xy(unsigned int jerk);
std::string set_pressure_advance(double pa) const;
@ -114,8 +113,7 @@ private:
//BBS
unsigned int m_last_additional_fan_speed;
// BBS
std::vector<int> m_last_bed_temperature;
int m_last_bed_temperature;
bool m_last_bed_temperature_reached;
double m_lifted;

View file

@ -65,7 +65,7 @@ public:
// ordered collection of extrusion paths to fill surfaces
// (this collection contains only ExtrusionEntityCollection objects)
ExtrusionEntityCollection fills;
Flow flow(FlowRole role) const;
Flow flow(FlowRole role, double layer_height) const;
Flow bridging_flow(FlowRole role, bool thick_bridge = false) const;
@ -110,7 +110,7 @@ private:
const PrintRegion *m_region;
};
class Layer
class Layer
{
public:
// Sequential index of this layer in PrintObject::m_layers, offsetted by the number of raft layers.
@ -132,7 +132,7 @@ public:
mutable ExPolygons cantilevers;
mutable std::map<const ExPolygon*, float> sharp_tails_height;
// Collection of expolygons generated by slicing the possibly multiple meshes of the source geometry
// Collection of expolygons generated by slicing the possibly multiple meshes of the source geometry
// (with possibly differing extruder ID and slicing parameters) and merged.
// For the first layer, if the Elephant foot compensation is applied, this lslice is uncompensated, therefore
// it includes the Elephant foot effect, thus it corresponds to the shape of the printed 1st layer.
@ -149,7 +149,7 @@ public:
LayerRegion* add_region(const PrintRegion *print_region);
const LayerRegionPtrs& regions() const { return m_regions; }
// Test whether whether there are any slices assigned to this layer.
bool empty() const;
bool empty() const;
void make_slices();
// Backup and restore raw sliced regions if needed.
//FIXME Review whether not to simplify the code by keeping the raw_slices all the time.
@ -209,7 +209,7 @@ private:
LayerRegionPtrs m_regions;
};
class SupportLayer : public Layer
class SupportLayer : public Layer
{
public:
// Polygons covered by the supports: base, interface and contact areas.
@ -248,14 +248,22 @@ public:
ExPolygons roof_1st_layer; // the layer just below roof. When working with PolySupport, this layer should be printed with regular material
ExPolygons floor_areas;
ExPolygons base_areas;
ExPolygons roof_gap_areas; // the areas in the gap between support roof and overhang
enum AreaType {
enum AreaType {
BaseType=0,
RoofType=1,
FloorType=2,
Roof1stLayer=3
};
std::vector<std::pair<ExPolygon *, int>> area_groups;
struct AreaGroup
{
ExPolygon *area;
int type;
int dist_to_top;
AreaGroup(ExPolygon *a, int t, int d) : area(a), type(t), dist_to_top(d) {}
};
std::vector<AreaGroup> area_groups;
enum OverhangType {
Detected=0,

View file

@ -105,8 +105,11 @@ void LayerRegion::make_perimeters(const SurfaceCollection &slices, SurfaceCollec
g.ext_perimeter_flow = this->flow(frExternalPerimeter);
g.overhang_flow = this->bridging_flow(frPerimeter, object_config.thick_bridges);
g.solid_infill_flow = this->flow(frSolidInfill);
g.process();
if (this->layer()->object()->config().wall_generator.value == PerimeterGeneratorType::Arachne && !spiral_mode)
g.process_arachne();
else
g.process_classic();
}
//#define EXTERNAL_SURFACES_OFFSET_PARAMETERS ClipperLib::jtMiter, 3.
@ -225,7 +228,9 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly
break;
}
// Grown by 3mm.
Polygons polys = offset(bridges[i].expolygon, bridge_margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS);
//BBS: eliminate too narrow area to avoid generating bridge on top layer when wall loop is 1
//Polygons polys = offset(bridges[i].expolygon, bridge_margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS);
Polygons polys = offset2({ bridges[i].expolygon }, -scale_(nozzle_diameter * 0.1), bridge_margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS);
if (idx_island == -1) {
BOOST_LOG_TRIVIAL(trace) << "Bridge did not fall into the source region!";
} else {

View file

@ -14,6 +14,7 @@
#include "Format/OBJ.hpp"
#include "Format/STL.hpp"
#include "Format/STEP.hpp"
#include "Format/svg.hpp"
// BBS
#include "FaceDetector.hpp"
@ -137,7 +138,7 @@ Model::~Model()
// Loading model from a file, it may be a simple geometry file as STL or OBJ, however it may be a project file as well.
Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* config, ConfigSubstitutionContext* config_substitutions,
LoadStrategy options, PlateDataPtrs* plate_data, std::vector<Preset*>* project_presets, bool *is_xxx, Semver* file_version, Import3mfProgressFn proFn,
ImportstlProgressFn stlFn, ImportStepProgressFn stepFn, StepIsUtf8Fn stepIsUtf8Fn, BBLProject* project)
ImportstlProgressFn stlFn, ImportStepProgressFn stepFn, StepIsUtf8Fn stepIsUtf8Fn, BBLProject* project, int plate_id)
{
Model model;
@ -159,6 +160,7 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c
file_version = &temp_version;
bool result = false;
std::string message;
if (boost::algorithm::iends_with(input_file, ".stp") ||
boost::algorithm::iends_with(input_file, ".step"))
result = load_step(input_file.c_str(), &model, stepFn, stepIsUtf8Fn);
@ -166,6 +168,8 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c
result = load_stl(input_file.c_str(), &model, nullptr, stlFn);
else if (boost::algorithm::iends_with(input_file, ".obj"))
result = load_obj(input_file.c_str(), &model);
else if (boost::algorithm::iends_with(input_file, ".svg"))
result = load_svg(input_file.c_str(), &model, message);
//BBS: remove the old .amf.xml files
//else if (boost::algorithm::iends_with(input_file, ".amf") || boost::algorithm::iends_with(input_file, ".amf.xml"))
else if (boost::algorithm::iends_with(input_file, ".amf"))
@ -176,12 +180,16 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c
// BBS: backup & restore
//FIXME options & LoadStrategy::CheckVersion ?
//BBS: is_xxx is used for is_bbs_3mf when load 3mf
result = load_bbs_3mf(input_file.c_str(), config, config_substitutions, &model, plate_data, project_presets, is_xxx, file_version, proFn, options, project);
result = load_bbs_3mf(input_file.c_str(), config, config_substitutions, &model, plate_data, project_presets, is_xxx, file_version, proFn, options, project, plate_id);
else
throw Slic3r::RuntimeError("Unknown file format. Input file must have .stl, .obj, .amf(.xml) extension.");
if (! result)
throw Slic3r::RuntimeError("Loading of a model file failed.");
if (!result) {
if (message.empty())
throw Slic3r::RuntimeError("Loading of a model file failed.");
else
throw Slic3r::RuntimeError(message);
}
if (model.objects.empty())
throw Slic3r::RuntimeError("The supplied file couldn't be read because it's empty");
@ -203,7 +211,8 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c
//BBS: add part plate related logic
// BBS: backup & restore
// Loading model from a file (3MF or AMF), not from a simple geometry file (STL or OBJ).
Model Model::read_from_archive(const std::string& input_file, DynamicPrintConfig* config, ConfigSubstitutionContext* config_substitutions, En3mfType& out_file_type, LoadStrategy options, PlateDataPtrs* plate_data, std::vector<Preset*>* project_presets, Semver* file_version, Import3mfProgressFn proFn, BBLProject *project)
Model Model::read_from_archive(const std::string& input_file, DynamicPrintConfig* config, ConfigSubstitutionContext* config_substitutions, En3mfType& out_file_type, LoadStrategy options,
PlateDataPtrs* plate_data, std::vector<Preset*>* project_presets, Semver* file_version, Import3mfProgressFn proFn, BBLProject *project)
{
assert(config != nullptr);
assert(config_substitutions != nullptr);
@ -2911,13 +2920,14 @@ double getTemperatureFromExtruder(const ModelVolumePtrs objectVolumes) {
double ModelInstance::get_auto_brim_width() const
{
return 0.;
double adhcoeff = getadhesionCoeff(object->volumes);
double DeltaT = getTemperatureFromExtruder(object->volumes);
// get auto brim width (Note even if the global brim_type=btOuterBrim, we can still go into this branch)
return get_auto_brim_width(DeltaT, adhcoeff);
}
void ModelInstance::get_arrange_polygon(void* ap) const
void ModelInstance::get_arrange_polygon(void *ap, const Slic3r::DynamicPrintConfig &config_global) const
{
// static const double SIMPLIFY_TOLERANCE_MM = 0.1;
@ -2956,6 +2966,16 @@ void ModelInstance::get_arrange_polygon(void* ap) const
ret.extrude_ids = volume->get_extruders();
if (ret.extrude_ids.empty()) //the default extruder
ret.extrude_ids.push_back(1);
// get per-object support extruders
auto op = object->get_config_value<ConfigOptionBool>(config_global, "enable_support");
bool is_support_enabled = op && op->getBool();
if (is_support_enabled) {
auto op1 = object->get_config_value<ConfigOptionInt>(config_global, "support_filament");
auto op2 = object->get_config_value<ConfigOptionInt>(config_global, "support_interface_filament");
if (op1) ret.extrude_ids.push_back(op1->getInt());
if (op2) ret.extrude_ids.push_back(op2->getInt());
}
}
indexed_triangle_set FacetsAnnotation::get_facets(const ModelVolume& mv, EnforcerBlockerType type) const

View file

@ -1050,7 +1050,7 @@ public:
// BBS
void set_offset_to_assembly(const Vec3d& offset) { m_offset_to_assembly = offset; }
Vec3d get_offset_to_assembly() { return m_offset_to_assembly; }
Vec3d get_offset_to_assembly() const { return m_offset_to_assembly; }
const Vec3d& get_offset() const { return m_transformation.get_offset(); }
double get_offset(Axis axis) const { return m_transformation.get_offset(axis); }
@ -1111,7 +1111,7 @@ public:
// Getting the input polygon for arrange
// We use void* as input type to avoid including Arrange.hpp in Model.hpp.
void get_arrange_polygon(void* arrange_polygon) const;
void get_arrange_polygon(void *arrange_polygon, const Slic3r::DynamicPrintConfig &config = Slic3r::DynamicPrintConfig()) const;
// Apply the arrange result on the ModelInstance
void apply_arrange_result(const Vec2d& offs, double rotation)
@ -1213,6 +1213,7 @@ struct GlobalSpeedMap
double supportSpeed;
double smallPerimeterSpeed;
double maxSpeed;
Polygon bed_poly;
};
/* info in ModelDesignInfo can not changed after initialization */
@ -1234,12 +1235,15 @@ public:
std::string copyright; // utf8 format
std::string model_name; // utf8 format
std::map<std::string, std::string> metadata_items; // other meta data items
void load(ModelInfo &info) {
this->cover_file = info.cover_file;
this->license = info.license;
this->description = info.description;
this->copyright = info.copyright;
this->model_name = info.model_name;
this->metadata_items = info.metadata_items;
}
};
@ -1300,11 +1304,12 @@ public:
DynamicPrintConfig* config = nullptr, ConfigSubstitutionContext* config_substitutions = nullptr,
LoadStrategy options = LoadStrategy::AddDefaultInstances, PlateDataPtrs* plate_data = nullptr,
std::vector<Preset*>* project_presets = nullptr, bool* is_xxx = nullptr, Semver* file_version = nullptr, Import3mfProgressFn proFn = nullptr,
ImportstlProgressFn stlFn = nullptr, ImportStepProgressFn stepFn = nullptr, StepIsUtf8Fn stepIsUtf8Fn = nullptr, BBLProject* project = nullptr);
ImportstlProgressFn stlFn = nullptr, ImportStepProgressFn stepFn = nullptr, StepIsUtf8Fn stepIsUtf8Fn = nullptr, BBLProject* project = nullptr, int plate_id = 0);
// BBS
static double findMaxSpeed(const ModelObject* object);
static double getThermalLength(const ModelVolume* modelVolumePtr);
static double getThermalLength(const std::vector<ModelVolume*> modelVolumePtrs);
static Polygon getBedPolygon() { return Model::printSpeedMap.bed_poly; }
// BBS: backup
static Model read_from_archive(

View file

@ -88,9 +88,9 @@ void duplicate_objects(Model &model, size_t copies_num)
// Set up arrange polygon for a ModelInstance and Wipe tower
template<class T>
arrangement::ArrangePolygon get_arrange_poly(T obj)
arrangement::ArrangePolygon get_arrange_poly(T obj, const Slic3r::DynamicPrintConfig& config)
{
ArrangePolygon ap = obj.get_arrange_polygon();
ArrangePolygon ap = obj.get_arrange_polygon(config);
//BBS: always set bed_idx to 0 to use original transforms with no bed_idx
//if this object is not arranged, it can keep the original transforms
//ap.bed_idx = ap.translation.x() / bed_stride_x(plater);
@ -110,14 +110,14 @@ arrangement::ArrangePolygon get_arrange_poly(T obj)
}
template<>
arrangement::ArrangePolygon get_arrange_poly(ModelInstance* inst)
arrangement::ArrangePolygon get_arrange_poly(ModelInstance* inst, const Slic3r::DynamicPrintConfig& config)
{
return get_arrange_poly(PtrWrapper{ inst });
return get_arrange_poly(PtrWrapper{ inst },config);
}
ArrangePolygon get_instance_arrange_poly(ModelInstance* instance, const Slic3r::DynamicPrintConfig& config)
{
ArrangePolygon ap = get_arrange_poly(PtrWrapper{ instance });
ArrangePolygon ap = get_arrange_poly(PtrWrapper{ instance }, config);
//BBS: add temperature information
if (config.has("curr_bed_type")) {
@ -127,24 +127,25 @@ ArrangePolygon get_instance_arrange_poly(ModelInstance* instance, const Slic3r::
const ConfigOptionInts* bed_opt = config.option<ConfigOptionInts>(get_bed_temp_key(curr_bed_type));
if (bed_opt != nullptr)
ap.bed_temp = bed_opt->get_at(ap.extrude_ids.back()-1);
ap.bed_temp = bed_opt->get_at(ap.extrude_ids.front()-1);
const ConfigOptionInts* bed_opt_1st_layer = config.option<ConfigOptionInts>(get_bed_temp_1st_layer_key(curr_bed_type));
if (bed_opt_1st_layer != nullptr)
ap.first_bed_temp = bed_opt_1st_layer->get_at(ap.extrude_ids.back()-1);
ap.first_bed_temp = bed_opt_1st_layer->get_at(ap.extrude_ids.front()-1);
}
if (config.has("nozzle_temperature")) //get the print temperature
ap.print_temp = config.opt_int("nozzle_temperature", ap.extrude_ids.back() - 1);
ap.print_temp = config.opt_int("nozzle_temperature", ap.extrude_ids.front() - 1);
if (config.has("nozzle_temperature_initial_layer")) //get the nozzle_temperature_initial_layer
ap.first_print_temp = config.opt_int("nozzle_temperature_initial_layer", ap.extrude_ids.back() - 1);
ap.first_print_temp = config.opt_int("nozzle_temperature_initial_layer", ap.extrude_ids.front() - 1);
if (config.has("temperature_vitrification")) {
ap.vitrify_temp = config.opt_int("temperature_vitrification", ap.extrude_ids.back() - 1);
ap.vitrify_temp = config.opt_int("temperature_vitrification", ap.extrude_ids.front() - 1);
}
// get brim width
auto obj = instance->get_object();
#if 0
ap.brim_width = instance->get_auto_brim_width();
auto brim_type_ptr = obj->get_config_value<ConfigOptionEnum<BrimType>>(config, "brim_type");
if (brim_type_ptr) {
@ -154,7 +155,9 @@ ArrangePolygon get_instance_arrange_poly(ModelInstance* instance, const Slic3r::
else if (brim_type == btNoBrim)
ap.brim_width = 0;
}
#else
ap.brim_width = 0;
#endif
ap.height = obj->bounding_box().size().z();
ap.name = obj->name;

View file

@ -71,10 +71,10 @@ template<class T> struct PtrWrapper
explicit PtrWrapper(T* p) : ptr{ p } {}
arrangement::ArrangePolygon get_arrange_polygon() const
arrangement::ArrangePolygon get_arrange_polygon(const Slic3r::DynamicPrintConfig &config = Slic3r::DynamicPrintConfig()) const
{
arrangement::ArrangePolygon ap;
ptr->get_arrange_polygon(&ap);
ptr->get_arrange_polygon(&ap, config);
return ap;
}
@ -86,12 +86,12 @@ template<class T> struct PtrWrapper
};
template<class T>
arrangement::ArrangePolygon get_arrange_poly(T obj);
arrangement::ArrangePolygon get_arrange_poly(T obj, const DynamicPrintConfig &config = DynamicPrintConfig());
template<>
arrangement::ArrangePolygon get_arrange_poly(ModelInstance* inst);
arrangement::ArrangePolygon get_arrange_poly(ModelInstance* inst, const DynamicPrintConfig& config);
ArrangePolygon get_instance_arrange_poly(ModelInstance* instance, const Slic3r::DynamicPrintConfig& config);
ArrangePolygon get_instance_arrange_poly(ModelInstance* instance, const DynamicPrintConfig& config);
}
#endif // MODELARRANGE_HPP

View file

@ -1100,8 +1100,12 @@ static MMU_Graph build_graph(size_t layer_idx, const std::vector<std::vector<Col
return graph;
}
static inline Polygon to_polygon(const std::vector<Linef> &lines)
static inline Polygon to_polygon(const std::vector<std::pair<size_t, Linef>> &id_to_lines)
{
std::vector<Linef> lines;
for (auto id_to_line : id_to_lines)
lines.emplace_back(id_to_line.second);
Polygon poly_out;
poly_out.points.reserve(lines.size());
for (const Linef &line : lines)
@ -1109,6 +1113,112 @@ static inline Polygon to_polygon(const std::vector<Linef> &lines)
return poly_out;
}
static std::vector<std::vector<const MMU_Graph::Arc *>> get_all_next_arcs(
const MMU_Graph &graph,
std::vector<bool> &used_arcs,
const Linef &process_line,
const MMU_Graph::Arc &original_arc,
const int color)
{
std::vector<std::vector<const MMU_Graph::Arc *>> all_next_arcs;
for (const size_t &arc_idx : graph.nodes[original_arc.to_idx].arc_idxs) {
std::vector<const MMU_Graph::Arc *> next_continue_arc;
const MMU_Graph::Arc & arc = graph.arcs[arc_idx];
if (graph.nodes[arc.to_idx].point == process_line.a || used_arcs[arc_idx])
continue;
if (original_arc.type == MMU_Graph::ARC_TYPE::BORDER && original_arc.color != color)
continue;
if (arc.type == MMU_Graph::ARC_TYPE::BORDER && arc.color != color)
continue;
Vec2d arc_line = graph.nodes[arc.to_idx].point - graph.nodes[arc.from_idx].point;
if (arc_line.norm() < 5) { // two points whose distance is less than 5 are considered as one point
Linef process_line_1(graph.nodes[arc.from_idx].point, graph.nodes[arc.to_idx].point);
std::vector<std::vector<const MMU_Graph::Arc *>> next_arcs = get_all_next_arcs(graph, used_arcs, process_line_1, arc, color);
if (next_arcs.empty())
continue;
for (std::vector<const MMU_Graph::Arc *> &next_arc : next_arcs) {
next_continue_arc.emplace_back(&arc);
next_continue_arc.insert(next_continue_arc.end(), next_arc.begin(), next_arc.end());
all_next_arcs.emplace_back(next_continue_arc);
}
} else {
next_continue_arc.emplace_back(&arc);
all_next_arcs.emplace_back(next_continue_arc);
}
}
return all_next_arcs;
}
// two points that are very close are considered as one point
// std::vector contain the close points
static std::vector<const MMU_Graph::Arc *> get_next_arc(
const MMU_Graph &graph,
std::vector<bool> &used_arcs,
const Linef &process_line,
const MMU_Graph::Arc &original_arc,
const int color)
{
std::vector<const MMU_Graph::Arc *> res;
std::vector<std::vector<const MMU_Graph::Arc *>> all_next_arcs = get_all_next_arcs(graph, used_arcs, process_line, original_arc, color);
if (all_next_arcs.empty()) {
res.emplace_back(&original_arc);
return res;
}
std::vector<std::pair<std::vector<const MMU_Graph::Arc *>, double>> sorted_arcs;
for (auto next_arc : all_next_arcs) {
if (next_arc.empty())
continue;
Vec2d process_line_vec_n = (process_line.a - process_line.b).normalized();
Vec2d neighbour_line_vec_n = (graph.nodes[next_arc.back()->to_idx].point - graph.nodes[next_arc.back()->from_idx].point).normalized();
double angle = ::acos(std::clamp(neighbour_line_vec_n.dot(process_line_vec_n), -1.0, 1.0));
if (Slic3r::cross2(neighbour_line_vec_n, process_line_vec_n) < 0.0)
angle = 2.0 * (double) PI - angle;
sorted_arcs.emplace_back(next_arc, angle);
}
std::sort(sorted_arcs.begin(), sorted_arcs.end(),
[](std::pair<std::vector<const MMU_Graph::Arc *>, double> &l, std::pair<std::vector<const MMU_Graph::Arc *>, double> &r) -> bool {
return l.second < r.second;
});
// Try to return left most edge witch is unused
for (auto &sorted_arc : sorted_arcs) {
if (size_t arc_idx = sorted_arc.first.back() - &graph.arcs.front(); !used_arcs[arc_idx])
return sorted_arc.first;
}
if (sorted_arcs.empty()) {
res.emplace_back(&original_arc);
return res;
}
return sorted_arcs.front().first;
}
static bool is_profile_self_interaction(Polygon poly)
{
auto lines = poly.lines();
Point intersection;
for (int i = 0; i < lines.size(); ++i) {
for (int j = i + 2; j < std::min(lines.size(), lines.size() + i - 1); ++j) {
if (lines[i].intersection(lines[j], &intersection))
return true;
}
}
return false;
}
// Returns list of polygons and assigned colors.
// It iterates through all nodes on the border between two different colors, and from this point,
// start selection always left most edges for every node to construct CCW polygons.
@ -1116,43 +1226,7 @@ static inline Polygon to_polygon(const std::vector<Linef> &lines)
static std::vector<ExPolygons> extract_colored_segments(const MMU_Graph &graph, const size_t num_extruders)
{
std::vector<bool> used_arcs(graph.arcs.size(), false);
// When there is no next arc, then is returned original_arc or edge with is marked as used
auto get_next = [&graph, &used_arcs](const Linef &process_line, const MMU_Graph::Arc &original_arc, const int color) -> const MMU_Graph::Arc & {
std::vector<std::pair<const MMU_Graph::Arc *, double>> sorted_arcs;
for (const size_t &arc_idx : graph.nodes[original_arc.to_idx].arc_idxs) {
const MMU_Graph::Arc &arc = graph.arcs[arc_idx];
if (graph.nodes[arc.to_idx].point == process_line.a || used_arcs[arc_idx])
continue;
// BBS
if (original_arc.type == MMU_Graph::ARC_TYPE::BORDER && original_arc.color != color)
continue;
assert(original_arc.to_idx == arc.from_idx);
Vec2d process_line_vec_n = (process_line.a - process_line.b).normalized();
Vec2d neighbour_line_vec_n = (graph.nodes[arc.to_idx].point - graph.nodes[arc.from_idx].point).normalized();
double angle = ::acos(std::clamp(neighbour_line_vec_n.dot(process_line_vec_n), -1.0, 1.0));
if (Slic3r::cross2(neighbour_line_vec_n, process_line_vec_n) < 0.0)
angle = 2.0 * (double) PI - angle;
sorted_arcs.emplace_back(&arc, angle);
}
std::sort(sorted_arcs.begin(), sorted_arcs.end(),
[](std::pair<const MMU_Graph::Arc *, double> &l, std::pair<const MMU_Graph::Arc *, double> &r) -> bool { return l.second < r.second; });
// Try to return left most edge witch is unused
for (auto &sorted_arc : sorted_arcs)
if (size_t arc_idx = sorted_arc.first - &graph.arcs.front(); !used_arcs[arc_idx])
return *sorted_arc.first;
if (sorted_arcs.empty())
return original_arc;
return *(sorted_arcs.front().first);
};
auto all_arc_used = [&used_arcs](const MMU_Graph::Node &node) -> bool {
return std::all_of(node.arc_idxs.cbegin(), node.arc_idxs.cend(), [&used_arcs](const size_t &arc_idx) -> bool { return used_arcs[arc_idx]; });
};
@ -1166,29 +1240,58 @@ static std::vector<ExPolygons> extract_colored_segments(const MMU_Graph &graph,
if (arc.type == MMU_Graph::ARC_TYPE::NON_BORDER || used_arcs[arc_idx])
continue;
Linef process_line(node.point, graph.nodes[arc.to_idx].point);
Linef process_line(graph.nodes[arc.from_idx].point, graph.nodes[arc.to_idx].point);
used_arcs[arc_idx] = true;
std::vector<Linef> face_lines;
face_lines.emplace_back(process_line);
std::vector<std::pair<size_t, Linef>> arc_id_to_face_lines;
arc_id_to_face_lines.emplace_back(std::make_pair(arc_idx, process_line));
Vec2d start_p = process_line.a;
Linef p_vec = process_line;
const MMU_Graph::Arc *p_arc = &arc;
bool flag = false;
do {
const MMU_Graph::Arc& next = get_next(p_vec, *p_arc, arc.color);
size_t next_arc_idx = &next - &graph.arcs.front();
face_lines.emplace_back(graph.nodes[next.from_idx].point, graph.nodes[next.to_idx].point);
if (used_arcs[next_arc_idx])
std::vector<const MMU_Graph::Arc *> nexts = get_next_arc(graph, used_arcs, p_vec, *p_arc, arc.color);
for (auto next : nexts) {
size_t next_arc_idx = next - &graph.arcs.front();
if (used_arcs[next_arc_idx]) {
flag = true;
break;
}
}
if (flag)
break;
used_arcs[next_arc_idx] = true;
p_vec = Linef(graph.nodes[next.from_idx].point, graph.nodes[next.to_idx].point);
p_arc = &next;
for (auto next : nexts) {
size_t next_arc_idx = next - &graph.arcs.front();
arc_id_to_face_lines.emplace_back(std::make_pair(next_arc_idx, Linef(graph.nodes[next->from_idx].point, graph.nodes[next->to_idx].point)));
used_arcs[next_arc_idx] = true;
}
p_vec = Linef(graph.nodes[nexts.back()->from_idx].point, graph.nodes[nexts.back()->to_idx].point);
p_arc = nexts.back();
} while (graph.nodes[p_arc->to_idx].point != start_p || !all_arc_used(graph.nodes[p_arc->to_idx]));
if (Polygon poly = to_polygon(face_lines); poly.is_counter_clockwise() && poly.is_valid())
if (Polygon poly = to_polygon(arc_id_to_face_lines); poly.is_counter_clockwise() && poly.is_valid()) {
expolygons_segments[arc.color].emplace_back(std::move(poly));
} else{
while (arc_id_to_face_lines.size() > 1)
{
auto id_to_line = arc_id_to_face_lines.back();
used_arcs[id_to_line.first] = false;
arc_id_to_face_lines.pop_back();
Linef add_line(arc_id_to_face_lines.back().second.b, arc_id_to_face_lines.front().second.a);
arc_id_to_face_lines.emplace_back(std::make_pair(-1, add_line));
Polygon poly = to_polygon(arc_id_to_face_lines);
if (!is_profile_self_interaction(poly) && poly.is_counter_clockwise() && poly.is_valid()) {
expolygons_segments[arc.color].emplace_back(std::move(poly));
break;
}
arc_id_to_face_lines.pop_back();
}
}
}
}
return expolygons_segments;

View file

@ -57,16 +57,19 @@ namespace orientation {
// management and spatial index structures for acceleration.
class AutoOrienter {
public:
int face_count_hull;
OrientMesh *orient_mesh = NULL;
TriangleMesh* mesh;
TriangleMesh mesh_convex_hull;
Eigen::MatrixXf normals, normals_hull;
Eigen::MatrixXf normals, normals_quantize, normals_hull, normals_hull_quantize;
Eigen::VectorXf areas, areas_hull;
Eigen::VectorXf is_apperance; // whether a facet is outer apperance
Eigen::MatrixXf z_projected;
Eigen::VectorXf z_max, z_max_hull; // max of projected z
Eigen::VectorXf z_median; // median of projected z
Eigen::VectorXf z_mean; // mean of projected z
std::vector<Vec3f> face_normals;
std::vector<Vec3f> face_normals_hull;
OrientParams params;
@ -111,9 +114,9 @@ public:
{
orientations = { { 0,0,-1 } }; // original orientation
area_cumulation(normals, areas);
area_cumulation_accurate(face_normals, normals_quantize, areas, 10);
area_cumulation(normals_hull, areas_hull, 10);
area_cumulation_accurate(face_normals_hull, normals_hull_quantize, areas_hull, 10);
add_supplements();
@ -152,8 +155,23 @@ public:
if (progressind)
progressind(80);
//To avoid flipping, we need to verify if there are orientations with same unprintability.
Vec3f n1 = {0, 0, 1};
auto best_orientation = results_vector[0].first;
for (int i = 1; i< results_vector.size()-1; i++) {
if (abs(results_vector[i].second.unprintability - results_vector[0].second.unprintability) < EPSILON && abs(results_vector[0].first.dot(n1)-1) > EPSILON) {
if (abs(results_vector[i].first.dot(n1)-1) < EPSILON*EPSILON) {
best_orientation = n1;
break;
}
}
else {
break;
}
}
BOOST_LOG_TRIVIAL(info) << std::fixed << std::setprecision(6) << "best:" << best_orientation.transpose() << ", costs:" << results_vector[0].second.field_values();
std::cout << std::fixed << std::setprecision(6) << "best:" << best_orientation.transpose() << ", costs:" << results_vector[0].second.field_values() << std::endl;
@ -166,17 +184,16 @@ public:
{
int face_count = mesh->facets_count();
auto its = mesh->its;
auto face_normals = its_face_normals(its);
face_normals = its_face_normals(its);
areas = Eigen::VectorXf::Zero(face_count);
is_apperance = Eigen::VectorXf::Zero(face_count);
normals = Eigen::MatrixXf::Zero(face_count, 3);
normals_quantize = Eigen::MatrixXf::Zero(face_count, 3);
for (size_t i = 0; i < face_count; i++)
{
float area = its.facet_area(i);
if (params.NEGL_FACE_SIZE > 0 && area < params.NEGL_FACE_SIZE)
continue;
normals.row(i) = quantize_vec3f(face_normals[i]);
normals.row(i) = face_normals[i];
normals_quantize.row(i) = quantize_vec3f(face_normals[i]);
areas(i) = area;
is_apperance(i) = (its.get_property(i).type == EnumFaceTypes::eExteriorAppearance);
count_apperance += (is_apperance(i)==1);
@ -193,15 +210,17 @@ public:
int face_count = mesh_convex_hull.facets_count();
auto its = mesh_convex_hull.its;
auto face_normals = its_face_normals(its);
face_count_hull = mesh_convex_hull.facets_count();
face_normals_hull = its_face_normals(its);
areas_hull = Eigen::VectorXf::Zero(face_count);
normals_hull = Eigen::MatrixXf::Zero(face_count, 3);
normals_hull = Eigen::MatrixXf::Zero(face_count_hull, 3);
normals_hull_quantize = Eigen::MatrixXf::Zero(face_count_hull, 3);
for (size_t i = 0; i < face_count; i++)
{
float area = its.facet_area(i);
if (params.NEGL_FACE_SIZE > 0 && area < params.NEGL_FACE_SIZE)
continue;
normals_hull.row(i) = quantize_vec3f(face_normals[i]);
//We cannot use quantized vector here, the accumulated error will result in bad orientations.
normals_hull.row(i) = face_normals_hull[i];
normals_hull_quantize.row(i) = quantize_vec3f(face_normals_hull[i]);
areas_hull(i) = area;
}
}
@ -227,10 +246,41 @@ public:
for (size_t i = 0; i < num_directions; i++)
{
orientations.push_back(align_counts[i].first);
//orientations.push_back(its_face_normals(mesh->its)[i]);
BOOST_LOG_TRIVIAL(debug) << align_counts[i].first.transpose() << ", area: " << align_counts[i].second;
}
}
//This function is to make sure to return the accurate normal rather than quantized normal
void area_cumulation_accurate( std::vector<Vec3f>& normals_, const Eigen::MatrixXf& quantize_normals_, const Eigen::VectorXf& areas_, int num_directions = 10)
{
std::unordered_map<stl_normal, std::pair<std::vector<float>, Vec3f>, VecHash> alignments_;
Vec3f n1 = { 0, 0, 0 };
std::vector<float> current_areas = {0, 0};
// init to 0
for (size_t i = 0; i < areas_.size(); i++) {
alignments_.insert(std::pair(quantize_normals_.row(i), std::pair(current_areas, n1)));
}
// cumulate areas
for (size_t i = 0; i < areas_.size(); i++)
{
alignments_[quantize_normals_.row(i)].first[1] += areas_(i);
if (areas_(i) > alignments_[quantize_normals_.row(i)].first[0]){
alignments_[quantize_normals_.row(i)].second = normals_[i];
alignments_[quantize_normals_.row(i)].first[0] = areas_(i);
}
}
typedef std::pair<stl_normal, std::pair<std::vector<float>, Vec3f>> PAIR;
std::vector<PAIR> align_counts(alignments_.begin(), alignments_.end());
sort(align_counts.begin(), align_counts.end(), [](const PAIR& p1, const PAIR& p2) {return p1.second.first[1] > p2.second.first[1]; });
num_directions = std::min((size_t)num_directions, align_counts.size());
for (size_t i = 0; i < num_directions; i++)
{
orientations.push_back(align_counts[i].second.second);
BOOST_LOG_TRIVIAL(debug) << align_counts[i].second.second.transpose() << ", area: " << align_counts[i].second.first[1];
}
}
void add_supplements()
{
std::vector<Vec3f> vecs = { {0, 0, -1} ,{0.70710678, 0, -0.70710678},{0, 0.70710678, -0.70710678},
@ -246,7 +296,7 @@ public:
/// remove duplicate orientations
/// </summary>
/// <param name="tol">tolerance. default 0.01 =sin(0.57\degree)</param>
void remove_duplicates(float tol=0.01)
void remove_duplicates(double tol=0.0000001)
{
for (auto it = orientations.begin()+1; it < orientations.end(); )
{
@ -332,8 +382,14 @@ public:
float total_min_z = z_projected.minCoeff();
// filter bottom area
auto bottom_condition = z_max.array() < total_min_z + this->params.FIRST_LAY_H;
costs.bottom = bottom_condition.select(areas, 0).sum();
auto bottom_condition = z_max.array() < total_min_z + this->params.FIRST_LAY_H - EPSILON;
auto bottom_condition_hull = z_max_hull.array() < total_min_z + this->params.FIRST_LAY_H - EPSILON;
auto bottom_condition_2nd = z_max.array() < total_min_z + this->params.FIRST_LAY_H/2.f - EPSILON;
//The first layer is sliced on half of the first layer height.
//The bottom area is measured by accumulating first layer area with the facets area below first layer height.
//By combining these two factors, we can avoid the wrong orientation of large planar faces while not influence the
//orientations of complex objects with small bottom areas.
costs.bottom = bottom_condition.select(areas, 0).sum()*0.5 + bottom_condition_2nd.select(areas, 0).sum();
// filter overhang
Eigen::VectorXf normal_projection(normals.rows(), 1);// = this->normals.dot(orientation);
@ -342,7 +398,7 @@ public:
normal_projection(i) = normals.row(i).dot(orientation);
}
auto areas_appearance = areas.cwiseProduct((is_apperance * params.APPERANCE_FACE_SUPP + Eigen::VectorXf::Ones(is_apperance.rows(), is_apperance.cols())));
auto overhang_areas = ((normal_projection.array() < params.ASCENT) * (!bottom_condition)).select(areas_appearance, 0);
auto overhang_areas = ((normal_projection.array() < params.ASCENT) * (!bottom_condition_2nd)).select(areas_appearance, 0);
Eigen::MatrixXf inner = normal_projection.array() - params.ASCENT;
inner = inner.cwiseMin(0).cwiseAbs();
if (min_volume)
@ -378,7 +434,7 @@ public:
}
// bottom of convex hull
costs.bottom_hull = (z_max_hull.array()< total_min_z + this->params.FIRST_LAY_H).select(areas_hull, 0).sum();
costs.bottom_hull = (bottom_condition_hull).select(areas_hull, 0).sum();
// low angle faces
auto normal_projection_abs = normal_projection.cwiseAbs();

View file

@ -53,7 +53,7 @@ struct OrientParamsArea {
float TAR_E = 0.0115f;
float FIRST_LAY_H = 0.2f;//0.0475;
float VECTOR_TOL = -0.00083f;
float NEGL_FACE_SIZE = 0.1f;
float NEGL_FACE_SIZE = 0.01f;
float ASCENT = -0.5f;
float PLAFOND_ADV = 0.0599f;
float CONTOUR_AMOUNT = 0.0182427f;
@ -61,14 +61,14 @@ struct OrientParamsArea {
float height_offset = 2.3728f;
float height_log = 0.041375f;
float height_log_k = 1.9325457f;
float LAF_MAX = 0.9997f; // cos(1.4\degree) for low angle face
float LAF_MIN = 0.9703f; // cos(14\degree)
float TAR_LAF = 0.01f;
float LAF_MAX = 0.999f; // cos(1.4\degree) for low angle face 0.9997f
float LAF_MIN = 0.97f; // cos(14\degree) 0.9703f
float TAR_LAF = 0.001f; //0.01f
float TAR_PROJ_AREA = 0.1f;
float BOTTOM_MIN = 0.1f; // min bottom area. If lower than it the object may be unstable
float BOTTOM_MAX = 400; // max bottom area. If get to it the object is stable enough (further increase bottom area won't do more help)
float BOTTOM_MAX = 2000; // max bottom area. If get to it the object is stable enough (further increase bottom area won't do more help)
float height_to_bottom_hull_ratio_MIN = 1;
float BOTTOM_HULL_MAX = 600;// max bottom hull area
float BOTTOM_HULL_MAX = 2000;// max bottom hull area
float APPERANCE_FACE_SUPP=3; // penalty of generating supports on appearance face
float overhang_angle = 60.f;
@ -109,14 +109,14 @@ struct OrientParams {
float height_offset = 2.7417608343142073f;
float height_log = 0.06442030687034085f;
float height_log_k = 0.3933594673063997f;
float LAF_MAX = 0.9997f; // cos(1.4\degree) for low angle face
float LAF_MIN= 0.9703f; // cos(14\degree)
float TAR_LAF= 0.1f;
float LAF_MAX = 0.999f; // cos(1.4\degree) for low angle face //0.9997f;
float LAF_MIN= 0.9703f; // cos(14\degree) 0.9703f;
float TAR_LAF = 0.01f; //0.1f
float TAR_PROJ_AREA = 0.1f;
float BOTTOM_MIN = 0.1f; // min bottom area. If lower than it the objects may be unstable
float BOTTOM_MAX = 400;
float BOTTOM_MAX = 2000; //400
float height_to_bottom_hull_ratio_MIN = 1;
float BOTTOM_HULL_MAX = 600;// max bottom hull area to clip
float BOTTOM_HULL_MAX = 2000;// max bottom hull area to clip //600
float APPERANCE_FACE_SUPP=3; // penalty of generating supports on appearance face
float overhang_angle = 60.f;

View file

@ -4,6 +4,8 @@
#include "ShortestPath.hpp"
#include "VariableWidth.hpp"
#include "CurveAnalyzer.hpp"
#include "Clipper2Utils.hpp"
#include "Arachne/WallToolPaths.hpp"
#include <cmath>
#include <cassert>
@ -78,6 +80,51 @@ static void fuzzy_polygon(Polygon &poly, double fuzzy_skin_thickness, double fuz
poly.points = std::move(out);
}
// Thanks Cura developers for this function.
static void fuzzy_extrusion_line(Arachne::ExtrusionLine& ext_lines, double fuzzy_skin_thickness, double fuzzy_skin_point_dist)
{
const double min_dist_between_points = fuzzy_skin_point_dist * 3. / 4.; // hardcoded: the point distance may vary between 3/4 and 5/4 the supplied value
const double range_random_point_dist = fuzzy_skin_point_dist / 2.;
double dist_left_over = double(rand()) * (min_dist_between_points / 2) / double(RAND_MAX); // the distance to be traversed on the line before making the first new point
auto* p0 = &ext_lines.front();
std::vector<Arachne::ExtrusionJunction> out;
out.reserve(ext_lines.size());
for (auto& p1 : ext_lines) {
if (p0->p == p1.p) { // Connect endpoints.
out.emplace_back(p1.p, p1.w, p1.perimeter_index);
continue;
}
// 'a' is the (next) new point between p0 and p1
Vec2d p0p1 = (p1.p - p0->p).cast<double>();
double p0p1_size = p0p1.norm();
// so that p0p1_size - dist_last_point evaulates to dist_left_over - p0p1_size
double dist_last_point = dist_left_over + p0p1_size * 2.;
for (double p0pa_dist = dist_left_over; p0pa_dist < p0p1_size; p0pa_dist += min_dist_between_points + double(rand()) * range_random_point_dist / double(RAND_MAX)) {
double r = double(rand()) * (fuzzy_skin_thickness * 2.) / double(RAND_MAX) - fuzzy_skin_thickness;
out.emplace_back(p0->p + (p0p1 * (p0pa_dist / p0p1_size) + perp(p0p1).cast<double>().normalized() * r).cast<coord_t>(), p1.w, p1.perimeter_index);
dist_last_point = p0pa_dist;
}
dist_left_over = p0p1_size - dist_last_point;
p0 = &p1;
}
while (out.size() < 3) {
size_t point_idx = ext_lines.size() - 2;
out.emplace_back(ext_lines[point_idx].p, ext_lines[point_idx].w, ext_lines[point_idx].perimeter_index);
if (point_idx == 0)
break;
--point_idx;
}
if (ext_lines.back().p == ext_lines.front().p) // Connect endpoints.
out.front().p = out.back().p;
if (out.size() >= 3)
ext_lines.junctions = std::move(out);
}
using PerimeterGeneratorLoops = std::vector<PerimeterGeneratorLoop>;
static void lowpass_filter_by_paths_overhang_degree(ExtrusionPaths& paths) {
@ -230,7 +277,7 @@ static ExtrusionEntityCollection traverse_loops(const PerimeterGenerator &perime
Polylines inside_polines = (it == lower_polygons_series->begin()) ?
intersection_pl({ polygon }, it->second) :
intersection_pl(remain_polines, it->second);
intersection_pl_2(remain_polines, it->second);
extrusion_paths_append(
paths,
std::move(inside_polines),
@ -243,7 +290,7 @@ static ExtrusionEntityCollection traverse_loops(const PerimeterGenerator &perime
remain_polines = (it == lower_polygons_series->begin()) ?
diff_pl({ polygon }, it->second) :
diff_pl(remain_polines, it->second);
diff_pl_2(remain_polines, it->second);
if (remain_polines.size() == 0)
break;
@ -355,7 +402,229 @@ static ExtrusionEntityCollection traverse_loops(const PerimeterGenerator &perime
return out;
}
void PerimeterGenerator::process()
static ClipperLib_Z::Paths clip_extrusion(const ClipperLib_Z::Path& subject, const ClipperLib_Z::Paths& clip, ClipperLib_Z::ClipType clipType)
{
ClipperLib_Z::Clipper clipper;
clipper.ZFillFunction([](const ClipperLib_Z::IntPoint& e1bot, const ClipperLib_Z::IntPoint& e1top, const ClipperLib_Z::IntPoint& e2bot,
const ClipperLib_Z::IntPoint& e2top, ClipperLib_Z::IntPoint& pt) {
ClipperLib_Z::IntPoint start = e1bot;
ClipperLib_Z::IntPoint end = e1top;
if (start.z() <= 0 && end.z() <= 0) {
start = e2bot;
end = e2top;
}
assert(start.z() > 0 && end.z() > 0);
// Interpolate extrusion line width.
double length_sqr = (end - start).cast<double>().squaredNorm();
double dist_sqr = (pt - start).cast<double>().squaredNorm();
double t = std::sqrt(dist_sqr / length_sqr);
pt.z() = start.z() + coord_t((end.z() - start.z()) * t);
});
clipper.AddPath(subject, ClipperLib_Z::ptSubject, false);
clipper.AddPaths(clip, ClipperLib_Z::ptClip, true);
ClipperLib_Z::PolyTree clipped_polytree;
ClipperLib_Z::Paths clipped_paths;
clipper.Execute(clipType, clipped_polytree, ClipperLib_Z::pftNonZero, ClipperLib_Z::pftNonZero);
ClipperLib_Z::PolyTreeToPaths(clipped_polytree, clipped_paths);
// Clipped path could contain vertices from the clip with a Z coordinate equal to zero.
// For those vertices, we must assign value based on the subject.
// This happens only in sporadic cases.
for (ClipperLib_Z::Path& path : clipped_paths)
for (ClipperLib_Z::IntPoint& c_pt : path)
if (c_pt.z() == 0) {
// Now we must find the corresponding line on with this point is located and compute line width (Z coordinate).
if (subject.size() <= 2)
continue;
const Point pt(c_pt.x(), c_pt.y());
Point projected_pt_min;
auto it_min = subject.begin();
auto dist_sqr_min = std::numeric_limits<double>::max();
Point prev(subject.front().x(), subject.front().y());
for (auto it = std::next(subject.begin()); it != subject.end(); ++it) {
Point curr(it->x(), it->y());
Point projected_pt = pt.projection_onto(Line(prev, curr));
if (double dist_sqr = (projected_pt - pt).cast<double>().squaredNorm(); dist_sqr < dist_sqr_min) {
dist_sqr_min = dist_sqr;
projected_pt_min = projected_pt;
it_min = std::prev(it);
}
prev = curr;
}
assert(dist_sqr_min <= SCALED_EPSILON);
assert(std::next(it_min) != subject.end());
const Point pt_a(it_min->x(), it_min->y());
const Point pt_b(std::next(it_min)->x(), std::next(it_min)->y());
const double line_len = (pt_b - pt_a).cast<double>().norm();
const double dist = (projected_pt_min - pt_a).cast<double>().norm();
c_pt.z() = coord_t(double(it_min->z()) + (dist / line_len) * double(std::next(it_min)->z() - it_min->z()));
}
assert([&clipped_paths = std::as_const(clipped_paths)]() -> bool {
for (const ClipperLib_Z::Path& path : clipped_paths)
for (const ClipperLib_Z::IntPoint& pt : path)
if (pt.z() <= 0)
return false;
return true;
}());
return clipped_paths;
}
struct PerimeterGeneratorArachneExtrusion
{
Arachne::ExtrusionLine* extrusion = nullptr;
// Indicates if closed ExtrusionLine is a contour or a hole. Used it only when ExtrusionLine is a closed loop.
bool is_contour = false;
// Should this extrusion be fuzzyfied on path generation?
bool fuzzify = false;
};
static ExtrusionEntityCollection traverse_extrusions(const PerimeterGenerator& perimeter_generator, std::vector<PerimeterGeneratorArachneExtrusion>& pg_extrusions)
{
ExtrusionEntityCollection extrusion_coll;
for (PerimeterGeneratorArachneExtrusion& pg_extrusion : pg_extrusions) {
Arachne::ExtrusionLine* extrusion = pg_extrusion.extrusion;
if (extrusion->empty())
continue;
const bool is_external = extrusion->inset_idx == 0;
ExtrusionRole role = is_external ? erExternalPerimeter : erPerimeter;
if (pg_extrusion.fuzzify)
fuzzy_extrusion_line(*extrusion, scaled<float>(perimeter_generator.config->fuzzy_skin_thickness.value), scaled<float>(perimeter_generator.config->fuzzy_skin_point_distance.value));
ExtrusionPaths paths;
// detect overhanging/bridging perimeters
if (perimeter_generator.config->detect_overhang_wall && perimeter_generator.layer_id > perimeter_generator.object_config->raft_layers
&& !((perimeter_generator.object_config->enable_support || perimeter_generator.object_config->enforce_support_layers > 0) &&
perimeter_generator.object_config->support_top_z_distance.value == 0)) {
ClipperLib_Z::Path extrusion_path;
extrusion_path.reserve(extrusion->size());
for (const Arachne::ExtrusionJunction& ej : extrusion->junctions)
extrusion_path.emplace_back(ej.p.x(), ej.p.y(), ej.w);
ClipperLib_Z::Paths lower_slices_paths;
lower_slices_paths.reserve(perimeter_generator.lower_slices_polygons().size());
for (const Polygon& poly : perimeter_generator.lower_slices_polygons()) {
lower_slices_paths.emplace_back();
ClipperLib_Z::Path& out = lower_slices_paths.back();
out.reserve(poly.points.size());
for (const Point& pt : poly.points)
out.emplace_back(pt.x(), pt.y(), 0);
}
// get non-overhang paths by intersecting this loop with the grown lower slices
extrusion_paths_append(paths, clip_extrusion(extrusion_path, lower_slices_paths, ClipperLib_Z::ctIntersection), role,
is_external ? perimeter_generator.ext_perimeter_flow : perimeter_generator.perimeter_flow);
// get overhang paths by checking what parts of this loop fall
// outside the grown lower slices (thus where the distance between
// the loop centerline and original lower slices is >= half nozzle diameter
extrusion_paths_append(paths, clip_extrusion(extrusion_path, lower_slices_paths, ClipperLib_Z::ctDifference), erOverhangPerimeter,
perimeter_generator.overhang_flow);
// Reapply the nearest point search for starting point.
// We allow polyline reversal because Clipper may have randomly reversed polylines during clipping.
// Arachne sometimes creates extrusion with zero-length (just two same endpoints);
if (!paths.empty()) {
Point start_point = paths.front().first_point();
if (!extrusion->is_closed) {
// Especially for open extrusion, we need to select a starting point that is at the start
// or the end of the extrusions to make one continuous line. Also, we prefer a non-overhang
// starting point.
struct PointInfo
{
size_t occurrence = 0;
bool is_overhang = false;
};
std::unordered_map<Point, PointInfo, PointHash> point_occurrence;
for (const ExtrusionPath& path : paths) {
++point_occurrence[path.polyline.first_point()].occurrence;
++point_occurrence[path.polyline.last_point()].occurrence;
if (path.role() == erOverhangPerimeter) {
point_occurrence[path.polyline.first_point()].is_overhang = true;
point_occurrence[path.polyline.last_point()].is_overhang = true;
}
}
// Prefer non-overhang point as a starting point.
for (const std::pair<Point, PointInfo> pt : point_occurrence)
if (pt.second.occurrence == 1) {
start_point = pt.first;
if (!pt.second.is_overhang) {
start_point = pt.first;
break;
}
}
}
chain_and_reorder_extrusion_paths(paths, &start_point);
}
}
else {
extrusion_paths_append(paths, *extrusion, role, is_external ? perimeter_generator.ext_perimeter_flow : perimeter_generator.perimeter_flow);
}
// Append paths to collection.
if (!paths.empty()) {
if (extrusion->is_closed) {
ExtrusionLoop extrusion_loop(std::move(paths));
// Restore the orientation of the extrusion loop.
if (pg_extrusion.is_contour)
extrusion_loop.make_counter_clockwise();
else
extrusion_loop.make_clockwise();
for (auto it = std::next(extrusion_loop.paths.begin()); it != extrusion_loop.paths.end(); ++it) {
assert(it->polyline.points.size() >= 2);
assert(std::prev(it)->polyline.last_point() == it->polyline.first_point());
}
assert(extrusion_loop.paths.front().first_point() == extrusion_loop.paths.back().last_point());
extrusion_coll.append(std::move(extrusion_loop));
}
else {
// Because we are processing one ExtrusionLine all ExtrusionPaths should form one connected path.
// But there is possibility that due to numerical issue there is poss
assert([&paths = std::as_const(paths)]() -> bool {
for (auto it = std::next(paths.begin()); it != paths.end(); ++it)
if (std::prev(it)->polyline.last_point() != it->polyline.first_point())
return false;
return true;
}());
ExtrusionMultiPath multi_path;
multi_path.paths.emplace_back(std::move(paths.front()));
for (auto it_path = std::next(paths.begin()); it_path != paths.end(); ++it_path) {
if (multi_path.paths.back().last_point() != it_path->first_point()) {
extrusion_coll.append(ExtrusionMultiPath(std::move(multi_path)));
multi_path = ExtrusionMultiPath();
}
multi_path.paths.emplace_back(std::move(*it_path));
}
extrusion_coll.append(ExtrusionMultiPath(std::move(multi_path)));
}
}
}
return extrusion_coll;
}
void PerimeterGenerator::process_classic()
{
// other perimeters
m_mm3_per_mm = this->perimeter_flow.mm3_per_mm();
@ -562,7 +831,7 @@ void PerimeterGenerator::process()
//BBS: refer to superslicer
//store surface for top infill if only_one_wall_top
if (i == 0 && config->only_one_wall_top && this->upper_slices != NULL) {
if (i == 0 && i!=loop_number && config->only_one_wall_top && this->upper_slices != NULL) {
//split the polygons with top/not_top
//get the offset from solid surface anchor
coord_t offset_top_surface = scale_(1.5 * (config->wall_loops.value == 0 ? 0. : unscaled(double(ext_perimeter_width + perimeter_spacing * int(int(config->wall_loops.value) - int(1))))));
@ -577,9 +846,19 @@ void PerimeterGenerator::process()
//set the clip to a virtual "second perimeter"
fill_clip = offset_ex(last, -double(ext_perimeter_spacing));
// get the real top surface
ExPolygons top_polygons = diff_ex(last, grown_upper_slices, ApplySafetyOffset::Yes);
ExPolygons grown_lower_slices;
ExPolygons bridge_checker;
// BBS: check whether surface be bridge or not
if (this->lower_slices != NULL) {
grown_lower_slices =*this->lower_slices;
double bridge_offset = std::max(double(ext_perimeter_spacing), (double(perimeter_width)));
bridge_checker = offset_ex(diff_ex(last, grown_lower_slices, ApplySafetyOffset::Yes), 1.5 * bridge_offset);
}
ExPolygons delete_bridge = diff_ex(last, bridge_checker, ApplySafetyOffset::Yes);
ExPolygons top_polygons = diff_ex(delete_bridge, grown_upper_slices, ApplySafetyOffset::Yes);
//get the not-top surface, from the "real top" but enlarged by external_infill_margin (and the min_width_top_surface we removed a bit before)
ExPolygons temp_gap = diff_ex(top_polygons, fill_clip);
ExPolygons inner_polygons = diff_ex(last,
offset_ex(top_polygons, offset_top_surface + min_width_top_surface - double(ext_perimeter_spacing / 2)),
ApplySafetyOffset::Yes);
@ -591,6 +870,8 @@ void PerimeterGenerator::process()
double infill_spacing_unscaled = this->config->sparse_infill_line_width.value;
fill_clip = offset_ex(last, double(ext_perimeter_spacing / 2) - scale_(infill_spacing_unscaled / 2));
last = intersection_ex(inner_polygons, last);
if (has_gap_fill)
last = union_ex(last,temp_gap);
//{
// std::stringstream stri;
// stri << this->layer->id() << "_1_"<< i <<"_only_one_peri"<< ".svg";
@ -818,6 +1099,261 @@ void PerimeterGenerator::process()
} // for each island
}
// Thanks, Cura developers, for implementing an algorithm for generating perimeters with variable width (Arachne) that is based on the paper
// "A framework for adaptive width control of dense contour-parallel toolpaths in fused deposition modeling"
void PerimeterGenerator::process_arachne()
{
// other perimeters
m_mm3_per_mm = this->perimeter_flow.mm3_per_mm();
coord_t perimeter_spacing = this->perimeter_flow.scaled_spacing();
// external perimeters
m_ext_mm3_per_mm = this->ext_perimeter_flow.mm3_per_mm();
coord_t ext_perimeter_width = this->ext_perimeter_flow.scaled_width();
coord_t ext_perimeter_spacing = this->ext_perimeter_flow.scaled_spacing();
coord_t ext_perimeter_spacing2 = scaled<coord_t>(0.5f * (this->ext_perimeter_flow.spacing() + this->perimeter_flow.spacing()));
// overhang perimeters
m_mm3_per_mm_overhang = this->overhang_flow.mm3_per_mm();
// solid infill
coord_t solid_infill_spacing = this->solid_infill_flow.scaled_spacing();
// prepare grown lower layer slices for overhang detection
if (this->lower_slices != nullptr && this->config->detect_overhang_wall) {
// We consider overhang any part where the entire nozzle diameter is not supported by the
// lower layer, so we take lower slices and offset them by half the nozzle diameter used
// in the current layer
double nozzle_diameter = this->print_config->nozzle_diameter.get_at(this->config->wall_filament - 1);
m_lower_slices_polygons = offset(*this->lower_slices, float(scale_(+nozzle_diameter / 2)));
}
// we need to process each island separately because we might have different
// extra perimeters for each one
for (const Surface& surface : this->slices->surfaces) {
// detect how many perimeters must be generated for this island
int loop_number = this->config->wall_loops + surface.extra_perimeters - 1; // 0-indexed loops
ExPolygons last = offset_ex(surface.expolygon.simplify_p(m_scaled_resolution), -float(ext_perimeter_width / 2. - ext_perimeter_spacing / 2.));
Polygons last_p = to_polygons(last);
double min_nozzle_diameter = *std::min_element(print_config->nozzle_diameter.values.begin(), print_config->nozzle_diameter.values.end());
Arachne::WallToolPathsParams input_params;
{
if (const auto& min_feature_size_opt = object_config->min_feature_size)
input_params.min_feature_size = min_feature_size_opt.value * 0.01 * min_nozzle_diameter;
if (const auto& min_bead_width_opt = object_config->min_bead_width)
input_params.min_bead_width = min_bead_width_opt.value * 0.01 * min_nozzle_diameter;
if (const auto& wall_transition_filter_deviation_opt = object_config->wall_transition_filter_deviation)
input_params.wall_transition_filter_deviation = wall_transition_filter_deviation_opt.value * 0.01 * min_nozzle_diameter;
if (const auto& wall_transition_length_opt = object_config->wall_transition_length)
input_params.wall_transition_length = wall_transition_length_opt.value * 0.01 * min_nozzle_diameter;
input_params.wall_transition_angle = this->object_config->wall_transition_angle.value;
input_params.wall_distribution_count = this->object_config->wall_distribution_count.value;
}
Arachne::WallToolPaths wallToolPaths(last_p, ext_perimeter_spacing, perimeter_spacing, coord_t(loop_number + 1), 0, layer_height, input_params);
std::vector<Arachne::VariableWidthLines> perimeters = wallToolPaths.getToolPaths();
loop_number = int(perimeters.size()) - 1;
#ifdef ARACHNE_DEBUG
{
static int iRun = 0;
export_perimeters_to_svg(debug_out_path("arachne-perimeters-%d-%d.svg", layer_id, iRun++), to_polygons(last), perimeters, union_ex(wallToolPaths.getInnerContour()));
}
#endif
// All closed ExtrusionLine should have the same the first and the last point.
// But in rare cases, Arachne produce ExtrusionLine marked as closed but without
// equal the first and the last point.
assert([&perimeters = std::as_const(perimeters)]() -> bool {
for (const Arachne::VariableWidthLines& perimeter : perimeters)
for (const Arachne::ExtrusionLine& el : perimeter)
if (el.is_closed && el.junctions.front().p != el.junctions.back().p)
return false;
return true;
}());
int start_perimeter = int(perimeters.size()) - 1;
int end_perimeter = -1;
int direction = -1;
bool is_outer_wall_first =
this->print_config->wall_infill_order == WallInfillOrder::OuterInnerInfill ||
this->print_config->wall_infill_order == WallInfillOrder::InfillOuterInner;
if (is_outer_wall_first) {
start_perimeter = 0;
end_perimeter = int(perimeters.size());
direction = 1;
}
std::vector<Arachne::ExtrusionLine*> all_extrusions;
for (int perimeter_idx = start_perimeter; perimeter_idx != end_perimeter; perimeter_idx += direction) {
if (perimeters[perimeter_idx].empty())
continue;
for (Arachne::ExtrusionLine& wall : perimeters[perimeter_idx])
all_extrusions.emplace_back(&wall);
}
// Find topological order with constraints from extrusions_constrains.
std::vector<size_t> blocked(all_extrusions.size(), 0); // Value indicating how many extrusions it is blocking (preceding extrusions) an extrusion.
std::vector<std::vector<size_t>> blocking(all_extrusions.size()); // Each extrusion contains a vector of extrusions that are blocked by this extrusion.
std::unordered_map<const Arachne::ExtrusionLine*, size_t> map_extrusion_to_idx;
for (size_t idx = 0; idx < all_extrusions.size(); idx++)
map_extrusion_to_idx.emplace(all_extrusions[idx], idx);
auto extrusions_constrains = Arachne::WallToolPaths::getRegionOrder(all_extrusions, is_outer_wall_first);
for (auto [before, after] : extrusions_constrains) {
auto after_it = map_extrusion_to_idx.find(after);
++blocked[after_it->second];
blocking[map_extrusion_to_idx.find(before)->second].emplace_back(after_it->second);
}
std::vector<bool> processed(all_extrusions.size(), false); // Indicate that the extrusion was already processed.
Point current_position = all_extrusions.empty() ? Point::Zero() : all_extrusions.front()->junctions.front().p; // Some starting position.
std::vector<PerimeterGeneratorArachneExtrusion> ordered_extrusions; // To store our result in. At the end we'll std::swap.
ordered_extrusions.reserve(all_extrusions.size());
while (ordered_extrusions.size() < all_extrusions.size()) {
size_t best_candidate = 0;
double best_distance_sqr = std::numeric_limits<double>::max();
bool is_best_closed = false;
std::vector<size_t> available_candidates;
for (size_t candidate = 0; candidate < all_extrusions.size(); ++candidate) {
if (processed[candidate] || blocked[candidate])
continue; // Not a valid candidate.
available_candidates.push_back(candidate);
}
std::sort(available_candidates.begin(), available_candidates.end(), [&all_extrusions](const size_t a_idx, const size_t b_idx) -> bool {
return all_extrusions[a_idx]->is_closed < all_extrusions[b_idx]->is_closed;
});
for (const size_t candidate_path_idx : available_candidates) {
auto& path = all_extrusions[candidate_path_idx];
if (path->junctions.empty()) { // No vertices in the path. Can't find the start position then or really plan it in. Put that at the end.
if (best_distance_sqr == std::numeric_limits<double>::max()) {
best_candidate = candidate_path_idx;
is_best_closed = path->is_closed;
}
continue;
}
const Point candidate_position = path->junctions.front().p;
double distance_sqr = (current_position - candidate_position).cast<double>().norm();
if (distance_sqr < best_distance_sqr) { // Closer than the best candidate so far.
if (path->is_closed || (!path->is_closed && best_distance_sqr != std::numeric_limits<double>::max()) || (!path->is_closed && !is_best_closed)) {
best_candidate = candidate_path_idx;
best_distance_sqr = distance_sqr;
is_best_closed = path->is_closed;
}
}
}
auto& best_path = all_extrusions[best_candidate];
ordered_extrusions.push_back({ best_path, best_path->is_contour(), false });
processed[best_candidate] = true;
for (size_t unlocked_idx : blocking[best_candidate])
blocked[unlocked_idx]--;
if (!best_path->junctions.empty()) { //If all paths were empty, the best path is still empty. We don't upate the current position then.
if (best_path->is_closed)
current_position = best_path->junctions[0].p; //We end where we started.
else
current_position = best_path->junctions.back().p; //Pick the other end from where we started.
}
}
if (this->layer_id > 0 && this->config->fuzzy_skin != FuzzySkinType::None) {
std::vector<PerimeterGeneratorArachneExtrusion*> closed_loop_extrusions;
for (PerimeterGeneratorArachneExtrusion& extrusion : ordered_extrusions)
if (extrusion.extrusion->inset_idx == 0) {
if (extrusion.extrusion->is_closed && this->config->fuzzy_skin == FuzzySkinType::External) {
closed_loop_extrusions.emplace_back(&extrusion);
}
else {
extrusion.fuzzify = true;
}
}
if (this->config->fuzzy_skin == FuzzySkinType::External) {
ClipperLib_Z::Paths loops_paths;
loops_paths.reserve(closed_loop_extrusions.size());
for (const auto& cl_extrusion : closed_loop_extrusions) {
assert(cl_extrusion->extrusion->junctions.front() == cl_extrusion->extrusion->junctions.back());
size_t loop_idx = &cl_extrusion - &closed_loop_extrusions.front();
ClipperLib_Z::Path loop_path;
loop_path.reserve(cl_extrusion->extrusion->junctions.size() - 1);
for (auto junction_it = cl_extrusion->extrusion->junctions.begin(); junction_it != std::prev(cl_extrusion->extrusion->junctions.end()); ++junction_it)
loop_path.emplace_back(junction_it->p.x(), junction_it->p.y(), loop_idx);
loops_paths.emplace_back(loop_path);
}
ClipperLib_Z::Clipper clipper;
clipper.AddPaths(loops_paths, ClipperLib_Z::ptSubject, true);
ClipperLib_Z::PolyTree loops_polytree;
clipper.Execute(ClipperLib_Z::ctUnion, loops_polytree, ClipperLib_Z::pftEvenOdd, ClipperLib_Z::pftEvenOdd);
for (const ClipperLib_Z::PolyNode* child_node : loops_polytree.Childs) {
// The whole contour must have the same index.
coord_t polygon_idx = child_node->Contour.front().z();
bool has_same_idx = std::all_of(child_node->Contour.begin(), child_node->Contour.end(),
[&polygon_idx](const ClipperLib_Z::IntPoint& point) -> bool { return polygon_idx == point.z(); });
if (has_same_idx)
closed_loop_extrusions[polygon_idx]->fuzzify = true;
}
}
}
if (ExtrusionEntityCollection extrusion_coll = traverse_extrusions(*this, ordered_extrusions); !extrusion_coll.empty())
this->loops->append(extrusion_coll);
ExPolygons infill_contour = union_ex(wallToolPaths.getInnerContour());
const coord_t spacing = (perimeters.size() == 1) ? ext_perimeter_spacing2 : perimeter_spacing;
if (offset_ex(infill_contour, -float(spacing / 2.)).empty())
infill_contour.clear(); // Infill region is too small, so let's filter it out.
// create one more offset to be used as boundary for fill
// we offset by half the perimeter spacing (to get to the actual infill boundary)
// and then we offset back and forth by half the infill spacing to only consider the
// non-collapsing regions
coord_t inset =
(loop_number < 0) ? 0 :
(loop_number == 0) ?
// one loop
ext_perimeter_spacing :
// two or more loops?
perimeter_spacing;
inset = coord_t(scale_(this->config->infill_wall_overlap.get_abs_value(unscale<double>(inset))));
Polygons pp;
for (ExPolygon& ex : infill_contour)
ex.simplify_p(m_scaled_resolution, &pp);
// collapse too narrow infill areas
const auto min_perimeter_infill_spacing = coord_t(solid_infill_spacing * (1. - INSET_OVERLAP_TOLERANCE));
// append infill areas to fill_surfaces
this->fill_surfaces->append(
offset2_ex(
union_ex(pp),
float(-min_perimeter_infill_spacing / 2.),
float(inset + min_perimeter_infill_spacing / 2.)),
stInternal);
// BBS: get the no-overlap infill expolygons
{
append(*this->fill_no_overlap, offset2_ex(
union_ex(pp),
float(-min_perimeter_infill_spacing / 2.),
float(+min_perimeter_infill_spacing / 2.)));
}
}
}
bool PerimeterGeneratorLoop::is_internal_contour() const
{
// An internal contour is a contour containing no other contours

View file

@ -66,13 +66,15 @@ public:
m_ext_mm3_per_mm(-1), m_mm3_per_mm(-1), m_mm3_per_mm_overhang(-1), m_ext_mm3_per_mm_smaller_width(-1)
{}
void process();
void process_classic();
void process_arachne();
double ext_mm3_per_mm() const { return m_ext_mm3_per_mm; }
double mm3_per_mm() const { return m_mm3_per_mm; }
double mm3_per_mm_overhang() const { return m_mm3_per_mm_overhang; }
//BBS
double smaller_width_ext_mm3_per_mm() const { return m_ext_mm3_per_mm_smaller_width; }
Polygons lower_slices_polygons() const { return m_lower_slices_polygons; }
private:
std::map<int, Polygons> generate_lower_polygons_series(float width);
@ -85,6 +87,7 @@ private:
double m_mm3_per_mm_overhang;
//BBS
double m_ext_mm3_per_mm_smaller_width;
Polygons m_lower_slices_polygons;
};
}

View file

@ -8,8 +8,7 @@
#include <string>
#include <sstream>
#include <unordered_map>
#include <Eigen/Geometry>
#include <Eigen/Geometry>
#include "LocalesUtils.hpp"

View file

@ -521,10 +521,10 @@ void Preset::save(DynamicPrintConfig* parent_config)
ConfigOption *opt_dst = temp_config.option(option, true);
opt_dst->set(opt_src);
}
temp_config.save_to_json(this->file, this->name, from_str, this->version.to_string());
temp_config.save_to_json(this->file, this->name, from_str, this->version.to_string(), this->custom_defined);
}
else
this->config.save_to_json(this->file, this->name, from_str, this->version.to_string());
this->config.save_to_json(this->file, this->name, from_str, this->version.to_string(), this->custom_defined);
fs::path idx_file(this->file);
idx_file.replace_extension(".info");
@ -662,6 +662,28 @@ std::string Preset::get_printer_type(PresetBundle *preset_bundle)
return "";
}
std::string Preset::get_current_printer_type(PresetBundle *preset_bundle)
{
if (preset_bundle) {
auto config = &(this->config);
std::string vendor_name;
for (auto vendor_profile : preset_bundle->vendors) {
for (auto vendor_model : vendor_profile.second.models)
if (vendor_model.name == config->opt_string("printer_model")) {
vendor_name = vendor_profile.first;
return vendor_model.model_id;
}
}
}
return "";
}
bool Preset::is_custom_defined()
{
if (custom_defined == "1")
return true;
return false;
}
bool Preset::is_bbl_vendor_preset(PresetBundle *preset_bundle)
{
@ -684,11 +706,11 @@ bool Preset::is_bbl_vendor_preset(PresetBundle *preset_bundle)
}
static std::vector<std::string> s_Preset_print_options {
"layer_height", "initial_layer_print_height", "wall_loops", "slice_closing_radius", "spiral_mode",
"layer_height", "initial_layer_print_height", "wall_loops", "slice_closing_radius", "spiral_mode", "slicing_mode",
"top_shell_layers", "top_shell_thickness", "bottom_shell_layers", "bottom_shell_thickness",
"reduce_crossing_wall", "detect_thin_wall", "detect_overhang_wall",
"ensure_vertical_shell_thickness", "reduce_crossing_wall", "detect_thin_wall", "detect_overhang_wall",
"seam_position", "wall_infill_order", "sparse_infill_density", "sparse_infill_pattern", "top_surface_pattern", "bottom_surface_pattern",
"infill_direction",
"infill_direction", "bridge_angle",
"minimum_sparse_infill_area", "reduce_infill_retraction",
"ironing_type", "ironing_flow", "ironing_speed", "ironing_spacing",
"max_travel_detour_distance",
@ -703,13 +725,13 @@ static std::vector<std::string> s_Preset_print_options {
"default_jerk", "outer_wall_jerk", "inner_wall_jerk", "top_surface_jerk", "initial_layer_jerk","travel_jerk",
"brim_width", "brim_object_gap", "brim_type", "enable_support", "support_type", "support_threshold_angle", "enforce_support_layers",
"raft_layers", "raft_first_layer_density", "raft_first_layer_expansion", "raft_contact_distance", "raft_expansion",
"support_base_pattern", "support_base_pattern_spacing", "support_style",
"support_base_pattern", "support_base_pattern_spacing", "support_expansion", "support_style",
// BBS
//"independent_support_layer_height",
"support_angle", "support_interface_top_layers", "support_interface_bottom_layers",
"support_interface_pattern", "support_interface_spacing", "support_interface_loop_pattern",
"support_top_z_distance", "support_on_build_plate_only","support_critical_regions_only", "bridge_no_support", "thick_bridges", "max_bridge_length", "print_sequence",
"filename_format", "wall_filament",
"filename_format", "wall_filament", "support_bottom_z_distance",
"sparse_infill_filament", "solid_infill_filament", "support_filament", "support_interface_filament",
"ooze_prevention", "standby_temperature_delta", "interface_shells", "line_width", "initial_layer_line_width",
"inner_wall_line_width", "outer_wall_line_width", "sparse_infill_line_width", "internal_solid_infill_line_width",
@ -719,20 +741,21 @@ static std::vector<std::string> s_Preset_print_options {
"wipe_tower_no_sparse_layers", "compatible_printers", "compatible_printers_condition", "inherits",
"flush_into_infill", "flush_into_objects", "flush_into_support",
// BBS
"tree_support_branch_angle", "tree_support_with_infill", "tree_support_wall_count", "tree_support_branch_distance",
"tree_support_branch_angle", "tree_support_wall_count", "tree_support_branch_distance",
"tree_support_branch_diameter",
"detect_narrow_internal_solid_infill",
"gcode_add_line_number", "enable_arc_fitting", "infill_combination", "adaptive_layer_height",
"gcode_add_line_number", "enable_arc_fitting", "infill_combination", /*"adaptive_layer_height",*/
"support_bottom_interface_spacing", "enable_overhang_speed", "overhang_1_4_speed", "overhang_2_4_speed", "overhang_3_4_speed", "overhang_4_4_speed",
"initial_layer_infill_speed", "only_one_wall_top", "only_one_wall_first_layer",
"timelapse_type",
"initial_layer_infill_speed", "only_one_wall_top",
"timelapse_type", "internal_bridge_support_thickness",
"wall_generator", "wall_transition_length", "wall_transition_filter_deviation", "wall_transition_angle",
"wall_distribution_count", "min_feature_size", "min_bead_width",
//SoftFever
"top_solid_infill_flow_ratio","bottom_solid_infill_flow_ratio"
"top_solid_infill_flow_ratio","bottom_solid_infill_flow_ratio","only_one_wall_first_layer"
};
static std::vector<std::string> s_Preset_filament_options {
/*"filament_colour", */"filament_diameter", "filament_type", "filament_soluble", "filament_is_support", "filament_max_volumetric_speed",
/*"filament_colour", */ "default_filament_colour","filament_diameter", "filament_type", "filament_soluble", "filament_is_support", "filament_max_volumetric_speed",
"filament_flow_ratio", "enable_pressure_advance", "pressure_advance", "filament_density", "filament_cost", "filament_minimal_purge_on_wipe_tower",
"chamber_temperature", "nozzle_temperature", "nozzle_temperature_initial_layer",
// BBS
@ -762,14 +785,14 @@ static std::vector<std::string> s_Preset_machine_limits_options {
static std::vector<std::string> s_Preset_printer_options {
"printer_technology",
"printable_area", "bed_exclude_area", "gcode_flavor","z_lift_type",
"printable_area", "bed_exclude_area","bed_custom_texture", "bed_custom_model", "gcode_flavor", "z_lift_type",
"single_extruder_multi_material", "machine_start_gcode", "machine_end_gcode", "before_layer_change_gcode", "layer_change_gcode", "change_filament_gcode",
"printer_model", "printer_variant", "printable_height", "extruder_clearance_radius", "extruder_clearance_max_radius","extruder_clearance_height_to_lid", "extruder_clearance_height_to_rod",
"default_print_profile", "inherits",
"silent_mode",
// BBS
"scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time", "machine_pause_gcode", "template_custom_gcode",
"nozzle_type", "nozzle_diameter", "auxiliary_fan", "nozzle_volume",
"nozzle_type", "nozzle_hrc","nozzle_diameter", "auxiliary_fan", "nozzle_volume","upward_compatible_machine",
//SoftFever
"host_type", "print_host", "printhost_apikey",
"printhost_cafile","printhost_port","printhost_authorization_type",
@ -848,7 +871,7 @@ static std::vector<std::string> s_Preset_sla_material_options {
static std::vector<std::string> s_Preset_sla_printer_options {
"printer_technology",
"printable_area", "printable_height",
"printable_area","bed_custom_texture", "bed_custom_model", "printable_height",
"display_width", "display_height", "display_pixels_x", "display_pixels_y",
"display_mirror_x", "display_mirror_y",
"display_orientation",
@ -1024,14 +1047,20 @@ void PresetCollection::load_presets(
}
preset.version = *version;
if (key_values.find(BBL_JSON_KEY_IS_CUSTOM) != key_values.end())
preset.custom_defined = key_values[BBL_JSON_KEY_IS_CUSTOM];
//BBS: use inherit config as the base
Preset* inherit_preset = nullptr;
ConfigOption* inherits_config = config.option(BBL_JSON_KEY_INHERITS);
// check inherits_config
if (inherits_config) {
ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
std::string inherits_value = option_str->value;
inherit_preset = this->find_preset(inherits_value, false, true);
} else {
;
}
const Preset& default_preset = this->default_preset_for(config);
if (inherit_preset) {
@ -1039,19 +1068,22 @@ void PresetCollection::load_presets(
preset.filament_id = inherit_preset->filament_id;
}
else {
if (!preset.is_custom_defined()) {
BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent for config %1%!")%preset.file;
continue;
}
//should not happen
BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent for config %1%!")%preset.file;
//BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent for config %1%!")%preset.file;
// Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
//preset.config = default_preset.config;
continue;
preset.config = default_preset.config;
}
preset.config.apply(std::move(config));
Preset::normalize(preset.config);
// Report configuration fields, which are misplaced into a wrong group.
std::string incorrect_keys = Preset::remove_invalid_keys(preset.config, default_preset.config);
if (! incorrect_keys.empty())
if (!incorrect_keys.empty())
BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" <<
preset.file << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
preset.file << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
preset.loaded = true;
//BBS: add some workaround for previous incorrect settings
if ((!preset.setting_id.empty())&&(preset.setting_id == preset.base_id))
@ -1359,25 +1391,29 @@ void PresetCollection::save_user_presets(const std::string& dir_path, const std:
if (!preset->is_user()) continue;
preset->file = path_from_name(preset->name);
//BBS: only save difference for user preset
std::string inherits = Preset::inherits(preset->config);
if (inherits.empty()) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find inherits for %1% , should not happen")%preset->name;
// BBS add sync info
preset->sync_info = "delete";
need_to_delete_list.push_back(preset->setting_id);
delete_name_list.push_back(preset->name);
continue;
}
Preset* parent_preset = this->find_preset(inherits, false, true);
if (!parent_preset) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find parent preset for %1% , inherits %2%")%preset->name %inherits;
continue;
}
if (preset->is_custom_defined()) {
preset->save(nullptr);
} else {
//BBS: only save difference for user preset
std::string inherits = Preset::inherits(preset->config);
if (inherits.empty()) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find inherits for %1% , should not happen")%preset->name;
// BBS add sync info
preset->sync_info = "delete";
need_to_delete_list.push_back(preset->setting_id);
delete_name_list.push_back(preset->name);
continue;
}
Preset* parent_preset = this->find_preset(inherits, false, true);
if (!parent_preset) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find parent preset for %1% , inherits %2%")%preset->name %inherits;
continue;
}
if (preset->base_id.empty())
preset->base_id = parent_preset->setting_id;
preset->save(&(parent_preset->config));
if (preset->base_id.empty())
preset->base_id = parent_preset->setting_id;
preset->save(&(parent_preset->config));
}
}
for (auto delete_name: delete_name_list)
@ -1603,11 +1639,11 @@ bool PresetCollection::validate_printers(const std::string &name, DynamicPrintCo
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
// and select it, losing previous modifications.
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select)
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select, Semver file_version, bool is_custom_defined)
{
DynamicPrintConfig cfg(this->default_preset().config);
cfg.apply_only(config, cfg.keys(), true);
return this->load_preset(path, name, std::move(cfg), select);
return this->load_preset(path, name, std::move(cfg), select, file_version, is_custom_defined);
}
static bool profile_print_params_same(const DynamicPrintConfig &cfg_old, const DynamicPrintConfig &cfg_new)
@ -1874,7 +1910,7 @@ std::pair<Preset*, bool> PresetCollection::load_external_preset(
return std::make_pair(&preset, false);
}
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select)
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select, Semver file_version, bool is_custom_defined)
{
lock();
auto it = this->find_preset_internal(name);
@ -1889,6 +1925,10 @@ Preset& PresetCollection::load_preset(const std::string &path, const std::string
preset.config = std::move(config);
preset.loaded = true;
preset.is_dirty = false;
preset.custom_defined = is_custom_defined ? "1": "0";
//BBS
if (file_version.valid())
preset.version = file_version;
if (select)
this->select_preset_by_name(name, true);
unlock();

View file

@ -29,6 +29,7 @@
//BBS: add json support
#define BBL_JSON_KEY_VERSION "version"
#define BBL_JSON_KEY_IS_CUSTOM "is_custom_defined"
#define BBL_JSON_KEY_URL "url"
#define BBL_JSON_KEY_NAME "name"
#define BBL_JSON_KEY_DESCRIPTION "description"
@ -229,6 +230,7 @@ public:
std::string user_id; // preset user_id
std::string base_id; // base id of preset
std::string sync_info; // enum: "delete", "create", "update", ""
std::string custom_defined; // enum: "1", "0", ""
long long updated_time{0}; //last updated time
std::map<std::string, std::string> key_values;
@ -296,10 +298,14 @@ public:
// special for upport G and Support W
std::string get_filament_type(std::string &display_filament_type);
std::string get_printer_type(PresetBundle *preset_bundle);
std::string get_printer_type(PresetBundle *preset_bundle); // get edited preset type
std::string get_current_printer_type(PresetBundle *preset_bundle); // get current preset type
bool is_custom_defined();
bool is_bbl_vendor_preset(PresetBundle *preset_bundle);
static const std::vector<std::string>& print_options();
static const std::vector<std::string>& filament_options();
// Printer options contain the nozzle options.
@ -434,8 +440,8 @@ public:
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
// and select it, losing previous modifications.
Preset& load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select = true);
Preset& load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select = true);
Preset& load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select = true, Semver file_version = Semver(), bool is_custom_defined = false);
Preset& load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select = true, Semver file_version = Semver(), bool is_custom_defined = false);
// Returns a loaded preset, returns true if an existing preset was selected AND modified from config.
// In that case the successive filament loaded for a multi material printer should not be modified, but

View file

@ -13,7 +13,7 @@
#include <boost/filesystem.hpp>
#include <boost/algorithm/clamp.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/nowide/cenv.hpp>
#include <boost/nowide/cstdio.hpp>
#include <boost/nowide/fstream.hpp>
@ -1165,7 +1165,12 @@ void PresetBundle::load_installed_filaments(AppConfig &config)
if (!add_default_materials)
continue;
for (auto default_filament: printer.vendor->models[0].default_materials)
const VendorProfile::PrinterModel *printer_model = PresetUtils::system_printer_model(printer);
if (!printer_model) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": can not find printer_model for printer %1%")%printer.name;
continue;
}
for (auto default_filament: printer_model->default_materials)
{
Preset* filament = filaments.find_preset(default_filament, false, true);
if (filament && filament->is_system)
@ -1256,8 +1261,6 @@ void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& p
sla_prints.select_preset_by_name_strict(initial_sla_print_profile_name);
sla_materials.select_preset_by_name_strict(initial_sla_material_profile_name);
// BBS: filament_presets are now considered as project config instead of app config
#if 0
// Load the names of the other filament profiles selected for a multi-material printer.
// Load it even if the current printer technology is SLA.
// The possibly excessive filament names will be later removed with this->update_multi_material_filament_presets()
@ -1270,7 +1273,22 @@ void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& p
break;
this->filament_presets.emplace_back(remove_ini_suffix(config.get("presets", name)));
}
#endif
std::vector<std::string> filament_colors;
if (config.has("presets", "filament_colors")) {
boost::algorithm::split(filament_colors, config.get("presets", "filament_colors"), boost::algorithm::is_any_of(","));
project_config.option<ConfigOptionStrings>("filament_colour")->values = filament_colors;
}
std::vector<std::string> matrix;
if (config.has("presets", "flush_volumes_matrix")) {
boost::algorithm::split(matrix, config.get("presets", "flush_volumes_matrix"), boost::algorithm::is_any_of("|"));
auto flush_volumes_matrix = matrix | boost::adaptors::transformed(boost::lexical_cast<double, std::string>);
project_config.option<ConfigOptionFloats>("flush_volumes_matrix")->values = std::vector<double>(flush_volumes_matrix.begin(), flush_volumes_matrix.end());
}
if (config.has("presets", "flush_volumes_vector")) {
boost::algorithm::split(matrix, config.get("presets", "flush_volumes_vector"), boost::algorithm::is_any_of("|"));
auto flush_volumes_vector = matrix | boost::adaptors::transformed(boost::lexical_cast<double, std::string>);
project_config.option<ConfigOptionFloats>("flush_volumes_vector")->values = std::vector<double>(flush_volumes_vector.begin(), flush_volumes_vector.end());
}
// Update visibility of presets based on their compatibility with the active printer.
// Always try to select a compatible print and filament preset to the current printer preset,
@ -1298,6 +1316,15 @@ void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& p
}
}
std::string first_visible_filament_name;
for (auto & fp : filament_presets) {
if (auto it = filaments.find_preset_internal(fp); it == filaments.end() || !it->is_visible || !it->is_compatible) {
if (first_visible_filament_name.empty())
first_visible_filament_name = filaments.first_compatible().name;
fp = first_visible_filament_name;
}
}
// Parse the initial physical printer name.
std::string initial_physical_printer_name = remove_ini_suffix(config.get("presets", "physical_printer"));
@ -1322,6 +1349,17 @@ void PresetBundle::export_selections(AppConfig &config)
sprintf(name, "filament_%u", i);
config.set("presets", name, filament_presets[i]);
}
CNumericLocalesSetter locales_setter;
std::string filament_colors = boost::algorithm::join(project_config.option<ConfigOptionStrings>("filament_colour")->values, ",");
config.set("presets", "filament_colors", filament_colors);
std::string flush_volumes_matrix = boost::algorithm::join(project_config.option<ConfigOptionFloats>("flush_volumes_matrix")->values |
boost::adaptors::transformed(static_cast<std::string (*)(double)>(std::to_string)),
"|");
config.set("presets", "flush_volumes_matrix", flush_volumes_matrix);
std::string flush_volumes_vector = boost::algorithm::join(project_config.option<ConfigOptionFloats>("flush_volumes_vector")->values |
boost::adaptors::transformed(static_cast<std::string (*)(double)>(std::to_string)),
"|");
config.set("presets", "flush_volumes_vector", flush_volumes_vector);
config.set("presets", PRESET_PRINTER_NAME, printers.get_selected_preset_name());
// BBS
@ -1357,7 +1395,7 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
update_multi_material_filament_presets();
}
unsigned int PresetBundle::sync_ams_list()
unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns)
{
std::vector<std::string> filament_presets;
std::vector<std::string> filament_colors;
@ -1367,7 +1405,16 @@ unsigned int PresetBundle::sync_ams_list()
auto iter = std::find_if(filaments.begin(), filaments.end(), [&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; });
if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
continue;
auto filament_type = "Generic " + ams.opt_string("filament_type", 0u);
iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto &f) { return f.is_compatible && f.is_system
&& boost::algorithm::starts_with(f.name, filament_type);
});
if (iter == filaments.end())
iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto &f) { return f.is_compatible && f.is_system; });
if (iter == filaments.end())
continue;
++unknowns;
filament_id = iter->filament_id;
}
filament_presets.push_back(iter->name);
filament_colors.push_back(filament_color);
@ -1449,10 +1496,15 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
std::vector<std::string> compatible_prints_condition;
std::vector<std::string> inherits;
std::vector<std::string> filament_ids;
std::vector<std::string> print_compatible_printers;
//BBS: add logic for settings check between different system presets
std::vector<std::string> different_settings;
std::string different_print_settings, different_printer_settings;
compatible_printers_condition.emplace_back(this->prints.get_edited_preset().compatible_printers_condition());
const ConfigOptionStrings* compatible_printers = (const_cast<PresetBundle*>(this))->prints.get_edited_preset().config.option<ConfigOptionStrings>("compatible_printers", false);
if (compatible_printers)
print_compatible_printers = compatible_printers->values;
//BBS: add logic for settings check between different system presets
std::string print_inherits = this->prints.get_edited_preset().inherits();
inherits .emplace_back(print_inherits);
@ -1627,6 +1679,7 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
add_if_some_non_empty(std::move(inherits), "inherits_group");
//BBS: add logic for settings check between different system presets
add_if_some_non_empty(std::move(different_settings), "different_settings_to_system");
add_if_some_non_empty(std::move(print_compatible_printers), "print_compatible_printers");
out.option<ConfigOptionEnumGeneric>("printer_technology", true)->value = ptFFF;
return out;
@ -1756,20 +1809,19 @@ ConfigSubstitutions PresetBundle::load_config_file(const std::string &path, Forw
// Load a config file from a boost property_tree. This is a private method called from load_config_file.
// is_external == false on if called from ConfigWizard
void PresetBundle::load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version)
void PresetBundle::load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version, bool selected, bool is_custom_defined)
{
PrinterTechnology printer_technology = Preset::printer_technology(config);
// The "compatible_printers" field should not have been exported into a config.ini or a G-code anyway,
// but some of the alpha versions of Slic3r did.
{
auto clear_compatible_printers = [](DynamicPrintConfig& config){
ConfigOption *opt_compatible = config.optptr("compatible_printers");
if (opt_compatible != nullptr) {
assert(opt_compatible->type() == coStrings);
if (opt_compatible->type() == coStrings)
static_cast<ConfigOptionStrings*>(opt_compatible)->values.clear();
}
}
};
clear_compatible_printers(config);
#if 0
size_t num_extruders = (printer_technology == ptFFF) ?
@ -1791,6 +1843,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
std::vector<std::string> compatible_prints_condition_values = std::move(config.option<ConfigOptionStrings>("compatible_process_expression_group", true)->values);
std::vector<std::string> inherits_values = std::move(config.option<ConfigOptionStrings>("inherits_group", true)->values);
std::vector<std::string> filament_ids = std::move(config.option<ConfigOptionStrings>("filament_ids", true)->values);
std::vector<std::string> print_compatible_printers = std::move(config.option<ConfigOptionStrings>("print_compatible_printers", true)->values);
//BBS: add different settings check logic
bool has_different_settings_to_system = config.option("different_settings_to_system")?true:false;
std::vector<std::string> different_values = std::move(config.option<ConfigOptionStrings>("different_settings_to_system", true)->values);
@ -1826,7 +1879,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
[&config, &inherits, &inherits_values,
&compatible_printers_condition, &compatible_printers_condition_values,
&compatible_prints_condition, &compatible_prints_condition_values,
is_external, &name, &name_or_path, file_version]
is_external, &name, &name_or_path, file_version, selected, is_custom_defined]
(PresetCollection &presets, size_t idx, const std::string &key, const std::set<std::string> &different_keys, std::string filament_id) {
// Split the "compatible_printers_condition" and "inherits" values one by one from a single vector to the print & printer profiles.
inherits = inherits_values[idx];
@ -1838,7 +1891,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
if (is_external)
presets.load_external_preset(name_or_path, name, config.opt_string(key, true), config, different_keys, PresetCollection::LoadAndSelect::Always, file_version, filament_id);
else
presets.load_preset(presets.path_from_name(name), name, config).save(nullptr);
presets.load_preset(presets.path_from_name(name), name, config, selected, file_version, is_custom_defined).save(nullptr);
};
switch (Preset::printer_technology(config)) {
@ -1855,8 +1908,16 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
//}
//else
print_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end());
if (!print_compatible_printers.empty()) {
ConfigOptionStrings* compatible_printers = config.option<ConfigOptionStrings>("compatible_printers", true);
compatible_printers->values = print_compatible_printers;
}
load_preset(this->prints, 0, "print_settings_id", print_different_keys_set, std::string());
//clear compatible printers
clear_compatible_printers(config);
std::vector<std::string> printer_different_keys_vector;
std::string printer_different_settings = different_values[num_filaments + 1];
Slic3r::unescape_strings_cstyle(printer_different_settings, printer_different_keys_vector);
@ -1899,7 +1960,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
loaded = this->filaments.load_external_preset(name_or_path, name, old_filament_profile_names->values.front(), config, filament_different_keys_set, PresetCollection::LoadAndSelect::Always, file_version, filament_id).first;
else {
// called from Config Wizard.
loaded= &this->filaments.load_preset(this->filaments.path_from_name(name), name, config);
loaded= &this->filaments.load_preset(this->filaments.path_from_name(name), name, config, true, file_version, is_custom_defined);
loaded->save(nullptr);
}
this->filament_presets.clear();
@ -3424,8 +3485,10 @@ std::vector<std::string> PresetBundle::export_current_configs(const std::string
// an optional "(modified)" suffix will be removed from the filament name.
void PresetBundle::set_filament_preset(size_t idx, const std::string &name)
{
if (idx >= filament_presets.size())
filament_presets.resize(idx + 1, filaments.default_preset().name);
if (idx >= filament_presets.size()) {
BOOST_LOG_TRIVIAL(warning) << boost::format("Warning: set_filament_preset out of range %1% - %2%") % idx % filament_presets.size();
return;
}
filament_presets[idx] = Preset::remove_suffix_modified(name);
}

View file

@ -81,7 +81,7 @@ public:
// BBS
void set_num_filaments(unsigned int n, std::string new_col = "");
unsigned int sync_ams_list();
unsigned int sync_ams_list(unsigned int & unknowns);
//BBS: check whether this is the only edited filament
bool is_the_only_edited_filament(unsigned int filament_index);
@ -126,8 +126,8 @@ public:
// Load user configuration and store it into the user profiles.
// This method is called by the configuration wizard.
void load_config_from_wizard(const std::string &name, DynamicPrintConfig config)
{ this->load_config_file_config(name, false, std::move(config)); }
void load_config_from_wizard(const std::string &name, DynamicPrintConfig config, Semver file_version, bool is_custom_defined = false)
{ this->load_config_file_config(name, false, std::move(config), file_version, true, is_custom_defined); }
// Load configuration that comes from a model file containing configuration, such as 3MF et al.
// This method is called by the Plater.
@ -225,7 +225,7 @@ private:
// Load print, filament & printer presets from a config. If it is an external config, then the name is extracted from the external path.
// and the external config is just referenced, not stored into user profile directory.
// If it is not an external config, then the config will be stored into the user profile directory.
void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version = Semver());
void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version = Semver(), bool selected = false, bool is_custom_defined = false);
/*ConfigSubstitutions load_config_file_config_bundle(
const std::string &path, const boost::property_tree::ptree &tree, ForwardCompatibilitySubstitutionRule compatibility_rule);*/

File diff suppressed because it is too large Load diff

View file

@ -515,7 +515,6 @@ private:
// This was a per-object setting and now we default enable it.
static bool clip_multipart_objects;
static bool infill_only_where_needed;
static bool ensure_vertical_shell_thickness;
};
struct WipeTowerData
@ -629,10 +628,13 @@ public:
ApplyStatus apply(const Model &model, DynamicPrintConfig config) override;
void process() override;
void process(bool use_cache = false) override;
// Exports G-code into a file name based on the path_template, returns the file path of the generated G-code file.
// If preview_data is not null, the preview_data is filled in for the G-code visualization (not used by the command line Slic3r).
std::string export_gcode(const std::string& path_template, GCodeProcessorResult* result, ThumbnailsGeneratorCallback thumbnail_cb = nullptr);
//return 0 means successful
int export_cached_data(const std::string& dir_path, bool with_space=false);
int load_cached_data(const std::string& directory);
// methods for handling state
bool is_step_done(PrintStep step) const { return Inherited::is_step_done(step); }
@ -721,6 +723,8 @@ public:
void export_gcode_from_previous_file(const std::string& file, GCodeProcessorResult* result, ThumbnailsGeneratorCallback thumbnail_cb = nullptr);
//BBS: add modify_count logic
int get_modified_count() const {return m_modified_count;}
//BBS: add status for whether support used
bool is_support_used() const {return m_support_used;}
//BBS
static StringObjectException sequential_print_clearance_valid(const Print &print, Polygons *polygons = nullptr, std::vector<std::pair<Polygon, float>>* height_polygons = nullptr);
@ -777,6 +781,7 @@ private:
// Estimated print time, filament consumed.
PrintStatistics m_print_statistics;
bool m_support_used {false};
//BBS: plate's origin
Vec3d m_origin;
@ -793,6 +798,7 @@ public:
static float min_skirt_length;
};
} /* slic3r_Print_hpp_ */
#endif

View file

@ -97,7 +97,7 @@ static inline void layer_height_ranges_copy_configs(t_layer_config_ranges &lr_ds
}
}
static inline bool transform3d_lower(const Transform3d &lhs, const Transform3d &rhs)
static inline bool transform3d_lower(const Transform3d &lhs, const Transform3d &rhs)
{
typedef Transform3d::Scalar T;
const T *lv = lhs.data();
@ -111,7 +111,7 @@ static inline bool transform3d_lower(const Transform3d &lhs, const Transform3d &
return false;
}
static inline bool transform3d_equal(const Transform3d &lhs, const Transform3d &rhs)
static inline bool transform3d_equal(const Transform3d &lhs, const Transform3d &rhs)
{
typedef Transform3d::Scalar T;
const T *lv = lhs.data();
@ -434,7 +434,7 @@ struct PrintObjectStatus {
New
};
PrintObjectStatus(PrintObject *print_object, Status status = Unknown) :
PrintObjectStatus(PrintObject *print_object, Status status = Unknown) :
id(print_object->model_object()->id()),
print_object(print_object),
trafo(print_object->trafo()),
@ -445,7 +445,7 @@ struct PrintObjectStatus {
ObjectID id;
// Pointer to the old PrintObject
PrintObject *print_object;
// Trafo generated with model_object->world_matrix(true)
// Trafo generated with model_object->world_matrix(true)
Transform3d trafo;
Status status;
@ -464,7 +464,7 @@ public:
}
struct iterator_range : std::pair<const_iterator, const_iterator>
{
{
using std::pair<const_iterator, const_iterator>::pair;
iterator_range(const std::pair<const_iterator, const_iterator> in) : std::pair<const_iterator, const_iterator>(in) {}
@ -549,7 +549,7 @@ static PrintObjectRegions::BoundingBox transformed_its_bbox2d(const indexed_tria
}
static void transformed_its_bboxes_in_z_ranges(
const indexed_triangle_set &its,
const indexed_triangle_set &its,
const Transform3f &m,
const std::vector<t_layer_height_range> &z_ranges,
std::vector<std::pair<PrintObjectRegions::BoundingBox, bool>> &bboxes,
@ -732,7 +732,7 @@ bool verify_update_print_object_regions(
assert(next_region_id == int(layer_range.volume_regions.size()) ||
layer_range.volume_regions[next_region_id].model_volume != region.model_volume ||
layer_range.volume_regions[next_region_id].parent <= parent_region_id);
if (next_region_id < int(layer_range.volume_regions.size()) &&
if (next_region_id < int(layer_range.volume_regions.size()) &&
layer_range.volume_regions[next_region_id].model_volume == region.model_volume &&
layer_range.volume_regions[next_region_id].parent == parent_region_id) {
// A parent region is already overridden.
@ -767,7 +767,7 @@ bool verify_update_print_object_regions(
}
}
// Verify and / or update PrintRegions produced by color painting.
// Verify and / or update PrintRegions produced by color painting.
for (const PrintObjectRegions::LayerRangeRegions &layer_range : print_object_regions.layer_ranges)
for (const PrintObjectRegions::PaintedRegion &region : layer_range.painted_regions) {
const PrintObjectRegions::VolumeRegion &parent_region = layer_range.volume_regions[region.parent];
@ -819,7 +819,7 @@ void update_volume_bboxes(
std::vector<PrintObjectRegions::LayerRangeRegions> &layer_ranges,
std::vector<ObjectID> &cached_volume_ids,
ModelVolumePtrs model_volumes,
const Transform3d &object_trafo,
const Transform3d &object_trafo,
const float offset)
{
// output will be sorted by the order of model_volumes sorted by their ObjectIDs.
@ -968,7 +968,7 @@ static PrintObjectRegions* generate_print_object_regions(
if (parent_volume.is_model_part() || parent_volume.is_modifier())
if (PrintObjectRegions::BoundingBox parent_bbox = find_modifier_volume_extents(layer_range, parent_region_id); parent_bbox.intersects(*bbox)) {
// Only create new region for a modifier, which actually modifies config of it's parent.
if (PrintRegionConfig config = region_config_from_model_volume(parent_region.region->config(), nullptr, volume, num_extruders);
if (PrintRegionConfig config = region_config_from_model_volume(parent_region.region->config(), nullptr, volume, num_extruders);
config != parent_region.region->config()) {
added = true;
layer_range.volume_regions.push_back({ &volume, parent_region_id, get_create_region(std::move(config)), bbox });
@ -1021,7 +1021,21 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
new_full_config.option("printer_settings_id", true);
// BBS
int used_filaments = this->extruders().size();
new_full_config.normalize_fdm(used_filaments);
//new_full_config.normalize_fdm(used_filaments);
new_full_config.normalize_fdm_1();
t_config_option_keys changed_keys = new_full_config.normalize_fdm_2(used_filaments);
if (changed_keys.size() > 0) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got changed_keys, size=%1%")%changed_keys.size();
for (int i = 0; i < changed_keys.size(); i++)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", i=%1%, key=%2%")%i %changed_keys[i];
}
}
const ConfigOption* enable_support_option = new_full_config.option("enable_support");
if (enable_support_option && enable_support_option->getBool())
m_support_used = true;
else
m_support_used = false;
// Find modified keys of the various configs. Resolve overrides extruder retract values by filament profiles.
DynamicPrintConfig filament_overrides;
@ -1075,13 +1089,14 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
m_default_object_config.apply_only(new_full_config, object_diff, true);
// Handle changes to regions config defaults
m_default_region_config.apply_only(new_full_config, region_diff, true);
m_full_print_config = std::move(new_full_config);
//m_full_print_config = std::move(new_full_config);
m_full_print_config = new_full_config;
if (num_extruders != m_config.filament_diameter.size()) {
num_extruders = m_config.filament_diameter.size();
num_extruders_changed = true;
}
}
ModelObjectStatusDB model_object_status_db;
// 1) Synchronize model objects.
@ -1219,7 +1234,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
if (solid_or_modifier_differ || model_origin_translation_differ || layer_height_ranges_differ ||
! model_object.layer_height_profile.timestamp_matches(model_object_new.layer_height_profile)) {
// The very first step (the slicing step) is invalidated. One may freely remove all associated PrintObjects.
model_object_status.print_object_regions_status =
model_object_status.print_object_regions_status =
model_object_status.print_object_regions == nullptr || model_origin_translation_differ || layer_height_ranges_differ ?
// Drop print_objects_regions.
ModelObjectStatus::PrintObjectRegionsStatus::Invalid :
@ -1279,7 +1294,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
model_object.name = model_object_new.name;
model_object.input_file = model_object_new.input_file;
// Only refresh ModelInstances if there is any change.
if (model_object.instances.size() != model_object_new.instances.size() ||
if (model_object.instances.size() != model_object_new.instances.size() ||
! std::equal(model_object.instances.begin(), model_object.instances.end(), model_object_new.instances.begin(), [](auto l, auto r){ return l->id() == r->id(); })) {
// G-code generator accesses model_object.instances to generate sequential print ordering matching the Plater object list.
update_apply_status(this->invalidate_step(psGCodeExport));
@ -1289,8 +1304,8 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
model_object.instances.emplace_back(new ModelInstance(*model_instance));
model_object.instances.back()->set_model_object(&model_object);
}
} else if (! std::equal(model_object.instances.begin(), model_object.instances.end(), model_object_new.instances.begin(),
[](auto l, auto r){ return l->print_volume_state == r->print_volume_state && l->printable == r->printable &&
} else if (! std::equal(model_object.instances.begin(), model_object.instances.end(), model_object_new.instances.begin(),
[](auto l, auto r){ return l->print_volume_state == r->print_volume_state && l->printable == r->printable &&
l->get_transformation().get_matrix().isApprox(r->get_transformation().get_matrix()); })) {
// If some of the instances changed, the bounding box of the updated ModelObject is likely no more valid.
// This is safe as the ModelObject's bounding box is only accessed from this function, which is called from the main thread only.
@ -1391,12 +1406,50 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
// BBS
for (PrintObject* object : m_objects) {
auto ept_iter = std::find(print_diff.begin(), print_diff.end(), "enable_prime_tower");
if (object->config().adaptive_layer_height && ept_iter != print_diff.end()) {
if (/*object->config().adaptive_layer_height &&*/ ept_iter != print_diff.end()) {
update_apply_status(object->invalidate_step(posSlice));
}
}
}
//BBS: check the config again
int new_used_filaments = this->extruders().size();
t_config_option_keys new_changed_keys = new_full_config.normalize_fdm_2(new_used_filaments);
if (new_changed_keys.size() > 0) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got new_changed_keys, size=%1%")%new_changed_keys.size();
for (int i = 0; i < new_changed_keys.size(); i++)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", i=%1%, key=%2%")%i %new_changed_keys[i];
}
update_apply_status(false);
// The following call may stop the background processing.
update_apply_status(this->invalidate_state_by_config_options(new_full_config, new_changed_keys));
update_apply_status(this->invalidate_step(psGCodeExport));
if (full_config_diff.empty()) {
//BBS: previous empty
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: full_config_diff previous empty, need to apply now.")%__LINE__;
m_placeholder_parser.clear_config();
// Set the profile aliases for the PrintBase::output_filename()
m_placeholder_parser.set("print_preset", new_full_config.option("print_settings_id")->clone());
m_placeholder_parser.set("filament_preset", new_full_config.option("filament_settings_id")->clone());
m_placeholder_parser.set("printer_preset", new_full_config.option("printer_settings_id")->clone());
//m_placeholder_parser.apply_config(filament_overrides);
}
// It is also safe to change m_config now after this->invalidate_state_by_config_options() call.
m_config.apply_only(new_full_config, new_changed_keys, true);
// Handle changes to object config defaults
m_default_object_config.apply_only(new_full_config, new_changed_keys, true);
// Handle changes to regions config defaults
m_default_region_config.apply_only(new_full_config, new_changed_keys, true);
m_full_print_config = std::move(new_full_config);
}
// All regions now have distinct settings.
// Check whether applying the new region config defaults we would get different regions,
// update regions or create regions from scratch.
@ -1502,7 +1555,10 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
// If it is not valid, then it is ensured that PrintObject.m_slicing_params is not in use
// (posSlicing and posSupportMaterial was invalidated).
for (PrintObject *object : m_objects)
{
object->update_slicing_parameters();
m_support_used |= object->config().enable_support;
}
#ifdef _DEBUG
check_model_ids_equal(m_model, model);
@ -1511,7 +1567,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
//BBS: add timestamp logic
if (apply_status != APPLY_STATUS_UNCHANGED)
m_modified_count++;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: finished, this %2%, m_modified_count %3%, apply_status %4%, ")%__LINE__ %this %m_modified_count %apply_status;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: finished, this %2%, m_modified_count %3%, apply_status %4%, m_support_used %5%")%__LINE__ %this %m_modified_count %apply_status %m_support_used;
return static_cast<ApplyStatus>(apply_status);
}

View file

@ -16,12 +16,20 @@
namespace Slic3r {
enum StringExceptionType {
STRING_EXCEPT_NOT_DEFINED = 0,
STRING_EXCEPT_FILAMENT_NOT_MATCH_BED_TYPE = 1,
STRING_EXCEPT_COUNT
};
// BBS: error with object
struct StringObjectException
{
std::string string;
ObjectBase const *object = nullptr;
std::string opt_key;
StringExceptionType type; // warning type for tips
std::vector<std::string> params; // warning params for tips
};
class CanceledException : public std::exception
@ -411,7 +419,9 @@ public:
// After calling the apply() function, call set_task() to limit the task to be processed by process().
virtual void set_task(const TaskParams &params) {}
// Perform the calculation. This is the only method that is to be called at a worker thread.
virtual void process() = 0;
virtual void process(bool use_cache = false) = 0;
virtual int export_cached_data(const std::string& dir_path, bool with_space=false) { return 0;}
virtual int load_cached_data(const std::string& directory) { return 0;}
// Clean up after process() finished, either with success, error or if canceled.
// The adjustments on the Print / PrintObject data due to set_task() are to be reverted here.
virtual void finalize() {}

View file

@ -141,9 +141,7 @@ static t_config_enum_values s_keys_map_InfillPattern {
{ "archimedeanchords", ipArchimedeanChords },
{ "octagramspiral", ipOctagramSpiral },
{ "supportcubic", ipSupportCubic },
#if HAS_LIGHTNING_INFILL
{ "lightning", ipLightning }
#endif // HAS_LIGHTNING_INFILL
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(InfillPattern)
@ -183,9 +181,9 @@ static t_config_enum_values s_keys_map_SupportMaterialPattern {
{ "rectilinear", smpRectilinear },
{ "rectilinear-grid", smpRectilinearGrid },
{ "honeycomb", smpHoneycomb },
#if HAS_LIGHTNING_INFILL
{ "lightning", smpLightning },
#endif
{ "default", smpDefault},
{ "none", smpNone},
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(SupportMaterialPattern)
@ -206,8 +204,8 @@ static t_config_enum_values s_keys_map_SupportType{
{ "normal(auto)", stNormalAuto },
{ "tree(auto)", stTreeAuto },
{ "hybrid(auto)", stHybridAuto },
{ "normal", stNormal },
{ "tree", stTree }
{ "normal(manual)", stNormal },
{ "tree(manual)", stTree }
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(SupportType)
@ -247,11 +245,10 @@ static const t_config_enum_values s_keys_map_BrimType = {
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BrimType)
// using 0,1,2 to compatible with old files
// using 0,1 to compatible with old files
static const t_config_enum_values s_keys_map_TimelapseType = {
{"0", tlNone},
{"1", tlSmooth},
{"2", tlTraditional}
{"0", tlTraditional},
{"1", tlSmooth}
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(TimelapseType)
@ -270,19 +267,22 @@ static const t_config_enum_values s_keys_map_ForwardCompatibilitySubstitutionRul
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(ForwardCompatibilitySubstitutionRule)
static const t_config_enum_values s_keys_map_OverhangFanThreshold = {
{ "0%", Overhang_threshold_none },
{ "5%", Overhang_threshold_1_4 },
{ "25%", Overhang_threshold_2_4 },
{ "50%", Overhang_threshold_3_4 },
{ "75%", Overhang_threshold_4_4 },
{ "95%", Overhang_threshold_bridge }
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(OverhangFanThreshold)
// BBS
static const t_config_enum_values s_keys_map_BedType = {
{ "Default Plate", btDefault },
{ "Cool Plate", btPC },
{ "Engineering Plate", btEP },
{ "High Temp Plate", btPEI },
{ "Textured PEI Plate", btPTE }
{ "Textured PEI Plate", btPTE }
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BedType)
@ -294,6 +294,12 @@ static t_config_enum_values s_keys_map_NozzleType {
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(NozzleType)
static t_config_enum_values s_keys_map_PerimeterGeneratorType{
{ "classic", int(PerimeterGeneratorType::Classic) },
{ "arachne", int(PerimeterGeneratorType::Arachne) }
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(PerimeterGeneratorType)
static void assign_printer_technology_to_unknown(t_optiondef_map &options, PrinterTechnology printer_technology)
{
for (std::pair<const t_config_option_key, ConfigOptionDef> &kvp : options)
@ -340,6 +346,16 @@ void PrintConfigDef::init_common_params()
def->gui_type = ConfigOptionDef::GUIType::one_string;
def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) });
def = this->add("bed_custom_texture", coString);
def->label = L("Bed custom texture");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionString(""));
def = this->add("bed_custom_model", coString);
def->label = L("Bed custom model");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionString(""));
def = this->add("elefant_foot_compensation", coFloat);
def->label = L("Elephant foot compensation");
def->category = L("Quality");
@ -412,14 +428,14 @@ void PrintConfigDef::init_common_params()
def = this->add("printhost_user", coString);
def->label = L("User");
// def->tooltip = L("");
// def->tooltip = "";
def->mode = comAdvanced;
def->cli = ConfigOptionDef::nocli;
def->set_default_value(new ConfigOptionString(""));
def = this->add("printhost_password", coString);
def->label = L("Password");
// def->tooltip = L("");
// def->tooltip = "";
def->mode = comAdvanced;
def->cli = ConfigOptionDef::nocli;
def->set_default_value(new ConfigOptionString(""));
@ -441,7 +457,7 @@ void PrintConfigDef::init_common_params()
def = this->add("printhost_authorization_type", coEnum);
def->label = L("Authorization Type");
// def->tooltip = L("");
// def->tooltip = "";
def->enum_keys_map = &ConfigOptionEnum<AuthorizationType>::get_enum_values();
def->enum_values.push_back("key");
def->enum_values.push_back("user");
@ -565,7 +581,7 @@ void PrintConfigDef::init_fff_params()
def->max = 120;
def->set_default_value(new ConfigOptionInts{45});
def = this->add("curr_bed_type", coEnums);
def = this->add("curr_bed_type", coEnum);
def->label = L("Bed type");
def->tooltip = L("Bed types supported by the printer");
def->mode = comSimple;
@ -629,15 +645,18 @@ void PrintConfigDef::init_fff_params()
def = this->add("overhang_fan_threshold", coEnums);
def->label = L("Cooling overhang threshold");
def->tooltip = L("Force cooling fan to be specific speed when overhang degree of printed part exceeds this value. "
"Expressed as percentage which indicides how much width of the line without support from lower layer");
def->sidetext = L("");
def->enum_keys_map = &s_keys_map_OverhangFanThreshold;
"Expressed as percentage which indicides how much width of the line without support from lower layer. "
"0% means forcing cooling for all outer wall no matter how much overhang degree");
def->sidetext = "";
def->enum_keys_map = &ConfigOptionEnum<OverhangFanThreshold>::get_enum_values();
def->mode = comAdvanced;
def->enum_values.emplace_back("0%");
def->enum_values.emplace_back("5%");
def->enum_values.emplace_back("25%");
def->enum_values.emplace_back("50%");
def->enum_values.emplace_back("75%");
def->enum_values.emplace_back("95%");
def->enum_labels.emplace_back("0%");
def->enum_labels.emplace_back("10%");
def->enum_labels.emplace_back("25%");
def->enum_labels.emplace_back("50%");
@ -645,6 +664,17 @@ void PrintConfigDef::init_fff_params()
def->enum_labels.emplace_back("95%");
def->set_default_value(new ConfigOptionEnumsGeneric{ (int)Overhang_threshold_bridge });
def = this->add("bridge_angle", coFloat);
def->label = L("Bridge direction");
def->category = L("Strength");
def->tooltip = L("Bridging angle override. If left to zero, the bridging angle will be calculated "
"automatically. Otherwise the provided angle will be used for external bridges. "
"Use 180°for zero angle.");
def->sidetext = L("°");
def->min = 0;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.));
def = this->add("bridge_flow", coFloat);
def->label = L("Bridge flow");
def->category = L("Quality");
@ -791,6 +821,13 @@ void PrintConfigDef::init_fff_params()
def->set_default_value(new ConfigOptionStrings());
def->cli = ConfigOptionDef::nocli;
//BBS.
def = this->add("upward_compatible_machine", coStrings);
def->label = L("upward compatible machine");
def->mode = comDevelop;
def->set_default_value(new ConfigOptionStrings());
def->cli = ConfigOptionDef::nocli;
def = this->add("compatible_printers_condition", coString);
def->label = L("Compatible machine condition");
//def->tooltip = L("A boolean expression using the configuration values of an active printer profile. "
@ -829,6 +866,10 @@ void PrintConfigDef::init_fff_params()
def->set_default_value(new ConfigOptionStrings());
def->cli = ConfigOptionDef::nocli;
def = this->add("print_compatible_printers", coStrings);
def->set_default_value(new ConfigOptionStrings());
def->cli = ConfigOptionDef::nocli;
def = this->add("print_sequence", coEnum);
def->label = L("Print sequence");
def->tooltip = L("Print sequence, layer by layer or object by object");
@ -887,7 +928,7 @@ void PrintConfigDef::init_fff_params()
def = this->add("thick_bridges", coBool);
def->label = L("Thick bridges");
def->category = L("Layers and Perimeters");
def->category = L("Quality");
def->tooltip = L("If enabled, bridges are more reliable, can bridge longer distances, but may look worse. "
"If disabled, bridges look better but are reliable just for shorter bridged distances.");
def->mode = comAdvanced;
@ -920,6 +961,26 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionStrings { " " });
def = this->add("ensure_vertical_shell_thickness", coBool);
def->label = L("Ensure vertical shell thickness");
def->category = L("Strength");
def->tooltip = L("Add solid infill near sloping surfaces to guarantee the vertical shell thickness "
"(top+bottom solid layers)");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBool(true));
def = this->add("internal_bridge_support_thickness", coFloat);
def->label = L("Internal bridge support thickness");
def->category = L("Strength");
def->tooltip = L("If enabled, Studio will generate support loops under the contours of internal bridges."
"These support loops could prevent internal bridges from extruding over the air and improve the top surface quality, especially when the sparse infill density is low."
"This value determines the thickness of the support loops. 0 means disable this feature");
def->sidetext = L("mm");
def->min = 0;
def->max = 2;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0));
auto def_top_fill_pattern = def = this->add("top_surface_pattern", coEnum);
def->label = L("Top surface pattern");
def->category = L("Strength");
@ -931,16 +992,16 @@ void PrintConfigDef::init_fff_params()
def->enum_values.push_back("monotonicline");
def->enum_values.push_back("alignedrectilinear");
def->enum_values.push_back("hilbertcurve");
//def->enum_values.push_back("archimedeanchords");
//def->enum_values.push_back("octagramspiral");
def->enum_values.push_back("archimedeanchords");
def->enum_values.push_back("octagramspiral");
def->enum_labels.push_back(L("Concentric"));
def->enum_labels.push_back(L("Rectilinear"));
def->enum_labels.push_back(L("Monotonic"));
def->enum_labels.push_back(L("Monotonic line"));
def->enum_labels.push_back(L("Aligned Rectilinear"));
def->enum_labels.push_back(L("Hilbert Curve"));
//def->enum_labels.push_back(L("Archimedean Chords"));
//def->enum_labels.push_back(L("Octagram Spiral"));
def->enum_labels.push_back(L("Archimedean Chords"));
def->enum_labels.push_back(L("Octagram Spiral"));
def->set_default_value(new ConfigOptionEnum<InfillPattern>(ipRectilinear));
def = this->add("bottom_surface_pattern", coEnum);
@ -1126,6 +1187,13 @@ void PrintConfigDef::init_fff_params()
def->mode = comSimple;
def->set_default_value(new ConfigOptionFloats{ 60.0f });
def = this->add("default_filament_colour", coStrings);
def->label = L("Default color");
def->tooltip = L("Default filament color");
def->gui_type = ConfigOptionDef::GUIType::color;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionStrings{""});
def = this->add("filament_colour", coStrings);
def->label = L("Color");
def->tooltip = L("Only used as a visual help on UI");
@ -1133,15 +1201,25 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionStrings{ "#00AE42" });
//bbs
def = this->add("required_nozzle_HRC", coInts);
def->label = L("Required nozzle HRC");
def->tooltip = L("Minimum HRC of nozzle required to print the filament. Zero means no checking of nozzle's HRC.");
def->min = 0;
def->max = 500;
def->mode = comDevelop;
def->set_default_value(new ConfigOptionInts{0});
def = this->add("filament_max_volumetric_speed", coFloats);
def->label = L("Max volumetric speed");
def->tooltip = L("This setting stands for how much volume of filament can be melted and extruded per second. "
"Printing speed is limited by max volumetric speed, in case of too high and unreasonable speed setting. "
"Zero means no limit");
"Can't be zero");
def->sidetext = L("mm³/s");
def->min = 0;
def->max = 50;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats { 0. });
def->set_default_value(new ConfigOptionFloats { 2. });
def = this->add("filament_minimal_purge_on_wipe_tower", coFloats);
def->label = L("Minimal purge on wipe tower");
@ -1289,14 +1367,12 @@ void PrintConfigDef::init_fff_params()
def->enum_values.push_back("honeycomb");
def->enum_values.push_back("adaptivecubic");
def->enum_values.push_back("alignedrectilinear");
//def->enum_values.push_back("3dhoneycomb");
//def->enum_values.push_back("hilbertcurve");
//def->enum_values.push_back("archimedeanchords");
//def->enum_values.push_back("octagramspiral");
//def->enum_values.push_back("supportcubic");
#if HAS_LIGHTNING_INFILL
def->enum_values.push_back("3dhoneycomb");
def->enum_values.push_back("hilbertcurve");
def->enum_values.push_back("archimedeanchords");
def->enum_values.push_back("octagramspiral");
def->enum_values.push_back("supportcubic");
def->enum_values.push_back("lightning");
#endif // HAS_LIGHTNING_INFILL
def->enum_labels.push_back(L("Concentric"));
def->enum_labels.push_back(L("Rectilinear"));
def->enum_labels.push_back(L("Grid"));
@ -1308,14 +1384,12 @@ void PrintConfigDef::init_fff_params()
def->enum_labels.push_back(L("Honeycomb"));
def->enum_labels.push_back(L("Adaptive Cubic"));
def->enum_labels.push_back(L("Aligned Rectilinear"));
//def->enum_labels.push_back(L("3D Honeycomb"));
//def->enum_labels.push_back(L("Hilbert Curve"));
//def->enum_labels.push_back(L("Archimedean Chords"));
//def->enum_labels.push_back(L("Octagram Spiral"));
//def->enum_labels.push_back(L("Support Cubic"));
#if HAS_LIGHTNING_INFILL
def->enum_labels.push_back(L("3D Honeycomb"));
def->enum_labels.push_back(L("Hilbert Curve"));
def->enum_labels.push_back(L("Archimedean Chords"));
def->enum_labels.push_back(L("Octagram Spiral"));
def->enum_labels.push_back(L("Support Cubic"));
def->enum_labels.push_back(L("Lightning"));
#endif // HAS_LIGHTNING_INFILL
def->set_default_value(new ConfigOptionEnum<InfillPattern>(ipCubic));
def = this->add("outer_wall_acceleration", coFloat);
@ -1350,6 +1424,14 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(500));
def = this->add("outer_wall_acceleration", coFloat);
def->label = L("Outer wall");
def->tooltip = L("Acceleration of outer wall. Using a lower value can improve quality");
def->sidetext = L("mm/s²");
def->min = 0;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(500));
def = this->add("initial_layer_acceleration", coFloat);
def->label = L("Initial layer");
def->tooltip = L("Acceleration of initial layer. Using a lower value can improve build plate adhensive");
@ -1423,13 +1505,13 @@ void PrintConfigDef::init_fff_params()
def->min = 0;
def->set_default_value(new ConfigOptionFloat(0.2));
def = this->add("adaptive_layer_height", coBool);
def->label = L("Adaptive layer height");
def->category = L("Quality");
def->tooltip = L("Enabling this option means the height of every layer except the first will be automatically calculated "
"during slicing according to the slope of the models surface.\n"
"Note that this option only takes effect if no prime tower is generated in current plate.");
def->set_default_value(new ConfigOptionBool(0));
//def = this->add("adaptive_layer_height", coBool);
//def->label = L("Adaptive layer height");
//def->category = L("Quality");
//def->tooltip = L("Enabling this option means the height of every layer except the first will be automatically calculated "
// "during slicing according to the slope of the models surface.\n"
// "Note that this option only takes effect if no prime tower is generated in current plate.");
//def->set_default_value(new ConfigOptionBool(0));
def = this->add("initial_layer_speed", coFloat);
def->label = L("Initial layer");
@ -1488,7 +1570,7 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("The width within which to jitter. It's adversed to be below outer wall line width");
def->sidetext = L("mm");
def->min = 0;
def->mode = comAdvanced;
def->mode = comSimple;
def->set_default_value(new ConfigOptionFloat(0.3));
def = this->add("fuzzy_skin_point_distance", coFloat);
@ -1496,7 +1578,7 @@ void PrintConfigDef::init_fff_params()
def->category = L("Others");
def->tooltip = L("The average diatance between the random points introducded on each line segment");
def->sidetext = L("mm");
def->mode = comAdvanced;
def->mode = comSimple;
def->set_default_value(new ConfigOptionFloat(0.8));
def = this->add("filter_out_gap_fill", coFloat);
@ -1558,6 +1640,15 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionEnum<NozzleType>(ntUndefine));
def = this->add("nozzle_hrc", coInt);
def->label = L("Nozzle HRC");
def->tooltip = L("The nozzle's hardness. Zero means no checking for nozzle's hardness during slicing.");
def->sidetext = L("HRC");
def->min = 0;
def->max = 500;
def->mode = comDevelop;
def->set_default_value(new ConfigOptionInt{0});
def = this->add("auxiliary_fan", coBool);
def->label = L("Auxiliary part cooling fan");
def->tooltip = L("Enable this option if machine has auxiliary part cooling fan");
@ -2358,12 +2449,10 @@ void PrintConfigDef::init_fff_params()
def->enum_keys_map = &ConfigOptionEnum<TimelapseType>::get_enum_values();
def->enum_values.emplace_back("0");
def->enum_values.emplace_back("1");
def->enum_values.emplace_back("2");
def->enum_labels.emplace_back(L("None"));
def->enum_labels.emplace_back(L("Smooth"));
def->enum_labels.emplace_back(L("Traditional"));
def->enum_labels.emplace_back(L("Smooth"));
def->mode = comSimple;
def->set_default_value(new ConfigOptionEnum<TimelapseType>(tlNone));
def->set_default_value(new ConfigOptionEnum<TimelapseType>(tlTraditional));
def = this->add("standby_temperature_delta", coInt);
def->label = L("Temperature variation");
@ -2418,6 +2507,20 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.049));
def = this->add("slicing_mode", coEnum);
def->label = L("Slicing Mode");
def->category = L("Other");
def->tooltip = L("Use \"Even-odd\" for 3DLabPrint airplane models. Use \"Close holes\" to close all holes in the model.");
def->enum_keys_map = &ConfigOptionEnum<SlicingMode>::get_enum_values();
def->enum_values.push_back("regular");
def->enum_values.push_back("even_odd");
def->enum_values.push_back("close_holes");
def->enum_labels.push_back(L("Regular"));
def->enum_labels.push_back(L("Even-odd"));
def->enum_labels.push_back(L("Close holes"));
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionEnum<SlicingMode>(SlicingMode::Regular));
def = this->add("enable_support", coBool);
//BBS: remove material behind support
def->label = L("Enable support");
@ -2434,13 +2537,13 @@ void PrintConfigDef::init_fff_params()
def->enum_values.push_back("normal(auto)");
def->enum_values.push_back("tree(auto)");
def->enum_values.push_back("hybrid(auto)");
def->enum_values.push_back("normal");
def->enum_values.push_back("tree");
def->enum_values.push_back("normal(manual)");
def->enum_values.push_back("tree(manual)");
def->enum_labels.push_back(L("normal(auto)"));
def->enum_labels.push_back(L("tree(auto)"));
def->enum_labels.push_back(L("hybrid(auto)"));
def->enum_labels.push_back(L("normal"));
def->enum_labels.push_back(L("tree"));
def->enum_labels.push_back(L("normal(manual)"));
def->enum_labels.push_back(L("tree(manual)"));
def->mode = comSimple;
def->set_default_value(new ConfigOptionEnum<SupportType>(stNormalAuto));
@ -2500,6 +2603,15 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.2));
// BBS:MusangKing
def = this->add("support_bottom_z_distance", coFloat);
def->label = L("Bottom Z distance");
def->category = L("Support");
def->tooltip = L("The z gap between the bottom support interface and object");
def->sidetext = L("mm");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.2));
def = this->add("enforce_support_layers", coInt);
//def->label = L("Enforce support for the first");
def->category = L("Support");
@ -2515,9 +2627,10 @@ void PrintConfigDef::init_fff_params()
def->set_default_value(new ConfigOptionInt(0));
def = this->add("support_filament", coInt);
def->label = L("Support");
def->gui_type = ConfigOptionDef::GUIType::i_enum_open;
def->label = L("Support");
def->category = L("Support");
def->tooltip = L("Filament to print support and skirt. 0 means no specific filament for support and current filament is used");
def->tooltip = L("Filament to print support and raft. \"Default\" means no specific filament for support and current filament is used");
def->min = 0;
def->mode = comSimple;
def->set_default_value(new ConfigOptionInt(1));
@ -2539,11 +2652,12 @@ void PrintConfigDef::init_fff_params()
def->set_default_value(new ConfigOptionBool(false));
def = this->add("support_interface_filament", coInt);
def->label = L("Support interface");
def->gui_type = ConfigOptionDef::GUIType::i_enum_open;
def->label = L("Support interface");
def->category = L("Support");
def->tooltip = L("Filament to print support interface. 0 means no specific filament for support interface and current filament is used");
def->tooltip = L("Filament to print support interface. \"Default\" means no specific filament for support interface and current filament is used");
def->min = 0;
//BBS
// BBS
def->mode = comSimple;
def->set_default_value(new ConfigOptionInt(1));
@ -2614,18 +2728,18 @@ void PrintConfigDef::init_fff_params()
def->category = L("Support");
def->tooltip = L("Line pattern of support");
def->enum_keys_map = &ConfigOptionEnum<SupportMaterialPattern>::get_enum_values();
def->enum_values.push_back("default");
def->enum_values.push_back("rectilinear");
def->enum_values.push_back("rectilinear-grid");
def->enum_values.push_back("honeycomb");
#if HAS_LIGHTNING_INFILL
def->enum_values.push_back("lightning");
#endif
def->enum_values.push_back("none");
def->enum_labels.push_back(L("Default"));
def->enum_labels.push_back(L("Rectilinear"));
def->enum_labels.push_back(L("Rectilinear grid"));
def->enum_labels.push_back(L("Honeycomb"));
#if HAS_LIGHTNING_INFILL
def->enum_labels.push_back(L("Lightning"));
#endif
def->enum_labels.push_back(L("None"));
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionEnum<SupportMaterialPattern>(smpRectilinear));
@ -2654,6 +2768,14 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(2.5));
def = this->add("support_expansion", coFloat);
def->label = L("Normal Support expansion");
def->category = L("Support");
def->tooltip = L("Expand (+) or shrink (-) the horizontal span of normal support");
def->sidetext = L("mm");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0));
def = this->add("support_speed", coFloat);
def->label = L("Support");
def->category = L("Speed");
@ -2760,19 +2882,19 @@ void PrintConfigDef::init_fff_params()
def = this->add("nozzle_temperature_range_low", coInts);
def->label = L("Min");
//def->tooltip = L("");
//def->tooltip = "";
def->sidetext = L("°C");
def->min = 0;
def->max = max_temp;
def->set_default_value(new ConfigOptionInts { 0 });
def->set_default_value(new ConfigOptionInts { 190 });
def = this->add("nozzle_temperature_range_high", coInts);
def->label = L("Max");
//def->tooltip = L("");
//def->tooltip = "";
def->sidetext = L("°C");
def->min = 0;
def->max = max_temp;
def->set_default_value(new ConfigOptionInts { 0 });
def->set_default_value(new ConfigOptionInts { 240 });
def = this->add("bed_temperature_difference", coInts);
def->label = L("Bed temperature difference");
@ -2914,10 +3036,8 @@ void PrintConfigDef::init_fff_params()
def = this->add("flush_multiplier", coFloat);
def->label = L("Flush multiplier");
def->tooltip = L("");
def->sidetext = L("");
def->mode = comAdvanced;
def->min = 0;
def->tooltip = L("The actual flushing volumes is equal to the flush multiplier multiplied by the flushing volumes in the table.");
def->sidetext = "";
def->set_default_value(new ConfigOptionFloat(1.0));
// BBS
@ -2925,7 +3045,7 @@ void PrintConfigDef::init_fff_params()
def->label = L("Prime volume");
def->tooltip = L("The volume of material to prime extruder on tower.");
def->sidetext = L("mm³");
def->min = 0;
def->min = 1.0;
def->mode = comSimple;
def->set_default_value(new ConfigOptionFloat(45.));
@ -2949,6 +3069,7 @@ void PrintConfigDef::init_fff_params()
def->label = L("Width");
def->tooltip = L("Width of prime tower");
def->sidetext = L("mm");
def->min = 2.0;
def->mode = comSimple;
def->set_default_value(new ConfigOptionFloat(35.));
@ -2972,21 +3093,24 @@ void PrintConfigDef::init_fff_params()
def->label = L("Flush into objects' infill");
def->tooltip = L("Purging after filament change will be done inside objects' infills. "
"This may lower the amount of waste and decrease the print time. "
"If the walls are printed with transparent filament, the mixed color infill will be seen outside");
"If the walls are printed with transparent filament, the mixed color infill will be seen outside. "
"It will not take effect, unless the prime tower is enabled.");
def->set_default_value(new ConfigOptionBool(false));
def = this->add("flush_into_support", coBool);
def->category = L("Flush options");
def->label = L("Flush into objects' support");
def->tooltip = L("Purging after filament change will be done inside objects' support. "
"This may lower the amount of waste and decrease the print time");
"This may lower the amount of waste and decrease the print time. "
"It will not take effect, unless the prime tower is enabled.");
def->set_default_value(new ConfigOptionBool(true));
def = this->add("flush_into_objects", coBool);
def->category = L("Flush options");
def->label = L("Flush into this object");
def->tooltip = L("This object will be used to purge the nozzle after a filament change to save filament and decrease the print time. "
"Colours of the objects will be mixed as a result");
"Colours of the objects will be mixed as a result. "
"It will not take effect, unless the prime tower is enabled.");
def->set_default_value(new ConfigOptionBool(false));
//BBS
@ -3024,6 +3148,92 @@ void PrintConfigDef::init_fff_params()
def->gui_type = ConfigOptionDef::GUIType::one_string;
def->set_default_value(new ConfigOptionPoints{Vec2d(300, 300)});
def = this->add("wall_generator", coEnum);
def->label = L("Wall generator");
def->category = L("Quality");
def->tooltip = L("Classic wall generator produces walls with constant extrusion width and for "
"very thin areas is used gap-fill. "
"Arachne engine produces walls with variable extrusion width");
def->enum_keys_map = &ConfigOptionEnum<PerimeterGeneratorType>::get_enum_values();
def->enum_values.push_back("classic");
def->enum_values.push_back("arachne");
def->enum_labels.push_back(L("Classic"));
def->enum_labels.push_back(L("Arachne"));
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionEnum<PerimeterGeneratorType>(PerimeterGeneratorType::Classic));
def = this->add("wall_transition_length", coPercent);
def->label = L("Wall transition length");
def->category = L("Quality");
def->tooltip = L("When transitioning between different numbers of walls as the part becomes "
"thinner, a certain amount of space is allotted to split or join the wall segments. "
"It's expressed as a percentage over nozzle diameter");
def->sidetext = L("%");
def->mode = comAdvanced;
def->min = 0;
def->set_default_value(new ConfigOptionPercent(100));
def = this->add("wall_transition_filter_deviation", coPercent);
def->label = L("Wall transitioning filter margin");
def->category = L("Quality");
def->tooltip = L("Prevent transitioning back and forth between one extra wall and one less. This "
"margin extends the range of extrusion widths which follow to [Minimum wall width "
"- margin, 2 * Minimum wall width + margin]. Increasing this margin "
"reduces the number of transitions, which reduces the number of extrusion "
"starts/stops and travel time. However, large extrusion width variation can lead to "
"under- or overextrusion problems. "
"It's expressed as a percentage over nozzle diameter");
def->sidetext = L("%");
def->mode = comAdvanced;
def->min = 0;
def->set_default_value(new ConfigOptionPercent(25));
def = this->add("wall_transition_angle", coFloat);
def->label = L("Wall transitioning threshold angle");
def->category = L("Quality");
def->tooltip = L("When to create transitions between even and odd numbers of walls. A wedge shape with"
" an angle greater than this setting will not have transitions and no walls will be "
"printed in the center to fill the remaining space. Reducing this setting reduces "
"the number and length of these center walls, but may leave gaps or overextrude");
def->sidetext = L("°");
def->mode = comAdvanced;
def->min = 1.;
def->max = 59.;
def->set_default_value(new ConfigOptionFloat(10.));
def = this->add("wall_distribution_count", coInt);
def->label = L("Wall distribution count");
def->category = L("Quality");
def->tooltip = L("The number of walls, counted from the center, over which the variation needs to be "
"spread. Lower values mean that the outer walls don't change in width");
def->mode = comAdvanced;
def->min = 1;
def->set_default_value(new ConfigOptionInt(1));
def = this->add("min_feature_size", coPercent);
def->label = L("Minimum feature size");
def->category = L("Quality");
def->tooltip = L("Minimum thickness of thin features. Model features that are thinner than this value will "
"not be printed, while features thicker than the Minimum feature size will be widened to "
"the Minimum wall width. "
"It's expressed as a percentage over nozzle diameter");
def->sidetext = L("%");
def->mode = comAdvanced;
def->min = 0;
def->set_default_value(new ConfigOptionPercent(25));
def = this->add("min_bead_width", coPercent);
def->label = L("Minimum wall width");
def->category = L("Quality");
def->tooltip = L("Width of the wall that will replace thin features (according to the Minimum feature size) "
"of the model. If the Minimum wall width is thinner than the thickness of the feature,"
" the wall will become as thick as the feature itself. "
"It's expressed as a percentage over nozzle diameter");
def->sidetext = L("%");
def->mode = comAdvanced;
def->min = 0;
def->set_default_value(new ConfigOptionPercent(85));
// Declare retract values for filament profile, overriding the printer's extruder profile.
for (const char *opt_key : {
// floats
@ -3097,7 +3307,7 @@ void PrintConfigDef::init_filament_option_keys()
"filament_diameter", "min_layer_height", "max_layer_height",
"retraction_length", "z_hop", "retraction_speed", "deretraction_speed",
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", /*"filament_colour",*/
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "filament_colour",
"default_filament_profile"
};
@ -3797,6 +4007,14 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
opt_key = "slow_down_for_layer_cooling";
} else if (opt_key == "timelapse_no_toolhead") {
opt_key = "timelapse_type";
} else if (opt_key == "timelapse_type" && value == "2") {
// old file "0" is None, "2" is Traditional
// new file "0" is Traditional, erase "2"
value = "0";
} else if (opt_key == "support_type" && value == "normal") {
value = "normal(manual)";
} else if (opt_key == "support_type" && value == "tree") {
value = "tree(manual)";
} else if (opt_key == "different_settings_to_system") {
std::string copy_value = value;
copy_value.erase(std::remove(copy_value.begin(), copy_value.end(), '\"'), copy_value.end()); // remove '"' in string
@ -3820,12 +4038,12 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
#endif /* HAS_PRESSURE_EQUALIZER */
// BBS
, "support_sharp_tails","remove_small_overhangs", "support_with_sheath",
"tree_support_branch_diameter_angle", "tree_support_collision_resolution",
"tree_support_branch_diameter_angle", "tree_support_collision_resolution", "tree_support_with_infill",
"max_volumetric_speed", "max_print_speed",
"support_bottom_z_distance", "support_closing_radius", "slicing_mode",
"support_closing_radius",
"remove_freq_sweep", "remove_bed_leveling", "remove_extrusion_calibration",
"support_transition_line_width", "support_transition_speed", "bed_temperature", "bed_temperature_initial_layer",
"can_switch_nozzle_type", "can_add_auxiliary_fan", "extra_flush_volume", "spaghetti_detector"
"can_switch_nozzle_type", "can_add_auxiliary_fan", "extra_flush_volume", "spaghetti_detector", "adaptive_layer_height"
};
if (ignore.find(opt_key) != ignore.end()) {
@ -3931,7 +4149,7 @@ void DynamicPrintConfig::normalize_fdm(int used_filaments)
ConfigOptionBool* ept_opt = this->option<ConfigOptionBool>("enable_prime_tower");
if (used_filaments > 0 && ept_opt != nullptr) {
ConfigOptionBool* islh_opt = this->option<ConfigOptionBool>("independent_support_layer_height", true);
ConfigOptionBool* alh_opt = this->option<ConfigOptionBool>("adaptive_layer_height");
//ConfigOptionBool* alh_opt = this->option<ConfigOptionBool>("adaptive_layer_height");
ConfigOptionEnum<PrintSequence>* ps_opt = this->option<ConfigOptionEnum<PrintSequence>>("print_sequence");
ConfigOptionEnum<TimelapseType>* timelapse_opt = this->option<ConfigOptionEnum<TimelapseType>>("timelapse_type");
@ -3943,8 +4161,8 @@ void DynamicPrintConfig::normalize_fdm(int used_filaments)
if (ept_opt->value) {
if (islh_opt)
islh_opt->value = false;
if (alh_opt)
alh_opt->value = false;
//if (alh_opt)
// alh_opt->value = false;
}
else {
if (islh_opt)
@ -3953,6 +4171,102 @@ void DynamicPrintConfig::normalize_fdm(int used_filaments)
}
}
//BBS:divide normalize_fdm to 2 steps and call them one by one in Print::Apply
void DynamicPrintConfig::normalize_fdm_1()
{
if (this->has("extruder")) {
int extruder = this->option("extruder")->getInt();
this->erase("extruder");
if (extruder != 0) {
if (!this->has("sparse_infill_filament"))
this->option("sparse_infill_filament", true)->setInt(extruder);
if (!this->has("wall_filament"))
this->option("wall_filament", true)->setInt(extruder);
// Don't propagate the current extruder to support.
// For non-soluble supports, the default "0" extruder means to use the active extruder,
// for soluble supports one certainly does not want to set the extruder to non-soluble.
// if (!this->has("support_filament"))
// this->option("support_filament", true)->setInt(extruder);
// if (!this->has("support_interface_filament"))
// this->option("support_interface_filament", true)->setInt(extruder);
}
}
if (!this->has("solid_infill_filament") && this->has("sparse_infill_filament"))
this->option("solid_infill_filament", true)->setInt(this->option("sparse_infill_filament")->getInt());
if (this->has("spiral_mode") && this->opt<ConfigOptionBool>("spiral_mode", true)->value) {
{
// this should be actually done only on the spiral layers instead of all
auto* opt = this->opt<ConfigOptionBools>("retract_when_changing_layer", true);
opt->values.assign(opt->values.size(), false); // set all values to false
// Disable retract on layer change also for filament overrides.
auto* opt_n = this->opt<ConfigOptionBoolsNullable>("filament_retract_when_changing_layer", true);
opt_n->values.assign(opt_n->values.size(), false); // Set all values to false.
}
{
this->opt<ConfigOptionInt>("wall_loops", true)->value = 1;
this->opt<ConfigOptionInt>("top_shell_layers", true)->value = 0;
this->opt<ConfigOptionPercent>("sparse_infill_density", true)->value = 0;
}
}
if (auto *opt_gcode_resolution = this->opt<ConfigOptionFloat>("resolution", false); opt_gcode_resolution)
// Resolution will be above 1um.
opt_gcode_resolution->value = std::max(opt_gcode_resolution->value, 0.001);
return;
}
t_config_option_keys DynamicPrintConfig::normalize_fdm_2(int used_filaments)
{
t_config_option_keys changed_keys;
ConfigOptionBool* ept_opt = this->option<ConfigOptionBool>("enable_prime_tower");
if (used_filaments > 0 && ept_opt != nullptr) {
ConfigOptionBool* islh_opt = this->option<ConfigOptionBool>("independent_support_layer_height", true);
//ConfigOptionBool* alh_opt = this->option<ConfigOptionBool>("adaptive_layer_height");
ConfigOptionEnum<PrintSequence>* ps_opt = this->option<ConfigOptionEnum<PrintSequence>>("print_sequence");
ConfigOptionEnum<TimelapseType>* timelapse_opt = this->option<ConfigOptionEnum<TimelapseType>>("timelapse_type");
bool is_smooth_timelapse = timelapse_opt != nullptr && timelapse_opt->value == TimelapseType::tlSmooth;
if (!is_smooth_timelapse && (used_filaments == 1 || ps_opt->value == PrintSequence::ByObject)) {
if (ept_opt->value) {
ept_opt->value = false;
changed_keys.push_back("enable_prime_tower");
}
//ept_opt->value = false;
}
if (ept_opt->value) {
if (islh_opt) {
if (islh_opt->value) {
islh_opt->value = false;
changed_keys.push_back("independent_support_layer_height");
}
//islh_opt->value = false;
}
//if (alh_opt) {
// if (alh_opt->value) {
// alh_opt->value = false;
// changed_keys.push_back("adaptive_layer_height");
// }
// //alh_opt->value = false;
//}
}
else {
if (islh_opt) {
if (!islh_opt->value) {
islh_opt->value = true;
changed_keys.push_back("independent_support_layer_height");
}
//islh_opt->value = true;
}
}
}
return changed_keys;
}
void handle_legacy_sla(DynamicPrintConfig &config)
{
for (std::string corr : {"relative_correction", "material_correction"}) {
@ -4084,6 +4398,16 @@ std::string DynamicPrintConfig::get_filament_type(std::string &displayed_filamen
return "PLA";
}
bool DynamicPrintConfig::is_custom_defined()
{
auto* is_custom_defined = dynamic_cast<const ConfigOptionStrings*>(this->option("is_custom_defined"));
if (!is_custom_defined || is_custom_defined->empty())
return false;
if (is_custom_defined->get_at(0) == "1")
return true;
return false;
}
//FIXME localize this function.
std::string validate(const FullPrintConfig &cfg)
{
@ -4166,7 +4490,7 @@ std::string validate(const FullPrintConfig &cfg)
// config before exporting, leaving this check in would mean that config would be rejected before export
// (although both the UI and the backend handle it).
// --default-acceleration
//if ((cfg.perimeter_acceleration != 0. || cfg.infill_acceleration != 0. || cfg.bridge_acceleration != 0. || cfg.initial_layer_acceleration != 0.) &&
//if ((cfg.outer_wall_acceleration != 0. || cfg.infill_acceleration != 0. || cfg.bridge_acceleration != 0. || cfg.initial_layer_acceleration != 0.) &&
// cfg.default_acceleration == 0.)
// return "Invalid zero value for --default-acceleration when using other acceleration settings";
@ -4299,6 +4623,18 @@ CLIActionsConfigDef::CLIActionsConfigDef()
def->cli_params = "filename.3mf";
def->set_default_value(new ConfigOptionString("output.3mf"));
def = this->add("export_slicedata", coString);
def->label = L("Export slicing data");
def->tooltip = L("Export slicing data to a folder.");
def->cli_params = "slicing_data_directory";
def->set_default_value(new ConfigOptionString("cached_data"));
def = this->add("load_slicedata", coStrings);
def->label = L("Load slicing data");
def->tooltip = L("Load cached slicing data from directory");
def->cli_params = "slicing_data_directory";
def->set_default_value(new ConfigOptionString("cached_data"));
/*def = this->add("export_amf", coBool);
def->label = L("Export AMF");
def->tooltip = L("Export the model(s) as AMF.");
@ -4335,6 +4671,12 @@ CLIActionsConfigDef::CLIActionsConfigDef()
def->cli = "help|h";
def->set_default_value(new ConfigOptionBool(false));
def = this->add("uptodate", coBool);
def->label = L("UpToDate");
def->tooltip = L("Update the configs values of 3mf to latest.");
def->cli = "uptodate";
def->set_default_value(new ConfigOptionBool(false));
/*def = this->add("help_fff", coBool);
def->label = L("Help (FFF options)");
def->tooltip = L("Show the full list of print/G-code configuration options.");
@ -4355,6 +4697,12 @@ CLIActionsConfigDef::CLIActionsConfigDef()
def->tooltip = L("Export settings to a file.");
def->cli_params = "settings.json";
def->set_default_value(new ConfigOptionString("output.json"));
def = this->add("pipe", coString);
def->label = L("Send progress to pipe");
def->tooltip = L("Send progress to pipe.");
def->cli_params = "pipename";
def->set_default_value(new ConfigOptionString("cli_pipe"));
}
//BBS: remove unused command currently
@ -4433,10 +4781,10 @@ CLITransformConfigDef::CLITransformConfigDef()
//def->cli = "orient|o";
def->set_default_value(new ConfigOptionBool(false));
def = this->add("repair", coBool);
/*def = this->add("repair", coBool);
def->label = L("Repair");
def->tooltip = L("Repair the model's meshes if it is non-manifold mesh");
def->set_default_value(new ConfigOptionBool(false));
def->set_default_value(new ConfigOptionBool(false));*/
/*def = this->add("rotate", coFloat);
def->label = L("Rotate");

View file

@ -50,14 +50,10 @@ enum AuthorizationType {
atKeyPassword, atUserPassword
};
#define HAS_LIGHTNING_INFILL 1
enum InfillPattern : int {
ipConcentric, ipRectilinear, ipGrid, ipLine, ipCubic, ipTriangles, ipStars, ipGyroid, ipHoneycomb, ipAdaptiveCubic, ipMonotonic, ipMonotonicLine, ipAlignedRectilinear, ip3DHoneycomb,
ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipSupportCubic, ipSupportBase, ipConcentricInternal,
#if HAS_LIGHTNING_INFILL
ipLightning,
#endif // HAS_LIGHTNING_INFILL
ipLightning,
ipCount,
};
@ -96,10 +92,10 @@ enum class SlicingMode
};
enum SupportMaterialPattern {
smpDefault,
smpRectilinear, smpRectilinearGrid, smpHoneycomb,
#if HAS_LIGHTNING_INFILL
smpLightning,
#endif // HAS_LIGHTNING_INFILL
smpNone,
};
enum SupportMaterialStyle {
@ -153,18 +149,27 @@ enum BrimType {
};
enum TimelapseType {
tlNone,
tlSmooth,
tlTraditional
tlTraditional,
tlSmooth
};
enum DraftShield {
dsDisabled, dsLimited, dsEnabled
};
enum class PerimeterGeneratorType
{
// Classic perimeter generator using Clipper offsets with constant extrusion width.
Classic,
// Perimeter generator with variable extrusion width based on the paper
// "A framework for adaptive width control of dense contour-parallel toolpaths in fused deposition modeling" ported from Cura.
Arachne
};
// BBS
enum OverhangFanThreshold {
Overhang_threshold_1_4 = 0,
Overhang_threshold_none = 0,
Overhang_threshold_1_4,
Overhang_threshold_2_4,
Overhang_threshold_3_4,
Overhang_threshold_4_4,
@ -173,7 +178,8 @@ enum OverhangFanThreshold {
// BBS
enum BedType {
btPC = 0,
btDefault = 0,
btPC,
btEP,
btPEI,
btPTE,
@ -198,13 +204,14 @@ static std::string bed_type_to_gcode_string(const BedType type)
type_str = "cool_plate";
break;
case btEP:
type_str = "engineering_plate";
type_str = "eng_plate";
break;
case btPEI:
type_str = "high_temp_plate";
type_str = "hot_plate";
break;
case btPTE:
type_str = "frosted_plate";
type_str = "textured_plate";
break;
default:
type_str = "unknown";
break;
@ -273,6 +280,7 @@ CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ForwardCompatibilitySubstitutionRule)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PrintHostType)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(AuthorizationType)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PerimeterGeneratorType)
#undef CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS
@ -346,6 +354,9 @@ public:
const ConfigDef* def() const override { return &print_config_def; }
void normalize_fdm(int used_filaments = 0);
void normalize_fdm_1();
//return the changed param set
t_config_option_keys normalize_fdm_2(int used_filaments = 0);
void set_num_extruders(unsigned int num_extruders);
@ -364,6 +375,8 @@ public:
//BBS special case Support G/ Support W
std::string get_filament_type(std::string &displayed_filament_type, int id = 0);
bool is_custom_defined();
};
void handle_legacy_sla(DynamicPrintConfig &config);
@ -610,6 +623,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionInt, raft_layers))
((ConfigOptionEnum<SeamPosition>, seam_position))
((ConfigOptionFloat, slice_closing_radius))
((ConfigOptionEnum<SlicingMode>, slicing_mode))
((ConfigOptionBool, enable_support))
// Automatic supports (generated based on support_threshold_angle).
((ConfigOptionEnum<SupportType>, support_type))
@ -618,6 +632,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionBool, support_on_build_plate_only))
((ConfigOptionBool, support_critical_regions_only))
((ConfigOptionFloat, support_top_z_distance))
((ConfigOptionFloat, support_bottom_z_distance))
((ConfigOptionInt, enforce_support_layers))
((ConfigOptionInt, support_filament))
((ConfigOptionFloat, support_line_width))
@ -632,10 +647,11 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionEnum<SupportMaterialInterfacePattern>, support_interface_pattern))
// Spacing between support material lines (the hatching distance).
((ConfigOptionFloat, support_base_pattern_spacing))
((ConfigOptionFloat, support_expansion))
((ConfigOptionFloat, support_speed))
((ConfigOptionEnum<SupportMaterialStyle>, support_style))
// BBS
((ConfigOptionBool, independent_support_layer_height))
//((ConfigOptionBool, independent_support_layer_height))
((ConfigOptionBool, thick_bridges))
// Overhang angle threshold.
((ConfigOptionInt, support_threshold_angle))
@ -651,10 +667,17 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionFloat, tree_support_branch_diameter))
((ConfigOptionFloat, tree_support_branch_angle))
((ConfigOptionInt, tree_support_wall_count))
((ConfigOptionBool, tree_support_with_infill))
((ConfigOptionBool, detect_narrow_internal_solid_infill))
((ConfigOptionBool, adaptive_layer_height))
// ((ConfigOptionBool, adaptive_layer_height))
((ConfigOptionFloat, support_bottom_interface_spacing))
((ConfigOptionFloat, internal_bridge_support_thickness))
((ConfigOptionEnum<PerimeterGeneratorType>, wall_generator))
((ConfigOptionPercent, wall_transition_length))
((ConfigOptionPercent, wall_transition_filter_deviation))
((ConfigOptionFloat, wall_transition_angle))
((ConfigOptionInt, wall_distribution_count))
((ConfigOptionPercent, min_feature_size))
((ConfigOptionPercent, min_bead_width))
)
// This object is mapped to Perl as Slic3r::Config::PrintRegion.
@ -663,9 +686,10 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionInt, bottom_shell_layers))
((ConfigOptionFloat, bottom_shell_thickness))
((ConfigOptionFloat, bridge_angle))
((ConfigOptionFloat, bridge_flow))
((ConfigOptionFloat, bridge_speed))
((ConfigOptionFloat, bridge_angle))
((ConfigOptionBool, ensure_vertical_shell_thickness))
((ConfigOptionEnum<InfillPattern>, top_surface_pattern))
((ConfigOptionFloat, top_solid_infill_flow_ratio))
((ConfigOptionFloat, bottom_solid_infill_flow_ratio))
@ -769,8 +793,10 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionBools, filament_soluble))
((ConfigOptionBools, filament_is_support))
((ConfigOptionFloats, filament_cost))
((ConfigOptionStrings, default_filament_colour))
((ConfigOptionInts, temperature_vitrification)) //BBS
((ConfigOptionFloats, filament_max_volumetric_speed))
((ConfigOptionInts, required_nozzle_HRC))
((ConfigOptionFloat, machine_load_filament_time))
((ConfigOptionFloat, machine_unload_filament_time))
((ConfigOptionFloats, filament_minimal_purge_on_wipe_tower))
@ -805,13 +831,14 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionString, template_custom_gcode))
//BBS
((ConfigOptionEnum<NozzleType>, nozzle_type))
((ConfigOptionInt, nozzle_hrc))
((ConfigOptionBool, auxiliary_fan))
)
// This object is mapped to Perl as Slic3r::Config::Print.
PRINT_CONFIG_CLASS_DERIVED_DEFINE(
PrintConfig,
PrintConfig,
(MachineEnvelopeConfig, GCodeConfig),
//BBS
@ -918,6 +945,8 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE(
((ConfigOptionFloat, nozzle_volume))
((ConfigOptionEnum<TimelapseType>, timelapse_type))
((ConfigOptionPoints, thumbnails))
// BBS: move from PrintObjectConfig
((ConfigOptionBool, independent_support_layer_height))
)
// This object is mapped to Perl as Slic3r::Config::Full.

View file

@ -546,7 +546,7 @@ FillLightning::GeneratorPtr PrintObject::prepare_lightning_infill_data()
break;
}
return has_lightning_infill ? FillLightning::build_generator(std::as_const(*this)) : FillLightning::GeneratorPtr();
return has_lightning_infill ? FillLightning::build_generator(std::as_const(*this), [this]() -> void { this->throw_if_canceled(); }) : FillLightning::GeneratorPtr();
}
void PrintObject::clear_layers()
@ -665,6 +665,14 @@ bool PrintObject::invalidate_state_by_config_options(
|| opt_key == "top_surface_speed") {
// Brim is printed below supports, support invalidates brim and skirt.
steps.emplace_back(posSupportMaterial);
if (opt_key == "brim_type") {
const auto* old_brim_type = old_config.option<ConfigOptionEnum<BrimType>>(opt_key);
const auto* new_brim_type = new_config.option<ConfigOptionEnum<BrimType>>(opt_key);
//BBS: When switch to manual brim, the object must have brim, then re-generate perimeter
//to make the wall order of first layer to be outer-first
if (old_brim_type->value == btOuterOnly || new_brim_type->value == btOuterOnly)
steps.emplace_back(posPerimeters);
}
} else if (
opt_key == "wall_loops"
|| opt_key == "only_one_wall_top"
@ -695,15 +703,15 @@ bool PrintObject::invalidate_state_by_config_options(
steps.emplace_back(posPerimeters);
} else if (
opt_key == "layer_height"
//BBS
|| opt_key == "adaptive_layer_height"
|| opt_key == "raft_layers"
|| opt_key == "raft_contact_distance"
|| opt_key == "slice_closing_radius") {
|| opt_key == "slice_closing_radius"
|| opt_key == "slicing_mode") {
steps.emplace_back(posSlice);
} else if (
opt_key == "elefant_foot_compensation"
|| opt_key == "support_top_z_distance"
|| opt_key == "support_bottom_z_distance"
|| opt_key == "xy_hole_compensation"
|| opt_key == "xy_contour_compensation") {
steps.emplace_back(posSlice);
@ -735,7 +743,8 @@ bool PrintObject::invalidate_state_by_config_options(
|| opt_key == "support_style"
|| opt_key == "support_object_xy_distance"
|| opt_key == "support_base_pattern_spacing"
|| opt_key == "independent_support_layer_height" // BBS
|| opt_key == "support_expansion"
//|| opt_key == "independent_support_layer_height" // BBS
|| opt_key == "support_threshold_angle"
|| opt_key == "raft_expansion"
|| opt_key == "raft_first_layer_density"
@ -746,7 +755,6 @@ bool PrintObject::invalidate_state_by_config_options(
|| opt_key == "tree_support_branch_distance"
|| opt_key == "tree_support_branch_diameter"
|| opt_key == "tree_support_branch_angle"
|| opt_key == "tree_support_with_infill"
|| opt_key == "tree_support_wall_count") {
steps.emplace_back(posSupportMaterial);
} else if (opt_key == "bottom_shell_layers") {
@ -767,7 +775,10 @@ bool PrintObject::invalidate_state_by_config_options(
|| opt_key == "solid_infill_filament"
|| opt_key == "sparse_infill_line_width"
|| opt_key == "infill_direction"
|| opt_key == "bridge_angle") {
|| opt_key == "ensure_vertical_shell_thickness"
|| opt_key == "bridge_angle"
//BBS
|| opt_key == "internal_bridge_support_thickness") {
steps.emplace_back(posPrepareInfill);
} else if (
opt_key == "top_surface_pattern"
@ -779,7 +790,6 @@ bool PrintObject::invalidate_state_by_config_options(
steps.emplace_back(posInfill);
} else if (opt_key == "sparse_infill_pattern") {
steps.emplace_back(posInfill);
#if HAS_LIGHTNING_INFILL
const auto *old_fill_pattern = old_config.option<ConfigOptionEnum<InfillPattern>>(opt_key);
const auto *new_fill_pattern = new_config.option<ConfigOptionEnum<InfillPattern>>(opt_key);
assert(old_fill_pattern && new_fill_pattern);
@ -787,7 +797,6 @@ bool PrintObject::invalidate_state_by_config_options(
// the Lightning infill to another infill or vice versa.
if (PrintObject::infill_only_where_needed && (new_fill_pattern->value == ipLightning || old_fill_pattern->value == ipLightning))
steps.emplace_back(posPrepareInfill);
#endif
} else if (opt_key == "sparse_infill_density") {
// One likely wants to reslice only when switching between zero infill to simulate boolean difference (subtracting volumes),
// normal infill and 100% (solid) infill.
@ -823,6 +832,15 @@ bool PrintObject::invalidate_state_by_config_options(
steps.emplace_back(posInfill);
steps.emplace_back(posSupportMaterial);
}
} else if (
opt_key == "wall_generator"
|| opt_key == "wall_transition_length"
|| opt_key == "wall_transition_filter_deviation"
|| opt_key == "wall_transition_angle"
|| opt_key == "wall_distribution_count"
|| opt_key == "min_feature_size"
|| opt_key == "min_bead_width") {
steps.emplace_back(posSlice);
} else if (
opt_key == "seam_position"
|| opt_key == "support_speed"
@ -1223,9 +1241,7 @@ void PrintObject::discover_vertical_shells()
bool has_extra_layers = false;
for (size_t region_id = 0; region_id < this->num_printing_regions(); ++region_id) {
const PrintRegionConfig &config = this->printing_region(region_id).config();
//BBS
//if (config.ensure_vertical_shell_thickness.value && has_extra_layers_fn(config)) {
if (PrintObject::ensure_vertical_shell_thickness && has_extra_layers_fn(config)) {
if (config.ensure_vertical_shell_thickness.value && has_extra_layers_fn(config)) {
has_extra_layers = true;
break;
}
@ -1305,9 +1321,7 @@ void PrintObject::discover_vertical_shells()
PROFILE_BLOCK(discover_vertical_shells_region);
const PrintRegion &region = this->printing_region(region_id);
//BBS
//if (! region.config().ensure_vertical_shell_thickness.value)
if (! PrintObject::ensure_vertical_shell_thickness)
if (! region.config().ensure_vertical_shell_thickness.value)
// This region will be handled by discover_horizontal_shells().
continue;
if (! has_extra_layers_fn(region.config()))
@ -1614,6 +1628,7 @@ void PrintObject::bridge_over_infill()
Layer *layer = *layer_it;
LayerRegion *layerm = layer->m_regions[region_id];
const PrintObjectConfig& object_config = layer->object()->config();
//BBS: enable thick bridge for internal bridge only
Flow bridge_flow = layerm->bridging_flow(frSolidInfill, true);
@ -1645,6 +1660,10 @@ void PrintObject::bridge_over_infill()
to_bridge_pp = intersection(to_bridge_pp, lower_internal);
}
// BBS: expand to make avoid gap between bridge and inner wall
to_bridge_pp = expand(to_bridge_pp, bridge_flow.scaled_width());
to_bridge_pp = intersection(to_bridge_pp, internal_solid);
// there's no point in bridging too thin/short regions
//FIXME Vojtech: The offset2 function is not a geometric offset,
// therefore it may create 1) gaps, and 2) sharp corners, which are outside the original contour.
@ -1677,8 +1696,43 @@ void PrintObject::bridge_over_infill()
(layerm->fill_surfaces.surfaces.end() - 1)->bridge_angle = ibd.angle;
}
}
for (ExPolygon &ex : not_to_bridge)
layerm->fill_surfaces.surfaces.push_back(Surface(stInternalSolid, ex));
//BBS: modify stInternal to be stInternalWithLoop to give better support to internal bridge
if (!to_bridge.empty()){
float internal_loop_thickness = object_config.internal_bridge_support_thickness.value;
double bottom_z = layer->print_z - layer->height - internal_loop_thickness + EPSILON;
//BBS: lighting infill doesn't support this feature. Don't need to add loop when infill density is high than 50%
if (region.config().sparse_infill_pattern != InfillPattern::ipLightning && region.config().sparse_infill_density.value < 50)
for (int i = int(layer_it - m_layers.begin()) - 1; i >= 0; --i) {
const Layer* lower_layer = m_layers[i];
if (lower_layer->print_z < bottom_z) break;
for (LayerRegion* lower_layerm : lower_layer->m_regions) {
Polygons lower_internal;
lower_layerm->fill_surfaces.filter_by_type(stInternal, &lower_internal);
ExPolygons internal_with_loop = intersection_ex(lower_internal, to_bridge);
ExPolygons internal = diff_ex(lower_internal, to_bridge);
if (internal_with_loop.empty()) {
//BBS: don't need to do anything
}
else if (internal.empty()) {
lower_layerm->fill_surfaces.change_to_new_type(stInternal, stInternalWithLoop);
}
else {
lower_layerm->fill_surfaces.remove_type(stInternal);
for (ExPolygon& ex : internal_with_loop)
lower_layerm->fill_surfaces.surfaces.push_back(Surface(stInternalWithLoop, ex));
for (ExPolygon& ex : internal)
lower_layerm->fill_surfaces.surfaces.push_back(Surface(stInternal, ex));
}
}
}
}
/*
# exclude infill from the layers below if needed
# see discussion at https://github.com/alexrj/Slic3r/issues/240
@ -1895,8 +1949,7 @@ bool PrintObject::update_layer_height_profile(const ModelObject &model_object, c
{
bool updated = false;
//BBS:annotate these part and will do adaptive layer height below
/*if (layer_height_profile.empty()) {
if (layer_height_profile.empty()) {
// use the constructor because the assignement is crashing on ASAN OsX
layer_height_profile = std::vector<coordf_t>(model_object.layer_height_profile.get());
// layer_height_profile = model_object.layer_height_profile;
@ -1911,22 +1964,11 @@ bool PrintObject::update_layer_height_profile(const ModelObject &model_object, c
std::abs(layer_height_profile[layer_height_profile.size() - 2] - slicing_parameters.object_print_z_max + slicing_parameters.object_print_z_min) > 1e-3))
layer_height_profile.clear();
if (layer_height_profile.empty()) {
if (layer_height_profile.empty() || layer_height_profile[1] != slicing_parameters.first_object_layer_height) {
//layer_height_profile = layer_height_profile_adaptive(slicing_parameters, model_object.layer_config_ranges, model_object.volumes);
layer_height_profile = layer_height_profile_from_ranges(slicing_parameters, model_object.layer_config_ranges);
updated = true;
}*/
//BBS
if (slicing_parameters.adaptive_layer_height) {
layer_height_profile = layer_height_profile_adaptive(slicing_parameters, model_object, 0.5);
HeightProfileSmoothingParams smoothing_params(5, true);
layer_height_profile = smooth_height_profile(layer_height_profile, slicing_parameters, smoothing_params);
}
else {
layer_height_profile = layer_height_profile_from_ranges(slicing_parameters, model_object.layer_config_ranges);
}
updated = true;
return updated;
}
@ -2048,9 +2090,7 @@ void PrintObject::discover_horizontal_shells()
#endif
// If ensure_vertical_shell_thickness, then the rest has already been performed by discover_vertical_shells().
//BBS
//if (region_config.ensure_vertical_shell_thickness.value)
if (PrintObject::ensure_vertical_shell_thickness)
if (region_config.ensure_vertical_shell_thickness.value)
continue;
coordf_t print_z = layer->print_z;
@ -2772,6 +2812,10 @@ static void project_triangles_to_slabs(ConstLayerPtrsAdaptor layers, const index
void PrintObject::project_and_append_custom_facets(
bool seam, EnforcerBlockerType type, std::vector<Polygons>& out) const
{
// BBS: Approve adding enforcer support on vertical faces
SlabSlicingConfig config;
config.isVertical = true;
for (const ModelVolume* mv : this->model_object()->volumes)
if (mv->is_model_part()) {
const indexed_triangle_set custom_facets = seam
@ -2785,7 +2829,7 @@ void PrintObject::project_and_append_custom_facets(
else {
std::vector<Polygons> projected;
// Support blockers or enforcers. Project downward facing painted areas upwards to their respective slicing plane.
slice_mesh_slabs(custom_facets, zs_from_layers(this->layers()), this->trafo_centered() * mv->get_matrix(), nullptr, &projected, [](){});
slice_mesh_slabs(custom_facets, zs_from_layers(this->layers()), this->trafo_centered() * mv->get_matrix(), nullptr, &projected, [](){}, config);
// Merge these projections with the output, layer by layer.
assert(! projected.empty());
assert(out.empty() || out.size() == projected.size());

View file

@ -18,7 +18,6 @@ namespace Slic3r {
bool PrintObject::clip_multipart_objects = true;
bool PrintObject::infill_only_where_needed = false;
bool PrintObject::ensure_vertical_shell_thickness = true;
LayerPtrs new_layers(
PrintObject *print_object,
@ -142,13 +141,11 @@ static std::vector<VolumeSlices> slice_volumes_inner(
//BBS: 0.0025mm is safe enough to simplify the data to speed slicing up for high-resolution model.
//Also has on influence on arc fitting which has default resolution 0.0125mm.
params_base.resolution = 0.0025;
//BBS: remove slice mode, always regular
//switch (print_object_config.slicing_mode.value) {
//case SlicingMode::Regular: params_base.mode = MeshSlicingParams::SlicingMode::Regular; break;
//case SlicingMode::EvenOdd: params_base.mode = MeshSlicingParams::SlicingMode::EvenOdd; break;
//case SlicingMode::CloseHoles: params_base.mode = MeshSlicingParams::SlicingMode::Positive; break;
//}
params_base.mode = MeshSlicingParams::SlicingMode::Regular;
switch (print_object_config.slicing_mode.value) {
case SlicingMode::Regular: params_base.mode = MeshSlicingParams::SlicingMode::Regular; break;
case SlicingMode::EvenOdd: params_base.mode = MeshSlicingParams::SlicingMode::EvenOdd; break;
case SlicingMode::CloseHoles: params_base.mode = MeshSlicingParams::SlicingMode::Positive; break;
}
params_base.mode_below = params_base.mode;
@ -584,7 +581,7 @@ void PrintObject::slice()
//BBS: send warning message to slicing callback
if (!warning.empty()) {
BOOST_LOG_TRIVIAL(info) << warning;
this->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL, warning+L(" Object:")+this->m_model_object->name, PrintStateBase::SlicingReplaceInitEmptyLayers);
this->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL, warning, PrintStateBase::SlicingReplaceInitEmptyLayers);
}
// Update bounding boxes, back up raw slices of complex models.
tbb::parallel_for(
@ -938,8 +935,7 @@ void PrintObject::slice_volumes()
//this->active_step_add_warning(
// PrintStateBase::WarningLevel::CRITICAL,
// L("An object has enabled XY Size compensation which will not be used because it is also multi-material painted.\nXY Size "
// "compensation cannot be combined with multi-material painting.") +
// "\n" + (L("Object")) + ": " + this->model_object()->name);
// "compensation cannot be combined with multi-material painting."));
BOOST_LOG_TRIVIAL(info) << "xy compensation will not work for object " << this->model_object()->name << " for multi filament.";
}

View file

@ -37,7 +37,7 @@ bool is_zero_elevation(const SLAPrintObjectConfig &c)
sla::SupportTreeConfig make_support_cfg(const SLAPrintObjectConfig& c)
{
sla::SupportTreeConfig scfg;
scfg.enabled = c.supports_enable.getBool();
scfg.head_front_radius_mm = 0.5*c.support_head_front_diameter.getFloat();
double pillar_r = 0.5 * c.support_pillar_diameter.getFloat();
@ -66,18 +66,18 @@ sla::SupportTreeConfig make_support_cfg(const SLAPrintObjectConfig& c)
scfg.pillar_base_safety_distance_mm =
c.support_base_safety_distance.getFloat() < EPSILON ?
scfg.safety_distance_mm : c.support_base_safety_distance.getFloat();
scfg.max_bridges_on_pillar = unsigned(c.support_max_bridges_on_pillar.getInt());
return scfg;
}
sla::PadConfig::EmbedObject builtin_pad_cfg(const SLAPrintObjectConfig& c)
{
sla::PadConfig::EmbedObject ret;
ret.enabled = is_zero_elevation(c);
if(ret.enabled) {
ret.everywhere = c.pad_around_object_everywhere.getBool();
ret.object_gap_mm = c.pad_object_gap.getFloat();
@ -86,24 +86,24 @@ sla::PadConfig::EmbedObject builtin_pad_cfg(const SLAPrintObjectConfig& c)
ret.stick_penetration_mm = c.pad_object_connector_penetration
.getFloat();
}
return ret;
}
sla::PadConfig make_pad_cfg(const SLAPrintObjectConfig& c)
{
sla::PadConfig pcfg;
pcfg.wall_thickness_mm = c.pad_wall_thickness.getFloat();
pcfg.wall_slope = c.pad_wall_slope.getFloat() * PI / 180.0;
pcfg.max_merge_dist_mm = c.pad_max_merge_distance.getFloat();
pcfg.wall_height_mm = c.pad_wall_height.getFloat();
pcfg.brim_size_mm = c.pad_brim_size.getFloat();
// set builtin pad implicitly ON
pcfg.embed_object = builtin_pad_cfg(c);
return pcfg;
}
@ -174,8 +174,8 @@ static std::vector<SLAPrintObject::Instance> sla_instances(const ModelObject &mo
return instances;
}
std::vector<ObjectID> SLAPrint::print_object_ids() const
{
std::vector<ObjectID> SLAPrint::print_object_ids() const
{
std::vector<ObjectID> out;
// Reserve one more for the caller to append the ID of the Print itself.
out.reserve(m_objects.size() + 1);
@ -238,7 +238,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
m_material_config.apply_only(config, material_diff, true);
// Handle changes to object config defaults
m_default_object_config.apply_only(config, object_diff, true);
if (m_printer) m_printer->apply(m_printer_config);
struct ModelObjectStatus {
@ -429,7 +429,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
model_object.sla_support_points = model_object_new.sla_support_points;
}
model_object.sla_points_status = model_object_new.sla_points_status;
// Invalidate hollowing if drain holes have changed
if (model_object.sla_drain_holes != model_object_new.sla_drain_holes)
{
@ -629,15 +629,15 @@ StringObjectException SLAPrint::validate(StringObjectException *exception, Polyg
sla::SupportTreeConfig cfg = make_support_cfg(po->config());
double elv = cfg.object_elevation_mm;
sla::PadConfig padcfg = make_pad_cfg(po->config());
sla::PadConfig::EmbedObject &builtinpad = padcfg.embed_object;
if(supports_en && !builtinpad.enabled && elv < cfg.head_fullwidth())
return {L(
"Elevation is too low for object. Use the \"Pad around "
"object\" feature to print the object without elevation."), po};
if(supports_en && builtinpad.enabled &&
cfg.pillar_base_safety_distance_mm < builtinpad.object_gap_mm) {
return {L(
@ -646,7 +646,7 @@ StringObjectException SLAPrint::validate(StringObjectException *exception, Polyg
"distance' has to be greater than the 'Pad object gap' "
"parameter to avoid this."), po};
}
std::string pval = padcfg.validate();
if (!pval.empty()) return {pval, po};
}
@ -686,7 +686,7 @@ bool SLAPrint::invalidate_step(SLAPrintStep step)
return invalidated;
}
void SLAPrint::process()
void SLAPrint::process(bool use_cache)
{
if (m_objects.empty())
return;
@ -695,7 +695,7 @@ void SLAPrint::process()
// Assumption: at this point the print objects should be populated only with
// the model objects we have to process and the instances are also filtered
Steps printsteps(this);
// We want to first process all objects...
@ -709,7 +709,7 @@ void SLAPrint::process()
};
SLAPrintStep print_steps[] = { slapsMergeSlicesAndEval, slapsRasterize };
double st = Steps::min_objstatus;
BOOST_LOG_TRIVIAL(info) << "Start slicing process.";
@ -749,7 +749,7 @@ void SLAPrint::process()
throw_if_canceled();
po->set_done(step);
}
incr = printsteps.progressrange(step);
}
}
@ -760,7 +760,7 @@ void SLAPrint::process()
// this would disable the rasterization step
// std::fill(m_stepmask.begin(), m_stepmask.end(), false);
st = Steps::max_objstatus;
for(SLAPrintStep currentstep : print_steps) {
throw_if_canceled();
@ -774,7 +774,7 @@ void SLAPrint::process()
throw_if_canceled();
set_done(currentstep);
}
st += printsteps.progressrange(currentstep);
}
@ -1132,7 +1132,7 @@ const TriangleMesh& SLAPrintObject::support_mesh() const
{
if(m_config.supports_enable.getBool() && m_supportdata)
return m_supportdata->tree_mesh;
return EMPTY_MESH;
}
@ -1149,7 +1149,7 @@ const indexed_triangle_set &SLAPrintObject::hollowed_interior_mesh() const
if (m_hollowing_data && m_hollowing_data->interior &&
m_config.hollowing_enable.getBool())
return sla::get_mesh(*m_hollowing_data->interior);
return EMPTY_TRIANGLE_SET;
}
@ -1174,7 +1174,7 @@ sla::SupportPoints SLAPrintObject::transformed_support_points() const
for (sla::SupportPoint& suppt : spts) {
suppt.pos = tr * suppt.pos;
}
return spts;
}

View file

@ -77,7 +77,7 @@ public:
// Get a pad mesh centered around origin in XY, and with zero rotation around Z applied.
// Support mesh is only valid if this->is_step_done(slaposPad) is true.
const TriangleMesh& pad_mesh() const;
// Ready after this->is_step_done(slaposDrillHoles) is true
const indexed_triangle_set &hollowed_interior_mesh() const;
@ -201,7 +201,7 @@ private:
{
return level<T>(r1) < level<T>(r2);
});
if(it == cont.end()) return it;
T diff = std::abs(level<T>(*it) - lvl);
@ -307,18 +307,18 @@ private:
// Caching the transformed (m_trafo) raw mesh of the object
mutable CachedObject<TriangleMesh> m_transformed_rmesh;
class SupportData : public sla::SupportableMesh
{
public:
sla::SupportTree::UPtr support_tree_ptr; // the supports
std::vector<ExPolygons> support_slices; // sliced supports
TriangleMesh tree_mesh, pad_mesh, full_mesh;
inline SupportData(const TriangleMesh &t)
: sla::SupportableMesh{t.its, {}, {}}
{}
sla::SupportTree::UPtr &create_support_tree(const sla::JobController &ctl)
{
support_tree_ptr = sla::SupportTree::create(*this, ctl);
@ -335,9 +335,9 @@ private:
pad_mesh = TriangleMesh{support_tree_ptr->retrieve_mesh(sla::MeshType::Pad)};
}
};
std::unique_ptr<SupportData> m_supportdata;
class HollowingData
{
public:
@ -346,7 +346,7 @@ private:
mutable TriangleMesh hollow_mesh_with_holes; // caching the complete hollowed mesh
mutable TriangleMesh hollow_mesh_with_holes_trimmed;
};
std::unique_ptr<HollowingData> m_hollowing_data;
};
@ -390,15 +390,15 @@ struct SLAPrintStatistics
class SLAArchive {
protected:
std::vector<sla::EncodedRaster> m_layers;
virtual std::unique_ptr<sla::RasterBase> create_raster() const = 0;
virtual sla::RasterEncoder get_encoder() const = 0;
public:
virtual ~SLAArchive() = default;
virtual void apply(const SLAPrinterConfig &cfg) = 0;
// Fn have to be thread safe: void(sla::RasterBase& raster, size_t lyrid);
template<class Fn, class CancelFn, class EP = ExecutionTBB>
void draw_layers(
@ -434,9 +434,9 @@ class SLAPrint : public PrintBaseWithState<SLAPrintStep, slapsCount>
{
private: // Prevents erroneous use by other classes.
typedef PrintBaseWithState<SLAPrintStep, slapsCount> Inherited;
class Steps; // See SLAPrintSteps.cpp
public:
SLAPrint(): m_stepmask(slapsCount, true) {}
@ -451,7 +451,7 @@ public:
std::vector<ObjectID> print_object_ids() const override;
ApplyStatus apply(const Model &model, DynamicPrintConfig config) override;
void set_task(const TaskParams &params) override;
void process() override;
void process(bool use_cache = false) override;
void finalize() override;
// Returns true if an object step is done on all objects and there's at least one object.
bool is_step_done(SLAPrintObjectStep step) const;
@ -501,11 +501,11 @@ public:
{
m_transformed_slices = std::forward<Container>(c);
}
friend class SLAPrint::Steps;
public:
explicit PrintLayer(coord_t lvl) : m_level(lvl) {}
// for being sorted in their container (see m_printer_input)
@ -527,11 +527,11 @@ public:
// The aggregated and leveled print records from various objects.
// TODO: use this structure for the preview in the future.
const std::vector<PrintLayer>& print_layers() const { return m_printer_input; }
void set_printer(SLAArchive *archiver);
private:
// Implement same logic as in SLAPrintObject
bool invalidate_step(SLAPrintStep st);
@ -548,24 +548,24 @@ private:
// Ready-made data for rasterization.
std::vector<PrintLayer> m_printer_input;
// The archive object which collects the raster images after slicing
SLAArchive *m_printer = nullptr;
// Estimated print time, material consumed.
SLAPrintStatistics m_print_statistics;
class StatusReporter
{
double m_st = 0;
public:
void operator()(SLAPrint & p,
double st,
const std::string &msg,
unsigned flags = SlicingStatus::DEFAULT,
const std::string &logmsg = "");
double status() const { return m_st; }
} m_report_status;

View file

@ -30,6 +30,17 @@
namespace Slic3r {
static std::map<std::string, std::string> g_occt_fonts_maps; //map<font_name, font_path>
static const std::vector<Standard_CString> fonts_suffix{ "Bold", "Medium", "Heavy", "Italic", "Oblique", "Inclined", "Light", "Thin",
"Semibold", "ExtraBold", "ExtraBold", "Semilight", "SemiLight", "ExtraLight", "Extralight", "Ultralight",
"Condensed", "Ultra", "Extra", "Expanded", "Extended", "1", "2", "3", "4", "5", "6", "7", "8", "9", "Al Tarikh"};
std::map<std::string, std::string> get_occt_fonts_maps()
{
return g_occt_fonts_maps;
}
std::vector<std::string> init_occt_fonts()
{
std::vector<std::string> stdFontNames;
@ -41,9 +52,46 @@ std::vector<std::string> init_occt_fonts()
aFontMgr->GetAvailableFontsNames(availFontNames);
stdFontNames.reserve(availFontNames.Size());
for (auto afn : availFontNames)
stdFontNames.push_back(afn->ToCString());
g_occt_fonts_maps.clear();
BOOST_LOG_TRIVIAL(info) << "init_occt_fonts start";
#ifdef __APPLE__
//from resource
stdFontNames.push_back("HarmonyOS Sans SC");
g_occt_fonts_maps.insert(std::make_pair("HarmoneyOS Sans SC", Slic3r::resources_dir() + "/fonts/" + "HarmonyOS_Sans_SC_Regular.ttf"));
#endif
for (auto afn : availFontNames) {
#ifdef __APPLE__
if(afn->String().StartsWith("."))
continue;
#endif
if(afn->Search("Emoji") != -1 || afn->Search("emoji") != -1)
continue;
bool repeat = false;
for (size_t i = 0; i < fonts_suffix.size(); i++) {
if (afn->SearchFromEnd(fonts_suffix[i]) != -1) {
repeat = true;
break;
}
}
if (repeat)
continue;
Handle(Font_SystemFont) sys_font = aFontMgr->GetFont(afn->ToCString());
TCollection_AsciiString font_path = sys_font->FontPath(Font_FontAspect::Font_FontAspect_Regular);
if (!font_path.IsEmpty() && font_path.SearchFromEnd(".") != -1) {
auto file_type = font_path.SubString(font_path.SearchFromEnd(".") + 1, font_path.Length());
file_type.LowerCase();
if (file_type == "ttf" || file_type == "otf" || file_type == "ttc") {
g_occt_fonts_maps.insert(std::make_pair(afn->ToCString(), decode_path(font_path.ToCString())));
}
}
}
BOOST_LOG_TRIVIAL(info) << "init_occt_fonts end";
// in order
for (auto occt_font : g_occt_fonts_maps) {
stdFontNames.push_back(occt_font.first);
}
return stdFontNames;
}

View file

@ -7,6 +7,8 @@ class TriangleMesh;
extern std::vector<std::string> init_occt_fonts();
extern void load_text_shape(const char* text, const char* font, const float text_height, const float thickness, bool is_bold, bool is_italic, TriangleMesh& text_mesh);
std::map<std::string, std::string> get_occt_fonts_maps();
}; // namespace Slic3r
#endif // slic3r_Text_Shape_hpp_

View file

@ -24,6 +24,19 @@ void chain_and_reorder_extrusion_paths(std::vect
Polylines chain_polylines(Polylines &&src, const Point *start_near = nullptr);
inline Polylines chain_polylines(const Polylines& src, const Point* start_near = nullptr) { Polylines tmp(src); return chain_polylines(std::move(tmp), start_near); }
template<typename T> inline void reorder_by_shortest_traverse(std::vector<T> &polylines_out)
{
Points start_point;
start_point.reserve(polylines_out.size());
for (const T contour : polylines_out) start_point.push_back(contour.points.front());
std::vector<Points::size_type> order = chain_points(start_point);
std::vector<T> Temp = polylines_out;
polylines_out.erase(polylines_out.begin(), polylines_out.end());
for (size_t i:order) polylines_out.emplace_back(std::move(Temp[i]));
}
std::vector<ClipperLib::PolyNode*> chain_clipper_polynodes(const Points &points, const std::vector<ClipperLib::PolyNode*> &items);

View file

@ -84,8 +84,6 @@ SlicingParameters SlicingParameters::create_from_config(
params.object_print_z_max = object_height;
params.base_raft_layers = object_config.raft_layers.value;
params.soluble_interface = soluble_interface;
//BBS
params.adaptive_layer_height = print_config.enable_prime_tower ? false : object_config.adaptive_layer_height;
// Miniumum/maximum of the minimum layer height over all extruders.
params.min_layer_height = MIN_LAYER_HEIGHT;
@ -115,13 +113,12 @@ SlicingParameters SlicingParameters::create_from_config(
if (! soluble_interface) {
params.gap_raft_object = object_config.raft_contact_distance.value;
//BBS
//params.gap_object_support = object_config.support_bottom_z_distance.value;
params.gap_object_support = object_config.support_top_z_distance.value;
params.gap_object_support = object_config.support_bottom_z_distance.value;
params.gap_support_object = object_config.support_top_z_distance.value;
if (params.gap_object_support <= 0)
params.gap_object_support = params.gap_support_object;
if (!object_config.independent_support_layer_height) {
if (!print_config.independent_support_layer_height) {
params.gap_raft_object = std::round(params.gap_raft_object / object_config.layer_height + EPSILON) * object_config.layer_height;
params.gap_object_support = std::round(params.gap_object_support / object_config.layer_height + EPSILON) * object_config.layer_height;
params.gap_support_object = std::round(params.gap_support_object / object_config.layer_height + EPSILON) * object_config.layer_height;
@ -400,31 +397,32 @@ std::vector<double> smooth_height_profile(const std::vector<double>& profile, co
};
//BBS: avoid the layer height change to be too steep
auto has_steep_height_change = [&slicing_params](const std::vector<double>& profile, const double height_step) {
//BBS: skip first layer
size_t skip_count = slicing_params.first_object_layer_height_fixed() ? 4 : 0;
size_t size = profile.size();
//BBS: not enough data to smmoth, return false directly
if ((int)size - (int)skip_count < 6)
return false;
//auto has_steep_height_change = [&slicing_params](const std::vector<double>& profile, const double height_step) {
// //BBS: skip first layer
// size_t skip_count = slicing_params.first_object_layer_height_fixed() ? 4 : 0;
// size_t size = profile.size();
// //BBS: not enough data to smmoth, return false directly
// if ((int)size - (int)skip_count < 6)
// return false;
//BBS: Don't need to check the difference between top layer and the last 2th layer
for (size_t i = skip_count; i < size - 6; i += 2) {
if (abs(profile[i + 1] - profile[i + 3]) > height_step)
return true;
}
return false;
};
// //BBS: Don't need to check the difference between top layer and the last 2th layer
// for (size_t i = skip_count; i < size - 6; i += 2) {
// if (abs(profile[i + 1] - profile[i + 3]) > height_step)
// return true;
// }
// return false;
//};
int count = 0;
std::vector<double> ret = profile;
bool has_steep_change = has_steep_height_change(ret, LAYER_HEIGHT_CHANGE_STEP);
while (has_steep_change && count < 6) {
ret = gauss_blur(ret, smoothing_params);
has_steep_change = has_steep_height_change(ret, LAYER_HEIGHT_CHANGE_STEP);
count++;
}
return ret;
//int count = 0;
//std::vector<double> ret = profile;
//bool has_steep_change = has_steep_height_change(ret, LAYER_HEIGHT_CHANGE_STEP);
//while (has_steep_change && count < 6) {
// ret = gauss_blur(ret, smoothing_params);
// has_steep_change = has_steep_height_change(ret, LAYER_HEIGHT_CHANGE_STEP);
// count++;
//}
//return ret;
return gauss_blur(profile, smoothing_params);
}
void adjust_layer_height_profile(

View file

@ -96,8 +96,6 @@ struct SlicingParameters
// In case of a soluble interface, object_print_z_min == raft_contact_top_z, otherwise there is a gap between the raft and the 1st object layer.
coordf_t object_print_z_min { 0 };
coordf_t object_print_z_max { 0 };
//BBS
bool adaptive_layer_height{ false };
};
static_assert(IsTriviallyCopyable<SlicingParameters>::value, "SlicingParameters class is not POD (and it should be - see constructor).");

View file

@ -1512,11 +1512,22 @@ static inline Polygons detect_overhangs(
0.;
const coordf_t max_bridge_length = scale_(object_config.max_bridge_length.value);
const bool bridge_no_support = object_config.bridge_no_support.value;
const coordf_t xy_expansion = scale_(object_config.support_expansion.value);
if (layer_id == 0)
if (layer_id == 0)
{
// Don't fill in the holes. The user may apply a higher raft_expansion if one wants a better 1st layer adhesion.
overhang_polygons = to_polygons(layer.lslices);
for (auto& slice : layer.lslices) {
auto bbox_size = get_extents(slice).size();
if (g_config_support_sharp_tails &&
!(bbox_size.x() > length_thresh_well_supported && bbox_size.y() > length_thresh_well_supported))
{
layer.sharp_tails.push_back(slice);
layer.sharp_tails_height.insert({ &slice, layer.height });
}
}
}
else if (! layer.regions().empty())
{
@ -1567,9 +1578,9 @@ static inline Polygons detect_overhangs(
// Offset the support regions back to a full overhang, restrict them to the full overhang.
// This is done to increase size of the supporting columns below, as they are calculated by
// propagating these contact surfaces downwards.
diff_polygons = diff(
intersection(expand(diff_polygons, lower_layer_offset, SUPPORT_SURFACES_OFFSET_PARAMETERS), layerm_polygons),
lower_layer_polygons);
diff_polygons =
expand(diff(intersection(expand(diff_polygons, lower_layer_offset, SUPPORT_SURFACES_OFFSET_PARAMETERS), layerm_polygons), lower_layer_polygons),
xy_expansion, SUPPORT_SURFACES_OFFSET_PARAMETERS);
}
//FIXME add user defined filtering here based on minimal area or minimum radius or whatever.
@ -1608,12 +1619,12 @@ static inline Polygons detect_overhangs(
supported_area += temp.area();
bbox.merge(get_extents(temp));
}
#if 0
if (supported_area > area_thresh_well_supported) {
is_sharp_tail = false;
break;
}
#endif
if (bbox.size().x() > length_thresh_well_supported && bbox.size().y() > length_thresh_well_supported) {
is_sharp_tail = false;
break;
@ -1839,7 +1850,7 @@ static inline std::pair<PrintObjectSupportMaterial::MyLayer*, PrintObjectSupport
bottom_z = (layer_id == 1) ? slicing_params.object_print_z_min : layer.lower_layer->lower_layer->print_z;
} else {
print_z = layer.bottom_z() - slicing_params.gap_support_object;
height = object_config.independent_support_layer_height ? 0. : object_config.layer_height;
height = print_config.independent_support_layer_height ? 0. : object_config.layer_height;
bottom_z = print_z - height;
// Ignore this contact area if it's too low.
// Don't want to print a layer below the first layer height as it may not stick well.
@ -1870,7 +1881,7 @@ static inline std::pair<PrintObjectSupportMaterial::MyLayer*, PrintObjectSupport
bridging_height += region->region().bridging_height_avg(print_config);
bridging_height /= coordf_t(layer.regions().size());
// BBS: align bridging height
if (!object_config.independent_support_layer_height)
if (!print_config.independent_support_layer_height)
bridging_height = std::ceil(bridging_height / object_config.layer_height - EPSILON) * object_config.layer_height;
coordf_t bridging_print_z = layer.print_z - bridging_height - slicing_params.gap_support_object;
if (bridging_print_z >= min_print_z) {
@ -1890,7 +1901,7 @@ static inline std::pair<PrintObjectSupportMaterial::MyLayer*, PrintObjectSupport
} else {
// BBS: if independent_support_layer_height is not enabled, the support layer_height should be the same as layer height.
// Note that for this case, adaptive layer height must be disabled.
bridging_layer->height = object_config.independent_support_layer_height ? 0. : object_config.layer_height;
bridging_layer->height = print_config.independent_support_layer_height ? 0. : object_config.layer_height;
// Don't know the height yet.
bridging_layer->bottom_z = bridging_print_z - bridging_layer->height;
}
@ -2423,7 +2434,7 @@ static inline PrintObjectSupportMaterial::MyLayer* detect_bottom_contacts(
// top shapes so this can be done here
//FIXME calculate layer height based on the actual thickness of the layer:
// If the layer is extruded with no bridging flow, support just the normal extrusions.
layer_new.height = slicing_params.soluble_interface || !object.config().independent_support_layer_height ?
layer_new.height = slicing_params.soluble_interface || !object.print()->config().independent_support_layer_height ?
// Align the interface layer with the object's layer height.
layer.upper_layer->height :
// Place a bridge flow interface layer or the normal flow interface layer over the top surface.
@ -4517,9 +4528,13 @@ void PrintObjectSupportMaterial::generate_toolpaths(
(m_object_config->support_interface_bottom_layers == 0 && &layer_ex == &bottom_contact_layer);
//FIXME Bottom interfaces are extruded with the briding flow. Some bridging layers have its height slightly reduced, therefore
// the bridging flow does not quite apply. Reduce the flow to area of an ellipse? (A = pi * a * b)
auto interface_flow = layer_ex.layer->bridging ?
Flow::bridging_flow(layer_ex.layer->height, m_support_params.support_material_bottom_interface_flow.nozzle_diameter()) :
(interface_as_base ? &m_support_params.support_material_flow : &m_support_params.support_material_interface_flow)->with_height(float(layer_ex.layer->height));
Flow interface_flow;
if (layer_ex.layer->bridging)
interface_flow = Flow::bridging_flow(layer_ex.layer->height, m_support_params.support_material_bottom_interface_flow.nozzle_diameter());
else if (layer_ex.layer->bottom_z < EPSILON) {
interface_flow = m_support_params.first_layer_flow;
}else
interface_flow = (interface_as_base ? &m_support_params.support_material_flow : &m_support_params.support_material_interface_flow)->with_height(float(layer_ex.layer->height));
filler_interface->angle = interface_as_base ?
// If zero interface layers are configured, use the same angle as for the base layers.
angles[support_layer_id % angles.size()] :

View file

@ -136,6 +136,7 @@ public:
float base_angle;
float interface_angle;
coordf_t interface_spacing;
coordf_t support_expansion;
coordf_t interface_density;
coordf_t support_spacing;
coordf_t support_density;
@ -161,7 +162,7 @@ public:
bool has_support() const { return m_object_config->enable_support.value || m_object_config->enforce_support_layers; }
bool build_plate_only() const { return this->has_support() && m_object_config->support_on_build_plate_only.value; }
// BBS
bool synchronize_layers() const { return /*m_slicing_params.soluble_interface && */!m_object_config->independent_support_layer_height.value; }
bool synchronize_layers() const { return /*m_slicing_params.soluble_interface && */!m_print_config->independent_support_layer_height.value; }
bool has_contact_loops() const { return m_object_config->support_interface_loop_pattern.value; }
// Generate support material for the object.

Some files were not shown because too many files have changed in this diff Show more