This commit is contained in:
Filip Sykala - NTB T15p 2023-01-03 13:24:09 +01:00
commit d6e9b2909b
9 changed files with 131 additions and 71 deletions

View File

@ -430,7 +430,26 @@ static bool contains_skew(const Transform3d& trafo)
Matrix3d rotation; Matrix3d rotation;
Matrix3d scale; Matrix3d scale;
trafo.computeRotationScaling(&rotation, &scale); trafo.computeRotationScaling(&rotation, &scale);
return !scale.isDiagonal();
if (scale.isDiagonal())
return false;
if (scale.determinant() >= 0.0)
return true;
// the matrix contains mirror
const Matrix3d ratio = scale.cwiseQuotient(trafo.matrix().block<3,3>(0,0));
auto check_skew = [&ratio](int i, int j, bool& skew) {
if (!std::isnan(ratio(i, j)) && !std::isnan(ratio(j, i)))
skew |= std::abs(ratio(i, j) * ratio(j, i) - 1.0) > EPSILON;
};
bool has_skew = false;
check_skew(0, 1, has_skew);
check_skew(0, 2, has_skew);
check_skew(1, 2, has_skew);
return has_skew;
} }
Vec3d Transformation::get_rotation() const Vec3d Transformation::get_rotation() const

View File

@ -1198,7 +1198,11 @@ void ObjectManipulation::change_scale_value(int axis, double value)
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
const Selection& selection = wxGetApp().plater()->canvas3D()->get_selection(); const Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
Vec3d ref_scale = m_cache.scale; Vec3d ref_scale = m_cache.scale;
if (selection.is_single_full_instance()) { if (selection.is_single_volume_or_modifier()) {
if (is_local_coordinates())
ref_scale = 100.0 * Vec3d::Ones();
}
else if (selection.is_single_full_instance()) {
scale = scale.cwiseQuotient(ref_scale); scale = scale.cwiseQuotient(ref_scale);
ref_scale = Vec3d::Ones(); ref_scale = Vec3d::Ones();
} }

View File

@ -4188,6 +4188,8 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name); wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);
} }
std::string last_selected_ph_printer_name = combo->get_selected_ph_printer_name();
bool select_preset = !combo->selection_is_changed_according_to_physical_printers(); bool select_preset = !combo->selection_is_changed_according_to_physical_printers();
// TODO: ? // TODO: ?
if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) { if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) {
@ -4196,7 +4198,7 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
} }
else if (select_preset) { else if (select_preset) {
wxWindowUpdateLocker noUpdates(sidebar->presets_panel()); wxWindowUpdateLocker noUpdates(sidebar->presets_panel());
wxGetApp().get_tab(preset_type)->select_preset(preset_name); wxGetApp().get_tab(preset_type)->select_preset(preset_name, false, last_selected_ph_printer_name);
} }
if (preset_type != Preset::TYPE_PRINTER || select_preset) { if (preset_type != Preset::TYPE_PRINTER || select_preset) {

View File

@ -666,6 +666,18 @@ void PlaterPresetComboBox::OnSelect(wxCommandEvent &evt)
evt.Skip(); evt.Skip();
} }
std::string PlaterPresetComboBox::get_selected_ph_printer_name() const
{
if (m_type != Preset::TYPE_PRINTER)
return {};
const PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers;
if (physical_printers.has_selection())
return physical_printers.get_selected_full_printer_name();
return {};
}
void PlaterPresetComboBox::switch_to_tab() void PlaterPresetComboBox::switch_to_tab()
{ {
Tab* tab = wxGetApp().get_tab(m_type); Tab* tab = wxGetApp().get_tab(m_type);

View File

@ -164,6 +164,8 @@ public:
void sys_color_changed() override; void sys_color_changed() override;
void OnSelect(wxCommandEvent& evt) override; void OnSelect(wxCommandEvent& evt) override;
std::string get_selected_ph_printer_name() const;
private: private:
int m_extruder_idx = -1; int m_extruder_idx = -1;
}; };

View File

@ -826,17 +826,26 @@ void Selection::translate(const Vec3d& displacement, TransformationType transfor
const VolumeCache& volume_data = m_cache.volumes_data[i]; const VolumeCache& volume_data = m_cache.volumes_data[i];
if (m_mode == Instance && !is_wipe_tower()) { if (m_mode == Instance && !is_wipe_tower()) {
assert(is_from_fully_selected_instance(i)); assert(is_from_fully_selected_instance(i));
if (transformation_type.world()) if (transformation_type.instance()) {
v.set_instance_transformation(Geometry::translation_transform(displacement) * volume_data.get_instance_full_matrix()); const Geometry::Transformation& inst_trafo = volume_data.get_instance_transform();
else if (transformation_type.instance()) { v.set_instance_offset(inst_trafo.get_offset() + inst_trafo.get_rotation_matrix() * displacement);
const Vec3d world_displacement = volume_data.get_instance_rotation_matrix() * displacement;
v.set_instance_transformation(Geometry::translation_transform(world_displacement) * volume_data.get_instance_full_matrix());
} }
else else
assert(false); transform_instance_relative(v, volume_data, transformation_type, Geometry::translation_transform(displacement), m_cache.dragging_center);
}
else {
if (transformation_type.local()) {
const Geometry::Transformation& vol_trafo = volume_data.get_volume_transform();
v.set_volume_offset(vol_trafo.get_offset() + vol_trafo.get_rotation_matrix() * displacement);
}
else {
Vec3d relative_disp = displacement;
if (transformation_type.instance())
relative_disp = volume_data.get_instance_scale_matrix().inverse() * relative_disp;
transform_volume_relative(v, volume_data, transformation_type, Geometry::translation_transform(relative_disp), m_cache.dragging_center);
}
} }
else
transform_volume_relative(v, volume_data, transformation_type, Geometry::translation_transform(displacement), m_cache.dragging_center);
} }
#if !DISABLE_INSTANCES_SYNCH #if !DISABLE_INSTANCES_SYNCH
@ -909,23 +918,16 @@ void Selection::rotate(const Vec3d& rotation, TransformationType transformation_
const Geometry::Transformation& inst_trafo = volume_data.get_instance_transform(); const Geometry::Transformation& inst_trafo = volume_data.get_instance_transform();
if (m_mode == Instance && !is_wipe_tower()) { if (m_mode == Instance && !is_wipe_tower()) {
assert(is_from_fully_selected_instance(i)); assert(is_from_fully_selected_instance(i));
Transform3d new_rotation_matrix = Transform3d::Identity(); if (transformation_type.instance()) {
if (transformation_type.absolute()) const Vec3d world_inst_pivot = m_cache.dragging_center - inst_trafo.get_offset();
new_rotation_matrix = rotation_matrix; const Vec3d local_inst_pivot = inst_trafo.get_matrix_no_offset().inverse() * world_inst_pivot;
else { Matrix3d inst_rotation, inst_scale;
if (transformation_type.world()) inst_trafo.get_matrix().computeRotationScaling(&inst_rotation, &inst_scale);
new_rotation_matrix = rotation_matrix * inst_trafo.get_rotation_matrix(); const Transform3d trafo = inst_trafo.get_rotation_matrix() * rotation_matrix;
else if (transformation_type.instance()) v.set_instance_transformation(Geometry::translation_transform(world_inst_pivot) * inst_trafo.get_offset_matrix() * trafo * Transform3d(inst_scale) * Geometry::translation_transform(-local_inst_pivot));
new_rotation_matrix = inst_trafo.get_rotation_matrix() * rotation_matrix;
else
assert(false);
} }
else
const Vec3d new_offset = transformation_type.independent() ? inst_trafo.get_offset() : transform_instance_relative(v, volume_data, transformation_type, rotation_matrix, m_cache.dragging_center);
m_cache.dragging_center + new_rotation_matrix * inst_trafo.get_rotation_matrix().inverse() *
(inst_trafo.get_offset() - m_cache.dragging_center);
v.set_instance_transformation(Geometry::assemble_transform(Geometry::translation_transform(new_offset), new_rotation_matrix,
inst_trafo.get_scaling_factor_matrix(), inst_trafo.get_mirror_matrix()));
} }
else { else {
if (!is_single_volume_or_modifier()) { if (!is_single_volume_or_modifier()) {
@ -933,8 +935,15 @@ void Selection::rotate(const Vec3d& rotation, TransformationType transformation_
transform_volume_relative(v, volume_data, transformation_type, rotation_matrix, m_cache.dragging_center); transform_volume_relative(v, volume_data, transformation_type, rotation_matrix, m_cache.dragging_center);
} }
else { else {
transformation_type.set_independent(); if (transformation_type.local()) {
transform_volume_relative(v, volume_data, transformation_type, rotation_matrix, m_cache.dragging_center); const Geometry::Transformation& vol_trafo = volume_data.get_volume_transform();
Matrix3d vol_rotation, vol_scale;
vol_trafo.get_matrix().computeRotationScaling(&vol_rotation, &vol_scale);
const Transform3d trafo = vol_trafo.get_rotation_matrix() * rotation_matrix;
v.set_volume_transformation(vol_trafo.get_offset_matrix() * trafo * Transform3d(vol_scale));
}
else
transform_volume_relative(v, volume_data, transformation_type, rotation_matrix, m_cache.dragging_center);
} }
} }
} }
@ -1357,32 +1366,17 @@ void Selection::scale_and_translate(const Vec3d& scale, const Vec3d& translation
} }
if (m_mode == Instance) { if (m_mode == Instance) {
assert(is_from_fully_selected_instance(i)); if (transformation_type.instance()) {
if (transformation_type.world()) { const Vec3d world_inst_pivot = m_cache.dragging_center - inst_trafo.get_offset();
const Transform3d scale_matrix = Geometry::scale_transform(relative_scale); const Vec3d local_inst_pivot = inst_trafo.get_matrix_no_offset().inverse() * world_inst_pivot;
const Transform3d offset_matrix = (transformation_type.joint() && translation.isApprox(Vec3d::Zero())) ? Matrix3d inst_rotation, inst_scale;
// non-constrained scaling - add offset to scale around selection center inst_trafo.get_matrix().computeRotationScaling(&inst_rotation, &inst_scale);
Geometry::translation_transform(m_cache.dragging_center + scale_matrix * (inst_trafo.get_offset() - m_cache.dragging_center)) : const Transform3d offset_trafo = Geometry::translation_transform(inst_trafo.get_offset() + inst_rotation * translation);
// constrained scaling - add offset to keep constraint const Transform3d scale_trafo = Transform3d(inst_scale) * Geometry::scale_transform(relative_scale);
Geometry::translation_transform(translation) * inst_trafo.get_offset_matrix(); v.set_instance_transformation(Geometry::translation_transform(world_inst_pivot) * offset_trafo * Transform3d(inst_rotation) * scale_trafo * Geometry::translation_transform(-local_inst_pivot));
v.set_instance_transformation(offset_matrix * scale_matrix * inst_trafo.get_matrix_no_offset());
}
else if (transformation_type.instance()) {
const Transform3d scale_matrix = Geometry::scale_transform(relative_scale);
Vec3d offset;
if (transformation_type.joint() && translation.isApprox(Vec3d::Zero())) {
// non-constrained scaling - add offset to scale around selection center
offset = inst_trafo.get_matrix_no_offset().inverse() * (inst_trafo.get_offset() - m_cache.dragging_center);
offset = inst_trafo.get_matrix_no_offset() * (scale_matrix * offset - offset);
}
else
// constrained scaling - add offset to keep constraint
offset = translation;
v.set_instance_transformation(Geometry::translation_transform(offset) * inst_trafo.get_matrix() * scale_matrix);
} }
else else
assert(false); transform_instance_relative(v, volume_data, transformation_type, Geometry::translation_transform(translation) * Geometry::scale_transform(relative_scale), m_cache.dragging_center);
} }
else { else {
if (!is_single_volume_or_modifier()) { if (!is_single_volume_or_modifier()) {
@ -1390,8 +1384,18 @@ void Selection::scale_and_translate(const Vec3d& scale, const Vec3d& translation
transform_volume_relative(v, volume_data, transformation_type, Geometry::translation_transform(translation) * Geometry::scale_transform(relative_scale), m_cache.dragging_center); transform_volume_relative(v, volume_data, transformation_type, Geometry::translation_transform(translation) * Geometry::scale_transform(relative_scale), m_cache.dragging_center);
} }
else { else {
transformation_type.set_independent(); if (transformation_type.local()) {
transform_volume_relative(v, volume_data, transformation_type, Geometry::translation_transform(translation) * Geometry::scale_transform(relative_scale), m_cache.dragging_center); const Geometry::Transformation& vol_trafo = volume_data.get_volume_transform();
Matrix3d vol_rotation, vol_scale;
vol_trafo.get_matrix().computeRotationScaling(&vol_rotation, &vol_scale);
const Transform3d offset_trafo = Geometry::translation_transform(vol_trafo.get_offset() + vol_rotation * translation);
const Transform3d scale_trafo = Transform3d(vol_scale) * Geometry::scale_transform(relative_scale);
v.set_volume_transformation(offset_trafo * Transform3d(vol_rotation) * scale_trafo);
}
else {
transformation_type.set_independent();
transform_volume_relative(v, volume_data, transformation_type, Geometry::translation_transform(translation) * Geometry::scale_transform(relative_scale), m_cache.dragging_center);
}
} }
} }
} }
@ -3040,28 +3044,36 @@ void Selection::paste_objects_from_clipboard()
} }
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
void Selection::transform_instance_relative(GLVolume& volume, const VolumeCache& volume_data, TransformationType transformation_type,
const Transform3d& transform, const Vec3d& world_pivot)
{
assert(transformation_type.relative());
assert(transformation_type.world());
const Geometry::Transformation& inst_trafo = volume_data.get_instance_transform();
const Vec3d inst_pivot = transformation_type.independent() && !is_from_single_instance() ? inst_trafo.get_offset() : world_pivot;
const Transform3d trafo = Geometry::translation_transform(inst_pivot) * transform * Geometry::translation_transform(-inst_pivot);
volume.set_instance_transformation(trafo * inst_trafo.get_matrix());
}
void Selection::transform_volume_relative(GLVolume& volume, const VolumeCache& volume_data, TransformationType transformation_type, void Selection::transform_volume_relative(GLVolume& volume, const VolumeCache& volume_data, TransformationType transformation_type,
const Transform3d& transform, const Vec3d& world_pivot) const Transform3d& transform, const Vec3d& world_pivot)
{ {
assert(transformation_type.relative()); assert(transformation_type.relative());
const Geometry::Transformation& volume_trafo = volume_data.get_volume_transform(); const Geometry::Transformation& vol_trafo = volume_data.get_volume_transform();
const Geometry::Transformation& inst_trafo = volume_data.get_instance_transform(); const Geometry::Transformation& inst_trafo = volume_data.get_instance_transform();
if (transformation_type.world()) { if (transformation_type.world()) {
const Vec3d inst_pivot = transformation_type.independent() ? volume_trafo.get_offset() : (Vec3d)(inst_trafo.get_matrix().inverse() * world_pivot); const Vec3d inst_pivot = transformation_type.independent() ? vol_trafo.get_offset() : (Vec3d)(inst_trafo.get_matrix().inverse() * world_pivot);
const Transform3d inst_matrix_no_offset = inst_trafo.get_matrix_no_offset(); const Transform3d inst_matrix_no_offset = inst_trafo.get_matrix_no_offset();
const Transform3d trafo = Geometry::translation_transform(inst_pivot) * inst_matrix_no_offset.inverse() * transform * inst_matrix_no_offset * Geometry::translation_transform(-inst_pivot); const Transform3d trafo = Geometry::translation_transform(inst_pivot) * inst_matrix_no_offset.inverse() * transform * inst_matrix_no_offset * Geometry::translation_transform(-inst_pivot);
volume.set_volume_transformation(trafo * volume_trafo.get_matrix()); volume.set_volume_transformation(trafo * vol_trafo.get_matrix());
} }
else if (transformation_type.instance()) { else if (transformation_type.instance()) {
const Vec3d inst_pivot = transformation_type.independent() ? volume_trafo.get_offset() : (Vec3d)(inst_trafo.get_matrix().inverse() * world_pivot); const Vec3d inst_pivot = transformation_type.independent() ? vol_trafo.get_offset() : (Vec3d)(inst_trafo.get_matrix().inverse() * world_pivot);
const Transform3d trafo = Geometry::translation_transform(inst_pivot) * transform * Geometry::translation_transform(-inst_pivot); const Transform3d trafo = Geometry::translation_transform(inst_pivot) * transform * Geometry::translation_transform(-inst_pivot);
volume.set_volume_transformation(trafo * volume_trafo.get_matrix()); volume.set_volume_transformation(trafo * vol_trafo.get_matrix());
}
else if (transformation_type.local()) {
const Geometry::Transformation trafo(transform);
volume.set_volume_transformation(trafo.get_offset_matrix() * volume_trafo.get_matrix() * trafo.get_matrix_no_offset());
} }
else else
assert(false); assert(false);

View File

@ -501,6 +501,8 @@ private:
void paste_objects_from_clipboard(); void paste_objects_from_clipboard();
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
void transform_instance_relative(GLVolume& volume, const VolumeCache& volume_data, TransformationType transformation_type,
const Transform3d& transform, const Vec3d& world_pivot);
void transform_volume_relative(GLVolume& volume, const VolumeCache& volume_data, TransformationType transformation_type, void transform_volume_relative(GLVolume& volume, const VolumeCache& volume_data, TransformationType transformation_type,
const Transform3d& transform, const Vec3d& world_pivot); const Transform3d& transform, const Vec3d& world_pivot);
#endif // ENABLE_WORLD_COORDINATE #endif // ENABLE_WORLD_COORDINATE

View File

@ -2978,6 +2978,10 @@ void TabPrinter::activate_selected_page(std::function<void()> throw_if_canceled)
void TabPrinter::clear_pages() void TabPrinter::clear_pages()
{ {
Tab::clear_pages(); Tab::clear_pages();
m_machine_limits_description_line = nullptr;
m_fff_print_host_upload_description_line = nullptr;
m_sla_print_host_upload_description_line = nullptr;
} }
void TabPrinter::toggle_options() void TabPrinter::toggle_options()
@ -3402,7 +3406,7 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/,
// If preset selection was canceled and previously was selected physical printer, we should select it back // If preset selection was canceled and previously was selected physical printer, we should select it back
m_preset_bundle->physical_printers.select_printer(last_selected_ph_printer_name); m_preset_bundle->physical_printers.select_printer(last_selected_ph_printer_name);
} }
if (m_preset_bundle->physical_printers.has_selection()) { else if (m_preset_bundle->physical_printers.has_selection()) {
// If preset selection was canceled and physical printer was selected // If preset selection was canceled and physical printer was selected
// we must disable selection marker for the physical printers // we must disable selection marker for the physical printers
m_preset_bundle->physical_printers.unselect_printer(); m_preset_bundle->physical_printers.unselect_printer();

View File

@ -1571,6 +1571,13 @@ void DiffPresetDialog::create_tree()
m_tree->GetColumn(DiffModel::colToggle)->SetHidden(true); m_tree->GetColumn(DiffModel::colToggle)->SetHidden(true);
} }
static std::array<Preset::Type, 3> types_list(PrinterTechnology pt)
{
if (pt == ptFFF)
return { Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT };
return { Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL };
}
void DiffPresetDialog::create_buttons() void DiffPresetDialog::create_buttons()
{ {
wxFont font = this->GetFont().Scaled(1.4f); wxFont font = this->GetFont().Scaled(1.4f);
@ -1598,8 +1605,7 @@ void DiffPresetDialog::create_buttons()
bool enable = m_tree->has_selection(); bool enable = m_tree->has_selection();
if (enable) { if (enable) {
if (m_view_type == Preset::TYPE_INVALID) { if (m_view_type == Preset::TYPE_INVALID) {
for (const Preset::Type& type : (m_pr_technology == ptFFF ? std::initializer_list<Preset::Type>{Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT} : for (const Preset::Type& type : types_list(m_pr_technology))
std::initializer_list<Preset::Type>{ Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL }))
if (!enable_transfer(type)) { if (!enable_transfer(type)) {
enable = false; enable = false;
break; break;
@ -2024,10 +2030,7 @@ bool DiffPresetDialog::is_save_confirmed()
std::vector<Preset::Type> types_for_save; std::vector<Preset::Type> types_for_save;
const auto list = m_pr_technology == ptFFF ? std::initializer_list<Preset::Type>{Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT} : for (const Preset::Type& type : types_list(m_pr_technology)) {
std::initializer_list<Preset::Type>{ Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL };
for (const Preset::Type& type : list) {
if (!m_tree->options(type, true).empty()) { if (!m_tree->options(type, true).empty()) {
types_for_save.emplace_back(type); types_for_save.emplace_back(type);
presets_to_save.emplace_back(PresetToSave{ type, get_left_preset_name(type), get_right_preset_name(type), get_right_preset_name(type) }); presets_to_save.emplace_back(PresetToSave{ type, get_left_preset_name(type), get_right_preset_name(type), get_right_preset_name(type) });