Developer Documentation
QtCoordFrameDialog.cc
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42
43
44
45
46//=============================================================================
47//
48// CLASS QtCoordFrameDialog - IMPLEMENTATION
49//
50//=============================================================================
51
52
53//== INCLUDES =================================================================
54
55#include "QtCoordFrameDialog.hh"
56#include "../Scenegraph/CoordFrameNode.hh"
57
58
59//== NAMESPACES ==============================================================
60
61
62namespace ACG {
63namespace QtWidgets {
64
65
66//== IMPLEMENTATION ==========================================================
67
68
69QtCoordFrameDialog::
70QtCoordFrameDialog( QWidget* _parent,
71 SceneGraph::CoordFrameNode* _node,
72 Qt::WindowFlags _fl )
73
74 : QDialog(_parent, _fl),
75 node_(_node)
76
77{
78 ui_.setupUi( this );
79
80 connect( ui_.OkButton, SIGNAL( clicked() ), this, SLOT( apply_changes() ) );
81 connect( ui_.OkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
82 connect( ui_.ApplyButton, SIGNAL( clicked() ), this, SLOT( apply_changes() ) );
83 connect( ui_.CancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
84 connect( ui_.CancelButton, SIGNAL( clicked() ), this, SLOT( undo_changes() ) );
85 connect( ui_.x_add_button, SIGNAL( clicked() ), this, SLOT( add_x_plane() ) );
86 connect( ui_.x_mod_button, SIGNAL( clicked() ), this, SLOT( mod_x_plane() ) );
87 connect( ui_.x_del_button, SIGNAL( clicked() ), this, SLOT( del_x_plane() ) );
88 connect( ui_.y_add_button, SIGNAL( clicked() ), this, SLOT( add_y_plane() ) );
89 connect( ui_.y_mod_button, SIGNAL( clicked() ), this, SLOT( mod_y_plane() ) );
90 connect( ui_.y_del_button, SIGNAL( clicked() ), this, SLOT( del_y_plane() ) );
91 connect( ui_.z_add_button, SIGNAL( clicked() ), this, SLOT( add_z_plane() ) );
92 connect( ui_.z_mod_button, SIGNAL( clicked() ), this, SLOT( mod_z_plane() ) );
93 connect( ui_.z_del_button, SIGNAL( clicked() ), this, SLOT( del_z_plane() ) );
94
95 update_values();
96}
97
98
99//-----------------------------------------------------------------------------
100
101
102void
103QtCoordFrameDialog::show()
104{
105 update_values();
106 QDialog::show();
107}
108
109
110//-----------------------------------------------------------------------------
111
112
113void
114QtCoordFrameDialog::update_values()
115{
116 x_planes_bak_ = node_->x_planes();
117 y_planes_bak_ = node_->y_planes();
118 z_planes_bak_ = node_->z_planes();
119
120 planes2combo(x_planes_bak_, ui_.x_combobox);
121 planes2combo(y_planes_bak_, ui_.y_combobox);
122 planes2combo(z_planes_bak_, ui_.z_combobox);
123
124
125 QString s, title;
126
127 title = ( QString("X-Planes: [") +
128 s.setNum(node_->bb_min()[0], 'f', 4) +
129 QString(", ") +
130 s.setNum(node_->bb_max()[0], 'f', 4) +
131 QString("]") );
132 ui_.x_groupbox->setTitle(title);
133
134 title = ( QString("Y-Planes: [") +
135 s.setNum(node_->bb_min()[1], 'f', 4) +
136 QString(", ") +
137 s.setNum(node_->bb_max()[1], 'f', 4) +
138 QString("]") );
139 ui_.y_groupbox->setTitle(title);
140
141 title = ( QString("Z-Planes: [") +
142 s.setNum(node_->bb_min()[2], 'f', 4) +
143 QString(", ") +
144 s.setNum(node_->bb_max()[2], 'f', 4) +
145 QString("]") );
146 ui_.z_groupbox->setTitle(title);
147}
148
149
150//-----------------------------------------------------------------------------
151
152
153void
154QtCoordFrameDialog::combo2planes(const QComboBox* _combo,
155 std::vector<float>& _planes)
156{
157 unsigned int i(0), N(_combo->count());
158
159 _planes.clear();
160 _planes.reserve(N);
161
162 for (; i<N; ++i)
163 _planes.push_back(_combo->itemText(i).toFloat());
164}
165
166
167void
168QtCoordFrameDialog::planes2combo(const std::vector<float>& _planes,
169 QComboBox* _combo)
170{
171 std::vector<float>::const_iterator p_it, p_end;
172 QString s;
173
174 _combo->clear();
175 for (p_it=_planes.begin(), p_end=_planes.end(); p_it!=p_end; ++p_it)
176 _combo->addItem(s.setNum(*p_it, 'f', 3));
177}
178
179
180//-----------------------------------------------------------------------------
181
182
183void QtCoordFrameDialog::apply_changes()
184{
185 std::vector<float> planes;
186
187 combo2planes(ui_.x_combobox, planes);
188 node_->set_x_planes(planes);
189
190 combo2planes(ui_.y_combobox, planes);
191 node_->set_y_planes(planes);
192
193 combo2planes(ui_.z_combobox, planes);
194 node_->set_z_planes(planes);
195
196 emit signalNodeChanged(node_);
197}
198
199
200//-----------------------------------------------------------------------------
201
202
203void QtCoordFrameDialog::undo_changes()
204{
205 node_->set_x_planes(x_planes_bak_);
206 node_->set_y_planes(y_planes_bak_);
207 node_->set_z_planes(z_planes_bak_);
208
209 emit signalNodeChanged(node_);
210}
211
212
213//-----------------------------------------------------------------------------
214
215
216void QtCoordFrameDialog::add_x_plane()
217{
218 ui_.x_combobox->addItem(ui_.x_combobox->currentText());
219 apply_changes();
220}
221
222void QtCoordFrameDialog::mod_x_plane()
223{
224 ui_.x_combobox->setItemText(ui_.x_combobox->currentIndex(),ui_.x_combobox->currentText());
225 apply_changes();
226}
227
228void QtCoordFrameDialog::del_x_plane()
229{
230 ui_.x_combobox->removeItem(ui_.x_combobox->currentIndex());
231 apply_changes();
232}
233
234
235//-----------------------------------------------------------------------------
236
237
238void QtCoordFrameDialog::add_y_plane()
239{
240 ui_.y_combobox->addItem(ui_.y_combobox->currentText());
241 apply_changes();
242}
243
244void QtCoordFrameDialog::mod_y_plane()
245{
246 ui_.y_combobox->setItemText(ui_.y_combobox->currentIndex(),ui_.y_combobox->currentText());
247 apply_changes();
248}
249
250void QtCoordFrameDialog::del_y_plane()
251{
252 ui_.y_combobox->removeItem(ui_.y_combobox->currentIndex());
253 apply_changes();
254}
255
256
257//-----------------------------------------------------------------------------
258
259
260void QtCoordFrameDialog::add_z_plane()
261{
262 ui_.z_combobox->addItem(ui_.z_combobox->currentText());
263 apply_changes();
264}
265
266void QtCoordFrameDialog::mod_z_plane()
267{
268 ui_.z_combobox->setItemText(ui_.z_combobox->currentIndex(),ui_.z_combobox->currentText());
269 apply_changes();
270}
271
272void QtCoordFrameDialog::del_z_plane()
273{
274 ui_.z_combobox->removeItem(ui_.z_combobox->currentIndex());
275 apply_changes();
276}
277
278
279//=============================================================================
280} // namespace QtWidgets
281} // namespace ACG
282//=============================================================================
Namespace providing different geometric functions concerning angles.