There has been a question in the forum some time ago, why "mediniGetTracedElements()" does not work on Simulink elements. Well, the reason is mainly that it has a different inheritance hierarchy in EMF and does not (for historical reasons) inherit the right base class. The question now was, whether such a feature could be realized as a script itself. I would like to present one solution here:
At first the implementation of the function itself. It is working, but only in case the other end of the trace has the "mediniGetTracedElements" function:
/*
* Implement MediniObject.mediniGetTracedElements for Simulink objects.
*/
function mediniGetTracedElements(object, type, name) {
return finder.findByType(type).filter(function (elem) {
if (!elem["mediniGetTracedElements"]) {
return false;
}
return elem.mediniGetTracedElements(object.prototype, name).contains(object);
}).asList();
}
The request is basically reversed and search from the other end using the finder in the first place. Sample code may look like this:
finder.findByType("SimulinkBlock").forEach(function (block) {
var opp = mediniGetTracedElements(block, Metamodel.safetygoals.SafetyRequirement, null);
if (opp.size()) {
console.log("Block: {0} has {1} traced requirements", block.name, opp.size());
}
});
Note that we use "Simulink" here because the package is also not part of the "Metamodel" singleton, but that's a different story.
Happy Scripting
Jan