Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QtCoordFrameDialog.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openflipper.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenFlipper. *
9  * *
10  * OpenFlipper is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenFlipper is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenFlipper. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 10745 $ *
38  * $Author: moebius $ *
39  * $Date: 2011-01-26 10:23:50 +0100 (Mi, 26 Jan 2011) $ *
40  * *
41 \*===========================================================================*/
42 
43 
44 
45 //=============================================================================
46 //
47 // CLASS QtCoordFrameDialog - IMPLEMENTATION
48 //
49 //=============================================================================
50 
51 
52 //== INCLUDES =================================================================
53 
54 #include "QtCoordFrameDialog.hh"
55 #include "../Scenegraph/CoordFrameNode.hh"
56 
57 #include <qcombobox.h>
58 #include <qpushbutton.h>
59 #include <qgroupbox.h>
60 
61 
62 //== NAMESPACES ==============================================================
63 
64 
65 namespace ACG {
66 namespace QtWidgets {
67 
68 
69 //== IMPLEMENTATION ==========================================================
70 
71 
72 QtCoordFrameDialog::
73 QtCoordFrameDialog( QWidget* _parent,
74  SceneGraph::CoordFrameNode* _node,
75  Qt::WFlags _fl )
76 
77  : QDialog(_parent, _fl),
78  node_(_node)
79 
80 {
81  ui_.setupUi( this );
82 
83  connect( ui_.OkButton, SIGNAL( clicked() ), this, SLOT( apply_changes() ) );
84  connect( ui_.OkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
85  connect( ui_.ApplyButton, SIGNAL( clicked() ), this, SLOT( apply_changes() ) );
86  connect( ui_.CancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
87  connect( ui_.CancelButton, SIGNAL( clicked() ), this, SLOT( undo_changes() ) );
88  connect( ui_.x_add_button, SIGNAL( clicked() ), this, SLOT( add_x_plane() ) );
89  connect( ui_.x_mod_button, SIGNAL( clicked() ), this, SLOT( mod_x_plane() ) );
90  connect( ui_.x_del_button, SIGNAL( clicked() ), this, SLOT( del_x_plane() ) );
91  connect( ui_.y_add_button, SIGNAL( clicked() ), this, SLOT( add_y_plane() ) );
92  connect( ui_.y_mod_button, SIGNAL( clicked() ), this, SLOT( mod_y_plane() ) );
93  connect( ui_.y_del_button, SIGNAL( clicked() ), this, SLOT( del_y_plane() ) );
94  connect( ui_.z_add_button, SIGNAL( clicked() ), this, SLOT( add_z_plane() ) );
95  connect( ui_.z_mod_button, SIGNAL( clicked() ), this, SLOT( mod_z_plane() ) );
96  connect( ui_.z_del_button, SIGNAL( clicked() ), this, SLOT( del_z_plane() ) );
97 
98  update_values();
99 }
100 
101 
102 //-----------------------------------------------------------------------------
103 
104 
105 void
106 QtCoordFrameDialog::show()
107 {
108  update_values();
109  QDialog::show();
110 }
111 
112 
113 //-----------------------------------------------------------------------------
114 
115 
116 void
117 QtCoordFrameDialog::update_values()
118 {
119  x_planes_bak_ = node_->x_planes();
120  y_planes_bak_ = node_->y_planes();
121  z_planes_bak_ = node_->z_planes();
122 
123  planes2combo(x_planes_bak_, ui_.x_combobox);
124  planes2combo(y_planes_bak_, ui_.y_combobox);
125  planes2combo(z_planes_bak_, ui_.z_combobox);
126 
127 
128  QString s, title;
129 
130  title = ( QString("X-Planes: [") +
131  s.setNum(node_->bb_min()[0], 'f', 4) +
132  QString(", ") +
133  s.setNum(node_->bb_max()[0], 'f', 4) +
134  QString("]") );
135  ui_.x_groupbox->setTitle(title);
136 
137  title = ( QString("Y-Planes: [") +
138  s.setNum(node_->bb_min()[1], 'f', 4) +
139  QString(", ") +
140  s.setNum(node_->bb_max()[1], 'f', 4) +
141  QString("]") );
142  ui_.y_groupbox->setTitle(title);
143 
144  title = ( QString("Z-Planes: [") +
145  s.setNum(node_->bb_min()[2], 'f', 4) +
146  QString(", ") +
147  s.setNum(node_->bb_max()[2], 'f', 4) +
148  QString("]") );
149  ui_.z_groupbox->setTitle(title);
150 }
151 
152 
153 //-----------------------------------------------------------------------------
154 
155 
156 void
157 QtCoordFrameDialog::combo2planes(const QComboBox* _combo,
158  std::vector<float>& _planes)
159 {
160  unsigned int i(0), N(_combo->count());
161 
162  _planes.clear();
163  _planes.reserve(N);
164 
165  for (; i<N; ++i)
166  _planes.push_back(_combo->itemText(i).toFloat());
167 }
168 
169 
170 void
171 QtCoordFrameDialog::planes2combo(const std::vector<float>& _planes,
172  QComboBox* _combo)
173 {
174  std::vector<float>::const_iterator p_it, p_end;
175  QString s;
176 
177  _combo->clear();
178  for (p_it=_planes.begin(), p_end=_planes.end(); p_it!=p_end; ++p_it)
179  _combo->addItem(s.setNum(*p_it, 'f', 3));
180 }
181 
182 
183 //-----------------------------------------------------------------------------
184 
185 
186 void QtCoordFrameDialog::apply_changes()
187 {
188  std::vector<float> planes;
189 
190  combo2planes(ui_.x_combobox, planes);
191  node_->set_x_planes(planes);
192 
193  combo2planes(ui_.y_combobox, planes);
194  node_->set_y_planes(planes);
195 
196  combo2planes(ui_.z_combobox, planes);
197  node_->set_z_planes(planes);
198 
199  emit signalNodeChanged(node_);
200 }
201 
202 
203 //-----------------------------------------------------------------------------
204 
205 
206 void QtCoordFrameDialog::undo_changes()
207 {
208  node_->set_x_planes(x_planes_bak_);
209  node_->set_y_planes(y_planes_bak_);
210  node_->set_z_planes(z_planes_bak_);
211 
212  emit signalNodeChanged(node_);
213 }
214 
215 
216 //-----------------------------------------------------------------------------
217 
218 
219 void QtCoordFrameDialog::add_x_plane()
220 {
221  ui_.x_combobox->addItem(ui_.x_combobox->currentText());
222  apply_changes();
223 }
224 
225 void QtCoordFrameDialog::mod_x_plane()
226 {
227  ui_.x_combobox->setItemText(ui_.x_combobox->currentIndex(),ui_.x_combobox->currentText());
228  apply_changes();
229 }
230 
231 void QtCoordFrameDialog::del_x_plane()
232 {
233  ui_.x_combobox->removeItem(ui_.x_combobox->currentIndex());
234  apply_changes();
235 }
236 
237 
238 //-----------------------------------------------------------------------------
239 
240 
241 void QtCoordFrameDialog::add_y_plane()
242 {
243  ui_.y_combobox->addItem(ui_.y_combobox->currentText());
244  apply_changes();
245 }
246 
247 void QtCoordFrameDialog::mod_y_plane()
248 {
249  ui_.y_combobox->setItemText(ui_.y_combobox->currentIndex(),ui_.y_combobox->currentText());
250  apply_changes();
251 }
252 
253 void QtCoordFrameDialog::del_y_plane()
254 {
255  ui_.y_combobox->removeItem(ui_.y_combobox->currentIndex());
256  apply_changes();
257 }
258 
259 
260 //-----------------------------------------------------------------------------
261 
262 
263 void QtCoordFrameDialog::add_z_plane()
264 {
265  ui_.z_combobox->addItem(ui_.z_combobox->currentText());
266  apply_changes();
267 }
268 
269 void QtCoordFrameDialog::mod_z_plane()
270 {
271  ui_.z_combobox->setItemText(ui_.z_combobox->currentIndex(),ui_.z_combobox->currentText());
272  apply_changes();
273 }
274 
275 void QtCoordFrameDialog::del_z_plane()
276 {
277  ui_.z_combobox->removeItem(ui_.z_combobox->currentIndex());
278  apply_changes();
279 }
280 
281 
282 //=============================================================================
283 } // namespace QtWidgets
284 } // namespace ACG
285 //=============================================================================