Implemented possibility to show resin colors from the Plater (Bottles with resin are colored now in preset combobox)

+ Added nsvgParseFromFileWithReplace() to replace some colors before parsing from SVG file
+ Thumbnails are saved with selected resin color in SL1 or SL1S files
+ "white" folder is deleted from "icons" now. THere is no needed anymore.
This commit is contained in:
YuSanka 2021-11-09 17:00:57 +01:00
parent 69731b1d96
commit e8be7b2ecd
100 changed files with 109 additions and 2126 deletions

View file

@ -1136,15 +1136,11 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con
if (static_cast<PrinterTechnology>(config->opt_int("printer_technology")) == ptSLA)
{
const ConfigOptionStrings* resin_clr = dynamic_cast<const ConfigOptionStrings*>(config->option("material_colour"));
if (resin_clr == nullptr)
return;
assert(resin_clr->values.size() == 1);
colors.resize(1);
const std::string& txt_color = config->opt_string("material_colour", 0);
if (Slic3r::GUI::BitmapCache::parse_color(txt_color, rgb))
const std::string& txt_color = config->opt_string("material_colour");
if (Slic3r::GUI::BitmapCache::parse_color(txt_color, rgb)) {
colors.resize(1);
colors[0].set(txt_color, rgb);
}
}
else
{

View file

@ -261,51 +261,28 @@ wxBitmap* BitmapCache::load_png(const std::string &bitmap_name, unsigned width,
}
wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_width, unsigned target_height,
const bool grayscale/* = false*/, const bool dark_mode/* = false*/)
const bool grayscale/* = false*/, const bool dark_mode/* = false*/, const std::string& new_color /*= ""*/)
{
std::string bitmap_key = bitmap_name + ( target_height !=0 ?
"-h" + std::to_string(target_height) :
"-w" + std::to_string(target_width))
+ (m_scale != 1.0f ? "-s" + float_to_string_decimal_point(m_scale) : "")
+ (grayscale ? "-gs" : "");
+ (dark_mode ? "-dm" : "")
+ (grayscale ? "-gs" : "")
+ new_color;
/* For the Dark mode of any platform, we should draw icons in respect to OS background
* Note: All standard(regular) icons are collected in "icons" folder,
* SVG-icons, which have "Dark mode" variant, are collected in "icons/white" folder
*/
std::string folder;
auto it = m_map.find(bitmap_key);
if (it != m_map.end())
return it->second;
// map of color replaces
std::map<std::string, std::string> replaces;
if (dark_mode)
{
#ifdef __WXMSW__
folder = "white\\";
#else
folder = "white/";
#endif
auto it = m_map.find(folder + bitmap_key);
if (it != m_map.end())
return it->second;
// It's expensive to check if the bitmap exists every time, but otherwise:
// For the case, when application was started in Light mode and then switched to the Dark,
// we will never get a white bitmaps, if check m_map.find(bitmap_key)
// before boost::filesystem::exists(var(folder + bitmap_name + ".svg"))
if (!boost::filesystem::exists(var(folder + bitmap_name + ".svg"))) {
folder.clear();
it = m_map.find(bitmap_key);
if (it != m_map.end())
return it->second;
}
replaces["#808080"] = "#FFFFFF";
if (!new_color.empty())
replaces["#ED6B21"] = new_color;
bitmap_key = folder + bitmap_key;
}
else
{
auto it = m_map.find(bitmap_key);
if (it != m_map.end())
return it->second;
}
NSVGimage *image = ::nsvgParseFromFile(Slic3r::var(folder + bitmap_name + ".svg").c_str(), "px", 96.0f);
NSVGimage *image = ::nsvgParseFromFileWithReplace(Slic3r::var(bitmap_name + ".svg").c_str(), "px", 96.0f, replaces);
if (image == nullptr)
return nullptr;

View file

@ -33,7 +33,7 @@ public:
// Load png from resources/icons. bitmap_key is given without the .png suffix. Bitmap will be rescaled to provided height/width if nonzero.
wxBitmap* load_png(const std::string &bitmap_key, unsigned width = 0, unsigned height = 0, const bool grayscale = false);
// Load svg from resources/icons. bitmap_key is given without the .svg suffix. SVG will be rasterized to provided height/width.
wxBitmap* load_svg(const std::string &bitmap_key, unsigned width = 0, unsigned height = 0, const bool grayscale = false, const bool dark_mode = false);
wxBitmap* load_svg(const std::string &bitmap_key, unsigned width = 0, unsigned height = 0, const bool grayscale = false, const bool dark_mode = false, const std::string& new_color = "");
wxBitmap mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency, bool suppress_scaling = false, size_t border_width = 0, bool dark_mode = false);
wxBitmap mksolid(size_t width, size_t height, const unsigned char rgb[3], bool suppress_scaling = false, size_t border_width = 0, bool dark_mode = false) { return mksolid(width, height, rgb[0], rgb[1], rgb[2], wxALPHA_OPAQUE, suppress_scaling, border_width, dark_mode); }

View file

@ -1320,7 +1320,7 @@ void ColourPicker::BUILD()
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
// Validate the color
wxString clr_str(m_opt.get_default_value<ConfigOptionStrings>()->get_at(m_opt_idx));
wxString clr_str(m_opt.type == coString ? m_opt.get_default_value<ConfigOptionString>()->value : m_opt.get_default_value<ConfigOptionStrings>()->get_at(m_opt_idx));
wxColour clr(clr_str);
if (clr_str.IsEmpty() || !clr.IsOk()) {
clr = wxTransparentColour;

View file

@ -4197,7 +4197,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const
shader->set_uniform("emission_factor", 0.0f);
for (GLVolume* vol : visible_volumes) {
shader->set_uniform("uniform_color", (vol->printable && !vol->is_outside) ? orange : gray);
shader->set_uniform("uniform_color", (vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : orange) : gray);
// the volume may have been deactivated by an active gizmo
bool is_active = vol->is_active;
vol->is_active = true;

View file

@ -1017,15 +1017,7 @@ std::vector<unsigned char> ImGuiWrapper::load_svg(const std::string& bitmap_name
{
std::vector<unsigned char> empty_vector;
#ifdef __WXMSW__
std::string folder = "white\\";
#else
std::string folder = "white/";
#endif
if (!boost::filesystem::exists(Slic3r::var(folder + bitmap_name + ".svg")))
folder.clear();
NSVGimage* image = ::nsvgParseFromFile(Slic3r::var(folder + bitmap_name + ".svg").c_str(), "px", 96.0f);
NSVGimage* image = ::nsvgParseFromFileWithReplace(Slic3r::var(bitmap_name + ".svg").c_str(), "px", 96.0f, { { "#808080", "#FFFFFF" } });
if (image == nullptr)
return empty_vector;

View file

@ -6221,14 +6221,8 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
continue;
}
}
if (opt_key == "material_colour") {
update_scheduled = true; // update should be scheduled (for update 3DScene)
// update material color in full config
std::vector<std::string> material_colors = { config.opt_string("material_colour", (unsigned)0) };
p->config->option<ConfigOptionStrings>("material_colour")->values = material_colors;
continue;
}
p->config->set_key_value(opt_key, config.option(opt_key)->clone());

View file

@ -419,7 +419,7 @@ wxString PresetComboBox::separator(const std::string& label)
wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, const std::string& main_icon_name,
bool is_compatible/* = true*/, bool is_system/* = false*/, bool is_single_bar/* = false*/,
std::string filament_rgb/* = ""*/, std::string extruder_rgb/* = ""*/)
const std::string& filament_rgb/* = ""*/, const std::string& extruder_rgb/* = ""*/, const std::string& material_rgb/* = ""*/)
{
// If the filament preset is not compatible and there is a "red flag" icon loaded, show it left
// to the filament color image.
@ -431,6 +431,7 @@ wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, con
bool dark_mode = wxGetApp().dark_mode();
if (dark_mode)
bitmap_key += ",dark";
bitmap_key += material_rgb;
wxBitmap* bmp = bitmap_cache().find(bitmap_key);
if (bmp == nullptr) {
@ -457,7 +458,10 @@ wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, con
{
// Paint the color bars.
bmps.emplace_back(bitmap_cache().mkclear(thin_space_icon_width, icon_height));
bmps.emplace_back(create_scaled_bitmap(main_icon_name));
if (m_type == Preset::TYPE_SLA_MATERIAL)
bmps.emplace_back(create_scaled_bitmap(main_icon_name, this, 16, false, material_rgb));
else
bmps.emplace_back(create_scaled_bitmap(main_icon_name));
// Paint a lock at the system presets.
bmps.emplace_back(bitmap_cache().mkclear(wide_space_icon_width, icon_height));
}
@ -789,7 +793,7 @@ void PlaterPresetComboBox::update()
if (!preset.is_visible || (!preset.is_compatible && !is_selected))
continue;
std::string bitmap_key, filament_rgb, extruder_rgb;
std::string bitmap_key, filament_rgb, extruder_rgb, material_rgb;
std::string bitmap_type_name = bitmap_key = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
bool single_bar = false;
@ -803,10 +807,12 @@ void PlaterPresetComboBox::update()
bitmap_key += single_bar ? filament_rgb : filament_rgb + extruder_rgb;
}
else if (m_type == Preset::TYPE_SLA_MATERIAL)
material_rgb = is_selected ? m_preset_bundle->sla_materials.get_edited_preset().config.opt_string("material_colour") : preset.config.opt_string("material_colour");
wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, bitmap_type_name,
preset.is_compatible, preset.is_system || preset.is_default,
single_bar, filament_rgb, extruder_rgb);
single_bar, filament_rgb, extruder_rgb, material_rgb);
assert(bmp);
const std::string name = preset.alias.empty() ? preset.name : preset.alias;

View file

@ -122,7 +122,7 @@ protected:
wxBitmap* get_bmp( std::string bitmap_key, bool wide_icons, const std::string& main_icon_name,
bool is_compatible = true, bool is_system = false, bool is_single_bar = false,
std::string filament_rgb = "", std::string extruder_rgb = "");
const std::string& filament_rgb = "", const std::string& extruder_rgb = "", const std::string& material_rgb = "");
wxBitmap* get_bmp( std::string bitmap_key, const std::string& main_icon_name, const std::string& next_icon_name,
bool is_enabled = true, bool is_compatible = true, bool is_system = false);

View file

@ -419,7 +419,7 @@ int mode_icon_px_size()
wxBitmap create_menu_bitmap(const std::string& bmp_name)
{
return create_scaled_bitmap(bmp_name, nullptr, 16, false, true);
return create_scaled_bitmap(bmp_name, nullptr, 16, false, "", true);
}
// win is used to get a correct em_unit value
@ -429,6 +429,7 @@ wxBitmap create_scaled_bitmap( const std::string& bmp_name_in,
wxWindow *win/* = nullptr*/,
const int px_cnt/* = 16*/,
const bool grayscale/* = false*/,
const std::string& new_color/* = std::string()*/, // color witch will used instead of orange
const bool menu_bitmap/* = false*/)
{
static Slic3r::GUI::BitmapCache cache;
@ -446,7 +447,7 @@ wxBitmap create_scaled_bitmap( const std::string& bmp_name_in,
Slic3r::GUI::wxGetApp().dark_mode();
// Try loading an SVG first, then PNG if SVG is not found:
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, grayscale, dark_mode);
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, grayscale, dark_mode, new_color);
if (bmp == nullptr) {
bmp = cache.load_png(bmp_name, width, height, grayscale);
}
@ -459,6 +460,33 @@ wxBitmap create_scaled_bitmap( const std::string& bmp_name_in,
return *bmp;
}
wxBitmap create_scaled_bitmap(const std::string& bmp_name_in,
const std::string& new_color, // color witch will used instead of orange
wxWindow* win,
const int px_cnt/* = 16*/,
const bool grayscale/* = false*/)
{
static Slic3r::GUI::BitmapCache cache;
unsigned int width = 0;
unsigned int height = (unsigned int)(em_unit(win) * px_cnt * 0.1f + 0.5f);
std::string bmp_name = bmp_name_in;
auto it = boost::find_last(bmp_name, ".png");
assert(it == bmp_name.end()); // this function works just with SVGs
bool dark_mode = Slic3r::GUI::wxGetApp().dark_mode();
// Try loading an SVG first, then PNG if SVG is not found:
wxBitmap* bmp = cache.load_svg(bmp_name, width, height, grayscale, dark_mode, new_color);
if (bmp == nullptr) {
// Neither SVG nor PNG has been found, raise error
throw Slic3r::RuntimeError("Could not load bitmap: " + bmp_name);
}
return *bmp;
}
std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon/* = false*/)
{
static Slic3r::GUI::BitmapCache bmp_cache;

View file

@ -51,7 +51,9 @@ int mode_icon_px_size();
wxBitmap create_menu_bitmap(const std::string& bmp_name);
wxBitmap create_scaled_bitmap(const std::string& bmp_name, wxWindow *win = nullptr,
const int px_cnt = 16, const bool grayscale = false, const bool menu_bitmap = false);
const int px_cnt = 16, const bool grayscale = false,
const std::string& new_color = std::string(), // color witch will used instead of orange
const bool menu_bitmap = false);
std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon = false);