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->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) {
|
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") {
|
if (opt_key == "scale_unit") {
|
||||||
const wxString& selection = boost::any_cast<wxString>(value);
|
const wxString& selection = boost::any_cast<wxString>(value);
|
||||||
std::vector<std::string> axes{ "x", "y", "z" };
|
|
||||||
for (auto axis : axes) {
|
for (auto axis : axes) {
|
||||||
std::string key = "scale_" + axis;
|
std::string key = "scale" + axis;
|
||||||
m_og->set_side_text(key, selection);
|
m_og->set_side_text(key, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,13 +40,17 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
||||||
std::string param;
|
std::string param;
|
||||||
std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
|
std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
|
||||||
|
|
||||||
if (param == "position") {
|
size_t i = 0;
|
||||||
Vec3d displacement;
|
Vec3d new_value;
|
||||||
displacement(0) = boost::any_cast<double>(m_og->get_value("position_x"));
|
for (auto axis : axes)
|
||||||
displacement(1) = boost::any_cast<double>(m_og->get_value("position_y"));
|
new_value(i++) = boost::any_cast<double>(m_og->get_value(param+axis));
|
||||||
displacement(2) = boost::any_cast<double>(m_og->get_value("position_z"));
|
|
||||||
change_position_value(displacement);
|
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;
|
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("Rotation"), "°"));
|
||||||
m_og->append_line(add_og_to_object_settings(L("Scale"), "mm"));
|
m_og->append_line(add_og_to_object_settings(L("Scale"), "mm"));
|
||||||
|
|
||||||
|
/* Unused parameter at this time
|
||||||
def.label = L("Place on bed");
|
def.label = L("Place on bed");
|
||||||
def.type = coBool;
|
def.type = coBool;
|
||||||
def.tooltip = L("Automatic placing of models on printing bed in Y axis");
|
def.tooltip = L("Automatic placing of models on printing bed in Y axis");
|
||||||
|
@ -140,6 +145,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
||||||
def.sidetext = "";
|
def.sidetext = "";
|
||||||
def.default_value = new ConfigOptionBool{ false };
|
def.default_value = new ConfigOptionBool{ false };
|
||||||
m_og->append_single_option_line(Option(def, "place_on_bed"));
|
m_og->append_single_option_line(Option(def, "place_on_bed"));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectManipulation::Show(const bool show)
|
void ObjectManipulation::Show(const bool show)
|
||||||
|
@ -241,6 +247,8 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
reset_settings_value();
|
reset_settings_value();
|
||||||
|
|
||||||
|
m_og->get_field("scale_unit")->disable();// temporary decision
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectManipulation::reset_settings_value()
|
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));
|
m_og->set_value("scale_z", double_to_string(instance->get_scaling_factor(Z) * 100, 2));
|
||||||
}
|
}
|
||||||
else {
|
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_x", double_to_string(size(0), 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_y", double_to_string(size(1), 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_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
|
// to be able to update the values as size
|
||||||
// we need to store somewhere the original size
|
// we need to store somewhere the original size
|
||||||
// or have it passed as parameter
|
// 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", _("%"));
|
m_og->set_value("scale_unit", _("%"));
|
||||||
|
}
|
||||||
|
|
||||||
auto scale = scaling_factor * 100.0;
|
auto scale = scaling_factor * 100.0;
|
||||||
m_og->set_value("scale_x", double_to_string(scale(0), 2));
|
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;
|
cache_position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectManipulation::change_rotation_value(const Vec3d& rotation)
|
||||||
|
|
||||||
void ObjectManipulation::print_cashe_value(const std::string& label, const Vec3d& value)
|
|
||||||
{
|
{
|
||||||
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
|
} //namespace GUI
|
||||||
|
|
|
@ -18,8 +18,6 @@ class ObjectManipulation : public OG_Settings
|
||||||
bool m_is_uniform_scale = false; // It indicates if scale is uniform
|
bool m_is_uniform_scale = false; // It indicates if scale is uniform
|
||||||
|
|
||||||
Vec3d cache_position { 0., 0., 0. };
|
Vec3d cache_position { 0., 0., 0. };
|
||||||
Vec3d cache_rotation { 0., 0., 0. };
|
|
||||||
Vec3d cache_scale { 0., 0., 0. };
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectManipulation(wxWindow* parent);
|
ObjectManipulation(wxWindow* parent);
|
||||||
|
@ -55,6 +53,8 @@ public:
|
||||||
|
|
||||||
// change values
|
// change values
|
||||||
void change_position_value(const Vec3d& position);
|
void change_position_value(const Vec3d& position);
|
||||||
|
void change_rotation_value(const Vec3d& rotation);
|
||||||
|
void change_scale_value(const Vec3d& scale);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -449,8 +449,7 @@ void Sidebar::priv::show_preset_comboboxes()
|
||||||
{
|
{
|
||||||
const bool showSLA = plater->printer_technology() == ptSLA;
|
const bool showSLA = plater->printer_technology() == ptSLA;
|
||||||
|
|
||||||
wxWindowUpdateLocker noUpdates_scrolled(scrolled);
|
wxWindowUpdateLocker noUpdates_scrolled(scrolled->GetParent());
|
||||||
// scrolled->Freeze();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < 4; ++i) {
|
for (size_t i = 0; i < 4; ++i) {
|
||||||
if (sizer_presets->IsShown(i) == showSLA)
|
if (sizer_presets->IsShown(i) == showSLA)
|
||||||
|
@ -465,8 +464,8 @@ void Sidebar::priv::show_preset_comboboxes()
|
||||||
if (frequently_changed_parameters->IsShown() == showSLA)
|
if (frequently_changed_parameters->IsShown() == showSLA)
|
||||||
frequently_changed_parameters->Show(!showSLA);
|
frequently_changed_parameters->Show(!showSLA);
|
||||||
|
|
||||||
scrolled->Layout();
|
scrolled->GetParent()->Layout();
|
||||||
// scrolled->Thaw();
|
scrolled->Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -710,7 +709,7 @@ void Sidebar::show_info_sizer()
|
||||||
|
|
||||||
const ModelInstance* model_instance = !model_object->instances.empty() ? model_object->instances.front() : nullptr;
|
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_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())));
|
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();
|
Layout();
|
||||||
|
p->scrolled->Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sidebar::show_buttons(const bool show)
|
void Sidebar::show_buttons(const bool show)
|
||||||
|
@ -2370,7 +2370,7 @@ void Plater::on_extruders_change(int num_extruders)
|
||||||
{
|
{
|
||||||
auto& choices = sidebar().combos_filament();
|
auto& choices = sidebar().combos_filament();
|
||||||
|
|
||||||
wxWindowUpdateLocker noUpdates_scrolled_panel(sidebar().scrolled_panel());
|
wxWindowUpdateLocker noUpdates_scrolled_panel(&sidebar()/*.scrolled_panel()*/);
|
||||||
// sidebar().scrolled_panel()->Freeze();
|
// sidebar().scrolled_panel()->Freeze();
|
||||||
|
|
||||||
int i = choices.size();
|
int i = choices.size();
|
||||||
|
@ -2388,8 +2388,8 @@ void Plater::on_extruders_change(int num_extruders)
|
||||||
// remove unused choices if any
|
// remove unused choices if any
|
||||||
sidebar().remove_unused_filament_combos(num_extruders);
|
sidebar().remove_unused_filament_combos(num_extruders);
|
||||||
|
|
||||||
sidebar().scrolled_panel()->Layout();
|
sidebar().Layout();
|
||||||
// sidebar().scrolled_panel()->Thaw();
|
sidebar().scrolled_panel()->Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plater::on_config_change(const DynamicPrintConfig &config)
|
void Plater::on_config_change(const DynamicPrintConfig &config)
|
||||||
|
|
Loading…
Reference in a new issue