Changeset 9d11fa2 in OpenModelica


Ignore:
Timestamp:
2020-10-16T15:17:36+02:00 (3 years ago)
Author:
GitHub <noreply@…>
Branches:
Added-citation-metadata, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, master, omlib-staging
Children:
23fedde
Parents:
1da8b221
git-author:
arun3688 <rain100falls@…> (10/16/20 15:17:36)
git-committer:
GitHub <noreply@…> (10/16/20 15:17:36)
Message:

fix ElementPropertiesDialog before instantiation (#6785)

  • fix start values in elementPropertiesDialog before instantiation
  • allow causality=parameter and delete start values
  • improve code readability
Location:
OMEdit/OMEditLIB/OMS
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OMEdit/OMEditLIB/OMS/ElementPropertiesDialog.cpp

    r1a785313 r9d11fa2  
    171171  mParameterLabels.clear();
    172172  mParameterLineEdits.clear();
    173   LibraryTreeItem *pModelLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(
    174                                              StringHandler::getFirstWordBeforeDot(mpComponent->getLibraryTreeItem()->getNameStructure()));
    175   bool modelInstantiated = pModelLibraryTreeItem && pModelLibraryTreeItem->isOMSModelInstantiated();
    176173  bool hasParameter = false;
    177174  if (mpComponent->getLibraryTreeItem()->getOMSElement() && mpComponent->getLibraryTreeItem()->getOMSElement()->connectors) {
     
    190187          pParameterLineEdit->setValidator(pDoubleValidator);
    191188          double value;
    192           if (modelInstantiated && (status = OMSProxy::instance()->getReal(nameStructure, &value))) {
     189          if ((status = OMSProxy::instance()->getReal(nameStructure, &value))) {
    193190            pParameterLineEdit->setText(QString::number(value));
    194191          }
     
    197194          pParameterLineEdit->setValidator(pIntValidator);
    198195          int value;
    199           if (modelInstantiated && (status = OMSProxy::instance()->getInteger(nameStructure, &value))) {
     196          if ((status = OMSProxy::instance()->getInteger(nameStructure, &value))) {
    200197            pParameterLineEdit->setText(QString::number(value));
    201198          }
     
    204201          pParameterLineEdit->setValidator(pIntValidator);
    205202          bool value;
    206           if (modelInstantiated && (status = OMSProxy::instance()->getBoolean(nameStructure, &value))) {
     203          if ((status = OMSProxy::instance()->getBoolean(nameStructure, &value))) {
    207204            pParameterLineEdit->setText(QString::number(value));
    208205          }
     
    259256          pInputLineEdit->setValidator(pDoubleValidator);
    260257          double value;
    261           if (modelInstantiated && (status = OMSProxy::instance()->getReal(nameStructure, &value))) {
     258          if ((status = OMSProxy::instance()->getReal(nameStructure, &value))) {
    262259            pInputLineEdit->setText(QString::number(value));
    263260          }
     
    266263          pInputLineEdit->setValidator(pIntValidator);
    267264          int value;
    268           if (modelInstantiated && (status = OMSProxy::instance()->getInteger(nameStructure, &value))) {
     265          if ((status = OMSProxy::instance()->getInteger(nameStructure, &value))) {
    269266            pInputLineEdit->setText(QString::number(value));
    270267          }
     
    273270          pInputLineEdit->setValidator(pIntValidator);
    274271          bool value;
    275           if (modelInstantiated && (status = OMSProxy::instance()->getBoolean(nameStructure, &value))) {
     272          if ((status = OMSProxy::instance()->getBoolean(nameStructure, &value))) {
    276273            pInputLineEdit->setText(QString::number(value));
    277274          }
     
    302299  mpOkButton = new QPushButton(Helper::ok);
    303300  mpOkButton->setAutoDefault(true);
    304   mpOkButton->setEnabled(modelInstantiated);
    305301  connect(mpOkButton, SIGNAL(clicked()), this, SLOT(updateProperties()));
    306302  mpCancelButton = new QPushButton(Helper::cancel);
     
    356352        QString parameterValue = mParameterLineEdits.at(parametersIndex)->text();
    357353        parametersIndex++;
    358         if (pInterfaces[i]->type == oms_signal_type_real) {
    359           OMSProxy::instance()->setReal(nameStructure, parameterValue.toDouble());
    360         } else if (pInterfaces[i]->type == oms_signal_type_integer) {
    361           OMSProxy::instance()->setInteger(nameStructure, parameterValue.toInt());
    362         } else if (pInterfaces[i]->type == oms_signal_type_boolean) {
    363           OMSProxy::instance()->setBoolean(nameStructure, parameterValue.toInt());
    364         } else if (pInterfaces[i]->type == oms_signal_type_string) {
    365           qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_string not implemented yet.";
    366         } else if (pInterfaces[i]->type == oms_signal_type_enum) {
    367           qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_enum not implemented yet.";
    368         } else if (pInterfaces[i]->type == oms_signal_type_bus) {
    369           qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_bus not implemented yet.";
     354        if (parameterValue.isEmpty()) {
     355          // delete start values only
     356          OMSProxy::instance()->omsDelete(nameStructure + ":start");
    370357        } else {
    371           qDebug() << "ElementPropertiesDialog::updateProperties() unknown oms_signal_type_enu_t.";
     358          if (pInterfaces[i]->type == oms_signal_type_real) {
     359            OMSProxy::instance()->setReal(nameStructure, parameterValue.toDouble());
     360          } else if (pInterfaces[i]->type == oms_signal_type_integer) {
     361            OMSProxy::instance()->setInteger(nameStructure, parameterValue.toInt());
     362          } else if (pInterfaces[i]->type == oms_signal_type_boolean) {
     363            OMSProxy::instance()->setBoolean(nameStructure, parameterValue.toInt());
     364          } else if (pInterfaces[i]->type == oms_signal_type_string) {
     365            qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_string not implemented yet.";
     366          } else if (pInterfaces[i]->type == oms_signal_type_enum) {
     367            qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_enum not implemented yet.";
     368          } else if (pInterfaces[i]->type == oms_signal_type_bus) {
     369            qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_bus not implemented yet.";
     370          } else {
     371            qDebug() << "ElementPropertiesDialog::updateProperties() unknown oms_signal_type_enu_t.";
     372          }
    372373        }
    373374      } else if (pInterfaces[i]->causality == oms_causality_input) {
    374375        QString inputValue = mInputLineEdits.at(inputsIndex)->text();
    375376        inputsIndex++;
    376         if (pInterfaces[i]->type == oms_signal_type_real) {
    377           OMSProxy::instance()->setReal(nameStructure, inputValue.toDouble());
    378         } else if (pInterfaces[i]->type == oms_signal_type_integer) {
    379           OMSProxy::instance()->setInteger(nameStructure, inputValue.toInt());
    380         } else if (pInterfaces[i]->type == oms_signal_type_boolean) {
    381           OMSProxy::instance()->setBoolean(nameStructure, inputValue.toInt());
    382         } else if (pInterfaces[i]->type == oms_signal_type_string) {
    383           qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_string not implemented yet.";
    384         } else if (pInterfaces[i]->type == oms_signal_type_enum) {
    385           qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_enum not implemented yet.";
    386         } else if (pInterfaces[i]->type == oms_signal_type_bus) {
    387           qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_bus not implemented yet.";
     377        if (inputValue.isEmpty()){
     378          // delete start values only
     379          OMSProxy::instance()->omsDelete(nameStructure + ":start");
    388380        } else {
    389           qDebug() << "ElementPropertiesDialog::updateProperties() unknown oms_signal_type_enu_t.";
     381          if (pInterfaces[i]->type == oms_signal_type_real) {
     382            OMSProxy::instance()->setReal(nameStructure, inputValue.toDouble());
     383          } else if (pInterfaces[i]->type == oms_signal_type_integer) {
     384            OMSProxy::instance()->setInteger(nameStructure, inputValue.toInt());
     385          } else if (pInterfaces[i]->type == oms_signal_type_boolean) {
     386            OMSProxy::instance()->setBoolean(nameStructure, inputValue.toInt());
     387          } else if (pInterfaces[i]->type == oms_signal_type_string) {
     388            qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_string not implemented yet.";
     389          } else if (pInterfaces[i]->type == oms_signal_type_enum) {
     390            qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_enum not implemented yet.";
     391          } else if (pInterfaces[i]->type == oms_signal_type_bus) {
     392            qDebug() << "ElementPropertiesDialog::updateProperties() oms_signal_type_bus not implemented yet.";
     393          } else {
     394            qDebug() << "ElementPropertiesDialog::updateProperties() unknown oms_signal_type_enu_t.";
     395          }
    390396        }
    391397      }
  • OMEdit/OMEditLIB/OMS/ModelDialog.cpp

    r1a785313 r9d11fa2  
    534534  mpCausalityComboBox->addItem("Input", oms_causality_input);
    535535  mpCausalityComboBox->addItem("Output", oms_causality_output);
     536  mpCausalityComboBox->addItem("Parameter", oms_causality_parameter);
     537
    536538  // type
    537539  mpTypeLabel = new Label(Helper::type);
Note: See TracChangeset for help on using the changeset viewer.