diff --git a/src/plugins/editing/MappingView/src/mappingviewplugin.cpp b/src/plugins/editing/MappingView/src/mappingviewplugin.cpp index 884c1b5e8a..02126b0dea 100644 --- a/src/plugins/editing/MappingView/src/mappingviewplugin.cpp +++ b/src/plugins/editing/MappingView/src/mappingviewplugin.cpp @@ -24,6 +24,7 @@ along with this program. If not, see . #include "coreguiutils.h" #include "mappingviewplugin.h" #include "mappingviewwidget.h" +#include "filemanager.h" //============================================================================== @@ -294,6 +295,17 @@ QWidget * MappingViewPlugin::viewWidget(const QString &pFileName) { // Update and return our Mapping view widget using the given file + // Make sure that we are not dealing with a new file, but a CellML 1.0/1.1 + // file + + CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileVersion(pFileName); + + if ( Core::FileManager::instance()->isNew(pFileName) + || ( (cellmlVersion != CellMLSupport::CellmlFile::Version::Cellml_1_0) + && (cellmlVersion != CellMLSupport::CellmlFile::Version::Cellml_1_1))) { + return nullptr; + } + mFileName = pFileName; mViewWidget->update(pFileName); diff --git a/src/plugins/editing/MappingView/src/mappingviewwidget.cpp b/src/plugins/editing/MappingView/src/mappingviewwidget.cpp index 301dd61ebe..b01b93bdb2 100644 --- a/src/plugins/editing/MappingView/src/mappingviewwidget.cpp +++ b/src/plugins/editing/MappingView/src/mappingviewwidget.cpp @@ -119,7 +119,7 @@ void MappingViewWidget::update(const QString &pFileName) // Retrieve the requested CellML file mCellmlFile = CellMLSupport::CellmlFileManager::instance()->cellmlFile(pFileName); - + //TODO can be null populateCellmlModel(); } diff --git a/src/plugins/editing/MappingView/src/mappingviewwidget.cpp.autosave b/src/plugins/editing/MappingView/src/mappingviewwidget.cpp.autosave deleted file mode 100644 index ff01ba277e..0000000000 --- a/src/plugins/editing/MappingView/src/mappingviewwidget.cpp.autosave +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - -Copyright (C) The University of Auckland - -OpenCOR is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -OpenCOR is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -*******************************************************************************/ - -//============================================================================== -// Mapping view widget -//============================================================================== - -#include "corecliutils.h" -#include "filemanager.h" -#include "mappingviewwidget.h" - -#include "cellmlfilemanager.h" - -//============================================================================== - -#include "ui_mappingviewwidget.h" - -//============================================================================== - -#include -#include - -//============================================================================== - -namespace OpenCOR { -namespace MappingView { - -//============================================================================== - -MappingViewWidget::MappingViewWidget(QWidget *pParent) : - ViewWidget(pParent), - mGui(new Ui::MappingViewWidget) -{ - // Delete the layout that comes with ViewWidget - - delete layout(); - - // Set up the GUI - - mGui->setupUi(this); - -} - -//============================================================================== - -MappingViewWidget::~MappingViewWidget() -{ - // Delete the GUI - - delete mGui; -} - -//============================================================================== - -void MappingViewWidget::retranslateUi() -{ - // Retranslate our GUI - - mGui->retranslateUi(this); - - // Update ourself too since some widgets will have been reset following the - // retranslation (e.g. mGui->fileNameValue) - - update(mFileName); -} - -//============================================================================== - -QWidget * MappingViewWidget::widget(const QString &pFileName) -{ - Q_UNUSED(pFileName) - - // Return the requested (self) widget - - return this; -} - -//============================================================================== - -void MappingViewWidget::update(const QString &pFileName) -{ - // Keep track of the given file name - - mFileName = pFileName; - - // Initialise our GUI with some information about the given file - - mGui->fileNameValue->setText(pFileName); - - Core::FileManager *fileManagerInstance = Core::FileManager::instance(); - - mGui->lockedValue->setText(fileManagerInstance->isLocked(pFileName)?tr("Yes"):tr("No")); - - QString sha1Value = fileManagerInstance->sha1(pFileName); - - mGui->sha1Value->setText(sha1Value.isEmpty()?"???":sha1Value); - mGui->sizeValue->setText(Core::sizeAsString(quint64(QFile(pFileName).size()))); - - mListViewModel= new QStringListModel(this); //TODO defining only when charging the plugin ? - - mGui->variablesList->setModel(mListViewModel); //TODO set only when charging the plugin ? - - // Retrieve the requested CellML file - - mCellmlFile = CellMLSupport::CellmlFileManager::instance()->cellmlFile(pFileName); - //TODO can be null - populateCellmlModel(); -} - -void MappingViewWidget::populateCellmlModel() -{ - QStringList list; - - // Make sure that we have a model before actually populating ourselves - - iface::cellml_api::Model *cellmlModel = mCellmlFile->model(); - - if (cellmlModel == nullptr) { - return; - } - - // Retrieve the model's components - - ObjRef components = cellmlModel->localComponents(); - - if (components->length() != 0) { - - // Retrieve the model's components themselves - - ObjRef componentsIter = components->iterateComponents(); - - for (ObjRef component = componentsIter->nextComponent(); - component != nullptr; component = componentsIter->nextComponent()) { - - // Retrieve the model's component's variables - - ObjRef componentVariables = component->variables(); - - if (componentVariables->length() != 0) { - // Retrieve the model's component's variables themselves - - ObjRef componentVariablesIter = componentVariables->iterateVariables(); - - for (ObjRef componentVariable = componentVariablesIter->nextVariable(); - componentVariable != nullptr; componentVariable = componentVariablesIter->nextVariable()) { - - list.append(QString::fromStdWString(componentVariable->name())); - } - } - } - } - - mListViewModel->setStringList(list); -} - - -//============================================================================== - -} // namespace MappingView -} // namespace OpenCOR - -//============================================================================== -// End of file -//==============================================================================