use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class FlowSpecificationCreationUtil method getPotentialOwnersByFeature.
public static List<ComponentType> getPotentialOwnersByFeature(BusinessObjectContext featureBoc, final QueryService queryService) {
final Context context = getContext(featureBoc, queryService);
final Feature feature = (Feature) featureBoc.getBusinessObject();
final String childName = context == null ? feature.getName() : context.getName();
if (childName == null) {
return Collections.emptyList();
}
final BusinessObjectContext containerBoc = getFlowSpecificationOwnerBoc(featureBoc, queryService);
if (containerBoc == null) {
return Collections.emptyList();
}
final Element bo = (Element) containerBoc.getBusinessObject();
return AadlUiUtil.getPotentialClassifierTypesForEditing(bo).stream().filter(tmpBo -> canOwnFlowSpecification(tmpBo)).map(ComponentType.class::cast).filter(ct -> hasFeatureWithName(ct, childName)).collect(Collectors.toList());
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class CreateFlowPathSpecificationPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
final BusinessObjectContext srcBoc = ctx.getSource();
final Feature srcFeature = srcBoc.getBusinessObject(Feature.class).orElse(null);
final BusinessObjectContext dstBoc = ctx.getDestination();
final Feature dstFeature = dstBoc.getBusinessObject(Feature.class).orElse(null);
if (srcFeature == null || dstFeature == null) {
return Optional.empty();
}
final List<ComponentType> potentialOwners = getPotentialOwners(srcBoc, dstBoc, ctx.getQueryService());
if (potentialOwners.size() == 0 || !FlowSpecificationCreationUtil.isValidFlowEnd(dstFeature, dstBoc, DirectionType.OUT, ctx.getQueryService())) {
return Optional.empty();
}
final BusinessObjectContext container = FlowSpecificationCreationUtil.getFlowSpecificationOwnerBoc(srcBoc, ctx.getQueryService());
if (container == null) {
return Optional.empty();
}
return Optional.of(Operation.createWithBuilder(createOp -> {
AadlUiUtil.selectClassifier(createOp, potentialOwners).modifyPreviousResult(ct -> {
final FlowSpecification fs = ct.createOwnedFlowSpecification();
fs.setKind(FlowKind.PATH);
fs.setName(FlowSpecificationCreationUtil.getNewFlowSpecificationName(ct));
// Create the flow ends
final FlowEnd inFlowEnd = fs.createInEnd();
inFlowEnd.setFeature(srcFeature);
inFlowEnd.setContext(FlowSpecificationCreationUtil.getContext(srcBoc, ctx.getQueryService()));
final FlowEnd outFlowEnd = fs.createOutEnd();
outFlowEnd.setFeature(dstFeature);
outFlowEnd.setContext(FlowSpecificationCreationUtil.getContext(dstBoc, ctx.getQueryService()));
ct.setNoFlows(false);
return StepResultBuilder.create().showNewBusinessObject(container, fs).build();
});
}));
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class GoToTypeDiagramHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (!(activeEditor instanceof InternalDiagramEditor)) {
throw new RuntimeException("Unexpected editor: " + activeEditor);
}
// Get diagram and selected BOCs
final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
if (selectedBusinessObjectContexts.size() == 0) {
throw new RuntimeException("No element selected");
}
final Object bo = selectedBusinessObjectContexts.get(0).getBusinessObject();
final DiagramService diagramService = Objects.requireNonNull(Adapters.adapt(activeEditor, DiagramService.class), "Unable to retrieve diagram service");
final ComponentType ct = Objects.requireNonNull(getComponentType(bo), "Unable to retrieve component type");
;
diagramService.openOrCreateDiagramForBusinessObject(ct);
return null;
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class PasteAction method ensureBusinessObjectHasUniqueName.
/**
* If the element is renameable and the name can be validated, then generate a name that passes validation.
* Otherwise, do not change the element's name. Contains special handling for component implementations.
* @param bo
* @param boHandler
*/
private static void ensureBusinessObjectHasUniqueName(final EObject bo, final BusinessObjectHandler boHandler) {
if (supportsRenaming(bo, boHandler) && boHandler.canRename(new CanRenameContext(bo))) {
// Determine the current name of the business object.
final String originalName = boHandler.getNameForRenaming(new GetNameContext(bo));
// contain the component type / component type alias appropriate for the destination package.
if (bo instanceof ComponentImplementation) {
final ComponentImplementation ci = (ComponentImplementation) bo;
final ComponentType ct = ci.getType();
final ClassifierCreationHelper classifierCreationHelper = new ClassifierCreationHelper(ci.eResource().getResourceSet());
final String ciTypeName;
if (ct == null) {
ciTypeName = ci.getTypeName();
} else {
if (!AadlNameUtil.namesAreEqual(ci.getNamespace(), ct.getNamespace())) {
if (!(ci.getNamespace() instanceof PackageSection)) {
throw new RuntimeException("New component implementation is not contained in a package section");
}
final PackageSection section = (PackageSection) ci.getNamespace();
// Import the package if necessary
final AadlPackage typePkg = (AadlPackage) ct.getNamespace().getOwner();
AadlImportsUtil.addImportIfNeeded(section, typePkg);
// Create an alias for the component type
final ClassifierCreationHelper.RenamedTypeDetails aliasDetails = classifierCreationHelper.getRenamedType(section, typePkg, ct.getName());
if (!aliasDetails.exists) {
final ComponentTypeRename ctr = section.createOwnedComponentTypeRename();
ctr.setName(aliasDetails.aliasName);
ctr.setCategory(ct.getCategory());
ctr.setRenamedComponentType(ct);
}
ciTypeName = aliasDetails.aliasName;
} else {
ciTypeName = ct.getName();
}
}
setName(bo, boHandler, ciTypeName + ".osate_ge_temporary_name_00001");
} else {
// Set name to dummy name so that validate name will work as expected. Many implementations
// of validate name check if the name has changed.
setName(bo, boHandler, "");
}
// Determine a new name for the business object
final String baseName = originalName;
String newName = originalName;
int count = 1;
while (true) {
final String result = RenameUtil.checkNewNameValidity(bo, boHandler, newName);
if (result == null) {
break;
}
newName = baseName + "_copy" + (count == 1 ? "" : Integer.toString(count));
count++;
}
// specified value does not include the type name.
if (bo instanceof ComponentImplementation) {
newName = ((ComponentImplementation) bo).getTypeName() + "." + newName;
}
// Update the business object's name
setName(bo, boHandler, newName);
}
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project AGREE by loonwerks.
the class AgreeASTBuilder method getAgreeNode.
private AgreeNode getAgreeNode(ComponentInstance compInst, boolean isTop) {
List<AgreeVar> inputs = new ArrayList<>();
List<AgreeVar> outputs = new ArrayList<>();
List<AgreeVar> locals = new ArrayList<>();
List<AgreeAADLConnection> aadlConnections = new ArrayList<>();
List<AgreeOverriddenConnection> userDefinedConections = new ArrayList<>();
List<AgreeConnection> connections = new ArrayList<>();
List<AgreeNode> subNodes = new ArrayList<>();
List<AgreeStatement> assertions = new ArrayList<>();
List<AgreeStatement> assumptions = new ArrayList<>();
List<AgreeStatement> guarantees = new ArrayList<>();
List<AgreeStatement> lemmas = new ArrayList<>();
List<AgreeEquation> localEquations = new ArrayList<>();
List<AgreeStatement> patternProps = Collections.emptyList();
timeOfVarMap = new HashMap<>();
timeRiseVarMap = new HashMap<>();
timeFallVarMap = new HashMap<>();
unspecifiedAadlProperties = new HashMap<>();
Expr clockConstraint = new BoolExpr(true);
Expr initialConstraint = new BoolExpr(true);
String id = compInst.getName();
AgreeVar clockVar = new AgreeVar(id + clockIDSuffix, NamedType.BOOL, compInst.getSubcomponent(), compInst, null);
EObject reference = isTop ? compInst.getComponentClassifier() : compInst.getSubcomponent();
TimingModel timing = null;
boolean foundSubNode = false;
boolean hasDirectAnnex = false;
boolean hasSubcomponents = false;
ComponentClassifier compClass = compInst.getComponentClassifier();
Set<ComponentType> effectiveTypes = new HashSet<>();
Map<String, jkind.lustre.Expr> portRewriteMap = new HashMap<>();
if (compClass instanceof ComponentImplementation) {
boolean latched = false;
ComponentImplementation cc = (ComponentImplementation) compClass;
effectiveTypes.addAll(getEffectiveComponentTypes(cc.getType()));
if (isTop || isMonolithic) {
while (cc != null) {
AgreeContractSubclause annex = getAgreeAnnex(cc);
for (ComponentInstance subInst : compInst.getComponentInstances()) {
hasSubcomponents = true;
curInst = subInst;
AgreeNode subNode = getAgreeNode(subInst, false);
if (subNode != null && subNodes.stream().noneMatch(it -> it.reference.equals(subNode.reference))) {
foundSubNode = true;
subNodes.add(subNode);
}
}
if (annex != null) {
hasDirectAnnex = true;
AgreeContract contract = (AgreeContract) annex.getContract();
curInst = compInst;
assertions.addAll(getAssertionStatements(contract.getSpecs()));
getEquationStatements(contract.getSpecs(), portRewriteMap).addAllTo(locals, assertions, guarantees);
assertions.addAll(getPropertyStatements(contract.getSpecs()));
assertions.addAll(getAssignmentStatements(contract.getSpecs()));
userDefinedConections.addAll(getConnectionStatements(contract.getSpecs()));
lemmas.addAll(getLemmaStatements(contract.getSpecs()));
lemmas.addAll(getReachableStatements(contract.getSpecs(), portRewriteMap));
addLustreNodes(contract.getSpecs());
gatherLustreTypes(contract.getSpecs());
// the clock constraints contain other nodes that we add
clockConstraint = getClockConstraint(contract.getSpecs(), subNodes);
timing = getTimingModel(contract.getSpecs());
outputs.addAll(getEquationVars(contract.getSpecs(), compInst));
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof LatchedStatement) {
latched = true;
break;
}
}
}
// Find extended effective types
effectiveTypes.addAll(getEffectiveComponentTypes(cc.getType()));
cc = cc.getExtended();
}
EList<ConnectionInstance> connectionInstances = compInst.getAllEnclosingConnectionInstances();
List<ConnectionInstance> foo = new ArrayList<>();
compInst.getAllComponentInstances().forEach(ci -> ci.allEnclosingConnectionInstances().forEach(foo::add));
aadlConnections.addAll(getConnectionsFromInstances(connectionInstances, compInst, subNodes, latched));
connections.addAll(filterConnections(aadlConnections, userDefinedConections));
}
ComponentType compType = ((ComponentImplementation) compClass).getType();
AgreeContractSubclause compImpAnnex = getAgreeAnnex(compClass);
if (compImpAnnex != null) {
AgreeContract contract = (AgreeContract) compImpAnnex.getContract();
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof LiftContractStatement) {
Subcomponent sub = ((ComponentImplementation) compClass).getOwnedSubcomponents().get(0);
ComponentType ct = sub.getComponentType();
for (Connection conn : ((ComponentImplementation) compClass).getAllConnections()) {
NamedElement sourceNe = conn.getSource().getConnectionEnd();
NamedElement destNe = conn.getDestination().getConnectionEnd();
String sourceStr = sourceNe.getName().replace("::", "__");
String destStr = destNe.getName().replace("::", "__");
if (ct == sourceNe.getContainingClassifier()) {
portRewriteMap.put(sourceStr, new IdExpr(destStr));
} else if (ct == destNe.getContainingClassifier()) {
portRewriteMap.put(destStr, new IdExpr(sourceStr));
}
}
effectiveTypes.addAll(getEffectiveComponentTypes(ct));
}
}
}
// make compClass the type so we can get it's other contract elements
compClass = compType;
} else if (compClass instanceof ComponentType) {
effectiveTypes.addAll(getEffectiveComponentTypes((ComponentType) compClass));
} else {
throw new AgreeException("Internal error: attempt to run AGREE analysis on instance " + compInst.getFullName() + " not instance of ComponentImplementation or ComponentType.");
}
curInst = compInst;
if (timing == null) {
timing = TimingModel.SYNC;
}
for (ComponentType compType : effectiveTypes) {
AgreeContractSubclause annex = getAgreeAnnex(compType);
if (annex != null) {
hasDirectAnnex = true;
AgreeContract contract = (AgreeContract) annex.getContract();
// this makes files for monolithic verification a bit smaller
if (!isMonolithic || isTop || !hasSubcomponents) {
assumptions.addAll(getAssumptionStatements(contract.getSpecs(), portRewriteMap));
guarantees.addAll(getGuaranteeStatements(contract.getSpecs(), portRewriteMap));
lemmas.addAll(getReachableStatements(contract.getSpecs(), portRewriteMap));
}
// Count eq statements with expressions as assertions
getEquationStatements(contract.getSpecs(), portRewriteMap).addAllTo(locals, assertions, guarantees);
assertions.addAll(getPropertyStatements(contract.getSpecs()));
outputs.addAll(getEquationVars(contract.getSpecs(), compInst));
getAgreeInputVars(contract.getSpecs(), compInst).addAllTo(inputs, assumptions, guarantees);
initialConstraint = getInitialConstraint(contract.getSpecs());
addLustreNodes(contract.getSpecs());
gatherLustreTypes(contract.getSpecs());
}
}
gatherUnspecifiedAadlProperties(unspecifiedAadlProperties, inputs, assumptions, guarantees);
if (!(foundSubNode || hasDirectAnnex)) {
return null;
}
gatherOutputsInputsAndTypes(outputs, inputs, compInst.getFeatureInstances(), assumptions, guarantees);
AgreeNodeBuilder builder = new AgreeNodeBuilder(id);
builder.addInput(inputs);
builder.addOutput(outputs);
builder.addLocal(locals);
builder.addLocalEquation(localEquations);
builder.addConnection(connections);
builder.addSubNode(subNodes);
// Clean up any vacuous true predicates
Predicate<AgreeStatement> isBoolExprAndisTrue = st -> (st.expr instanceof BoolExpr) && ((BoolExpr) st.expr).value;
assertions.removeIf(isBoolExprAndisTrue);
assumptions.removeIf(isBoolExprAndisTrue);
guarantees.removeIf(isBoolExprAndisTrue);
builder.addAssertion(assertions);
builder.addAssumption(assumptions);
builder.addGuarantee(guarantees);
builder.addLemma(lemmas);
builder.addPatternProp(patternProps);
builder.setClockConstraint(clockConstraint);
builder.setInitialConstraint(initialConstraint);
builder.setClockVar(clockVar);
builder.setReference(reference);
builder.setTiming(timing);
builder.setCompInst(compInst);
builder.addTimeOf(timeOfVarMap);
builder.addTimeRise(timeRiseVarMap);
builder.addTimeFall(timeFallVarMap);
AgreeNode result = builder.build();
renamings.put(id, compInst.getName());
refMap.put(id, compInst);
return linearizationRewriter.visit(result);
}
Aggregations