Esempio n. 1
0
 private static void processGraph(SFCGraph graph, File dir, String baseName) {
   File output = new File(dir, baseName + "_" + graph.getName() + ".tex");
   try {
     FileWriter fw = new FileWriter(output);
     writeTex(graph, fw);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
  private static void writeTex(SFCGraph graph, Writer fw) throws IOException {
    fw.write(
        "\\documentclass{article}\n"
            + "\\usepackage[utf8]{inputenc}\n\\usepackage{tikz}\n\\usepackage{grafcet}\n\\usetikzlibrary{shapes,arrows,positioning}\n"
            + "\\begin{document}\\begin{tikzpicture}");

    Queue<SFCGraph.Step> queue = new LinkedList<>();

    for (SFCGraph.Node node : graph.getNodes()) {
      if (node instanceof SFCGraph.Step) {
        SFCGraph.Step step = (SFCGraph.Step) node;
        if (step.initial) {
          queue.add(step);
        }
      }
    }

    NameGiver name = new NameGiver();
    Set<SFCGraph.Step> visited = new HashSet<>();

    while (!queue.isEmpty()) {
      SFCGraph.Step step = queue.poll();
      String n = step.name.replace("_", "-");
      int number = name.get(step.name);

      if (step.initial) {
        fw.write("\\EtapeInit{" + n + "}\n");
      } else {
        fw.write("\\Etape{" + n + "}\n");
      }

      for (SFCGraph.Transition t : step.outgoing) {
        fw.write(
            "\\Transition{"
                + number
                + "}\\Recept{T"
                + number
                + "}{"
                + guardString(t.conditions)
                + "}\n");
        if (!visited.contains(t.to)) {
          queue.add((SFCGraph.Step) t.to);
          visited.add((SFCGraph.Step) t.to);
        } else {
          fw.write("\\LienRetour{T" + number + "}{X" + t.to.name.replace("_", "-") + "}\n");
        }
      }
    }

    fw.write("\\end{tikzpicture}\\end{document}");

    fw.flush();
    fw.close();
  }