2018-06-13 07:12:16 +00:00
|
|
|
#ifndef slic3r_GLGizmo_hpp_
|
|
|
|
#define slic3r_GLGizmo_hpp_
|
|
|
|
|
|
|
|
#include "../../slic3r/GUI/GLTexture.hpp"
|
2018-06-15 12:10:28 +00:00
|
|
|
#include "../../libslic3r/Point.hpp"
|
|
|
|
|
|
|
|
#include <vector>
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
2018-06-13 13:44:04 +00:00
|
|
|
|
|
|
|
class BoundingBoxf3;
|
|
|
|
class Pointf3;
|
2018-08-17 13:40:47 +00:00
|
|
|
class ModelObject;
|
2018-06-13 13:44:04 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class GLGizmoBase
|
|
|
|
{
|
2018-06-14 08:00:59 +00:00
|
|
|
protected:
|
|
|
|
static const float BaseColor[3];
|
|
|
|
static const float HighlightColor[3];
|
2018-06-15 12:10:28 +00:00
|
|
|
|
|
|
|
struct Grabber
|
|
|
|
{
|
|
|
|
static const float HalfSize;
|
|
|
|
static const float HoverOffset;
|
|
|
|
|
|
|
|
Pointf center;
|
2018-06-15 14:16:55 +00:00
|
|
|
float angle_z;
|
2018-06-15 12:10:28 +00:00
|
|
|
float color[3];
|
|
|
|
|
|
|
|
Grabber();
|
|
|
|
void render(bool hover) const;
|
|
|
|
};
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
public:
|
|
|
|
enum EState
|
|
|
|
{
|
|
|
|
Off,
|
|
|
|
Hover,
|
|
|
|
On,
|
|
|
|
Num_States
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EState m_state;
|
2018-06-15 12:10:28 +00:00
|
|
|
// textures are assumed to be square and all with the same size in pixels, no internal check is done
|
2018-06-13 07:12:16 +00:00
|
|
|
GLTexture m_textures[Num_States];
|
2018-06-14 13:32:26 +00:00
|
|
|
int m_hover_id;
|
2018-06-15 12:10:28 +00:00
|
|
|
mutable std::vector<Grabber> m_grabbers;
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GLGizmoBase();
|
|
|
|
virtual ~GLGizmoBase();
|
|
|
|
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
EState get_state() const;
|
2018-06-13 08:49:59 +00:00
|
|
|
void set_state(EState state);
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-06-22 13:11:04 +00:00
|
|
|
unsigned int get_texture_id() const;
|
2018-06-13 08:49:59 +00:00
|
|
|
int get_textures_size() const;
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
int get_hover_id() const;
|
2018-06-14 13:32:26 +00:00
|
|
|
void set_hover_id(int id);
|
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
void start_dragging();
|
2018-07-12 09:26:13 +00:00
|
|
|
void stop_dragging();
|
2018-06-15 12:10:28 +00:00
|
|
|
void update(const Pointf& mouse_pos);
|
2018-07-12 09:26:13 +00:00
|
|
|
void refresh();
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-06-13 13:44:04 +00:00
|
|
|
void render(const BoundingBoxf3& box) const;
|
2018-06-14 13:32:26 +00:00
|
|
|
void render_for_picking(const BoundingBoxf3& box) const;
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool on_init() = 0;
|
2018-07-12 09:26:13 +00:00
|
|
|
virtual void on_set_state();
|
2018-06-18 13:07:17 +00:00
|
|
|
virtual void on_start_dragging();
|
2018-07-12 09:26:13 +00:00
|
|
|
virtual void on_stop_dragging();
|
2018-06-15 12:10:28 +00:00
|
|
|
virtual void on_update(const Pointf& mouse_pos) = 0;
|
2018-07-12 09:26:13 +00:00
|
|
|
virtual void on_refresh();
|
2018-06-13 13:44:04 +00:00
|
|
|
virtual void on_render(const BoundingBoxf3& box) const = 0;
|
2018-06-14 13:32:26 +00:00
|
|
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0;
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
void render_grabbers() const;
|
2018-06-13 07:12:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GLGizmoRotate : public GLGizmoBase
|
|
|
|
{
|
2018-06-14 08:00:59 +00:00
|
|
|
static const float Offset;
|
|
|
|
static const unsigned int CircleResolution;
|
2018-06-15 14:16:55 +00:00
|
|
|
static const unsigned int AngleResolution;
|
2018-06-14 08:00:59 +00:00
|
|
|
static const unsigned int ScaleStepsCount;
|
|
|
|
static const float ScaleStepRad;
|
|
|
|
static const unsigned int ScaleLongEvery;
|
|
|
|
static const float ScaleLongTooth;
|
|
|
|
static const float ScaleShortTooth;
|
|
|
|
static const unsigned int SnapRegionsCount;
|
|
|
|
static const float GrabberOffset;
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
float m_angle_z;
|
|
|
|
|
2018-06-15 14:16:55 +00:00
|
|
|
mutable Pointf m_center;
|
|
|
|
mutable float m_radius;
|
2018-08-15 10:50:06 +00:00
|
|
|
mutable bool m_keep_initial_values;
|
2018-06-15 14:16:55 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
public:
|
|
|
|
GLGizmoRotate();
|
|
|
|
|
2018-06-19 07:46:26 +00:00
|
|
|
float get_angle_z() const;
|
|
|
|
void set_angle_z(float angle_z);
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
protected:
|
|
|
|
virtual bool on_init();
|
2018-07-12 09:26:13 +00:00
|
|
|
virtual void on_set_state();
|
2018-06-15 12:10:28 +00:00
|
|
|
virtual void on_update(const Pointf& mouse_pos);
|
2018-07-12 09:26:13 +00:00
|
|
|
virtual void on_refresh();
|
2018-06-13 13:44:04 +00:00
|
|
|
virtual void on_render(const BoundingBoxf3& box) const;
|
2018-06-14 13:32:26 +00:00
|
|
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
2018-06-14 08:00:59 +00:00
|
|
|
|
|
|
|
private:
|
2018-06-15 14:16:55 +00:00
|
|
|
void _render_circle() const;
|
|
|
|
void _render_scale() const;
|
|
|
|
void _render_snap_radii() const;
|
|
|
|
void _render_reference_radius() const;
|
|
|
|
void _render_angle_z() const;
|
|
|
|
void _render_grabber() const;
|
2018-06-13 07:12:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GLGizmoScale : public GLGizmoBase
|
|
|
|
{
|
2018-06-13 13:44:04 +00:00
|
|
|
static const float Offset;
|
|
|
|
|
2018-06-18 13:07:17 +00:00
|
|
|
float m_scale;
|
2018-06-19 07:46:26 +00:00
|
|
|
float m_starting_scale;
|
2018-06-18 13:07:17 +00:00
|
|
|
|
|
|
|
Pointf m_starting_drag_position;
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GLGizmoScale();
|
|
|
|
|
2018-06-18 13:07:17 +00:00
|
|
|
float get_scale() const;
|
|
|
|
void set_scale(float scale);
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
protected:
|
|
|
|
virtual bool on_init();
|
2018-06-18 13:07:17 +00:00
|
|
|
virtual void on_start_dragging();
|
2018-06-15 12:10:28 +00:00
|
|
|
virtual void on_update(const Pointf& mouse_pos);
|
2018-06-13 13:44:04 +00:00
|
|
|
virtual void on_render(const BoundingBoxf3& box) const;
|
2018-06-14 13:32:26 +00:00
|
|
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
2018-06-13 07:12:16 +00:00
|
|
|
};
|
|
|
|
|
2018-08-09 14:55:43 +00:00
|
|
|
|
|
|
|
class GLGizmoFlatten : public GLGizmoBase
|
|
|
|
{
|
|
|
|
// This gizmo does not use grabbers. The m_hover_id relates to polygon managed by the class itself.
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable Pointf3 m_normal;
|
|
|
|
|
|
|
|
struct PlaneData {
|
|
|
|
std::vector<Pointf3> vertices;
|
|
|
|
Pointf3 normal;
|
2018-08-17 13:40:47 +00:00
|
|
|
};
|
|
|
|
struct SourceDataSummary {
|
|
|
|
std::vector<BoundingBoxf3> bounding_boxes; // bounding boxes of convex hulls of individual volumes
|
|
|
|
float scaling_factor;
|
|
|
|
float rotation;
|
2018-08-20 09:27:25 +00:00
|
|
|
Pointf3 mesh_first_point;
|
2018-08-09 14:55:43 +00:00
|
|
|
};
|
|
|
|
|
2018-08-17 13:40:47 +00:00
|
|
|
// This holds information to decide whether recalculation is necessary:
|
|
|
|
SourceDataSummary m_source_data;
|
|
|
|
|
2018-08-09 14:55:43 +00:00
|
|
|
std::vector<PlaneData> m_planes;
|
2018-08-17 13:40:47 +00:00
|
|
|
std::vector<Pointf> m_instances_positions;
|
|
|
|
mutable std::unique_ptr<Pointf3> m_center = nullptr;
|
|
|
|
const ModelObject* m_model_object = nullptr;
|
|
|
|
void update_planes();
|
|
|
|
bool is_plane_update_necessary() const;
|
2018-08-09 14:55:43 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GLGizmoFlatten();
|
|
|
|
|
2018-08-17 13:40:47 +00:00
|
|
|
void set_flattening_data(const ModelObject* model_object);
|
2018-08-09 14:55:43 +00:00
|
|
|
Pointf3 get_flattening_normal() const;
|
|
|
|
|
|
|
|
protected:
|
2018-08-17 13:40:47 +00:00
|
|
|
bool on_init() override;
|
|
|
|
void on_start_dragging() override;
|
|
|
|
void on_update(const Pointf& mouse_pos) override {};
|
|
|
|
void on_render(const BoundingBoxf3& box) const override;
|
|
|
|
void on_render_for_picking(const BoundingBoxf3& box) const override;
|
|
|
|
void on_set_state() override {
|
|
|
|
if (m_state == On && is_plane_update_necessary())
|
|
|
|
update_planes();
|
|
|
|
}
|
2018-08-09 14:55:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif // slic3r_GLGizmo_hpp_
|
|
|
|
|