Rename m_last_obj_copy to m_current_instance and use struct instead of std::pair.

Also, instead of storing the shift of the instance, store the instance index.
This commit is contained in:
Lukáš Hejl 2023-12-01 11:24:29 +01:00 committed by Martin Šach
parent 317db5fab4
commit 1b0ba60280
2 changed files with 15 additions and 6 deletions

View File

@ -2422,10 +2422,10 @@ void GCodeGenerator::process_layer_single_object(
m_avoid_crossing_perimeters.init_layer(*m_layer); m_avoid_crossing_perimeters.init_layer(*m_layer);
// When starting a new object, use the external motion planner for the first travel move. // When starting a new object, use the external motion planner for the first travel move.
const Point &offset = print_object.instances()[print_instance.instance_id].shift; const Point &offset = print_object.instances()[print_instance.instance_id].shift;
std::pair<const PrintObject*, Point> this_object_copy(&print_object, offset); GCode::PrintObjectInstance next_instance = {&print_object, int(print_instance.instance_id)};
if (m_last_obj_copy != this_object_copy) if (m_current_instance != next_instance)
m_avoid_crossing_perimeters.use_external_mp_once(); m_avoid_crossing_perimeters.use_external_mp_once();
m_last_obj_copy = this_object_copy; m_current_instance = next_instance;
this->set_origin(unscale(offset)); this->set_origin(unscale(offset));
gcode += m_label_objects.start_object(print_instance.print_object.instances()[print_instance.instance_id], GCode::LabelObjects::IncludeName::No); gcode += m_label_objects.start_object(print_instance.print_object.instances()[print_instance.instance_id], GCode::LabelObjects::IncludeName::No);
} }

View File

@ -102,6 +102,15 @@ struct ObjectLayerToPrint
coordf_t print_z() const { return (object_layer != nullptr && support_layer != nullptr) ? 0.5 * (object_layer->print_z + support_layer->print_z) : this->layer()->print_z; } coordf_t print_z() const { return (object_layer != nullptr && support_layer != nullptr) ? 0.5 * (object_layer->print_z + support_layer->print_z) : this->layer()->print_z; }
}; };
struct PrintObjectInstance
{
const PrintObject *print_object = nullptr;
int instance_idx = -1;
bool operator==(const PrintObjectInstance &other) const {return print_object == other.print_object && instance_idx == other.instance_idx; }
bool operator!=(const PrintObjectInstance &other) const { return *this == other; }
};
} // namespace GCode } // namespace GCode
class GCodeGenerator { class GCodeGenerator {
@ -126,7 +135,7 @@ public:
m_brim_done(false), m_brim_done(false),
m_second_layer_things_done(false), m_second_layer_things_done(false),
m_silent_time_estimator_enabled(false), m_silent_time_estimator_enabled(false),
m_last_obj_copy(nullptr, Point(std::numeric_limits<coord_t>::max(), std::numeric_limits<coord_t>::max())) m_current_instance({nullptr, -1})
{} {}
~GCodeGenerator() = default; ~GCodeGenerator() = default;
@ -445,8 +454,8 @@ private:
bool m_brim_done; bool m_brim_done;
// Flag indicating whether the nozzle temperature changes from 1st to 2nd layer were performed. // Flag indicating whether the nozzle temperature changes from 1st to 2nd layer were performed.
bool m_second_layer_things_done; bool m_second_layer_things_done;
// Index of a last object copy extruded. // Pointer to currently exporting PrintObject and instance index.
std::pair<const PrintObject*, Point> m_last_obj_copy; GCode::PrintObjectInstance m_current_instance;
bool m_silent_time_estimator_enabled; bool m_silent_time_estimator_enabled;