2013-12-20 00:36:42 +00:00
|
|
|
#include "Print.hpp"
|
2014-05-06 08:07:18 +00:00
|
|
|
#include "BoundingBox.hpp"
|
2014-11-09 14:27:34 +00:00
|
|
|
#include "ClipperUtils.hpp"
|
2017-02-15 10:05:52 +00:00
|
|
|
#include "Extruder.hpp"
|
2014-12-12 18:14:52 +00:00
|
|
|
#include "Flow.hpp"
|
2014-11-11 20:17:02 +00:00
|
|
|
#include "Geometry.hpp"
|
2018-06-20 11:57:37 +00:00
|
|
|
#include "I18N.hpp"
|
2014-12-12 18:14:52 +00:00
|
|
|
#include "SupportMaterial.hpp"
|
2018-03-23 10:41:20 +00:00
|
|
|
#include "GCode.hpp"
|
2017-05-25 20:27:53 +00:00
|
|
|
#include "GCode/WipeTowerPrusaMM.hpp"
|
2014-08-03 16:41:09 +00:00
|
|
|
#include <algorithm>
|
2017-05-31 15:02:23 +00:00
|
|
|
#include <unordered_set>
|
2016-12-20 18:26:23 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2018-03-23 10:41:20 +00:00
|
|
|
#include <boost/log/trivial.hpp>
|
2013-12-20 00:36:42 +00:00
|
|
|
|
2018-06-27 15:43:54 +00:00
|
|
|
#include "PrintExport.hpp"
|
2013-12-20 00:36:42 +00:00
|
|
|
|
2018-06-20 11:57:37 +00:00
|
|
|
//! macro used to mark string used at localization,
|
|
|
|
//! return same string
|
2018-06-20 16:55:31 +00:00
|
|
|
#define L(s) Slic3r::I18N::translate(s)
|
2018-06-20 11:57:37 +00:00
|
|
|
|
2013-12-20 00:36:42 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
2017-05-30 15:17:26 +00:00
|
|
|
template class PrintState<PrintStep, psCount>;
|
|
|
|
template class PrintState<PrintObjectStep, posCount>;
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
void Print::clear_objects()
|
2014-05-06 08:07:18 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
tbb::mutex::scoped_lock lock(m_mutex);
|
2018-09-14 08:25:20 +00:00
|
|
|
for (PrintObject *object : m_objects)
|
|
|
|
delete object;
|
|
|
|
m_objects.clear();
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintRegion *region : m_regions)
|
2017-05-31 15:02:23 +00:00
|
|
|
delete region;
|
2018-09-11 12:04:47 +00:00
|
|
|
m_regions.clear();
|
2018-09-14 08:25:20 +00:00
|
|
|
this->invalidate_all_steps();
|
2014-05-06 08:07:18 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
void Print::delete_object(size_t idx)
|
2014-05-06 08:07:18 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
tbb::mutex::scoped_lock lock(m_mutex);
|
2014-12-12 19:16:32 +00:00
|
|
|
// destroy object and remove it from our container
|
2018-09-11 12:04:47 +00:00
|
|
|
delete m_objects[idx];
|
|
|
|
m_objects.erase(m_objects.begin() + idx);
|
2017-05-31 10:55:59 +00:00
|
|
|
this->invalidate_all_steps();
|
2014-05-06 08:07:18 +00:00
|
|
|
// TODO: purge unused regions
|
|
|
|
}
|
|
|
|
|
2017-05-31 15:02:23 +00:00
|
|
|
void Print::reload_object(size_t /* idx */)
|
2014-11-07 19:25:05 +00:00
|
|
|
{
|
2018-09-14 08:25:20 +00:00
|
|
|
ModelObjectPtrs model_objects;
|
|
|
|
{
|
|
|
|
tbb::mutex::scoped_lock lock(m_mutex);
|
|
|
|
/* TODO: this method should check whether the per-object config and per-material configs
|
|
|
|
have changed in such a way that regions need to be rearranged or we can just apply
|
|
|
|
the diff and invalidate something. Same logic as apply_config()
|
|
|
|
For now we just re-add all objects since we haven't implemented this incremental logic yet.
|
|
|
|
This should also check whether object volumes (parts) have changed. */
|
|
|
|
// collect all current model objects
|
|
|
|
model_objects.reserve(m_objects.size());
|
|
|
|
for (PrintObject *object : m_objects)
|
|
|
|
model_objects.push_back(object->model_object());
|
|
|
|
// remove our print objects
|
|
|
|
for (PrintObject *object : m_objects)
|
|
|
|
delete object;
|
|
|
|
m_objects.clear();
|
|
|
|
for (PrintRegion *region : m_regions)
|
|
|
|
delete region;
|
|
|
|
m_regions.clear();
|
|
|
|
this->invalidate_all_steps();
|
|
|
|
}
|
|
|
|
// re-add model objects
|
2017-05-30 18:09:34 +00:00
|
|
|
for (ModelObject *mo : model_objects)
|
|
|
|
this->add_model_object(mo);
|
2014-11-07 19:25:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 15:30:18 +00:00
|
|
|
// Reloads the model instances into the print class.
|
|
|
|
// The slicing shall not be running as the modified model instances at the print
|
|
|
|
// are used for the brim & skirt calculation.
|
|
|
|
// Returns true if the brim or skirt have been invalidated.
|
2017-05-30 18:09:34 +00:00
|
|
|
bool Print::reload_model_instances()
|
2014-12-29 21:29:24 +00:00
|
|
|
{
|
2018-09-14 07:28:00 +00:00
|
|
|
tbb::mutex::scoped_lock lock(m_mutex);
|
2014-12-29 21:29:24 +00:00
|
|
|
bool invalidated = false;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects)
|
2017-05-30 18:09:34 +00:00
|
|
|
invalidated |= object->reload_model_instances();
|
2014-12-29 21:29:24 +00:00
|
|
|
return invalidated;
|
|
|
|
}
|
|
|
|
|
2018-07-18 07:37:25 +00:00
|
|
|
PrintObjectPtrs Print::get_printable_objects() const
|
|
|
|
{
|
2018-09-12 09:59:02 +00:00
|
|
|
PrintObjectPtrs printable_objects(m_objects);
|
2018-07-18 07:37:25 +00:00
|
|
|
printable_objects.erase(std::remove_if(printable_objects.begin(), printable_objects.end(), [](PrintObject* o) { return !o->is_printable(); }), printable_objects.end());
|
|
|
|
return printable_objects;
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
PrintRegion* Print::add_region()
|
2014-05-06 08:07:18 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
m_regions.emplace_back(new PrintRegion(this));
|
|
|
|
return m_regions.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintRegion* Print::add_region(const PrintRegionConfig &config)
|
|
|
|
{
|
|
|
|
m_regions.emplace_back(new PrintRegion(this, config));
|
|
|
|
return m_regions.back();
|
2014-05-06 08:07:18 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
// Called by Print::apply_config().
|
|
|
|
// This method only accepts PrintConfig option keys.
|
|
|
|
bool Print::invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys)
|
2014-05-06 08:07:18 +00:00
|
|
|
{
|
2017-05-30 18:09:34 +00:00
|
|
|
if (opt_keys.empty())
|
|
|
|
return false;
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2017-05-31 15:02:23 +00:00
|
|
|
// Cache the plenty of parameters, which influence the G-code generator only,
|
|
|
|
// or they are only notes not influencing the generated G-code.
|
2018-03-28 15:05:31 +00:00
|
|
|
static std::unordered_set<std::string> steps_gcode = {
|
2017-11-28 14:19:57 +00:00
|
|
|
"avoid_crossing_perimeters",
|
|
|
|
"bed_shape",
|
|
|
|
"bed_temperature",
|
|
|
|
"before_layer_gcode",
|
|
|
|
"between_objects_gcode",
|
|
|
|
"bridge_acceleration",
|
|
|
|
"bridge_fan_speed",
|
|
|
|
"cooling",
|
|
|
|
"default_acceleration",
|
|
|
|
"deretract_speed",
|
|
|
|
"disable_fan_first_layers",
|
|
|
|
"duplicate_distance",
|
|
|
|
"end_gcode",
|
|
|
|
"end_filament_gcode",
|
|
|
|
"extrusion_axis",
|
|
|
|
"extruder_clearance_height",
|
|
|
|
"extruder_clearance_radius",
|
|
|
|
"extruder_colour",
|
|
|
|
"extruder_offset",
|
|
|
|
"extrusion_multiplier",
|
|
|
|
"fan_always_on",
|
|
|
|
"fan_below_layer_time",
|
|
|
|
"filament_colour",
|
|
|
|
"filament_diameter",
|
|
|
|
"filament_density",
|
|
|
|
"filament_notes",
|
|
|
|
"filament_cost",
|
|
|
|
"filament_max_volumetric_speed",
|
|
|
|
"first_layer_acceleration",
|
|
|
|
"first_layer_bed_temperature",
|
|
|
|
"first_layer_speed",
|
|
|
|
"gcode_comments",
|
|
|
|
"gcode_flavor",
|
|
|
|
"infill_acceleration",
|
|
|
|
"layer_gcode",
|
|
|
|
"min_fan_speed",
|
|
|
|
"max_fan_speed",
|
2018-03-09 09:40:42 +00:00
|
|
|
"max_print_height",
|
2017-11-28 14:19:57 +00:00
|
|
|
"min_print_speed",
|
|
|
|
"max_print_speed",
|
|
|
|
"max_volumetric_speed",
|
|
|
|
"max_volumetric_extrusion_rate_slope_positive",
|
|
|
|
"max_volumetric_extrusion_rate_slope_negative",
|
|
|
|
"notes",
|
|
|
|
"only_retract_when_crossing_perimeters",
|
|
|
|
"output_filename_format",
|
|
|
|
"perimeter_acceleration",
|
|
|
|
"post_process",
|
|
|
|
"printer_notes",
|
|
|
|
"retract_before_travel",
|
|
|
|
"retract_before_wipe",
|
|
|
|
"retract_layer_change",
|
|
|
|
"retract_length",
|
|
|
|
"retract_length_toolchange",
|
|
|
|
"retract_lift",
|
|
|
|
"retract_lift_above",
|
|
|
|
"retract_lift_below",
|
|
|
|
"retract_restart_extra",
|
|
|
|
"retract_restart_extra_toolchange",
|
|
|
|
"retract_speed",
|
2018-07-27 20:19:46 +00:00
|
|
|
"single_extruder_multi_material_priming",
|
2017-11-28 14:19:57 +00:00
|
|
|
"slowdown_below_layer_time",
|
|
|
|
"standby_temperature_delta",
|
|
|
|
"start_gcode",
|
|
|
|
"start_filament_gcode",
|
|
|
|
"toolchange_gcode",
|
|
|
|
"threads",
|
|
|
|
"travel_speed",
|
|
|
|
"use_firmware_retraction",
|
|
|
|
"use_relative_e_distances",
|
|
|
|
"use_volumetric_e",
|
|
|
|
"variable_layer_height",
|
2018-07-27 13:56:27 +00:00
|
|
|
"wipe",
|
|
|
|
"wipe_tower_x",
|
|
|
|
"wipe_tower_y",
|
|
|
|
"wipe_tower_rotation_angle"
|
2017-11-28 14:19:57 +00:00
|
|
|
};
|
2017-05-31 15:02:23 +00:00
|
|
|
|
2018-03-28 17:47:26 +00:00
|
|
|
static std::unordered_set<std::string> steps_ignore;
|
2018-03-28 15:05:31 +00:00
|
|
|
|
2017-05-30 15:17:26 +00:00
|
|
|
std::vector<PrintStep> steps;
|
|
|
|
std::vector<PrintObjectStep> osteps;
|
2017-05-31 15:02:23 +00:00
|
|
|
bool invalidated = false;
|
2018-06-07 14:19:57 +00:00
|
|
|
|
2017-05-30 15:17:26 +00:00
|
|
|
for (const t_config_option_key &opt_key : opt_keys) {
|
2018-03-28 15:05:31 +00:00
|
|
|
if (steps_gcode.find(opt_key) != steps_gcode.end()) {
|
2017-05-31 15:02:23 +00:00
|
|
|
// These options only affect G-code export or they are just notes without influence on the generated G-code,
|
|
|
|
// so there is nothing to invalidate.
|
2018-03-28 15:05:31 +00:00
|
|
|
steps.emplace_back(psGCodeExport);
|
|
|
|
} else if (steps_ignore.find(opt_key) != steps_ignore.end()) {
|
|
|
|
// These steps have no influence on the G-code whatsoever. Just ignore them.
|
2017-05-31 15:02:23 +00:00
|
|
|
} else if (
|
|
|
|
opt_key == "skirts"
|
2017-05-30 15:17:26 +00:00
|
|
|
|| opt_key == "skirt_height"
|
|
|
|
|| opt_key == "skirt_distance"
|
|
|
|
|| opt_key == "min_skirt_length"
|
|
|
|
|| opt_key == "ooze_prevention") {
|
|
|
|
steps.emplace_back(psSkirt);
|
|
|
|
} else if (opt_key == "brim_width") {
|
|
|
|
steps.emplace_back(psBrim);
|
|
|
|
steps.emplace_back(psSkirt);
|
2017-05-31 15:02:23 +00:00
|
|
|
} else if (
|
|
|
|
opt_key == "nozzle_diameter"
|
2017-05-30 15:17:26 +00:00
|
|
|
|| opt_key == "resolution") {
|
|
|
|
osteps.emplace_back(posSlice);
|
2017-05-25 20:27:53 +00:00
|
|
|
} else if (
|
2017-05-30 15:17:26 +00:00
|
|
|
opt_key == "complete_objects"
|
|
|
|
|| opt_key == "filament_type"
|
2017-05-31 15:02:23 +00:00
|
|
|
|| opt_key == "filament_soluble"
|
2017-05-30 15:17:26 +00:00
|
|
|
|| opt_key == "first_layer_temperature"
|
2018-03-05 09:45:35 +00:00
|
|
|
|| opt_key == "filament_loading_speed"
|
2018-08-21 12:36:24 +00:00
|
|
|
|| opt_key == "filament_loading_speed_start"
|
2018-03-05 09:45:35 +00:00
|
|
|
|| opt_key == "filament_unloading_speed"
|
2018-08-14 14:23:23 +00:00
|
|
|
|| opt_key == "filament_unloading_speed_start"
|
2018-03-05 09:45:35 +00:00
|
|
|
|| opt_key == "filament_toolchange_delay"
|
2018-04-24 11:02:08 +00:00
|
|
|
|| opt_key == "filament_cooling_moves"
|
2018-08-02 13:14:12 +00:00
|
|
|
|| opt_key == "filament_minimal_purge_on_wipe_tower"
|
2018-04-24 11:02:08 +00:00
|
|
|
|| opt_key == "filament_cooling_initial_speed"
|
|
|
|
|| opt_key == "filament_cooling_final_speed"
|
2018-03-15 13:04:12 +00:00
|
|
|
|| opt_key == "filament_ramming_parameters"
|
2017-05-30 15:17:26 +00:00
|
|
|
|| opt_key == "gcode_flavor"
|
2018-08-06 14:31:51 +00:00
|
|
|
|| opt_key == "infill_first"
|
2017-05-30 15:17:26 +00:00
|
|
|
|| opt_key == "single_extruder_multi_material"
|
|
|
|
|| opt_key == "spiral_vase"
|
|
|
|
|| opt_key == "temperature"
|
|
|
|
|| opt_key == "wipe_tower"
|
|
|
|
|| opt_key == "wipe_tower_width"
|
2018-03-12 14:41:25 +00:00
|
|
|
|| opt_key == "wipe_tower_bridging"
|
2018-03-20 14:07:18 +00:00
|
|
|
|| opt_key == "wiping_volumes_matrix"
|
2018-04-12 13:38:05 +00:00
|
|
|
|| opt_key == "parking_pos_retraction"
|
|
|
|
|| opt_key == "cooling_tube_retraction"
|
|
|
|
|| opt_key == "cooling_tube_length"
|
2018-04-16 12:26:57 +00:00
|
|
|
|| opt_key == "extra_loading_move"
|
2017-05-30 15:17:26 +00:00
|
|
|
|| opt_key == "z_offset") {
|
|
|
|
steps.emplace_back(psWipeTower);
|
2017-05-31 15:02:23 +00:00
|
|
|
} else if (
|
|
|
|
opt_key == "first_layer_extrusion_width"
|
|
|
|
|| opt_key == "min_layer_height"
|
|
|
|
|| opt_key == "max_layer_height") {
|
2017-05-30 15:17:26 +00:00
|
|
|
osteps.emplace_back(posPerimeters);
|
|
|
|
osteps.emplace_back(posInfill);
|
|
|
|
osteps.emplace_back(posSupportMaterial);
|
|
|
|
steps.emplace_back(psSkirt);
|
|
|
|
steps.emplace_back(psBrim);
|
2014-06-10 22:15:02 +00:00
|
|
|
} else {
|
2014-06-13 09:19:53 +00:00
|
|
|
// for legacy, if we can't handle this option let's invalidate all steps
|
2017-05-31 10:55:59 +00:00
|
|
|
//FIXME invalidate all steps of all objects as well?
|
2017-05-31 15:02:23 +00:00
|
|
|
invalidated |= this->invalidate_all_steps();
|
|
|
|
// Continue with the other opt_keys to possibly invalidate any object specific steps.
|
2014-06-10 22:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-31 15:02:23 +00:00
|
|
|
|
2017-05-30 15:17:26 +00:00
|
|
|
sort_remove_duplicates(steps);
|
|
|
|
for (PrintStep step : steps)
|
|
|
|
invalidated |= this->invalidate_step(step);
|
|
|
|
sort_remove_duplicates(osteps);
|
|
|
|
for (PrintObjectStep ostep : osteps)
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects)
|
2017-05-31 10:55:59 +00:00
|
|
|
invalidated |= object->invalidate_step(ostep);
|
2014-06-13 09:19:53 +00:00
|
|
|
return invalidated;
|
2014-06-10 22:15:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:17:26 +00:00
|
|
|
bool Print::invalidate_step(PrintStep step)
|
2014-06-10 22:15:02 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
bool invalidated = m_state.invalidate(step, m_mutex, m_cancel_callback);
|
2017-05-30 15:17:26 +00:00
|
|
|
// Propagate to dependent steps.
|
2017-05-31 15:02:23 +00:00
|
|
|
//FIXME Why should skirt invalidate brim? Shouldn't it be vice versa?
|
2017-05-25 20:27:53 +00:00
|
|
|
if (step == psSkirt)
|
2018-09-11 12:04:47 +00:00
|
|
|
invalidated |= m_state.invalidate(psBrim, m_mutex, m_cancel_callback);
|
2014-06-13 09:19:53 +00:00
|
|
|
return invalidated;
|
2014-06-10 22:15:02 +00:00
|
|
|
}
|
|
|
|
|
2014-11-30 19:18:09 +00:00
|
|
|
// returns true if an object step is done on all objects
|
|
|
|
// and there's at least one object
|
2018-03-28 15:05:31 +00:00
|
|
|
bool Print::is_step_done(PrintObjectStep step) const
|
2014-11-30 19:18:09 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
if (m_objects.empty())
|
2017-05-30 15:17:26 +00:00
|
|
|
return false;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (const PrintObject *object : m_objects)
|
2018-03-28 15:05:31 +00:00
|
|
|
if (!object->m_state.is_done(step))
|
2014-11-30 19:18:09 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-03 16:41:09 +00:00
|
|
|
// returns 0-based indices of used extruders
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<unsigned int> Print::object_extruders() const
|
2014-08-03 16:41:09 +00:00
|
|
|
{
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<unsigned int> extruders;
|
2014-08-03 16:41:09 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintRegion* region : m_regions) {
|
2015-03-06 20:35:00 +00:00
|
|
|
// these checks reflect the same logic used in the GUI for enabling/disabling
|
|
|
|
// extruder selection fields
|
2018-09-11 12:04:47 +00:00
|
|
|
if (region->config().perimeters.value > 0 || m_config.brim_width.value > 0)
|
|
|
|
extruders.push_back(region->config().perimeter_extruder - 1);
|
|
|
|
if (region->config().fill_density.value > 0)
|
|
|
|
extruders.push_back(region->config().infill_extruder - 1);
|
|
|
|
if (region->config().top_solid_layers.value > 0 || region->config().bottom_solid_layers.value > 0)
|
|
|
|
extruders.push_back(region->config().solid_infill_extruder - 1);
|
2014-08-03 16:41:09 +00:00
|
|
|
}
|
2015-03-09 18:27:57 +00:00
|
|
|
|
2017-05-15 09:32:59 +00:00
|
|
|
sort_remove_duplicates(extruders);
|
2015-03-09 18:27:57 +00:00
|
|
|
return extruders;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns 0-based indices of used extruders
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<unsigned int> Print::support_material_extruders() const
|
2015-03-09 18:27:57 +00:00
|
|
|
{
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<unsigned int> extruders;
|
2017-01-30 18:56:46 +00:00
|
|
|
bool support_uses_current_extruder = false;
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects) {
|
2017-05-03 16:28:22 +00:00
|
|
|
if (object->has_support_material()) {
|
2018-09-11 12:04:47 +00:00
|
|
|
if (object->config().support_material_extruder == 0)
|
2017-01-30 18:56:46 +00:00
|
|
|
support_uses_current_extruder = true;
|
|
|
|
else
|
2018-09-11 12:04:47 +00:00
|
|
|
extruders.push_back(object->config().support_material_extruder - 1);
|
|
|
|
if (object->config().support_material_interface_extruder == 0)
|
2017-01-30 18:56:46 +00:00
|
|
|
support_uses_current_extruder = true;
|
|
|
|
else
|
2018-09-11 12:04:47 +00:00
|
|
|
extruders.push_back(object->config().support_material_interface_extruder - 1);
|
2015-03-06 08:56:58 +00:00
|
|
|
}
|
2014-08-03 16:41:09 +00:00
|
|
|
}
|
2017-01-30 18:56:46 +00:00
|
|
|
|
2017-05-03 16:28:22 +00:00
|
|
|
if (support_uses_current_extruder)
|
2017-01-30 18:56:46 +00:00
|
|
|
// Add all object extruders to the support extruders as it is not know which one will be used to print supports.
|
2017-05-03 16:28:22 +00:00
|
|
|
append(extruders, this->object_extruders());
|
2014-08-03 16:41:09 +00:00
|
|
|
|
2017-05-15 09:32:59 +00:00
|
|
|
sort_remove_duplicates(extruders);
|
2014-08-03 16:41:09 +00:00
|
|
|
return extruders;
|
|
|
|
}
|
|
|
|
|
2015-03-09 18:36:23 +00:00
|
|
|
// returns 0-based indices of used extruders
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<unsigned int> Print::extruders() const
|
2015-03-09 18:36:23 +00:00
|
|
|
{
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<unsigned int> extruders = this->object_extruders();
|
|
|
|
append(extruders, this->support_material_extruders());
|
2017-05-15 09:32:59 +00:00
|
|
|
sort_remove_duplicates(extruders);
|
2015-03-09 18:36:23 +00:00
|
|
|
return extruders;
|
|
|
|
}
|
|
|
|
|
2018-10-23 20:53:43 +00:00
|
|
|
unsigned int Print::num_object_instances() const
|
|
|
|
{
|
|
|
|
unsigned int instances = 0;
|
|
|
|
for (const PrintObject *print_object : m_objects)
|
|
|
|
instances += print_object->copies().size();
|
|
|
|
return instances;
|
|
|
|
}
|
|
|
|
|
2017-05-03 16:28:22 +00:00
|
|
|
void Print::_simplify_slices(double distance)
|
2014-08-03 16:41:09 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects) {
|
|
|
|
for (Layer *layer : object->m_layers) {
|
2017-05-30 18:09:34 +00:00
|
|
|
layer->slices.simplify(distance);
|
2018-09-11 12:04:47 +00:00
|
|
|
for (LayerRegion *layerm : layer->regions())
|
2017-05-30 18:09:34 +00:00
|
|
|
layerm->slices.simplify(distance);
|
2014-08-03 16:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-03 16:28:22 +00:00
|
|
|
double Print::max_allowed_layer_height() const
|
2014-08-03 16:41:09 +00:00
|
|
|
{
|
2017-05-03 16:28:22 +00:00
|
|
|
double nozzle_diameter_max = 0.;
|
|
|
|
for (unsigned int extruder_id : this->extruders())
|
2018-09-11 12:04:47 +00:00
|
|
|
nozzle_diameter_max = std::max(nozzle_diameter_max, m_config.nozzle_diameter.get_at(extruder_id));
|
2017-05-03 16:28:22 +00:00
|
|
|
return nozzle_diameter_max;
|
2014-08-03 16:41:09 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 12:36:46 +00:00
|
|
|
static PrintRegionConfig region_config_from_model_volume(const PrintRegionConfig &default_region_config, const ModelVolume &volume)
|
|
|
|
{
|
|
|
|
PrintRegionConfig config = default_region_config;
|
|
|
|
normalize_and_apply_config(config, volume.get_object()->config);
|
|
|
|
normalize_and_apply_config(config, volume.config);
|
|
|
|
if (! volume.material_id().empty())
|
|
|
|
normalize_and_apply_config(config, volume.material()->config);
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2017-05-31 10:55:59 +00:00
|
|
|
// Caller is responsible for supplying models whose objects don't collide
|
|
|
|
// and have explicit instance positions.
|
2017-05-03 16:28:22 +00:00
|
|
|
void Print::add_model_object(ModelObject* model_object, int idx)
|
2014-11-09 11:25:59 +00:00
|
|
|
{
|
2018-09-14 07:28:00 +00:00
|
|
|
tbb::mutex::scoped_lock lock(m_mutex);
|
2017-05-31 10:55:59 +00:00
|
|
|
// Initialize a new print object and store it at the given position.
|
|
|
|
PrintObject *object = new PrintObject(this, model_object, model_object->raw_bounding_box());
|
|
|
|
if (idx != -1) {
|
2018-09-11 12:04:47 +00:00
|
|
|
delete m_objects[idx];
|
|
|
|
m_objects[idx] = object;
|
2017-05-31 10:55:59 +00:00
|
|
|
} else
|
2018-09-11 12:04:47 +00:00
|
|
|
m_objects.emplace_back(object);
|
2017-05-31 10:55:59 +00:00
|
|
|
// Invalidate all print steps.
|
|
|
|
this->invalidate_all_steps();
|
2014-11-09 11:25:59 +00:00
|
|
|
|
2018-10-24 15:20:15 +00:00
|
|
|
// Set the transformation matrix without translation from the first instance.
|
|
|
|
if (! model_object->instances.empty())
|
|
|
|
object->set_trafo(model_object->instances.front()->world_matrix(true));
|
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
size_t volume_id = 0;
|
|
|
|
for (const ModelVolume *volume : model_object->volumes) {
|
|
|
|
if (! volume->is_model_part() && ! volume->is_modifier())
|
|
|
|
continue;
|
2017-05-31 10:55:59 +00:00
|
|
|
// Get the config applied to this volume.
|
2018-10-18 12:36:46 +00:00
|
|
|
PrintRegionConfig config = region_config_from_model_volume(m_default_region_config, *volume);
|
2017-05-31 10:55:59 +00:00
|
|
|
// Find an existing print region with the same config.
|
2017-05-30 15:17:26 +00:00
|
|
|
size_t region_id = size_t(-1);
|
2018-09-11 12:04:47 +00:00
|
|
|
for (size_t i = 0; i < m_regions.size(); ++ i)
|
|
|
|
if (config.equals(m_regions[i]->config())) {
|
2017-05-30 15:17:26 +00:00
|
|
|
region_id = i;
|
2014-11-09 11:25:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-05-31 10:55:59 +00:00
|
|
|
// If no region exists with the same config, create a new one.
|
2017-05-30 15:17:26 +00:00
|
|
|
if (region_id == size_t(-1)) {
|
2018-09-12 09:59:02 +00:00
|
|
|
region_id = m_regions.size();
|
2018-09-11 12:04:47 +00:00
|
|
|
this->add_region(config);
|
2014-11-09 11:25:59 +00:00
|
|
|
}
|
2017-05-31 10:55:59 +00:00
|
|
|
// Assign volume to a region.
|
|
|
|
object->add_region_volume(region_id, volume_id);
|
2018-09-17 13:12:13 +00:00
|
|
|
++ volume_id;
|
2014-11-09 11:25:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-31 10:55:59 +00:00
|
|
|
// Apply config to print object.
|
2018-09-11 12:04:47 +00:00
|
|
|
object->config_apply(this->default_object_config());
|
|
|
|
{
|
|
|
|
//normalize_and_apply_config(object->config(), model_object->config);
|
|
|
|
DynamicPrintConfig src_normalized(model_object->config);
|
|
|
|
src_normalized.normalize();
|
|
|
|
object->config_apply(src_normalized, true);
|
|
|
|
}
|
2016-12-20 18:26:23 +00:00
|
|
|
|
2018-10-18 12:36:46 +00:00
|
|
|
this->update_object_placeholders();
|
2014-11-09 11:25:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
bool Print::apply_config(DynamicPrintConfig config)
|
2014-11-09 11:25:59 +00:00
|
|
|
{
|
2018-09-14 07:28:00 +00:00
|
|
|
tbb::mutex::scoped_lock lock(m_mutex);
|
|
|
|
|
2014-11-09 11:25:59 +00:00
|
|
|
// we get a copy of the config object so we can modify it safely
|
|
|
|
config.normalize();
|
|
|
|
|
|
|
|
// apply variables to placeholder parser
|
2018-09-11 12:04:47 +00:00
|
|
|
m_placeholder_parser.apply_config(config);
|
2014-11-09 11:25:59 +00:00
|
|
|
|
|
|
|
// handle changes to print config
|
2018-09-11 12:04:47 +00:00
|
|
|
t_config_option_keys print_diff = m_config.diff(config);
|
|
|
|
m_config.apply_only(config, print_diff, true);
|
2017-05-31 10:55:59 +00:00
|
|
|
bool invalidated = this->invalidate_state_by_config_options(print_diff);
|
2014-11-09 11:25:59 +00:00
|
|
|
|
|
|
|
// handle changes to object config defaults
|
2018-09-11 12:04:47 +00:00
|
|
|
m_default_object_config.apply(config, true);
|
|
|
|
for (PrintObject *object : m_objects) {
|
2014-11-09 11:25:59 +00:00
|
|
|
// we don't assume that config contains a full ObjectConfig,
|
|
|
|
// so we base it on the current print-wise default
|
2018-09-11 12:04:47 +00:00
|
|
|
PrintObjectConfig new_config = this->default_object_config();
|
2014-11-09 11:25:59 +00:00
|
|
|
// we override the new config with object-specific options
|
2017-05-31 10:55:59 +00:00
|
|
|
normalize_and_apply_config(new_config, object->model_object()->config);
|
2017-06-09 11:27:35 +00:00
|
|
|
// Force a refresh of a variable layer height profile at the PrintObject if it is not valid.
|
|
|
|
if (! object->layer_height_profile_valid) {
|
|
|
|
// The layer_height_profile is not valid for some reason (updated by the user or invalidated due to some option change).
|
|
|
|
// Invalidate the slicing step, which in turn invalidates everything.
|
|
|
|
object->invalidate_step(posSlice);
|
|
|
|
// Trigger recalculation.
|
|
|
|
invalidated = true;
|
|
|
|
}
|
2014-11-09 11:25:59 +00:00
|
|
|
// check whether the new config is different from the current one
|
2018-09-11 12:04:47 +00:00
|
|
|
t_config_option_keys diff = object->config().diff(new_config);
|
|
|
|
object->config_apply_only(new_config, diff, true);
|
2017-05-30 18:09:34 +00:00
|
|
|
invalidated |= object->invalidate_state_by_config_options(diff);
|
2014-11-09 11:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle changes to regions config defaults
|
2018-09-11 12:04:47 +00:00
|
|
|
m_default_region_config.apply(config, true);
|
2014-11-09 11:25:59 +00:00
|
|
|
|
|
|
|
// All regions now have distinct settings.
|
|
|
|
// Check whether applying the new region config defaults we'd get different regions.
|
|
|
|
bool rearrange_regions = false;
|
2017-05-30 18:09:34 +00:00
|
|
|
{
|
2017-05-31 10:55:59 +00:00
|
|
|
// Collect the already visited region configs into other_region_configs,
|
|
|
|
// so one may check for duplicates.
|
|
|
|
std::vector<PrintRegionConfig> other_region_configs;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (size_t region_id = 0; region_id < m_regions.size(); ++ region_id) {
|
|
|
|
PrintRegion ®ion = *m_regions[region_id];
|
2017-05-31 10:55:59 +00:00
|
|
|
PrintRegionConfig this_region_config;
|
|
|
|
bool this_region_config_set = false;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects) {
|
2017-05-31 10:55:59 +00:00
|
|
|
if (region_id < object->region_volumes.size()) {
|
|
|
|
for (int volume_id : object->region_volumes[region_id]) {
|
|
|
|
const ModelVolume &volume = *object->model_object()->volumes[volume_id];
|
|
|
|
if (this_region_config_set) {
|
|
|
|
// If the new config for this volume differs from the other
|
2018-05-15 16:01:47 +00:00
|
|
|
// volume configs currently associated to this region, it means
|
2017-05-31 10:55:59 +00:00
|
|
|
// the region subdivision does not make sense anymore.
|
2018-10-18 12:36:46 +00:00
|
|
|
if (! this_region_config.equals(region_config_from_model_volume(m_default_region_config, volume))) {
|
2017-05-31 10:55:59 +00:00
|
|
|
rearrange_regions = true;
|
|
|
|
goto exit_for_rearrange_regions;
|
|
|
|
}
|
|
|
|
} else {
|
2018-10-18 12:36:46 +00:00
|
|
|
this_region_config = region_config_from_model_volume(m_default_region_config, volume);
|
2017-05-31 10:55:59 +00:00
|
|
|
this_region_config_set = true;
|
|
|
|
}
|
|
|
|
for (const PrintRegionConfig &cfg : other_region_configs) {
|
|
|
|
// If the new config for this volume equals any of the other
|
|
|
|
// volume configs that are not currently associated to this
|
|
|
|
// region, it means the region subdivision does not make
|
|
|
|
// sense anymore.
|
|
|
|
if (cfg.equals(this_region_config)) {
|
|
|
|
rearrange_regions = true;
|
|
|
|
goto exit_for_rearrange_regions;
|
|
|
|
}
|
|
|
|
}
|
2014-11-09 11:25:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-31 10:55:59 +00:00
|
|
|
}
|
|
|
|
if (this_region_config_set) {
|
2018-09-11 12:04:47 +00:00
|
|
|
t_config_option_keys diff = region.config().diff(this_region_config);
|
2017-05-30 18:09:34 +00:00
|
|
|
if (! diff.empty()) {
|
2018-09-11 12:04:47 +00:00
|
|
|
region.config_apply_only(this_region_config, diff, false);
|
|
|
|
for (PrintObject *object : m_objects)
|
2017-05-31 10:55:59 +00:00
|
|
|
if (region_id < object->region_volumes.size() && ! object->region_volumes[region_id].empty())
|
|
|
|
invalidated |= object->invalidate_state_by_config_options(diff);
|
2014-11-09 11:25:59 +00:00
|
|
|
}
|
2017-09-01 15:30:18 +00:00
|
|
|
other_region_configs.emplace_back(std::move(this_region_config));
|
2014-11-09 11:25:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 10:55:59 +00:00
|
|
|
|
|
|
|
exit_for_rearrange_regions:
|
2014-11-09 11:25:59 +00:00
|
|
|
|
|
|
|
if (rearrange_regions) {
|
2017-05-30 18:09:34 +00:00
|
|
|
// The current subdivision of regions does not make sense anymore.
|
|
|
|
// We need to remove all objects and re-add them.
|
2014-11-09 11:25:59 +00:00
|
|
|
ModelObjectPtrs model_objects;
|
2018-09-11 12:04:47 +00:00
|
|
|
model_objects.reserve(m_objects.size());
|
|
|
|
for (PrintObject *object : m_objects)
|
2017-05-30 18:09:34 +00:00
|
|
|
model_objects.push_back(object->model_object());
|
2014-11-09 11:25:59 +00:00
|
|
|
this->clear_objects();
|
2017-06-15 18:15:53 +00:00
|
|
|
for (ModelObject *mo : model_objects)
|
2017-05-30 18:09:34 +00:00
|
|
|
this->add_model_object(mo);
|
2014-11-09 11:25:59 +00:00
|
|
|
invalidated = true;
|
|
|
|
}
|
2017-06-15 18:15:53 +00:00
|
|
|
|
|
|
|
// Always make sure that the layer_height_profiles are set, as they should not be modified from the worker threads.
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects)
|
2017-06-15 18:15:53 +00:00
|
|
|
if (! object->layer_height_profile_valid)
|
|
|
|
object->update_layer_height_profile();
|
2014-11-09 11:25:59 +00:00
|
|
|
|
|
|
|
return invalidated;
|
|
|
|
}
|
|
|
|
|
2018-10-17 09:12:38 +00:00
|
|
|
// Test whether the two models contain the same number of ModelObjects with the same set of IDs
|
|
|
|
// ordered in the same order. In that case it is not necessary to kill the background processing.
|
|
|
|
static inline bool model_object_list_equal(const Model &model_old, const Model &model_new)
|
|
|
|
{
|
|
|
|
if (model_old.objects.size() != model_new.objects.size())
|
|
|
|
return false;
|
|
|
|
for (size_t i = 0; i < model_old.objects.size(); ++ i)
|
|
|
|
if (model_old.objects[i]->id() != model_new.objects[i]->id())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test whether the new model is just an extension of the old model (new objects were added
|
|
|
|
// to the end of the original list. In that case it is not necessary to kill the background processing.
|
|
|
|
static inline bool model_object_list_extended(const Model &model_old, const Model &model_new)
|
|
|
|
{
|
|
|
|
if (model_old.objects.size() >= model_new.objects.size())
|
|
|
|
return false;
|
|
|
|
for (size_t i = 0; i < model_old.objects.size(); ++ i)
|
|
|
|
if (model_old.objects[i]->id() != model_new.objects[i]->id())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool model_volume_list_changed(const ModelObject &model_object_old, const ModelObject &model_object_new, const ModelVolume::Type type)
|
|
|
|
{
|
|
|
|
bool modifiers_differ = false;
|
|
|
|
size_t i_old, i_new;
|
|
|
|
for (i_old = 0, i_new = 0; i_old < model_object_old.volumes.size() && i_new < model_object_new.volumes.size();) {
|
|
|
|
const ModelVolume &mv_old = *model_object_old.volumes[i_old];
|
|
|
|
const ModelVolume &mv_new = *model_object_new.volumes[i_old];
|
|
|
|
if (mv_old.type() != type) {
|
|
|
|
++ i_old;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mv_new.type() != type) {
|
|
|
|
++ i_new;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mv_old.id() != mv_new.id())
|
|
|
|
return true;
|
|
|
|
//FIXME test for the content of the mesh!
|
|
|
|
//FIXME test for the transformation matrices!
|
|
|
|
++ i_old;
|
|
|
|
++ i_new;
|
|
|
|
}
|
|
|
|
for (; i_old < model_object_old.volumes.size(); ++ i_old) {
|
|
|
|
const ModelVolume &mv_old = *model_object_old.volumes[i_old];
|
|
|
|
if (mv_old.type() == type)
|
|
|
|
// ModelVolume was deleted.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (; i_new < model_object_new.volumes.size(); ++ i_new) {
|
|
|
|
const ModelVolume &mv_new = *model_object_new.volumes[i_new];
|
|
|
|
if (mv_new.type() == type)
|
|
|
|
// ModelVolume was added.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void model_volume_list_update_supports(ModelObject &model_object_dst, const ModelObject &model_object_src)
|
|
|
|
{
|
|
|
|
// 1) Delete the support volumes from model_object_dst.
|
|
|
|
{
|
|
|
|
std::vector<ModelVolume*> dst;
|
|
|
|
dst.reserve(model_object_dst.volumes.size());
|
|
|
|
for (ModelVolume *vol : model_object_dst.volumes) {
|
|
|
|
if (vol->is_support_modifier())
|
|
|
|
dst.emplace_back(vol);
|
|
|
|
else
|
|
|
|
delete vol;
|
|
|
|
}
|
|
|
|
model_object_dst.volumes = std::move(dst);
|
|
|
|
}
|
|
|
|
// 2) Copy the support volumes from model_object_src to the end of model_object_dst.
|
|
|
|
for (ModelVolume *vol : model_object_src.volumes) {
|
|
|
|
if (vol->is_support_modifier())
|
|
|
|
model_object_dst.volumes.emplace_back(vol->clone(&model_object_dst));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool transform3d_lower(const Transform3d &lhs, const Transform3d &rhs)
|
|
|
|
{
|
|
|
|
typedef Transform3d::Scalar T;
|
|
|
|
const T *lv = lhs.data();
|
|
|
|
const T *rv = rhs.data();
|
|
|
|
for (size_t i = 0; i < 16; ++ i, ++ lv, ++ rv) {
|
|
|
|
if (*lv < *rv)
|
|
|
|
return true;
|
|
|
|
else if (*lv > *rv)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool transform3d_equal(const Transform3d &lhs, const Transform3d &rhs)
|
|
|
|
{
|
|
|
|
typedef Transform3d::Scalar T;
|
|
|
|
const T *lv = lhs.data();
|
|
|
|
const T *rv = rhs.data();
|
|
|
|
for (size_t i = 0; i < 16; ++ i, ++ lv, ++ rv)
|
|
|
|
if (*lv != *rv)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PrintInstances
|
|
|
|
{
|
|
|
|
Transform3d trafo;
|
2018-10-18 12:36:46 +00:00
|
|
|
Points copies;
|
2018-10-17 09:12:38 +00:00
|
|
|
bool operator<(const PrintInstances &rhs) const { return transform3d_lower(this->trafo, rhs.trafo); }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate a list of trafos and XY offsets for instances of a ModelObject
|
|
|
|
static std::vector<PrintInstances> print_objects_from_model_object(const ModelObject &model_object)
|
|
|
|
{
|
|
|
|
std::set<PrintInstances> trafos;
|
|
|
|
PrintInstances trafo;
|
2018-10-18 12:36:46 +00:00
|
|
|
trafo.copies.assign(1, Point());
|
2018-10-17 09:12:38 +00:00
|
|
|
for (ModelInstance *model_instance : model_object.instances)
|
|
|
|
if (model_instance->is_printable()) {
|
|
|
|
const Vec3d &offst = model_instance->get_offset();
|
|
|
|
trafo.trafo = model_instance->world_matrix(true);
|
2018-10-18 12:36:46 +00:00
|
|
|
trafo.copies.front() = Point::new_scale(offst(0), offst(1));
|
2018-10-17 09:12:38 +00:00
|
|
|
auto it = trafos.find(trafo);
|
|
|
|
if (it == trafos.end())
|
|
|
|
trafos.emplace(trafo);
|
|
|
|
else
|
2018-10-18 12:36:46 +00:00
|
|
|
const_cast<PrintInstances&>(*it).copies.emplace_back(trafo.copies.front());
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
|
|
|
return std::vector<PrintInstances>(trafos.begin(), trafos.end());
|
|
|
|
}
|
|
|
|
|
2018-10-23 20:53:43 +00:00
|
|
|
Print::ApplyStatus Print::apply(const Model &model, const DynamicPrintConfig &config_in)
|
2018-10-17 09:12:38 +00:00
|
|
|
{
|
2018-10-18 12:36:46 +00:00
|
|
|
// Make a copy of the config, normalize it.
|
|
|
|
DynamicPrintConfig config(config_in);
|
|
|
|
config.normalize();
|
|
|
|
// Collect changes to print config.
|
|
|
|
t_config_option_keys print_diff = m_config.diff(config);
|
|
|
|
t_config_option_keys object_diff = m_default_object_config.diff(config);
|
|
|
|
t_config_option_keys region_diff = m_default_region_config.diff(config);
|
|
|
|
|
2018-10-23 20:53:43 +00:00
|
|
|
// Do not use the ApplyStatus as we will use the max function when updating apply_status.
|
|
|
|
unsigned int apply_status = APPLY_STATUS_UNCHANGED;
|
|
|
|
auto update_apply_status = [&apply_status](bool invalidated)
|
|
|
|
{ apply_status = std::max<unsigned int>(apply_status, invalidated ? APPLY_STATUS_INVALIDATED : APPLY_STATUS_CHANGED); };
|
|
|
|
if (! (print_diff.empty() && object_diff.empty() && region_diff.empty()))
|
|
|
|
update_apply_status(false);
|
|
|
|
|
2018-10-17 09:12:38 +00:00
|
|
|
// Grab the lock for the Print / PrintObject milestones.
|
|
|
|
tbb::mutex::scoped_lock lock(m_mutex);
|
|
|
|
|
2018-10-18 12:36:46 +00:00
|
|
|
// The following call may stop the background processing.
|
2018-10-23 20:53:43 +00:00
|
|
|
update_apply_status(this->invalidate_state_by_config_options(print_diff));
|
2018-10-18 12:36:46 +00:00
|
|
|
// Apply variables to placeholder parser. The placeholder parser is used by G-code export,
|
|
|
|
// which should be stopped if print_diff is not empty.
|
2018-10-23 20:53:43 +00:00
|
|
|
if (m_placeholder_parser.apply_config(config))
|
|
|
|
update_apply_status(this->invalidate_step(psGCodeExport));
|
|
|
|
|
2018-10-18 12:36:46 +00:00
|
|
|
// It is also safe to change m_config now after this->invalidate_state_by_config_options() call.
|
|
|
|
m_config.apply_only(config, print_diff, true);
|
|
|
|
// Handle changes to object config defaults
|
|
|
|
m_default_object_config.apply_only(config, object_diff, true);
|
|
|
|
// Handle changes to regions config defaults
|
|
|
|
m_default_region_config.apply_only(config, region_diff, true);
|
|
|
|
|
2018-10-17 09:12:38 +00:00
|
|
|
struct ModelObjectStatus {
|
|
|
|
enum Status {
|
|
|
|
Unknown,
|
|
|
|
Old,
|
|
|
|
New,
|
|
|
|
Moved,
|
|
|
|
Deleted,
|
|
|
|
};
|
|
|
|
ModelObjectStatus(ModelID id, Status status = Unknown) : id(id), status(status) {}
|
2018-10-18 12:36:46 +00:00
|
|
|
ModelID id;
|
|
|
|
Status status;
|
|
|
|
t_config_option_keys object_config_diff;
|
2018-10-17 09:12:38 +00:00
|
|
|
// Search by id.
|
|
|
|
bool operator<(const ModelObjectStatus &rhs) const { return id < rhs.id; }
|
|
|
|
};
|
|
|
|
std::set<ModelObjectStatus> model_object_status;
|
|
|
|
|
|
|
|
// 1) Synchronize model objects.
|
|
|
|
if (model.id() != m_model.id()) {
|
|
|
|
// Kill everything, initialize from scratch.
|
2018-10-18 12:36:46 +00:00
|
|
|
// Stop background processing.
|
|
|
|
m_cancel_callback();
|
2018-10-23 20:53:43 +00:00
|
|
|
update_apply_status(this->invalidate_all_steps());
|
2018-10-17 09:12:38 +00:00
|
|
|
for (PrintObject *object : m_objects) {
|
|
|
|
model_object_status.emplace(object->model_object()->id(), ModelObjectStatus::Deleted);
|
|
|
|
delete object;
|
|
|
|
}
|
|
|
|
m_objects.clear();
|
|
|
|
for (PrintRegion *region : m_regions)
|
|
|
|
delete region;
|
|
|
|
m_regions.clear();
|
|
|
|
m_model = model;
|
2018-10-18 16:03:17 +00:00
|
|
|
for (const ModelObject *model_object : m_model.objects)
|
|
|
|
model_object_status.emplace(model_object->id(), ModelObjectStatus::New);
|
2018-10-17 09:12:38 +00:00
|
|
|
} else {
|
|
|
|
if (model_object_list_equal(m_model, model)) {
|
|
|
|
// The object list did not change.
|
2018-10-18 16:03:17 +00:00
|
|
|
for (const ModelObject *model_object : m_model.objects)
|
|
|
|
model_object_status.emplace(model_object->id(), ModelObjectStatus::Old);
|
2018-10-17 09:12:38 +00:00
|
|
|
} else if (model_object_list_extended(m_model, model)) {
|
|
|
|
// Add new objects. Their volumes and configs will be synchronized later.
|
2018-10-23 20:53:43 +00:00
|
|
|
update_apply_status(this->invalidate_step(psGCodeExport));
|
2018-10-18 12:36:46 +00:00
|
|
|
for (const ModelObject *model_object : m_model.objects)
|
|
|
|
model_object_status.emplace(model_object->id(), ModelObjectStatus::Old);
|
2018-10-17 09:12:38 +00:00
|
|
|
for (size_t i = m_model.objects.size(); i < model.objects.size(); ++ i) {
|
|
|
|
model_object_status.emplace(model.objects[i]->id(), ModelObjectStatus::New);
|
|
|
|
m_model.objects.emplace_back(model.objects[i]->clone(&m_model));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Reorder the objects, add new objects.
|
|
|
|
// First stop background processing before shuffling or deleting the PrintObjects in the object list.
|
|
|
|
m_cancel_callback();
|
|
|
|
this->invalidate_step(psGCodeExport);
|
|
|
|
// Second create a new list of objects.
|
2018-10-23 20:53:43 +00:00
|
|
|
std::vector<ModelObject*> model_objects_old(std::move(m_model.objects));
|
2018-10-17 09:12:38 +00:00
|
|
|
m_model.objects.clear();
|
|
|
|
m_model.objects.reserve(model.objects.size());
|
|
|
|
auto by_id_lower = [](const ModelObject *lhs, const ModelObject *rhs){ return lhs->id() < rhs->id(); };
|
2018-10-23 20:53:43 +00:00
|
|
|
std::sort(model_objects_old.begin(), model_objects_old.end(), by_id_lower);
|
2018-10-17 09:12:38 +00:00
|
|
|
for (const ModelObject *mobj : model.objects) {
|
2018-10-23 20:53:43 +00:00
|
|
|
auto it = std::lower_bound(model_objects_old.begin(), model_objects_old.end(), mobj, by_id_lower);
|
|
|
|
if (it == model_objects_old.end() || (*it)->id() != mobj->id()) {
|
2018-10-17 09:12:38 +00:00
|
|
|
// New ModelObject added.
|
|
|
|
m_model.objects.emplace_back((*it)->clone(&m_model));
|
|
|
|
model_object_status.emplace(mobj->id(), ModelObjectStatus::New);
|
|
|
|
} else {
|
|
|
|
// Existing ModelObject re-added (possibly moved in the list).
|
|
|
|
m_model.objects.emplace_back(*it);
|
2018-10-18 12:36:46 +00:00
|
|
|
model_object_status.emplace(mobj->id(), ModelObjectStatus::Moved);
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool deleted_any = false;
|
2018-10-23 20:53:43 +00:00
|
|
|
for (ModelObject *&model_object : model_objects_old) {
|
|
|
|
if (model_object_status.find(ModelObjectStatus(model_object->id())) == model_object_status.end()) {
|
|
|
|
model_object_status.emplace(model_object->id(), ModelObjectStatus::Deleted);
|
2018-10-17 09:12:38 +00:00
|
|
|
deleted_any = true;
|
2018-10-23 20:53:43 +00:00
|
|
|
} else
|
|
|
|
// Do not delete this ModelObject instance.
|
|
|
|
model_object = nullptr;
|
|
|
|
}
|
2018-10-17 09:12:38 +00:00
|
|
|
if (deleted_any) {
|
|
|
|
// Delete PrintObjects of the deleted ModelObjects.
|
2018-10-23 20:53:43 +00:00
|
|
|
std::vector<PrintObject*> print_objects_old = std::move(m_objects);
|
2018-10-17 09:12:38 +00:00
|
|
|
m_objects.clear();
|
2018-10-23 20:53:43 +00:00
|
|
|
m_objects.reserve(print_objects_old.size());
|
|
|
|
for (PrintObject *print_object : print_objects_old) {
|
2018-10-17 09:12:38 +00:00
|
|
|
auto it_status = model_object_status.find(ModelObjectStatus(print_object->model_object()->id()));
|
|
|
|
assert(it_status != model_object_status.end());
|
|
|
|
if (it_status->status == ModelObjectStatus::Deleted) {
|
2018-10-23 20:53:43 +00:00
|
|
|
update_apply_status(print_object->invalidate_all_steps());
|
2018-10-17 09:12:38 +00:00
|
|
|
delete print_object;
|
|
|
|
} else
|
|
|
|
m_objects.emplace_back(print_object);
|
|
|
|
}
|
2018-10-23 20:53:43 +00:00
|
|
|
for (ModelObject *model_object : model_objects_old)
|
|
|
|
delete model_object;
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2) Map print objects including their transformation matrices.
|
|
|
|
struct PrintObjectStatus {
|
|
|
|
enum Status {
|
|
|
|
Unknown,
|
|
|
|
Deleted,
|
2018-10-30 08:27:31 +00:00
|
|
|
Reused,
|
2018-10-17 09:12:38 +00:00
|
|
|
New
|
|
|
|
};
|
|
|
|
PrintObjectStatus(PrintObject *print_object, Status status = Unknown) :
|
|
|
|
id(print_object->model_object()->id()),
|
|
|
|
print_object(print_object),
|
|
|
|
trafo(print_object->trafo()),
|
|
|
|
status(status) {}
|
|
|
|
PrintObjectStatus(ModelID id) : id(id), print_object(nullptr), trafo(Transform3d::Identity()), status(Unknown) {}
|
|
|
|
// ID of the ModelObject & PrintObject
|
|
|
|
ModelID id;
|
|
|
|
// Pointer to the old PrintObject
|
|
|
|
PrintObject *print_object;
|
|
|
|
// Trafo generated with model_object->world_matrix(true)
|
|
|
|
Transform3d trafo;
|
|
|
|
Status status;
|
|
|
|
// Search by id.
|
|
|
|
bool operator<(const PrintObjectStatus &rhs) const { return id < rhs.id; }
|
|
|
|
};
|
|
|
|
std::multiset<PrintObjectStatus> print_object_status;
|
|
|
|
for (PrintObject *print_object : m_objects)
|
|
|
|
print_object_status.emplace(PrintObjectStatus(print_object));
|
|
|
|
|
|
|
|
// 3) Synchronize ModelObjects & PrintObjects.
|
|
|
|
for (size_t idx_model_object = 0; idx_model_object < model.objects.size(); ++ idx_model_object) {
|
|
|
|
ModelObject &model_object = *m_model.objects[idx_model_object];
|
|
|
|
auto it_status = model_object_status.find(ModelObjectStatus(model_object.id()));
|
|
|
|
assert(it_status != model_object_status.end());
|
|
|
|
assert(it_status->status != ModelObjectStatus::Deleted);
|
|
|
|
if (it_status->status == ModelObjectStatus::New)
|
|
|
|
// PrintObject instances will be added in the next loop.
|
|
|
|
continue;
|
|
|
|
// Update the ModelObject instance, possibly invalidate the linked PrintObjects.
|
2018-10-18 12:36:46 +00:00
|
|
|
assert(it_status->status == ModelObjectStatus::Old || it_status->status == ModelObjectStatus::Moved);
|
2018-10-17 09:12:38 +00:00
|
|
|
const ModelObject &model_object_new = *model.objects[idx_model_object];
|
|
|
|
// Check whether a model part volume was added or removed, their transformations or order changed.
|
|
|
|
bool model_parts_differ = model_volume_list_changed(model_object, model_object_new, ModelVolume::MODEL_PART);
|
|
|
|
bool modifiers_differ = model_volume_list_changed(model_object, model_object_new, ModelVolume::PARAMETER_MODIFIER);
|
|
|
|
bool support_blockers_differ = model_volume_list_changed(model_object, model_object_new, ModelVolume::SUPPORT_BLOCKER);
|
|
|
|
bool support_enforcers_differ = model_volume_list_changed(model_object, model_object_new, ModelVolume::SUPPORT_ENFORCER);
|
2018-10-23 13:27:31 +00:00
|
|
|
if (model_parts_differ || modifiers_differ ||
|
|
|
|
model_object.origin_translation != model_object_new.origin_translation ||
|
|
|
|
model_object.layer_height_ranges != model_object_new.layer_height_ranges ||
|
|
|
|
model_object.layer_height_profile != model_object_new.layer_height_profile ||
|
|
|
|
model_object.layer_height_profile_valid != model_object_new.layer_height_profile_valid) {
|
2018-10-17 09:12:38 +00:00
|
|
|
// The very first step (the slicing step) is invalidated. One may freely remove all associated PrintObjects.
|
|
|
|
auto range = print_object_status.equal_range(PrintObjectStatus(model_object.id()));
|
|
|
|
for (auto it = range.first; it != range.second; ++ it) {
|
2018-10-23 20:53:43 +00:00
|
|
|
update_apply_status(it->print_object->invalidate_all_steps());
|
2018-10-17 09:12:38 +00:00
|
|
|
const_cast<PrintObjectStatus&>(*it).status = PrintObjectStatus::Deleted;
|
|
|
|
}
|
|
|
|
// Copy content of the ModelObject including its ID, reset the parent.
|
|
|
|
model_object = model_object_new;
|
|
|
|
model_object.set_model(&m_model);
|
|
|
|
} else if (support_blockers_differ || support_enforcers_differ) {
|
|
|
|
// First stop background processing before shuffling or deleting the ModelVolumes in the ModelObject's list.
|
|
|
|
m_cancel_callback();
|
|
|
|
// Invalidate just the supports step.
|
|
|
|
auto range = print_object_status.equal_range(PrintObjectStatus(model_object.id()));
|
|
|
|
for (auto it = range.first; it != range.second; ++ it)
|
2018-10-23 20:53:43 +00:00
|
|
|
update_apply_status(it->print_object->invalidate_step(posSupportMaterial));
|
2018-10-17 09:12:38 +00:00
|
|
|
// Copy just the support volumes.
|
|
|
|
model_volume_list_update_supports(model_object, model_object_new);
|
|
|
|
}
|
|
|
|
if (! model_parts_differ && ! modifiers_differ) {
|
|
|
|
// Synchronize the remaining data of ModelVolumes (name, config, m_type, m_material_id)
|
2018-10-18 12:36:46 +00:00
|
|
|
// Synchronize Object's config.
|
|
|
|
t_config_option_keys &this_object_config_diff = const_cast<ModelObjectStatus&>(*it_status).object_config_diff;
|
|
|
|
this_object_config_diff = model_object.config.diff(model_object_new.config);
|
|
|
|
if (! this_object_config_diff.empty())
|
|
|
|
model_object.config.apply_only(model_object_new.config, this_object_config_diff, true);
|
2018-10-23 20:53:43 +00:00
|
|
|
if (! object_diff.empty() || ! this_object_config_diff.empty()) {
|
2018-10-18 12:36:46 +00:00
|
|
|
PrintObjectConfig new_config = m_default_object_config;
|
|
|
|
normalize_and_apply_config(new_config, model_object.config);
|
|
|
|
auto range = print_object_status.equal_range(PrintObjectStatus(model_object.id()));
|
|
|
|
for (auto it = range.first; it != range.second; ++ it) {
|
|
|
|
t_config_option_keys diff = it->print_object->config().diff(new_config);
|
2018-10-23 20:53:43 +00:00
|
|
|
if (! diff.empty()) {
|
|
|
|
update_apply_status(it->print_object->invalidate_state_by_config_options(diff));
|
|
|
|
it->print_object->config_apply_only(new_config, diff, true);
|
|
|
|
}
|
2018-10-18 12:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-23 13:27:31 +00:00
|
|
|
model_object.name = model_object_new.name;
|
|
|
|
model_object.input_file = model_object_new.input_file;
|
2018-10-23 20:53:43 +00:00
|
|
|
model_object.clear_instances();
|
|
|
|
for (const ModelInstance *model_instance : model_object_new.instances)
|
|
|
|
model_object.add_instance(*model_instance);
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4) Generate PrintObjects from ModelObjects and their instances.
|
2018-10-18 12:36:46 +00:00
|
|
|
{
|
|
|
|
std::vector<PrintObject*> print_objects_new;
|
|
|
|
print_objects_new.reserve(std::max(m_objects.size(), m_model.objects.size()));
|
2018-10-30 08:27:31 +00:00
|
|
|
bool new_objects = false;
|
2018-10-18 12:36:46 +00:00
|
|
|
// Walk over all new model objects and check, whether there are matching PrintObjects.
|
|
|
|
for (ModelObject *model_object : m_model.objects) {
|
|
|
|
auto range = print_object_status.equal_range(PrintObjectStatus(model_object->id()));
|
|
|
|
std::vector<const PrintObjectStatus*> old;
|
|
|
|
if (range.first != range.second) {
|
|
|
|
old.reserve(print_object_status.count(PrintObjectStatus(model_object->id())));
|
|
|
|
for (auto it = range.first; it != range.second; ++ it)
|
|
|
|
if (it->status != PrintObjectStatus::Deleted)
|
|
|
|
old.emplace_back(&(*it));
|
|
|
|
}
|
|
|
|
// Generate a list of trafos and XY offsets for instances of a ModelObject
|
|
|
|
PrintObjectConfig config = m_default_object_config;
|
|
|
|
normalize_and_apply_config(config, model_object->config);
|
|
|
|
std::vector<PrintInstances> new_print_instances = print_objects_from_model_object(*model_object);
|
|
|
|
if (old.empty()) {
|
|
|
|
// Simple case, just generate new instances.
|
|
|
|
for (const PrintInstances &print_instances : new_print_instances) {
|
|
|
|
PrintObject *print_object = new PrintObject(this, model_object, model_object->raw_bounding_box());
|
2018-10-24 09:48:39 +00:00
|
|
|
print_object->set_trafo(print_instances.trafo);
|
2018-10-18 12:36:46 +00:00
|
|
|
print_object->set_copies(print_instances.copies);
|
|
|
|
print_object->config_apply(config);
|
|
|
|
print_objects_new.emplace_back(print_object);
|
2018-10-30 08:27:31 +00:00
|
|
|
// print_object_status.emplace(PrintObjectStatus(print_object, PrintObjectStatus::New));
|
|
|
|
new_objects = true;
|
2018-10-18 12:36:46 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Complex case, try to merge the two lists.
|
|
|
|
// Sort the old lexicographically by their trafos.
|
|
|
|
std::sort(old.begin(), old.end(), [](const PrintObjectStatus *lhs, const PrintObjectStatus *rhs){ return transform3d_lower(lhs->trafo, rhs->trafo); });
|
|
|
|
// Merge the old / new lists.
|
|
|
|
auto it_old = old.begin();
|
|
|
|
for (const PrintInstances &new_instances : new_print_instances) {
|
2018-10-24 09:48:39 +00:00
|
|
|
for (; it_old != old.end() && transform3d_lower((*it_old)->trafo, new_instances.trafo); ++ it_old);
|
|
|
|
if (it_old == old.end() || ! transform3d_equal((*it_old)->trafo, new_instances.trafo)) {
|
2018-10-18 12:36:46 +00:00
|
|
|
// This is a new instance (or a set of instances with the same trafo). Just add it.
|
|
|
|
PrintObject *print_object = new PrintObject(this, model_object, model_object->raw_bounding_box());
|
2018-10-24 09:48:39 +00:00
|
|
|
print_object->set_trafo(new_instances.trafo);
|
2018-10-18 12:36:46 +00:00
|
|
|
print_object->set_copies(new_instances.copies);
|
|
|
|
print_object->config_apply(config);
|
|
|
|
print_objects_new.emplace_back(print_object);
|
2018-10-30 08:27:31 +00:00
|
|
|
// print_object_status.emplace(PrintObjectStatus(print_object, PrintObjectStatus::New));
|
|
|
|
new_objects = true;
|
|
|
|
if (it_old != old.end())
|
|
|
|
const_cast<PrintObjectStatus*>(*it_old)->status = PrintObjectStatus::Deleted;
|
2018-10-18 12:36:46 +00:00
|
|
|
} else if ((*it_old)->print_object->copies() != new_instances.copies) {
|
2018-10-23 13:27:31 +00:00
|
|
|
// The PrintObject already exists and the copies differ.
|
2018-10-23 20:53:43 +00:00
|
|
|
if ((*it_old)->print_object->copies().size() != new_instances.copies.size())
|
|
|
|
update_apply_status(this->invalidate_step(psWipeTower));
|
|
|
|
update_apply_status(this->invalidate_step(psSkirt) || this->invalidate_step(psBrim) || this->invalidate_step(psGCodeExport));
|
2018-10-18 12:36:46 +00:00
|
|
|
(*it_old)->print_object->set_copies(new_instances.copies);
|
2018-10-23 13:27:31 +00:00
|
|
|
print_objects_new.emplace_back((*it_old)->print_object);
|
2018-10-30 08:27:31 +00:00
|
|
|
const_cast<PrintObjectStatus*>(*it_old)->status = PrintObjectStatus::Reused;
|
2018-10-23 13:27:31 +00:00
|
|
|
}
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-18 12:36:46 +00:00
|
|
|
if (m_objects != print_objects_new) {
|
|
|
|
m_cancel_callback();
|
|
|
|
m_objects = print_objects_new;
|
2018-10-30 08:27:31 +00:00
|
|
|
// Delete the PrintObjects marked as Unknown or Deleted.
|
|
|
|
bool deleted_objects = false;
|
|
|
|
for (auto &pos : print_object_status)
|
|
|
|
if (pos.status == PrintObjectStatus::Unknown || pos.status == PrintObjectStatus::Deleted) {
|
|
|
|
// update_apply_status(pos.print_object->invalidate_all_steps());
|
|
|
|
delete pos.print_object;
|
|
|
|
deleted_objects = true;
|
|
|
|
}
|
|
|
|
if (deleted_objects)
|
|
|
|
update_apply_status(this->invalidate_step(psSkirt) || this->invalidate_step(psBrim) || this->invalidate_step(psWipeTower) || this->invalidate_step(psGCodeExport));
|
|
|
|
update_apply_status(new_objects);
|
2018-10-18 12:36:46 +00:00
|
|
|
}
|
2018-10-30 08:27:31 +00:00
|
|
|
print_object_status.clear();
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
2018-10-18 12:36:46 +00:00
|
|
|
|
|
|
|
// 5) Synchronize configs of ModelVolumes, synchronize AMF / 3MF materials (and their configs), refresh PrintRegions.
|
|
|
|
// Update reference counts of regions from the remaining PrintObjects and their volumes.
|
|
|
|
// Regions with zero references could and should be reused.
|
|
|
|
for (PrintRegion *region : m_regions)
|
|
|
|
region->m_refcnt = 0;
|
|
|
|
for (PrintObject *print_object : m_objects) {
|
|
|
|
int idx_region = 0;
|
|
|
|
for (const auto &volumes : print_object->region_volumes) {
|
|
|
|
if (! volumes.empty())
|
2018-10-23 13:27:31 +00:00
|
|
|
++ m_regions[idx_region]->m_refcnt;
|
2018-10-18 12:36:46 +00:00
|
|
|
++ idx_region;
|
|
|
|
}
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 12:36:46 +00:00
|
|
|
// All regions now have distinct settings.
|
|
|
|
// Check whether applying the new region config defaults we'd get different regions.
|
|
|
|
for (size_t region_id = 0; region_id < m_regions.size(); ++ region_id) {
|
|
|
|
PrintRegion ®ion = *m_regions[region_id];
|
|
|
|
PrintRegionConfig this_region_config;
|
|
|
|
bool this_region_config_set = false;
|
|
|
|
for (PrintObject *print_object : m_objects) {
|
|
|
|
if (region_id < print_object->region_volumes.size()) {
|
|
|
|
for (int volume_id : print_object->region_volumes[region_id]) {
|
|
|
|
const ModelVolume &volume = *print_object->model_object()->volumes[volume_id];
|
|
|
|
if (this_region_config_set) {
|
|
|
|
// If the new config for this volume differs from the other
|
|
|
|
// volume configs currently associated to this region, it means
|
|
|
|
// the region subdivision does not make sense anymore.
|
|
|
|
if (! this_region_config.equals(region_config_from_model_volume(m_default_region_config, volume)))
|
|
|
|
// Regions were split. Reset this print_object.
|
|
|
|
goto print_object_end;
|
|
|
|
} else {
|
|
|
|
this_region_config = region_config_from_model_volume(m_default_region_config, volume);
|
|
|
|
for (size_t i = 0; i < region_id; ++ i)
|
|
|
|
if (m_regions[i]->config().equals(this_region_config))
|
|
|
|
// Regions were merged. Reset this print_object.
|
|
|
|
goto print_object_end;
|
|
|
|
this_region_config_set = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
print_object_end:
|
2018-10-23 20:53:43 +00:00
|
|
|
update_apply_status(print_object->invalidate_all_steps());
|
2018-10-18 12:36:46 +00:00
|
|
|
// Decrease the references to regions from this volume.
|
|
|
|
int ireg = 0;
|
|
|
|
for (const std::vector<int> &volumes : print_object->region_volumes) {
|
|
|
|
if (! volumes.empty())
|
|
|
|
-- m_regions[ireg];
|
|
|
|
++ ireg;
|
|
|
|
}
|
|
|
|
print_object->region_volumes.clear();
|
|
|
|
}
|
|
|
|
if (this_region_config_set) {
|
|
|
|
t_config_option_keys diff = region.config().diff(this_region_config);
|
|
|
|
if (! diff.empty()) {
|
|
|
|
region.config_apply_only(this_region_config, diff, false);
|
|
|
|
for (PrintObject *print_object : m_objects)
|
|
|
|
if (region_id < print_object->region_volumes.size() && ! print_object->region_volumes[region_id].empty())
|
2018-10-23 20:53:43 +00:00
|
|
|
update_apply_status(print_object->invalidate_state_by_config_options(diff));
|
2018-10-18 12:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 09:12:38 +00:00
|
|
|
|
2018-10-18 12:36:46 +00:00
|
|
|
// Possibly add new regions for the newly added or resetted PrintObjects.
|
|
|
|
for (size_t idx_print_object = 0; idx_print_object < m_objects.size(); ++ idx_print_object) {
|
|
|
|
PrintObject &print_object0 = *m_objects[idx_print_object];
|
|
|
|
const ModelObject &model_object = *print_object0.model_object();
|
|
|
|
std::vector<int> map_volume_to_region(model_object.volumes.size(), -1);
|
|
|
|
for (size_t i = idx_print_object; i < m_objects.size() && m_objects[i]->model_object() == &model_object; ++ i) {
|
|
|
|
PrintObject &print_object = *m_objects[i];
|
2018-10-18 16:03:17 +00:00
|
|
|
bool fresh = print_object.region_volumes.empty();
|
2018-10-18 12:36:46 +00:00
|
|
|
unsigned int volume_id = 0;
|
|
|
|
for (const ModelVolume *volume : model_object.volumes) {
|
2018-10-17 09:12:38 +00:00
|
|
|
if (! volume->is_model_part() && ! volume->is_modifier())
|
|
|
|
continue;
|
2018-10-18 12:36:46 +00:00
|
|
|
int region_id = -1;
|
|
|
|
if (&print_object == &print_object0) {
|
|
|
|
// Get the config applied to this volume.
|
|
|
|
PrintRegionConfig config = region_config_from_model_volume(m_default_region_config, *volume);
|
|
|
|
// Find an existing print region with the same config.
|
|
|
|
for (int i = 0; i < (int)m_regions.size(); ++ i)
|
|
|
|
if (config.equals(m_regions[i]->config())) {
|
|
|
|
region_id = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// If no region exists with the same config, create a new one.
|
|
|
|
if (region_id == size_t(-1)) {
|
|
|
|
for (region_id = 0; region_id < m_regions.size(); ++ region_id)
|
|
|
|
if (m_regions[region_id]->m_refcnt == 0) {
|
|
|
|
// An empty slot was found.
|
|
|
|
m_regions[region_id]->set_config(std::move(config));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (region_id == m_regions.size())
|
|
|
|
this->add_region(config);
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
2018-10-18 12:36:46 +00:00
|
|
|
map_volume_to_region[volume_id] = region_id;
|
|
|
|
} else
|
|
|
|
region_id = map_volume_to_region[volume_id];
|
2018-10-17 09:12:38 +00:00
|
|
|
// Assign volume to a region.
|
2018-10-18 16:03:17 +00:00
|
|
|
if (fresh) {
|
|
|
|
if (print_object.region_volumes.empty())
|
|
|
|
++ m_regions[region_id]->m_refcnt;
|
|
|
|
print_object.add_region_volume(region_id, volume_id);
|
|
|
|
}
|
2018-10-17 09:12:38 +00:00
|
|
|
++ volume_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-18 16:03:17 +00:00
|
|
|
// Always make sure that the layer_height_profiles are set, as they should not be modified from the worker threads.
|
|
|
|
for (PrintObject *object : m_objects)
|
|
|
|
if (! object->layer_height_profile_valid)
|
|
|
|
object->update_layer_height_profile();
|
|
|
|
|
2018-10-17 09:12:38 +00:00
|
|
|
this->update_object_placeholders();
|
2018-10-23 20:53:43 +00:00
|
|
|
return static_cast<ApplyStatus>(apply_status);
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update "scale", "input_filename", "input_filename_base" placeholders from the current m_objects.
|
|
|
|
void Print::update_object_placeholders()
|
|
|
|
{
|
|
|
|
// get the first input file name
|
|
|
|
std::string input_file;
|
|
|
|
std::vector<std::string> v_scale;
|
|
|
|
for (const PrintObject *object : m_objects) {
|
|
|
|
const ModelObject &mobj = *object->model_object();
|
|
|
|
// CHECK_ME -> Is the following correct ?
|
|
|
|
v_scale.push_back("x:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(X) * 100) +
|
|
|
|
"% y:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(Y) * 100) +
|
|
|
|
"% z:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(Z) * 100) + "%");
|
|
|
|
if (input_file.empty())
|
|
|
|
input_file = mobj.input_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlaceholderParser &pp = m_placeholder_parser;
|
|
|
|
pp.set("scale", v_scale);
|
|
|
|
if (! input_file.empty()) {
|
|
|
|
// get basename with and without suffix
|
|
|
|
const std::string input_basename = boost::filesystem::path(input_file).filename().string();
|
|
|
|
pp.set("input_filename", input_basename);
|
|
|
|
const std::string input_basename_base = input_basename.substr(0, input_basename.find_last_of("."));
|
|
|
|
pp.set("input_filename_base", input_basename_base);
|
2018-10-18 16:03:17 +00:00
|
|
|
}
|
2018-10-17 09:12:38 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 08:56:58 +00:00
|
|
|
bool Print::has_infinite_skirt() const
|
2014-08-03 16:41:09 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
return (m_config.skirt_height == -1 && m_config.skirts > 0)
|
|
|
|
|| (m_config.ooze_prevention && this->extruders().size() > 1);
|
2015-03-06 08:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Print::has_skirt() const
|
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
return (m_config.skirt_height > 0 && m_config.skirts > 0)
|
2015-03-06 08:56:58 +00:00
|
|
|
|| this->has_infinite_skirt();
|
2014-08-03 16:41:09 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
std::string Print::validate() const
|
2014-11-09 14:27:34 +00:00
|
|
|
{
|
2018-10-23 13:27:31 +00:00
|
|
|
if (m_objects.empty())
|
2018-07-18 07:37:25 +00:00
|
|
|
return L("All objects are outside of the print volume.");
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
if (m_config.complete_objects) {
|
2017-05-31 10:55:59 +00:00
|
|
|
// Check horizontal clearance.
|
2014-11-09 14:27:34 +00:00
|
|
|
{
|
2017-05-31 10:55:59 +00:00
|
|
|
Polygons convex_hulls_other;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects) {
|
2017-06-13 09:35:24 +00:00
|
|
|
// Get convex hull of all meshes assigned to this print object.
|
2015-01-07 20:57:22 +00:00
|
|
|
Polygon convex_hull;
|
|
|
|
{
|
|
|
|
Polygons mesh_convex_hulls;
|
2017-05-31 10:55:59 +00:00
|
|
|
for (const std::vector<int> &volumes : object->region_volumes)
|
|
|
|
for (int volume_id : volumes)
|
|
|
|
mesh_convex_hulls.emplace_back(object->model_object()->volumes[volume_id]->mesh.convex_hull());
|
2015-01-07 20:57:22 +00:00
|
|
|
// make a single convex hull for all of them
|
2015-01-19 17:53:04 +00:00
|
|
|
convex_hull = Slic3r::Geometry::convex_hull(mesh_convex_hulls);
|
2015-01-07 20:57:22 +00:00
|
|
|
}
|
2017-05-31 10:55:59 +00:00
|
|
|
// Apply the same transformations we apply to the actual meshes when slicing them.
|
2014-11-09 14:27:34 +00:00
|
|
|
object->model_object()->instances.front()->transform_polygon(&convex_hull);
|
2017-05-31 10:55:59 +00:00
|
|
|
// Grow convex hull with the clearance margin.
|
2018-09-11 12:04:47 +00:00
|
|
|
convex_hull = offset(convex_hull, scale_(m_config.extruder_clearance_radius.value)/2, jtRound, scale_(0.1)).front();
|
2017-05-31 10:55:59 +00:00
|
|
|
// Now we check that no instance of convex_hull intersects any of the previously checked object instances.
|
2018-09-12 09:59:02 +00:00
|
|
|
for (const Point © : object->m_copies) {
|
2014-11-09 14:27:34 +00:00
|
|
|
Polygon p = convex_hull;
|
2017-05-03 16:28:22 +00:00
|
|
|
p.translate(copy);
|
2017-05-31 10:55:59 +00:00
|
|
|
if (! intersection(convex_hulls_other, p).empty())
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("Some objects are too close; your extruder will collide with them.");
|
2017-05-31 10:55:59 +00:00
|
|
|
polygons_append(convex_hulls_other, p);
|
2014-11-09 14:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 10:55:59 +00:00
|
|
|
// Check vertical clearance.
|
2014-11-09 14:27:34 +00:00
|
|
|
{
|
|
|
|
std::vector<coord_t> object_height;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (const PrintObject *object : m_objects)
|
2018-08-17 13:53:43 +00:00
|
|
|
object_height.insert(object_height.end(), object->copies().size(), object->size(2));
|
2014-11-09 14:27:34 +00:00
|
|
|
std::sort(object_height.begin(), object_height.end());
|
2017-05-31 10:55:59 +00:00
|
|
|
// Ignore the tallest *copy* (this is why we repeat height for all of them):
|
|
|
|
// it will be printed as last one so its height doesn't matter.
|
2014-11-09 14:27:34 +00:00
|
|
|
object_height.pop_back();
|
2018-09-11 12:04:47 +00:00
|
|
|
if (! object_height.empty() && object_height.back() > scale_(m_config.extruder_clearance_height.value))
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("Some objects are too tall and cannot be printed without extruder collisions.");
|
2014-11-09 14:27:34 +00:00
|
|
|
}
|
2018-09-11 12:04:47 +00:00
|
|
|
} // end if (m_config.complete_objects)
|
2017-05-31 10:55:59 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
if (m_config.spiral_vase) {
|
2014-11-09 14:27:34 +00:00
|
|
|
size_t total_copies_count = 0;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (const PrintObject *object : m_objects)
|
2017-05-31 10:55:59 +00:00
|
|
|
total_copies_count += object->copies().size();
|
2017-06-23 08:13:09 +00:00
|
|
|
// #4043
|
2018-09-11 12:04:47 +00:00
|
|
|
if (total_copies_count > 1 && ! m_config.complete_objects.value)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Spiral Vase option can only be used when printing a single object.");
|
2018-09-11 12:04:47 +00:00
|
|
|
if (m_regions.size() > 1)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Spiral Vase option can only be used when printing single material objects.");
|
2014-11-09 14:27:34 +00:00
|
|
|
}
|
2017-06-06 08:36:14 +00:00
|
|
|
|
2018-09-12 09:59:02 +00:00
|
|
|
if (m_config.single_extruder_multi_material) {
|
|
|
|
for (size_t i=1; i<m_config.nozzle_diameter.values.size(); ++i)
|
|
|
|
if (m_config.nozzle_diameter.values[i] != m_config.nozzle_diameter.values[i-1])
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("All extruders must have the same diameter for single extruder multimaterial printer.");
|
2014-11-09 14:27:34 +00:00
|
|
|
}
|
2017-06-06 08:36:14 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
if (this->has_wipe_tower() && ! m_objects.empty()) {
|
|
|
|
if (m_config.gcode_flavor != gcfRepRap && m_config.gcode_flavor != gcfMarlin)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Wipe Tower is currently only supported for the Marlin and RepRap/Sprinter G-code flavors.");
|
2018-09-11 12:04:47 +00:00
|
|
|
if (! m_config.use_relative_e_distances)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Wipe Tower is currently only supported with the relative extruder addressing (use_relative_e_distances=1).");
|
2018-09-11 12:04:47 +00:00
|
|
|
SlicingParameters slicing_params0 = m_objects.front()->slicing_parameters();
|
2018-04-16 09:47:35 +00:00
|
|
|
|
2018-09-12 09:59:02 +00:00
|
|
|
const PrintObject* tallest_object = m_objects.front(); // let's find the tallest object
|
|
|
|
for (const auto* object : m_objects)
|
2018-04-26 09:19:51 +00:00
|
|
|
if (*(object->layer_height_profile.end()-2) > *(tallest_object->layer_height_profile.end()-2) )
|
|
|
|
tallest_object = object;
|
2018-04-16 09:47:35 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects) {
|
2017-06-08 14:58:29 +00:00
|
|
|
SlicingParameters slicing_params = object->slicing_parameters();
|
|
|
|
if (std::abs(slicing_params.first_print_layer_height - slicing_params0.first_print_layer_height) > EPSILON ||
|
|
|
|
std::abs(slicing_params.layer_height - slicing_params0.layer_height ) > EPSILON)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Wipe Tower is only supported for multiple objects if they have equal layer heigths");
|
2017-06-08 14:58:29 +00:00
|
|
|
if (slicing_params.raft_layers() != slicing_params0.raft_layers())
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Wipe Tower is only supported for multiple objects if they are printed over an equal number of raft layers");
|
2018-09-11 12:04:47 +00:00
|
|
|
if (object->config().support_material_contact_distance != m_objects.front()->config().support_material_contact_distance)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Wipe Tower is only supported for multiple objects if they are printed with the same support_material_contact_distance");
|
2017-06-08 14:58:29 +00:00
|
|
|
if (! equal_layering(slicing_params, slicing_params0))
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Wipe Tower is only supported for multiple objects if they are sliced equally.");
|
2017-06-09 11:27:35 +00:00
|
|
|
bool was_layer_height_profile_valid = object->layer_height_profile_valid;
|
2017-06-06 09:40:35 +00:00
|
|
|
object->update_layer_height_profile();
|
2017-06-09 11:27:35 +00:00
|
|
|
object->layer_height_profile_valid = was_layer_height_profile_valid;
|
2018-04-03 11:51:12 +00:00
|
|
|
|
2018-09-12 09:59:02 +00:00
|
|
|
if ( m_config.variable_layer_height ) { // comparing layer height profiles
|
2018-04-26 09:19:51 +00:00
|
|
|
bool failed = false;
|
|
|
|
if (tallest_object->layer_height_profile.size() >= object->layer_height_profile.size() ) {
|
|
|
|
int i = 0;
|
|
|
|
while ( i < object->layer_height_profile.size() && i < tallest_object->layer_height_profile.size()) {
|
|
|
|
if (std::abs(tallest_object->layer_height_profile[i] - object->layer_height_profile[i])) {
|
|
|
|
failed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
if (i == object->layer_height_profile.size()-2) // this element contains this objects max z
|
|
|
|
if (tallest_object->layer_height_profile[i] > object->layer_height_profile[i]) // the difference does not matter in this case
|
|
|
|
++i;
|
|
|
|
}
|
2018-04-04 07:59:41 +00:00
|
|
|
}
|
2018-04-26 09:19:51 +00:00
|
|
|
else
|
|
|
|
failed = true;
|
|
|
|
|
|
|
|
if (failed)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The Wipe tower is only supported if all objects have the same layer height profile");
|
2018-04-03 11:51:12 +00:00
|
|
|
}
|
2017-06-06 09:40:35 +00:00
|
|
|
}
|
2017-06-06 08:36:14 +00:00
|
|
|
}
|
2014-11-09 14:27:34 +00:00
|
|
|
|
|
|
|
{
|
2015-03-06 20:35:00 +00:00
|
|
|
// find the smallest nozzle diameter
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<unsigned int> extruders = this->extruders();
|
2015-03-06 20:35:00 +00:00
|
|
|
if (extruders.empty())
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("The supplied settings will cause an empty print.");
|
2015-03-06 20:35:00 +00:00
|
|
|
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<double> nozzle_diameters;
|
|
|
|
for (unsigned int extruder_id : extruders)
|
2018-09-11 12:04:47 +00:00
|
|
|
nozzle_diameters.push_back(m_config.nozzle_diameter.get_at(extruder_id));
|
2015-03-06 20:35:00 +00:00
|
|
|
double min_nozzle_diameter = *std::min_element(nozzle_diameters.begin(), nozzle_diameters.end());
|
2018-09-12 09:59:02 +00:00
|
|
|
unsigned int total_extruders_count = m_config.nozzle_diameter.size();
|
2018-03-21 15:01:31 +00:00
|
|
|
for (const auto& extruder_idx : extruders)
|
|
|
|
if ( extruder_idx >= total_extruders_count )
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("One or more object were assigned an extruder that the printer does not have.");
|
2018-03-21 15:01:31 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *object : m_objects) {
|
|
|
|
if ((object->config().support_material_extruder == -1 || object->config().support_material_interface_extruder == -1) &&
|
|
|
|
(object->config().raft_layers > 0 || object->config().support_material.value)) {
|
2017-01-30 18:56:46 +00:00
|
|
|
// The object has some form of support and either support_material_extruder or support_material_interface_extruder
|
|
|
|
// will be printed with the current tool without a forced tool change. Play safe, assert that all object nozzles
|
|
|
|
// are of the same diameter.
|
|
|
|
if (nozzle_diameters.size() > 1)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("Printing with multiple extruders of differing nozzle diameters. "
|
2017-02-11 23:51:53 +00:00
|
|
|
"If support is to be printed with the current extruder (support_material_extruder == 0 or support_material_interface_extruder == 0), "
|
2018-06-20 11:57:37 +00:00
|
|
|
"all nozzles have to be of the same diameter.");
|
2017-01-30 18:56:46 +00:00
|
|
|
}
|
2015-03-06 20:35:00 +00:00
|
|
|
|
|
|
|
// validate first_layer_height
|
2018-09-12 09:59:02 +00:00
|
|
|
double first_layer_height = object->config().get_abs_value(L("first_layer_height"));
|
2015-03-06 20:35:00 +00:00
|
|
|
double first_layer_min_nozzle_diameter;
|
2018-09-11 12:04:47 +00:00
|
|
|
if (object->config().raft_layers > 0) {
|
2015-03-06 20:35:00 +00:00
|
|
|
// if we have raft layers, only support material extruder is used on first layer
|
2018-09-11 12:04:47 +00:00
|
|
|
size_t first_layer_extruder = object->config().raft_layers == 1
|
|
|
|
? object->config().support_material_interface_extruder-1
|
|
|
|
: object->config().support_material_extruder-1;
|
2017-01-30 18:56:46 +00:00
|
|
|
first_layer_min_nozzle_diameter = (first_layer_extruder == size_t(-1)) ?
|
|
|
|
min_nozzle_diameter :
|
2018-09-11 12:04:47 +00:00
|
|
|
m_config.nozzle_diameter.get_at(first_layer_extruder);
|
2015-03-06 20:35:00 +00:00
|
|
|
} else {
|
|
|
|
// if we don't have raft layers, any nozzle diameter is potentially used in first layer
|
|
|
|
first_layer_min_nozzle_diameter = min_nozzle_diameter;
|
|
|
|
}
|
|
|
|
if (first_layer_height > first_layer_min_nozzle_diameter)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("First layer height can't be greater than nozzle diameter");
|
2015-03-06 20:35:00 +00:00
|
|
|
|
|
|
|
// validate layer_height
|
2018-09-11 12:04:47 +00:00
|
|
|
if (object->config().layer_height.value > min_nozzle_diameter)
|
2018-06-20 11:57:37 +00:00
|
|
|
return L("Layer height can't be greater than nozzle diameter");
|
2014-11-09 14:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-05 01:23:46 +00:00
|
|
|
|
|
|
|
return std::string();
|
2014-11-09 14:27:34 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 18:14:52 +00:00
|
|
|
// the bounding box of objects placed in copies position
|
|
|
|
// (without taking skirt/brim/support material into account)
|
2017-05-30 18:09:34 +00:00
|
|
|
BoundingBox Print::bounding_box() const
|
2014-12-12 18:14:52 +00:00
|
|
|
{
|
|
|
|
BoundingBox bb;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (const PrintObject *object : m_objects)
|
2018-09-12 09:59:02 +00:00
|
|
|
for (Point copy : object->m_copies) {
|
2017-05-31 10:55:59 +00:00
|
|
|
bb.merge(copy);
|
2018-08-21 15:43:05 +00:00
|
|
|
copy += to_2d(object->size);
|
2017-05-31 10:55:59 +00:00
|
|
|
bb.merge(copy);
|
2014-12-12 18:14:52 +00:00
|
|
|
}
|
|
|
|
return bb;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the total bounding box of extrusions, including skirt/brim/support material
|
|
|
|
// this methods needs to be called even when no steps were processed, so it should
|
|
|
|
// only use configuration values
|
2017-05-30 18:09:34 +00:00
|
|
|
BoundingBox Print::total_bounding_box() const
|
2014-12-12 18:14:52 +00:00
|
|
|
{
|
|
|
|
// get objects bounding box
|
|
|
|
BoundingBox bb = this->bounding_box();
|
|
|
|
|
2014-12-12 18:25:50 +00:00
|
|
|
// we need to offset the objects bounding box by at least half the perimeters extrusion width
|
2018-09-11 12:04:47 +00:00
|
|
|
Flow perimeter_flow = m_objects.front()->get_layer(0)->get_region(0)->flow(frPerimeter);
|
2014-12-12 18:25:50 +00:00
|
|
|
double extra = perimeter_flow.width/2;
|
|
|
|
|
|
|
|
// consider support material
|
|
|
|
if (this->has_support_material()) {
|
|
|
|
extra = std::max(extra, SUPPORT_MATERIAL_MARGIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
// consider brim and skirt
|
2018-09-11 12:04:47 +00:00
|
|
|
if (m_config.brim_width.value > 0) {
|
2014-12-16 23:45:05 +00:00
|
|
|
Flow brim_flow = this->brim_flow();
|
2018-09-11 12:04:47 +00:00
|
|
|
extra = std::max(extra, m_config.brim_width.value + brim_flow.width/2);
|
2014-12-12 18:25:50 +00:00
|
|
|
}
|
2015-03-06 08:56:58 +00:00
|
|
|
if (this->has_skirt()) {
|
2018-09-11 12:04:47 +00:00
|
|
|
int skirts = m_config.skirts.value;
|
2015-03-06 08:56:58 +00:00
|
|
|
if (skirts == 0 && this->has_infinite_skirt()) skirts = 1;
|
2014-12-16 23:45:05 +00:00
|
|
|
Flow skirt_flow = this->skirt_flow();
|
2014-12-12 18:14:52 +00:00
|
|
|
extra = std::max(
|
|
|
|
extra,
|
2018-09-11 12:04:47 +00:00
|
|
|
m_config.brim_width.value
|
|
|
|
+ m_config.skirt_distance.value
|
2015-03-06 08:56:58 +00:00
|
|
|
+ skirts * skirt_flow.spacing()
|
2014-12-12 18:25:50 +00:00
|
|
|
+ skirt_flow.width/2
|
2014-12-12 18:14:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extra > 0)
|
|
|
|
bb.offset(scale_(extra));
|
|
|
|
|
|
|
|
return bb;
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
double Print::skirt_first_layer_height() const
|
2014-12-12 18:14:52 +00:00
|
|
|
{
|
2018-09-18 08:09:58 +00:00
|
|
|
if (m_objects.empty())
|
|
|
|
throw std::invalid_argument("skirt_first_layer_height() can't be called without PrintObjects");
|
2018-09-11 12:04:47 +00:00
|
|
|
return m_objects.front()->config().get_abs_value("first_layer_height");
|
2014-12-12 18:14:52 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
Flow Print::brim_flow() const
|
2014-12-16 23:45:05 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
ConfigOptionFloatOrPercent width = m_config.first_layer_extrusion_width;
|
2017-11-09 09:48:06 +00:00
|
|
|
if (width.value == 0)
|
2018-09-11 12:04:47 +00:00
|
|
|
width = m_regions.front()->config().perimeter_extrusion_width;
|
2017-11-09 09:48:06 +00:00
|
|
|
if (width.value == 0)
|
2018-09-11 12:04:47 +00:00
|
|
|
width = m_objects.front()->config().extrusion_width;
|
2014-12-16 23:45:05 +00:00
|
|
|
|
|
|
|
/* We currently use a random region's perimeter extruder.
|
|
|
|
While this works for most cases, we should probably consider all of the perimeter
|
|
|
|
extruders and take the one with, say, the smallest index.
|
|
|
|
The same logic should be applied to the code that selects the extruder during G-code
|
|
|
|
generation as well. */
|
|
|
|
return Flow::new_from_config_width(
|
|
|
|
frPerimeter,
|
|
|
|
width,
|
2018-09-11 12:04:47 +00:00
|
|
|
m_config.nozzle_diameter.get_at(m_regions.front()->config().perimeter_extruder-1),
|
2014-12-16 23:45:05 +00:00
|
|
|
this->skirt_first_layer_height(),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
Flow Print::skirt_flow() const
|
2014-12-12 18:14:52 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
ConfigOptionFloatOrPercent width = m_config.first_layer_extrusion_width;
|
2017-11-09 09:48:06 +00:00
|
|
|
if (width.value == 0)
|
2018-09-11 12:04:47 +00:00
|
|
|
width = m_regions.front()->config().perimeter_extrusion_width;
|
2017-11-09 09:48:06 +00:00
|
|
|
if (width.value == 0)
|
2018-09-11 12:04:47 +00:00
|
|
|
width = m_objects.front()->config().extrusion_width;
|
2014-12-12 18:14:52 +00:00
|
|
|
|
2014-12-16 23:45:05 +00:00
|
|
|
/* We currently use a random object's support material extruder.
|
|
|
|
While this works for most cases, we should probably consider all of the support material
|
|
|
|
extruders and take the one with, say, the smallest index;
|
|
|
|
The same logic should be applied to the code that selects the extruder during G-code
|
|
|
|
generation as well. */
|
2014-12-12 18:14:52 +00:00
|
|
|
return Flow::new_from_config_width(
|
|
|
|
frPerimeter,
|
|
|
|
width,
|
2018-09-11 12:04:47 +00:00
|
|
|
m_config.nozzle_diameter.get_at(m_objects.front()->config().support_material_extruder-1),
|
2014-12-12 18:14:52 +00:00
|
|
|
this->skirt_first_layer_height(),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:09:34 +00:00
|
|
|
bool Print::has_support_material() const
|
2014-08-03 16:41:09 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
for (const PrintObject *object : m_objects)
|
2017-05-30 18:09:34 +00:00
|
|
|
if (object->has_support_material())
|
|
|
|
return true;
|
2014-08-03 16:41:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-02 17:29:33 +00:00
|
|
|
/* This method assigns extruders to the volumes having a material
|
|
|
|
but not having extruders set in the volume config. */
|
2017-05-30 18:09:34 +00:00
|
|
|
void Print::auto_assign_extruders(ModelObject* model_object) const
|
2015-12-02 17:29:33 +00:00
|
|
|
{
|
|
|
|
// only assign extruders if object has more than one volume
|
2017-05-30 18:09:34 +00:00
|
|
|
if (model_object->volumes.size() < 2)
|
|
|
|
return;
|
2015-12-02 17:29:33 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
// size_t extruders = m_config.nozzle_diameter.values.size();
|
2017-05-30 18:09:34 +00:00
|
|
|
for (size_t volume_id = 0; volume_id < model_object->volumes.size(); ++ volume_id) {
|
|
|
|
ModelVolume *volume = model_object->volumes[volume_id];
|
|
|
|
//FIXME Vojtech: This assigns an extruder ID even to a modifier volume, if it has a material assigned.
|
2018-09-17 13:12:13 +00:00
|
|
|
if ((volume->is_model_part() || volume->is_modifier()) && ! volume->material_id().empty() && ! volume->config.has("extruder"))
|
2017-05-30 18:09:34 +00:00
|
|
|
volume->config.opt<ConfigOptionInt>("extruder", true)->value = int(volume_id + 1);
|
2015-12-02 17:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-23 10:41:20 +00:00
|
|
|
// Slicing process, running at a background thread.
|
|
|
|
void Print::process()
|
|
|
|
{
|
|
|
|
BOOST_LOG_TRIVIAL(info) << "Staring the slicing process.";
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *obj : m_objects)
|
2018-03-23 10:41:20 +00:00
|
|
|
obj->make_perimeters();
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
2018-03-23 10:41:20 +00:00
|
|
|
this->set_status(70, "Infilling layers");
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *obj : m_objects)
|
2018-03-23 10:41:20 +00:00
|
|
|
obj->infill();
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
2018-09-11 12:04:47 +00:00
|
|
|
for (PrintObject *obj : m_objects)
|
2018-03-23 10:41:20 +00:00
|
|
|
obj->generate_support_material();
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
|
|
|
if (! m_state.is_done(psSkirt)) {
|
|
|
|
this->set_started(psSkirt);
|
2018-09-11 12:04:47 +00:00
|
|
|
m_skirt.clear();
|
2018-03-23 10:41:20 +00:00
|
|
|
if (this->has_skirt()) {
|
|
|
|
this->set_status(88, "Generating skirt");
|
|
|
|
this->_make_skirt();
|
|
|
|
}
|
2018-09-11 12:04:47 +00:00
|
|
|
this->set_done(psSkirt);
|
2018-03-23 10:41:20 +00:00
|
|
|
}
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
|
|
|
if (! m_state.is_done(psBrim)) {
|
|
|
|
this->set_started(psBrim);
|
2018-09-11 12:04:47 +00:00
|
|
|
m_brim.clear();
|
|
|
|
if (m_config.brim_width > 0) {
|
2018-03-23 10:41:20 +00:00
|
|
|
this->set_status(88, "Generating brim");
|
|
|
|
this->_make_brim();
|
|
|
|
}
|
2018-09-11 12:04:47 +00:00
|
|
|
this->set_done(psBrim);
|
2018-03-23 10:41:20 +00:00
|
|
|
}
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
|
|
|
if (! m_state.is_done(psWipeTower)) {
|
|
|
|
this->set_started(psWipeTower);
|
2018-09-11 12:04:47 +00:00
|
|
|
m_wipe_tower_data.clear();
|
2018-03-23 10:41:20 +00:00
|
|
|
if (this->has_wipe_tower()) {
|
|
|
|
//this->set_status(95, "Generating wipe tower");
|
|
|
|
this->_make_wipe_tower();
|
|
|
|
}
|
2018-09-11 12:04:47 +00:00
|
|
|
this->set_done(psWipeTower);
|
2018-03-23 10:41:20 +00:00
|
|
|
}
|
|
|
|
BOOST_LOG_TRIVIAL(info) << "Slicing process finished.";
|
|
|
|
}
|
|
|
|
|
|
|
|
// G-code export process, running at a background thread.
|
|
|
|
// The export_gcode may die for various reasons (fails to process output_filename_format,
|
|
|
|
// write error into the G-code, cannot execute post-processing scripts).
|
|
|
|
// It is up to the caller to show an error message.
|
|
|
|
void Print::export_gcode(const std::string &path_template, GCodePreviewData *preview_data)
|
|
|
|
{
|
|
|
|
// prerequisites
|
|
|
|
this->process();
|
|
|
|
|
|
|
|
// output everything to a G-code file
|
|
|
|
// The following call may die if the output_filename_format template substitution fails.
|
|
|
|
std::string path = this->output_filepath(path_template);
|
|
|
|
std::string message = "Exporting G-code";
|
|
|
|
if (! path.empty()) {
|
|
|
|
message += " to ";
|
|
|
|
message += path;
|
|
|
|
}
|
|
|
|
this->set_status(90, message);
|
|
|
|
|
|
|
|
// The following line may die for multiple reasons.
|
|
|
|
GCode gcode;
|
|
|
|
gcode.do_export(this, path.c_str(), preview_data);
|
|
|
|
}
|
|
|
|
|
2017-02-15 10:05:52 +00:00
|
|
|
void Print::_make_skirt()
|
|
|
|
{
|
|
|
|
// First off we need to decide how tall the skirt must be.
|
|
|
|
// The skirt_height option from config is expressed in layers, but our
|
|
|
|
// object might have different layer heights, so we need to find the print_z
|
|
|
|
// of the highest layer involved.
|
|
|
|
// Note that unless has_infinite_skirt() == true
|
|
|
|
// the actual skirt might not reach this $skirt_height_z value since the print
|
|
|
|
// order of objects on each layer is not guaranteed and will not generally
|
|
|
|
// include the thickest object first. It is just guaranteed that a skirt is
|
|
|
|
// prepended to the first 'n' layers (with 'n' = skirt_height).
|
|
|
|
// $skirt_height_z in this case is the highest possible skirt height for safety.
|
|
|
|
coordf_t skirt_height_z = 0.;
|
2018-07-18 07:37:25 +00:00
|
|
|
PrintObjectPtrs printable_objects = get_printable_objects();
|
|
|
|
for (const PrintObject *object : printable_objects) {
|
|
|
|
size_t skirt_layers = this->has_infinite_skirt() ?
|
2017-02-15 10:05:52 +00:00
|
|
|
object->layer_count() :
|
2018-09-11 12:04:47 +00:00
|
|
|
std::min(size_t(m_config.skirt_height.value), object->layer_count());
|
|
|
|
skirt_height_z = std::max(skirt_height_z, object->m_layers[skirt_layers-1]->print_z);
|
2017-02-15 10:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect points from all layers contained in skirt height.
|
|
|
|
Points points;
|
2018-07-18 07:37:25 +00:00
|
|
|
for (const PrintObject *object : printable_objects) {
|
2017-02-15 10:05:52 +00:00
|
|
|
Points object_points;
|
|
|
|
// Get object layers up to skirt_height_z.
|
2018-09-11 12:04:47 +00:00
|
|
|
for (const Layer *layer : object->m_layers) {
|
2017-02-15 10:05:52 +00:00
|
|
|
if (layer->print_z > skirt_height_z)
|
|
|
|
break;
|
|
|
|
for (const ExPolygon &expoly : layer->slices.expolygons)
|
|
|
|
// Collect the outer contour points only, ignore holes for the calculation of the convex hull.
|
|
|
|
append(object_points, expoly.contour.points);
|
|
|
|
}
|
|
|
|
// Get support layers up to skirt_height_z.
|
2018-09-11 12:04:47 +00:00
|
|
|
for (const SupportLayer *layer : object->support_layers()) {
|
2017-02-15 10:05:52 +00:00
|
|
|
if (layer->print_z > skirt_height_z)
|
|
|
|
break;
|
|
|
|
for (const ExtrusionEntity *extrusion_entity : layer->support_fills.entities)
|
|
|
|
append(object_points, extrusion_entity->as_polyline().points);
|
|
|
|
}
|
|
|
|
// Repeat points for each object copy.
|
2018-09-12 09:59:02 +00:00
|
|
|
for (const Point &shift : object->m_copies) {
|
2017-02-15 10:05:52 +00:00
|
|
|
Points copy_points = object_points;
|
|
|
|
for (Point &pt : copy_points)
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
pt += shift;
|
2017-02-15 10:05:52 +00:00
|
|
|
append(points, copy_points);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (points.size() < 3)
|
|
|
|
// At least three points required for a convex hull.
|
|
|
|
return;
|
|
|
|
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
2017-02-15 10:05:52 +00:00
|
|
|
Polygon convex_hull = Slic3r::Geometry::convex_hull(points);
|
|
|
|
|
|
|
|
// Skirt may be printed on several layers, having distinct layer heights,
|
|
|
|
// but loops must be aligned so can't vary width/spacing
|
|
|
|
// TODO: use each extruder's own flow
|
|
|
|
double first_layer_height = this->skirt_first_layer_height();
|
|
|
|
Flow flow = this->skirt_flow();
|
|
|
|
float spacing = flow.spacing();
|
|
|
|
double mm3_per_mm = flow.mm3_per_mm();
|
|
|
|
|
|
|
|
std::vector<size_t> extruders;
|
|
|
|
std::vector<double> extruders_e_per_mm;
|
|
|
|
{
|
|
|
|
auto set_extruders = this->extruders();
|
|
|
|
extruders.reserve(set_extruders.size());
|
|
|
|
extruders_e_per_mm.reserve(set_extruders.size());
|
|
|
|
for (auto &extruder_id : set_extruders) {
|
|
|
|
extruders.push_back(extruder_id);
|
2018-09-11 12:04:47 +00:00
|
|
|
extruders_e_per_mm.push_back(Extruder((unsigned int)extruder_id, &m_config).e_per_mm(mm3_per_mm));
|
2017-02-15 10:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Number of skirt loops per skirt layer.
|
2018-09-11 12:04:47 +00:00
|
|
|
int n_skirts = m_config.skirts.value;
|
2017-02-15 10:05:52 +00:00
|
|
|
if (this->has_infinite_skirt() && n_skirts == 0)
|
|
|
|
n_skirts = 1;
|
|
|
|
|
|
|
|
// Initial offset of the brim inner edge from the object (possible with a support & raft).
|
|
|
|
// The skirt will touch the brim if the brim is extruded.
|
2018-05-18 10:19:54 +00:00
|
|
|
Flow brim_flow = this->brim_flow();
|
2018-09-12 09:59:02 +00:00
|
|
|
double actual_brim_width = brim_flow.spacing() * floor(m_config.brim_width.value / brim_flow.spacing());
|
|
|
|
coord_t distance = scale_(std::max(m_config.skirt_distance.value, actual_brim_width) - spacing/2.);
|
2017-02-15 10:05:52 +00:00
|
|
|
// Draw outlines from outside to inside.
|
|
|
|
// Loop while we have less skirts than required or any extruder hasn't reached the min length if any.
|
|
|
|
std::vector<coordf_t> extruded_length(extruders.size(), 0.);
|
|
|
|
for (int i = n_skirts, extruder_idx = 0; i > 0; -- i) {
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
2017-02-15 10:05:52 +00:00
|
|
|
// Offset the skirt outside.
|
|
|
|
distance += coord_t(scale_(spacing));
|
|
|
|
// Generate the skirt centerline.
|
2017-03-23 11:35:00 +00:00
|
|
|
Polygon loop;
|
|
|
|
{
|
|
|
|
Polygons loops = offset(convex_hull, distance, ClipperLib::jtRound, scale_(0.1));
|
|
|
|
Geometry::simplify_polygons(loops, scale_(0.05), &loops);
|
|
|
|
loop = loops.front();
|
|
|
|
}
|
2017-02-15 10:05:52 +00:00
|
|
|
// Extrude the skirt loop.
|
|
|
|
ExtrusionLoop eloop(elrSkirt);
|
|
|
|
eloop.paths.emplace_back(ExtrusionPath(
|
|
|
|
ExtrusionPath(
|
|
|
|
erSkirt,
|
|
|
|
mm3_per_mm, // this will be overridden at G-code export time
|
|
|
|
flow.width,
|
|
|
|
first_layer_height // this will be overridden at G-code export time
|
|
|
|
)));
|
|
|
|
eloop.paths.back().polyline = loop.split_at_first_point();
|
2018-09-11 12:04:47 +00:00
|
|
|
m_skirt.append(eloop);
|
|
|
|
if (m_config.min_skirt_length.value > 0) {
|
2017-02-15 10:05:52 +00:00
|
|
|
// The skirt length is limited. Sum the total amount of filament length extruded, in mm.
|
2018-08-21 15:43:05 +00:00
|
|
|
extruded_length[extruder_idx] += unscale<double>(loop.length()) * extruders_e_per_mm[extruder_idx];
|
2018-09-11 12:04:47 +00:00
|
|
|
if (extruded_length[extruder_idx] < m_config.min_skirt_length.value) {
|
2017-02-15 10:05:52 +00:00
|
|
|
// Not extruded enough yet with the current extruder. Add another loop.
|
|
|
|
if (i == 1)
|
|
|
|
++ i;
|
|
|
|
} else {
|
2018-09-11 12:04:47 +00:00
|
|
|
assert(extruded_length[extruder_idx] >= m_config.min_skirt_length.value);
|
2017-02-15 10:05:52 +00:00
|
|
|
// Enough extruded with the current extruder. Extrude with the next one,
|
|
|
|
// until the prescribed number of skirt loops is extruded.
|
|
|
|
if (extruder_idx + 1 < extruders.size())
|
|
|
|
++ extruder_idx;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The skirt lenght is not limited, extrude the skirt with the 1st extruder only.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Brims were generated inside out, reverse to print the outmost contour first.
|
2018-09-11 12:04:47 +00:00
|
|
|
m_skirt.reverse();
|
2017-02-15 10:05:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 14:40:23 +00:00
|
|
|
void Print::_make_brim()
|
|
|
|
{
|
|
|
|
// Brim is only printed on first layer and uses perimeter extruder.
|
|
|
|
Flow flow = this->brim_flow();
|
|
|
|
Polygons islands;
|
2018-07-18 07:37:25 +00:00
|
|
|
PrintObjectPtrs printable_objects = get_printable_objects();
|
|
|
|
for (PrintObject *object : printable_objects) {
|
2017-07-07 14:40:23 +00:00
|
|
|
Polygons object_islands;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (ExPolygon &expoly : object->m_layers.front()->slices.expolygons)
|
2017-07-07 14:40:23 +00:00
|
|
|
object_islands.push_back(expoly.contour);
|
2018-09-11 12:04:47 +00:00
|
|
|
if (! object->support_layers().empty())
|
|
|
|
object->support_layers().front()->support_fills.polygons_covered_by_spacing(object_islands, float(SCALED_EPSILON));
|
2018-09-12 09:59:02 +00:00
|
|
|
islands.reserve(islands.size() + object_islands.size() * object->m_copies.size());
|
|
|
|
for (const Point &pt : object->m_copies)
|
2017-07-07 14:40:23 +00:00
|
|
|
for (Polygon &poly : object_islands) {
|
|
|
|
islands.push_back(poly);
|
|
|
|
islands.back().translate(pt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Polygons loops;
|
2018-09-12 09:59:02 +00:00
|
|
|
size_t num_loops = size_t(floor(m_config.brim_width.value / flow.spacing()));
|
2017-07-07 14:40:23 +00:00
|
|
|
for (size_t i = 0; i < num_loops; ++ i) {
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
2017-07-07 14:40:23 +00:00
|
|
|
islands = offset(islands, float(flow.scaled_spacing()), jtSquare);
|
|
|
|
for (Polygon &poly : islands) {
|
|
|
|
// poly.simplify(SCALED_RESOLUTION);
|
|
|
|
poly.points.push_back(poly.points.front());
|
|
|
|
Points p = MultiPoint::_douglas_peucker(poly.points, SCALED_RESOLUTION);
|
|
|
|
p.pop_back();
|
|
|
|
poly.points = std::move(p);
|
|
|
|
}
|
|
|
|
polygons_append(loops, offset(islands, -0.5f * float(flow.scaled_spacing())));
|
|
|
|
}
|
|
|
|
|
|
|
|
loops = union_pt_chained(loops, false);
|
|
|
|
std::reverse(loops.begin(), loops.end());
|
2018-09-11 12:04:47 +00:00
|
|
|
extrusion_entities_append_loops(m_brim.entities, std::move(loops), erSkirt, float(flow.mm3_per_mm()), float(flow.width), float(this->skirt_first_layer_height()));
|
2017-07-07 14:40:23 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 20:27:53 +00:00
|
|
|
// Wipe tower support.
|
2017-07-17 07:07:18 +00:00
|
|
|
bool Print::has_wipe_tower() const
|
2017-05-25 20:27:53 +00:00
|
|
|
{
|
|
|
|
return
|
2018-09-11 12:04:47 +00:00
|
|
|
m_config.single_extruder_multi_material.value &&
|
|
|
|
! m_config.spiral_vase.value &&
|
|
|
|
m_config.wipe_tower.value &&
|
|
|
|
m_config.nozzle_diameter.values.size() > 1;
|
2017-05-25 20:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Print::_make_wipe_tower()
|
|
|
|
{
|
2018-09-12 09:59:02 +00:00
|
|
|
m_wipe_tower_data.clear();
|
2017-05-25 20:27:53 +00:00
|
|
|
if (! this->has_wipe_tower())
|
|
|
|
return;
|
|
|
|
|
2018-05-24 15:24:37 +00:00
|
|
|
// Get wiping matrix to get number of extruders and convert vector<double> to vector<float>:
|
2018-09-12 09:59:02 +00:00
|
|
|
std::vector<float> wiping_matrix(cast<float>(m_config.wiping_volumes_matrix.values));
|
2018-05-24 15:24:37 +00:00
|
|
|
// Extract purging volumes for each extruder pair:
|
|
|
|
std::vector<std::vector<float>> wipe_volumes;
|
|
|
|
const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON);
|
|
|
|
for (unsigned int i = 0; i<number_of_extruders; ++i)
|
|
|
|
wipe_volumes.push_back(std::vector<float>(wiping_matrix.begin()+i*number_of_extruders, wiping_matrix.begin()+(i+1)*number_of_extruders));
|
2018-05-24 12:05:51 +00:00
|
|
|
|
2017-09-01 15:30:18 +00:00
|
|
|
// Let the ToolOrdering class know there will be initial priming extrusions at the start of the print.
|
2018-09-11 12:04:47 +00:00
|
|
|
m_wipe_tower_data.tool_ordering = ToolOrdering(*this, (unsigned int)-1, true);
|
|
|
|
if (! m_wipe_tower_data.tool_ordering.has_wipe_tower())
|
2017-05-30 07:25:34 +00:00
|
|
|
// Don't generate any wipe tower.
|
2017-05-25 20:27:53 +00:00
|
|
|
return;
|
|
|
|
|
2017-12-11 16:19:55 +00:00
|
|
|
// Check whether there are any layers in m_tool_ordering, which are marked with has_wipe_tower,
|
|
|
|
// they print neither object, nor support. These layers are above the raft and below the object, and they
|
|
|
|
// shall be added to the support layers to be printed.
|
|
|
|
// see https://github.com/prusa3d/Slic3r/issues/607
|
|
|
|
{
|
|
|
|
size_t idx_begin = size_t(-1);
|
2018-09-11 12:04:47 +00:00
|
|
|
size_t idx_end = m_wipe_tower_data.tool_ordering.layer_tools().size();
|
2017-12-11 16:19:55 +00:00
|
|
|
// Find the first wipe tower layer, which does not have a counterpart in an object or a support layer.
|
|
|
|
for (size_t i = 0; i < idx_end; ++ i) {
|
2018-09-12 09:59:02 +00:00
|
|
|
const LayerTools < = m_wipe_tower_data.tool_ordering.layer_tools()[i];
|
2017-12-11 16:19:55 +00:00
|
|
|
if (lt.has_wipe_tower && ! lt.has_object && ! lt.has_support) {
|
|
|
|
idx_begin = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idx_begin != size_t(-1)) {
|
2018-09-11 12:04:47 +00:00
|
|
|
// Find the position in m_objects.first()->support_layers to insert these new support layers.
|
|
|
|
double wipe_tower_new_layer_print_z_first = m_wipe_tower_data.tool_ordering.layer_tools()[idx_begin].print_z;
|
|
|
|
SupportLayerPtrs::const_iterator it_layer = m_objects.front()->support_layers().begin();
|
|
|
|
SupportLayerPtrs::const_iterator it_end = m_objects.front()->support_layers().end();
|
2018-02-13 10:18:58 +00:00
|
|
|
for (; it_layer != it_end && (*it_layer)->print_z - EPSILON < wipe_tower_new_layer_print_z_first; ++ it_layer);
|
2017-12-11 16:19:55 +00:00
|
|
|
// Find the stopper of the sequence of wipe tower layers, which do not have a counterpart in an object or a support layer.
|
|
|
|
for (size_t i = idx_begin; i < idx_end; ++ i) {
|
2018-09-12 09:59:02 +00:00
|
|
|
LayerTools < = const_cast<LayerTools&>(m_wipe_tower_data.tool_ordering.layer_tools()[i]);
|
2017-12-11 16:19:55 +00:00
|
|
|
if (! (lt.has_wipe_tower && ! lt.has_object && ! lt.has_support))
|
|
|
|
break;
|
|
|
|
lt.has_support = true;
|
|
|
|
// Insert the new support layer.
|
2018-09-11 12:04:47 +00:00
|
|
|
double height = lt.print_z - m_wipe_tower_data.tool_ordering.layer_tools()[i-1].print_z;
|
2018-02-13 10:18:58 +00:00
|
|
|
//FIXME the support layer ID is set to -1, as Vojtech hopes it is not being used anyway.
|
2018-09-11 12:04:47 +00:00
|
|
|
it_layer = m_objects.front()->insert_support_layer(it_layer, size_t(-1), height, lt.print_z, lt.print_z - 0.5 * height);
|
2017-12-11 16:19:55 +00:00
|
|
|
++ it_layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-28 15:05:31 +00:00
|
|
|
this->throw_if_canceled();
|
2017-12-11 16:19:55 +00:00
|
|
|
|
2017-05-25 20:27:53 +00:00
|
|
|
// Initialize the wipe tower.
|
|
|
|
WipeTowerPrusaMM wipe_tower(
|
2018-09-11 12:04:47 +00:00
|
|
|
float(m_config.wipe_tower_x.value), float(m_config.wipe_tower_y.value),
|
2018-09-12 09:59:02 +00:00
|
|
|
float(m_config.wipe_tower_width.value),
|
|
|
|
float(m_config.wipe_tower_rotation_angle.value), float(m_config.cooling_tube_retraction.value),
|
|
|
|
float(m_config.cooling_tube_length.value), float(m_config.parking_pos_retraction.value),
|
|
|
|
float(m_config.extra_loading_move.value), float(m_config.wipe_tower_bridging), wipe_volumes,
|
2018-09-11 12:04:47 +00:00
|
|
|
m_wipe_tower_data.tool_ordering.first_extruder());
|
2018-03-20 14:45:11 +00:00
|
|
|
|
2017-05-25 20:27:53 +00:00
|
|
|
//wipe_tower.set_retract();
|
|
|
|
//wipe_tower.set_zhop();
|
|
|
|
|
|
|
|
// Set the extruder & material properties at the wipe tower object.
|
2018-05-24 15:24:37 +00:00
|
|
|
for (size_t i = 0; i < number_of_extruders; ++ i)
|
2017-05-25 20:27:53 +00:00
|
|
|
wipe_tower.set_extruder(
|
|
|
|
i,
|
2018-09-11 12:04:47 +00:00
|
|
|
WipeTowerPrusaMM::parse_material(m_config.filament_type.get_at(i).c_str()),
|
|
|
|
m_config.temperature.get_at(i),
|
2018-09-12 09:59:02 +00:00
|
|
|
m_config.first_layer_temperature.get_at(i),
|
|
|
|
m_config.filament_loading_speed.get_at(i),
|
|
|
|
m_config.filament_loading_speed_start.get_at(i),
|
|
|
|
m_config.filament_unloading_speed.get_at(i),
|
|
|
|
m_config.filament_unloading_speed_start.get_at(i),
|
|
|
|
m_config.filament_toolchange_delay.get_at(i),
|
|
|
|
m_config.filament_cooling_moves.get_at(i),
|
|
|
|
m_config.filament_cooling_initial_speed.get_at(i),
|
|
|
|
m_config.filament_cooling_final_speed.get_at(i),
|
|
|
|
m_config.filament_ramming_parameters.get_at(i),
|
|
|
|
m_config.nozzle_diameter.get_at(i));
|
2017-09-12 13:55:38 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
m_wipe_tower_data.priming = Slic3r::make_unique<WipeTower::ToolChangeResult>(
|
2018-09-12 09:59:02 +00:00
|
|
|
wipe_tower.prime(this->skirt_first_layer_height(), m_wipe_tower_data.tool_ordering.all_extruders(), false));
|
2017-09-01 15:30:18 +00:00
|
|
|
|
2017-12-21 12:28:26 +00:00
|
|
|
// Lets go through the wipe tower layers and determine pairs of extruder changes for each
|
|
|
|
// to pass to wipe_tower (so that it can use it for planning the layout of the tower)
|
|
|
|
{
|
2018-09-12 09:59:02 +00:00
|
|
|
unsigned int current_extruder_id = m_wipe_tower_data.tool_ordering.all_extruders().back();
|
|
|
|
for (auto &layer_tools : m_wipe_tower_data.tool_ordering.layer_tools()) { // for all layers
|
2017-12-21 12:28:26 +00:00
|
|
|
if (!layer_tools.has_wipe_tower) continue;
|
2018-09-12 09:59:02 +00:00
|
|
|
bool first_layer = &layer_tools == &m_wipe_tower_data.tool_ordering.front();
|
2017-12-22 10:26:43 +00:00
|
|
|
wipe_tower.plan_toolchange(layer_tools.print_z, layer_tools.wipe_tower_layer_height, current_extruder_id, current_extruder_id,false);
|
2017-12-21 12:28:26 +00:00
|
|
|
for (const auto extruder_id : layer_tools.extruders) {
|
2018-09-12 09:59:02 +00:00
|
|
|
if ((first_layer && extruder_id == m_wipe_tower_data.tool_ordering.all_extruders().back()) || extruder_id != current_extruder_id) {
|
2018-08-02 13:14:12 +00:00
|
|
|
float volume_to_wipe = wipe_volumes[current_extruder_id][extruder_id]; // total volume to wipe after this toolchange
|
|
|
|
// Not all of that can be used for infill purging:
|
2018-09-12 09:59:02 +00:00
|
|
|
volume_to_wipe -= m_config.filament_minimal_purge_on_wipe_tower.get_at(extruder_id);
|
2018-05-24 15:24:37 +00:00
|
|
|
|
2018-07-13 11:16:38 +00:00
|
|
|
// try to assign some infills/objects for the wiping:
|
2018-08-02 13:14:12 +00:00
|
|
|
volume_to_wipe = layer_tools.wiping_extrusions().mark_wiping_extrusions(*this, current_extruder_id, extruder_id, volume_to_wipe);
|
2018-05-24 15:24:37 +00:00
|
|
|
|
2018-08-02 13:14:12 +00:00
|
|
|
// add back the minimal amount toforce on the wipe tower:
|
2018-09-12 09:59:02 +00:00
|
|
|
volume_to_wipe += m_config.filament_minimal_purge_on_wipe_tower.get_at(extruder_id);
|
2018-05-24 15:24:37 +00:00
|
|
|
|
2018-08-02 13:14:12 +00:00
|
|
|
// request a toolchange at the wipe tower with at least volume_to_wipe purging amount
|
|
|
|
wipe_tower.plan_toolchange(layer_tools.print_z, layer_tools.wipe_tower_layer_height, current_extruder_id, extruder_id,
|
2018-09-12 09:59:02 +00:00
|
|
|
first_layer && extruder_id == m_wipe_tower_data.tool_ordering.all_extruders().back(), volume_to_wipe);
|
2017-12-21 12:28:26 +00:00
|
|
|
current_extruder_id = extruder_id;
|
2017-05-25 20:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-11 12:46:13 +00:00
|
|
|
layer_tools.wiping_extrusions().ensure_perimeters_infills_order(*this);
|
2018-09-12 09:59:02 +00:00
|
|
|
if (&layer_tools == &m_wipe_tower_data.tool_ordering.back() || (&layer_tools + 1)->wipe_tower_partitions == 0)
|
2017-12-21 12:28:26 +00:00
|
|
|
break;
|
2017-05-25 20:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-21 12:28:26 +00:00
|
|
|
|
2017-05-25 20:27:53 +00:00
|
|
|
// Generate the wipe tower layers.
|
2018-09-12 09:59:02 +00:00
|
|
|
m_wipe_tower_data.tool_changes.reserve(m_wipe_tower_data.tool_ordering.layer_tools().size());
|
|
|
|
wipe_tower.generate(m_wipe_tower_data.tool_changes);
|
|
|
|
m_wipe_tower_data.depth = wipe_tower.get_depth();
|
2018-07-27 13:56:27 +00:00
|
|
|
|
2017-05-25 20:27:53 +00:00
|
|
|
// Unload the current filament over the purge tower.
|
2018-09-11 12:04:47 +00:00
|
|
|
coordf_t layer_height = m_objects.front()->config().layer_height.value;
|
|
|
|
if (m_wipe_tower_data.tool_ordering.back().wipe_tower_partitions > 0) {
|
2017-05-30 07:25:34 +00:00
|
|
|
// The wipe tower goes up to the last layer of the print.
|
|
|
|
if (wipe_tower.layer_finished()) {
|
|
|
|
// The wipe tower is printed to the top of the print and it has no space left for the final extruder purge.
|
|
|
|
// Lift Z to the next layer.
|
2018-09-11 12:04:47 +00:00
|
|
|
wipe_tower.set_layer(float(m_wipe_tower_data.tool_ordering.back().print_z + layer_height), float(layer_height), 0, false, true);
|
2017-05-30 07:25:34 +00:00
|
|
|
} else {
|
|
|
|
// There is yet enough space at this layer of the wipe tower for the final purge.
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The wipe tower does not reach the last print layer, perform the pruge at the last print layer.
|
2018-09-11 12:04:47 +00:00
|
|
|
assert(m_wipe_tower_data.tool_ordering.back().wipe_tower_partitions == 0);
|
|
|
|
wipe_tower.set_layer(float(m_wipe_tower_data.tool_ordering.back().print_z), float(layer_height), 0, false, true);
|
2017-05-25 20:27:53 +00:00
|
|
|
}
|
2018-09-11 12:04:47 +00:00
|
|
|
m_wipe_tower_data.final_purge = Slic3r::make_unique<WipeTower::ToolChangeResult>(
|
2018-03-08 15:44:52 +00:00
|
|
|
wipe_tower.tool_change((unsigned int)-1, false));
|
2018-09-17 13:12:13 +00:00
|
|
|
|
|
|
|
m_wipe_tower_data.used_filament = wipe_tower.get_used_filament();
|
|
|
|
m_wipe_tower_data.number_of_toolchanges = wipe_tower.get_number_of_toolchanges();
|
2017-05-25 20:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
std::string Print::output_filename() const
|
2016-12-20 18:01:51 +00:00
|
|
|
{
|
2018-09-11 12:04:47 +00:00
|
|
|
DynamicConfig cfg_timestamp;
|
|
|
|
PlaceholderParser::update_timestamp(cfg_timestamp);
|
2017-12-05 14:54:24 +00:00
|
|
|
try {
|
2018-09-11 12:04:47 +00:00
|
|
|
return this->placeholder_parser().process(m_config.output_filename_format.value, 0, &cfg_timestamp);
|
2017-12-05 14:54:24 +00:00
|
|
|
} catch (std::runtime_error &err) {
|
2018-06-20 11:57:37 +00:00
|
|
|
throw std::runtime_error(L("Failed processing of the output_filename_format template.") + "\n" + err.what());
|
2017-12-05 14:54:24 +00:00
|
|
|
}
|
2016-12-20 18:01:51 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
std::string Print::output_filepath(const std::string &path) const
|
2016-12-20 18:01:51 +00:00
|
|
|
{
|
|
|
|
// if we were supplied no path, generate an automatic one based on our first object's input file
|
|
|
|
if (path.empty()) {
|
|
|
|
// get the first input file name
|
|
|
|
std::string input_file;
|
2018-09-11 12:04:47 +00:00
|
|
|
for (const PrintObject *object : m_objects) {
|
2017-05-31 10:55:59 +00:00
|
|
|
input_file = object->model_object()->input_file;
|
|
|
|
if (! input_file.empty())
|
|
|
|
break;
|
2016-12-20 18:01:51 +00:00
|
|
|
}
|
2017-10-27 20:49:59 +00:00
|
|
|
return (boost::filesystem::path(input_file).parent_path() / this->output_filename()).make_preferred().string();
|
2016-12-20 18:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we were supplied a directory, use it and append our automatically generated filename
|
|
|
|
boost::filesystem::path p(path);
|
|
|
|
if (boost::filesystem::is_directory(p))
|
2017-10-27 20:49:59 +00:00
|
|
|
return (p / this->output_filename()).make_preferred().string();
|
2016-12-20 18:01:51 +00:00
|
|
|
|
|
|
|
// if we were supplied a file which is not a directory, use it
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-09-17 10:01:02 +00:00
|
|
|
void Print::export_png(const std::string &dirpath)
|
2017-09-01 15:30:18 +00:00
|
|
|
{
|
2018-09-18 17:13:56 +00:00
|
|
|
// size_t idx = 0;
|
|
|
|
// for (PrintObject *obj : m_objects) {
|
|
|
|
// obj->slice();
|
|
|
|
// this->set_status(int(floor(idx * 100. / m_objects.size() + 0.5)), "Slicing...");
|
|
|
|
// ++ idx;
|
|
|
|
// }
|
|
|
|
// this->set_status(90, "Exporting zipped archive...");
|
|
|
|
// print_to<FilePrinterFormat::PNG>(*this,
|
|
|
|
// dirpath,
|
|
|
|
// float(m_config.bed_size_x.value),
|
|
|
|
// float(m_config.bed_size_y.value),
|
|
|
|
// int(m_config.pixel_width.value),
|
|
|
|
// int(m_config.pixel_height.value),
|
|
|
|
// float(m_config.exp_time.value),
|
|
|
|
// float(m_config.exp_time_first.value));
|
|
|
|
// this->set_status(100, "Done.");
|
2018-05-15 16:01:47 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 12:46:13 +00:00
|
|
|
// Returns extruder this eec should be printed with, according to PrintRegion config
|
|
|
|
int Print::get_extruder(const ExtrusionEntityCollection& fill, const PrintRegion ®ion)
|
|
|
|
{
|
2018-09-12 09:59:02 +00:00
|
|
|
return is_infill(fill.role()) ? std::max<int>(0, (is_solid_infill(fill.entities.front()->role()) ? region.config().solid_infill_extruder : region.config().infill_extruder) - 1) :
|
|
|
|
std::max<int>(region.config().perimeter_extruder.value - 1, 0);
|
2013-12-20 00:36:42 +00:00
|
|
|
}
|
2018-07-11 12:46:13 +00:00
|
|
|
|
2018-09-12 09:59:02 +00:00
|
|
|
} // namespace Slic3r
|
|
|
|
|