Add min_object_distance method as free function taking ConfigBase argument
This commit is contained in:
parent
9bc96bf28e
commit
89d376dc35
@ -174,6 +174,7 @@ int CLI::run(int argc, char **argv)
|
|||||||
m_print_config.apply(fff_print_config, true);
|
m_print_config.apply(fff_print_config, true);
|
||||||
} else if (printer_technology == ptSLA) {
|
} else if (printer_technology == ptSLA) {
|
||||||
// The default value has to be different from the one in fff mode.
|
// The default value has to be different from the one in fff mode.
|
||||||
|
sla_print_config.printer_technology.value = ptSLA;
|
||||||
sla_print_config.output_filename_format.value = "[input_filename_base].sl1";
|
sla_print_config.output_filename_format.value = "[input_filename_base].sl1";
|
||||||
|
|
||||||
// The default bed shape should reflect the default display parameters
|
// The default bed shape should reflect the default display parameters
|
||||||
@ -186,6 +187,8 @@ int CLI::run(int argc, char **argv)
|
|||||||
m_print_config.apply(sla_print_config, true);
|
m_print_config.apply(sla_print_config, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double min_obj_dist = min_object_distance(m_print_config);
|
||||||
|
|
||||||
// Loop through transform options.
|
// Loop through transform options.
|
||||||
bool user_center_specified = false;
|
bool user_center_specified = false;
|
||||||
for (auto const &opt_key : m_transforms) {
|
for (auto const &opt_key : m_transforms) {
|
||||||
@ -199,7 +202,7 @@ int CLI::run(int argc, char **argv)
|
|||||||
m.add_default_instances();
|
m.add_default_instances();
|
||||||
const BoundingBoxf &bb = fff_print_config.bed_shape.values;
|
const BoundingBoxf &bb = fff_print_config.bed_shape.values;
|
||||||
m.arrange_objects(
|
m.arrange_objects(
|
||||||
fff_print_config.min_object_distance(),
|
min_obj_dist,
|
||||||
// If we are going to use the merged model for printing, honor
|
// If we are going to use the merged model for printing, honor
|
||||||
// the configured print bed for arranging, otherwise do it freely.
|
// the configured print bed for arranging, otherwise do it freely.
|
||||||
this->has_print_action() ? &bb : nullptr
|
this->has_print_action() ? &bb : nullptr
|
||||||
@ -216,10 +219,10 @@ int CLI::run(int argc, char **argv)
|
|||||||
);
|
);
|
||||||
if (all_objects_have_instances) {
|
if (all_objects_have_instances) {
|
||||||
// if all input objects have defined position(s) apply duplication to the whole model
|
// if all input objects have defined position(s) apply duplication to the whole model
|
||||||
model.duplicate(m_config.opt_int("duplicate"), fff_print_config.min_object_distance(), &bb);
|
model.duplicate(m_config.opt_int("duplicate"), min_obj_dist, &bb);
|
||||||
} else {
|
} else {
|
||||||
model.add_default_instances();
|
model.add_default_instances();
|
||||||
model.duplicate_objects(m_config.opt_int("duplicate"), fff_print_config.min_object_distance(), &bb);
|
model.duplicate_objects(m_config.opt_int("duplicate"), min_obj_dist, &bb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (opt_key == "duplicate_grid") {
|
} else if (opt_key == "duplicate_grid") {
|
||||||
@ -424,7 +427,7 @@ int CLI::run(int argc, char **argv)
|
|||||||
PrintBase *print = (printer_technology == ptFFF) ? static_cast<PrintBase*>(&fff_print) : static_cast<PrintBase*>(&sla_print);
|
PrintBase *print = (printer_technology == ptFFF) ? static_cast<PrintBase*>(&fff_print) : static_cast<PrintBase*>(&sla_print);
|
||||||
if (! m_config.opt_bool("dont_arrange")) {
|
if (! m_config.opt_bool("dont_arrange")) {
|
||||||
//FIXME make the min_object_distance configurable.
|
//FIXME make the min_object_distance configurable.
|
||||||
model.arrange_objects(fff_print.config().min_object_distance());
|
model.arrange_objects(min_obj_dist);
|
||||||
model.center_instances_around_point((! user_center_specified && m_print_config.has("bed_shape")) ?
|
model.center_instances_around_point((! user_center_specified && m_print_config.has("bed_shape")) ?
|
||||||
BoundingBoxf(m_print_config.opt<ConfigOptionPoints>("bed_shape")->values).center() :
|
BoundingBoxf(m_print_config.opt<ConfigOptionPoints>("bed_shape")->values).center() :
|
||||||
m_config.option<ConfigOptionPoint>("center")->value);
|
m_config.option<ConfigOptionPoint>("center")->value);
|
||||||
|
@ -3060,6 +3060,42 @@ DynamicPrintConfig* DynamicPrintConfig::new_from_defaults_keys(const std::vector
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double min_object_distance(const ConfigBase &cfg)
|
||||||
|
{
|
||||||
|
double ret = 0.;
|
||||||
|
|
||||||
|
if (printer_technology(cfg) == ptSLA) ret = 6.;
|
||||||
|
else {
|
||||||
|
auto ecr_opt = cfg.option<ConfigOptionFloat>("extruder_clearance_radius");
|
||||||
|
auto dd_opt = cfg.option<ConfigOptionFloat>("duplicate_distance");
|
||||||
|
auto co_opt = cfg.option<ConfigOptionBool>("complete_objects");
|
||||||
|
|
||||||
|
if (!ecr_opt || !dd_opt || !co_opt) ret = 0.;
|
||||||
|
else {
|
||||||
|
// min object distance is max(duplicate_distance, clearance_radius)
|
||||||
|
ret = (co_opt->value && ecr_opt->value > dd_opt->value) ?
|
||||||
|
ecr_opt->value : dd_opt->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrinterTechnology printer_technology(const ConfigBase &cfg)
|
||||||
|
{
|
||||||
|
const ConfigOptionEnum<PrinterTechnology> *opt = cfg.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
|
||||||
|
|
||||||
|
if (opt) return opt->value;
|
||||||
|
|
||||||
|
const ConfigOptionBool *export_opt = cfg.option<ConfigOptionBool>("export_sla");
|
||||||
|
if (export_opt && export_opt->getBool()) return ptSLA;
|
||||||
|
|
||||||
|
export_opt = cfg.option<ConfigOptionBool>("export_gcode");
|
||||||
|
if (export_opt && export_opt->getBool()) return ptFFF;
|
||||||
|
|
||||||
|
return ptUnknown;
|
||||||
|
}
|
||||||
|
|
||||||
void DynamicPrintConfig::normalize()
|
void DynamicPrintConfig::normalize()
|
||||||
{
|
{
|
||||||
if (this->has("extruder")) {
|
if (this->has("extruder")) {
|
||||||
@ -3130,22 +3166,6 @@ std::string DynamicPrintConfig::validate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double PrintConfig::min_object_distance() const
|
|
||||||
{
|
|
||||||
return PrintConfig::min_object_distance(static_cast<const ConfigBase*>(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
double PrintConfig::min_object_distance(const ConfigBase *config)
|
|
||||||
{
|
|
||||||
double extruder_clearance_radius = config->option("extruder_clearance_radius")->getFloat();
|
|
||||||
double duplicate_distance = config->option("duplicate_distance")->getFloat();
|
|
||||||
|
|
||||||
// min object distance is max(duplicate_distance, clearance_radius)
|
|
||||||
return (config->option("complete_objects")->getBool() && extruder_clearance_radius > duplicate_distance)
|
|
||||||
? extruder_clearance_radius
|
|
||||||
: duplicate_distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
//FIXME localize this function.
|
//FIXME localize this function.
|
||||||
std::string FullPrintConfig::validate()
|
std::string FullPrintConfig::validate()
|
||||||
{
|
{
|
||||||
|
@ -194,6 +194,9 @@ extern const PrintConfigDef print_config_def;
|
|||||||
|
|
||||||
class StaticPrintConfig;
|
class StaticPrintConfig;
|
||||||
|
|
||||||
|
PrinterTechnology printer_technology(const ConfigBase &cfg);
|
||||||
|
double min_object_distance(const ConfigBase &cfg);
|
||||||
|
|
||||||
// Slic3r dynamic configuration, used to override the configuration
|
// Slic3r dynamic configuration, used to override the configuration
|
||||||
// per object, per modification volume or per printing material.
|
// per object, per modification volume or per printing material.
|
||||||
// The dynamic configuration is also used to store user modifications of the print global parameters,
|
// The dynamic configuration is also used to store user modifications of the print global parameters,
|
||||||
@ -749,8 +752,6 @@ class PrintConfig : public MachineEnvelopeConfig, public GCodeConfig
|
|||||||
STATIC_PRINT_CONFIG_CACHE_DERIVED(PrintConfig)
|
STATIC_PRINT_CONFIG_CACHE_DERIVED(PrintConfig)
|
||||||
PrintConfig() : MachineEnvelopeConfig(0), GCodeConfig(0) { initialize_cache(); *this = s_cache_PrintConfig.defaults(); }
|
PrintConfig() : MachineEnvelopeConfig(0), GCodeConfig(0) { initialize_cache(); *this = s_cache_PrintConfig.defaults(); }
|
||||||
public:
|
public:
|
||||||
double min_object_distance() const;
|
|
||||||
static double min_object_distance(const ConfigBase *config);
|
|
||||||
|
|
||||||
ConfigOptionBool avoid_crossing_perimeters;
|
ConfigOptionBool avoid_crossing_perimeters;
|
||||||
ConfigOptionPoints bed_shape;
|
ConfigOptionPoints bed_shape;
|
||||||
|
@ -2868,12 +2868,7 @@ void Plater::priv::find_new_position(const ModelInstancePtrs &instances,
|
|||||||
void Plater::priv::ArrangeJob::process() {
|
void Plater::priv::ArrangeJob::process() {
|
||||||
static const auto arrangestr = _L("Arranging");
|
static const auto arrangestr = _L("Arranging");
|
||||||
|
|
||||||
// FIXME: I don't know how to obtain the minimum distance, it depends
|
double dist = min_object_distance(*plater().config);
|
||||||
// on printer technology. I guess the following should work but it crashes.
|
|
||||||
double dist = 6; // PrintConfig::min_object_distance(config);
|
|
||||||
if (plater().printer_technology == ptFFF) {
|
|
||||||
dist = PrintConfig::min_object_distance(plater().config);
|
|
||||||
}
|
|
||||||
|
|
||||||
coord_t min_d = scaled(dist);
|
coord_t min_d = scaled(dist);
|
||||||
auto count = unsigned(m_selected.size() + m_unprintable.size());
|
auto count = unsigned(m_selected.size() + m_unprintable.size());
|
||||||
|
@ -167,7 +167,7 @@ void init_print(std::vector<TriangleMesh> &&meshes, Slic3r::Print &print, Slic3r
|
|||||||
object->add_volume(std::move(t));
|
object->add_volume(std::move(t));
|
||||||
object->add_instance();
|
object->add_instance();
|
||||||
}
|
}
|
||||||
model.arrange_objects(PrintConfig::min_object_distance(&config));
|
model.arrange_objects(min_object_distance(config));
|
||||||
model.center_instances_around_point(Slic3r::Vec2d(100, 100));
|
model.center_instances_around_point(Slic3r::Vec2d(100, 100));
|
||||||
for (ModelObject *mo : model.objects) {
|
for (ModelObject *mo : model.objects) {
|
||||||
mo->ensure_on_bed();
|
mo->ensure_on_bed();
|
||||||
|
@ -41,7 +41,7 @@ SCENARIO("Model construction", "[Model]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
model_object->add_instance();
|
model_object->add_instance();
|
||||||
model.arrange_objects(PrintConfig::min_object_distance(&config));
|
model.arrange_objects(min_object_distance(config));
|
||||||
model.center_instances_around_point(Slic3r::Vec2d(100, 100));
|
model.center_instances_around_point(Slic3r::Vec2d(100, 100));
|
||||||
model_object->ensure_on_bed();
|
model_object->ensure_on_bed();
|
||||||
print.auto_assign_extruders(model_object);
|
print.auto_assign_extruders(model_object);
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
void erase(t_config_option_key opt_key);
|
void erase(t_config_option_key opt_key);
|
||||||
void normalize();
|
void normalize();
|
||||||
%name{setenv} void setenv_();
|
%name{setenv} void setenv_();
|
||||||
double min_object_distance() %code{% PrintConfig cfg; cfg.apply(*THIS, true); RETVAL = cfg.min_object_distance(); %};
|
double min_object_distance() %code{% RETVAL = Slic3r::min_object_distance(*THIS); %};
|
||||||
static DynamicPrintConfig* load(char *path)
|
static DynamicPrintConfig* load(char *path)
|
||||||
%code%{
|
%code%{
|
||||||
auto config = new DynamicPrintConfig();
|
auto config = new DynamicPrintConfig();
|
||||||
@ -114,7 +114,7 @@
|
|||||||
}
|
}
|
||||||
%};
|
%};
|
||||||
%name{setenv} void setenv_();
|
%name{setenv} void setenv_();
|
||||||
double min_object_distance() %code{% RETVAL = PrintConfig::min_object_distance(THIS); %};
|
double min_object_distance() %code{% RETVAL = Slic3r::min_object_distance(*THIS); %};
|
||||||
static StaticPrintConfig* load(char *path)
|
static StaticPrintConfig* load(char *path)
|
||||||
%code%{
|
%code%{
|
||||||
auto config = new FullPrintConfig();
|
auto config = new FullPrintConfig();
|
||||||
|
Loading…
Reference in New Issue
Block a user