42 #include "ui_filterdesignview.h"
57 #include <QFileDialog>
58 #include <QStandardPaths>
59 #include <QSvgGenerator>
62 #include <QApplication>
74 using namespace DISPLIB;
75 using namespace FIFFLIB;
76 using namespace UTILSLIB;
77 using namespace RTPROCESSINGLIB;
87 , m_pUi(new Ui::FilterDesignViewWidget)
116 if(iMaxNumberFilterTaps%2 != 0) {
117 iMaxNumberFilterTaps--;
120 m_pUi->m_spinBox_filterTaps->setMaximum(iMaxNumberFilterTaps);
121 m_pUi->m_spinBox_filterTaps->setMinimum(16);
131 return m_pUi->m_spinBox_filterTaps->value();
138 if(dSamplingRate <= 0) {
139 qWarning() <<
"[FilterDesignView::setSamplingRate] Sampling frequency is <= 0. Returning.";
145 double nyquistFrequency =
m_dSFreq/2;
147 m_pUi->m_doubleSpinBox_to->setMaximum(nyquistFrequency);
148 m_pUi->m_doubleSpinBox_from->setMaximum(nyquistFrequency);
167 m_pUi->m_doubleSpinBox_from->setValue(dFrom);
175 m_pUi->m_doubleSpinBox_to->setValue(dTo);
190 return m_pUi->m_comboBox_filterApplyTo->currentText();
197 m_pUi->m_comboBox_filterApplyTo->setCurrentText(sType);
209 QSettings settings(
"MNECPP");
214 settings.setValue(
m_sSettingsPath + QString(
"/FilterDesignView/filterDesignMethod"), FilterKernel::m_designMethods.indexOf(
m_filterKernel.getDesignMethod()));
217 settings.setValue(
m_sSettingsPath + QString(
"/FilterDesignView/Position"), this->pos());
228 QSettings settings(
"MNECPP");
231 m_pUi->m_doubleSpinBox_to->setValue(settings.value(
m_sSettingsPath + QString(
"/FilterDesignView/filterTo"), 40.0).toDouble());
232 m_pUi->m_doubleSpinBox_from->setValue(settings.value(
m_sSettingsPath + QString(
"/FilterDesignView/filterFrom"), 1.0).toDouble());
233 m_pUi->m_spinBox_filterTaps->setValue(settings.value(
m_sSettingsPath + QString(
"/FilterDesignView/filterOrder"), 128).toInt());
234 m_pUi->m_comboBox_designMethod->setCurrentIndex(settings.value(
m_sSettingsPath + QString(
"/FilterDesignView/filterDesignMethod"), FilterKernel::m_designMethods.indexOf(
FilterParameter(
"Cosine"))).toInt());
235 m_pUi->m_doubleSpinBox_transitionband->setValue(settings.value(
m_sSettingsPath + QString(
"/FilterDesignView/filterTransition"), 0.1).toDouble());
236 m_pUi->m_comboBox_filterApplyTo->setCurrentText(settings.value(
m_sSettingsPath + QString(
"/FilterDesignView/filterChannelType"),
"All").toString());
238 QPoint pos = settings.value(
m_sSettingsPath + QString(
"/FilterDesignView/Position"), QPoint(100,100)).toPoint();
240 QRect screenRect = QApplication::primaryScreen()->geometry();
241 if(!screenRect.contains(pos) && QGuiApplication::screens().size() == 1) {
242 move(QPoint(100,100));
253 case GuiMode::Clinical:
265 case ProcessingMode::Offline:
276 connect(
m_pUi->m_doubleSpinBox_from, &QDoubleSpinBox::editingFinished,
279 connect(
m_pUi->m_doubleSpinBox_to, &QDoubleSpinBox::editingFinished,
282 connect(
m_pUi->m_doubleSpinBox_transitionband, &QDoubleSpinBox::editingFinished,
285 connect(
m_pUi->m_spinBox_filterTaps, &QSpinBox::editingFinished,
289 m_pUi->m_doubleSpinBox_from->installEventFilter(
this);
290 m_pUi->m_doubleSpinBox_to->installEventFilter(
this);
291 m_pUi->m_doubleSpinBox_transitionband->installEventFilter(
this);
298 connect(
m_pUi->m_pushButton_exportPlot,&QPushButton::released,
301 connect(
m_pUi->m_pushButton_exportFilter,&QPushButton::released,
304 connect(
m_pUi->m_pushButton_loadFilter,&QPushButton::released,
313 m_pUi->m_comboBox_designMethod->addItem(filterMethod.getName());
316 connect(
m_pUi->m_comboBox_designMethod,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
320 m_pUi->m_doubleSpinBox_from->setVisible(
true);
321 m_pUi->m_label_lowpass->setVisible(
true);
323 m_pUi->m_doubleSpinBox_to->setVisible(
true);
324 m_pUi->m_label_highpass->setVisible(
true);
326 m_pUi->m_spinBox_filterTaps->setVisible(
true);
327 m_pUi->m_label_filterTaps->setVisible(
true);
329 connect(
m_pUi->m_comboBox_filterApplyTo, &QComboBox::currentTextChanged,
340 m_pUi->m_graphicsView_filterPlot->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
341 m_pUi->m_graphicsView_filterPlot->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
358 if(event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
362 if((event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_Z) || event->key() == Qt::Key_Delete) {
374 m_pUi->m_doubleSpinBox_from->value(),
375 m_pUi->m_doubleSpinBox_to->value());
384 Q_UNUSED(currentIndex);
387 switch(
m_pUi->m_comboBox_designMethod->currentIndex()) {
391 m_pUi->m_spinBox_filterTaps->setVisible(
true);
392 m_pUi->m_label_filterTaps->setVisible(
true);
396 m_pUi->m_spinBox_filterTaps->setVisible(
true);
397 m_pUi->m_label_filterTaps->setVisible(
true);
412 double from =
m_pUi->m_doubleSpinBox_from->value();
413 double to =
m_pUi->m_doubleSpinBox_to->value();
415 double trans_width =
m_pUi->m_doubleSpinBox_transitionband->value();
418 double center = from+bw/2;
420 double nyquistFrequency =
m_dSFreq/2;
424 if(
m_pUi->m_spinBox_filterTaps->value()%2 != 0) {
429 m_pUi->m_doubleSpinBox_to->setMaximum(nyquistFrequency);
430 m_pUi->m_doubleSpinBox_from->setMaximum(nyquistFrequency);
431 m_pUi->m_doubleSpinBox_to->setMinimum(0);
432 m_pUi->m_doubleSpinBox_from->setMinimum(0);
434 if((
m_pUi->m_doubleSpinBox_to->value() <
m_pUi->m_doubleSpinBox_from->value())) {
435 m_pUi->m_doubleSpinBox_to->setValue(
m_pUi->m_doubleSpinBox_from->value() + 1);
438 m_pUi->m_doubleSpinBox_to->setMinimum(
m_pUi->m_doubleSpinBox_from->value());
439 m_pUi->m_doubleSpinBox_from->setMaximum(
m_pUi->m_doubleSpinBox_to->value());
441 int iMethod = FilterKernel::m_designMethods.indexOf(
FilterParameter(
m_pUi->m_comboBox_designMethod->currentText()));
447 (
double)center/nyquistFrequency,
448 (
double)bw/nyquistFrequency,
449 (
double)trans_width/nyquistFrequency,
474 QString fileName = QFileDialog::getSaveFileName(
this,
476 QString(
"%1/%2_%3_%4_FilterPlot").arg(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)).arg(date.currentDate().year()).arg(date.currentDate().month()).arg(date.currentDate().day()),
477 tr(
"Vector graphic(*.svg);;Images (*.png)"));
479 if(!fileName.isEmpty()) {
481 if(fileName.contains(
".svg")) {
482 QSvgGenerator svgGen;
484 svgGen.setFileName(fileName);
486 svgGen.setSize(QSize(rect.width(), rect.height()));
489 QPainter painter(&svgGen);
493 if(fileName.contains(
".png")) {
496 image.fill(Qt::transparent);
498 QPainter painter(&image);
500 image.save(fileName);
516 filterWriteTemp.getName() = filtername;
518 QString fileName = QFileDialog::getSaveFileName(
this,
519 "Save filter coefficients",
520 QString(
"%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)).arg(filtername),
521 tr(
"Text file(*.txt)"));
523 FilterIO::writeFilter(fileName, filterWriteTemp);
530 QString path = QFileDialog::getOpenFileName(
this,
531 QString(
"Load filter"),
533 tr(
"txt files (*.txt)"));
535 if(!path.isEmpty()) {
539 if(!FilterIO::readFilter(path, filterLoadTemp)) {
549 qDebug()<<
"Could not load filter.";
564 return m_pUi->m_doubleSpinBox_from->value();
571 return m_pUi->m_doubleSpinBox_to->value();
578 m_pUi->m_doubleSpinBox_from->setValue(filter.getHighpassFreq());
579 m_pUi->m_doubleSpinBox_to->setValue(filter.getLowpassFreq());
580 m_pUi->m_spinBox_filterTaps->setValue(filter.getFilterOrder());
581 m_pUi->m_doubleSpinBox_transitionband->setValue(filter.getParksWidth()*(filter.getSamplingFrequency()/2));
583 m_pUi->m_comboBox_designMethod->setCurrentIndex(FilterKernel::m_designMethods.indexOf(filter.getDesignMethod()));