From 75f1f832aa01af7cf0595ee3e5feef51d45e5d0b Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 15 May 2018 11:07:32 +0200 Subject: [PATCH] 3DScene bed origin moved to c++ --- lib/Slic3r/GUI/3DScene.pm | 48 ++++++++++++++++++------- xs/src/slic3r/GUI/3DScene.cpp | 11 ++++++ xs/src/slic3r/GUI/3DScene.hpp | 3 ++ xs/src/slic3r/GUI/GLCanvas3D.cpp | 20 +++++++++++ xs/src/slic3r/GUI/GLCanvas3D.hpp | 7 ++++ xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 13 +++++++ xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 3 ++ xs/xsp/GUI_3DScene.xsp | 15 ++++++++ 8 files changed, 108 insertions(+), 12 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 67f5866b7..b12f84a94 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -53,7 +53,6 @@ __PACKAGE__->mk_accessors( qw(_quat init bed_grid_lines bed_polygon background - origin _mouse_pos _hover_volume_idx @@ -997,7 +996,10 @@ sub set_auto_bed_shape { [ $center->x - $max_size, $center->y + $max_size ], #++ ]); # Set the origin for painting of the coordinate system axes. - $self->origin(Slic3r::Pointf->new(@$center[X,Y])); +#============================================================================================================================== + Slic3r::GUI::_3DScene::set_bed_origin($self, Slic3r::Pointf->new(@$center[X,Y])); +# $self->origin(Slic3r::Pointf->new(@$center[X,Y])); +#============================================================================================================================== } # Set the bed shape to a single closed 2D polygon (array of two element arrays), @@ -1048,7 +1050,10 @@ sub set_bed_shape { } # Set the origin for painting of the coordinate system axes. - $self->origin(Slic3r::Pointf->new(0,0)); +#============================================================================================================================== + Slic3r::GUI::_3DScene::set_bed_origin($self, Slic3r::Pointf->new(0,0)); +# $self->origin(Slic3r::Pointf->new(0,0)); +#============================================================================================================================== $self->bed_polygon(offset_ex([$expolygon->contour], $bed_bb->radius * 1.7, JT_ROUND, scale(0.5))->[0]->contour->clone); } @@ -1548,7 +1553,10 @@ sub Render { # draw axes # disable depth testing so that axes are not covered by ground glDisable(GL_DEPTH_TEST); - my $origin = $self->origin; +#============================================================================================================================== + my $origin = Slic3r::GUI::_3DScene::get_bed_origin($self); +# my $origin = $self->origin; +#============================================================================================================================== my $axis_len = $self->use_plain_shader ? 0.3 * max(@{ $self->bed_bounding_box->size }) : 2 * max(@{ $volumes_bb->size }); glLineWidth(2); glBegin(GL_LINES); @@ -1906,10 +1914,18 @@ sub draw_legend { my ($cw, $ch) = $self->GetSizeWH; - my $l = (-0.5 * $cw) / $self->_zoom; - my $t = (0.5 * $ch) / $self->_zoom; - my $r = $l + $tex_w / $self->_zoom; - my $b = $t - $tex_h / $self->_zoom; +#============================================================================================================================== + my $zoom = Slic3r::GUI::_3DScene::get_camera_zoom($self); + my $l = (-0.5 * $cw) / $zoom; + my $t = (0.5 * $ch) / $zoom; + my $r = $l + $tex_w / $zoom; + my $b = $t - $tex_h / $zoom; + +# my $l = (-0.5 * $cw) / $self->_zoom; +# my $t = (0.5 * $ch) / $self->_zoom; +# my $r = $l + $tex_w / $self->_zoom; +# my $b = $t - $tex_h / $self->_zoom; +#============================================================================================================================== $self->_render_texture($tex_id, $l, $r, $b, $t); glPopMatrix(); @@ -1939,10 +1955,18 @@ sub draw_warning { my ($cw, $ch) = $self->GetSizeWH; - my $l = (-0.5 * $tex_w) / $self->_zoom; - my $t = (-0.5 * $ch + $tex_h) / $self->_zoom; - my $r = $l + $tex_w / $self->_zoom; - my $b = $t - $tex_h / $self->_zoom; +#============================================================================================================================== + my $zoom = Slic3r::GUI::_3DScene::get_camera_zoom($self); + my $l = (-0.5 * $tex_w) / $zoom; + my $t = (-0.5 * $ch + $tex_h) / $zoom; + my $r = $l + $tex_w / $zoom; + my $b = $t - $tex_h / $zoom; + +# my $l = (-0.5 * $tex_w) / $self->_zoom; +# my $t = (-0.5 * $ch + $tex_h) / $self->_zoom; +# my $r = $l + $tex_w / $self->_zoom; +# my $b = $t - $tex_h / $self->_zoom; +#============================================================================================================================== $self->_render_texture($tex_id, $l, $r, $b, $t); glPopMatrix(); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 98326e95e..c6effb0a9 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1767,6 +1767,17 @@ void _3DScene::set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape) return s_canvas_mgr.set_bed_shape(canvas, shape); } +Pointf _3DScene::get_bed_origin(wxGLCanvas* canvas) +{ + return s_canvas_mgr.get_bed_origin(canvas); +} + +void _3DScene::set_bed_origin(wxGLCanvas* canvas, const Pointf* origin) +{ + if (origin != nullptr) + s_canvas_mgr.set_bed_origin(canvas, *origin); +} + BoundingBoxf3 _3DScene::get_bed_bounding_box(wxGLCanvas* canvas) { return s_canvas_mgr.get_bed_bounding_box(canvas); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 66f506a7f..5c603028d 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -551,6 +551,9 @@ public: static void set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape); + static Pointf get_bed_origin(wxGLCanvas* canvas); + static void set_bed_origin(wxGLCanvas* canvas, const Pointf* origin); + static BoundingBoxf3 get_bed_bounding_box(wxGLCanvas* canvas); static BoundingBoxf3 get_volumes_bounding_box(wxGLCanvas* canvas); static BoundingBoxf3 get_max_bounding_box(wxGLCanvas* canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index d358ebeca..487ffbc75 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -119,6 +119,16 @@ const BoundingBoxf3& GLCanvas3D::Bed::get_bounding_box() const return m_bounding_box; } +const Pointf& GLCanvas3D::Bed::get_origin() const +{ + return m_origin; +} + +void GLCanvas3D::Bed::set_origin(const Pointf& origin) +{ + m_origin = origin; +} + void GLCanvas3D::Bed::_calc_bounding_box() { m_bounding_box = BoundingBoxf3(); @@ -235,6 +245,16 @@ void GLCanvas3D::set_bed_shape(const Pointfs& shape) m_bed.set_shape(shape); } +const Pointf& GLCanvas3D::get_bed_origin() const +{ + return m_bed.get_origin(); +} + +void GLCanvas3D::set_bed_origin(const Pointf& origin) +{ + m_bed.set_origin(origin); +} + bool GLCanvas3D::is_dirty() const { return m_dirty; diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 41c0e0b4a..d32421542 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -64,6 +64,7 @@ public: { Pointfs m_shape; BoundingBoxf3 m_bounding_box; + Pointf m_origin; public: const Pointfs& get_shape() const; @@ -71,6 +72,9 @@ public: const BoundingBoxf3& get_bounding_box() const; + const Pointf& get_origin() const; + void set_origin(const Pointf& origin); + private: void _calc_bounding_box(); }; @@ -103,6 +107,9 @@ public: void set_bed_shape(const Pointfs& shape); + const Pointf& get_bed_origin() const; + void set_bed_origin(const Pointf& origin); + bool is_dirty() const; void set_dirty(bool dirty); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index 7c0db99d3..9bde6210d 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -180,6 +180,19 @@ void GLCanvas3DManager::set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape) it->second->set_bed_shape(shape); } +Pointf GLCanvas3DManager::get_bed_origin(wxGLCanvas* canvas) const +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->get_bed_origin() : Pointf(); +} + +void GLCanvas3DManager::set_bed_origin(wxGLCanvas* canvas, const Pointf& origin) +{ + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->set_bed_origin(origin); +} + BoundingBoxf3 GLCanvas3DManager::get_bed_bounding_box(wxGLCanvas* canvas) { CanvasesMap::const_iterator it = _get_canvas(canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index d7e8f0b2f..4edf97dd6 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -61,6 +61,9 @@ public: void set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape); + Pointf get_bed_origin(wxGLCanvas* canvas) const; + void set_bed_origin(wxGLCanvas* canvas, const Pointf& origin); + BoundingBoxf3 get_bed_bounding_box(wxGLCanvas* canvas); BoundingBoxf3 get_volumes_bounding_box(wxGLCanvas* canvas); BoundingBoxf3 get_max_bounding_box(wxGLCanvas* canvas); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 4d155816d..ee1a94cc8 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -215,6 +215,21 @@ set_bed_shape(canvas, shape) CODE: _3DScene::set_bed_shape((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), shape); +Clone +get_bed_origin(canvas) + SV *canvas; + CODE: + RETVAL = _3DScene::get_bed_origin((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); + OUTPUT: + RETVAL + +void +set_bed_origin(canvas, origin) + SV *canvas; + Pointf *origin + CODE: + _3DScene::set_bed_origin((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), origin); + Clone get_bed_bounding_box(canvas) SV *canvas;