mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-26 10:21:00 +00:00
Merge remote-tracking branch 'upstream/main' into haryr/aug25-rebase
# Conflicts: # src/libslic3r/Support/TreeSupport.cpp
This commit is contained in:
+15
-1
@@ -75,7 +75,7 @@ if (SLIC3R_GUI)
|
||||
list(FILTER wxWidgets_LIBRARIES EXCLUDE REGEX expat)
|
||||
list(APPEND wxWidgets_LIBRARIES ${EXPAT_LIBRARIES})
|
||||
endif ()
|
||||
|
||||
|
||||
# This is an issue in the new wxWidgets cmake build, doesn't deal with librt
|
||||
find_library(LIBRT rt)
|
||||
if(LIBRT)
|
||||
@@ -300,6 +300,16 @@ if (WIN32)
|
||||
endif()
|
||||
|
||||
else ()
|
||||
if (NOT APPLE)
|
||||
set(output_sos_Release "")
|
||||
set(output_sos_Debug "")
|
||||
add_custom_target(OrcaSlicerSosCopy ALL DEPENDS OrcaSlicer)
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
||||
orcaslicer_copy_sos(OrcaSlicerSosCopy "Debug" "d" output_sos_Debug)
|
||||
else()
|
||||
orcaslicer_copy_sos(OrcaSlicerSosCopy "Release" "" output_sos_Release)
|
||||
endif()
|
||||
endif()
|
||||
if (APPLE AND NOT CMAKE_MACOSX_BUNDLE)
|
||||
# On OSX, the name of the binary matches the name of the Application.
|
||||
add_custom_command(TARGET OrcaSlicer POST_BUILD
|
||||
@@ -378,5 +388,9 @@ if (WIN32)
|
||||
install(FILES ${output_dlls_${build_type}} DESTINATION ".")
|
||||
install(DIRECTORY "${CMAKE_PREFIX_PATH}/libpython/" DESTINATION "python")
|
||||
else ()
|
||||
if (APPLE)
|
||||
else()
|
||||
install(FILES ${output_sos_${build_type}} DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
endif()
|
||||
install(TARGETS OrcaSlicer RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif ()
|
||||
|
||||
@@ -83,6 +83,10 @@ copy_shared_object_to_dir() {
|
||||
src_real="$(readlink -f "$src")"
|
||||
dst_name="$(basename "$src_real")"
|
||||
mkdir -p "$dst_dir"
|
||||
if [ "$src_real" = "$dst_dir/$dst_name" ]; then
|
||||
# Already bundled; the dependency resolved from the bundle directory.
|
||||
return 0
|
||||
fi
|
||||
cp -fL "$src_real" "$dst_dir/$dst_name"
|
||||
|
||||
if [ -L "$src" ]; then
|
||||
@@ -96,12 +100,23 @@ copy_shared_object_to_dir() {
|
||||
}
|
||||
|
||||
bundle_dependency_closure() {
|
||||
local dst_dir="$1"
|
||||
local dst_dir
|
||||
dst_dir="$(cd -- "$1" && pwd)"
|
||||
shift
|
||||
|
||||
local -a queue=("$@")
|
||||
local target dep dep_real copied_path
|
||||
local target dep dep_real dep_key copied_path
|
||||
declare -A seen=()
|
||||
# Dependencies are resolved with ldd, which only searches the default
|
||||
# loader path. Deps-built shared libraries (e.g. the FFmpeg stack) are not
|
||||
# installed there and carry no RUNPATH of their own, so once copied into
|
||||
# the bundle ldd can no longer resolve one sibling from another
|
||||
# (libavcodec -> libavutil) and reports it as missing. Extend the loader
|
||||
# path with the bundle directory plus the source directories of files
|
||||
# already bundled, so every library that was resolved once keeps resolving
|
||||
# for its own dependencies. The audit script does the same
|
||||
# (scripts/check_appimage_libs.sh).
|
||||
local -a search_dirs=("$dst_dir")
|
||||
|
||||
while [ ${#queue[@]} -gt 0 ]; do
|
||||
target="${queue[0]}"
|
||||
@@ -122,17 +137,24 @@ bundle_dependency_closure() {
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ -n "${seen[$dep_real]}" ]; then
|
||||
# Key dedup on the bundled file rather than the source path: once
|
||||
# ldd resolves a library from the bundle directory (via the
|
||||
# LD_LIBRARY_PATH above) its path is a dst_dir path, which differs
|
||||
# from the source path the first resolution returned. Keying on
|
||||
# the source path would re-copy the file onto itself.
|
||||
dep_key="$dst_dir/$(basename "$dep_real")"
|
||||
if [ -n "${seen[$dep_key]}" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
seen[$dep_real]=1
|
||||
seen[$dep_key]=1
|
||||
copy_shared_object_to_dir "$dep" "$dst_dir"
|
||||
search_dirs+=("$(dirname "$dep_real")")
|
||||
copied_path="$dst_dir/$(basename "$dep_real")"
|
||||
if [ -e "$copied_path" ]; then
|
||||
queue+=("$copied_path")
|
||||
fi
|
||||
done < <(appimage_list_direct_dependencies "$target")
|
||||
done < <(LD_LIBRARY_PATH="$(IFS=:; printf '%s' "${search_dirs[*]}")${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" appimage_list_direct_dependencies "$target")
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ public:
|
||||
m_bbox(bbox.min - Point(SCALED_EPSILON, SCALED_EPSILON), bbox.max + Point(SCALED_EPSILON, SCALED_EPSILON)) {}
|
||||
size_t idx() const { return m_idx; }
|
||||
const BoundingBox& bbox() const { return m_bbox; }
|
||||
Point centroid() const { return (m_bbox.min() + m_bbox.max() / 2); }
|
||||
Point centroid() const { return (m_bbox.min() + m_bbox.max()) / 2; }
|
||||
private:
|
||||
size_t m_idx;
|
||||
BoundingBox m_bbox;
|
||||
|
||||
@@ -57,24 +57,24 @@ void ArcFitter::do_arc_fitting(const Points& points, std::vector<PathFittingData
|
||||
//BBS: can be fit as arc, then save arc data temperarily
|
||||
last_arc = target_arc;
|
||||
if (back_index == points.size() - 1) {
|
||||
result.emplace_back(std::move(PathFittingData{ front_index,
|
||||
result.emplace_back(PathFittingData{ front_index,
|
||||
back_index,
|
||||
last_arc.direction == ArcDirection::Arc_Dir_CCW ? EMovePathType::Arc_move_ccw : EMovePathType::Arc_move_cw,
|
||||
last_arc }));
|
||||
last_arc });
|
||||
front_index = back_index;
|
||||
}
|
||||
} else {
|
||||
if (back_index - front_index > 2) {
|
||||
//BBS: althought current point_stack can't be fit as arc,
|
||||
//but previous must can be fit if removing the top in stack, so save last arc
|
||||
result.emplace_back(std::move(PathFittingData{ front_index,
|
||||
result.emplace_back(PathFittingData{ front_index,
|
||||
back_index - 1,
|
||||
last_arc.direction == ArcDirection::Arc_Dir_CCW ? EMovePathType::Arc_move_ccw : EMovePathType::Arc_move_cw,
|
||||
last_arc }));
|
||||
last_arc });
|
||||
} else {
|
||||
//BBS: save the first segment as line move when 3 point-line can't be fit as arc move
|
||||
if (result.empty() || result.back().path_type != EMovePathType::Linear_move)
|
||||
result.emplace_back(std::move(PathFittingData{front_index, front_index + 1, EMovePathType::Linear_move, ArcSegment()}));
|
||||
result.emplace_back(PathFittingData{front_index, front_index + 1, EMovePathType::Linear_move, ArcSegment()});
|
||||
else if(result.back().path_type == EMovePathType::Linear_move)
|
||||
result.back().end_point_index = front_index + 1;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ void ArcFitter::do_arc_fitting(const Points& points, std::vector<PathFittingData
|
||||
//BBS: handle the remain data
|
||||
if (front_index != back_index) {
|
||||
if (result.empty() || result.back().path_type != EMovePathType::Linear_move)
|
||||
result.emplace_back(std::move(PathFittingData{front_index, back_index, EMovePathType::Linear_move, ArcSegment()}));
|
||||
result.emplace_back(PathFittingData{front_index, back_index, EMovePathType::Linear_move, ArcSegment()});
|
||||
else if (result.back().path_type == EMovePathType::Linear_move)
|
||||
result.back().end_point_index = back_index;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ Slic3r::Polylines Paths64_to_polylines(const Clipper2Lib::Paths64& 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)));
|
||||
points.emplace_back(Slic3r::Point(point64.x, point64.y));
|
||||
out.emplace_back(Slic3r::Polyline(points));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ Clipper2Lib::Paths64 Slic3rPoints_to_Paths64(const Container& 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())));
|
||||
path.emplace_back(Clipper2Lib::Point64(point.x(), point.y()));
|
||||
out.emplace_back(std::move(path));
|
||||
}
|
||||
return out;
|
||||
@@ -44,7 +44,7 @@ Points Path64ToPoints(const Clipper2Lib::Path64& path64)
|
||||
{
|
||||
Points points;
|
||||
points.reserve(path64.size());
|
||||
for (const Clipper2Lib::Point64 &point64 : path64) points.emplace_back(std::move(Slic3r::Point(point64.x, point64.y)));
|
||||
for (const Clipper2Lib::Point64 &point64 : path64) points.emplace_back(Slic3r::Point(point64.x, point64.y));
|
||||
return points;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ Clipper2Lib::Paths64 Slic3rPolygons_to_Paths64(const Polygons &in)
|
||||
for (const Polygon &poly : in) {
|
||||
Clipper2Lib::Path64 path;
|
||||
path.reserve(poly.points.size());
|
||||
for (const Slic3r::Point &point : poly.points) path.emplace_back(std::move(Clipper2Lib::Point64(point.x(), point.y())));
|
||||
for (const Slic3r::Point &point : poly.points) path.emplace_back(Clipper2Lib::Point64(point.x(), point.y()));
|
||||
out.emplace_back(std::move(path));
|
||||
}
|
||||
return out;
|
||||
@@ -114,7 +114,7 @@ Clipper2Lib::Paths64 Slic3rExPolygons_to_Paths64(const ExPolygons& in)
|
||||
const auto &poly = expolygon.contour_or_hole(i);
|
||||
Clipper2Lib::Path64 path;
|
||||
path.reserve(poly.points.size());
|
||||
for (const Slic3r::Point &point : poly.points) path.emplace_back(std::move(Clipper2Lib::Point64(point.x(), point.y())));
|
||||
for (const Slic3r::Point &point : poly.points) path.emplace_back(Clipper2Lib::Point64(point.x(), point.y()));
|
||||
out.emplace_back(std::move(path));
|
||||
}
|
||||
}
|
||||
@@ -134,8 +134,8 @@ Polylines _clipper2_pl_open(Clipper2Lib::ClipType clipType, const Slic3r::Polyli
|
||||
|
||||
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)));
|
||||
polylines_append(out, Paths64_to_polylines(solution));
|
||||
polylines_append(out, Paths64_to_polylines(solution_open));
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -108,6 +108,22 @@ const std::vector<Vec2d>& CornerSmoother::curve_coefficients(
|
||||
return m_cached_coefficients;
|
||||
}
|
||||
|
||||
bool CornerSmoother::is_on_straight_run(const Vec2d &previous, const Vec2d &vertex, const Vec2d &next)
|
||||
{
|
||||
const Vec2d incoming_leg = vertex - previous;
|
||||
const Vec2d outgoing_leg = next - vertex;
|
||||
const double incoming_length = incoming_leg.norm();
|
||||
const double outgoing_length = outgoing_leg.norm();
|
||||
// A vertex repeating one of its neighbours carries no direction of its own.
|
||||
if (incoming_length < EPSILON || outgoing_length < EPSILON)
|
||||
return true;
|
||||
|
||||
const Vec2d incoming = incoming_leg / incoming_length;
|
||||
const Vec2d outgoing = outgoing_leg / outgoing_length;
|
||||
return incoming.dot(outgoing) > 0. &&
|
||||
std::abs(incoming.x() * outgoing.y() - incoming.y() * outgoing.x()) < EPSILON;
|
||||
}
|
||||
|
||||
void CornerSmoother::round_corner(const Vec2d &previous, const Vec2d &corner, const Vec2d &next)
|
||||
{
|
||||
m_corner_points.clear();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
@@ -47,36 +48,57 @@ public:
|
||||
|
||||
template<typename Emit> void push(const Vec2d &point, Emit &emit)
|
||||
{
|
||||
if (m_pending == 0) {
|
||||
if (m_held == 0) {
|
||||
// The first point of a path is an end, not a corner, and stays where it is.
|
||||
emit(point);
|
||||
m_previous = point;
|
||||
} else if (m_pending > 1) {
|
||||
round_corner(m_previous, m_corner, point);
|
||||
for (const Vec2d &corner_point : m_corner_points)
|
||||
emit(corner_point);
|
||||
m_previous = m_corner;
|
||||
m_window[m_held++] = point;
|
||||
return;
|
||||
}
|
||||
m_corner = point;
|
||||
m_pending = std::min(m_pending + 1, 2);
|
||||
if (m_held > 1 && is_on_straight_run(m_window[m_held - 2], m_window[m_held - 1], point)) {
|
||||
// The newest vertex only splits a straight leg, so the leg runs on to this point instead.
|
||||
m_window[m_held - 1] = point;
|
||||
return;
|
||||
}
|
||||
if (m_held < 3) {
|
||||
m_window[m_held++] = point;
|
||||
return;
|
||||
}
|
||||
// Both legs of the middle vertex are complete now, so its curve can no longer grow.
|
||||
emit_corner(m_window[0], m_window[1], m_window[2], emit);
|
||||
m_window[0] = m_window[1];
|
||||
m_window[1] = m_window[2];
|
||||
m_window[2] = point;
|
||||
}
|
||||
|
||||
// Emits the last point of the path and prepares the smoother for a new one.
|
||||
template<typename Emit> void flush(Emit &emit)
|
||||
{
|
||||
if (m_pending > 1)
|
||||
emit(m_corner);
|
||||
m_pending = 0;
|
||||
if (m_held > 2)
|
||||
emit_corner(m_window[0], m_window[1], m_window[2], emit);
|
||||
if (m_held > 1)
|
||||
emit(m_window[m_held - 1]);
|
||||
m_held = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Emit> void emit_corner(const Vec2d &previous, const Vec2d &corner, const Vec2d &next, Emit &emit)
|
||||
{
|
||||
round_corner(previous, corner, next);
|
||||
for (const Vec2d &corner_point : m_corner_points)
|
||||
emit(corner_point);
|
||||
}
|
||||
|
||||
// Tells a vertex that only continues a straight leg (or repeats its predecessor) from a corner.
|
||||
// A path doubling back on itself is not one, that vertex is a hairpin and stays where it is.
|
||||
static bool is_on_straight_run(const Vec2d &previous, const Vec2d &vertex, const Vec2d &next);
|
||||
// Fills m_corner_points with the points replacing the corner vertex.
|
||||
void round_corner(const Vec2d &previous, const Vec2d &corner, const Vec2d &next);
|
||||
// Flattens the canonical corner curve of the given size and turn into coordinates of the
|
||||
// (incoming, outgoing) basis of the corner. Cached, as an infill path repeats the same corner.
|
||||
const std::vector<Vec2d>& curve_coefficients(double corner_distance, const Vec2d &incoming, const Vec2d &outgoing);
|
||||
|
||||
// Fraction of the shorter adjoining segment consumed on each side of a corner. Half of a segment
|
||||
// is the maximum, otherwise the curves of two adjacent corners would overlap.
|
||||
// Fraction of the shorter adjoining leg consumed on each side of a corner. Half of a leg is the
|
||||
// maximum, otherwise the curves of two adjacent corners would overlap.
|
||||
const double m_corner_distance_ratio;
|
||||
const double m_tolerance;
|
||||
const double m_max_corner_distance;
|
||||
@@ -88,10 +110,11 @@ private:
|
||||
double m_cached_cosine { 0. };
|
||||
bool m_has_cached_coefficients { false };
|
||||
|
||||
Vec2d m_previous { Vec2d::Zero() };
|
||||
Vec2d m_corner { Vec2d::Zero() };
|
||||
// Number of points held back: none, the first point of a path, or a corner candidate.
|
||||
int m_pending { 0 };
|
||||
// The corners seen last, kept free of vertices that merely split a straight leg. The middle one
|
||||
// is rounded once the third arrives, which is what makes its outgoing leg final.
|
||||
std::array<Vec2d, 3> m_window { Vec2d::Zero(), Vec2d::Zero(), Vec2d::Zero() };
|
||||
// How many of them are filled in.
|
||||
int m_held { 0 };
|
||||
};
|
||||
|
||||
// Rounds the corners of already scaled paths in place. Paths of less than three points are left alone.
|
||||
|
||||
@@ -55,9 +55,9 @@ bool load_obj(const char *path, TriangleMesh *meshptr, ObjInfo& obj_info, std::s
|
||||
boost::filesystem::path temp_mtl_path(mtl_file);
|
||||
mtl_path = temp_mtl_path;
|
||||
}
|
||||
auto _mtl_path = mtl_name_is_path ? mtl_abs_path.string().c_str() : mtl_path.string().c_str();
|
||||
const std::string _mtl_path = (mtl_name_is_path ? mtl_abs_path : mtl_path).string();
|
||||
if (boost::filesystem::exists(mtl_name_is_path ? mtl_abs_path : mtl_path)) {
|
||||
if (!ObjParser::mtlparse(_mtl_path, mtl_data)) {
|
||||
if (!ObjParser::mtlparse(_mtl_path.c_str(), mtl_data)) {
|
||||
BOOST_LOG_TRIVIAL(error) << "load_obj:load_mtl: failed to parse " << _mtl_path;
|
||||
message = _L("load mtl in obj: failed to parse");
|
||||
return false;
|
||||
|
||||
@@ -111,14 +111,19 @@ bool StepPreProcessor::isUtf8File(const char* path)
|
||||
bool StepPreProcessor::isUtf8(const std::string str)
|
||||
{
|
||||
size_t num = 0;
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
while (i < str.length()) {
|
||||
if ((str[i] & 0x80) == 0x00) {
|
||||
const unsigned char lead = static_cast<unsigned char>(str[i]);
|
||||
if ((lead & 0x80) == 0x00) {
|
||||
i++;
|
||||
} else if ((num = preNum(str[i])) > 2) {
|
||||
// preNum() counts the leading 1 bits, and a multi-byte sequence is 2 to 4
|
||||
// bytes long, so anything outside that range is not a lead byte.
|
||||
} else if ((num = preNum(lead)) >= 2 && num <= 4) {
|
||||
if (i + num > str.length())
|
||||
return false;
|
||||
i++;
|
||||
for (int j = 0; j < num - 1; j++) {
|
||||
if ((str[i] & 0xc0) != 0x80)
|
||||
for (size_t j = 0; j < num - 1; j++) {
|
||||
if ((static_cast<unsigned char>(str[i]) & 0xc0) != 0x80)
|
||||
return false;
|
||||
i++;
|
||||
}
|
||||
@@ -132,15 +137,20 @@ bool StepPreProcessor::isUtf8(const std::string str)
|
||||
bool StepPreProcessor::isGBK(const std::string str) {
|
||||
size_t i = 0;
|
||||
while (i < str.length()) {
|
||||
if (str[i] <= 0x7f) {
|
||||
// char is signed here, so every byte compares <= 0x7f unless widened first.
|
||||
const unsigned char lead = static_cast<unsigned char>(str[i]);
|
||||
if (lead <= 0x7f) {
|
||||
i++;
|
||||
continue;
|
||||
} else {
|
||||
if (str[i] >= 0x81 &&
|
||||
str[i] <= 0xfe &&
|
||||
str[i + 1] >= 0x40 &&
|
||||
str[i + 1] <= 0xfe &&
|
||||
str[i + 1] != 0xf7) {
|
||||
if (i + 1 >= str.length())
|
||||
return false;
|
||||
const unsigned char trail = static_cast<unsigned char>(str[i + 1]);
|
||||
if (lead >= 0x81 &&
|
||||
lead <= 0xfe &&
|
||||
trail >= 0x40 &&
|
||||
trail <= 0xfe &&
|
||||
trail != 0xf7) {
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
@@ -586,7 +596,7 @@ Step::Step_Status Step::mesh(Model* model,
|
||||
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())));
|
||||
points.emplace_back(Vec3f(aPnt.X(), aPnt.Y(), aPnt.Z()));
|
||||
}
|
||||
// BBS: copy triangles
|
||||
const TopAbs_Orientation anOrientation = anExpSF.Current().Orientation();
|
||||
|
||||
@@ -8963,7 +8963,7 @@ private:
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " inital and interval = " << m_interval;
|
||||
m_next_backup = boost::get_system_time() + boost::posix_time::seconds(m_interval);
|
||||
boost::unique_lock lock(m_mutex);
|
||||
m_thread = std::move(boost::thread(boost::ref(*this)));
|
||||
m_thread = boost::thread(boost::ref(*this));
|
||||
}
|
||||
|
||||
~_BBS_Backup_Manager() {
|
||||
|
||||
@@ -352,7 +352,7 @@ bool load_svg(const char *path, Model *model, std::string &message)
|
||||
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())));
|
||||
points.emplace_back(Vec3f(aPnt.X(), aPnt.Y(), aPnt.Z()));
|
||||
}
|
||||
// BBS: copy triangles
|
||||
const TopAbs_Orientation anOrientation = anExpSF.Current().Orientation();
|
||||
|
||||
@@ -9562,7 +9562,7 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp
|
||||
continue;
|
||||
|
||||
Polygons temp;
|
||||
temp.emplace_back(std::move(instance_bbox.polygon()));
|
||||
temp.emplace_back(instance_bbox.polygon());
|
||||
if (intersection_pl(travel, temp).empty())
|
||||
continue;
|
||||
|
||||
|
||||
@@ -352,7 +352,7 @@ void segment(CGALMesh& src, std::vector<CGALMesh>& dst, double smoothing_alpha =
|
||||
//}
|
||||
//else
|
||||
{
|
||||
dst.emplace_back(std::move(CGALMesh(out)));
|
||||
dst.emplace_back(CGALMesh(out));
|
||||
}
|
||||
}
|
||||
//if (mesh_merged.is_empty() == false) {
|
||||
@@ -371,7 +371,7 @@ std::vector<TriangleMesh> segment(const TriangleMesh& src, double smoothing_alph
|
||||
std::vector<TriangleMesh> out_meshes;
|
||||
for (auto& outf_cgal_mesh: out_cgal_meshes)
|
||||
{
|
||||
out_meshes.emplace_back(std::move(cgal_to_triangle_mesh(outf_cgal_mesh.m)));
|
||||
out_meshes.emplace_back(cgal_to_triangle_mesh(outf_cgal_mesh.m));
|
||||
}
|
||||
|
||||
return out_meshes;
|
||||
|
||||
@@ -261,7 +261,7 @@ static void add_textured_mesh_to_model(Model& model, const TexturedMesh& tex_mes
|
||||
its_remove_degenerate_faces(its);
|
||||
its_compactify_vertices(its);
|
||||
|
||||
model.add_object(object_name.c_str(), input_file.c_str(), std::move(TriangleMesh(std::move(its))));
|
||||
model.add_object(object_name.c_str(), input_file.c_str(), TriangleMesh(std::move(its)));
|
||||
}
|
||||
|
||||
Model Model::read_from_file(const std::string& input_file,
|
||||
|
||||
@@ -408,7 +408,7 @@ static ExtrusionEntityCollection traverse_extrusions(const PerimeterGenerator& p
|
||||
ExtrusionRole role = is_external ? erExternalPerimeter : erPerimeter;
|
||||
|
||||
const bool is_contour = !extrusion->is_closed || pg_extrusion.is_contour;
|
||||
apply_fuzzy_skin(extrusion, perimeter_generator, is_contour);
|
||||
apply_fuzzy_skin(extrusion, perimeter_generator, is_contour, extrusion->is_closed);
|
||||
|
||||
ExtrusionPaths paths;
|
||||
// detect overhanging/bridging perimeters
|
||||
|
||||
@@ -3190,63 +3190,6 @@ void PresetBundle::export_selections(AppConfig &config)
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1%, print %2%, filaments[0] %3% ")%printers.get_selected_preset_name() % prints.get_selected_preset_name() %filament_presets[0];
|
||||
}
|
||||
|
||||
// BBS
|
||||
void PresetBundle::set_num_filaments(unsigned int n, std::vector<std::string> new_colors) {
|
||||
int old_filament_count = this->filament_presets.size();
|
||||
if (n > old_filament_count && old_filament_count != 0)
|
||||
filament_presets.resize(n, filament_presets.back());
|
||||
else {
|
||||
filament_presets.resize(n);
|
||||
}
|
||||
ConfigOptionStrings* filament_color = project_config.option<ConfigOptionStrings>("filament_colour");
|
||||
ConfigOptionStrings *filament_multi_color = project_config.option<ConfigOptionStrings>("filament_multi_colour");
|
||||
ConfigOptionStrings* filament_color_type = project_config.option<ConfigOptionStrings>("filament_colour_type");
|
||||
ConfigOptionInts* filament_map = project_config.option<ConfigOptionInts>("filament_map");
|
||||
ConfigOptionInts* filament_nozzle_map = project_config.option<ConfigOptionInts>("filament_nozzle_map");
|
||||
ConfigOptionInts* filament_volume_map = project_config.option<ConfigOptionInts>("filament_volume_map");
|
||||
|
||||
filament_color->resize(n);
|
||||
// Sync filament multi colour
|
||||
filament_multi_color->values.resize(n);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
filament_multi_color->values[i] = filament_color->values[i];
|
||||
}
|
||||
filament_color_type->resize(n);
|
||||
filament_map->values.resize(n, 1);
|
||||
filament_nozzle_map->values.resize(n, 0);
|
||||
filament_volume_map->values.resize(n, static_cast<int>(NozzleVolumeType::nvtStandard));
|
||||
ams_multi_color_filment.resize(n);
|
||||
|
||||
// Mixed-color metadata is a parallel per-filament array set, so it has to grow and shrink
|
||||
// with the filament count exactly like filament_colour above.
|
||||
if (auto* opt = project_config.option<ConfigOptionBools>("filament_is_mixed"))
|
||||
opt->values.resize(n, false);
|
||||
if (auto* opt = project_config.option<ConfigOptionStrings>("filament_mixed_components"))
|
||||
opt->values.resize(n, std::string{});
|
||||
if (auto* opt = project_config.option<ConfigOptionStrings>("filament_mixed_sublayer_ratios"))
|
||||
opt->values.resize(n, std::string{});
|
||||
if (auto* opt = project_config.option<ConfigOptionBools>("filament_mixed_gradient"))
|
||||
opt->values.resize(n, false);
|
||||
if (auto* opt = project_config.option<ConfigOptionStrings>("filament_mixed_gradient_range"))
|
||||
opt->values.resize(n, std::string{});
|
||||
if (auto* opt = project_config.option<ConfigOptionStrings>("filament_mixed_gradient_curve"))
|
||||
opt->values.resize(n, std::string{});
|
||||
if (auto* opt = project_config.option<ConfigOptionBools>("filament_mixed_gradient_per_part"))
|
||||
opt->values.resize(n, false);
|
||||
|
||||
// BBS set new filament color to new_color
|
||||
if (old_filament_count < n) {
|
||||
if (!new_colors.empty()) {
|
||||
for (int i = old_filament_count; i < n; i++) {
|
||||
filament_color->values[i] = new_colors[i - old_filament_count];
|
||||
filament_multi_color->values[i] = new_colors[i - old_filament_count];
|
||||
filament_color_type->values[i] = "1"; // default color type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_multi_material_filament_presets();
|
||||
}
|
||||
void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
|
||||
{
|
||||
unsigned old_filament_count = this->filament_presets.size();
|
||||
@@ -3262,6 +3205,11 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
|
||||
ConfigOptionInts* filament_nozzle_map = project_config.option<ConfigOptionInts>("filament_nozzle_map");
|
||||
ConfigOptionInts* filament_volume_map = project_config.option<ConfigOptionInts>("filament_volume_map");
|
||||
|
||||
// Which slots are new is a fact about the arrays below, not about filament_presets:
|
||||
// update_multi_material_filament_presets() tops that list up to the nozzle count on its own,
|
||||
// so it can already sit at the new size while every array below is still at the old one.
|
||||
const size_t old_slot_count = filament_color->values.size();
|
||||
|
||||
filament_color->resize(n);
|
||||
// Sync filament multi colour
|
||||
filament_multi_color->values.resize(n);
|
||||
@@ -3292,13 +3240,11 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
|
||||
opt->values.resize(n, false);
|
||||
|
||||
//BBS set new filament color to new_color
|
||||
if (old_filament_count < n) {
|
||||
if (!new_color.empty()) {
|
||||
for (unsigned i = old_filament_count; i < n; i++) {
|
||||
filament_color->values[i] = new_color;
|
||||
filament_multi_color->values[i] = new_color;
|
||||
filament_color_type->values[i] = "1"; // default color type
|
||||
}
|
||||
if (!new_color.empty()) {
|
||||
for (size_t i = old_slot_count; i < n; i++) {
|
||||
filament_color->values[i] = new_color;
|
||||
filament_multi_color->values[i] = new_color;
|
||||
filament_color_type->values[i] = "1"; // default color type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3407,6 +3353,16 @@ size_t PresetBundle::num_mixed_filaments() const
|
||||
return opt == nullptr ? 0 : size_t(std::count(opt->values.begin(), opt->values.end(), true));
|
||||
}
|
||||
|
||||
// Counted off the mixed flags, not filament_presets: that list is topped up to the nozzle count on
|
||||
// its own, so it can sit a slot ahead of the arrays that describe slots. Unlike the sibling
|
||||
// physical_filament_config_indices(), which bounds by filament_presets, this ignores that top-up.
|
||||
size_t PresetBundle::num_physical_filaments() const
|
||||
{
|
||||
const auto *opt = project_config.option<ConfigOptionBools>("filament_is_mixed");
|
||||
return opt == nullptr ? filament_presets.size()
|
||||
: size_t(std::count(opt->values.begin(), opt->values.end(), false));
|
||||
}
|
||||
|
||||
std::vector<size_t> PresetBundle::physical_filament_config_indices() const
|
||||
{
|
||||
std::vector<size_t> indices;
|
||||
|
||||
@@ -326,8 +326,9 @@ public:
|
||||
// Export selections (current print, current filaments, current printer) into config.ini
|
||||
void export_selections(AppConfig &config);
|
||||
|
||||
// BBS
|
||||
void set_num_filaments(unsigned int n, std::vector<std::string> new_colors);
|
||||
// n is the total slot count, and growth appends at the raw tail - which is where the mixed
|
||||
// slots live. A caller adding physical filaments has to add num_mixed_filaments() on top and
|
||||
// then move the new slots ahead of the mixed tail, as Sidebar::add_custom_filament does.
|
||||
void set_num_filaments(unsigned int n, std::string new_col = "");
|
||||
void update_num_filaments(unsigned int to_del_flament_id);
|
||||
|
||||
@@ -503,6 +504,8 @@ public:
|
||||
// How many slots are mixed. They sit at the tail of the filament list and have no nozzle of
|
||||
// their own, so any resize driven by the printer's extruder count has to add this on top.
|
||||
size_t num_mixed_filaments() const;
|
||||
// How many slots hold a real filament, i.e. everything ahead of the mixed tail.
|
||||
size_t num_physical_filaments() const;
|
||||
|
||||
void on_extruders_count_changed(int extruder_count);
|
||||
|
||||
|
||||
@@ -4039,7 +4039,7 @@ std::vector<Polygons> Print::get_extruder_printable_polygons() const
|
||||
Polygons ploys = {Polygon::new_scale(e_printable_area)};
|
||||
extruder_printable_polys.emplace_back(ploys);
|
||||
}
|
||||
return std::move(extruder_printable_polys);
|
||||
return extruder_printable_polys;
|
||||
}
|
||||
|
||||
std::vector<Polygons> Print::get_extruder_unprintable_polygons() const
|
||||
@@ -4052,7 +4052,7 @@ std::vector<Polygons> Print::get_extruder_unprintable_polygons() const
|
||||
Polygons ploys = diff(printable_poly, Polygon::new_scale(e_printable_area));
|
||||
extruder_unprintable_polys.emplace_back(ploys);
|
||||
}
|
||||
return std::move(extruder_unprintable_polys);
|
||||
return extruder_unprintable_polys;
|
||||
}
|
||||
|
||||
size_t Print::get_extruder_id(unsigned int filament_id) const
|
||||
|
||||
@@ -915,7 +915,7 @@ void PrintObject::detect_overhangs_for_lift()
|
||||
Layer& lower_layer = *layer.lower_layer;
|
||||
|
||||
ExPolygons overhangs = diff_ex(layer.lslices, offset_ex(lower_layer.lslices, scale_(min_overlap)));
|
||||
layer.loverhangs = std::move(offset2_ex(overhangs, -0.1f * scale_(line_width), 0.1f * scale_(line_width)));
|
||||
layer.loverhangs = offset2_ex(overhangs, -0.1f * scale_(line_width), 0.1f * scale_(line_width));
|
||||
layer.loverhangs_bbox = get_extents(layer.loverhangs);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -199,7 +199,7 @@ static void MakeMesh(TopoDS_Shape& theSolid, TriangleMesh& theMesh)
|
||||
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())));
|
||||
points.emplace_back(Vec3f(aPnt.X(), aPnt.Y(), aPnt.Z()));
|
||||
}
|
||||
//BBS: copy triangles
|
||||
const TopAbs_Orientation anOrientation = anExpSF.Current().Orientation();
|
||||
|
||||
@@ -867,7 +867,7 @@ void TreeSupport::detect_overhangs(bool check_support_necessity/* = false*/)
|
||||
|
||||
// normal overhang
|
||||
ExPolygons lower_layer_offseted = offset_ex(effective_lower, support_offset_scaled, SUPPORT_SURFACES_OFFSET_PARAMETERS);
|
||||
overhangs_all_layers[layer_nr] = std::move(diff_ex(curr_polys, lower_layer_offseted));
|
||||
overhangs_all_layers[layer_nr] = diff_ex(curr_polys, lower_layer_offseted);
|
||||
|
||||
double duration{ std::chrono::duration_cast<second_>(clock_::now() - t0).count() };
|
||||
if (duration > 30 || overhangs_all_layers[layer_nr].size() > 100) {
|
||||
@@ -1421,7 +1421,7 @@ void TreeSupport::generate_toolpaths()
|
||||
raft_areas.push_back(expoly);
|
||||
}
|
||||
|
||||
raft_areas = std::move(offset_ex(raft_areas, scale_(object_config.raft_first_layer_expansion)));
|
||||
raft_areas = offset_ex(raft_areas, scale_(object_config.raft_first_layer_expansion));
|
||||
|
||||
size_t layer_nr = 0;
|
||||
for (; layer_nr < m_slicing_params.base_raft_layers; layer_nr++) {
|
||||
@@ -1557,9 +1557,9 @@ void TreeSupport::generate_toolpaths()
|
||||
erSupportMaterialInterface : erSupportMaterial;
|
||||
make_perimeter_and_inner_brim(ts_layer->support_fills.entities, poly, wall_count, flow,
|
||||
brim_role);
|
||||
polys = std::move(offset_ex(poly, -flow.scaled_spacing()));
|
||||
polys = offset_ex(poly, -flow.scaled_spacing());
|
||||
} else if (area_group.type == SupportLayer::Roof1stLayer) {
|
||||
polys = std::move(offset_ex(poly, 0.5*support_flow.scaled_width()));
|
||||
polys = offset_ex(poly, 0.5*support_flow.scaled_width());
|
||||
}
|
||||
else {
|
||||
polys.push_back(poly);
|
||||
@@ -2465,7 +2465,7 @@ void TreeSupport::draw_circles()
|
||||
// Inside the gap: remove only the part overlapping the contact surface, keep the rest.
|
||||
if (bottom_gap_height > EPSILON && layer_bottom_z < band_gap_top - EPSILON) {
|
||||
any_gap_cleared = true;
|
||||
comp_poly = std::move(diff_ex(comp_poly, band.surfaces));
|
||||
comp_poly = diff_ex(comp_poly, band.surfaces);
|
||||
}
|
||||
|
||||
// Overlaps interface band
|
||||
@@ -2500,7 +2500,7 @@ void TreeSupport::draw_circles()
|
||||
ExPolygons comp_interface = band_ex.empty() ? ExPolygons {} : intersection_ex(comp_poly, band_ex);
|
||||
if (!comp_interface.empty()) {
|
||||
append(new_floor_areas, comp_interface);
|
||||
comp_poly = std::move(diff_ex(comp_poly, offset_ex(comp_interface, 10)));
|
||||
comp_poly = diff_ex(comp_poly, offset_ex(comp_interface, 10));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2592,7 +2592,7 @@ void TreeSupport::draw_circles()
|
||||
ts_layer->lslices.emplace_back(*expoly);
|
||||
}
|
||||
|
||||
ts_layer->lslices = std::move(union_ex(ts_layer->lslices));
|
||||
ts_layer->lslices = union_ex(ts_layer->lslices);
|
||||
//Must update bounding box which is used in avoid crossing perimeter
|
||||
ts_layer->lslices_bboxes.clear();
|
||||
ts_layer->lslices_bboxes.reserve(ts_layer->lslices.size());
|
||||
@@ -2670,7 +2670,7 @@ void TreeSupport::draw_circles()
|
||||
if (global_lightning_infill)
|
||||
{
|
||||
//search overhangs globally
|
||||
overhang = std::move(diff_ex(offset_ex(base_areas_lower, -2.0 * scale_(support_extrusion_width)), base_areas));
|
||||
overhang = diff_ex(offset_ex(base_areas_lower, -2.0 * scale_(support_extrusion_width)), base_areas);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2681,13 +2681,13 @@ void TreeSupport::draw_circles()
|
||||
Polygon rev_hole = hole;
|
||||
rev_hole.make_counter_clockwise();
|
||||
ExPolygons ex_hole;
|
||||
ex_hole.emplace_back(std::move(ExPolygon(rev_hole)));
|
||||
ex_hole.emplace_back(ExPolygon(rev_hole));
|
||||
for (auto& other_area : base_areas)
|
||||
//if (&other_area != &base_area)
|
||||
ex_hole = std::move(diff_ex(ex_hole, other_area));
|
||||
overhang = std::move(union_ex(overhang, ex_hole));
|
||||
ex_hole = diff_ex(ex_hole, other_area);
|
||||
overhang = union_ex(overhang, ex_hole);
|
||||
}
|
||||
overhang = std::move(intersection_ex(overhang, offset_ex(base_areas_lower, -0.5 * scale_(support_extrusion_width))));
|
||||
overhang = intersection_ex(overhang, offset_ex(base_areas_lower, -0.5 * scale_(support_extrusion_width)));
|
||||
}
|
||||
|
||||
overhangs.emplace_back(to_polygons(overhang));
|
||||
@@ -2945,7 +2945,7 @@ void TreeSupport::drop_nodes()
|
||||
|
||||
m_object->print()->set_status(60 + int(10 * (1 - float(layer_nr) / contact_nodes.size())), _u8L("Generating support"));// (boost::format(_u8L("Support: propagate branches at layer %d")) % layer_nr).str());
|
||||
|
||||
Polygons layer_contours = std::move(m_ts_data->get_contours_with_holes(obj_layer_nr));
|
||||
Polygons layer_contours = m_ts_data->get_contours_with_holes(obj_layer_nr);
|
||||
//std::unordered_map<Line, bool, LineHash>& mst_line_x_layer_contour_cache = m_mst_line_x_layer_contour_caches[layer_nr];
|
||||
tbb::concurrent_unordered_map<Line, bool, LineHash> mst_line_x_layer_contour_cache;
|
||||
auto is_line_cut_by_contour = [&mst_line_x_layer_contour_cache,&layer_contours](Point a, Point b)
|
||||
@@ -4007,7 +4007,7 @@ const ExPolygons& TreeSupportData::calculate_avoidance(const RadiusLayerPair& ke
|
||||
}
|
||||
const ExPolygons &collision = get_collision(radius, layer_nr);
|
||||
avoidance_areas.insert(avoidance_areas.end(), collision.begin(), collision.end());
|
||||
avoidance_areas = std::move(union_ex(avoidance_areas));
|
||||
avoidance_areas = union_ex(avoidance_areas);
|
||||
auto ret = m_avoidance_cache.insert({key, std::move(avoidance_areas)});
|
||||
//assert(ret.second);
|
||||
return ret.first->second;
|
||||
|
||||
@@ -146,6 +146,85 @@ public:
|
||||
|
||||
using IntersectionLines = std::vector<IntersectionLine>;
|
||||
|
||||
// Orca: A planar face is commonly represented by multiple triangles. A slicing plane then crosses
|
||||
// their shared edges and creates intermediate 2D points which are not part of the model contour.
|
||||
// Track only edges whose two incident triangles lie in the same geometric plane within the slicing
|
||||
// coordinate precision, so those artificial junctions can be omitted without simplifying genuine,
|
||||
// nearly-collinear geometry.
|
||||
using CoplanarEdges = std::vector<bool>;
|
||||
|
||||
static CoplanarEdges coplanar_edges(const indexed_triangle_set &mesh, const std::vector<Vec3i32> &face_edge_ids,
|
||||
const Transform3d &trafo)
|
||||
{
|
||||
struct FacePlane {
|
||||
Vec3d origin { Vec3d::Zero() };
|
||||
Vec3d normal { Vec3d::Zero() };
|
||||
bool valid { false };
|
||||
};
|
||||
|
||||
// Orca: Edge IDs are dense but may include boundary edges referenced by just one face.
|
||||
int num_edges = 0;
|
||||
for (const Vec3i32 &edge_ids : face_edge_ids)
|
||||
num_edges = std::max(num_edges, edge_ids.maxCoeff() + 1);
|
||||
|
||||
CoplanarEdges coplanar(num_edges, false);
|
||||
std::vector<int> first_face(num_edges, -1);
|
||||
std::vector<int> first_face_edge(num_edges, -1);
|
||||
std::vector<FacePlane> face_planes(face_edge_ids.size());
|
||||
std::vector<bool> face_plane_computed(face_edge_ids.size(), false);
|
||||
auto transformed_vertex = [&mesh, &trafo](int vertex_idx) {
|
||||
return trafo * mesh.vertices[vertex_idx].cast<double>();
|
||||
};
|
||||
// Orca: Compute planes lazily. The single-plane slicer masks most faces, so eagerly calculating
|
||||
// every plane would defeat part of that optimization.
|
||||
auto face_plane = [&mesh, &face_planes, &face_plane_computed, &transformed_vertex](int face_idx) -> const FacePlane& {
|
||||
if (! face_plane_computed[face_idx]) {
|
||||
const Vec3i32 &face = mesh.indices[face_idx];
|
||||
const Vec3d a = transformed_vertex(face(0));
|
||||
const Vec3d b = transformed_vertex(face(1));
|
||||
const Vec3d c = transformed_vertex(face(2));
|
||||
FacePlane &plane = face_planes[face_idx];
|
||||
plane.origin = a;
|
||||
plane.normal = (b - a).cross(c - a);
|
||||
const double normal_length = plane.normal.norm();
|
||||
if (normal_length > 0.) {
|
||||
plane.normal /= normal_length;
|
||||
plane.valid = true;
|
||||
}
|
||||
face_plane_computed[face_idx] = true;
|
||||
}
|
||||
return face_planes[face_idx];
|
||||
};
|
||||
const double plane_distance_tolerance = SCALING_FACTOR;
|
||||
for (int face_idx = 0; face_idx < int(face_edge_ids.size()); ++ face_idx) {
|
||||
for (int edge_idx = 0; edge_idx < 3; ++ edge_idx) {
|
||||
const int edge_id = face_edge_ids[face_idx](edge_idx);
|
||||
if (edge_id < 0)
|
||||
continue;
|
||||
if (first_face[edge_id] == -1) {
|
||||
first_face[edge_id] = face_idx;
|
||||
first_face_edge[edge_id] = edge_idx;
|
||||
} else {
|
||||
const int first_face_idx = first_face[edge_id];
|
||||
const FacePlane &first_plane = face_plane(first_face_idx);
|
||||
const FacePlane &second_plane = face_plane(face_idx);
|
||||
const int first_opposite_idx = mesh.indices[first_face_idx]((first_face_edge[edge_id] + 2) % 3);
|
||||
const int second_opposite_idx = mesh.indices[face_idx]((edge_idx + 2) % 3);
|
||||
const Vec3d first_opposite = transformed_vertex(first_opposite_idx);
|
||||
const Vec3d second_opposite = transformed_vertex(second_opposite_idx);
|
||||
// Orca: A shared edge guarantees that the planes intersect, but not that they coincide.
|
||||
// Check both opposite vertices against the neighboring plane using one coord_t as the
|
||||
// distance tolerance. The normal dot product only preserves face orientation; it does
|
||||
// not classify a shallow angle as coplanar (see #15364).
|
||||
coplanar[edge_id] = first_plane.valid && second_plane.valid && first_plane.normal.dot(second_plane.normal) > 0. &&
|
||||
std::abs(first_plane.normal.dot(second_opposite - first_plane.origin)) <= plane_distance_tolerance &&
|
||||
std::abs(second_plane.normal.dot(first_opposite - second_plane.origin)) <= plane_distance_tolerance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return coplanar;
|
||||
}
|
||||
|
||||
enum class FacetSliceType {
|
||||
NoSlice = 0,
|
||||
Slicing = 1,
|
||||
@@ -1057,7 +1136,8 @@ struct OpenPolyline {
|
||||
|
||||
// called by make_loops() to connect sliced triangles into closed loops and open polylines by the triangle connectivity.
|
||||
// Only connects segments crossing triangles of the same orientation.
|
||||
static void chain_lines_by_triangle_connectivity(IntersectionLines &lines, Polygons &loops, std::vector<OpenPolyline> &open_polylines)
|
||||
static void chain_lines_by_triangle_connectivity(IntersectionLines &lines, const CoplanarEdges &coplanar_edges,
|
||||
Polygons &loops, std::vector<OpenPolyline> &open_polylines)
|
||||
{
|
||||
// Build a map of lines by edge_a_id and a_id.
|
||||
std::vector<IntersectionLine*> by_edge_a_id;
|
||||
@@ -1134,6 +1214,11 @@ static void chain_lines_by_triangle_connectivity(IntersectionLines &lines, Polyg
|
||||
(first_line->a_id != -1 && first_line->a_id == last_line->b_id)) {
|
||||
// The current loop is complete. Add it to the output.
|
||||
assert(first_line->a == last_line->b);
|
||||
// Orca: The seed point is also a triangle junction. Handle it explicitly because it
|
||||
// is never visited through the next_line branch below when the loop closes.
|
||||
if (first_line->edge_a_id >= 0 && first_line->edge_a_id < int(coplanar_edges.size()) &&
|
||||
coplanar_edges[first_line->edge_a_id])
|
||||
loop_pts.erase(loop_pts.begin());
|
||||
loops.emplace_back(std::move(loop_pts));
|
||||
#ifdef SLIC3R_TRIANGLEMESH_DEBUG
|
||||
printf(" Discovered %s polygon of %d points\n", (p.is_counter_clockwise() ? "ccw" : "cw"), (int)p.points.size());
|
||||
@@ -1153,7 +1238,12 @@ static void chain_lines_by_triangle_connectivity(IntersectionLines &lines, Polyg
|
||||
next_line->a.x, next_line->a.y, next_line->b.x, next_line->b.y);
|
||||
*/
|
||||
assert(last_line->b == next_line->a);
|
||||
loop_pts.emplace_back(next_line->a);
|
||||
// Orca: Skip only junctions introduced by triangulating one planar face. Unlike a generic
|
||||
// collinearity cleanup, this preserves intentional shallow corners used when comparing
|
||||
// adjacent layers for bridges and overhang perimeters (see #15364).
|
||||
if (next_line->edge_a_id < 0 || next_line->edge_a_id >= int(coplanar_edges.size()) ||
|
||||
! coplanar_edges[next_line->edge_a_id])
|
||||
loop_pts.emplace_back(next_line->a);
|
||||
last_line = next_line;
|
||||
next_line->set_skip();
|
||||
}
|
||||
@@ -1382,7 +1472,8 @@ static void chain_open_polylines_close_gaps(std::vector<OpenPolyline> &open_poly
|
||||
|
||||
static Polygons make_loops(
|
||||
// Lines will have their flags modified.
|
||||
IntersectionLines &lines)
|
||||
IntersectionLines &lines,
|
||||
const CoplanarEdges &coplanar_edges)
|
||||
{
|
||||
Polygons loops;
|
||||
#if 0
|
||||
@@ -1412,7 +1503,7 @@ static Polygons make_loops(
|
||||
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
|
||||
|
||||
std::vector<OpenPolyline> open_polylines;
|
||||
chain_lines_by_triangle_connectivity(lines, loops, open_polylines);
|
||||
chain_lines_by_triangle_connectivity(lines, coplanar_edges, loops, open_polylines);
|
||||
|
||||
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
|
||||
{
|
||||
@@ -1484,6 +1575,7 @@ template<typename ThrowOnCancel>
|
||||
static std::vector<Polygons> make_loops(
|
||||
// Lines will have their flags modified.
|
||||
std::vector<IntersectionLines> &lines,
|
||||
const CoplanarEdges &coplanar_edges,
|
||||
const MeshSlicingParams ¶ms,
|
||||
ThrowOnCancel throw_on_cancel)
|
||||
{
|
||||
@@ -1491,20 +1583,13 @@ static std::vector<Polygons> make_loops(
|
||||
layers.resize(lines.size());
|
||||
tbb::parallel_for(
|
||||
tbb::blocked_range<size_t>(0, lines.size()),
|
||||
[&lines, &layers, ¶ms, throw_on_cancel](const tbb::blocked_range<size_t> &range) {
|
||||
[&lines, &layers, &coplanar_edges, ¶ms, throw_on_cancel](const tbb::blocked_range<size_t> &range) {
|
||||
for (size_t line_idx = range.begin(); line_idx < range.end(); ++ line_idx) {
|
||||
if ((line_idx & 0x0ffff) == 0)
|
||||
throw_on_cancel();
|
||||
|
||||
Polygons &polygons = layers[line_idx];
|
||||
polygons = make_loops(lines[line_idx]);
|
||||
|
||||
// Orca: A planar quad represented by two triangles contributes a point where the
|
||||
// slicing plane crosses the shared diagonal. After rounding to coord_t this
|
||||
// point may be very slightly off the otherwise straight contour edge. Apart
|
||||
// from being redundant, such points make the subsequent contour
|
||||
// simplification depend on the slice height (and may move seam candidates).
|
||||
remove_collinear(polygons);
|
||||
polygons = make_loops(lines[line_idx], coplanar_edges);
|
||||
|
||||
auto this_mode = line_idx < params.slicing_mode_normal_below_layer ? params.mode_below : params.mode;
|
||||
if (! polygons.empty()) {
|
||||
@@ -1633,7 +1718,7 @@ static std::vector<Polygons> make_slab_loops(
|
||||
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
|
||||
Polygons &loops = layers[line_idx];
|
||||
std::vector<OpenPolyline> open_polylines;
|
||||
chain_lines_by_triangle_connectivity(in, loops, open_polylines);
|
||||
chain_lines_by_triangle_connectivity(in, {}, loops, open_polylines);
|
||||
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
|
||||
{
|
||||
SVG svg(debug_out_path("make_slab_loops-out-%d-%d-%s.svg", iRun, line_idx, ProjectionFromTop ? "top" : "bottom").c_str(), bbox_svg);
|
||||
@@ -1673,7 +1758,7 @@ static ExPolygons make_expolygons_simple(std::vector<IntersectionLine> &lines)
|
||||
ExPolygons slices;
|
||||
Polygons holes;
|
||||
|
||||
for (Polygon &loop : make_loops(lines))
|
||||
for (Polygon &loop : make_loops(lines, {}))
|
||||
if (loop.area() >= 0.)
|
||||
slices.emplace_back(std::move(loop));
|
||||
else
|
||||
@@ -1878,6 +1963,7 @@ std::vector<Polygons> slice_mesh(
|
||||
BOOST_LOG_TRIVIAL(debug) << "slice_mesh to polygons";
|
||||
|
||||
std::vector<IntersectionLines> lines;
|
||||
CoplanarEdges coplanar;
|
||||
|
||||
{
|
||||
//FIXME facets_edges is likely not needed and quite costly to calculate.
|
||||
@@ -1885,6 +1971,8 @@ std::vector<Polygons> slice_mesh(
|
||||
// However facets_edges assigns a single edge ID to two triangles only, thus when factoring facets_edges out, one will have
|
||||
// to make sure that no code relies on it.
|
||||
std::vector<Vec3i32> face_edge_ids = its_face_edge_ids(mesh);
|
||||
// Orca: Keep the coplanarity classification aligned with the edge IDs used to chain this slice.
|
||||
coplanar = coplanar_edges(mesh, face_edge_ids, params.trafo);
|
||||
if (zs.size() <= 1) {
|
||||
// It likely is not worthwile to copy the vertices. Apply the transformation in place.
|
||||
if (is_identity(params.trafo)) {
|
||||
@@ -1906,7 +1994,7 @@ std::vector<Polygons> slice_mesh(
|
||||
|
||||
throw_on_cancel();
|
||||
|
||||
std::vector<Polygons> layers = make_loops(lines, params, throw_on_cancel);
|
||||
std::vector<Polygons> layers = make_loops(lines, coplanar, params, throw_on_cancel);
|
||||
|
||||
#ifdef SLIC3R_DEBUG
|
||||
{
|
||||
@@ -1952,6 +2040,7 @@ Polygons slice_mesh(
|
||||
const MeshSlicingParams ¶ms)
|
||||
{
|
||||
std::vector<IntersectionLines> lines;
|
||||
CoplanarEdges coplanar;
|
||||
|
||||
{
|
||||
bool trafo_identity = is_identity(params.trafo);
|
||||
@@ -1987,6 +2076,8 @@ Polygons slice_mesh(
|
||||
|
||||
// 3) Calculate face neighbors for just the faces in face_mask.
|
||||
std::vector<Vec3i32> face_edge_ids = its_face_edge_ids(mesh, face_mask);
|
||||
// Orca: The single-plane path has its own masked edge-ID space, so classify that space separately.
|
||||
coplanar = coplanar_edges(mesh, face_edge_ids, params.trafo);
|
||||
|
||||
// 4) Slice "face_mask" triangles, collect line segments.
|
||||
// It likely is not worthwile to copy the vertices. Apply the transformation in place.
|
||||
@@ -2002,7 +2093,7 @@ Polygons slice_mesh(
|
||||
}
|
||||
|
||||
// 5) Chain the line segments.
|
||||
std::vector<Polygons> layers = make_loops(lines, params, [](){});
|
||||
std::vector<Polygons> layers = make_loops(lines, coplanar, params, [](){});
|
||||
assert(layers.size() == 1);
|
||||
return layers.front();
|
||||
}
|
||||
|
||||
+24
-18
@@ -38,6 +38,8 @@ set(SLIC3R_GUI_SOURCES
|
||||
GUI/AuxiliaryDataViewModel.hpp
|
||||
GUI/AuxiliaryDialog.cpp
|
||||
GUI/AuxiliaryDialog.hpp
|
||||
GUI/AVVideoDecoder.cpp
|
||||
GUI/AVVideoDecoder.hpp
|
||||
GUI/Auxiliary.hpp
|
||||
GUI/BackgroundSlicingProcess.cpp
|
||||
GUI/BackgroundSlicingProcess.hpp
|
||||
@@ -613,6 +615,8 @@ set(SLIC3R_GUI_SOURCES
|
||||
GUI/WipeTowerDialog.cpp
|
||||
GUI/wxExtensions.cpp
|
||||
GUI/wxExtensions.hpp
|
||||
GUI/wxMediaCtrl3.cpp
|
||||
GUI/wxMediaCtrl3.h
|
||||
plugin/PythonInterpreter.cpp
|
||||
plugin/PythonInterpreter.hpp
|
||||
plugin/PythonPluginBridge.cpp
|
||||
@@ -801,21 +805,8 @@ if (APPLE)
|
||||
GUI/DeepLinkHandlerMac.mm
|
||||
GUI/DeepLinkHandlerMac.h
|
||||
GUI/GUI_UtilsMac.mm
|
||||
GUI/wxMediaCtrl2.mm
|
||||
GUI/wxMediaCtrl2.h
|
||||
)
|
||||
FIND_LIBRARY(DISKARBITRATION_LIBRARY DiskArbitration)
|
||||
else ()
|
||||
list(APPEND SLIC3R_GUI_SOURCES
|
||||
GUI/wxMediaCtrl2.cpp
|
||||
GUI/wxMediaCtrl2.h
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
list(APPEND SLIC3R_GUI_SOURCES
|
||||
GUI/Printer/gstbambusrc.c
|
||||
)
|
||||
endif ()
|
||||
|
||||
set(ORCA_UPDATER_SIG_KEY_B64 "${ORCA_UPDATER_SIG_KEY}")
|
||||
@@ -915,6 +906,26 @@ if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
|
||||
add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE)
|
||||
endif ()
|
||||
|
||||
if (APPLE)
|
||||
# Static FFmpeg from the deps install: nothing to bundle into the .app,
|
||||
# no rpath/install_name handling. Order matters: avcodec -> swscale -> avutil.
|
||||
find_library(LIBAVCODEC_LIBRARY NAMES libavcodec.a PATHS ${CMAKE_PREFIX_PATH}/lib NO_DEFAULT_PATH)
|
||||
find_library(LIBSWSCALE_LIBRARY NAMES libswscale.a PATHS ${CMAKE_PREFIX_PATH}/lib NO_DEFAULT_PATH)
|
||||
find_library(LIBAVUTIL_LIBRARY NAMES libavutil.a PATHS ${CMAKE_PREFIX_PATH}/lib NO_DEFAULT_PATH)
|
||||
if (NOT LIBAVCODEC_LIBRARY OR NOT LIBSWSCALE_LIBRARY OR NOT LIBAVUTIL_LIBRARY)
|
||||
message(FATAL_ERROR "Static FFmpeg (libavcodec.a/libswscale.a/libavutil.a) not found under ${CMAKE_PREFIX_PATH}/lib. Rebuild the deps — FFMPEG builds static-only on macOS.")
|
||||
endif ()
|
||||
target_link_libraries(libslic3r_gui ${LIBAVCODEC_LIBRARY} ${LIBSWSCALE_LIBRARY} ${LIBAVUTIL_LIBRARY})
|
||||
target_include_directories(libslic3r_gui SYSTEM PRIVATE ${CMAKE_PREFIX_PATH}/include)
|
||||
else ()
|
||||
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
|
||||
libavcodec
|
||||
libswscale
|
||||
libavutil
|
||||
)
|
||||
target_link_libraries(libslic3r_gui PkgConfig::LIBAV)
|
||||
endif()
|
||||
|
||||
# We need to implement some hacks for wxWidgets and touch the underlying GTK
|
||||
# layer and sub-libraries. This forces us to use the include locations and
|
||||
# link these libraries.
|
||||
@@ -941,11 +952,6 @@ if (UNIX AND NOT APPLE)
|
||||
target_compile_definitions(libslic3r_gui PRIVATE wxHAVE_GDK_WAYLAND)
|
||||
endif ()
|
||||
|
||||
# We add GStreamer for bambu:/// support.
|
||||
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
|
||||
pkg_check_modules(GST_BASE REQUIRED gstreamer-base-1.0)
|
||||
target_link_libraries(libslic3r_gui ${GSTREAMER_LIBRARIES} ${GST_BASE_LIBRARIES})
|
||||
target_include_directories(libslic3r_gui SYSTEM PRIVATE ${GSTREAMER_INCLUDE_DIRS} ${GST_BASE_INCLUDE_DIRS})
|
||||
endif ()
|
||||
|
||||
# Add a definition so that we can tell we are compiling slic3r.
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
#include "AVVideoDecoder.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <libavutil/avutil.h>
|
||||
#include <libavutil/imgutils.h>
|
||||
}
|
||||
|
||||
AVVideoDecoder::AVVideoDecoder()
|
||||
{
|
||||
codec_ctx_ = avcodec_alloc_context3(nullptr);
|
||||
}
|
||||
|
||||
AVVideoDecoder::~AVVideoDecoder()
|
||||
{
|
||||
if (sws_ctx_)
|
||||
sws_freeContext(sws_ctx_);
|
||||
if (frame_)
|
||||
av_frame_free(&frame_);
|
||||
if (codec_ctx_)
|
||||
avcodec_free_context(&codec_ctx_);
|
||||
}
|
||||
|
||||
int AVVideoDecoder::open(Bambu_StreamInfo const &info)
|
||||
{
|
||||
auto codec_id = info.sub_type == AVC1 ? AV_CODEC_ID_H264 : AV_CODEC_ID_MJPEG;
|
||||
auto codec = avcodec_find_decoder(codec_id);
|
||||
if (codec == nullptr) {
|
||||
fprintf(stderr, "AVVideoDecoder: unsupported codec!\n");
|
||||
return -1; // Codec not found
|
||||
}
|
||||
/* open the coderc */
|
||||
if (avcodec_open2(codec_ctx_, codec, nullptr) < 0) {
|
||||
fprintf(stderr, "AVVideoDecoder: could not open codec\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Allocate an AVFrame structure
|
||||
frame_ = av_frame_alloc();
|
||||
if (frame_ == nullptr)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AVVideoDecoder::decode(const Bambu_Sample &sample)
|
||||
{
|
||||
int ret = -1;
|
||||
AVPacket *pkt = av_packet_alloc();
|
||||
if (!pkt) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = av_new_packet(pkt, sample.size);
|
||||
if (ret != 0) {
|
||||
av_packet_free(&pkt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(pkt->data, sample.buffer, size_t(sample.size));
|
||||
|
||||
ret = avcodec_send_packet(codec_ctx_, pkt);
|
||||
if (ret == 0) {
|
||||
got_frame_ = avcodec_receive_frame(codec_ctx_, frame_) == 0;
|
||||
}
|
||||
|
||||
av_packet_unref(pkt);
|
||||
av_packet_free(&pkt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AVVideoDecoder::flush()
|
||||
{
|
||||
int ret = avcodec_send_packet(codec_ctx_, nullptr);
|
||||
got_frame_ = avcodec_receive_frame(codec_ctx_, frame_) == 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AVVideoDecoder::close()
|
||||
{
|
||||
}
|
||||
|
||||
bool AVVideoDecoder::toWxImage(wxImage &image, wxSize const &size2)
|
||||
{
|
||||
if (!got_frame_)
|
||||
return false;
|
||||
|
||||
auto size1 = size2;
|
||||
if (!size1.IsFullySpecified())
|
||||
size1 = {frame_->width, frame_->height };
|
||||
auto size = size1;
|
||||
if (size.GetWidth() & 0x0f) {
|
||||
size.SetWidth((size.GetWidth() & ~0x0f) + 0x10);
|
||||
if (size.GetWidth() != width_) {
|
||||
std::fill(bits_.begin(), bits_.end(), 0);
|
||||
width_ = size.GetWidth();
|
||||
}
|
||||
}
|
||||
AVPixelFormat wxFmt = AV_PIX_FMT_RGB24;
|
||||
sws_ctx_ = sws_getCachedContext(sws_ctx_,
|
||||
frame_->width, frame_->height, AVPixelFormat(frame_->format),
|
||||
size1.GetWidth(), size1.GetHeight(), wxFmt,
|
||||
SWS_GAUSS,
|
||||
nullptr, nullptr, nullptr);
|
||||
if (sws_ctx_ == nullptr)
|
||||
return false;
|
||||
int length = size.GetWidth() * size.GetHeight() * 3;
|
||||
if (bits_.size() < length)
|
||||
bits_.resize(length);
|
||||
uint8_t * datas[] = { bits_.data() };
|
||||
int strides[] = { size.GetWidth() * 3 };
|
||||
int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides);
|
||||
if (result_h != size.GetHeight()) {
|
||||
return false;
|
||||
}
|
||||
// Copy: the frame outlives this decoder and is painted by the GUI thread while the
|
||||
// next sws_scale is already overwriting bits_, so it must own its pixels. The Windows
|
||||
// path below needs no equivalent, wxBitmap copies the bits into GDI.
|
||||
image = wxImage(size.GetWidth(), size.GetHeight(), bits_.data(), true).Copy();
|
||||
if (!image.IsOk()) {
|
||||
fprintf(stderr, "AVVideoDecoder: image not ok %dx%d\n", size.GetWidth(), size.GetHeight());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AVVideoDecoder::toWxBitmap(wxBitmap &bitmap, wxSize const &size2)
|
||||
{
|
||||
if (!got_frame_)
|
||||
return false;
|
||||
|
||||
auto size1 = size2;
|
||||
if (!size1.IsFullySpecified())
|
||||
size1 = {frame_->width, frame_->height };
|
||||
auto size = size1;
|
||||
if (size.GetWidth() & 0x0f) {
|
||||
size.SetWidth((size.GetWidth() & ~0x0f) + 0x10);
|
||||
if (size.GetWidth() != width_) {
|
||||
std::fill(bits_.begin(), bits_.end(), 0);
|
||||
width_ = size.GetWidth();
|
||||
}
|
||||
}
|
||||
AVPixelFormat wxFmt = AV_PIX_FMT_RGB32;
|
||||
sws_ctx_ = sws_getCachedContext(sws_ctx_,
|
||||
frame_->width, frame_->height, AVPixelFormat(frame_->format),
|
||||
size1.GetWidth(), size1.GetHeight(), wxFmt,
|
||||
SWS_GAUSS,
|
||||
nullptr, nullptr, nullptr);
|
||||
if (sws_ctx_ == nullptr)
|
||||
return false;
|
||||
int length = size.GetWidth() * size.GetHeight() * 4;
|
||||
if (bits_.size() < length)
|
||||
bits_.resize(length);
|
||||
uint8_t *datas[] = { bits_.data() };
|
||||
int strides[] = { size.GetWidth() * 4 };
|
||||
int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides);
|
||||
if (result_h != size.GetHeight()) {
|
||||
fprintf(stderr, "AVVideoDecoder: result_h %d %d\n", result_h, size.GetHeight());
|
||||
return false;
|
||||
}
|
||||
bitmap = wxBitmap((char const *) bits_.data(), size.GetWidth(), size.GetHeight(), 32);
|
||||
assert(bitmap.IsOk());
|
||||
if (!bitmap.IsOk()) {
|
||||
fprintf(stderr, "AVVideoDecoder: bitmap not ok %dx%d\n", size.GetWidth(), size.GetHeight());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef AVVIDEODECODER_HPP
|
||||
#define AVVIDEODECODER_HPP
|
||||
|
||||
#include "Printer/BambuTunnel.h"
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libswscale/swscale.h>
|
||||
}
|
||||
#include <vector>
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/image.h>
|
||||
|
||||
class wxBitmap;
|
||||
|
||||
class AVVideoDecoder
|
||||
{
|
||||
public:
|
||||
AVVideoDecoder();
|
||||
|
||||
~AVVideoDecoder();
|
||||
|
||||
public:
|
||||
int open(Bambu_StreamInfo const &info);
|
||||
|
||||
int decode(Bambu_Sample const &sample);
|
||||
|
||||
int flush();
|
||||
|
||||
void close();
|
||||
|
||||
bool toWxImage(wxImage &image, wxSize const &size);
|
||||
|
||||
bool toWxBitmap(wxBitmap &bitmap, wxSize const & size);
|
||||
|
||||
private:
|
||||
AVCodecContext *codec_ctx_ = nullptr;
|
||||
AVFrame * frame_ = nullptr;
|
||||
SwsContext * sws_ctx_ = nullptr;
|
||||
bool got_frame_ = false;
|
||||
int width_ { 0 }; // scale result width
|
||||
std::vector<uint8_t> bits_;
|
||||
};
|
||||
|
||||
#endif // AVVIDEODECODER_HPP
|
||||
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// BambuPlayer.h
|
||||
// BambuPlayer
|
||||
//
|
||||
// Created by cmguo on 2021/12/6.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AVFoundation/AVSampleBufferDisplayLayer.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BambuPlayer : NSObject
|
||||
|
||||
+ (void) initialize;
|
||||
|
||||
- (instancetype) initWithDisplayLayer: (AVSampleBufferDisplayLayer*) layer;
|
||||
- (instancetype) initWithImageView: (NSView*) view;
|
||||
- (int) open: (char const *) url;
|
||||
- (NSSize) videoSize;
|
||||
- (int) play;
|
||||
- (void) stop;
|
||||
- (void) close;
|
||||
|
||||
- (void) setLogger: (void (*)(void const * context, int level, char const * msg)) logger withContext: (void const *) context;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1015,7 +1015,7 @@ wxBoxSizer* CalibrationPresetPage::create_ams_items_sizer(MachineObject* obj, wx
|
||||
auto ams_items_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
for (auto &info : ams_info) {
|
||||
auto preview_ams_item = new AMSPreview(ams_preview_panel, wxID_ANY, info, info.ams_type);
|
||||
preview_ams_item->Update(info);
|
||||
preview_ams_item->UpdateInfo(info);
|
||||
preview_ams_item->Open();
|
||||
ams_preview_list.push_back(preview_ams_item);
|
||||
std::string ams_id = preview_ams_item->get_ams_id();
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
DevFirmware(MachineObject* obj) : m_owner(obj) {}
|
||||
|
||||
private:
|
||||
MachineObject* m_owner = nullptr;
|
||||
[[maybe_unused]] MachineObject* m_owner = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -2,7 +2,7 @@
|
||||
/* File: uiAMSBestPositionPopup.hpp
|
||||
* Description: The popup with suggest best ams position
|
||||
*
|
||||
//**********************************************************/
|
||||
************************************************************/
|
||||
|
||||
#include "uiAMSBestPositionPopup.hpp"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* File: uiAMSBestPositionPopup.hpp
|
||||
* Description: The popup with suggest best ams position
|
||||
*
|
||||
//**********************************************************/
|
||||
************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "slic3r/GUI/Widgets/AMSItem.hpp"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* \n class wgtDeviceNozzleRackNozzleItem;
|
||||
* \n class wgtDeviceNozzleRackToolHead;
|
||||
* \n class wgtDeviceNozzleRackPos;
|
||||
//**********************************************************/
|
||||
************************************************************/
|
||||
|
||||
#include "wgtDeviceNozzleRack.h"
|
||||
#include "wgtDeviceNozzleRackUpdate.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* \n class wgtDeviceNozzleRackNozzleItem;
|
||||
* \n class wgtDeviceNozzleRackToolHead;
|
||||
* \n class wgtDeviceNozzleRackPos;
|
||||
//**********************************************************/
|
||||
************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "slic3r/GUI/DeviceCore/DevNozzleRack.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Description: The panel with rack updating
|
||||
*
|
||||
* \n class wgtDeviceNozzleRackUpdate
|
||||
//**********************************************************/
|
||||
************************************************************/
|
||||
|
||||
#include "wgtDeviceNozzleRackUpdate.h"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Description: The panel for updating hotends
|
||||
*
|
||||
* \n class wgtDeviceNozzleRackUpdate
|
||||
//**********************************************************/
|
||||
************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "slic3r/GUI/DeviceCore/DevNozzleRack.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Description: The panel to select nozzle
|
||||
*
|
||||
* \n class wgtDeviceNozzleSelect;
|
||||
//**********************************************************/
|
||||
************************************************************/
|
||||
|
||||
#include "wgtDeviceNozzleSelect.h"
|
||||
#include "wgtDeviceNozzleRack.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Description: The panel to select nozzle
|
||||
*
|
||||
* \n class wgtDeviceNozzleSelect;
|
||||
//**********************************************************/
|
||||
************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -8906,10 +8906,16 @@ void GUI_App::load_current_presets(bool active_preset_combox/*= false*/, bool ch
|
||||
auto* nozzle_diameter = edited_printer_preset.config.option<ConfigOptionFloats>("nozzle_diameter");
|
||||
if (nozzle_diameter) {
|
||||
// Mixed-color slots are virtual filaments kept at the tail of the list, so they have no
|
||||
// nozzle of their own. Sizing to the nozzle count alone would silently drop the mixes of
|
||||
// a just-loaded project, and update_extruder_count() would then strip the facets painted
|
||||
// with them.
|
||||
preset_bundle->set_num_filaments(nozzle_diameter->values.size() + preset_bundle->num_mixed_filaments());
|
||||
// nozzle of their own and the count has to allow for them. Only ever grow: this sizes
|
||||
// the list so the combo boxes have something to bind to, and set_num_filaments() trims
|
||||
// at the raw tail, so shrinking here would eat the mixes rather than the surplus
|
||||
// physical slots. A list longer than the nozzle count is a state the app reaches
|
||||
// legitimately - raising the extruder count and not saving the printer preset leaves
|
||||
// exactly that on the next start - and losing the project's mixes to it is worse than
|
||||
// carrying a filament the printer has no nozzle for until the count is next changed.
|
||||
const size_t target = nozzle_diameter->values.size() + preset_bundle->num_mixed_filaments();
|
||||
if (target > preset_bundle->filament_presets.size())
|
||||
preset_bundle->set_num_filaments(target);
|
||||
}
|
||||
}
|
||||
this->plater()->set_printer_technology(printer_technology);
|
||||
|
||||
@@ -155,6 +155,9 @@ public:
|
||||
update_dark_config();
|
||||
on_sys_color_changed();
|
||||
event.Skip();
|
||||
#else
|
||||
// Not calling Skip() is what stops the event propagating on Windows.
|
||||
(void) this;
|
||||
#endif // __WINDOWS__
|
||||
|
||||
});
|
||||
|
||||
@@ -2482,6 +2482,19 @@ static const ImWchar ranges_keyboard_shortcuts[] =
|
||||
};
|
||||
#endif // __APPLE__
|
||||
|
||||
// Names drawn through the atlas come from file names and CAD data, not from the UI language.
|
||||
// GetGlyphRangesDefault() already gives every language the CJK ideographs, which is why a
|
||||
// Chinese file name renders under an English UI; these are the alphabetic scripts it omits.
|
||||
// Codepoints the font lacks are skipped at build time, so only existing glyphs cost anything.
|
||||
static const ImWchar ranges_language_independent[] =
|
||||
{
|
||||
0x0100, 0x024F, // Latin Extended-A and Extended-B
|
||||
0x0370, 0x03FF, // Greek and Coptic
|
||||
0x0400, 0x04FF, // Cyrillic
|
||||
0x1E00, 0x1EFF, // Latin Extended Additional (Vietnamese)
|
||||
0,
|
||||
};
|
||||
|
||||
|
||||
std::vector<unsigned char> ImGuiWrapper::load_svg(const std::string& bitmap_name, unsigned target_width, unsigned target_height, unsigned *outwidth, unsigned *outheight)
|
||||
{
|
||||
@@ -2792,6 +2805,7 @@ void ImGuiWrapper::init_font(bool compress)
|
||||
ImFontAtlas::GlyphRangesBuilder builder;
|
||||
builder.AddRanges(m_glyph_ranges);
|
||||
builder.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesDefault());
|
||||
builder.AddRanges(ranges_language_independent);
|
||||
#ifdef __APPLE__
|
||||
if (m_font_cjk)
|
||||
// Apple keyboard shortcuts are only contained in the CJK fonts.
|
||||
@@ -2813,12 +2827,17 @@ void ImGuiWrapper::init_font(bool compress)
|
||||
// Orca: temp fix for Korean font
|
||||
auto font_name_regular = "HarmonyOS_Sans_SC_Regular.ttf";
|
||||
auto font_name_bold = "HarmonyOS_Sans_SC_Bold.ttf";
|
||||
// The Korean and Thai fonts cover their own script and little else, so they need the
|
||||
// default font merged in behind them to reach the full range.
|
||||
bool needs_glyph_fallback = false;
|
||||
if(m_glyph_ranges == ImGui::GetIO().Fonts->GetGlyphRangesKorean()) {
|
||||
font_name_regular = "NanumGothic-Regular.ttf";
|
||||
font_name_bold = "NanumGothic-Bold.ttf";
|
||||
needs_glyph_fallback = true;
|
||||
} else if (m_glyph_ranges == ImGui::GetIO().Fonts->GetGlyphRangesThai()) {
|
||||
font_name_regular = "Sarabun-Medium.ttf";
|
||||
font_name_bold = "Sarabun-SemiBold.ttf";
|
||||
needs_glyph_fallback = true;
|
||||
}
|
||||
default_font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/" + font_name_regular).c_str(), m_font_size, &cfg, ranges.Data);
|
||||
if (default_font == nullptr) {
|
||||
@@ -2828,11 +2847,12 @@ void ImGuiWrapper::init_font(bool compress)
|
||||
}
|
||||
}
|
||||
|
||||
if (m_glyph_ranges == ImGui::GetIO().Fonts->GetGlyphRangesThai()) {
|
||||
// A merged font only supplies glyphs the font ahead of it lacks, so this fills the gaps
|
||||
// without restyling anything the script font already covers.
|
||||
if (needs_glyph_fallback) {
|
||||
ImFontConfig fallback_cfg = cfg;
|
||||
fallback_cfg.MergeMode = true;
|
||||
static constexpr ImWchar celsius_range[] = { 0x2103, 0x2103, 0 };
|
||||
io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/HarmonyOS_Sans_SC_Regular.ttf").c_str(), m_font_size, &fallback_cfg, celsius_range);
|
||||
io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/HarmonyOS_Sans_SC_Regular.ttf").c_str(), m_font_size, &fallback_cfg, ranges.Data);
|
||||
}
|
||||
|
||||
bold_font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/" + font_name_bold).c_str(), m_font_size, &cfg, ranges.Data);
|
||||
@@ -2841,11 +2861,10 @@ void ImGuiWrapper::init_font(bool compress)
|
||||
if (bold_font == nullptr) { throw Slic3r::RuntimeError("ImGui: Could not load deafult font"); }
|
||||
}
|
||||
|
||||
if (m_glyph_ranges == ImGui::GetIO().Fonts->GetGlyphRangesThai()) {
|
||||
if (needs_glyph_fallback) {
|
||||
ImFontConfig fallback_cfg = cfg;
|
||||
fallback_cfg.MergeMode = true;
|
||||
static constexpr ImWchar celsius_range[] = { 0x2103, 0x2103, 0 };
|
||||
io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/HarmonyOS_Sans_SC_Bold.ttf").c_str(), m_font_size, &fallback_cfg, celsius_range);
|
||||
io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/HarmonyOS_Sans_SC_Bold.ttf").c_str(), m_font_size, &fallback_cfg, ranges.Data);
|
||||
}
|
||||
|
||||
if (m_glyph_ranges == ImGui::GetIO().Fonts->GetGlyphRangesThai()) {
|
||||
@@ -2897,13 +2916,18 @@ void ImGuiWrapper::init_font(bool compress)
|
||||
glsafe(::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max_tex_size));
|
||||
constexpr int max_retries = 6;
|
||||
for (int attempt = 0; attempt < max_retries && io.Fonts->TexHeight > gl_max_tex_size; ++attempt) {
|
||||
io.Fonts->TexDesiredWidth = (io.Fonts->TexDesiredWidth > 0 ? io.Fonts->TexDesiredWidth : io.Fonts->TexWidth) * 2;
|
||||
const int width = io.Fonts->TexDesiredWidth > 0 ? io.Fonts->TexDesiredWidth : io.Fonts->TexWidth;
|
||||
// Both dimensions share the same limit, so widening past it would only trade an
|
||||
// illegal height for an illegal width.
|
||||
if (width * 2 > gl_max_tex_size)
|
||||
break;
|
||||
io.Fonts->TexDesiredWidth = width * 2;
|
||||
io.Fonts->Build();
|
||||
}
|
||||
if (io.Fonts->TexHeight > gl_max_tex_size) {
|
||||
// Shouldn't really happen
|
||||
BOOST_LOG_TRIVIAL(error) << "Font atlas height " << io.Fonts->TexHeight
|
||||
<< " still exceeds GL_MAX_TEXTURE_SIZE (" << gl_max_tex_size << ")"
|
||||
// Needs both a very large glyph set and a small GL_MAX_TEXTURE_SIZE.
|
||||
BOOST_LOG_TRIVIAL(error) << "Font atlas " << io.Fonts->TexWidth << "x" << io.Fonts->TexHeight
|
||||
<< " does not fit GL_MAX_TEXTURE_SIZE (" << gl_max_tex_size << ")"
|
||||
<< " after " << max_retries << " attempts; rendering may be incomplete";
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ bool ImageDPIFrame::Show(bool show)
|
||||
}
|
||||
|
||||
void ImageDPIFrame::set_bitmap(const wxBitmap &bit_map) {
|
||||
if (&bit_map && bit_map.IsOk()) {
|
||||
if (bit_map.IsOk()) {
|
||||
m_bitmap->SetBitmap(bit_map);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,13 +39,14 @@ static std::map<int, std::string> error_messages = {
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const wxPoint &pos, const wxSize &size)
|
||||
MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl3 *media_ctrl, const wxPoint &pos, const wxSize &size)
|
||||
: wxPanel(parent, wxID_ANY, pos, size)
|
||||
, m_media_ctrl(media_ctrl)
|
||||
{
|
||||
SetLabel("MediaPlayCtrl");
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
m_media_ctrl->Bind(wxEVT_MEDIA_STATECHANGED, &MediaPlayCtrl::onStateChanged, this);
|
||||
m_media_ctrl->SetIdleImage(from_u8(resources_dir() + "/images/live_stream_default.png"));
|
||||
|
||||
m_button_play = new Button(this, "", "media_play", wxBORDER_NONE);
|
||||
m_button_play->SetCanFocus(false);
|
||||
@@ -177,13 +178,6 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj)
|
||||
if (machine == m_machine) {
|
||||
if (m_last_state == MEDIASTATE_IDLE && IsEnabled())
|
||||
Play();
|
||||
else if (m_last_state == MEDIASTATE_LOADING && m_tutk_state == "disable"
|
||||
&& m_last_user_play + wxTimeSpan::Seconds(3) < wxDateTime::Now()) {
|
||||
// resend ttcode to printer
|
||||
if (auto agent = wxGetApp().getAgent())
|
||||
agent->get_camera_url(machine, [](auto) {}, wxGetApp().get_printer_cloud_provider());
|
||||
m_last_user_play = wxDateTime::Now();
|
||||
}
|
||||
return;
|
||||
}
|
||||
m_machine = machine;
|
||||
@@ -313,7 +307,7 @@ void MediaPlayCtrl::Play()
|
||||
// !m_lan_mode && !m_remote_proto && m_lan_proto == LVL_None (x)
|
||||
|
||||
if (m_lan_proto <= MachineObject::LVL_Disable && (m_lan_mode || !m_remote_proto)) {
|
||||
Stop(m_lan_proto == MachineObject::LVL_None
|
||||
Stop(m_lan_proto == MachineObject::LVL_None
|
||||
? _L("A problem occurred. Please update the printer firmware and try again.")
|
||||
: _L("LAN Only Liveview is off. Please turn on the liveview on printer screen."));
|
||||
return;
|
||||
@@ -351,7 +345,7 @@ void MediaPlayCtrl::Play()
|
||||
url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid");
|
||||
url += "&cli_ver=" + std::string(SLIC3R_VERSION);
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: " << hide_passwd(url,
|
||||
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: " << hide_passwd(url,
|
||||
{"?uid=", "authkey=", "passwd=", "license=", "token="});
|
||||
CallAfter([this, m, url] {
|
||||
if (m != m_machine) {
|
||||
@@ -426,7 +420,7 @@ void MediaPlayCtrl::Stop(wxString const &msg, wxString const &msg2)
|
||||
auto tunnel = m_url.empty() ? "" : into_u8(wxURI(m_url).GetPath()).substr(1);
|
||||
if (auto n = tunnel.find_first_of("/_"); n != std::string::npos)
|
||||
tunnel = tunnel.substr(0, n);
|
||||
if (last_state != wxMEDIASTATE_PLAYING && m_failed_code != 0
|
||||
if (last_state != wxMEDIASTATE_PLAYING && m_failed_code != 0
|
||||
&& m_last_failed_codes.find(m_failed_code) == m_last_failed_codes.end()
|
||||
&& (m_user_triggered || m_failed_retry > 3)) {
|
||||
m_last_failed_codes.insert(m_failed_code);
|
||||
@@ -560,7 +554,7 @@ void MediaPlayCtrl::ToggleStream()
|
||||
url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid");
|
||||
url += "&cli_ver=" + std::string(SLIC3R_VERSION);
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::ToggleStream: " << hide_passwd(url,
|
||||
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::ToggleStream: " << hide_passwd(url,
|
||||
{"?uid=", "authkey=", "passwd=", "license=", "token="});
|
||||
CallAfter([this, m, url] {
|
||||
if (m != m_machine) return;
|
||||
@@ -580,8 +574,8 @@ void MediaPlayCtrl::ToggleStream()
|
||||
}, wxGetApp().get_printer_cloud_provider());
|
||||
}
|
||||
|
||||
void MediaPlayCtrl::msw_rescale() {
|
||||
m_button_play->Rescale();
|
||||
void MediaPlayCtrl::msw_rescale() {
|
||||
m_button_play->Rescale();
|
||||
}
|
||||
|
||||
void MediaPlayCtrl::jump_to_play()
|
||||
@@ -715,7 +709,9 @@ void MediaPlayCtrl::media_proc()
|
||||
break;
|
||||
}
|
||||
else if (url == "<play>") {
|
||||
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: start play";
|
||||
m_media_ctrl->Play();
|
||||
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: end play";
|
||||
}
|
||||
else {
|
||||
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: start load";
|
||||
@@ -771,15 +767,15 @@ bool MediaPlayCtrl::start_stream_service(bool *need_install)
|
||||
if (!boost::filesystem::exists(file_dll) || boost::filesystem::last_write_time(file_dll) != boost::filesystem::last_write_time(file_dll2))
|
||||
boost::filesystem::copy_file(file_dll2, file_dll, boost::filesystem::copy_options::overwrite_existing);
|
||||
}
|
||||
boost::process::child process_source(file_source, file_url2.ToStdWstring(), boost::process::start_dir(tools_dir),
|
||||
boost::process::windows::create_no_window,
|
||||
boost::process::child process_source(file_source, file_url2.ToStdWstring(), boost::process::start_dir(tools_dir),
|
||||
boost::process::windows::create_no_window,
|
||||
boost::process::std_out > intermediate, boost::process::limit_handles);
|
||||
boost::process::child process_ffmpeg(file_ffmpeg, configss, boost::process::windows::create_no_window,
|
||||
boost::process::child process_ffmpeg(file_ffmpeg, configss, boost::process::windows::create_no_window,
|
||||
boost::process::std_in < intermediate, boost::process::limit_handles);
|
||||
#else
|
||||
boost::filesystem::permissions(file_source, boost::filesystem::owner_exe | boost::filesystem::add_perms);
|
||||
boost::filesystem::permissions(file_ffmpeg, boost::filesystem::owner_exe | boost::filesystem::add_perms);
|
||||
boost::process::child process_source(file_source, file_url2.data().AsInternal(), boost::process::start_dir(start_dir),
|
||||
boost::process::child process_source(file_source, file_url2.data().AsInternal(), boost::process::start_dir(start_dir),
|
||||
boost::process::std_out > intermediate, boost::process::limit_handles);
|
||||
boost::process::child process_ffmpeg(file_ffmpeg, configss, boost::process::std_in < intermediate, boost::process::limit_handles);
|
||||
#endif
|
||||
@@ -830,27 +826,16 @@ bool MediaPlayCtrl::get_stream_url(std::string *url)
|
||||
|
||||
}}
|
||||
|
||||
void wxMediaCtrl2::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||
void wxMediaCtrl_OnSize(wxWindow * ctrl, wxSize const & videoSize, int width, int height)
|
||||
{
|
||||
#ifdef __WXMAC__
|
||||
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
|
||||
#else
|
||||
wxMediaCtrl::DoSetSize(x, y, width, height, sizeFlags);
|
||||
#endif
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
if (m_gtk_video_window) {
|
||||
const wxSize client_size = GetClientSize();
|
||||
m_gtk_video_window->SetSize(0, 0, client_size.GetWidth(), client_size.GetHeight());
|
||||
}
|
||||
#endif
|
||||
if (sizeFlags & wxSIZE_USE_EXISTING) return;
|
||||
wxSize size = m_video_size;
|
||||
wxSize size = videoSize;
|
||||
if (!size.IsFullySpecified()) size = {16, 9};
|
||||
int maxHeight = (width * size.GetHeight() + size.GetHeight() - 1) / size.GetWidth();
|
||||
if (maxHeight != GetMaxHeight()) {
|
||||
// BOOST_LOG_TRIVIAL(info) << "wxMediaCtrl2::DoSetSize: width: " << width << ", height: " << height << ", maxHeight: " << maxHeight;
|
||||
SetMaxSize({-1, maxHeight});
|
||||
CallAfter([this] {
|
||||
if (auto p = GetParent()) {
|
||||
if (maxHeight != ctrl->GetMaxHeight()) {
|
||||
// BOOST_LOG_TRIVIAL(info) << "wxMediaCtrl_OnSize: width: " << width << ", height: " << height << ", maxHeight: " << maxHeight;
|
||||
ctrl->SetMaxSize({-1, maxHeight});
|
||||
ctrl->CallAfter([ctrl] {
|
||||
if (auto p = ctrl->GetParent()) {
|
||||
p->Layout();
|
||||
p->Refresh();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef MediaPlayCtrl_h
|
||||
#define MediaPlayCtrl_h
|
||||
|
||||
#include "wxMediaCtrl2.h"
|
||||
#include "wxMediaCtrl3.h"
|
||||
|
||||
#include <wx/panel.h>
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace GUI {
|
||||
class MediaPlayCtrl : public wxPanel
|
||||
{
|
||||
public:
|
||||
MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize);
|
||||
MediaPlayCtrl(wxWindow *parent, wxMediaCtrl3 *media_ctrl, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize);
|
||||
|
||||
~MediaPlayCtrl();
|
||||
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
// token
|
||||
std::shared_ptr<int> m_token = std::make_shared<int>(0);
|
||||
|
||||
wxMediaCtrl2 * m_media_ctrl;
|
||||
wxMediaCtrl3 * m_media_ctrl;
|
||||
wxMediaState m_last_state = MEDIASTATE_IDLE;
|
||||
std::string m_machine;
|
||||
int m_lan_proto = 0;
|
||||
@@ -90,7 +90,7 @@ private:
|
||||
bool m_device_busy = false;
|
||||
bool m_disable_lan = false;
|
||||
wxString m_url;
|
||||
|
||||
|
||||
std::deque<wxString> m_tasks;
|
||||
boost::mutex m_mutex;
|
||||
boost::condition_variable m_cond;
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include "Widgets/AxisCtrlButton.hpp"
|
||||
#include "Widgets/TextInput.hpp"
|
||||
#include "Widgets/StaticLine.hpp"
|
||||
#include "wxMediaCtrl2.h"
|
||||
#include "MediaPlayCtrl.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1468,12 +1468,12 @@ void ExtruderGroup::update_ams()
|
||||
size_t left = 4;
|
||||
size_t index = 0;
|
||||
for (size_t i = i4; i < ams_n4 && left > 0; ++i, ++index, left -= 2) {
|
||||
ams[index]->Update(i < ams_4.size() ? ams_4[i] : info4);
|
||||
ams[index]->UpdateInfo(i < ams_4.size() ? ams_4[i] : info4);
|
||||
ams[index]->Refresh();
|
||||
ams[index]->Open();
|
||||
}
|
||||
for (size_t i = i1; i < ams_n1 && left > 0; ++i, ++index, --left) {
|
||||
ams[index]->Update(i < ams_1.size() ? ams_1[i] : info1);
|
||||
ams[index]->UpdateInfo(i < ams_1.size() ? ams_1[i] : info1);
|
||||
ams[index]->Refresh();
|
||||
ams[index]->Open();
|
||||
}
|
||||
@@ -3871,7 +3871,7 @@ bool Sidebar::reset_bed_type_combox_choices(bool is_sidebar_init)
|
||||
}
|
||||
}
|
||||
m_last_combo_bedtype_count = p->combo_printer_bed->GetCount();
|
||||
if (!is_sidebar_init && &p->plater->get_partplate_list()) {
|
||||
if (!is_sidebar_init) {
|
||||
p->plater->get_partplate_list().check_all_plate_local_bed_type(m_cur_combox_bed_types);
|
||||
}
|
||||
return true;
|
||||
@@ -4915,7 +4915,10 @@ void Sidebar::edit_mixed_filament(size_t panel_idx)
|
||||
if (multi_colour_opt && cfg_idx < multi_colour_opt->values.size())
|
||||
multi_colour_opt->values[cfg_idx] = blended;
|
||||
|
||||
// The edited slot keeps its index, so nothing else refreshes the per-feature filament
|
||||
// lists - and its blended colour and type are what they show for it.
|
||||
update_mixed_filament_list();
|
||||
update_dynamic_filament_list();
|
||||
wxGetApp().plater()->update_project_dirty_from_presets();
|
||||
wxPostEvent(this, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, this));
|
||||
}
|
||||
@@ -5287,8 +5290,11 @@ void Sidebar::on_filament_count_change(size_t num_filaments)
|
||||
if (num_physical == choices.size()) {
|
||||
// The ctor pre-creates one combo, so a single-filament project hits this guard before
|
||||
// any layout pass has sized the scroll areas; refresh them here as well.
|
||||
// Adding a mixed slot also lands here, since only the virtual count changed, so the
|
||||
// per-feature filament lists - which do list mixed slots - have to be refreshed too.
|
||||
recalc_filament_scroll_sizes();
|
||||
update_mixed_filament_list();
|
||||
update_dynamic_filament_list();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5501,12 +5507,15 @@ void Sidebar::add_custom_filament(wxColour new_col, const std::string& preset_na
|
||||
|
||||
// Mixed-color slots are kept at the tail of the filament arrays, so a new physical
|
||||
// filament has to be inserted just after the last physical one rather than appended.
|
||||
// total == every slot (physical + mixed); insert_pos == the physical slot count.
|
||||
size_t total = wxGetApp().preset_bundle->filament_presets.size();
|
||||
size_t insert_pos = p->combos_filament.size();
|
||||
// Count off filament_is_mixed, not filament_presets or the combos: the extruder-count spinner
|
||||
// reaches this before the sidebar has rebuilt, and update_multi_material_filament_presets()
|
||||
// can have grown filament_presets alone.
|
||||
auto *bundle = wxGetApp().preset_bundle;
|
||||
size_t insert_pos = bundle->num_physical_filaments();
|
||||
size_t total = insert_pos + bundle->num_mixed_filaments();
|
||||
int filament_count = (int)(total + 1);
|
||||
std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString();
|
||||
wxGetApp().preset_bundle->set_num_filaments(filament_count, new_color);
|
||||
bundle->set_num_filaments(filament_count, new_color);
|
||||
|
||||
// Maintain physical-first ordering: rotate the new slot from end to insert_pos.
|
||||
// No mixed slots -> insert_pos == total -> every rotate below is a no-op.
|
||||
@@ -22077,7 +22086,7 @@ void Plater::show_object_info()
|
||||
auto mesh_errors = p->sidebar->obj_list()->get_mesh_errors_info(&info_manifold, &non_manifold_edges);
|
||||
|
||||
if (non_manifold_edges > 0) {
|
||||
info_manifold += into_u8("\n" + _L("Tips:") + "\n" + _L("Use \"Fix Model\" to repair the mesh."));
|
||||
info_manifold += "\n" + _L("Tips:") + "\n" + _L("Use \"Fix Model\" to repair the mesh.");
|
||||
}
|
||||
|
||||
info_manifold = "<Error>" + info_manifold + "</Error>";
|
||||
|
||||
@@ -662,10 +662,10 @@ PrinterFileSystem::File const &PrinterFileSystem::GetFile(size_t index, bool &se
|
||||
void PrinterFileSystem::Attached()
|
||||
{
|
||||
boost::unique_lock lock(m_mutex);
|
||||
m_recv_thread = std::move(boost::thread([w = weak_from_this()] {
|
||||
m_recv_thread = boost::thread([w = weak_from_this()] {
|
||||
boost::shared_ptr<PrinterFileSystem> s = w.lock();
|
||||
if (s) s->RecvMessageThread();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
void PrinterFileSystem::Start()
|
||||
|
||||
@@ -1,657 +0,0 @@
|
||||
/* bambusrc for gstreamer
|
||||
* integration with proprietary Bambu Lab blob for getting raw h.264 video
|
||||
*
|
||||
* Copyright (C) 2023 Joshua Wise <joshua@accelerated.tech>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
||||
* which case the following provisions apply instead of the ones
|
||||
* mentioned above:
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include "gstbambusrc.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#ifndef EXTERNAL_GST_PLUGIN
|
||||
#define BAMBU_DYNAMIC
|
||||
#endif
|
||||
#include "BambuTunnel.h"
|
||||
|
||||
#ifdef BAMBU_DYNAMIC
|
||||
// From PrinterFileSystem.
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
BambuLib *bambulib_get();
|
||||
BambuLib *_lib = NULL;
|
||||
#define BAMBULIB(x) (_lib->x)
|
||||
|
||||
#else
|
||||
#define BAMBULIB(x) (x)
|
||||
#endif
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_bambusrc_debug);
|
||||
#define GST_CAT_DEFAULT gst_bambusrc_debug
|
||||
|
||||
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS_ANY);
|
||||
//GST_STATIC_CAPS("video/x-h264,framerate=0/1,parsed=(boolean)false,stream-format=(string)byte-stream"));
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_LOCATION,
|
||||
};
|
||||
|
||||
static void gst_bambusrc_uri_handler_init (gpointer g_iface,
|
||||
gpointer iface_data);
|
||||
static void gst_bambusrc_finalize (GObject * gobject);
|
||||
static void gst_bambusrc_dispose (GObject * gobject);
|
||||
|
||||
static void gst_bambusrc_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_bambusrc_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
static GstStateChangeReturn gst_bambusrc_change_state (GstElement *
|
||||
element, GstStateChange transition);
|
||||
static GstFlowReturn gst_bambusrc_create (GstPushSrc * psrc,
|
||||
GstBuffer ** outbuf);
|
||||
static gboolean gst_bambusrc_start (GstBaseSrc * bsrc);
|
||||
static gboolean gst_bambusrc_stop (GstBaseSrc * bsrc);
|
||||
static gboolean gst_bambusrc_is_seekable (GstBaseSrc * bsrc);
|
||||
static gboolean gst_bambusrc_query (GstBaseSrc * bsrc, GstQuery * query);
|
||||
static gboolean gst_bambusrc_unlock (GstBaseSrc * bsrc);
|
||||
static gboolean gst_bambusrc_unlock_stop (GstBaseSrc * bsrc);
|
||||
static gboolean gst_bambusrc_set_location (GstBambuSrc * src,
|
||||
const gchar * uri, GError ** error);
|
||||
|
||||
#define gst_bambusrc_parent_class parent_class
|
||||
G_DEFINE_TYPE_WITH_CODE (GstBambuSrc, gst_bambusrc, GST_TYPE_PUSH_SRC,
|
||||
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
|
||||
gst_bambusrc_uri_handler_init));
|
||||
|
||||
static void
|
||||
gst_bambusrc_class_init (GstBambuSrcClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
GstBaseSrcClass *gstbasesrc_class;
|
||||
GstPushSrcClass *gstpushsrc_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
gstbasesrc_class = (GstBaseSrcClass *) klass;
|
||||
gstpushsrc_class = (GstPushSrcClass *) klass;
|
||||
|
||||
gobject_class->set_property = gst_bambusrc_set_property;
|
||||
gobject_class->get_property = gst_bambusrc_get_property;
|
||||
gobject_class->finalize = gst_bambusrc_finalize;
|
||||
gobject_class->dispose = gst_bambusrc_dispose;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_LOCATION,
|
||||
g_param_spec_string ("location", "Location",
|
||||
"URI to pass to Bambu Lab blobs", "",
|
||||
(GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
|
||||
|
||||
gst_element_class_set_static_metadata (gstelement_class, "Bambu Lab source",
|
||||
"Source/Network",
|
||||
"Receive data as a client over the network using the proprietary Bambu Lab blobs",
|
||||
"Joshua Wise <joshua@accelerated.tech>");
|
||||
gstelement_class->change_state =
|
||||
GST_DEBUG_FUNCPTR (gst_bambusrc_change_state);
|
||||
|
||||
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_bambusrc_start);
|
||||
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_bambusrc_stop);
|
||||
gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_bambusrc_unlock);
|
||||
gstbasesrc_class->unlock_stop =
|
||||
GST_DEBUG_FUNCPTR (gst_bambusrc_unlock_stop);
|
||||
gstbasesrc_class->is_seekable =
|
||||
GST_DEBUG_FUNCPTR (gst_bambusrc_is_seekable);
|
||||
gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_bambusrc_query);
|
||||
|
||||
gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_bambusrc_create);
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (gst_bambusrc_debug, "bambusrc", 0,
|
||||
"Bambu Lab src");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_bambusrc_reset (GstBambuSrc * src)
|
||||
{
|
||||
gst_caps_replace (&src->src_caps, NULL);
|
||||
if (src->tnl) {
|
||||
BAMBULIB(Bambu_Close)(src->tnl);
|
||||
BAMBULIB(Bambu_Destroy)(src->tnl);
|
||||
src->tnl = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_bambusrc_init (GstBambuSrc * src)
|
||||
{
|
||||
src->location = NULL;
|
||||
src->tnl = NULL;
|
||||
|
||||
gst_base_src_set_automatic_eos (GST_BASE_SRC (src), FALSE);
|
||||
gst_base_src_set_live(GST_BASE_SRC(src), TRUE);
|
||||
|
||||
gst_bambusrc_reset (src);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_bambusrc_dispose (GObject * gobject)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (gobject);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "dispose");
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_bambusrc_finalize (GObject * gobject)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (gobject);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "finalize");
|
||||
|
||||
g_free (src->location);
|
||||
if (src->tnl) {
|
||||
BAMBULIB(Bambu_Close)(src->tnl);
|
||||
BAMBULIB(Bambu_Destroy)(src->tnl);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_bambusrc_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LOCATION:
|
||||
{
|
||||
const gchar *location;
|
||||
|
||||
location = g_value_get_string (value);
|
||||
|
||||
if (location == NULL) {
|
||||
GST_WARNING ("location property cannot be NULL");
|
||||
goto done;
|
||||
}
|
||||
if (!gst_bambusrc_set_location (src, location, NULL)) {
|
||||
GST_WARNING ("badly formatted location");
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
done:
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_bambusrc_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LOCATION:
|
||||
g_value_set_string (value, src->location);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int gst_bambu_last_error = 0;
|
||||
|
||||
static GstFlowReturn
|
||||
gst_bambusrc_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
||||
{
|
||||
GstBambuSrc *src;
|
||||
|
||||
src = GST_BAMBUSRC (psrc);
|
||||
|
||||
(void) src;
|
||||
GST_DEBUG_OBJECT (src, "create()");
|
||||
|
||||
int rv;
|
||||
Bambu_Sample sample;
|
||||
|
||||
if (!src->tnl) {
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
while ((rv = BAMBULIB(Bambu_ReadSample)(src->tnl, &sample)) == Bambu_would_block) {
|
||||
GST_DEBUG_OBJECT(src, "create would block");
|
||||
usleep(33333); /* 30Hz */
|
||||
}
|
||||
|
||||
if (rv == Bambu_stream_end) {
|
||||
return GST_FLOW_EOS;
|
||||
}
|
||||
|
||||
if (rv != Bambu_success) {
|
||||
gst_bambu_last_error = rv;
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,68,0)
|
||||
gpointer sbuf = g_memdup2(sample.buffer, sample.size);
|
||||
#else
|
||||
gpointer sbuf = g_memdup(sample.buffer, sample.size);
|
||||
#endif
|
||||
*outbuf = gst_buffer_new_wrapped_full(0, sbuf, sample.size, 0, sample.size, sbuf, g_free);
|
||||
|
||||
/* Synthesize monotonic timestamps at the announced frame rate, anchored
|
||||
* to the first frame's arrival time. The X1C's RTSPS server emits
|
||||
* unreliable decode timestamps (wildly non-monotonic jumps, or sometimes
|
||||
* none at all); forwarding them directly froze the pipeline after a few
|
||||
* seconds. Pacing on a synthesized clock — the same trick mpv uses when
|
||||
* it reports "No video PTS! Making something up." — gives smooth
|
||||
* playback regardless of network jitter, and only drops late frames if
|
||||
* the printer can't keep up. A snap-back resets the anchor if real
|
||||
* arrival drifts more than two frame periods from the synthesized
|
||||
* timeline (e.g. announced framerate was wrong).
|
||||
*/
|
||||
GstClock *clock = GST_ELEMENT_CLOCK(psrc);
|
||||
GstClockTime base_time = gst_element_get_base_time((GstElement *)psrc);
|
||||
GstClockTime running_now = GST_CLOCK_TIME_NONE;
|
||||
if (clock) {
|
||||
GstClockTime now = gst_clock_get_time(clock);
|
||||
if (now != GST_CLOCK_TIME_NONE && now >= base_time)
|
||||
running_now = now - base_time;
|
||||
}
|
||||
|
||||
/* Adapt the period to actual inter-arrival time via EWMA. The announced
|
||||
* frame_rate is unreliable on Bambu printers (X1C announces 30 but
|
||||
* delivers ~28), so trusting it causes the synthesized timeline to drift
|
||||
* relative to real time, which makes the sink consider frames late and
|
||||
* skip pacing entirely. Measuring the real rate keeps PTS in step with
|
||||
* arrival on average, so the sink can pace inside bursts while still
|
||||
* tracking the printer's actual frame cadence.
|
||||
*/
|
||||
if (src->avg_period == 0) {
|
||||
int fps = src->frame_rate > 0 ? src->frame_rate : 30;
|
||||
src->avg_period = GST_SECOND / fps;
|
||||
}
|
||||
if (running_now != GST_CLOCK_TIME_NONE && src->last_arrival != 0) {
|
||||
GstClockTimeDiff delta = GST_CLOCK_DIFF(src->last_arrival, running_now);
|
||||
/* clamp to plausible video frame periods (5..200 ms) so a one-off
|
||||
* burst-of-zero or long stall doesn't poison the average */
|
||||
if (delta > 5 * GST_MSECOND && delta < 200 * GST_MSECOND) {
|
||||
src->avg_period = (src->avg_period * 15 + (GstClockTime)delta) / 16;
|
||||
}
|
||||
}
|
||||
src->last_arrival = (running_now != GST_CLOCK_TIME_NONE) ? running_now : src->last_arrival;
|
||||
GstClockTime period = src->avg_period;
|
||||
|
||||
/* Lead time: schedule frames a few periods in the future of their
|
||||
* arrival, so the sink has a small jitter buffer. Without this, frames
|
||||
* arriving slightly later than expected land behind the running clock
|
||||
* and the sink renders them immediately, producing visible stutter.
|
||||
* 100ms is invisible for a live print-monitor view.
|
||||
*/
|
||||
const GstClockTime LEAD = 100 * GST_MSECOND;
|
||||
|
||||
if (!src->sttime) {
|
||||
src->sttime = (running_now != GST_CLOCK_TIME_NONE) ? running_now + LEAD : LEAD;
|
||||
src->frame_count = 0;
|
||||
}
|
||||
|
||||
GstClockTime pts = src->sttime + src->frame_count * period;
|
||||
|
||||
/* Safety net: with the lead applied, expected drift is roughly -LEAD
|
||||
* (pts sits LEAD ns ahead of running_now). Re-anchor only if the
|
||||
* synthesized timeline diverges from that expectation by several frame
|
||||
* periods, which indicates a real disturbance (printer paused, stream
|
||||
* resumed, large fps change) rather than ordinary jitter.
|
||||
*/
|
||||
if (running_now != GST_CLOCK_TIME_NONE) {
|
||||
GstClockTimeDiff drift = GST_CLOCK_DIFF(pts, running_now);
|
||||
GstClockTimeDiff expected = -(GstClockTimeDiff)LEAD;
|
||||
GstClockTimeDiff slack = (GstClockTimeDiff)(4 * period);
|
||||
if (drift > expected + slack || drift < expected - slack) {
|
||||
GST_DEBUG_OBJECT(src, "ts drift %" G_GINT64_FORMAT " ns; re-anchoring", drift);
|
||||
src->sttime = running_now + LEAD;
|
||||
src->frame_count = 0;
|
||||
pts = src->sttime;
|
||||
}
|
||||
}
|
||||
|
||||
GST_BUFFER_PTS(*outbuf) = pts;
|
||||
GST_BUFFER_DTS(*outbuf) = pts;
|
||||
GST_BUFFER_DURATION(*outbuf) = period;
|
||||
src->frame_count++;
|
||||
GST_DEBUG_OBJECT(src,
|
||||
"sttime:%lu, DTS:%lu, PTS: %lu~",
|
||||
src->sttime, GST_BUFFER_DTS(*outbuf), GST_BUFFER_PTS(*outbuf));
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
static void _log(void *ctx, int lvl, const char *msg) {
|
||||
GstBambuSrc *src = (GstBambuSrc *) ctx;
|
||||
GST_DEBUG_OBJECT(src, "bambu: %s", msg);
|
||||
BAMBULIB(Bambu_FreeLogMsg)(msg);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_bambusrc_start (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (bsrc);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "start(\"%s\")", src->location);
|
||||
|
||||
if (src->tnl) {
|
||||
BAMBULIB(Bambu_Close)(src->tnl);
|
||||
BAMBULIB(Bambu_Destroy)(src->tnl);
|
||||
src->tnl = NULL;
|
||||
}
|
||||
|
||||
#ifdef BAMBU_DYNAMIC
|
||||
if (!_lib) {
|
||||
_lib = bambulib_get();
|
||||
if (!_lib->Bambu_Open) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (BAMBULIB(Bambu_Create)(&src->tnl, src->location) != Bambu_success) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int rv = 0;
|
||||
BAMBULIB(Bambu_SetLogger)(src->tnl, _log, (void *)src);
|
||||
if ((rv = BAMBULIB(Bambu_Open)(src->tnl)) != Bambu_success) {
|
||||
BAMBULIB(Bambu_Destroy)(src->tnl);
|
||||
src->tnl = NULL;
|
||||
gst_bambu_last_error = rv;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
while ((rv = BAMBULIB(Bambu_StartStream)(src->tnl, 1 /* video */)) == Bambu_would_block) {
|
||||
usleep(100000);
|
||||
}
|
||||
if (rv != Bambu_success) {
|
||||
BAMBULIB(Bambu_Close)(src->tnl);
|
||||
BAMBULIB(Bambu_Destroy)(src->tnl);
|
||||
src->tnl = NULL;
|
||||
gst_bambu_last_error = rv;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
src->video_type = AVC1;
|
||||
n = BAMBULIB(Bambu_GetStreamCount)(src->tnl);
|
||||
GST_INFO_OBJECT (src, "Bambu_GetStreamCount returned stream count=%d",n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
Bambu_StreamInfo info;
|
||||
BAMBULIB(Bambu_GetStreamInfo)(src->tnl, i, &info);
|
||||
|
||||
GST_INFO_OBJECT (src, "stream %d type=%d, sub_type=%d", i, info.type, info.sub_type);
|
||||
if (info.type == VIDE) {
|
||||
src->video_type = info.sub_type;
|
||||
src->frame_rate = info.format.video.frame_rate;
|
||||
GST_INFO_OBJECT (src, " width %d height=%d, frame_rate=%d",
|
||||
info.format.video.width, info.format.video.height, info.format.video.frame_rate);
|
||||
}
|
||||
}
|
||||
|
||||
src->sttime = 0;
|
||||
src->frame_count = 0;
|
||||
src->last_arrival = 0;
|
||||
src->avg_period = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_bambusrc_stop (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstBambuSrc *src;
|
||||
|
||||
src = GST_BAMBUSRC (bsrc);
|
||||
GST_DEBUG_OBJECT (src, "stop()");
|
||||
if (src->tnl) {
|
||||
BAMBULIB(Bambu_Close)(src->tnl);
|
||||
BAMBULIB(Bambu_Destroy)(src->tnl);
|
||||
src->tnl = NULL;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstStateChangeReturn
|
||||
gst_bambusrc_change_state (GstElement * element, GstStateChange transition)
|
||||
{
|
||||
GstStateChangeReturn ret;
|
||||
GstBambuSrc *src;
|
||||
|
||||
src = GST_BAMBUSRC (element);
|
||||
|
||||
(void) src;
|
||||
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||
//gst_bambusrc_session_close (src);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Interrupt a blocking request. */
|
||||
static gboolean
|
||||
gst_bambusrc_unlock (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstBambuSrc *src;
|
||||
|
||||
src = GST_BAMBUSRC (bsrc);
|
||||
GST_DEBUG_OBJECT (src, "unlock()");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Interrupt interrupt. */
|
||||
static gboolean
|
||||
gst_bambusrc_unlock_stop (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstBambuSrc *src;
|
||||
|
||||
src = GST_BAMBUSRC (bsrc);
|
||||
GST_DEBUG_OBJECT (src, "unlock_stop()");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_bambusrc_is_seekable (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (bsrc);
|
||||
|
||||
(void) src;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_bambusrc_query (GstBaseSrc * bsrc, GstQuery * query)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (bsrc);
|
||||
gboolean ret;
|
||||
GstSchedulingFlags flags;
|
||||
gint minsize, maxsize, align;
|
||||
|
||||
switch (GST_QUERY_TYPE (query)) {
|
||||
case GST_QUERY_URI:
|
||||
gst_query_set_uri (query, src->location);
|
||||
ret = TRUE;
|
||||
break;
|
||||
default:
|
||||
ret = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
ret = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
|
||||
|
||||
switch (GST_QUERY_TYPE (query)) {
|
||||
case GST_QUERY_SCHEDULING:
|
||||
gst_query_parse_scheduling (query, &flags, &minsize, &maxsize, &align);
|
||||
flags = (GstSchedulingFlags)((int)flags | (int)GST_SCHEDULING_FLAG_SEQUENTIAL);
|
||||
gst_query_set_scheduling (query, flags, minsize, maxsize, align);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_bambusrc_set_location (GstBambuSrc * src, const gchar * uri,
|
||||
GError ** error)
|
||||
{
|
||||
if (src->location) {
|
||||
g_free (src->location);
|
||||
src->location = NULL;
|
||||
}
|
||||
|
||||
if (uri == NULL)
|
||||
return FALSE;
|
||||
|
||||
src->location = g_strdup (uri);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstURIType
|
||||
gst_bambusrc_uri_get_type (GType type)
|
||||
{
|
||||
return GST_URI_SRC;
|
||||
}
|
||||
|
||||
static const gchar *const *
|
||||
gst_bambusrc_uri_get_protocols (GType type)
|
||||
{
|
||||
static const gchar *protocols[] = { "bambu", NULL };
|
||||
|
||||
return protocols;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
gst_bambusrc_uri_get_uri (GstURIHandler * handler)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (handler);
|
||||
|
||||
/* FIXME: make thread-safe */
|
||||
return g_strdup (src->location);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_bambusrc_uri_set_uri (GstURIHandler * handler, const gchar * uri,
|
||||
GError ** error)
|
||||
{
|
||||
GstBambuSrc *src = GST_BAMBUSRC (handler);
|
||||
|
||||
return gst_bambusrc_set_location (src, uri, error);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_bambusrc_uri_handler_init (gpointer g_iface, gpointer iface_data)
|
||||
{
|
||||
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
|
||||
|
||||
iface->get_type = gst_bambusrc_uri_get_type;
|
||||
iface->get_protocols = gst_bambusrc_uri_get_protocols;
|
||||
iface->get_uri = gst_bambusrc_uri_get_uri;
|
||||
iface->set_uri = gst_bambusrc_uri_set_uri;
|
||||
}
|
||||
|
||||
static gboolean gstbambusrc_init(GstPlugin *plugin)
|
||||
{
|
||||
return gst_element_register(plugin, "bambusrc", GST_RANK_PRIMARY, GST_TYPE_BAMBUSRC);
|
||||
}
|
||||
|
||||
#ifndef EXTERNAL_GST_PLUGIN
|
||||
|
||||
// for use inside of Bambu Slicer
|
||||
void gstbambusrc_register()
|
||||
{
|
||||
static int did_register = 0;
|
||||
if (did_register)
|
||||
return;
|
||||
did_register = 1;
|
||||
|
||||
gst_plugin_register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "bambusrc", "Bambu Lab source", gstbambusrc_init, "0.0.1", "GPL", "BambuStudio", "BambuStudio", "https://github.com/bambulab/BambuStudio");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#ifndef PACKAGE
|
||||
#define PACKAGE "bambusrc"
|
||||
#endif
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, bambusrc, "Bambu Lab source", gstbambusrc_init, "0.0.1", "GPL", "BambuStudio", "https://github.com/bambulab/BambuStudio")
|
||||
|
||||
#endif
|
||||
@@ -1,78 +0,0 @@
|
||||
/* bambusrc for gstreamer
|
||||
* integration with proprietary Bambu Lab blob for getting raw h.264 video
|
||||
*
|
||||
* Copyright (C) 2023 Joshua Wise <joshua@accelerated.tech>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
||||
* which case the following provisions apply instead of the ones
|
||||
* mentioned above:
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_BAMBUSRC_H__
|
||||
#define __GST_BAMBUSRC_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstpushsrc.h>
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_BAMBUSRC (gst_bambusrc_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GstBambuSrc, gst_bambusrc,
|
||||
GST, BAMBUSRC, GstPushSrc)
|
||||
|
||||
typedef void *Bambu_Tunnel;
|
||||
|
||||
struct _GstBambuSrc
|
||||
{
|
||||
GstPushSrc element;
|
||||
GstCaps *src_caps;
|
||||
gchar *location;
|
||||
Bambu_Tunnel tnl;
|
||||
GstClockTime sttime;
|
||||
int video_type;
|
||||
int frame_rate;
|
||||
guint64 frame_count;
|
||||
GstClockTime last_arrival;
|
||||
GstClockTime avg_period;
|
||||
};
|
||||
|
||||
extern void gstbambusrc_register();
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_BAMBUSRC_H__ */
|
||||
@@ -681,7 +681,7 @@ SearchDialog::SearchDialog(OptionsSearcher *searcher, Preset::Type type, wxWindo
|
||||
|
||||
SearchDialog::~SearchDialog() {}
|
||||
|
||||
void SearchDialog::Popup(wxPoint position /*= wxDefaultPosition*/)
|
||||
void SearchDialog::Popup(wxWindow *focus /*= nullptr*/)
|
||||
{
|
||||
/* const std::string& line = searcher->search_string();
|
||||
search_line->SetValue(line.empty() ? default_string : from_u8(line));
|
||||
@@ -696,17 +696,19 @@ void SearchDialog::Popup(wxPoint position /*= wxDefaultPosition*/)
|
||||
search_line2->SetValue(wxString(""));
|
||||
//const std::string &line = searcher->search_string();
|
||||
//searcher->search(into_u8(line), true);
|
||||
PopupWindow::Popup();
|
||||
PopupWindow::Popup(focus);
|
||||
search_line2->SetFocus();
|
||||
update_list();
|
||||
}
|
||||
|
||||
|
||||
#ifdef __WXMSW__
|
||||
void SearchDialog::MSWDismissUnfocusedPopup()
|
||||
{
|
||||
Dismiss();
|
||||
OnDismiss();
|
||||
}
|
||||
#endif // __WXMSW__
|
||||
|
||||
void SearchDialog::OnDismiss() { }
|
||||
|
||||
@@ -926,7 +928,7 @@ SearchObjectDialog::SearchObjectDialog(GUI::ObjectList* object_list, wxWindow* p
|
||||
|
||||
SearchObjectDialog::~SearchObjectDialog() {}
|
||||
|
||||
void SearchObjectDialog::Popup(wxPoint position /*= wxDefaultPosition*/)
|
||||
void SearchObjectDialog::Popup(wxWindow *focus /*= nullptr*/)
|
||||
{
|
||||
if (m_is_dismissing || this->IsShown()) {
|
||||
return;
|
||||
@@ -937,7 +939,7 @@ void SearchObjectDialog::Popup(wxPoint position /*= wxDefaultPosition*/)
|
||||
// dropdown list, otherwise the text input won't be usable
|
||||
m_object_list->SetFocus();
|
||||
#endif
|
||||
PopupWindow::Popup();
|
||||
PopupWindow::Popup(focus);
|
||||
search_line2->SetFocus();
|
||||
|
||||
m_object_list->assembly_plate_object_name();
|
||||
@@ -945,11 +947,13 @@ void SearchObjectDialog::Popup(wxPoint position /*= wxDefaultPosition*/)
|
||||
update_list();
|
||||
}
|
||||
|
||||
#ifdef __WXMSW__
|
||||
void SearchObjectDialog::MSWDismissUnfocusedPopup()
|
||||
{
|
||||
Dismiss();
|
||||
OnDismiss();
|
||||
}
|
||||
#endif // __WXMSW__
|
||||
|
||||
void SearchObjectDialog::OnDismiss() {}
|
||||
|
||||
|
||||
@@ -216,10 +216,12 @@ public:
|
||||
SearchDialog(OptionsSearcher *searcher, Preset::Type type, wxWindow *parent, TextInput *input, wxWindow *search_btn);
|
||||
~SearchDialog();
|
||||
|
||||
void MSWDismissUnfocusedPopup();
|
||||
void Popup(wxPoint position = wxDefaultPosition);
|
||||
void OnDismiss();
|
||||
void Dismiss();
|
||||
#ifdef __WXMSW__
|
||||
void MSWDismissUnfocusedPopup() override;
|
||||
#endif // __WXMSW__
|
||||
void Popup(wxWindow *focus = nullptr) override;
|
||||
void OnDismiss() override;
|
||||
void Dismiss() override;
|
||||
void Die();
|
||||
void msw_rescale();
|
||||
|
||||
@@ -260,10 +262,12 @@ public:
|
||||
SearchObjectDialog(GUI::ObjectList* object_list, wxWindow* parent, TextInput* input);
|
||||
~SearchObjectDialog();
|
||||
|
||||
void MSWDismissUnfocusedPopup();
|
||||
void Popup(wxPoint position = wxDefaultPosition);
|
||||
void OnDismiss();
|
||||
void Dismiss();
|
||||
#ifdef __WXMSW__
|
||||
void MSWDismissUnfocusedPopup() override;
|
||||
#endif // __WXMSW__
|
||||
void Popup(wxWindow *focus = nullptr) override;
|
||||
void OnDismiss() override;
|
||||
void Dismiss() override;
|
||||
void Die();
|
||||
|
||||
void OnInputText(wxCommandEvent& event);
|
||||
|
||||
@@ -483,7 +483,7 @@ SelectMachineDialog::SelectMachineDialog(Plater *plater)
|
||||
|
||||
m_link_edit_nozzle->Bind(wxEVT_LEFT_DOWN, [this](auto &e) {
|
||||
|
||||
if (this && this->m_is_in_sending_mode) {
|
||||
if (m_is_in_sending_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2847,7 +2847,7 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
|
||||
});
|
||||
|
||||
// STUDIO-9580
|
||||
/* use warning color if there are warning and normal messages* /
|
||||
/* use warning color if there are warning and normal messages*/
|
||||
/* use indexes if there are several messages*/
|
||||
/* add header and ending if there are several messages or has none block warnings*/
|
||||
if (confirm_text.size() > 1 || !is_printing_block)
|
||||
|
||||
@@ -978,18 +978,16 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
|
||||
m_send_job->on_check_ip_address_fail([this, token = std::weak_ptr(m_token)](int result) {
|
||||
CallAfter([token, this] {
|
||||
if (token.expired()) { return; }
|
||||
if (this) {
|
||||
SendFailedConfirm sfcDlg;
|
||||
auto res = sfcDlg.ShowModal();
|
||||
m_status_bar->cancel();
|
||||
SendFailedConfirm sfcDlg;
|
||||
auto res = sfcDlg.ShowModal();
|
||||
m_status_bar->cancel();
|
||||
|
||||
if (res == wxYES) {
|
||||
wxQueueEvent(m_button_ensure, new wxCommandEvent(wxEVT_BUTTON));
|
||||
} else if (res == wxAPPLY) {
|
||||
wxCommandEvent *evt = new wxCommandEvent(EVT_CLEAR_IPADDRESS);
|
||||
wxQueueEvent(this, evt);
|
||||
wxGetApp().show_ip_address_enter_dialog();
|
||||
}
|
||||
if (res == wxYES) {
|
||||
wxQueueEvent(m_button_ensure, new wxCommandEvent(wxEVT_BUTTON));
|
||||
} else if (res == wxAPPLY) {
|
||||
wxCommandEvent *evt = new wxCommandEvent(EVT_CLEAR_IPADDRESS);
|
||||
wxQueueEvent(this, evt);
|
||||
wxGetApp().show_ip_address_enter_dialog();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -983,7 +983,7 @@ void PrintingTaskPanel::paint(wxPaintEvent&)
|
||||
dc.DrawBitmap(m_thumbnail_bmp_display, wxPoint(0, 0));
|
||||
}
|
||||
dc.SetFont(Label::Body_12);
|
||||
|
||||
|
||||
if (m_plate_index >= 0) {
|
||||
wxString plate_id_str = wxString::Format("%d", m_plate_index);
|
||||
dc.DrawText(plate_id_str, wxPoint(4, 4));
|
||||
@@ -1271,7 +1271,7 @@ void PrintingTaskPanel::set_plate_index(int plate_idx)
|
||||
}
|
||||
|
||||
void PrintingTaskPanel::market_scoring_show()
|
||||
{
|
||||
{
|
||||
m_score_staticline->Show();
|
||||
m_score_subtask_info->Show();
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " show market scoring page";
|
||||
@@ -1402,7 +1402,7 @@ void StatusBasePanel::init_bitmaps()
|
||||
m_bitmap_fan_off = ScalableBitmap(this, "monitor_fan_off", 22);
|
||||
m_bitmap_speed = ScalableBitmap(this, "monitor_speed", 24);
|
||||
m_bitmap_speed_active = ScalableBitmap(this, "monitor_speed_active", 24);
|
||||
|
||||
|
||||
m_thumbnail_brokenimg = ScalableBitmap(this, "monitor_brokenimg", 120);
|
||||
m_thumbnail_sdcard = ScalableBitmap(this, "monitor_sdcard_thumbnail", 120);
|
||||
//m_bitmap_camera = create_scaled_bitmap("monitor_camera", nullptr, 18);
|
||||
@@ -1530,7 +1530,7 @@ wxBoxSizer *StatusBasePanel::create_monitoring_page()
|
||||
// media_ctrl_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
// media_ctrl_panel->SetBackgroundColour(*wxBLACK);
|
||||
// wxBoxSizer *bSizer_monitoring = new wxBoxSizer(wxVERTICAL);
|
||||
m_media_ctrl = new wxMediaCtrl2(this);
|
||||
m_media_ctrl = new wxMediaCtrl3(this);
|
||||
m_media_ctrl->SetMinSize(wxSize(PAGE_MIN_WIDTH, FromDIP(288)));
|
||||
|
||||
m_custom_camera_view = WebView::CreateWebView(this, wxEmptyString);
|
||||
@@ -2458,7 +2458,7 @@ StatusPanel::StatusPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, co
|
||||
m_project_task_panel->get_pause_resume_button()->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_subtask_pause_resume), NULL, this);
|
||||
m_project_task_panel->get_abort_button()->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_subtask_abort), NULL, this);
|
||||
m_project_task_panel->get_market_scoring_button()->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_market_scoring), NULL, this);
|
||||
m_project_task_panel->get_market_retry_buttom()->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_market_retry), NULL, this);
|
||||
m_project_task_panel->get_market_retry_buttom()->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_market_retry), NULL, this);
|
||||
m_project_task_panel->get_clean_button()->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_print_error_clean), NULL, this);
|
||||
|
||||
m_setting_button->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(StatusPanel::on_camera_enter), NULL, this);
|
||||
@@ -2520,7 +2520,7 @@ StatusPanel::~StatusPanel()
|
||||
m_project_task_panel->get_pause_resume_button()->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_subtask_pause_resume), NULL, this);
|
||||
m_project_task_panel->get_abort_button()->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_subtask_abort), NULL, this);
|
||||
m_project_task_panel->get_market_scoring_button()->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_market_scoring), NULL, this);
|
||||
m_project_task_panel->get_market_retry_buttom()->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_market_retry), NULL, this);
|
||||
m_project_task_panel->get_market_retry_buttom()->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_market_retry), NULL, this);
|
||||
m_project_task_panel->get_clean_button()->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_print_error_clean), NULL, this);
|
||||
|
||||
m_setting_button->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(StatusPanel::on_camera_enter), NULL, this);
|
||||
@@ -2566,7 +2566,7 @@ StatusPanel::~StatusPanel()
|
||||
if (sdcard_hint_dlg != nullptr)
|
||||
delete sdcard_hint_dlg;
|
||||
|
||||
if (m_score_data != nullptr) {
|
||||
if (m_score_data != nullptr) {
|
||||
delete m_score_data;
|
||||
}
|
||||
}
|
||||
@@ -2590,7 +2590,7 @@ void StatusPanel::init_scaled_buttons()
|
||||
m_bpButton_e_down_10->SetCornerRadius(FromDIP(12));
|
||||
}
|
||||
|
||||
void StatusPanel::on_market_scoring(wxCommandEvent &event) {
|
||||
void StatusPanel::on_market_scoring(wxCommandEvent &event) {
|
||||
if (obj && obj->is_makeworld_subtask() && obj->rating_info && obj->rating_info->request_successful) { // model is mall model and has rating_id
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_market_scoring" ;
|
||||
if (m_score_data && m_score_data->rating_id == obj->rating_info->rating_id) { // current score data for model is same as mall model
|
||||
@@ -2599,7 +2599,7 @@ void StatusPanel::on_market_scoring(wxCommandEvent &event) {
|
||||
int ret = m_score_dlg.ShowModal();
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": old data";
|
||||
|
||||
if (ret == wxID_OK) {
|
||||
if (ret == wxID_OK) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": old data is upload";
|
||||
m_score_data->rating_id = -1;
|
||||
m_project_task_panel->set_star_count_dirty(false);
|
||||
@@ -2621,11 +2621,11 @@ void StatusPanel::on_market_scoring(wxCommandEvent &event) {
|
||||
|
||||
std::string comment = obj->rating_info->content;
|
||||
if (!comment.empty()) { m_score_dlg.set_comment(comment); }
|
||||
|
||||
|
||||
std::vector<std::string> images_json_array;
|
||||
images_json_array = obj->rating_info->image_url_paths;
|
||||
if (!images_json_array.empty()) m_score_dlg.set_cloud_bitmap(images_json_array);
|
||||
|
||||
|
||||
int ret = m_score_dlg.ShowModal();
|
||||
|
||||
if (ret == wxID_OK) {
|
||||
@@ -3651,14 +3651,14 @@ void StatusPanel::update_basic_print_data(bool def)
|
||||
void StatusPanel::update_model_info()
|
||||
{
|
||||
auto get_subtask_fn = [this](BBLModelTask* subtask) {
|
||||
CallAfter([this, subtask]() {
|
||||
CallAfter([this, subtask]() {
|
||||
if (obj && obj->subtask_id_ == subtask->task_id) {
|
||||
obj->set_modeltask(subtask);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
if (wxGetApp().getAgent() && obj) {
|
||||
BBLSubTask* curr_task = obj->get_subtask();
|
||||
if (curr_task) {
|
||||
@@ -3982,7 +3982,7 @@ void StatusPanel::reset_printing_values()
|
||||
m_project_task_panel->update_left_time(NA_STR);
|
||||
m_project_task_panel->update_layers_num(true, wxString::Format(_L("Layer: %s"), NA_STR));
|
||||
update_calib_bitmap();
|
||||
|
||||
|
||||
task_thumbnail_state = ThumbnailState::PLACE_HOLDER;
|
||||
m_start_loading_thumbnail = false;
|
||||
m_load_sdcard_thumbnail = false;
|
||||
@@ -4037,7 +4037,7 @@ bool StatusPanel::check_axis_z_at_home(MachineObject* obj)
|
||||
}
|
||||
|
||||
void StatusPanel::on_axis_ctrl_z_up_10(wxCommandEvent &event)
|
||||
{
|
||||
{
|
||||
if (obj) {
|
||||
obj->command_axis_control("Z", 1.0, -10.0f, 900);
|
||||
if (!check_axis_z_at_home(obj))
|
||||
@@ -5396,7 +5396,7 @@ void StatusPanel::msw_rescale()
|
||||
m_calibration_btn->Rescale();
|
||||
|
||||
m_options_btn->SetMinSize(wxSize(-1, FromDIP(26)));
|
||||
m_options_btn->Rescale();
|
||||
m_options_btn->Rescale();
|
||||
|
||||
m_safety_btn->SetMinSize(wxSize(-1, FromDIP(26)));
|
||||
m_safety_btn->Rescale();
|
||||
@@ -5578,11 +5578,11 @@ ScoreDialog::ScoreDialog(wxWindow *parent, ScoreData *score_data)
|
||||
, m_upload_status_code(StatusCode::CODE_NUMBER)
|
||||
{
|
||||
m_tocken.reset(new int(0));
|
||||
|
||||
|
||||
wxBoxSizer *m_main_sizer = get_main_sizer(score_data->local_to_url_image, score_data->comment_text);
|
||||
|
||||
m_image_url_paths = score_data->image_url_paths;
|
||||
|
||||
|
||||
|
||||
this->SetSizer(m_main_sizer);
|
||||
Fit();
|
||||
@@ -5598,16 +5598,16 @@ void ScoreDialog::on_dpi_changed(const wxRect &suggested_rect) {}
|
||||
void ScoreDialog::OnBitmapClicked(wxMouseEvent &event)
|
||||
{
|
||||
wxStaticBitmap *clickedBitmap = dynamic_cast<wxStaticBitmap *>(event.GetEventObject());
|
||||
if (m_image.find(clickedBitmap) != m_image.end()) {
|
||||
if (m_image.find(clickedBitmap) != m_image.end()) {
|
||||
if (!m_image[clickedBitmap].is_selected) {
|
||||
for (auto panel : m_image[clickedBitmap].image_broad) {
|
||||
for (auto panel : m_image[clickedBitmap].image_broad) {
|
||||
panel->Show();
|
||||
}
|
||||
m_image[clickedBitmap].is_selected = true;
|
||||
m_selected_image_list.insert(clickedBitmap);
|
||||
} else {
|
||||
for (auto panel : m_image[clickedBitmap].image_broad) {
|
||||
panel->Hide();
|
||||
for (auto panel : m_image[clickedBitmap].image_broad) {
|
||||
panel->Hide();
|
||||
}
|
||||
m_image[clickedBitmap].is_selected = false;
|
||||
m_selected_image_list.erase(clickedBitmap);
|
||||
@@ -5624,9 +5624,9 @@ void ScoreDialog::OnBitmapClicked(wxMouseEvent &event)
|
||||
}
|
||||
|
||||
std::set <std::pair<wxStaticBitmap * ,wxString>> ScoreDialog::add_need_upload_imgs()
|
||||
{
|
||||
{
|
||||
std::set<std::pair<wxStaticBitmap *, wxString>> need_upload_images;
|
||||
for (auto bitmap : m_image) {
|
||||
for (auto bitmap : m_image) {
|
||||
if (!bitmap.second.is_uploaded) {
|
||||
wxString &local_image_path = bitmap.second.local_image_url;
|
||||
if (!local_image_path.empty()) { need_upload_images.insert(std::make_pair(bitmap.first, local_image_path)); }
|
||||
@@ -5646,7 +5646,7 @@ std::pair<wxStaticBitmap *, ScoreDialog::ImageMsg> ScoreDialog::create_local_thu
|
||||
cur_image_msg.local_image_url = local_path;
|
||||
cur_image_msg.img_url_paths = "";
|
||||
cur_image_msg.is_uploaded = false;
|
||||
|
||||
|
||||
wxStaticBitmap *imageCtrl = new wxStaticBitmap(this, wxID_ANY, wxBitmap(wxImage(local_path, wxBITMAP_TYPE_ANY).Rescale(FromDIP(80), FromDIP(60))), wxDefaultPosition,
|
||||
wxDefaultSize, 0);
|
||||
imageCtrl->Bind(wxEVT_LEFT_DOWN, &ScoreDialog::OnBitmapClicked, this);
|
||||
@@ -5711,7 +5711,7 @@ void ScoreDialog::update_static_bitmap(wxStaticBitmap* static_bitmap, wxImage im
|
||||
}
|
||||
|
||||
wxBoxSizer *ScoreDialog::create_broad_sizer(wxStaticBitmap *bitmap, ImageMsg& cur_image_msg)
|
||||
{
|
||||
{
|
||||
// tb: top and bottom lr: left and right
|
||||
auto m_image_tb_broad = new wxBoxSizer(wxVERTICAL);
|
||||
auto line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
|
||||
@@ -5755,7 +5755,7 @@ void ScoreDialog::init() {
|
||||
fail_image = wxImage(Slic3r::resources_dir() + "/images/oss_picture_load_failed.png", wxBITMAP_TYPE_ANY);
|
||||
}
|
||||
|
||||
wxBoxSizer *ScoreDialog::get_score_sizer() {
|
||||
wxBoxSizer *ScoreDialog::get_score_sizer() {
|
||||
wxBoxSizer *score_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxStaticText *static_score_text = new wxStaticText(this, wxID_ANY, _L("Rate"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
static_score_text->Wrap(-1);
|
||||
@@ -5878,18 +5878,18 @@ wxBoxSizer *ScoreDialog::get_photo_btn_sizer() {
|
||||
for (int i = 0; i < filePaths.GetCount(); i++) { //It's ugly, but useful
|
||||
bool is_repeat = false;
|
||||
for (auto image : m_image) {
|
||||
if (filePaths[i] == image.second.local_image_url) {
|
||||
if (filePaths[i] == image.second.local_image_url) {
|
||||
is_repeat = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!is_repeat) {
|
||||
local_path.push_back(std::make_pair(filePaths[i], ""));
|
||||
if (local_path.size() + m_image.size() > m_photo_nums) {
|
||||
break;
|
||||
if (local_path.size() + m_image.size() > m_photo_nums) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
load_photo(local_path);
|
||||
@@ -6007,7 +6007,7 @@ wxBoxSizer *ScoreDialog::get_button_sizer()
|
||||
}
|
||||
}
|
||||
progress_dialog->Hide();
|
||||
if (progress_dialog) {
|
||||
if (progress_dialog) {
|
||||
delete progress_dialog;
|
||||
progress_dialog = nullptr;
|
||||
}
|
||||
@@ -6141,7 +6141,7 @@ wxBoxSizer *ScoreDialog::get_main_sizer(const std::vector<std::pair<wxString, st
|
||||
m_main_sizer->Add(m_photo_sizer, 0, wxEXPAND | wxTOP, FromDIP(8));
|
||||
|
||||
m_image_sizer = new wxGridSizer(5, FromDIP(5), FromDIP(5));
|
||||
if (!images.empty()) {
|
||||
if (!images.empty()) {
|
||||
load_photo(images);
|
||||
}
|
||||
m_main_sizer->Add(m_image_sizer, 0, wxEXPAND | wxLEFT, FromDIP(24));
|
||||
@@ -6153,7 +6153,7 @@ wxBoxSizer *ScoreDialog::get_main_sizer(const std::vector<std::pair<wxString, st
|
||||
return m_main_sizer;
|
||||
}
|
||||
|
||||
ScoreData ScoreDialog::get_score_data() {
|
||||
ScoreData ScoreDialog::get_score_data() {
|
||||
ScoreData score_data;
|
||||
score_data.rating_id = m_rating_id;
|
||||
score_data.design_id = m_design_id;
|
||||
@@ -6164,20 +6164,20 @@ ScoreData ScoreDialog::get_score_data() {
|
||||
score_data.comment_text = m_comment_text->GetValue();
|
||||
score_data.image_url_paths = m_image_url_paths;
|
||||
for (auto img : m_image) { score_data.local_to_url_image.push_back(std::make_pair(img.second.local_image_url, img.second.img_url_paths)); }
|
||||
|
||||
|
||||
return score_data;
|
||||
}
|
||||
|
||||
void ScoreDialog::set_comment(std::string comment)
|
||||
{
|
||||
if (m_comment_text) {
|
||||
if (m_comment_text) {
|
||||
|
||||
m_comment_text->SetValue(wxString::FromUTF8(comment));
|
||||
}
|
||||
}
|
||||
|
||||
void ScoreDialog::set_cloud_bitmap(std::vector<std::string> cloud_bitmaps)
|
||||
{
|
||||
{
|
||||
m_image_url_paths = cloud_bitmaps;
|
||||
for (std::string &url : cloud_bitmaps) {
|
||||
if (std::string::npos == url.find(m_model_id)) continue;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/gbsizer.h>
|
||||
#include <wx/webrequest.h>
|
||||
#include "wxMediaCtrl2.h"
|
||||
#include "MediaPlayCtrl.h"
|
||||
#include "AMSSetting.hpp"
|
||||
#include "Calibration.hpp"
|
||||
@@ -195,11 +194,11 @@ public:
|
||||
void set_cloud_bitmap(std::vector<std::string> cloud_bitmaps);
|
||||
|
||||
protected:
|
||||
enum StatusCode {
|
||||
UPLOAD_PROGRESS = 0,
|
||||
UPLOAD_EXIST_ISSUE,
|
||||
enum StatusCode {
|
||||
UPLOAD_PROGRESS = 0,
|
||||
UPLOAD_EXIST_ISSUE,
|
||||
UPLOAD_IMG_FAILED,
|
||||
CODE_NUMBER
|
||||
CODE_NUMBER
|
||||
};
|
||||
|
||||
std::shared_ptr<int> m_tocken;
|
||||
@@ -217,7 +216,7 @@ protected:
|
||||
{
|
||||
wxString local_image_url; //local image path
|
||||
std::string img_url_paths; // oss url path
|
||||
vector<wxPanel *> image_broad;
|
||||
vector<wxPanel *> image_broad;
|
||||
bool is_selected;
|
||||
bool is_uploaded; // load
|
||||
wxBoxSizer * image_tb_broad = nullptr;
|
||||
@@ -252,7 +251,7 @@ protected:
|
||||
std::set<std::pair<wxStaticBitmap *, wxString>> add_need_upload_imgs();
|
||||
std::pair<wxStaticBitmap *, ImageMsg> create_local_thumbnail(wxString &local_path);
|
||||
std::pair<wxStaticBitmap *, ImageMsg> create_oss_thumbnail(std::string &oss_path);
|
||||
|
||||
|
||||
};
|
||||
|
||||
class PrintingTaskPanel : public wxPanel
|
||||
@@ -261,7 +260,7 @@ public:
|
||||
PrintingTaskPanel(wxWindow* parent, PrintingTaskType type);
|
||||
~PrintingTaskPanel();
|
||||
void create_panel(wxWindow* parent);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
MachineObject* m_obj{nullptr};
|
||||
@@ -353,7 +352,7 @@ public:
|
||||
void set_plate_index(int plate_idx = -1);
|
||||
void market_scoring_show();
|
||||
void market_scoring_hide();
|
||||
|
||||
|
||||
public:
|
||||
ScalableButton* get_abort_button() {return m_button_abort;};
|
||||
ScalableButton* get_pause_resume_button() {return m_button_pause_resume;};
|
||||
@@ -443,7 +442,7 @@ protected:
|
||||
wxStaticBitmap* m_camera_switch_button;
|
||||
|
||||
|
||||
wxMediaCtrl2 * m_media_ctrl;
|
||||
wxMediaCtrl3 * m_media_ctrl;
|
||||
MediaPlayCtrl * m_media_play_ctrl;
|
||||
|
||||
Label * m_staticText_printing;
|
||||
@@ -567,7 +566,7 @@ protected:
|
||||
virtual void on_bed_temp_kill_focus(wxFocusEvent &event) { event.Skip(); }
|
||||
virtual void on_bed_temp_set_focus(wxFocusEvent &event) { event.Skip(); }
|
||||
virtual void on_nozzle_temp_kill_focus(wxFocusEvent &event) { event.Skip(); }
|
||||
virtual void on_nozzle_temp_set_focus(wxFocusEvent &event) { event.Skip(); }
|
||||
virtual void on_nozzle_temp_set_focus(wxFocusEvent &event) { event.Skip(); }
|
||||
virtual void on_nozzle_fan_switch(wxCommandEvent &event) { event.Skip(); }
|
||||
virtual void on_printing_fan_switch(wxCommandEvent &event) { event.Skip(); }
|
||||
virtual void on_axis_ctrl_z_up_10(wxCommandEvent &event) { event.Skip(); }
|
||||
|
||||
+19
-15
@@ -2182,21 +2182,25 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
|
||||
|
||||
//Orca: sync filament num if it's a multi tool printer
|
||||
if (opt_key == "extruders_count" && !m_config->opt_bool("single_extruder_multi_material")){
|
||||
auto num_extruder = boost::any_cast<size_t>(value);
|
||||
int old_filament_size = wxGetApp().preset_bundle->filament_presets.size();
|
||||
std::vector<std::string> new_colors;
|
||||
for (int i = old_filament_size; i < num_extruder; ++i) {
|
||||
wxColour new_col = Plater::get_next_color_for_filament();
|
||||
std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString();
|
||||
new_colors.push_back(new_color);
|
||||
const size_t num_extruder = boost::any_cast<size_t>(value);
|
||||
auto *bundle = wxGetApp().preset_bundle;
|
||||
Sidebar &sidebar = wxGetApp().plater()->sidebar();
|
||||
// A tool changer feeds filament N from nozzle N, so the extruder count sizes the physical
|
||||
// run only; mixed slots are virtual and keep the tail. Go one slot at a time through the
|
||||
// sidebar's own +/- calls: they insert ahead of the mixed tail and renumber filament ids,
|
||||
// painted facets, custom g-code and mixed components, which a bulk resize clamps away.
|
||||
// Both also refresh the print tab and export the selections, so nothing to do afterwards.
|
||||
size_t physical = bundle->num_physical_filaments();
|
||||
while (physical != num_extruder) {
|
||||
if (physical < num_extruder)
|
||||
sidebar.add_custom_filament(Plater::get_next_color_for_filament());
|
||||
else
|
||||
sidebar.delete_filament(physical - 1); // physical > num_extruder >= 1
|
||||
const size_t updated = bundle->num_physical_filaments();
|
||||
if (updated == physical)
|
||||
break; // the call declined, e.g. the total slot limit - do not spin
|
||||
physical = updated;
|
||||
}
|
||||
// Mixed-color slots are virtual filaments at the tail of the list with no nozzle of their
|
||||
// own, so they are carried on top of the new extruder count instead of being truncated.
|
||||
const size_t total_filaments = num_extruder + wxGetApp().preset_bundle->num_mixed_filaments();
|
||||
wxGetApp().preset_bundle->set_num_filaments(total_filaments, new_colors);
|
||||
wxGetApp().plater()->on_filament_count_change(total_filaments);
|
||||
wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
|
||||
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
|
||||
}
|
||||
|
||||
//Orca: disable purge_in_prime_tower if single_extruder_multi_material is disabled
|
||||
@@ -7747,7 +7751,7 @@ void Tab::delete_preset()
|
||||
for (auto &preset2 : *m_presets)
|
||||
if (preset2.inherits() == current_preset.name) {
|
||||
++count;
|
||||
presets += "\n - " + preset2.name;
|
||||
presets += "\n - " + from_u8(preset2.name);
|
||||
}
|
||||
if (count > 0) {
|
||||
msg = _L("Presets inherited by other presets cannot be deleted!");
|
||||
|
||||
@@ -36,7 +36,6 @@ public:
|
||||
TabButton* pageButton;
|
||||
|
||||
private:
|
||||
wxWindow* m_parent;
|
||||
wxFlexGridSizer* m_buttons_sizer;
|
||||
wxBoxSizer* m_sizer;
|
||||
ScalableBitmap m_arrow_img;
|
||||
@@ -400,8 +399,6 @@ private:
|
||||
unsigned m_showTimeout,
|
||||
m_hideTimeout;
|
||||
|
||||
TabButtonsListCtrl *m_ctrl{nullptr};
|
||||
|
||||
};
|
||||
//#endif // _WIN32
|
||||
#endif // slic3r_Tabbook_hpp_
|
||||
|
||||
@@ -984,7 +984,7 @@ void AMSControl::UpdateAms(const std::string &series_name,
|
||||
if (cans->get_ams_id() == std::to_string(VIRTUAL_TRAY_MAIN_ID) || cans->get_ams_id() == std::to_string(VIRTUAL_TRAY_DEPUTY_ID)) {
|
||||
for (auto ifo : m_ext_info) {
|
||||
if (ifo.ams_id == ams_id) {
|
||||
cans->Update(ifo);
|
||||
cans->UpdateInfo(ifo);
|
||||
cans->show_sn_value(m_ams_model == AMSModel::AMS_LITE ? false : true);
|
||||
}
|
||||
}
|
||||
@@ -992,7 +992,7 @@ void AMSControl::UpdateAms(const std::string &series_name,
|
||||
else{
|
||||
for (auto ifo : m_ams_info) {
|
||||
if (ifo.ams_id == ams_id) {
|
||||
cans->Update(ifo);
|
||||
cans->UpdateInfo(ifo);
|
||||
cans->show_sn_value(m_ams_model == AMSModel::AMS_LITE ? false : true);
|
||||
}
|
||||
}
|
||||
@@ -1015,7 +1015,7 @@ void AMSControl::UpdateAms(const std::string &series_name,
|
||||
std::string id = ams_prv.second->get_ams_id();
|
||||
auto item = m_ams_item_list.find(id);
|
||||
if (item != m_ams_item_list.end())
|
||||
{ ams_prv.second->Update(item->second->get_ams_info());
|
||||
{ ams_prv.second->UpdateInfo(item->second->get_ams_info());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ AMSrefresh::AMSrefresh(wxWindow *parent, std::string ams_id, wxString can_id, Ca
|
||||
m_can_id = can_id.ToStdString();
|
||||
create(parent, wxID_ANY, pos, size);
|
||||
|
||||
Update(ams_id, info);
|
||||
UpdateInfo(ams_id, info);
|
||||
}
|
||||
|
||||
AMSrefresh::AMSrefresh(wxWindow *parent, std::string ams_id, int can_id, Caninfo info, const wxPoint &pos, const wxSize &size) : AMSrefresh()
|
||||
@@ -333,7 +333,7 @@ AMSrefresh::AMSrefresh(wxWindow *parent, std::string ams_id, int can_id, Caninfo
|
||||
m_can_id = wxString::Format("%d", can_id).ToStdString();
|
||||
create(parent, wxID_ANY, pos, size);
|
||||
|
||||
Update(ams_id, info);
|
||||
UpdateInfo(ams_id, info);
|
||||
}
|
||||
|
||||
AMSrefresh::~AMSrefresh()
|
||||
@@ -482,7 +482,7 @@ void AMSrefresh::paintEvent(wxPaintEvent &evt)
|
||||
dc.DrawText(m_refresh_id, pot);
|
||||
}
|
||||
|
||||
void AMSrefresh::Update(std::string ams_id, Caninfo info)
|
||||
void AMSrefresh::UpdateInfo(std::string ams_id, Caninfo info)
|
||||
{
|
||||
if (m_ams_id == ams_id && m_info == info)
|
||||
{
|
||||
@@ -945,7 +945,7 @@ AMSLib::AMSLib(wxWindow *parent, std::string ams_idx, Caninfo info, AMSModelOrig
|
||||
Bind(wxEVT_LEAVE_WINDOW, &AMSLib::on_leave_window, this);
|
||||
Bind(wxEVT_LEFT_DOWN, &AMSLib::on_left_down, this);
|
||||
|
||||
Update(info, ams_idx, false);
|
||||
UpdateInfo(info, ams_idx, false);
|
||||
}
|
||||
|
||||
AMSLib::~AMSLib()
|
||||
@@ -1730,7 +1730,7 @@ void AMSLib::on_pass_road(bool pass)
|
||||
}
|
||||
}
|
||||
|
||||
void AMSLib::Update(Caninfo info, std::string ams_idx, bool refresh)
|
||||
void AMSLib::UpdateInfo(Caninfo info, std::string ams_idx, bool refresh)
|
||||
{
|
||||
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
|
||||
if (!dev) return;
|
||||
@@ -1868,7 +1868,7 @@ AMSRoad::AMSRoad(wxWindow *parent, wxWindowID id, Caninfo info, int canindex, in
|
||||
|
||||
void AMSRoad::create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size) { wxWindow::Create(parent, id, pos, size); }
|
||||
|
||||
void AMSRoad::Update(AMSinfo amsinfo, Caninfo info, int canindex, int maxcan)
|
||||
void AMSRoad::UpdateInfo(AMSinfo amsinfo, Caninfo info, int canindex, int maxcan)
|
||||
{
|
||||
m_amsinfo = amsinfo;
|
||||
m_info = info;
|
||||
@@ -2083,9 +2083,6 @@ void AMSRoad::OnPassRoad(std::vector<AMSPassRoadMode> prord_list)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
/*************************************************
|
||||
Description:AMSRoadUpPart
|
||||
**************************************************/
|
||||
@@ -2124,7 +2121,7 @@ void AMSRoadUpPart::create(wxWindow* parent, wxWindowID id, const wxPoint& pos,
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void AMSRoadUpPart::Update(AMSinfo amsinfo)
|
||||
void AMSRoadUpPart::UpdateInfo(AMSinfo amsinfo)
|
||||
{
|
||||
if (m_amsinfo != amsinfo)
|
||||
{
|
||||
@@ -2616,7 +2613,7 @@ void AMSPreview::Close()
|
||||
Hide();
|
||||
}
|
||||
|
||||
void AMSPreview::Update(AMSinfo amsinfo)
|
||||
void AMSPreview::UpdateInfo(AMSinfo amsinfo)
|
||||
{
|
||||
if (m_amsinfo == amsinfo)
|
||||
{
|
||||
@@ -2954,7 +2951,7 @@ AMSHumidity::AMSHumidity(wxWindow* parent, wxWindowID id, AMSinfo info, const wx
|
||||
}
|
||||
});
|
||||
|
||||
Update(info);
|
||||
UpdateInfo(info);
|
||||
}
|
||||
|
||||
void AMSHumidity::create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size) {
|
||||
@@ -2963,7 +2960,7 @@ void AMSHumidity::create(wxWindow* parent, wxWindowID id, const wxPoint& pos, co
|
||||
}
|
||||
|
||||
|
||||
void AMSHumidity::Update(AMSinfo amsinfo)
|
||||
void AMSHumidity::UpdateInfo(AMSinfo amsinfo)
|
||||
{
|
||||
if (m_amsinfo != amsinfo)
|
||||
{
|
||||
@@ -3380,7 +3377,7 @@ void AmsItem::AddLiteCan(Caninfo caninfo, int canindex, wxGridSizer* sizer)
|
||||
//m_can_road_list[caninfo.can_id] = m_panel_road;
|
||||
}
|
||||
|
||||
void AmsItem::Update(AMSinfo info)
|
||||
void AmsItem::UpdateInfo(AMSinfo info)
|
||||
{
|
||||
if (m_info == info)
|
||||
{
|
||||
@@ -3392,7 +3389,7 @@ void AmsItem::Update(AMSinfo info)
|
||||
|
||||
if (m_humidity)
|
||||
{
|
||||
m_humidity->Update(m_info);
|
||||
m_humidity->UpdateInfo(m_info);
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_can_count; i++) {
|
||||
@@ -3401,7 +3398,7 @@ void AmsItem::Update(AMSinfo info)
|
||||
|
||||
auto refresh = it->second;
|
||||
if (refresh != nullptr){
|
||||
refresh->Update(info.ams_id, info.cans[i]);
|
||||
refresh->UpdateInfo(info.ams_id, info.cans[i]);
|
||||
refresh->Show();
|
||||
}
|
||||
}
|
||||
@@ -3410,7 +3407,7 @@ void AmsItem::Update(AMSinfo info)
|
||||
AMSLib* lib = m_can_lib_list[std::to_string(i)];
|
||||
if (lib != nullptr){
|
||||
if (i < m_can_count){
|
||||
lib->Update(info.cans[i], info.ams_id);
|
||||
lib->UpdateInfo(info.cans[i], info.ams_id);
|
||||
lib->Show();
|
||||
}
|
||||
else{
|
||||
@@ -3419,12 +3416,7 @@ void AmsItem::Update(AMSinfo info)
|
||||
}
|
||||
}
|
||||
if (m_panel_road != nullptr){
|
||||
m_panel_road->Update(m_info);
|
||||
}
|
||||
|
||||
if (true || m_ams_model == AMSModel::GENERIC_AMS) {
|
||||
/*m_panel_road->Update(m_info, info.cans[0]);
|
||||
m_panel_road->Show();*/
|
||||
m_panel_road->UpdateInfo(m_info);
|
||||
}
|
||||
|
||||
Layout();
|
||||
|
||||
@@ -312,7 +312,7 @@ public:
|
||||
~AMSrefresh();
|
||||
|
||||
public:
|
||||
void Update(std::string ams_id, Caninfo info);
|
||||
void UpdateInfo(std::string ams_id, Caninfo info);
|
||||
|
||||
std::string GetCanId() const { return m_info.can_id; };
|
||||
|
||||
@@ -492,7 +492,7 @@ public:
|
||||
AMSModel m_ams_model;
|
||||
AMSModelOriginType m_ext_type = { AMSModelOriginType::GENERIC_EXT };
|
||||
|
||||
void Update(Caninfo info, std::string ams_idx, bool refresh = true);
|
||||
void UpdateInfo(Caninfo info, std::string ams_idx, bool refresh = true);
|
||||
void UnableSelected() { m_unable_selected = true; };
|
||||
void EableSelected() { m_unable_selected = false; };
|
||||
void OnSelected();
|
||||
@@ -581,7 +581,7 @@ public:
|
||||
double m_radius = {4};
|
||||
wxColour m_road_def_color;
|
||||
wxColour m_road_color;
|
||||
void Update(AMSinfo amsinfo, Caninfo info, int canindex, int maxcan);
|
||||
void UpdateInfo(AMSinfo amsinfo, Caninfo info, int canindex, int maxcan);
|
||||
|
||||
std::vector<ScalableBitmap> ams_humidity_img;
|
||||
|
||||
@@ -614,7 +614,7 @@ public:
|
||||
void create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
|
||||
|
||||
public:
|
||||
void Update(AMSinfo amsinfo);
|
||||
void UpdateInfo(AMSinfo amsinfo);
|
||||
|
||||
void OnVamsLoading(bool load, wxColour col = AMS_CONTROL_GRAY500);
|
||||
void SetPassRoadColour(wxColour col);
|
||||
@@ -715,7 +715,7 @@ public:
|
||||
void Open();
|
||||
void Close();
|
||||
|
||||
void Update(AMSinfo amsinfo);
|
||||
void UpdateInfo(AMSinfo amsinfo);
|
||||
void create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size);
|
||||
void OnEnterWindow(wxMouseEvent &evt);
|
||||
void OnLeaveWindow(wxMouseEvent &evt);
|
||||
@@ -768,7 +768,7 @@ public:
|
||||
int m_canindex = { 0 };
|
||||
bool m_selected = { false };
|
||||
double m_radius = { 12 };
|
||||
void Update(AMSinfo amsinfo);
|
||||
void UpdateInfo(AMSinfo amsinfo);
|
||||
|
||||
std::vector<ScalableBitmap> ams_humidity_imgs;
|
||||
std::vector<ScalableBitmap> ams_humidity_dark_imgs;
|
||||
@@ -801,7 +801,7 @@ public:
|
||||
AmsItem(wxWindow *parent, AMSinfo info, AMSModel model, AMSPanelPos pos);
|
||||
~AmsItem();
|
||||
|
||||
void Update(AMSinfo info);
|
||||
void UpdateInfo(AMSinfo info);
|
||||
void create(wxWindow *parent);
|
||||
void AddCan(Caninfo caninfo, int canindex, int maxcan, wxBoxSizer* sizer);
|
||||
void AddLiteCan(Caninfo caninfo, int canindex, wxGridSizer* sizer);
|
||||
|
||||
@@ -124,7 +124,7 @@ void AxisCtrlButton::SetInnerBackgroundColor(StateColor const& color)
|
||||
|
||||
void AxisCtrlButton::SetBitmap(ScalableBitmap &bmp)
|
||||
{
|
||||
if (&bmp && (& bmp.bmp()) && (bmp.bmp().IsOk())) {
|
||||
if (bmp.bmp().IsOk()) {
|
||||
m_icon = bmp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ bool ComboBox::SetFont(wxFont const& font)
|
||||
|
||||
int ComboBox::Append(const wxString &item, const wxBitmap &bitmap, int style)
|
||||
{
|
||||
if (&bitmap && bitmap.IsOk()) {
|
||||
if (bitmap.IsOk()) {
|
||||
return Append(item, bitmap, nullptr, style);
|
||||
}
|
||||
return Append(item, wxNullBitmap, nullptr, style);
|
||||
@@ -219,7 +219,7 @@ int ComboBox::Append(const wxString &text,
|
||||
void * clientData,
|
||||
int style)
|
||||
{
|
||||
if (&bitmap && bitmap.IsOk()) {
|
||||
if (bitmap.IsOk()) {
|
||||
return Append(text, bitmap, wxString{}, clientData, style);
|
||||
}
|
||||
return Append(text, wxNullBitmap, wxString{}, clientData, style);
|
||||
@@ -237,7 +237,7 @@ int ComboBox::Append(const wxString &text,
|
||||
void *clientData,
|
||||
int style)
|
||||
{
|
||||
auto valid_bit_map = (&bitmap && bitmap.IsOk()) ? bitmap : wxNullBitmap;
|
||||
auto valid_bit_map = bitmap.IsOk() ? bitmap : wxNullBitmap;
|
||||
Item item{text, wxEmptyString, valid_bit_map, valid_bit_map, clientData, group_key, group_label};
|
||||
item.style = style;
|
||||
items.push_back(item);
|
||||
@@ -333,7 +333,7 @@ wxBitmap ComboBox::GetItemBitmap(unsigned int n) { return items[n].icon; }
|
||||
void ComboBox::SetItemBitmap(unsigned int n, wxBitmap const &bitmap)
|
||||
{
|
||||
if (n >= items.size()) return;
|
||||
items[n].icon = (&bitmap && bitmap.IsOk()) ? bitmap : wxNullBitmap;
|
||||
items[n].icon = bitmap.IsOk() ? bitmap : wxNullBitmap;
|
||||
drop.Invalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ void LabeledStaticBox::SetBorderColor(StateColor const &color)
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void LabeledStaticBox::SetFont(wxFont set_font)
|
||||
bool LabeledStaticBox::SetFont(const wxFont &set_font)
|
||||
{
|
||||
m_font = set_font;
|
||||
|
||||
@@ -109,6 +109,7 @@ void LabeledStaticBox::SetFont(wxFont set_font)
|
||||
m_label_width = tW;
|
||||
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LabeledStaticBox::Enable(bool enable)
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
void SetBorderColor(StateColor const &color);
|
||||
|
||||
void SetFont(wxFont set_font);
|
||||
bool SetFont(const wxFont &set_font) override;
|
||||
|
||||
bool Enable(bool enable) override;
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ ScrolledWindow::ScrolledWindow(wxWindow *parent, wxWindowID id, wxPoint position
|
||||
m_bottomScrollbar = NULL;
|
||||
m_verticalSplitter = NULL;
|
||||
m_horizontalSplitter = NULL;
|
||||
m_userPanel = NULL;
|
||||
m_scroll_win = NULL;
|
||||
|
||||
m_marginWidth = marginWidth;
|
||||
|
||||
@@ -110,23 +112,13 @@ void ScrolledWindow::SetTipColor(wxColour color)
|
||||
if (m_bottomScrollbar) m_bottomScrollbar->SetTipColor(color);
|
||||
}
|
||||
|
||||
void ScrolledWindow::Refresh()
|
||||
bool ScrolledWindow::SetBackgroundColour(const wxColour &color)
|
||||
{
|
||||
// m_rightScrollbar->SetViewStart(0);
|
||||
// m_rightScrollbar->Refresh();
|
||||
// m_rightScrollbar->Update();
|
||||
// m_userPanel->Refresh();
|
||||
// m_bottomScrollbar->SetViewStart(0);
|
||||
// m_rightScrollbar->Refresh();
|
||||
// m_bottomScrollbar->Refresh();
|
||||
}
|
||||
|
||||
void ScrolledWindow::SetBackgroundColour(wxColour color)
|
||||
{
|
||||
wxWindow::SetBackgroundColour(color);
|
||||
const bool result = wxWindow::SetBackgroundColour(color);
|
||||
m_verticalSplitter->SetBackgroundColour(color);
|
||||
m_userPanel->SetBackgroundColour(color);
|
||||
m_scroll_win->SetBackgroundColour(color);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ScrolledWindow::SetMarginColor(wxColour color)
|
||||
|
||||
@@ -15,8 +15,7 @@ public:
|
||||
ScrolledWindow(wxWindow *parent, wxWindowID id, wxPoint position, wxSize size, long style, int marginWidth = 0, int scrollbarWidth = 4, int tipLength = 0);
|
||||
void OnMouseWheel(wxMouseEvent &event);
|
||||
void SetTipColor(wxColour color);
|
||||
void Refresh();
|
||||
void SetBackgroundColour(wxColour color);
|
||||
bool SetBackgroundColour(const wxColour &color) override;
|
||||
|
||||
void SetMarginColor(wxColour color);
|
||||
void SetScrollbarColor(wxColour color);
|
||||
@@ -27,7 +26,7 @@ public:
|
||||
// wxSplitterWindow* GetVerticalSplitter() { return m_verticalSplitter; }
|
||||
// wxSplitterWindow* GetHorizontalSplitter() { return m_horizontalSplitter; }
|
||||
bool IsBothDirections() { return m_bothDirections; }
|
||||
virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY, int noUnitsX, int noUnitsY, int xPos = 0, int yPos = 0, bool noRefresh = false);
|
||||
virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY, int noUnitsX, int noUnitsY, int xPos = 0, int yPos = 0, bool noRefresh = false) override;
|
||||
|
||||
private:
|
||||
wxPanel * m_userPanel; // the panel targeted by the scrolled window
|
||||
|
||||
@@ -111,7 +111,7 @@ int TabCtrl::AppendItem(const wxString &item,
|
||||
btns.push_back(btn);
|
||||
if (btns.size() > 1)
|
||||
sizer->GetItem(sizer->GetItemCount() - 1)->SetMinSize({0, 0});
|
||||
sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, TAB_BUTTON_SPACE * 2);
|
||||
sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, TAB_BUTTON_SPACE);
|
||||
sizer->AddStretchSpacer(1);
|
||||
relayout();
|
||||
return btns.size() - 1;
|
||||
@@ -225,8 +225,9 @@ bool TabCtrl::IsVisible(unsigned int item) const
|
||||
|
||||
void TabCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||
{
|
||||
auto size = GetSize();
|
||||
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
|
||||
if (sizeFlags & wxSIZE_USE_EXISTING) return;
|
||||
if (size == GetSize()) return;
|
||||
relayout();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,633 +0,0 @@
|
||||
#include "wxMediaCtrl2.h"
|
||||
#include "libslic3r/Time.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "LinuxDisplayBackend.hpp"
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <string>
|
||||
#ifdef __WIN32__
|
||||
#include <winuser.h>
|
||||
#include <versionhelpers.h>
|
||||
#include <wx/msw/registry.h>
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
|
||||
#ifdef __LINUX__
|
||||
#include "Printer/gstbambusrc.h"
|
||||
#include <gst/gst.h> // main gstreamer header
|
||||
#endif
|
||||
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
#include <gtk/gtk.h>
|
||||
#include <wx/nativewin.h>
|
||||
|
||||
namespace {
|
||||
bool ensure_gstreamer_initialized_for_liveview()
|
||||
{
|
||||
GError* error = nullptr;
|
||||
if (!gst_init_check(nullptr, nullptr, &error)) {
|
||||
BOOST_LOG_TRIVIAL(error) << "wxMediaCtrl2: gst_init_check failed before native Wayland liveview setup"
|
||||
<< (error ? std::string(": ") + error->message : std::string());
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_gstreamer_feature_available(const char* feature)
|
||||
{
|
||||
if (!ensure_gstreamer_initialized_for_liveview())
|
||||
return false;
|
||||
|
||||
GstElementFactory* factory = gst_element_factory_find(feature);
|
||||
if (!factory)
|
||||
return false;
|
||||
|
||||
gst_object_unref(factory);
|
||||
return true;
|
||||
}
|
||||
|
||||
void set_gstreamer_feature_rank(const char* feature, guint rank)
|
||||
{
|
||||
GstElementFactory* factory = gst_element_factory_find(feature);
|
||||
if (!factory)
|
||||
return;
|
||||
|
||||
gst_plugin_feature_set_rank(GST_PLUGIN_FEATURE(factory), rank);
|
||||
gst_object_unref(factory);
|
||||
}
|
||||
|
||||
void configure_wayland_gstreamer_liveview_path()
|
||||
{
|
||||
static bool configured = false;
|
||||
if (configured)
|
||||
return;
|
||||
configured = true;
|
||||
|
||||
if (!ensure_gstreamer_initialized_for_liveview())
|
||||
return;
|
||||
|
||||
// Prefer software decode for Bambu liveview on Wayland/NVIDIA, where
|
||||
// zero-copy GL/DMABUF display paths can be fragile. Keep hardware
|
||||
// decoders available as lower-ranked fallbacks for VAAPI/NVDEC/V4L2-only
|
||||
// installations instead of passing preflight and then blocking autoplug.
|
||||
set_gstreamer_feature_rank("avdec_h264", GST_RANK_PRIMARY + 300);
|
||||
set_gstreamer_feature_rank("openh264dec", GST_RANK_PRIMARY + 100);
|
||||
set_gstreamer_feature_rank("nvh264dec", GST_RANK_MARGINAL);
|
||||
set_gstreamer_feature_rank("vaapih264dec", GST_RANK_MARGINAL);
|
||||
set_gstreamer_feature_rank("vah264dec", GST_RANK_MARGINAL);
|
||||
set_gstreamer_feature_rank("v4l2h264dec", GST_RANK_MARGINAL);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // defined(__LINUX__) && defined(__WXGTK__)
|
||||
|
||||
#ifdef __LINUX__
|
||||
extern "C" int gst_bambu_last_error;
|
||||
|
||||
class WXDLLIMPEXP_MEDIA
|
||||
wxGStreamerMediaBackend : public wxMediaBackendCommonBase
|
||||
{
|
||||
public:
|
||||
GstElement *m_playbin; // GStreamer media element
|
||||
};
|
||||
#endif
|
||||
|
||||
wxDEFINE_EVENT(EVT_MEDIA_CTRL_STAT, wxCommandEvent);
|
||||
|
||||
wxMediaCtrl2::wxMediaCtrl2(wxWindow *parent)
|
||||
{
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
m_native_wayland = Slic3r::GUI::is_running_on_wayland();
|
||||
if (m_native_wayland && is_gstreamer_feature_available("gtksink"))
|
||||
configure_wayland_gstreamer_liveview_path();
|
||||
else if (m_native_wayland) {
|
||||
m_gtk_sink_error = _L("Native Wayland liveview requires the GStreamer GTK video sink. Please install the gtksink plugin for GStreamer, then restart OrcaSlicer.");
|
||||
BOOST_LOG_TRIVIAL(warning) << "wxMediaCtrl2: native Wayland liveview disabled because GStreamer gtksink is unavailable";
|
||||
}
|
||||
#endif
|
||||
#ifdef __WIN32__
|
||||
auto hModExe = GetModuleHandle(NULL);
|
||||
// BOOST_LOG_TRIVIAL(info) << "wxMediaCtrl2: GetModuleHandle " << hModExe;
|
||||
auto NvOptimusEnablement = (DWORD *) GetProcAddress(hModExe, "NvOptimusEnablement");
|
||||
auto AmdPowerXpressRequestHighPerformance = (int *) GetProcAddress(hModExe, "AmdPowerXpressRequestHighPerformance");
|
||||
if (NvOptimusEnablement) {
|
||||
// BOOST_LOG_TRIVIAL(info) << "wxMediaCtrl2: NvOptimusEnablement " << *NvOptimusEnablement;
|
||||
*NvOptimusEnablement = 0;
|
||||
}
|
||||
if (AmdPowerXpressRequestHighPerformance) {
|
||||
// BOOST_LOG_TRIVIAL(info) << "wxMediaCtrl2: AmdPowerXpressRequestHighPerformance " << *AmdPowerXpressRequestHighPerformance;
|
||||
*AmdPowerXpressRequestHighPerformance = 0;
|
||||
}
|
||||
#endif
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
if (m_native_wayland)
|
||||
wxControl::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
else
|
||||
#endif
|
||||
wxMediaCtrl::Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxMEDIACTRLPLAYERCONTROLS_NONE);
|
||||
#ifdef __LINUX__
|
||||
gstbambusrc_register();
|
||||
#ifdef __WXGTK__
|
||||
if (m_native_wayland && m_gtk_sink_error.empty())
|
||||
m_use_gtk_sink = CreateGtkSinkPlayer();
|
||||
if (m_native_wayland && !m_use_gtk_sink && m_gtk_sink_error.empty())
|
||||
m_gtk_sink_error = _L("Failed to initialize the native Wayland GStreamer video sink. Please check your GStreamer GTK plugin installation.");
|
||||
#endif
|
||||
if (!m_use_gtk_sink && m_imp) {
|
||||
auto playbin = reinterpret_cast<wxGStreamerMediaBackend *>(m_imp)->m_playbin;
|
||||
g_object_set(G_OBJECT(playbin),
|
||||
"audio-sink", nullptr,
|
||||
nullptr);
|
||||
} else if (!m_use_gtk_sink) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "wxMediaCtrl2: wxMediaCtrl backend is unavailable";
|
||||
}
|
||||
Bind(wxEVT_MEDIA_LOADED, [this](auto & e) {
|
||||
m_loaded = true;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(0);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
wxMediaCtrl2::~wxMediaCtrl2()
|
||||
{
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
DestroyGtkSinkPlayer();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
bool wxMediaCtrl2::CreateGtkSinkPlayer()
|
||||
{
|
||||
GstElement *playbin = gst_element_factory_make("playbin", "orca-wayland-gtk-playbin");
|
||||
if (!playbin)
|
||||
return false;
|
||||
|
||||
GError *error = nullptr;
|
||||
GstElement *video_sink = gst_parse_bin_from_description(
|
||||
"videoconvert ! videoscale ! video/x-raw,format=BGRx ! gtksink name=orca_wayland_gtksink sync=false",
|
||||
TRUE,
|
||||
&error);
|
||||
if (!video_sink) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "wxMediaCtrl2: failed to create gtksink video bin"
|
||||
<< (error ? std::string(": ") + error->message : std::string());
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
gst_object_unref(playbin);
|
||||
return false;
|
||||
}
|
||||
|
||||
GstElement *gtk_sink = gst_bin_get_by_name(GST_BIN(video_sink), "orca_wayland_gtksink");
|
||||
if (!gtk_sink) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "wxMediaCtrl2: failed to find gtksink in video bin";
|
||||
gst_object_unref(video_sink);
|
||||
gst_object_unref(playbin);
|
||||
return false;
|
||||
}
|
||||
|
||||
GtkWidget *gtk_widget = nullptr;
|
||||
g_object_get(G_OBJECT(gtk_sink), "widget", >k_widget, nullptr);
|
||||
if (!gtk_widget) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "wxMediaCtrl2: gtksink did not expose a GtkWidget";
|
||||
gst_object_unref(gtk_sink);
|
||||
gst_object_unref(video_sink);
|
||||
gst_object_unref(playbin);
|
||||
return false;
|
||||
}
|
||||
|
||||
gtk_widget_show(gtk_widget);
|
||||
m_gtk_video_window = new wxNativeWindow(this, wxID_ANY, gtk_widget);
|
||||
m_gtk_video_window->Show();
|
||||
g_object_unref(gtk_widget);
|
||||
|
||||
g_object_set(G_OBJECT(playbin),
|
||||
"video-sink", video_sink,
|
||||
"audio-sink", nullptr,
|
||||
nullptr);
|
||||
gst_object_unref(video_sink);
|
||||
|
||||
m_gtk_playbin = playbin;
|
||||
m_gtk_sink = gtk_sink;
|
||||
|
||||
GstBus *bus = gst_element_get_bus(playbin);
|
||||
m_gtk_bus_watch_id = gst_bus_add_watch(bus, [](GstBus *, GstMessage *message, gpointer data) -> gboolean {
|
||||
auto *self = static_cast<wxMediaCtrl2 *>(data);
|
||||
if (!self || !self->m_gtk_playbin)
|
||||
return G_SOURCE_REMOVE;
|
||||
|
||||
switch (GST_MESSAGE_TYPE(message)) {
|
||||
case GST_MESSAGE_ERROR:
|
||||
{
|
||||
GError *error = nullptr;
|
||||
gchar *debug = nullptr;
|
||||
gst_message_parse_error(message, &error, &debug);
|
||||
BOOST_LOG_TRIVIAL(warning) << "wxMediaCtrl2: gtksink pipeline error"
|
||||
<< (error ? std::string(": ") + error->message : std::string())
|
||||
<< (debug ? std::string(" debug: ") + debug : std::string());
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
if (debug)
|
||||
g_free(debug);
|
||||
|
||||
self->m_error = gst_bambu_last_error ? gst_bambu_last_error : 2;
|
||||
self->m_loaded = false;
|
||||
self->m_gtk_state = wxMEDIASTATE_STOPPED;
|
||||
self->PostGtkSinkStateEvent(self->GetId());
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_EOS:
|
||||
self->m_loaded = false;
|
||||
self->m_gtk_state = wxMEDIASTATE_STOPPED;
|
||||
self->PostGtkSinkStateEvent(self->GetId());
|
||||
break;
|
||||
case GST_MESSAGE_STATE_CHANGED:
|
||||
if (GST_MESSAGE_SRC(message) == GST_OBJECT(self->m_gtk_playbin)) {
|
||||
GstState old_state;
|
||||
GstState new_state;
|
||||
GstState pending_state;
|
||||
gst_message_parse_state_changed(message, &old_state, &new_state, &pending_state);
|
||||
|
||||
if (new_state == GST_STATE_PLAYING) {
|
||||
self->m_loaded = true;
|
||||
self->m_gtk_state = wxMEDIASTATE_PLAYING;
|
||||
self->PostGtkSinkStateEvent();
|
||||
} else if (new_state == GST_STATE_PAUSED && old_state < GST_STATE_PAUSED) {
|
||||
// Treat only upward READY/NULL -> PAUSED as load completion.
|
||||
// PLAYING -> PAUSED is a normal teardown step before NULL.
|
||||
self->m_loaded = true;
|
||||
self->m_gtk_state = wxMEDIASTATE_PAUSED;
|
||||
self->PostGtkSinkStateEvent();
|
||||
} else if (new_state <= GST_STATE_READY && old_state >= GST_STATE_PAUSED) {
|
||||
self->m_loaded = false;
|
||||
self->m_gtk_state = wxMEDIASTATE_STOPPED;
|
||||
self->PostGtkSinkStateEvent();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return G_SOURCE_CONTINUE;
|
||||
}, this);
|
||||
gst_object_unref(bus);
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "wxMediaCtrl2: using GTK native Wayland video sink";
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::DestroyGtkSinkPlayer()
|
||||
{
|
||||
if (m_gtk_bus_watch_id) {
|
||||
g_source_remove(m_gtk_bus_watch_id);
|
||||
m_gtk_bus_watch_id = 0;
|
||||
}
|
||||
|
||||
if (m_gtk_playbin) {
|
||||
gst_element_set_state(m_gtk_playbin, GST_STATE_NULL);
|
||||
}
|
||||
|
||||
if (m_gtk_video_window) {
|
||||
m_gtk_video_window->Destroy();
|
||||
m_gtk_video_window = nullptr;
|
||||
}
|
||||
|
||||
if (m_gtk_playbin) {
|
||||
gst_object_unref(m_gtk_playbin);
|
||||
m_gtk_playbin = nullptr;
|
||||
}
|
||||
|
||||
if (m_gtk_sink) {
|
||||
gst_object_unref(m_gtk_sink);
|
||||
m_gtk_sink = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::PostGtkSinkStateEvent(int id)
|
||||
{
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(id);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
#endif // defined(__LINUX__) && defined(__WXGTK__)
|
||||
|
||||
#define CLSID_BAMBU_SOURCE L"{233E64FB-2041-4A6C-AFAB-FF9BCF83E7AA}"
|
||||
|
||||
void wxMediaCtrl2::Load(wxURI url)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
InvalidateBestSize();
|
||||
if (m_imp == nullptr) {
|
||||
static bool notified = false;
|
||||
if (!notified) CallAfter([] {
|
||||
auto res = wxMessageBox(_L("Windows Media Player is required for this task! Do you want to enable 'Windows Media Player' for your operation system?"), _L("Error"), wxOK | wxCANCEL);
|
||||
if (res == wxOK) {
|
||||
wxString url = IsWindows10OrGreater()
|
||||
? "ms-settings:optionalfeatures?activationSource=SMC-Article-14209"
|
||||
: "https://support.microsoft.com/en-au/windows/get-windows-media-player-81718e0d-cfce-25b1-aee3-94596b658287";
|
||||
wxExecute("cmd /c start " + url, wxEXEC_HIDE_CONSOLE);
|
||||
}
|
||||
});
|
||||
m_error = 100;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
return;
|
||||
}
|
||||
{
|
||||
wxRegKey key11(wxRegKey::HKCU, L"SOFTWARE\\Classes\\CLSID\\" CLSID_BAMBU_SOURCE L"\\InProcServer32");
|
||||
wxRegKey key12(wxRegKey::HKCR, L"CLSID\\" CLSID_BAMBU_SOURCE L"\\InProcServer32");
|
||||
wxString path = key11.Exists() ? key11.QueryDefaultValue()
|
||||
: key12.Exists() ? key12.QueryDefaultValue() : wxString{};
|
||||
wxRegKey key2(wxRegKey::HKCR, "bambu");
|
||||
wxString clsid;
|
||||
if (key2.Exists())
|
||||
key2.QueryRawValue("Source Filter", clsid);
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": clsid %1% path %2%") % clsid % path;
|
||||
|
||||
std::string data_dir_str = Slic3r::data_dir();
|
||||
boost::filesystem::path data_dir_path(data_dir_str);
|
||||
auto dll_path = data_dir_path / "plugins" / "BambuSource.dll";
|
||||
if (path.empty() || !wxFile::Exists(path) || clsid != CLSID_BAMBU_SOURCE) {
|
||||
if (boost::filesystem::exists(dll_path)) {
|
||||
CallAfter(
|
||||
[dll_path] {
|
||||
int res = wxMessageBox(_L("BambuSource has not correctly been registered for media playing! Press Yes to re-register it. You will be promoted twice"), _L("Error"), wxYES_NO);
|
||||
if (res == wxYES) {
|
||||
std::string regContent = R"(Windows Registry Editor Version 5.00
|
||||
[HKEY_CLASSES_ROOT\bambu]
|
||||
"Source Filter"="{233E64FB-2041-4A6C-AFAB-FF9BCF83E7AA}"
|
||||
)";
|
||||
|
||||
auto reg_path = (fs::temp_directory_path() / fs::unique_path()).replace_extension(".reg");
|
||||
std::ofstream temp_reg_file(reg_path.c_str());
|
||||
if (!temp_reg_file) {
|
||||
return false;
|
||||
}
|
||||
temp_reg_file << regContent;
|
||||
temp_reg_file.close();
|
||||
auto sei_params = L"/q /s " + reg_path.wstring();
|
||||
SHELLEXECUTEINFO sei{sizeof(sei), SEE_MASK_NOCLOSEPROCESS, NULL, L"open",
|
||||
L"regedit", sei_params.c_str(),SW_HIDE,SW_HIDE};
|
||||
::ShellExecuteEx(&sei);
|
||||
|
||||
wstring quoted_dll_path = L"\"" + dll_path.wstring() + L"\"";
|
||||
SHELLEXECUTEINFO info{sizeof(info), 0, NULL, L"runas", L"regsvr32", quoted_dll_path.c_str(), SW_HIDE };
|
||||
::ShellExecuteEx(&info);
|
||||
fs::remove(reg_path);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
CallAfter([] {
|
||||
wxMessageBox(_L("Missing BambuSource component registered for media playing! Please re-install OrcaSlicer or seek community help."), _L("Error"), wxOK);
|
||||
});
|
||||
}
|
||||
m_error = clsid != CLSID_BAMBU_SOURCE ? 101 : path.empty() ? 102 : 103;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
return;
|
||||
}
|
||||
if (path != dll_path) {
|
||||
static bool notified = false;
|
||||
if (!notified) CallAfter([dll_path] {
|
||||
int res = wxMessageBox(_L("Using a BambuSource from a different install, video play may not work correctly! Press Yes to fix it."), _L("Warning"), wxYES_NO | wxICON_WARNING);
|
||||
if (res == wxYES) {
|
||||
auto path = dll_path.wstring();
|
||||
if (path.find(L' ') != std::wstring::npos)
|
||||
path = L"\"" + path + L"\"";
|
||||
SHELLEXECUTEINFO info{sizeof(info), 0, NULL, L"open", L"regsvr32", path.c_str(), SW_HIDE};
|
||||
::ShellExecuteEx(&info);
|
||||
}
|
||||
});
|
||||
notified = true;
|
||||
}
|
||||
wxRegKey keyWmp(wxRegKey::HKCU, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\.");
|
||||
keyWmp.Create();
|
||||
long permissions = 0;
|
||||
if (keyWmp.HasValue("Permissions"))
|
||||
keyWmp.QueryValue("Permissions", &permissions);
|
||||
if ((permissions & 32) == 0) {
|
||||
permissions |= 32;
|
||||
keyWmp.SetValue("Permissions", permissions);
|
||||
}
|
||||
}
|
||||
url = wxURI(url.BuildURI().append("&hwnd=").append(boost::lexical_cast<std::string>(GetHandle())).append("&tid=").append(
|
||||
boost::lexical_cast<std::string>(GetCurrentThreadId())));
|
||||
#endif
|
||||
#ifdef __WXGTK3__
|
||||
GstElementFactory *factory;
|
||||
int hasplugins = 1;
|
||||
|
||||
factory = gst_element_factory_find("h264parse");
|
||||
if (!factory) {
|
||||
hasplugins = 0;
|
||||
} else {
|
||||
gst_object_unref(factory);
|
||||
}
|
||||
|
||||
factory = gst_element_factory_find("openh264dec");
|
||||
if (!factory) {
|
||||
factory = gst_element_factory_find("avdec_h264");
|
||||
}
|
||||
if (!factory) {
|
||||
factory = gst_element_factory_find("vaapih264dec");
|
||||
}
|
||||
if (!factory) {
|
||||
factory = gst_element_factory_find("vah264dec");
|
||||
}
|
||||
if (!factory) {
|
||||
factory = gst_element_factory_find("nvh264dec");
|
||||
}
|
||||
if (!factory) {
|
||||
factory = gst_element_factory_find("v4l2h264dec");
|
||||
}
|
||||
if (!factory) {
|
||||
hasplugins = 0;
|
||||
} else {
|
||||
gst_object_unref(factory);
|
||||
}
|
||||
|
||||
if (!hasplugins) {
|
||||
CallAfter([] {
|
||||
wxMessageBox(_L("Your system is missing H.264 codecs for GStreamer, which are required to play video. (Try installing the gstreamer1.0-plugins-bad or gstreamer1.0-libav packages, then restart Orca Slicer?)"), _L("Error"), wxOK);
|
||||
});
|
||||
m_error = 101;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
return;
|
||||
}
|
||||
wxLog::EnableLogging(false);
|
||||
#endif
|
||||
m_error = 0;
|
||||
m_loaded = false;
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
if (m_use_gtk_sink && m_gtk_playbin) {
|
||||
const std::string uri = std::string(url.BuildURI().ToUTF8().data());
|
||||
gst_element_set_state(m_gtk_playbin, GST_STATE_NULL);
|
||||
g_object_set(G_OBJECT(m_gtk_playbin), "uri", uri.c_str(), nullptr);
|
||||
m_gtk_state = wxMEDIASTATE_STOPPED;
|
||||
GstStateChangeReturn state = gst_element_set_state(m_gtk_playbin, GST_STATE_PAUSED);
|
||||
if (state == GST_STATE_CHANGE_FAILURE) {
|
||||
m_error = gst_bambu_last_error ? gst_bambu_last_error : 2;
|
||||
PostGtkSinkStateEvent(GetId());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!m_imp) {
|
||||
m_error = m_native_wayland && !m_gtk_sink_error.empty() ? 104 : 100;
|
||||
m_loaded = false;
|
||||
if (m_native_wayland && !m_gtk_sink_error.empty() && !m_gtk_sink_error_notified) {
|
||||
m_gtk_sink_error_notified = true;
|
||||
const wxString message = m_gtk_sink_error;
|
||||
CallAfter([message] {
|
||||
wxMessageBox(message, _L("Error"), wxOK);
|
||||
});
|
||||
}
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
wxMediaCtrl::Load(url);
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Play()
|
||||
{
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
if (m_use_gtk_sink && m_gtk_playbin) {
|
||||
GstStateChangeReturn state = gst_element_set_state(m_gtk_playbin, GST_STATE_PLAYING);
|
||||
if (state == GST_STATE_CHANGE_FAILURE) {
|
||||
m_error = gst_bambu_last_error ? gst_bambu_last_error : 2;
|
||||
m_gtk_state = wxMEDIASTATE_STOPPED;
|
||||
PostGtkSinkStateEvent(GetId());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!m_imp) {
|
||||
m_error = m_native_wayland && !m_gtk_sink_error.empty() ? 104 : 100;
|
||||
if (m_native_wayland && !m_gtk_sink_error.empty() && !m_gtk_sink_error_notified) {
|
||||
m_gtk_sink_error_notified = true;
|
||||
const wxString message = m_gtk_sink_error;
|
||||
CallAfter([message] {
|
||||
wxMessageBox(message, _L("Error"), wxOK);
|
||||
});
|
||||
}
|
||||
PostGtkSinkStateEvent(GetId());
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
wxMediaCtrl::Play();
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Stop()
|
||||
{
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
if (m_use_gtk_sink && m_gtk_playbin) {
|
||||
gst_element_set_state(m_gtk_playbin, GST_STATE_NULL);
|
||||
m_gtk_state = wxMEDIASTATE_STOPPED;
|
||||
m_loaded = false;
|
||||
PostGtkSinkStateEvent(0);
|
||||
return;
|
||||
}
|
||||
if (!m_imp)
|
||||
return;
|
||||
#endif
|
||||
wxMediaCtrl::Stop();
|
||||
}
|
||||
|
||||
wxMediaState wxMediaCtrl2::GetState()
|
||||
{
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
if (m_use_gtk_sink && m_gtk_playbin)
|
||||
return m_gtk_state;
|
||||
if (!m_imp)
|
||||
return wxMEDIASTATE_STOPPED;
|
||||
#endif
|
||||
return wxMediaCtrl::GetState();
|
||||
}
|
||||
|
||||
int wxMediaCtrl2::GetLastError() const
|
||||
{
|
||||
#ifdef __LINUX__
|
||||
#ifdef __WXGTK__
|
||||
if (m_use_gtk_sink && m_error)
|
||||
return m_error;
|
||||
#endif
|
||||
if (m_error)
|
||||
return m_error;
|
||||
return gst_bambu_last_error;
|
||||
#else
|
||||
return m_error;
|
||||
#endif
|
||||
}
|
||||
|
||||
wxSize wxMediaCtrl2::GetVideoSize() const
|
||||
{
|
||||
#ifdef __LINUX__
|
||||
// Gstreamer doesn't give us a VideoSize until we're playing, which
|
||||
// confuses the MediaPlayCtrl into claiming that it is stuck
|
||||
// "Loading...". Fake it out for now.
|
||||
return m_loaded ? wxSize(1280, 720) : wxSize{};
|
||||
#else
|
||||
wxSize size = m_imp ? m_imp->GetVideoSize() : wxSize(0, 0);
|
||||
if (size.GetWidth() > 0)
|
||||
const_cast<wxSize&>(m_video_size) = size;
|
||||
return size;
|
||||
#endif
|
||||
}
|
||||
|
||||
wxSize wxMediaCtrl2::DoGetBestSize() const
|
||||
{
|
||||
return {-1, -1};
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
WXLRESULT wxMediaCtrl2::MSWWindowProc(WXUINT nMsg,
|
||||
WXWPARAM wParam,
|
||||
WXLPARAM lParam)
|
||||
{
|
||||
// The stream source sends WM_USER+1000 with a synchronous SendMessage from its own threads,
|
||||
// so this runs re-entrantly on the UI thread at whatever message-retrieval point the player
|
||||
// happens to be in - often nested inside an Orca log statement. Never BOOST_LOG_TRIVIAL here:
|
||||
// boost::log is not re-entrant on one thread, and doing so corrupted its per-thread record
|
||||
// state, crashing later in unrelated places (the player, the log filter, a plug-in heap free).
|
||||
// Post the string out (as the stat branch does) and log it on a clean stack instead.
|
||||
if (nMsg == WM_USER + 1000) {
|
||||
wxString msg((wchar_t const *) lParam);
|
||||
if (wParam == 1) {
|
||||
if (msg.EndsWith("]")) {
|
||||
int n = msg.find_last_of('[');
|
||||
if (n != wxString::npos) {
|
||||
long val = 0;
|
||||
if (msg.SubString(n + 1, msg.Length() - 2).ToLong(&val))
|
||||
m_error = (int) val;
|
||||
}
|
||||
} else if (msg.Contains("stat_log")) {
|
||||
wxCommandEvent evt(EVT_MEDIA_CTRL_STAT);
|
||||
evt.SetEventObject(this);
|
||||
evt.SetString(msg.Mid(msg.Find(' ') + 1));
|
||||
wxPostEvent(this, evt);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return wxMediaCtrl::MSWWindowProc(nMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,117 +0,0 @@
|
||||
//
|
||||
// wxMediaCtrl2.h
|
||||
// libslic3r_gui
|
||||
//
|
||||
// Created by cmguo on 2021/12/7.
|
||||
//
|
||||
|
||||
#ifndef wxMediaCtrl2_h
|
||||
#define wxMediaCtrl2_h
|
||||
|
||||
#include "wx/uri.h"
|
||||
#include "wx/mediactrl.h"
|
||||
|
||||
wxDECLARE_EVENT(EVT_MEDIA_CTRL_STAT, wxCommandEvent);
|
||||
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
typedef struct _GstElement GstElement;
|
||||
#endif
|
||||
|
||||
#ifdef __WXMAC__
|
||||
|
||||
class wxMediaCtrl2 : public wxWindow
|
||||
{
|
||||
public:
|
||||
wxMediaCtrl2(wxWindow * parent);
|
||||
|
||||
~wxMediaCtrl2();
|
||||
|
||||
void Load(wxURI url);
|
||||
|
||||
void Play();
|
||||
|
||||
void Stop();
|
||||
|
||||
void SetIdleImage(wxString const & image);
|
||||
|
||||
wxMediaState GetState() const;
|
||||
|
||||
wxSize GetVideoSize() const;
|
||||
|
||||
int GetLastError() const { return m_error; }
|
||||
|
||||
static inline const wxMediaState MEDIASTATE_BUFFERING = static_cast<wxMediaState>(6);
|
||||
|
||||
protected:
|
||||
void DoSetSize(int x, int y, int width, int height, int sizeFlags) override;
|
||||
|
||||
static void bambu_log(void const * ctx, int level, char const * msg);
|
||||
|
||||
void NotifyStopped();
|
||||
|
||||
private:
|
||||
void create_player();
|
||||
void * m_player = nullptr;
|
||||
wxMediaState m_state = wxMEDIASTATE_STOPPED;
|
||||
int m_error = 0;
|
||||
wxSize m_video_size{16, 9};
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class wxMediaCtrl2 : public wxMediaCtrl
|
||||
{
|
||||
public:
|
||||
wxMediaCtrl2(wxWindow *parent);
|
||||
~wxMediaCtrl2();
|
||||
|
||||
void Load(wxURI url);
|
||||
|
||||
void Play();
|
||||
|
||||
void Stop();
|
||||
|
||||
void SetIdleImage(wxString const & image);
|
||||
|
||||
wxMediaState GetState();
|
||||
|
||||
int GetLastError() const;
|
||||
|
||||
wxSize GetVideoSize() const;
|
||||
|
||||
protected:
|
||||
wxSize DoGetBestSize() const override;
|
||||
|
||||
void DoSetSize(int x, int y, int width, int height, int sizeFlags) override;
|
||||
|
||||
#ifdef __WIN32__
|
||||
WXLRESULT MSWWindowProc(WXUINT nMsg,
|
||||
WXWPARAM wParam,
|
||||
WXLPARAM lParam) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if defined(__LINUX__) && defined(__WXGTK__)
|
||||
bool CreateGtkSinkPlayer();
|
||||
void DestroyGtkSinkPlayer();
|
||||
void PostGtkSinkStateEvent(int id = 0);
|
||||
|
||||
bool m_native_wayland = false;
|
||||
bool m_use_gtk_sink = false;
|
||||
wxString m_gtk_sink_error;
|
||||
bool m_gtk_sink_error_notified = false;
|
||||
GstElement *m_gtk_playbin = nullptr;
|
||||
GstElement *m_gtk_sink = nullptr;
|
||||
unsigned int m_gtk_bus_watch_id = 0;
|
||||
wxWindow *m_gtk_video_window = nullptr;
|
||||
wxMediaState m_gtk_state = wxMEDIASTATE_STOPPED;
|
||||
#endif
|
||||
wxString m_idle_image;
|
||||
int m_error = 0;
|
||||
bool m_loaded = false;
|
||||
wxSize m_video_size{16, 9};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* wxMediaCtrl2_h */
|
||||
@@ -1,170 +0,0 @@
|
||||
//
|
||||
// wxMediaCtrl2.m
|
||||
// OrcaSlicer
|
||||
//
|
||||
// Created by cmguo on 2021/12/7.
|
||||
//
|
||||
|
||||
#import "wxMediaCtrl2.h"
|
||||
#import "wx/mediactrl.h"
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "BambuPlayer/BambuPlayer.h"
|
||||
#import "../Utils/NetworkAgent.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
wxDEFINE_EVENT(EVT_MEDIA_CTRL_STAT, wxCommandEvent);
|
||||
|
||||
#define BAMBU_DYNAMIC
|
||||
|
||||
void wxMediaCtrl2::bambu_log(void const * ctx, int level, char const * msg)
|
||||
{
|
||||
if (level == 1) {
|
||||
wxString msg2(msg);
|
||||
if (msg2.EndsWith("]")) {
|
||||
int n = msg2.find_last_of('[');
|
||||
if (n != wxString::npos) {
|
||||
long val = 0;
|
||||
wxMediaCtrl2 * ctrl = (wxMediaCtrl2 *) ctx;
|
||||
if (msg2.SubString(n + 1, msg2.Length() - 2).ToLong(&val))
|
||||
ctrl->m_error = (int) val;
|
||||
}
|
||||
} else if (strstr(msg, "stat_log")) {
|
||||
wxMediaCtrl2 * ctrl = (wxMediaCtrl2 *) ctx;
|
||||
wxCommandEvent evt(EVT_MEDIA_CTRL_STAT);
|
||||
evt.SetEventObject(ctrl);
|
||||
evt.SetString(strchr(msg, ' ') + 1);
|
||||
wxPostEvent(ctrl, evt);
|
||||
}
|
||||
} else if (level < 0) {
|
||||
wxMediaCtrl2 * ctrl = (wxMediaCtrl2 *) ctx;
|
||||
ctrl->NotifyStopped();
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << msg;
|
||||
}
|
||||
|
||||
wxMediaCtrl2::wxMediaCtrl2(wxWindow * parent)
|
||||
: wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
|
||||
{
|
||||
NSView * imageView = (NSView *) GetHandle();
|
||||
imageView.layer = [[CALayer alloc] init];
|
||||
CGColorRef color = CGColorCreateGenericRGB(0, 0, 0, 1.0f);
|
||||
imageView.layer.backgroundColor = color;
|
||||
CGColorRelease(color);
|
||||
imageView.wantsLayer = YES;
|
||||
create_player();
|
||||
}
|
||||
|
||||
wxMediaCtrl2::~wxMediaCtrl2()
|
||||
{
|
||||
BambuPlayer * player = (BambuPlayer *) m_player;
|
||||
[player dealloc];
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::create_player()
|
||||
{
|
||||
auto module = Slic3r::NetworkAgent::get_bambu_source_entry();
|
||||
if (!module) {
|
||||
//not ready yet
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Network plugin not ready currently!";
|
||||
return;
|
||||
}
|
||||
Class cls = (__bridge Class) dlsym(module, "OBJC_CLASS_$_BambuPlayer");
|
||||
if (cls == nullptr) {
|
||||
m_error = -2;
|
||||
return;
|
||||
}
|
||||
NSView * imageView = (NSView *) GetHandle();
|
||||
BambuPlayer * player = [cls alloc];
|
||||
[player initWithImageView: imageView];
|
||||
[player setLogger: bambu_log withContext: this];
|
||||
m_player = player;
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Load(wxURI url)
|
||||
{
|
||||
if (!m_player) {
|
||||
create_player();
|
||||
if (!m_player) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": create_player failed currently!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BambuPlayer * player = (BambuPlayer *) m_player;
|
||||
if (player) {
|
||||
[player close];
|
||||
m_error = 0;
|
||||
m_error = [player open: url.BuildURI().ToUTF8()];
|
||||
}
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Play()
|
||||
{
|
||||
if (!m_player) {
|
||||
create_player();
|
||||
if (!m_player) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": create_player failed currently!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
[player2 play];
|
||||
if (m_state != wxMEDIASTATE_PLAYING) {
|
||||
m_state = wxMEDIASTATE_PLAYING;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Stop()
|
||||
{
|
||||
if (!m_player) {
|
||||
create_player();
|
||||
if (!m_player) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": create_player failed currently!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
[player2 close];
|
||||
NotifyStopped();
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::NotifyStopped()
|
||||
{
|
||||
if (m_state != wxMEDIASTATE_STOPPED) {
|
||||
m_state = wxMEDIASTATE_STOPPED;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
}
|
||||
|
||||
wxMediaState wxMediaCtrl2::GetState() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
wxSize wxMediaCtrl2::GetVideoSize() const
|
||||
{
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
if (player2) {
|
||||
NSSize size = [player2 videoSize];
|
||||
if (size.width > 0)
|
||||
const_cast<wxSize&>(m_video_size) = {(int) size.width, (int) size.height};
|
||||
return {(int) size.width, (int) size.height};
|
||||
} else {
|
||||
return {0, 0};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
#include "wxMediaCtrl3.h"
|
||||
#include "AVVideoDecoder.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <wx/dcclient.h>
|
||||
#ifdef __WIN32__
|
||||
#include <versionhelpers.h>
|
||||
#include <wx/msw/registry.h>
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
|
||||
wxDEFINE_EVENT(EVT_MEDIA_CTRL_STAT, wxCommandEvent);
|
||||
|
||||
BEGIN_EVENT_TABLE(wxMediaCtrl3, wxWindow)
|
||||
|
||||
// catch paint events
|
||||
EVT_PAINT(wxMediaCtrl3::paintEvent)
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
struct StaticBambuLib : BambuLib
|
||||
{
|
||||
static StaticBambuLib &get(BambuLib *);
|
||||
};
|
||||
|
||||
wxMediaCtrl3::wxMediaCtrl3(wxWindow *parent)
|
||||
: wxWindow(parent, wxID_ANY)
|
||||
, BambuLib(StaticBambuLib::get(this))
|
||||
, m_thread([this] { PlayThread(); })
|
||||
{
|
||||
SetBackgroundColour("#000001ff");
|
||||
}
|
||||
|
||||
wxMediaCtrl3::~wxMediaCtrl3()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
m_url.reset(new wxURI);
|
||||
m_frame = wxImage(m_idle_image);
|
||||
m_cond.notify_all();
|
||||
}
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::Load(wxURI url)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
m_video_size = wxDefaultSize;
|
||||
m_error = 0;
|
||||
m_url.reset(new wxURI(url));
|
||||
m_cond.notify_all();
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::Play()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
if (m_state != wxMEDIASTATE_PLAYING) {
|
||||
m_state = wxMEDIASTATE_PLAYING;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::Stop()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
m_url.reset();
|
||||
m_frame = wxImage(m_idle_image);
|
||||
NotifyStopped();
|
||||
m_cond.notify_all();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::SetIdleImage(wxString const &image)
|
||||
{
|
||||
if (m_idle_image == image)
|
||||
return;
|
||||
m_idle_image = image;
|
||||
if (m_url == nullptr) {
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
m_frame = wxImage(m_idle_image);
|
||||
assert(m_frame.IsOk());
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
wxMediaState wxMediaCtrl3::GetState()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
return m_state;
|
||||
}
|
||||
|
||||
int wxMediaCtrl3::GetLastError()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
return m_error;
|
||||
}
|
||||
|
||||
wxSize wxMediaCtrl3::GetVideoSize()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
return m_video_size;
|
||||
}
|
||||
|
||||
wxSize wxMediaCtrl3::DoGetBestSize() const
|
||||
{
|
||||
return {-1, -1};
|
||||
}
|
||||
|
||||
static void adjust_frame_size(wxSize & frame, wxSize const & video, wxSize const & window)
|
||||
{
|
||||
if (video.x * window.y < video.y * window.x)
|
||||
frame = { video.x * window.y / video.y, window.y };
|
||||
else
|
||||
frame = { window.x, video.y * window.x / video.x };
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::paintEvent(wxPaintEvent &evt)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
auto size = GetSize();
|
||||
if (size.x <= 0 || size.y <= 0)
|
||||
return;
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
if (!m_frame.IsOk())
|
||||
return;
|
||||
auto size2 = m_frame.GetSize();
|
||||
if (size2.x != m_frame_size.x && size2.y == m_frame_size.y)
|
||||
size2.x = m_frame_size.x;
|
||||
auto size3 = (size - size2) / 2;
|
||||
if (size2.x != size.x && size2.y != size.y) {
|
||||
double scale = 1.;
|
||||
if (size.x * size2.y > size.y * size2.x) {
|
||||
size3 = {size.x * size2.y / size.y, size2.y};
|
||||
scale = double(size.y) / size2.y;
|
||||
} else {
|
||||
size3 = {size2.x, size.y * size2.x / size.x};
|
||||
scale = double(size.x) / size2.x;
|
||||
}
|
||||
dc.SetUserScale(scale, scale);
|
||||
size3 = (size3 - size2) / 2;
|
||||
}
|
||||
dc.DrawBitmap(m_frame, size3.x, size3.y);
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||
{
|
||||
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
|
||||
if (sizeFlags == wxSIZE_USE_EXISTING) return;
|
||||
wxMediaCtrl_OnSize(this, m_video_size, width, height);
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
adjust_frame_size(m_frame_size, m_video_size, GetSize());
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::bambu_log(void *ctx, int level, tchar const *msg2)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
wxString msg(msg2);
|
||||
#else
|
||||
wxString msg = wxString::FromUTF8(msg2);
|
||||
#endif
|
||||
if (level == 1) {
|
||||
if (msg.EndsWith("]")) {
|
||||
int n = msg.find_last_of('[');
|
||||
if (n != wxString::npos) {
|
||||
long val = 0;
|
||||
wxMediaCtrl3 *ctrl = (wxMediaCtrl3 *) ctx;
|
||||
if (msg.SubString(n + 1, msg.Length() - 2).ToLong(&val)) {
|
||||
std::unique_lock<std::mutex> lk(ctrl->m_mutex);
|
||||
ctrl->m_error = (int) val;
|
||||
}
|
||||
}
|
||||
} else if (msg.Contains("stat_log")) {
|
||||
wxCommandEvent evt(EVT_MEDIA_CTRL_STAT);
|
||||
wxMediaCtrl3 *ctrl = (wxMediaCtrl3 *) ctx;
|
||||
evt.SetEventObject(ctrl);
|
||||
evt.SetString(msg.Mid(msg.Find(' ') + 1));
|
||||
wxPostEvent(ctrl, evt);
|
||||
}
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << msg.ToUTF8().data();
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::PlayThread()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
std::shared_ptr<wxURI> url;
|
||||
std::unique_lock<std::mutex> lk(m_mutex);
|
||||
while (true) {
|
||||
m_cond.wait(lk, [this, &url] { return m_url != url; });
|
||||
url = m_url;
|
||||
if (url == nullptr)
|
||||
continue;
|
||||
if (!url->HasScheme())
|
||||
break;
|
||||
lk.unlock();
|
||||
Bambu_Tunnel tunnel = nullptr;
|
||||
int error = Bambu_Create(&tunnel, m_url->BuildURI().ToUTF8());
|
||||
if (error == 0) {
|
||||
Bambu_SetLogger(tunnel, &wxMediaCtrl3::bambu_log, this);
|
||||
error = Bambu_Open(tunnel);
|
||||
if (error == 0)
|
||||
error = Bambu_would_block;
|
||||
}
|
||||
lk.lock();
|
||||
while (error == int(Bambu_would_block)) {
|
||||
m_cond.wait_for(lk, 100ms);
|
||||
if (m_url != url) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
lk.unlock();
|
||||
error = Bambu_StartStream(tunnel, true);
|
||||
lk.lock();
|
||||
}
|
||||
Bambu_StreamInfo info;
|
||||
if (error == 0)
|
||||
error = Bambu_GetStreamInfo(tunnel, 0, &info);
|
||||
AVVideoDecoder decoder;
|
||||
int minFrameDuration = 0;
|
||||
if (error == 0) {
|
||||
decoder.open(info);
|
||||
m_video_size = { info.format.video.width, info.format.video.height };
|
||||
adjust_frame_size(m_frame_size, m_video_size, GetSize());
|
||||
minFrameDuration = 800 / info.format.video.frame_rate; // 80%
|
||||
NotifyStopped();
|
||||
}
|
||||
Bambu_Sample sample;
|
||||
while (error == 0) {
|
||||
lk.unlock();
|
||||
error = Bambu_ReadSample(tunnel, &sample);
|
||||
lk.lock();
|
||||
while (error == int(Bambu_would_block)) {
|
||||
m_cond.wait_for(lk, 100ms);
|
||||
if (m_url != url) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
lk.unlock();
|
||||
error = Bambu_ReadSample(tunnel, &sample);
|
||||
lk.lock();
|
||||
}
|
||||
if (error == 0) {
|
||||
auto frame_size = m_frame_size;
|
||||
lk.unlock();
|
||||
decoder.decode(sample);
|
||||
#ifdef _WIN32
|
||||
wxBitmap bm;
|
||||
decoder.toWxBitmap(bm, frame_size);
|
||||
#else
|
||||
wxImage bm;
|
||||
decoder.toWxImage(bm, frame_size);
|
||||
#endif
|
||||
lk.lock();
|
||||
if (m_url != url) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
if (bm.IsOk()) {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
if (m_last_PTS && (sample.decode_time - m_last_PTS) < 30000000ULL) { // 3s
|
||||
auto next_PTS_expected = m_last_PTS_expected + std::chrono::milliseconds((sample.decode_time - m_last_PTS) / 10000ULL);
|
||||
// The frame is late, catch up a little
|
||||
auto next_PTS_practical = m_last_PTS_practical + std::chrono::milliseconds(minFrameDuration);
|
||||
auto next_PTS = std::max(next_PTS_expected, next_PTS_practical);
|
||||
if(now < next_PTS)
|
||||
std::this_thread::sleep_until(next_PTS);
|
||||
else
|
||||
next_PTS = now;
|
||||
//auto text = wxString::Format(L"wxMediaCtrl3 pts diff %ld\n", std::chrono::duration_cast<std::chrono::milliseconds>(next_PTS - next_PTS_expected).count());
|
||||
//OutputDebugString(text);
|
||||
m_last_PTS = sample.decode_time;
|
||||
m_last_PTS_expected = next_PTS_expected;
|
||||
m_last_PTS_practical = next_PTS;
|
||||
} else {
|
||||
// Resync
|
||||
m_last_PTS = sample.decode_time;
|
||||
m_last_PTS_expected = now;
|
||||
m_last_PTS_practical = now;
|
||||
}
|
||||
m_frame = bm;
|
||||
}
|
||||
CallAfter([this] { Refresh(); });
|
||||
}
|
||||
}
|
||||
if (tunnel) {
|
||||
lk.unlock();
|
||||
Bambu_Close(tunnel);
|
||||
Bambu_Destroy(tunnel);
|
||||
tunnel = nullptr;
|
||||
lk.lock();
|
||||
}
|
||||
if (m_url == url)
|
||||
m_error = error;
|
||||
m_frame_size = wxDefaultSize;
|
||||
m_video_size = wxDefaultSize;
|
||||
NotifyStopped();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void wxMediaCtrl3::NotifyStopped()
|
||||
{
|
||||
m_state = wxMEDIASTATE_STOPPED;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// wxMediaCtrl3.h
|
||||
// libslic3r_gui
|
||||
//
|
||||
// Created by cmguo on 2024/6/22.
|
||||
//
|
||||
|
||||
#ifndef wxMediaCtrl3_h
|
||||
#define wxMediaCtrl3_h
|
||||
|
||||
#include "wx/uri.h"
|
||||
#include "wx/mediactrl.h"
|
||||
|
||||
wxDECLARE_EVENT(EVT_MEDIA_CTRL_STAT, wxCommandEvent);
|
||||
|
||||
void wxMediaCtrl_OnSize(wxWindow * ctrl, wxSize const & videoSize, int width, int height);
|
||||
|
||||
#define BAMBU_DYNAMIC
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
#ifndef _WIN32
|
||||
#include <wx/image.h>
|
||||
#endif
|
||||
#include "Printer/BambuTunnel.h"
|
||||
|
||||
class AVVideoDecoder;
|
||||
|
||||
class wxMediaCtrl3 : public wxWindow, BambuLib
|
||||
{
|
||||
public:
|
||||
wxMediaCtrl3(wxWindow *parent);
|
||||
|
||||
~wxMediaCtrl3();
|
||||
|
||||
void Load(wxURI url);
|
||||
|
||||
void Play();
|
||||
|
||||
void Stop();
|
||||
|
||||
void SetIdleImage(wxString const & image);
|
||||
|
||||
wxMediaState GetState();
|
||||
|
||||
int GetLastError();
|
||||
|
||||
wxSize GetVideoSize();
|
||||
|
||||
protected:
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
void paintEvent(wxPaintEvent &evt);
|
||||
|
||||
wxSize DoGetBestSize() const override;
|
||||
|
||||
void DoSetSize(int x, int y, int width, int height, int sizeFlags) override;
|
||||
|
||||
static void bambu_log(void *ctx, int level, tchar const *msg);
|
||||
|
||||
void PlayThread();
|
||||
|
||||
void NotifyStopped();
|
||||
|
||||
private:
|
||||
wxString m_idle_image;
|
||||
wxMediaState m_state = wxMEDIASTATE_STOPPED;
|
||||
int m_error = 0;
|
||||
wxSize m_video_size = wxDefaultSize;
|
||||
wxSize m_frame_size = wxDefaultSize;
|
||||
#ifdef _WIN32
|
||||
wxBitmap m_frame;
|
||||
#else
|
||||
wxImage m_frame;
|
||||
#endif
|
||||
|
||||
std::shared_ptr<wxURI> m_url;
|
||||
std::uint64_t m_last_PTS{0};
|
||||
std::chrono::system_clock::time_point m_last_PTS_expected;
|
||||
std::chrono::system_clock::time_point m_last_PTS_practical;
|
||||
std::mutex m_mutex;
|
||||
std::condition_variable m_cond;
|
||||
std::thread m_thread;
|
||||
};
|
||||
|
||||
#endif /* wxMediaCtrl3_h */
|
||||
@@ -1198,7 +1198,7 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version
|
||||
version.config_version = cache_ver;
|
||||
version.comment = description;
|
||||
// Orca: update vendor.json
|
||||
updates.updates.emplace_back(std::move(file_path), std::move(path_in_vendor.string()), std::move(version), vendor_name, changelog, "", force_update, false);
|
||||
updates.updates.emplace_back(std::move(file_path), path_in_vendor.string(), std::move(version), vendor_name, changelog, "", force_update, false);
|
||||
//Orca: update vendor folder
|
||||
updates.updates.emplace_back(cache_profile_path / vendor_name, vendor_path / vendor_name, Version(), vendor_name, "", "", force_update, true);
|
||||
} else {
|
||||
|
||||
@@ -631,7 +631,7 @@ void parse_metadata_rfc822(const std::string& content,
|
||||
bool is_ignored_plugin_directory(const boost::filesystem::path& path)
|
||||
{
|
||||
const std::string name = path.filename().string();
|
||||
return name.empty() || name[0] == '.' || name.rfind("__", 0) == 0 || name == PLUGIN_SUBSCRIBED_DIR;
|
||||
return name.empty() || name[0] == '.' || name.rfind("__", 0) == 0 || name == PLUGIN_SUBSCRIBED_DIR || name == PLUGIN_DATA_DIR;
|
||||
}
|
||||
|
||||
bool is_safe_relative_path(const boost::filesystem::path& path)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <vector>
|
||||
|
||||
#define PLUGIN_SUBSCRIBED_DIR "_subscribed"
|
||||
#define PLUGIN_DATA_DIR "plugin_data"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
||||
@@ -522,6 +522,38 @@ bool PluginManager::try_get_plugin_descriptor_for_capability(const std::string&
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string PluginManager::get_storage_dir(const std::string& plugin_key) const
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
PluginDescriptor descriptor;
|
||||
if (!try_get_plugin_descriptor(plugin_key, descriptor))
|
||||
throw std::runtime_error("The current plugin is not registered");
|
||||
|
||||
const fs::path base_storage_dir = fs::path(get_orca_plugins_dir()) / PLUGIN_DATA_DIR;
|
||||
|
||||
if (!descriptor.is_cloud_plugin()) {
|
||||
const fs::path local_storage_dir = base_storage_dir / plugin_key;
|
||||
fs::create_directories(local_storage_dir);
|
||||
return local_storage_dir.string();
|
||||
}
|
||||
|
||||
auto agent = m_cloud_service.get_cloud_agent();
|
||||
if (!agent)
|
||||
throw std::runtime_error("Cloud plugin storage is unavailable before networking is initialized");
|
||||
|
||||
const std::string user_id = agent->get_user_id();
|
||||
if (user_id.empty())
|
||||
throw std::runtime_error("Cloud plugin storage is unavailable without a logged-in user");
|
||||
|
||||
if (!is_valid_plugin_id(plugin_key))
|
||||
throw std::runtime_error("The current cloud plugin key is not a valid folder name");
|
||||
|
||||
const fs::path cloud_storage_dir = base_storage_dir / PLUGIN_SUBSCRIBED_DIR / user_id / plugin_key;
|
||||
fs::create_directories(cloud_storage_dir);
|
||||
return cloud_storage_dir.string();
|
||||
}
|
||||
|
||||
// ── Capability instances ────────────────────────────────────────────────────────────────────
|
||||
|
||||
std::vector<std::shared_ptr<PluginCapabilityInterface>> PluginManager::get_plugin_capabilities(const std::string& plugin_key,
|
||||
|
||||
@@ -143,6 +143,10 @@ public:
|
||||
bool try_get_plugin_descriptor_for_capability(const std::string& capability_name,
|
||||
PluginCapabilityType type,
|
||||
PluginDescriptor& out) const;
|
||||
// Per-plugin storage directory under orca_plugins/plugin_data, created if missing. Throws
|
||||
// std::runtime_error if the plugin is unregistered, the key is invalid, or (cloud plugins)
|
||||
// no user is logged in yet.
|
||||
std::string get_storage_dir(const std::string& plugin_key) const;
|
||||
|
||||
std::vector<std::shared_ptr<PluginCapabilityInterface>> get_plugin_capabilities(
|
||||
const std::string& plugin_key = "", // "" => all plugins
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
#include "PluginHost.hpp"
|
||||
#include "PluginHostBindings.hpp"
|
||||
#include "PluginHostUi.hpp"
|
||||
#include <slic3r/plugin/PluginAuditManager.hpp>
|
||||
#include <slic3r/plugin/PluginManager.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace host_bindings {
|
||||
void register_plugin(pybind11::module_& host)
|
||||
{
|
||||
auto plugin_host = host.def_submodule("plugin", "Plugin host API");
|
||||
|
||||
plugin_host.def(
|
||||
"storage",
|
||||
[]() -> std::string {
|
||||
const std::string plugin_key = PluginAuditManager::instance().current_plugin();
|
||||
if (plugin_key.empty())
|
||||
throw std::runtime_error("plugin.storage() must be called from a plugin callback");
|
||||
|
||||
return PluginManager::instance().get_storage_dir(plugin_key);
|
||||
},
|
||||
"Return the installed folder of the current plugin.");
|
||||
}
|
||||
} // namespace host_bindings
|
||||
|
||||
void PluginHost::RegisterBindings(pybind11::module_& module)
|
||||
{
|
||||
auto host = module.def_submodule("host", "Host application API");
|
||||
@@ -15,6 +37,7 @@ void PluginHost::RegisterBindings(pybind11::module_& module)
|
||||
host_bindings::register_presets(host);
|
||||
host_bindings::register_model(host);
|
||||
host_bindings::register_app(host);
|
||||
host_bindings::register_plugin(host);
|
||||
|
||||
// UI: native dialogs and interactive HTML windows for plugins.
|
||||
PluginHostUi::RegisterBindings(host);
|
||||
|
||||
@@ -12,5 +12,5 @@ void register_presets(pybind11::module_& host); // PluginHostPresets.cpp
|
||||
void register_model(pybind11::module_& host); // PluginHostModel.cpp
|
||||
void register_app(pybind11::module_& host); // PluginHostApp.cpp
|
||||
void register_slicing(pybind11::module_& host); // PluginHostSlicing.cpp
|
||||
|
||||
void register_plugin(pybind11::module_& host); // PluginHost.cpp
|
||||
} // namespace Slic3r::host_bindings
|
||||
|
||||
Reference in New Issue
Block a user