NEW:add variable layer height

Change-Id: Idef7f0dea32e4faaeb4d6eb188695cc7b554099c
(cherry picked from commit 4969835159eebb356e9b26dab223ad0a18882b70)
This commit is contained in:
liz.li 2022-10-28 11:19:43 +08:00 committed by Lane.Wei
parent b44f3ae3e6
commit 22dd20ab58
16 changed files with 927 additions and 75 deletions

View file

@ -188,6 +188,9 @@ wxDECLARE_EVENT(EVT_GLCANVAS_TOOLBAR_HIGHLIGHTER_TIMER, wxTimerEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_GIZMO_HIGHLIGHTER_TIMER, wxTimerEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE, SimpleEvent);
wxDECLARE_EVENT(EVT_CUSTOMEVT_TICKSCHANGED, wxCommandEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_RESET_LAYER_HEIGHT_PROFILE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ADAPTIVE_LAYER_HEIGHT_PROFILE, Event<float>);
wxDECLARE_EVENT(EVT_GLCANVAS_SMOOTH_LAYER_HEIGHT_PROFILE, HeightProfileSmoothEvent);
class GLCanvas3D
{
@ -202,6 +205,108 @@ class GLCanvas3D
static void update_render_colors();
static void load_render_colors();
class LayersEditing
{
public:
enum EState : unsigned char
{
Unknown,
Editing,
Completed,
Num_States
};
static const float THICKNESS_BAR_WIDTH;
private:
bool m_enabled{ false };
unsigned int m_z_texture_id{ 0 };
// Not owned by LayersEditing.
const DynamicPrintConfig* m_config{ nullptr };
// ModelObject for the currently selected object (Model::objects[last_object_id]).
const ModelObject* m_model_object{ nullptr };
// Maximum z of the currently selected object (Model::objects[last_object_id]).
float m_object_max_z{ 0.0f };
// Owned by LayersEditing.
SlicingParameters* m_slicing_parameters{ nullptr };
std::vector<double> m_layer_height_profile;
mutable float m_adaptive_quality{ 0.5f };
mutable HeightProfileSmoothingParams m_smooth_params;
static float s_overlay_window_width;
struct LayersTexture
{
// Texture data
std::vector<char> data;
// Width of the texture, top level.
size_t width{ 0 };
// Height of the texture, top level.
size_t height{ 0 };
// For how many levels of detail is the data allocated?
size_t levels{ 0 };
// Number of texture cells allocated for the height texture.
size_t cells{ 0 };
// Does it need to be refreshed?
bool valid{ false };
};
LayersTexture m_layers_texture;
public:
EState state{ Unknown };
float band_width{ 2.0f };
float strength{ 0.005f };
int last_object_id{ -1 };
float last_z{ 0.0f };
LayerHeightEditActionType last_action{ LAYER_HEIGHT_EDIT_ACTION_INCREASE };
LayersEditing() = default;
~LayersEditing();
void init();
void set_config(const DynamicPrintConfig* config);
void select_object(const Model& model, int object_id);
bool is_allowed() const;
bool is_enabled() const;
void set_enabled(bool enabled);
void show_tooltip_information(const GLCanvas3D& canvas, std::map<wxString, wxString> captions_texts, float x, float y);
void render_variable_layer_height_dialog(const GLCanvas3D& canvas);
void render_overlay(const GLCanvas3D& canvas);
void render_volumes(const GLCanvas3D& canvas, const GLVolumeCollection& volumes);
void adjust_layer_height_profile();
void accept_changes(GLCanvas3D& canvas);
void reset_layer_height_profile(GLCanvas3D& canvas);
void adaptive_layer_height_profile(GLCanvas3D& canvas, float quality_factor);
void smooth_layer_height_profile(GLCanvas3D& canvas, const HeightProfileSmoothingParams& smoothing_params);
static float get_cursor_z_relative(const GLCanvas3D& canvas);
static bool bar_rect_contains(const GLCanvas3D& canvas, float x, float y);
static Rect get_bar_rect_screen(const GLCanvas3D& canvas);
static Rect get_bar_rect_viewport(const GLCanvas3D& canvas);
static float get_overlay_window_width() { return LayersEditing::s_overlay_window_width; }
float object_max_z() const { return m_object_max_z; }
std::string get_tooltip(const GLCanvas3D& canvas) const;
private:
bool is_initialized() const;
void generate_layer_height_texture();
void render_background_texture(const GLCanvas3D& canvas, const Rect& bar_rect);
void render_curve(const Rect& bar_rect);
void update_slicing_parameters();
static float thickness_bar_width(const GLCanvas3D& canvas);
};
struct Mouse
{
struct Drag
@ -394,6 +499,7 @@ private:
unsigned int m_last_w, m_last_h;
bool m_in_render;
wxTimer m_timer;
LayersEditing m_layers_editing;
Mouse m_mouse;
GLGizmosManager m_gizmos;
//BBS: GUI refactor: GLToolbar
@ -655,8 +761,16 @@ public:
BoundingBoxf3 scene_bounding_box() const;
BoundingBoxf3 plate_scene_bounding_box(int plate_idx) const;
bool is_layers_editing_enabled() const;
bool is_layers_editing_allowed() const;
void reset_layer_height_profile();
void adaptive_layer_height_profile(float quality_factor);
void smooth_layer_height_profile(const HeightProfileSmoothingParams& smoothing_params);
bool is_reload_delayed() const;
void enable_layers_editing(bool enable);
void enable_legend_texture(bool enable);
void enable_picking(bool enable);
void enable_moving(bool enable);
@ -914,6 +1028,8 @@ public:
bool is_object_sinking(int object_idx) 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);
@ -1030,9 +1146,11 @@ private:
bool _deactivate_arrange_menu();
//BBS: add deactivate_orient_menu
bool _deactivate_orient_menu();
//BBS: add _deactivate_layersediting_menu
bool _deactivate_layersediting_menu();
// BBS FIXME
float get_overlay_window_width() { return 100.f; }
float get_overlay_window_width() { return 0; /*LayersEditing::get_overlay_window_width();*/ }
static std::vector<std::array<float, 4>> _parse_colors(const std::vector<std::string>& colors);
};