diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 7fb7ed9f1..f3f31ed4f 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1425,11 +1425,11 @@ void ModelObject::bake_xy_rotation_into_meshes(size_t instance_idx) assert(instance_idx < this->instances.size()); const Geometry::Transformation reference_trafo = this->instances[instance_idx]->get_transformation(); -#if !ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if !ENABLE_WORLD_COORDINATE if (Geometry::is_rotation_ninety_degrees(reference_trafo.get_rotation())) // nothing to do, scaling in the world coordinate space is possible in the representation of Geometry::Transformation. return; -#endif // !ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // !ENABLE_WORLD_COORDINATE bool left_handed = reference_trafo.is_left_handed(); bool has_mirrorring = ! reference_trafo.get_mirror().isApprox(Vec3d(1., 1., 1.)); diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index e8f9fc965..250a45f3f 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -73,8 +73,6 @@ #define ENABLE_WORLD_COORDINATE (1 && ENABLE_2_5_0_ALPHA1) // Enable showing world coordinates of volumes' offset relative to the instance containing them #define ENABLE_WORLD_COORDINATE_VOLUMES_LOCAL_OFFSET (0 && ENABLE_WORLD_COORDINATE) -// Enable alternate implementation of manipulating scale for instances and volumes -#define ENABLE_WORLD_COORDINATE_SCALE_REVISITED (1 && ENABLE_WORLD_COORDINATE) // Enable implementation of Geometry::Transformation using matrices only #define ENABLE_TRANSFORMATIONS_BY_MATRICES (1 && ENABLE_WORLD_COORDINATE) // Enable modified camera control using mouse diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 0317d0d72..6fbc55511 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -675,17 +675,17 @@ void ObjectManipulation::update_settings_value(const Selection& selection) #endif // ENABLE_WORLD_COORDINATE m_new_rotate_label_string = L("Rotate"); #if !ENABLE_TRANSFORMATIONS_BY_MATRICES -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE m_new_scale_label_string = L("Scale"); -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE #endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES m_new_rotation = Vec3d::Zero(); m_new_size = selection.get_scaled_instance_bounding_box().size(); -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED && !ENABLE_TRANSFORMATIONS_BY_MATRICES - m_new_scale = Vec3d(100.0, 100.0, 100.0); +#if ENABLE_WORLD_COORDINATE && !ENABLE_TRANSFORMATIONS_BY_MATRICES + m_new_scale = Vec3d(100.0, 100.0, 100.0); #else m_new_scale = m_new_size.cwiseQuotient(selection.get_unscaled_instance_bounding_box().size()) * 100.0; -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED && !ENABLE_TRANSFORMATIONS_BY_MATRICES +#endif // ENABLE_WORLD_COORDINATE && !ENABLE_TRANSFORMATIONS_BY_MATRICES } else { #if ENABLE_WORLD_COORDINATE @@ -736,21 +736,15 @@ void ObjectManipulation::update_settings_value(const Selection& selection) m_new_position = offset; m_new_rotate_label_string = L("Rotate"); #if !ENABLE_TRANSFORMATIONS_BY_MATRICES -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED m_new_scale_label_string = L("Scale"); -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED #endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES m_new_rotation = Vec3d::Zero(); m_new_size = volume->transformed_convex_hull_bounding_box(trafo.get_matrix()).size(); -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED && !ENABLE_TRANSFORMATIONS_BY_MATRICES - m_new_scale = Vec3d(100.0, 100.0, 100.0); -#else #if ENABLE_TRANSFORMATIONS_BY_MATRICES m_new_scale = m_new_size.cwiseQuotient(volume->transformed_convex_hull_bounding_box(volume->get_instance_transformation().get_matrix() * volume->get_volume_transformation().get_matrix_no_scaling_factor()).size()) * 100.0; #else - m_new_scale = m_new_size.cwiseProduct(volume->transformed_convex_hull_bounding_box(volume->get_instance_transformation().get_matrix() * volume->get_volume_transformation().get_matrix(false, false, true, false)).size().cwiseInverse()) * 100.0; + m_new_scale = Vec3d(100.0, 100.0, 100.0); #endif // ENABLE_TRANSFORMATIONS_BY_MATRICES -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED && !ENABLE_TRANSFORMATIONS_BY_MATRICES } else if (is_local_coordinates()) { m_new_move_label_string = L("Translate"); @@ -771,22 +765,18 @@ void ObjectManipulation::update_settings_value(const Selection& selection) m_new_position = volume->get_volume_offset(); m_new_rotate_label_string = L("Rotate"); #if !ENABLE_TRANSFORMATIONS_BY_MATRICES -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE m_new_scale_label_string = L("Scale"); -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE #endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES m_new_rotation = Vec3d::Zero(); #if ENABLE_WORLD_COORDINATE m_new_size = volume->transformed_convex_hull_bounding_box(volume->get_volume_transformation().get_matrix()).size(); -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED && !ENABLE_TRANSFORMATIONS_BY_MATRICES - m_new_scale = Vec3d(100.0, 100.0, 100.0); -#else #if ENABLE_TRANSFORMATIONS_BY_MATRICES m_new_scale = m_new_size.cwiseQuotient(volume->transformed_convex_hull_bounding_box(volume->get_volume_transformation().get_matrix_no_scaling_factor()).size()) * 100.0; #else - m_new_scale = m_new_size.cwiseProduct(volume->transformed_convex_hull_bounding_box(volume->get_volume_transformation().get_matrix(false, false, true, false)).size().cwiseInverse()) * 100.0; + m_new_scale = Vec3d(100.0, 100.0, 100.0); #endif // ENABLE_TRANSFORMATIONS_BY_MATRICES -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED && !ENABLE_TRANSFORMATIONS_BY_MATRICES } #else m_new_scale = volume->get_volume_scaling_factor() * 100.0; @@ -861,40 +851,14 @@ void ObjectManipulation::update_if_dirty() #if ENABLE_WORLD_COORDINATE Selection::EUniformScaleRequiredReason reason; if (selection.requires_uniform_scale(&reason)) { -#else - if (selection.requires_uniform_scale()) { -#endif // ENABLE_WORLD_COORDINATE -#if !ENABLE_WORLD_COORDINATE_SCALE_REVISITED - m_lock_bnt->SetLock(true); -#endif // !ENABLE_WORLD_COORDINATE_SCALE_REVISITED -#if ENABLE_WORLD_COORDINATE - wxString tooltip; - if (selection.is_single_volume_or_modifier()) { -#if !ENABLE_WORLD_COORDINATE_SCALE_REVISITED - if (reason == Selection::EUniformScaleRequiredReason::VolumeNotAxisAligned_Instance) - tooltip = _L("You cannot use non-uniform scaling mode for parts non aligned with the instance local axes"); - else if (reason == Selection::EUniformScaleRequiredReason::VolumeNotAxisAligned_World) - tooltip = _L("You cannot use non-uniform scaling mode for parts non aligned with the printer axes"); -#endif // !ENABLE_WORLD_COORDINATE_SCALE_REVISITED - } - else if (selection.is_single_full_instance()) { -#if !ENABLE_WORLD_COORDINATE_SCALE_REVISITED - if (reason == Selection::EUniformScaleRequiredReason::InstanceNotAxisAligned_World) - tooltip = _L("You cannot use non-uniform scaling mode for instances non aligned with the printer axes"); - else if (reason == Selection::EUniformScaleRequiredReason::VolumeNotAxisAligned_Instance) - tooltip = _L("You cannot use non-uniform scaling mode for instances containing non locally axis-aligned parts"); -#endif // !ENABLE_WORLD_COORDINATE_SCALE_REVISITED - } - else - tooltip = _L("You cannot use non-uniform scaling mode for multiple objects/parts selection"); - + wxString tooltip = _L("You cannot use non-uniform scaling mode for multiple objects/parts selection"); m_lock_bnt->SetToolTip(tooltip); #else + if (selection.requires_uniform_scale()) { + m_lock_bnt->SetLock(true); m_lock_bnt->SetToolTip(_L("You cannot use non-uniform scaling mode for multiple objects/parts selection")); -#endif // ENABLE_WORLD_COORDINATE -#if !ENABLE_WORLD_COORDINATE_SCALE_REVISITED m_lock_bnt->disable(); -#endif // !ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE } else { #endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES @@ -1313,11 +1277,11 @@ void ObjectManipulation::change_size_value(int axis, double value) selection.get_unscaled_instance_bounding_box().size() : wxGetApp().model().objects[selection.get_first_volume()->object_idx()]->raw_mesh_bounding_box().size(); -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE this->do_size(axis, size.cwiseQuotient(ref_size)); #else this->do_scale(axis, size.cwiseQuotient(ref_size)); -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE m_cache.size = size; m_cache.size_rounded(axis) = DBL_MAX; @@ -1333,24 +1297,17 @@ void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const #if ENABLE_WORLD_COORDINATE TransformationType transformation_type; -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED if (is_local_coordinates()) transformation_type.set_local(); else if (is_instance_coordinates()) transformation_type.set_instance(); -#if !ENABLE_TRANSFORMATIONS_BY_MATRICES - if (!is_local_coordinates()) - transformation_type.set_relative(); -#endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES -#else - if (!is_world_coordinates()) - transformation_type.set_local(); -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED - #if ENABLE_TRANSFORMATIONS_BY_MATRICES Vec3d scaling_factor = m_uniform_scale ? scale(axis) * Vec3d::Ones() : scale; #else + if (!is_local_coordinates()) + transformation_type.set_relative(); + bool uniform_scale = m_uniform_scale || selection.requires_uniform_scale(); Vec3d scaling_factor = uniform_scale ? scale(axis) * Vec3d::Ones() : scale; @@ -1381,7 +1338,7 @@ void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const wxGetApp().plater()->canvas3D()->do_scale(L("Set Scale")); } -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE void ObjectManipulation::do_size(int axis, const Vec3d& scale) const { Selection& selection = wxGetApp().plater()->canvas3D()->get_selection(); @@ -1418,7 +1375,7 @@ void ObjectManipulation::do_size(int axis, const Vec3d& scale) const selection.scale(scaling_factor, transformation_type); wxGetApp().plater()->canvas3D()->do_scale(L("Set Size")); } -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE void ObjectManipulation::on_change(const std::string& opt_key, int axis, double new_value) { @@ -1457,7 +1414,7 @@ void ObjectManipulation::on_change(const std::string& opt_key, int axis, double void ObjectManipulation::set_uniform_scaling(const bool use_uniform_scale) { const Selection &selection = wxGetApp().plater()->canvas3D()->get_selection(); -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE if (!use_uniform_scale) { #if !ENABLE_TRANSFORMATIONS_BY_MATRICES int res = selection.bake_transform_if_needed(); @@ -1477,12 +1434,8 @@ void ObjectManipulation::set_uniform_scaling(const bool use_uniform_scale) #if ENABLE_TRANSFORMATIONS_BY_MATRICES set_dirty(); #endif // ENABLE_TRANSFORMATIONS_BY_MATRICES -#else -#if ENABLE_WORLD_COORDINATE - if (selection.is_single_full_instance() && is_world_coordinates() && !use_uniform_scale) { #else if (selection.is_single_full_instance() && m_world_coordinates && !use_uniform_scale) { -#endif // ENABLE_WORLD_COORDINATE // Verify whether the instance rotation is multiples of 90 degrees, so that the scaling in world coordinates is possible. // all volumes in the selection belongs to the same instance, any of them contains the needed instance data, so we take the first one const GLVolume* volume = selection.get_first_volume(); @@ -1513,7 +1466,7 @@ void ObjectManipulation::set_uniform_scaling(const bool use_uniform_scale) } m_uniform_scale = use_uniform_scale; -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE } #if ENABLE_WORLD_COORDINATE diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index 696f75128..e25e05f60 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -263,11 +263,9 @@ private: void change_scale_value(int axis, double value); void change_size_value(int axis, double value); void do_scale(int axis, const Vec3d &scale) const; -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED - void do_size(int axis, const Vec3d& scale) const; -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED - #if ENABLE_WORLD_COORDINATE + void do_size(int axis, const Vec3d& scale) const; + void set_coordinates_type(const wxString& type_string); #endif // ENABLE_WORLD_COORDINATE }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index bee57ec6e..0810ddc97 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -335,7 +335,7 @@ bool GLGizmoBase::use_grabbers(const wxMouseEvent &mouse_event) { return true; } else if (mouse_event.LeftUp() || is_leaving || is_dragging_finished) { -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE do_stop_dragging(is_leaving); #else for (auto &grabber : m_grabbers) grabber.dragging = false; @@ -360,14 +360,14 @@ bool GLGizmoBase::use_grabbers(const wxMouseEvent &mouse_event) { m_parent.post_event(SimpleEvent(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED)); // updates camera target constraints m_parent.refresh_camera_scene_box(); -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE return true; } } return false; } -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE void GLGizmoBase::do_stop_dragging(bool perform_mouse_cleanup) { for (auto& grabber : m_grabbers) grabber.dragging = false; @@ -393,7 +393,7 @@ void GLGizmoBase::do_stop_dragging(bool perform_mouse_cleanup) // updates camera target constraints m_parent.refresh_camera_scene_box(); } -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE std::string GLGizmoBase::format(float value, unsigned int decimals) const { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index fff699479..95763f004 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -89,156 +89,156 @@ protected: static GLModel s_cone; #else GLModel m_cube; -#endif // ENABLE_GIZMO_GRABBER_REFACTOR - }; - -public: - enum EState - { - Off, - On, - Num_States - }; - - struct UpdateData - { - const Linef3& mouse_ray; - const Point& mouse_pos; - - UpdateData(const Linef3& mouse_ray, const Point& mouse_pos) - : mouse_ray(mouse_ray), mouse_pos(mouse_pos) - {} - }; - -protected: - GLCanvas3D& m_parent; - int m_group_id; // TODO: remove only for rotate - EState m_state; - int m_shortcut_key; - std::string m_icon_filename; - unsigned int m_sprite_id; - int m_hover_id; - bool m_dragging; - mutable std::vector m_grabbers; - ImGuiWrapper* m_imgui; - bool m_first_input_window_render; - CommonGizmosDataPool* m_c; -public: - GLGizmoBase(GLCanvas3D& parent, - const std::string& icon_filename, - unsigned int sprite_id); - virtual ~GLGizmoBase() = default; - - bool init() { return on_init(); } - - void load(cereal::BinaryInputArchive& ar) { m_state = On; on_load(ar); } - void save(cereal::BinaryOutputArchive& ar) const { on_save(ar); } - - std::string get_name(bool include_shortcut = true) const; - - EState get_state() const { return m_state; } - void set_state(EState state) { m_state = state; on_set_state(); } - - int get_shortcut_key() const { return m_shortcut_key; } - - const std::string& get_icon_filename() const { return m_icon_filename; } - - bool is_activable() const { return on_is_activable(); } - bool is_selectable() const { return on_is_selectable(); } - CommonGizmosDataID get_requirements() const { return on_get_requirements(); } - virtual bool wants_enter_leave_snapshots() const { return false; } - virtual std::string get_gizmo_entering_text() const { assert(false); return ""; } - virtual std::string get_gizmo_leaving_text() const { assert(false); return ""; } - virtual std::string get_action_snapshot_name() { return _u8L("Gizmo action"); } - void set_common_data_pool(CommonGizmosDataPool* ptr) { m_c = ptr; } - - unsigned int get_sprite_id() const { return m_sprite_id; } - - int get_hover_id() const { return m_hover_id; } - void set_hover_id(int id); - - bool is_dragging() const { return m_dragging; } - - // returns True when Gizmo changed its state - bool update_items_state(); - - void render() { on_render(); } - void render_for_picking() { on_render_for_picking(); } - void render_input_window(float x, float y, float bottom_limit); - - /// - /// Mouse tooltip text - /// - /// Text to be visible in mouse tooltip - virtual std::string get_tooltip() const { return ""; } - - /// - /// Is called when data (Selection) is changed - /// - virtual void data_changed(){}; - - /// - /// Implement when want to process mouse events in gizmo - /// Click, Right click, move, drag, ... - /// - /// Keep information about mouse click - /// Return True when use the information and don't want to propagate it otherwise False. - virtual bool on_mouse(const wxMouseEvent &mouse_event) { return false; } -protected: - virtual bool on_init() = 0; - virtual void on_load(cereal::BinaryInputArchive& ar) {} - virtual void on_save(cereal::BinaryOutputArchive& ar) const {} - virtual std::string on_get_name() const = 0; - virtual void on_set_state() {} - virtual void on_set_hover_id() {} - virtual bool on_is_activable() const { return true; } - virtual bool on_is_selectable() const { return true; } - virtual CommonGizmosDataID on_get_requirements() const { return CommonGizmosDataID(0); } - virtual void on_enable_grabber(unsigned int id) {} - virtual void on_disable_grabber(unsigned int id) {} - - // called inside use_grabbers - virtual void on_start_dragging() {} - virtual void on_stop_dragging() {} - virtual void on_dragging(const UpdateData& data) {} - - virtual void on_render() = 0; - virtual void on_render_for_picking() = 0; - virtual void on_render_input_window(float x, float y, float bottom_limit) {} - - // Returns the picking color for the given id, based on the BASE_ID constant - // No check is made for clashing with other picking color (i.e. GLVolumes) - ColorRGBA picking_color_component(unsigned int id) const; - - void render_grabbers(const BoundingBoxf3& box) const; - void render_grabbers(float size) const; - void render_grabbers_for_picking(const BoundingBoxf3& box) const; - - std::string format(float value, unsigned int decimals) const; - - // Mark gizmo as dirty to Re-Render when idle() - void set_dirty(); - - /// - /// function which - /// Set up m_dragging and call functions - /// on_start_dragging / on_dragging / on_stop_dragging - /// - /// Keep information about mouse click - /// same as on_mouse - bool use_grabbers(const wxMouseEvent &mouse_event); - -#if ENABLE_WORLD_COORDINATE - void do_stop_dragging(bool perform_mouse_cleanup); -#endif // ENABLE_WORLD_COORDINATE - -private: - // Flag for dirty visible state of Gizmo - // When True then need new rendering - bool m_dirty; -}; - -} // namespace GUI -} // namespace Slic3r - -#endif // slic3r_GLGizmoBase_hpp_ +#endif // ENABLE_GIZMO_GRABBER_REFACTOR + }; + +public: + enum EState + { + Off, + On, + Num_States + }; + + struct UpdateData + { + const Linef3& mouse_ray; + const Point& mouse_pos; + + UpdateData(const Linef3& mouse_ray, const Point& mouse_pos) + : mouse_ray(mouse_ray), mouse_pos(mouse_pos) + {} + }; + +protected: + GLCanvas3D& m_parent; + int m_group_id; // TODO: remove only for rotate + EState m_state; + int m_shortcut_key; + std::string m_icon_filename; + unsigned int m_sprite_id; + int m_hover_id; + bool m_dragging; + mutable std::vector m_grabbers; + ImGuiWrapper* m_imgui; + bool m_first_input_window_render; + CommonGizmosDataPool* m_c; +public: + GLGizmoBase(GLCanvas3D& parent, + const std::string& icon_filename, + unsigned int sprite_id); + virtual ~GLGizmoBase() = default; + + bool init() { return on_init(); } + + void load(cereal::BinaryInputArchive& ar) { m_state = On; on_load(ar); } + void save(cereal::BinaryOutputArchive& ar) const { on_save(ar); } + + std::string get_name(bool include_shortcut = true) const; + + EState get_state() const { return m_state; } + void set_state(EState state) { m_state = state; on_set_state(); } + + int get_shortcut_key() const { return m_shortcut_key; } + + const std::string& get_icon_filename() const { return m_icon_filename; } + + bool is_activable() const { return on_is_activable(); } + bool is_selectable() const { return on_is_selectable(); } + CommonGizmosDataID get_requirements() const { return on_get_requirements(); } + virtual bool wants_enter_leave_snapshots() const { return false; } + virtual std::string get_gizmo_entering_text() const { assert(false); return ""; } + virtual std::string get_gizmo_leaving_text() const { assert(false); return ""; } + virtual std::string get_action_snapshot_name() { return _u8L("Gizmo action"); } + void set_common_data_pool(CommonGizmosDataPool* ptr) { m_c = ptr; } + + unsigned int get_sprite_id() const { return m_sprite_id; } + + int get_hover_id() const { return m_hover_id; } + void set_hover_id(int id); + + bool is_dragging() const { return m_dragging; } + + // returns True when Gizmo changed its state + bool update_items_state(); + + void render() { on_render(); } + void render_for_picking() { on_render_for_picking(); } + void render_input_window(float x, float y, float bottom_limit); + + /// + /// Mouse tooltip text + /// + /// Text to be visible in mouse tooltip + virtual std::string get_tooltip() const { return ""; } + + /// + /// Is called when data (Selection) is changed + /// + virtual void data_changed(){}; + + /// + /// Implement when want to process mouse events in gizmo + /// Click, Right click, move, drag, ... + /// + /// Keep information about mouse click + /// Return True when use the information and don't want to propagate it otherwise False. + virtual bool on_mouse(const wxMouseEvent &mouse_event) { return false; } +protected: + virtual bool on_init() = 0; + virtual void on_load(cereal::BinaryInputArchive& ar) {} + virtual void on_save(cereal::BinaryOutputArchive& ar) const {} + virtual std::string on_get_name() const = 0; + virtual void on_set_state() {} + virtual void on_set_hover_id() {} + virtual bool on_is_activable() const { return true; } + virtual bool on_is_selectable() const { return true; } + virtual CommonGizmosDataID on_get_requirements() const { return CommonGizmosDataID(0); } + virtual void on_enable_grabber(unsigned int id) {} + virtual void on_disable_grabber(unsigned int id) {} + + // called inside use_grabbers + virtual void on_start_dragging() {} + virtual void on_stop_dragging() {} + virtual void on_dragging(const UpdateData& data) {} + + virtual void on_render() = 0; + virtual void on_render_for_picking() = 0; + virtual void on_render_input_window(float x, float y, float bottom_limit) {} + + // Returns the picking color for the given id, based on the BASE_ID constant + // No check is made for clashing with other picking color (i.e. GLVolumes) + ColorRGBA picking_color_component(unsigned int id) const; + + void render_grabbers(const BoundingBoxf3& box) const; + void render_grabbers(float size) const; + void render_grabbers_for_picking(const BoundingBoxf3& box) const; + + std::string format(float value, unsigned int decimals) const; + + // Mark gizmo as dirty to Re-Render when idle() + void set_dirty(); + + /// + /// function which + /// Set up m_dragging and call functions + /// on_start_dragging / on_dragging / on_stop_dragging + /// + /// Keep information about mouse click + /// same as on_mouse + bool use_grabbers(const wxMouseEvent &mouse_event); + +#if ENABLE_WORLD_COORDINATE + void do_stop_dragging(bool perform_mouse_cleanup); +#endif // ENABLE_WORLD_COORDINATE + +private: + // Flag for dirty visible state of Gizmo + // When True then need new rendering + bool m_dirty; +}; + +} // namespace GUI +} // namespace Slic3r + +#endif // slic3r_GLGizmoBase_hpp_ diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index 58095375f..1d87d772a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -80,7 +80,7 @@ bool GLGizmoScale3D::on_mouse(const wxMouseEvent &mouse_event) if (mouse_event.Dragging()) { if (m_dragging) { #if !ENABLE_TRANSFORMATIONS_BY_MATRICES -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE int res = 1; if (m_scale.x() != m_scale.y() || m_scale.x() != m_scale.z()) res = m_parent.get_selection().bake_transform_if_needed(); @@ -90,7 +90,7 @@ bool GLGizmoScale3D::on_mouse(const wxMouseEvent &mouse_event) return true; } else { -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE #endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES // Apply new temporary scale factors #if ENABLE_WORLD_COORDINATE @@ -123,9 +123,9 @@ bool GLGizmoScale3D::on_mouse(const wxMouseEvent &mouse_event) #endif // ENABLE_WORLD_COORDINATE #endif // ENABLE_TRANSFORMATIONS_BY_MATRICES #if !ENABLE_TRANSFORMATIONS_BY_MATRICES -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED - } -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE + } +#endif // ENABLE_WORLD_COORDINATE #endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES } } @@ -138,9 +138,6 @@ void GLGizmoScale3D::data_changed() const Selection &selection = m_parent.get_selection(); #endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES #if ENABLE_WORLD_COORDINATE -#if !ENABLE_WORLD_COORDINATE_SCALE_REVISITED - bool enable_scale_xyz = !selection.requires_uniform_scale(); -#endif // !ENABLE_WORLD_COORDINATE_SCALE_REVISITED #else bool enable_scale_xyz = selection.is_single_full_instance() || selection.is_single_volume() || @@ -149,24 +146,28 @@ void GLGizmoScale3D::data_changed() #if ENABLE_TRANSFORMATIONS_BY_MATRICES set_scale(Vec3d::Ones()); #else -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE if (selection.is_single_full_instance() || selection.is_single_volume_or_modifier()) { #else for (unsigned int i = 0; i < 6; ++i) m_grabbers[i].enabled = enable_scale_xyz; if (enable_scale_xyz) { +#endif // ENABLE_WORLD_COORDINATE // all volumes in the selection belongs to the same instance, any of // them contains the needed data, so we take the first const GLVolume* volume = selection.get_first_volume(); if (selection.is_single_full_instance()) set_scale(volume->get_instance_scaling_factor()); +#if ENABLE_WORLD_COORDINATE + else if (selection.is_single_volume_or_modifier()) +#else else if (selection.is_single_volume() || selection.is_single_modifier()) +#endif // ENABLE_WORLD_COORDINATE set_scale(volume->get_volume_scaling_factor()); } else set_scale(Vec3d::Ones()); -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED #endif // ENABLE_TRANSFORMATIONS_BY_MATRICES } diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 0212ed305..c377fda16 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -10,9 +10,9 @@ #include "Camera.hpp" #include "Plater.hpp" -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE #include "MsgDialog.hpp" -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE #include "Gizmos/GLGizmoBase.hpp" @@ -1559,7 +1559,7 @@ void Selection::translate(unsigned int object_idx, unsigned int instance_idx, co this->set_bounding_boxes_dirty(); } -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE int Selection::bake_transform_if_needed() const { if ((is_single_full_instance() && wxGetApp().obj_manipul()->is_world_coordinates()) || @@ -1610,7 +1610,7 @@ int Selection::bake_transform_if_needed() const return 1; } -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE void Selection::erase() { diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index b62db2e6e..c919927ea 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -386,13 +386,13 @@ public: #endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES void translate(unsigned int object_idx, unsigned int instance_idx, const Vec3d& displacement); -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE // returns: // -1 if the user refused to proceed with baking when asked // 0 if the baking was performed // 1 if no baking was needed int bake_transform_if_needed() const; -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE void erase(); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index bacdb1f9c..876398510 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -581,12 +581,12 @@ void LockButton::OnButton(wxCommandEvent& event) if (m_disabled) return; -#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#if ENABLE_WORLD_COORDINATE SetLock(!m_is_pushed); #else m_is_pushed = !m_is_pushed; update_button_bitmaps(); -#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED +#endif // ENABLE_WORLD_COORDINATE event.Skip(); }