Skip to content

Commit

Permalink
Allow OspModelDescription to be located at model path (#556)
Browse files Browse the repository at this point in the history
* looking for ospModelDescr at model path

* moving modelDescriptions #462

* check for file uri #462

* Testing OspModelDescriptions at both allowed locations #462
  • Loading branch information
ljamt authored Apr 17, 2020
1 parent dc8dc3c commit 7c5731b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/cpp/cse_config_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cse/function/vector_sum.hpp"
#include <cse/exception.hpp>
#include <cse/log/logger.hpp>
#include <cse/uri.hpp>
#include <cse/utility/utility.hpp>

#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -590,7 +591,8 @@ struct extended_model_description
}
}

static variable_group_description create_variable_group_description(xercesc::DOMElement *variableGroupElement) {
static variable_group_description create_variable_group_description(xercesc::DOMElement* variableGroupElement)
{
variable_group_description variableGroupDescription;

variableGroupDescription.name = tc(variableGroupElement->getAttribute(tc("name").get())).get();
Expand Down Expand Up @@ -924,7 +926,7 @@ void connect_vector_sum_functions(
execution.connect_variables(
function_io_id{fn, variable_type::real, vector_sum_function<double>::out_io_reference(i)},
targetVariable);
}
}
}
}

Expand Down Expand Up @@ -996,9 +998,26 @@ std::pair<execution, simulator_map> load_cse_config(
}

std::string msmiFileName = model->description()->name + "_OspModelDescription.xml";
const auto msmiFilePath = configFile.parent_path() / msmiFileName;
if (boost::filesystem::exists(msmiFilePath)) {
emds.emplace(simulator.name, msmiFilePath);
const auto modelUri = resolve_reference(baseURI, simulator.source);
boost::filesystem::path msmiFilePath;

if (modelUri.scheme() == "file") {
msmiFilePath = file_uri_to_path(modelUri).remove_leaf() / msmiFileName;
if (boost::filesystem::exists(msmiFilePath)) {
emds.emplace(simulator.name, msmiFilePath);
} else {
msmiFilePath = configFile.parent_path() / msmiFileName;
if (boost::filesystem::exists(msmiFilePath)) {
emds.emplace(simulator.name, msmiFilePath);
}
}
} else {
// Makes it possible to keep OspModelDescription at configuration path
// even when there are FMUs with other URI than file (fmu-proxy).
msmiFilePath = configFile.parent_path() / msmiFileName;
if (boost::filesystem::exists(msmiFilePath)) {
emds.emplace(simulator.name, msmiFilePath);
}
}
}

Expand Down

0 comments on commit 7c5731b

Please sign in to comment.