GCodeViewer -> Toggle visibility of extrusions roles

This commit is contained in:
enricoturri1966 2020-04-17 10:43:29 +02:00
parent 9c68abfb35
commit 9776d7c5a1
5 changed files with 52 additions and 14 deletions

View File

@ -104,6 +104,7 @@ void GCodeViewer::reset()
buffer.reset();
}
m_extrusions.reset_role_visibility_flags();
m_shells.volumes.clear();
m_layers_zs = std::vector<double>();
}
@ -121,7 +122,7 @@ bool GCodeViewer::is_toolpath_visible(GCodeProcessor::EMoveType type) const
return (id < m_buffers.size()) ? m_buffers[id].visible : false;
}
void GCodeViewer::set_toolpath_visible(GCodeProcessor::EMoveType type, bool visible)
void GCodeViewer::set_toolpath_move_type_visible(GCodeProcessor::EMoveType type, bool visible)
{
size_t id = static_cast<size_t>(buffer_id(type));
if (id < m_buffers.size())
@ -364,7 +365,7 @@ void GCodeViewer::render_toolpaths() const
if (color_id >= erCount)
color_id = 0;
color = m_extrusion_role_colors[color_id];
color = m_extrusions.role_colors[color_id];
break;
}
case EViewType::Height:
@ -394,6 +395,10 @@ void GCodeViewer::render_toolpaths() const
BOOST_LOG_TRIVIAL(error) << "Unable to find uniform_color uniform";
};
auto is_path_visible = [](unsigned int flags, const Path& path) {
return Extrusions::is_role_visible(flags, path.role);
};
glsafe(::glCullFace(GL_BACK));
unsigned char begin_id = buffer_id(GCodeProcessor::EMoveType::Retract);
@ -456,6 +461,9 @@ void GCodeViewer::render_toolpaths() const
{
for (const Path& path : buffer.paths)
{
if (!is_path_visible(m_extrusions.role_visibility_flags, path))
continue;
set_color(current_program_id, extrusion_color(path));
glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint))));
}

View File

@ -62,6 +62,24 @@ class GCodeViewer
Shader shader;
};
struct Extrusions
{
std::array<std::array<float, 4>, erCount> role_colors;
unsigned int role_visibility_flags{ 0 };
void reset_role_visibility_flags() {
role_visibility_flags = 0;
for (unsigned int i = 0; i < erCount; ++i)
{
role_visibility_flags |= 1 << i;
}
}
static bool is_role_visible(unsigned int flags, ExtrusionRole role) {
return role < erCount && (flags & (1 << role)) != 0;
}
};
public:
enum class EViewType : unsigned char
{
@ -82,10 +100,8 @@ private:
unsigned int m_last_result_id{ 0 };
std::vector<double> m_layers_zs;
Extrusions m_extrusions;
Shells m_shells;
std::array<std::array<float, 4>, erCount> m_extrusion_role_colors;
EViewType m_view_type{ EViewType::FeatureType };
public:
@ -93,8 +109,8 @@ public:
~GCodeViewer() { reset(); }
bool init() {
m_extrusion_role_colors = Default_Extrusion_Role_Colors;
set_toolpath_visible(GCodeProcessor::EMoveType::Extrude, true);
m_extrusions.role_colors = Default_Extrusion_Role_Colors;
set_toolpath_move_type_visible(GCodeProcessor::EMoveType::Extrude, true);
return init_shaders();
}
void load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized);
@ -112,7 +128,8 @@ public:
}
bool is_toolpath_visible(GCodeProcessor::EMoveType type) const;
void set_toolpath_visible(GCodeProcessor::EMoveType type, bool visible);
void set_toolpath_move_type_visible(GCodeProcessor::EMoveType type, bool visible);
void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; }
bool are_shells_visible() const { return m_shells.visible; }
void set_shells_visible(bool visible) { m_shells.visible = visible; }

View File

@ -2322,9 +2322,14 @@ const std::vector<double>& GLCanvas3D::get_layers_zs() const
return m_gcode_viewer.get_layers_zs();
}
void GLCanvas3D::set_toolpath_visible(GCodeProcessor::EMoveType type, bool visible)
void GLCanvas3D::set_toolpath_move_type_visible(GCodeProcessor::EMoveType type, bool visible)
{
m_gcode_viewer.set_toolpath_visible(type, visible);
m_gcode_viewer.set_toolpath_move_type_visible(type, visible);
}
void GLCanvas3D::set_toolpath_role_visibility_flags(unsigned int flags)
{
m_gcode_viewer.set_toolpath_role_visibility_flags(flags);
}
void GLCanvas3D::set_toolpath_view_type(GCodeViewer::EViewType type)

View File

@ -641,7 +641,8 @@ public:
#if ENABLE_GCODE_VIEWER
const std::vector<double>& get_layers_zs() const;
void set_toolpath_visible(GCodeProcessor::EMoveType type, bool visible);
void set_toolpath_move_type_visible(GCodeProcessor::EMoveType type, bool visible);
void set_toolpath_role_visibility_flags(unsigned int flags);
void set_toolpath_view_type(GCodeViewer::EViewType type);
void set_shells_visible(bool visible);
#else

View File

@ -308,6 +308,9 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view
m_combochecklist_features->Create(this, wxID_ANY, _(L("Feature types")), wxDefaultPosition, wxSize(15 * wxGetApp().em_unit(), -1), wxCB_READONLY);
std::string feature_text = GUI::into_u8(_(L("Feature types")));
std::string feature_items = GUI::into_u8(
#if ENABLE_GCODE_VIEWER
_L("Unknown") + "|" +
#endif // ENABLE_GCODE_VIEWER
_(L("Perimeter")) + "|" +
_(L("External perimeter")) + "|" +
_(L("Overhang perimeter")) + "|" +
@ -618,14 +621,18 @@ void Preview::on_choice_view_type(wxCommandEvent& evt)
void Preview::on_combochecklist_features(wxCommandEvent& evt)
{
int flags = Slic3r::GUI::combochecklist_get_flags(m_combochecklist_features);
#if ENABLE_GCODE_VIEWER
m_canvas->set_toolpath_role_visibility_flags(static_cast<unsigned int>(flags));
#else
m_gcode_preview_data->extrusion.role_flags = (unsigned int)flags;
#endif // ENABLE_GCODE_VIEWER
refresh_print();
}
void Preview::on_checkbox_travel(wxCommandEvent& evt)
{
#if ENABLE_GCODE_VIEWER
m_canvas->set_toolpath_visible(GCodeProcessor::EMoveType::Travel, m_checkbox_travel->IsChecked());
m_canvas->set_toolpath_move_type_visible(GCodeProcessor::EMoveType::Travel, m_checkbox_travel->IsChecked());
refresh_print();
#else
m_gcode_preview_data->travel.is_visible = m_checkbox_travel->IsChecked();
@ -638,7 +645,7 @@ void Preview::on_checkbox_travel(wxCommandEvent& evt)
void Preview::on_checkbox_retractions(wxCommandEvent& evt)
{
#if ENABLE_GCODE_VIEWER
m_canvas->set_toolpath_visible(GCodeProcessor::EMoveType::Retract, m_checkbox_retractions->IsChecked());
m_canvas->set_toolpath_move_type_visible(GCodeProcessor::EMoveType::Retract, m_checkbox_retractions->IsChecked());
#else
m_gcode_preview_data->retraction.is_visible = m_checkbox_retractions->IsChecked();
#endif // ENABLE_GCODE_VIEWER
@ -648,7 +655,7 @@ void Preview::on_checkbox_retractions(wxCommandEvent& evt)
void Preview::on_checkbox_unretractions(wxCommandEvent& evt)
{
#if ENABLE_GCODE_VIEWER
m_canvas->set_toolpath_visible(GCodeProcessor::EMoveType::Unretract, m_checkbox_unretractions->IsChecked());
m_canvas->set_toolpath_move_type_visible(GCodeProcessor::EMoveType::Unretract, m_checkbox_unretractions->IsChecked());
#else
m_gcode_preview_data->unretraction.is_visible = m_checkbox_unretractions->IsChecked();
#endif // ENABLE_GCODE_VIEWER