Rotation/Scale from modification pane for SingleObject, SingleVolume & SingleInstance
Note: - doesn't work for group selection - scaling work only with percent mode
This commit is contained in:
parent
e83e755e8b
commit
ede21eec7a
3 changed files with 67 additions and 28 deletions
|
@ -23,11 +23,12 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
|||
m_og->set_process_enter(); // We need to update new values only after press ENTER
|
||||
|
||||
m_og->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
|
||||
std::vector<std::string> axes{ "_x", "_y", "_z" };
|
||||
|
||||
if (opt_key == "scale_unit") {
|
||||
const wxString& selection = boost::any_cast<wxString>(value);
|
||||
std::vector<std::string> axes{ "x", "y", "z" };
|
||||
for (auto axis : axes) {
|
||||
std::string key = "scale_" + axis;
|
||||
std::string key = "scale" + axis;
|
||||
m_og->set_side_text(key, selection);
|
||||
}
|
||||
|
||||
|
@ -39,13 +40,17 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
|||
std::string param;
|
||||
std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
|
||||
|
||||
if (param == "position") {
|
||||
Vec3d displacement;
|
||||
displacement(0) = boost::any_cast<double>(m_og->get_value("position_x"));
|
||||
displacement(1) = boost::any_cast<double>(m_og->get_value("position_y"));
|
||||
displacement(2) = boost::any_cast<double>(m_og->get_value("position_z"));
|
||||
change_position_value(displacement);
|
||||
}
|
||||
size_t i = 0;
|
||||
Vec3d new_value;
|
||||
for (auto axis : axes)
|
||||
new_value(i++) = boost::any_cast<double>(m_og->get_value(param+axis));
|
||||
|
||||
if (param == "position")
|
||||
change_position_value(new_value);
|
||||
else if (param == "rotation")
|
||||
change_rotation_value(new_value);
|
||||
else if (param == "scale")
|
||||
change_scale_value(new_value);
|
||||
};
|
||||
|
||||
ConfigOptionDef def;
|
||||
|
@ -132,7 +137,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
|||
m_og->append_line(add_og_to_object_settings(L("Rotation"), "°"));
|
||||
m_og->append_line(add_og_to_object_settings(L("Scale"), "mm"));
|
||||
|
||||
|
||||
/* Unused parameter at this time
|
||||
def.label = L("Place on bed");
|
||||
def.type = coBool;
|
||||
def.tooltip = L("Automatic placing of models on printing bed in Y axis");
|
||||
|
@ -140,6 +145,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
|||
def.sidetext = "";
|
||||
def.default_value = new ConfigOptionBool{ false };
|
||||
m_og->append_single_option_line(Option(def, "place_on_bed"));
|
||||
*/
|
||||
}
|
||||
|
||||
void ObjectManipulation::Show(const bool show)
|
||||
|
@ -241,6 +247,8 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
|
|||
}
|
||||
else
|
||||
reset_settings_value();
|
||||
|
||||
m_og->get_field("scale_unit")->disable();// temporary decision
|
||||
}
|
||||
|
||||
void ObjectManipulation::reset_settings_value()
|
||||
|
@ -317,9 +325,9 @@ void ObjectManipulation::update_scale_values()
|
|||
m_og->set_value("scale_z", double_to_string(instance->get_scaling_factor(Z) * 100, 2));
|
||||
}
|
||||
else {
|
||||
m_og->set_value("scale_x", double_to_string(instance->get_scaling_factor(X) * size(0) + 0.5, 2));
|
||||
m_og->set_value("scale_y", double_to_string(instance->get_scaling_factor(Y) * size(1) + 0.5, 2));
|
||||
m_og->set_value("scale_z", double_to_string(instance->get_scaling_factor(Z) * size(2) + 0.5, 2));
|
||||
m_og->set_value("scale_x", double_to_string(size(0), 2));
|
||||
m_og->set_value("scale_y", double_to_string(size(1), 2));
|
||||
m_og->set_value("scale_z", double_to_string(size(2), 2));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,8 +355,10 @@ void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor)
|
|||
// to be able to update the values as size
|
||||
// we need to store somewhere the original size
|
||||
// or have it passed as parameter
|
||||
if (!m_is_percent_scale)
|
||||
if (!m_is_percent_scale) {
|
||||
m_is_percent_scale = true;
|
||||
m_og->set_value("scale_unit", _("%"));
|
||||
}
|
||||
|
||||
auto scale = scaling_factor * 100.0;
|
||||
m_og->set_value("scale_x", double_to_string(scale(0), 2));
|
||||
|
@ -399,11 +409,40 @@ void ObjectManipulation::change_position_value(const Vec3d& position)
|
|||
cache_position = position;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ObjectManipulation::print_cashe_value(const std::string& label, const Vec3d& value)
|
||||
void ObjectManipulation::change_rotation_value(const Vec3d& rotation)
|
||||
{
|
||||
std::cout << label << " => " << " X:" << value(0) << " Y:" << value(1) << " Z:" << value(2) << std::endl;
|
||||
Vec3d rad_rotation;
|
||||
for (size_t i = 0; i < 3; ++i)
|
||||
rad_rotation(i) = Geometry::deg2rad(rotation(i));
|
||||
auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D());
|
||||
canvas->get_selection().start_dragging();
|
||||
canvas->get_selection().rotate(rad_rotation);
|
||||
canvas->_on_rotate();
|
||||
}
|
||||
|
||||
void ObjectManipulation::change_scale_value(const Vec3d& scale)
|
||||
{
|
||||
Vec3d scaling_factor;
|
||||
if (m_is_percent_scale)
|
||||
scaling_factor = scale*0.01;
|
||||
else {
|
||||
int selection = ol_selection();
|
||||
ModelObjectPtrs& objects = *wxGetApp().model_objects();
|
||||
|
||||
auto size = objects[selection]->instance_bounding_box(0).size();
|
||||
for (size_t i = 0; i < 3; ++i)
|
||||
scaling_factor(i) = scale(i) / size(i);
|
||||
}
|
||||
|
||||
auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D());
|
||||
canvas->get_selection().start_dragging();
|
||||
canvas->get_selection().scale(scaling_factor);
|
||||
canvas->_on_scale();
|
||||
}
|
||||
|
||||
void ObjectManipulation::print_cashe_value(const std::string& label, const Vec3d& v)
|
||||
{
|
||||
std::cout << label << " => " << " X:" << v(0) << " Y:" << v(1) << " Z:" << v(2) << std::endl;
|
||||
}
|
||||
|
||||
} //namespace GUI
|
||||
|
|
|
@ -18,8 +18,6 @@ class ObjectManipulation : public OG_Settings
|
|||
bool m_is_uniform_scale = false; // It indicates if scale is uniform
|
||||
|
||||
Vec3d cache_position { 0., 0., 0. };
|
||||
Vec3d cache_rotation { 0., 0., 0. };
|
||||
Vec3d cache_scale { 0., 0., 0. };
|
||||
|
||||
public:
|
||||
ObjectManipulation(wxWindow* parent);
|
||||
|
@ -55,6 +53,8 @@ public:
|
|||
|
||||
// change values
|
||||
void change_position_value(const Vec3d& position);
|
||||
void change_rotation_value(const Vec3d& rotation);
|
||||
void change_scale_value(const Vec3d& scale);
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
@ -449,8 +449,7 @@ void Sidebar::priv::show_preset_comboboxes()
|
|||
{
|
||||
const bool showSLA = plater->printer_technology() == ptSLA;
|
||||
|
||||
wxWindowUpdateLocker noUpdates_scrolled(scrolled);
|
||||
// scrolled->Freeze();
|
||||
wxWindowUpdateLocker noUpdates_scrolled(scrolled->GetParent());
|
||||
|
||||
for (size_t i = 0; i < 4; ++i) {
|
||||
if (sizer_presets->IsShown(i) == showSLA)
|
||||
|
@ -465,8 +464,8 @@ void Sidebar::priv::show_preset_comboboxes()
|
|||
if (frequently_changed_parameters->IsShown() == showSLA)
|
||||
frequently_changed_parameters->Show(!showSLA);
|
||||
|
||||
scrolled->Layout();
|
||||
// scrolled->Thaw();
|
||||
scrolled->GetParent()->Layout();
|
||||
scrolled->Refresh();
|
||||
}
|
||||
|
||||
|
||||
|
@ -710,7 +709,7 @@ void Sidebar::show_info_sizer()
|
|||
|
||||
const ModelInstance* model_instance = !model_object->instances.empty() ? model_object->instances.front() : nullptr;
|
||||
|
||||
auto size = model_object->instance_bounding_box(0).size();
|
||||
auto size = model_object->bounding_box().size();
|
||||
p->object_info->info_size->SetLabel(wxString::Format("%.2f x %.2f x %.2f",size(0), size(1), size(2)));
|
||||
p->object_info->info_materials->SetLabel(wxString::Format("%d", static_cast<int>(model_object->materials_count())));
|
||||
|
||||
|
@ -776,6 +775,7 @@ void Sidebar::show_sliced_info_sizer(const bool show)
|
|||
}
|
||||
|
||||
Layout();
|
||||
p->scrolled->Refresh();
|
||||
}
|
||||
|
||||
void Sidebar::show_buttons(const bool show)
|
||||
|
@ -2370,7 +2370,7 @@ void Plater::on_extruders_change(int num_extruders)
|
|||
{
|
||||
auto& choices = sidebar().combos_filament();
|
||||
|
||||
wxWindowUpdateLocker noUpdates_scrolled_panel(sidebar().scrolled_panel());
|
||||
wxWindowUpdateLocker noUpdates_scrolled_panel(&sidebar()/*.scrolled_panel()*/);
|
||||
// sidebar().scrolled_panel()->Freeze();
|
||||
|
||||
int i = choices.size();
|
||||
|
@ -2388,8 +2388,8 @@ void Plater::on_extruders_change(int num_extruders)
|
|||
// remove unused choices if any
|
||||
sidebar().remove_unused_filament_combos(num_extruders);
|
||||
|
||||
sidebar().scrolled_panel()->Layout();
|
||||
// sidebar().scrolled_panel()->Thaw();
|
||||
sidebar().Layout();
|
||||
sidebar().scrolled_panel()->Refresh();
|
||||
}
|
||||
|
||||
void Plater::on_config_change(const DynamicPrintConfig &config)
|
||||
|
|
Loading…
Reference in a new issue