mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-07 06:59:07 +08:00
Merge branch 'master' into tm_colldetection_upgr
This commit is contained in:
commit
3dba1e1fb4
@ -603,12 +603,14 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
|
||||
const double fullheight = wingheight + thickness;
|
||||
const double slope = cfg.wall_slope;
|
||||
const double wingdist = wingheight / std::tan(slope);
|
||||
const double bottom_offs = (thickness + wingheight) / std::tan(slope);
|
||||
|
||||
// scaled values
|
||||
const coord_t s_thickness = mm(thickness);
|
||||
const coord_t s_eradius = mm(cfg.edge_radius_mm);
|
||||
const coord_t s_safety_dist = 2*s_eradius + coord_t(0.8*s_thickness);
|
||||
const coord_t s_wingdist = mm(wingdist);
|
||||
const coord_t s_bottom_offs = mm(bottom_offs);
|
||||
|
||||
auto& thrcl = cfg.throw_on_cancel;
|
||||
|
||||
@ -620,7 +622,7 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
|
||||
// Get rid of any holes in the concave hull output.
|
||||
concaveh.holes.clear();
|
||||
|
||||
// Here lies the trick that does the smooting only with clipper offset
|
||||
// Here lies the trick that does the smoothing only with clipper offset
|
||||
// calls. The offset is configured to round edges. Inner edges will
|
||||
// be rounded because we offset twice: ones to get the outer (top) plate
|
||||
// and again to get the inner (bottom) plate
|
||||
@ -628,10 +630,9 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
|
||||
outer_base.holes.clear();
|
||||
offset(outer_base, s_safety_dist + s_wingdist + s_thickness);
|
||||
|
||||
|
||||
ExPolygon bottom_poly = outer_base;
|
||||
bottom_poly.holes.clear();
|
||||
if(s_wingdist > 0) offset(bottom_poly, -s_wingdist);
|
||||
offset(bottom_poly, -s_bottom_offs);
|
||||
|
||||
// Punching a hole in the top plate for the cavity
|
||||
ExPolygon top_poly;
|
||||
@ -692,7 +693,7 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
|
||||
// Now that we have the rounded edge connecting the top plate with
|
||||
// the outer side walls, we can generate and merge the sidewall geometry
|
||||
pool.merge(walls(ob.contour, bottom_poly.contour, wh, -fullheight,
|
||||
wingdist, thrcl));
|
||||
bottom_offs, thrcl));
|
||||
|
||||
if(wingheight > 0) {
|
||||
// Generate the smoothed edge geometry
|
||||
|
@ -76,6 +76,8 @@ set(SLIC3R_GUI_SOURCES
|
||||
GUI/2DBed.hpp
|
||||
GUI/3DBed.cpp
|
||||
GUI/3DBed.hpp
|
||||
GUI/Camera.cpp
|
||||
GUI/Camera.hpp
|
||||
GUI/wxExtensions.cpp
|
||||
GUI/wxExtensions.hpp
|
||||
GUI/WipeTowerDialog.cpp
|
||||
|
@ -2002,9 +2002,9 @@ std::string _3DScene::get_gl_info(bool format_as_html, bool extensions)
|
||||
return s_canvas_mgr.get_gl_info(format_as_html, extensions);
|
||||
}
|
||||
|
||||
bool _3DScene::add_canvas(wxGLCanvas* canvas)
|
||||
bool _3DScene::add_canvas(wxGLCanvas* canvas, GUI::Bed3D& bed, GUI::Camera& camera, GUI::GLToolbar& view_toolbar)
|
||||
{
|
||||
return s_canvas_mgr.add(canvas);
|
||||
return s_canvas_mgr.add(canvas, bed, camera, view_toolbar);
|
||||
}
|
||||
|
||||
bool _3DScene::remove_canvas(wxGLCanvas* canvas)
|
||||
|
@ -25,6 +25,11 @@ inline void glAssertRecentCall() { }
|
||||
#endif
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
class Bed3D;
|
||||
struct Camera;
|
||||
class GLToolbar;
|
||||
} // namespace GUI
|
||||
|
||||
class Print;
|
||||
class PrintObject;
|
||||
@ -563,7 +568,7 @@ class _3DScene
|
||||
public:
|
||||
static std::string get_gl_info(bool format_as_html, bool extensions);
|
||||
|
||||
static bool add_canvas(wxGLCanvas* canvas);
|
||||
static bool add_canvas(wxGLCanvas* canvas, GUI::Bed3D& bed, GUI::Camera& camera, GUI::GLToolbar& view_toolbar);
|
||||
static bool remove_canvas(wxGLCanvas* canvas);
|
||||
static void remove_all_canvases();
|
||||
|
||||
|
62
src/slic3r/GUI/Camera.cpp
Normal file
62
src/slic3r/GUI/Camera.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include "libslic3r/libslic3r.h"
|
||||
|
||||
#include "Camera.hpp"
|
||||
|
||||
static const float GIMBALL_LOCK_THETA_MAX = 180.0f;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
Camera::Camera()
|
||||
: type(Ortho)
|
||||
, zoom(1.0f)
|
||||
, phi(45.0f)
|
||||
// , distance(0.0f)
|
||||
, requires_zoom_to_bed(false)
|
||||
, m_theta(45.0f)
|
||||
, m_target(Vec3d::Zero())
|
||||
{
|
||||
}
|
||||
|
||||
std::string Camera::get_type_as_string() const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case Unknown:
|
||||
return "unknown";
|
||||
// case Perspective:
|
||||
// return "perspective";
|
||||
case Ortho:
|
||||
return "ortho";
|
||||
};
|
||||
}
|
||||
|
||||
void Camera::set_target(const Vec3d& target)
|
||||
{
|
||||
m_target = target;
|
||||
m_target(0) = clamp(m_scene_box.min(0), m_scene_box.max(0), m_target(0));
|
||||
m_target(1) = clamp(m_scene_box.min(1), m_scene_box.max(1), m_target(1));
|
||||
m_target(2) = clamp(m_scene_box.min(2), m_scene_box.max(2), m_target(2));
|
||||
}
|
||||
|
||||
void Camera::set_theta(float theta, bool apply_limit)
|
||||
{
|
||||
if (apply_limit)
|
||||
m_theta = clamp(0.0f, GIMBALL_LOCK_THETA_MAX, theta);
|
||||
else
|
||||
{
|
||||
m_theta = fmod(theta, 360.0f);
|
||||
if (m_theta < 0.0f)
|
||||
m_theta += 360.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::set_scene_box(const BoundingBoxf3& box)
|
||||
{
|
||||
m_scene_box = box;
|
||||
}
|
||||
|
||||
} // GUI
|
||||
} // Slic3r
|
||||
|
50
src/slic3r/GUI/Camera.hpp
Normal file
50
src/slic3r/GUI/Camera.hpp
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef slic3r_Camera_hpp_
|
||||
#define slic3r_Camera_hpp_
|
||||
|
||||
#include "libslic3r/BoundingBox.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
struct Camera
|
||||
{
|
||||
enum EType : unsigned char
|
||||
{
|
||||
Unknown,
|
||||
// Perspective,
|
||||
Ortho,
|
||||
Num_types
|
||||
};
|
||||
|
||||
EType type;
|
||||
float zoom;
|
||||
float phi;
|
||||
// float distance;
|
||||
bool requires_zoom_to_bed;
|
||||
|
||||
private:
|
||||
Vec3d m_target;
|
||||
float m_theta;
|
||||
|
||||
BoundingBoxf3 m_scene_box;
|
||||
|
||||
public:
|
||||
Camera();
|
||||
|
||||
std::string get_type_as_string() const;
|
||||
|
||||
const Vec3d& get_target() const { return m_target; }
|
||||
void set_target(const Vec3d& target);
|
||||
|
||||
float get_theta() const { return m_theta; }
|
||||
void set_theta(float theta, bool apply_limit);
|
||||
|
||||
const BoundingBoxf3& get_scene_box() const { return m_scene_box; }
|
||||
void set_scene_box(const BoundingBoxf3& box);
|
||||
};
|
||||
|
||||
} // GUI
|
||||
} // Slic3r
|
||||
|
||||
#endif // slic3r_Camera_hpp_
|
||||
|
@ -54,7 +54,6 @@
|
||||
#include <cmath>
|
||||
|
||||
static const float TRACKBALLSIZE = 0.8f;
|
||||
static const float GIMBALL_LOCK_THETA_MAX = 180.0f;
|
||||
static const float GROUND_Z = -0.02f;
|
||||
|
||||
// phi / theta angles to orient the camera.
|
||||
@ -183,61 +182,6 @@ void Rect::set_bottom(float bottom)
|
||||
m_bottom = bottom;
|
||||
}
|
||||
|
||||
GLCanvas3D::Camera::Camera()
|
||||
: type(Ortho)
|
||||
, zoom(1.0f)
|
||||
, phi(45.0f)
|
||||
// , distance(0.0f)
|
||||
, m_theta(45.0f)
|
||||
, m_target(Vec3d::Zero())
|
||||
{
|
||||
}
|
||||
|
||||
std::string GLCanvas3D::Camera::get_type_as_string() const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case Unknown:
|
||||
return "unknown";
|
||||
// case Perspective:
|
||||
// return "perspective";
|
||||
case Ortho:
|
||||
return "ortho";
|
||||
};
|
||||
}
|
||||
|
||||
void GLCanvas3D::Camera::set_theta(float theta, bool apply_limit)
|
||||
{
|
||||
if (apply_limit)
|
||||
m_theta = clamp(0.0f, GIMBALL_LOCK_THETA_MAX, theta);
|
||||
else
|
||||
{
|
||||
m_theta = fmod(theta, 360.0f);
|
||||
if (m_theta < 0.0f)
|
||||
m_theta += 360.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::Camera::set_target(const Vec3d& target, GLCanvas3D& canvas)
|
||||
{
|
||||
m_target = target;
|
||||
m_target(0) = clamp(m_scene_box.min(0), m_scene_box.max(0), m_target(0));
|
||||
m_target(1) = clamp(m_scene_box.min(1), m_scene_box.max(1), m_target(1));
|
||||
m_target(2) = clamp(m_scene_box.min(2), m_scene_box.max(2), m_target(2));
|
||||
if (!m_target.isApprox(target))
|
||||
canvas.viewport_changed();
|
||||
}
|
||||
|
||||
void GLCanvas3D::Camera::set_scene_box(const BoundingBoxf3& box, GLCanvas3D& canvas)
|
||||
{
|
||||
if (m_scene_box != box)
|
||||
{
|
||||
m_scene_box = box;
|
||||
canvas.viewport_changed();
|
||||
}
|
||||
}
|
||||
|
||||
#if !ENABLE_TEXTURES_FROM_SVG
|
||||
GLCanvas3D::Shader::Shader()
|
||||
: m_shader(nullptr)
|
||||
@ -1278,7 +1222,26 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, GLCanvas3D::Transforma
|
||||
// Only relative rotation values are allowed in the world coordinate system.
|
||||
assert(! transformation_type.world() || transformation_type.relative());
|
||||
|
||||
int rot_axis_max;
|
||||
int rot_axis_max = 0;
|
||||
if (rotation.isApprox(Vec3d::Zero()))
|
||||
{
|
||||
for (unsigned int i : m_list)
|
||||
{
|
||||
GLVolume &volume = *(*m_volumes)[i];
|
||||
if (m_mode == Instance)
|
||||
{
|
||||
volume.set_instance_rotation(m_cache.volumes_data[i].get_instance_rotation());
|
||||
volume.set_instance_offset(m_cache.volumes_data[i].get_instance_position());
|
||||
}
|
||||
else if (m_mode == Volume)
|
||||
{
|
||||
volume.set_volume_rotation(m_cache.volumes_data[i].get_volume_rotation());
|
||||
volume.set_volume_offset(m_cache.volumes_data[i].get_volume_position());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//FIXME this does not work for absolute rotations (transformation_type.absolute() is true)
|
||||
rotation.cwiseAbs().maxCoeff(&rot_axis_max);
|
||||
|
||||
@ -1301,8 +1264,8 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, GLCanvas3D::Transforma
|
||||
transformation_type.absolute() ? rotation : rotation + m_cache.volumes_data[i].get_instance_rotation();
|
||||
if (rot_axis_max == 2 && transformation_type.joint()) {
|
||||
// Only allow rotation of multiple instances as a single rigid body when rotating around the Z axis.
|
||||
double z_diff = rotation_diff_z(new_rotation, m_cache.volumes_data[i].get_instance_rotation());
|
||||
volume.set_instance_offset(m_cache.dragging_center + Eigen::AngleAxisd(z_diff, Vec3d::UnitZ()) * (m_cache.volumes_data[i].get_instance_position() - m_cache.dragging_center));
|
||||
Vec3d offset = Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, 0.0, new_rotation(2) - m_cache.volumes_data[i].get_instance_rotation()(2))) * (m_cache.volumes_data[i].get_instance_position() - m_cache.dragging_center);
|
||||
volume.set_instance_offset(m_cache.dragging_center + offset);
|
||||
}
|
||||
volume.set_instance_rotation(new_rotation);
|
||||
object_instance_first[volume.object_idx()] = i;
|
||||
@ -1344,6 +1307,7 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, GLCanvas3D::Transforma
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !DISABLE_INSTANCES_SYNCH
|
||||
if (m_mode == Instance)
|
||||
@ -3209,7 +3173,7 @@ void GLCanvas3D::Gizmos::do_render_overlay(const GLCanvas3D& canvas, const GLCan
|
||||
GLTexture::render_sub_texture(icons_texture_id, top_x, top_x + scaled_icons_size, top_y - scaled_icons_size, top_y, { { left, bottom }, { right, bottom }, { right, top }, { left, top } });
|
||||
#if ENABLE_IMGUI
|
||||
if (it->second->get_state() == GLGizmoBase::On) {
|
||||
float toolbar_top = (float)cnv_h - canvas.m_view_toolbar->get_height();
|
||||
float toolbar_top = (float)cnv_h - canvas.m_view_toolbar.get_height();
|
||||
#if ENABLE_SVG_ICONS
|
||||
it->second->render_input_window(2.0f * m_overlay_border + m_overlay_icons_size, 0.5f * cnv_h - top_y * zoom, toolbar_top, selection);
|
||||
#else
|
||||
@ -3713,7 +3677,6 @@ void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_INIT, SimpleEvent);
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent);
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent);
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent);
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent);
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent);
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
|
||||
@ -3730,20 +3693,21 @@ wxDEFINE_EVENT(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, SimpleEvent);
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_BED_SHAPE, SimpleEvent);
|
||||
wxDEFINE_EVENT(EVT_GLCANVAS_TAB, SimpleEvent);
|
||||
|
||||
GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas)
|
||||
GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar)
|
||||
: m_canvas(canvas)
|
||||
, m_context(nullptr)
|
||||
#if ENABLE_RETINA_GL
|
||||
, m_retina_helper(nullptr)
|
||||
#endif
|
||||
, m_in_render(false)
|
||||
, m_bed(nullptr)
|
||||
, m_bed(bed)
|
||||
, m_camera(camera)
|
||||
, m_view_toolbar(view_toolbar)
|
||||
#if ENABLE_SVG_ICONS
|
||||
, m_toolbar(GLToolbar::Normal, "Top")
|
||||
#else
|
||||
, m_toolbar(GLToolbar::Normal)
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
, m_view_toolbar(nullptr)
|
||||
, m_use_clipping_planes(false)
|
||||
, m_sidebar_field("")
|
||||
, m_config(nullptr)
|
||||
@ -3752,7 +3716,6 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas)
|
||||
, m_dirty(true)
|
||||
, m_initialized(false)
|
||||
, m_use_VBOs(false)
|
||||
, m_requires_zoom_to_bed(false)
|
||||
, m_apply_zoom_to_volumes_filter(false)
|
||||
, m_hover_volume_id(-1)
|
||||
, m_toolbar_action_running(false)
|
||||
@ -3792,11 +3755,6 @@ void GLCanvas3D::post_event(wxEvent &&event)
|
||||
wxPostEvent(m_canvas, event);
|
||||
}
|
||||
|
||||
void GLCanvas3D::viewport_changed()
|
||||
{
|
||||
post_event(SimpleEvent(EVT_GLCANVAS_VIEWPORT_CHANGED));
|
||||
}
|
||||
|
||||
bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl)
|
||||
{
|
||||
if (m_initialized)
|
||||
@ -3971,9 +3929,8 @@ void GLCanvas3D::set_model(Model* model)
|
||||
|
||||
void GLCanvas3D::bed_shape_changed()
|
||||
{
|
||||
m_camera.set_scene_box(scene_bounding_box(), *this);
|
||||
m_requires_zoom_to_bed = true;
|
||||
|
||||
m_camera.set_scene_box(scene_bounding_box());
|
||||
m_camera.requires_zoom_to_bed = true;
|
||||
m_dirty = true;
|
||||
}
|
||||
|
||||
@ -4001,8 +3958,7 @@ BoundingBoxf3 GLCanvas3D::volumes_bounding_box() const
|
||||
BoundingBoxf3 GLCanvas3D::scene_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 bb = volumes_bounding_box();
|
||||
if (m_bed != nullptr)
|
||||
bb.merge(m_bed->get_bounding_box());
|
||||
bb.merge(m_bed.get_bounding_box());
|
||||
|
||||
if (m_config != nullptr)
|
||||
{
|
||||
@ -4091,8 +4047,7 @@ bool GLCanvas3D::is_toolbar_item_pressed(const std::string& name) const
|
||||
|
||||
void GLCanvas3D::zoom_to_bed()
|
||||
{
|
||||
if (m_bed != nullptr)
|
||||
_zoom_to_bounding_box(m_bed->get_bounding_box());
|
||||
_zoom_to_bounding_box(m_bed.get_bounding_box());
|
||||
}
|
||||
|
||||
void GLCanvas3D::zoom_to_volumes()
|
||||
@ -4131,24 +4086,11 @@ void GLCanvas3D::select_view(const std::string& direction)
|
||||
{
|
||||
m_camera.phi = dir_vec[0];
|
||||
m_camera.set_theta(dir_vec[1], false);
|
||||
|
||||
viewport_changed();
|
||||
|
||||
if (m_canvas != nullptr)
|
||||
m_canvas->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::set_viewport_from_scene(const GLCanvas3D& other)
|
||||
{
|
||||
m_camera.phi = other.m_camera.phi;
|
||||
m_camera.set_theta(other.m_camera.get_theta(), false);
|
||||
m_camera.set_scene_box(other.m_camera.get_scene_box(), *this);
|
||||
m_camera.set_target(other.m_camera.get_target(), *this);
|
||||
m_camera.zoom = other.m_camera.zoom;
|
||||
m_dirty = true;
|
||||
}
|
||||
|
||||
void GLCanvas3D::update_volumes_colors_by_extruder()
|
||||
{
|
||||
if (m_config != nullptr)
|
||||
@ -4196,25 +4138,26 @@ void GLCanvas3D::render()
|
||||
if (m_canvas == nullptr)
|
||||
return;
|
||||
|
||||
#ifndef __WXMAC__
|
||||
// on Mac this check causes flickering when changing view
|
||||
if (!_is_shown_on_screen())
|
||||
return;
|
||||
#endif // __WXMAC__
|
||||
|
||||
// ensures this canvas is current and initialized
|
||||
if (!_set_current() || !_3DScene::init(m_canvas))
|
||||
return;
|
||||
|
||||
if ((m_bed != nullptr) && m_bed->get_shape().empty())
|
||||
{
|
||||
if (m_bed.get_shape().empty())
|
||||
// this happens at startup when no data is still saved under <>\AppData\Roaming\Slic3rPE
|
||||
post_event(SimpleEvent(EVT_GLCANVAS_UPDATE_BED_SHAPE));
|
||||
}
|
||||
|
||||
if (m_requires_zoom_to_bed)
|
||||
if (m_camera.requires_zoom_to_bed)
|
||||
{
|
||||
zoom_to_bed();
|
||||
const Size& cnv_size = get_canvas_size();
|
||||
_resize((unsigned int)cnv_size.get_width(), (unsigned int)cnv_size.get_height());
|
||||
m_requires_zoom_to_bed = false;
|
||||
m_camera.requires_zoom_to_bed = false;
|
||||
}
|
||||
|
||||
_camera_tranform();
|
||||
@ -4229,8 +4172,6 @@ void GLCanvas3D::render()
|
||||
// absolute value of the rotation
|
||||
theta = 360.f - theta;
|
||||
|
||||
bool is_custom_bed = (m_bed == nullptr) || m_bed->is_custom();
|
||||
|
||||
#if ENABLE_IMGUI
|
||||
wxGetApp().imgui()->new_frame();
|
||||
#endif // ENABLE_IMGUI
|
||||
@ -4243,7 +4184,7 @@ void GLCanvas3D::render()
|
||||
_render_background();
|
||||
|
||||
// textured bed needs to be rendered after objects if the texture is transparent
|
||||
bool early_bed_render = is_custom_bed || (theta <= 90.0f);
|
||||
bool early_bed_render = m_bed.is_custom() || (theta <= 90.0f);
|
||||
if (early_bed_render)
|
||||
_render_bed(theta);
|
||||
|
||||
@ -4661,8 +4602,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
||||
// restore to default value
|
||||
m_regenerate_volumes = true;
|
||||
|
||||
m_camera.set_scene_box(scene_bounding_box(), *this);
|
||||
m_camera.set_target(m_camera.get_target(), *this);
|
||||
m_camera.set_scene_box(scene_bounding_box());
|
||||
|
||||
if (m_selection.is_empty())
|
||||
{
|
||||
@ -5116,7 +5056,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||
m_layers_editing.select_object(*m_model, layer_editing_object_idx);
|
||||
bool gizmos_overlay_contains_mouse = m_gizmos.overlay_contains_mouse(*this, m_mouse.position);
|
||||
int toolbar_contains_mouse = m_toolbar.contains_mouse(m_mouse.position, *this);
|
||||
int view_toolbar_contains_mouse = (m_view_toolbar != nullptr) ? m_view_toolbar->contains_mouse(m_mouse.position, *this) : -1;
|
||||
int view_toolbar_contains_mouse = m_view_toolbar.contains_mouse(m_mouse.position, *this);
|
||||
|
||||
#if ENABLE_MOVE_MIN_THRESHOLD
|
||||
if (m_mouse.drag.move_requires_threshold && m_mouse.is_move_start_threshold_position_2D_defined() && m_mouse.is_move_threshold_met(pos))
|
||||
@ -5228,10 +5168,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||
// event was taken care of by the SlaSupports gizmo
|
||||
}
|
||||
else if (evt.LeftDown() && (view_toolbar_contains_mouse != -1))
|
||||
{
|
||||
if (m_view_toolbar != nullptr)
|
||||
m_view_toolbar->do_action((unsigned int)view_toolbar_contains_mouse, *this);
|
||||
}
|
||||
m_view_toolbar.do_action((unsigned int)view_toolbar_contains_mouse, *this);
|
||||
else if (evt.LeftDown() && (toolbar_contains_mouse != -1))
|
||||
{
|
||||
m_toolbar_action_running = true;
|
||||
@ -5462,9 +5399,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||
const Vec3d& orig = m_mouse.drag.start_position_3D;
|
||||
m_camera.phi += (((float)pos(0) - (float)orig(0)) * TRACKBALLSIZE);
|
||||
m_camera.set_theta(m_camera.get_theta() - ((float)pos(1) - (float)orig(1)) * TRACKBALLSIZE, wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA);
|
||||
|
||||
viewport_changed();
|
||||
|
||||
m_dirty = true;
|
||||
}
|
||||
m_mouse.drag.start_position_3D = Vec3d((double)pos(0), (double)pos(1), 0.0);
|
||||
@ -5478,10 +5412,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||
float z = 0.0f;
|
||||
const Vec3d& cur_pos = _mouse_to_3d(pos, &z);
|
||||
Vec3d orig = _mouse_to_3d(m_mouse.drag.start_position_2D, &z);
|
||||
m_camera.set_target(m_camera.get_target() + orig - cur_pos, *this);
|
||||
|
||||
viewport_changed();
|
||||
|
||||
m_camera.set_target(m_camera.get_target() + orig - cur_pos);
|
||||
m_dirty = true;
|
||||
}
|
||||
|
||||
@ -5558,8 +5489,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||
// Let the platter know that the dragging finished, so a delayed refresh
|
||||
// of the scene with the background processing data should be performed.
|
||||
post_event(SimpleEvent(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED));
|
||||
m_camera.set_scene_box(scene_bounding_box(), *this);
|
||||
set_camera_zoom(0.0f);
|
||||
m_camera.set_scene_box(scene_bounding_box());
|
||||
}
|
||||
|
||||
m_moving = false;
|
||||
@ -5589,9 +5519,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||
tooltip = m_toolbar.update_hover_state(m_mouse.position, *this);
|
||||
|
||||
// updates view toolbar overlay
|
||||
if (tooltip.empty() && (m_view_toolbar != nullptr))
|
||||
if (tooltip.empty())
|
||||
{
|
||||
tooltip = m_view_toolbar->update_hover_state(m_mouse.position, *this);
|
||||
tooltip = m_view_toolbar.update_hover_state(m_mouse.position, *this);
|
||||
if (!tooltip.empty())
|
||||
m_dirty = true;
|
||||
}
|
||||
@ -5905,7 +5835,6 @@ void GLCanvas3D::set_camera_zoom(float zoom)
|
||||
zoom = std::min(zoom, 100.0f);
|
||||
|
||||
m_camera.zoom = zoom;
|
||||
viewport_changed();
|
||||
_refresh_if_shown_on_screen();
|
||||
}
|
||||
|
||||
@ -5981,6 +5910,9 @@ bool GLCanvas3D::_init_toolbar()
|
||||
return true;
|
||||
}
|
||||
|
||||
#if ENABLE_SVG_ICONS
|
||||
m_toolbar.set_icons_size(40);
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
// m_toolbar.set_layout_type(GLToolbar::Layout::Vertical);
|
||||
m_toolbar.set_layout_type(GLToolbar::Layout::Horizontal);
|
||||
m_toolbar.set_layout_orientation(GLToolbar::Layout::Top);
|
||||
@ -6185,8 +6117,7 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h)
|
||||
BoundingBoxf3 GLCanvas3D::_max_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 bb = volumes_bounding_box();
|
||||
if (m_bed != nullptr)
|
||||
bb.merge(m_bed->get_bounding_box());
|
||||
bb.merge(m_bed.get_bounding_box());
|
||||
return bb;
|
||||
}
|
||||
|
||||
@ -6198,10 +6129,7 @@ void GLCanvas3D::_zoom_to_bounding_box(const BoundingBoxf3& bbox)
|
||||
{
|
||||
m_camera.zoom = zoom;
|
||||
// center view around bounding box center
|
||||
m_camera.set_target(bbox.center(), *this);
|
||||
|
||||
viewport_changed();
|
||||
|
||||
m_camera.set_target(bbox.center());
|
||||
m_dirty = true;
|
||||
}
|
||||
}
|
||||
@ -6293,7 +6221,6 @@ void GLCanvas3D::_camera_tranform() const
|
||||
|
||||
::glRotatef(-m_camera.get_theta(), 1.0f, 0.0f, 0.0f); // pitch
|
||||
::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f); // yaw
|
||||
|
||||
Vec3d target = -m_camera.get_target();
|
||||
::glTranslated(target(0), target(1), target(2));
|
||||
}
|
||||
@ -6389,16 +6316,13 @@ void GLCanvas3D::_render_bed(float theta) const
|
||||
float scale_factor = 1.0;
|
||||
#if ENABLE_RETINA_GL
|
||||
scale_factor = m_retina_helper->get_scale_factor();
|
||||
#endif
|
||||
|
||||
if (m_bed != nullptr)
|
||||
m_bed->render(theta, m_use_VBOs, scale_factor);
|
||||
#endif // ENABLE_RETINA_GL
|
||||
m_bed.render(theta, m_use_VBOs, scale_factor);
|
||||
}
|
||||
|
||||
void GLCanvas3D::_render_axes() const
|
||||
{
|
||||
if (m_bed != nullptr)
|
||||
m_bed->render_axes();
|
||||
m_bed.render_axes();
|
||||
}
|
||||
|
||||
void GLCanvas3D::_render_objects() const
|
||||
@ -6416,9 +6340,9 @@ void GLCanvas3D::_render_objects() const
|
||||
// Update the layer editing selection to the first object selected, update the current object maximum Z.
|
||||
const_cast<LayersEditing&>(m_layers_editing).select_object(*m_model, this->is_layers_editing_enabled() ? m_selection.get_object_idx() : -1);
|
||||
|
||||
if ((m_config != nullptr) && (m_bed != nullptr))
|
||||
if (m_config != nullptr)
|
||||
{
|
||||
const BoundingBoxf3& bed_bb = m_bed->get_bounding_box();
|
||||
const BoundingBoxf3& bed_bb = m_bed.get_bounding_box();
|
||||
m_volumes.set_print_box((float)bed_bb.min(0), (float)bed_bb.min(1), 0.0f, (float)bed_bb.max(0), (float)bed_bb.max(1), (float)m_config->opt_float("max_print_height"));
|
||||
m_volumes.check_outside_state(m_config, nullptr);
|
||||
}
|
||||
@ -6600,7 +6524,7 @@ void GLCanvas3D::_render_toolbar() const
|
||||
}
|
||||
else
|
||||
{
|
||||
top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar->get_height()) * inv_zoom;
|
||||
top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom;
|
||||
left = -0.5f * m_toolbar.get_width() * inv_zoom;
|
||||
}
|
||||
break;
|
||||
@ -6635,12 +6559,11 @@ void GLCanvas3D::_render_toolbar() const
|
||||
|
||||
void GLCanvas3D::_render_view_toolbar() const
|
||||
{
|
||||
if (m_view_toolbar != nullptr) {
|
||||
#if ENABLE_SVG_ICONS
|
||||
#if ENABLE_RETINA_GL
|
||||
m_view_toolbar->set_scale(m_retina_helper->get_scale_factor());
|
||||
m_view_toolbar.set_scale(m_retina_helper->get_scale_factor());
|
||||
#else
|
||||
m_view_toolbar->set_scale(m_canvas->GetContentScaleFactor());
|
||||
m_view_toolbar.set_scale(m_canvas->GetContentScaleFactor());
|
||||
#endif // ENABLE_RETINA_GL
|
||||
|
||||
Size cnv_size = get_canvas_size();
|
||||
@ -6648,18 +6571,17 @@ void GLCanvas3D::_render_view_toolbar() const
|
||||
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
||||
|
||||
// places the toolbar on the bottom-left corner of the 3d scene
|
||||
float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar->get_height()) * inv_zoom;
|
||||
float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom;
|
||||
float left = -0.5f * (float)cnv_size.get_width() * inv_zoom;
|
||||
m_view_toolbar->set_position(top, left);
|
||||
m_view_toolbar.set_position(top, left);
|
||||
#else
|
||||
#if ENABLE_RETINA_GL
|
||||
m_view_toolbar->set_icons_scale(m_retina_helper->get_scale_factor());
|
||||
m_view_toolbar.set_icons_scale(m_retina_helper->get_scale_factor());
|
||||
#else
|
||||
m_view_toolbar->set_icons_scale(m_canvas->GetContentScaleFactor());
|
||||
m_view_toolbar.set_icons_scale(m_canvas->GetContentScaleFactor());
|
||||
#endif /* __WXMSW__ */
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
m_view_toolbar->render(*this);
|
||||
}
|
||||
m_view_toolbar.render(*this);
|
||||
}
|
||||
|
||||
#if ENABLE_SHOW_CAMERA_TARGET
|
||||
@ -8175,7 +8097,7 @@ void GLCanvas3D::_resize_toolbars() const
|
||||
}
|
||||
else
|
||||
{
|
||||
top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar->get_height()) * inv_zoom;
|
||||
top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom;
|
||||
left = -0.5f * m_toolbar.get_width() * inv_zoom;
|
||||
}
|
||||
m_toolbar.set_position(top, left);
|
||||
@ -8203,15 +8125,15 @@ void GLCanvas3D::_resize_toolbars() const
|
||||
if (m_view_toolbar != nullptr)
|
||||
{
|
||||
#if ENABLE_RETINA_GL
|
||||
m_view_toolbar->set_icons_scale(m_retina_helper->get_scale_factor());
|
||||
m_view_toolbar.set_icons_scale(m_retina_helper->get_scale_factor());
|
||||
#else
|
||||
m_view_toolbar->set_icons_scale(m_canvas->GetContentScaleFactor());
|
||||
m_view_toolbar.set_icons_scale(m_canvas->GetContentScaleFactor());
|
||||
#endif /* __WXMSW__ */
|
||||
|
||||
// places the toolbar on the bottom-left corner of the 3d scene
|
||||
float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar->get_height()) * inv_zoom;
|
||||
float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom;
|
||||
float left = -0.5f * (float)cnv_size.get_width() * inv_zoom;
|
||||
m_view_toolbar->set_position(top, left);
|
||||
m_view_toolbar.set_position(top, left);
|
||||
}
|
||||
}
|
||||
#endif // !ENABLE_SVG_ICONS
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "GLToolbar.hpp"
|
||||
#include "Event.hpp"
|
||||
#include "3DBed.hpp"
|
||||
#include "Camera.hpp"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
@ -100,7 +101,6 @@ template <size_t N> using Vec3dsEvent = ArrayEvent<Vec3d, N>;
|
||||
|
||||
wxDECLARE_EVENT(EVT_GLCANVAS_INIT, SimpleEvent);
|
||||
wxDECLARE_EVENT(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent);
|
||||
wxDECLARE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent);
|
||||
wxDECLARE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent);
|
||||
wxDECLARE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent);
|
||||
wxDECLARE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
|
||||
@ -162,41 +162,6 @@ class GLCanvas3D
|
||||
void reset() { first_volumes.clear(); }
|
||||
};
|
||||
|
||||
struct Camera
|
||||
{
|
||||
enum EType : unsigned char
|
||||
{
|
||||
Unknown,
|
||||
// Perspective,
|
||||
Ortho,
|
||||
Num_types
|
||||
};
|
||||
|
||||
EType type;
|
||||
float zoom;
|
||||
float phi;
|
||||
// float distance;
|
||||
|
||||
private:
|
||||
Vec3d m_target;
|
||||
BoundingBoxf3 m_scene_box;
|
||||
float m_theta;
|
||||
|
||||
public:
|
||||
Camera();
|
||||
|
||||
std::string get_type_as_string() const;
|
||||
|
||||
float get_theta() const { return m_theta; }
|
||||
void set_theta(float theta, bool apply_limit);
|
||||
|
||||
const Vec3d& get_target() const { return m_target; }
|
||||
void set_target(const Vec3d& target, GLCanvas3D& canvas);
|
||||
|
||||
const BoundingBoxf3& get_scene_box() const { return m_scene_box; }
|
||||
void set_scene_box(const BoundingBoxf3& box, GLCanvas3D& canvas);
|
||||
};
|
||||
|
||||
#if !ENABLE_TEXTURES_FROM_SVG
|
||||
class Shader
|
||||
{
|
||||
@ -885,14 +850,14 @@ private:
|
||||
LegendTexture m_legend_texture;
|
||||
WarningTexture m_warning_texture;
|
||||
wxTimer m_timer;
|
||||
Camera m_camera;
|
||||
Bed3D* m_bed;
|
||||
Bed3D& m_bed;
|
||||
Camera& m_camera;
|
||||
GLToolbar& m_view_toolbar;
|
||||
LayersEditing m_layers_editing;
|
||||
Shader m_shader;
|
||||
Mouse m_mouse;
|
||||
mutable Gizmos m_gizmos;
|
||||
mutable GLToolbar m_toolbar;
|
||||
GLToolbar* m_view_toolbar;
|
||||
ClippingPlane m_clipping_planes[2];
|
||||
bool m_use_clipping_planes;
|
||||
mutable SlaCap m_sla_caps[2];
|
||||
@ -908,7 +873,6 @@ private:
|
||||
bool m_dirty;
|
||||
bool m_initialized;
|
||||
bool m_use_VBOs;
|
||||
bool m_requires_zoom_to_bed;
|
||||
bool m_apply_zoom_to_volumes_filter;
|
||||
mutable int m_hover_volume_id;
|
||||
bool m_toolbar_action_running;
|
||||
@ -934,7 +898,7 @@ private:
|
||||
#endif // not ENABLE_IMGUI
|
||||
|
||||
public:
|
||||
GLCanvas3D(wxGLCanvas* canvas);
|
||||
GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar);
|
||||
~GLCanvas3D();
|
||||
|
||||
void set_context(wxGLContext* context) { m_context = context; }
|
||||
@ -942,10 +906,6 @@ public:
|
||||
wxGLCanvas* get_wxglcanvas() { return m_canvas; }
|
||||
const wxGLCanvas* get_wxglcanvas() const { return m_canvas; }
|
||||
|
||||
void set_bed(Bed3D* bed) { m_bed = bed; }
|
||||
|
||||
void set_view_toolbar(GLToolbar* toolbar) { m_view_toolbar = toolbar; }
|
||||
|
||||
bool init(bool useVBOs, bool use_legacy_opengl);
|
||||
void post_event(wxEvent &&event);
|
||||
|
||||
@ -1005,7 +965,6 @@ public:
|
||||
void zoom_to_volumes();
|
||||
void zoom_to_selection();
|
||||
void select_view(const std::string& direction);
|
||||
void set_viewport_from_scene(const GLCanvas3D& other);
|
||||
|
||||
void update_volumes_colors_by_extruder();
|
||||
|
||||
@ -1070,8 +1029,6 @@ public:
|
||||
|
||||
void update_gizmos_on_off_state();
|
||||
|
||||
void viewport_changed();
|
||||
|
||||
void handle_sidebar_focus_event(const std::string& opt_key, bool focus_on);
|
||||
|
||||
void update_ui_from_settings();
|
||||
|
@ -129,7 +129,7 @@ GLCanvas3DManager::~GLCanvas3DManager()
|
||||
}
|
||||
}
|
||||
|
||||
bool GLCanvas3DManager::add(wxGLCanvas* canvas)
|
||||
bool GLCanvas3DManager::add(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar)
|
||||
{
|
||||
if (canvas == nullptr)
|
||||
return false;
|
||||
@ -137,7 +137,7 @@ bool GLCanvas3DManager::add(wxGLCanvas* canvas)
|
||||
if (_get_canvas(canvas) != m_canvases.end())
|
||||
return false;
|
||||
|
||||
GLCanvas3D* canvas3D = new GLCanvas3D(canvas);
|
||||
GLCanvas3D* canvas3D = new GLCanvas3D(canvas, bed, camera, view_toolbar);
|
||||
if (canvas3D == nullptr)
|
||||
return false;
|
||||
|
||||
|
@ -23,6 +23,9 @@ class PrintObject;
|
||||
namespace GUI {
|
||||
|
||||
class GLCanvas3D;
|
||||
class Bed3D;
|
||||
class GLToolbar;
|
||||
struct Camera;
|
||||
|
||||
class GLCanvas3DManager
|
||||
{
|
||||
@ -62,7 +65,7 @@ public:
|
||||
GLCanvas3DManager();
|
||||
~GLCanvas3DManager();
|
||||
|
||||
bool add(wxGLCanvas* canvas);
|
||||
bool add(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar);
|
||||
bool remove(wxGLCanvas* canvas);
|
||||
void remove_all();
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
View3D::View3D(wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process)
|
||||
View3D::View3D(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process)
|
||||
: m_canvas_widget(nullptr)
|
||||
, m_canvas(nullptr)
|
||||
#if !ENABLE_IMGUI
|
||||
@ -37,7 +37,7 @@ View3D::View3D(wxWindow* parent, Model* model, DynamicPrintConfig* config, Backg
|
||||
, m_config(nullptr)
|
||||
, m_process(nullptr)
|
||||
{
|
||||
init(parent, model, config, process);
|
||||
init(parent, bed, camera, view_toolbar, model, config, process);
|
||||
}
|
||||
|
||||
View3D::~View3D()
|
||||
@ -50,13 +50,13 @@ View3D::~View3D()
|
||||
}
|
||||
}
|
||||
|
||||
bool View3D::init(wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process)
|
||||
bool View3D::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process)
|
||||
{
|
||||
if (!Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* disable wxTAB_TRAVERSAL */))
|
||||
return false;
|
||||
|
||||
m_canvas_widget = GLCanvas3DManager::create_wxglcanvas(this);
|
||||
_3DScene::add_canvas(m_canvas_widget);
|
||||
_3DScene::add_canvas(m_canvas_widget, bed, camera, view_toolbar);
|
||||
m_canvas = _3DScene::get_canvas(this->m_canvas_widget);
|
||||
|
||||
m_canvas->allow_multisample(GLCanvas3DManager::can_multisample());
|
||||
@ -89,18 +89,6 @@ bool View3D::init(wxWindow* parent, Model* model, DynamicPrintConfig* config, Ba
|
||||
return true;
|
||||
}
|
||||
|
||||
void View3D::set_bed(Bed3D* bed)
|
||||
{
|
||||
if (m_canvas != nullptr)
|
||||
m_canvas->set_bed(bed);
|
||||
}
|
||||
|
||||
void View3D::set_view_toolbar(GLToolbar* toolbar)
|
||||
{
|
||||
if (m_canvas != nullptr)
|
||||
m_canvas->set_view_toolbar(toolbar);
|
||||
}
|
||||
|
||||
void View3D::set_as_dirty()
|
||||
{
|
||||
if (m_canvas != nullptr)
|
||||
@ -193,7 +181,7 @@ void View3D::render()
|
||||
m_canvas->set_as_dirty();
|
||||
}
|
||||
|
||||
Preview::Preview(wxWindow* parent, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data, std::function<void()> schedule_background_process_func)
|
||||
Preview::Preview(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data, std::function<void()> schedule_background_process_func)
|
||||
: m_canvas_widget(nullptr)
|
||||
, m_canvas(nullptr)
|
||||
, m_double_slider_sizer(nullptr)
|
||||
@ -214,14 +202,14 @@ Preview::Preview(wxWindow* parent, DynamicPrintConfig* config, BackgroundSlicing
|
||||
, m_enabled(false)
|
||||
, m_schedule_background_process(schedule_background_process_func)
|
||||
{
|
||||
if (init(parent, config, process, gcode_preview_data))
|
||||
if (init(parent, bed, camera, view_toolbar, config, process, gcode_preview_data))
|
||||
{
|
||||
show_hide_ui_elements("none");
|
||||
load_print();
|
||||
}
|
||||
}
|
||||
|
||||
bool Preview::init(wxWindow* parent, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data)
|
||||
bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data)
|
||||
{
|
||||
if ((config == nullptr) || (process == nullptr) || (gcode_preview_data == nullptr))
|
||||
return false;
|
||||
@ -230,7 +218,7 @@ bool Preview::init(wxWindow* parent, DynamicPrintConfig* config, BackgroundSlici
|
||||
return false;
|
||||
|
||||
m_canvas_widget = GLCanvas3DManager::create_wxglcanvas(this);
|
||||
_3DScene::add_canvas(m_canvas_widget);
|
||||
_3DScene::add_canvas(m_canvas_widget, bed, camera, view_toolbar);
|
||||
m_canvas = _3DScene::get_canvas(this->m_canvas_widget);
|
||||
m_canvas->allow_multisample(GLCanvas3DManager::can_multisample());
|
||||
m_canvas->set_config(m_config);
|
||||
@ -342,18 +330,6 @@ Preview::~Preview()
|
||||
}
|
||||
}
|
||||
|
||||
void Preview::set_bed(Bed3D* bed)
|
||||
{
|
||||
if (m_canvas != nullptr)
|
||||
m_canvas->set_bed(bed);
|
||||
}
|
||||
|
||||
void Preview::set_view_toolbar(GLToolbar* toolbar)
|
||||
{
|
||||
if (m_canvas != nullptr)
|
||||
m_canvas->set_view_toolbar(toolbar);
|
||||
}
|
||||
|
||||
void Preview::set_number_extruders(unsigned int number_extruders)
|
||||
{
|
||||
if (m_number_extruders != number_extruders)
|
||||
@ -390,18 +366,6 @@ void Preview::select_view(const std::string& direction)
|
||||
m_canvas->select_view(direction);
|
||||
}
|
||||
|
||||
void Preview::set_viewport_from_scene(GLCanvas3D* canvas)
|
||||
{
|
||||
if (canvas != nullptr)
|
||||
m_canvas->set_viewport_from_scene(*canvas);
|
||||
}
|
||||
|
||||
void Preview::set_viewport_into_scene(GLCanvas3D* canvas)
|
||||
{
|
||||
if (canvas != nullptr)
|
||||
canvas->set_viewport_from_scene(*m_canvas);
|
||||
}
|
||||
|
||||
void Preview::set_drop_target(wxDropTarget* target)
|
||||
{
|
||||
if (target != nullptr)
|
||||
|
@ -28,6 +28,7 @@ namespace GUI {
|
||||
class GLCanvas3D;
|
||||
class GLToolbar;
|
||||
class Bed3D;
|
||||
struct Camera;
|
||||
|
||||
class View3D : public wxPanel
|
||||
{
|
||||
@ -43,15 +44,12 @@ class View3D : public wxPanel
|
||||
BackgroundSlicingProcess* m_process;
|
||||
|
||||
public:
|
||||
View3D(wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process);
|
||||
View3D(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process);
|
||||
virtual ~View3D();
|
||||
|
||||
wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; }
|
||||
GLCanvas3D* get_canvas3d() { return m_canvas; }
|
||||
|
||||
void set_bed(Bed3D* bed);
|
||||
void set_view_toolbar(GLToolbar* toolbar);
|
||||
|
||||
void set_as_dirty();
|
||||
void bed_shape_changed();
|
||||
|
||||
@ -75,7 +73,7 @@ public:
|
||||
void render();
|
||||
|
||||
private:
|
||||
bool init(wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process);
|
||||
bool init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process);
|
||||
};
|
||||
|
||||
class Preview : public wxPanel
|
||||
@ -108,22 +106,17 @@ class Preview : public wxPanel
|
||||
PrusaDoubleSlider* m_slider {nullptr};
|
||||
|
||||
public:
|
||||
Preview(wxWindow* parent, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data, std::function<void()> schedule_background_process = [](){});
|
||||
Preview(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data, std::function<void()> schedule_background_process = [](){});
|
||||
virtual ~Preview();
|
||||
|
||||
wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; }
|
||||
GLCanvas3D* get_canvas3d() { return m_canvas; }
|
||||
|
||||
void set_bed(Bed3D* bed);
|
||||
void set_view_toolbar(GLToolbar* toolbar);
|
||||
|
||||
void set_number_extruders(unsigned int number_extruders);
|
||||
void set_canvas_as_dirty();
|
||||
void set_enabled(bool enabled);
|
||||
void bed_shape_changed();
|
||||
void select_view(const std::string& direction);
|
||||
void set_viewport_from_scene(GLCanvas3D* canvas);
|
||||
void set_viewport_into_scene(GLCanvas3D* canvas);
|
||||
void set_drop_target(wxDropTarget* target);
|
||||
|
||||
void load_print();
|
||||
@ -131,7 +124,7 @@ public:
|
||||
void refresh_print();
|
||||
|
||||
private:
|
||||
bool init(wxWindow* parent, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data);
|
||||
bool init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data);
|
||||
|
||||
void bind_event_handlers();
|
||||
void unbind_event_handlers();
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "GLToolbar.hpp"
|
||||
#include "GUI_Preview.hpp"
|
||||
#include "3DBed.hpp"
|
||||
#include "Camera.hpp"
|
||||
#include "Tab.hpp"
|
||||
#include "PresetBundle.hpp"
|
||||
#include "BackgroundSlicingProcess.hpp"
|
||||
@ -1019,6 +1020,7 @@ struct Plater::priv
|
||||
std::vector<wxPanel*> panels;
|
||||
Sidebar *sidebar;
|
||||
Bed3D bed;
|
||||
Camera camera;
|
||||
View3D* view3D;
|
||||
GLToolbar view_toolbar;
|
||||
Preview *preview;
|
||||
@ -1115,7 +1117,6 @@ struct Plater::priv
|
||||
void on_action_layersediting(SimpleEvent&);
|
||||
|
||||
void on_object_select(SimpleEvent&);
|
||||
void on_viewport_changed(SimpleEvent&);
|
||||
void on_right_click(Vec2dEvent&);
|
||||
void on_wipetower_moved(Vec3dEvent&);
|
||||
void on_update_geometry(Vec3dsEvent<2>&);
|
||||
@ -1202,11 +1203,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
sla_print.set_status_callback(statuscb);
|
||||
this->q->Bind(EVT_SLICING_UPDATE, &priv::on_slicing_update, this);
|
||||
|
||||
view3D = new View3D(q, &model, config, &background_process);
|
||||
preview = new Preview(q, config, &background_process, &gcode_preview_data, [this](){ schedule_background_process(); });
|
||||
|
||||
view3D->set_bed(&bed);
|
||||
preview->set_bed(&bed);
|
||||
view3D = new View3D(q, bed, camera, view_toolbar, &model, config, &background_process);
|
||||
preview = new Preview(q, bed, camera, view_toolbar, config, &background_process, &gcode_preview_data, [this](){ schedule_background_process(); });
|
||||
|
||||
panels.push_back(view3D);
|
||||
panels.push_back(preview);
|
||||
@ -1238,7 +1236,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
// 3DScene events:
|
||||
view3D_canvas->Bind(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS, [this](SimpleEvent&) { this->schedule_background_process(); });
|
||||
view3D_canvas->Bind(EVT_GLCANVAS_OBJECT_SELECT, &priv::on_object_select, this);
|
||||
view3D_canvas->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this);
|
||||
view3D_canvas->Bind(EVT_GLCANVAS_RIGHT_CLICK, &priv::on_right_click, this);
|
||||
view3D_canvas->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); });
|
||||
view3D_canvas->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent&) { arrange(); });
|
||||
@ -1268,7 +1265,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [this](SimpleEvent&) { set_bed_shape(config->option<ConfigOptionPoints>("bed_shape")->values); });
|
||||
|
||||
// Preview events:
|
||||
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this);
|
||||
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_QUESTION_MARK, [this](SimpleEvent&) { wxGetApp().keyboard_shortcuts(); });
|
||||
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [this](SimpleEvent&) { set_bed_shape(config->option<ConfigOptionPoints>("bed_shape")->values); });
|
||||
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_TAB, [this](SimpleEvent&) { select_next_view_3D(); });
|
||||
@ -2226,6 +2222,10 @@ void Plater::priv::set_current_panel(wxPanel* panel)
|
||||
if (std::find(panels.begin(), panels.end(), panel) == panels.end())
|
||||
return;
|
||||
|
||||
#ifdef __WXMAC__
|
||||
bool force_render = (current_panel != nullptr);
|
||||
#endif // __WXMAC__
|
||||
|
||||
if (current_panel == panel)
|
||||
return;
|
||||
|
||||
@ -2234,8 +2234,20 @@ void Plater::priv::set_current_panel(wxPanel* panel)
|
||||
for (wxPanel* p : panels)
|
||||
{
|
||||
if (p == current_panel)
|
||||
{
|
||||
#ifdef __WXMAC__
|
||||
// On Mac we need also to force a render to avoid flickering when changing view
|
||||
if (force_render)
|
||||
{
|
||||
if (p == view3D)
|
||||
dynamic_cast<View3D*>(p)->get_canvas3d()->render();
|
||||
else if (p == preview)
|
||||
dynamic_cast<Preview*>(p)->get_canvas3d()->render();
|
||||
}
|
||||
#endif // __WXMAC__
|
||||
p->Show();
|
||||
}
|
||||
}
|
||||
// then set to invisible the other
|
||||
for (wxPanel* p : panels)
|
||||
{
|
||||
@ -2435,15 +2447,6 @@ void Plater::priv::on_object_select(SimpleEvent& evt)
|
||||
selection_changed();
|
||||
}
|
||||
|
||||
void Plater::priv::on_viewport_changed(SimpleEvent& evt)
|
||||
{
|
||||
wxObject* o = evt.GetEventObject();
|
||||
if (o == preview->get_wxglcanvas())
|
||||
preview->set_viewport_into_scene(view3D->get_canvas3d());
|
||||
else if (o == view3D->get_wxglcanvas())
|
||||
preview->set_viewport_from_scene(view3D->get_canvas3d());
|
||||
}
|
||||
|
||||
void Plater::priv::on_right_click(Vec2dEvent& evt)
|
||||
{
|
||||
int obj_idx = get_selected_object_idx();
|
||||
@ -2681,9 +2684,6 @@ void Plater::priv::init_view_toolbar()
|
||||
|
||||
view_toolbar.select_item("3D");
|
||||
view_toolbar.set_enabled(true);
|
||||
|
||||
view3D->set_view_toolbar(&view_toolbar);
|
||||
preview->set_view_toolbar(&view_toolbar);
|
||||
}
|
||||
|
||||
bool Plater::priv::can_delete_object() const
|
||||
|
Loading…
x
Reference in New Issue
Block a user