Skip to content

Commit

Permalink
Few minor fixes
Browse files Browse the repository at this point in the history
Removed LibraryTreeItem::callFunction as is not needed.
Added copyright text to FunctionArgumentDialog files.
Use Label instead of QLabel.
Do not fetch the components again and again. Just load the class and get the components from it.
Read the class comment from LibraryTreeItem.
FunctionArgumentDialog formatting.
  • Loading branch information
adeas31 committed Aug 14, 2018
1 parent 717eccd commit a937586
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 66 deletions.
104 changes: 70 additions & 34 deletions 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 <QGridLayout>
#include <QLabel>
#include <QLineEdit>

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<ComponentInfo*> 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<ComponentInfo*> 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();

Expand Down
31 changes: 31 additions & 0 deletions 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

Expand Down
42 changes: 23 additions & 19 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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. */
Expand All @@ -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);
}
}

/*!
Expand Down
5 changes: 2 additions & 3 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -382,7 +381,7 @@ public slots:
void instantiateModel();
void checkModel();
void checkAllModels();
void call();
void callFunction();
void simulate();
void simulateWithTransformationalDebugger();
void simulateWithAlgorithmicDebugger();
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -399,6 +399,7 @@ class ModelWidget : public QWidget
void removeInheritedClass(LibraryTreeItem *pLibraryTreeItem) {mInheritedClassesList.removeOne(pLibraryTreeItem);}
void clearInheritedClasses() {mInheritedClassesList.clear();}
QList<LibraryTreeItem*> getInheritedClassesList() {return mInheritedClassesList;}
QList<ComponentInfo*> getComponentsList() {return mComponentsList;}
QMap<QString, QString> getExtendsModifiersMap(QString extendsClass);
void fetchExtendsModifiers(QString extendsClass);
void reDrawModelWidgetInheritedClasses();
Expand Down
8 changes: 4 additions & 4 deletions OMEdit/OMEditGUI/OMEditGUI.pro
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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) {

Expand Down
8 changes: 4 additions & 4 deletions OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Util/Helper.h
Expand Up @@ -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;
Expand Down

0 comments on commit a937586

Please sign in to comment.