open simplification on center when open from notification
This commit is contained in:
parent
7e2691241b
commit
76c0c76f5f
@ -24,6 +24,7 @@ GLGizmoSimplify::GLGizmoSimplify(GLCanvas3D & parent,
|
|||||||
, m_obj_index(0)
|
, m_obj_index(0)
|
||||||
, m_need_reload(false)
|
, m_need_reload(false)
|
||||||
, m_show_wireframe(false)
|
, m_show_wireframe(false)
|
||||||
|
, m_move_to_center(false)
|
||||||
// translation for GUI size
|
// translation for GUI size
|
||||||
, tr_mesh_name(_u8L("Mesh name"))
|
, tr_mesh_name(_u8L("Mesh name"))
|
||||||
, tr_triangles(_u8L("Triangles"))
|
, tr_triangles(_u8L("Triangles"))
|
||||||
@ -50,6 +51,61 @@ bool GLGizmoSimplify::on_esc_key_down() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// while opening needs GLGizmoSimplify to set window position
|
||||||
|
void GLGizmoSimplify::add_simplify_suggestion_notification(
|
||||||
|
const std::vector<size_t> &object_ids,
|
||||||
|
const ModelObjectPtrs & objects,
|
||||||
|
NotificationManager & manager)
|
||||||
|
{
|
||||||
|
std::vector<size_t> big_ids;
|
||||||
|
big_ids.reserve(object_ids.size());
|
||||||
|
auto is_big_object = [&objects](size_t object_id) {
|
||||||
|
const uint32_t triangles_to_suggest_simplify = 1000000;
|
||||||
|
if (object_id >= objects.size()) return false; // out of object index
|
||||||
|
ModelVolumePtrs &volumes = objects[object_id]->volumes;
|
||||||
|
if (volumes.size() != 1) return false; // not only one volume
|
||||||
|
size_t triangle_count = volumes.front()->mesh().its.indices.size();
|
||||||
|
if (triangle_count < triangles_to_suggest_simplify)
|
||||||
|
return false; // small volume
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
std::copy_if(object_ids.begin(), object_ids.end(),
|
||||||
|
std::back_inserter(big_ids), is_big_object);
|
||||||
|
if (big_ids.empty()) return;
|
||||||
|
|
||||||
|
for (size_t object_id : big_ids) {
|
||||||
|
std::string t = _u8L(
|
||||||
|
"Processing model '@object_name' with more than 1M triangles "
|
||||||
|
"could be slow. It is highly recommend to reduce "
|
||||||
|
"amount of triangles.");
|
||||||
|
t.replace(t.find("@object_name"), sizeof("@object_name") - 1,
|
||||||
|
objects[object_id]->name);
|
||||||
|
// std::stringstream text;
|
||||||
|
// text << t << "\n";
|
||||||
|
std::string hypertext = _u8L("Simplify model");
|
||||||
|
|
||||||
|
std::function<bool(wxEvtHandler *)> open_simplify =
|
||||||
|
[object_id](wxEvtHandler *) {
|
||||||
|
auto plater = wxGetApp().plater();
|
||||||
|
if (object_id >= plater->model().objects.size()) return true;
|
||||||
|
|
||||||
|
Selection &selection = plater->canvas3D()->get_selection();
|
||||||
|
selection.clear();
|
||||||
|
selection.add_object((unsigned int) object_id);
|
||||||
|
|
||||||
|
auto &manager = plater->canvas3D()->get_gizmos_manager();
|
||||||
|
bool close_notification = true;
|
||||||
|
if(!manager.open_gizmo(GLGizmosManager::Simplify))
|
||||||
|
return close_notification;
|
||||||
|
GLGizmoSimplify* simplify = dynamic_cast<GLGizmoSimplify*>(manager.get_current());
|
||||||
|
if (simplify == nullptr) return close_notification;
|
||||||
|
simplify->set_center_position();
|
||||||
|
};
|
||||||
|
manager.push_simplify_suggestion_notification(
|
||||||
|
t, objects[object_id]->id(), hypertext, open_simplify);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string GLGizmoSimplify::on_get_name() const
|
std::string GLGizmoSimplify::on_get_name() const
|
||||||
{
|
{
|
||||||
return _u8L("Simplify");
|
return _u8L("Simplify");
|
||||||
@ -92,7 +148,15 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
|
|||||||
m_exist_preview = false;
|
m_exist_preview = false;
|
||||||
init_wireframe();
|
init_wireframe();
|
||||||
live_preview();
|
live_preview();
|
||||||
if (change_window_position) {
|
|
||||||
|
// set window position
|
||||||
|
if (m_move_to_center && change_window_position) {
|
||||||
|
m_move_to_center = false;
|
||||||
|
auto parent_size = m_parent.get_canvas_size();
|
||||||
|
ImVec2 pos(parent_size.get_width() / 2 - m_gui_cfg->window_offset_x,
|
||||||
|
parent_size.get_height() / 2 - m_gui_cfg->window_offset_y);
|
||||||
|
ImGui::SetNextWindowPos(pos, ImGuiCond_Always);
|
||||||
|
}else if (change_window_position) {
|
||||||
ImVec2 pos = ImGui::GetMousePos();
|
ImVec2 pos = ImGui::GetMousePos();
|
||||||
pos.x -= m_gui_cfg->window_offset_x;
|
pos.x -= m_gui_cfg->window_offset_x;
|
||||||
pos.y -= m_gui_cfg->window_offset_y;
|
pos.y -= m_gui_cfg->window_offset_y;
|
||||||
@ -474,6 +538,10 @@ void GLGizmoSimplify::request_rerender() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLGizmoSimplify::set_center_position() {
|
||||||
|
m_move_to_center = true;
|
||||||
|
}
|
||||||
|
|
||||||
bool GLGizmoSimplify::exist_volume(ModelVolume *volume) {
|
bool GLGizmoSimplify::exist_volume(ModelVolume *volume) {
|
||||||
auto objs = wxGetApp().plater()->model().objects;
|
auto objs = wxGetApp().plater()->model().objects;
|
||||||
for (const auto &obj : objs) {
|
for (const auto &obj : objs) {
|
||||||
|
@ -15,12 +15,14 @@
|
|||||||
|
|
||||||
#include <GL/glew.h> // GLUint
|
#include <GL/glew.h> // GLUint
|
||||||
|
|
||||||
namespace Slic3r {
|
// for simplify suggestion
|
||||||
|
class ModelObjectPtrs; // std::vector<ModelObject*>
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
class ModelVolume;
|
class ModelVolume;
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
class NotificationManager; // for simplify suggestion
|
||||||
|
|
||||||
class GLGizmoSimplify: public GLGizmoBase, public GLGizmoTransparentRender // GLGizmoBase
|
class GLGizmoSimplify: public GLGizmoBase, public GLGizmoTransparentRender // GLGizmoBase
|
||||||
{
|
{
|
||||||
@ -28,6 +30,10 @@ public:
|
|||||||
GLGizmoSimplify(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
|
GLGizmoSimplify(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
|
||||||
virtual ~GLGizmoSimplify();
|
virtual ~GLGizmoSimplify();
|
||||||
bool on_esc_key_down();
|
bool on_esc_key_down();
|
||||||
|
static void add_simplify_suggestion_notification(
|
||||||
|
const std::vector<size_t> &object_ids,
|
||||||
|
const ModelObjectPtrs & objects,
|
||||||
|
NotificationManager & manager);
|
||||||
protected:
|
protected:
|
||||||
virtual std::string on_get_name() const override;
|
virtual std::string on_get_name() const override;
|
||||||
virtual void on_render_input_window(float x, float y, float bottom_limit) override;
|
virtual void on_render_input_window(float x, float y, float bottom_limit) override;
|
||||||
@ -51,6 +57,7 @@ private:
|
|||||||
void create_gui_cfg();
|
void create_gui_cfg();
|
||||||
void request_rerender();
|
void request_rerender();
|
||||||
|
|
||||||
|
void set_center_position();
|
||||||
// move to global functions
|
// move to global functions
|
||||||
static ModelVolume *get_volume(const Selection &selection, Model &model);
|
static ModelVolume *get_volume(const Selection &selection, Model &model);
|
||||||
static const ModelVolume *get_volume(const GLVolume::CompositeID &cid, const Model &model);
|
static const ModelVolume *get_volume(const GLVolume::CompositeID &cid, const Model &model);
|
||||||
@ -61,6 +68,8 @@ private:
|
|||||||
std::atomic_bool m_is_valid_result; // differ what to do in apply
|
std::atomic_bool m_is_valid_result; // differ what to do in apply
|
||||||
std::atomic_bool m_exist_preview; // set when process end
|
std::atomic_bool m_exist_preview; // set when process end
|
||||||
|
|
||||||
|
bool m_move_to_center; // opening gizmo
|
||||||
|
|
||||||
volatile int m_progress; // percent of done work
|
volatile int m_progress; // percent of done work
|
||||||
ModelVolume *m_volume; // keep pointer to actual working volume
|
ModelVolume *m_volume; // keep pointer to actual working volume
|
||||||
size_t m_obj_index;
|
size_t m_obj_index;
|
||||||
|
@ -89,6 +89,7 @@
|
|||||||
#include "PresetComboBoxes.hpp"
|
#include "PresetComboBoxes.hpp"
|
||||||
#include "MsgDialog.hpp"
|
#include "MsgDialog.hpp"
|
||||||
#include "ProjectDirtyStateManager.hpp"
|
#include "ProjectDirtyStateManager.hpp"
|
||||||
|
#include "Gizmos/GLGizmoSimplify.hpp" // create suggestion notification
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "Gizmos/GLGizmosManager.hpp"
|
#include "Gizmos/GLGizmosManager.hpp"
|
||||||
@ -1779,7 +1780,6 @@ struct Plater::priv
|
|||||||
#endif // ENABLE_RELOAD_FROM_DISK_REPLACE_FILE
|
#endif // ENABLE_RELOAD_FROM_DISK_REPLACE_FILE
|
||||||
void replace_with_stl();
|
void replace_with_stl();
|
||||||
void reload_all_from_disk();
|
void reload_all_from_disk();
|
||||||
void create_simplify_notification(const std::vector<size_t>& obj_ids);
|
|
||||||
void set_current_panel(wxPanel* panel);
|
void set_current_panel(wxPanel* panel);
|
||||||
|
|
||||||
void on_select_preset(wxCommandEvent&);
|
void on_select_preset(wxCommandEvent&);
|
||||||
@ -2564,8 +2564,9 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||||||
// this is required because the selected object changed and the flatten on face an sla support gizmos need to be updated accordingly
|
// this is required because the selected object changed and the flatten on face an sla support gizmos need to be updated accordingly
|
||||||
view3D->get_canvas3d()->update_gizmos_on_off_state();
|
view3D->get_canvas3d()->update_gizmos_on_off_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
create_simplify_notification(obj_idxs);
|
GLGizmoSimplify::add_simplify_suggestion_notification(
|
||||||
|
obj_idxs, model.objects, *notification_manager);
|
||||||
|
|
||||||
return obj_idxs;
|
return obj_idxs;
|
||||||
}
|
}
|
||||||
@ -3755,53 +3756,6 @@ void Plater::priv::reload_all_from_disk()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plater::priv::create_simplify_notification(const std::vector<size_t>& obj_ids) {
|
|
||||||
const uint32_t triangles_to_suggest_simplify = 1000000;
|
|
||||||
|
|
||||||
std::vector<size_t> big_ids;
|
|
||||||
big_ids.reserve(obj_ids.size());
|
|
||||||
std::copy_if(obj_ids.begin(), obj_ids.end(), std::back_inserter(big_ids),
|
|
||||||
[this, triangles_to_suggest_simplify](size_t object_id) {
|
|
||||||
if (object_id >= model.objects.size()) return false; // out of object index
|
|
||||||
ModelVolumePtrs& volumes = model.objects[object_id]->volumes;
|
|
||||||
if (volumes.size() != 1) return false; // not only one volume
|
|
||||||
size_t triangle_count = volumes.front()->mesh().its.indices.size();
|
|
||||||
if (triangle_count < triangles_to_suggest_simplify) return false; // small volume
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (big_ids.empty()) return;
|
|
||||||
|
|
||||||
for (size_t object_id : big_ids) {
|
|
||||||
std::string t = _u8L(
|
|
||||||
"Processing model '@object_name' with more than 1M triangles "
|
|
||||||
"could be slow. It is highly recommend to reduce "
|
|
||||||
"amount of triangles.");
|
|
||||||
t.replace(t.find("@object_name"), sizeof("@object_name") - 1,
|
|
||||||
model.objects[object_id]->name);
|
|
||||||
//std::stringstream text;
|
|
||||||
//text << t << "\n";
|
|
||||||
std::string hypertext = _u8L("Simplify model");
|
|
||||||
|
|
||||||
std::function<bool(wxEvtHandler *)> open_simplify = [object_id](wxEvtHandler *) {
|
|
||||||
auto plater = wxGetApp().plater();
|
|
||||||
if (object_id >= plater->model().objects.size()) return true;
|
|
||||||
|
|
||||||
Selection &selection = plater->canvas3D()->get_selection();
|
|
||||||
selection.clear();
|
|
||||||
selection.add_object((unsigned int) object_id);
|
|
||||||
|
|
||||||
auto &manager = plater->canvas3D()->get_gizmos_manager();
|
|
||||||
manager.open_gizmo(GLGizmosManager::EType::Simplify);
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
notification_manager->push_simplify_suggestion_notification(t,
|
|
||||||
model.objects[object_id]->id(),
|
|
||||||
hypertext,
|
|
||||||
open_simplify);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Plater::priv::set_current_panel(wxPanel* panel)
|
void Plater::priv::set_current_panel(wxPanel* panel)
|
||||||
{
|
{
|
||||||
if (std::find(panels.begin(), panels.end(), panel) == panels.end())
|
if (std::find(panels.begin(), panels.end(), panel) == panels.end())
|
||||||
|
Loading…
Reference in New Issue
Block a user