From 218a9c602aaf36482cbe90539726a3c4e1d3090c Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Tue, 22 Sep 2009 15:40:13 +0000 Subject: [PATCH] Generation of EBRDDs --- src/req/ebrdd/EBRDD.java | 40 ++ src/req/ebrdd/EBRDDChoice.java | 159 ++++++ src/req/ebrdd/EBRDDComponent.java | 12 + src/req/ebrdd/EBRDDERC.java | 79 +++ src/req/ebrdd/EBRDDSequence.java | 128 +++-- src/req/ebrdd/ERB.java | 84 +++ src/req/ebrdd/ERCElement.java | 63 +++ src/req/ebrdd/ESO.java | 121 ++++ src/ui/CorrespondanceTGElement.java | 12 + src/ui/EBRDDTranslator.java | 839 +++++----------------------- 10 files changed, 801 insertions(+), 736 deletions(-) create mode 100755 src/req/ebrdd/EBRDDChoice.java create mode 100644 src/req/ebrdd/EBRDDERC.java create mode 100644 src/req/ebrdd/ERB.java create mode 100644 src/req/ebrdd/ERCElement.java create mode 100644 src/req/ebrdd/ESO.java diff --git a/src/req/ebrdd/EBRDD.java b/src/req/ebrdd/EBRDD.java index 08efc98d03..976575f00c 100644 --- a/src/req/ebrdd/EBRDD.java +++ b/src/req/ebrdd/EBRDD.java @@ -75,5 +75,45 @@ public class EBRDD extends ArrayList<EBRDDComponent> { public EBRDDComponent getEBRDDComponent(int index) { return get(index); } + + public void removeAllNonReferencedElts() { + EBRDDComponent adc; + while((adc = hasNonReferencedElts()) != null) { + remove(adc); + } + } + + public EBRDDComponent hasNonReferencedElts() { + EBRDDComponent adc; + EBRDDComponent adc1; + for(int i=0; i<size(); i++) { + adc = (EBRDDComponent)(get(i)); + if (adc != ads) { + adc1 = getFirstComponentLeadingTo(adc); + if (adc1 == null) { + // no component! + return adc; + } + } + } + return null; + } + + public EBRDDComponent getFirstComponentLeadingTo(EBRDDComponent ad) { + EBRDDComponent ad1; + int i, j; + + for (i=0; i<size(); i++) { + ad1 = get(i); + for(j=0; j<ad1.getNbNext(); j++) { + if (ad1.getNext(j) == ad) { + return ad1; + } + } + } + return null; + } + + } diff --git a/src/req/ebrdd/EBRDDChoice.java b/src/req/ebrdd/EBRDDChoice.java new file mode 100755 index 0000000000..50b98444ff --- /dev/null +++ b/src/req/ebrdd/EBRDDChoice.java @@ -0,0 +1,159 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + /** + * Class EBRDDLoop + * Creation: 22/09/2009 + * @version 1.0 22/09/2009 + * @author Ludovic APVRILLE + * @see + */ + +package req.ebrdd; + +import java.util.*; + +import myutil.*; + +public class EBRDDChoice extends EBRDDComponent { + private ArrayList<String> guards; + + public EBRDDChoice() { + nbNext = -1; + guards = new ArrayList<String>(); + } + + public void addGuard(String _g) { + guards.add(_g); + } + + public int getNbGuard() { + return guards.size(); + } + + public String getGuard(int i) { + if (i < getNbGuard()) { + return guards.get(i); + } else { + return null; + } + } + + + + public void setGuardAt(int _i, String _g) { + guards.set(_i, _g); + } + + public boolean hasMoreThanOneElse() { + int cpt = 0; + String guard; + for(int i=0; i<getNbGuard(); i++) { + guard = getGuard(i); + guard = Conversion.replaceAllChar(guard, '[', " "); + guard = Conversion.replaceAllChar(guard, ']', " "); + guard = guard.trim(); + if (guard.compareTo("else") == 0) { + cpt ++; + } + } + + return (cpt > 1); + } + + + public int getElseGuard() { + //int cpt = 0; + String guard; + for(int i=0; i<getNbGuard(); i++) { + guard = getGuard(i); + guard = Conversion.replaceAllChar(guard, '[', " "); + guard = Conversion.replaceAllChar(guard, ']', " "); + guard = guard.trim(); + if (guard.compareTo("else") == 0) { + return i; + } + } + + return -1; + } + + public String getValueOfElse() { + String g = ""; + int cpt = 0; + String guard; + + for(int i=0; i<getNbGuard(); i++) { + guard = getGuard(i); + guard = Conversion.replaceAllChar(guard, '[', " "); + guard = Conversion.replaceAllChar(guard, ']', " "); + guard = guard.trim(); + if ((!(guard.compareTo("else") == 0)) && (!(guard.compareTo("after") == 0))) { + guard = getGuard(i); + guard = Conversion.replaceAllChar(guard, '[', "("); + guard = Conversion.replaceAllChar(guard, ']', ")"); + guard = "(" + guard + ")"; + if (cpt == 0) { + g = guard; + } else { + g = g + " or " +guard; + } + cpt ++; + } + } + + return "[not(" + g + ")]"; + } + + public void orderGuards() { + int index; + String guard; + EBRDDComponent next; + + // Put else at the end + index = getElseGuard(); + if ((index > -1) && (index != (getNbGuard() - 1))) { + next = getNext(index); + guard = getGuard(index); + guards.remove(index); + removeNext(index); + addNext(next); + addGuard(guard); + } + } + +} \ No newline at end of file diff --git a/src/req/ebrdd/EBRDDComponent.java b/src/req/ebrdd/EBRDDComponent.java index 0d7e03bb5f..0758a8c651 100644 --- a/src/req/ebrdd/EBRDDComponent.java +++ b/src/req/ebrdd/EBRDDComponent.java @@ -80,5 +80,17 @@ public abstract class EBRDDComponent implements Cloneable { public ArrayList<EBRDDComponent> getAllNext() { return nexts; } + + public void addNext(EBRDDComponent _comp) { + nexts.add(_comp); + } + + public void addNext(int _index, EBRDDComponent _comp) { + nexts.add(_index, _comp); + } + + public void removeNext(int index) { + nexts.remove(index); + } } \ No newline at end of file diff --git a/src/req/ebrdd/EBRDDERC.java b/src/req/ebrdd/EBRDDERC.java new file mode 100644 index 0000000000..229dc870f8 --- /dev/null +++ b/src/req/ebrdd/EBRDDERC.java @@ -0,0 +1,79 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class EBRDDERC + * Creation: 22/09/2009 + * @version 1.0 22/09/2009 + * @author Ludovic APVRILLE + * @see + */ + +package req.ebrdd; + +import java.util.*; + + +public class EBRDDERC extends EBRDDComponent { + protected ArrayList<ERCElement> treeElements; + protected ESO root; + + public EBRDDERC() { + treeElements = new ArrayList<ERCElement>(); + } + + public String toString() { + return "EBRDERC: " + treeElements.size(); + } + + + public void setRoot(ESO _root) { + root = _root; + } + + public ESO getRoot() { + return root; + } + + public ArrayList<ERCElement> getTreeElements() { + return treeElements; + } + + public void addTreeElement(ERCElement elt) { + treeElements.add(elt); + } +} \ No newline at end of file diff --git a/src/req/ebrdd/EBRDDSequence.java b/src/req/ebrdd/EBRDDSequence.java index a9b8203161..dfdf1383e2 100644 --- a/src/req/ebrdd/EBRDDSequence.java +++ b/src/req/ebrdd/EBRDDSequence.java @@ -1,59 +1,101 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille - -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * /** * Class EBRDDSequence - * Creation: 18/09/2009 - * @version 1.0 18/09/2009 + * Creation: 22/09/2009 + * @version 1.0 22/09/2009 * @author Ludovic APVRILLE * @see */ package req.ebrdd; +import java.util.*; -public class EBRDDSequence extends EBRDDComponent { +public class EBRDDSequence extends EBRDDComponent{ + private Vector indexes; public EBRDDSequence() { - nbNext = -1; + nbNext = -1; + indexes = new Vector(); } - public String toString() { - return "Start state"; + public void addIndex(int index) { + indexes.add(new Integer(index)); } -} \ No newline at end of file + + public void sortNexts() { + if (indexes.size() == 0) { + return; + } + + //System.out.println("Nb of indexes" + indexes.size()); + //System.out.println("Nb of nexts" + nexts.size()); + ArrayList<EBRDDComponent> nextsbis = new ArrayList<EBRDDComponent>(); + + // Sort according to index stored in indexes + // The smaller is removed at each step + Integer i0; + int index; + int i; + + while(indexes.size() > 0) { + i0 = new Integer(1000); + index = -1; + for(i=0; i<indexes.size(); i++) { + if ((((Integer)indexes.elementAt(i)).compareTo(i0))<0) { + index = i; + i0 = ((Integer)indexes.elementAt(i)); + } + } + nextsbis.add(nexts.get(index)); + nexts.remove(index); + indexes.remove(index); + } + + nexts = nextsbis; + + //for(i=0; i<nexts.size(); i++){ + // System.out.println("sequence #" + i + " = " + nexts.elementAt(i)); + //} + + } + + +} diff --git a/src/req/ebrdd/ERB.java b/src/req/ebrdd/ERB.java new file mode 100644 index 0000000000..9b391b8131 --- /dev/null +++ b/src/req/ebrdd/ERB.java @@ -0,0 +1,84 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class ERB + * Event Reaction Block + * Creation: 22/09/2009 + * @version 1.0 22/09/2009 + * @author Ludovic APVRILLE + * @see + */ + +package req.ebrdd; + +import java.util.*; + +public class ERB extends ERCElement { + + protected String evt, condition, action; + + public ERB() { + } + + public void setEvent(String _evt) { + evt = _evt; + } + + public void setCondition(String _condition) { + condition = _condition; + } + + public void setAction(String _action) { + action = _action; + } + + public String getEvent() { + return evt; + } + + public String getCondition() { + return condition; + } + + public String getAction() { + return action; + } + + + +} \ No newline at end of file diff --git a/src/req/ebrdd/ERCElement.java b/src/req/ebrdd/ERCElement.java new file mode 100644 index 0000000000..ca1dc04769 --- /dev/null +++ b/src/req/ebrdd/ERCElement.java @@ -0,0 +1,63 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class ERCElement + * Creation: 22/09/2009 + * @version 1.0 22/09/2009 + * @author Ludovic APVRILLE + * @see + */ + +package req.ebrdd; + +import java.util.*; + +public abstract class ERCElement implements Cloneable { + protected boolean negated; + + public ERCElement() { + } + + public void setNegated(boolean _negated) { + negated = _negated; + } + + public boolean isNegated() { + return negated; + } +} \ No newline at end of file diff --git a/src/req/ebrdd/ESO.java b/src/req/ebrdd/ESO.java new file mode 100644 index 0000000000..4f0b2bb337 --- /dev/null +++ b/src/req/ebrdd/ESO.java @@ -0,0 +1,121 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class ESO + * Creation: 22/09/2009 + * @version 1.0 22/09/2009 + * @author Ludovic APVRILLE + * @see + */ + +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"}; + + protected ArrayList<ERCElement> nexts; + protected int id; + protected int timeout; + protected boolean oncePerEvent; + protected int n, m; + + + public ESO() { + nexts = new ArrayList<ERCElement>(); + } + + + public ERCElement getNext(int index) { + if (index < nexts.size()) { + return nexts.get(index); + } else { + return null; + } + } + + public int getNbNext() { + return nexts.size(); + } + + public ArrayList<ERCElement> getAllNext() { + return nexts; + } + + public int getID() { + return id; + } + + public int getTimeout() { + return timeout; + } + + public boolean getOncePerEvent() { + return oncePerEvent; + } + + public int getN() { + return n; + } + + public int getM() { + return m; + } + + public void setID(int _id) { + id = _id; + } + + public void setTimeout(int _timeout) { + timeout = _timeout; + } + + public void setOncePerEvent(boolean _oncePerEvent) { + oncePerEvent = _oncePerEvent; + } + + public void setN(int _n) { + n = _n; + } + + public void setM(int _m) { + m = _m; + } + +} \ No newline at end of file diff --git a/src/ui/CorrespondanceTGElement.java b/src/ui/CorrespondanceTGElement.java index 2d2f11926b..636b47b4b8 100755 --- a/src/ui/CorrespondanceTGElement.java +++ b/src/ui/CorrespondanceTGElement.java @@ -50,6 +50,7 @@ package ui; import java.awt.*; import java.util.*; +import req.ebrdd.*; import translator.*; import tmltranslator.*; import sddescription.*; @@ -234,6 +235,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 fe92bf53f8..04236b2465 100755 --- a/src/ui/EBRDDTranslator.java +++ b/src/ui/EBRDDTranslator.java @@ -129,725 +129,178 @@ public class EBRDDTranslator { } - /*TADActionState tadas; + req.ebrdd.EBRDDActionState acst; + req.ebrdd.EBRDDChoice ch; + req.ebrdd.EBRDDERC erc; + req.ebrdd.EBRDDLoop loop; + req.ebrdd.EBRDDSequence seq; + req.ebrdd.EBRDDStart start; + req.ebrdd.EBRDDStop stop; + ESO eso; + ERB erb; - ADStart ads; - //ADActionState ada; - ADActionStateWithGate adag; - ADActionStateWithParam adap; - ADActionStateWithMultipleParam adamp; - ADChoice adch; - ADDelay add; - ADJunction adj; - ADLatency adl; - ADParallel adp; - ADSequence adseq; - ADPreempt adpre; - ADStop adst; - ADTimeInterval adti; - ADTLO adtlo; - ADTimeCapture adtc; - String s, s1; - Gate g; - Param p; - - int nbActions; - String sTmp; - - // Creation of the activity diagram - ads = new ADStart(); - listE.addCor(ads, tss); - ActivityDiagram ad = new ActivityDiagram(ads); - t.setActivityDiagram(ad); - //System.out.println("Making activity diagram of " + t.getName()); + start = ebrdd.getStartState(); + listE.addCor(start, tss); // Creation of other elements iterator = list.listIterator(); while(iterator.hasNext()) { tgc = (TGComponent)(iterator.next()); - if (tgc instanceof TADActionState) { - tadas = (TADActionState)tgc; - s = ((TADActionState)tgc).getAction(); - s = s.trim(); - //remove ';' if last character - if (s.substring(s.length()-1, s.length()).compareTo(";") == 0) { - s = s.substring(0, s.length()-1); - } - nbActions = Conversion.nbChar(s, ';') + 1; - //System.out.println("Nb Actions in state: " + nbActions); - - s = TURTLEModeling.manageDataStructures(t, s); - - g = t.getGateFromActionState(s); - p = t.getParamFromActionState(s); - if ((g != null) && (nbActions == 1)){ - //System.out.println("Action state with gate found " + g.getName() + " value:" + t.getActionValueFromActionState(s)); - adag = new ADActionStateWithGate(g); - ad.addElement(adag); - s1 = t.getActionValueFromActionState(s); - //System.out.println("s1=" + s1); - //System.out.println("Adding type"); - s1 = TURTLEModeling.manageGateDataStructures(t, s1); - - //System.out.println("hi"); - if (s1 == null) { - //System.out.println("ho"); - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Invalid expression: " + t.getActionValueFromActionState(s)); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - tadas.setStateAction(ErrorHighlight.UNKNOWN_AS); - //return; - } else { - tadas.setStateAction(ErrorHighlight.GATE); - s1 = TURTLEModeling.addTypeToDataReceiving(t, s1); - - adag.setActionValue(s1); - //System.out.println("Adding correspondance tgc=" + tgc + "adag=" + adag); - listE.addCor(adag, tgc); - } - } else if ((p != null) && (nbActions == 1)){ - //System.out.println("Action state with param found " + p.getName() + " value:" + t.getExprValueFromActionState(s)); - if (t.getExprValueFromActionState(s).trim().startsWith("=")) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, s + " should not start with a '=='"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - tadas.setStateAction(ErrorHighlight.UNKNOWN_AS); - } - adap = new ADActionStateWithParam(p); - ad.addElement(adap); - adap.setActionValue(TURTLEModeling.manageDataStructures(t, t.getExprValueFromActionState(s))); - listE.addCor(adap, tgc); - tadas.setStateAction(ErrorHighlight.ATTRIBUTE); - - } else if ((p != null) && (nbActions > 1)){ - //System.out.println("Action state with multi param found " + p.getName() + " value:" + t.getExprValueFromActionState(s)); - // Checking params - CheckingError ce; - for(j=0; j<nbActions; j++) { - sTmp = TURTLEModeling.manageDataStructures(t,((TADActionState)(tgc)).getAction(j)); - if (sTmp == null) { - ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Action state (0) (" + s + "): \"" + s + "\" is not a correct expression"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - tadas.setStateAction(ErrorHighlight.UNKNOWN_AS); - } - - p = t.getParamFromActionState(sTmp); - if (p == null) { - ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Action state (1) (" + s + "): \"" + sTmp + "\" is not a correct expression"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - tadas.setStateAction(ErrorHighlight.UNKNOWN_AS); - } - } - tadas.setStateAction(ErrorHighlight.ATTRIBUTE); - adamp = new ADActionStateWithMultipleParam(); - ad.addElement(adamp); - adamp.setActionValue(TURTLEModeling.manageDataStructures(t, s)); - listE.addCor(adamp, tgc); - } else { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Action state (2) (" + s + "): \"" + s + "\" is not a correct expression"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - tadas.setStateAction(ErrorHighlight.UNKNOWN_AS); - //System.out.println("Bad action state found " + s); - } - - } else if (tgc instanceof TADTimeCapture) { - p = t.getParamByName(tgc.getValue().trim()); - if (p != null){ - System.out.println("Time capture with param " + p.getName()); - adtc = new ADTimeCapture(p); - ad.addElement(adtc); - ((TADTimeCapture)tgc).setStateAction(ErrorHighlight.ATTRIBUTE); - } else { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Unknown variable: " + tgc.getValue()); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ((TADTimeCapture)tgc).setStateAction(ErrorHighlight.UNKNOWN_AS); - } - - // Get element from Array - } else if (tgc instanceof TADArrayGetState) { - TADArrayGetState ags = (TADArrayGetState)tgc; - sTmp = ags.getIndex(); - try { - nbActions = Integer.decode(sTmp).intValue(); - - p = t.getParamByName(ags.getVariable()); - if (p == null) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Array setting: " + ags.getVariable() + ": unknown variable"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ags.setStateAction(ErrorHighlight.UNKNOWN); - } else { - adap = new ADActionStateWithParam(p); - p = t.getParamByName(ags.getArray() + "__" + nbActions); - if (p == null) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Array setting: " + ags.getArray() + "[" + ags.getIndex() + "]: unknown array or wrong index"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ags.setStateAction(ErrorHighlight.UNKNOWN); - } else { - ad.addElement(adap); - adap.setActionValue(TURTLEModeling.manageDataStructures(t, ags.getArray() + "__" + nbActions)); - listE.addCor(adap, tgc); - listB.addCor(adap, tgc); - ags.setStateAction(ErrorHighlight.OK); - } - } - } catch (Exception e) { - // Index is not an absolute value - System.out.println("Index is not an absolute value"); - Gate error = t.addNewGateIfApplicable("arrayOverflow"); - - ADChoice choice1 = new ADChoice(); - ADJunction junc = new ADJunction(); - ADStop stop1 = new ADStop(); - ADActionStateWithGate adag1 = new ADActionStateWithGate(error); - - ad.addElement(choice1); - ad.addElement(junc); - ad.addElement(stop1); - ad.addElement(adag1); - - String basicGuard = "(" + ags.getIndex() + ")"; - - p = t.getParamByName(ags.getArray() + "__size"); - - if (p == null) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Array setting: " + ags.getArray() + "[" + ags.getIndex() + "]: unknown array or wrong index"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ags.setStateAction(ErrorHighlight.UNKNOWN); - } else { - int size = 2; - try { - size = Integer.decode(p.getValue()).intValue(); - } catch (Exception e0) { - } - - p = t.getParamByName(ags.getVariable()); - - if (p == null) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Array setting: " + ags.getVariable() + ": unknown variable"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ags.setStateAction(ErrorHighlight.UNKNOWN); - } else { - for(int i=0; i<size; i++) { - //System.out.println("Adding guard: [" + basicGuard + "== " + i + "]"); - choice1.addGuard("[" + basicGuard + " == " + i + "]"); - adap = new ADActionStateWithParam(p); - ad.addElement(adap); - adap.setActionValue(TURTLEModeling.manageDataStructures(t, ags.getArray() + "__" + i)); - choice1.addNext(adap); - adap.addNext(junc); - ags.setStateAction(ErrorHighlight.OK); - } - - choice1.addGuard("[" + basicGuard + "> (" + ags.getArray() + "__size - 1)]"); - choice1.addNext(adag1); - adag1.addNext(stop1); - - listE.addCor(junc, tgc); - listB.addCor(choice1, tgc); - - } - } - } - - } else if (tgc instanceof TADArraySetState) { - TADArraySetState ass = (TADArraySetState)tgc; - sTmp = ass.getIndex(); - try { - nbActions = Integer.decode(sTmp).intValue(); - p = t.getParamByName(ass.getArray() + "__" + nbActions); - if (p == null) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Array setting: " + ass.getArray() + "[" + ass.getIndex() + "]: unknown array or wrong index"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ass.setStateAction(ErrorHighlight.UNKNOWN); - } else { - adap = new ADActionStateWithParam(p); - ad.addElement(adap); - adap.setActionValue(TURTLEModeling.manageDataStructures(t, ass.getExpr())); - listE.addCor(adap, tgc); - listB.addCor(adap, tgc); - ass.setStateAction(ErrorHighlight.OK); - } - - } catch (Exception e) { - // Index is not an absolute value - //System.out.println("Set: Index is not an absolute value"); - Gate error = t.addNewGateIfApplicable("arrayOverflow"); - - ADChoice choice1 = new ADChoice(); - ADJunction junc = new ADJunction(); - ADStop stop1 = new ADStop(); - ADActionStateWithGate adag1 = new ADActionStateWithGate(error); - - ad.addElement(choice1); - ad.addElement(junc); - ad.addElement(stop1); - ad.addElement(adag1); - - String basicGuard = "(" + ass.getIndex() + ")"; - - p = t.getParamByName(ass.getArray() + "__size"); - - if (p == null) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Array setting: " + ass.getArray() + "[" + ass.getIndex() + "]: unknown array or wrong index"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ass.setStateAction(ErrorHighlight.UNKNOWN); - } else { - int size = 2; - try { - size = Integer.decode(p.getValue()).intValue(); - } catch (Exception e0) { - } - - for(int i=0; i<size; i++) { - //System.out.println("Adding guard: [" + basicGuard + "== " + i + "]"); - p = t.getParamByName(ass.getArray() + "__" + i); - adap = null; - if (p == null) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Array setting: " + ass.getArray() + "[" + ass.getIndex() + "]: unknown array or wrong index"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ass.setStateAction(ErrorHighlight.UNKNOWN); - } else { - choice1.addGuard("[" + basicGuard + " == " + i + "]"); - adap = new ADActionStateWithParam(p); - ad.addElement(adap); - adap.setActionValue(TURTLEModeling.manageDataStructures(t, ass.getExpr())); - choice1.addNext(adap); - adap.addNext(junc); - ass.setStateAction(ErrorHighlight.OK); - } - - choice1.addGuard("[" + basicGuard + "> (" + ass.getArray() + "__size - 1)]"); - choice1.addNext(adag1); - adag1.addNext(stop1); - - listE.addCor(junc, tgc); - listE.addCor(choice1, tgc); - if (adap != null) { - listE.addCor(adap, tgc); - } - listE.addCor(stop1, tgc); - listE.addCor(adag1, tgc); - listB.addCor(choice1, tgc); - - } - } - } + // Action + if (tgc instanceof ui.ebrdd.EBRDDActionState) { + acst = new req.ebrdd.EBRDDActionState(); + acst.setAction(((ui.ebrdd.EBRDDActionState)tgc).getAction()); + listE.addCor(acst, tgc); + + // Stop + } else if (tgc instanceof ui.ebrdd.EBRDDStopState) { + stop = new req.ebrdd.EBRDDStop(); + listE.addCor(stop, tgc); - } else if (tgc instanceof TADChoice) { - adch = new ADChoice(); - ad.addElement(adch); - listE.addCor(adch, tgc); - } else if (tgc instanceof TADDeterministicDelay) { - add = new ADDelay(); - ad.addElement(add); - add.setValue(TURTLEModeling.manageGateDataStructures(t, ((TADDeterministicDelay)tgc).getDelayValue())); - listE.addCor(add, tgc); - } else if (tgc instanceof TADJunction) { - adj = new ADJunction(); - ad.addElement(adj); - listE.addCor(adj, tgc); - } else if (tgc instanceof TADNonDeterministicDelay) { - adl = new ADLatency(); - ad.addElement(adl); - adl.setValue(TURTLEModeling.manageGateDataStructures(t, ((TADNonDeterministicDelay)tgc).getLatencyValue())); - listE.addCor(adl, tgc); - } else if (tgc instanceof TADParallel) { - adp = new ADParallel(); - ad.addElement(adp); - adp.setValueGate(((TADParallel)tgc).getValueGate()); - listE.addCor(adp, tgc); - } else if (tgc instanceof TADSequence) { - adseq = new ADSequence(); - ad.addElement(adseq); - listE.addCor(adseq, tgc); - } else if (tgc instanceof TADPreemption) { - adpre = new ADPreempt(); - ad.addElement(adpre); - listE.addCor(adpre, tgc); - } else if (tgc instanceof TADStopState) { - adst = new ADStop(); - ad.addElement(adst); - listE.addCor(adst, tgc); - } else if (tgc instanceof TADTimeInterval) { - adti = new ADTimeInterval(); - ad.addElement(adti); - adti.setValue(TURTLEModeling.manageGateDataStructures(t, ((TADTimeInterval)tgc).getMinDelayValue()), TURTLEModeling.manageGateDataStructures(t, ((TADTimeInterval)tgc).getMaxDelayValue())); - listE.addCor(adti, tgc); - } else if (tgc instanceof TADTimeLimitedOffer) { - s = ((TADTimeLimitedOffer)tgc).getAction(); - g = t.getGateFromActionState(s); - if (g != null) { - adtlo = new ADTLO(g); - ad.addElement(adtlo); - adtlo.setLatency("0"); - s1 = t.getActionValueFromActionState(s); - //System.out.println("Adding type"); - s1 = TURTLEModeling.manageGateDataStructures(t, s1); - s1 = TURTLEModeling.addTypeToDataReceiving(t, s1); - //System.out.println("Adding type done"); - adtlo.setAction(s1); - adtlo.setDelay(TURTLEModeling.manageGateDataStructures(t, ((TADTimeLimitedOffer)tgc).getDelay())); - listE.addCor(adtlo, tgc); - ((TADTimeLimitedOffer)tgc).setStateAction(ErrorHighlight.GATE); - } else { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Time-limited offer (" + s + ", " + ((TADTimeLimitedOffer)tgc).getDelay() + "): \"" + s + "\" is not a correct expression"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ((TADTimeLimitedOffer)tgc).setStateAction(ErrorHighlight.UNKNOWN_AS); - //System.out.println("Bad time limited offer found " + s); - } - } else if (tgc instanceof TADTimeLimitedOfferWithLatency) { - s = ((TADTimeLimitedOfferWithLatency)tgc).getAction(); - g = t.getGateFromActionState(s); - if (g != null) { - adtlo = new ADTLO(g); - ad.addElement(adtlo); - adtlo.setLatency(TURTLEModeling.manageGateDataStructures(t, ((TADTimeLimitedOfferWithLatency)tgc).getLatency())); - s1 = t.getActionValueFromActionState(s); - //System.out.println("Adding type"); - s1 = TURTLEModeling.manageGateDataStructures(t, s1); - s1 = TURTLEModeling.addTypeToDataReceiving(t, s1); - //System.out.println("Adding type done"); - adtlo.setAction(s1); - adtlo.setDelay(TURTLEModeling.manageGateDataStructures(t, ((TADTimeLimitedOfferWithLatency)tgc).getDelay())); - listE.addCor(adtlo, tgc); - ((TADTimeLimitedOfferWithLatency)tgc).setStateAction(ErrorHighlight.GATE); - } else { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Time-limited offer (" + s + ", " + ((TADTimeLimitedOfferWithLatency)tgc).getLatency() + ", " + ((TADTimeLimitedOfferWithLatency)tgc).getDelay() + "): \"" + s + "\" is not a correct expression"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - ((TADTimeLimitedOfferWithLatency)tgc).setStateAction(ErrorHighlight.UNKNOWN_AS); - //System.out.println("Bad time limited offer found " + s); - } + // Choice + } else if (tgc instanceof ui.ebrdd.EBRDDChoice) { + // guards are added later on + ch = new req.ebrdd.EBRDDChoice(); + listE.addCor(ch, tgc); - // TURTLE-OS AD - } else if (tgc instanceof TOSADTimeInterval) { - adti = new ADTimeInterval(); - ad.addElement(adti); - adti.setValue(TURTLEModeling.manageGateDataStructures(t, ((TOSADTimeInterval)tgc).getMinDelayValue()), TURTLEModeling.manageGateDataStructures(t, ((TOSADTimeInterval)tgc).getMaxDelayValue())); - listE.addCor(adti, tgc); - } else if (tgc instanceof TOSADIntTimeInterval) { - adti = new ADTimeInterval(); - ad.addElement(adti); - adti.setValue(TURTLEModeling.manageGateDataStructures(t, ((TOSADIntTimeInterval)tgc).getMinDelayValue()), TURTLEModeling.manageGateDataStructures(t, ((TOSADIntTimeInterval)tgc).getMaxDelayValue())); - listE.addCor(adti, tgc); - } else if (tgc instanceof TOSADStopState) { - adst = new ADStop(); - ad.addElement(adst); - listE.addCor(adst, tgc); - } else if (tgc instanceof TOSADJunction) { - adj = new ADJunction(); - ad.addElement(adj); - listE.addCor(adj, tgc); - } else if (tgc instanceof TOSADChoice) { - adch = new ADChoice(); - ad.addElement(adch); - listE.addCor(adch, tgc); - } if (tgc instanceof TOSADActionState) { - s = ((TOSADActionState)tgc).getAction(); - s = s.trim(); - //remove ';' if last character - if (s.substring(s.length()-1, s.length()).compareTo(";") == 0) { - s = s.substring(0, s.length()-1); - } - nbActions = Conversion.nbChar(s, ';') + 1; + // Sequence + } else if (tgc instanceof ui.ebrdd.EBRDDSequence) { + // guards are added later on + seq = new req.ebrdd.EBRDDSequence(); + listE.addCor(seq, tgc); - if (nbActions>1) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, s + " should not start with a '=='"); - ce.setTClass(t); - ce.setTGComponent(tgc); - ce.setTDiagramPanel(tdp); - addCheckingError(ce); - } else { - //s = TURTLEModeling.manageDataStructures(t, s); - g = t.getGateFromActionState(s); - p = t.getParamFromActionState(s); - - if (p != null) { - adap = new ADActionStateWithParam(p); - ad.addElement(adap); - adap.setActionValue(TURTLEModeling.manageDataStructures(t, t.getExprValueFromActionState(s))); - listE.addCor(adap, tgc); - } else { - adag = new ADActionStateWithGate(g); - ad.addElement(adag); - listE.addCor(adag, tgc); - adag.setActionValue(s); - } - } - //System.out.println("Nb Actions in state: " + nbActions); + // Loop + } else if (tgc instanceof ui.ebrdd.EBRDDForLoop) { + // guards are added later on + loop = new req.ebrdd.EBRDDLoop(); + listE.addCor(loop, tgc); + loop.setInit(((ui.ebrdd.EBRDDForLoop)tgc).getInit()); + loop.setCondition(((ui.ebrdd.EBRDDForLoop)tgc).getCondition()); + loop.setIncrement(((ui.ebrdd.EBRDDForLoop)tgc).getIncrement()); + + // ERC + } else if (tgc instanceof ui.ebrdd.EBRDDERC) { + // guards are added later on + erc = new req.ebrdd.EBRDDERC(); + listE.addCor(erc, tgc); } } - TGConnectingPoint p1, p2; - //TGConnectorFullArrow tgco; - TGComponent tgc1, tgc2, tgc3; - ADComponent ad1, ad2; - - // Managing Java code - iterator = list.listIterator(); - while(iterator.hasNext()) { - tgc = (TGComponent)(iterator.next()); - if (tgc instanceof PreJavaCode) { - ad1 = listE.getADComponentByIndex(tgc, tdp.count); - if (ad1 != null) { - ad1.setPreJavaCode(tgc.getPreJavaCode()); - } - } - if (tgc instanceof PostJavaCode) { - ad1 = listE.getADComponentByIndex(tgc, tdp.count); - if (ad1 != null) { - ad1.setPostJavaCode(tgc.getPostJavaCode()); - } + Vector v = listE.getData(); + Object o; + for(int i=0; i<v.size(); i++) { + o = v.get(i); + if (o instanceof EBRDDComponent) { + ebrdd.add((EBRDDComponent)o); } } - // Connecting elements - TGConnectorBetweenElementsInterface tgcbei; - iterator = list.listIterator(); - while(iterator.hasNext()) { - tgc = (TGComponent)(iterator.next()); - if (tgc instanceof TGConnectorBetweenElementsInterface) { - tgcbei = (TGConnectorBetweenElementsInterface)tgc; - p1 = tgcbei.getTGConnectingPointP1(); - p2 = tgcbei.getTGConnectingPointP2(); - - // identification of connected components - 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; - } - } - - // connecting turtle modeling components - if ((tgc1 != null) && (tgc2 != null)) { - //ADComponent ad1, ad2; - - //System.out.println("tgc1 = " + tgc1.getValue() + " tgc2= "+ tgc2.getValue()); - + + // Interconnection between elements + TGConnectorEBRDD tgco; + TGConnectingPoint p1, p2; + EBRDDComponent eb1, eb2; + TGComponent tgc1, tgc2, tgc3; + int j, index; + + iterator = list.listIterator(); + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + if (tgc instanceof TGConnectorEBRDD) { + tgco = (TGConnectorEBRDD)tgc; + p1 = tgco.getTGConnectingPointP1(); + p2 = tgco.getTGConnectingPointP2(); + + // Identification of connected components + 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; + } + } + + // Connecting ebrdd modeling components + if ((tgc1 != null) && (tgc2 != null)) { + //ADComponent ad1, ad2; + eb1 = listE.getEBRDDComponent(tgc1); + eb2 = listE.getEBRDDComponent(tgc2); + + if ((eb1 != null ) && (eb2 != null)) { + //Special case if "for loop" or if "choice" + + if (eb1 instanceof req.ebrdd.EBRDDLoop) { + index = tgc1.indexOf(p1) - 1; + if (index == 0) { + eb1.addNext(0, eb2); + } else { + eb1.addNext(eb2); + } + } else if (eb1 instanceof req.ebrdd.EBRDDChoice) { + index = tgc1.indexOf(p1) - 1; + //System.out.println("Adding next:" + ae2); + eb1.addNext(eb2); + //System.out.println("Adding guard:" + ((TMLADChoice)tgc1).getGuard(index)); + ((req.ebrdd.EBRDDChoice)eb1).addGuard(((ui.ebrdd.EBRDDChoice)tgc1).getGuard(index)); + } else if (eb1 instanceof req.ebrdd.EBRDDSequence) { + index = tgc1.indexOf(p1) - 1; + ((req.ebrdd.EBRDDSequence)eb1).addIndex(index); + eb1.addNext(eb2); + //System.out.println("Adding " + ae2 + " at index " + index); + } else { + eb1.addNext(eb2); + } + } + } + } + } + + // Check that each "for" has two nexts + // Check that Choice have compatible guards + iterator = list.listIterator(); + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + if (tgc instanceof ui.ebrdd.EBRDDChoice) { + ch = (req.ebrdd.EBRDDChoice)(listE.getEBRDDComponent(tgc)); + ch.orderGuards(); - ad1 = listE.getADComponentByIndex(tgc1, tdp.count); - //} - if ((tgc2 instanceof TADArrayGetState) || (tgc2 instanceof TADArraySetState)) { - ad2 = listB.getADComponent(tgc2); - } else { - ad2 = listE.getADComponentByIndex(tgc2, tdp.count); - } - - //System.out.println("ad1 = " + ad1 + " ad2= "+ ad2); - - if ((ad1 == null) || (ad2 == null)) { - //System.out.println("Correspondance issue"); - } - int index = 0; - if ((ad1 != null ) && (ad2 != null)) { - if ((tgc1 instanceof TADTimeLimitedOffer) || (tgc1 instanceof TADTimeLimitedOfferWithLatency)) { - index = tgc1.indexOf(p1) - 1; - ad1.addNextAtIndex(ad2, index); - } else if (tgc1 instanceof TADChoice) { - TADChoice tadch = (TADChoice)tgc1; - index = tgc1.indexOf(p1) - 1; - ((ADChoice)ad1).addGuard(TURTLEModeling.manageGateDataStructures(t, tadch.getGuard(index))); - ad1.addNext(ad2); - } else if ((tgc1 instanceof TADSequence) ||(tgc1 instanceof TADPreemption)){ - index = tgc1.indexOf(p1) - 1; - ad1.addNextAtIndex(ad2, index); - } else if (tgc1 instanceof TOSADChoice) { - TOSADChoice tadch = (TOSADChoice)tgc1; - index = tgc1.indexOf(p1) - 1; - ((ADChoice)ad1).addGuard(TURTLEModeling.manageGateDataStructures(t, tadch.getGuard(index))); - ad1.addNext(ad2); - } else { - ad1.addNextAtIndex(ad2, index); - //System.out.println("Adding connector from " + ad1 + " to " + ad2); - } - } - } - } - } - // Increasing count of this panel - tdp.count ++; + if (ch.hasMoreThanOneElse()) { + CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Choice should have only one [else] guard"); + ce.setTDiagramPanel(ebrddp); + ce.setTGComponent(tgc); + checkingErrors.add(ce); + } + } + } + + // Sorting nexts elements of Sequence + for(j=0; j<ebrdd.size(); j++) { + eb1 = ebrdd.get(j); + if (eb1 instanceof req.ebrdd.EBRDDSequence) { + ((req.ebrdd.EBRDDSequence)eb1).sortNexts(); + } + } - // Remove all elements not reachable from start state - int sizeb = ad.size(); - ad.removeAllNonReferencedElts(); - int sizea = ad.size(); + // Remove all elements not reachable from start state + int sizeb = ebrdd.size(); + ebrdd.removeAllNonReferencedElts(); + int sizea = ebrdd.size(); if (sizeb > sizea) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Non reachable elements have been removed in " + t.getName()); - ce.setTClass(t); + CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Non reachable elements have been removed in EBRDD"); ce.setTGComponent(null); - ce.setTDiagramPanel(tdp); + ce.setTDiagramPanel(ebrddp); addWarning(ce); //System.out.println("Non reachable elements have been removed in " + t.getName()); - }*/ - - return ebrdd; - } - - /*public void addRelations(TURTLEDesignPanelInterface dp, String prename, TURTLEModeling tm) { - addRelationFromPanel(dp.getStructurePanel(), prename, tm); - } - - public void addRelations(TURTLEDesignPanelInterface dp, TURTLEModeling tm) { - addRelationFromPanel(dp.getStructurePanel(), "", tm); - } - - private void addRelationFromPanel(ClassDiagramPanelInterface tdp, String prename, TURTLEModeling tm) { - LinkedList list = tdp.getComponentList(); - Iterator iterator = list.listIterator(); - // search for Composition Operator - TGComponent tgc; - - while(iterator.hasNext()) { - tgc = (TGComponent)(iterator.next()); - if (tgc instanceof CompositionOperatorInterface) { - addRelationFromCompositionOperator((CompositionOperatorInterface)tgc, tdp, prename, tm); - } } - } - - private void addRelationFromCompositionOperator(CompositionOperatorInterface tco, ClassDiagramPanelInterface tdp, String prename, TURTLEModeling tm) { - TClassInterface t1 = tdp.getTClass1ToWhichIamConnected(tco); - TClassInterface t2 = tdp.getTClass2ToWhichIamConnected(tco); - TGConnector tgco = tdp.getTGConnectorAssociationOf(tco); + System.out.println("EBRDD generated"); - if ((t1 != null) && (t2 != null) && (tgco != null)) { - TClass tc1 = tm.getTClassWithName(prename + t1.getValue()); - TClass tc2 = tm.getTClassWithName(prename + t2.getValue()); - - if ((tc1 != null) && (tc2 != null)) { - int type = typeOf(tco); - if (type == -1) { - return; - } - - Relation r; - - if (tgco instanceof TGConnectorAssociationWithNavigation) { - r = new Relation(type, tc1, tc2, true); - } else { - r = new Relation(type, tc1, tc2, false); - } - - tm.addRelation(r); - //System.out.println("Adding " + Relation.translation(type) + " relation between " + tc1.getName() + " and " + tc2.getName()); - - // if tgco is a synchro operator -> synchronizations gates - if (tco instanceof TCDSynchroOperator) { - Vector gates = ((TCDSynchroOperator)tco).getGates(); - setGatesOf(r, gates, tc1, tc2); - } - - if (tco instanceof TCDInvocationOperator) { - Vector gates = ((TCDInvocationOperator)tco).getGates(); - setGatesOf(r, gates, tc1, tc2); - } - - // if tgco watcdog -> list of gates - if (tco instanceof TCDWatchdogOperator) { - Vector gates = ((TCDWatchdogOperator)tco).getGates(); - setWatchdogGatesOf(r, gates, tc1, tc2); - } - - } - } - } - - private int typeOf(CompositionOperatorInterface tco) { - if (tco instanceof TCDParallelOperator) { - return Relation.PAR; - } else if (tco instanceof TCDPreemptionOperator) { - return Relation.PRE; - } else if (tco instanceof TCDSequenceOperator) { - return Relation.SEQ; - } else if (tco instanceof TCDSynchroOperator) { - return Relation.SYN; - } else if (tco instanceof TCDInvocationOperator) { - return Relation.INV; - } else if (tco instanceof TCDWatchdogOperator) { - return Relation.WAT; - } - return -1; - } - - private void setGatesOf(Relation r, Vector gates, TClass tc1, TClass tc2) { - TTwoAttributes tt; - Gate g1, g2; - - for(int i=0; i<gates.size(); i++) { - tt = (TTwoAttributes)(gates.elementAt(i)); - g1 = tc1.getGateByName(tt.ta1.getId()); - g2 = tc2.getGateByName(tt.ta2.getId()); - - if ((g1 != null) && (g2 != null)) { - r.addGates(g1, g2); - //System.out.println("Adding gates " + g1.getName() + " = " + g2.getName()); - } - } + return ebrdd; } - private void setWatchdogGatesOf(Relation r, Vector gates, TClass tc1, TClass tc2) { - //TTwoAttributes tt; - TAttribute t; - Gate g1; - - for(int i=0; i<gates.size(); i++) { - t = (TAttribute)(gates.elementAt(i)); - g1 = tc1.getGateByName(t.getId()); - - if (g1 != null) { - r.addGates(g1, g1); - } - } - }*/ - } -- GitLab