GCode Viewer - Fixed color print visualization for gcode containing multiple extruders

This commit is contained in:
enricoturri1966 2020-11-09 13:06:20 +01:00
parent 006630299b
commit bf12c7cb8c
7 changed files with 57 additions and 24 deletions

View file

@ -508,6 +508,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config)
m_flavor = config.gcode_flavor;
size_t extruders_count = config.nozzle_diameter.values.size();
m_result.extruders_count = extruders_count;
m_extruder_offsets.resize(extruders_count);
for (size_t i = 0; i < extruders_count; ++i) {
@ -580,6 +581,8 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
}
}
m_result.extruders_count = config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
const ConfigOptionPoints* extruder_offset = config.option<ConfigOptionPoints>("extruder_offset");
if (extruder_offset != nullptr) {
m_extruder_offsets.resize(extruder_offset->values.size());

View file

@ -283,6 +283,7 @@ namespace Slic3r {
std::vector<MoveVertex> moves;
Pointfs bed_shape;
SettingsIds settings_ids;
size_t extruders_count;
std::vector<std::string> extruder_colors;
PrintEstimatedTimeStatistics time_statistics;
@ -294,6 +295,7 @@ namespace Slic3r {
moves = std::vector<MoveVertex>();
bed_shape = Pointfs();
extruder_colors = std::vector<std::string>();
extruders_count = 0;
settings_ids.reset();
}
#else
@ -302,6 +304,7 @@ namespace Slic3r {
moves = std::vector<MoveVertex>();
bed_shape = Pointfs();
extruder_colors = std::vector<std::string>();
extruders_count = 0;
settings_ids.reset();
}
#endif // ENABLE_GCODE_VIEWER_STATISTICS

View file

@ -420,6 +420,7 @@ void GCodeViewer::reset()
m_paths_bounding_box = BoundingBoxf3();
m_max_bounding_box = BoundingBoxf3();
m_tool_colors = std::vector<Color>();
m_extruders_count = 0;
m_extruder_ids = std::vector<unsigned char>();
m_extrusions.reset_role_visibility_flags();
m_extrusions.reset_ranges();
@ -967,6 +968,8 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
new wxProgressDialog(_L("Generating toolpaths"), "...",
100, wxGetApp().plater(), wxPD_AUTO_HIDE | wxPD_APP_MODAL) : nullptr;
m_extruders_count = gcode_result.extruders_count;
for (size_t i = 0; i < m_moves_count; ++i) {
const GCodeProcessor::MoveVertex& move = gcode_result.moves[i];
if (wxGetApp().is_gcode_viewer())
@ -2318,8 +2321,7 @@ void GCodeViewer::render_legend() const
case EViewType::ColorPrint:
{
const std::vector<CustomGCode::Item>& custom_gcode_per_print_z = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
const int extruders_count = wxGetApp().extruders_edited_cnt();
if (extruders_count == 1) { // single extruder use case
if (m_extruders_count == 1) { // single extruder use case
std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(0, custom_gcode_per_print_z);
const int items_cnt = static_cast<int>(cp_values.size());
if (items_cnt == 0) { // There are no color changes, but there are some pause print or custom Gcode

View file

@ -399,6 +399,7 @@ private:
std::vector<double> m_layers_zs;
std::array<double, 2> m_layers_z_range;
std::vector<ExtrusionRole> m_roles;
size_t m_extruders_count;
std::vector<unsigned char> m_extruder_ids;
mutable Extrusions m_extrusions;
mutable SequentialView m_sequential_view;

View file

@ -1292,13 +1292,12 @@ void Preview::load_print_as_fff(bool keep_z_range)
// set color print values, if it si selected "ColorPrint" view type
#if ENABLE_GCODE_VIEWER
if (gcode_view_type == GCodeViewer::EViewType::ColorPrint) {
colors = wxGetApp().plater()->get_colors_for_color_print(m_gcode_result);
#else
if (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint) {
#endif // ENABLE_GCODE_VIEWER
colors = wxGetApp().plater()->get_colors_for_color_print();
#if !ENABLE_GCODE_VIEWER
colors.push_back("#808080"); // gray color for pause print or custom G-code
#endif // !ENABLE_GCODE_VIEWER
#endif // ENABLE_GCODE_VIEWER
if (!gcode_preview_data_valid) {
color_print_values = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
@ -1309,10 +1308,11 @@ void Preview::load_print_as_fff(bool keep_z_range)
}
#if ENABLE_GCODE_VIEWER
else if (gcode_preview_data_valid || gcode_view_type == GCodeViewer::EViewType::Tool) {
colors = wxGetApp().plater()->get_extruder_colors_from_plater_config(m_gcode_result);
#else
else if (gcode_preview_data_valid || (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Tool) ) {
#endif // ENABLE_GCODE_VIEWER
colors = wxGetApp().plater()->get_extruder_colors_from_plater_config();
#endif // ENABLE_GCODE_VIEWER
color_print_values.clear();
}

View file

@ -32,11 +32,9 @@
#include "libslic3r/Format/STL.hpp"
#include "libslic3r/Format/AMF.hpp"
#include "libslic3r/Format/3mf.hpp"
#if ENABLE_GCODE_VIEWER
#include "libslic3r/GCode/GCodeProcessor.hpp"
#else
#if !ENABLE_GCODE_VIEWER
#include "libslic3r/GCode/PreviewData.hpp"
#endif // ENABLE_GCODE_VIEWER
#endif // !ENABLE_GCODE_VIEWER
#include "libslic3r/GCode/ThumbnailData.hpp"
#include "libslic3r/Model.hpp"
#include "libslic3r/SLA/Hollowing.hpp"
@ -5632,31 +5630,49 @@ void Plater::on_activate()
}
// Get vector of extruder colors considering filament color, if extruder color is undefined.
#if ENABLE_GCODE_VIEWER
std::vector<std::string> Plater::get_extruder_colors_from_plater_config(const GCodeProcessor::Result* const result) const
#else
std::vector<std::string> Plater::get_extruder_colors_from_plater_config() const
#endif // ENABLE_GCODE_VIEWER
{
const Slic3r::DynamicPrintConfig* config = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
std::vector<std::string> extruder_colors;
if (!config->has("extruder_colour")) // in case of a SLA print
#if ENABLE_GCODE_VIEWER
if (wxGetApp().is_gcode_viewer() && result != nullptr)
return result->extruder_colors;
else {
#endif // ENABLE_GCODE_VIEWER
const Slic3r::DynamicPrintConfig* config = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
std::vector<std::string> extruder_colors;
if (!config->has("extruder_colour")) // in case of a SLA print
return extruder_colors;
extruder_colors = (config->option<ConfigOptionStrings>("extruder_colour"))->values;
if (!wxGetApp().plater())
return extruder_colors;
const std::vector<std::string>& filament_colours = (p->config->option<ConfigOptionStrings>("filament_colour"))->values;
for (size_t i = 0; i < extruder_colors.size(); ++i)
if (extruder_colors[i] == "" && i < filament_colours.size())
extruder_colors[i] = filament_colours[i];
return extruder_colors;
extruder_colors = (config->option<ConfigOptionStrings>("extruder_colour"))->values;
if (!wxGetApp().plater())
return extruder_colors;
const std::vector<std::string>& filament_colours = (p->config->option<ConfigOptionStrings>("filament_colour"))->values;
for (size_t i = 0; i < extruder_colors.size(); ++i)
if (extruder_colors[i] == "" && i < filament_colours.size())
extruder_colors[i] = filament_colours[i];
return extruder_colors;
#if ENABLE_GCODE_VIEWER
}
#endif // ENABLE_GCODE_VIEWER
}
/* Get vector of colors used for rendering of a Preview scene in "Color print" mode
* It consists of extruder colors and colors, saved in model.custom_gcode_per_print_z
*/
#if ENABLE_GCODE_VIEWER
std::vector<std::string> Plater::get_colors_for_color_print(const GCodeProcessor::Result* const result) const
{
std::vector<std::string> colors = get_extruder_colors_from_plater_config(result);
#else
std::vector<std::string> Plater::get_colors_for_color_print() const
{
std::vector<std::string> colors = get_extruder_colors_from_plater_config();
#endif // ENABLE_GCODE_VIEWER
colors.reserve(colors.size() + p->model.custom_gcode_per_print_z.gcodes.size());
for (const CustomGCode::Item& code : p->model.custom_gcode_per_print_z.gcodes)

View file

@ -11,6 +11,9 @@
#include "libslic3r/Preset.hpp"
#include "libslic3r/BoundingBox.hpp"
#if ENABLE_GCODE_VIEWER
#include "libslic3r/GCode/GCodeProcessor.hpp"
#endif // ENABLE_GCODE_VIEWER
#include "Jobs/Job.hpp"
#include "Search.hpp"
@ -233,8 +236,13 @@ public:
void force_print_bed_update();
// On activating the parent window.
void on_activate();
#if ENABLE_GCODE_VIEWER
std::vector<std::string> get_extruder_colors_from_plater_config(const GCodeProcessor::Result* const result = nullptr) const;
std::vector<std::string> get_colors_for_color_print(const GCodeProcessor::Result* const result = nullptr) const;
#else
std::vector<std::string> get_extruder_colors_from_plater_config() const;
std::vector<std::string> get_colors_for_color_print() const;
#endif // ENABLE_GCODE_VIEWER
void update_object_menu();
void show_action_buttons(const bool is_ready_to_slice) const;