<commit_before>// Begin CVS Header
//   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/copasiui3window.cpp,v $
//   $Revision: 1.269 $
//   $Name:  $
//   $Author: nsimus $
//   $Date: 2009/10/30 16:10:35 $
// End CVS Header

// Copyright (C) 2008 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., EML Research, gGmbH, University of Heidelberg,
// and The University of Manchester.
// All rights reserved.

// Copyright (C) 2001 - 2007 by <NAME>, Virginia Tech Intellectual
// Properties, Inc. and EML Research, gGmbH.
// All rights reserved.

#include <QMenuBar>
#include <QTimer>
#include <QComboBox>
#include <QToolBar>
#include <QTextEdit>

#include <vector>
#include <sstream>

#ifdef COPASI_SBW_INTEGRATION
#include <stdlib.h>
#endif // COPASI_SBW_INTEGRATION

extern const char * CopasiLicense;

#include "AboutDialog.h"
#include "CopasiFileDialog.h"
#include "copasiui3window.h"
#include "listviews.h"
#include "DataModelGUI.h"
#include "ObjectBrowserDialog.h"
#include "qtUtilities.h"
#include "SliderDialog.h"
#include "CQMessageBox.h"
#include "CQPreferenceDialog.h"
#include "CQSBMLFileDialog.h"
#include "copasi/UI/qtUtilities.h"
#include "copasiWidget.h"

#include "CopasiDataModel/CCopasiDataModel.h"
#include "report/CCopasiRootContainer.h"
#include "utilities/CCopasiException.h"
#include "utilities/CDirEntry.h"
#include "model/CModel.h"
#include "commandline/COptionParser.h"
#include "commandline/COptions.h"
#include "commandline/CConfigurationFile.h"
#include "wizard/wizard.h"
#include "report/CKeyFactory.h"
#include "sbml/SBMLIncompatibility.h"
#include "MIRIAM/CConstants.h"
#include "copasi/utilities/CVersion.h"
#include "model/CModelExpansion.h"
#ifdef WITH_MERGEMODEL
#include "model/CModelMerging.h"
#endif

#include "./icons/filenew.xpm"
#include "./icons/fileopen.xpm"
#include "./icons/filesave.xpm"
//#include "./icons/fileprint.xpm"
#include "./icons/showSliders.xpm"
#include "./icons/Copasi16-Alpha.xpm"
#include "./icons/checkModel.xpm"
#include "./icons/MIRIAM.xpm"
#include "./icons/istos.xpm"
#include "./icons/stois.xpm"
#include "./icons/photo.xpm"

#ifdef WITH_MERGEMODEL
#include "./icons/fileadd.xpm"
#endif

#define AutoSaveInterval 10*60*1000

#ifdef DEBUG_UI
#include <QtDebug>
#endif

static const unsigned char image0_data[] =
{
  0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
  0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,
  0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff, 0x61, 0x00, 0x00, 0x03,
  0x1f, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x85, 0x93, 0x6b, 0x48, 0x54,
  0x09, 0x14, 0xc7, 0xcf, 0x75, 0xee, 0xf8, 0x68, 0xd0, 0x4c, 0xad, 0x29,
  0xb7, 0xed, 0x49, 0x46, 0x59, 0xd9, 0x46, 0x4a, 0xa5, 0x6d, 0x0f, 0x74,
  0xb7, 0x28, 0xa4, 0xa0, 0x2c, 0xc4, 0xad, 0xa8, 0x88, 0xa2, 0x68, 0x09,
  0xb4, 0x97, 0x59, 0xba, 0x6d, 0x0a, 0x91, 0x21, 0xd1, 0x16, 0x54, 0x8a,
  0x14, 0x11, 0x3d, 0xc6, 0x8c, 0x61, 0x62, 0x26, 0xc7, 0x9a, 0xa8, 0xac,
  0xed, 0x85, 0x65, 0x39, 0x3d, 0x74, 0x1c, 0xf3, 0x35, 0x77, 0x1e, 0xa2,
  0x73, 0xbd, 0xf7, 0xce, 0x78, 0xe7, 0xce, 0xbf, 0x2f, 0x23, 0xbb, 0xb8,
  0xdb, 0xee, 0x81, 0xf3, 0xed, 0xfc, 0x7e, 0xe7, 0xc3, 0x39, 0x7f, 0x06,
  0x00, 0xfd, 0x4f, 0x8d, 0x1a, 0x1c, 0x54, 0x96, 0x70, 0x9c, 0xf4, 0x73,
  0x67, 0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0xf5, 0xbb, 0x1d, 0xf8, 0xbd,
  0xe4, 0x89, 0xcf, 0x6a, 0xf5, 0xb8, 0xfa, 0xac, 0x66, 0xbc, 0x39, 0xb2,
  0x04, 0x67, 0x17, 0x8f, 0xc6, 0xc9, 0x94, 0x58, 0x14, 0x25, 0x6b, 0xb1,
  0x3d, 0x3e, 0x01, 0x5b, 0x7f, 0x58, 0x89, 0x1b, 0x97, 0x2d, 0x3d, 0x92,
  0xe4, 0xcf, 0x1b, 0xfa, 0x05, 0x26, 0x94, 0xc6, 0xe9, 0x4f, 0x1e, 0xd9,
  0xae, 0x94, 0x97, 0x9b, 0xe7, 0x3f, 0x6b, 0xe8, 0x60, 0xd4, 0xe4, 0x26,
  0xa8, 0xe2, 0x48, 0x12, 0x88, 0x22, 0x23, 0x18, 0x9a, 0x97, 0x36, 0x1a,
  0x99, 0x3f, 0x25, 0xf3, 0x39, 0x1b, 0xd3, 0xaa, 0xb4, 0xda, 0x98, 0x52,
  0x22, 0x72, 0x0d, 0x25, 0x6e, 0x48, 0x40, 0x44, 0x14, 0xae, 0x28, 0xca,
  0x6a, 0x8e, 0xf3, 0xae, 0xb0, 0xb5, 0x38, 0x53, 0x82, 0x20, 0x76, 0x84,
  0x26, 0xd2, 0xa9, 0xd5, 0xc6, 0xb5, 0x27, 0x26, 0x8e, 0x30, 0xab, 0x54,
  0x2a, 0x0b, 0x11, 0xb9, 0x87, 0x47, 0xf6, 0x2b, 0x7b, 0xdd, 0x48, 0xf1,
  0x37, 0x6e, 0xda, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
  0xae, 0x42, 0x60, 0x82
};

CopasiUI3Window * CopasiUI3Window::create()
{
  CopasiUI3Window * pWindow = new CopasiUI3Window;

#ifdef COPASI_LICENSE_COM

  if (!pWindow->checkRegistration())
    pdelete(pWindow);

#endif // COPASI_LICENSE_COM

#ifdef COPASI_SBW_INTEGRATION
  pWindow->connectSBW();

  if (COptions::compareValue("SBWRegister", true))
    pWindow->registerSBW();

#endif // COPASI_SBW_INTEGRATION

  return pWindow;
}

/**
 *  Constructs a CopasiUI window which is a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 *  @param parent The widget which this window is a child of.
 *  @param name The object name is a text that can be used to identify
 *  this QObject. It's particularly useful in conjunction with the Qt Designer.
 *  You can find an object by name (and type) using child(), and more than one
 *  using queryList().
 *  @param flags Flags for this widget. Refer Qt::WidgetFlags of Qt documentation
 *  for more information about these flags.
 */
CopasiUI3Window::CopasiUI3Window():
    QMainWindow(),
    dataModel(NULL),
    listViews(NULL),
    mpBoxSelectFramework(NULL),
    newFlag(0),
    mpSliders(NULL),
    mpObjectBrowser(NULL),
    mSaveAsRequired(true),
    mpAutoSaveTimer(NULL),
    mSuspendAutoSave(false),
    mpMenuRecentFiles(NULL),
    mpMenuRecentSBMLFiles(NULL),
    mpMIRIAMResources(NULL)
#ifdef COPASI_SBW_INTEGRATION
    , mpSBWModule(NULL)
    , mAnalyzerModules()
    , mAnalyzerServices()
    , mpMenuSBW(NULL)
    , mIdMenuSBW(-1)
    , mIgnoreSBWShutdownEvent(false)
#endif // COPASI_SBW_INTEGRATION
{
  // set destructive close
  Qt::WindowFlags f = this->windowFlags();
  f |= Qt::WDestructiveClose;
  this->setWindowFlags(f);
  QImage img;
  img.loadFromData(image0_data, sizeof(image0_data), "PNG");
  QPixmap image0 = QPixmap::fromImage(img);
  setWindowIcon(image0);

  // Set the window caption/title
  FixedTitle = "COPASI ";
#ifdef COPASI_LICENSE_COM
  FixedTitle += "(commercial) ";
#endif // COPASI_LICENSE_COM
  FixedTitle += FROM_UTF8(CVersion::VERSION.getVersion());
  updateTitle();

  createActions();
  createToolBar(); // creates a tool bar
  createMenuBar();  // creates a menu bar

  setIconSize(QSize(18, 20));

  mpaSave->setEnabled(false);
  mpaSaveAs->setEnabled(false);
  mpaExportSBML->setEnabled(false);
  mpaExportODE->setEnabled(false);

  if (!dataModel)
    {
      // create the data model
      dataModel = new DataModelGUI();
    }

  listViews = new ListViews(this);

  connect(listViews->folders, SIGNAL(currentChanged(Q3ListViewItem*)), this, SLOT(listViewsFolderChanged(Q3ListViewItem*)));

  ListViews::setDataModel(dataModel);
  listViews->show();
  this->setCentralWidget(listViews);

  //create sliders window
  this->mpSliders = new SliderDialog(NULL);
  this->mpSliders->setParentWindow(this);
  C_INT32 id = ((FolderListItem*)listViews->folders->currentItem())->getFolder()->getId();
  this->mpSliders->setCurrentFolderId(id);
  this->mpSliders->resize(320, 350);

  //look at commandline
  if (!COptions::compareValue("ImportSBML", std::string("")))
    {
      // Import the SBML File
      std::string ImportSBML;
      COptions::getValue("ImportSBML", ImportSBML);
      slotImportSBML(FROM_UTF8(ImportSBML));
    }
  else if (COptions::getNonOptions().size())
    {
      slotFileOpen(FROM_UTF8(COptions::getNonOptions()[0]));
    }
  else
    {
      newDoc();
    }

  listViews->switchToOtherWidget(0, "");

  resize(800, 600);
  show();

  checkPendingMessages();

  // Assure that the changed flag is still false;
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  (*CCopasiRootContainer::getDatamodelList())[0]->changed(false);

  mpAutoSaveTimer = new QTimer(this);
  mpAutoSaveTimer->start(AutoSaveInterval); // every 10 minutes
  connect(mpAutoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
  // ListViews::notify(ListViews::FUNCTION, ListViews::ADD, "");
}

CopasiUI3Window::~CopasiUI3Window()
{
#ifdef COPASI_SBW_INTEGRATION
  pdelete(mpSBWModule);
#endif // COPASI_SBW_INTEGRATION

  pdelete(listViews);
  pdelete(dataModel);
}

void CopasiUI3Window::createActions()
{
  //TODO: use the QKeySequence standard shortcuts
  //TODO: add tool tips, status tips etc.

  mpaNew = new QAction(QPixmap(filenew), "&New", Qt::CTRL + Qt::Key_N, this, "new");
  connect(mpaNew, SIGNAL(activated()), this, SLOT(newDoc()));

  mpaOpen = new QAction(QPixmap(fileopen), "&Open...", Qt::CTRL + Qt::Key_O, this, "open");
  connect(mpaOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));

  mpaOpenCopasiFiles = new QAction(QPixmap(fileopen), "COP&ASI Files...", Qt::CTRL + Qt::Key_A, this, "copasifiles");
  connect(mpaOpenCopasiFiles, SIGNAL(activated()), this, SLOT(slotFileExamplesCopasiFiles()));

  mpaOpenSBMLFiles = new QAction(QPixmap(fileopen), "S&BML Files...", Qt::CTRL + Qt::Key_B, this, "sbmlfiles");
  connect(mpaOpenSBMLFiles, SIGNAL(activated()), this, SLOT(slotFileExamplesSBMLFiles()));

  mpaSave = new QAction(QPixmap(filesave), "&Save", Qt::CTRL + Qt::Key_S, this, "save");
  connect(mpaSave, SIGNAL(activated()), this, SLOT(slotFileSave()));

  mpaSaveAs = new QAction(QPixmap(filesave), "Save &As...", Qt::SHIFT + Qt::CTRL + Qt::Key_S, this, "saveas");
  connect(mpaSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));

  mpaImportSBML = new QAction(QPixmap(fileopen), "&Import SBML...", Qt::CTRL + Qt::Key_I, this, "importsbml");
  connect(mpaImportSBML, SIGNAL(activated()), this, SLOT(slotImportSBML()));

  mpaExportSBML = new QAction(QPixmap(filesave), "&Export SBML...", Qt::CTRL + Qt::Key_E, this, "exportsbml");
  connect(mpaExportSBML, SIGNAL(activated()), this, SLOT(slotExportSBML()));

  mpaExportODE = new QAction(QPixmap(filesave), "Export ODEs...", Qt::CTRL + Qt::Key_M, this, "exportode");
  connect(mpaExportODE, SIGNAL(activated()), this, SLOT(slotExportMathModel()));

  mpaQuit = new QAction("&Quit", Qt::CTRL + Qt::Key_Q, this, "quitcopasi");
  connect(mpaQuit, SIGNAL(activated()), this, SLOT(slotQuit()));

  mpaSliders = new QAction(QPixmap(toggleSliderDialog), "Show sliders", 0, this, "showsliders");
  mpaSliders->setToggleAction(true);
  connect(mpaSliders, SIGNAL(toggled(bool)), this, SLOT(slotShowSliders(bool)));

  mpaObjectBrowser = new QAction("Object &Browser", 0, this, "objectbrowser");
  mpaObjectBrowser->setToggleAction(true);
  connect(mpaObjectBrowser, SIGNAL(toggled(bool)), this, SLOT(slotShowObjectBrowserDialog(bool)));

  mpaCheckModel = new QAction(QPixmap(checkModel_xpm), "Check model", 0, this, "checkmodel");
  connect(mpaCheckModel, SIGNAL(activated()), this, SLOT(slotCheckModel()));

  mpaUpdateMIRIAM = new QAction(QPixmap(MIRIAM_xpm), "Update MIRIAM", 0, this, "updatemiriam");
  connect(mpaUpdateMIRIAM, SIGNAL(activated()), this, SLOT(slotUpdateMIRIAM()));

  mpaApplyInitialState = new QAction(QPixmap(istos_xpm), "Apply initial state", 0, this, "applyinitialstate");
  connect(mpaApplyInitialState, SIGNAL(activated()), this, SLOT(slotApplyInitialState()));

  mpaUpdateInitialState = new QAction(QPixmap(stois_xpm), "Update initial state from current state", 0, this, "updateinitialstate");
  connect(mpaUpdateInitialState, SIGNAL(activated()), this, SLOT(slotUpdateInitialState()));

  mpaCapture = new QAction(QPixmap(photo), "Capture the main window", 0, this, "capture");
  connect(mpaCapture, SIGNAL(activated()), this, SLOT(slotCapture()));

  mpaExpandModel = new QAction("Create array of compartments (debug version)", 0, this, "expandmodel");
  connect(mpaExpandModel, SIGNAL(activated()), this, SLOT(slotExpandModel()));

  //     QAction* mpaObjectBrowser;

#ifdef WITH_MERGEMODEL
  mpaAddModel = new QAction(QPixmap(fileadd), "&Add ...", Qt::SHIFT + Qt::CTRL + Qt::Key_A, this, "addmodel");
  connect(mpaAddModel, SIGNAL(activated()), this, SLOT(slotAddFileOpen()));

  mpaMergeModels = new QAction("&Merge ...", Qt::SHIFT + Qt::CTRL + Qt::Key_M, this, "mergemodel");
  connect(mpaMergeModels, SIGNAL(activated()), this, SLOT(slotMergeModels()));
#endif
}

void CopasiUI3Window::createToolBar()
{
  QToolBar * tb = addToolBar("MainToolBar");

  tb->addAction(mpaNew);
  tb->addAction(mpaOpen);
  tb->addAction(mpaSave);
  tb->addAction(mpaCapture);
  tb->addAction(mpaSliders);
  tb->addAction(mpaCheckModel);
  tb->addAction(mpaApplyInitialState);
  tb->addAction(mpaUpdateInitialState);
  tb->addAction(mpaUpdateMIRIAM);

#ifdef WITH_MERGEMODEL
  tb->addAction(mpaAddModel);
  //tb->addAction(mpaMergeModels);
#endif

  tb->addSeparator();

  mpBoxSelectFramework = new QComboBox(tb);
  mpBoxSelectFramework->insertItem("Concentrations");
  mpBoxSelectFramework->insertItem("Particle Numbers");
  tb->addWidget(mpBoxSelectFramework);

  //tbMain->setCloseMode(Q3DockWindow::Never);

  connect(mpBoxSelectFramework, SIGNAL(activated(int)), this, SLOT(slotFrameworkChanged(int)));
}

void CopasiUI3Window::createMenuBar()
{

  QMenu * pFileMenu = menuBar()->addMenu("&File");

  pFileMenu->addAction(mpaNew);
  pFileMenu->addAction(mpaOpen);

  mpMenuExamples = pFileMenu->addMenu("Examples");
  mpMenuExamples->addAction(mpaOpenCopasiFiles);
  mpMenuExamples->addAction(mpaOpenSBMLFiles);

  pFileMenu->addAction(mpaSave);
  pFileMenu->addAction(mpaSaveAs);

  pFileMenu->addSeparator();

  pFileMenu->addAction(mpaImportSBML);
  pFileMenu->addAction(mpaExportSBML);
  pFileMenu->addAction(mpaExportODE);

#ifdef WITH_MERGEMODEL
  pFileMenu->addAction(mpaAddModel);
  //pFileMenu->addAction(mpaMergeModels);
#endif

  pFileMenu->addSeparator();

  mpMenuRecentFiles = pFileMenu->addMenu("Recent Files");
  refreshRecentFileMenu();

  mpMenuRecentSBMLFiles = pFileMenu->addMenu("Recent SBML Files");
  refreshRecentSBMLFileMenu();

  pFileMenu->addSeparator();

  pFileMenu->addAction(mpaQuit);

  //****** tools menu **************

  mpTools = menuBar()->addMenu("&Tools");

  mpTools->addAction(mpaApplyInitialState);
  mpTools->addAction(mpaUpdateInitialState);
  mpTools->addAction(mpaSliders);
  mpTools->addAction(mpaCapture);
  mpTools->addAction(mpaMergeModels);

  mpTools->addSeparator();
#ifdef COPASI_DEBUG
  mpTools->addAction(mpaObjectBrowser);
  mpTools->addAction(mpaExpandModel);
  mpTools->addSeparator();
#endif // COPASI_DEBUG

  mpTools->addAction(mpaCheckModel);
  mpTools->insertItem("&Convert to irreversible", this, SLOT(slotConvertToIrreversible()));

#ifdef COPASI_SBW_INTEGRATION
  // create and populate SBW menu<commit_msg>Fix bug of adding the merging tool<commit_after>// Begin CVS Header
//   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/copasiui3window.cpp,v $
//   $Revision: 1.270 $
//   $Name:  $
//   $Author: pwilly $
//   $Date: 2009/10/31 11:54:13 $
// End CVS Header

// Copyright (C) 2008 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., EML Research, gGmbH, University of Heidelberg,
// and The University of Manchester.
// All rights reserved.

// Copyright (C) 2001 - 2007 by <NAME>, Virginia Tech Intellectual
// Properties, Inc. and EML Research, gGmbH.
// All rights reserved.

#include <QMenuBar>
#include <QTimer>
#include <QComboBox>
#include <QToolBar>
#include <QTextEdit>

#include <vector>
#include <sstream>

#ifdef COPASI_SBW_INTEGRATION
#include <stdlib.h>
#endif // COPASI_SBW_INTEGRATION

extern const char * CopasiLicense;

#include "AboutDialog.h"
#include "CopasiFileDialog.h"
#include "copasiui3window.h"
#include "listviews.h"
#include "DataModelGUI.h"
#include "ObjectBrowserDialog.h"
#include "qtUtilities.h"
#include "SliderDialog.h"
#include "CQMessageBox.h"
#include "CQPreferenceDialog.h"
#include "CQSBMLFileDialog.h"
#include "copasi/UI/qtUtilities.h"
#include "copasiWidget.h"

#include "CopasiDataModel/CCopasiDataModel.h"
#include "report/CCopasiRootContainer.h"
#include "utilities/CCopasiException.h"
#include "utilities/CDirEntry.h"
#include "model/CModel.h"
#include "commandline/COptionParser.h"
#include "commandline/COptions.h"
#include "commandline/CConfigurationFile.h"
#include "wizard/wizard.h"
#include "report/CKeyFactory.h"
#include "sbml/SBMLIncompatibility.h"
#include "MIRIAM/CConstants.h"
#include "copasi/utilities/CVersion.h"
#include "model/CModelExpansion.h"
#ifdef WITH_MERGEMODEL
#include "model/CModelMerging.h"
#endif

#include "./icons/filenew.xpm"
#include "./icons/fileopen.xpm"
#include "./icons/filesave.xpm"
//#include "./icons/fileprint.xpm"
#include "./icons/showSliders.xpm"
#include "./icons/Copasi16-Alpha.xpm"
#include "./icons/checkModel.xpm"
#include "./icons/MIRIAM.xpm"
#include "./icons/istos.xpm"
#include "./icons/stois.xpm"
#include "./icons/photo.xpm"

#ifdef WITH_MERGEMODEL
#include "./icons/fileadd.xpm"
#endif

#define AutoSaveInterval 10*60*1000

#ifdef DEBUG_UI
#include <QtDebug>
#endif

static const unsigned char image0_data[] =
{
  0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
  0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,
  0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff, 0x61, 0x00, 0x00, 0x03,
  0x1f, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x85, 0x93, 0x6b, 0x48, 0x54,
  0x09, 0x14, 0xc7, 0xcf, 0x75, 0xee, 0xf8, 0x68, 0xd0, 0x4c, 0xad, 0x29,
  0xb7, 0xed, 0x49, 0x46, 0x59, 0xd9, 0x46, 0x4a, 0xa5, 0x6d, 0x0f, 0x74,
  0xb7, 0x28, 0xa4, 0xa0, 0x2c, 0xc4, 0xad, 0xa8, 0x88, 0xa2, 0x68, 0x09,
  0xb4, 0x97, 0x59, 0xba, 0x6d, 0x0a, 0x91, 0x21, 0xd1, 0x16, 0x54, 0x8a,
  0x14, 0x11, 0x3d, 0xc6, 0x8c, 0x61, 0x62, 0x26, 0xc7, 0x9a, 0xa8, 0xac,
  0xed, 0x85, 0x65, 0x39, 0x3d, 0x74, 0x1c, 0xf3, 0x35, 0x77, 0x1e, 0xa2,
  0x73, 0xbd, 0xf7, 0xce, 0x78, 0xe7, 0xce, 0xbf, 0x2f, 0x23, 0xb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0x16, 0xde, 0x50, 0xa3, 0x0b, 0xf3, 0x70, 0x7e,
  0x5a, 0xb9, 0xad, 0x40, 0xde, 0x5c, 0x90, 0xff, 0x2b, 0xcb, 0xb2, 0x8f,
  0x09, 0x40, 0xac, 0xc1, 0xf0, 0xd6, 0x3a, 0xf5, 0xbb, 0x1d, 0xf8, 0xbd,
  0xe4, 0x89, 0xcf, 0x6a, 0xf5, 0xb8, 0xfa, 0xac, 0x66, 0xbc, 0x39, 0xb2,
  0x04, 0x67, 0x17, 0x8f, 0xc6, 0xc9, 0x94, 0x58, 0x14, 0x25, 0x6b, 0xb1,
  0x3d, 0x3e, 0x01, 0x5b, 0x7f, 0x58, 0x89, 0x1b, 0x97, 0x2d, 0x3d, 0x92,
  0xe4, 0xcf, 0x1b, 0xfa, 0x05, 0x26, 0x94, 0xc6, 0xe9, 0x4f, 0x1e, 0xd9,
  0xae, 0x94, 0x97, 0x9b, 0xe7, 0x3f, 0x6b, 0xe8, 0x60, 0xd4, 0xe4, 0x26,
  0xa8, 0xe2, 0x48, 0x12, 0x88, 0x22, 0x23, 0x18, 0x9a, 0x97, 0x36, 0x1a,
  0x99, 0x3f, 0x25, 0xf3, 0x39, 0x1b, 0xd3, 0xaa, 0xb4, 0xda, 0x98, 0x52,
  0x22, 0x72, 0x0d, 0x25, 0x6e, 0x48, 0x40, 0x44, 0x14, 0xae, 0x28, 0xca,
  0x6a, 0x8e, 0xf3, 0xae, 0xb0, 0xb5, 0x38, 0x53, 0x82, 0x20, 0x76, 0x84,
  0x26, 0xd2, 0xa9, 0xd5, 0xc6, 0xb5, 0x27, 0x26, 0x8e, 0x30, 0xab, 0x54,
  0x2a, 0x0b, 0x11, 0xb9, 0x87, 0x47, 0xf6, 0x2b, 0x7b, 0xdd, 0x48, 0xf1,
  0x37, 0x6e, 0xda, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
  0xae, 0x42, 0x60, 0x82
};

CopasiUI3Window * CopasiUI3Window::create()
{
  CopasiUI3Window * pWindow = new CopasiUI3Window;

#ifdef COPASI_LICENSE_COM

  if (!pWindow->checkRegistration())
    pdelete(pWindow);

#endif // COPASI_LICENSE_COM

#ifdef COPASI_SBW_INTEGRATION
  pWindow->connectSBW();

  if (COptions::compareValue("SBWRegister", true))
    pWindow->registerSBW();

#endif // COPASI_SBW_INTEGRATION

  return pWindow;
}

/**
 *  Constructs a CopasiUI window which is a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 *  @param parent The widget which this window is a child of.
 *  @param name The object name is a text that can be used to identify
 *  this QObject. It's particularly useful in conjunction with the Qt Designer.
 *  You can find an object by name (and type) using child(), and more than one
 *  using queryList().
 *  @param flags Flags for this widget. Refer Qt::WidgetFlags of Qt documentation
 *  for more information about these flags.
 */
CopasiUI3Window::CopasiUI3Window():
    QMainWindow(),
    dataModel(NULL),
    listViews(NULL),
    mpBoxSelectFramework(NULL),
    newFlag(0),
    mpSliders(NULL),
    mpObjectBrowser(NULL),
    mSaveAsRequired(true),
    mpAutoSaveTimer(NULL),
    mSuspendAutoSave(false),
    mpMenuRecentFiles(NULL),
    mpMenuRecentSBMLFiles(NULL),
    mpMIRIAMResources(NULL)
#ifdef COPASI_SBW_INTEGRATION
    , mpSBWModule(NULL)
    , mAnalyzerModules()
    , mAnalyzerServices()
    , mpMenuSBW(NULL)
    , mIdMenuSBW(-1)
    , mIgnoreSBWShutdownEvent(false)
#endif // COPASI_SBW_INTEGRATION
{
  // set destructive close
  Qt::WindowFlags f = this->windowFlags();
  f |= Qt::WDestructiveClose;
  this->setWindowFlags(f);
  QImage img;
  img.loadFromData(image0_data, sizeof(image0_data), "PNG");
  QPixmap image0 = QPixmap::fromImage(img);
  setWindowIcon(image0);

  // Set the window caption/title
  FixedTitle = "COPASI ";
#ifdef COPASI_LICENSE_COM
  FixedTitle += "(commercial) ";
#endif // COPASI_LICENSE_COM
  FixedTitle += FROM_UTF8(CVersion::VERSION.getVersion());
  updateTitle();

  createActions();
  createToolBar(); // creates a tool bar
  createMenuBar();  // creates a menu bar

  setIconSize(QSize(18, 20));

  mpaSave->setEnabled(false);
  mpaSaveAs->setEnabled(false);
  mpaExportSBML->setEnabled(false);
  mpaExportODE->setEnabled(false);

  if (!dataModel)
    {
      // create the data model
      dataModel = new DataModelGUI();
    }

  listViews = new ListViews(this);

  connect(listViews->folders, SIGNAL(currentChanged(Q3ListViewItem*)), this, SLOT(listViewsFolderChanged(Q3ListViewItem*)));

  ListViews::setDataModel(dataModel);
  listViews->show();
  this->setCentralWidget(listViews);

  //create sliders window
  this->mpSliders = new SliderDialog(NULL);
  this->mpSliders->setParentWindow(this);
  C_INT32 id = ((FolderListItem*)listViews->folders->currentItem())->getFolder()->getId();
  this->mpSliders->setCurrentFolderId(id);
  this->mpSliders->resize(320, 350);

  //look at commandline
  if (!COptions::compareValue("ImportSBML", std::string("")))
    {
      // Import the SBML File
      std::string ImportSBML;
      COptions::getValue("ImportSBML", ImportSBML);
      slotImportSBML(FROM_UTF8(ImportSBML));
    }
  else if (COptions::getNonOptions().size())
    {
      slotFileOpen(FROM_UTF8(COptions::getNonOptions()[0]));
    }
  else
    {
      newDoc();
    }

  listViews->switchToOtherWidget(0, "");

  resize(800, 600);
  show();

  checkPendingMessages();

  // Assure that the changed flag is still false;
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  (*CCopasiRootContainer::getDatamodelList())[0]->changed(false);

  mpAutoSaveTimer = new QTimer(this);
  mpAutoSaveTimer->start(AutoSaveInterval); // every 10 minutes
  connect(mpAutoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
  // ListViews::notify(ListViews::FUNCTION, ListViews::ADD, "");
}

CopasiUI3Window::~CopasiUI3Window()
{
#ifdef COPASI_SBW_INTEGRATION
  pdelete(mpSBWModule);
#endif // COPASI_SBW_INTEGRATION

  pdelete(listViews);
  pdelete(dataModel);
}

void CopasiUI3Window::createActions()
{
  //TODO: use the QKeySequence standard shortcuts
  //TODO: add tool tips, status tips etc.

  mpaNew = new QAction(QPixmap(filenew), "&New", Qt::CTRL + Qt::Key_N, this, "new");
  connect(mpaNew, SIGNAL(activated()), this, SLOT(newDoc()));

  mpaOpen = new QAction(QPixmap(fileopen), "&Open...", Qt::CTRL + Qt::Key_O, this, "open");
  connect(mpaOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));

  mpaOpenCopasiFiles = new QAction(QPixmap(fileopen), "COP&ASI Files...", Qt::CTRL + Qt::Key_A, this, "copasifiles");
  connect(mpaOpenCopasiFiles, SIGNAL(activated()), this, SLOT(slotFileExamplesCopasiFiles()));

  mpaOpenSBMLFiles = new QAction(QPixmap(fileopen), "S&BML Files...", Qt::CTRL + Qt::Key_B, this, "sbmlfiles");
  connect(mpaOpenSBMLFiles, SIGNAL(activated()), this, SLOT(slotFileExamplesSBMLFiles()));

  mpaSave = new QAction(QPixmap(filesave), "&Save", Qt::CTRL + Qt::Key_S, this, "save");
  connect(mpaSave, SIGNAL(activated()), this, SLOT(slotFileSave()));

  mpaSaveAs = new QAction(QPixmap(filesave), "Save &As...", Qt::SHIFT + Qt::CTRL + Qt::Key_S, this, "saveas");
  connect(mpaSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));

  mpaImportSBML = new QAction(QPixmap(fileopen), "&Import SBML...", Qt::CTRL + Qt::Key_I, this, "importsbml");
  connect(mpaImportSBML, SIGNAL(activated()), this, SLOT(slotImportSBML()));

  mpaExportSBML = new QAction(QPixmap(filesave), "&Export SBML...", Qt::CTRL + Qt::Key_E, this, "exportsbml");
  connect(mpaExportSBML, SIGNAL(activated()), this, SLOT(slotExportSBML()));

  mpaExportODE = new QAction(QPixmap(filesave), "Export ODEs...", Qt::CTRL + Qt::Key_M, this, "exportode");
  connect(mpaExportODE, SIGNAL(activated()), this, SLOT(slotExportMathModel()));

  mpaQuit = new QAction("&Quit", Qt::CTRL + Qt::Key_Q, this, "quitcopasi");
  connect(mpaQuit, SIGNAL(activated()), this, SLOT(slotQuit()));

  mpaSliders = new QAction(QPixmap(toggleSliderDialog), "Show sliders", 0, this, "showsliders");
  mpaSliders->setToggleAction(true);
  connect(mpaSliders, SIGNAL(toggled(bool)), this, SLOT(slotShowSliders(bool)));

  mpaObjectBrowser = new QAction("Object &Browser", 0, this, "objectbrowser");
  mpaObjectBrowser->setToggleAction(true);
  connect(mpaObjectBrowser, SIGNAL(toggled(bool)), this, SLOT(slotShowObjectBrowserDialog(bool)));

  mpaCheckModel = new QAction(QPixmap(checkModel_xpm), "Check model", 0, this, "checkmodel");
  connect(mpaCheckModel, SIGNAL(activated()), this, SLOT(slotCheckModel()));

  mpaUpdateMIRIAM = new QAction(QPixmap(MIRIAM_xpm), "Update MIRIAM", 0, this, "updatemiriam");
  connect(mpaUpdateMIRIAM, SIGNAL(activated()), this, SLOT(slotUpdateMIRIAM()));

  mpaApplyInitialState = new QAction(QPixmap(istos_xpm), "Apply initial state", 0, this, "applyinitialstate");
  connect(mpaApplyInitialState, SIGNAL(activated()), this, SLOT(slotApplyInitialState()));

  mpaUpdateInitialState = new QAction(QPixmap(stois_xpm), "Update initial state from current state", 0, this, "updateinitialstate");
  connect(mpaUpdateInitialState, SIGNAL(activated()), this, SLOT(slotUpdateInitialState()));

  mpaCapture = new QAction(QPixmap(photo), "Capture the main window", 0, this, "capture");
  connect(mpaCapture, SIGNAL(activated()), this, SLOT(slotCapture()));

  mpaExpandModel = new QAction("Create array of compartments (debug version)", 0, this, "expandmodel");
  connect(mpaExpandModel, SIGNAL(activated()), this, SLOT(slotExpandModel()));

  //     QAction* mpaObjectBrowser;

#ifdef WITH_MERGEMODEL
  mpaAddModel = new QAction(QPixmap(fileadd), "&Add ...", Qt::SHIFT + Qt::CTRL + Qt::Key_A, this, "addmodel");
  connect(mpaAddModel, SIGNAL(activated()), this, SLOT(slotAddFileOpen()));

  mpaMergeModels = new QAction("&Merge ...", Qt::SHIFT + Qt::CTRL + Qt::Key_M, this, "mergemodel");
  connect(mpaMergeModels, SIGNAL(activated()), this, SLOT(slotMergeModels()));
#endif
}

void CopasiUI3Window::createToolBar()
{
  QToolBar * tb = addToolBar("MainToolBar");

  tb->addAction(mpaNew);
  tb->addAction(mpaOpen);
  tb->addAction(mpaSave);
  tb->addAction(mpaCapture);
  tb->addAction(mpaSliders);
  tb->addAction(mpaCheckModel);
  tb->addAction(mpaApplyInitialState);
  tb->addAction(mpaUpdateInitialState);
  tb->addAction(mpaUpdateMIRIAM);

#ifdef WITH_MERGEMODEL
  tb->addAction(mpaAddModel);
  //tb->addAction(mpaMergeModels);
#endif

  tb->addSeparator();

  mpBoxSelectFramework = new QComboBox(tb);
  mpBoxSelectFramework->insertItem("Concentrations");
  mpBoxSelectFramework->insertItem("Particle Numbers");
  tb->addWidget(mpBoxSelectFramework);

  //tbMain->setCloseMode(Q3DockWindow::Never);

  connect(mpBoxSelectFramework, SIGNAL(activated(int)), this, SLOT(slotFrameworkChanged(int)));
}

void CopasiUI3Window::createMenuBar()
{

  QMenu * pFileMenu = menuBar()->addMenu("&File");

  pFileMenu->addAction(mpaNew);
  pFileMenu->addAction(mpaOpen);

  mpMenuExamples = pFileMenu->addMenu("Examples");
  mpMenuExamples->addAction(mpaOpenCopasiFiles);
  mpMenuExamples->addAction(mpaOpenSBMLFiles);

  pFileMenu->addAction(mpaSave);
  pFileMenu->addAction(mpaSaveAs);

  pFileMenu->addSeparator();

  pFileMenu->addAction(mpaImportSBML);
  pFileMenu->addAction(mpaExportSBML);
  pFileMenu->addAction(mpaExportODE);

#ifdef WITH_MERGEMODEL
  pFileMenu->addAction(mpaAddModel);
  //pFileMenu->addAction(mpaMergeModels);
#endif

  pFileMenu->addSeparator();

  mpMenuRecentFiles = pFileMenu->addMenu("Recent Files");
  refreshRecentFileMenu();

  mpMenuRecentSBMLFiles = pFileMenu->addMenu("Recent SBML Files");
  refreshRecentSBMLFileMenu();

  pFileMenu->addSeparator();

  pFileMenu->addAction(mpaQuit);

  //****** tools menu **************

  mpTools = menuBar()->addMenu("&Tools");

  mpTools->addAction(mpaApplyInitialState);
  mpTools->addAction(mpaUpdateInitialState);
  mpTools->addAction(mpaSliders);
  mpTools->addAction(mpaCapture);
#ifdef WITH_MERGEMODEL
  mpTools->addAction(mpaMergeModels);
#endif

  mpTools->addSeparator();
#ifdef COPASI_DEBUG
  mpTools->addAction(mpaObjectBrowser);
  mpTools->addAction(mpaExpandModel);
  mpTools->addSeparator();
#endif // COPASI_DEBUG

  mpTools->addAction(mpaCheckModel);
  mpTools->insertItem("&Convert to irreversible", this, SLOT(slotConvertToIrreversible()));

#ifdef COPASI_SBW_INTEGRATION
  // create and populate SBW menu
{'fraction_non_alphanumeric': 0.15486344566999138, 'fraction_numerical': 0.11480010001944822, 'mean_word_length': 5.218728403593642, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 179, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '4306166', 'n_tokens_mistral': 18975, 'n_tokens_neox': 16253, 'n_words': 3388}