Skip to content

Commit

Permalink
add oms_referenceResources() to switch the references
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 committed Aug 30, 2021
1 parent 4b004e3 commit 0c2904c
Show file tree
Hide file tree
Showing 13 changed files with 532 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace oms
virtual oms_status_enu_t setReal(const ComRef& cref, double value) { return logError_NotImplemented; }
virtual oms_status_enu_t setRealInputDerivative(const ComRef& cref, const SignalDerivative& der) { return logError_NotImplemented; }
virtual oms_status_enu_t stepUntil(double stopTime) { return oms_status_ok; }
virtual oms_status_enu_t newResources(const std::string& filename) { return logError_NotImplemented; }
virtual oms_status_enu_t newResources(const std::string& filename, bool externalResources) { return logError_NotImplemented; }
virtual oms_status_enu_t addResources(std::string& filename) { return logError_NotImplemented; }
virtual oms_status_enu_t deleteReferencesInSSD(const std::string& filename) {return logError_NotImplemented;}
virtual oms_status_enu_t deleteResourcesInSSP(const std::string& filename) {return logError_NotImplemented;}
Expand Down
4 changes: 3 additions & 1 deletion src/OMSimulatorLib/ComponentFMUCS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,19 @@ oms::ComRef oms::ComponentFMUCS::getValidCref(ComRef cref)
return tail;
}

oms_status_enu_t oms::ComponentFMUCS::newResources(const std::string& filename)
oms_status_enu_t oms::ComponentFMUCS::newResources(const std::string& filename, bool externalResources)
{
Values resources;
if (!values.hasResources())
{
resources.allresources[filename] = resources;
resources.isExternalSSV = externalResources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
values.parameterResources.push_back(resources);
}
else
{
// generate empty ssv file, if more resources are added to same level
resources.isExternalSSV = externalResources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
values.parameterResources[0].allresources[filename] = resources;
}

Expand Down
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/ComponentFMUCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace oms

void getFilteredSignals(std::vector<Connector>& filteredSignals) const;

oms_status_enu_t newResources(const std::string& filename);
oms_status_enu_t newResources(const std::string& filename, bool externalResources);
oms_status_enu_t setResourcesHelper1(Values value);
oms_status_enu_t setResourcesHelper2(Values value);

Expand Down
4 changes: 3 additions & 1 deletion src/OMSimulatorLib/ComponentFMUME.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,17 +710,19 @@ oms_status_enu_t oms::ComponentFMUME::doEventIteration()
return oms_status_ok;
}

oms_status_enu_t oms::ComponentFMUME::newResources(const std::string& filename)
oms_status_enu_t oms::ComponentFMUME::newResources(const std::string& filename, bool externalResources)
{
Values resources;
if (!values.hasResources())
{
resources.allresources[filename] = resources;
resources.isExternalSSV = externalResources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
values.parameterResources.push_back(resources);
}
else
{
// generate empty ssv file, if more resources are added to same level
resources.isExternalSSV = externalResources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
values.parameterResources[0].allresources[filename] = resources;
}

Expand Down
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/ComponentFMUME.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace oms

void getFilteredSignals(std::vector<Connector>& filteredSignals) const;

oms_status_enu_t newResources(const std::string& filename);
oms_status_enu_t newResources(const std::string& filename, bool externalResources);
oms_status_enu_t setResourcesHelper1(Values value);
oms_status_enu_t setResourcesHelper2(Values value);

Expand Down
11 changes: 11 additions & 0 deletions src/OMSimulatorLib/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,17 @@ oms_status_enu_t oms::Model::addResources(const oms::ComRef& cref, const std::st
return oms_status_ok;
}

oms_status_enu_t oms::Model::referenceResources(const oms::ComRef& cref)
{
ComRef subCref(cref);
std::string fileName = "resources/" + subCref.pop_suffix();

if (system)
return system->newResources(subCref, fileName, true);

return oms_status_ok;
}

oms_status_enu_t oms::Model::deleteReferencesInSSD(const oms::ComRef& cref)
{
ComRef subCref(cref);
Expand Down
1 change: 1 addition & 0 deletions src/OMSimulatorLib/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace oms
oms_status_enu_t addResources(const ComRef& cref, const std::string& path);
oms_status_enu_t deleteReferencesInSSD(const ComRef& cref);
oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
oms_status_enu_t referenceResources(const ComRef& cref);
oms_status_enu_t exportToSSD(Snapshot& snapshot) const;
oms_status_enu_t exportSnapshot(const ComRef& cref, char** contents);
oms_status_enu_t exportSSVTemplate(const ComRef& cref, const std::string& filename);
Expand Down
15 changes: 15 additions & 0 deletions src/OMSimulatorLib/OMSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ oms_status_enu_t oms_deleteResources(const char* cref_)
return model->deleteReferencesInSSD(tail);
}

oms_status_enu_t oms_referenceResources(const char* cref_)
{
oms::ComRef tail(cref_);
oms::ComRef front = tail.pop_front();

oms::ComRef modelCref(front);
modelCref.pop_suffix();

oms::Model* model = oms::Scope::GetInstance().getModel(modelCref);
if (!model)
return logError_ModelNotInScope(front);

return model->referenceResources(tail);
}

oms_status_enu_t oms_export(const char* cref, const char* filename)
{
return oms::Scope::GetInstance().exportModel(oms::ComRef(cref), std::string(filename));
Expand Down
1 change: 1 addition & 0 deletions src/OMSimulatorLib/OMSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ OMSAPI oms_status_enu_t OMSCALL oms_newResources(const char* cref);
OMSAPI oms_status_enu_t OMSCALL oms_removeSignalsFromResults(const char* cref, const char* regex);
OMSAPI oms_status_enu_t OMSCALL oms_rename(const char* cref, const char* newCref);
OMSAPI oms_status_enu_t OMSCALL oms_reset(const char* cref);
OMSAPI oms_status_enu_t OMSCALL oms_referenceResources(const char* cref);
OMSAPI oms_status_enu_t OMSCALL oms_RunFile(const char* filename);
OMSAPI oms_status_enu_t OMSCALL oms_setBoolean(const char* cref, bool value);
OMSAPI oms_status_enu_t OMSCALL oms_setBusGeometry(const char* bus, const ssd_connector_geometry_t* geometry);
Expand Down
13 changes: 7 additions & 6 deletions src/OMSimulatorLib/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ oms_status_enu_t oms::System::addSubModel(const oms::ComRef& cref, const std::st
return system->addSubModel(tail, path);
}

oms_status_enu_t oms::System::newResources(const ComRef& cref, const std::string& filename, bool isExternalresources)
oms_status_enu_t oms::System::newResources(const ComRef& cref, const std::string& filename, bool externalresources)
{
ComRef tail(cref);
ComRef front = tail.pop_front();
Expand All @@ -337,25 +337,25 @@ oms_status_enu_t oms::System::newResources(const ComRef& cref, const std::string
if (!values.hasResources())
{
resources.allresources[filename] = resources;
resources.isExternalSSV = isExternalresources;
resources.isExternalSSV = externalresources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
values.parameterResources.push_back(resources);
}
else
{
// generate empty ssv file, if more resources are added to same level
resources.isExternalSSV = isExternalresources;
resources.isExternalSSV = externalresources; // set if resources is "external" or "newResources", if "external" only references will be set in ssd
values.parameterResources[0].allresources[filename] = resources;
}
return oms_status_ok;
}

auto subsystem = subsystems.find(tail);
if (subsystem != subsystems.end())
return subsystem->second->newResources(tail, filename);
return subsystem->second->newResources(tail, filename, externalresources);

auto component = components.find(tail);
if (component != components.end())
return component->second->newResources(filename);
return component->second->newResources(filename, externalresources);

/*check for adding resources to components in subsystems
e.g root.system1.add
Expand All @@ -370,7 +370,7 @@ oms_status_enu_t oms::System::newResources(const ComRef& cref, const std::string

auto componentA = system->components.find(tailA);
if (componentA != components.end())
return componentA->second->newResources(filename);
return componentA->second->newResources(filename, externalresources);

return logError("failed for \"" + std::string(getFullCref() + cref) + "\"" + " as the identifier could not be resolved to a system or subsystem or component");
}
Expand Down Expand Up @@ -423,6 +423,7 @@ oms_status_enu_t oms::System::deleteResourcesInSSP(const std::string& filename)
return logError("failed to delete Resources in SSP because the filename \"" + filename + "\"" + " couldn't be resolved to any system or subsystem or component in the model");
}


oms_status_enu_t oms::System::listUnconnectedConnectors(char** contents) const
{
if (!contents)
Expand Down
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace oms
oms_status_enu_t setConnectorGeometry(const ComRef& cref, const oms::ssd::ConnectorGeometry* geometry);
oms_status_enu_t setConnectionGeometry(const ComRef &crefA, const ComRef &crefB, const oms::ssd::ConnectionGeometry* geometry);
oms_status_enu_t addBus(const ComRef& cref);
oms_status_enu_t newResources(const ComRef& cref, const std::string& filename, bool isExternalResources = false);
oms_status_enu_t newResources(const ComRef& cref, const std::string& filename, bool externalresources = false);
oms_status_enu_t addConnectorToBus(const ComRef& busCref, const ComRef& connectorCref);
oms_status_enu_t deleteConnectorFromBus(const ComRef& busCref, const ComRef& connectorCref);
oms_status_enu_t setBusGeometry(const ComRef& cref, const oms::ssd::ConnectorGeometry* geometry);
Expand Down
15 changes: 15 additions & 0 deletions src/OMSimulatorLua/OMSimulatorLua.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,20 @@ static int OMSimulatorLua_oms_newResources(lua_State *L)
return 1;
}

//oms_status_enu_t oms_referenceResources(const char* cref);
static int OMSimulatorLua_oms_referenceResources(lua_State *L)
{
if (lua_gettop(L) != 1)
return luaL_error(L, "expecting exactly 1 argument");
luaL_checktype(L, 1, LUA_TSTRING);

const char* cref = lua_tostring(L, 1);
oms_status_enu_t status = oms_referenceResources(cref);

lua_pushinteger(L, status);
return 1;
}

//oms_status_enu_t oms_addResources(const char* cref, const char* path);
static int OMSimulatorLua_oms_addResources(lua_State *L)
{
Expand Down Expand Up @@ -1346,6 +1360,7 @@ DLLEXPORT int luaopen_OMSimulatorLua(lua_State *L)
REGISTER_LUA_CALL(oms_removeSignalsFromResults);
REGISTER_LUA_CALL(oms_rename);
REGISTER_LUA_CALL(oms_reset);
REGISTER_LUA_CALL(oms_referenceResources);
REGISTER_LUA_CALL(oms_setBoolean);
REGISTER_LUA_CALL(oms_setCommandLineOption);
REGISTER_LUA_CALL(oms_setFixedStepSize);
Expand Down
Loading

0 comments on commit 0c2904c

Please sign in to comment.