Exemplo n.º 1
0
  /**
   * Called to convert FSM to LaTeX code. Once the Latex is generated, a popup window is created
   * from within the function.
   */
  public void toLatex() {
    List<FATransition> transitions = machine.getTransitionList();

    String latex = "\\begin{tikzpicture}[shorten >=1pt, node distance = 2.5cm, auto]\n";

    // Following block is for state data
    // TODO Insert positioning data

    List<GElementFAState> nodes = getStates();

    Vector2D scale = getScaleFactor(nodes);

    // latex += "minX " + this.left + " minY " + this.bottom + " maxX " +
    // this.right + " maxY " + this.top;

    latex += nodesToLatex(nodes, scale);

    Iterator<FATransition> it = transitions.iterator();

    List<String> transitionToLatex = new LinkedList();

    while (it.hasNext()) {
      FATransition transition = it.next();

      int node1 = getLatexId(transition.s1);
      int node2 = getLatexId(transition.s2);

      String s = new String();
      s = "\t\t(q" + node1 + ")";
      if (node1 == node2) {
        s += "\tedge [loop] node {" + transition.symbol + "}";
      } else {
        s += "\tedge node {" + transition.symbol + "}";
      }
      s += " (q" + node2 + ")";
      transitionToLatex.add(s);
    }

    latex += "\\path[->]";
    for (String s : transitionToLatex) {
      latex += "\n" + s;
    }
    latex += ";\n";

    // End the LaTeX FA element
    latex += "\\end{tikzpicture}";

    LaTexWindow w = new LaTexWindow(latex);
    w.setVisible(true);
  }