1 #ifndef slic3r_GLGizmoScale_hpp_
2 #define slic3r_GLGizmoScale_hpp_
3 
4 #include "GLGizmoBase.hpp"
5 
6 #include "libslic3r/BoundingBox.hpp"
7 
8 
9 namespace Slic3r {
10 namespace GUI {
11 
12 class GLGizmoScale3D : public GLGizmoBase
13 {
14     static const float Offset;
15 
16     struct StartingData
17     {
18         Vec3d scale;
19         Vec3d drag_position;
20         BoundingBoxf3 box;
21         Vec3d pivots[6];
22         bool ctrl_down;
23 
StartingDataSlic3r::GUI::GLGizmoScale3D::StartingData24         StartingData() : scale(Vec3d::Ones()), drag_position(Vec3d::Zero()), ctrl_down(false) { for (int i = 0; i < 5; ++i) { pivots[i] = Vec3d::Zero(); } }
25     };
26 
27     mutable BoundingBoxf3 m_box;
28     mutable Transform3d m_transform;
29     // Transforms grabbers offsets to the proper reference system (world for instances, instance for volumes)
30     mutable Transform3d m_offsets_transform;
31     Vec3d m_scale;
32     Vec3d m_offset;
33     double m_snap_step;
34     StartingData m_starting;
35 
36 public:
37     GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
38 
get_snap_step(double step) const39     double get_snap_step(double step) const { return m_snap_step; }
set_snap_step(double step)40     void set_snap_step(double step) { m_snap_step = step; }
41 
get_scale() const42     const Vec3d& get_scale() const { return m_scale; }
set_scale(const Vec3d & scale)43     void set_scale(const Vec3d& scale) { m_starting.scale = scale; m_scale = scale; }
44 
get_offset() const45     const Vec3d& get_offset() const { return m_offset; }
46 
47     std::string get_tooltip() const override;
48 
49 protected:
50     virtual bool on_init();
51     virtual std::string on_get_name() const;
52     virtual bool on_is_activable() const;
53     virtual void on_start_dragging();
54     virtual void on_update(const UpdateData& data);
55     virtual void on_render() const;
56     virtual void on_render_for_picking() const;
57 
58 private:
59     void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const;
60 
61     void do_scale_along_axis(Axis axis, const UpdateData& data);
62     void do_scale_uniform(const UpdateData& data);
63 
64     double calc_ratio(const UpdateData& data) const;
65 };
66 
67 
68 } // namespace GUI
69 } // namespace Slic3r
70 
71 #endif // slic3r_GLGizmoScale_hpp_
72