Skip to content

Commit

Permalink
Read all values from init.xml, ticket:4089
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Oct 24, 2016
1 parent c58bee3 commit 295a040
Showing 1 changed file with 36 additions and 43 deletions.
79 changes: 36 additions & 43 deletions SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
Expand Up @@ -59,16 +59,6 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
if (descriptonOpt)
descripton = *descriptonOpt;

if (_globalSettings->getEmitResults() != EMIT_ALL)
{
if (name.substr(0, 3) == "_D_")
continue;
std::string hideResultInfo = vars.second.get<std::string>("<xmlattr>.hideResult");
if (hideResultInfo.compare("true") == 0)
// Note: we don't need values of hidden variables because the code calculates them
continue;
}

refIdx = *refIdxOpt;
std::string aliasInfo = vars.second.get<std::string>("<xmlattr>.alias");
std::string variabilityInfo = vars.second.get<std::string>("<xmlattr>.variability");
Expand All @@ -77,6 +67,18 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
bool isAlias = aliasInfo.compare("alias") == 0;
bool isNegatedAlias = aliasInfo.compare("negatedAlias") == 0;

bool emitResult = true;
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;
}

FOREACH(ptree::value_type const& var, vars.second.get_child(""))
{
if (var.first == "Real")
Expand All @@ -91,10 +93,13 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
}
const double& realVar = sim_vars->getRealVar(refIdx);
const double* realVarPtr = &realVar;
if (isParameter)
_realVars.addParameter(name,descripton,realVarPtr);
else
_realVars.addOutputVar(name,descripton,realVarPtr,isNegatedAlias);
if (emitResult)
{
if (isParameter)
_realVars.addParameter(name, descripton, realVarPtr);
else
_realVars.addOutputVar(name, descripton, realVarPtr, isNegatedAlias);
}
}
else if (var.first == "Integer")
{
Expand All @@ -108,10 +113,13 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
}
const int& intVar = sim_vars->getIntVar(refIdx);
const int* intVarPtr = &intVar;
if (isParameter)
_intVars.addParameter(name,descripton,intVarPtr);
else
_intVars.addOutputVar(name,descripton,intVarPtr,isNegatedAlias);
if (emitResult)
{
if (isParameter)
_intVars.addParameter(name, descripton, intVarPtr);
else
_intVars.addOutputVar(name, descripton, intVarPtr, isNegatedAlias);
}
}
else if (var.first == "Boolean")
{
Expand All @@ -125,10 +133,13 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
}
const bool& boolVar = sim_vars->getBoolVar(refIdx);
const bool* boolVarPtr = &boolVar;
if (isParameter)
_boolVars.addParameter(name,descripton,boolVarPtr);
else
_boolVars.addOutputVar(name,descripton,boolVarPtr,isNegatedAlias);
if (emitResult)
{
if (isParameter)
_boolVars.addParameter(name, descripton, boolVarPtr);
else
_boolVars.addOutputVar(name, descripton, boolVarPtr, isNegatedAlias);
}
}
else if (var.first == "String")
{
Expand Down Expand Up @@ -159,42 +170,24 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa

const output_int_vars_t& XmlPropertyReader::getIntOutVars()
{
static output_int_vars_t int_none;
if (_isInitialized)
{
if (_globalSettings->getEmitResults() == EMIT_NONE)
return int_none;
else
return _intVars;
}
return _intVars;
else
throw ModelicaSimulationError(UTILITY, "init xml file has not been read");
}

const output_real_vars_t& XmlPropertyReader::getRealOutVars()
{
static output_real_vars_t real_none;
if (_isInitialized)
{
if (_globalSettings->getEmitResults() == EMIT_NONE)
return real_none;
else
return _realVars;
}
return _realVars;
else
throw ModelicaSimulationError(UTILITY, "init xml file has not been read");
}

const output_bool_vars_t& XmlPropertyReader::getBoolOutVars()
{
static output_bool_vars_t bool_none;
if (_isInitialized)
{
if (_globalSettings->getEmitResults() == EMIT_NONE)
return bool_none;
else
return _boolVars;
}
return _boolVars;
else
throw ModelicaSimulationError(UTILITY, "init xml file has not been read");
}
Expand Down

0 comments on commit 295a040

Please sign in to comment.