Code cleanup in Selection and GLCanvas3D

This commit is contained in:
enricoturri1966 2022-01-27 13:17:32 +01:00
parent 703aefa75c
commit 9d764bfeac
4 changed files with 17 additions and 79 deletions

View File

@ -5381,11 +5381,7 @@ void GLCanvas3D::_render_gcode()
m_gcode_viewer.render(); m_gcode_viewer.render();
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void GLCanvas3D::_render_selection() void GLCanvas3D::_render_selection()
#else
void GLCanvas3D::_render_selection() const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
float scale_factor = 1.0; float scale_factor = 1.0;
#if ENABLE_RETINA_GL #if ENABLE_RETINA_GL
@ -5660,11 +5656,7 @@ void GLCanvas3D::_render_view_toolbar() const
} }
#if ENABLE_SHOW_CAMERA_TARGET #if ENABLE_SHOW_CAMERA_TARGET
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void GLCanvas3D::_render_camera_target() void GLCanvas3D::_render_camera_target()
#else
void GLCanvas3D::_render_camera_target() const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
static const double half_length = 5.0; static const double half_length = 5.0;
@ -5857,11 +5849,7 @@ void GLCanvas3D::_render_sla_slices()
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void GLCanvas3D::_render_selection_sidebar_hints() void GLCanvas3D::_render_selection_sidebar_hints()
#else
void GLCanvas3D::_render_selection_sidebar_hints() const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
m_selection.render_sidebar_hints(m_sidebar_field); m_selection.render_sidebar_hints(m_sidebar_field);
} }

View File

@ -936,11 +936,7 @@ private:
void _render_bed_for_picking(bool bottom); void _render_bed_for_picking(bool bottom);
void _render_objects(GLVolumeCollection::ERenderType type); void _render_objects(GLVolumeCollection::ERenderType type);
void _render_gcode(); void _render_gcode();
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void _render_selection(); void _render_selection();
#else
void _render_selection() const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
void _render_sequential_clearance(); void _render_sequential_clearance();
#if ENABLE_RENDER_SELECTION_CENTER #if ENABLE_RENDER_SELECTION_CENTER
void _render_selection_center(); void _render_selection_center();
@ -955,18 +951,10 @@ private:
void _render_collapse_toolbar() const; void _render_collapse_toolbar() const;
void _render_view_toolbar() const; void _render_view_toolbar() const;
#if ENABLE_SHOW_CAMERA_TARGET #if ENABLE_SHOW_CAMERA_TARGET
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void _render_camera_target(); void _render_camera_target();
#else
void _render_camera_target() const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
#endif // ENABLE_SHOW_CAMERA_TARGET #endif // ENABLE_SHOW_CAMERA_TARGET
void _render_sla_slices(); void _render_sla_slices();
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void _render_selection_sidebar_hints(); void _render_selection_sidebar_hints();
#else
void _render_selection_sidebar_hints() const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
bool _render_undo_redo_stack(const bool is_undo, float pos_x); bool _render_undo_redo_stack(const bool is_undo, float pos_x);
bool _render_search_list(float pos_x); bool _render_search_list(float pos_x);
bool _render_arrange_menu(float pos_x); bool _render_arrange_menu(float pos_x);

View File

@ -1255,21 +1255,15 @@ void Selection::erase()
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void Selection::render(float scale_factor) void Selection::render(float scale_factor)
#else
void Selection::render(float scale_factor) const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
if (!m_valid || is_empty()) if (!m_valid || is_empty())
return; return;
#if ENABLE_GLBEGIN_GLEND_REMOVAL
m_scale_factor = scale_factor; m_scale_factor = scale_factor;
#if ENABLE_GLBEGIN_GLEND_REMOVAL
render_bounding_box(get_bounding_box(), ColorRGB::WHITE()); render_bounding_box(get_bounding_box(), ColorRGB::WHITE());
#else #else
*const_cast<float*>(&m_scale_factor) = scale_factor;
// render cumulative bounding box of selected volumes // render cumulative bounding box of selected volumes
render_selected_volumes(); render_selected_volumes();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
@ -1306,11 +1300,7 @@ void Selection::render_center(bool gizmo_is_dragging)
} }
#endif // ENABLE_RENDER_SELECTION_CENTER #endif // ENABLE_RENDER_SELECTION_CENTER
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void Selection::render_sidebar_hints(const std::string& sidebar_field) void Selection::render_sidebar_hints(const std::string& sidebar_field)
#else
void Selection::render_sidebar_hints(const std::string& sidebar_field) const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
if (sidebar_field.empty()) if (sidebar_field.empty())
return; return;
@ -1845,11 +1835,7 @@ void Selection::render_selected_volumes() const
} }
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void Selection::render_synchronized_volumes() void Selection::render_synchronized_volumes()
#else
void Selection::render_synchronized_volumes() const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
if (m_mode == Instance) if (m_mode == Instance)
return; return;
@ -2032,9 +2018,9 @@ static ColorRGBA get_color(Axis axis)
return AXES_COLOR[axis]; return AXES_COLOR[axis];
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void Selection::render_sidebar_position_hints(const std::string& sidebar_field) void Selection::render_sidebar_position_hints(const std::string& sidebar_field)
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL
if (boost::ends_with(sidebar_field, "x")) { if (boost::ends_with(sidebar_field, "x")) {
glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0));
m_arrow.set_color(get_color(X)); m_arrow.set_color(get_color(X));
@ -2049,30 +2035,27 @@ void Selection::render_sidebar_position_hints(const std::string& sidebar_field)
m_arrow.set_color(get_color(Z)); m_arrow.set_color(get_color(Z));
m_arrow.render(); m_arrow.render();
} }
}
#else #else
void Selection::render_sidebar_position_hints(const std::string& sidebar_field) const
{
if (boost::ends_with(sidebar_field, "x")) { if (boost::ends_with(sidebar_field, "x")) {
glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0));
const_cast<GLModel*>(&m_arrow)->set_color(-1, get_color(X)); m_arrow.set_color(-1, get_color(X));
m_arrow.render(); m_arrow.render();
} }
else if (boost::ends_with(sidebar_field, "y")) { else if (boost::ends_with(sidebar_field, "y")) {
const_cast<GLModel*>(&m_arrow)->set_color(-1, get_color(Y)); m_arrow.set_color(-1, get_color(Y));
m_arrow.render(); m_arrow.render();
} }
else if (boost::ends_with(sidebar_field, "z")) { else if (boost::ends_with(sidebar_field, "z")) {
glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(90.0, 1.0, 0.0, 0.0));
const_cast<GLModel*>(&m_arrow)->set_color(-1, get_color(Z)); m_arrow.set_color(-1, get_color(Z));
m_arrow.render(); m_arrow.render();
} }
}
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
}
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field) void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field)
{ {
#if ENABLE_GLBEGIN_GLEND_REMOVAL
auto render_sidebar_rotation_hint = [this]() { auto render_sidebar_rotation_hint = [this]() {
m_curved_arrow.render(); m_curved_arrow.render();
glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(180.0, 0.0, 0.0, 1.0));
@ -2093,10 +2076,7 @@ void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field)
m_curved_arrow.set_color(get_color(Z)); m_curved_arrow.set_color(get_color(Z));
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
} }
}
#else #else
void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field) const
{
auto render_sidebar_rotation_hint = [this]() { auto render_sidebar_rotation_hint = [this]() {
m_curved_arrow.render(); m_curved_arrow.render();
glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); glsafe(::glRotated(180.0, 0.0, 0.0, 1.0));
@ -2105,26 +2085,22 @@ void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field)
if (boost::ends_with(sidebar_field, "x")) { if (boost::ends_with(sidebar_field, "x")) {
glsafe(::glRotated(90.0, 0.0, 1.0, 0.0)); glsafe(::glRotated(90.0, 0.0, 1.0, 0.0));
const_cast<GLModel*>(&m_curved_arrow)->set_color(-1, get_color(X)); m_curved_arrow.set_color(-1, get_color(X));
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
} }
else if (boost::ends_with(sidebar_field, "y")) { else if (boost::ends_with(sidebar_field, "y")) {
glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0));
const_cast<GLModel*>(&m_curved_arrow)->set_color(-1, get_color(Y)); m_curved_arrow.set_color(-1, get_color(Y));
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
} }
else if (boost::ends_with(sidebar_field, "z")) { else if (boost::ends_with(sidebar_field, "z")) {
const_cast<GLModel*>(&m_curved_arrow)->set_color(-1, get_color(Z)); m_curved_arrow.set_color(-1, get_color(Z));
render_sidebar_rotation_hint(); render_sidebar_rotation_hint();
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
} }
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) void Selection::render_sidebar_scale_hints(const std::string& sidebar_field)
#else
void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
bool uniform_scale = requires_uniform_scale() || wxGetApp().obj_manipul()->get_uniform_scaling(); bool uniform_scale = requires_uniform_scale() || wxGetApp().obj_manipul()->get_uniform_scaling();
@ -2132,7 +2108,7 @@ void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) con
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
m_arrow.set_color(uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); m_arrow.set_color(uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis));
#else #else
const_cast<GLModel*>(&m_arrow)->set_color(-1, uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); m_arrow.set_color(-1, uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
GLShaderProgram* shader = wxGetApp().get_current_shader(); GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader != nullptr) if (shader != nullptr)
@ -2167,11 +2143,7 @@ void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) con
} }
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
#else
void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) const
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
{ {
static const float Margin = 10.0f; static const float Margin = 10.0f;

View File

@ -338,13 +338,8 @@ public:
void erase(); void erase();
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void render(float scale_factor = 1.0); void render(float scale_factor = 1.0);
void render_sidebar_hints(const std::string& sidebar_field); void render_sidebar_hints(const std::string& sidebar_field);
#else
void render(float scale_factor = 1.0) const;
void render_sidebar_hints(const std::string& sidebar_field) const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_RENDER_SELECTION_CENTER #if ENABLE_RENDER_SELECTION_CENTER
void render_center(bool gizmo_is_dragging); void render_center(bool gizmo_is_dragging);
#endif // ENABLE_RENDER_SELECTION_CENTER #endif // ENABLE_RENDER_SELECTION_CENTER
@ -377,22 +372,17 @@ private:
void do_remove_instance(unsigned int object_idx, unsigned int instance_idx); void do_remove_instance(unsigned int object_idx, unsigned int instance_idx);
void do_remove_object(unsigned int object_idx); void do_remove_object(unsigned int object_idx);
void set_bounding_boxes_dirty() { m_bounding_box.reset(); m_unscaled_instance_bounding_box.reset(); m_scaled_instance_bounding_box.reset(); } void set_bounding_boxes_dirty() { m_bounding_box.reset(); m_unscaled_instance_bounding_box.reset(); m_scaled_instance_bounding_box.reset(); }
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void render_synchronized_volumes(); void render_synchronized_volumes();
#if ENABLE_GLBEGIN_GLEND_REMOVAL
void render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color); void render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color);
#else
void render_selected_volumes() const;
void render_bounding_box(const BoundingBoxf3& box, float* color) const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
void render_sidebar_position_hints(const std::string& sidebar_field); void render_sidebar_position_hints(const std::string& sidebar_field);
void render_sidebar_rotation_hints(const std::string& sidebar_field); void render_sidebar_rotation_hints(const std::string& sidebar_field);
void render_sidebar_scale_hints(const std::string& sidebar_field); void render_sidebar_scale_hints(const std::string& sidebar_field);
void render_sidebar_layers_hints(const std::string& sidebar_field); void render_sidebar_layers_hints(const std::string& sidebar_field);
#else
void render_selected_volumes() const;
void render_synchronized_volumes() const;
void render_bounding_box(const BoundingBoxf3& box, float* color) const;
void render_sidebar_position_hints(const std::string& sidebar_field) const;
void render_sidebar_rotation_hints(const std::string& sidebar_field) const;
void render_sidebar_scale_hints(const std::string& sidebar_field) const;
void render_sidebar_layers_hints(const std::string& sidebar_field) const;
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
public: public:
enum SyncRotationType { enum SyncRotationType {