#ifndef slic3r_SurfaceDrag_hpp_ #define slic3r_SurfaceDrag_hpp_ #include #include "libslic3r/Point.hpp" // Vec2d, Transform3d #include "slic3r/Utils/RaycastManager.hpp" #include "wx/event.h" // wxMouseEvent #include namespace Slic3r { class GLVolume; class ModelVolume; } // namespace Slic3r namespace Slic3r::GUI { class GLCanvas3D; class Selection; class TransformationType; struct Camera; // Data for drag&drop over surface with mouse struct SurfaceDrag { // hold screen coor offset of cursor from object center Vec2d mouse_offset; // Start dragging text transformations to world Transform3d world; // Invers transformation of text volume instance // Help convert world transformation to instance space Transform3d instance_inv; // Dragged gl volume GLVolume *gl_volume; // condition for raycaster RaycastManager::AllowVolumes condition; // initial rotation in Z axis of volume std::optional start_angle; // initial Z distance from surface std::optional start_distance; // Flag whether coordinate hit some volume bool exist_hit = true; // hold screen coor offset of cursor from object center without SLA shift Vec2d mouse_offset_without_sla_shift; }; // Limit direction of up vector on model // Between side and top surface constexpr double UP_LIMIT = 0.9; /// /// Mouse event handler, when move(drag&drop) volume over model surface /// NOTE: Dragged volume has to be selected. And also has to be hovered on start of dragging. /// /// Contain type of event and mouse position /// Actual viewport of camera /// Structure which keep information about dragging /// Contain gl_volumes and selection /// AABB trees for raycast in object /// Refresh state inside of function /// When set than use correction of up vector /// True when event is processed otherwise false bool on_mouse_surface_drag(const wxMouseEvent &mouse_event, const Camera &camera, std::optional &surface_drag, GLCanvas3D &canvas, RaycastManager &raycast_manager, const std::optional&up_limit = {}); /// /// Calculate translation of volume onto surface of model /// /// Must contain only one selected volume, Transformation of current instance /// AABB trees of object. Actualize object /// Offset of volume in volume coordinate std::optional calc_surface_offset(const Selection &selection, RaycastManager &raycast_manager); /// /// Calculate distance by ray to surface of object in emboss direction /// /// Define embossed volume /// Way to cast rays to object /// Contain model /// Calculated distance from surface std::optional calc_distance(const GLVolume &gl_volume, RaycastManager &raycaster, GLCanvas3D &canvas); std::optional calc_distance(const GLVolume &gl_volume, const RaycastManager &raycaster, const RaycastManager::ISkip *condition, const std::optional& fix); /// /// Calculate up vector angle /// /// Calculation of angle is for selected one volume /// std::optional calc_angle(const Selection &selection); /// /// Get transformation to world /// - use fix after store to 3mf when exists /// /// Scene volume /// To identify Model volume with fix transformation /// Fixed Transformation of gl_volume Transform3d world_matrix_fixed(const GLVolume &gl_volume, const ModelObjectPtrs& objects); /// /// Get transformation to world /// - use fix after store to 3mf when exists /// NOTE: when not one volume selected return identity /// /// Selected volume /// Fixed Transformation of selected volume in selection Transform3d world_matrix_fixed(const Selection &selection); /// /// Wrap function around selection transformation to apply fix transformation /// Fix transformation is needed because of (store/load) volume (to/from) 3mf /// /// Selected gl volume will be modified /// Function modified Selection transformation void selection_transform(Selection &selection, const std::function& selection_transformation_fnc); /// /// Apply camera direction for emboss direction /// /// Define view vector /// Containe Selected ModelVolume to modify orientation /// [Optional]Limit for direction of up vector /// True when apply change otherwise false bool face_selected_volume_to_camera(const Camera &camera, GLCanvas3D &canvas, const std::optional &wanted_up_limit = {}); /// /// Rotation around z Axis(emboss direction) /// /// Selected volume for rotation /// Relative angle to rotate around emboss direction void do_local_z_rotate(Selection &selection, double relative_angle); /// /// Translation along local z Axis (emboss direction) /// /// Selected volume for translate /// Relative move along emboss direction void do_local_z_move(Selection &selection, double relative_move); /// /// Distiguish between object and volume /// Differ in possible transformation type /// /// Contain selected volume/object /// Transformation to use TransformationType get_drag_transformation_type(const Selection &selection); /// /// On dragging rotate gizmo func /// Transform GLVolume from selection /// /// GLGizmoRotate::get_angle() /// In/Out current angle visible in UI /// Cache for start dragging angle /// Selected only Actual embossed volume void dragging_rotate_gizmo(double gizmo_angle, std::optional& current_angle, std::optional &start_angle, Selection &selection); } // namespace Slic3r::GUI #endif // slic3r_SurfaceDrag_hpp_