diff --git a/src/main/java/avatartranslator/toexecutable/AVATAR2CPOSIX.java b/src/main/java/avatartranslator/toexecutable/AVATAR2CPOSIX.java index a3c99b3f09cc88809c7b26b49850f5d328106748..ea519876e5f2815276b6e185d9262febd2ba4762 100755 --- a/src/main/java/avatartranslator/toexecutable/AVATAR2CPOSIX.java +++ b/src/main/java/avatartranslator/toexecutable/AVATAR2CPOSIX.java @@ -104,7 +104,12 @@ public class AVATAR2CPOSIX { public void saveInFiles(String path) throws FileException { TraceManager.addDev("Generating files"); - + if (!FileUtils.checkAndCreateAVATARCodeDir(path)) + throw new FileException("ERROR: Executable code directory cannot be created."); + File src_dir = new File(path + GENERATED_PATH); + if (!src_dir.exists()) { + src_dir.mkdir(); + } if (mainFile != null) { TraceManager.addDev("Generating main files in " + path + mainFile.getName() + ".h"); FileUtils.saveFile(path + GENERATED_PATH + mainFile.getName() + ".h", Conversion.indentString(mainFile.getHeaderCode(), 2)); diff --git a/src/main/java/avatartranslator/touppaal/AVATAR2UPPAAL.java b/src/main/java/avatartranslator/touppaal/AVATAR2UPPAAL.java index 550c946dfcb012fec2b3e9ae53efa0715c7011cf..e5b05fb9c57d373d86be5defef10d9586d06f93e 100755 --- a/src/main/java/avatartranslator/touppaal/AVATAR2UPPAAL.java +++ b/src/main/java/avatartranslator/touppaal/AVATAR2UPPAAL.java @@ -144,6 +144,7 @@ public class AVATAR2UPPAAL { public void saveInFile(String path) throws FileException { + FileUtils.checkAndCreateUPPAALDir(path); FileUtils.saveFile(path + "spec.xml", spec.makeSpec()); //System.out.println("spec.xml generated:\n" + spec.getFullSpec()); } diff --git a/src/main/java/common/ConfigurationTTool.java b/src/main/java/common/ConfigurationTTool.java index b53531d257c1aba657d5dc296560d17b70bf6362..2d49da6f06c588387b4a65a9dfaf07e9c21f1524 100755 --- a/src/main/java/common/ConfigurationTTool.java +++ b/src/main/java/common/ConfigurationTTool.java @@ -198,6 +198,7 @@ public class ConfigurationTTool { } loadConfigurationFromXML(data, systemcOn); + SpecConfigTTool.loadConfiguration(); } public static void saveConfiguration() throws MalformedConfigurationException { diff --git a/src/main/java/common/SpecConfigTTool.java b/src/main/java/common/SpecConfigTTool.java new file mode 100644 index 0000000000000000000000000000000000000000..1b0e619a3b5b6f2a834e979d6ac3b7d30a3f8d5b --- /dev/null +++ b/src/main/java/common/SpecConfigTTool.java @@ -0,0 +1,310 @@ +package common; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import myutil.FileUtils; +import myutil.MalformedConfigurationException; +import myutil.TraceManager; + +/** + * Specific configuration for ttool project + * Creation: 13/10/2017 + * @version 1.0 + * @author Fabien Tessier + * + */ +public class SpecConfigTTool { + public static String SystemCCodeDirectory=""; + public static String SystemCCodeCompileCommand=""; + public static String SystemCCodeExecuteCommand=""; + public static String SystemCCodeInteractiveExecuteCommand=""; + + public static String CCodeDirectory=""; + + public static String ProVerifCodeDirectory=""; + + public static String AVATARExecutableCodeDirectory=""; + public static String AVATARExecutableCodeCompileCommand=""; + public static String AVATARExecutableCodeExecuteCommand=""; + + public static String AVATARMPSoCCodeDirectory=""; + public static String AVATARMPSoCCompileCommand=""; + public static String AVATARExecutableSoclibCodeCompileCommand=""; + public static String AVATARExecutableSoclibCodeExecuteCommand=""; + public static String AVATARExecutableSoclibCodeTraceCommand=""; + + public static String TMLCodeDirectory=""; + + public static String IMGPath=""; + + public static String DocGenPath=""; + + public static String GGraphPath=""; + public static String TGraphPath=""; + + public static String UPPAALCodeDirectory=""; + + public static String VCDPath=""; + public static String ExternalCommand1=""; + + public static String NCDirectory=""; + + private static String ProjectSystemCCodeDirectory = "/c++_code/"; + private static String ProjectCCodeDirectory = "/c_code/"; + private static String ProjectProVerifCodeDirectory = "/proverif/"; + private static String ProjectAVATARExecutableCodeDirectory = "/AVATAR_executablecode/"; + private static String ProjectAVATARMPSoCCodeDirectory = "/MPSoC/"; + private static String ProjectTMLCodeDirectory = "/tmlcode/"; + private static String ProjectIMGDirectory = "/figures"; + private static String ProjectDocGenDirectory = "/doc"; + private static String ProjectGGraphDirectory="/graphs"; + private static String ProjectTGraphDirectory="/graphs"; + private static String ProjectUPPAALCodeDirectory="/uppaal/"; + private static String ProjectVCDDirectory="/c++_code/"; + private static String ProjectNCDirectory="/nc/"; + + public static int lastPanel = -1; + public static int lastTab = -1; + public static String lastVCD=""; + + private static String basicConfigPath=""; + + public static void loadConfiguration() { + SystemCCodeDirectory = ConfigurationTTool.SystemCCodeDirectory; + SystemCCodeCompileCommand = ConfigurationTTool.SystemCCodeCompileCommand; + SystemCCodeExecuteCommand = ConfigurationTTool.SystemCCodeExecuteCommand; + SystemCCodeInteractiveExecuteCommand = ConfigurationTTool.SystemCCodeInteractiveExecuteCommand; + + CCodeDirectory = ConfigurationTTool.CCodeDirectory; + + ProVerifCodeDirectory = ConfigurationTTool.ProVerifCodeDirectory; + + AVATARExecutableCodeDirectory = ConfigurationTTool.AVATARExecutableCodeDirectory; + AVATARExecutableCodeCompileCommand = ConfigurationTTool.AVATARExecutableCodeCompileCommand; + AVATARExecutableCodeExecuteCommand = ConfigurationTTool.AVATARExecutableCodeExecuteCommand; + + AVATARMPSoCCodeDirectory = ConfigurationTTool.AVATARMPSoCCodeDirectory; + AVATARMPSoCCompileCommand = ConfigurationTTool.AVATARMPSoCCompileCommand; + AVATARExecutableSoclibCodeCompileCommand = ConfigurationTTool.AVATARExecutableSoclibCodeCompileCommand; + AVATARExecutableSoclibCodeExecuteCommand = ConfigurationTTool.AVATARExecutableSoclibCodeExecuteCommand; + AVATARExecutableSoclibCodeTraceCommand = ConfigurationTTool.AVATARExecutableSoclibCodeTraceCommand; + + TMLCodeDirectory = ConfigurationTTool.TMLCodeDirectory; + + IMGPath = ConfigurationTTool.IMGPath; + + DocGenPath = ConfigurationTTool.DocGenPath; + + GGraphPath = ConfigurationTTool.GGraphPath; + TGraphPath = ConfigurationTTool.TGraphPath; + + UPPAALCodeDirectory = ConfigurationTTool.UPPAALCodeDirectory; + + VCDPath = ConfigurationTTool.VCDPath; + ExternalCommand1 = ConfigurationTTool.ExternalCommand1; + + NCDirectory = ConfigurationTTool.NCDirectory; + } + + public static void setDirConfig(File dir) { + SystemCCodeDirectory = dir.getAbsolutePath() + ProjectSystemCCodeDirectory; + CCodeDirectory = dir.getAbsolutePath() + ProjectCCodeDirectory; + ProVerifCodeDirectory = dir.getAbsolutePath() + ProjectProVerifCodeDirectory; + AVATARExecutableCodeDirectory = dir.getAbsolutePath() + ProjectAVATARExecutableCodeDirectory; + AVATARMPSoCCodeDirectory = dir.getAbsolutePath() + ProjectAVATARMPSoCCodeDirectory; + TMLCodeDirectory = dir.getAbsolutePath() + ProjectTMLCodeDirectory; + IMGPath = dir.getAbsolutePath() + ProjectIMGDirectory; + DocGenPath = dir.getAbsolutePath() + ProjectDocGenDirectory; + GGraphPath = dir.getAbsolutePath() + ProjectGGraphDirectory; + TGraphPath = dir.getAbsolutePath() + ProjectTGraphDirectory; + UPPAALCodeDirectory = dir.getAbsolutePath() + ProjectUPPAALCodeDirectory; + VCDPath = dir.getAbsolutePath() + ProjectVCDDirectory; + NCDirectory = dir.getAbsolutePath() + ProjectNCDirectory; + + SystemCCodeCompileCommand = ConfigurationTTool.SystemCCodeCompileCommand.replace(ConfigurationTTool.SystemCCodeDirectory, SystemCCodeDirectory); + SystemCCodeExecuteCommand = ConfigurationTTool.SystemCCodeExecuteCommand.replace(ConfigurationTTool.SystemCCodeDirectory, SystemCCodeDirectory); + SystemCCodeInteractiveExecuteCommand = ConfigurationTTool.SystemCCodeInteractiveExecuteCommand.replace(ConfigurationTTool.SystemCCodeDirectory, SystemCCodeDirectory); + + AVATARExecutableCodeExecuteCommand = ConfigurationTTool.AVATARExecutableCodeExecuteCommand.replace(ConfigurationTTool.AVATARExecutableCodeDirectory, AVATARExecutableCodeDirectory); + AVATARExecutableCodeCompileCommand = ConfigurationTTool.AVATARExecutableCodeCompileCommand.replace(ConfigurationTTool.AVATARExecutableCodeDirectory, AVATARExecutableCodeDirectory); + + AVATARMPSoCCompileCommand = ConfigurationTTool.AVATARMPSoCCompileCommand.replace(ConfigurationTTool.AVATARMPSoCCodeDirectory, AVATARMPSoCCompileCommand); + AVATARExecutableSoclibCodeCompileCommand = ConfigurationTTool.AVATARExecutableSoclibCodeCompileCommand.replace(ConfigurationTTool.AVATARMPSoCCodeDirectory, AVATARMPSoCCompileCommand); + AVATARExecutableSoclibCodeExecuteCommand = ConfigurationTTool.AVATARExecutableSoclibCodeExecuteCommand.replace(ConfigurationTTool.AVATARMPSoCCodeDirectory, AVATARMPSoCCompileCommand); + AVATARExecutableSoclibCodeTraceCommand = ConfigurationTTool.AVATARExecutableSoclibCodeTraceCommand.replace(ConfigurationTTool.AVATARMPSoCCodeDirectory, AVATARMPSoCCompileCommand); + ExternalCommand1 = ConfigurationTTool.ExternalCommand1.replace(ConfigurationTTool.VCDPath, SpecConfigTTool.VCDPath); + } + + public static void setBasicConfig(boolean systemcOn) { + try { + ConfigurationTTool.loadConfiguration(basicConfigPath, systemcOn); + } catch (MalformedConfigurationException e) { + System.out.println("Couldn't load configuration from file: config.xml"); + } + } + + public static File createProjectConfig(File dir) { + File figures = new File(IMGPath); + figures.mkdir(); + + File GGraph = new File(GGraphPath); + GGraph.mkdir(); + + if (!GGraphPath.equals(TGraphPath)) { + File TGraph = new File(TGraphPath); + TGraph.mkdir(); + } + + File test = new File ("./"); + File base; + if (test.getAbsolutePath().contains("TTool/bin/")) + base = new File("../ttool/project_config.xml"); + else + base = new File("./project_config.xml"); + try { + FileUtils.copyFileToDirectory(base, dir, false); + return new File(dir + File.separator + "project_config.xml"); + } catch (IOException e) { + System.err.println(e.getMessage()); + } + return null; + } + + public static void loadConfigFile(File f) throws MalformedConfigurationException { + if (!FileUtils.checkFileForOpen(f)) { + throw new MalformedConfigurationException("Filepb"); + } + + String data = FileUtils.loadFileData(f); + + if (data == null) { + throw new MalformedConfigurationException("Filepb"); + } + + loadConfigurationFromXML(data); + } + + public static void loadConfigurationFromXML(String data) throws MalformedConfigurationException { + + try { + ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes()); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + // building nodes from xml String + Document doc = db.parse(bais); + NodeList nl; + + nl = doc.getElementsByTagName("LastVCD"); + if (nl.getLength() > 0) + LastVCD(nl); + + nl = doc.getElementsByTagName("LastOpenDiagram"); + if (nl.getLength() > 0) + LastOpenDiagram(nl); + + } catch (Exception e) { + throw new MalformedConfigurationException(e.getMessage()); + } + } + + private static void LastOpenDiagram(NodeList nl) throws MalformedConfigurationException { + try { + Element elt = (Element)(nl.item(0)); + lastTab = Integer.parseInt(elt.getAttribute("tab")); + lastPanel = Integer.parseInt(elt.getAttribute("panel")); + } catch (Exception e) { + throw new MalformedConfigurationException(e.getMessage()); + } + } + + private static void LastVCD(NodeList nl) throws MalformedConfigurationException { + try { + Element elt = (Element)(nl.item(0)); + lastVCD = elt.getAttribute("data"); + ExternalCommand1 = "gtkwave " + lastVCD; + } catch (Exception e) { + throw new MalformedConfigurationException(e.getMessage()); + } + } + + public static void saveConfiguration(File f) throws MalformedConfigurationException { + int index0, index1, index2; + String tmp, tmp1, tmp2, location; + boolean write = false; + + if (!FileUtils.checkFileForOpen(f)) { + throw new MalformedConfigurationException("Filepb"); + } + + String data = FileUtils.loadFileData(f); + + if (data == null) { + throw new MalformedConfigurationException("Filepb"); + } + + index0 = data.indexOf("LastVCD"); + + if (index0 > -1) { + index1 = data.indexOf('"', index0); + if (index1 > -1) { + index2 = data.indexOf('"', index1 + 1); + if (index2 > -1) { + tmp = data.substring(index2, data.length()); + data = data.substring(0, index1+1) + lastVCD + tmp; + write = true; + } + } + } + + index0 = data.indexOf("LastOpenDiagram"); + + if (index0 > -1) { + tmp1 = data.substring(0, index0+16); + tmp2 = data.substring(index0+20, data.length()); + index1 = tmp2.indexOf("/>"); + if (index1 > -1) { + tmp2 = tmp2.substring(index1, tmp2.length()); + location = " tab=\"" + lastTab; + location += "\" panel=\"" + lastPanel + "\" "; + data = tmp1 + location + tmp2; + write = true; + } + } else { + index1= data.indexOf("</PROJECTCONFIGURATION>"); + if (index1 > -1) { + location = "<LastOpenDiagram tab=\"" + lastTab; + location += "\" panel=\"" + lastPanel + "\"/>\n\n"; + data = data.substring(0, index1) + location + data.substring(index1, data.length()); + write = true; + } + } + + if (write) { + //sb.append("Writing data=" + data); + try { + FileOutputStream fos = new FileOutputStream(f); + fos.write(data.getBytes()); + fos.close(); + } catch (Exception e) { + throw new MalformedConfigurationException("Saving file failed"); + } + } else { + TraceManager.addError("Configuration could not be saved"); + } + } + + public static void setBasicConfigFile(String file) { + basicConfigPath = file; + } +} diff --git a/src/main/java/myutil/FileUtils.java b/src/main/java/myutil/FileUtils.java index d00e1be406bbeb8744d44d9964ec4aeed37ac325..5a120b797c69a67eeb0dac1cee9ff94167c44e9b 100755 --- a/src/main/java/myutil/FileUtils.java +++ b/src/main/java/myutil/FileUtils.java @@ -45,6 +45,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FilenameFilter; +import java.io.IOException; + +import common.ConfigurationTTool; /** @@ -53,7 +56,7 @@ import java.io.FilenameFilter; * @version 1.1 01/12/2003 * @author Ludovic APVRILLE */ -public class FileUtils { +public class FileUtils extends org.apache.commons.io.FileUtils{ public final static String xml = "xml"; public final static String rtl = "lot"; @@ -72,7 +75,7 @@ public class FileUtils { public static String getExtension(File f) { - String ext = null; + String ext = ""; String s = f.getName(); int i = s.lastIndexOf('.'); @@ -87,6 +90,152 @@ public class FileUtils { return new File(path).isDirectory(); } + /** + * Check and create the directory for c++ code generation in DIPLODOCUS + * @author Fabien Tessier + * @param s directory path + * @return true if there's no error, false if the directory cannot be created + * @throws FileException + */ + public static boolean checkAndCreateSystemCDir(String s) throws FileException { + File f = new File(s); + try { + if (!f.exists()) + if(!f.mkdir()) + return false; + if (!s.equals(ConfigurationTTool.SystemCCodeDirectory)) { + File make = new File(ConfigurationTTool.SystemCCodeDirectory + "Makefile"); + File defs = new File(ConfigurationTTool.SystemCCodeDirectory + "Makefile.defs"); + File src = new File(ConfigurationTTool.SystemCCodeDirectory + "src_simulator"); + File lic = new File(ConfigurationTTool.SystemCCodeDirectory + "LICENSE"); + File liceng = new File(ConfigurationTTool.SystemCCodeDirectory + "LICENSE_CECILL_ENG"); + File licfr = new File(ConfigurationTTool.SystemCCodeDirectory + "LICENSE_CECILL_FR"); + + FileUtils.copyFileToDirectory(make, f, false); + FileUtils.copyFileToDirectory(defs, f, false); + FileUtils.copyDirectoryToDirectory(src, f); + FileUtils.copyFileToDirectory(lic, f, false); + FileUtils.copyFileToDirectory(liceng, f, false); + FileUtils.copyFileToDirectory(licfr, f, false); + } + return true; + } catch (Exception e) { + throw new FileException(e.getMessage()); + } + } + + /** + * Check and create the directory for c code generation in AVATAR + * @author Fabien Tessier + * @param s directory path + * @return true if there's no error, false if the directory cannot be created + * @throws FileException + */ + public static boolean checkAndCreateAVATARCodeDir(String s) throws FileException { + File f = new File(s); + try { + if (!f.exists()) + if(!f.mkdir()) + return false; + if (!s.equals(ConfigurationTTool.AVATARExecutableCodeDirectory)) { + File make = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "Makefile"); + File defs = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "Makefile.defs"); + File soclib = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "Makefile.forsoclib"); + File src = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "src"); + File lic = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "LICENSE"); + File liceng = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "LICENSE_CECILL_ENG"); + File licfr = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "LICENSE_CECILL_FR"); + //File topcell = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "generated_topcell"); + + FileUtils.copyFileToDirectory(make, f, false); + FileUtils.copyFileToDirectory(defs, f,false); + FileUtils.copyFileToDirectory(soclib, f, false); + FileUtils.copyDirectoryToDirectory(src, f); + FileUtils.copyFileToDirectory(lic, f, false); + FileUtils.copyFileToDirectory(liceng, f, false); + FileUtils.copyFileToDirectory(licfr, f, false); + //FileUtils.copyDirectoryToDirectory(topcell, f); + } + return true; + } + catch (IOException e) { + throw new FileException(e.getMessage()); + } + + } + + public static boolean checkAndCreateProverifDir(String s) throws FileException { + File f = new File(s); + try { + if (!f.exists()) + if(!f.mkdir()) + return false; + if (!s.equals(ConfigurationTTool.ProVerifCodeDirectory)) { + File readme = new File(ConfigurationTTool.ProVerifCodeDirectory + "README"); + if (readme.exists()) + FileUtils.copyFileToDirectory(readme, f, false); + } + return true; + } + catch (IOException e) { + throw new FileException(e.getMessage()); + } + } + + public static boolean checkAndCreateTMLDir(String s) throws FileException { + File f = new File(s); + try { + if (!f.exists()) + if(!f.mkdir()) + return false; + if (!s.equals(ConfigurationTTool.TMLCodeDirectory)) { + File readme = new File(ConfigurationTTool.TMLCodeDirectory + "README_TML"); + if (readme.exists()) + FileUtils.copyFileToDirectory(readme, f, false); + } + return true; + } + catch (IOException e) { + throw new FileException(e.getMessage()); + } + } + + public static boolean checkAndCreateCCodeDir(String s) throws FileException { + File f = new File(s); + try { + if (!f.exists()) + if(!f.mkdir()) + return false; + if (!s.equals(ConfigurationTTool.CCodeDirectory)) { + File readme = new File(ConfigurationTTool.CCodeDirectory + "README"); + if (readme.exists()) + FileUtils.copyFileToDirectory(readme, f, false); + } + return true; + } + catch (IOException e) { + throw new FileException(e.getMessage()); + } + } + + public static boolean checkAndCreateUPPAALDir(String s) throws FileException { + File f = new File(s); + try { + if (!f.exists()) + if(!f.mkdir()) + return false; + if (!s.equals(ConfigurationTTool.UPPAALCodeDirectory)) { + File readme = new File(ConfigurationTTool.UPPAALCodeDirectory + "README"); + if (readme.exists()) + FileUtils.copyFileToDirectory(readme, f, false); + } + return true; + } + catch (IOException e) { + throw new FileException(e.getMessage()); + } + } + public static boolean checkFileForSave(File file) throws FileException { // boolean ok = true; // String pb = ""; diff --git a/src/main/java/tmltranslator/TMLCPTextSpecification.java b/src/main/java/tmltranslator/TMLCPTextSpecification.java index f3a4a4493a58f53704e86bc56ba0a94038193669..9ee601411eb55246315ec21726664f8a84b69482 100755 --- a/src/main/java/tmltranslator/TMLCPTextSpecification.java +++ b/src/main/java/tmltranslator/TMLCPTextSpecification.java @@ -48,6 +48,7 @@ import myutil.FileUtils; import myutil.TraceManager; import tmltranslator.tmlcp.*; +import java.io.File; import java.util.*; /** @@ -137,6 +138,9 @@ public class TMLCPTextSpecification { // } public void saveFile(String path, String filename) throws FileException { + File dir = new File(path); + if (!dir.exists()) + dir.mkdir(); TraceManager.addUser("Saving TMLCP spec file in " + path + filename); FileUtils.saveFile(path + filename, spec); } diff --git a/src/main/java/tmltranslator/TMLMappingTextSpecification.java b/src/main/java/tmltranslator/TMLMappingTextSpecification.java index 283e9492d320b5e3e459b6cc633c3bcbeca41fa1..8a3db1c5b61ed256fb7a931cb5e53ac59eab7739 100755 --- a/src/main/java/tmltranslator/TMLMappingTextSpecification.java +++ b/src/main/java/tmltranslator/TMLMappingTextSpecification.java @@ -48,6 +48,7 @@ import myutil.FileUtils; import myutil.TraceManager; import java.io.BufferedReader; +import java.io.File; import java.io.StringReader; import java.util.ArrayList; import java.util.List; @@ -87,6 +88,10 @@ public class TMLMappingTextSpecification<E> { public void saveFile(String path, String filename) throws FileException { + File dir = new File(path); + if (!dir.exists()) + dir.mkdir(); + if (tmlmtxt != null) { tmlmtxt.saveFile(path, filename + ".tml"); } diff --git a/src/main/java/tmltranslator/TMLTextSpecification.java b/src/main/java/tmltranslator/TMLTextSpecification.java index c4f2af038496fc6eed003fa8cc36964c9d8db3e0..175c4fb58a61e90d8dc62f6077f4d1963cceb86c 100755 --- a/src/main/java/tmltranslator/TMLTextSpecification.java +++ b/src/main/java/tmltranslator/TMLTextSpecification.java @@ -48,6 +48,7 @@ import myutil.FileUtils; import myutil.TraceManager; import java.io.BufferedReader; +import java.io.File; import java.io.StringReader; import java.util.ArrayList; import java.util.Date; @@ -105,6 +106,7 @@ public class TMLTextSpecification<E> { } public void saveFile(String path, String filename) throws FileException { + FileUtils.checkAndCreateTMLDir(path); TraceManager.addUser("Saving TML spec file in " + path + filename); FileUtils.saveFile(path + filename, spec); } diff --git a/src/main/java/tmltranslator/touppaal/TML2UPPAAL.java b/src/main/java/tmltranslator/touppaal/TML2UPPAAL.java index ae112db01bed47f507ae5f1ad05069694641f993..fa3784493ffc6fa7997443ca7c71d1c50d7db7b0 100755 --- a/src/main/java/tmltranslator/touppaal/TML2UPPAAL.java +++ b/src/main/java/tmltranslator/touppaal/TML2UPPAAL.java @@ -95,6 +95,7 @@ public class TML2UPPAAL { // Returns a list of all file names .. public void saveInFile(String path) throws FileException { + FileUtils.checkAndCreateUPPAALDir(path); FileUtils.saveFile(path + "spec.xml", spec.makeSpec()); //System.out.println("spec.xml generated:\n" + spec.getFullSpec()); } diff --git a/src/main/java/translator/touppaal/TURTLE2UPPAAL.java b/src/main/java/translator/touppaal/TURTLE2UPPAAL.java index e146c2c731ecee46c785e669e2136e0f8e810c54..02c2aaed40b637fb0ab64db6c8bc290646a0149a 100755 --- a/src/main/java/translator/touppaal/TURTLE2UPPAAL.java +++ b/src/main/java/translator/touppaal/TURTLE2UPPAAL.java @@ -114,6 +114,7 @@ public class TURTLE2UPPAAL { public void saveInFile(String path) throws FileException { + FileUtils.checkAndCreateUPPAALDir(path); FileUtils.saveFile(path + "spec.xml", spec.makeSpec()); //System.out.println("spec.xml generated:\n" + spec.getFullSpec()); diff --git a/src/main/java/ui/ActionPerformer.java b/src/main/java/ui/ActionPerformer.java index 635e8c508e115c852ec37ef0df167f3420458eec..17bb41bfb4ee6753379d9834de95953214fc7ac4 100755 --- a/src/main/java/ui/ActionPerformer.java +++ b/src/main/java/ui/ActionPerformer.java @@ -43,6 +43,7 @@ package ui; import common.ConfigurationTTool; +import common.SpecConfigTTool; import javax.swing.*; import java.awt.event.ActionEvent; @@ -61,7 +62,9 @@ public class ActionPerformer { // Compare the action command to the known actions. if (command.equals(mgui.actions[TGUIAction.ACT_NEW].getActionCommand())) { - mgui.newProject(); + mgui.newProject(); + } else if (command.equals(mgui.actions[TGUIAction.ACT_NEW_PROJECT].getActionCommand())) { + mgui.newProjectDir(); } else if (command.equals(mgui.actions[TGUIAction.ACT_NEW_DESIGN].getActionCommand())) { mgui.newDesign(); } else if (command.equals(mgui.actions[TGUIAction.ACT_NEW_ANALYSIS].getActionCommand())) { @@ -69,7 +72,9 @@ public class ActionPerformer { } else if (command.equals(mgui.actions[TGUIAction.ACT_OPEN_FROM_NETWORK].getActionCommand())) { mgui.openNetworkProject(); } else if (command.equals(mgui.actions[TGUIAction.ACT_OPEN].getActionCommand())) { - mgui.openProject(); + mgui.openProject(false); + } else if (command.equals(mgui.actions[TGUIAction.ACT_OPEN_PROJECT].getActionCommand())) { + mgui.openProject(true); } else if (command.equals(mgui.actions[TGUIAction.ACT_MERGE].getActionCommand())) { mgui.mergeProject(); } else if (command.equals(mgui.actions[TGUIAction.ACT_OPEN_LAST].getActionCommand())) { @@ -299,7 +304,7 @@ public class ActionPerformer { } else if (command.equals(mgui.actions[TGUIAction.ACT_NC].getActionCommand())) { mgui.NC(); } else if (command.equals(mgui.actions[TGUIAction.EXTERNAL_ACTION_1].getActionCommand())) { - mgui.executeUserCommand(ConfigurationTTool.ExternalCommand1Host, ConfigurationTTool.ExternalCommand1); + mgui.executeUserCommand(ConfigurationTTool.ExternalCommand1Host, SpecConfigTTool.ExternalCommand1); } else if (command.equals(mgui.actions[TGUIAction.EXTERNAL_ACTION_2].getActionCommand())) { mgui.executeUserCommand(ConfigurationTTool.ExternalCommand2Host, ConfigurationTTool.ExternalCommand2); } else if (command.equals(mgui.actions[TGUIAction.CONNECTOR_COMMENT].getActionCommand())) { diff --git a/src/main/java/ui/DocumentationGenerator.java b/src/main/java/ui/DocumentationGenerator.java index 26ceeb9237d068b82b4db39d8ac46b773fae1944..c7883afab82792284cab2b4a03c55e5d0e58ef20 100644 --- a/src/main/java/ui/DocumentationGenerator.java +++ b/src/main/java/ui/DocumentationGenerator.java @@ -58,6 +58,7 @@ import javax.imageio.ImageIO; import javax.swing.*; import common.ConfigurationTTool; +import common.SpecConfigTTool; import java.awt.image.BufferedImage; import java.io.File; @@ -189,7 +190,7 @@ public class DocumentationGenerator implements SteppedAlgorithm, StoppableGUIEle docFolder.mkdir(); final String makefileName = File.separator + "Makefile"; - final File makeFile = new File( ConfigurationTTool.IMGPath + makefileName ); + final File makeFile = new File( SpecConfigTTool.IMGPath + makefileName ); try { if ( makeFile.exists() ) { @@ -197,7 +198,7 @@ public class DocumentationGenerator implements SteppedAlgorithm, StoppableGUIEle } final String mliFileName = File.separator + "mli.mk"; - final File mliFile = new File( ConfigurationTTool.IMGPath + mliFileName ); + final File mliFile = new File( SpecConfigTTool.IMGPath + mliFileName ); if ( mliFile.exists() ) { Files.copy( mliFile.toPath(), new File( getPath() + mliFileName ).toPath() ); diff --git a/src/main/java/ui/GTURTLEModeling.java b/src/main/java/ui/GTURTLEModeling.java index a535fea9cb71e38c7b528d0464afff0c249e0d1b..27c74ab9972d3a6a7853d3fdb76aa9525e97646c 100755 --- a/src/main/java/ui/GTURTLEModeling.java +++ b/src/main/java/ui/GTURTLEModeling.java @@ -45,6 +45,7 @@ import avatartranslator.totpn.AVATAR2TPN; import avatartranslator.toturtle.AVATAR2TURTLE; import avatartranslator.touppaal.AVATAR2UPPAAL; import common.ConfigurationTTool; +import common.SpecConfigTTool; import ddtranslator.DDSyntaxException; import ddtranslator.DDTranslator; import launcher.LauncherException; @@ -486,16 +487,16 @@ public class GTURTLEModeling { CCode.toTextFormat(); try { - // Issue #98: Use the passed directory - if( directory/*ConfigurationTTool.CCodeDirectory*/.equals("") ) { + if( directory.equals("") ) { + JOptionPane.showMessageDialog( mgui.frame, "No directory for C code generation found in config.xml. The C code cannot be generated.", "Control code generation failed", JOptionPane.INFORMATION_MESSAGE ); return true; } - else { - // Issue #98: Use the passed directory - CCode.saveFile( directory/*ConfigurationTTool.CCodeDirectory*/ + File.separator, applicationName ); + else { + FileUtils.checkAndCreateCCodeDir(directory); + CCode.saveFile( directory + File.separator, applicationName ); } } catch( Exception e ) { @@ -506,8 +507,7 @@ public class GTURTLEModeling { } public boolean generateTMLTxt( String _title ) { - - + //This branch is activated if doing the syntax check from the architecture panel. //It generates the text TML for the architecture and the application + mapping information if (tmap != null) { @@ -515,7 +515,7 @@ public class GTURTLEModeling { spec.toTextFormat( tmap ); //TMLMapping try { //TraceManager.addDev( "*** " + ConfigurationTTool.TMLCodeDirectory + File.separator ); - spec.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec" ); + spec.saveFile( SpecConfigTTool.TMLCodeDirectory, "spec" ); } catch( Exception e ) { TraceManager.addError( "Files could not be saved: " + e.getMessage() ); @@ -558,7 +558,7 @@ public class GTURTLEModeling { // from which the button is pressed. If there are multiple CP panels this operation must be repeated for each panel. It // should be no difficult to implement. try { - specCP.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec.tmlcp" ); + specCP.saveFile( SpecConfigTTool.TMLCodeDirectory, "spec.tmlcp" ); } catch( Exception e ) { TraceManager.addError( "Writing TMLText for CPs, file could not be saved: " + e.getMessage() ); @@ -572,7 +572,7 @@ public class GTURTLEModeling { TMLTextSpecification<TGComponent> spec = new TMLTextSpecification<>( _title ); spec.toTextFormat( tmlm ); //TMLModeling try { - spec.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec.tml" ); + spec.saveFile( SpecConfigTTool.TMLCodeDirectory, "spec.tml" ); } catch( Exception e ) { TraceManager.addError( "File could not be saved: " + e.getMessage() ); @@ -3276,7 +3276,7 @@ public class GTURTLEModeling { public String showRGDiplodocus() { //TraceManager.addDev("Show diplodocus graph located in " + ConfigurationTTool.GGraphPath + "/tree.dot"); - RemoteExecutionThread ret = new RemoteExecutionThread(ConfigurationTTool.DOTTYHost, null, null, ConfigurationTTool.DOTTYPath + " " + ConfigurationTTool.GGraphPath + "/tree.dot"); + RemoteExecutionThread ret = new RemoteExecutionThread(ConfigurationTTool.DOTTYHost, null, null, ConfigurationTTool.DOTTYPath + " " + SpecConfigTTool.GGraphPath + "/tree.dot"); ret.start(); return null; } @@ -3571,7 +3571,7 @@ public class GTURTLEModeling { } public String getPathUPPAALFile() { - return ConfigurationTTool.UPPAALCodeDirectory; + return SpecConfigTTool.UPPAALCodeDirectory; } public String getUPPAALVerifierHost() { @@ -9067,15 +9067,20 @@ public class GTURTLEModeling { } else { // Generate XML file try { + if (SpecConfigTTool.NCDirectory != null) { + File dir = new File(SpecConfigTTool.NCDirectory); + if (!dir.exists()) + dir.mkdirs(); + } String fileName = "network.xml"; - if (ConfigurationTTool.NCDirectory != null) { - fileName = ConfigurationTTool.NCDirectory + fileName; + if (SpecConfigTTool.NCDirectory != null) { + fileName = SpecConfigTTool.NCDirectory + fileName; } TraceManager.addDev("Saving in network structure in file: " + fileName); FileUtils.saveFile(fileName, ncs.toISAENetworkXML()); fileName = "traffics.xml"; - if (ConfigurationTTool.NCDirectory != null) { - fileName = ConfigurationTTool.NCDirectory + fileName; + if (SpecConfigTTool.NCDirectory != null) { + fileName = SpecConfigTTool.NCDirectory + fileName; } TraceManager.addDev("Saving in traffics in file: " + fileName); FileUtils.saveFile(fileName, ncs.toISAETrafficsXML()); diff --git a/src/main/java/ui/JMenuBarTurtle.java b/src/main/java/ui/JMenuBarTurtle.java index 8e2c0d40d910a76e5d95c8001d06ebf9753bbcc2..448c131c8ad5a62cb0b4e8911bf549ddd57bae3e 100755 --- a/src/main/java/ui/JMenuBarTurtle.java +++ b/src/main/java/ui/JMenuBarTurtle.java @@ -42,6 +42,7 @@ package ui; import common.ConfigurationTTool; +import common.SpecConfigTTool; import javax.swing.*; //import javax.swing.event.*; @@ -96,8 +97,12 @@ public class JMenuBarTurtle extends JMenuBar { // FILE menuItem = file.add(mgui.actions[TGUIAction.ACT_NEW]); menuItem.addMouseListener(mgui.mouseHandler); + menuItem = file.add(mgui.actions[TGUIAction.ACT_NEW_PROJECT]); + menuItem.addMouseListener(mgui.mouseHandler); menuItem = file.add(mgui.actions[TGUIAction.ACT_OPEN]); menuItem.addMouseListener(mgui.mouseHandler); + menuItem = file.add(mgui.actions[TGUIAction.ACT_OPEN_PROJECT]); + menuItem.addMouseListener(mgui.mouseHandler); menuItem = file.add(mgui.actions[TGUIAction.ACT_OPEN_FROM_NETWORK]); menuItem.addMouseListener(mgui.mouseHandler); menuItem = file.add(mgui.actions[TGUIAction.ACT_SAVE]); @@ -597,10 +602,10 @@ public class JMenuBarTurtle extends JMenuBar { menuItem = tool.add(mgui.actions[TGUIAction.ACT_GEN_DOC_REQ]); menuItem.addMouseListener(mgui.mouseHandler); - if ((ConfigurationTTool.ExternalCommand1.length() > 0) && (ConfigurationTTool.ExternalCommand1Host.length() > 0)) { + if ((SpecConfigTTool.ExternalCommand1.length() > 0) && (ConfigurationTTool.ExternalCommand1Host.length() > 0)) { menuItem = tool.add(mgui.actions[TGUIAction.EXTERNAL_ACTION_1]); menuItem.addMouseListener(mgui.mouseHandler); - menuItem.setToolTipText(ConfigurationTTool.ExternalCommand1); + menuItem.setToolTipText("Launch gtkwave with last vcd file"); } if ((ConfigurationTTool.ExternalCommand2.length() > 0) && (ConfigurationTTool.ExternalCommand2Host.length() > 0)) { diff --git a/src/main/java/ui/JToolBarMainTurtle.java b/src/main/java/ui/JToolBarMainTurtle.java index 825d0f7b5f61c4ec2238e9f9edad82f708bcde3d..676e230093a5d45419207ecb1b3d35b92eed6db5 100755 --- a/src/main/java/ui/JToolBarMainTurtle.java +++ b/src/main/java/ui/JToolBarMainTurtle.java @@ -43,6 +43,7 @@ package ui; import common.ConfigurationTTool; +import common.SpecConfigTTool; import myutil.TraceManager; import javax.swing.*; @@ -83,8 +84,12 @@ public class JToolBarMainTurtle extends JToolBar implements ActionListener button = add(mgui.actions[TGUIAction.ACT_NEW]); button.addMouseListener(mgui.mouseHandler); + button = add(mgui.actions[TGUIAction.ACT_NEW_PROJECT]); + button.addMouseListener(mgui.mouseHandler); button = add(mgui.actions[TGUIAction.ACT_OPEN]); button.addMouseListener(mgui.mouseHandler); + button = add(mgui.actions[TGUIAction.ACT_OPEN_PROJECT]); + button.addMouseListener(mgui.mouseHandler); button = add(mgui.actions[TGUIAction.ACT_SAVE]); button.addMouseListener(mgui.mouseHandler); //button = add(mgui.actions[TGUIAction.ACT_SAVE_AS]); @@ -257,10 +262,10 @@ public class JToolBarMainTurtle extends JToolBar implements ActionListener addSeparator(); - if ((ConfigurationTTool.ExternalCommand1.length() > 0) && (ConfigurationTTool.ExternalCommand1Host.length() > 0)) { + if ((SpecConfigTTool.ExternalCommand1.length() > 0) && (ConfigurationTTool.ExternalCommand1Host.length() > 0)) { button = add(mgui.actions[TGUIAction.EXTERNAL_ACTION_1]); button.addMouseListener(mgui.mouseHandler); - button.setToolTipText(ConfigurationTTool.ExternalCommand1); + button.setToolTipText("Launch gtkwave with last vcd file"); addSeparator(); } diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java index 62d677b1b92672a3cd1848b8c65adfb042cd5faa..6088a4efc3a70fd2fa86238e85a6a81de2ce3d49 100644 --- a/src/main/java/ui/MainGUI.java +++ b/src/main/java/ui/MainGUI.java @@ -43,6 +43,7 @@ package ui; import avatartranslator.AvatarSpecification; import common.ConfigurationTTool; +import common.SpecConfigTTool; import ddtranslatorSoclib.AvatarddSpecification; import ddtranslatorSoclib.toSoclib.TasksAndMainGenerator; import launcher.RemoteExecutionThread; @@ -100,6 +101,8 @@ import javax.imageio.ImageIO; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.filechooser.FileNameExtensionFilter; + import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; @@ -135,6 +138,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public static boolean experimentalOn; public static boolean avatarOnly; public static boolean turtleOn; + + public boolean isxml = false; public final static int LOTOS = 0; public final static int RT_LOTOS = 1; @@ -283,6 +288,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe private Plugin pluginSelected; private File file; + private File dir; + private File config; private File lotosfile; private File simfile; private File dtafile; @@ -352,7 +359,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe //PluginManager.pluginManager = new PluginManager(); } - + public void setKey(String _sk) { sk = _sk; RshClient.sk = sk; @@ -361,7 +368,10 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public String getKey() { return sk; } - + + public File getDir() { + return dir; + } public boolean isAvatarOn() { return avatarOn; @@ -411,14 +421,14 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe jfclib = new JFileChooser(); } - if (ConfigurationTTool.IMGPath.length() > 0) { - jfcimg = new JFileChooser(ConfigurationTTool.IMGPath); + if (SpecConfigTTool.IMGPath.length() > 0) { + jfcimg = new JFileChooser(SpecConfigTTool.IMGPath); } else { jfcimg = new JFileChooser(); } - if (ConfigurationTTool.IMGPath.length() > 0) { - jfcimgsvg = new JFileChooser(ConfigurationTTool.IMGPath); + if (SpecConfigTTool.IMGPath.length() > 0) { + jfcimgsvg = new JFileChooser(SpecConfigTTool.IMGPath); } else { jfcimgsvg = new JFileChooser(); } @@ -429,20 +439,21 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe jfclot = new JFileChooser(); } - if (ConfigurationTTool.GGraphPath.length() > 0) { - jfcggraph = new JFileChooser(ConfigurationTTool.GGraphPath); + if (SpecConfigTTool.GGraphPath.length() > 0) { + jfcggraph = new JFileChooser(SpecConfigTTool.GGraphPath); } else { jfcggraph = new JFileChooser(); } - if (ConfigurationTTool.TGraphPath.length() > 0) { - jfctgraph = new JFileChooser(ConfigurationTTool.TGraphPath); + if (SpecConfigTTool.TGraphPath.length() > 0) { + jfctgraph = new JFileChooser(SpecConfigTTool.TGraphPath); } else { jfctgraph = new JFileChooser(); } TFileFilter filter = new TFileFilter(); jfc.setFileFilter(filter); + jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); TTIFFilter filtertif = new TTIFFilter(); jfctif.setFileFilter(filtertif); @@ -1546,13 +1557,13 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe } public void firstDiag() { - TURTLEPanel tp = getCurrentTURTLEPanel(); - if (tp == null) { - return; - } - tp.tabbedPane.setSelectedIndex(0); - } + TURTLEPanel tp = getCurrentTURTLEPanel(); + if (tp == null) { + return; + } + tp.tabbedPane.setSelectedIndex(0); + } public String getTitleOf(TDiagramPanel _tdp) { TURTLEPanel panel; for(int i=0; i<tabs.size(); i++) { @@ -1909,6 +1920,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe newTurtleModeling(); //gtm.saveOperation(tcdp); file = null; + dir = null; + config = null; frame.setTitle("TTool: unsaved project"); } else { // check if previous modeling is saved @@ -1949,7 +1962,52 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe frame.setTitle("TTool: unsaved project"); } } - + + public void newProjectDir() { + if (mode == NOT_OPENED) { + int val = createFileDialog(); + if (val == JFileChooser.APPROVE_OPTION) + createFile(); + } + else { + // check if previous modeling is saved + boolean b = actions[TGUIAction.ACT_SAVE].isEnabled(); + if (b) { + if (!saveBeforeAction("Save and Start New Modeling", "Start New modeling")) { + return; + } + /*int back = JOptionPane.showConfirmDialog(frame, "Modeling has not been saved\nDo you really want to open a new one ?", "Attention: current modeling not saved ?", JOptionPane.OK_CANCEL_OPTION); + if (back == JOptionPane.CANCEL_OPTION) { + return; */ + /*}*/ + } + int val = createFileDialog(); + if (val == JFileChooser.APPROVE_OPTION) { + // close current modeling + closeTurtleModeling(); + createFile(); + } + } + } + + public void saveConfig() { + int i = 0; + for (; i < tabs.size(); i++) { + if (tabs.get(i) == activetdp.tp) + break; + } + int j = tabs.get(i).getIndexOfChild(activetdp); + SpecConfigTTool.lastTab = i; + SpecConfigTTool.lastPanel = j; + try { + SpecConfigTTool.saveConfiguration(config); + SpecConfigTTool.lastPanel = -1; + SpecConfigTTool.lastTab = -1; + } catch (MalformedConfigurationException e) { + System.err.println(e.getMessage() + " : Can't save config file."); + } + } + public String loadFile(File f) { String s = null; @@ -2045,6 +2103,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe /* textual form */ DTAFileFilter filter = new DTAFileFilter(); jfctgraph.setFileFilter(filter); + jfctgraph.setCurrentDirectory(new File(SpecConfigTTool.TGraphPath)); int returnVal = jfctgraph.showDialog(frame, "Save last DTA (textual form)"); if(returnVal != JFileChooser.APPROVE_OPTION) { @@ -2086,6 +2145,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe /* textual form */ RGFileFilter filter = new RGFileFilter(); jfctgraph.setFileFilter(filter); + jfctgraph.setCurrentDirectory(new File(SpecConfigTTool.TGraphPath)); int returnVal = jfctgraph.showDialog(frame, "Save last RG (textual form)"); if(returnVal != JFileChooser.APPROVE_OPTION) { @@ -2213,6 +2273,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe /* textual form */ AUTFileFilter filter = new AUTFileFilter(); jfctgraph.setFileFilter(filter); + jfctgraph.setCurrentDirectory(new File(SpecConfigTTool.TGraphPath)); int returnVal = jfctgraph.showDialog(frame, "Load AUT graph"); if(returnVal != JFileChooser.APPROVE_OPTION) { @@ -2232,10 +2293,42 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe ret[1] = spec; return ret; } + + public void loadAUTGraphsDir() { + File dir = new File(SpecConfigTTool.TGraphPath); + if (!dir.exists()) { + System.err.println("Graphs directory doesn't exists !"); + return; + } + + for (File autfile: dir.listFiles()) { + if (!FileUtils.getExtension(autfile).equals("aut")) + continue; + + String spec = loadFile(autfile); + if (spec == null) { + continue; + } + + RG rg = new RG(autfile.getName()); + rg.fileName = autfile.getName(); + rg.data = spec; + addRG(rg); + } + + } public void updateLastOpenFile(File file) { if (ConfigurationTTool.LastOpenFileDefined) { ConfigurationTTool.LastOpenFile = file.getPath(); + if (ConfigurationTTool.LastOpenFile.contains(".ttool" + File.separator)) { + int last = 0; + for (int i = 0;i < ConfigurationTTool.LastOpenFile.length(); i++) { + if (ConfigurationTTool.LastOpenFile.charAt(i) == '/') + last = i; + } + ConfigurationTTool.LastOpenFile = ConfigurationTTool.LastOpenFile.substring(0, last); + } // Change name of action actions[TGUIAction.ACT_OPEN_LAST].setName(TGUIAction.ACT_OPEN_LAST, ConfigurationTTool.LastOpenFile); } @@ -2315,7 +2408,9 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe } - public void openProject() { + public void openProject(boolean isProject) { + if (config != null && activetdp != null) + saveConfig(); // check if a current modeling is opened boolean b = actions[TGUIAction.ACT_SAVE].isEnabled(); @@ -2330,6 +2425,99 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe } //jfc.setApproveButtonText("Open"); + if (isProject) { + jfc.resetChoosableFileFilters(); + jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + jfc.setAcceptAllFileFilterUsed(false); + FileNameExtensionFilter filter = new FileNameExtensionFilter("TTool project", "ttool"); + jfc.setFileFilter(filter); + /*jfc.addMouseListener(new MouseListener() { + + @Override + public void mouseClicked(MouseEvent arg0) { + + if(arg0.getClickCount() == 2) { + File file = jfc.getSelectedFile(); + if(!FileUtils.getExtension(file).equals("ttool")) { + jfc.setCurrentDirectory(file); + jfc.rescanCurrentDirectory(); + } + else { + jfc.approveSelection(); + } + } + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + return; + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + return; + } + + @Override + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + return; + } + + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + return; + } + });*/ + } + else { + jfc.resetChoosableFileFilters(); + jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); + jfc.setAcceptAllFileFilterUsed(false); + FileNameExtensionFilter filter = new FileNameExtensionFilter("XML files", "xml"); + jfc.setFileFilter(filter); + /*jfc.addMouseListener(new MouseListener() { + + @Override + public void mouseClicked(MouseEvent arg0) { + + if(arg0.getClickCount() == 2) { + File file = jfc.getSelectedFile(); + if(!FileUtils.getExtension(file).equals("ttool")) { + jfc.setCurrentDirectory(file); + jfc.rescanCurrentDirectory(); + } + } + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + return; + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + return; + } + + @Override + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + return; + } + + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + return; + } + });*/ + } int returnVal = jfc.showOpenDialog(frame); if (returnVal == JFileChooser.CANCEL_OPTION) { @@ -2344,13 +2532,30 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe } public void openProjectFromFile(File _f) { - file = _f; - - if(checkFileForOpen(_f)) { + if (FileUtils.getExtension(_f).equals("ttool")) { + dir = _f; + SpecConfigTTool.setDirConfig(dir); + String filename = dir.getAbsolutePath() + "/" + dir.getName().replaceAll(".ttool", ".xml"); + file = new File(filename); + config = new File(dir.getAbsolutePath() + "/project_config.xml"); + try { + SpecConfigTTool.loadConfigFile(config); + } catch (MalformedConfigurationException e) { + System.err.println(e.getMessage() + " : Can't load config file."); + } + } + else { + dir = null; + config = null; + SpecConfigTTool.setBasicConfig(systemcOn); + file = _f; + } + + if(checkFileForOpen(file)) { String s = null; try { - FileInputStream fis = new FileInputStream(_f); + FileInputStream fis = new FileInputStream(file); int nb = fis.available(); byte [] ba = new byte[nb]; @@ -2371,7 +2576,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe // gtm.enableUndo(false); // Update configuration - updateLastOpenFile(_f); + updateLastOpenFile(file); // Issue #41: Moved to common method loadModels( s, "loaded" ); @@ -2394,7 +2599,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe // gtm.enableUndo(true); // gtm.saveOperation(getCurrentSelectedPoint()); // dtree.forceUpdate(); - getCurrentTDiagramPanel().repaint(); + if (getCurrentTDiagramPanel() != null) + getCurrentTDiagramPanel().repaint(); } } @@ -2411,6 +2617,29 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe if(checkFileForOpen(file)) { String s = null; + + if (FileUtils.getExtension(file).equals("ttool")) { + int last = 0; + for (int i = 0;i < ConfigurationTTool.LastOpenFile.length(); i++) { + if (ConfigurationTTool.LastOpenFile.charAt(i) == '/') + last = i; + } + dir = file; + String xml = ConfigurationTTool.LastOpenFile.substring(last, ConfigurationTTool.LastOpenFile.length()).replaceAll(".ttool", ".xml"); + file = new File(dir.getAbsolutePath() + File.separator + xml); + SpecConfigTTool.setDirConfig(dir); + config = new File(dir.getAbsolutePath() + "/project_config.xml"); + try { + SpecConfigTTool.loadConfigFile(config); + } catch (MalformedConfigurationException e) { + System.err.println(e.getMessage() + " : Can't load config file."); + } + } + else { + dir = null; + config = null; + SpecConfigTTool.setBasicConfig(systemcOn); + } try { FileInputStream fis = new FileInputStream(file); @@ -2424,7 +2653,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe JOptionPane.showMessageDialog(frame, "File could not be opened because " + e.getMessage(), "File Error", JOptionPane.INFORMATION_MESSAGE); return; } - + // close current modeling closeTurtleModeling(); @@ -2489,6 +2718,15 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe gtm.enableUndo(true); gtm.saveOperation(getCurrentSelectedPoint()); dtree.forceUpdate(); + if (SpecConfigTTool.lastTab > -1 && SpecConfigTTool.lastPanel > -1 && mainTabbedPane.getTabCount() > 0) { + mainTabbedPane.setSelectedIndex(SpecConfigTTool.lastTab); + activetdp = tabs.get(SpecConfigTTool.lastTab).getPanels().elementAt(SpecConfigTTool.lastPanel); + activetdp.selectTab(activetdp.name); + basicActivateDrawing(); + } + + if (dir != null) + loadAUTGraphsDir(); } public void saveAsLibrary(String data) { @@ -2632,23 +2870,75 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe } + private int createFileDialog() { + int returnVal = jfc.showSaveDialog(frame); + if(returnVal == JFileChooser.APPROVE_OPTION) { + dir = jfc.getSelectedFile(); + dir = FileUtils.addFileExtensionIfMissing(dir, "ttool"); + dir.mkdir(); + SpecConfigTTool.setDirConfig(dir); + config = SpecConfigTTool.createProjectConfig(dir); + try { + SpecConfigTTool.loadConfigFile(config); + } catch (MalformedConfigurationException e) { + System.err.println(e.getMessage() + " : Can't load config file."); + } + String newname = FileUtils.removeFileExtension(dir.getName()); + file = new File(dir, newname); + file = FileUtils.addFileExtensionIfMissing(file, TFileFilter.getExtension()); + } + + return returnVal; + } + + private void createFile() { + newTurtleModeling(); + frame.setTitle(file.getName()); + try { + if (gtm == null) { + throw new Exception("Internal model Error 1"); + } + String s = gtm.makeXMLFromTurtleModeling(-1); + if (s == null) { + throw new Exception("Internal model Error 2"); + } + FileOutputStream fos = new FileOutputStream(file); + fos.write(s.getBytes()); + fos.close(); + updateLastOpenFile(file); + setMode(MODEL_SAVED); + String title = "TTool: " + file.getAbsolutePath(); + if (!frame.getTitle().equals(title)) { + frame.setTitle(title); + } + if (lotosfile == null) { + makeLotosFile(); + } + } + catch(Exception e) { + JOptionPane.showMessageDialog(frame, "File could not be saved because " + e.getMessage(), "File Error", JOptionPane.INFORMATION_MESSAGE); + } + } + protected boolean saveProject() { if (file == null) { - //jfc.setApproveButtonText("Save"); - int returnVal = jfc.showSaveDialog(frame); - if(returnVal == JFileChooser.APPROVE_OPTION) { - file = jfc.getSelectedFile(); - file = FileUtils.addFileExtensionIfMissing(file, TFileFilter.getExtension()); - } + if (dir != null) + createFileDialog(); + else { + int returnVal = jfc.showSaveDialog(frame); + if(returnVal == JFileChooser.APPROVE_OPTION) { + file = jfc.getSelectedFile(); + file = FileUtils.addFileExtensionIfMissing(file, TFileFilter.getExtension()); + } + } } if( checkFileForSave(file)) { - String s = gtm.makeXMLFromTurtleModeling(-1); - try { if (gtm == null) { throw new Exception("Internal model Error 1"); } + String s = gtm.makeXMLFromTurtleModeling(-1); if (s == null) { throw new Exception("Internal model Error 2"); } @@ -2857,6 +3147,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe try { if (ConfigurationTTool.LastOpenFileDefined) { + if (dir != null) + saveConfig(); ConfigurationTTool.saveConfiguration(); //TraceManager.addDev("Configuration written to file"); } @@ -4122,7 +4414,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe } public void generateAUT() { - JDialogGenAUT jdgaut = new JDialogGenAUT(frame, this, "Generation of automata", ConfigurationTTool.BcgioPath, ConfigurationTTool.AldebaranHost, ConfigurationTTool.TGraphPath); + JDialogGenAUT jdgaut = new JDialogGenAUT(frame, this, "Generation of automata", ConfigurationTTool.BcgioPath, ConfigurationTTool.AldebaranHost, SpecConfigTTool.TGraphPath); // jdgaut.setSize(450, 600); GraphicLib.centerOnParent(jdgaut, 450, 600); jdgaut.setVisible(true); @@ -4143,7 +4435,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe JDialogGenAUTS jdgauts = new JDialogGenAUTS(frame, this, "Generation of automata via LOTOS", gtm.getPathCaesar(), GTURTLEModeling.getPathBcgio(), REMOTE_RTL_LOTOS_FILE, - GTURTLEModeling.getCaesarHost(), ConfigurationTTool.TGraphPath); + GTURTLEModeling.getCaesarHost(), SpecConfigTTool.TGraphPath); // jdgauts.setSize(450, 600); GraphicLib.centerOnParent(jdgauts, 450, 600); jdgauts.setVisible(true); @@ -4171,7 +4463,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public void avatarUPPAALVerification() { TraceManager.addDev("Avatar uppaal fv"); - boolean result = gtm.generateUPPAALFromAVATAR(ConfigurationTTool.UPPAALCodeDirectory); + boolean result = gtm.generateUPPAALFromAVATAR(SpecConfigTTool.UPPAALCodeDirectory); if (result) { formalValidation(true); } else { @@ -4190,9 +4482,9 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe AvatarDesignPanel adp = null; if (tp instanceof AvatarDesignPanel){ adp = (AvatarDesignPanel) tp; - limit=false; - } - JDialogProverifVerification jgen = new JDialogProverifVerification(frame, this, "Security verification with ProVerif", ConfigurationTTool.ProVerifVerifierHost, ConfigurationTTool.ProVerifCodeDirectory, ConfigurationTTool.ProVerifVerifierPath, adp,limit, gtm.getCPUTaskMap()); + limit=false; + } + JDialogProverifVerification jgen = new JDialogProverifVerification(frame, this, "Security verification with ProVerif", ConfigurationTTool.ProVerifVerifierHost, SpecConfigTTool.ProVerifCodeDirectory, ConfigurationTTool.ProVerifVerifierPath, adp,limit, gtm.getCPUTaskMap()); // jgen.setSize(500, 450); GraphicLib.centerOnParent(jgen, 600, 800); jgen.setVisible(true); @@ -4201,7 +4493,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public void dse(){ TraceManager.addDev("Design space exploration"); - JDialogDSE jdse= new JDialogDSE(frame, this, "Design Space Exploration", ConfigurationTTool.SystemCCodeDirectory, ConfigurationTTool.TMLCodeDirectory); + JDialogDSE jdse= new JDialogDSE(frame, this, "Design Space Exploration", SpecConfigTTool.SystemCCodeDirectory, SpecConfigTTool.TMLCodeDirectory); // jdse.setSize(600,800); GraphicLib.centerOnParent(jdse, 600,800); jdse.setVisible(true); @@ -4219,7 +4511,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public void avatarExecutableCodeGeneration() { TraceManager.addDev("Avatar code generation"); - JDialogAvatarExecutableCodeGeneration jgen = new JDialogAvatarExecutableCodeGeneration(frame, this, "Executable Code generation, compilation and execution", ConfigurationTTool.AVATARExecutableCodeHost, ConfigurationTTool.AVATARExecutableCodeDirectory, ConfigurationTTool.AVATARExecutableCodeCompileCommand, ConfigurationTTool.AVATARExecutableCodeExecuteCommand, ConfigurationTTool.AVATARExecutableSoclibCodeCompileCommand, ConfigurationTTool.AVATARExecutableSoclibCodeExecuteCommand, ConfigurationTTool.AVATARExecutableSoclibTraceFile); + JDialogAvatarExecutableCodeGeneration jgen = new JDialogAvatarExecutableCodeGeneration(frame, this, "Executable Code generation, compilation and execution", ConfigurationTTool.AVATARExecutableCodeHost, SpecConfigTTool.AVATARExecutableCodeDirectory, SpecConfigTTool.AVATARExecutableCodeCompileCommand, SpecConfigTTool.AVATARExecutableCodeExecuteCommand, ConfigurationTTool.AVATARExecutableSoclibCodeCompileCommand, ConfigurationTTool.AVATARExecutableSoclibCodeExecuteCommand, ConfigurationTTool.AVATARExecutableSoclibTraceFile); // jgen.setSize(500, 450); GraphicLib.centerOnParent(jgen, 500, 450); jgen.setVisible(true); @@ -4253,7 +4545,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe //TraceManager.addDev("4173"); if (gtm.getTURTLEModelingState() == 3) { //AVATAR - boolean result = gtm.generateUPPAALFromAVATAR(ConfigurationTTool.UPPAALCodeDirectory); + boolean result = gtm.generateUPPAALFromAVATAR(SpecConfigTTool.UPPAALCodeDirectory); TraceManager.addDev("4177"); if (showWindow) { TraceManager.addDev("4178"); @@ -4288,7 +4580,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe boolean result = false; if ((tp instanceof TMLDesignPanel) || (tp instanceof TMLComponentDesignPanel)) { - result = gtm.generateUPPAALFromTML(ConfigurationTTool.UPPAALCodeDirectory, false, 1024, true); + result = gtm.generateUPPAALFromTML(SpecConfigTTool.UPPAALCodeDirectory, false, 1024, true); } if (result != false) { formalValidation(); @@ -4306,7 +4598,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe TraceManager.addDev( "gtm.getTURTLEModelingState() <= 0)" ); //TraceManager.addDev("After UPPAAL"); if (showWindow) { - JDialogUPPAALGeneration jgen = new JDialogUPPAALGeneration(frame, this, "UPPAAL code generation", ConfigurationTTool.UPPAALCodeDirectory, JDialogUPPAALGeneration.TURTLE_MODE); + JDialogUPPAALGeneration jgen = new JDialogUPPAALGeneration(frame, this, "UPPAAL code generation", SpecConfigTTool.UPPAALCodeDirectory, JDialogUPPAALGeneration.TURTLE_MODE); //jgen.setSize(450, 600); GraphicLib.centerOnParent(jgen, 450, 600); jgen.setVisible(true); @@ -4321,7 +4613,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe TraceManager.addDev("Null avatar spec"); return; } - JDialogAvatarModelChecker jmc = new JDialogAvatarModelChecker(frame, this, "Avatar: Model Checking", gtm.getAvatarSpecification(), ConfigurationTTool.TGraphPath, experimentalOn); + JDialogAvatarModelChecker jmc = new JDialogAvatarModelChecker(frame, this, "Avatar: Model Checking", gtm.getAvatarSpecification(), SpecConfigTTool.TGraphPath, experimentalOn); // jmc.setSize(550, 600); GraphicLib.centerOnParent(jmc, 550, 600); jmc.setVisible(true); @@ -4378,8 +4670,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe avatarSimulation(); } else if ((tp instanceof TMLDesignPanel) || (tp instanceof TMLComponentDesignPanel) || (tp instanceof TMLArchiPanel)) { JDialogSystemCGeneration jgen = new JDialogSystemCGeneration(frame, this, "Simulation Code Generation and Compilation", - ConfigurationTTool.SystemCHost, ConfigurationTTool.SystemCCodeDirectory, ConfigurationTTool.SystemCCodeCompileCommand, - ConfigurationTTool.SystemCCodeExecuteCommand, ConfigurationTTool.SystemCCodeInteractiveExecuteCommand, ConfigurationTTool.GGraphPath, _mode); + ConfigurationTTool.SystemCHost, SpecConfigTTool.SystemCCodeDirectory, SpecConfigTTool.SystemCCodeCompileCommand, + SpecConfigTTool.SystemCCodeExecuteCommand, SpecConfigTTool.SystemCCodeInteractiveExecuteCommand, SpecConfigTTool.GGraphPath, _mode); //jgen.setSize(500, 750); GraphicLib.centerOnParent( jgen, 700, 750 ); jgen.setVisible(true); @@ -4392,7 +4684,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe } public void interactiveSimulationSystemC() { - interactiveSimulationSystemC(ConfigurationTTool.SystemCCodeInteractiveExecuteCommand + " -gpath " + ConfigurationTTool.GGraphPath); + interactiveSimulationSystemC(SpecConfigTTool.SystemCCodeInteractiveExecuteCommand + " -gpath " + SpecConfigTTool.GGraphPath); } public void interactiveSimulationSystemC(String executePath) { @@ -4491,8 +4783,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe // path = file.getAbsolutePath(); // } JDialogCCodeGeneration jgen = new JDialogCCodeGeneration( frame, this, "Application code generation and compilation", - ConfigurationTTool.CCodeDirectory, - "make -C " + ConfigurationTTool.CCodeDirectory, + SpecConfigTTool.CCodeDirectory, + "make -C " + SpecConfigTTool.CCodeDirectory, gtm ); // jgen.setSize(500, 750); GraphicLib.centerOnParent(jgen, 500, 750); @@ -4869,7 +5161,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe // Loadng the graph // Adding RG to the tree on the left try { - String fileName = ConfigurationTTool.TGraphPath + "/" + graphName + ".aut"; + String fileName = SpecConfigTTool.TGraphPath + "/" + graphName + ".aut"; File f = new File(fileName); String spec = loadFile(f); RG rg = new RG(graphName); @@ -5163,7 +5455,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe //Select file File file = selectFileForCapture(); if (file == null) - return; + return; + Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screenSize = toolkit.getScreenSize(); Rectangle screenRect = new Rectangle(screenSize); @@ -5360,9 +5653,11 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public File selectFileForCapture() { File file = null; + jfcimg.setCurrentDirectory(new File(SpecConfigTTool.IMGPath)); int returnVal = jfcimg.showSaveDialog(frame); if (returnVal == JFileChooser.CANCEL_OPTION) - return null; + return null; + if(returnVal == JFileChooser.APPROVE_OPTION) { file = jfcimg.getSelectedFile(); file = FileUtils.addFileExtensionIfMissing(file, TImgFilter.getExtension()); @@ -5380,9 +5675,11 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public File selectSVGFileForCapture(boolean checkForSave) { File file = null; + jfcimgsvg.setCurrentDirectory(new File(SpecConfigTTool.IMGPath)); int returnVal = jfcimgsvg.showSaveDialog(frame); if (returnVal == JFileChooser.CANCEL_OPTION) - return null; + return null; + if(returnVal == JFileChooser.APPROVE_OPTION) { file = jfcimgsvg.getSelectedFile(); file = FileUtils.addFileExtensionIfMissing(file, TSVGFilter.getExtension()); @@ -5445,7 +5742,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public void generateDocumentation() { //TraceManager.addDev("Documentation"); - ThreadGUIElement t = new ThreadGUIElement(frame, 1, tabs, mainTabbedPane, ConfigurationTTool.DocGenPath, file.getName(),"Documentation", "Generating documentation ... Please wait"); + ThreadGUIElement t = new ThreadGUIElement(frame, 1, tabs, mainTabbedPane, SpecConfigTTool.DocGenPath, file.getName(),"Documentation", "Generating documentation ... Please wait"); t.go(); /*DocumentationGenerator docgen = new DocumentationGenerator(tabs, mainTabbedPane, ConfigurationTTool.IMGPath, file.getName()); docgen.setFirstHeadingNumber(2); @@ -7020,8 +7317,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe public void paneDiplodocusMethodologyAction(ChangeEvent e) { //TraceManager.addDev("Pane design action size=" + tabs.size()); try { - - TDiagramPanel tdp1 = getCurrentTURTLEPanel().panels.elementAt(getCurrentJTabbedPane().getSelectedIndex()); + TDiagramPanel tdp1 = getCurrentTURTLEPanel().panels.elementAt(getCurrentJTabbedPane().getSelectedIndex()); //TraceManager.addDev("Pane design action 1"); if (activetdp != null) { diff --git a/src/main/java/ui/ModeManager.java b/src/main/java/ui/ModeManager.java index fca9ec44ff48141669279ac78a510a147f4d0b08..4a9b4fcafe351781acab785894f4d175b5df8481 100755 --- a/src/main/java/ui/ModeManager.java +++ b/src/main/java/ui/ModeManager.java @@ -43,6 +43,7 @@ package ui; import common.ConfigurationTTool; +import common.SpecConfigTTool; import myutil.TraceManager; /** @@ -60,7 +61,9 @@ public class ModeManager { case MainGUI.NOT_OPENED: mgui.activeActions(false); actions[TGUIAction.ACT_NEW].setEnabled(true); + actions[TGUIAction.ACT_NEW_PROJECT].setEnabled(true); actions[TGUIAction.ACT_OPEN].setEnabled(true); + actions[TGUIAction.ACT_OPEN_PROJECT].setEnabled(true); actions[TGUIAction.ACT_OPEN_FROM_NETWORK].setEnabled(true); actions[TGUIAction.ACT_OPEN_TIF].setEnabled(true); actions[TGUIAction.ACT_OPEN_SD].setEnabled(true); @@ -87,8 +90,8 @@ public class ModeManager { actions[TGUIAction.EXTERNAL_ACTION_1].setEnabled(true); actions[TGUIAction.EXTERNAL_ACTION_2].setEnabled(true); //actions[TGUIAction.ACT_SIMU_SYSTEMC].setEnabled(true); - actions[TGUIAction.ACT_VIEW_RG_DIPLODOCUS].setEnabled(ConfigurationTTool.GGraphPath != null); - actions[TGUIAction.ACT_VIEW_STAT_AUTDIPLODOCUS].setEnabled(ConfigurationTTool.GGraphPath != null); + actions[TGUIAction.ACT_VIEW_RG_DIPLODOCUS].setEnabled(SpecConfigTTool.GGraphPath != null); + actions[TGUIAction.ACT_VIEW_STAT_AUTDIPLODOCUS].setEnabled(SpecConfigTTool.GGraphPath != null); if (mainBar != null) { mainBar.activateSearch(false); } diff --git a/src/main/java/ui/TDiagramMouseManager.java b/src/main/java/ui/TDiagramMouseManager.java index 0304f93386dade657575bd2ca5b890922c5ff202..c2f7f308527804c78c63afb1e2d4ca8461e6547b 100755 --- a/src/main/java/ui/TDiagramMouseManager.java +++ b/src/main/java/ui/TDiagramMouseManager.java @@ -694,6 +694,10 @@ public class TDiagramMouseManager extends MouseAdapter {//implements MouseListen public void clearSelectComponents(){ this.selectedMultiComponents.clear(); } + + public TDiagramPanel getTdp() { + return tdp; + } // // public void removeSelectedComponentFromList(){ // this.selectedMultiComponents.clear(); diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java index 61b4ccb0908525ec6b24a47c8d4e1a66f6f4ca1c..934ce8592b0f712c1f79a91b21f51603892537ff 100755 --- a/src/main/java/ui/TGUIAction.java +++ b/src/main/java/ui/TGUIAction.java @@ -67,9 +67,11 @@ public class TGUIAction extends AbstractAction { // Actions public static final int ACT_NEW = 0; + public static final int ACT_NEW_PROJECT = 471; public static final int ACT_NEW_DESIGN = 100; public static final int ACT_NEW_ANALYSIS = 101; public static final int ACT_OPEN = 1; + public static final int ACT_OPEN_PROJECT = 472; public static final int ACT_OPEN_FROM_NETWORK = 455; public static final int ACT_OPEN_LAST = 154; public static final int ACT_MERGE = 228; @@ -627,7 +629,7 @@ public class TGUIAction extends AbstractAction { public static final int MOVE_ENABLED = 463; public static final int FIRST_DIAGRAM = 464; - public static final int NB_ACTION = 471; + public static final int NB_ACTION = 473; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -681,9 +683,11 @@ public class TGUIAction extends AbstractAction { public void init() { actions[ACT_NEW] = new TAction("new-command", "New", IconManager.imgic20, IconManager.imgic21, "New", "New modeling", 'N'); + actions[ACT_NEW_PROJECT] = new TAction("new-project-command", "New project", IconManager.imgic20, IconManager.imgic21, "New project", "New project", 0); actions[ACT_NEW_DESIGN] = new TAction("new-command-design", "New design", IconManager.imgic14, IconManager.imgic14, "New design", "New TURTLE design", 0); actions[ACT_NEW_ANALYSIS] = new TAction("new-command-analysis", "New analysis", IconManager.imgic17, IconManager.imgic17, "New analysis", "New TURTLE analysis", 0); actions[ACT_OPEN] = new TAction("open-command","Open", IconManager.imgic22, IconManager.imgic23, "Open", "Open an existing TTool model",'O', true); + actions[ACT_OPEN_PROJECT] = new TAction("open-project-command","Open project", IconManager.imgic22, IconManager.imgic23, "Open project", "Open an existing TTool project",'O', true); actions[ACT_OPEN_FROM_NETWORK] = new TAction("open-command-from-network","Open from TTool repository", IconManager.imgic22, IconManager.imgic23, "Open from TTool repository", "Open an existing TTool model from the TTool repository (TTool website)",'0', true); actions[ACT_OPEN_LAST] = new TAction("openlast-command","Open file: " + ConfigurationTTool.LastOpenFile, IconManager.imgic22, IconManager.imgic23, "Open: " + ConfigurationTTool.LastOpenFile, "Open the lastly saved TTool model", 0); actions[ACT_MERGE] = new TAction("merge-command","Merge", IconManager.imgic22, IconManager.imgic23, "Merge", "Merge the current TTool modeling with another one saved in a file ", 0); diff --git a/src/main/java/ui/diplodocusmethodology/DiplodocusMethodologyDiagramReferenceToApplication.java b/src/main/java/ui/diplodocusmethodology/DiplodocusMethodologyDiagramReferenceToApplication.java index 18bf5bda3dae4103a970bd099e2a6d94a3df99c4..a0a07e012901a1a92aa67d41331e59f96ae043b5 100755 --- a/src/main/java/ui/diplodocusmethodology/DiplodocusMethodologyDiagramReferenceToApplication.java +++ b/src/main/java/ui/diplodocusmethodology/DiplodocusMethodologyDiagramReferenceToApplication.java @@ -41,8 +41,7 @@ package ui.diplodocusmethodology; - -import common.ConfigurationTTool; +import common.SpecConfigTTool; import myutil.TraceManager; import ui.*; import ui.window.JDialogSystemCGeneration; @@ -134,7 +133,7 @@ public class DiplodocusMethodologyDiagramReferenceToApplication extends Diplodoc case 2: if (tdp.getMGUI().checkModelingSyntax(diagramName, true)) { tdp.getMGUI().generateUPPAAL(false); - boolean result = tdp.getMGUI().gtm.generateUPPAALFromTML(ConfigurationTTool.UPPAALCodeDirectory, false, 8, false); + boolean result = tdp.getMGUI().gtm.generateUPPAALFromTML(SpecConfigTTool.UPPAALCodeDirectory, false, 8, false); if (!result) { giveInformation("UPPAAL Generation failed"); return false; diff --git a/src/main/java/ui/graph/AUTGraphDisplay.java b/src/main/java/ui/graph/AUTGraphDisplay.java index 026b62957bc435fe3f5ef0f03b72515534a5b71f..ddaf61d08fc05aff7306e9723cb1c1fa6000cc90 100755 --- a/src/main/java/ui/graph/AUTGraphDisplay.java +++ b/src/main/java/ui/graph/AUTGraphDisplay.java @@ -47,6 +47,7 @@ import org.graphstream.graph.implementations.MultiGraph; import org.graphstream.ui.view.*; import org.graphstream.ui.view.Viewer; import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.util.IconManager; import ui.file.PNGFilter; @@ -438,8 +439,8 @@ public class AUTGraphDisplay implements MouseListener, ViewerListener, Runnable public void screenshot() { TraceManager.addDev("Screenshot"); JFileChooser jfcggraph; - if (ConfigurationTTool.GGraphPath.length() > 0) { - jfcggraph = new JFileChooser(ConfigurationTTool.GGraphPath); + if (SpecConfigTTool.GGraphPath.length() > 0) { + jfcggraph = new JFileChooser(SpecConfigTTool.GGraphPath); } else { jfcggraph = new JFileChooser(); } diff --git a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java index a34610cc56ce8153b68bd8dd44dcd4317d74ceb4..b0163e7142feca335eae7d12bf593bc55498ccc0 100755 --- a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java +++ b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java @@ -39,6 +39,7 @@ package ui.interactivesimulation; import common.ConfigurationTTool; +import common.SpecConfigTTool; import launcher.LauncherException; import launcher.RshClient; import myutil.*; @@ -527,7 +528,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene jp02.add(new JLabel("Directory:"), c01); saveDirName = new JTextField(30); if (ConfigurationTTool.SystemCCodeDirectory != null) { - saveDirName.setText(ConfigurationTTool.SystemCCodeDirectory); + saveDirName.setText(SpecConfigTTool.SystemCCodeDirectory); } jp02.add(saveDirName, c01); jp02.add(new JLabel("File name:"), c01); @@ -2481,8 +2482,14 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene final String directory = saveDirName.getText().trim(); if ( !directory.isEmpty() ) { - filename = directory + File.separator + filename; + if (!directory.endsWith(File.separator)) + filename = directory + File.separator + filename; + else + filename = directory + filename; } + + SpecConfigTTool.ExternalCommand1 = SpecConfigTTool.ExternalCommand1.replace(SpecConfigTTool.lastVCD, filename); + SpecConfigTTool.lastVCD = filename; // DB: now useless check // if (param.length() >0) { diff --git a/src/main/java/ui/networkmodelloader/JDialogLoadingNetworkModel.java b/src/main/java/ui/networkmodelloader/JDialogLoadingNetworkModel.java index 7df0e332660f71c9d126d5fc3a26dd9b339f3b0c..6820f27f1842d5b4b942273c54880b5b445327d8 100644 --- a/src/main/java/ui/networkmodelloader/JDialogLoadingNetworkModel.java +++ b/src/main/java/ui/networkmodelloader/JDialogLoadingNetworkModel.java @@ -43,13 +43,14 @@ package ui.networkmodelloader; import java.awt.*; import java.awt.event.*; -import java.io.File; import java.util.*; import javax.swing.*; import java.io.*; import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.*; +import ui.file.TFileFilter; import myutil.*; import ui.util.IconManager; @@ -96,6 +97,7 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac private String url; private NetworkModelPanel panel; private String filePath; + private JFileChooser jfc; /** Creates new form */ @@ -123,6 +125,13 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac protected void myInitComponents() { + + if (ConfigurationTTool.DownloadedFILEPath.length() > 0) { + jfc = new JFileChooser(ConfigurationTTool.DownloadedFILEPath); + } else { + jfc = new JFileChooser(); + } + mode = NOT_LISTED; setButtons(); } @@ -355,14 +364,18 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac jta.append("Loading model: " + fileName); String urlToLoad = URLManager.getBaseURL(url) + fileName; URLManager urlm = new URLManager(); - if ((ConfigurationTTool.DownloadedFILEPath == null) || (ConfigurationTTool.DownloadedFILEPath.length() == 0)) { - filePath = fileName; - } else { - filePath = ConfigurationTTool.DownloadedFILEPath + "/" + fileName; - } - boolean ok = urlm.downloadFile(filePath, urlToLoad,this); - if (!ok) { - loadFailed(); + jfc.setSelectedFile(new File(FileUtils.removeFileExtension(fileName))); + int returnVal = jfc.showSaveDialog(f); + if(returnVal == JFileChooser.APPROVE_OPTION) { + filePath = jfc.getSelectedFile().getAbsolutePath(); + filePath = FileUtils.addFileExtensionIfMissing(filePath, "xml"); + boolean ok = urlm.downloadFile(filePath, urlToLoad,this); + if (!ok) { + loadFailed(); + } + } + else { + panel.reactivateSelection(); } } @@ -370,15 +383,33 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac public void loadDone() { jta.append("Model transfered, opening it in TTool\n"); this.dispose(); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - mgui.openProjectFromFile(new File(filePath)); - // Here, we can safely update the GUI - // because we'll be called from the - // event dispatch thread - //statusLabel.setText("Query: " + queryNo); - } - }); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + File dir = new File(filePath.replace(".xml", "")); + dir = FileUtils.addFileExtensionIfMissing(dir, "ttool"); + dir.mkdir(); + SpecConfigTTool.setDirConfig(dir); + File config = SpecConfigTTool.createProjectConfig(dir); + try { + SpecConfigTTool.loadConfigFile(config); + } catch (MalformedConfigurationException e) { + System.err.println(e.getMessage() + " : Can't load config file."); + } + File file = new File(filePath); + file = FileUtils.addFileExtensionIfMissing(file, TFileFilter.getExtension()); + try { + FileUtils.moveFileToDirectory(file, dir, false); + } catch (IOException e) { + System.err.println(e.getMessage() + " : Network loading failed"); + } + mgui.openProjectFromFile(dir); + // Here, we can safely update the GUI + // because we'll be called from the + // event dispatch thread + //statusLabel.setText("Query: " + queryNo); + } + }); //mgui.openProjectFromFile(new File(filePath)); } diff --git a/src/main/java/ui/sysmlsecmethodology/SysmlsecMethodologyReferenceToApplication.java b/src/main/java/ui/sysmlsecmethodology/SysmlsecMethodologyReferenceToApplication.java index fbdddb5e79dd734f70f214f45d4c7bca8baaa0ee..458e25bf47bf958e3246c888c372cac2016af043 100755 --- a/src/main/java/ui/sysmlsecmethodology/SysmlsecMethodologyReferenceToApplication.java +++ b/src/main/java/ui/sysmlsecmethodology/SysmlsecMethodologyReferenceToApplication.java @@ -41,8 +41,7 @@ package ui.sysmlsecmethodology; - -import common.ConfigurationTTool; +import common.SpecConfigTTool; import myutil.TraceManager; import ui.*; import ui.window.JDialogSystemCGeneration; @@ -133,7 +132,7 @@ public class SysmlsecMethodologyReferenceToApplication extends SysmlsecMethodolo case 3: if (tdp.getMGUI().checkModelingSyntax(diagramName, true)) { tdp.getMGUI().generateUPPAAL(false); - boolean result = tdp.getMGUI().gtm.generateUPPAALFromTML(ConfigurationTTool.UPPAALCodeDirectory, false, 8, false); + boolean result = tdp.getMGUI().gtm.generateUPPAALFromTML(SpecConfigTTool.UPPAALCodeDirectory, false, 8, false); if (!result) { giveInformation("UPPAAL Generation failed"); return false; diff --git a/src/main/java/ui/window/JDialogAvatarExecutableCodeGeneration.java b/src/main/java/ui/window/JDialogAvatarExecutableCodeGeneration.java index 0b3222f149788f59a2b66fffbf2e053418e7cd04..cbb4f90c6352fac3cfceb471d9df84d4da3db248 100644 --- a/src/main/java/ui/window/JDialogAvatarExecutableCodeGeneration.java +++ b/src/main/java/ui/window/JDialogAvatarExecutableCodeGeneration.java @@ -151,15 +151,12 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JFrame im f = _f; mgui = _mgui; - if (pathCode == null) { - pathCode = _pathCode; - } - if (pathCompiler == null) - pathCompiler = _pathCompiler; + pathCode = _pathCode; + + pathCompiler = _pathCompiler; - if (pathExecute == null) - pathExecute = _pathExecute; + pathExecute = _pathExecute; if (pathCompileSoclib == null) { pathCompileSoclib = _pathCompilerSoclib; @@ -354,7 +351,7 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JFrame im exetrace.addActionListener(this); exegroup.add(exetrace); jp03.add(exetrace, c03); - exe3 = new JTextField(pathExecute + " " + pathCode + File.separator + "trace.txt", 100); + exe3 = new JTextField(pathExecute + " " + pathCode + "trace.txt", 100); jp03.add(exe3, c03); exesoclib = new JRadioButton(textSysC6, false); @@ -394,7 +391,7 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JFrame im viewgroup.add(viewtrace); viewtrace.addActionListener(this); jp04.add(viewtrace, c04); - simulationTraceFile = new JTextField(pathCode + File.separator + "trace.txt", 100); + simulationTraceFile = new JTextField(pathCode + "trace.txt", 100); jp04.add(simulationTraceFile, c04); viewtracesoclib = new JRadioButton(textSysC9, false); viewgroup.add(viewtracesoclib); diff --git a/src/main/java/ui/window/JDialogAvatarddExecutableCodeGeneration.java b/src/main/java/ui/window/JDialogAvatarddExecutableCodeGeneration.java index e7adc83934815e979e0eb166aadc16d5b79445a9..9698af393903271af56d8d5bc9be6585af618471 100755 --- a/src/main/java/ui/window/JDialogAvatarddExecutableCodeGeneration.java +++ b/src/main/java/ui/window/JDialogAvatarddExecutableCodeGeneration.java @@ -354,7 +354,7 @@ public class JDialogAvatarddExecutableCodeGeneration extends javax.swing.JFrame viewgroup.add(viewtrace); viewtrace.addActionListener(this); jp04.add(viewtrace, c04); - simulationTraceFile = new JTextField(pathCode + File.separator + "trace.txt", 100); + simulationTraceFile = new JTextField(pathCode + "trace.txt", 100); jp04.add(simulationTraceFile, c04); viewtracesoclib = new JRadioButton(textSysC6, false); viewgroup.add(viewtracesoclib); diff --git a/src/main/java/ui/window/JDialogBisimulation.java b/src/main/java/ui/window/JDialogBisimulation.java index 0dddc94a1e760d83ea8a501b5dbc67cdaeaf436f..7eacbd50e3e23bfb8110424c11c8a35eb28b2b6b 100755 --- a/src/main/java/ui/window/JDialogBisimulation.java +++ b/src/main/java/ui/window/JDialogBisimulation.java @@ -45,7 +45,7 @@ import launcher.LauncherException; import launcher.RshClient; import myutil.FileUtils; import myutil.ScrolledJTextArea; -import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.util.IconManager; import ui.file.AUTFileFilter; @@ -278,8 +278,8 @@ public class JDialogBisimulation extends JDialog implements ActionListener, Runn private String selectFile() { JFileChooser jfc; - if (ConfigurationTTool.TGraphPath.length() > 0) { - jfc = new JFileChooser(ConfigurationTTool.TGraphPath); + if (SpecConfigTTool.TGraphPath.length() > 0) { + jfc = new JFileChooser(SpecConfigTTool.TGraphPath); } else { jfc = new JFileChooser(); } diff --git a/src/main/java/ui/window/JDialogBisimulationBisimulator.java b/src/main/java/ui/window/JDialogBisimulationBisimulator.java index 23f8f049ece49a67ef20ed9de0bdb04ba0849077..a30b1e8f569424457b877080279653ff91d7d950 100755 --- a/src/main/java/ui/window/JDialogBisimulationBisimulator.java +++ b/src/main/java/ui/window/JDialogBisimulationBisimulator.java @@ -45,7 +45,7 @@ import launcher.LauncherException; import launcher.RshClient; import myutil.FileUtils; import myutil.ScrolledJTextArea; -import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.util.IconManager; import ui.file.AUTFileFilter; import ui.file.BCGFileFilter; @@ -326,8 +326,8 @@ public class JDialogBisimulationBisimulator extends JDialog implements ActionLis private String selectFile() { JFileChooser jfc; - if (ConfigurationTTool.TGraphPath.length() > 0) { - jfc = new JFileChooser(ConfigurationTTool.TGraphPath); + if (SpecConfigTTool.TGraphPath.length() > 0) { + jfc = new JFileChooser(SpecConfigTTool.TGraphPath); } else { jfc = new JFileChooser(); } diff --git a/src/main/java/ui/window/JDialogCCodeGeneration.java b/src/main/java/ui/window/JDialogCCodeGeneration.java index 6bd1a75aff6bc4b244a9bfe35af114b4f00c1911..88861b5cc865a17bac6cd00f29ec5cdf9c0b7796 100755 --- a/src/main/java/ui/window/JDialogCCodeGeneration.java +++ b/src/main/java/ui/window/JDialogCCodeGeneration.java @@ -138,12 +138,9 @@ public class JDialogCCodeGeneration extends JDialog implements ActionListener, R mgui = _mgui; gtm = _gtm; - if (pathCode == null) { - pathCode = _pathCode; - } - - if (pathCompiler == null) - pathCompiler = _pathCompiler; + pathCode = _pathCode; + + pathCompiler = _pathCompiler; initComponents(); myInitComponents(); diff --git a/src/main/java/ui/window/JDialogGenAUTS.java b/src/main/java/ui/window/JDialogGenAUTS.java index 4a73ab84a6367444ec415eff6b4fb6bfc85c2f09..33501d098f77b8d2dccea8e02dbc8ac574fa8e7d 100755 --- a/src/main/java/ui/window/JDialogGenAUTS.java +++ b/src/main/java/ui/window/JDialogGenAUTS.java @@ -46,6 +46,7 @@ import launcher.RshClient; import myutil.ScrolledJTextArea; import myutil.SortedVector; import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.util.IconManager; import ui.MainGUI; @@ -314,7 +315,7 @@ public class JDialogGenAUTS extends JDialog implements ActionListener, Runnable } if (fc2.isSelected()) { - String path = ConfigurationTTool.GGraphPath; + String path = SpecConfigTTool.GGraphPath; if ((path == null) || (path.length() == 0)) { path = new File("").getAbsolutePath(); } diff --git a/src/main/java/ui/window/JDialogGraphModification.java b/src/main/java/ui/window/JDialogGraphModification.java index 39233674b68faa45843b30255f7f3472b8ec5b1f..3c85a4916d23b9a29d2a0552b9f924449bba0548 100755 --- a/src/main/java/ui/window/JDialogGraphModification.java +++ b/src/main/java/ui/window/JDialogGraphModification.java @@ -45,7 +45,7 @@ import launcher.LauncherException; import launcher.RshClient; import myutil.FileUtils; import myutil.ScrolledJTextArea; -import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.util.IconManager; import ui.file.AUTFileFilter; import ui.graph.AUTMappingGraph; @@ -324,8 +324,8 @@ public class JDialogGraphModification extends JDialog implements ActionListener, private String selectFile() { JFileChooser jfc; - if (ConfigurationTTool.TGraphPath.length() > 0) { - jfc = new JFileChooser(ConfigurationTTool.TGraphPath); + if (SpecConfigTTool.TGraphPath.length() > 0) { + jfc = new JFileChooser(SpecConfigTTool.TGraphPath); } else { jfc = new JFileChooser(); } diff --git a/src/main/java/ui/window/JDialogPerformancePragma.java b/src/main/java/ui/window/JDialogPerformancePragma.java index bbdbc847e401a372a78b68dffe3535214b785837..d4e0979e3a6eca6ee3b355dd569ea2d4078eae59 100644 --- a/src/main/java/ui/window/JDialogPerformancePragma.java +++ b/src/main/java/ui/window/JDialogPerformancePragma.java @@ -262,43 +262,41 @@ public class JDialogPerformancePragma extends JDialogBase implements ActionListe Font f = new Font("Helvetica", Font.PLAIN, 14); setFont(f); c.setLayout(new BorderLayout()); - //setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - + //setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + helpPopup = new JPopupMenu(); - //JTextArea jft = new JTextArea("UPPAAL pragmas"); - //helpPopup.add(jft); - JLabel t = new JLabel(""); - JLabel header= new JLabel(" Performance Pragma"); - Font headerFont=new Font(t.getFont().getName(),Font.BOLD,t.getFont().getSize()+2); - header.setFont(headerFont); - helpPopup.add(header); - //Text - helpPopup.add(new JLabel(" Performance Pragma allow us to query and record ")); - helpPopup.add(new JLabel(" the latency (in cycles) between two events after simulation")); - helpPopup.add(new JLabel(" Depending on the format of the pragma, results can be the")); - helpPopup.add(new JLabel(" numeric average latency value or a verified true/false result")); - - JLabel example =new JLabel(" Examples:"); - example.setFont(headerFont); - helpPopup.add(example); - - Font exFont=new Font(t.getFont().getName(),Font.ITALIC,t.getFont().getSize()); - JLabel t1 = new JLabel(" Latency(block1.state1, block2.s)<10"); - t1.setFont(exFont); - helpPopup.add(t1); - helpPopup.add(new JLabel(" Will be marked with a green check mark or ")); - helpPopup.add(new JLabel(" red cross depending on simulation results")); - - JLabel t2 = new JLabel(" Latency(block1.state1, block2.s)?"); - t2.setFont(exFont); - helpPopup.add(t2); - - helpPopup.add(new JLabel(" Will be marked with the average latency")); - helpPopup.add(new JLabel(" time after simulation")); - helpPopup.setPreferredSize(new Dimension(600,250)); - - - + //JTextArea jft = new JTextArea("UPPAAL pragmas"); + //helpPopup.add(jft); + JLabel t = new JLabel(""); + JLabel header= new JLabel(" Performance Pragma"); + Font headerFont=new Font(t.getFont().getName(),Font.BOLD,t.getFont().getSize()+2); + header.setFont(headerFont); + helpPopup.add(header); + //Text + helpPopup.add(new JLabel(" Performance Pragma allow us to query and record ")); + helpPopup.add(new JLabel(" the latency (in cycles) between two events after simulation")); + helpPopup.add(new JLabel(" Depending on the format of the pragma, results can be the")); + helpPopup.add(new JLabel(" numeric average latency value or a verified true/false result")); + + JLabel example =new JLabel(" Examples:"); + example.setFont(headerFont); + helpPopup.add(example); + + Font exFont=new Font(t.getFont().getName(),Font.ITALIC,t.getFont().getSize()); + JLabel t1 = new JLabel(" Latency(block1.state1, block2.s)<10:"); + t1.setFont(exFont); + helpPopup.add(t1); + helpPopup.add(new JLabel(" Will be marked with a green check mark or ")); + helpPopup.add(new JLabel(" red cross depending on simulation results")); + + JLabel t2 = new JLabel(" Latency(block1.state1, block2.s)?:"); + t2.setFont(exFont); + helpPopup.add(t2); + + helpPopup.add(new JLabel(" Will be marked with the average latency")); + helpPopup.add(new JLabel(" time after simulation")); + helpPopup.setPreferredSize(new Dimension(600,250)); + textarea = new JTextArea(); textarea.setEditable(true); diff --git a/src/main/java/ui/window/JDialogProverifVerification.java b/src/main/java/ui/window/JDialogProverifVerification.java index b2076a7d1f47f9b95bde7cd36a3ca6d8ed8149a6..0a9b4738716f005f0b5da88cc0e8384e7aabb814 100644 --- a/src/main/java/ui/window/JDialogProverifVerification.java +++ b/src/main/java/ui/window/JDialogProverifVerification.java @@ -48,6 +48,8 @@ import avatartranslator.AvatarPragmaSecret; import launcher.LauncherException; import launcher.RshClient; import launcher.RshClientReader; +import myutil.FileException; +import myutil.FileUtils; import myutil.GraphicLib; import myutil.MasterProcessInterface; import myutil.TraceManager; @@ -201,9 +203,8 @@ public class JDialogProverifVerification extends JDialog implements ActionListen this.adp = adp; this.pvoa = null; this.limit=lim; - if (pathCode == null) { - pathCode = _pathCode; - } + + pathCode = _pathCode; if (pathExecute == null) pathExecute = _pathExecute; @@ -798,17 +799,15 @@ public class JDialogProverifVerification extends JDialog implements ActionListen testGo(); pathCode = code1.getText().trim (); - if (pathCode.isEmpty() || pathCode.endsWith(File.separator)) { + if (pathCode.isEmpty()) { pathCode += "pvspec"; } + + FileUtils.checkAndCreateProverifDir(pathCode); + pathCode += "pvspec"; testFile = new File(pathCode); - - if (testFile.isDirectory()){ - pathCode += File.separator; - pathCode += "pvspec"; - testFile = new File(pathCode); - } + File dir = testFile.getParentFile(); @@ -872,6 +871,8 @@ public class JDialogProverifVerification extends JDialog implements ActionListen mode = STOPPED; } catch (InterruptedException ie) { mode = NOT_STARTED; + } catch (FileException e) { + System.err.println(e.getMessage() + " : Can't generate proverif file."); } catch (Exception e) { mode = STOPPED; throw e; diff --git a/src/main/java/ui/window/JDialogSearchBox.java b/src/main/java/ui/window/JDialogSearchBox.java index 970654be3e7e007dd0c10a45459c463e83ef3f45..0554dc05ae7f2427364bb53c40ceeb0bed66b319 100644 --- a/src/main/java/ui/window/JDialogSearchBox.java +++ b/src/main/java/ui/window/JDialogSearchBox.java @@ -810,6 +810,8 @@ public class JDialogSearchBox extends javax.swing.JFrame { dbaddress=jTextaddressDB.getText().split(":")[0]; dbport=Integer.parseInt(jTextaddressDB.getText().split(":")[1]); try { + if (tdmm.getTdp().getMainGUI().getDir() != null) + tdmm.getTdp().getMainGUI().saveConfig(); ConfigurationTTool.saveConfiguration(); } catch (MalformedConfigurationException e) { e.printStackTrace(); diff --git a/src/main/java/ui/window/JDialogSystemCGeneration.java b/src/main/java/ui/window/JDialogSystemCGeneration.java index fed047dd55973174842a154d854c79fba5ba51dc..9a5cef376fdc967cfef67a767ad78ad348f98926 100755 --- a/src/main/java/ui/window/JDialogSystemCGeneration.java +++ b/src/main/java/ui/window/JDialogSystemCGeneration.java @@ -57,6 +57,10 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; + +import common.ConfigurationTTool; +import common.SpecConfigTTool; + import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -155,31 +159,25 @@ public class JDialogSystemCGeneration extends JDialog implements ActionListener, mgui = _mgui; - if (pathCode == null) { - pathCode = _pathCode; - } - - if (pathCompiler == null) - pathCompiler = _pathCompiler; + pathCode = _pathCode; + + pathCompiler = _pathCompiler; - if (pathExecute == null) - pathExecute = _pathExecute; + pathExecute = _pathExecute; - if (pathInteractiveExecute == null) { - if (_graphPath != null) { - _pathInteractiveExecute += " -gpath " + _graphPath; - } - pathInteractiveExecute = _pathInteractiveExecute; + if (_graphPath != null) { + _pathInteractiveExecute += " -gpath " + _graphPath; } + pathInteractiveExecute = _pathInteractiveExecute; + - if (pathFormalExecute == null) { - pathFormalExecute = pathInteractiveExecute; + pathFormalExecute = pathInteractiveExecute; - int index = pathFormalExecute.indexOf("-server"); - if (index != -1) { - pathFormalExecute = pathFormalExecute.substring(0, index) + pathFormalExecute.substring(index+7, pathFormalExecute.length()); - pathFormalExecute += " -gname graph -explo"; - } + int index = pathFormalExecute.indexOf("-server"); + if (index != -1) { + pathFormalExecute = pathFormalExecute.substring(0, index) + pathFormalExecute.substring(index+7, pathFormalExecute.length()); + pathFormalExecute += " -gname graph -explo"; + } simulatorHost = _simulatorHost; @@ -771,6 +769,8 @@ public class JDialogSystemCGeneration extends JDialog implements ActionListener, jta.append("Saving C++ files...\n"); pathCode = code1.getText(); + if (!FileUtils.checkAndCreateSystemCDir(SpecConfigTTool.SystemCCodeDirectory)) + throw new Throwable(); tml2systc.saveFile(pathCode, "appmodel"); jta.append( "C++ files saved." + System.lineSeparator() ); @@ -874,6 +874,9 @@ public class JDialogSystemCGeneration extends JDialog implements ActionListener, switch(toDo) { case ONE_TRACE: executeSimulationCmd(exe2.getText(), "Generating one simulation trace"); + String[] tab = exe2.getText().split(" "); + SpecConfigTTool.lastVCD = tab[2]; + SpecConfigTTool.ExternalCommand1 = "gtkwave " + SpecConfigTTool.lastVCD; break; case ANIMATION: dispose(); diff --git a/src/main/java/ui/window/JDialogUPPAALGeneration.java b/src/main/java/ui/window/JDialogUPPAALGeneration.java index 76dfca83a5933e1d25803f8384c6f7e2160c13ec..4727810db12d97c0bc1962f8f435b7b14f39c46d 100755 --- a/src/main/java/ui/window/JDialogUPPAALGeneration.java +++ b/src/main/java/ui/window/JDialogUPPAALGeneration.java @@ -109,9 +109,7 @@ public class JDialogUPPAALGeneration extends JDialog implements ActionListener, mgui = _mgui; - if (pathCode == null) { - pathCode = _pathCode; - } + pathCode = _pathCode; editionMode = _mode; diff --git a/src/main/java/ui/window/JFramePowerManagementAnalysis.java b/src/main/java/ui/window/JFramePowerManagementAnalysis.java index 0188de7e81222b377de5f89f03caf04566cd20b2..ed1c1b57cf28ec586ad9c8f8c2ca6cda25bafe11 100755 --- a/src/main/java/ui/window/JFramePowerManagementAnalysis.java +++ b/src/main/java/ui/window/JFramePowerManagementAnalysis.java @@ -45,6 +45,7 @@ import myutil.FileException; import myutil.GraphicLib; import myutil.ScrolledJTextArea; import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.FormatManager; import ui.util.IconManager; import ui.StoppableGUIElement; @@ -423,9 +424,11 @@ public class JFramePowerManagementAnalysis extends JFrame implements ActionListe if (ret == 0) { jta.append("VCD generated... \n"); //System.out.println(generator.getVCDString()); - jta.append("Saving VCD in " + ConfigurationTTool.VCDPath + "spec.vcd \n"); + jta.append("Saving VCD in " + SpecConfigTTool.VCDPath + "spec.vcd \n"); try { - generator.saveInFile(ConfigurationTTool.VCDPath, "spec.vcd"); + generator.saveInFile(SpecConfigTTool.VCDPath, "spec.vcd"); + SpecConfigTTool.lastVCD = SpecConfigTTool.VCDPath + "spec.vcd"; + SpecConfigTTool.ExternalCommand1 = "gtkwave " + SpecConfigTTool.lastVCD; } catch (FileException fe) { jta.append("Saving in file failed: " + fe.getMessage() + "\n"); } diff --git a/src/main/java/ui/window/JFrameRequirementTable.java b/src/main/java/ui/window/JFrameRequirementTable.java index c93805ed0182595229e858eb0bc576213c8e3662..f75637f2d339c38f8330324057831d5d8f8d3e4c 100755 --- a/src/main/java/ui/window/JFrameRequirementTable.java +++ b/src/main/java/ui/window/JFrameRequirementTable.java @@ -39,6 +39,7 @@ package ui.window; import common.ConfigurationTTool; +import common.SpecConfigTTool; import myutil.*; import ui.*; import ui.avatarrd.AvatarRDPanel; @@ -214,7 +215,7 @@ public class JFrameRequirementTable extends JFrame implements ActionListener /*, } else if (evt.getSource() == buttonGenerate) { // Issue #32 Improve document generation - final File genFile = new File( ConfigurationTTool.DocGenPath ); + final File genFile = new File( SpecConfigTTool.DocGenPath ); String path; try { @@ -250,8 +251,8 @@ public class JFrameRequirementTable extends JFrame implements ActionListener /*, TraceManager.addDev("HTML code:" + s); String path; - if (ConfigurationTTool.DocGenPath.length() > 0) { - path = ConfigurationTTool.DocGenPath + "/"; + if (SpecConfigTTool.DocGenPath.length() > 0) { + path = SpecConfigTTool.DocGenPath + "/"; } else { path = ""; } diff --git a/src/main/java/ui/window/JFrameStatistics.java b/src/main/java/ui/window/JFrameStatistics.java index c946ec3c1293f3f94540d15d4136caea13089c9f..a19ee81a7ebf87fb7d532f0440311c805e37715e 100755 --- a/src/main/java/ui/window/JFrameStatistics.java +++ b/src/main/java/ui/window/JFrameStatistics.java @@ -45,7 +45,7 @@ import automata.Automata; import automata.State; import automata.Transition; import myutil.*; -import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.util.IconManager; import ui.StoppableGUIElement; import ui.ThreadGUIElement; @@ -583,8 +583,8 @@ public class JFrameStatistics extends JFrame implements ActionListener, Stoppab private void saveAutomata(Automata aut) { // Select file JFileChooser jfc; - if (ConfigurationTTool.TGraphPath.length() > 0) { - jfc = new JFileChooser(ConfigurationTTool.TGraphPath); + if (SpecConfigTTool.TGraphPath.length() > 0) { + jfc = new JFileChooser(SpecConfigTTool.TGraphPath); } else { jfc = new JFileChooser(); } diff --git a/ttool/launch_configurations/TTool.launch b/ttool/launch_configurations/TTool.launch index 5f9a19dffbd35fd932a9c251c762940339c25e66..e08418c4f7c26d566d4a314c7a1f5670962ca003 100644 --- a/ttool/launch_configurations/TTool.launch +++ b/ttool/launch_configurations/TTool.launch @@ -14,6 +14,6 @@ </listAttribute> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="Main"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-debug -config ./launch_configurations/config.xml"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-debug -config ./runtime/config.xml"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="ttool"/> </launchConfiguration> diff --git a/ttool/launch_configurations/config.xml b/ttool/launch_configurations/config.xml index 1a3310b028af528b4324d49e3715560b54f8100d..136c01167ff8e9f377ddd9ba20264862882a46c6 100755 --- a/ttool/launch_configurations/config.xml +++ b/ttool/launch_configurations/config.xml @@ -37,7 +37,7 @@ <SystemCCodeCompileCommand data="make -C ../simulators/c++2/" /> <SystemCCodeExecuteCommand data="../simulators/c++2/run.x -ovcd ../simulators/c++2/vcddump.vcd" /> <SystemCCodeInteractiveExecuteCommand data="../simulators/c++2/run.x -server" /> -<TMLCodeDirectory data="../simulators/c++2/tmlcode" /> +<TMLCodeDirectory data="../tmlcode/" /> <CCodeDirectory data="../CCode" /> <GTKWavePath data="/opt/local/bin/gtkwave" /> <VCDPath data="../simulators/c++2/" /> @@ -47,19 +47,19 @@ <UPPAALPropertyVerifMessage data="Formula is satisfied"/> <UPPAALPropertyNotVerifMessage data="Formula is NOT satisfied"/> <ProVerifCodeDirectory data="../proverif/" /> -<ProVerifVerifierPath data="/packages/proverif/proverif" /> +<ProVerifVerifierPath data="../../proverif" /> <ProVerifVerifierHost data="localhost" /> <AVATARExecutableCodeDirectory data="../executablecode/" /> <AVATARMPSoCCodeDirectory data="../MPSoC/" /> -<AVATARMPSoCCompileCommand data="make -C ../MPSoC updateruntime updategeneratedcode compilesoclib" /> +<AVATARMPSoCCompileCommand data="make -C ../MPSoC/ updateruntime updategeneratedcode compilesoclib" /> <AVATARExecutableCodeHost data="localhost"/> -<AVATARExecutableCodeCompileCommand data="make -C ../executablecode" /> +<AVATARExecutableCodeCompileCommand data="make -C ../executablecode/" /> <AVATARExecutableCodeExecuteCommand data="../executablecode/run.x" /> -<AVATARExecutableSoclibCodeCompileCommand data="make -C ../MPSoC updategeneratedcode compilesoclib" /> -<AVATARExecutableSoclibCodeExecuteCommand data="make -C ../MPSoC runsoclib" /> -<AVATARExecutableSoclibCodeTraceCommand data="make -C ../MPSoC runsoclib-trace" /> +<AVATARExecutableSoclibCodeCompileCommand data="make -C ../MPSoC/ updategeneratedcode compilesoclib" /> +<AVATARExecutableSoclibCodeExecuteCommand data="make -C ../MPSoC/ runsoclib" /> +<AVATARExecutableSoclibCodeTraceCommand data="make -C ../MPSoC/ runsoclib-trace" /> <AVATARExecutableSoclibTraceFile data="../Prog/soclib/soclib/platform/topcells/caba-vgmn-mutekh_kernel_tutorial/trace" /> - +<NCDirectory data="../nc/"/> <ExternalCommand1Host data="localhost"/> <ExternalCommand1 data="gtkwave ../simulators/c++2/vcddump.vcd"/> @@ -68,12 +68,10 @@ <PLUGIN_JAVA_CODE_GENERATOR data="../plugins/CustomizerAvatarCodeGeneration.jar" /> -<LastOpenFile data="/home/dblouin/Projets/TTool/git/TTool/modeling/DIPLODOCUS/ZigBeeTutorial.xml"/> - - +<LastOpenFile data="/home/satan/TTool/modeling/DIPLODOCUS/ZigBeeTutorial.ttool"/> -<LastWindowAttributes x="65" y="24" width="1855" height="1056" max="true" /> +<LastWindowAttributes x="65" y="24" width="1301" height="744" max="true" /> -<ProVerifHash data="-2047053751"/> +<ProVerifHash data="1427594573"/> </TURTLECONFIGURATION> diff --git a/ttool/project_config.xml b/ttool/project_config.xml new file mode 100644 index 0000000000000000000000000000000000000000..b77779f27c36815b72b46e868bee37ba09fff8c7 --- /dev/null +++ b/ttool/project_config.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> + +<PROJECTCONFIGURATION> + <LastVCD data=""/> + <LastOpenDiagram tab="0" panel="0"/> +</PROJECTCONFIGURATION> diff --git a/ttool/runtime/config.xml b/ttool/runtime/config.xml index bc87937afe25b97fe3333247cac26914c6b5fbae..5ce160559cc2c3c3c9cbf5ce69892133e3d1bdba 100755 --- a/ttool/runtime/config.xml +++ b/ttool/runtime/config.xml @@ -37,7 +37,7 @@ <SystemCCodeCompileCommand data="make -C ../simulators/c++2/" /> <SystemCCodeExecuteCommand data="../simulators/c++2/run.x -ovcd ../simulators/c++2/vcddump.vcd" /> <SystemCCodeInteractiveExecuteCommand data="../simulators/c++2/run.x -server" /> -<TMLCodeDirectory data="../simulators/c++2/tmlcode" /> +<TMLCodeDirectory data="../tmlcode/" /> <CCodeDirectory data="../CCode" /> <GTKWavePath data="/opt/local/bin/gtkwave" /> <VCDPath data="../simulators/c++2/" /> @@ -45,19 +45,19 @@ <UPPAALVerifierPath data="/packages/uppaal-4.0.11/verifyta" /> <UPPAALVerifierHost data="localhost" /> <ProVerifCodeDirectory data="../proverif/" /> -<ProVerifVerifierPath data="/packages/proverif/proverif" /> +<ProVerifVerifierPath data="../../proverif" /> <ProVerifVerifierHost data="localhost" /> <AVATARExecutableCodeDirectory data="../executablecode/" /> <AVATARMPSoCCodeDirectory data="../MPSoC/" /> -<AVATARMPSoCCompileCommand data="make -C ../MPSoC updateruntime updategeneratedcode compilesoclib" /> +<AVATARMPSoCCompileCommand data="make -C ../MPSoC/ updateruntime updategeneratedcode compilesoclib" /> <AVATARExecutableCodeHost data="localhost"/> -<AVATARExecutableCodeCompileCommand data="make -C ../executablecode" /> +<AVATARExecutableCodeCompileCommand data="make -C ../executablecode/" /> <AVATARExecutableCodeExecuteCommand data="../executablecode/run.x" /> -<AVATARExecutableSoclibCodeCompileCommand data="make -C ../MPSoC updategeneratedcode compilesoclib" /> -<AVATARExecutableSoclibCodeExecuteCommand data="make -C ../MPSoC runsoclib" /> -<AVATARExecutableSoclibCodeTraceCommand data="make -C ../MPSoC runsoclib-trace" /> +<AVATARExecutableSoclibCodeCompileCommand data="make -C ../MPSoC/ updategeneratedcode compilesoclib" /> +<AVATARExecutableSoclibCodeExecuteCommand data="make -C ../MPSoC/ runsoclib" /> +<AVATARExecutableSoclibCodeTraceCommand data="make -C ../MPSoC/ runsoclib-trace" /> <AVATARExecutableSoclibTraceFile data="../Prog/soclib/soclib/platform/topcells/caba-vgmn-mutekh_kernel_tutorial/trace" /> - +<NCDirectory data="../nc/"/> <ExternalCommand1Host data="localhost"/> <ExternalCommand1 data="gtkwave ../simulators/c++2/vcddump.vcd"/> @@ -65,12 +65,12 @@ <ExternalCommand2 data="/packages/uppaal4.0.11/uppaal ../uppaal/spec.xml"/> -<LastOpenFile data=""/> +<LastOpenFile data="/home/satan/TTool/modeling/DIPLODOCUS/ZigBeeTutorial.ttool"/> -<LastWindowAttributes x="65" y="24" width="1295" height="640" max="true" /> +<LastWindowAttributes x="65" y="-4" width="1301" height="772" max="true" /> -<ProVerifHash data=""/> +<ProVerifHash data="1427594573"/> </TURTLECONFIGURATION> diff --git a/ttool/src/main/java/Main.java b/ttool/src/main/java/Main.java index 56efd2c3aa1d905696101bfe02a2e611fb669f28..25ce697c95c8bd57f175544dfca16985221530a7 100755 --- a/ttool/src/main/java/Main.java +++ b/ttool/src/main/java/Main.java @@ -46,6 +46,7 @@ import myutil.*; import common.ConfigurationTTool; +import common.SpecConfigTTool; import ui.*; import ui.util.DefaultText; import ui.util.IconManager; @@ -253,6 +254,7 @@ public class Main implements ActionListener { //ConfigurationTTool.makeDefaultConfiguration(); try { ConfigurationTTool.loadConfiguration(config, systemc); + SpecConfigTTool.setBasicConfigFile(config); } catch (Exception e) { System.out.println("Couldn't load configuration from file: " + config); } diff --git a/ttool/src/test/java/launcher/TestRshClient.java b/ttool/src/test/java/launcher/TestRshClient.java index 793d6136f89ebd847e137953f9cfb074887b1237..a6ab1e75a866c58b0bdf7609523e570311a6502f 100644 --- a/ttool/src/test/java/launcher/TestRshClient.java +++ b/ttool/src/test/java/launcher/TestRshClient.java @@ -25,7 +25,7 @@ public class TestRshClient { private static final String EXPECTED_COMMAND_OUTPUT = "!!!Hello World!!!" + System.lineSeparator(); private static final String TEST_PROGRAM_NAME = "helloWorld"; private static final String TEST_COMMAND = "./resources/launcher/" + TEST_PROGRAM_NAME; - private static final String TEST_COMMAND_NON_STOP = "./resources//launcher/helloWorldNonStop"; + private static final String TEST_COMMAND_NON_STOP = "./resources/launcher/helloWorldNonStop"; private static final String TEST_FILE_NAME = "./resources/launcher/test.txt"; private static final String TEST_FILE_DATA = "testDatafhkenomrcg ,jgh o";