diff --git a/OMCompiler/Compiler/NSimCode/NSimCode.mo b/OMCompiler/Compiler/NSimCode/NSimCode.mo index 57fac108f30..ec274498105 100644 --- a/OMCompiler/Compiler/NSimCode/NSimCode.mo +++ b/OMCompiler/Compiler/NSimCode/NSimCode.mo @@ -270,7 +270,7 @@ public // old SimCode strcutures Absyn.Program program; list libs, includes, includeDirs, libPaths; - String directory; + String fileName, directory; OldSimCodeFunction.MakefileParams makefileParams; list functions; list recordDecls; @@ -396,8 +396,12 @@ public (jac_blocks, simCodeIndices) := SimStrongComponent.Block.fixIndices(jac_blocks, {}, simCodeIndices); generic_loop_calls := list(SimGenericCall.fromIdentifier(tpl) for tpl in UnorderedMap.toList(simCodeIndices.generic_call_map)); - - (modelInfo, simCodeIndices) := ModelInfo.create(vars, name, directory, functions, linearLoops, nonlinearLoops, bdae.eventInfo, simCodeIndices); + try + Absyn.CLASS(info = SOURCEINFO(fileName = fileName)) := InteractiveUtil.getPathedClassInProgram(name, program); + else + fileName := ""; + end try; + (modelInfo, simCodeIndices) := ModelInfo.create(vars, name, fileName, directory, functions, linearLoops, nonlinearLoops, bdae.eventInfo, simCodeIndices); simCode := SIM_CODE( modelInfo = modelInfo, @@ -567,6 +571,7 @@ public uniontype ModelInfo record MODEL_INFO Absyn.Path name; + String fileName; String description; String directory; SimVars vars; @@ -595,6 +600,7 @@ public function create input SimVars vars; input Absyn.Path name; + input String fileName; input String directory; input list functions; input list linearLoops; @@ -606,7 +612,7 @@ public VarInfo info; algorithm info := VarInfo.create(vars, eventInfo, simCodeIndices); - modelInfo := MODEL_INFO(name, "", directory, vars, info, functions, {}, {}, {}, 0, 0, 0, true, linearLoops, nonlinearLoops); + modelInfo := MODEL_INFO(name, fileName, "", directory, vars, info, functions, {}, {}, {}, 0, 0, 0, true, linearLoops, nonlinearLoops); end create; function setSeedVars @@ -635,6 +641,7 @@ public varInfo := VarInfo.convert(modelInfo.varInfo); oldModelInfo := OldSimCode.MODELINFO( name = modelInfo.name, + fileName = modelInfo.fileName, description = modelInfo.description, directory = modelInfo.directory, varInfo = VarInfo.convert(modelInfo.varInfo), diff --git a/OMCompiler/Compiler/Script/CevalScriptBackend.mo b/OMCompiler/Compiler/Script/CevalScriptBackend.mo index ac5913a16e3..5a60d827030 100644 --- a/OMCompiler/Compiler/Script/CevalScriptBackend.mo +++ b/OMCompiler/Compiler/Script/CevalScriptBackend.mo @@ -3468,7 +3468,6 @@ protected function callTranslateModel output String outFileDir; output list> resultValues; algorithm - (success, outCache, outStringLst, outFileDir, resultValues) := SimCodeMain.translateModel(SimCodeMain.TranslateModelKind.NORMAL(), inCache, inEnv, className, inFileNamePrefix, runBackend, Flags.getConfigBool(Flags.DAE_MODE), runSilent, inSimSettingsOpt, Absyn.FUNCTIONARGS({},{})); @@ -4187,12 +4186,10 @@ protected function translateModelXML " author: Alachew protected Boolean success; algorithm - (success,cache) := SimCodeMain.translateModel(SimCodeMain.TranslateModelKind.XML(), cache, env, className, - fileNamePrefix, true, false, true, inSimSettingsOpt); + (success,cache) := SimCodeMain.translateModel(SimCodeMain.TranslateModelKind.XML(), cache, env, className, fileNamePrefix, true, false, true, inSimSettingsOpt); outValue := Values.STRING(if success then ((if not Testsuite.isRunning() then System.pwd() + Autoconf.pathDelimiter else "") + fileNamePrefix+".xml") else ""); end translateModelXML; - public function translateGraphics "function: translates the graphical annotations from old to new version" input Absyn.Path className; input Absyn.Msg inMsg; diff --git a/OMCompiler/Compiler/SimCode/SimCode.mo b/OMCompiler/Compiler/SimCode/SimCode.mo index b6f7d7eca96..dfe21b1fcb7 100644 --- a/OMCompiler/Compiler/SimCode/SimCode.mo +++ b/OMCompiler/Compiler/SimCode/SimCode.mo @@ -262,6 +262,7 @@ end BaseUnit; uniontype ModelInfo "Container for metadata about a Modelica model." record MODELINFO Absyn.Path name; + String fileName; String description; String directory; VarInfo varInfo; diff --git a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo index ec643f640e8..2a06259bfac 100644 --- a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo +++ b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo @@ -121,6 +121,7 @@ import ZeroCrossings; import ReduceDAE; import Settings; import UnorderedSet; +import InteractiveUtil; protected constant String UNDERLINE = "========================================"; @@ -7676,7 +7677,7 @@ public function createModelInfo input list tempVars; output SimCode.ModelInfo modelInfo; protected - String description, directory; + String fileName, description, directory; SimCode.VarInfo varInfo; SimCodeVar.SimVars vars; Integer nx, ny, ndy, np, na, next, numOutVars, numInVars, ny_int, np_int, na_int, ny_bool, np_bool, dim_1, dim_2, numOptimizeConstraints, numOptimizeFinalConstraints, numRealInputVars; @@ -7721,7 +7722,8 @@ algorithm if debug then execStat("simCode: createVarInfo"); end if; hasLargeEqSystems := hasLargeEquationSystems(dlow, inInitDAE); if debug then execStat("simCode: hasLargeEquationSystems"); end if; - modelInfo := SimCode.MODELINFO(class_, dlow.shared.info.description, directory, varInfo, vars, functions, + Absyn.CLASS(info = SOURCEINFO(fileName = fileName)) := InteractiveUtil.getPathedClassInProgram(class_, program); + modelInfo := SimCode.MODELINFO(class_, fileName, dlow.shared.info.description, directory, varInfo, vars, functions, labels, if Flags.getConfigBool(Flags.BUILDING_FMU) then getResources(program.classes, dlow, inInitDAE) else {}, List.sort(program.classes, AbsynUtil.classNameGreater), @@ -16045,5 +16047,16 @@ algorithm end match; end getExpNominal; +public function isMocFile + input String fileName; + output Integer result; +algorithm + if (StringUtil.endsWith(fileName, ".moc")) then + result := 1; + else + result := 0; + end if; +end isMocFile; + annotation(__OpenModelica_Interface="backend"); end SimCodeUtil; diff --git a/OMCompiler/Compiler/Template/CodegenC.tpl b/OMCompiler/Compiler/Template/CodegenC.tpl index 33c7052d423..f0ccab42111 100644 --- a/OMCompiler/Compiler/Template/CodegenC.tpl +++ b/OMCompiler/Compiler/Template/CodegenC.tpl @@ -1470,6 +1470,7 @@ template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String gu data->modelData->resultFileName = NULL; data->modelData->modelDir = "<%directory%>"; data->modelData->modelGUID = "{<%guid%>}"; + data->modelData->encrypted = <%SimCodeUtil.isMocFile(fileName)%>; <% match isModelExchangeFMU case "1.0" then << diff --git a/OMCompiler/Compiler/Template/SimCodeTV.mo b/OMCompiler/Compiler/Template/SimCodeTV.mo index a91d7323c8f..5d3db83d261 100644 --- a/OMCompiler/Compiler/Template/SimCodeTV.mo +++ b/OMCompiler/Compiler/Template/SimCodeTV.mo @@ -766,6 +766,7 @@ package SimCode uniontype ModelInfo record MODELINFO Absyn.Path name; + String fileName; String description; String directory; VarInfo varInfo; @@ -1432,6 +1433,11 @@ package SimCodeUtil input DAE.Exp exp; output DAE.Exp nom; end getExpNominal; + + function isMocFile + input String fileName; + output Integer result; + end isMocFile; end SimCodeUtil; package SimCodeFunctionUtil diff --git a/OMCompiler/SimulationRuntime/c/simulation/simulation_input_xml.c b/OMCompiler/SimulationRuntime/c/simulation/simulation_input_xml.c index c76144c784e..e155a55ef4e 100644 --- a/OMCompiler/SimulationRuntime/c/simulation/simulation_input_xml.c +++ b/OMCompiler/SimulationRuntime/c/simulation/simulation_input_xml.c @@ -617,10 +617,10 @@ void read_input_xml(MODEL_DATA* modelData, * the check is like this: * - we filter if isProtected (protected variables) * - we filter if annotation(HideResult=true) - * - we emit (remove filtering) if emitProtected && isProtected + * - we emit (remove filtering) if !encrypted && emitProtected && isProtected * - we emit (remove filtering) if ignoreHideResult && annotation(HideResult=true) */ -#define setFilterOuput(v, s, n) \ +#define setFilterOuput(v, s, n, e) \ { \ int ep = omc_flag[FLAG_EMIT_PROTECTED]; \ int ihr = omc_flag[FLAG_IGNORE_HIDERESULT]; \ @@ -638,7 +638,7 @@ void read_input_xml(MODEL_DATA* modelData, infoStreamPrint(LOG_DEBUG, 0, "filtering variable %s due to HideResult annotation", (n)); \ (s).filterOutput = 1; \ } \ - if (ep && ipcmptrue) \ + if (!e && ep && ipcmptrue) \ { \ infoStreamPrint(LOG_DEBUG, 0, "emitting protected variable %s due to flag %s", (n), omc_flagValue[FLAG_EMIT_PROTECTED]); \ (s).filterOutput = 0; \ @@ -651,7 +651,7 @@ void read_input_xml(MODEL_DATA* modelData, } /* read all static data from File for every variable */ -#define READ_VARIABLES(out, in, attributeKind, read_var_attribute, debugName, start, nStates, mapAlias) \ +#define READ_VARIABLES(out, in, attributeKind, read_var_attribute, debugName, start, nStates, mapAlias, e) \ infoStreamPrint(LOG_DEBUG, 1, "read xml file for %s", debugName); \ for(i = 0; i < nStates; i++) \ { \ @@ -661,7 +661,7 @@ void read_input_xml(MODEL_DATA* modelData, omc_ScalarVariable *v = *findHashLongVar(in, i); \ read_var_info(v, info); \ read_var_attribute(v, attribute); \ - setFilterOuput(v, out[j], info->name); \ + setFilterOuput(v, out[j], info->name, e); \ addHashStringLong(&mapAlias, info->name, j); /* create a mapping for Alias variable to get the correct index */ \ debugStreamPrint(LOG_DEBUG, 0, "real %s: mapAlias[%s] = %ld", debugName, info->name, (long) j); \ if (omc_flag[FLAG_IDAS] && 0 == strcmp(debugName, "real sensitivities")) \ @@ -677,22 +677,22 @@ void read_input_xml(MODEL_DATA* modelData, } \ messageClose(LOG_DEBUG); - READ_VARIABLES(modelData->realVarsData,mi.rSta,REAL_ATTRIBUTE,read_var_attribute_real,"real states",0,modelData->nStates,mapAlias); - READ_VARIABLES(modelData->realVarsData,mi.rDer,REAL_ATTRIBUTE,read_var_attribute_real,"real state derivatives",modelData->nStates,modelData->nStates,mapAlias); - READ_VARIABLES(modelData->realVarsData,mi.rAlg,REAL_ATTRIBUTE,read_var_attribute_real,"real algebraics",2*modelData->nStates,modelData->nVariablesReal - 2*modelData->nStates,mapAlias); + READ_VARIABLES(modelData->realVarsData,mi.rSta,REAL_ATTRIBUTE,read_var_attribute_real,"real states",0,modelData->nStates,mapAlias,modelData->encrypted); + READ_VARIABLES(modelData->realVarsData,mi.rDer,REAL_ATTRIBUTE,read_var_attribute_real,"real state derivatives",modelData->nStates,modelData->nStates,mapAlias,modelData->encrypted); + READ_VARIABLES(modelData->realVarsData,mi.rAlg,REAL_ATTRIBUTE,read_var_attribute_real,"real algebraics",2*modelData->nStates,modelData->nVariablesReal - 2*modelData->nStates,mapAlias,modelData->encrypted); - READ_VARIABLES(modelData->integerVarsData,mi.iAlg,INTEGER_ATTRIBUTE,read_var_attribute_int,"integer variables",0,modelData->nVariablesInteger,mapAlias); - READ_VARIABLES(modelData->booleanVarsData,mi.bAlg,BOOLEAN_ATTRIBUTE,read_var_attribute_bool,"boolean variables",0,modelData->nVariablesBoolean,mapAlias); - READ_VARIABLES(modelData->stringVarsData,mi.sAlg,STRING_ATTRIBUTE,read_var_attribute_string,"string variables",0,modelData->nVariablesString,mapAlias); + READ_VARIABLES(modelData->integerVarsData,mi.iAlg,INTEGER_ATTRIBUTE,read_var_attribute_int,"integer variables",0,modelData->nVariablesInteger,mapAlias,modelData->encrypted); + READ_VARIABLES(modelData->booleanVarsData,mi.bAlg,BOOLEAN_ATTRIBUTE,read_var_attribute_bool,"boolean variables",0,modelData->nVariablesBoolean,mapAlias,modelData->encrypted); + READ_VARIABLES(modelData->stringVarsData,mi.sAlg,STRING_ATTRIBUTE,read_var_attribute_string,"string variables",0,modelData->nVariablesString,mapAlias,modelData->encrypted); - READ_VARIABLES(modelData->realParameterData,mi.rPar,REAL_ATTRIBUTE,read_var_attribute_real,"real parameters",0,modelData->nParametersReal,mapAliasParam); - READ_VARIABLES(modelData->integerParameterData,mi.iPar,INTEGER_ATTRIBUTE,read_var_attribute_int,"integer parameters",0,modelData->nParametersInteger,mapAliasParam); - READ_VARIABLES(modelData->booleanParameterData,mi.bPar,BOOLEAN_ATTRIBUTE,read_var_attribute_bool,"boolean parameters",0,modelData->nParametersBoolean,mapAliasParam); - READ_VARIABLES(modelData->stringParameterData,mi.sPar,STRING_ATTRIBUTE,read_var_attribute_string,"string parameters",0,modelData->nParametersString,mapAliasParam); + READ_VARIABLES(modelData->realParameterData,mi.rPar,REAL_ATTRIBUTE,read_var_attribute_real,"real parameters",0,modelData->nParametersReal,mapAliasParam,modelData->encrypted); + READ_VARIABLES(modelData->integerParameterData,mi.iPar,INTEGER_ATTRIBUTE,read_var_attribute_int,"integer parameters",0,modelData->nParametersInteger,mapAliasParam,modelData->encrypted); + READ_VARIABLES(modelData->booleanParameterData,mi.bPar,BOOLEAN_ATTRIBUTE,read_var_attribute_bool,"boolean parameters",0,modelData->nParametersBoolean,mapAliasParam,modelData->encrypted); + READ_VARIABLES(modelData->stringParameterData,mi.sPar,STRING_ATTRIBUTE,read_var_attribute_string,"string parameters",0,modelData->nParametersString,mapAliasParam,modelData->encrypted); if (omc_flag[FLAG_IDAS]) { - READ_VARIABLES(modelData->realSensitivityData,mi.rSen,REAL_ATTRIBUTE,read_var_attribute_real,"real sensitivities",0, modelData->nSensitivityVars,mapAliasSen); + READ_VARIABLES(modelData->realSensitivityData,mi.rSen,REAL_ATTRIBUTE,read_var_attribute_real,"real sensitivities",0, modelData->nSensitivityVars,mapAliasSen,modelData->encrypted); } /* @@ -712,7 +712,7 @@ void read_input_xml(MODEL_DATA* modelData, } infoStreamPrint(LOG_DEBUG, 0, "read for %s negated %d from setup file", modelData->realAlias[i].info.name, modelData->realAlias[i].negate); - setFilterOuput(*findHashLongVar(mi.rAli,i), modelData->realAlias[i], modelData->realAlias[i].info.name); + setFilterOuput(*findHashLongVar(mi.rAli,i), modelData->realAlias[i], modelData->realAlias[i].info.name, modelData->encrypted); free((char*)aliasTmp); aliasTmp = NULL; @@ -758,7 +758,7 @@ void read_input_xml(MODEL_DATA* modelData, infoStreamPrint(LOG_DEBUG, 0, "read for %s negated %d from setup file",modelData->integerAlias[i].info.name,modelData->integerAlias[i].negate); - setFilterOuput(*findHashLongVar(mi.iAli,i), modelData->integerAlias[i], modelData->integerAlias[i].info.name); + setFilterOuput(*findHashLongVar(mi.iAli,i), modelData->integerAlias[i], modelData->integerAlias[i].info.name, modelData->encrypted); free((char*)aliasTmp); aliasTmp = NULL; @@ -802,7 +802,7 @@ void read_input_xml(MODEL_DATA* modelData, infoStreamPrint(LOG_DEBUG, 0, "read for %s negated %d from setup file", modelData->booleanAlias[i].info.name, modelData->booleanAlias[i].negate); - setFilterOuput(*findHashLongVar(mi.bAli,i), modelData->booleanAlias[i], modelData->booleanAlias[i].info.name); + setFilterOuput(*findHashLongVar(mi.bAli,i), modelData->booleanAlias[i], modelData->booleanAlias[i].info.name, modelData->encrypted); free((char*)aliasTmp); aliasTmp = NULL; @@ -845,7 +845,7 @@ void read_input_xml(MODEL_DATA* modelData, } infoStreamPrint(LOG_DEBUG, 0, "read for %s negated %d from setup file", modelData->stringAlias[i].info.name, modelData->stringAlias[i].negate); - setFilterOuput(*findHashLongVar(mi.sAli,i), modelData->stringAlias[i], modelData->stringAlias[i].info.name); + setFilterOuput(*findHashLongVar(mi.sAli,i), modelData->stringAlias[i], modelData->stringAlias[i].info.name, modelData->encrypted); free((char*)aliasTmp); aliasTmp = NULL; diff --git a/OMCompiler/SimulationRuntime/c/simulation_data.h b/OMCompiler/SimulationRuntime/c/simulation_data.h index d72dbd20dd3..dd7ed282eb3 100644 --- a/OMCompiler/SimulationRuntime/c/simulation_data.h +++ b/OMCompiler/SimulationRuntime/c/simulation_data.h @@ -563,6 +563,7 @@ typedef struct MODEL_DATA char* resultFileName; /* default is _res.mat, but it can be overriden using -r= */ const char* modelDir; const char* modelGUID; + modelica_boolean encrypted; const char* initXMLData; char* resourcesDir; /* Resources directory, only set for FMUs */ modelica_boolean runTestsuite; /* true if this model was generated during testing */ diff --git a/OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp b/OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp index 025a69443cb..9103dbbeb21 100644 --- a/OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp +++ b/OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp @@ -609,11 +609,13 @@ void VariablesTreeModel::parseInitXml(QXmlStreamReader &xmlReader, SimulationOpt bool hideResultIsFalse = scalarVariable.value("hideResult").compare(QStringLiteral("false")) == 0; bool isProtected = scalarVariable.value("isProtected").compare(QStringLiteral("true")) == 0; /* Skip variables, - * 1. If ignoreHideResult is not set and hideResult is true. - * 2. If emit protected flag is false and variable is protected. + * 1. If encrytped model. + * 2. If ignoreHideResult is not set and hideResult is true. + * 3. If emit protected flag is false and variable is protected. * If hideResult is false for protected variable then we show it. */ - if ((ignoreHideResult || !hideResultIsTrue) + if (!simulationOptions.getFileName().endsWith(".moc") + && (ignoreHideResult || !hideResultIsTrue) && (protectedVariables || (!isProtected || (!ignoreHideResult && hideResultIsFalse)))) { mScalarVariablesHash.insert(scalarVariable.value("name"),scalarVariable); if (addVariablesToList) { diff --git a/OMEdit/OMEditLIB/Simulation/SimulationDialog.cpp b/OMEdit/OMEditLIB/Simulation/SimulationDialog.cpp index f7795e5aa23..11faccc4e80 100644 --- a/OMEdit/OMEditLIB/Simulation/SimulationDialog.cpp +++ b/OMEdit/OMEditLIB/Simulation/SimulationDialog.cpp @@ -503,7 +503,7 @@ void SimulationDialog::setUpForm() mpVariableFilterHelpButton->setToolTip(tr("Variable Filter help")); connect(mpVariableFilterHelpButton, SIGNAL(clicked()), SLOT(showVariableFilterHelp())); // Protected Variabels - mpProtectedVariablesCheckBox = new QCheckBox(tr("Protected Variables")); + mpProtectedVariablesCheckBox = new QCheckBox(tr("Protected Variables if not encrypted")); // ignore hide result mpIgnoreHideResultCheckBox = new QCheckBox(tr("Ignore HideResult")); // Equidistant time grid diff --git a/doc/UsersGuide/source/omedit.rst b/doc/UsersGuide/source/omedit.rst index 96c19fb9895..3d794dc5da6 100644 --- a/doc/UsersGuide/source/omedit.rst +++ b/doc/UsersGuide/source/omedit.rst @@ -855,7 +855,7 @@ Output - *Variable Filter (Optional)* - only output variables with names fully matching the regular expression. -- *Protected Variables* - adds the protected variables in result file. +- *Protected Variables if not encrypted* - adds the protected variables in result file. - *Equidistant Time Grid -* output the internal steps given by dassl instead of interpolating results into an equidistant time grid as given by stepSize or @@ -1446,7 +1446,7 @@ General Options - *Show Protected Classes* - If enabled then Libraries Browser will also list the protected classes. - - *Show Hidden Classes* - If enabled then Libraries Browser will also list the hidden classes. + - *Show Hidden Classes if not encrypted* - If enabled then Libraries Browser will also list the hidden classes. Ignores the annotation(Protection(access = Access.hide)) - *Synchronize with Model Widget* - If enabled then Libraries Browser will scroll automatically