From 5904fbc13da4b5839df66455276f0c362945b0ec Mon Sep 17 00:00:00 2001 From: ThummeTo <83663542+ThummeTo@users.noreply.github.com> Date: Tue, 19 Apr 2022 13:18:02 +0200 Subject: [PATCH] Printing fmu (#11) * 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 <93336654+stoljarjo@users.noreply.github.com> --- Project.toml | 4 ++-- src/FMI2.jl | 19 +++++++++++++++++++ src/FMI2_c.jl | 13 +++++++++++++ src/FMI3.jl | 19 +++++++++++++++++++ src/FMI3_c.jl | 13 ++++++++++++- 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 0ca0fb4..75f2e9d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FMICore" uuid = "8af89139-c281-408e-bce2-3005eb87462f" authors = ["TT ", "LM ", "JK "] -version = "0.8.0" +version = "0.8.1" [compat] -julia = "^1.5" \ No newline at end of file +julia = "^1.5" diff --git a/src/FMI2.jl b/src/FMI2.jl index f89c1aa..664f79d 100644 --- a/src/FMI2.jl +++ b/src/FMI2.jl @@ -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. @@ -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. """ diff --git a/src/FMI2_c.jl b/src/FMI2_c.jl index 4fa0bc5..1cb7500 100644 --- a/src/FMI2_c.jl +++ b/src/FMI2_c.jl @@ -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 @@ -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 ### """ diff --git a/src/FMI3.jl b/src/FMI3.jl index 6a0d9bf..7547e2d 100644 --- a/src/FMI3.jl +++ b/src/FMI3.jl @@ -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 @@ -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. """ diff --git a/src/FMI3_c.jl b/src/FMI3_c.jl index 6ef0cb0..25aac1e 100644 --- a/src/FMI3_c.jl +++ b/src/FMI3_c.jl @@ -407,4 +407,15 @@ mutable struct fmi3ModelDescription # additional fields (non-FMI-specific) valueReferenceIndicies::Dict{Integer,Integer} -end \ No newline at end of file +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)" +) \ No newline at end of file