Skip to content

Commit

Permalink
Printing fmu (#11)
Browse files Browse the repository at this point in the history
* Update Project.toml

* Custom printing (#10)

* Add CompatHelper to GitHub actions

* Add custom printing

* Bug fix in printing FMU

* Beautify printing

Co-authored-by: Johannes Stoljar <[email protected]>
  • Loading branch information
ThummeTo and stoljarjo authored Apr 19, 2022
1 parent f891bbc commit 5904fbc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMICore"
uuid = "8af89139-c281-408e-bce2-3005eb87462f"
authors = ["TT <[email protected]>", "LM <[email protected]>", "JK <[email protected]>"]
version = "0.8.0"
version = "0.8.1"

[compat]
julia = "^1.5"
julia = "^1.5"
19 changes: 19 additions & 0 deletions src/FMI2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ mutable struct FMU2Component
end
end

""" Overload the Base.show() function for custom printing of the FMU2Component"""
Base.show(io::IO, fmu::FMU2Component) = print(io,
"FMU2: $(fmu.fmu)
State: $(fmu.state)
Logging: $(fmu.loggingOn)
Instance name: $(fmu.instanceName)
System time: $(fmu.t)
System states: $(fmu.x)"
)

"""
A mutable struct representing the excution configuration of a FMU.
For FMUs that have issues with calls like `fmi2Reset` or `fmi2FreeInstance`, this is pretty useful.
Expand Down Expand Up @@ -361,6 +371,15 @@ mutable struct FMU2 <: FMU
end
end

""" Overload the Base.show() function for custom printing of the FMU2"""
Base.show(io::IO, fmu::FMU2) = print(io,
"Model name: $(fmu.modelName)
Instance name: $(fmu.instanceName)
Model description: $(fmu.modelDescription)
Type: $(fmu.type)
Components: $(fmu.components)"
)

"""
Formats a fmi2Status to String.
"""
Expand Down
13 changes: 13 additions & 0 deletions src/FMI2_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ mutable struct fmi2ScalarVariable
end
end

""" Overload the Base.show() function for custom printing of the fmi2ScalarVariable"""
Base.show(io::IO, var::fmi2ScalarVariable) = print(io,
"Var. name: $(var.name) (reference: $(var.valueReference))")

"""
Source: FMISpec2.0.2[p.106]: 4.2.3 Retrieving Status Information from the Slave
Expand Down Expand Up @@ -558,6 +562,15 @@ mutable struct fmi2ModelDescription
end
end

""" Overload the Base.show() function for custom printing of the fmi2ModelDescription"""
Base.show(io::IO, desc::fmi2ModelDescription) = print(io,
"Model name: $(desc.modelName)
FMI version: $(desc.fmiVersion)
GUID: $(desc.guid)
Description: $(desc.description)
Model variables: $(desc.modelVariables)"
)

### FUNCTIONS ###

"""
Expand Down
19 changes: 19 additions & 0 deletions src/FMI3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ mutable struct FMU3Component
end
end

""" Overload the Base.show() function for custom printing of the FMU2Component"""
Base.show(io::IO, fmu::FMU3Component) = print(io,
"FMU2: $(fmu.fmu)
State: $(fmu.state)
Logging: $(fmu.loggingOn)
Instance name: $(fmu.instanceName)
System time: $(fmu.t)
Values: $(fmu.realValues)"
)

"""
Source: FMISpec3.0, Version D5ef1c1: 2.2.1. Header Files and Naming of Functions
Expand Down Expand Up @@ -210,6 +220,15 @@ mutable struct FMU3 <: FMU
end
end

""" Overload the Base.show() function for custom printing of the FMU3"""
Base.show(io::IO, fmu::FMU3) = print(io,
"Model name: $(fmu.modelName)
Instance name: $(fmu.instanceName)
Model description: $(fmu.modelDescription)
Type: $(fmu.type)
Components: $(fmu.components)"
)

"""
Formats the fmi3Status into a String.
"""
Expand Down
13 changes: 12 additions & 1 deletion src/FMI3_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,15 @@ mutable struct fmi3ModelDescription

# additional fields (non-FMI-specific)
valueReferenceIndicies::Dict{Integer,Integer}
end
end

""" Overload the Base.show() function for custom printing of the fmi3ModelDescription"""
Base.show(io::IO, desc::fmi3ModelDescription) = print(io,
"Model name: $(desc.modelName)
FMI version: $(desc.fmiVersion)
GUID: $(desc.instantiationToken)
Description: $(desc.description)
Co-Simulation: $(desc.isCoSimulation)
Model-Exchange: $(desc.isModelExchange)
Model variables: $(desc.modelVariables)"
)

2 comments on commit 5904fbc

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/58730

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.1 -m "<description of version>" 5904fbc13da4b5839df66455276f0c362945b0ec
git push origin v0.8.1

Please sign in to comment.