2018-02-14 19:38:03 +00:00
|
|
|
#include "Analyzer.hpp"
|
|
|
|
#include "PreviewData.hpp"
|
2018-02-14 20:57:46 +00:00
|
|
|
#include <float.h>
|
2018-06-20 16:55:31 +00:00
|
|
|
#include <I18N.hpp>
|
2018-12-18 14:55:45 +00:00
|
|
|
#include "Utils.hpp"
|
2018-06-20 16:55:31 +00:00
|
|
|
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
|
|
|
//! macro used to mark string used at localization,
|
|
|
|
#define L(s) (s)
|
2018-02-14 19:38:03 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
std::vector<unsigned char> Color::as_bytes() const
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
|
|
|
std::vector<unsigned char> ret;
|
|
|
|
for (unsigned int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
ret.push_back((unsigned char)(255.0f * rgba[i]));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-30 14:25:26 +00:00
|
|
|
GCodePreviewData::Extrusion::Layer::Layer(float z, const Paths& paths)
|
2018-02-14 19:38:03 +00:00
|
|
|
: z(z)
|
|
|
|
, paths(paths)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GCodePreviewData::Travel::Polyline::Polyline(EType type, EDirection direction, float feedrate, unsigned int extruder_id, const Polyline3& polyline)
|
|
|
|
: type(type)
|
|
|
|
, direction(direction)
|
|
|
|
, feedrate(feedrate)
|
|
|
|
, extruder_id(extruder_id)
|
|
|
|
, polyline(polyline)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GCodePreviewData::Range::Range()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GCodePreviewData::Range::reset()
|
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
min_val = FLT_MAX;
|
|
|
|
max_val = -FLT_MAX;
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GCodePreviewData::Range::empty() const
|
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
return min_val >= max_val;
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GCodePreviewData::Range::update_from(float value)
|
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
min_val = std::min(min_val, value);
|
|
|
|
max_val = std::max(max_val, value);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
void GCodePreviewData::Range::update_from(const RangeBase& other)
|
2018-03-06 11:12:00 +00:00
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
min_val = std::min(min_val, other.min());
|
|
|
|
max_val = std::max(max_val, other.max());
|
2018-03-06 11:12:00 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
float GCodePreviewData::RangeBase::step_size() const
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
return (max() - min()) / static_cast<float>(range_rainbow_colors.size() - 1);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color GCodePreviewData::RangeBase::get_color_at(float value) const
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
2018-04-27 07:54:21 +00:00
|
|
|
if (empty())
|
2019-12-08 00:31:28 +00:00
|
|
|
return Color{};
|
2018-04-27 07:54:21 +00:00
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
// Input value scaled to the color range
|
|
|
|
const float global_t = std::max(0.0f, value - min()) / step_size(); // lower limit of 0.0f
|
|
|
|
|
|
|
|
constexpr std::size_t color_max_idx = range_rainbow_colors.size() - 1;
|
2018-04-27 07:54:21 +00:00
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
// Compute the two colors just below (low) and above (high) the input value
|
|
|
|
const std::size_t color_low_idx = clamp(std::size_t{0}, color_max_idx, static_cast<std::size_t>(global_t));
|
|
|
|
const std::size_t color_high_idx = clamp(std::size_t{0}, color_max_idx, color_low_idx + 1);
|
|
|
|
const Color color_low = range_rainbow_colors[color_low_idx];
|
|
|
|
const Color color_high = range_rainbow_colors[color_high_idx];
|
2018-04-27 07:54:21 +00:00
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
// Compute how far the value is between the low and high colors so that they can be interpolated
|
|
|
|
const float local_t = std::min(global_t - static_cast<float>(color_low_idx), 1.0f); // upper limit of 1.0f
|
2018-04-27 07:54:21 +00:00
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
// Interpolate between the low and high colors in RGB space to find exactly which color the input value should get
|
2018-04-27 07:54:21 +00:00
|
|
|
Color ret;
|
|
|
|
for (unsigned int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
ret.rgba[i] = lerp(color_low.rgba[i], color_high.rgba[i], local_t);
|
|
|
|
}
|
|
|
|
return ret;
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
float GCodePreviewData::Range::min() const
|
|
|
|
{
|
|
|
|
return min_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GCodePreviewData::Range::max() const
|
|
|
|
{
|
|
|
|
return max_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
GCodePreviewData::LegendItem::LegendItem(const std::string& text, const Color& color)
|
2018-02-14 19:38:03 +00:00
|
|
|
: text(text)
|
|
|
|
, color(color)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
const Color GCodePreviewData::Extrusion::Default_Extrusion_Role_Colors[erCount] =
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
|
|
|
Color(0.0f, 0.0f, 0.0f, 1.0f), // erNone
|
|
|
|
Color(1.0f, 0.0f, 0.0f, 1.0f), // erPerimeter
|
|
|
|
Color(0.0f, 1.0f, 0.0f, 1.0f), // erExternalPerimeter
|
|
|
|
Color(0.0f, 0.0f, 1.0f, 1.0f), // erOverhangPerimeter
|
|
|
|
Color(1.0f, 1.0f, 0.0f, 1.0f), // erInternalInfill
|
|
|
|
Color(1.0f, 0.0f, 1.0f, 1.0f), // erSolidInfill
|
|
|
|
Color(0.0f, 1.0f, 1.0f, 1.0f), // erTopSolidInfill
|
|
|
|
Color(0.5f, 0.5f, 0.5f, 1.0f), // erBridgeInfill
|
|
|
|
Color(1.0f, 1.0f, 1.0f, 1.0f), // erGapFill
|
|
|
|
Color(0.5f, 0.0f, 0.0f, 1.0f), // erSkirt
|
|
|
|
Color(0.0f, 0.5f, 0.0f, 1.0f), // erSupportMaterial
|
|
|
|
Color(0.0f, 0.0f, 0.5f, 1.0f), // erSupportMaterialInterface
|
|
|
|
Color(0.7f, 0.89f, 0.67f, 1.0f), // erWipeTower
|
2018-02-22 07:59:47 +00:00
|
|
|
Color(1.0f, 1.0f, 0.0f, 1.0f), // erCustom
|
2018-02-14 19:38:03 +00:00
|
|
|
Color(0.0f, 0.0f, 0.0f, 1.0f) // erMixed
|
|
|
|
};
|
|
|
|
|
|
|
|
const GCodePreviewData::Extrusion::EViewType GCodePreviewData::Extrusion::Default_View_Type = GCodePreviewData::Extrusion::FeatureType;
|
|
|
|
|
|
|
|
void GCodePreviewData::Extrusion::set_default()
|
|
|
|
{
|
|
|
|
view_type = Default_View_Type;
|
|
|
|
|
2019-09-06 12:58:04 +00:00
|
|
|
::memcpy((void*)role_colors, (const void*)Default_Extrusion_Role_Colors, erCount * sizeof(Color));
|
2018-02-14 19:38:03 +00:00
|
|
|
|
2019-09-06 12:58:04 +00:00
|
|
|
for (unsigned int i = 0; i < erCount; ++i)
|
|
|
|
role_names[i] = ExtrusionEntity::role_to_string(ExtrusionRole(i));
|
2018-02-14 19:38:03 +00:00
|
|
|
|
|
|
|
role_flags = 0;
|
2019-09-06 12:58:04 +00:00
|
|
|
for (unsigned int i = 0; i < erCount; ++i)
|
2018-02-14 19:38:03 +00:00
|
|
|
role_flags |= 1 << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GCodePreviewData::Extrusion::is_role_flag_set(ExtrusionRole role) const
|
|
|
|
{
|
|
|
|
return is_role_flag_set(role_flags, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GCodePreviewData::Extrusion::is_role_flag_set(unsigned int flags, ExtrusionRole role)
|
|
|
|
{
|
|
|
|
return GCodeAnalyzer::is_valid_extrusion_role(role) && (flags & (1 << (role - erPerimeter))) != 0;
|
|
|
|
}
|
|
|
|
|
2018-12-18 14:55:45 +00:00
|
|
|
size_t GCodePreviewData::Extrusion::memory_used() const
|
|
|
|
{
|
|
|
|
size_t out = sizeof(*this);
|
|
|
|
out += SLIC3R_STDVEC_MEMSIZE(this->layers, Layer);
|
|
|
|
for (const Layer &layer : this->layers) {
|
2019-09-30 14:25:26 +00:00
|
|
|
out += SLIC3R_STDVEC_MEMSIZE(layer.paths, Path);
|
|
|
|
for (const Path &path : layer.paths)
|
2018-12-18 14:55:45 +00:00
|
|
|
out += SLIC3R_STDVEC_MEMSIZE(path.polyline.points, Point);
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-02-14 19:38:03 +00:00
|
|
|
const float GCodePreviewData::Travel::Default_Width = 0.075f;
|
|
|
|
const float GCodePreviewData::Travel::Default_Height = 0.075f;
|
2019-12-08 00:31:28 +00:00
|
|
|
const Color GCodePreviewData::Travel::Default_Type_Colors[Num_Types] =
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
|
|
|
Color(0.0f, 0.0f, 0.75f, 1.0f), // Move
|
|
|
|
Color(0.0f, 0.75f, 0.0f, 1.0f), // Extrude
|
|
|
|
Color(0.75f, 0.0f, 0.0f, 1.0f), // Retract
|
|
|
|
};
|
|
|
|
|
|
|
|
void GCodePreviewData::Travel::set_default()
|
|
|
|
{
|
|
|
|
width = Default_Width;
|
|
|
|
height = Default_Height;
|
|
|
|
::memcpy((void*)type_colors, (const void*)Default_Type_Colors, Num_Types * sizeof(Color));
|
2018-11-26 15:07:09 +00:00
|
|
|
color_print_idx = 0;
|
2018-03-06 11:12:00 +00:00
|
|
|
|
2018-02-14 19:38:03 +00:00
|
|
|
is_visible = false;
|
|
|
|
}
|
|
|
|
|
2018-12-18 14:55:45 +00:00
|
|
|
size_t GCodePreviewData::Travel::memory_used() const
|
|
|
|
{
|
|
|
|
size_t out = sizeof(*this);
|
|
|
|
out += SLIC3R_STDVEC_MEMSIZE(this->polylines, Polyline);
|
|
|
|
for (const Polyline &polyline : this->polylines)
|
|
|
|
out += SLIC3R_STDVEC_MEMSIZE(polyline.polyline.points, Vec3crd);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
const Color GCodePreviewData::Retraction::Default_Color = Color(1.0f, 1.0f, 1.0f, 1.0f);
|
2018-02-14 19:38:03 +00:00
|
|
|
|
2018-08-21 20:14:47 +00:00
|
|
|
GCodePreviewData::Retraction::Position::Position(const Vec3crd& position, float width, float height)
|
2018-02-14 19:38:03 +00:00
|
|
|
: position(position)
|
|
|
|
, width(width)
|
|
|
|
, height(height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GCodePreviewData::Retraction::set_default()
|
|
|
|
{
|
|
|
|
color = Default_Color;
|
|
|
|
is_visible = false;
|
|
|
|
}
|
|
|
|
|
2018-12-18 14:55:45 +00:00
|
|
|
size_t GCodePreviewData::Retraction::memory_used() const
|
|
|
|
{
|
|
|
|
return sizeof(*this) + SLIC3R_STDVEC_MEMSIZE(this->positions, Position);
|
|
|
|
}
|
|
|
|
|
2018-02-14 19:38:03 +00:00
|
|
|
void GCodePreviewData::Shell::set_default()
|
|
|
|
{
|
|
|
|
is_visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GCodePreviewData::GCodePreviewData()
|
|
|
|
{
|
|
|
|
set_default();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GCodePreviewData::set_default()
|
|
|
|
{
|
|
|
|
extrusion.set_default();
|
|
|
|
travel.set_default();
|
|
|
|
retraction.set_default();
|
|
|
|
unretraction.set_default();
|
|
|
|
shell.set_default();
|
2019-12-08 00:31:28 +00:00
|
|
|
|
|
|
|
// Configure the color range for feedrate to match the default for travels and to enable extrusions since they are always visible
|
|
|
|
ranges.feedrate.set_mode(FeedrateKind::TRAVEL, travel.is_visible);
|
|
|
|
ranges.feedrate.set_mode(FeedrateKind::EXTRUSION, true);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GCodePreviewData::reset()
|
|
|
|
{
|
2018-03-07 08:17:59 +00:00
|
|
|
ranges.width.reset();
|
|
|
|
ranges.height.reset();
|
|
|
|
ranges.feedrate.reset();
|
2018-03-21 09:03:10 +00:00
|
|
|
ranges.volumetric_rate.reset();
|
2018-02-14 19:38:03 +00:00
|
|
|
extrusion.layers.clear();
|
|
|
|
travel.polylines.clear();
|
|
|
|
retraction.positions.clear();
|
|
|
|
unretraction.positions.clear();
|
|
|
|
}
|
|
|
|
|
2018-02-14 20:57:46 +00:00
|
|
|
bool GCodePreviewData::empty() const
|
|
|
|
{
|
|
|
|
return extrusion.layers.empty() && travel.polylines.empty() && retraction.positions.empty() && unretraction.positions.empty();
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color GCodePreviewData::get_extrusion_role_color(ExtrusionRole role) const
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
|
|
|
return extrusion.role_colors[role];
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color GCodePreviewData::get_height_color(float height) const
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
2018-03-07 08:17:59 +00:00
|
|
|
return ranges.height.get_color_at(height);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color GCodePreviewData::get_width_color(float width) const
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
2018-03-07 08:17:59 +00:00
|
|
|
return ranges.width.get_color_at(width);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color GCodePreviewData::get_feedrate_color(float feedrate) const
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
2018-03-07 08:17:59 +00:00
|
|
|
return ranges.feedrate.get_color_at(feedrate);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color GCodePreviewData::get_fan_speed_color(float fan_speed) const
|
2019-09-23 12:56:27 +00:00
|
|
|
{
|
|
|
|
return ranges.fan_speed.get_color_at(fan_speed);
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color GCodePreviewData::get_volumetric_rate_color(float rate) const
|
2018-03-21 09:03:10 +00:00
|
|
|
{
|
|
|
|
return ranges.volumetric_rate.get_color_at(rate);
|
|
|
|
}
|
|
|
|
|
2018-02-14 19:38:03 +00:00
|
|
|
void GCodePreviewData::set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha)
|
|
|
|
{
|
2019-09-06 12:58:04 +00:00
|
|
|
for (unsigned int i = 0; i < erCount; ++i)
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
|
|
|
if (role_name == extrusion.role_names[i])
|
|
|
|
{
|
|
|
|
extrusion.role_colors[i] = Color(red, green, blue, alpha);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GCodePreviewData::set_extrusion_paths_colors(const std::vector<std::string>& colors)
|
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
unsigned int size = (unsigned int)range_rainbow_colors.size();
|
2018-02-14 19:38:03 +00:00
|
|
|
|
|
|
|
if (size % 2 != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < size; i += 2)
|
|
|
|
{
|
|
|
|
const std::string& color_str = colors[i + 1];
|
|
|
|
|
|
|
|
if (color_str.size() == 6)
|
|
|
|
{
|
|
|
|
bool valid = true;
|
|
|
|
for (int c = 0; c < 6; ++c)
|
|
|
|
{
|
|
|
|
if (::isxdigit(color_str[c]) == 0)
|
|
|
|
{
|
|
|
|
valid = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid)
|
|
|
|
{
|
|
|
|
unsigned int color;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::hex << color_str;
|
|
|
|
ss >> color;
|
|
|
|
|
|
|
|
float den = 1.0f / 255.0f;
|
|
|
|
|
|
|
|
float r = (float)((color & 0xFF0000) >> 16) * den;
|
|
|
|
float g = (float)((color & 0x00FF00) >> 8) * den;
|
|
|
|
float b = (float)(color & 0x0000FF) * den;
|
|
|
|
|
|
|
|
this->set_extrusion_role_color(colors[i], r, g, b, 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GCodePreviewData::get_legend_title() const
|
|
|
|
{
|
|
|
|
switch (extrusion.view_type)
|
|
|
|
{
|
|
|
|
case Extrusion::FeatureType:
|
2018-02-26 15:23:44 +00:00
|
|
|
return L("Feature type");
|
2018-02-14 19:38:03 +00:00
|
|
|
case Extrusion::Height:
|
2018-02-26 15:23:44 +00:00
|
|
|
return L("Height (mm)");
|
2018-02-14 19:38:03 +00:00
|
|
|
case Extrusion::Width:
|
2018-02-26 15:23:44 +00:00
|
|
|
return L("Width (mm)");
|
2018-02-14 19:38:03 +00:00
|
|
|
case Extrusion::Feedrate:
|
2018-02-26 15:23:44 +00:00
|
|
|
return L("Speed (mm/s)");
|
2019-09-23 12:56:27 +00:00
|
|
|
case Extrusion::FanSpeed:
|
|
|
|
return L("Fan Speed (%)");
|
2018-03-21 09:03:10 +00:00
|
|
|
case Extrusion::VolumetricRate:
|
2019-09-23 09:11:43 +00:00
|
|
|
return L("Volumetric flow rate (mm³/s)");
|
2018-02-14 19:38:03 +00:00
|
|
|
case Extrusion::Tool:
|
2018-02-26 15:23:44 +00:00
|
|
|
return L("Tool");
|
2018-11-26 15:07:09 +00:00
|
|
|
case Extrusion::ColorPrint:
|
|
|
|
return L("Color Print");
|
2019-06-25 11:06:04 +00:00
|
|
|
case Extrusion::Num_View_Types:
|
|
|
|
break; // just to supress warning about non-handled value
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-11-04 15:28:57 +00:00
|
|
|
GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::vector<float>& tool_colors,
|
2019-11-07 15:36:24 +00:00
|
|
|
const std::vector<std::string>& cp_items) const
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
|
|
|
struct Helper
|
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
static void FillListFromRange(LegendItemsList& list, const RangeBase& range, unsigned int decimals, float scale_factor)
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
list.reserve(range_rainbow_colors.size());
|
2018-03-06 11:12:00 +00:00
|
|
|
|
2018-03-07 08:17:59 +00:00
|
|
|
float step = range.step_size();
|
2019-12-08 00:31:28 +00:00
|
|
|
for (int i = static_cast<int>(range_rainbow_colors.size()) - 1; i >= 0; --i)
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
2018-03-06 11:12:00 +00:00
|
|
|
char buf[1024];
|
2019-12-08 00:31:28 +00:00
|
|
|
sprintf(buf, "%.*f", decimals, scale_factor * (range.min() + (float)i * step));
|
|
|
|
list.emplace_back(buf, range_rainbow_colors[i]);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LegendItemsList items;
|
|
|
|
|
|
|
|
switch (extrusion.view_type)
|
|
|
|
{
|
|
|
|
case Extrusion::FeatureType:
|
|
|
|
{
|
2018-02-22 07:59:47 +00:00
|
|
|
ExtrusionRole first_valid = erPerimeter;
|
|
|
|
ExtrusionRole last_valid = erCustom;
|
|
|
|
|
|
|
|
items.reserve(last_valid - first_valid + 1);
|
|
|
|
for (unsigned int i = (unsigned int)first_valid; i <= (unsigned int)last_valid; ++i)
|
2018-02-14 19:38:03 +00:00
|
|
|
{
|
2018-06-20 16:55:31 +00:00
|
|
|
items.emplace_back(Slic3r::I18N::translate(extrusion.role_names[i]), extrusion.role_colors[i]);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Extrusion::Height:
|
|
|
|
{
|
2018-03-07 08:17:59 +00:00
|
|
|
Helper::FillListFromRange(items, ranges.height, 3, 1.0f);
|
2018-02-14 19:38:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Extrusion::Width:
|
|
|
|
{
|
2018-03-07 08:17:59 +00:00
|
|
|
Helper::FillListFromRange(items, ranges.width, 3, 1.0f);
|
2018-02-14 19:38:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Extrusion::Feedrate:
|
|
|
|
{
|
2018-04-27 07:54:21 +00:00
|
|
|
Helper::FillListFromRange(items, ranges.feedrate, 1, 1.0f);
|
2018-02-14 19:38:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-09-23 12:56:27 +00:00
|
|
|
case Extrusion::FanSpeed:
|
|
|
|
{
|
|
|
|
Helper::FillListFromRange(items, ranges.fan_speed, 0, 1.0f);
|
|
|
|
break;
|
|
|
|
}
|
2018-03-21 09:03:10 +00:00
|
|
|
case Extrusion::VolumetricRate:
|
|
|
|
{
|
|
|
|
Helper::FillListFromRange(items, ranges.volumetric_rate, 3, 1.0f);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-14 19:38:03 +00:00
|
|
|
case Extrusion::Tool:
|
|
|
|
{
|
2019-07-09 13:47:34 +00:00
|
|
|
unsigned int tools_colors_count = (unsigned int)tool_colors.size() / 4;
|
2018-02-14 19:38:03 +00:00
|
|
|
items.reserve(tools_colors_count);
|
|
|
|
for (unsigned int i = 0; i < tools_colors_count; ++i)
|
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
Color color;
|
|
|
|
::memcpy((void*)color.rgba.data(), (const void*)(tool_colors.data() + i * 4), 4 * sizeof(float));
|
2018-06-20 16:55:31 +00:00
|
|
|
items.emplace_back((boost::format(Slic3r::I18N::translate(L("Extruder %d"))) % (i + 1)).str(), color);
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 15:07:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-11-04 15:28:57 +00:00
|
|
|
case Extrusion::ColorPrint:
|
|
|
|
{
|
|
|
|
const int color_cnt = (int)tool_colors.size()/4;
|
|
|
|
const auto color_print_cnt = (int)cp_items.size();
|
|
|
|
if (color_print_cnt == 1) // means "Default print color"
|
|
|
|
{
|
|
|
|
Color color;
|
2019-12-08 00:31:28 +00:00
|
|
|
::memcpy((void*)color.rgba.data(), (const void*)(tool_colors.data()), 4 * sizeof(float));
|
2019-11-04 15:28:57 +00:00
|
|
|
|
|
|
|
items.emplace_back(cp_items[0], color);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color_cnt != color_print_cnt)
|
|
|
|
break;
|
|
|
|
|
2019-11-07 15:36:24 +00:00
|
|
|
for (int i = 0 ; i < color_print_cnt; ++i)
|
2019-11-04 15:28:57 +00:00
|
|
|
{
|
|
|
|
Color color;
|
2019-12-08 00:31:28 +00:00
|
|
|
::memcpy((void*)color.rgba.data(), (const void*)(tool_colors.data() + i * 4), 4 * sizeof(float));
|
2019-11-04 15:28:57 +00:00
|
|
|
|
|
|
|
items.emplace_back(cp_items[i], color);
|
|
|
|
}
|
|
|
|
break;
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
2019-06-25 11:06:04 +00:00
|
|
|
case Extrusion::Num_View_Types:
|
|
|
|
break; // just to supress warning about non-handled value
|
2018-02-14 19:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2018-12-18 14:55:45 +00:00
|
|
|
// Return an estimate of the memory consumed by the time estimator.
|
|
|
|
size_t GCodePreviewData::memory_used() const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
this->extrusion.memory_used() +
|
|
|
|
this->travel.memory_used() +
|
|
|
|
this->retraction.memory_used() +
|
|
|
|
this->unretraction.memory_used() +
|
|
|
|
sizeof(shell) + sizeof(ranges);
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
const std::vector<std::string>& ColorPrintColors()
|
2019-01-29 14:11:29 +00:00
|
|
|
{
|
|
|
|
static std::vector<std::string> color_print = {"#C0392B", "#E67E22", "#F1C40F", "#27AE60", "#1ABC9C", "#2980B9", "#9B59B6"};
|
|
|
|
return color_print;
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color operator + (const Color& c1, const Color& c2)
|
2018-12-19 13:47:16 +00:00
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
return Color(clamp(0.0f, 1.0f, c1.rgba[0] + c2.rgba[0]),
|
2018-12-19 13:47:16 +00:00
|
|
|
clamp(0.0f, 1.0f, c1.rgba[1] + c2.rgba[1]),
|
|
|
|
clamp(0.0f, 1.0f, c1.rgba[2] + c2.rgba[2]),
|
|
|
|
clamp(0.0f, 1.0f, c1.rgba[3] + c2.rgba[3]));
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:31:28 +00:00
|
|
|
Color operator * (float f, const Color& color)
|
2018-12-19 13:47:16 +00:00
|
|
|
{
|
2019-12-08 00:31:28 +00:00
|
|
|
return Color(clamp(0.0f, 1.0f, f * color.rgba[0]),
|
2018-12-19 13:47:16 +00:00
|
|
|
clamp(0.0f, 1.0f, f * color.rgba[1]),
|
|
|
|
clamp(0.0f, 1.0f, f * color.rgba[2]),
|
|
|
|
clamp(0.0f, 1.0f, f * color.rgba[3]));
|
|
|
|
}
|
|
|
|
|
2018-02-14 19:38:03 +00:00
|
|
|
} // namespace Slic3r
|