Skip to content

Commit

Permalink
test mac compile
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Feb 14, 2024
2 parents b165c4b + 4846a39 commit 71e47f1
Show file tree
Hide file tree
Showing 11 changed files with 829 additions and 397 deletions.
7 changes: 5 additions & 2 deletions src/libslic3r/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,11 @@ struct ConfigSubstitutionContext
// A generic value of a configuration option.
class ConfigOption {
public:
// if true, this option doesn't need to be saved, it's a computed value from an other configOption.
// uint32_t because macos crash if it's a bool. and it doesn't change the size of the object because of alignment.
// Flags ta save some states into the option.
// note: uint32_t because macos crash if it's a bool. and it doesn't change the size of the object because of alignment.
// FCO_PHONY: if true, this option doesn't need to be saved (or with empty string), it's a computed value from an other ConfigOption.
// FCO_EXTRUDER_ARRAY: set if the ConfigDef has is_extruder_size(). Only apply to ConfigVectorBase and childs
// FCO_PLACEHOLDER_TEMP: for PlaceholderParser, to be able to recognise temporary fake ConfigOption (for default_XXX() macro)
uint32_t flags;
enum FlagsConfigOption : uint32_t {
FCO_PHONY = 1,
Expand Down
23 changes: 2 additions & 21 deletions src/libslic3r/Fill/Fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ void Layer::make_fills(FillAdaptive::Octree* adaptive_fill_octree, FillAdaptive:
// Unpacks the collection, creates multiple collections per path.
// The path type could be ExtrusionPath, ExtrusionLoop or ExtrusionEntityCollection.
// Why the paths are unpacked?
for (LayerRegion *layerm : m_regions)
for (LayerRegion *layerm : m_regions) {
for (const ExtrusionEntity *thin_fill : layerm->thin_fills.entities()) {
ExtrusionEntityCollection *collection = new ExtrusionEntityCollection();
if (!layerm->fills.can_sort() && layerm->fills.entities().size() > 0 && layerm->fills.entities()[0]->is_collection()) {
Expand All @@ -729,27 +729,8 @@ void Layer::make_fills(FillAdaptive::Octree* adaptive_fill_octree, FillAdaptive:
layerm->fills.append(ExtrusionEntitiesPtr{ collection });
collection->append(*thin_fill);
}
}

#ifndef NDEBUG
for (LayerRegion *layerm : m_regions)
for (size_t i1 = 0; i1 < layerm->fills.entities().size(); ++i1) {
assert(dynamic_cast<ExtrusionEntityCollection*>(layerm->fills.entities()[i1]) != nullptr);
if (!layerm->fills.can_sort() && layerm->fills.entities().size() > 0 && i1 == 0){
ExtrusionEntityCollection* no_sort_fill = static_cast<ExtrusionEntityCollection*>(layerm->fills.entities()[0]);
assert(no_sort_fill != nullptr);
assert(!no_sort_fill->empty());
for (size_t i2 = 0; i2 < no_sort_fill->entities().size(); ++i2) {
ExtrusionEntityCollection* priority_fill = dynamic_cast<ExtrusionEntityCollection*>(no_sort_fill->entities()[i2]);
assert(priority_fill != nullptr);
assert(!priority_fill->empty());
if (!no_sort_fill->can_sort()) {
for (size_t i3 = 0; i3 < priority_fill->entities().size(); ++i3)
assert(dynamic_cast<ExtrusionEntityCollection*>(priority_fill->entities()[i3]) != nullptr);
}
}
}
}
#endif
}

// Create ironing extrusions over top surfaces.
Expand Down
67 changes: 44 additions & 23 deletions src/libslic3r/Format/3mf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3005,13 +3005,20 @@ namespace Slic3r {
opt_tree.put("<xmlattr>.opt_key", opt_key);
} else {
std::ofstream log("ERROR_FILE_TO_SEND_TO_MERILL_PLZZZZ.txt", std::ios_base::app);
log << "error in ranges, can't serialize " << opt_key << ": '" << value << "' " << (config.option(opt_key) != nullptr) << "\n";
if (config.option(opt_key) != nullptr) {
log << "type : " << config.option(opt_key)->type();
const ConfigOption *option = config.option(opt_key);
log << "error in ranges, can't serialize " << opt_key << ": '" << value << "' " << (option != nullptr) << "\n";
if (option != nullptr) {
log << "type : " << option->type();
log << ", flags : " << option->flags;
log << ", phony : " << option->is_phony();
log << ", serialized : '" << option->serialize() << "'";
log << "\n";
}
if (config.option(opt_key) != nullptr && config.option(opt_key)->type() == ConfigOptionType::coEnum) {
log << "enum : " << config.option(opt_key)->get_int();
log << "Keys in config:";
for(const std::string &k : config.keys()) log << " " << k;
log << "\n";
if (option != nullptr && option->type() == ConfigOptionType::coEnum) {
log << "enum : " << option->get_int();
log << "\n";
const ConfigOptionDef* def = nullptr;
try {
Expand All @@ -3025,8 +3032,8 @@ namespace Slic3r {
}
}
}
if (config.option(opt_key) != nullptr && config.option(opt_key)->type() == ConfigOptionType::coInt) {
log << "int : " << config.option(opt_key)->get_int();
if (option != nullptr && option->type() == ConfigOptionType::coInt) {
log << "int : " << option->get_int();
log << "\n";
}
log.close();
Expand Down Expand Up @@ -3230,16 +3237,23 @@ namespace Slic3r {
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << OBJECT_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << value << "\"/>\n";
} else {
std::ofstream log("ERROR_FILE_TO_SEND_TO_MERILL_PLZZZZ.txt", std::ios_base::app);
log << "error in model, can't serialize " << key << ": '" << value << "' " << (obj->config.option(key) != nullptr) << "\n";
if (obj->config.option(key) != nullptr) {
log << "type : " << obj->config.option(key)->type();
const ConfigOption *option = obj->config.option(key);
log << "error in model, can't serialize " << key << ": '" << value << "' " << (option != nullptr) << "\n";
if (option != nullptr) {
log << "type : " << option->type();
log << ", flags : " << option->flags;
log << ", phony : " << option->is_phony();
log << ", serialized : '" << option->serialize() << "'";
log << "\n";
}
if (obj->config.option(key) != nullptr && obj->config.option(key)->type() == ConfigOptionType::coEnum) {
log << "Keys in obj:";
for(const std::string &k : obj->config.keys()) log << " " << k;
log << "\n";
if (option != nullptr && option->type() == ConfigOptionType::coEnum) {
try{
log << "raw_int_value : " << obj->config.option(key)->get_int() << "\n";
log << "raw_int_value : " << option->get_int() << "\n";
} catch (std::exception ex) {}
log << "enum : " << obj->config.option(key)->get_int();
log << "enum : " << option->get_int();
log << "\n";
const ConfigOptionDef* def = nullptr;
try {
Expand All @@ -3253,8 +3267,8 @@ namespace Slic3r {
}
}
}
if (obj->config.option(key) != nullptr && obj->config.option(key)->type() == ConfigOptionType::coInt) {
log << "int : " << obj->config.option(key)->get_int();
if (option != nullptr && option->type() == ConfigOptionType::coInt) {
log << "int : " << option->get_int();
log << "\n";
}
log.close();
Expand Down Expand Up @@ -3338,16 +3352,23 @@ namespace Slic3r {
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << value << "\"/>\n";
} else {
std::ofstream log("ERROR_FILE_TO_SEND_TO_MERILL_PLZZZZ.txt", std::ios_base::app);
log << "error in volume, can't serialize " << key << ": '" << value << "' " << ((volume->config.option(key) != nullptr)?"exist":"doesn't exist") << "\n";
if (volume->config.option(key) != nullptr) {
log << "type : " << volume->config.option(key)->type();
const ConfigOption *option = volume->config.option(key);
log << "error in volume, can't serialize " << key << ": '" << value << "' " << ((option != nullptr)?"exist":"doesn't exist") << "\n";
if (option != nullptr) {
log << "type : " << option->type();
log << ", flags : " << option->flags;
log << ", phony : " << option->is_phony();
log << ", serialized : '" << option->serialize() << "'";
log << "\n";
}
if (volume->config.option(key) != nullptr && volume->config.option(key)->type() == ConfigOptionType::coEnum) {
log << "Keys in volume:";
for(const std::string &k : volume->config.keys()) log << " " << k;
log << "\n";
if (option != nullptr && option->type() == ConfigOptionType::coEnum) {
try{
log << "raw_int_value : " << volume->config.option(key)->get_int() << "\n";
log << "raw_int_value : " << option->get_int() << "\n";
} catch (std::exception ex) {}
log << "enum : " << volume->config.option(key)->get_int();
log << "enum : " << option->get_int();
log << "\n";
const ConfigOptionDef* def = nullptr;
try {
Expand All @@ -3361,8 +3382,8 @@ namespace Slic3r {
}
}
}
if (volume->config.option(key) != nullptr && volume->config.option(key)->type() == ConfigOptionType::coInt) {
log << "int : " << volume->config.option(key)->get_int();
if (option != nullptr && option->type() == ConfigOptionType::coInt) {
log << "int : " << option->get_int();
log << "\n";
}
log.close();
Expand Down
38 changes: 24 additions & 14 deletions src/libslic3r/GCode/FanMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,18 @@ int16_t get_fan_speed(const std::string &line, GCodeFlavor flavor) {

}

void FanMover::_put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec_since_itemtosplit_start, BufferData &&line_to_write) {
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) {
assert(item_to_split != m_buffer.end());
if (nb_sec_since_itemtosplit_start > item_to_split->time * 0.9) {
// if the fan is at the end of the g1 and the diff is less than 10% of the delay, then don't bother
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) {
// doesn't really need to be split, print it after
m_buffer.insert(next(item_to_split), line_to_write);
} else if (nb_sec_since_itemtosplit_start < item_to_split->time * 0.1) {
} else
// does it need to be split?
// if it's almost at the start of the g1, and the time "lost" is less than 10%
if (nb_sec_since_itemtosplit_start < item_to_split->time * 0.1 && nb_sec_since_itemtosplit_start < max_time * 0.1 &&
// and the previous isn't a fan value
(item_to_split == m_buffer.begin() || std::prev(item_to_split)->fan_speed < 0)) {
// doesn't really need to be split, print it before
//will also print before if line_to_split.time == 0
m_buffer.insert(item_to_split, line_to_write);
Expand Down Expand Up @@ -340,11 +346,18 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
if (fan_speed >= 0) {
const auto fan_baseline = (m_writer.config.fan_percentage.value ? 100.0 : 255.0);
fan_speed = 100 * fan_speed / fan_baseline;
//speed change: stop kickstart reverting if any
m_current_kickstart.time = -1;
if (!m_is_custom_gcode) {
// if slow down => put in the queue. if not =>
if (m_back_buffer_fan_speed < fan_speed) {
if (m_current_kickstart.time > 0) {
assert(m_back_buffer_fan_speed == m_current_kickstart.fan_speed);
}
if (m_back_buffer_fan_speed >= fan_speed) {
if (m_current_kickstart.time > 0) {
// stop kiskstart, and slow down
m_current_kickstart.time = -1;
//this fan speed will be printed, to make and end to the kickstart
}
} else {
if (nb_seconds_delay > 0 && (!only_overhangs || current_role == ExtrusionRole::erOverhangPerimeter)) {
//don't put this command in the queue
time = -1;
Expand Down Expand Up @@ -376,7 +389,7 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
time_count -= it->time;
if (time_count< 0) {
//found something that is lower than us
_put_in_middle_G1(it, it->time + time_count, BufferData(std::string(line.raw()), 0, fan_speed, true));
_put_in_middle_G1(it, it->time + time_count, BufferData(std::string(line.raw()), 0, fan_speed, true), nb_seconds_delay);
//found, stop
break;
}
Expand Down Expand Up @@ -502,7 +515,7 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
m_current_kickstart.time -= time;
if (m_current_kickstart.time < 0) {
//prev is possible because we just do a emplace_back.
_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 });
_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);
}
}
}/* else {
Expand Down Expand Up @@ -547,17 +560,14 @@ void FanMover::write_buffer_data()
if (frontdata.fan_speed < 0 || frontdata.fan_speed != m_front_buffer_fan_speed || frontdata.is_kickstart) {
if (frontdata.is_kickstart && frontdata.fan_speed < m_front_buffer_fan_speed) {
// you have to slow down! not kickstart! rewrite the fan speed.
m_process_output += _set_fan(
frontdata.fan_speed); // m_writer.set_fan(frontdata.fan_speed,true); //FIXME extruder id (or use the
// gcode writer, but then you have to disable the multi-thread thing

m_process_output += _set_fan(frontdata.fan_speed) + "\n";
m_front_buffer_fan_speed = frontdata.fan_speed;
} else {
m_process_output += frontdata.raw + "\n";
if (frontdata.fan_speed >= 0) {
if (frontdata.fan_speed >= 0 || frontdata.is_kickstart) {
// note that this is the only place where the fan_speed is set and we print from the buffer, as if the
// fan_speed >= 0 => time == 0 and as this flush all time == 0 lines from the back of the queue...
m_front_buffer_fan_speed = frontdata.fan_speed;
m_front_buffer_fan_speed = frontdata.is_kickstart ? 100 : frontdata.fan_speed;
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/libslic3r/GCode/FanMover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class FanMover
{
private:
const std::regex regex_fan_speed;
const float nb_seconds_delay;
const float nb_seconds_delay; // in s
const bool with_D_option;
const bool relative_e;
const bool only_overhangs;
const float kickstart;
const float kickstart; // in s

GCodeReader m_parser{};
const GCodeWriter& m_writer;
Expand Down Expand Up @@ -76,8 +76,13 @@ class FanMover

private:
BufferData& put_in_buffer(BufferData&& data) {
m_buffer_time_size += data.time;
m_buffer.emplace_back(data);
m_buffer_time_size += data.time;
if (data.fan_speed >= 0 && !m_buffer.empty() && m_buffer.back().fan_speed >= 0) {
// erase last item
m_buffer.back() = data;
} else {
m_buffer.emplace_back(data);
}
return m_buffer.back();
}
std::list<BufferData>::iterator remove_from_buffer(std::list<BufferData>::iterator data) {
Expand All @@ -88,7 +93,7 @@ class FanMover
void _process_gcode_line(GCodeReader& reader, const GCodeReader::GCodeLine& line);
void _process_ACTIVATE_EXTRUDER(const std::string_view command);
void _process_T(const std::string_view command);
void _put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec, BufferData&& line_to_write);
void _put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec, BufferData&& line_to_write, float max_time);
void _print_in_middle_G1(BufferData& line_to_split, float nb_sec, const std::string& line_to_write);
void _remove_slow_fan(int16_t min_speed, float past_sec);
void write_buffer_data();
Expand Down
Loading

0 comments on commit 71e47f1

Please sign in to comment.