Improved objects manipulation using sidebar
This commit is contained in:
parent
f8b83d20d3
commit
0ccd19f1ee
4 changed files with 130 additions and 19 deletions
|
@ -43,6 +43,13 @@
|
|||
// Separate rendering for opaque and transparent volumes
|
||||
#define ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING (1 && ENABLE_1_42_0)
|
||||
|
||||
//====================
|
||||
// 1.42.0.alpha1 techs
|
||||
//====================
|
||||
#define ENABLE_1_42_0_ALPHA1 1
|
||||
|
||||
#define ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION (1 && ENABLE_1_42_0_ALPHA1)
|
||||
|
||||
#endif // _technologies_h_
|
||||
|
||||
|
||||
|
|
|
@ -184,8 +184,10 @@ bool GUI_App::OnInit()
|
|||
if (app_config->dirty())
|
||||
app_config->save();
|
||||
|
||||
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
if (this->plater() != nullptr)
|
||||
this->obj_manipul()->update_if_dirty();
|
||||
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
});
|
||||
|
||||
// On OS X the UI tends to freeze in weird ways if modal dialogs(config wizard, update notifications, ...)
|
||||
|
|
|
@ -17,6 +17,12 @@ namespace GUI
|
|||
|
||||
ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
||||
OG_Settings(parent, true)
|
||||
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
, m_cache_position(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX))
|
||||
, m_cache_rotation(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX))
|
||||
, m_cache_scale(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX))
|
||||
, m_cache_size(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX))
|
||||
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
{
|
||||
m_og->set_name(_(L("Object Manipulation")));
|
||||
m_og->label_width = 100;
|
||||
|
@ -38,16 +44,32 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
|||
else if (param == "rotation")
|
||||
change_rotation_value(new_value);
|
||||
else if (param == "scale")
|
||||
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
{
|
||||
change_scale_value(new_value);
|
||||
update_settings_value(wxGetApp().plater()->canvas3D()->get_selection());
|
||||
}
|
||||
#else
|
||||
change_scale_value(new_value);
|
||||
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
else if (param == "size")
|
||||
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
{
|
||||
change_size_value(new_value);
|
||||
update_settings_value(wxGetApp().plater()->canvas3D()->get_selection());
|
||||
}
|
||||
#else
|
||||
change_size_value(new_value);
|
||||
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
|
||||
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false);
|
||||
};
|
||||
|
||||
m_og->m_fill_empty_value = [this](const std::string& opt_key)
|
||||
{
|
||||
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
this->update_if_dirty();
|
||||
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
|
||||
std::string param;
|
||||
std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
|
||||
|
@ -58,25 +80,25 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
|||
int axis = opt_key.back() == 'x' ? 0 :
|
||||
opt_key.back() == 'y' ? 1 : 2;
|
||||
|
||||
value = cache_position(axis);
|
||||
value = m_cache_position(axis);
|
||||
}
|
||||
else if (param == "rotation") {
|
||||
int axis = opt_key.back() == 'x' ? 0 :
|
||||
opt_key.back() == 'y' ? 1 : 2;
|
||||
|
||||
value = cache_rotation(axis);
|
||||
value = m_cache_rotation(axis);
|
||||
}
|
||||
else if (param == "scale") {
|
||||
int axis = opt_key.back() == 'x' ? 0 :
|
||||
opt_key.back() == 'y' ? 1 : 2;
|
||||
|
||||
value = cache_scale(axis);
|
||||
value = m_cache_scale(axis);
|
||||
}
|
||||
else if (param == "size") {
|
||||
int axis = opt_key.back() == 'x' ? 0 :
|
||||
opt_key.back() == 'y' ? 1 : 2;
|
||||
|
||||
value = cache_size(axis);
|
||||
value = m_cache_size(axis);
|
||||
}
|
||||
|
||||
m_og->set_value(opt_key, double_to_string(value));
|
||||
|
@ -85,7 +107,9 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
|||
|
||||
m_og->m_set_focus = [this](const std::string& opt_key)
|
||||
{
|
||||
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
this->update_if_dirty();
|
||||
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, true);
|
||||
};
|
||||
|
||||
|
@ -184,7 +208,9 @@ void ObjectManipulation::UpdateAndShow(const bool show)
|
|||
{
|
||||
if (show) {
|
||||
update_settings_value(wxGetApp().plater()->canvas3D()->get_selection());
|
||||
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
update_if_dirty();
|
||||
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
}
|
||||
|
||||
OG_Settings::UpdateAndShow(show);
|
||||
|
@ -244,11 +270,75 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
|
|||
else
|
||||
reset_settings_value();
|
||||
|
||||
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
update_if_dirty();
|
||||
#else
|
||||
m_dirty = true;
|
||||
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
}
|
||||
|
||||
void ObjectManipulation::update_if_dirty()
|
||||
{
|
||||
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
if (_(m_new_move_label_string) != m_move_Label->GetLabel())
|
||||
m_move_Label->SetLabel(_(m_new_move_label_string));
|
||||
|
||||
if (_(m_new_rotate_label_string) != m_rotate_Label->GetLabel())
|
||||
m_rotate_Label->SetLabel(_(m_new_rotate_label_string));
|
||||
|
||||
if (_(m_new_scale_label_string) != m_scale_Label->GetLabel())
|
||||
m_scale_Label->SetLabel(_(m_new_scale_label_string));
|
||||
|
||||
if (m_cache_position(0) != m_new_position(0))
|
||||
m_og->set_value("position_x", double_to_string(m_new_position(0), 2));
|
||||
|
||||
if (m_cache_position(1) != m_new_position(1))
|
||||
m_og->set_value("position_y", double_to_string(m_new_position(1), 2));
|
||||
|
||||
if (m_cache_position(2) != m_new_position(2))
|
||||
m_og->set_value("position_z", double_to_string(m_new_position(2), 2));
|
||||
|
||||
m_cache_position = m_new_position;
|
||||
|
||||
auto scale = m_new_scale * 100.0;
|
||||
if (m_cache_scale(0) != scale(0))
|
||||
m_og->set_value("scale_x", double_to_string(scale(0), 2));
|
||||
|
||||
if (m_cache_scale(1) != scale(1))
|
||||
m_og->set_value("scale_y", double_to_string(scale(1), 2));
|
||||
|
||||
if (m_cache_scale(2) != scale(2))
|
||||
m_og->set_value("scale_z", double_to_string(scale(2), 2));
|
||||
|
||||
m_cache_scale = scale;
|
||||
|
||||
if (m_cache_size(0) != m_new_size(0))
|
||||
m_og->set_value("size_x", double_to_string(m_new_size(0), 2));
|
||||
|
||||
if (m_cache_size(1) != m_new_size(1))
|
||||
m_og->set_value("size_y", double_to_string(m_new_size(1), 2));
|
||||
|
||||
if (m_cache_size(2) != m_new_size(2))
|
||||
m_og->set_value("size_z", double_to_string(m_new_size(2), 2));
|
||||
|
||||
m_cache_size = m_new_size;
|
||||
|
||||
if (m_cache_rotation(0) != m_new_rotation(0))
|
||||
m_og->set_value("rotation_x", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(0)), 0), 2));
|
||||
|
||||
if (m_cache_rotation(1) != m_new_rotation(1))
|
||||
m_og->set_value("rotation_y", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(1)), 0), 2));
|
||||
|
||||
if (m_cache_rotation(2) != m_new_rotation(2))
|
||||
m_og->set_value("rotation_z", double_to_string(round_nearest(Geometry::rad2deg(m_new_rotation(2)), 0), 2));
|
||||
|
||||
m_cache_rotation = m_new_rotation;
|
||||
|
||||
if (m_new_enabled)
|
||||
m_og->enable();
|
||||
else
|
||||
m_og->disable();
|
||||
#else
|
||||
if (! m_dirty)
|
||||
return;
|
||||
|
||||
|
@ -259,23 +349,23 @@ void ObjectManipulation::update_if_dirty()
|
|||
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));
|
||||
cache_position = m_new_position;
|
||||
m_cache_position = m_new_position;
|
||||
|
||||
auto scale = m_new_scale * 100.0;
|
||||
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));
|
||||
cache_scale = scale;
|
||||
m_cache_scale = scale;
|
||||
|
||||
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));
|
||||
cache_size = m_new_size;
|
||||
m_cache_size = m_new_size;
|
||||
|
||||
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));
|
||||
cache_rotation = m_new_rotation;
|
||||
m_cache_rotation = m_new_rotation;
|
||||
|
||||
if (m_new_enabled)
|
||||
m_og->enable();
|
||||
|
@ -283,15 +373,19 @@ void ObjectManipulation::update_if_dirty()
|
|||
m_og->disable();
|
||||
|
||||
m_dirty = false;
|
||||
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
}
|
||||
|
||||
void ObjectManipulation::reset_settings_value()
|
||||
{
|
||||
m_new_position = Vec3d::Zero();
|
||||
m_new_rotation = Vec3d::Zero();
|
||||
m_new_scale = Vec3d(1.0, 1.0, 1.0);
|
||||
m_new_size = Vec3d::Zero();
|
||||
m_new_scale = Vec3d::Ones();
|
||||
m_new_size = Vec3d::Zero();
|
||||
m_new_enabled = false;
|
||||
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
m_dirty = true;
|
||||
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
}
|
||||
|
||||
void ObjectManipulation::change_position_value(const Vec3d& position)
|
||||
|
@ -299,10 +393,10 @@ void ObjectManipulation::change_position_value(const Vec3d& position)
|
|||
auto canvas = wxGetApp().plater()->canvas3D();
|
||||
GLCanvas3D::Selection& selection = canvas->get_selection();
|
||||
selection.start_dragging();
|
||||
selection.translate(position - cache_position, selection.requires_local_axes());
|
||||
selection.translate(position - m_cache_position, selection.requires_local_axes());
|
||||
canvas->do_move();
|
||||
|
||||
cache_position = position;
|
||||
m_cache_position = position;
|
||||
}
|
||||
|
||||
void ObjectManipulation::change_rotation_value(const Vec3d& rotation)
|
||||
|
@ -327,7 +421,7 @@ void ObjectManipulation::change_scale_value(const Vec3d& scale)
|
|||
const GLCanvas3D::Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
|
||||
if (selection.requires_uniform_scale())
|
||||
{
|
||||
Vec3d abs_scale_diff = (scale - cache_scale).cwiseAbs();
|
||||
Vec3d abs_scale_diff = (scale - m_cache_scale).cwiseAbs();
|
||||
double max_diff = abs_scale_diff(X);
|
||||
Axis max_diff_axis = X;
|
||||
if (max_diff < abs_scale_diff(Y))
|
||||
|
@ -355,7 +449,7 @@ void ObjectManipulation::change_size_value(const Vec3d& size)
|
|||
{
|
||||
const GLCanvas3D::Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
|
||||
|
||||
Vec3d ref_size = cache_size;
|
||||
Vec3d ref_size = m_cache_size;
|
||||
if (selection.is_single_full_instance())
|
||||
{
|
||||
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
|
|
|
@ -14,18 +14,26 @@ namespace GUI {
|
|||
|
||||
class ObjectManipulation : public OG_Settings
|
||||
{
|
||||
Vec3d cache_position { 0., 0., 0. };
|
||||
Vec3d cache_rotation { 0., 0., 0. };
|
||||
Vec3d cache_scale { 100., 100., 100. };
|
||||
Vec3d cache_size { 0., 0., 0. };
|
||||
#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
Vec3d m_cache_position;
|
||||
Vec3d m_cache_rotation;
|
||||
Vec3d m_cache_scale;
|
||||
Vec3d m_cache_size;
|
||||
#else
|
||||
Vec3d m_cache_position{ 0., 0., 0. };
|
||||
Vec3d m_cache_rotation{ 0., 0., 0. };
|
||||
Vec3d m_cache_scale{ 100., 100., 100. };
|
||||
Vec3d m_cache_size{ 0., 0., 0. };
|
||||
#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
|
||||
wxStaticText* m_move_Label = nullptr;
|
||||
wxStaticText* m_scale_Label = nullptr;
|
||||
wxStaticText* m_rotate_Label = nullptr;
|
||||
|
||||
|
||||
#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
// Needs to be updated from OnIdle?
|
||||
bool m_dirty = false;
|
||||
#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION
|
||||
// Cached labels for the delayed update, not localized!
|
||||
std::string m_new_move_label_string;
|
||||
std::string m_new_rotate_label_string;
|
||||
|
|
Loading…
Reference in a new issue