2018-10-04 14:43:10 +00:00
|
|
|
#include "GUI_ObjectManipulation.hpp"
|
2018-10-05 21:29:15 +00:00
|
|
|
#include "GUI_ObjectList.hpp"
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "I18N.hpp"
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
#include "OptionsGroup.hpp"
|
|
|
|
#include "wxExtensions.hpp"
|
2018-10-05 21:29:15 +00:00
|
|
|
#include "PresetBundle.hpp"
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "libslic3r/Model.hpp"
|
|
|
|
#include "libslic3r/Geometry.hpp"
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
namespace Slic3r
|
|
|
|
{
|
|
|
|
namespace GUI
|
|
|
|
{
|
|
|
|
|
2018-11-14 15:24:36 +00:00
|
|
|
ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
2018-10-04 14:43:10 +00:00
|
|
|
OG_Settings(parent, true)
|
|
|
|
{
|
|
|
|
m_og->set_name(_(L("Object Manipulation")));
|
|
|
|
m_og->label_width = 100;
|
|
|
|
m_og->set_grid_vgap(5);
|
2018-11-14 11:33:48 +00:00
|
|
|
|
2018-12-11 12:34:37 +00:00
|
|
|
m_og->m_on_change = [this](const std::string& opt_key, const boost::any& value) {
|
2018-11-15 10:15:24 +00:00
|
|
|
std::vector<std::string> axes{ "_x", "_y", "_z" };
|
|
|
|
|
2018-11-14 15:24:36 +00:00
|
|
|
std::string param;
|
|
|
|
std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
|
|
|
|
|
2018-11-15 10:15:24 +00:00
|
|
|
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")
|
2019-01-02 12:42:29 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
{
|
|
|
|
change_scale_value(new_value);
|
|
|
|
update_settings_value(wxGetApp().plater()->canvas3D()->get_selection());
|
|
|
|
}
|
|
|
|
#else
|
2018-11-15 10:15:24 +00:00
|
|
|
change_scale_value(new_value);
|
2019-01-02 12:42:29 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-18 09:10:14 +00:00
|
|
|
else if (param == "size")
|
2019-01-02 12:42:29 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
{
|
2018-12-18 09:10:14 +00:00
|
|
|
change_size_value(new_value);
|
2019-01-02 12:42:29 +00:00
|
|
|
update_settings_value(wxGetApp().plater()->canvas3D()->get_selection());
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
change_size_value(new_value);
|
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-18 09:40:53 +00:00
|
|
|
|
|
|
|
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false);
|
2018-10-04 14:43:10 +00:00
|
|
|
};
|
|
|
|
|
2018-12-11 12:34:37 +00:00
|
|
|
m_og->m_fill_empty_value = [this](const std::string& opt_key)
|
|
|
|
{
|
2019-01-02 12:42:29 +00:00
|
|
|
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-20 19:12:26 +00:00
|
|
|
this->update_if_dirty();
|
2019-01-02 12:42:29 +00:00
|
|
|
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-20 19:12:26 +00:00
|
|
|
|
2018-12-11 12:34:37 +00:00
|
|
|
std::string param;
|
|
|
|
std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
|
2018-12-18 09:10:14 +00:00
|
|
|
|
|
|
|
double value = 0.0;
|
|
|
|
|
2018-12-11 12:34:37 +00:00
|
|
|
if (param == "position") {
|
|
|
|
int axis = opt_key.back() == 'x' ? 0 :
|
|
|
|
opt_key.back() == 'y' ? 1 : 2;
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
value = m_cache.position(axis);
|
|
|
|
#else
|
2019-01-02 12:42:29 +00:00
|
|
|
value = m_cache_position(axis);
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-11 12:34:37 +00:00
|
|
|
}
|
2018-12-18 09:10:14 +00:00
|
|
|
else if (param == "rotation") {
|
|
|
|
int axis = opt_key.back() == 'x' ? 0 :
|
|
|
|
opt_key.back() == 'y' ? 1 : 2;
|
2018-12-11 12:34:37 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
value = m_cache.rotation(axis);
|
|
|
|
#else
|
2019-01-02 12:42:29 +00:00
|
|
|
value = m_cache_rotation(axis);
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-18 09:10:14 +00:00
|
|
|
}
|
|
|
|
else if (param == "scale") {
|
|
|
|
int axis = opt_key.back() == 'x' ? 0 :
|
|
|
|
opt_key.back() == 'y' ? 1 : 2;
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
value = m_cache.scale(axis);
|
|
|
|
#else
|
2019-01-02 12:42:29 +00:00
|
|
|
value = m_cache_scale(axis);
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-18 09:10:14 +00:00
|
|
|
}
|
|
|
|
else if (param == "size") {
|
|
|
|
int axis = opt_key.back() == 'x' ? 0 :
|
|
|
|
opt_key.back() == 'y' ? 1 : 2;
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
value = m_cache.size(axis);
|
|
|
|
#else
|
2019-01-02 12:42:29 +00:00
|
|
|
value = m_cache_size(axis);
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-18 09:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_og->set_value(opt_key, double_to_string(value));
|
2018-12-18 09:40:53 +00:00
|
|
|
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false);
|
2018-12-11 12:34:37 +00:00
|
|
|
};
|
|
|
|
|
2018-12-11 12:57:50 +00:00
|
|
|
m_og->m_set_focus = [this](const std::string& opt_key)
|
|
|
|
{
|
2019-01-02 12:42:29 +00:00
|
|
|
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-20 19:12:26 +00:00
|
|
|
this->update_if_dirty();
|
2019-01-02 12:42:29 +00:00
|
|
|
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-18 09:40:53 +00:00
|
|
|
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, true);
|
2018-12-11 12:57:50 +00:00
|
|
|
};
|
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
ConfigOptionDef def;
|
|
|
|
|
|
|
|
// Objects(sub-objects) name
|
|
|
|
def.label = L("Name");
|
|
|
|
// def.type = coString;
|
|
|
|
def.gui_type = "legend";
|
|
|
|
def.tooltip = L("Object name");
|
|
|
|
def.full_width = true;
|
|
|
|
def.default_value = new ConfigOptionString{ " " };
|
|
|
|
m_og->append_single_option_line(Option(def, "object_name"));
|
|
|
|
|
|
|
|
// Legend for object modification
|
|
|
|
auto line = Line{ "", "" };
|
|
|
|
def.label = "";
|
|
|
|
def.type = coString;
|
2018-11-14 12:40:32 +00:00
|
|
|
def.width = 50;
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
std::vector<std::string> axes{ "x", "y", "z" };
|
|
|
|
for (const auto axis : axes) {
|
|
|
|
const auto label = boost::algorithm::to_upper_copy(axis);
|
|
|
|
def.default_value = new ConfigOptionString{ " " + label };
|
|
|
|
Option option = Option(def, axis + "_axis_legend");
|
|
|
|
line.append_option(option);
|
|
|
|
}
|
|
|
|
m_og->append_line(line);
|
|
|
|
|
|
|
|
|
|
|
|
auto add_og_to_object_settings = [](const std::string& option_name, const std::string& sidetext)
|
|
|
|
{
|
|
|
|
Line line = { _(option_name), "" };
|
|
|
|
ConfigOptionDef def;
|
2018-11-14 11:33:48 +00:00
|
|
|
def.type = coFloat;
|
|
|
|
def.default_value = new ConfigOptionFloat(0.0);
|
2018-11-14 12:40:32 +00:00
|
|
|
def.width = 50;
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
if (option_name == "Rotation")
|
2018-12-18 09:10:14 +00:00
|
|
|
{
|
2018-10-04 14:43:10 +00:00
|
|
|
def.min = -360;
|
2018-12-18 09:10:14 +00:00
|
|
|
def.max = 360;
|
|
|
|
}
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
const std::string lower_name = boost::algorithm::to_lower_copy(option_name);
|
|
|
|
|
|
|
|
std::vector<std::string> axes{ "x", "y", "z" };
|
|
|
|
for (auto axis : axes) {
|
2018-12-18 09:10:14 +00:00
|
|
|
if (axis == "z")
|
2018-10-04 14:43:10 +00:00
|
|
|
def.sidetext = sidetext;
|
|
|
|
Option option = Option(def, lower_name + "_" + axis);
|
|
|
|
option.opt.full_width = true;
|
|
|
|
line.append_option(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Settings table
|
2018-11-22 14:12:09 +00:00
|
|
|
m_og->append_line(add_og_to_object_settings(L("Position"), L("mm")), &m_move_Label);
|
2018-12-18 10:11:06 +00:00
|
|
|
m_og->append_line(add_og_to_object_settings(L("Rotation"), "°"), &m_rotate_Label);
|
|
|
|
m_og->append_line(add_og_to_object_settings(L("Scale"), "%"), &m_scale_Label);
|
2018-12-18 09:10:14 +00:00
|
|
|
m_og->append_line(add_og_to_object_settings(L("Size"), "mm"));
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-11-15 10:15:24 +00:00
|
|
|
/* Unused parameter at this time
|
2018-10-04 14:43:10 +00:00
|
|
|
def.label = L("Place on bed");
|
|
|
|
def.type = coBool;
|
|
|
|
def.tooltip = L("Automatic placing of models on printing bed in Y axis");
|
|
|
|
def.gui_type = "";
|
|
|
|
def.sidetext = "";
|
|
|
|
def.default_value = new ConfigOptionBool{ false };
|
|
|
|
m_og->append_single_option_line(Option(def, "place_on_bed"));
|
2018-11-15 10:15:24 +00:00
|
|
|
*/
|
2018-11-09 17:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectManipulation::Show(const bool show)
|
|
|
|
{
|
|
|
|
if (show == IsShown())
|
|
|
|
return;
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-11-09 17:39:07 +00:00
|
|
|
m_og->Show(show);
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-11-09 17:39:07 +00:00
|
|
|
if (show && wxGetApp().get_view_mode() != ConfigMenuModeSimple) {
|
|
|
|
m_og->get_grid_sizer()->Show(size_t(0), false);
|
|
|
|
m_og->get_grid_sizer()->Show(size_t(1), false);
|
|
|
|
}
|
2018-10-04 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 17:39:07 +00:00
|
|
|
bool ObjectManipulation::IsShown()
|
2018-10-04 14:43:10 +00:00
|
|
|
{
|
2018-11-09 17:39:07 +00:00
|
|
|
return m_og->get_grid_sizer()->IsShown(2);
|
2018-10-04 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 17:39:07 +00:00
|
|
|
void ObjectManipulation::UpdateAndShow(const bool show)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-12-20 19:12:26 +00:00
|
|
|
if (show) {
|
2018-11-23 11:47:32 +00:00
|
|
|
update_settings_value(wxGetApp().plater()->canvas3D()->get_selection());
|
2019-01-02 12:42:29 +00:00
|
|
|
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-20 19:12:26 +00:00
|
|
|
update_if_dirty();
|
2019-01-02 12:42:29 +00:00
|
|
|
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-20 19:12:26 +00:00
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-11-09 17:39:07 +00:00
|
|
|
OG_Settings::UpdateAndShow(show);
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-10-08 12:02:12 +00:00
|
|
|
void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& selection)
|
|
|
|
{
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_move_label_string = L("Position:");
|
|
|
|
m_new_rotate_label_string = L("Rotation:");
|
|
|
|
m_new_scale_label_string = L("Scale factors:");
|
2018-12-18 10:11:06 +00:00
|
|
|
if (selection.is_single_full_instance())
|
2018-10-08 12:02:12 +00:00
|
|
|
{
|
2019-01-02 09:18:02 +00:00
|
|
|
// all volumes in the selection belongs to the same instance, any of them contains the needed instance data, so we take the first one
|
2018-10-09 13:56:34 +00:00
|
|
|
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_position = volume->get_instance_offset();
|
|
|
|
m_new_rotation = volume->get_instance_rotation();
|
|
|
|
m_new_scale = volume->get_instance_scaling_factor();
|
2019-01-02 09:18:02 +00:00
|
|
|
int obj_idx = volume->object_idx();
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
int instance_idx = volume->instance_idx();
|
|
|
|
if ((0 <= obj_idx) && (obj_idx < (int)wxGetApp().model_objects()->size()))
|
|
|
|
{
|
|
|
|
bool changed_box = false;
|
2019-01-08 08:51:58 +00:00
|
|
|
if (!m_cache.instance.matches_object(obj_idx))
|
2019-01-07 09:53:48 +00:00
|
|
|
{
|
2019-01-08 08:51:58 +00:00
|
|
|
m_cache.instance.set(obj_idx, instance_idx, (*wxGetApp().model_objects())[obj_idx]->raw_mesh().bounding_box().size());
|
2019-01-07 09:53:48 +00:00
|
|
|
changed_box = true;
|
|
|
|
}
|
2019-01-08 08:51:58 +00:00
|
|
|
if (changed_box || !m_cache.instance.matches_instance(instance_idx) || !m_cache.scale.isApprox(100.0 * m_new_scale))
|
|
|
|
m_new_size = volume->get_instance_transformation().get_matrix(true, true) * m_cache.instance.box_size;
|
2019-01-07 09:53:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
// this should never happen
|
|
|
|
m_new_size = Vec3d::Zero();
|
|
|
|
#else
|
2019-01-02 09:18:02 +00:00
|
|
|
if ((0 <= obj_idx) && (obj_idx < (int)wxGetApp().model_objects()->size()))
|
|
|
|
m_new_size = volume->get_instance_transformation().get_matrix(true, true) * (*wxGetApp().model_objects())[obj_idx]->raw_mesh().bounding_box().size();
|
|
|
|
else
|
|
|
|
// this should never happen
|
|
|
|
m_new_size = Vec3d::Zero();
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-02 09:49:13 +00:00
|
|
|
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_enabled = true;
|
2018-10-08 12:02:12 +00:00
|
|
|
}
|
2018-12-18 10:11:06 +00:00
|
|
|
else if (selection.is_single_full_object())
|
2018-10-08 12:02:12 +00:00
|
|
|
{
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-08 08:51:58 +00:00
|
|
|
m_cache.instance.reset();
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
|
2018-12-18 10:11:06 +00:00
|
|
|
const BoundingBoxf3& box = selection.get_bounding_box();
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_position = box.center();
|
|
|
|
m_new_rotation = Vec3d::Zero();
|
|
|
|
m_new_scale = Vec3d(1.0, 1.0, 1.0);
|
|
|
|
m_new_size = box.size();
|
|
|
|
m_new_rotate_label_string = L("Rotate:");
|
|
|
|
m_new_scale_label_string = L("Scale:");
|
|
|
|
m_new_enabled = true;
|
2018-10-08 12:02:12 +00:00
|
|
|
}
|
2018-11-21 08:45:43 +00:00
|
|
|
else if (selection.is_single_modifier() || selection.is_single_volume())
|
2018-10-08 12:02:12 +00:00
|
|
|
{
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-08 08:51:58 +00:00
|
|
|
m_cache.instance.reset();
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
|
2018-10-08 12:02:12 +00:00
|
|
|
// the selection contains a single volume
|
2018-10-09 13:56:34 +00:00
|
|
|
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_position = volume->get_volume_offset();
|
|
|
|
m_new_rotation = volume->get_volume_rotation();
|
|
|
|
m_new_scale = volume->get_volume_scaling_factor();
|
2019-01-02 09:18:02 +00:00
|
|
|
m_new_size = volume->get_instance_transformation().get_matrix(true, true) * volume->get_volume_transformation().get_matrix(true, true) * volume->bounding_box.size();
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_enabled = true;
|
2018-10-08 12:02:12 +00:00
|
|
|
}
|
2018-11-22 14:12:09 +00:00
|
|
|
else if (wxGetApp().obj_list()->multiple_selection())
|
|
|
|
{
|
|
|
|
reset_settings_value();
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_move_label_string = L("Translate:");
|
|
|
|
m_new_rotate_label_string = L("Rotate:");
|
|
|
|
m_new_scale_label_string = L("Scale:");
|
|
|
|
m_new_size = selection.get_bounding_box().size();
|
|
|
|
m_new_enabled = true;
|
2018-11-22 14:12:09 +00:00
|
|
|
}
|
2018-10-08 12:02:12 +00:00
|
|
|
else
|
|
|
|
reset_settings_value();
|
2018-11-15 10:15:24 +00:00
|
|
|
|
2019-01-02 12:42:29 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
update_if_dirty();
|
|
|
|
#else
|
2018-12-20 19:12:26 +00:00
|
|
|
m_dirty = true;
|
2019-01-02 12:42:29 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-10-08 12:02:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 19:12:26 +00:00
|
|
|
void ObjectManipulation::update_if_dirty()
|
2018-10-09 13:56:34 +00:00
|
|
|
{
|
2019-01-02 12:42:29 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.move_label_string != _(m_new_move_label_string))
|
|
|
|
{
|
|
|
|
m_cache.move_label_string = _(m_new_move_label_string);
|
|
|
|
m_move_Label->SetLabel(m_cache.move_label_string);
|
|
|
|
}
|
2019-01-02 12:42:29 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.rotate_label_string != _(m_new_rotate_label_string))
|
|
|
|
{
|
|
|
|
m_cache.rotate_label_string = _(m_new_rotate_label_string);
|
|
|
|
m_rotate_Label->SetLabel(m_cache.rotate_label_string);
|
|
|
|
}
|
2019-01-02 12:42:29 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.scale_label_string != _(m_new_scale_label_string))
|
|
|
|
{
|
|
|
|
m_cache.scale_label_string = _(m_new_scale_label_string);
|
|
|
|
m_scale_Label->SetLabel(m_cache.scale_label_string);
|
|
|
|
}
|
2019-01-02 12:42:29 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.position(0) != m_new_position(0))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("position_x", double_to_string(m_new_position(0), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.position(1) != m_new_position(1))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("position_y", double_to_string(m_new_position(1), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.position(2) != m_new_position(2))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("position_z", double_to_string(m_new_position(2), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.position = m_new_position;
|
2019-01-02 12:42:29 +00:00
|
|
|
|
|
|
|
auto scale = m_new_scale * 100.0;
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.scale(0) != scale(0))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("scale_x", double_to_string(scale(0), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.scale(1) != scale(1))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("scale_y", double_to_string(scale(1), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.scale(2) != scale(2))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("scale_z", double_to_string(scale(2), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.scale = scale;
|
2019-01-02 12:42:29 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.size(0) != m_new_size(0))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("size_x", double_to_string(m_new_size(0), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.size(1) != m_new_size(1))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("size_y", double_to_string(m_new_size(1), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.size(2) != m_new_size(2))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("size_z", double_to_string(m_new_size(2), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.size = m_new_size;
|
2019-01-02 12:42:29 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.rotation(0) != m_new_rotation(0))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("rotation_x", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(0)), 0), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.rotation(1) != m_new_rotation(1))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("rotation_y", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(1)), 0), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
if (m_cache.rotation(2) != m_new_rotation(2))
|
2019-01-02 12:42:29 +00:00
|
|
|
m_og->set_value("rotation_z", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(2)), 0), 2));
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.rotation = m_new_rotation;
|
2019-01-02 12:42:29 +00:00
|
|
|
|
|
|
|
if (m_new_enabled)
|
|
|
|
m_og->enable();
|
|
|
|
else
|
|
|
|
m_og->disable();
|
|
|
|
#else
|
2018-12-20 19:12:26 +00:00
|
|
|
if (! m_dirty)
|
|
|
|
return;
|
2018-12-18 09:10:14 +00:00
|
|
|
|
2018-12-20 19:12:26 +00:00
|
|
|
m_move_Label->SetLabel(_(m_new_move_label_string));
|
|
|
|
m_rotate_Label->SetLabel(_(m_new_rotate_label_string));
|
|
|
|
m_scale_Label->SetLabel(_(m_new_scale_label_string));
|
2018-10-08 12:02:12 +00:00
|
|
|
|
2018-12-20 19:12:26 +00:00
|
|
|
m_og->set_value("position_x", double_to_string(m_new_position(0), 2));
|
|
|
|
m_og->set_value("position_y", double_to_string(m_new_position(1), 2));
|
|
|
|
m_og->set_value("position_z", double_to_string(m_new_position(2), 2));
|
2019-01-02 12:42:29 +00:00
|
|
|
m_cache_position = m_new_position;
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-12-20 19:12:26 +00:00
|
|
|
auto scale = m_new_scale * 100.0;
|
2018-11-14 11:33:48 +00:00
|
|
|
m_og->set_value("scale_x", double_to_string(scale(0), 2));
|
|
|
|
m_og->set_value("scale_y", double_to_string(scale(1), 2));
|
|
|
|
m_og->set_value("scale_z", double_to_string(scale(2), 2));
|
2019-01-02 12:42:29 +00:00
|
|
|
m_cache_scale = scale;
|
2018-12-18 09:10:14 +00:00
|
|
|
|
2018-12-20 19:12:26 +00:00
|
|
|
m_og->set_value("size_x", double_to_string(m_new_size(0), 2));
|
|
|
|
m_og->set_value("size_y", double_to_string(m_new_size(1), 2));
|
|
|
|
m_og->set_value("size_z", double_to_string(m_new_size(2), 2));
|
2019-01-02 12:42:29 +00:00
|
|
|
m_cache_size = m_new_size;
|
2018-12-20 19:12:26 +00:00
|
|
|
|
|
|
|
m_og->set_value("rotation_x", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(0)), 0), 2));
|
|
|
|
m_og->set_value("rotation_y", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(1)), 0), 2));
|
|
|
|
m_og->set_value("rotation_z", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(2)), 0), 2));
|
2019-01-02 12:42:29 +00:00
|
|
|
m_cache_rotation = m_new_rotation;
|
2018-12-18 09:10:14 +00:00
|
|
|
|
2018-12-20 19:12:26 +00:00
|
|
|
if (m_new_enabled)
|
|
|
|
m_og->enable();
|
|
|
|
else
|
|
|
|
m_og->disable();
|
|
|
|
|
|
|
|
m_dirty = false;
|
2019-01-02 12:42:29 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-10-04 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 19:12:26 +00:00
|
|
|
void ObjectManipulation::reset_settings_value()
|
2018-10-04 14:43:10 +00:00
|
|
|
{
|
2019-01-07 09:53:48 +00:00
|
|
|
m_new_position = Vec3d::Zero();
|
|
|
|
m_new_rotation = Vec3d::Zero();
|
2019-01-02 12:42:29 +00:00
|
|
|
m_new_scale = Vec3d::Ones();
|
|
|
|
m_new_size = Vec3d::Zero();
|
2019-01-07 09:53:48 +00:00
|
|
|
m_new_enabled = false;
|
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-08 08:51:58 +00:00
|
|
|
m_cache.instance.reset();
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-02 12:42:29 +00:00
|
|
|
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
m_dirty = true;
|
|
|
|
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-11-14 15:24:36 +00:00
|
|
|
void ObjectManipulation::change_position_value(const Vec3d& position)
|
|
|
|
{
|
2018-11-23 11:47:32 +00:00
|
|
|
auto canvas = wxGetApp().plater()->canvas3D();
|
2018-12-19 14:03:49 +00:00
|
|
|
GLCanvas3D::Selection& selection = canvas->get_selection();
|
|
|
|
selection.start_dragging();
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
selection.translate(position - m_cache.position, selection.requires_local_axes());
|
|
|
|
#else
|
2019-01-02 12:42:29 +00:00
|
|
|
selection.translate(position - m_cache_position, selection.requires_local_axes());
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-11-21 09:36:09 +00:00
|
|
|
canvas->do_move();
|
2018-11-14 15:24:36 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
m_cache.position = position;
|
|
|
|
#else
|
2019-01-02 12:42:29 +00:00
|
|
|
m_cache_position = position;
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-11-14 15:24:36 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 10:15:24 +00:00
|
|
|
void ObjectManipulation::change_rotation_value(const Vec3d& rotation)
|
|
|
|
{
|
2018-12-18 10:11:06 +00:00
|
|
|
GLCanvas3D* canvas = wxGetApp().plater()->canvas3D();
|
|
|
|
const GLCanvas3D::Selection& selection = canvas->get_selection();
|
|
|
|
|
2018-11-15 10:15:24 +00:00
|
|
|
Vec3d rad_rotation;
|
|
|
|
for (size_t i = 0; i < 3; ++i)
|
2018-12-18 10:11:06 +00:00
|
|
|
{
|
2018-11-15 10:15:24 +00:00
|
|
|
rad_rotation(i) = Geometry::deg2rad(rotation(i));
|
2018-12-18 10:11:06 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 10:15:24 +00:00
|
|
|
canvas->get_selection().start_dragging();
|
2018-12-18 10:11:06 +00:00
|
|
|
canvas->get_selection().rotate(rad_rotation, selection.is_single_full_instance());
|
2018-11-21 09:36:09 +00:00
|
|
|
canvas->do_rotate();
|
2019-01-03 10:24:03 +00:00
|
|
|
|
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.rotation = rotation;
|
2019-01-03 10:24:03 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-11-15 10:15:24 +00:00
|
|
|
}
|
2018-11-14 15:24:36 +00:00
|
|
|
|
2018-11-15 10:15:24 +00:00
|
|
|
void ObjectManipulation::change_scale_value(const Vec3d& scale)
|
|
|
|
{
|
2018-12-18 09:10:14 +00:00
|
|
|
Vec3d scaling_factor = scale;
|
|
|
|
const GLCanvas3D::Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
|
2018-12-18 13:08:46 +00:00
|
|
|
if (selection.requires_uniform_scale())
|
2018-12-18 09:10:14 +00:00
|
|
|
{
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
Vec3d abs_scale_diff = (scale - m_cache.scale).cwiseAbs();
|
|
|
|
#else
|
2019-01-02 12:42:29 +00:00
|
|
|
Vec3d abs_scale_diff = (scale - m_cache_scale).cwiseAbs();
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-18 10:50:22 +00:00
|
|
|
double max_diff = abs_scale_diff(X);
|
|
|
|
Axis max_diff_axis = X;
|
|
|
|
if (max_diff < abs_scale_diff(Y))
|
|
|
|
{
|
|
|
|
max_diff = abs_scale_diff(Y);
|
|
|
|
max_diff_axis = Y;
|
|
|
|
}
|
|
|
|
if (max_diff < abs_scale_diff(Z))
|
|
|
|
{
|
|
|
|
max_diff = abs_scale_diff(Z);
|
|
|
|
max_diff_axis = Z;
|
|
|
|
}
|
2019-01-04 12:59:41 +00:00
|
|
|
scaling_factor = scale(max_diff_axis) * Vec3d::Ones();
|
2018-11-15 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 09:10:14 +00:00
|
|
|
scaling_factor *= 0.01;
|
|
|
|
|
2018-11-23 11:47:32 +00:00
|
|
|
auto canvas = wxGetApp().plater()->canvas3D();
|
2018-11-15 10:15:24 +00:00
|
|
|
canvas->get_selection().start_dragging();
|
2018-11-20 14:39:36 +00:00
|
|
|
canvas->get_selection().scale(scaling_factor, false);
|
2018-11-21 09:36:09 +00:00
|
|
|
canvas->do_scale();
|
2019-01-03 10:24:03 +00:00
|
|
|
|
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-08 08:51:58 +00:00
|
|
|
if (!m_cache.scale.isApprox(scale))
|
|
|
|
m_cache.instance.instance_idx = -1;
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.scale = scale;
|
2019-01-03 10:24:03 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-11-15 10:15:24 +00:00
|
|
|
}
|
2018-11-14 15:24:36 +00:00
|
|
|
|
2018-12-18 09:10:14 +00:00
|
|
|
void ObjectManipulation::change_size_value(const Vec3d& size)
|
2018-11-14 15:24:36 +00:00
|
|
|
{
|
2018-12-18 09:10:14 +00:00
|
|
|
const GLCanvas3D::Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
|
|
|
Vec3d ref_size = m_cache.size;
|
|
|
|
#else
|
2019-01-02 12:42:29 +00:00
|
|
|
Vec3d ref_size = m_cache_size;
|
2019-01-07 09:53:48 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-12-18 09:10:14 +00:00
|
|
|
if (selection.is_single_full_instance())
|
|
|
|
{
|
|
|
|
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
|
|
|
ref_size = volume->bounding_box.size();
|
|
|
|
}
|
|
|
|
|
2019-01-03 10:24:03 +00:00
|
|
|
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2019-01-04 12:59:41 +00:00
|
|
|
Vec3d scale = 100.0 * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2));
|
|
|
|
Vec3d scaling_factor = scale;
|
|
|
|
|
|
|
|
if (selection.requires_uniform_scale())
|
|
|
|
{
|
2019-01-07 09:53:48 +00:00
|
|
|
Vec3d abs_scale_diff = (scale - m_cache.scale).cwiseAbs();
|
2019-01-04 12:59:41 +00:00
|
|
|
double max_diff = abs_scale_diff(X);
|
|
|
|
Axis max_diff_axis = X;
|
|
|
|
if (max_diff < abs_scale_diff(Y))
|
|
|
|
{
|
|
|
|
max_diff = abs_scale_diff(Y);
|
|
|
|
max_diff_axis = Y;
|
|
|
|
}
|
|
|
|
if (max_diff < abs_scale_diff(Z))
|
|
|
|
{
|
|
|
|
max_diff = abs_scale_diff(Z);
|
|
|
|
max_diff_axis = Z;
|
|
|
|
}
|
|
|
|
scaling_factor = scale(max_diff_axis) * Vec3d::Ones();
|
|
|
|
}
|
|
|
|
|
|
|
|
scaling_factor *= 0.01;
|
|
|
|
|
|
|
|
auto canvas = wxGetApp().plater()->canvas3D();
|
|
|
|
canvas->get_selection().start_dragging();
|
|
|
|
canvas->get_selection().scale(scaling_factor, false);
|
|
|
|
canvas->do_scale();
|
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.size = size;
|
2019-01-04 12:59:41 +00:00
|
|
|
#else
|
|
|
|
change_scale_value(100.0 * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2)));
|
2019-01-03 10:24:03 +00:00
|
|
|
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
2018-11-14 15:24:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
} //namespace GUI
|
|
|
|
} //namespace Slic3r
|