COPASI API  4.16.103
CQExperimentData.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include "CQExperimentData.h"
16 
17 #include <QtCore/QVariant>
18 #include <QtCore/QTimer>
19 
20 #include <algorithm>
21 #include <limits>
22 #include <cmath>
23 #include <QtCore/QSignalMapper>
24 #include <QtGui/QComboBox>
25 
26 #include "copasi.h"
27 
28 #include "CCopasiSelectionDialog.h"
29 #include "CopasiFileDialog.h"
30 #include "CQValidator.h"
31 #include "qtUtilities.h"
32 #include "CQMessageBox.h"
34 #include "CQPushButtonDelegate.h"
35 #include "CQComboDelegate.h"
36 
41 
42 #include "report/CKeyFactory.h"
43 #include "utilities/CDirEntry.h"
44 #include "utilities/utility.h"
48 
49 #define COL_NAME 0
50 #define COL_TYPE 1
51 #define COL_TYPE_HIDDEN 2
52 #define COL_BTN 3
53 #define COL_OBJECT 4
54 #define COL_OBJECT_HIDDEN 5
55 #define COL_SCALE 6
56 
57 #define InvalidIndex std::numeric_limits< unsigned C_INT32 >::max()
58 
59 /*
60  * Constructs a CQExperimentData as a child of 'parent', with the
61  * name 'name' and widget flags set to 'f'.
62  *
63  * The dialog will by default be modeless, unless you set 'modal' to
64  * true to construct a modal dialog.
65  */
66 CQExperimentData::CQExperimentData(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl):
67  QDialog(parent, fl),
68  mOldWeightMethod(),
69  mpValidatorHeader(NULL),
70  mpValidatorLast(NULL),
71  mpExperiment(NULL),
72  mpFileInfo(NULL),
73  mpExperimentSet(NULL),
74  mpExperimentSetCopy(NULL),
75  mKeyMap(),
76  mFileMap(),
77  mpValidatorFirst(),
78  mShown(-1),
79  mpValidatorName(NULL),
80  mCrossValidation(false),
81  mShowError(true),
82  mpDataModel(NULL),
83  mpComboDelegate(NULL),
84  mTypeItems(),
85  mTypeWithoutTimeItems(),
86  mModelObjectRow(-1)
87 {
88  setObjectName(QString::fromUtf8(name));
89  setModal(modal);
90  setupUi(this);
91 
92  init();
93 }
94 
95 /*
96  * Destroys the object and frees any allocated resources
97  */
99 {
100  destroy();
101  // no need to delete child widgets, Qt does it all for us
102 }
103 
105 {
106 public:
107  enum Type
108  {
109  Name = 0,
113  };
114 
115  // Operations
116 public:
117  CQExperimentDataValidator(QLineEdit * parent,
118  const char * name,
119  CQExperimentData * pContext,
120  const Type & type):
121  CQValidatorNotEmpty(parent, name),
122  mpIntValidator(new QIntValidator(1, std::numeric_limits< int >::max(), parent)),
123  mpContext(pContext),
124  mType(type)
125  {}
126 
127  virtual State validate(QString & input, int & pos) const
128  {
129  if (mpContext->mShown == -1) return Acceptable;
130 
131  if (mType == Name)
132  {
133  if (input == "All")
134  {
135  setColor(Invalid);
136  return Intermediate;
137  }
138 
139  if (mLastAccepted != input &&
141  {
142  setColor(Invalid);
143  return Intermediate;
144  }
145  }
146  else
147  {
148  if (mpIntValidator->validate(input, pos) != Acceptable)
149  {
150  setColor(Invalid);
151  return Intermediate;
152  }
153 
154  size_t First, Last;
155 
156  switch (mType)
157  {
158  case FirstRow:
159 
160  if (!mpContext->mpFileInfo->validateFirst(mpContext->mShown, input.toULong()))
161  {
162  size_t NewFirst = input.toULong();
163 
165 
166  while (NewFirst > Last)
168 
169  if (First <= NewFirst && NewFirst <= Last)
170  {
171  if (First > mpContext->mpExperiment->getLastRow())
172  {
173  mpContext->mpExperiment->setLastRow((unsigned C_INT32) Last);
174  mpContext->mpExperiment->setFirstRow((unsigned C_INT32) First);
175  }
176  else
177  {
178  mpContext->mpExperiment->setFirstRow((unsigned C_INT32) First);
179  mpContext->mpExperiment->setLastRow((unsigned C_INT32) Last);
180  }
181 
183 
184  mpContext->mpEditFirst->setText(QString::number(First));
185  mpContext->mpEditLast->setText(QString::number(Last));
187 
188  return validate(input, pos);
189  }
190 
191  setColor(Invalid);
192  return Intermediate;
193  }
194 
195  mpContext->mpExperiment->setFirstRow(input.toULong());
197  mpContext->mpBtnExperimentAdd->setEnabled(mpContext->mpFileInfo->getFirstUnusedSection(First, Last));
198  break;
199 
200  case LastRow:
201 
202  if (!mpContext->mpFileInfo->validateLast(mpContext->mShown, input.toULong()))
203  {
204  setColor(Invalid);
205  return Intermediate;
206  }
207 
208  mpContext->mpExperiment->setLastRow(input.toULong());
210  mpContext->mpBtnExperimentAdd->setEnabled(mpContext->mpFileInfo->getFirstUnusedSection(First, Last));
211  break;
212 
213  case HeaderRow:
214 
215  if (!mpContext->mpFileInfo->validateHeader(mpContext->mShown, input.toULong()))
216  {
217  setColor(Invalid);
218  return Intermediate;
219  }
220 
221  mpContext->mpExperiment->setHeaderRow(input.toULong());
222  break;
223 
224  default:
225  break;
226  }
227  }
228 
229  return CQValidatorNotEmpty::validate(input, pos);
230  }
231 
232  // virtual State revalidate();
233 
234  // virtual void forceAcceptance(const QString & input) const;
235 
236  // virtual void saved() const;
237 
238  // Attributes
239 private:
240  QIntValidator * mpIntValidator;
241 
243 
245 };
246 
248 {
250 }
251 
253 {
254  qWarning("CQExperimentData::slotFirst(): Not implemented yet");
255 
256  size_t Row = C_INVALID_INDEX;
257 
258  if (mpEditFirst->text() != "")
259  Row = mpEditFirst->text().toULong();
260 
261  if (Row == C_INVALID_INDEX)
262  {
263  // Row = find first non used row in file
264  }
265 
266  // display dialog with table showing file section of First row
267 
268  // if accept
269  // set mpEditFirst
270 }
271 
273 {
274  size_t Row = C_INVALID_INDEX;
275 
276  if (mpEditLast->text() != "")
277  Row = mpEditLast->text().toULong();
278 
279  if (Row == C_INVALID_INDEX && mpEditFirst->text() != "")
280  Row = mpEditFirst->text().toULong();
281 
282  // display dialog with table showing file section of First row
283 
284  // if accept
285  // set mpEditFirst
286  // if last row
287  // display table showing file section of last row inexperiment
288  // else if first
289  // display table showing file section of first row in file
290  // else
291  // display table showing file section of last non used row in file
292 
293  // if accept
294  // set mpEditLast
295 }
296 
298 {
299  qWarning("CQExperimentData::slotHeader(): Not implemented yet");
300 
301  // if header row
302  // display table showing file section of header row inexperiment
303  // if first row
304  // display table showing file section of first row inexperiment
305  // else if last row
306  // display table showing file section of last row inexperiment
307  // else
308  // display table showing file section of first non used row in file
309 
310  // if accept
311  // set mpEditHeader
312  // check mpCheckHeader
313  // else
314  // uncheck mpCheckHeader
315 }
316 
317 void CQExperimentData::slotExprimentType(bool isSteadyState)
318 {
319  if (!mpExperiment) return;
320 
321  if (isSteadyState)
322  {
323  mpBtnSteadystate->setFocus();
325  }
326  else
327  {
328  mpBtnTimeCourse->setFocus();
330  }
331 
333 
334  // Undo the changes so that copy from and to work.
335  if (isSteadyState)
336  {
338  }
339  else
340  {
342  }
343 
344  size_t i, imax = mpTable->rowCount();
345 
346  if (isSteadyState)
347  for (i = 0; i < imax; i++)
348  {
349  CExperiment::Type Type = static_cast< CExperiment::Type >(mpTable->item((int) i, COL_TYPE_HIDDEN)->data(Qt::DisplayRole).toInt());
350 
351  if (Type == CExperiment::time)
353  };
354 
355  loadTable(mpExperiment, true);
356  return;
357 }
358 
360 {
361  mpEditSeparator->setEnabled(!checked);
362 
363  if (checked)
364  mpCheckTab->setFocus();
365  else
366  mpEditSeparator->setFocus();
367 
368  if (mpEditSeparator->isEnabled() &&
369  mpEditSeparator->text().isEmpty())
370  mpEditSeparator->setText(",");
371  else
372  slotSeparator();
373 }
374 
376 {
377  mpEditHeader->setEnabled(checked);
378 
379  if (!checked)
380  {
381  this->mpEditHeader->setText("");
382  }
383 }
384 
386 {
387  mShowError = false;
388 
389  CExperiment Experiment(mpDataModel);
390  CExperiment * pExperiment = mpExperimentSetCopy->addExperiment(Experiment);
391 
392  size_t First, Last;
393  mpFileInfo->getFirstUnusedSection(First, Last);
394  pExperiment->setFirstRow((unsigned C_INT32) First);
395  pExperiment->setLastRow((unsigned C_INT32) Last);
396  pExperiment->setHeaderRow((unsigned C_INT32) First);
397  pExperiment->setFileName(mpFileInfo->getFileName());
398 
399  pExperiment->setNormalizeWeightsPerExperiment(CCopasiRootContainer::getConfiguration()->normalizePerExperiment());
400 
401  pExperiment->setNumColumns((unsigned C_INT32) pExperiment->guessColumnNumber());
402  mpFileInfo->sync();
403 
404  mpBoxExperiment->addItem(FROM_UTF8(pExperiment->getObjectName()));
405  mpBoxExperiment->setCurrentRow(mpBoxExperiment->count() - 1);
406 
407  syncExperiments();
408  mpBtnExperimentAdd->setEnabled(mpFileInfo->getFirstUnusedSection(First, Last));
409 
410  mShowError = true;
411 }
412 
413 void CQExperimentData::slotExperimentChanged(QListWidgetItem * pCurrentItem, QListWidgetItem * /* pPreviousItem */)
414 {
415  std::string Name;
416 
417  if (pCurrentItem != NULL)
418  Name = TO_UTF8(pCurrentItem->text());
419 
421 
422  bool success = true;
423 
425 
426  if (pCurrentItem != NULL)
427  {
429  mShown = mpBoxExperiment->currentRow();
430 
431  std::ifstream File;
432  File.open(CLocaleString::fromUtf8(mpExperiment->getFileName()).c_str());
433 
434  size_t CurrentLine = 1;
435  success &= mpExperiment->read(File, CurrentLine);
436 
437  if (success)
438  success &= mpExperiment->compile();
439  }
440  else
441  {
442  mpExperiment = NULL;
443  mShown = -1;
444  }
445 
447 
448  if (!success && CCopasiMessage::size() > 0 && mShowError)
449  {
451  QMessageBox::Ok, QMessageBox::Ok);
453  }
454 
455  enableEdit(!mpCheckFrom->isChecked());
456 }
457 
459 {
460  // Get info from current selection
461  size_t index = mpBoxExperiment->currentRow();
462 
463  if (index == C_INVALID_INDEX) return;
464 
465  std::string key =
466  mpFileInfo->getExperiment(TO_UTF8(mpBoxExperiment->item((int) index)->text()))->CCopasiParameter::getKey();
467 
468  // change selection
469  if (mpBoxExperiment->count() > 1)
470  {
471  if (mpBoxExperiment->count() > (int)index + 1)
472  mpBoxExperiment->setCurrentRow((int)(index + 1));
473  else
474  mpBoxExperiment->setCurrentRow((int)(index - 1));
475  }
476  else
477  slotExperimentChanged(NULL, NULL);
478 
479  // remove experiment
481  syncExperiments();
482 
483  size_t First, Last;
484  mpBtnExperimentAdd->setEnabled(mpFileInfo->getFirstUnusedSection(First, Last));
485 
486  // We need to correct mpCheckFrom and mpCheckTo since the removal of the experiment
487  // may have changed their status.
488  disconnect(mpCheckTo, SIGNAL(toggled(bool)), this, SLOT(slotCheckTo(bool)));
489  disconnect(mpCheckFrom, SIGNAL(toggled(bool)), this, SLOT(slotCheckFrom(bool)));
490 
491  mpCheckFrom->setChecked(isLikePreviousExperiment(mpExperiment));
492  enableEdit(!mpCheckFrom->isChecked());
493 
494  if (mpExperiment)
495  {
496  size_t Next =
497  mpExperimentSetCopy->keyToIndex(mpExperiment->CCopasiParameter::getKey()) + 1;
498 
499  if (Next < mpExperimentSetCopy->size())
500  mpCheckTo->setChecked(isLikePreviousExperiment(mpExperimentSetCopy->getExperiment(Next)));
501  else
502  mpCheckTo->setChecked(false);
503  }
504 
505  connect(mpCheckFrom, SIGNAL(toggled(bool)), this, SLOT(slotCheckFrom(bool)));
506  connect(mpCheckTo, SIGNAL(toggled(bool)), this, SLOT(slotCheckTo(bool)));
507 }
508 
510 {
511  QString File =
513  "Open File Dialog",
514  "",
515  "Data Files (*.txt *.csv);;All Files (*)",
516  "Open Data Files");
517 
518  if (File.isNull()) return;
519 
520  std::map<std::string, std::string>::const_iterator it = mFileMap.begin();
521  std::map<std::string, std::string>::const_iterator end = mFileMap.end();
522  int i;
523 
524  for (; it != end; ++it)
525  if (it->second == TO_UTF8(File))
526  {
527  for (i = 0; i < mpBoxFile->count(); i++)
528  if (it->first == TO_UTF8(mpBoxFile->item(i)->text()))
529  {
530  mpBoxFile->setCurrentRow(i);
531  break;
532  }
533 
534  return;
535  }
536 
537  std::string FileName = CDirEntry::fileName(TO_UTF8(File));
538 
539  i = 0;
540 
541  while (mFileMap.find(FileName) != mFileMap.end())
542  FileName = StringPrint("%s_%d", CDirEntry::fileName(TO_UTF8(File)).c_str(), i++);
543 
544  mFileMap[FileName] = TO_UTF8(File);
545  mpBoxFile->addItem(FROM_UTF8(FileName));
546 
547  mpBoxFile->setCurrentRow(mpBoxFile->count() - 1);
548 
549  size_t First, Last;
550 
551  if (mpFileInfo->getFirstUnusedSection(First, Last))
552  {
553  do
554  {
556  }
557  while (mpBtnExperimentAdd->isEnabled());
558 
559  mpBoxExperiment->setCurrentRow(0);
560  }
561 }
562 
563 void CQExperimentData::slotFileChanged(QListWidgetItem * pCurrentItem, QListWidgetItem * /* pPreviousItem */)
564 {
565  if (pCurrentItem)
566  {
567  slotExperimentChanged(NULL, NULL); // Assure that changes are saved.
568  mpBoxExperiment->clear();
569 
570  if (mpFileInfo->setFileName(mFileMap[TO_UTF8(pCurrentItem->text())]))
571  {
572  // fill experiment list box
573 
574  std::vector< std::string > ExperimentNames = mpFileInfo->getExperimentNames();
575  std::vector< std::string >::const_iterator it = ExperimentNames.begin();
576  std::vector< std::string >::const_iterator end = ExperimentNames.end();
577 
578  for (; it != end; ++it)
579  mpBoxExperiment->addItem(FROM_UTF8((*it)));
580  }
581 
582  if (mpBoxExperiment->count())
583  mpBoxExperiment->setCurrentRow(0);
584  else
585  slotExperimentChanged(NULL, NULL);
586  }
587  else
588  {
589  mpBoxExperiment->clear();
590  }
591 
592  size_t First, Last;
593  mpBtnExperimentAdd->setEnabled(mpFileInfo->getFirstUnusedSection(First, Last));
594 }
595 
597 {
598  // Get info from current selection
599  size_t index = mpBoxFile->currentRow();
600 
601  if (index == C_INVALID_INDEX) return;
602 
603  std::string FileName = mFileMap[TO_UTF8(mpBoxFile->item((int) index)->text())];
604 
605  // change selection
606  if (mpBoxFile->count() > 1)
607  {
608  if (mpBoxFile->count() > (int)index + 1)
609  mpBoxFile->setCurrentRow((int)(index + 1));
610  else
611  mpBoxFile->setCurrentRow((int)(index - 1));
612  }
613  else
614  slotFileChanged(NULL, NULL);
615 
616  // remove file
617  mFileMap.erase(TO_UTF8(mpBoxFile->item((int) index)->text()));
618 
619  QListWidgetItem * pItem = mpBoxFile->takeItem((int) index);
620  pdelete(pItem);
621 
622  // delete all experiments in current file.
623  size_t i = mpExperimentSetCopy->getExperimentCount() - 1;
624 
625  for (; i != C_INVALID_INDEX; i--)
626  if (mpExperimentSetCopy->getExperiment(i)->getFileName() == FileName)
628 }
629 
631 {
632  reject();
633 }
634 
636 {
637  mpBtnOK->setFocus();
638 
639  // Force the save all current changes.
640  slotExperimentChanged(NULL, NULL);
641 
642  CExperiment * pExperiment;
643 
644  size_t i = mpExperimentSet->getExperimentCount() - 1;
645 
646  for (; i != C_INVALID_INDEX; i--)
647  {
648  pExperiment =
649  dynamic_cast<CExperiment *>(CCopasiRootContainer::getKeyFactory()->get(mKeyMap[mpExperimentSet->getExperiment(i)->CCopasiParameter::getKey()]));
650 
651  if (pExperiment)
652  {
653  *mpExperimentSet->getExperiment(i) = *pExperiment;
655  }
656  else
658  }
659 
660  emit experimentChanged();
661 
662  for (i = 0; i < mpExperimentSetCopy->getExperimentCount(); i++)
664 
665  if (mCrossValidation)
666  {
667  CCrossValidationSet * pSet = static_cast< CCrossValidationSet * >(mpExperimentSet);
668 
669  if (QString::number(pSet->getWeight()) != mpEditWeight->text())
670  {
671  pSet->setWeight(mpEditWeight->text().toDouble());
672  }
673 
674  if (QString::number(pSet->getThreshold()) != mpEditThreshold->text())
675  {
676  pSet->setThreshold(mpEditThreshold->text().toUInt());
677  }
678  }
679 
681  accept();
682 }
683 
684 bool CQExperimentData::load(CExperimentSet * pExperimentSet, CCopasiDataModel * pDataModel)
685 {
686  mpDataModel = pDataModel;
687 
688  mCrossValidation = (dynamic_cast< CCrossValidationSet * >(pExperimentSet) != NULL);
689 
690  if (mCrossValidation)
691  {
692  setWindowTitle("Validation Data");
693  mpLblWeight->show();
694  mpEditWeight->show();
695  mpLblThreshold->show();
696  mpEditThreshold->show();
697  mpLineCrossValidation->show();
698 
699  mpEditWeight->setText(QString::number(static_cast< CCrossValidationSet * >(pExperimentSet)->getWeight()));
700  mpEditThreshold->setText(QString::number(static_cast< CCrossValidationSet * >(pExperimentSet)->getThreshold()));
701  }
702  else
703  {
704  mpLblWeight->hide();
705  mpEditWeight->hide();
706  mpLblThreshold->hide();
707  mpEditThreshold->hide();
708  mpLineCrossValidation->hide();
709  }
710 
711  if (!pExperimentSet) return false;
712 
713  mpExperiment = NULL;
714  mShown = -1;
715 
716  mpExperimentSet = pExperimentSet;
717 
719 
720  mpExperimentSetCopy = new CExperimentSet(*pExperimentSet);
721 
722  if (mCrossValidation)
723  mpExperimentSetCopy = elevate< CCrossValidationSet, CExperimentSet >(mpExperimentSetCopy);
724 
727 
728  // Build the key map so that we are able to update the correct experiments
729  // on OK.
730  mKeyMap.clear();
731  size_t i, imax = mpExperimentSet->getExperimentCount();
732 
733  for (i = 0; i < imax; i++)
734  mKeyMap[mpExperimentSet->getExperiment(i)->CCopasiParameter::getKey()] =
735  mpExperimentSetCopy->getExperiment(i)->CCopasiParameter::getKey();
736 
737  // fill file list box
738  mpBoxFile->clear();
739 
740  std::vector< std::string > FileNames = mpExperimentSetCopy->getFileNames();
741  std::vector< std::string >::const_iterator it = FileNames.begin();
742  std::vector< std::string >::const_iterator end = FileNames.end();
743 
744  std::string FileName;
745  i = 0;
746 
747  mFileMap.clear();
748 
749  for (; it != end; ++it)
750  {
751  FileName = CDirEntry::fileName(*it);
752 
753  while (mFileMap.find(FileName) != mFileMap.end())
754  FileName = StringPrint("%s_%d", CDirEntry::fileName(*it).c_str(), i++);
755 
756  mFileMap[FileName] = *it;
757  mpBoxFile->addItem(FROM_UTF8(FileName));
758  }
759 
760  if (mpBoxFile->count())
761  mpBoxFile->setCurrentRow(0); // This triggers the rest of the update :)
762  else
763  slotFileChanged(NULL, NULL);
764 
765  return true;
766 }
767 
769 {
770  mpBtnFileAdd->setIcon(CQIconResource::icon(CQIconResource::editAdd));
771  mpBtnFileDelete->setIcon(CQIconResource::icon(CQIconResource::editDelete));
772  mpBtnExperimentAdd->setIcon(CQIconResource::icon(CQIconResource::editAdd));
773  mpBtnExperimentDelete->setIcon(CQIconResource::icon(CQIconResource::editDelete));
774 
775  mpTable->hideColumn(COL_TYPE_HIDDEN);
776  mpTable->hideColumn(COL_OBJECT_HIDDEN);
777 
778  mpComboDelegate = new CQComboDelegate(NULL, this);
779  mpTable->setItemDelegateForColumn(COL_TYPE, mpComboDelegate);
780  connect(mpComboDelegate, SIGNAL(currentIndexChanged(int, int)), this, SLOT(slotTypeChanged(int, int)));
781 
784  mpTable->setItemDelegateForColumn(COL_BTN, pButtonDelegate);
785  connect(pButtonDelegate, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotModelObject(const QModelIndex &)));
786 
787  const std::string * pWeightMethod = CExperiment::WeightMethodName;
788 
789  while (*pWeightMethod != "")
790  mpBoxWeightMethod->insertItem(mpBoxWeightMethod->count(), FROM_UTF8(*pWeightMethod++));
791 
792  mpExperimentSetCopy = NULL;
793  mpFileInfo = NULL;
794  mpExperiment = NULL;
795 
797  mpEditName->setValidator(mpValidatorName);
799  mpEditFirst->setValidator(mpValidatorFirst);
801  mpEditLast->setValidator(mpValidatorLast);
803  mpEditHeader->setValidator(mpValidatorHeader);
804 
805  mCrossValidation = false;
806  mShowError = true;
807 
808  mpDataModel = NULL;
809 
810  // Set the combo box items
811  const std::string * pTmp = CExperiment::TypeName;
812 
813  while (*pTmp != "")
814  {
815  mTypeItems.push_back(FROM_UTF8(*pTmp));
816 
817  if (*pTmp != "Time")
818  mTypeWithoutTimeItems.push_back(FROM_UTF8(*pTmp));
819 
820  pTmp++;
821  }
822 }
823 
825 {
828 }
829 
830 void CQExperimentData::setTypeItems(const int & timeRow)
831 {
832  int i, imax = mpTable->rowCount();
833 
834  for (i = 0; i < imax; i++)
835  {
836  if ((timeRow != -1 && timeRow != i) ||
837  mpBtnSteadystate->isChecked())
838  {
840  }
841  else
842  {
844  }
845  }
846 }
847 
849 {
850 
851  // Temporarily disconnect signals
852  mpCheckTo->blockSignals(true);
853  mpCheckFrom->blockSignals(true);
854  mpBtnSteadystate->blockSignals(true);
855  mpEditSeparator->blockSignals(true);
856  mpCheckTab->blockSignals(true);
857  mpCheckNormalizeWeightsPerExperiment->blockSignals(true);
858 
859  if (!pExperiment)
860  {
861  mpEditName->setText("");
862  mpEditSeparator->setText("");
863  mpCheckTab->setChecked(true);
864  mpEditFirst->setText("");
865  mpEditLast->setText("");
866  mpEditHeader->setText("");
867  mpCheckHeader->setChecked(false);
868  mpBtnTimeCourse->setChecked(true);
869  mpCheckNormalizeWeightsPerExperiment->setChecked(true);
870  mpCheckFrom->setChecked(false);
871  mpCheckTo->setChecked(false);
872  mpBoxWeightMethod->setCurrentIndex(CExperiment::SD);
873  }
874  else
875  {
876  mpEditName->setText(FROM_UTF8(pExperiment->getObjectName()));
877 
878  if (pExperiment->getSeparator() == "\t")
879  {
880  mpEditSeparator->setText("");
881  mpCheckTab->setChecked(true);
882  }
883  else
884  {
885  mpEditSeparator->setText(FROM_UTF8(pExperiment->getSeparator()));
886  mpCheckTab->setChecked(false);
887  }
888 
889  QString Row = (pExperiment->getFirstRow() == InvalidIndex) ?
890  "" : QString::number(pExperiment->getFirstRow());
891  mpEditFirst->setText(Row);
892  Row = (pExperiment->getLastRow() == InvalidIndex) ?
893  "" : QString::number(pExperiment->getLastRow());
894  mpEditLast->setText(Row);
895 
896  if (pExperiment->getHeaderRow() == InvalidIndex)
897  {
898  mpEditHeader->setText("");
899  mpCheckHeader->setChecked(false);
900  }
901  else
902  {
903  mpEditHeader->setText(QString::number(pExperiment->getHeaderRow()));
904  mpCheckHeader->setChecked(true);
905  }
906 
907  if (pExperiment->getExperimentType() == CCopasiTask::timeCourse)
908  mpBtnTimeCourse->setChecked(true);
909  else
910  mpBtnSteadystate->setChecked(true);
911 
912  mOldWeightMethod = pExperiment->getWeightMethod();
913  mpBoxWeightMethod->setCurrentIndex(mOldWeightMethod);
914 
916  {
918  mpTable->horizontalHeaderItem(COL_SCALE)->setText("Epsilon");
919  break;
920 
921  default:
922  mpTable->horizontalHeaderItem(COL_SCALE)->setText("Weight");
923  break;
924  }
925 
926  mpCheckNormalizeWeightsPerExperiment->setChecked(pExperiment->getNormalizeWeightsPerExperiment());
927 
928  size_t Next =
929  mpExperimentSetCopy->keyToIndex(pExperiment->CCopasiParameter::getKey()) + 1;
930 
931  mpCheckFrom->setChecked(isLikePreviousExperiment(pExperiment));
932 
933  if (Next < mpExperimentSetCopy->getExperimentCount())
934  mpCheckTo->setChecked(isLikePreviousExperiment(mpExperimentSetCopy->getExperiment(Next)));
935  else
936  mpCheckTo->setChecked(false);
937  }
938 
943 
944  // Reconnect signals
945  mpCheckTo->blockSignals(false);
946  mpCheckFrom->blockSignals(false);
947  mpBtnSteadystate->blockSignals(false);
948  mpEditSeparator->blockSignals(false);
949  mpCheckTab->blockSignals(false);
950  mpCheckNormalizeWeightsPerExperiment->blockSignals(false);
951 
952  loadTable(pExperiment, false);
953 
954  return true;
955 }
956 
957 bool CQExperimentData::saveExperiment(CExperiment * pExperiment, const bool & full)
958 {
959  if (!pExperiment) return false;
960 
961  bool success = true;
962 
963  size_t Next =
964  mpExperimentSetCopy->keyToIndex(pExperiment->CCopasiParameter::getKey()) + 1;
965 
966  if (Next < mpExperimentSetCopy->getExperimentCount() && mpCheckTo->isChecked())
967  {
969 
970  if (isLikePreviousExperiment(pNext))
971  success &= saveExperiment(pNext, false);
972  }
973 
974  QString value = mpEditName->text();
975  int pos = value.length();
976 
977  if (full &&
978  pExperiment->getObjectName() != TO_UTF8(value) &&
979  mpValidatorName->validate(value, pos) == QValidator::Acceptable)
980  {
981  int current = mpBoxExperiment->currentRow();
982  mpBoxExperiment->blockSignals(true);
983  mpBoxExperiment->item(mShown)->setText(value);
984  mpBoxExperiment->setCurrentRow(current);
985  mpBoxExperiment->blockSignals(false);
986  pExperiment->setObjectName(TO_UTF8(value));
987  }
988 
989  if (mpCheckTab->isChecked())
990  pExperiment->setSeparator("\t");
991  else
992  pExperiment->setSeparator(TO_UTF8(mpEditSeparator->text()));
993 
994  value = mpEditFirst->text();
995  pos = value.length();
996 
997  if (full &&
998  mpValidatorFirst->validate(value, pos) == QValidator::Acceptable)
999  pExperiment->setFirstRow(value.toULong());
1000 
1001  value = mpEditLast->text();
1002  pos = value.length();
1003 
1004  if (full &&
1005  mpValidatorLast->validate(value, pos) == QValidator::Acceptable)
1006  pExperiment->setLastRow(value.toULong());
1007 
1008  value = mpEditHeader->text();
1009  pos = value.length();
1010 
1011  if (mpCheckHeader->isChecked() &&
1012  mpValidatorHeader->validate(value, pos) == QValidator::Acceptable)
1013  pExperiment->setHeaderRow(value.toULong());
1014  else
1015  {
1016  pExperiment->setHeaderRow(InvalidIndex);
1017  mpCheckHeader->setChecked(false);
1018  }
1019 
1020  if (mpBtnTimeCourse->isChecked())
1022  else
1024 
1025  pExperiment->setWeightMethod((CExperiment::WeightMethod) mpBoxWeightMethod->currentIndex());
1026 
1027  pExperiment->setNormalizeWeightsPerExperiment(mpCheckNormalizeWeightsPerExperiment->isChecked());
1028 
1029  mpFileInfo->sync();
1030 
1031  size_t First, Last;
1032  mpBtnExperimentAdd->setEnabled(mpFileInfo->getFirstUnusedSection(First, Last));
1033 
1038 
1039  saveTable(pExperiment);
1040 
1041  return success;
1042 }
1043 
1045 {
1046  std::string Current = TO_UTF8(mpBoxExperiment->currentItem()->text());
1047  std::string Shown;
1048 
1049  if (mShown != -1)
1050  Shown = TO_UTF8(mpBoxExperiment->item(mShown)->text());
1051 
1052  mpFileInfo->sync();
1053 
1054  mpBoxExperiment->blockSignals(true);
1055  mpBoxExperiment->clear();
1056 
1057  std::vector< std::string > ExperimentNames = mpFileInfo->getExperimentNames();
1058  std::vector< std::string >::const_iterator it = ExperimentNames.begin();
1059  std::vector< std::string >::const_iterator end = ExperimentNames.end();
1060 
1061  int i;
1062 
1063  for (i = 0; it != end; ++it, i++)
1064  {
1065  mpBoxExperiment->addItem(FROM_UTF8((*it)));
1066 
1067  if (*it == Current)
1068  {
1069  mpBoxExperiment->setCurrentRow(mpBoxExperiment->count() - 1);
1070  }
1071 
1072  if (*it == Shown) mShown = i;
1073  }
1074 
1075  mpBoxExperiment->blockSignals(false);
1076 
1077  return;
1078 }
1079 
1081 {loadTable(mpExperiment, true);}
1082 
1083 void CQExperimentData::slotModelObject(const QModelIndex & index)
1084 {
1085  selectModelObject(index.row());
1086 }
1087 
1089 {
1091  CExperiment::Type Type = static_cast< CExperiment::Type >(mpTable->item(row, COL_TYPE_HIDDEN)->data(Qt::DisplayRole).toInt());
1092 
1093  if (Type == CExperiment::independent)
1094  Classes =
1097  else
1098  Classes =
1101 
1102  const CCopasiObject * pObject =
1104 
1105  if (pObject)
1106  {
1107  mpTable->item(row, COL_OBJECT)->setText(FROM_UTF8(pObject->getObjectDisplayName()));
1108  mpTable->item(row, COL_OBJECT_HIDDEN)->setText(FROM_UTF8(pObject->getCN()));
1109  }
1110 
1111  updateScales();
1112 }
1113 
1115 {
1116  if (mModelObjectRow != -1)
1117  {
1119  }
1120 
1121  mModelObjectRow = -1;
1122 }
1123 
1124 void CQExperimentData::loadTable(CExperiment * pExperiment, const bool & guess)
1125 {
1126  if (!pExperiment)
1127  {
1128  mpTable->clearContents();
1129  mpTable->setRowCount(0);
1130 
1131  return;
1132  }
1133 
1134  size_t TimeRow = C_INVALID_INDEX;
1135 
1136  pExperiment->readColumnNames();
1137  const std::vector<std::string> & ColumnNames = pExperiment->getColumnNames();
1138 
1139  size_t OldRowCount = mpTable->rowCount();
1140  size_t i, imax = ColumnNames.size();
1141  mpTable->setRowCount((int)(imax));
1142 
1143  CExperimentObjectMap & ObjectMap = pExperiment->getObjectMap();
1144  const CCopasiObject *pObject;
1145  CExperiment::Type Type;
1146  QTableWidgetItem *pItem = NULL;
1147  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1149  assert(pDataModel != NULL);
1150 
1151  for (i = 0; i < imax; i++)
1152  {
1153  // Check whether we need to allocate table items.
1154  if (OldRowCount <= i)
1155  {
1156  // COL_NAME
1157  pItem = new QTableWidgetItem();
1158  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
1159  mpTable->setItem((int) i, COL_NAME, pItem);
1160 
1161  // COL_TYPE
1162  pItem = new QTableWidgetItem();
1163  mpTable->setItem((int) i, COL_TYPE, pItem);
1164 
1165  // COL_TYPE_HIDDEN
1166  pItem = new QTableWidgetItem();
1167  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
1168  mpTable->setItem((int) i, COL_TYPE_HIDDEN, pItem);
1169 
1170  // COL_BTN
1171  pItem = new QTableWidgetItem();
1172  mpTable->setItem(i, COL_BTN, pItem);
1173 
1174  // COL_OBJECT
1175  pItem = new QTableWidgetItem();
1176  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
1177  mpTable->setItem((int) i, COL_OBJECT, pItem);
1178 
1179  // COL_OBJECT_HIDDEN
1180  pItem = new QTableWidgetItem();
1181  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
1182  mpTable->setItem((int) i, COL_OBJECT_HIDDEN, pItem);
1183 
1184  // COL_SCALE
1185  pItem = new QTableWidgetItem("");
1186  mpTable->setItem((int) i, COL_SCALE, pItem);
1187  }
1188 
1189  // COL_NAME
1190  mpTable->item((int) i, COL_NAME)->setText(FROM_UTF8(ColumnNames[i]));
1191 
1192  // COL_TYPE
1193  if (guess && TimeRow == C_INVALID_INDEX &&
1194  mpBtnTimeCourse->isChecked() &&
1195  mpTable->item((int) i, COL_NAME)->text().contains("time", Qt::CaseInsensitive))
1196  {
1197  ObjectMap.setRole(i, CExperiment::time);
1198  }
1199 
1200  Type = ObjectMap.getRole(i);
1201 
1202  if (Type == CExperiment::time) TimeRow = i;
1203 
1204  mpTable->item((int) i, COL_TYPE)->setText(FROM_UTF8(CExperiment::TypeName[Type]));
1205 
1206  // COL_TYPE_HIDDEN
1207  mpTable->item((int) i, COL_TYPE_HIDDEN)->setText(QString::number(Type));
1208 
1209  // COL_BTN
1210  pItem = mpTable->item(i, COL_BTN);
1211 
1212  // Show the Button
1213  if (Type == CExperiment::ignore || Type == CExperiment::time)
1214  {
1215  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsEnabled);
1216  mpTable->closePersistentEditor(pItem);
1217  }
1218  else
1219  {
1220  pItem->setFlags(pItem->flags() | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1221  mpTable->openPersistentEditor(pItem);
1222  }
1223 
1224  // COL_OBJECT and COL_OBJECT_HIDDEN
1225  QTableWidgetItem * pItem;
1226 
1227  if (ObjectMap.getObjectCN(i) != "")
1228  {
1229  pObject = pDataModel->getDataObject(ObjectMap.getObjectCN(i));
1230 
1231  if (pObject)
1232  mpTable->item((int) i, COL_OBJECT)->setText(FROM_UTF8(pObject->getObjectDisplayName()));
1233  else
1234  mpTable->item((int) i, COL_OBJECT)->setText("not found");
1235 
1236  mpTable->item((int) i, COL_OBJECT_HIDDEN)->setText(FROM_UTF8(ObjectMap.getObjectCN(i)));
1237  }
1238  else
1239  {
1240  mpTable->item((int) i, COL_OBJECT)->setText("");
1241  mpTable->item((int) i, COL_OBJECT_HIDDEN)->setText("");
1242  }
1243 
1244  // COL_SCALE
1245  pItem = mpTable->item((int) i, COL_SCALE);
1246 
1247  if (Type != CExperiment::dependent)
1248  {
1249  pItem->setText("");
1250  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
1251  }
1252  else
1253  {
1254  C_FLOAT64 DefaultScale = ObjectMap.getDefaultScale(i);
1255  C_FLOAT64 Scale = ObjectMap.getScale(i);
1256 
1257  QString ScaleText;
1258  Qt::ItemFlags FlagMask = Qt::NoItemFlags;
1259 
1260  if ((isnan(DefaultScale) && isnan(Scale)) ||
1261  DefaultScale == Scale)
1262  ScaleText = "(" + QString::number(DefaultScale) + ")";
1263  else
1264  ScaleText = QString::number(Scale);
1265 
1266  pItem->setText(ScaleText);
1267  pItem->setFlags(pItem->flags() & ~FlagMask);
1268  }
1269  }
1270 
1271  setTypeItems(TimeRow);
1272 
1273  mpTable->resizeColumnsToContents();
1274  mpTable->resizeRowsToContents();
1275 }
1276 
1277 void CQExperimentData::slotTypeChanged(int row, int index)
1278 {
1279  CExperiment::Type NewType = static_cast<CExperiment::Type>(index);
1280  CExperiment::Type OldType = static_cast<CExperiment::Type>(mpTable->item(row, COL_TYPE_HIDDEN)->data(Qt::DisplayRole).toInt());
1281 
1282  if (OldType == NewType) return;
1283 
1284  bool BtnEnabled = true;
1285  //C_INT32 i, imax = mpTable->rowCount();
1286 
1287  mpTable->item(row, COL_TYPE)->setText(QString(FROM_UTF8(CExperiment::TypeName[NewType])));
1288  mpTable->item(row, COL_TYPE_HIDDEN)->setText(QString::number(NewType));
1289 
1290  CCopasiObjectName CN = CCopasiObjectName(TO_UTF8(mpTable->item(row, COL_OBJECT_HIDDEN)->text()));
1291  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1293  assert(pDataModel != NULL);
1294 
1295  switch (NewType)
1296  {
1297  case CExperiment::ignore:
1298  BtnEnabled = false;
1299  break;
1300 
1302 
1305  pDataModel->getDataObject(CN)))
1306  {
1307  mModelObjectRow = row;
1308  // slotModelObject(row);
1309  QTimer::singleShot(10, this, SLOT(slotModelObjectDelayed()));
1310  }
1311 
1312  BtnEnabled = true;
1313  break;
1314 
1316 
1319  pDataModel->getDataObject(CN)))
1320  {
1321  mModelObjectRow = row;
1322  // slotModelObject(row);
1323  QTimer::singleShot(10, this, SLOT(slotModelObjectDelayed()));
1324  }
1325 
1326  BtnEnabled = true;
1327  break;
1328 
1329  case CExperiment::time:
1330  BtnEnabled = false;
1331  setTypeItems(row);
1332 
1333  break;
1334  }
1335 
1336  QTableWidgetItem * pItem = mpTable->item(row, COL_BTN);
1337 
1338  if (BtnEnabled)
1339  {
1340  pItem->setFlags(pItem->flags() | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1341  mpTable->openPersistentEditor(pItem);
1342  }
1343  else
1344  {
1345  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsEnabled);
1346  mpTable->closePersistentEditor(pItem);
1347  }
1348 
1349  switch (OldType)
1350  {
1351  case CExperiment::ignore:
1354  break;
1355 
1356  case CExperiment::time:
1357  setTypeItems(-1);
1358  break;
1359  }
1360 
1361  // The default weights need to be recalculated and the table updated if the type change
1362  // involves dependent values.
1363  if (OldType == CExperiment::dependent ||
1364  NewType == CExperiment::dependent)
1365  {
1366  updateScales();
1367  }
1368 
1369  return;
1370 }
1371 
1373 {
1375 
1376  // Since the interpretation of the data has changed we need read the file again
1377  std::ifstream File;
1378  File.open(CLocaleString::fromUtf8(mpExperiment->getFileName()).c_str());
1379 
1380  size_t CurrentLine = 1;
1381  mpExperiment->read(File, CurrentLine);
1382  mpExperiment->compile();
1383 
1384  // We can not simply use loadTable as this would destroy the two signal maps
1385  // for the buttons and comboboxes leading to crashes in Qt.
1387 
1388  C_INT32 i, imax = mpTable->rowCount();
1389 
1390  for (i = 0; i < imax; i++)
1391  {
1392  QTableWidgetItem * pItem = mpTable->item(i, COL_SCALE);
1393 
1394  // COL_SCALE
1395  if (ObjectMap.getRole(i) != CExperiment::dependent)
1396  {
1397  pItem->setText("");
1398  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
1399  }
1400  else
1401  {
1402  QString ScaleText = pItem->text();
1403 
1404  // Keep non default values
1405  if (ScaleText == "" || ScaleText[0] == '(')
1406  {
1407 
1408  C_FLOAT64 DefaultWeight = ObjectMap.getDefaultScale(i);
1409 
1410  ScaleText = "(" + QString::number(DefaultWeight) + ")";
1411  pItem->setText(ScaleText);
1412  }
1413 
1414  pItem->setFlags(pItem->flags() | Qt::ItemIsEditable);
1415  }
1416  }
1417 }
1418 
1420 {
1421  if (!mpExperiment) return;
1422 
1423  // saveTable(mpExperiment);
1424 
1425  if (mpCheckTab->isChecked())
1426  mpExperiment->setSeparator("\t");
1427  else
1428  mpExperiment->setSeparator(TO_UTF8(mpEditSeparator->text()));
1429 
1432 
1433  loadTable(mpExperiment, true);
1434 }
1435 
1437 {
1438  CExperimentObjectMap & ObjectMap = pExperiment->getObjectMap();
1439  size_t i, imax = mpTable->rowCount();
1440  bool FoundTime = false;
1441  bool Changed = false;
1442 
1443  ObjectMap.setNumCols(imax);
1444 
1445  for (i = 0; i < imax; i++)
1446  {
1447  CExperiment::Type Type = toEnum(TO_UTF8(mpTable->item((int) i, COL_TYPE)->text()),
1449 
1450  if (Type == CExperiment::time)
1451  FoundTime = true;
1452 
1453  if (ObjectMap.getRole(i) != Type)
1454  {
1455  ObjectMap.setRole(i, Type);
1456  Changed = true;
1457  }
1458 
1459  if (ObjectMap.getObjectCN(i) != TO_UTF8(mpTable->item((int) i, COL_OBJECT_HIDDEN)->text()))
1460  {
1461  ObjectMap.setObjectCN(i, TO_UTF8(mpTable->item((int) i, COL_OBJECT_HIDDEN)->text()));
1462  Changed = true;
1463  }
1464 
1465  QString ScaleText = mpTable->item((int) i, COL_SCALE)->text();
1466 
1467  // Empty fields are treated as default.
1468  if (ScaleText == "")
1469  ScaleText = QString::number(std::numeric_limits<C_FLOAT64>::quiet_NaN());
1470 
1471  if (Type == CExperiment::dependent &&
1472  ScaleText[0] != '(' &&
1473  QString::number(ObjectMap.getScale(i)) != ScaleText)
1474  {
1475  ObjectMap.setScale(i, ScaleText.toDouble());
1476  Changed = true;
1477  }
1478  }
1479 
1480  pExperiment->updateFittedPoints();
1481 
1482  return Changed;
1483 }
1484 
1486 {
1487  mpCheckFrom->setFocus();
1488 
1489  size_t Current = this->mpBoxExperiment->currentRow();
1490 
1491  if (checked && Current && Current != C_INVALID_INDEX)
1492  {
1493  // Load the information from the previous experiment
1494  CExperiment * pPrevious =
1495  mpFileInfo->getExperiment(TO_UTF8(mpBoxExperiment->item((int)(Current - 1))->text()));
1496 
1497  unsigned C_INT32 OldWeightMethod = mOldWeightMethod;
1498  loadExperiment(pPrevious);
1499  mOldWeightMethod = OldWeightMethod;
1500 
1501  // Load the experiment individual information.
1502  mpEditName->setText(FROM_UTF8(mpExperiment->getObjectName()));
1503  QString Row = (mpExperiment->getFirstRow() == InvalidIndex) ?
1504  "" : QString::number(mpExperiment->getFirstRow());
1505  mpEditFirst->setText(Row);
1506  Row = (mpExperiment->getLastRow() == InvalidIndex) ?
1507  "" : QString::number(mpExperiment->getLastRow());
1508  mpEditLast->setText(Row);
1509 
1513  }
1514  else
1515  {
1517  }
1518 
1519  // loadExperiment determines the status of mpCheckFrom and may have overwritten
1520  // the desired setting. We correct that here.
1521  disconnect(mpCheckFrom, SIGNAL(toggled(bool)), this, SLOT(slotCheckFrom(bool)));
1522  mpCheckFrom->setChecked(checked);
1523  connect(mpCheckFrom, SIGNAL(toggled(bool)), this, SLOT(slotCheckFrom(bool)));
1524 
1525  enableEdit(!checked);
1526 }
1527 
1529 {
1530  if (!pExperiment) return false;
1531 
1532  size_t Previous =
1533  mpExperimentSetCopy->keyToIndex(pExperiment->CCopasiParameter::getKey()) - 1;
1534 
1535  if (Previous == C_INVALID_INDEX) return false;
1536 
1537  CExperiment * pPrevious = mpExperimentSetCopy->getExperiment(Previous);
1538 
1539  if (pExperiment->getSeparator() != pPrevious->getSeparator()) return false;
1540 
1541  if (pExperiment->getHeaderRow() != pPrevious->getHeaderRow()) return false;
1542 
1543  if (pExperiment->getExperimentType() != pPrevious->getExperimentType()) return false;
1544 
1545  if (mpExperiment != pExperiment)
1546  {
1547  if (pExperiment->getWeightMethod() != (CExperiment::WeightMethod) mOldWeightMethod) return false;
1548 
1549  if (pExperiment->getNormalizeWeightsPerExperiment() != pPrevious->getNormalizeWeightsPerExperiment()) return false;
1550  }
1551  else
1552  {
1553  if ((CExperiment::WeightMethod) mOldWeightMethod != pPrevious->getWeightMethod()) return false;
1554  }
1555 
1556  if (!(pExperiment->getObjectMap() == pPrevious->getObjectMap())) return false;
1557 
1558  return true;
1559 }
1560 
1562 {
1563  mpCheckTo->setFocus();
1564 
1565  if (!checked || !mpExperiment) return;
1566 
1567  size_t Next =
1568  mpExperimentSetCopy->keyToIndex(mpExperiment->CCopasiParameter::getKey()) + 1;
1569 
1570  if (Next < mpExperimentSetCopy->getExperimentCount())
1571  {
1573  unsigned C_INT32 OldWeightMethod = mOldWeightMethod;
1574  mOldWeightMethod = pNext->getWeightMethod();
1576  mOldWeightMethod = OldWeightMethod;
1577  }
1578 }
1579 
1580 void CQExperimentData::enableEdit(const bool & enable)
1581 {
1582  if (enable)
1583  {
1584  mpBtnSteadystate->setEnabled(true);
1585  mpBtnTimeCourse->setEnabled(true);
1586 
1587  if (mpCheckHeader->isChecked()) mpEditHeader->setEnabled(true);
1588 
1589  mpCheckHeader->setEnabled(true);
1590 
1591  if (!mpCheckTab->isChecked()) mpEditSeparator->setEnabled(true);
1592 
1593  mpCheckTab->setEnabled(true);
1594  mpTable->setEnabled(true);
1595  mpBoxWeightMethod->setEnabled(true);
1596 
1597  mpCheckNormalizeWeightsPerExperiment->setEnabled(true);
1598 
1599  // We need to enable all items in COL_TYPE and some in COL_BTN
1600  // Disable is inheritted but enable not.
1601  /*
1602  if (mpExperiment)
1603  {
1604  size_t i, imax = mpTable->rowCount();
1605 
1606  for (i = 0; i < imax; i++)
1607  {
1608  CExperiment::Type Type = static_cast< CExperiment::Type >(mpTable->item((int) i, COL_TYPE_HIDDEN)->data(Qt::DisplayRole).toInt());
1609 
1610  QTableWidgetItem * pItem = mpTable->item((int) i, COL_BTN);
1611 
1612  if (Type == CExperiment::ignore || Type == CExperiment::time)
1613  {
1614  pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsEnabled);
1615  mpTable->closePersistentEditor(pItem);
1616  }
1617  else
1618  {
1619  pItem->setFlags(pItem->flags() | Qt::ItemIsEditable | Qt::ItemIsEnabled);
1620  mpTable->openPersistentEditor(pItem);
1621  }
1622  }
1623  }
1624  */
1625  }
1626  else
1627  {
1628  mpBtnSteadystate->setEnabled(false);
1629  mpBtnTimeCourse->setEnabled(false);
1630  mpEditHeader->setEnabled(false);
1631  mpCheckHeader->setEnabled(false);
1632  mpEditSeparator->setEnabled(false);
1633  mpCheckTab->setEnabled(false);
1634  mpTable->setEnabled(false);
1635  mpBoxWeightMethod->setEnabled(false);
1636  mpCheckNormalizeWeightsPerExperiment->setEnabled(false);
1637  }
1638 }
1639 
1641 {
1642  if (!mpExperiment) return;
1643 
1644  size_t Current =
1645  mpExperimentSetCopy->keyToIndex(mpExperiment->CCopasiParameter::getKey());
1646  size_t Next = Current + 1;
1647 
1648  // Find all experiments which are like this.
1649  while (Next < mpExperimentSetCopy->getExperimentCount() && mpCheckTo->isChecked())
1650  {
1652 
1653  if (!isLikePreviousExperiment(pNext)) break;
1654 
1655  Next++;
1656  }
1657 
1658  // Update each of them.
1659  while (true)
1660  {
1661  Next--;
1662 
1664 
1665  bool Changed = saveTable(pNext);
1666 
1667  if (Changed)
1668  {
1669  std::ifstream File;
1670  File.open(CLocaleString::fromUtf8(pNext->getFileName()).c_str());
1671 
1672  size_t CurrentLine = 1;
1673  pNext->read(File, CurrentLine);
1674  pNext->compile();
1675  }
1676 
1677  pNext->setNormalizeWeightsPerExperiment(flag);
1678  pNext->calculateWeights();
1679 
1680  if (Next == Current) break;
1681  }
1682 
1683  loadTable(mpExperiment, false);
1684 }
1685 
1687 {
1688  if (mpExperiment == NULL) return;
1689 
1690  if ((CExperiment::WeightMethod) weightMethod ==
1691  mpExperiment->getWeightMethod()) return;
1692 
1693  switch ((CExperiment::WeightMethod) weightMethod)
1694  {
1696  mpTable->horizontalHeaderItem(COL_SCALE)->setText("Epsilon");
1697  break;
1698 
1699  default:
1700  mpTable->horizontalHeaderItem(COL_SCALE)->setText("Weight");
1701  break;
1702  }
1703 
1704  size_t Current =
1705  mpExperimentSetCopy->keyToIndex(mpExperiment->CCopasiParameter::getKey());
1706  size_t Next = Current + 1;
1707 
1708  // Find all experiments which are like this.
1709  while (Next < mpExperimentSetCopy->getExperimentCount() && mpCheckTo->isChecked())
1710  {
1712 
1713  if (!isLikePreviousExperiment(pNext)) break;
1714 
1715  Next++;
1716  }
1717 
1718  // Update each of them.
1719  while (true)
1720  {
1721  Next--;
1722 
1724 
1725  bool Changed = saveTable(pNext);
1726 
1727  if (Changed)
1728  {
1729  std::ifstream File;
1730  File.open(CLocaleString::fromUtf8(pNext->getFileName()).c_str());
1731 
1732  size_t CurrentLine = 1;
1733  pNext->read(File, CurrentLine);
1734  pNext->compile();
1735  }
1736 
1737  pNext->setWeightMethod((CExperiment::WeightMethod) weightMethod);
1738  pNext->calculateWeights();
1739 
1740  if (Next == Current) break;
1741  }
1742 
1743  loadTable(mpExperiment, false);
1744 }
friend class CQExperimentDataValidator
std::vector< std::string > getFileNames() const
void slotTypeChanged(int row, int index)
const std::string & getFileName() const
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
CQExperimentDataValidator * mpValidatorFirst
bool setExperimentType(const CCopasiTask::Type &type)
C_FLOAT64 getScale(const size_t &index) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
#define pdelete(p)
Definition: copasi.h:215
bool setScale(const size_t &index, const C_FLOAT64 &scale)
bool getFirstUnusedSection(size_t &First, size_t &Last)
CQExperimentDataValidator(QLineEdit *parent, const char *name, CQExperimentData *pContext, const Type &type)
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
void slotExprimentType(bool isSteadyState)
const unsigned C_INT32 & getFirstRow() const
virtual CCopasiObjectName getCN() const
bool isLikePreviousExperiment(CExperiment *pExperiment)
CQComboDelegate * mpComboDelegate
const std::string & getObjectName() const
bool validateLast(const size_t &index, const size_t &value)
CExperiment::Type getRole(const size_t &index) const
std::map< std::string, std::string > mFileMap
const std::string & getFileName() const
CCopasiObject * get(const std::string &key)
C_FLOAT64 getDefaultScale(const size_t &index) const
static std::string getAllMessageText(const bool &chronological=true)
void slotFileChanged(QListWidgetItem *pCurrentItem, QListWidgetItem *pPreviousItem)
#define COL_BTN
CCopasiDataModel * mpDataModel
bool setHeaderRow(const unsigned C_INT32 &headerRow)
void slotCheckTo(bool checked)
#define COL_OBJECT_HIDDEN
static std::string fileName(const std::string &path)
Definition: CDirEntry.cpp:119
bool setFileName(const std::string &fileName)
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
#define C_INVALID_INDEX
Definition: copasi.h:222
CExperiment * getExperiment(const size_t &index)
const WeightMethod & getWeightMethod() const
void slotCheckNormalizeWeightsPerExperiment(bool flag)
#define C_INT32
Definition: copasi.h:90
CQExperimentDataValidator * mpValidatorName
static void clearDeque()
size_t guessColumnNumber() const
void setNormalizeWeightsPerExperiment(bool flag)
static bool filter(const ObjectClasses &classes, const CCopasiObject *pObject)
std::map< std::string, std::string > mKeyMap
static CConfigurationFile * getConfiguration()
bool removeParameter(const std::string &name)
const std::vector< std::string > & getColumnNames() const
#define COL_SCALE
bool setFileName(const std::string &fileName)
virtual void saved() const
Definition: CQValidator.h:71
const C_FLOAT64 & getWeight() const
CExperiment * addExperiment(const CExperiment &experiment)
virtual State revalidate()
Definition: CQValidator.h:63
CQExperimentData * mpContext
CExperiment * mpExperiment
bool getNextUnusedSection(size_t &First, size_t &Last)
bool validateFirst(const size_t &index, const size_t &value)
bool setSeparator(const std::string &seperator)
unsigned int mOldWeightMethod
static size_t size()
bool setRole(const size_t &index, const CExperiment::Type &role)
bool saveExperiment(CExperiment *pExperiment, const bool &full)
static const QIcon & icon(const IconID &id)
void setWeight(const C_FLOAT64 &weight)
CExperimentObjectMap & getObjectMap()
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void slotExperimentChanged(QListWidgetItem *pCurrentItem, QListWidgetItem *pPreviousItem)
static QString getOpenFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
#define COL_NAME
virtual void loadTable(CExperiment *pExperiment, const bool &guess)
CExperimentFileInfo * mpFileInfo
const unsigned C_INT32 & getHeaderRow() const
CCopasiParameter * getParameter(const std::string &name)
static const std::string WeightMethodName[]
Definition: CExperiment.h:101
#define COL_TYPE_HIDDEN
void slotWeightMethod(int weightMethod)
virtual State validate(QString &input, int &pos) const
CType toEnum(const char *attribute, const char **enumNames, const CType &enumDefault)
Definition: utility.h:107
void slotModelObject(const QModelIndex &index)
QStringList mTypeWithoutTimeItems
size_t keyToIndex(const std::string &key) const
long int flag
Definition: f2c.h:52
void setTypeItems(const int &timeRow)
void enableEdit(const bool &enable)
const CCopasiTask::Type & getExperimentType() const
virtual bool load(CExperimentSet *pExperimentSet, CCopasiDataModel *pDataModel)
bool calculateWeights()
static CKeyFactory * getKeyFactory()
#define COL_TYPE
void setThreshold(const unsigned C_INT32 &threshold)
#define C_FLOAT64
Definition: copasi.h:92
void updateFittedPoints()
#define InvalidIndex
const unsigned C_INT32 & getThreshold() const
std::vector< std::string > getExperimentNames() const
std::string StringPrint(const char *format,...)
Definition: utility.cpp:87
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
void slotCheckTab(bool checked)
bool compile(const std::vector< CCopasiContainer * > listOfContainer=CCopasiContainer::EmptyList)
const std::string & getSeparator() const
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
CExperimentSet * mpExperimentSet
CQExperimentDataValidator * mpValidatorHeader
virtual bool loadExperiment(CExperiment *pExperiment)
bool setNumColumns(const unsigned C_INT32 &cols)
QStringList mTypeItems
void setItems(int row, const QStringList *pComboItems)
CQExperimentData(QWidget *parent=0, const char *name=0, bool modal=false, Qt::WindowFlags fl=0)
void selectModelObject(const int &row)
std::string getObjectCN(const size_t &index) const
bool setFirstRow(const unsigned C_INT32 &firstRow)
#define COL_OBJECT
static CLocaleString fromUtf8(const std::string &utf8)
virtual State validate(QString &input, int &pos) const
Definition: CQValidator.cpp:25
CExperimentSet * mpExperimentSetCopy
bool setNumCols(const size_t &numCols)
const unsigned C_INT32 & getLastRow() const
bool validateHeader(const size_t &index, const size_t &value)
bool setLastRow(const unsigned C_INT32 &lastRow)
bool setObjectName(const std::string &name)
CExperiment * getExperiment(const std::string &name)
bool getNormalizeWeightsPerExperiment() const
bool setObjectCN(const size_t &index, const std::string &objectCN)
bool readColumnNames()
State setColor(const State &state) const
Definition: CQValidator.h:84
static const std::string TypeName[]
Definition: CExperiment.h:79
bool saveTable(CExperiment *pExperiment)
void slotCheckFrom(bool checked)
size_t getExperimentCount() const
CQExperimentDataValidator * mpValidatorLast
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)
void experimentChanged()
bool setWeightMethod(const WeightMethod &weightMethod)
void slotCheckHeader(bool checked)
void removeExperiment(const size_t &index)
bool read(std::istream &in, size_t &currentLine)
#define max(a, b)
Definition: f2c.h:176