Skip to content

Commit

Permalink
Add options --ignore-hide-result and -ignoreHideResult to Cpp runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Oct 23, 2021
1 parent 6402d9b commit c49166f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
Expand Up @@ -36,6 +36,7 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
int refIdx = -1;
boost::optional<int> refIdxOpt;
std::regex filterRegex(_globalSettings->getVariableFilter());
EmitResults emitResults = _globalSettings->getEmitResults();
try
{
ptree tree;
Expand Down Expand Up @@ -70,16 +71,18 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
bool isAlias = aliasInfo.compare("alias") == 0;
bool isNegatedAlias = aliasInfo.compare("negatedAlias") == 0;

bool emitResult = std::regex_match(name, filterRegex);
if (_globalSettings->getEmitResults() == EMIT_NONE)
emitResult = false;
else if (_globalSettings->getEmitResults() != EMIT_ALL)
{
if (name.substr(0, 3) == "_D_")
emitResult = false;
std::string hideResultInfo = vars.second.get<std::string>("<xmlattr>.hideResult");
if (hideResultInfo.compare("true") == 0)
emitResult = false;
bool emitResult = false;
if (emitResults != EMIT_NONE) {
emitResult = std::regex_match(name, filterRegex);
if (emitResults != EMIT_ALL) {
boost::optional<string> isProtectedOpt = vars.second.get_optional<string>("<xmlattr>.isProtected");
bool isProtected = isProtectedOpt && *isProtectedOpt == "true";
boost::optional<string> hideResultOpt = vars.second.get_optional<string>("<xmlattr>.hideResult");
bool hideResultIsTrue = hideResultOpt && *hideResultOpt == "true";
bool hideResultIsFalse = hideResultOpt && *hideResultOpt == "false";
emitResult &= emitResults == EMIT_HIDDEN || !hideResultIsTrue;
emitResult &= emitResults == EMIT_PROTECTED || (!isProtected || (emitResults != EMIT_HIDDEN && hideResultIsFalse));
}
}

FOREACH(ptree::value_type const& var, vars.second.get_child(""))
Expand Down
Expand Up @@ -31,7 +31,7 @@ enum LogFormat {LF_TXT = 0, LF_FMI = 1, LF_FMI2 = 2, LF_XML = 3, LF_XMLTCP = 4};
enum LogOMEdit {LOG_EVENTS = 0, LOG_INIT, LOG_LS, LOG_NLS, LOG_SOLVER, LOG_STATS};
enum OutputPointType {OPT_ALL, OPT_STEP, OPT_NONE};
enum OutputFormat {CSV, MAT, BUFFER, EMPTY};
enum EmitResults {EMIT_ALL, EMIT_PUBLIC, EMIT_NONE};
enum EmitResults {EMIT_ALL, EMIT_HIDDEN, EMIT_PROTECTED, EMIT_PUBLIC, EMIT_NONE};

struct LogSettings
{
Expand Down
Expand Up @@ -318,7 +318,8 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
"csv", CSV MAP_LIST_SEP "mat", MAT MAP_LIST_SEP
"buffer", BUFFER MAP_LIST_SEP "empty", EMPTY MAP_LIST_END;
map<string, EmitResults> emitResultsMap = MAP_LIST_OF
"all", EMIT_ALL MAP_LIST_SEP "public", EMIT_PUBLIC MAP_LIST_SEP
"all", EMIT_ALL MAP_LIST_SEP "hidden", EMIT_HIDDEN MAP_LIST_SEP
"protected", EMIT_PROTECTED MAP_LIST_SEP "public", EMIT_PUBLIC MAP_LIST_SEP
"none", EMIT_NONE MAP_LIST_END;
po::options_description desc("Allowed options");

Expand Down Expand Up @@ -349,7 +350,8 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
("alarm,A", po::value<unsigned int >()->default_value(360), "sets timeout in seconds for simulation")
("output-type,O", po::value< string >()->default_value("all"), "the points in time written to result file: all (output steps + events), step (just output points), none")
("output-format,P", po::value< string >()->default_value("mat"), "simulation results output format: csv, mat, buffer, empty")
("emit-results,U", po::value< string >()->default_value("public"), "emit results: all, public, none")
("emit-results,U", po::value< string >()->default_value("public"), "emit results: all, hidden, protected, public, none")
("ignore-hide-result", po::bool_switch()->default_value(false), "ignore HideResult annotations")
("variable-filter,B", po::value< string >()->default_value(".*"), "only write variables that match filter")
;

Expand Down Expand Up @@ -502,6 +504,19 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
throw ModelicaSimulationError(MODEL_FACTORY,
"Unknown emit-results " + emitResults_str);
}
if (vm.count("ignore-hide-result") && vm["ignore-hide-result"].as<bool>())
{
switch (emitResults) {
case EMIT_NONE:
case EMIT_PUBLIC:
emitResults = EMIT_HIDDEN;
break;
case EMIT_PROTECTED:
emitResults = EMIT_ALL;
default:
break;
}
}

string variableFilter = ".*";
if (vm.count("variable-filter"))
Expand Down Expand Up @@ -592,7 +607,8 @@ void OMCFactory::fillArgumentsToReplace()
_argumentsToReplace.insert(pair<string,string>("-logFormat", "log-format"));
_argumentsToReplace.insert(pair<string,string>("-port", "log-port"));
_argumentsToReplace.insert(pair<string,string>("-alarm", "alarm"));
_argumentsToReplace.insert(pair<string,string>("-emit_protected", "emit-results all"));
_argumentsToReplace.insert(pair<string,string>("-emit_protected", "emit-results protected"));
_argumentsToReplace.insert(pair<string,string>("-ignoreHideResult", "ignore-hide-result"));
_argumentsToReplace.insert(pair<string,string>("-inputPath", "input-path"));
_argumentsToReplace.insert(pair<string,string>("-outputPath", "output-path"));
}
Expand Down

0 comments on commit c49166f

Please sign in to comment.