diff --git a/src/main/java/avatartranslator/AvatarSyntaxChecker.java b/src/main/java/avatartranslator/AvatarSyntaxChecker.java index 00b8d61dbf8b922c92689923838cd7030718ed2d..7ee7aad53b38df992711208626723dadfde0dcb4 100644 --- a/src/main/java/avatartranslator/AvatarSyntaxChecker.java +++ b/src/main/java/avatartranslator/AvatarSyntaxChecker.java @@ -269,7 +269,19 @@ public class AvatarSyntaxChecker { act = Conversion.putVariableValueInString(AvatarSpecification.ops, act, aa.getName(), aa.getDefaultInitialValue()); } - IntExpressionEvaluator iee = new IntExpressionEvaluator(); + AvatarExpressionSolver e1 = new AvatarExpressionSolver(act); + boolean ret = e1.buildExpression(); + if (!ret) { + return -1; + } + + if (e1.getReturnType() == AvatarExpressionSolver.IMMEDIATE_INT) { + return 0; + } + + return -1; + + /*IntExpressionEvaluator iee = new IntExpressionEvaluator(); //TraceManager.addDev("Evaluating int:" + act); double result = iee.getResultOf(act); @@ -278,7 +290,7 @@ public class AvatarSyntaxChecker { return -1; } - return 0; + return 0;*/ // OLD return parse(_as, _ab, "actionnat", _expr); } diff --git a/src/main/java/avatartranslator/directsimulation/AvatarSimulationBlock.java b/src/main/java/avatartranslator/directsimulation/AvatarSimulationBlock.java index 4b4d11c243576a916414e829a0e0eefe7e939329..2ae76e0d56ad92d8e95ec23830de5a9de29dfcba 100644 --- a/src/main/java/avatartranslator/directsimulation/AvatarSimulationBlock.java +++ b/src/main/java/avatartranslator/directsimulation/AvatarSimulationBlock.java @@ -744,7 +744,7 @@ public class AvatarSimulationBlock { } - public int evaluateIntExpression(String _expr, Vector<String> _attributeValues) { + /*public int evaluateIntExpression(String _expr, Vector<String> _attributeValues) { String act = _expr; int cpt = 0; for (String attrValue : _attributeValues) { @@ -758,7 +758,7 @@ public class AvatarSimulationBlock { //TraceManager.addDev("Evaluating expression: " + act); return (int) (new IntExpressionEvaluator().getResultOf(act)); - } + }*/ public boolean evaluateBoolExpression(String _expr, Vector<String> _attributeValues) { String act = _expr; @@ -778,7 +778,7 @@ public class AvatarSimulationBlock { } int[] attributes = AvatarSimulationTransaction.getAttributeValues(_attributeValues); - + return aee.getResult(attributes) != 0; /*BoolExpressionEvaluator bee = new BoolExpressionEvaluator(); diff --git a/src/main/java/myutil/CSVObject.java b/src/main/java/myutil/CSVObject.java new file mode 100644 index 0000000000000000000000000000000000000000..4eb8a7c6c5d440ce1551b1047030a5b9b1040c16 --- /dev/null +++ b/src/main/java/myutil/CSVObject.java @@ -0,0 +1,151 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille 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. + */ + + + + +package myutil; + +import java.util.ArrayList; +import java.util.BitSet; + +/** + * Class CSVObject + * Creation: 16/04/2021 + * Version 2.0 16/04/2021 + * @author Ludovic APVRILLE + */ +public class CSVObject { + public ArrayList<String[]> lines; + + public CSVObject () { + } + + public CSVObject (String _toParse) { + parse(_toParse); + } + + public boolean parse(String _toParse) { + if (_toParse == null) { + return false; + } + + _toParse = _toParse.trim(); + if (_toParse.length() == 0) { + return false; + } + + String[] allLines = _toParse.split(System.getProperty("line.separator")); + + if (lines == null) { + lines = new ArrayList<>(allLines.length); + } else { + lines.clear(); + } + + + + int lineLength = 0; + for(int i=0; i<allLines.length; i++) { + String [] elt = allLines[i].split(","); + if (i == 0) { + lineLength = elt.length; + } else { + if (elt.length != lineLength) { + lines = null; + return false; + } + } + lines.add(elt); + } + + // Remove spaces + removeSpaces(); + + return true; + + } + + private void removeSpaces() { + for(String[] ss: lines) { + for(int i=0; i<ss.length; i++) { + ss[i] = ss[i].trim(); + } + } + } + + public int getNbOfLines() { + if (lines == null) { + return -1; + } + return lines.size(); + } + + public int getNbOfEltsPerLine() { + if (lines == null) { + return -1; + } + + if (lines.size() == 0) { + return -1; + } + + return lines.get(0).length; + } + + + + public String get(int line, int col) { + if (lines == null) { + return null; + } + + if (line >= lines.size()) { + return null; + } + + String[] selectedLine = lines.get(line); + if (col >= selectedLine.length) { + return null; + } + + return selectedLine[col]; + } + + +} diff --git a/src/main/java/myutil/FileUtils.java b/src/main/java/myutil/FileUtils.java index 03c7cbedc7426424b340db6e5f9b14110b4cda01..d5755bc99876ef19d2ca125dc189a66909b23724 100644 --- a/src/main/java/myutil/FileUtils.java +++ b/src/main/java/myutil/FileUtils.java @@ -65,6 +65,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils { public final static String tlsa = "tlsa"; public final static String tif = "tif"; public final static String svg = "svg"; + public final static String csv = "csv"; public static String getExtension(File f) { diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java index dd4a30eef8e29de2e6627596d18f63d0130ce5c6..b8bfbdde26397aad8b8c615caa6e5f4f7b7c9ac7 100644 --- a/src/main/java/ui/MainGUI.java +++ b/src/main/java/ui/MainGUI.java @@ -2591,6 +2591,34 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per return ret; } + public String[] loadSimulationTraceCSV() { + File file; + + /* textual form */ + CSVFileFilter filter = new CSVFileFilter(); + jfctgraph.setFileFilter(filter); + jfctgraph.setCurrentDirectory(new File(SpecConfigTTool.TGraphPath)); + + int returnVal = jfctgraph.showDialog(frame, "Load simulation trace (CSV format)"); + if (returnVal != JFileChooser.APPROVE_OPTION) { + return null; + } + + file = jfctgraph.getSelectedFile(); + file = FileUtils.addFileExtensionIfMissing(file, CSVFileFilter.getExtension()); + + String spec = loadFile(file); + if (spec == null) { + return null; + } + + String[] ret = new String[3]; + ret[0] = file.getName(); + ret[1] = file.getAbsolutePath(); + ret[2] = spec; + return ret; + } + public void loadAUTGraphsDir() { File dir = new File(SpecConfigTTool.TGraphPath); if (!dir.exists()) { @@ -4894,6 +4922,13 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per jfais.setVisible(true); } + public void setSimulationTraceSelected(SimulationTrace _st) { + JFrameAvatarInteractiveSimulation.SELECTED_SIMULATION_TRACE = _st; + if (jfais != null) { + jfais.updateSimulationTrace(); + } + } + public void avatarUPPAALVerification() { // TraceManager.addDev("Avatar uppaal fv"); boolean result = gtm.generateUPPAALFromAVATAR(SpecConfigTTool.UPPAALCodeDirectory); diff --git a/src/main/java/ui/SimulationTrace.java b/src/main/java/ui/SimulationTrace.java index f96a09b17d8982ae8313bcd28e93f8c1d3d12b5a..f0a40acc58e4827ea2b188598df768e1b6ba165f 100644 --- a/src/main/java/ui/SimulationTrace.java +++ b/src/main/java/ui/SimulationTrace.java @@ -43,6 +43,8 @@ public class SimulationTrace { private String fullPathToFile = null; private int type; + private String content; + public static final int VCD_DIPLO = 0; public static final int TXT_DIPLO = 1; public static final int HTML_DIPLO = 2; @@ -52,7 +54,9 @@ public class SimulationTrace { public static final int TXT_AVATAR = 4; public static final int SVG_AVATAR = 5; - private static String[] TYPES = {"VCD DIPLO", "TXT DIPLO", "HTML DIPLO", "PNG AVATAR", "TXT AVATAR", "SVG AVATAR","XML DIPLO"}; + public static final int CSV_AVATAR = 7; + + private static String[] TYPES = {"VCD DIPLO", "TXT DIPLO", "HTML DIPLO", "PNG AVATAR", "TXT AVATAR", "SVG AVATAR","XML DIPLO", "CSV AVATAR"}; public SimulationTrace(String name, int type) { this(name, type, null); @@ -88,6 +92,18 @@ public class SimulationTrace { return name; } + public boolean hasContent() { + return content != null; + } + + public void setContent(String _content) { + content = _content; + } + + public String getContent() { + return content; + } + public String toString() { String ret=""; ret += name + " of type " + TYPES[type]; diff --git a/src/main/java/ui/avatarinteractivesimulation/AvatarInteractiveSimulationActions.java b/src/main/java/ui/avatarinteractivesimulation/AvatarInteractiveSimulationActions.java index b2f61568aa8ef22bb99fb950ad1005d7958797b2..b915488f93a1f0941cb462cf4e9205e3ead3e3a0 100755 --- a/src/main/java/ui/avatarinteractivesimulation/AvatarInteractiveSimulationActions.java +++ b/src/main/java/ui/avatarinteractivesimulation/AvatarInteractiveSimulationActions.java @@ -66,6 +66,7 @@ public class AvatarInteractiveSimulationActions extends AbstractAction { public static final int ACT_RUN_X_TRANSACTIONS = 8; public static final int ACT_RUN_X_COMMANDS = 9; public static final int ACT_RUN_SIMU_MAX_TRANS = 38; + public static final int ACT_RUN_TRACE = 39; public static final int ACT_RUN_EXPLORATION = 20; public static final int ACT_RUN_TO_NEXT_BUS_TRANSFER = 21; @@ -107,7 +108,7 @@ public class AvatarInteractiveSimulationActions extends AbstractAction { public static final int ACT_ADD_LATENCY = 35; public static final int ACT_REMOVE_ALL_TRANS = 36; - public static final int NB_ACTION = 39; + public static final int NB_ACTION = 40; private static final TAction[] actions = new TAction[NB_ACTION]; @@ -154,6 +155,11 @@ public class AvatarInteractiveSimulationActions extends AbstractAction { actions[ACT_RUN_TO_TIME] = new TAction("run-to-time", "Run to time x", IconManager.imgic1304, IconManager.imgic1304, "Run to time x", "Run simulation until time x is reached. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_X_TRANSACTIONS] = new TAction("run-x-transactions", "Run x transactions", IconManager.imgic1306, IconManager.imgic1306, "Run x transactions", "Run simulation for x transactions. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_X_COMMANDS] = new TAction("run-x-commands", "x Step-by-Step", IconManager.imgic1330, IconManager.imgic1330, "x Step-by-Step", "Run simulation for x commands. Works only if the simulator is \"ready\"", 'R'); + + actions[ACT_RUN_TRACE] = new TAction("run-trace", "Play trace", IconManager.imgic1336, IconManager.imgic1336, "Play trace", + "Plays a formerly saved and selected simulation trace. Works only if the simulator is \"ready\"", 'R'); + + actions[ACT_REMOVE_ALL_TRANS] = new TAction("remove-all-trans","Remove all transactions",IconManager.imgic337, IconManager.imgic337,"Remove all transactions", "Remove all the transactions stored in transaction list", 'R'); actions[ACT_BACK_ONE] = new TAction("back-one", "Back one transaction", IconManager.imgic47, IconManager.imgic47, "Back one transaction", "Go one transaction backward", 'B'); diff --git a/src/main/java/ui/avatarinteractivesimulation/AvatarMainCommandsToolBar.java b/src/main/java/ui/avatarinteractivesimulation/AvatarMainCommandsToolBar.java index 68d8432827b7c5afee5bf445892866b25e14df5a..25d761e2d9f92f22786b5c18ee62c597cde378ee 100755 --- a/src/main/java/ui/avatarinteractivesimulation/AvatarMainCommandsToolBar.java +++ b/src/main/java/ui/avatarinteractivesimulation/AvatarMainCommandsToolBar.java @@ -41,6 +41,8 @@ package ui.avatarinteractivesimulation; +import ui.MainGUI; + import javax.swing.*; //import java.awt.*; @@ -76,6 +78,8 @@ public class AvatarMainCommandsToolBar extends AvatarInteractiveSimulationBar { jfais.actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(b); jfais.actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(b); jfais.actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(b); + jfais.actions[AvatarInteractiveSimulationActions.ACT_RUN_TRACE]. + setEnabled(b&&JFrameAvatarInteractiveSimulation.SELECTED_SIMULATION_TRACE != null); jfais.actions[AvatarInteractiveSimulationActions.ACT_REMOVE_ALL_TRANS].setEnabled(b); @@ -114,6 +118,13 @@ public class AvatarMainCommandsToolBar extends AvatarInteractiveSimulationBar { button = this.add(jfais.actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS]); button.addMouseListener(jfais.mouseHandler); + if (MainGUI.experimentalOn) { + this.addSeparator(); + + button = this.add(jfais.actions[AvatarInteractiveSimulationActions.ACT_RUN_TRACE]); + button.addMouseListener(jfais.mouseHandler); + } + this.addSeparator(); this.addSeparator(); diff --git a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java index 37f5eac21f246c203142a81bc884ee1526dc41e7..94f5bf2fac8b77efee2bece6880ba398e50675bc 100755 --- a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java +++ b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java @@ -73,6 +73,8 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS private static int TRACED_TRANSACTIONS = 1000; private static int LAST_TRANSACTIONS = 0; + public static SimulationTrace SELECTED_SIMULATION_TRACE; + // private static String buttonStartS = "Start simulator"; // private static String buttonStopAndCloseS = "Stop simulator and close"; @@ -105,6 +107,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS // Commands JPanel main, mainTop, commands, save, state, infos; //outputs, cpuPanel; // from MGUI + JLabel nameOfTrace; JCheckBox latex, debug, animate, diploids, hidden, update, openDiagram, animateWithInfo, executeEmptyTransition, executeStateEntering, traceInSD; JTabbedPane commandTab, infoTab; protected JTextField displayedTransactionsText, lastTransactionsText; @@ -239,6 +242,9 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS private Map<String, List<String>> transTimes = new HashMap<String, List<String>>(); //Map of each checked element: all transaction times private JScrollPane jspLatency; + // Trace playing + private SimulationTrace selectedTrace; + public JFrameAvatarInteractiveSimulation(/*Frame _f,*/ MainGUI _mgui, String _title, AvatarSpecification _avspec) { super(_title); @@ -501,6 +507,13 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS c01.gridwidth = GridBagConstraints.REMAINDER; //end row paramMainCommand = new JTextField("1", 30); jp02.add(paramMainCommand, c01); + + c01.gridwidth = 1; + jp02.add(new JLabel("Selected trace: "), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + nameOfTrace = new JLabel(); + jp02.add(nameOfTrace, c01); + // list of pending transactions JPanel panellpt = new JPanel(); panellpt.setLayout(new BorderLayout()); @@ -513,6 +526,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS JScrollPane scrollPane1 = new JScrollPane(listPendingTransactions); scrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); panellpt.add(scrollPane1); + c01.gridheight = 10; jp02.add(panellpt, c01); jp01.add(jp02, BorderLayout.CENTER); @@ -1147,6 +1161,27 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS } } + + public void runTrace() { + if (SELECTED_SIMULATION_TRACE == null) { + return; + } + + if (!SELECTED_SIMULATION_TRACE.hasContent()) { + return; + } + + selectedTrace = SELECTED_SIMULATION_TRACE; + + // Transform String into a CSV object + + + + + + // Implement CSV object running; + } + public void stopSimulation() { //previousTime = System.currentTimeMillis(); if (ass != null) { @@ -1243,7 +1278,21 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS } } + private void setTraceName() { + if (SELECTED_SIMULATION_TRACE.hasContent()) { + nameOfTrace.setText(SELECTED_SIMULATION_TRACE.getName()); + } else { + nameOfTrace.setText("No selected trace"); + } + } + + public void updateSimulationTrace() { + setTraceName(); + setAll(); + } + public void setAll() { + boolean b = true; switch (busyMode) { @@ -1252,6 +1301,8 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS actions[AvatarInteractiveSimulationActions.ACT_RUN_SIMU_MAX_TRANS].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_BACK_ONE].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(true); + actions[AvatarInteractiveSimulationActions.ACT_RUN_TRACE].setEnabled( + JFrameAvatarInteractiveSimulation.SELECTED_SIMULATION_TRACE != null); actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_REMOVE_ALL_TRANS].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(false); @@ -1264,6 +1315,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS actions[AvatarInteractiveSimulationActions.ACT_RUN_SIMU_MAX_TRANS].setEnabled(false); actions[AvatarInteractiveSimulationActions.ACT_BACK_ONE].setEnabled(false); actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(false); + actions[AvatarInteractiveSimulationActions.ACT_RUN_TRACE].setEnabled(false); actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(false); actions[AvatarInteractiveSimulationActions.ACT_REMOVE_ALL_TRANS].setEnabled(false); actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(true); @@ -1274,6 +1326,8 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS actions[AvatarInteractiveSimulationActions.ACT_RUN_SIMU_MAX_TRANS].setEnabled(false); actions[AvatarInteractiveSimulationActions.ACT_BACK_ONE].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(false); + actions[AvatarInteractiveSimulationActions.ACT_RUN_TRACE].setEnabled( + JFrameAvatarInteractiveSimulation.SELECTED_SIMULATION_TRACE != null); actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_REMOVE_ALL_TRANS].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(false); @@ -1286,6 +1340,8 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS actions[AvatarInteractiveSimulationActions.ACT_RUN_SIMU_MAX_TRANS].setEnabled(false); actions[AvatarInteractiveSimulationActions.ACT_BACK_ONE].setEnabled(false); actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(false); + actions[AvatarInteractiveSimulationActions.ACT_RUN_TRACE].setEnabled( + JFrameAvatarInteractiveSimulation.SELECTED_SIMULATION_TRACE != null); actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_REMOVE_ALL_TRANS].setEnabled(true); actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(false); @@ -1801,8 +1857,8 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS fileName += "simulationtrace_fromttool.txt"; } - if (ConfigurationTTool.isConfigured(ConfigurationTTool.IMGPath)) { - fileName = ConfigurationTTool.IMGPath + System.getProperty("file.separator") + fileName; + if (ConfigurationTTool.isConfigured(ConfigurationTTool.TGraphPath)) { + fileName = ConfigurationTTool.TGraphPath + System.getProperty("file.separator") + fileName; } else { // Using model directory String path = mgui.getModelFileFullPath(); @@ -1862,8 +1918,8 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS fileName += "simulationtrace_fromttool.csv"; } - if (ConfigurationTTool.isConfigured(ConfigurationTTool.IMGPath)) { - fileName = ConfigurationTTool.IMGPath + System.getProperty("file.separator") + fileName; + if (ConfigurationTTool.isConfigured(ConfigurationTTool.TGraphPath)) { + fileName = ConfigurationTTool.TGraphPath + System.getProperty("file.separator") + fileName; } else { // Using model directory String path = mgui.getModelFileFullPath(); @@ -1901,15 +1957,12 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS return; } - /*JOptionPane.showMessageDialog(this, - "Simulation trace was saved in " + fileName, - "Error", - JOptionPane.INFORMATION_MESSAGE);*/ + String shortFileName; File f = new File(fileName); shortFileName = f.getName(); - SimulationTrace st = new SimulationTrace(shortFileName, SimulationTrace.TXT_AVATAR, fileName); + SimulationTrace st = new SimulationTrace(shortFileName, SimulationTrace.CSV_AVATAR, fileName); mgui.addSimulationTrace(st); //ass.printExecutedTransactions(); @@ -2174,6 +2227,9 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS } else if (command.equals(actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].getActionCommand())) { runXCommands(); + } else if (command.equals(actions[AvatarInteractiveSimulationActions.ACT_RUN_TRACE].getActionCommand())) { + runTrace(); + } else if (command.equals(actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].getActionCommand())) { stopSimulation(); diff --git a/src/main/java/ui/file/CSVFileFilter.java b/src/main/java/ui/file/CSVFileFilter.java new file mode 100755 index 0000000000000000000000000000000000000000..04fc76570c5c132a88688844c12bebda21c78707 --- /dev/null +++ b/src/main/java/ui/file/CSVFileFilter.java @@ -0,0 +1,87 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille 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. + */ + + + + +package ui.file; + +import myutil.FileUtils; + +import javax.swing.filechooser.FileFilter; +import java.io.File; + + +/** + * Class CSVFileFilter + * Creation : 16/04/2021 + * @author Ludovic APVRILLE + */ +public class CSVFileFilter extends FileFilter { + +//Accept all directories and xml files + public boolean accept(File f) { + if (f.isDirectory()) { + return true; + } + + String extension = FileUtils.getExtension(f); + if (extension != null) { + return extension.equals(FileUtils.csv); + } + + return false; + } + + public String getDescription() { + return "CSV"; + } + + public static String getExtension() { + return FileUtils.csv; + } + + +} + + + + + + + diff --git a/src/main/java/ui/tree/JDiagramTree.java b/src/main/java/ui/tree/JDiagramTree.java index c259c1218acb4f40af28e6de8153c7f6b0198278..cf77e9323770fd13e669a6e8c92bc030acd8969a 100755 --- a/src/main/java/ui/tree/JDiagramTree.java +++ b/src/main/java/ui/tree/JDiagramTree.java @@ -49,6 +49,8 @@ import tmltranslator.TMLCheckingError; import ui.*; import graph.RG; import myutil.*; +import ui.avatarinteractivesimulation.JFrameAvatarInteractiveSimulation; +import ui.interactivesimulation.JFrameInteractiveSimulation; import ui.window.JFrameHelp; import javax.swing.*; @@ -99,6 +101,7 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M protected JMenuItem jmiRefusalGraph; protected JMenuItem jmiRemove; protected JMenuItem jmiShowInFinder; + protected JMenuItem jmiSelectInSimulator; protected JMenuItem jmiShowST; protected JMenuItem jmiShowInFinderST; protected JMenuItem jmiCompareST; @@ -111,8 +114,10 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M protected JPopupMenu popupGraphTree; protected JPopupMenu popupSimulationTraceTree; + protected JMenuItem jmiAddSimTraceFromFile; protected JMenuItem jmiAddFromFile; protected GraphTree selectedGT; + protected SimulationTraceTree selectedSTT; /* @@ -205,6 +210,17 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M //TraceManager.addDev("Adding popup menu to " + obj.getClass() + "/" + obj); + if (obj instanceof SimulationTraceTree) { + selectedSTT = (SimulationTraceTree) obj; + if (popupSimulationTraceTree == null) { + popupSimulationTraceTree = new JPopupMenu(); + jmiAddSimTraceFromFile = new JMenuItem("Add simulation trace from file (.csv)"); + jmiAddSimTraceFromFile.addActionListener(this); + popupSimulationTraceTree.add(jmiAddSimTraceFromFile); + } + popupSimulationTraceTree.show(tree, x, y); + } + if (obj instanceof GraphTree) { selectedGT = (GraphTree) obj; if (popupGraphTree == null) { @@ -259,12 +275,19 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M } jmiShowST.addActionListener(this); popupTreeST.add(jmiShowST); - if(selectedST.hasFile()) { + if (selectedST.hasFile()) { jmiShowInFinderST = new JMenuItem("Show in File Explorer"); jmiShowInFinderST.addActionListener(this); } + if (selectedST.hasContent() && selectedST.getType() == SimulationTrace.CSV_AVATAR) { + jmiSelectInSimulator = new JMenuItem("Select in simulator"); + jmiSelectInSimulator.addActionListener(this); + } popupTreeST.add(jmiShowInFinderST); + if (jmiSelectInSimulator != null) { + popupTreeST.add(jmiSelectInSimulator); + } if (selectedST.getType() == SimulationTrace.XML_DIPLO) { @@ -527,39 +550,43 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M if (selectedST != null) { if (ae.getSource() == jmiShowST) { showSimulationTrace(); + } else if (ae.getSource() == jmiShowInFinderST) { mgui.showInFinder(selectedST, true); - } - else if (ae.getSource() == jmiCompareST) { + + } else if (ae.getSource() == jmiSelectInSimulator) { + mgui.setSimulationTraceSelected(selectedST); + + } else if (ae.getSource() == jmiCompareST) { mgui.compareSimulationTraces(selectedST, true); - } - else if (ae.getSource() == jmiLatencyAnalysisST) { + } else if (ae.getSource() == jmiLatencyAnalysisST) { try { mgui.latencyDetailedAnalysisForXML(selectedST, true , false,1); - } catch (XPathExpressionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SAXException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (Exception e) { + TraceManager.addDev("Error in latency analysis: " + e.getMessage()); } - } else if (ae.getSource() == jmiCompareLatencyAnalysisST) { - + } else if (ae.getSource() == jmiCompareLatencyAnalysisST) { mgui.compareLatencyForXML(selectedST, false); - - } } + if (selectedSTT != null) { + if (ae.getSource() == jmiAddSimTraceFromFile) { + + //TraceManager.addDev("Adding simulation trace from file"); + String[] st = mgui.loadSimulationTraceCSV(); + if (st != null) { + SimulationTrace sim = new SimulationTrace(st[0], SimulationTrace.CSV_AVATAR, st[1]); + sim.setContent(st[2]); + mgui.addSimulationTrace(sim); + } + + } + } + if (selectedGT != null) { if (ae.getSource() == jmiAddFromFile) { diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index 0f02644afadcfd8c84e5ef3721e4f45628640e74..56087bede61d0278e68b891545c5fc749f2162dd 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -137,7 +137,7 @@ public class IconManager { public static ImageIcon imgic1300, imgic1302, imgic1304, imgic1306, imgic1308; public static ImageIcon imgic1310, imgic1312, imgic1314, imgic1316, imgic1318; public static ImageIcon imgic1320, imgic1322, imgic1324, imgic1326, imgic1328; - public static ImageIcon imgic1330, imgic1332, imgic1334; + public static ImageIcon imgic1330, imgic1332, imgic1334, imgic1336; // SMD diagram @@ -579,6 +579,7 @@ public class IconManager { private static String icon1330 = "stepforwardx24.gif"; private static String icon1332 = "savexml24.gif"; private static String icon1334 = "savecsv24.gif"; + private static String icon1336 = "steptrace24.gif"; // SMD diagrams private static String icon2000 = "prosmdsendmsg.gif"; @@ -1121,6 +1122,7 @@ public class IconManager { imgic1330 = getIcon(icon1330); imgic1332 = getIcon(icon1332); imgic1334 = getIcon(icon1334); + imgic1336 = getIcon(icon1336); imgic2000 = getIcon(icon2000); imgic2002 = getIcon(icon2002); diff --git a/src/main/resources/ui/util/steptrace24.gif b/src/main/resources/ui/util/steptrace24.gif new file mode 100755 index 0000000000000000000000000000000000000000..21cbaf02851cb9741e3061f66420471f736e2d1c Binary files /dev/null and b/src/main/resources/ui/util/steptrace24.gif differ diff --git a/ttool/src/test/java/myutil/CSVObjectTest.java b/ttool/src/test/java/myutil/CSVObjectTest.java new file mode 100755 index 0000000000000000000000000000000000000000..43c75b7625fc1ac3454d87503faa72243ce649c0 --- /dev/null +++ b/ttool/src/test/java/myutil/CSVObjectTest.java @@ -0,0 +1,80 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + + ludovic.apvrille 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. +*/ +package myutil; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CSVObjectTest { + private static String GOOD_CSV = "student, teacher, class\nfoo, too, uml\nfii, tii, os and uml "; + private static String BAD_CSV_1 = "student, teacher, class\nfoo, too\nfii, tii, os"; + private static String BAD_CSV_2 = "student, teacher, class\nfoo, too, uml, os\nfii, tii, os"; + + @Test + public void parsingTest() { + + CSVObject csv = new CSVObject(); + + assertFalse(csv.parse(null)); + assertFalse(csv.parse("")); + assertFalse(csv.parse(" ")); + + assertFalse(csv.parse(BAD_CSV_1)); + assertFalse(csv.parse(BAD_CSV_2)); + + assertTrue(csv.parse(GOOD_CSV)); + + assertEquals(csv.getNbOfLines(), 3); + assertEquals(csv.getNbOfEltsPerLine(), 3); + + assertEquals(csv.get(0, 0), "student"); + assertEquals(csv.get(0, 1), "teacher"); + assertEquals(csv.get(0, 2), "class"); + assertEquals(csv.get(1, 0), "foo"); + assertEquals(csv.get(1, 1), "too"); + assertEquals(csv.get(1, 2), "uml"); + assertEquals(csv.get(2, 0), "fii"); + assertEquals(csv.get(2, 1), "tii"); + assertEquals(csv.get(2, 2), "os and uml"); + + + } + + +}