From 341ec99841d71ff9599ebaa1f624f7a79565adab Mon Sep 17 00:00:00 2001
From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr>
Date: Fri, 25 Feb 2011 16:16:09 +0000
Subject: [PATCH] DIPLODOCUS: bug resolved on channel mapping edition of
 artifact

---
 .../AvatarSimulationBlock.java                |  3 ++
 .../AvatarSpecificationSimulation.java        | 44 +++++++++++++------
 .../BlockTableModel.java                      |  4 +-
 .../TMLComponentTaskDiagramPanel.java         |  4 +-
 .../window/JDialogCommunicationArtifact.java  | 13 ++++++
 5 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/src/avatartranslator/directsimulation/AvatarSimulationBlock.java b/src/avatartranslator/directsimulation/AvatarSimulationBlock.java
index 5dff83b4b3..636d445618 100644
--- a/src/avatartranslator/directsimulation/AvatarSimulationBlock.java
+++ b/src/avatartranslator/directsimulation/AvatarSimulationBlock.java
@@ -299,7 +299,10 @@ public class AvatarSimulationBlock  {
 		ast.id = ast.setID();
 		if (_aspt != null) {
 			ast.silent = _aspt.isSilent;
+		} else {
+			ast.silent = true;
 		}
+		TraceManager.addDev("Transaction " + ast.id + " silent=" + ast.silent);
 		if (_aspt != null) {
 			_aspt.clockValueAtEnd = _clockValue;
 			if (_aspt.hasClock) {
diff --git a/src/avatartranslator/directsimulation/AvatarSpecificationSimulation.java b/src/avatartranslator/directsimulation/AvatarSpecificationSimulation.java
index a74fe77c48..44efa3b6ef 100644
--- a/src/avatartranslator/directsimulation/AvatarSpecificationSimulation.java
+++ b/src/avatartranslator/directsimulation/AvatarSpecificationSimulation.java
@@ -103,7 +103,9 @@ public class AvatarSpecificationSimulation  {
 		executeEmptyTransition = true;
 		executeStateEntering = true;
 		
-		setState(INITIALIZE);
+		initialize();
+		reset();
+		setState(GATHER);
     }
 	
 	public AvatarSpecification getAvatarSpecification() {
@@ -684,7 +686,7 @@ public class AvatarSpecificationSimulation  {
 					}
 				}
 			// State entering?
-			} else if ((tr.elementToExecute instanceof AvatarState) && (executeStateEntering)) {
+			} else if (((tr.elementToExecute instanceof AvatarState) ||  (tr.elementToExecute instanceof AvatarStopState)) && (executeStateEntering)) {
 				if (nbOfTransactions(tr.asb, _pendingTransactions) < 2) {
 					tr.isSilent = true;
 					return tr;
@@ -713,13 +715,19 @@ public class AvatarSpecificationSimulation  {
 			if ((tr.elementToExecute instanceof AvatarTransition) && (executeEmptyTransition)) {
 				AvatarTransition atr = (AvatarTransition)(tr.elementToExecute);
 				if (!(atr.hasDelay()) && !(atr.hasCompute()) && !(atr.hasActions())){
+					TraceManager.addDev("Empty transition?");
 					if (nbOfTransactions(tr.asb, _pendingTransactions) < 2) {
+						tr.isSilent = true;
+						TraceManager.addDev("Yes");
 						return tr;
 					}
 				}
 			// State entering?
-			} else if ((tr.elementToExecute instanceof AvatarState) && (executeStateEntering)) {
+			} else if (((tr.elementToExecute instanceof AvatarState) ||  (tr.elementToExecute instanceof AvatarStopState)) && (executeStateEntering)) {
+				TraceManager.addDev("Empty state enter?");
 				if (nbOfTransactions(tr.asb, _pendingTransactions) < 2) {
+					tr.isSilent = true;
+					TraceManager.addDev("Yes");
 					return tr;
 				}
 			}
@@ -848,6 +856,10 @@ public class AvatarSpecificationSimulation  {
 	}
 	
 	public synchronized void backOneTransactionBunch() {
+		backOneTransactionBunch(false);
+	}
+	
+	public synchronized void backOneTransactionBunch(boolean _rec) {
 		if ( (state != DONT_EXECUTE) && (state != TERMINATED)) {
 			return;
 		}
@@ -862,11 +874,11 @@ public class AvatarSpecificationSimulation  {
 		// Getting last transaction
 		
 		AvatarSimulationTransaction ast = allTransactions.get(allTransactions.size()-1);
-		long bunchid = ast.bunchid;
+		long bunchid_tmp = ast.bunchid;
 		
 		boolean isAllSilent = true;
 		
-		while((ast != null) && (ast.bunchid == bunchid)) {
+		while((ast != null) && (ast.bunchid == bunchid_tmp)) {
 			allTransactions.removeElementAt(allTransactions.size()-1);
 			if (ast.asb != null) {
 				ast.asb.removeLastTransaction(ast);
@@ -892,9 +904,19 @@ public class AvatarSpecificationSimulation  {
 			}
 		}
 		
-		if (ast != null) {
+		if (isAllSilent) {
+			backOneTransactionBunch(true);
+		}
+		
+		if (_rec) {
+			return;
+		}
+		
+		TraceManager.addDev("Backward size="+ allTransactions.size());
+		
+		if (allTransactions.size() > 0) {
 			bunchid = (allTransactions.get(allTransactions.size()-1).bunchid) + 1;
-			clockValue = ast.clockValueWhenFinished;
+			clockValue = (allTransactions.get(allTransactions.size()-1)).clockValueWhenFinished;
 		} else {
 			bunchid = 0;
 			clockValue =  0;
@@ -902,13 +924,7 @@ public class AvatarSpecificationSimulation  {
 		
 		AvatarSimulationTransaction.setID(allTransactions.size());
 		
-		
-		TraceManager.addDev("Backward size="+ allTransactions.size());
-		
-		if (isAllSilent) {
-			backOneTransactionBunch();
-		}
-		
+		setNbOfCommands(0);
 		newState = true;
 		notifyAll();
 	}
diff --git a/src/ui/avatarinteractivesimulation/BlockTableModel.java b/src/ui/avatarinteractivesimulation/BlockTableModel.java
index f4676aaadc..b8aef127db 100755
--- a/src/ui/avatarinteractivesimulation/BlockTableModel.java
+++ b/src/ui/avatarinteractivesimulation/BlockTableModel.java
@@ -144,10 +144,10 @@ public class BlockTableModel extends AbstractTableModel {
 		
 		if (ass.getSimulationBlocks() != null) {
 			nbOfRows = ass.getSimulationBlocks().size();
+		} else {
+			nbOfRows = -1;
 		}
 		
-		nbOfRows = -1;
-		
 		return;
 	}
 
diff --git a/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java b/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java
index fb0481cab4..4a02cd1bd6 100755
--- a/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java
+++ b/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java
@@ -304,9 +304,9 @@ public class TMLComponentTaskDiagramPanel extends TDiagramPanel implements TDPWi
 					//TraceManager.addDev("Considering port1 = " +port1.getPortName() + " size of connecting ports:" + portstome.size());
 					
 					ListIterator ite = portstome.listIterator();
-					while(ite.hasNext()) {
+					//while(ite.hasNext()) {
 						//TraceManager.addDev("port=" + ((TMLCPrimitivePort)(ite.next())).getPortName());
-					}
+					//}
 					
 					if (portstome.size() == 1) {
 						port2 = (TMLCPrimitivePort)(portstome.get(0));
diff --git a/src/ui/window/JDialogCommunicationArtifact.java b/src/ui/window/JDialogCommunicationArtifact.java
index f7d8b96636..aa2d934782 100755
--- a/src/ui/window/JDialogCommunicationArtifact.java
+++ b/src/ui/window/JDialogCommunicationArtifact.java
@@ -56,6 +56,8 @@ import ui.*;
 
 import ui.tmldd.*;
 
+import myutil.*;
+
 
 public class JDialogCommunicationArtifact extends javax.swing.JDialog implements ActionListener  {
     
@@ -80,8 +82,15 @@ public class JDialogCommunicationArtifact extends javax.swing.JDialog implements
 		
 		//System.out.println("New window");
         
+		TraceManager.addDev("init components");
+		
         initComponents();
+		
+		TraceManager.addDev("my init components");
+		
         myInitComponents();
+		
+		TraceManager.addDev("pack");
         pack();
     }
     
@@ -116,6 +125,7 @@ public class JDialogCommunicationArtifact extends javax.swing.JDialog implements
         c1.fill = GridBagConstraints.HORIZONTAL;
         panel2.add(new JLabel("Task:"), c2);
         c1.gridwidth = GridBagConstraints.REMAINDER; //end row
+		TraceManager.addDev("Getting communications");
 		Vector<String> list = artifact.getTDiagramPanel().getMGUI().getAllTMLCommunicationNames();
 		int index = 0;
 		if (list.size() == 0) {
@@ -126,6 +136,9 @@ public class JDialogCommunicationArtifact extends javax.swing.JDialog implements
 			index = indexOf(list, artifact.getFullValue());
 			//System.out.println("name=" + artifact.getFullValue() + " index=" + index);
 		}
+		
+		TraceManager.addDev("Got communications");
+		
         referenceCommunicationName = new JComboBox(list);
 		referenceCommunicationName.setSelectedIndex(index);
 		referenceCommunicationName.addActionListener(this);
-- 
GitLab