Changeset dfa5c6bb in OpenModelica


Ignore:
Timestamp:
2022-05-16T16:03:11+02:00 (2 years ago)
Author:
GitHub <noreply@…>
Branches:
maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master
Children:
82edd6c, e4b7953
Parents:
2ad1387
git-author:
perost <perost86@…> (05/16/22 16:03:11)
git-committer:
GitHub <noreply@…> (05/16/22 16:03:11)
Message:

Dumps annotations as JSON in instance API (#8963)

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/Script/NFApi.mo

    raa8243e0 rdfa5c6bb  
    11581158  if isSome(annOpt) then
    11591159    SOME(ann) := annOpt;
    1160     json := JSON.addPair("annotation",
    1161       JSON.makeString(SCodeDump.printModStr(ann.modification)), json);
     1160    json := JSON.addPair("annotation", dumpJSONMod(ann.modification), json);
    11621161  end if;
    11631162end dumpJSONAnnotationOpt;
     
    12201219end dumpJSONReplaceableElements;
    12211220
     1221function dumpJSONMod
     1222  input SCode.Mod mod;
     1223  output JSON json = JSON.emptyObject();
     1224algorithm
     1225  () := match mod
     1226    case SCode.Mod.MOD()
     1227      algorithm
     1228        for sm in mod.subModLst loop
     1229          json := JSON.addPair(sm.ident, dumpJSONSubMod(sm), json);
     1230        end for;
     1231      then
     1232        ();
     1233
     1234    else ();
     1235  end match;
     1236end dumpJSONMod;
     1237
     1238function dumpJSONSubMod
     1239  input SCode.SubMod subMod;
     1240  output JSON json = JSON.emptyObject();
     1241protected
     1242  SCode.Mod mod = subMod.mod;
     1243algorithm
     1244  () := match mod
     1245    case SCode.Mod.MOD()
     1246      algorithm
     1247        if not listEmpty(mod.subModLst) then
     1248          json := JSON.addPair("modifiers", dumpJSONMod(mod), json);
     1249        end if;
     1250
     1251        if isSome(mod.binding) then
     1252          json := JSON.addPair("value",
     1253            JSON.makeString(Dump.printExpStr(Util.getOption(mod.binding))), json);
     1254        end if;
     1255      then
     1256        ();
     1257
     1258    else ();
     1259  end match;
     1260end dumpJSONSubMod;
     1261
    12221262  annotation(__OpenModelica_Interface="backend");
    12231263end NFApi;
  • testsuite/openmodelica/instance-API/GetModelInstanceAnnotation1.mos

    raa8243e0 rdfa5c6bb  
    2020// "{
    2121//   \"name\": \"M\",
    22 //   \"annotation\": \"(Icon(graphics = {Rectangle(extent = {{-66, 78}, {70, -56}}, lineColor = {28, 108, 200})}), Diagram(graphics = {Ellipse(extent = {{-62, 68}, {56, -60}}, lineColor = {28, 108, 200})}))\",
     22//   \"annotation\": {
     23//     \"Icon\": {
     24//       \"modifiers\": {
     25//         \"graphics\": {
     26//           \"value\": \"{Rectangle(extent = {{-66, 78}, {70, -56}}, lineColor = {28, 108, 200})}\"
     27//         }
     28//       }
     29//     },
     30//     \"Diagram\": {
     31//       \"modifiers\": {
     32//         \"graphics\": {
     33//           \"value\": \"{Ellipse(extent = {{-62, 68}, {56, -60}}, lineColor = {28, 108, 200})}\"
     34//         }
     35//       }
     36//     }
     37//   },
    2338//   \"connections\": [
    2439//
  • testsuite/openmodelica/instance-API/GetModelInstanceConnection1.mos

    r4cb8721 rdfa5c6bb  
    9090//       \"lhs\": \"c1\",
    9191//       \"rhs\": \"c3\",
    92 //       \"annotation\": \"(Line(points = {{-25, 30}, {10, 30}, {10, -20}, {40, -20}}))\"
     92//       \"annotation\": {
     93//         \"Line\": {
     94//           \"modifiers\": {
     95//             \"points\": {
     96//               \"value\": \"{{-25, 30}, {10, 30}, {10, -20}, {40, -20}}\"
     97//             }
     98//           }
     99//         }
     100//       }
    93101//     },
    94102//     {
Note: See TracChangeset for help on using the changeset viewer.