1 17 18 19 package SOFA.SOFAnode.Util.DFSRChecker.DFSR; 20 21 22 import java.io.FileOutputStream ; 23 import java.io.IOException ; 24 25 26 import SOFA.SOFAnode.Util.DFSRChecker.node.ActionRepository; 27 import SOFA.SOFAnode.Util.DFSRChecker.node.InvalidParameterException; 28 import SOFA.SOFAnode.Util.DFSRChecker.node.TreeNode; 29 import SOFA.SOFAnode.Util.DFSRChecker.state.State; 30 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair; 31 32 37 public class DFSRDotVis implements IDFSRExtension { 38 39 46 public DFSRDotVis(FileOutputStream outputfile, TreeNode automaton, ActionRepository repository) { 47 this.outputfile = outputfile; 48 this.automaton = automaton; 49 this.repository = repository; 50 } 51 52 55 public void action(State state) throws InvalidParameterException { 56 } 57 58 61 public boolean actionNew(State state) throws InvalidParameterException, CheckingException { 62 state.label = new String ("S" + timestamp); 63 64 try { 65 boolean acc = automaton.isAccepting(state); 67 State initstate = automaton.getInitial(); 68 boolean init = initstate.getSignature().equals(state.getSignature()); 69 if (acc) 70 outputfile.write((" \"" + state.getSignature() + "\" [label=\"S" + timestamp + "\", shape=doublecircle, style=filled, fillcolor=\"grey\"];\n").getBytes()); 71 else 72 outputfile.write((" \"" + state.getSignature() + "\" [label=\"S" + timestamp + "\"];\n").getBytes()); 73 74 if (init) 75 if (acc) 76 outputfile.write((" \"" + state.getSignature() + "\" [shape=box, peripheries=2, style=filled, fillcolor=\"grey\"];\n").getBytes()); 77 else 78 outputfile.write((" \"" + state.getSignature() + "\" [shape=box];\n").getBytes()); 79 80 TransitionPair[] trans = automaton.getTransitions(state).transitions; 82 for (int i = 0; i < trans.length; ++i) { 83 outputfile.write((" \"" + state.getSignature() + "\" -> \"" + trans[i].state.getSignature() + "\" [label=\"" + repository.getItemString(trans[i].eventIndex) + "\"];\n").getBytes()); 84 if (trans[i].state.label.equals("<no_label>")) 85 outputfile.write((" \"" + trans[i].state.getSignature() + "\" [label=\".\"];\n").getBytes()); 86 } 87 88 } catch (IOException e) { 89 throw new AcceptingStateException("Visualization backend: error while writing to the file."); 90 } 91 92 state.timestamp = timestamp++; 93 94 95 return automaton.isAccepting(state); 96 } 97 98 101 public void actionCycle(State state) throws InvalidParameterException { 102 if (state.getSignature().getCycleId() == Long.MAX_VALUE) { 103 state.cycleStart = true; 104 state.getSignature().setCycleId(state.timestamp); 105 } 106 } 107 108 111 public void actionVisited(State state) throws InvalidParameterException { 112 } 113 114 117 public void actionBack(State state) throws InvalidParameterException { 118 try { 119 if (state.isAcceptingReachable()) { 120 outputfile.write((" \"" + state.getSignature() + "\" [style=filled, fillcolor=\"grey\"];\n").getBytes()); 121 } 122 } catch (IOException e) { 123 } 124 125 } 126 127 130 public void reset() { 131 timestamp = 0; 132 } 133 134 138 private FileOutputStream outputfile; 139 140 143 private int timestamp = 0; 144 145 148 private TreeNode automaton; 149 150 153 private ActionRepository repository; 154 155 } | Popular Tags |