diff --git a/src/libs/dvcore/CMakeLists.txt b/src/libs/dvcore/CMakeLists.txt index 5240a872add2e4949b502792e41990fa069980ba..5d83afd2c4828ce46c33edbdc97f01c8143d4af5 100644 --- a/src/libs/dvcore/CMakeLists.txt +++ b/src/libs/dvcore/CMakeLists.txt @@ -50,7 +50,8 @@ target_sources(${LIB_NAME} PRIVATE dvxmlreader.h ) -target_include_directories(${LIB_NAME} PUBLIC .) +target_include_directories(${LIB_NAME} + PUBLIC . ${CMAKE_SOURCE_DIR}/src/libs) target_link_libraries(${LIB_NAME} shared diff --git a/src/libs/ivcore/CMakeLists.txt b/src/libs/ivcore/CMakeLists.txt index 4ebfd8e3735f6d4a4812cef5ebe29d764f1d87a2..efb32a8914833394217c5765893ccc155e8c0367 100644 --- a/src/libs/ivcore/CMakeLists.txt +++ b/src/libs/ivcore/CMakeLists.txt @@ -3,6 +3,8 @@ set(LIB_NAME ivcore) add_library(${LIB_NAME} STATIC) target_sources(${LIB_NAME} PRIVATE + abstractsystemchecks.cpp + abstractsystemchecks.h ivcommonprops.cpp ivcommonprops.h ivconnectionchain.cpp @@ -47,8 +49,7 @@ target_sources(${LIB_NAME} PRIVATE ) target_include_directories(${LIB_NAME} - PUBLIC . - ${CMAKE_SOURCE_DIR}/src/libs) + PUBLIC . ${CMAKE_SOURCE_DIR}/src/libs) target_link_libraries(${LIB_NAME} asn1editor diff --git a/src/libs/ivcore/abstractsystemchecks.cpp b/src/libs/ivcore/abstractsystemchecks.cpp new file mode 100644 index 0000000000000000000000000000000000000000..646e2163efad1c49e9883c792b759d758248ffe1 --- /dev/null +++ b/src/libs/ivcore/abstractsystemchecks.cpp @@ -0,0 +1,27 @@ +/* + Copyright (C) 2021 European Space Agency - <maxime.perrotin@esa.int> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#include "abstractsystemchecks.h" + +namespace ivm { + +AbstractSystemChecks::AbstractSystemChecks(QObject *parent) + : QObject(parent) +{ +} + +} // namespace ivm diff --git a/src/libs/ivcore/abstractsystemchecks.h b/src/libs/ivcore/abstractsystemchecks.h new file mode 100644 index 0000000000000000000000000000000000000000..7d9fd15f557fa39908a419c20e96e5f4e224ba59 --- /dev/null +++ b/src/libs/ivcore/abstractsystemchecks.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2021 European Space Agency - <maxime.perrotin@esa.int> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#pragma once + +#include <QObject> + +namespace ivm { +class IVFunction; + +/*! + Class for IV to check for information of the rest of the system + */ +class AbstractSystemChecks : public QObject +{ + Q_OBJECT +public: + explicit AbstractSystemChecks(QObject *parent = nullptr); + + virtual bool isImplementationUsed(ivm::IVFunction *fn, const QString &name) const = 0; + +Q_SIGNALS: +}; + +} // namespace ivm diff --git a/src/libs/libiveditor/interfacedocument.cpp b/src/libs/libiveditor/interfacedocument.cpp index c14d7a19458bb0bce0174cbefea2ab3d31b12dcf..c30d8c78372838133db89a01f1d190cb5f4fbb87 100644 --- a/src/libs/libiveditor/interfacedocument.cpp +++ b/src/libs/libiveditor/interfacedocument.cpp @@ -37,6 +37,7 @@ #include "ivcomment.h" #include "ivconnection.h" #include "ivconnectiongroup.h" +#include "ivcore/abstractsystemchecks.h" #include "ivcreatortool.h" #include "ivexporter.h" #include "ivfunction.h" @@ -101,6 +102,7 @@ struct InterfaceDocument::InterfaceDocumentPrivate { IVCreatorTool *tool { nullptr }; Asn1Acn::Asn1SystemChecks *asnCheck { nullptr }; + ivm::AbstractSystemChecks *ivCheck { nullptr }; QString mscFileName; QString asnFileName; }; @@ -567,6 +569,11 @@ void InterfaceDocument::setAsn1Check(Asn1Acn::Asn1SystemChecks *check) &ive::InterfaceDocument::checkAllInterfacesForAsn1Compliance, Qt::QueuedConnection); } +void InterfaceDocument::setIvCheck(ivm::AbstractSystemChecks *checks) +{ + d->ivCheck = checks; +} + QString InterfaceDocument::supportedFileExtensions() const { return QStringLiteral("*.xml"); @@ -729,7 +736,7 @@ void InterfaceDocument::showPropertyEditor(const shared::Id &id) return; } - ive::IVPropertiesDialog dialog(d->dynPropConfig, obj, d->asnCheck, d->commandsStack, d->graphicsView); + ive::IVPropertiesDialog dialog(d->dynPropConfig, obj, d->ivCheck, d->asnCheck, d->commandsStack, d->graphicsView); dialog.init(); dialog.exec(); } diff --git a/src/libs/libiveditor/interfacedocument.h b/src/libs/libiveditor/interfacedocument.h index f096f54b6e2ad191ded23fc95f77da518c385345..bcd9a9004958b5fe7a77e30ae024c306e2d05035 100644 --- a/src/libs/libiveditor/interfacedocument.h +++ b/src/libs/libiveditor/interfacedocument.h @@ -41,6 +41,7 @@ class VEObject; } namespace ivm { +class AbstractSystemChecks; class IVObject; class IVInterface; class IVModel; @@ -113,6 +114,7 @@ public: IVItemModel *itemsModel() const; void setAsn1Check(Asn1Acn::Asn1SystemChecks *check); + void setIvCheck(ivm::AbstractSystemChecks *checks); QString supportedFileExtensions() const; diff --git a/src/libs/libiveditor/iveditorcore.cpp b/src/libs/libiveditor/iveditorcore.cpp index fe776c762adc438d99967686488c8a64a626ceab..43dcfd116d6941cb912f91cdc5904702d93f2be5 100644 --- a/src/libs/libiveditor/iveditorcore.cpp +++ b/src/libs/libiveditor/iveditorcore.cpp @@ -31,6 +31,7 @@ #include "interfacedocument.h" #include "itemeditor/common/ivutils.h" #include "ivconnection.h" +#include "ivcore/abstractsystemchecks.h" #include "ivcreatortool.h" #include "ivexporter.h" #include "ivfunction.h" @@ -439,6 +440,16 @@ QStringList IVEditorCore::ivConnectionNames() const return connectionNames; } +void IVEditorCore::setDvChecks(ivm::AbstractSystemChecks *checks) +{ + m_checks = checks; +} + +ivm::AbstractSystemChecks *IVEditorCore::dvChecks() const +{ + return m_checks; +} + /*! * \brief Return the list of image formats which the Qt is available to write. */ diff --git a/src/libs/libiveditor/iveditorcore.h b/src/libs/libiveditor/iveditorcore.h index b134c432bc8572b2154ab0a53f7b3ab22f0feab2..001a81b7b5152a3f0d12158540d9fe829df0deb5 100644 --- a/src/libs/libiveditor/iveditorcore.h +++ b/src/libs/libiveditor/iveditorcore.h @@ -21,10 +21,12 @@ #include "ivinterface.h" #include "ui/graphicsviewbase.h" +#include <QPointer> #include <QSharedPointer> #include <QVector> namespace ivm { +class AbstractSystemChecks; class IVConnection; class IVFunction; } @@ -81,6 +83,9 @@ public: QStringList ivFunctionsNames() const; QStringList ivConnectionNames() const; + void setDvChecks(ivm::AbstractSystemChecks *checks); + ivm::AbstractSystemChecks *dvChecks() const; + public Q_SLOTS: void onSaveRenderRequested(); @@ -105,6 +110,8 @@ private: QVector<ivm::IVConnection *> m_ivConnections; Qt::CaseSensitivity m_caseCheck = Qt::CaseInsensitive; + + QPointer<ivm::AbstractSystemChecks> m_checks; }; } diff --git a/src/libs/libiveditor/properties/ivpropertiesdialog.cpp b/src/libs/libiveditor/properties/ivpropertiesdialog.cpp index 27da84eaf26dafac7d7d654cf14a7168ae2540f4..43029e68748cd24e4947ee973e9cce9929101bff 100644 --- a/src/libs/libiveditor/properties/ivpropertiesdialog.cpp +++ b/src/libs/libiveditor/properties/ivpropertiesdialog.cpp @@ -28,6 +28,7 @@ #include "ivcomment.h" #include "ivconnectiongroup.h" #include "ivconnectiongroupmodel.h" +#include "ivcore/abstractsystemchecks.h" #include "ivinterface.h" #include "ivnamevalidator.h" #include "ivobject.h" @@ -49,8 +50,10 @@ namespace ive { IVPropertiesDialog::IVPropertiesDialog(ivm::IVPropertyTemplateConfig *dynPropConfig, ivm::IVObject *obj, - Asn1Acn::Asn1SystemChecks *asn1Checks, cmd::CommandsStack *commandsStack, QWidget *parent) + ivm::AbstractSystemChecks *checks, Asn1Acn::Asn1SystemChecks *asn1Checks, cmd::CommandsStack *commandsStack, + QWidget *parent) : shared::PropertiesDialog(dynPropConfig, obj, asn1Checks, commandsStack, parent) + , m_checks(checks) { } @@ -233,7 +236,7 @@ void IVPropertiesDialog::initLanguageView() if (!fn) { return; } - auto languagesWidget = new ive::LanguageSelect(fn, commandMacro(), this); + auto languagesWidget = new ive::LanguageSelect(fn, m_checks, commandMacro(), this); insertTab(languagesWidget, tr("Implementations")); } diff --git a/src/libs/libiveditor/properties/ivpropertiesdialog.h b/src/libs/libiveditor/properties/ivpropertiesdialog.h index 98aed78b41fd06e3c52556efc1808bfbbf4115b4..12b4f1827803e17f225ff6ec193de6d80ac87183 100644 --- a/src/libs/libiveditor/properties/ivpropertiesdialog.h +++ b/src/libs/libiveditor/properties/ivpropertiesdialog.h @@ -27,6 +27,7 @@ class Asn1SystemChecks; } namespace ivm { +class AbstractSystemChecks; class IVPropertyTemplateConfig; } @@ -41,7 +42,8 @@ class IVPropertiesDialog : public shared::PropertiesDialog public: explicit IVPropertiesDialog(ivm::IVPropertyTemplateConfig *dynPropConfig, ivm::IVObject *obj, - Asn1Acn::Asn1SystemChecks *asn1Checks, cmd::CommandsStack *commandsStack, QWidget *parent = nullptr); + ivm::AbstractSystemChecks *checks, Asn1Acn::Asn1SystemChecks *asn1Checks, cmd::CommandsStack *commandsStack, + QWidget *parent = nullptr); ~IVPropertiesDialog() override; void init() override; @@ -56,6 +58,8 @@ private: void initIfaceParams(); void initCommentView(); void initLanguageView(); + + QPointer<ivm::AbstractSystemChecks> m_checks; }; } // namespace ive diff --git a/src/libs/libiveditor/properties/languagemodel.cpp b/src/libs/libiveditor/properties/languagemodel.cpp index 137bef4bb51a61e91031f44b45e2c1c06d4a8c67..9209a59a726d9fe4c689a657b0de1b73727fcb8b 100644 --- a/src/libs/libiveditor/properties/languagemodel.cpp +++ b/src/libs/libiveditor/properties/languagemodel.cpp @@ -21,16 +21,19 @@ #include "commands/cmdfunctionlanguageinsert.h" #include "commands/cmdfunctionlanguageremove.h" #include "commands/cmdfunctionlanguageupdate.h" +#include "ivcore/abstractsystemchecks.h" #include "ivfunction.h" #include "ivmodel.h" #include <QDebug> +#include <QFont> #include <QMetaEnum> namespace ive { -LanguageModel::LanguageModel(cmd::CommandsStack::Macro *macro, QObject *parent) +LanguageModel::LanguageModel(ivm::AbstractSystemChecks *checks, cmd::CommandsStack::Macro *macro, QObject *parent) : QAbstractItemModel(parent) + , m_checks(checks) , m_cmdMacro(macro) { } @@ -109,6 +112,12 @@ QVariant LanguageModel::data(const QModelIndex &index, int role) const return m_function->defaultLanguage() == attribute.name() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked; } + if (role == Qt::FontRole && isImplementationUsed(index.row())) { + QFont font; + font.setItalic(true); + return QVariant::fromValue(font); + } + return QVariant(); } @@ -226,6 +235,16 @@ QModelIndex LanguageModel::defaultIndex() const return QModelIndex(); } +bool LanguageModel::isImplementationUsed(int row) const +{ + if (!m_checks || row < 0 || row >= m_function->languages().size()) { + return false; + } + + const QString name = m_function->languages().at(row).name(); + return m_checks->isImplementationUsed(m_function, name); +} + QString LanguageModel::uniqueName(const QString &name) { if (!m_function) { diff --git a/src/libs/libiveditor/properties/languagemodel.h b/src/libs/libiveditor/properties/languagemodel.h index a6d91ab45514b19ad57995e933b4c00741728094..eaf59fb450a8ad3f03f39520edd5a6639596aef5 100644 --- a/src/libs/libiveditor/properties/languagemodel.h +++ b/src/libs/libiveditor/properties/languagemodel.h @@ -23,6 +23,7 @@ #include <QPointer> namespace ivm { +class AbstractSystemChecks; class IVFunction; } @@ -41,7 +42,8 @@ public: }; Q_ENUM(Column) - explicit LanguageModel(cmd::CommandsStack::Macro *macro, QObject *parent = nullptr); + explicit LanguageModel( + ivm::AbstractSystemChecks *checks, cmd::CommandsStack::Macro *macro, QObject *parent = nullptr); void setFunction(ivm::IVFunction *fn); @@ -63,10 +65,13 @@ public: QModelIndex defaultIndex() const; + bool isImplementationUsed(int row) const; + private: QString uniqueName(const QString &name); QPointer<ivm::IVFunction> m_function; + QPointer<ivm::AbstractSystemChecks> m_checks; cmd::CommandsStack::Macro *m_cmdMacro { nullptr }; }; diff --git a/src/libs/libiveditor/properties/languageselect.cpp b/src/libs/libiveditor/properties/languageselect.cpp index 0c25d1e0f3ae10daf78a86b1190b6aea90704184..067dd78f86e8d0f16f129c796526fe1bb2500237 100644 --- a/src/libs/libiveditor/properties/languageselect.cpp +++ b/src/libs/libiveditor/properties/languageselect.cpp @@ -28,7 +28,8 @@ namespace ive { -LanguageSelect::LanguageSelect(ivm::IVFunction *fn, shared::cmd::CommandsStackBase::Macro *macro, QWidget *parent) +LanguageSelect::LanguageSelect(ivm::IVFunction *fn, ivm::AbstractSystemChecks *checks, + shared::cmd::CommandsStackBase::Macro *macro, QWidget *parent) : QWidget(parent) , ui(new Ui::LanguageSelect) { @@ -38,7 +39,7 @@ LanguageSelect::LanguageSelect(ivm::IVFunction *fn, shared::cmd::CommandsStackBa ui->tableView->setItemDelegateForColumn(LanguageModel::Column::Language, new shared::ComboBoxDelegate(fn->model()->availableFunctionLanguages(), ui->tableView)); - m_model = new LanguageModel(macro, this); + m_model = new LanguageModel(checks, macro, this); m_model->setFunction(fn); ui->tableView->setModel(m_model); ui->tableView->horizontalHeader()->resizeSection(0, 220); @@ -81,17 +82,17 @@ void LanguageSelect::deleteSelectedLanguage() void LanguageSelect::updateDeleteButton() { QModelIndexList selections = ui->tableView->selectionModel()->selectedRows(); + bool editable = true; if (selections.size() != 1) { - ui->deleteButton->setEnabled(false); - return; - } - - if (selections.at(0).row() == m_model->defaultIndex().row()) { - ui->deleteButton->setEnabled(false); - return; + editable = false; + } else { + int selectedRow = selections.at(0).row(); + if (selectedRow == m_model->defaultIndex().row() || m_model->isImplementationUsed(selectedRow)) { + editable = false; + } } - return ui->deleteButton->setEnabled(true); + ui->deleteButton->setEnabled(editable); } } // namespace ive diff --git a/src/libs/libiveditor/properties/languageselect.h b/src/libs/libiveditor/properties/languageselect.h index 27edd1883e00b5e901cd853652532970e9c46c57..9ee452d349e6ea67ab631c80400b4d1364dde3a3 100644 --- a/src/libs/libiveditor/properties/languageselect.h +++ b/src/libs/libiveditor/properties/languageselect.h @@ -22,6 +22,7 @@ #include <QWidget> namespace ivm { +class AbstractSystemChecks; class IVFunction; } @@ -40,7 +41,8 @@ class LanguageSelect : public QWidget Q_OBJECT public: - explicit LanguageSelect(ivm::IVFunction *fn, cmd::CommandsStack::Macro *macro, QWidget *parent = nullptr); + explicit LanguageSelect(ivm::IVFunction *fn, ivm::AbstractSystemChecks *checks, cmd::CommandsStack::Macro *macro, + QWidget *parent = nullptr); ~LanguageSelect(); private Q_SLOTS: diff --git a/src/libs/spacecreatorsystem/dvsystemchecks.cpp b/src/libs/spacecreatorsystem/dvsystemchecks.cpp index 8cad46c7bebb696dfc9139ce5d6fa09aae9cc64c..6bb3b4005cfb826779129110601ac9c2f21e364d 100644 --- a/src/libs/spacecreatorsystem/dvsystemchecks.cpp +++ b/src/libs/spacecreatorsystem/dvsystemchecks.cpp @@ -38,7 +38,7 @@ namespace scs { DvSystemChecks::DvSystemChecks(QObject *parent) - : QObject(parent) + : ivm::AbstractSystemChecks(parent) { } @@ -125,6 +125,24 @@ dvm::DVFunction *DvSystemChecks::correspondingFunction(ivm::IVFunction *ivFunc, return qobject_cast<dvm::DVFunction *>(dvf); } +bool DvSystemChecks::isImplementationUsed(ivm::IVFunction *ivFunc, const QString &name) const +{ + if (!m_storage) { + return false; + } + + for (DVEditorCorePtr dvCore : m_storage->allDVCores()) { + dvm::DVFunction *dvFunc = correspondingFunction(ivFunc, dvCore); + if (dvFunc) { + if (dvFunc->implementation() == name) { + return true; + } + } + } + + return false; +} + bool DvSystemChecks::checkFunctionIvValidity(const DVEditorCorePtr &dvCore) const { if (!m_storage && m_storage->ivQuery()) { diff --git a/src/libs/spacecreatorsystem/dvsystemchecks.h b/src/libs/spacecreatorsystem/dvsystemchecks.h index 86eb5858877f16e0d57da4b1126f422bba778c22..d56b4331e3cef5bfb6440d00f25a0e709d3cc811 100644 --- a/src/libs/spacecreatorsystem/dvsystemchecks.h +++ b/src/libs/spacecreatorsystem/dvsystemchecks.h @@ -18,6 +18,7 @@ #pragma once #include "dveditorcore.h" +#include "ivcore/abstractsystemchecks.h" #include <QObject> #include <QPointer> @@ -35,7 +36,7 @@ class IVInterface; namespace scs { class SpaceCreatorProject; -class DvSystemChecks : public QObject +class DvSystemChecks : public ivm::AbstractSystemChecks { Q_OBJECT public: @@ -56,6 +57,8 @@ public Q_SLOTS: ivm::IVFunction *correspondingFunction(dvm::DVFunction *dvFunc) const; dvm::DVFunction *correspondingFunction(ivm::IVFunction *ivFunc, const DVEditorCorePtr &dvCore) const; + bool isImplementationUsed(ivm::IVFunction *ivFunc, const QString &name) const override; + private: bool checkFunctionIvValidity(const DVEditorCorePtr &dvCore) const; bool checkUniqueFunctionBindings(const DVEditorCorePtr &dvCore) const; diff --git a/src/libs/spacecreatorsystem/ivsystemqueries.h b/src/libs/spacecreatorsystem/ivsystemqueries.h index 3082816700d0b3b49f5aceb1ac2a61d76b36f0f1..0b4c80e9ddfc269fb6c0fa0d05f9c46f27ccea2e 100644 --- a/src/libs/spacecreatorsystem/ivsystemqueries.h +++ b/src/libs/spacecreatorsystem/ivsystemqueries.h @@ -17,7 +17,7 @@ #pragma once -#include "abstractsystemchecks.h" +#include "dvcore/abstractsystemchecks.h" #include "iveditorcore.h" #include <QPointer> diff --git a/src/libs/spacecreatorsystem/spacecreatorproject.cpp b/src/libs/spacecreatorsystem/spacecreatorproject.cpp index fd4fe41ee967268f9d08a8c2cf004d1ebd5f318e..bdbd3353627a5872bbbf297f779d2f92fd0c1831 100644 --- a/src/libs/spacecreatorsystem/spacecreatorproject.cpp +++ b/src/libs/spacecreatorsystem/spacecreatorproject.cpp @@ -88,6 +88,7 @@ IVEditorCorePtr SpaceCreatorProject::ivData(const QString &fileName) const data->registerBasicActions(); data->document()->customActions(); // There some further actions are registered data->document()->setAsn1Check(m_asnChecks.get()); + data->document()->setIvCheck(m_dvChecks.get()); data->document()->load(fileName); if (data->document()->asn1FileName().isEmpty()) { @@ -360,6 +361,7 @@ void SpaceCreatorProject::setIvData(const QString &fileName, IVEditorCorePtr ivD m_ivStore[fileName] = ivData; connect(ivData.data(), &shared::EditorCore::editedExternally, this, &scs::SpaceCreatorProject::editedExternally); + ivData->setDvChecks(m_dvChecks.get()); Q_EMIT ivCoreAdded(ivData); }