From f22e86a6f43de7a81ede3f1997183fbf5242a3f7 Mon Sep 17 00:00:00 2001 From: Sophie Coudert <sophie.coudert@telecom-paris.fr> Date: Mon, 3 Mar 2025 14:40:09 +0000 Subject: [PATCH] Avatar sys ml 04 2024 (can now parse from file) --- .idea/uiDesigner.xml | 124 ++++++++++++++++++ .../avatartranslator/AvatarSpecification.java | 3 +- .../tosysmlv2/Avatar2SysMLCDElement.java | 92 +++++++++++++ .../tosysmlv2/AvatarFromSysML.java | 29 +++- src/main/java/cli/Action.java | 5 +- src/main/java/ui/GTURTLEModeling.java | 3 +- .../test/java/cli/CLIAvatar2SysMLV2Test.java | 11 +- 7 files changed, 250 insertions(+), 17 deletions(-) create mode 100644 .idea/uiDesigner.xml create mode 100644 src/main/java/avatartranslator/tosysmlv2/Avatar2SysMLCDElement.java diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000000..2b63946d5b --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Palette2"> + <group name="Swing"> + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> + </item> + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> + <initial-values> + <property name="text" value="Button" /> + </initial-values> + </item> + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="RadioButton" /> + </initial-values> + </item> + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="CheckBox" /> + </initial-values> + </item> + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="Label" /> + </initial-values> + </item> + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> + <preferred-size width="-1" height="20" /> + </default-constraints> + </item> + <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> + </item> + </group> + </component> +</project> \ No newline at end of file diff --git a/src/main/java/avatartranslator/AvatarSpecification.java b/src/main/java/avatartranslator/AvatarSpecification.java index 7cc291f051..4e4923458c 100644 --- a/src/main/java/avatartranslator/AvatarSpecification.java +++ b/src/main/java/avatartranslator/AvatarSpecification.java @@ -45,7 +45,6 @@ import myutil.Conversion; import myutil.NameChecker; import myutil.TraceManager; import myutil.intboolsolver.IBSParamSpec; -import org.apache.derby.iapi.types.DataType; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -1816,7 +1815,7 @@ public class AvatarSpecification extends AvatarElement implements IBSParamSpec { // SysML V2 public static AvatarSpecification makeFromSysMLV2(String pathToFile) { AvatarFromSysML builder = new AvatarFromSysML(); - return builder.sysMLtoSpec(pathToFile); + return builder.sysMLFiletoSpec(pathToFile); } public List<String> getExtraTypes() { diff --git a/src/main/java/avatartranslator/tosysmlv2/Avatar2SysMLCDElement.java b/src/main/java/avatartranslator/tosysmlv2/Avatar2SysMLCDElement.java new file mode 100644 index 0000000000..9dd5d78f60 --- /dev/null +++ b/src/main/java/avatartranslator/tosysmlv2/Avatar2SysMLCDElement.java @@ -0,0 +1,92 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.tosysmlv2; + +import ui.CDElement; +import ui.ICDElementVisitor; +import ui.TGCOneLineText; + +/** + * Interface CDElement + * Creation : 22/12/2003 + * @author Ludovic APVRILLE + */ +public class Avatar2SysMLCDElement implements CDElement { + private int x; + private int y; + private int height; + private int width; + + public int getX() { return x; } + + public int getY() { return y; } + + public void setCd(int _x, int _y) { x = _x; y = _y; } + + public int getWidth() { return height; } + + public int getHeight() { return width; } + + public void setUserResize(int desired_x, int desired_y, int desired_width, int desired_height) { + x = desired_x; + y = desired_y; + height = desired_height; + width = desired_width; + } + + // Unused, dummy implementation ========================================= + + public String getName() { return null; } + + public void acceptForward( ICDElementVisitor visitor ) {} + + public void acceptBackward( ICDElementVisitor visitor ) {} + + public boolean canBeDisabled() { return false; } + + public void setEnabled( boolean _enabled ) {} + + public void doSetEnabled( boolean _enabled ) {} + + public boolean isEnabled() { return false; } + + public boolean isEnabled( boolean checkBranch ) { return false; } + + public boolean canLabelBeDisabled( TGCOneLineText label ) { return false; } +} diff --git a/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysML.java b/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysML.java index bef2ad38c4..c2a18def68 100644 --- a/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysML.java +++ b/src/main/java/avatartranslator/tosysmlv2/AvatarFromSysML.java @@ -45,6 +45,7 @@ package avatartranslator.tosysmlv2; import java.io.FileReader; +import java.io.StringReader; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -120,7 +121,7 @@ public class AvatarFromSysML { /** Builds an Avatar Specification from an Avatar SysML V2 description provided in a file. * If errors are found, they are printed using TraceManager.addError before returning */ - public AvatarSpecification sysMLtoSpec(String _fileName) { + public AvatarSpecification sysMLFiletoSpec(String _fileName) { errors = new ArrayList<AvatarFromSysMLError>(); // Initialize parser AvatarFromSysMLParser parser; @@ -134,7 +135,29 @@ public class AvatarFromSysML { TraceManager.addError(errorMsg); return null; } - + return sysMLtoSpec(parser); + } + /** Builds an Avatar Specification from an Avatar SysML V2 description provided in a string. + * If errors are found, they are printed using TraceManager.addError before returning + */ + public AvatarSpecification sysMLStringtoSpec(String _string) { + errors = new ArrayList<AvatarFromSysMLError>(); + // Initialize parser + AvatarFromSysMLParser parser; + try { + parser = + new AvatarFromSysMLParser(new AvatarFromSysMLLexer(new StringReader(_string)), + new ComplexSymbolFactory()); + } catch (java.lang.Exception e) { + //e.printStackTrace(out); + String errorMsg = "cannot initialize parser from string "; + addError(new AvatarFromSysMLError(AvatarFromSysMLError.ERROR, errorMsg)); + TraceManager.addError(errorMsg); + return null; + } + return sysMLtoSpec(parser); + } + private AvatarSpecification sysMLtoSpec(AvatarFromSysMLParser parser) { // Run parser and get parser errors TraceManager.addDev("Parsing Model"); stxSpec = parser.parseModel(); @@ -269,6 +292,8 @@ public class AvatarFromSysML { getAttributeByName(_s.getVariable().replaceAll("\\.", "__"),_b), null, _b); break; case AvatarFromSysMLSyntax.STXSTOPSTATE : + addError(new AvatarFromSysMLError(AvatarFromSysMLError.BUG, null, + "adding stop state (AvatarFromSysML.getState)", null)); break; case AvatarFromSysMLSyntax.STXSENDSTATE : case AvatarFromSysMLSyntax.STXRECEIVESTATE : diff --git a/src/main/java/cli/Action.java b/src/main/java/cli/Action.java index 612eff7324..2014258850 100644 --- a/src/main/java/cli/Action.java +++ b/src/main/java/cli/Action.java @@ -63,7 +63,6 @@ import myutil.Conversion; import myutil.FileUtils; import myutil.PluginManager; import myutil.TraceManager; -import org.apache.batik.anim.timing.Trace; import proverifspec.ProVerifOutputAnalyzer; import proverifspec.ProVerifOutputListener; import proverifspec.ProVerifQueryAuthResult; @@ -71,7 +70,6 @@ import proverifspec.ProVerifQueryResult; import tmltranslator.*; import tmltranslator.mutations.ApplyDiplodocusMutationException; import tmltranslator.mutations.DiplodocusMutation; -import tmltranslator.mutations.DiplodocusMutationParser; import tmltranslator.mutations.ParseDiplodocusMutationException; import ui.MainGUI; import ui.atd.AttackTreeDiagramPanel; @@ -88,7 +86,6 @@ import java.awt.*; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -2482,7 +2479,7 @@ public class Action extends Command implements ProVerifOutputListener { } AvatarFromSysML builder = new AvatarFromSysML(); - AvatarSpecification tmpAs = builder.sysMLtoSpec(commands[0]); + AvatarSpecification tmpAs = builder.sysMLFiletoSpec(commands[0]); if (tmpAs != null) { as = tmpAs; diff --git a/src/main/java/ui/GTURTLEModeling.java b/src/main/java/ui/GTURTLEModeling.java index 149e9fc92f..77b0b1e490 100644 --- a/src/main/java/ui/GTURTLEModeling.java +++ b/src/main/java/ui/GTURTLEModeling.java @@ -52,7 +52,6 @@ import avatartranslator.tosysmlv2.AvatarFromSysMLError; import avatartranslator.totpn.AVATAR2TPN; import avatartranslator.toturtle.AVATAR2TURTLE; import avatartranslator.touppaal.AVATAR2UPPAAL; -import cli.Interpreter; import common.ConfigurationTTool; import common.SpecConfigTTool; import common.Tag; @@ -456,7 +455,7 @@ public class GTURTLEModeling { public boolean openSysMLV2(String fileName) { AvatarFromSysML builder = new AvatarFromSysML(); - AvatarSpecification tmpAs = builder.sysMLtoSpec(fileName); + AvatarSpecification tmpAs = builder.sysMLFiletoSpec(fileName); diff --git a/ttool/src/test/java/cli/CLIAvatar2SysMLV2Test.java b/ttool/src/test/java/cli/CLIAvatar2SysMLV2Test.java index 6e2c9a53b0..1168f8497e 100644 --- a/ttool/src/test/java/cli/CLIAvatar2SysMLV2Test.java +++ b/ttool/src/test/java/cli/CLIAvatar2SysMLV2Test.java @@ -50,7 +50,6 @@ import avatartranslator.tosysmlv2.Avatar2SysML; import avatartranslator.tosysmlv2.AvatarFromSysML; import avatartranslator.tosysmlv2.AvatarFromSysMLError; import graph.AUTGraph; -import graph.AUTTransition; import myutil.FileException; import myutil.FileUtils; import myutil.TraceManager; @@ -59,12 +58,10 @@ import test.AbstractTest; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.List; import static org.junit.Assert.*; @@ -272,7 +269,7 @@ public class CLIAvatar2SysMLV2Test extends AbstractTest implements InterpreterOu System.out.println("Testing Model " + model + "................................."); AvatarFromSysML builder = new AvatarFromSysML(); - AvatarSpecification as = builder.sysMLtoSpec(model); + AvatarSpecification as = builder.sysMLFiletoSpec(model); System.out.println("Testing if null return value: (expected:" + errorFromNull[i] + ", obtained:" + (as == null) + ")"); // expected return value ? assertTrue( (as == null ? errorFromNull[i] : !errorFromNull[i])); @@ -345,7 +342,7 @@ public class CLIAvatar2SysMLV2Test extends AbstractTest implements InterpreterOu filePath = "avsysml.sysml"; AvatarFromSysML builder = new AvatarFromSysML(); - AvatarSpecification as = builder.sysMLtoSpec (filePath); + AvatarSpecification as = builder.sysMLFiletoSpec(filePath); assertNotNull(as); // test junk signals @@ -413,7 +410,7 @@ public class CLIAvatar2SysMLV2Test extends AbstractTest implements InterpreterOu public void TestOrder() { File f = new File("test_from.txt"); AvatarFromSysML parser = new AvatarFromSysML(); - AvatarSpecification as = parser.sysMLtoSpec(getBaseResourcesDir() + PATH_TO_MODELS + "avSysML_original.sysml"); + AvatarSpecification as = parser.sysMLFiletoSpec(getBaseResourcesDir() + PATH_TO_MODELS + "avSysML_original.sysml"); assertNotNull(as); try {FileUtils.saveFile(f,as.toString());} catch (FileException e) {fail();} @@ -424,7 +421,7 @@ public class CLIAvatar2SysMLV2Test extends AbstractTest implements InterpreterOu catch (FileException e) {fail();} f = new File("test_to.txt"); - as = parser.sysMLtoSpec("avsysml.sysml"); + as = parser.sysMLFiletoSpec("avsysml.sysml"); try {FileUtils.saveFile(f,as.toString());} catch (FileException e) {fail();} try {assertTrue(filesCompareByLine(Paths.get("test_from.txt"), Paths.get("test_to.txt"))== -1);} -- GitLab