diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 8587f01f2..17b76e629 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -85,8 +85,8 @@ set(SLIC3R_GUI_SOURCES GUI/GUI_ObjectLayers.hpp GUI/LambdaObjectDialog.cpp GUI/LambdaObjectDialog.hpp - GUI/MeshClipper.cpp - GUI/MeshClipper.hpp + GUI/MeshUtils.cpp + GUI/MeshUtils.hpp GUI/Tab.cpp GUI/Tab.hpp GUI/ConfigManipulation.cpp diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 1b998c67e..b15402a52 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -12,6 +12,7 @@ #include "Selection.hpp" #include "Gizmos/GLGizmosManager.hpp" #include "GUI_ObjectLayers.hpp" +#include "MeshUtils.hpp" #include @@ -67,54 +68,6 @@ public: }; -class ClippingPlane -{ - double m_data[4]; - -public: - ClippingPlane() - { - m_data[0] = 0.0; - m_data[1] = 0.0; - m_data[2] = 1.0; - m_data[3] = 0.0; - } - - ClippingPlane(const Vec3d& direction, double offset) - { - Vec3d norm_dir = direction.normalized(); - m_data[0] = norm_dir(0); - m_data[1] = norm_dir(1); - m_data[2] = norm_dir(2); - m_data[3] = offset; - } - - bool operator==(const ClippingPlane& cp) const { - return m_data[0]==cp.m_data[0] && m_data[1]==cp.m_data[1] && m_data[2]==cp.m_data[2] && m_data[3]==cp.m_data[3]; - } - bool operator!=(const ClippingPlane& cp) const { return ! (*this==cp); } - - double distance(const Vec3d& pt) const { - assert(is_approx(get_normal().norm(), 1.)); - return (-get_normal().dot(pt) + m_data[3]); - } - - void set_normal(const Vec3d& normal) { for (size_t i=0; i<3; ++i) m_data[i] = normal(i); } - void set_offset(double offset) { m_data[3] = offset; } - Vec3d get_normal() const { return Vec3d(m_data[0], m_data[1], m_data[2]); } - bool is_active() const { return m_data[3] != DBL_MAX; } - static ClippingPlane ClipsNothing() { return ClippingPlane(Vec3d(0., 0., 1.), DBL_MAX); } - const double* get_data() const { return m_data; } - - // Serialization through cereal library - template - void serialize( Archive & ar ) - { - ar( m_data[0], m_data[1], m_data[2], m_data[3] ); - } -}; - - wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent); using Vec2dEvent = Event; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 99c4612ce..80afb29b1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -1,6 +1,7 @@ // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. #include "GLGizmoSlaSupports.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" +#include "slic3r/GUI/Gizmos/GLGizmos.hpp" #include @@ -12,11 +13,10 @@ #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_ObjectSettings.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" -#include "slic3r/GUI/MeshClipper.hpp" +#include "slic3r/GUI/MeshUtils.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/PresetBundle.hpp" #include "libslic3r/SLAPrint.hpp" -#include "libslic3r/Tesselate.hpp" namespace Slic3r { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index 515783d98..7bef33e1b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -2,8 +2,6 @@ #define slic3r_GLGizmoSlaSupports_hpp_ #include "GLGizmoBase.hpp" -#include "GLGizmos.hpp" -#include "slic3r/GUI/GLSelectionRectangle.hpp" #include "slic3r/GUI/GLSelectionRectangle.hpp" // There is an L function in igl that would be overridden by our localization macro - let's undefine it... @@ -22,6 +20,7 @@ namespace GUI { class ClippingPlane; class MeshClipper; +enum class SLAGizmoEventType : unsigned char; class GLGizmoSlaSupports : public GLGizmoBase { diff --git a/src/slic3r/GUI/Gizmos/GLGizmos.hpp b/src/slic3r/GUI/Gizmos/GLGizmos.hpp index 2e98899be..272fa098a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmos.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmos.hpp @@ -2,7 +2,10 @@ #define slic3r_GLGizmos_hpp_ // this describes events being passed from GLCanvas3D to SlaSupport gizmo -enum class SLAGizmoEventType { +namespace Slic3r { +namespace GUI { + +enum class SLAGizmoEventType : unsigned char { LeftDown = 1, LeftUp, RightDown, @@ -20,6 +23,9 @@ enum class SLAGizmoEventType { ResetClippingPlane }; +} // namespace GUI +} // namespace Slic3r + #include "slic3r/GUI/Gizmos/GLGizmoMove.hpp" #include "slic3r/GUI/Gizmos/GLGizmoScale.hpp" #include "slic3r/GUI/Gizmos/GLGizmoRotate.hpp" diff --git a/src/slic3r/GUI/MeshClipper.hpp b/src/slic3r/GUI/MeshClipper.hpp deleted file mode 100644 index 18b60761e..000000000 --- a/src/slic3r/GUI/MeshClipper.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef slic3r_MeshClipper_hpp_ -#define slic3r_MeshClipper_hpp_ - -#include "libslic3r/Point.hpp" -#include "slic3r/GUI/GLCanvas3D.hpp" - -namespace Slic3r { -namespace GUI { - -class MeshClipper { -public: - void set_plane(const ClippingPlane& plane); - void set_mesh(const TriangleMesh& mesh); - void set_transformation(const Geometry::Transformation& trafo); - - const std::vector& get_triangles(); - -private: - void recalculate_triangles(); - - Geometry::Transformation m_trafo; - const TriangleMesh* m_mesh = nullptr; - ClippingPlane m_plane; - std::vector m_triangles2d; - std::vector m_triangles3d; - bool m_triangles_valid = false; - std::unique_ptr m_tms; -}; - - - -} // namespace GUI -} // namespace Slic3r - - -#endif // slic3r_MeshClipper_hpp_ diff --git a/src/slic3r/GUI/MeshClipper.cpp b/src/slic3r/GUI/MeshUtils.cpp similarity index 97% rename from src/slic3r/GUI/MeshClipper.cpp rename to src/slic3r/GUI/MeshUtils.cpp index 21ddf52bc..9542f0b1f 100644 --- a/src/slic3r/GUI/MeshClipper.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -1,6 +1,7 @@ -#include "MeshClipper.hpp" -#include "GLCanvas3D.hpp" +#include "MeshUtils.hpp" + #include "libslic3r/Tesselate.hpp" +#include "libslic3r/TriangleMesh.hpp" namespace Slic3r { namespace GUI { @@ -13,6 +14,8 @@ void MeshClipper::set_plane(const ClippingPlane& plane) } } + + void MeshClipper::set_mesh(const TriangleMesh& mesh) { if (m_mesh != &mesh) { @@ -24,6 +27,8 @@ void MeshClipper::set_mesh(const TriangleMesh& mesh) } } + + void MeshClipper::set_transformation(const Geometry::Transformation& trafo) { if (! m_trafo.get_matrix().isApprox(trafo.get_matrix())) { @@ -44,6 +49,8 @@ const std::vector& MeshClipper::get_triangles() return m_triangles3d; } + + void MeshClipper::recalculate_triangles() { if (! m_tms) { @@ -51,7 +58,6 @@ void MeshClipper::recalculate_triangles() m_tms->init(m_mesh, [](){}); } - const Transform3f& instance_matrix_no_translation_no_scaling = m_trafo.get_matrix(true,false,true).cast(); const Vec3f& scaling = m_trafo.get_scaling_factor().cast(); // Calculate clipping plane normal in mesh coordinates. diff --git a/src/slic3r/GUI/MeshUtils.hpp b/src/slic3r/GUI/MeshUtils.hpp new file mode 100644 index 000000000..f97003a91 --- /dev/null +++ b/src/slic3r/GUI/MeshUtils.hpp @@ -0,0 +1,94 @@ +#ifndef slic3r_MeshUtils_hpp_ +#define slic3r_MeshUtils_hpp_ + +#include "libslic3r/Point.hpp" +#include "libslic3r/Geometry.hpp" + + +#include + +namespace Slic3r { + +class TriangleMesh; +class TriangleMeshSlicer; + +namespace GUI { + + + +class ClippingPlane +{ + double m_data[4]; + +public: + ClippingPlane() + { + m_data[0] = 0.0; + m_data[1] = 0.0; + m_data[2] = 1.0; + m_data[3] = 0.0; + } + + ClippingPlane(const Vec3d& direction, double offset) + { + Vec3d norm_dir = direction.normalized(); + m_data[0] = norm_dir(0); + m_data[1] = norm_dir(1); + m_data[2] = norm_dir(2); + m_data[3] = offset; + } + + bool operator==(const ClippingPlane& cp) const { + return m_data[0]==cp.m_data[0] && m_data[1]==cp.m_data[1] && m_data[2]==cp.m_data[2] && m_data[3]==cp.m_data[3]; + } + bool operator!=(const ClippingPlane& cp) const { return ! (*this==cp); } + + double distance(const Vec3d& pt) const { + assert(is_approx(get_normal().norm(), 1.)); + return (-get_normal().dot(pt) + m_data[3]); + } + + void set_normal(const Vec3d& normal) { for (size_t i=0; i<3; ++i) m_data[i] = normal(i); } + void set_offset(double offset) { m_data[3] = offset; } + Vec3d get_normal() const { return Vec3d(m_data[0], m_data[1], m_data[2]); } + bool is_active() const { return m_data[3] != DBL_MAX; } + static ClippingPlane ClipsNothing() { return ClippingPlane(Vec3d(0., 0., 1.), DBL_MAX); } + const double* get_data() const { return m_data; } + + // Serialization through cereal library + template + void serialize( Archive & ar ) + { + ar( m_data[0], m_data[1], m_data[2], m_data[3] ); + } +}; + + + +class MeshClipper { +public: + void set_plane(const ClippingPlane& plane); + void set_mesh(const TriangleMesh& mesh); + void set_transformation(const Geometry::Transformation& trafo); + + const std::vector& get_triangles(); + +private: + void recalculate_triangles(); + + Geometry::Transformation m_trafo; + const TriangleMesh* m_mesh = nullptr; + ClippingPlane m_plane; + std::vector m_triangles2d; + std::vector m_triangles3d; + bool m_triangles_valid = false; + std::unique_ptr m_tms; +}; + + + +} // namespace GUI +} // namespace Slic3r + + +#endif // slic3r_MeshUtils_hpp_