mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 23:17:35 -06:00
Introduction of classes ColorRGB and ColorRGBA to unify color data definition and manipulation
(cherry picked from commit prusa3d/PrusaSlicer@d0bff2d996 )
This commit is contained in:
parent
36ffb18059
commit
28d0147d09
60 changed files with 1290 additions and 1174 deletions
|
@ -90,42 +90,6 @@ static EMoveType buffer_type(unsigned char id) {
|
|||
return static_cast<EMoveType>(static_cast<unsigned char>(EMoveType::Retract) + id);
|
||||
}
|
||||
|
||||
static std::array<float, 4> decode_color(const std::string& color) {
|
||||
static const float INV_255 = 1.0f / 255.0f;
|
||||
|
||||
std::array<float, 4> ret = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
const char* c = color.data() + 1;
|
||||
if (color.size() == 7 && color.front() == '#') {
|
||||
for (size_t j = 0; j < 3; ++j) {
|
||||
int digit1 = hex_digit_to_int(*c++);
|
||||
int digit2 = hex_digit_to_int(*c++);
|
||||
if (digit1 == -1 || digit2 == -1)
|
||||
break;
|
||||
|
||||
ret[j] = float(digit1 * 16 + digit2) * INV_255;
|
||||
}
|
||||
}
|
||||
else if (color.size() == 9 && color.front() == '#') {
|
||||
for (size_t j = 0; j < 4; ++j) {
|
||||
int digit1 = hex_digit_to_int(*c++);
|
||||
int digit2 = hex_digit_to_int(*c++);
|
||||
if (digit1 == -1 || digit2 == -1)
|
||||
break;
|
||||
|
||||
ret[j] = float(digit1 * 16 + digit2) * INV_255;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::vector<std::array<float, 4>> decode_colors(const std::vector<std::string>& colors) {
|
||||
std::vector<std::array<float, 4>> output(colors.size(), { 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
for (size_t i = 0; i < colors.size(); ++i) {
|
||||
output[i] = decode_color(colors[i]);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
// Round to a bin with minimum two digits resolution.
|
||||
// Equivalent to conversion to string with sprintf(buf, "%.2g", value) and conversion back to float, but faster.
|
||||
static float round_to_bin(const float value)
|
||||
|
@ -263,7 +227,7 @@ void GCodeViewer::TBuffer::add_path(const GCodeProcessorResult::MoveVertex& move
|
|||
move.volumetric_rate(), move.layer_duration, move.extruder_id, move.cp_color_id, { { endpoint, endpoint } } });
|
||||
}
|
||||
|
||||
GCodeViewer::Color GCodeViewer::Extrusions::Range::get_color_at(float value) const
|
||||
ColorRGBA GCodeViewer::Extrusions::Range::get_color_at(float value) const
|
||||
{
|
||||
// Input value scaled to the colors range
|
||||
const float step = step_size();
|
||||
|
@ -280,15 +244,8 @@ GCodeViewer::Color GCodeViewer::Extrusions::Range::get_color_at(float value) con
|
|||
const size_t color_low_idx = std::clamp<size_t>(static_cast<size_t>(global_t), 0, color_max_idx);
|
||||
const size_t color_high_idx = std::clamp<size_t>(color_low_idx + 1, 0, color_max_idx);
|
||||
|
||||
// Compute how far the value is between the low and high colors so that they can be interpolated
|
||||
const float local_t = std::clamp(global_t - static_cast<float>(color_low_idx), 0.0f, 1.0f);
|
||||
|
||||
// Interpolate between the low and high colors to find exactly which color the input value should get
|
||||
Color ret = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
for (unsigned int i = 0; i < 3; ++i) {
|
||||
ret[i] = lerp(Range_Colors[color_low_idx][i], Range_Colors[color_high_idx][i], local_t);
|
||||
}
|
||||
return ret;
|
||||
return lerp(Range_Colors[color_low_idx], Range_Colors[color_high_idx], global_t - static_cast<float>(color_low_idx));
|
||||
}
|
||||
|
||||
float GCodeViewer::Extrusions::Range::step_size() const {
|
||||
|
@ -584,11 +541,11 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, f
|
|||
return ret;
|
||||
};
|
||||
|
||||
static const ImVec4 LINE_NUMBER_COLOR = ImGuiWrapper::COL_ORANGE_LIGHT;
|
||||
static const ImVec4 LINE_NUMBER_COLOR = ImGuiWrapper::COL_ORANGE_LIGHT;
|
||||
static const ImVec4 SELECTION_RECT_COLOR = ImGuiWrapper::COL_ORANGE_DARK;
|
||||
static const ImVec4 COMMAND_COLOR = { 0.8f, 0.8f, 0.0f, 1.0f };
|
||||
static const ImVec4 PARAMETERS_COLOR = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
static const ImVec4 COMMENT_COLOR = { 0.7f, 0.7f, 0.7f, 1.0f };
|
||||
static const ImVec4 COMMAND_COLOR = { 0.8f, 0.8f, 0.0f, 1.0f };
|
||||
static const ImVec4 PARAMETERS_COLOR = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
static const ImVec4 COMMENT_COLOR = { 0.7f, 0.7f, 0.7f, 1.0f };
|
||||
|
||||
if (!m_visible || !wxGetApp().show_gcode_window() || m_filename.empty() || m_lines_ends.empty() || curr_line_id == 0)
|
||||
return;
|
||||
|
@ -728,7 +685,7 @@ if (has_render_path)
|
|||
gcode_window.render(legend_height + 2, std::max(10.f, (float)canvas_height - 40), (float)canvas_width - (float)right_margin, static_cast<uint64_t>(gcode_ids[current.last]));
|
||||
}
|
||||
|
||||
const std::vector<GCodeViewer::Color> GCodeViewer::Extrusion_Role_Colors {{
|
||||
const std::vector<ColorRGBA> GCodeViewer::Extrusion_Role_Colors{ {
|
||||
{ 0.90f, 0.70f, 0.70f, 1.0f }, // erNone
|
||||
{ 1.00f, 0.90f, 0.30f, 1.0f }, // erPerimeter
|
||||
{ 1.00f, 0.49f, 0.22f, 1.0f }, // erExternalPerimeter
|
||||
|
@ -750,7 +707,7 @@ const std::vector<GCodeViewer::Color> GCodeViewer::Extrusion_Role_Colors {{
|
|||
{ 0.37f, 0.82f, 0.58f, 1.0f } // erCustom
|
||||
}};
|
||||
|
||||
const std::vector<GCodeViewer::Color> GCodeViewer::Options_Colors {{
|
||||
const std::vector<ColorRGBA> GCodeViewer::Options_Colors{ {
|
||||
{ 0.803f, 0.135f, 0.839f, 1.0f }, // Retractions
|
||||
{ 0.287f, 0.679f, 0.810f, 1.0f }, // Unretractions
|
||||
{ 0.900f, 0.900f, 0.900f, 1.0f }, // Seams
|
||||
|
@ -760,7 +717,7 @@ const std::vector<GCodeViewer::Color> GCodeViewer::Options_Colors {{
|
|||
{ 0.886f, 0.825f, 0.262f, 1.0f } // CustomGCodes
|
||||
}};
|
||||
|
||||
const std::vector<GCodeViewer::Color> GCodeViewer::Travel_Colors {{
|
||||
const std::vector<ColorRGBA> GCodeViewer::Travel_Colors{ {
|
||||
{ 0.219f, 0.282f, 0.609f, 1.0f }, // Move
|
||||
{ 0.112f, 0.422f, 0.103f, 1.0f }, // Extrude
|
||||
{ 0.505f, 0.064f, 0.028f, 1.0f } // Retract
|
||||
|
@ -768,7 +725,7 @@ const std::vector<GCodeViewer::Color> GCodeViewer::Travel_Colors {{
|
|||
|
||||
// Normal ranges
|
||||
// blue to red
|
||||
const std::vector<GCodeViewer::Color> GCodeViewer::Range_Colors{{
|
||||
const std::vector<ColorRGBA> GCodeViewer::Range_Colors{ {
|
||||
decode_color_to_float_array("#0b2c7a"), // bluish
|
||||
decode_color_to_float_array("#135985"),
|
||||
decode_color_to_float_array("#1c8891"),
|
||||
|
@ -782,8 +739,8 @@ const std::vector<GCodeViewer::Color> GCodeViewer::Range_Colors{{
|
|||
decode_color_to_float_array("#942616") // reddish
|
||||
}};
|
||||
|
||||
const GCodeViewer::Color GCodeViewer::Wipe_Color = { 1.0f, 1.0f, 0.0f, 1.0f };
|
||||
const GCodeViewer::Color GCodeViewer::Neutral_Color = { 0.25f, 0.25f, 0.25f, 1.0f };
|
||||
const ColorRGBA GCodeViewer::Wipe_Color = ColorRGBA::YELLOW();
|
||||
const ColorRGBA GCodeViewer::Neutral_Color = ColorRGBA::DARK_GRAY();
|
||||
|
||||
GCodeViewer::GCodeViewer()
|
||||
{
|
||||
|
@ -1140,13 +1097,13 @@ void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::v
|
|||
|
||||
if (m_view_type == EViewType::Tool && !gcode_result.extruder_colors.empty()) {
|
||||
// update tool colors from config stored in the gcode
|
||||
m_tools.m_tool_colors = decode_colors(gcode_result.extruder_colors);
|
||||
decode_colors(gcode_result.extruder_colors, m_tools.m_tool_colors);
|
||||
m_tools.m_tool_visibles = std::vector<bool>(m_tools.m_tool_colors.size());
|
||||
for (auto item: m_tools.m_tool_visibles) item = true;
|
||||
}
|
||||
else {
|
||||
// update tool colors
|
||||
m_tools.m_tool_colors = decode_colors(str_tool_colors);
|
||||
decode_colors(str_tool_colors, m_tools.m_tool_colors);
|
||||
m_tools.m_tool_visibles = std::vector<bool>(m_tools.m_tool_colors.size());
|
||||
for (auto item : m_tools.m_tool_visibles) item = true;
|
||||
}
|
||||
|
@ -1154,9 +1111,11 @@ void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::v
|
|||
for (int i = 0; i < m_tools.m_tool_colors.size(); i++) {
|
||||
m_tools.m_tool_colors[i] = adjust_color_for_rendering(m_tools.m_tool_colors[i]);
|
||||
}
|
||||
// ensure there are enough colors defined
|
||||
ColorRGBA default_color;
|
||||
decode_color("#FF8000", default_color);
|
||||
// ensure there are enough colors defined
|
||||
while (m_tools.m_tool_colors.size() < std::max(size_t(1), gcode_result.extruders_count)) {
|
||||
m_tools.m_tool_colors.push_back(decode_color("#FF8000"));
|
||||
m_tools.m_tool_colors.push_back(default_color);
|
||||
m_tools.m_tool_visibles.push_back(true);
|
||||
}
|
||||
|
||||
|
@ -1247,7 +1206,7 @@ void GCodeViewer::reset()
|
|||
m_paths_bounding_box = BoundingBoxf3();
|
||||
m_max_bounding_box = BoundingBoxf3();
|
||||
m_max_print_height = 0.0f;
|
||||
m_tools.m_tool_colors = std::vector<Color>();
|
||||
m_tools.m_tool_colors = std::vector<ColorRGBA>();
|
||||
m_tools.m_tool_visibles = std::vector<bool>();
|
||||
m_extruders_count = 0;
|
||||
m_extruder_ids = std::vector<unsigned char>();
|
||||
|
@ -1904,7 +1863,7 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const
|
|||
return;
|
||||
|
||||
// collect color information to generate materials
|
||||
std::vector<Color> colors;
|
||||
std::vector<ColorRGBA> colors;
|
||||
for (const RenderPath& path : t_buffer.render_paths) {
|
||||
colors.push_back(path.color);
|
||||
}
|
||||
|
@ -1926,10 +1885,10 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const
|
|||
fprintf(fp, "# Generated by %s-%s based on Slic3r\n", SLIC3R_APP_NAME, SoftFever_VERSION);
|
||||
|
||||
unsigned int colors_count = 1;
|
||||
for (const Color& color : colors) {
|
||||
for (const ColorRGBA& color : colors) {
|
||||
fprintf(fp, "\nnewmtl material_%d\n", colors_count++);
|
||||
fprintf(fp, "Ka 1 1 1\n");
|
||||
fprintf(fp, "Kd %g %g %g\n", color[0], color[1], color[2]);
|
||||
fprintf(fp, "Kd %g %g %g\n", color.r(), color.g(), color.b());
|
||||
fprintf(fp, "Ks 0 0 0\n");
|
||||
}
|
||||
|
||||
|
@ -1990,7 +1949,7 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const
|
|||
}
|
||||
|
||||
size_t i = 0;
|
||||
for (const Color& color : colors) {
|
||||
for (const ColorRGBA& color : colors) {
|
||||
// save material triangles to file
|
||||
fprintf(fp, "\nusemtl material_%zu\n", i + 1);
|
||||
fprintf(fp, "# triangles material %zu\n", i + 1);
|
||||
|
@ -3231,7 +3190,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized, bool force_p
|
|||
|
||||
for (GLVolume* volume : m_shells.volumes.volumes) {
|
||||
volume->zoom_to_volumes = false;
|
||||
volume->color[3] = 0.5f;
|
||||
volume->color.a(0.5f);
|
||||
volume->force_native_color = true;
|
||||
volume->set_render_color();
|
||||
//BBS: add shell bounding box logic
|
||||
|
@ -3254,7 +3213,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
|
|||
|
||||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": enter, m_buffers size %1%!")%m_buffers.size();
|
||||
auto extrusion_color = [this](const Path& path) {
|
||||
Color color;
|
||||
ColorRGBA color;
|
||||
switch (m_view_type)
|
||||
{
|
||||
case EViewType::FeatureType: { color = Extrusion_Role_Colors[static_cast<unsigned int>(path.role)]; break; }
|
||||
|
@ -3269,7 +3228,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
|
|||
case EViewType::Tool: { color = m_tools.m_tool_colors[path.extruder_id]; break; }
|
||||
case EViewType::ColorPrint: {
|
||||
if (path.cp_color_id >= static_cast<unsigned char>(m_tools.m_tool_colors.size()))
|
||||
color = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
color = ColorRGBA::GRAY();
|
||||
else {
|
||||
color = m_tools.m_tool_colors[path.cp_color_id];
|
||||
color = adjust_color_for_rendering(color);
|
||||
|
@ -3282,7 +3241,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
|
|||
color = {id, role, id, 1.0f};
|
||||
break;
|
||||
}
|
||||
default: { color = { 1.0f, 1.0f, 1.0f, 1.0f }; break; }
|
||||
default: { color = ColorRGBA::WHITE(); break; }
|
||||
}
|
||||
|
||||
return color;
|
||||
|
@ -3515,7 +3474,7 @@ m_no_render_path = false;
|
|||
if (m_sequential_view.current.last < sub_path.first.s_id || sub_path.last.s_id < m_sequential_view.current.first)
|
||||
continue;
|
||||
|
||||
Color color;
|
||||
ColorRGBA color;
|
||||
switch (path.type)
|
||||
{
|
||||
case EMoveType::Tool_change:
|
||||
|
@ -4168,7 +4127,8 @@ void GCodeViewer::render_all_plates_stats(const std::vector<const GCodeProcessor
|
|||
|
||||
std::vector<float> filament_diameters = gcode_result_list.front()->filament_diameters;
|
||||
std::vector<float> filament_densities = gcode_result_list.front()->filament_densities;
|
||||
std::vector<Color> filament_colors = decode_colors(wxGetApp().plater()->get_extruder_colors_from_plater_config(gcode_result_list.back()));
|
||||
std::vector<ColorRGBA> filament_colors;
|
||||
decode_colors(wxGetApp().plater()->get_extruder_colors_from_plater_config(gcode_result_list.back()), filament_colors);
|
||||
|
||||
for (int i = 0; i < filament_colors.size(); i++) {
|
||||
filament_colors[i] = adjust_color_for_rendering(filament_colors[i]);
|
||||
|
@ -4213,13 +4173,13 @@ void GCodeViewer::render_all_plates_stats(const std::vector<const GCodeProcessor
|
|||
|
||||
return ret;
|
||||
};
|
||||
auto append_item = [icon_size, &imgui, imperial_units, &window_padding, &draw_list, this](const Color& color, const std::vector<std::pair<std::string, float>>& columns_offsets)
|
||||
auto append_item = [icon_size, &imgui, imperial_units, &window_padding, &draw_list, this](const ColorRGBA& color, const std::vector<std::pair<std::string, float>>& columns_offsets)
|
||||
{
|
||||
// render icon
|
||||
ImVec2 pos = ImVec2(ImGui::GetCursorScreenPos().x + window_padding * 3, ImGui::GetCursorScreenPos().y);
|
||||
|
||||
draw_list->AddRectFilled({ pos.x + 1.0f * m_scale, pos.y + 3.0f * m_scale }, { pos.x + icon_size - 1.0f * m_scale, pos.y + icon_size + 1.0f * m_scale },
|
||||
ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }));
|
||||
ImGuiWrapper::to_ImU32(color));
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20.0 * m_scale, 6.0 * m_scale));
|
||||
|
||||
|
@ -4425,7 +4385,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
|
||||
auto append_item = [icon_size, &imgui, imperial_units, &window_padding, &draw_list, this](
|
||||
EItemType type,
|
||||
const Color& color,
|
||||
const ColorRGBA& color,
|
||||
const std::vector<std::pair<std::string, float>>& columns_offsets,
|
||||
bool checkbox = true,
|
||||
bool visible = true,
|
||||
|
@ -4437,21 +4397,21 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
default:
|
||||
case EItemType::Rect: {
|
||||
draw_list->AddRectFilled({ pos.x + 1.0f * m_scale, pos.y + 3.0f * m_scale }, { pos.x + icon_size - 1.0f * m_scale, pos.y + icon_size + 1.0f * m_scale },
|
||||
ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }));
|
||||
ImGuiWrapper::to_ImU32(color));
|
||||
break;
|
||||
}
|
||||
case EItemType::Circle: {
|
||||
ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size + 5.0f));
|
||||
draw_list->AddCircleFilled(center, 0.5f * icon_size, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
||||
draw_list->AddCircleFilled(center, 0.5f * icon_size, ImGuiWrapper::to_ImU32(color), 16);
|
||||
break;
|
||||
}
|
||||
case EItemType::Hexagon: {
|
||||
ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size + 5.0f));
|
||||
draw_list->AddNgonFilled(center, 0.5f * icon_size, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 6);
|
||||
draw_list->AddNgonFilled(center, 0.5f * icon_size, ImGuiWrapper::to_ImU32(color), 6);
|
||||
break;
|
||||
}
|
||||
case EItemType::Line: {
|
||||
draw_list->AddLine({ pos.x + 1, pos.y + icon_size + 2 }, { pos.x + icon_size - 1, pos.y + 4 }, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 3.0f);
|
||||
draw_list->AddLine({ pos.x + 1, pos.y + icon_size + 2 }, { pos.x + icon_size - 1, pos.y + 4 }, ImGuiWrapper::to_ImU32(color), 3.0f);
|
||||
break;
|
||||
case EItemType::None:
|
||||
break;
|
||||
|
@ -4567,7 +4527,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
};
|
||||
|
||||
auto color_print_ranges = [this](unsigned char extruder_id, const std::vector<CustomGCode::Item>& custom_gcode_per_print_z) {
|
||||
std::vector<std::pair<Color, std::pair<double, double>>> ret;
|
||||
std::vector<std::pair<ColorRGBA, std::pair<double, double>>> ret;
|
||||
ret.reserve(custom_gcode_per_print_z.size());
|
||||
|
||||
for (const auto& item : custom_gcode_per_print_z) {
|
||||
|
@ -4587,7 +4547,11 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
|
||||
// to avoid duplicate values, check adding values
|
||||
if (ret.empty() || !(ret.back().second.first == previous_z && ret.back().second.second == current_z))
|
||||
ret.push_back({ decode_color(item.color), { previous_z, current_z } });
|
||||
{
|
||||
ColorRGBA color;
|
||||
decode_color(item.color, color);
|
||||
ret.push_back({ color, { previous_z, current_z } });
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -4834,7 +4798,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
}
|
||||
|
||||
auto append_option_item = [this, append_item](EMoveType type, std::vector<float> offsets) {
|
||||
auto append_option_item_with_type = [this, offsets, append_item](EMoveType type, const Color& color, const std::string& label, bool visible) {
|
||||
auto append_option_item_with_type = [this, offsets, append_item](EMoveType type, const ColorRGBA& color, const std::string& label, bool visible) {
|
||||
append_item(EItemType::Rect, color, {{ label , offsets[0] }}, true, visible, [this, type, visible]() {
|
||||
m_buffers[buffer_id(type)].visible = !m_buffers[buffer_id(type)].visible;
|
||||
// update buffers' render paths
|
||||
|
@ -4958,7 +4922,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
if (need_scrollable)
|
||||
ImGui::BeginChild("color_prints", { -1.0f, child_height }, false);
|
||||
if (m_extruder_ids.size() == 1) { // single extruder use case
|
||||
const std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(0, custom_gcode_per_print_z);
|
||||
const std::vector<std::pair<ColorRGBA, 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());
|
||||
auto extruder_idx = m_extruder_ids[0];
|
||||
if (items_cnt == 0) { // There are no color changes, but there are some pause print or custom Gcode
|
||||
|
@ -4990,7 +4954,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
// shows only extruders actually used
|
||||
size_t i = 0;
|
||||
for (auto extruder_idx : m_extruder_ids) {
|
||||
const std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(extruder_idx, custom_gcode_per_print_z);
|
||||
const std::vector<std::pair<ColorRGBA, std::pair<double, double>>> cp_values = color_print_ranges(extruder_idx, 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
|
||||
const bool filament_visible = m_tools.m_tool_visibles[extruder_idx];
|
||||
|
@ -5119,8 +5083,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
};
|
||||
EType type;
|
||||
int extruder_id;
|
||||
Color color1;
|
||||
Color color2;
|
||||
ColorRGBA color1;
|
||||
ColorRGBA color2;
|
||||
Times times;
|
||||
std::pair<double, double> used_filament {0.0f, 0.0f};
|
||||
};
|
||||
|
@ -5131,7 +5095,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
|
||||
//BBS: replace model custom gcode with current plate custom gcode
|
||||
std::vector<CustomGCode::Item> custom_gcode_per_print_z = wxGetApp().is_editor() ? wxGetApp().plater()->model().get_curr_plate_custom_gcodes().gcodes : m_custom_gcode_per_print_z;
|
||||
std::vector<Color> last_color(m_extruders_count);
|
||||
std::vector<ColorRGBA> last_color(m_extruders_count);
|
||||
for (size_t i = 0; i < m_extruders_count; ++i) {
|
||||
last_color[i] = m_tools.m_tool_colors[i];
|
||||
}
|
||||
|
@ -5143,8 +5107,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
case CustomGCode::PausePrint: {
|
||||
auto it = std::find_if(custom_gcode_per_print_z.begin(), custom_gcode_per_print_z.end(), [time_rec](const CustomGCode::Item& item) { return item.type == time_rec.first; });
|
||||
if (it != custom_gcode_per_print_z.end()) {
|
||||
items.push_back({ PartialTime::EType::Print, it->extruder, last_color[it->extruder - 1], Color(), time_rec.second });
|
||||
items.push_back({ PartialTime::EType::Pause, it->extruder, Color(), Color(), time_rec.second });
|
||||
items.push_back({ PartialTime::EType::Print, it->extruder, last_color[it->extruder - 1], ColorRGBA::BLACK(), time_rec.second });
|
||||
items.push_back({ PartialTime::EType::Pause, it->extruder, ColorRGBA::BLACK(), ColorRGBA::BLACK(), time_rec.second });
|
||||
custom_gcode_per_print_z.erase(it);
|
||||
}
|
||||
break;
|
||||
|
@ -5152,14 +5116,16 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
case CustomGCode::ColorChange: {
|
||||
auto it = std::find_if(custom_gcode_per_print_z.begin(), custom_gcode_per_print_z.end(), [time_rec](const CustomGCode::Item& item) { return item.type == time_rec.first; });
|
||||
if (it != custom_gcode_per_print_z.end()) {
|
||||
items.push_back({ PartialTime::EType::Print, it->extruder, last_color[it->extruder - 1], Color(), time_rec.second, get_used_filament_from_volume(used_filaments[color_change_idx++], it->extruder-1) });
|
||||
items.push_back({ PartialTime::EType::ColorChange, it->extruder, last_color[it->extruder - 1], decode_color(it->color), time_rec.second });
|
||||
last_color[it->extruder - 1] = decode_color(it->color);
|
||||
items.push_back({ PartialTime::EType::Print, it->extruder, last_color[it->extruder - 1], ColorRGBA::BLACK(), time_rec.second, get_used_filament_from_volume(used_filaments[color_change_idx++], it->extruder - 1) });
|
||||
ColorRGBA color;
|
||||
decode_color(it->color, color);
|
||||
items.push_back({ PartialTime::EType::ColorChange, it->extruder, last_color[it->extruder - 1], color, time_rec.second });
|
||||
last_color[it->extruder - 1] = color;
|
||||
last_extruder_id = it->extruder;
|
||||
custom_gcode_per_print_z.erase(it);
|
||||
}
|
||||
else
|
||||
items.push_back({ PartialTime::EType::Print, last_extruder_id, last_color[last_extruder_id - 1], Color(), time_rec.second, get_used_filament_from_volume(used_filaments[color_change_idx++], last_extruder_id -1) });
|
||||
items.push_back({ PartialTime::EType::Print, last_extruder_id, last_color[last_extruder_id - 1], ColorRGBA::BLACK(), time_rec.second, get_used_filament_from_volume(used_filaments[color_change_idx++], last_extruder_id - 1) });
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -5170,7 +5136,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
return items;
|
||||
};
|
||||
|
||||
auto append_color_change = [&imgui](const Color& color1, const Color& color2, const std::array<float, 4>& offsets, const Times& times) {
|
||||
auto append_color_change = [&imgui](const ColorRGBA& color1, const ColorRGBA& color2, const std::array<float, 4>& offsets, const Times& times) {
|
||||
imgui.text(_u8L("Color change"));
|
||||
ImGui::SameLine();
|
||||
|
||||
|
@ -5180,16 +5146,16 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
pos.x -= 0.5f * ImGui::GetStyle().ItemSpacing.x;
|
||||
|
||||
draw_list->AddRectFilled({ pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f },
|
||||
ImGui::GetColorU32({ color1[0], color1[1], color1[2], 1.0f }));
|
||||
ImGuiWrapper::to_ImU32(color1));
|
||||
pos.x += icon_size;
|
||||
draw_list->AddRectFilled({ pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f },
|
||||
ImGui::GetColorU32({ color2[0], color2[1], color2[2], 1.0f }));
|
||||
ImGuiWrapper::to_ImU32(color2));
|
||||
|
||||
ImGui::SameLine(offsets[0]);
|
||||
imgui.text(short_time(get_time_dhms(times.second - times.first)));
|
||||
};
|
||||
|
||||
auto append_print = [&imgui, imperial_units](const Color& color, const std::array<float, 4>& offsets, const Times& times, std::pair<double, double> used_filament) {
|
||||
auto append_print = [&imgui, imperial_units](const ColorRGBA& color, const std::array<float, 4>& offsets, const Times& times, std::pair<double, double> used_filament) {
|
||||
imgui.text(_u8L("Print"));
|
||||
ImGui::SameLine();
|
||||
|
||||
|
@ -5199,7 +5165,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
pos.x -= 0.5f * ImGui::GetStyle().ItemSpacing.x;
|
||||
|
||||
draw_list->AddRectFilled({ pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f },
|
||||
ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }));
|
||||
ImGuiWrapper::to_ImU32(color));
|
||||
|
||||
ImGui::SameLine(offsets[0]);
|
||||
imgui.text(short_time(get_time_dhms(times.second)));
|
||||
|
@ -5713,7 +5679,7 @@ void GCodeViewer::log_memory_used(const std::string& label, int64_t additional)
|
|||
}
|
||||
}
|
||||
|
||||
GCodeViewer::Color GCodeViewer::option_color(EMoveType move_type) const
|
||||
ColorRGBA GCodeViewer::option_color(EMoveType move_type) const
|
||||
{
|
||||
switch (move_type)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue