From 1efa7988a370529a380787ac5b4e1971b07dfc9c Mon Sep 17 00:00:00 2001
From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr>
Date: Fri, 24 Jul 2009 09:35:45 +0000
Subject: [PATCH] Update on MSC loader

---
 src/sddescription/MSC.java                    | 31 +++++++
 src/sddescription/SDExchange.java             |  6 +-
 src/ui/MSCDrawer.java                         | 90 +++++++++++++++++--
 src/ui/TDiagramPanel.java                     |  2 +-
 src/ui/TGUIAction.java                        |  4 +-
 .../JFrameInteractiveSimulation.java          | 23 ++++-
 src/ui/sd/SequenceDiagramPanel.java           | 21 +++++
 7 files changed, 164 insertions(+), 13 deletions(-)

diff --git a/src/sddescription/MSC.java b/src/sddescription/MSC.java
index 093f89f035..6b6131cbc0 100755
--- a/src/sddescription/MSC.java
+++ b/src/sddescription/MSC.java
@@ -345,5 +345,36 @@ public class MSC extends HMSCElement {
 		return list;
 	}
 	
+	public int getOrderOfEvt(Evt _evt) {
+		// Computes the nb of evts that occur in the instance before
+		// the evt given as parameter
+		
+		ArrayList<Evt> metEvts = new ArrayList<Evt>();
+		
+		
+		computeAllEvtsBefore(metEvts, _evt);
+		
+		return (metEvts.size() - 1);
+	}
+	
+	private void computeAllEvtsBefore(ArrayList<Evt> _metEvts, Evt _evt) {
+		ListIterator iterator;
+		Order order;
+		
+		_metEvts.add(_evt);
+		
+		iterator = orders.listIterator();
+		while(iterator.hasNext()) {
+			order = (Order)(iterator.next());
+			if(order.evt2 == _evt) {
+				if (order.evt1.getInstance() == _evt.getInstance()) {
+					if (!_metEvts.contains(order.evt1)) {
+						computeAllEvtsBefore(_metEvts, order.evt1);
+					}
+				}
+			}
+		}
+	}
+	
 	
 }
diff --git a/src/sddescription/SDExchange.java b/src/sddescription/SDExchange.java
index 3b235fccd5..dbae83d626 100755
--- a/src/sddescription/SDExchange.java
+++ b/src/sddescription/SDExchange.java
@@ -185,8 +185,8 @@ public class SDExchange {
 								System.out.println("Duplicate name for instance " + tmp + ": ignoring second instance");
 							} else {
 								instance = _hmsc.getCreateInstanceIfNecessary(tmp);
-								loadInstance(elt.getChildNodes(), _hmsc, _msc, instance);
 							}
+							loadInstance(elt.getChildNodes(), _hmsc, _msc, instance);
 						} else {
 							System.out.println("Instance without a name: skipping");
 						}
@@ -279,7 +279,7 @@ public class SDExchange {
 			LinkEvts le;
             
             System.out.println("Loading links ");
-            //System.out.println(nl.toString());
+            System.out.println(nl.toString());
             
             for(int i=0; i<nl.getLength(); i++) {
                 n1 = nl.item(i);
@@ -307,6 +307,7 @@ public class SDExchange {
 									System.out.println("Error in xml specification: evts not found. Skipping");
 								}
 							} catch (Exception e) {
+								System.out.println("Exception in loadlinks: parsing ints");
 							}
 							
 						}
@@ -316,6 +317,7 @@ public class SDExchange {
 			}
     
         } catch (Exception e) {
+			System.out.println("Exception in loadlinks");
             return false;
         }
 		return true;
diff --git a/src/ui/MSCDrawer.java b/src/ui/MSCDrawer.java
index 34b2058ab0..338445be5e 100755
--- a/src/ui/MSCDrawer.java
+++ b/src/ui/MSCDrawer.java
@@ -54,7 +54,10 @@ import ui.iod.*;
 
 public class MSCDrawer {
 	public final static int DEC = 50;
-	public final static int DEC_COMP = 50;
+	public final static int DEC_COMP = 30;
+	public final static int INIT_X = 100;
+	public final static int INIT_Y = 40;
+	
     private MainGUI mgui;
 	private HMSC hmsc;
     private MSC msc;
@@ -168,9 +171,11 @@ public class MSCDrawer {
 		SequenceDiagramPanel sdp;
 		ListIterator iterator;
 		Instance instance;
-		int myX = 50;
-		int myY = 40;
+		int myX = INIT_X;
+		int myY = INIT_Y;
 		TGComponent tgc;
+		ArrayList<SDInstance> ginstances;
+		SDInstance sdi;
 		//SDInstance sdi;
 		
 		// Creates the panel
@@ -185,21 +190,92 @@ public class MSCDrawer {
 		}
 		
 		// Put instances
+		ginstances = new ArrayList<SDInstance>();
 		iterator = _hmsc.getInstances().listIterator();
 		while(iterator.hasNext()) {
 			instance = (Instance)(iterator.next());
 			tgc = TGComponentManager.addComponent(myX, myY, TGComponentManager.SD_INSTANCE, sdp);
 			tgc.setValue(instance.getName());
 			sdp.addBuiltComponent(tgc);
+			ginstances.add((SDInstance)tgc);
 			telements.add(instance);
 			gelements.add(tgc);
-			myX += (4 * DEC);
+			myX += (5 * DEC);
 		}
 		
 		// Put events on instances -> sending, receving are ignored for the moment
-		ListIterator li2;
-		ListIterator li1 = _hmsc.getInstances().listIterator();
-		Order order;
+		//ListIterator li2;
+		ListIterator li1 = msc.getEvts().listIterator();
+		Evt evt, evt1, evt2;
+		int indexInstance;
+		
+		while(li1.hasNext()) {
+			evt = (Evt)(li1.next());
+			indexInstance = hmsc.getInstances().indexOf(evt.getInstance());
+			sdi = ginstances.get(indexInstance);
+			myX = INIT_X + (5*DEC) * indexInstance;
+			myY = INIT_Y + DEC_COMP + msc.getOrderOfEvt(evt) * (DEC_COMP);
+			tgc = null;
+			
+			if (evt.getType() == Evt.VARIABLE_SET) {
+				tgc = TGComponentManager.addComponent(myX, myY, TGComponentManager.SD_ACTION_STATE, sdp);
+				tgc.setValue(evt.getActionId());
+			}
+			
+			if (tgc != null) {
+				// Check first the size of the instance as well as the size of the panel
+				if (myY > (sdi.getY() + sdi.getHeight() + 20)) {
+						// Increase size of all instances
+						sdp.increaseInstanceSize(250);
+				}
+				// Add the component to the instance
+				sdi.addSwallowedTGComponent(tgc, myX, myY);
+			}
+			
+		}
+		
+		// Sending, receiving events
+		// For them, we parse links between events
+		li1 = msc.getLinksEvts().listIterator();
+		LinkEvts le;
+		TGConnectingPoint p1, p2;
+		TGConnectorMessageSD msg;
+		
+		while(li1.hasNext()) {
+			le = (LinkEvts)(li1.next());
+			
+			evt1 = le.evt1;
+			evt2 = le.evt2;
+			
+			if (evt2.getType() == Evt.SEND_SYNC) {
+				evt = evt2;
+				evt2 = evt1;
+				evt1 = evt;
+			}
+			
+			if ((evt1.getType() == Evt.SEND_SYNC) && (evt2.getType() == Evt.RECV_SYNC)) {
+				indexInstance = hmsc.getInstances().indexOf(evt1.getInstance());
+				sdi = ginstances.get(indexInstance);
+				myX = INIT_X + (5*DEC) * indexInstance;
+				myY = INIT_Y + DEC_COMP + msc.getOrderOfEvt(evt1) * (DEC_COMP);
+				p1 = sdi.closerFreeTGConnectingPoint(myX, myY);
+				
+				indexInstance = hmsc.getInstances().indexOf(evt2.getInstance());
+				sdi = ginstances.get(indexInstance);
+				myX = INIT_X + (5*DEC) * indexInstance;
+				myY = INIT_Y + DEC_COMP + msc.getOrderOfEvt(evt2) * (DEC_COMP);
+				p2 = sdi.closerFreeTGConnectingPoint(myX, myY);
+				
+				if ((p1 != null) && (p2 != null)) {
+					msg = (TGConnectorMessageSD)(TGComponentManager.addConnector(p1.x, p1.y, TGComponentManager.CONNECTOR_MESSAGE_SYNC_SD, sdp, p1, p2, new Vector()));
+					msg.setValue(evt1.getActionId());
+					sdp.addBuiltComponent(msg);
+					System.out.println("added a synchronous message");
+				}
+			} else {
+				System.out.println("Badly formed linkevt");
+			}
+		}
 		
 		
 		/*while(li1.hasNext()) {
diff --git a/src/ui/TDiagramPanel.java b/src/ui/TDiagramPanel.java
index fef6003936..c2fb957059 100755
--- a/src/ui/TDiagramPanel.java
+++ b/src/ui/TDiagramPanel.java
@@ -120,7 +120,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     
     private final int minimumXSize = 900;
     private final int minimumYSize = 900;
-    private final int increment = 500;
+    protected final int increment = 500;
     
     private double zoom = 1.0;
 	private boolean zoomed = false;
diff --git a/src/ui/TGUIAction.java b/src/ui/TGUIAction.java
index 2a5ab4f3aa..642d4bccc6 100755
--- a/src/ui/TGUIAction.java
+++ b/src/ui/TGUIAction.java
@@ -475,8 +475,8 @@ public class TGUIAction extends AbstractAction {
         actions[ACT_GEN_RTLOTOS] = new TAction("gen_rtlotos-command", "Generate RT-LOTOS", IconManager.imgic34, IconManager.imgic35, "Generate RT-LOTOS specification",  "Generates a RT-LOTOS specification from TURTLE diagrams", KeyEvent.VK_F6);
         actions[ACT_GEN_LOTOS] = new TAction("gen_lotos-command", "Generate LOTOS", IconManager.imgic34, IconManager.imgic35, "Generate LOTOS specification",  "Generates a LOTOS specification from TURTLE diagrams", '0');
         actions[ACT_ONECLICK_LOTOS_RG] = new TAction("gen_rglotos-command", "Generate LOTOS-based RG", IconManager.imgic342, IconManager.imgic342, "Generate LOTOS-based RG ",  "Generates a LOTOS-based RG  from TURTLE diagrams", '0');
-        actions[ACT_ONECLICK_RTLOTOS_RG] = new TAction("gen_rgrtlotos-command", "Generate RT-LOTOS-based RG", IconManager.imgic342, IconManager.imgic342, "Generate RT-LOTOS-based RG ",  "Generates a RT-LOTOS-based RG  from TURTLE diagrams", '0');
-        actions[ACT_GEN_UPPAAL] = new TAction("gen_uppaal-command", "Generate UPPAAL", IconManager.imgic34, IconManager.imgic35, "Generate UPPAAL specification",  "Generates an UPPAAL specification from DIPLODOCUS diagrams", '0');
+        actions[ACT_ONECLICK_RTLOTOS_RG] = new TAction("gen_rgrtlotos-command", "Generate RT-LOTOS-based RG", IconManager.imgic342, IconManager.imgic342, "Generate RT-LOTOS-based RG ",  "Generates an RT-LOTOS-based RG  from TURTLE diagrams", '0');
+        actions[ACT_GEN_UPPAAL] = new TAction("gen_uppaal-command", "Generate UPPAAL", IconManager.imgic34, IconManager.imgic35, "Generate UPPAAL specification",  "Generates a UPPAAL specification from DIPLODOCUS diagrams", '0');
         actions[ACT_GEN_JAVA] = new TAction("gen_java-command", "Generate JAVA", IconManager.imgic38, IconManager.imgic39, "Generate JAVA",  "Generates Java code from TURTLE diagrams", 0);
         actions[ACT_SIMU_JAVA] = new TAction("gen_simujava-command", "Java-based simulation", IconManager.imgic38, IconManager.imgic39, "JAVA-based simualtion",  "Simulate diagrams using Java language", 0);
         actions[ACT_GEN_SYSTEMC] = new TAction("gen_systemc-command", "Generate SystemC", IconManager.imgic61, IconManager.imgic61, "Generate SystemC",  "Generates SystemC code from TML Design diagrams", 0);
diff --git a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java
index d8d119416a..c76a4a56c1 100755
--- a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java
+++ b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java
@@ -131,7 +131,7 @@ public	class JFrameInteractiveSimulation extends JFrame implements ActionListene
 	private String[] cpuIDs, busIDs, memIDs, taskIDs, chanIDs;
 	
 	// Status elements
-	JLabel status, time;
+	JLabel status, time, info;
 	
 	// Task elements
 	TaskVariableTableModel tvtm;
@@ -560,6 +560,11 @@ public	class JFrameInteractiveSimulation extends JFrame implements ActionListene
 		time = new JLabel("Unknown");
 		time.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN);
 		jp02.add(time);
+		jp02.add(new JLabel(" "));
+		jp02.add(new JLabel("Sim. interrupt reason:"));
+		info = new JLabel("Unknown");
+		info.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN);
+		jp02.add(info);
 		
 		// Options
 		jp01 = new JPanel();
@@ -1144,6 +1149,14 @@ public	class JFrameInteractiveSimulation extends JFrame implements ActionListene
 							makeStatus(node0.getTextContent());
 						}
 						
+						nl = elt.getElementsByTagName("brkreason");
+						if (nl.getLength() > 0) {
+							node0 = nl.item(0);
+							//System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent());
+							
+							makeBrkReason(node0.getTextContent());
+						}
+						
 						nl = elt.getElementsByTagName("simtime");
 						if (nl.getLength() > 0) {
 							gotTimeAnswerFromServer = true;
@@ -1409,6 +1422,10 @@ public	class JFrameInteractiveSimulation extends JFrame implements ActionListene
 		notify();
 	}
 	
+	public void makeBrkReason(String s) {
+		info.setText(s);
+	}
+	
 	public void makeStatus(String s) {
 		//System.out.println("busystatus="  + busyStatus);
 		
@@ -1452,18 +1469,22 @@ public	class JFrameInteractiveSimulation extends JFrame implements ActionListene
 		case 0:
 			status.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN);
 			time.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN);
+			info.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN);
 			break;
 		case 1:
 			status.setForeground(ColorManager.InteractiveSimulationText_READY);
 			time.setForeground(ColorManager.InteractiveSimulationText_READY);
+			info.setForeground(ColorManager.InteractiveSimulationText_READY);
 			break;        
 		case 2:
 			status.setForeground(ColorManager.InteractiveSimulationText_BUSY);
 			time.setForeground(ColorManager.InteractiveSimulationText_BUSY);
+			info.setForeground(ColorManager.InteractiveSimulationText_BUSY);
 			break;
 		case 3:
 			status.setForeground(ColorManager.InteractiveSimulationText_TERM);
 			time.setForeground(ColorManager.InteractiveSimulationText_TERM);
+			info.setForeground(ColorManager.InteractiveSimulationText_TERM);
 			break;
 		}
 		
diff --git a/src/ui/sd/SequenceDiagramPanel.java b/src/ui/sd/SequenceDiagramPanel.java
index 5c5902051d..ff2df3193b 100755
--- a/src/ui/sd/SequenceDiagramPanel.java
+++ b/src/ui/sd/SequenceDiagramPanel.java
@@ -305,4 +305,25 @@ public class SequenceDiagramPanel extends TDiagramPanel {
         }
         return found;
     }
+	
+	public void increaseInstanceSize(int size) {
+		Iterator iterator = componentList.listIterator();
+        TGComponent tgc;
+		int maxYH = 0;
+		
+        while(iterator.hasNext()) {
+            tgc = (TGComponent)(iterator.next());
+			
+			if (tgc instanceof SDInstance) {
+				tgc.setUserResize(tgc.getX(), tgc.getY(), tgc.getWidth(), tgc.getHeight() + size);
+			}
+			
+			maxYH = Math.max(maxYH, tgc.getY() + tgc.getHeight());
+		}
+		
+		if (maxYH > getMaxY()) {
+			setMaxY(getMaxY() + increment);
+            updateSize();
+		}
+	}
 }
\ No newline at end of file
-- 
GitLab