Skip to content

Commit 3bb0075

Browse files
authored
Add choices comments to the instance API (#12786)
1 parent 7834560 commit 3bb0075

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

OMCompiler/Compiler/Script/NFApi.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,10 @@ algorithm
21582158
json := JSON.addPair("each", JSON.makeBoolean(true), json);
21592159
end if;
21602160

2161+
if isChoices and isSome(mod.comment) then
2162+
json := JSON.addPair("comment", JSON.makeString(Util.getOption(mod.comment)), json);
2163+
end if;
2164+
21612165
if isSome(mod.binding) then
21622166
binding_json := JSON.makeString(Dump.printExpStr(Util.getOption(mod.binding)));
21632167

OMEdit/OMEditLIB/Modeling/Model.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,8 @@ namespace ModelInstance
733733
mFinal = true;
734734
} else if (modifierKey.compare(QStringLiteral("each")) == 0) {
735735
mEach = true;
736+
} else if (modifierKey.compare(QStringLiteral("comment")) == 0) {
737+
mComment = modifierValue.toString();
736738
} else if (modifierKey.compare(QStringLiteral("$value")) == 0) {
737739
if (modifierValue.isObject()) {
738740
QJsonObject valueObject = modifierValue.toObject();
@@ -777,15 +779,14 @@ namespace ModelInstance
777779
if (!subModifiers.isEmpty()) {
778780
value.append("(" % subModifiers.join(", ") % ")");
779781
}
780-
if (mValue.isEmpty()) {
781-
if (value.compare(mName) != 0) {
782-
return value;
783-
} else {
784-
return "";
785-
}
786-
} else {
787-
return value.append(mName.isEmpty() ? mValue : " = " % mValue);
782+
if (!mValue.isEmpty()) {
783+
value.append(mName.isEmpty() ? mValue : " = " % mValue);
788784
}
785+
if (!mComment.isEmpty()) {
786+
value.append(" \"" % mComment % "\"");
787+
}
788+
789+
return value.compare(mName) == 0 ? "" : value;
789790
}
790791
}
791792

OMEdit/OMEditLIB/Modeling/Model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ namespace ModelInstance
487487
bool mEach = false;
488488
QString mValue;
489489
bool mValueDefined = false;
490+
QString mComment;
490491
Element *mpElement = 0;
491492
QList<Modifier*> mModifiers;
492493

testsuite/openmodelica/instance-API/GetModelInstanceChoices1.mos

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ getErrorString();
4040
// \"annotation\": {
4141
// \"choices\": {
4242
// \"choice\": [
43-
// \"1.0\",
44-
// \"2.0\",
45-
// \"3.0\"
43+
// {
44+
// \"comment\": \"A\",
45+
// \"$value\": \"1.0\"
46+
// },
47+
// {
48+
// \"comment\": \"B\",
49+
// \"$value\": \"2.0\"
50+
// },
51+
// {
52+
// \"comment\": \"C\",
53+
// \"$value\": \"3.0\"
54+
// }
4655
// ],
4756
// \"checkBox\": true
4857
// }

0 commit comments

Comments
 (0)