Skip to content

Commit bf7f7c6

Browse files
authored
add separate FMU export output window, which shows FMI export progress in OMEdit (#12891)
* add fmuExportOutputWidget to CMakeLists.txt * read progress percentage from cmake build
1 parent d863c0d commit bf7f7c6

File tree

11 files changed

+892
-43
lines changed

11 files changed

+892
-43
lines changed

OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,16 +2524,22 @@ end importFMUModelDescription;
25242524

25252525
function translateModelFMU
25262526
"Deprecated: Use buildModelFMU instead.
2527-
Translates a modelica model into a Functional Mockup Unit.
2527+
Translates a modelica model to c code without building it
25282528
The only required argument is the className, while all others have some default values.
25292529
Example command:
25302530
translateModelFMU(className, version=\"2.0\");"
25312531
input TypeName className "the class that should translated";
25322532
input String version = "2.0" "FMU version, 1.0 or 2.0.";
25332533
input String fmuType = "me" "FMU type, me (model exchange), cs (co-simulation), me_cs (both model exchange and co-simulation)";
25342534
input String fileNamePrefix = "<default>" "fileNamePrefix. <default> = \"className\"";
2535+
input String platforms[:] = {"static"} "The list of platforms to generate code for.
2536+
\"dynamic\"=current platform, dynamically link the runtime.
2537+
\"static\"=current platform, statically link everything.
2538+
\"<cpu>-<vendor>-<os>\", host tripple, e.g. \"x86_64-linux-gnu\" or \"x86_64-w64-mingw32\".
2539+
\"<cpu>-<vendor>-<os> docker run <image>\" host tripple with Docker image, e.g. \"x86_64-linux-gnu docker run --pull=never multiarch/crossbuild\"";
2540+
25352541
input Boolean includeResources = false "include Modelica based resources via loadResource or not";
2536-
output String generatedFileName "Returns the full path of the generated FMU.";
2542+
output Boolean success;
25372543
external "builtin";
25382544
annotation(preferredView="text", version="Deprecated");
25392545
end translateModelFMU;

OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,17 +2776,21 @@ annotation(preferredView="text");
27762776
end importFMUModelDescription;
27772777

27782778
function translateModelFMU
2779-
"Deprecated: Use buildModelFMU instead.
2780-
Translates a modelica model into a Functional Mockup Unit.
2779+
"Translates a modelica model into c code without building it
27812780
The only required argument is the className, while all others have some default values.
27822781
Example command:
27832782
translateModelFMU(className, version=\"2.0\");"
27842783
input TypeName className "the class that should translated";
27852784
input String version = "2.0" "FMU version, 1.0 or 2.0.";
27862785
input String fmuType = "me" "FMU type, me (model exchange), cs (co-simulation), me_cs (both model exchange and co-simulation)";
27872786
input String fileNamePrefix = "<default>" "fileNamePrefix. <default> = \"className\"";
2787+
input String platforms[:] = {"static"} "The list of platforms to generate code for.
2788+
\"dynamic\"=current platform, dynamically link the runtime.
2789+
\"static\"=current platform, statically link everything.
2790+
\"<cpu>-<vendor>-<os>\", host tripple, e.g. \"x86_64-linux-gnu\" or \"x86_64-w64-mingw32\".
2791+
\"<cpu>-<vendor>-<os> docker run <image>\" host tripple with Docker image, e.g. \"x86_64-linux-gnu docker run --pull=never multiarch/crossbuild\"";
27882792
input Boolean includeResources = false "include Modelica based resources via loadResource or not";
2789-
output String generatedFileName "Returns the full path of the generated FMU.";
2793+
output Boolean success;
27902794
external "builtin";
27912795
annotation(preferredView="text", version="Deprecated");
27922796
end translateModelFMU;

OMCompiler/Compiler/Script/CevalScriptBackend.mo

Lines changed: 125 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,11 @@ algorithm
11961196
case ("modelEquationsUC",_)
11971197
then Values.STRING("There were errors during extraction of uncertainty equations. Use getErrorString() to see them.");
11981198

1199-
case ("translateModelFMU", Values.CODE(Absyn.C_TYPENAME(className))::Values.STRING(str1)::Values.STRING(str2)::Values.STRING(filenameprefix)::_)
1199+
case ("translateModelFMU", Values.CODE(Absyn.C_TYPENAME(className))::Values.STRING(str1)::Values.STRING(str2)::Values.STRING(filenameprefix)::Values.ARRAY(valueLst=cvars)::_)
12001200
algorithm
1201-
Error.addMessage(Error.DEPRECATED_API_CALL, {"translateModelFMU", "buildModelFMU"});
1202-
(outCache, ret_val) := buildModelFMU(outCache, inEnv, className, str1, str2, filenameprefix, true);
1201+
(b, outCache, ret_val) := translateModelFMU(outCache, inEnv, className, str1, str2, filenameprefix, true, list(ValuesUtil.extractValueString(vv) for vv in cvars));
12031202
then
1204-
ret_val;
1203+
Values.BOOL(b);
12051204

12061205
case ("translateModelFMU", _)
12071206
then Values.STRING("");
@@ -3919,6 +3918,128 @@ algorithm
39193918
end if;
39203919
end configureFMU;
39213920

3921+
protected function translateModelFMU
3922+
"translates modelica model as FMU, generates only c code and does not build"
3923+
input FCore.Cache inCache;
3924+
input FCore.Graph inEnv;
3925+
input Absyn.Path className "path for the model";
3926+
input String FMUVersion;
3927+
input String inFMUType;
3928+
input String inFileNamePrefix;
3929+
input Boolean addDummy "if true, add a dummy state";
3930+
input list<String> platforms = {"static"};
3931+
input Option<SimCode.SimulationSettings> inSimSettings = NONE();
3932+
output Boolean success;
3933+
output FCore.Cache cache;
3934+
output Values.Value outValue;
3935+
protected
3936+
Absyn.Program p;
3937+
Flags.Flag flags;
3938+
String commandLineOptions;
3939+
list<String> args;
3940+
Boolean haveAnnotation;
3941+
algorithm
3942+
// handle encryption
3943+
// if AST contains encrypted class show nothing
3944+
p := SymbolTable.getAbsyn();
3945+
if Interactive.astContainsEncryptedClass(p) then
3946+
Error.addMessage(Error.ACCESS_ENCRYPTED_PROTECTED_CONTENTS, {});
3947+
cache := inCache;
3948+
outValue := Values.STRING("");
3949+
elseif Config.ignoreCommandLineOptionsAnnotation() then
3950+
(success, cache, outValue) := callTranslateModelFMU(inCache,inEnv,className,FMUVersion,inFMUType,inFileNamePrefix,addDummy,platforms,inSimSettings);
3951+
else
3952+
// read the __OpenModelica_commandLineOptions
3953+
Absyn.STRING(commandLineOptions) := Interactive.getNamedAnnotation(className, SymbolTable.getAbsyn(), Absyn.IDENT("__OpenModelica_commandLineOptions"), SOME(Absyn.STRING("")), Interactive.getAnnotationExp);
3954+
haveAnnotation := boolNot(stringEq(commandLineOptions, ""));
3955+
// backup the flags.
3956+
flags := if haveAnnotation then FlagsUtil.backupFlags() else FlagsUtil.loadFlags();
3957+
try
3958+
// apply if there are any new flags
3959+
if haveAnnotation then
3960+
args := System.strtok(commandLineOptions, " ");
3961+
FlagsUtil.readArgs(args);
3962+
end if;
3963+
3964+
(success, cache, outValue) := callTranslateModelFMU(inCache,inEnv,className,FMUVersion,inFMUType,inFileNamePrefix,addDummy,platforms,inSimSettings);
3965+
// reset to the original flags
3966+
FlagsUtil.saveFlags(flags);
3967+
else
3968+
FlagsUtil.saveFlags(flags);
3969+
fail();
3970+
end try;
3971+
end if;
3972+
end translateModelFMU;
3973+
3974+
protected function callTranslateModelFMU
3975+
"Translates a model into target code and writes CMakeLists.txt"
3976+
input FCore.Cache inCache;
3977+
input FCore.Graph inEnv;
3978+
input Absyn.Path className "path for the model";
3979+
input String FMUVersion;
3980+
input String inFMUType;
3981+
input String inFileNamePrefix;
3982+
input Boolean addDummy "if true, add a dummy state";
3983+
input list<String> platforms = {"static"};
3984+
input Option<SimCode.SimulationSettings> inSimSettings = NONE();
3985+
output Boolean success;
3986+
output FCore.Cache cache;
3987+
output Values.Value outValue;
3988+
protected
3989+
String filenameprefix, fmuTargetName;
3990+
GlobalScript.SimulationOptions defaultSimOpt;
3991+
SimCode.SimulationSettings simSettings;
3992+
list<String> libs;
3993+
String FMUType = inFMUType;
3994+
algorithm
3995+
cache := inCache;
3996+
if not FMI.checkFMIVersion(FMUVersion) then
3997+
success :=false;
3998+
outValue := Values.STRING("");
3999+
Error.addMessage(Error.UNKNOWN_FMU_VERSION, {FMUVersion});
4000+
return;
4001+
elseif not FMI.checkFMIType(FMUType) then
4002+
success :=false;
4003+
outValue := Values.STRING("");
4004+
Error.addMessage(Error.UNKNOWN_FMU_TYPE, {FMUType});
4005+
return;
4006+
end if;
4007+
if not FMI.canExportFMU(FMUVersion, FMUType) then
4008+
success :=false;
4009+
outValue := Values.STRING("");
4010+
Error.addMessage(Error.FMU_EXPORT_NOT_SUPPORTED, {FMUType, FMUVersion});
4011+
return;
4012+
end if;
4013+
if Config.simCodeTarget() == "Cpp" and FMI.isFMICSType(FMUType) then
4014+
Error.addMessage(Error.FMU_EXPORT_NOT_SUPPORTED_CPP, {FMUType});
4015+
FMUType := "me";
4016+
end if;
4017+
4018+
// NOTE: The FMUs use fileNamePrefix for the internal name when it would be expected to be fileNamePrefix that decides the .fmu filename
4019+
// The scripting environment from a user's perspective is like that. fmuTargetName is the name of the .fmu in the templates, etc.
4020+
filenameprefix := Util.stringReplaceChar(if inFileNamePrefix == "<default>" then AbsynUtil.pathLastIdent(className) else inFileNamePrefix, ".", "_");
4021+
fmuTargetName := if FMUVersion == "1.0" then filenameprefix else (if inFileNamePrefix == "<default>" then AbsynUtil.pathLastIdent(className) else inFileNamePrefix);
4022+
if isSome(inSimSettings) then
4023+
SOME(simSettings) := inSimSettings;
4024+
else
4025+
defaultSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, filenameprefix, SOME(defaultSimulationOptions));
4026+
simSettings := convertSimulationOptionsToSimCode(defaultSimOpt);
4027+
end if;
4028+
FlagsUtil.setConfigBool(Flags.BUILDING_FMU, true);
4029+
FlagsUtil.setConfigString(Flags.FMI_VERSION, FMUVersion);
4030+
4031+
try
4032+
(success, cache, libs, _, _) := SimCodeMain.translateModel(SimCodeMain.TranslateModelKind.FMU(FMUType, fmuTargetName),
4033+
cache, inEnv, className, filenameprefix, true, false, true, SOME(simSettings));
4034+
outValue := Values.STRING((if not Testsuite.isRunning() then System.pwd() + Autoconf.pathDelimiter else "") + fmuTargetName + ".fmu");
4035+
else
4036+
success :=false;
4037+
outValue := Values.STRING("");
4038+
end try;
4039+
FlagsUtil.setConfigBool(Flags.BUILDING_FMU, false);
4040+
FlagsUtil.setConfigString(Flags.FMI_VERSION, "");
4041+
end callTranslateModelFMU;
4042+
39224043
protected function buildModelFMU
39234044
input FCore.Cache inCache;
39244045
input FCore.Graph inEnv;

OMEdit/OMEditLIB/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ set(OMEDITLIB_SOURCES Util/Helper.cpp
8787
TLM/TLMCoSimulationThread.cpp
8888
FMI/ImportFMUDialog.cpp
8989
FMI/ImportFMUModelDescriptionDialog.cpp
90+
FMI/FMUExportOutputWidget.cpp
9091
Plotting/VariablesWidget.cpp
9192
Plotting/DiagramWindow.cpp
9293
Options/NotificationsDialog.cpp
@@ -218,6 +219,7 @@ set(OMEDITLIB_HEADERS Util/Helper.h
218219
TLM/TLMCoSimulationThread.h
219220
FMI/ImportFMUDialog.h
220221
FMI/ImportFMUModelDescriptionDialog.h
222+
FMI/FMUExportOutputWidget.h
221223
Plotting/VariablesWidget.h
222224
Plotting/DiagramWindow.h
223225
Options/NotificationsDialog.h

0 commit comments

Comments
 (0)