mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-23 16:51:21 -06:00
Fixed import of color print view from gcode files into GCodeViewer
This commit is contained in:
parent
9cd61c7d0b
commit
8ebb2e2a29
10 changed files with 155 additions and 3 deletions
|
|
@ -1551,6 +1551,9 @@ void Control::OnMotion(wxMouseEvent& event)
|
|||
event.Skip();
|
||||
|
||||
// Set tooltips with information for each icon
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
if (GUI::wxGetApp().is_editor())
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
this->SetToolTip(get_tooltip(tick));
|
||||
|
||||
if (action) {
|
||||
|
|
|
|||
|
|
@ -586,6 +586,11 @@ void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print&
|
|||
m_sequential_view.gcode_window.set_filename(gcode_result.filename);
|
||||
m_sequential_view.gcode_window.load_gcode();
|
||||
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
if (wxGetApp().is_gcode_viewer())
|
||||
m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z;
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
|
||||
load_toolpaths(gcode_result);
|
||||
|
||||
if (m_layers.empty())
|
||||
|
|
@ -743,6 +748,9 @@ void GCodeViewer::reset()
|
|||
m_layers_z_range = { 0, 0 };
|
||||
m_roles = std::vector<ExtrusionRole>();
|
||||
m_print_statistics.reset();
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
m_custom_gcode_per_print_z = std::vector<CustomGCode::Item>();
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
m_sequential_view.gcode_window.reset();
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
m_statistics.reset_all();
|
||||
|
|
@ -2939,7 +2947,11 @@ void GCodeViewer::render_legend(float& legend_height) const
|
|||
}
|
||||
case EViewType::ColorPrint:
|
||||
{
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
const std::vector<CustomGCode::Item>& custom_gcode_per_print_z = wxGetApp().is_editor() ? wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes : m_custom_gcode_per_print_z;
|
||||
#else
|
||||
const std::vector<CustomGCode::Item>& custom_gcode_per_print_z = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
size_t total_items = 1;
|
||||
for (unsigned char i : m_extruder_ids) {
|
||||
total_items += color_print_ranges(i, custom_gcode_per_print_z).size();
|
||||
|
|
@ -3034,7 +3046,11 @@ void GCodeViewer::render_legend(float& legend_height) const
|
|||
auto generate_partial_times = [this, get_used_filament_from_volume](const TimesList& times, const std::vector<double>& used_filaments) {
|
||||
PartialTimes items;
|
||||
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
std::vector<CustomGCode::Item> custom_gcode_per_print_z = wxGetApp().is_editor() ? wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes : m_custom_gcode_per_print_z;
|
||||
#else
|
||||
std::vector<CustomGCode::Item> custom_gcode_per_print_z = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
int extruders_count = wxGetApp().extruders_edited_cnt();
|
||||
std::vector<Color> last_color(extruders_count);
|
||||
for (int i = 0; i < extruders_count; ++i) {
|
||||
|
|
|
|||
|
|
@ -616,6 +616,10 @@ private:
|
|||
GCodeProcessor::Result::SettingsIds m_settings_ids;
|
||||
std::array<SequentialRangeCap, 2> m_sequential_range_caps;
|
||||
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
std::vector<CustomGCode::Item> m_custom_gcode_per_print_z;
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
|
||||
public:
|
||||
GCodeViewer();
|
||||
~GCodeViewer() { reset(); }
|
||||
|
|
@ -665,6 +669,10 @@ public:
|
|||
void stop_mapping_gcode_window();
|
||||
void toggle_gcode_window_visibility() { m_sequential_view.gcode_window.toggle_visibility(); }
|
||||
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
std::vector<CustomGCode::Item>& get_custom_gcode_per_print_z() { return m_custom_gcode_per_print_z; }
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
|
||||
private:
|
||||
void load_toolpaths(const GCodeProcessor::Result& gcode_result);
|
||||
void load_shells(const Print& print, bool initialized);
|
||||
|
|
|
|||
|
|
@ -634,6 +634,9 @@ public:
|
|||
void set_toolpath_view_type(GCodeViewer::EViewType type);
|
||||
void set_volumes_z_range(const std::array<double, 2>& range);
|
||||
void set_toolpaths_z_range(const std::array<unsigned int, 2>& range);
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
std::vector<CustomGCode::Item>& get_custom_gcode_per_print_z() { return m_gcode_viewer.get_custom_gcode_per_print_z(); }
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
|
||||
std::vector<int> load_object(const ModelObject& model_object, int obj_idx, std::vector<int> instance_idxs);
|
||||
std::vector<int> load_object(const Model& model, int obj_idx);
|
||||
|
|
|
|||
|
|
@ -637,11 +637,25 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
|
|||
update_layers_slider_mode();
|
||||
|
||||
Plater* plater = wxGetApp().plater();
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
CustomGCode::Info ticks_info_from_model;
|
||||
if (wxGetApp().is_editor())
|
||||
ticks_info_from_model = plater->model().custom_gcode_per_print_z;
|
||||
else {
|
||||
ticks_info_from_model.mode = CustomGCode::Mode::SingleExtruder;
|
||||
ticks_info_from_model.gcodes = m_canvas->get_custom_gcode_per_print_z();
|
||||
}
|
||||
#else
|
||||
CustomGCode::Info& ticks_info_from_model = plater->model().custom_gcode_per_print_z;
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
check_layers_slider_values(ticks_info_from_model.gcodes, layers_z);
|
||||
|
||||
//first of all update extruder colors to avoid crash, when we are switching printer preset from MM to SM
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
m_layers_slider->SetExtruderColors(plater->get_extruder_colors_from_plater_config(wxGetApp().is_editor() ? nullptr : m_gcode_result));
|
||||
#else
|
||||
m_layers_slider->SetExtruderColors(plater->get_extruder_colors_from_plater_config());
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
|
||||
m_layers_slider->SetSliderValues(layers_z);
|
||||
assert(m_layers_slider->GetMinValue() == 0);
|
||||
|
|
@ -904,7 +918,14 @@ void Preview::load_print_as_fff(bool keep_z_range)
|
|||
colors = wxGetApp().plater()->get_colors_for_color_print(m_gcode_result);
|
||||
|
||||
if (!gcode_preview_data_valid) {
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
if (wxGetApp().is_editor())
|
||||
color_print_values = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
|
||||
else
|
||||
color_print_values = m_canvas->get_custom_gcode_per_print_z();
|
||||
#else
|
||||
color_print_values = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
colors.push_back("#808080"); // gray color for pause print or custom G-code
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6059,9 +6059,22 @@ std::vector<std::string> Plater::get_colors_for_color_print(const GCodeProcessor
|
|||
std::vector<std::string> colors = get_extruder_colors_from_plater_config(result);
|
||||
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)
|
||||
if (code.type == CustomGCode::ColorChange)
|
||||
colors.emplace_back(code.color);
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
if (wxGetApp().is_gcode_viewer() && result != nullptr) {
|
||||
for (const CustomGCode::Item& code : result->custom_gcode_per_print_z) {
|
||||
if (code.type == CustomGCode::ColorChange)
|
||||
colors.emplace_back(code.color);
|
||||
}
|
||||
}
|
||||
else {
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
for (const CustomGCode::Item& code : p->model.custom_gcode_per_print_z.gcodes) {
|
||||
if (code.type == CustomGCode::ColorChange)
|
||||
colors.emplace_back(code.color);
|
||||
}
|
||||
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
}
|
||||
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue