diff --git a/OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.cpp b/OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.cpp index 8d5b6034a22..2431be66452 100644 --- a/OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.cpp +++ b/OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.cpp @@ -1,68 +1,104 @@ +/* + * This file is part of OpenModelica. + * + * Copyright (c) 1998-2014, 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. + * + */ + #include "FunctionArgumentDialog.h" #include "LibraryTreeWidget.h" #include "Component/Component.h" #include -#include #include FunctionArgumentDialog::FunctionArgumentDialog(LibraryTreeItem *pLibraryTreeItem, QWidget *parent): QDialog(parent), mpLibraryTreeItem(pLibraryTreeItem) { - setWindowTitle(pLibraryTreeItem->getNameStructure()); - QGridLayout *pGrid = new QGridLayout(); - - OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy(); - mComponents = pOMCProxy->getComponents(pLibraryTreeItem->getNameStructure()); - QString comment = pOMCProxy->getClassComment(pLibraryTreeItem->getNameStructure()); - + setWindowTitle(QString("%1 - %2 - %3").arg(Helper::applicationName, Helper::callFunction, pLibraryTreeItem->getNameStructure())); + setMinimumWidth(400); + + QVBoxLayout *pMainLayout = new QVBoxLayout; + pMainLayout->setAlignment(Qt::AlignTop); + // Function description + QGroupBox *pDescriptionGroupBox = new QGroupBox(Helper::description); + QVBoxLayout *pDescriptionLayout = new QVBoxLayout; + pDescriptionGroupBox->setAlignment(Qt::AlignTop); + pDescriptionLayout->addWidget(new Label(mpLibraryTreeItem->mClassInformation.comment)); + pDescriptionGroupBox->setLayout(pDescriptionLayout); + pMainLayout->addWidget(pDescriptionGroupBox); + + // Function arguments + QList components = mpLibraryTreeItem->getModelWidget()->getComponentsList(); + QGroupBox *pInputsGroupBox = new QGroupBox(tr("Inputs")); + QGridLayout *pInputsGridLayout = new QGridLayout; + pInputsGridLayout->setAlignment(Qt::AlignTop); int row = 0; - pGrid->addWidget(new QLabel(comment), row++, 0, 1, 4); - - for (int i = 0; i < mComponents.size(); ++i) { - ComponentInfo *pComponent = mComponents[i]; - if (!isInput(pComponent)) + for (int i = 0; i < components.size(); ++i) { + ComponentInfo *pComponent = components[i]; + if (!isInput(pComponent)) { continue; - - pGrid->addWidget(new QLabel(pComponent->getName()), row, 0); - - QLabel *typeLabel = new QLabel(pComponent->getClassName()); - QFont typeFont; - typeFont.setBold(true); - typeLabel->setFont(typeFont); - pGrid->addWidget(typeLabel, row, 1); - - QLabel *commentLabel = new QLabel(pComponent->getComment()); - QFont commentFont; - commentFont.setItalic(true); - commentLabel->setFont(commentFont); - pGrid->addWidget(commentLabel, row, 2); - + } + // input name + pInputsGridLayout->addWidget(new Label(pComponent->getName()), row, 0); + // input textbox QLineEdit *pEditor = new QLineEdit(); mEditors.append(pEditor); - pGrid->addWidget(pEditor, row, 3); + pInputsGridLayout->addWidget(pEditor, row, 1); + // input comment + pInputsGridLayout->addWidget(new Label(pComponent->getComment()), row, 2); + ++row; } + pInputsGroupBox->setLayout(pInputsGridLayout); + pMainLayout->addWidget(pInputsGroupBox); + QDialogButtonBox *pButtons = new QDialogButtonBox( QDialogButtonBox::StandardButton::Ok | QDialogButtonBox::StandardButton::Cancel); - pGrid->addWidget(pButtons, row, 0, 1, 4); + pMainLayout->addWidget(pButtons); connect(pButtons, SIGNAL(accepted()), SLOT(accept())); connect(pButtons, SIGNAL(rejected()), SLOT(reject())); - setLayout(pGrid); + setLayout(pMainLayout); } QString FunctionArgumentDialog::getFunctionCallCommand() { QString result = mpLibraryTreeItem->getNameStructure() + "("; int inputArgIndex = 0; - for (int i = 0; i < mComponents.size(); ++i) { - ComponentInfo *pComponent = mComponents[i]; - if (!isInput(pComponent)) + QList components = mpLibraryTreeItem->getModelWidget()->getComponentsList(); + for (int i = 0; i < components.size(); ++i) { + ComponentInfo *pComponent = components[i]; + if (!isInput(pComponent)) { continue; + } QString value = mEditors[inputArgIndex]->text(); diff --git a/OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.h b/OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.h index 40d3f169273..2fd498e0e07 100644 --- a/OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.h +++ b/OMEdit/OMEditGUI/Modeling/FunctionArgumentDialog.h @@ -1,3 +1,34 @@ +/* + * This file is part of OpenModelica. + * + * Copyright (c) 1998-2014, 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. + * + */ + #ifndef FUNCTIONPARAMETERDIALOG_H #define FUNCTIONPARAMETERDIALOG_H diff --git a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp index 11d5b0e93ef..e7743326519 100644 --- a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp +++ b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp @@ -748,18 +748,6 @@ void LibraryTreeItem::handleCoOrdinateSystemUpdated(GraphicsView *pGraphicsView) emit coOrdinateSystemUpdated(pGraphicsView); } -void LibraryTreeItem::callFunction() -{ - FunctionArgumentDialog dlg(this, MainWindow::instance()); - - if (dlg.exec() == QDialog::Accepted) { - QString cmd = dlg.getFunctionCallCommand(); - - MainWindow::instance()->getOMCProxy()->openOMCLoggerWidget(); - MainWindow::instance()->getOMCProxy()->sendCommand(cmd); - } -} - /*! * \class LibraryTreeProxyModel * \brief A sort filter proxy model for Libraries Browser. @@ -2688,10 +2676,10 @@ void LibraryTreeView::createActions() mpSimulateAction = new QAction(QIcon(":/Resources/icons/simulate.svg"), Helper::simulate, this); mpSimulateAction->setStatusTip(Helper::simulateTip); connect(mpSimulateAction, SIGNAL(triggered()), SLOT(simulate())); - // call Action - mpCallAction = new QAction(QIcon(":/Resources/icons/simulate.svg"), Helper::call, this); - mpCallAction->setStatusTip(Helper::callTip); - connect(mpCallAction, SIGNAL(triggered()), SLOT(call())); + // call function Action + mpCallFunctionAction = new QAction(QIcon(":/Resources/icons/simulate.svg"), Helper::callFunction, this); + mpCallFunctionAction->setStatusTip(Helper::callFunctionTip); + connect(mpCallFunctionAction, SIGNAL(triggered()), SLOT(callFunction())); // simulate with transformational debugger Action mpSimulateWithTransformationalDebuggerAction = new QAction(QIcon(":/Resources/icons/simulate-equation.svg"), Helper::simulateWithTransformationalDebugger, this); mpSimulateWithTransformationalDebuggerAction->setStatusTip(Helper::simulateWithTransformationalDebuggerTip); @@ -2918,7 +2906,7 @@ void LibraryTreeView::showContextMenu(QPoint point) menu.addAction(mpSimulationSetupAction); } if (pLibraryTreeItem->getRestriction() == StringHandler::ModelicaClasses::Function) { - menu.addAction(mpCallAction); + menu.addAction(mpCallFunctionAction); } /* If item is OpenModelica or part of it then don't show the duplicate menu item for it. */ if (!(StringHandler::getFirstWordBeforeDot(pLibraryTreeItem->getNameStructure()).compare("OpenModelica") == 0)) { @@ -3240,7 +3228,11 @@ void LibraryTreeView::checkAllModels() } } -void LibraryTreeView::call() +/*! + * \brief LibraryTreeView::callFunction + * Opens the call function dialog for the selected LibraryTreeItem + */ +void LibraryTreeView::callFunction() { LibraryTreeItem *pLibraryTreeItem = getSelectedLibraryTreeItem(); /* if Modelica text is changed manually by user then validate it before saving. */ @@ -3249,7 +3241,19 @@ void LibraryTreeView::call() return; } } - pLibraryTreeItem->callFunction(); + // Load the class if its not loaded so we can get the components + if (!pLibraryTreeItem->getModelWidget()) { + mpLibraryWidget->getLibraryTreeModel()->showModelWidget(pLibraryTreeItem, false); + } + pLibraryTreeItem->getModelWidget()->loadComponents(); + + FunctionArgumentDialog functionArgumentDialog(pLibraryTreeItem, MainWindow::instance()); + + if (functionArgumentDialog.exec() == QDialog::Accepted) { + QString cmd = functionArgumentDialog.getFunctionCallCommand(); + MainWindow::instance()->getOMCProxy()->openOMCLoggerWidget(); + MainWindow::instance()->getOMCProxy()->sendCommand(cmd); + } } /*! diff --git a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h index bfbde0c06b5..c6b4c252151 100644 --- a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h +++ b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h @@ -146,7 +146,6 @@ class LibraryTreeItem : public QObject LibraryTreeItem* parent() const {return mpParentLibraryTreeItem;} bool isTopLevel() const; bool isSimulationAllowed(); - void callFunction(); void emitLoaded(); void emitUnLoaded(); void emitShapeAdded(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView); @@ -331,7 +330,7 @@ class LibraryTreeView : public QTreeView QAction *mpCheckModelAction; QAction *mpCheckAllModelsAction; QAction *mpSimulateAction; - QAction *mpCallAction; + QAction *mpCallFunctionAction; QAction *mpSimulateWithTransformationalDebuggerAction; QAction *mpSimulateWithAlgorithmicDebuggerAction; #if !defined(WITHOUT_OSG) @@ -382,7 +381,7 @@ public slots: void instantiateModel(); void checkModel(); void checkAllModels(); - void call(); + void callFunction(); void simulate(); void simulateWithTransformationalDebugger(); void simulateWithAlgorithmicDebugger(); diff --git a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h index ff914cf8e6a..6e1d2239ca5 100644 --- a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h +++ b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h @@ -399,6 +399,7 @@ class ModelWidget : public QWidget void removeInheritedClass(LibraryTreeItem *pLibraryTreeItem) {mInheritedClassesList.removeOne(pLibraryTreeItem);} void clearInheritedClasses() {mInheritedClassesList.clear();} QList getInheritedClassesList() {return mInheritedClassesList;} + QList getComponentsList() {return mComponentsList;} QMap getExtendsModifiersMap(QString extendsClass); void fetchExtendsModifiers(QString extendsClass); void reDrawModelWidgetInheritedClasses(); diff --git a/OMEdit/OMEditGUI/OMEditGUI.pro b/OMEdit/OMEditGUI/OMEditGUI.pro index 9d7538c61f3..b125cda1fee 100644 --- a/OMEdit/OMEditGUI/OMEditGUI.pro +++ b/OMEdit/OMEditGUI/OMEditGUI.pro @@ -129,6 +129,7 @@ SOURCES += main.cpp \ Modeling/CoOrdinateSystem.cpp \ Modeling/ModelWidgetContainer.cpp \ Modeling/ModelicaClassDialog.cpp \ + Modeling/FunctionArgumentDialog.cpp \ Search/SearchWidget.cpp \ Options/OptionsDialog.cpp \ Editors/BaseEditor.cpp \ @@ -194,8 +195,7 @@ SOURCES += main.cpp \ OMS/OMSProxy.cpp \ Component/FMUProperties.cpp \ OMS/OMSSimulationDialog.cpp \ - OMS/OMSSimulationOutputWidget.cpp \ - Modeling/FunctionArgumentDialog.cpp + OMS/OMSSimulationOutputWidget.cpp HEADERS += Util/Helper.h \ Util/Utilities.h \ @@ -211,6 +211,7 @@ HEADERS += Util/Helper.h \ Modeling/CoOrdinateSystem.h \ Modeling/ModelWidgetContainer.h \ Modeling/ModelicaClassDialog.h \ + Modeling/FunctionArgumentDialog.h \ Search/SearchWidget.h \ Options/OptionsDialog.h \ Editors/BaseEditor.h \ @@ -278,8 +279,7 @@ HEADERS += Util/Helper.h \ Component/FMUProperties.h \ OMS/OMSSimulationOptions.h \ OMS/OMSSimulationDialog.h \ - OMS/OMSSimulationOutputWidget.h \ - Modeling/FunctionArgumentDialog.h + OMS/OMSSimulationOutputWidget.h CONFIG(osg) { diff --git a/OMEdit/OMEditGUI/Util/Helper.cpp b/OMEdit/OMEditGUI/Util/Helper.cpp index c09bcd76cfd..6b3f043513d 100644 --- a/OMEdit/OMEditGUI/Util/Helper.cpp +++ b/OMEdit/OMEditGUI/Util/Helper.cpp @@ -199,8 +199,8 @@ QString Helper::unloadOMSModelTip; QString Helper::refresh; QString Helper::simulate; QString Helper::simulateTip; -QString Helper::call; -QString Helper::callTip; +QString Helper::callFunction; +QString Helper::callFunctionTip; QString Helper::reSimulate; QString Helper::reSimulateTip; QString Helper::reSimulateSetup; @@ -468,8 +468,8 @@ void Helper::initHelperVariables() Helper::refresh = tr("Refresh"); Helper::simulate = tr("Simulate"); Helper::simulateTip = tr("Simulates the Modelica class"); - Helper::call = tr("Call function"); - Helper::callTip = tr("Calls the Modelica function"); + Helper::callFunction = tr("Call function"); + Helper::callFunctionTip = tr("Calls the Modelica function"); Helper::reSimulate = tr("Re-simulate"); Helper::reSimulateTip = tr("Re-simulates the Modelica class"); Helper::reSimulateSetup = tr("Re-simulate Setup"); diff --git a/OMEdit/OMEditGUI/Util/Helper.h b/OMEdit/OMEditGUI/Util/Helper.h index 19113b87039..baaa4cd2f5d 100644 --- a/OMEdit/OMEditGUI/Util/Helper.h +++ b/OMEdit/OMEditGUI/Util/Helper.h @@ -201,8 +201,8 @@ class Helper : public QObject static QString refresh; static QString simulate; static QString simulateTip; - static QString call; - static QString callTip; + static QString callFunction; + static QString callFunctionTip; static QString reSimulate; static QString reSimulateTip; static QString reSimulateSetup;