mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-29 17:13:15 +08:00
ENH: seperate flush time from other types
jira:NONE Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I4cfeaec770de678b8dac405617b32738a3f68b3d
This commit is contained in:
parent
54375fede2
commit
7020256f59
@ -620,6 +620,7 @@ std::string ExtrusionEntity::role_to_string(ExtrusionRole role)
|
|||||||
case erWipeTower : return L("Prime tower");
|
case erWipeTower : return L("Prime tower");
|
||||||
case erCustom : return L("Custom");
|
case erCustom : return L("Custom");
|
||||||
case erMixed : return L("Multiple");
|
case erMixed : return L("Multiple");
|
||||||
|
case erFlush : return L("Flush");
|
||||||
default : assert(false);
|
default : assert(false);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@ -663,6 +664,8 @@ ExtrusionRole ExtrusionEntity::string_to_role(const std::string_view role)
|
|||||||
return erCustom;
|
return erCustom;
|
||||||
else if (role == L("Multiple"))
|
else if (role == L("Multiple"))
|
||||||
return erMixed;
|
return erMixed;
|
||||||
|
else if (role == L("Flush"))
|
||||||
|
return erFlush;
|
||||||
else
|
else
|
||||||
return erNone;
|
return erNone;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ enum ExtrusionRole : uint8_t {
|
|||||||
erSupportTransition,
|
erSupportTransition,
|
||||||
erWipeTower,
|
erWipeTower,
|
||||||
erCustom,
|
erCustom,
|
||||||
|
erFlush,
|
||||||
// Extrusion role for a collection with multiple extrusion roles.
|
// Extrusion role for a collection with multiple extrusion roles.
|
||||||
erMixed,
|
erMixed,
|
||||||
erCount
|
erCount
|
||||||
|
@ -224,12 +224,12 @@ void GCodeProcessor::TimeMachine::reset()
|
|||||||
prepare_time = 0.0f;
|
prepare_time = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCodeProcessor::TimeMachine::simulate_st_synchronize(float additional_time)
|
void GCodeProcessor::TimeMachine::simulate_st_synchronize(float additional_time, ExtrusionRole target_role)
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
calculate_time(0, additional_time);
|
calculate_time(0, additional_time,target_role);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void planner_forward_pass_kernel(GCodeProcessor::TimeBlock& prev, GCodeProcessor::TimeBlock& curr)
|
static void planner_forward_pass_kernel(GCodeProcessor::TimeBlock& prev, GCodeProcessor::TimeBlock& curr)
|
||||||
@ -302,7 +302,7 @@ static void recalculate_trapezoids(std::vector<GCodeProcessor::TimeBlock>& block
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks, float additional_time)
|
void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks, float additional_time, ExtrusionRole target_role)
|
||||||
{
|
{
|
||||||
if (!enabled || blocks.size() < 2)
|
if (!enabled || blocks.size() < 2)
|
||||||
return;
|
return;
|
||||||
@ -321,11 +321,16 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks, floa
|
|||||||
recalculate_trapezoids(blocks);
|
recalculate_trapezoids(blocks);
|
||||||
|
|
||||||
size_t n_blocks_process = blocks.size() - keep_last_n_blocks;
|
size_t n_blocks_process = blocks.size() - keep_last_n_blocks;
|
||||||
|
bool found_target_block = false;
|
||||||
for (size_t i = 0; i < n_blocks_process; ++i) {
|
for (size_t i = 0; i < n_blocks_process; ++i) {
|
||||||
const TimeBlock& block = blocks[i];
|
const TimeBlock& block = blocks[i];
|
||||||
float block_time = block.time();
|
float block_time = block.time();
|
||||||
if (i == 0)
|
|
||||||
|
bool is_valid_block = target_role == ExtrusionRole::erNone || target_role == block.role || i == n_blocks_process - 1;
|
||||||
|
if (!found_target_block && is_valid_block) {
|
||||||
block_time += additional_time;
|
block_time += additional_time;
|
||||||
|
found_target_block = true;
|
||||||
|
}
|
||||||
|
|
||||||
time += block_time;
|
time += block_time;
|
||||||
gcode_time.cache += block_time;
|
gcode_time.cache += block_time;
|
||||||
@ -344,6 +349,10 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks, floa
|
|||||||
//BBS
|
//BBS
|
||||||
if (block.flags.prepare_stage)
|
if (block.flags.prepare_stage)
|
||||||
prepare_time += block_time;
|
prepare_time += block_time;
|
||||||
|
|
||||||
|
if(!g1_times_cache.empty() && g1_times_cache.back().id == block.g1_line_id)
|
||||||
|
g1_times_cache.back().elapsed_time = time;
|
||||||
|
else
|
||||||
g1_times_cache.push_back({ block.g1_line_id, time });
|
g1_times_cache.push_back({ block.g1_line_id, time });
|
||||||
// update times for remaining time to printer stop placeholders
|
// update times for remaining time to printer stop placeholders
|
||||||
auto it_stop_time = std::lower_bound(stop_times.begin(), stop_times.end(), block.g1_line_id,
|
auto it_stop_time = std::lower_bound(stop_times.begin(), stop_times.end(), block.g1_line_id,
|
||||||
@ -865,6 +874,7 @@ void GCodeProcessor::UsedFilaments::process_support_cache(GCodeProcessor* proces
|
|||||||
void GCodeProcessor::UsedFilaments::update_flush_per_filament(size_t extrude_id, float flush_volume)
|
void GCodeProcessor::UsedFilaments::update_flush_per_filament(size_t extrude_id, float flush_volume)
|
||||||
{
|
{
|
||||||
if (flush_volume != 0.f) {
|
if (flush_volume != 0.f) {
|
||||||
|
role_cache += flush_volume;
|
||||||
if (flush_per_filament.find(extrude_id) != flush_per_filament.end())
|
if (flush_per_filament.find(extrude_id) != flush_per_filament.end())
|
||||||
flush_per_filament[extrude_id] += flush_volume;
|
flush_per_filament[extrude_id] += flush_volume;
|
||||||
else
|
else
|
||||||
@ -1603,7 +1613,7 @@ void GCodeProcessor::finalize(bool post_process)
|
|||||||
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
||||||
TimeMachine& machine = m_time_processor.machines[i];
|
TimeMachine& machine = m_time_processor.machines[i];
|
||||||
TimeMachine::CustomGCodeTime& gcode_time = machine.gcode_time;
|
TimeMachine::CustomGCodeTime& gcode_time = machine.gcode_time;
|
||||||
machine.calculate_time();
|
machine.calculate_time(0, 0, ExtrusionRole::erNone);
|
||||||
if (gcode_time.needed && gcode_time.cache != 0.0f)
|
if (gcode_time.needed && gcode_time.cache != 0.0f)
|
||||||
gcode_time.times.push_back({ CustomGCode::ColorChange, gcode_time.cache });
|
gcode_time.times.push_back({ CustomGCode::ColorChange, gcode_time.cache });
|
||||||
}
|
}
|
||||||
@ -2184,6 +2194,7 @@ bool GCodeProcessor::get_last_z_from_gcode(const std::string& gcode_str, double&
|
|||||||
|
|
||||||
void GCodeProcessor::process_tags(const std::string_view comment, bool producers_enabled)
|
void GCodeProcessor::process_tags(const std::string_view comment, bool producers_enabled)
|
||||||
{
|
{
|
||||||
|
static ExtrusionRole prev_role;
|
||||||
// producers tags
|
// producers tags
|
||||||
if (producers_enabled && process_producers_tags(comment))
|
if (producers_enabled && process_producers_tags(comment))
|
||||||
return;
|
return;
|
||||||
@ -2222,12 +2233,15 @@ void GCodeProcessor::process_tags(const std::string_view comment, bool producers
|
|||||||
|
|
||||||
//BBS: flush start tag
|
//BBS: flush start tag
|
||||||
if (boost::starts_with(comment, GCodeProcessor::Flush_Start_Tag)) {
|
if (boost::starts_with(comment, GCodeProcessor::Flush_Start_Tag)) {
|
||||||
|
prev_role = m_extrusion_role;
|
||||||
|
set_extrusion_role(erFlush);
|
||||||
m_flushing = true;
|
m_flushing = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//BBS: flush end tag
|
//BBS: flush end tag
|
||||||
if (boost::starts_with(comment, GCodeProcessor::Flush_End_Tag)) {
|
if (boost::starts_with(comment, GCodeProcessor::Flush_End_Tag)) {
|
||||||
|
set_extrusion_role(prev_role);
|
||||||
m_flushing = false;
|
m_flushing = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3201,8 +3215,9 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
|
|||||||
|
|
||||||
blocks.push_back(block);
|
blocks.push_back(block);
|
||||||
|
|
||||||
if (blocks.size() > TimeProcessor::Planner::refresh_threshold)
|
if (blocks.size() > TimeProcessor::Planner::refresh_threshold) {
|
||||||
machine.calculate_time(TimeProcessor::Planner::queue_size);
|
machine.calculate_time(TimeProcessor::Planner::queue_size, 0, erNone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_seams_detector.is_active()) {
|
if (m_seams_detector.is_active()) {
|
||||||
@ -3636,8 +3651,9 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line)
|
|||||||
|
|
||||||
blocks.push_back(block);
|
blocks.push_back(block);
|
||||||
|
|
||||||
if (blocks.size() > TimeProcessor::Planner::refresh_threshold)
|
if (blocks.size() > TimeProcessor::Planner::refresh_threshold) {
|
||||||
machine.calculate_time(TimeProcessor::Planner::queue_size);
|
machine.calculate_time(TimeProcessor::Planner::queue_size, 0, erNone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//BBS: seam detector
|
//BBS: seam detector
|
||||||
@ -4239,11 +4255,29 @@ void GCodeProcessor::process_T(const std::string_view command)
|
|||||||
float extra_time = get_filament_unload_time(static_cast<size_t>(m_last_extruder_id));
|
float extra_time = get_filament_unload_time(static_cast<size_t>(m_last_extruder_id));
|
||||||
m_time_processor.extruder_unloaded = false;
|
m_time_processor.extruder_unloaded = false;
|
||||||
extra_time += get_filament_load_time(static_cast<size_t>(m_extruder_id));
|
extra_time += get_filament_load_time(static_cast<size_t>(m_extruder_id));
|
||||||
simulate_st_synchronize(extra_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
// store tool change move
|
// store tool change move
|
||||||
store_move_vertex(EMoveType::Tool_change);
|
store_move_vertex(EMoveType::Tool_change);
|
||||||
|
// construct a new time block to handle filament change
|
||||||
|
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
||||||
|
TimeMachine& machine = m_time_processor.machines[i];
|
||||||
|
if (!machine.enabled)
|
||||||
|
continue;
|
||||||
|
TimeBlock block;
|
||||||
|
block.role = erFlush;
|
||||||
|
block.move_type = EMoveType::Tool_change;
|
||||||
|
block.layer_id = std::max<unsigned int>(1, m_layer_id);
|
||||||
|
block.g1_line_id = m_g1_line_id;
|
||||||
|
block.flags.prepare_stage = m_processing_start_custom_gcode;
|
||||||
|
block.distance = 0;
|
||||||
|
block.calculate_trapezoid();
|
||||||
|
|
||||||
|
// when do st_sync, we will clear all of the blocks without keeping last n blocks, so we can directly add the new block into the blocks
|
||||||
|
machine.blocks.push_back(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
simulate_st_synchronize(extra_time, erFlush);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4450,7 +4484,7 @@ void GCodeProcessor::process_custom_gcode_time(CustomGCode::Type code)
|
|||||||
gcode_time.needed = true;
|
gcode_time.needed = true;
|
||||||
//FIXME this simulates st_synchronize! is it correct?
|
//FIXME this simulates st_synchronize! is it correct?
|
||||||
// The estimated time may be longer than the real print time.
|
// The estimated time may be longer than the real print time.
|
||||||
machine.simulate_st_synchronize();
|
machine.simulate_st_synchronize(0, erNone);
|
||||||
if (gcode_time.cache != 0.0f) {
|
if (gcode_time.cache != 0.0f) {
|
||||||
gcode_time.times.push_back({ code, gcode_time.cache });
|
gcode_time.times.push_back({ code, gcode_time.cache });
|
||||||
gcode_time.cache = 0.0f;
|
gcode_time.cache = 0.0f;
|
||||||
@ -4472,10 +4506,14 @@ void GCodeProcessor::process_filaments(CustomGCode::Type code)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCodeProcessor::simulate_st_synchronize(float additional_time)
|
void GCodeProcessor::simulate_st_synchronize(float additional_time, ExtrusionRole target_role)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
||||||
m_time_processor.machines[i].simulate_st_synchronize(additional_time);
|
TimeMachine& machine = m_time_processor.machines[i];
|
||||||
|
if (!machine.enabled)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
machine.simulate_st_synchronize(additional_time, target_role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,9 +459,26 @@ namespace Slic3r {
|
|||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
// Simulates firmware st_synchronize() call
|
/**
|
||||||
void simulate_st_synchronize(float additional_time = 0.0f);
|
* @brief Simulates firmware st_synchronize() call
|
||||||
void calculate_time(size_t keep_last_n_blocks = 0, float additional_time = 0.0f);
|
*
|
||||||
|
* Adding additional time to the specified extrusion role's time block.
|
||||||
|
*
|
||||||
|
* @param additional_time Addtional time to calculate
|
||||||
|
* @param target_role Target extrusion role for addtional time.Default is none,means any role is ok.
|
||||||
|
*/
|
||||||
|
void simulate_st_synchronize(float additional_time = 0.0f, ExtrusionRole target_role = ExtrusionRole::erNone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates the time for all blocks
|
||||||
|
*
|
||||||
|
* Computes the time for all blocks.
|
||||||
|
*
|
||||||
|
* @param keep_last_n_blocks The number of last blocks to retain during calculation (default is 0).
|
||||||
|
* @param additional_time Additional time to calculate.
|
||||||
|
* @param target_role Target extrusion role for addtional time.Default is none, means any role is ok.
|
||||||
|
*/
|
||||||
|
void calculate_time(size_t keep_last_n_blocks = 0, float additional_time = 0.0f, ExtrusionRole target_role = ExtrusionRole::erNone);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UsedFilaments // filaments per ColorChange
|
struct UsedFilaments // filaments per ColorChange
|
||||||
@ -964,7 +981,7 @@ namespace Slic3r {
|
|||||||
void process_filaments(CustomGCode::Type code);
|
void process_filaments(CustomGCode::Type code);
|
||||||
|
|
||||||
// Simulates firmware st_synchronize() call
|
// Simulates firmware st_synchronize() call
|
||||||
void simulate_st_synchronize(float additional_time = 0.0f);
|
void simulate_st_synchronize(float additional_time = 0.0f, ExtrusionRole target_role =ExtrusionRole::erNone);
|
||||||
|
|
||||||
void update_estimated_times_stats();
|
void update_estimated_times_stats();
|
||||||
//BBS:
|
//BBS:
|
||||||
|
@ -751,7 +751,8 @@ const std::vector<GCodeViewer::Color> GCodeViewer::Extrusion_Role_Colors {{
|
|||||||
{ 0.00f, 0.50f, 0.00f, 1.0f }, // erSupportMaterialInterface
|
{ 0.00f, 0.50f, 0.00f, 1.0f }, // erSupportMaterialInterface
|
||||||
{ 0.00f, 0.25f, 0.00f, 1.0f }, // erSupportTransition
|
{ 0.00f, 0.25f, 0.00f, 1.0f }, // erSupportTransition
|
||||||
{ 0.70f, 0.89f, 0.67f, 1.0f }, // erWipeTower
|
{ 0.70f, 0.89f, 0.67f, 1.0f }, // erWipeTower
|
||||||
{ 0.37f, 0.82f, 0.58f, 1.0f } // erCustom
|
{ 0.37f, 0.82f, 0.58f, 1.0f }, // erCustom
|
||||||
|
{ 0.85f, 0.65f, 0.95f, 1.0f } // erFlush
|
||||||
}};
|
}};
|
||||||
|
|
||||||
const std::vector<GCodeViewer::Color> GCodeViewer::Options_Colors {{
|
const std::vector<GCodeViewer::Color> GCodeViewer::Options_Colors {{
|
||||||
@ -3096,6 +3097,9 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result, const
|
|||||||
|
|
||||||
last_travel_s_id = move_id;
|
last_travel_s_id = move_id;
|
||||||
}
|
}
|
||||||
|
else if (move.type == EMoveType::Unretract && move.extrusion_role == ExtrusionRole::erFlush) {
|
||||||
|
m_roles.emplace_back(move.extrusion_role);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// roles -> remove duplicates
|
// roles -> remove duplicates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user