Scale and rotation from scene to value updates correctly
This commit is contained in:
parent
54f14e7ebb
commit
c2993de6e0
9 changed files with 98 additions and 15 deletions
|
@ -1099,6 +1099,7 @@ sub rotate {
|
|||
$model_object->center_around_origin;
|
||||
$self->reset_thumbnail($obj_idx);
|
||||
}
|
||||
Slic3r::GUI::update_rotation_value(deg2rad($angle), $axis == X ? "x" : ($axis == Y ? "y" : "z"));
|
||||
|
||||
# update print and start background processing
|
||||
$self->{print}->add_model_object($model_object, $obj_idx);
|
||||
|
|
|
@ -261,6 +261,11 @@ const Pointf3& GLVolume::get_origin() const
|
|||
return m_origin;
|
||||
}
|
||||
|
||||
float GLVolume::get_angle_z()
|
||||
{
|
||||
return m_angle_z;
|
||||
}
|
||||
|
||||
void GLVolume::set_origin(const Pointf3& origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
|
|
|
@ -318,6 +318,7 @@ public:
|
|||
void set_render_color();
|
||||
|
||||
const Pointf3& get_origin() const;
|
||||
float get_angle_z();
|
||||
void set_origin(const Pointf3& origin);
|
||||
void set_angle_z(float angle_z);
|
||||
void set_scale_factor(float scale_factor);
|
||||
|
|
|
@ -333,9 +333,7 @@ void SpinCtrl::BUILD() {
|
|||
break;
|
||||
}
|
||||
|
||||
const int min_val = m_opt_id == "standby_temperature_delta" ?
|
||||
-500 : m_opt.min > 0 ?
|
||||
m_opt.min : 0;
|
||||
const int min_val = m_opt.min == INT_MIN ? 0: m_opt.min;
|
||||
const int max_val = m_opt.max < 2147483647 ? m_opt.max : 2147483647;
|
||||
|
||||
auto temp = new wxSpinCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size,
|
||||
|
|
|
@ -414,8 +414,8 @@ public:
|
|||
|
||||
boost::any& get_value()override { return m_value; }
|
||||
|
||||
void enable() override { dynamic_cast<wxColourPickerCtrl*>(window)->Enable(); };
|
||||
void disable() override{ dynamic_cast<wxColourPickerCtrl*>(window)->Disable(); };
|
||||
void enable() override { dynamic_cast<wxStaticText*>(window)->Enable(); };
|
||||
void disable() override{ dynamic_cast<wxStaticText*>(window)->Disable(); };
|
||||
wxWindow* getWindow() override { return window; }
|
||||
};
|
||||
|
||||
|
|
|
@ -3243,6 +3243,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
const BoundingBoxf3& bb = volumes[0]->transformed_bounding_box();
|
||||
const Pointf3& size = bb.size();
|
||||
m_on_update_geometry_info_callback.call(size.x, size.y, size.z, m_gizmos.get_scale());
|
||||
update_scale_values(size, m_gizmos.get_scale());
|
||||
update_rotation_value(volumes[0]->get_angle_z(), "z");
|
||||
}
|
||||
|
||||
if ((m_gizmos.get_current_type() != Gizmos::Rotate) && (volumes.size() > 1))
|
||||
|
@ -3341,6 +3343,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
case Gizmos::Scale:
|
||||
{
|
||||
m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale());
|
||||
Slic3r::GUI::update_settings_value();
|
||||
break;
|
||||
}
|
||||
case Gizmos::Rotate:
|
||||
|
@ -3387,7 +3390,13 @@ void GLCanvas3D::on_key_down(wxKeyEvent& evt)
|
|||
if (key == WXK_DELETE)
|
||||
m_on_remove_object_callback.call();
|
||||
else
|
||||
{
|
||||
#ifdef __WXOSX__
|
||||
if (key == WXK_BACK)
|
||||
m_on_remove_object_callback.call();
|
||||
#endif
|
||||
evt.Skip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <wx/frame.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "Geometry.hpp"
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
|
@ -40,6 +41,9 @@ int m_selected_object_id = -1;
|
|||
bool g_prevent_list_events = false; // We use this flag to avoid circular event handling Select()
|
||||
// happens to fire a wxEVT_LIST_ITEM_SELECTED on OSX, whose event handler
|
||||
// calls this method again and again and again
|
||||
bool g_is_percent_scale = false; // It indicates if scale unit is percentage
|
||||
int g_rotation_x = 0; // Last value of the rotation around the X axis
|
||||
int g_rotation_y = 0; // Last value of the rotation around the Y axis
|
||||
ModelObjectPtrs* m_objects;
|
||||
std::shared_ptr<DynamicPrintConfig*> m_config;
|
||||
std::shared_ptr<DynamicPrintConfig> m_default_config;
|
||||
|
@ -435,6 +439,9 @@ Line add_og_to_object_settings(const std::string& option_name, const std::string
|
|||
def.sidetext = sidetext;
|
||||
def.width = 70;
|
||||
|
||||
if (option_name == "Rotation")
|
||||
def.min = -360;
|
||||
|
||||
const std::string lower_name = boost::algorithm::to_lower_copy(option_name);
|
||||
|
||||
std::vector<std::string> axes{ "x", "y", "z" };
|
||||
|
@ -458,6 +465,7 @@ Line add_og_to_object_settings(const std::string& option_name, const std::string
|
|||
Option option = Option(def, lower_name + "_unit");
|
||||
line.append_option(option);
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
|
@ -475,6 +483,9 @@ void add_object_settings(wxWindow* parent, wxBoxSizer* sizer)
|
|||
std::string key = "scale_" + axis;
|
||||
get_optgroup(ogFrequentlyObjectSettings)->set_side_text(key, selection);
|
||||
}
|
||||
|
||||
g_is_percent_scale = selection == _("%");
|
||||
update_scale_values();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -485,16 +496,25 @@ void add_object_settings(wxWindow* parent, wxBoxSizer* sizer)
|
|||
// def.default_value = new ConfigOptionString{ "BlaBla_object.stl" };
|
||||
// optgroup->append_single_option_line(Option(def, "object_name"));
|
||||
|
||||
ConfigOptionDef def;
|
||||
|
||||
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{ "BlaBla_object.stl" };
|
||||
optgroup->append_single_option_line(Option(def, "object_name"));
|
||||
|
||||
optgroup->set_flag(ogSIDE_OPTIONS_VERTICAL);
|
||||
optgroup->sidetext_width = 25;
|
||||
|
||||
optgroup->append_line(add_og_to_object_settings(L("Position"), L("mm")));
|
||||
optgroup->append_line(add_og_to_object_settings(L("Rotation"), "°", 1));
|
||||
optgroup->append_line(add_og_to_object_settings(L("Scale"), "%", 2));
|
||||
optgroup->append_line(add_og_to_object_settings(L("Rotation"), "°"));
|
||||
optgroup->append_line(add_og_to_object_settings(L("Scale"), "%"));
|
||||
|
||||
optgroup->set_flag(ogDEFAULT);
|
||||
|
||||
ConfigOptionDef def;
|
||||
def.label = L("Place on bed");
|
||||
def.type = coBool;
|
||||
def.tooltip = L("Automatic placing of models on printing bed in Y axis");
|
||||
|
@ -1142,10 +1162,8 @@ void update_settings_value()
|
|||
printf("return because of unselect\n");
|
||||
return;
|
||||
}
|
||||
auto bb_size = (*m_objects)[m_selected_object_id]->instance_bounding_box(0).size();
|
||||
og->set_value("scale_x", int(bb_size.x+0.5));
|
||||
og->set_value("scale_y", int(bb_size.y+0.5));
|
||||
og->set_value("scale_z", int(bb_size.z+0.5));
|
||||
g_is_percent_scale = boost::any_cast<wxString>(og->get_value("scale_unit")) == _("%");
|
||||
update_scale_values();
|
||||
}
|
||||
|
||||
void part_selection_changed()
|
||||
|
@ -1153,9 +1171,9 @@ void part_selection_changed()
|
|||
printf("part_selection_changed\n");
|
||||
auto item = m_objects_ctrl->GetSelection();
|
||||
int obj_idx = -1;
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
if (item)
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
bool is_part = false;
|
||||
if (m_objects_model->GetParent(item) == wxDataViewItem(0)) {
|
||||
obj_idx = m_objects_model->GetIdByItem(item);
|
||||
|
@ -1173,10 +1191,14 @@ void part_selection_changed()
|
|||
}
|
||||
|
||||
auto config = m_config;
|
||||
og->set_value("object_name", m_objects_model->GetName(item));
|
||||
m_default_config = std::make_shared<DynamicPrintConfig>(*DynamicPrintConfig::new_from_defaults_keys(get_options(is_part)));
|
||||
}
|
||||
else
|
||||
m_config = nullptr;
|
||||
else {
|
||||
wxString empty_str = wxEmptyString;
|
||||
og->set_value("object_name", empty_str);
|
||||
m_config = nullptr;
|
||||
}
|
||||
|
||||
update_settings_list();
|
||||
|
||||
|
@ -1298,5 +1320,43 @@ void update_extruder_in_config(const wxString& selection)
|
|||
}
|
||||
}
|
||||
|
||||
void update_scale_values()
|
||||
{
|
||||
update_scale_values((*m_objects)[m_selected_object_id]->instance_bounding_box(0).size(),
|
||||
(*m_objects)[m_selected_object_id]->instances[0]->scaling_factor);
|
||||
}
|
||||
|
||||
void update_scale_values(const Pointf3& size, float scaling_factor)
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
|
||||
if (g_is_percent_scale) {
|
||||
auto scale = scaling_factor * 100;
|
||||
og->set_value("scale_x", int(scale));
|
||||
og->set_value("scale_y", int(scale));
|
||||
og->set_value("scale_z", int(scale));
|
||||
}
|
||||
else {
|
||||
og->set_value("scale_x", int(size.x + 0.5));
|
||||
og->set_value("scale_y", int(size.y + 0.5));
|
||||
og->set_value("scale_z", int(size.z + 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
void update_rotation_value()
|
||||
{
|
||||
// update_rotation_values(0, 0, (*m_objects)[m_selected_object_id]->volumes[0]->get_angle_z());
|
||||
}
|
||||
|
||||
void update_rotation_value(const double angle, const std::string& axis)
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
|
||||
int deg = int(Geometry::rad2deg(angle));
|
||||
if (deg>180) deg -= 360;
|
||||
|
||||
og->set_value("rotation_"+axis, deg);
|
||||
}
|
||||
|
||||
} //namespace GUI
|
||||
} //namespace Slic3r
|
|
@ -95,10 +95,16 @@ void on_btn_move_down();
|
|||
void parts_changed(int obj_idx);
|
||||
void part_selection_changed();
|
||||
|
||||
void update_settings_value();
|
||||
// show/hide "Extruder" column for Objects List
|
||||
void set_extruder_column_hidden(bool hide);
|
||||
// update extruder in current config
|
||||
void update_extruder_in_config(const wxString& selection);
|
||||
// update scale values after scale unit changing or "gizmos"
|
||||
void update_scale_values();
|
||||
void update_scale_values(const Pointf3& size, float scale);
|
||||
// update rotation values after "gizmos"
|
||||
void update_rotation_value(const double angle, const std::string& axis);
|
||||
} //namespace GUI
|
||||
} //namespace Slic3r
|
||||
#endif //slic3r_GUI_ObjectParts_hpp_
|
|
@ -158,6 +158,9 @@ void select_current_object(int idx)
|
|||
void remove_obj()
|
||||
%code%{ Slic3r::GUI::remove(); %};
|
||||
|
||||
void update_rotation_value(double angle, const char *axis)
|
||||
%code%{ Slic3r::GUI::update_rotation_value(angle, axis); %};
|
||||
|
||||
std::string fold_utf8_to_ascii(const char *src)
|
||||
%code%{ RETVAL = Slic3r::fold_utf8_to_ascii(src); %};
|
||||
|
||||
|
|
Loading…
Reference in a new issue