Exemplo n.º 1
0
bool TaskWidget::commonAfterRunTask()
{
  if (!mpTask) return false;

  if (CRootContainer::getConfiguration()->displayPopulations())
    {

      if (dynamic_cast<COptTask*>(mpTask) != NULL || dynamic_cast<CFitTask*>(mpTask) != NULL)
        {
          CopasiUI3Window* pWindow = CopasiUI3Window::getMainWindow();
          CQOptPopulation* pPopWidget = pWindow->getPopulationDisplay();
          COptPopulationMethod* pMethod = dynamic_cast<COptPopulationMethod*>(mpTask->getMethod());
          pPopWidget->setMethod(NULL);

          if (pMethod != NULL)
            {
              mpDataModel->removeInterface(pPopWidget);
            }
        }
    }

  if (mProgressBar != NULL)
    {
      mProgressBar->finish();
      mProgressBar->deleteLater();
      mProgressBar = NULL;
    }

  mpTask->setCallBack(NULL);

  CCopasiMessage::clearDeque();

  assert(mpDataModel != NULL);
  mpDataModel->finish();

  CMathContainer * pContainer = mpTask->getMathContainer();
  protectedNotify(ListViews::ObjectType::STATE, ListViews::CHANGE, pContainer->getModel().getKey());

  unsetCursor();
  CopasiUI3Window::getMainWindow()->suspendAutoSave(false);

  return loadTask();
}
Exemplo n.º 2
0
bool TaskWidget::commonBeforeRunTask()
{
  // save the state of the widget
  if (!saveTask())
    {
      CQMessageBox::critical(this, "Simulation Error",
                             CCopasiMessage::getAllMessageText().c_str(),
                             QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton);
      return false;
    }

  if (!mpTask) return false;

  if (mProgressBar != NULL)
    {
      //CQMessageBox::critical(this, "Task in Progress",
      //                       "A task is currently running, another cannot be started before the current task ended.",
      //                       QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton);
      return false;
    }

  // if overwrite is enabled and the file exists, then ask
  if (!mpTask->getReport().getTarget().empty() &&
      mpTask->getReport().confirmOverwrite())
    {
      // The target might be a relative path
      std::string Target = mpTask->getReport().getTarget();

      if (CDirEntry::isRelativePath(Target) &&
          !CDirEntry::makePathAbsolute(Target, mpDataModel->getReferenceDirectory()))
        Target = CDirEntry::fileName(Target);

      if (CDirEntry::exist(Target) &&
          QMessageBox::question(this,
                                QString("Confirm Overwrite"),
                                QString("The report file already exists. Would you like to overwrite it? \n\n(You can disable this dialog by clicking the 'Report' button.)"),
                                QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
        return false;
    }

  //set mouse cursor
  setCursor(Qt::WaitCursor);

  //handle autosave feature
  CopasiUI3Window::getMainWindow()->autoSave();
  CopasiUI3Window::getMainWindow()->suspendAutoSave(true);

  //create progress bar
  mProgressBar = CProgressBar::create();
  mpTask->setCallBack(mProgressBar);

  CCopasiMessage::clearDeque();

  // create population display if needed
  if (CRootContainer::getConfiguration()->displayPopulations())
    {

      if (dynamic_cast<COptTask*>(mpTask) != NULL || dynamic_cast<CFitTask*>(mpTask) != NULL)
        {
          CopasiUI3Window* pWindow = CopasiUI3Window::getMainWindow();
          CQOptPopulation* pPopWidget = pWindow->getPopulationDisplay();
          COptPopulationMethod* pMethod = dynamic_cast<COptPopulationMethod*>(mpTask->getMethod());
          pPopWidget->setMethod(pMethod);

          if (pMethod != NULL)
            {
              pPopWidget->addToMainWindow(pWindow);
              pPopWidget->show();
              mpDataModel->addInterface(pPopWidget);
            }
        }
    }

  return true;
}