Merge upstream main: Design tab CAD, OTA OPC CI, JAYO filament profiles

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clifford Garwood
2026-09-18 08:00:12 -04:00
co-authored by Claude Opus 5
413 changed files with 74409 additions and 86 deletions
+235 -5
View File
@@ -1,5 +1,8 @@
#include "libslic3r/libslic3r.h"
#include "GLCanvas3D.hpp"
#ifdef SLIC3R_CAD
#include "slic3r/GUI/CAD/DesignSketchTool.hpp" // Design tab: interactive 2D sketch tool
#endif
#include <igl/unproject.h>
@@ -1827,6 +1830,16 @@ void GLCanvas3D::enable_separator_toolbar(bool enable)
m_separator_toolbar.set_enabled(enable);
}
void GLCanvas3D::enable_collapse_toolbar(bool enable)
{
m_collapse_toolbar_enabled = enable;
}
void GLCanvas3D::enable_plate_chrome(bool enable)
{
m_plate_chrome_enabled = enable;
}
bool GLCanvas3D::has_mouse_capture() const {
return m_canvas != nullptr && m_canvas->HasCapture();
}
@@ -2048,14 +2061,24 @@ void GLCanvas3D::render(bool only_init)
no_partplate = true;
else if (gizmo_type == GLGizmosManager::BrimEars && !camera.is_looking_downward())
show_grid = false;
if (m_axes_at_bed_center)
// Design tab: the plate grid is generated from the plate's front-left corner, so it
// floats mid-cell under the modeling-origin triad. Suppress it here; a CAD grid centred
// on the origin is rendered in its place (see _render_cad_grid).
show_grid = false;
/* view3D render*/
int hover_id = (m_hover_plate_idxs.size() > 0)?m_hover_plate_idxs.front():-1;
if (m_canvas_type == ECanvasType::CanvasView3D) {
if (!no_partplate)
// m_show_bed gates the plate list too: hiding the bed but leaving its grid and outline
// floating would read as a rendering fault rather than a deliberate view option.
if (!no_partplate && m_show_bed)
_render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), !camera.is_looking_downward(), m_show_world_axes);
if (!no_partplate) //BBS: add outline logic
if (!no_partplate && m_show_bed) //BBS: add outline logic
_render_platelist(camera.get_view_matrix(), camera.get_projection_matrix(), !camera.is_looking_downward(), only_current, only_body, hover_id, true, show_grid);
if (m_axes_at_bed_center && m_show_bed && !no_partplate)
// Design tab: replace the plate's corner-origin grid with the origin-centred CAD grid.
_render_cad_grid(camera.get_view_matrix(), camera.get_projection_matrix());
//BBS: add outline logic
// Depth pass for object-on-object and self shadows; consumed by the gouraud shader below.
@@ -2121,6 +2144,13 @@ void GLCanvas3D::render(bool only_init)
if (_is_fxaa_enabled())
_render_fxaa_pass(static_cast<unsigned int>(cnv_size.get_width()), static_cast<unsigned int>(cnv_size.get_height()));
// Design tab: interactive 2D sketch overlay, drawn over the scene but
// beneath the UI overlays (toolbars, labels).
#ifdef SLIC3R_CAD
if (m_design_sketch_tool != nullptr && m_design_sketch_tool->has_display())
m_design_sketch_tool->render(*this);
#endif
// draw overlays
_render_overlays();
@@ -3211,7 +3241,11 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt)
// BBS
//m_dirty |= wxGetApp().plater()->get_view_toolbar().update_items_state();
m_dirty |= wxGetApp().plater()->get_collapse_toolbar().update_items_state();
bool mouse3d_controller_applied = wxGetApp().plater()->get_mouse3d_controller().apply(wxGetApp().plater()->get_camera());
// apply() DRAINS the 3D-mouse queue, so only the canvas actually on screen may call it: a
// hidden canvas renders nothing, so the motion it swallowed moves the shared camera without
// ever being drawn and the next visible frame jumps several states at once.
bool mouse3d_controller_applied = _is_shown_on_screen()
&& wxGetApp().plater()->get_mouse3d_controller().apply(wxGetApp().plater()->get_camera());
m_dirty |= mouse3d_controller_applied;
m_dirty |= wxGetApp().plater()->get_notification_manager()->update_notifications(*this);
auto gizmo = wxGetApp().plater()->get_view3D_canvas3D()->get_gizmos_manager().get_current();
@@ -3279,6 +3313,64 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
return;
}
// Design tab: Delete/Backspace removes the selected sketch entities while a
// sketch tool is active and the canvas has focus (dialog text fields are separate
// wx controls, so this never eats their editing keys).
#ifdef SLIC3R_CAD
if (m_design_sketch_tool != nullptr && m_design_sketch_tool->is_active()
&& (keyCode == WXK_DELETE || keyCode == WXK_BACK)
&& !m_design_sketch_tool->selection().empty()) {
m_design_sketch_tool->delete_selected();
m_dirty = true;
render();
return;
}
#endif
// Esc exits the active sketch tool (Onshape-like, layered: abort in-progress entity ->
// drop to Select -> exit the session back to Feature mode).
#ifdef SLIC3R_CAD
if (m_design_sketch_tool != nullptr && m_design_sketch_tool->is_active()
&& keyCode == WXK_ESCAPE) {
m_design_sketch_tool->request_exit();
m_dirty = true;
render();
return;
}
#endif
// Design tab: Ctrl+Z / Ctrl+Shift+Z (and Ctrl+Y) undo/redo the Design feature
// history. Scoped by m_design_sketch_tool — only the Design canvas owns one — so the
// main 3D editor's undo/redo (the CanvasView3D-gated cases further below) is untouched.
// Handled here, before the generic Ctrl block, so it takes precedence and early-returns.
#ifdef SLIC3R_CAD
if (m_design_sketch_tool != nullptr && (evt.GetModifiers() & ctrlMask) != 0) {
const bool is_z = (keyCode == 'z' || keyCode == 'Z' || keyCode == WXK_CONTROL_Z);
const bool is_y = (keyCode == 'y' || keyCode == 'Y' || keyCode == WXK_CONTROL_Y);
if (is_z || is_y) {
const bool redo = is_y || ((evt.GetModifiers() & shiftMask) != 0);
m_design_sketch_tool->request_undo_redo(redo);
m_dirty = true;
render();
return;
}
}
#endif
// Design tab: F = Place on Face (Prepare's lay-flat), when the Design viewport is up
// and a body face is selected. The tool forwards to DesignPanel::place_on_face; it returns
// false (no face picked) so F falls through to the default handler below.
#ifdef SLIC3R_CAD
if (m_design_sketch_tool != nullptr && m_design_sketch_tool->has_display()
&& (keyCode == 'f' || keyCode == 'F') && (evt.GetModifiers() & ctrlMask) == 0) {
if (m_design_sketch_tool->request_place_on_face()) {
m_dirty = true;
render();
return;
}
}
#endif
bool is_in_painting_mode = false;
GLGizmoPainterBase *current_gizmo_painter = dynamic_cast<GLGizmoPainterBase *>(get_gizmos_manager().get_current());
if (current_gizmo_painter != nullptr) {
@@ -3656,6 +3748,20 @@ public:
void GLCanvas3D::on_key(wxKeyEvent& evt)
{
// Design tab: Delete/Backspace removes selected sketch entities. GTK delivers
// these as KEY_DOWN rather than CHAR, so handle it here too.
#ifdef SLIC3R_CAD
if (evt.GetEventType() == wxEVT_KEY_DOWN
&& m_design_sketch_tool != nullptr && m_design_sketch_tool->is_active()
&& (evt.GetKeyCode() == WXK_DELETE || evt.GetKeyCode() == WXK_BACK)
&& !m_design_sketch_tool->selection().empty()) {
m_design_sketch_tool->delete_selected();
m_dirty = true;
render();
return;
}
#endif
static GLCanvas3D const * thiz = nullptr;
static TranslationProcessor translationProcessor(nullptr, nullptr);
if (thiz != this) {
@@ -4220,6 +4326,23 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
return;
}
// Design tab: the interactive sketch tool owns the mouse whenever it has
// something on screen — an active session OR committed sketch overlays that the user
// can click to select. It runs after ImGui (so dialogs still work) but before
// camera/toolbar/gizmo handling; on_mouse returns false for events it doesn't consume
// (drag/orbit/wheel) so the camera keeps working over the display-only plate.
#ifdef SLIC3R_CAD
if (m_design_sketch_tool != nullptr && m_design_sketch_tool->has_display()) {
if (evt.LeftDown() && m_canvas != nullptr)
m_canvas->SetFocus(); // grab keyboard focus so Delete/keys reach this canvas
if (m_design_sketch_tool->on_mouse(evt, *this)) {
m_dirty = true;
render(); // force an immediate redraw so the sketch overlay updates live
return;
}
}
#endif
#ifdef __WXMSW__
bool on_enter_workaround = false;
if (! evt.Entering() && ! evt.Leaving() && m_mouse.position.x() == -1.0) {
@@ -4941,6 +5064,8 @@ bool GLCanvas3D::is_camera_rotate(const wxMouseEvent& evt, const std::map<MouseB
{
if (m_is_touchpad_navigation) {
return evt.Moving() && evt.AltDown() && !evt.ShiftDown();
} else if (m_cad_navigation) {
return evt.Dragging() && evt.MiddleIsDown(); // left-drag is the selection rubber band
} else {
return evt.Dragging() && clicked_button_matches_action(evt, MouseAction::Rotation, mappings);
}
@@ -4950,6 +5075,8 @@ bool GLCanvas3D::is_camera_pan(const wxMouseEvent& evt, const std::map<MouseButt
{
if (m_is_touchpad_navigation) {
return evt.Moving() && evt.ShiftDown() && !evt.AltDown();
} else if (m_cad_navigation) {
return evt.Dragging() && evt.RightIsDown(); // middle now orbits, so pan is right only
} else {
return evt.Dragging() && clicked_button_matches_action(evt, MouseAction::Pan, mappings);
;
@@ -8227,13 +8354,113 @@ void GLCanvas3D::_render_bed(const Transform3d& view_matrix, const Transform3d&
*/
//bool show_texture = true;
//BBS set axes mode
m_bed.set_axes_mode(m_main_toolbar.is_enabled());
if (m_axes_at_bed_center) {
// Design tab: triad at the bed centre = modeling origin (set every frame because
// set_shape/set_axes_mode otherwise reset it to the bed corner).
const Vec2d bc = m_bed.build_volume().bed_center();
m_bed.set_axes_origin(Vec3d(bc.x(), bc.y(), 0.0));
} else {
m_bed.set_axes_mode(m_main_toolbar.is_enabled());
}
m_bed.render(*this, view_matrix, projection_matrix, bottom, scale_factor, show_axes);
}
void GLCanvas3D::_render_platelist(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool only_current, bool only_body, int hover_id, bool render_cali, bool show_grid)
{
wxGetApp().plater()->get_partplate_list().render(view_matrix, projection_matrix, bottom, only_current, only_body, hover_id, render_cali, show_grid);
wxGetApp().plater()->get_partplate_list().render(view_matrix, projection_matrix, bottom, only_current, only_body, hover_id, render_cali, show_grid, !m_plate_chrome_enabled);
}
// Design tab: CAD grid on the bed plane, drawn in place of the plate's corner-origin grid.
// Generated from the bed centre (= modeling origin) so a grid line passes exactly through the
// triad in both axes. Minor lines every 10 mm, major every 50 mm; the two GLModels are built
// once and rebuilt only when the bed shape changes, not per frame.
void GLCanvas3D::_render_cad_grid(const Transform3d& view_matrix, const Transform3d& projection_matrix)
{
const BuildVolume& build_volume = m_bed.build_volume();
if (!build_volume.valid())
return;
const Vec2d center = build_volume.bed_center();
const BoundingBoxf bb = build_volume.bounding_volume2d();
if (!m_cad_grid_valid || m_cad_grid_center != center || m_cad_grid_bb != bb) {
m_cad_grid_center = center;
m_cad_grid_bb = bb;
m_cad_grid_valid = true;
// Same z as PartPlate::GROUND_Z_GRIDLINE (-0.26f): just below the bed fill (GROUND_Z =
// -0.03f, which is drawn with the depth mask disabled) and above the physical bed model
// (offset z = -0.41), so the grid never z-fights the bed quad. Chosen by construction,
// not by magic number: it is the exact z the plate grid already uses on the shared bed.
const float z = -0.26f;
auto build_grid = [&z, &center, &bb](double step, GLModel& model) {
std::vector<std::pair<Vec2d, Vec2d>> segs;
// Constant-x (vertical on screen) lines, both directions from the centre so the
// centre column itself is always present. Clipped to the bed bounding box so nothing
// spills past the bed quad.
for (double x = center.x(); x >= bb.min.x(); x -= step)
segs.emplace_back(Vec2d(x, bb.min.y()), Vec2d(x, bb.max.y()));
for (double x = center.x() + step; x <= bb.max.x(); x += step)
segs.emplace_back(Vec2d(x, bb.min.y()), Vec2d(x, bb.max.y()));
// Constant-y (horizontal on screen) lines, same centre-first convention.
for (double y = center.y(); y >= bb.min.y(); y -= step)
segs.emplace_back(Vec2d(bb.min.x(), y), Vec2d(bb.max.x(), y));
for (double y = center.y() + step; y <= bb.max.y(); y += step)
segs.emplace_back(Vec2d(bb.min.x(), y), Vec2d(bb.max.x(), y));
GLModel::Geometry data;
data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
data.reserve_vertices(2 * segs.size());
data.reserve_indices(2 * segs.size());
for (const auto& s : segs) {
data.add_vertex(Vec3f(float(s.first.x()), float(s.first.y()), z));
data.add_vertex(Vec3f(float(s.second.x()), float(s.second.y()), z));
const unsigned int vc = static_cast<unsigned int>(data.vertices_count());
data.add_line(vc - 2, vc - 1);
}
model.init_from(std::move(data));
};
m_cad_grid_minor.reset();
m_cad_grid_major.reset();
build_grid(10.0, m_cad_grid_minor);
build_grid(50.0, m_cad_grid_major);
}
if (!m_cad_grid_minor.is_initialized() || !m_cad_grid_major.is_initialized())
return;
GLShaderProgram* shader = wxGetApp().get_shader("flat");
if (shader == nullptr)
return;
shader->start_using();
glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
shader->set_uniform("view_model_matrix", view_matrix);
shader->set_uniform("projection_matrix", projection_matrix);
// White every 5 cm, grey every 1 cm — the SAME in both themes, deliberately. There is no
// "white bed" to vanish against: the plate is dark grey either way, DEFAULT_MODEL_COLOR
// {0.326,0.337,0.337} on light and DEFAULT_MODEL_COLOR_DARK {0.255,0.255,0.283} on dark
// (3DBed.cpp:185-186), a difference of 0.07. A per-theme palette here would be a branch
// that buys nothing and one more thing to keep in step.
//
// For contrast with what this replaces: the plate's own grid uses LINE_TOP_DARK_COLOR, a
// 0.43 grey, for BOTH its thin and its bold family — which is most of why the stock grid
// reads as a flat mesh with no scale to it.
const ColorRGBA minor_color(0.40f, 0.40f, 0.42f, 1.0f);
const ColorRGBA major_color(0.90f, 0.90f, 0.90f, 1.0f);
glsafe(::glLineWidth(1.0f));
m_cad_grid_minor.set_color(minor_color);
m_cad_grid_minor.render();
glsafe(::glLineWidth(2.0f));
m_cad_grid_major.set_color(major_color);
m_cad_grid_major.render();
glsafe(::glDisable(GL_BLEND));
}
void GLCanvas3D::_render_shadows(const Transform3d& view_matrix, const Transform3d& projection_matrix)
@@ -9909,6 +10136,9 @@ void GLCanvas3D::_render_separator_toolbar_left() const
void GLCanvas3D::_render_collapse_toolbar() const
{
if (!m_collapse_toolbar_enabled)
return;
auto& plater = *wxGetApp().plater();
const auto sidebar_docking_dir = plater.get_sidebar_docking_state();
if (sidebar_docking_dir == Sidebar::None) {