From 3b1aff1b4d7421ef003e04f51bf0394b8448d980 Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Mon, 28 Sep 2009 16:22:09 +0000 Subject: [PATCH] Update on EBRDDs --- src/req/ebrdd/EBRDD.java | 39 ++++++++++++++++++ src/req/ebrdd/EBRDDERC.java | 36 ++++++++++++++++- src/req/ebrdd/ERB.java | 5 +++ src/req/ebrdd/ERCElement.java | 4 ++ src/req/ebrdd/ESO.java | 14 ++++++- src/ui/CorrespondanceTGElement.java | 11 +++++ src/ui/EBRDDTranslator.java | 62 +++++++++++++++++++---------- src/ui/GTURTLEModeling.java | 1 + src/ui/ebrdd/EBRDDERB.java | 8 ++-- 9 files changed, 153 insertions(+), 27 deletions(-) diff --git a/src/req/ebrdd/EBRDD.java b/src/req/ebrdd/EBRDD.java index 976575f00c..2acf10c351 100644 --- a/src/req/ebrdd/EBRDD.java +++ b/src/req/ebrdd/EBRDD.java @@ -113,6 +113,45 @@ public class EBRDD extends ArrayList<EBRDDComponent> { } return null; } + + public String toString() { + StringBuffer sb = new StringBuffer("EBRDD="); + + if (ads != null) { + exploreString(ads, sb, 0); + } + + return sb.toString(); + } + + public void exploreString(EBRDDComponent elt, StringBuffer sb, int tabLevel) { + int j; + for(j=0; j<tabLevel; j++) { + sb.append("\t"); + } + sb.append(elt.toString() + "\n"); + + if (elt instanceof EBRDDERC) { + ((EBRDDERC)elt).exploreString(((EBRDDERC)elt).getRoot(), sb, tabLevel+1); + } + + if (elt.getRealNbOfNext() == 0) { + return; + } + if (elt.getRealNbOfNext() == 1) { + exploreString(elt.getNext(0), sb, tabLevel); + return; + } + + tabLevel ++; + for(int i=0; i<elt.getRealNbOfNext(); i++) { + for(j=0; j<tabLevel; j++) { + sb.append("\t"); + } + sb.append("#" + i + ":\n"); + exploreString(elt.getNext(i), sb, tabLevel+1); + } + } diff --git a/src/req/ebrdd/EBRDDERC.java b/src/req/ebrdd/EBRDDERC.java index d32ab42dfc..8130f82d0f 100644 --- a/src/req/ebrdd/EBRDDERC.java +++ b/src/req/ebrdd/EBRDDERC.java @@ -85,6 +85,7 @@ public class EBRDDERC extends EBRDDComponent { public boolean makeRoot() { if (treeElements.size() ==0) { + System.out.println("Empty tree"); return false; } @@ -98,6 +99,7 @@ public class EBRDDERC extends EBRDDComponent { if (cpt != 1) { // The ERB is the son of several ESOs or // The ERB is not attached to an ESO + System.out.println("Malformed ERB: " + cpt); return false; } } @@ -105,6 +107,7 @@ public class EBRDDERC extends EBRDDComponent { if (elt instanceof ESO) { // Must check that all ESO have at least one son if (((ESO)elt).getNbOfSons() == 0) { + System.out.println("ESO with no son"); return false; } @@ -114,6 +117,7 @@ public class EBRDDERC extends EBRDDComponent { if (isRoot((ESO)elt)) { if (root != null) { // Second root!! + System.out.println("More than one root"); return false; } else { root = (ESO)elt; @@ -124,12 +128,16 @@ public class EBRDDERC extends EBRDDComponent { // no root found! if (root == null) { + System.out.println("no root found"); return false; } + setRoot(root); + // Must check that there is no cycle in the tree ArrayList<ERCElement> mets = new ArrayList<ERCElement>(); - if (!hasCycle(root, mets)) { + if (hasCycle(root, mets)) { + System.out.println("hasCycle"); return false; } @@ -187,4 +195,30 @@ public class EBRDDERC extends EBRDDComponent { } } } + + public void exploreString(ERCElement elt, StringBuffer sb, int tabLevel) { + if (elt == null) { + return; + } + + int j; + for(j=0; j<tabLevel; j++) { + sb.append("\t"); + } + sb.append(elt.toString() + "\n"); + + if (elt instanceof ESO) { + ESO eso = (ESO)elt; + tabLevel ++; + for(int i=0; i<eso.getNbOfSons(); i++) { + for(j=0; j<tabLevel; j++) { + sb.append("\t"); + } + sb.append("#" + i + ":\n"); + exploreString(eso.getSon(i), sb, tabLevel+1); + } + } + + + } } \ No newline at end of file diff --git a/src/req/ebrdd/ERB.java b/src/req/ebrdd/ERB.java index 9b391b8131..1c1aa83d3e 100644 --- a/src/req/ebrdd/ERB.java +++ b/src/req/ebrdd/ERB.java @@ -78,6 +78,11 @@ public class ERB extends ERCElement { public String getAction() { return action; } + + public String toString() { + String s = "ERB(" + evt + ", " + condition + ", " + action + ")"; + return s; + } diff --git a/src/req/ebrdd/ERCElement.java b/src/req/ebrdd/ERCElement.java index fa1776767e..ec71bf3383 100644 --- a/src/req/ebrdd/ERCElement.java +++ b/src/req/ebrdd/ERCElement.java @@ -60,4 +60,8 @@ public abstract class ERCElement extends EBRDDGeneralComponent implements Clonea public boolean isNegated() { return negated; } + + public String superString() { + return super.toString(); + } } \ No newline at end of file diff --git a/src/req/ebrdd/ESO.java b/src/req/ebrdd/ESO.java index 12f6e5f573..03fd0e30bc 100644 --- a/src/req/ebrdd/ESO.java +++ b/src/req/ebrdd/ESO.java @@ -48,7 +48,7 @@ package req.ebrdd; import java.util.*; public class ESO extends ERCElement { - //public final static String [] ESOS = {"Conjunction", "Disjunction", "Sequence", "Strict sequence", "Simultaneous", "At least/At most"}; + public final static String [] ESOSTR = {"Conjunction", "Disjunction", "Sequence", "Strict sequence", "Simultaneous", "At least/At most"}; protected ArrayList<ERCElement> sons; protected int id; @@ -180,5 +180,17 @@ public class ESO extends ERCElement { return cpt; } + + public String toString() { + String s = "ESO " + super.toString() + " " + IDToString() + " timeOut=" + timeout + " oncePerEvent=" + oncePerEvent + " n=" + n + " m=" + m; + /*for(int i=0; i<sons.size(); i++) { + s += " son#" + i + ":" + sons.get(i).superString(); + }*/ + return s; + } + + public String IDToString() { + return ESOSTR[id]; + } } \ No newline at end of file diff --git a/src/ui/CorrespondanceTGElement.java b/src/ui/CorrespondanceTGElement.java index a79f7b55fe..dab064a7ed 100755 --- a/src/ui/CorrespondanceTGElement.java +++ b/src/ui/CorrespondanceTGElement.java @@ -246,6 +246,17 @@ public class CorrespondanceTGElement { return null; } + public EBRDDComponent getEBRDDComponent(TGComponent tgc) { + int index = tg.indexOf(tgc); + if ((index != -1) && (data.size() > index)) { + Object o = data.elementAt(index); + if (o instanceof EBRDDComponent) { + return (EBRDDComponent)o; + } + } + return null; + } + public ArrayList<ADComponent> getADComponents(TGComponent tgc) { ArrayList<ADComponent> list = new ArrayList<ADComponent>(); TGComponent tmptgc; diff --git a/src/ui/EBRDDTranslator.java b/src/ui/EBRDDTranslator.java index b233f796f0..e9f3b822a0 100755 --- a/src/ui/EBRDDTranslator.java +++ b/src/ui/EBRDDTranslator.java @@ -102,7 +102,7 @@ public class EBRDDTranslator { // Search for start state LinkedList list = ebrddp.getComponentList(); Iterator iterator = list.listIterator(); - TGComponent tgc, tgc1, tgc2, tgc3; + TGComponent tgc, tgc1, tgc2, tgc3, tgc1tmp, tgc2tmp; TGComponent tss = null; int cptStart = 0; @@ -221,6 +221,7 @@ public class EBRDDTranslator { eso.setOncePerEvent(esotgc.getOncePerEvent()); eso.setN(esotgc.getN()); eso.setM(esotgc.getM()); + erc.addTreeElement(eso); } else if (tgc1 instanceof ui.ebrdd.EBRDDERB) { System.out.println("ERB found"); @@ -230,6 +231,7 @@ public class EBRDDTranslator { erb.setEvent(erbtgc.getEvent()); erb.setAction(erbtgc.getAction()); erb.setCondition(erbtgc.getCondition()); + erc.addTreeElement(erb); } } } @@ -238,7 +240,9 @@ public class EBRDDTranslator { // Interconnection between elements - TGConnectorEBRDD tgco; + //TGConnectorEBRDD tgco; + //TGConnectorEBRDDERC tgcoerc; + TGConnector tgco; TGConnectingPoint p1, p2; EBRDDComponent eb1, eb2; EBRDDGeneralComponent ebg1, ebg2; @@ -247,8 +251,9 @@ public class EBRDDTranslator { iterator = list.listIterator(); while(iterator.hasNext()) { tgc = (TGComponent)(iterator.next()); - if (tgc instanceof TGConnectorEBRDD) { - tgco = (TGConnectorEBRDD)tgc; + if (tgc instanceof TGConnector) { + //tgco = (TGConnectorEBRDD)tgc; + tgco = (TGConnector)tgc; p1 = tgco.getTGConnectingPointP1(); p2 = tgco.getTGConnectingPointP2(); @@ -256,12 +261,15 @@ public class EBRDDTranslator { tgc1 = null; tgc2 = null; for(j=0; j<list.size(); j++) { tgc3 = (TGComponent)(list.get(j)); - if (tgc3.belongsToMe(p1)) { - tgc1 = tgc3; - } - if (tgc3.belongsToMe(p2)) { - tgc2 = tgc3; - } + tgc1tmp = tgc3.belongsToMeOrSon(p1); + tgc2tmp = tgc3.belongsToMeOrSon(p2); + if (tgc1tmp != null) { + tgc1 = tgc1tmp; + } + if (tgc2tmp != null) { + tgc2 = tgc2tmp; + } + } // Connecting ebrdd modeling components @@ -270,7 +278,8 @@ public class EBRDDTranslator { ebg1 = listE.getEBRDDGeneralComponent(tgc1); ebg2 = listE.getEBRDDGeneralComponent(tgc2); if ((ebg1 != null ) && (ebg2 != null)) { - if ((ebg1 instanceof EBRDDComponent) && (ebg2 instanceof EBRDDComponent)) { + if ((ebg1 instanceof EBRDDComponent) && (ebg2 instanceof EBRDDComponent)) { + System.out.println("Adding link"); eb1 = (EBRDDComponent)ebg1; eb2 = (EBRDDComponent)ebg2; //Special case if "for loop" or if "choice" @@ -297,6 +306,7 @@ public class EBRDDTranslator { eb1.addNext(eb2); } } else if ((ebg1 instanceof ERCElement) && (ebg2 instanceof ERCElement)) { + //System.out.println("ERCElements!"); if (ebg1 instanceof req.ebrdd.ESO) { index = tgc1.indexOf(p1) - 1; ((req.ebrdd.ESO)ebg1).addIndex(index); @@ -306,8 +316,18 @@ public class EBRDDTranslator { } } } - } + } } + + // Sorting nexts elements of Sequence and ESOs + for(j=0; j<ebrdd.size(); j++) { + eb1 = ebrdd.get(j); + if (eb1 instanceof req.ebrdd.EBRDDSequence) { + ((req.ebrdd.EBRDDSequence)eb1).sortNexts(); + } else if (eb1 instanceof req.ebrdd.EBRDDERC) { + ((req.ebrdd.EBRDDERC)eb1).sortNexts(); + } + } // Check that each "for" has two nexts // Check that Choice have compatible guards @@ -331,20 +351,20 @@ public class EBRDDTranslator { CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Loop should have exactly two next elements"); ce.setTDiagramPanel(ebrddp); ce.setTGComponent(tgc); + checkingErrors.add(ce); + } + } else if (tgc instanceof ui.ebrdd.EBRDDERC) { + erc = (req.ebrdd.EBRDDERC)(listE.getEBRDDGeneralComponent(tgc)); + if (!erc.makeRoot()) { + CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Badly formed ERC"); + ce.setTDiagramPanel(ebrddp); + ce.setTGComponent(tgc); checkingErrors.add(ce); } } } - // Sorting nexts elements of Sequence and ESOs - for(j=0; j<ebrdd.size(); j++) { - eb1 = ebrdd.get(j); - if (eb1 instanceof req.ebrdd.EBRDDSequence) { - ((req.ebrdd.EBRDDSequence)eb1).sortNexts(); - } else if (eb1 instanceof req.ebrdd.EBRDDERC) { - ((req.ebrdd.EBRDDERC)eb1).sortNexts(); - } - } + // Remove all elements not reachable from start state diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java index 55f7eab609..62dfaf04bf 100755 --- a/src/ui/GTURTLEModeling.java +++ b/src/ui/GTURTLEModeling.java @@ -4852,6 +4852,7 @@ public class GTURTLEModeling { if (checkingErrors.size() > 0) { return false; } + System.out.println("the EBRDD:\n" + ebrdd.toString()); return true; } diff --git a/src/ui/ebrdd/EBRDDERB.java b/src/ui/ebrdd/EBRDDERB.java index af2f9c0af3..af293f94eb 100644 --- a/src/ui/ebrdd/EBRDDERB.java +++ b/src/ui/ebrdd/EBRDDERB.java @@ -174,16 +174,16 @@ public class EBRDDERB extends TGCOneLineText implements SwallowedTGComponent { } val = dialog.getCondition().trim(); - if (val.length() == 0) { + /*if (val.length() == 0) { error = true; errors += "condition "; - } + }*/ val = dialog.getAction().trim(); - if (val.length() == 0) { + /*if (val.length() == 0) { error = true; errors += "action "; - } + }*/ if (error) { -- GitLab