Skip to content

Commit 6128659

Browse files
committed
fix legend & kickstart, add discrete colors for legend
2 parents 75855cb + 80ba439 commit 6128659

File tree

9 files changed

+786
-372
lines changed

9 files changed

+786
-372
lines changed

Diff for: src/libslic3r/Fill/Fill.cpp

+2-21
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ void Layer::make_fills(FillAdaptive::Octree* adaptive_fill_octree, FillAdaptive:
715715
// Unpacks the collection, creates multiple collections per path.
716716
// The path type could be ExtrusionPath, ExtrusionLoop or ExtrusionEntityCollection.
717717
// Why the paths are unpacked?
718-
for (LayerRegion *layerm : m_regions)
718+
for (LayerRegion *layerm : m_regions) {
719719
for (const ExtrusionEntity *thin_fill : layerm->thin_fills.entities()) {
720720
ExtrusionEntityCollection *collection = new ExtrusionEntityCollection();
721721
if (!layerm->fills.can_sort() && layerm->fills.entities().size() > 0 && layerm->fills.entities()[0]->is_collection()) {
@@ -729,27 +729,8 @@ void Layer::make_fills(FillAdaptive::Octree* adaptive_fill_octree, FillAdaptive:
729729
layerm->fills.append(ExtrusionEntitiesPtr{ collection });
730730
collection->append(*thin_fill);
731731
}
732+
}
732733

733-
#ifndef NDEBUG
734-
for (LayerRegion *layerm : m_regions)
735-
for (size_t i1 = 0; i1 < layerm->fills.entities().size(); ++i1) {
736-
assert(dynamic_cast<ExtrusionEntityCollection*>(layerm->fills.entities()[i1]) != nullptr);
737-
if (!layerm->fills.can_sort() && layerm->fills.entities().size() > 0 && i1 == 0){
738-
ExtrusionEntityCollection* no_sort_fill = static_cast<ExtrusionEntityCollection*>(layerm->fills.entities()[0]);
739-
assert(no_sort_fill != nullptr);
740-
assert(!no_sort_fill->empty());
741-
for (size_t i2 = 0; i2 < no_sort_fill->entities().size(); ++i2) {
742-
ExtrusionEntityCollection* priority_fill = dynamic_cast<ExtrusionEntityCollection*>(no_sort_fill->entities()[i2]);
743-
assert(priority_fill != nullptr);
744-
assert(!priority_fill->empty());
745-
if (!no_sort_fill->can_sort()) {
746-
for (size_t i3 = 0; i3 < priority_fill->entities().size(); ++i3)
747-
assert(dynamic_cast<ExtrusionEntityCollection*>(priority_fill->entities()[i3]) != nullptr);
748-
}
749-
}
750-
}
751-
}
752-
#endif
753734
}
754735

755736
// Create ironing extrusions over top surfaces.

Diff for: src/libslic3r/GCode/FanMover.cpp

+24-14
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ int16_t get_fan_speed(const std::string &line, GCodeFlavor flavor) {
9191

9292
}
9393

94-
void FanMover::_put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec_since_itemtosplit_start, BufferData &&line_to_write) {
94+
void FanMover::_put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec_since_itemtosplit_start, BufferData &&line_to_write, float max_time) {
9595
assert(item_to_split != m_buffer.end());
96-
if (nb_sec_since_itemtosplit_start > item_to_split->time * 0.9) {
96+
// if the fan is at the end of the g1 and the diff is less than 10% of the delay, then don't bother
97+
if (nb_sec_since_itemtosplit_start > item_to_split->time * 0.9 && (item_to_split->time - nb_sec_since_itemtosplit_start) < max_time * 0.1) {
9798
// doesn't really need to be split, print it after
9899
m_buffer.insert(next(item_to_split), line_to_write);
99-
} else if (nb_sec_since_itemtosplit_start < item_to_split->time * 0.1) {
100+
} else
101+
// does it need to be split?
102+
// if it's almost at the start of the g1, and the time "lost" is less than 10%
103+
if (nb_sec_since_itemtosplit_start < item_to_split->time * 0.1 && nb_sec_since_itemtosplit_start < max_time * 0.1 &&
104+
// and the previous isn't a fan value
105+
(item_to_split == m_buffer.begin() || std::prev(item_to_split)->fan_speed < 0)) {
100106
// doesn't really need to be split, print it before
101107
//will also print before if line_to_split.time == 0
102108
m_buffer.insert(item_to_split, line_to_write);
@@ -340,11 +346,18 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
340346
if (fan_speed >= 0) {
341347
const auto fan_baseline = (m_writer.config.fan_percentage.value ? 100.0 : 255.0);
342348
fan_speed = 100 * fan_speed / fan_baseline;
343-
//speed change: stop kickstart reverting if any
344-
m_current_kickstart.time = -1;
345349
if (!m_is_custom_gcode) {
346350
// if slow down => put in the queue. if not =>
347-
if (m_back_buffer_fan_speed < fan_speed) {
351+
if (m_current_kickstart.time > 0) {
352+
assert(m_back_buffer_fan_speed == m_current_kickstart.fan_speed);
353+
}
354+
if (m_back_buffer_fan_speed >= fan_speed) {
355+
if (m_current_kickstart.time > 0) {
356+
// stop kiskstart, and slow down
357+
m_current_kickstart.time = -1;
358+
//this fan speed will be printed, to make and end to the kickstart
359+
}
360+
} else {
348361
if (nb_seconds_delay > 0 && (!only_overhangs || current_role == ExtrusionRole::erOverhangPerimeter)) {
349362
//don't put this command in the queue
350363
time = -1;
@@ -376,7 +389,7 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
376389
time_count -= it->time;
377390
if (time_count< 0) {
378391
//found something that is lower than us
379-
_put_in_middle_G1(it, it->time + time_count, BufferData(std::string(line.raw()), 0, fan_speed, true));
392+
_put_in_middle_G1(it, it->time + time_count, BufferData(std::string(line.raw()), 0, fan_speed, true), nb_seconds_delay);
380393
//found, stop
381394
break;
382395
}
@@ -502,7 +515,7 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
502515
m_current_kickstart.time -= time;
503516
if (m_current_kickstart.time < 0) {
504517
//prev is possible because we just do a emplace_back.
505-
_put_in_middle_G1(prev(m_buffer.end()), time + m_current_kickstart.time, BufferData{ m_current_kickstart.raw, 0, m_current_kickstart.fan_speed, true });
518+
_put_in_middle_G1(prev(m_buffer.end()), time + m_current_kickstart.time, BufferData{ m_current_kickstart.raw, 0, m_current_kickstart.fan_speed, true }, kickstart);
506519
}
507520
}
508521
}/* else {
@@ -547,17 +560,14 @@ void FanMover::write_buffer_data()
547560
if (frontdata.fan_speed < 0 || frontdata.fan_speed != m_front_buffer_fan_speed || frontdata.is_kickstart) {
548561
if (frontdata.is_kickstart && frontdata.fan_speed < m_front_buffer_fan_speed) {
549562
// you have to slow down! not kickstart! rewrite the fan speed.
550-
m_process_output += _set_fan(
551-
frontdata.fan_speed); // m_writer.set_fan(frontdata.fan_speed,true); //FIXME extruder id (or use the
552-
// gcode writer, but then you have to disable the multi-thread thing
553-
563+
m_process_output += _set_fan(frontdata.fan_speed) + "\n";
554564
m_front_buffer_fan_speed = frontdata.fan_speed;
555565
} else {
556566
m_process_output += frontdata.raw + "\n";
557-
if (frontdata.fan_speed >= 0) {
567+
if (frontdata.fan_speed >= 0 || frontdata.is_kickstart) {
558568
// note that this is the only place where the fan_speed is set and we print from the buffer, as if the
559569
// fan_speed >= 0 => time == 0 and as this flush all time == 0 lines from the back of the queue...
560-
m_front_buffer_fan_speed = frontdata.fan_speed;
570+
m_front_buffer_fan_speed = frontdata.is_kickstart ? 100 : frontdata.fan_speed;
561571
}
562572
}
563573
}

Diff for: src/libslic3r/GCode/FanMover.hpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ class FanMover
3535
{
3636
private:
3737
const std::regex regex_fan_speed;
38-
const float nb_seconds_delay;
38+
const float nb_seconds_delay; // in s
3939
const bool with_D_option;
4040
const bool relative_e;
4141
const bool only_overhangs;
42-
const float kickstart;
42+
const float kickstart; // in s
4343

4444
GCodeReader m_parser{};
4545
const GCodeWriter& m_writer;
@@ -76,8 +76,13 @@ class FanMover
7676

7777
private:
7878
BufferData& put_in_buffer(BufferData&& data) {
79-
m_buffer_time_size += data.time;
80-
m_buffer.emplace_back(data);
79+
m_buffer_time_size += data.time;
80+
if (data.fan_speed >= 0 && !m_buffer.empty() && m_buffer.back().fan_speed >= 0) {
81+
// erase last item
82+
m_buffer.back() = data;
83+
} else {
84+
m_buffer.emplace_back(data);
85+
}
8186
return m_buffer.back();
8287
}
8388
std::list<BufferData>::iterator remove_from_buffer(std::list<BufferData>::iterator data) {
@@ -88,7 +93,7 @@ class FanMover
8893
void _process_gcode_line(GCodeReader& reader, const GCodeReader::GCodeLine& line);
8994
void _process_ACTIVATE_EXTRUDER(const std::string_view command);
9095
void _process_T(const std::string_view command);
91-
void _put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec, BufferData&& line_to_write);
96+
void _put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec, BufferData&& line_to_write, float max_time);
9297
void _print_in_middle_G1(BufferData& line_to_split, float nb_sec, const std::string& line_to_write);
9398
void _remove_slow_fan(int16_t min_speed, float past_sec);
9499
void write_buffer_data();

Diff for: src/libslic3r/GCodeWriter.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,15 @@ std::string GCodeWriter::_travel_to_z(double z, const std::string &comment)
567567
gcode << " F" << F_NUM(speed * 60.0);
568568
COMMENT(comment);
569569
gcode << "\n";
570-
return gcode.str();
570+
// replace 'Z-0' by ' Z0'
571+
std::string str = gcode.str();
572+
if (auto it = str.find("Z-0 "); it != std::string::npos) {
573+
str.replace(it, 2, "Z");
574+
}
575+
if (auto it = str.find("Z-0\n"); it != std::string::npos) {
576+
str.replace(it, 2, "Z");
577+
}
578+
return str;
571579
}
572580

573581
bool GCodeWriter::will_move_z(double z) const
@@ -641,7 +649,15 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std
641649
gcode << " " << m_extrusion_axis << E_NUM(m_tool->E());
642650
COMMENT(comment);
643651
gcode << "\n";
644-
return gcode.str();
652+
// replace 'Z-0' by ' Z0'
653+
std::string str = gcode.str();
654+
if (auto it = str.find("Z-0 "); it != std::string::npos) {
655+
str.replace(it, 2, "Z");
656+
}
657+
if (auto it = str.find("Z-0\n"); it != std::string::npos) {
658+
str.replace(it, 2, "Z");
659+
}
660+
return str;
645661
}
646662

647663
std::string GCodeWriter::retract(bool before_wipe)

0 commit comments

Comments
 (0)