1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/************************************************************************
*
* Copyright (C) 2017-2025 IRCAD France
* Copyright (C) 2017-2019 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#pragma once
#include <data/boolean.hpp>
#include <data/matrix4.hpp>
#include <ui/__/editor.hpp>
#include <QObject>
#include <QPointer>
class QSlider;
class QLabel;
class QLineEdit;
namespace sight::module::ui::qt::viz
{
/**
* @brief This editor regulates the position and rotation defined in a transformation matrix. To respect the T*R*S
* matrices multiplication order, the translation is applied after the rotation.
*
* @section Signals Signals
* - \b set_translation_range(double, double): Allows to dynamically set the min and max of the translation.
*
* @section XML XML Configuration
*
* @code{.xml}
<service uid="..." type="sight::module::ui::qt::viz::transform_editor" >
<inout key="matrix" uid="..."/>
<translation enabled="false" min="-300"/>
<rotation enabled="true" min="-180" max="180" />
<properties minimal="false" />
</service>
@endcode
*
* @subsection In-Out In-Out
* - \b matrix [sight::data::matrix4]: matrix modified by the editor
*
* @subsection Configuration Configuration
* - \b enabled (optional): enable/disable rotation/translation edition.
* Can be 'true', 'false' or a combination of [xyz] (default: true).
* - \b min (optional): set the minimum value for translation/rotation (default: translation=-300, rotation=-180 ).
* - \b max (optional): set the maximum value for translation/rotation (default: translation=+300, rotation=180).
*
* @subsection Configuration Configuration
* - \b minimal (optional, default=false): only shows the slider, no label displayed
*/
class transform_editor final : public QObject,
public sight::ui::editor
{
Q_OBJECT;
public:
struct slots
{
static inline const std::string SET_TRANSLATION_RANGE = "set_translation_range";
};
SIGHT_DECLARE_SERVICE(transform_editor, sight::ui::editor);
/// Constructor. Do nothing.
transform_editor() noexcept;
/// Destructor. Do nothing.
~transform_editor() noexcept final = default;
protected:
/// This method is used to configure the service parameters:
void configuring() final;
///This method launches the sight::ui::service::create method.
void starting() final;
///This method launches the sight::ui::service::destroy method.
void stopping() final;
/// Updates Slider value
void updating() final;
// Connect data::matrix4::MODIFIED_SIG to update slot
connections_t auto_connections() const final;
void set_translation_range(double _min, double _max);
private Q_SLOTS:
/// Slot called when slider value changed.
void on_slider_changed(int _value);
/// Slot called when line edit value changed.
void on_text_changed();
private:
/// Update the editor when the matrix changes
void update_from_matrix();
/*
* @brief This enum defines the transformation matrix entries indexes
*/
enum slider_index
{
position_x = 0,
position_y,
position_z,
rotation_x,
rotation_y,
rotation_z,
max_slider_index
};
/*
* @brief This struct regulates a transformation matrix entry in the editor
*/
struct slider_widget
{
QPointer<QSlider> m_slider; ///< Slider to change coefficient value.
QPointer<QLabel> m_label_min; ///< Label to show the min value.
QPointer<QLabel> m_label_max; ///< Label to show the max value.
QPointer<QLabel> m_label_definition; ///< Label to show the coefficient description.
QPointer<QLineEdit> m_slider_value; ///< Editor to show the current value of the slider.
};
/// Array containing the different structs to regulate the transformation matrix entries.
std::array<slider_widget, max_slider_index> m_sliders;
/// Contains a string identifying which axes [xyz] are displayed for rotation
std::string m_rotation;
/// Contains a string identifying which axes [xyz] are displayed for translation
std::string m_translation;
/// Range of translation sliders
std::array<int, 2> m_translation_range {};
/// Range of rotation sliders
std::array<int, 2> m_rotation_range {};
static constexpr std::string_view MATRIX_INOUT = "matrix";
data::ptr<data::matrix4, sight::data::access::inout> m_matrix {this, MATRIX_INOUT};
/// If true, only shows the slider, no label displayed
data::property<data::boolean> m_minimal {this, "minimal", false};
};
} // namespace sight::module::ui::qt::viz
|