Optimized and fixed some bugs

This commit is contained in:
QIDI TECH
2024-09-28 16:31:40 +08:00
parent cc186748ed
commit 72571efb04
44 changed files with 991 additions and 603 deletions

View File

@@ -329,6 +329,11 @@ void AppConfig::set_defaults()
set_bool("backup_switch", true);
}
//1.9.7.52
if (get("liveview", "auto_stop_liveview").empty()) {
set("liveview", "auto_stop_liveview", true);
}
if (get("backup_interval").empty()) {
set("backup_interval", "10");
}

View File

@@ -66,6 +66,20 @@ void ExtrusionPath::polygons_covered_by_spacing(Polygons &out, const float scale
polygons_append(out, offset(this->polyline, 0.5f * float(flow.scaled_spacing()) + scaled_epsilon));
}
//1.9.7.52
bool ExtrusionPath::can_merge(const ExtrusionPath& other)
{
return overhang_degree == other.overhang_degree &&
curve_degree==other.curve_degree &&
mm3_per_mm == other.mm3_per_mm &&
width == other.width &&
height == other.height &&
m_can_reverse == other.m_can_reverse &&
m_role == other.m_role &&
m_no_extrusion == other.m_no_extrusion &&
smooth_speed == other.smooth_speed;
}
void ExtrusionMultiPath::reverse()
{
for (ExtrusionPath &path : this->paths)

View File

@@ -285,6 +285,9 @@ public:
void set_reverse() override { m_can_reverse = false; }
bool can_reverse() const override { return m_can_reverse; }
//1.9.7.52
bool can_merge(const ExtrusionPath& other);
private:
void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const;
bool m_can_reverse = true;

View File

@@ -5,6 +5,7 @@
#include <assert.h>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/log/trivial.hpp>
// Mark string for localization and translate.
#define L(s) Slic3r::I18N::translate(s)

View File

@@ -511,6 +511,11 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
config.set_key_value("flush_length", new ConfigOptionFloat(purge_length));
int flush_count = std::min(g_max_flush_count, (int)std::round(purge_volume / g_purge_volume_one_time));
//1.9.7.52
// handle cases for very small purge
if (flush_count == 0 && purge_volume > 0)
flush_count += 1;
float flush_unit = purge_length / flush_count;
int flush_idx = 0;
for (; flush_idx < flush_count; flush_idx++) {
@@ -1269,7 +1274,8 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
break;
}
}
//1.9.7.52
m_processor.set_filaments(m_writer.extruders());
m_processor.finalize(true);
// DoExport::update_print_estimated_times_stats(m_processor, print->m_print_statistics);
DoExport::update_print_estimated_stats(m_processor, m_writer.extruders(), print->m_print_statistics);
@@ -1304,13 +1310,16 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
// free functions called by GCode::_do_export()
namespace DoExport {
static void init_gcode_processor(const PrintConfig& config, GCodeProcessor& processor, bool& silent_time_estimator_enabled)
//1.9.7.52
static void init_gcode_processor(const PrintConfig& config, GCodeProcessor& processor, bool& silent_time_estimator_enabled,const std::vector<Extruder>& filaments)
{
silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlinLegacy || config.gcode_flavor == gcfMarlinFirmware)
&& config.silent_mode;
processor.reset();
processor.apply_config(config);
processor.enable_stealth_time_estimator(silent_time_estimator_enabled);
//1.9.7.52
processor.set_filaments(filaments);
}
#if 0
@@ -1586,7 +1595,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
PROFILE_FUNC();
// modifies m_silent_time_estimator_enabled
DoExport::init_gcode_processor(print.config(), m_processor, m_silent_time_estimator_enabled);
//1.9.7.52
DoExport::init_gcode_processor(print.config(), m_processor, m_silent_time_estimator_enabled, m_writer.extruders());
// resets analyzer's tracking data
m_last_height = 0.f;
m_last_layer_z = 0.f;
@@ -1669,6 +1679,15 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
//file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Estimated_Printing_Time_Placeholder).c_str());
//QDS: total layer number
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Total_Layer_Number_Placeholder).c_str());
//1.9.7.52
//QDS: total filament used in mm
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Used_Filament_Length_Placeholder).c_str());
//QDS: total filament used in cm3
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Used_Filament_Volume_Placeholder).c_str());
//QDS: total filament used in g
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Used_Filament_Weight_Placeholder).c_str());
//QDS: judge whether support skipping, if yes, list all label_object_id with sorted order here
if (print.num_object_instances() <= g_max_label_object && //Don't support too many objects on one plate
(print.num_object_instances() > 1) && //Don't support skipping single object
@@ -2399,12 +2418,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
has_wipe_tower, print.wipe_tower_data(),
m_writer.extruders(),
// Modifies
print.m_print_statistics));
file.write("\n");*/
//file.write_format("; total filament weight [g] = %.2lf\n", print.m_print_statistics.total_weight);
//file.write_format("; total filament cost = %.2lf\n", print.m_print_statistics.total_cost);
//if (print.m_print_statistics.total_toolchanges > 0)
// file.write_format("; total filament change = %i\n", print.m_print_statistics.total_toolchanges);
print.m_print_statistics));*/
bool activate_air_filtration = false;
for (const auto& extruder : m_writer.extruders())
@@ -4677,41 +4691,38 @@ ExtrusionPaths GCode::split_and_mapping_speed(double &other_path_v, double &fina
ExtrusionPaths GCode::merge_same_speed_paths(const ExtrusionPaths &paths)
{
ExtrusionPaths output_paths;
//1.9.7.52
std::optional<ExtrusionPath> merged_path;
size_t path_idx = 0;
int merge_start = 0;
ExtrusionPath merge_path;
for (; path_idx < paths.size(); path_idx++) {
for(size_t path_idx=0;path_idx<paths.size();++path_idx){
ExtrusionPath path = paths[path_idx];
path.smooth_speed = get_path_speed(path);
path.smooth_speed = get_path_speed(path);
// 100% overhang speed will not to set smooth speed
if (path.role() == erOverhangPerimeter) {
if (!merge_path.empty()) {
output_paths.push_back(std::move(merge_path));
merge_path.polyline.clear();
if(path.role() == erOverhangPerimeter){
if(merged_path.has_value()){
output_paths.push_back(std::move(*merged_path));
merged_path=std::nullopt;
}
output_paths.push_back(std::move(path));
merge_start = path_idx + 1;
output_paths.emplace_back(path);
continue;
}
if (merge_start == path_idx) {
merge_path = path;
if(!merged_path.has_value()){
merged_path=path;
continue;
}
// merge path with same speed
if (merge_path.smooth_speed == path.smooth_speed) {
merge_path.polyline.append(path.polyline);
} else {
output_paths.push_back(std::move(merge_path));
merge_path = path;
if(merged_path->can_merge(path)){
merged_path->polyline.append(path.polyline);
}
else{
output_paths.push_back(std::move(*merged_path));
merged_path = path;
}
}
if (!merge_path.empty() && merge_start < paths.size())
output_paths.push_back(std::move(merge_path));
if(merged_path.has_value())
output_paths.push_back(std::move(*merged_path));
return output_paths;
}
@@ -5594,6 +5605,10 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z, bool b
dyn_config.set_key_value("flush_length", new ConfigOptionFloat(wipe_length));
int flush_count = std::min(g_max_flush_count, (int)std::round(wipe_volume / g_purge_volume_one_time));
//1.9.7.52
// handle cases for very small purge
if (flush_count == 0 && wipe_volume > 0)
flush_count += 1;
float flush_unit = wipe_length / flush_count;
int flush_idx = 0;
for (; flush_idx < flush_count; flush_idx++) {

View File

@@ -61,7 +61,11 @@ const std::vector<std::string> GCodeProcessor::Reserved_Tags = {
"_GP_ESTIMATED_PRINTING_TIME_PLACEHOLDER",
"_GP_TOTAL_LAYER_NUMBER_PLACEHOLDER",
" WIPE_TOWER_START",
" WIPE_TOWER_END"
//1.9.7.52
" WIPE_TOWER_END",
"_GP_FILAMENT_USED_WEIGHT_PLACEHOLDER",
"_GP_FILAMENT_USED_VOLUME_PLACEHOLDER",
"_GP_FILAMENT_USED_LENGTH_PLACEHOLDER"
};
const std::string GCodeProcessor::Flush_Start_Tag = " FLUSH_START";
@@ -370,7 +374,8 @@ void GCodeProcessor::TimeProcessor::reset()
machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Normal)].enabled = true;
}
void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, std::vector<GCodeProcessorResult::MoveVertex>& moves, std::vector<size_t>& lines_ends, size_t total_layer_num)
//1.9.7.52
void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, std::vector<GCodeProcessorResult::MoveVertex>& moves, std::vector<size_t>& lines_ends, const TimeProcessContext& context)
{
FilePtr in{ boost::nowide::fopen(filename.c_str(), "rb") };
if (in.f == nullptr)
@@ -447,6 +452,20 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st
// gcode_line is in/out parameter, to reduce expensive memory allocation
auto process_placeholders = [&](std::string& gcode_line) {
unsigned int extra_lines_count = 0;
//1.9.7.52
auto format_filament_used_info = [](const std::string& info, std::map<size_t, double>val_per_extruder) {
auto double_to_fmt_string = [](double num) -> std::string {
char buf[20];
sprintf(buf, "%.2f", num);
return std::string(buf);
};
std::string buf = "; " + info + " : ";
size_t idx = 0;
for (auto item : val_per_extruder)
buf += (idx++ == 0 ? double_to_fmt_string(item.second) : "," + double_to_fmt_string(item.second));
buf += '\n';
return buf;
};
// remove trailing '\n'
auto line = std::string_view(gcode_line).substr(0, gcode_line.length() - 1);
@@ -486,11 +505,12 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st
sprintf(buf, "; estimated printing time (normal mode) = %s\n",
get_time_dhms(machine.time).c_str());
ret += buf;
} else {
}
else {
// QDS estimator
sprintf(buf, "; model printing time: %s; total estimated time: %s\n",
get_time_dhms(machine.time - machine.prepare_time).c_str(),
get_time_dhms(machine.time).c_str());
get_time_dhms(machine.time - machine.prepare_time).c_str(),
get_time_dhms(machine.time).c_str());
ret += buf;
}
}
@@ -499,9 +519,49 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st
//QDS: write total layer number
else if (line == reserved_tag(ETags::Total_Layer_Number_Placeholder)) {
char buf[128];
sprintf(buf, "; total layer number: %zd\n", total_layer_num);
sprintf(buf, "; total layer number: %zd\n", context.total_layer_num);
ret += buf;
}
//1.9.7.52
else if (line == reserved_tag(ETags::Used_Filament_Weight_Placeholder)) {
std::map<size_t, double>total_weight_per_extruder;
for (const auto& pair : context.used_filaments.total_volumes_per_extruder) {
auto filament_id = pair.first;
auto volume = pair.second;
auto iter = std::find_if(context.filament_lists.begin(), context.filament_lists.end(), [filament_id](const Extruder& filament) { return filament.id() == filament_id; });
if (iter == context.filament_lists.end())
continue;
double weight = volume * iter->filament_density() * 0.001;
total_weight_per_extruder[filament_id] += weight;
}
ret += format_filament_used_info("total filament weight [g]", total_weight_per_extruder);
}
else if (line == reserved_tag(ETags::Used_Filament_Volume_Placeholder)) {
std::map<size_t, double>total_volume_per_extruder;
for (const auto& pair : context.used_filaments.total_volumes_per_extruder) {
auto filament_id = pair.first;
auto volume = pair.second;
auto iter = std::find_if(context.filament_lists.begin(), context.filament_lists.end(), [filament_id](const Extruder& filament) { return filament.id() == filament_id; });
if (iter == context.filament_lists.end())
continue;
total_volume_per_extruder[filament_id] += volume;
}
ret += format_filament_used_info("total filament volume [cm^3]", total_volume_per_extruder);
}
else if (line == reserved_tag(ETags::Used_Filament_Length_Placeholder)) {
std::map<size_t, double>total_length_per_extruder;
for (const auto& pair : context.used_filaments.total_volumes_per_extruder) {
auto filament_id = pair.first;
auto volume = pair.second;
auto iter = std::find_if(context.filament_lists.begin(), context.filament_lists.end(), [filament_id](const Extruder& filament) { return filament.id() == filament_id; });
if (iter == context.filament_lists.end())
continue;
double length = volume / (PI * sqr(0.5 * iter->filament_diameter()));
total_length_per_extruder[filament_id] += length;
}
ret += format_filament_used_info("total filament length [mm]", total_length_per_extruder);
}
}
if (! ret.empty())
@@ -1583,7 +1643,9 @@ void GCodeProcessor::finalize(bool post_process)
m_width_compare.output();
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
if (post_process){
m_time_processor.post_process(m_result.filename, m_result.moves, m_result.lines_ends, m_layer_id);
//1.9.7.52
TimeProcessContext context(m_layer_id,m_filament_lists,m_used_filaments);
m_time_processor.post_process(m_result.filename, m_result.moves, m_result.lines_ends, context);
}
#if ENABLE_GCODE_VIEWER_STATISTICS
m_result.time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - m_start_time).count();

View File

@@ -6,6 +6,7 @@
#include "libslic3r/ExtrusionEntity.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/CustomGCode.hpp"
#include "libslic3r/Extruder.hpp"
#include <cstdint>
#include <array>
@@ -285,6 +286,10 @@ namespace Slic3r {
Total_Layer_Number_Placeholder,
Wipe_Tower_Start,
Wipe_Tower_End,
//1.9.7.52
Used_Filament_Weight_Placeholder,
Used_Filament_Volume_Placeholder,
Used_Filament_Length_Placeholder
};
static const std::string& reserved_tag(ETags tag) { return Reserved_Tags[static_cast<unsigned char>(tag)]; }
@@ -460,38 +465,6 @@ namespace Slic3r {
void calculate_time(size_t keep_last_n_blocks = 0, float additional_time = 0.0f);
};
struct TimeProcessor
{
struct Planner
{
// Size of the firmware planner queue. The old 8-bit Marlins usually just managed 16 trapezoidal blocks.
// Let's be conservative and plan for newer boards with more memory.
static constexpr size_t queue_size = 64;
// The firmware recalculates last planner_queue_size trapezoidal blocks each time a new block is added.
// We are not simulating the firmware exactly, we calculate a sequence of blocks once a reasonable number of blocks accumulate.
static constexpr size_t refresh_threshold = queue_size * 4;
};
// extruder_id is currently used to correctly calculate filament load / unload times into the total print time.
// This is currently only really used by the MK3 MMU2:
// extruder_unloaded = true means no filament is loaded yet, all the filaments are parked in the MK3 MMU2 unit.
bool extruder_unloaded;
// allow to skip the lines M201/M203/M204/M205 generated by GCode::print_machine_envelope() for non-Normal time estimate mode
bool machine_envelope_processing_enabled;
MachineEnvelopeConfig machine_limits;
// Additional load / unload times for a filament exchange sequence.
float filament_load_times;
float filament_unload_times;
std::array<TimeMachine, static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count)> machines;
void reset();
// post process the file with the given filename to add remaining time lines M73
// and updates moves' gcode ids accordingly
void post_process(const std::string& filename, std::vector<GCodeProcessorResult::MoveVertex>& moves, std::vector<size_t>& lines_ends, size_t total_layer_num);
};
struct UsedFilaments // filaments per ColorChange
{
double color_change_cache;
@@ -534,6 +507,49 @@ namespace Slic3r {
friend class GCodeProcessor;
};
//1.9.7.52
struct TimeProcessContext
{
size_t total_layer_num;
std::vector<Extruder> filament_lists;
UsedFilaments used_filaments;
TimeProcessContext( size_t total_layer_num_,
const std::vector<Extruder>& filament_lists_,
const UsedFilaments& used_filaments_)
:total_layer_num(total_layer_num_), filament_lists(filament_lists_), used_filaments(used_filaments_) {}
};
struct TimeProcessor
{
struct Planner
{
// Size of the firmware planner queue. The old 8-bit Marlins usually just managed 16 trapezoidal blocks.
// Let's be conservative and plan for newer boards with more memory.
static constexpr size_t queue_size = 64;
// The firmware recalculates last planner_queue_size trapezoidal blocks each time a new block is added.
// We are not simulating the firmware exactly, we calculate a sequence of blocks once a reasonable number of blocks accumulate.
static constexpr size_t refresh_threshold = queue_size * 4;
};
// extruder_id is currently used to correctly calculate filament load / unload times into the total print time.
// This is currently only really used by the MK3 MMU2:
// extruder_unloaded = true means no filament is loaded yet, all the filaments are parked in the MK3 MMU2 unit.
bool extruder_unloaded;
// allow to skip the lines M201/M203/M204/M205 generated by GCode::print_machine_envelope() for non-Normal time estimate mode
bool machine_envelope_processing_enabled;
MachineEnvelopeConfig machine_limits;
// Additional load / unload times for a filament exchange sequence.
float filament_load_times;
float filament_unload_times;
std::array<TimeMachine, static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count)> machines;
void reset();
// post process the file with the given filename to add remaining time lines M73
// and updates moves' gcode ids accordingly
void post_process(const std::string& filename, std::vector<GCodeProcessorResult::MoveVertex>& moves, std::vector<size_t>& lines_ends, const TimeProcessContext& context);
};
public:
class SeamsDetector
{
@@ -677,6 +693,8 @@ namespace Slic3r {
bool m_flushing;
bool m_wipe_tower;
float m_remaining_volume;
//1.9.7.52
std::vector<Extruder> m_filament_lists;
//QDS: x, y offset for gcode generated
double m_x_offset{ 0 };
@@ -750,6 +768,9 @@ namespace Slic3r {
GCodeProcessor();
void apply_config(const PrintConfig& config);
//1.9.7.52
void set_filaments(const std::vector<Extruder>&filament_lists) { m_filament_lists=filament_lists;}
void enable_stealth_time_estimator(bool enabled);
bool is_stealth_time_estimator_enabled() const {
return m_time_processor.machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Stealth)].enabled;

View File

@@ -10,6 +10,7 @@
#include <cmath>
#include <cassert>
#include <random>
#include <thread>
#include <unordered_set>
#include "libslic3r/AABBTreeLines.hpp"
static const int overhang_sampling_number = 6;

View File

@@ -559,7 +559,7 @@ void PrintConfigDef::init_fff_params()
// Maximum extruder temperature, bumped to 1500 to support printing of glass.
//w24
const int max_temp = 350;
const int max_temp = 370;
def = this->add("reduce_crossing_wall", coBool);
def->label = L("Avoid crossing wall");