MNE-CPP  beta 1.0
enhancededitorwindow.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "enhancededitorwindow.h"
42 #include "ui_enhancededitorwindow.h"
43 
44 #include "deletemessagebox.h"
45 #include "ui_deletemessagebox.h"
46 
47 #include "formulaeditor.h"
48 
49 //*************************************************************************************************************
50 //=============================================================================================================
51 // QT INCLUDES
52 //=============================================================================================================
53 
54 #include "QtGui"
55 #include <QWidget>
56 #include <QMessageBox>
57 
58 //*************************************************************************************************************
59 //=============================================================================================================
60 // USED NAMESPACES
61 //=============================================================================================================
62 
63 
64 
65 //*************************************************************************************************************
66 //=============================================================================================================
67 // MAIN
68 //=============================================================================================================
69 
70 qint32 _atom_count = 1;
71 qint32 _sample_count = 64;
72 QList<qreal> value_a_list;
73 QList<qreal> value_b_list;
74 QList<qreal> value_c_list;
75 QList<qreal> value_d_list;
76 QList<qreal> value_e_list;
77 QList<qreal> value_f_list;
78 QList<qreal> value_g_list;
79 QList<qreal> value_h_list;
80 QStringList _names_list;
81 
82 //***********************************************************************************************************************
83 
84 //constructor
85 Enhancededitorwindow::Enhancededitorwindow(QWidget *parent): QWidget(parent), ui(new Ui::Enhancededitorwindow)
86 {
87  this->setAccessibleName("formel");
88  ui->setupUi(this);
89 
90  QSettings settings;
91  move(settings.value("pos_enhanced_editor", QPoint(200, 200)).toPoint());
92 
93  m_strStandardFunction.append("");
94  m_strStandardFunction.append("PI");
95  m_strStandardFunction.append("ABS");
96  m_strStandardFunction.append("SQRT");
97  m_strStandardFunction.append("SINH");
98  m_strStandardFunction.append("COSH");
99  m_strStandardFunction.append("TANH");
100  m_strStandardFunction.append("ARCTAN");
101  m_strStandardFunction.append("LN");
102  m_strStandardFunction.append("LOG");
103  m_strStandardFunction.append("EXP");
104  m_strStandardFunction.append("SIN"); //must be addended behind SINH!!!
105  m_strStandardFunction.append("COS");
106  m_strStandardFunction.append("TAN");
107  m_strStandardFunction.append("COT");
108  m_strStandardFunction.append("ARCSIN");
109  m_strStandardFunction.append("ARCCOS");
110  m_strStandardFunction.append("INT");
111  m_strStandardFunction.append("RAD");
112  m_strStandardFunction.append("DEG");
113  m_strStandardFunction.append("SIGN");
114  m_strStandardFunction.append("ARSINH");
115  m_strStandardFunction.append("ARCOSH");
116  m_strStandardFunction.append("ARTANH");
117  m_strStandardFunction.append("KGV");
118  m_strStandardFunction.append("GGT");
119 
120  read_formula();
121 }
122 
123 //***********************************************************************************************************************
124 
125 Enhancededitorwindow::~Enhancededitorwindow()
126 {
127  delete ui;
128 }
129 
130 //*************************************************************************************************************************************
131 
132 void Enhancededitorwindow::closeEvent(QCloseEvent * event)
133 {
134  Q_UNUSED(event);
135  QSettings settings;
136  if(!this->isMaximized())
137  {
138  settings.setValue("pos_enhanced_editor", pos());
139  }
140 }
141 
142 //*************************************************************************************************************************************
143 
144 
145 void Enhancededitorwindow::on_formula_saved()
146 {
147  read_formula();
148 }
149 
150 //*************************************************************************************************************************************
151 
152 
153 void Enhancededitorwindow::read_formula()
154 {
155  _names_list.clear();
156  ui->cb_AtomFormula->clear();
157 
158  QString contents;
159  QFile formula_file(QDir::homePath() + "/" + "Matching-Pursuit-Toolbox/user.fml");
160 
161  if (formula_file.open(QIODevice::ReadOnly | QIODevice::Text))
162  {
163  while(!formula_file.atEnd())
164  {
165  contents = formula_file.readLine(0).constData();
166  ui->cb_AtomFormula->addItem(QIcon(":/images/icons/formel.png"), contents.trimmed());
167  }
168  }
169  formula_file.close();
170 
171  QDir dictDir = QDir(QDir::homePath() + "/" + "Matching-Pursuit-Toolbox");
172 
173  QStringList filterList;
174  filterList.append("*.dict");
175  filterList.append("*.pdict");
176 
177  QFileInfoList fileList = dictDir.entryInfoList(filterList);
178  for(int i = 0; i < fileList.length(); i++)
179  _names_list.append(fileList.at(i).baseName());
180 
181  if(ui->cb_AtomFormula->count() != 0)
182  ui->cb_AtomFormula->setCurrentIndex(0);
183 }
184 
185 //***********************************************************************************************************************
186 
187 // when "all combined" toogelt
188 void Enhancededitorwindow::on_chb_allCombined_toggled(bool checked)
189 {
190  if(checked)
191  {
192  ui->sb_Atomcount->setEnabled(false);
193 
194  ui->dsb_StepVauleA->setEnabled(true);
195  ui->dsb_StepVauleB->setEnabled(true);
196  ui->dsb_StepVauleC->setEnabled(true);
197  ui->dsb_StepVauleD->setEnabled(true);
198  ui->dsb_StepVauleE->setEnabled(true);
199  ui->dsb_StepVauleF->setEnabled(true);
200  ui->dsb_StepVauleG->setEnabled(true);
201  ui->dsb_StepVauleH->setEnabled(true);
202 
203  ui->dsb_EndValueA->setEnabled(true);
204  ui->dsb_EndValueB->setEnabled(true);
205  ui->dsb_EndValueC->setEnabled(true);
206  ui->dsb_EndValueD->setEnabled(true);
207  ui->dsb_EndValueE->setEnabled(true);
208  ui->dsb_EndValueF->setEnabled(true);
209  ui->dsb_EndValueG->setEnabled(true);
210  ui->dsb_EndValueH->setEnabled(true);
211 
212  calc_atom_count_all_combined();
213  }
214  else
215  {
216  ui->sb_Atomcount->setEnabled(true);
217  ui->dsb_EndValueA->setEnabled(false);
218  ui->dsb_EndValueB->setEnabled(false);
219  ui->dsb_EndValueC->setEnabled(false);
220  ui->dsb_EndValueD->setEnabled(false);
221  ui->dsb_EndValueE->setEnabled(false);
222  ui->dsb_EndValueF->setEnabled(false);
223  ui->dsb_EndValueG->setEnabled(false);
224  ui->dsb_EndValueH->setEnabled(false);
225  }
226 }
227 
228 //***********************************************************************************************************************
229 
230 // when number of atoms is changing
231 void Enhancededitorwindow::on_sb_Atomcount_valueChanged(int arg1)
232 {
233  if(arg1 <= 1)
234  {
235  ui->dsb_StepVauleA->setEnabled(false);
236  ui->dsb_StepVauleB->setEnabled(false);
237  ui->dsb_StepVauleC->setEnabled(false);
238  ui->dsb_StepVauleD->setEnabled(false);
239  ui->dsb_StepVauleE->setEnabled(false);
240  ui->dsb_StepVauleF->setEnabled(false);
241  ui->dsb_StepVauleG->setEnabled(false);
242  ui->dsb_StepVauleH->setEnabled(false);
243  }
244  else
245  {
246  ui->dsb_StepVauleA->setEnabled(true);
247  ui->dsb_StepVauleB->setEnabled(true);
248  ui->dsb_StepVauleC->setEnabled(true);
249  ui->dsb_StepVauleD->setEnabled(true);
250  ui->dsb_StepVauleE->setEnabled(true);
251  ui->dsb_StepVauleF->setEnabled(true);
252  ui->dsb_StepVauleG->setEnabled(true);
253  ui->dsb_StepVauleH->setEnabled(true);
254  }
255 
256  if(!ui->chb_allCombined->isChecked())
257  {
258  if(ui->lb_A->isVisible()) ui->dsb_EndValueA->setValue(calc_end_value(ui->dsb_StartValueA->value(), ui->dsb_StepVauleA->value()));
259  if(ui->lb_B->isVisible()) ui->dsb_EndValueB->setValue(calc_end_value(ui->dsb_StartValueB->value(), ui->dsb_StepVauleB->value()));
260  if(ui->lb_C->isVisible()) ui->dsb_EndValueC->setValue(calc_end_value(ui->dsb_StartValueC->value(), ui->dsb_StepVauleC->value()));
261  if(ui->lb_D->isVisible()) ui->dsb_EndValueD->setValue(calc_end_value(ui->dsb_StartValueD->value(), ui->dsb_StepVauleD->value()));
262  if(ui->lb_E->isVisible()) ui->dsb_EndValueE->setValue(calc_end_value(ui->dsb_StartValueE->value(), ui->dsb_StepVauleE->value()));
263  if(ui->lb_F->isVisible()) ui->dsb_EndValueF->setValue(calc_end_value(ui->dsb_StartValueF->value(), ui->dsb_StepVauleF->value()));
264  if(ui->lb_G->isVisible()) ui->dsb_EndValueG->setValue(calc_end_value(ui->dsb_StartValueG->value(), ui->dsb_StepVauleG->value()));
265  if(ui->lb_H->isVisible()) ui->dsb_EndValueH->setValue(calc_end_value(ui->dsb_StartValueH->value(), ui->dsb_StepVauleH->value()));
266  }
267  _atom_count = arg1;
268 }
269 
270 //***********************************************************************************************************************
271 
272 void Enhancededitorwindow::on_sb_SampleCount_editingFinished()
273 {
274  _sample_count = ui->sb_SampleCount->value();
275 }
276 
277 //***********************************************************************************************************************
278 
279 // when formula is changed
280 void Enhancededitorwindow::on_cb_AtomFormula_currentIndexChanged(const QString &arg1)
281 {
282  QList<QChar> foundChar;
283  foundChar.clear();
284  for(qint32 i = 0; i < arg1.length(); i++)
285  {
286  bool beforeFound = false;
287  bool nextfound = false;
288  QChar upperChar = arg1.at(i).toUpper();
289  if((upperChar >= 'A' && upperChar <= 'H') || upperChar == 'X')
290  {
291  if(i != 0)
292  {
293  QChar beforeUpperChar = arg1.at(i - 1).toUpper();
294  if(beforeUpperChar < 'A' || (beforeUpperChar > 'Z' && beforeUpperChar < 126)) beforeFound = true;
295  }
296  else beforeFound = true;
297 
298  if(i < arg1.length() - 1)
299  {
300  QChar nextUpperChar = arg1.at(i+1).toUpper();
301  if(nextUpperChar < 'A' || (nextUpperChar > 'Z' && nextUpperChar < 126)) nextfound = true;
302  }
303  else nextfound = true;
304 
305 
306  if(beforeFound && nextfound)
307  {
308  if(upperChar == 'A') foundChar.append(upperChar);
309  else if(upperChar == 'B') foundChar.append(upperChar);
310  else if(upperChar == 'C') foundChar.append(upperChar);
311  else if(upperChar == 'D') foundChar.append(upperChar);
312  else if(upperChar == 'E') foundChar.append(upperChar);
313  else if(upperChar == 'F') foundChar.append(upperChar);
314  else if(upperChar == 'G') foundChar.append(upperChar);
315  else if(upperChar == 'H') foundChar.append(upperChar);
316  else if(upperChar == 'X') foundChar.append(upperChar);
317  }
318  }
319  }
320 
321  ui->gb_A->setHidden(true);
322  ui->gb_B->setHidden(true);
323  ui->gb_C->setHidden(true);
324  ui->gb_D->setHidden(true);
325  ui->gb_E->setHidden(true);
326  ui->gb_F->setHidden(true);
327  ui->gb_G->setHidden(true);
328  ui->gb_H->setHidden(true);
329 
330  for(qint32 j = 0; j < foundChar.length(); j++)
331  {
332  if(foundChar.at(j) =='A') ui->gb_A->setHidden(false);
333  else if(foundChar.at(j) =='B') ui->gb_B->setHidden(false);
334  else if(foundChar.at(j) =='C') ui->gb_C->setHidden(false);
335  else if(foundChar.at(j) =='D') ui->gb_D->setHidden(false);
336  else if(foundChar.at(j) =='E') ui->gb_E->setHidden(false);
337  else if(foundChar.at(j) =='F') ui->gb_F->setHidden(false);
338  else if(foundChar.at(j) =='G') ui->gb_G->setHidden(false);
339  else if(foundChar.at(j) =='H') ui->gb_H->setHidden(false);
340  }
341 
342  resize(minimumSize());
343  setFixedHeight(sizeHint().height()); // no user access
344 }
345 
346 //***********************************************************************************************************************
347 
348 void Enhancededitorwindow::on_btt_DeleteFormula_clicked()
349 {
350  QString contents;
351  QSettings settings;
352  if(settings.value("show_warnings", true).toBool())
353  {
354  DeleteMessageBox* msgBox = new DeleteMessageBox(this);
355  msgBox->setModal(true);
356  qint32 result = msgBox->exec();
357 
358  if(result == 0)
359  {
360  msgBox->close();
361  return;
362  }
363  msgBox->close();
364  }
365 
366  QFile formel_file(QDir::homePath() + "/" + "Matching-Pursuit-Toolbox/user.fml");
367  QFile formel_temp_file(QDir::homePath() + "/" + "Matching-Pursuit-Toolbox/user.temp");
368 
369  if(!formel_temp_file.exists())
370  {
371  if (formel_temp_file.open(QIODevice::ReadWrite | QIODevice::Text))
372  formel_temp_file.close();
373  }
374 
375  QTextStream stream( &formel_temp_file );
376  if (formel_file.open(QIODevice::ReadWrite | QIODevice::Text))
377  {
378  if (formel_temp_file.open (QIODevice::WriteOnly| QIODevice::Append))
379  {
380  while(!formel_file.atEnd())
381  {
382  contents = formel_file.readLine(0).constData();
383  if(!QString::compare(ui->cb_AtomFormula->currentText() + "\n", contents) == 0)
384  stream << contents;
385  }
386  }
387  }
388 
389  formel_file.close();
390  formel_temp_file.close();
391 
392  formel_file.remove();
393  formel_temp_file.rename(QDir::homePath() + "/" + "Matching-Pursuit-Toolbox/user.fml");
394 
395  ui->cb_AtomFormula->removeItem(ui->cb_AtomFormula->currentIndex());
396 }
397 
398 //***********************************************************************************************************************
399 
400 // calculates number of atoms if "combine all"
401 void Enhancededitorwindow::calc_atom_count_all_combined()
402 {
403  qint32 count = 0;
404  qint32 count_a = 1;
405  qint32 count_b = 1;
406  qint32 count_c = 1;
407  qint32 count_d = 1;
408  qint32 count_e = 1;
409  qint32 count_f = 1;
410  qint32 count_g = 1;
411  qint32 count_h = 1;
412 
413  if(value_a_list.length() != 0) count_a = value_a_list.length();
414  if(value_b_list.length() != 0) count_b = value_b_list.length();
415  if(value_c_list.length() != 0) count_c = value_c_list.length();
416  if(value_d_list.length() != 0) count_d = value_d_list.length();
417  if(value_e_list.length() != 0) count_e = value_e_list.length();
418  if(value_f_list.length() != 0) count_f = value_f_list.length();
419  if(value_g_list.length() != 0) count_g = value_g_list.length();
420  if(value_h_list.length() != 0) count_h = value_h_list.length();
421 
422  count = count_a * count_b * count_c * count_d * count_e * count_f * count_g * count_h;
423 
424  if(count > 10000000)
425  {
426  QMessageBox::warning(this, tr("Error"),
427  tr("The number of atoms is too large."));
428  //return;
429  }
430  ui->sb_Atomcount->setValue(count);
431 }
432 
433 //***********************************************************************************************************************
434 
435 QList<qreal> Enhancededitorwindow::calc_value_list(qreal start_value, qreal line_step_value, qreal end_value)
436 {
437  qreal atom_count = _atom_count;
438  QList<qreal> resultList;
439  if(ui->chb_allCombined->isChecked())
440  atom_count = (end_value - start_value + 1) / line_step_value;
441 
442  for(qint32 i = 0; i < atom_count; i++)
443  resultList.append(start_value + (i * line_step_value));
444 
445  return resultList;
446 }
447 
448 //***********************************************************************************************************************
449 
450 qreal Enhancededitorwindow::calc_end_value(qreal startValue, qreal linStepValue)
451 {
452  if(ui->sb_Atomcount->value() == 1)
453  return startValue;
454  return startValue + (_atom_count * linStepValue);
455 }
456 
457 //***********************************************************************************************************************
458 
459 void Enhancededitorwindow::on_dsb_StepVauleA_valueChanged(double arg1)
460 {
461  value_a_list = calc_value_list(ui->dsb_StartValueA->value(), arg1, ui->dsb_EndValueA->value());
462  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueA->setValue(calc_end_value(ui->dsb_StartValueA->value(), arg1));
463  if(ui->chb_allCombined->isChecked())
464  {
465  ui->dsb_EndValueA->setMinimum(ui->dsb_StartValueA->value() + arg1);
466  calc_atom_count_all_combined();
467  }
468 }
469 
470 void Enhancededitorwindow::on_dsb_StepVauleB_valueChanged(double arg1)
471 {
472  value_b_list = calc_value_list(ui->dsb_StartValueB->value(), arg1, ui->dsb_EndValueB->value());
473  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueB->setValue(calc_end_value(ui->dsb_StartValueB->value(), arg1));
474  if(ui->chb_allCombined->isChecked())
475  {
476  ui->dsb_EndValueB->setMinimum(ui->dsb_StartValueB->value() + arg1);
477  calc_atom_count_all_combined();
478  }
479 }
480 
481 void Enhancededitorwindow::on_dsb_StepVauleC_valueChanged(double arg1)
482 {
483  value_c_list = calc_value_list(ui->dsb_StartValueC->value(), arg1, ui->dsb_EndValueC->value());
484  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueC->setValue(calc_end_value(ui->dsb_StartValueC->value(), arg1));
485  if(ui->chb_allCombined->isChecked())
486  {
487  ui->dsb_EndValueC->setMinimum(ui->dsb_StartValueC->value() + arg1);
488  calc_atom_count_all_combined();
489  }
490 }
491 
492 void Enhancededitorwindow::on_dsb_StepVauleD_valueChanged(double arg1)
493 {
494  value_d_list = calc_value_list(ui->dsb_StartValueD->value(), arg1, ui->dsb_EndValueD->value());
495  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueD->setValue(calc_end_value(ui->dsb_StartValueD->value(), arg1));
496  if(ui->chb_allCombined->isChecked())
497  {
498  ui->dsb_EndValueD->setMinimum(ui->dsb_StartValueD->value() + arg1);
499  calc_atom_count_all_combined();
500  }
501 }
502 
503 void Enhancededitorwindow::on_dsb_StepVauleE_valueChanged(double arg1)
504 {
505  value_e_list = calc_value_list(ui->dsb_StartValueE->value(), arg1, ui->dsb_EndValueE->value());
506  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueE->setValue(calc_end_value(ui->dsb_StartValueE->value(), arg1));
507  if(ui->chb_allCombined->isChecked())
508  {
509  ui->dsb_EndValueE->setMinimum(ui->dsb_StartValueE->value() + arg1);
510  calc_atom_count_all_combined();
511  }
512 }
513 
514 void Enhancededitorwindow::on_dsb_StepVauleF_valueChanged(double arg1)
515 {
516  value_f_list = calc_value_list(ui->dsb_StartValueF->value(), arg1, ui->dsb_EndValueF->value());
517  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueF->setValue(calc_end_value(ui->dsb_StartValueF->value(), arg1));
518  if(ui->chb_allCombined->isChecked())
519  {
520  ui->dsb_EndValueF->setMinimum(ui->dsb_StartValueF->value() + arg1);
521  calc_atom_count_all_combined();
522  }
523 }
524 
525 void Enhancededitorwindow::on_dsb_StepVauleG_valueChanged(double arg1)
526 {
527  value_g_list = calc_value_list(ui->dsb_StartValueG->value(), arg1, ui->dsb_EndValueG->value());
528  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueG->setValue(calc_end_value(ui->dsb_StartValueG->value(), arg1));
529  if(ui->chb_allCombined->isChecked())
530  {
531  ui->dsb_EndValueG->setMinimum(ui->dsb_StartValueG->value() + arg1);
532  calc_atom_count_all_combined();
533  }
534 }
535 
536 void Enhancededitorwindow::on_dsb_StepVauleH_valueChanged(double arg1)
537 {
538  value_h_list = calc_value_list(ui->dsb_StartValueH->value(), arg1, ui->dsb_EndValueH->value());
539  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueH->setValue(calc_end_value(ui->dsb_StartValueH->value(), arg1));
540  if(ui->chb_allCombined->isChecked())
541  {
542  ui->dsb_EndValueH->setMinimum(ui->dsb_StartValueH->value() + arg1);
543  calc_atom_count_all_combined();
544  }
545 }
546 
547 //***********************************************************************************************************************
548 
549 
550 void Enhancededitorwindow::on_dsb_StartValueA_valueChanged(double arg1)
551 {
552  value_a_list = calc_value_list(arg1, ui->dsb_StepVauleA->value(), ui->dsb_EndValueA->value());
553  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueA->setValue(calc_end_value(arg1, ui->dsb_StepVauleA->value()));
554  if(ui->chb_allCombined->isChecked())
555  {
556  ui->dsb_EndValueA->setMinimum(arg1 + ui->dsb_StepVauleA->value());
557  calc_atom_count_all_combined();
558  }
559 }
560 
561 void Enhancededitorwindow::on_dsb_StartValueB_valueChanged(double arg1)
562 {
563  value_b_list = calc_value_list(arg1, ui->dsb_StepVauleB->value(), ui->dsb_EndValueB->value());
564  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueB->setValue(calc_end_value(arg1, ui->dsb_StepVauleB->value()));
565  if(ui->chb_allCombined->isChecked())
566  {
567  ui->dsb_EndValueA->setMinimum(arg1 + ui->dsb_StepVauleB->value());
568  calc_atom_count_all_combined();
569  }
570 }
571 
572 void Enhancededitorwindow::on_dsb_StartValueC_valueChanged(double arg1)
573 {
574  value_c_list = calc_value_list(arg1, ui->dsb_StepVauleC->value(), ui->dsb_EndValueC->value());
575  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueC->setValue(calc_end_value(arg1, ui->dsb_StepVauleC->value()));
576  if(ui->chb_allCombined->isChecked())
577  {
578  ui->dsb_EndValueA->setMinimum(arg1 + ui->dsb_StepVauleC->value());
579  calc_atom_count_all_combined();
580  }
581 }
582 
583 void Enhancededitorwindow::on_dsb_StartValueD_valueChanged(double arg1)
584 {
585  value_d_list = calc_value_list(arg1, ui->dsb_StepVauleD->value(), ui->dsb_EndValueD->value());
586  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueD->setValue(calc_end_value(arg1, ui->dsb_StepVauleD->value()));
587  if(ui->chb_allCombined->isChecked())
588  {
589  ui->dsb_EndValueA->setMinimum(arg1 + ui->dsb_StepVauleD->value());
590  calc_atom_count_all_combined();
591  }
592 }
593 
594 void Enhancededitorwindow::on_dsb_StartValueE_valueChanged(double arg1)
595 {
596  value_e_list = calc_value_list(arg1, ui->dsb_StepVauleE->value(), ui->dsb_EndValueE->value());
597  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueE->setValue(calc_end_value(arg1, ui->dsb_StepVauleE->value()));
598  if(ui->chb_allCombined->isChecked())
599  {
600  ui->dsb_EndValueA->setMinimum(arg1 + ui->dsb_StepVauleE->value());
601  calc_atom_count_all_combined();
602  }
603 }
604 
605 void Enhancededitorwindow::on_dsb_StartValueF_valueChanged(double arg1)
606 {
607  value_f_list = calc_value_list(arg1, ui->dsb_StepVauleF->value(), ui->dsb_EndValueF->value());
608  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueF->setValue(calc_end_value(arg1, ui->dsb_StepVauleF->value()));
609  if(ui->chb_allCombined->isChecked())
610  {
611  ui->dsb_EndValueA->setMinimum(arg1 + ui->dsb_StepVauleF->value());
612  calc_atom_count_all_combined();
613  }
614 }
615 
616 void Enhancededitorwindow::on_dsb_StartValueG_valueChanged(double arg1)
617 {
618  value_g_list = calc_value_list(arg1, ui->dsb_StepVauleG->value(), ui->dsb_EndValueG->value());
619  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueG->setValue(calc_end_value(arg1, ui->dsb_StepVauleG->value()));
620  if(ui->chb_allCombined->isChecked())
621  {
622  ui->dsb_EndValueA->setMinimum(arg1 + ui->dsb_StepVauleG->value());
623  calc_atom_count_all_combined();
624  }
625 }
626 
627 void Enhancededitorwindow::on_dsb_StartValueH_valueChanged(double arg1)
628 {
629  value_h_list = calc_value_list(arg1, ui->dsb_StepVauleH->value(), ui->dsb_EndValueH->value());
630  if(!ui->chb_allCombined->isChecked()) ui->dsb_EndValueH->setValue(calc_end_value(arg1, ui->dsb_StepVauleH->value()));
631  if(ui->chb_allCombined->isChecked())
632  {
633  ui->dsb_EndValueA->setMinimum(arg1 + ui->dsb_StepVauleH->value());
634  calc_atom_count_all_combined();
635  }
636 }
637 
638 //***********************************************************************************************************************
639 
640 void Enhancededitorwindow::on_dsb_EndValueA_valueChanged(double arg1)
641 {
642  value_a_list = calc_value_list(ui->dsb_StartValueA->value(), ui->dsb_StepVauleA->value(), arg1);
643  if(ui->chb_allCombined->isChecked()) calc_atom_count_all_combined();
644 }
645 
646 void Enhancededitorwindow::on_dsb_EndValueB_valueChanged(double arg1)
647 {
648  value_b_list = calc_value_list(ui->dsb_StartValueB->value(), ui->dsb_StepVauleB->value(), arg1);
649  if(ui->chb_allCombined->isChecked()) calc_atom_count_all_combined();
650 }
651 
652 void Enhancededitorwindow::on_dsb_EndValueC_valueChanged(double arg1)
653 {
654  value_c_list = calc_value_list(ui->dsb_StartValueC->value(), ui->dsb_StepVauleC->value(), arg1);
655  if(ui->chb_allCombined->isChecked()) calc_atom_count_all_combined();
656 }
657 
658 void Enhancededitorwindow::on_dsb_EndValueD_valueChanged(double arg1)
659 {
660  value_d_list = calc_value_list(ui->dsb_StartValueD->value(), ui->dsb_StepVauleD->value(), arg1);
661  if(ui->chb_allCombined->isChecked()) calc_atom_count_all_combined();
662 }
663 
664 void Enhancededitorwindow::on_dsb_EndValueE_valueChanged(double arg1)
665 {
666  value_e_list = calc_value_list(ui->dsb_StartValueE->value(), ui->dsb_StepVauleE->value(), arg1);
667  if(ui->chb_allCombined->isChecked()) calc_atom_count_all_combined();
668 }
669 
670 void Enhancededitorwindow::on_dsb_EndValueF_valueChanged(double arg1)
671 {
672  value_f_list = calc_value_list(ui->dsb_StartValueF->value(), ui->dsb_StepVauleF->value(), arg1);
673  if(ui->chb_allCombined->isChecked()) calc_atom_count_all_combined();
674 }
675 
676 void Enhancededitorwindow::on_dsb_EndValueG_valueChanged(double arg1)
677 {
678  value_g_list = calc_value_list(ui->dsb_StartValueG->value(), ui->dsb_StepVauleG->value(), arg1);
679  if(ui->chb_allCombined->isChecked()) calc_atom_count_all_combined();
680 }
681 
682 void Enhancededitorwindow::on_dsb_EndValueH_valueChanged(double arg1)
683 {
684  value_h_list = calc_value_list(ui->dsb_StartValueH->value(), ui->dsb_StepVauleH->value(), arg1);
685  if(ui->chb_allCombined->isChecked()) calc_atom_count_all_combined();
686 }
687 
688 //***********************************************************************************************************************
689 
690 // calc all atoms with choosen parameters and save to list and to drive
691 void Enhancededitorwindow::on_pushButton_clicked()
692 {
693  QStringList results_list;
694  results_list.clear();
695 
696  QString savePath = QString(QDir::homePath() + "/" + "Matching-Pursuit-Toolbox/%1.pdict").arg(ui->tb_atom_name->text());
697  QFile dict(savePath);
698 
699  if(ui->tb_atom_name->text().isEmpty())
700  {
701  QMessageBox::warning(this, tr("Error"),
702  tr("There was no name assigned."));
703  ui->tb_atom_name->setFocus();
704  return;
705  }
706 
707  QStringList filterList;
708  filterList.append("*.pdict");
709  QDir dictDir = QDir(QDir::homePath() + "/" + "Matching-Pursuit-Toolbox");
710  QFileInfoList fileList = dictDir.entryInfoList(filterList);
711 
712  for(qint32 i = 0; i < fileList.length(); i++)
713  {
714  QFileInfo fileInfo = fileList.at(i);
715  if(QString::compare(fileInfo.baseName(), ui->tb_atom_name->text()) == 0)
716  {
717  QMessageBox::warning(this, tr("Error"),
718  tr("The name for the dictionary is already taken."));
719  ui->tb_atom_name->setFocus();
720  ui->tb_atom_name->selectAll();
721  return;
722  }
723  }
724 
725  QString save_path_xml = QString(QDir::homePath() + "/" + "Matching-Pursuit-Toolbox/%1_xml.pdict").arg(ui->tb_atom_name->text());
726  QFile xml_file(save_path_xml);
727 
728  xml_file.open(QIODevice::WriteOnly);
729 
730  QXmlStreamWriter xmlWriter(&xml_file);
731  xmlWriter.setAutoFormatting(true);
732  xmlWriter.writeStartDocument();
733 
734  xmlWriter.writeStartElement("COUNT");
735  xmlWriter.writeAttribute("of_atoms", QString::number(ui->sb_Atomcount->value()));
736  xmlWriter.writeStartElement("built_Atoms");
737 
738  xmlWriter.writeAttribute("formula", ui->cb_AtomFormula->currentText());
739  xmlWriter.writeAttribute("sample_count", QString::number(ui->sb_SampleCount->value()));
740  xmlWriter.writeAttribute("atom_count", QString::number(ui->sb_Atomcount->value()));
741  xmlWriter.writeAttribute("source_dict", ui->tb_atom_name->text());
742 
743  if (dict.open (QIODevice::WriteOnly| QIODevice::Append))
744  {
745  QTextStream stream( &dict );
746  stream << QString("atomcount = %1 ").arg(_atom_count) << "\n";
747  if(ui->chb_allCombined->isChecked())
748  {
749  qint32 atomIndex = 0;
750  qint32 max_a = 1;
751  qint32 max_b = 1;
752  qint32 max_c = 1;
753  qint32 max_d = 1;
754  qint32 max_e = 1;
755  qint32 max_f = 1;
756  qint32 max_g = 1;
757  qint32 max_h = 1;
758 
759  if(value_a_list.length() != 0) max_a = value_a_list.length();
760  if(value_b_list.length() != 0) max_b = value_b_list.length();
761  if(value_c_list.length() != 0) max_c = value_c_list.length();
762  if(value_d_list.length() != 0) max_d = value_d_list.length();
763  if(value_e_list.length() != 0) max_e = value_e_list.length();
764  if(value_f_list.length() != 0) max_f = value_f_list.length();
765  if(value_g_list.length() != 0) max_g = value_g_list.length();
766  if(value_h_list.length() != 0) max_h = value_h_list.length();
767 
768  qint32 count_h = 0;
769  while(count_h < max_h)
770  {
771  qint32 count_g = 0;
772  while(count_g < max_g)
773  {
774  qint32 count_f = 0;
775  while(count_f < max_f)
776  {
777  qint32 count_e = 0;
778  while(count_e < max_e)
779  {
780  qint32 count_d = 0;
781  while(count_d < max_d)
782  {
783  qint32 count_c = 0;
784  while(count_c < max_c)
785  {
786  qint32 count_b = 0;
787  while(count_b < max_b)
788  {
789  qint32 count_a = 0;
790  while(count_a < max_a)
791  {
792  qreal temp_a = ui->dsb_StartValueA->value();
793  qreal temp_b = ui->dsb_StartValueB->value();
794  qreal temp_c = ui->dsb_StartValueC->value();
795  qreal temp_d = ui->dsb_StartValueD->value();
796  qreal temp_e = ui->dsb_StartValueE->value();
797  qreal temp_f = ui->dsb_StartValueF->value();
798  qreal temp_g = ui->dsb_StartValueG->value();
799  qreal temp_h = ui->dsb_StartValueH->value();
800  if(value_a_list.length() > 0) temp_a = value_a_list.at(count_a);
801  if(value_b_list.length() > 0) temp_b = value_b_list.at(count_b);
802  if(value_c_list.length() > 0) temp_c = value_c_list.at(count_c);
803  if(value_d_list.length() > 0) temp_d = value_d_list.at(count_d);
804  if(value_e_list.length() > 0) temp_e = value_e_list.at(count_e);
805  if(value_f_list.length() > 0) temp_f = value_f_list.at(count_f);
806  if(value_g_list.length() > 0) temp_g = value_g_list.at(count_g);
807  if(value_h_list.length() > 0) temp_h = value_h_list.at(count_h);
808 
809 
810  Formulaeditor formula_parser;
811 
812  formula_parser.set_funct_const(0, temp_a);
813  formula_parser.set_funct_const(1, temp_b);
814  formula_parser.set_funct_const(2, temp_c);
815  formula_parser.set_funct_const(3, temp_d);
816  formula_parser.set_funct_const(4, temp_e);
817  formula_parser.set_funct_const(5, temp_f);
818  formula_parser.set_funct_const(6, temp_g);
819  formula_parser.set_funct_const(7, temp_h);
820 
821  results_list.clear();
822  VectorXd formel_vec = VectorXd::Zero(_sample_count);
823  qreal norm = 0;
824  for(qint32 i = 0; i < _sample_count; i++)
825  {
826  formel_vec[i] = formula_parser.calculation(ui->cb_AtomFormula->currentText(), i);
827 
828  //normalization
829  norm = formel_vec.norm();
830  if(norm != 0) formel_vec /= norm;
831 
832  results_list.append(QString::number(formel_vec[i]));
833  }
834  stream << QString("%1_ATOM_%2 \n %3: a: %4 b: %5 c: %6 d: %7 e: %8 f: %9 g: %10 h: %11")
835  .arg(ui->tb_atom_name->text())
836  .arg(atomIndex)
837  .arg(ui->cb_AtomFormula->currentText())
838  .arg(temp_a)
839  .arg(temp_b)
840  .arg(temp_c)
841  .arg(temp_d)
842  .arg(temp_e)
843  .arg(temp_f)
844  .arg(temp_g)
845  .arg(temp_h) << "\n";
846 
847  for (QStringList::Iterator it = results_list.begin(); it != results_list.end(); it++)
848  stream << *it << "\n";
849 
850  xmlWriter.writeStartElement("ATOM");
851  xmlWriter.writeAttribute("ID", QString::number(atomIndex));
852  xmlWriter.writeAttribute("a", QString::number(temp_a));
853  xmlWriter.writeAttribute("b", QString::number(temp_b));
854  xmlWriter.writeAttribute("c", QString::number(temp_c));
855  xmlWriter.writeAttribute("d", QString::number(temp_d));
856  xmlWriter.writeAttribute("e", QString::number(temp_e));
857  xmlWriter.writeAttribute("f", QString::number(temp_f));
858  xmlWriter.writeAttribute("g", QString::number(temp_g));
859  xmlWriter.writeAttribute("h", QString::number(temp_h));
860 
861  xmlWriter.writeStartElement("samples");
862  QString samples_to_xml;
863  for (qint32 it = 0; it < results_list.length(); it++)
864  {
865  samples_to_xml.append(results_list.at(it));
866  samples_to_xml.append(":");
867  }
868  xmlWriter.writeAttribute("samples", samples_to_xml);
869  xmlWriter.writeEndElement();
870 
871  xmlWriter.writeEndElement();
872 
873 
874  atomIndex++;
875  count_a++;
876  }
877  count_b++;
878  }
879  count_c++;
880  }
881  count_d++;
882  }
883  count_e++;
884  }
885  count_f++;
886  }
887  count_g++;
888  }
889  count_h++;
890  }
891  }
892  else // not all params combined
893  {
894  qint32 atom_index = 0;
895  while (atom_index < _atom_count)
896  {
897  qreal temp_a = ui->dsb_StartValueA->value();
898  qreal temp_b = ui->dsb_StartValueB->value();
899  qreal temp_c = ui->dsb_StartValueC->value();
900  qreal temp_d = ui->dsb_StartValueD->value();
901  qreal temp_e = ui->dsb_StartValueE->value();
902  qreal temp_f = ui->dsb_StartValueF->value();
903  qreal temp_g = ui->dsb_StartValueG->value();
904  qreal temp_h = ui->dsb_StartValueH->value();
905  if(value_a_list.length() > 0 && atom_index < value_a_list.length()) temp_a = value_a_list.at(atom_index);
906  if(value_b_list.length() > 0 && atom_index < value_b_list.length()) temp_b = value_b_list.at(atom_index);
907  if(value_c_list.length() > 0 && atom_index < value_c_list.length()) temp_c = value_c_list.at(atom_index);
908  if(value_d_list.length() > 0 && atom_index < value_d_list.length()) temp_d = value_d_list.at(atom_index);
909  if(value_e_list.length() > 0 && atom_index < value_e_list.length()) temp_e = value_e_list.at(atom_index);
910  if(value_f_list.length() > 0 && atom_index < value_f_list.length()) temp_f = value_f_list.at(atom_index);
911  if(value_g_list.length() > 0 && atom_index < value_g_list.length()) temp_g = value_g_list.at(atom_index);
912  if(value_h_list.length() > 0 && atom_index < value_h_list.length()) temp_h = value_h_list.at(atom_index);
913 
914  Formulaeditor formula_parser;
915  formula_parser.set_funct_const(0, temp_a);
916  formula_parser.set_funct_const(1, temp_b);
917  formula_parser.set_funct_const(2, temp_c);
918  formula_parser.set_funct_const(3, temp_d);
919  formula_parser.set_funct_const(4, temp_e);
920  formula_parser.set_funct_const(5, temp_f);
921  formula_parser.set_funct_const(6, temp_g);
922  formula_parser.set_funct_const(7, temp_h);
923 
924  results_list.clear();
925  for(qint32 i = 0; i < _sample_count; i++)
926  results_list.append(QString::number(formula_parser.calculation(ui->cb_AtomFormula->currentText(), i)));
927 
928  stream << QString("%1_ATOM_%2 \n %3: a: %4 b: %5 c: %6 d: %7 e: %8 f: %9 g: %10 h: %11")
929  .arg(ui->tb_atom_name->text())
930  .arg(atom_index)
931  .arg(ui->cb_AtomFormula->currentText())
932  .arg(temp_a)
933  .arg(temp_b)
934  .arg(temp_c)
935  .arg(temp_d)
936  .arg(temp_e)
937  .arg(temp_f)
938  .arg(temp_g)
939  .arg(temp_h) << "\n";
940 
941  for (QStringList::Iterator it = results_list.begin(); it != results_list.end(); it++)
942  stream << *it << "\n";
943 
944  xmlWriter.writeStartElement("ATOM");
945  xmlWriter.writeAttribute("ID", QString::number(atom_index));
946  xmlWriter.writeAttribute("a", QString::number(temp_a));
947  xmlWriter.writeAttribute("b", QString::number(temp_b));
948  xmlWriter.writeAttribute("c", QString::number(temp_c));
949  xmlWriter.writeAttribute("d", QString::number(temp_d));
950  xmlWriter.writeAttribute("e", QString::number(temp_e));
951  xmlWriter.writeAttribute("f", QString::number(temp_f));
952  xmlWriter.writeAttribute("g", QString::number(temp_g));
953  xmlWriter.writeAttribute("h", QString::number(temp_h));
954 
955  xmlWriter.writeStartElement("samples");
956  QString samples_to_xml;
957  for (qint32 it = 0; it < results_list.length(); it++)
958  {
959  samples_to_xml.append(results_list.at(it));
960  samples_to_xml.append(":");
961  }
962  xmlWriter.writeAttribute("samples", samples_to_xml);
963  xmlWriter.writeEndElement();
964 
965  xmlWriter.writeEndElement();
966 
967 
968  atom_index++;
969  }
970  }
971  dict.close();
972  }
973  xmlWriter.writeEndElement();
974  xmlWriter.writeEndElement();
975  xmlWriter.writeEndDocument();
976 
977  xml_file.close();
978 
979  emit dict_saved();
980 }
void set_funct_const(int index, double val)
Definition: aboutwindow.h:52
double calculation(QString strFormula, qreal xValue, bool strip=true)
EnhancedEditorWindow class declaration which enables the adaption of parameters for stored formulas...
DeleteMessageBox class declaration, which asked for acknowledgment to delete dictionaries or formulas...
FormulaEditor class declaration which allows the definition of individual atomformulas for the usage ...