Tech ENABLE_SHOW_TOOLPATHS_COG - Show toolpaths center of gravity

This commit is contained in:
enricoturri1966 2022-02-08 12:57:56 +01:00
parent f6c7fefec2
commit 92aa6540f5
15 changed files with 407 additions and 37 deletions
src/slic3r/GUI

View file

@ -380,6 +380,52 @@ class GCodeViewer
bool visible{ false };
};
#if ENABLE_SHOW_TOOLPATHS_COG
// helper to render center of gravity
class COG
{
GLModel m_model;
bool m_visible{ false };
// whether or not to render the model with fixed screen size
bool m_fixed_size{ true };
double m_total_mass{ 0.0 };
Vec3d m_position{ Vec3d::Zero() };
public:
void render();
void reset() {
m_position = Vec3d::Zero();
m_total_mass = 0.0;
}
bool is_visible() const { return m_visible; }
void set_visible(bool visible) { m_visible = visible; }
void add_segment(const Vec3d& v1, const Vec3d& v2, double mass) {
assert(mass > 0.0);
m_position += mass * 0.5 * (v1 + v2);
m_total_mass += mass;
}
Vec3d cog() const { return (m_total_mass > 0.0) ? (Vec3d)(m_position / m_total_mass) : Vec3d::Zero(); }
private:
void init() {
if (m_model.is_initialized())
return;
const float radius = m_fixed_size ? 10.0f : 1.0f;
#if ENABLE_GLBEGIN_GLEND_REMOVAL
m_model.init_from(smooth_sphere(32, radius));
#else
m_model.init_from(its_make_sphere(radius, PI / 32.0));
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
}
};
#endif // ENABLE_SHOW_TOOLPATHS_COG
// helper to render extrusion paths
struct Extrusions
{
@ -734,6 +780,9 @@ private:
Extrusions m_extrusions;
SequentialView m_sequential_view;
Shells m_shells;
#if ENABLE_SHOW_TOOLPATHS_COG
COG m_cog;
#endif // ENABLE_SHOW_TOOLPATHS_COG
EViewType m_view_type{ EViewType::FeatureType };
bool m_legend_enabled{ true };
#if ENABLE_PREVIEW_LAYOUT
@ -779,6 +828,9 @@ public:
void reset();
void render();
#if ENABLE_SHOW_TOOLPATHS_COG
void render_cog() { m_cog.render(); }
#endif // ENABLE_SHOW_TOOLPATHS_COG
bool has_data() const { return !m_roles.empty(); }
bool can_export_toolpaths() const;