mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-21 05:37:52 -06:00
open simplification on center when open from notification
This commit is contained in:
parent
7e2691241b
commit
76c0c76f5f
3 changed files with 84 additions and 53 deletions
|
@ -24,6 +24,7 @@ GLGizmoSimplify::GLGizmoSimplify(GLCanvas3D & parent,
|
|||
, m_obj_index(0)
|
||||
, m_need_reload(false)
|
||||
, m_show_wireframe(false)
|
||||
, m_move_to_center(false)
|
||||
// translation for GUI size
|
||||
, tr_mesh_name(_u8L("Mesh name"))
|
||||
, tr_triangles(_u8L("Triangles"))
|
||||
|
@ -50,6 +51,61 @@ bool GLGizmoSimplify::on_esc_key_down() {
|
|||
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
|
||||
{
|
||||
return _u8L("Simplify");
|
||||
|
@ -92,7 +148,15 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
|
|||
m_exist_preview = false;
|
||||
init_wireframe();
|
||||
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();
|
||||
pos.x -= m_gui_cfg->window_offset_x;
|
||||
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) {
|
||||
auto objs = wxGetApp().plater()->model().objects;
|
||||
for (const auto &obj : objs) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue