Skip to content

Commit

Permalink
[NewAPI] Check for choicesAllMatching annotation (#10302)
Browse files Browse the repository at this point in the history
If choicesAllMatching = true then call getAllSubtypeOf otherwise not
  • Loading branch information
adeas31 committed Mar 2, 2023
1 parent dd857c6 commit e810ab7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
65 changes: 43 additions & 22 deletions OMEdit/OMEditLIB/Element/ElementProperties.cpp
Expand Up @@ -209,6 +209,8 @@ Parameter::Parameter(ModelInstance::Component *pComponent, ElementParameters *pE
}
} else if (!mpModelInstanceComponent->getAnnotation()->getChoices().getChoices().isEmpty()) {
mValueType = Parameter::Choices;
} else if (mpModelInstanceComponent->getAnnotation()->isChoicesAllMatching()) {
mValueType = Parameter::ChoicesAllMatching;
} else {
mValueType = Parameter::Normal;
}
Expand Down Expand Up @@ -273,10 +275,17 @@ Parameter::Parameter(ModelInstance::Component *pComponent, ElementParameters *pE
update();
}

/*!
* \brief Parameter::isParameter
* Returns true if parameter
* \return
*/
bool Parameter::isParameter() const
{
if (mpModelInstanceComponent) {
return mpModelInstanceComponent->getPrefixes()->getVariability().compare(QStringLiteral("parameter")) == 0;
} else {
return mpElement->getElementInfo()->getVariablity().compare("parameter") == 0;
}
}

Expand Down Expand Up @@ -341,6 +350,7 @@ void Parameter::setValueWidget(QString value, bool defaultValue, QString fromUni
case Parameter::ReplaceableClass:
case Parameter::ReplaceableComponent:
case Parameter::Choices:
case Parameter::ChoicesAllMatching:
if (defaultValue) {
mpValueComboBox->lineEdit()->setPlaceholderText(value);
} else {
Expand Down Expand Up @@ -404,6 +414,7 @@ QWidget* Parameter::getValueWidget()
case Parameter::ReplaceableClass:
case Parameter::ReplaceableComponent:
case Parameter::Choices:
case Parameter::ChoicesAllMatching:
return mpValueComboBox;
case Parameter::CheckBox:
return mpValueCheckBox;
Expand All @@ -426,6 +437,7 @@ bool Parameter::isValueModified()
case Parameter::ReplaceableClass:
case Parameter::ReplaceableComponent:
case Parameter::Choices:
case Parameter::ChoicesAllMatching:
return mpValueComboBox->lineEdit()->isModified();
case Parameter::CheckBox:
return mValueCheckBoxModified;
Expand All @@ -448,6 +460,7 @@ QString Parameter::getValue()
case Parameter::ReplaceableClass:
case Parameter::ReplaceableComponent:
case Parameter::Choices:
case Parameter::ChoicesAllMatching:
return mpValueComboBox->lineEdit()->text().trimmed();
case Parameter::CheckBox:
return mpValueCheckBox->isChecked() ? "true" : "false";
Expand Down Expand Up @@ -484,6 +497,7 @@ void Parameter::setEnabled(bool enable)
case Parameter::ReplaceableComponent:
case Parameter::ReplaceableClass:
case Parameter::Choices:
case Parameter::ChoicesAllMatching:
mpValueComboBox->setEnabled(enable);
break;
case Parameter::CheckBox:
Expand Down Expand Up @@ -559,10 +573,14 @@ void Parameter::createValueWidget()

case Parameter::ReplaceableComponent:
case Parameter::ReplaceableClass:
case Parameter::Choices:
case Parameter::ChoicesAllMatching:
if (MainWindow::instance()->isNewApi()) {
constrainedByClassName = mpModelInstanceComponent->getPrefixes()->getReplaceable()->getConstrainedby();
if (constrainedByClassName.isEmpty()) {
constrainedByClassName = mpModelInstanceComponent->getType();
if (mValueType == Parameter::ReplaceableComponent || mValueType == Parameter::ReplaceableClass) {
constrainedByClassName = mpModelInstanceComponent->getPrefixes()->getReplaceable()->getConstrainedby();
if (constrainedByClassName.isEmpty()) {
constrainedByClassName = mpModelInstanceComponent->getType();
}
}
choices = mpModelInstanceComponent->getAnnotation()->getChoices().getChoices();
parentClassName = mpModelInstanceComponent->getParentModel()->getName();
Expand All @@ -582,24 +600,35 @@ void Parameter::createValueWidget()
elementName = mpElement->getName();
}

mpValueComboBox = new QComboBox;
mpValueComboBox->setEditable(true);
mpValueComboBox->addItem("", "");

if (constrainedByClassName.contains(QStringLiteral("$Any"))) {
constrainedByClassName = className;
}

mpValueComboBox = new QComboBox;
mpValueComboBox->setEditable(true);
mpValueComboBox->addItem("", "");
// add choices if there are any
for (i = 0; i < choices.size(); i++) {
QString choice = choices[i];
QString comment = StringHandler::getModelicaComment(choice);
QString comment;
if (MainWindow::instance()->isNewApi()) {
comment = choice;
} else {
comment = StringHandler::getModelicaComment(choice);
}
mpValueComboBox->addItem(comment, choice);
}

// do replaceable only if not choicesAllMatching=false
// if choicesAllMatching is not defined, consider choicesAllMatching=true
replaceableChoices = pOMCProxy->getAllSubtypeOf(constrainedByClassName, parentClassName);
// choicesAllMatching
if (MainWindow::instance()->isNewApi()) {
if (mpModelInstanceComponent->getAnnotation()->isChoicesAllMatching()) {
replaceableChoices = pOMCProxy->getAllSubtypeOf(constrainedByClassName, parentClassName);
}
} else {
// do replaceable only if not choicesAllMatching=false
// if choicesAllMatching is not defined, consider choicesAllMatching=true
replaceableChoices = pOMCProxy->getAllSubtypeOf(constrainedByClassName, parentClassName);
}
for (i = 0; i < replaceableChoices.size(); i++) {
replaceableChoice = replaceableChoices[i];
// if replaceableChoices points to a class in this scope, remove scope
Expand All @@ -614,25 +643,17 @@ void Parameter::createValueWidget()
}
replaceableText = replaceableChoices[i] + str;
mpValueComboBox->addItem(replaceableText, replaceable);
} else {
} else if (mValueType == Parameter::ReplaceableComponent) {
replaceable = QString("redeclare %1 %2").arg(replaceableChoice, elementName);
mpValueComboBox->addItem(replaceable, replaceable);
} else {
mpValueComboBox->addItem(replaceableChoice, replaceableChoice);
}
}

connect(mpValueComboBox, SIGNAL(currentIndexChanged(int)), SLOT(valueComboBoxChanged(int)));
break;

case Parameter::Choices:
mpValueComboBox = new QComboBox;
mpValueComboBox->setEditable(true);
mpValueComboBox->addItem("", "");
foreach (QString choice, mpModelInstanceComponent->getAnnotation()->getChoices().getChoices()) {
mpValueComboBox->addItem(choice, choice);
}
connect(mpValueComboBox, SIGNAL(currentIndexChanged(int)), SLOT(valueComboBoxChanged(int)));
break;

case Parameter::Normal:
default:
mpValueTextBox = new QLineEdit;
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditLIB/Element/ElementProperties.h
Expand Up @@ -52,7 +52,8 @@ class Parameter : public QObject
Enumeration,
ReplaceableComponent,
ReplaceableClass,
Choices
Choices,
ChoicesAllMatching
};
Parameter(Element *pElement, bool showStartAttribute, QString tab, QString groupBox);
Parameter(ModelInstance::Component *pComponent, ElementParameters *pElementParameters);
Expand Down
9 changes: 2 additions & 7 deletions OMEdit/OMEditLIB/Modeling/Model.h
Expand Up @@ -389,14 +389,9 @@ namespace ModelInstance

IconDiagramAnnotation *getIconAnnotation() const {return mpIconAnnotation.get();}
IconDiagramAnnotation *getDiagramAnnotation() const {return mpDiagramAnnotation.get();}
bool isDocumentationClass() const {return mDocumentationClass;}
QString getVersion() const {return mVersion;}
QString getVersionDate() const {return mVersionDate;}
QString getDateModified() const {return mDateModified;}
QString getPreferredView() const {return mPreferredView;}
bool isState() const {return mState;}
QString getAccess() const {return mAccess;}
BooleanAnnotation isState() const {return mState;}
// Element annotation
BooleanAnnotation isChoicesAllMatching() const {return mChoicesAllMatching;}
PlacementAnnotation getPlacementAnnotation() const {return mPlacementAnnotation;}
bool hasDialogAnnotation() const {return mHasDialogAnnotation;}
DialogAnnotation getDialogAnnotation() const {return mDialogAnnotation;}
Expand Down

0 comments on commit e810ab7

Please sign in to comment.