PrusaSlicer-NonPlainar/src/slic3r/GUI/GLCanvas3D.hpp

771 lines
25 KiB
C++
Raw Normal View History

2018-05-09 08:47:04 +00:00
#ifndef slic3r_GLCanvas3D_hpp_
#define slic3r_GLCanvas3D_hpp_
#include <stddef.h>
#include <memory>
2018-05-09 08:47:04 +00:00
2019-07-01 16:22:07 +00:00
#include "libslic3r/Arrange.hpp"
2018-09-17 10:15:11 +00:00
#include "3DScene.hpp"
#include "GLToolbar.hpp"
#include "Event.hpp"
#include "3DBed.hpp"
#include "Camera.hpp"
#include "Selection.hpp"
#include "Gizmos/GLGizmosManager.hpp"
2018-05-09 08:47:04 +00:00
2018-11-29 14:10:11 +00:00
#include <float.h>
2018-10-25 07:35:08 +00:00
#include <wx/timer.h>
2018-10-01 14:48:08 +00:00
class wxWindow;
2018-05-09 08:47:04 +00:00
class wxSizeEvent;
class wxIdleEvent;
class wxKeyEvent;
2018-05-28 13:23:01 +00:00
class wxMouseEvent;
class wxTimerEvent;
class wxPaintEvent;
2018-10-18 13:13:38 +00:00
class wxGLCanvas;
2018-05-09 08:47:04 +00:00
// Support for Retina OpenGL on Mac OS
#define ENABLE_RETINA_GL __APPLE__
2018-05-09 08:47:04 +00:00
namespace Slic3r {
2018-05-14 12:14:19 +00:00
2018-05-23 07:57:44 +00:00
class GLShader;
2018-05-15 13:38:25 +00:00
class ExPolygon;
class BackgroundSlicingProcess;
class GCodePreviewData;
2019-01-21 09:06:51 +00:00
struct SlicingParameters;
enum LayerHeightEditActionType : unsigned int;
2018-05-14 12:14:19 +00:00
2018-05-09 08:47:04 +00:00
namespace GUI {
2018-06-13 07:12:16 +00:00
class GLGizmoBase;
#if ENABLE_RETINA_GL
class RetinaHelper;
#endif
class Size
{
int m_width;
int m_height;
float m_scale_factor;
public:
Size();
Size(int width, int height, float scale_factor = 1.0);
int get_width() const;
void set_width(int width);
int get_height() const;
void set_height(int height);
int get_scale_factor() const;
void set_scale_factor(int height);
};
class ClippingPlane
{
double m_data[4];
public:
ClippingPlane()
{
m_data[0] = 0.0;
m_data[1] = 0.0;
m_data[2] = 1.0;
m_data[3] = 0.0;
}
ClippingPlane(const Vec3d& direction, double offset)
{
Vec3d norm_dir = direction.normalized();
m_data[0] = norm_dir(0);
m_data[1] = norm_dir(1);
m_data[2] = norm_dir(2);
m_data[3] = offset;
}
2019-04-12 14:08:40 +00:00
bool is_active() const { return m_data[3] != DBL_MAX; }
static ClippingPlane ClipsNothing() { return ClippingPlane(Vec3d(0., 0., 1.), DBL_MAX); }
const double* get_data() const { return m_data; }
};
2018-10-16 14:04:19 +00:00
wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent);
using Vec2dEvent = Event<Vec2d>;
template <size_t N> using Vec2dsEvent = ArrayEvent<Vec2d, N>;
using Vec3dEvent = Event<Vec3d>;
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_RIGHT_CLICK, Vec2dEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_SELECT_ALL, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_QUESTION_MARK, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_INCREASE_INSTANCES, Event<int>); // data: +1 => increase, -1 => decrease
wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_ROTATED, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_SCALED, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_WIPETOWER_ROTATED, Vec3dEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event<bool>);
wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>);
wxDECLARE_EVENT(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_BED_SHAPE, SimpleEvent);
2019-02-21 10:54:18 +00:00
wxDECLARE_EVENT(EVT_GLCANVAS_TAB, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_RESETGIZMOS, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, wxKeyEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_EDIT_COLOR_CHANGE, wxKeyEvent);
2018-05-09 08:47:04 +00:00
class GLCanvas3D
{
2018-06-05 08:56:55 +00:00
struct GCodePreviewVolumeIndex
{
enum EType
{
Extrusion,
Travel,
Retraction,
Unretraction,
Shell,
Num_Geometry_Types
};
struct FirstVolume
{
EType type;
unsigned int flag;
// Index of the first volume in a GLVolumeCollection.
unsigned int id;
FirstVolume(EType type, unsigned int flag, unsigned int id) : type(type), flag(flag), id(id) {}
};
std::vector<FirstVolume> first_volumes;
void reset() { first_volumes.clear(); }
};
#if !ENABLE_TEXTURES_FROM_SVG
2018-05-25 12:05:08 +00:00
class Shader
{
GLShader* m_shader;
public:
Shader();
~Shader();
bool init(const std::string& vertex_shader_filename, const std::string& fragment_shader_filename);
bool is_initialized() const;
bool start_using() const;
void stop_using() const;
void set_uniform(const std::string& name, float value) const;
2018-06-21 06:37:04 +00:00
void set_uniform(const std::string& name, const float* matrix) const;
const GLShader* get_shader() const;
2018-05-25 12:05:08 +00:00
private:
void _reset();
};
#endif // !ENABLE_TEXTURES_FROM_SVG
2018-05-25 12:05:08 +00:00
class LayersEditing
{
public:
enum EState : unsigned char
{
Unknown,
Editing,
Completed,
Num_States
};
private:
static const float THICKNESS_BAR_WIDTH;
static const float THICKNESS_RESET_BUTTON_HEIGHT;
2019-01-21 09:06:51 +00:00
bool m_enabled;
Shader m_shader;
unsigned int m_z_texture_id;
mutable GLTexture m_tooltip_texture;
mutable GLTexture m_reset_texture;
// Not owned by LayersEditing.
const DynamicPrintConfig *m_config;
// ModelObject for the currently selected object (Model::objects[last_object_id]).
const ModelObject *m_model_object;
// Maximum z of the currently selected object (Model::objects[last_object_id]).
float m_object_max_z;
// Owned by LayersEditing.
SlicingParameters *m_slicing_parameters;
std::vector<coordf_t> m_layer_height_profile;
bool m_layer_height_profile_modified;
class LayersTexture
{
public:
LayersTexture() : width(0), height(0), levels(0), cells(0), valid(false) {}
// Texture data
std::vector<char> data;
// Width of the texture, top level.
size_t width;
// Height of the texture, top level.
size_t height;
// For how many levels of detail is the data allocated?
size_t levels;
// Number of texture cells allocated for the height texture.
size_t cells;
// Does it need to be refreshed?
bool valid;
};
LayersTexture m_layers_texture;
public:
2018-06-01 13:54:41 +00:00
EState state;
float band_width;
float strength;
int last_object_id;
float last_z;
2019-01-21 09:06:51 +00:00
LayerHeightEditActionType last_action;
2018-06-01 13:54:41 +00:00
LayersEditing();
~LayersEditing();
2018-05-25 12:05:08 +00:00
bool init(const std::string& vertex_shader_filename, const std::string& fragment_shader_filename);
void set_config(const DynamicPrintConfig* config);
2019-01-21 09:06:51 +00:00
void select_object(const Model &model, int object_id);
2018-05-25 12:05:08 +00:00
bool is_allowed() const;
bool is_enabled() const;
2018-05-25 12:05:08 +00:00
void set_enabled(bool enabled);
2019-01-21 09:06:51 +00:00
void render_overlay(const GLCanvas3D& canvas) const;
void render_volumes(const GLCanvas3D& canvas, const GLVolumeCollection& volumes) const;
2019-01-21 09:06:51 +00:00
void adjust_layer_height_profile();
void accept_changes(GLCanvas3D& canvas);
void reset_layer_height_profile(GLCanvas3D& canvas);
2018-05-25 12:05:08 +00:00
static float get_cursor_z_relative(const GLCanvas3D& canvas);
static bool bar_rect_contains(const GLCanvas3D& canvas, float x, float y);
static bool reset_rect_contains(const GLCanvas3D& canvas, float x, float y);
static Rect get_bar_rect_screen(const GLCanvas3D& canvas);
static Rect get_reset_rect_screen(const GLCanvas3D& canvas);
static Rect get_bar_rect_viewport(const GLCanvas3D& canvas);
static Rect get_reset_rect_viewport(const GLCanvas3D& canvas);
2019-01-21 09:06:51 +00:00
float object_max_z() const { return m_object_max_z; }
private:
2018-05-25 12:05:08 +00:00
bool _is_initialized() const;
void generate_layer_height_texture();
void _render_tooltip_texture(const GLCanvas3D& canvas, const Rect& bar_rect, const Rect& reset_rect) const;
2018-06-13 07:12:16 +00:00
void _render_reset_texture(const Rect& reset_rect) const;
2019-01-21 09:06:51 +00:00
void _render_active_object_annotations(const GLCanvas3D& canvas, const Rect& bar_rect) const;
void _render_profile(const Rect& bar_rect) const;
void update_slicing_parameters();
static float thickness_bar_width(const GLCanvas3D &canvas);
static float reset_button_height(const GLCanvas3D &canvas);
};
2018-06-01 13:54:41 +00:00
struct Mouse
2018-05-23 11:56:54 +00:00
{
2018-06-01 13:54:41 +00:00
struct Drag
{
static const Point Invalid_2D_Point;
static const Vec3d Invalid_3D_Point;
static const int MoveThresholdPx;
2018-05-23 11:56:54 +00:00
2018-06-01 13:54:41 +00:00
Point start_position_2D;
Vec3d start_position_3D;
2018-06-21 06:37:04 +00:00
int move_volume_idx;
bool move_requires_threshold;
Point move_start_threshold_position_2D;
2018-05-23 11:56:54 +00:00
2018-06-01 13:54:41 +00:00
public:
Drag();
};
2018-05-23 11:56:54 +00:00
2018-06-01 13:54:41 +00:00
bool dragging;
Vec2d position;
Vec3d scene_position;
2018-06-01 13:54:41 +00:00
Drag drag;
bool ignore_left_up;
2018-06-01 13:54:41 +00:00
Mouse();
void set_start_position_2D_as_invalid() { drag.start_position_2D = Drag::Invalid_2D_Point; }
void set_start_position_3D_as_invalid() { drag.start_position_3D = Drag::Invalid_3D_Point; }
void set_move_start_threshold_position_2D_as_invalid() { drag.move_start_threshold_position_2D = Drag::Invalid_2D_Point; }
bool is_start_position_2D_defined() const { return (drag.start_position_2D != Drag::Invalid_2D_Point); }
bool is_start_position_3D_defined() const { return (drag.start_position_3D != Drag::Invalid_3D_Point); }
bool is_move_start_threshold_position_2D_defined() const { return (drag.move_start_threshold_position_2D != Drag::Invalid_2D_Point); }
bool is_move_threshold_met(const Point& mouse_pos) const {
return (std::abs(mouse_pos(0) - drag.move_start_threshold_position_2D(0)) > Drag::MoveThresholdPx)
|| (std::abs(mouse_pos(1) - drag.move_start_threshold_position_2D(1)) > Drag::MoveThresholdPx);
}
};
struct SlaCap
{
2018-12-10 11:59:49 +00:00
struct Triangles
{
Pointf3s object;
Pointf3s supports;
2018-12-10 11:59:49 +00:00
};
typedef std::map<unsigned int, Triangles> ObjectIdToTrianglesMap;
double z;
2018-12-10 11:59:49 +00:00
ObjectIdToTrianglesMap triangles;
SlaCap() { reset(); }
void reset() { z = DBL_MAX; triangles.clear(); }
bool matches(double z) const { return this->z == z; }
};
class WarningTexture : public GUI::GLTexture
{
public:
WarningTexture();
enum Warning {
ObjectOutside,
ToolpathOutside,
SlaSupportsOutside,
SomethingNotShown,
ObjectClashed
};
// Sets a warning of the given type to be active/inactive. If several warnings are active simultaneously,
// only the last one is shown (decided by the order in the enum above).
void activate(WarningTexture::Warning warning, bool state, const GLCanvas3D& canvas);
void render(const GLCanvas3D& canvas) const;
// function used to get an information for rescaling of the warning
void msw_rescale(const GLCanvas3D& canvas);
private:
static const unsigned char Background_Color[3];
static const unsigned char Opacity;
int m_original_width;
int m_original_height;
// information for rescaling of the warning legend
std::string m_msg_text = "";
bool m_is_colored_red{false};
// Information about which warnings are currently active.
std::vector<Warning> m_warnings;
// Generates the texture with given text.
2019-05-28 10:53:16 +00:00
bool generate(const std::string& msg, const GLCanvas3D& canvas, bool compress, bool red_colored = false);
};
class LegendTexture : public GUI::GLTexture
{
static const int Px_Title_Offset = 5;
static const int Px_Text_Offset = 5;
static const int Px_Square = 20;
static const int Px_Square_Contour = 1;
static const int Px_Border = Px_Square / 2;
static const unsigned char Squares_Border_Color[3];
static const unsigned char Default_Background_Color[3];
static const unsigned char Error_Background_Color[3];
static const unsigned char Opacity;
int m_original_width;
int m_original_height;
public:
LegendTexture();
void fill_color_print_legend_values(const GCodePreviewData& preview_data, const GLCanvas3D& canvas,
std::vector<std::pair<double, double>>& cp_legend_values);
2019-05-28 10:53:16 +00:00
bool generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas, bool compress);
void render(const GLCanvas3D& canvas) const;
};
#if ENABLE_RENDER_STATISTICS
struct RenderStats
{
long long last_frame;
RenderStats() : last_frame(0) {}
};
#endif // ENABLE_RENDER_STATISTICS
public:
enum ECursorType : unsigned char
{
Standard,
Cross
};
private:
2018-05-09 08:47:04 +00:00
wxGLCanvas* m_canvas;
wxGLContext* m_context;
#if ENABLE_RETINA_GL
std::unique_ptr<RetinaHelper> m_retina_helper;
#endif
bool m_in_render;
LegendTexture m_legend_texture;
WarningTexture m_warning_texture;
2018-10-25 07:35:08 +00:00
wxTimer m_timer;
Bed3D& m_bed;
Camera& m_camera;
GLToolbar& m_view_toolbar;
LayersEditing m_layers_editing;
2018-05-23 07:57:44 +00:00
Shader m_shader;
2018-05-23 11:56:54 +00:00
Mouse m_mouse;
mutable GLGizmosManager m_gizmos;
2018-07-23 11:49:48 +00:00
mutable GLToolbar m_toolbar;
2018-11-27 13:50:57 +00:00
ClippingPlane m_clipping_planes[2];
mutable ClippingPlane m_camera_clipping_plane;
2018-11-27 13:50:57 +00:00
bool m_use_clipping_planes;
mutable SlaCap m_sla_caps[2];
2018-12-18 09:40:53 +00:00
std::string m_sidebar_field;
bool m_keep_dirty;
2018-05-14 12:14:19 +00:00
2018-06-11 13:13:13 +00:00
mutable GLVolumeCollection m_volumes;
Selection m_selection;
2019-01-21 09:06:51 +00:00
const DynamicPrintConfig* m_config;
2018-06-07 09:18:28 +00:00
Model* m_model;
BackgroundSlicingProcess *m_process;
2018-05-09 08:47:04 +00:00
// Screen is only refreshed from the OnIdle handler if it is dirty.
2018-05-09 08:47:04 +00:00
bool m_dirty;
bool m_initialized;
bool m_use_VBOs;
2018-05-14 12:14:19 +00:00
bool m_apply_zoom_to_volumes_filter;
mutable std::vector<int> m_hover_volume_idxs;
2018-05-21 12:40:09 +00:00
bool m_warning_texture_enabled;
2018-05-21 12:57:43 +00:00
bool m_legend_texture_enabled;
bool m_picking_enabled;
bool m_moving_enabled;
bool m_dynamic_background_enabled;
2018-05-23 13:35:11 +00:00
bool m_multisample_allowed;
bool m_regenerate_volumes;
2018-11-26 09:41:16 +00:00
bool m_moving;
2019-02-21 17:31:01 +00:00
bool m_tab_down;
ECursorType m_cursor_type;
GLSelectionRectangle m_rectangle_selection;
// Following variable is obsolete and it should be safe to remove it.
// I just don't want to do it now before a release (Lukas Matena 24.3.2019)
bool m_render_sla_auxiliaries;
2018-05-09 08:47:04 +00:00
std::string m_color_by;
bool m_reload_delayed;
2018-06-05 08:56:55 +00:00
GCodePreviewVolumeIndex m_gcode_preview_volume_index;
#if ENABLE_RENDER_STATISTICS
RenderStats m_render_stats;
#endif // ENABLE_RENDER_STATISTICS
2018-05-09 08:47:04 +00:00
public:
GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar);
~GLCanvas3D();
2018-05-09 08:47:04 +00:00
2018-10-04 08:41:11 +00:00
void set_context(wxGLContext* context) { m_context = context; }
wxGLCanvas* get_wxglcanvas() { return m_canvas; }
const wxGLCanvas* get_wxglcanvas() const { return m_canvas; }
2018-09-17 10:15:11 +00:00
bool init(bool useVBOs);
void post_event(wxEvent &&event);
2018-05-23 07:57:44 +00:00
void set_as_dirty();
2018-05-14 12:14:19 +00:00
2018-06-11 11:48:02 +00:00
unsigned int get_volumes_count() const;
void reset_volumes();
int check_volumes_outside_state() const;
void toggle_sla_auxiliaries_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1);
void toggle_model_objects_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1);
2019-01-21 09:06:51 +00:00
void set_config(const DynamicPrintConfig* config);
void set_process(BackgroundSlicingProcess* process);
2018-06-07 09:18:28 +00:00
void set_model(Model* model);
2018-05-23 09:14:49 +00:00
const Selection& get_selection() const { return m_selection; }
Selection& get_selection() { return m_selection; }
void bed_shape_changed();
2018-05-15 09:07:32 +00:00
2018-11-27 13:50:57 +00:00
void set_clipping_plane(unsigned int id, const ClippingPlane& plane)
{
if (id < 2)
{
2018-11-27 13:50:57 +00:00
m_clipping_planes[id] = plane;
m_sla_caps[id].reset();
}
2018-11-27 13:50:57 +00:00
}
void reset_clipping_planes_cache() { m_sla_caps[0].triangles.clear(); m_sla_caps[1].triangles.clear(); }
2018-11-27 13:50:57 +00:00
void set_use_clipping_planes(bool use) { m_use_clipping_planes = use; }
2018-06-06 10:36:52 +00:00
void set_color_by(const std::string& value);
2018-09-06 14:10:31 +00:00
const Camera& get_camera() const { return m_camera; }
2018-05-09 08:47:04 +00:00
2018-05-14 12:14:19 +00:00
BoundingBoxf3 volumes_bounding_box() const;
BoundingBoxf3 scene_bounding_box() const;
2018-05-14 12:14:19 +00:00
bool is_layers_editing_enabled() const;
bool is_layers_editing_allowed() const;
bool is_reload_delayed() const;
2018-05-25 12:05:08 +00:00
void enable_layers_editing(bool enable);
2018-05-21 12:57:43 +00:00
void enable_legend_texture(bool enable);
void enable_picking(bool enable);
void enable_moving(bool enable);
2018-06-13 07:12:16 +00:00
void enable_gizmos(bool enable);
void enable_selection(bool enable);
2018-07-23 11:49:48 +00:00
void enable_toolbar(bool enable);
void enable_dynamic_background(bool enable);
2018-05-23 13:35:11 +00:00
void allow_multisample(bool allow);
2018-05-21 12:40:09 +00:00
2018-05-15 08:32:38 +00:00
void zoom_to_bed();
void zoom_to_volumes();
void zoom_to_selection();
void select_view(const std::string& direction);
2018-05-15 08:32:38 +00:00
void update_volumes_colors_by_extruder();
2018-11-26 09:41:16 +00:00
bool is_dragging() const { return m_gizmos.is_dragging() || m_moving; }
void render();
2018-05-15 13:38:25 +00:00
2018-11-21 14:28:35 +00:00
void select_all();
void deselect_all();
void delete_selected();
void ensure_on_bed(unsigned int object_idx);
std::vector<double> get_current_print_zs(bool active_only) const;
void set_toolpaths_range(double low, double high);
std::vector<int> load_object(const ModelObject& model_object, int obj_idx, std::vector<int> instance_idxs);
std::vector<int> load_object(const Model& model, int obj_idx);
void mirror_selection(Axis axis);
void reload_scene(bool refresh_immediately, bool force_full_scene_refresh = false);
2018-06-05 08:56:55 +00:00
void load_gcode_preview(const GCodePreviewData& preview_data, const std::vector<std::string>& str_tool_colors);
2018-11-26 14:16:35 +00:00
void load_sla_preview();
void load_preview(const std::vector<std::string>& str_tool_colors, const std::vector<double>& color_print_values);
2018-06-06 12:19:28 +00:00
void bind_event_handlers();
void unbind_event_handlers();
void on_size(wxSizeEvent& evt);
void on_idle(wxIdleEvent& evt);
void on_char(wxKeyEvent& evt);
void on_key(wxKeyEvent& evt);
2018-05-28 13:23:01 +00:00
void on_mouse_wheel(wxMouseEvent& evt);
void on_timer(wxTimerEvent& evt);
void on_mouse(wxMouseEvent& evt);
void on_paint(wxPaintEvent& evt);
Size get_canvas_size() const;
Vec2d get_local_mouse_position() const;
void reset_legend_texture();
2018-10-25 07:35:08 +00:00
void set_tooltip(const std::string& tooltip) const;
2018-11-21 09:36:09 +00:00
void do_move();
void do_rotate();
void do_scale();
void do_flatten();
void do_mirror();
void set_camera_zoom(double zoom);
2018-11-29 08:03:38 +00:00
2018-12-03 12:29:07 +00:00
void update_gizmos_on_off_state();
void reset_all_gizmos() { m_gizmos.reset_all_states(); }
2018-12-03 12:29:07 +00:00
2018-12-18 09:40:53 +00:00
void handle_sidebar_focus_event(const std::string& opt_key, bool focus_on);
void update_ui_from_settings();
float get_view_toolbar_height() const { return m_view_toolbar.get_height(); }
int get_move_volume_id() const { return m_mouse.drag.move_volume_idx; }
int get_first_hover_volume_idx() const { return m_hover_volume_idxs.empty() ? -1 : m_hover_volume_idxs.front(); }
2019-06-27 19:13:44 +00:00
2019-07-01 16:22:07 +00:00
class WipeTowerInfo: public arrangement::Arrangeable {
2019-06-28 15:03:50 +00:00
Vec2d m_pos = {std::nan(""), std::nan("")};
2019-06-27 19:13:44 +00:00
Vec2d m_bb_size;
double m_rotation;
friend class GLCanvas3D;
public:
inline operator bool() const
{
2019-06-28 15:03:50 +00:00
return !std::isnan(m_pos.x()) && !std::isnan(m_pos.y());
2019-06-27 19:13:44 +00:00
}
2019-06-28 15:03:50 +00:00
virtual void apply_arrange_result(Vec2d offset, double rotation_rads) final;
2019-06-28 15:03:50 +00:00
virtual std::tuple<Polygon, Vec2crd, double> get_arrange_polygon() const final
2019-06-27 19:13:44 +00:00
{
Polygon p({
{coord_t(0), coord_t(0)},
{scaled(m_bb_size(X)), coord_t(0)},
{scaled(m_bb_size)},
{coord_t(0), scaled(m_bb_size(Y))},
{coord_t(0), coord_t(0)},
});
2019-06-28 15:03:50 +00:00
return std::make_tuple(p, scaled(m_pos), m_rotation);
2019-06-27 19:13:44 +00:00
}
};
WipeTowerInfo get_wipe_tower_info() const;
// Returns the view ray line, in world coordinate, at the given mouse position.
Linef3 mouse_ray(const Point& mouse_pos);
void set_mouse_as_dragging() { m_mouse.dragging = true; }
void disable_regenerate_volumes() { m_regenerate_volumes = false; }
void refresh_camera_scene_box() { m_camera.set_scene_box(scene_bounding_box()); }
bool is_mouse_dragging() const { return m_mouse.dragging; }
double get_size_proportional_to_max_bed_size(double factor) const;
void set_cursor(ECursorType type);
void msw_rescale();
void start_keeping_dirty() { m_keep_dirty = true; }
void stop_keeping_dirty() { m_keep_dirty = false; }
2018-05-14 12:14:19 +00:00
private:
bool _is_shown_on_screen() const;
2018-07-23 11:49:48 +00:00
bool _init_toolbar();
2018-10-04 08:41:11 +00:00
bool _set_current();
2018-06-01 13:54:41 +00:00
void _resize(unsigned int w, unsigned int h);
BoundingBoxf3 _max_bounding_box(bool include_bed_model) const;
2018-06-01 13:54:41 +00:00
void _zoom_to_box(const BoundingBoxf3& box);
2018-05-28 13:23:01 +00:00
void _refresh_if_shown_on_screen();
void _picking_pass() const;
void _rectangular_selection_picking_pass() const;
void _render_background() const;
2018-06-11 08:46:32 +00:00
void _render_bed(float theta) const;
2018-12-17 13:09:35 +00:00
void _render_axes() const;
void _render_objects() const;
void _render_selection() const;
#if ENABLE_RENDER_SELECTION_CENTER
void _render_selection_center() const;
#endif // ENABLE_RENDER_SELECTION_CENTER
void _render_overlays() const;
void _render_warning_texture() const;
void _render_legend_texture() const;
void _render_volumes_for_picking() const;
2018-08-21 12:27:36 +00:00
void _render_current_gizmo() const;
void _render_gizmos_overlay() const;
2018-07-23 11:49:48 +00:00
void _render_toolbar() const;
void _render_view_toolbar() const;
#if ENABLE_SHOW_CAMERA_TARGET
void _render_camera_target() const;
#endif // ENABLE_SHOW_CAMERA_TARGET
void _render_sla_slices() const;
void _render_selection_sidebar_hints() const;
void _update_volumes_hover_state() const;
void _perform_layer_editing_action(wxMouseEvent* evt = nullptr);
// Convert the screen space coordinate to an object space coordinate.
// If the Z screen space coordinate is not provided, a depth buffer value is substituted.
Vec3d _mouse_to_3d(const Point& mouse_pos, float* z = nullptr);
2018-06-01 13:54:41 +00:00
2018-06-15 12:10:28 +00:00
// Convert the screen space coordinate to world coordinate on the bed.
Vec3d _mouse_to_bed_3d(const Point& mouse_pos);
2018-06-15 12:10:28 +00:00
2018-06-01 13:54:41 +00:00
void _start_timer();
void _stop_timer();
2018-06-05 08:56:55 +00:00
// Create 3D thick extrusion lines for a skirt and brim.
// Adds a new Slic3r::GUI::3DScene::Volume to volumes.
void _load_print_toolpaths();
// Create 3D thick extrusion lines for object forming extrusions.
// Adds a new Slic3r::GUI::3DScene::Volume to $self->volumes,
// one for perimeters, one for infill and one for supports.
void _load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors,
const std::vector<double>& color_print_values);
// Create 3D thick extrusion lines for wipe tower extrusions
void _load_wipe_tower_toolpaths(const std::vector<std::string>& str_tool_colors);
2018-06-13 11:14:17 +00:00
2018-06-05 08:56:55 +00:00
// generates gcode extrusion paths geometry
void _load_gcode_extrusion_paths(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
// generates gcode travel paths geometry
void _load_gcode_travel_paths(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
bool _travel_paths_by_type(const GCodePreviewData& preview_data);
bool _travel_paths_by_feedrate(const GCodePreviewData& preview_data);
bool _travel_paths_by_tool(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
// generates gcode retractions geometry
void _load_gcode_retractions(const GCodePreviewData& preview_data);
// generates gcode unretractions geometry
void _load_gcode_unretractions(const GCodePreviewData& preview_data);
// generates objects and wipe tower geometry
void _load_fff_shells();
// generates objects geometry for sla
void _load_sla_shells();
2018-06-05 08:56:55 +00:00
// sets gcode geometry visibility according to user selection
void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data);
void _update_toolpath_volumes_outside_state();
void _update_sla_shells_outside_state();
void _show_warning_texture_if_needed(WarningTexture::Warning warning);
2018-11-21 09:36:09 +00:00
// generates the legend texture in dependence of the current shown view type
void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
// generates a warning texture containing the given message
void _set_warning_texture(WarningTexture::Warning warning, bool state);
bool _is_any_volume_outside() const;
#if !ENABLE_SVG_ICONS
void _resize_toolbars() const;
#endif // !ENABLE_SVG_ICONS
2018-07-31 10:25:00 +00:00
// updates the selection from the content of m_hover_volume_idxs
void _update_selection_from_hover();
static std::vector<float> _parse_colors(const std::vector<std::string>& colors);
2018-12-21 11:35:20 +00:00
public:
const Print* fff_print() const;
const SLAPrint* sla_print() const;
2018-05-09 08:47:04 +00:00
};
} // namespace GUI
} // namespace Slic3r
#endif // slic3r_GLCanvas3D_hpp_