Skip to content

Commit

Permalink
Added "Color" parameter for SLA material
Browse files Browse the repository at this point in the history
  • Loading branch information
YuSanka committed Nov 5, 2021
1 parent ddef93e commit 2fcab52
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ static std::vector<std::string> s_Preset_sla_print_options {
};

static std::vector<std::string> s_Preset_sla_material_options {
"material_colour",
"material_type",
"initial_layer_height",
"bottle_cost",
Expand Down
7 changes: 7 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3163,6 +3163,13 @@ void PrintConfigDef::init_sla_params()


// SLA Material settings.

def = this->add("material_colour", coStrings);
def->label = L("Color");
def->tooltip = L("This is only used in the Slic3r interface as a visual help.");
def->gui_type = ConfigOptionDef::GUIType::color;
def->set_default_value(new ConfigOptionStrings{ "#29B2B2" });

def = this->add("material_type", coString);
def->label = L("SLA material type");
def->tooltip = L("SLA material type");
Expand Down
50 changes: 33 additions & 17 deletions src/slic3r/GUI/3DScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,29 +1131,45 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con
if (config == nullptr)
return;

const ConfigOptionStrings* extruders_opt = dynamic_cast<const ConfigOptionStrings*>(config->option("extruder_colour"));
if (extruders_opt == nullptr)
return;
unsigned char rgb[3];
std::vector<Color> colors;

const ConfigOptionStrings* filamemts_opt = dynamic_cast<const ConfigOptionStrings*>(config->option("filament_colour"));
if (filamemts_opt == nullptr)
return;
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);

unsigned int colors_count = std::max((unsigned int)extruders_opt->values.size(), (unsigned int)filamemts_opt->values.size());
if (colors_count == 0)
return;
const std::string& txt_color = config->opt_string("material_colour", 0);
if (Slic3r::GUI::BitmapCache::parse_color(txt_color, rgb))
colors[0].set(txt_color, rgb);
}
else
{
const ConfigOptionStrings* extruders_opt = dynamic_cast<const ConfigOptionStrings*>(config->option("extruder_colour"));
if (extruders_opt == nullptr)
return;

std::vector<Color> colors(colors_count);
const ConfigOptionStrings* filamemts_opt = dynamic_cast<const ConfigOptionStrings*>(config->option("filament_colour"));
if (filamemts_opt == nullptr)
return;

unsigned char rgb[3];
for (unsigned int i = 0; i < colors_count; ++i) {
const std::string& txt_color = config->opt_string("extruder_colour", i);
if (Slic3r::GUI::BitmapCache::parse_color(txt_color, rgb))
colors[i].set(txt_color, rgb);
else {
const std::string& txt_color = config->opt_string("filament_colour", i);
unsigned int colors_count = std::max((unsigned int)extruders_opt->values.size(), (unsigned int)filamemts_opt->values.size());
if (colors_count == 0)
return;
colors.resize(colors_count);

for (unsigned int i = 0; i < colors_count; ++i) {
const std::string& txt_color = config->opt_string("extruder_colour", i);
if (Slic3r::GUI::BitmapCache::parse_color(txt_color, rgb))
colors[i].set(txt_color, rgb);
else {
const std::string& txt_color = config->opt_string("filament_colour", i);
if (Slic3r::GUI::BitmapCache::parse_color(txt_color, rgb))
colors[i].set(txt_color, rgb);
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
"bed_shape", "bed_custom_texture", "bed_custom_model", "complete_objects", "duplicate_distance", "extruder_clearance_radius", "skirts", "skirt_distance",
"brim_width", "brim_separation", "brim_type", "variable_layer_height", "nozzle_diameter", "single_extruder_multi_material",
"wipe_tower", "wipe_tower_x", "wipe_tower_y", "wipe_tower_width", "wipe_tower_rotation_angle", "wipe_tower_brim_width",
"extruder_colour", "filament_colour", "max_print_height", "printer_model", "printer_technology",
"extruder_colour", "filament_colour", "material_colour", "max_print_height", "printer_model", "printer_technology",
// These values are necessary to construct SlicingParameters by the Canvas3D variable layer height editor.
"layer_height", "first_layer_height", "min_layer_height", "max_layer_height",
"brim_width", "perimeters", "perimeter_extruder", "fill_density", "infill_extruder", "top_solid_layers",
Expand Down Expand Up @@ -6222,6 +6222,15 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
}
}

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());
if (opt_key == "printer_technology") {
this->set_printer_technology(config.opt_enum<PrinterTechnology>(opt_key));
Expand Down
7 changes: 7 additions & 0 deletions src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4157,13 +4157,20 @@ void TabSLAMaterial::build()
auto page = add_options_page(L("Material"), "resin");

auto optgroup = page->new_optgroup(L("Material"));
optgroup->append_single_option_line("material_colour");
optgroup->append_single_option_line("bottle_cost");
optgroup->append_single_option_line("bottle_volume");
optgroup->append_single_option_line("bottle_weight");
optgroup->append_single_option_line("material_density");

optgroup->m_on_change = [this, optgroup](t_config_option_key opt_key, boost::any value)
{
if (opt_key == "material_colour") {
update_dirty();
on_value_change(opt_key, value);
return;
}

DynamicPrintConfig new_conf = *m_config;

if (opt_key == "bottle_volume") {
Expand Down

0 comments on commit 2fcab52

Please sign in to comment.