mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-06 07:11:10 +00:00
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes. clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer. * Remove Unused Project Includes From Files With Platform-Specific Code A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block. * Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass The platform-file pass treated pchheader.hpp as an ordinary header and emptied it, and left GUI_Preview.hpp and 14 other files relying on headers they no longer reached directly. * Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call * Include Headers That Files Reached Through Ones the Cleanup Removed * Drop Includes Duplicated by the Cleanup or by Main's Own Additions * Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
198 lines
7.2 KiB
C++
198 lines
7.2 KiB
C++
#include "GLSelectionRectangle.hpp"
|
|
#include "Camera.hpp"
|
|
#include "CameraUtils.hpp"
|
|
#include "3DScene.hpp"
|
|
#include "GLCanvas3D.hpp"
|
|
#include "GUI_App.hpp"
|
|
#include "Plater.hpp"
|
|
#include <array>
|
|
#include <igl/project.h>
|
|
|
|
#include <glad/gl.h>
|
|
#include "libslic3r/Point.hpp"
|
|
#include <vector>
|
|
#include "libslic3r/BoundingBox.hpp"
|
|
#include "libslic3r/libslic3r.h"
|
|
#include "slic3r/GUI/OpenGLManager.hpp"
|
|
#include <utility>
|
|
#include "libslic3r/Color.hpp"
|
|
#include "slic3r/GUI/GLModel.hpp"
|
|
#include "slic3r/GUI/GLShader.hpp"
|
|
|
|
namespace Slic3r {
|
|
namespace GUI {
|
|
|
|
void GLSelectionRectangle::start_dragging(const Vec2d& mouse_position, EState state)
|
|
{
|
|
if (is_dragging() || (state == Off))
|
|
return;
|
|
|
|
m_state = state;
|
|
m_start_corner = mouse_position;
|
|
m_end_corner = mouse_position;
|
|
}
|
|
|
|
void GLSelectionRectangle::dragging(const Vec2d& mouse_position)
|
|
{
|
|
if (!is_dragging())
|
|
return;
|
|
|
|
m_end_corner = mouse_position;
|
|
}
|
|
|
|
std::vector<unsigned int> GLSelectionRectangle::contains(const std::vector<Vec3d>& points) const
|
|
{
|
|
std::vector<unsigned int> out;
|
|
|
|
// bounding box created from the rectangle corners - will take care of order of the corners
|
|
const BoundingBox rectangle(Points{ Point(m_start_corner.cast<coord_t>()), Point(m_end_corner.cast<coord_t>()) });
|
|
|
|
// Iterate over all points and determine whether they're in the rectangle.
|
|
const Camera &camera = wxGetApp().plater()->get_camera();
|
|
Points points_2d = CameraUtils::project(camera, points);
|
|
unsigned int size = static_cast<unsigned int>(points.size());
|
|
for (unsigned int i = 0; i< size; ++i)
|
|
if (rectangle.contains(points_2d[i]))
|
|
out.push_back(i);
|
|
|
|
return out;
|
|
}
|
|
|
|
void GLSelectionRectangle::stop_dragging()
|
|
{
|
|
if (is_dragging())
|
|
m_state = Off;
|
|
}
|
|
|
|
void GLSelectionRectangle::render(const GLCanvas3D& canvas)
|
|
{
|
|
if (!is_dragging())
|
|
return;
|
|
|
|
const Size cnv_size = canvas.get_canvas_size();
|
|
const float cnv_width = (float)cnv_size.get_width();
|
|
const float cnv_height = (float)cnv_size.get_height();
|
|
if (cnv_width == 0.0f || cnv_height == 0.0f)
|
|
return;
|
|
|
|
const float cnv_inv_width = 1.0f / cnv_width;
|
|
const float cnv_inv_height = 1.0f / cnv_height;
|
|
const float left = 2.0f * (get_left() * cnv_inv_width - 0.5f);
|
|
const float right = 2.0f * (get_right() * cnv_inv_width - 0.5f);
|
|
const float top = -2.0f * (get_top() * cnv_inv_height - 0.5f);
|
|
const float bottom = -2.0f * (get_bottom() * cnv_inv_height - 0.5f);
|
|
|
|
#if !SLIC3R_OPENGL_ES
|
|
if (!OpenGLManager::get_gl_info().is_core_profile())
|
|
glsafe(::glLineWidth(1.5f));
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
|
|
glsafe(::glDisable(GL_DEPTH_TEST));
|
|
|
|
#if !SLIC3R_OPENGL_ES
|
|
if (!OpenGLManager::get_gl_info().is_core_profile()) {
|
|
glsafe(::glPushAttrib(GL_ENABLE_BIT));
|
|
glsafe(::glLineStipple(4, 0xAAAA));
|
|
glsafe(::glEnable(GL_LINE_STIPPLE));
|
|
}
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
|
|
#if SLIC3R_OPENGL_ES
|
|
GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines");
|
|
#else
|
|
GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
|
|
#endif // SLIC3R_OPENGL_ES
|
|
if (shader != nullptr) {
|
|
shader->start_using();
|
|
|
|
if (!m_rectangle.is_initialized() || !m_old_start_corner.isApprox(m_start_corner) || !m_old_end_corner.isApprox(m_end_corner)) {
|
|
m_old_start_corner = m_start_corner;
|
|
m_old_end_corner = m_end_corner;
|
|
m_rectangle.reset();
|
|
|
|
GLModel::Geometry init_data;
|
|
#if !SLIC3R_OPENGL_ES
|
|
if (OpenGLManager::get_gl_info().is_core_profile()) {
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P4 };
|
|
init_data.reserve_vertices(5);
|
|
init_data.reserve_indices(8);
|
|
#if !SLIC3R_OPENGL_ES
|
|
}
|
|
else {
|
|
init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 };
|
|
init_data.reserve_vertices(4);
|
|
init_data.reserve_indices(4);
|
|
}
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
|
|
// vertices
|
|
#if !SLIC3R_OPENGL_ES
|
|
if (OpenGLManager::get_gl_info().is_core_profile()) {
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
const float width = right - left;
|
|
const float height = top - bottom;
|
|
float perimeter = 0.0f;
|
|
|
|
init_data.add_vertex(Vec4f(left, bottom, 0.0f, perimeter));
|
|
perimeter += width;
|
|
init_data.add_vertex(Vec4f(right, bottom, 0.0f, perimeter));
|
|
perimeter += height;
|
|
init_data.add_vertex(Vec4f(right, top, 0.0f, perimeter));
|
|
perimeter += width;
|
|
init_data.add_vertex(Vec4f(left, top, 0.0f, perimeter));
|
|
perimeter += height;
|
|
init_data.add_vertex(Vec4f(left, bottom, 0.0f, perimeter));
|
|
|
|
// indices
|
|
init_data.add_line(0, 1);
|
|
init_data.add_line(1, 2);
|
|
init_data.add_line(2, 3);
|
|
init_data.add_line(3, 4);
|
|
#if !SLIC3R_OPENGL_ES
|
|
}
|
|
else {
|
|
init_data.add_vertex(Vec2f(left, bottom));
|
|
init_data.add_vertex(Vec2f(right, bottom));
|
|
init_data.add_vertex(Vec2f(right, top));
|
|
init_data.add_vertex(Vec2f(left, top));
|
|
|
|
// indices
|
|
init_data.add_index(0);
|
|
init_data.add_index(1);
|
|
init_data.add_index(2);
|
|
init_data.add_index(3);
|
|
}
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
|
|
m_rectangle.init_from(std::move(init_data));
|
|
}
|
|
|
|
shader->set_uniform("view_model_matrix", Transform3d::Identity());
|
|
shader->set_uniform("projection_matrix", Transform3d::Identity());
|
|
#if !SLIC3R_OPENGL_ES
|
|
if (OpenGLManager::get_gl_info().is_core_profile()) {
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
const std::array<int, 4>& viewport = wxGetApp().plater()->get_camera().get_viewport();
|
|
shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3])));
|
|
shader->set_uniform("width", 0.25f);
|
|
shader->set_uniform("dash_size", 0.01f);
|
|
shader->set_uniform("gap_size", 0.0075f);
|
|
#if !SLIC3R_OPENGL_ES
|
|
}
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
|
|
m_rectangle.set_color(ColorRGBA::ORCA()); // ORCA: use orca color for selection rectangle
|
|
m_rectangle.render();
|
|
shader->stop_using();
|
|
}
|
|
|
|
#if !SLIC3R_OPENGL_ES
|
|
if (!OpenGLManager::get_gl_info().is_core_profile())
|
|
glsafe(::glPopAttrib());
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
}
|
|
|
|
} // namespace GUI
|
|
} // namespace Slic3r
|