OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::GLSelectionRectangle Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLSelectionRectangle.hpp>

Collaboration diagram for Slic3r::GUI::GLSelectionRectangle:

Public Types

enum  EState { Off , Select , Deselect }

Public Member Functions

void start_dragging (const Vec2d &mouse_position, EState state)
void dragging (const Vec2d &mouse_position)
std::vector< unsigned int > contains (const std::vector< Vec3d > &points) const
void stop_dragging ()
void render (const GLCanvas3D &canvas)
bool is_dragging () const
EState get_state () const
float get_width () const
float get_height () const
float get_left () const
float get_right () const
float get_top () const
float get_bottom () const

Private Attributes

EState m_state { Off }
Vec2d m_start_corner { Vec2d::Zero() }
Vec2d m_end_corner { Vec2d::Zero() }
GLModel m_rectangle
Vec2d m_old_start_corner { Vec2d::Zero() }
Vec2d m_old_end_corner { Vec2d::Zero() }

Detailed Description

Member Enumeration Documentation

◆ EState

Enumerator
Off 
Select 
Deselect 
18 {
19 Off,
20 Select,
22 };
@ Select
Definition GLSelectionRectangle.hpp:20
@ Deselect
Definition GLSelectionRectangle.hpp:21
@ Off
Definition GLSelectionRectangle.hpp:19

Member Function Documentation

◆ contains()

std::vector< unsigned int > Slic3r::GUI::GLSelectionRectangle::contains ( const std::vector< Vec3d > & points) const
44 {
45 std::vector<unsigned int> out;
46
47 // bounding box created from the rectangle corners - will take care of order of the corners
48 const BoundingBox rectangle(Points{ Point(m_start_corner.cast<coord_t>()), Point(m_end_corner.cast<coord_t>()) });
49
50 // Iterate over all points and determine whether they're in the rectangle.
51 const Camera &camera = wxGetApp().plater()->get_camera();
52 Points points_2d = CameraUtils::project(camera, points);
53 unsigned int size = static_cast<unsigned int>(points.size());
54 for (unsigned int i = 0; i< size; ++i)
55 if (rectangle.contains(points_2d[i]))
56 out.push_back(i);
57
58 return out;
59 }
static Points project(const Camera &camera, const std::vector< Vec3d > &points)
Project point throw camera to 2d coordinate into imgui window.
Definition CameraUtils.cpp:23
Vec2d m_start_corner
Definition GLSelectionRectangle.hpp:51
Vec2d m_end_corner
Definition GLSelectionRectangle.hpp:52
int64_t coord_t
Definition libslic3r.h:48
@ Camera
Definition Shortcuts.hpp:72
Kernel::Point_3 Point
Definition MeshRepair.cpp:81
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:73

References m_end_corner, m_start_corner, and Slic3r::GUI::CameraUtils::project().

Here is the call graph for this function:

◆ dragging()

void Slic3r::GUI::GLSelectionRectangle::dragging ( const Vec2d & mouse_position)
36 {
37 if (!is_dragging())
38 return;
39
41 }
bool is_dragging() const
Definition GLSelectionRectangle.hpp:39
Vec2d mouse_position(const wxMouseEvent &mouse_event)
Extract position of mouse from mouse event.
Definition SurfaceDrag.cpp:502

References is_dragging(), and m_end_corner.

Here is the call graph for this function:

◆ get_bottom()

float Slic3r::GUI::GLSelectionRectangle::get_bottom ( ) const
inline
47{ return std::min(m_start_corner.y(), m_end_corner.y()); }

References m_end_corner, and m_start_corner.

Referenced by render().

Here is the caller graph for this function:

◆ get_height()

float Slic3r::GUI::GLSelectionRectangle::get_height ( ) const
inline
43{ return std::abs(m_start_corner.y() - m_end_corner.y()); }

References m_end_corner, and m_start_corner.

◆ get_left()

float Slic3r::GUI::GLSelectionRectangle::get_left ( ) const
inline
44{ return std::min(m_start_corner.x(), m_end_corner.x()); }

References m_end_corner, and m_start_corner.

Referenced by render().

Here is the caller graph for this function:

◆ get_right()

float Slic3r::GUI::GLSelectionRectangle::get_right ( ) const
inline
45{ return std::max(m_start_corner.x(), m_end_corner.x()); }

References m_end_corner, and m_start_corner.

Referenced by render().

Here is the caller graph for this function:

◆ get_state()

EState Slic3r::GUI::GLSelectionRectangle::get_state ( ) const
inline
40{ return m_state; }
EState m_state
Definition GLSelectionRectangle.hpp:50

References m_state.

◆ get_top()

float Slic3r::GUI::GLSelectionRectangle::get_top ( ) const
inline
46{ return std::max(m_start_corner.y(), m_end_corner.y()); }

References m_end_corner, and m_start_corner.

Referenced by render().

Here is the caller graph for this function:

◆ get_width()

float Slic3r::GUI::GLSelectionRectangle::get_width ( ) const
inline
42{ return std::abs(m_start_corner.x() - m_end_corner.x()); }

References m_end_corner, and m_start_corner.

◆ is_dragging()

bool Slic3r::GUI::GLSelectionRectangle::is_dragging ( ) const
inline
39{ return m_state != Off; }

References m_state, and Off.

Referenced by dragging(), render(), start_dragging(), and stop_dragging().

Here is the caller graph for this function:

◆ render()

void Slic3r::GUI::GLSelectionRectangle::render ( const GLCanvas3D & canvas)
68 {
69 if (!is_dragging())
70 return;
71
72 const Size cnv_size = canvas.get_canvas_size();
73 const float cnv_width = (float)cnv_size.get_width();
74 const float cnv_height = (float)cnv_size.get_height();
75 if (cnv_width == 0.0f || cnv_height == 0.0f)
76 return;
77
78 const float cnv_inv_width = 1.0f / cnv_width;
79 const float cnv_inv_height = 1.0f / cnv_height;
80 const float left = 2.0f * (get_left() * cnv_inv_width - 0.5f);
81 const float right = 2.0f * (get_right() * cnv_inv_width - 0.5f);
82 const float top = -2.0f * (get_top() * cnv_inv_height - 0.5f);
83 const float bottom = -2.0f * (get_bottom() * cnv_inv_height - 0.5f);
84
85#if !SLIC3R_OPENGL_ES
86 if (!OpenGLManager::get_gl_info().is_core_profile())
87 glsafe(::glLineWidth(1.5f));
88#endif // !SLIC3R_OPENGL_ES
89
91
92#if !SLIC3R_OPENGL_ES
93 if (!OpenGLManager::get_gl_info().is_core_profile()) {
95 glsafe(::glLineStipple(4, 0xAAAA));
97 }
98#endif // !SLIC3R_OPENGL_ES
99
100#if SLIC3R_OPENGL_ES
101 GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines");
102#else
103 GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
104#endif // SLIC3R_OPENGL_ES
105 if (shader != nullptr) {
106 shader->start_using();
107
108 if (!m_rectangle.is_initialized() || !m_old_start_corner.isApprox(m_start_corner) || !m_old_end_corner.isApprox(m_end_corner)) {
111 m_rectangle.reset();
112
113 GLModel::Geometry init_data;
114#if !SLIC3R_OPENGL_ES
115 if (OpenGLManager::get_gl_info().is_core_profile()) {
116#endif // !SLIC3R_OPENGL_ES
118 init_data.reserve_vertices(5);
119 init_data.reserve_indices(8);
120#if !SLIC3R_OPENGL_ES
121 }
122 else {
124 init_data.reserve_vertices(4);
125 init_data.reserve_indices(4);
126 }
127#endif // !SLIC3R_OPENGL_ES
128
129 // vertices
130#if !SLIC3R_OPENGL_ES
131 if (OpenGLManager::get_gl_info().is_core_profile()) {
132#endif // !SLIC3R_OPENGL_ES
133 const float width = right - left;
134 const float height = top - bottom;
135 float perimeter = 0.0f;
136
137 init_data.add_vertex(Vec4f(left, bottom, 0.0f, perimeter));
138 perimeter += width;
139 init_data.add_vertex(Vec4f(right, bottom, 0.0f, perimeter));
140 perimeter += height;
141 init_data.add_vertex(Vec4f(right, top, 0.0f, perimeter));
142 perimeter += width;
143 init_data.add_vertex(Vec4f(left, top, 0.0f, perimeter));
144 perimeter += height;
145 init_data.add_vertex(Vec4f(left, bottom, 0.0f, perimeter));
146
147 // indices
148 init_data.add_line(0, 1);
149 init_data.add_line(1, 2);
150 init_data.add_line(2, 3);
151 init_data.add_line(3, 4);
152#if !SLIC3R_OPENGL_ES
153 }
154 else {
155 init_data.add_vertex(Vec2f(left, bottom));
156 init_data.add_vertex(Vec2f(right, bottom));
157 init_data.add_vertex(Vec2f(right, top));
158 init_data.add_vertex(Vec2f(left, top));
159
160 // indices
161 init_data.add_index(0);
162 init_data.add_index(1);
163 init_data.add_index(2);
164 init_data.add_index(3);
165 }
166#endif // !SLIC3R_OPENGL_ES
167
168 m_rectangle.init_from(std::move(init_data));
169 }
170
171 shader->set_uniform("view_model_matrix", Transform3d::Identity());
172 shader->set_uniform("projection_matrix", Transform3d::Identity());
173#if !SLIC3R_OPENGL_ES
174 if (OpenGLManager::get_gl_info().is_core_profile()) {
175#endif // !SLIC3R_OPENGL_ES
176 const std::array<int, 4>& viewport = wxGetApp().plater()->get_camera().get_viewport();
177 shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3])));
178 shader->set_uniform("width", 0.25f);
179 shader->set_uniform("dash_size", 0.01f);
180 shader->set_uniform("gap_size", 0.0075f);
181#if !SLIC3R_OPENGL_ES
182 }
183#endif // !SLIC3R_OPENGL_ES
184
185 m_rectangle.set_color(ColorRGBA::ORCA()); // ORCA: use orca color for selection rectangle
186 m_rectangle.render();
187 shader->stop_using();
188 }
189
190#if !SLIC3R_OPENGL_ES
191 if (!OpenGLManager::get_gl_info().is_core_profile())
193#endif // !SLIC3R_OPENGL_ES
194 }
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
static const ColorRGBA ORCA()
Definition Color.hpp:143
float get_right() const
Definition GLSelectionRectangle.hpp:45
Vec2d m_old_start_corner
Definition GLSelectionRectangle.hpp:54
GLModel m_rectangle
Definition GLSelectionRectangle.hpp:53
float get_bottom() const
Definition GLSelectionRectangle.hpp:47
float get_left() const
Definition GLSelectionRectangle.hpp:44
float get_top() const
Definition GLSelectionRectangle.hpp:46
Vec2d m_old_end_corner
Definition GLSelectionRectangle.hpp:55
bool is_core_profile() const
Definition OpenGLManager.hpp:53
static const GLInfo & get_gl_info()
Definition OpenGLManager.hpp:106
#define glEnable
Definition gl.h:3667
#define GL_DEPTH_TEST
Definition gl.h:574
#define GL_LINE_STIPPLE
Definition gl.h:941
#define GL_ENABLE_BIT
Definition gl.h:639
#define glLineStipple
Definition gl.h:4213
#define glPopAttrib
Definition gl.h:4477
#define glLineWidth
Definition gl.h:4215
#define glPushAttrib
Definition gl.h:4597
#define glDisable
Definition gl.h:3607
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185
Eigen::Matrix< float, 4, 1, Eigen::DontAlign > Vec4f
Definition Point.hpp:66
Eigen::Matrix< float, 2, 1, Eigen::DontAlign > Vec2f
Definition Point.hpp:64
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67
@ right
Definition MarchingSquares.hpp:190
@ left
Definition MarchingSquares.hpp:188

References Slic3r::GUI::GLModel::Geometry::add_index(), Slic3r::GUI::GLModel::Geometry::add_line(), Slic3r::GUI::GLModel::Geometry::add_vertex(), Slic3r::GUI::GLModel::Geometry::format, get_bottom(), Slic3r::GUI::GLCanvas3D::get_canvas_size(), Slic3r::GUI::OpenGLManager::get_gl_info(), Slic3r::GUI::Size::get_height(), get_left(), get_right(), get_top(), Slic3r::GUI::Size::get_width(), GL_DEPTH_TEST, GL_ENABLE_BIT, GL_LINE_STIPPLE, glDisable, glEnable, glLineStipple, glLineWidth, glPopAttrib, glPushAttrib, glsafe, Slic3r::GUI::OpenGLManager::GLInfo::is_core_profile(), is_dragging(), Slic3r::GUI::GLModel::Geometry::LineLoop, Slic3r::GUI::GLModel::Geometry::Lines, m_end_corner, m_old_end_corner, m_old_start_corner, m_rectangle, m_start_corner, Slic3r::ColorRGBA::ORCA(), Slic3r::GUI::GLModel::Geometry::P2, Slic3r::GUI::GLModel::Geometry::P4, Slic3r::GUI::GLModel::Geometry::reserve_indices(), Slic3r::GUI::GLModel::Geometry::reserve_vertices(), Slic3r::GLShaderProgram::set_uniform(), Slic3r::GLShaderProgram::start_using(), and Slic3r::GLShaderProgram::stop_using().

Here is the call graph for this function:

◆ start_dragging()

void Slic3r::GUI::GLSelectionRectangle::start_dragging ( const Vec2d & mouse_position,
EState state )
26 {
27 if (is_dragging() || (state == Off))
28 return;
29
30 m_state = state;
33 }

References is_dragging(), m_end_corner, m_start_corner, m_state, and Off.

Here is the call graph for this function:

◆ stop_dragging()

void Slic3r::GUI::GLSelectionRectangle::stop_dragging ( )
62 {
63 if (is_dragging())
64 m_state = Off;
65 }

References is_dragging(), m_state, and Off.

Here is the call graph for this function:

Member Data Documentation

◆ m_end_corner

Vec2d Slic3r::GUI::GLSelectionRectangle::m_end_corner { Vec2d::Zero() }
private

◆ m_old_end_corner

Vec2d Slic3r::GUI::GLSelectionRectangle::m_old_end_corner { Vec2d::Zero() }
private
55{ Vec2d::Zero() };

Referenced by render().

◆ m_old_start_corner

Vec2d Slic3r::GUI::GLSelectionRectangle::m_old_start_corner { Vec2d::Zero() }
private
54{ Vec2d::Zero() };

Referenced by render().

◆ m_rectangle

GLModel Slic3r::GUI::GLSelectionRectangle::m_rectangle
private

Referenced by render().

◆ m_start_corner

Vec2d Slic3r::GUI::GLSelectionRectangle::m_start_corner { Vec2d::Zero() }
private

◆ m_state

EState Slic3r::GUI::GLSelectionRectangle::m_state { Off }
private

The documentation for this class was generated from the following files: