From 5ba38b5e49dcda5b382dcf489f58c1606a5dbe5f Mon Sep 17 00:00:00 2001 From: Andreea Nechita <57031264+andreea-nechita@users.noreply.github.com> Date: Wed, 29 Apr 2026 23:20:07 +0100 Subject: [PATCH 1/4] Updated SimulinkElement.java to add new constructor --- .../model/element/SimulinkElement.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/element/SimulinkElement.java b/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/element/SimulinkElement.java index 21ca712a38..8266a1e877 100644 --- a/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/element/SimulinkElement.java +++ b/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/element/SimulinkElement.java @@ -32,6 +32,34 @@ public abstract class SimulinkElement extends SimulinkModelElement { protected static final String GET_HANDLE_PROPERTY = "get_param(handle, '?');"; protected Double handle = null; + + // Used when creating a new block on a given path + public SimulinkElement(SimulinkModel model, MatlabEngine engine, String type, String destPath) throws MatlabRuntimeException { + super(model, engine); + try { + String parentSysPath; + + // If the path to the parent (sub)system is not provided, create the block + // at the top level of the Simulink model. This should be consistent with + // the behaviour exhibited when re-parenting blocks + if (destPath != null && !destPath.isEmpty()) { + parentSysPath = destPath; + } else { + parentSysPath = model.getSimulinkModelName(); + } + + this.handle = (Double) engine.evalWithResult(ADD_BLOCK_MAKE_NAME_UNIQUE_ON, type, + parentSysPath + "/" + SimulinkUtil.getSimpleTypeName(type)); + } catch (Exception e) { + e.printStackTrace(); + throw new MatlabRuntimeException("Unable to create block element"); + } + try { + setType(); + } catch (MatlabException e) { + throw new MatlabRuntimeException("Unable to set up the type"); + } + } // Used when creating blocks public SimulinkElement(SimulinkModel model, MatlabEngine engine, String type) throws MatlabRuntimeException { From 23fd0b71477778d475a256cd743deffb182bacb8 Mon Sep 17 00:00:00 2001 From: Andreea Nechita <57031264+andreea-nechita@users.noreply.github.com> Date: Wed, 29 Apr 2026 23:20:49 +0100 Subject: [PATCH 2/4] Update SimulinkBlock.java with new constructor --- .../epsilon/emc/simulink/model/element/SimulinkBlock.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/element/SimulinkBlock.java b/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/element/SimulinkBlock.java index 5349d0bdfb..1080284206 100644 --- a/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/element/SimulinkBlock.java +++ b/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/element/SimulinkBlock.java @@ -45,6 +45,10 @@ public class SimulinkBlock extends SimulinkElement { * @throws EolRuntimeException */ + public SimulinkBlock(SimulinkModel model, MatlabEngine engine, String type, String destPath) throws MatlabRuntimeException { + super(model, engine, type, destPath); + } + public SimulinkBlock(SimulinkModel model, MatlabEngine engine, Double handle) throws MatlabRuntimeException { super(model, engine, handle); } From 2d5283c3448b23da4e1c131fe11bca084f8f04dd Mon Sep 17 00:00:00 2001 From: Andreea Nechita <57031264+andreea-nechita@users.noreply.github.com> Date: Wed, 29 Apr 2026 23:21:34 +0100 Subject: [PATCH 3/4] Update SimulinkModel.java to add parametrised instance creation --- .../eclipse/epsilon/emc/simulink/model/SimulinkModel.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/SimulinkModel.java b/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/SimulinkModel.java index 1cf2856941..e2ecafb5c3 100644 --- a/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/SimulinkModel.java +++ b/plugins/org.eclipse.epsilon.emc.simulink/src/org/eclipse/epsilon/emc/simulink/model/SimulinkModel.java @@ -240,6 +240,13 @@ public Object createInstance(String type, Collection parameters) } catch (EolRuntimeException e) { throw new EolModelElementTypeNotFoundException(type, null, e.getMessage()); } + } else if (type.contains("/") && parameters.size() == 1) { + Object parentPath = parameters.toArray()[0]; + try { + return new SimulinkBlock(this, engine, type, (String) parentPath); + } catch (MatlabRuntimeException e) { + throw new EolNotInstantiableModelElementTypeException(getSimulinkModelName(), type); + } } throw new EolModelElementTypeNotFoundException(type, null); } From 6f1aaf67639cea7ff5bc3adb05a6dce5437be0a1 Mon Sep 17 00:00:00 2001 From: Andreea Nechita <57031264+andreea-nechita@users.noreply.github.com> Date: Wed, 29 Apr 2026 23:22:27 +0100 Subject: [PATCH 4/4] Update createSimpleSimulation.eol --- .../create/createSimpleSimulation.eol | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/org.eclipse.epsilon.emc.simulink.examples/create/createSimpleSimulation.eol b/examples/org.eclipse.epsilon.emc.simulink.examples/create/createSimpleSimulation.eol index 9f17a640d2..772a6092e7 100644 --- a/examples/org.eclipse.epsilon.emc.simulink.examples/create/createSimpleSimulation.eol +++ b/examples/org.eclipse.epsilon.emc.simulink.examples/create/createSimpleSimulation.eol @@ -13,6 +13,19 @@ assert(BusCreator.all.size() = 1); var scope = new `simulink/Sinks/Scope`; assert(Scope.all.size() = 1); +// Test creating a new block within an existing subsystem +var subsys = new `simulink/Ports & Subsystems/Subsystem`; +subsys.name = "TestSubsystem"; +var childSubsys = new `simulink/Ports & Subsystems/Subsystem`(subsys.path); +assert(childSubsys.parent.path == subsys.path); + +// Test creating a new block on an empty path (this is expected +// to create the block at the top level of the model) +var blockAtTopLevel = new `simulink/Commonly Used Blocks/In1`(null); +var anotherBlockAtTopLevel = new `simulink/Commonly Used Blocks/Out1`(""); +assert(blockAtTopLevel.parent == null); +assert(anotherBlockAtTopLevel.parent == null); + sineWave.position = "[100 100 130 130]"; assert(sineWave.position.at(0) = 100); assert(sineWave.position.at(1) = 100); @@ -54,4 +67,4 @@ gain.link(saturation); // TODO TESTS saturation.link(busCreator); // TODO TESTS gain.linkTo(busCreator, 2); // TODO TESTS sineWave.linkTo(busCreator, 3); // TODO TESTS -busCreator.link(scope); // TODO TESTS \ No newline at end of file +busCreator.link(scope); // TODO TESTS