use of org.geotoolkit.sml.xml.v100.Classifier in project alisa-examples by osate.
the class ModelVerifications method sameVoltage.
public static boolean sameVoltage(ComponentInstance ci) {
EList<FeatureInstance> inlets = new BasicEList<FeatureInstance>();
for (FeatureInstance fi : ci.getAllFeatureInstances(FeatureCategory.ABSTRACT_FEATURE)) {
Classifier cl = fi.getFeature().getAllClassifier();
if (cl.getName().equalsIgnoreCase("power")) {
inlets.add(fi);
}
}
if (inlets.size() == 2) {
double v1 = getVoltage(inlets.get(0));
double v2 = getVoltage(inlets.get(1));
return v1 == v2;
}
return false;
}
use of org.geotoolkit.sml.xml.v100.Classifier in project AGREE by loonwerks.
the class VerifyHandler method getComponentImplementation.
protected ComponentImplementation getComponentImplementation(Element root, EphemeralImplementationUtil implUtil) {
Classifier classifier = getOutermostClassifier(root);
if (isRealizability()) {
if (!(classifier instanceof ComponentType)) {
throw new AgreeException("Must select an AADL Component Type");
}
ComponentImplementation result;
try {
result = implUtil.generateEphemeralCompImplFromType((ComponentType) classifier);
} catch (Exception e) {
e.printStackTrace();
throw new AgreeException("Error creating component implementation.");
}
return result;
} else {
if (classifier instanceof ComponentImplementation) {
return (ComponentImplementation) classifier;
}
if (!(classifier instanceof ComponentType)) {
throw new AgreeException("Must select an AADL Component Type or Implementation");
}
ComponentType ct = (ComponentType) classifier;
List<ComponentImplementation> cis = getComponentImplementations(ct);
if (cis.size() == 0) {
throw new AgreeException("AADL Component Type has no implementation to verify");
} else if (cis.size() == 1) {
ComponentImplementation ci = cis.get(0);
Shell shell = getWindow().getShell();
String message = "User selected " + ct.getFullName() + ".\nRunning analysis on " + ci.getFullName() + " instead.";
shell.getDisplay().asyncExec(() -> MessageDialog.openInformation(shell, "Analysis information", message));
return ci;
} else {
throw new AgreeException("AADL Component Type has multiple implementations to verify: please select just one");
}
}
}
use of org.geotoolkit.sml.xml.v100.Classifier in project AGREE by loonwerks.
the class MATLABFunctionHandler method runJob.
@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
Classifier classifier = getOutermostClassifier(root);
if (!(classifier instanceof ComponentType)) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Must select an AADL Component Type");
}
ComponentType ct = (ComponentType) classifier;
ComponentImplementation ci = null;
EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
try {
SystemInstance si = implUtil.generateEphemeralCompInstanceFromType(ct);
ComponentType sysType = AgreeUtils.getInstanceType(si);
EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (annexSubClauses.size() == 0) {
throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
}
// Get Agree program
AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
if (agreeProgram.containsRealTimePatterns) {
throw new AgreeException("'" + sysType.getName() + "' system type contains AGREE Real Time Patterns." + " Export of AGREE Real Time Patterns NOT Supported - they are considered scheduling properties" + " of components and can be decomposed further.");
}
// Translate Agree Node to Lustre Node with pre-statement flatten, helper nodes inlined,
// and variable declarations sorted so they are declared before use
Node lustreNode = AgreeNodeToLustreContract.translate(agreeProgram.topNode, agreeProgram);
// Translate Lustre Node to MATLAB Function AST
MATLABPrimaryFunction matlabFunction = LustreToMATLABTranslator.translate(lustreNode, agreeProgram);
ModelInfo info = getModelInfo(ct);
if (info == null) {
// return;
return Status.CANCEL_STATUS;
}
String dirStr = info.outputDirPath;
if (dirStr == null || dirStr.isEmpty()) {
// return;
return Status.CANCEL_STATUS;
}
boolean exportContractsPressed = info.exportPressed;
boolean genImplPressed = info.generatePressed;
boolean genVerificationPressed = info.updatePressed;
boolean verifySubsysPressed = info.verifyPressed;
String matlabFuncScriptName = matlabFunction.name + ".m";
if (genImplPressed) {
// Write MATLAB script to generate subsystem in the selected
// output folder
String subsysName = "";
if (info.subsystemName.equals("")) {
subsysName = sysType.getName();
} else {
subsysName = info.subsystemName;
}
MdlScriptCreator implMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, subsysName, matlabFunction.ports, matlabFuncScriptName, true, info.verifyPressed);
String implMdlScriptName = "generate_" + subsysName + ".m";
// generate the script to create the impl model file into the path specified for the model
File implMdlFile = new File(info.implMdlPath);
String implMdlDir = implMdlFile.getParent();
if (implMdlDir != null) {
Path implMdlScriptPath = Paths.get(implMdlDir, implMdlScriptName);
writeToFile(implMdlScriptPath, implMdlScript.toString());
}
}
if (exportContractsPressed || genVerificationPressed || verifySubsysPressed) {
Path matlabFuncScriptPath = Paths.get(dirStr, matlabFuncScriptName);
// Write MATLAB function code into the specified file in the
// selected output folder
writeToFile(matlabFuncScriptPath, matlabFunction.toString());
if (genVerificationPressed || verifySubsysPressed) {
// Create Simulink Model Update script into the output
// folder
MdlScriptCreator verifMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, info.subsystemName, matlabFunction.ports, matlabFuncScriptName, false, info.verifyPressed);
String verifMdlScriptName = matlabFunction.name + "_Observer.m";
Path verifMdlScriptPath = Paths.get(dirStr, verifMdlScriptName);
writeToFile(verifMdlScriptPath, verifMdlScript.toString());
}
}
// return;
return Status.OK_STATUS;
} catch (Throwable e) {
String messages = getNestedMessages(e);
e.printStackTrace();
Dialog.showError("AGREE Error", e.toString());
// return;
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
if (ci != null) {
ci.eResource().getContents().remove(ci);
}
implUtil.cleanup();
}
}
use of org.geotoolkit.sml.xml.v100.Classifier in project AGREE by loonwerks.
the class AgreeValidator method checkAssume.
@Check(CheckType.FAST)
public void checkAssume(AssumeStatement assume) {
Classifier comp = assume.getContainingClassifier();
if (!(comp instanceof ComponentType)) {
error(assume, "Assume statements are allowed only in component types");
}
// the expression could be null if a pattern is used
Expr expr = assume.getExpr();
if (expr != null) {
TypeDef exprType = AgreeTypeSystem.infer(expr);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
error(assume, "Expression for assume statement is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'bool'");
}
}
if (assume.getName() == null) {
info(assume, "It is recommended that assume statements be named." + " (Hint: an identifier may be placed between the \"assume\" keyword and the quoted description.)");
}
}
use of org.geotoolkit.sml.xml.v100.Classifier in project AGREE by loonwerks.
the class AgreeValidator method checkOrderStatement.
@Check(CheckType.FAST)
public void checkOrderStatement(OrderStatement order) {
Classifier container = order.getContainingClassifier();
if (container instanceof ComponentImplementation) {
ComponentImplementation compImpl = (ComponentImplementation) container;
for (int index = 0; index < order.getComps().size(); ++index) {
NamedElement comp = order.getComps().get(index);
if (!(comp instanceof Subcomponent) || !((Subcomponent) comp).getContainingComponentImpl().equals(container)) {
error("Element '" + comp.getName() + "' is not a subcomponent of '" + container.getName() + "'", order, AgreePackage.Literals.ORDER_STATEMENT__COMPS, index);
}
}
List<NamedElement> notPresent = new ArrayList<>();
for (Subcomponent subcomp : compImpl.getAllSubcomponents()) {
boolean found = false;
for (NamedElement el : order.getComps()) {
if (el.equals(subcomp)) {
found = true;
break;
}
}
if (!found) {
notPresent.add(subcomp);
}
}
if (notPresent.size() != 0) {
String delim = "";
StringBuilder errorStr = new StringBuilder("The following subcomponents are not present in the ordering: ");
for (NamedElement subcomp : notPresent) {
errorStr.append(delim);
errorStr.append(subcomp.getName());
delim = ", ";
}
error(order, errorStr.toString());
}
} else {
error(order, "Ordering statements can appear only in component implementations");
}
}
Aggregations