Skip to content

Commit

Permalink
[2069] FunctionalChain, PhysicalPath internal arrow to a port
Browse files Browse the repository at this point in the history
without
exchanges
must not be displayed

- Forcing refresh diagram on creating new PhysicalPath at LAB and SAB
- Move "update the internal links" into post refresh
- In show/hide category, hide a PhysicalPort, FunctionPort if no edge
(except Internal Edge) is visible
- Add test for "Allocated Functions" tool with internal FunctionalChain
in LAB
- Add test for "Actors" tool with internal PhysicalPath in LAB

Change-Id: I8d0dcbb25316462d8cb9a0338549df0299ad1cd4
Signed-off-by: cong-bang.do <docongbang1993@gmail.com>
  • Loading branch information
bang-dc authored and pdulth committed Aug 22, 2018
1 parent eb7dd21 commit e3b9213
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 168 deletions.
Expand Up @@ -3864,7 +3864,7 @@
</tools>
</ownedTools>
<ownedTools xsi:type="tool_1:PopupMenu" name="Physical Path">
<menuItemDescription xsi:type="tool_1:OperationAction" name="Create a Physical Path" precondition="&lt;%isValidPhysicalPathSelection($views)%>">
<menuItemDescription xsi:type="tool_1:OperationAction" name="Create a Physical Path" precondition="&lt;%isValidPhysicalPathSelection($views)%>" forceRefresh="true">
<view name="views"/>
<initialOperation>
<firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="&lt;% $views%>">
Expand Down
Expand Up @@ -2427,7 +2427,7 @@
</initialOperation>
</ownedTools>
<ownedTools xsi:type="tool:PopupMenu" name="Physical Path">
<menuItemDescription xsi:type="tool:OperationAction" name="Create a Physical Path" precondition="&lt;%isValidPhysicalPathSelection($views)%>">
<menuItemDescription xsi:type="tool:OperationAction" name="Create a Physical Path" precondition="&lt;%isValidPhysicalPathSelection($views)%>" forceRefresh="true">
<view name="views"/>
<initialOperation>
<firstModelOperations xsi:type="tool:ChangeContext" browseExpression="&lt;% $views%>">
Expand Down
Expand Up @@ -1330,26 +1330,7 @@ public boolean isValidABFunctionalChainInternalLinkEdge(FunctionalChain chain, D

public boolean isValidABPhysicalPathInternalLinkEdge(PhysicalPath path, DSemanticDecorator source,
DSemanticDecorator target) {
if (source instanceof EdgeTarget) {
HashSet<DEdge> edges = new HashSet<DEdge>();
EdgeTarget src = (EdgeTarget) source;
edges.addAll(DiagramServices.getDiagramServices().getIncomingEdges(src));
edges.addAll(DiagramServices.getDiagramServices().getOutgoingEdges(src));

int nbEdges = 0;
for (DEdge edge : edges) {
if ((edge != null) && edge.getTarget().equals(path)) {
if (edge.getSourceNode().equals(target)) {
nbEdges++;
}
if (edge.getTargetNode().equals(target)) {
nbEdges++;
}
}
}
return nbEdges <= 1;
}
return true;
return PhysicalServices.getService().isValidInternalLinkEdge((EdgeTarget) source, (EdgeTarget) target);
}

public boolean isValidFunctionalExchangeCategoryEdge(ExchangeCategory category, DSemanticDecorator source,
Expand Down
Expand Up @@ -1046,7 +1046,7 @@ private EdgeTarget getPortOnInvolved(DEdge edge, InvolvedElement involved) {
return null;
}

private boolean isValidInternalLinkEdge(EdgeTarget currentSourceNode, EdgeTarget currentTargetNode) {
public boolean isValidInternalLinkEdge(EdgeTarget currentSourceNode, EdgeTarget currentTargetNode) {
if (currentSourceNode == null) {
return false;
}
Expand Down
Expand Up @@ -96,25 +96,6 @@ public void beforeRefresh(DDiagram diagram) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnReordering, e);
}

// -------------------------------------
// Update the internal edges for physical paths and functional chains.
// -------------------------------------
try {
List<String> physicalPathSupportingDiagrams = Arrays.asList(IDiagramNameConstants.PHYSICAL_ARCHITECTURE_BLANK_DIAGRAM_NAME,
IDiagramNameConstants.SYSTEM_ARCHITECTURE_BLANK_DIAGRAM_NAME, IDiagramNameConstants.LOGICAL_ARCHITECTURE_BLANK_DIAGRAM_NAME);
if (physicalPathSupportingDiagrams.contains(diagram.getDescription().getName())) {
PhysicalServices.getService().updateInternalPhysicalPaths(diagram);
}
} catch (Exception e) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnUpdatePhysicalPathStyle, e);
}

try {
FunctionalChainServices.getFunctionalChainServices().updateInternalFunctionalChains(diagram);
} catch (Exception e) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnUpdateFunctionalChainStyle, e);
}

// -------------------------------------
// Update categories
// -------------------------------------
Expand Down Expand Up @@ -479,8 +460,8 @@ protected List<AbstractNodeMapping> getListOfMappingsToMove(DDiagram diagram) {
*/
@Override
public void postRefresh(DDiagram diagram) {

try {
FunctionalChainServices.getFunctionalChainServices().updateInternalFunctionalChains(diagram);
FunctionalChainServices.getFunctionalChainServices().updateFunctionalChainStyles(diagram);
} catch (Exception e) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnUpdateFunctionalChainStyle, e);
Expand All @@ -490,6 +471,7 @@ public void postRefresh(DDiagram diagram) {
List<String> physicalPathSupportingDiagrams = Arrays.asList(IDiagramNameConstants.PHYSICAL_ARCHITECTURE_BLANK_DIAGRAM_NAME,
IDiagramNameConstants.SYSTEM_ARCHITECTURE_BLANK_DIAGRAM_NAME, IDiagramNameConstants.LOGICAL_ARCHITECTURE_BLANK_DIAGRAM_NAME);
if (physicalPathSupportingDiagrams.contains(diagram.getDescription().getName())) {
PhysicalServices.getService().updateInternalPhysicalPaths(diagram);
PhysicalServices.getService().updatePhysicalPathStyles(diagram);
}
} catch (Exception e) {
Expand Down
Expand Up @@ -53,13 +53,6 @@ public void beforeRefresh(DDiagram diagram) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnContextualElements, e);
}

// Update the internal edges for functional chains.
try {
FunctionalChainServices.getFunctionalChainServices().updateInternalFunctionalChains(diagram);
} catch (Exception e) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnUpdateFunctionalChainStyle, e);
}

try {
updateFunctionalExchangeCategories(context);
} catch (Exception e) {
Expand Down Expand Up @@ -92,6 +85,7 @@ public void beforeRefresh(DDiagram diagram) {
*/
public void postRefresh(DDiagram diagram) {
try {
FunctionalChainServices.getFunctionalChainServices().updateInternalFunctionalChains(diagram);
FunctionalChainServices.getFunctionalChainServices().updateFunctionalChainStyles(diagram);
} catch (Exception e) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnUpdateFunctionalChainStyle, e);
Expand Down
Expand Up @@ -45,13 +45,6 @@ public void beforeRefresh(DDiagram diagram) {

DDiagramContents context = FaServices.getFaServices().getDDiagramContents(diagram);

// Update the internal edges for functional chains
try {
FunctionalChainServices.getFunctionalChainServices().updateInternalFunctionalChains(diagram);
} catch (Exception e) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnUpdateFunctionalChainStyle, e);
}

// -------------------------------------
// Show in diagram related contextual elements
// -------------------------------------
Expand All @@ -75,8 +68,8 @@ public void beforeRefresh(DDiagram diagram) {
* @see org.eclipse.sirius.business.api.refresh.IRefreshExtension#postRefresh(org.eclipse.sirius.DDiagram)
*/
public void postRefresh(DDiagram diagram) {

try {
FunctionalChainServices.getFunctionalChainServices().updateInternalFunctionalChains(diagram);
FunctionalChainServices.getFunctionalChainServices().updateFunctionalChainStyles(diagram);
} catch (Exception e) {
Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM).error(Messages.RefreshExtension_ErrorOnUpdateFunctionalChainStyle, e);
Expand Down
Expand Up @@ -12,6 +12,8 @@

import java.util.Collection;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.diagram.AbstractDNode;
import org.eclipse.sirius.diagram.DDiagramElement;
Expand All @@ -24,6 +26,7 @@
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.cs.PhysicalLink;
import org.polarsys.capella.core.data.cs.PhysicalLinkCategory;
import org.polarsys.capella.core.data.cs.PhysicalPath;
import org.polarsys.capella.core.data.cs.PhysicalPort;
import org.polarsys.capella.core.model.helpers.PhysicalLinkExt;
import org.polarsys.capella.core.model.helpers.PortExt;
Expand Down Expand Up @@ -210,28 +213,22 @@ protected boolean hideInsteadOfRemoveView(DDiagramElement element_p, DiagramCont
@Override
protected boolean mustHide(DDiagramElement view_p, DiagramContext context_p) {

// A component port must be hide if no edges or hidden edges
// A component port must be hide if no edges whose target is Physical Path, is visible
if (view_p.getDiagramElementMapping() instanceof AbstractNodeMapping) {
EObject target = view_p.getTarget();
if ((target != null) && ((target instanceof PhysicalPort))) {
boolean result = true;
if (result) {
for (DEdge edge : ((EdgeTarget) view_p).getIncomingEdges()) {
if (getContent().isVisible(edge)) {
result = false;
break;
}
}
}
if (result) {
for (DEdge edge : ((EdgeTarget) view_p).getOutgoingEdges()) {
if (getContent().isVisible(edge)) {
result = false;
break;
}

EList<DEdge> relatedEdges = new BasicEList<>();
relatedEdges.addAll(((EdgeTarget) view_p).getIncomingEdges());
relatedEdges.addAll(((EdgeTarget) view_p).getOutgoingEdges());

for (DEdge edge : relatedEdges) {
if (edge != null && !(edge.getTarget() instanceof PhysicalPath) && getContent().isVisible(edge)) {
return false;
}
}
return result;

return true;
}
}

Expand Down
Expand Up @@ -12,6 +12,8 @@

import java.util.Collection;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.DEdge;
Expand All @@ -26,6 +28,7 @@
import org.polarsys.capella.core.data.fa.FunctionInputPort;
import org.polarsys.capella.core.data.fa.FunctionOutputPort;
import org.polarsys.capella.core.data.fa.FunctionPort;
import org.polarsys.capella.core.data.fa.FunctionalChain;
import org.polarsys.capella.core.data.fa.FunctionalExchange;
import org.polarsys.capella.core.data.oa.Entity;
import org.polarsys.capella.core.sirius.analysis.ABServices;
Expand Down Expand Up @@ -61,30 +64,23 @@ protected boolean isValidSemanticView(EObject semantic, DSemanticDecorator seman

@Override
protected boolean mustHide(DDiagramElement view, DiagramContext context) {

// A function port must be hidden if no edges or hidden edges
// A function port must be hidden if no edges whose target is not FunctionalChain are visible
if (view.getDiagramElementMapping() instanceof AbstractNodeMapping) {
EObject target = view.getTarget();
if ((target != null) && ((target instanceof FunctionPort || target instanceof ExchangeCategory))) {
boolean result = true;
for (DEdge edge : ((EdgeTarget) view).getIncomingEdges()) {
if (getContent().isVisible(edge)) {
result = false;
break;
}
}
if (result) {
for (DEdge edge : ((EdgeTarget) view).getOutgoingEdges()) {
if (getContent().isVisible(edge)) {
result = false;
break;
}
if ((target instanceof FunctionPort) || (target instanceof ExchangeCategory)) {
EList<DEdge> relatedEdges = new BasicEList<>();
relatedEdges.addAll(((EdgeTarget) view).getIncomingEdges());
relatedEdges.addAll(((EdgeTarget) view).getOutgoingEdges());

for (DEdge edge : relatedEdges) {
if (edge != null && !(edge.getTarget() instanceof FunctionalChain) && getContent().isVisible(edge)) {
return false;
}
}
return result;

return true;
}
}

return super.mustHide(view, context);
}

Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.polarsys.capella.test.diagram.common.ju.api.AbstractDiagramTestCase;
import org.polarsys.capella.test.diagram.common.ju.context.DiagramContext;
import org.polarsys.capella.test.diagram.common.ju.step.crud.OpenDiagramStep;
import org.polarsys.capella.test.diagram.common.ju.step.tools.InsertRemoveTool;
import org.polarsys.capella.test.diagram.common.ju.step.tools.SwitchTool;
import org.polarsys.capella.test.framework.context.SessionContext;

Expand All @@ -27,12 +28,15 @@
public class SwitchFunctionalCategoryHidingInternalEdgesTestCase extends AbstractDiagramTestCase {

private static String DIAGRAM_NAME = "[LAB] Logical System";
private static String INTERNAL_FUNCTIONAL_CHAIN_TO_BE_REMOVED = "4046880f-4b4b-4f89-b340-d50fe33b7844";
private static String PORT_TO_BE_HIDDEN = "c4b057aa-daa7-4ac1-a3ce-5bd8419c4421";
private static String PORT_2 = "33c30db4-aca7-4141-8a25-a4350d2274cc";
private static String FUNCTIONAL_EXCHANGE_TO_BE_HIDDEN = "1489756a-75be-46bc-a797-0a53eeef67c9";
private static String EXCHANGE_CATEGORY_TO_BE_SHOWN = "020642b3-59ca-4a33-a34a-da499d81f67f";
private static String FUNCTIONAL_EXCHANGE_2 = "1489756a-75be-46bc-a797-0a53eeef67c9";
private static String EXCHANGE_CATEGORY_1 = "020642b3-59ca-4a33-a34a-da499d81f67f";

private static String LOGICAL_SYSTEM_CONTAINER = "2671b6e9-5f9a-40bc-8f2a-2ff5ee0fe029";
private static String LOGICAL_FUNCTION_5 = "704851d2-9622-4e9f-8ddc-7c45c3027f93";
private static String FUNCTIONAL_EXCHANGE_3 = "3144ef94-bf0a-40bd-a56a-9c81e0dc032f";
private static String INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4 = "4046880f-4b4b-4f89-b340-d50fe33b7844";
private static String PORT_OUT_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4 = "c4b057aa-daa7-4ac1-a3ce-5bd8419c4421";
private static String PORT_IN_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4 = "33c30db4-aca7-4141-8a25-a4350d2274cc";

public void test() throws Exception {
Session session = getSessionForTestModel(getRequiredTestModel());
Expand All @@ -42,26 +46,54 @@ public void test() throws Exception {

// Switch to exchange category
new SwitchTool(diagramContext, IToolNameConstants.TOOL_LAB_INSERT_REMOVE_EXCHANGE_CATEGORIES)
.insert(EXCHANGE_CATEGORY_TO_BE_SHOWN);
.insert(EXCHANGE_CATEGORY_1);

diagramContext.hasView(EXCHANGE_CATEGORY_TO_BE_SHOWN);
diagramContext.hasView(EXCHANGE_CATEGORY_1);

Assert.assertFalse("The internal physical path should be removed", diagramContext.hasEdge(PORT_TO_BE_HIDDEN, PORT_2, INTERNAL_FUNCTIONAL_CHAIN_TO_BE_REMOVED));
Assert.assertFalse("The internal functional chain should be removed",
diagramContext.hasEdge(PORT_OUT_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4,
PORT_IN_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4,
INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4));

diagramContext.hasHiddenView(PORT_TO_BE_HIDDEN);
diagramContext.hasHiddenView(PORT_OUT_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4);

diagramContext.hasHiddenView(FUNCTIONAL_EXCHANGE_TO_BE_HIDDEN);
diagramContext.hasHiddenView(FUNCTIONAL_EXCHANGE_2);

// Switch again to functional exchange
new SwitchTool(diagramContext, IToolNameConstants.TOOL_LAB_INSERT_REMOVE_EXCHANGE_CATEGORIES)
.remove(EXCHANGE_CATEGORY_TO_BE_SHOWN);
diagramContext.hasntView(EXCHANGE_CATEGORY_TO_BE_SHOWN);
.remove(EXCHANGE_CATEGORY_1);
diagramContext.hasntView(EXCHANGE_CATEGORY_1);

Assert.assertTrue("The internal physical path should be added", diagramContext.hasEdge(PORT_TO_BE_HIDDEN, PORT_2, INTERNAL_FUNCTIONAL_CHAIN_TO_BE_REMOVED));
Assert.assertTrue("The internal functional chain should be added",
diagramContext.hasEdge(PORT_OUT_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4,
PORT_IN_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4,
INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4));

diagramContext.hasView(PORT_TO_BE_HIDDEN);
diagramContext.hasView(PORT_OUT_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4);

diagramContext.hasView(FUNCTIONAL_EXCHANGE_TO_BE_HIDDEN);
diagramContext.hasView(FUNCTIONAL_EXCHANGE_2);


// Test Allocated Functions tool
// un-allocate
new InsertRemoveTool(diagramContext, IToolNameConstants.TOOL_LAB_INSERT_REMOVE_ALLOCATED_FUNCTIONS, LOGICAL_SYSTEM_CONTAINER)
.remove(LOGICAL_FUNCTION_5);
diagramContext.hasntView(LOGICAL_FUNCTION_5);
diagramContext.hasntView(FUNCTIONAL_EXCHANGE_3);
Assert.assertFalse("The internal functional chain should be removed",
diagramContext.hasEdge(PORT_OUT_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4,
PORT_IN_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4,
INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4));

// re-allocate
new InsertRemoveTool(diagramContext, IToolNameConstants.TOOL_LAB_INSERT_REMOVE_ALLOCATED_FUNCTIONS, LOGICAL_SYSTEM_CONTAINER)
.insert(LOGICAL_FUNCTION_5);
diagramContext.hasView(LOGICAL_FUNCTION_5);
diagramContext.hasView(FUNCTIONAL_EXCHANGE_3);
Assert.assertTrue("The internal functional chain should be added",
diagramContext.hasEdge(PORT_OUT_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4,
PORT_IN_OF_INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4,
INTERNAL_FUNCTIONAL_CHAIN_IN_LOGICAL_FUNCTION_4));
}

@Override
Expand Down

0 comments on commit e3b9213

Please sign in to comment.