From 5f48e893ab6cee1f6350e8ccee9b721aba82b4e5 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Mon, 18 Feb 2019 15:25:46 +0100 Subject: [PATCH] Added plugins interfaces The `InformationInterface` reads the plugin information like name and icon. The `ModelInterface` provides the active model information to the plugin. --- .../Interfaces/InformationInterface.h | 46 +++++++++++++ OMEdit/OMEditGUI/Interfaces/Model.cpp | 61 ++++++++++++++++ OMEdit/OMEditGUI/Interfaces/Model.h | 69 +++++++++++++++++++ OMEdit/OMEditGUI/Interfaces/ModelInterface.h | 47 +++++++++++++ OMEdit/OMEditGUI/MainWindow.cpp | 43 ++++++++++++ OMEdit/OMEditGUI/MainWindow.h | 2 + OMEdit/OMEditGUI/OMEditGUI.pro | 8 ++- 7 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 OMEdit/OMEditGUI/Interfaces/InformationInterface.h create mode 100644 OMEdit/OMEditGUI/Interfaces/Model.cpp create mode 100644 OMEdit/OMEditGUI/Interfaces/Model.h create mode 100644 OMEdit/OMEditGUI/Interfaces/ModelInterface.h diff --git a/OMEdit/OMEditGUI/Interfaces/InformationInterface.h b/OMEdit/OMEditGUI/Interfaces/InformationInterface.h new file mode 100644 index 000000000..9fb74e24e --- /dev/null +++ b/OMEdit/OMEditGUI/Interfaces/InformationInterface.h @@ -0,0 +1,46 @@ +/* + * This file is part of OpenModelica. + * + * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), + * c/o Linköpings universitet, Department of Computer and Information Science, + * SE-58183 Linköping, Sweden. + * + * All rights reserved. + * + * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE + * OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE. + * + * The OpenModelica software and the Open Source Modelica + * Consortium (OSMC) Public License (OSMC-PL) are obtained + * from OSMC, either from the above address, + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or + * http://www.openmodelica.org, and in the OpenModelica distribution. + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. + * + * This program is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. + * + * See the full OSMC Public License conditions for more details. + * + */ +/* + * @author Adeel Asghar + */ + +#ifndef INFORMATIONINTERFACE_H +#define INFORMATIONINTERFACE_H + +class InformationInterface +{ +public: + virtual QString name() = 0; + virtual QIcon icon() = 0; +}; + +Q_DECLARE_INTERFACE(InformationInterface, "org.openmodelica.OMEdit.InformationInterface") + +#endif // INFORMATIONINTERFACE_H diff --git a/OMEdit/OMEditGUI/Interfaces/Model.cpp b/OMEdit/OMEditGUI/Interfaces/Model.cpp new file mode 100644 index 000000000..89fa72d07 --- /dev/null +++ b/OMEdit/OMEditGUI/Interfaces/Model.cpp @@ -0,0 +1,61 @@ +/* + * This file is part of OpenModelica. + * + * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), + * c/o Linköpings universitet, Department of Computer and Information Science, + * SE-58183 Linköping, Sweden. + * + * All rights reserved. + * + * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE + * OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE. + * + * The OpenModelica software and the Open Source Modelica + * Consortium (OSMC) Public License (OSMC-PL) are obtained + * from OSMC, either from the above address, + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or + * http://www.openmodelica.org, and in the OpenModelica distribution. + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. + * + * This program is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. + * + * See the full OSMC Public License conditions for more details. + * + */ +/* + * @author Adeel Asghar + */ + +#include "Model.h" +#include "Modeling/ModelWidgetContainer.h" + +Model::Model(ModelWidget *pModelWidget) +{ + mModelName = pModelWidget->getLibraryTreeItem()->getNameStructure(); + mFilePath = pModelWidget->getLibraryTreeItem()->getFileName(); + + foreach (Component *pComponent, pModelWidget->getDiagramGraphicsView()->getComponentsList()) { + ComponentInformation componentInformation; + componentInformation.mClassName = pComponent->getComponentInfo()->getClassName(); + componentInformation.mName = pComponent->getComponentInfo()->getName(); + componentInformation.mComment = pComponent->getComponentInfo()->getComment(); + componentInformation.mIsProtected = pComponent->getComponentInfo()->getProtected(); + componentInformation.mIsFinal = pComponent->getComponentInfo()->getFinal(); + componentInformation.mIsFlow = pComponent->getComponentInfo()->getFlow(); + componentInformation.mIsStream = pComponent->getComponentInfo()->getStream(); + componentInformation.mIsReplaceable = pComponent->getComponentInfo()->getReplaceable(); + componentInformation.mVariability = pComponent->getComponentInfo()->getVariablity(); + componentInformation.mIsInner = pComponent->getComponentInfo()->getInner(); + componentInformation.mIsOuter = pComponent->getComponentInfo()->getOuter(); + componentInformation.mCasuality = pComponent->getComponentInfo()->getCausality(); + componentInformation.mArrayIndex = pComponent->getComponentInfo()->getArrayIndex(); + componentInformation.mParameterValue = pComponent->getComponentInfo()->getParameterValue(MainWindow::instance()->getOMCProxy(), mModelName); + + mComponents.append(componentInformation); + } +} diff --git a/OMEdit/OMEditGUI/Interfaces/Model.h b/OMEdit/OMEditGUI/Interfaces/Model.h new file mode 100644 index 000000000..1c2e42ce7 --- /dev/null +++ b/OMEdit/OMEditGUI/Interfaces/Model.h @@ -0,0 +1,69 @@ +/* + * This file is part of OpenModelica. + * + * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), + * c/o Linköpings universitet, Department of Computer and Information Science, + * SE-58183 Linköping, Sweden. + * + * All rights reserved. + * + * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE + * OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE. + * + * The OpenModelica software and the Open Source Modelica + * Consortium (OSMC) Public License (OSMC-PL) are obtained + * from OSMC, either from the above address, + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or + * http://www.openmodelica.org, and in the OpenModelica distribution. + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. + * + * This program is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. + * + * See the full OSMC Public License conditions for more details. + * + */ +/* + * @author Adeel Asghar + */ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include + +class ModelWidget; + +typedef struct { + QString mClassName; + QString mName; + QString mComment; + bool mIsProtected; + bool mIsFinal; + bool mIsFlow; + bool mIsStream; + bool mIsReplaceable; + QString mVariability; + bool mIsInner; + bool mIsOuter; + QString mCasuality; + QString mArrayIndex; + QString mParameterValue; +} ComponentInformation; + +class Model +{ +public: + Model(ModelWidget *pModelWidget); + + QString mModelName; + QString mFilePath; + QList mComponents; +}; + +#endif // MODEL_H diff --git a/OMEdit/OMEditGUI/Interfaces/ModelInterface.h b/OMEdit/OMEditGUI/Interfaces/ModelInterface.h new file mode 100644 index 000000000..7867a654b --- /dev/null +++ b/OMEdit/OMEditGUI/Interfaces/ModelInterface.h @@ -0,0 +1,47 @@ +/* + * This file is part of OpenModelica. + * + * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), + * c/o Linköpings universitet, Department of Computer and Information Science, + * SE-58183 Linköping, Sweden. + * + * All rights reserved. + * + * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE + * OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE. + * + * The OpenModelica software and the Open Source Modelica + * Consortium (OSMC) Public License (OSMC-PL) are obtained + * from OSMC, either from the above address, + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or + * http://www.openmodelica.org, and in the OpenModelica distribution. + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. + * + * This program is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. + * + * See the full OSMC Public License conditions for more details. + * + */ +/* + * @author Adeel Asghar + */ + +#ifndef MODELINTERFACE_H +#define MODELINTERFACE_H + +#include "Model.h" + +class ModelInterface +{ +public: + virtual void analyzeModel(const Model &model) = 0; +}; + +Q_DECLARE_INTERFACE(ModelInterface, "org.openmodelica.OMEdit.ModelInterface") + +#endif // MODELINTERFACE_H diff --git a/OMEdit/OMEditGUI/MainWindow.cpp b/OMEdit/OMEditGUI/MainWindow.cpp index fc8c3f099..4a240d94b 100644 --- a/OMEdit/OMEditGUI/MainWindow.cpp +++ b/OMEdit/OMEditGUI/MainWindow.cpp @@ -73,6 +73,9 @@ #include "Traceability/TraceabilityInformationURI.h" #include "Traceability/TraceabilityGraphViewWidget.h" #include "Plotting/DiagramWindow.h" +#include "Interfaces/InformationInterface.h" +#include "Interfaces/ModelInterface.h" +#include "Interfaces/Model.h" #include "omc_config.h" #include @@ -2518,6 +2521,24 @@ void MainWindow::openConfigurationOptions() OptionsDialog::instance()->show(); } +/*! + * \brief MainWindow::runOMSensPlugin + * Slots activated when OMSens plugin action is triggered.\n + * Runs OMSens plugin. + */ +void MainWindow::runOMSensPlugin() +{ + ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget(); + if (pModelWidget) { + QAction *pAction = qobject_cast(sender()); + ModelInterface *pModelInterface = qobject_cast(pAction->parent()); + pModelInterface->analyzeModel(Model(pModelWidget)); + } else { + QMessageBox::information(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::information), + tr("Please open a model before starting the OMSens plugin."), Helper::ok); + } +} + /*! * \brief MainWindow::openUsersGuide * Slot activated when mpUsersGuideAction triggered signal is raised.\n @@ -3867,6 +3888,28 @@ void MainWindow::createMenus() pToolsMenu->addAction(mpOpenTerminalAction); pToolsMenu->addSeparator(); pToolsMenu->addAction(mpOptionsAction); + // Plugins View Menu + mpPluginsMenu = new QMenu(menuBar()); + mpPluginsMenu->setObjectName("PluginsMenu"); + mpPluginsMenu->setTitle(tr("Plugins")); + // load OMSens plugin +#ifdef Q_OS_WIN + QPluginLoader loader("../../../OMSensPlugin/bin/OMSensPlugin.dll"); +#elif defined(Q_OS_MAC) + QPluginLoader loader("../../../OMSensPlugin/bin/libOMSensPlugin.dylib"); +#else + QPluginLoader loader("../../../OMSensPlugin/bin/libOMSensPlugin.so"); +#endif + QObject *pOMSensPlugin = loader.instance(); + if (pOMSensPlugin) { + InformationInterface *pInformationInterface = qobject_cast(pOMSensPlugin); + // Add OMSens plugin action to plugins menu + QAction *pOMSensPluginAction = new QAction(pInformationInterface->icon(), pInformationInterface->name(), pOMSensPlugin); + connect(pOMSensPluginAction, SIGNAL(triggered()), SLOT(runOMSensPlugin())); + mpPluginsMenu->addAction(pOMSensPluginAction); + } + pToolsMenu->addSeparator(); + pToolsMenu->addMenu(mpPluginsMenu); // add Tools menu to menu bar menuBar()->addAction(pToolsMenu->menuAction()); // Help menu diff --git a/OMEdit/OMEditGUI/MainWindow.h b/OMEdit/OMEditGUI/MainWindow.h index a1552c303..d37b4b72b 100644 --- a/OMEdit/OMEditGUI/MainWindow.h +++ b/OMEdit/OMEditGUI/MainWindow.h @@ -429,6 +429,7 @@ class MainWindow : public QMainWindow // Toolbars QMenu *mpRecentFilesMenu; QMenu *mpLibrariesMenu; + QMenu *mpPluginsMenu; QToolBar *mpFileToolBar; QToolBar *mpEditToolBar; QToolBar *mpViewToolBar; @@ -509,6 +510,7 @@ public slots: void openWorkingDirectory(); void openTerminal(); void openConfigurationOptions(); + void runOMSensPlugin(); void openUsersGuide(); void openUsersGuidePdf(); void openUsersGuideOldPdf(); diff --git a/OMEdit/OMEditGUI/OMEditGUI.pro b/OMEdit/OMEditGUI/OMEditGUI.pro index e1ee7f510..a0466bace 100644 --- a/OMEdit/OMEditGUI/OMEditGUI.pro +++ b/OMEdit/OMEditGUI/OMEditGUI.pro @@ -205,7 +205,8 @@ SOURCES += main.cpp \ OMS/InstantiateDialog.cpp \ OMS/OMSSimulationDialog.cpp \ OMS/OMSSimulationOutputWidget.cpp \ - Animation/TimeManager.cpp + Animation/TimeManager.cpp \ + Interfaces/Model.cpp HEADERS += Util/Helper.h \ Util/Utilities.h \ @@ -296,7 +297,10 @@ HEADERS += Util/Helper.h \ OMS/OMSSimulationOptions.h \ OMS/OMSSimulationDialog.h \ OMS/OMSSimulationOutputWidget.h \ - Animation/TimeManager.h + Animation/TimeManager.h \ + Interfaces/InformationInterface.h \ + Interfaces/ModelInterface.h \ + Interfaces/Model.h CONFIG(osg) {