ENH: translate old models to correct position
Correct the position of some old models Change-Id: I5105dacff5d6b2895507fb57d77197334a651b47
This commit is contained in:
parent
a03dc779b6
commit
f3af4558ce
|
@ -324,6 +324,11 @@ static void glfw_callback(int error_code, const char* description)
|
||||||
BOOST_LOG_TRIVIAL(error) << "error_code " <<error_code <<", description: " <<description<< std::endl;
|
BOOST_LOG_TRIVIAL(error) << "error_code " <<error_code <<", description: " <<description<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float bed3d_ax3s_default_stem_radius = 0.5f;
|
||||||
|
const float bed3d_ax3s_default_stem_length = 25.0f;
|
||||||
|
const float bed3d_ax3s_default_tip_radius = 2.5f * bed3d_ax3s_default_stem_radius;
|
||||||
|
const float bed3d_ax3s_default_tip_length = 5.0f;
|
||||||
|
|
||||||
int CLI::run(int argc, char **argv)
|
int CLI::run(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// Mark the main thread for the debugger and for runtime checks.
|
// Mark the main thread for the debugger and for runtime checks.
|
||||||
|
@ -398,6 +403,8 @@ int CLI::run(int argc, char **argv)
|
||||||
boost::algorithm::iends_with(boost::filesystem::path(argv[0]).filename().string(), "gcodeviewer");
|
boost::algorithm::iends_with(boost::filesystem::path(argv[0]).filename().string(), "gcodeviewer");
|
||||||
#endif // _WIN32*/
|
#endif // _WIN32*/
|
||||||
|
|
||||||
|
bool translate_old = false;
|
||||||
|
int current_width, current_depth, current_height;
|
||||||
const std::vector<std::string> &load_configs = m_config.option<ConfigOptionStrings>("load_settings", true)->values;
|
const std::vector<std::string> &load_configs = m_config.option<ConfigOptionStrings>("load_settings", true)->values;
|
||||||
//BBS: always use ForwardCompatibilitySubstitutionRule::Enable
|
//BBS: always use ForwardCompatibilitySubstitutionRule::Enable
|
||||||
//const ForwardCompatibilitySubstitutionRule config_substitution_rule = m_config.option<ConfigOptionEnum<ForwardCompatibilitySubstitutionRule>>("config_compatibility", true)->value;
|
//const ForwardCompatibilitySubstitutionRule config_substitution_rule = m_config.option<ConfigOptionEnum<ForwardCompatibilitySubstitutionRule>>("config_compatibility", true)->value;
|
||||||
|
@ -540,6 +547,11 @@ int CLI::run(int argc, char **argv)
|
||||||
BOOST_LOG_TRIVIAL(info) << "object "<<o->name <<", id :" << o->id().id << ", from bbl 3mf\n";
|
BOOST_LOG_TRIVIAL(info) << "object "<<o->name <<", id :" << o->id().id << ", from bbl 3mf\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Semver old_version(1, 5, 9);
|
||||||
|
if ((file_version < old_version) && !config.empty()) {
|
||||||
|
translate_old = true;
|
||||||
|
}
|
||||||
|
|
||||||
/*for (ModelObject *model_object : model.objects)
|
/*for (ModelObject *model_object : model.objects)
|
||||||
for (ModelInstance *model_instance : model_object->instances)
|
for (ModelInstance *model_instance : model_object->instances)
|
||||||
{
|
{
|
||||||
|
@ -1280,7 +1292,15 @@ int CLI::run(int argc, char **argv)
|
||||||
if (m_models.size() > 0)
|
if (m_models.size() > 0)
|
||||||
{
|
{
|
||||||
std::string bed_texture;
|
std::string bed_texture;
|
||||||
partplate_list.reset_size(bedfs[2].x() - bedfs[0].x(), bedfs[2].y() - bedfs[0].y(), print_height);
|
if (translate_old) {
|
||||||
|
current_width = bedfs[2].x() - bedfs[0].x();
|
||||||
|
current_depth = bedfs[2].y() - bedfs[0].y();
|
||||||
|
current_height = print_height;
|
||||||
|
partplate_list.reset_size(current_width + bed3d_ax3s_default_tip_radius, current_depth + bed3d_ax3s_default_tip_radius, current_height, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
partplate_list.reset_size(bedfs[2].x() - bedfs[0].x(), bedfs[2].y() - bedfs[0].y(), print_height, false);
|
||||||
|
}
|
||||||
partplate_list.set_shapes(bedfs, excluse_areas, bed_texture, height_to_lid, height_to_rod);
|
partplate_list.set_shapes(bedfs, excluse_areas, bed_texture, height_to_lid, height_to_rod);
|
||||||
plate_stride = partplate_list.plate_stride_x();
|
plate_stride = partplate_list.plate_stride_x();
|
||||||
BOOST_LOG_TRIVIAL(info) << "bed size, x="<<bedfs[2].x() - bedfs[0].x()<<",y="<<bedfs[2].y() - bedfs[0].y()<<",z="<< print_height <<"\n";
|
BOOST_LOG_TRIVIAL(info) << "bed size, x="<<bedfs[2].x() - bedfs[0].x()<<",y="<<bedfs[2].y() - bedfs[0].y()<<",z="<< print_height <<"\n";
|
||||||
|
@ -1288,6 +1308,20 @@ int CLI::run(int argc, char **argv)
|
||||||
if (plate_data_src.size() > 0)
|
if (plate_data_src.size() > 0)
|
||||||
{
|
{
|
||||||
partplate_list.load_from_3mf_structure(plate_data_src);
|
partplate_list.load_from_3mf_structure(plate_data_src);
|
||||||
|
//BBS: translate old 3mf to correct positions
|
||||||
|
if (translate_old) {
|
||||||
|
//translate the objects
|
||||||
|
int plate_count = partplate_list.get_plate_count();
|
||||||
|
for (int index = 1; index < plate_count; index ++) {
|
||||||
|
Slic3r::GUI::PartPlate* cur_plate = (Slic3r::GUI::PartPlate *)partplate_list.get_plate(index);
|
||||||
|
|
||||||
|
Vec3d cur_origin = cur_plate->get_origin();
|
||||||
|
Vec3d new_origin = partplate_list.compute_origin_using_new_size(index, current_width, current_depth);
|
||||||
|
|
||||||
|
cur_plate->translate_all_instance(new_origin - cur_origin);
|
||||||
|
}
|
||||||
|
partplate_list.reset_size(current_width, current_depth, current_height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*for (ModelObject *model_object : m_models[0].objects)
|
/*for (ModelObject *model_object : m_models[0].objects)
|
||||||
for (ModelInstance *model_instance : model_object->instances)
|
for (ModelInstance *model_instance : model_object->instances)
|
||||||
|
|
|
@ -1745,6 +1745,29 @@ int PartPlate::remove_instance(int obj_id, int instance_id)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//translate instance on the plate
|
||||||
|
void PartPlate::translate_all_instance(Vec3d position)
|
||||||
|
{
|
||||||
|
for (std::set<std::pair<int, int>>::iterator it = obj_to_instance_set.begin(); it != obj_to_instance_set.end(); ++it)
|
||||||
|
{
|
||||||
|
int obj_id = it->first;
|
||||||
|
int instance_id = it->second;
|
||||||
|
|
||||||
|
if ((obj_id >= 0) && (obj_id < m_model->objects.size()))
|
||||||
|
{
|
||||||
|
ModelObject* object = m_model->objects[obj_id];
|
||||||
|
if ((instance_id >= 0) && (instance_id < object->instances.size()))
|
||||||
|
{
|
||||||
|
ModelInstance* instance = object->instances[instance_id];
|
||||||
|
const Vec3d& offset = instance->get_offset();
|
||||||
|
instance->set_offset(offset + position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//update instance exclude state
|
//update instance exclude state
|
||||||
void PartPlate::update_instance_exclude_status(int obj_id, int instance_id, BoundingBoxf3* bounding_box)
|
void PartPlate::update_instance_exclude_status(int obj_id, int instance_id, BoundingBoxf3* bounding_box)
|
||||||
{
|
{
|
||||||
|
@ -2467,6 +2490,23 @@ Vec3d PartPlateList::compute_origin(int i, int cols)
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//compute the origin for printable plate with index i using new width
|
||||||
|
Vec3d PartPlateList::compute_origin_using_new_size(int i, int new_width, int new_depth)
|
||||||
|
{
|
||||||
|
Vec3d origin;
|
||||||
|
int row, col;
|
||||||
|
|
||||||
|
row = i / m_plate_cols;
|
||||||
|
col = i % m_plate_cols;
|
||||||
|
|
||||||
|
origin(0) = col * (new_width * (1. + LOGICAL_PART_PLATE_GAP));
|
||||||
|
origin(1) = -row * (new_depth * (1. + LOGICAL_PART_PLATE_GAP));
|
||||||
|
origin(2) = 0;
|
||||||
|
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//compute the origin for printable plate with index i
|
//compute the origin for printable plate with index i
|
||||||
Vec3d PartPlateList::compute_origin_for_unprintable()
|
Vec3d PartPlateList::compute_origin_for_unprintable()
|
||||||
{
|
{
|
||||||
|
@ -2698,7 +2738,7 @@ void PartPlateList::release_icon_textures()
|
||||||
}
|
}
|
||||||
|
|
||||||
//this may be happened after machine changed
|
//this may be happened after machine changed
|
||||||
void PartPlateList::reset_size(int width, int depth, int height)
|
void PartPlateList::reset_size(int width, int depth, int height, bool reload_objects)
|
||||||
{
|
{
|
||||||
Vec3d origin1, origin2;
|
Vec3d origin1, origin2;
|
||||||
|
|
||||||
|
@ -2710,7 +2750,10 @@ void PartPlateList::reset_size(int width, int depth, int height)
|
||||||
m_plate_depth = depth;
|
m_plate_depth = depth;
|
||||||
m_plate_height = height;
|
m_plate_height = height;
|
||||||
update_all_plates_pos_and_size(false, false);
|
update_all_plates_pos_and_size(false, false);
|
||||||
|
if (reload_objects)
|
||||||
reload_all_objects();
|
reload_all_objects();
|
||||||
|
else
|
||||||
|
clear(false, false, false, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -290,6 +290,9 @@ public:
|
||||||
//remove instance from plate
|
//remove instance from plate
|
||||||
int remove_instance(int obj_id, int instance_id);
|
int remove_instance(int obj_id, int instance_id);
|
||||||
|
|
||||||
|
//translate instance on the plate
|
||||||
|
void translate_all_instance(Vec3d position);
|
||||||
|
|
||||||
//update instance exclude state
|
//update instance exclude state
|
||||||
void update_instance_exclude_status(int obj_id, int instance_id, BoundingBoxf3* bounding_box = nullptr);
|
void update_instance_exclude_status(int obj_id, int instance_id, BoundingBoxf3* bounding_box = nullptr);
|
||||||
|
|
||||||
|
@ -568,11 +571,13 @@ public:
|
||||||
~PartPlateList();
|
~PartPlateList();
|
||||||
|
|
||||||
//this may be happened after machine changed
|
//this may be happened after machine changed
|
||||||
void reset_size(int width, int depth, int height);
|
void reset_size(int width, int depth, int height, bool reload_objects = true);
|
||||||
//clear all the instances in the plate, but keep the plates
|
//clear all the instances in the plate, but keep the plates
|
||||||
void clear(bool delete_plates = false, bool release_print_list = false, bool except_locked = false, int plate_index = -1);
|
void clear(bool delete_plates = false, bool release_print_list = false, bool except_locked = false, int plate_index = -1);
|
||||||
//clear all the instances in the plate, and delete the plates, only keep the first default plate
|
//clear all the instances in the plate, and delete the plates, only keep the first default plate
|
||||||
void reset(bool do_init);
|
void reset(bool do_init);
|
||||||
|
//compute the origin for printable plate with index i using new width
|
||||||
|
Vec3d compute_origin_using_new_size(int i, int new_width, int new_depth);
|
||||||
|
|
||||||
//reset partplate to init states
|
//reset partplate to init states
|
||||||
void reinit();
|
void reinit();
|
||||||
|
@ -580,6 +585,11 @@ public:
|
||||||
//get the plate stride
|
//get the plate stride
|
||||||
double plate_stride_x();
|
double plate_stride_x();
|
||||||
double plate_stride_y();
|
double plate_stride_y();
|
||||||
|
void get_plate_size(int& width, int& depth, int& height) {
|
||||||
|
width = m_plate_width;
|
||||||
|
depth = m_plate_depth;
|
||||||
|
height = m_plate_height;
|
||||||
|
}
|
||||||
|
|
||||||
/*basic plate operations*/
|
/*basic plate operations*/
|
||||||
//create an empty plate and return its index
|
//create an empty plate and return its index
|
||||||
|
|
|
@ -2902,6 +2902,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||||
std::vector<size_t> empty_result;
|
std::vector<size_t> empty_result;
|
||||||
bool dlg_cont = true;
|
bool dlg_cont = true;
|
||||||
bool is_user_cancel = false;
|
bool is_user_cancel = false;
|
||||||
|
bool translate_old = false;
|
||||||
|
int current_width, current_depth, current_height;
|
||||||
|
|
||||||
if (input_files.empty()) { return std::vector<size_t>(); }
|
if (input_files.empty()) { return std::vector<size_t>(); }
|
||||||
|
|
||||||
|
@ -3160,7 +3162,17 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||||
return empty_result;
|
return empty_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Semver old_version(1, 5, 9);
|
||||||
|
if ((en_3mf_file_type == En3mfType::From_BBS) && (file_version < old_version) && load_model && load_config && !config_loaded.empty()) {
|
||||||
|
translate_old = true;
|
||||||
|
partplate_list.get_plate_size(current_width, current_depth, current_height);
|
||||||
|
}
|
||||||
|
|
||||||
if (load_config) {
|
if (load_config) {
|
||||||
|
if (translate_old) {
|
||||||
|
//set the size back
|
||||||
|
partplate_list.reset_size(current_width + Bed3D::Axes::DefaultTipRadius, current_depth + Bed3D::Axes::DefaultTipRadius, current_height, false);
|
||||||
|
}
|
||||||
partplate_list.load_from_3mf_structure(plate_data);
|
partplate_list.load_from_3mf_structure(plate_data);
|
||||||
partplate_list.update_slice_context_to_current_plate(background_process);
|
partplate_list.update_slice_context_to_current_plate(background_process);
|
||||||
this->preview->update_gcode_result(partplate_list.get_current_slice_result());
|
this->preview->update_gcode_result(partplate_list.get_current_slice_result());
|
||||||
|
@ -3552,6 +3564,21 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||||
|
|
||||||
if (new_model) delete new_model;
|
if (new_model) delete new_model;
|
||||||
|
|
||||||
|
//BBS: translate old 3mf to correct positions
|
||||||
|
if (translate_old) {
|
||||||
|
//translate the objects
|
||||||
|
int plate_count = partplate_list.get_plate_count();
|
||||||
|
for (int index = 1; index < plate_count; index ++) {
|
||||||
|
PartPlate* cur_plate = (PartPlate *)partplate_list.get_plate(index);
|
||||||
|
|
||||||
|
Vec3d cur_origin = cur_plate->get_origin();
|
||||||
|
Vec3d new_origin = partplate_list.compute_origin_using_new_size(index, current_width, current_depth);
|
||||||
|
|
||||||
|
cur_plate->translate_all_instance(new_origin - cur_origin);
|
||||||
|
}
|
||||||
|
partplate_list.reset_size(current_width, current_depth, current_height);
|
||||||
|
}
|
||||||
|
|
||||||
//BBS: add gcode loading logic in the end
|
//BBS: add gcode loading logic in the end
|
||||||
q->m_exported_file = false;
|
q->m_exported_file = false;
|
||||||
q->skip_thumbnail_invalid = false;
|
q->skip_thumbnail_invalid = false;
|
||||||
|
@ -6905,7 +6932,7 @@ void Plater::priv::set_bed_shape(const Pointfs& shape, const Pointfs& exclude_ar
|
||||||
double z = config->opt_float("printable_height");
|
double z = config->opt_float("printable_height");
|
||||||
|
|
||||||
//Pointfs& exclude_areas = config->option<ConfigOptionPoints>("bed_exclude_area")->values;
|
//Pointfs& exclude_areas = config->option<ConfigOptionPoints>("bed_exclude_area")->values;
|
||||||
partplate_list.reset_size(max.x() - min.x(), max.y() - min.y(), z);
|
partplate_list.reset_size(max.x() - min.x() - Bed3D::Axes::DefaultTipRadius, max.y() - min.y() - Bed3D::Axes::DefaultTipRadius, z);
|
||||||
partplate_list.set_shapes(shape, exclude_areas, custom_texture, height_to_lid, height_to_rod);
|
partplate_list.set_shapes(shape, exclude_areas, custom_texture, height_to_lid, height_to_rod);
|
||||||
|
|
||||||
Vec2d new_shape_position = partplate_list.get_current_shape_position();
|
Vec2d new_shape_position = partplate_list.get_current_shape_position();
|
||||||
|
|
Loading…
Reference in New Issue