diff --git a/src/tmltranslator/TMLCPTextSpecification.java b/src/tmltranslator/TMLCPTextSpecification.java index ac1aa6b05e2f31fd37c92cbadc0c9e49d8a9fd16..91e4d57015717b97769c02ebb9b3658345805aa3 100755 --- a/src/tmltranslator/TMLCPTextSpecification.java +++ b/src/tmltranslator/TMLCPTextSpecification.java @@ -220,21 +220,101 @@ public class TMLCPTextSpecification { sb += "SEQUENCE" + SP + refSD.getName() + CR + TAB; } if( elem instanceof TMLCPConnector ) { - listTMLCPConnectors.add( (TMLCPConnector) elem); + TMLCPConnector connector = (TMLCPConnector) elem; + listTMLCPConnectors.add( connector ); } +/* if( elem instanceof TMLCPFork ) { + tmltranslator.tmlcp.TMLCPFork fork = (TMLCPFork) elem; + listTMLADItems.add( new TMLADItem( fork.getName(), fork.getStartName(), fork.getEndName(), "FORK", fork.getYCoord() ) ); + } + if( elem instanceof TMLCPJoin ) { + tmltranslator.tmlcp.TMLCPJoin join = (TMLCPJoin) elem; + listTMLADItems.add( new TMLADItem( join.getName(), join.getStartName(), join.getEndName(), "FORK", join.getYCoord() ) ); + } + if( elem instanceof TMLCPChoice ) { + tmltranslator.tmlcp.TMLCPChoice choice = (TMLCPChoice) elem; + listTMLADItems.add( new TMLADItem( choice.getName(), choice.getStartName(), choice.getEndName(), "FORK", choice.getYCoord() ) ); + }*/ } //global variables should go here, but there are none up to now - sb += CR + MAIN + CR + TAB + "<>" + SC; - //sortYCoord( listTMLConnectors ); //to be implemented - ArrayList<String> connNameList = new ArrayList<String>(); + sb += CR + MAIN + CR + TAB + "<>" + SC + " "; //should I start with an open parenthesis? for( TMLCPConnector conn : listTMLCPConnectors ) { - connNameList.add( Integer.toString( conn.getYCoord() ) + SP + conn.getSourceName() + SP + conn.getDestName() ); + TraceManager.addDev( "connector from " + conn.getStartName() + " to " + conn.getEndName()+ " " + conn.getYCoord() ); } - Collections.sort( connNameList ); - TraceManager.addDev( "PRINTING ORDERED LIST" ); - for( int y = 0; y < connNameList.size(); y++ ) { - TraceManager.addDev( connNameList.get(y) ); + //up to know I just consider sequence, activities, fork and join, no choices, no guards, no nested structures keep things simple! + String currentElem = "start state"; + String nextElem = "seqXXX"; + while( nextElem.substring(0,3).equals( "seq" ) || nextElem.substring(0,3).equals( "act" ) || nextElem.substring(0,4).equals( "join" ) ) { +// while( !nextElem.substring(0,3).equals( "stop state" ) ) { + for( TMLCPConnector conn: listTMLCPConnectors ) { //Does not work in case diagrams dont have a unique name + if( conn.getStartName().equals( currentElem ) ) { + nextElem = conn.getEndName(); + break; + } + } + if( nextElem.substring(0,3).equals( "seq" ) || nextElem.substring(0,3).equals( "act" ) ) { //returned diagram name + sb += nextElem + " " + SC + " "; + } + if( nextElem.substring(0,4).equals( "fork" ) ) { //returned fork node + sb += "{ "; + ArrayList<TMLCPConnector> connToFork = new ArrayList<TMLCPConnector>(); + for( TMLCPConnector conn: listTMLCPConnectors ) { //Does not work in case diagrams dont have a unique name + if( conn.getStartName().equals( nextElem ) ) { + connToFork.add( conn ); + } + } + for( TMLCPConnector conn: connToFork ) { //Does not work in case diagrams dont have a unique name + sb += conn.getEndName() + "*"; + nextElem = conn.getEndName(); + } + String newS = sb.substring( 0, sb.length()-1 ); + sb = newS; + } + if( nextElem.substring(0,4).equals( "join" ) ) { + sb += " }" + SC; + } + //to avoid the problems with parenthesis I need to parse everything in a block that opens and closes parentheses! + // from a graphical viewpoint I am missing the possibility to add guards. I think I should not continue that much: add + // choice and junction, then refine all the missing parts: e.g., syntax analysis. KISS! + if( nextElem.substring(0,6).equals( "choice" ) ) { + sb += " || {"; + //there can be three branches that must all terminate with either a stop state or a junction + //get branches + ArrayList<TMLCPConnector> connToChoice = new ArrayList<TMLCPConnector>(); + for( TMLCPConnector conn: listTMLCPConnectors ) { //Does not work in case diagrams dont have a unique name + if( conn.getStartName().equals( nextElem ) ) { + connToChoice.add( conn ); + } + } + //explore them till stop state or junction + for( TMLCPConnector conn: connToChoice ) { //Does not work in case diagrams dont have a unique name + nextElem = conn.getEndName(); + //start again recursively + } + } //I need to rethink the algotrithm... + //Better to stop here and boucler the existing with a complete syntax analysis and TML generation for all the ADs + if( nextElem.equals( "ERROR" ) ) { + TraceManager.addDev( "ERROR WHEN GENERATING TML CODE" ); + } + currentElem = nextElem; } + String newS = sb.substring( 0, sb.length()-1 ); //drop last semi-colon + sb = newS; + + //Yet to add: + // 1) nested forks + // 2) choices and junctions + // I dont remember the grammar/syntax for choice nodes exactly, I need to check, I will put || bewteen two blocks! + + + // + //It is misleading to sort connectors + + /*Collections.sort( listTMLCPConnectors ); + TraceManager.addDev( "PRINTING ORDERED LIST" ); + for( TMLCPConnector conn : listTMLCPConnectors ) { + TraceManager.addDev( "connector from " + conn.getStartName() + " to " + conn.getEndName()+ " " + conn.getYCoord() ); + }*/ sb += CR; sb += END + CR + END + CR2; @@ -247,7 +327,6 @@ public class TMLCPTextSpecification { ArrayList<TMLSDMessage> listMessages = SD.getMessages(); ArrayList<TMLSDAction> listActions = SD.getActions(); ArrayList<TMLAttribute> listAttributes = SD.getAttributes(); - //ArrayList<String> actions = new ArrayList<String>(); for( tmltranslator.tmlcp.TMLSDInstance inst: listInstances ) { sb += inst.getType() + " " + inst.getName() + CR + TAB + TAB; } @@ -265,25 +344,16 @@ public class TMLCPTextSpecification { sb += CR2; sb += MAIN + CR; //actions and messages must be ordered and printed according to Y before being written! - //sortedMessages = sort( listMessages ); - ArrayList<TMLSDMessage> sortedMessages = listMessages; - for( TMLSDMessage msg: sortedMessages ) { //print the message and all its attributes - sb += msg.getName() + "("; - ArrayList<TMLSDAttribute> listAttr = msg.getAttributes(); //mind the difference between TMLSDAttribute and TMLAttribute - for( int index = 0; index < listAttr.size(); index++ ) { - if( index == ( listAttr.size() - 1 ) ) { - sb += listAttr.get(index).getName(); - } - else { - sb += listAttr.get(index).getName() + ", "; - } - } - sb += ")"; + ArrayList<TMLSDItem> listItems = SD.getItems(); + Collections.sort( listItems ); + TraceManager.addDev( "PRINTING SORTED ITEMS" ); + for( TMLSDItem item: listItems ) { //print the items + TraceManager.addDev( item.toString() ); + } + for( TMLSDItem item: listItems ) { + sb += item.getValue(); sb += CR + TAB; } - for( TMLSDAction action: listActions ) { - sb += action.getAction() + CR; - } sb += CR; sb += END + CR + END + CR2; } @@ -291,10 +361,10 @@ public class TMLCPTextSpecification { } -/* private ArrayList<TMLSDMessage> sort( ArrayList<TMLSDMessage> input ) { - //To be implemented... - return sorted; - }*/ + private String parseConnectors( ArrayList<TMLCPConnector> list, String _elem ) { + + return "ERROR"; + } public String makeTasks(TMLModeling tmlm) { String sb = ""; diff --git a/src/tmltranslator/tmlcp/TMLADItem.java b/src/tmltranslator/tmlcp/TMLADItem.java new file mode 100755 index 0000000000000000000000000000000000000000..5464555554d16ac815ef8788e4195e64f860cc10 --- /dev/null +++ b/src/tmltranslator/tmlcp/TMLADItem.java @@ -0,0 +1,98 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + +ludovic.apvrille AT enst.fr +andrea.enrici 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 TMLADItem. An item is either a message or an action. This class is used to produce the TML code corresponding to messages +* and actions that are sorted according to the graphical version of a SD diagram. +* Creation: 18/02/2014 +* @version 1.0 26/06/2014 +* @author Ludovic APVRILLE, Andrea ENRICI +* @see +*/ + +package tmltranslator.tmlcp;; + +import java.util.*; + +import tmltranslator.*; +import myutil.*; + +public class TMLADItem implements Comparable<TMLADItem> { + + //mind the difference between TMLSDAttribute and TMLAttribute! + private String name; + private String startName; + private String endName; + private String type; + private int yCoord; + + public TMLADItem( String _name, String _startName, String _endName, String _type, int _yCoord ) { + this.name = _name; + this.startName = _startName; + this.endName = _endName; + this.type = _type; + this.yCoord = _yCoord; + } + + public String getName() { + return this.name; + } + + public int getYCoord() { + return this.yCoord; + } + + public void setYCoord( int _coord ) { + this.yCoord = _coord; + } + + public void setName( String _name ) { + this.name = _name; + } + + public int compareTo( TMLADItem _item ) { + + int compareValue = ((TMLADItem) _item).getYCoord(); + //sort in ascending order + return this.yCoord - compareValue; + } + + @Override public String toString() { + return this.value + " " + this.yCoord; + } +} //End of class diff --git a/src/tmltranslator/tmlcp/TMLCPSequenceDiagram.java b/src/tmltranslator/tmlcp/TMLCPSequenceDiagram.java index f2cae0a357c2c66e6ddce5462c8748ef7ea37862..9998031c558b404a2a6cc832fd7b1fdd440c6640 100755 --- a/src/tmltranslator/tmlcp/TMLCPSequenceDiagram.java +++ b/src/tmltranslator/tmlcp/TMLCPSequenceDiagram.java @@ -57,6 +57,8 @@ public class TMLCPSequenceDiagram extends TMLElement { private ArrayList<TMLSDInstance> mappingInstances; private ArrayList<TMLAttribute> globalVariables; private ArrayList<TMLSDMessage> messages; + //used to sort messages and actions according to their order in the graphical window, to produce the TMLTxt code + private ArrayList<TMLSDItem> items; private ArrayList<TMLSDAction> actions; private int hashCode; @@ -73,6 +75,7 @@ public class TMLCPSequenceDiagram extends TMLElement { instances = new ArrayList<TMLSDInstance>(); messages = new ArrayList<TMLSDMessage>(); actions = new ArrayList<TMLSDAction>(); + items = new ArrayList<TMLSDItem>(); } /*public void addVariable( TMLAttribute _attr ) throws MultipleVariableDeclarationException { @@ -86,6 +89,14 @@ public class TMLCPSequenceDiagram extends TMLElement { } }*/ + public ArrayList<TMLSDItem> getItems() { + return items; + } + + public void addItem( TMLSDItem _item ) { + items.add( _item ); + } + public void addVariable( TMLAttribute _attr ) { globalVariables.add( _attr ); } @@ -108,6 +119,7 @@ public class TMLCPSequenceDiagram extends TMLElement { public void addAction( TMLSDAction _action ) { actions.add( _action ); + addItem( new TMLSDItem( _action.getAction(), _action.getYCoord() ) ); } //commenting the throw exception because bot needed by the graphical 2 TMLTxt compiler yet @@ -138,8 +150,9 @@ public class TMLCPSequenceDiagram extends TMLElement { return mappingInstances; } - public void addMessage( TMLSDMessage _elt ) { - messages.add( _elt ); + public void addMessage( TMLSDMessage _msg ) { + messages.add( _msg ); + addItem( new TMLSDItem( _msg.toString(), _msg.getYCoord() ) ); } public void insertInitialValue( String _name, String value ) throws UninitializedVariableException { diff --git a/src/tmltranslator/tmlcp/TMLSDItem.java b/src/tmltranslator/tmlcp/TMLSDItem.java new file mode 100755 index 0000000000000000000000000000000000000000..823e7f714f764fc62a443b5b24a002a6c4f59bcf --- /dev/null +++ b/src/tmltranslator/tmlcp/TMLSDItem.java @@ -0,0 +1,102 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + +ludovic.apvrille AT enst.fr +andrea.enrici 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 TMLSDItem. An item is either a message or an action. This class is used to produce the TML code corresponding to messages +* and actions that are sorted according to the graphical version of a SD diagram. +* Creation: 18/02/2014 +* @version 1.0 26/06/2014 +* @author Ludovic APVRILLE, Andrea ENRICI +* @see +*/ + +package tmltranslator.tmlcp;; + +import java.util.*; + +import tmltranslator.*; +import myutil.*; + +public class TMLSDItem implements Comparable<TMLSDItem> { + + //mind the difference between TMLSDAttribute and TMLAttribute! + private String value; + private int yCoord; + + public TMLSDItem( String _value, int _yCoord ) { + this.value = _value; + this.yCoord = _yCoord; + } + + public String getValue() { + return this.value; + } + + public int getYCoord() { + return this.yCoord; + } + + public void setYCoord( int _coord ) { + this.yCoord = _coord; + } + + public void setValue( String _value ) { + this.value = _value; + } + + public int compareTo( TMLSDItem _item ) { + + int compareValue = ((TMLSDItem) _item).getYCoord(); + //sort in ascending order + return this.yCoord - compareValue; + } + + /*public static Comparator<TMLSDItem> yCoordComparator = new Comparator<TMLSDItem>() { + public int compare( TMLSDItem _item1, TMLSDItem _item2 ) { + int yCoord1 = _item1.getYCoord(); + int yCoord2 = _item2.getYCoord(); + + //ascending order + return yCoord1.compareTo( yCoord2 ); + } + };*/ + + @Override public String toString() { + return "TMLSDItem " + this.value + " " + this.yCoord; + } +} //End of class diff --git a/src/tmltranslator/tmlcp/TMLSDMessage.java b/src/tmltranslator/tmlcp/TMLSDMessage.java index b2e60a133bf647686f3b59f3ed0e9a534ac01918..b30d5d120f1c4d5b0eeaaa1e3f4cad9ebd226c4b 100755 --- a/src/tmltranslator/tmlcp/TMLSDMessage.java +++ b/src/tmltranslator/tmlcp/TMLSDMessage.java @@ -57,34 +57,48 @@ public class TMLSDMessage extends TMLElement { private ArrayList<TMLSDAttribute> attributeList; private int yCoord; - public TMLSDMessage( String _name, Object _referenceObject ) { - super( _name, _referenceObject ); - attributeList = new ArrayList<TMLSDAttribute>(); - } - - public TMLSDMessage( String _name, Object _referenceObject, ArrayList<String> _params ) { - super( _name, _referenceObject ); - attributeList = new ArrayList<TMLSDAttribute>(); - for( String p: _params ) { - attributeList.add( new TMLSDAttribute(p) ); - } + public TMLSDMessage( String _name, int _yCoord, Object _referenceObject ) { + super( _name, _referenceObject ); + this.yCoord = _yCoord; + attributeList = new ArrayList<TMLSDAttribute>(); + } + + public TMLSDMessage( String _name, int _yCoord, Object _referenceObject, ArrayList<String> _params ) { + super( _name, _referenceObject ); + this.yCoord = _yCoord; + attributeList = new ArrayList<TMLSDAttribute>(); + for( String p: _params ) { + attributeList.add( new TMLSDAttribute(p) ); } + } - public void addAttribute( TMLSDAttribute _attribute ) { - if( _attribute != null ) - attributeList.add( _attribute ); - } - - public ArrayList<TMLSDAttribute> getAttributes() { - return attributeList; - } - - public int getYCoord() { - return this.yCoord; - } - - public void setYCoord( int _coord ) { - this.yCoord = _coord; - } + public void addAttribute( TMLSDAttribute _attribute ) { + if( _attribute != null ) + attributeList.add( _attribute ); + } + + public ArrayList<TMLSDAttribute> getAttributes() { + return attributeList; + } + + public int getYCoord() { + return this.yCoord; + } + + public void setYCoord( int _coord ) { + this.yCoord = _coord; + } + @Override public String toString() { + String s = this.name + "( "; + for( TMLSDAttribute attribute: attributeList ) { + if( attribute.getName() != "" && attribute.getName() != "null" && attribute.getName() != null ) { + s += attribute.getName() + ", "; + } + } + String newS = s.substring( 0, s.length()-2 ); +// s.setCharAt( s.length()-1, ' ' ); + s = newS + " )"; + return s; + } } //End of class diff --git a/src/ui/GTMLModeling.java b/src/ui/GTMLModeling.java index f851c8266da9211fe6714361220ecccdf6e0ae9d..5aa4a8c937a8eda7d8b6285949da1a305a4997ce 100755 --- a/src/ui/GTMLModeling.java +++ b/src/ui/GTMLModeling.java @@ -2368,7 +2368,7 @@ public class GTMLModeling { } if( elem instanceof TGConnectorMessageTMLSD ) { connector = (TGConnectorMessageTMLSD) elemList.get(j); - SD.addMessage( new TMLSDMessage( connector.getName(), null, connector.getParams() ) ); + SD.addMessage( new TMLSDMessage( connector.getName(), connector.getY(), null, connector.getParams() ) ); TraceManager.addDev( "Found message: " + connector.getValue() + " " + connector.getY() ); for( String param : connector.getParams() ) { TraceManager.addDev( param ); diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java index 43f6429a23f1408093d38473eec3a539c6076195..c57a71c22c5716c3bf7a661fa50e70a13c27c063 100755 --- a/src/ui/GTURTLEModeling.java +++ b/src/ui/GTURTLEModeling.java @@ -5669,7 +5669,7 @@ public class GTURTLEModeling { int myX = -1, myY = -1, myWidth = -1, myHeight =-1; int myMinWidth = -1, myMinHeight = -1, myMinDesiredWidth = -1, myMinDesiredHeight = -1; int myMaxWidth = -1, myMaxHeight = -1; - String myName = null, myValue = null; + String myName = null, myValue = null, endName = null, startName = null; int tmpx, tmpy, tmpid; TGConnectingPoint p1 = null, p2=null; Vector pointList = new Vector(); @@ -5701,6 +5701,8 @@ public class GTURTLEModeling { myMinDesiredHeight = Integer.decode(elt.getAttribute("minDesiredHeight")).intValue(); } else if (elt.getTagName().equals("infoparam")) { myName = elt.getAttribute("name"); + startName = elt.getAttribute("start"); + endName = elt.getAttribute("end"); myValue = elt.getAttribute("value"); } else if (elt.getTagName().equals("P1")) { tmpx = Integer.decode(elt.getAttribute("x")).intValue() + decX; @@ -5756,6 +5758,12 @@ public class GTURTLEModeling { if (myName != null) { tgco.setName(myName); } + if(startName != null) { + tgco.setStartName(startName); + } + if( endName != null) { + tgco.setEndName(endName); + } if ((myValue != null) && (!myValue.equals(null))){ tgco.setValueWithChange(myValue); diff --git a/src/ui/TGConnector.java b/src/ui/TGConnector.java index 0882a77d4eeec79a6a9f93d31a00528bae4223d9..58260168fc1b14d7ee52997496d6955d2ca05542 100755 --- a/src/ui/TGConnector.java +++ b/src/ui/TGConnector.java @@ -55,7 +55,7 @@ import java.util.*; import myutil.*; -public abstract class TGConnector extends TGCWithInternalComponent { +public abstract class TGConnector extends TGCWithInternalComponent { protected final static String XML_CONNECTOR_HEAD = "<CONNECTOR type=\""; protected final static String XML_ID = "\" id=\""; @@ -799,12 +799,12 @@ public abstract class TGConnector extends TGCWithInternalComponent { public void setStartName( String _name ) { startName = _name; - name = "connector from " + startName + " to " + endName; + //name = "connector from " + startName + " to " + endName; } public void setEndName( String _name ) { endName = _name; - name = "connector from " + startName + " to " + endName; + //name = "connector from " + startName + " to " + endName; } public String getStartName() {