Skip to content

Commit

Permalink
Fixing #78 by adding check for name collision
Browse files Browse the repository at this point in the history
  • Loading branch information
imbur committed Jul 10, 2018
1 parent 2a30332 commit f0fb2ef
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,25 @@ public void export(SimulinkModel model, MatlabCommandFactory commandFactory) thr

String modelFQN = getFQN(model);

// TODO do not close, open the model if able instead
// Before the new system creation, close the possibly open model
// MatlabCommand closeSystem = commandFactory.closeSystem().addParam(modelFQN);
// closeSystem.execute();
boolean modelAlreadyExists = Handle.getHandleData(commandFactory.exist().addParam(modelFQN).execute()) > 0.5;
int existValue = Handle.getHandleData(commandFactory.exist().addParam(modelFQN).execute()).intValue();
boolean modelAlreadyExists = existValue == 4;
if(modelAlreadyExists){
MatlabCommand loadSystem = commandFactory.loadSytem();
loadSystem.addParam(modelFQN).execute();
} else {
MatlabCommand newSystem = commandFactory.newSytem();
newSystem.addParam(modelFQN);
if (model.isLibrary()) {
newSystem.addParam("Library");
}
newSystem.execute();
} else {
if (existValue == 0) {
MatlabCommand newSystem = commandFactory.newSytem();
newSystem.addParam(modelFQN);
if (model.isLibrary()) {
newSystem.addParam("Library");
}
newSystem.execute();
} else {
logger.error("Model name collides with a MATLAB object name. 'exist' return status: " + existValue
+ System.getProperty("line.separator") + "See > help exist in MATLAB for details");
return;

}
}

BusSignalMapper mapper = new BusSignalMapper(model.eResource().getResourceSet());
Expand Down

0 comments on commit f0fb2ef

Please sign in to comment.