From 066c1eaed6a5093232bcc0085448f8a4a79828b6 Mon Sep 17 00:00:00 2001 From: Letitia Li <letitia.li@telecom-paristech.fr> Date: Thu, 14 Dec 2017 12:22:10 +0100 Subject: [PATCH] Jumping to references across diagrams enabled --- src/main/java/ui/GTURTLEModeling.java | 20 +++- src/main/java/ui/LinkedReference.java | 55 +++++++++++ src/main/java/ui/TDiagramPanel.java | 30 ++++++ src/main/java/ui/TGComponent.java | 9 ++ .../ui/avatarsmd/AvatarSMDReceiveSignal.java | 94 ++++++++++++++++++- .../ui/avatarsmd/AvatarSMDSendSignal.java | 13 ++- .../JFrameInteractiveSimulation.java | 3 +- src/main/java/ui/tmlad/TMLADReadChannel.java | 2 +- src/main/java/ui/tmlad/TMLADWriteChannel.java | 2 +- .../java/ui/tmlcompd/TMLCPrimitivePort.java | 2 +- src/main/java/ui/tmldd/TMLArchiBUSNode.java | 2 +- .../java/ui/window/JDialogAvatarSignal.java | 3 + 12 files changed, 221 insertions(+), 14 deletions(-) create mode 100644 src/main/java/ui/LinkedReference.java diff --git a/src/main/java/ui/GTURTLEModeling.java b/src/main/java/ui/GTURTLEModeling.java index 71f72d5338..d765c21bdc 100755 --- a/src/main/java/ui/GTURTLEModeling.java +++ b/src/main/java/ui/GTURTLEModeling.java @@ -8134,6 +8134,7 @@ public class GTURTLEModeling { Element elt1; TGComponent tgc = null; TGComponent father; + TGComponent reference; // try { @@ -8154,6 +8155,7 @@ public class GTURTLEModeling { Point p; int i, x, y; int fatherId = -1, fatherNum = -1; + int referenceId=-1; String pre = "", post = ""; String internalComment = ""; boolean accessibility = false; @@ -8197,6 +8199,8 @@ public class GTURTLEModeling { } else if (elt.getTagName().equals("father")) { fatherId = Integer.decode(elt.getAttribute("id")).intValue(); fatherNum = Integer.decode(elt.getAttribute("num")).intValue(); + } else if (elt.getTagName().equals("reference")) { + referenceId = Integer.decode(elt.getAttribute("id")).intValue(); } else if (elt.getTagName().equals("prejavacode")) { pre += elt.getAttribute("value") + "\n"; } else if (elt.getTagName().equals("postjavacode")) { @@ -8223,6 +8227,8 @@ public class GTURTLEModeling { //TraceManager.addDev("Making TGComponent of type " + myType + " and of name " + myName); //TGComponent is ready to be built + + if(fatherId != -1) { fatherId += decId; // internal component @@ -8276,7 +8282,19 @@ public class GTURTLEModeling { tgc.setName(myName); } - tgc.setHidden(hidden); + + if (referenceId !=-1){ + referenceId += decId; + for (TURTLEPanel turtlepanel: panels){ + for (TDiagramPanel tdpanel: turtlepanel.panels){ + if (tdpanel.findComponentWithId(referenceId) !=null){ + tgc.reference=tdpanel.findComponentWithId(referenceId); + break; + } + } + } + } + tgc.setEnabled(enable); /*if (tgc instanceof TCDTObject) { diff --git a/src/main/java/ui/LinkedReference.java b/src/main/java/ui/LinkedReference.java new file mode 100644 index 0000000000..4e3e0bbe2e --- /dev/null +++ b/src/main/java/ui/LinkedReference.java @@ -0,0 +1,55 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + + + + +package ui; +import java.util.HashMap; +/** + * Class LinkedReference + * Components which link a reference requirement or other component from another type of diagram (i.e: Public Buses link to Attacks from an Attack Tree) + * Creation: 14/12/2017 + * @version 1.0 14/12/2017 + * @author Letitia LI + */ +public interface LinkedReference { + + +} diff --git a/src/main/java/ui/TDiagramPanel.java b/src/main/java/ui/TDiagramPanel.java index 68ec600e15..db7989072f 100755 --- a/src/main/java/ui/TDiagramPanel.java +++ b/src/main/java/ui/TDiagramPanel.java @@ -126,6 +126,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { protected int popupX, popupY; protected JMenuItem remove, edit, clone, bringFront, bringBack, makeSquare, setJavaCode, removeJavaCode, setInternalComment, removeInternalComment, attach, detach, hide, unhide,search, enableDisable, setAsCryptoBlock, setAsRegularBlock; protected JMenuItem checkAccessibility, checkInvariant, checkMasterMutex, checkLatency; + protected JMenuItem gotoReference; protected JMenuItem breakpoint; protected JMenuItem paste, insertLibrary, upX, upY, downX, downY, fitToContent, backToMainDiagram; protected JMenuItem cut, copy, saveAsLibrary, captureSelected; @@ -1407,6 +1408,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { componentMenu.add(checkAccessibility); componentMenu.add(checkInvariant); componentMenu.add(checkLatency); + componentMenu.add(gotoReference); componentMenu.add(checkMasterMutex); componentMenu.add(breakpoint); @@ -1521,6 +1523,9 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { breakpoint = new JMenuItem("Add / remove breakpoint"); breakpoint.addActionListener(menuAL); + gotoReference = new JMenuItem("Go to reference"); + gotoReference.addActionListener(menuAL); + search = new JMenuItem("External Search"); search.addActionListener(menuAL); @@ -1783,6 +1788,23 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { componentPopup.setCheckLatency(!componentPopup.getCheckLatency()); } } + + if (e.getSource() == gotoReference) { + if (componentPopup instanceof LinkedReference){ + //Code for navigating to the diagram + if (componentPopup.reference !=null){ + TDiagramPanel refTDP = componentPopup.reference.getTDiagramPanel(); + if (refTDP!=null){ + mgui.selectTab(refTDP.tp); + mgui.selectTab(refTDP); + refTDP.highlightTGComponent(componentPopup.reference); + } + + } + + } + } + if (e.getSource() == checkMasterMutex) { if (componentPopup instanceof CheckableInvariant) { @@ -2029,6 +2051,14 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { } + + if (componentPointed instanceof LinkedReference){ + gotoReference.setEnabled(true); + } else { + gotoReference.setEnabled(false); + + } + if (componentPointed instanceof CheckableInvariant){ checkInvariant.setEnabled(true); checkMasterMutex.setEnabled(true); diff --git a/src/main/java/ui/TGComponent.java b/src/main/java/ui/TGComponent.java index d10f0363f3..daf834739b 100755 --- a/src/main/java/ui/TGComponent.java +++ b/src/main/java/ui/TGComponent.java @@ -113,6 +113,8 @@ public abstract class TGComponent implements CDElement, GenericTree { protected TGComponent father; private boolean moveWithFather = true; + protected TGComponent reference; + private int id; // DIPLODOCUS ID @@ -3016,6 +3018,9 @@ public abstract class TGComponent implements CDElement, GenericTree { if (!b) { sb.append(translateFatherInformation()); } + if (reference!=null){ + sb.append(translateReferenceInformation()); + } sb.append(translateCDParam()); sb.append(translateSizeParam()); sb.append(translateHidden()); @@ -3046,6 +3051,10 @@ public abstract class TGComponent implements CDElement, GenericTree { return sb; } + protected String translateReferenceInformation(){ + return "<reference id=\"" + reference.getId() + "\" />\n"; + } + protected String translateFatherInformation() { return "<father id=\"" + father.getId() + "\" num=\"" + father.getMyNum(this) + "\" />\n"; } diff --git a/src/main/java/ui/avatarsmd/AvatarSMDReceiveSignal.java b/src/main/java/ui/avatarsmd/AvatarSMDReceiveSignal.java index ad312783a5..8deb1f95ec 100644 --- a/src/main/java/ui/avatarsmd/AvatarSMDReceiveSignal.java +++ b/src/main/java/ui/avatarsmd/AvatarSMDReceiveSignal.java @@ -56,6 +56,7 @@ import java.util.LinkedList; import java.util.ArrayList; import java.util.HashMap; import java.util.Vector; +import ui.avatarrd.AvatarRDRequirement; import ui.tmlad.TMLADReadChannel; /** @@ -65,7 +66,7 @@ import ui.tmlad.TMLADReadChannel; * @version 1.0 12/04/2010 * @author Ludovic APVRILLE */ -public class AvatarSMDReceiveSignal extends AvatarSMDBasicComponent implements CheckableAccessibility, CheckableLatency, BasicErrorHighlight, PartOfInvariant { +public class AvatarSMDReceiveSignal extends AvatarSMDBasicComponent implements CheckableAccessibility, LinkedReference, CheckableLatency, BasicErrorHighlight, PartOfInvariant { protected int lineLength = 5; protected int textX = 5; protected int textY = 15; @@ -74,12 +75,13 @@ public class AvatarSMDReceiveSignal extends AvatarSMDBasicComponent implements C protected int textX1 = 2; private ConcurrentHashMap<String, String> latencyVals; - private TGComponent reference; + protected int latencyX=30; protected int latencyY=25; protected int textWidth=10; protected int textHeight=20; + protected int stateOfError = 0; // Not yet checked @@ -181,7 +183,12 @@ public class AvatarSMDReceiveSignal extends AvatarSMDBasicComponent implements C drawLatencyInformation(g); } } - + if (reference!=null){ + if (reference instanceof AvatarRDRequirement){ + AvatarRDRequirement refReq = (AvatarRDRequirement) reference; + g.drawString("ref: "+ refReq.getValue(), x, y+height1+textY); + } + } } public void drawLatencyInformation(Graphics g){ int index=1; @@ -191,7 +198,77 @@ public class AvatarSMDReceiveSignal extends AvatarSMDBasicComponent implements C g.drawRect(x-latencyX-w, y-latencyY*index-textHeight, w+4, textHeight); g.drawLine(x,y,x-latencyX, y-latencyY*index); Color c = g.getColor(); - if (reference instanceof TMLADReadChannel){ + if (reference !=null){ + //References must be in the form "The max delay between send/recieve signal:(signalname) and send/receive signal (signalname) is (less than/greater than) X. + String req= ((AvatarRDRequirement) reference).getText().trim(); + if (req.contains("The max delay between")){ + //Attempt to parse string + boolean lessThan= req.contains(" less than "); + String sig1 = req.split(" between ")[1].split(" and ")[0].trim(); + String sig2 = req.split(" and ")[1].split(" is ")[0].trim(); + String num = req.split(" than ")[1]; + + num = num.replaceAll("\\.",""); + + int refNum = -1; + try { + refNum = Integer.valueOf(num); + } + catch(Exception e){ + } + + if (sig1.equals("receive signal: " + value.split("\\(")[0])){ + if (sig2.replaceAll(": ","-").equalsIgnoreCase(s)){ + //Compare times + int tActual=Integer.valueOf(latencyVals.get(s.split(":")[0])); + if (refNum>0){ + if (lessThan){ + if (tActual < refNum){ + g.setColor(Color.GREEN); + } + else { + g.setColor(Color.RED); + } + } + else { + if (tActual> refNum){ + g.setColor(Color.GREEN); + } + else { + g.setColor(Color.RED); + } + } + } + } + } + else if (sig2.equals("receive signal: " + value.split("\\(")[0])){ + if (sig1.replaceAll(": ","-").trim().equalsIgnoreCase(s.split(":")[0].trim())){ + //Compare times + int tActual=Integer.valueOf(latencyVals.get(s)); + //System.out.println(refNum + " " + tActual); + if (refNum>0){ + if (lessThan){ + if (tActual < refNum){ + g.setColor(Color.GREEN); + } + else { + g.setColor(Color.RED); + } + } + else { + if (tActual> refNum){ + g.setColor(Color.GREEN); + } + else { + g.setColor(Color.RED); + } + } + } + } + } + } + } + /*if (reference instanceof TMLADReadChannel){ // System.out.println("ref " + reference.toString().split(": ")[1].split("\\(")[0] + " " + s.split("-")[1].split(":")[0]); TMLADReadChannel rc = (TMLADReadChannel) reference; ConcurrentHashMap<String, String> refLats =rc.getLatencyMap(); @@ -209,7 +286,7 @@ public class AvatarSMDReceiveSignal extends AvatarSMDBasicComponent implements C } } } - } + }*/ g.drawString(latencyVals.get(s), x-latencyX/2, y-latencyY*index/2); g.setColor(c); index++; @@ -282,12 +359,19 @@ public class AvatarSMDReceiveSignal extends AvatarSMDBasicComponent implements C public boolean editOndoubleClick(JFrame frame) { + // System.out.println("reference " + reference); LinkedList<AvatarSignal> signals = tdp.getMGUI().getAllSignals(); TraceManager.addDev("Nb of signals:" + signals.size()); ArrayList<TGComponent> comps = tdp.getMGUI().getAllLatencyChecks(); Vector<TGComponent> refs = new Vector<TGComponent>(); + for (TGComponent req: tdp.getMGUI().getAllRequirements()){ + //System.out.println("req " + req); + if (req instanceof AvatarRDRequirement){ + refs.add(((AvatarRDRequirement) req)); + } + } for (TGComponent tg:comps){ if (tg instanceof TMLADReadChannel){ refs.add(tg); diff --git a/src/main/java/ui/avatarsmd/AvatarSMDSendSignal.java b/src/main/java/ui/avatarsmd/AvatarSMDSendSignal.java index 693ab0c8b9..7a1cf09d2c 100644 --- a/src/main/java/ui/avatarsmd/AvatarSMDSendSignal.java +++ b/src/main/java/ui/avatarsmd/AvatarSMDSendSignal.java @@ -54,6 +54,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.Vector; +import ui.avatarrd.AvatarRDRequirement; import ui.tmlad.TMLADWriteChannel; /** @@ -63,7 +64,7 @@ import ui.tmlad.TMLADWriteChannel; * @version 1.0 12/04/2010 * @author Ludovic APVRILLE */ -public class AvatarSMDSendSignal extends AvatarSMDBasicComponent implements CheckableAccessibility, CheckableLatency, BasicErrorHighlight, PartOfInvariant { +public class AvatarSMDSendSignal extends AvatarSMDBasicComponent implements CheckableAccessibility, LinkedReference, CheckableLatency, BasicErrorHighlight, PartOfInvariant { protected int lineLength = 5; protected int textX = 5; protected int textY = 15; @@ -71,7 +72,6 @@ public class AvatarSMDSendSignal extends AvatarSMDBasicComponent implements Chec protected int linebreak = 10; private ConcurrentHashMap<String, String> latencyVals; - private TGComponent reference; protected int latencyX=30; protected int latencyY=25; @@ -277,8 +277,15 @@ public class AvatarSMDSendSignal extends AvatarSMDBasicComponent implements Chec LinkedList<AvatarSignal> signals = tdp.getMGUI().getAllSignals(); //TraceManager.addDev("Nb of signals:" + signals.size()); ArrayList<TGComponent> comps = tdp.getMGUI().getAllLatencyChecks(); + Vector<TGComponent> refs = new Vector<TGComponent>(); - refs.add(null); + for (TGComponent req: tdp.getMGUI().getAllRequirements()){ + //System.out.println("req " + req); + if (req instanceof AvatarRDRequirement){ + refs.add((AvatarRDRequirement) req); + } + } + for (TGComponent tg:comps){ if (tg instanceof TMLADWriteChannel){ refs.add(tg); diff --git a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java index 7d85aad1a9..a34610cc56 100755 --- a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java +++ b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java @@ -1525,7 +1525,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene }*/ protected void addTransactionToNode(SimulationTransaction tran){ - //System.out.println("Command " + tran.command + " " + tran.deviceName + " " + tran.channelName); + String command = tran.command; if (command.contains(" ")){ @@ -1703,6 +1703,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene } else { TraceManager.addDev("UNHANDLED COMMAND " + tran.command + " " + tran.deviceName + " " + tran.nodeType); +// System.out.println("Command " + tran.command + " " + tran.deviceName + " " + tran.channelName); } //System.out.println("Simulation command " + tran.command + " " + tran.channelName + " " + tran.length); diff --git a/src/main/java/ui/tmlad/TMLADReadChannel.java b/src/main/java/ui/tmlad/TMLADReadChannel.java index c3d37e1107..d0e94d2c47 100755 --- a/src/main/java/ui/tmlad/TMLADReadChannel.java +++ b/src/main/java/ui/tmlad/TMLADReadChannel.java @@ -63,7 +63,7 @@ import java.util.concurrent.ConcurrentHashMap; * @version 1.0 21/11/2005 * @author Ludovic APVRILLE */ -public class TMLADReadChannel extends TGCWithoutInternalComponent implements CheckableAccessibility, CheckableLatency, EmbeddedComment, AllowedBreakpoint, BasicErrorHighlight { +public class TMLADReadChannel extends TGCWithoutInternalComponent implements CheckableAccessibility, LinkedReference, CheckableLatency, EmbeddedComment, AllowedBreakpoint, BasicErrorHighlight { private ConcurrentHashMap<String, String> latencyVals; protected int lineLength = 5; protected int textX = 5; diff --git a/src/main/java/ui/tmlad/TMLADWriteChannel.java b/src/main/java/ui/tmlad/TMLADWriteChannel.java index a15f95ec63..244fd6b4a7 100755 --- a/src/main/java/ui/tmlad/TMLADWriteChannel.java +++ b/src/main/java/ui/tmlad/TMLADWriteChannel.java @@ -65,7 +65,7 @@ import java.util.concurrent.ConcurrentHashMap; * @version 1.0 17/11/2005 * @author Ludovic APVRILLE */ -public class TMLADWriteChannel extends TGCWithoutInternalComponent implements CheckableAccessibility, CheckableLatency, EmbeddedComment, AllowedBreakpoint, BasicErrorHighlight { +public class TMLADWriteChannel extends TGCWithoutInternalComponent implements CheckableAccessibility, LinkedReference, CheckableLatency, EmbeddedComment, AllowedBreakpoint, BasicErrorHighlight { protected int lineLength = 5; protected int textX = 5; protected int textY = 15; diff --git a/src/main/java/ui/tmlcompd/TMLCPrimitivePort.java b/src/main/java/ui/tmlcompd/TMLCPrimitivePort.java index d5b3c164e9..ae1e6793ea 100755 --- a/src/main/java/ui/tmlcompd/TMLCPrimitivePort.java +++ b/src/main/java/ui/tmlcompd/TMLCPrimitivePort.java @@ -66,7 +66,7 @@ import java.util.Vector; * @version 1.0 12/03/2008 * @author Ludovic APVRILLE */ -public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent implements SwallowedTGComponent, WithAttributes { +public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent implements SwallowedTGComponent, LinkedReference, WithAttributes { protected Color myColor; protected int orientation; protected int oldx, oldy; diff --git a/src/main/java/ui/tmldd/TMLArchiBUSNode.java b/src/main/java/ui/tmldd/TMLArchiBUSNode.java index cb731ab15e..2776110fca 100755 --- a/src/main/java/ui/tmldd/TMLArchiBUSNode.java +++ b/src/main/java/ui/tmldd/TMLArchiBUSNode.java @@ -62,7 +62,7 @@ import java.util.Vector; * @version 1.0 31/10/2007 * @author Ludovic APVRILLE */ -public class TMLArchiBUSNode extends TMLArchiCommunicationNode implements SwallowTGComponent, WithAttributes, TMLArchiElementInterface { +public class TMLArchiBUSNode extends TMLArchiCommunicationNode implements SwallowTGComponent, LinkedReference, WithAttributes, TMLArchiElementInterface { private int textY1 = 15; private int textY2 = 30; private int derivationx = 2; diff --git a/src/main/java/ui/window/JDialogAvatarSignal.java b/src/main/java/ui/window/JDialogAvatarSignal.java index c2d3821510..d9221b4996 100755 --- a/src/main/java/ui/window/JDialogAvatarSignal.java +++ b/src/main/java/ui/window/JDialogAvatarSignal.java @@ -175,6 +175,9 @@ public class JDialogAvatarSignal extends JDialogBase implements ActionListener panel1.add(new JLabel("Reference Requirement"),c1); c1.gridwidth = GridBagConstraints.REMAINDER; //end row refChecks = new JComboBox<TGComponent>(refs); + if (reference!=null){ + refChecks.setSelectedItem(reference); + } panel1.add(refChecks,c1); -- GitLab