/**
   * parseLayers is an improvement on the old parseLayers from Noah, etc. 's dualstrusion, but uses
   * the same basic method because skeinforge is what it is. look for layer tags, break up the file
   * using those tags.
   *
   * @param source
   * @return
   */
  private LinkedList<Layer> parseLayers(GCodeSource source) {
    final LinkedList<Layer> result = new LinkedList<Layer>();
    String line;

    for (Iterator<String> it = source.iterator(); it.hasNext(); ) {
      line = it.next();
      if (line.startsWith("(<layer>")) {
        // Get the layer height (or whatever SF claims it is)
        float layerHeight = 0;
        try {
          layerHeight = Float.parseFloat(line.split(" ")[1]);
        } catch (NumberFormatException e) {
          Base.logger.log(
              Level.SEVERE,
              "one of your layer heights was unparseable, "
                  + "please check and make sure all of them are in the format (<layer> 0.00)");
        }

        // collect every command up to the end of the layer
        final List<String> accumulate = new ArrayList<String>();
        //				String next = it.next(); actually, let's keep the initial layer tag
        String next = line;
        while (!next.startsWith("(</layer>)")) {
          accumulate.add(next);
          next = it.next();
        }
        // skip empty layers
        if (accumulate.size() > 1) result.add(new Layer(layerHeight, accumulate));
      }
    }

    return result;
  }
Ejemplo n.º 2
0
 /// inserts the passed gcode at specified location, 0 indexed.
 public void add(int location, GCodeSource toAdd) {
   add(location, toAdd.asList());
 }
Ejemplo n.º 3
0
 /// appends an entire GCode source file.
 public void add(GCodeSource toAdd) {
   add(toAdd.asList());
 }
Ejemplo n.º 4
0
 public MutableGCodeSource(GCodeSource shallowCopy) {
   source.addAll(shallowCopy.asList());
 }