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"
|
2019-03-19 12:30:21 +00:00
|
|
|
#include "Selection.hpp"
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2019-04-24 11:33:05 +00:00
|
|
|
#include "slic3r/Utils/FixModelByWin10.hpp"
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
namespace Slic3r
|
|
|
|
{
|
|
|
|
namespace GUI
|
|
|
|
{
|
|
|
|
|
2019-04-24 17:03:05 +00:00
|
|
|
static wxBitmapComboBox* create_word_local_combo(wxWindow *parent)
|
|
|
|
{
|
|
|
|
wxSize size(15 * wxGetApp().em_unit(), -1);
|
|
|
|
|
|
|
|
wxBitmapComboBox *temp = nullptr;
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
/* wxBitmapComboBox with wxCB_READONLY style return NULL for GetTextCtrl(),
|
|
|
|
* so ToolTip doesn't shown.
|
|
|
|
* Next workaround helps to solve this problem
|
|
|
|
*/
|
|
|
|
temp = new wxBitmapComboBox();
|
|
|
|
temp->SetTextCtrlStyle(wxTE_READONLY);
|
|
|
|
temp->Create(parent, wxID_ANY, wxString(""), wxDefaultPosition, size, 0, nullptr);
|
|
|
|
#else
|
|
|
|
temp = new wxBitmapComboBox(parent, wxID_ANY, wxString(""), wxDefaultPosition, size, 0, nullptr, wxCB_READONLY);
|
|
|
|
#endif //__WXOSX__
|
|
|
|
|
|
|
|
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
|
|
|
temp->SetBackgroundStyle(wxBG_STYLE_PAINT);
|
|
|
|
|
2019-05-07 13:43:53 +00:00
|
|
|
temp->Append(_(L("World coordinates")));
|
|
|
|
temp->Append(_(L("Local coordinates")));
|
2019-04-24 17:03:05 +00:00
|
|
|
temp->SetSelection(0);
|
|
|
|
temp->SetValue(temp->GetString(0));
|
|
|
|
|
|
|
|
#ifndef __WXGTK__
|
|
|
|
/* Workaround for a correct rendering of the control without Bitmap (under MSW and OSX):
|
|
|
|
*
|
|
|
|
* 1. We should create small Bitmap to fill Bitmaps RefData,
|
|
|
|
* ! in this case wxBitmap.IsOK() return true.
|
|
|
|
* 2. But then set width to 0 value for no using of bitmap left and right spacing
|
|
|
|
* 3. Set this empty bitmap to the at list one item and BitmapCombobox will be recreated correct
|
|
|
|
*
|
|
|
|
* Note: Set bitmap height to the Font size because of OSX rendering.
|
|
|
|
*/
|
|
|
|
wxBitmap empty_bmp(1, temp->GetFont().GetPixelSize().y + 2);
|
|
|
|
empty_bmp.SetWidth(0);
|
|
|
|
temp->SetItemBitmap(0, empty_bmp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
temp->SetToolTip(_(L("Select coordinate space, in which the transformation will be performed.")));
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2018-11-14 15:24:36 +00:00
|
|
|
ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
2018-10-04 14:43:10 +00:00
|
|
|
OG_Settings(parent, true)
|
2019-01-31 13:12:07 +00:00
|
|
|
#ifndef __APPLE__
|
|
|
|
, m_focused_option("")
|
|
|
|
#endif // __APPLE__
|
2018-10-04 14:43:10 +00:00
|
|
|
{
|
2019-05-03 11:09:42 +00:00
|
|
|
m_manifold_warning_bmp = ScalableBitmap(parent, "exclamation");
|
2018-10-04 14:43:10 +00:00
|
|
|
m_og->set_name(_(L("Object Manipulation")));
|
2019-04-13 21:46:52 +00:00
|
|
|
m_og->label_width = 12;//125;
|
2018-10-04 14:43:10 +00:00
|
|
|
m_og->set_grid_vgap(5);
|
2018-11-14 11:33:48 +00:00
|
|
|
|
2019-01-31 13:12:07 +00:00
|
|
|
m_og->m_on_change = std::bind(&ObjectManipulation::on_change, this, std::placeholders::_1, std::placeholders::_2);
|
|
|
|
m_og->m_fill_empty_value = std::bind(&ObjectManipulation::on_fill_empty_value, this, std::placeholders::_1);
|
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-31 13:12:07 +00:00
|
|
|
#ifndef __APPLE__
|
|
|
|
m_focused_option = opt_key;
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
2019-01-28 14:50:02 +00:00
|
|
|
// needed to show the visual hints in 3D scene
|
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
|
2019-04-24 11:33:05 +00:00
|
|
|
// def.label = L("Name");
|
|
|
|
// def.gui_type = "legend";
|
|
|
|
// def.tooltip = L("Object name");
|
|
|
|
// def.width = 21 * wxGetApp().em_unit();
|
|
|
|
// def.default_value = new ConfigOptionString{ " " };
|
|
|
|
// m_og->append_single_option_line(Option(def, "object_name"));
|
|
|
|
|
|
|
|
Line line = Line{ "Name", "Object name" };
|
|
|
|
|
|
|
|
auto manifold_warning_icon = [this](wxWindow* parent) {
|
|
|
|
m_fix_throught_netfab_bitmap = new wxStaticBitmap(parent, wxID_ANY, wxNullBitmap);
|
|
|
|
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sizer->Add(m_fix_throught_netfab_bitmap);
|
|
|
|
|
|
|
|
if (is_windows10())
|
|
|
|
m_fix_throught_netfab_bitmap->Bind(wxEVT_CONTEXT_MENU, [this](wxCommandEvent &e)
|
|
|
|
{
|
|
|
|
// if object/sub-object has no errors
|
|
|
|
if (m_fix_throught_netfab_bitmap->GetBitmap().GetRefData() == wxNullBitmap.GetRefData())
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxGetApp().obj_list()->fix_through_netfabb();
|
2019-05-02 07:54:18 +00:00
|
|
|
update_warning_icon_state(wxGetApp().obj_list()->get_mesh_errors_list());
|
2019-04-24 11:33:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return sizer;
|
|
|
|
};
|
|
|
|
|
|
|
|
line.append_widget(manifold_warning_icon);
|
|
|
|
def.label = "";
|
2018-10-04 14:43:10 +00:00
|
|
|
def.gui_type = "legend";
|
|
|
|
def.tooltip = L("Object name");
|
2019-05-03 11:09:42 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
def.width = 19;
|
2019-05-03 17:13:47 +00:00
|
|
|
#else
|
2019-04-13 21:46:52 +00:00
|
|
|
def.width = 21;
|
2019-05-03 11:09:42 +00:00
|
|
|
#endif
|
2019-05-03 16:01:39 +00:00
|
|
|
def.set_default_value(new ConfigOptionString{ " " });
|
2019-04-24 11:33:05 +00:00
|
|
|
line.append_option(Option(def, "object_name"));
|
|
|
|
m_og->append_line(line);
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2019-04-13 21:46:52 +00:00
|
|
|
const int field_width = 5;
|
2019-02-04 11:07:15 +00:00
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
// Legend for object modification
|
2019-04-24 11:33:05 +00:00
|
|
|
line = Line{ "", "" };
|
2018-10-04 14:43:10 +00:00
|
|
|
def.label = "";
|
|
|
|
def.type = coString;
|
2019-02-04 11:07:15 +00:00
|
|
|
def.width = field_width/*50*/;
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2019-04-24 09:01:59 +00:00
|
|
|
for (const std::string axis : { "x", "y", "z" }) {
|
|
|
|
const std::string label = boost::algorithm::to_upper_copy(axis);
|
2019-05-03 16:01:39 +00:00
|
|
|
def.set_default_value(new ConfigOptionString{ " " + label });
|
2018-10-04 14:43:10 +00:00
|
|
|
Option option = Option(def, axis + "_axis_legend");
|
|
|
|
line.append_option(option);
|
|
|
|
}
|
2019-04-24 17:03:05 +00:00
|
|
|
line.near_label_widget = [this](wxWindow* parent) {
|
|
|
|
wxBitmapComboBox *combo = create_word_local_combo(parent);
|
|
|
|
combo->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent &evt) { this->set_world_coordinates(evt.GetSelection() != 1); }), combo->GetId());
|
|
|
|
m_word_local_combo = combo;
|
|
|
|
return combo;
|
|
|
|
};
|
2018-10-04 14:43:10 +00:00
|
|
|
m_og->append_line(line);
|
|
|
|
|
2019-02-04 11:07:15 +00:00
|
|
|
auto add_og_to_object_settings = [this, field_width](const std::string& option_name, const std::string& sidetext)
|
2018-10-04 14:43:10 +00:00
|
|
|
{
|
|
|
|
Line line = { _(option_name), "" };
|
|
|
|
ConfigOptionDef def;
|
2018-11-14 11:33:48 +00:00
|
|
|
def.type = coFloat;
|
2019-05-03 16:01:39 +00:00
|
|
|
def.set_default_value(new ConfigOptionFloat(0.0));
|
2019-02-04 11:07:15 +00:00
|
|
|
def.width = field_width/*50*/;
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2019-01-08 12:34:47 +00:00
|
|
|
// Add "uniform scaling" button in front of "Scale" option
|
2019-02-06 08:57:52 +00:00
|
|
|
if (option_name == "Scale") {
|
2019-01-08 12:34:47 +00:00
|
|
|
line.near_label_widget = [this](wxWindow* parent) {
|
2019-04-24 23:45:00 +00:00
|
|
|
auto btn = new LockButton(parent, wxID_ANY);
|
2019-01-08 12:34:47 +00:00
|
|
|
btn->Bind(wxEVT_BUTTON, [btn, this](wxCommandEvent &event){
|
|
|
|
event.Skip();
|
|
|
|
wxTheApp->CallAfter([btn, this]() { set_uniform_scaling(btn->IsLocked()); });
|
|
|
|
});
|
2019-01-09 07:48:25 +00:00
|
|
|
m_lock_bnt = btn;
|
2019-01-08 12:34:47 +00:00
|
|
|
return btn;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add empty bmp (Its size have to be equal to PrusaLockButton) in front of "Size" option to label alignment
|
|
|
|
else if (option_name == "Size") {
|
|
|
|
line.near_label_widget = [this](wxWindow* parent) {
|
2019-02-11 13:14:35 +00:00
|
|
|
return new wxStaticBitmap(parent, wxID_ANY, wxNullBitmap, wxDefaultPosition,
|
2019-04-05 16:53:02 +00:00
|
|
|
create_scaled_bitmap(m_parent, "one_layer_lock_on.png").GetSize());
|
2019-01-08 12:34:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
const std::string lower_name = boost::algorithm::to_lower_copy(option_name);
|
|
|
|
|
2019-04-24 09:01:59 +00:00
|
|
|
for (const char *axis : { "_x", "_y", "_z" }) {
|
|
|
|
if (axis[1] == 'z')
|
2018-10-04 14:43:10 +00:00
|
|
|
def.sidetext = sidetext;
|
2019-04-24 09:01:59 +00:00
|
|
|
Option option = Option(def, lower_name + axis);
|
2018-10-04 14:43:10 +00:00
|
|
|
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
|
|
|
|
2019-04-16 08:05:45 +00:00
|
|
|
// call back for a rescale of button "Set uniform scale"
|
|
|
|
m_og->rescale_near_label_widget = [this](wxWindow* win) {
|
2019-04-24 23:45:00 +00:00
|
|
|
auto *ctrl = dynamic_cast<LockButton*>(win);
|
2019-04-16 08:05:45 +00:00
|
|
|
if (ctrl == nullptr)
|
|
|
|
return;
|
2019-04-24 23:45:00 +00:00
|
|
|
ctrl->msw_rescale();
|
2019-04-16 08:05:45 +00:00
|
|
|
};
|
2018-11-09 17:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectManipulation::Show(const bool show)
|
|
|
|
{
|
2019-04-26 15:28:31 +00:00
|
|
|
if (show != IsShown()) {
|
|
|
|
m_og->Show(show);
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2019-04-26 15:28:31 +00:00
|
|
|
if (show && wxGetApp().get_mode() != comSimple) {
|
|
|
|
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
|
|
|
|
2019-04-26 15:28:31 +00:00
|
|
|
if (show) {
|
|
|
|
bool show_world_local_combo = wxGetApp().plater()->canvas3D()->get_selection().is_single_full_instance();
|
|
|
|
m_word_local_combo->Show(show_world_local_combo);
|
|
|
|
}
|
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
|
|
|
{
|
2019-05-07 13:43:53 +00:00
|
|
|
return dynamic_cast<const wxStaticBoxSizer*>(m_og->sizer)->GetStaticBox()->IsShown(); // 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
|
|
|
{
|
2019-05-03 10:36:26 +00:00
|
|
|
if (show) {
|
|
|
|
this->set_dirty();
|
|
|
|
this->update_if_dirty();
|
|
|
|
}
|
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
|
|
|
|
2019-03-19 12:30:21 +00:00
|
|
|
void ObjectManipulation::update_settings_value(const Selection& selection)
|
2018-10-08 12:02:12 +00:00
|
|
|
{
|
2019-01-21 11:34:28 +00:00
|
|
|
m_new_move_label_string = L("Position");
|
|
|
|
m_new_rotate_label_string = L("Rotation");
|
|
|
|
m_new_scale_label_string = L("Scale factors");
|
2019-03-29 13:36:09 +00:00
|
|
|
|
|
|
|
ObjectList* obj_list = wxGetApp().obj_list();
|
2019-05-03 10:36:26 +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();
|
2019-05-03 10:36:26 +00:00
|
|
|
|
|
|
|
// Verify whether the instance rotation is multiples of 90 degrees, so that the scaling in world coordinates is possible.
|
|
|
|
if (m_world_coordinates && ! m_uniform_scale &&
|
|
|
|
! Geometry::is_rotation_ninety_degrees(volume->get_instance_rotation())) {
|
|
|
|
// Manipulating an instance in the world coordinate system, rotation is not multiples of ninety degrees, therefore enforce uniform scaling.
|
|
|
|
m_uniform_scale = true;
|
|
|
|
m_lock_bnt->SetLock(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_world_coordinates) {
|
|
|
|
m_new_rotate_label_string = L("Rotate");
|
|
|
|
m_new_rotation = Vec3d::Zero();
|
2019-05-07 13:43:53 +00:00
|
|
|
m_new_size = selection.get_scaled_instance_bounding_box().size();
|
2019-05-03 10:36:26 +00:00
|
|
|
m_new_scale = m_new_size.cwiseProduct(selection.get_unscaled_instance_bounding_box().size().cwiseInverse()) * 100.;
|
|
|
|
} else {
|
|
|
|
m_new_rotation = volume->get_instance_rotation() * (180. / M_PI);
|
|
|
|
m_new_size = volume->get_instance_transformation().get_scaling_factor().cwiseProduct((*wxGetApp().model_objects())[volume->object_idx()]->raw_mesh_bounding_box().size());
|
|
|
|
m_new_scale = volume->get_instance_scaling_factor() * 100.;
|
|
|
|
}
|
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
|
|
|
}
|
2019-05-03 10:36:26 +00:00
|
|
|
else if (selection.is_single_full_object() && obj_list->is_selected(itObject))
|
2018-10-08 12:02:12 +00:00
|
|
|
{
|
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();
|
2019-04-24 17:03:05 +00:00
|
|
|
m_new_scale = Vec3d(100., 100., 100.);
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_size = box.size();
|
2019-01-21 11:34:28 +00:00
|
|
|
m_new_rotate_label_string = L("Rotate");
|
|
|
|
m_new_scale_label_string = L("Scale");
|
2018-12-20 19:12:26 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
// 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();
|
2019-04-24 17:03:05 +00:00
|
|
|
m_new_rotation = volume->get_volume_rotation() * (180. / M_PI);
|
|
|
|
m_new_scale = volume->get_volume_scaling_factor() * 100.;
|
2019-04-24 09:01:59 +00:00
|
|
|
m_new_size = volume->get_volume_transformation().get_scaling_factor().cwiseProduct(volume->bounding_box.size());
|
2019-03-22 10:51:10 +00:00
|
|
|
m_new_enabled = true;
|
2018-10-08 12:02:12 +00:00
|
|
|
}
|
2019-03-29 13:36:09 +00:00
|
|
|
else if (obj_list->multiple_selection() || obj_list->is_selected(itInstanceRoot))
|
2018-11-22 14:12:09 +00:00
|
|
|
{
|
|
|
|
reset_settings_value();
|
2019-01-21 11:34:28 +00:00
|
|
|
m_new_move_label_string = L("Translate");
|
|
|
|
m_new_rotate_label_string = L("Rotate");
|
|
|
|
m_new_scale_label_string = L("Scale");
|
2018-12-20 19:12:26 +00:00
|
|
|
m_new_size = selection.get_bounding_box().size();
|
|
|
|
m_new_enabled = true;
|
2018-11-22 14:12:09 +00:00
|
|
|
}
|
2019-04-24 09:01:59 +00:00
|
|
|
else {
|
|
|
|
// No selection, reset the cache.
|
2019-04-24 17:03:05 +00:00
|
|
|
// assert(selection.is_empty());
|
2019-04-24 09:01:59 +00:00
|
|
|
reset_settings_value();
|
|
|
|
}
|
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-05-03 10:36:26 +00:00
|
|
|
if (! m_dirty)
|
2019-01-24 10:37:58 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-03 10:36:26 +00:00
|
|
|
const Selection &selection = wxGetApp().plater()->canvas3D()->get_selection();
|
|
|
|
this->update_settings_value(selection);
|
|
|
|
|
2019-04-29 16:10:08 +00:00
|
|
|
auto update_label = [](wxString &label_cache, const std::string &new_label, wxStaticText *widget) {
|
|
|
|
wxString new_label_localized = _(new_label) + ":";
|
2019-04-24 09:01:59 +00:00
|
|
|
if (label_cache != new_label_localized) {
|
|
|
|
label_cache = new_label_localized;
|
|
|
|
widget->SetLabel(new_label_localized);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
update_label(m_cache.move_label_string, m_new_move_label_string, m_move_Label);
|
|
|
|
update_label(m_cache.rotate_label_string, m_new_rotate_label_string, m_rotate_Label);
|
|
|
|
update_label(m_cache.scale_label_string, m_new_scale_label_string, m_scale_Label);
|
|
|
|
|
|
|
|
char axis[2] = "x";
|
|
|
|
for (int i = 0; i < 3; ++ i, ++ axis[0]) {
|
2019-04-24 17:03:05 +00:00
|
|
|
auto update = [this, i, &axis](Vec3d &cached, Vec3d &cached_rounded, const char *key, const Vec3d &new_value) {
|
|
|
|
wxString new_text = double_to_string(new_value(i), 2);
|
|
|
|
double new_rounded;
|
|
|
|
new_text.ToDouble(&new_rounded);
|
|
|
|
if (std::abs(cached_rounded(i) - new_rounded) > EPSILON) {
|
|
|
|
cached_rounded(i) = new_rounded;
|
|
|
|
m_og->set_value(std::string(key) + axis, new_text);
|
|
|
|
}
|
|
|
|
cached(i) = new_value(i);
|
|
|
|
};
|
|
|
|
update(m_cache.position, m_cache.position_rounded, "position_", m_new_position);
|
|
|
|
update(m_cache.scale, m_cache.scale_rounded, "scale_", m_new_scale);
|
|
|
|
update(m_cache.size, m_cache.size_rounded, "size_", m_new_size);
|
|
|
|
update(m_cache.rotation, m_cache.rotation_rounded, "rotation_", m_new_rotation);
|
2019-01-07 09:53:48 +00:00
|
|
|
}
|
2019-01-02 12:42:29 +00:00
|
|
|
|
2019-05-03 10:36:26 +00:00
|
|
|
if (selection.requires_uniform_scale()) {
|
2019-01-09 07:48:25 +00:00
|
|
|
m_lock_bnt->SetLock(true);
|
2019-01-09 08:47:05 +00:00
|
|
|
m_lock_bnt->Disable();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_lock_bnt->SetLock(m_uniform_scale);
|
|
|
|
m_lock_bnt->Enable();
|
2019-01-09 07:48:25 +00:00
|
|
|
}
|
2019-01-08 14:16:40 +00:00
|
|
|
|
2019-04-24 17:03:05 +00:00
|
|
|
{
|
|
|
|
int new_selection = m_world_coordinates ? 0 : 1;
|
|
|
|
if (m_word_local_combo->GetSelection() != new_selection)
|
|
|
|
m_word_local_combo->SetSelection(new_selection);
|
|
|
|
}
|
|
|
|
|
2019-01-02 12:42:29 +00:00
|
|
|
if (m_new_enabled)
|
|
|
|
m_og->enable();
|
|
|
|
else
|
|
|
|
m_og->disable();
|
2018-12-20 19:12:26 +00:00
|
|
|
|
|
|
|
m_dirty = false;
|
2018-10-04 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 13:12:07 +00:00
|
|
|
#ifndef __APPLE__
|
|
|
|
void ObjectManipulation::emulate_kill_focus()
|
|
|
|
{
|
|
|
|
if (m_focused_option.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// we need to use a copy because the value of m_focused_option is modified inside on_change() and on_fill_empty_value()
|
|
|
|
std::string option = m_focused_option;
|
|
|
|
|
|
|
|
// see TextCtrl::propagate_value()
|
|
|
|
if (static_cast<wxTextCtrl*>(m_og->get_fieldc(option, 0)->getWindow())->GetValue().empty())
|
|
|
|
on_fill_empty_value(option);
|
|
|
|
else
|
|
|
|
on_change(option, 0);
|
|
|
|
}
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
2019-05-02 07:54:18 +00:00
|
|
|
void ObjectManipulation::update_warning_icon_state(const wxString& tooltip)
|
2019-04-24 11:33:05 +00:00
|
|
|
{
|
2019-04-29 13:27:59 +00:00
|
|
|
m_fix_throught_netfab_bitmap->SetBitmap(tooltip.IsEmpty() ? wxNullBitmap : m_manifold_warning_bmp.bmp());
|
2019-04-24 11:33:05 +00:00
|
|
|
m_fix_throught_netfab_bitmap->SetToolTip(tooltip);
|
|
|
|
}
|
|
|
|
|
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-05-07 13:43:53 +00:00
|
|
|
m_new_scale = Vec3d::Ones() * 100.;
|
2019-01-02 12:42:29 +00:00
|
|
|
m_new_size = Vec3d::Zero();
|
2019-01-07 09:53:48 +00:00
|
|
|
m_new_enabled = false;
|
2019-05-03 10:36:26 +00:00
|
|
|
// no need to set the dirty flag here as this method is called from update_settings_value(),
|
|
|
|
// which is called from update_if_dirty(), which resets the dirty flag anyways.
|
|
|
|
// m_dirty = true;
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2019-04-24 17:03:05 +00:00
|
|
|
void ObjectManipulation::change_position_value(int axis, double value)
|
2018-11-14 15:24:36 +00:00
|
|
|
{
|
2019-04-24 17:03:05 +00:00
|
|
|
if (std::abs(m_cache.position_rounded(axis) - value) < EPSILON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vec3d position = m_cache.position;
|
|
|
|
position(axis) = value;
|
|
|
|
|
2018-11-23 11:47:32 +00:00
|
|
|
auto canvas = wxGetApp().plater()->canvas3D();
|
2019-03-19 12:30:21 +00:00
|
|
|
Selection& selection = canvas->get_selection();
|
2018-12-19 14:03:49 +00:00
|
|
|
selection.start_dragging();
|
2019-01-07 09:53:48 +00:00
|
|
|
selection.translate(position - m_cache.position, selection.requires_local_axes());
|
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
|
|
|
m_cache.position = position;
|
2019-04-24 17:03:05 +00:00
|
|
|
m_cache.position_rounded(axis) = DBL_MAX;
|
|
|
|
this->UpdateAndShow(true);
|
2018-11-14 15:24:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 17:03:05 +00:00
|
|
|
void ObjectManipulation::change_rotation_value(int axis, double value)
|
2018-11-15 10:15:24 +00:00
|
|
|
{
|
2019-04-24 17:03:05 +00:00
|
|
|
if (std::abs(m_cache.rotation_rounded(axis) - value) < EPSILON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vec3d rotation = m_cache.rotation;
|
|
|
|
rotation(axis) = value;
|
|
|
|
|
2018-12-18 10:11:06 +00:00
|
|
|
GLCanvas3D* canvas = wxGetApp().plater()->canvas3D();
|
2019-04-24 09:01:59 +00:00
|
|
|
Selection& selection = canvas->get_selection();
|
2018-12-18 10:11:06 +00:00
|
|
|
|
2019-03-19 12:30:21 +00:00
|
|
|
TransformationType transformation_type(TransformationType::World_Relative_Joint);
|
|
|
|
if (selection.is_single_full_instance() || selection.requires_local_axes())
|
2019-03-01 09:20:12 +00:00
|
|
|
transformation_type.set_independent();
|
2019-04-24 09:01:59 +00:00
|
|
|
if (selection.is_single_full_instance() && ! m_world_coordinates) {
|
2019-03-19 14:33:09 +00:00
|
|
|
//FIXME Selection::rotate() does not process absoulte rotations correctly: It does not recognize the axis index, which was changed.
|
2019-03-01 14:35:48 +00:00
|
|
|
// transformation_type.set_absolute();
|
2019-03-01 09:20:12 +00:00
|
|
|
transformation_type.set_local();
|
|
|
|
}
|
2019-01-29 10:26:35 +00:00
|
|
|
|
2019-04-24 09:01:59 +00:00
|
|
|
selection.start_dragging();
|
|
|
|
selection.rotate(
|
|
|
|
(M_PI / 180.0) * (transformation_type.absolute() ? rotation : rotation - m_cache.rotation),
|
|
|
|
transformation_type);
|
2018-11-21 09:36:09 +00:00
|
|
|
canvas->do_rotate();
|
2019-01-03 10:24:03 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.rotation = rotation;
|
2019-04-24 17:03:05 +00:00
|
|
|
m_cache.rotation_rounded(axis) = DBL_MAX;
|
|
|
|
this->UpdateAndShow(true);
|
2018-11-15 10:15:24 +00:00
|
|
|
}
|
2018-11-14 15:24:36 +00:00
|
|
|
|
2019-04-24 17:03:05 +00:00
|
|
|
void ObjectManipulation::change_scale_value(int axis, double value)
|
2018-11-15 10:15:24 +00:00
|
|
|
{
|
2019-04-24 17:03:05 +00:00
|
|
|
if (std::abs(m_cache.scale_rounded(axis) - value) < EPSILON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vec3d scale = m_cache.scale;
|
2019-05-03 10:36:26 +00:00
|
|
|
scale(axis) = value;
|
2019-04-24 17:03:05 +00:00
|
|
|
|
2019-05-03 10:36:26 +00:00
|
|
|
this->do_scale(axis, scale);
|
2019-01-08 08:51:58 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
m_cache.scale = scale;
|
2019-04-24 17:03:05 +00:00
|
|
|
m_cache.scale_rounded(axis) = DBL_MAX;
|
|
|
|
this->UpdateAndShow(true);
|
2018-11-15 10:15:24 +00:00
|
|
|
}
|
2018-11-14 15:24:36 +00:00
|
|
|
|
2019-04-24 17:03:05 +00:00
|
|
|
void ObjectManipulation::change_size_value(int axis, double value)
|
2018-11-14 15:24:36 +00:00
|
|
|
{
|
2019-04-24 17:03:05 +00:00
|
|
|
if (std::abs(m_cache.size_rounded(axis) - value) < EPSILON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vec3d size = m_cache.size;
|
|
|
|
size(axis) = value;
|
|
|
|
|
2019-03-19 12:30:21 +00:00
|
|
|
const Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
|
2018-12-18 09:10:14 +00:00
|
|
|
|
2019-01-07 09:53:48 +00:00
|
|
|
Vec3d ref_size = m_cache.size;
|
2019-05-03 10:36:26 +00:00
|
|
|
if (selection.is_single_volume() || selection.is_single_modifier())
|
|
|
|
ref_size = selection.get_volume(*selection.get_volume_idxs().begin())->bounding_box.size();
|
|
|
|
else if (selection.is_single_full_instance())
|
|
|
|
ref_size = m_world_coordinates ?
|
|
|
|
selection.get_unscaled_instance_bounding_box().size() :
|
|
|
|
(*wxGetApp().model_objects())[selection.get_volume(*selection.get_volume_idxs().begin())->object_idx()]->raw_mesh_bounding_box().size();
|
2018-12-18 09:10:14 +00:00
|
|
|
|
2019-05-03 10:36:26 +00:00
|
|
|
this->do_scale(axis, 100. * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2)));
|
2019-04-24 09:01:59 +00:00
|
|
|
|
|
|
|
m_cache.size = size;
|
2019-04-24 17:03:05 +00:00
|
|
|
m_cache.size_rounded(axis) = DBL_MAX;
|
|
|
|
this->UpdateAndShow(true);
|
2019-04-24 09:01:59 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 10:36:26 +00:00
|
|
|
void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const
|
2019-04-24 09:01:59 +00:00
|
|
|
{
|
|
|
|
Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
|
2019-01-04 12:59:41 +00:00
|
|
|
Vec3d scaling_factor = scale;
|
|
|
|
|
2019-05-01 09:33:41 +00:00
|
|
|
TransformationType transformation_type(TransformationType::World_Relative_Joint);
|
|
|
|
if (selection.is_single_full_instance()) {
|
2019-05-03 10:36:26 +00:00
|
|
|
transformation_type.set_absolute();
|
|
|
|
if (! m_world_coordinates)
|
2019-05-01 09:33:41 +00:00
|
|
|
transformation_type.set_local();
|
|
|
|
}
|
|
|
|
|
2019-05-03 10:36:26 +00:00
|
|
|
if (m_uniform_scale || selection.requires_uniform_scale())
|
|
|
|
scaling_factor = scale(axis) * Vec3d::Ones();
|
2019-01-04 12:59:41 +00:00
|
|
|
|
2019-04-24 09:01:59 +00:00
|
|
|
selection.start_dragging();
|
|
|
|
selection.scale(scaling_factor * 0.01, transformation_type);
|
|
|
|
wxGetApp().plater()->canvas3D()->do_scale();
|
2018-11-14 15:24:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 09:01:59 +00:00
|
|
|
void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any& value)
|
2019-01-31 13:12:07 +00:00
|
|
|
{
|
|
|
|
// needed to hide the visual hints in 3D scene
|
|
|
|
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false);
|
|
|
|
#ifndef __APPLE__
|
|
|
|
m_focused_option = "";
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
|
|
|
if (!m_cache.is_valid())
|
|
|
|
return;
|
|
|
|
|
2019-04-24 17:03:05 +00:00
|
|
|
int axis = opt_key.back() - 'x';
|
|
|
|
double new_value = boost::any_cast<double>(m_og->get_value(opt_key));
|
2019-01-31 13:12:07 +00:00
|
|
|
|
2019-04-24 09:01:59 +00:00
|
|
|
if (boost::starts_with(opt_key, "position_"))
|
2019-04-24 17:03:05 +00:00
|
|
|
change_position_value(axis, new_value);
|
2019-04-24 09:01:59 +00:00
|
|
|
else if (boost::starts_with(opt_key, "rotation_"))
|
2019-04-24 17:03:05 +00:00
|
|
|
change_rotation_value(axis, new_value);
|
2019-04-24 09:01:59 +00:00
|
|
|
else if (boost::starts_with(opt_key, "scale_"))
|
2019-04-24 17:03:05 +00:00
|
|
|
change_scale_value(axis, new_value);
|
2019-04-24 09:01:59 +00:00
|
|
|
else if (boost::starts_with(opt_key, "size_"))
|
2019-04-24 17:03:05 +00:00
|
|
|
change_size_value(axis, new_value);
|
2019-01-31 13:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectManipulation::on_fill_empty_value(const std::string& opt_key)
|
|
|
|
{
|
|
|
|
// needed to hide the visual hints in 3D scene
|
|
|
|
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false);
|
|
|
|
#ifndef __APPLE__
|
|
|
|
m_focused_option = "";
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
|
|
|
if (!m_cache.is_valid())
|
|
|
|
return;
|
|
|
|
|
2019-04-24 09:01:59 +00:00
|
|
|
const Vec3d *vec = nullptr;
|
2019-04-24 17:03:05 +00:00
|
|
|
Vec3d *rounded = nullptr;
|
|
|
|
if (boost::starts_with(opt_key, "position_")) {
|
2019-04-24 09:01:59 +00:00
|
|
|
vec = &m_cache.position;
|
2019-04-24 17:03:05 +00:00
|
|
|
rounded = &m_cache.position_rounded;
|
|
|
|
} else if (boost::starts_with(opt_key, "rotation_")) {
|
2019-04-24 09:01:59 +00:00
|
|
|
vec = &m_cache.rotation;
|
2019-04-24 17:03:05 +00:00
|
|
|
rounded = &m_cache.rotation_rounded;
|
|
|
|
} else if (boost::starts_with(opt_key, "scale_")) {
|
2019-04-24 09:01:59 +00:00
|
|
|
vec = &m_cache.scale;
|
2019-04-24 17:03:05 +00:00
|
|
|
rounded = &m_cache.scale_rounded;
|
|
|
|
} else if (boost::starts_with(opt_key, "size_")) {
|
2019-04-24 09:01:59 +00:00
|
|
|
vec = &m_cache.size;
|
2019-04-24 17:03:05 +00:00
|
|
|
rounded = &m_cache.size_rounded;
|
|
|
|
} else
|
2019-04-24 09:01:59 +00:00
|
|
|
assert(false);
|
|
|
|
|
2019-04-24 17:03:05 +00:00
|
|
|
if (vec != nullptr) {
|
|
|
|
int axis = opt_key.back() - 'x';
|
|
|
|
wxString new_text = double_to_string((*vec)(axis));
|
|
|
|
m_og->set_value(opt_key, new_text);
|
|
|
|
new_text.ToDouble(&(*rounded)(axis));
|
|
|
|
}
|
2019-01-31 13:12:07 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 07:24:33 +00:00
|
|
|
void ObjectManipulation::set_uniform_scaling(const bool new_value)
|
|
|
|
{
|
|
|
|
const Selection &selection = wxGetApp().plater()->canvas3D()->get_selection();
|
|
|
|
if (selection.is_single_full_instance() && m_world_coordinates && !new_value) {
|
|
|
|
// Verify whether the instance rotation is multiples of 90 degrees, so that the scaling in world coordinates is possible.
|
|
|
|
// all volumes in the selection belongs to the same instance, any of them contains the needed instance data, so we take the first one
|
|
|
|
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
|
|
|
// Is the angle close to a multiple of 90 degrees?
|
2019-04-26 15:28:31 +00:00
|
|
|
if (! Geometry::is_rotation_ninety_degrees(volume->get_instance_rotation())) {
|
2019-04-25 07:24:33 +00:00
|
|
|
// Cannot apply scaling in the world coordinate system.
|
|
|
|
wxMessageDialog dlg(GUI::wxGetApp().mainframe,
|
2019-05-03 10:36:26 +00:00
|
|
|
_(L("The currently manipulated object is tilted (rotation angles are not multiples of 90°).\n"
|
|
|
|
"Non-uniform scaling of tilted objects is only possible in the World coordinate system,\n"
|
2019-05-07 13:43:53 +00:00
|
|
|
"once the rotation is embedded into the object coordinates.")) + "\n" +
|
|
|
|
_(L("This operation is irreversible.\n"
|
2019-05-03 10:36:26 +00:00
|
|
|
"Do you want to proceed?")),
|
2019-04-25 07:24:33 +00:00
|
|
|
SLIC3R_APP_NAME,
|
2019-05-07 13:43:53 +00:00
|
|
|
wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT | wxICON_QUESTION);
|
2019-04-25 07:24:33 +00:00
|
|
|
if (dlg.ShowModal() != wxID_YES) {
|
|
|
|
// Enforce uniform scaling.
|
|
|
|
m_lock_bnt->SetLock(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Bake the rotation into the meshes of the object.
|
2019-04-26 15:28:31 +00:00
|
|
|
(*wxGetApp().model_objects())[volume->composite_id.object_id]->bake_xy_rotation_into_meshes(volume->composite_id.instance_id);
|
|
|
|
// Update the 3D scene, selections etc.
|
|
|
|
wxGetApp().plater()->update();
|
2019-05-03 10:36:26 +00:00
|
|
|
// Recalculate cached values at this panel, refresh the screen.
|
|
|
|
this->UpdateAndShow(true);
|
2019-04-25 07:24:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_uniform_scale = new_value;
|
|
|
|
}
|
|
|
|
|
2019-04-29 13:27:59 +00:00
|
|
|
void ObjectManipulation::msw_rescale()
|
|
|
|
{
|
|
|
|
m_manifold_warning_bmp.msw_rescale();
|
|
|
|
m_fix_throught_netfab_bitmap->SetBitmap(m_manifold_warning_bmp.bmp());
|
|
|
|
|
|
|
|
get_og()->msw_rescale();
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
} //namespace GUI
|
2019-04-24 09:01:59 +00:00
|
|
|
} //namespace Slic3r
|