Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
busCreator.link(scope); // TODO TESTS
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ public Object createInstance(String type, Collection<Object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading