Skip to content

Commit

Permalink
Adding API.instantiateModel
Browse files Browse the repository at this point in the history
  - Updating setup-openmodelica action
  • Loading branch information
AnHeuermann committed Dec 7, 2023
1 parent d8c81e6 commit 9c76b66
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v4

- name: "Set up OpenModelica Compiler"
uses: AnHeuermann/setup-openmodelica@v0.6
uses: AnHeuermann/setup-openmodelica@v0.7
with:
version: ${{ matrix.omc-version }}
packages: |
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OMJulia"
uuid = "0f4fe800-344e-11e9-2949-fb537ad918e1"
authors = ["Martin Sjölund <[email protected]>", "Arunkumar Palanisamy <[email protected]>"]
version = "0.3.0"
version = "0.3.1"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
17 changes: 16 additions & 1 deletion src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ module API
requireExactVersion::Bool = false
)
exp = join(["loadModel", "(", "className", "=", className, ",", "priorityVersion", "=", "{", makeVectorString(priorityVersion), "}", ",", "notify", "=", notify,",", "languageStandard", "=", modelicaString(languageStandard), ",", "requireExactVersion", "=", requireExactVersion,")"])

success = OMJulia.sendExpression(omc, exp)

if !success
Expand Down Expand Up @@ -534,4 +533,20 @@ module API
return (ret[1], convert(Vector{String}, ret[2]))
end
end

"""
instantiateModel(omc, className)
Instantiates the class and returns the flat Modelica code.
See [OpenModelica scripting API `instantiateModel`](https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/scripting_api.html#instantiatemodel).
"""
function instantiateModel(omc::OMJulia.OMCSession, className::String)
flatModelicaCode = OMJulia.sendExpression(omc, "instantiateModel($className)")
if isempty(flatModelicaCode)
throw(OMJulia.API.ScriptingError(omc, msg = "instantiateModel($className)"))
end

return flatModelicaCode
end
end
3 changes: 3 additions & 0 deletions test/apiTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,8 @@ import OMJulia

@test [:BouncingBall, :ModSeborgCSTRorg] == sort(OMJulia.API.getClassNames(omc))

flatModelicaCode = OMJulia.API.instantiateModel(omc, "BouncingBall")
@test occursin("class BouncingBall", flatModelicaCode)

OMJulia.quit(omc)
end

0 comments on commit 9c76b66

Please sign in to comment.