FIX: CLI: fix the brim related issues

1. move the global functions to Model
2. set brim automation paremeters before process
JIRA: STUDIO-4208

Change-Id: I3f75175ec74d214ca2a6d5f3ade56d08e0ecd4f3
(cherry picked from commit bcc88bc01ec396e8fb8af1186b47a75cd5116f3c)
This commit is contained in:
lane.wei 2023-08-25 15:28:44 +08:00 committed by Lane.Wei
parent 7f642112d2
commit d5b9dcfbbe
6 changed files with 159 additions and 126 deletions

View file

@ -2875,12 +2875,14 @@ int CLI::run(int argc, char **argv)
// is supplied); if any object has no instances, it will get a default one // is supplied); if any object has no instances, it will get a default one
// and all instances will be rearranged (unless --dont-arrange is supplied). // and all instances will be rearranged (unless --dont-arrange is supplied).
std::string outfile; std::string outfile;
Print fff_print; //Print fff_print;
while(!finished) while(!finished)
{ {
//BBS: slice every partplate one by one //BBS: slice every partplate one by one
PrintBase *print=NULL; PrintBase *print=NULL;
Print *print_fff = NULL;
Slic3r::GUI::GCodeResult *gcode_result = NULL; Slic3r::GUI::GCodeResult *gcode_result = NULL;
int print_index; int print_index;
for (int index = 0; index < partplate_list.get_plate_count(); index ++) for (int index = 0; index < partplate_list.get_plate_count(); index ++)
@ -2895,6 +2897,8 @@ int CLI::run(int argc, char **argv)
//get the current partplate //get the current partplate
Slic3r::GUI::PartPlate* part_plate = partplate_list.get_plate(index); Slic3r::GUI::PartPlate* part_plate = partplate_list.get_plate(index);
part_plate->get_print(&print, &gcode_result, &print_index); part_plate->get_print(&print, &gcode_result, &print_index);
print_fff = dynamic_cast<Print *>(print);
/*if (outfile_config.empty()) /*if (outfile_config.empty())
{ {
outfile = "plate_" + std::to_string(index + 1) + ".gcode"; outfile = "plate_" + std::to_string(index + 1) + ".gcode";
@ -3074,6 +3078,11 @@ int CLI::run(int argc, char **argv)
BOOST_LOG_TRIVIAL(info) << boost::format("new_printer_name: %1%, current_printer_system_name %2%, is_bbl_vendor_preset %3%")%new_printer_name %current_printer_system_name %is_bbl_vendor_preset; BOOST_LOG_TRIVIAL(info) << boost::format("new_printer_name: %1%, current_printer_system_name %2%, is_bbl_vendor_preset %3%")%new_printer_name %current_printer_system_name %is_bbl_vendor_preset;
} }
(dynamic_cast<Print*>(print))->set_BBL_Printer(is_bbl_vendor_preset); (dynamic_cast<Print*>(print))->set_BBL_Printer(is_bbl_vendor_preset);
//update information for brim
const PrintConfig& print_config = print_fff->config();
Model::setExtruderParams(m_print_config, filament_count);
Model::setPrintSpeedTable(m_print_config, print_config);
if (load_slicedata) { if (load_slicedata) {
std::string plate_dir = load_slice_data_dir+"/"+std::to_string(index+1); std::string plate_dir = load_slice_data_dir+"/"+std::to_string(index+1);
int ret = print->load_cached_data(plate_dir); int ret = print->load_cached_data(plate_dir);
@ -3098,12 +3107,13 @@ int CLI::run(int argc, char **argv)
print->process(); print->process();
} }
if (printer_technology == ptFFF) { if (printer_technology == ptFFF) {
std::string conflict_result = dynamic_cast<Print *>(print)->get_conflict_string(); std::string conflict_result = print_fff->get_conflict_string();
if (!conflict_result.empty()) { if (!conflict_result.empty()) {
BOOST_LOG_TRIVIAL(error) << "plate "<< index+1<< ": found slicing result conflict!"<< std::endl; BOOST_LOG_TRIVIAL(error) << "plate "<< index+1<< ": found slicing result conflict!"<< std::endl;
record_exit_reson(outfile_dir, CLI_GCODE_PATH_CONFLICTS, index+1, cli_errors[CLI_GCODE_PATH_CONFLICTS]); record_exit_reson(outfile_dir, CLI_GCODE_PATH_CONFLICTS, index+1, cli_errors[CLI_GCODE_PATH_CONFLICTS]);
flush_and_exit(CLI_GCODE_PATH_CONFLICTS); flush_and_exit(CLI_GCODE_PATH_CONFLICTS);
} }
// The outfile is processed by a PlaceholderParser. // The outfile is processed by a PlaceholderParser.
//outfile = part_plate->get_tmp_gcode_path(); //outfile = part_plate->get_tmp_gcode_path();
if (outfile_dir.empty()) { if (outfile_dir.empty()) {
@ -3114,7 +3124,7 @@ int CLI::run(int argc, char **argv)
part_plate->set_tmp_gcode_path(outfile); part_plate->set_tmp_gcode_path(outfile);
} }
BOOST_LOG_TRIVIAL(info) << "process finished, will export gcode temporily to " << outfile << std::endl; BOOST_LOG_TRIVIAL(info) << "process finished, will export gcode temporily to " << outfile << std::endl;
outfile = (dynamic_cast<Print*>(print))->export_gcode(outfile, gcode_result, nullptr); outfile = print_fff->export_gcode(outfile, gcode_result, nullptr);
//outfile_final = (dynamic_cast<Print*>(print))->print_statistics().finalize_output_path(outfile); //outfile_final = (dynamic_cast<Print*>(print))->print_statistics().finalize_output_path(outfile);
//m_fff_print->export_gcode(m_temp_output_path, m_gcode_result, [this](const ThumbnailsParams& params) { return this->render_thumbnails(params); }); //m_fff_print->export_gcode(m_temp_output_path, m_gcode_result, [this](const ThumbnailsParams& params) { return this->render_thumbnails(params); });
}/* else { }/* else {

View file

@ -3238,6 +3238,91 @@ void ModelInstance::transform_polygon(Polygon* polygon) const
} }
//BBS //BBS
// BBS set print speed table and find maximum speed
void Model::setPrintSpeedTable(const DynamicPrintConfig& config, const PrintConfig& print_config) {
//Slic3r::DynamicPrintConfig config = wxGetApp().preset_bundle->full_config();
printSpeedMap.maxSpeed = 0;
if (config.has("inner_wall_speed")) {
printSpeedMap.perimeterSpeed = config.opt_float("inner_wall_speed");
if (printSpeedMap.perimeterSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.perimeterSpeed;
}
if (config.has("outer_wall_speed")) {
printSpeedMap.externalPerimeterSpeed = config.opt_float("outer_wall_speed");
printSpeedMap.maxSpeed = std::max(printSpeedMap.maxSpeed, printSpeedMap.externalPerimeterSpeed);
}
if (config.has("sparse_infill_speed")) {
printSpeedMap.infillSpeed = config.opt_float("sparse_infill_speed");
if (printSpeedMap.infillSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.infillSpeed;
}
if (config.has("internal_solid_infill_speed")) {
printSpeedMap.solidInfillSpeed = config.opt_float("internal_solid_infill_speed");
if (printSpeedMap.solidInfillSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.solidInfillSpeed;
}
if (config.has("top_surface_speed")) {
printSpeedMap.topSolidInfillSpeed = config.opt_float("top_surface_speed");
if (printSpeedMap.topSolidInfillSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.topSolidInfillSpeed;
}
if (config.has("support_speed")) {
printSpeedMap.supportSpeed = config.opt_float("support_speed");
if (printSpeedMap.supportSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.supportSpeed;
}
//auto& print = wxGetApp().plater()->get_partplate_list().get_current_fff_print();
//auto print_config = print.config();
//printSpeedMap.bed_poly.points = get_bed_shape(*(wxGetApp().plater()->config()));
printSpeedMap.bed_poly.points = get_bed_shape(config);
Pointfs excluse_area_points = print_config.bed_exclude_area.values;
Polygons exclude_polys;
Polygon exclude_poly;
for (int i = 0; i < excluse_area_points.size(); i++) {
auto pt = excluse_area_points[i];
exclude_poly.points.emplace_back(scale_(pt.x()), scale_(pt.y()));
if (i % 4 == 3) { // exclude areas are always rectangle
exclude_polys.push_back(exclude_poly);
exclude_poly.points.clear();
}
}
printSpeedMap.bed_poly = diff({ printSpeedMap.bed_poly }, exclude_polys)[0];
}
// find temperature of heatend and bed and matierial of an given extruder
void Model::setExtruderParams(const DynamicPrintConfig& config, int extruders_count) {
extruderParamsMap.clear();
//Slic3r::DynamicPrintConfig config = wxGetApp().preset_bundle->full_config();
// BBS
//int numExtruders = wxGetApp().preset_bundle->filament_presets.size();
for (unsigned int i = 0; i != extruders_count; ++i) {
std::string matName = "";
// BBS
int bedTemp = 35;
double endTemp = 0.f;
if (config.has("filament_type")) {
matName = config.opt_string("filament_type", i);
}
if (config.has("nozzle_temperature")) {
endTemp = config.opt_int("nozzle_temperature", i);
}
// FIXME: curr_bed_type is now a plate config rather than a global config.
// Currently bed temp is not used for brim generation, so just comment it for now.
#if 0
if (config.has("curr_bed_type")) {
BedType curr_bed_type = config.opt_enum<BedType>("curr_bed_type");
bedTemp = config.opt_int(get_bed_temp_key(curr_bed_type), i);
}
#endif
if (i == 0) extruderParamsMap.insert({ i,{matName, bedTemp, endTemp} });
extruderParamsMap.insert({ i + 1,{matName, bedTemp, endTemp} });
}
}
// update the maxSpeed of an object if it is different from the global configuration // update the maxSpeed of an object if it is different from the global configuration
double Model::findMaxSpeed(const ModelObject* object) { double Model::findMaxSpeed(const ModelObject* object) {
auto objectKeys = object->config.keys(); auto objectKeys = object->config.keys();

View file

@ -1545,6 +1545,9 @@ public:
static double getThermalLength(const ModelVolume* modelVolumePtr); static double getThermalLength(const ModelVolume* modelVolumePtr);
static double getThermalLength(const std::vector<ModelVolume*> modelVolumePtrs); static double getThermalLength(const std::vector<ModelVolume*> modelVolumePtrs);
static Polygon getBedPolygon() { return Model::printSpeedMap.bed_poly; } static Polygon getBedPolygon() { return Model::printSpeedMap.bed_poly; }
//BBS static functions that update extruder params and speed table
static void setPrintSpeedTable(const DynamicPrintConfig& config, const PrintConfig& print_config);
static void setExtruderParams(const DynamicPrintConfig& config, int extruders_count);
// BBS: backup // BBS: backup
static Model read_from_archive( static Model read_from_archive(

View file

@ -395,8 +395,13 @@ void ArrangeJob::prepare()
params = init_arrange_params(m_plater); params = init_arrange_params(m_plater);
//BBS update extruder params and speed table before arranging //BBS update extruder params and speed table before arranging
Plater::setExtruderParams(Model::extruderParamsMap); const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config();
Plater::setPrintSpeedTable(Model::printSpeedMap); auto& print = wxGetApp().plater()->get_partplate_list().get_current_fff_print();
auto print_config = print.config();
int numExtruders = wxGetApp().preset_bundle->filament_presets.size();
Model::setExtruderParams(config, numExtruders);
Model::setPrintSpeedTable(config, print_config);
int state = m_plater->get_prepare_state(); int state = m_plater->get_prepare_state();
if (state == Job::JobPrepareState::PREPARE_STATE_DEFAULT) { if (state == Job::JobPrepareState::PREPARE_STATE_DEFAULT) {

View file

@ -2807,89 +2807,6 @@ void Plater::priv::select_view(const std::string& direction)
assemble_view->select_view(direction); assemble_view->select_view(direction);
} }
} }
// BBS set print speed table and find maximum speed
void Plater::setPrintSpeedTable(GlobalSpeedMap &printSpeedMap) {
Slic3r::DynamicPrintConfig config = wxGetApp().preset_bundle->full_config();
printSpeedMap.maxSpeed = 0;
if (config.has("inner_wall_speed")) {
printSpeedMap.perimeterSpeed = config.opt_float("inner_wall_speed");
if (printSpeedMap.perimeterSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.perimeterSpeed;
}
if (config.has("outer_wall_speed")) {
printSpeedMap.externalPerimeterSpeed = config.opt_float("outer_wall_speed");
printSpeedMap.maxSpeed = std::max(printSpeedMap.maxSpeed, printSpeedMap.externalPerimeterSpeed);
}
if (config.has("sparse_infill_speed")) {
printSpeedMap.infillSpeed = config.opt_float("sparse_infill_speed");
if (printSpeedMap.infillSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.infillSpeed;
}
if (config.has("internal_solid_infill_speed")) {
printSpeedMap.solidInfillSpeed = config.opt_float("internal_solid_infill_speed");
if (printSpeedMap.solidInfillSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.solidInfillSpeed;
}
if (config.has("top_surface_speed")) {
printSpeedMap.topSolidInfillSpeed = config.opt_float("top_surface_speed");
if (printSpeedMap.topSolidInfillSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.topSolidInfillSpeed;
}
if (config.has("support_speed")) {
printSpeedMap.supportSpeed = config.opt_float("support_speed");
if (printSpeedMap.supportSpeed > printSpeedMap.maxSpeed)
printSpeedMap.maxSpeed = printSpeedMap.supportSpeed;
}
auto& print = wxGetApp().plater()->get_partplate_list().get_current_fff_print();
auto print_config = print.config();
printSpeedMap.bed_poly.points = get_bed_shape(*(wxGetApp().plater()->config()));
Pointfs excluse_area_points = print_config.bed_exclude_area.values;
Polygons exclude_polys;
Polygon exclude_poly;
for (int i = 0; i < excluse_area_points.size(); i++) {
auto pt = excluse_area_points[i];
exclude_poly.points.emplace_back(scale_(pt.x()), scale_(pt.y()));
if (i % 4 == 3) { // exclude areas are always rectangle
exclude_polys.push_back(exclude_poly);
exclude_poly.points.clear();
}
}
printSpeedMap.bed_poly = diff({ printSpeedMap.bed_poly }, exclude_polys)[0];
}
// find temperature of heatend and bed and matierial of an given extruder
void Plater::setExtruderParams(std::map<size_t, Slic3r::ExtruderParams>& extParas) {
extParas.clear();
Slic3r::DynamicPrintConfig config = wxGetApp().preset_bundle->full_config();
// BBS
int numExtruders = wxGetApp().preset_bundle->filament_presets.size();
for (unsigned int i = 0; i != numExtruders; ++i) {
std::string matName = "";
// BBS
int bedTemp = 35;
double endTemp = 0.f;
if (config.has("filament_type")) {
matName = config.opt_string("filament_type", i);
}
if (config.has("nozzle_temperature")) {
endTemp = config.opt_int("nozzle_temperature", i);
}
// FIXME: curr_bed_type is now a plate config rather than a global config.
// Currently bed temp is not used for brim generation, so just comment it for now.
#if 0
if (config.has("curr_bed_type")) {
BedType curr_bed_type = config.opt_enum<BedType>("curr_bed_type");
bedTemp = config.opt_int(get_bed_temp_key(curr_bed_type), i);
}
#endif
if (i == 0) extParas.insert({ i,{matName, bedTemp, endTemp} });
extParas.insert({ i + 1,{matName, bedTemp, endTemp} });
}
}
wxColour Plater::get_next_color_for_filament() wxColour Plater::get_next_color_for_filament()
{ {
@ -2955,8 +2872,13 @@ void Plater::priv::select_view_3D(const std::string& name, bool no_slice)
else if (name == "Preview") { else if (name == "Preview") {
BOOST_LOG_TRIVIAL(info) << "select preview"; BOOST_LOG_TRIVIAL(info) << "select preview";
//BBS update extruder params and speed table before slicing //BBS update extruder params and speed table before slicing
Plater::setExtruderParams(Slic3r::Model::extruderParamsMap); const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config();
Plater::setPrintSpeedTable(Slic3r::Model::printSpeedMap); auto& print = q->get_partplate_list().get_current_fff_print();
auto print_config = print.config();
int numExtruders = wxGetApp().preset_bundle->filament_presets.size();
Model::setExtruderParams(config, numExtruders);
Model::setPrintSpeedTable(config, print_config);
set_current_panel(preview, no_slice); set_current_panel(preview, no_slice);
} }
else if (name == "Assemble") { else if (name == "Assemble") {
@ -6244,8 +6166,13 @@ void Plater::priv::on_action_slice_plate(SimpleEvent&)
if (q != nullptr) { if (q != nullptr) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received slice plate event\n" ; BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received slice plate event\n" ;
//BBS update extruder params and speed table before slicing //BBS update extruder params and speed table before slicing
Plater::setExtruderParams(Slic3r::Model::extruderParamsMap); const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config();
Plater::setPrintSpeedTable(Slic3r::Model::printSpeedMap); auto& print = q->get_partplate_list().get_current_fff_print();
auto print_config = print.config();
int numExtruders = wxGetApp().preset_bundle->filament_presets.size();
Model::setExtruderParams(config, numExtruders);
Model::setPrintSpeedTable(config, print_config);
m_slice_all = false; m_slice_all = false;
q->reslice(); q->reslice();
q->select_view_3D("Preview"); q->select_view_3D("Preview");
@ -6258,8 +6185,13 @@ void Plater::priv::on_action_slice_all(SimpleEvent&)
if (q != nullptr) { if (q != nullptr) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received slice project event\n" ; BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received slice project event\n" ;
//BBS update extruder params and speed table before slicing //BBS update extruder params and speed table before slicing
Plater::setExtruderParams(Slic3r::Model::extruderParamsMap); const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config();
Plater::setPrintSpeedTable(Slic3r::Model::printSpeedMap); auto& print = q->get_partplate_list().get_current_fff_print();
auto print_config = print.config();
int numExtruders = wxGetApp().preset_bundle->filament_presets.size();
Model::setExtruderParams(config, numExtruders);
Model::setPrintSpeedTable(config, print_config);
m_slice_all = true; m_slice_all = true;
m_slice_all_only_has_gcode = true; m_slice_all_only_has_gcode = true;
m_cur_slice_plate = 0; m_cur_slice_plate = 0;

View file

@ -255,9 +255,7 @@ public:
void update_all_plate_thumbnails(bool force_update = false); void update_all_plate_thumbnails(bool force_update = false);
void invalid_all_plate_thumbnails(); void invalid_all_plate_thumbnails();
void force_update_all_plate_thumbnails(); void force_update_all_plate_thumbnails();
//BBS static functions that update extruder params and speed table
static void setPrintSpeedTable(Slic3r::GlobalSpeedMap& printSpeedMap);
static void setExtruderParams(std::map<size_t, Slic3r::ExtruderParams>& extParas);
static wxColour get_next_color_for_filament(); static wxColour get_next_color_for_filament();
static wxString get_slice_warning_string(GCodeProcessorResult::SliceWarning& warning); static wxString get_slice_warning_string(GCodeProcessorResult::SliceWarning& warning);