|
38 | 38 | #include "Modeling/Commands.h" |
39 | 39 | #include "Options/OptionsDialog.h" |
40 | 40 | #include "OMPlot.h" |
| 41 | +#include "FlatModelica/Parser.h" |
41 | 42 |
|
42 | 43 | #include <QApplication> |
43 | 44 | #include <QMenu> |
@@ -200,11 +201,11 @@ Parameter::Parameter(ModelInstance::Component *pComponent, ElementParameters *pE |
200 | 201 | // For now we only handle replaceable component. Enable the line below once we start handling the replaceable class. |
201 | 202 | //mValueType = Parameter::ReplaceableClass; |
202 | 203 | if (mpModelInstanceComponent->getModel()) { |
203 | | - mpModifyReplaceableButton = new QToolButton; |
204 | | - mpModifyReplaceableButton->setIcon( QIcon(":/Resources/icons/edit-icon.svg")); |
205 | | - mpModifyReplaceableButton->setToolTip(tr("Edit")); |
206 | | - mpModifyReplaceableButton->setAutoRaise(true); |
207 | | - connect(mpModifyReplaceableButton, SIGNAL(clicked()), SLOT(modifyReplaceableButtonClicked())); |
| 204 | + mpEditRedeclareClassButton = new QToolButton; |
| 205 | + mpEditRedeclareClassButton->setIcon( QIcon(":/Resources/icons/edit-icon.svg")); |
| 206 | + mpEditRedeclareClassButton->setToolTip(tr("Edit")); |
| 207 | + mpEditRedeclareClassButton->setAutoRaise(true); |
| 208 | + connect(mpEditRedeclareClassButton, SIGNAL(clicked()), SLOT(editRedeclareClassButtonClicked())); |
208 | 209 | } |
209 | 210 | } else if (!mpModelInstanceComponent->getAnnotation()->getChoices().getChoices().isEmpty()) { |
210 | 211 | mValueType = Parameter::Choices; |
@@ -515,8 +516,8 @@ void Parameter::setEnabled(bool enable) |
515 | 516 | if (enable) { |
516 | 517 | enableDisableUnitComboBox(getValue()); |
517 | 518 | } |
518 | | - if (mpModifyReplaceableButton) { |
519 | | - mpModifyReplaceableButton->setEnabled(enable); |
| 519 | + if (mpEditRedeclareClassButton) { |
| 520 | + mpEditRedeclareClassButton->setEnabled(enable); |
520 | 521 | } |
521 | 522 | } |
522 | 523 |
|
@@ -624,7 +625,7 @@ void Parameter::createValueWidget() |
624 | 625 | if (MainWindow::instance()->isNewApi()) { |
625 | 626 | comment = choice; |
626 | 627 | } else { |
627 | | - comment = StringHandler::getModelicaComment(choice); |
| 628 | + comment = StringHandler::removeFirstLastQuotes(FlatModelica::Parser::getModelicaComment(choice)); |
628 | 629 | } |
629 | 630 | mpValueComboBox->addItem(comment, choice); |
630 | 631 | } |
@@ -717,22 +718,50 @@ void Parameter::updateValueBinding(const FlatModelica::Expression expression) |
717 | 718 | } |
718 | 719 | } |
719 | 720 |
|
720 | | -void Parameter::modifyReplaceableButtonClicked() |
| 721 | +/*! |
| 722 | + * \brief Parameter::editRedeclareClassButtonClicked |
| 723 | + * Slot activate when mpEditRedeclareClassButton clicked signal is raised. |
| 724 | + * Opens ElementParameters dialog for the redeclare class. |
| 725 | + */ |
| 726 | +void Parameter::editRedeclareClassButtonClicked() |
721 | 727 | { |
722 | | -// QString className = mpModelInstanceComponent->getType(); |
723 | | -// qDebug() << className; |
724 | | - MainWindow::instance()->getProgressBar()->setRange(0, 0); |
725 | | - MainWindow::instance()->showProgressBar(); |
726 | | - ElementParameters *pElementParameters = new ElementParameters(mpModelInstanceComponent, mpElementParameters->getGraphicsView(), |
727 | | - mpElementParameters->isInherited(), true, mpElementParameters); |
728 | | - MainWindow::instance()->hideProgressBar(); |
729 | | - MainWindow::instance()->getStatusBar()->clearMessage(); |
730 | | - if (pElementParameters->exec() == QDialog::Accepted) { |
731 | | - if (!pElementParameters->getModification().isEmpty()) { |
732 | | - setValueWidget(pElementParameters->getModification(), false, mUnit, true); |
| 728 | + QString type; |
| 729 | + if (mpValueComboBox->currentIndex() == 0) { |
| 730 | + type = mpModelInstanceComponent->getType(); |
| 731 | + } else { |
| 732 | + type = mpModelInstanceComponent->getAnnotation()->getChoices().getType(mpValueComboBox->currentIndex() - 1); |
| 733 | + } |
| 734 | + |
| 735 | + // if type is empty then try to parse the Modelica code of redeclare to get the type |
| 736 | + if (type.isEmpty()) { |
| 737 | + type = FlatModelica::Parser::getTypeFromElementRedeclaration(mpValueComboBox->lineEdit()->text()); |
| 738 | + } |
| 739 | + |
| 740 | + if (type.isEmpty()) { |
| 741 | + QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error), |
| 742 | + tr("Unable to find the redeclare class %1.").arg(type), Helper::ok); |
| 743 | + } else { |
| 744 | + MainWindow::instance()->getProgressBar()->setRange(0, 0); |
| 745 | + MainWindow::instance()->showProgressBar(); |
| 746 | + ModelInstance::Model *pCurrentModel = mpModelInstanceComponent->getModel(); |
| 747 | + const QJsonObject newModelJSON = MainWindow::instance()->getOMCProxy()->getModelInstance(type); |
| 748 | + if (!newModelJSON.isEmpty()) { |
| 749 | + ModelInstance::Model *pNewModel = new ModelInstance::Model(newModelJSON); |
| 750 | + mpModelInstanceComponent->setModel(pNewModel); |
| 751 | + ElementParameters *pElementParameters = new ElementParameters(mpModelInstanceComponent, mpElementParameters->getGraphicsView(), mpElementParameters->isInherited(), true, mpElementParameters); |
| 752 | + MainWindow::instance()->hideProgressBar(); |
| 753 | + MainWindow::instance()->getStatusBar()->clearMessage(); |
| 754 | + if (pElementParameters->exec() == QDialog::Accepted) { |
| 755 | + if (!pElementParameters->getModification().isEmpty()) { |
| 756 | + setValueWidget(pElementParameters->getModification(), false, mUnit, true); |
| 757 | + } |
| 758 | + } |
| 759 | + pElementParameters->deleteLater(); |
| 760 | + // reset the actual model of the element |
| 761 | + mpModelInstanceComponent->setModel(pCurrentModel); |
| 762 | + delete pNewModel; |
733 | 763 | } |
734 | 764 | } |
735 | | - pElementParameters->deleteLater(); |
736 | 765 | } |
737 | 766 |
|
738 | 767 | /*! |
@@ -1201,8 +1230,8 @@ void ElementParameters::setUpDialog() |
1201 | 1230 | } |
1202 | 1231 | pGroupBoxGridLayout->addWidget(pParameter->getValueWidget(), layoutIndex, columnIndex++); |
1203 | 1232 |
|
1204 | | - if (pParameter->getModifyReplaceableButton()) { |
1205 | | - pGroupBoxGridLayout->addWidget(pParameter->getModifyReplaceableButton(), layoutIndex, columnIndex++); |
| 1233 | + if (pParameter->getEditRedeclareClassButton()) { |
| 1234 | + pGroupBoxGridLayout->addWidget(pParameter->getEditRedeclareClassButton(), layoutIndex, columnIndex++); |
1206 | 1235 | } else { |
1207 | 1236 | pGroupBoxGridLayout->addItem(new QSpacerItem(1, 1), layoutIndex, columnIndex++); |
1208 | 1237 | } |
@@ -1716,12 +1745,6 @@ void ElementParametersOld::setUpDialog() |
1716 | 1745 | } |
1717 | 1746 | pGroupBoxGridLayout->addWidget(pParameter->getValueWidget(), layoutIndex, columnIndex++); |
1718 | 1747 |
|
1719 | | - if (pParameter->getModifyReplaceableButton()) { |
1720 | | - pGroupBoxGridLayout->addWidget(pParameter->getModifyReplaceableButton(), layoutIndex, columnIndex++); |
1721 | | - } else { |
1722 | | - pGroupBoxGridLayout->addItem(new QSpacerItem(1, 1), layoutIndex, columnIndex++); |
1723 | | - } |
1724 | | - |
1725 | 1748 | if (pParameter->getLoadSelectorFilter().compare("-") != 0 || pParameter->getLoadSelectorCaption().compare("-") != 0 || |
1726 | 1749 | pParameter->getSaveSelectorFilter().compare("-") != 0 || pParameter->getSaveSelectorCaption().compare("-") != 0) { |
1727 | 1750 | pGroupBoxGridLayout->addWidget(pParameter->getFileSelectorButton(), layoutIndex, columnIndex++); |
|
0 commit comments