Merge branch 'dev' into lm_sla_supports_ui

This commit is contained in:
Lukas Matena 2018-09-17 10:26:38 +02:00
commit 37c222a54f
21 changed files with 301 additions and 44 deletions

View file

@ -684,7 +684,11 @@ std::vector<int> GLVolumeCollection::load_object(
}
v.is_modifier = model_volume->modifier;
v.shader_outside_printer_detection_enabled = !model_volume->modifier;
#if ENABLE_MODELINSTANCE_3D_OFFSET
v.set_offset(instance->get_offset());
#else
v.set_offset(Vec3d(instance->offset(0), instance->offset(1), 0.0));
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
v.set_rotation(instance->rotation);
v.set_scaling_factor(instance->scaling_factor);
}

View file

@ -1142,8 +1142,10 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
if (!gizmo->init())
return false;
#if !ENABLE_MODELINSTANCE_3D_OFFSET
// temporary disable z grabber
gizmo->disable_grabber(2);
#endif // !ENABLE_MODELINSTANCE_3D_OFFSET
m_gizmos.insert(GizmosMap::value_type(Move, gizmo));
@ -2410,7 +2412,11 @@ void GLCanvas3D::update_gizmos_data()
ModelInstance* model_instance = model_object->instances[0];
if (model_instance != nullptr)
{
#if ENABLE_MODELINSTANCE_3D_OFFSET
m_gizmos.set_position(model_instance->get_offset());
#else
m_gizmos.set_position(Vec3d(model_instance->offset(0), model_instance->offset(1), 0.0));
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
m_gizmos.set_scale(model_instance->scaling_factor);
m_gizmos.set_angle_z(model_instance->rotation);
m_gizmos.set_flattening_data(model_object);
@ -5496,8 +5502,12 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
ModelObject* model_object = m_model->objects[obj_idx];
if (model_object != nullptr)
{
#if ENABLE_MODELINSTANCE_3D_OFFSET
model_object->instances[instance_idx]->set_offset(volume->get_offset());
#else
const Vec3d& offset = volume->get_offset();
model_object->instances[instance_idx]->offset = Vec2d(offset(0), offset(1));
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
model_object->invalidate_bounding_box();
update_position_values();
object_moved = true;

View file

@ -1033,6 +1033,7 @@ GLGizmoMove3D::GLGizmoMove3D(GLCanvas3D& parent)
, m_position(Vec3d::Zero())
, m_starting_drag_position(Vec3d::Zero())
, m_starting_box_center(Vec3d::Zero())
, m_starting_box_bottom_center(Vec3d::Zero())
{
}
@ -1066,17 +1067,19 @@ void GLGizmoMove3D::on_start_dragging(const BoundingBoxf3& box)
{
m_starting_drag_position = m_grabbers[m_hover_id].center;
m_starting_box_center = box.center();
m_starting_box_bottom_center = box.center();
m_starting_box_bottom_center(2) = box.min(2);
}
}
void GLGizmoMove3D::on_update(const Linef3& mouse_ray)
{
if (m_hover_id == 0)
m_position(0) = 2.0 * m_starting_box_center(0) + calc_displacement(1, mouse_ray) - m_starting_drag_position(0);
m_position(0) = 2.0 * m_starting_box_center(0) + calc_projection(X, 1, mouse_ray) - m_starting_drag_position(0);
else if (m_hover_id == 1)
m_position(1) = 2.0 * m_starting_box_center(1) + calc_displacement(2, mouse_ray) - m_starting_drag_position(1);
m_position(1) = 2.0 * m_starting_box_center(1) + calc_projection(Y, 2, mouse_ray) - m_starting_drag_position(1);
else if (m_hover_id == 2)
m_position(2) = 2.0 * m_starting_box_center(2) + calc_displacement(1, mouse_ray) - m_starting_drag_position(2);
m_position(2) = 2.0 * m_starting_box_bottom_center(2) + calc_projection(Z, 1, mouse_ray) - m_starting_drag_position(2);
}
void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
@ -1145,40 +1148,40 @@ void GLGizmoMove3D::on_render_for_picking(const BoundingBoxf3& box) const
render_grabbers_for_picking(box);
}
double GLGizmoMove3D::calc_displacement(unsigned int preferred_plane_id, const Linef3& mouse_ray) const
double GLGizmoMove3D::calc_projection(Axis axis, unsigned int preferred_plane_id, const Linef3& mouse_ray) const
{
double displacement = 0.0;
double projection = 0.0;
Vec3d starting_vec = m_starting_drag_position - m_starting_box_center;
Vec3d starting_vec = (axis == Z) ? m_starting_drag_position - m_starting_box_bottom_center : m_starting_drag_position - m_starting_box_center;
double len_starting_vec = starting_vec.norm();
if (len_starting_vec == 0.0)
return displacement;
return projection;
Vec3d starting_vec_dir = starting_vec.normalized();
Vec3d mouse_dir = mouse_ray.unit_vector();
unsigned int plane_id = select_best_plane(mouse_dir, preferred_plane_id);
switch (plane_id)
switch (plane_id)
{
case 0:
{
displacement = starting_vec_dir.dot(intersection_on_plane_xy(mouse_ray, m_starting_box_center));
projection = starting_vec_dir.dot(intersection_on_plane_xy(mouse_ray, (axis == Z) ? m_starting_box_bottom_center : m_starting_box_center));
break;
}
case 1:
{
displacement = starting_vec_dir.dot(intersection_on_plane_xz(mouse_ray, m_starting_box_center));
projection = starting_vec_dir.dot(intersection_on_plane_xz(mouse_ray, (axis == Z) ? m_starting_box_bottom_center : m_starting_box_center));
break;
}
case 2:
{
displacement = starting_vec_dir.dot(intersection_on_plane_yz(mouse_ray, m_starting_box_center));
projection = starting_vec_dir.dot(intersection_on_plane_yz(mouse_ray, (axis == Z) ? m_starting_box_bottom_center : m_starting_box_center));
break;
}
}
return displacement;
return projection;
}
GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent)
@ -1234,10 +1237,19 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
else
::glColor4f(0.9f, 0.9f, 0.9f, 0.5f);
#if ENABLE_MODELINSTANCE_3D_OFFSET
for (Vec3d offset : m_instances_positions) {
offset += dragged_offset;
#else
for (Vec2d offset : m_instances_positions) {
offset += to_2d(dragged_offset);
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
::glPushMatrix();
#if ENABLE_MODELINSTANCE_3D_OFFSET
::glTranslated(offset(0), offset(1), offset(2));
#else
::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices)
::glVertex3f((GLfloat)vertex(0), (GLfloat)vertex(1), (GLfloat)vertex(2));
@ -1256,9 +1268,17 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
for (unsigned int i = 0; i < m_planes.size(); ++i)
{
::glColor3f(1.0f, 1.0f, picking_color_component(i));
#if ENABLE_MODELINSTANCE_3D_OFFSET
for (const Vec3d& offset : m_instances_positions) {
#else
for (const Vec2d& offset : m_instances_positions) {
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
::glPushMatrix();
#if ENABLE_MODELINSTANCE_3D_OFFSET
::glTranslated(offset(0), offset(1), offset(2));
#else
::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices)
::glVertex3f((GLfloat)vertex(0), (GLfloat)vertex(1), (GLfloat)vertex(2));
@ -1276,7 +1296,11 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
if (m_model_object && !m_model_object->instances.empty()) {
m_instances_positions.clear();
for (const auto* instance : m_model_object->instances)
#if ENABLE_MODELINSTANCE_3D_OFFSET
m_instances_positions.emplace_back(instance->get_offset());
#else
m_instances_positions.emplace_back(instance->offset);
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
}
if (is_plane_update_necessary())

View file

@ -287,6 +287,7 @@ class GLGizmoMove3D : public GLGizmoBase
Vec3d m_position;
Vec3d m_starting_drag_position;
Vec3d m_starting_box_center;
Vec3d m_starting_box_bottom_center;
public:
explicit GLGizmoMove3D(GLCanvas3D& parent);
@ -302,7 +303,7 @@ protected:
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
private:
double calc_displacement(unsigned int preferred_plane_id, const Linef3& mouse_ray) const;
double calc_projection(Axis axis, unsigned int preferred_plane_id, const Linef3& mouse_ray) const;
};
class GLGizmoFlatten : public GLGizmoBase
@ -328,7 +329,11 @@ private:
SourceDataSummary m_source_data;
std::vector<PlaneData> m_planes;
#if ENABLE_MODELINSTANCE_3D_OFFSET
Pointf3s m_instances_positions;
#else
std::vector<Vec2d> m_instances_positions;
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
Vec3d m_starting_center;
const ModelObject* m_model_object = nullptr;

View file

@ -259,6 +259,15 @@ void set_show_print_info(bool show)
void set_show_manifold_warning_icon(bool show)
{
g_show_manifold_warning_icon = show;
if (!g_manifold_warning_icon)
return;
// update manifold_warning_icon showing
if (show && !g_info_sizer->IsShown(static_cast<size_t>(0)))
g_show_manifold_warning_icon = false;
g_manifold_warning_icon->Show(g_show_manifold_warning_icon);
g_manifold_warning_icon->GetParent()->Layout();
}
void set_objects_list_sizer(wxBoxSizer *objects_list_sizer){
@ -1118,11 +1127,11 @@ void show_buttons(bool show)
}
}
void show_info_sizer(const bool show, const bool is_update_settings/* = false*/)
void show_info_sizer(const bool show)
{
g_info_sizer->Show(static_cast<size_t>(0), show);
g_info_sizer->Show(1, show && g_show_print_info);
g_manifold_warning_icon->Show(show && (!is_update_settings && g_show_manifold_warning_icon));
g_manifold_warning_icon->Show(show && g_show_manifold_warning_icon);
}
void show_object_name(bool show)
@ -1142,6 +1151,7 @@ void update_mode()
show_info_sizer(mode == ConfigMenuModeExpert);
show_buttons(mode == ConfigMenuModeExpert);
show_object_name(mode == ConfigMenuModeSimple);
show_manipulation_sizer(mode == ConfigMenuModeSimple);
// TODO There is a not the best place of it!
// *** Update showing of the collpane_settings

View file

@ -182,7 +182,7 @@ bool select_language(wxArrayString & names, wxArrayLong & identifiers);
// update right panel of the Plater according to view mode
void update_mode();
void show_info_sizer(const bool show, const bool is_update_settinfs = false);
void show_info_sizer(const bool show);
std::vector<Tab *>& get_tabs_list();
bool checked_tab(Tab* tab);

View file

@ -731,11 +731,8 @@ void select_current_object(int idx)
{
g_prevent_list_events = true;
m_objects_ctrl->UnselectAll();
if (idx < 0) {
g_prevent_list_events = false;
return;
}
m_objects_ctrl->Select(m_objects_model->GetItemById(idx));
if (idx>=0)
m_objects_ctrl->Select(m_objects_model->GetItemById(idx));
part_selection_changed();
g_prevent_list_events = false;
}
@ -748,12 +745,8 @@ void select_current_volume(int idx, int vol_idx)
}
g_prevent_list_events = true;
m_objects_ctrl->UnselectAll();
if (idx < 0) {
g_prevent_list_events = false;
return;
}
m_objects_ctrl->Select(m_objects_model->GetItemByVolumeId(idx, vol_idx));
if (idx >= 0)
m_objects_ctrl->Select(m_objects_model->GetItemByVolumeId(idx, vol_idx));
part_selection_changed();
g_prevent_list_events = false;
}
@ -1186,8 +1179,8 @@ wxMenu *create_add_settings_popupmenu(bool is_part)
menu->Append(menu_item);
}
#ifndef __WXMSW__
menu->Bind(wxEVT_MENU, [menu](wxEvent &event) {
get_settings_choice(menu, event.GetId(), true);
menu->Bind(wxEVT_MENU, [menu,is_part](wxEvent &event) {
get_settings_choice(menu, event.GetId(), is_part);
});
#endif //no __WXMSW__
return menu;
@ -1771,9 +1764,15 @@ void update_position_values()
auto og = get_optgroup(ogFrequentlyObjectSettings);
auto instance = (*m_objects)[m_selected_object_id]->instances.front();
#if ENABLE_MODELINSTANCE_3D_OFFSET
og->set_value("position_x", int(instance->get_offset(X)));
og->set_value("position_y", int(instance->get_offset(Y)));
og->set_value("position_z", int(instance->get_offset(Z)));
#else
og->set_value("position_x", int(instance->offset(0)));
og->set_value("position_y", int(instance->offset(1)));
og->set_value("position_z", 0);
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
}
void update_position_values(const Vec3d& position)
@ -2027,5 +2026,17 @@ void update_double_slider_from_canvas(wxKeyEvent& event)
event.Skip();
}
void show_manipulation_sizer(const bool is_simple_mode)
{
auto item = m_objects_ctrl->GetSelection();
if (!item || !is_simple_mode)
return;
if (m_objects_model->IsSettingsItem(item)) {
m_objects_ctrl->Select(m_objects_model->GetParent(item));
part_selection_changed();
}
}
} //namespace GUI
} //namespace Slic3r

View file

@ -140,6 +140,8 @@ void reset_double_slider();
// update DoubleSlider after keyDown in canvas
void update_double_slider_from_canvas(wxKeyEvent& event);
void show_manipulation_sizer(const bool is_simple_mode);
} //namespace GUI
} //namespace Slic3r
#endif //slic3r_GUI_ObjectParts_hpp_