Skip to content

Commit

Permalink
Creation of an accelerator for concretization of computed function
Browse files Browse the repository at this point in the history
allocation.
  • Loading branch information
ebausson-obeo authored and pdulth committed Sep 4, 2023
1 parent 3c32690 commit 0aa8934
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,22 @@
</with>
</or>
</definition>
<definition
id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation.expression">
<or>
<with
variable="selection">
<iterate
ifEmpty="false">
<test
forcePluginActivation="true"
property="org.polarsys.capella.core.platform.sirius.ui.actionMode"
value="concretizeFunctionAllocation">
</test>
</iterate>
</with>
</or>
</definition>

<definition
id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.PropagateExchangeItemAllocations.expression">
Expand Down Expand Up @@ -500,6 +516,15 @@
</reference>
</visibleWhen>
</command>
<command
commandId="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation">
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation.expression">
</reference>
</visibleWhen>
</command>



Expand Down Expand Up @@ -730,6 +755,12 @@
id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.PropagateExchangeItemAllocations"
name="%PropagateEIOnPorts">
</command>
<command
categoryId="org.polarsys.capella.core.accelerators"
defaultHandler="org.polarsys.capella.core.platform.sirius.ui.handlers.ConcretizeFunctionAllocationHandler"
id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation"
name="Concretize Function Allocation">
</command>

<command
categoryId="org.polarsys.capella.core.accelerators"
Expand Down Expand Up @@ -801,6 +832,10 @@
commandId="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.SynchronizeExchangeItemAllocations"
icon="platform:/plugin/org.polarsys.capella.core.ui.resources/icons/full/obj16/capella_process.gif">
</image>
<image
commandId="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation"
icon="platform:/plugin/org.polarsys.capella.core.ui.resources/icons/full/obj16/capella_process.gif">
</image>

<image
commandId="org.polarsys.capella.core.platform.sirius.ui.actions.wizard.AllocationManagementWizardAction"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2023 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales Global Services - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.platform.sirius.ui.actions;

import org.eclipse.core.runtime.IProgressMonitor;
import org.polarsys.capella.common.ef.command.ICommand;
import org.polarsys.capella.core.platform.sirius.ui.commands.ConcretizeFunctionAllocationCommand;

/**
* Action for the ConcretizeFunctionAllocation accelerator
*
* @author ebausson
*/
public class ConcretizeFunctionAllocationAction extends AbstractFixAction {

@Override
protected ICommand createCommand(IProgressMonitor progressMonitor) {
return new ConcretizeFunctionAllocationCommand(getSelectedElements());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2023 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales Global Services - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.platform.sirius.ui.commands;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.util.EList;
import org.polarsys.capella.common.data.modellingcore.ModelElement;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.ctx.SystemFunction;
import org.polarsys.capella.core.data.fa.AbstractFunction;
import org.polarsys.capella.core.data.fa.AbstractFunctionalBlock;
import org.polarsys.capella.core.data.fa.ComponentFunctionalAllocation;
import org.polarsys.capella.core.data.fa.FaFactory;
import org.polarsys.capella.core.data.helpers.fa.services.FunctionExt;
import org.polarsys.capella.core.data.la.LogicalFunction;
import org.polarsys.capella.core.data.pa.PhysicalFunction;
import org.polarsys.capella.core.model.helpers.AbstractFunctionExt;

/**
* Command for the ConcretizeFunctionAllocation accelerator
*
* @author ebausson
*/
public class ConcretizeFunctionAllocationCommand extends AbstractFixCommand {

public ConcretizeFunctionAllocationCommand(Collection<ModelElement> selection) {
super(selection);
}

@Override
protected void process(ModelElement element) {
if ((element instanceof LogicalFunction) || (element instanceof SystemFunction) || (element instanceof PhysicalFunction)) {
AbstractFunction motherFunction = (AbstractFunction) element;
Component component = resolveMotherFunctionAllocation(motherFunction);
if (component != null) {
createAlloction(component, motherFunction);
}
}
}

private Component resolveMotherFunctionAllocation(AbstractFunction motherFunction) {
List<Component> motherFunctionAllocation = new ArrayList<Component>();
// In case the function is a leaf, there are already
// two queries that do the job:
// - Function Actor Allocation
// - Function Component Allocation
if (!FunctionExt.isLeaf(motherFunction)) {
// Check block allocation
EList<AbstractFunctionalBlock> blockAllocations = motherFunction.getAllocationBlocks();

// If mother is already allocated, there are already queries
// that do the job so only get the leaves allocation in case the
// mother is not already allocated
if ((null == blockAllocations) || blockAllocations.isEmpty()) {
motherFunctionAllocation.addAll(AbstractFunctionExt.getMotherFunctionAllocation(motherFunction));
if (motherFunctionAllocation.size() == 1) {
return AbstractFunctionExt.getMotherFunctionAllocation(motherFunction).get(0);
}
}
}
return null;
}

private void createAlloction(Component component, AbstractFunction function) {
ComponentFunctionalAllocation allocation = FaFactory.eINSTANCE.createComponentFunctionalAllocation();
if (component != null) {
allocation.setSourceElement(component);
allocation.setTargetElement(function);
component.getOwnedFunctionalAllocation().add(allocation);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2023 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales Global Services - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.platform.sirius.ui.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.polarsys.capella.common.ui.services.commands.ActionCommandDelegate;
import org.polarsys.capella.core.platform.sirius.ui.actions.ConcretizeFunctionAllocationAction;

/**
* Handler for the ConcretizeFunctionAllocation accelerator,
*
* Delegate event handling and determine accelerator visibility.
* @author ebausson
*/
public class ConcretizeFunctionAllocationHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ActionCommandDelegate delegate = new ActionCommandDelegate(event);
ConcretizeFunctionAllocationAction action = new ConcretizeFunctionAllocationAction();
action.selectionChanged(delegate, HandlerUtil.getCurrentSelection(event));
action.run(delegate);
return null;
}

@Override
public boolean isEnabled() {
ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getSelectionProvider().getSelection();
return (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2020 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2023 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -13,16 +13,23 @@
package org.polarsys.capella.core.platform.sirius.ui;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.emf.common.util.EList;
import org.polarsys.capella.common.data.modellingcore.ModelElement;
import org.polarsys.capella.common.ui.actions.ModelAdaptation;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.ctx.SystemFunction;
import org.polarsys.capella.core.data.epbs.ConfigurationItem;
import org.polarsys.capella.core.data.fa.AbstractFunction;
import org.polarsys.capella.core.data.fa.AbstractFunctionalBlock;
import org.polarsys.capella.core.data.fa.ComponentExchange;
import org.polarsys.capella.core.data.fa.FunctionalExchange;
import org.polarsys.capella.core.data.helpers.fa.services.FunctionExt;
import org.polarsys.capella.core.data.information.datavalue.LiteralNumericValue;
import org.polarsys.capella.core.data.la.LogicalFunction;
import org.polarsys.capella.core.data.pa.PhysicalFunction;
import org.polarsys.capella.core.model.helpers.AbstractFunctionExt;
import org.polarsys.capella.core.model.utils.CapellaLayerCheckingExt;

/**
Expand All @@ -34,6 +41,7 @@ public class ActionPropertyTester extends PropertyTester {
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[],
* java.lang.Object)
*/
@Override
public boolean test(Object object_p, String propertyName_p, Object[] params_p, Object testedValue_p) {
boolean result = false;
if (propertyName_p.equals("actionMode") || propertyName_p.equals("graphicalActionMode")) { //$NON-NLS-1$ //$NON-NLS-2$
Expand All @@ -54,6 +62,9 @@ public boolean test(Object object_p, String propertyName_p, Object[] params_p, O
if ("propagationPortRealizationsFromCE".equals(actionName)) { //$NON-NLS-1$
return isPropagationPortRealizationsFromCE(element);
}
if ("concretizeFunctionAllocation".equals(actionName)) { //$NON-NLS-1$
return isConcretizableFunctionAllocation(element);
}
if ("convertClassPrimitive".equals(actionName)) { //$NON-NLS-1$
return isConvertPrimitive(element);
}
Expand Down Expand Up @@ -143,6 +154,19 @@ private boolean isPropagationPortRealizationsFromFE(ModelElement element_p) {
return result;
}

private boolean isConcretizableFunctionAllocation(ModelElement element) {
if ((element instanceof LogicalFunction) || (element instanceof SystemFunction) || (element instanceof PhysicalFunction)) {
AbstractFunction motherFunction = (AbstractFunction) element;
if (!FunctionExt.isLeaf(motherFunction)) {
EList<AbstractFunctionalBlock> blockAllocations = motherFunction.getAllocationBlocks();
if ((null == blockAllocations) || blockAllocations.isEmpty()) {
return AbstractFunctionExt.getMotherFunctionAllocation(motherFunction).size() == 1;
}
}
}
return false;
}

/**
* @param element_p
* @return
Expand Down

0 comments on commit 0aa8934

Please sign in to comment.