From c333766940513e9a2b9fa3c244b7298a5bd3d5a4 Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Tue, 11 Mar 2014 16:49:00 +0000 Subject: [PATCH] DIPLO: Update on paths checking at component level --- src/ui/tmlcompd/TMLCPath.java | 68 ++++++++- .../TMLComponentTaskDiagramPanel.java | 140 +++++++++++++++++- 2 files changed, 202 insertions(+), 6 deletions(-) diff --git a/src/ui/tmlcompd/TMLCPath.java b/src/ui/tmlcompd/TMLCPath.java index bf5c8e4d1b..364f5aeef3 100755 --- a/src/ui/tmlcompd/TMLCPath.java +++ b/src/ui/tmlcompd/TMLCPath.java @@ -70,7 +70,10 @@ public class TMLCPath { private int errorNumber; private String[] errors = {"Fork and Join operators in the same path", - "More than one producer in a path with a fork"}; + "Must have at least one sender", + "Must have at least one receiver", + "More than one sender in a path with a fork", + "Senders and receivers are not of the same kind"}; public TMLCPath() { cports = new ArrayList<TMLCCompositePort>(); @@ -105,6 +108,31 @@ public class TMLCPath { } + public boolean contains(TGComponent tgc) { + if (cports.contains(tgc)) { + return true; + } + + if (producerPorts.contains(tgc)) { + return true; + } + + if (consumerPorts.contains(tgc)) { + return true; + } + + if (forks.contains(tgc)) { + return true; + } + + if (joins.contains(tgc)) { + return true; + } + + return false; + + } + public void mergeWith(TMLCPath _path) { cports.addAll(_path.cports); producerPorts.addAll(_path.producerPorts); @@ -118,6 +146,14 @@ public class TMLCPath { return (errorNumber != -1); } + public String getErrorMessage() { + if (hasError()) { + return errors[errorNumber]; + } + + return ""; + } + public void checkRules() { errorNumber = -1; @@ -127,10 +163,36 @@ public class TMLCPath { errorNumber = 0; } - // If fork: must have only one producer - if ((forks.size() > 0) && (producerPorts.size() >1)) { + //rule1: Must have at least one producer + if (producerPorts.size() == 0) { errorNumber = 1; } + + //rule2: Must have at least one receiver + if (consumerPorts.size() == 0) { + errorNumber = 2; + } + + //rule3: If fork: must have only one producer + if ((forks.size() > 0) && (producerPorts.size() >1)) { + errorNumber = 3; + } + + //rule4: producers and consumers must be of the same type + if ((forks.size() > 0) && (producerPorts.size() >1)) { + errorNumber = 4; + } + } + + public void setColor() { + /*if (hasError()) { + // Setting the red color + }*/ + + // set the inp and outp primitive ports if possible (otherwise, null) + + // if no error: set conflict to false + // If error -> set the conflict to true } diff --git a/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java b/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java index 56f1ea8ffd..4971791841 100755 --- a/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java +++ b/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java @@ -803,7 +803,21 @@ public class TMLComponentTaskDiagramPanel extends TDiagramPanel implements TDPWi } public void updatePorts() { - makePaths(); + TraceManager.addDev("Making paths"); + ArrayList<TMLCPath> paths = makePaths(); + + // Checking rules of paths, and setting colors accordingly + for(TMLCPath path: paths) { + path.checkRules(); + if (path.hasError()) { + TraceManager.addDev("Path error:" + path.getErrorMessage()); + } + path.setColor(); + } + + } + + public void updatePorts_oldVersion() { TraceManager.addDev("Update ports / nb of components = " + componentList.size()); Iterator iterator; @@ -1239,7 +1253,127 @@ public class TMLComponentTaskDiagramPanel extends TDiagramPanel implements TDPWi return getRecordNamed((TMLCCompositeComponent)(comp.getFather()), _nameOfRecord); } - public void makePaths() { - TMLCPath path; + public ArrayList<TMLCPath> makePaths() { + ArrayList<TMLCPath> paths = new ArrayList<TMLCPath>(); + + + // Go through the compnent lisg, and make paths. Then, go thru connectors, and merge paths until no + // more merging is possible + + ListIterator iterator = componentList.listIterator(); + TGComponent tgc; + + ArrayList<TMLCCompositePort> listcp; + ArrayList<TMLCPrimitivePort> listpp; + + + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + + if (tgc instanceof TMLCCompositeComponent) { + listcp = ((TMLCCompositeComponent)tgc).getAllInternalCompositePorts(); + for(TMLCCompositePort cp: listcp) { + addToPaths(paths, cp); + } + + listpp = ((TMLCCompositeComponent)tgc).getAllInternalPrimitivePorts(); + for(TMLCPrimitivePort pp: listpp) { + addToPaths(paths, pp); + } + + /*referencedports.addAll(((TMLCCompositeComponent)tgc).getAllReferencedCompositePorts());*/ + } + + /*if (tgc instanceof TMLCRemoteCompositeComponent) { + ports.addAll(((TMLCRemoteCompositeComponent)tgc).getAllInternalCompositePorts()); + pports.addAll(((TMLCRemoteCompositeComponent)tgc).getAllInternalPrimitivePorts()); + }*/ + + if (tgc instanceof TMLCPrimitiveComponent) { + listpp = ((TMLCPrimitiveComponent)tgc).getAllInternalPrimitivePorts(); + for(TMLCPrimitivePort pp: listpp) { + addToPaths(paths, pp); + } + } + + if (tgc instanceof TMLCPrimitivePort) { + addToPaths(paths, tgc); + } + + if (tgc instanceof TMLCChannelFacility) { + addToPaths(paths, tgc); + } + } + + + // Use connectors to merge paths with one another + iterator = componentList.listIterator(); + TMLCPortConnector connector; + TGComponent tgc1, tgc2; + TMLCPath path1, path2; + + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + + if (tgc instanceof TMLCPortConnector) { + connector = (TMLCPortConnector)tgc; + if (connector.getTGConnectingPointP1().getFather() instanceof TGComponent) { + tgc1 = (TGComponent)(connector.getTGConnectingPointP1().getFather()); + } else { + tgc1 = null; + } + if (connector.getTGConnectingPointP2().getFather() instanceof TGComponent) { + tgc2 = (TGComponent)(connector.getTGConnectingPointP2().getFather()); + } else { + tgc2 = null; + } + if ((tgc1 != null) && (tgc2 != null) && (tgc1 != tgc2)) { + path1 = getPathOf(paths, tgc1); + path2 = getPathOf(paths, tgc2); + if ((path1 != null) && (path2 != null)) { + // Not in the same path -> we must do a merging + // and then we remove path2 from path + if (path1 != path2) { + path1.mergeWith(path2); + paths.remove(path2); + } + } + } + + } + } + + TraceManager.addDev("----------- Nb of paths: " + paths.size()); + + + return paths; + + } + + public TMLCPath getPathOf(ArrayList<TMLCPath> paths, TGComponent tgc) { + for(TMLCPath path: paths) { + if (path.contains(tgc)) { + return path; + } + } + + return null; + } + + public void addToPaths(ArrayList<TMLCPath> paths, TGComponent tgc) { + Boolean found = false; + + for(TMLCPath path: paths) { + if (path.contains(tgc)) { + found = true; + return; + } + } + + // Create a new path + TMLCPath ph = new TMLCPath(); + ph.addComponent(tgc); + paths.add(ph); + } } -- GitLab