Commit a70d7a6d authored by Hernan Ponce de Leon's avatar Hernan Ponce de Leon
Browse files

Merge branch '3464-MCDC_requirements' into '3477-MCDC_implementation'

3464 mcdc requirements

See merge request !60
parents a9a9d0af 82dad5df
......@@ -268,7 +268,10 @@
<extension
point="org.fortiss.tooling.kernel.ui.contextMenuContribution">
<contextMenuContribution
contributor="org.fortiss.af3.component.ui.editor.PackSelectionToComponent">
contributor="org.fortiss.af3.component.ui.editor.PackSelectionToComponentMenu">
</contextMenuContribution>
<contextMenuContribution
contributor="org.fortiss.af3.component.ui.editor.UnpackSelectionToComponentsMenu">
</contextMenuContribution>
<contextMenuContribution
contributor="org.fortiss.af3.component.ui.simulator.SimulatorEasyStartMenu">
......
......@@ -3,6 +3,7 @@ CodeSpecificationEditorBinding.java aeff3d23f484b3adeac6dfa01bb52ddcb8daba94 GRE
ComponentArchitectureEditorBinding.java c7756ac19f55df928c6b9b0ece1982c47e8f0e1c GREEN
ComponentStructureEditor.java 2eb198630fa961f42568b0bd272d19db5e6630aa GREEN
ComponentStructureEditorBinding.java 5801ef5d8882d026acc6f4ac7ecb4daba3452299 GREEN
LayoutComponentCommand.java 89f12c354b832adce29322b7f7ccd85b975fbf83 RED
PackComponentCommand.java 30a8b76cf748d7142c45696c414e4610f62ee592 GREEN
PackSelectionToComponent.java 0323bc6f85088869b093bd6c415b17b8f0fe722b GREEN
PackSelectionToComponentMenu.java 187ac87f2afdac3b4d67e4a88a7286510e88a82e GREEN
PackUnpackComponentMenuBase.java 4dd4e9f2489e8d6772c7b590f6f47a33c903e310 GREEN
PackUnpackComponents.java 3fa1b1b7eb6bf863bfff7b9116ccabe14b15aba3 GREEN
UnpackSelectionToComponentsMenu.java 5a9ddced6f128942d31424e9f5a6ae01b405221f GREEN
/*-------------------------------------------------------------------------+
| Copyright 2014 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor;
import static java.util.Collections.max;
import static java.util.Collections.min;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE;
import static org.fortiss.tooling.base.model.layout.EOrientation.EAST;
import static org.fortiss.tooling.base.model.layout.EOrientation.WEST;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodePosition;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeSize;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.moveNode;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.setNodePosition;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.setNodeSize;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.setStickyConnectorLayoutData;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
/**
* Takes a component and its referenced components and arranges them properly
* in the diagram. At the moment it is used after the packing of 2 components to
* properly display the new component in the diagram
*
* TODO (AB, 13) There are plenty of magic constants used throughout this code.
*
* @author aravantinos
*/
public class LayoutComponentCommand implements Runnable {
/** component to be positioned */
private Component component;
/** referenced components */
private List<Component> refs;
/** Constructor */
public LayoutComponentCommand(Component component, List<Component> refCompnents) {
this.component = component;
this.refs = refCompnents;
}
/** {@inheritDoc} */
@Override
public void run() {
ArrayList<Integer> xDimensions = new ArrayList<Integer>();
ArrayList<Integer> yDimensions = new ArrayList<Integer>();
ArrayList<Integer> xPositions = new ArrayList<Integer>();
ArrayList<Integer> yPositions = new ArrayList<Integer>();
for(Component comp : refs) {
xPositions.add(getNodePosition(comp).getX());
yPositions.add(getNodePosition(comp).getY());
xDimensions.add(getNodeSize(comp).getWidth() + getNodePosition(comp).getX());
yDimensions.add(getNodeSize(comp).getHeight() + getNodePosition(comp).getX());
}
int minPosX = min(xPositions);
int minPosY = min(yPositions);
int maxX = max(xDimensions);
int maxY = max(yDimensions);
setNodeSize(component, maxX - minPosX, maxY - minPosY);
setNodePosition(component, minPosX, minPosY);
int index = 0;
for(InputPort input : component.getInputPorts()) {
setStickyConnectorLayoutData(input, WEST, DEFAULT_GRID_SIZE * (index * 5 + 1));
index++;
}
int indexOut = 0;
for(OutputPort output : component.getOutputPorts()) {
setStickyConnectorLayoutData(output, EAST, DEFAULT_GRID_SIZE * (indexOut * 5 + 1));
indexOut++;
}
ArrayList<InputPort> inPorts = new ArrayList<InputPort>();
ArrayList<OutputPort> outPorts = new ArrayList<OutputPort>();
for(Component com : refs) {
for(int i = 0; i < com.getInputPorts().size(); i++) {
inPorts.add(com.getInputPorts().get(i));
}
for(int i = 0; i < com.getOutputPorts().size(); i++) {
outPorts.add(com.getOutputPorts().get(i));
}
}
int indexedIn = 0;
for(InputPort input : inPorts) {
for(int i = 0; i < input.getIncomingChannels().size(); i++) {
moveNode(input.getIncomingChannels().get(i).getSource(), 50, 100 + indexedIn);
indexedIn += 50;
}
}
int indexedOut = 0;
for(OutputPort output : outPorts) {
for(int i = 0; i < output.getOutgoingChannels().size(); i++) {
moveNode(output.getOutgoingChannels().get(i).getTarget(), 0, 50 + indexedOut);
indexedOut += 50;
}
}
}
}
/*-------------------------------------------------------------------------+
| Copyright 2013 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createChannelAndAttach;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createInputPortAndAttach;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createOutputPortAndAttach;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.component.utils.ComponentModelElementFactory;
import org.fortiss.tooling.kernel.utils.UniqueIDUtils;
/**
* Takes a given selection of components and packs them to a new component
* adapting all connections / dependencies to the newly created comp.
* Command is called by : PackSelectionToComponent
*
* @author aravantinos
*/
public class PackComponentCommand implements Runnable {
/** selected components */
private List<Component> components;
/** Component for checking */
private Component newComp;
/** Constructor */
public PackComponentCommand(List<Component> components) {
this.components = components;
}
/** {@inheritDoc} */
@Override
public void run() {
// get(0) because we take the first component on purpose.
// The first component exists because this command can only be run on a command.
Component refComp = components.get(0);
for(Component component : components) {
if(component.getParentComponent() != refComp.getParentComponent() &&
component.getCausalitySpecification() != refComp.getCausalitySpecification()) {
org.conqat.ide.commons.ui.dialog.MessageUtils
.showErrorAsync("Unsupported Operation",
"The selected components are on different levels or their causal specification differs.");
return;
}
}
Component parentComp = refComp.getParentComponent();
boolean causalityValue = refComp.getCausalitySpecification().isStronglyCausal();
newComp =
ComponentModelElementFactory.createComponentAndAttach(parentComp, "New Component",
causalityValue);
UniqueIDUtils.prepareUniqueID(newComp, parentComp);
parentComp.getContainedElements().add(newComp);
for(Component component : components) {
newComp.getContainedElements().add(component);
for(InputPort inputPort : component.getInputPorts()) {
ArrayList<Channel> externChannels = new ArrayList<Channel>();
for(Channel channel : inputPort.getIncomingChannels()) {
if(!components.contains(channel.getSource().getComponent())) {
externChannels.add(channel);
}
}
if(externChannels.isEmpty()) {
for(Channel channel : inputPort.getIncomingChannels()) {
newComp.getConnections().add(channel);
}
} else {
InputPort input =
createInputPortAndAttach(newComp, inputPort.getName(),
copy(inputPort.getVariableType()),
copy(inputPort.getInitialValue()));
for(Channel channel : inputPort.getIncomingChannels()) {
if(externChannels.contains(channel)) {
createChannelAndAttach(parentComp, channel.getName(),
channel.getSource(), input);
newComp.getConnections().add(channel);
channel.setSource(input);
} else {
newComp.getConnections().add(channel);
}
}
}
}
for(OutputPort outputPort : component.getOutputPorts()) {
ArrayList<Channel> externChannels = new ArrayList<Channel>();
for(Channel channel : outputPort.getOutgoingChannels()) {
if(!components.contains(channel.getTarget().getComponent())) {
externChannels.add(channel);
}
}
if(externChannels.isEmpty()) {
for(Channel channel : outputPort.getOutgoingChannels()) {
newComp.getConnections().add(channel);
}
} else {
OutputPort output =
createOutputPortAndAttach(newComp, outputPort.getName(),
copy(outputPort.getVariableType()),
copy(outputPort.getInitialValue()));
output.setOwner(newComp);
output.setId(outputPort.getId());
for(Channel channel : outputPort.getOutgoingChannels()) {
if(externChannels.contains(channel)) {
createChannelAndAttach(parentComp, channel.getName(), output,
channel.getTarget());
newComp.getConnections().add(channel);
channel.setTarget(output);
} else {
newComp.getConnections().add(channel);
}
}
}
}
}
}
/** @return new component */
public Component getCreatedComponent() {
return newComp;
}
}
/*-------------------------------------------------------------------------+
| Copyright 2014 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor;
import static org.conqat.ide.commons.ui.dialog.MessageUtils.showErrorAsync;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.runAsCommand;
import java.util.List;
import org.eclipse.jface.action.Action;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.ui.AF3ComponentUIActivator;
import org.fortiss.tooling.base.ui.layout.auto.IAutoLayouter;
import org.fortiss.tooling.base.ui.layout.auto.KielerAutoLayouter;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.base.MultiEObjectActionBase;
/**
* {@link IContextMenuContributor} to pack selection to {@link Component}.
*
* @author Andreiasw1, reaboi
*/
public class PackSelectionToComponentMenu extends PackUnpackComponentMenuBase {
/** {@inheritDoc} */
@Override
protected Action createAction(List<Component> components) {
return new PackComponentAction(components);
}
/** The action. */
private class PackComponentAction extends MultiEObjectActionBase<List<Component>> {
/** Constructor. */
public PackComponentAction(List<Component> selectedElement) {
super("Pack component", AF3ComponentUIActivator.getImageDescriptor("icons/pack16.png"));
setTarget(selectedElement);
}
/** {@inheritDoc} */
@Override
public void run() {
// The list of selected components is guaranteed to be non-empty() by
// PackSelectionToComponents::getContributedItems()
runAsCommand(
getTarget().get(0),
() -> {
Component newComponent = PackUnpackComponents.pack(getTarget());
if(newComponent == null) {
showErrorAsync("Unsupported Operation",
"The selected components are on different levels or their causal specification differs.");
return;
}
IAutoLayouter layouter = new KielerAutoLayouter();
layouter.performAutoLayout(newComponent);
layouter.performAutoLayout(newComponent.getParentComponent());
});
}
}
}
......@@ -16,51 +16,36 @@
package org.fortiss.af3.component.ui.editor;
import static java.util.Collections.singletonList;
import static org.conqat.ide.commons.ui.dialog.MessageUtils.showWarningAsync;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getNodeBounds;
import static org.eclipse.emf.common.util.ECollections.singletonEList;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.tooling.base.ui.ToolingBaseUIActivator;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuMultiSelectionContributor;
import org.fortiss.tooling.kernel.ui.extension.base.MultiEObjectActionBase;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
/**
* {@link IContextMenuContributor} for pack components
* {@link IContextMenuContributor} base class to pack / unpack {@link Component}s.
*
* @author Andreiasw1
* @author barner
*/
public class PackSelectionToComponent implements IContextMenuMultiSelectionContributor {
public abstract class PackUnpackComponentMenuBase implements IContextMenuMultiSelectionContributor {
/** {@inheritDoc} */
@Override
public List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if(selection instanceof Component) {
// Do not allow repacking of the top-level component (associated with the
// ComponentArcitecture); only an issue with single selection, multi not affected.
ComponentArchitecture compArch =
getParentElement(selection, ComponentArchitecture.class, false);
if(compArch != null && compArch.getTopComponent() != (Component)selection) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(new PackComponentAction(
singletonList((Component)selection))));
return contributionItems;
}
}
return null;
return getContributedItems(singletonEList(selection), contextProvider);
}
/** {@inheritDoc} */
......@@ -68,60 +53,26 @@ public class PackSelectionToComponent implements IContextMenuMultiSelectionContr
public List<IContributionItem> getContributedItems(List<EObject> selection,
ContextMenuContextProvider contextProvider) {
EList<Component> components = pickInstanceOf(Component.class, selection);
if(components != null && !components.isEmpty() && components.size() == selection.size()) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(new PackComponentAction(components)));
return contributionItems;
if(components == null || components.isEmpty() || components.size() != selection.size()) {
return null;
}
for(Component component : components) {
ComponentArchitecture compArch =
getParentElement(component, ComponentArchitecture.class, false);
if(compArch == null || compArch.getTopComponent() == component) {
return null;
}
}
return null;
return singletonList(new ActionContributionItem(createAction(components)));
}
/** Creates the {@link Action} to issue the pack / unpack action. */
protected abstract Action createAction(List<Component> components);
/** {@inheritDoc} */
@Override
public String getMenuSectionID() {
return null;
}
/** The action. */
private class PackComponentAction extends MultiEObjectActionBase<List<Component>> {
/** selected element/-s */
protected List<Component> selectedElement;
/** Constructor. */
public PackComponentAction(List<Component> selectedElement) {
super("Pack Component", ToolingBaseUIActivator
.getImageDescriptor("icons/refinement_function.png"));
this.selectedElement = selectedElement;
setTarget(selectedElement);
}
/** {@inheritDoc} */
@Override
public void run() {
PackComponentCommand packCMD = new PackComponentCommand(getTarget());
// get(0) because we take the first component on purpose.
// The first component exists because this command can only be run on a command.
Component targetElement = selectedElement.get(0);
ICommandStackService.getInstance().runAsCommand(targetElement, packCMD);
Component newComp = packCMD.getCreatedComponent();
LayoutComponentCommand layoutCmd = new LayoutComponentCommand(newComp, getTarget());
ICommandStackService.getInstance().runAsCommand(targetElement, layoutCmd);
for(Component compon : newComp.getParentComponent().getSubComponents()) {
if(compon == newComp) {
continue;
}
if(getNodeBounds(compon).intersects(getNodeBounds(newComp))) {
showWarningAsync("Warning",
"The newly created component intersects existing components. Please reposition it.");
break;
}
}
}
}
}
/*-------------------------------------------------------------------------+
| Copyright 2013 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createChannelAndAttach;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createComponentAndAttach;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createInputPortAndAttach;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createOutputPortAndAttach;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.fixMissingIDs;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.prepareUniqueID;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
/**
* Model transformations to pack or unpack {@link Component}s.
*
* @author aravantinos, barner, reaboi
*/
public class PackUnpackComponents {
// *******************
// Unpack components *