All Classes Namespaces Files Functions Variables Enumerations Enumerator
programs/UrgViewer/CaptureSettingWidget.cpp
Go to the documentation of this file.
00001 
00010 #include "CaptureSettingWidget.h"
00011 #include "RangeViewWidget.h"
00012 #include "RangeSensor.h"
00013 #include "RangeSensorParameter.h"
00014 #include <QShortcut>
00015 
00016 using namespace qrk;
00017 
00018 
00019 struct CaptureSettingWidget::pImpl
00020 {
00021     CaptureSettingWidget* widget_;
00022 
00023     const RangeSensor& sensor_;
00024     QButtonGroup mode_group_;
00025     QButtonGroup times_group_;
00026 
00027     RangeSensorParameter parameter_;
00028 
00029     RangeViewWidget range_view_widget_;
00030 
00031     bool apply_completed_;
00032 
00033 
00034     pImpl(CaptureSettingWidget* widget, const RangeSensor& sensor)
00035         : widget_(widget), sensor_(sensor), range_view_widget_(widget_),
00036           apply_completed_(true)
00037     {
00038     }
00039 
00040 
00041     void initializeForm(void)
00042     {
00043         // フォーム
00044         widget_->intensity_button_->hide();
00045         widget_->dummy_label_->hide();
00046         widget_->preview_layout_->addWidget(&range_view_widget_);
00047 
00048         // モード
00049         mode_group_.addButton(widget_->intensity_button_, ME);
00050         mode_group_.addButton(widget_->gd_button_, GD);
00051         mode_group_.addButton(widget_->md_button_, MD);
00052         times_group_.addButton(widget_->infinity_times_button_);
00053         times_group_.addButton(widget_->n_times_button_);
00054 
00055         // フォームイベント
00056         connect(widget_->apply_button_, SIGNAL(clicked()),
00057                 widget_, SLOT(applyPressed()));
00058         connect(widget_->cancel_button_, SIGNAL(clicked()),
00059                 widget_, SLOT(close()));
00060         connect(widget_->load_button_, SIGNAL(clicked()),
00061                 widget_, SLOT(loadPressed()));
00062         connect(&mode_group_, SIGNAL(buttonClicked(int)),
00063                 widget_, SLOT(modeChanged(int)));
00064 
00065         connect(widget_->range_first_spinbox_, SIGNAL(editingFinished()),
00066                 widget_, SLOT(firstFinished()));
00067         connect(widget_->range_last_spinbox_, SIGNAL(editingFinished()),
00068                 widget_, SLOT(lastFinished()));
00069         connect(widget_->range_first_spinbox_, SIGNAL(valueChanged(int)),
00070                 widget_, SLOT(isRangeChanged()));
00071         connect(widget_->range_last_spinbox_, SIGNAL(valueChanged(int)),
00072                 widget_, SLOT(isRangeChanged()));
00073 
00074         connect(&times_group_, SIGNAL(buttonClicked(int)),
00075                 widget_, SLOT(timesChanged()));
00076 
00077         connect(widget_->line_group_spinbox_, SIGNAL(valueChanged(int)),
00078                 widget_, SLOT(lineGroupsChanged()));
00079         connect(widget_->frame_skips_spinbox_, SIGNAL(valueChanged(int)),
00080                 widget_, SLOT(frameSkipsChanged()));
00081         connect(widget_->capture_times_spinbox_, SIGNAL(valueChanged(int)),
00082                 widget_, SLOT(captureTimesChanged()));
00083 
00084 
00085         // キー割り付け
00086         (void)new QShortcut(Qt::CTRL + Qt::Key_Q, widget_, SLOT(quitPressed()));
00087         (void)new QShortcut(Qt::CTRL + Qt::Key_W, widget_, SLOT(close()));
00088 
00089         // 初期設定
00090         setMode(MD);
00091         setTimes(InfinityTimes);
00092     }
00093 
00094 
00095     void createSettings(CaptureSettings& settings)
00096     {
00097         settings.type = static_cast<CaptureType>(mode_group_.checkedId());
00098 
00099         settings.capture_first = widget_->range_first_spinbox_->value();
00100         settings.capture_last = widget_->range_last_spinbox_->value();
00101         settings.skip_lines = widget_->line_group_spinbox_->value();
00102         settings.skip_frames = widget_->frame_skips_spinbox_->value();
00103         if (widget_->infinity_times_button_->isChecked()) {
00104             settings.remain_times = 0;
00105         } else {
00106             settings.remain_times = widget_->capture_times_spinbox_->value();
00107         }
00108     }
00109 
00110 
00111     void setMode(int type)
00112     {
00113         QAbstractButton* selected_button = mode_group_.button(type);
00114         if (selected_button) {
00115             selected_button->click();
00116         }
00117     }
00118 
00119 
00120     void setTimes(size_t times)
00121     {
00122         if (times <= 99) {
00123             widget_->n_times_button_->click();
00124         } else {
00125             widget_->infinity_times_button_->click();
00126         }
00127     }
00128 
00129 
00130     void setTimesEnabled(bool enable)
00131     {
00132         bool infinity_checked = widget_->infinity_times_button_->isChecked();
00133         bool n_times_checked = (! infinity_checked);
00134 
00135         widget_->infinity_times_button_->setEnabled(enable);
00136         widget_->n_times_button_->setEnabled(enable);
00137         widget_->capture_times_spinbox_->setEnabled(enable && n_times_checked);
00138     }
00139 
00140 
00141     void updateApplyButton(void)
00142     {
00143         if (apply_completed_) {
00144             widget_->apply_button_->setEnabled(true);
00145         }
00146     }
00147 };
00148 
00149 
00150 CaptureSettingWidget::CaptureSettingWidget(const qrk::RangeSensor& sensor,
00151                                            QWidget* parent)
00152     : QWidget(parent), pimpl(new pImpl(this, sensor))
00153 {
00154     setupUi(this);
00155     pimpl->initializeForm();
00156 }
00157 
00158 
00159 CaptureSettingWidget::~CaptureSettingWidget(void)
00160 {
00161 }
00162 
00163 
00164 void CaptureSettingWidget::closeEvent(QCloseEvent* event)
00165 {
00166     static_cast<void>(event);
00167 
00168     emit widgetClose("CaptureSettingWidget");
00169     close();
00170 }
00171 
00172 
00173 void CaptureSettingWidget::applyPressed(void)
00174 {
00175     apply_button_->setEnabled(false);
00176 
00177     pimpl->apply_completed_ = false;
00178 
00179     CaptureSettings settings;
00180     pimpl->createSettings(settings);
00181 
00182     // 新しいパラメータを送信
00183     emit setCaptureSettings(settings);
00184 
00185     // 再接続の要求を送信
00186     emit reconnectRequest();
00187 }
00188 
00189 
00190 void CaptureSettingWidget::loadPressed(void)
00191 {
00192     if (! pimpl->sensor_.isConnected()) {
00193         return;
00194     }
00195 
00196     pimpl->parameter_ = pimpl->sensor_.parameter();
00197     pimpl->range_view_widget_.setParameter(pimpl->parameter_);
00198 
00199     // 読み出した取得範囲の情報を、フォームに反映させる
00200     int first_index = pimpl->parameter_.area_min;
00201     int last_index = pimpl->parameter_.area_max;
00202     range_first_spinbox_->setValue(first_index);
00203     range_last_spinbox_->setValue(last_index);
00204 
00205     setApplyEnabled(true);
00206 
00207     emit rangeChanged(first_index, last_index);
00208 }
00209 
00210 
00211 void CaptureSettingWidget::reconnectCompleted(void)
00212 {
00213     pimpl->apply_completed_ = true;
00214 }
00215 
00216 
00217 void CaptureSettingWidget::firstFinished(void)
00218 {
00219     // last の値を first 以上にする
00220     int first_value = range_first_spinbox_->value();
00221     if (first_value > range_last_spinbox_->value()) {
00222         range_last_spinbox_->setValue(first_value);
00223     }
00224 }
00225 
00226 
00227 void CaptureSettingWidget::lastFinished(void)
00228 {
00229     int last_value = range_last_spinbox_->value();
00230 
00231     // !!! この実装が汚いのをなんとかする
00232     if (pimpl->parameter_.area_min != pimpl->parameter_.area_max) {
00233         // パラメータ読み出し後のみ、制限をつける
00234         if (last_value > pimpl->parameter_.area_max) {
00235             last_value = pimpl->parameter_.area_max;
00236             range_last_spinbox_->setValue(last_value);
00237         }
00238     }
00239 
00240     // first の値を last 以下にする
00241     if (last_value < range_first_spinbox_->value()) {
00242         range_first_spinbox_->setValue(last_value);
00243     }
00244 }
00245 
00246 
00247 void CaptureSettingWidget::isRangeChanged(void)
00248 {
00249     emit rangeChanged(range_first_spinbox_->value(),
00250                       range_last_spinbox_->value());
00251 
00252     pimpl->updateApplyButton();
00253 }
00254 
00255 
00256 void CaptureSettingWidget::modeChanged(int type)
00257 {
00258     // GD, MD 各モードでの setEnable() を調整する
00259     bool md_enable = ((type == MD) || (type == ME)) ? true : false;
00260 
00261     frame_skips_label_->setEnabled(md_enable);
00262     frame_skips_spinbox_->setEnabled(md_enable);
00263 
00264     capture_times_label_->setEnabled(md_enable);
00265     pimpl->setTimesEnabled(md_enable);
00266 
00267     pimpl->updateApplyButton();
00268 }
00269 
00270 
00271 void CaptureSettingWidget::timesChanged(void)
00272 {
00273     // Infinity のときに、n_times_spinbox_ を無効にする
00274     pimpl->setTimesEnabled(true);
00275 
00276     pimpl->updateApplyButton();
00277 }
00278 
00279 
00280 void CaptureSettingWidget::setIntensityMode(bool enable_cluster)
00281 {
00282     intensity_button_->show();
00283     setMode(ME);
00284     gd_button_->hide();
00285     md_button_->hide();
00286 
00287     // UTM 以外の場合は "まとめる数" の属性が指定できないため、無効にする
00288     line_group_label_->setEnabled(enable_cluster);
00289     line_group_spinbox_->setEnabled(enable_cluster);
00290 }
00291 
00292 
00293 void CaptureSettingWidget::setMode(CaptureType type)
00294 {
00295     pimpl->setMode(type);
00296 }
00297 
00298 
00299 void CaptureSettingWidget::setTimes(size_t times)
00300 {
00301     pimpl->setTimes(times);
00302 }
00303 
00304 
00305 void CaptureSettingWidget::setApplyEnabled(bool enable)
00306 {
00307     apply_button_->setEnabled(enable);
00308 }
00309 
00310 
00311 void CaptureSettingWidget::quitPressed(void)
00312 {
00313     emit quit();
00314 }
00315 
00316 
00317 void CaptureSettingWidget::setConnected(bool connection)
00318 {
00319     load_button_->setEnabled(connection);
00320 }
00321 
00322 
00323 void CaptureSettingWidget::lineGroupsChanged(void)
00324 {
00325     pimpl->updateApplyButton();
00326 }
00327 
00328 
00329 void CaptureSettingWidget::frameSkipsChanged(void)
00330 {
00331     pimpl->updateApplyButton();
00332 }
00333 
00334 
00335 void CaptureSettingWidget::captureTimesChanged(void)
00336 {
00337     pimpl->updateApplyButton();
00338 }