Commit 2b69ffc4 authored by Marco Volpe's avatar Marco Volpe
Browse files

Changed the naming of coupling (de)constraints.

* Commonized a method for calculation of names between allocation and
(de)coupling constraints.

Issue-Ref: 3812
Issue-Url: https://af3-developer.fortiss.org/issues/3812

Signed-off-by: Marco Volpe's avatarMarco Volpe <volpe@fortiss.org>
parent 0fa82a6f
AllocationPatternCompositeBackend.java 3ce29c907932fd803e3ef977a91008edef63289a GREEN
AllocationPatternCompositeBackend.java 773bd1034e974dd59624b91e0aade1facce44432 YELLOW
ConstraintPatternHeader.java 6e6b46562953f3490ff3beeaa446d169a366cb48 GREEN
ConstraintViewBackend.java 4099a405a81ccdf05e3f517d6b1de3f2f2b2d926 GREEN
FunctionCouplingCompositeBackend.java 7a60b7b73ae0330bc24c310b8167c515c6942fed GREEN
FunctionCouplingCompositeBackend.java 36f63403034b15e7f668da551798c752edb6724e YELLOW
MemoryPatternBackend.java c452fa46dce1d8646a60ba48ee7bcdd2b39debd7 GREEN
SafetyPatternBackend.java bfb2d61e387f33cdff9270978253868d50308b43 GREEN
......@@ -15,14 +15,12 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.ui.perspective.targetdef.constraint;
import static java.util.stream.Collectors.joining;
import static org.fortiss.af3.exploration.smt.util.Z3ModelElementFactory.createSMTConstraint;
import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.DSE_EVENT.DSE_REMOVED_EVENT;
import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.DSE_EVENT.DSE_SELECTED_EVENT;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.calcPatternName;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
......@@ -43,7 +41,6 @@ import org.fortiss.af3.exploration.util.PatternFactoryUtils;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.task.model.Task;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
/**
......@@ -55,16 +52,14 @@ import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
public class AllocationPatternCompositeBackend extends AllocationPatternCompositeGUI
implements IEventListener {
/** The left set of element(s). allocation source. */
private Set<IModelElement> taskSet;
/** The right set of element(s). allocation destination. */
private Set<IModelElement> ecuSet;
/** The left list of element(s). allocation source. */
private List<IModelElement> taskList;
/** The right list of element(s). allocation destination. */
private List<IModelElement> ecuList;
/** Separation marker for allocation targets. */
final String SEPARATION_STRING_LEFT = "; ";
/** Separation marker for allocation targets. */
final String SEPARATION_STRING_RIGHT = " | ";
/** Maximum length of one side of the expression (string representation). */
int MAX_ALLOC_SIZE_PER_SIDE = 50;
/** Constructor. */
public AllocationPatternCompositeBackend(Composite parent, int style) {
......@@ -105,8 +100,8 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
IDSEPerspectiveManager pm = IDSEPerspectiveManager.INSTANCE;
pm.addExplorationTarget(constraint);
// Reset the fields and GUI elements.
taskSet = null;
ecuSet = null;
taskList = null;
ecuList = null;
leftTreeViewer.setSelection(StructuredSelection.EMPTY);
rightTreeViewer.setSelection(StructuredSelection.EMPTY);
header.setConstraintName("");
......@@ -124,9 +119,9 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
((IStructuredSelection)event.getSelection()).toList();
Object eventSource = event.getSource();
if(eventSource.equals(leftTreeViewer)) {
taskSet = new HashSet<IModelElement>(selectionList);
taskList = selectionList;
} else if(eventSource.equals(rightTreeViewer)) {
ecuSet = new HashSet<IModelElement>(selectionList);
ecuList = selectionList;
}
updateConstraint();
}
......@@ -145,16 +140,16 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
private void updateConstraint() {
// Calculate the name.
String constraintText = "";
if(taskSet != null) {
constraintText = calcAllocLeftRightName(taskSet, SEPARATION_STRING_LEFT);
if(taskList != null) {
constraintText = calcPatternName(taskList, SEPARATION_STRING_LEFT);
}
if(btnAllocation.getSelection()) {
constraintText += " -> ";
} else {
constraintText += " -/> ";
}
if(ecuSet != null) {
constraintText += calcAllocLeftRightName(ecuSet, SEPARATION_STRING_RIGHT);
if(ecuList != null) {
constraintText += calcPatternName(ecuList, SEPARATION_STRING_RIGHT);
}
// Update the GUI elements displaying the name.
......@@ -162,52 +157,15 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
header.setConstraintName(constraintText);
// Make add button available only if constraint is fully specified.
if(taskSet != null && ecuSet != null) {
if(taskList != null && ecuList != null) {
btnAdd.setEnabled(isConstraintComplete());
}
}
/**
* Calculates the "name" of constraints. It supports sets and shortening the name if it becomes
* "too long". The contained elements of sets can still be easily seen by setting
* "DSE_DEBUG_VERBOSE" to "true" in the environment variable section.
*/
private String calcAllocLeftRightName(Set<IModelElement> selectedElements, String separator) {
String constraintNamePart = " ";
if(selectedElements != null) {
// Denote Sets if needed.
if(selectedElements.size() <= 1) {
constraintNamePart = "";
} else {
constraintNamePart = "{";
}
// Add the element names.
constraintNamePart += selectedElements.stream()
.map(e -> ((INamedElement)e).getName() + separator).collect(joining());
// Remove the tailing separator.
if(constraintNamePart.length() > separator.length()) {
constraintNamePart = constraintNamePart.substring(0,
constraintNamePart.length() - separator.length());
}
if(selectedElements.size() > 1) {
constraintNamePart += "}";
}
// Trim the element description if needed (aware of long names & sets with many
// elements).
if(constraintNamePart.length() > MAX_ALLOC_SIZE_PER_SIDE) {
constraintNamePart = constraintNamePart.substring(0, MAX_ALLOC_SIZE_PER_SIDE);
if(selectedElements.size() > 1) {
constraintNamePart = "{" + constraintNamePart + "...; ...}";
}
}
}
return constraintNamePart;
}
/** Check if constraint is fully specified. */
private boolean isConstraintComplete() {
boolean complete = true;
if(taskSet == null || ecuSet == null) {
if(taskList == null || ecuList == null) {
complete = false;
}
return complete;
......@@ -219,7 +177,7 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
boolean isAllocation = btnAllocation.getSelection();
// Cannot use static import due to function name clash
IExpression allocationPattern = PatternFactoryUtils.createAllocationPatternExpression(dse,
isAllocation, taskSet, ecuSet);
isAllocation, taskList, ecuList);
SMTConstraint constraint =
createSMTConstraint(header.getConstraintName(), allocationPattern, false);
constraint.setDimension(header.getCategoryName());
......
......@@ -19,10 +19,12 @@ import static org.conqat.ide.commons.ui.selection.SelectionUtils.checkAndSelectA
import static org.fortiss.af3.exploration.smt.util.Z3ModelElementFactory.createSMTConstraint;
import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.DSE_EVENT.DSE_REMOVED_EVENT;
import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.DSE_EVENT.DSE_SELECTED_EVENT;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.calcPatternName;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.createFunctionCouplingPattern;
import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirst;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.prepareUniqueID;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.ISelectionChangedListener;
......@@ -43,6 +45,7 @@ import org.fortiss.af3.exploration.ui.perspective.service.IEventListener;
import org.fortiss.af3.exploration.ui.perspective.targetdef.SuperSetContentProvider;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.task.model.Task;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
......@@ -119,17 +122,27 @@ public class FunctionCouplingCompositeBackend extends FunctionCouplingCompositeG
public void widgetSelected(SelectionEvent e) {
selectedTasks = checkAndSelectAll(treeViewerSet1Selection.getSelection(), Task.class);
selectedConstName = header.getConstraintName();
if(!isValidSelection()) {
printMessage(errorMessage);
return;
}
String name;
if(btnCoupling.getSelection()) {
name = "Coupling";
} else {
name = "Decoupling";
}
List<IModelElement> elementList = new ArrayList<IModelElement>();
elementList.addAll(selectedTasks);
name = name + calcPatternName(elementList, ",");
header.setConstraintName(name);
IDSEPerspectiveManager pm = IDSEPerspectiveManager.INSTANCE;
DSE dse = pm.getCurrentlySelectedDSE();
SMTConstraint constraint = createSMTConstraint();
constraint.setName(selectedConstName);
constraint.setName(name);
constraint.setExpression(
createFunctionCouplingPattern(dse, btnCoupling.getSelection(), selectedTasks));
constraint.setDimension(header.getCategoryName());
......
......@@ -6,4 +6,4 @@ ExplorationModelElementFactory.java bb48b2d09b92efcb1b2d3e382555089bb7ed5db5 GRE
ExplorationReflectionUtils.java 62731e1cef32fe93f2c2017f93f5ba1f054d5197 GREEN
ExplorationUtils.java 3e317c851bd1a0b48fbec3fdbe039d8b66506c51 GREEN
ModelSnapshotExtractUtils.java dde8b42c5a7228478ffe8c67820bcac91e875562 GREEN
PatternFactoryUtils.java 6b3c61d421258967af94ce019fdb778e3161c90d GREEN
PatternFactoryUtils.java 2a888de216d471b437cd0dbdfdb184655d354720 YELLOW
......@@ -15,6 +15,7 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.util;
import static java.util.stream.Collectors.joining;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createAllocation;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createAnd;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createArithmeticLiteral;
......@@ -77,6 +78,7 @@ import org.fortiss.af3.task.model.Signal;
import org.fortiss.af3.task.model.Task;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* Utility methods for generating DSEML constraints and objectives according to patterns.
......@@ -85,6 +87,9 @@ import org.fortiss.tooling.base.model.element.IModelElement;
*/
public class PatternFactoryUtils {
/** Maximum length of one side of the expression (string representation). */
static int MAX_ALLOC_SIZE_PER_SIDE = 50;
/**
* Creates an {@link IExpression} according to the {@link Route} weight constraint pattern.
*
......@@ -458,4 +463,41 @@ public class PatternFactoryUtils {
return expression;
}
/**
* Calculates the "name" of constraints. It supports sets and shortening the name if it becomes
* "too long". The contained elements of sets can still be easily seen by setting
* "DSE_DEBUG_VERBOSE" to "true" in the environment variable section.
*/
public static String calcPatternName(List<IModelElement> selectedElements, String separator) {
String constraintNamePart = " ";
if(selectedElements != null) {
// Denote Sets if needed.
if(selectedElements.size() <= 1) {
constraintNamePart = "";
} else {
constraintNamePart = "{";
}
// Add the element names.
constraintNamePart += selectedElements.stream()
.map(e -> ((INamedElement)e).getName() + separator).collect(joining());
// Remove the tailing separator.
if(constraintNamePart.length() > separator.length()) {
constraintNamePart = constraintNamePart.substring(0,
constraintNamePart.length() - separator.length());
}
if(selectedElements.size() > 1) {
constraintNamePart += "}";
}
// Trim the element description if needed (aware of long names & sets with many
// elements).
if(constraintNamePart.length() > MAX_ALLOC_SIZE_PER_SIDE) {
constraintNamePart = constraintNamePart.substring(0, MAX_ALLOC_SIZE_PER_SIDE);
if(selectedElements.size() > 1) {
constraintNamePart = "{" + constraintNamePart + "...; ...}";
}
}
}
return constraintNamePart;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment