diff --git a/src/main/java/cli/Action.java b/src/main/java/cli/Action.java index 3ede8b7940b771a554c059df6534fee24d0422c7..ce0adc24c9cae2e0f390865755232faed756f8c1 100644 --- a/src/main/java/cli/Action.java +++ b/src/main/java/cli/Action.java @@ -39,6 +39,7 @@ package cli; +import attacktrees.AttackTree; import avatartranslator.*; import avatartranslator.directsimulation.AvatarSpecificationSimulation; import avatartranslator.modelchecker.AvatarModelChecker; @@ -70,6 +71,7 @@ import tmltranslator.mutations.DiplodocusMutation; import tmltranslator.mutations.DiplodocusMutationParser; import tmltranslator.mutations.ParseDiplodocusMutationException; import ui.MainGUI; +import ui.atd.AttackTreeDiagramPanel; import ui.avatarinteractivesimulation.AvatarInteractiveSimulationActions; import ui.avatarinteractivesimulation.JFrameAvatarInteractiveSimulation; import ui.graphd.GraphDPanel; @@ -137,6 +139,8 @@ public class Action extends Command implements ProVerifOutputListener { private final static String SELECT_PANEL = "select-panel"; + private final static String ATTACK_TREE_DUPLICATE = "attack-tree-duplicate"; + private final static String AVATAR_MUTATION = "avatar-mutation"; private final static String AVATAR_MUTATION_BATCH = "avatar-mutation-batch"; private final static String AVATAR_DRAW = "avatar-draw"; @@ -2472,6 +2476,55 @@ public class Action extends Command implements ProVerifOutputListener { }; + Command attackTreeDuplication = new Command() { + public String getCommand() { + return ATTACK_TREE_DUPLICATE; + } + + public String getShortCommand() { + return "atd"; + } + + public String getDescription() { + return "Duplicate a displayed attack tree via its internal representation"; + } + + public String getUsage() { + return ATTACK_TREE_DUPLICATE; + } + + public String executeCommand(String command, Interpreter interpreter) { + if (!interpreter.isTToolStarted()) { + return Interpreter.TTOOL_NOT_STARTED; + } + + TDiagramPanel tdp = interpreter.mgui.getCurrentTDiagramPanel(); + + if (tdp == null) { + return interpreter.TTOOL_NO_MODEL; + } + + if (!(tdp instanceof AttackTreeDiagramPanel)) { + return interpreter.TTOOL_BAD_DIAGRAM; + } + + AttackTreePanelTranslator atpt = new AttackTreePanelTranslator((AttackTreeDiagramPanel) tdp); + AttackTree at = atpt.translateToAttackTreeDataStructure(); + if (at == null) { + return interpreter.GEN_FAILED; + } + + TraceManager.addDev("Drawing attack tree:" + at.toString() + " / " + at.toTextFormat()); + + interpreter.mgui.drawAttackTreeDiagram(at); + + + + return null; + } + }; + + @@ -2530,6 +2583,8 @@ public class Action extends Command implements ProVerifOutputListener { addAndSortSubcommand(graphtToAvatar); addAndSortSubcommand(AvatarDependencyGraphGeneration); + addAndSortSubcommand(attackTreeDuplication); + } diff --git a/src/main/java/cli/Interpreter.java b/src/main/java/cli/Interpreter.java index d47aca788ec09ad3e8c581d5353eaed50d5aa5d2..52e9afed35952ff6b9d8c9be2ef03ae53ad32598 100644 --- a/src/main/java/cli/Interpreter.java +++ b/src/main/java/cli/Interpreter.java @@ -72,6 +72,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { public final static String UNKNOWN_NEXT_COMMAND = "Invalid action: "; public final static String TTOOL_NOT_STARTED = "TTool is not yet started. Cannot execute command."; public final static String TTOOL_NO_MODEL = "TTool is started no model has been created. Execute new or load a model"; + public final static String TTOOL_BAD_DIAGRAM = "The selected diagram is not the correct one"; public final static String TTOOL_ALREADY_STARTED = "TTool is already started. Cannot execute command."; public final static String BAD_COMMAND_NAME = "The provided command is invalid"; public final static String ROBOT_EXCEPTION = "Robot could not be started"; @@ -87,6 +88,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { public final static String BAD_TYPE = "Invalid type"; + private String script; private InterpreterOutputInterface printInterface; private boolean show; diff --git a/src/main/java/ui/atd/ATDCountermeasure.java b/src/main/java/ui/atd/ATDCountermeasure.java index 4b3b650c32953b751c706d360d1a80ba2ac17c4d..8b0684a7f749028ffce8e3940488d58506cab423 100644 --- a/src/main/java/ui/atd/ATDCountermeasure.java +++ b/src/main/java/ui/atd/ATDCountermeasure.java @@ -204,7 +204,7 @@ public class ATDCountermeasure extends TGCScalableWithInternalComponent implemen g.setFont(fold); } - + private Polygon getMyPolygon() { Polygon p = new Polygon(); diff --git a/src/main/java/ui/atd/AttackTreeDiagramPanel.java b/src/main/java/ui/atd/AttackTreeDiagramPanel.java index 4ff293462c10ca9d7da00655eec5227c72098330..29e3e3d01685994018b077af746f452b3d6dab30 100644 --- a/src/main/java/ui/atd/AttackTreeDiagramPanel.java +++ b/src/main/java/ui/atd/AttackTreeDiagramPanel.java @@ -222,9 +222,17 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr ATDConstraint _const, int _valueConst, int _x, int _y, int _length) { ATDAttack attack = alreadyDrawnAttack(_att); + int newX, newY; if (attack == null) { // We draw the attack + newX = _x; + newY = _y; + attack = new ATDAttack(_x, _y, getMinX(), getMaxX(), getMinY(), getMaxY(), true, null, this); + if ((_att.getReferenceObject() != null) && (_att.getReferenceObject() instanceof CDElement)) { + CDElement cd = (CDElement) _att.getReferenceObject(); + attack.setUserResize(cd.getX(), cd.getY(), cd.getWidth(), cd.getHeight()); + } attack.setValue(_att.getName()); attack.setRootAttack(_att.isRoot()); attack.setDescription(_att.getDescription()); @@ -275,6 +283,10 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr _y = _y + 70; ATDConstraint constraint = new ATDConstraint(_x, _y, getMinX(), getMaxX(), getMinY(), getMaxY(), true, null, this); //constraint.setValue(nextNode.getName()); + if ((nextNode.getReferenceObject() != null) && (nextNode.getReferenceObject() instanceof CDElement)) { + CDElement cd = (CDElement) nextNode.getReferenceObject(); + constraint.setUserResize(cd.getX(), cd.getY(), cd.getWidth(), cd.getHeight()); + } constraint.setType(nextNode.getType()); addBuiltComponent(constraint); _mapOfComponents.put(nextNode, constraint); @@ -365,6 +377,10 @@ public class AttackTreeDiagramPanel extends TDiagramPanel implements TDPWithAttr for(Defense def : _at.getDefenses()) { ATDCountermeasure atdc = new ATDCountermeasure(xNoRel, yNoRel, getMinX(), getMaxX(), getMinY(), getMaxY(), true, null, this); + if ((def.getReferenceObject() != null) && (def.getReferenceObject() instanceof CDElement)) { + CDElement cd = (CDElement) def.getReferenceObject(); + atdc.setUserResize(cd.getX(), cd.getY(), cd.getWidth(), cd.getHeight()); + } atdc.setCountermeasureName(def.getName()); atdc.setDescription(def.getDescription()); atdc.setEnabled(true);