Skip to content

Commit

Permalink
MIRIAM resources are now owned by the root container.
Browse files Browse the repository at this point in the history
  • Loading branch information
shoops committed Feb 10, 2025
1 parent 82b9b65 commit 389e773
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 72 deletions.
4 changes: 2 additions & 2 deletions copasi/MIRIAM/CMIRIAMResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ void CMIRIAMResources::isCitation(void * pData, void * /* pCallee */)
// static
bool CMIRIAMResources::isCitation(const std::string & uri)
{
size_t Index = CRootContainer::getConfiguration()->getRecentMIRIAMResources().getMIRIAMResourceIndex(uri);
size_t Index = CRootContainer::getMiriamResources().getMIRIAMResourceIndex(uri);

if (Index != C_INVALID_INDEX &&
CRootContainer::getConfiguration()->getRecentMIRIAMResources().getMIRIAMResource(Index).getMIRIAMCitation())
CRootContainer::getMiriamResources().getMIRIAMResource(Index).getMIRIAMCitation())
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions copasi/MIRIAMUI/CQMiriamWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the
// Copyright (C) 2019 - 2025 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.
Expand Down Expand Up @@ -505,7 +505,7 @@ void CQMiriamWidget::updateResourcesList()
{
// Build the list of known resources
assert(CRootContainer::getDatamodelList()->size() > 0);
const CMIRIAMResources *pResource = &CRootContainer::getConfiguration()->getRecentMIRIAMResources();
const CMIRIAMResources *pResource = &CRootContainer::getMiriamResources();
QMap< QString, QString > ResourceMap;
QMap< QString, QString > ReferenceMap;
size_t i, imax = pResource->getResourceList().size();
Expand Down
26 changes: 9 additions & 17 deletions copasi/UI/CQPreferenceDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 by Pedro Mendes, Rector and Visitors of the
// Copyright (C) 2019 - 2025 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.
Expand Down Expand Up @@ -36,7 +36,6 @@
#define COL_NAME 0
#define COL_VALUE 1


#include <QApplication>

/*
Expand Down Expand Up @@ -66,8 +65,6 @@ CQPreferenceDialog::~CQPreferenceDialog()
{
delete mpConfiguration;
mpConfiguration = NULL;
// restore pointer to miriam resources
CMIRIAMResourceObject::setMIRIAMResources(&CRootContainer::getConfiguration()->getRecentMIRIAMResources());
}
}

Expand All @@ -80,7 +77,6 @@ CQPreferenceDialog::~CQPreferenceDialog()
#include <QFile>
#include <QFormLayout>


void CQPreferenceDialog::slotPropertyChanged()
{
auto widget = dynamic_cast<QWidget*>(sender());
Expand All @@ -93,7 +89,7 @@ void CQPreferenceDialog::slotPropertyChanged()

if (auto edit = dynamic_cast<QLineEdit*>(widget))
{
parameter->setValue(edit->text().toStdString());
parameter->setValue(edit->text().toStdString());
}
else if (auto edit = dynamic_cast<QCheckBox*>(widget))
{
Expand All @@ -107,7 +103,7 @@ void CQPreferenceDialog::slotPropertyChanged()

void CQPreferenceDialog::initTabsFromSettings(QSettings& settings)
{
// the ini file will have groups for each tab, each tab should
// the ini file will have groups for each tab, each tab should
// have a form layout with the name of the setting as the key
// and the value as the value

Expand All @@ -125,7 +121,7 @@ void CQPreferenceDialog::initTabsFromSettings(QSettings& settings)
tab->setLayout(layout);
tabWidget->insertTab(0, tab, mainGroup);

// each group has child elements with keys:
// each group has child elements with keys:
// - name: the name of the setting
// - type: the type of the setting
// - parameter: the parameter of the COPASI setting to change
Expand All @@ -140,20 +136,20 @@ void CQPreferenceDialog::initTabsFromSettings(QSettings& settings)
auto type = settings.value("type").toString();
auto parameter = settings.value("parameter").toString();
auto value = settings.value("value");

auto param_path = parameter.split(".");
CCopasiParameter * pNode = mpConfiguration;
for (auto paramName : param_path)
if (pNode && dynamic_cast< CCopasiParameterGroup * >(pNode))
pNode = dynamic_cast< CCopasiParameterGroup * >(pNode)->getParameter(paramName.toStdString());

auto tooltip = settings.value("tooltip").toString();

if (type == "string")
{
auto edit = new QLineEdit(value.toString());
edit->setToolTip(tooltip);

if (pNode)
edit->setText(FROM_UTF8(pNode->getValue<std::string>()));
layout->addRow(name, edit);
Expand Down Expand Up @@ -183,7 +179,7 @@ void CQPreferenceDialog::initTabsFromSettings(QSettings& settings)

connect(edit, QOverload<int>::of(&QSpinBox::valueChanged), this, &CQPreferenceDialog::slotPropertyChanged);
mWidgetToParameter[edit] = pNode;
}
}
else
{
CQMessageBox::warning(this, "Error", "Unknown type: " + type);
Expand All @@ -210,7 +206,6 @@ void CQPreferenceDialog::init()
mpTreeView->setAdvanced(false);
mpTreeView->pushGroup(mpConfiguration);


// initialize other tabs from config file
auto copasiDir = COptions::getConfigDir();
auto preferenceConfigFile = copasiDir + "/preferences.ini";
Expand All @@ -228,11 +223,10 @@ void CQPreferenceDialog::init()
outFile.write(file.readAll());
outFile.close();
}
file.close();
file.close();
}
}


QSettings settings(preferenceConfigFile.c_str(), QSettings::IniFormat, this);
initTabsFromSettings(settings);
}
Expand Down Expand Up @@ -263,8 +257,6 @@ void CQPreferenceDialog::slotBtnCancel()

delete mpConfiguration;
mpConfiguration = NULL;
// restore pointer to miriam resources
CMIRIAMResourceObject::setMIRIAMResources(&CRootContainer::getConfiguration()->getRecentMIRIAMResources());
}

done(0);
Expand Down
5 changes: 1 addition & 4 deletions copasi/UI/copasiui3window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2664,8 +2664,6 @@ void CopasiUI3Window::slotUpdateMIRIAMFinished(bool success)
if (success)
{
mpDataModelGUI->saveConfiguration(true);
CMIRIAMResourceObject::setMIRIAMResources(
&CRootContainer::getConfiguration()->getRecentMIRIAMResources());
mpDataModelGUI->updateMIRIAMResourceContents();
this->checkPendingMessages();
}
Expand All @@ -2683,8 +2681,7 @@ void CopasiUI3Window::slotUpdateMIRIAM()

try
{
success = mpDataModelGUI->updateMIRIAM(
CRootContainer::getConfiguration()->getRecentMIRIAMResources());
success = mpDataModelGUI->updateMIRIAM(CRootContainer::getMiriamResources());
}
catch (...)
{
Expand Down
33 changes: 11 additions & 22 deletions copasi/commandline/CConfigurationFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
#include "CConfigurationFile.h"
#include "COptions.h"

#include "copasi/core/CRootContainer.h"
#include "copasi/CopasiDataModel/CDataModel.h"
#include "copasi/utilities/CVersion.h"
#include "copasi/utilities/utility.h"
#include "copasi/utilities/CDirEntry.h"
#include "copasi/MIRIAM/CConstants.h"

#include "copasi/xml/parser/CXMLParser.h"
#include "copasi/xml/CGroupXML.h"
Expand Down Expand Up @@ -118,7 +118,6 @@ CConfigurationFile::CConfigurationFile(const std::string & name,
, mpRecentFiles(NULL)
, mpRecentSBMLFiles(NULL)
, mpRecentSEDMLFiles(NULL)
, mRecentMIRIAMResources("MIRIAM Resources", pParent)
, mpApplicationFont(NULL)
, mpValidateUnits(NULL)
, mpDisplayIssueSeverity(NULL)
Expand Down Expand Up @@ -152,7 +151,6 @@ CConfigurationFile::CConfigurationFile(const CConfigurationFile & src,
, mpRecentFiles(NULL)
, mpRecentSBMLFiles(NULL)
, mpRecentSEDMLFiles(NULL)
, mRecentMIRIAMResources(src.mRecentMIRIAMResources, pParent)
, mpApplicationFont(NULL)
, mpValidateUnits(NULL)
, mpDisplayIssueSeverity(NULL)
Expand Down Expand Up @@ -207,13 +205,13 @@ bool CConfigurationFile::elevateChildren()

if (!mpCheckForUpdates) success = false;

// We need to make sure that the contained group "MIRIAM Resources" is converted to mRecentMIRIAMResources
// We need to make sure that the contained group "MIRIAM Resources" is converted to CRootContainer::getMiriamResources()
CCopasiParameterGroup *pMIRIAMResources = getGroup("MIRIAM Resources");

if (mRecentMIRIAMResources.getResourceList().size() == 0
if (CRootContainer::getMiriamResources().getResourceList().size() == 0
&& pMIRIAMResources != nullptr)
{
mRecentMIRIAMResources = *pMIRIAMResources;
CRootContainer::getMiriamResources() = *pMIRIAMResources;
removeParameter(pMIRIAMResources);
}

Expand Down Expand Up @@ -310,11 +308,12 @@ bool CConfigurationFile::save(bool saveMiriam)
COptions::getValue("ConfigFile", ConfigFile);

std::string miriamConfigFile = ConfigFile + std::string(".miriam");
saveMiriam |= (!CDirEntry::exist(miriamConfigFile) && mRecentMIRIAMResources.getResourceList().size() > 0);
saveMiriam |= (!CDirEntry::exist(miriamConfigFile)
&& CRootContainer::getMiriamResources().getResourceList().size() > 0);

if (saveMiriam)
{
CGroupXML(mRecentMIRIAMResources).CCopasiXMLInterface::save(miriamConfigFile, CDirEntry::dirName(ConfigFile));
CGroupXML(CRootContainer::getMiriamResources()).CCopasiXMLInterface::save(miriamConfigFile, CDirEntry::dirName(ConfigFile));
}

bool success = CGroupXML(*this).CCopasiXMLInterface::save(ConfigFile, CDirEntry::dirName(ConfigFile));
Expand All @@ -341,12 +340,12 @@ bool CConfigurationFile::load()
CCopasiParameterGroup MIRIAMResources("MIRIAM Resources");

if (CGroupXML(MIRIAMResources).CCopasiXMLInterface::load(configMIRIAMResourceFile, configMIRIAMResourceFile))
mRecentMIRIAMResources = MIRIAMResources;
CRootContainer::getMiriamResources() = MIRIAMResources;
else
return false;
}

if (mRecentMIRIAMResources.getResourceList().size() == 0)
if (CRootContainer::getMiriamResources().getResourceList().size() == 0)
{
// We load the default MIRIAM resources, which are part of the COPASI installation.
std::string MIRIAMResourceFile;
Expand All @@ -363,11 +362,11 @@ bool CConfigurationFile::load()
if (pGroup == nullptr)
return false;

mRecentMIRIAMResources = *pGroup;
CRootContainer::getMiriamResources() = *pGroup;

if (!haveConfigMiriam)
{
CGroupXML(mRecentMIRIAMResources).CCopasiXMLInterface::save(configMIRIAMResourceFile, configMIRIAMResourceFile);
CGroupXML(CRootContainer::getMiriamResources()).CCopasiXMLInterface::save(configMIRIAMResourceFile, configMIRIAMResourceFile);
}
}
else
Expand Down Expand Up @@ -408,16 +407,6 @@ CRecentFiles & CConfigurationFile::getRecentSEDMLFiles()
return *mpRecentSEDMLFiles;
}

CMIRIAMResources & CConfigurationFile::getRecentMIRIAMResources()
{
return mRecentMIRIAMResources;
}

void CConfigurationFile::setRecentMIRIAMResources(const CMIRIAMResources & miriamResources)
{
mRecentMIRIAMResources = miriamResources;
}

const std::string CConfigurationFile::getApplicationFont() const
{
return *mpApplicationFont;
Expand Down
13 changes: 0 additions & 13 deletions copasi/commandline/CConfigurationFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,6 @@ class CConfigurationFile : public CCopasiParameterGroup
*/
CRecentFiles & getRecentSEDMLFiles();

/**
* Retrieve the list of recent MIRIAM Resources
* @return CMIRIAMResources & recentMIRIAMResources
*/
CMIRIAMResources & getRecentMIRIAMResources();

void setRecentMIRIAMResources(const CMIRIAMResources & miriamResources);

/**
* Retrieve the application font.
* @return const std::string & applicationFont
Expand Down Expand Up @@ -494,11 +486,6 @@ class CConfigurationFile : public CCopasiParameterGroup
*/
CRecentFiles * mpRecentSEDMLFiles;

/**
* A pointer to the list of MIRIAM Resources
*/
CMIRIAMResources mRecentMIRIAMResources;

/**
* A pointer to the application font
*/
Expand Down
35 changes: 23 additions & 12 deletions copasi/core/CRootContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ extern CRootContainer * pRootContainer;
* The only way to create a root container is through the static init
* method.
*/
CRootContainer::CRootContainer(const bool & withGUI):
CDataContainer("Root", NULL, "CN", CDataObject::Root),
mKeyFactory(),
mpUnknownResource(NULL),
mpFunctionList(NULL),
mpUnitDefinitionList(NULL),
mpConfiguration(NULL),
mpDataModelList(NULL),
mWithGUI(withGUI),
mpUndefined(NULL)
CRootContainer::CRootContainer(const bool & withGUI)
: CDataContainer("Root", NULL, "CN", CDataObject::Root)
, mKeyFactory()
, mpUnknownResource(NULL)
, mpMIRIAMResources(NULL)
, mpFunctionList(NULL)
, mpUnitDefinitionList(NULL)
, mpConfiguration(NULL)
, mpDataModelList(NULL)
, mWithGUI(withGUI)
, mpUndefined(NULL)
{}

// Destructor
Expand All @@ -69,6 +70,9 @@ CRootContainer::~CRootContainer()
// delete the unkown resource
pdelete(mpUnknownResource);

// delete the MIRIAM resources
pdelete(mpMIRIAMResources);

// delete the model list
pdelete(mpDataModelList);

Expand Down Expand Up @@ -126,6 +130,9 @@ void CRootContainer::initializeChildren()
mpUnknownResource->setMIRIAMDisplayName("-- select --");
mpUnknownResource->setMIRIAMURI("urn:miriam:unknown");

mpMIRIAMResources = new CMIRIAMResources;
CMIRIAMResourceObject::setMIRIAMResources(mpMIRIAMResources);

mpFunctionList = new CFunctionDB("FunctionDB", this);
mpFunctionList->load();

Expand All @@ -134,8 +141,6 @@ void CRootContainer::initializeChildren()
mpConfiguration = new CConfigurationFile;
mpConfiguration->load();

CMIRIAMResourceObject::setMIRIAMResources(&mpConfiguration->getRecentMIRIAMResources());

mpUndefined = new CFunction("undefined", this);
mpUndefined->setInfix("nan");
mpUndefined->compile();
Expand Down Expand Up @@ -253,6 +258,12 @@ const CMIRIAMResource & CRootContainer::getUnknownMiriamResource()
return *pRootContainer->mpUnknownResource;
}

// static
CMIRIAMResources & CRootContainer::getMiriamResources()
{
return *pRootContainer->mpMIRIAMResources;
}

// static
bool CRootContainer::removeDatamodel(const CDataModel * pDatamodel)
{
Expand Down
Loading

0 comments on commit 389e773

Please # to comment.