diff --git a/src/remotesimulation/CommandParser.java b/src/remotesimulation/CommandParser.java index 97ac3484ce55a5490e0a09882e268ecf283aa0ad..41aba9453942e772e9fbb56b18fdb95a79067f4d 100755 --- a/src/remotesimulation/CommandParser.java +++ b/src/remotesimulation/CommandParser.java @@ -197,9 +197,11 @@ public class CommandParser { // get-command-and-task - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("get-command-and-task", "gcat", "14", params, paramNames, "Returns the current command and task"); + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "Task id"; + sc = new SimulationCommand("get-command-of-task", "gcot", "14", params, paramNames, "Returns the current command of the task provided as argument"); commandList.add(sc); // get-hash-code diff --git a/src/remotesimulation/RemoteConnection.java b/src/remotesimulation/RemoteConnection.java index 1964c11fed27a1d2369e81c56e07b21bb0a31aa4..2de2ac110ad618a8cbf578f96e84513a4c76efdc 100755 --- a/src/remotesimulation/RemoteConnection.java +++ b/src/remotesimulation/RemoteConnection.java @@ -120,7 +120,7 @@ public class RemoteConnection { } public void send(String s) throws RemoteConnectionException { - s = s .trim(); + s = s .trim() + " \n"; if (s.length() == 0) { return; } diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java index 6dd266ab92e5fac019d527bd20018fff64527fd5..c8c894c7be47c694eb1b92500e92d31e3395e611 100755 --- a/src/ui/MainGUI.java +++ b/src/ui/MainGUI.java @@ -244,6 +244,9 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { private JFileChooser jfctif; //private int selectedAction = -1; + + // Interaction with simulators + ArrayList<Integer> runningIDs; public MainGUI(boolean _systemcOn, boolean _lotosOn, boolean _proactiveOn, boolean _tpnOn, boolean _osOn, boolean _uppaalOn, boolean _ncOn) { systemcOn = _systemcOn; @@ -4856,9 +4859,50 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { } } + + // For simulation purpose public void toggleDiploIDs() { - TDiagramPanel.DIPLO_ID_ON = !TDiagramPanel.DIPLO_ID_ON; - getCurrentTDiagramPanel().repaint(); + setDiploIDs(!TDiagramPanel.DIPLO_ID_ON); + } + + public void setDiploIDs(boolean b) { + TDiagramPanel.DIPLO_ID_ON = b; + getCurrentTDiagramPanel().repaint(); + } + + public synchronized boolean isRunningID(int id) { + if (runningIDs == null) { + return false; + } + + for(Integer i: runningIDs) { + if (i.intValue() == id) { + return true; + } + } + + return false; + } + + public synchronized void addRunningID(Integer id) { + if (runningIDs == null) { + runningIDs = new ArrayList<Integer>(); + } + + runningIDs.add(id); + //System.out.println("Running id " + id + " added"); + getCurrentTDiagramPanel().repaint(); + } + + public synchronized void removeRunningId(Integer id) { + for(Integer i: runningIDs) { + if (i.intValue() == id.intValue()) { + runningIDs.remove(i); + //System.out.println("Running id " + i + " removed"); + return; + } + } + getCurrentTDiagramPanel().repaint(); } public void toggleGates() { diff --git a/src/ui/TGComponent.java b/src/ui/TGComponent.java index e4c3cea53f6dd990c0359dc9c734ed279b229483..0691bd2c905cceceb7d8dc812ddd6836727afa01 100755 --- a/src/ui/TGComponent.java +++ b/src/ui/TGComponent.java @@ -100,6 +100,7 @@ public abstract class TGComponent implements CDElement, GenericTree { // DIPLODOCUS ID private int DIPLOID = -1; + private boolean DIPLO_running = false; // Zone of drawing -> relative to father if applicable @@ -424,9 +425,47 @@ public abstract class TGComponent implements CDElement, GenericTree { } public void drawDiploID(Graphics g) { + g.setColor(ColorManager.DIPLOID); g.drawString(""+getDIPLOID(), x+width, y+height + 5); } + public void drawRunningDiploID(Graphics g) { + //System.out.println("Drawing running DIPLO"); + int wb = 30; + int hb = 10; + int wh = 15; + int hh = 20; + int sep = 10; + + int[] xp = new int[7]; + int[] yp = new int[7]; + + xp[0] = x - sep - wb -wh; + yp[0] = y + ((height-hb) / 2); + + xp[1] = x - sep - wh; + yp[1] = y + ((height-hb) / 2); + + xp[2] = x - sep - wh; + yp[2] = y + ((height-hh) / 2); + + xp[3] = x - sep; + yp[3] = y + (height / 2); + + xp[4] = x - sep - wh; + yp[4] = y + ((height+hh) / 2); + + xp[5] = x - sep - wh; + yp[5] = y + ((height+hb) / 2); + + xp[6] = x - sep - wb -wh; + yp[6] = y + ((height+hb) / 2); + + g.setColor(ColorManager.BREAKPOINT); + g.fillPolygon(xp, yp, 7); + + } + public void draw(Graphics g) { ColorManager.setColor(g, state, 0); internalDrawing(g); @@ -460,11 +499,13 @@ public abstract class TGComponent implements CDElement, GenericTree { g.drawString("bk", x+width, y+3); g.setFont(f); } - g.setColor(ColorManager.DIPLOID); if (! ((this instanceof TGConnector) || (this instanceof TGCNote))) { if (tdp instanceof TMLActivityDiagramPanel) { if (getFather() == null) { drawDiploID(g); + if (tdp.getMGUI().isRunningID(getDIPLOID())) { + drawRunningDiploID(g); + } } } else if (tdp instanceof TMLComponentTaskDiagramPanel) { if (this instanceof TMLCPrimitiveComponent) { diff --git a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java index b646b46e66c715882b6963d21c297bd08f1c386a..e5c1606010b1dff99b67d9b862d38bd52b7cbfc3 100755 --- a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java +++ b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java @@ -69,10 +69,11 @@ import org.xml.sax.*; import javax.xml.parsers.*; -public class JFrameInteractiveSimulation extends JFrame implements ActionListener, Runnable, MouseListener/*, StoppableGUIElement, SteppedAlgorithm, ExternalCall*/ { +public class JFrameInteractiveSimulation extends JFrame implements ActionListener, Runnable, MouseListener, ItemListener/*, StoppableGUIElement, SteppedAlgorithm, ExternalCall*/ { protected static final String SIMULATION_HEADER = "siminfo"; protected static final String SIMULATION_GLOBAL = "global"; + protected static final String SIMULATION_TASK = "task"; private static String buttonStartS = "Start simulator"; private static String buttonCloseS = "Close"; @@ -114,7 +115,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene protected StateCommandsToolBar stctb; JPanel main, mainTop, commands, save, state, infos, outputs, cpuPanel, variablePanel; // from MGUI - JCheckBox debug; + JCheckBox debug, animate; JTabbedPane commandTab, infoTab; protected JTextField paramMainCommand; protected JTextField saveFileName; @@ -168,6 +169,8 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene private Hashtable <Integer, String> valueTable; private Hashtable <Integer, Integer> rowTable; + private Hashtable <Integer, Integer> runningTable; + public JFrameInteractiveSimulation(Frame _f, MainGUI _mgui, String _title, String _hostSystemC, String _pathExecute, TMLMapping _tmap) { super(_title); @@ -188,6 +191,8 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene valueTable = new Hashtable<Integer, String>(); rowTable = new Hashtable<Integer, Integer>(); + runningTable = new Hashtable<Integer, Integer>(); + setBackground(new Color(50, 40, 40, 200)); @@ -471,6 +476,10 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene jp01.add(new JLabel(" "), c01); debug = new JCheckBox("Print messages received from server"); jp01.add(debug, c01); + animate = new JCheckBox("Animate UML diagrams"); + jp01.add(animate, c01); + animate.addItemListener(this); + animate.setSelected(true); TableSorter sorterPI; @@ -480,7 +489,13 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene taskPanel = new JPanel(); taskPanel.setLayout(new BorderLayout()); infoTab.addTab("Tasks", IconManager.imgic1202, taskPanel, "Current state of tasks"); - TaskTableModel tasktm = new TaskTableModel(tmap.getTMLModeling(), valueTable, rowTable); + TaskTableModel tasktm; + if (tmap == null) { + tasktm = new TaskTableModel(null, valueTable, rowTable); + } else { + tasktm = new TaskTableModel(tmap.getTMLModeling(), valueTable, rowTable); + } + sorterPI = new TableSorter(tasktm); jtablePI = new JTable(sorterPI); sorterPI.setTableHeader(jtablePI.getTableHeader()); @@ -729,7 +744,8 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene setComponents(); - sendCommand("time"); + //sendCommand("time"); + askForUpdate(); if (tmap != null) { sendCommand("get-hashcode"); } @@ -763,10 +779,11 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene threadStarted(); while(true) { testGo(); - Thread.currentThread().sleep(200); + Thread.currentThread().sleep(500); if (busyStatus && gotTimeAnswerFromServer) { gotTimeAnswerFromServer = false; - sendCommand("time"); + askForUpdate(); + } } } @@ -842,7 +859,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene protected void sendCommand() { String text = textCommand.getText().trim(); - sendCommand(text); + sendCommand(text + "\n"); } protected void sendCommand(String text) { @@ -962,6 +979,10 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene String error = null; String hash = null; + String id; + String name; + String command; + try { for(int j=0; j<diagramNl.getLength(); j++) { //System.out.println("Ndes: " + j); @@ -1007,6 +1028,25 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene } } + + if (elt.getTagName().compareTo(SIMULATION_TASK) == 0) { + id = null; + name = null; + command = null; + id = elt.getAttribute("id"); + name = elt.getAttribute("name"); + nl = elt.getElementsByTagName("currcmd"); + if (nl.getLength() > 0) { + node0 = nl.item(0); + command = node0.getTextContent(); + } + + System.out.println("Got info on task " + id + " command=" + command); + + if ((id != null) && (command != null)) { + updateRunningCommand(id, command); + } + } } } } catch (Exception e) { @@ -1037,8 +1077,12 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene jta.append("*** Some features are therefore deactivated ***\n\n"); cpuPanel.setVisible(false); variablePanel.setVisible(false); + animate.setSelected(false); + animate.setEnabled(false); } else { jta.append("\n*** Simulated model is the one currently loaded under TTool ***\n"); + animate.setSelected(true); + animate.setEnabled(true); } } catch (Exception e) { } @@ -1076,7 +1120,8 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene if (s.equals("ready")) { if (busyStatus) { System.out.println("Sending time command"); - sendCommand("time"); + askForUpdate(); + //sendCommand("time"); } setBusyStatus(false); } @@ -1272,7 +1317,55 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene } } + private void updateTaskCommands() { + if (tmap == null) { + return; + } + + if (mode != STARTED_AND_CONNECTED) { + return; + } + + for(TMLTask task: tmap.getTMLModeling().getTasks()) { + sendCommand("get-command-of-task " + task.getID()); + } + } + + private void updateRunningCommand(String id, String command) { + Integer i = getInteger(id); + Integer c = getInteger(command); + + if ((i != null) && (c != null)) { + try { + System.out.println("Searching for old value"); + Integer old = runningTable.get(i); + if(old != null) { + mgui.removeRunningId(old); + runningTable.remove(old); + } + + runningTable.put(i, c); + System.out.println("Adding running command"); + mgui.addRunningID(c); + } catch (Exception e) { + System.out.println("Exception updateRunningCommand: " + e.getMessage()); + } + } + + } + + public void askForUpdate() { + sendCommand("time"); + if (animate.isSelected()) { + updateTaskCommands(); + } + } + public void itemStateChanged(ItemEvent e) { + if (e.getSource() == animate) { + mgui.setDiploIDs(animate.isSelected()); + } + } public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); @@ -1311,6 +1404,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene sendRestoreStateCommand(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_RESET_SIMU].getActionCommand())) { sendCommand("reset"); + askForUpdate(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_STOP_SIMU].getActionCommand())) { sendCommand("stop"); } else if (command.equals(actions[InteractiveSimulationActions.ACT_UPDATE_VARIABLES].getActionCommand())) { @@ -1343,5 +1437,13 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene return false; } + public Integer getInteger(String s) { + try { + return Integer.decode(s); + } catch (Exception e) { + return null; + } + } + } // Class \ No newline at end of file