2018-05-09 08:47:04 +00:00
|
|
|
#ifndef slic3r_GLCanvas3D_hpp_
|
|
|
|
#define slic3r_GLCanvas3D_hpp_
|
|
|
|
|
2018-05-14 12:14:19 +00:00
|
|
|
#include "../../libslic3r/BoundingBox.hpp"
|
2018-05-15 07:50:01 +00:00
|
|
|
#include "../../libslic3r/Utils.hpp"
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
class wxGLCanvas;
|
|
|
|
class wxGLContext;
|
|
|
|
class wxSizeEvent;
|
2018-05-14 12:47:13 +00:00
|
|
|
class wxIdleEvent;
|
2018-05-15 14:09:04 +00:00
|
|
|
class wxKeyEvent;
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
2018-05-14 12:14:19 +00:00
|
|
|
|
|
|
|
class GLVolumeCollection;
|
2018-05-15 13:38:25 +00:00
|
|
|
class ExPolygon;
|
2018-05-14 12:14:19 +00:00
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2018-05-15 13:38:25 +00:00
|
|
|
class GeometryBuffer
|
|
|
|
{
|
|
|
|
std::vector<float> m_data;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool set_from_triangles(const Polygons& triangles, float z);
|
|
|
|
bool set_from_lines(const Lines& lines, float z);
|
|
|
|
|
|
|
|
const float* get_data() const;
|
|
|
|
unsigned int get_data_size() const;
|
|
|
|
};
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
class GLCanvas3D
|
|
|
|
{
|
|
|
|
public:
|
2018-05-14 10:08:23 +00:00
|
|
|
class Camera
|
2018-05-09 08:47:04 +00:00
|
|
|
{
|
2018-05-14 10:08:23 +00:00
|
|
|
public:
|
2018-05-09 08:47:04 +00:00
|
|
|
enum EType : unsigned char
|
|
|
|
{
|
|
|
|
CT_Unknown,
|
|
|
|
CT_Perspective,
|
|
|
|
CT_Ortho,
|
|
|
|
CT_Count
|
|
|
|
};
|
|
|
|
|
2018-05-14 10:08:23 +00:00
|
|
|
private:
|
|
|
|
EType m_type;
|
|
|
|
float m_zoom;
|
|
|
|
float m_phi;
|
|
|
|
float m_theta;
|
|
|
|
float m_distance;
|
|
|
|
Pointf3 m_target;
|
2018-05-09 08:47:04 +00:00
|
|
|
|
2018-05-14 10:08:23 +00:00
|
|
|
public:
|
2018-05-09 08:47:04 +00:00
|
|
|
Camera();
|
2018-05-14 09:31:58 +00:00
|
|
|
|
2018-05-14 10:08:23 +00:00
|
|
|
Camera::EType get_type() const;
|
|
|
|
void set_type(Camera::EType type);
|
2018-05-14 09:31:58 +00:00
|
|
|
std::string get_type_as_string() const;
|
2018-05-14 10:08:23 +00:00
|
|
|
|
|
|
|
float get_zoom() const;
|
|
|
|
void set_zoom(float zoom);
|
|
|
|
|
|
|
|
float get_phi() const;
|
|
|
|
void set_phi(float phi);
|
|
|
|
|
|
|
|
float get_theta() const;
|
|
|
|
void set_theta(float theta);
|
|
|
|
|
|
|
|
float get_distance() const;
|
|
|
|
void set_distance(float distance);
|
|
|
|
|
|
|
|
const Pointf3& get_target() const;
|
|
|
|
void set_target(const Pointf3& target);
|
2018-05-09 08:47:04 +00:00
|
|
|
};
|
|
|
|
|
2018-05-14 12:14:19 +00:00
|
|
|
class Bed
|
|
|
|
{
|
|
|
|
Pointfs m_shape;
|
|
|
|
BoundingBoxf3 m_bounding_box;
|
2018-05-15 09:07:32 +00:00
|
|
|
Pointf m_origin;
|
2018-05-15 13:38:25 +00:00
|
|
|
Polygon m_polygon;
|
|
|
|
GeometryBuffer m_triangles;
|
|
|
|
GeometryBuffer m_gridlines;
|
2018-05-14 12:14:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
const Pointfs& get_shape() const;
|
|
|
|
void set_shape(const Pointfs& shape);
|
|
|
|
|
|
|
|
const BoundingBoxf3& get_bounding_box() const;
|
|
|
|
|
2018-05-15 09:07:32 +00:00
|
|
|
const Pointf& get_origin() const;
|
|
|
|
void set_origin(const Pointf& origin);
|
|
|
|
|
2018-05-15 13:38:25 +00:00
|
|
|
void render();
|
|
|
|
|
2018-05-14 12:14:19 +00:00
|
|
|
private:
|
|
|
|
void _calc_bounding_box();
|
2018-05-15 13:38:25 +00:00
|
|
|
void _calc_triangles(const ExPolygon& poly);
|
|
|
|
void _calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox);
|
2018-05-14 12:14:19 +00:00
|
|
|
};
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
private:
|
|
|
|
wxGLCanvas* m_canvas;
|
|
|
|
wxGLContext* m_context;
|
|
|
|
Camera m_camera;
|
2018-05-14 12:14:19 +00:00
|
|
|
Bed m_bed;
|
|
|
|
|
|
|
|
GLVolumeCollection* m_volumes;
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
bool m_dirty;
|
2018-05-14 12:14:19 +00:00
|
|
|
bool m_apply_zoom_to_volumes_filter;
|
2018-05-09 08:47:04 +00:00
|
|
|
|
2018-05-15 07:50:01 +00:00
|
|
|
PerlCallback m_on_viewport_changed_callback;
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
public:
|
|
|
|
GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context);
|
2018-05-15 07:50:01 +00:00
|
|
|
~GLCanvas3D();
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
void set_current();
|
|
|
|
|
2018-05-15 13:38:25 +00:00
|
|
|
bool is_dirty() const;
|
|
|
|
void set_dirty(bool dirty);
|
|
|
|
|
2018-05-14 12:14:19 +00:00
|
|
|
bool is_shown_on_screen() const;
|
|
|
|
|
|
|
|
void resize(unsigned int w, unsigned int h);
|
|
|
|
|
|
|
|
GLVolumeCollection* get_volumes();
|
|
|
|
void set_volumes(GLVolumeCollection* volumes);
|
|
|
|
|
2018-05-15 13:38:25 +00:00
|
|
|
// Set the bed shape to a single closed 2D polygon(array of two element arrays),
|
|
|
|
// triangulate the bed and store the triangles into m_bed.m_triangles,
|
|
|
|
// fills the m_bed.m_grid_lines and sets m_bed.m_origin.
|
|
|
|
// Sets m_bed.m_polygon to limit the object placement.
|
2018-05-14 12:14:19 +00:00
|
|
|
void set_bed_shape(const Pointfs& shape);
|
2018-05-15 13:38:25 +00:00
|
|
|
// Used by ObjectCutDialog and ObjectPartsPanel to generate a rectangular ground plane to support the scene objects.
|
|
|
|
void set_auto_bed_shape();
|
2018-05-14 12:14:19 +00:00
|
|
|
|
2018-05-15 09:07:32 +00:00
|
|
|
const Pointf& get_bed_origin() const;
|
|
|
|
void set_bed_origin(const Pointf& origin);
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
Camera::EType get_camera_type() const;
|
|
|
|
void set_camera_type(Camera::EType type);
|
2018-05-14 09:31:58 +00:00
|
|
|
std::string get_camera_type_as_string() const;
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
float get_camera_zoom() const;
|
|
|
|
void set_camera_zoom(float zoom);
|
|
|
|
|
|
|
|
float get_camera_phi() const;
|
|
|
|
void set_camera_phi(float phi);
|
|
|
|
|
|
|
|
float get_camera_theta() const;
|
|
|
|
void set_camera_theta(float theta);
|
|
|
|
|
|
|
|
float get_camera_distance() const;
|
|
|
|
void set_camera_distance(float distance);
|
|
|
|
|
|
|
|
const Pointf3& get_camera_target() const;
|
|
|
|
void set_camera_target(const Pointf3& target);
|
|
|
|
|
2018-05-14 12:14:19 +00:00
|
|
|
BoundingBoxf3 bed_bounding_box() const;
|
|
|
|
BoundingBoxf3 volumes_bounding_box() const;
|
|
|
|
BoundingBoxf3 max_bounding_box() const;
|
|
|
|
|
2018-05-15 08:32:38 +00:00
|
|
|
void zoom_to_bed();
|
|
|
|
void zoom_to_volumes();
|
2018-05-15 09:30:11 +00:00
|
|
|
void select_view(const std::string& direction);
|
2018-05-15 08:32:38 +00:00
|
|
|
|
2018-05-15 13:38:25 +00:00
|
|
|
void render();
|
|
|
|
|
2018-05-15 07:50:01 +00:00
|
|
|
void register_on_viewport_changed_callback(void* callback);
|
|
|
|
|
2018-05-14 12:47:13 +00:00
|
|
|
void on_size(wxSizeEvent& evt);
|
|
|
|
void on_idle(wxIdleEvent& evt);
|
2018-05-15 14:09:04 +00:00
|
|
|
void on_char(wxKeyEvent& evt);
|
2018-05-14 12:47:13 +00:00
|
|
|
|
2018-05-14 12:14:19 +00:00
|
|
|
private:
|
|
|
|
void _zoom_to_bounding_box(const BoundingBoxf3& bbox);
|
2018-05-14 12:47:13 +00:00
|
|
|
std::pair<int, int> _get_canvas_size() const;
|
2018-05-15 07:50:01 +00:00
|
|
|
float _get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) const;
|
|
|
|
|
|
|
|
void _deregister_callbacks();
|
2018-05-09 08:47:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif // slic3r_GLCanvas3D_hpp_
|