From a149021b1c31999fe10c49565b07ef3efec00e4c Mon Sep 17 00:00:00 2001
From: Andrea Enrici <andrea.enrici@nokia.com>
Date: Mon, 16 Jun 2014 16:31:17 +0000
Subject: [PATCH] Stopped using graphical data structure for parsing
 graphical2TMLTxt

---
 src/tmltranslator/TMLAttribute.java           | 11 ++--
 src/tmltranslator/TMLCP.java                  |  6 +-
 src/tmltranslator/TMLCPTextSpecification.java | 66 ++-----------------
 src/tmltranslator/TMLSDAttribute.java         |  5 +-
 .../tmlcp/CPSequenceDiagram.java              | 32 ++++++---
 src/tmltranslator/tmlcp/TMLSDAction.java      | 30 +++++----
 src/tmltranslator/tmlcp/TMLSDInstance.java    | 31 +++++++--
 src/tmltranslator/tmlcp/TMLSDMessage.java     | 30 ++++++---
 src/ui/GTURTLEModeling.java                   |  3 +-
 9 files changed, 108 insertions(+), 106 deletions(-)

diff --git a/src/tmltranslator/TMLAttribute.java b/src/tmltranslator/TMLAttribute.java
index 4ab2baaadb..1defdb67ce 100755
--- a/src/tmltranslator/TMLAttribute.java
+++ b/src/tmltranslator/TMLAttribute.java
@@ -48,21 +48,22 @@
 
 package tmltranslator;
 
-
-
-
 public class TMLAttribute extends DIPLOElement {
     
     public TMLType type;
     public String name;
     public String initialValue;
     
-    public TMLAttribute() {
+    public TMLAttribute( String _name, TMLType _type, String _initialValue ) {
+        this.name = _name;
+        this.type = _type;
+				this.initialValue = _initialValue;
     }
     
-    public TMLAttribute(String _name, TMLType _type) {
+    public TMLAttribute( String _name, TMLType _type ) {
         name = _name;
         type = _type;
+				initialValue = "NULL";
     }
     
     public String getName() {
diff --git a/src/tmltranslator/TMLCP.java b/src/tmltranslator/TMLCP.java
index 3ddf03463f..cd2b1367e4 100755
--- a/src/tmltranslator/TMLCP.java
+++ b/src/tmltranslator/TMLCP.java
@@ -235,12 +235,12 @@ public class TMLCP extends TMLElement {
 		}
   }
     
-  public void addCPSequenceDiagram( CPSequenceDiagram _tmlsdSection ) throws UndeclaredDiagramException, MultipleDiagDeclarationsException	{
+  public void addCPSequenceDiagram( CPSequenceDiagram _tmlsdSection ) /*throws UndeclaredDiagramException, MultipleDiagDeclarationsException*/	{
 
 		if( checkDiagramDeclaration( _tmlsdSection ) )	{
 			if( checkMultipleDiagramDeclaration( _tmlsdSection ) )	{
 				String errorMessage = "TMLCP COMPILER ERROR: sequence diagram " + _tmlsdSection.getName() + " is defined multiple times";
-				throw new MultipleDiagDeclarationsException( errorMessage );
+				/*throw new MultipleDiagDeclarationsException( errorMessage );*/
 			}
 			else	{
    			sds.add( _tmlsdSection );
@@ -248,7 +248,7 @@ public class TMLCP extends TMLElement {
 		}
 		else	{
 			String errorMessage = "TMLCP COMPILER ERROR: sequence diagram " + _tmlsdSection.getName() + " undeclared";
-			throw new UndeclaredDiagramException( errorMessage );
+			/*throw new UndeclaredDiagramException( errorMessage );*/
 		}
   }
 	
diff --git a/src/tmltranslator/TMLCPTextSpecification.java b/src/tmltranslator/TMLCPTextSpecification.java
index 9316313d3d..cec3781b13 100755
--- a/src/tmltranslator/TMLCPTextSpecification.java
+++ b/src/tmltranslator/TMLCPTextSpecification.java
@@ -179,7 +179,7 @@ public class TMLCPTextSpecification {
 		return spec;
 	}
 	
-	public String toTextFormat( TMLCP.TMLCPGraphicalCP tmlcp ) {
+	public String toTextFormat( TMLCP tmlcp ) {
 
 		//tmlcp.sortByName();
 		spec = makeDeclarations( tmlcp );
@@ -198,14 +198,14 @@ public class TMLCPTextSpecification {
 		return "FAKE";
 	}
 	
-	public String makeDeclarations( TMLCP.TMLCPGraphicalCP tmlcp ) {
+	public String makeDeclarations( TMLCP tmlcp ) {
 
 		String sb = "";
 		sb += "// TML Communication Pattern - FORMAT 0.1" + CR;
 		sb += "// Communication Pattern: " + title + CR;
 		sb += "// Generated: " + new Date().toString() + CR2; 
 		
-		ArrayList<CPSequenceDiagram.TMLCPGraphicalSD> listSDs = tmlcp.getGraphicalSDs();
+		/*ArrayList<CPSequenceDiagram.TMLCPGraphicalSD> listSDs = tmlcp.getGraphicalSDs();
 
 		for( int i = 0; i < listSDs.size(); i++ )	{
 			CPSequenceDiagram.TMLCPGraphicalSD tempSD = listSDs.get(i);
@@ -226,66 +226,8 @@ public class TMLCPTextSpecification {
 			sb += CR;
 		}
 		sb += END + CR;
-		sb += END;
+		sb += END;*/
 
-		/*sb += "// Channels" + CR;
-		for(TMLChannel ch:tmlm.getChannels()) {
-			sb += "CHANNEL" + SP + ch.getName() + SP + TMLChannel.getStringType(ch.getType()) + SP + ch.getSize();
-			if (!ch.isInfinite()) {
-				sb += SP + ch.getMax();
-			}
-			sb += SP + ch.getOriginTask().getName() + SP + ch.getDestinationTask().getName() + CR;
-			
-			if (ch.isLossy()) {
-				sb += "LOSSYCHANNEL" + SP + ch.getName() + SP + ch.getLossPercentage() + SP + ch.getMaxNbOfLoss() + CR;
-			}
-		}
-		sb+= CR;
-		
-		sb += "// Events" + CR;
-		for(TMLEvent evt:tmlm.getEvents()) {
-			sb += "EVENT" + SP + evt.getName() + "(";
-				for(i=0; i<evt.getNbOfParams(); i++) {
-					if (i != 0) {
-						sb+= ", ";
-					}
-					sb += TMLType.getStringType(evt.getType(i).getType());
-				}
-				sb += ")";
-			sb += SP + evt.getTypeTextFormat();
-			if (!evt.isInfinite()) {
-				sb += SP + evt.getMaxSize();
-			}
-			sb +=  SP + evt.getOriginTask().getName() + SP + evt.getDestinationTask().getName();
-			
-			sb+= CR;
-			
-			if (evt.isLossy()) {
-				sb += "LOSSYEVENT" + SP + evt.getName() + SP + evt.getLossPercentage() + SP + evt.getMaxNbOfLoss() + CR;
-			}
-		}
-		sb+= CR;
-		
-		sb += "// Requests" + CR;
-		for(TMLRequest request:tmlm.getRequests()) {
-			sb += "REQUEST" + SP + request.getName() + "(";
-				for(i=0; i<request.getNbOfParams(); i++) {
-					if (i != 0) {
-						sb+= ", ";
-					}
-					sb += TMLType.getStringType(request.getType(i).getType());
-				}
-				sb += ")";
-			for(TMLTask t: request.getOriginTasks()) {
-				sb+= SP + t.getName();
-			}
-			sb += SP + request.getDestinationTask().getName();
-			sb+= CR;
-			
-			if (request.isLossy()) {
-				sb += "LOSSYREQUEST" + SP + request.getName() + SP + request.getLossPercentage() + SP + request.getMaxNbOfLoss() + CR;
-			}
-		}*/
 		sb+= CR;
 		
 		return sb;
diff --git a/src/tmltranslator/TMLSDAttribute.java b/src/tmltranslator/TMLSDAttribute.java
index a3b5a5f2e5..0987c1de21 100755
--- a/src/tmltranslator/TMLSDAttribute.java
+++ b/src/tmltranslator/TMLSDAttribute.java
@@ -54,7 +54,10 @@ public class TMLSDAttribute extends DIPLOElement {
     public String name;
     public String initialValue;
     
-    public TMLSDAttribute() {
+    public TMLSDAttribute( String _name ) {
+			this.name = _name;
+			type = new TMLSDType( "unknown" );
+			initialValue = "unknown";
     }
     
     public TMLSDAttribute( String _name, TMLSDType _type ) {
diff --git a/src/tmltranslator/tmlcp/CPSequenceDiagram.java b/src/tmltranslator/tmlcp/CPSequenceDiagram.java
index fe494bacf5..b11d1dec58 100755
--- a/src/tmltranslator/tmlcp/CPSequenceDiagram.java
+++ b/src/tmltranslator/tmlcp/CPSequenceDiagram.java
@@ -164,6 +164,7 @@ public class CPSequenceDiagram  extends TMLElement {
 	private ArrayList<TMLSDInstance> mappingInstances;
 	private ArrayList<TMLAttribute> globalVariables;
 	private ArrayList<TMLSDMessage> messages; 
+	private ArrayList<TMLSDAction> actions;
 	
 	private int hashCode;
 	private boolean hashCodeComputed = false;
@@ -174,15 +175,11 @@ public class CPSequenceDiagram  extends TMLElement {
 		init();
 	}
 
-	/*public CPSequenceDiagram()	{
-		super( "DefaultName", null );
-		init();
-	}*/
-
 	private void init() {
 		globalVariables = new ArrayList<TMLAttribute>();
 		instances = new ArrayList<TMLSDInstance>();
 		messages = new ArrayList<TMLSDMessage>();
+		actions = new ArrayList<TMLSDAction>();
 	}
     
  	public void addVariable( TMLAttribute _attr ) throws MultipleVariableDeclarationException	{
@@ -195,16 +192,33 @@ public class CPSequenceDiagram  extends TMLElement {
       globalVariables.add(_attr);
     }
 	}
+
+	public void addAttribute( TMLAttribute _attribute )	{	//used by the graphical 2 TMLTxt compiler
+      globalVariables.add( _attribute );
+	}
 	
 	public ArrayList<TMLAttribute> getAttributes() {
 		return globalVariables;
 	}
+
+	public void addAttribute( TMLSDAction _action ) {
+		actions.add( _action );
+	}
+
+	public ArrayList<TMLSDAction> getActions() {
+		return actions;
+	}
+
+	public void addAction( TMLSDAction _action ) {
+		actions.add( _action );
+	}
 	
-	public void addInstance( TMLSDInstance _elt ) throws MultipleInstanceDeclarationException {
+	//commenting the throw exception because bot needed by the graphical 2 TMLTxt compiler yet
+	public void addInstance( TMLSDInstance _elt )/* throws MultipleInstanceDeclarationException*/ {
 		
 		if( declaredInstance( _elt ) )	{
 			String errorMessage = "TMLCP COMPILER ERROR: instance " + _elt.getName() + " in diagram " + this.name + " declared multiple times";
-			throw new MultipleInstanceDeclarationException( errorMessage );
+			/*throw new MultipleInstanceDeclarationException( errorMessage );*/
 		}
 		else	{
 	    instances.add( _elt );
@@ -339,7 +353,7 @@ public class CPSequenceDiagram  extends TMLElement {
 	public TMLSDInstance retrieveInstance( String _name )	{
 			
 			ArrayList<TMLSDInstance> instList;
-			TMLSDInstance inst = new TMLSDInstance( "error", new Object() );
+			TMLSDInstance inst;
 			int i;
 
 			for( i = 0; i < instances.size(); i++ )	{
@@ -349,7 +363,7 @@ public class CPSequenceDiagram  extends TMLElement {
 					return inst;
 				}
 			}
-			return inst;
+			return new TMLSDInstance( "error", null, "NO_TYPE" );
 	}
 
 }	//End of class
diff --git a/src/tmltranslator/tmlcp/TMLSDAction.java b/src/tmltranslator/tmlcp/TMLSDAction.java
index f2bb4dc817..7b71ceddd9 100755
--- a/src/tmltranslator/tmlcp/TMLSDAction.java
+++ b/src/tmltranslator/tmlcp/TMLSDAction.java
@@ -1,6 +1,7 @@
-/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
+/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici
 
-ludovic.apvrille AT enst.fr
+ludovic.apvrille AT telecom-paristech.fr
+andrea.enrici AT telecom-paristech.fr
 
 This software is a computer program whose purpose is to allow the 
 edition of TURTLE analysis, design and deployment diagrams, to 
@@ -39,7 +40,7 @@ knowledge of the CeCILL license and that you accept its terms.
 * Class TMLSDAction
 * Creation: 18/02/2014
 * @version 1.0 18/02/2014
-* @author Ludovic APVRILLE
+* @author Ludovic APVRILLE, Andrea ENRICI
 * @see
 */
 
@@ -51,15 +52,22 @@ import java.util.*;
 import myutil.*;
 
 public class TMLSDAction extends TMLSDElement  {
+
 	private String action;
+	private int yCoord;
 	
-    public TMLSDAction(String _action, String _name, Object _referenceObject) {
-        super(_msg, _name, _referenceObject);
-        action = _action;
-    }
+   public TMLSDAction( String _action, Object _referenceObject, int _yCoord ) {
+		super( "action", _referenceObject);
+    action = _action;
+		this.yCoord = _yCoord;
+  }
     
-    public String getAction() {
-    	return action;
-    }
+  public String getAction() {
+  	return action;
+  }
+
+  public int getYCoord() {
+  	return this.yCoord;
+  }
 	
-}
\ No newline at end of file
+}
diff --git a/src/tmltranslator/tmlcp/TMLSDInstance.java b/src/tmltranslator/tmlcp/TMLSDInstance.java
index da56bd24f4..a1b17d5dea 100755
--- a/src/tmltranslator/tmlcp/TMLSDInstance.java
+++ b/src/tmltranslator/tmlcp/TMLSDInstance.java
@@ -1,6 +1,7 @@
-/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
+/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici
 
-ludovic.apvrille AT enst.fr
+ludovic.apvrille AT telecom-paristech.fr
+andrea.enrici AT telecom-paristech.fr
 
 This software is a computer program whose purpose is to allow the 
 edition of TURTLE analysis, design and deployment diagrams, to 
@@ -52,11 +53,18 @@ import java.util.*;
 import myutil.*;
 
 public class TMLSDInstance extends TMLElement  {
-		
+
 	private ArrayList<TMLSDElement> elements;
+	private String type;
 	
-	public TMLSDInstance(String _name, Object _referenceObject) {
-  	super(_name, _referenceObject);
+	public TMLSDInstance( String _name, Object _referenceObject, String _type ) {
+  	super( _name, _referenceObject );
+		this.type = _type;
+		elements = new ArrayList<TMLSDElement>();
+	}
+
+	public TMLSDInstance( String _name ) {
+  	super( _name, null );
 		elements = new ArrayList<TMLSDElement>();
 	}
     
@@ -67,5 +75,18 @@ public class TMLSDInstance extends TMLElement  {
   public ArrayList<TMLSDElement> getElements() {
   	return elements;
   }
+
+	public void setType( String _type )	{
+		if( _type != "" )	{
+			this.type = _type;
+		}
+		else	{
+			this.type = "NO_TYPE";
+		}
+	}
+	
+	public String getType()	{
+		return this.type;
+	}
 	
 }
diff --git a/src/tmltranslator/tmlcp/TMLSDMessage.java b/src/tmltranslator/tmlcp/TMLSDMessage.java
index ba6a57edcd..d8ed296b1a 100755
--- a/src/tmltranslator/tmlcp/TMLSDMessage.java
+++ b/src/tmltranslator/tmlcp/TMLSDMessage.java
@@ -52,25 +52,37 @@ import tmltranslator.*;
 import myutil.*;
 
 public class TMLSDMessage extends TMLElement  {
-	private String nameOfMessage;
+
 	private ArrayList<TMLSDAttribute> attributeList;	
+	private int yCoord;
 	
-    public TMLSDMessage(String _nameOfMsg, String _name, Object _referenceObject) {
-        super(_name, _referenceObject);
-        nameOfMessage = _nameOfMsg;
-				attributeList = new ArrayList<TMLSDAttribute>();
+    public TMLSDMessage( String _name, Object _referenceObject ) {
+    	super( _name, _referenceObject );
+			attributeList = new ArrayList<TMLSDAttribute>();
     }
+
+		public TMLSDMessage( String _name, Object _referenceObject, String[] _params )	{
+    	super( _name, _referenceObject );
+			attributeList = new ArrayList<TMLSDAttribute>();
+			for( String p: _params )	{
+				attributeList.add( new TMLSDAttribute(p) );
+			}
+		}
     
 		public void addAttribute( TMLSDAttribute _attribute )	{
 				attributeList.add( _attribute );
 		}
 
-    public String getMessageName() {
-    	return nameOfMessage;
-    }
-
 		public ArrayList<TMLSDAttribute> getAttributes()	{
 			return attributeList;
 		}
+
+		public int getYCoord()	{
+			return this.yCoord;
+		}
+
+		public void setYCoord( int _coord )	{
+			this.yCoord = _coord;
+		}
 	
 }	//End of class
diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java
index 97bd30d36c..4fa9d5eb06 100755
--- a/src/ui/GTURTLEModeling.java
+++ b/src/ui/GTURTLEModeling.java
@@ -144,7 +144,8 @@ public class GTURTLEModeling {
 	private TMLModeling tmlm;
 	private TMLMapping artificialtmap;
 	private TMLMapping tmap;
-	private TMLCP.TMLCPGraphicalCP tmlcp;
+	//private TMLCP.TMLCPGraphicalCP tmlcp;
+	private TMLCP tmlcp;
 	private RequirementModeling rm;
 	private NCStructure ncs;
 	private MainGUI mgui;
-- 
GitLab