OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::GLCanvas3D::Labels Class Reference
Collaboration diagram for Slic3r::GUI::GLCanvas3D::Labels:

Public Member Functions

 Labels (GLCanvas3D &canvas)
void enable (bool enable)
void show (bool show)
bool is_shown () const
void render (const std::vector< const ModelInstance * > &sorted_instances) const

Private Attributes

bool m_enabled { false }
bool m_shown { false }
GLCanvas3D & m_canvas

Detailed Description

Constructor & Destructor Documentation

◆ Labels()

Slic3r::GUI::GLCanvas3D::Labels::Labels ( GLCanvas3D & canvas)
inlineexplicit
477: m_canvas(canvas) {}
GLCanvas3D & m_canvas
Definition GLCanvas3D.hpp:474

References Slic3r::GUI::GLCanvas3D::GLCanvas3D(), and m_canvas.

Here is the call graph for this function:

Member Function Documentation

◆ enable()

void Slic3r::GUI::GLCanvas3D::Labels::enable ( bool enable)
inline
478{ m_enabled = enable; }
bool m_enabled
Definition GLCanvas3D.hpp:472
void enable(bool enable)
Definition GLCanvas3D.hpp:478

References enable(), and m_enabled.

Referenced by enable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_shown()

bool Slic3r::GUI::GLCanvas3D::Labels::is_shown ( ) const
inline
480{ return m_shown; }
bool m_shown
Definition GLCanvas3D.hpp:473

References m_shown.

Referenced by render().

Here is the caller graph for this function:

◆ render()

void Slic3r::GUI::GLCanvas3D::Labels::render ( const std::vector< const ModelInstance * > & sorted_instances) const
879{
880 if (!m_enabled || !is_shown() || m_canvas.get_gizmos_manager().is_running())
881 return;
882
883 const Camera& camera = wxGetApp().plater()->get_camera();
884 const Model* model = m_canvas.get_model();
885 if (model == nullptr)
886 return;
887
888 Transform3d world_to_eye = camera.get_view_matrix();
889 Transform3d world_to_screen = camera.get_projection_matrix() * world_to_eye;
890 const std::array<int, 4>& viewport = camera.get_viewport();
891
892 struct Owner
893 {
894 int obj_idx;
895 int inst_idx;
896 size_t model_instance_id;
897 BoundingBoxf3 world_box;
898 double eye_center_z;
899 std::string title;
900 std::string label;
901 std::string print_order;
902 bool selected;
903 };
904
905 // collect owners world bounding boxes and data from volumes
906 std::vector<Owner> owners;
907 const GLVolumeCollection& volumes = m_canvas.get_volumes();
908 PartPlate* cur_plate = wxGetApp().plater()->get_partplate_list().get_curr_plate();
909 for (const GLVolume* volume : volumes.volumes) {
910 int obj_idx = volume->object_idx();
911 if (0 <= obj_idx && obj_idx < (int)model->objects.size()) {
912 int inst_idx = volume->instance_idx();
913 //only show current plate's label
914 if (!cur_plate->contain_instance(obj_idx, inst_idx))
915 continue;
916 std::vector<Owner>::iterator it = std::find_if(owners.begin(), owners.end(), [obj_idx, inst_idx](const Owner& owner) {
917 return (owner.obj_idx == obj_idx) && (owner.inst_idx == inst_idx);
918 });
919 if (it != owners.end()) {
920 it->world_box.merge(volume->transformed_bounding_box());
921 it->selected &= volume->selected;
922 } else {
923 const ModelObject* model_object = model->objects[obj_idx];
924 Owner owner;
925 owner.obj_idx = obj_idx;
926 owner.inst_idx = inst_idx;
927 owner.model_instance_id = model_object->instances[inst_idx]->id().id;
928 owner.world_box = volume->transformed_bounding_box();
929 owner.title = "object" + std::to_string(obj_idx) + "_inst##" + std::to_string(inst_idx);
930 owner.label = model_object->name;
931 if (model_object->instances.size() > 1)
932 owner.label += " (" + std::to_string(inst_idx + 1) + ")";
933 owner.selected = volume->selected;
934 owners.emplace_back(owner);
935 }
936 }
937 }
938
939 // updates print order strings
940 if (sorted_instances.size() > 0) {
941 for (size_t i = 0; i < sorted_instances.size(); ++i) {
942 size_t id = sorted_instances[i]->id().id;
943 std::vector<Owner>::iterator it = std::find_if(owners.begin(), owners.end(), [id](const Owner& owner) {
944 return owner.model_instance_id == id;
945 });
946 if (it != owners.end())
947 //it->print_order = std::string((_(L("Sequence"))).ToUTF8()) + "#: " + std::to_string(i + 1);
948 it->print_order = std::string((_(L("Sequence"))).ToUTF8()) + "#: " + std::to_string(sorted_instances[i]->arrange_order);
949 }
950 }
951
952 // calculate eye bounding boxes center zs
953 for (Owner& owner : owners) {
954 owner.eye_center_z = (world_to_eye * owner.world_box.center())(2);
955 }
956
957 // sort owners by center eye zs and selection
958 std::sort(owners.begin(), owners.end(), [](const Owner& owner1, const Owner& owner2) {
959 if (!owner1.selected && owner2.selected)
960 return true;
961 else if (owner1.selected && !owner2.selected)
962 return false;
963 else
964 return (owner1.eye_center_z < owner2.eye_center_z);
965 });
966
967 ImGuiWrapper& imgui = *wxGetApp().imgui();
968
969 // render info windows
970 for (const Owner& owner : owners) {
971 Vec3d screen_box_center = world_to_screen * owner.world_box.center();
972 float x = 0.0f;
973 float y = 0.0f;
975 x = (0.5f + 0.001f * 0.5f * (float)screen_box_center(0)) * viewport[2];
976 y = (0.5f - 0.001f * 0.5f * (float)screen_box_center(1)) * viewport[3];
977 } else {
978 x = (0.5f + 0.5f * (float)screen_box_center(0)) * viewport[2];
979 y = (0.5f - 0.5f * (float)screen_box_center(1)) * viewport[3];
980 }
981
982 if (x < 0.0f || viewport[2] < x || y < 0.0f || viewport[3] < y)
983 continue;
984
985 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, owner.selected ? 3.0f : 1.5f);
986 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
987 ImGui::PushStyleColor(ImGuiCol_Border, owner.selected ? ImVec4(0.757f, 0.404f, 0.216f, 1.0f) : ImVec4(0.75f, 0.75f, 0.75f, 1.0f));
988 imgui.set_next_window_pos(x, y, ImGuiCond_Always, 0.5f, 0.5f);
989 imgui.begin(owner.title, ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove);
990 ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
991 float win_w = ImGui::GetWindowWidth();
992 ImGui::AlignTextToFramePadding();
993 imgui.text(owner.label);
994
995 if (!owner.print_order.empty()) {
996 ImGui::Separator();
997 float po_len = imgui.calc_text_size(owner.print_order).x;
998 ImGui::SetCursorPosX(0.5f * (win_w - po_len));
999 ImGui::AlignTextToFramePadding();
1000 imgui.text(owner.print_order);
1001 }
1002
1003 // force re-render while the windows gets to its final size (it takes several frames)
1004 if (ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowNextAutoFitSize(ImGui::GetCurrentWindow()).x)
1005 imgui.set_requires_extra_frame();
1006
1007 imgui.end();
1008 ImGui::PopStyleColor();
1009 ImGui::PopStyleVar(2);
1010 }
1011}
#define _(s)
Definition 3mf.cpp:306
#define L(s)
Definition ExtrusionEntity.cpp:25
bool is_shown() const
Definition GLCanvas3D.hpp:480
Camera camera
Definition GLCanvas3D.hpp:794
@ Camera
Definition Shortcuts.hpp:72
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68
Eigen::Transform< double, 3, Eigen::Affine, Eigen::DontAlign > Transform3d
Definition Point.hpp:96
const Transform3d & get_projection_matrix() const
Definition Camera.hpp:116
EType get_type() const
Definition Camera.hpp:83
@ Perspective
Definition Camera.hpp:40
const Transform3d & get_view_matrix() const
Definition Camera.hpp:115
const std::array< int, 4 > & get_viewport() const
Definition Camera.hpp:114

References _, Slic3r::GUI::ImGuiWrapper::begin(), Slic3r::GUI::ImGuiWrapper::calc_text_size(), Slic3r::GUI::GLCanvas3D::camera, Slic3r::GUI::PartPlate::contain_instance(), Slic3r::GUI::ImGuiWrapper::end(), Slic3r::GLVolume::instance_idx(), Slic3r::ModelObject::instances, is_shown(), L, m_canvas, m_enabled, Slic3r::ModelObject::name, Slic3r::GLVolume::object_idx(), Slic3r::Model::objects, Slic3r::GUI::Camera::Perspective, render(), Slic3r::GUI::ImGuiWrapper::set_next_window_pos(), Slic3r::GUI::ImGuiWrapper::set_requires_extra_frame(), Slic3r::GUI::ImGuiWrapper::text(), Slic3r::GLVolume::transformed_bounding_box(), and Slic3r::GLVolumeCollection::volumes.

Referenced by render().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ show()

void Slic3r::GUI::GLCanvas3D::Labels::show ( bool show)
inline
479{ m_shown = m_enabled ? show : false; }
void show(bool show)
Definition GLCanvas3D.hpp:479

References m_enabled, m_shown, and show().

Referenced by show().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_canvas

GLCanvas3D& Slic3r::GUI::GLCanvas3D::Labels::m_canvas
private

Referenced by Labels(), and render().

◆ m_enabled

bool Slic3r::GUI::GLCanvas3D::Labels::m_enabled { false }
private
472{ false };

Referenced by enable(), render(), and show().

◆ m_shown

bool Slic3r::GUI::GLCanvas3D::Labels::m_shown { false }
private
473{ false };

Referenced by is_shown(), and show().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLCanvas3D.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLCanvas3D.cpp