GCC Code Coverage Report


./
File: modules/ui/qt/viz/transform_editor.hpp
Date: 2025-01-21 16:21:04
Lines:
0/1
0.0%
Functions:
0/5
0.0%
Branches:
0/9
0.0%

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