<commit_before>// Begin CVS Header
//   $Source: /fs/turing/cvs/copasi_dev/cvs_admin/addHeader,v $
//   $Revision: 1.15.2.2 $
//   $Name: Build-33 $
//   $Author: shoops $
//   $Date: 2011/02/17 19:14:45 $
// End CVS Header

// Copyright (C) 2012 - 2010 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and The University
// of Manchester.
// All rights reserved.

/*
 *  Created by <NAME> on 5/21/10.
 */

#include "CQCrossSectionTaskWidget.h"
#include "listviews.h"
#include "CQTaskBtnWidget.h"
#include "CQTaskHeaderWidget.h"
#include "CQTaskMethodWidget.h"
#include "CQMessageBox.h"
#include "CQValidator.h"

#include "resourcesUI/CQIconResource.h"

#include "copasi.h"

#include "DataModelGUI.h"
#include "qtUtilities.h"
#include "CCopasiSelectionDialog.h"

#include "CopasiDataModel/CCopasiDataModel.h"
#include "report/CCopasiRootContainer.h"
#include "model/CModel.h"
#include "utilities/CCopasiException.h"
#include "report/CKeyFactory.h"

#include "crosssection/CCrossSectionTask.h"
#include "crosssection/CCrossSectionProblem.h"
#include "crosssection/CCrossSectionMethod.h"

/*
 *  Constructs a CQCrossSectionWidget which is a child of 'parent', with the
 *  name 'name'.'
 */
CQCrossSectionTaskWidget::CQCrossSectionTaskWidget(QWidget* parent, const char* name)
    : TaskWidget(parent, name)
{
  setupUi(this);
  mpButtonVariable->setIcon(CQIconResource::icon(CQIconResource::copasi));

  init();
}

/*
 *  Destroys the object and frees any allocated resources
 */
CQCrossSectionTaskWidget::~CQCrossSectionTaskWidget()
{
  destroy();
  // no need to delete child widgets, Qt does it all for us
}

void CQCrossSectionTaskWidget::init()
{
  mpCrossSectionProblem = NULL;

  mpHeaderWidget->setTaskName("Cross Section");

  verticalLayout->insertWidget(0, mpHeaderWidget); // header

  mpMethodWidget->showMethodParameters(true);
  verticalLayout->addWidget(mpMethodWidget);

  verticalLayout->addWidget(mpBtnWidget);      // 'footer'

  mpValidatorCrossing = new CQValidatorDouble(mpLineEditValue);
  mpLineEditValue->setValidator(mpValidatorCrossing);

  mpValidatorLC = new CQValidatorInt(mpLineEditLC);
  mpValidatorLC->setRange(0, std::numeric_limits< int >::max());
  mpLineEditLC->setValidator(mpValidatorLC);

  mpValidatorLT = new CQValidatorDouble(mpLineEditLT);
  mpValidatorLT->setRange(0, std::numeric_limits< double >::max());
  mpLineEditLT->setValidator(mpValidatorLT);

  mpValidator = new CQValidatorDouble(mpLineEdit);
  mpLineEdit->setValidator(mpValidator);
}


void CQCrossSectionTaskWidget::destroy()
{
  pdelete(mpCrossSectionProblem);
}


bool CQCrossSectionTaskWidget::runTask()
{
  return true;
}


/*
 * Function to save actual changes of the Task
 */
bool CQCrossSectionTaskWidget::saveTask()
{
  // check the existence of Task
  CCrossSectionTask * pTask =
    dynamic_cast< CCrossSectionTask * >(mpTask);

  if (!pTask) return false;

  // save functions from the Parent, TaskWidget
  saveCommon();
  saveMethod();

  // check the existence of Problem
  CCrossSectionProblem* pProblem =
    dynamic_cast<CCrossSectionProblem *>(pTask->getProblem());
  assert(pProblem);

  // save the actual changes

  if (mpCheckLC->isChecked())
    pProblem->setCrossingsLimit(mpLineEditLC->text().toULong());

  if (mpCheckLT->isChecked())
    pProblem->setTimeLimit(mpLineEditLT->text().toDouble());

  if (mpCheck->isChecked())
    pProblem->setOutputStartTime(mpLineEdit->text().toDouble());

  mpValidatorCrossing->saved();
  mpValidatorLC->saved();
  mpValidatorLT->saved();
  mpValidator->saved();

  return true;
}

/*
 * Function to load saved values of the Task
 */
bool CQCrossSectionTaskWidget::loadTask()
{
  // load Task
  CCrossSectionTask * pTask =
    dynamic_cast< CCrossSectionTask * >(mpTask);

  if (!pTask) return false;

  // load functions from the Parent, TaskWidget
  loadCommon();
  loadMethod();

  // load Problem
  CCrossSectionProblem* pProblem =
    dynamic_cast<CCrossSectionProblem *>(pTask->getProblem());
  assert(pProblem);

  pdelete(mpCrossSectionProblem);
  mpCrossSectionProblem = new CCrossSectionProblem(*pProblem);

  CCrossSectionMethod* pMethod =
    dynamic_cast<CCrossSectionMethod *>(pTask->getMethod());
  assert(pMethod);

  // load the saved values

  mpCheckLC->setChecked(pProblem->getFlagLimitCrossings());
  mpLineEditLC->setEnabled(pProblem->getFlagLimitCrossings());

  if (pProblem->getFlagLimitCrossings())
    mpLineEditLC->setText(QString::number(pProblem->getCrossingsLimit()));
  else
    mpLineEditLC->setText("");

  mpCheckLT->setChecked(pProblem->getFlagLimitTime());
  mpLineEditLT->setEnabled(pProblem->getFlagLimitTime());
<commit_msg>small adaptation to changes in cross section task<commit_after>// Begin CVS Header
//   $Source: /fs/turing/cvs/copasi_dev/cvs_admin/addHeader,v $
//   $Revision: 1.15.2.2 $
//   $Name: Build-33 $
//   $Author: shoops $
//   $Date: 2011/02/17 19:14:45 $
// End CVS Header

// Copyright (C) 2012 - 2010 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and The University
// of Manchester.
// All rights reserved.

/*
 *  Created by <NAME> on 5/21/10.
 */

#include "CQCrossSectionTaskWidget.h"
#include "listviews.h"
#include "CQTaskBtnWidget.h"
#include "CQTaskHeaderWidget.h"
#include "CQTaskMethodWidget.h"
#include "CQMessageBox.h"
#include "CQValidator.h"

#include "resourcesUI/CQIconResource.h"

#include "copasi.h"

#include "DataModelGUI.h"
#include "qtUtilities.h"
#include "CCopasiSelectionDialog.h"

#include "CopasiDataModel/CCopasiDataModel.h"
#include "report/CCopasiRootContainer.h"
#include "model/CModel.h"
#include "utilities/CCopasiException.h"
#include "report/CKeyFactory.h"

#include "crosssection/CCrossSectionTask.h"
#include "crosssection/CCrossSectionProblem.h"
//#include "crosssection/CCrossSectionMethod.h"

/*
 *  Constructs a CQCrossSectionWidget which is a child of 'parent', with the
 *  name 'name'.'
 */
CQCrossSectionTaskWidget::CQCrossSectionTaskWidget(QWidget* parent, const char* name)
    : TaskWidget(parent, name)
{
  setupUi(this);
  mpButtonVariable->setIcon(CQIconResource::icon(CQIconResource::copasi));

  init();
}

/*
 *  Destroys the object and frees any allocated resources
 */
CQCrossSectionTaskWidget::~CQCrossSectionTaskWidget()
{
  destroy();
  // no need to delete child widgets, Qt does it all for us
}

void CQCrossSectionTaskWidget::init()
{
  mpCrossSectionProblem = NULL;

  mpHeaderWidget->setTaskName("Cross Section");

  verticalLayout->insertWidget(0, mpHeaderWidget); // header

  mpMethodWidget->showMethodParameters(true);
  verticalLayout->addWidget(mpMethodWidget);

  verticalLayout->addWidget(mpBtnWidget);      // 'footer'

  mpValidatorCrossing = new CQValidatorDouble(mpLineEditValue);
  mpLineEditValue->setValidator(mpValidatorCrossing);

  mpValidatorLC = new CQValidatorInt(mpLineEditLC);
  mpValidatorLC->setRange(0, std::numeric_limits< int >::max());
  mpLineEditLC->setValidator(mpValidatorLC);

  mpValidatorLT = new CQValidatorDouble(mpLineEditLT);
  mpValidatorLT->setRange(0, std::numeric_limits< double >::max());
  mpLineEditLT->setValidator(mpValidatorLT);

  mpValidator = new CQValidatorDouble(mpLineEdit);
  mpLineEdit->setValidator(mpValidator);
}


void CQCrossSectionTaskWidget::destroy()
{
  pdelete(mpCrossSectionProblem);
}


bool CQCrossSectionTaskWidget::runTask()
{
  return true;
}


/*
 * Function to save actual changes of the Task
 */
bool CQCrossSectionTaskWidget::saveTask()
{
  // check the existence of Task
  CCrossSectionTask * pTask =
    dynamic_cast< CCrossSectionTask * >(mpTask);

  if (!pTask) return false;

  // save functions from the Parent, TaskWidget
  saveCommon();
  saveMethod();

  // check the existence of Problem
  CCrossSectionProblem* pProblem =
    dynamic_cast<CCrossSectionProblem *>(pTask->getProblem());
  assert(pProblem);

  // save the actual changes

  if (mpCheckLC->isChecked())
    pProblem->setCrossingsLimit(mpLineEditLC->text().toULong());

  if (mpCheckLT->isChecked())
    pProblem->setTimeLimit(mpLineEditLT->text().toDouble());

  if (mpCheck->isChecked())
    pProblem->setOutputStartTime(mpLineEdit->text().toDouble());

  mpValidatorCrossing->saved();
  mpValidatorLC->saved();
  mpValidatorLT->saved();
  mpValidator->saved();

  return true;
}

/*
 * Function to load saved values of the Task
 */
bool CQCrossSectionTaskWidget::loadTask()
{
  // load Task
  CCrossSectionTask * pTask =
    dynamic_cast< CCrossSectionTask * >(mpTask);

  if (!pTask) return false;

  // load functions from the Parent, TaskWidget
  loadCommon();
  loadMethod();

  // load Problem
  CCrossSectionProblem* pProblem =
    dynamic_cast<CCrossSectionProblem *>(pTask->getProblem());
  assert(pProblem);

  pdelete(mpCrossSectionProblem);
  mpCrossSectionProblem = new CCrossSectionProblem(*pProblem);

  //CCrossSectionMethod* pMethod =
  //  dynamic_cast<CCrossSectionMethod *>(pTask->getMethod());
  //assert(pMethod);

  //for now, we use a trajectory method
  CTrajectoryMethod* pMethod =
  dynamic_cast<CTrajectoryMethod *>(pTask->getMethod());
  assert(pMethod);

  // load the saved values

  mpCheckLC->setChecked(pProblem->getFlagLimitCrossings());
  mpLineEditLC->setEnabled(pProblem->getFlagLimitCrossings());

  if (pProblem->getFlagLimitCrossings())
    mpLineEditLC->setText(QString::number(pProblem->getCrossingsLimit()));
  else
    mpLineEditLC->setText("");

  mpCheckLT->setChecked(pProblem->getFlagLimitTime());
  mpLineEditLT->setEnabled(pProblem->getFlagLimitTime());

{'fraction_non_alphanumeric': 0.13155686109945447, 'fraction_numerical': 0.007763323541754091, 'mean_word_length': 5.170226537216829, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2633975', 'n_tokens_mistral': 3191, 'n_tokens_neox': 3022, 'n_words': 605}