@@ -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 ;
39203919end 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+
39224043protected function buildModelFMU
39234044 input FCore . Cache inCache;
39244045 input FCore . Graph inEnv;
0 commit comments